diff options
author | James Booth <boothj5@gmail.com> | 2015-03-16 01:29:03 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-03-16 01:29:03 +0000 |
commit | 981618b7da2d151d51987c3942e959d6838b08ae (patch) | |
tree | 78406477ed3e7c7aeadc316d978d66a8314cc93f /src | |
parent | e7e1688d8aa3e7deaea7e15cad7c189a32c570e0 (diff) | |
download | profani-tty-981618b7da2d151d51987c3942e959d6838b08ae.tar.gz |
Added static functions to commands.c for sending messages
Diffstat (limited to 'src')
-rw-r--r-- | src/command/commands.c | 65 | ||||
-rw-r--r-- | src/ui/window.c | 1 |
2 files changed, 35 insertions, 31 deletions
diff --git a/src/command/commands.c b/src/command/commands.c index 4919648a..c53782c7 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -76,6 +76,8 @@ static void _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filt static gint _compare_commands(Command *a, Command *b); static void _who_room(gchar **args, struct cmd_help_t help); static void _who_roster(gchar **args, struct cmd_help_t help); +static void _send_chat_message(const char * const barejid, const char * const message); +static void _send_otr_chat_message(const char * const barejid, const char * const message); extern GHashTable *commands; @@ -121,24 +123,12 @@ cmd_execute_default(const char * inp) return TRUE; } if (otr_is_secure(chatwin->barejid)) { - char *encrypted = otr_encrypt_message(chatwin->barejid, inp); - if (encrypted != NULL) { - char *id = message_send_chat_encrypted(chatwin->barejid, encrypted); - otr_free_message(encrypted); - chat_log_otr_msg_out(chatwin->barejid, inp); - ui_outgoing_chat_msg(chatwin->barejid, inp, id); - } else { - cons_show_error("Failed to send message."); - } + _send_otr_chat_message(chatwin->barejid, inp); } else { - char *id = message_send_chat(chatwin->barejid, inp); - chat_log_msg_out(chatwin->barejid, inp); - ui_outgoing_chat_msg(chatwin->barejid, inp, id); + _send_chat_message(chatwin->barejid, inp); } #else - char *id = message_send_chat(chatwin->barejid, inp); - chat_log_msg_out(chatwin->barejid, inp); - ui_outgoing_chat_msg(chatwin->barejid, inp, id); + _send_chat_message(chatwin->barejid, inp); #endif } break; @@ -1388,6 +1378,7 @@ cmd_msg(gchar **args, struct cmd_help_t help) if (win_type == WIN_CHAT || win_type == WIN_CONSOLE) { chat_log_otr_msg_out(barejid, msg); } + free(id); } else { cons_show_error("Failed to encrypt and send message,"); } @@ -1412,6 +1403,7 @@ cmd_msg(gchar **args, struct cmd_help_t help) if (win_type == WIN_CHAT || win_type == WIN_CONSOLE) { chat_log_msg_out(barejid, msg); } + free(id); } return TRUE; #else @@ -1420,6 +1412,7 @@ cmd_msg(gchar **args, struct cmd_help_t help) if (win_type == WIN_CHAT || win_type == WIN_CONSOLE) { chat_log_msg_out(barejid, msg); } + free(id); return TRUE; #endif @@ -3184,24 +3177,12 @@ cmd_tiny(gchar **args, struct cmd_help_t help) ProfChatWin *chatwin = wins_get_current_chat(); #ifdef HAVE_LIBOTR if (otr_is_secure(chatwin->barejid)) { - char *encrypted = otr_encrypt_message(chatwin->barejid, tiny); - if (encrypted != NULL) { - char *id = message_send_chat_encrypted(chatwin->barejid, encrypted); - chat_log_otr_msg_out(chatwin->barejid, tiny); - ui_outgoing_chat_msg(chatwin->barejid, tiny, id); - otr_free_message(encrypted); - } else { - cons_show_error("Failed to send message."); - } + _send_otr_chat_message(chatwin->barejid, tiny); } else { - char *id = message_send_chat(chatwin->barejid, tiny); - chat_log_msg_out(chatwin->barejid, tiny); - ui_outgoing_chat_msg(chatwin->barejid, tiny, id); + _send_chat_message(chatwin->barejid, tiny); } #else - char *id = message_send_chat(chatwin->barejid, tiny); - chat_log_msg_out(chatwin->barejid, tiny); - ui_outgoing_chat_msg(chatwin->barejid, tiny, id); + _send_chat_message(chatwin->barejid, tiny); #endif } else if (win_type == WIN_PRIVATE) { ProfPrivateWin *privatewin = wins_get_current_private(); @@ -4455,3 +4436,27 @@ gint _compare_commands(Command *a, Command *b) return result; } + +static void +_send_chat_message(const char * const barejid, const char * const message) +{ + char *id = message_send_chat(barejid, message); + chat_log_msg_out(barejid, message); + ui_outgoing_chat_msg(barejid, message, id); + free(id); +} + +static void +_send_otr_chat_message(const char * const barejid, const char * const message) +{ + char *encrypted = otr_encrypt_message(barejid, message); + if (encrypted != NULL) { + char *id = message_send_chat_encrypted(barejid, encrypted); + chat_log_otr_msg_out(barejid, message); + ui_outgoing_chat_msg(barejid, message, id); + otr_free_message(encrypted); + free(id); + } else { + cons_show_error("Failed to encrypt and send message."); + } +} \ No newline at end of file diff --git a/src/ui/window.c b/src/ui/window.c index 4663089f..2a1b1a7b 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -906,7 +906,6 @@ win_print_with_receipt(ProfWin *window, const char show_char, GTimeVal *tstamp, DeliveryReceipt *receipt = malloc(sizeof(struct delivery_receipt_t)); receipt->id = strdup(id); receipt->received = FALSE; - free(id); buffer_push(window->layout->buffer, show_char, time, flags, theme_item, from, message, receipt); _win_print(window, show_char, time, flags, theme_item, from, message, receipt); |