comparison mcabber/src/jab_iq.c @ 704:4118a66f2c02

Display IQ results (time, version) in the chat window
author Mikael Berthe <mikael@lilotux.net>
date Sat, 18 Feb 2006 12:05:46 +0100
parents 8cbcbff8de7d
children 603b43e4f56a
comparison
equal deleted inserted replaced
703:8cbcbff8de7d 704:4118a66f2c02
29 #include "jab_priv.h" 29 #include "jab_priv.h"
30 #include "roster.h" 30 #include "roster.h"
31 #include "utils.h" 31 #include "utils.h"
32 #include "screen.h" 32 #include "screen.h"
33 #include "settings.h" 33 #include "settings.h"
34 #include "hbuf.h"
34 35
35 36
36 static GSList *iqs_list; 37 static GSList *iqs_list;
37 38
38 39
243 244
244 void iqscallback_version(iqs *iqp, xmlnode xml_result, guint iqcontext) 245 void iqscallback_version(iqs *iqp, xmlnode xml_result, guint iqcontext)
245 { 246 {
246 xmlnode ansqry; 247 xmlnode ansqry;
247 char *p, *p_noutf8; 248 char *p, *p_noutf8;
249 char *bjid;
250 char *buf;
248 251
249 // Leave now if we cannot process xml_result 252 // Leave now if we cannot process xml_result
250 if (!xml_result || iqcontext) return; 253 if (!xml_result || iqcontext) return;
251 254
252 ansqry = xmlnode_get_tag(xml_result, "query"); 255 ansqry = xmlnode_get_tag(xml_result, "query");
258 p = xmlnode_get_attrib(xml_result, "from"); 261 p = xmlnode_get_attrib(xml_result, "from");
259 if (!p) { 262 if (!p) {
260 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:version result (no sender name)."); 263 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:version result (no sender name).");
261 return; 264 return;
262 } 265 }
263 p_noutf8 = from_utf8(p); 266 bjid = from_utf8(p);
264 if (p_noutf8) { 267 if (!bjid) {
265 scr_LogPrint(LPRINT_LOGNORM, "IQ:version from <%s>", p_noutf8); 268 scr_LogPrint(LPRINT_LOGNORM, "UTF-8 decoding error in IQ:version result "
266 g_free(p_noutf8); 269 "(sender name).");
267 } 270 return;
271 }
272
273 buf = g_strdup_printf("IQ:version result from <%s>", bjid);
274 scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
275
276 // bjid should now really be the "bare JID", let's strip the resource
277 p = strchr(bjid, '/');
278 if (p) *p = '\0';
279
280 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO);
281 g_free(buf);
282
268 // Get result data... 283 // Get result data...
269 p = xmlnode_get_tag_data(ansqry, "name"); 284 p = xmlnode_get_tag_data(ansqry, "name");
270 if (p) { 285 if (p) {
271 p_noutf8 = from_utf8(p); 286 p_noutf8 = from_utf8(p);
272 if (p_noutf8) { 287 if (p_noutf8) {
273 scr_LogPrint(LPRINT_LOGNORM, "Name: %s", p_noutf8); 288 buf = g_strdup_printf("Name: %s", p_noutf8);
289 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO);
274 g_free(p_noutf8); 290 g_free(p_noutf8);
291 g_free(buf);
275 } 292 }
276 } 293 }
277 p = xmlnode_get_tag_data(ansqry, "version"); 294 p = xmlnode_get_tag_data(ansqry, "version");
278 if (p) { 295 if (p) {
279 p_noutf8 = from_utf8(p); 296 p_noutf8 = from_utf8(p);
280 if (p_noutf8) { 297 if (p_noutf8) {
281 scr_LogPrint(LPRINT_LOGNORM, "Version: %s", p_noutf8); 298 buf = g_strdup_printf("Version: %s", p_noutf8);
299 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO);
282 g_free(p_noutf8); 300 g_free(p_noutf8);
301 g_free(buf);
283 } 302 }
284 } 303 }
285 p = xmlnode_get_tag_data(ansqry, "os"); 304 p = xmlnode_get_tag_data(ansqry, "os");
286 if (p) { 305 if (p) {
287 p_noutf8 = from_utf8(p); 306 p_noutf8 = from_utf8(p);
288 if (p_noutf8) { 307 if (p_noutf8) {
289 scr_LogPrint(LPRINT_LOGNORM, "OS: %s", p_noutf8); 308 buf = g_strdup_printf("OS: %s", p_noutf8);
309 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO);
290 g_free(p_noutf8); 310 g_free(p_noutf8);
291 } 311 g_free(buf);
292 } 312 }
313 }
314 g_free(bjid);
293 } 315 }
294 316
295 void request_version(const char *fulljid) 317 void request_version(const char *fulljid)
296 { 318 {
297 iqs *iqn; 319 iqs *iqn;
306 328
307 void iqscallback_time(iqs *iqp, xmlnode xml_result, guint iqcontext) 329 void iqscallback_time(iqs *iqp, xmlnode xml_result, guint iqcontext)
308 { 330 {
309 xmlnode ansqry; 331 xmlnode ansqry;
310 char *p, *p_noutf8; 332 char *p, *p_noutf8;
333 char *bjid;
334 char *buf;
311 335
312 // Leave now if we cannot process xml_result 336 // Leave now if we cannot process xml_result
313 if (!xml_result || iqcontext) return; 337 if (!xml_result || iqcontext) return;
314 338
315 ansqry = xmlnode_get_tag(xml_result, "query"); 339 ansqry = xmlnode_get_tag(xml_result, "query");
321 p = xmlnode_get_attrib(xml_result, "from"); 345 p = xmlnode_get_attrib(xml_result, "from");
322 if (!p) { 346 if (!p) {
323 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:time result (no sender name)."); 347 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:time result (no sender name).");
324 return; 348 return;
325 } 349 }
326 p_noutf8 = from_utf8(p); 350 bjid = from_utf8(p);
327 if (p_noutf8) { 351 if (!bjid) {
328 scr_LogPrint(LPRINT_LOGNORM, "IQ:time from <%s>", p_noutf8); 352 scr_LogPrint(LPRINT_LOGNORM, "UTF-8 decoding error in IQ:time result "
329 g_free(p_noutf8); 353 "(sender name).");
330 } 354 return;
355 }
356
357 buf = g_strdup_printf("IQ:time result from <%s>", bjid);
358 scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
359
360 // bjid should now really be the "bare JID", let's strip the resource
361 p = strchr(bjid, '/');
362 if (p) *p = '\0';
363
364 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO);
365 g_free(buf);
366
331 // Get result data... 367 // Get result data...
332 p = xmlnode_get_tag_data(ansqry, "utc"); 368 p = xmlnode_get_tag_data(ansqry, "utc");
333 if (p) { 369 if (p) {
334 p_noutf8 = from_utf8(p); 370 p_noutf8 = from_utf8(p);
335 if (p_noutf8) { 371 if (p_noutf8) {
336 scr_LogPrint(LPRINT_LOGNORM, "UTC: %s", p_noutf8); 372 buf = g_strdup_printf("UTC: %s", p_noutf8);
373 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO);
337 g_free(p_noutf8); 374 g_free(p_noutf8);
375 g_free(buf);
338 } 376 }
339 } 377 }
340 p = xmlnode_get_tag_data(ansqry, "tz"); 378 p = xmlnode_get_tag_data(ansqry, "tz");
341 if (p) { 379 if (p) {
342 p_noutf8 = from_utf8(p); 380 p_noutf8 = from_utf8(p);
343 if (p_noutf8) { 381 if (p_noutf8) {
344 scr_LogPrint(LPRINT_LOGNORM, "TZ: %s", p_noutf8); 382 buf = g_strdup_printf("TZ: %s", p_noutf8);
383 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO);
345 g_free(p_noutf8); 384 g_free(p_noutf8);
385 g_free(buf);
346 } 386 }
347 } 387 }
348 p = xmlnode_get_tag_data(ansqry, "display"); 388 p = xmlnode_get_tag_data(ansqry, "display");
349 if (p) { 389 if (p) {
350 p_noutf8 = from_utf8(p); 390 p_noutf8 = from_utf8(p);
351 if (p_noutf8) { 391 if (p_noutf8) {
352 scr_LogPrint(LPRINT_LOGNORM, "Time: %s", p_noutf8); 392 buf = g_strdup_printf("Time: %s", p_noutf8);
393 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO);
353 g_free(p_noutf8); 394 g_free(p_noutf8);
354 } 395 g_free(buf);
355 } 396 }
397 }
398 g_free(bjid);
356 } 399 }
357 400
358 void request_time(const char *fulljid) 401 void request_time(const char *fulljid)
359 { 402 {
360 iqs *iqn; 403 iqs *iqn;