[svn-commits] file: branch group/media_formats-reviewed-trunk r418778 - in /team/group/medi...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jul 16 09:34:20 CDT 2014


Author: file
Date: Wed Jul 16 09:34:16 2014
New Revision: 418778

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=418778
Log:
Multiple revisions 418755,418757

........
  r418755 | mjordan | 2014-07-16 06:55:36 -0700 (Wed, 16 Jul 2014) | 16 lines
  
  cel_pgsql, cdr_pgsql, res_config_pgsql: Add PostgreSQL application_name support
  
  This patch adds support for the PostgreSQL application_name connection setting.
  When the appropriate PostgreSQL module's configuration is set with an
  application name, the name will be passed to PostgreSQL on connection and
  displayed in the database's pg_stat_activity view, as well as in CSV logs. This
  aids in managing which applications/servers are connected to a PostgreSQL
  database, as well as tracing the activity of those connections.
  
  Review: https://reviewboard.asterisk.org/r/3591
  
  ASTERISK-23737 #close
  Reported by: Gergely Domodi
  patches:
    pgsql_application_name.patch uploaded by Gergely Domodi (License 6610)
........
  r418757 | mjordan | 2014-07-16 07:03:51 -0700 (Wed, 16 Jul 2014) | 19 lines
  
  res_pjsip: Support setting a default accountcode on endpoints
  
  Most channel drivers let you specify a default accountcode to be set on
  channels associated with a particular peer/endpoint/object. Prior to this
  patch, chan_pjsip/res_pjsip did not support such a setting.
  
  This patch adds a new setting to the res_pjsip endpoint object, 'accountcode'.
  When a channel is created that is associated with an endpoint with this value
  set, the channel will automatically have its accountcode property set to the
  value configured for the endpoint.
  
  Review: https://reviewboard.asterisk.org/r/3724/
  
  ASTERISK-24000 #close
  Reported by: Matt Jordan
  ........
  
  Merged revisions 418756 from http://svn.asterisk.org/svn/asterisk/branches/12
........

Merged revisions 418755,418757 from http://svn.asterisk.org/svn/asterisk/trunk

Added:
    team/group/media_formats-reviewed-trunk/contrib/ast-db-manage/config/versions/1d50859ed02e_create_accountcode.py
      - copied unchanged from r418757, trunk/contrib/ast-db-manage/config/versions/1d50859ed02e_create_accountcode.py
Modified:
    team/group/media_formats-reviewed-trunk/   (props changed)
    team/group/media_formats-reviewed-trunk/CHANGES
    team/group/media_formats-reviewed-trunk/cdr/cdr_pgsql.c
    team/group/media_formats-reviewed-trunk/cel/cel_pgsql.c
    team/group/media_formats-reviewed-trunk/channels/chan_pjsip.c
    team/group/media_formats-reviewed-trunk/configs/cdr_pgsql.conf.sample
    team/group/media_formats-reviewed-trunk/configs/cel_pgsql.conf.sample
    team/group/media_formats-reviewed-trunk/configs/pjsip.conf.sample
    team/group/media_formats-reviewed-trunk/configs/res_pgsql.conf.sample
    team/group/media_formats-reviewed-trunk/include/asterisk/res_pjsip.h
    team/group/media_formats-reviewed-trunk/res/res_config_pgsql.c
    team/group/media_formats-reviewed-trunk/res/res_pjsip.c
    team/group/media_formats-reviewed-trunk/res/res_pjsip/pjsip_configuration.c

Propchange: team/group/media_formats-reviewed-trunk/
------------------------------------------------------------------------------
    automerge = *

Propchange: team/group/media_formats-reviewed-trunk/
------------------------------------------------------------------------------
Binary property 'branch-12-merged' - no diff available.

Propchange: team/group/media_formats-reviewed-trunk/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Wed Jul 16 09:34:16 2014
@@ -1,1 +1,1 @@
-/trunk:1-418753
+/trunk:1-418764

