diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2007-07-15 16:47:34 +0100 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2007-07-15 16:47:34 +0100 |
commit | 85023c65b697d2dab932acbda31258ae5270dbe6 (patch) | |
tree | 5ecc35fc39a5f71f0c68b4c0497d5431bef90b9a | |
parent | 1ffb46f027f501da45951428e097f69ced1c80e0 (diff) |
Added imcb_clean_handle() to sanitize handles properly (without putting
IRC-specific stuff into the Jabber module). Only using this in the MUC
code for now because this only works if the IM module can somehow convert
the cleaned up handle back to the original one.
-rw-r--r-- | protocols/jabber/conference.c | 3 | ||||
-rw-r--r-- | protocols/nogaim.c | 33 | ||||
-rw-r--r-- | protocols/nogaim.h | 1 |
3 files changed, 36 insertions, 1 deletions
diff --git a/protocols/jabber/conference.c b/protocols/jabber/conference.c index f49dbd1c..3fc9ee70 100644 --- a/protocols/jabber/conference.c +++ b/protocols/jabber/conference.c @@ -179,6 +179,9 @@ void jabber_chat_pkt_presence( struct im_connection *ic, struct jabber_buddy *bu for( i = 0; bud->resource[i]; i ++ ) if( bud->ext_jid[i] == '=' || bud->ext_jid[i] == '@' ) bud->ext_jid[i] = '_'; + + /* Some program-specific restrictions. */ + imcb_clean_handle( ic, bud->ext_jid ); } bud->flags |= JBFLAG_IS_ANONYMOUS; } diff --git a/protocols/nogaim.c b/protocols/nogaim.c index 7dc777ef..4b0b738b 100644 --- a/protocols/nogaim.c +++ b/protocols/nogaim.c @@ -98,7 +98,6 @@ void register_protocol (struct prpl *p) protocols = g_list_append(protocols, p); } - struct prpl *find_protocol(const char *name) { GList *gl; @@ -1113,3 +1112,35 @@ void imc_rem_block( struct im_connection *ic, char *handle ) ic->acc->prpl->rem_deny( ic, handle ); } + +void imcb_clean_handle( struct im_connection *ic, char *handle ) +{ + /* Accepts a handle and does whatever is necessary to make it + BitlBee-friendly. Currently this means removing everything + outside 33-127 (ASCII printable excl spaces), @ (only one + is allowed) and ! and : */ + char out[strlen(handle)+1]; + int s, d; + + s = d = 0; + while( handle[s] ) + { + if( handle[s] > ' ' && handle[s] != '!' && handle[s] != ':' && + ( handle[s] & 0x80 ) == 0 ) + { + if( handle[s] == '@' ) + { + /* See if we got an @ already? */ + out[d] = 0; + if( strchr( out, '@' ) ) + continue; + } + + out[d++] = handle[s]; + } + s ++; + } + out[d] = handle[s]; + + strcpy( handle, out ); +} diff --git a/protocols/nogaim.h b/protocols/nogaim.h index 74a63306..6aa057ff 100644 --- a/protocols/nogaim.h +++ b/protocols/nogaim.h @@ -200,6 +200,7 @@ G_MODULE_EXPORT void imcb_buddy_status( struct im_connection *ic, const char *ha /* Not implemented yet! */ G_MODULE_EXPORT void imcb_buddy_times( struct im_connection *ic, const char *handle, time_t login, time_t idle ); G_MODULE_EXPORT void imcb_buddy_msg( struct im_connection *ic, char *handle, char *msg, u_int32_t flags, time_t sent_at ); G_MODULE_EXPORT void imcb_buddy_typing( struct im_connection *ic, char *handle, u_int32_t flags ); +G_MODULE_EXPORT void imcb_clean_handle( struct im_connection *ic, char *handle ); /* Groupchats */ G_MODULE_EXPORT void imcb_chat_invited( struct im_connection *ic, char *handle, char *who, char *msg, GList *data ); |