Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/hbuf.c @ 1602:f4a2c6f767d1
Message Receipts support (XEP-0184)
author | franky |
---|---|
date | Wed, 24 Sep 2008 11:41:29 +0200 |
parents | dcd5d4c75199 |
children |
comparison
equal
deleted
inserted
replaced
1601:3efc92a48945 | 1602:f4a2c6f767d1 |
---|---|
42 // (for ex. when HBB_FLAG_PERSISTENT is set). | 42 // (for ex. when HBB_FLAG_PERSISTENT is set). |
43 struct { // hbuf_line_info | 43 struct { // hbuf_line_info |
44 time_t timestamp; | 44 time_t timestamp; |
45 unsigned mucnicklen; | 45 unsigned mucnicklen; |
46 guint flags; | 46 guint flags; |
47 gpointer xep184; | |
47 } prefix; | 48 } prefix; |
48 } hbuf_block; | 49 } hbuf_block; |
49 | 50 |
50 | 51 |
51 // do_wrap(p_hbuf, first_hbuf_elt, width) | 52 // do_wrap(p_hbuf, first_hbuf_elt, width) |
121 // Note 1: Splitting according to width won't work if there are tabs; they | 122 // Note 1: Splitting according to width won't work if there are tabs; they |
122 // should be expanded before. | 123 // should be expanded before. |
123 // Note 2: width does not include the ending \0. | 124 // Note 2: width does not include the ending \0. |
124 void hbuf_add_line(GList **p_hbuf, const char *text, time_t timestamp, | 125 void hbuf_add_line(GList **p_hbuf, const char *text, time_t timestamp, |
125 guint prefix_flags, guint width, guint maxhbufblocks, | 126 guint prefix_flags, guint width, guint maxhbufblocks, |
126 unsigned mucnicklen) | 127 unsigned mucnicklen, gpointer xep184) |
127 { | 128 { |
128 GList *curr_elt; | 129 GList *curr_elt; |
129 char *line; | 130 char *line; |
130 guint hbb_blocksize, textlen; | 131 guint hbb_blocksize, textlen; |
131 hbuf_block *hbuf_block_elt; | 132 hbuf_block *hbuf_block_elt; |
132 | 133 |
133 if (!text) return; | 134 if (!text) return; |
134 | 135 |
136 prefix_flags |= (xep184 ? HBB_PREFIX_RECEIPT : 0); | |
137 | |
135 textlen = strlen(text); | 138 textlen = strlen(text); |
136 hbb_blocksize = MAX(textlen+1, HBB_BLOCKSIZE); | 139 hbb_blocksize = MAX(textlen+1, HBB_BLOCKSIZE); |
137 | 140 |
138 hbuf_block_elt = g_new0(hbuf_block, 1); | 141 hbuf_block_elt = g_new0(hbuf_block, 1); |
139 hbuf_block_elt->prefix.timestamp = timestamp; | 142 hbuf_block_elt->prefix.timestamp = timestamp; |
140 hbuf_block_elt->prefix.flags = prefix_flags; | 143 hbuf_block_elt->prefix.flags = prefix_flags; |
141 hbuf_block_elt->prefix.mucnicklen = mucnicklen; | 144 hbuf_block_elt->prefix.mucnicklen = mucnicklen; |
145 hbuf_block_elt->prefix.xep184 = xep184; | |
142 if (!*p_hbuf) { | 146 if (!*p_hbuf) { |
143 hbuf_block_elt->ptr = g_new(char, hbb_blocksize); | 147 hbuf_block_elt->ptr = g_new(char, hbb_blocksize); |
144 if (!hbuf_block_elt->ptr) { | 148 if (!hbuf_block_elt->ptr) { |
145 g_free(hbuf_block_elt); | 149 g_free(hbuf_block_elt); |
146 return; | 150 return; |
472 | 476 |
473 fclose(fp); | 477 fclose(fp); |
474 return; | 478 return; |
475 } | 479 } |
476 | 480 |
481 // hbuf_remove_receipt(hbuf, xep184) | |
482 // Remove the Receipt Flag for the message with the given xep184 id | |
483 // Returns TRUE if it was found and removed, otherwise FALSE | |
484 gboolean hbuf_remove_receipt(GList *hbuf, gpointer xep184) | |
485 { | |
486 hbuf_block *blk; | |
487 | |
488 hbuf = g_list_first(hbuf); | |
489 | |
490 for ( ; hbuf; hbuf = g_list_next(hbuf)) { | |
491 blk = (hbuf_block*)(hbuf->data); | |
492 if (blk->prefix.xep184 == xep184) { | |
493 blk->prefix.xep184 = NULL; | |
494 blk->prefix.flags ^= HBB_PREFIX_RECEIPT; | |
495 return TRUE; | |
496 } | |
497 } | |
498 return FALSE; | |
499 } | |
500 | |
477 // hbuf_get_blocks_number() | 501 // hbuf_get_blocks_number() |
478 // Returns the number of allocated hbuf_block's. | 502 // Returns the number of allocated hbuf_block's. |
479 guint hbuf_get_blocks_number(GList *hbuf) | 503 guint hbuf_get_blocks_number(GList *hbuf) |
480 { | 504 { |
481 hbuf_block *hbuf_b_elt; | 505 hbuf_block *hbuf_b_elt; |