author | franky |
Tue, 01 Nov 2016 08:39:07 +0100 | |
changeset 2291 | 0d350e979bde |
parent 2268 | f5402d705f67 |
child 2292 | f181418db215 |
permissions | -rw-r--r-- |
1599 | 1 |
/* |
2 |
* xmpp_iqrequest.c -- Jabber IQ request handling |
|
3 |
* |
|
1729
e6e89b1d7831
Minor style and header updates
Mikael Berthe <mikael@lilotux.net>
parents:
1719
diff
changeset
|
4 |
* Copyright (C) 2008-2010 Frank Zschockelt <mcabber@freakysoft.de> |
2134
fc7a758ebbde
Remove deprecated options comments, update headers
Mikael Berthe <mikael@lilotux.net>
parents:
2111
diff
changeset
|
5 |
* Copyright (C) 2005-2014 Mikael Berthe <mikael@lilotux.net> |
1599 | 6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
|
8 |
* it under the terms of the GNU General Public License as published by |
|
9 |
* the Free Software Foundation; either version 2 of the License, or (at |
|
10 |
* your option) any later version. |
|
11 |
* |
|
12 |
* This program is distributed in the hope that it will be useful, but |
|
13 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
15 |
* General Public License for more details. |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License |
|
2268
f5402d705f67
Fix FSF addresses in all files
Mikael Berthe <mikael@lilotux.net>
parents:
2134
diff
changeset
|
18 |
* along with this program; if not, see <http://www.gnu.org/licenses/>. |
1599 | 19 |
*/ |
1598 | 20 |
|
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
21 |
#include <string.h> |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
22 |
#include <stdlib.h> |
1705
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
23 |
#include <sys/time.h> |
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
24 |
|
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
25 |
#include "xmpp_helper.h" |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
26 |
#include "xmpp_iq.h" |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
27 |
#include "screen.h" |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
28 |
#include "utils.h" |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
29 |
#include "settings.h" |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
30 |
#include "hooks.h" |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
31 |
#include "hbuf.h" |
2104
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2103
diff
changeset
|
32 |
#include "carbons.h" |
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
33 |
|
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
34 |
extern LmMessageNode *bookmarks; |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
35 |
extern LmMessageNode *rosternotes; |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
36 |
|
1598 | 37 |
static LmHandlerResult cb_roster(LmMessageHandler *h, LmConnection *c, |
38 |
LmMessage *m, gpointer user_data); |
|
39 |
static LmHandlerResult cb_version(LmMessageHandler *h, LmConnection *c, |
|
40 |
LmMessage *m, gpointer user_data); |
|
41 |
static LmHandlerResult cb_time(LmMessageHandler *h, LmConnection *c, |
|
42 |
LmMessage *m, gpointer user_data); |
|
43 |
static LmHandlerResult cb_last(LmMessageHandler *h, LmConnection *c, |
|
44 |
LmMessage *m, gpointer user_data); |
|
1705
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
45 |
static LmHandlerResult cb_ping(LmMessageHandler *h, LmConnection *c, |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
46 |
LmMessage *m, gpointer user_data); |
1598 | 47 |
static LmHandlerResult cb_vcard(LmMessageHandler *h, LmConnection *c, |
48 |
LmMessage *m, gpointer user_data); |
|
2103
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
49 |
static LmHandlerResult cb_disco_info(LmMessageHandler *h, LmConnection *c, |
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
50 |
LmMessage *m, gpointer user_data); |
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
51 |
|
29 | 52 |
|
1598 | 53 |
static struct IqRequestHandlers |
54 |
{ |
|
55 |
const gchar *xmlns; |
|
56 |
const gchar *querytag; |
|
57 |
LmHandleMessageFunction handler; |
|
58 |
} iq_request_handlers[] = { |
|
2017 | 59 |
{NS_ROSTER, "query", &cb_roster}, |
60 |
{NS_VERSION, "query", &cb_version}, |
|
61 |
{NS_XMPP_TIME,"time", &cb_time}, |
|
62 |
{NS_LAST, "query", &cb_last}, |
|
63 |
{NS_PING, "ping", &cb_ping}, |
|
64 |
{NS_VCARD, "vCard", &cb_vcard}, |
|
2103
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
65 |
{NS_DISCO_INFO, "query", &cb_disco_info}, |
1598 | 66 |
{NULL, NULL, NULL} |
67 |
}; |
|
1254
401639413340
More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents:
1224
diff
changeset
|
68 |
|
1006 | 69 |
// Enum for vCard attributes |
70 |
enum vcard_attr { |
|
71 |
vcard_home = 1<<0, |
|
72 |
vcard_work = 1<<1, |
|
73 |
vcard_postal = 1<<2, |
|
74 |
vcard_voice = 1<<3, |
|
75 |
vcard_fax = 1<<4, |
|
76 |
vcard_cell = 1<<5, |
|
77 |
vcard_inet = 1<<6, |
|
78 |
vcard_pref = 1<<7, |
|
79 |
}; |
|
683 | 80 |
|
2103
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
81 |
static LmHandlerResult cb_disco_info(LmMessageHandler *h, LmConnection *c, |
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
82 |
LmMessage *m, gpointer user_data) |
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
83 |
{ |
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
84 |
LmMessageNode *ansqry; |
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
85 |
LmMessageNode *feature; |
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
86 |
|
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
87 |
ansqry = lm_message_node_get_child(m->node, "query"); |
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
88 |
|
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
89 |
feature = lm_message_node_get_child(ansqry, "feature"); |
2111 | 90 |
for (; feature; feature = feature->next) { |
2103
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
91 |
const char *v = lm_message_node_get_attribute(feature, "var"); |
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
92 |
|
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
93 |
if (!g_strcmp0(v, NS_CARBONS_2)) { |
2104
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2103
diff
changeset
|
94 |
carbons_available(); |
2103
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
95 |
} |
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
96 |
} |
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
97 |
|
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
98 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
99 |
} |
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
100 |
|
1705
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
101 |
static LmHandlerResult cb_ping(LmMessageHandler *h, LmConnection *c, |
1706 | 102 |
LmMessage *m, gpointer user_data) |
1705
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
103 |
{ |
1706 | 104 |
struct timeval *timestamp = (struct timeval *)user_data; |
1705
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
105 |
struct timeval now; |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
106 |
time_t dsec; |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
107 |
suseconds_t dusec; |
1706 | 108 |
const gchar *fjid; |
1707 | 109 |
gchar *bjid, *mesg = NULL; |
1705
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
110 |
|
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
111 |
gettimeofday(&now, NULL); |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
112 |
dsec = now.tv_sec - timestamp->tv_sec; |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
113 |
if (now.tv_usec < timestamp->tv_usec) { |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
114 |
dusec = now.tv_usec + 1000000 - timestamp->tv_usec; |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
115 |
--dsec; |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
116 |
} else |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
117 |
dusec = now.tv_usec - timestamp->tv_usec; |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
118 |
|
1706 | 119 |
// Check IQ result sender |
120 |
fjid = lm_message_get_from(m); |
|
121 |
if (!fjid) |
|
122 |
fjid = lm_connection_get_jid(lconnection); // No from means our JID... |
|
123 |
if (!fjid) { |
|
124 |
scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:version result (no sender name)."); |
|
125 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
|
126 |
} |
|
127 |
||
128 |
bjid = jidtodisp(fjid); |
|
129 |
||
130 |
switch (lm_message_get_sub_type(m)) { |
|
1705
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
131 |
case LM_MESSAGE_SUB_TYPE_RESULT: |
1707 | 132 |
mesg = g_strdup_printf("Pong from <%s>: %d second%s %d ms.", fjid, |
133 |
(int)dsec, dsec > 1 ? "s" : "", |
|
134 |
(int)(dusec/1000L)); |
|
1705
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
135 |
break; |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
136 |
|
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
137 |
case LM_MESSAGE_SUB_TYPE_ERROR: |
1800
d2747442918a
When displaying a server error, show the sender JID
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
138 |
display_server_error(lm_message_node_get_child(m->node, "error"), |
d2747442918a
When displaying a server error, show the sender JID
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
139 |
fjid); |
1707 | 140 |
mesg = g_strdup_printf("Ping to <%s> failed. " |
141 |
"Response time: %d second%s %d ms.", |
|
142 |
fjid, (int)dsec, dsec > 1 ? "s" : "", |
|
143 |
(int)(dusec/1000L)); |
|
1705
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
144 |
break; |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
145 |
|
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
146 |
default: |
1706 | 147 |
g_free(bjid); |
1705
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
148 |
return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
149 |
break; |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
150 |
} |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
151 |
|
1707 | 152 |
if (mesg) |
153 |
scr_WriteIncomingMessage(bjid, mesg, 0, HBB_PREFIX_INFO, 0); |
|
154 |
g_free(mesg); |
|
1706 | 155 |
g_free(bjid); |
1705
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
156 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
157 |
} |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
158 |
|
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
159 |
// Warning!! xmlns has to be a namespace from iq_request_handlers[].xmlns |
1598 | 160 |
void xmpp_iq_request(const char *fulljid, const char *xmlns) |
1215
80c095886fb5
Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents:
1213
diff
changeset
|
161 |
{ |
1598 | 162 |
LmMessage *iq; |
163 |
LmMessageNode *query; |
|
164 |
LmMessageHandler *handler; |
|
1705
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
165 |
gpointer data = NULL; |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
166 |
GDestroyNotify notifier = NULL; |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
167 |
GError *error = NULL; |
1598 | 168 |
int i; |
683 | 169 |
|
1598 | 170 |
iq = lm_message_new_with_sub_type(fulljid, LM_MESSAGE_TYPE_IQ, |
171 |
LM_MESSAGE_SUB_TYPE_GET); |
|
2017 | 172 |
for (i = 0; iq_request_handlers[i].xmlns && |
173 |
strcmp(iq_request_handlers[i].xmlns, xmlns) != 0 ; ++i) |
|
1598 | 174 |
; |
175 |
query = lm_message_node_add_child(iq->node, |
|
176 |
iq_request_handlers[i].querytag, |
|
177 |
NULL); |
|
178 |
lm_message_node_set_attribute(query, "xmlns", xmlns); |
|
1705
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
179 |
|
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
180 |
if (!g_strcmp0(xmlns, NS_PING)) { // Create handler for ping queries |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
181 |
struct timeval *now = g_new(struct timeval, 1); |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
182 |
gettimeofday(now, NULL); |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
183 |
data = (gpointer)now; |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
184 |
notifier = g_free; |
2103
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
185 |
} else if (!g_strcmp0(xmlns, NS_DISCO_INFO)) { |
2111 | 186 |
gchar *servername = get_servername(settings_opt_get("jid"), |
187 |
settings_opt_get("server")); |
|
2103
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
188 |
lm_message_node_set_attribute(iq->node, "to", servername); |
1210a22726d3
We can determine if the server supports carbons. By means of XEP-0030: Service
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2017
diff
changeset
|
189 |
g_free(servername); |
1705
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
190 |
} |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
191 |
|
1598 | 192 |
handler = lm_message_handler_new(iq_request_handlers[i].handler, |
1705
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
193 |
data, notifier); |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
194 |
|
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
195 |
lm_connection_send_with_reply(lconnection, iq, handler, &error); |
1598 | 196 |
lm_message_handler_unref(handler); |
197 |
lm_message_unref(iq); |
|
1705
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
198 |
|
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
199 |
if (error) { |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
200 |
scr_LogPrint(LPRINT_LOGNORM, "Error sending IQ request: %s.", error->message); |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
201 |
g_error_free(error); |
ac881b5f9248
Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents:
1703
diff
changeset
|
202 |
} |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
203 |
} |
29 | 204 |
|
1353
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
205 |
// This callback is reached when mcabber receives the first roster update |
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
206 |
// after the connection. |
1598 | 207 |
static LmHandlerResult cb_roster(LmMessageHandler *h, LmConnection *c, |
208 |
LmMessage *m, gpointer user_data) |
|
1353
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
209 |
{ |
1598 | 210 |
LmMessageNode *x; |
211 |
const char *ns; |
|
1353
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
212 |
|
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
213 |
// Only execute the hook if the roster has been successfully retrieved |
1598 | 214 |
if (lm_message_get_sub_type(m) != LM_MESSAGE_SUB_TYPE_RESULT) |
215 |
return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; |
|
1353
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
216 |
|
1598 | 217 |
x = lm_message_node_find_child(m->node, "query"); |
1353
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
218 |
if (!x) |
1598 | 219 |
return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; |
1365 | 220 |
|
1598 | 221 |
ns = lm_message_node_get_attribute(x, "xmlns"); |
1365 | 222 |
if (ns && !strcmp(ns, NS_ROSTER)) |
1598 | 223 |
handle_iq_roster(NULL, c, m, user_data); |
1353
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
224 |
|
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
225 |
// Post-login stuff |
1683
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
226 |
hk_postconnect(); |
1353
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
227 |
|
1598 | 228 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
1353
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
229 |
} |
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
230 |
|
1598 | 231 |
static LmHandlerResult cb_version(LmMessageHandler *h, LmConnection *c, |
232 |
LmMessage *m, gpointer user_data) |
|
1353
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
233 |
{ |
1598 | 234 |
LmMessageNode *ansqry; |
235 |
const char *p, *bjid; |
|
1703
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
236 |
char *buf, *tmp; |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
237 |
|
1703
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
238 |
// Check IQ result sender |
1698
e67bdd863638
Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents:
1683
diff
changeset
|
239 |
bjid = lm_message_get_from(m); |
e67bdd863638
Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents:
1683
diff
changeset
|
240 |
if (!bjid) |
1699
527c965b45c5
Add small comment in previous change
Mikael Berthe <mikael@lilotux.net>
parents:
1698
diff
changeset
|
241 |
bjid = lm_connection_get_jid(lconnection); // No from means our JID... |
1698
e67bdd863638
Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents:
1683
diff
changeset
|
242 |
if (!bjid) { |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
243 |
scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:version result (no sender name)."); |
1698
e67bdd863638
Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents:
1683
diff
changeset
|
244 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
245 |
} |
704
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
246 |
|
1703
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
247 |
// Check for error message |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
248 |
if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_ERROR) { |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
249 |
scr_LogPrint(LPRINT_LOGNORM, "Received error IQ message (%s)", bjid); |
1800
d2747442918a
When displaying a server error, show the sender JID
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
250 |
display_server_error(lm_message_node_get_child(m->node, "error"), NULL); |
1703
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
251 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
252 |
} |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
253 |
|
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
254 |
// Check message contents |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
255 |
ansqry = lm_message_node_get_child(m->node, "query"); |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
256 |
if (!ansqry) { |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
257 |
scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:version result from <%s>!", bjid); |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
258 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
259 |
} |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
260 |
|
782
19121d9f4aa2
Nicer message when receiving IQ result packet
Mikael Berthe <mikael@lilotux.net>
parents:
776
diff
changeset
|
261 |
buf = g_strdup_printf("Received IQ:version result from <%s>", bjid); |
704
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
262 |
scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
263 |
|
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
264 |
// bjid should now really be the "bare JID", let's strip the resource |
1598 | 265 |
tmp = strchr(bjid, JID_RESOURCE_SEPARATOR); |
266 |
if (tmp) *tmp = '\0'; |
|
704
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
267 |
|
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1283
diff
changeset
|
268 |
scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0); |
704
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
269 |
g_free(buf); |
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
270 |
|
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
271 |
// Get result data... |
1598 | 272 |
p = lm_message_node_get_child_value(ansqry, "name"); |
1899
decf94827efe
More lm_message_node_get_child_value() return value checks
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
273 |
if (p && *p) { |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
274 |
buf = g_strdup_printf("Name: %s", p); |
1333
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
275 |
scr_WriteIncomingMessage(bjid, buf, |
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
276 |
0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
277 |
g_free(buf); |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
278 |
} |
1598 | 279 |
p = lm_message_node_get_child_value(ansqry, "version"); |
1899
decf94827efe
More lm_message_node_get_child_value() return value checks
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
280 |
if (p && *p) { |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
281 |
buf = g_strdup_printf("Version: %s", p); |
1333
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
282 |
scr_WriteIncomingMessage(bjid, buf, |
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
283 |
0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
284 |
g_free(buf); |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
285 |
} |
1598 | 286 |
p = lm_message_node_get_child_value(ansqry, "os"); |
1899
decf94827efe
More lm_message_node_get_child_value() return value checks
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
287 |
if (p && *p) { |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
288 |
buf = g_strdup_printf("OS: %s", p); |
1333
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
289 |
scr_WriteIncomingMessage(bjid, buf, |
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
290 |
0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
291 |
g_free(buf); |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
292 |
} |
1598 | 293 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
294 |
} |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
295 |
|
1598 | 296 |
static LmHandlerResult cb_time(LmMessageHandler *h, LmConnection *c, |
297 |
LmMessage *m, gpointer user_data) |
|
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
298 |
{ |
1598 | 299 |
LmMessageNode *ansqry; |
300 |
const char *p, *bjid; |
|
1703
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
301 |
char *buf, *tmp; |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
302 |
|
1703
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
303 |
// Check IQ result sender |
1698
e67bdd863638
Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents:
1683
diff
changeset
|
304 |
bjid = lm_message_get_from(m); |
e67bdd863638
Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents:
1683
diff
changeset
|
305 |
if (!bjid) |
1699
527c965b45c5
Add small comment in previous change
Mikael Berthe <mikael@lilotux.net>
parents:
1698
diff
changeset
|
306 |
bjid = lm_connection_get_jid(lconnection); // No from means our JID... |
1698
e67bdd863638
Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents:
1683
diff
changeset
|
307 |
if (!bjid) { |
1703
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
308 |
scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:time result (no sender name)."); |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
309 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
310 |
} |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
311 |
|
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
312 |
// Check for error message |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
313 |
if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_ERROR) { |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
314 |
scr_LogPrint(LPRINT_LOGNORM, "Received error IQ message (%s)", bjid); |
1800
d2747442918a
When displaying a server error, show the sender JID
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
315 |
display_server_error(lm_message_node_get_child(m->node, "error"), NULL); |
1703
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
316 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
317 |
} |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
318 |
|
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
319 |
// Check message contents |
2017 | 320 |
ansqry = lm_message_node_get_child(m->node, "time"); |
1703
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
321 |
if (!ansqry) { |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
322 |
scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:time result from <%s>!", bjid); |
1698
e67bdd863638
Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents:
1683
diff
changeset
|
323 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
324 |
} |
704
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
325 |
|
782
19121d9f4aa2
Nicer message when receiving IQ result packet
Mikael Berthe <mikael@lilotux.net>
parents:
776
diff
changeset
|
326 |
buf = g_strdup_printf("Received IQ:time result from <%s>", bjid); |
704
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
327 |
scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
328 |
|
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
329 |
// bjid should now really be the "bare JID", let's strip the resource |
1598 | 330 |
tmp = strchr(bjid, JID_RESOURCE_SEPARATOR); |
331 |
if (tmp) *tmp = '\0'; |
|
704
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
332 |
|
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1283
diff
changeset
|
333 |
scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0); |
704
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
334 |
g_free(buf); |
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
335 |
|
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
336 |
// Get result data... |
1598 | 337 |
p = lm_message_node_get_child_value(ansqry, "utc"); |
1899
decf94827efe
More lm_message_node_get_child_value() return value checks
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
338 |
if (p && *p) { |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
339 |
buf = g_strdup_printf("UTC: %s", p); |
1333
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
340 |
scr_WriteIncomingMessage(bjid, buf, |
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
341 |
0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
342 |
g_free(buf); |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
343 |
} |
2017 | 344 |
p = lm_message_node_get_child_value(ansqry, "tzo"); |
1899
decf94827efe
More lm_message_node_get_child_value() return value checks
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
345 |
if (p && *p) { |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
346 |
buf = g_strdup_printf("TZ: %s", p); |
1333
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
347 |
scr_WriteIncomingMessage(bjid, buf, |
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
348 |
0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
349 |
g_free(buf); |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
350 |
} |
1598 | 351 |
p = lm_message_node_get_child_value(ansqry, "display"); |
1899
decf94827efe
More lm_message_node_get_child_value() return value checks
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
352 |
if (p && *p) { |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
353 |
buf = g_strdup_printf("Time: %s", p); |
1333
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
354 |
scr_WriteIncomingMessage(bjid, buf, |
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
355 |
0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
356 |
g_free(buf); |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
357 |
} |
1598 | 358 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
359 |
} |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
360 |
|
1598 | 361 |
static LmHandlerResult cb_last(LmMessageHandler *h, LmConnection *c, |
362 |
LmMessage *m, gpointer user_data) |
|
1015 | 363 |
{ |
1598 | 364 |
LmMessageNode *ansqry; |
365 |
const char *p, *bjid; |
|
366 |
char *buf, *tmp; |
|
1015 | 367 |
|
1703
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
368 |
// Check IQ result sender |
1698
e67bdd863638
Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents:
1683
diff
changeset
|
369 |
bjid = lm_message_get_from(m); |
e67bdd863638
Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents:
1683
diff
changeset
|
370 |
if (!bjid) |
1699
527c965b45c5
Add small comment in previous change
Mikael Berthe <mikael@lilotux.net>
parents:
1698
diff
changeset
|
371 |
bjid = lm_connection_get_jid(lconnection); // No from means our JID... |
1698
e67bdd863638
Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents:
1683
diff
changeset
|
372 |
if (!bjid) { |
1703
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
373 |
scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:last result (no sender name)."); |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
374 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
375 |
} |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
376 |
|
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
377 |
// Check for error message |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
378 |
if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_ERROR) { |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
379 |
scr_LogPrint(LPRINT_LOGNORM, "Received error IQ message (%s)", bjid); |
1800
d2747442918a
When displaying a server error, show the sender JID
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
380 |
display_server_error(lm_message_node_get_child(m->node, "error"), NULL); |
1703
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
381 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
382 |
} |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
383 |
|
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
384 |
// Check message contents |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
385 |
ansqry = lm_message_node_get_child(m->node, "query"); |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
386 |
if (!ansqry) { |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
387 |
scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:version result from <%s>!", bjid); |
1698
e67bdd863638
Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents:
1683
diff
changeset
|
388 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
1015 | 389 |
} |
390 |
||
391 |
buf = g_strdup_printf("Received IQ:last result from <%s>", bjid); |
|
392 |
scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
|
393 |
||
394 |
// bjid should now really be the "bare JID", let's strip the resource |
|
1598 | 395 |
tmp = strchr(bjid, JID_RESOURCE_SEPARATOR); |
396 |
if (tmp) *tmp = '\0'; |
|
1015 | 397 |
|
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1283
diff
changeset
|
398 |
scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0); |
1015 | 399 |
g_free(buf); |
400 |
||
401 |
// Get result data... |
|
1598 | 402 |
p = lm_message_node_get_attribute(ansqry, "seconds"); |
1015 | 403 |
if (p) { |
404 |
long int s; |
|
405 |
GString *sbuf; |
|
406 |
sbuf = g_string_new("Idle time: "); |
|
407 |
s = atol(p); |
|
408 |
// Days |
|
409 |
if (s > 86400L) { |
|
410 |
g_string_append_printf(sbuf, "%ldd ", s/86400L); |
|
411 |
s %= 86400L; |
|
412 |
} |
|
413 |
// hh:mm:ss |
|
414 |
g_string_append_printf(sbuf, "%02ld:", s/3600L); |
|
415 |
s %= 3600L; |
|
416 |
g_string_append_printf(sbuf, "%02ld:%02ld", s/60L, s%60L); |
|
1268
dbc907b2d92f
Add configurable colors for info and incoming messages (Michal 'vorner' Vaner)
Mikael Berthe <mikael@lilotux.net>
parents:
1261
diff
changeset
|
417 |
scr_WriteIncomingMessage(bjid, sbuf->str, |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1283
diff
changeset
|
418 |
0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); |
1015 | 419 |
g_string_free(sbuf, TRUE); |
420 |
} else { |
|
421 |
scr_WriteIncomingMessage(bjid, "No idle time reported.", |
|
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1283
diff
changeset
|
422 |
0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); |
1015 | 423 |
} |
1598 | 424 |
p = lm_message_node_get_value(ansqry); |
1015 | 425 |
if (p) { |
426 |
buf = g_strdup_printf("Status message: %s", p); |
|
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1283
diff
changeset
|
427 |
scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0); |
1015 | 428 |
g_free(buf); |
429 |
} |
|
1598 | 430 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
1015 | 431 |
} |
432 |
||
1006 | 433 |
static void display_vcard_item(const char *bjid, const char *label, |
434 |
enum vcard_attr vcard_attrib, const char *text) |
|
435 |
{ |
|
436 |
char *buf; |
|
437 |
||
1899
decf94827efe
More lm_message_node_get_child_value() return value checks
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
438 |
if (!text || !*text || !bjid || !label) |
1006 | 439 |
return; |
440 |
||
441 |
buf = g_strdup_printf("%s: %s%s%s%s%s%s%s%s%s%s", label, |
|
442 |
(vcard_attrib & vcard_home ? "[home]" : ""), |
|
443 |
(vcard_attrib & vcard_work ? "[work]" : ""), |
|
444 |
(vcard_attrib & vcard_postal ? "[postal]" : ""), |
|
445 |
(vcard_attrib & vcard_voice ? "[voice]" : ""), |
|
446 |
(vcard_attrib & vcard_fax ? "[fax]" : ""), |
|
447 |
(vcard_attrib & vcard_cell ? "[cell]" : ""), |
|
448 |
(vcard_attrib & vcard_inet ? "[inet]" : ""), |
|
449 |
(vcard_attrib & vcard_pref ? "[pref]" : ""), |
|
450 |
(vcard_attrib ? " " : ""), |
|
451 |
text); |
|
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1283
diff
changeset
|
452 |
scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); |
1006 | 453 |
g_free(buf); |
454 |
} |
|
455 |
||
1598 | 456 |
static void handle_vcard_node(const char *barejid, LmMessageNode *vcardnode) |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
457 |
{ |
1598 | 458 |
LmMessageNode *x; |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
459 |
const char *p; |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
460 |
|
1598 | 461 |
for (x = vcardnode->children ; x; x = x->next) { |
1006 | 462 |
const char *data; |
463 |
enum vcard_attr vcard_attrib = 0; |
|
464 |
||
1598 | 465 |
p = x->name; |
1719
f3c5e1175b22
Remove buggy check in handle_vcard_node() (Reported by Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents:
1707
diff
changeset
|
466 |
if (!p) |
f3c5e1175b22
Remove buggy check in handle_vcard_node() (Reported by Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents:
1707
diff
changeset
|
467 |
continue; |
f3c5e1175b22
Remove buggy check in handle_vcard_node() (Reported by Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents:
1707
diff
changeset
|
468 |
|
1598 | 469 |
data = lm_message_node_get_value(x); |
1006 | 470 |
|
471 |
if (!strcmp(p, "FN")) |
|
472 |
display_vcard_item(barejid, "Name", vcard_attrib, data); |
|
473 |
else if (!strcmp(p, "NICKNAME")) |
|
474 |
display_vcard_item(barejid, "Nickname", vcard_attrib, data); |
|
475 |
else if (!strcmp(p, "URL")) |
|
476 |
display_vcard_item(barejid, "URL", vcard_attrib, data); |
|
477 |
else if (!strcmp(p, "BDAY")) |
|
478 |
display_vcard_item(barejid, "Birthday", vcard_attrib, data); |
|
479 |
else if (!strcmp(p, "TZ")) |
|
480 |
display_vcard_item(barejid, "Timezone", vcard_attrib, data); |
|
481 |
else if (!strcmp(p, "TITLE")) |
|
482 |
display_vcard_item(barejid, "Title", vcard_attrib, data); |
|
483 |
else if (!strcmp(p, "ROLE")) |
|
484 |
display_vcard_item(barejid, "Role", vcard_attrib, data); |
|
485 |
else if (!strcmp(p, "DESC")) |
|
486 |
display_vcard_item(barejid, "Comment", vcard_attrib, data); |
|
487 |
else if (!strcmp(p, "N")) { |
|
1598 | 488 |
data = lm_message_node_get_child_value(x, "FAMILY"); |
1006 | 489 |
display_vcard_item(barejid, "Family Name", vcard_attrib, data); |
1598 | 490 |
data = lm_message_node_get_child_value(x, "GIVEN"); |
1006 | 491 |
display_vcard_item(barejid, "Given Name", vcard_attrib, data); |
1598 | 492 |
data = lm_message_node_get_child_value(x, "MIDDLE"); |
1006 | 493 |
display_vcard_item(barejid, "Middle Name", vcard_attrib, data); |
494 |
} else if (!strcmp(p, "ORG")) { |
|
1598 | 495 |
data = lm_message_node_get_child_value(x, "ORGNAME"); |
1006 | 496 |
display_vcard_item(barejid, "Organisation name", vcard_attrib, data); |
1598 | 497 |
data = lm_message_node_get_child_value(x, "ORGUNIT"); |
1006 | 498 |
display_vcard_item(barejid, "Organisation unit", vcard_attrib, data); |
499 |
} else { |
|
500 |
// The HOME, WORK and PREF attributes are common to the remaining fields |
|
501 |
// (ADR, TEL & EMAIL) |
|
1598 | 502 |
if (lm_message_node_get_child(x, "HOME")) |
1006 | 503 |
vcard_attrib |= vcard_home; |
1598 | 504 |
if (lm_message_node_get_child(x, "WORK")) |
1006 | 505 |
vcard_attrib |= vcard_work; |
1598 | 506 |
if (lm_message_node_get_child(x, "PREF")) |
1006 | 507 |
vcard_attrib |= vcard_pref; |
508 |
if (!strcmp(p, "ADR")) { // Address |
|
1598 | 509 |
if (lm_message_node_get_child(x, "POSTAL")) |
1006 | 510 |
vcard_attrib |= vcard_postal; |
1598 | 511 |
data = lm_message_node_get_child_value(x, "EXTADD"); |
1006 | 512 |
display_vcard_item(barejid, "Addr (ext)", vcard_attrib, data); |
1598 | 513 |
data = lm_message_node_get_child_value(x, "STREET"); |
1006 | 514 |
display_vcard_item(barejid, "Street", vcard_attrib, data); |
1598 | 515 |
data = lm_message_node_get_child_value(x, "LOCALITY"); |
1006 | 516 |
display_vcard_item(barejid, "Locality", vcard_attrib, data); |
1598 | 517 |
data = lm_message_node_get_child_value(x, "REGION"); |
1006 | 518 |
display_vcard_item(barejid, "Region", vcard_attrib, data); |
1598 | 519 |
data = lm_message_node_get_child_value(x, "PCODE"); |
1006 | 520 |
display_vcard_item(barejid, "Postal code", vcard_attrib, data); |
1598 | 521 |
data = lm_message_node_get_child_value(x, "CTRY"); |
1006 | 522 |
display_vcard_item(barejid, "Country", vcard_attrib, data); |
523 |
} else if (!strcmp(p, "TEL")) { // Telephone |
|
1598 | 524 |
data = lm_message_node_get_child_value(x, "NUMBER"); |
1005 | 525 |
if (data) { |
1598 | 526 |
if (lm_message_node_get_child(x, "VOICE")) |
1006 | 527 |
vcard_attrib |= vcard_voice; |
1598 | 528 |
if (lm_message_node_get_child(x, "FAX")) |
1006 | 529 |
vcard_attrib |= vcard_fax; |
1598 | 530 |
if (lm_message_node_get_child(x, "CELL")) |
1006 | 531 |
vcard_attrib |= vcard_cell; |
532 |
display_vcard_item(barejid, "Phone", vcard_attrib, data); |
|
1005 | 533 |
} |
1006 | 534 |
} else if (!strcmp(p, "EMAIL")) { // Email |
1598 | 535 |
if (lm_message_node_get_child(x, "INTERNET")) |
1006 | 536 |
vcard_attrib |= vcard_inet; |
1598 | 537 |
data = lm_message_node_get_child_value(x, "USERID"); |
1006 | 538 |
display_vcard_item(barejid, "Email", vcard_attrib, data); |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
539 |
} |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
540 |
} |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
541 |
} |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
542 |
} |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
543 |
|
1598 | 544 |
static LmHandlerResult cb_vcard(LmMessageHandler *h, LmConnection *c, |
545 |
LmMessage *m, gpointer user_data) |
|
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
546 |
{ |
1598 | 547 |
LmMessageNode *ansqry; |
1698
e67bdd863638
Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents:
1683
diff
changeset
|
548 |
const char *bjid; |
1598 | 549 |
char *buf, *tmp; |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
550 |
|
1703
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
551 |
// Check IQ result sender |
1698
e67bdd863638
Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents:
1683
diff
changeset
|
552 |
bjid = lm_message_get_from(m); |
e67bdd863638
Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents:
1683
diff
changeset
|
553 |
if (!bjid) |
1699
527c965b45c5
Add small comment in previous change
Mikael Berthe <mikael@lilotux.net>
parents:
1698
diff
changeset
|
554 |
bjid = lm_connection_get_jid(lconnection); // No from means our JID... |
1698
e67bdd863638
Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents:
1683
diff
changeset
|
555 |
if (!bjid) { |
1703
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
556 |
scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:vCard result (no sender name)."); |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
557 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
558 |
} |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
559 |
|
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
560 |
// Check for error message |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
561 |
if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_ERROR) { |
65ba89949252
Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents:
1699
diff
changeset
|
562 |
scr_LogPrint(LPRINT_LOGNORM, "Received error IQ message (%s)", bjid); |
1800
d2747442918a
When displaying a server error, show the sender JID
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
563 |
display_server_error(lm_message_node_get_child(m->node, "error"), NULL); |
1698
e67bdd863638
Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents:
1683
diff
changeset
|
564 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
565 |
} |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
566 |
|
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
567 |
buf = g_strdup_printf("Received IQ:vCard result from <%s>", bjid); |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
568 |
scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
569 |
|
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
570 |
// Get the vCard node |
1598 | 571 |
ansqry = lm_message_node_get_child(m->node, "vCard"); |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
572 |
if (!ansqry) { |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
573 |
scr_LogPrint(LPRINT_LOGNORM, "Empty IQ:vCard result!"); |
1340
2031f4b2cced
Fix a small memory leak
Mikael Berthe <mikael@lilotux.net>
parents:
1334
diff
changeset
|
574 |
g_free(buf); |
1598 | 575 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
576 |
} |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
577 |
|
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
578 |
// bjid should really be the "bare JID", let's strip the resource |
1598 | 579 |
tmp = strchr(bjid, JID_RESOURCE_SEPARATOR); |
580 |
if (tmp) *tmp = '\0'; |
|
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
581 |
|
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1283
diff
changeset
|
582 |
scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0); |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
583 |
g_free(buf); |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
584 |
|
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
585 |
// Get result data... |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
586 |
handle_vcard_node(bjid, ansqry); |
1598 | 587 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
588 |
} |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
589 |
|
1598 | 590 |
static void storage_bookmarks_parse_conference(LmMessageNode *node) |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
591 |
{ |
1058 | 592 |
const char *fjid, *name, *autojoin; |
1979
6febc7d1f760
Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents:
1976
diff
changeset
|
593 |
const char *pstatus, *awhois, *fjoins, *group; |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
594 |
char *bjid; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
595 |
GSList *room_elt; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
596 |
|
1598 | 597 |
fjid = lm_message_node_get_attribute(node, "jid"); |
1058 | 598 |
if (!fjid) |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
599 |
return; |
1598 | 600 |
name = lm_message_node_get_attribute(node, "name"); |
601 |
autojoin = lm_message_node_get_attribute(node, "autojoin"); |
|
602 |
awhois = lm_message_node_get_attribute(node, "autowhois"); |
|
603 |
pstatus = lm_message_node_get_child_value(node, "print_status"); |
|
1979
6febc7d1f760
Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents:
1976
diff
changeset
|
604 |
fjoins = lm_message_node_get_child_value(node, "flag_joins"); |
1976
e6beab22099b
Do not add items to roster with commands /move and /rename (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents:
1899
diff
changeset
|
605 |
group = lm_message_node_get_child_value(node, "group"); |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
606 |
|
1058 | 607 |
bjid = jidtodisp(fjid); // Bare jid |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
608 |
|
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
609 |
// Make sure this is a room (it can be a conversion user->room) |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
610 |
room_elt = roster_find(bjid, jidsearch, 0); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
611 |
if (!room_elt) { |
1976
e6beab22099b
Do not add items to roster with commands /move and /rename (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents:
1899
diff
changeset
|
612 |
room_elt = roster_add_user(bjid, name, group, ROSTER_TYPE_ROOM, |
1355 | 613 |
sub_none, -1); |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
614 |
} else { |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
615 |
buddy_settype(room_elt->data, ROSTER_TYPE_ROOM); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
616 |
/* |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
617 |
// If the name is available, should we use it? |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
618 |
// I don't think so, it would be confusing because this item is already |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
619 |
// in the roster. |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
620 |
if (name) |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
621 |
buddy_setname(room_elt->data, name); |
1976
e6beab22099b
Do not add items to roster with commands /move and /rename (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents:
1899
diff
changeset
|
622 |
|
e6beab22099b
Do not add items to roster with commands /move and /rename (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents:
1899
diff
changeset
|
623 |
// The same question for roster group. |
e6beab22099b
Do not add items to roster with commands /move and /rename (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents:
1899
diff
changeset
|
624 |
if (group) |
e6beab22099b
Do not add items to roster with commands /move and /rename (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents:
1899
diff
changeset
|
625 |
buddy_setgroup(room_elt->data, group); |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
626 |
*/ |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
627 |
} |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
628 |
|
1379
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
629 |
// Set the print_status and auto_whois values |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
630 |
if (pstatus) { |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
631 |
enum room_printstatus i; |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
632 |
for (i = status_none; i <= status_all; i++) |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
633 |
if (!strcasecmp(pstatus, strprintstatus[i])) |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
634 |
break; |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
635 |
if (i <= status_all) |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
636 |
buddy_setprintstatus(room_elt->data, i); |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
637 |
} |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
638 |
if (awhois) { |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
639 |
enum room_autowhois i = autowhois_default; |
1976
e6beab22099b
Do not add items to roster with commands /move and /rename (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents:
1899
diff
changeset
|
640 |
if (!strcmp(awhois, "1") || !(strcmp(awhois, "true"))) |
1379
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
641 |
i = autowhois_on; |
1976
e6beab22099b
Do not add items to roster with commands /move and /rename (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents:
1899
diff
changeset
|
642 |
else if (!strcmp(awhois, "0") || !(strcmp(awhois, "false"))) |
1379
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
643 |
i = autowhois_off; |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
644 |
if (i != autowhois_default) |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
645 |
buddy_setautowhois(room_elt->data, i); |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
646 |
} |
1979
6febc7d1f760
Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents:
1976
diff
changeset
|
647 |
if (fjoins) { |
6febc7d1f760
Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents:
1976
diff
changeset
|
648 |
enum room_flagjoins i; |
6febc7d1f760
Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents:
1976
diff
changeset
|
649 |
for (i = flagjoins_none; i <= flagjoins_all; i++) |
6febc7d1f760
Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents:
1976
diff
changeset
|
650 |
if (!strcasecmp(fjoins, strflagjoins[i])) |
6febc7d1f760
Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents:
1976
diff
changeset
|
651 |
break; |
6febc7d1f760
Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents:
1976
diff
changeset
|
652 |
if (i <= flagjoins_all) |
6febc7d1f760
Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents:
1976
diff
changeset
|
653 |
buddy_setflagjoins(room_elt->data, i); |
6febc7d1f760
Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents:
1976
diff
changeset
|
654 |
} |
1379
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
655 |
|
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
656 |
// Is autojoin set? |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
657 |
// If it is, we'll look up for more information (nick? password?) and |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
658 |
// try to join the room. |
2004
aa7e03c35488
Accept "true" as well as "1" for autojoin in bookmarked rooms
Hermitifier
parents:
2003
diff
changeset
|
659 |
if (autojoin && (!strcmp(autojoin, "1") || !strcmp(autojoin, "true"))) { |
1598 | 660 |
const char *nick, *passwd; |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
661 |
char *tmpnick = NULL; |
1598 | 662 |
nick = lm_message_node_get_child_value(node, "nick"); |
663 |
passwd = lm_message_node_get_child_value(node, "password"); |
|
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
664 |
if (!nick || !*nick) |
1395
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1393
diff
changeset
|
665 |
nick = tmpnick = default_muc_nickname(NULL); |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
666 |
// Let's join now |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
667 |
scr_LogPrint(LPRINT_LOGNORM, "Auto-join bookmark <%s>", bjid); |
1598 | 668 |
xmpp_room_join(bjid, nick, passwd); |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
669 |
g_free(tmpnick); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
670 |
} |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
671 |
g_free(bjid); |
1983
45e0b13a39e2
Refresh the roster when MUC bookmarks are received
Jan Zachorowski <quantifier666@gmail.com>
parents:
1979
diff
changeset
|
672 |
|
2291
0d350e979bde
Don't rebuild the buddylist multiple times before a screen refresh
franky
parents:
2268
diff
changeset
|
673 |
buddylist_defer_build(); |
1983
45e0b13a39e2
Refresh the roster when MUC bookmarks are received
Jan Zachorowski <quantifier666@gmail.com>
parents:
1979
diff
changeset
|
674 |
update_roster = TRUE; |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
675 |
} |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
676 |
|
1598 | 677 |
static LmHandlerResult cb_storage_bookmarks(LmMessageHandler *h, |
678 |
LmConnection *c, |
|
679 |
LmMessage *m, gpointer user_data) |
|
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
680 |
{ |
1598 | 681 |
LmMessageNode *x, *ansqry; |
2003 | 682 |
char *p = NULL; |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
683 |
|
1598 | 684 |
if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_ERROR) { |
2003 | 685 |
LmMessageNode *error = lm_message_node_get_child(m->node, "error"); |
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
686 |
// No server support, or no bookmarks? |
2003 | 687 |
if (error && error->children) |
688 |
p = error->children->name; |
|
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
689 |
if (p && !strcmp(p, "item-not-found")) { |
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
690 |
// item-no-found means the server has Private Storage, but it's |
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
691 |
// currently empty. |
1598 | 692 |
if (bookmarks) |
693 |
lm_message_node_unref(bookmarks); |
|
694 |
bookmarks = lm_message_node_new("storage", "storage:bookmarks"); |
|
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
695 |
// We return 0 so that the IQ error message be |
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
696 |
// not displayed, as it isn't a real error. |
2003 | 697 |
} else |
698 |
scr_LogPrint(LPRINT_LOGNORM, "Server does not support bookmarks storage."); |
|
699 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
|
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
700 |
} |
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
701 |
|
1598 | 702 |
ansqry = lm_message_node_get_child(m->node, "query"); |
703 |
ansqry = lm_message_node_get_child(ansqry, "storage"); |
|
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
704 |
if (!ansqry) { |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
705 |
scr_LogPrint(LPRINT_LOG, "Invalid IQ:private result! (storage:bookmarks)"); |
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
706 |
return 0; |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
707 |
} |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
708 |
|
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
709 |
// Walk through the storage tags |
1598 | 710 |
for (x = ansqry->children ; x; x = x->next) { |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
711 |
// If the current node is a conference item, parse it and update the roster |
1598 | 712 |
if (x->name && !strcmp(x->name, "conference")) |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
713 |
storage_bookmarks_parse_conference(x); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
714 |
} |
1598 | 715 |
// "Copy" the bookmarks node |
716 |
if (bookmarks) |
|
717 |
lm_message_node_unref(bookmarks); |
|
718 |
lm_message_node_deep_ref(ansqry); |
|
719 |
bookmarks = ansqry; |
|
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
720 |
return 0; |
686
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
685
diff
changeset
|
721 |
} |
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
685
diff
changeset
|
722 |
|
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
723 |
|
1598 | 724 |
static LmHandlerResult cb_storage_rosternotes(LmMessageHandler *h, |
725 |
LmConnection *c, |
|
726 |
LmMessage *m, gpointer user_data) |
|
1261
704adf4df2d0
Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents:
1255
diff
changeset
|
727 |
{ |
1598 | 728 |
LmMessageNode *ansqry; |
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
729 |
|
1598 | 730 |
if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_ERROR) { |
2003 | 731 |
const char *p = NULL; |
732 |
LmMessageNode *error = lm_message_node_get_child(m->node, "error"); |
|
1598 | 733 |
// No server support, or no roster notes? |
2003 | 734 |
if (error && error->children) |
735 |
p = error->children->name; |
|
1598 | 736 |
if (p && !strcmp(p, "item-not-found")) { |
737 |
// item-no-found means the server has Private Storage, but it's |
|
738 |
// currently empty. |
|
739 |
if (rosternotes) |
|
740 |
lm_message_node_unref(rosternotes); |
|
741 |
rosternotes = lm_message_node_new("storage", "storage:rosternotes"); |
|
742 |
// We return 0 so that the IQ error message be |
|
743 |
// not displayed, as it isn't a real error. |
|
2003 | 744 |
} else |
745 |
scr_LogPrint(LPRINT_LOGNORM, "Server does not support roster notes storage."); |
|
746 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
|
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
747 |
} |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
748 |
|
1598 | 749 |
ansqry = lm_message_node_get_child(m->node, "query"); |
750 |
ansqry = lm_message_node_get_child(ansqry, "storage"); |
|
751 |
if (!ansqry) { |
|
752 |
scr_LogPrint(LPRINT_LOG, "Invalid IQ:private result! " |
|
753 |
"(storage:rosternotes)"); |
|
754 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
|
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
755 |
} |
1598 | 756 |
// Copy the rosternotes node |
757 |
if (rosternotes) |
|
758 |
lm_message_node_unref(rosternotes); |
|
759 |
lm_message_node_deep_ref(ansqry); |
|
760 |
rosternotes = ansqry; |
|
761 |
return 0; |
|
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
762 |
} |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
763 |
|
995
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
764 |
|
1598 | 765 |
static struct IqRequestStorageHandlers |
1254
401639413340
More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents:
1224
diff
changeset
|
766 |
{ |
1598 | 767 |
const gchar *storagens; |
768 |
LmHandleMessageFunction handler; |
|
769 |
} iq_request_storage_handlers[] = { |
|
770 |
{"storage:rosternotes", &cb_storage_rosternotes}, |
|
771 |
{"storage:bookmarks", &cb_storage_bookmarks}, |
|
772 |
{NULL, NULL} |
|
773 |
}; |
|
619
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
774 |
|
1598 | 775 |
void xmpp_request_storage(const gchar *storage) |
619
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
776 |
{ |
1598 | 777 |
LmMessage *iq; |
778 |
LmMessageNode *query; |
|
779 |
LmMessageHandler *handler; |
|
780 |
int i; |
|
703
8cbcbff8de7d
Fix UTC time in IQ:version queries
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
781 |
|
1598 | 782 |
iq = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_IQ, |
783 |
LM_MESSAGE_SUB_TYPE_GET); |
|
784 |
query = lm_message_node_add_child(iq->node, "query", NULL); |
|
785 |
lm_message_node_set_attribute(query, "xmlns", NS_PRIVATE); |
|
786 |
lm_message_node_set_attribute(lm_message_node_add_child |
|
787 |
(query, "storage", NULL), |
|
788 |
"xmlns", storage); |
|
1283
2faf179166f3
Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents:
1268
diff
changeset
|
789 |
|
1598 | 790 |
for (i = 0; |
791 |
strcmp(iq_request_storage_handlers[i].storagens, storage) != 0; |
|
792 |
++i) ; |
|
595
0c1d37300862
IQ: send feature-not-implemented error stanzas
Mikael Berthe <mikael@lilotux.net>
parents:
582
diff
changeset
|
793 |
|
1598 | 794 |
handler = lm_message_handler_new(iq_request_storage_handlers[i].handler, |
795 |
NULL, FALSE); |
|
796 |
lm_connection_send_with_reply(lconnection, iq, handler, NULL); |
|
797 |
lm_message_handler_unref(handler); |
|
798 |
lm_message_unref(iq); |
|
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
799 |
} |
1599 | 800 |
|
1811 | 801 |
/* vim: set et cindent cinoptions=>2\:2(0 ts=2 sw=2: For Vim users... */ |