~ubuntu-branches/ubuntu/trusty/irssi-plugin-xmpp/trusty

« back to all changes in this revision

Viewing changes to src/core/xmpp-session.c

  • Committer: Bazaar Package Importer
  • Author(s): David Ammouial
  • Date: 2009-05-12 12:14:44 UTC
  • mfrom: (1.1.3 upstream) (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090512121444-5jeho5h3zsy4oij7
Tags: 0.13+cvs20090406-1
* New CVS snapshot, built against irssi-dev 0.8.13:
  - New features and bugfixes.
  - Fix segfault when successfully identified (Closes: #521227).
  - Fix build error (Closes: #527697)
* Depend on irssi >=0.8.13, build-depend on irssi-dev >=0.8.13.
* Bump Standards-Version to 3.8.1 (no changes needed).
* Add INTERNAL to documentation files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * $Id: xmpp-session.c,v 1.2 2008/03/01 17:57:21 errtu Exp $
3
 
 *
4
 
 * Copyright (C) 2007 Colin DIDIER
5
 
 *
6
 
 * This program is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License version 2 as
8
 
 * published by the Free Software Foundation.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License along
16
 
 * with this program; if not, write to the Free Software Foundation, Inc.,
17
 
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
 
 */
19
 
 
20
 
#include <string.h>
21
 
#include <time.h>
22
 
 
23
 
#include "module.h"
24
 
#include "misc.h"
25
 
#include "settings.h"
26
 
#include "signals.h"
27
 
#include "lib-config/iconfig.h"
28
 
 
29
 
#include "xmpp-channels.h"
30
 
#include "xmpp-protocol.h"
31
 
#include "xmpp-rosters.h"
32
 
#include "xmpp-servers.h"
33
 
#include "xmpp-tools.h"
34
 
 
35
 
static void
36
 
sig_session_save_server(XMPP_SERVER_REC *server, CONFIG_REC *config,
37
 
    CONFIG_NODE *node)
38
 
{
39
 
        if (!IS_XMPP_SERVER(server))
40
 
                return;
41
 
 
42
 
        config_node_set_bool(config, node, "usermode_away", server->usermode_away);
43
 
        config_node_set_str(config, node, "away_reason", server->away_reason);
44
 
 
45
 
        config_node_set_int(config, node, "show", server->show);
46
 
        config_node_set_bool(config, node, "default_priority",
47
 
            server->default_priority);
48
 
        config_node_set_int(config, node, "priority", server->priority);
49
 
}
50
 
 
51
 
static void
52
 
sig_session_restore_server(XMPP_SERVER_REC *server, CONFIG_NODE *node)
53
 
{
54
 
        if (!IS_XMPP_SERVER(server))
55
 
                return;
56
 
 
57
 
        server->usermode_away = config_node_get_bool(node, "usermode_away",
58
 
            FALSE);
59
 
        
60
 
        signal_emit("xmpp own_presence", 4, server,
61
 
            config_node_get_int(node, "show", XMPP_PRESENCE_AVAILABLE),
62
 
            config_node_get_str(node, "away_reason", NULL),
63
 
            config_node_get_bool(node, "priority", TRUE) ?
64
 
                config_node_get_int(node, "priority", 0) : server->priority);
65
 
}
66
 
 
67
 
static void
68
 
sig_session_restore_nick(XMPP_CHANNEL_REC *channel, CONFIG_NODE *node)
69
 
{
70
 
}
71
 
 
72
 
static void
73
 
session_restore_channel(XMPP_CHANNEL_REC *channel)
74
 
{
75
 
        g_return_if_fail(IS_XMPP_CHANNEL(channel));
76
 
}
77
 
 
78
 
static void
79
 
sig_connected(XMPP_SERVER_REC *server)
80
 
{
81
 
        GSList *tmp;
82
 
 
83
 
        if (!IS_XMPP_SERVER(server) || !server->session_reconnect)
84
 
                return;
85
 
 
86
 
        for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
87
 
                XMPP_CHANNEL_REC *channel = XMPP_CHANNEL(tmp->data);
88
 
 
89
 
                if (channel != NULL && channel->session_rejoin)
90
 
                        session_restore_channel(channel);
91
 
        }
92
 
}
93
 
 
94
 
void
95
 
xmpp_session_init(void)
96
 
{
97
 
        signal_add("session save server",
98
 
            (SIGNAL_FUNC)sig_session_save_server);
99
 
        signal_add("session restore server",
100
 
            (SIGNAL_FUNC)sig_session_restore_server);
101
 
        signal_add("session restore nick",
102
 
            (SIGNAL_FUNC)sig_session_restore_nick);
103
 
        signal_add("event connected", (SIGNAL_FUNC)sig_connected);
104
 
}
105
 
 
106
 
void
107
 
xmpp_session_deinit(void)
108
 
{
109
 
        signal_remove("session save server",
110
 
            (SIGNAL_FUNC)sig_session_save_server);
111
 
        signal_remove("session restore server",
112
 
            (SIGNAL_FUNC)sig_session_restore_server);
113
 
        signal_remove("session restore nick",
114
 
            (SIGNAL_FUNC)sig_session_restore_nick);
115
 
        signal_remove("event connected", (SIGNAL_FUNC)sig_connected);
116
 
}