diff options
| author | Wilmer van der Gaast <wilmer@gaast.net> | 2010-08-14 17:16:52 +0100 | 
|---|---|---|
| committer | Wilmer van der Gaast <wilmer@gaast.net> | 2010-08-14 17:16:52 +0100 | 
| commit | 193dc742d357bb604fff8921417c74ddf9e8729c (patch) | |
| tree | d9f720fb2304e47f39186c5d0b5bf927fbf8e000 | |
| parent | e5854a80111e337be01cf1e506073a231fac1c3d (diff) | |
Responses to add requests work now.
| -rw-r--r-- | protocols/msn/msn.c | 14 | ||||
| -rw-r--r-- | protocols/msn/msn.h | 4 | ||||
| -rw-r--r-- | protocols/msn/msn_util.c | 74 | ||||
| -rw-r--r-- | protocols/msn/ns.c | 7 | ||||
| -rw-r--r-- | protocols/msn/soap.c | 81 | ||||
| -rw-r--r-- | protocols/msn/soap.h | 41 | 
6 files changed, 198 insertions, 23 deletions
| diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index ed0881d1..679ac65e 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -216,14 +216,14 @@ static void msn_add_buddy( struct im_connection *ic, char *who, char *group )  {  	struct bee_user *bu = bee_user_by_handle( ic->bee, ic, who ); -	msn_buddy_list_add( ic, "FL", who, who, group ); +	msn_buddy_list_add( ic, MSN_BUDDY_FL, who, who, group );  	if( bu && bu->group ) -		msn_buddy_list_remove( ic, "FL", who, bu->group->name ); +		msn_buddy_list_remove( ic, MSN_BUDDY_FL, who, bu->group->name );  }  static void msn_remove_buddy( struct im_connection *ic, char *who, char *group )  { -	msn_buddy_list_remove( ic, "FL", who, NULL ); +	msn_buddy_list_remove( ic, MSN_BUDDY_FL, who, NULL );  }  static void msn_chat_msg( struct groupchat *c, char *message, int flags ) @@ -288,19 +288,19 @@ static void msn_keepalive( struct im_connection *ic )  static void msn_add_permit( struct im_connection *ic, char *who )  { -	msn_buddy_list_add( ic, "AL", who, who, NULL ); +	msn_buddy_list_add( ic, MSN_BUDDY_AL, who, who, NULL );  }  static void msn_rem_permit( struct im_connection *ic, char *who )  { -	msn_buddy_list_remove( ic, "AL", who, NULL ); +	msn_buddy_list_remove( ic, MSN_BUDDY_AL, who, NULL );  }  static void msn_add_deny( struct im_connection *ic, char *who )  {  	struct msn_switchboard *sb; -	msn_buddy_list_add( ic, "BL", who, who, NULL ); +	msn_buddy_list_add( ic, MSN_BUDDY_BL, who, who, NULL );  	/* If there's still a conversation with this person, close it. */  	if( ( sb = msn_sb_by_handle( ic, who ) ) ) @@ -311,7 +311,7 @@ static void msn_add_deny( struct im_connection *ic, char *who )  static void msn_rem_deny( struct im_connection *ic, char *who )  { -	msn_buddy_list_remove( ic, "BL", who, NULL ); +	msn_buddy_list_remove( ic, MSN_BUDDY_BL, who, NULL );  }  static int msn_send_typing( struct im_connection *ic, char *who, int typing ) diff --git a/protocols/msn/msn.h b/protocols/msn/msn.h index d9609189..862d1ef7 100644 --- a/protocols/msn/msn.h +++ b/protocols/msn/msn.h @@ -200,8 +200,8 @@ void msn_auth_got_contact_list( struct im_connection *ic );  /* msn_util.c */  int msn_write( struct im_connection *ic, char *s, int len );  int msn_logged_in( struct im_connection *ic ); -int msn_buddy_list_add( struct im_connection *ic, const char *list, const char *who, const char *realname_, const char *group ); -int msn_buddy_list_remove( struct im_connection *ic, char *list, const char *who, const char *group ); +int msn_buddy_list_add( struct im_connection *ic, msn_buddy_flags_t list, const char *who, const char *realname_, const char *group ); +int msn_buddy_list_remove( struct im_connection *ic, msn_buddy_flags_t list, const char *who, const char *group );  void msn_buddy_ask( bee_user_t *bu );  char *msn_findheader( char *text, char *header, int len );  char **msn_linesplit( char *line ); diff --git a/protocols/msn/msn_util.c b/protocols/msn/msn_util.c index 6a5afd93..54bfad7f 100644 --- a/protocols/msn/msn_util.c +++ b/protocols/msn/msn_util.c @@ -26,6 +26,7 @@  #include "nogaim.h"  #include "msn.h"  #include "md5.h" +#include "soap.h"  #include <ctype.h>  int msn_write( struct im_connection *ic, char *s, int len ) @@ -57,12 +58,31 @@ int msn_logged_in( struct im_connection *ic )  	return( 0 );  } -int msn_buddy_list_add( struct im_connection *ic, const char *list, const char *who, const char *realname_, const char *group ) +static char *adlrml_entry( const char *handle_, msn_buddy_flags_t list ) +{ +	char *domain, handle[strlen(handle_)+1]; +	 +	strcpy( handle, handle_ ); +	if( ( domain = strchr( handle, '@' ) ) ) +		*(domain +		++) = '\0'; +	else +		return NULL; +	 +	return g_markup_printf_escaped( "<ml><d n=\"%s\"><c n=\"%s\" l=\"%d\" t=\"1\"/></d></ml>", +		domain, handle, list ); +} + +int msn_buddy_list_add( struct im_connection *ic, msn_buddy_flags_t list, const char *who, const char *realname_, const char *group )  {  	struct msn_data *md = ic->proto_data; -	char buf[1024], realname[strlen(realname_)*3+1], groupid[8]; +	char buf[1024], groupid[8]; +	bee_user_t *bu; +	struct msn_buddy_data *bd; +	char *adl;  	*groupid = '\0'; +#if 0  	if( group )  	{  		int i; @@ -108,20 +128,36 @@ int msn_buddy_list_add( struct im_connection *ic, const char *list, const char *  			}  		}  	} +#endif +	 +	if( !( bu = bee_user_by_handle( ic->bee, ic, who ) ) || +	    !( bd = bu->data ) || bd->flags & list ) +		return 1; -	strcpy( realname, realname_ ); -	http_encode( realname ); -	g_snprintf( buf, sizeof( buf ), "ADD %d %s %s %s%s\r\n", ++md->trId, list, who, realname, groupid ); +	bd->flags |= list; -	return msn_write( ic, buf, strlen( buf ) ); +	msn_soap_memlist_edit( ic, who, TRUE, list ); +	 +	if( ( adl = adlrml_entry( who, list ) ) ) +	{ +		g_snprintf( buf, sizeof( buf ), "ADL %d %zd\r\n%s", +		            ++md->trId, strlen( adl ), adl ); +		g_free( adl ); +		 +		return msn_write( ic, buf, strlen( buf ) ); +	}  } -int msn_buddy_list_remove( struct im_connection *ic, char *list, const char *who, const char *group ) +int msn_buddy_list_remove( struct im_connection *ic, msn_buddy_flags_t list, const char *who, const char *group )  {  	struct msn_data *md = ic->proto_data;  	char buf[1024], groupid[8]; +	bee_user_t *bu; +	struct msn_buddy_data *bd; +	char *adl;  	*groupid = '\0'; +#if 0  	if( group )  	{  		int i; @@ -132,10 +168,24 @@ int msn_buddy_list_remove( struct im_connection *ic, char *list, const char *who  				break;  			}  	} +#endif +	 +	if( !( bu = bee_user_by_handle( ic->bee, ic, who ) ) || +	    !( bd = bu->data ) || !( bd->flags & list ) ) +		return 1; +	 +	bd->flags &= ~list; -	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 ); +	msn_soap_memlist_edit( ic, who, FALSE, list ); +	 +	if( ( adl = adlrml_entry( who, list ) ) ) +	{ +		g_snprintf( buf, sizeof( buf ), "RML %d %zd\r\n%s", +		            ++md->trId, strlen( adl ), adl ); +		g_free( adl ); +		 +		return msn_write( ic, buf, strlen( buf ) ); +	}  	return( 0 );  } @@ -151,7 +201,7 @@ 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, NULL ); +	msn_buddy_list_add( bla->ic, MSN_BUDDY_AL, bla->handle, bla->realname, NULL );  	imcb_ask_add( bla->ic, bla->handle, NULL ); @@ -164,7 +214,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, NULL ); +	msn_buddy_list_add( bla->ic, MSN_BUDDY_BL, bla->handle, bla->realname, NULL );  	g_free( bla->handle );  	g_free( bla->realname ); diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c index 7518dc25..23b8f3b1 100644 --- a/protocols/msn/ns.c +++ b/protocols/msn/ns.c @@ -263,10 +263,13 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts )  		if( num_parts >= 3 && strcmp( cmd[2], "OK" ) == 0 )  		{  			char buf[1024]; -			char *fn_raw = set_getstr( &ic->acc->set, "display_name" ); +			char *fn_raw;  			char *fn; -			if( fn_raw == NULL ) +			if( ic->flags & OPT_LOGGED_IN ) +				return 1; +			 +			if( ( fn_raw = set_getstr( &ic->acc->set, "display_name" ) ) == NULL )  				fn_raw = ic->acc->user;  			fn = g_malloc( strlen( fn_raw ) * 3 + 1 );  			strcpy( fn, fn_raw ); diff --git a/protocols/msn/soap.c b/protocols/msn/soap.c index 8cc241b8..93bb37a6 100644 --- a/protocols/msn/soap.c +++ b/protocols/msn/soap.c @@ -516,6 +516,87 @@ int msn_soap_memlist_request( struct im_connection *ic )  	                                 msn_soap_memlist_free_data );  } +/* Variant: Adding/Removing people */ +struct msn_soap_memlist_edit_data +{ +	char *handle; +	gboolean add; +	msn_buddy_flags_t list; +}; + +static int msn_soap_memlist_edit_build_request( struct msn_soap_req_data *soap_req ) +{ +	struct msn_data *md = soap_req->ic->proto_data; +	struct msn_soap_memlist_edit_data *med = soap_req->data; +	char *add, *scenario, *list; +	 +	soap_req->url = g_strdup( SOAP_MEMLIST_URL ); +	if( med->add ) +	{ +		soap_req->action = g_strdup( SOAP_MEMLIST_ADD_ACTION ); +		add = "Add"; +	} +	else +	{ +		soap_req->action = g_strdup( SOAP_MEMLIST_DEL_ACTION ); +		add = "Delete"; +	} +	switch( med->list ) +	{ +	case MSN_BUDDY_AL: +		scenario = "BlockUnblock"; +		list = "Allow"; +		break; +	case MSN_BUDDY_BL: +		scenario = "BlockUnblock"; +		list = "Block"; +		break; +	case MSN_BUDDY_RL: +		scenario = "Timer"; +		list = "Reverse"; +		break; +	case MSN_BUDDY_PL: +	default: +		scenario = "Timer"; +		list = "Pending"; +		break; +	} +	soap_req->payload = g_markup_printf_escaped( SOAP_MEMLIST_EDIT_PAYLOAD, +		scenario, md->tokens[1], add, list, med->handle, add ); +	 +	return 1; +} + +static int msn_soap_memlist_edit_handle_response( struct msn_soap_req_data *soap_req ) +{ +	return MSN_SOAP_OK; +} + +static int msn_soap_memlist_edit_free_data( struct msn_soap_req_data *soap_req ) +{ +	struct msn_soap_memlist_edit_data *med = soap_req->data; +	 +	g_free( med->handle ); +	g_free( med ); +	 +	return 0; +} + +int msn_soap_memlist_edit( struct im_connection *ic, const char *handle, gboolean add, int list ) +{ +	struct msn_soap_memlist_edit_data *med; +	 +	med = g_new0( struct msn_soap_memlist_edit_data, 1 ); +	med->handle = g_strdup( handle ); +	med->add = add; +	med->list = list; +	 +	return msn_soap_start( ic, med, msn_soap_memlist_edit_build_request, +	                                NULL, +	                                msn_soap_memlist_edit_handle_response, +	                                msn_soap_memlist_edit_free_data ); +} +  /* addressbook: Fetching the membership list (NOT address book) */ diff --git a/protocols/msn/soap.h b/protocols/msn/soap.h index 5673583a..9ef68df9 100644 --- a/protocols/msn/soap.h +++ b/protocols/msn/soap.h @@ -189,7 +189,48 @@ int msn_soap_oim_send_queue( struct im_connection *ic, GSList **msgq );    "</soap:Body>" \  "</soap:Envelope>" +#define SOAP_MEMLIST_ADD_ACTION "http://www.msn.com/webservices/AddressBook/AddMember" +#define SOAP_MEMLIST_DEL_ACTION "http://www.msn.com/webservices/AddressBook/DeleteMember" + +#define SOAP_MEMLIST_EDIT_PAYLOAD \ +"<?xml version=\"1.0\" encoding=\"utf-8\"?>" \ +"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" \ +  "<soap:Header xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" \ +    "<ABApplicationHeader xmlns=\"http://www.msn.com/webservices/AddressBook\">" \ +      "<ApplicationId xmlns=\"http://www.msn.com/webservices/AddressBook\">CFE80F9D-180F-4399-82AB-413F33A1FA11</ApplicationId>" \ +      "<IsMigration xmlns=\"http://www.msn.com/webservices/AddressBook\">false</IsMigration>" \ +      "<PartnerScenario xmlns=\"http://www.msn.com/webservices/AddressBook\">%s</PartnerScenario>" \ +    "</ABApplicationHeader>" \ +    "<ABAuthHeader xmlns=\"http://www.msn.com/webservices/AddressBook\">" \ +      "<ManagedGroupRequest xmlns=\"http://www.msn.com/webservices/AddressBook\">false</ManagedGroupRequest>" \ +      "<TicketToken>%s</TicketToken>" \ +    "</ABAuthHeader>" \ +  "</soap:Header>" \ +  "<soap:Body xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" \ +  "<%sMember xmlns=\"http://www.msn.com/webservices/AddressBook\">" \ +   "<serviceHandle>" \ +    "<Id>0</Id>" \ +    "<Type>Messenger</Type>" \ +    "<ForeignId></ForeignId>" \ +   "</serviceHandle>" \ +   "<memberships>" \ +    "<Membership>" \ +     "<MemberRole>%s</MemberRole>" \ +     "<Members>" \ +      "<Member xsi:type=\"PassportMember\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" \ +       "<Type>Passport</Type>" \ +       "<State>Accepted</State>" \ +       "<PassportName>%s</PassportName>" \ +      "</Member>" \ +     "</Members>" \ +    "</Membership>" \ +   "</memberships>" \ +  "</%sMember>" \ +  "</soap:Body>" \ +"</soap:Envelope>" +  int msn_soap_memlist_request( struct im_connection *ic ); +int msn_soap_memlist_edit( struct im_connection *ic, const char *handle, gboolean add, int list );  #define SOAP_ADDRESSBOOK_URL "http://contacts.msn.com/abservice/abservice.asmx" | 
