Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/jabglue.c @ 534:3569d38f7bbb
Add presnew()
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Fri, 25 Nov 2005 22:09:30 +0100 |
parents | c478e8f7f074 |
children | b407d19c39ab |
comparison
equal
deleted
inserted
replaced
533:c478e8f7f074 | 534:3569d38f7bbb |
---|---|
286 to = g_strdup_printf("%s/%s", jid, nickname); | 286 to = g_strdup_printf("%s/%s", jid, nickname); |
287 jb_setstatus(pres->st, to, pres->msg); | 287 jb_setstatus(pres->st, to, pres->msg); |
288 g_free(to); | 288 g_free(to); |
289 } | 289 } |
290 | 290 |
291 void jb_setstatus(enum imstatus st, const char *recipient, const char *msg) | 291 // presnew(status, recipient, message) |
292 { | 292 // Create an xmlnode with default presence attributes |
293 // Note: the caller must free the node after use | |
294 static xmlnode presnew(enum imstatus st, const char *recipient, | |
295 const char *msg) | |
296 { | |
297 unsigned int prio; | |
293 xmlnode x; | 298 xmlnode x; |
294 gchar *utf8_msg; | |
295 unsigned int prio; | |
296 struct T_presence room_presence; | |
297 | |
298 if (!online) return; | |
299 | 299 |
300 x = jutil_presnew(JPACKET__UNKNOWN, 0, 0); | 300 x = jutil_presnew(JPACKET__UNKNOWN, 0, 0); |
301 | 301 |
302 if (recipient) | 302 if (recipient) |
303 xmlnode_put_attrib(x, "to", recipient); | 303 xmlnode_put_attrib(x, "to", recipient); |
338 prio = settings_opt_get_int("priority"); | 338 prio = settings_opt_get_int("priority"); |
339 if (prio) { | 339 if (prio) { |
340 char strprio[8]; | 340 char strprio[8]; |
341 snprintf(strprio, 8, "%u", prio); | 341 snprintf(strprio, 8, "%u", prio); |
342 xmlnode_insert_cdata(xmlnode_insert_tag(x, "priority"), | 342 xmlnode_insert_cdata(xmlnode_insert_tag(x, "priority"), |
343 strprio, (unsigned) -1); | 343 strprio, (unsigned) -1); |
344 } | 344 } |
345 | |
346 if (msg) { | |
347 gchar *utf8_msg = to_utf8(msg); | |
348 xmlnode_insert_cdata(xmlnode_insert_tag(x, "status"), utf8_msg, | |
349 (unsigned) -1); | |
350 g_free(utf8_msg); | |
351 } | |
352 | |
353 return x; | |
354 } | |
355 | |
356 void jb_setstatus(enum imstatus st, const char *recipient, const char *msg) | |
357 { | |
358 xmlnode x; | |
359 struct T_presence room_presence; | |
360 | |
361 if (!online) return; | |
345 | 362 |
346 if (msg) { | 363 if (msg) { |
347 // The status message has been specified. We'll use it, unless it is | 364 // The status message has been specified. We'll use it, unless it is |
348 // "-" which is a special case (option meaning "no status message"). | 365 // "-" which is a special case (option meaning "no status message"). |
349 if (!strcmp(msg, "-")) | 366 if (!strcmp(msg, "-")) |
360 else | 377 else |
361 msg = ""; | 378 msg = ""; |
362 } | 379 } |
363 } | 380 } |
364 | 381 |
365 utf8_msg = to_utf8(msg); | 382 x = presnew(st, recipient, msg); |
366 xmlnode_insert_cdata(xmlnode_insert_tag(x, "status"), utf8_msg, | |
367 (unsigned) -1); | |
368 | |
369 jab_send(jc, x); | 383 jab_send(jc, x); |
370 g_free(utf8_msg); | |
371 xmlnode_free(x); | 384 xmlnode_free(x); |
372 | 385 |
373 // If we didn't change our _global_ status, we are done | 386 // If we didn't change our _global_ status, we are done |
374 if (recipient) return; | 387 if (recipient) return; |
375 | 388 |