mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Added stanza module for basic stanza handling
To reduce duplication in jabber module
This commit is contained in:
parent
ba11e88dcb
commit
dac4cf3c3c
@ -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
|
||||
|
51
src/jabber.c
51
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);
|
||||
}
|
||||
|
||||
|
43
src/stanza.c
Normal file
43
src/stanza.c
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* stanza.c
|
||||
*
|
||||
* Copyright (C) 2012 James Booth <boothj5@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <strophe.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
31
src/stanza.h
Normal file
31
src/stanza.h
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* stanza.h
|
||||
*
|
||||
* Copyright (C) 2012 James Booth <boothj5@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef STANZA_H
|
||||
#define STANZA_H
|
||||
|
||||
#include <strophe.h>
|
||||
|
||||
xmpp_stanza_t* stanza_create_chat_state(xmpp_ctx_t *ctx,
|
||||
const char * const recipient, const char * const state);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user