diff --git a/Makefile.am b/Makefile.am index 29ccad96..66304e99 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,7 +8,7 @@ profanity_SOURCES = src/command.c src/contact.c src/history.c src/jabber.h \ src/main.c src/profanity.h src/prof_history.h src/chat_log.c \ src/chat_log.h src/tinyurl.c src/tinyurl.h src/chat_session.c \ src/chat_session.h src/release.c src/release.h src/room_chat.c \ - src/room_chat.h + src/room_chat.h src/stanza.c src/stanza.h TESTS = tests/testsuite check_PROGRAMS = tests/testsuite diff --git a/src/jabber.c b/src/jabber.c index 4c8250eb..7bb53add 100644 --- a/src/jabber.c +++ b/src/jabber.c @@ -33,6 +33,7 @@ #include "preferences.h" #include "profanity.h" #include "room_chat.h" +#include "stanza.h" #define PING_INTERVAL 120000 // 2 minutes @@ -53,7 +54,6 @@ static void _xmpp_file_logger(void * const userdata, static xmpp_log_t * _xmpp_get_file_logger(); static void _jabber_roster_request(void); -void _jabber_send_state(const char * const recipient, const char * const state); // XMPP event handlers static void _connection_handler(xmpp_conn_t * const conn, @@ -216,25 +216,45 @@ jabber_send_groupchat(const char * const msg, const char * const recipient) void jabber_send_composing(const char * const recipient) { - _jabber_send_state(recipient, "composing"); + xmpp_stanza_t *stanza = stanza_create_chat_state(jabber_conn.ctx, recipient, + "composing"); + + xmpp_send(jabber_conn.conn, stanza); + xmpp_stanza_release(stanza); + chat_session_set_sent(recipient); } void jabber_send_paused(const char * const recipient) { - _jabber_send_state(recipient, "paused"); + xmpp_stanza_t *stanza = stanza_create_chat_state(jabber_conn.ctx, recipient, + "paused"); + + xmpp_send(jabber_conn.conn, stanza); + xmpp_stanza_release(stanza); + chat_session_set_sent(recipient); } void jabber_send_inactive(const char * const recipient) { - _jabber_send_state(recipient, "inactive"); + xmpp_stanza_t *stanza = stanza_create_chat_state(jabber_conn.ctx, recipient, + "inactive"); + + xmpp_send(jabber_conn.conn, stanza); + xmpp_stanza_release(stanza); + chat_session_set_sent(recipient); } void jabber_send_gone(const char * const recipient) { - _jabber_send_state(recipient, "gone"); + xmpp_stanza_t *stanza = stanza_create_chat_state(jabber_conn.ctx, recipient, + "gone"); + + xmpp_send(jabber_conn.conn, stanza); + xmpp_stanza_release(stanza); + chat_session_set_sent(recipient); } void @@ -812,24 +832,3 @@ _xmpp_get_file_logger() return file_log; } -void -_jabber_send_state(const char * const recipient, const char * const state) -{ - xmpp_stanza_t *message, *chat_state; - - message = xmpp_stanza_new(jabber_conn.ctx); - xmpp_stanza_set_name(message, "message"); - xmpp_stanza_set_type(message, "chat"); - xmpp_stanza_set_attribute(message, "to", recipient); - - chat_state = xmpp_stanza_new(jabber_conn.ctx); - xmpp_stanza_set_name(chat_state, state); - xmpp_stanza_set_ns(chat_state, "http://jabber.org/protocol/chatstates"); - xmpp_stanza_add_child(message, chat_state); - - xmpp_send(jabber_conn.conn, message); - xmpp_stanza_release(message); - - chat_session_set_sent(recipient); -} - diff --git a/src/stanza.c b/src/stanza.c new file mode 100644 index 00000000..a65365ff --- /dev/null +++ b/src/stanza.c @@ -0,0 +1,43 @@ +/* + * stanza.c + * + * Copyright (C) 2012 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 + +xmpp_stanza_t * +stanza_create_chat_state(xmpp_ctx_t *ctx, const char * const recipient, + const char * const state) +{ + xmpp_stanza_t *message, *chat_state; + + message = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(message, "message"); + xmpp_stanza_set_type(message, "chat"); + xmpp_stanza_set_attribute(message, "to", recipient); + + chat_state = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(chat_state, state); + xmpp_stanza_set_ns(chat_state, "http://jabber.org/protocol/chatstates"); + xmpp_stanza_add_child(message, chat_state); + + return message; +} + diff --git a/src/stanza.h b/src/stanza.h new file mode 100644 index 00000000..4f768f3a --- /dev/null +++ b/src/stanza.h @@ -0,0 +1,31 @@ +/* + * stanza.h + * + * Copyright (C) 2012 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 . + * + */ + +#ifndef STANZA_H +#define STANZA_H + +#include + +xmpp_stanza_t* stanza_create_chat_state(xmpp_ctx_t *ctx, + const char * const recipient, const char * const state); + +#endif