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.c

    raf359b4 r5ebff60  
    9191        struct twitter_data *td = c->ic->proto_data;
    9292        struct twitter_filter *tf = NULL;
    93         struct twitter_filter tfc = {type, (char*) text};
     93        struct twitter_filter tfc = { type, (char *) text };
    9494        GSList *l;
    9595
     
    9797                tf = l->data;
    9898
    99                 if (twitter_filter_cmp(tf, &tfc) == 0)
     99                if (twitter_filter_cmp(tf, &tfc) == 0) {
    100100                        break;
     101                }
    101102
    102103                tf = NULL;
     
    110111        }
    111112
    112         if (!g_slist_find(tf->groupchats, c))
     113        if (!g_slist_find(tf->groupchats, c)) {
    113114                tf->groupchats = g_slist_prepend(tf->groupchats, c);
    114 
    115         if (td->filter_update_id > 0)
     115        }
     116
     117        if (td->filter_update_id > 0) {
    116118                b_event_remove(td->filter_update_id);
     119        }
    117120
    118121        /* Wait for other possible filter changes to avoid request spam */
    119122        td->filter_update_id = b_timeout_add(TWITTER_FILTER_UPDATE_WAIT,
    120                                              twitter_filter_update, c->ic);
     123                                             twitter_filter_update, c->ic);
    121124        return tf;
    122125}
     
    149152        }
    150153
    151         if (td->filter_update_id > 0)
     154        if (td->filter_update_id > 0) {
    152155                b_event_remove(td->filter_update_id);
     156        }
    153157
    154158        /* Wait for other possible filter changes to avoid request spam */
    155159        td->filter_update_id = b_timeout_add(TWITTER_FILTER_UPDATE_WAIT,
    156                                              twitter_filter_update, c->ic);}
     160                                             twitter_filter_update, c->ic);
     161}
    157162
    158163static void twitter_filter_remove_all(struct im_connection *ic)
     
    169174                /* Build up a list of groupchats to be freed */
    170175                for (p = tf->groupchats; p; p = g_slist_next(p)) {
    171                         if (!g_slist_find(chats, p->data))
     176                        if (!g_slist_find(chats, p->data)) {
    172177                                chats = g_slist_prepend(chats, p->data);
     178                        }
    173179                }
    174180
     
    217223
    218224        for (f = fs; *f; f++) {
    219                 if ((v = strchr(*f, ':')) == NULL)
     225                if ((v = strchr(*f, ':')) == NULL) {
    220226                        continue;
     227                }
    221228
    222229                *(v++) = 0;
     
    229236                }
    230237
    231                 if (t < 0 || strlen(v) == 0)
     238                if (t < 0 || strlen(v) == 0) {
    232239                        continue;
     240                }
    233241
    234242                tf = twitter_filter_get(c, types[t], v);
     
    248256
    249257        // Check if we are still logged in...
    250         if (!g_slist_find(twitter_connections, ic))
     258        if (!g_slist_find(twitter_connections, ic)) {
    251259                return FALSE;
     260        }
    252261
    253262        // Do stuff..
     
    261270
    262271        char *last_tweet = set_getstr(&ic->acc->set, "_last_tweet");
    263         if (last_tweet)
     272
     273        if (last_tweet) {
    264274                td->timeline_id = g_ascii_strtoull(last_tweet, NULL, 0);
     275        }
    265276
    266277        /* Create the room now that we "logged in". */
    267         if (td->flags & TWITTER_MODE_CHAT)
     278        if (td->flags & TWITTER_MODE_CHAT) {
    268279                twitter_groupchat_init(ic);
     280        }
    269281
    270282        imcb_log(ic, "Getting initial statuses");
     
    273285        // stream if available).
    274286        twitter_main_loop(ic, -1, 0);
    275        
     287
    276288        if (set_getbool(&ic->acc->set, "stream")) {
    277289                /* That fetch was just to get backlog, the stream will give
    278290                   us the rest. \o/ */
    279291                twitter_open_stream(ic);
    280                
     292
    281293                /* Stream sends keepalives (empty lines) or actual data at
    282294                   least twice a minute. Disconnect if this stops. */
     
    286298                   fashioned way. :-( */
    287299                td->main_loop_id =
    288                     b_timeout_add(set_getint(&ic->acc->set, "fetch_interval") * 1000,
    289                                   twitter_main_loop, ic);
     300                        b_timeout_add(set_getint(&ic->acc->set, "fetch_interval") * 1000,
     301                                      twitter_main_loop, ic);
    290302        }
    291303}
     
    298310        GSList *l;
    299311
    300         if (td->timeline_gc)
     312        if (td->timeline_gc) {
    301313                return td->timeline_gc;
     314        }
    302315
    303316        td->timeline_gc = gc = imcb_chat_new(ic, "twitter/timeline");
     
    309322        for (l = ic->bee->users; l; l = l->next) {
    310323                bee_user_t *bu = l->data;
    311                 if (bu->ic == ic)
     324                if (bu->ic == ic) {
    312325                        imcb_chat_add_buddy(gc, bu->handle);
     326                }
    313327        }
    314328        imcb_chat_add_buddy(gc, ic->acc->user);
    315        
     329
    316330        return gc;
    317331}
     
    325339        td->flags &= ~TWITTER_DOING_TIMELINE;
    326340
    327         if (set_getbool(&ic->acc->set, "oauth") && !td->oauth_info)
     341        if (set_getbool(&ic->acc->set, "oauth") && !td->oauth_info) {
    328342                twitter_oauth_start(ic);
    329         else if (!(td->flags & TWITTER_MODE_ONE) &&
    330                  !(td->flags & TWITTER_HAVE_FRIENDS)) {
     343        } else if (!(td->flags & TWITTER_MODE_ONE) &&
     344                   !(td->flags & TWITTER_HAVE_FRIENDS)) {
    331345                imcb_log(ic, "Getting contact list");
    332346                twitter_get_friends_ids(ic, -1);
    333         } else
     347        } else {
    334348                twitter_main_loop_start(ic);
     349        }
    335350}
    336351
     
    357372        struct twitter_data *td = ic->proto_data;
    358373
    359         if (strstr(td->url_host, "identi.ca"))
     374        if (strstr(td->url_host, "identi.ca")) {
    360375                return &identica_oauth;
    361         else
     376        } else {
    362377                return &twitter_oauth;
     378        }
    363379
    364380        /* Could add more services, or allow configuring your own base URL +
     
    372388
    373389        imcb_log(ic, "Requesting OAuth request token");
    374        
    375         if (!strstr(url, "twitter.com") && !strstr(url, "identi.ca"))
     390
     391        if (!strstr(url, "twitter.com") && !strstr(url, "identi.ca")) {
    376392                imcb_log(ic, "Warning: OAuth only works with identi.ca and "
    377                              "Twitter.");
     393                         "Twitter.");
     394        }
    378395
    379396        td->oauth_info = oauth_request_token(get_oauth_service(ic), twitter_oauth_callback, ic);
     
    389406        struct twitter_data *td;
    390407
    391         if (!g_slist_find(twitter_connections, ic))
     408        if (!g_slist_find(twitter_connections, ic)) {
    392409                return FALSE;
     410        }
    393411
    394412        td = ic->proto_data;
     
    404422                name = g_strdup_printf("%s_%s", td->prefix, ic->acc->user);
    405423                msg = g_strdup_printf("To finish OAuth authentication, please visit "
    406                                       "%s and respond with the resulting PIN code.",
    407                                       info->auth_url);
     424                                      "%s and respond with the resulting PIN code.",
     425                                      info->auth_url);
    408426                imcb_buddy_msg(ic, name, msg, 0, 0);
    409427                g_free(name);
     
    411429        } else if (info->stage == OAUTH_ACCESS_TOKEN) {
    412430                const char *sn;
    413                
     431
    414432                if (info->token == NULL || info->token_secret == NULL) {
    415433                        imcb_error(ic, "OAuth error: %s", twitter_parse_error(info->http));
     
    417435                        return FALSE;
    418436                }
    419                
     437
    420438                if ((sn = oauth_params_get(&info->params, "screen_name"))) {
    421                         if (ic->acc->prpl->handle_cmp(sn, ic->acc->user) != 0)
     439                        if (ic->acc->prpl->handle_cmp(sn, ic->acc->user) != 0) {
    422440                                imcb_log(ic, "Warning: You logged in via OAuth as %s "
    423441                                         "instead of %s.", sn, ic->acc->user);
     442                        }
    424443                        g_free(td->user);
    425444                        td->user = g_strdup(sn);
     
    444463        GMatchInfo *match_info;
    445464
    446         if (regex == NULL)
     465        if (regex == NULL) {
    447466                regex = g_regex_new("(^|\\s)(http(s)?://[^\\s$]+)", 0, 0, NULL);
    448        
     467        }
     468
    449469        g_regex_match(regex, msg, 0, &match_info);
    450470        while (g_match_info_matches(match_info)) {
     
    452472                url_len_diff += target_len - g_utf8_strlen(url, -1);
    453473                /* Add another character for https://t.co/... URLs */
    454                 if (g_match_info_fetch(match_info, 3) != NULL)
     474                if (g_match_info_fetch(match_info, 3) != NULL) {
    455475                        url_len_diff += 1;
     476                }
    456477                g_free(url);
    457478                g_match_info_next(match_info, NULL);
     
    468489        int url_len_diff = 0;
    469490
    470         if (target_len > 0)
     491        if (target_len > 0) {
    471492                url_len_diff = twitter_url_len_diff(msg, target_len);
    472 
    473         if (max == 0 || (len = g_utf8_strlen(msg, -1) + url_len_diff) <= max)
     493        }
     494
     495        if (max == 0 || (len = g_utf8_strlen(msg, -1) + url_len_diff) <= max) {
    474496                return TRUE;
     497        }
    475498
    476499        twitter_log(ic, "Maximum message length exceeded: %d > %d", len, max);
     
    481504static char *set_eval_commands(set_t * set, char *value)
    482505{
    483         if (g_strcasecmp(value, "strict") == 0 )
     506        if (g_strcasecmp(value, "strict") == 0) {
    484507                return value;
    485         else
     508        } else {
    486509                return set_eval_bool(set, value);
     510        }
    487511}
    488512
     
    490514{
    491515        if (g_strcasecmp(value, "one") == 0 ||
    492             g_strcasecmp(value, "many") == 0 || g_strcasecmp(value, "chat") == 0)
     516            g_strcasecmp(value, "many") == 0 || g_strcasecmp(value, "chat") == 0) {
    493517                return value;
    494         else
     518        } else {
    495519                return NULL;
     520        }
    496521}
    497522
     
    507532                def_tul = "22";
    508533                def_mentions = "true";
    509         } else {                /* if( strcmp( acc->prpl->name, "identica" ) == 0 ) */
     534        } else {                /* if( strcmp( acc->prpl->name, "identica" ) == 0 ) */
    510535                def_url = IDENTICA_API_URL;
    511536                def_tul = "0";
     
    539564
    540565        s = set_add(&acc->set, "strip_newlines", "false", set_eval_bool, acc);
    541        
     566
    542567        s = set_add(&acc->set, "_last_tweet", "0", NULL, acc);
    543568        s->flags |= SET_HIDDEN | SET_NOSAVE;
     
    560585        url_t url;
    561586        char *s;
    562        
     587
    563588        if (!url_set(&url, set_getstr(&ic->acc->set, "base_url")) ||
    564589            (url.proto != PROTO_HTTP && url.proto != PROTO_HTTPS)) {
     
    571596            set_getbool(&ic->acc->set, "stream")) {
    572597                imcb_error(ic, "Warning: The streaming API is only supported by Twitter, "
    573                                "and you seem to be connecting to a different service.");
     598                           "and you seem to be connecting to a different service.");
    574599        }
    575600
     
    584609        td->url_port = url.port;
    585610        td->url_host = g_strdup(url.host);
    586         if (strcmp(url.file, "/") != 0)
     611        if (strcmp(url.file, "/") != 0) {
    587612                td->url_path = g_strdup(url.file);
    588         else {
     613        } else {
    589614                td->url_path = g_strdup("");
    590                 if (g_str_has_suffix(url.host, "twitter.com"))
     615                if (g_str_has_suffix(url.host, "twitter.com")) {
    591616                        /* May fire for people who turned on HTTPS. */
    592617                        imcb_error(ic, "Warning: Twitter requires a version number in API calls "
    593                                        "now. Try resetting the base_url account setting.");
    594         }
    595        
     618                                   "now. Try resetting the base_url account setting.");
     619                }
     620        }
     621
    596622        /* Hacky string mangling: Turn identi.ca into identi.ca and api.twitter.com
    597623           into twitter, and try to be sensible if we get anything else. */
    598624        td->prefix = g_strdup(url.host);
    599         if (g_str_has_suffix(td->prefix, ".com"))
     625        if (g_str_has_suffix(td->prefix, ".com")) {
    600626                td->prefix[strlen(url.host) - 4] = '\0';
     627        }
    601628        if ((s = strrchr(td->prefix, '.')) && strlen(s) > 4) {
    602629                /* If we have at least 3 chars after the last dot, cut off the rest.
     
    606633                td->prefix = s;
    607634        }
    608        
    609         if (strstr(acc->pass, "oauth_token="))
     635
     636        if (strstr(acc->pass, "oauth_token=")) {
    610637                td->oauth_info = oauth_from_string(acc->pass, get_oauth_service(ic));
     638        }
    611639
    612640        sprintf(name, "%s_%s", td->prefix, acc->user);
     
    616644        td->log = g_new0(struct twitter_log_data, TWITTER_LOG_LENGTH);
    617645        td->log_id = -1;
    618        
     646
    619647        s = set_getstr(&ic->acc->set, "mode");
    620         if (g_strcasecmp(s, "one") == 0)
     648        if (g_strcasecmp(s, "one") == 0) {
    621649                td->flags |= TWITTER_MODE_ONE;
    622         else if (g_strcasecmp(s, "many") == 0)
     650        } else if (g_strcasecmp(s, "many") == 0) {
    623651                td->flags |= TWITTER_MODE_MANY;
    624         else
     652        } else {
    625653                td->flags |= TWITTER_MODE_CHAT;
     654        }
    626655
    627656        twitter_login_finish(ic);
     
    641670        b_event_remove(td->main_loop_id);
    642671
    643         if (td->timeline_gc)
     672        if (td->timeline_gc) {
    644673                imcb_chat_free(td->timeline_gc);
     674        }
    645675
    646676        if (td) {
    647                 if (td->filter_update_id > 0)
     677                if (td->filter_update_id > 0) {
    648678                        b_event_remove(td->filter_update_id);
     679                }
    649680
    650681                http_close(td->stream);
     
    679710
    680711                        strcpy(pin, message);
    681                         for (s = pin + sizeof(pin) - 2; s > pin && g_ascii_isspace(*s); s--)
     712                        for (s = pin + sizeof(pin) - 2; s > pin && g_ascii_isspace(*s); s--) {
    682713                                *s = '\0';
     714                        }
    683715                        for (s = pin; *s && g_ascii_isspace(*s); s++) {
    684716                        }
     
    686718                        if (!oauth_access_token(s, td->oauth_info)) {
    687719                                imcb_error(ic, "OAuth error: %s",
    688                                            "Failed to send access token request");
     720                                           "Failed to send access token request");
    689721                                imc_logout(ic, TRUE);
    690722                                return FALSE;
    691723                        }
    692                 } else
     724                } else {
    693725                        twitter_handle_command(ic, message);
     726                }
    694727        } else {
    695728                twitter_direct_messages_new(ic, who, message);
     
    714747static void twitter_chat_msg(struct groupchat *c, char *message, int flags)
    715748{
    716         if (c && message)
     749        if (c && message) {
    717750                twitter_handle_command(c->ic, message);
     751        }
    718752}
    719753
     
    737771                tf = l->data;
    738772
    739                 if (topic->len > 0)
     773                if (topic->len > 0) {
    740774                        g_string_append(topic, ", ");
    741 
    742                 if (tf->type == TWITTER_FILTER_TYPE_FOLLOW)
     775                }
     776
     777                if (tf->type == TWITTER_FILTER_TYPE_FOLLOW) {
    743778                        g_string_append_c(topic, '@');
     779                }
    744780
    745781                g_string_append(topic, tf->text);
    746782        }
    747783
    748         if (topic->len > 0)
     784        if (topic->len > 0) {
    749785                g_string_prepend(topic, "Twitter Filter: ");
     786        }
    750787
    751788        imcb_chat_topic(c, NULL, topic->str, 0);
     
    820857 *  Returns 0 if the user provides garbage.
    821858 */
    822 static guint64 twitter_message_id_from_command_arg(struct im_connection *ic, char *arg, bee_user_t **bu_) {
     859static guint64 twitter_message_id_from_command_arg(struct im_connection *ic, char *arg, bee_user_t **bu_)
     860{
    823861        struct twitter_data *td = ic->proto_data;
    824862        struct twitter_user_data *tud;
    825863        bee_user_t *bu = NULL;
    826864        guint64 id = 0;
    827        
    828         if (bu_)
     865
     866        if (bu_) {
    829867                *bu_ = NULL;
    830         if (!arg || !arg[0])
     868        }
     869        if (!arg || !arg[0]) {
    831870                return 0;
    832        
     871        }
     872
    833873        if (arg[0] != '#' && (bu = bee_user_by_handle(ic->bee, ic, arg))) {
    834                 if ((tud = bu->data))
     874                if ((tud = bu->data)) {
    835875                        id = tud->last_id;
     876                }
    836877        } else {
    837                 if (arg[0] == '#')
     878                if (arg[0] == '#') {
    838879                        arg++;
     880                }
    839881                if (sscanf(arg, "%" G_GINT64_MODIFIER "x", &id) == 1 &&
    840882                    id < TWITTER_LOG_LENGTH) {
     
    842884                        id = td->log[id].id;
    843885                        /* Beware of dangling pointers! */
    844                         if (!g_slist_find(ic->bee->users, bu))
     886                        if (!g_slist_find(ic->bee->users, bu)) {
    845887                                bu = NULL;
     888                        }
    846889                } else if (sscanf(arg, "%" G_GINT64_MODIFIER "d", &id) == 1) {
    847890                        /* Allow normal tweet IDs as well; not a very useful
    848891                           feature but it's always been there. Just ignore
    849892                           very low IDs to avoid accidents. */
    850                         if (id < 1000000)
     893                        if (id < 1000000) {
    851894                                id = 0;
    852                 }
    853         }
    854         if (bu_)
     895                        }
     896                }
     897        }
     898        if (bu_) {
    855899                *bu_ = bu;
     900        }
    856901        return id;
    857902}
     
    863908        guint64 in_reply_to = 0, id;
    864909        gboolean allow_post =
    865                 g_strcasecmp(set_getstr(&ic->acc->set, "commands"), "strict") != 0;
     910                g_strcasecmp(set_getstr(&ic->acc->set, "commands"), "strict") != 0;
    866911        bee_user_t *bu = NULL;
    867912
     
    874919                /* Not supporting commands if "commands" is set to true/strict. */
    875920        } else if (g_strcasecmp(cmd[0], "undo") == 0) {
    876                 if (cmd[1] == NULL)
     921                if (cmd[1] == NULL) {
    877922                        twitter_status_destroy(ic, td->last_status_id);
    878                 else if ((id = twitter_message_id_from_command_arg(ic, cmd[1], NULL)))
     923                } else if ((id = twitter_message_id_from_command_arg(ic, cmd[1], NULL))) {
    879924                        twitter_status_destroy(ic, id);
    880                 else
     925                } else {
    881926                        twitter_log(ic, "Could not undo last action");
     927                }
    882928
    883929                goto eof;
    884930        } else if ((g_strcasecmp(cmd[0], "favourite") == 0 ||
    885                     g_strcasecmp(cmd[0], "favorite") == 0 ||
    886                     g_strcasecmp(cmd[0], "fav") == 0) && cmd[1]) {
     931                    g_strcasecmp(cmd[0], "favorite") == 0 ||
     932                    g_strcasecmp(cmd[0], "fav") == 0) && cmd[1]) {
    887933                if ((id = twitter_message_id_from_command_arg(ic, cmd[1], NULL))) {
    888934                        twitter_favourite_tweet(ic, id);
     
    900946                    g_strcasecmp(cmd[0], "spam") == 0) && cmd[1]) {
    901947                char *screen_name;
    902                
     948
    903949                /* Report nominally works on users but look up the user who
    904950                   posted the given ID if the user wants to do it that way */
    905951                twitter_message_id_from_command_arg(ic, cmd[1], &bu);
    906                 if (bu)
     952                if (bu) {
    907953                        screen_name = bu->handle;
    908                 else
     954                } else {
    909955                        screen_name = cmd[1];
    910                
     956                }
     957
    911958                twitter_report_spam(ic, screen_name);
    912959                goto eof;
     
    915962
    916963                td->last_status_id = 0;
    917                 if (id)
     964                if (id) {
    918965                        twitter_status_retweet(ic, id);
    919                 else
     966                } else {
    920967                        twitter_log(ic, "User `%s' does not exist or didn't "
    921                                     "post any statuses recently", cmd[1]);
     968                                    "post any statuses recently", cmd[1]);
     969                }
    922970
    923971                goto eof;
     
    926974                if (!id || !bu) {
    927975                        twitter_log(ic, "User `%s' does not exist or didn't "
    928                                     "post any statuses recently", cmd[1]);
     976                                    "post any statuses recently", cmd[1]);
    929977                        goto eof;
    930978                }
     
    949997                char *s;
    950998
    951                 if (!twitter_length_check(ic, message))
     999                if (!twitter_length_check(ic, message)) {
    9521000                        goto eof;
     1001                }
    9531002
    9541003                s = cmd[0] + strlen(cmd[0]) - 1;
     
    9601009
    9611010                                new = g_strdup_printf("@%s %s", bu->handle,
    962                                                       message + (s - cmd[0]) + 2);
     1011                                                      message + (s - cmd[0]) + 2);
    9631012                                message = new;
    9641013
    9651014                                if (time(NULL) < tud->last_time +
    966                                     set_getint(&ic->acc->set, "auto_reply_timeout"))
     1015                                    set_getint(&ic->acc->set, "auto_reply_timeout")) {
    9671016                                        in_reply_to = tud->last_id;
     1017                                }
    9681018                        }
    9691019                }
     
    9811031}
    9821032
    983 void twitter_log(struct im_connection *ic, char *format, ... )
     1033void twitter_log(struct im_connection *ic, char *format, ...)
    9841034{
    9851035        struct twitter_data *td = ic->proto_data;
    9861036        va_list params;
    9871037        char *text;
    988        
     1038
    9891039        va_start(params, format);
    9901040        text = g_strdup_vprintf(format, params);
    9911041        va_end(params);
    992        
    993         if (td->timeline_gc)
     1042
     1043        if (td->timeline_gc) {
    9941044                imcb_chat_log(td->timeline_gc, "%s", text);
    995         else
     1045        } else {
    9961046                imcb_log(ic, "%s", text);
    997        
     1047        }
     1048
    9981049        g_free(text);
    9991050}
Note: See TracChangeset for help on using the changeset viewer.