]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix some stuff and add set_user func
authorAnthony Minessale <anthony.minessale@gmail.com>
Tue, 13 Nov 2007 19:58:44 +0000 (19:58 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Tue, 13 Nov 2007 19:58:44 +0000 (19:58 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6239 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/applications/mod_dptools/mod_dptools.c
src/mod/applications/mod_limit/mod_limit.c
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_reg.c

index e495943e544e903226de5be3f0ef8a7b8aae186c..ef2c488c0d1372dd551554338521d59f1555ad5a 100644 (file)
@@ -86,6 +86,67 @@ SWITCH_STANDARD_APP(exe_function)
        }
 }
 
+
+#define SET_USER_SYNTAX "<user>@<domain>"
+SWITCH_STANDARD_APP(set_user_function)
+{
+       switch_xml_t x_domain, xml = NULL, x_user, x_param, x_params;   
+       char *user, *mailbox, *domain;
+       switch_channel_t *channel;
+
+       channel = switch_core_session_get_channel(session);
+       assert(channel != NULL);
+
+       if (switch_strlen_zero(data)) {
+               goto error;
+       }
+
+       user = switch_core_session_strdup(session, data);
+
+       if (!(domain = strchr(user, '@'))) {
+               goto error;
+       }
+
+       *domain++ = '\0';
+       
+       if (switch_xml_locate_user(user, domain, NULL, &xml, &x_domain, &x_user, NULL) != SWITCH_STATUS_SUCCESS) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", user, domain);
+               goto done;
+       }
+
+       if ((mailbox = (char *)switch_xml_attr(x_user, "mailbox"))) {
+               switch_channel_set_variable(channel, "mailbox", mailbox);
+       }
+       
+       if ((x_params = switch_xml_child(x_user, "variables"))) {
+               for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) {
+                       const char *var = switch_xml_attr(x_param, "name");
+                       const char *val = switch_xml_attr(x_param, "value");
+                       
+                       if (var && val) {
+                               switch_channel_set_variable(channel, var, val);
+                       }
+               }
+       }
+
+       switch_channel_set_variable(channel, "user_name", user);
+       switch_channel_set_variable(channel, "domain_name", domain);
+
+       goto done;
+
+ error:
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No user@domain specified.\n");
+
+ done:
+       
+       if (xml) {
+               switch_xml_free(xml);
+       }
+
+
+}
+
+
 SWITCH_STANDARD_APP(ring_ready_function)
 {
        switch_channel_t *channel;
@@ -1390,6 +1451,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load)
        SWITCH_ADD_APP(app_interface, "sched_broadcast", SCHED_BROADCAST_DESCR, SCHED_BROADCAST_DESCR, sched_broadcast_function, "[+]<time> <path> [aleg|bleg|both]", SAF_SUPPORT_NOMEDIA);
        SWITCH_ADD_APP(app_interface, "sched_transfer", SCHED_TRANSF_DESCR, SCHED_TRANSF_DESCR, sched_transfer_function, "[+]<time> <extension> <dialplan> <context>", SAF_SUPPORT_NOMEDIA);
        SWITCH_ADD_APP(app_interface, "execute_extension", "Execute an extension", "Execute an extension", exe_function, EXE_SYNTAX, SAF_SUPPORT_NOMEDIA);
+       SWITCH_ADD_APP(app_interface, "set_user", "Set a User", "Set a User", set_user_function, SET_USER_SYNTAX, SAF_SUPPORT_NOMEDIA);
        SWITCH_ADD_APP(app_interface, "stop_dtmf", "stop inband dtmf", "Stop detecting inband dtmf.", stop_dtmf_session_function, "", SAF_NONE);
        SWITCH_ADD_APP(app_interface, "start_dtmf", "Detect dtmf", "Detect inband dtmf on the session", dtmf_session_function, "", SAF_NONE);
        SWITCH_ADD_APP(app_interface, "stop_dtmf_generate", "stop inband dtmf generation", "Stop generating inband dtmf.", 
index 4ef4eb03f1640c99755d014bc06b7b36de374d68..c65a6dd2a2351f97e031a1f41d4eab62958c4a12 100644 (file)
@@ -390,14 +390,14 @@ SWITCH_STANDARD_API(db_api_function)
 }
 
 
-#define DB_USAGE "[add|del]/<realm>/<key>/<val>"
+#define DB_USAGE "[insert|delete]/<realm>/<key>/<val>"
 #define DB_DESC "save data"
 
 SWITCH_STANDARD_APP(db_function)
 {
     switch_channel_t *channel;
     int argc = 0;
-    char *argv[3] = { 0 };
+    char *argv[4] = { 0 };
     char *mydata = NULL;
     char *sql = NULL;
 
@@ -408,15 +408,15 @@ SWITCH_STANDARD_APP(db_function)
         mydata = switch_core_session_strdup(session, data);
         argc = switch_separate_string(mydata, '/', argv, (sizeof(argv) / sizeof(argv[0])));
     }
