Mercurial > ~mikael > mcabber > hg
comparison mcabber/mcabber/xmpp_iqrequest.c @ 2346:7921c8d671c8
Implemented another helper function jid_get_resource_name
author | franky |
---|---|
date | Tue, 14 May 2019 22:19:33 +0200 |
parents | 4f3821bda633 |
children |
comparison
equal
deleted
inserted
replaced
2345:462f4359391c | 2346:7921c8d671c8 |
---|---|
231 static LmHandlerResult cb_version(LmMessageHandler *h, LmConnection *c, | 231 static LmHandlerResult cb_version(LmMessageHandler *h, LmConnection *c, |
232 LmMessage *m, gpointer user_data) | 232 LmMessage *m, gpointer user_data) |
233 { | 233 { |
234 LmMessageNode *ansqry; | 234 LmMessageNode *ansqry; |
235 const char *p, *bjid; | 235 const char *p, *bjid; |
236 char *buf, *tmp; | 236 char *bare_jid; |
237 char *buf; | |
237 | 238 |
238 // Check IQ result sender | 239 // Check IQ result sender |
239 bjid = lm_message_get_from(m); | 240 bjid = lm_message_get_from(m); |
240 if (!bjid) | 241 if (!bjid) |
241 bjid = lm_connection_get_jid(lconnection); // No from means our JID... | 242 bjid = lm_connection_get_jid(lconnection); // No from means our JID... |
260 | 261 |
261 buf = g_strdup_printf("Received IQ:version result from <%s>", bjid); | 262 buf = g_strdup_printf("Received IQ:version result from <%s>", bjid); |
262 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); | 263 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
263 | 264 |
264 // bjid should now really be the "bare JID", let's strip the resource | 265 // bjid should now really be the "bare JID", let's strip the resource |
265 tmp = strchr(bjid, JID_RESOURCE_SEPARATOR); | 266 bare_jid = jidtodisp(bjid); |
266 if (tmp) *tmp = '\0'; | 267 |
267 | 268 scr_WriteIncomingMessage(bare_jid, buf, 0, HBB_PREFIX_INFO, 0); |
268 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0); | |
269 g_free(buf); | 269 g_free(buf); |
270 | 270 |
271 // Get result data... | 271 // Get result data... |
272 p = lm_message_node_get_child_value(ansqry, "name"); | 272 p = lm_message_node_get_child_value(ansqry, "name"); |
273 if (p && *p) { | 273 if (p && *p) { |
274 buf = g_strdup_printf("Name: %s", p); | 274 buf = g_strdup_printf("Name: %s", p); |
275 scr_WriteIncomingMessage(bjid, buf, | 275 scr_WriteIncomingMessage(bare_jid, buf, |
276 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); | 276 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); |
277 g_free(buf); | 277 g_free(buf); |
278 } | 278 } |
279 p = lm_message_node_get_child_value(ansqry, "version"); | 279 p = lm_message_node_get_child_value(ansqry, "version"); |
280 if (p && *p) { | 280 if (p && *p) { |
281 buf = g_strdup_printf("Version: %s", p); | 281 buf = g_strdup_printf("Version: %s", p); |
282 scr_WriteIncomingMessage(bjid, buf, | 282 scr_WriteIncomingMessage(bare_jid, buf, |
283 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); | 283 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); |
284 g_free(buf); | 284 g_free(buf); |
285 } | 285 } |
286 p = lm_message_node_get_child_value(ansqry, "os"); | 286 p = lm_message_node_get_child_value(ansqry, "os"); |
287 if (p && *p) { | 287 if (p && *p) { |
288 buf = g_strdup_printf("OS: %s", p); | 288 buf = g_strdup_printf("OS: %s", p); |
289 scr_WriteIncomingMessage(bjid, buf, | 289 scr_WriteIncomingMessage(bare_jid, buf, |
290 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); | 290 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); |
291 g_free(buf); | 291 g_free(buf); |
292 } | 292 } |
293 g_free(bare_jid); | |
293 return LM_HANDLER_RESULT_REMOVE_MESSAGE; | 294 return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
294 } | 295 } |
295 | 296 |
296 static LmHandlerResult cb_time(LmMessageHandler *h, LmConnection *c, | 297 static LmHandlerResult cb_time(LmMessageHandler *h, LmConnection *c, |
297 LmMessage *m, gpointer user_data) | 298 LmMessage *m, gpointer user_data) |
298 { | 299 { |
299 LmMessageNode *ansqry; | 300 LmMessageNode *ansqry; |
300 const char *p, *bjid; | 301 const char *p, *bjid; |
301 char *buf, *tmp; | 302 char *bare_jid; |
303 char *buf; | |
302 | 304 |
303 // Check IQ result sender | 305 // Check IQ result sender |
304 bjid = lm_message_get_from(m); | 306 bjid = lm_message_get_from(m); |
305 if (!bjid) | 307 if (!bjid) |
306 bjid = lm_connection_get_jid(lconnection); // No from means our JID... | 308 bjid = lm_connection_get_jid(lconnection); // No from means our JID... |
325 | 327 |
326 buf = g_strdup_printf("Received IQ:time result from <%s>", bjid); | 328 buf = g_strdup_printf("Received IQ:time result from <%s>", bjid); |
327 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); | 329 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
328 | 330 |
329 // bjid should now really be the "bare JID", let's strip the resource | 331 // bjid should now really be the "bare JID", let's strip the resource |
330 tmp = strchr(bjid, JID_RESOURCE_SEPARATOR); | 332 bare_jid = jidtodisp(bjid); |
331 if (tmp) *tmp = '\0'; | 333 |
332 | 334 scr_WriteIncomingMessage(bare_jid, buf, 0, HBB_PREFIX_INFO, 0); |
333 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0); | |
334 g_free(buf); | 335 g_free(buf); |
335 | 336 |
336 // Get result data... | 337 // Get result data... |
337 p = lm_message_node_get_child_value(ansqry, "utc"); | 338 p = lm_message_node_get_child_value(ansqry, "utc"); |
338 if (p && *p) { | 339 if (p && *p) { |
339 buf = g_strdup_printf("UTC: %s", p); | 340 buf = g_strdup_printf("UTC: %s", p); |
340 scr_WriteIncomingMessage(bjid, buf, | 341 scr_WriteIncomingMessage(bare_jid, buf, |
341 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); | 342 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); |
342 g_free(buf); | 343 g_free(buf); |
343 } | 344 } |
344 p = lm_message_node_get_child_value(ansqry, "tzo"); | 345 p = lm_message_node_get_child_value(ansqry, "tzo"); |
345 if (p && *p) { | 346 if (p && *p) { |
346 buf = g_strdup_printf("TZ: %s", p); | 347 buf = g_strdup_printf("TZ: %s", p); |
347 scr_WriteIncomingMessage(bjid, buf, | 348 scr_WriteIncomingMessage(bare_jid, buf, |
348 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); | 349 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); |
349 g_free(buf); | 350 g_free(buf); |
350 } | 351 } |
351 p = lm_message_node_get_child_value(ansqry, "display"); | 352 p = lm_message_node_get_child_value(ansqry, "display"); |
352 if (p && *p) { | 353 if (p && *p) { |
353 buf = g_strdup_printf("Time: %s", p); | 354 buf = g_strdup_printf("Time: %s", p); |
354 scr_WriteIncomingMessage(bjid, buf, | 355 scr_WriteIncomingMessage(bare_jid, buf, |
355 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); | 356 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); |
356 g_free(buf); | 357 g_free(buf); |
357 } | 358 } |
359 g_free(bare_jid); | |
358 return LM_HANDLER_RESULT_REMOVE_MESSAGE; | 360 return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
359 } | 361 } |
360 | 362 |
361 static LmHandlerResult cb_last(LmMessageHandler *h, LmConnection *c, | 363 static LmHandlerResult cb_last(LmMessageHandler *h, LmConnection *c, |
362 LmMessage *m, gpointer user_data) | 364 LmMessage *m, gpointer user_data) |
363 { | 365 { |
364 LmMessageNode *ansqry; | 366 LmMessageNode *ansqry; |
365 const char *p, *bjid; | 367 const char *p, *bjid; |
366 char *buf, *tmp; | 368 char *bare_jid; |
369 char *buf; | |
367 | 370 |
368 // Check IQ result sender | 371 // Check IQ result sender |
369 bjid = lm_message_get_from(m); | 372 bjid = lm_message_get_from(m); |
370 if (!bjid) | 373 if (!bjid) |
371 bjid = lm_connection_get_jid(lconnection); // No from means our JID... | 374 bjid = lm_connection_get_jid(lconnection); // No from means our JID... |
390 | 393 |
391 buf = g_strdup_printf("Received IQ:last result from <%s>", bjid); | 394 buf = g_strdup_printf("Received IQ:last result from <%s>", bjid); |
392 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); | 395 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
393 | 396 |
394 // bjid should now really be the "bare JID", let's strip the resource | 397 // bjid should now really be the "bare JID", let's strip the resource |
395 tmp = strchr(bjid, JID_RESOURCE_SEPARATOR); | 398 bare_jid = jidtodisp(bjid); |
396 if (tmp) *tmp = '\0'; | 399 |
397 | 400 scr_WriteIncomingMessage(bare_jid, buf, 0, HBB_PREFIX_INFO, 0); |
398 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0); | |
399 g_free(buf); | 401 g_free(buf); |
400 | 402 |
401 // Get result data... | 403 // Get result data... |
402 p = lm_message_node_get_attribute(ansqry, "seconds"); | 404 p = lm_message_node_get_attribute(ansqry, "seconds"); |
403 if (p) { | 405 if (p) { |
412 } | 414 } |
413 // hh:mm:ss | 415 // hh:mm:ss |
414 g_string_append_printf(sbuf, "%02ld:", s/3600L); | 416 g_string_append_printf(sbuf, "%02ld:", s/3600L); |
415 s %= 3600L; | 417 s %= 3600L; |
416 g_string_append_printf(sbuf, "%02ld:%02ld", s/60L, s%60L); | 418 g_string_append_printf(sbuf, "%02ld:%02ld", s/60L, s%60L); |
417 scr_WriteIncomingMessage(bjid, sbuf->str, | 419 scr_WriteIncomingMessage(bare_jid, sbuf->str, |
418 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); | 420 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); |
419 g_string_free(sbuf, TRUE); | 421 g_string_free(sbuf, TRUE); |
420 } else { | 422 } else { |
421 scr_WriteIncomingMessage(bjid, "No idle time reported.", | 423 scr_WriteIncomingMessage(bare_jid, "No idle time reported.", |
422 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); | 424 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0); |
423 } | 425 } |
424 p = lm_message_node_get_value(ansqry); | 426 p = lm_message_node_get_value(ansqry); |
425 if (p) { | 427 if (p) { |
426 buf = g_strdup_printf("Status message: %s", p); | 428 buf = g_strdup_printf("Status message: %s", p); |
427 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0); | 429 scr_WriteIncomingMessage(bare_jid, buf, 0, HBB_PREFIX_INFO, 0); |
428 g_free(buf); | 430 g_free(buf); |
429 } | 431 } |
432 g_free(bare_jid); | |
430 return LM_HANDLER_RESULT_REMOVE_MESSAGE; | 433 return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
431 } | 434 } |
432 | 435 |
433 static void display_vcard_item(const char *bjid, const char *label, | 436 static void display_vcard_item(const char *bjid, const char *label, |
434 enum vcard_attr vcard_attrib, const char *text) | 437 enum vcard_attr vcard_attrib, const char *text) |
544 static LmHandlerResult cb_vcard(LmMessageHandler *h, LmConnection *c, | 547 static LmHandlerResult cb_vcard(LmMessageHandler *h, LmConnection *c, |
545 LmMessage *m, gpointer user_data) | 548 LmMessage *m, gpointer user_data) |
546 { | 549 { |
547 LmMessageNode *ansqry; | 550 LmMessageNode *ansqry; |
548 const char *bjid; | 551 const char *bjid; |
549 char *buf, *tmp; | 552 char *bare_jid; |
553 char *buf; | |
550 | 554 |
551 // Check IQ result sender | 555 // Check IQ result sender |
552 bjid = lm_message_get_from(m); | 556 bjid = lm_message_get_from(m); |
553 if (!bjid) | 557 if (!bjid) |
554 bjid = lm_connection_get_jid(lconnection); // No from means our JID... | 558 bjid = lm_connection_get_jid(lconnection); // No from means our JID... |
574 g_free(buf); | 578 g_free(buf); |
575 return LM_HANDLER_RESULT_REMOVE_MESSAGE; | 579 return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
576 } | 580 } |
577 | 581 |
578 // bjid should really be the "bare JID", let's strip the resource | 582 // bjid should really be the "bare JID", let's strip the resource |
579 tmp = strchr(bjid, JID_RESOURCE_SEPARATOR); | 583 bare_jid = jidtodisp(bjid); |
580 if (tmp) *tmp = '\0'; | 584 |
581 | 585 scr_WriteIncomingMessage(bare_jid, buf, 0, HBB_PREFIX_INFO, 0); |
582 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0); | |
583 g_free(buf); | 586 g_free(buf); |
584 | 587 |
585 // Get result data... | 588 // Get result data... |
586 handle_vcard_node(bjid, ansqry); | 589 handle_vcard_node(bare_jid, ansqry); |
590 g_free(bare_jid); | |
587 return LM_HANDLER_RESULT_REMOVE_MESSAGE; | 591 return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
588 } | 592 } |
589 | 593 |
590 static void storage_bookmarks_parse_conference(LmMessageNode *node) | 594 static void storage_bookmarks_parse_conference(LmMessageNode *node) |
591 { | 595 { |