aboutsummaryrefslogtreecommitdiffstats
path: root/protocols/msn/msn_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/msn/msn_util.c')
-rw-r--r--protocols/msn/msn_util.c91
1 files changed, 73 insertions, 18 deletions
diff --git a/protocols/msn/msn_util.c b/protocols/msn/msn_util.c
index 9c9d2720..23447403 100644
--- a/protocols/msn/msn_util.c
+++ b/protocols/msn/msn_util.c
@@ -50,32 +50,82 @@ int msn_logged_in( struct im_connection *ic )
return( 0 );
}
-int msn_buddy_list_add( struct im_connection *ic, char *list, char *who, char *realname_ )
+int msn_buddy_list_add( struct im_connection *ic, const char *list, const char *who, const char *realname_, const char *group )
{
struct msn_data *md = ic->proto_data;
- char buf[1024], *realname;
+ char buf[1024], *realname, groupid[8];
- realname = msn_http_encode( realname_ );
-
- g_snprintf( buf, sizeof( buf ), "ADD %d %s %s %s\r\n", ++md->trId, list, who, realname );
- if( msn_write( ic, buf, strlen( buf ) ) )
+ *groupid = '\0';
+ if( group )
{
- g_free( realname );
+ int i;
+ for( i = 0; i < md->groupcount; i ++ )
+ if( g_strcasecmp( md->grouplist[i], group ) == 0 )
+ {
+ g_snprintf( groupid, sizeof( groupid ), " %d", i );
+ break;
+ }
- return( 1 );
+ if( *groupid == '\0' )
+ {
+ /* Have to create this group, it doesn't exist yet. */
+ struct msn_groupadd *ga;
+ GSList *l;
+
+ for( l = md->grpq; l; l = l->next )
+ {
+ ga = l->data;
+ if( g_strcasecmp( ga->group, group ) == 0 )
+ break;
+ }
+
+ ga = g_new0( struct msn_groupadd, 1 );
+ ga->who = g_strdup( who );
+ ga->group = g_strdup( group );
+ md->grpq = g_slist_prepend( md->grpq, ga );
+
+ if( l == NULL )
+ {
+ char *groupname = msn_http_encode( group );
+ g_snprintf( buf, sizeof( buf ), "ADG %d %s %d\r\n", ++md->trId, groupname, 0 );
+ g_free( groupname );
+ return msn_write( ic, buf, strlen( buf ) );
+ }
+ else
+ {
+ /* This can happen if the user's doing lots of adds to a
+ new group at once; we're still waiting for the server
+ to confirm group creation. */
+ return 1;
+ }
+ }
}
+ realname = msn_http_encode( realname_ );
+ g_snprintf( buf, sizeof( buf ), "ADD %d %s %s %s%s\r\n", ++md->trId, list, who, realname, groupid );
g_free( realname );
- return( 0 );
+ return msn_write( ic, buf, strlen( buf ) );
}
-int msn_buddy_list_remove( struct im_connection *ic, char *list, char *who )
+int msn_buddy_list_remove( struct im_connection *ic, char *list, const char *who, const char *group )
{
struct msn_data *md = ic->proto_data;
- char buf[1024];
+ char buf[1024], groupid[8];
+
+ *groupid = '\0';
+ if( group )
+ {
+ int i;
+ for( i = 0; i < md->groupcount; i ++ )
+ if( g_strcasecmp( md->grouplist[i], group ) == 0 )
+ {
+ g_snprintf( groupid, sizeof( groupid ), " %d", i );
+ break;
+ }
+ }
- g_snprintf( buf, sizeof( buf ), "REM %d %s %s\r\n", ++md->trId, list, who );
+ g_snprintf( buf, sizeof( buf ), "REM %d %s %s%s\r\n", ++md->trId, list, who, groupid );
if( msn_write( ic, buf, strlen( buf ) ) )
return( 1 );
@@ -93,10 +143,9 @@ static void msn_buddy_ask_yes( void *data )
{
struct msn_buddy_ask_data *bla = data;
- msn_buddy_list_add( bla->ic, "AL", bla->handle, bla->realname );
+ msn_buddy_list_add( bla->ic, "AL", bla->handle, bla->realname, NULL );
- if( imcb_find_buddy( bla->ic, bla->handle ) == NULL )
- imcb_ask_add( bla->ic, bla->handle, NULL );
+ imcb_ask_add( bla->ic, bla->handle, NULL );
g_free( bla->handle );
g_free( bla->realname );
@@ -107,7 +156,7 @@ static void msn_buddy_ask_no( void *data )
{
struct msn_buddy_ask_data *bla = data;
- msn_buddy_list_add( bla->ic, "BL", bla->handle, bla->realname );
+ msn_buddy_list_add( bla->ic, "BL", bla->handle, bla->realname, NULL );
g_free( bla->handle );
g_free( bla->realname );
@@ -348,6 +397,7 @@ void msn_msgq_purge( struct im_connection *ic, GSList **list )
struct msn_message *m;
GString *ret;
GSList *l;
+ int n = 0;
l = *list;
if( l == NULL )
@@ -362,7 +412,11 @@ void msn_msgq_purge( struct im_connection *ic, GSList **list )
{
m = l->data;
- g_string_append_printf( ret, "\n%s", m->text );
+ if( strncmp( m->text, "\r\r\r", 3 ) != 0 )
+ {
+ g_string_append_printf( ret, "\n%s", m->text );
+ n ++;
+ }
g_free( m->who );
g_free( m->text );
@@ -373,7 +427,8 @@ void msn_msgq_purge( struct im_connection *ic, GSList **list )
g_slist_free( *list );
*list = NULL;
- imcb_log( ic, "%s", ret->str );
+ if( n > 0 )
+ imcb_log( ic, "%s", ret->str );
g_string_free( ret, TRUE );
}