Ignore:
Timestamp:
2015-02-20T22:50:54Z (9 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
0b9daac, 3d45471, 7733b8c
Parents:
af359b4
git-author:
Indent <please@…> (19-02-15 05:47:20)
git-committer:
dequis <dx@…> (20-02-15 22:50:54)
Message:

Reindent everything to K&R style with tabs

Used uncrustify, with the configuration file in ./doc/uncrustify.cfg

Commit author set to "Indent <please@…>" so that it's easier to
skip while doing git blame.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/oscar/chat.c

    raf359b4 r5ebff60  
    66 */
    77
    8 #include <aim.h> 
     8#include <aim.h>
    99#include <glib.h>
    1010#include "info.h"
     
    1919void aim_conn_kill_chat(aim_session_t *sess, aim_conn_t *conn)
    2020{
    21         struct chatconnpriv *ccp = (struct chatconnpriv *)conn->priv;
    22 
    23         if (ccp)
     21        struct chatconnpriv *ccp = (struct chatconnpriv *) conn->priv;
     22
     23        if (ccp) {
    2424                g_free(ccp->name);
     25        }
    2526        g_free(ccp);
    2627
     
    3839 *                                 and displays the message as normal.)
    3940 *
    40  * XXX convert this to use tlvchains 
     41 * XXX convert this to use tlvchains
    4142 */
    4243int aim_chat_send_im(aim_session_t *sess, aim_conn_t *conn, guint16 flags, const char *msg, int msglen)
    43 {   
     44{
    4445        int i;
    4546        aim_frame_t *fr;
     
    4950        aim_tlvlist_t *otl = NULL, *itl = NULL;
    5051
    51         if (!sess || !conn || !msg || (msglen <= 0))
     52        if (!sess || !conn || !msg || (msglen <= 0)) {
    5253                return 0;
    53 
    54         if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
     54        }
     55
     56        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152))) {
    5557                return -ENOMEM;
     58        }
    5659
    5760        snacid = aim_cachesnac(sess, 0x000e, 0x0005, 0x0000, NULL, 0);
     
    5962
    6063
    61         /* 
     64        /*
    6265         * Generate a random message cookie.
    6366         *
     
    6669         *
    6770         */
    68         for (i = 0; i < sizeof(ckstr); i++)
    69                 (void) aimutil_put8(ckstr+i, (guint8) rand());
    70        
     71        for (i = 0; i < sizeof(ckstr); i++) {
     72                (void) aimutil_put8(ckstr + i, (guint8) rand());
     73        }
     74
    7175
    7276        cookie = aim_mkcookie(ckstr, AIM_COOKIETYPE_CHAT, NULL);
     
    7579        aim_cachecookie(sess, cookie);
    7680
    77         for (i = 0; i < sizeof(ckstr); i++)
     81        for (i = 0; i < sizeof(ckstr); i++) {
    7882                aimbs_put8(&fr->data, ckstr[i]);
    79 
    80 
    81         /*
    82          * Channel ID.
     83        }
     84
     85
     86        /*
     87         * Channel ID.
    8388         */
    8489        aimbs_put16(&fr->data, 0x0003);
     
    9398         * Type 6: Reflect
    9499         */
    95         if (!(flags & AIM_CHATFLAGS_NOREFLECT))
     100        if (!(flags & AIM_CHATFLAGS_NOREFLECT)) {
    96101                aim_addtlvtochain_noval(&otl, 0x0006);
     102        }
    97103
    98104        /*
    99105         * Type 7: Autoresponse
    100106         */
    101         if (flags & AIM_CHATFLAGS_AWAY)
     107        if (flags & AIM_CHATFLAGS_AWAY) {
    102108                aim_addtlvtochain_noval(&otl, 0x0007);
    103        
     109        }
     110
    104111        /* [WvG] This wasn't there originally, but we really should send
    105112                 the right charset flags, as we also do with normal
     
    107114        /*
    108115        if (flags & AIM_CHATFLAGS_UNICODE)
    109                 aimbs_put16(&fr->data, 0x0002);
     116                aimbs_put16(&fr->data, 0x0002);
    110117        else if (flags & AIM_CHATFLAGS_ISO_8859_1)
    111                 aimbs_put16(&fr->data, 0x0003);
     118                aimbs_put16(&fr->data, 0x0003);
    112119        else
    113                 aimbs_put16(&fr->data, 0x0000);
    114        
     120                aimbs_put16(&fr->data, 0x0000);
     121
    115122        aimbs_put16(&fr->data, 0x0000);
    116123        */
    117        
     124
    118125        /*
    119126         * SubTLV: Type 1: Message
    120127         */
    121         aim_addtlvtochain_raw(&itl, 0x0001, strlen(msg), (guint8 *)msg);
     128        aim_addtlvtochain_raw(&itl, 0x0001, strlen(msg), (guint8 *) msg);
    122129
    123130        /*
     
    125132         *
    126133         * This could include other information... We just
    127          * put in a message TLV however. 
    128          * 
     134         * put in a message TLV however.
     135         *
    129136         */
    130137        aim_addtlvtochain_frozentlvlist(&otl, 0x0005, &itl);
    131138
    132139        aim_writetlvchain(&fr->data, &otl);
    133        
     140
    134141        aim_freetlvchain(&itl);
    135142        aim_freetlvchain(&otl);
    136        
     143
    137144        aim_tx_enqueue(sess, fr);
    138145
     
    141148
    142149/*
    143  * Join a room of name roomname.  This is the first step to joining an 
    144  * already created room.  It's basically a Service Request for 
    145  * family 0x000e, with a little added on to specify the exchange and room 
     150 * Join a room of name roomname.  This is the first step to joining an
     151 * already created room.  It's basically a Service Request for
     152 * family 0x000e, with a little added on to specify the exchange and room
    146153 * name.
    147154 */
     
    152159        aim_tlvlist_t *tl = NULL;
    153160        struct chatsnacinfo csi;
    154        
    155         if (!sess || !conn || !roomname || !strlen(roomname))
     161
     162        if (!sess || !conn || !roomname || !strlen(roomname)) {
    156163                return -EINVAL;
    157 
    158         if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 512)))
     164        }
     165
     166        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 512))) {
    159167                return -ENOMEM;
     168        }
    160169
    161170        memset(&csi, 0, sizeof(csi));
     
    178187        aim_tx_enqueue(sess, fr);
    179188
    180         return 0; 
     189        return 0;
    181190}
    182191
     
    185194        int namelen;
    186195
    187         if (!bs || !outinfo)
     196        if (!bs || !outinfo) {
    188197                return 0;
     198        }
    189199
    190200        outinfo->exchange = aimbs_get16(bs);
     
    199209 * conn must be a BOS connection!
    200210 */
    201 int aim_chat_invite(aim_session_t *sess, aim_conn_t *conn, const char *sn, const char *msg, guint16 exchange, const char *roomname, guint16 instance)
     211int aim_chat_invite(aim_session_t *sess, aim_conn_t *conn, const char *sn, const char *msg, guint16 exchange,
     212                    const char *roomname, guint16 instance)
    202213{
    203214        int i;
     
    211222        int hdrlen;
    212223        aim_bstream_t hdrbs;
    213        
    214         if (!sess || !conn || !sn || !msg || !roomname)
     224
     225        if (!sess || !conn || !sn || !msg || !roomname) {
    215226                return -EINVAL;
    216 
    217         if (conn->type != AIM_CONN_TYPE_BOS)
     227        }
     228
     229        if (conn->type != AIM_CONN_TYPE_BOS) {
    218230                return -EINVAL;
    219 
    220         if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152+strlen(sn)+strlen(roomname)+strlen(msg))))
     231        }
     232
     233        if (!(fr =
     234                      aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152 + strlen(sn) + strlen(roomname) +
     235                                 strlen(msg)))) {
    221236                return -ENOMEM;
    222 
    223         snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, sn, strlen(sn)+1);
     237        }
     238
     239        snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, sn, strlen(sn) + 1);
    224240        aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid);
    225241
     
    228244         * Cookie
    229245         */
    230         for (i = 0; i < sizeof(ckstr); i++)
     246        for (i = 0; i < sizeof(ckstr); i++) {
    231247                (void) aimutil_put8(ckstr, (guint8) rand());
     248        }
    232249
    233250        /* XXX should be uncached by an unwritten 'invite accept' handler */
     
    239256        }
    240257
    241         if ((cookie = aim_mkcookie(ckstr, AIM_COOKIETYPE_INVITE, priv)))
     258        if ((cookie = aim_mkcookie(ckstr, AIM_COOKIETYPE_INVITE, priv))) {
    242259                aim_cachecookie(sess, cookie);
    243         else
     260        } else {
    244261                g_free(priv);
    245 
    246         for (i = 0; i < sizeof(ckstr); i++)
     262        }
     263
     264        for (i = 0; i < sizeof(ckstr); i++) {
    247265                aimbs_put8(&fr->data, ckstr[i]);
     266        }
    248267
    249268
     
    257276         */
    258277        aimbs_put8(&fr->data, strlen(sn));
    259         aimbs_putraw(&fr->data, (guint8 *)sn, strlen(sn));
     278        aimbs_putraw(&fr->data, (guint8 *) sn, strlen(sn));
    260279
    261280        /*
     
    266285         * Sigh.  AOL was rather inconsistent right here.  So we have
    267286         * to play some minor tricks.  Right inside the type 5 is some
    268          * raw data, followed by a series of TLVs. 
    269          *
    270          */
    271         hdrlen = 2+8+16+6+4+4+strlen(msg)+4+2+1+strlen(roomname)+2;
     287         * raw data, followed by a series of TLVs.
     288         *
     289         */
     290        hdrlen = 2 + 8 + 16 + 6 + 4 + 4 + strlen(msg) + 4 + 2 + 1 + strlen(roomname) + 2;
    272291        hdr = g_malloc(hdrlen);
    273292        aim_bstream_init(&hdrbs, hdr, hdrlen);
    274        
     293
    275294        aimbs_put16(&hdrbs, 0x0000); /* Unknown! */
    276295        aimbs_putraw(&hdrbs, ckstr, sizeof(ckstr)); /* I think... */
     
    279298        aim_addtlvtochain16(&itl, 0x000a, 0x0001);
    280299        aim_addtlvtochain_noval(&itl, 0x000f);
    281         aim_addtlvtochain_raw(&itl, 0x000c, strlen(msg), (guint8 *)msg);
     300        aim_addtlvtochain_raw(&itl, 0x000c, strlen(msg), (guint8 *) msg);
    282301        aim_addtlvtochain_chatroom(&itl, 0x2711, exchange, roomname, instance);
    283302        aim_writetlvchain(&hdrbs, &itl);
    284        
     303
    285304        aim_addtlvtochain_raw(&otl, 0x0005, aim_bstream_curpos(&hdrbs), hdr);
    286305
     
    290309        aim_freetlvchain(&itl);
    291310        aim_freetlvchain(&otl);
    292        
     311
    293312        aim_tx_enqueue(sess, fr);
    294313
     
    334353        /*
    335354         * Everything else are TLVs.
    336          */ 
     355         */
    337356        tlvlist = aim_readtlvchain(bs);
    338357
     
    340359         * TLV type 0x006a is the room name in Human Readable Form.
    341360         */
    342         if (aim_gettlv(tlvlist, 0x006a, 1))
     361        if (aim_gettlv(tlvlist, 0x006a, 1)) {
    343362                roomname = aim_gettlv_str(tlvlist, 0x006a, 1);
     363        }
    344364
    345365        /*
    346366         * Type 0x006f: Number of occupants.
    347367         */
    348         if (aim_gettlv(tlvlist, 0x006f, 1))
     368        if (aim_gettlv(tlvlist, 0x006f, 1)) {
    349369                usercount = aim_gettlv16(tlvlist, 0x006f, 1);
     370        }
    350371
    351372        /*
    352373         * Type 0x0073:  Occupant list.
    353374         */
    354         if (aim_gettlv(tlvlist, 0x0073, 1)) {   
     375        if (aim_gettlv(tlvlist, 0x0073, 1)) {
    355376                int curoccupant = 0;
    356377                aim_tlv_t *tmptlv;
     
    364385                aim_bstream_init(&occbs, tmptlv->value, tmptlv->length);
    365386
    366                 while (curoccupant < usercount)
     387                while (curoccupant < usercount) {
    367388                        aim_extractuserinfo(sess, &occbs, &userinfo[curoccupant++]);
    368         }
    369 
    370         /*
     389                }
     390        }
     391
     392        /*
    371393         * Type 0x00c9: Flags. (AIM_CHATROOM_FLAG)
    372394         */
    373         if (aim_gettlv(tlvlist, 0x00c9, 1))
     395        if (aim_gettlv(tlvlist, 0x00c9, 1)) {
    374396                flags = aim_gettlv16(tlvlist, 0x00c9, 1);
    375 
    376         /*
     397        }
     398
     399        /*
    377400         * Type 0x00ca: Creation time (4 bytes)
    378401         */
    379         if (aim_gettlv(tlvlist, 0x00ca, 1))
     402        if (aim_gettlv(tlvlist, 0x00ca, 1)) {
    380403                creationtime = aim_gettlv32(tlvlist, 0x00ca, 1);
    381 
    382         /*
     404        }
     405
     406        /*
    383407         * Type 0x00d1: Maximum Message Length
    384408         */
    385         if (aim_gettlv(tlvlist, 0x00d1, 1))
     409        if (aim_gettlv(tlvlist, 0x00d1, 1)) {
    386410                maxmsglen = aim_gettlv16(tlvlist, 0x00d1, 1);
    387 
    388         /*
     411        }
     412
     413        /*
    389414         * Type 0x00d2: Unknown. (2 bytes)
    390415         */
    391         if (aim_gettlv(tlvlist, 0x00d2, 1))
     416        if (aim_gettlv(tlvlist, 0x00d2, 1)) {
    392417                unknown_d2 = aim_gettlv16(tlvlist, 0x00d2, 1);
    393 
    394         /*
     418        }
     419
     420        /*
    395421         * Type 0x00d3: Room Description
    396422         */
    397         if (aim_gettlv(tlvlist, 0x00d3, 1))
     423        if (aim_gettlv(tlvlist, 0x00d3, 1)) {
    398424                roomdesc = aim_gettlv_str(tlvlist, 0x00d3, 1);
     425        }
    399426
    400427        /*
    401428         * Type 0x000d4: Unknown (flag only)
    402429         */
    403         if (aim_gettlv(tlvlist, 0x000d4, 1))
     430        if (aim_gettlv(tlvlist, 0x000d4, 1)) {
    404431                ;
    405 
    406         /*
     432        }
     433
     434        /*
    407435         * Type 0x00d5: Unknown. (1 byte)
    408436         */
    409         if (aim_gettlv(tlvlist, 0x00d5, 1))
     437        if (aim_gettlv(tlvlist, 0x00d5, 1)) {
    410438                unknown_d5 = aim_gettlv8(tlvlist, 0x00d5, 1);
     439        }
    411440
    412441
     
    414443         * Type 0x00d6: Encoding 1 ("us-ascii")
    415444         */
    416         if (aim_gettlv(tlvlist, 0x000d6, 1))
     445        if (aim_gettlv(tlvlist, 0x000d6, 1)) {
    417446                ;
    418        
     447        }
     448
    419449        /*
    420450         * Type 0x00d7: Language 1 ("en")
    421451         */
    422         if (aim_gettlv(tlvlist, 0x000d7, 1))
     452        if (aim_gettlv(tlvlist, 0x000d7, 1)) {
    423453                ;
     454        }
    424455
    425456        /*
    426457         * Type 0x00d8: Encoding 2 ("us-ascii")
    427458         */
    428         if (aim_gettlv(tlvlist, 0x000d8, 1))
     459        if (aim_gettlv(tlvlist, 0x000d8, 1)) {
    429460                ;
    430        
     461        }
     462
    431463        /*
    432464         * Type 0x00d9: Language 2 ("en")
    433465         */
    434         if (aim_gettlv(tlvlist, 0x000d9, 1))
     466        if (aim_gettlv(tlvlist, 0x000d9, 1)) {
    435467                ;
     468        }
    436469
    437470        /*
    438471         * Type 0x00da: Maximum visible message length
    439472         */
    440         if (aim_gettlv(tlvlist, 0x000da, 1))
     473        if (aim_gettlv(tlvlist, 0x000da, 1)) {
    441474                maxvisiblemsglen = aim_gettlv16(tlvlist, 0x00da, 1);
     475        }
    442476
    443477        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) {
    444478                ret = userfunc(sess,
    445                                 rx,
    446                                 &roominfo,
    447                                 roomname,
    448                                 usercount,
    449                                 userinfo,       
    450                                 roomdesc,
    451                                 flags,
    452                                 creationtime,
    453                                 maxmsglen,
    454                                 unknown_d2,
    455                                 unknown_d5,
    456                                 maxvisiblemsglen);
     479                               rx,
     480                               &roominfo,
     481                               roomname,
     482                               usercount,
     483                               userinfo,
     484                               roomdesc,
     485                               flags,
     486                               creationtime,
     487                               maxmsglen,
     488                               unknown_d2,
     489                               unknown_d5,
     490                               maxvisiblemsglen);
    457491        }
    458492
     
    466500}
    467501
    468 static int userlistchange(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
     502static int userlistchange(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac,
     503                          aim_bstream_t *bs)
    469504{
    470505        aim_userinfo_t *userinfo = NULL;
     
    475510                curcount++;
    476511                userinfo = g_realloc(userinfo, curcount * sizeof(aim_userinfo_t));
    477                 aim_extractuserinfo(sess, bs, &userinfo[curcount-1]);
    478         }
    479 
    480         if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
     512                aim_extractuserinfo(sess, bs, &userinfo[curcount - 1]);
     513        }
     514
     515        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) {
    481516                ret = userfunc(sess, rx, curcount, userinfo);
     517        }
    482518
    483519        g_free(userinfo);
     
    487523
    488524/*
    489  * We could probably include this in the normal ICBM parsing 
     525 * We could probably include this in the normal ICBM parsing
    490526 * code as channel 0x0003, however, since only the start
    491527 * would be the same, we might as well do it here.
     
    507543 *         message string
    508544 *       possibly others
    509  * 
     545 *
    510546 */
    511547static int incomingmsg(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
    512548{
    513549        aim_userinfo_t userinfo;
    514         aim_rxcallback_t userfunc;     
     550        aim_rxcallback_t userfunc;
    515551        int ret = 0;
    516552        guint8 *cookie;
     
    549585
    550586        /*
    551          * Start parsing TLVs right away. 
     587         * Start parsing TLVs right away.
    552588         */
    553589        otl = aim_readtlvchain(bs);
     
    567603
    568604        /*
    569          * Type 0x0001: If present, it means it was a message to the 
     605         * Type 0x0001: If present, it means it was a message to the
    570606         * room (as opposed to a whisper).
    571607         */
    572         if (aim_gettlv(otl, 0x0001, 1))
     608        if (aim_gettlv(otl, 0x0001, 1)) {
    573609                ;
     610        }
    574611
    575612        /*
     
    585622                itl = aim_readtlvchain(&tbs);
    586623
    587                 /* 
     624                /*
    588625                 * Type 0x0001: Message.
    589                  */     
    590                 if (aim_gettlv(itl, 0x0001, 1))
     626                 */
     627                if (aim_gettlv(itl, 0x0001, 1)) {
    591628                        msg = aim_gettlv_str(itl, 0x0001, 1);
    592 
    593                 aim_freetlvchain(&itl);
    594         }
    595 
    596         if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
     629                }
     630
     631                aim_freetlvchain(&itl);
     632        }
     633
     634        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) {
    597635                ret = userfunc(sess, rx, &userinfo, msg);
     636        }
    598637
    599638        g_free(cookie);
     
    607646{
    608647
    609         if (snac->subtype == 0x0002)
     648        if (snac->subtype == 0x0002) {
    610649                return infoupdate(sess, mod, rx, snac, bs);
    611         else if ((snac->subtype == 0x0003) || (snac->subtype == 0x0004))
     650        } else if ((snac->subtype == 0x0003) || (snac->subtype == 0x0004)) {
    612651                return userlistchange(sess, mod, rx, snac, bs);
    613         else if (snac->subtype == 0x0006)
     652        } else if (snac->subtype == 0x0006) {
    614653                return incomingmsg(sess, mod, rx, snac, bs);
     654        }
    615655
    616656        return 0;
Note: See TracChangeset for help on using the changeset viewer.