From b269ac97022bd15ac9a62d8b7cc98646313c4ce5 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 29 Jan 2013 00:21:04 +0000 Subject: [PATCH] Added xmpp_message.c --- Makefile.am | 2 +- src/command.c | 10 ++++----- src/xmpp.h | 4 +++- src/xmpp_conn.c | 23 -------------------- src/xmpp_message.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 61 insertions(+), 30 deletions(-) create mode 100644 src/xmpp_message.c diff --git a/Makefile.am b/Makefile.am index 66e599f2..9049375a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -7,7 +7,7 @@ profanity_SOURCES = src/command.c src/contact.c src/command_history.c src/xmpp.h src/history.c src/ui.h src/common.h src/ contact_list.h src/xmpp_conn.c \ src/main.c src/profanity.h src/history.h src/xmpp_presence.c \ src/tinyurl.c src/tinyurl.h src/chat_session.c \ - src/chat_session.h src/muc.c \ + src/chat_session.h src/muc.c src/xmpp_message.c \ src/muc.h src/xmpp_stanza.c src/command_parser.c \ src/theme.c src/theme.h src/window.c src/window.h \ src/files.c src/files.h src/accounts.c src/accounts.h \ diff --git a/src/command.c b/src/command.c index 23a0fa45..59f13a2b 100644 --- a/src/command.c +++ b/src/command.c @@ -909,7 +909,7 @@ cmd_execute_default(const char * const inp) win_current_show("You are not currently connected."); } else { char *recipient = win_current_get_recipient(); - jabber_send(inp, recipient); + message_send(inp, recipient); if (win_current_is_chat() && prefs_get_chlog()) { const char *jid = jabber_get_jid(); @@ -1669,7 +1669,7 @@ _cmd_msg(gchar **args, struct cmd_help_t help) g_string_append(full_jid, usr); if (msg != NULL) { - jabber_send(msg, full_jid->str); + message_send(msg, full_jid->str); win_show_outgoing_msg("me", full_jid->str, msg); } else { win_new_chat_win(full_jid->str); @@ -1685,7 +1685,7 @@ _cmd_msg(gchar **args, struct cmd_help_t help) } else { if (msg != NULL) { - jabber_send(msg, usr); + message_send(msg, usr); win_show_outgoing_msg("me", usr, msg); if (win_current_is_chat() && prefs_get_chlog()) { @@ -1882,7 +1882,7 @@ _cmd_tiny(gchar **args, struct cmd_help_t help) if (tiny != NULL) { if (win_current_is_chat()) { char *recipient = win_current_get_recipient(); - jabber_send(tiny, recipient); + message_send(tiny, recipient); if (prefs_get_chlog()) { const char *jid = jabber_get_jid(); @@ -1893,7 +1893,7 @@ _cmd_tiny(gchar **args, struct cmd_help_t help) free(recipient); } else if (win_current_is_private()) { char *recipient = win_current_get_recipient(); - jabber_send(tiny, recipient); + message_send(tiny, recipient); win_show_outgoing_msg("me", recipient, tiny); free(recipient); } else { // groupchat diff --git a/src/xmpp.h b/src/xmpp.h index bb651faa..3a179141 100644 --- a/src/xmpp.h +++ b/src/xmpp.h @@ -146,7 +146,6 @@ jabber_conn_status_t jabber_connect_with_account(ProfAccount *account, const char * const passwd); void jabber_disconnect(void); void jabber_process_events(void); -void jabber_send(const char * const msg, const char * const recipient); void jabber_send_groupchat(const char * const msg, const char * const recipient); void jabber_send_inactive(const char * const recipient); void jabber_send_composing(const char * const recipient); @@ -168,6 +167,9 @@ void jabber_conn_set_priority(int priority); void jabber_conn_set_status(const char * const message); char* jabber_get_account_name(void); +// message functions +void message_send(const char * const msg, const char * const recipient); + // iq functions void iq_add_handlers(void); diff --git a/src/xmpp_conn.c b/src/xmpp_conn.c index 130a04b2..626ed63d 100644 --- a/src/xmpp_conn.c +++ b/src/xmpp_conn.c @@ -241,29 +241,6 @@ jabber_process_events(void) } -void -jabber_send(const char * const msg, const char * const recipient) -{ - if (prefs_get_states()) { - if (!chat_session_exists(recipient)) { - chat_session_start(recipient, TRUE); - } - } - - xmpp_stanza_t *message; - if (prefs_get_states() && chat_session_get_recipient_supports(recipient)) { - chat_session_set_active(recipient); - message = stanza_create_message(jabber_conn.ctx, recipient, STANZA_TYPE_CHAT, - msg, STANZA_NAME_ACTIVE); - } else { - message = stanza_create_message(jabber_conn.ctx, recipient, STANZA_TYPE_CHAT, - msg, NULL); - } - - xmpp_send(jabber_conn.conn, message); - xmpp_stanza_release(message); -} - void jabber_send_groupchat(const char * const msg, const char * const recipient) { diff --git a/src/xmpp_message.c b/src/xmpp_message.c new file mode 100644 index 00000000..f018470c --- /dev/null +++ b/src/xmpp_message.c @@ -0,0 +1,52 @@ +/* + * xmpp_message.c + * + * Copyright (C) 2012, 2013 James Booth + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see . + * + */ + +#include + +#include "chat_session.h" +#include "preferences.h" +#include "xmpp.h" + +void +message_send(const char * const msg, const char * const recipient) +{ + xmpp_conn_t * const conn = jabber_get_conn(); + xmpp_ctx_t * const ctx = jabber_get_ctx(); + if (prefs_get_states()) { + if (!chat_session_exists(recipient)) { + chat_session_start(recipient, TRUE); + } + } + + xmpp_stanza_t *message; + if (prefs_get_states() && chat_session_get_recipient_supports(recipient)) { + chat_session_set_active(recipient); + message = stanza_create_message(ctx, recipient, STANZA_TYPE_CHAT, + msg, STANZA_NAME_ACTIVE); + } else { + message = stanza_create_message(ctx, recipient, STANZA_TYPE_CHAT, + msg, NULL); + } + + xmpp_send(conn, message); + xmpp_stanza_release(message); +}