Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/jab_iq.c @ 745:413e95f3051a
Introduce user "events" list
Not used yet.
The events list (evs_list) will be used to queue events for user approval,
for example subscription requests, file tranfers, etc.
The evs stuff is actually almost the same as the iqs stuff, a lot of code
is duplicated... :-\
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Mon, 13 Mar 2006 17:28:24 +0100 |
parents | 603b43e4f56a |
children | 3a76c2d73606 |
comparison
equal
deleted
inserted
replaced
744:c3b76a1a07cb | 745:413e95f3051a |
---|---|
38 | 38 |
39 | 39 |
40 // iqs_new(type, namespace, prefix, timeout) | 40 // iqs_new(type, namespace, prefix, timeout) |
41 // Create a query (GET, SET) IQ structure. This function should not be used | 41 // Create a query (GET, SET) IQ structure. This function should not be used |
42 // for RESULT packets. | 42 // for RESULT packets. |
43 iqs *iqs_new(guint8 type, const char *ns, const char *prefix, time_t timeout) | 43 eviqs *iqs_new(guint8 type, const char *ns, const char *prefix, time_t timeout) |
44 { | 44 { |
45 static guint iqs_idn; | 45 static guint iqs_idn; |
46 iqs *new_iqs; | 46 eviqs *new_iqs; |
47 time_t now_t; | 47 time_t now_t; |
48 | 48 |
49 iqs_idn++; | 49 iqs_idn++; |
50 | 50 |
51 new_iqs = g_new0(iqs, 1); | 51 new_iqs = g_new0(eviqs, 1); |
52 time(&now_t); | 52 time(&now_t); |
53 new_iqs->ts_create = now_t; | 53 new_iqs->ts_create = now_t; |
54 if (timeout) | 54 if (timeout) |
55 new_iqs->ts_expire = now_t + timeout; | 55 new_iqs->ts_expire = now_t + timeout; |
56 new_iqs->type = type; | 56 new_iqs->type = type; |
66 } | 66 } |
67 | 67 |
68 int iqs_del(const char *iqid) | 68 int iqs_del(const char *iqid) |
69 { | 69 { |
70 GSList *p; | 70 GSList *p; |
71 iqs *i; | 71 eviqs *i; |
72 | 72 |
73 if (!iqid) return 1; | 73 if (!iqid) return 1; |
74 | 74 |
75 for (p = iqs_list; p; p = g_slist_next(p)) { | 75 for (p = iqs_list; p; p = g_slist_next(p)) { |
76 i = p->data; | 76 i = p->data; |
86 return 0; // Ok, deleted | 86 return 0; // Ok, deleted |
87 } | 87 } |
88 return -1; // Not found | 88 return -1; // Not found |
89 } | 89 } |
90 | 90 |
91 static iqs *iqs_find(const char *iqid) | 91 static eviqs *iqs_find(const char *iqid) |
92 { | 92 { |
93 GSList *p; | 93 GSList *p; |
94 iqs *i; | 94 eviqs *i; |
95 | 95 |
96 if (!iqid) return NULL; | 96 if (!iqid) return NULL; |
97 | 97 |
98 for (p = iqs_list; p; p = g_slist_next(p)) { | 98 for (p = iqs_list; p; p = g_slist_next(p)) { |
99 i = p->data; | 99 i = p->data; |
108 // If we've received an answer, xml_result should point to the xmldata packet. | 108 // If we've received an answer, xml_result should point to the xmldata packet. |
109 // If this is a timeout, xml_result should be NULL. | 109 // If this is a timeout, xml_result should be NULL. |
110 // Return 0 in case of success, -1 if the iqid hasn't been found. | 110 // Return 0 in case of success, -1 if the iqid hasn't been found. |
111 int iqs_callback(const char *iqid, xmlnode xml_result, guint iqcontext) | 111 int iqs_callback(const char *iqid, xmlnode xml_result, guint iqcontext) |
112 { | 112 { |
113 iqs *i; | 113 eviqs *i; |
114 | 114 |
115 i = iqs_find(iqid); | 115 i = iqs_find(iqid); |
116 if (!i) return -1; | 116 if (!i) return -1; |
117 | 117 |
118 // IQ processing | 118 // IQ processing |
125 } | 125 } |
126 | 126 |
127 void iqs_check_timeout(time_t now_t) | 127 void iqs_check_timeout(time_t now_t) |
128 { | 128 { |
129 GSList *p; | 129 GSList *p; |
130 iqs *i; | 130 eviqs *i; |
131 | 131 |
132 p = iqs_list; | 132 p = iqs_list; |
133 while (p) { | 133 while (p) { |
134 i = p->data; | 134 i = p->data; |
135 // We must get next iqs element now because the current one | 135 // We must get next IQ eviqs element now because the current one |
136 // could be freed. | 136 // could be freed. |
137 p = g_slist_next(p); | 137 p = g_slist_next(p); |
138 | 138 |
139 if ((!i->ts_expire && now_t > i->ts_create + IQS_MAX_TIMEOUT) || | 139 if ((!i->ts_expire && now_t > i->ts_create + IQS_MAX_TIMEOUT) || |
140 (i->ts_expire && now_t > i->ts_expire)) { | 140 (i->ts_expire && now_t > i->ts_expire)) { |
144 } | 144 } |
145 | 145 |
146 void jb_iqs_display_list(void) | 146 void jb_iqs_display_list(void) |
147 { | 147 { |
148 GSList *p; | 148 GSList *p; |
149 iqs *i; | 149 eviqs *i; |
150 | 150 |
151 scr_LogPrint(LPRINT_LOGNORM, "IQ list:"); | 151 scr_LogPrint(LPRINT_LOGNORM, "IQ list:"); |
152 for (p = iqs_list; p; p = g_slist_next(p)) { | 152 for (p = iqs_list; p; p = g_slist_next(p)) { |
153 i = p->data; | 153 i = p->data; |
154 scr_LogPrint(LPRINT_LOGNORM, "Id [%s]", i->id); | 154 scr_LogPrint(LPRINT_LOGNORM, "Id [%s]", i->id); |
156 scr_LogPrint(LPRINT_LOGNORM, "End of IQ list."); | 156 scr_LogPrint(LPRINT_LOGNORM, "End of IQ list."); |
157 } | 157 } |
158 | 158 |
159 static void request_roster(void) | 159 static void request_roster(void) |
160 { | 160 { |
161 iqs *iqn = iqs_new(JPACKET__GET, NS_ROSTER, "Roster", IQS_DEFAULT_TIMEOUT); | 161 eviqs *iqn = iqs_new(JPACKET__GET, NS_ROSTER, "Roster", IQS_DEFAULT_TIMEOUT); |
162 jab_send(jc, iqn->xmldata); | 162 jab_send(jc, iqn->xmldata); |
163 iqs_del(iqn->id); // XXX | 163 iqs_del(iqn->id); // XXX |
164 } | 164 } |
165 | 165 |
166 static void handle_iq_roster(xmlnode x) | 166 static void handle_iq_roster(xmlnode x) |
242 update_roster = TRUE; | 242 update_roster = TRUE; |
243 if (need_refresh) | 243 if (need_refresh) |
244 scr_ShowBuddyWindow(); | 244 scr_ShowBuddyWindow(); |
245 } | 245 } |
246 | 246 |
247 void iqscallback_version(iqs *iqp, xmlnode xml_result, guint iqcontext) | 247 void iqscallback_version(eviqs *iqp, xmlnode xml_result, guint iqcontext) |
248 { | 248 { |
249 xmlnode ansqry; | 249 xmlnode ansqry; |
250 char *p, *p_noutf8; | 250 char *p, *p_noutf8; |
251 char *bjid; | 251 char *bjid; |
252 char *buf; | 252 char *buf; |
316 g_free(bjid); | 316 g_free(bjid); |
317 } | 317 } |
318 | 318 |
319 void request_version(const char *fulljid) | 319 void request_version(const char *fulljid) |
320 { | 320 { |
321 iqs *iqn; | 321 eviqs *iqn; |
322 gchar *utf8_jid = to_utf8(fulljid); | 322 gchar *utf8_jid = to_utf8(fulljid); |
323 | 323 |
324 iqn = iqs_new(JPACKET__GET, NS_VERSION, "version", IQS_DEFAULT_TIMEOUT); | 324 iqn = iqs_new(JPACKET__GET, NS_VERSION, "version", IQS_DEFAULT_TIMEOUT); |
325 xmlnode_put_attrib(iqn->xmldata, "to", utf8_jid); | 325 xmlnode_put_attrib(iqn->xmldata, "to", utf8_jid); |
326 if (utf8_jid) g_free(utf8_jid); | 326 if (utf8_jid) g_free(utf8_jid); |
327 iqn->callback = &iqscallback_version; | 327 iqn->callback = &iqscallback_version; |
328 jab_send(jc, iqn->xmldata); | 328 jab_send(jc, iqn->xmldata); |
329 } | 329 } |
330 | 330 |
331 void iqscallback_time(iqs *iqp, xmlnode xml_result, guint iqcontext) | 331 void iqscallback_time(eviqs *iqp, xmlnode xml_result, guint iqcontext) |
332 { | 332 { |
333 xmlnode ansqry; | 333 xmlnode ansqry; |
334 char *p, *p_noutf8; | 334 char *p, *p_noutf8; |
335 char *bjid; | 335 char *bjid; |
336 char *buf; | 336 char *buf; |
400 g_free(bjid); | 400 g_free(bjid); |
401 } | 401 } |
402 | 402 |
403 void request_time(const char *fulljid) | 403 void request_time(const char *fulljid) |
404 { | 404 { |
405 iqs *iqn; | 405 eviqs *iqn; |
406 gchar *utf8_jid = to_utf8(fulljid); | 406 gchar *utf8_jid = to_utf8(fulljid); |
407 | 407 |
408 iqn = iqs_new(JPACKET__GET, NS_TIME, "time", IQS_DEFAULT_TIMEOUT); | 408 iqn = iqs_new(JPACKET__GET, NS_TIME, "time", IQS_DEFAULT_TIMEOUT); |
409 xmlnode_put_attrib(iqn->xmldata, "to", utf8_jid); | 409 xmlnode_put_attrib(iqn->xmldata, "to", utf8_jid); |
410 if (utf8_jid) g_free(utf8_jid); | 410 if (utf8_jid) g_free(utf8_jid); |
411 iqn->callback = &iqscallback_time; | 411 iqn->callback = &iqscallback_time; |
412 jab_send(jc, iqn->xmldata); | 412 jab_send(jc, iqn->xmldata); |
413 } | 413 } |
414 | 414 |
415 void iqscallback_auth(iqs *iqp, xmlnode xml_result) | 415 void iqscallback_auth(eviqs *iqp, xmlnode xml_result) |
416 { | 416 { |
417 if (jstate == STATE_GETAUTH) { | 417 if (jstate == STATE_GETAUTH) { |
418 iqs *iqn; | 418 eviqs *iqn; |
419 | 419 |
420 if (xml_result) { | 420 if (xml_result) { |
421 xmlnode x = xmlnode_get_tag(xml_result, "query"); | 421 xmlnode x = xmlnode_get_tag(xml_result, "query"); |
422 if (x && !xmlnode_get_tag(x, "digest")) | 422 if (x && !xmlnode_get_tag(x, "digest")) |
423 jc->sid = 0; | 423 jc->sid = 0; |