Changeset 70ac477 for protocols/msn


Ignore:
Timestamp:
2010-06-11T11:34:39Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
1c8e5f7
Parents:
5266354
Message:

Create new MSN groups when necessary.

Location:
protocols/msn
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/msn.c

    r5266354 r70ac477  
    104104                g_free( md->grouplist );
    105105               
     106                while( md->grpq )
     107                {
     108                        struct msn_groupadd *ga = md->grpq->data;
     109                        g_free( ga->group );
     110                        g_free( ga->who );
     111                        g_free( ga );
     112                        md->grpq = g_slist_remove( md->grpq, ga );
     113                }
     114               
    106115                g_free( md );
    107116        }
     
    122131        struct msn_switchboard *sb;
    123132       
     133#ifdef DEBUG
     134        if( strcmp( who, "raw" ) == 0 )
     135        {
     136                msn_write( ic, message, strlen( message ) );
     137                msn_write( ic, "\r\n", 2 );
     138        }
     139        else
     140#endif
    124141        if( ( sb = msn_sb_by_handle( ic, who ) ) )
    125142        {
  • protocols/msn/msn.h

    r5266354 r70ac477  
    7070        int trId;
    7171       
    72         GSList *msgq;
     72        GSList *msgq, *grpq;
    7373        GSList *switchboards;
    7474        int sb_failures;
     
    119119        char *who;
    120120        char *text;
     121};
     122
     123struct msn_groupadd
     124{
     125        char *who;
     126        char *group;
    121127};
    122128
  • protocols/msn/msn_util.c

    r5266354 r70ac477  
    5555        struct msn_data *md = ic->proto_data;
    5656        char buf[1024], *realname, groupid[8];
    57        
    58         realname = msn_http_encode( realname_ );
    5957       
    6058        *groupid = '\0';
     
    6866                                break;
    6967                        }
    70         }
    71        
     68               
     69                if( *groupid == '\0' )
     70                {
     71                        /* Have to create this group, it doesn't exist yet. */
     72                        struct msn_groupadd *ga;
     73                        GSList *l;
     74                       
     75                        for( l = md->grpq; l; l = l->next )
     76                        {
     77                                ga = l->data;
     78                                if( g_strcasecmp( ga->group, group ) == 0 )
     79                                        break;
     80                        }
     81                       
     82                        ga = g_new0( struct msn_groupadd, 1 );
     83                        ga->who = g_strdup( who );
     84                        ga->group = g_strdup( group );
     85                        md->grpq = g_slist_prepend( md->grpq, ga );
     86                       
     87                        if( l == NULL )
     88                        {
     89                                char *groupname = msn_http_encode( group );
     90                                g_snprintf( buf, sizeof( buf ), "ADG %d %s %d\r\n", ++md->trId, groupname, 0 );
     91                                g_free( groupname );
     92                                return msn_write( ic, buf, strlen( buf ) );
     93                        }
     94                        else
     95                        {
     96                                /* This can happen if the user's doing lots of adds to a
     97                                   new group at once; we're still waiting for the server
     98                                   to confirm group creation. */
     99                                return 1;
     100                        }
     101                }
     102        }
     103       
     104        realname = msn_http_encode( realname_ );
    72105        g_snprintf( buf, sizeof( buf ), "ADD %d %s %s %s%s\r\n", ++md->trId, list, who, realname, groupid );
    73         if( msn_write( ic, buf, strlen( buf ) ) )
    74         {
    75                 g_free( realname );
    76                
    77                 return( 1 );
    78         }
    79        
    80106        g_free( realname );
    81107       
    82         return( 0 );
     108        return msn_write( ic, buf, strlen( buf ) );
    83109}
    84110
  • protocols/msn/ns.c

    r5266354 r70ac477  
    612612                }
    613613        }
     614        else if( strcmp( cmd[0], "ADG" ) == 0 )
     615        {
     616                char *group = g_strdup( cmd[3] );
     617                int groupnum, i;
     618                GSList *l, *next;
     619               
     620                http_decode( group );
     621                if( sscanf( cmd[4], "%d", &groupnum ) == 1 )
     622                {
     623                        if( groupnum >= md->groupcount )
     624                        {
     625                                md->grouplist = g_renew( char *, md->grouplist, groupnum + 1 );
     626                                for( i = md->groupcount; i <= groupnum; i ++ )
     627                                        md->grouplist[i] = NULL;
     628                                md->groupcount = groupnum + 1;
     629                        }
     630                        g_free( md->grouplist[groupnum] );
     631                        md->grouplist[groupnum] = group;
     632                }
     633                else
     634                {
     635                        /* Shouldn't happen, but if it does, give up on the group. */
     636                        g_free( group );
     637                        imcb_error( ic, "Syntax error" );
     638                        imc_logout( ic, TRUE );
     639                        return 0;
     640                }
     641               
     642                for( l = md->grpq; l; l = next )
     643                {
     644                        struct msn_groupadd *ga = l->data;
     645                        next = l->next;
     646                        if( g_strcasecmp( ga->group, group ) == 0 )
     647                        {
     648                                if( !msn_buddy_list_add( ic, "FL", ga->who, ga->who, group ) )
     649                                        return 0;
     650                               
     651                                g_free( ga->group );
     652                                g_free( ga->who );
     653                                g_free( ga );
     654                                md->grpq = g_slist_remove( md->grpq, ga );
     655                        }
     656                }
     657        }
    614658        else if( isdigit( cmd[0][0] ) )
    615659        {
Note: See TracChangeset for help on using the changeset viewer.