void LM::Presentity::push_presence (const std::string resource, LmMessageNode* presence) { if (resource.empty ()) return; ResourceInfo info; LmMessageNode* priority = lm_message_node_find_child (presence, "priority"); if (priority != NULL) { info.priority = atoi (lm_message_node_get_value (priority)); } else { info.priority = 50; } LmMessageNode* status = lm_message_node_find_child (presence, "status"); if (status != NULL) { const gchar* status_str = lm_message_node_get_value (status); if (status_str != NULL) info.status = status_str; } LmMessageNode* away = lm_message_node_find_child (presence, "show"); if (away != NULL) { info.presence = lm_message_node_get_value (away); } else { info.presence = "available"; } const gchar* oftype = lm_message_node_get_attribute (presence, "type"); if (oftype != NULL) { if (oftype == std::string ("unavailable")) { info.presence = "unavailable"; } } infos[resource] = info; if (info.presence == "unavailable") { infos.erase (resource); } updated (); }
void action_search_result(LmConnection * connection, LmMessage * message, gpointer data) { LmMessageNode *node; LmMessageNode *child; GSList *list = NULL; node = lm_message_node_get_child(message->node, "query"); if (!strcmp(lm_message_node_get_attribute(node, "xmlns"), "jabber:iq:search")) { child = lm_message_node_get_child(node, "item"); if (!child) { signal_emit("jabber", "gui show message", g_strdup(_("No users have been found!")), "main-gui"); return; } while (child) { gchar *jid = (gchar *) lm_message_node_get_attribute(child, "jid"); GGaduContact *k; LmMessageNode *child_node; k = g_new0(GGaduContact, 1); k->id = g_strdup(jid ? jid : "?"); child_node = lm_message_node_get_child(node, "first"); if (child_node) k->first_name = g_strdup((gchar *) lm_message_node_get_value(child_node)); child_node = lm_message_node_get_child(node, "last"); if (child_node) k->last_name = g_strdup((gchar *) lm_message_node_get_value(child_node)); child_node = lm_message_node_get_child(node, "nick"); if (child_node) k->nick = g_strdup((gchar *) lm_message_node_get_value(child_node)); child_node = lm_message_node_get_child(node, "email"); if (child_node) k->email = g_strdup((gchar *) lm_message_node_get_value(child_node)); k->status = JABBER_STATUS_UNAVAILABLE; list = g_slist_append(list, k); child = child->next; } signal_emit("jabber", "gui show search results", list, "main-gui"); } }
static LmHandlerResult sasl_failure_cb (LmMessageHandler *handler, LmConnection *connection, LmMessage *message, gpointer user_data) { LmSASL *sasl; const gchar *ns; const gchar *reason = "unknown reason"; ns = lm_message_node_get_attribute (message->node, "xmlns"); if (!ns || strcmp (ns, XMPP_NS_SASL_AUTH) != 0) { return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; } sasl = (LmSASL *) user_data; if (message->node->children) { const gchar *r; r = lm_message_node_get_value (message->node->children); if (r) { reason = r; } } g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL, "%s: SASL authentication failed: %s", G_STRFUNC, reason); if (sasl->handler) { sasl->handler (sasl, sasl->connection, FALSE, reason); } return LM_HANDLER_RESULT_REMOVE_MESSAGE; }
LmHandlerResult harmony_get_device_email_callback(LmMessageHandler* handler, LmConnection *connection, LmMessage *message, gpointer void_harmony) { char *email; MP3tunesHarmony *harmony = MP3TUNES_HARMONY(void_harmony); LmMessageNode *harmony_email_node; (void)handler; (void)connection; harmony_email_node = lm_message_node_get_child(message->node, "email"); if (harmony_email_node) { email = g_strdup(lm_message_node_get_value(harmony_email_node)); sleep(2); /* FIXME: This exists because mp3tunes website logins cannot exceed 1 per second. When a device connects that has been fully authenticated previously it will rapidly reconnect three times as it grabs pin, then email, then connects completely. */ mp3tunes_harmony_set_email(harmony, email); g_free(email); close_connection(harmony); open_connection(harmony); return LM_HANDLER_RESULT_REMOVE_MESSAGE; } return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; }
/* * Получение значения одного из child */ gchar* lm_message_node_get_child_value(LmMessageNode *node, const gchar *child) { LmMessageNode *tmp; tmp = lm_message_node_find_child(node, child); if(tmp) return (gchar*)lm_message_node_get_value(tmp); else return NULL; }
//doc Loudmouth registerAccount(server, username, password) Registers a new account at XMPP server. Returns <code>true</code> or <code>false</code>. IoObject *IoLoudmouth_registerAccount(IoLoudmouth *self, IoObject *locals, IoMessage *m) { char *server = IoMessage_locals_cStringArgAt_(m, locals, 0), *username = IoMessage_locals_cStringArgAt_(m, locals, 1), *password = IoMessage_locals_cStringArgAt_(m, locals, 2), *error_message = "Unknown error"; LmConnection *connection = lm_connection_new(server); LmMessage *xmpp_msg, *xmpp_reply; LmMessageNode *query, *node; int success = 0; if(!lm_connection_open_and_block(connection, NULL)) { error_message = "Could not open connection"; success = 0; } else { xmpp_msg = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_SET); query = lm_message_node_add_child(xmpp_msg->node, "query", NULL); lm_message_node_set_attributes(query, "xmlns", "jabber:iq:register", NULL); lm_message_node_add_child(query, "username", username); lm_message_node_add_child(query, "password", password); xmpp_reply = lm_connection_send_with_reply_and_block(connection, xmpp_msg, NULL); lm_connection_close(connection, NULL); lm_connection_unref(connection); if(!xmpp_reply) { success = 0; error_message = "No reply from server"; } else { switch(lm_message_get_sub_type(xmpp_reply)) { case LM_MESSAGE_SUB_TYPE_RESULT: success = 1; break; case LM_MESSAGE_SUB_TYPE_ERROR: default: success = 0; node = lm_message_node_find_child(xmpp_reply->node, "error"); error_message = (node == NULL) ? lm_message_node_get_value(node) : "Unknown error"; lm_message_node_unref(node); } } lm_message_unref(xmpp_reply); lm_message_unref(xmpp_msg); lm_message_node_unref(query); } free(server); free(username); free(password); IOASSERT(success, error_message); free(error_message); return IOBOOL(self, success); }
const gchar* lm_message_node_get_child_value(LmMessageNode *node, const gchar *child) { LmMessageNode *tmp; tmp = lm_message_node_find_child(node, child); if (tmp) { const gchar *val = lm_message_node_get_value(tmp); return (val ? val : ""); } return NULL; }
static gboolean sasl_digest_md5_handle_challenge (LmSASL *sasl, LmMessageNode *node) { const gchar *encoded; gchar *challenge; gsize len; GHashTable *h; encoded = lm_message_node_get_value (node); if (!encoded) { g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL, "%s: got empty challenge!", G_STRFUNC); return FALSE; } challenge = (gchar *) base64_decode (encoded, &len); h = sasl_digest_md5_challenge_to_hash (challenge); g_free(challenge); if (!h) { g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL, "%s: server sent an invalid challenge", G_STRFUNC); if (sasl->handler) { sasl->handler (sasl, sasl->connection, FALSE, "server error"); } return FALSE; } switch (sasl->state) { case SASL_AUTH_STATE_DIGEST_MD5_STARTED: sasl_digest_md5_send_initial_response (sasl, h); break; case SASL_AUTH_STATE_DIGEST_MD5_SENT_AUTH_RESPONSE: sasl_digest_md5_check_server_response (sasl, h); break; default: g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL, "%s: server sent a challenge at the wrong time", G_STRFUNC); if (sasl->handler) { sasl->handler (sasl, sasl->connection, FALSE, "server error"); } return FALSE; } g_hash_table_destroy(h); return TRUE; }
LmHandlerResult harmony_iq_callback(LmMessageHandler* handler, LmConnection *connection, LmMessage *message, gpointer void_harmony) { GError *err = NULL; MP3tunesHarmony *harmony = MP3TUNES_HARMONY(void_harmony); LmMessageNode *harmony_download_node, *harmony_email_node; mp3tunes_harmony_download_t *download; gchar *email; (void)handler; harmony_download_node = lm_message_node_get_child(message->node, "download"); if (harmony_download_node) { mp3tunes_harmony_download_init(&download); mp3tunes_harmony_download_set_file_key(download, (char*)lm_message_node_get_attribute(harmony_download_node, "fileKey")); mp3tunes_harmony_download_set_file_name(download, (char*)lm_message_node_get_attribute(harmony_download_node, "fileName")); mp3tunes_harmony_download_set_file_format(download, (char*)lm_message_node_get_attribute(harmony_download_node, "fileFormat")); mp3tunes_harmony_download_set_file_size(download, atoi(lm_message_node_get_attribute(harmony_download_node, "fileSize"))); mp3tunes_harmony_download_set_track_title(download, (char*)lm_message_node_get_attribute(harmony_download_node, "trackTitle")); mp3tunes_harmony_download_set_artist_name(download, (char*)lm_message_node_get_attribute(harmony_download_node, "artistName")); mp3tunes_harmony_download_set_album_title(download, (char*)lm_message_node_get_attribute(harmony_download_node, "albumTitle")); mp3tunes_harmony_download_set_device_bitrate(download, (char*)lm_message_node_get_attribute(harmony_download_node, "deviceBitrate")); mp3tunes_harmony_download_set_file_bitrate(download, (char*)lm_message_node_get_attribute(harmony_download_node, "fileBitrate")); download_pending_emit(harmony, download); mp3tunes_harmony_add_download_to_queue(harmony, download); harmony_success_reply(connection, message, &err); if (err != NULL) { error_emit(harmony, MP3TUNES_HARMONY_ERROR_MISC, "Sending success reply failed", err); } return LM_HANDLER_RESULT_REMOVE_MESSAGE; } harmony_email_node = lm_message_node_get_child(message->node, "email"); if (harmony_email_node) { email = g_strdup(lm_message_node_get_value(harmony_email_node)); mp3tunes_harmony_set_email(harmony, email); g_free(email); harmony_success_reply(connection, message, &err); if (err != NULL) { error_emit(harmony, MP3TUNES_HARMONY_ERROR_MISC, "Sending success reply failed", err); } close_connection(harmony); open_connection(harmony); return LM_HANDLER_RESULT_REMOVE_MESSAGE; } return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; }
/** * @brief A function to handle incoming jingle action * @param action The action which have been received * @param data Contain the JingleFT of the content concerned * @param node The node himself * @return TRUE if the action was handled, FALSE otherwise */ static JingleHandleStatus handle(JingleAction action, gconstpointer data, LmMessageNode *node, GError **err) { if (action == JINGLE_SESSION_INFO) { if (!g_strcmp0(lm_message_node_get_attribute(node, "xmlns"), NS_JINGLE_APP_FT_INFO) && !g_strcmp0(node->name, "hash")) { ((JingleFT *)data)->hash = g_strdup(lm_message_node_get_value(node)); return JINGLE_STATUS_HANDLED; } return JINGLE_STATUS_NOT_HANDLED; } return JINGLE_STATUS_NOT_HANDLED; }
LmHandlerResult LM::HeapRoster::handle_message (LmConnection* /*connection*/, LmMessage* message) { LmHandlerResult result = LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; LmMessageNode* node = lm_message_get_node (message); const gchar* from_c = lm_message_node_get_attribute (node, "from"); const gchar* type_attr = lm_message_node_get_attribute (node, "type"); std::string base_jid; if (from_c != 0) { std::string from (from_c); std::string::size_type index = from.find ('/'); base_jid = std::string (from, 0, index); } PresentityPtr item = find_item (base_jid); if (item && (type_attr == NULL || (type_attr != NULL && g_strcmp0 (type_attr, "normal") == 0) || (type_attr != NULL && g_strcmp0 (type_attr, "chat") == 0))) { // let's imagine it's a basic chat message LmMessageNode* body = lm_message_node_find_child (node, "body"); if (body && lm_message_node_get_value (body) != NULL) { result = LM_HANDLER_RESULT_REMOVE_MESSAGE; Ekiga::Message::payload_type payload; payload["text/plain"] = lm_message_node_get_value (body); dialect->push_message (item, payload); } // it could also be an avatar or a pubsub event or... } return result; }
static gboolean hippo_block_netflix_movie_update_from_xml (HippoBlock *block, HippoDataCache *cache, LmMessageNode *node) { HippoBlockNetflixMovie *block_netflix = HIPPO_BLOCK_NETFLIX_MOVIE(block); LmMessageNode *netflix_node, *queue_node, *description_node; LmMessageNode *child_node; HippoPerson *user; const char *image_url; if (!HIPPO_BLOCK_CLASS(hippo_block_netflix_movie_parent_class)->update_from_xml(block, cache, node)) return FALSE; if (!hippo_xml_split(cache, node, NULL, "netflixMovie", HIPPO_SPLIT_NODE, &netflix_node, "description", HIPPO_SPLIT_NODE | HIPPO_SPLIT_OPTIONAL, &description_node, NULL)) return FALSE; if (!hippo_xml_split(cache, netflix_node, NULL, "queue", HIPPO_SPLIT_NODE, &queue_node, "userId", HIPPO_SPLIT_PERSON, &user, NULL)) return FALSE; for (child_node = queue_node->children; child_node; child_node = child_node->next) { HippoNetflixMovie *movie; if (strcmp(child_node->name, "movie") != 0) continue; movie = hippo_netflix_movie_new_from_xml(cache, child_node); if (movie != NULL) { block_netflix->queue = g_list_append(block_netflix->queue, movie); } } if (!hippo_xml_split(cache, queue_node, NULL, "imageUrl", HIPPO_SPLIT_STRING, &image_url, NULL)) return FALSE; block_netflix->image_url = g_strdup(image_url); hippo_block_abstract_person_set_user(HIPPO_BLOCK_ABSTRACT_PERSON(block_netflix), user); if (description_node != NULL) { block_netflix->description = g_strdup(lm_message_node_get_value(description_node)); } return TRUE; }
static gboolean hippo_block_generic_update_from_xml (HippoBlock *block, HippoDataCache *cache, LmMessageNode *node) { /* HippoBlockGeneric *block_generic = HIPPO_BLOCK_GENERIC(block); */ LmMessageNode *description_node; LmMessageNode *thumbnails_node; const char *description; HippoThumbnails *thumbnails; if (!HIPPO_BLOCK_CLASS(hippo_block_generic_parent_class)->update_from_xml(block, cache, node)) return FALSE; description_node = NULL; thumbnails_node = NULL; if (!hippo_xml_split(cache, node, NULL, "description", HIPPO_SPLIT_NODE | HIPPO_SPLIT_OPTIONAL, &description_node, "thumbnails", HIPPO_SPLIT_NODE | HIPPO_SPLIT_OPTIONAL, &thumbnails_node, NULL)) return FALSE; description = NULL; if (description_node != NULL) { description = lm_message_node_get_value(description_node); } thumbnails = NULL; if (thumbnails_node != NULL) { thumbnails = hippo_thumbnails_new_from_xml(cache, thumbnails_node); if (thumbnails == NULL) g_warning("Failed to parse <thumbnails> node"); else g_debug("Parsed %d thumbnails", hippo_thumbnails_get_count(thumbnails)); } g_object_set(G_OBJECT(block), "description", description, "thumbnails", thumbnails, NULL); if (thumbnails != NULL) g_object_unref(thumbnails); return TRUE; }
LmHandlerResult harmony_get_session_id_callback(LmMessageHandler* handler, LmConnection *connection, LmMessage *message, gpointer void_harmony) { char *session_id; MP3tunesHarmony *harmony = MP3TUNES_HARMONY(void_harmony); LmMessageNode *harmony_session_node; (void)handler; (void)connection; harmony_session_node = lm_message_node_get_child(message->node, "sessionId"); if (harmony_session_node) { session_id = g_strdup(lm_message_node_get_value(harmony_session_node)); harmony->mp3tunes_locker->session_id = session_id; harmony->sid_state = MP3TUNES_HARMONY_SID_STATE_READY; harmony_reprocess_queue(harmony); return LM_HANDLER_RESULT_REMOVE_MESSAGE; } return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; }
LmHandlerResult harmony_get_device_pin_callback(LmMessageHandler* handler, LmConnection *connection, LmMessage *message, gpointer void_harmony) { char *pin; MP3tunesHarmony *harmony = MP3TUNES_HARMONY(void_harmony); LmMessageNode *harmony_pin_node; (void)handler; (void)connection; harmony_pin_node = lm_message_node_get_child(message->node, "pin"); if (harmony_pin_node) { pin = g_strdup(lm_message_node_get_value(harmony_pin_node)); mp3tunes_harmony_set_pin(harmony, pin); g_free(pin); close_connection(harmony); open_connection(harmony); return LM_HANDLER_RESULT_REMOVE_MESSAGE; } return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; }
LmHandlerResult xmpp_mesg_handler(LmMessageHandler *h, LmConnection *c, LmMessage *m, gpointer udata) { const char *from, *to, *body; LmMessageNode *node; from = lm_message_node_get_attribute(m->node, "from"); to = lm_message_node_get_attribute(m->node, "to"); node = lm_message_node_get_child(m->node, "body"); if(node && (body = lm_message_node_get_value(node))) { ui_tab_print_message(from, body); lua_msg_callback(from, to, body); } /* we're actually ignoring <subject> and <thread> elements, * as I've never actually seen them being used. If you do, and you care, * feel obliged to mail me and yell at me */ return LM_HANDLER_RESULT_REMOVE_MESSAGE; UNUSED(h); UNUSED(c); UNUSED(udata); } /* xmpp_mesg_handler */
HippoFeedEntry* hippo_feed_entry_new_from_xml (HippoDataCache *cache, LmMessageNode *node) { const char *title; const char *href; const char *description; HippoFeedEntry *entry; if (!hippo_xml_split(cache, node, NULL, "title", HIPPO_SPLIT_STRING, &title, "href", HIPPO_SPLIT_URI_ABSOLUTE, &href, NULL)) return NULL; description = lm_message_node_get_value(node); entry = g_object_new(HIPPO_TYPE_FEED_ENTRY, "description", description, "title", title, "url", href, NULL); return entry; }
static gboolean sasl_set_auth_type (LmSASL *sasl, LmMessageNode *mechanisms) { LmMessageNode *m; const gchar *ns; sasl->auth_type = 0; ns = lm_message_node_get_attribute (mechanisms, "xmlns"); if (!ns || strcmp (ns, XMPP_NS_SASL_AUTH) != 0) { return FALSE; } for (m = mechanisms->children; m; m = m->next) { const gchar *name; name = lm_message_node_get_value (m); if (!name) { continue; } if (strcmp (name, "PLAIN") == 0) { sasl->auth_type |= AUTH_TYPE_PLAIN; continue; } if (strcmp (name, "DIGEST-MD5") == 0) { sasl->auth_type |= AUTH_TYPE_DIGEST; continue; } g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL, "%s: unknown SASL auth mechanism: %s", G_STRFUNC, name); } return TRUE; }
gboolean jid_reg(struct _jid *jid, GMainContext *context) { LmConnection *reg_connect; LmMessage *m, *reply; LmMessageNode *query, *node; GError *error = NULL; // Проверяем context if(!context) context = g_main_context_default(); // Подключаемся reg_connect = lm_connection_new_with_context(jid->server, context); // Настраиваем ssl /* if(jid->use_ssl) { LmSSL *ssl; // Проверяем поддержку ssl if(!lm_ssl_is_supported()) { g_print("Your Loudmouth doesn't support SSL. Reinstall loudmouth.\n"); jid->use_ssl = FALSE; } g_print("Configure ssl\n"); ssl = lm_ssl_new(NULL, LM_SSL_RESPONSE_CONTINUE, NULL, NULL); lm_connection_set_ssl(reg_connect, ssl); lm_ssl_unref(ssl); lm_connection_set_port(reg_connect, LM_CONNECTION_DEFAULT_PORT_SSL); } */ // Проверяем коннект if(!lm_connection_open_and_block(reg_connect, &error)) { fprintf(stderr, "Failed to open connection: %s\n", error->message); return FALSE; } // Определяем сообщение m = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_SET); // Составляем запрос query = lm_message_node_add_child(m->node, "query", NULL); lm_message_node_set_attributes(query, "xmlns", "jabber:iq:register", NULL); lm_message_node_add_child(query, "username", jid->username); lm_message_node_add_child(query, "password", jid->password); // Отпревляем сообщение и ждём ответ reply = lm_connection_send_with_reply_and_block(reg_connect, m, &error); if(!reply) { fprintf(stderr, "Failed to send registration request on server \"%s\":\n %s\n", jid->server, error->message); return FALSE; } //Закрываем соединение lm_connection_close(reg_connect, NULL); lm_connection_unref(reg_connect); // Проверяем ответ switch(lm_message_get_sub_type(reply)) { case LM_MESSAGE_SUB_TYPE_RESULT: g_print("Succeeded in register account '%s@%s'\n", jid->username, jid->server); break; case LM_MESSAGE_SUB_TYPE_ERROR: default: g_print("Failed to register account '%s@%s' due to: ", jid->username, jid->server); node = lm_message_node_find_child(reply->node, "error"); if(node) g_print("%s\n", lm_message_node_get_value (node)); else g_print("Unknown error\n"); return FALSE; break; } return TRUE; }
LmHandlerResult handle_iq_roster(LmMessageHandler *h, LmConnection *c, LmMessage *m, gpointer ud) { LmMessageNode *y; const char *fjid, *name, *group, *sub, *ask; char *cleanalias; enum subscr esub; int need_refresh = FALSE; guint roster_type; y = lm_message_node_find_child(lm_message_node_find_xmlns(m->node, NS_ROSTER), "item"); for ( ; y; y = y->next) { char *name_tmp = NULL; fjid = lm_message_node_get_attribute(y, "jid"); name = lm_message_node_get_attribute(y, "name"); sub = lm_message_node_get_attribute(y, "subscription"); ask = lm_message_node_get_attribute(y, "ask"); if (lm_message_node_find_child(y, "group")) group = lm_message_node_get_value(lm_message_node_find_child(y, "group")); else group = NULL; if (!fjid) continue; cleanalias = jidtodisp(fjid); esub = sub_none; if (sub) { if (!strcmp(sub, "to")) esub = sub_to; else if (!strcmp(sub, "from")) esub = sub_from; else if (!strcmp(sub, "both")) esub = sub_both; else if (!strcmp(sub, "remove")) esub = sub_remove; } if (esub == sub_remove) { roster_del_user(cleanalias); scr_LogPrint(LPRINT_LOGNORM, "Buddy <%s> has been removed " "from the roster", cleanalias); g_free(cleanalias); need_refresh = TRUE; continue; } if (ask && !strcmp(ask, "subscribe")) esub |= sub_pending; if (!name) { if (!settings_opt_get_int("roster_hide_domain")) { name = cleanalias; } else { char *p; name = name_tmp = g_strdup(cleanalias); p = strchr(name_tmp, JID_DOMAIN_SEPARATOR); if (p) *p = '\0'; } } // Tricky... :-\ My guess is that if there is no JID_DOMAIN_SEPARATOR, // this is an agent. if (strchr(cleanalias, JID_DOMAIN_SEPARATOR)) roster_type = ROSTER_TYPE_USER; else roster_type = ROSTER_TYPE_AGENT; roster_add_user(cleanalias, name, group, roster_type, esub, 1); g_free(name_tmp); g_free(cleanalias); } // Acknowledge IQ message if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_SET) { LmMessage *result; result = lm_message_new_iq_from_query(m, LM_MESSAGE_SUB_TYPE_RESULT); lm_connection_send(c, result, NULL); lm_message_unref(result); } buddylist_build(); update_roster = TRUE; if (need_refresh) scr_update_buddy_window(); return LM_HANDLER_RESULT_REMOVE_MESSAGE; }
static LmHandlerResult handle_iq_command_leave_groupchats(LmMessageHandler *h, LmConnection *c, LmMessage *m, gpointer ud) { const char *action, *node; char *sessionid; LmMessage *iq; LmMessageNode *command, *x; x = lm_message_node_get_child(m->node, "command"); if (!x) return LM_HANDLER_RESULT_REMOVE_MESSAGE; action = lm_message_node_get_attribute(x, "action"); node = lm_message_node_get_attribute(x, "node"); sessionid = (char*)lm_message_node_get_attribute(x, "sessionid"); iq = lm_message_new_iq_from_query(m, LM_MESSAGE_SUB_TYPE_RESULT); command = lm_message_node_add_child(iq->node, "command", NULL); lm_message_node_set_attributes(command, "node", node, "xmlns", NS_COMMANDS, NULL); if (!sessionid) { LmMessageNode *field; sessionid = generate_session_id("leave-groupchats"); lm_message_node_set_attribute(command, "sessionid", sessionid); g_free(sessionid); sessionid = NULL; lm_message_node_set_attribute(command, "status", "executing"); x = lm_message_node_add_child(command, "x", NULL); lm_message_node_set_attributes(x, "type", "form", "xmlns", "jabber:x:data", NULL); lm_message_node_add_child(x, "title", "Leave groupchat(s)"); lm_message_node_add_child(x, "instructions", "What groupchats do you want to leave?"); field = lm_message_node_add_child(x, "field", NULL); lm_message_node_set_attributes(field, "type", "hidden", "var", "FORM_TYPE", NULL); lm_message_node_add_child(field, "value", "http://jabber.org/protocol/rc"); field = lm_message_node_add_child(x, "field", NULL); lm_message_node_set_attributes(field, "type", "list-multi", "var", "groupchats", "label", "Groupchats: ", NULL); lm_message_node_add_child(field, "required", NULL); foreach_buddy(ROSTER_TYPE_ROOM, &_callback_foreach_buddy_groupchat, field); // TODO: return an error if we are not connected to groupchats } else if (action && !strcmp(action, "cancel")) { lm_message_node_set_attribute(command, "status", "canceled"); } else { // (if sessionid and not canceled) LmMessageNode *form = lm_message_node_find_xmlns(x, "jabber:x:data");// TODO if (form) { LmMessageNode *field; lm_message_node_set_attribute(command, "status", "completed"); // TODO: implement sth. like "field?var=groupchats" in xmlnode... field = lm_message_node_get_child(form, "field"); while (field && strcmp("groupchats", lm_message_node_get_attribute(field, "var"))) field = field->next; if (field) for (x = field->children ; x ; x = x->next) { if (!strcmp (x->name, "value")) { GList* b = buddy_search_jid(lm_message_node_get_value(x)); if (b) cmd_room_leave(b->data, "Requested by remote command"); } } lm_message_node_add_dataform_result(command, "Groupchats have been left"); } } if (sessionid) lm_message_node_set_attribute(command, "sessionid", sessionid); lm_connection_send(c, iq, NULL); lm_message_unref(iq); return LM_HANDLER_RESULT_REMOVE_MESSAGE; }
static LmHandlerResult handle_iq_command_set_status(LmMessageHandler *h, LmConnection *c, LmMessage *m, gpointer ud) { const char *action, *node; char *sessionid; LmMessage *iq; LmMessageNode *command, *x, *y; const struct adhoc_status *s; x = lm_message_node_get_child(m->node, "command"); action = lm_message_node_get_attribute(x, "action"); node = lm_message_node_get_attribute(x, "node"); sessionid = (char *)lm_message_node_get_attribute(x, "sessionid"); iq = lm_message_new_iq_from_query(m, LM_MESSAGE_SUB_TYPE_RESULT); command = lm_message_node_add_child(iq->node, "command", NULL); lm_message_node_set_attribute(command, "node", node); lm_message_node_set_attribute(command, "xmlns", NS_COMMANDS); if (!sessionid) { sessionid = generate_session_id("set-status"); lm_message_node_set_attribute(command, "sessionid", sessionid); g_free(sessionid); sessionid = NULL; lm_message_node_set_attribute(command, "status", "executing"); x = lm_message_node_add_child(command, "x", NULL); lm_message_node_set_attribute(x, "type", "form"); lm_message_node_set_attribute(x, "xmlns", "jabber:x:data"); lm_message_node_add_child(x, "title", "Change Status"); lm_message_node_add_child(x, "instructions", "Choose the status and status message"); // TODO see if factorisation is possible y = lm_message_node_add_child(x, "field", NULL); lm_message_node_set_attribute(y, "type", "hidden"); lm_message_node_set_attribute(y, "var", "FORM_TYPE"); lm_message_node_add_child(y, "value", "http://jabber.org/protocol/rc"); y = lm_message_node_add_child(x, "field", NULL); lm_message_node_set_attributes(y, "type", "list-single", "var", "status", "label", "Status", NULL); lm_message_node_add_child(y, "required", NULL); // XXX: ugly lm_message_node_add_child(y, "value", adhoc_status_list[xmpp_getstatus()].name); for (s = adhoc_status_list; s->name; s++) { LmMessageNode *option = lm_message_node_add_child(y, "option", NULL); lm_message_node_add_child(option, "value", s->name); lm_message_node_set_attribute(option, "label", s->description); } // TODO add priority ? // I do not think this is useful, user should not have to care of the // priority like gossip and gajim do (misc) lm_message_node_set_attributes (lm_message_node_add_child(x, "field", NULL), "type", "text-multi", "var", "status-message", "label", "Message", NULL); } else if (action && !strcmp(action, "cancel")) { lm_message_node_set_attribute(command, "status", "canceled"); } else { // (if sessionid and not canceled) y = lm_message_node_find_xmlns(x, "jabber:x:data"); //x?xmlns=jabber:x:data if (y) { const char *value=NULL, *message=NULL; LmMessageNode *fields, *field; field = fields = lm_message_node_get_child(y, "field"); //field?var=status while (field && strcmp("status", lm_message_node_get_attribute(field, "var"))) field = field->next; field = lm_message_node_get_child(field, "value"); if (field) value = lm_message_node_get_value(field); field = fields; //field?var=status-message while (field && strcmp("status-message", lm_message_node_get_attribute(field, "var"))) field = field->next; field = lm_message_node_get_child(field, "value"); if (field) message = lm_message_node_get_value(field); if (value) { for (s = adhoc_status_list; !s->name || strcmp(s->name, value); s++); if (s->name) { char *status = g_strdup_printf("%s %s", s->status, message ? message : ""); cmd_setstatus(NULL, status); g_free(status); lm_message_node_set_attribute(command, "status", "completed"); lm_message_node_add_dataform_result(command, "Status has been changed"); } } } } if (sessionid) lm_message_node_set_attribute(command, "sessionid", sessionid); lm_connection_send(c, iq, NULL); lm_message_unref(iq); return LM_HANDLER_RESULT_REMOVE_MESSAGE; }
static LmHandlerResult ft_msg_msg_handler (LmMessageHandler *handler, LmConnection *conn, LmMessage *msg, gpointer user_data) { LmMessageNode *root, *body, *x; const char *from, *msg_str, *type; char *ts = NULL; char *new_from = NULL; root = lm_message_get_node (msg); if (!root) goto out; body = lm_message_node_get_child (root, "body"); if (!body) goto out; from = lm_message_node_get_attribute (msg->node, "from"); if (!from) goto out; msg_str = lm_message_node_get_value (body); type = lm_message_node_get_attribute (msg->node, "type"); if (type && g_ascii_strcasecmp (type, "chat") != 0) { PRINTF (_("[message of type '%s']"), type); goto out; } // Offline messages for (x = root->children; x != NULL; x = x->next) { if (!g_ascii_strcasecmp (x->name, "x")) { const char *xmlns = lm_message_node_get_attribute (x, "xmlns"); if (xmlns && !g_ascii_strcasecmp (xmlns, "jabber:x:delay")) { ts = parse_timestamp ((char *)lm_message_node_get_attribute (x, "stamp")); } } } set_hook_return (0); { FtRosterItem *item = NULL; char *nickname; new_from = g_strdup (from); item = ft_roster_lookup (new_from); if (!item) nickname = NULL; else nickname = item->nickname; scm_run_hook (ex_message_receive_hook, scm_list_n (ts ? scm_from_locale_string (ts) : scm_from_locale_string (""), scm_from_locale_string (new_from), nickname ? scm_from_locale_string (nickname) : scm_from_locale_string (""), scm_from_locale_string (msg_str), SCM_UNDEFINED)); } if (get_hook_return () == 1) goto out; PRINTF ("%s: %s", new_from, msg_str); out: if (ts) g_free (ts); if (new_from) g_free (new_from); return LM_HANDLER_RESULT_REMOVE_MESSAGE; }
static gboolean update_location_from_msg (GabbleConnection *conn, TpHandle contact, LmMessage *msg) { LmMessageNode *node; GHashTable *location = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_free, (GDestroyNotify) tp_g_value_slice_free); TpHandleRepoIface *contact_repo = tp_base_connection_get_handles ( (TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT); const gchar *from = tp_handle_inspect (contact_repo, contact); NodeIter i; const gchar *lang; node = lm_message_node_find_child (wocky_stanza_get_top_node (msg), "geoloc"); if (node == NULL) return FALSE; DEBUG ("LocationsUpdate for %s:", from); lang = lm_message_node_get_attribute (node, "xml:lang"); if (lang != NULL) { g_hash_table_insert (location, g_strdup ("language"), tp_g_value_slice_new_string (lang)); } build_mapping_tables (); for (i = node_iter (node); i; i = node_iter_next (i)) { LmMessageNode *subloc_node = node_iter_data (i); GValue *value = NULL; gchar *xmpp_name; const gchar *str; LocationMapping *mapping; xmpp_name = subloc_node->name; str = lm_message_node_get_value (subloc_node); if (str == NULL) continue; mapping = g_hash_table_lookup (xmpp_to_tp, xmpp_name); if (mapping == NULL) { DEBUG ("Unknown location attribute: %s\n", xmpp_name); continue; } if (mapping->type == G_TYPE_DOUBLE) { gdouble double_value; gchar *end; double_value = g_ascii_strtod (str, &end); if (end == str) continue; value = tp_g_value_slice_new_double (double_value); DEBUG ("\t - %s: %f", xmpp_name, double_value); } else if (strcmp (xmpp_name, "timestamp") == 0) { GTimeVal timeval; if (g_time_val_from_iso8601 (str, &timeval)) { value = tp_g_value_slice_new_int64 (timeval.tv_sec); DEBUG ("\t - %s: %s", xmpp_name, str); } else { DEBUG ("\t - %s: %s: unknown date format", xmpp_name, str); continue; } } else if (mapping->type == G_TYPE_STRING) { value = tp_g_value_slice_new_string (str); DEBUG ("\t - %s: %s", xmpp_name, str); } else { g_assert_not_reached (); } g_hash_table_insert (location, g_strdup (mapping->tp_name), value); } tp_svc_connection_interface_location_emit_location_updated (conn, contact, location); gabble_presence_cache_update_location (conn->presence_cache, contact, location); return TRUE; }
static LmHandlerResult cb_last(LmMessageHandler *h, LmConnection *c, LmMessage *m, gpointer user_data) { LmMessageNode *ansqry; const char *p, *bjid; char *buf, *tmp; // Check IQ result sender bjid = lm_message_get_from(m); if (!bjid) bjid = lm_connection_get_jid(lconnection); // No from means our JID... if (!bjid) { scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:last result (no sender name)."); return LM_HANDLER_RESULT_REMOVE_MESSAGE; } // Check for error message if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_ERROR) { scr_LogPrint(LPRINT_LOGNORM, "Received error IQ message (%s)", bjid); display_server_error(lm_message_node_get_child(m->node, "error"), NULL); return LM_HANDLER_RESULT_REMOVE_MESSAGE; } // Check message contents ansqry = lm_message_node_get_child(m->node, "query"); if (!ansqry) { scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:version result from <%s>!", bjid); return LM_HANDLER_RESULT_REMOVE_MESSAGE; } buf = g_strdup_printf("Received IQ:last result from <%s>", bjid); scr_LogPrint(LPRINT_LOGNORM, "%s", buf); // bjid should now really be the "bare JID", let's strip the resource tmp = strchr(bjid, JID_RESOURCE_SEPARATOR); if (tmp) *tmp = '\0'; scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0); g_free(buf); // Get result data... p = lm_message_node_get_attribute(ansqry, "seconds"); if (p) { long int s; GString *sbuf; sbuf = g_string_new("Idle time: "); s = atol(p); // Days if (s > 86400L) { g_string_append_printf(sbuf, "%ldd ", s/86400L); s %= 86400L; } // hh:mm:ss g_string_append_printf(sbuf, "%02ld:", s/3600L); s %= 3600L; g_string_append_printf(sbuf, "%02ld:%02ld", s/60L, s%60L); scr_WriteIncomingMessage(bjid, sbuf->str, 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); g_string_free(sbuf, TRUE); } else { scr_WriteIncomingMessage(bjid, "No idle time reported.", 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); } p = lm_message_node_get_value(ansqry); if (p) { buf = g_strdup_printf("Status message: %s", p); scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0); g_free(buf); } return LM_HANDLER_RESULT_REMOVE_MESSAGE; }
static void handle_vcard_node(const char *barejid, LmMessageNode *vcardnode) { LmMessageNode *x; const char *p; for (x = vcardnode->children ; x; x = x->next) { const char *data; enum vcard_attr vcard_attrib = 0; p = x->name; if (!p) continue; data = lm_message_node_get_value(x); if (!g_strcmp0(p, "FN")) display_vcard_item(barejid, "Name", vcard_attrib, data); else if (!g_strcmp0(p, "NICKNAME")) display_vcard_item(barejid, "Nickname", vcard_attrib, data); else if (!g_strcmp0(p, "URL")) display_vcard_item(barejid, "URL", vcard_attrib, data); else if (!g_strcmp0(p, "BDAY")) display_vcard_item(barejid, "Birthday", vcard_attrib, data); else if (!g_strcmp0(p, "TZ")) display_vcard_item(barejid, "Timezone", vcard_attrib, data); else if (!g_strcmp0(p, "TITLE")) display_vcard_item(barejid, "Title", vcard_attrib, data); else if (!g_strcmp0(p, "ROLE")) display_vcard_item(barejid, "Role", vcard_attrib, data); else if (!g_strcmp0(p, "DESC")) display_vcard_item(barejid, "Comment", vcard_attrib, data); else if (!g_strcmp0(p, "N")) { data = lm_message_node_get_child_value(x, "FAMILY"); display_vcard_item(barejid, "Family Name", vcard_attrib, data); data = lm_message_node_get_child_value(x, "GIVEN"); display_vcard_item(barejid, "Given Name", vcard_attrib, data); data = lm_message_node_get_child_value(x, "MIDDLE"); display_vcard_item(barejid, "Middle Name", vcard_attrib, data); } else if (!g_strcmp0(p, "ORG")) { data = lm_message_node_get_child_value(x, "ORGNAME"); display_vcard_item(barejid, "Organisation name", vcard_attrib, data); data = lm_message_node_get_child_value(x, "ORGUNIT"); display_vcard_item(barejid, "Organisation unit", vcard_attrib, data); } else { // The HOME, WORK and PREF attributes are common to the remaining fields // (ADR, TEL & EMAIL) if (lm_message_node_get_child(x, "HOME")) vcard_attrib |= vcard_home; if (lm_message_node_get_child(x, "WORK")) vcard_attrib |= vcard_work; if (lm_message_node_get_child(x, "PREF")) vcard_attrib |= vcard_pref; if (!g_strcmp0(p, "ADR")) { // Address if (lm_message_node_get_child(x, "POSTAL")) vcard_attrib |= vcard_postal; data = lm_message_node_get_child_value(x, "EXTADD"); display_vcard_item(barejid, "Addr (ext)", vcard_attrib, data); data = lm_message_node_get_child_value(x, "STREET"); display_vcard_item(barejid, "Street", vcard_attrib, data); data = lm_message_node_get_child_value(x, "LOCALITY"); display_vcard_item(barejid, "Locality", vcard_attrib, data); data = lm_message_node_get_child_value(x, "REGION"); display_vcard_item(barejid, "Region", vcard_attrib, data); data = lm_message_node_get_child_value(x, "PCODE"); display_vcard_item(barejid, "Postal code", vcard_attrib, data); data = lm_message_node_get_child_value(x, "CTRY"); display_vcard_item(barejid, "Country", vcard_attrib, data); } else if (!g_strcmp0(p, "TEL")) { // Telephone data = lm_message_node_get_child_value(x, "NUMBER"); if (data) { if (lm_message_node_get_child(x, "VOICE")) vcard_attrib |= vcard_voice; if (lm_message_node_get_child(x, "FAX")) vcard_attrib |= vcard_fax; if (lm_message_node_get_child(x, "CELL")) vcard_attrib |= vcard_cell; display_vcard_item(barejid, "Phone", vcard_attrib, data); } } else if (!g_strcmp0(p, "EMAIL")) { // Email if (lm_message_node_get_child(x, "INTERNET")) vcard_attrib |= vcard_inet; data = lm_message_node_get_child_value(x, "USERID"); display_vcard_item(barejid, "Email", vcard_attrib, data); } } } }
LmHandlerResult LM::HeapRoster::handle_presence (LmConnection* /*connection*/, LmMessage* message) { LmHandlerResult result = LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; const gchar* from_c = lm_message_node_get_attribute (lm_message_get_node (message), "from"); const gchar* type_attr = lm_message_node_get_attribute (lm_message_get_node (message), "type"); std::string base_jid; std::string resource; if (from_c != 0) { std::string from (from_c); std::string::size_type index = from.find ('/'); base_jid = std::string (from, 0, index); resource = std::string (from, index + 1, std::string::npos); } PresentityPtr item = find_item (base_jid); if (type_attr != NULL && g_strcmp0 (type_attr, "subscribe") == 0) { result = LM_HANDLER_RESULT_REMOVE_MESSAGE; boost::shared_ptr<Ekiga::FormRequestSimple> request = boost::shared_ptr<Ekiga::FormRequestSimple> (new Ekiga::FormRequestSimple (boost::bind (&LM::HeapRoster::subscribe_from_form_submitted, this, _1, _2))); LmMessageNode* status = lm_message_node_find_child (lm_message_get_node (message), "status"); gchar* instructions = NULL; std::string item_name; if (item) { item_name = item->get_name (); } else { item_name = base_jid; } request->title (_("Authorization to see your presence")); if (status != NULL && lm_message_node_get_value (status) != NULL) { instructions = g_strdup_printf (_("%s asks the permission to see your presence, saying: \"%s\"."), item_name.c_str (), lm_message_node_get_value (status)); } else { instructions = g_strdup_printf (_("%s asks the permission to see your presence."), item_name.c_str ()); } request->instructions (instructions); g_free (instructions); std::map<std::string, std::string> choices; choices["grant"] = _("grant him/her the permission to see your presence"); choices["refuse"] = _("refuse him/her the permission to see your presence"); choices["later"] = _("decide later (also close or cancel this dialog)"); request->single_choice ("answer", _("Your answer is: "), "grant", choices); request->hidden ("jid", base_jid); questions (request); } else { if (item) { result = LM_HANDLER_RESULT_REMOVE_MESSAGE; item->push_presence (resource, lm_message_get_node (message)); } } return result; }