Modified: team/group/media_formats-reviewed-trunk/CHANGES
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/CHANGES?view=diff&rev=418778&r1=418777&r2=418778
==============================================================================
--- team/group/media_formats-reviewed-trunk/CHANGES (original)
+++ team/group/media_formats-reviewed-trunk/CHANGES Wed Jul 16 09:34:16 2014
@@ -49,6 +49,20 @@
 -----------------
  * This module was deprecated and has been removed. Users of cdr_sqlite
    should use cdr_sqlite3_custom.
+
+cdr_pgsql
+------------------
+ * Added the ability to support PostgreSQL application_name on connections.
+   This allows PostgreSQL to display the configured name in the
+   pg_stat_activity view and CSV log entries. This setting is configurable
+   for cdr_pgsql via the appname configuration setting in cdr_pgsql.conf.
+
+cel_pgsql
+------------------
+ * Added the ability to support PostgreSQL application_name on connections.
+   This allows PostgreSQL to display the configured name in the
+   pg_stat_activity view and CSV log entries. This setting is configurable
+   for cel_pgsql via the appname configuration setting in cel_pgsql.conf.
 
 CEL
 ------------------
@@ -155,6 +169,25 @@
    - jb-ga: article ga
    - jb-wa: article wa
    - jb-wo: article wo
+
+res_config_pgsql
+------------------
+ * Added the ability to support PostgreSQL application_name on connections.
+   This allows PostgreSQL to display the configured name in the
+   pg_stat_activity view and CSV log entries. This setting is configurable
+   for res_config_pgsql via the dbappname configuration setting in
+   res_pgsql.conf.
+
+------------------------------------------------------------------------------
+--- Functionality changes from Asterisk 12.4.0 to Asterisk 12.5.0 ------------
+------------------------------------------------------------------------------
+
+res_pjsip
+------------------
+ * The endpoint configuration object now supports 'accountcode'. Any channel
+   created for an endpoint with this setting will have its accountcode set
+   to the specified value.
+
 
 ------------------------------------------------------------------------------
 --- Functionality changes from Asterisk 12.3.0 to Asterisk 12.4.0 ------------

Modified: team/group/media_formats-reviewed-trunk/cdr/cdr_pgsql.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/cdr/cdr_pgsql.c?view=diff&rev=418778&r1=418777&r2=418778
==============================================================================
--- team/group/media_formats-reviewed-trunk/cdr/cdr_pgsql.c (original)
+++ team/group/media_formats-reviewed-trunk/cdr/cdr_pgsql.c Wed Jul 16 09:34:16 2014
@@ -63,7 +63,17 @@
 
 static const char name[] = "pgsql";
 static const char config[] = "cdr_pgsql.conf";
-static char *pghostname = NULL, *pgdbname = NULL, *pgdbuser = NULL, *pgpassword = NULL, *pgdbport = NULL, *table = NULL, *encoding = NULL, *tz = NULL;
+
+static char *pghostname;
+static char *pgdbname;
+static char *pgdbuser;
+static char *pgpassword;
+static char *pgappname;
+static char *pgdbport;
+static char *table;
+static char *encoding;
+static char *tz;
+
 static int connected = 0;
 static int maxsize = 512, maxsize2 = 512;
 static time_t connect_time = 0;
@@ -174,6 +184,34 @@
 	return CLI_SUCCESS;
 }
 
