Mercurial > pidgin
annotate src/protocols/oscar/misc.c @ 13254:e9802db22b06
[gaim-migrate @ 15620]
This is the way we clean the code, clean the code, clean the code
This is the way we clean the code, clean the code, clean the code
So early in the morning
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 12 Feb 2006 22:14:38 +0000 |
parents | 87a7c3077c19 |
children | 6519aeb66b31 |
rev | line source |
---|---|
13234 | 1 /* |
2 * Gaim's oscar protocol plugin | |
3 * This file is the legal property of its developers. | |
4 * Please see the AUTHORS file distributed alongside this file. | |
5 * | |
6 * This library is free software; you can redistribute it and/or | |
7 * modify it under the terms of the GNU Lesser General Public | |
8 * License as published by the Free Software Foundation; either | |
9 * version 2 of the License, or (at your option) any later version. | |
10 * | |
11 * This library is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * Lesser General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU Lesser General Public | |
17 * License along with this library; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 */ | |
20 | |
2086 | 21 /* |
3952 | 22 * misc.c |
2086 | 23 * |
13234 | 24 * Random stuff. Basically just a few functions for sending |
3952 | 25 * simple SNACs, and then the generic error handler. |
2086 | 26 * |
27 */ | |
28 | |
13234 | 29 #include "oscar.h" |
2086 | 30 |
31 /* | |
32 * Generic routine for sending commands. | |
33 * | |
34 * I know I can do this in a smarter way...but I'm not thinking straight | |
35 * right now... | |
36 * | |
37 * I had one big function that handled all three cases, but then it broke | |
38 * and I split it up into three. But then I fixed it. I just never went | |
39 * back to the single. I don't see any advantage to doing it either way. | |
40 * | |
41 */ | |
13239 | 42 faim_internal int aim_genericreq_n(OscarSession *sess, OscarConnection *conn, guint16 family, guint16 subtype) |
2086 | 43 { |
13239 | 44 FlapFrame *fr; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
45 aim_snacid_t snacid = 0x00000000; |
2086 | 46 |
13253 | 47 if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10))) |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
48 return -ENOMEM; |
2086 | 49 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
50 aim_putsnac(&fr->data, family, subtype, 0x0000, snacid); |
2086 | 51 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
52 aim_tx_enqueue(sess, fr); |
2086 | 53 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
54 return 0; |
2086 | 55 } |
56 | |
13239 | 57 faim_internal int aim_genericreq_n_snacid(OscarSession *sess, OscarConnection *conn, guint16 family, guint16 subtype) |
2086 | 58 { |
13239 | 59 FlapFrame *fr; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
60 aim_snacid_t snacid; |
2086 | 61 |
13253 | 62 if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10))) |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
63 return -ENOMEM; |
2086 | 64 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
65 snacid = aim_cachesnac(sess, family, subtype, 0x0000, NULL, 0); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
66 aim_putsnac(&fr->data, family, subtype, 0x0000, snacid); |
2086 | 67 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
68 aim_tx_enqueue(sess, fr); |
2086 | 69 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
70 return 0; |
2086 | 71 } |
72 | |
13239 | 73 faim_internal int aim_genericreq_l(OscarSession *sess, OscarConnection *conn, guint16 family, guint16 subtype, guint32 *longdata) |
2086 | 74 { |
13239 | 75 FlapFrame *fr; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
76 aim_snacid_t snacid; |
2086 | 77 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
78 if (!longdata) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
79 return aim_genericreq_n(sess, conn, family, subtype); |
2086 | 80 |
13253 | 81 if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+4))) |
13254 | 82 return -ENOMEM; |
2086 | 83 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
84 snacid = aim_cachesnac(sess, family, subtype, 0x0000, NULL, 0); |
2086 | 85 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
86 aim_putsnac(&fr->data, family, subtype, 0x0000, snacid); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
87 aimbs_put32(&fr->data, *longdata); |
2086 | 88 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
89 aim_tx_enqueue(sess, fr); |
2086 | 90 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
91 return 0; |
2086 | 92 } |
93 | |
13239 | 94 faim_internal int aim_genericreq_s(OscarSession *sess, OscarConnection *conn, guint16 family, guint16 subtype, guint16 *shortdata) |
2086 | 95 { |
13239 | 96 FlapFrame *fr; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
97 aim_snacid_t snacid; |
2086 | 98 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
99 if (!shortdata) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
100 return aim_genericreq_n(sess, conn, family, subtype); |
2086 | 101 |
13253 | 102 if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2))) |
13254 | 103 return -ENOMEM; |
2086 | 104 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
105 snacid = aim_cachesnac(sess, family, subtype, 0x0000, NULL, 0); |
2086 | 106 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
107 aim_putsnac(&fr->data, family, subtype, 0x0000, snacid); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
108 aimbs_put16(&fr->data, *shortdata); |
2086 | 109 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
110 aim_tx_enqueue(sess, fr); |
2086 | 111 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
112 return 0; |
2086 | 113 } |
114 | |
115 /* | |
2703
441b84ab7f4e
[gaim-migrate @ 2716]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
116 * Should be generic enough to handle the errors for all groups. |
2086 | 117 * |
118 */ | |
13239 | 119 static int generror(OscarSession *sess, aim_module_t *mod, FlapFrame *rx, aim_modsnac_t *snac, ByteStream *bs) |
2086 | 120 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
121 int ret = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
122 int error = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
123 aim_rxcallback_t userfunc; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
124 aim_snac_t *snac2; |
2086 | 125 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
126 snac2 = aim_remsnac(sess, snac->id); |
2086 | 127 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
128 if (aim_bstream_empty(bs)) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
129 error = aimbs_get16(bs); |
2086 | 130 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
131 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
132 ret = userfunc(sess, rx, error, snac2 ? snac2->data : NULL); |
2086 | 133 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
134 if (snac2) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
135 free(snac2->data); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
136 free(snac2); |
2086 | 137 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
138 return ret; |
2086 | 139 } |
140 | |
13239 | 141 static int snachandler(OscarSession *sess, aim_module_t *mod, FlapFrame *rx, aim_modsnac_t *snac, ByteStream *bs) |
2086 | 142 { |
143 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
144 if (snac->subtype == 0x0001) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
145 return generror(sess, mod, rx, snac, bs); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
146 else if ((snac->family == 0xffff) && (snac->subtype == 0xffff)) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
147 aim_rxcallback_t userfunc; |
2086 | 148 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
149 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
150 return userfunc(sess, rx); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
151 } |
2086 | 152 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
153 return 0; |
2086 | 154 } |
155 | |
13239 | 156 faim_internal int misc_modfirst(OscarSession *sess, aim_module_t *mod) |
2086 | 157 { |
158 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
159 mod->family = 0xffff; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
160 mod->version = 0x0000; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
161 mod->flags = AIM_MODFLAG_MULTIFAMILY; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
162 strncpy(mod->name, "misc", sizeof(mod->name)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
163 mod->snachandler = snachandler; |
2086 | 164 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
165 return 0; |
2086 | 166 } |