From c4ae4e394db060a2e77f2f53db2a28410e12571e Mon Sep 17 00:00:00 2001
From: Anthony Minessale <anthony.minessale@gmail.com>
Date: Wed, 10 Oct 2007 23:38:48 +0000
Subject: [PATCH] make xtra_params arg instead of just profile name

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5838 d0543943-73ff-0310-b7d9-9358b9ac24b2
---
 src/include/switch_xml.h                |  2 +-
 src/mod/endpoints/mod_sofia/sofia_reg.c |  7 +++++--
 src/switch_xml.c                        | 10 ++++++++--
 3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/include/switch_xml.h b/src/include/switch_xml.h
index 060edfb7bc..74d0523b59 100644
--- a/src/include/switch_xml.h
+++ b/src/include/switch_xml.h
@@ -324,7 +324,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate_user(char *user_name, char *do
 													   switch_xml_t *root,
 													   switch_xml_t *domain,
 													   switch_xml_t *user,
-													   char *profile_name);
+													   char *xtra_params);
 
 ///\brief open a config in the core registry
 ///\param file_path the name of the config section e.g. modules.conf
diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c
index 60c8af3dc5..6673443560 100644
--- a/src/mod/endpoints/mod_sofia/sofia_reg.c
+++ b/src/mod/endpoints/mod_sofia/sofia_reg.c
@@ -749,7 +749,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
 	char *sql;
 	switch_xml_t domain, xml = NULL, user, param, xparams;	
 	char hexdigest[2 * SU_MD5_DIGEST_SIZE + 1] = "";
-	
+	char *pbuf = NULL;
 	username = realm = nonce = uri = qop = cnonce = nc = response = NULL;
 	
 	if (authorization->au_params) {
@@ -816,7 +816,9 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
 		free(sql);
 	} 
 	
-	if (switch_xml_locate_user(username, realm, ip, &xml, &domain, &user, profile->name) != SWITCH_STATUS_SUCCESS) {
+	pbuf = switch_mprintf("profile=%s", profile->name);
+
+	if (switch_xml_locate_user(username, realm, ip, &xml, &domain, &user, pbuf) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", username, realm);
 		ret = AUTH_FORBIDDEN;
 		goto end;
@@ -964,6 +966,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
 	if (xml) {
 		switch_xml_free(xml);
 	}
+	switch_safe_free(pbuf);
 	switch_safe_free(input);
 	switch_safe_free(input2);
 	switch_safe_free(username);
diff --git a/src/switch_xml.c b/src/switch_xml.c
index 24f4378c8d..e417918895 100644
--- a/src/switch_xml.c
+++ b/src/switch_xml.c
@@ -1246,7 +1246,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate_user(char *user_name, char *do
 													   switch_xml_t *root,
 													   switch_xml_t *domain,
 													   switch_xml_t *user,
-													   char *profile_name)
+													   char *xtra_params)
 {
 	char params[1024] = "";
 	switch_status_t status;
@@ -1254,7 +1254,13 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate_user(char *user_name, char *do
 	*user = NULL;
 	*domain = NULL;
 	
-	snprintf(params, sizeof(params), "user=%s&domain=%s&ip=%s&profile=%s", switch_str_nil(user_name), switch_str_nil(domain_name), switch_str_nil(ip), profile_name);
+	if (!switch_strlen_zero(xtra_params)) {
+		snprintf(params, sizeof(params), "user=%s&domain=%s&ip=%s&%s", 
+				 switch_str_nil(user_name), switch_str_nil(domain_name), switch_str_nil(ip), xtra_params);
+	} else {
+		snprintf(params, sizeof(params), "user=%s&domain=%s&ip=%s", 
+				 switch_str_nil(user_name), switch_str_nil(domain_name), switch_str_nil(ip));
+	}
 	if ((status = switch_xml_locate_domain(domain_name, params, root, domain)) != SWITCH_STATUS_SUCCESS) {
 		return status;
 	}