aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@google.com>2012-02-10 18:00:00 +0000
committerWilmer van der Gaast <wilmer@google.com>2012-02-10 18:00:00 +0000
commitfc0640ec4530975b95f3fb14aff1fce86ffff121 (patch)
tree1d97b5af0390acb432af1d831a707f8996b4f3b7
parentbb2d198251e2001591e0080ec9500e1078e1cd4f (diff)
Support for "nameless" chatrooms on Jabber.
Just join #somechannel and start inviting people. It should Just Work, like on other IM networks. Works at least with GTalk and with other servers that have conference stuff installed on conference.$servername.
-rw-r--r--protocols/jabber/conference.c47
-rw-r--r--protocols/jabber/jabber.c6
-rw-r--r--protocols/jabber/jabber.h2
3 files changed, 55 insertions, 0 deletions
diff --git a/protocols/jabber/conference.c b/protocols/jabber/conference.c
index 74561d24..0a66b461 100644
--- a/protocols/jabber/conference.c
+++ b/protocols/jabber/conference.c
@@ -22,6 +22,7 @@
\***************************************************************************/
#include "jabber.h"
+#include "sha1.h"
static xt_status jabber_chat_join_failed( struct im_connection *ic, struct xt_node *node, struct xt_node *orig );
@@ -67,6 +68,42 @@ struct groupchat *jabber_chat_join( struct im_connection *ic, const char *room,
return c;
}
+struct groupchat *jabber_chat_with( struct im_connection *ic, char *who )
+{
+ struct jabber_data *jd = ic->proto_data;
+ struct jabber_chat *jc;
+ struct groupchat *c;
+ sha1_state_t sum;
+ double now = gettime();
+ char *uuid, *rjid, *cserv;
+
+ sha1_init( &sum );
+ sha1_append( &sum, (uint8_t*) ic->acc->user, strlen( ic->acc->user ) );
+ sha1_append( &sum, (uint8_t*) &now, sizeof( now ) );
+ sha1_append( &sum, (uint8_t*) who, strlen( who ) );
+ uuid = sha1_random_uuid( &sum );
+
+ if( jd->flags & JFLAG_GTALK )
+ cserv = g_strdup( "groupchat.google.com" );
+ else
+ /* Guess... */
+ cserv = g_strdup_printf( "conference.%s", jd->server );
+
+ rjid = g_strdup_printf( "private-chat-%s@%s", uuid, cserv );
+ g_free( uuid );
+ g_free( cserv );
+
+ c = jabber_chat_join( ic, rjid, jd->username, NULL );
+ g_free( rjid );
+ if( c == NULL )
+ return NULL;
+
+ jc = c->data;
+ jc->invite = g_strdup( who );
+
+ return c;
+}
+
static xt_status jabber_chat_join_failed( struct im_connection *ic, struct xt_node *node, struct xt_node *orig )
{
struct jabber_error *err;
@@ -115,6 +152,7 @@ void jabber_chat_free( struct groupchat *c )
g_free( jc->my_full_jid );
g_free( jc->name );
+ g_free( jc->invite );
g_free( jc );
imcb_chat_free( c );
@@ -282,6 +320,15 @@ void jabber_chat_pkt_presence( struct im_connection *ic, struct jabber_buddy *bu
imcb_buddy_nick_hint( ic, bud->ext_jid, bud->resource );
}
+ if( bud == jc->me && jc->invite != NULL )
+ {
+ char *msg = g_strdup_printf( "Please join me in room %s", jc->name );
+ jabber_chat_invite( chat, jc->invite, msg );
+ g_free( jc->invite );
+ g_free( msg );
+ jc->invite = NULL;
+ }
+
s = strchr( bud->ext_jid, '/' );
if( s ) *s = 0; /* Should NEVER be NULL, but who knows... */
imcb_chat_add_buddy( chat, bud->ext_jid );
diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c
index 41ce509b..1169963f 100644
--- a/protocols/jabber/jabber.c
+++ b/protocols/jabber/jabber.c
@@ -482,6 +482,11 @@ static struct groupchat *jabber_chat_join_( struct im_connection *ic, const char
return NULL;
}
+static struct groupchat *jabber_chat_with_( struct im_connection *ic, char *who )
+{
+ return jabber_chat_with( ic, who );
+}
+
static void jabber_chat_msg_( struct groupchat *c, char *message, int flags )
{
if( c && message )
@@ -634,6 +639,7 @@ void jabber_initmodule()
ret->chat_invite = jabber_chat_invite_;
ret->chat_leave = jabber_chat_leave_;
ret->chat_join = jabber_chat_join_;
+ ret->chat_with = jabber_chat_with_;
ret->chat_add_settings = jabber_chat_add_settings;
ret->chat_free_settings = jabber_chat_free_settings;
ret->keepalive = jabber_keepalive;
diff --git a/protocols/jabber/jabber.h b/protocols/jabber/jabber.h
index 19430505..d11d2fe8 100644
--- a/protocols/jabber/jabber.h
+++ b/protocols/jabber/jabber.h
@@ -162,6 +162,7 @@ struct jabber_chat
char *name;
char *my_full_jid; /* Separate copy because of case sensitivity. */
struct jabber_buddy *me;
+ char *invite;
};
struct jabber_transfer
@@ -338,6 +339,7 @@ extern const struct oauth2_service oauth2_service_mslive;
/* conference.c */
struct groupchat *jabber_chat_join( struct im_connection *ic, const char *room, const char *nick, const char *password );
+struct groupchat *jabber_chat_with( struct im_connection *ic, char *who );
struct groupchat *jabber_chat_by_jid( struct im_connection *ic, const char *name );
void jabber_chat_free( struct groupchat *c );
int jabber_chat_msg( struct groupchat *ic, char *message, int flags );