annotate src/protocols/oscar/bstream.c @ 13434:ffd724befbf8

[gaim-migrate @ 15809] Cleanup the busy cursor handling code to eliminate a bunch of these loops: while (gtk_events_pending()) gtk_main_iteration(); They seem like a race condition waiting to happen. This code is also simpler, and more generic. This leaves only one such loop, in src/gtkblist.c's gaim_gtk_blist_expand_contact_cb(). committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Tue, 07 Mar 2006 05:48:54 +0000
parents f260d319bbbc
children 6519aeb66b31
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
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
27 faim_internal int aim_bstream_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
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
40 faim_internal int aim_bstream_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
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
45 faim_internal int aim_bstream_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
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
50 faim_internal int aim_bstream_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
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
61 faim_internal void aim_bstream_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
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
64 aim_bstream_setpos(bs, 0);
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 */
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
74 faim_internal int aim_bstream_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
10595
de34037a02c7 [gaim-migrate @ 12010]
Mark Doliner <mark@kingant.net>
parents: 10464
diff changeset
77 if ((aim_bstream_curpos(bs) + n < 0) || (aim_bstream_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
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
85 faim_internal guint8 aimbs_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
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
88 if (aim_bstream_empty(bs) < 1)
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
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
96 faim_internal guint16 aimbs_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
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
99 if (aim_bstream_empty(bs) < 2)
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
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
107 faim_internal guint32 aimbs_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
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
110 if (aim_bstream_empty(bs) < 4)
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
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
118 faim_internal guint8 aimbs_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
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
121 if (aim_bstream_empty(bs) < 1)
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
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
129 faim_internal guint16 aimbs_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
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
132 if (aim_bstream_empty(bs) < 2)
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
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
140 faim_internal guint32 aimbs_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
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
143 if (aim_bstream_empty(bs) < 4)
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
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
151 faim_internal int aimbs_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
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
154 if (aim_bstream_empty(bs) < len)
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
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
163 faim_internal guint8 *aimbs_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
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
167 if (!(ob = malloc(len)))
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
168 return NULL;
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
169
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
170 if (aimbs_getrawbuf(bs, ob, len) < len) {
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
171 free(ob);
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
172 return NULL;
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
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
175 return ob;
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
176 }
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
177
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
178 faim_internal char *aimbs_getstr(ByteStream *bs, int len)
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
179 {
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
180 char *ob;
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
181
10993
b6ca6d3c5332 [gaim-migrate @ 12831]
Mark Doliner <mark@kingant.net>
parents: 10990
diff changeset
182 if (!(ob = malloc(len + 1)))
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
183 return NULL;
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
184
13234
f2431a7e33aa [gaim-migrate @ 15600]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
185 if (aimbs_getrawbuf(bs, (guint8 *)ob, len) < len) {
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
186 free(ob);
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
187 return NULL;
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
188 }
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 ob[len] = '\0';
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 return ob;
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
193 }
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
194
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
195 faim_internal int aimbs_put8(ByteStream *bs, guint8 v)
3952
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) < 1)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
199 return 0; /* XXX throw an exception */
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 bs->offset += aimutil_put8(bs->data + bs->offset, v);
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 return 1;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
204 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
205
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
206 faim_internal int aimbs_put16(ByteStream *bs, guint16 v)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
207 {
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 if (aim_bstream_empty(bs) < 2)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
210 return 0; /* XXX throw an exception */
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 bs->offset += aimutil_put16(bs->data + bs->offset, v);
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 return 2;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
215 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
216
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
217 faim_internal int aimbs_put32(ByteStream *bs, guint32 v)
3952
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
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
220 if (aim_bstream_empty(bs) < 4)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
221 return 0; /* XXX throw an exception */
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 bs->offset += aimutil_put32(bs->data + bs->offset, v);
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 return 1;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
226 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
227
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
228 faim_internal int aimbs_putle8(ByteStream *bs, guint8 v)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
229 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
230
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
231 if (aim_bstream_empty(bs) < 1)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
232 return 0; /* XXX throw an exception */
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 bs->offset += aimutil_putle8(bs->data + bs->offset, v);
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 return 1;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
237 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
238
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
239 faim_internal int aimbs_putle16(ByteStream *bs, guint16 v)
3952
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) < 2)
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 bs->offset += aimutil_putle16(bs->data + bs->offset, v);
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 return 2;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
248 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
249
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
250 faim_internal int aimbs_putle32(ByteStream *bs, guint32 v)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
251 {
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 if (aim_bstream_empty(bs) < 4)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
254 return 0; /* XXX throw an exception */
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 bs->offset += aimutil_putle32(bs->data + bs->offset, v);
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 return 1;
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
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
261
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
262 faim_internal int aimbs_putraw(ByteStream *bs, const guint8 *v, int len)
3952
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
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
265 if (aim_bstream_empty(bs) < len)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
266 return 0; /* XXX throw an exception */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
267
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
268 memcpy(bs->data + bs->offset, v, len);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
269 bs->offset += 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 return len;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
272 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
273
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
274 faim_internal int aimbs_putstr(ByteStream *bs, const char *str)
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
275 {
13234
f2431a7e33aa [gaim-migrate @ 15600]
Mark Doliner <mark@kingant.net>
parents: 10993
diff changeset
276 return aimbs_putraw(bs, (guint8 *)str, strlen(str));
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
277 }
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
278
13239
f260d319bbbc [gaim-migrate @ 15605]
Mark Doliner <mark@kingant.net>
parents: 13234
diff changeset
279 faim_internal int aimbs_putbs(ByteStream *bs, ByteStream *srcbs, int len)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
280 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
281
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
282 if (aim_bstream_empty(srcbs) < len)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
283 return 0; /* XXX throw exception (underrun) */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
284
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
285 if (aim_bstream_empty(bs) < len)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
286 return 0; /* XXX throw exception (overflow) */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
287
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
288 memcpy(bs->data + bs->offset, srcbs->data + srcbs->offset, len);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
289 bs->offset += len;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
290 srcbs->offset += len;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
291
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
292 return len;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
293 }