]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
move param gen func to the core
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 16 Nov 2007 19:11:16 +0000 (19:11 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 16 Nov 2007 19:11:16 +0000 (19:11 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6310 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_channel.h
src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c
src/switch_channel.c

index 1846d819016e0a0b517216faa20c01b6be26a014..3c36a57cf9f2767ccf41a1b38d873de77d0c66c3 100644 (file)
@@ -456,6 +456,7 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel_t *channel, sw
   \note it's necessary to test if the return val is the same as the input and free the string if it is not.
 */
 SWITCH_DECLARE(char *) switch_channel_expand_variables(switch_channel_t *channel, char *in);
+SWITCH_DECLARE(char *) switch_channel_build_param_string(switch_channel_t *channel, switch_caller_profile_t *caller_profile);
 
 /** @} */
 
index 0d848e127cb498deb2d4ce5d5153a20eb51efbb2..f368244eae2b1b5715839c059d40f069a60a89bf 100644 (file)
@@ -181,102 +181,15 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
 static switch_status_t dialplan_xml_locate(switch_core_session_t *session, switch_caller_profile_t *caller_profile, switch_xml_t * root,
                                                                                   switch_xml_t * node)
 {
-       switch_status_t status = SWITCH_STATUS_GENERR;
+       char *data;
        switch_channel_t *channel;
-       switch_stream_handle_t stream = { 0 };
-       switch_size_t encode_len = 1024, new_len = 0;
-       char *encode_buf = NULL;
-       const char *prof[12] = { 0 }, *prof_names[12] = {0};
-       char *e = NULL;
-       switch_event_header_t *hi;
-       uint32_t x = 0;
+       switch_status_t status = SWITCH_STATUS_GENERR;
 
        channel = switch_core_session_get_channel(session);
+       data = switch_channel_build_param_string(channel, caller_profile);
 
-       SWITCH_STANDARD_STREAM(stream);
-
-       if (!(encode_buf = malloc(encode_len))) {
-               goto done;
-       }
-
-       prof[0] = caller_profile->context;
-       prof[1] = caller_profile->destination_number;
-       prof[2] = caller_profile->caller_id_name;
-       prof[3] = caller_profile->caller_id_number;
-       prof[4] = caller_profile->network_addr;
-       prof[5] = caller_profile->ani;
-       prof[6] = caller_profile->aniii;
-       prof[7] = caller_profile->rdnis;
-       prof[8] = caller_profile->source;
-       prof[9] = caller_profile->chan_name;
-       prof[10] = caller_profile->uuid;
-
-       prof_names[0] = "context";
-       prof_names[1] = "destination_number";
-       prof_names[2] = "caller_id_name";
-       prof_names[3] = "caller_id_number";
-       prof_names[4] = "network_addr";
-       prof_names[5] = "ani";
-       prof_names[6] = "aniii";
-       prof_names[7] = "rdnis";
-       prof_names[8] = "source";
-       prof_names[9] = "chan_name";
-       prof_names[10] = "uuid";
-
-       for (x = 0; prof[x]; x++) {
-               if (switch_strlen_zero(prof[x])) {
-                       continue;
-               }
-               new_len = (strlen(prof[x]) * 3) + 1;
-               if (encode_len < new_len) {
-                       char *tmp;
-
-                       encode_len = new_len;
-
-                       if (!(tmp = realloc(encode_buf, encode_len))) {
-                               goto done;
-                       }
-
-                       encode_buf = tmp;
-               }
-               switch_url_encode(prof[x], encode_buf, encode_len - 1);
-               stream.write_function(&stream, "%s=%s&", prof_names[x], encode_buf);
-       }
-
-       if ((hi = switch_channel_variable_first(channel))) {
-               for (; hi; hi = hi->next) {
-                       char *var = hi->name;
-                       char *val = hi->value;
-                       
-                       new_len = (strlen((char *) var) * 3) + 1;
-                       if (encode_len < new_len) {
-                               char *tmp;
-                               
-                               encode_len = new_len;
-                       
-                               tmp = realloc(encode_buf, encode_len);
-                               assert(tmp);
-                               encode_buf = tmp;
-                       }
-
-                       switch_url_encode((char *) val, encode_buf, encode_len - 1);
-                       stream.write_function(&stream, "%s=%s&", (char *) var, encode_buf);
-
-               }
-               switch_channel_variable_last(channel);
-       }
-
-       e = (char *) stream.data + (strlen((char *) stream.data) - 1);
-
-       if (e && *e == '&') {
-               *e = '\0';
-       }
-
-       status = switch_xml_locate("dialplan", NULL, NULL, NULL, root, node, stream.data);
-
-  done:
-       switch_safe_free(stream.data);
-       switch_safe_free(encode_buf);
+       status = switch_xml_locate("dialplan", NULL, NULL, NULL, root, node, data);
+       switch_safe_free(data);
        return status;
 }
 
index 1467c953a641666161a300b97a404ed030f5f3b7..649c301f01f5886b4ffac72553cabfc4a70cde38 100644 (file)
@@ -1510,6 +1510,106 @@ SWITCH_DECLARE(char *) switch_channel_expand_variables(switch_channel_t *channel
        return data;
 }
 
+SWITCH_DECLARE(char *) switch_channel_build_param_string(switch_channel_t *channel, switch_caller_profile_t *caller_profile)
+{
+       switch_stream_handle_t stream = { 0 };
+       switch_size_t encode_len = 1024, new_len = 0;
+       char *encode_buf = NULL;
+       const char *prof[12] = { 0 }, *prof_names[12] = {0};
+       char *e = NULL;
+       switch_event_header_t *hi;
+       uint32_t x = 0;
+
+       SWITCH_STANDARD_STREAM(stream);
+
+       encode_buf = malloc(encode_len);
+       assert(encode_buf);
+
+       if (!caller_profile) {
+               caller_profile = switch_channel_get_caller_profile(channel);
+       }
+
+       assert(caller_profile != NULL);
+       
+       prof[0] = caller_profile->context;
+       prof[1] = caller_profile->destination_number;
+       prof[2] = caller_profile->caller_id_name;
+       prof[3] = caller_profile->caller_id_number;
+       prof[4] = caller_profile->network_addr;
+       prof[5] = caller_profile->ani;
+       prof[6] = caller_profile->aniii;
+       prof[7] = caller_profile->rdnis;
+       prof[8] = caller_profile->source;
+       prof[9] = caller_profile->chan_name;
+       prof[10] = caller_profile->uuid;
+       
+       prof_names[0] = "context";
+       prof_names[1] = "destination_number";
+       prof_names[2] = "caller_id_name";
+       prof_names[3] = "caller_id_number";
+       prof_names[4] = "network_addr";
+       prof_names[5] = "ani";
+       prof_names[6] = "aniii";
+       prof_names[7] = "rdnis";
+       prof_names[8] = "source";
+       prof_names[9] = "chan_name";
+       prof_names[10] = "uuid";
+
+       for (x = 0; prof[x]; x++) {
+               if (switch_strlen_zero(prof[x])) {
+                       continue;
+               }
+               new_len = (strlen(prof[x]) * 3) + 1;
+               if (encode_len < new_len) {
+                       char *tmp;
+
+                       encode_len = new_len;
+
+                       if (!(tmp = realloc(encode_buf, encode_len))) {
+                               abort();
+                       }
+
+                       encode_buf = tmp;
+               }
+               switch_url_encode(prof[x], encode_buf, encode_len - 1);
+               stream.write_function(&stream, "%s=%s&", prof_names[x], encode_buf);
+       }
+
+       if ((hi = switch_channel_variable_first(channel))) {
+               for (; hi; hi = hi->next) {
+                       char *var = hi->name;
+                       char *val = hi->value;
+                       
+                       new_len = (strlen((char *) var) * 3) + 1;
+                       if (encode_len < new_len) {
+                               char *tmp;
+                               
+                               encode_len = new_len;
+                       
+                               tmp = realloc(encode_buf, encode_len);
+                               assert(tmp);
+                               encode_buf = tmp;
+                       }
+
+                       switch_url_encode((char *) val, encode_buf, encode_len - 1);
+                       stream.write_function(&stream, "%s=%s&", (char *) var, encode_buf);
+
+               }
+               switch_channel_variable_last(channel);
+       }
+
+       e = (char *) stream.data + (strlen((char *) stream.data) - 1);
+
+       if (e && *e == '&') {
+               *e = '\0';
+       }
+
+       switch_safe_free(encode_buf);
+
+       return stream.data;
+}
+
+
 /* For Emacs:
  * Local Variables:
  * mode:c