aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2006-07-03 01:20:27 +0200
committerWilmer van der Gaast <wilmer@gaast.net>2006-07-03 01:20:27 +0200
commit911f2eb7060f6af6fe8e4e02144cfb7c4bb4cc8b (patch)
tree596dd741397ba57b4e17d521a583bde46b15935b
parent96863f65118767e968469e82ba6b02006e36b81c (diff)
Added display_name setting for MSN connections. (Should replace the nick
command later.)
-rw-r--r--account.h1
-rw-r--r--protocols/msn/msn.c90
-rw-r--r--protocols/msn/ns.c16
-rw-r--r--root_commands.c7
4 files changed, 83 insertions, 31 deletions
diff --git a/account.h b/account.h
index adb63f9e..9cf6987d 100644
--- a/account.h
+++ b/account.h
@@ -53,5 +53,6 @@ char *set_eval_account( set_t *set, char *value );
#define ACC_SET_NOSAVE 1
#define ACC_SET_OFFLINE_ONLY 2
+#define ACC_SET_ONLINE_ONLY 4
#endif
diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c
index b00354c9..790b372a 100644
--- a/protocols/msn/msn.c
+++ b/protocols/msn/msn.c
@@ -26,6 +26,16 @@
#include "nogaim.h"
#include "msn.h"
+static char *msn_set_display_name( set_t *set, char *value );
+
+static void msn_acc_init( account_t *acc )
+{
+ set_t *s;
+
+ s = set_add( &acc->set, "display_name", NULL, msn_set_display_name, acc );
+ s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY;
+}
+
static void msn_login( account_t *acc )
{
struct gaim_connection *gc = new_gaim_conn( acc );
@@ -209,36 +219,7 @@ static void msn_set_away( struct gaim_connection *gc, char *state, char *message
static void msn_set_info( struct gaim_connection *gc, char *info )
{
- int i;
- char buf[1024], *fn, *s;
- struct msn_data *md = gc->proto_data;
-
- if( strlen( info ) > 129 )
- {
- do_error_dialog( gc, "Maximum name length exceeded", "MSN" );
- return;
- }
-
- /* Of course we could use http_encode() here, but when we encode
- every character, the server is less likely to complain about the
- chosen name. However, the MSN server doesn't seem to like escaped
- non-ASCII chars, so we keep those unescaped. */
- s = fn = g_new0( char, strlen( info ) * 3 + 1 );
- for( i = 0; info[i]; i ++ )
- if( info[i] & 128 )
- {
- *s = info[i];
- s ++;
- }
- else
- {
- g_snprintf( s, 4, "%%%02X", info[i] );
- s += 3;
- }
-
- g_snprintf( buf, sizeof( buf ), "REA %d %s %s\r\n", ++md->trId, gc->username, fn );
- msn_write( gc, buf, strlen( buf ) );
- g_free( fn );
+ msn_set_display_name( set_find( &gc->acc->set, "display_name" ), info );
}
static void msn_get_info(struct gaim_connection *gc, char *who)
@@ -377,11 +358,60 @@ static int msn_send_typing( struct gaim_connection *gc, char *who, int typing )
return( 1 );
}
+static char *msn_set_display_name( set_t *set, char *value )
+{
+ account_t *acc = set->data;
+ struct gaim_connection *gc = acc->gc;
+ struct msn_data *md;
+ char buf[1024], *fn, *s;
+ int i;
+
+ /* Double-check. */
+ if( gc == NULL )
+ return NULL;
+
+ md = gc->proto_data;
+
+ if( strlen( value ) > 129 )
+ {
+ serv_got_crap( gc, "Maximum name length exceeded" );
+ return NULL;
+ }
+
+ /* Of course we could use http_encode() here, but when we encode
+ every character, the server is less likely to complain about the
+ chosen name. However, the MSN server doesn't seem to like escaped
+ non-ASCII chars, so we keep those unescaped. */
+ s = fn = g_new0( char, strlen( value ) * 3 + 1 );
+ for( i = 0; value[i]; i ++ )
+ if( value[i] & 128 )
+ {
+ *s = value[i];
+ s ++;
+ }
+ else
+ {
+ g_snprintf( s, 4, "%%%02X", value[i] );
+ s += 3;
+ }
+
+ g_snprintf( buf, sizeof( buf ), "REA %d %s %s\r\n", ++md->trId, gc->username, fn );
+ msn_write( gc, buf, strlen( buf ) );
+ g_free( fn );
+
+ /* Returning NULL would be better, because the server still has to
+ confirm the name change. However, it looks a bit confusing to the
+ user. */
+ return value;
+}
+
void msn_init()
{
struct prpl *ret = g_new0(struct prpl, 1);
+
ret->name = "msn";
ret->login = msn_login;
+ ret->acc_init = msn_acc_init;
ret->close = msn_close;
ret->send_im = msn_send_im;
ret->away_states = msn_away_states;
diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c
index e4c2b68c..9774f3e2 100644
--- a/protocols/msn/ns.c
+++ b/protocols/msn/ns.c
@@ -222,11 +222,19 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts )
}
else if( num_parts == 7 && strcmp( cmd[2], "OK" ) == 0 )
{
+ set_t *s;
+
http_decode( cmd[4] );
strncpy( gc->displayname, cmd[4], sizeof( gc->displayname ) );
gc->displayname[sizeof(gc->displayname)-1] = 0;
+ if( ( s = set_find( &gc->acc->set, "display_name" ) ) )
+ {
+ g_free( s->value );
+ s->value = g_strdup( cmd[4] );
+ }
+
set_login_progress( gc, 1, "Authenticated, getting buddy list" );
g_snprintf( buf, sizeof( buf ), "SYN %d 0\r\n", ++md->trId );
@@ -516,9 +524,17 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts )
if( g_strcasecmp( cmd[3], gc->username ) == 0 )
{
+ set_t *s;
+
http_decode( cmd[4] );
strncpy( gc->displayname, cmd[4], sizeof( gc->displayname ) );
gc->displayname[sizeof(gc->displayname)-1] = 0;
+
+ if( ( s = set_find( &gc->acc->set, "display_name" ) ) )
+ {
+ g_free( s->value );
+ s->value = g_strdup( cmd[4] );
+ }
}
else
{
diff --git a/root_commands.c b/root_commands.c
index b975b0f4..42e113ed 100644
--- a/root_commands.c
+++ b/root_commands.c
@@ -386,7 +386,12 @@ static void cmd_account( irc_t *irc, char **cmd )
if( a->gc && s && s->flags & ACC_SET_OFFLINE_ONLY )
{
- irc_usermsg( irc, "This setting can only be changed when the account is off-line" );
+ irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "off" );
+ return;
+ }
+ else if( !a->gc && s && s->flags & ACC_SET_ONLINE_ONLY )
+ {
+ irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "on" );
return;
}