annotate src/protocols/oscar/bstream.c @ 4878:77b04219f3e2

[gaim-migrate @ 5208] someone please let me know if this sounds better with 8-bit sounds (like the ones that come with winaim) committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Mon, 24 Mar 2003 06:58:25 +0000
parents c0abcd675ca6
children ea2d07ad05a9
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 /*
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
2 * bstream.c
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
3 *
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
4 * This file contains all functions needed to use bstreams.
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
5 */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
6
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
7 #define FAIM_INTERNAL
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
8 #include <aim.h>
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
9
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
10 faim_internal int aim_bstream_init(aim_bstream_t *bs, fu8_t *data, int len)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
11 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
12
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
13 if (!bs)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
14 return -1;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
15
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
16 bs->data = data;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
17 bs->len = len;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
18 bs->offset = 0;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
19
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
20 return 0;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
21 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
22
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
23 faim_internal int aim_bstream_empty(aim_bstream_t *bs)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
24 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
25 return bs->len - bs->offset;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
26 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
27
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
28 faim_internal int aim_bstream_curpos(aim_bstream_t *bs)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
29 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
30 return bs->offset;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
31 }
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 faim_internal int aim_bstream_setpos(aim_bstream_t *bs, int off)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
34 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
35
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
36 if (off > bs->len)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
37 return -1;
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 bs->offset = off;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
40
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
41 return off;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
42 }
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 faim_internal void aim_bstream_rewind(aim_bstream_t *bs)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
45 {
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 aim_bstream_setpos(bs, 0);
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 return;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
50 }
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 faim_internal int aim_bstream_advance(aim_bstream_t *bs, int n)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
53 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
54
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
55 if (aim_bstream_empty(bs) < n)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
56 return 0; /* XXX throw an exception */
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 bs->offset += n;
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 return n;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
61 }
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 faim_internal fu8_t aimbs_get8(aim_bstream_t *bs)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
64 {
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 if (aim_bstream_empty(bs) < 1)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
67 return 0; /* XXX throw an exception */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
68
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
69 bs->offset++;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
70
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
71 return aimutil_get8(bs->data + bs->offset - 1);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
72 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
73
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
74 faim_internal fu16_t aimbs_get16(aim_bstream_t *bs)
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
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
77 if (aim_bstream_empty(bs) < 2)
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 += 2;
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 aimutil_get16(bs->data + bs->offset - 2);
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
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
85 faim_internal fu32_t aimbs_get32(aim_bstream_t *bs)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
86 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
87
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
88 if (aim_bstream_empty(bs) < 4)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
89 return 0; /* XXX throw an exception */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
90
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
91 bs->offset += 4;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
92
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
93 return aimutil_get32(bs->data + bs->offset - 4);
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
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
96 faim_internal fu8_t aimbs_getle8(aim_bstream_t *bs)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
97 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
98
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
99 if (aim_bstream_empty(bs) < 1)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
100 return 0; /* XXX throw an exception */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
101
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
102 bs->offset++;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
103
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
104 return aimutil_getle8(bs->data + bs->offset - 1);
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
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
107 faim_internal fu16_t aimbs_getle16(aim_bstream_t *bs)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
108 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
109
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
110 if (aim_bstream_empty(bs) < 2)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
111 return 0; /* XXX throw an exception */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
112
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
113 bs->offset += 2;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
114
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
115 return aimutil_getle16(bs->data + bs->offset - 2);
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
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
118 faim_internal fu32_t aimbs_getle32(aim_bstream_t *bs)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
119 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
120
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
121 if (aim_bstream_empty(bs) < 4)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
122 return 0; /* XXX throw an exception */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
123
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
124 bs->offset += 4;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
125
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
126 return aimutil_getle32(bs->data + bs->offset - 4);
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
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
129 faim_internal int aimbs_put8(aim_bstream_t *bs, fu8_t v)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
130 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
131
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
132 if (aim_bstream_empty(bs) < 1)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
133 return 0; /* XXX throw an exception */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
134
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
135 bs->offset += aimutil_put8(bs->data + bs->offset, v);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
136
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
137 return 1;
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
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
140 faim_internal int aimbs_put16(aim_bstream_t *bs, fu16_t v)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
141 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
142
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
143 if (aim_bstream_empty(bs) < 2)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
144 return 0; /* XXX throw an exception */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
145
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
146 bs->offset += aimutil_put16(bs->data + bs->offset, v);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
147
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
148 return 2;
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
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
151 faim_internal int aimbs_put32(aim_bstream_t *bs, fu32_t v)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
152 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
153
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
154 if (aim_bstream_empty(bs) < 4)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
155 return 0; /* XXX throw an exception */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
156
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
157 bs->offset += aimutil_put32(bs->data + bs->offset, v);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
158
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
159 return 1;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
160 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
161
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
162 faim_internal int aimbs_putle8(aim_bstream_t *bs, fu8_t v)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
163 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
164
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
165 if (aim_bstream_empty(bs) < 1)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
166 return 0; /* XXX throw an exception */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
167
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
168 bs->offset += aimutil_putle8(bs->data + bs->offset, v);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
169
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
170 return 1;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
171 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
172
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
173 faim_internal int aimbs_putle16(aim_bstream_t *bs, fu16_t v)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
174 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
175
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
176 if (aim_bstream_empty(bs) < 2)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
177 return 0; /* XXX throw an exception */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
178
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
179 bs->offset += aimutil_putle16(bs->data + bs->offset, v);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
180
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
181 return 2;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
182 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
183
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
184 faim_internal int aimbs_putle32(aim_bstream_t *bs, fu32_t v)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
185 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
186
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
187 if (aim_bstream_empty(bs) < 4)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
188 return 0; /* XXX throw an exception */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
189
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
190 bs->offset += aimutil_putle32(bs->data + bs->offset, v);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
191
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
192 return 1;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
193 }
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 faim_internal int aimbs_getrawbuf(aim_bstream_t *bs, fu8_t *buf, int len)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
196 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
197
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
198 if (aim_bstream_empty(bs) < len)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
199 return 0;
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 memcpy(buf, bs->data + bs->offset, len);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
202 bs->offset += len;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
203
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
204 return len;
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
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
207 faim_internal fu8_t *aimbs_getraw(aim_bstream_t *bs, int len)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
208 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
209 fu8_t *ob;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
210
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
211 if (!(ob = malloc(len)))
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
212 return NULL;
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 if (aimbs_getrawbuf(bs, ob, len) < len) {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
215 free(ob);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
216 return NULL;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
217 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
218
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
219 return ob;
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
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
222 faim_internal char *aimbs_getstr(aim_bstream_t *bs, int len)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
223 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
224 char *ob;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
225
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
226 if (!(ob = malloc(len+1)))
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
227 return NULL;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
228
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
229 if (aimbs_getrawbuf(bs, ob, len) < len) {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
230 free(ob);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
231 return NULL;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
232 }
4624
a964972cb361 [gaim-migrate @ 4915]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
233
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
234 ob[len] = '\0';
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
235
4642
c0abcd675ca6 [gaim-migrate @ 4952]
Mark Doliner <mark@kingant.net>
parents: 4641
diff changeset
236 return ob;
c0abcd675ca6 [gaim-migrate @ 4952]
Mark Doliner <mark@kingant.net>
parents: 4641
diff changeset
237 }
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 faim_internal int aimbs_putraw(aim_bstream_t *bs, const fu8_t *v, int len)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
240 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
241
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
242 if (aim_bstream_empty(bs) < len)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
243 return 0; /* XXX throw an exception */
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 memcpy(bs->data + bs->offset, v, len);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
246 bs->offset += len;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
247
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
248 return len;
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
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
251 faim_internal int aimbs_putbs(aim_bstream_t *bs, aim_bstream_t *srcbs, int len)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
252 {
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 if (aim_bstream_empty(srcbs) < len)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
255 return 0; /* XXX throw exception (underrun) */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
256
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
257 if (aim_bstream_empty(bs) < len)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
258 return 0; /* XXX throw exception (overflow) */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
259
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
260 memcpy(bs->data + bs->offset, srcbs->data + srcbs->offset, len);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
261 bs->offset += len;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
262 srcbs->offset += len;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
263
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
264 return len;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
265 }