14192
|
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
|
|
21 /*
|
|
22 * Random stuff. Basically just a few functions for sending
|
|
23 * simple SNACs, and then the generic error handler.
|
|
24 */
|
|
25
|
|
26 #include "oscar.h"
|
|
27
|
|
28 /*
|
|
29 * Generic routine for sending commands.
|
|
30 *
|
|
31 * I know I can do this in a smarter way...but I'm not thinking straight
|
|
32 * right now...
|
|
33 *
|
|
34 * I had one big function that handled all three cases, but then it broke
|
|
35 * and I split it up into three. But then I fixed it. I just never went
|
|
36 * back to the single. I don't see any advantage to doing it either way.
|
|
37 *
|
|
38 */
|
|
39 int
|
|
40 aim_genericreq_n(OscarData *od, FlapConnection *conn, guint16 family, guint16 subtype)
|
|
41 {
|
|
42 FlapFrame *frame;
|
|
43 aim_snacid_t snacid = 0x00000000;
|
|
44
|
|
45 frame = flap_frame_new(od, 0x02, 10);
|
|
46
|
|
47 aim_putsnac(&frame->data, family, subtype, 0x0000, snacid);
|
|
48
|
|
49 flap_connection_send(conn, frame);
|
|
50
|
|
51 return 0;
|
|
52 }
|
|
53
|
|
54 void
|
|
55 aim_genericreq_n_snacid(OscarData *od, FlapConnection *conn, guint16 family, guint16 subtype)
|
|
56 {
|
|
57 FlapFrame *frame;
|
|
58 aim_snacid_t snacid;
|
|
59
|
|
60 frame = flap_frame_new(od, 0x02, 10);
|
|
61
|
|
62 snacid = aim_cachesnac(od, family, subtype, 0x0000, NULL, 0);
|
|
63 aim_putsnac(&frame->data, family, subtype, 0x0000, snacid);
|
|
64
|
|
65 flap_connection_send(conn, frame);
|
|
66 }
|
|
67
|
|
68 int
|
|
69 aim_genericreq_l(OscarData *od, FlapConnection *conn, guint16 family, guint16 subtype, guint32 *longdata)
|
|
70 {
|
|
71 FlapFrame *frame;
|
|
72 aim_snacid_t snacid;
|
|
73
|
|
74 if (!longdata)
|
|
75 return aim_genericreq_n(od, conn, family, subtype);
|
|
76
|
|
77 frame = flap_frame_new(od, 0x02, 10+4);
|
|
78
|
|
79 snacid = aim_cachesnac(od, family, subtype, 0x0000, NULL, 0);
|
|
80
|
|
81 aim_putsnac(&frame->data, family, subtype, 0x0000, snacid);
|
|
82 byte_stream_put32(&frame->data, *longdata);
|
|
83
|
|
84 flap_connection_send(conn, frame);
|
|
85
|
|
86 return 0;
|
|
87 }
|
|
88
|
|
89 int
|
|
90 aim_genericreq_s(OscarData *od, FlapConnection *conn, guint16 family, guint16 subtype, guint16 *shortdata)
|
|
91 {
|
|
92 FlapFrame *frame;
|
|
93 aim_snacid_t snacid;
|
|
94
|
|
95 if (!shortdata)
|
|
96 return aim_genericreq_n(od, conn, family, subtype);
|
|
97
|
|
98 frame = flap_frame_new(od, 0x02, 10+2);
|
|
99
|
|
100 snacid = aim_cachesnac(od, family, subtype, 0x0000, NULL, 0);
|
|
101
|
|
102 aim_putsnac(&frame->data, family, subtype, 0x0000, snacid);
|
|
103 byte_stream_put16(&frame->data, *shortdata);
|
|
104
|
|
105 flap_connection_send(conn, frame);
|
|
106
|
|
107 return 0;
|
|
108 }
|
|
109
|
|
110 /*
|
|
111 * Should be generic enough to handle the errors for all groups.
|
|
112 *
|
|
113 */
|
|
114 static int
|
|
115 generror(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
|
|
116 {
|
|
117 int ret = 0;
|
|
118 int error = 0;
|
|
119 aim_rxcallback_t userfunc;
|
|
120 aim_snac_t *snac2;
|
|
121
|
|
122 snac2 = aim_remsnac(od, snac->id);
|
|
123
|
|
124 if (byte_stream_empty(bs))
|
|
125 error = byte_stream_get16(bs);
|
|
126
|
|
127 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
|
|
128 ret = userfunc(od, conn, frame, error, snac2 ? snac2->data : NULL);
|
|
129
|
|
130 if (snac2)
|
|
131 free(snac2->data);
|
|
132 free(snac2);
|
|
133
|
|
134 return ret;
|
|
135 }
|
|
136
|
|
137 static int
|
|
138 snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
|
|
139 {
|
|
140 if (snac->subtype == 0x0001)
|
|
141 return generror(od, conn, mod, frame, snac, bs);
|
|
142 else if ((snac->family == 0xffff) && (snac->subtype == 0xffff)) {
|
|
143 aim_rxcallback_t userfunc;
|
|
144
|
|
145 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
|
|
146 return userfunc(od, conn, frame);
|
|
147 }
|
|
148
|
|
149 return 0;
|
|
150 }
|
|
151
|
|
152 int
|
|
153 misc_modfirst(OscarData *od, aim_module_t *mod)
|
|
154 {
|
|
155 mod->family = 0xffff;
|
|
156 mod->version = 0x0000;
|
|
157 mod->flags = AIM_MODFLAG_MULTIFAMILY;
|
|
158 strncpy(mod->name, "misc", sizeof(mod->name));
|
|
159 mod->snachandler = snachandler;
|
|
160
|
|
161 return 0;
|
|
162 }
|