]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
split this into 2 functions so its clear if this function allocates or not
authorMichael Jerris <mike@jerris.com>
Wed, 30 Apr 2014 19:48:23 +0000 (15:48 -0400)
committerMichael Jerris <mike@jerris.com>
Wed, 30 Apr 2014 19:48:23 +0000 (15:48 -0400)
src/mod/applications/mod_voicemail_ivr/menu.c
src/mod/applications/mod_voicemail_ivr/utils.c
src/mod/applications/mod_voicemail_ivr/utils.h

index 560068ceadd9b199e5a06401afd234d13c90a7d1..9553a9095197493f4b073d883e9dca65c0a19e63 100644 (file)
@@ -95,7 +95,7 @@ void vmivr_menu_main(switch_core_session_t *session, vmivr_profile_t *profile) {
                ivre_init(&menu.ivre_d, menu.dtmfa);
 
                cmd = switch_core_session_sprintf(session, "json %s %s %s %s", profile->api_profile, profile->domain, profile->id, profile->folder_name);
-               jsonapi2event(session, menu.phrase_params, profile->api_msg_count, cmd);
+               jsonapi_populate_event(session, menu.phrase_params, profile->api_msg_count, cmd);
 
                /* Verify that phrases returned values, if not, exit */
                if (!switch_event_get_header(menu.phrase_params, "VM-Total-New-Messages")) {
@@ -192,7 +192,7 @@ void vmivr_menu_navigator(switch_core_session_t *session, vmivr_profile_t *profi
 
        /* Get VoiceMail List And update msg count */
        cmd = switch_core_session_sprintf(session, "json %s %s %s %s %s", profile->api_profile, profile->domain, profile->id, profile->folder_name, profile->folder_filter);
-       msg_list_params = jsonapi2event(session, NULL, profile->api_msg_list, cmd);
+       msg_list_params = jsonapi2event(session, profile->api_msg_list, cmd);
        if (msg_list_params) {
                msg_count = atol(switch_event_get_header(msg_list_params,"VM-List-Count"));
                if (msg_count == 0) {
@@ -266,7 +266,7 @@ void vmivr_menu_navigator(switch_core_session_t *session, vmivr_profile_t *profi
                if (!skip_header) {
                        if (!initial_count_played) {
                                cmd = switch_core_session_sprintf(session, "json %s %s %s", profile->api_profile, profile->domain, profile->id);
-                               jsonapi2event(session, menu.phrase_params, profile->api_msg_count, cmd);
+                               jsonapi_populate_event(session, menu.phrase_params, profile->api_msg_count, cmd);
                                initial_count_played = SWITCH_TRUE;
                                // TODO ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "msg_count"), NULL, menu.phrase_params, NULL, 0);
                        }
@@ -597,7 +597,7 @@ void vmivr_menu_select_greeting_slot(switch_core_session_t *session, vmivr_profi
                if (vmivr_api_execute(session, profile->api_pref_greeting_set, cmd) == SWITCH_STATUS_SUCCESS) {
                        char *str_num = switch_core_session_sprintf(session, "%d", gnum);
                        char *cmd = switch_core_session_sprintf(session, "json %s %s %s %d %s", profile->api_profile, profile->domain, profile->id);
-                       switch_event_t *phrases = jsonapi2event(session, NULL, profile->api_pref_greeting_get, cmd);
+                       switch_event_t *phrases = jsonapi2event(session, profile->api_pref_greeting_get, cmd);
 
                        ivre_playback_dtmf_buffered(session, switch_event_get_header(menu.event_phrases, "selected_slot"), str_num, phrases, NULL, 0);
 
index 73f58b84b2529b105cb1af2965e564aff6e8b880..b35edb407119302beb3da0e8aaec6e12455456b8 100644 (file)
@@ -75,25 +75,35 @@ end:
        return status;
 }
 
-switch_event_t *jsonapi2event(switch_core_session_t *session, switch_event_t *apply_event, const char *api, const char *data) {
+void jsonapi_populate_event(switch_core_session_t *session, switch_event_t *apply_event, const char *api, const char *data) {
        switch_event_t *phrases_event = NULL;
        switch_stream_handle_t stream = { 0 };
+
+       switch_assert(apply_event);
        SWITCH_STANDARD_STREAM(stream);
        switch_api_execute(api, data, session, &stream);
        switch_event_create_json(&phrases_event, (char *) stream.data);
        switch_safe_free(stream.data);
 
-       if (apply_event) {
-               switch_event_header_t *hp;
-               for (hp = phrases_event->headers; hp; hp = hp->next) {
-                       if (!strncasecmp(hp->name, "VM-", 3)) {
-                               switch_event_add_header(apply_event, SWITCH_STACK_BOTTOM, hp->name, "%s", hp->value);
-                       }
+       switch_event_header_t *hp;
+       for (hp = phrases_event->headers; hp; hp = hp->next) {
+               if (!strncasecmp(hp->name, "VM-", 3)) {
+                       switch_event_add_header(apply_event, SWITCH_STACK_BOTTOM, hp->name, "%s", hp->value);
                }
-               switch_event_destroy(&phrases_event);
-               phrases_event = apply_event;
-
        }
+       switch_event_destroy(&phrases_event);
+       phrases_event = apply_event;
+
+       return;
+}
+
+switch_event_t *jsonapi2event(switch_core_session_t *session, const char *api, const char *data) {
+       switch_event_t *phrases_event = NULL;
+       switch_stream_handle_t stream = { 0 };
+       SWITCH_STANDARD_STREAM(stream);
+       switch_api_execute(api, data, session, &stream);
+       switch_event_create_json(&phrases_event, (char *) stream.data);
+       switch_safe_free(stream.data);
 
        return phrases_event;
 }
@@ -139,7 +149,7 @@ void append_event_message(switch_core_session_t *session, vmivr_profile_t *profi
 
        switch_safe_free(varname);
 
-       jsonapi2event(session, phrase_params, profile->api_msg_get, apicmd);
+       jsonapi_populate_event(session, phrase_params, profile->api_msg_get, apicmd);
 
        /* TODO Set these 2 header correctly */
        switch_event_add_header(phrase_params, SWITCH_STACK_BOTTOM, "VM-Message-Type", "%s", "new");
index 11219d1aadeec25f4e6be6f903ee77b00ff70f88..e497ec610168e9ef9db6e69a527d18a0a71e4cd0 100644 (file)
@@ -36,7 +36,8 @@
 
 void append_event_message(switch_core_session_t *session, vmivr_profile_t *profile, switch_event_t *phrase_params, switch_event_t *msg_list_event, size_t current_msg);
 char *generate_random_file_name(switch_core_session_t *session, const char *mod_name, const char *file_extension);
-switch_event_t *jsonapi2event(switch_core_session_t *session, switch_event_t *apply_event, const char *api, const char *data);
+switch_event_t *jsonapi2event(switch_core_session_t *session, const char *api, const char *data);
+void jsonapi_populate_event(switch_core_session_t *session, switch_event_t *apply_event, const char *api, const char *data);
 switch_status_t vmivr_merge_media_files(const char** inputs, const char *output, int rate);
 switch_status_t vmivr_api_execute(switch_core_session_t *session, const char *apiname, const char *arguments);
 #endif /* _UTIL_H_ */