1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Moved private xmpp functions to connection.h

This commit is contained in:
James Booth 2013-02-03 22:40:54 +00:00
parent b7535a0fe2
commit 0b40de5a4f
7 changed files with 88 additions and 55 deletions

View File

@ -6,7 +6,7 @@ profanity_SOURCES = src/contact.c src/contact.h src/log.c src/common.c \
src/xmpp/xmpp.h src/xmpp/capabilities.c src/xmpp/connection.c \
src/xmpp/iq.c src/xmpp/message.c src/xmpp/presence.c src/xmpp/stanza.c \
src/xmpp/stanza.h src/xmpp/message.h src/xmpp/iq.h src/xmpp/presence.h \
src/xmpp/capabilities.h \
src/xmpp/capabilities.h src/xmpp/connection.h \
src/ui/ui.h src/ui/window.c src/ui/window.h src/ui/windows.c \
src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \
src/command/command.h src/command/command.c src/command/history.c \

View File

@ -34,6 +34,7 @@
#include "log.h"
#include "muc.h"
#include "profanity.h"
#include "xmpp/connection.h"
#include "xmpp/iq.h"
#include "xmpp/message.h"
#include "xmpp/presence.h"
@ -154,7 +155,7 @@ jabber_disconnect(void)
while (jabber_get_connection_status() == JABBER_DISCONNECTING) {
jabber_process_events();
}
jabber_free_resources();
connection_free_resources();
}
}
@ -200,13 +201,13 @@ jabber_get_connection_status(void)
}
xmpp_conn_t *
jabber_get_conn(void)
connection_get_conn(void)
{
return jabber_conn.conn;
}
xmpp_ctx_t *
jabber_get_ctx(void)
connection_get_ctx(void)
{
return jabber_conn.ctx;
}
@ -236,13 +237,13 @@ jabber_get_account_name(void)
}
void
jabber_conn_set_presence_type(jabber_presence_t presence_type)
connection_set_presence_type(jabber_presence_t presence_type)
{
jabber_conn.presence_type = presence_type;
}
void
jabber_conn_set_presence_message(const char * const message)
connection_set_presence_message(const char * const message)
{
FREE_SET_NULL(jabber_conn.presence_message);
if (message != NULL) {
@ -251,13 +252,13 @@ jabber_conn_set_presence_message(const char * const message)
}
void
jabber_conn_set_priority(int priority)
connection_set_priority(int priority)
{
jabber_conn.priority = priority;
}
void
jabber_free_resources(void)
connection_free_resources(void)
{
FREE_SET_NULL(saved_details.name);
FREE_SET_NULL(saved_details.jid);
@ -273,7 +274,7 @@ jabber_free_resources(void)
}
int
error_handler(xmpp_stanza_t * const stanza)
connection_error_handler(xmpp_stanza_t * const stanza)
{
gchar *err_msg = NULL;
gchar *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
@ -429,14 +430,14 @@ _connection_handler(xmpp_conn_t * const conn,
reconnect_timer = g_timer_new();
// TODO: free resources but leave saved_user untouched
} else {
jabber_free_resources();
connection_free_resources();
}
// login attempt failed
} else if (jabber_conn.conn_status != JABBER_DISCONNECTING) {
if (reconnect_timer == NULL) {
prof_handle_failed_login();
jabber_free_resources();
connection_free_resources();
} else {
if (prefs_get_reconnect() != 0) {
g_timer_start(reconnect_timer);

36
src/xmpp/connection.h Normal file
View File

@ -0,0 +1,36 @@
/*
* connection.h
*
* Copyright (C) 2012, 2013 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 CONNECTION_H
#define CONNECTION_H
#include <strophe.h>
void connection_free_resources(void);
xmpp_conn_t *connection_get_conn(void);
xmpp_ctx_t *connection_get_ctx(void);
int connection_error_handler(xmpp_stanza_t * const stanza);
void connection_set_presence_type(jabber_presence_t presence_type);
void connection_set_priority(int priority);
void connection_set_presence_message(const char * const message);
#endif

View File

@ -31,6 +31,7 @@
#include "contact_list.h"
#include "log.h"
#include "xmpp/capabilities.h"
#include "xmpp/connection.h"
#include "xmpp/iq.h"
#include "xmpp/stanza.h"
#include "xmpp/xmpp.h"
@ -55,8 +56,8 @@ static int _iq_handle_discoinfo_result(xmpp_conn_t * const conn,
void
iq_add_handlers(void)
{
xmpp_conn_t * const conn = jabber_get_conn();
xmpp_ctx_t * const ctx = jabber_get_ctx();
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
HANDLE(NULL, STANZA_TYPE_ERROR, _iq_handle_error);
HANDLE(XMPP_NS_ROSTER, STANZA_TYPE_SET, _iq_handle_roster_set);
HANDLE(XMPP_NS_ROSTER, STANZA_TYPE_RESULT, _iq_handle_roster_result);
@ -69,8 +70,8 @@ iq_add_handlers(void)
void
iq_roster_request(void)
{
xmpp_conn_t * const conn = jabber_get_conn();
xmpp_ctx_t * const ctx = jabber_get_ctx();
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *iq = stanza_create_roster_iq(ctx);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);

View File

@ -30,6 +30,7 @@
#include "log.h"
#include "muc.h"
#include "profanity.h"
#include "xmpp/connection.h"
#include "xmpp/message.h"
#include "xmpp/stanza.h"
#include "xmpp/xmpp.h"
@ -44,16 +45,16 @@ static int _chat_message_handler(xmpp_stanza_t * const stanza);
void
message_add_handlers(void)
{
xmpp_conn_t * const conn = jabber_get_conn();
xmpp_ctx_t * const ctx = jabber_get_ctx();
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
HANDLE(NULL, NULL, _message_handler);
}
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();
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
if (prefs_get_boolean(PREF_STATES)) {
if (!chat_session_exists(recipient)) {
chat_session_start(recipient, TRUE);
@ -77,8 +78,8 @@ message_send(const char * const msg, const char * const recipient)
void
message_send_groupchat(const char * const msg, const char * const recipient)
{
xmpp_conn_t * const conn = jabber_get_conn();
xmpp_ctx_t * const ctx = jabber_get_ctx();
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *message = stanza_create_message(ctx, recipient,
STANZA_TYPE_GROUPCHAT, msg, NULL);
@ -89,8 +90,8 @@ message_send_groupchat(const char * const msg, const char * const recipient)
void
message_send_composing(const char * const recipient)
{
xmpp_conn_t * const conn = jabber_get_conn();
xmpp_ctx_t * const ctx = jabber_get_ctx();
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, recipient,
STANZA_NAME_COMPOSING);
@ -102,8 +103,8 @@ message_send_composing(const char * const recipient)
void
message_send_paused(const char * const recipient)
{
xmpp_conn_t * const conn = jabber_get_conn();
xmpp_ctx_t * const ctx = jabber_get_ctx();
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, recipient,
STANZA_NAME_PAUSED);
@ -115,8 +116,8 @@ message_send_paused(const char * const recipient)
void
message_send_inactive(const char * const recipient)
{
xmpp_conn_t * const conn = jabber_get_conn();
xmpp_ctx_t * const ctx = jabber_get_ctx();
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, recipient,
STANZA_NAME_INACTIVE);
@ -128,8 +129,8 @@ message_send_inactive(const char * const recipient)
void
message_send_gone(const char * const recipient)
{
xmpp_conn_t * const conn = jabber_get_conn();
xmpp_ctx_t * const ctx = jabber_get_ctx();
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, recipient,
STANZA_NAME_GONE);
@ -148,7 +149,7 @@ _message_handler(xmpp_conn_t * const conn,
log_error("Message stanza received with no type attribute");
return 1;
} else if (strcmp(type, STANZA_TYPE_ERROR) == 0) {
return error_handler(stanza);
return connection_error_handler(stanza);
} else if (strcmp(type, STANZA_TYPE_GROUPCHAT) == 0) {
return _groupchat_message_handler(stanza);
} else if (strcmp(type, STANZA_TYPE_CHAT) == 0) {

View File

@ -31,6 +31,7 @@
#include "muc.h"
#include "profanity.h"
#include "xmpp/capabilities.h"
#include "xmpp/connection.h"
#include "xmpp/stanza.h"
#include "xmpp/xmpp.h"
@ -53,16 +54,16 @@ presence_init(void)
void
presence_add_handlers(void)
{
xmpp_conn_t * const conn = jabber_get_conn();
xmpp_ctx_t * const ctx = jabber_get_ctx();
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
HANDLE(NULL, NULL, _presence_handler);
}
void
presence_subscription(const char * const jid, const jabber_subscr_t action)
{
xmpp_ctx_t *ctx = jabber_get_ctx();
xmpp_conn_t *conn = jabber_get_conn();
xmpp_ctx_t *ctx = connection_get_ctx();
xmpp_conn_t *conn = connection_get_conn();
xmpp_stanza_t *presence;
char *type, *jid_cpy, *bare_jid;
@ -108,8 +109,8 @@ void
presence_update(jabber_presence_t presence_type, const char * const msg,
int idle)
{
xmpp_ctx_t *ctx = jabber_get_ctx();
xmpp_conn_t *conn = jabber_get_conn();
xmpp_ctx_t *ctx = connection_get_ctx();
xmpp_conn_t *conn = connection_get_conn();
int pri = accounts_get_priority_for_presence_type(jabber_get_account_name(),
presence_type);
const char *show = stanza_get_presence_string_from_type(presence_type);
@ -118,9 +119,9 @@ presence_update(jabber_presence_t presence_type, const char * const msg,
if (jabber_get_connection_status() != JABBER_CONNECTED)
return;
jabber_conn_set_presence_type(presence_type);
jabber_conn_set_presence_message(msg);
jabber_conn_set_priority(pri);
connection_set_presence_type(presence_type);
connection_set_presence_message(msg);
connection_set_priority(pri);
xmpp_stanza_t *presence = stanza_create_presence(ctx, show, msg);
stanza_attach_priority(ctx, presence, pri);
@ -156,8 +157,8 @@ presence_update(jabber_presence_t presence_type, const char * const msg,
void
presence_join_room(Jid *jid)
{
xmpp_ctx_t *ctx = jabber_get_ctx();
xmpp_conn_t *conn = jabber_get_conn();
xmpp_ctx_t *ctx = connection_get_ctx();
xmpp_conn_t *conn = connection_get_conn();
jabber_presence_t presence_type = jabber_get_presence_type();
const char *show = stanza_get_presence_string_from_type(presence_type);
char *status = jabber_get_presence_message();
@ -177,8 +178,8 @@ presence_join_room(Jid *jid)
void
presence_change_room_nick(const char * const room, const char * const nick)
{
xmpp_ctx_t *ctx = jabber_get_ctx();
xmpp_conn_t *conn = jabber_get_conn();
xmpp_ctx_t *ctx = connection_get_ctx();
xmpp_conn_t *conn = connection_get_conn();
char *full_room_jid = create_fulljid(room, nick);
xmpp_stanza_t *presence = stanza_create_room_newnick_presence(ctx, full_room_jid);
xmpp_send(conn, presence);
@ -190,8 +191,8 @@ presence_change_room_nick(const char * const room, const char * const nick)
void
presence_leave_chat_room(const char * const room_jid)
{
xmpp_ctx_t *ctx = jabber_get_ctx();
xmpp_conn_t *conn = jabber_get_conn();
xmpp_ctx_t *ctx = connection_get_ctx();
xmpp_conn_t *conn = connection_get_conn();
char *nick = muc_get_room_nick(room_jid);
xmpp_stanza_t *presence = stanza_create_room_leave_presence(ctx, room_jid,
@ -214,7 +215,7 @@ _presence_handler(xmpp_conn_t * const conn,
Jid *from_jid = jid_create(from);
if ((type != NULL) && (strcmp(type, STANZA_TYPE_ERROR) == 0)) {
return error_handler(stanza);
return connection_error_handler(stanza);
}
// handle chat room presence
@ -283,8 +284,8 @@ _presence_handler(xmpp_conn_t * const conn,
static char *
_handle_presence_caps(xmpp_stanza_t * const stanza)
{
xmpp_ctx_t *ctx = jabber_get_ctx();
xmpp_conn_t *conn = jabber_get_conn();
xmpp_ctx_t *ctx = connection_get_ctx();
xmpp_conn_t *conn = connection_get_conn();
char *caps_key = NULL;
char *node = NULL;
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);

View File

@ -62,15 +62,8 @@ const char * jabber_get_jid(void);
jabber_conn_status_t jabber_get_connection_status(void);
jabber_presence_t jabber_get_presence_type(void);
char * jabber_get_presence_message(void);
void jabber_free_resources(void);
void jabber_restart(void);
void jabber_set_autoping(int seconds);
xmpp_conn_t *jabber_get_conn(void);
xmpp_ctx_t *jabber_get_ctx(void);
int error_handler(xmpp_stanza_t * const stanza);
void jabber_conn_set_presence_type(jabber_presence_t presence_type);
void jabber_conn_set_priority(int priority);
void jabber_conn_set_presence_message(const char * const message);
char* jabber_get_account_name(void);
// message functions