Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/jab_iq.c @ 1015:579299b1c9b2
Add /request last
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Mon, 13 Nov 2006 21:58:18 +0100 |
parents | 99c5278bf6b8 |
children | 4d3c48844746 |
comparison
equal
deleted
inserted
replaced
1014:99c5278bf6b8 | 1015:579299b1c9b2 |
---|---|
364 eviqs *iqn; | 364 eviqs *iqn; |
365 | 365 |
366 iqn = iqs_new(JPACKET__GET, NS_TIME, "time", IQS_DEFAULT_TIMEOUT); | 366 iqn = iqs_new(JPACKET__GET, NS_TIME, "time", IQS_DEFAULT_TIMEOUT); |
367 xmlnode_put_attrib(iqn->xmldata, "to", fulljid); | 367 xmlnode_put_attrib(iqn->xmldata, "to", fulljid); |
368 iqn->callback = &iqscallback_time; | 368 iqn->callback = &iqscallback_time; |
369 jab_send(jc, iqn->xmldata); | |
370 } | |
371 | |
372 static void iqscallback_last(eviqs *iqp, xmlnode xml_result, guint iqcontext) | |
373 { | |
374 xmlnode ansqry; | |
375 char *p; | |
376 char *bjid; | |
377 char *buf; | |
378 | |
379 // Leave now if we cannot process xml_result | |
380 if (!xml_result || iqcontext) return; | |
381 | |
382 ansqry = xmlnode_get_tag(xml_result, "query"); | |
383 if (!ansqry) { | |
384 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:last result!"); | |
385 return; | |
386 } | |
387 // Display IQ result sender... | |
388 p = xmlnode_get_attrib(xml_result, "from"); | |
389 if (!p) { | |
390 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:last result (no sender name)."); | |
391 return; | |
392 } | |
393 bjid = p; | |
394 | |
395 buf = g_strdup_printf("Received IQ:last result from <%s>", bjid); | |
396 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); | |
397 | |
398 // bjid should now really be the "bare JID", let's strip the resource | |
399 p = strchr(bjid, JID_RESOURCE_SEPARATOR); | |
400 if (p) *p = '\0'; | |
401 | |
402 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO); | |
403 g_free(buf); | |
404 | |
405 // Get result data... | |
406 p = xmlnode_get_attrib(ansqry, "seconds"); | |
407 if (p) { | |
408 long int s; | |
409 GString *sbuf; | |
410 sbuf = g_string_new("Idle time: "); | |
411 s = atol(p); | |
412 // Days | |
413 if (s > 86400L) { | |
414 g_string_append_printf(sbuf, "%ldd ", s/86400L); | |
415 s %= 86400L; | |
416 } | |
417 // hh:mm:ss | |
418 g_string_append_printf(sbuf, "%02ld:", s/3600L); | |
419 s %= 3600L; | |
420 g_string_append_printf(sbuf, "%02ld:%02ld", s/60L, s%60L); | |
421 scr_WriteIncomingMessage(bjid, sbuf->str, 0, HBB_PREFIX_NONE); | |
422 g_string_free(sbuf, TRUE); | |
423 } else { | |
424 scr_WriteIncomingMessage(bjid, "No idle time reported.", | |
425 0, HBB_PREFIX_NONE); | |
426 } | |
427 p = xmlnode_get_data(ansqry); | |
428 if (p) { | |
429 buf = g_strdup_printf("Status message: %s", p); | |
430 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO); | |
431 g_free(buf); | |
432 } | |
433 } | |
434 | |
435 void request_last(const char *fulljid) | |
436 { | |
437 eviqs *iqn; | |
438 | |
439 iqn = iqs_new(JPACKET__GET, NS_LAST, "last", IQS_DEFAULT_TIMEOUT); | |
440 xmlnode_put_attrib(iqn->xmldata, "to", fulljid); | |
441 iqn->callback = &iqscallback_last; | |
369 jab_send(jc, iqn->xmldata); | 442 jab_send(jc, iqn->xmldata); |
370 } | 443 } |
371 | 444 |
372 static void display_vcard_item(const char *bjid, const char *label, | 445 static void display_vcard_item(const char *bjid, const char *label, |
373 enum vcard_attr vcard_attrib, const char *text) | 446 enum vcard_attr vcard_attrib, const char *text) |