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/twitter/twitter_lib.c

    raf359b4 r5ebff60  
    2424
    2525/* For strptime(): */
    26 #if(__sun)
     26#if (__sun)
    2727#else
    2828#define _XOPEN_SOURCE
     
    7070static void txu_free(struct twitter_xml_user *txu)
    7171{
    72         if (txu == NULL)
    73                 return;
     72        if (txu == NULL) {
     73                return;
     74        }
    7475
    7576        g_free(txu->name);
     
    8384static void txs_free(struct twitter_xml_status *txs)
    8485{
    85         if (txs == NULL)
    86                 return;
     86        if (txs == NULL) {
     87                return;
     88        }
    8789
    8890        g_free(txs->text);
     
    98100{
    99101        GSList *l;
    100         if (txl == NULL)
    101                 return;
     102
     103        if (txl == NULL) {
     104                return;
     105        }
    102106
    103107        for (l = txl->list; l; l = g_slist_next(l)) {
     
    148152                           exact Twitter username. */
    149153                        imcb_buddy_nick_hint(ic, name, name);
    150                         if (td->timeline_gc)
     154                        if (td->timeline_gc) {
    151155                                imcb_chat_add_buddy(td->timeline_gc, name);
    152                 } else if (td->flags & TWITTER_MODE_MANY)
     156                        }
     157                } else if (td->flags & TWITTER_MODE_MANY) {
    153158                        imcb_buddy_status(ic, name, OPT_LOGGED_IN, NULL, NULL);
     159                }
    154160        }
    155161}
     
    171177                    err->type == json_object) {
    172178                        const char *msg = json_o_str(err, "message");
    173                         if (msg)
     179                        if (msg) {
    174180                                ret = g_strdup_printf("%s (%s)", req->status_string, msg);
     181                        }
    175182                }
    176183                json_value_free(root);
     
    189196        json_value *ret;
    190197        char path[64] = "", *s;
    191        
     198
    192199        if ((s = strchr(req->request, ' '))) {
    193                 path[sizeof(path)-1] = '\0';
     200                path[sizeof(path) - 1] = '\0';
    194201                strncpy(path, s + 1, sizeof(path) - 1);
    195                 if ((s = strchr(path, '?')) || (s = strchr(path, ' ')))
     202                if ((s = strchr(path, '?')) || (s = strchr(path, ' '))) {
    196203                        *s = '\0';
    197         }
    198        
     204                }
     205        }
     206
    199207        /* Kinda nasty. :-( Trying to suppress error messages, but only
    200208           for periodic (i.e. mentions/timeline) queries. */
    201209        periodic = strstr(path, "timeline") || strstr(path, "mentions");
    202        
     210
    203211        if (req->status_code == 401 && logging_in) {
    204212                /* IIRC Twitter once had an outage where they were randomly
     
    206214                   only during login. */
    207215                imcb_error(ic, "Authentication failure (%s)",
    208                                twitter_parse_error(req));
     216                           twitter_parse_error(req));
    209217                imc_logout(ic, FALSE);
    210218                return NULL;
    211219        } else if (req->status_code != 200) {
    212220                // It didn't go well, output the error and return.
    213                 if (!periodic || logging_in || ++td->http_fails >= 5)
     221                if (!periodic || logging_in || ++td->http_fails >= 5) {
    214222                        twitter_log(ic, "Error: Could not retrieve %s: %s",
    215                                     path, twitter_parse_error(req));
    216                
    217                 if (logging_in)
     223                                    path, twitter_parse_error(req));
     224                }
     225
     226                if (logging_in) {
    218227                        imc_logout(ic, TRUE);
     228                }
    219229                return NULL;
    220230        } else {
     
    224234        if ((ret = json_parse(req->reply_body, req->body_size)) == NULL) {
    225235                imcb_error(ic, "Could not retrieve %s: %s",
    226                            path, "XML parse error");
     236                           path, "XML parse error");
    227237        }
    228238        return ret;
     
    238248        // Primitive, but hey! It works...
    239249        char *args[2];
     250
    240251        args[0] = "cursor";
    241252        args[1] = g_strdup_printf("%" G_GINT64_FORMAT, next_cursor);
     
    257268
    258269        c = json_o_get(node, "ids");
    259         if (!c || c->type != json_array)
     270        if (!c || c->type != json_array) {
    260271                return FALSE;
    261 
    262         for (i = 0; i < c->u.array.length; i ++) {
    263                 if (c->u.array.values[i]->type != json_integer)
     272        }
     273
     274        for (i = 0; i < c->u.array.length; i++) {
     275                if (c->u.array.values[i]->type != json_integer) {
    264276                        continue;
    265                
     277                }
     278
    266279                txl->list = g_slist_prepend(txl->list,
    267                         g_strdup_printf("%" PRIu64, c->u.array.values[i]->u.integer));
    268         }
    269        
     280                                            g_strdup_printf("%" PRIu64, c->u.array.values[i]->u.integer));
     281        }
     282
    270283        c = json_o_get(node, "next_cursor");
    271         if (c && c->type == json_integer)
     284        if (c && c->type == json_integer) {
    272285                txl->next_cursor = c->u.integer;
    273         else
     286        } else {
    274287                txl->next_cursor = -1;
    275        
     288        }
     289
    276290        return TRUE;
    277291}
     
    292306
    293307        // Check if the connection is still active.
    294         if (!g_slist_find(twitter_connections, ic))
    295                 return;
     308        if (!g_slist_find(twitter_connections, ic)) {
     309                return;
     310        }
    296311
    297312        td = ic->proto_data;
     
    301316
    302317        // Parse the data.
    303         if (!(parsed = twitter_parse_response(ic, req)))
    304                 return;
    305        
     318        if (!(parsed = twitter_parse_response(ic, req))) {
     319                return;
     320        }
     321
    306322        twitter_xt_get_friends_id_list(parsed, txl);
    307323        json_value_free(parsed);
    308324
    309325        td->follow_ids = txl->list;
    310         if (txl->next_cursor)
     326        if (txl->next_cursor) {
    311327                /* These were just numbers. Up to 4000 in a response AFAIK so if we get here
    312328                   we may be using a spammer account. \o/ */
    313329                twitter_get_friends_ids(ic, txl->next_cursor);
    314         else
     330        } else {
    315331                /* Now to convert all those numbers into names.. */
    316332                twitter_get_users_lookup(ic);
     333        }
    317334
    318335        txl->list = NULL;
     
    332349        GString *ids = g_string_new("");
    333350        int i;
    334        
     351
    335352        /* We can request up to 100 users at a time. */
    336         for (i = 0; i < 100 && td->follow_ids; i ++) {
    337                 g_string_append_printf(ids, ",%s", (char*) td->follow_ids->data);
     353        for (i = 0; i < 100 && td->follow_ids; i++) {
     354                g_string_append_printf(ids, ",%s", (char *) td->follow_ids->data);
    338355                g_free(td->follow_ids->data);
    339356                td->follow_ids = g_slist_remove(td->follow_ids, td->follow_ids->data);
     
    354371 * Callback for getting (twitter)friends...
    355372 *
    356  * Be afraid, be very afraid! This function will potentially add hundreds of "friends". "Who has 
    357  * hundreds of friends?" you wonder? You probably not, since you are reading the source of 
     373 * Be afraid, be very afraid! This function will potentially add hundreds of "friends". "Who has
     374 * hundreds of friends?" you wonder? You probably not, since you are reading the source of
    358375 * BitlBee... Get a life and meet new people!
    359376 */
     
    367384
    368385        // Check if the connection is still active.
    369         if (!g_slist_find(twitter_connections, ic))
    370                 return;
     386        if (!g_slist_find(twitter_connections, ic)) {
     387                return;
     388        }
    371389
    372390        txl = g_new0(struct twitter_xml_list, 1);
     
    374392
    375393        // Get the user list from the parsed xml feed.
    376         if (!(parsed = twitter_parse_response(ic, req)))
    377                 return;
     394        if (!(parsed = twitter_parse_response(ic, req))) {
     395                return;
     396        }
    378397        twitter_xt_get_users(parsed, txl);
    379398        json_value_free(parsed);
     
    395414        struct twitter_xml_user *txu;
    396415        json_value *jv;
    397        
     416
    398417        txu = g_new0(struct twitter_xml_user, 1);
    399418        txu->name = g_strdup(json_o_str(node, "name"));
    400419        txu->screen_name = g_strdup(json_o_str(node, "screen_name"));
    401        
     420
    402421        jv = json_o_get(node, "id");
    403422        txu->uid = jv->u.integer;
    404        
     423
    405424        return txu;
    406425}
     
    419438        txl->type = TXL_USER;
    420439
    421         if (!node || node->type != json_array)
     440        if (!node || node->type != json_array) {
    422441                return FALSE;
     442        }
    423443
    424444        // The root <users> node should hold the list of users <user>
    425445        // Walk over the nodes children.
    426         for (i = 0; i < node->u.array.length; i ++) {
     446        for (i = 0; i < node->u.array.length; i++) {
    427447                txu = twitter_xt_get_user(node->u.array.values[i]);
    428                 if (txu)
     448                if (txu) {
    429449                        txl->list = g_slist_prepend(txl->list, txu);
     450                }
    430451        }
    431452
     
    453474        struct twitter_xml_status *txs;
    454475        const json_value *rt = NULL, *entities = NULL;
    455        
    456         if (node->type != json_object)
     476
     477        if (node->type != json_object) {
    457478                return FALSE;
     479        }
    458480        txs = g_new0(struct twitter_xml_status, 1);
    459481
    460         JSON_O_FOREACH (node, k, v) {
     482        JSON_O_FOREACH(node, k, v) {
    461483                if (strcmp("text", k) == 0 && v->type == json_string) {
    462484                        txs->text = g_memdup(v->u.string.ptr, v->u.string.length + 1);
     
    470492                           this field. :-( Also assumes the timezone used
    471493                           is UTC since C time handling functions suck. */
    472                         if (strptime(v->u.string.ptr, TWITTER_TIME_FORMAT, &parsed) != NULL)
     494                        if (strptime(v->u.string.ptr, TWITTER_TIME_FORMAT, &parsed) != NULL) {
    473495                                txs->created_at = mktime_utc(&parsed);
     496                        }
    474497                } else if (strcmp("user", k) == 0 && v->type == json_object) {
    475498                        txs->user = twitter_xt_get_user(v);
     
    497520        }
    498521
    499         if (txs->text && txs->user && txs->id)
     522        if (txs->text && txs->user && txs->id) {
    500523                return txs;
    501        
     524        }
     525
    502526        txs_free(txs);
    503527        return NULL;
     
    511535        struct twitter_xml_status *txs;
    512536        const json_value *entities = NULL;
    513        
    514         if (node->type != json_object)
     537
     538        if (node->type != json_object) {
    515539                return FALSE;
     540        }
    516541        txs = g_new0(struct twitter_xml_status, 1);
    517542
    518         JSON_O_FOREACH (node, k, v) {
     543        JSON_O_FOREACH(node, k, v) {
    519544                if (strcmp("text", k) == 0 && v->type == json_string) {
    520545                        txs->text = g_memdup(v->u.string.ptr, v->u.string.length + 1);
     
    526551                           this field. :-( Also assumes the timezone used
    527552                           is UTC since C time handling functions suck. */
    528                         if (strptime(v->u.string.ptr, TWITTER_TIME_FORMAT, &parsed) != NULL)
     553                        if (strptime(v->u.string.ptr, TWITTER_TIME_FORMAT, &parsed) != NULL) {
    529554                                txs->created_at = mktime_utc(&parsed);
     555                        }
    530556                } else if (strcmp("sender", k) == 0 && v->type == json_object) {
    531557                        txs->user = twitter_xt_get_user(v);
     
    539565        }
    540566
    541         if (txs->text && txs->user && txs->id)
     567        if (txs->text && txs->user && txs->id) {
    542568                return txs;
    543        
     569        }
     570
    544571        txs_free(txs);
    545572        return NULL;
    546573}
    547574
    548 static char* expand_entities(char* text, const json_value *entities) {
    549         JSON_O_FOREACH (entities, k, v) {
     575static char* expand_entities(char* text, const json_value *entities)
     576{
     577        JSON_O_FOREACH(entities, k, v) {
    550578                int i;
    551                
    552                 if (v->type != json_array)
     579
     580                if (v->type != json_array) {
    553581                        continue;
    554                 if (strcmp(k, "urls") != 0 && strcmp(k, "media") != 0)
     582                }
     583                if (strcmp(k, "urls") != 0 && strcmp(k, "media") != 0) {
    555584                        continue;
    556                
    557                 for (i = 0; i < v->u.array.length; i ++) {
    558                         if (v->u.array.values[i]->type != json_object)
     585                }
     586
     587                for (i = 0; i < v->u.array.length; i++) {
     588                        if (v->u.array.values[i]->type != json_object) {
    559589                                continue;
    560                        
     590                        }
     591
    561592                        const char *kort = json_o_str(v->u.array.values[i], "url");
    562593                        const char *disp = json_o_str(v->u.array.values[i], "display_url");
    563594                        char *pos, *new;
    564                        
    565                         if (!kort || !disp || !(pos = strstr(text, kort)))
     595
     596                        if (!kort || !disp || !(pos = strstr(text, kort))) {
    566597                                continue;
    567                        
     598                        }
     599
    568600                        *pos = '\0';
    569601                        new = g_strdup_printf("%s%s <%s>%s", text, kort,
    570602                                              disp, pos + strlen(kort));
    571                        
     603
    572604                        g_free(text);
    573605                        text = new;
    574606                }
    575607        }
    576        
     608
    577609        return text;
    578610}
     
    592624        // Set the type of the list.
    593625        txl->type = TXL_STATUS;
    594        
    595         if (node->type != json_array)
     626
     627        if (node->type != json_array) {
    596628                return FALSE;
     629        }
    597630
    598631        // The root <statuses> node should hold the list of statuses <status>
    599632        // Walk over the nodes children.
    600         for (i = 0; i < node->u.array.length; i ++) {
     633        for (i = 0; i < node->u.array.length; i++) {
    601634                txs = twitter_xt_get_status(node->u.array.values[i]);
    602                 if (!txs)
     635                if (!txs) {
    603636                        continue;
    604                
     637                }
     638
    605639                txl->list = g_slist_prepend(txl->list, txs);
    606640        }
     
    612646   Plus, show_ids is on by default and I don't see why anyone would disable it. */
    613647static char *twitter_msg_add_id(struct im_connection *ic,
    614                                 struct twitter_xml_status *txs, const char *prefix)
     648                                struct twitter_xml_status *txs, const char *prefix)
    615649{
    616650        struct twitter_data *td = ic->proto_data;
     
    620654        if (txs->reply_to) {
    621655                int i;
    622                 for (i = 0; i < TWITTER_LOG_LENGTH; i++)
     656                for (i = 0; i < TWITTER_LOG_LENGTH; i++) {
    623657                        if (td->log[i].id == txs->reply_to) {
    624658                                reply_to = i;
    625659                                break;
    626660                        }
     661                }
    627662        }
    628663
     
    636671                }
    637672        }
    638        
     673
    639674        td->log_id = (td->log_id + 1) % TWITTER_LOG_LENGTH;
    640675        td->log[td->log_id].id = txs->id;
    641676        td->log[td->log_id].bu = bee_user_by_handle(ic->bee, ic, txs->user->screen_name);
    642        
     677
    643678        /* This is all getting hairy. :-( If we RT'ed something ourselves,
    644679           remember OUR id instead so undo will work. In other cases, the
    645680           original tweet's id should be remembered for deduplicating. */
    646         if (g_strcasecmp(txs->user->screen_name, td->user) == 0)
     681        if (g_strcasecmp(txs->user->screen_name, td->user) == 0) {
    647682                td->log[td->log_id].id = txs->rt_id;
    648        
     683        }
     684
    649685        if (set_getbool(&ic->acc->set, "show_ids")) {
    650                 if (reply_to != -1)
     686                if (reply_to != -1) {
    651687                        return g_strdup_printf("\002[\002%02x->%02x\002]\002 %s%s",
    652688                                               td->log_id, reply_to, prefix, txs->text);
    653                 else
     689                } else {
    654690                        return g_strdup_printf("\002[\002%02x\002]\002 %s%s",
    655691                                               td->log_id, prefix, txs->text);
     692                }
    656693        } else {
    657                 if (*prefix)
     694                if (*prefix) {
    658695                        return g_strconcat(prefix, txs->text, NULL);
    659                 else
     696                } else {
    660697                        return NULL;
     698                }
    661699        }
    662700}
     
    678716                switch (tf->type) {
    679717                case TWITTER_FILTER_TYPE_FOLLOW:
    680                         if (status->user->uid != tf->uid)
     718                        if (status->user->uid != tf->uid) {
    681719                                continue;
     720                        }
    682721                        break;
    683722
    684723                case TWITTER_FILTER_TYPE_TRACK:
    685                         if (strcasestr(status->text, tf->text) == NULL)
     724                        if (strcasestr(status->text, tf->text) == NULL) {
    686725                                continue;
     726                        }
    687727                        break;
    688728
     
    693733                for (l = tf->groupchats; l; l = g_slist_next(l)) {
    694734                        imcb_chat_msg(l->data, status->user->screen_name,
    695                                       msg ? msg : status->text, 0, 0);
     735                                      msg ? msg : status->text, 0, 0);
    696736                }
    697737        }
     
    713753        gc = twitter_groupchat_init(ic);
    714754
    715         if (!me)
     755        if (!me) {
    716756                /* MUST be done before twitter_msg_add_id() to avoid #872. */
    717757                twitter_add_buddy(ic, status->user->screen_name, status->user->name);
     758        }
    718759        msg = twitter_msg_add_id(ic, status, "");
    719        
     760
    720761        // Say it!
    721762        if (me) {
     
    723764        } else {
    724765                imcb_chat_msg(gc, status->user->screen_name,
    725                               msg ? msg : status->text, 0, status->created_at);
     766                              msg ? msg : status->text, 0, status->created_at);
    726767        }
    727768
     
    744785        }
    745786
    746         if (td->flags & TWITTER_MODE_ONE)
     787        if (td->flags & TWITTER_MODE_ONE) {
    747788                prefix = g_strdup_printf("\002<\002%s\002>\002 ",
    748789                                         status->user->screen_name);
    749         else if (!me)
     790        } else if (!me) {
    750791                twitter_add_buddy(ic, status->user->screen_name, status->user->name);
    751         else
     792        } else {
    752793                prefix = g_strdup("You: ");
     794        }
    753795
    754796        text = twitter_msg_add_id(ic, status, prefix ? prefix : "");
     
    766808        struct twitter_data *td = ic->proto_data;
    767809        char *last_id_str;
    768        
    769         if (status->user == NULL || status->text == NULL)
    770                 return;
    771        
     810
     811        if (status->user == NULL || status->text == NULL) {
     812                return;
     813        }
     814
    772815        /* Grrrr. Would like to do this during parsing, but can't access
    773816           settings from there. */
    774         if (set_getbool(&ic->acc->set, "strip_newlines"))
     817        if (set_getbool(&ic->acc->set, "strip_newlines")) {
    775818                strip_newlines(status->text);
    776        
    777         if (status->from_filter)
     819        }
     820
     821        if (status->from_filter) {
    778822                twitter_status_show_filter(ic, status);
    779         else if (td->flags & TWITTER_MODE_CHAT)
     823        } else if (td->flags & TWITTER_MODE_CHAT) {
    780824                twitter_status_show_chat(ic, status);
    781         else
     825        } else {
    782826                twitter_status_show_msg(ic, status);
     827        }
    783828
    784829        // Update the timeline_id to hold the highest id, so that by the next request
     
    801846        char c, *nl;
    802847        gboolean from_filter;
    803        
    804         if (!g_slist_find(twitter_connections, ic))
    805                 return;
    806        
     848
     849        if (!g_slist_find(twitter_connections, ic)) {
     850                return;
     851        }
     852
    807853        ic->flags |= OPT_PONGED;
    808854        td = ic->proto_data;
    809        
     855
    810856        if ((req->flags & HTTPC_EOF) || !req->reply_body) {
    811                 if (req == td->stream)
     857                if (req == td->stream) {
    812858                        td->stream = NULL;
    813                 else if (req == td->filter_stream)
     859                } else if (req == td->filter_stream) {
    814860                        td->filter_stream = NULL;
     861                }
    815862
    816863                imcb_error(ic, "Stream closed (%s)", req->status_string);
     
    818865                return;
    819866        }
    820        
     867
    821868        /* MUST search for CRLF, not just LF:
    822869           https://dev.twitter.com/docs/streaming-apis/processing#Parsing_responses */
    823         if (!(nl = strstr(req->reply_body, "\r\n")))
    824                 return;
    825        
     870        if (!(nl = strstr(req->reply_body, "\r\n"))) {
     871                return;
     872        }
     873
    826874        len = nl - req->reply_body;
    827875        if (len > 0) {
    828876                c = req->reply_body[len];
    829877                req->reply_body[len] = '\0';
    830                
     878
    831879                if ((parsed = json_parse(req->reply_body, req->body_size))) {
    832880                        from_filter = (req == td->filter_stream);
     
    836884                req->reply_body[len] = c;
    837885        }
    838        
     886
    839887        http_flush_bytes(req, len + 2);
    840        
     888
    841889        /* One notification might bring multiple events! */
    842         if (req->body_size > 0)
     890        if (req->body_size > 0) {
    843891                twitter_http_stream(req);
     892        }
    844893}
    845894
     
    852901        struct twitter_xml_status *txs;
    853902        json_value *c;
    854        
     903
    855904        if ((txs = twitter_xt_get_status(o))) {
    856905                txs->from_filter = from_filter;
     
    860909        } else if ((c = json_o_get(o, "direct_message")) &&
    861910                   (txs = twitter_xt_get_dm(c))) {
    862                 if (g_strcasecmp(txs->user->screen_name, td->user) != 0)
     911                if (g_strcasecmp(txs->user->screen_name, td->user) != 0) {
    863912                        imcb_buddy_msg(ic, txs->user->screen_name,
    864                                        txs->text, 0, txs->created_at);
     913                                       txs->text, 0, txs->created_at);
     914                }
    865915                txs_free(txs);
    866916                return TRUE;
     
    886936        struct twitter_data *td = ic->proto_data;
    887937        int i;
    888        
     938
    889939        for (i = 0; i < TWITTER_LOG_LENGTH; i++) {
    890940                if (td->log[i].id == txs->id) {
     
    893943                }
    894944        }
    895        
     945
    896946        if (!(g_strcasecmp(txs->user->screen_name, td->user) == 0 ||
    897947              set_getbool(&ic->acc->set, "fetch_mentions") ||
     
    905955                return TRUE;
    906956        }
    907        
     957
    908958        twitter_status_show(ic, txs);
    909        
     959
    910960        return TRUE;
    911961}
     
    917967        json_value *target = json_o_get(o, "target");
    918968        const char *type = json_o_str(o, "event");
    919        
     969
    920970        if (!type || !source || source->type != json_object
    921                   || !target || target->type != json_object) {
     971            || !target || target->type != json_object) {
    922972                return FALSE;
    923973        }
    924        
     974
    925975        if (strcmp(type, "follow") == 0) {
    926976                struct twitter_xml_user *us = twitter_xt_get_user(source);
     
    932982                txu_free(ut);
    933983        }
    934        
     984
    935985        return TRUE;
    936986}
     
    939989{
    940990        struct twitter_data *td = ic->proto_data;
    941         char *args[2] = {"with", "followings"};
    942        
     991        char *args[2] = { "with", "followings" };
     992
    943993        if ((td->stream = twitter_http(ic, TWITTER_USER_STREAM_URL,
    944994                                       twitter_http_stream, ic, 0, args, 2))) {
     
    948998                return TRUE;
    949999        }
    950        
     1000
    9511001        return FALSE;
    9521002}
     
    9551005{
    9561006        struct twitter_data *td = ic->proto_data;
    957         char *args[4] = {"follow", NULL, "track", NULL};
     1007        char *args[4] = { "follow", NULL, "track", NULL };
    9581008        GString *followstr = g_string_new("");
    9591009        GString *trackstr = g_string_new("");
     
    9671017                switch (tf->type) {
    9681018                case TWITTER_FILTER_TYPE_FOLLOW:
    969                         if (followstr->len > 0)
     1019                        if (followstr->len > 0) {
    9701020                                g_string_append_c(followstr, ',');
     1021                        }
    9711022
    9721023                        g_string_append_printf(followstr, "%" G_GUINT64_FORMAT,
    973                                                tf->uid);
     1024                                               tf->uid);
    9741025                        break;
    9751026
    9761027                case TWITTER_FILTER_TYPE_TRACK:
    977                         if (trackstr->len > 0)
     1028                        if (trackstr->len > 0) {
    9781029                                g_string_append_c(trackstr, ',');
     1030                        }
    9791031
    9801032                        g_string_append(trackstr, tf->text);
     
    9891041        args[3] = trackstr->str;
    9901042
    991         if (td->filter_stream)
     1043        if (td->filter_stream) {
    9921044                http_close(td->filter_stream);
     1045        }
    9931046
    9941047        if ((td->filter_stream = twitter_http(ic, TWITTER_FILTER_STREAM_URL,
    9951048                                              twitter_http_stream, ic, 0,
    996                                               args, 4))) {
     1049                                              args, 4))) {
    9971050                /* This flag must be enabled or we'll get no data until EOF
    9981051                   (which err, kind of, defeats the purpose of a streaming API). */
     
    10221075
    10231076        // Check if the connection is still active.
    1024         if (!g_slist_find(twitter_connections, ic))
    1025                 return;
     1077        if (!g_slist_find(twitter_connections, ic)) {
     1078                return;
     1079        }
    10261080
    10271081        td = ic->proto_data;
    10281082
    1029         if (!(parsed = twitter_parse_response(ic, req)))
    1030                 return;
     1083        if (!(parsed = twitter_parse_response(ic, req))) {
     1084                return;
     1085        }
    10311086
    10321087        for (l = td->filters; l; l = g_slist_next(l)) {
    10331088                tf = l->data;
    10341089
    1035                 if (tf->type == TWITTER_FILTER_TYPE_FOLLOW)
     1090                if (tf->type == TWITTER_FILTER_TYPE_FOLLOW) {
    10361091                        users = g_list_prepend(users, tf);
    1037         }
    1038 
    1039         if (parsed->type != json_array)
     1092                }
     1093        }
     1094
     1095        if (parsed->type != json_array) {
    10401096                goto finish;
     1097        }
    10411098
    10421099        for (i = 0; i < parsed->u.array.length; i++) {
     
    10441101                name = json_o_str(parsed->u.array.values[i], "screen_name");
    10451102
    1046                 if (!name || !id || id->type != json_integer)
     1103                if (!name || !id || id->type != json_integer) {
    10471104                        continue;
     1105                }
    10481106
    10491107                for (u = users; u; u = g_list_next(u)) {
     
    10621120        twitter_filter_stream(ic);
    10631121
    1064         if (!users)
    1065                 return;
     1122        if (!users) {
     1123                return;
     1124        }
    10661125
    10671126        fstr = g_string_new("");
    10681127
    10691128        for (u = users; u; u = g_list_next(u)) {
    1070                 if (fstr->len > 0)
     1129                if (fstr->len > 0) {
    10711130                        g_string_append(fstr, ", ");
     1131                }
    10721132
    10731133                g_string_append(fstr, tf->text);
     
    10831143{
    10841144        struct twitter_data *td = ic->proto_data;
    1085         char *args[2] = {"screen_name", NULL};
     1145        char *args[2] = { "screen_name", NULL };
    10861146        GString *ustr = g_string_new("");
    10871147        struct twitter_filter *tf;
     
    10921152                tf = l->data;
    10931153
    1094                 if (tf->type != TWITTER_FILTER_TYPE_FOLLOW || tf->uid != 0)
     1154                if (tf->type != TWITTER_FILTER_TYPE_FOLLOW || tf->uid != 0) {
    10951155                        continue;
    1096 
    1097                 if (ustr->len > 0)
     1156                }
     1157
     1158                if (ustr->len > 0) {
    10981159                        g_string_append_c(ustr, ',');
     1160                }
    10991161
    11001162                g_string_append(ustr, tf->text);
     
    11081170        args[1] = ustr->str;
    11091171        req = twitter_http(ic, TWITTER_USERS_LOOKUP_URL,
    1110                            twitter_filter_users_post,
    1111                            ic, 0, args, 2);
     1172                           twitter_filter_users_post,
     1173                           ic, 0, args, 2);
    11121174
    11131175        g_string_free(ustr, TRUE);
     
    11411203                twitter_get_mentions(ic, next_cursor);
    11421204        }
    1143        
     1205
    11441206        return TRUE;
    11451207}
     
    11611223
    11621224        imcb_connected(ic);
    1163        
     1225
    11641226        if (!(td->flags & TWITTER_GOT_TIMELINE)) {
    11651227                return;
     
    11891251        while (output) {
    11901252                struct twitter_xml_status *txs = output->data;
    1191                 if (txs->id != last_id)
     1253                if (txs->id != last_id) {
    11921254                        twitter_status_show(ic, txs);
     1255                }
    11931256                last_id = txs->id;
    11941257                output = g_slist_remove(output, txs);
     
    12271290
    12281291        if (twitter_http(ic, TWITTER_HOME_TIMELINE_URL, twitter_http_get_home_timeline, ic, 0, args,
    1229                      td->timeline_id ? 6 : 4) == NULL) {
    1230                 if (++td->http_fails >= 5)
     1292                         td->timeline_id ? 6 : 4) == NULL) {
     1293                if (++td->http_fails >= 5) {
    12311294                        imcb_error(ic, "Could not retrieve %s: %s",
    12321295                                   TWITTER_HOME_TIMELINE_URL, "connection failed");
     1296                }
    12331297                td->flags |= TWITTER_GOT_TIMELINE;
    12341298                twitter_flush_timeline(ic);
     
    12671331        if (twitter_http(ic, TWITTER_MENTIONS_URL, twitter_http_get_mentions,
    12681332                         ic, 0, args, 6) == NULL) {
    1269                 if (++td->http_fails >= 5)
     1333                if (++td->http_fails >= 5) {
    12701334                        imcb_error(ic, "Could not retrieve %s: %s",
    12711335                                   TWITTER_MENTIONS_URL, "connection failed");
     1336                }
    12721337                td->flags |= TWITTER_GOT_MENTIONS;
    12731338                twitter_flush_timeline(ic);
     
    12891354
    12901355        // Check if the connection is still active.
    1291         if (!g_slist_find(twitter_connections, ic))
    1292                 return;
     1356        if (!g_slist_find(twitter_connections, ic)) {
     1357                return;
     1358        }
    12931359
    12941360        td = ic->proto_data;
     
    12981364
    12991365        // The root <statuses> node should hold the list of statuses <status>
    1300         if (!(parsed = twitter_parse_response(ic, req)))
     1366        if (!(parsed = twitter_parse_response(ic, req))) {
    13011367                goto end;
     1368        }
    13021369        twitter_xt_get_status_list(ic, parsed, txl);
    13031370        json_value_free(parsed);
     
    13051372        td->home_timeline_obj = txl;
    13061373
    1307       end:
    1308         if (!g_slist_find(twitter_connections, ic))
    1309                 return;
     1374end:
     1375        if (!g_slist_find(twitter_connections, ic)) {
     1376                return;
     1377        }
    13101378
    13111379        td->flags |= TWITTER_GOT_TIMELINE;
     
    13251393
    13261394        // Check if the connection is still active.
    1327         if (!g_slist_find(twitter_connections, ic))
    1328                 return;
     1395        if (!g_slist_find(twitter_connections, ic)) {
     1396                return;
     1397        }
    13291398
    13301399        td = ic->proto_data;
     
    13341403
    13351404        // The root <statuses> node should hold the list of statuses <status>
    1336         if (!(parsed = twitter_parse_response(ic, req)))
     1405        if (!(parsed = twitter_parse_response(ic, req))) {
    13371406                goto end;
     1407        }
    13381408        twitter_xt_get_status_list(ic, parsed, txl);
    13391409        json_value_free(parsed);
     
    13411411        td->mentions_obj = txl;
    13421412
    1343       end:
    1344         if (!g_slist_find(twitter_connections, ic))
    1345                 return;
     1413end:
     1414        if (!g_slist_find(twitter_connections, ic)) {
     1415                return;
     1416        }
    13461417
    13471418        td->flags |= TWITTER_GOT_MENTIONS;
     
    13611432
    13621433        // Check if the connection is still active.
    1363         if (!g_slist_find(twitter_connections, ic))
    1364                 return;
     1434        if (!g_slist_find(twitter_connections, ic)) {
     1435                return;
     1436        }
    13651437
    13661438        td = ic->proto_data;
    13671439        td->last_status_id = 0;
    13681440
    1369         if (!(parsed = twitter_parse_response(ic, req)))
    1370                 return;
    1371        
     1441        if (!(parsed = twitter_parse_response(ic, req))) {
     1442                return;
     1443        }
     1444
    13721445        if ((id = json_o_get(parsed, "id")) && id->type == json_integer) {
    13731446                td->last_status_id = id->u.integer;
    13741447        }
    1375        
     1448
    13761449        json_value_free(parsed);
    1377        
    1378         if (req->flags & TWITTER_HTTP_USER_ACK)
     1450
     1451        if (req->flags & TWITTER_HTTP_USER_ACK) {
    13791452                twitter_log(ic, "Command processed successfully");
     1453        }
    13801454}
    13811455
     
    13901464                g_strdup_printf("%" G_GUINT64_FORMAT, in_reply_to)
    13911465        };
     1466
    13921467        twitter_http(ic, TWITTER_STATUS_UPDATE_URL, twitter_http_post, ic, 1,
    1393                      args, in_reply_to ? 4 : 2);
     1468                     args, in_reply_to ? 4 : 2);
    13941469        g_free(args[3]);
    13951470}
     
    14021477{
    14031478        char *args[4];
     1479
    14041480        args[0] = "screen_name";
    14051481        args[1] = who;
     
    14131489{
    14141490        char *args[2];
     1491
    14151492        args[0] = "screen_name";
    14161493        args[1] = who;
    14171494        twitter_http(ic, create ? TWITTER_FRIENDSHIPS_CREATE_URL : TWITTER_FRIENDSHIPS_DESTROY_URL,
    1418                      twitter_http_post, ic, 1, args, 2);
     1495                     twitter_http_post, ic, 1, args, 2);
    14191496}
    14201497
     
    14221499{
    14231500        char *url;
     1501
    14241502        url = g_strdup_printf("%s%" G_GUINT64_FORMAT "%s",
    14251503                              TWITTER_STATUS_DESTROY_URL, id, ".json");
     
    14321510{
    14331511        char *url;
     1512
    14341513        url = g_strdup_printf("%s%" G_GUINT64_FORMAT "%s",
    14351514                              TWITTER_STATUS_RETWEET_URL, id, ".json");
     
    14481527                NULL,
    14491528        };
     1529
    14501530        args[1] = screen_name;
    14511531        twitter_http_f(ic, TWITTER_REPORT_SPAM_URL, twitter_http_post,
     
    14621542                NULL,
    14631543        };
     1544
    14641545        args[1] = g_strdup_printf("%" G_GUINT64_FORMAT, id);
    14651546        twitter_http_f(ic, TWITTER_FAVORITE_CREATE_URL, twitter_http_post,
Note: See TracChangeset for help on using the changeset viewer.