+static void pgsql_reconnect(void)
+{
+	struct ast_str *conn_info = ast_str_create(128);
+	if (!conn_info) {
+		ast_log(LOG_ERROR, "Failed to allocate memory for connection string.\n");
+		return;
+	}
+
+	if (conn) {
+		PQfinish(conn);
+		conn = NULL;
+	}
+
+	ast_str_set(&conn_info, 0, "host=%s port=%s dbname=%s user=%s",
+		pghostname, pgdbport, pgdbname, pgdbuser);
+
+	if (!ast_strlen_zero(pgappname)) {
+		ast_str_append(&conn_info, 0, " application_name=%s", pgappname);
+	}
+
+	if (!ast_strlen_zero(pgpassword)) {
+		ast_str_append(&conn_info, 0, " password=%s", pgpassword);
+	}
+
+	conn = PQconnectdb(ast_str_buffer(conn_info));
+	ast_free(conn_info);
+}
+
 static int pgsql_log(struct ast_cdr *cdr)
 {
 	struct ast_tm tm;
@@ -183,7 +221,8 @@
 	ast_mutex_lock(&pgsql_lock);
 
 	if ((!connected) && pghostname && pgdbuser && pgpassword && pgdbname) {
-		conn = PQsetdbLogin(pghostname, pgdbport, NULL, NULL, pgdbname, pgdbuser, pgpassword);
+		pgsql_reconnect();
+
 		if (PQstatus(conn) != CONNECTION_BAD) {
 			connected = 1;
 			connect_time = time(NULL);
@@ -441,12 +480,15 @@
 
 	ast_cli_unregister_multiple(cdr_pgsql_status_cli, ARRAY_LEN(cdr_pgsql_status_cli));
 
-	PQfinish(conn);
-
+	if (conn) {
+		PQfinish(conn);
+		conn = NULL;
+	}
 	ast_free(pghostname);
 	ast_free(pgdbname);
 	ast_free(pgdbuser);
 	ast_free(pgpassword);
+	ast_free(pgappname);
 	ast_free(pgdbport);
 	ast_free(table);
 	ast_free(encoding);
@@ -519,6 +561,18 @@
 		return -1;
 	}
 
+	if (!(tmp = ast_variable_retrieve(cfg, "global", "appname"))) {
+		tmp = "";
+	}
+
+	ast_free(pgappname);
+	if (!(pgappname = ast_strdup(tmp))) {
+		ast_config_destroy(cfg);
+		ast_mutex_unlock(&pgsql_lock);
+		return -1;
+	}
+
+
 	if (!(tmp = ast_variable_retrieve(cfg, "global", "password"))) {
 		ast_log(LOG_WARNING, "PostgreSQL database password not specified.  Assuming blank\n");
 		tmp = "";
@@ -590,12 +644,14 @@
 		ast_debug(1, "got user of %s\n", pgdbuser);
 		ast_debug(1, "got dbname of %s\n", pgdbname);
 		ast_debug(1, "got password of %s\n", pgpassword);
+		ast_debug(1, "got application name of %s\n", pgappname);
 		ast_debug(1, "got sql table name of %s\n", table);
 		ast_debug(1, "got encoding of %s\n", encoding);
 		ast_debug(1, "got timezone of %s\n", tz);
 	}
 
-	conn = PQsetdbLogin(pghostname, pgdbport, NULL, NULL, pgdbname, pgdbuser, pgpassword);
+	pgsql_reconnect();
+
 	if (PQstatus(conn) != CONNECTION_BAD) {
 		char sqlcmd[768];
 		char *fname, *ftype, *flen, *fnotnull, *fdef;
@@ -719,6 +775,8 @@
 		ast_log(LOG_ERROR, "Unable to connect to database server %s.  CALLS WILL NOT BE LOGGED!!\n", pghostname);
 		ast_log(LOG_ERROR, "Reason: %s\n", pgerror);
 		connected = 0;
+		PQfinish(conn);
+		conn = NULL;
 	}
 
 	ast_config_destroy(cfg);

Modified: team/group/media_formats-reviewed-trunk/cel/cel_pgsql.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/cel/cel_pgsql.c?view=diff&rev=418778&r1=418777&r2=418778
==============================================================================
--- team/group/media_formats-reviewed-trunk/cel/cel_pgsql.c (original)
+++ team/group/media_formats-reviewed-trunk/cel/cel_pgsql.c Wed Jul 16 09:34:16 2014
@@ -4,8 +4,8 @@
  * Copyright (C) 2008
  *
  * Steve Murphy - adapted to CEL, from:
- * Matthew D. Hardeman <mhardemn at papersoft.com> 
- * Adapted from the MySQL CDR logger originally by James Sharp 
+ * Matthew D. Hardeman <mhardemn at papersoft.com>
+ * Adapted from the MySQL CDR logger originally by James Sharp
  *
  * Modified April, 2007; Dec, 2008
  * Steve Murphy <murf at digium.com>
@@ -26,8 +26,8 @@
 
 /*! \file
  *
- * \brief PostgreSQL CEL logger 
- * 
+ * \brief PostgreSQL CEL logger
+ *
  * \author Steve Murphy <murf at digium.com>
  * PostgreSQL http://www.postgresql.org/
  *
@@ -61,7 +61,15 @@
 #define PGSQL_BACKEND_NAME "CEL PGSQL backend"
 
 static char *config = "cel_pgsql.conf";
-static char *pghostname = NULL, *pgdbname = NULL, *pgdbuser = NULL, *pgpassword = NULL, *pgdbport = NULL, *table = NULL;
+
+static char *pghostname;
+static char *pgdbname;
+static char *pgdbuser;
+static char *pgpassword;
+static char *pgappname;
+static char *pgdbport;
+static char *table;
+
 static int connected = 0;
 static int maxsize = 512, maxsize2 = 512;
 
@@ -114,6 +122,35 @@
 		} \
 	} while (0)
 
+static void pgsql_reconnect(void)
+{
+	struct ast_str *conn_info = ast_str_create(128);
+	if (!conn_info) {
+		ast_log(LOG_ERROR, "Failed to allocate memory for connection string.\n");
+		return;
+	}
+
+	if (conn) {
+		PQfinish(conn);
+		conn = NULL;
+	}
+
+	ast_str_set(&conn_info, 0, "host=%s port=%s dbname=%s user=%s",
+		pghostname, pgdbport, pgdbname, pgdbuser);
+
+	if (!ast_strlen_zero(pgappname)) {
+		ast_str_append(&conn_info, 0, " application_name=%s", pgappname);
+	}
+
+	if (!ast_strlen_zero(pgpassword)) {
+		ast_str_append(&conn_info, 0, " password=%s", pgpassword);
+	}
+
+	conn = PQconnectdb(ast_str_buffer(conn_info));
+	ast_free(conn_info);
+}
+
+
 static void pgsql_log(struct ast_event *event)
 {
 	struct ast_tm tm;
@@ -133,7 +170,7 @@
 	ast_strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
 
 	if ((!connected) && pghostname && pgdbuser && pgpassword && pgdbname) {
-		conn = PQsetdbLogin(pghostname, pgdbport, NULL, NULL, pgdbname, pgdbuser, pgpassword);
+		pgsql_reconnect();
 		if (PQstatus(conn) != CONNECTION_BAD) {
 			connected = 1;
 		} else {
@@ -368,6 +405,10 @@
 		ast_free(pgpassword);
 		pgpassword = NULL;
 	}
+	if (pgappname) {
+		ast_free(pgappname);
+		pgappname = NULL;
+	}
 	if (pgdbport) {
 		ast_free(pgdbport);
 		pgdbport = NULL;
@@ -440,6 +481,17 @@
 		ast_log(LOG_WARNING,"PostgreSQL Ran out of memory copying password info\n");
 		return AST_MODULE_LOAD_DECLINE;
 	}
+	if (!(tmp = ast_variable_retrieve(cfg, "global", "appname"))) {
+		tmp = "";
+	}
+	if (pgappname) {
+		ast_free(pgappname);
+	}
+	if (!(pgappname = ast_strdup(tmp))) {
+		ast_log(LOG_WARNING,"PostgreSQL Ran out of memory copying appname info\n");
+		return AST_MODULE_LOAD_DECLINE;
+	}
+
 	if (!(tmp = ast_variable_retrieve(cfg,"global","port"))) {
 		ast_log(LOG_WARNING,"PostgreSQL database port not specified.  Using default 5432.\n");
 		tmp = "5432";
@@ -478,7 +530,7 @@
 			cel_show_user_def ? "Yes" : "No");
 	}
 
-	conn = PQsetdbLogin(pghostname, pgdbport, NULL, NULL, pgdbname, pgdbuser, pgpassword);
+	pgsql_reconnect();
 	if (PQstatus(conn) != CONNECTION_BAD) {
 		char sqlcmd[512];
 		char *fname, *ftype, *flen, *fnotnull, *fdef;
@@ -540,6 +592,8 @@
 		ast_log(LOG_ERROR, "cel_pgsql: Unable to connect to database server %s.  CALLS WILL NOT BE LOGGED!!\n", pghostname);
 		ast_log(LOG_ERROR, "cel_pgsql: Reason: %s\n", pgerror);
 		connected = 0;
+		PQfinish(conn);
+		conn = NULL;
 	}
 	return AST_MODULE_LOAD_SUCCESS;
 }

Modified: team/group/media_formats-reviewed-trunk/channels/chan_pjsip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/channels/chan_pjsip.c?view=diff&rev=418778&r1=418777&r2=418778
==============================================================================
--- team/group/media_formats-reviewed-trunk/channels/chan_pjsip.c (original)
+++ team/group/media_formats-reviewed-trunk/channels/chan_pjsip.c Wed Jul 16 09:34:16 2014
@@ -366,13 +366,12 @@
 	if (!(pvt = ao2_alloc(sizeof(*pvt), chan_pjsip_pvt_dtor))) {
 		return NULL;
 	}
-
 	caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
 	if (!caps) {
 		return NULL;
 	}
 
-	if (!(chan = ast_channel_alloc(1, state, S_OR(session->id.number.str, ""), S_OR(session->id.name.str, ""), "", "", "", assignedids, requestor, 0, "PJSIP/%s-%08x", ast_sorcery_object_get_id(session->endpoint),
+	if (!(chan = ast_channel_alloc(1, state, S_OR(session->id.number.str, ""), S_OR(session->id.name.str, ""), session->endpoint->accountcode, "", "", assignedids, requestor, 0, "PJSIP/%s-%08x", ast_sorcery_object_get_id(session->endpoint),
 		(unsigned)ast_atomic_fetchadd_int((int *)&chan_idx, +1)))) {
 		ao2_ref(caps, -1);
 		return NULL;

Modified: team/group/media_formats-reviewed-trunk/configs/cdr_pgsql.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/configs/cdr_pgsql.conf.sample?view=diff&rev=418778&r1=418777&r2=418778
==============================================================================
--- team/group/media_formats-reviewed-trunk/configs/cdr_pgsql.conf.sample (original)
+++ team/group/media_formats-reviewed-trunk/configs/cdr_pgsql.conf.sample Wed Jul 16 09:34:16 2014
@@ -10,6 +10,7 @@
 ;dbname=asterisk
 ;password=password
 ;user=postgres
-;table=cdr		;SQL table where CDRs will be inserted
-;encoding=LATIN9	; Encoding of logged characters in Asterisk
-;timezone=UTC		; Uncomment if you want datetime fields in UTC/GMT
+;appname=asterisk    ; Postgres application_name support (optional). Whitespace not allowed.
+;table=cdr           ; SQL table where CDRs will be inserted
+;encoding=LATIN9     ; Encoding of logged characters in Asterisk
+;timezone=UTC        ; Uncomment if you want datetime fields in UTC/GMT

Modified: team/group/media_formats-reviewed-trunk/configs/cel_pgsql.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/configs/cel_pgsql.conf.sample?view=diff&rev=418778&r1=418777&r2=418778
==============================================================================
--- team/group/media_formats-reviewed-trunk/configs/cel_pgsql.conf.sample (original)
+++ team/group/media_formats-reviewed-trunk/configs/cel_pgsql.conf.sample Wed Jul 16 09:34:16 2014
@@ -64,4 +64,5 @@
 ;dbname=asterisk
 ;password=password
 ;user=postgres
-;table=cel		;SQL table where CEL's will be inserted
+;table=cel          ; SQL table where CEL's will be inserted
+;appname=asterisk   ; Postgres application_name support (optional). Whitespace not allowed.

Modified: team/group/media_formats-reviewed-trunk/configs/pjsip.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/configs/pjsip.conf.sample?view=diff&rev=418778&r1=418777&r2=418778
==============================================================================
--- team/group/media_formats-reviewed-trunk/configs/pjsip.conf.sample (original)
+++ team/group/media_formats-reviewed-trunk/configs/pjsip.conf.sample Wed Jul 16 09:34:16 2014
@@ -435,6 +435,8 @@
 ;  SYNOPSIS: Endpoint
 ;100rel=yes     ; Allow support for RFC3262 provisional ACK tags (default:
                 ; "yes")
+;accountcode=foo        ; Set a default account code for channels created for
+                        ; this endpoint
 ;aggregate_mwi=yes      ;  (default: "yes")
 ;allow= ; Media Codec s to allow (default: "")
 ;aors=  ; AoR s to be used with the endpoint (default: "")

Modified: team/group/media_formats-reviewed-trunk/configs/res_pgsql.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/configs/res_pgsql.conf.sample?view=diff&rev=418778&r1=418777&r2=418778
==============================================================================
--- team/group/media_formats-reviewed-trunk/configs/res_pgsql.conf.sample (original)
+++ team/group/media_formats-reviewed-trunk/configs/res_pgsql.conf.sample Wed Jul 16 09:34:16 2014
@@ -12,12 +12,13 @@
 dbname=asterisk
 dbuser=asterisk
 dbpass=password
+;dbappname=asterisk    ; Postgres application_name support (optional). Whitespace not allowed.
 ;
 ; dbsock is specified as the directory where the socket file may be found. The
 ; actual socket is constructed as a combination of dbsock and dbport.  For
 ; example, the values of '/tmp' and '5432', respectively, will specify a socket
 ; file of '/tmp/.s.PGSQL.5432'.
-; 
+;
 ;dbsock=/tmp
 ;
 ; requirements - At startup, each realtime family will make requirements

Modified: team/group/media_formats-reviewed-trunk/include/asterisk/res_pjsip.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/include/asterisk/res_pjsip.h?view=diff&rev=418778&r1=418777&r2=418778
==============================================================================
--- team/group/media_formats-reviewed-trunk/include/asterisk/res_pjsip.h (original)
+++ team/group/media_formats-reviewed-trunk/include/asterisk/res_pjsip.h Wed Jul 16 09:34:16 2014
@@ -568,6 +568,8 @@
 		AST_STRING_FIELD(fromdomain);
 		/*! Context to route incoming MESSAGE requests to */
 		AST_STRING_FIELD(message_context);
+		/*! Accountcode to auto-set on channels */
+		AST_STRING_FIELD(accountcode);
 	);
 	/*! Configuration for extensions */
 	struct ast_sip_endpoint_extensions extensions;

Modified: team/group/media_formats-reviewed-trunk/res/res_config_pgsql.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/res/res_config_pgsql.c?view=diff&rev=418778&r1=418777&r2=418778
==============================================================================
--- team/group/media_formats-reviewed-trunk/res/res_config_pgsql.c (original)
+++ team/group/media_formats-reviewed-trunk/res/res_config_pgsql.c Wed Jul 16 09:34:16 2014
@@ -79,6 +79,7 @@
 static char dbuser[MAX_DB_OPTION_SIZE] = "";
 static char dbpass[MAX_DB_OPTION_SIZE] = "";
 static char dbname[MAX_DB_OPTION_SIZE] = "";
+static char dbappname[MAX_DB_OPTION_SIZE] = "";
 static char dbsock[MAX_DB_OPTION_SIZE] = "";
 static int dbport = 5432;
 static time_t connect_time = 0;
@@ -1436,6 +1437,12 @@
 		dbport = atoi(s);
 	}
 
