Annotation of ChivanetAimPidgin/oscarprpl/src/c/misc.c, revision 1.1
1.1 ! snw 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.
! 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 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: void
! 40: aim_genericreq_n(OscarData *od, FlapConnection *conn, guint16 family, guint16 subtype)
! 41: {
! 42: aim_snacid_t snacid = 0x00000000;
! 43:
! 44: flap_connection_send_snac(od, conn, family, subtype, snacid, NULL);
! 45: }
! 46:
! 47: void
! 48: aim_genericreq_n_snacid(OscarData *od, FlapConnection *conn, guint16 family, guint16 subtype)
! 49: {
! 50: aim_snacid_t snacid;
! 51:
! 52: snacid = aim_cachesnac(od, family, subtype, 0x0000, NULL, 0);
! 53:
! 54: flap_connection_send_snac(od, conn, family, subtype, snacid, NULL);
! 55: }
! 56:
! 57: void
! 58: aim_genericreq_l(OscarData *od, FlapConnection *conn, guint16 family, guint16 subtype, guint32 *longdata)
! 59: {
! 60: ByteStream bs;
! 61: aim_snacid_t snacid;
! 62:
! 63: if (!longdata)
! 64: {
! 65: aim_genericreq_n(od, conn, family, subtype);
! 66: return;
! 67: }
! 68:
! 69: byte_stream_new(&bs, 4);
! 70:
! 71: snacid = aim_cachesnac(od, family, subtype, 0x0000, NULL, 0);
! 72:
! 73: byte_stream_put32(&bs, *longdata);
! 74:
! 75: flap_connection_send_snac(od, conn, family, subtype, snacid, &bs);
! 76:
! 77: byte_stream_destroy(&bs);
! 78: }
! 79:
! 80: /*
! 81: * Should be generic enough to handle the errors for all groups.
! 82: *
! 83: */
! 84: static int
! 85: generror(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
! 86: {
! 87: int ret = 0;
! 88: int error = 0;
! 89: aim_rxcallback_t userfunc;
! 90: aim_snac_t *snac2;
! 91:
! 92: snac2 = aim_remsnac(od, snac->id);
! 93:
! 94: if (byte_stream_bytes_left(bs))
! 95: error = byte_stream_get16(bs);
! 96:
! 97: if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
! 98: ret = userfunc(od, conn, frame, error, snac2 ? snac2->data : NULL);
! 99:
! 100: if (snac2) {
! 101: g_free(snac2->data);
! 102: g_free(snac2);
! 103: }
! 104:
! 105: return ret;
! 106: }
! 107:
! 108: static int
! 109: snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
! 110: {
! 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;
! 115:
! 116: if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
! 117: return userfunc(od, conn, frame);
! 118: }
! 119:
! 120: return 0;
! 121: }
! 122:
! 123: int
! 124: misc_modfirst(OscarData *od, aim_module_t *mod)
! 125: {
! 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;
! 131:
! 132: return 0;
! 133: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>