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