rename accountopt.[ch] to purpleaccountoption.[ch]
[pidgin-git.git] / libpurple / protocols / oscar / misc.c
blobed6b569914f1c705abe7aec29e6cc86ac7093dc3
1 /*
2 * Purple's oscar protocol plugin
3 * This file is the legal property of its developers.
4 * Please see the AUTHORS file distributed alongside this file.
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 * Random stuff. Basically just a few functions for sending
23 * simple SNACs, and then the generic error handler.
26 #include "oscar.h"
29 * Generic routine for sending commands.
31 * I know I can do this in a smarter way...but I'm not thinking straight
32 * right now...
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.
39 void
40 aim_genericreq_n(OscarData *od, FlapConnection *conn, guint16 family, guint16 subtype)
42 aim_snacid_t snacid = 0x00000000;
44 flap_connection_send_snac(od, conn, family, subtype, snacid, NULL);
47 void
48 aim_genericreq_n_snacid(OscarData *od, FlapConnection *conn, guint16 family, guint16 subtype)
50 aim_snacid_t snacid;
52 snacid = aim_cachesnac(od, family, subtype, 0x0000, NULL, 0);
54 flap_connection_send_snac(od, conn, family, subtype, snacid, NULL);
57 void
58 aim_genericreq_l(OscarData *od, FlapConnection *conn, guint16 family, guint16 subtype, guint32 *longdata)
60 ByteStream bs;
61 aim_snacid_t snacid;
63 if (!longdata)
65 aim_genericreq_n(od, conn, family, subtype);
66 return;
69 byte_stream_new(&bs, 4);
71 snacid = aim_cachesnac(od, family, subtype, 0x0000, NULL, 0);
73 byte_stream_put32(&bs, *longdata);
75 flap_connection_send_snac(od, conn, family, subtype, snacid, &bs);
77 byte_stream_destroy(&bs);
81 * Should be generic enough to handle the errors for all groups.
84 static int
85 generror(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
87 int ret = 0;
88 int error = 0;
89 aim_rxcallback_t userfunc;
90 aim_snac_t *snac2;
92 snac2 = aim_remsnac(od, snac->id);
94 if (byte_stream_bytes_left(bs))
95 error = byte_stream_get16(bs);
97 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
98 ret = userfunc(od, conn, frame, error, snac2 ? snac2->data : NULL);
100 if (snac2) {
101 g_free(snac2->data);
102 g_free(snac2);
105 return ret;
108 static int
109 snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
111 if (snac->subtype == 0x0001)
112 return generror(od, conn, mod, frame, snac, bs);
113 else if ((snac->family == 0xffff) && (snac->subtype == 0xffff)) {
114 aim_rxcallback_t userfunc;
116 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
117 return userfunc(od, conn, frame);
120 return 0;
124 misc_modfirst(OscarData *od, aim_module_t *mod)
126 mod->family = 0xffff;
127 mod->version = 0x0000;
128 mod->flags = AIM_MODFLAG_MULTIFAMILY;
129 strncpy(mod->name, "misc", sizeof(mod->name));
130 mod->snachandler = snachandler;
132 return 0;