Ignore:
Timestamp:
2015-02-20T22:50:54Z (10 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/rxqueue.c

    raf359b4 r5ebff60  
    77 */
    88
    9 #include <aim.h> 
     9#include <aim.h>
    1010
    1111#include <sys/socket.h>
     
    1616int aim_recv(int fd, void *buf, size_t count)
    1717{
    18         int left, cur; 
     18        int left, cur;
    1919
    2020        for (cur = 0, left = count; left; ) {
    2121                int ret;
    22                
    23                 ret = recv(fd, ((unsigned char *)buf)+cur, left, 0);
     22
     23                ret = recv(fd, ((unsigned char *) buf) + cur, left, 0);
    2424
    2525                /* Of course EOF is an error, only morons disagree with that. */
    26                 if (ret <= 0)
     26                if (ret <= 0) {
    2727                        return -1;
     28                }
    2829
    2930                cur += ret;
     
    4243        int red = 0;
    4344
    44         if (!bs || (fd < 0) || (count < 0))
     45        if (!bs || (fd < 0) || (count < 0)) {
    4546                return -1;
    46        
    47         if (count > (bs->len - bs->offset))
     47        }
     48
     49        if (count > (bs->len - bs->offset)) {
    4850                count = bs->len - bs->offset; /* truncate to remaining space */
    4951
     52        }
    5053        if (count) {
    5154
    5255                red = aim_recv(fd, bs->data + bs->offset, count);
    5356
    54                 if (red <= 0)
     57                if (red <= 0) {
    5558                        return -1;
     59                }
    5660        }
    5761
     
    6367int aim_bstream_init(aim_bstream_t *bs, guint8 *data, int len)
    6468{
    65        
    66         if (!bs)
     69
     70        if (!bs) {
    6771                return -1;
     72        }
    6873
    6974        bs->data = data;
     
    8792{
    8893
    89         if (off > bs->len)
     94        if (off > bs->len) {
    9095                return -1;
     96        }
    9197
    9298        bs->offset = off;
     
    106112{
    107113
    108         if (aim_bstream_empty(bs) < n)
    109                 return 0; /* XXX throw an exception */
    110 
     114        if (aim_bstream_empty(bs) < n) {
     115                return 0; /* XXX throw an exception */
     116
     117        }
    111118        bs->offset += n;
    112119
     
    116123guint8 aimbs_get8(aim_bstream_t *bs)
    117124{
    118        
    119         if (aim_bstream_empty(bs) < 1)
    120                 return 0; /* XXX throw an exception */
    121        
     125
     126        if (aim_bstream_empty(bs) < 1) {
     127                return 0; /* XXX throw an exception */
     128
     129        }
    122130        bs->offset++;
    123        
     131
    124132        return aimutil_get8(bs->data + bs->offset - 1);
    125133}
     
    127135guint16 aimbs_get16(aim_bstream_t *bs)
    128136{
    129        
    130         if (aim_bstream_empty(bs) < 2)
    131                 return 0; /* XXX throw an exception */
    132        
     137
     138        if (aim_bstream_empty(bs) < 2) {
     139                return 0; /* XXX throw an exception */
     140
     141        }
    133142        bs->offset += 2;
    134        
     143
    135144        return aimutil_get16(bs->data + bs->offset - 2);
    136145}
     
    138147guint32 aimbs_get32(aim_bstream_t *bs)
    139148{
    140        
    141         if (aim_bstream_empty(bs) < 4)
    142                 return 0; /* XXX throw an exception */
    143        
     149
     150        if (aim_bstream_empty(bs) < 4) {
     151                return 0; /* XXX throw an exception */
     152
     153        }
    144154        bs->offset += 4;
    145        
     155
    146156        return aimutil_get32(bs->data + bs->offset - 4);
    147157}
     
    149159guint8 aimbs_getle8(aim_bstream_t *bs)
    150160{
    151        
    152         if (aim_bstream_empty(bs) < 1)
    153                 return 0; /* XXX throw an exception */
    154        
     161
     162        if (aim_bstream_empty(bs) < 1) {
     163                return 0; /* XXX throw an exception */
     164
     165        }
    155166        bs->offset++;
    156        
     167
    157168        return aimutil_getle8(bs->data + bs->offset - 1);
    158169}
     
    160171guint16 aimbs_getle16(aim_bstream_t *bs)
    161172{
    162        
    163         if (aim_bstream_empty(bs) < 2)
    164                 return 0; /* XXX throw an exception */
    165        
     173
     174        if (aim_bstream_empty(bs) < 2) {
     175                return 0; /* XXX throw an exception */
     176
     177        }
    166178        bs->offset += 2;
    167        
     179
    168180        return aimutil_getle16(bs->data + bs->offset - 2);
    169181}
     
    171183guint32 aimbs_getle32(aim_bstream_t *bs)
    172184{
    173        
    174         if (aim_bstream_empty(bs) < 4)
    175                 return 0; /* XXX throw an exception */
    176        
     185
     186        if (aim_bstream_empty(bs) < 4) {
     187                return 0; /* XXX throw an exception */
     188
     189        }
    177190        bs->offset += 4;
    178        
     191
    179192        return aimutil_getle32(bs->data + bs->offset - 4);
    180193}
     
    183196{
    184197
    185         if (aim_bstream_empty(bs) < 1)
    186                 return 0; /* XXX throw an exception */
    187 
     198        if (aim_bstream_empty(bs) < 1) {
     199                return 0; /* XXX throw an exception */
     200
     201        }
    188202        bs->offset += aimutil_put8(bs->data + bs->offset, v);
    189203
     
    194208{
    195209
    196         if (aim_bstream_empty(bs) < 2)
    197                 return 0; /* XXX throw an exception */
    198 
     210        if (aim_bstream_empty(bs) < 2) {
     211                return 0; /* XXX throw an exception */
     212
     213        }
    199214        bs->offset += aimutil_put16(bs->data + bs->offset, v);
    200215
     
    205220{
    206221
    207         if (aim_bstream_empty(bs) < 4)
    208                 return 0; /* XXX throw an exception */
    209 
     222        if (aim_bstream_empty(bs) < 4) {
     223                return 0; /* XXX throw an exception */
     224
     225        }
    210226        bs->offset += aimutil_put32(bs->data + bs->offset, v);
    211227
     
    216232{
    217233
    218         if (aim_bstream_empty(bs) < 1)
    219                 return 0; /* XXX throw an exception */
    220 
     234        if (aim_bstream_empty(bs) < 1) {
     235                return 0; /* XXX throw an exception */
     236
     237        }
    221238        bs->offset += aimutil_putle8(bs->data + bs->offset, v);
    222239
     
    227244{
    228245
    229         if (aim_bstream_empty(bs) < 2)
    230                 return 0; /* XXX throw an exception */
    231 
     246        if (aim_bstream_empty(bs) < 2) {
     247                return 0; /* XXX throw an exception */
     248
     249        }
    232250        bs->offset += aimutil_putle16(bs->data + bs->offset, v);
    233251
     
    238256{
    239257
    240         if (aim_bstream_empty(bs) < 4)
    241                 return 0; /* XXX throw an exception */
    242 
     258        if (aim_bstream_empty(bs) < 4) {
     259                return 0; /* XXX throw an exception */
     260
     261        }
    243262        bs->offset += aimutil_putle32(bs->data + bs->offset, v);
    244263
     
    249268{
    250269
    251         if (aim_bstream_empty(bs) < len)
     270        if (aim_bstream_empty(bs) < len) {
    252271                return 0;
     272        }
    253273
    254274        memcpy(buf, bs->data + bs->offset, len);
     
    262282        guint8 *ob;
    263283
    264         if (!(ob = g_malloc(len)))
     284        if (!(ob = g_malloc(len))) {
    265285                return NULL;
     286        }
    266287
    267288        if (aimbs_getrawbuf(bs, ob, len) < len) {
     
    277298        guint8 *ob;
    278299
    279         if (!(ob = g_malloc(len+1)))
     300        if (!(ob = g_malloc(len + 1))) {
    280301                return NULL;
     302        }
    281303
    282304        if (aimbs_getrawbuf(bs, ob, len) < len) {
     
    284306                return NULL;
    285307        }
    286        
     308
    287309        ob[len] = '\0';
    288310
    289         return (char *)ob;
     311        return (char *) ob;
    290312}
    291313
     
    293315{
    294316
    295         if (aim_bstream_empty(bs) < len)
    296                 return 0; /* XXX throw an exception */
    297 
     317        if (aim_bstream_empty(bs) < len) {
     318                return 0; /* XXX throw an exception */
     319
     320        }
    298321        memcpy(bs->data + bs->offset, v, len);
    299322        bs->offset += len;
     
    305328{
    306329
    307         if (aim_bstream_empty(srcbs) < len)
     330        if (aim_bstream_empty(srcbs) < len) {
    308331                return 0; /* XXX throw exception (underrun) */
    309332
    310         if (aim_bstream_empty(bs) < len)
     333        }
     334        if (aim_bstream_empty(bs) < len) {
    311335                return 0; /* XXX throw exception (overflow) */
    312336
     337        }
    313338        memcpy(bs->data + bs->offset, srcbs->data + srcbs->offset, len);
    314339        bs->offset += len;
     
    319344
    320345/**
    321  * aim_frame_destroy - free aim_frame_t 
    322  * @frame: the frame to free 
    323  *
    324  * returns -1 on error; 0 on success. 
     346 * aim_frame_destroy - free aim_frame_t
     347 * @frame: the frame to free
     348 *
     349 * returns -1 on error; 0 on success.
    325350 *
    326351 */
     
    331356
    332357        g_free(frame);
    333 } 
     358}
    334359
    335360
     
    344369        aim_frame_t *newrx;
    345370        guint16 payloadlen;
    346        
    347         if (!sess || !conn)
     371
     372        if (!sess || !conn) {
    348373                return 0;
    349 
    350         if (conn->fd == -1)
     374        }
     375
     376        if (conn->fd == -1) {
    351377                return -1; /* its a aim_conn_close()'d connection */
    352378
     379        }
    353380        /* KIDS, THIS IS WHAT HAPPENS IF YOU USE CODE WRITTEN FOR GUIS IN A DAEMON!
    354            
     381
    355382           And wouldn't it make sense to return something that prevents this function
    356383           from being called again IMMEDIATELY (and making the program suck up all
    357384           CPU time)?...
    358            
     385
    359386        if (conn->fd < 3)
    360                 return 0;
     387                return 0;
    361388        */
    362389
    363         if (conn->status & AIM_CONN_STATUS_INPROGRESS)
     390        if (conn->status & AIM_CONN_STATUS_INPROGRESS) {
    364391                return aim_conn_completeconnect(sess, conn);
     392        }
    365393
    366394        aim_bstream_init(&flaphdr, flaphdr_raw, sizeof(flaphdr_raw));
     
    368396        /*
    369397         * Read FLAP header.  Six bytes:
    370          *   
     398         *
    371399         *   0 char  -- Always 0x2a
    372400         *   1 char  -- Channel ID.  Usually 2 -- 1 and 4 are used during login.
    373          *   2 short -- Sequence number 
     401         *   2 short -- Sequence number
    374402         *   4 short -- Number of data bytes that follow.
    375403         */
     
    391419                aim_conn_close(conn);
    392420                return -1;
    393         }       
     421        }
    394422
    395423        /* allocate a new struct */
    396         if (!(newrx = (aim_frame_t *)g_new0(aim_frame_t,1)))
     424        if (!(newrx = (aim_frame_t *) g_new0(aim_frame_t, 1))) {
    397425                return -1;
     426        }
    398427
    399428        /* we're doing FLAP if we're here */
    400429        newrx->hdrtype = AIM_FRAMETYPE_FLAP;
    401        
     430
    402431        newrx->hdr.flap.type = aimbs_get8(&flaphdr);
    403432        newrx->hdr.flap.seqnum = aimbs_get16(&flaphdr);
     
    422451                        return -1;
    423452                }
    424         } else
     453        } else {
    425454                aim_bstream_init(&newrx->data, NULL, 0);
     455        }
    426456
    427457
     
    432462        newrx->next = NULL;  /* this will always be at the bottom */
    433463
    434         if (!sess->queue_incoming)
     464        if (!sess->queue_incoming) {
    435465                sess->queue_incoming = newrx;
    436         else {
     466        } else {
    437467                aim_frame_t *cur;
    438468
    439                 for (cur = sess->queue_incoming; cur->next; cur = cur->next)
     469                for (cur = sess->queue_incoming; cur->next; cur = cur->next) {
    440470                        ;
     471                }
    441472                cur->next = newrx;
    442473        }
     
    444475        newrx->conn->lastactivity = time(NULL);
    445476
    446         return 0; 
     477        return 0;
    447478}
    448479
     
    450481 * Purge recieve queue of all handled commands (->handled==1).  Also
    451482 * allows for selective freeing using ->nofree so that the client can
    452  * keep the data for various purposes. 
    453  *
    454  * If ->nofree is nonzero, the frame will be delinked from the global list, 
     483 * keep the data for various purposes.
     484 *
     485 * If ->nofree is nonzero, the frame will be delinked from the global list,
    455486 * but will not be free'ed.  The client _must_ keep a pointer to the
    456487 * data -- libfaim will not!  If the client marks ->nofree but
     
    466497
    467498                        *prev = cur->next;
    468                        
    469                         if (!cur->nofree)
     499
     500                        if (!cur->nofree) {
    470501                                aim_frame_destroy(cur);
    471 
    472                 } else
     502                        }
     503
     504                } else {
    473505                        prev = &cur->next;
     506                }
    474507        }
    475508
     
    489522
    490523        for (currx = sess->queue_incoming; currx; currx = currx->next) {
    491                 if ((!currx->handled) && (currx->conn == conn))
     524                if ((!currx->handled) && (currx->conn == conn)) {
    492525                        currx->handled = 1;
    493         }       
     526                }
     527        }
    494528        return;
    495529}
Note: See TracChangeset for help on using the changeset viewer.