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")) {
/* 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) {
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);
}
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);
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;
}
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");
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_ */