-
+    printf("WTF [%s] %d\n", argv[0], argc);
     if (argc < 4) {
         goto error;
     }
-
     
-    if (!strcasecmp(argv[0], "add")) {
+    
+    if (!strcasecmp(argv[0], "insert")) {
         sql = switch_mprintf("insert into db_data values('%q','%q','%q','%q');", globals.hostname, argv[1], argv[2], argv[3]);
-    } else if (!strcasecmp(argv[0], "del")) {
+    } else if (!strcasecmp(argv[0], "delete")) {
         sql = switch_mprintf("delete from db_data where realm='%q' and data_key='%q'", argv[1], argv[2]);
     }
 
@@ -454,7 +454,7 @@ SWITCH_STANDARD_API(group_api_function)
         goto error;
     }
 
-    if (!strcasecmp(argv[0], "add")) {
+    if (!strcasecmp(argv[0], "insert")) {
         if (argc < 3) {
             goto error;
         }
@@ -468,7 +468,7 @@ SWITCH_STANDARD_API(group_api_function)
         switch_safe_free(sql);
         stream->write_function(stream, "+OK");
         goto done;
-    } else if (!strcasecmp(argv[0], "del")) {
+    } else if (!strcasecmp(argv[0], "delete")) {
         if (argc < 3) {
             goto error;
         }
@@ -515,7 +515,7 @@ SWITCH_STANDARD_API(group_api_function)
     
 }
 
-#define GROUP_USAGE "[add|del]:<group name>:<val>"
+#define GROUP_USAGE "[insert|delete]:<group name>:<val>"
 #define GROUP_DESC "save data"
 
 SWITCH_STANDARD_APP(group_function)
@@ -539,12 +539,12 @@ SWITCH_STANDARD_APP(group_function)
         return;
     }
 
-    if (!strcasecmp(argv[0], "add")) {
+    if (!strcasecmp(argv[0], "insert")) {
         sql = switch_mprintf("insert into group_data values('%q','%q','%q');", globals.hostname, argv[1], argv[2]);
         assert(sql);
         limit_execute_sql(sql, globals.mutex);
         switch_safe_free(sql);
-    } else if (!strcasecmp(argv[0], "del")) {
+    } else if (!strcasecmp(argv[0], "delete")) {
         sql = switch_mprintf("delete from group_data where groupname='%q' and url='%q';", argv[1], argv[2]);
         assert(sql);
         limit_execute_sql(sql, globals.mutex);
@@ -643,11 +643,11 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_limit_load)
     *module_interface = switch_loadable_module_create_module_interface(pool, modname);
 
        SWITCH_ADD_APP(app_interface, "limit", "Limit", LIMIT_DESC, limit_function, LIMIT_USAGE, SAF_NONE);
-       SWITCH_ADD_APP(app_interface, "db_insert", "Insert to the db", DB_DESC, db_function, DB_USAGE, SAF_NONE);
+       SWITCH_ADD_APP(app_interface, "db", "Insert to the db", DB_DESC, db_function, DB_USAGE, SAF_NONE);
        SWITCH_ADD_APP(app_interface, "group", "Manage a group", GROUP_DESC, group_function, GROUP_USAGE, SAF_NONE);
 
        SWITCH_ADD_API(commands_api_interface, "db", "db get/set", db_api_function, "[get|set]/<realm>/<key>/<value>");
-       SWITCH_ADD_API(commands_api_interface, "group", "group [add|del|call]", group_api_function, "[add|del|call] <group name> <url>");
+       SWITCH_ADD_API(commands_api_interface, "group", "group [insert|delete|call]", group_api_function, "[insert|delete|call] <group name> <url>");
 
     /* indicate that the module should continue to be loaded */
     return SWITCH_STATUS_SUCCESS;
index 030e4fc98eb8a44bcb33f3d019f94a1ae215a36b..ac3f0b29d3881fed98f5f72b14d8eb52cbacb5c1 100644 (file)
@@ -1994,8 +1994,6 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
                
                
                if (!switch_strlen_zero(from_user)) {
-                       switch_channel_set_variable(channel, "sip_mailbox", from_user);
-
                        if (*from_user == '+') {
                                switch_channel_set_variable(channel, "sip_from_user_stripped", (const char *) (from_user + 1));
                        } else {
index a1d83dbfd4f314eee4dadf3bfcc28609e19517dd..92ed4b334186753823f1552ca5a7176d99c1f080 100644 (file)
@@ -981,6 +981,9 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
                        switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, "sip_mailbox", "%s", mailbox);
                        switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, "sip_auth_username", "%s", username);
                        switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, "sip_auth_realm", "%s", realm);
+                       switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, "mailbox", "%s", mailbox);
+                       switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, "user_name", "%s", username);
+                       switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, "domain_name", "%s", realm);
                        
                        if ((xparams = switch_xml_child(user, "variables"))) {
                                for (param = switch_xml_child(xparams, "variable"); param; param = param->next) {