void files(const char *from, const char *to, int error, xmpp_stanza_t *stanza, xmpp_conn_t *const conn, void *const userdata) { wlog("files()"); if (error == 0) { char *action_attr = xmpp_stanza_get_attribute(stanza, "action"); /* action attribute */ if (action_attr == NULL) { werr("xmpp_stanza_get_attribute attribute = action"); } wfatal(action_attr == NULL, "xmpp_stanza_get_attribute [attribute = action]"); if (strcmp(action_attr, "attributes") == 0) { files_attr(stanza); } else if (strcmp(action_attr, "list") == 0) { files_list(stanza); } else if (strncasecmp(action_attr, "read", 4) == 0) { files_read(stanza); } else { werr("Unknown action: %s", action_attr); } } else { werr("error stanza %s %s", xmpp_stanza_get_attribute(stanza, "path"), xmpp_stanza_get_attribute(stanza, "action")); } wlog("Return from files()"); }
static int _iq_handle_ping_get(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 *to = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TO); const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); if ((from == NULL) || (to == NULL)) { return 1; } xmpp_stanza_t *pong = xmpp_stanza_new(ctx); xmpp_stanza_set_name(pong, STANZA_NAME_IQ); xmpp_stanza_set_attribute(pong, STANZA_ATTR_TO, from); xmpp_stanza_set_attribute(pong, STANZA_ATTR_FROM, to); xmpp_stanza_set_attribute(pong, STANZA_ATTR_TYPE, STANZA_TYPE_RESULT); if (id != NULL) { xmpp_stanza_set_attribute(pong, STANZA_ATTR_ID, id); } xmpp_send(conn, pong); xmpp_stanza_release(pong); return 1; }
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; }
gboolean stanza_get_delay(xmpp_stanza_t * const stanza, GTimeVal *tv_stamp) { // first check for XEP-0203 delayed delivery xmpp_stanza_t *delay = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_DELAY); if (delay != NULL) { char *xmlns = xmpp_stanza_get_attribute(delay, STANZA_ATTR_XMLNS); if ((xmlns != NULL) && (strcmp(xmlns, "urn:xmpp:delay") == 0)) { char *stamp = xmpp_stanza_get_attribute(delay, STANZA_ATTR_STAMP); if ((stamp != NULL) && (g_time_val_from_iso8601(stamp, tv_stamp))) { return TRUE; } } } // otherwise check for XEP-0091 legacy delayed delivery // stanp format : CCYYMMDDThh:mm:ss xmpp_stanza_t *x = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_X); if (x != NULL) { char *xmlns = xmpp_stanza_get_attribute(x, STANZA_ATTR_XMLNS); if ((xmlns != NULL) && (strcmp(xmlns, "jabber:x:delay") == 0)) { char *stamp = xmpp_stanza_get_attribute(x, STANZA_ATTR_STAMP); if ((stamp != NULL) && (g_time_val_from_iso8601(stamp, tv_stamp))) { return TRUE; } } } return FALSE; }
static int _conference_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata) { xmpp_stanza_t *xns_conference = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CONFERENCE); char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); if (!from) { log_warning("Message received with no from attribute, ignoring"); return 1; } Jid *jidp = jid_create(from); if (!jidp) { return 1; } // XEP-0249 char *room = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_JID); if (!room) { jid_destroy(jidp); return 1; } char *reason = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_REASON); char *password = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_PASSWORD); sv_ev_room_invite(INVITE_DIRECT, jidp->barejid, room, reason, password); jid_destroy(jidp); return 1; }
static int _room_config_submit_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); const char *type = xmpp_stanza_get_type(stanza); const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); if (id != NULL) { log_debug("IQ room config submit handler fired, id: %s.", id); } else { log_debug("IQ room config submit handler fired."); } // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); handle_room_config_submit_result_error(from, error_message); free(error_message); return 0; } handle_room_config_submit_result(from); return 0; }
static void _respond_iq_with_error(xmpp_conn_t *conn, xmpp_stanza_t *stanza, const char *type, const char* condition) { char *id = xmpp_stanza_get_attribute(stanza, "id"); if (!id) return; xmpp_stanza_t *response = xmpp_stanza_new(_xmpp_ctx); xmpp_stanza_set_name(response, "iq"); xmpp_stanza_set_attribute(response, "type", "error"); xmpp_stanza_set_attribute(response, "id", id); char *req_from = xmpp_stanza_get_attribute(stanza, "from"); //当req_from为NULL时, to属性应该设为服务器, 不设应该默认是服务器; if (req_from) xmpp_stanza_set_attribute(response, "to", req_from); xmpp_stanza_t *stanza_error = xmpp_stanza_new(_xmpp_ctx); xmpp_stanza_set_name(stanza_error, "error"); xmpp_stanza_set_attribute(stanza_error, "type", type); xmpp_stanza_t *stanza_condition = xmpp_stanza_new(_xmpp_ctx); xmpp_stanza_set_name(stanza_condition, condition); xmpp_stanza_set_ns(stanza_condition, XMPP_NS_STANZA); xmpp_stanza_add_child(stanza_error, stanza_condition); xmpp_stanza_add_child(response, stanza_error); xmpp_stanza_release(stanza_condition); xmpp_stanza_release(stanza_error); xmpp_send(conn, response); xmpp_stanza_release(response); }
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; }
static int _receipt_received_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata) { xmpp_stanza_t *receipt = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_RECEIPTS); char *name = xmpp_stanza_get_name(receipt); if (g_strcmp0(name, "received") != 0) { return 1; } char *id = xmpp_stanza_get_attribute(receipt, STANZA_ATTR_ID); if (!id) { return 1; } char *fulljid = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); if (!fulljid) { return 1; } Jid *jidp = jid_create(fulljid); sv_ev_message_receipt(jidp->barejid, id); jid_destroy(jidp); return 1; }
int handle_reply(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_stanza_t *query, *item; char *type, *name; type = xmpp_stanza_get_type(stanza); if (strcmp(type, "error") == 0) fprintf(stderr, "ERROR: query failed\n"); else { query = xmpp_stanza_get_child_by_name(stanza, "query"); printf("Roster:\n"); for (item = xmpp_stanza_get_children(query); item; item = xmpp_stanza_get_next(item)) if ((name = xmpp_stanza_get_attribute(item, "name"))) printf("\t %s (%s) sub=%s\n", name, xmpp_stanza_get_attribute(item, "jid"), xmpp_stanza_get_attribute(item, "subscription")); else printf("\t %s sub=%s\n", xmpp_stanza_get_attribute(item, "jid"), xmpp_stanza_get_attribute(item, "subscription")); printf("END OF LIST\n"); } /* disconnect */ xmpp_disconnect(conn); return 0; }
static int _zkmuc_on_source_query(xmpp_ua_t *ua, xmpp_stanza_t *stanza, void *userdata) { query_source_data *data = (query_source_data *)userdata; char *from = xmpp_stanza_get_attribute(stanza, "from"); xmpp_stanza_t *x = xmpp_stanza_get_child_by_name(stanza, "x"); xmpp_stanza_t *item = xmpp_stanza_get_children(x); zkmuc_source_t *head = NULL; zkmuc_source_t **current = &head; while (item) { if (!strcmp("item", xmpp_stanza_get_name(item))) { *current = (zkmuc_source_t *)malloc(sizeof(zkmuc_source_t)); (*current)->cid = atoi(xmpp_stanza_get_attribute(item, "cid")); (*current)->sid = atoi(xmpp_stanza_get_attribute(item, "sid")); (*current)->description = strdup(xmpp_stanza_get_attribute(item, "desc")); (*current)->mcu = strdup(xmpp_stanza_get_attribute(item, "mcu")); current = &(*current)->next; } item = xmpp_stanza_get_next(item); } *current = NULL; data->cb(data->ctx, from, data->userdata, head); _zkmuc_free_all_remote_source(head); free(data); 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; }
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; }
/** * This handles a status response iq be printing it out */ int PresenceHandler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { // xmpp_stanza_t *reply; char *type; // char *id; char *sender; xmpp_ctx_t *ctx = (xmpp_ctx_t *) userdata; sdvpIdleCounter = 0; sdvpPingsSent = 0; // type is NULL if initial presence is received type = xmpp_stanza_get_type(stanza); if (type != NULL ) { if (strcmp(type, "error") == 0) { syslog(LOG_WARNING, "ERROR: Received presence with type of error\n"); } else { // id = xmpp_stanza_get_id(stanza); sender = xmpp_stanza_get_attribute(stanza, "from"); // reply = xmpp_stanza_new(ctx); // xmpp_stanza_set_name(reply, "presence"); // xmpp_stanza_set_type(reply, "result"); // if (id != NULL ) { // xmpp_stanza_set_id(reply, id); // } // xmpp_stanza_set_attribute(reply, "to", sender); // xmpp_send(conn, reply); // xmpp_stanza_release(reply); } } else { // id = xmpp_stanza_get_id(stanza); sender = strdup(xmpp_stanza_get_attribute(stanza, "from")); // Check if the presence is from the server user char *senderUsername; senderUsername = GetUsernameFromJid(sender); if (strcmp(sdvpServerUsername, senderUsername) == 0) { sdvpServerFullJid = strdup(sender); // Send status-request _SendRpcCall(conn, ctx, sdvpServerFullJid); } free(sender); // Dont send reply as the server should do this automatically // to all connected users on the roster // reply = xmpp_stanza_new(ctx); // xmpp_stanza_set_name(reply, "presence"); // xmpp_stanza_set_type(reply, "result"); // if (id != NULL ) { // xmpp_stanza_set_id(reply, id); // } // xmpp_stanza_set_attribute(reply, "to", sender); // xmpp_send(conn, reply); // xmpp_stanza_release(reply); } return 1; }
static gboolean _handle_carbons(xmpp_stanza_t *const stanza) { xmpp_stanza_t *carbons = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS); if (!carbons) { return FALSE; } char *name = xmpp_stanza_get_name(carbons); if ((g_strcmp0(name, "received") == 0) || (g_strcmp0(name, "sent")) == 0) { xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(carbons, STANZA_NS_FORWARD); xmpp_stanza_t *message = xmpp_stanza_get_child_by_name(forwarded, STANZA_NAME_MESSAGE); xmpp_ctx_t *ctx = connection_get_ctx(); gchar *to = xmpp_stanza_get_attribute(message, STANZA_ATTR_TO); gchar *from = xmpp_stanza_get_attribute(message, STANZA_ATTR_FROM); // happens when receive a carbon of a self sent message if (!to) to = from; Jid *jid_from = jid_create(from); Jid *jid_to = jid_create(to); Jid *my_jid = jid_create(jabber_get_fulljid()); // check for and deal with message xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(message, STANZA_NAME_BODY); if (body) { char *message_txt = xmpp_stanza_get_text(body); if (message_txt) { // check for pgp encrypted message char *enc_message = NULL; xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(message, STANZA_NS_ENCRYPTED); if (x) { enc_message = xmpp_stanza_get_text(x); } // if we are the recipient, treat as standard incoming message if(g_strcmp0(my_jid->barejid, jid_to->barejid) == 0){ sv_ev_incoming_carbon(jid_from->barejid, jid_from->resourcepart, message_txt, enc_message); // else treat as a sent message } else { sv_ev_outgoing_carbon(jid_to->barejid, message_txt, enc_message); } xmpp_free(ctx, message_txt); xmpp_free(ctx, enc_message); } } jid_destroy(jid_from); jid_destroy(jid_to); jid_destroy(my_jid); return TRUE; } return FALSE; }
static void files_list(xmpp_stanza_t *stanza) { int rc; /* Return code */ rc = pthread_mutex_lock(&mutex); wsyserr(rc != 0, "pthread_mutex_lock"); char *error_attr = xmpp_stanza_get_attribute(stanza, "error"); /* error attribute */ wfatal(error_attr == NULL, "no error attribute in files stanza"); if (strcmp(error_attr, "0") != 0) { wlog("Error in attributes: %s", error_attr); } else { char *path_attr = xmpp_stanza_get_attribute(stanza, "path"); /* path attribute */ wfatal(path_attr == NULL, "xmpp_stanza_get_attribute [attribute = path]"); xmpp_stanza_t *child = xmpp_stanza_get_children(stanza); while (child != NULL) { elem_t *elem = (elem_t *)malloc(sizeof(elem_t)); wsyserr(elem == NULL, "malloc"); elem->next = NULL; char *name = xmpp_stanza_get_name(child); wfatal(name == NULL, "xmpp_stanza_get_name"); if (strcmp(name, "directory") == 0) { elem->type = DIR; } else if (strcmp(name, "file") == 0) { elem->type = REG; } else { werr("Unknown name: %s", name); } char *filename_attr = xmpp_stanza_get_attribute(child, "filename"); wfatal(filename_attr == NULL, "xmpp_stanza_get_attribute [attribute = filename]"); elem->filename = strdup(filename_attr); wsyserr(elem->filename == NULL, "strdup"); /* Add elem in list */ if (root == NULL) { root = elem; } else { last->next = elem; } last = elem; child = xmpp_stanza_get_next(child); } } /* Data set */ signal_list = true; rc = pthread_cond_signal(&cond); wsyserr(rc != 0, "pthread_cond_signal"); rc = pthread_mutex_unlock(&mutex); wsyserr(rc != 0, "pthread_mutex_unlock"); }
/** * 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; }
int XMPP_IBB_Data_Process(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { char* intext; unsigned char *result; xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata; char *szSid, szSeq; // xmpp_ibb_session_t* ibb_ssn; szSid = \ xmpp_stanza_get_attribute(xmpp_stanza_get_child_by_name(stanza, "data"), "sid"); szSeq = \ xmpp_stanza_get_attribute(xmpp_stanza_get_child_by_name(stanza, "data"), "seq"); intext = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "data")); printf("[Sid=%s][Seq=%s][Raw Data=%s]\n", szSid, szSeq, intext); result = base64_decode(ctx, intext, strlen(intext)); printf("Decode result=%s\n", result); gRecv = malloc(strlen(result)+1); strcpy(gRecv, result); if(gStanza == NULL) gStanza = xmpp_stanza_copy(stanza); #if 0 //data queue function has not been verified. ibb_ssn = XMPP_Get_IBB_Session_Handle(szSid); if( ibb_ssn == NULL) { printf("Opened Session ID not found\n"); goto error; } xmpp_ibb_data_t* ibb_data_new = malloc(sizeof(xmpp_ibb_data_t)); ibb_data_new->seq_num = malloc(strlen(szSeq)+1); ibb_data_new->recv_data = malloc(strlen(result)+1); strcpy(ibb_data_new->seq_num, szSeq); strcpy(ibb_data_new->recv_data, result); XMPP_IBB_Add_Session_Data_Queue(ibb_ssn, ibb_data_new); #endif error: xmpp_free(ctx, szSid); xmpp_free(ctx, szSeq); xmpp_free(ctx, intext); xmpp_free(ctx, result); return 1; }
gboolean stanza_is_muc_self_presence(xmpp_stanza_t * const stanza, const char * const self_jid) { if (stanza == NULL) { return FALSE; } if (strcmp(xmpp_stanza_get_name(stanza), STANZA_NAME_PRESENCE) != 0) { return FALSE; } xmpp_stanza_t *x = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_X); if (x == NULL) { return FALSE; } char *ns = xmpp_stanza_get_ns(x); if (ns == NULL) { return FALSE; } if (strcmp(ns, STANZA_NS_MUC_USER) != 0) { return FALSE; } xmpp_stanza_t *x_children = xmpp_stanza_get_children(x); if (x_children == NULL) { return FALSE; } while (x_children != NULL) { if (strcmp(xmpp_stanza_get_name(x_children), STANZA_NAME_STATUS) == 0) { char *code = xmpp_stanza_get_attribute(x_children, STANZA_ATTR_CODE); if (strcmp(code, "110") == 0) { return TRUE; } } x_children = xmpp_stanza_get_next(x_children); } // for older server that don't send status 110 x_children = xmpp_stanza_get_children(x); while (x_children != NULL) { if (strcmp(xmpp_stanza_get_name(x_children), STANZA_NAME_ITEM) == 0) { char *jid = xmpp_stanza_get_attribute(x_children, STANZA_ATTR_JID); if (jid != NULL) { if (g_str_has_prefix(jid, self_jid)) { return TRUE; } } } x_children = xmpp_stanza_get_next(x_children); } return FALSE; }
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 }
static int _room_config_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); const char *type = xmpp_stanza_get_type(stanza); const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); if (id != NULL) { log_debug("IQ room config handler fired, id: %s.", id); } else { log_debug("IQ room config handler fired."); } // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); handle_room_configuration_form_error(from, error_message); free(error_message); return 0; } if (from == NULL) { log_warning("No from attribute for IQ config request result"); handle_room_configuration_form_error(from, "No from attribute for room cofig response."); return 0; } xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); if (query == NULL) { log_warning("No query element found parsing room config response"); handle_room_configuration_form_error(from, "No query element found parsing room config response"); return 0; } xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(query, STANZA_NS_DATA); if (x == NULL) { log_warning("No x element found with %s namespace parsing room config response", STANZA_NS_DATA); handle_room_configuration_form_error(from, "No form configuration options available"); return 0; } char *form_type = xmpp_stanza_get_attribute(x, STANZA_ATTR_TYPE); if (g_strcmp0(form_type, "form") != 0) { log_warning("x element not of type 'form' parsing room config response"); handle_room_configuration_form_error(from, "Form not of type 'form' parsing room config response."); return 0; } DataForm *form = form_create(x); handle_room_configure(from, form); return 0; }
static int _muc_user_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata) { xmpp_ctx_t *ctx = connection_get_ctx(); xmpp_stanza_t *xns_muc_user = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER); char *room = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); if (!room) { log_warning("Message received with no from attribute, ignoring"); return 1; } // XEP-0045 xmpp_stanza_t *invite = xmpp_stanza_get_child_by_name(xns_muc_user, STANZA_NAME_INVITE); if (!invite) { return 1; } char *invitor_jid = xmpp_stanza_get_attribute(invite, STANZA_ATTR_FROM); if (!invitor_jid) { log_warning("Chat room invite received with no from attribute"); return 1; } Jid *jidp = jid_create(invitor_jid); if (!jidp) { return 1; } char *invitor = jidp->barejid; char *reason = NULL; xmpp_stanza_t *reason_st = xmpp_stanza_get_child_by_name(invite, STANZA_NAME_REASON); if (reason_st) { reason = xmpp_stanza_get_text(reason_st); } char *password = NULL; xmpp_stanza_t *password_st = xmpp_stanza_get_child_by_name(xns_muc_user, STANZA_NAME_PASSWORD); if (password_st) { password = xmpp_stanza_get_text(password_st); } sv_ev_room_invite(INVITE_MEDIATED, invitor, room, reason, password); jid_destroy(jidp); if (reason) { xmpp_free(ctx, reason); } if (password) { xmpp_free(ctx, password); } return 1; }
static int _zkmuc_source_query(xmpp_ua_t *ua, xmpp_stanza_t *stanza, void *userdata) { zkmuc_ctx_t *ctx = (zkmuc_ctx_t *)userdata; char *from = xmpp_stanza_get_attribute(stanza, "from"); char *id = xmpp_stanza_get_id(stanza); if (id == NULL) { return 0; } xmpp_stanza_t *x = xmpp_stanza_get_child_by_name(stanza, "x"); if(x && xmpp_stanza_get_ns(x) && !strcmp(XMPP_NS_SOURCE, xmpp_stanza_get_ns(x))) { char *action = xmpp_stanza_get_attribute(x, "action"); if (!strcmp("query", action)) { xmpp_stanza_t *message = xmpp_stanza_new(_xmpp_ctx); xmpp_stanza_set_name(message, "message"); xmpp_stanza_set_attribute(message, "to", from); xmpp_stanza_set_id(message, id); xmpp_stanza_t *result_x = xmpp_stanza_new(_xmpp_ctx); xmpp_stanza_set_name(result_x, "x"); xmpp_stanza_set_ns(result_x, XMPP_NS_SOURCE); xmpp_stanza_set_attribute(result_x, "action", "result"); WaitForSingleObject(ctx->_mutex_4_source, INFINITE); zkmuc_source_t *item = ctx->head; while (item) { xmpp_stanza_t *stanza_item = xmpp_stanza_new(_xmpp_ctx); xmpp_stanza_set_name(stanza_item, "item"); char buf[32]; xmpp_stanza_set_attribute(stanza_item, "cid", itoa(item->cid, buf, 10)); xmpp_stanza_set_attribute(stanza_item, "sid", itoa(item->sid, buf, 10)); xmpp_stanza_set_attribute(stanza_item, "desc", item->description); xmpp_stanza_set_attribute(stanza_item, "mcu", item->mcu); xmpp_stanza_add_child(result_x, stanza_item); xmpp_stanza_release(stanza_item); item = item->next; } ReleaseMutex(ctx->_mutex_4_source); xmpp_stanza_add_child(message, result_x); xmpp_stanza_release(result_x); xmpp_ua_send(ctx->ua, message); xmpp_stanza_release(message); return 1; } } return 0; }
int handle_disco_info(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_stanza_t *query, *child; const char *from = NULL; xmppipe_state_t *state = userdata; from = xmpp_stanza_get_attribute(stanza, "from"); if (from == NULL) return 1; query = xmpp_stanza_get_child_by_name(stanza, "query"); if (query == NULL) return 1; for (child = xmpp_stanza_get_children(query); child != NULL; child = xmpp_stanza_get_next(child)) { const char *feature = NULL; const char *var = NULL; feature = xmpp_stanza_get_name(child); if (feature == NULL) continue; if (XMPPIPE_STRNEQ(feature, "feature")) continue; var = xmpp_stanza_get_attribute(child, "var"); if (var == NULL) continue; if (XMPPIPE_STRNEQ(var, "http://jabber.org/protocol/muc")) continue; state->mucservice = xmppipe_strdup(from); state->out = xmppipe_conference(state->room, state->mucservice); state->mucjid = xmppipe_mucjid(state->out, state->resource); if (state->opt & XMPPIPE_OPT_GROUPCHAT) { xmppipe_muc_join(state); xmppipe_muc_unlock(state); } return 0; } return 1; }
static int _iq_handle_discoitems_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { log_debug("Recieved diso#items response"); const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); const char *stanza_name = NULL; const char *item_jid = NULL; const char *item_name = NULL; GSList *items = NULL; if ((g_strcmp0(id, "confreq") == 0) || (g_strcmp0(id, "discoitemsreq") == 0)) { log_debug("Response to query: %s", id); xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); if (query != NULL) { xmpp_stanza_t *child = xmpp_stanza_get_children(query); while (child != NULL) { stanza_name = xmpp_stanza_get_name(child); if ((stanza_name != NULL) && (g_strcmp0(stanza_name, STANZA_NAME_ITEM) == 0)) { item_jid = xmpp_stanza_get_attribute(child, STANZA_ATTR_JID); if (item_jid != NULL) { DiscoItem *item = malloc(sizeof(struct disco_item_t)); item->jid = strdup(item_jid); item_name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME); if (item_name != NULL) { item->name = strdup(item_name); } else { item->name = NULL; } items = g_slist_append(items, item); } } child = xmpp_stanza_get_next(child); } } } if (g_strcmp0(id, "confreq") == 0) { handle_room_list(items, from); } else if (g_strcmp0(id, "discoitemsreq") == 0) { handle_disco_items(items, from); } g_slist_free_full(items, (GDestroyNotify)_item_destroy); return 1; }
static void files_attr(xmpp_stanza_t *stanza) { int rc; /* Return code */ rc = pthread_mutex_lock(&mutex); wsyserr(rc != 0, "pthread_mutex_lock"); char *error_attr = xmpp_stanza_get_attribute(stanza, "error"); /* error attribute */ wfatal(error_attr == NULL, "no error attribute in files stanza"); if (strcmp(error_attr, "0") != 0) { wlog("Error in attributes: %s", error_attr); attributes.is_valid = -1; } else { char *type_attr = xmpp_stanza_get_attribute(stanza, "type"); /* type attribute */ wfatal(type_attr == NULL, "no type attribute in files stanza"); if (strcmp(type_attr, "directory") == 0) { attributes.is_valid = 1; attributes.type = DIR; } else if (strcmp(type_attr, "file") == 0) { attributes.is_valid = 1; attributes.type = REG; } else { werr("Unknown type: %s", type_attr); attributes.is_valid = -1; } char *size_attr = xmpp_stanza_get_attribute(stanza, "size"); /* size */ if (size_attr == NULL) { werr("xmpp_stanza_get_attribute attribute = size (%s)", xmpp_stanza_get_attribute(stanza, "path")); attributes.size = 0; } else { char *endptr; /* strtol endptr */ long int size = strtol(size_attr, &endptr, 10); if (*endptr != '\0') { werr("strtol error: str = %s, val = %ld", size_attr, size); attributes.size = 0; } attributes.size = size; } } signal_attr = true; rc = pthread_cond_signal(&cond); wsyserr(rc != 0, "pthread_cond_signal"); rc = pthread_mutex_unlock(&mutex); wsyserr(rc != 0, "pthread_mutex_unlock"); }
int blocked_set_handler(xmpp_stanza_t *stanza) { xmpp_stanza_t *block = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BLOCK); if (block) { xmpp_stanza_t *child = xmpp_stanza_get_children(block); while (child) { if (g_strcmp0(xmpp_stanza_get_name(child), STANZA_NAME_ITEM) == 0) { const char *jid = xmpp_stanza_get_attribute(child, STANZA_ATTR_JID); if (jid) { blocked = g_list_append(blocked, strdup(jid)); autocomplete_add(blocked_ac, jid); } } child = xmpp_stanza_get_next(child); } } xmpp_stanza_t *unblock = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_UNBLOCK); if (unblock) { xmpp_stanza_t *child = xmpp_stanza_get_children(unblock); if (!child) { g_list_free_full(blocked, free); blocked = NULL; autocomplete_clear(blocked_ac); } else { while (child) { if (g_strcmp0(xmpp_stanza_get_name(child), STANZA_NAME_ITEM) == 0) { const char *jid = xmpp_stanza_get_attribute(child, STANZA_ATTR_JID); if (jid) { GList *found = g_list_find_custom(blocked, jid, (GCompareFunc)g_strcmp0); if (found) { blocked = g_list_remove_link(blocked, found); g_list_free_full(found, free); autocomplete_remove(blocked_ac, jid); } } } child = xmpp_stanza_get_next(child); } } } return 1; }
/* * Main callback function to dispatch XEP-0047 open/data/close stanzas * @param conn a Strophe connection object * @param stanza a Strophe stanza object received from sender. * @param userdata a callback interface to pass xmpp_ctx. */ int XMPP_IBB_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { char* szBlock_size; char* szSid; printf("XMPP IBB Handler\n"); if( xmpp_stanza_get_child_by_name(stanza, "open") != NULL) { printf(" =====XEP0047 Open Handle\n"); szBlock_size = \ xmpp_stanza_get_attribute( xmpp_stanza_get_child_by_name(stanza, "open"), "block-size"); szSid = \ xmpp_stanza_get_attribute(xmpp_stanza_get_child_by_name(stanza, "open"), "sid"); printf("XEP0047 IQ blocksize=%s sid=%s \n",szBlock_size, szSid ); #if 0 // The is used to support multi sesssion. not verified. xmpp_ibb_session_t* ibb_ssn_p; ibb_ssn_p = malloc(sizeof(xmpp_ibb_session_t)); ibb_ssn_p->sid = malloc(strlen(szSid)+1); ibb_ssn_p->szblock_size = malloc(strlen(szBlock_size)+1); ibb_ssn_p->ibb_data_queue = NULL; ibb_ssn_p->next = NULL; strcpy(ibb_ssn_p->sid, szBlock_size); strcpy(ibb_ssn_p->szblock_size, szSid); //=================> gXMPP_IBB_handle-> next = ibb_ssn_p; XMPP_IBB_Add_Session_Queue(ibb_ssn_p); #endif XMPP_IBB_Ack_Send(conn, stanza, userdata); } else if( xmpp_stanza_get_child_by_name(stanza, "data") != NULL) { XMPP_IBB_Ack_Send(conn, stanza, userdata); printf("========XEP0047 Data process\n"); XMPP_IBB_Data_Process(conn, stanza , userdata); } else if( xmpp_stanza_get_child_by_name(stanza, "close") ) { XMPP_IBB_Ack_Send(conn, stanza, userdata); } return 1; }
static int _message_error_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata) { char *id = xmpp_stanza_get_id(stanza); char *jid = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); xmpp_stanza_t *error_stanza = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR); char *type = NULL; if (error_stanza) { type = xmpp_stanza_get_attribute(error_stanza, STANZA_ATTR_TYPE); } // stanza_get_error never returns NULL char *err_msg = stanza_get_error_message(stanza); GString *log_msg = g_string_new("message stanza error received"); if (id) { g_string_append(log_msg, " id="); g_string_append(log_msg, id); } if (jid) { g_string_append(log_msg, " from="); g_string_append(log_msg, jid); } if (type) { g_string_append(log_msg, " type="); g_string_append(log_msg, type); } g_string_append(log_msg, " error="); g_string_append(log_msg, err_msg); log_info(log_msg->str); g_string_free(log_msg, TRUE); if (!jid) { ui_handle_error(err_msg); } else if (type && (strcmp(type, "cancel") == 0)) { log_info("Recipient %s not found: %s", jid, err_msg); Jid *jidp = jid_create(jid); chat_session_remove(jidp->barejid); jid_destroy(jidp); } else { ui_handle_recipient_error(jid, err_msg); } free(err_msg); return 1; }
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); }