annotate src/protocols/oscar/bstream.c @ 12756:6ef1cdc26b40

[gaim-migrate @ 15103] Cleanup to STUN code. Fixed endianness. Fixed to work where sizeof(short) != 2 or sizeof(int) != 4. Close the socket when we're done with it. Instead of using a bunch of static variables, pass data around the various callbacks. Don't invoke the specified StunCallback before the initial function has returned. Deal with requerying if the STUN server has changed since last query, or the last query was unsuccessful and 5 minutes have elapsed. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Sat, 07 Jan 2006 22:10:18 +0000
parents b6ca6d3c5332
children f2431a7e33aa
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
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
8 #include <aim.h>
3952
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 {
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
12
3952
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
7631
ea2d07ad05a9 [gaim-migrate @ 8255]
Nathan Walp <nwalp@pidgin.im>
parents: 4642
diff changeset
33 faim_internal int aim_bstream_setpos(aim_bstream_t *bs, unsigned int off)
3952
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
10595
de34037a02c7 [gaim-migrate @ 12010]
Mark Doliner <mark@kingant.net>
parents: 10464
diff changeset
52 /*
de34037a02c7 [gaim-migrate @ 12010]
Mark Doliner <mark@kingant.net>
parents: 10464
diff changeset
53 * N can be negative, which can be used for going backwards
de34037a02c7 [gaim-migrate @ 12010]
Mark Doliner <mark@kingant.net>
parents: 10464
diff changeset
54 * in a bstream. I'm not sure if libfaim actually does
de34037a02c7 [gaim-migrate @ 12010]
Mark Doliner <mark@kingant.net>
parents: 10464
diff changeset
55 * this anywhere...
de34037a02c7 [gaim-migrate @ 12010]
Mark Doliner <mark@kingant.net>
parents: 10464
diff changeset
56 */
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
57 faim_internal int aim_bstream_advance(aim_bstream_t *bs, int n)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
58 {
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
59
10595
de34037a02c7 [gaim-migrate @ 12010]
Mark Doliner <mark@kingant.net>
parents: 10464
diff changeset
60 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
61 return 0; /* XXX throw an exception */
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 bs->offset += n;
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 return n;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
66 }
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 faim_internal fu8_t aimbs_get8(aim_bstream_t *bs)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
69 {
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
70
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
71 if (aim_bstream_empty(bs) < 1)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
72 return 0; /* XXX throw an exception */
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
73
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
74 bs->offset++;
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
75
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
76 return aimutil_get8(bs->data + bs->offset - 1);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
77 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
78
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
79 faim_internal fu16_t aimbs_get16(aim_bstream_t *bs)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
80 {
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
81
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
82 if (aim_bstream_empty(bs) < 2)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
83 return 0; /* XXX throw an exception */
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
84
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
85 bs->offset += 2;
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
86
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
87 return aimutil_get16(bs->data + bs->offset - 2);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
88 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
89
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
90 faim_internal fu32_t aimbs_get32(aim_bstream_t *bs)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
91 {
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 if (aim_bstream_empty(bs) < 4)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
94 return 0; /* XXX throw an exception */
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
95
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
96 bs->offset += 4;
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
97
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
98 return aimutil_get32(bs->data + bs->offset - 4);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
99 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
100
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
101 faim_internal fu8_t aimbs_getle8(aim_bstream_t *bs)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
102 {
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 if (aim_bstream_empty(bs) < 1)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
105 return 0; /* XXX throw an exception */
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
106
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
107 bs->offset++;
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
108
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
109 return aimutil_getle8(bs->data + bs->offset - 1);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
110 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
111
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
112 faim_internal fu16_t aimbs_getle16(aim_bstream_t *bs)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
113 {
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 if (aim_bstream_empty(bs) < 2)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
116 return 0; /* XXX throw an exception */
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
117
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
118 bs->offset += 2;
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
119
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
120 return aimutil_getle16(bs->data + bs->offset - 2);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
121 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
122
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
123 faim_internal fu32_t aimbs_getle32(aim_bstream_t *bs)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
124 {
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 if (aim_bstream_empty(bs) < 4)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
127 return 0; /* XXX throw an exception */
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
128
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
129 bs->offset += 4;
10464
61ef9a964574 [gaim-migrate @ 11739]
Mark Doliner <mark@kingant.net>
parents: 7631
diff changeset
130
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
131 return aimutil_getle32(bs->data + bs->offset - 4);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
132 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
133
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
134 faim_internal int aimbs_getrawbuf(aim_bstream_t *bs, fu8_t *buf, int len)
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
135 {
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
136
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
137 if (aim_bstream_empty(bs) < len)
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
138 return 0;
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
139
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
140 memcpy(buf, bs->data + bs->offset, len);
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
141 bs->offset += len;
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
142
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
143 return len;
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
144 }
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
145
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
146 faim_internal fu8_t *aimbs_getraw(aim_bstream_t *bs, int len)
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
147 {
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
148 fu8_t *ob;
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
149
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
150 if (!(ob = malloc(len)))
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
151 return NULL;
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 if (aimbs_getrawbuf(bs, ob, len) < len) {
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
154 free(ob);
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
155 return NULL;
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
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
158 return ob;
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
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
161 faim_internal char *aimbs_getstr(aim_bstream_t *bs, int len)
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
162 {
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
163 char *ob;
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
164
10993
b6ca6d3c5332 [gaim-migrate @ 12831]
Mark Doliner <mark@kingant.net>
parents: 10990
diff changeset
165 if (!(ob = malloc(len + 1)))
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
166 return NULL;
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
167
10993
b6ca6d3c5332 [gaim-migrate @ 12831]
Mark Doliner <mark@kingant.net>
parents: 10990
diff changeset
168 if (aimbs_getrawbuf(bs, (fu8_t *)ob, len) < len) {
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
169 free(ob);
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
170 return NULL;
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
171 }
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 ob[len] = '\0';
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
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
178 faim_internal int aimbs_put8(aim_bstream_t *bs, fu8_t v)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
179 {
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 if (aim_bstream_empty(bs) < 1)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
182 return 0; /* XXX throw an exception */
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 bs->offset += aimutil_put8(bs->data + bs->offset, 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 return 1;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
187 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
188
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
189 faim_internal int aimbs_put16(aim_bstream_t *bs, fu16_t v)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
190 {
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 if (aim_bstream_empty(bs) < 2)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
193 return 0; /* XXX throw an exception */
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 bs->offset += aimutil_put16(bs->data + bs->offset, v);
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 return 2;
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
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
200 faim_internal int aimbs_put32(aim_bstream_t *bs, fu32_t v)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
201 {
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 if (aim_bstream_empty(bs) < 4)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
204 return 0; /* XXX throw an exception */
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 bs->offset += aimutil_put32(bs->data + bs->offset, v);
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 return 1;
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
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
211 faim_internal int aimbs_putle8(aim_bstream_t *bs, fu8_t v)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
212 {
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 (aim_bstream_empty(bs) < 1)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
215 return 0; /* XXX throw an exception */
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 bs->offset += aimutil_putle8(bs->data + bs->offset, v);
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 1;
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 int aimbs_putle16(aim_bstream_t *bs, fu16_t v)
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
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
225 if (aim_bstream_empty(bs) < 2)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
226 return 0; /* XXX throw an exception */
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 bs->offset += aimutil_putle16(bs->data + bs->offset, v);
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 return 2;
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
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
233 faim_internal int aimbs_putle32(aim_bstream_t *bs, fu32_t v)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
234 {
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 if (aim_bstream_empty(bs) < 4)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
237 return 0; /* XXX throw an exception */
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 bs->offset += aimutil_putle32(bs->data + bs->offset, v);
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 return 1;
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
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 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
246 {
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 if (aim_bstream_empty(bs) < len)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
249 return 0; /* XXX throw an exception */
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 memcpy(bs->data + bs->offset, v, len);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
252 bs->offset += len;
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 return len;
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
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
257 faim_internal int aimbs_putstr(aim_bstream_t *bs, const char *str)
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
258 {
10993
b6ca6d3c5332 [gaim-migrate @ 12831]
Mark Doliner <mark@kingant.net>
parents: 10990
diff changeset
259 return aimbs_putraw(bs, (fu8_t *)str, strlen(str));
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
260 }
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10595
diff changeset
261
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
262 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
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(srcbs) < len)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
266 return 0; /* XXX throw exception (underrun) */
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 if (aim_bstream_empty(bs) < len)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
269 return 0; /* XXX throw exception (overflow) */
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 memcpy(bs->data + bs->offset, srcbs->data + srcbs->offset, len);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
272 bs->offset += len;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
273 srcbs->offset += len;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
274
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
275 return len;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
276 }