/** * This is called when someone sends a RPC method call * Checks for XML-RPC format validation and sends error if so otherwise it calls the * HandleServiceCall for finding the right service and creating the right structures * @return KEEP_THIS_HANDLER_ACTIVE */ int HandleRpcCall(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_stanza_t *reply; xmpp_stanza_t *xmlRpcReply; xmpp_ctx_t *ctx = (xmpp_ctx_t*) userdata; sdvp_from_t* from; sdvp_reply_params_t* replyParams = NULL; int formatInvalid; sdvpIdleCounter = 0; sdvpPingsSent = 0; reply = xmpp_stanza_new(ctx); xmpp_stanza_set_name(reply, "iq"); // TODO: Get the Group and get the jid from = _CreateFrom(xmpp_stanza_get_attribute(stanza, "from"), "TODO", "TODO"); syslog(LOG_DEBUG, "Received a RPC Method call from %s\n", from->name); formatInvalid = _CheckRpcFormat(stanza); if (formatInvalid) { // FIXME: Something here fails! syslog(LOG_WARNING, "Error in XML-RPC format\n"); sdvp_InitiateReplyParameters(&replyParams, 1); replyParams->params[0].strValue = strdup("Error in XML-RPC format\n"); replyParams->params[0].type = IEC_VISIBLE_STRING; xmpp_stanza_set_type(reply, "error"); // TODO: Create a type //HJP var her! xmlRpcReply = _CreateReply(ctx, SDVP_METHOD_UNDEFINED ,replyParams); xmpp_stanza_add_child(reply, xmlRpcReply); //HJP: stanza_add_child laver en kopi, så der skal releases xmpp_stanza_release(xmlRpcReply); sdvp_FreeReplyParameters(replyParams); } else { // The reply from this function should be ready to send xmlRpcReply = _HandleServiceRequest(conn, stanza, userdata); xmpp_stanza_add_child(reply, xmlRpcReply); //HJP: stanza_add_child laver en kopi, så der skal releases xmpp_stanza_release(xmlRpcReply); } xmpp_stanza_set_id(reply, xmpp_stanza_get_id(stanza)); xmpp_stanza_set_attribute(reply, "to", xmpp_stanza_get_attribute(stanza, "from")); xmpp_stanza_set_type(reply, "result"); xmpp_send(conn, reply); xmpp_stanza_release(reply); // Frees the stanza and all of its children _FreeFrom(from); return KEEP_THIS_HANDLER_ACTIVE; }
void send_stdin_once(xmpp_conn_t * const conn, xmpp_ctx_t *ctx, char *jid_to) { int n; char buf[1024], *stdin_b64; xmpp_stanza_t *message, *body, *text; while (n = fread(buf, sizeof(char), sizeof buf, stdin)){ stdin_b64 = to_base64(buf, n); message = xmpp_stanza_new(ctx); xmpp_stanza_set_name(message, "message"); xmpp_stanza_set_type(message, "chat"); xmpp_stanza_set_attribute(message, "to", jid_to); body = xmpp_stanza_new(ctx); xmpp_stanza_set_name(body, "body"); text = xmpp_stanza_new(ctx); xmpp_stanza_set_text(text, stdin_b64); xmpp_stanza_add_child(body, text); xmpp_stanza_add_child(message, body); xmpp_send(conn, message); xmpp_stanza_release(message); free(stdin_b64); } }
static int _iq_handle_discoinfo_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); xmpp_stanza_t *incoming_query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); const char *node_str = xmpp_stanza_get_attribute(incoming_query, STANZA_ATTR_NODE); if (from != NULL) { xmpp_stanza_t *response = xmpp_stanza_new(ctx); xmpp_stanza_set_name(response, STANZA_NAME_IQ); xmpp_stanza_set_id(response, xmpp_stanza_get_id(stanza)); xmpp_stanza_set_attribute(response, STANZA_ATTR_TO, from); xmpp_stanza_set_type(response, STANZA_TYPE_RESULT); xmpp_stanza_t *query = caps_create_query_response_stanza(ctx); if (node_str != NULL) { xmpp_stanza_set_attribute(query, STANZA_ATTR_NODE, node_str); } xmpp_stanza_add_child(response, query); xmpp_send(conn, response); xmpp_stanza_release(query); xmpp_stanza_release(response); } return 1; }
xmpp_stanza_t * stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient, const char * const type, const char * const message, const char * const state) { char *encoded_xml = encode_xml(message); xmpp_stanza_t *msg, *body, *text; msg = xmpp_stanza_new(ctx); xmpp_stanza_set_name(msg, STANZA_NAME_MESSAGE); xmpp_stanza_set_type(msg, type); xmpp_stanza_set_attribute(msg, STANZA_ATTR_TO, recipient); body = xmpp_stanza_new(ctx); xmpp_stanza_set_name(body, STANZA_NAME_BODY); text = xmpp_stanza_new(ctx); xmpp_stanza_set_text(text, encoded_xml); xmpp_stanza_add_child(body, text); xmpp_stanza_add_child(msg, body); if (state != NULL) { xmpp_stanza_t *chat_state = xmpp_stanza_new(ctx); xmpp_stanza_set_name(chat_state, state); xmpp_stanza_set_ns(chat_state, STANZA_NS_CHATSTATES); xmpp_stanza_add_child(msg, chat_state); } g_free(encoded_xml); return msg; }
int message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_stanza_t *reply, *body, *text; char *intext; xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata; if (!xmpp_stanza_get_child_by_name(stanza, "body")) return 1; if (xmpp_stanza_get_attribute(stanza, "type") != NULL && !strcmp(xmpp_stanza_get_attribute(stanza, "type"), "error")) return 1; intext = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body")); printf("Incoming message from %s: %s\n", xmpp_stanza_get_attribute(stanza, "from"), intext); reply = xmpp_stanza_new(ctx); xmpp_stanza_set_name(reply, "message"); xmpp_stanza_set_type(reply, xmpp_stanza_get_type(stanza) ? xmpp_stanza_get_type(stanza) : "chat"); xmpp_stanza_set_attribute(reply, "to", xmpp_stanza_get_attribute(stanza, "from")); body = xmpp_stanza_new(ctx); xmpp_stanza_set_name(body, "body"); char replytext[1024]; scanf("%[^\n]", replytext); text = xmpp_stanza_new(ctx); xmpp_stanza_set_text(text, replytext); xmpp_stanza_add_child(body, text); xmpp_stanza_add_child(reply, body); xmpp_send(conn, reply); xmpp_stanza_release(reply); return 1; }
int message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata; xmpp_stanza_t *reply; char *intext, *replytext; if (!xmpp_stanza_get_child_by_name(stanza, "body")) return 1; if (xmpp_stanza_get_type(stanza) != NULL && !strcmp(xmpp_stanza_get_type(stanza), "error")) return 1; intext = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body")); printf("Incoming message from %s: %s\n", xmpp_stanza_get_from(stanza), intext); reply = xmpp_stanza_reply(stanza); if (xmpp_stanza_get_type(reply) == NULL) xmpp_stanza_set_type(reply, "chat"); replytext = (char *) malloc(strlen(" to you too!") + strlen(intext) + 1); strcpy(replytext, intext); strcat(replytext, " to you too!"); xmpp_free(ctx, intext); xmpp_message_set_body(reply, replytext); xmpp_send(conn, reply); xmpp_stanza_release(reply); free(replytext); return 1; }
int message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_stanza_t *reply, *body, *text; char *intext, *replytext; xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata; if(!xmpp_stanza_get_child_by_name(stanza, "body")) return 1; intext = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body")); printf("Incoming message from %s: %s\n", xmpp_stanza_get_attribute(stanza, "from"), intext); reply = xmpp_stanza_new(ctx); xmpp_stanza_set_name(reply, "message"); xmpp_stanza_set_type(reply, xmpp_stanza_get_type(stanza)?xmpp_stanza_get_type(stanza):"chat"); xmpp_stanza_set_attribute(reply, "to", xmpp_stanza_get_attribute(stanza, "from")); body = xmpp_stanza_new(ctx); xmpp_stanza_set_name(body, "body"); replytext = malloc(strlen(" to you too!") + strlen(intext) + 1); strcpy(replytext, intext); strcat(replytext, " to you too!"); text = xmpp_stanza_new(ctx); xmpp_stanza_set_text(text, replytext); xmpp_stanza_add_child(body, text); xmpp_stanza_add_child(reply, body); xmpp_send(conn, reply); xmpp_stanza_release(reply); free(replytext); return 1; }
static int _disco_items_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); if (id != NULL) { log_debug("IQ disco items get handler fired, id: %s.", id); } else { log_debug("IQ disco items get handler fired."); } if (from != NULL) { xmpp_stanza_t *response = xmpp_stanza_new(ctx); xmpp_stanza_set_name(response, STANZA_NAME_IQ); xmpp_stanza_set_id(response, xmpp_stanza_get_id(stanza)); xmpp_stanza_set_attribute(response, STANZA_ATTR_TO, from); xmpp_stanza_set_type(response, STANZA_TYPE_RESULT); xmpp_stanza_t *query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, STANZA_NAME_QUERY); xmpp_stanza_set_ns(query, XMPP_NS_DISCO_ITEMS); xmpp_stanza_add_child(response, query); xmpp_send(conn, response); xmpp_stanza_release(response); } return 1; }
int xmppchat_send_message(xmpp_conn_t *conn, xmppdata_t *xdata) { xmpp_stanza_t *szmsg, *szbody, *sztext; xmpp_ctx_t *ctx; ctx = xmpp_conn_get_context(conn); sztext = xmpp_stanza_new(ctx); xmpp_stanza_set_text(sztext, xdata->data); szbody = xmpp_stanza_new(ctx); xmpp_stanza_set_name(szbody, "body"); xmpp_stanza_add_child(szbody, sztext); szmsg = xmpp_stanza_new(ctx); xmpp_stanza_set_name(szmsg, "message"); xmpp_stanza_set_type(szmsg, "chat"); xmpp_stanza_set_attribute(szmsg, "to", xdata->tojid); xmpp_stanza_add_child(szmsg, szbody); xmpp_send(conn, szmsg); xmpp_stanza_release(szmsg); return 0; }
static void _zkmuc_destroy_room(char *room_jid, xmpp_ua_t *ua) { xmpp_stanza_t *iq = xmpp_stanza_new(_xmpp_ctx); char id[128]; xmpp_ua_get_unique_string(ua, id); xmpp_stanza_set_name(iq, "iq"); xmpp_stanza_set_id(iq, id); xmpp_stanza_set_type(iq, "set"); xmpp_stanza_set_attribute(iq, "to", room_jid); xmpp_stanza_t *query = xmpp_stanza_new(_xmpp_ctx); xmpp_stanza_set_name(query, "query"); xmpp_stanza_set_ns(query, XMPP_NS_MUC_OWNER); xmpp_stanza_t *destroy = xmpp_stanza_new(_xmpp_ctx); xmpp_stanza_set_name(destroy, "destroy"); xmpp_stanza_set_attribute(destroy, "jid", room_jid); xmpp_stanza_add_child(query, destroy); xmpp_stanza_release(destroy); xmpp_stanza_add_child(iq, query); xmpp_stanza_release(query); xmpp_ua_id_handler_add(ua, zkmuc_destroy_room_result, id, NULL); xmpp_ua_send(ua, iq); xmpp_stanza_release(iq); }
int zkmuc_broadcast_message(zkmuc_ctx_t *ctx, const char *msg) { xmpp_stanza_t *stanza_msg = xmpp_stanza_new(_xmpp_ctx); xmpp_stanza_set_name(stanza_msg, "message"); xmpp_stanza_set_attribute(stanza_msg, "to", ctx->room_id); xmpp_stanza_set_type(stanza_msg, "groupchat"); xmpp_stanza_t *stanza_body = xmpp_stanza_new(_xmpp_ctx); xmpp_stanza_set_name(stanza_body, "zonekey"); xmpp_stanza_t *stanza_jid = xmpp_stanza_new(_xmpp_ctx); xmpp_stanza_set_name(stanza_jid, "jid"); xmpp_stanza_t *stanza_jid_value = xmpp_stanza_new(_xmpp_ctx); xmpp_stanza_set_text(stanza_jid_value, xmpp_ua_get_jid(ctx->ua)); xmpp_stanza_add_child(stanza_jid, stanza_jid_value); xmpp_stanza_release(stanza_jid_value); xmpp_stanza_add_child(stanza_body, stanza_jid); xmpp_stanza_release(stanza_jid); xmpp_stanza_t *stanza_txt = xmpp_stanza_new(_xmpp_ctx); xmpp_stanza_set_text(stanza_txt, msg); xmpp_stanza_add_child(stanza_body, stanza_txt); xmpp_stanza_release(stanza_txt); xmpp_stanza_add_child(stanza_msg, stanza_body); xmpp_stanza_release(stanza_body); xmpp_ua_send(ctx->ua, stanza_msg); xmpp_stanza_release(stanza_msg); return 0; }
int zkmuc_get_room_description(zkmuc_ctx_t *ctx, const char *room_id, on_get_room_description cb, void *user_data) { char iq_id[128]; xmpp_ua_get_unique_string(ctx->ua, iq_id); xmpp_stanza_t *stanza_iq = xmpp_stanza_new(_xmpp_ctx); xmpp_stanza_set_name(stanza_iq, "iq"); xmpp_stanza_set_attribute(stanza_iq, "to", room_id); xmpp_stanza_set_attribute(stanza_iq, "id", iq_id); xmpp_stanza_set_type(stanza_iq, "get"); xmpp_stanza_t *stanza_query = xmpp_stanza_new(_xmpp_ctx); xmpp_stanza_set_name(stanza_query, "query"); xmpp_stanza_set_ns(stanza_query, XMPP_NS_MUC_ROOM_INFO); xmpp_stanza_add_child(stanza_iq, stanza_query); xmpp_stanza_release(stanza_query); room_info_data *info_data = (room_info_data *)malloc(sizeof(room_info_data)); info_data->cb = cb; info_data->ctx = ctx; info_data->user_data = user_data; xmpp_ua_id_handler_add(ctx->ua, _on_room_info, iq_id, info_data); xmpp_ua_send(ctx->ua, stanza_iq); xmpp_stanza_release(stanza_iq); return 0; }
static void zkmuc_unlock_room(zkmuc_ctx_t *ctx) { xmpp_stanza_t *iq = xmpp_stanza_new(_xmpp_ctx); char id[128]; xmpp_ua_get_unique_string(ctx->ua, id); xmpp_stanza_set_name(iq, "iq"); xmpp_stanza_set_id(iq, id); xmpp_stanza_set_type(iq, "set"); xmpp_stanza_set_attribute(iq, "to", ctx->room_id); xmpp_stanza_t *query = xmpp_stanza_new(_xmpp_ctx); xmpp_stanza_set_name(query, "query"); xmpp_stanza_set_ns(query, XMPP_NS_MUC_OWNER); xmpp_stanza_t *x = xmpp_stanza_new(_xmpp_ctx); xmpp_stanza_set_name(x, "x"); xmpp_stanza_set_ns(x, XMPP_NS_X); xmpp_stanza_set_type(x, "submit"); xmpp_stanza_t *field = xmpp_stanza_new(_xmpp_ctx); xmpp_stanza_set_name(field, "field"); xmpp_stanza_set_attribute(field, "var", "muc#roomconfig_roomname"); xmpp_stanza_t *stanza_value = xmpp_stanza_new(_xmpp_ctx); xmpp_stanza_set_name(stanza_value, "value"); xmpp_stanza_t *stanza_text = xmpp_stanza_new(_xmpp_ctx); xmpp_stanza_set_text(stanza_text, ctx->room_desc); xmpp_stanza_add_child(stanza_value, stanza_text); xmpp_stanza_release(stanza_text); xmpp_stanza_add_child(field, stanza_value); xmpp_stanza_release(stanza_value); xmpp_stanza_add_child(x, field); xmpp_stanza_release(field); xmpp_stanza_add_child(query, x); xmpp_stanza_release(x); xmpp_stanza_add_child(iq, query); xmpp_stanza_release(query); xmpp_ua_id_handler_add(ctx->ua, zkmuc_unlock_room_result, id, ctx); xmpp_ua_send(ctx->ua, iq); xmpp_stanza_release(iq); }
int register_user(mio_conn_t *conn, char *user, char *pass) { int err; mio_response_t *response = mio_response_new(); xmpp_stanza_t *iq = NULL, *query = NULL, *username = NULL, *username_tag = NULL, *password = NULL, *password_tag = NULL; mio_stanza_t *stanza = mio_stanza_new(conn); // Check if connection is active if (!conn->xmpp_conn->authenticated) { return MIO_ERROR_DISCONNECTED; } // Create a new user stanza iq = xmpp_stanza_new(conn->xmpp_conn->ctx); xmpp_stanza_set_name(iq, "iq"); xmpp_stanza_set_attribute(iq, "id", "reg2"); xmpp_stanza_set_type(iq, "set"); // Creqte query stanza query = xmpp_stanza_new(conn -> xmpp_conn -> ctx); xmpp_stanza_set_name(query,"query"); xmpp_stanza_set_ns(query,"jabber:iq:register"); // create username stanza username = xmpp_stanza_new(conn -> xmpp_conn -> ctx); username_tag = xmpp_stanza_new(conn -> xmpp_conn -> ctx); xmpp_stanza_set_name(username,"username"); xmpp_stanza_set_text(username_tag, user); // create password stanza password = xmpp_stanza_new(conn -> xmpp_conn -> ctx); password_tag = xmpp_stanza_new(conn -> xmpp_conn -> ctx); xmpp_stanza_set_name(password, "password"); xmpp_stanza_set_text(password_tag,pass); // create password stanza password = xmpp_stanza_new(conn -> xmpp_conn -> ctx); password_tag = xmpp_stanza_new(conn -> xmpp_conn -> ctx); xmpp_stanza_set_name(password, "password"); xmpp_stanza_set_text(password_tag,pass); // Build xmpp message xmpp_stanza_add_child(password, password_tag); xmpp_stanza_add_child(username, username_tag); xmpp_stanza_add_child(query, username); xmpp_stanza_add_child(query, password); xmpp_stanza_add_child(iq, query); stanza -> xmpp_stanza = iq; // Send out the stanza err = _mio_send_nonblocking(conn, stanza); // Release the stanzas mio_stanza_free(stanza); mio_response_free(response); return 0; }
void zkmuc_leave_room(zkmuc_ctx_t *ctx) { xmpp_stanza_t *prensece = xmpp_stanza_new(_xmpp_ctx); xmpp_stanza_set_name(prensece, "presence"); xmpp_stanza_set_attribute(prensece, "to", ctx->room_jid); xmpp_stanza_set_type(prensece, "unavailable"); xmpp_ua_send(ctx->ua, prensece); xmpp_stanza_release(prensece); }
void mood_publish(mood_callback_t callback, const char * const usermood, const char * const usertext) { xmpp_stanza_t *iq, *pubsub, *publish, *item, *mood, *stanza, *text; iq = xmpp_stanza_new(ctx); xmpp_stanza_set_name(iq, "iq"); xmpp_stanza_set_type(iq, "set"); xmpp_stanza_set_id(iq, "mood1"); /* FIXME */ pubsub = xmpp_stanza_new(ctx); xmpp_stanza_set_name(pubsub, "pubsub"); xmpp_stanza_set_ns(pubsub, NS_PUBSUB); xmpp_stanza_add_child(iq, pubsub); xmpp_stanza_release(pubsub); publish = xmpp_stanza_new(ctx); xmpp_stanza_set_name(publish, "publish"); xmpp_stanza_set_attribute(publish, "node", NS_MOOD); xmpp_stanza_add_child(pubsub, publish); xmpp_stanza_release(publish); item = xmpp_stanza_new(ctx); xmpp_stanza_set_name(item, "item"); xmpp_stanza_add_child(publish, item); xmpp_stanza_release(item); mood = xmpp_stanza_new(ctx); xmpp_stanza_set_name(mood, "mood"); xmpp_stanza_set_ns(mood, NS_MOOD); xmpp_stanza_add_child(item, mood); xmpp_stanza_release(mood); if (usermood != NULL) { stanza = xmpp_stanza_new(ctx); xmpp_stanza_set_name(stanza, usermood); xmpp_stanza_add_child(mood, stanza); xmpp_stanza_release(stanza); } if (usertext != NULL) { text = xmpp_stanza_new(ctx); xmpp_stanza_set_name(text, "text"); xmpp_stanza_set_text(text, usertext); xmpp_stanza_add_child(mood, text); xmpp_stanza_release(text); } xmpp_id_handler_add(conn, mood_result_handler, xmpp_stanza_get_id(iq), callback); xmpp_send(conn, iq); xmpp_stanza_release(iq); }
void XMPP_IBB_SendPayload(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata, char* resp ) { static int seq = 0; int data_seq = 0; char Data_Seq_Buf[32]; char ID_Buf[32]; char* encoded_data; xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; xmpp_stanza_t *iq, *data, *text; iq = xmpp_stanza_new(ctx); data = xmpp_stanza_new(ctx); text = xmpp_stanza_new(ctx); xmpp_stanza_set_name(iq, "iq"); xmpp_stanza_set_type(iq, "set"); sprintf(ID_Buf, "ID-seq-%d", seq); seq++; xmpp_stanza_set_id(iq, ID_Buf); xmpp_stanza_set_attribute(iq, "to", xmpp_stanza_get_attribute(stanza, "from")); xmpp_stanza_set_attribute(iq, "from", xmpp_stanza_get_attribute(stanza, "to")); xmpp_stanza_set_name(data, "data"); xmpp_stanza_set_ns(data, XMLNS_IBB); xmpp_stanza_set_attribute(data, "sid", \ xmpp_stanza_get_attribute(xmpp_stanza_get_child_by_name(stanza, "data"), "sid")); sprintf(Data_Seq_Buf , "%d", data_seq); xmpp_stanza_set_attribute(data, "seq", Data_Seq_Buf); printf("\n[Response =%s]\n", resp); encoded_data = base64_encode(ctx, (unsigned char*)resp, strlen(resp)); xmpp_stanza_set_text_with_size(text, encoded_data, strlen(encoded_data)); xmpp_stanza_add_child(data, text); xmpp_stanza_add_child(iq, data); xmpp_send(conn, iq); seq++; free(resp); xmpp_free(ctx, encoded_data); xmpp_stanza_release(data); xmpp_stanza_release(iq); xmpp_stanza_release(text); xmpp_stanza_release(stanza); //copied by IBB IQ receiver handler }
void conflate_init_form(conflate_form_result *r) { if (!r->container) { r->container = xmpp_stanza_new(r->ctx); /* X data in the command response */ xmpp_stanza_set_name(r->container, "x"); xmpp_stanza_set_attribute(r->container, "xmlns", "jabber:x:data"); xmpp_stanza_set_type(r->container, "result"); add_and_release(r->cmd_res, r->container); } }
void XMPP_IBB_Ack_Send(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; xmpp_stanza_t *iq; iq = xmpp_stanza_new(ctx); xmpp_stanza_set_name(iq, "iq"); xmpp_stanza_set_type(iq, "result"); xmpp_stanza_set_id(iq, xmpp_stanza_get_attribute(stanza, "id")); xmpp_stanza_set_attribute(iq, "to", xmpp_stanza_get_attribute(stanza, "from")); xmpp_stanza_set_attribute(iq, "from", xmpp_stanza_get_attribute(stanza, "to")); xmpp_send(conn, iq); xmpp_stanza_release(iq); }
/* Create an IQ response */ static xmpp_stanza_t* create_reply(xmpp_ctx_t* ctx, xmpp_stanza_t* stanza) { xmpp_stanza_t* reply = xmpp_stanza_new(ctx); assert(reply); xmpp_stanza_set_name(reply, "iq"); xmpp_stanza_set_type(reply, "result"); if (xmpp_stanza_get_id(stanza)) { xmpp_stanza_set_id(reply, xmpp_stanza_get_id(stanza)); } xmpp_stanza_set_attribute(reply, "to", xmpp_stanza_get_attribute(stanza, "from")); return reply; }
void presence_subscription(const char *const jid, const jabber_subscr_t action) { assert(jid != NULL); Jid *jidp = jid_create(jid); autocomplete_remove(sub_requests_ac, jidp->barejid); const char *type = NULL; switch (action) { case PRESENCE_SUBSCRIBE: log_debug("Sending presence subscribe: %s", jid); type = STANZA_TYPE_SUBSCRIBE; break; case PRESENCE_SUBSCRIBED: log_debug("Sending presence subscribed: %s", jid); type = STANZA_TYPE_SUBSCRIBED; break; case PRESENCE_UNSUBSCRIBED: log_debug("Sending presence usubscribed: %s", jid); type = STANZA_TYPE_UNSUBSCRIBED; break; default: break; } if (!type) { log_error("Attempt to send unknown subscription action: %s", jid); return; } xmpp_ctx_t * const ctx = connection_get_ctx(); xmpp_stanza_t *presence = xmpp_presence_new(ctx); char *id = create_unique_id("sub"); xmpp_stanza_set_id(presence, id); free(id); xmpp_stanza_set_type(presence, type); xmpp_stanza_set_to(presence, jidp->barejid); jid_destroy(jidp); _send_presence_stanza(presence); xmpp_stanza_release(presence); }
xmpp_stanza_t * stanza_create_room_leave_presence(xmpp_ctx_t *ctx, const char * const room, const char * const nick) { GString *full_jid = g_string_new(room); g_string_append(full_jid, "/"); g_string_append(full_jid, nick); xmpp_stanza_t *presence = xmpp_stanza_new(ctx); xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE); xmpp_stanza_set_type(presence, STANZA_TYPE_UNAVAILABLE); xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_jid->str); g_string_free(full_jid, TRUE); return presence; }
xmpp_ibb_session_t *xmpp_ibb_open(xmpp_conn_t * const conn, char * const peer, char * const sid) { xmpp_ibb_session_t *sess; xmpp_stanza_t *iq, *open; xmpp_ctx_t *ctx; const char *jid = xmpp_conn_get_bound_jid(conn); char sizetemp[6] = ""; int size; if (peer == NULL || strlen(peer) == 0) { return NULL; } sess = _ibb_session_init(conn, peer, sid); if (sess == NULL) { return NULL; } size = snprintf(sizetemp, sizeof(sizetemp), "%d", sess->block_size); if (size < sizeof(sizetemp)) { sizetemp[size] = '\0'; } nmtoken_generate(sess->id, 8); ctx = xmpp_conn_get_context(conn); iq = xmpp_stanza_new(ctx); xmpp_stanza_set_name(iq, "iq"); xmpp_stanza_set_type(iq, "set"); xmpp_stanza_set_id(iq, sess->id); xmpp_stanza_set_attribute(iq, "from", jid); xmpp_stanza_set_attribute(iq, "to", sess->peer); open = xmpp_stanza_new(ctx); xmpp_stanza_set_name(open, "open"); xmpp_stanza_set_ns(open, XMLNS_IBB); xmpp_stanza_set_attribute(open, "block-size", sizetemp); xmpp_stanza_set_attribute(open, "sid", sess->sid); xmpp_stanza_set_attribute(open, "stanza", "iq"); xmpp_stanza_add_child(iq, open); xmpp_send(conn, iq); xmpp_stanza_release(open); xmpp_stanza_release(iq); ilist_add(g_list, sess); return sess; }
xmpp_stanza_t * stanza_create_roster_iq(xmpp_ctx_t *ctx) { xmpp_stanza_t *iq = xmpp_stanza_new(ctx); xmpp_stanza_set_name(iq, STANZA_NAME_IQ); xmpp_stanza_set_type(iq, STANZA_TYPE_GET); xmpp_stanza_set_id(iq, "roster"); xmpp_stanza_t *query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, STANZA_NAME_QUERY); xmpp_stanza_set_ns(query, XMPP_NS_ROSTER); xmpp_stanza_add_child(iq, query); xmpp_stanza_release(query); return iq; }
int version_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_stanza_t *reply, *query, *name, *version, *text; const char *ns; xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata; printf("Received version request from %s\n", xmpp_stanza_get_from(stanza)); reply = xmpp_stanza_reply(stanza); xmpp_stanza_set_type(reply, "result"); query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, "query"); ns = xmpp_stanza_get_ns(xmpp_stanza_get_children(stanza)); if (ns) { xmpp_stanza_set_ns(query, ns); } name = xmpp_stanza_new(ctx); xmpp_stanza_set_name(name, "name"); xmpp_stanza_add_child(query, name); xmpp_stanza_release(name); text = xmpp_stanza_new(ctx); xmpp_stanza_set_text(text, "libstrophe example bot"); xmpp_stanza_add_child(name, text); xmpp_stanza_release(text); version = xmpp_stanza_new(ctx); xmpp_stanza_set_name(version, "version"); xmpp_stanza_add_child(query, version); xmpp_stanza_release(version); text = xmpp_stanza_new(ctx); xmpp_stanza_set_text(text, "1.0"); xmpp_stanza_add_child(version, text); xmpp_stanza_release(text); xmpp_stanza_add_child(reply, query); xmpp_stanza_release(query); xmpp_send(conn, reply); xmpp_stanza_release(reply); return 1; }
xmpp_stanza_t * stanza_create_ping_iq(xmpp_ctx_t *ctx) { xmpp_stanza_t *iq = xmpp_stanza_new(ctx); xmpp_stanza_set_name(iq, STANZA_NAME_IQ); xmpp_stanza_set_type(iq, STANZA_TYPE_GET); xmpp_stanza_set_id(iq, "c2s1"); xmpp_stanza_t *ping = xmpp_stanza_new(ctx); xmpp_stanza_set_name(ping, STANZA_NAME_PING); xmpp_stanza_set_ns(ping, STANZA_NS_PING); xmpp_stanza_add_child(iq, ping); xmpp_stanza_release(ping); return iq; }
xmpp_stanza_t * stanza_create_chat_state(xmpp_ctx_t *ctx, const char * const recipient, const char * const state) { xmpp_stanza_t *msg, *chat_state; msg = xmpp_stanza_new(ctx); xmpp_stanza_set_name(msg, STANZA_NAME_MESSAGE); xmpp_stanza_set_type(msg, STANZA_TYPE_CHAT); xmpp_stanza_set_attribute(msg, STANZA_ATTR_TO, recipient); chat_state = xmpp_stanza_new(ctx); xmpp_stanza_set_name(chat_state, state); xmpp_stanza_set_ns(chat_state, STANZA_NS_CHATSTATES); xmpp_stanza_add_child(msg, chat_state); return msg; }
static void _presence_subscription(const char * const jid, const jabber_subscr_t action) { assert(jid != NULL); xmpp_ctx_t * const ctx = connection_get_ctx(); xmpp_conn_t * const conn = connection_get_conn(); const char *type = NULL; Jid *jidp = jid_create(jid); autocomplete_remove(sub_requests_ac, jidp->barejid); switch (action) { case PRESENCE_SUBSCRIBE: log_debug("Sending presence subscribe: %s", jid); type = STANZA_TYPE_SUBSCRIBE; break; case PRESENCE_SUBSCRIBED: log_debug("Sending presence subscribed: %s", jid); type = STANZA_TYPE_SUBSCRIBED; break; case PRESENCE_UNSUBSCRIBED: log_debug("Sending presence usubscribed: %s", jid); type = STANZA_TYPE_UNSUBSCRIBED; break; default: log_warning("Attempt to send unknown subscription action: %s", jid); break; } xmpp_stanza_t *presence = xmpp_stanza_new(ctx); char *id = create_unique_id("sub"); xmpp_stanza_set_id(presence, id); xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE); xmpp_stanza_set_type(presence, type); xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, jidp->barejid); xmpp_send(conn, presence); xmpp_stanza_release(presence); jid_destroy(jidp); free(id); }
int presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata; if (!strcmp(xmpp_stanza_get_name(stanza), "presence")) { xmpp_stanza_t *message, *text, *body; char username[1024]; char sendtext[1024]; printf("Enter the username you would like to send this message to: "); scanf("%[^\n]", username); char c = getchar(); printf("Type the message that you would like to send: "); scanf("%[^\n]", sendtext); message = xmpp_stanza_new(ctx); xmpp_stanza_set_name(message, "message"); xmpp_stanza_set_type(message, "chat"); xmpp_stanza_set_attribute(message, "to", username); body = xmpp_stanza_new(ctx); xmpp_stanza_set_name(body, "body"); text = xmpp_stanza_new(ctx); xmpp_stanza_set_text(text, sendtext); xmpp_stanza_add_child(body, text); xmpp_stanza_add_child(message, body); xmpp_send(conn, message); xmpp_stanza_release(message); } }
void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status, const int error, xmpp_stream_error_t * const stream_error, void * const userdata) { xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; xmpp_stanza_t *iq, *query; if (status == XMPP_CONN_CONNECT) { fprintf(stderr, "DEBUG: connected\n"); /* create iq stanza for request */ iq = xmpp_stanza_new(ctx); xmpp_stanza_set_name(iq, "iq"); xmpp_stanza_set_type(iq, "get"); xmpp_stanza_set_id(iq, "active1"); xmpp_stanza_set_attribute(iq, "to", "xxxxxxxxx.com"); query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, "query"); xmpp_stanza_set_ns(query, XMPP_NS_DISCO_ITEMS); xmpp_stanza_set_attribute(query, "node", "sessions"); xmpp_stanza_add_child(iq, query); /* we can release the stanza since it belongs to iq now */ xmpp_stanza_release(query); /* set up reply handler */ xmpp_id_handler_add(conn, handle_reply, "active1", ctx); /* send out the stanza */ xmpp_send(conn, iq); /* release the stanza */ xmpp_stanza_release(iq); } else { fprintf(stderr, "DEBUG: disconnected\n"); xmpp_stop(ctx); } }