void _private_chat_handler(xmpp_stanza_t *const stanza, const char *const fulljid) { xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); if (!body) { return; } char *message = xmpp_stanza_get_text(body); if (!message) { return; } GDateTime *timestamp = stanza_get_delay(stanza); if (timestamp) { sv_ev_delayed_private_message(fulljid, message, timestamp); g_date_time_unref(timestamp); } else { sv_ev_incoming_private_message(fulljid, message); } xmpp_ctx_t *ctx = connection_get_ctx(); xmpp_free(ctx, message); }
static int _chat_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata) { // ignore if type not chat or absent char *type = xmpp_stanza_get_type(stanza); if (!(g_strcmp0(type, "chat") == 0 || type == NULL)) { return 1; } // check if carbon message gboolean res = _handle_carbons(stanza); if (res) { return 1; } // ignore handled namespaces xmpp_stanza_t *conf = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CONFERENCE); xmpp_stanza_t *captcha = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CAPTCHA); if (conf || captcha) { return 1; } // some clients send the mucuser namespace with private messages // if the namespace exists, and the stanza contains a body element, assume its a private message // otherwise exit the handler xmpp_stanza_t *mucuser = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER); xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); if (mucuser && body == NULL) { return 1; } gchar *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); Jid *jid = jid_create(from); // private message from chat room use full jid (room/nick) if (muc_active(jid->barejid)) { _private_chat_handler(stanza, jid->fulljid); jid_destroy(jid); return 1; } // standard chat message, use jid without resource xmpp_ctx_t *ctx = connection_get_ctx(); GDateTime *timestamp = stanza_get_delay(stanza); if (body) { char *message = xmpp_stanza_get_text(body); if (message) { char *enc_message = NULL; xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_ENCRYPTED); if (x) { enc_message = xmpp_stanza_get_text(x); } sv_ev_incoming_message(jid->barejid, jid->resourcepart, message, enc_message, timestamp); xmpp_free(ctx, enc_message); _receipt_request_handler(stanza); xmpp_free(ctx, message); } } // handle chat sessions and states if (!timestamp && jid->resourcepart) { gboolean gone = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_GONE) != NULL; gboolean typing = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL; gboolean paused = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PAUSED) != NULL; gboolean inactive = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_INACTIVE) != NULL; if (gone) { sv_ev_gone(jid->barejid, jid->resourcepart); } else if (typing) { sv_ev_typing(jid->barejid, jid->resourcepart); } else if (paused) { sv_ev_paused(jid->barejid, jid->resourcepart); } else if (inactive) { sv_ev_inactive(jid->barejid, jid->resourcepart); } else if (stanza_contains_chat_state(stanza)) { sv_ev_activity(jid->barejid, jid->resourcepart, TRUE); } else { sv_ev_activity(jid->barejid, jid->resourcepart, FALSE); } } if (timestamp) g_date_time_unref(timestamp); jid_destroy(jid); return 1; }
static int _chat_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_ctx_t *ctx = connection_get_ctx(); gchar *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); Jid *jid = jid_create(from); // handle ddg searches if (strcmp(jid->barejid, "*****@*****.**") == 0) { xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); if (body != NULL) { char *message = xmpp_stanza_get_text(body); if (message != NULL) { prof_handle_duck_result(message); xmpp_free(ctx, message); } } jid_destroy(jid); return 1; // private message from chat room use full jid (room/nick) } else if (muc_room_is_active(jid)) { // determine if the notifications happened whilst offline GTimeVal tv_stamp; gboolean delayed = stanza_get_delay(stanza, &tv_stamp); // check for and deal with message xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); if (body != NULL) { char *message = xmpp_stanza_get_text(body); if (message != NULL) { if (delayed) { prof_handle_delayed_message(jid->str, message, tv_stamp, TRUE); } else { prof_handle_incoming_message(jid->str, message, TRUE); } xmpp_free(ctx, message); } } jid_destroy(jid); return 1; // standard chat message, use jid without resource } else { // determine chatstate support of recipient gboolean recipient_supports = FALSE; if (stanza_contains_chat_state(stanza)) { recipient_supports = TRUE; } // create or update chat session if (!chat_session_exists(jid->barejid)) { chat_session_start(jid->barejid, recipient_supports); } else { chat_session_set_recipient_supports(jid->barejid, recipient_supports); } // determine if the notifications happened whilst offline GTimeVal tv_stamp; gboolean delayed = stanza_get_delay(stanza, &tv_stamp); // deal with chat states if recipient supports them if (recipient_supports && (!delayed)) { if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL) { if (prefs_get_boolean(PREF_NOTIFY_TYPING) || prefs_get_boolean(PREF_INTYPE)) { prof_handle_typing(jid->barejid); } } else if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_GONE) != NULL) { prof_handle_gone(jid->barejid); } else if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PAUSED) != NULL) { // do something } else if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_INACTIVE) != NULL) { // do something } else { // handle <active/> // do something } } // check for and deal with message xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); if (body != NULL) { char *message = xmpp_stanza_get_text(body); if (message != NULL) { if (delayed) { prof_handle_delayed_message(jid->barejid, message, tv_stamp, FALSE); } else { prof_handle_incoming_message(jid->barejid, message, FALSE); } xmpp_free(ctx, message); } } jid_destroy(jid); return 1; } }
static int _groupchat_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata) { xmpp_ctx_t *ctx = connection_get_ctx(); char *message = NULL; char *room_jid = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); Jid *jid = jid_create(room_jid); // handle room subject xmpp_stanza_t *subject = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_SUBJECT); if (subject) { message = xmpp_stanza_get_text(subject); sv_ev_room_subject(jid->barejid, jid->resourcepart, message); xmpp_free(ctx, message); jid_destroy(jid); return 1; } // handle room broadcasts if (!jid->resourcepart) { xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); if (!body) { jid_destroy(jid); return 1; } message = xmpp_stanza_get_text(body); if (!message) { jid_destroy(jid); return 1; } sv_ev_room_broadcast(room_jid, message); xmpp_free(ctx, message); jid_destroy(jid); return 1; } if (!jid_is_valid_room_form(jid)) { log_error("Invalid room JID: %s", jid->str); jid_destroy(jid); return 1; } // room not active in profanity if (!muc_active(jid->barejid)) { log_error("Message received for inactive chat room: %s", jid->str); jid_destroy(jid); return 1; } xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); // check for and deal with message if (!body) { jid_destroy(jid); return 1; } message = xmpp_stanza_get_text(body); if (!message) { jid_destroy(jid); return 1; } // determine if the notifications happened whilst offline GDateTime *timestamp = stanza_get_delay(stanza); if (timestamp) { sv_ev_room_history(jid->barejid, jid->resourcepart, timestamp, message); g_date_time_unref(timestamp); } else { sv_ev_room_message(jid->barejid, jid->resourcepart, message); } xmpp_free(ctx, message); jid_destroy(jid); return 1; }
static int _groupchat_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_ctx_t *ctx = connection_get_ctx(); char *message = NULL; char *room_jid = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); Jid *jid = jid_create(room_jid); // handle room broadcasts if (jid->resourcepart == NULL) { xmpp_stanza_t *subject = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_SUBJECT); // handle subject if (subject != NULL) { message = xmpp_stanza_get_text(subject); if (message != NULL) { prof_handle_room_subject(jid->barejid, message); } jid_destroy(jid); return 1; // handle other room broadcasts } else { xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); if (body != NULL) { message = xmpp_stanza_get_text(body); if (message != NULL) { prof_handle_room_broadcast(room_jid, message); xmpp_free(ctx, message); } } jid_destroy(jid); return 1; } } if (!jid_is_valid_room_form(jid)) { log_error("Invalid room JID: %s", jid->str); jid_destroy(jid); return 1; } // room not active in profanity if (!muc_room_is_active(jid)) { log_error("Message recieved for inactive chat room: %s", jid->str); jid_destroy(jid); return 1; } // determine if the notifications happened whilst offline GTimeVal tv_stamp; gboolean delayed = stanza_get_delay(stanza, &tv_stamp); xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); // check for and deal with message if (body != NULL) { message = xmpp_stanza_get_text(body); if (message != NULL) { if (delayed) { prof_handle_room_history(jid->barejid, jid->resourcepart, tv_stamp, message); } else { prof_handle_room_message(jid->barejid, jid->resourcepart, message); } xmpp_free(ctx, message); } } jid_destroy(jid); return 1; }