gboolean prefs_do_room_notify_mention(const char *const roomjid, int unread, gboolean mention, gboolean trigger) { gboolean notify_room = FALSE; if (g_key_file_has_key(prefs, roomjid, "notify", NULL)) { notify_room = g_key_file_get_boolean(prefs, roomjid, "notify", NULL); } else { notify_room = prefs_get_boolean(PREF_NOTIFY_ROOM); } if (notify_room && unread > 0) { return TRUE; } gboolean notify_mention = FALSE; if (g_key_file_has_key(prefs, roomjid, "notify.mention", NULL)) { notify_mention = g_key_file_get_boolean(prefs, roomjid, "notify.mention", NULL); } else { notify_mention = prefs_get_boolean(PREF_NOTIFY_ROOM_MENTION); } if (notify_mention && mention) { return TRUE; } gboolean notify_trigger = FALSE; if (g_key_file_has_key(prefs, roomjid, "notify.trigger", NULL)) { notify_trigger = g_key_file_get_boolean(prefs, roomjid, "notify.trigger", NULL); } else { notify_trigger = prefs_get_boolean(PREF_NOTIFY_ROOM_TRIGGER); } if (notify_trigger && trigger) { return TRUE; } return FALSE; }
void cons_notify_setting(void) { if (prefs_get_boolean(PREF_NOTIFY_MESSAGE)) cons_show("Messages (/notify message) : ON"); else cons_show("Messages (/notify message) : OFF"); if (prefs_get_boolean(PREF_NOTIFY_TYPING)) cons_show("Composing (/notify typing) : ON"); else cons_show("Composing (/notify typing) : OFF"); if (prefs_get_boolean(PREF_NOTIFY_INVITE)) cons_show("Room invites (/notify invite) : ON"); else cons_show("Room invites (/notify invite) : OFF"); if (prefs_get_boolean(PREF_NOTIFY_SUB)) cons_show("Subscription requests (/notify sub) : ON"); else cons_show("Subscription requests (/notify sub) : OFF"); gint remind_period = prefs_get_notify_remind(); if (remind_period == 0) { cons_show("Reminder period (/notify remind) : OFF"); } else if (remind_period == 1) { cons_show("Reminder period (/notify remind) : 1 second"); } else { cons_show("Reminder period (/notify remind) : %d seconds", remind_period); } }
static void _shutdown(void) { if (prefs_get_boolean(PREF_TITLEBAR_SHOW)) { if (prefs_get_boolean(PREF_TITLEBAR_GOODBYE)) { ui_goodbye_title(); } else { ui_clear_win_title(); } } ui_close_all_wins(); jabber_disconnect(); jabber_shutdown(); roster_free(); muc_close(); caps_close(); ui_close(); #ifdef HAVE_LIBOTR otr_shutdown(); #endif #ifdef HAVE_LIBGPGME p_gpg_close(); #endif chat_log_close(); theme_close(); accounts_close(); tlscerts_close(); cmd_uninit(); log_stderr_close(); log_close(); prefs_close(); if (saved_status) { free(saved_status); } }
void caps_init(void) { log_info("Loading capabilities cache"); cache_loc = files_get_data_path(FILE_CAPSCACHE); if (g_file_test(cache_loc, G_FILE_TEST_EXISTS)) { g_chmod(cache_loc, S_IRUSR | S_IWUSR); } cache = g_key_file_new(); g_key_file_load_from_file(cache, cache_loc, G_KEY_FILE_KEEP_COMMENTS, NULL); jid_to_ver = g_hash_table_new_full(g_str_hash, g_str_equal, free, free); jid_to_caps = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)caps_destroy); prof_features = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL); g_hash_table_add(prof_features, strdup(STANZA_NS_CAPS)); g_hash_table_add(prof_features, strdup(XMPP_NS_DISCO_INFO)); g_hash_table_add(prof_features, strdup(XMPP_NS_DISCO_ITEMS)); g_hash_table_add(prof_features, strdup(STANZA_NS_MUC)); g_hash_table_add(prof_features, strdup(STANZA_NS_CONFERENCE)); g_hash_table_add(prof_features, strdup(STANZA_NS_VERSION)); g_hash_table_add(prof_features, strdup(STANZA_NS_CHATSTATES)); g_hash_table_add(prof_features, strdup(STANZA_NS_PING)); if (prefs_get_boolean(PREF_RECEIPTS_SEND)) { g_hash_table_add(prof_features, strdup(STANZA_NS_RECEIPTS)); } if (prefs_get_boolean(PREF_LASTACTIVITY)) { g_hash_table_add(prof_features, strdup(STANZA_NS_LASTACTIVITY)); } my_sha1 = NULL; }
void message_send(const char * const msg, const char * const recipient) { const char * jid = NULL; if (roster_barejid_from_name(recipient) != NULL) { jid = roster_barejid_from_name(recipient); } else { jid = recipient; } if (prefs_get_boolean(PREF_STATES)) { if (!chat_session_exists(jid)) { chat_session_start(jid, TRUE); } } xmpp_stanza_t *message; xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); if (prefs_get_boolean(PREF_STATES) && chat_session_get_recipient_supports(jid)) { chat_session_set_active(jid); message = stanza_create_message(ctx, jid, STANZA_TYPE_CHAT, msg, STANZA_NAME_ACTIVE, NULL); } else { message = stanza_create_message(ctx, jid, STANZA_TYPE_CHAT, msg, NULL, NULL); } xmpp_send(conn, message); xmpp_stanza_release(message); }
void ui_handle_login_account_success(ProfAccount *account, gboolean secured) { if (account->theme) { if (theme_load(account->theme)) { ui_load_colours(); if (prefs_get_boolean(PREF_ROSTER)) { ui_show_roster(); } else { ui_hide_roster(); } if (prefs_get_boolean(PREF_OCCUPANTS)) { ui_show_all_room_rosters(); } else { ui_hide_all_room_rosters(); } ui_resize(); } else { cons_show("Couldn't find account theme: %s", account->theme); } } resource_presence_t resource_presence = accounts_get_login_presence(account->name); contact_presence_t contact_presence = contact_presence_from_resource_presence(resource_presence); cons_show_login_success(account, secured); title_bar_set_presence(contact_presence); title_bar_set_connected(TRUE); title_bar_set_tls(secured); status_bar_print_message(connection_get_fulljid()); status_bar_update_virtual(); }
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); }
gboolean prefs_do_chat_notify(gboolean current_win) { if (prefs_get_boolean(PREF_NOTIFY_CHAT) == FALSE) { return FALSE; } else { if ((current_win == FALSE) || ((current_win == TRUE) && prefs_get_boolean(PREF_NOTIFY_CHAT_CURRENT))) { return TRUE; } else { return FALSE; } } }
void handle_incoming_message(char *from, char *message, gboolean priv) { #ifdef HAVE_LIBOTR gboolean was_decrypted = FALSE; char *newmessage; if (!priv) { newmessage = otr_decrypt_message(from, message, &was_decrypted); // internal OTR message if (newmessage == NULL) { return; } } else { newmessage = message; } ui_incoming_msg(from, newmessage, NULL, priv); ui_current_page_off(); if (prefs_get_boolean(PREF_CHLOG) && !priv) { Jid *from_jid = jid_create(from); const char *jid = jabber_get_fulljid(); Jid *jidp = jid_create(jid); if (!was_decrypted || (strcmp(prefs_get_string(PREF_OTR_LOG), "on") == 0)) { chat_log_chat(jidp->barejid, from_jid->barejid, newmessage, PROF_IN_LOG, NULL); } else if (strcmp(prefs_get_string(PREF_OTR_LOG), "redact") == 0) { chat_log_chat(jidp->barejid, from_jid->barejid, "[redacted]", PROF_IN_LOG, NULL); } jid_destroy(jidp); jid_destroy(from_jid); } if (!priv) otr_free_message(newmessage); #else ui_incoming_msg(from, message, NULL, priv); ui_current_page_off(); if (prefs_get_boolean(PREF_CHLOG) && !priv) { Jid *from_jid = jid_create(from); const char *jid = jabber_get_fulljid(); Jid *jidp = jid_create(jid); chat_log_chat(jidp->barejid, from_jid->barejid, message, PROF_IN_LOG, NULL); jid_destroy(jidp); jid_destroy(from_jid); } #endif }
void ui_outgoing_msg(const char * const from, const char * const to, const char * const message) { PContact contact = roster_get_contact(to); ProfWin *window = wins_get_by_recipient(to); int num = 0; // create new window if (window == NULL) { Jid *jid = jid_create(to); if (muc_room_is_active(jid)) { window = wins_new(to, WIN_PRIVATE); } else { window = wins_new(to, WIN_CHAT); } jid_destroy(jid); num = wins_get_num(window); if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { _win_show_history(window->win, num, to); } if (contact != NULL) { if (strcmp(p_contact_presence(contact), "offline") == 0) { const char const *show = p_contact_presence(contact); const char const *status = p_contact_status(contact); _show_status_string(window, to, show, status, NULL, "--", "offline"); } } // use existing window } else { num = wins_get_num(window); } win_print_time(window, '-'); if (strncmp(message, "/me ", 4) == 0) { wattron(window->win, COLOUR_ME); wprintw(window->win, "*%s ", from); wprintw(window->win, "%s", message + 4); wprintw(window->win, "\n"); wattroff(window->win, COLOUR_ME); } else { _win_show_user(window->win, from, 0); _win_show_message(window->win, message); } ui_switch_win(num); }
gboolean prefs_do_room_notify(gboolean current_win, const char *const roomjid, const char *const mynick, const char *const theirnick, const char *const message, gboolean mention, gboolean trigger_found) { if (g_strcmp0(mynick, theirnick) == 0) { return FALSE; } gboolean notify_current = prefs_get_boolean(PREF_NOTIFY_ROOM_CURRENT); gboolean notify_window = FALSE; if (!current_win || (current_win && notify_current) ) { notify_window = TRUE; } if (!notify_window) { return FALSE; } gboolean notify_room = FALSE; if (g_key_file_has_key(prefs, roomjid, "notify", NULL)) { notify_room = g_key_file_get_boolean(prefs, roomjid, "notify", NULL); } else { notify_room = prefs_get_boolean(PREF_NOTIFY_ROOM); } if (notify_room) { return TRUE; } gboolean notify_mention = FALSE; if (g_key_file_has_key(prefs, roomjid, "notify.mention", NULL)) { notify_mention = g_key_file_get_boolean(prefs, roomjid, "notify.mention", NULL); } else { notify_mention = prefs_get_boolean(PREF_NOTIFY_ROOM_MENTION); } if (notify_mention && mention) { return TRUE; } gboolean notify_trigger = FALSE; if (g_key_file_has_key(prefs, roomjid, "notify.trigger", NULL)) { notify_trigger = g_key_file_get_boolean(prefs, roomjid, "notify.trigger", NULL); } else { notify_trigger = prefs_get_boolean(PREF_NOTIFY_ROOM_TRIGGER); } if (notify_trigger && trigger_found) { return TRUE; } return FALSE; }
void ui_init(void) { log_info("Initialising UI"); initscr(); raw(); keypad(stdscr, TRUE); if (prefs_get_boolean(PREF_MOUSE)) { mousemask(ALL_MOUSE_EVENTS, NULL); mouseinterval(5); } ui_load_colours(); refresh(); create_title_bar(); create_status_bar(); status_bar_active(1); create_input_window(); wins_init(); cons_about(); notifier_init(); #ifdef HAVE_LIBXSS display = XOpenDisplay(0); #endif ui_idle_time = g_timer_new(); wins_refresh_current(); }
void ui_idle(void) { GSList *recipients = wins_get_chat_recipients(); GSList *curr = recipients; while (curr != NULL) { char *recipient = curr->data; chat_session_no_activity(recipient); if (chat_session_is_gone(recipient) && !chat_session_get_sent(recipient)) { message_send_gone(recipient); } else if (chat_session_is_inactive(recipient) && !chat_session_get_sent(recipient)) { message_send_inactive(recipient); } else if (prefs_get_boolean(PREF_OUTTYPE) && chat_session_is_paused(recipient) && !chat_session_get_sent(recipient)) { message_send_paused(recipient); } curr = g_slist_next(curr); } if (recipients != NULL) { g_slist_free(recipients); } }
void inp_nonblocking(gboolean reset) { if (! prefs_get_boolean(PREF_INPBLOCK_DYNAMIC)) { inp_timeout = prefs_get_inpblock(); return; } if (reset) { inp_timeout = 0; no_input_count = 0; } if (inp_timeout < prefs_get_inpblock()) { no_input_count++; if (no_input_count % 10 == 0) { inp_timeout += no_input_count; if (inp_timeout > prefs_get_inpblock()) { inp_timeout = prefs_get_inpblock(); } } } }
void ui_update(void) { ProfWin *current = wins_get_current(); if (current->layout->paged == 0) { win_move_to_end(current); } win_update_virtual(current); if (prefs_get_boolean(PREF_WINTITLE_SHOW)) { _ui_draw_term_title(); } title_bar_update_virtual(); status_bar_update_virtual(); inp_put_back(); doupdate(); if (perform_resize) { signal(SIGWINCH, SIG_IGN); ui_resize(); perform_resize = FALSE; signal(SIGWINCH, ui_sigwinch_handler); } }
/* * Callback for the timer * * This is the callback that the timer is calling in order to check if messages are there. * */ gboolean _tray_change_icon(gpointer data) { if (shutting_down) { return FALSE; } unread_messages = wins_get_total_unread(); if (unread_messages) { if (!prof_tray) { prof_tray = gtk_status_icon_new_from_file(icon_msg_filename->str); } else { gtk_status_icon_set_from_file(prof_tray, icon_msg_filename->str); } } else { if (prefs_get_boolean(PREF_TRAY_READ)) { if (!prof_tray) { prof_tray = gtk_status_icon_new_from_file(icon_filename->str); } else { gtk_status_icon_set_from_file(prof_tray, icon_filename->str); } } else { g_clear_object(&prof_tray); prof_tray = NULL; } } return TRUE; }
void sv_ev_subscription(const char *barejid, jabber_subscr_t type) { switch (type) { case PRESENCE_SUBSCRIBE: /* TODO: auto-subscribe if needed */ cons_show("Received authorization request from %s", barejid); log_info("Received authorization request from %s", barejid); ui_print_system_msg_from_recipient(barejid, "Authorization request, type '/sub allow' to accept or '/sub deny' to reject"); if (prefs_get_boolean(PREF_NOTIFY_SUB)) { notify_subscription(barejid); } break; case PRESENCE_SUBSCRIBED: cons_show("Subscription received from %s", barejid); log_info("Subscription received from %s", barejid); ui_print_system_msg_from_recipient(barejid, "Subscribed"); break; case PRESENCE_UNSUBSCRIBED: cons_show("%s deleted subscription", barejid); log_info("%s deleted subscription", barejid); ui_print_system_msg_from_recipient(barejid, "Unsubscribed"); break; default: /* unknown type */ break; } }
void handle_login_account_success(char *account_name) { ProfAccount *account = accounts_get_account(account_name); #ifdef HAVE_LIBOTR otr_on_connect(account); #endif ui_handle_login_account_success(account); // attempt to rejoin rooms with passwords GList *curr = muc_rooms(); while (curr != NULL) { char *password = muc_password(curr->data); if (password != NULL) { char *nick = muc_nick(curr->data); presence_join_room(curr->data, nick, password); } curr = g_list_next(curr); } g_list_free(curr); log_info("%s logged in successfully", account->jid); account_free(account); if (prefs_get_boolean(PREF_ROSTER)) { ui_show_roster(); } }
void sv_ev_roster_received(void) { if (prefs_get_boolean(PREF_ROSTER)) { ui_show_roster(); } }
void prof_handle_idle(void) { jabber_conn_status_t status = jabber_get_connection_status(); if (status == JABBER_CONNECTED) { GSList *recipients = ui_get_recipients(); GSList *curr = recipients; while (curr != NULL) { char *recipient = curr->data; if (chat_session_get_recipient_supports(recipient)) { chat_session_no_activity(recipient); if (chat_session_is_gone(recipient) && !chat_session_get_sent(recipient)) { message_send_gone(recipient); } else if (chat_session_is_inactive(recipient) && !chat_session_get_sent(recipient)) { message_send_inactive(recipient); } else if (prefs_get_boolean(PREF_OUTTYPE) && chat_session_is_paused(recipient) && !chat_session_get_sent(recipient)) { message_send_paused(recipient); } } curr = g_slist_next(curr); } if (recipients != NULL) { g_slist_free(recipients); } } }
char* roster_get_msg_display_name(const char *const barejid, const char *const resource) { assert(roster != NULL); GString *result = g_string_new(""); PContact contact = roster_get_contact(barejid); if (contact) { if (p_contact_name(contact)) { g_string_append(result, p_contact_name(contact)); } else { g_string_append(result, barejid); } } else { g_string_append(result, barejid); } if (resource && prefs_get_boolean(PREF_RESOURCE_MESSAGE)) { g_string_append(result, "/"); g_string_append(result, resource); } char *result_str = result->str; g_string_free(result, FALSE); return result_str; }
void _receipt_request_handler(xmpp_stanza_t *const stanza) { if (!prefs_get_boolean(PREF_RECEIPTS_SEND)) { return; } char *id = xmpp_stanza_get_id(stanza); if (!id) { return; } xmpp_stanza_t *receipts = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_RECEIPTS); if (!receipts) { return; } char *receipts_name = xmpp_stanza_get_name(receipts); if (g_strcmp0(receipts_name, "request") != 0) { return; } gchar *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); Jid *jid = jid_create(from); _message_send_receipt(jid->fulljid, id); jid_destroy(jid); }
char* message_send_chat_otr(const char *const barejid, const char *const msg) { xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); char *state = _session_state(barejid); char *jid = _session_jid(barejid); char *id = create_unique_id("msg"); xmpp_stanza_t *message = stanza_create_message(ctx, id, barejid, STANZA_TYPE_CHAT, msg); free(jid); if (state) { stanza_attach_state(ctx, message, state); } stanza_attach_carbons_private(ctx, message); stanza_attach_hints_no_copy(ctx, message); stanza_attach_hints_no_store(ctx, message); if (prefs_get_boolean(PREF_RECEIPTS_REQUEST)) { stanza_attach_receipt_request(ctx, message); } xmpp_send(conn, message); xmpp_stanza_release(message); return id; }
void cons_vercheck_setting(void) { if (prefs_get_boolean(PREF_VERCHECK)) cons_show("Version checking (/vercheck) : ON"); else cons_show("Version checking (/vercheck) : OFF"); }
void cons_beep_setting(void) { if (prefs_get_boolean(PREF_BEEP)) cons_show("Terminal beep (/beep) : ON"); else cons_show("Terminal beep (/beep) : OFF"); }
void cons_flash_setting(void) { if (prefs_get_boolean(PREF_FLASH)) cons_show("Terminal flash (/flash) : ON"); else cons_show("Terminal flash (/flash) : OFF"); }
void cons_splash_setting(void) { if (prefs_get_boolean(PREF_SPLASH)) cons_show("Splash screen (/splash) : ON"); else cons_show("Splash screen (/splash) : OFF"); }
void cons_mouse_setting(void) { if (prefs_get_boolean(PREF_MOUSE)) cons_show("Mouse handling (/mouse) : ON"); else cons_show("Mouse handling (/mouse) : OFF"); }
static char* _session_state(const char *const barejid) { ChatSession *session = chat_session_get(barejid); char *state = NULL; if (session) { if (prefs_get_boolean(PREF_STATES) && session->send_states) { state = STANZA_NAME_ACTIVE; } } else { if (prefs_get_boolean(PREF_STATES)) { state = STANZA_NAME_ACTIVE; } } return state; }
void cons_statuses_setting(void) { if (prefs_get_boolean(PREF_STATUSES)) cons_show("Status (/statuses) : ON"); else cons_show("Status (/statuses) : OFF"); }