Changeset 1aa0bb5


Ignore:
Timestamp:
2005-12-13T21:20:34Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
ab4afba
Parents:
34759e6 (diff), b8ef1b1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

AIM groupchat support, thanks to Hanji (Nelson Elhage)!

Location:
protocols/oscar
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • protocols/oscar/aim.h

    r34759e6 r1aa0bb5  
    466466int aim_addtlvtochain_caps(aim_tlvlist_t **list, const guint16 t, const guint32 caps);
    467467int aim_addtlvtochain_noval(aim_tlvlist_t **list, const guint16 type);
     468int aim_addtlvtochain_chatroom(aim_tlvlist_t **list, guint16 type, guint16 exchange, const char *roomname, guint16 instance);
    468469int aim_addtlvtochain_userinfo(aim_tlvlist_t **list, guint16 type, aim_userinfo_t *ui);
    469470int aim_addtlvtochain_frozentlvlist(aim_tlvlist_t **list, guint16 type, aim_tlvlist_t **tl);
     
    572573};
    573574
     575struct aim_chat_invitation {
     576        struct gaim_connection * gc;
     577        char * name;
     578        guint8 exchange;
     579};
    574580
    575581#define AIM_VISIBILITYCHANGE_PERMITADD    0x05
  • protocols/oscar/chat.c

    r34759e6 r1aa0bb5  
    180180       
    181181        aim_tx_enqueue(sess, fr);
    182 
    183         return 0;
    184 }
    185 
    186 static int aim_addtlvtochain_chatroom(aim_tlvlist_t **list, guint16 type, guint16 exchange, const char *roomname, guint16 instance)
    187 {
    188         guint8 *buf;
    189         int buflen;
    190         aim_bstream_t bs;
    191 
    192         buflen = 2 + 1 + strlen(roomname) + 2;
    193        
    194         if (!(buf = g_malloc(buflen)))
    195                 return 0;
    196 
    197         aim_bstream_init(&bs, buf, buflen);
    198 
    199         aimbs_put16(&bs, exchange);
    200         aimbs_put8(&bs, strlen(roomname));
    201         aimbs_putraw(&bs, (guint8 *)roomname, strlen(roomname));
    202         aimbs_put16(&bs, instance);
    203 
    204         aim_addtlvtochain_raw(list, type, aim_bstream_curpos(&bs), buf);
    205 
    206         g_free(buf);
    207182
    208183        return 0;
  • protocols/oscar/im.c

    r34759e6 r1aa0bb5  
    13691369}
    13701370
     1371
     1372static void incomingim_ch2_chat_free(aim_session_t *sess, struct aim_incomingim_ch2_args *args)
     1373{
     1374
     1375        /* XXX aim_chat_roominfo_free() */
     1376        g_free(args->info.chat.roominfo.name);
     1377
     1378        return;
     1379}
     1380
     1381static void incomingim_ch2_chat(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_userinfo_t *userinfo, struct aim_incomingim_ch2_args *args, aim_bstream_t *servdata)
     1382{
     1383
     1384        /*
     1385         * Chat room info.
     1386         */
     1387        if (servdata)
     1388                aim_chat_readroominfo(servdata, &args->info.chat.roominfo);
     1389
     1390        args->destructor = (void *)incomingim_ch2_chat_free;
     1391
     1392        return;
     1393}
     1394
    13711395static void incomingim_ch2_icqserverrelay_free(aim_session_t *sess, struct aim_incomingim_ch2_args *args)
    13721396{
     
    16171641        if (args.reqclass & AIM_CAPS_ICQSERVERRELAY)
    16181642                incomingim_ch2_icqserverrelay(sess, mod, rx, snac, userinfo, &args, sdbsptr);
     1643        else if (args.reqclass & AIM_CAPS_CHAT)
     1644                incomingim_ch2_chat(sess, mod, rx, snac, userinfo, &args, sdbsptr);
    16191645
    16201646
  • protocols/oscar/oscar.c

    r34759e6 r1aa0bb5  
    6262   static int gaim_caps = AIM_CAPS_UTF8; */
    6363
    64 static int gaim_caps = AIM_CAPS_INTEROP | AIM_CAPS_ICHAT | AIM_CAPS_ICQSERVERRELAY;
     64static int gaim_caps = AIM_CAPS_INTEROP | AIM_CAPS_ICHAT | AIM_CAPS_ICQSERVERRELAY | AIM_CAPS_CHAT;
    6565static guint8 gaim_features[] = {0x01, 0x01, 0x01, 0x02};
    6666
     
    156156}
    157157
    158 #if 0
    159158static struct chat_connection *find_oscar_chat(struct gaim_connection *gc, int id) {
    160159        GSList *g = ((struct oscar_data *)gc->proto_data)->oscar_chats;
     
    171170        return c;
    172171}
    173 #endif
     172
    174173
    175174static struct chat_connection *find_oscar_chat_by_conn(struct gaim_connection *gc,
     
    10761075}
    10771076
     1077void oscar_accept_chat(gpointer w, struct aim_chat_invitation * inv);
     1078void oscar_reject_chat(gpointer w, struct aim_chat_invitation * inv);
     1079       
    10781080static int incomingim_chan2(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *userinfo, struct aim_incomingim_ch2_args *args) {
    1079 #if 0
    10801081        struct gaim_connection *gc = sess->aux_data;
    1081 #endif
    10821082
    10831083        if (args->status != AIM_RENDEZVOUS_PROPOSE)
    10841084                return 1;
    1085 #if 0
     1085
    10861086        if (args->reqclass & AIM_CAPS_CHAT) {
    10871087                char *name = extract_name(args->info.chat.roominfo.name);
     
    10911091                *exch = args->info.chat.roominfo.exchange;
    10921092                m = g_list_append(m, exch);
    1093                 serv_got_chat_invite(gc,
    1094                                      name ? name : args->info.chat.roominfo.name,
    1095                                      userinfo->sn,
    1096                                      (char *)args->msg,
    1097                                      m);
     1093
     1094                char txt[1024];
     1095
     1096                g_snprintf( txt, 1024, "Got an invitation to chatroom %s from %s: %s", name, userinfo->sn, args->msg );
     1097
     1098                struct aim_chat_invitation * inv = g_new0(struct aim_chat_invitation, 1);
     1099
     1100                inv->gc = gc;
     1101                inv->exchange = *exch;
     1102                inv->name = g_strdup(name);
     1103               
     1104                do_ask_dialog( gc, txt, inv, oscar_accept_chat, oscar_reject_chat);
     1105       
    10981106                if (name)
    10991107                        g_free(name);
    11001108        }
    1101 #endif
     1109
    11021110        return 1;
    11031111}
     
    24842492}
    24852493
     2494int oscar_chat_send(struct gaim_connection * gc, int id, char *message)
     2495{
     2496        struct oscar_data * od = (struct oscar_data*)gc->proto_data;
     2497        struct chat_connection * ccon;
     2498       
     2499        if(!(ccon = find_oscar_chat(gc, id)))
     2500                return -1;
     2501       
     2502        int ret;
     2503        guint8 len = strlen(message);
     2504        char *s;
     2505               
     2506        for (s = message; *s; s++)
     2507                if (*s & 128)
     2508                        break;
     2509               
     2510        /* Message contains high ASCII chars, time for some translation! */
     2511        if (*s) {
     2512                s = g_malloc(BUF_LONG);
     2513                /* Try if we can put it in an ISO8859-1 string first.
     2514                   If we can't, fall back to UTF16. */
     2515                if ((ret = do_iconv("UTF-8", "ISO8859-1", message, s, len, BUF_LONG)) >= 0) {
     2516                        len = ret;
     2517                } else if ((ret = do_iconv("UTF-8", "UNICODEBIG", message, s, len, BUF_LONG)) >= 0) {
     2518                        len = ret;
     2519                } else {
     2520                        /* OOF, translation failed... Oh well.. */
     2521                        g_free( s );
     2522                        s = message;
     2523                }
     2524        } else {
     2525                s = message;
     2526        }
     2527               
     2528        ret = aim_chat_send_im(od->sess, ccon->conn, AIM_CHATFLAGS_NOREFLECT, s, len);
     2529               
     2530        if (s != message) {     
     2531                g_free(s);
     2532  }
     2533 
     2534  return (ret >= 0);
     2535}
     2536
     2537void oscar_chat_invite(struct gaim_connection * gc, int id, char *message, char *who)
     2538{
     2539        struct oscar_data * od = (struct oscar_data *)gc->proto_data;
     2540        struct chat_connection *ccon = find_oscar_chat(gc, id);
     2541       
     2542        if (ccon == NULL)
     2543                return;
     2544       
     2545        aim_chat_invite(od->sess, od->conn, who, message ? message : "",
     2546                                        ccon->exchange, ccon->name, 0x0);
     2547}
     2548
     2549void oscar_chat_kill(struct gaim_connection *gc, struct chat_connection *cc)
     2550{
     2551        struct oscar_data *od = (struct oscar_data *)gc->proto_data;
     2552
     2553        /* Notify the conversation window that we've left the chat */
     2554        serv_got_chat_left(gc, cc->id);
     2555
     2556        /* Destroy the chat_connection */
     2557        od->oscar_chats = g_slist_remove(od->oscar_chats, cc);
     2558        if (cc->inpa > 0)
     2559                gaim_input_remove(cc->inpa);
     2560        aim_conn_kill(od->sess, &cc->conn);
     2561        g_free(cc->name);
     2562        g_free(cc->show);
     2563        g_free(cc);
     2564}
     2565
     2566void oscar_chat_leave(struct gaim_connection * gc, int id)
     2567{
     2568        struct chat_connection * ccon = find_oscar_chat(gc, id);
     2569
     2570        if(ccon == NULL)
     2571                return;
     2572
     2573        oscar_chat_kill(gc, ccon);
     2574}
     2575
     2576int oscar_chat_join(struct gaim_connection * gc, char * name)
     2577{
     2578    struct oscar_data * od = (struct oscar_data *)gc->proto_data;
     2579       
     2580        aim_conn_t * cur;
     2581
     2582        if((cur = aim_getconn_type(od->sess, AIM_CONN_TYPE_CHATNAV))) {
     2583       
     2584                return (aim_chatnav_createroom(od->sess, cur, name, 4) == 0);
     2585       
     2586        } else {
     2587                struct create_room * cr = g_new0(struct create_room, 1);
     2588                cr->exchange = 4;
     2589                cr->name = g_strdup(name);
     2590                od->create_rooms = g_slist_append(od->create_rooms, cr);
     2591                aim_reqservice(od->sess, od->conn, AIM_CONN_TYPE_CHATNAV);
     2592                return 1;
     2593        }
     2594}
     2595
     2596int oscar_chat_open(struct gaim_connection * gc, char *who)
     2597{
     2598        struct oscar_data * od = (struct oscar_data *)gc->proto_data;
     2599
     2600        static int chat_id = 0;
     2601        char * chatname = g_new0(char, strlen(gc->username)+4);
     2602        g_snprintf(chatname, strlen(gc->username) + 4, "%s%d", gc->username, chat_id++);
     2603 
     2604        int ret = oscar_chat_join(gc, chatname);
     2605
     2606        aim_chat_invite(od->sess, od->conn, who, "", 4, chatname, 0x0);
     2607
     2608        g_free(chatname);
     2609       
     2610        return ret;
     2611}
     2612
     2613void oscar_accept_chat(gpointer w, struct aim_chat_invitation * inv)
     2614{
     2615        oscar_chat_join(inv->gc, inv->name);
     2616        g_free(inv->name);
     2617        g_free(inv);
     2618}
     2619
     2620void oscar_reject_chat(gpointer w, struct aim_chat_invitation * inv)
     2621{
     2622        g_free(inv->name);
     2623        g_free(inv);
     2624}
     2625
    24862626static struct prpl *my_protocol = NULL;
    24872627
     
    24972637        ret->add_buddy = oscar_add_buddy;
    24982638        ret->remove_buddy = oscar_remove_buddy;
     2639        ret->chat_send = oscar_chat_send;
     2640        ret->chat_invite = oscar_chat_invite;
     2641        ret->chat_leave = oscar_chat_leave;
     2642        ret->chat_open = oscar_chat_open;
    24992643        ret->add_permit = oscar_add_permit;
    25002644        ret->add_deny = oscar_add_deny;
  • protocols/oscar/tlv.c

    r34759e6 r1aa0bb5  
    340340}
    341341
     342int aim_addtlvtochain_chatroom(aim_tlvlist_t **list, guint16 type, guint16 exchange, const char *roomname, guint16 instance)
     343{
     344        guint8 *buf;
     345        int buflen;
     346        aim_bstream_t bs;
     347
     348        buflen = 2 + 1 + strlen(roomname) + 2;
     349       
     350        if (!(buf = g_malloc(buflen)))
     351                return 0;
     352
     353        aim_bstream_init(&bs, buf, buflen);
     354
     355        aimbs_put16(&bs, exchange);
     356        aimbs_put8(&bs, strlen(roomname));
     357        aimbs_putraw(&bs, (guint8 *)roomname, strlen(roomname));
     358        aimbs_put16(&bs, instance);
     359
     360        aim_addtlvtochain_raw(list, type, aim_bstream_curpos(&bs), buf);
     361
     362        g_free(buf);
     363
     364        return 0;
     365}
     366
    342367/**
    343368 * aim_writetlvchain - Write a TLV chain into a data buffer.
Note: See TracChangeset for help on using the changeset viewer.