/** * open next file for reading * @param handle the file handle */ static switch_status_t next_file(switch_file_handle_t *handle) { int loops = 0; struct rayo_file_context *context = handle->private_info; struct output_component *output = context->component ? OUTPUT_COMPONENT(context->component) : NULL; top: if (switch_test_flag((&context->fh), SWITCH_FILE_OPEN)) { switch_core_file_close(&context->fh); } if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) { /* unsupported */ return SWITCH_STATUS_FALSE; } if (!context->cur_doc) { context->cur_doc = iks_find(output->document, "document"); if (!context->cur_doc) { iks_delete(output->document); output->document = NULL; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Missing <document>\n"); return SWITCH_STATUS_FALSE; } } else { context->cur_doc = iks_next_tag(context->cur_doc); } /* done? */ if (!context->cur_doc) { if (context->could_open && ++loops < 2 && (output->repeat_times == 0 || ++context->play_count < output->repeat_times)) { /* repeat all document(s) */ if (!output->repeat_interval_ms) { goto top; } } else { /* no more files to play */ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Done playing\n"); return SWITCH_STATUS_FALSE; } } if (!context->cur_doc) { /* play silence between repeats */ switch_safe_free(context->ssml); context->ssml = switch_mprintf("silence_stream://%i", output->repeat_interval_ms); } else { /* play next document */ iks *speak = NULL; switch_safe_free(context->ssml); context->ssml = NULL; speak = iks_find(context->cur_doc, "speak"); if (speak) { /* <speak> is child node */ char *ssml_str = iks_string(NULL, speak); if (zstr(output->renderer)) { /* FS must parse the SSML */ context->ssml = switch_mprintf("ssml://%s", ssml_str); } else { /* renderer will parse the SSML */ if (!zstr(output->headers) && !strncmp("unimrcp", output->renderer, 7)) { /* pass MRCP headers */ context->ssml = switch_mprintf("tts://%s||%s%s", output->renderer, output->headers, ssml_str); } else { context->ssml = switch_mprintf("tts://%s||%s", output->renderer, ssml_str); } } iks_free(ssml_str); } else if (iks_has_children(context->cur_doc)) { /* check if <speak> is in CDATA */ const char *ssml_str = NULL; iks *ssml = iks_child(context->cur_doc); if (ssml && iks_type(ssml) == IKS_CDATA) { ssml_str = iks_cdata(ssml); } if (zstr(ssml_str)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Missing <document> CDATA\n"); return SWITCH_STATUS_FALSE; } if (zstr(output->renderer)) { /* FS must parse the SSML */ context->ssml = switch_mprintf("ssml://%s", ssml_str); } else { /* renderer will parse the SSML */ if (!zstr(output->headers) && !strncmp("unimrcp", output->renderer, 7)) { /* pass MRCP headers */ context->ssml = switch_mprintf("tts://%s||%s%s", output->renderer, output->headers, ssml_str); } else { context->ssml = switch_mprintf("tts://%s||%s", output->renderer, ssml_str); } } } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Missing <speak>\n"); return SWITCH_STATUS_FALSE; } } if (switch_core_file_open(&context->fh, context->ssml, handle->channels, handle->samplerate, handle->flags, NULL) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Failed to open %s\n", context->ssml); goto top; } else { context->could_open = 1; } handle->samples = context->fh.samples; handle->format = context->fh.format; handle->sections = context->fh.sections; handle->seekable = context->fh.seekable; handle->speed = context->fh.speed; handle->vol = context->fh.vol; handle->offset_pos = context->fh.offset_pos; handle->interval = context->fh.interval; if (switch_test_flag((&context->fh), SWITCH_FILE_NATIVE)) { switch_set_flag(handle, SWITCH_FILE_NATIVE); } else { switch_clear_flag(handle, SWITCH_FILE_NATIVE); } return SWITCH_STATUS_SUCCESS; }
ikspak * iks_packet (iks *x) { ikspak *pak; ikstack *s; char *tmp; s = iks_stack (x); pak = iks_stack_alloc (s, sizeof (ikspak)); if (!pak) return NULL; memset (pak, 0, sizeof (ikspak)); pak->x = x; tmp = iks_find_attrib (x, "from"); if (tmp) pak->from = iks_id_new (s, tmp); pak->id = iks_find_attrib (x, "id"); tmp = iks_find_attrib (x, "type"); if (strcmp (iks_name (x), "message") == 0) { pak->type = IKS_PAK_MESSAGE; if (tmp) { if (strcmp (tmp, "chat") == 0) pak->subtype = IKS_TYPE_CHAT; else if (strcmp (tmp, "groupchat") == 0) pak->subtype = IKS_TYPE_GROUPCHAT; else if (strcmp (tmp, "headline") == 0) pak->subtype = IKS_TYPE_HEADLINE; else if (strcmp (tmp, "error") == 0) pak->subtype = IKS_TYPE_ERROR; } } else if (strcmp (iks_name (x), "presence") == 0) { pak->type = IKS_PAK_S10N; if (tmp) { if (strcmp (tmp, "unavailable") == 0) { pak->type = IKS_PAK_PRESENCE; pak->subtype = IKS_TYPE_UNAVAILABLE; pak->show = IKS_SHOW_UNAVAILABLE; } else if (strcmp (tmp, "probe") == 0) { pak->type = IKS_PAK_PRESENCE; pak->subtype = IKS_TYPE_PROBE; } else if(strcmp(tmp, "subscribe") == 0) pak->subtype = IKS_TYPE_SUBSCRIBE; else if(strcmp(tmp, "subscribed") == 0) pak->subtype = IKS_TYPE_SUBSCRIBED; else if(strcmp(tmp, "unsubscribe") == 0) pak->subtype = IKS_TYPE_UNSUBSCRIBE; else if(strcmp(tmp, "unsubscribed") == 0) pak->subtype = IKS_TYPE_UNSUBSCRIBED; else if(strcmp(tmp, "error") == 0) pak->subtype = IKS_TYPE_ERROR; } else { pak->type = IKS_PAK_PRESENCE; pak->subtype = IKS_TYPE_AVAILABLE; tmp = iks_find_cdata (x, "show"); pak->show = IKS_SHOW_AVAILABLE; if (tmp) { if (strcmp (tmp, "chat") == 0) pak->show = IKS_SHOW_CHAT; else if (strcmp (tmp, "away") == 0) pak->show = IKS_SHOW_AWAY; else if (strcmp (tmp, "xa") == 0) pak->show = IKS_SHOW_XA; else if (strcmp (tmp, "dnd") == 0) pak->show = IKS_SHOW_DND; } } } else if (strcmp (iks_name (x), "iq") == 0) { iks *q; pak->type = IKS_PAK_IQ; if (tmp) { if (strcmp (tmp, "get") == 0) pak->subtype = IKS_TYPE_GET; else if (strcmp (tmp, "set") == 0) pak->subtype = IKS_TYPE_SET; else if (strcmp (tmp, "result") == 0) pak->subtype = IKS_TYPE_RESULT; else if (strcmp (tmp, "error") == 0) pak->subtype = IKS_TYPE_ERROR; } for (q = iks_child (x); q; q = iks_next (q)) { if (IKS_TAG == iks_type (q)) { char *ns; ns = iks_find_attrib (q, "xmlns"); if (ns) { pak->query = q; pak->ns = ns; break; } } } } return pak; }