int axis2_xmpp_client_on_presence( void *user_data, ikspak *pak) { axis2_xmpp_session_data_t *session = NULL; axutil_env_t *env = NULL; char* presence_str = NULL; axis2_status_t status = AXIS2_SUCCESS; char request_uri[500] = ""; session = (axis2_xmpp_session_data_t*) user_data; env = session->env; presence_str = iks_string(iks_stack(pak->x), pak->x); if(!presence_str) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[xmpp]Failed to serialize the " "presence envelope"); return IKS_FILTER_EAT; } snprintf(request_uri, 500, "xmpp://localhost/axis2/services/%s", axis2_svc_get_name( session->svc, env)); status = axis2_xmpp_transport_utils_process_presence_client(session->env, session, presence_str, request_uri); return IKS_FILTER_EAT; /* no need to pass to other filters */ }
/** * Handle barge event */ static iks *prompt_component_handle_input_barge(struct rayo_actor *prompt, struct rayo_message *msg, void *data) { iks *presence = msg->payload; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s (%s) input barge\n", RAYO_JID(prompt), prompt_component_state_to_string(PROMPT_COMPONENT(prompt)->state)); switch (PROMPT_COMPONENT(prompt)->state) { case PCS_INPUT_OUTPUT: switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s, got <start-of-input> from %s: %s\n", RAYO_JID(prompt), msg->from_jid, iks_string(iks_stack(presence), presence)); PROMPT_COMPONENT(prompt)->state = PCS_STOP_OUTPUT; rayo_component_send_stop(prompt, PROMPT_COMPONENT(prompt)->output_jid); break; case PCS_STOP_OUTPUT: case PCS_INPUT: /* don't care */ break; case PCS_OUTPUT: case PCS_START_OUTPUT: case PCS_START_OUTPUT_BARGE: case PCS_START_INPUT: case PCS_START_INPUT_OUTPUT: case PCS_START_INPUT_TIMERS: case PCS_DONE_STOP_OUTPUT: case PCS_DONE: switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s, unexpected start output error event\n", RAYO_JID(prompt)); break; } return NULL; }
void serialize_test (char *buf, int len) { unsigned long time; iks *x; iksparser *prs; char *xml; int err; prs = iks_dom_new (&x); err = iks_parse (prs, buf, len, 1); switch (err) { case IKS_OK: break; case IKS_NOMEM: exit (2); case IKS_BADXML: fprintf (stderr, "Invalid xml at byte %ld, line %ld\n", iks_nr_bytes (prs), iks_nr_lines (prs)); exit (1); case IKS_HOOK: exit (1); } iks_parser_delete (prs); t_reset (); xml = iks_string (iks_stack (x), x); time = t_elapsed (); printf ("Serialize: serializing the tree took %ld milliseconds.\n", time); iks_delete (x); }
int ikss_Stream_send_node (ikss_Stream *self, iks *x) { // Note that iks_string caller is responsible for freeing the // returned string. char* xmlstr = iks_string (NULL, x); if (!xmlstr) return IKS_NOMEM; return ikss_Stream_send_raw (self, xmlstr); }
static int auth_failed_cb (ta_xmpp_client_t *client, void *data, void *TA_UNUSED(hdata)) { ikspak *pak = (ikspak *) data; char *node_str = iks_string (iks_stack (pak->x), pak->x); printf ("not connected: =(\n"); printf ("%s\n", node_str); ta_xmpp_client_disconnect (client); return 0; }
int axis2_xmpp_client_on_message( void *user_data, ikspak *pak) { axis2_xmpp_session_data_t *session = NULL; axutil_env_t *env = NULL; iks* body_elem = NULL; iks* soap_elem = NULL; char *soap_str = NULL; char *from = NULL; char request_uri[500] = ""; axis2_status_t status = AXIS2_SUCCESS; session = (axis2_xmpp_session_data_t*) user_data; env = session->env; /* Serialize the message and pass it up */ /* extract the body of message */ body_elem = iks_find(pak->x, "body"); if(!body_elem) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[xmpp]Failed to extract body of " "message stanza"); return IKS_FILTER_EAT; } soap_elem = iks_child(body_elem); if(!soap_elem) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[xmpp]Failed to extract soap envelope" "from message stanza"); return IKS_FILTER_EAT; } soap_str = iks_string(iks_stack(soap_elem), soap_elem); if(!soap_str) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[xmpp]Failed to serialize the soap " "envelope"); return IKS_FILTER_EAT; } snprintf(request_uri, 500, "xmpp://localhost/axis2/services/%s", axis2_svc_get_name( session->svc, env)); from = iks_find_attrib(pak->x, "from"); status = axis2_xmpp_transport_utils_process_message_client(session->env, session, soap_str, from, request_uri); /* TODO: Check whether we need to return IKS_HOOK on failure. I think not, * because, failure here means the failure of a single request. We should * keep running for other requests */ session->in_msg = 1; return IKS_FILTER_EAT; /* no need to pass to other filters */ }
/** * Handle start of input/output. */ static iks *prompt_component_handle_io_start(struct rayo_actor *prompt, struct rayo_message *msg, void *data) { iks *iq = msg->payload; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s, got <ref> from %s: %s\n", RAYO_JID(prompt), msg->from_jid, iks_string(iks_stack(iq), iq)); if (!strcmp("input", msg->from_subtype)) { return prompt_component_handle_input_start(prompt, msg, data); } else if (!strcmp("output", msg->from_subtype)) { return prompt_component_handle_output_start(prompt, msg, data); } return NULL; }
void string (char *xml) { char *tmp; tmp = iks_string (iks_stack (my_x), my_x); if (iks_strcmp (tmp, xml) != 0) { PR_TEST; printf ("Result: %s\n", tmp); printf ("Expected: %s\n", xml); exit (1); } }
char * db_dump_profile(void) { struct databases db; struct pack *p; DBC *cursor = NULL; DBT pair[2]; int e; iks *xml = NULL, *item, *x; char *ret = NULL; memset(&pair[0], 0, sizeof(DBT) * 2); pair[1].flags = DB_DBT_MALLOC; if (open_env(&db, PROFILE_DB)) goto out; db.profile->cursor(db.profile, NULL, &cursor, 0); xml = iks_new("comarProfile"); iks_insert_cdata(xml, "\n", 1); while ((e = cursor->c_get(cursor, &pair[0], &pair[1], DB_NEXT)) == 0) { char *t; size_t ts; item = iks_insert(xml, "item"); iks_insert_cdata(iks_insert(item, "key"), pair[0].data, pair[0].size); p = pack_wrap(pair[1].data, pair[1].size); while (pack_get(p, &t, &ts)) { iks_insert_cdata(item, "\n", 1); x = iks_insert(item, "data"); iks_insert_attrib(x, "key", t); pack_get(p, &t, &ts); iks_insert_cdata(iks_insert(x, "value"), t, ts); } pack_delete(p); iks_insert_cdata(xml, "\n", 1); } if (e != DB_NOTFOUND) { goto out; } ret = iks_string(NULL, xml); out: if (cursor) cursor->c_close(cursor); close_env(&db); if (xml) iks_delete(xml); return ret; }
static int CFStouSvrConnSendStanza(CFStouSvrConn* conn, iks* stz) { const char *stzStr; size_t len; if ((stzStr = iks_string(iks_stack(stz), stz))) { len = strlen(stzStr); if (CFStouSvrConnSend(conn, (const uint8_t*)stzStr, len)) { LCF_ERR_OUT(ERR_OUT, "CFStouSvrConnWrite() failed, maybe blocking\n todo: send iq error back\n"); } } else { LCF_ERR_OUT(ERR_OUT, "iks_string() failed, maybe iks stack memory is so low\n"); } return 0; ERR_OUT: return -1; }
/// 客户端组装发给服务器端的协商包。 char* pkg_talk_make(const packet_parser_t *pkg) { char *r; iks *x, *tmp; x = iks_new ("connection"); if(NULL == x) return NULL; iks_insert_attrib(x, "xmlns", TALK_XMLNS); iks_insert_attrib(x, "type", "create"); tmp = iks_insert(x, "client-id"); if(NULL != tmp) { iks_insert_cdata(tmp, pkg->client_cert.client_id, 0); } tmp = iks_insert(x, "public-key"); if(NULL != tmp) { iks_insert_cdata(tmp, pkg->curr_ert.ert_keys[0], 0); iks_insert_attrib(tmp, "type", pkg->curr_ert.talk_ert_type); } if(0 != strlen(pkg->curr_ert.talk_ert_type)){ tmp = iks_insert(x, "encryption"); iks_insert_cdata(iks_insert(tmp,"allow"), pkg->curr_ert.transfer_ert_type, 0); } if(0 != strlen(pkg->cps_type)){ tmp = iks_insert(x, "compression"); iks_insert_cdata(iks_insert(tmp,"allow"), pkg->cps_type, 0); } if( pkg->client_cert.signature[0] != 0 ){ tmp = iks_insert(x, "certificate"); iks_insert_attrib(tmp, "id", pkg->client_cert.cert_id); iks_insert_cdata(iks_insert(tmp, "subject"), pkg->client_cert.subject, 0); iks_insert_cdata(iks_insert(tmp, "signature"), pkg->client_cert.signature, 0); } r = iks_string(NULL, x); iks_delete(x); return r; }
// 服务器端组装发给客户端的协商包 char* pkg_talk_rtn(const packet_parser_t *pkg) { char *r; unsigned char *encrypted_key;// 使用公钥加密过的临时密钥 char *output; iks *x, *tmp; int dest_len; x = iks_new ("connection"); if(NULL == x) return NULL; iks_insert_attrib(x, "xmlns", TALK_XMLNS); iks_insert_attrib(x, "type", "result"); tmp = iks_insert(x, "encryption"); iks_insert_attrib(tmp, "type", pkg->curr_ert.transfer_ert_type); // 使用公钥对临时密钥进行加密 if (pkg->asym_encrypt_hook == NULL) { encrypted_key = rsa_encrypt((unsigned char *)get_transfer_crt_key(pkg), strlen(get_transfer_crt_key(pkg)), &dest_len, (char *)(pkg->curr_ert.ert_keys[0]), CRYPT_TYPE_ENCRYPT); } else { encrypted_key = pkg->asym_encrypt_hook((unsigned char *)get_transfer_crt_key(pkg), strlen(get_transfer_crt_key(pkg)), &dest_len, (char *)(pkg->curr_ert.ert_keys[0]), CRYPT_TYPE_ENCRYPT); } output = (char *)calloc(dest_len*2+1, 1); byte2hex(encrypted_key, dest_len, output); iks_insert_cdata(tmp, output, 0); free(output); free(encrypted_key); iks_insert_cdata(iks_insert(x, "compression"), pkg->cps_type, 0); tmp = iks_insert(x, "heartbeat"); // TODO:在初始化服务器端包解析器的时候应该设置心跳参数 iks_insert_attrib(tmp, "sponsor", "server"); iks_insert_attrib(tmp, "seconds", "60"); r = iks_string(NULL, x); iks_delete(x); return r; }
static int _XcFilterIqCtlHook(void *userData, ikspak *pak) { iks *stz; const char *stzStr; CFStouXmppGwConn* gwConn; CFStouSvrConn* stouConn; size_t len; LCF_DBG_IN_FUNC(); gwConn = userData; stouConn = gwConn->stouConn; stz = pak->x; if ((stzStr = iks_string(iks_stack(stz), stz))) { len = strlen(stzStr); if (CFStouSvrConnSend(stouConn, (const uint8_t*)stzStr, len)) { LCF_ERR("CFStouSvrConnWrite() failed, maybe blocking\n todo: send iq error back\n"); } } else { LCF_ERR("iks_string() failed, maybe iks stack memory is so low\n"); } return IKS_FILTER_EAT; }
/** * 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; }
/** * Handle output failure. */ static iks *prompt_component_handle_output_error(struct rayo_actor *prompt, struct rayo_message *msg, void *data) { iks *iq = msg->payload; iks *error = iks_find(iq, "error"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s (%s) output error\n", RAYO_JID(prompt), prompt_component_state_to_string(PROMPT_COMPONENT(prompt)->state)); switch (PROMPT_COMPONENT(prompt)->state) { case PCS_START_OUTPUT: case PCS_START_OUTPUT_BARGE: switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s, <output> error: %s\n", RAYO_JID(prompt), iks_string(iks_stack(iq), iq)); PROMPT_COMPONENT(prompt)->state = PCS_DONE; /* forward IQ error to client */ iq = PROMPT_COMPONENT(prompt)->iq; iks_insert_attrib(iq, "from", RAYO_JID(RAYO_COMPONENT(prompt)->parent)); iks_insert_attrib(iq, "to", RAYO_COMPONENT(prompt)->client_jid); iks_insert_node(iq, iks_copy_within(error, iks_stack(iq))); RAYO_SEND_REPLY(prompt, RAYO_COMPONENT(prompt)->client_jid, iq); /* done */ RAYO_UNLOCK(prompt); RAYO_DESTROY(prompt); break; case PCS_START_INPUT_OUTPUT: case PCS_START_INPUT_TIMERS: case PCS_START_INPUT: case PCS_INPUT_OUTPUT: case PCS_STOP_OUTPUT: case PCS_INPUT: case PCS_OUTPUT: case PCS_DONE_STOP_OUTPUT: case PCS_DONE: switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s, unexpected start output error event\n", RAYO_JID(prompt)); break; } return NULL; }
/** * Handle input failure. */ static iks *prompt_component_handle_input_error(struct rayo_actor *prompt, struct rayo_message *msg, void *data) { iks *iq = msg->payload; iks *error = iks_find(iq, "error"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s (%s) input error\n", RAYO_JID(prompt), prompt_component_state_to_string(PROMPT_COMPONENT(prompt)->state)); switch (PROMPT_COMPONENT(prompt)->state) { case PCS_START_INPUT_TIMERS: switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s, <input> error: %s\n", RAYO_JID(prompt), iks_string(iks_stack(iq), iq)); PROMPT_COMPONENT(prompt)->state = PCS_DONE; /* forward IQ error to client */ iq = PROMPT_COMPONENT(prompt)->iq; iks_insert_attrib(iq, "from", RAYO_JID(RAYO_COMPONENT(prompt)->parent)); iks_insert_attrib(iq, "to", RAYO_COMPONENT(prompt)->client_jid); iks_insert_node(iq, iks_copy_within(error, iks_stack(iq))); RAYO_SEND_REPLY(prompt, RAYO_COMPONENT(prompt)->client_jid, iq); /* done */ iks_delete(PROMPT_COMPONENT(prompt)->iq); RAYO_UNLOCK(prompt); RAYO_DESTROY(prompt); break; case PCS_START_INPUT: PROMPT_COMPONENT(prompt)->state = PCS_DONE; iks_delete(PROMPT_COMPONENT(prompt)->iq); if (iks_find(error, "item-not-found")) { /* call is gone (hangup) */ rayo_component_send_complete(RAYO_COMPONENT(prompt), COMPONENT_COMPLETE_HANGUP); } else { /* send presence error to client */ rayo_component_send_complete(RAYO_COMPONENT(prompt), COMPONENT_COMPLETE_ERROR); } break; case PCS_START_INPUT_OUTPUT: PROMPT_COMPONENT(prompt)->state = PCS_DONE_STOP_OUTPUT; /* forward IQ error to client */ iq = PROMPT_COMPONENT(prompt)->iq; iks_insert_attrib(iq, "from", RAYO_JID(RAYO_COMPONENT(prompt)->parent)); iks_insert_attrib(iq, "to", RAYO_COMPONENT(prompt)->client_jid); iks_insert_node(iq, iks_copy_within(error, iks_stack(iq))); PROMPT_COMPONENT(prompt)->complete = iq; rayo_component_send_stop(prompt, PROMPT_COMPONENT(prompt)->output_jid); break; case PCS_START_OUTPUT: case PCS_START_OUTPUT_BARGE: case PCS_INPUT_OUTPUT: case PCS_STOP_OUTPUT: case PCS_INPUT: case PCS_OUTPUT: case PCS_DONE_STOP_OUTPUT: case PCS_DONE: switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s, unexpected start input error event\n", RAYO_JID(prompt)); break; } return NULL; }
int iks_send(iksparser *prs, iks *x) { return iks_send_raw(prs, iks_string(iks_stack(x), x)); }