]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[mod_verto] add exptime to ping and pong and log any hangups as a result of auth...
authorAnthony Minessale <anthm@signalwire.com>
Wed, 31 Mar 2021 20:13:38 +0000 (20:13 +0000)
committerAndrey Volk <andywolk@gmail.com>
Sat, 23 Oct 2021 19:01:05 +0000 (22:01 +0300)
src/mod/endpoints/mod_verto/mod_verto.c
src/mod/endpoints/mod_verto/mod_verto.h

index 610ec131c9a4cacdd2f3430f18e2c05f9dfd6fa8..85d1f3e49c71ca6f19d594b1130e8892b66303b4 100644 (file)
@@ -1117,6 +1117,8 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char *
                                        switch_event_add_header_string(jsock->user_vars, SWITCH_STACK_BOTTOM, var, val);
                                        switch_mutex_unlock(jsock->flag_mutex);
 
+                                       switch_clear_flag(jsock, JPFLAG_AUTH_EXPIRED);
+                                       
                                        if (!strcmp(var, "login-expires")) {
                                                uint32_t tmp = atol(val);
 
@@ -1348,7 +1350,16 @@ static void drop_detached(void)
                }
 
                if (tech_pvt->detach_time && (now - tech_pvt->detach_time) > verto_globals.detach_timeout) {
-                       switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_RECOVERY_ON_TIMER_EXPIRE);
+                       jsock_t *jsock = NULL;
+
+                       if ((jsock = get_jsock(tech_pvt->jsock_uuid))) {
+                               if (switch_test_flag(jsock, JPFLAG_AUTH_EXPIRED)) {
+                                       switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_BEARERCAPABILITY_NOTAUTH);
+                               }
+                               switch_thread_rwlock_unlock(jsock->rwlock);
+                       } else {
+                               switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_RECOVERY_ON_TIMER_EXPIRE);
+                       }
                }
        }
        switch_thread_rwlock_unlock(verto_globals.tech_rwlock);
@@ -1985,6 +1996,7 @@ static void client_run(jsock_t *jsock)
                        now = switch_epoch_time_now(NULL);
 
                        if (now >= jsock->exptime) {
+                               switch_set_flag(jsock, JPFLAG_AUTH_EXPIRED);
                                die("%s Authentication Expired\n", jsock->uid);
                        }
 
@@ -1998,6 +2010,10 @@ static void client_run(jsock_t *jsock)
                        cJSON *params = NULL;
                        cJSON *msg = jrpc_new_req("verto.ping", 0, &params);
 
+                       if (jsock->exptime) {
+                               cJSON_AddItemToObject(params, "auth-expires", cJSON_CreateNumber(jsock->exptime));
+                       }
+                       
                        cJSON_AddItemToObject(params, "serno", cJSON_CreateNumber(switch_epoch_time_now(NULL)));
                        jsock_queue_event(jsock, &msg, SWITCH_TRUE);
                        idle = 0;
@@ -3700,6 +3716,11 @@ static void parse_user_vars(cJSON *obj, switch_core_session_t *session)
 static switch_bool_t verto__ping_func(const char *method, cJSON *params, jsock_t *jsock, cJSON **response)
 {
        *response = cJSON_CreateObject();
+
+       if (jsock->exptime) {
+               cJSON_AddItemToObject(*response, "auth-expires", cJSON_CreateNumber(jsock->exptime));
+       }
+                       
        cJSON_AddItemToObject(*response, "message", cJSON_CreateString("PONG"));
        return SWITCH_TRUE;
 }
index 6d48a922c3ea1d880997c862fea11fe324ddf8e4..f3326f605d71f2c278001e2d30a4c8c9fd361320 100644 (file)
@@ -95,7 +95,8 @@ typedef enum {
        JPFLAG_CHECK_ATTACH = (1 << 2),
        JPFLAG_EVENTS = (1 << 3),
        JPFLAG_AUTH_EVENTS = (1 << 4),
-       JPFLAG_ALL_EVENTS_AUTHED = (1 << 5)
+       JPFLAG_ALL_EVENTS_AUTHED = (1 << 5),
+       JPFLAG_AUTH_EXPIRED = (1 << 6)
 } jpflag_t;
 
 struct verto_profile_s;