Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/purple/purple.c

    r2dd23da r5ebff60  
    2323
    2424#include "bitlbee.h"
    25 #include "bpurple.h"
    2625#include "help.h"
    2726
     
    4039static char *set_eval_display_name(set_t *set, char *value);
    4140
    42 void purple_request_input_callback(guint id, struct im_connection *ic,
    43                                    const char *message, const char *who);
    44 
    45 /* purple_request_input specific stuff */
    46 typedef void (*ri_callback_t)(gpointer, const gchar *);
    47 
    48 struct request_input_data {
    49         ri_callback_t data_callback;
    50         void *user_data;
    51         struct im_connection *ic;
    52         char *buddy;
    53         guint id;
    54 };
    55 
    5641struct im_connection *purple_ic_by_pa(PurpleAccount *pa)
    5742{
    5843        GSList *i;
    59         struct purple_data *pd;
    6044
    6145        for (i = purple_connections; i; i = i->next) {
    62                 pd = ((struct im_connection *) i->data)->proto_data;
    63                 if (pd->account == pa) {
     46                if (((struct im_connection *) i->data)->proto_data == pa) {
    6447                        return i->data;
    6548                }
     
    307290{
    308291        struct im_connection *ic = imcb_new(acc);
    309         struct purple_data *pd;
     292        PurpleAccount *pa;
    310293
    311294        if ((local_bee != NULL && local_bee != acc->bee) ||
     
    323306        purple_connections = g_slist_prepend(purple_connections, ic);
    324307
    325         ic->proto_data = pd = g_new0(struct purple_data, 1);
    326         pd->account = purple_account_new(acc->user, (char *) acc->prpl->data);
    327         pd->input_requests = g_hash_table_new_full(g_direct_hash, g_direct_equal,
    328                                                    NULL, g_free);
    329         pd->next_request_id = 0;
    330         purple_account_set_password(pd->account, acc->pass);
    331         purple_sync_settings(acc, pd->account);
    332 
    333         purple_account_set_enabled(pd->account, "BitlBee", TRUE);
     308        ic->proto_data = pa = purple_account_new(acc->user, (char *) acc->prpl->data);
     309        purple_account_set_password(pa, acc->pass);
     310        purple_sync_settings(acc, pa);
     311
     312        purple_account_set_enabled(pa, "BitlBee", TRUE);
    334313}
    335314
    336315static void purple_logout(struct im_connection *ic)
    337316{
    338         struct purple_data *pd = ic->proto_data;
    339 
    340         if (!pd) {
    341                 return;
    342         }
    343 
    344         purple_account_set_enabled(pd->account, "BitlBee", FALSE);
     317        PurpleAccount *pa = ic->proto_data;
     318
     319        purple_account_set_enabled(pa, "BitlBee", FALSE);
    345320        purple_connections = g_slist_remove(purple_connections, ic);
    346         purple_accounts_remove(pd->account);
    347         g_hash_table_destroy(pd->input_requests);
    348         g_free(pd);
     321        purple_accounts_remove(pa);
    349322}
    350323
     
    352325{
    353326        PurpleConversation *conv;
    354         struct purple_data *pd = ic->proto_data;
    355 
    356         if (!strncmp(who, PURPLE_REQUEST_HANDLE, sizeof(PURPLE_REQUEST_HANDLE) - 1)) {
    357                 guint request_id = atoi(who + sizeof(PURPLE_REQUEST_HANDLE));
    358                 purple_request_input_callback(request_id, ic, message, who);
    359                 return 1;
    360         }
    361327
    362328        if ((conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM,
    363                                                           who, pd->account)) == NULL) {
     329                                                          who, ic->proto_data)) == NULL) {
    364330                conv = purple_conversation_new(PURPLE_CONV_TYPE_IM,
    365                                                pd->account, who);
     331                                               ic->proto_data, who);
    366332        }
    367333
     
    373339static GList *purple_away_states(struct im_connection *ic)
    374340{
    375         struct purple_data *pd = ic->proto_data;
     341        PurpleAccount *pa = ic->proto_data;
    376342        GList *st, *ret = NULL;
    377343
    378         for (st = purple_account_get_status_types(pd->account); st; st = st->next) {
     344        for (st = purple_account_get_status_types(pa); st; st = st->next) {
    379345                PurpleStatusPrimitive prim = purple_status_type_get_primitive(st->data);
    380346                if (prim != PURPLE_STATUS_AVAILABLE && prim != PURPLE_STATUS_OFFLINE) {
     
    388354static void purple_set_away(struct im_connection *ic, char *state_txt, char *message)
    389355{
    390         struct purple_data *pd = ic->proto_data;
    391         GList *status_types = purple_account_get_status_types(pd->account), *st;
     356        PurpleAccount *pa = ic->proto_data;
     357        GList *status_types = purple_account_get_status_types(pa), *st;
    392358        PurpleStatusType *pst = NULL;
    393359        GList *args = NULL;
     
    412378        }
    413379
    414         purple_account_set_status_list(pd->account,
    415                                        st ? purple_status_type_get_id(pst) : "away",
     380        purple_account_set_status_list(pa, st ? purple_status_type_get_id(pst) : "away",
    416381                                       TRUE, args);
    417382
     
    482447        PurpleBuddy *pb;
    483448        PurpleGroup *pg = NULL;
    484         struct purple_data *pd = ic->proto_data;
    485449
    486450        if (group && !(pg = purple_find_group(group))) {
     
    489453        }
    490454
    491         pb = purple_buddy_new(pd->account, who, NULL);
     455        pb = purple_buddy_new((PurpleAccount *) ic->proto_data, who, NULL);
    492456        purple_blist_add_buddy(pb, NULL, pg, NULL);
    493         purple_account_add_buddy(pd->account, pb);
    494 
    495         purple_gg_buddylist_export(pd->account->gc);
     457        purple_account_add_buddy((PurpleAccount *) ic->proto_data, pb);
     458
     459        purple_gg_buddylist_export(((PurpleAccount *) ic->proto_data)->gc);
    496460}
    497461
     
    499463{
    500464        PurpleBuddy *pb;
    501         struct purple_data *pd = ic->proto_data;
    502 
    503         pb = purple_find_buddy(pd->account, who);
     465
     466        pb = purple_find_buddy((PurpleAccount *) ic->proto_data, who);
    504467        if (pb != NULL) {
    505468                PurpleGroup *group;
    506469
    507470                group = purple_buddy_get_group(pb);
    508                 purple_account_remove_buddy(pd->account, pb, group);
     471                purple_account_remove_buddy((PurpleAccount *) ic->proto_data, pb, group);
    509472
    510473                purple_blist_remove_buddy(pb);
    511474        }
    512475
    513         purple_gg_buddylist_export(pd->account->gc);
     476        purple_gg_buddylist_export(((PurpleAccount *) ic->proto_data)->gc);
    514477}
    515478
    516479static void purple_add_permit(struct im_connection *ic, char *who)
    517480{
    518         struct purple_data *pd = ic->proto_data;
    519 
    520         purple_privacy_permit_add(pd->account, who, FALSE);
     481        PurpleAccount *pa = ic->proto_data;
     482
     483        purple_privacy_permit_add(pa, who, FALSE);
    521484}
    522485
    523486static void purple_add_deny(struct im_connection *ic, char *who)
    524487{
    525         struct purple_data *pd = ic->proto_data;
    526 
    527         purple_privacy_deny_add(pd->account, who, FALSE);
     488        PurpleAccount *pa = ic->proto_data;
     489
     490        purple_privacy_deny_add(pa, who, FALSE);
    528491}
    529492
    530493static void purple_rem_permit(struct im_connection *ic, char *who)
    531494{
    532         struct purple_data *pd = ic->proto_data;
    533 
    534         purple_privacy_permit_remove(pd->account, who, FALSE);
     495        PurpleAccount *pa = ic->proto_data;
     496
     497        purple_privacy_permit_remove(pa, who, FALSE);
    535498}
    536499
    537500static void purple_rem_deny(struct im_connection *ic, char *who)
    538501{
    539         struct purple_data *pd = ic->proto_data;
    540 
    541         purple_privacy_deny_remove(pd->account, who, FALSE);
     502        PurpleAccount *pa = ic->proto_data;
     503
     504        purple_privacy_deny_remove(pa, who, FALSE);
    542505}
    543506
    544507static void purple_get_info(struct im_connection *ic, char *who)
    545508{
    546         struct purple_data *pd = ic->proto_data;
    547 
    548         serv_get_info(purple_account_get_connection(pd->account), who);
     509        serv_get_info(purple_account_get_connection(ic->proto_data), who);
    549510}
    550511
     
    556517{
    557518        PurpleTypingState state = PURPLE_NOT_TYPING;
    558         struct purple_data *pd = ic->proto_data;
     519        PurpleAccount *pa = ic->proto_data;
    559520
    560521        if (flags & OPT_TYPING) {
     
    564525        }
    565526
    566         serv_send_typing(purple_account_get_connection(pd->account), who, state);
     527        serv_send_typing(purple_account_get_connection(pa), who, state);
    567528
    568529        return 1;
     
    598559        /* There went my nice afternoon. :-( */
    599560
    600         struct purple_data *pd = ic->proto_data;
    601         PurplePlugin *prpl = purple_plugins_find_with_id(pd->account->protocol_id);
     561        PurpleAccount *pa = ic->proto_data;
     562        PurplePlugin *prpl = purple_plugins_find_with_id(pa->protocol_id);
    602563        PurplePluginProtocolInfo *pi = prpl->info->extra_info;
    603         PurpleBuddy *pb = purple_find_buddy(pd->account, who);
     564        PurpleBuddy *pb = purple_find_buddy((PurpleAccount *) ic->proto_data, who);
    604565        PurpleMenuAction *mi;
    605566        GList *menu;
     
    636597        PurpleConversation *pc = gc->data;
    637598        PurpleConvChat *pcc = PURPLE_CONV_CHAT(pc);
    638         struct purple_data *pd = gc->ic->proto_data;
    639 
    640         serv_chat_invite(purple_account_get_connection(pd->account),
     599
     600        serv_chat_invite(purple_account_get_connection(gc->ic->proto_data),
    641601                         purple_conv_chat_get_id(pcc),
    642602                         message && *message ? message : "Please join my chat",
     
    663623                                   set_t **sets)
    664624{
    665         struct purple_data *pd = ic->proto_data;
    666         PurplePlugin *prpl = purple_plugins_find_with_id(pd->account->protocol_id);
     625        PurpleAccount *pa = ic->proto_data;
     626        PurplePlugin *prpl = purple_plugins_find_with_id(pa->protocol_id);
    667627        PurplePluginProtocolInfo *pi = prpl->info->extra_info;
    668628        GHashTable *chat_hash;
     
    671631
    672632        if (!pi->chat_info || !pi->chat_info_defaults ||
    673             !(info = pi->chat_info(purple_account_get_connection(pd->account)))) {
     633            !(info = pi->chat_info(purple_account_get_connection(pa)))) {
    674634                imcb_error(ic, "Joining chatrooms not supported by this protocol");
    675635                return NULL;
    676636        }
    677637
    678         if ((conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT,
    679                                                           room, pd->account))) {
     638        if ((conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, room, pa))) {
    680639                purple_conversation_destroy(conv);
    681640        }
    682641
    683         chat_hash = pi->chat_info_defaults(
    684                 purple_account_get_connection(pd->account), room
    685         );
     642        chat_hash = pi->chat_info_defaults(purple_account_get_connection(pa), room);
    686643
    687644        for (l = info; l; l = l->next) {
     
    697654        }
    698655
    699         serv_join_chat(purple_account_get_connection(pd->account), chat_hash);
     656        serv_join_chat(purple_account_get_connection(pa), chat_hash);
    700657
    701658        return NULL;
     
    1024981                pqad->yes(pqad->user_data, pqad->yes_i);
    1025982        }
     983        g_free(pqad);
    1026984}
    1027985
     
    1033991                pqad->no(pqad->user_data, pqad->no_i);
    1034992        }
    1035 }
    1036 
    1037 /* q->free() callback from query_del()*/
    1038 static void prplcb_request_action_free(void *data)
    1039 {
    1040         struct prplcb_request_action_data *pqad = data;
    1041 
    1042         pqad->bee_data = NULL;
    1043         purple_request_close(PURPLE_REQUEST_ACTION, pqad);
     993        g_free(pqad);
    1044994}
    1045995
     
    10761026        q = g_strdup_printf("Request: %s\n\n%s\n\n%s", title, primary, secondary);
    10771027        pqad->bee_data = query_add(local_bee->ui_data, purple_ic_by_pa(account), q,
    1078                                    prplcb_request_action_yes, prplcb_request_action_no,
    1079                                    prplcb_request_action_free, pqad);
     1028                                   prplcb_request_action_yes, prplcb_request_action_no, g_free, pqad);
    10801029
    10811030        g_free(q);
     
    10841033}
    10851034
    1086 /* So it turns out some requests have no account context at all, because
    1087  * libpurple hates us. This means that query_del_by_conn() won't remove those
    1088  * on logout, and will segfault if the user replies. That's why this exists.
    1089  */
    1090 static void prplcb_close_request(PurpleRequestType type, void *data)
    1091 {
    1092         struct prplcb_request_action_data *pqad;
    1093         struct request_input_data *ri;
    1094         struct purple_data *pd;
    1095 
    1096         if (!data) {
    1097                 return;
    1098         }
    1099 
    1100         switch (type) {
    1101         case PURPLE_REQUEST_ACTION:
    1102                 pqad = data;
    1103                 /* if this is null, it's because query_del was run already */
    1104                 if (pqad->bee_data) {
    1105                         query_del(local_bee->ui_data, pqad->bee_data);
    1106                 }
    1107                 g_free(pqad);
    1108                 break;
    1109         case PURPLE_REQUEST_INPUT:
    1110                 ri = data;
    1111                 pd = ri->ic->proto_data;
    1112                 imcb_remove_buddy(ri->ic, ri->buddy, NULL);
    1113                 g_free(ri->buddy);
    1114                 g_hash_table_remove(pd->input_requests, GUINT_TO_POINTER(ri->id));
    1115                 break;
    1116         default:
    1117                 g_free(data);
    1118                 break;
    1119         }
    1120 
    1121 }
    1122 
    1123 void* prplcb_request_input(const char *title, const char *primary,
    1124         const char *secondary, const char *default_value, gboolean multiline,
    1125         gboolean masked, gchar *hint, const char *ok_text, GCallback ok_cb,
    1126         const char *cancel_text, GCallback cancel_cb, PurpleAccount *account,
    1127         const char *who, PurpleConversation *conv, void *user_data)
    1128 {
    1129         struct im_connection *ic = purple_ic_by_pa(account);
    1130         struct purple_data *pd = ic->proto_data;
    1131         struct request_input_data *ri = g_new0(struct request_input_data, 1);
    1132         guint id = pd->next_request_id++;
    1133 
    1134         ri->id = id;
    1135         ri->ic = ic;
    1136         ri->buddy = g_strdup_printf("%s_%u", PURPLE_REQUEST_HANDLE, id);
    1137         ri->data_callback = (ri_callback_t) ok_cb;
    1138         ri->user_data = user_data;
    1139         g_hash_table_insert(pd->input_requests, GUINT_TO_POINTER(id), ri);
    1140 
    1141         imcb_add_buddy(ic, ri->buddy, NULL);
    1142         imcb_buddy_msg(ic, ri->buddy, secondary, 0, 0);
    1143 
    1144         return ri;
    1145 }
    1146 
    1147 void purple_request_input_callback(guint id, struct im_connection *ic,
    1148                                    const char *message, const char *who)
    1149 {
    1150         struct purple_data *pd = ic->proto_data;
    1151         struct request_input_data *ri;
    1152 
    1153         if (!(ri = g_hash_table_lookup(pd->input_requests, GUINT_TO_POINTER(id)))) {
    1154                 return;
    1155         }
    1156 
    1157         ri->data_callback(ri->user_data, message);
    1158 
    1159         purple_request_close(PURPLE_REQUEST_INPUT, ri);
    1160 }
    1161 
     1035/*
     1036static void prplcb_request_test()
     1037{
     1038        fprintf( stderr, "bla\n" );
     1039}
     1040*/
    11621041
    11631042static PurpleRequestUiOps bee_request_uiops =
    11641043{
    1165         prplcb_request_input,
     1044        NULL,
    11661045        NULL,
    11671046        prplcb_request_action,
    11681047        NULL,
    11691048        NULL,
    1170         prplcb_close_request,
     1049        NULL,
    11711050        NULL,
    11721051};
Note: See TracChangeset for help on using the changeset viewer.