Fri, 14 Dec 2018 18:51:17 -0600
Use G_BEGIN_DECLS and G_END_DECLS instead of raw extern "C"
This patch replaces direct usage of 'extern "C"', guarded with
_cplusplus, with GLib's G_BEGIN_DECLS and G_END_DECLS.
| 3952 | 1 | /* |
| 15884 | 2 | * Purple's oscar protocol plugin |
|
13235
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
3 | * This file is the legal property of its developers. |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
4 | * Please see the AUTHORS file distributed alongside this file. |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
5 | * |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
6 | * This library is free software; you can redistribute it and/or |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
7 | * modify it under the terms of the GNU Lesser General Public |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
8 | * License as published by the Free Software Foundation; either |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
9 | * version 2 of the License, or (at your option) any later version. |
| 3952 | 10 | * |
|
13235
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
11 | * This library is distributed in the hope that it will be useful, |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
14 | * Lesser General Public License for more details. |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
15 | * |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
16 | * You should have received a copy of the GNU Lesser General Public |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
17 | * License along with this library; if not, write to the Free Software |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17280
diff
changeset
|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
13235
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
19 | */ |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
20 | |
|
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
21 | /* |
| 3952 | 22 | * This file contains all functions needed to use bstreams. |
| 23 | */ | |
| 24 | ||
|
13235
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
25 | #include "oscar.h" |
| 3952 | 26 | |
|
30689
d7ebbdb28650
Change the "length of bstream" data type to be a gsize, since it represents
Mark Doliner <markdoliner@pidgin.im>
parents:
30669
diff
changeset
|
27 | int byte_stream_new(ByteStream *bs, size_t len) |
|
15151
bb985812fefa
[gaim-migrate @ 17875]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
28 | { |
|
bb985812fefa
[gaim-migrate @ 17875]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
29 | if (bs == NULL) |
|
bb985812fefa
[gaim-migrate @ 17875]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
30 | return -1; |
|
bb985812fefa
[gaim-migrate @ 17875]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
31 | |
|
bb985812fefa
[gaim-migrate @ 17875]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
32 | return byte_stream_init(bs, g_malloc(len), len); |
|
bb985812fefa
[gaim-migrate @ 17875]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
33 | } |
|
bb985812fefa
[gaim-migrate @ 17875]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
34 | |
|
30689
d7ebbdb28650
Change the "length of bstream" data type to be a gsize, since it represents
Mark Doliner <markdoliner@pidgin.im>
parents:
30669
diff
changeset
|
35 | int byte_stream_init(ByteStream *bs, guint8 *data, size_t len) |
| 3952 | 36 | { |
|
15151
bb985812fefa
[gaim-migrate @ 17875]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
37 | if (bs == NULL) |
| 3952 | 38 | return -1; |
| 39 | ||
| 40 | bs->data = data; | |
| 41 | bs->len = len; | |
| 42 | bs->offset = 0; | |
| 43 | ||
| 44 | return 0; | |
| 45 | } | |
| 46 | ||
|
22860
2b0e247173b2
All SNACs on FLAP channel 2 except in the auth family are now sent through
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
47 | void byte_stream_destroy(ByteStream *bs) |
|
2b0e247173b2
All SNACs on FLAP channel 2 except in the auth family are now sent through
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
48 | { |
|
2b0e247173b2
All SNACs on FLAP channel 2 except in the auth family are now sent through
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
49 | g_free(bs->data); |
|
2b0e247173b2
All SNACs on FLAP channel 2 except in the auth family are now sent through
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
50 | } |
|
2b0e247173b2
All SNACs on FLAP channel 2 except in the auth family are now sent through
Evan Schoenberg <evands@pidgin.im>
parents:
19859
diff
changeset
|
51 | |
|
36256
a437550a9308
Remove -Wno-sign-compare and backport fixes from default.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30689
diff
changeset
|
52 | size_t byte_stream_bytes_left(ByteStream *bs) |
| 3952 | 53 | { |
|
34304
faf0414a8b51
Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
30689
diff
changeset
|
54 | g_return_val_if_fail(bs != NULL, 0); |
|
34311
2eb147600041
Fix AIM connection issue related to recent -Wsign-compare fixes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
34304
diff
changeset
|
55 | g_return_val_if_fail(bs->len >= bs->offset, 0); |
|
34304
faf0414a8b51
Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
30689
diff
changeset
|
56 | |
| 3952 | 57 | return bs->len - bs->offset; |
| 58 | } | |
| 59 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
60 | int byte_stream_curpos(ByteStream *bs) |
| 3952 | 61 | { |
| 62 | return bs->offset; | |
| 63 | } | |
| 64 | ||
|
30689
d7ebbdb28650
Change the "length of bstream" data type to be a gsize, since it represents
Mark Doliner <markdoliner@pidgin.im>
parents:
30669
diff
changeset
|
65 | int byte_stream_setpos(ByteStream *bs, size_t off) |
| 3952 | 66 | { |
| 30668 | 67 | g_return_val_if_fail(off <= bs->len, -1); |
| 3952 | 68 | |
| 69 | bs->offset = off; | |
| 70 | return off; | |
| 71 | } | |
| 72 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
73 | void byte_stream_rewind(ByteStream *bs) |
| 3952 | 74 | { |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
75 | byte_stream_setpos(bs, 0); |
| 3952 | 76 | } |
| 77 | ||
|
10595
1338add2b0b0
[gaim-migrate @ 12010]
Mark Doliner <markdoliner@pidgin.im>
parents:
10464
diff
changeset
|
78 | /* |
|
1338add2b0b0
[gaim-migrate @ 12010]
Mark Doliner <markdoliner@pidgin.im>
parents:
10464
diff
changeset
|
79 | * N can be negative, which can be used for going backwards |
| 30668 | 80 | * in a bstream. |
|
10595
1338add2b0b0
[gaim-migrate @ 12010]
Mark Doliner <markdoliner@pidgin.im>
parents:
10464
diff
changeset
|
81 | */ |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
82 | int byte_stream_advance(ByteStream *bs, int n) |
| 3952 | 83 | { |
|
30669
e669bab0688e
Renames and cleanups.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30668
diff
changeset
|
84 | g_return_val_if_fail(byte_stream_curpos(bs) + n >= 0, 0); |
|
36256
a437550a9308
Remove -Wno-sign-compare and backport fixes from default.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30689
diff
changeset
|
85 | g_return_val_if_fail((gsize)n <= byte_stream_bytes_left(bs), 0); |
| 3952 | 86 | |
| 87 | bs->offset += n; | |
| 88 | return n; | |
| 89 | } | |
| 90 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
91 | guint8 byte_stream_get8(ByteStream *bs) |
| 3952 | 92 | { |
| 30668 | 93 | g_return_val_if_fail(byte_stream_bytes_left(bs) >= 1, 0); |
|
10464
034b1b3ad2be
[gaim-migrate @ 11739]
Mark Doliner <markdoliner@pidgin.im>
parents:
7631
diff
changeset
|
94 | |
| 3952 | 95 | bs->offset++; |
| 96 | return aimutil_get8(bs->data + bs->offset - 1); | |
| 97 | } | |
| 98 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
99 | guint16 byte_stream_get16(ByteStream *bs) |
| 3952 | 100 | { |
| 30668 | 101 | g_return_val_if_fail(byte_stream_bytes_left(bs) >= 2, 0); |
|
10464
034b1b3ad2be
[gaim-migrate @ 11739]
Mark Doliner <markdoliner@pidgin.im>
parents:
7631
diff
changeset
|
102 | |
| 3952 | 103 | bs->offset += 2; |
| 104 | return aimutil_get16(bs->data + bs->offset - 2); | |
| 105 | } | |
| 106 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
107 | guint32 byte_stream_get32(ByteStream *bs) |
| 3952 | 108 | { |
| 30668 | 109 | g_return_val_if_fail(byte_stream_bytes_left(bs) >= 4, 0); |
|
10464
034b1b3ad2be
[gaim-migrate @ 11739]
Mark Doliner <markdoliner@pidgin.im>
parents:
7631
diff
changeset
|
110 | |
| 3952 | 111 | bs->offset += 4; |
| 112 | return aimutil_get32(bs->data + bs->offset - 4); | |
| 113 | } | |
| 114 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
115 | guint8 byte_stream_getle8(ByteStream *bs) |
| 3952 | 116 | { |
| 30668 | 117 | g_return_val_if_fail(byte_stream_bytes_left(bs) >= 1, 0); |
|
10464
034b1b3ad2be
[gaim-migrate @ 11739]
Mark Doliner <markdoliner@pidgin.im>
parents:
7631
diff
changeset
|
118 | |
| 3952 | 119 | bs->offset++; |
| 120 | return aimutil_getle8(bs->data + bs->offset - 1); | |
| 121 | } | |
| 122 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
123 | guint16 byte_stream_getle16(ByteStream *bs) |
| 3952 | 124 | { |
| 30668 | 125 | g_return_val_if_fail(byte_stream_bytes_left(bs) >= 2, 0); |
|
10464
034b1b3ad2be
[gaim-migrate @ 11739]
Mark Doliner <markdoliner@pidgin.im>
parents:
7631
diff
changeset
|
126 | |
| 3952 | 127 | bs->offset += 2; |
| 128 | return aimutil_getle16(bs->data + bs->offset - 2); | |
| 129 | } | |
| 130 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
131 | guint32 byte_stream_getle32(ByteStream *bs) |
| 3952 | 132 | { |
| 30668 | 133 | g_return_val_if_fail(byte_stream_bytes_left(bs) >= 4, 0); |
|
10464
034b1b3ad2be
[gaim-migrate @ 11739]
Mark Doliner <markdoliner@pidgin.im>
parents:
7631
diff
changeset
|
134 | |
| 3952 | 135 | bs->offset += 4; |
| 136 | return aimutil_getle32(bs->data + bs->offset - 4); | |
| 137 | } | |
| 138 | ||
|
30689
d7ebbdb28650
Change the "length of bstream" data type to be a gsize, since it represents
Mark Doliner <markdoliner@pidgin.im>
parents:
30669
diff
changeset
|
139 | static void byte_stream_getrawbuf_nocheck(ByteStream *bs, guint8 *buf, size_t len) |
|
27437
4e89d2e440bb
Apply [6525ecee38c5d0cbcb9bbbe105749a8553f021b3] here as well. I should
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
26069
diff
changeset
|
140 | { |
|
4e89d2e440bb
Apply [6525ecee38c5d0cbcb9bbbe105749a8553f021b3] here as well. I should
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
26069
diff
changeset
|
141 | memcpy(buf, bs->data + bs->offset, len); |
|
4e89d2e440bb
Apply [6525ecee38c5d0cbcb9bbbe105749a8553f021b3] here as well. I should
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
26069
diff
changeset
|
142 | bs->offset += len; |
|
4e89d2e440bb
Apply [6525ecee38c5d0cbcb9bbbe105749a8553f021b3] here as well. I should
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
26069
diff
changeset
|
143 | } |
|
4e89d2e440bb
Apply [6525ecee38c5d0cbcb9bbbe105749a8553f021b3] here as well. I should
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
26069
diff
changeset
|
144 | |
|
30689
d7ebbdb28650
Change the "length of bstream" data type to be a gsize, since it represents
Mark Doliner <markdoliner@pidgin.im>
parents:
30669
diff
changeset
|
145 | int byte_stream_getrawbuf(ByteStream *bs, guint8 *buf, size_t len) |
|
10990
6655ae14e763
[gaim-migrate @ 12828]
Mark Doliner <markdoliner@pidgin.im>
parents:
10595
diff
changeset
|
146 | { |
| 30668 | 147 | g_return_val_if_fail(byte_stream_bytes_left(bs) >= len, 0); |
|
10990
6655ae14e763
[gaim-migrate @ 12828]
Mark Doliner <markdoliner@pidgin.im>
parents:
10595
diff
changeset
|
148 | |
|
27437
4e89d2e440bb
Apply [6525ecee38c5d0cbcb9bbbe105749a8553f021b3] here as well. I should
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
26069
diff
changeset
|
149 | byte_stream_getrawbuf_nocheck(bs, buf, len); |
|
10990
6655ae14e763
[gaim-migrate @ 12828]
Mark Doliner <markdoliner@pidgin.im>
parents:
10595
diff
changeset
|
150 | return len; |
|
6655ae14e763
[gaim-migrate @ 12828]
Mark Doliner <markdoliner@pidgin.im>
parents:
10595
diff
changeset
|
151 | } |
|
6655ae14e763
[gaim-migrate @ 12828]
Mark Doliner <markdoliner@pidgin.im>
parents:
10595
diff
changeset
|
152 | |
|
30689
d7ebbdb28650
Change the "length of bstream" data type to be a gsize, since it represents
Mark Doliner <markdoliner@pidgin.im>
parents:
30669
diff
changeset
|
153 | guint8 *byte_stream_getraw(ByteStream *bs, size_t len) |
|
10990
6655ae14e763
[gaim-migrate @ 12828]
Mark Doliner <markdoliner@pidgin.im>
parents:
10595
diff
changeset
|
154 | { |
|
13235
72bddc689630
[gaim-migrate @ 15600]
Mark Doliner <markdoliner@pidgin.im>
parents:
10993
diff
changeset
|
155 | guint8 *ob; |
|
10990
6655ae14e763
[gaim-migrate @ 12828]
Mark Doliner <markdoliner@pidgin.im>
parents:
10595
diff
changeset
|
156 | |
| 30668 | 157 | g_return_val_if_fail(byte_stream_bytes_left(bs) >= len, NULL); |
|
27437
4e89d2e440bb
Apply [6525ecee38c5d0cbcb9bbbe105749a8553f021b3] here as well. I should
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
26069
diff
changeset
|
158 | |
|
17280
7c0472208173
Make all the oscar memory allocations and frees use the glib functions to avoid problems when mixing C runtimes.
Daniel Atallah <datallah@pidgin.im>
parents:
15884
diff
changeset
|
159 | ob = g_malloc(len); |
|
27437
4e89d2e440bb
Apply [6525ecee38c5d0cbcb9bbbe105749a8553f021b3] here as well. I should
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
26069
diff
changeset
|
160 | byte_stream_getrawbuf_nocheck(bs, ob, len); |
|
10990
6655ae14e763
[gaim-migrate @ 12828]
Mark Doliner <markdoliner@pidgin.im>
parents:
10595
diff
changeset
|
161 | return ob; |
|
6655ae14e763
[gaim-migrate @ 12828]
Mark Doliner <markdoliner@pidgin.im>
parents:
10595
diff
changeset
|
162 | } |
|
6655ae14e763
[gaim-migrate @ 12828]
Mark Doliner <markdoliner@pidgin.im>
parents:
10595
diff
changeset
|
163 | |
|
30689
d7ebbdb28650
Change the "length of bstream" data type to be a gsize, since it represents
Mark Doliner <markdoliner@pidgin.im>
parents:
30669
diff
changeset
|
164 | char *byte_stream_getstr(ByteStream *bs, size_t len) |
|
10990
6655ae14e763
[gaim-migrate @ 12828]
Mark Doliner <markdoliner@pidgin.im>
parents:
10595
diff
changeset
|
165 | { |
|
6655ae14e763
[gaim-migrate @ 12828]
Mark Doliner <markdoliner@pidgin.im>
parents:
10595
diff
changeset
|
166 | char *ob; |
|
6655ae14e763
[gaim-migrate @ 12828]
Mark Doliner <markdoliner@pidgin.im>
parents:
10595
diff
changeset
|
167 | |
| 30668 | 168 | g_return_val_if_fail(byte_stream_bytes_left(bs) >= len, NULL); |
|
27437
4e89d2e440bb
Apply [6525ecee38c5d0cbcb9bbbe105749a8553f021b3] here as well. I should
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
26069
diff
changeset
|
169 | |
|
17280
7c0472208173
Make all the oscar memory allocations and frees use the glib functions to avoid problems when mixing C runtimes.
Daniel Atallah <datallah@pidgin.im>
parents:
15884
diff
changeset
|
170 | ob = g_malloc(len + 1); |
|
27437
4e89d2e440bb
Apply [6525ecee38c5d0cbcb9bbbe105749a8553f021b3] here as well. I should
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
26069
diff
changeset
|
171 | byte_stream_getrawbuf_nocheck(bs, (guint8 *)ob, len); |
|
10990
6655ae14e763
[gaim-migrate @ 12828]
Mark Doliner <markdoliner@pidgin.im>
parents:
10595
diff
changeset
|
172 | ob[len] = '\0'; |
|
6655ae14e763
[gaim-migrate @ 12828]
Mark Doliner <markdoliner@pidgin.im>
parents:
10595
diff
changeset
|
173 | return ob; |
|
6655ae14e763
[gaim-migrate @ 12828]
Mark Doliner <markdoliner@pidgin.im>
parents:
10595
diff
changeset
|
174 | } |
|
6655ae14e763
[gaim-migrate @ 12828]
Mark Doliner <markdoliner@pidgin.im>
parents:
10595
diff
changeset
|
175 | |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
176 | int byte_stream_put8(ByteStream *bs, guint8 v) |
| 3952 | 177 | { |
| 30668 | 178 | g_return_val_if_fail(byte_stream_bytes_left(bs) >= 1, 0); |
| 3952 | 179 | |
| 180 | bs->offset += aimutil_put8(bs->data + bs->offset, v); | |
| 181 | return 1; | |
| 182 | } | |
| 183 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
184 | int byte_stream_put16(ByteStream *bs, guint16 v) |
| 3952 | 185 | { |
| 30668 | 186 | g_return_val_if_fail(byte_stream_bytes_left(bs) >= 2, 0); |
| 3952 | 187 | |
| 188 | bs->offset += aimutil_put16(bs->data + bs->offset, v); | |
| 189 | return 2; | |
| 190 | } | |
| 191 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
192 | int byte_stream_put32(ByteStream *bs, guint32 v) |
| 3952 | 193 | { |
| 30668 | 194 | g_return_val_if_fail(byte_stream_bytes_left(bs) >= 4, 0); |
| 3952 | 195 | |
| 196 | bs->offset += aimutil_put32(bs->data + bs->offset, v); | |
| 197 | return 1; | |
| 198 | } | |
| 199 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
200 | int byte_stream_putle8(ByteStream *bs, guint8 v) |
| 3952 | 201 | { |
| 30668 | 202 | g_return_val_if_fail(byte_stream_bytes_left(bs) >= 1, 0); |
| 3952 | 203 | |
| 204 | bs->offset += aimutil_putle8(bs->data + bs->offset, v); | |
| 205 | return 1; | |
| 206 | } | |
| 207 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
208 | int byte_stream_putle16(ByteStream *bs, guint16 v) |
| 3952 | 209 | { |
| 30668 | 210 | g_return_val_if_fail(byte_stream_bytes_left(bs) >= 2, 0); |
| 3952 | 211 | |
| 212 | bs->offset += aimutil_putle16(bs->data + bs->offset, v); | |
| 213 | return 2; | |
| 214 | } | |
| 215 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
216 | int byte_stream_putle32(ByteStream *bs, guint32 v) |
| 3952 | 217 | { |
| 30668 | 218 | g_return_val_if_fail(byte_stream_bytes_left(bs) >= 4, 0); |
| 3952 | 219 | |
| 220 | bs->offset += aimutil_putle32(bs->data + bs->offset, v); | |
| 221 | return 1; | |
| 222 | } | |
| 223 | ||
| 224 | ||
|
30689
d7ebbdb28650
Change the "length of bstream" data type to be a gsize, since it represents
Mark Doliner <markdoliner@pidgin.im>
parents:
30669
diff
changeset
|
225 | int byte_stream_putraw(ByteStream *bs, const guint8 *v, size_t len) |
| 3952 | 226 | { |
| 30668 | 227 | g_return_val_if_fail(byte_stream_bytes_left(bs) >= len, 0); |
| 3952 | 228 | |
| 229 | memcpy(bs->data + bs->offset, v, len); | |
| 230 | bs->offset += len; | |
| 231 | return len; | |
| 232 | } | |
| 233 | ||
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
234 | int byte_stream_putstr(ByteStream *bs, const char *str) |
|
10990
6655ae14e763
[gaim-migrate @ 12828]
Mark Doliner <markdoliner@pidgin.im>
parents:
10595
diff
changeset
|
235 | { |
|
13593
3450a7cede99
[gaim-migrate @ 15978]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
236 | return byte_stream_putraw(bs, (guint8 *)str, strlen(str)); |
|
10990
6655ae14e763
[gaim-migrate @ 12828]
Mark Doliner <markdoliner@pidgin.im>
parents:
10595
diff
changeset
|
237 | } |
|
6655ae14e763
[gaim-migrate @ 12828]
Mark Doliner <markdoliner@pidgin.im>
parents:
10595
diff
changeset
|
238 | |
|
30689
d7ebbdb28650
Change the "length of bstream" data type to be a gsize, since it represents
Mark Doliner <markdoliner@pidgin.im>
parents:
30669
diff
changeset
|
239 | int byte_stream_putbs(ByteStream *bs, ByteStream *srcbs, size_t len) |
| 3952 | 240 | { |
| 30668 | 241 | g_return_val_if_fail(byte_stream_bytes_left(srcbs) >= len, 0); |
| 242 | g_return_val_if_fail(byte_stream_bytes_left(bs) >= len, 0); | |
| 3952 | 243 | |
| 244 | memcpy(bs->data + bs->offset, srcbs->data + srcbs->offset, len); | |
| 245 | bs->offset += len; | |
| 246 | srcbs->offset += len; | |
| 247 | return len; | |
| 248 | } | |
|
25086
fb94ee60a4f2
Minor cleanup: remove od->sn, since it's the same as PurpleAccount->username
Mark Doliner <markdoliner@pidgin.im>
parents:
22860
diff
changeset
|
249 | |
|
fb94ee60a4f2
Minor cleanup: remove od->sn, since it's the same as PurpleAccount->username
Mark Doliner <markdoliner@pidgin.im>
parents:
22860
diff
changeset
|
250 | int byte_stream_putuid(ByteStream *bs, OscarData *od) |
|
fb94ee60a4f2
Minor cleanup: remove od->sn, since it's the same as PurpleAccount->username
Mark Doliner <markdoliner@pidgin.im>
parents:
22860
diff
changeset
|
251 | { |
|
fb94ee60a4f2
Minor cleanup: remove od->sn, since it's the same as PurpleAccount->username
Mark Doliner <markdoliner@pidgin.im>
parents:
22860
diff
changeset
|
252 | PurpleAccount *account; |
|
fb94ee60a4f2
Minor cleanup: remove od->sn, since it's the same as PurpleAccount->username
Mark Doliner <markdoliner@pidgin.im>
parents:
22860
diff
changeset
|
253 | |
|
fb94ee60a4f2
Minor cleanup: remove od->sn, since it's the same as PurpleAccount->username
Mark Doliner <markdoliner@pidgin.im>
parents:
22860
diff
changeset
|
254 | account = purple_connection_get_account(od->gc); |
|
fb94ee60a4f2
Minor cleanup: remove od->sn, since it's the same as PurpleAccount->username
Mark Doliner <markdoliner@pidgin.im>
parents:
22860
diff
changeset
|
255 | |
|
fb94ee60a4f2
Minor cleanup: remove od->sn, since it's the same as PurpleAccount->username
Mark Doliner <markdoliner@pidgin.im>
parents:
22860
diff
changeset
|
256 | return byte_stream_putle32(bs, atoi(purple_account_get_username(account))); |
|
fb94ee60a4f2
Minor cleanup: remove od->sn, since it's the same as PurpleAccount->username
Mark Doliner <markdoliner@pidgin.im>
parents:
22860
diff
changeset
|
257 | } |
|
26069
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
258 | |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
259 | void byte_stream_put_bart_asset(ByteStream *bs, guint16 type, ByteStream *data) |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
260 | { |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
261 | byte_stream_put16(bs, type); |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
262 | |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
263 | if (data != NULL && data->len > 0) { |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
264 | /* Flags. 0x04 means "this asset has data attached to it" */ |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
265 | byte_stream_put8(bs, 0x04); /* Flags */ |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
266 | byte_stream_put8(bs, data->len); /* Length */ |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
267 | byte_stream_rewind(data); |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
268 | byte_stream_putbs(bs, data, data->len); /* Data */ |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
269 | } else { |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
270 | byte_stream_put8(bs, 0x00); /* No flags */ |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
271 | byte_stream_put8(bs, 0x00); /* Length */ |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
272 | /* No data */ |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
273 | } |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
274 | } |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
275 | |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
276 | void byte_stream_put_bart_asset_str(ByteStream *bs, guint16 type, const char *datastr) |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
277 | { |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
278 | ByteStream data; |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
279 | size_t len = datastr != NULL ? strlen(datastr) : 0; |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
280 | |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
281 | if (len > 0) { |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
282 | byte_stream_new(&data, 2 + len + 2); |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
283 | byte_stream_put16(&data, len); /* Length */ |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
284 | byte_stream_putstr(&data, datastr); /* String */ |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
285 | byte_stream_put16(&data, 0x0000); /* Unknown */ |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
286 | byte_stream_put_bart_asset(bs, type, &data); |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
287 | byte_stream_destroy(&data); |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
288 | } else { |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
289 | byte_stream_put_bart_asset(bs, type, NULL); |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
290 | } |
|
0fa1f9b71cea
Create two helper functions for setting the available message and iTunes
Mark Doliner <markdoliner@pidgin.im>
parents:
25086
diff
changeset
|
291 | } |