]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[mod_verto] add new verto command construct basics
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 21 Feb 2020 18:52:35 +0000 (18:52 +0000)
committerAndrey Volk <andywolk@gmail.com>
Sat, 23 Oct 2021 19:00:19 +0000 (22:00 +0300)
src/mod/endpoints/mod_verto/mod_verto.c

index 182786d5f757a7f8c1c31f074980c84d570e79e1..9aea22c9a2425d6869dde9e0acad8ea8268ddab6 100644 (file)
@@ -3431,7 +3431,7 @@ static void parse_user_vars(cJSON *obj, switch_core_session_t *session)
 
 static switch_bool_t verto__info_func(const char *method, cJSON *params, jsock_t *jsock, cJSON **response)
 {
-       cJSON *msg = NULL, *dialog = NULL, *txt = NULL;
+       cJSON *msg = NULL, *dialog = NULL, *txt = NULL, *jevent = NULL;
        const char *call_id = NULL, *dtmf = NULL;
        switch_bool_t r = SWITCH_TRUE;
        char *proto = VERTO_CHAT_PROTO;
@@ -3449,17 +3449,42 @@ static switch_bool_t verto__info_func(const char *method, cJSON *params, jsock_t
                switch_core_session_t *session = NULL;
 
                if ((session = switch_core_session_locate(call_id))) {
+                       verto_pvt_t *tech_pvt = switch_core_session_get_private_class(session, SWITCH_PVT_SECONDARY);
+
+                       if (!tech_pvt) {
+                               cJSON_AddItemToObject(*response, "message", cJSON_CreateString("Invalid channel"));
+                               switch_core_session_rwunlock(session);
+                               err = 1; goto cleanup;
+                       }
 
                        parse_user_vars(dialog, session);
 
-                       if ((dtmf = cJSON_GetObjectCstr(params, "dtmf"))) {
-                               verto_pvt_t *tech_pvt = switch_core_session_get_private_class(session, SWITCH_PVT_SECONDARY);
-                               char *send;
+                       if ((jevent = cJSON_GetObjectItem(params, "command"))) {
+                               switch_event_t *event = NULL;
+
+                               if (switch_event_create(&event, SWITCH_EVENT_COMMAND) == SWITCH_STATUS_SUCCESS) {
+                                       char *json_text;
+
+                                       json_text = cJSON_PrintUnformatted(jevent);
+                                       switch_assert(json_text);
 
-                               if (!tech_pvt) {
-                                       cJSON_AddItemToObject(*response, "message", cJSON_CreateString("Invalid channel"));
-                                       err = 1; goto cleanup;
+                                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "content-type", "text/json");
+                                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "content-source", "verto");
+                                       switch_event_add_body(event, "%s", json_text);
+
+                                       switch_safe_free(json_text);
+                                       
+                                       if (switch_core_session_queue_event(session, &event) != SWITCH_STATUS_SUCCESS) {
+                                               switch_event_destroy(&event);
+                                               cJSON_AddItemToObject(*response, "message", cJSON_CreateString("Unexpected Error"));
+                                               switch_core_session_rwunlock(session);
+                                               err = 1; goto cleanup;
+                                       }
                                }
+                       }
+                       
+                       if ((dtmf = cJSON_GetObjectCstr(params, "dtmf"))) {
+                               char *send;
 
                                send = switch_mprintf("~%s", dtmf);