+	if (!(s = ast_variable_retrieve(config, "general", "dbappname"))) {
+		dbappname[0] = '\0';
+	} else {
+		ast_copy_string(dbappname, s, sizeof(dbappname));
+	}
+
 	if (!ast_strlen_zero(dbhost)) {
 		/* No socket needed */
 	} else if (!(s = ast_variable_retrieve(config, "general", "dbsock"))) {
@@ -1499,18 +1506,27 @@
 
 	/* DB password can legitimately be 0-length */
 	if ((!pgsqlConn) && (!ast_strlen_zero(dbhost) || !ast_strlen_zero(dbsock)) && !ast_strlen_zero(dbuser) && !ast_strlen_zero(my_database)) {
-		struct ast_str *connInfo = ast_str_create(128);
-
-		ast_str_set(&connInfo, 0, "host=%s port=%d dbname=%s user=%s",
+		struct ast_str *conn_info = ast_str_create(128);
+
+		if (!conn_info) {
+			ast_log(LOG_ERROR, "PostgreSQL RealTime: Failed to allocate memory for connection string.\n");
+			return 0;
+		}
+
+		ast_str_set(&conn_info, 0, "host=%s port=%d dbname=%s user=%s",
 			S_OR(dbhost, dbsock), dbport, my_database, dbuser);
-		if (!ast_strlen_zero(dbpass))
-			ast_str_append(&connInfo, 0, " password=%s", dbpass);
-
-		ast_debug(1, "%u connInfo=%s\n", (unsigned int)ast_str_size(connInfo), ast_str_buffer(connInfo));
-		pgsqlConn = PQconnectdb(ast_str_buffer(connInfo));
-		ast_debug(1, "%u connInfo=%s\n", (unsigned int)ast_str_size(connInfo), ast_str_buffer(connInfo));
-		ast_free(connInfo);
-		connInfo = NULL;
+
+		if (!ast_strlen_zero(dbappname)) {
+			ast_str_append(&conn_info, 0, " application_name=%s", dbappname);
+		}
+
+		if (!ast_strlen_zero(dbpass)) {
+			ast_str_append(&conn_info, 0, " password=%s", dbpass);
+		}
+
+		pgsqlConn = PQconnectdb(ast_str_buffer(conn_info));
+		ast_free(conn_info);
+		conn_info = NULL;
 
 		ast_debug(1, "pgsqlConn=%p\n", pgsqlConn);
 		if (pgsqlConn && PQstatus(pgsqlConn) == CONNECTION_OK) {

Modified: team/group/media_formats-reviewed-trunk/res/res_pjsip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/res/res_pjsip.c?view=diff&rev=418778&r1=418777&r2=418778
==============================================================================
--- team/group/media_formats-reviewed-trunk/res/res_pjsip.c (original)
+++ team/group/media_formats-reviewed-trunk/res/res_pjsip.c Wed Jul 16 09:34:16 2014
@@ -713,6 +713,13 @@
 						If specified, incoming MESSAGE requests will be routed to the indicated
 						dialplan context. If no <replaceable>message_context</replaceable> is
 						specified, then the <replaceable>context</replaceable> setting is used.
+					</para></description>
+				</configOption>
+				<configOption name="accountcode">
+					<synopsis>An accountcode to set automatically on any channels created for this endpoint.</synopsis>
+					<description><para>
+						If specified, any channel created for this endpoint will automatically
+						have this accountcode set on it.
 					</para></description>
 				</configOption>
 			</configObject>

Modified: team/group/media_formats-reviewed-trunk/res/res_pjsip/pjsip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/res/res_pjsip/pjsip_configuration.c?view=diff&rev=418778&r1=418777&r2=418778
==============================================================================
--- team/group/media_formats-reviewed-trunk/res/res_pjsip/pjsip_configuration.c (original)
+++ team/group/media_formats-reviewed-trunk/res/res_pjsip/pjsip_configuration.c Wed Jul 16 09:34:16 2014
@@ -1730,6 +1730,7 @@
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "redirect_method", "user", redirect_handler, NULL, NULL, 0, 0);
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "set_var", "", set_var_handler, set_var_to_str, set_var_to_vl, 0, 0);
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "message_context", "", OPT_STRINGFIELD_T, 1, STRFLDSET(struct ast_sip_endpoint, message_context));
+	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "accountcode", "", OPT_STRINGFIELD_T, 1, STRFLDSET(struct ast_sip_endpoint, accountcode));
 
 	if (ast_sip_initialize_sorcery_transport()) {
 		ast_log(LOG_ERROR, "Failed to register SIP transport support with sorcery\n");




More information about the svn-commits mailing list