annotate libpurple/protocols/msn/tlv.c @ 31564:bd59044a9100

The type and length of the TLV are only bytes, so fix the function declarations and definitions.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sat, 07 May 2011 07:14:48 +0000
parents dfc2a8e98430
children c714ccbcdf00
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
1 /**
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
2 * @file tlv.c MSN TLV functions
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
3 *
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
4 * purple
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
5 *
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
6 * Purple is the legal property of its developers, whose names are too numerous
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
7 * to list here. Please refer to the COPYRIGHT file distributed with this
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
8 * source distribution.
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
9 *
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
10 * This program is free software; you can redistribute it and/or modify
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
11 * it under the terms of the GNU General Public License as published by
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
12 * the Free Software Foundation; either version 2 of the License, or
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
13 * (at your option) any later version.
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
14 *
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
15 * This program is distributed in the hope that it will be useful,
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
18 * GNU General Public License for more details.
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
19 *
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
21 * along with this program; if not, write to the Free Software
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
23 */
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
24
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
25 #include "tlv.h"
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
26 #include "msnutils.h"
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
27
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
28 static msn_tlv_t *
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
29 createtlv(guint8 type, guint8 length, guint8 *value)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
30 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
31 msn_tlv_t *ret;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
32
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
33 ret = g_new(msn_tlv_t, 1);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
34 ret->type = type;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
35 ret->length = length;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
36 ret->value = value;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
37
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
38 return ret;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
39 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
40
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
41 static void
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
42 freetlv(msn_tlv_t *oldtlv)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
43 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
44 g_free(oldtlv->value);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
45 g_free(oldtlv);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
46 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
47
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
48 GSList *
31322
b8e076d51817 Add P2Pv2 parsing and saving functions. Tested by compiling them!
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31086
diff changeset
49 msn_tlvlist_read(const char *bs, size_t bs_len)
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
50 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
51 GSList *list = NULL;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
52
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
53 while (bs_len > 0) {
31549
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
54 guint8 type, length;
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
55 msn_tlv_t *tlv;
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
56
31550
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
57 if (bs_len == 3 && *bs == 0) {
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
58 /* Padding to multiple of 4 */
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
59 break;
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
60 } else if (bs_len == 2 && *bs == 0) {
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
61 /* Padding to multiple of 4 */
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
62 break;
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
63 } else if (bs_len == 1) {
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
64 if (*bs == 0) {
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
65 /* Padding to multiple of 4 */
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
66 break;
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
67 } else {
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
68 /* TLV is not small enough to fit here */
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
69 msn_tlvlist_free(list);
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
70 return NULL;
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
71 }
31549
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
72 }
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
73
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
74 type = msn_pop8(bs);
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
75 length = msn_pop8(bs);
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
76 bs_len -= 2;
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
77
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
78 if (length > bs_len) {
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
79 msn_tlvlist_free(list);
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
80 return NULL;
31549
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
81 }
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
82
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
83 tlv = createtlv(type, length, NULL);
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
84 if (length > 0) {
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
85 tlv->value = g_memdup(bs, length);
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
86 if (!tlv->value) {
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
87 freetlv(tlv);
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
88 msn_tlvlist_free(list);
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
89 return NULL;
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
90 }
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
91 }
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
92
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
93 bs_len -= length;
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
94 bs += length;
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
95
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
96 list = g_slist_prepend(list, tlv);
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
97 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
98
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
99 return g_slist_reverse(list);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
100 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
101
31549
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
102 GSList *
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
103 msn_tlvlist_copy(GSList *orig)
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
104 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
105 GSList *new = NULL;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
106 msn_tlv_t *tlv;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
107
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
108 while (orig != NULL) {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
109 tlv = orig->data;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
110 msn_tlvlist_add_raw(&new, tlv->type, tlv->length, (const char *)tlv->value);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
111 orig = orig->next;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
112 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
113
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
114 return new;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
115 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
116
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
117 gboolean
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
118 msn_tlvlist_equal(GSList *one, GSList *two)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
119 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
120 while (one && two) {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
121 msn_tlv_t *a = one->data;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
122 msn_tlv_t *b = two->data;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
123
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
124 if (a->type != b->type)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
125 return FALSE;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
126 else if (a->length != b->length)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
127 return FALSE;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
128 else if (!a->value && b->value)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
129 return FALSE;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
130 else if (a->value && !b->value)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
131 return FALSE;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
132 else if (a->value && b->value && memcmp(a->value, b->value, a->length) != 0)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
133 return FALSE;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
134
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
135 one = one->next;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
136 two = two->next;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
137 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
138
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
139 return one == two;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
140 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
141
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
142 void
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
143 msn_tlvlist_free(GSList *list)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
144 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
145 while (list != NULL) {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
146 freetlv(list->data);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
147 list = g_slist_delete_link(list, list);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
148 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
149 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
150
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
151 int
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
152 msn_tlvlist_count(GSList *list)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
153 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
154 return g_slist_length(list);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
155 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
156
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
157 size_t
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
158 msn_tlvlist_size(GSList *list)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
159 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
160 int size;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
161
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
162 if (list == NULL)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
163 return 0;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
164
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
165 for (size = 0; list; list = list->next)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
166 size += (2 + ((msn_tlv_t *)list->data)->length);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
167
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
168 return size;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
169 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
170
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
171 int
31564
bd59044a9100 The type and length of the TLV are only bytes, so fix the function
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31550
diff changeset
172 msn_tlvlist_add_raw(GSList **list, const guint8 type, const guint8 length, const char *value)
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
173 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
174 msn_tlv_t *tlv;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
175
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
176 if (list == NULL)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
177 return 0;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
178
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
179 tlv = createtlv(type, length, NULL);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
180 if (length > 0)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
181 tlv->value = g_memdup(value, length);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
182
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
183 *list = g_slist_append(*list, tlv);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
184
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
185 return tlv->length;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
186 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
187
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
188 int
31564
bd59044a9100 The type and length of the TLV are only bytes, so fix the function
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31550
diff changeset
189 msn_tlvlist_add_8(GSList **list, const guint8 type, const guint8 value)
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
190 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
191 char v8[1];
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
192
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
193 msn_write8(v8, value);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
194
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
195 return msn_tlvlist_add_raw(list, type, 1, v8);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
196 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
197
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
198 int
31564
bd59044a9100 The type and length of the TLV are only bytes, so fix the function
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31550
diff changeset
199 msn_tlvlist_add_16(GSList **list, const guint8 type, const guint16 value)
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
200 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
201 char v16[2];
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
202
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
203 msn_write16be(v16, value);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
204
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
205 return msn_tlvlist_add_raw(list, type, 2, v16);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
206 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
207
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
208 int
31564
bd59044a9100 The type and length of the TLV are only bytes, so fix the function
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31550
diff changeset
209 msn_tlvlist_add_32(GSList **list, const guint8 type, const guint32 value)
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
210 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
211 char v32[4];
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
212
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
213 msn_write32be(v32, value);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
214
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
215 return msn_tlvlist_add_raw(list, type, 4, v32);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
216 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
217
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
218 int
31564
bd59044a9100 The type and length of the TLV are only bytes, so fix the function
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31550
diff changeset
219 msn_tlvlist_add_str(GSList **list, const guint8 type, const char *value)
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
220 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
221 return msn_tlvlist_add_raw(list, type, strlen(value), value);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
222 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
223
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
224 int
31564
bd59044a9100 The type and length of the TLV are only bytes, so fix the function
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31550
diff changeset
225 msn_tlvlist_add_empty(GSList **list, const guint8 type)
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
226 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
227 return msn_tlvlist_add_raw(list, type, 0, NULL);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
228 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
229
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
230 int
31564
bd59044a9100 The type and length of the TLV are only bytes, so fix the function
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31550
diff changeset
231 msn_tlvlist_replace_raw(GSList **list, const guint8 type, const guint8 length, const char *value)
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
232 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
233 GSList *cur;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
234 msn_tlv_t *tlv;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
235
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
236 if (list == NULL)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
237 return 0;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
238
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
239 for (cur = *list; cur != NULL; cur = cur->next) {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
240 tlv = cur->data;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
241 if (tlv->type == type)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
242 break;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
243 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
244
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
245 if (cur == NULL)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
246 /* TLV does not exist, so add a new one */
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
247 return msn_tlvlist_add_raw(list, type, length, value);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
248
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
249 g_free(tlv->value);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
250 tlv->length = length;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
251 if (length > 0) {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
252 tlv->value = g_memdup(value, length);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
253 } else
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
254 tlv->value = NULL;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
255
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
256 return length;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
257 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
258
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
259 int
31564
bd59044a9100 The type and length of the TLV are only bytes, so fix the function
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31550
diff changeset
260 msn_tlvlist_replace_str(GSList **list, const guint8 type, const char *str)
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
261 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
262 return msn_tlvlist_replace_raw(list, type, strlen(str), str);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
263 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
264
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
265 int
31564
bd59044a9100 The type and length of the TLV are only bytes, so fix the function
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31550
diff changeset
266 msn_tlvlist_replace_empty(GSList **list, const guint8 type)
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
267 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
268 return msn_tlvlist_replace_raw(list, type, 0, NULL);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
269 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
270
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
271 int
31564
bd59044a9100 The type and length of the TLV are only bytes, so fix the function
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31550
diff changeset
272 msn_tlvlist_replace_8(GSList **list, const guint8 type, const guint8 value)
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
273 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
274 char v8[1];
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
275
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
276 msn_write8(v8, value);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
277
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
278 return msn_tlvlist_replace_raw(list, type, 1, v8);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
279 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
280
31086
a8cc50c2279f Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents: 31047
diff changeset
281 int
31564
bd59044a9100 The type and length of the TLV are only bytes, so fix the function
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31550
diff changeset
282 msn_tlvlist_replace_32(GSList **list, const guint8 type, const guint32 value)
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
283 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
284 char v32[4];
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
285
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
286 msn_write32be(v32, value);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
287
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
288 return msn_tlvlist_replace_raw(list, type, 4, v32);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
289 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
290
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
291 void
31564
bd59044a9100 The type and length of the TLV are only bytes, so fix the function
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31550
diff changeset
292 msn_tlvlist_remove(GSList **list, const guint8 type)
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
293 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
294 GSList *cur, *next;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
295 msn_tlv_t *tlv;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
296
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
297 if (list == NULL || *list == NULL)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
298 return;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
299
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
300 cur = *list;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
301 while (cur != NULL) {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
302 tlv = cur->data;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
303 next = cur->next;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
304
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
305 if (tlv->type == type) {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
306 /* Delete this TLV */
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
307 *list = g_slist_delete_link(*list, cur);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
308 g_free(tlv->value);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
309 g_free(tlv);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
310 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
311
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
312 cur = next;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
313 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
314 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
315
31549
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
316 char *
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
317 msn_tlvlist_write(GSList *list, size_t *out_len)
31322
b8e076d51817 Add P2Pv2 parsing and saving functions. Tested by compiling them!
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31086
diff changeset
318 {
31549
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
319 char *buf;
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
320 char *tmp;
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
321 size_t bytes_left;
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
322 size_t total_len;
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
323
31549
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
324 tmp = buf = g_malloc(256);
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
325 bytes_left = total_len = 256;
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
326
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
327 for (; list; list = g_slist_next(list)) {
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
328 msn_tlv_t *tlv = (msn_tlv_t *)list->data;
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
329
31549
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
330 if (G_UNLIKELY(tlv->length + 2 > bytes_left)) {
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
331 buf = g_realloc(buf, total_len + 256);
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
332 bytes_left += 256;
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
333 total_len += 256;
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
334 tmp = buf + (total_len - bytes_left);
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
335 }
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
336
31549
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
337 msn_push8(tmp, tlv->type);
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
338 msn_push8(tmp, tlv->length);
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
339 memcpy(tmp, tlv->value, tlv->length);
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
340 tmp += tlv->length;
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
341
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
342 bytes_left -= (tlv->length + 2);
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
343 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
344
31550
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
345 /* Align length to multiple of 4 */
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
346 total_len = total_len - bytes_left;
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
347 bytes_left = 4 - total_len % 4;
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
348 if (bytes_left != 4)
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
349 memset(tmp, 0, bytes_left);
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
350 else
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
351 bytes_left = 0;
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
352
dfc2a8e98430 The TLV list should be padded to a multiple of 4.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31549
diff changeset
353 *out_len = total_len + bytes_left;
31549
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
354
506b77a27a53 This should fix TLV in from and out of the wire.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31322
diff changeset
355 return buf;
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
356 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
357
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
358 msn_tlv_t *
31564
bd59044a9100 The type and length of the TLV are only bytes, so fix the function
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31550
diff changeset
359 msn_tlv_gettlv(GSList *list, const guint8 type, const int nth)
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
360 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
361 msn_tlv_t *tlv;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
362 int i;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
363
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
364 for (i = 0; list != NULL; list = list->next) {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
365 tlv = list->data;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
366 if (tlv->type == type)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
367 i++;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
368 if (i >= nth)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
369 return tlv;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
370 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
371
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
372 return NULL;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
373 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
374
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
375 int
31564
bd59044a9100 The type and length of the TLV are only bytes, so fix the function
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31550
diff changeset
376 msn_tlv_getlength(GSList *list, const guint8 type, const int nth)
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
377 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
378 msn_tlv_t *tlv;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
379
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
380 tlv = msn_tlv_gettlv(list, type, nth);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
381 if (tlv == NULL)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
382 return -1;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
383
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
384 return tlv->length;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
385 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
386
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
387 char *
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
388 msn_tlv_getvalue_as_string(msn_tlv_t *tlv)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
389 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
390 char *ret;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
391
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
392 ret = g_malloc(tlv->length + 1);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
393 memcpy(ret, tlv->value, tlv->length);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
394 ret[tlv->length] = '\0';
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
395
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
396 return ret;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
397 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
398
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
399 char *
31564
bd59044a9100 The type and length of the TLV are only bytes, so fix the function
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31550
diff changeset
400 msn_tlv_getstr(GSList *list, const guint8 type, const int nth)
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
401 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
402 msn_tlv_t *tlv;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
403
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
404 tlv = msn_tlv_gettlv(list, type, nth);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
405 if (tlv == NULL)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
406 return NULL;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
407
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
408 return msn_tlv_getvalue_as_string(tlv);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
409 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
410
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
411 guint8
31564
bd59044a9100 The type and length of the TLV are only bytes, so fix the function
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31550
diff changeset
412 msn_tlv_get8(GSList *list, const guint8 type, const int nth)
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
413 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
414 msn_tlv_t *tlv;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
415
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
416 tlv = msn_tlv_gettlv(list, type, nth);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
417 if (tlv == NULL)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
418 return 0; /* erm */
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
419
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
420 return msn_read8((const char *)tlv->value);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
421 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
422
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
423 guint16
31564
bd59044a9100 The type and length of the TLV are only bytes, so fix the function
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31550
diff changeset
424 msn_tlv_get16(GSList *list, const guint8 type, const int nth)
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
425 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
426 msn_tlv_t *tlv;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
427
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
428 tlv = msn_tlv_gettlv(list, type, nth);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
429 if (tlv == NULL)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
430 return 0; /* erm */
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
431
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
432 return msn_read16be((const char *)tlv->value);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
433 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
434
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
435 guint32
31564
bd59044a9100 The type and length of the TLV are only bytes, so fix the function
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31550
diff changeset
436 msn_tlv_get32(GSList *list, const guint8 type, const int nth)
31047
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
437 {
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
438 msn_tlv_t *tlv;
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
439
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
440 tlv = msn_tlv_gettlv(list, type, nth);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
441 if (tlv == NULL)
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
442 return 0; /* erm */
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
443
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
444 return msn_read32be((const char *)tlv->value);
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
445 }
a6d2d7de8a08 Nick some TLV functions from AIM. I don't know if I need all of these,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
446