annotate src/protocols/oscar/bstream.c @ 14027:931320242432

[gaim-migrate @ 16628] This line doesn't seem to be needed, and having it there causes duplicate "Transfer of file whatever.crp complete" messages committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Thu, 03 Aug 2006 09:31:14 +0000
parents 6519aeb66b31
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1 /*
13234
f2431a7e33aa [gaim-migrate @ 15600]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
2 * Gaim's oscar protocol plugin
f2431a7e33aa [gaim-migrate @ 15600]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
3 * This file is the legal property of its developers.
f2431a7e33aa [gaim-migrate @ 15600]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
4 * Please see the AUTHORS file distributed alongside this file.
f2431a7e33aa [gaim-migrate @ 15600]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
5 *
f2431a7e33aa [gaim-migrate @ 15600]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
6 * This library is free software; you can redistribute it and/or
f2431a7e33aa [gaim-migrate @ 15600]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
f2431a7e33aa [gaim-migrate @ 15600]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
8 * License as published by the Free Software Foundation; either
f2431a7e33aa [gaim-migrate @ 15600]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
9 * version 2 of the License, or (at your option) any later version.
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
10 *
13234
f2431a7e33aa [gaim-migrate @ 15600]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
11 * This library is distributed in the hope that it will be useful,
f2431a7e33aa [gaim-migrate @ 15600]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f2431a7e33aa [gaim-migrate @ 15600]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f2431a7e33aa [gaim-migrate @ 15600]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
14 * Lesser General Public License for more details.
f2431a7e33aa [gaim-migrate @ 15600]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
15 *
f2431a7e33aa [gaim-migrate @ 15600]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
f2431a7e33aa [gaim-migrate @ 15600]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
17 * License along with this library; if not, write to the Free Software
f2431a7e33aa [gaim-migrate @ 15600]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
f2431a7e33aa [gaim-migrate @ 15600]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
19 */
f2431a7e33aa [gaim-migrate @ 15600]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
20
f2431a7e33aa [gaim-migrate @ 15600]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
21 /*
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
22 * This file contains all functions needed to use bstreams.
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
23 */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
24
13234
f2431a7e33aa [gaim-migrate @ 15600]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
25 #include "oscar.h"
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
26
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
27 int byte_stream_init(ByteStream *bs, guint8 *data, int len)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
28 {
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
29
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
30 if (!bs)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
31 return -1;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
32
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
33 bs->data = data;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
34 bs->len = len;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
35 bs->offset = 0;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
36
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
37 return 0;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
38 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
39
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
40 int byte_stream_empty(ByteStream *bs)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
41 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
42 return bs->len - bs->offset;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
43 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
44
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
45 int byte_stream_curpos(ByteStream *bs)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
46 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
47 return bs->offset;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
48 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
49
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
50 int byte_stream_setpos(ByteStream *bs, unsigned int off)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
51 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
52
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
53 if (off > bs->len)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
54 return -1;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
55
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
56 bs->offset = off;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
57
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
58 return off;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
59 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
60
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
61 void byte_stream_rewind(ByteStream *bs)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
62 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
63
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
64 byte_stream_setpos(bs, 0);
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
65
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
66 return;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
67 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
68
10595
de34037a02c7 [gaim-migrate @ 12010]
Mark Doliner <mark@kingant.net>
parents: 10464
diff changeset
69 /*
de34037a02c7 [gaim-migrate @ 12010]
Mark Doliner <mark@kingant.net>
parents: 10464
diff changeset
70 * N can be negative, which can be used for going backwards
de34037a02c7 [gaim-migrate @ 12010]
Mark Doliner <mark@kingant.net>
parents: 10464
diff changeset
71 * in a bstream. I'm not sure if libfaim actually does
de34037a02c7 [gaim-migrate @ 12010]
Mark Doliner <mark@kingant.net>
parents: 10464
diff changeset
72 * this anywhere...
de34037a02c7 [gaim-migrate @ 12010]
Mark Doliner <mark@kingant.net>
parents: 10464
diff changeset
73 */
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
74 int byte_stream_advance(ByteStream *bs, int n)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
75 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
76
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
77 if ((byte_stream_curpos(bs) + n < 0) || (byte_stream_empty(bs) < n))
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
78 return 0; /* XXX throw an exception */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
79
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
80 bs->offset += n;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
81
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
82 return n;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
83 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
84
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
85 guint8 byte_stream_get8(ByteStream *bs)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
86 {
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
87
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
88 if (byte_stream_empty(bs) < 1)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
89 return 0; /* XXX throw an exception */
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
90
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
91 bs->offset++;
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
92
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
93 return aimutil_get8(bs->data + bs->offset - 1);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
94 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
95
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
96 guint16 byte_stream_get16(ByteStream *bs)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
97 {
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
98
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
99 if (byte_stream_empty(bs) < 2)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
100 return 0; /* XXX throw an exception */
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
101
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
102 bs->offset += 2;
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
103
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
104 return aimutil_get16(bs->data + bs->offset - 2);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
105 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
106
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
107 guint32 byte_stream_get32(ByteStream *bs)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
108 {
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
109
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
110 if (byte_stream_empty(bs) < 4)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
111 return 0; /* XXX throw an exception */
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
112
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
113 bs->offset += 4;
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
114
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
115 return aimutil_get32(bs->data + bs->offset - 4);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
116 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
117
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
118 guint8 byte_stream_getle8(ByteStream *bs)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
119 {
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
120
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
121 if (byte_stream_empty(bs) < 1)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
122 return 0; /* XXX throw an exception */
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
123
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
124 bs->offset++;
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
125
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
126 return aimutil_getle8(bs->data + bs->offset - 1);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
127 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
128
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
129 guint16 byte_stream_getle16(ByteStream *bs)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
130 {
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
131
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
132 if (byte_stream_empty(bs) < 2)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
133 return 0; /* XXX throw an exception */
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
134
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
135 bs->offset += 2;
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
136
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
137 return aimutil_getle16(bs->data + bs->offset - 2);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
138 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
139
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
140 guint32 byte_stream_getle32(ByteStream *bs)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
141 {
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
142
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
143 if (byte_stream_empty(bs) < 4)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
144 return 0; /* XXX throw an exception */
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
145
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
146 bs->offset += 4;
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
147
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
148 return aimutil_getle32(bs->data + bs->offset - 4);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
149 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
150
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
151 int byte_stream_getrawbuf(ByteStream *bs, guint8 *buf, int len)
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
152 {
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
153
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
154 if (byte_stream_empty(bs) < len)
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
155 return 0;
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
156
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
157 memcpy(buf, bs->data + bs->offset, len);
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
158 bs->offset += len;
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
159
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
160 return len;
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
161 }
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
162
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
163 guint8 *byte_stream_getraw(ByteStream *bs, int len)
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
164 {
13234
f2431a7e33aa [gaim-migrate @ 15600]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
165 guint8 *ob;
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
166
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
167 ob = malloc(len);
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
168
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
169 if (byte_stream_getrawbuf(bs, ob, len) < len) {
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
170 free(ob);
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
171 return NULL;
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
172 }
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
173
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
174 return ob;
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
175 }
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
176
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
177 char *byte_stream_getstr(ByteStream *bs, int len)
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
178 {
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
179 char *ob;
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
180
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
181 ob = malloc(len + 1);
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
182
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
183 if (byte_stream_getrawbuf(bs, (guint8 *)ob, len) < len) {
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
184 free(ob);
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
185 return NULL;
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
186 }
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
187
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
188 ob[len] = '\0';
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
189
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
190 return ob;
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
191 }
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
192
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
193 int byte_stream_put8(ByteStream *bs, guint8 v)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
194 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
195
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
196 if (byte_stream_empty(bs) < 1)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
197 return 0; /* XXX throw an exception */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
198
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
199 bs->offset += aimutil_put8(bs->data + bs->offset, v);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
200
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
201 return 1;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
202 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
203
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
204 int byte_stream_put16(ByteStream *bs, guint16 v)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
205 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
206
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
207 if (byte_stream_empty(bs) < 2)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
208 return 0; /* XXX throw an exception */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
209
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
210 bs->offset += aimutil_put16(bs->data + bs->offset, v);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
211
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
212 return 2;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
213 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
214
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
215 int byte_stream_put32(ByteStream *bs, guint32 v)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
216 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
217
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
218 if (byte_stream_empty(bs) < 4)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
219 return 0; /* XXX throw an exception */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
220
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
221 bs->offset += aimutil_put32(bs->data + bs->offset, v);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
222
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
223 return 1;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
224 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
225
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
226 int byte_stream_putle8(ByteStream *bs, guint8 v)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
227 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
228
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
229 if (byte_stream_empty(bs) < 1)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
230 return 0; /* XXX throw an exception */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
231
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
232 bs->offset += aimutil_putle8(bs->data + bs->offset, v);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
233
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
234 return 1;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
235 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
236
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
237 int byte_stream_putle16(ByteStream *bs, guint16 v)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
238 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
239
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
240 if (byte_stream_empty(bs) < 2)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
241 return 0; /* XXX throw an exception */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
242
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
243 bs->offset += aimutil_putle16(bs->data + bs->offset, v);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
244
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
245 return 2;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
246 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
247
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
248 int byte_stream_putle32(ByteStream *bs, guint32 v)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
249 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
250
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
251 if (byte_stream_empty(bs) < 4)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
252 return 0; /* XXX throw an exception */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
253
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
254 bs->offset += aimutil_putle32(bs->data + bs->offset, v);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
255
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
256 return 1;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
257 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
258
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
259
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
260 int byte_stream_putraw(ByteStream *bs, const guint8 *v, int len)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
261 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
262
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
263 if (byte_stream_empty(bs) < len)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
264 return 0; /* XXX throw an exception */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
265
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
266 memcpy(bs->data + bs->offset, v, len);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
267 bs->offset += len;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
268
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
269 return len;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
270 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
271
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
272 int byte_stream_putstr(ByteStream *bs, const char *str)
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
273 {
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
274 return byte_stream_putraw(bs, (guint8 *)str, strlen(str));
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
275 }
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
276
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
277 int byte_stream_putbs(ByteStream *bs, ByteStream *srcbs, int len)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
278 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
279
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
280 if (byte_stream_empty(srcbs) < len)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
281 return 0; /* XXX throw exception (underrun) */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
282
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents: 13239
diff changeset
283 if (byte_stream_empty(bs) < len)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
284 return 0; /* XXX throw exception (overflow) */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
285
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
286 memcpy(bs->data + bs->offset, srcbs->data + srcbs->offset, len);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
287 bs->offset += len;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
288 srcbs->offset += len;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
289
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
290 return len;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
291 }