1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-15 19:38:07 -04:00

Added server_events.c

This commit is contained in:
James Booth 2014-01-05 20:52:45 +00:00
parent 4a8d6c2153
commit 87cdbe015a
5 changed files with 72 additions and 17 deletions

View File

@ -25,6 +25,7 @@ core_sources = \
src/xmpp/capabilities.h src/xmpp/connection.h \
src/xmpp/roster.c src/xmpp/roster.h \
src/xmpp/bookmark.c src/xmpp/bookmark.h \
src/server_events.c src/server_events.h \
src/ui/ui.h src/ui/window.c src/ui/window.h src/ui/core.c \
src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \
src/ui/console.c src/ui/notifier.c \

View File

@ -196,21 +196,6 @@ prof_handle_group_remove(const char * const contact,
ui_current_page_off();
}
void
prof_handle_error_message(const char *from, const char *err_msg)
{
ui_handle_error_message(from, err_msg);
if (g_strcmp0(err_msg, "conflict") == 0) {
// remove the room from muc
Jid *room_jid = jid_create(from);
if (!muc_get_roster_received(room_jid->barejid)) {
muc_leave_room(room_jid->barejid);
}
jid_destroy(room_jid);
}
}
void
prof_handle_subscription(const char *from, jabber_subscr_t type)
{

40
src/server_events.c Normal file
View File

@ -0,0 +1,40 @@
/*
* server_events.c
*
* 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/>.
*
*/
#include "ui/ui.h"
#include "muc.h"
void
handle_error_message(const char *from, const char *err_msg)
{
ui_handle_error_message(from, err_msg);
if (g_strcmp0(err_msg, "conflict") == 0) {
// remove the room from muc
Jid *room_jid = jid_create(from);
if (!muc_get_roster_received(room_jid->barejid)) {
muc_leave_room(room_jid->barejid);
}
jid_destroy(room_jid);
}
}

28
src/server_events.h Normal file
View File

@ -0,0 +1,28 @@
/*
* server_events.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 SERVER_EVENTS_H
#define SERVER_EVENTS_H
void handle_error_message(const char *from, const char *err_msg);
#endif

View File

@ -33,6 +33,7 @@
#include "log.h"
#include "muc.h"
#include "profanity.h"
#include "server_events.h"
#include "xmpp/bookmark.h"
#include "xmpp/capabilities.h"
#include "xmpp/connection.h"
@ -349,7 +350,7 @@ connection_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
if (text_stanza != NULL) {
err_msg = xmpp_stanza_get_text(text_stanza);
if (err_msg != NULL) {
prof_handle_error_message(from, err_msg);
handle_error_message(from, err_msg);
xmpp_free(ctx, err_msg);
}
@ -364,7 +365,7 @@ connection_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
} else {
err_msg = xmpp_stanza_get_name(err_cond);
prof_handle_error_message(from, err_msg);
handle_error_message(from, err_msg);
// TODO : process 'type' attribute from <error/> [RFC6120, 8.3.2]
}