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 */
|
15086
|
39 void
|
14192
|
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
|
|
52 void
|
|
53 aim_genericreq_n_snacid(OscarData *od, FlapConnection *conn, guint16 family, guint16 subtype)
|
|
54 {
|
|
55 FlapFrame *frame;
|
|
56 aim_snacid_t snacid;
|
|
57
|
|
58 frame = flap_frame_new(od, 0x02, 10);
|
|
59
|
|
60 snacid = aim_cachesnac(od, family, subtype, 0x0000, NULL, 0);
|
|
61 aim_putsnac(&frame->data, family, subtype, 0x0000, snacid);
|
|
62
|
|
63 flap_connection_send(conn, frame);
|
|
64 }
|
|
65
|
15086
|
66 void
|
14192
|
67 aim_genericreq_l(OscarData *od, FlapConnection *conn, guint16 family, guint16 subtype, guint32 *longdata)
|
|
68 {
|
|
69 FlapFrame *frame;
|
|
70 aim_snacid_t snacid;
|
|
71
|
|
72 if (!longdata)
|
|
73 return aim_genericreq_n(od, conn, family, subtype);
|
|
74
|
|
75 frame = flap_frame_new(od, 0x02, 10+4);
|
|
76
|
|
77 snacid = aim_cachesnac(od, family, subtype, 0x0000, NULL, 0);
|
|
78
|
|
79 aim_putsnac(&frame->data, family, subtype, 0x0000, snacid);
|
|
80 byte_stream_put32(&frame->data, *longdata);
|
|
81
|
|
82 flap_connection_send(conn, frame);
|
|
83 }
|
|
84
|
15086
|
85 void
|
14192
|
86 aim_genericreq_s(OscarData *od, FlapConnection *conn, guint16 family, guint16 subtype, guint16 *shortdata)
|
|
87 {
|
|
88 FlapFrame *frame;
|
|
89 aim_snacid_t snacid;
|
|
90
|
|
91 if (!shortdata)
|
|
92 return aim_genericreq_n(od, conn, family, subtype);
|
|
93
|
|
94 frame = flap_frame_new(od, 0x02, 10+2);
|
|
95
|
|
96 snacid = aim_cachesnac(od, family, subtype, 0x0000, NULL, 0);
|
|
97
|
|
98 aim_putsnac(&frame->data, family, subtype, 0x0000, snacid);
|
|
99 byte_stream_put16(&frame->data, *shortdata);
|
|
100
|
|
101 flap_connection_send(conn, frame);
|
|
102 }
|
|
103
|
|
104 /*
|
|
105 * Should be generic enough to handle the errors for all groups.
|
|
106 *
|
|
107 */
|
|
108 static int
|
|
109 generror(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
|
|
110 {
|
|
111 int ret = 0;
|
|
112 int error = 0;
|
|
113 aim_rxcallback_t userfunc;
|
|
114 aim_snac_t *snac2;
|
|
115
|
|
116 snac2 = aim_remsnac(od, snac->id);
|
|
117
|
|
118 if (byte_stream_empty(bs))
|
|
119 error = byte_stream_get16(bs);
|
|
120
|
|
121 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
|
|
122 ret = userfunc(od, conn, frame, error, snac2 ? snac2->data : NULL);
|
|
123
|
|
124 if (snac2)
|
|
125 free(snac2->data);
|
|
126 free(snac2);
|
|
127
|
|
128 return ret;
|
|
129 }
|
|
130
|
|
131 static int
|
|
132 snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
|
|
133 {
|
|
134 if (snac->subtype == 0x0001)
|
|
135 return generror(od, conn, mod, frame, snac, bs);
|
|
136 else if ((snac->family == 0xffff) && (snac->subtype == 0xffff)) {
|
|
137 aim_rxcallback_t userfunc;
|
|
138
|
|
139 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
|
|
140 return userfunc(od, conn, frame);
|
|
141 }
|
|
142
|
|
143 return 0;
|
|
144 }
|
|
145
|
|
146 int
|
|
147 misc_modfirst(OscarData *od, aim_module_t *mod)
|
|
148 {
|
|
149 mod->family = 0xffff;
|
|
150 mod->version = 0x0000;
|
|
151 mod->flags = AIM_MODFLAG_MULTIFAMILY;
|
|
152 strncpy(mod->name, "misc", sizeof(mod->name));
|
|
153 mod->snachandler = snachandler;
|
|
154
|
|
155 return 0;
|
|
156 }
|