Changeset 7733b8c


Ignore:
Timestamp:
2015-02-21T06:10:54Z (10 years ago)
Author:
dequis <dx@…>
Children:
75ad761
Parents:
5ebff60
git-author:
dequis <dx@…> (19-07-14 04:51:58)
git-committer:
dequis <dx@…> (21-02-15 06:10:54)
Message:

Add the concept of jabber sub-protocols

Currently including: jabber (none), gtalk, facebook, hipchat.

They provide a default server field and an oauth service definition.

Also the "account tag guesses" become subprotocol guesses

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • protocols/account.c

    r5ebff60 r7733b8c  
    8383                } else {
    8484                        strcpy(tag, "aim");
    85                 }
    86         } else if (strcmp(prpl->name, "jabber") == 0) {
    87                 if (strstr(a->user, "@gmail.com") ||
    88                     strstr(a->user, "@googlemail.com")) {
    89                         strcpy(tag, "gtalk");
    90                 } else if (strstr(a->user, "@chat.facebook.com")) {
    91                         strcpy(tag, "fb");
    9285                }
    9386        }
  • protocols/jabber/jabber.c

    r5ebff60 r7733b8c  
    5454};
    5555
     56static jabber_subproto_desc_t jabber_subproto_list[] = {
     57        { "jabber", JSUB_NONE, NULL, NULL },
     58        { "gtalk", JSUB_GTALK, &oauth2_service_google, "talk.google.com" },
     59        { "fb", JSUB_FACEBOOK, &oauth2_service_facebook, "chat.facebook.com" },
     60        { "hipchat", JSUB_HIPCHAT, NULL, "chat.hipchat.com" },
     61        { NULL },
     62};
     63
    5664static void jabber_init(account_t *acc)
    5765{
    5866        set_t *s;
    5967        char str[16];
     68        jabber_subproto_desc_t *subproto = acc->prpl->data;
    6069
    6170        s = set_add(&acc->set, "activity_timeout", "600", set_eval_int, acc);
    6271
    63         s = set_add(&acc->set, "oauth", "false", set_eval_oauth, acc);
    64 
    6572        s = set_add(&acc->set, "display_name", NULL, NULL, acc);
     73
     74        if (subproto->oauth2_service) {
     75                s = set_add(&acc->set, "oauth", "false", set_eval_oauth, acc);
     76        }
    6677
    6778        g_snprintf(str, sizeof(str), "%d", jabber_port_list[0]);
     
    100111        acc->flags |= ACC_FLAG_AWAY_MESSAGE | ACC_FLAG_STATUS_MESSAGE |
    101112                      ACC_FLAG_HANDLE_DOMAINS;
     113
     114        if (subproto->server) {
     115                set_setstr(&acc->set, "server", (char *) subproto->server);
     116        }
    102117}
    103118
     
    108123        struct im_connection *ic = imcb_new(acc);
    109124        struct jabber_data *jd = g_new0(struct jabber_data, 1);
     125        jabber_subproto_desc_t *subproto = acc->prpl->data;
    110126        char *s;
    111127
     
    117133        jd->ic = ic;
    118134        ic->proto_data = jd;
     135        jd->subproto = subproto->id;
    119136
    120137        jabber_set_me(ic, acc->user);
     
    141158        jd->buddies = g_hash_table_new(g_str_hash, g_str_equal);
    142159
    143         if (set_getbool(&acc->set, "oauth")) {
     160        if (subproto->oauth2_service && set_getbool(&acc->set, "oauth")) {
    144161                GSList *p_in = NULL;
    145162                const char *tok;
     
    147164                jd->fd = jd->r_inpa = jd->w_inpa = -1;
    148165
    149                 if (strstr(jd->server, ".facebook.com")) {
    150                         jd->oauth2_service = &oauth2_service_facebook;
    151                 } else {
    152                         jd->oauth2_service = &oauth2_service_google;
    153                 }
     166                jd->oauth2_service = subproto->oauth2_service;
    154167
    155168                oauth_params_parse(&p_in, ic->acc->pass);
     
    655668void jabber_initmodule()
    656669{
    657         struct prpl *ret = g_new0(struct prpl, 1);
    658 
    659         ret->name = "jabber";
    660         ret->mms = 0;                        /* no limit */
    661         ret->login = jabber_login;
    662         ret->init = jabber_init;
    663         ret->logout = jabber_logout;
    664         ret->buddy_msg = jabber_buddy_msg;
    665         ret->away_states = jabber_away_states;
    666         ret->set_away = jabber_set_away;
    667 //      ret->set_info = jabber_set_info;
    668         ret->get_info = jabber_get_info;
    669         ret->add_buddy = jabber_add_buddy;
    670         ret->remove_buddy = jabber_remove_buddy;
    671         ret->chat_msg = jabber_chat_msg_;
    672         ret->chat_topic = jabber_chat_topic_;
    673         ret->chat_invite = jabber_chat_invite_;
    674         ret->chat_leave = jabber_chat_leave_;
    675         ret->chat_join = jabber_chat_join_;
    676         ret->chat_with = jabber_chat_with_;
    677         ret->chat_add_settings = jabber_chat_add_settings;
    678         ret->chat_free_settings = jabber_chat_free_settings;
    679         ret->keepalive = jabber_keepalive;
    680         ret->send_typing = jabber_send_typing;
    681         ret->handle_cmp = g_strcasecmp;
    682         ret->handle_is_self = jabber_handle_is_self;
    683         ret->transfer_request = jabber_si_transfer_request;
    684         ret->buddy_action_list = jabber_buddy_action_list;
    685         ret->buddy_action = jabber_buddy_action;
    686 
    687         register_protocol(ret);
    688 }
     670        int i;
     671        struct prpl funcs;
     672
     673        memset(&funcs, 0, sizeof(funcs));
     674
     675        funcs.mms = 0;                        /* no limit */
     676        funcs.login = jabber_login;
     677        funcs.init = jabber_init;
     678        funcs.logout = jabber_logout;
     679        funcs.buddy_msg = jabber_buddy_msg;
     680        funcs.away_states = jabber_away_states;
     681        funcs.set_away = jabber_set_away;
     682        funcs.get_info = jabber_get_info;
     683        funcs.add_buddy = jabber_add_buddy;
     684        funcs.remove_buddy = jabber_remove_buddy;
     685        funcs.chat_msg = jabber_chat_msg_;
     686        funcs.chat_topic = jabber_chat_topic_;
     687        funcs.chat_invite = jabber_chat_invite_;
     688        funcs.chat_leave = jabber_chat_leave_;
     689        funcs.chat_join = jabber_chat_join_;
     690        funcs.chat_with = jabber_chat_with_;
     691        funcs.chat_add_settings = jabber_chat_add_settings;
     692        funcs.chat_free_settings = jabber_chat_free_settings;
     693        funcs.keepalive = jabber_keepalive;
     694        funcs.send_typing = jabber_send_typing;
     695        funcs.handle_cmp = g_strcasecmp;
     696        funcs.handle_is_self = jabber_handle_is_self;
     697        funcs.transfer_request = jabber_si_transfer_request;
     698        funcs.buddy_action_list = jabber_buddy_action_list;
     699        funcs.buddy_action = jabber_buddy_action;
     700
     701        for (i = 0; jabber_subproto_list[i].name; i++) {
     702                struct prpl *subproto = g_memdup(&funcs, sizeof(funcs));
     703                subproto->name = jabber_subproto_list[i].name;
     704                subproto->data = &jabber_subproto_list[i];
     705                register_protocol(subproto);
     706        }
     707}
  • protocols/jabber/jabber.h

    r5ebff60 r7733b8c  
    7777} jabber_chat_flags_t;
    7878
     79typedef enum {
     80        JSUB_NONE = 0,
     81        JSUB_GTALK,
     82        JSUB_FACEBOOK,
     83        JSUB_HIPCHAT,
     84} jabber_subproto_t;
     85
     86typedef struct {
     87        const char *name;
     88        jabber_subproto_t id;
     89        const struct oauth2_service *oauth2_service;
     90        const char *server;
     91} jabber_subproto_desc_t;
     92
    7993struct jabber_data {
    8094        struct im_connection *ic;
     
    88102        struct xt_parser *xt;
    89103        jabber_flags_t flags;
     104        jabber_subproto_t subproto;
    90105
    91106        char *username;         /* USERNAME@server */
  • root_commands.c

    r5ebff60 r7733b8c  
    395395        if (len >= 1 && g_strncasecmp(cmd[1], "add", len) == 0) {
    396396                struct prpl *prpl;
     397                char *protocol_name = cmd[2];
    397398
    398399                MIN_ARGS(3);
     
    410411                }
    411412
    412                 prpl = find_protocol(cmd[2]);
     413                /* These used to be just hardcoded account tag guesses,
     414                 * now they are promoted to hardecoded subprotocol guesses */
     415                if (strcmp(protocol_name, "jabber") == 0) {
     416                        if (strstr(cmd[3], "@gmail.com") || strstr(cmd[3], "@googlemail.com")) {
     417                                protocol_name = "gtalk";
     418                        } else if (strstr(cmd[3], "@chat.facebook.com")) {
     419                                protocol_name = "fb";
     420                        }
     421                }
     422
     423                prpl = find_protocol(protocol_name);
    413424
    414425                if (prpl == NULL) {
Note: See TracChangeset for help on using the changeset viewer.