author | Myhailo Danylenko <isbear@ukrpost.net> |
Tue, 19 Jan 2010 16:09:27 +0200 | |
changeset 1683 | b09f82f61745 |
parent 1668 | 41c26b7d2890 |
child 1698 | e67bdd863638 |
permissions | -rw-r--r-- |
1599 | 1 |
/* |
2 |
* xmpp_iqrequest.c -- Jabber IQ request handling |
|
3 |
* |
|
4 |
* Copyright (C) 2008-2009 Frank Zschockelt <mcabber@freakysoft.de> |
|
5 |
* Copyright (C) 2005-2009 Mikael Berthe <mikael@lilotux.net> |
|
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 |
|
18 |
* along with this program; if not, write to the Free Software |
|
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|
20 |
* USA |
|
21 |
*/ |
|
1598 | 22 |
|
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
23 |
#include <string.h> |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
24 |
#include <stdlib.h> |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
25 |
|
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
26 |
#include "xmpp_helper.h" |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
27 |
#include "xmpp_iq.h" |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
28 |
#include "screen.h" |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
29 |
#include "utils.h" |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
30 |
#include "settings.h" |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
31 |
#include "hooks.h" |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1599
diff
changeset
|
32 |
#include "hbuf.h" |
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); |
|
45 |
static LmHandlerResult cb_vcard(LmMessageHandler *h, LmConnection *c, |
|
46 |
LmMessage *m, gpointer user_data); |
|
29 | 47 |
|
1598 | 48 |
static struct IqRequestHandlers |
49 |
{ |
|
50 |
const gchar *xmlns; |
|
51 |
const gchar *querytag; |
|
52 |
LmHandleMessageFunction handler; |
|
53 |
} iq_request_handlers[] = { |
|
54 |
{NS_ROSTER, "query", &cb_roster}, |
|
55 |
{NS_VERSION,"query", &cb_version}, |
|
56 |
{NS_TIME, "query", &cb_time}, |
|
57 |
{NS_LAST, "query", &cb_last}, |
|
58 |
{NS_VCARD, "vCard", &cb_vcard}, |
|
59 |
{NULL, NULL, NULL} |
|
60 |
}; |
|
1254
401639413340
More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents:
1224
diff
changeset
|
61 |
|
1006 | 62 |
// Enum for vCard attributes |
63 |
enum vcard_attr { |
|
64 |
vcard_home = 1<<0, |
|
65 |
vcard_work = 1<<1, |
|
66 |
vcard_postal = 1<<2, |
|
67 |
vcard_voice = 1<<3, |
|
68 |
vcard_fax = 1<<4, |
|
69 |
vcard_cell = 1<<5, |
|
70 |
vcard_inet = 1<<6, |
|
71 |
vcard_pref = 1<<7, |
|
72 |
}; |
|
683 | 73 |
|
1598 | 74 |
// xmlns has to be a namespace from iq_request_handlers[].xmlns |
75 |
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
|
76 |
{ |
1598 | 77 |
LmMessage *iq; |
78 |
LmMessageNode *query; |
|
79 |
LmMessageHandler *handler; |
|
80 |
int i; |
|
683 | 81 |
|
1598 | 82 |
iq = lm_message_new_with_sub_type(fulljid, LM_MESSAGE_TYPE_IQ, |
83 |
LM_MESSAGE_SUB_TYPE_GET); |
|
84 |
for (i = 0; strcmp(iq_request_handlers[i].xmlns, xmlns) != 0 ; ++i) |
|
85 |
; |
|
86 |
query = lm_message_node_add_child(iq->node, |
|
87 |
iq_request_handlers[i].querytag, |
|
88 |
NULL); |
|
89 |
lm_message_node_set_attribute(query, "xmlns", xmlns); |
|
90 |
handler = lm_message_handler_new(iq_request_handlers[i].handler, |
|
91 |
NULL, FALSE); |
|
92 |
lm_connection_send_with_reply(lconnection, iq, handler, NULL); |
|
93 |
lm_message_handler_unref(handler); |
|
94 |
lm_message_unref(iq); |
|
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
95 |
} |
29 | 96 |
|
1353
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
97 |
// 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
|
98 |
// after the connection. |
1598 | 99 |
static LmHandlerResult cb_roster(LmMessageHandler *h, LmConnection *c, |
100 |
LmMessage *m, gpointer user_data) |
|
1353
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
101 |
{ |
1598 | 102 |
LmMessageNode *x; |
103 |
const char *ns; |
|
1353
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
104 |
|
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
105 |
// Only execute the hook if the roster has been successfully retrieved |
1598 | 106 |
if (lm_message_get_sub_type(m) != LM_MESSAGE_SUB_TYPE_RESULT) |
107 |
return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; |
|
1353
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
108 |
|
1598 | 109 |
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
|
110 |
if (!x) |
1598 | 111 |
return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; |
1365 | 112 |
|
1598 | 113 |
ns = lm_message_node_get_attribute(x, "xmlns"); |
1365 | 114 |
if (ns && !strcmp(ns, NS_ROSTER)) |
1598 | 115 |
handle_iq_roster(NULL, c, m, user_data); |
1353
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
116 |
|
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
117 |
// Post-login stuff |
1683
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
118 |
hk_postconnect(); |
1353
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
119 |
|
1598 | 120 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
1353
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
121 |
} |
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
122 |
|
1598 | 123 |
static LmHandlerResult cb_version(LmMessageHandler *h, LmConnection *c, |
124 |
LmMessage *m, gpointer user_data) |
|
1353
7caedca15e50
Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1348
diff
changeset
|
125 |
{ |
1598 | 126 |
LmMessageNode *ansqry; |
127 |
const char *p, *bjid; |
|
128 |
char *tmp; |
|
704
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
129 |
char *buf; |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
130 |
|
1598 | 131 |
ansqry = lm_message_node_get_child(m->node, "query"); |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
132 |
if (!ansqry) { |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
133 |
scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:version result!"); |
1598 | 134 |
return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
135 |
} |
1598 | 136 |
|
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
137 |
// Display IQ result sender... |
1598 | 138 |
p = lm_message_get_from(m); |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
139 |
if (!p) { |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
140 |
scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:version result (no sender name)."); |
1598 | 141 |
return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
142 |
} |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
746
diff
changeset
|
143 |
bjid = p; |
704
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
144 |
|
782
19121d9f4aa2
Nicer message when receiving IQ result packet
Mikael Berthe <mikael@lilotux.net>
parents:
776
diff
changeset
|
145 |
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
|
146 |
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
|
147 |
|
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
148 |
// bjid should now really be the "bare JID", let's strip the resource |
1598 | 149 |
tmp = strchr(bjid, JID_RESOURCE_SEPARATOR); |
150 |
if (tmp) *tmp = '\0'; |
|
704
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
151 |
|
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1283
diff
changeset
|
152 |
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
|
153 |
g_free(buf); |
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
154 |
|
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
155 |
// Get result data... |
1598 | 156 |
p = lm_message_node_get_child_value(ansqry, "name"); |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
157 |
if (p) { |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
158 |
buf = g_strdup_printf("Name: %s", p); |
1333
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
159 |
scr_WriteIncomingMessage(bjid, buf, |
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
160 |
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
|
161 |
g_free(buf); |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
162 |
} |
1598 | 163 |
p = lm_message_node_get_child_value(ansqry, "version"); |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
164 |
if (p) { |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
165 |
buf = g_strdup_printf("Version: %s", p); |
1333
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
166 |
scr_WriteIncomingMessage(bjid, buf, |
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
167 |
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
|
168 |
g_free(buf); |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
169 |
} |
1598 | 170 |
p = lm_message_node_get_child_value(ansqry, "os"); |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
171 |
if (p) { |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
172 |
buf = g_strdup_printf("OS: %s", p); |
1333
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
173 |
scr_WriteIncomingMessage(bjid, buf, |
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
174 |
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
|
175 |
g_free(buf); |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
176 |
} |
1598 | 177 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
178 |
} |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
179 |
|
1598 | 180 |
static LmHandlerResult cb_time(LmMessageHandler *h, LmConnection *c, |
181 |
LmMessage *m, gpointer user_data) |
|
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
182 |
{ |
1598 | 183 |
LmMessageNode *ansqry; |
184 |
const char *p, *bjid; |
|
185 |
char *tmp; |
|
704
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
186 |
char *buf; |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
187 |
|
1598 | 188 |
ansqry = lm_message_node_get_child(m->node, "query"); |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
189 |
if (!ansqry) { |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
190 |
scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:time result!"); |
1598 | 191 |
return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
192 |
} |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
193 |
// Display IQ result sender... |
1598 | 194 |
p = lm_message_get_from(m); |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
195 |
if (!p) { |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
196 |
scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:time result (no sender name)."); |
1598 | 197 |
return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
198 |
} |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
746
diff
changeset
|
199 |
bjid = p; |
704
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
200 |
|
782
19121d9f4aa2
Nicer message when receiving IQ result packet
Mikael Berthe <mikael@lilotux.net>
parents:
776
diff
changeset
|
201 |
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
|
202 |
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
|
203 |
|
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
204 |
// bjid should now really be the "bare JID", let's strip the resource |
1598 | 205 |
tmp = strchr(bjid, JID_RESOURCE_SEPARATOR); |
206 |
if (tmp) *tmp = '\0'; |
|
704
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
207 |
|
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1283
diff
changeset
|
208 |
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
|
209 |
g_free(buf); |
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
210 |
|
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
211 |
// Get result data... |
1598 | 212 |
p = lm_message_node_get_child_value(ansqry, "utc"); |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
213 |
if (p) { |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
214 |
buf = g_strdup_printf("UTC: %s", p); |
1333
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
215 |
scr_WriteIncomingMessage(bjid, buf, |
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
216 |
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
|
217 |
g_free(buf); |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
218 |
} |
1598 | 219 |
p = lm_message_node_get_child_value(ansqry, "tz"); |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
220 |
if (p) { |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
221 |
buf = g_strdup_printf("TZ: %s", p); |
1333
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
222 |
scr_WriteIncomingMessage(bjid, buf, |
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
223 |
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
|
224 |
g_free(buf); |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
225 |
} |
1598 | 226 |
p = lm_message_node_get_child_value(ansqry, "display"); |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
227 |
if (p) { |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
228 |
buf = g_strdup_printf("Time: %s", p); |
1333
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
229 |
scr_WriteIncomingMessage(bjid, buf, |
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
230 |
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
|
231 |
g_free(buf); |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
232 |
} |
1598 | 233 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
234 |
} |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
235 |
|
1598 | 236 |
static LmHandlerResult cb_last(LmMessageHandler *h, LmConnection *c, |
237 |
LmMessage *m, gpointer user_data) |
|
1015 | 238 |
{ |
1598 | 239 |
LmMessageNode *ansqry; |
240 |
const char *p, *bjid; |
|
241 |
char *buf, *tmp; |
|
1015 | 242 |
|
1598 | 243 |
ansqry = lm_message_node_get_child(m->node, "query"); |
1015 | 244 |
if (!ansqry) { |
245 |
scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:last result!"); |
|
1598 | 246 |
return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; |
1015 | 247 |
} |
248 |
// Display IQ result sender... |
|
1598 | 249 |
p = lm_message_get_from(m); |
1015 | 250 |
if (!p) { |
251 |
scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:last result (no sender name)."); |
|
1598 | 252 |
return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; |
1015 | 253 |
} |
254 |
bjid = p; |
|
255 |
||
256 |
buf = g_strdup_printf("Received IQ:last result from <%s>", bjid); |
|
257 |
scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
|
258 |
||
259 |
// bjid should now really be the "bare JID", let's strip the resource |
|
1598 | 260 |
tmp = strchr(bjid, JID_RESOURCE_SEPARATOR); |
261 |
if (tmp) *tmp = '\0'; |
|
1015 | 262 |
|
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1283
diff
changeset
|
263 |
scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0); |
1015 | 264 |
g_free(buf); |
265 |
||
266 |
// Get result data... |
|
1598 | 267 |
p = lm_message_node_get_attribute(ansqry, "seconds"); |
1015 | 268 |
if (p) { |
269 |
long int s; |
|
270 |
GString *sbuf; |
|
271 |
sbuf = g_string_new("Idle time: "); |
|
272 |
s = atol(p); |
|
273 |
// Days |
|
274 |
if (s > 86400L) { |
|
275 |
g_string_append_printf(sbuf, "%ldd ", s/86400L); |
|
276 |
s %= 86400L; |
|
277 |
} |
|
278 |
// hh:mm:ss |
|
279 |
g_string_append_printf(sbuf, "%02ld:", s/3600L); |
|
280 |
s %= 3600L; |
|
281 |
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
|
282 |
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
|
283 |
0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); |
1015 | 284 |
g_string_free(sbuf, TRUE); |
285 |
} else { |
|
286 |
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
|
287 |
0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); |
1015 | 288 |
} |
1598 | 289 |
p = lm_message_node_get_value(ansqry); |
1015 | 290 |
if (p) { |
291 |
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
|
292 |
scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0); |
1015 | 293 |
g_free(buf); |
294 |
} |
|
1598 | 295 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
1015 | 296 |
} |
297 |
||
1006 | 298 |
static void display_vcard_item(const char *bjid, const char *label, |
299 |
enum vcard_attr vcard_attrib, const char *text) |
|
300 |
{ |
|
301 |
char *buf; |
|
302 |
||
303 |
if (!text || !bjid || !label) |
|
304 |
return; |
|
305 |
||
306 |
buf = g_strdup_printf("%s: %s%s%s%s%s%s%s%s%s%s", label, |
|
307 |
(vcard_attrib & vcard_home ? "[home]" : ""), |
|
308 |
(vcard_attrib & vcard_work ? "[work]" : ""), |
|
309 |
(vcard_attrib & vcard_postal ? "[postal]" : ""), |
|
310 |
(vcard_attrib & vcard_voice ? "[voice]" : ""), |
|
311 |
(vcard_attrib & vcard_fax ? "[fax]" : ""), |
|
312 |
(vcard_attrib & vcard_cell ? "[cell]" : ""), |
|
313 |
(vcard_attrib & vcard_inet ? "[inet]" : ""), |
|
314 |
(vcard_attrib & vcard_pref ? "[pref]" : ""), |
|
315 |
(vcard_attrib ? " " : ""), |
|
316 |
text); |
|
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1283
diff
changeset
|
317 |
scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); |
1006 | 318 |
g_free(buf); |
319 |
} |
|
320 |
||
1598 | 321 |
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
|
322 |
{ |
1598 | 323 |
LmMessageNode *x; |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
324 |
const char *p; |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
325 |
|
1598 | 326 |
for (x = vcardnode->children ; x; x = x->next) { |
1006 | 327 |
const char *data; |
328 |
enum vcard_attr vcard_attrib = 0; |
|
329 |
||
1598 | 330 |
p = x->name; |
331 |
data = lm_message_node_get_value(x); |
|
1006 | 332 |
if (!p || !data) |
333 |
continue; |
|
334 |
||
335 |
if (!strcmp(p, "FN")) |
|
336 |
display_vcard_item(barejid, "Name", vcard_attrib, data); |
|
337 |
else if (!strcmp(p, "NICKNAME")) |
|
338 |
display_vcard_item(barejid, "Nickname", vcard_attrib, data); |
|
339 |
else if (!strcmp(p, "URL")) |
|
340 |
display_vcard_item(barejid, "URL", vcard_attrib, data); |
|
341 |
else if (!strcmp(p, "BDAY")) |
|
342 |
display_vcard_item(barejid, "Birthday", vcard_attrib, data); |
|
343 |
else if (!strcmp(p, "TZ")) |
|
344 |
display_vcard_item(barejid, "Timezone", vcard_attrib, data); |
|
345 |
else if (!strcmp(p, "TITLE")) |
|
346 |
display_vcard_item(barejid, "Title", vcard_attrib, data); |
|
347 |
else if (!strcmp(p, "ROLE")) |
|
348 |
display_vcard_item(barejid, "Role", vcard_attrib, data); |
|
349 |
else if (!strcmp(p, "DESC")) |
|
350 |
display_vcard_item(barejid, "Comment", vcard_attrib, data); |
|
351 |
else if (!strcmp(p, "N")) { |
|
1598 | 352 |
data = lm_message_node_get_child_value(x, "FAMILY"); |
1006 | 353 |
display_vcard_item(barejid, "Family Name", vcard_attrib, data); |
1598 | 354 |
data = lm_message_node_get_child_value(x, "GIVEN"); |
1006 | 355 |
display_vcard_item(barejid, "Given Name", vcard_attrib, data); |
1598 | 356 |
data = lm_message_node_get_child_value(x, "MIDDLE"); |
1006 | 357 |
display_vcard_item(barejid, "Middle Name", vcard_attrib, data); |
358 |
} else if (!strcmp(p, "ORG")) { |
|
1598 | 359 |
data = lm_message_node_get_child_value(x, "ORGNAME"); |
1006 | 360 |
display_vcard_item(barejid, "Organisation name", vcard_attrib, data); |
1598 | 361 |
data = lm_message_node_get_child_value(x, "ORGUNIT"); |
1006 | 362 |
display_vcard_item(barejid, "Organisation unit", vcard_attrib, data); |
363 |
} else { |
|
364 |
// The HOME, WORK and PREF attributes are common to the remaining fields |
|
365 |
// (ADR, TEL & EMAIL) |
|
1598 | 366 |
if (lm_message_node_get_child(x, "HOME")) |
1006 | 367 |
vcard_attrib |= vcard_home; |
1598 | 368 |
if (lm_message_node_get_child(x, "WORK")) |
1006 | 369 |
vcard_attrib |= vcard_work; |
1598 | 370 |
if (lm_message_node_get_child(x, "PREF")) |
1006 | 371 |
vcard_attrib |= vcard_pref; |
372 |
if (!strcmp(p, "ADR")) { // Address |
|
1598 | 373 |
if (lm_message_node_get_child(x, "POSTAL")) |
1006 | 374 |
vcard_attrib |= vcard_postal; |
1598 | 375 |
data = lm_message_node_get_child_value(x, "EXTADD"); |
1006 | 376 |
display_vcard_item(barejid, "Addr (ext)", vcard_attrib, data); |
1598 | 377 |
data = lm_message_node_get_child_value(x, "STREET"); |
1006 | 378 |
display_vcard_item(barejid, "Street", vcard_attrib, data); |
1598 | 379 |
data = lm_message_node_get_child_value(x, "LOCALITY"); |
1006 | 380 |
display_vcard_item(barejid, "Locality", vcard_attrib, data); |
1598 | 381 |
data = lm_message_node_get_child_value(x, "REGION"); |
1006 | 382 |
display_vcard_item(barejid, "Region", vcard_attrib, data); |
1598 | 383 |
data = lm_message_node_get_child_value(x, "PCODE"); |
1006 | 384 |
display_vcard_item(barejid, "Postal code", vcard_attrib, data); |
1598 | 385 |
data = lm_message_node_get_child_value(x, "CTRY"); |
1006 | 386 |
display_vcard_item(barejid, "Country", vcard_attrib, data); |
387 |
} else if (!strcmp(p, "TEL")) { // Telephone |
|
1598 | 388 |
data = lm_message_node_get_child_value(x, "NUMBER"); |
1005 | 389 |
if (data) { |
1598 | 390 |
if (lm_message_node_get_child(x, "VOICE")) |
1006 | 391 |
vcard_attrib |= vcard_voice; |
1598 | 392 |
if (lm_message_node_get_child(x, "FAX")) |
1006 | 393 |
vcard_attrib |= vcard_fax; |
1598 | 394 |
if (lm_message_node_get_child(x, "CELL")) |
1006 | 395 |
vcard_attrib |= vcard_cell; |
396 |
display_vcard_item(barejid, "Phone", vcard_attrib, data); |
|
1005 | 397 |
} |
1006 | 398 |
} else if (!strcmp(p, "EMAIL")) { // Email |
1598 | 399 |
if (lm_message_node_get_child(x, "INTERNET")) |
1006 | 400 |
vcard_attrib |= vcard_inet; |
1598 | 401 |
data = lm_message_node_get_child_value(x, "USERID"); |
1006 | 402 |
display_vcard_item(barejid, "Email", vcard_attrib, data); |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
403 |
} |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
404 |
} |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
405 |
} |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
406 |
} |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
407 |
|
1598 | 408 |
static LmHandlerResult cb_vcard(LmMessageHandler *h, LmConnection *c, |
409 |
LmMessage *m, gpointer user_data) |
|
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
410 |
{ |
1598 | 411 |
LmMessageNode *ansqry; |
412 |
const char *p, *bjid; |
|
413 |
char *buf, *tmp; |
|
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
414 |
|
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
415 |
// Display IQ result sender... |
1598 | 416 |
p = lm_message_get_from(m); |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
417 |
if (!p) { |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
418 |
scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:vCard result (no sender name)."); |
1598 | 419 |
return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
420 |
} |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
421 |
bjid = p; |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
422 |
|
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
423 |
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
|
424 |
scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
425 |
|
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
426 |
// Get the vCard node |
1598 | 427 |
ansqry = lm_message_node_get_child(m->node, "vCard"); |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
428 |
if (!ansqry) { |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
429 |
scr_LogPrint(LPRINT_LOGNORM, "Empty IQ:vCard result!"); |
1340
2031f4b2cced
Fix a small memory leak
Mikael Berthe <mikael@lilotux.net>
parents:
1334
diff
changeset
|
430 |
g_free(buf); |
1598 | 431 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
432 |
} |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
433 |
|
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
434 |
// bjid should really be the "bare JID", let's strip the resource |
1598 | 435 |
tmp = strchr(bjid, JID_RESOURCE_SEPARATOR); |
436 |
if (tmp) *tmp = '\0'; |
|
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
437 |
|
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1283
diff
changeset
|
438 |
scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0); |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
439 |
g_free(buf); |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
440 |
|
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
441 |
// Get result data... |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
442 |
handle_vcard_node(bjid, ansqry); |
1598 | 443 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
444 |
} |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
445 |
|
1598 | 446 |
static void storage_bookmarks_parse_conference(LmMessageNode *node) |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
447 |
{ |
1058 | 448 |
const char *fjid, *name, *autojoin; |
1379
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
449 |
const char *pstatus, *awhois; |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
450 |
char *bjid; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
451 |
GSList *room_elt; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
452 |
|
1598 | 453 |
fjid = lm_message_node_get_attribute(node, "jid"); |
1058 | 454 |
if (!fjid) |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
455 |
return; |
1598 | 456 |
name = lm_message_node_get_attribute(node, "name"); |
457 |
autojoin = lm_message_node_get_attribute(node, "autojoin"); |
|
458 |
awhois = lm_message_node_get_attribute(node, "autowhois"); |
|
459 |
pstatus = lm_message_node_get_child_value(node, "print_status"); |
|
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
460 |
|
1058 | 461 |
bjid = jidtodisp(fjid); // Bare jid |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
462 |
|
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
463 |
// 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
|
464 |
room_elt = roster_find(bjid, jidsearch, 0); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
465 |
if (!room_elt) { |
1355 | 466 |
room_elt = roster_add_user(bjid, name, NULL, ROSTER_TYPE_ROOM, |
467 |
sub_none, -1); |
|
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
468 |
} else { |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
469 |
buddy_settype(room_elt->data, ROSTER_TYPE_ROOM); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
470 |
/* |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
471 |
// If the name is available, should we use it? |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
472 |
// 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
|
473 |
// in the roster. |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
474 |
if (name) |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
475 |
buddy_setname(room_elt->data, name); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
476 |
*/ |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
477 |
} |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
478 |
|
1379
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
479 |
// 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
|
480 |
if (pstatus) { |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
481 |
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
|
482 |
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
|
483 |
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
|
484 |
break; |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
485 |
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
|
486 |
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
|
487 |
} |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
488 |
if (awhois) { |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
489 |
enum room_autowhois i = autowhois_default; |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
490 |
if (!strcmp(awhois, "1")) |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
491 |
i = autowhois_on; |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
492 |
else if (!strcmp(awhois, "0")) |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
493 |
i = autowhois_off; |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
494 |
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
|
495 |
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
|
496 |
} |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
497 |
|
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
498 |
// Is autojoin set? |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
499 |
// 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
|
500 |
// try to join the room. |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
501 |
if (autojoin && !strcmp(autojoin, "1")) { |
1598 | 502 |
const char *nick, *passwd; |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
503 |
char *tmpnick = NULL; |
1598 | 504 |
nick = lm_message_node_get_child_value(node, "nick"); |
505 |
passwd = lm_message_node_get_child_value(node, "password"); |
|
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
506 |
if (!nick || !*nick) |
1395
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1393
diff
changeset
|
507 |
nick = tmpnick = default_muc_nickname(NULL); |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
508 |
// Let's join now |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
509 |
scr_LogPrint(LPRINT_LOGNORM, "Auto-join bookmark <%s>", bjid); |
1598 | 510 |
xmpp_room_join(bjid, nick, passwd); |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
511 |
g_free(tmpnick); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
512 |
} |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
513 |
g_free(bjid); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
514 |
} |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
515 |
|
1598 | 516 |
static LmHandlerResult cb_storage_bookmarks(LmMessageHandler *h, |
517 |
LmConnection *c, |
|
518 |
LmMessage *m, gpointer user_data) |
|
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
519 |
{ |
1598 | 520 |
LmMessageNode *x, *ansqry; |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
521 |
char *p; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
522 |
|
1598 | 523 |
if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_ERROR) { |
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
524 |
// No server support, or no bookmarks? |
1598 | 525 |
p = m->node->children->name; |
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
526 |
if (p && !strcmp(p, "item-not-found")) { |
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
527 |
// 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
|
528 |
// currently empty. |
1598 | 529 |
if (bookmarks) |
530 |
lm_message_node_unref(bookmarks); |
|
531 |
bookmarks = lm_message_node_new("storage", "storage:bookmarks"); |
|
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
532 |
// We return 0 so that the IQ error message be |
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
533 |
// not displayed, as it isn't a real error. |
1598 | 534 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
535 |
} |
1598 | 536 |
return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; // Unhandled error |
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
537 |
} |
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
538 |
|
1598 | 539 |
ansqry = lm_message_node_get_child(m->node, "query"); |
540 |
ansqry = lm_message_node_get_child(ansqry, "storage"); |
|
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
541 |
if (!ansqry) { |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
542 |
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
|
543 |
return 0; |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
544 |
} |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
545 |
|
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
546 |
// Walk through the storage tags |
1598 | 547 |
for (x = ansqry->children ; x; x = x->next) { |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
548 |
// If the current node is a conference item, parse it and update the roster |
1598 | 549 |
if (x->name && !strcmp(x->name, "conference")) |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
550 |
storage_bookmarks_parse_conference(x); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
551 |
} |
1598 | 552 |
// "Copy" the bookmarks node |
553 |
if (bookmarks) |
|
554 |
lm_message_node_unref(bookmarks); |
|
555 |
lm_message_node_deep_ref(ansqry); |
|
556 |
bookmarks = ansqry; |
|
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
557 |
return 0; |
686
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
685
diff
changeset
|
558 |
} |
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
685
diff
changeset
|
559 |
|
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
560 |
|
1598 | 561 |
static LmHandlerResult cb_storage_rosternotes(LmMessageHandler *h, |
562 |
LmConnection *c, |
|
563 |
LmMessage *m, gpointer user_data) |
|
1261
704adf4df2d0
Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents:
1255
diff
changeset
|
564 |
{ |
1598 | 565 |
LmMessageNode *ansqry; |
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
566 |
|
1598 | 567 |
if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_ERROR) { |
568 |
const char *p; |
|
569 |
// No server support, or no roster notes? |
|
570 |
p = m->node->children->name; |
|
571 |
if (p && !strcmp(p, "item-not-found")) { |
|
572 |
// item-no-found means the server has Private Storage, but it's |
|
573 |
// currently empty. |
|
574 |
if (rosternotes) |
|
575 |
lm_message_node_unref(rosternotes); |
|
576 |
rosternotes = lm_message_node_new("storage", "storage:rosternotes"); |
|
577 |
// We return 0 so that the IQ error message be |
|
578 |
// not displayed, as it isn't a real error. |
|
579 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
|
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
580 |
} |
1598 | 581 |
return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; // Unhandled error |
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
582 |
} |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
583 |
|
1598 | 584 |
ansqry = lm_message_node_get_child(m->node, "query"); |
585 |
ansqry = lm_message_node_get_child(ansqry, "storage"); |
|
586 |
if (!ansqry) { |
|
587 |
scr_LogPrint(LPRINT_LOG, "Invalid IQ:private result! " |
|
588 |
"(storage:rosternotes)"); |
|
589 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
|
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
590 |
} |
1598 | 591 |
// Copy the rosternotes node |
592 |
if (rosternotes) |
|
593 |
lm_message_node_unref(rosternotes); |
|
594 |
lm_message_node_deep_ref(ansqry); |
|
595 |
rosternotes = ansqry; |
|
596 |
return 0; |
|
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
597 |
} |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
598 |
|
995
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
599 |
|
1598 | 600 |
static struct IqRequestStorageHandlers |
1254
401639413340
More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents:
1224
diff
changeset
|
601 |
{ |
1598 | 602 |
const gchar *storagens; |
603 |
LmHandleMessageFunction handler; |
|
604 |
} iq_request_storage_handlers[] = { |
|
605 |
{"storage:rosternotes", &cb_storage_rosternotes}, |
|
606 |
{"storage:bookmarks", &cb_storage_bookmarks}, |
|
607 |
{NULL, NULL} |
|
608 |
}; |
|
619
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
609 |
|
1598 | 610 |
void xmpp_request_storage(const gchar *storage) |
619
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
611 |
{ |
1598 | 612 |
LmMessage *iq; |
613 |
LmMessageNode *query; |
|
614 |
LmMessageHandler *handler; |
|
615 |
int i; |
|
703
8cbcbff8de7d
Fix UTC time in IQ:version queries
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
616 |
|
1598 | 617 |
iq = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_IQ, |
618 |
LM_MESSAGE_SUB_TYPE_GET); |
|
619 |
query = lm_message_node_add_child(iq->node, "query", NULL); |
|
620 |
lm_message_node_set_attribute(query, "xmlns", NS_PRIVATE); |
|
621 |
lm_message_node_set_attribute(lm_message_node_add_child |
|
622 |
(query, "storage", NULL), |
|
623 |
"xmlns", storage); |
|
1283
2faf179166f3
Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents:
1268
diff
changeset
|
624 |
|
1598 | 625 |
for (i = 0; |
626 |
strcmp(iq_request_storage_handlers[i].storagens, storage) != 0; |
|
627 |
++i) ; |
|
595
0c1d37300862
IQ: send feature-not-implemented error stanzas
Mikael Berthe <mikael@lilotux.net>
parents:
582
diff
changeset
|
628 |
|
1598 | 629 |
handler = lm_message_handler_new(iq_request_storage_handlers[i].handler, |
630 |
NULL, FALSE); |
|
631 |
lm_connection_send_with_reply(lconnection, iq, handler, NULL); |
|
632 |
lm_message_handler_unref(handler); |
|
633 |
lm_message_unref(iq); |
|
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
634 |
} |
1599 | 635 |
|
636 |
/* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |