void ft_register_msg_handlers (LmConnection *conn) { LmMessageHandler *handler = lm_message_handler_new ((LmHandleMessageFunction) ft_msg_msg_handler, NULL, NULL); lm_connection_register_message_handler (conn, handler, LM_MESSAGE_TYPE_MESSAGE, LM_HANDLER_PRIORITY_NORMAL); lm_message_handler_unref (handler); handler = lm_message_handler_new ((LmHandleMessageFunction) ft_msg_presence_handler, NULL, NULL); lm_connection_register_message_handler (conn, handler, LM_MESSAGE_TYPE_PRESENCE, LM_HANDLER_PRIORITY_NORMAL); lm_message_handler_unref (handler); handler = lm_message_handler_new ((LmHandleMessageFunction) ft_msg_iq_handler, NULL, NULL); lm_connection_register_message_handler (conn, handler, LM_MESSAGE_TYPE_IQ, LM_HANDLER_PRIORITY_NORMAL); lm_message_handler_unref (handler); lm_connection_set_disconnect_function (conn, ft_disconnect_function, NULL, NULL); }
static void connection_auth_cb(LmConnection *c, gboolean success, gpointer udata) { if(!success) { ui_print("ERROR: Authentication failed\n"); } else { LmMessageHandler *handler; handler = lm_message_handler_new(xmpp_iq_handler, NULL, NULL); lm_connection_register_message_handler(c, handler, LM_MESSAGE_TYPE_IQ, LM_HANDLER_PRIORITY_NORMAL); lm_message_handler_unref(handler); handler = lm_message_handler_new(xmpp_mesg_handler, NULL, NULL); lm_connection_register_message_handler(c, handler, LM_MESSAGE_TYPE_MESSAGE, LM_HANDLER_PRIORITY_NORMAL); lm_message_handler_unref(handler); handler = lm_message_handler_new(xmpp_pres_handler, NULL, NULL); lm_connection_register_message_handler(c, handler, LM_MESSAGE_TYPE_PRESENCE, LM_HANDLER_PRIORITY_NORMAL); lm_message_handler_unref(handler); xmpp_roster_request(c); g_timeout_add(60000, (GSourceFunc)reconnect, NULL); } lua_post_connect(); UNUSED(udata); } /* connection_auth_cb */
void xmpp_request_storage(const gchar *storage) { LmMessage *iq; LmMessageNode *query; LmMessageHandler *handler; int i; iq = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET); query = lm_message_node_add_child(iq->node, "query", NULL); lm_message_node_set_attribute(query, "xmlns", NS_PRIVATE); lm_message_node_set_attribute(lm_message_node_add_child (query, "storage", NULL), "xmlns", storage); for (i = 0; g_strcmp0(iq_request_storage_handlers[i].storagens, storage) != 0; ++i) ; handler = lm_message_handler_new(iq_request_storage_handlers[i].handler, NULL, FALSE); lm_connection_send_with_reply(lconnection, iq, handler, NULL); lm_message_handler_unref(handler); lm_message_unref(iq); }
// Destroy a MUC room // room syntax: "room@server" void xmpp_room_destroy(const char *room, const char *venue, const char *reason) { LmMessage *iq; LmMessageHandler *handler; LmMessageNode *query, *x; if (!xmpp_is_online() || !room) return; iq = lm_message_new_with_sub_type(room, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_SET); query = lm_message_node_add_child(iq->node, "query", NULL); lm_message_node_set_attribute(query, "xmlns", NS_MUC_OWNER); x = lm_message_node_add_child(query, "destroy", NULL); if (venue && *venue) lm_message_node_set_attribute(x, "jid", venue); if (reason) lm_message_node_add_child(x, "reason", reason); handler = lm_message_handler_new(handle_iq_dummy, NULL, FALSE); lm_connection_send_with_reply(lconnection, iq, handler, NULL); lm_message_handler_unref(handler); lm_message_unref(iq); }
LmMessageHandler* build_message_handler (boost::function2<LmHandlerResult, LmConnection*, LmMessage*> callback) { handler_data* data = new handler_data (callback); LmMessageHandler* result = lm_message_handler_new ((LmHandleMessageFunction)handler_function_c, data, NULL); return result; }
LM::Account::Account (boost::shared_ptr<Ekiga::PersonalDetails> details_, boost::shared_ptr<Dialect> dialect_, boost::shared_ptr<Cluster> cluster_, xmlNodePtr node_): details(details_), dialect(dialect_), cluster(cluster_), node(node_) { if (node == NULL) throw std::logic_error ("NULL node pointer received"); status = _("inactive"); xmlChar* xml_str = xmlGetProp (node, BAD_CAST "startup"); bool enable_on_startup = false; if (xml_str != NULL) { if (xmlStrEqual (xml_str, BAD_CAST "true")) { enable_on_startup = true; } else { enable_on_startup = false; } } xmlFree (xml_str); connection = lm_connection_new (NULL); LmMessageHandler* iq_lm_handler = lm_message_handler_new ((LmHandleMessageFunction)iq_handler_c, this, NULL); lm_connection_register_message_handler (connection, iq_lm_handler, LM_MESSAGE_TYPE_IQ, LM_HANDLER_PRIORITY_NORMAL); lm_message_handler_unref (iq_lm_handler); LmMessageHandler* presence_lm_handler = lm_message_handler_new ((LmHandleMessageFunction)presence_handler_c, this, NULL); lm_connection_register_message_handler (connection, presence_lm_handler, LM_MESSAGE_TYPE_PRESENCE, LM_HANDLER_PRIORITY_NORMAL); lm_message_handler_unref (presence_lm_handler); LmMessageHandler* message_lm_handler = lm_message_handler_new ((LmHandleMessageFunction)message_handler_c, this, NULL); lm_connection_register_message_handler (connection, message_lm_handler, LM_MESSAGE_TYPE_MESSAGE, LM_HANDLER_PRIORITY_NORMAL); lm_message_handler_unref (message_lm_handler); lm_connection_set_disconnect_function (connection, (LmDisconnectFunction)on_disconnected_c, this, NULL); if (enable_on_startup) { enable (); } }
void xmpp_init (void) { LmMessageHandler * handler; initialize_user_table(); connection = lm_connection_new (NULL); handler = lm_message_handler_new (xmpp_presence_callback, NULL, NULL); lm_connection_register_message_handler (connection, handler, LM_MESSAGE_TYPE_PRESENCE, 0); }
LmMessageHandler* get_ignore_answer_handler () { if ( !ignore_message_handler) { ignore_message_handler = boost::shared_ptr<LmMessageHandler> (lm_message_handler_new (ignorer_handler, NULL, NULL), lm_message_handler_unref); } return ignore_message_handler.get (); }
void lm_sasl_authenticate (LmSASL *sasl, const gchar *username, const gchar *password, const gchar *server, LmSASLResultHandler handler) { sasl->username = g_strdup (username); sasl->password = g_strdup (password); sasl->server = g_strdup (server); sasl->handler = handler; sasl->challenge_cb = lm_message_handler_new (sasl_challenge_cb, sasl, NULL); lm_connection_register_message_handler (sasl->connection, sasl->challenge_cb, LM_MESSAGE_TYPE_CHALLENGE, LM_HANDLER_PRIORITY_FIRST); sasl->success_cb = lm_message_handler_new (sasl_success_cb, sasl, NULL); lm_connection_register_message_handler (sasl->connection, sasl->success_cb, LM_MESSAGE_TYPE_SUCCESS, LM_HANDLER_PRIORITY_FIRST); sasl->failure_cb = lm_message_handler_new (sasl_failure_cb, sasl, NULL); lm_connection_register_message_handler (sasl->connection, sasl->failure_cb, LM_MESSAGE_TYPE_FAILURE, LM_HANDLER_PRIORITY_FIRST); if (sasl->features_received) { sasl_authenticate (sasl); } else { sasl->start_auth = TRUE; } }
int main (int argc, char **argv) { GMainLoop *main_loop; LmConnection *connection; LmMessageHandler *handler; gboolean result; UserInfo *info; LmProxy *proxy; guint proxy_port; if (argc < 6) { g_print ("Usage: %s <server> <username> <password> <proxyserver> <proxyport>\n", argv[0]); return 1; } connection = lm_connection_new (argv[1]); proxy = lm_proxy_new (LM_PROXY_TYPE_HTTP); lm_proxy_set_server (proxy, argv[4]); proxy_port = strtol (argv[5], (char **) NULL, 10); lm_proxy_set_port (proxy, proxy_port); lm_connection_set_proxy (connection, proxy); lm_proxy_unref (proxy); handler = lm_message_handler_new (handle_messages, NULL, NULL); lm_connection_register_message_handler (connection, handler, LM_MESSAGE_TYPE_MESSAGE, LM_HANDLER_PRIORITY_NORMAL); lm_message_handler_unref (handler); info = g_new0 (UserInfo, 1); info->name = g_strdup (argv[2]); info->passwd = g_strdup (argv[3]); result = lm_connection_open (connection, (LmResultFunction) connection_open_cb, info, NULL, NULL); if (!result) { g_print ("Opening connection failed: %d\n", result); } else { g_print ("Returned from the connection_open\n"); } main_loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (main_loop); return 0; }
int xmpp_room_setattrib(const char *roomid, const char *fjid, const char *nick, struct role_affil ra, const char *reason) { LmMessage *iq; LmMessageHandler *handler; LmMessageNode *query, *x; if (!xmpp_is_online() || !roomid) return 1; if (!fjid && !nick) return 1; if (check_jid_syntax((char*)roomid)) { scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", roomid); return 1; } if (fjid && check_jid_syntax((char*)fjid)) { scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", fjid); return 1; } if (ra.type == type_affil && ra.val.affil == affil_outcast && !fjid) return 1; // Shouldn't happen (jid mandatory when banning) iq = lm_message_new_with_sub_type(roomid, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_SET); query = lm_message_node_add_child(iq->node, "query", NULL); lm_message_node_set_attribute(query, "xmlns", NS_MUC_ADMIN); x = lm_message_node_add_child(query, "item", NULL); if (fjid) { lm_message_node_set_attribute(x, "jid", fjid); } else { // nickname lm_message_node_set_attribute(x, "nick", nick); } if (ra.type == type_affil) lm_message_node_set_attribute(x, "affiliation", straffil[ra.val.affil]); else if (ra.type == type_role) lm_message_node_set_attribute(x, "role", strrole[ra.val.role]); if (reason) lm_message_node_add_child(x, "reason", reason); handler = lm_message_handler_new(handle_iq_dummy, NULL, FALSE); lm_connection_send_with_reply(lconnection, iq, handler, NULL); lm_message_handler_unref(handler); lm_message_unref(iq); return 0; }
int main (int argc, char **argv) { GMainLoop *main_loop; LmConnection *connection; LmMessageHandler *handler; gboolean result; UserInfo *info; gchar *jid; if (argc < 6) { g_print ("Usage: %s <server> <username> <password> <connectserver> <connectport>\n", argv[0]); return 1; } connection = lm_connection_new (argv[4]); jid = g_strdup_printf ("%s@%s", argv[2], argv[1]); lm_connection_set_jid (connection, jid); g_free (jid); lm_connection_set_port (connection, strtol (argv[5], (char **) NULL, 10)); handler = lm_message_handler_new (handle_messages, NULL, NULL); lm_connection_register_message_handler (connection, handler, LM_MESSAGE_TYPE_MESSAGE, LM_HANDLER_PRIORITY_NORMAL); lm_message_handler_unref (handler); info = g_new0 (UserInfo, 1); info->name = g_strdup (argv[2]); info->passwd = g_strdup (argv[3]); result = lm_connection_open (connection, (LmResultFunction) connection_open_cb, info, NULL, NULL); if (!result) { g_print ("Opening connection failed: %d\n", result); } else { g_print ("Returned from the connection_open\n"); } main_loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (main_loop); return 0; }
static void register_lm_open_cb(LmConnection *connection, gboolean success, gpointer user_data) { struct register_data *rd; rd = user_data; if (!success) goto err; rd->handler = lm_message_handler_new(handle_register, rd, NULL); send_register(rd); return; err: signal_emit("xmpp registration failed", 3, rd->username, rd->domain, REGISTRATION_ERROR_CONNECTION); rd_cleanup(rd); }
static void register_stanzas(XMPP_SERVER_REC *server) { LmMessageHandler *h; int i; if (!IS_XMPP_SERVER(server)) return; if (server->msg_handlers != NULL && g_slist_length(server->msg_handlers) != 0) unregister_stanzas(server); for(i = 0; message_types[i] != -1; ++i) { h = lm_message_handler_new(handle_stanza, server, NULL); lm_connection_register_message_handler(server->lmconn, h, message_types[i], LM_HANDLER_PRIORITY_NORMAL); server->msg_handlers = g_slist_prepend(server->msg_handlers, h); } }
//doc Loudmouth connect Connects to the server. Returns <code>self</code>. IoObject *IoLoudmouth_connect(IoLoudmouth *self, IoObject *locals, IoMessage *m) { // Q: Should we io_free() these? IoSeq* username = IoObject_getSlot_(self, IOSYMBOL("username")); IoSeq* password = IoObject_getSlot_(self, IOSYMBOL("password")); IoSeq* resource = IoObject_getSlot_(self, IOSYMBOL("resource")); IoSeq* host = IoObject_getSlot_(self, IOSYMBOL("host")); IoNumber* port = IoObject_getSlot_(self, IOSYMBOL("port")); IoObject* use_ssl = IoObject_getSlot_(self, IOSYMBOL("useSsl")); IOASSERT(ISSEQ(username), "Loudmouth: username should be a Sequence"); IOASSERT(ISSEQ(password), "Loudmouth: password should be a Sequence"); IOASSERT(ISSEQ(resource), "Loudmouth: resource should be a Sequence"); IOASSERT(ISSEQ(host), "Loudmouth: host should be a Sequence"); IOASSERT(ISNUMBER(port), "Loudmouth: port should be a Number"); if(LMCONN(self) == NULL) { LmConnection *connection = lm_connection_new_with_context(CSTRING(host), main_context); IoObject_setDataPointer_(self, connection); lm_connection_set_jid(connection, CSTRING(IoObject_getSlot_(self, IOSYMBOL("jid")))); lm_connection_set_port(connection, CNUMBER(port)); if(ISTRUE(use_ssl) && lm_ssl_is_supported()) { LmSSL *ssl = lm_ssl_new(NULL, onSslError, NULL, NULL); lm_connection_set_ssl(connection, ssl); lm_ssl_unref(ssl); } LmMessageHandler* handler = lm_message_handler_new(onXmppMessage, self, NULL); lm_connection_register_message_handler( connection, handler, LM_MESSAGE_TYPE_MESSAGE, LM_HANDLER_PRIORITY_NORMAL ); lm_message_handler_unref(handler); lm_connection_set_disconnect_function(connection, onXmppDisconnect, NULL, NULL); } lm_connection_open(LMCONN(self), onXmppConnect, self, NULL, NULL); return self; }
LmSASL * lm_sasl_new (LmConnection *connection) { LmSASL *sasl; sasl = g_new0 (LmSASL, 1); sasl->connection = connection; sasl->features_received = FALSE; sasl->start_auth = FALSE; sasl->features_cb = lm_message_handler_new (sasl_features_cb, sasl, NULL); lm_connection_register_message_handler (connection, sasl->features_cb, LM_MESSAGE_TYPE_STREAM_FEATURES, LM_HANDLER_PRIORITY_LAST); return sasl; }
void harmony_get_session_id(MP3tunesHarmony *harmony) { LmMessage *message_out; LmMessageHandler *handler; LmMessageNode *message_out_node; GError *err = NULL; handler = lm_message_handler_new(harmony_get_session_id_callback, (gpointer)harmony, NULL); message_out = lm_message_new(MP3TUNES_HARMONY_CONDUCTOR, LM_MESSAGE_TYPE_IQ); message_out_node = lm_message_node_add_child(message_out->node, "sessionId", NULL); lm_message_node_set_attribute(message_out_node, "xmlns", MP3TUNES_HARMONY_XMLNS); lm_connection_send_with_reply(harmony->connection, message_out, handler, &err); lm_message_unref(message_out); if (err != NULL) { error_emit(harmony, MP3TUNES_HARMONY_ERROR_MISC, "Sending session id request failed", err); return; } harmony->sid_state = MP3TUNES_HARMONY_SID_STATE_WAITING; }
// Warning!! xmlns has to be a namespace from iq_request_handlers[].xmlns void xmpp_iq_request(const char *fulljid, const char *xmlns) { LmMessage *iq; LmMessageNode *query; LmMessageHandler *handler; gpointer data = NULL; GDestroyNotify notifier = NULL; GError *error = NULL; int i; iq = lm_message_new_with_sub_type(fulljid, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET); for (i = 0; strcmp(iq_request_handlers[i].xmlns, xmlns) != 0 ; ++i) ; query = lm_message_node_add_child(iq->node, iq_request_handlers[i].querytag, NULL); lm_message_node_set_attribute(query, "xmlns", xmlns); if (!g_strcmp0(xmlns, NS_PING)) { // Create handler for ping queries struct timeval *now = g_new(struct timeval, 1); gettimeofday(now, NULL); data = (gpointer)now; notifier = g_free; } handler = lm_message_handler_new(iq_request_handlers[i].handler, data, notifier); lm_connection_send_with_reply(lconnection, iq, handler, &error); lm_message_handler_unref(handler); lm_message_unref(iq); if (error) { scr_LogPrint(LPRINT_LOGNORM, "Error sending IQ request: %s.", error->message); g_error_free(error); } }
void harmony_get_device_pin(MP3tunesHarmony *harmony) { LmMessage *message_out; LmMessageNode *message_out_node; LmMessageHandler *handler; GError *err = NULL; handler = lm_message_handler_new(harmony_get_device_pin_callback, (gpointer)harmony, NULL); message_out = lm_message_new_with_sub_type(MP3TUNES_HARMONY_CONDUCTOR, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET); message_out_node = lm_message_node_add_child(message_out->node, "pin", NULL); lm_message_node_set_attribute(message_out_node, "xmlns", MP3TUNES_HARMONY_XMLNS); lm_connection_send_with_reply(harmony->connection, message_out, handler, &err); lm_message_unref(message_out); if (err != NULL) { error_emit(harmony, MP3TUNES_HARMONY_ERROR_MISC, "Sending device pin request failed", err); return; } state_change_emit(harmony, MP3TUNES_HARMONY_STATE_WAITING_FOR_PIN); }
// Unlock a MUC room // room syntax: "room@server" void xmpp_room_unlock(const char *room) { LmMessageNode *node; LmMessageHandler *handler; LmMessage *iq; if (!xmpp_is_online() || !room) return; iq = lm_message_new_with_sub_type(room, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_SET); node = lm_message_node_add_child(iq->node, "query", NULL); lm_message_node_set_attribute(node, "xmlns", NS_MUC_OWNER); node = lm_message_node_add_child(node, "x", NULL); lm_message_node_set_attributes(node, "xmlns", "jabber:x:data", "type", "submit", NULL); handler = lm_message_handler_new(handle_iq_dummy, NULL, FALSE); lm_connection_send_with_reply(lconnection, iq, handler, NULL); lm_message_handler_unref(handler); lm_message_unref(iq); }
void rebuild_connection(MP3tunesHarmony* harmony) { gchar* jid; /* if (harmony->connection != NULL) { lm_connection_unref(harmony->connection); harmony->connection = NULL; } if (harmony->harmony_download_message_handler != NULL) { lm_message_handler_unref(harmony->harmony_download_message_handler); harmony->harmony_download_message_handler = NULL; } */ harmony->connection = lm_connection_new(harmony->host); harmony->harmony_iq_message_handler = lm_message_handler_new(harmony_iq_callback, harmony, NULL); lm_connection_set_port(harmony->connection, harmony->port); jid = mp3tunes_harmony_get_jid(harmony); g_debug("Logging in with: %s", jid); lm_connection_set_jid(harmony->connection, jid); g_free(jid); lm_connection_register_message_handler(harmony->connection, harmony->harmony_iq_message_handler, LM_MESSAGE_TYPE_IQ, LM_HANDLER_PRIORITY_LAST); }
bool XMPPAccountHandler::setup() { UT_DEBUGMSG(("XMPPAccountHandler::setup()\n")); UT_return_val_if_fail(m_pConnection, false); AbiCollabSessionManager* pManager = AbiCollabSessionManager::getManager(); UT_return_val_if_fail(pManager, false); // try to request a frame here; note that this might return 0, for example on application startup XAP_Frame *pFrame = XAP_App::getApp()->getLastFocussedFrame(); const std::string server = getProperty("server"); // Register message handler for presence messages m_pPresenceHandler = lm_message_handler_new((LmHandleMessageFunction)presence_handler, reinterpret_cast< gpointer >(this), NULL); lm_connection_register_message_handler(m_pConnection, m_pPresenceHandler, LM_MESSAGE_TYPE_PRESENCE, LM_HANDLER_PRIORITY_NORMAL); // Register message handler for stream error messages m_pStreamErrorHandler = lm_message_handler_new((LmHandleMessageFunction)stream_error_handler, reinterpret_cast< gpointer >(this), NULL); lm_connection_register_message_handler(m_pConnection, m_pStreamErrorHandler, LM_MESSAGE_TYPE_STREAM_ERROR, LM_HANDLER_PRIORITY_NORMAL); // Register message handler for chat messages m_pChatHandler = lm_message_handler_new((LmHandleMessageFunction)chat_handler, reinterpret_cast< gpointer >(this), NULL); lm_connection_register_message_handler(m_pConnection, m_pChatHandler, LM_MESSAGE_TYPE_MESSAGE, LM_HANDLER_PRIORITY_NORMAL); // Send presence message to server GError* error = NULL; LmMessage* m = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_PRESENCE, LM_MESSAGE_SUB_TYPE_NOT_SET); if (!lm_connection_send(m_pConnection, m, &error)) { UT_DEBUGMSG(("Presence message could not be sent: %s", error ? error->message : "")); lm_connection_close(m_pConnection, NULL); lm_connection_unref(m_pConnection); m_pConnection = NULL; // FIXME: unregister the message handlers! // ... if (pFrame) { // inform the user of the sending error // TODO: this shouldn't be here, the caller should handle this UT_UTF8String msg; // TODO: make this localizable UT_UTF8String_sprintf(msg, "Error while connecting to %s: %s\n", server.c_str(), (error ? error->message : "")); pFrame->showMessageBox(msg.utf8_str(), XAP_Dialog_MessageBox::b_O, XAP_Dialog_MessageBox::a_OK); } return false; } lm_message_unref(m); m_bLoggedIn = true; // we are connected now, time to start sending out messages (such as events) pManager->registerEventListener(this); // signal all listeners we are logged in AccountOnlineEvent event; // TODO: fill the event AbiCollabSessionManager::getManager()->signal(event); return true;; }