]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7509: add userVariables parser to initial connection all variables set in this...
authorAnthony Minessale <anthm@freeswitch.org>
Sat, 25 Apr 2015 15:57:09 +0000 (10:57 -0500)
committerMichael Jerris <mike@jerris.com>
Thu, 28 May 2015 17:47:25 +0000 (12:47 -0500)
html5/verto/js/src/jquery.jsonrpcclient.js
html5/verto/js/src/jquery.verto.js
src/mod/endpoints/mod_verto/mod_verto.c
src/mod/endpoints/mod_verto/mod_verto.h

index 94222159217ec6a5aeb261ede8138ea539947828..a02885e802122c4e4a83183145f95dfefb982d34 100644 (file)
     $.JsonRpcClient = function(options) {
         var self = this;
         this.options = $.extend({
-            ajaxUrl     : null,
-            socketUrl   : null, ///< The ws-url for default getSocket.
-            onmessage   : null, ///< Other onmessage-handler.
-            login       : null, /// auth login
-            passwd      : null, /// auth passwd
-            sessid : null,
-           loginParams : null,
-            getSocket   : function(onmessage_cb) { return self._getSocket(onmessage_cb); }
+            ajaxUrl       : null,
+            socketUrl     : null, ///< The ws-url for default getSocket.
+            onmessage     : null, ///< Other onmessage-handler.
+            login         : null, /// auth login
+            passwd        : null, /// auth passwd
+            sessid        : null,
+           loginParams   : null,
+           userVariables : null,
+            getSocket     : function(onmessage_cb) { return self._getSocket(onmessage_cb); }
         }, options);
 
         self.ws_cnt = 0;
         self.options.login = params.login;
         self.options.passwd = params.passwd;
        self.options.loginParams = params.loginParams;
+       self.options.userVariables = params.userVariables;
     };
 
     $.JsonRpcClient.prototype.connectSocket = function(onmessage_cb) {
                     if (!self.authing && response.error.code == -32000 && self.options.login && self.options.passwd) {
                         self.authing = true;
 
-                        this.call("login", { login: self.options.login, passwd: self.options.passwd, loginParams: self.options.loginParams},
+                        this.call("login", { login: self.options.login, passwd: self.options.passwd, loginParams: self.options.loginParams,
+                                            userVariables: self.options.userVariables},
                             this._ws_callbacks[response.id].request_obj.method == "login" ?
                             function(e) {
                                 self.authing = false;
index 345012026ebe99ce73ddeac53c94cc0a2d827c3c..0777fc12b77a4814ee9941ee5b725f0892b5ad77 100644 (file)
@@ -76,6 +76,7 @@
             videoParams: {},
             audioParams: {},
            loginParams: {},
+           userVariables: {},
             iceServers: false,
             ringSleep: 6000
         }, options);
@@ -94,6 +95,7 @@
             passwd: verto.options.passwd,
             socketUrl: verto.options.socketUrl,
            loginParams: verto.options.loginParams,
+           userVariables: verto.options.userVariables,
             sessid: verto.sessid,
             onmessage: function(e) {
                 return verto.handleMessage(e.eventData);
index 4be239842db7f2e707837841494c66bb2cf102f6..1d422a53ad6d673ccfe9a287155ff1f6e5f8e89e 100644 (file)
@@ -885,7 +885,7 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char *
        switch_bool_t r = SWITCH_FALSE;
        const char *passwd = NULL;
        const char *login = NULL;
-       cJSON *login_params = NULL;
+       cJSON *json_ptr = NULL;
 
        if (!params) {
                *code = CODE_AUTH_FAILED;
@@ -945,10 +945,10 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char *
                switch_event_create(&req_params, SWITCH_EVENT_REQUEST_PARAMS);
                switch_assert(req_params);
 
-               if ((login_params = cJSON_GetObjectItem(params, "loginParams"))) {
+               if ((json_ptr = cJSON_GetObjectItem(params, "loginParams"))) {
                        cJSON * i;
-
-                       for(i = login_params->child; i; i = i->next) {
+                       
+                       for(i = json_ptr->child; i; i = i->next) {
                                if (i->type == cJSON_True) {
                                        switch_event_add_header_string(req_params, SWITCH_STACK_BOTTOM, i->string, "true");
                                } else if (i->type == cJSON_False) {
@@ -959,6 +959,21 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char *
                        }
                }
 
+
+               if ((json_ptr = cJSON_GetObjectItem(params, "userVariables"))) {
+                       cJSON * i;
+                       
+                       for(i = json_ptr->child; i; i = i->next) {
+                               if (i->type == cJSON_True) {
+                                       switch_event_add_header_string(jsock->user_vars, SWITCH_STACK_BOTTOM, i->string, "true");
+                               } else if (i->type == cJSON_False) {
+                                       switch_event_add_header_string(jsock->user_vars, SWITCH_STACK_BOTTOM, i->string, "false");
+                               } else if (!zstr(i->string) && !zstr(i->valuestring)) {
+                                       switch_event_add_header_string(jsock->user_vars, SWITCH_STACK_BOTTOM, i->string, i->valuestring);
+                               }
+                       }
+               }
+
                switch_event_add_header_string(req_params, SWITCH_STACK_BOTTOM, "action", "jsonrpc-authenticate");
                
                if (switch_xml_locate_user_merged("id", id, domain, NULL, &x_user, req_params) != SWITCH_STATUS_SUCCESS && !jsock->profile->blind_reg) {
@@ -1884,6 +1899,7 @@ static void *SWITCH_THREAD_FUNC client_thread(switch_thread_t *thread, void *obj
 
        switch_event_create(&jsock->params, SWITCH_EVENT_CHANNEL_DATA);
        switch_event_create(&jsock->vars, SWITCH_EVENT_CHANNEL_DATA);
+       switch_event_create(&jsock->user_vars, SWITCH_EVENT_CHANNEL_DATA);
 
 
        add_jsock(jsock);
@@ -1902,6 +1918,7 @@ static void *SWITCH_THREAD_FUNC client_thread(switch_thread_t *thread, void *obj
 
        switch_event_destroy(&jsock->params);
        switch_event_destroy(&jsock->vars);
+       switch_event_destroy(&jsock->user_vars);
 
        if (jsock->client_socket > -1) {
                close_socket(&jsock->client_socket);
@@ -2062,14 +2079,19 @@ static switch_status_t verto_connect(switch_core_session_t *session, const char
         cJSON *msg = NULL;
                const char *var = NULL;
                switch_caller_profile_t *caller_profile = switch_channel_get_caller_profile(tech_pvt->channel);
+               switch_event_header_t *hp;
 
-               DUMP_EVENT(jsock->params);
+               //DUMP_EVENT(jsock->params);
 
                switch_channel_set_variable(tech_pvt->channel, "verto_user", jsock->uid);
                switch_channel_set_variable(tech_pvt->channel, "presence_id", jsock->uid);
                switch_channel_set_variable(tech_pvt->channel, "chat_proto", VERTO_CHAT_PROTO);
                switch_channel_set_variable(tech_pvt->channel, "verto_host", jsock->domain);
 
+               for (hp = jsock->user_vars->headers; hp; hp = hp->next) {
+                       switch_channel_set_variable(tech_pvt->channel, hp->name, hp->value);
+               }
+               
                if ((var = switch_event_get_header(jsock->params, "caller-id-name"))) {
                        caller_profile->callee_id_name = switch_core_strdup(caller_profile->pool, var);
                }
@@ -3235,6 +3257,7 @@ static switch_bool_t verto__invite_func(const char *method, cJSON *params, jsock
        char name[512];
        const char *var, *destination_number, *call_id = NULL, *sdp = NULL, *bandwidth = NULL, 
                *caller_id_name = NULL, *caller_id_number = NULL, *remote_caller_id_name = NULL, *remote_caller_id_number = NULL,*context = NULL;
+       switch_event_header_t *hp;
        
        *response = obj;
 
@@ -3365,6 +3388,12 @@ static switch_bool_t verto__invite_func(const char *method, cJSON *params, jsock
                
        }
 
+
+       for (hp = jsock->user_vars->headers; hp; hp = hp->next) {
+               switch_channel_set_variable(channel, hp->name, hp->value);
+       }
+
+
        switch_channel_set_profile_var(channel, "callee_id_name", remote_caller_id_name);
        switch_channel_set_profile_var(channel, "callee_id_number", remote_caller_id_number);
 
index beb26ab072a2537ef88ec145afa1310d0e198731..11614926a6dfd20e4941739ed6258e844d83ae61 100644 (file)
@@ -141,6 +141,8 @@ struct jsock_s {
        switch_event_t *params;
        switch_event_t *vars;
 
+       switch_event_t *user_vars;
+
        switch_queue_t *event_queue;
        int lost_events;
        int ready;