void handle_ping_error_result(const char * const from, const char * const error) { if (error == NULL) { cons_show_error("Error returned from pinging %s.", from); } else { cons_show_error("Error returned from pinging %s: %s.", from, error); } }
void handle_disco_info_error(const char * const from, const char * const error) { if (from) { cons_show_error("Service discovery failed for %s: %s", from, error); } else { cons_show_error("Service discovery failed: %s", error); } }
static void cb_handle_msg_event(void *opdata, OtrlMessageEvent msg_event, ConnContext *context, const char *message, gcry_error_t err) { if (err != 0) { if (message != NULL) { cons_show_error("%s", message); } else { cons_show_error("OTR error event with no message."); } } }
void sv_ev_lost_connection(void) { cons_show_error("Lost connection."); #ifdef HAVE_LIBOTR GSList *recipients = wins_get_chat_recipients(); GSList *curr = recipients; while (curr) { char *barejid = curr->data; ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin && otr_is_secure(barejid)) { chatwin_otr_unsecured(chatwin); otr_end_session(barejid); } curr = g_slist_next(curr); } if (recipients) { g_slist_free(recipients); } #endif muc_invites_clear(); chat_sessions_clear(); ui_disconnected(); roster_destroy(); #ifdef HAVE_LIBGPGME p_gpg_on_disconnect(); #endif }
void handle_failed_login(void) { cons_show_error("Login failed."); log_info("Login failed"); ui_current_page_off(); }
static void cb_write_fingerprints(void *opdata) { gcry_error_t err = 0; gchar *data_home = xdg_get_data_home(); GString *basedir = g_string_new(data_home); free(data_home); gchar *account_dir = str_replace(jid, "@", "_at_"); g_string_append(basedir, "/profanity/otr/"); g_string_append(basedir, account_dir); g_string_append(basedir, "/"); free(account_dir); GString *fpsfilename = g_string_new(basedir->str); g_string_append(fpsfilename, "fingerprints.txt"); err = otrl_privkey_write_fingerprints(user_state, fpsfilename->str); if (!err == GPG_ERR_NO_ERROR) { log_error("Failed to write fingerprints file"); cons_show_error("Failed to create fingerprints file"); } g_string_free(basedir, TRUE); g_string_free(fpsfilename, TRUE); }
void sv_ev_failed_login(void) { cons_show_error("Login failed."); log_info("Login failed"); tlscerts_clear_current(); }
static int cb_display_otr_message(void *opdata, const char *accountname, const char *protocol, const char *username, const char *msg) { cons_show_error("%s", msg); return 0; }
void sv_ev_lost_connection(void) { cons_show_error("Lost connection."); roster_clear(); muc_invites_clear(); chat_sessions_clear(); ui_disconnected(); }
void handle_lost_connection(void) { cons_show_error("Lost connection."); roster_clear(); muc_clear_invites(); chat_sessions_clear(); ui_disconnected(); ui_current_page_off(); }
void ui_handle_error(const char *const err_msg) { GString *msg = g_string_new(""); g_string_printf(msg, "Error %s", err_msg); cons_show_error(msg->str); g_string_free(msg, TRUE); }
void ui_handle_otr_error(const char *const barejid, const char *const message) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { win_println((ProfWin*)chatwin, THEME_ERROR, '!', "%s", message); } else { cons_show_error("%s - %s", barejid, message); } }
void sv_ev_roster_received(void) { if (prefs_get_boolean(PREF_ROSTER)) { ui_show_roster(); } char *account_name = session_get_account_name(); #ifdef HAVE_LIBGPGME // check pgp key valid if specified ProfAccount *account = accounts_get_account(account_name); if (account && account->pgp_keyid) { char *err_str = NULL; if (!p_gpg_valid_key(account->pgp_keyid, &err_str)) { cons_show_error("Invalid PGP key ID specified: %s, %s", account->pgp_keyid, err_str); } free(err_str); } account_free(account); #endif // send initial presence resource_presence_t conn_presence = accounts_get_login_presence(account_name); char *last_activity_str = accounts_get_last_activity(account_name); if (last_activity_str) { GDateTime *nowdt = g_date_time_new_now_utc(); GTimeVal lasttv; gboolean res = g_time_val_from_iso8601(last_activity_str, &lasttv); if (res) { GDateTime *lastdt = g_date_time_new_from_timeval_utc(&lasttv); GTimeSpan diff_micros = g_date_time_difference(nowdt, lastdt); int diff_secs = (diff_micros / 1000) / 1000; if (prefs_get_boolean(PREF_LASTACTIVITY)) { cl_ev_presence_send(conn_presence, NULL, diff_secs); } else { cl_ev_presence_send(conn_presence, NULL, 0); } g_date_time_unref(lastdt); } else { cl_ev_presence_send(conn_presence, NULL, 0); } free(last_activity_str); g_date_time_unref(nowdt); } else { cl_ev_presence_send(conn_presence, NULL, 0); } const char *fulljid = connection_get_fulljid(); plugins_on_connect(account_name, fulljid); }
void sv_ev_lost_connection(void) { cons_show_error("Lost connection."); roster_clear(); muc_invites_clear(); chat_sessions_clear(); ui_disconnected(); #ifdef HAVE_LIBGPGME p_gpg_on_disconnect(); #endif }
static void _python_type_error(ProfPlugin *plugin, char *hook, char *type) { GString *err_msg = g_string_new("Plugin error - "); char *module_name = g_strndup(plugin->name, strlen(plugin->name) - 2); g_string_append(err_msg, module_name); free(module_name); g_string_append(err_msg, hook); g_string_append(err_msg, "(): incorrect return type, expected "); g_string_append(err_msg, type); log_error(err_msg->str); cons_show_error(err_msg->str); g_string_free(err_msg, TRUE); }
void ui_handle_recipient_error(const char *const recipient, const char *const err_msg) { // always show in console cons_show_error("Error from %s: %s", recipient, err_msg); ProfChatWin *chatwin = wins_get_chat(recipient); if (chatwin) { win_println((ProfWin*)chatwin, THEME_ERROR, '!', "Error from %s: %s", recipient, err_msg); return; } ProfMucWin *mucwin = wins_get_muc(recipient); if (mucwin) { win_println((ProfWin*)mucwin, THEME_ERROR, '!', "Error from %s: %s", recipient, err_msg); return; } ProfPrivateWin *privatewin = wins_get_private(recipient); if (privatewin) { win_println((ProfWin*)privatewin, THEME_ERROR, '!', "Error from %s: %s", recipient, err_msg); return; } }
void sv_ev_failed_login(void) { cons_show_error("Login failed."); log_info("Login failed"); }
void otr_keygen(ProfAccount *account) { if (data_loaded) { cons_show("OTR key already generated."); return; } if (jid) { free(jid); } jid = strdup(account->jid); log_info("Generating OTR key for %s", jid); gchar *data_home = xdg_get_data_home(); GString *basedir = g_string_new(data_home); free(data_home); gchar *account_dir = str_replace(jid, "@", "_at_"); g_string_append(basedir, "/profanity/otr/"); g_string_append(basedir, account_dir); g_string_append(basedir, "/"); free(account_dir); if (!mkdir_recursive(basedir->str)) { log_error("Could not create %s for account %s.", basedir->str, jid); cons_show_error("Could not create %s for account %s.", basedir->str, jid); g_string_free(basedir, TRUE); return; } gcry_error_t err = 0; GString *keysfilename = g_string_new(basedir->str); g_string_append(keysfilename, "keys.txt"); log_debug("Generating private key file %s for %s", keysfilename->str, jid); cons_show("Generating private key, this may take some time."); cons_show("Moving the mouse randomly around the screen may speed up the process!"); ui_update(); err = otrl_privkey_generate(user_state, keysfilename->str, account->jid, "xmpp"); if (!err == GPG_ERR_NO_ERROR) { g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); log_error("Failed to generate private key"); cons_show_error("Failed to generate private key"); return; } log_info("Private key generated"); cons_show(""); cons_show("Private key generation complete."); GString *fpsfilename = g_string_new(basedir->str); g_string_append(fpsfilename, "fingerprints.txt"); log_debug("Generating fingerprints file %s for %s", fpsfilename->str, jid); err = otrl_privkey_write_fingerprints(user_state, fpsfilename->str); if (!err == GPG_ERR_NO_ERROR) { g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); log_error("Failed to create fingerprints file"); cons_show_error("Failed to create fingerprints file"); return; } log_info("Fingerprints file created"); err = otrl_privkey_read(user_state, keysfilename->str); if (!err == GPG_ERR_NO_ERROR) { g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); log_error("Failed to load private key"); data_loaded = FALSE; return; } err = otrl_privkey_read_fingerprints(user_state, fpsfilename->str, NULL, NULL); if (!err == GPG_ERR_NO_ERROR) { g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); log_error("Failed to load fingerprints"); data_loaded = FALSE; return; } data_loaded = TRUE; g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); g_string_free(fpsfilename, TRUE); return; }
void otr_on_connect(ProfAccount *account) { if (jid) { free(jid); } jid = strdup(account->jid); log_info("Loading OTR key for %s", jid); gchar *data_home = xdg_get_data_home(); GString *basedir = g_string_new(data_home); free(data_home); gchar *account_dir = str_replace(jid, "@", "_at_"); g_string_append(basedir, "/profanity/otr/"); g_string_append(basedir, account_dir); g_string_append(basedir, "/"); free(account_dir); if (!mkdir_recursive(basedir->str)) { log_error("Could not create %s for account %s.", basedir->str, jid); cons_show_error("Could not create %s for account %s.", basedir->str, jid); g_string_free(basedir, TRUE); return; } user_state = otrl_userstate_create(); gcry_error_t err = 0; GString *keysfilename = g_string_new(basedir->str); g_string_append(keysfilename, "keys.txt"); if (!g_file_test(keysfilename->str, G_FILE_TEST_IS_REGULAR)) { log_info("No OTR private key file found %s", keysfilename->str); data_loaded = FALSE; } else { log_info("Loading OTR private key %s", keysfilename->str); err = otrl_privkey_read(user_state, keysfilename->str); if (!err == GPG_ERR_NO_ERROR) { log_warning("Failed to read OTR private key file: %s", keysfilename->str); cons_show_error("Failed to read OTR private key file: %s", keysfilename->str); g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); return; } OtrlPrivKey* privkey = otrl_privkey_find(user_state, jid, "xmpp"); if (!privkey) { log_warning("No OTR private key found for account \"%s\", protocol \"xmpp\" in file: %s", jid, keysfilename->str); cons_show_error("No OTR private key found for account \"%s\", protocol \"xmpp\" in file: %s", jid, keysfilename->str); g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); return; } log_info("Loaded OTR private key"); data_loaded = TRUE; } GString *fpsfilename = g_string_new(basedir->str); g_string_append(fpsfilename, "fingerprints.txt"); if (!g_file_test(fpsfilename->str, G_FILE_TEST_IS_REGULAR)) { log_info("No OTR fingerprints file found %s", fpsfilename->str); data_loaded = FALSE; } else { log_info("Loading OTR fingerprints %s", fpsfilename->str); err = otrl_privkey_read_fingerprints(user_state, fpsfilename->str, NULL, NULL); if (!err == GPG_ERR_NO_ERROR) { log_error("Failed to load OTR fingerprints file: %s", fpsfilename->str); g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); g_string_free(fpsfilename, TRUE); return; } else { log_info("Loaded OTR fingerprints"); data_loaded = TRUE; } } if (data_loaded) { cons_show("Loaded OTR private key for %s", jid); } g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); g_string_free(fpsfilename, TRUE); return; }
void handle_autoping_cancel(void) { prefs_set_autoping(0); cons_show_error("Server ping not supported, autoping disabled."); }
static void _presence_error_handler(xmpp_stanza_t *const stanza) { const char *xmlns = NULL; xmpp_stanza_t *x = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_X); if (x) { xmlns = xmpp_stanza_get_ns(x); } const char *from = xmpp_stanza_get_from(stanza); xmpp_stanza_t *error_stanza = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR); // handle MUC join errors if (g_strcmp0(xmlns, STANZA_NS_MUC) == 0) { const char *error_cond = NULL; xmpp_stanza_t *reason_st = xmpp_stanza_get_child_by_ns(error_stanza, STANZA_NS_STANZAS); if (reason_st) { error_cond = xmpp_stanza_get_name(reason_st); } if (error_cond == NULL) { error_cond = "unknown"; } Jid *fulljid = jid_create(from); log_info("Error joining room: %s, reason: %s", fulljid->barejid, error_cond); if (muc_active(fulljid->barejid)) { muc_leave(fulljid->barejid); } cons_show_error("Error joining room %s, reason: %s", fulljid->barejid, error_cond); jid_destroy(fulljid); return; } GString *log_msg = g_string_new("presence stanza error received"); const char *id = xmpp_stanza_get_id(stanza); if (id) { g_string_append(log_msg, " id="); g_string_append(log_msg, id); } if (from) { g_string_append(log_msg, " from="); g_string_append(log_msg, from); } const char *type = NULL; if (error_stanza) { type = xmpp_stanza_get_type(error_stanza); } if (type) { g_string_append(log_msg, " type="); g_string_append(log_msg, type); } // stanza_get_error never returns NULL char *err_msg = stanza_get_error_message(stanza); 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 (from) { ui_handle_recipient_error(from, err_msg); } else { ui_handle_error(err_msg); } free(err_msg); }
int sv_ev_certfail(const char *const errormsg, TLSCertificate *cert) { // check profanity trusted certs if (tlscerts_exists(cert->fingerprint)) { return 1; } // check current cert char *current_fp = tlscerts_get_current(); if (current_fp && g_strcmp0(current_fp, cert->fingerprint) == 0) { return 1; } cons_show(""); cons_show_error("TLS certificate verification failed: %s", errormsg); cons_show_tlscert(cert); cons_show(""); cons_show("Use '/tls allow' to accept this certificate."); cons_show("Use '/tls always' to accept this certificate permanently."); cons_show("Use '/tls deny' to reject this certificate."); cons_show(""); ui_update(); char *cmd = ui_get_line(); while ((g_strcmp0(cmd, "/tls allow") != 0) && (g_strcmp0(cmd, "/tls always") != 0) && (g_strcmp0(cmd, "/tls deny") != 0) && (g_strcmp0(cmd, "/quit") != 0)) { cons_show("Use '/tls allow' to accept this certificate."); cons_show("Use '/tls always' to accept this certificate permanently."); cons_show("Use '/tls deny' to reject this certificate."); cons_show(""); ui_update(); free(cmd); cmd = ui_get_line(); } if (g_strcmp0(cmd, "/tls allow") == 0) { cons_show("Coninuing with connection."); tlscerts_set_current(cert->fingerprint); free(cmd); return 1; } else if (g_strcmp0(cmd, "/tls always") == 0) { cons_show("Adding %s to trusted certificates.", cert->fingerprint); if (!tlscerts_exists(cert->fingerprint)) { tlscerts_add(cert); } free(cmd); return 1; } else if (g_strcmp0(cmd, "/quit") == 0) { prof_set_quit(); free(cmd); return 0; } else { cons_show("Aborting connection."); free(cmd); return 0; } }
void handle_failed_login(void) { cons_show_error("Login failed."); log_info("Login failed"); }