/* SYNTAX: XMPPPASSWD -yes <old_password> <new_password> */ static void cmd_xmpppasswd(const char *data, SERVER_REC *server, WI_ITEM_REC *item) { GHashTable *optlist; char *old_password, *new_password, *recoded; LmMessage *lmsg; LmMessageNode *node; void *free_arg; CMD_XMPP_SERVER(server); if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS, "xmpppasswd", &optlist, &old_password, &new_password)) return; if (g_hash_table_lookup(optlist, "yes") == NULL) cmd_param_error(CMDERR_NOT_GOOD_IDEA); if (strcmp(old_password, server->connrec->password) != 0) cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); lmsg = lm_message_new_with_sub_type(XMPP_SERVER(server)->domain, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_SET); node = lm_message_node_add_child(lmsg->node, "query", NULL); lm_message_node_set_attribute(node, XMLNS, XMLNS_REGISTER); recoded = xmpp_recode_out(XMPP_SERVER(server)->user); lm_message_node_add_child(node, "username", recoded); g_free(recoded); recoded = xmpp_recode_out(new_password); lm_message_node_add_child(node, "password", recoded); g_free(recoded); signal_emit("xmpp send iq", 2, server, lmsg); lm_message_unref(lmsg); cmd_params_free(free_arg); }
static void lm_auth_cb(LmConnection *connection, gboolean success, gpointer user_data) { XMPP_SERVER_REC *server; if ((server = XMPP_SERVER(user_data)) == NULL) return; if (!success) { server_connect_failed(SERVER(server), "Authentication failed"); return; } signal_emit("xmpp server status", 2, server, "Authenticated successfully."); /* finnish connection process */ lookup_servers = g_slist_remove(lookup_servers, server); g_source_remove(server->connect_tag); server->connect_tag = -1; server->show = XMPP_PRESENCE_AVAILABLE; server->connected = TRUE; if (server->timeout_tag) { g_source_remove(server->timeout_tag); server->timeout_tag = 0; } server_connect_finished(SERVER(server)); server->real_connect_time = server->connect_time; }
static void send_message(SERVER_REC *server, const char *target, const char *msg, int target_type) { LmMessage *lmsg; char *str, *recoded; if (!IS_XMPP_SERVER(server)) return; g_return_if_fail(target != NULL); g_return_if_fail(msg != NULL); if (target_type == SEND_TARGET_CHANNEL) { recoded = xmpp_recode_out(target); lmsg = lm_message_new_with_sub_type(recoded, LM_MESSAGE_TYPE_MESSAGE, LM_MESSAGE_SUB_TYPE_GROUPCHAT); } else { str = rosters_resolve_name(XMPP_SERVER(server), target); recoded = xmpp_recode_out(str != NULL ? str : target); g_free(str); lmsg = lm_message_new_with_sub_type(recoded, LM_MESSAGE_TYPE_MESSAGE, LM_MESSAGE_SUB_TYPE_CHAT); } g_free(recoded); /* ugly from irssi: recode the sent message back */ str = recode_in(server, msg, target); recoded = xmpp_recode_out(str); g_free(str); lm_message_node_add_child(lmsg->node, "body", recoded); g_free(recoded); signal_emit("xmpp send message", 2, server, lmsg); lm_message_unref(lmsg); }
static void sig_complete_command_away(GList **list, WINDOW_REC *window, const char *word, const char *args, int *want_space) { XMPP_SERVER_REC *server; int len; g_return_if_fail(list != NULL); g_return_if_fail(window != NULL); g_return_if_fail(word != NULL); server = XMPP_SERVER(window->active_server); if (server == NULL) return; len = strlen(word); if (g_ascii_strncasecmp(word, xmpp_presence_show[XMPP_PRESENCE_AWAY], len) == 0) *list = g_list_append(*list, g_strdup(xmpp_presence_show[XMPP_PRESENCE_AWAY])); if (g_ascii_strncasecmp(word, xmpp_presence_show[XMPP_PRESENCE_XA], len) == 0) *list = g_list_append(*list, g_strdup(xmpp_presence_show[XMPP_PRESENCE_XA])); if (g_ascii_strncasecmp(word, xmpp_presence_show[XMPP_PRESENCE_DND], len) == 0) *list = g_list_append(*list, g_strdup(xmpp_presence_show[XMPP_PRESENCE_DND])); if (g_ascii_strncasecmp(word, xmpp_presence_show[XMPP_PRESENCE_CHAT], len) == 0) *list = g_list_append(*list, g_strdup(xmpp_presence_show[XMPP_PRESENCE_CHAT])); if (g_ascii_strncasecmp(word, xmpp_presence_show[XMPP_PRESENCE_ONLINE], len) == 0) *list = g_list_append(*list, g_strdup("online")); signal_stop(); }
static void channels_join_func(SERVER_REC *server, const char *data, int automatic) { /* ignore automatic joins from irssi */ if (automatic) return; muc_join(XMPP_SERVER(server), data, FALSE); }
static void sig_window_changed(WINDOW_REC *window, WINDOW_REC *oldwindow) { XMPP_SERVER_REC *server; g_return_if_fail(window != NULL); if ((server = XMPP_SERVER(window->active_server)) == NULL) return; update_nick_statusbar(server, MUC(window->active), FALSE); }
static void lm_open_cb(LmConnection *connection, gboolean success, gpointer user_data) { XMPP_SERVER_REC *server; IPADDR ip; char *host; char *recoded_user, *recoded_password, *recoded_resource; if ((server = XMPP_SERVER(user_data)) == NULL || !success) return; /* get the server address */ host = lm_connection_get_local_host(server->lmconn); if (host != NULL) { net_host2ip(host, &ip); signal_emit("server connecting", 2, server, &ip); g_free(host); } else signal_emit("server connecting", 1, server); if (server->connrec->use_ssl) signal_emit("xmpp server status", 2, server, "Using SSL encryption."); else if (lm_ssl_get_use_starttls(lm_connection_get_ssl(server->lmconn))) signal_emit("xmpp server status", 2, server, "Using STARTTLS encryption."); recoded_user = xmpp_recode_out(server->user); /* prompt for password or re-use typed password */ if (server->connrec->prompted_password != NULL) { g_free_not_null(server->connrec->password); server->connrec->password = g_strdup(server->connrec->prompted_password); } else if (server->connrec->password == NULL || *(server->connrec->password) == '\0' || *(server->connrec->password) == '\r') { g_free_not_null(server->connrec->password); server->connrec->prompted_password = get_password(); signal_emit("send command", 1, "redraw"); if (server->connrec->prompted_password != NULL) server->connrec->password = g_strdup(server->connrec->prompted_password); else server->connrec->password = g_strdup(""); } recoded_password = xmpp_recode_out(server->connrec->password); recoded_resource = xmpp_recode_out(server->resource); lm_connection_authenticate(connection, recoded_user, recoded_password, recoded_resource, lm_auth_cb, server, NULL, NULL); g_free(recoded_user); g_free(recoded_password); g_free(recoded_resource); }
static void lm_close_cb(LmConnection *connection, LmDisconnectReason reason, gpointer user_data) { XMPP_SERVER_REC *server; if ((server = XMPP_SERVER(user_data)) == NULL || !server->connected || reason == LM_DISCONNECT_REASON_OK) return; server->connection_lost = TRUE; server_disconnect(SERVER(server)); }
void read_settings(void) { GSList *tmp; XMPP_SERVER_REC *server; const char *str; for (tmp = servers; tmp != NULL; tmp = tmp->next) { if ((server = XMPP_SERVER(tmp->data)) == NULL) continue; /* update priority */ if (server->show == XMPP_PRESENCE_AWAY) { if (server->priority != settings_get_int("xmpp_priority_away")) signal_emit("xmpp set presence", 4, server, server->show, server->away_reason, settings_get_int("xmpp_priority_away")); } else { if (server->priority != settings_get_int("xmpp_priority")) signal_emit("xmpp set presence", 4, server, server->show, server->away_reason, settings_get_int("xmpp_priority")); } /* update nick */ if (settings_get_bool("xmpp_set_nick_as_username")) { if (strcmp(server->nick, server->user) != 0) { g_free(server->nick); server->nick = g_strdup(server->user); } } else { if (strcmp(server->nick, server->jid) != 0) { g_free(server->nick); server->nick = g_strdup(server->jid); } } } /* check validity */ str = settings_get_str("xmpp_proxy_type"); #if 0 /* TODO print error message */ if (settings_get_bool("xmpp_use_proxy") && (str == NULL || g_ascii_strcasecmp(str, XMPP_PROXY_HTTP) != 0)) ; str = settings_get_str("xmpp_default_away_mode"); if (str == NULL || g_ascii_strcasecmp(str, xmpp_presence_show[XMPP_PRESENCE_AWAY]) != 0 || g_ascii_strcasecmp(str, xmpp_presence_show[XMPP_PRESENCE_CHAT]) != 0 || g_ascii_strcasecmp(str, xmpp_presence_show[XMPP_PRESENCE_DND]) != 0 || g_ascii_strcasecmp(str, xmpp_presence_show[XMPP_PRESENCE_XA]) != 0 || g_ascii_strcasecmp(str, xmpp_presence_show[XMPP_PRESENCE_ONLINE]) != 0) ; #endif }
static void sig_window_destroyed(WINDOW_REC *window) { XMPP_SERVER_REC *server; MUC_REC *channel; g_return_if_fail(window != NULL); if ((server = XMPP_SERVER(window->active_server)) == NULL) return; channel = MUC(window->active); if (channel != NULL || !IS_MUC(active_win->active)) update_nick_statusbar(server, NULL, TRUE); }
static void lm_auth_cb(LmConnection *connection, gboolean success, gpointer user_data) { XMPP_SERVER_REC *server; if ((server = XMPP_SERVER(user_data)) == NULL) return; if (!success) { server_connect_failed(SERVER(server), "Authentication failed"); return; } signal_emit("xmpp server status", 2, server, "Authenticated successfully."); }
static void sig_complete_command_channels(GList **list, WINDOW_REC *window, const char *word, const char *args, int *want_space) { XMPP_SERVER_REC *server; g_return_if_fail(list != NULL); g_return_if_fail(window != NULL); g_return_if_fail(word != NULL); server = XMPP_SERVER(window->active_server); if (server == NULL) return; *list = get_channels(server, word); if (*list != NULL) signal_stop(); }
static LmHandlerResult handle_stanza(LmMessageHandler *handler, LmConnection *connection, LmMessage *lmsg, gpointer user_data) { XMPP_SERVER_REC *server; int type; const char *id; char *from, *to, *raw; if ((server = XMPP_SERVER(user_data)) == NULL) return LM_HANDLER_RESULT_REMOVE_MESSAGE; raw = xmpp_recode_in(lm_message_node_to_string(lmsg->node)); signal_emit("xmpp xml in", 2, server, raw); g_free(raw); type = lm_message_get_sub_type(lmsg); id = lm_message_node_get_attribute(lmsg->node, "id"); if (id == NULL) id = ""; from = xmpp_recode_in(lm_message_node_get_attribute(lmsg->node, "from")); if (from == NULL) from = g_strdup(""); to = xmpp_recode_in(lm_message_node_get_attribute(lmsg->node, "to")); if (to == NULL) to = g_strdup(""); switch(lm_message_get_type(lmsg)) { case LM_MESSAGE_TYPE_MESSAGE: signal_emit("xmpp recv message", 6, server, lmsg, type, id, from, to); break; case LM_MESSAGE_TYPE_PRESENCE: signal_emit("xmpp recv presence", 6, server, lmsg, type, id, from, to); break; case LM_MESSAGE_TYPE_IQ: signal_emit("xmpp recv iq", 6, server, lmsg, type, id, from, to); break; default: signal_emit("xmpp recv others", 6, server, lmsg, type, id, from, to); break; } g_free(from); g_free(to); return LM_HANDLER_RESULT_REMOVE_MESSAGE; }
static void sig_window_changed(WINDOW_REC *new_window, WINDOW_REC *old_window) { XMPP_SERVER_REC *server; XMPP_QUERY_REC *query; if (!settings_get_bool("xmpp_send_composing") || (server = XMPP_SERVER(active_win->active_server)) == NULL) { keyloger_enabled(FALSE); return; } query = XMPP_QUERY(active_win->active); if (query == NULL || !xmpp_have_resource(query->name)) keyloger_enabled(FALSE); else keyloger_enabled(TRUE); }
static void sig_complete_word(GList **list, WINDOW_REC *window, const char *word, const char *linestart, int *want_space) { XMPP_SERVER_REC *server; g_return_if_fail(list != NULL); g_return_if_fail(window != NULL); g_return_if_fail(word != NULL); if ((server = XMPP_SERVER(window->active_server)) == NULL) return; if (g_ascii_strncasecmp(linestart, settings_get_str("cmdchars"), 1) == 0) { *list = g_list_concat(*list, get_nicks(server, *word == '"' ? word+1 : word , TRUE, TRUE)); } else if (!IS_CHANNEL(window->active)) *list = g_list_concat(*list, get_nicks(server, word, FALSE, TRUE)); }
static void sig_complete_command_invite(GList **list, WINDOW_REC *window, const char *word, const char *args, int *want_space) { XMPP_SERVER_REC *server; char **tmp; g_return_if_fail(list != NULL); g_return_if_fail(window != NULL); g_return_if_fail(word != NULL); server = XMPP_SERVER(window->active_server); if (server == NULL) return; /* complete channels */ tmp = g_strsplit(args, " ", 2); if (tmp[0] != NULL && tmp[1] == NULL) *list = get_channels(server, word); g_strfreev(tmp); if (*list != NULL) signal_stop(); }
static void sig_complete_command_presence(GList **list, WINDOW_REC *window, const char *word, const char *args, int *want_space) { XMPP_SERVER_REC *server; char **tmp; g_return_if_fail(list != NULL); g_return_if_fail(window != NULL); g_return_if_fail(word != NULL); g_return_if_fail(args != NULL); if ((server = XMPP_SERVER(window->active_server)) == NULL) return; tmp = g_strsplit(args, " ", 2); /* complete nicks */ if (tmp[0] == NULL) *list = g_list_concat(*list, get_jids(server, *word == '"' ? word+1 : word)); g_strfreev(tmp); if (*list != NULL) signal_stop(); }
static LmSSLResponse lm_ssl_cb(LmSSL *ssl, LmSSLStatus status, gpointer user_data) { XMPP_SERVER_REC *server; if ((server = XMPP_SERVER(user_data)) == NULL) return LM_SSL_RESPONSE_CONTINUE; switch (status) { case LM_SSL_STATUS_NO_CERT_FOUND: g_warning("SSL (%s): no certificate found", server->connrec->address); break; case LM_SSL_STATUS_UNTRUSTED_CERT: g_warning("SSL (%s): certificate is not trusted", server->connrec->address); break; case LM_SSL_STATUS_CERT_EXPIRED: g_warning("SSL (%s): certificate has expired", server->connrec->address); break; case LM_SSL_STATUS_CERT_NOT_ACTIVATED: g_warning("SSL (%s): certificate has not been activated", server->connrec->address); break; case LM_SSL_STATUS_CERT_HOSTNAME_MISMATCH: g_warning("SSL (%s): certificate hostname does not match " "expected hostname", server->connrec->address); break; case LM_SSL_STATUS_CERT_FINGERPRINT_MISMATCH: g_warning("SSL (%s): certificate fingerprint does not match " "expected fingerprint", server->connrec->address); break; case LM_SSL_STATUS_GENERIC_ERROR: g_warning("SSL (%s): generic error", server->connrec->address); break; } return LM_SSL_RESPONSE_CONTINUE; }
static void sig_complete_command_roster_group(GList **list, WINDOW_REC *window, const char *word, const char *args, int *want_space) { GSList *gl; XMPP_SERVER_REC *server; XMPP_ROSTER_GROUP_REC *group; int len; char **tmp; g_return_if_fail(list != NULL); g_return_if_fail(window != NULL); g_return_if_fail(word != NULL); g_return_if_fail(args != NULL); server = XMPP_SERVER(window->active_server); if (server == NULL) return; len = strlen(word); tmp = g_strsplit(args, " ", 2); /* complete nicks */ if (tmp[0] == NULL) *list = g_list_concat(*list, get_nicks(server, *word == '"' ? word+1 : word , TRUE, FALSE)); /* complete groups */ else if (tmp[0] != NULL && tmp[1] == NULL) { for (gl = server->roster; gl != NULL; gl = gl->next) { group = (XMPP_ROSTER_GROUP_REC *)gl->data; if (group->name != NULL && g_ascii_strncasecmp(word, group->name, len) == 0) *list = g_list_append(*list, g_strdup(group->name)); } } g_strfreev(tmp); if (*list != NULL) signal_stop(); }
static void sig_connected(SERVER_REC *server) { GSList *tmp; CHANNEL_SETUP_REC *channel_setup; if (!IS_XMPP_SERVER(server)) return; server->channel_find_func = channel_find_func; server->channels_join = channels_join_func; server->ischannel = ischannel_func; /* autojoin channels */ if (!server->connrec->no_autojoin_channels) { for (tmp = setupchannels; tmp != NULL; tmp = tmp->next) { channel_setup = tmp->data; if (IS_MUC_SETUP(channel_setup) && channel_setup->autojoin && strcmp(channel_setup->chatnet, server->connrec->chatnet) == 0) muc_join(XMPP_SERVER(server), channel_setup->name, TRUE); } } }