Annotation of ChivanetAimPidgin/oscarprpl/src/c/family_alert.c, revision 1.1.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:  * Family 0x0018 - Email notification
                     23:  *
                     24:  * Used for being alerted when the email address(es) associated with
                     25:  * your username get new electronic-m.  For normal AIM accounts, you
                     26:  * get the email address username@netscape.net.  AOL accounts have
                     27:  * username@aol.com, and can also activate a netscape.net account.
                     28:  * Note: This information might be out of date.
                     29:  */
                     30: 
                     31: #include "oscar.h"
                     32: 
                     33: /**
                     34:  * Subtype 0x0006 - Request information about your email account
                     35:  *
                     36:  * @param od The oscar session.
                     37:  * @param conn The email connection for this session.
                     38:  * @return Return 0 if no errors, otherwise return the error number.
                     39:  */
                     40: int
                     41: aim_email_sendcookies(OscarData *od)
                     42: {
                     43:        FlapConnection *conn;
                     44:        ByteStream bs;
                     45:        aim_snacid_t snacid;
                     46: 
                     47:        if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_ALERT)))
                     48:                return -EINVAL;
                     49: 
                     50:        byte_stream_new(&bs, 2+16+16);
                     51: 
                     52:        /* Number of cookies to follow */
                     53:        byte_stream_put16(&bs, 0x0002);
                     54: 
                     55:        /* Cookie */
                     56:        byte_stream_put16(&bs, 0x5d5e);
                     57:        byte_stream_put16(&bs, 0x1708);
                     58:        byte_stream_put16(&bs, 0x55aa);
                     59:        byte_stream_put16(&bs, 0x11d3);
                     60:        byte_stream_put16(&bs, 0xb143);
                     61:        byte_stream_put16(&bs, 0x0060);
                     62:        byte_stream_put16(&bs, 0xb0fb);
                     63:        byte_stream_put16(&bs, 0x1ecb);
                     64: 
                     65:        /* Cookie */
                     66:        byte_stream_put16(&bs, 0xb380);
                     67:        byte_stream_put16(&bs, 0x9ad8);
                     68:        byte_stream_put16(&bs, 0x0dba);
                     69:        byte_stream_put16(&bs, 0x11d5);
                     70:        byte_stream_put16(&bs, 0x9f8a);
                     71:        byte_stream_put16(&bs, 0x0060);
                     72:        byte_stream_put16(&bs, 0xb0ee);
                     73:        byte_stream_put16(&bs, 0x0631);
                     74: 
                     75:        snacid = aim_cachesnac(od, SNAC_FAMILY_ALERT, 0x0006, 0x0000, NULL, 0);
                     76:        flap_connection_send_snac(od, conn, SNAC_FAMILY_ALERT, 0x0006, snacid, &bs);
                     77: 
                     78:        byte_stream_destroy(&bs);
                     79: 
                     80:        return 0;
                     81: }
                     82: 
                     83: 
                     84: /**
                     85:  * Subtype 0x0007 - Receive information about your email account
                     86:  *
                     87:  * So I don't even know if you can have multiple 16 byte keys,
                     88:  * but this is coded so it will handle that, and handle it well.
                     89:  * This tells you if you have unread mail or not, the URL you
                     90:  * should use to access that mail, and the domain name for the
                     91:  * email account (username@domainname.com).  If this is the
                     92:  * first 0x0007 SNAC you've received since you signed on, or if
                     93:  * this is just a periodic status update, this will also contain
                     94:  * the number of unread emails that you have.
                     95:  */
                     96: static int
                     97: parseinfo(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
                     98: {
                     99:        int ret = 0;
                    100:        aim_rxcallback_t userfunc;
                    101:        struct aim_emailinfo *new;
                    102:        GSList *tlvlist;
                    103:        guint8 *cookie8, *cookie16;
                    104:        int tmp, havenewmail = 0; /* Used to tell the client we have _new_ mail */
                    105: 
                    106:        char *alertitle = NULL, *alerturl = NULL;
                    107: 
                    108:        cookie8 = byte_stream_getraw(bs, 8); /* Possibly the code used to log you in to mail? */
                    109:        cookie16 = byte_stream_getraw(bs, 16); /* Mail cookie sent above */
                    110: 
                    111:        /* See if we already have some info associated with this cookie */
                    112:        for (new = od->emailinfo; (new && memcmp(cookie16, new->cookie16, 16)); new = new->next);
                    113:        if (new) {
                    114:                /* Free some of the old info, if it exists */
                    115:                g_free(new->cookie8);
                    116:                g_free(new->cookie16);
                    117:                g_free(new->url);
                    118:                g_free(new->domain);
                    119:        } else {
                    120:                /* We don't already have info, so create a new struct for it */
                    121:                new = g_new0(struct aim_emailinfo, 1);
                    122:                new->next = od->emailinfo;
                    123:                od->emailinfo = new;
                    124:        }
                    125: 
                    126:        new->cookie8 = cookie8;
                    127:        new->cookie16 = cookie16;
                    128: 
                    129:        tlvlist = aim_tlvlist_readnum(bs, byte_stream_get16(bs));
                    130: 
                    131:        tmp = aim_tlv_get16(tlvlist, 0x0080, 1);
                    132:        if (tmp) {
                    133:                if (new->nummsgs < tmp)
                    134:                        havenewmail = 1;
                    135:                new->nummsgs = tmp;
                    136:        } else {
                    137:                /* If they don't send a 0x0080 TLV, it means we definitely have new mail */
                    138:                /* (ie. this is not just another status update) */
                    139:                havenewmail = 1;
                    140:                new->nummsgs++; /* We know we have at least 1 new email */
                    141:        }
                    142:        new->url = aim_tlv_getstr(tlvlist, 0x0007, 1);
                    143:        if (!(new->unread = aim_tlv_get8(tlvlist, 0x0081, 1))) {
                    144:                havenewmail = 0;
                    145:                new->nummsgs = 0;
                    146:        }
                    147:        new->domain = aim_tlv_getstr(tlvlist, 0x0082, 1);
                    148:        new->flag = aim_tlv_get16(tlvlist, 0x0084, 1);
                    149: 
                    150:        alertitle = aim_tlv_getstr(tlvlist, 0x0005, 1);
                    151:        alerturl  = aim_tlv_getstr(tlvlist, 0x000d, 1);
                    152: 
                    153:        if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
                    154:                ret = userfunc(od, conn, frame, new, havenewmail, alertitle, (alerturl ? alerturl + 2 : NULL));
                    155: 
                    156:        aim_tlvlist_free(tlvlist);
                    157: 
                    158:        g_free(alertitle);
                    159:        g_free(alerturl);
                    160: 
                    161:        return ret;
                    162: }
                    163: 
                    164: /**
                    165:  * Subtype 0x0016 - Send something or other
                    166:  *
                    167:  * @param od The oscar session.
                    168:  * @param conn The email connection for this session.
                    169:  * @return Return 0 if no errors, otherwise return the error number.
                    170:  */
                    171: int
                    172: aim_email_activate(OscarData *od)
                    173: {
                    174:        FlapConnection *conn;
                    175:        ByteStream bs;
                    176:        aim_snacid_t snacid;
                    177: 
                    178:        if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_ALERT)))
                    179:                return -EINVAL;
                    180: 
                    181:        byte_stream_new(&bs, 1+16);
                    182: 
                    183:        /* I would guess this tells AIM that you want updates for your mail accounts */
                    184:        /* ...but I really have no idea */
                    185:        byte_stream_put8(&bs, 0x02);
                    186:        byte_stream_put32(&bs, 0x04000000);
                    187:        byte_stream_put32(&bs, 0x04000000);
                    188:        byte_stream_put32(&bs, 0x04000000);
                    189:        byte_stream_put32(&bs, 0x00000000);
                    190: 
                    191:        snacid = aim_cachesnac(od, SNAC_FAMILY_ALERT, 0x0016, 0x0000, NULL, 0);
                    192:        flap_connection_send_snac(od, conn, SNAC_FAMILY_ALERT, 0x0006, snacid, &bs);
                    193: 
                    194:        byte_stream_destroy(&bs);
                    195: 
                    196:        return 0;
                    197: }
                    198: 
                    199: static int
                    200: snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
                    201: {
                    202:        if (snac->subtype == 0x0007)
                    203:                return parseinfo(od, conn, mod, frame, snac, bs);
                    204: 
                    205:        return 0;
                    206: }
                    207: 
                    208: static void
                    209: email_shutdown(OscarData *od, aim_module_t *mod)
                    210: {
                    211:        while (od->emailinfo)
                    212:        {
                    213:                struct aim_emailinfo *tmp = od->emailinfo;
                    214:                od->emailinfo = od->emailinfo->next;
                    215:                g_free(tmp->cookie16);
                    216:                g_free(tmp->cookie8);
                    217:                g_free(tmp->url);
                    218:                g_free(tmp->domain);
                    219:                g_free(tmp);
                    220:        }
                    221: 
                    222:        return;
                    223: }
                    224: 
                    225: int
                    226: email_modfirst(OscarData *od, aim_module_t *mod)
                    227: {
                    228:        mod->family = SNAC_FAMILY_ALERT;
                    229:        mod->version = 0x0001;
                    230:        mod->toolid = 0x0010;
                    231:        mod->toolversion = 0x0629;
                    232:        mod->flags = 0;
                    233:        strncpy(mod->name, "alert", sizeof(mod->name));
                    234:        mod->snachandler = snachandler;
                    235:        mod->shutdown = email_shutdown;
                    236: 
                    237:        return 0;
                    238: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>