Changeset 178e2f8 for protocols


Ignore:
Timestamp:
2008-06-28T17:32:41Z (17 years ago)
Author:
Jelmer Vernooij <jelmer@…>
Branches:
master
Children:
47b571d
Parents:
2e0f24d (diff), e0f9170 (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:

Merge trunk.

Location:
protocols
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/jabber.c

    r2e0f24d r178e2f8  
    3333#include "jabber.h"
    3434#include "md5.h"
    35 #include "base64.h"
    3635
    3736GSList *jabber_connections;
    3837
     38/* First enty is the default */
     39static const int jabber_port_list[] = {
     40        5222,
     41        5223,
     42        5220,
     43        5221,
     44        5224,
     45        5225,
     46        5226,
     47        5227,
     48        5228,
     49        5229,
     50        80,
     51        443,
     52        0
     53};
     54
    3955static void jabber_init( account_t *acc )
    4056{
    4157        set_t *s;
    42        
    43         s = set_add( &acc->set, "port", JABBER_PORT_DEFAULT, set_eval_int, acc );
     58        char str[16];
     59       
     60        g_snprintf( str, sizeof( str ), "%d", jabber_port_list[0] );
     61        s = set_add( &acc->set, "port", str, set_eval_int, acc );
    4462        s->flags |= ACC_SET_OFFLINE_ONLY;
    4563       
     
    7290        struct ns_srv_reply *srv = NULL;
    7391        char *connect_to, *s;
     92        int i;
    7493       
    7594        /* For now this is needed in the _connected() handlers if using
     
    177196        imcb_log( ic, "Connecting" );
    178197       
    179         if( set_getint( &acc->set, "port" ) < JABBER_PORT_MIN ||
    180             set_getint( &acc->set, "port" ) > JABBER_PORT_MAX )
    181         {
    182                 imcb_log( ic, "Incorrect port number, must be in the %d-%d range",
    183                                JABBER_PORT_MIN, JABBER_PORT_MAX );
     198        for( i = 0; jabber_port_list[i] > 0; i ++ )
     199                if( set_getint( &acc->set, "port" ) == jabber_port_list[i] )
     200                        break;
     201
     202        if( jabber_port_list[i] == 0 )
     203        {
     204                imcb_log( ic, "Illegal port number" );
    184205                imc_logout( ic, FALSE );
    185206                return;
     
    219240}
    220241
     242/* This generates an unfinished md5_state_t variable. Every time we generate
     243   an ID, we finish the state by adding a sequence number and take the hash. */
    221244static void jabber_generate_id_hash( struct jabber_data *jd )
    222245{
    223         md5_state_t id_hash;
    224         md5_byte_t binbuf[16];
     246        md5_byte_t binbuf[4];
    225247        char *s;
    226248       
    227         md5_init( &id_hash );
    228         md5_append( &id_hash, (unsigned char *) jd->username, strlen( jd->username ) );
    229         md5_append( &id_hash, (unsigned char *) jd->server, strlen( jd->server ) );
     249        md5_init( &jd->cached_id_prefix );
     250        md5_append( &jd->cached_id_prefix, (unsigned char *) jd->username, strlen( jd->username ) );
     251        md5_append( &jd->cached_id_prefix, (unsigned char *) jd->server, strlen( jd->server ) );
    230252        s = set_getstr( &jd->ic->acc->set, "resource" );
    231         md5_append( &id_hash, (unsigned char *) s, strlen( s ) );
    232         random_bytes( binbuf, 16 );
    233         md5_append( &id_hash, binbuf, 16 );
    234         md5_finish( &id_hash, binbuf );
    235        
    236         s = base64_encode( binbuf, 9 );
    237         jd->cached_id_prefix = g_strdup_printf( "%s%s", JABBER_CACHED_ID, s );
    238         g_free( s );
     253        md5_append( &jd->cached_id_prefix, (unsigned char *) s, strlen( s ) );
     254        random_bytes( binbuf, 4 );
     255        md5_append( &jd->cached_id_prefix, binbuf, 4 );
    239256}
    240257
     
    267284        xt_free( jd->xt );
    268285       
    269         g_free( jd->cached_id_prefix );
    270286        g_free( jd->away_message );
    271287        g_free( jd->username );
  • protocols/jabber/jabber.h

    r2e0f24d r178e2f8  
    8686        char *away_message;
    8787       
    88         char *cached_id_prefix;
     88        md5_state_t cached_id_prefix;
    8989        GHashTable *node_cache;
    9090        GHashTable *buddies;
     
    134134
    135135#define JABBER_XMLCONSOLE_HANDLE "xmlconsole"
    136 
    137 #define JABBER_PORT_DEFAULT "5222"
    138 #define JABBER_PORT_MIN 5220
    139 #define JABBER_PORT_MAX 5229
    140136
    141137/* Prefixes to use for packet IDs (mainly for IQ packets ATM). Usually the
  • protocols/jabber/jabber_util.c

    r2e0f24d r178e2f8  
    2323
    2424#include "jabber.h"
     25#include "md5.h"
     26#include "base64.h"
    2527
    2628static unsigned int next_id = 1;
     
    134136        struct jabber_data *jd = ic->proto_data;
    135137        struct jabber_cache_entry *entry = g_new0( struct jabber_cache_entry, 1 );
    136         char *id;
    137        
    138         id = g_strdup_printf( "%s%05x", jd->cached_id_prefix, ( next_id++ ) & 0xfffff );
     138        md5_state_t id_hash;
     139        md5_byte_t id_sum[16];
     140        char *id, *asc_hash;
     141       
     142        next_id ++;
     143       
     144        id_hash = jd->cached_id_prefix;
     145        md5_append( &id_hash, (md5_byte_t*) &next_id, sizeof( next_id ) );
     146        md5_finish( &id_hash, id_sum );
     147        asc_hash = base64_encode( id_sum, 12 );
     148       
     149        id = g_strdup_printf( "%s%s", JABBER_CACHED_ID, asc_hash );
    139150        xt_add_attr( node, "id", id );
    140151        g_free( id );
     152        g_free( asc_hash );
    141153       
    142154        entry->node = node;
     
    184196       
    185197        if( ( s = xt_find_attr( node, "id" ) ) == NULL ||
    186             strncmp( s, jd->cached_id_prefix, strlen( jd->cached_id_prefix ) ) != 0 )
     198            strncmp( s, JABBER_CACHED_ID, strlen( JABBER_CACHED_ID ) ) != 0 )
    187199        {
    188200                /* Silently ignore it, without an ID (or a non-cache
     
    196208        if( entry == NULL )
    197209        {
     210                /*
     211                There's no longer an easy way to see if we generated this
     212                one or someone else, and there's a ten-minute timeout anyway,
     213                so meh.
     214               
    198215                imcb_log( ic, "Warning: Received %s-%s packet with unknown/expired ID %s!",
    199216                              node->name, xt_find_attr( node, "type" ) ? : "(no type)", s );
     217                */
    200218        }
    201219        else if( entry->func )
     
    290308        len = strlen( orig );
    291309        new = g_new( char, len + 1 );
    292         for( i = 0; i < len; i ++ )
     310       
     311        /* So it turns out the /resource part is case sensitive. Yeah, and
     312           it's Unicode but feck Unicode. :-P So stop once we see a slash. */
     313        for( i = 0; i < len && orig[i] != '/' ; i ++ )
    293314                new[i] = tolower( orig[i] );
     315        for( ; orig[i]; i ++ )
     316                new[i] = orig[i];
    294317       
    295318        new[i] = 0;
     
    334357                {
    335358                        /* Check for dupes. */
    336                         if( g_strcasecmp( bi->resource, s + 1 ) == 0 )
     359                        if( strcmp( bi->resource, s + 1 ) == 0 )
    337360                        {
    338361                                *s = '/';
     
    387410        if( ( s = strchr( jid, '/' ) ) )
    388411        {
    389                 int none_found = 0;
     412                int bare_exists = 0;
    390413               
    391414                *s = 0;
     
    410433                        /* See if there's an exact match. */
    411434                        for( ; bud; bud = bud->next )
    412                                 if( g_strcasecmp( bud->resource, s + 1 ) == 0 )
     435                                if( strcmp( bud->resource, s + 1 ) == 0 )
    413436                                        break;
    414437                }
    415438                else
    416439                {
    417                         /* This hack is there to make sure that O_CREAT will
    418                            work if there's already another resouce present
    419                            for this JID, even if it's an unknown buddy. This
    420                            is done to handle conferences properly. */
    421                         none_found = 1;
    422                         /* TODO(wilmer): Find out what I was thinking when I
    423                            wrote this??? And then fix it. This makes me sad... */
    424                 }
    425                
    426                 if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && ( imcb_find_buddy( ic, jid ) || !none_found ) )
     440                        /* This variable tells the if down here that the bare
     441                           JID already exists and we should feel free to add
     442                           more resources, if the caller asked for that. */
     443                        bare_exists = 1;
     444                }
     445               
     446                if( bud == NULL && ( flags & GET_BUDDY_CREAT ) &&
     447                    ( !bare_exists || imcb_find_buddy( ic, jid ) ) )
    427448                {
    428449                        *s = '/';
     
    449470                        /* We want an exact match, so in thise case there shouldn't be a /resource. */
    450471                        return NULL;
    451                 else if( ( bud->resource == NULL || bud->next == NULL ) )
     472                else if( bud->resource == NULL || bud->next == NULL )
    452473                        /* No need for selection if there's only one option. */
    453474                        return bud;
     
    525546                   matches), removing it is simple. (And the hash reference
    526547                   should be removed too!) */
    527                 if( bud->next == NULL && ( ( s == NULL || bud->resource == NULL ) || g_strcasecmp( bud->resource, s + 1 ) == 0 ) )
     548                if( bud->next == NULL &&
     549                    ( ( s == NULL && bud->resource == NULL ) ||
     550                      ( bud->resource && s && strcmp( bud->resource, s + 1 ) == 0 ) ) )
    528551                {
    529552                        g_hash_table_remove( jd->buddies, bud->bare_jid );
     
    548571                {
    549572                        for( bi = bud, prev = NULL; bi; bi = (prev=bi)->next )
    550                                 if( g_strcasecmp( bi->resource, s + 1 ) == 0 )
     573                                if( strcmp( bi->resource, s + 1 ) == 0 )
    551574                                        break;
    552575                       
  • protocols/jabber/message.c

    r2e0f24d r178e2f8  
    4949        {
    5050                GString *fullmsg = g_string_new( "" );
     51
     52                for( c = node->children; ( c = xt_find_node( c, "x" ) ); c = c->next )
     53                {
     54                        char *ns = xt_find_attr( c, "xmlns" ), *room;
     55                        struct xt_node *inv, *reason;
     56                       
     57                        if( strcmp( ns, XMLNS_MUC_USER ) == 0 &&
     58                            ( inv = xt_find_node( c->children, "invite" ) ) )
     59                        {
     60                                room = from;
     61                                from = xt_find_attr( inv, "from" ) ? : from;
     62
     63                                g_string_append_printf( fullmsg, "<< \002BitlBee\002 - Invitation to chatroom %s >>\n", room );
     64                                if( ( reason = xt_find_node( inv->children, "reason" ) ) && reason->text_len > 0 )
     65                                        g_string_append( fullmsg, reason->text );
     66                        }
     67                }
    5168               
    5269                if( ( s = strchr( from, '/' ) ) )
  • protocols/nogaim.h

    r2e0f24d r178e2f8  
    4444#include "query.h"
    4545#include "md5.h"
    46 
    47 #define BUF_LEN MSG_LEN
    48 #define BUF_LONG ( BUF_LEN * 2 )
    49 #define MSG_LEN 2048
    50 #define BUF_LEN MSG_LEN
    5146
    5247#define BUDDY_ALIAS_MAXLEN 388   /* because MSN names can be 387 characters */
  • protocols/oscar/oscar.c

    r2e0f24d r178e2f8  
    6060
    6161#define OSCAR_GROUP "Friends"
     62
     63#define BUF_LEN 2048
     64#define BUF_LONG ( BUF_LEN * 2 )
    6265
    6366/* Don't know if support for UTF8 is really working. For now it's UTF16 here.
     
    240243};
    241244static int msgerrreasonlen = 25;
     245
     246/* Hurray, this function is NOT thread-safe \o/ */
     247static char *normalize(const char *s)
     248{
     249        static char buf[BUF_LEN];
     250        char *t, *u;
     251        int x = 0;
     252
     253        g_return_val_if_fail((s != NULL), NULL);
     254
     255        u = t = g_strdup(s);
     256
     257        strcpy(t, s);
     258        g_strdown(t);
     259
     260        while (*t && (x < BUF_LEN - 1)) {
     261                if (*t != ' ' && *t != '!') {
     262                        buf[x] = *t;
     263                        x++;
     264                }
     265                t++;
     266        }
     267        buf[x] = '\0';
     268        g_free(u);
     269        return buf;
     270}
    242271
    243272static gboolean oscar_callback(gpointer data, gint source,
     
    10021031        }
    10031032
    1004         tmp = g_strdup(normalize(ic->acc->user));
    1005         if (!strcmp(tmp, normalize(info->sn)))
     1033        if (!aim_sncmp(ic->acc->user, info->sn))
    10061034                g_snprintf(ic->displayname, sizeof(ic->displayname), "%s", info->sn);
    1007         g_free(tmp);
    1008 
    1009         imcb_buddy_status(ic, info->sn, flags, state_string, NULL);
    1010         /* imcb_buddy_times(ic, info->sn, signon, time_idle); */
     1035
     1036        tmp = normalize(info->sn);
     1037        imcb_buddy_status(ic, tmp, flags, state_string, NULL);
     1038        /* imcb_buddy_times(ic, tmp, signon, time_idle); */
     1039
    10111040
    10121041        return 1;
     
    10221051        va_end(ap);
    10231052
    1024         imcb_buddy_status(ic, info->sn, 0, NULL, NULL );
     1053        imcb_buddy_status(ic, normalize(info->sn), 0, NULL, NULL );
    10251054
    10261055        return 1;
     
    10781107       
    10791108        strip_linefeed(tmp);
    1080         imcb_buddy_msg(ic, userinfo->sn, tmp, flags, 0);
     1109        imcb_buddy_msg(ic, normalize(userinfo->sn), tmp, flags, 0);
    10811110        g_free(tmp);
    10821111       
     
    11771206                        message = g_strdup(args->msg);
    11781207                        strip_linefeed(message);
    1179                         imcb_buddy_msg(ic, uin, message, 0, 0);
     1208                        imcb_buddy_msg(ic, normalize(uin), message, 0, 0);
    11801209                        g_free(uin);
    11811210                        g_free(message);
     
    11961225
    11971226                        strip_linefeed(message);
    1198                         imcb_buddy_msg(ic, uin, message, 0, 0);
     1227                        imcb_buddy_msg(ic, normalize(uin), message, 0, 0);
    11991228                        g_free(uin);
    12001229                        g_free(m);
     
    14711500
    14721501        for (i = 0; i < count; i++)
    1473                 imcb_chat_add_buddy(c->cnv, info[i].sn);
     1502                imcb_chat_add_buddy(c->cnv, normalize(info[i].sn));
    14741503
    14751504        return 1;
     
    14941523
    14951524        for (i = 0; i < count; i++)
    1496                 imcb_chat_remove_buddy(c->cnv, info[i].sn, NULL);
     1525                imcb_chat_remove_buddy(c->cnv, normalize(info[i].sn), NULL);
    14971526
    14981527        return 1;
     
    15451574        tmp = g_malloc(BUF_LONG);
    15461575        g_snprintf(tmp, BUF_LONG, "%s", msg);
    1547         imcb_chat_msg(ccon->cnv, info->sn, tmp, 0, 0);
     1576        imcb_chat_msg(ccon->cnv, normalize(info->sn), tmp, 0, 0);
    15481577        g_free(tmp);
    15491578
     
    17581787                        g_snprintf(sender, sizeof(sender), "%u", msg->sender);
    17591788                        strip_linefeed(dialog_msg);
    1760                         imcb_buddy_msg(ic, sender, dialog_msg, 0, t);
     1789                        imcb_buddy_msg(ic, normalize(sender), dialog_msg, 0, t);
    17611790                        g_free(dialog_msg);
    17621791                } break;
     
    17791808
    17801809                        strip_linefeed(dialog_msg);
    1781                         imcb_buddy_msg(ic, sender, dialog_msg, 0, t);
     1810                        imcb_buddy_msg(ic, normalize(sender), dialog_msg, 0, t);
    17821811                        g_free(dialog_msg);
    17831812                        g_free(m);
     
    20172046        struct aim_ssi_item *curitem;
    20182047        int tmp;
     2048        char *nrm;
    20192049
    20202050        /* Add from server list to local list */
    20212051        tmp = 0;
    20222052        for (curitem=sess->ssi.items; curitem; curitem=curitem->next) {
     2053                nrm = curitem->name ? normalize(curitem->name) : NULL;
     2054               
    20232055                switch (curitem->type) {
    20242056                        case 0x0000: /* Buddy */
    2025                                 if ((curitem->name) && (!imcb_find_buddy(ic, curitem->name))) {
     2057                                if ((curitem->name) && (!imcb_find_buddy(ic, nrm))) {
    20262058                                        char *realname = NULL;
    20272059
     
    20292061                                                    realname = aim_gettlv_str(curitem->data, 0x0131, 1);
    20302062                                               
    2031                                         imcb_add_buddy(ic, curitem->name, NULL);
     2063                                        imcb_add_buddy(ic, nrm, NULL);
    20322064                                       
    20332065                                        if (realname) {
    2034                                                 imcb_buddy_nick_hint(ic, curitem->name, realname);
    2035                                                 imcb_rename_buddy(ic, curitem->name, realname);
     2066                                                imcb_buddy_nick_hint(ic, nrm, realname);
     2067                                                imcb_rename_buddy(ic, nrm, realname);
    20362068                                                g_free(realname);
    20372069                                        }
     
    20452077                                        if (!list) {
    20462078                                                char *name;
    2047                                                 name = g_strdup(normalize(curitem->name));
     2079                                                name = g_strdup(nrm);
    20482080                                                ic->permit = g_slist_append(ic->permit, name);
    20492081                                                tmp++;
     
    20582090                                        if (!list) {
    20592091                                                char *name;
    2060                                                 name = g_strdup(normalize(curitem->name));
     2092                                                name = g_strdup(nrm);
    20612093                                                ic->deny = g_slist_append(ic->deny, name);
    20622094                                                tmp++;
     
    21202152                        if( st == 0x00 )
    21212153                        {
    2122                                 imcb_add_buddy( sess->aux_data, list, NULL );
     2154                                imcb_add_buddy( sess->aux_data, normalize(list), NULL );
    21232155                        }
    21242156                        else if( st == 0x0E )
     
    24502482        if(type2 == 0x0002) {
    24512483                /* User is typing */
    2452                 imcb_buddy_typing(ic, sn, OPT_TYPING);
     2484                imcb_buddy_typing(ic, normalize(sn), OPT_TYPING);
    24532485        }
    24542486        else if (type2 == 0x0001) {
    24552487                /* User has typed something, but is not actively typing (stale) */
    2456                 imcb_buddy_typing(ic, sn, OPT_THINKING);
     2488                imcb_buddy_typing(ic, normalize(sn), OPT_THINKING);
    24572489        }
    24582490        else {
    24592491                /* User has stopped typing */
    2460                 imcb_buddy_typing(ic, sn, 0);
     2492                imcb_buddy_typing(ic, normalize(sn), 0);
    24612493        }
    24622494       
  • protocols/yahoo/libyahoo2.c

    r2e0f24d r178e2f8  
    379379
    380380/* call repeatedly to get the next one */
    381 /*
    382381static struct yahoo_input_data * find_input_by_id(int id)
    383382{
     
    390389        return NULL;
    391390}
    392 */
    393391
    394392static struct yahoo_input_data * find_input_by_id_and_webcam_user(int id, const char * who)
     
    795793{
    796794        struct yahoo_data *yd = find_conn_by_id(id);
     795       
    797796        if(!yd)
    798797                return;
     
    31643163
    31653164        LOG(("write callback: id=%d fd=%d data=%p", id, fd, data));
    3166         if(!yid || !yid->txqueues)
     3165        if(!yid || !yid->txqueues || !find_conn_by_id(id))
    31673166                return -2;
    31683167       
     
    38403839        }
    38413840
    3842        
    3843 /*      do {
     3841        do {
    38443842                yahoo_input_close(yid);
    3845         } while((yid = find_input_by_id(id)));*/
    3846        
     3843        } while((yid = find_input_by_id(id)));
    38473844}
    38483845
  • protocols/yahoo/yahoo.c

    r2e0f24d r178e2f8  
    163163        g_slist_free( yd->buddygroups );
    164164       
    165         if( yd->logged_in )
    166                 yahoo_logoff( yd->y2_id );
    167         else
    168                 yahoo_close( yd->y2_id );
     165        yahoo_logoff( yd->y2_id );
    169166       
    170167        g_free( yd );
     
    454451        struct byahoo_write_ready_data *d = data;
    455452       
    456         if( !byahoo_get_ic_by_id( d->id ) )
    457                 /* WTF doesn't libyahoo clean this up? */
    458                 return FALSE;
    459        
    460453        yahoo_write_ready( d->id, d->fd, d->data );
    461454       
Note: See TracChangeset for help on using the changeset viewer.