From 5ab557fd5167dbd10c3bf8ec2d7a32560269ca26 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 25 Apr 2015 10:57:09 -0500 Subject: [PATCH] FS-7509: add userVariables parser to initial connection all variables set in this obj will be set on every inbound call --- html5/verto/js/src/jquery.jsonrpcclient.js | 21 +++++++----- html5/verto/js/src/jquery.verto.js | 2 ++ src/mod/endpoints/mod_verto/mod_verto.c | 39 +++++++++++++++++++--- src/mod/endpoints/mod_verto/mod_verto.h | 2 ++ 4 files changed, 50 insertions(+), 14 deletions(-) diff --git a/html5/verto/js/src/jquery.jsonrpcclient.js b/html5/verto/js/src/jquery.jsonrpcclient.js index 9422215921..a02885e802 100644 --- a/html5/verto/js/src/jquery.jsonrpcclient.js +++ b/html5/verto/js/src/jquery.jsonrpcclient.js @@ -65,14 +65,15 @@ $.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; @@ -263,6 +264,7 @@ 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) { @@ -422,7 +424,8 @@ 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; diff --git a/html5/verto/js/src/jquery.verto.js b/html5/verto/js/src/jquery.verto.js index 345012026e..0777fc12b7 100644 --- a/html5/verto/js/src/jquery.verto.js +++ b/html5/verto/js/src/jquery.verto.js @@ -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); diff --git a/src/mod/endpoints/mod_verto/mod_verto.c b/src/mod/endpoints/mod_verto/mod_verto.c index 4be239842d..1d422a53ad 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.c +++ b/src/mod/endpoints/mod_verto/mod_verto.c @@ -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); diff --git a/src/mod/endpoints/mod_verto/mod_verto.h b/src/mod/endpoints/mod_verto/mod_verto.h index beb26ab072..11614926a6 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.h +++ b/src/mod/endpoints/mod_verto/mod_verto.h @@ -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;