Hi, this is marv from #gaim, I just though I'd let everyone know what I
was up to. So here's my patch against yahoo.c in gaim .63. There's still
a couple bugs i'm trying to track down, still need to handle some weird
formatting stuff chat's send, and for some reason you can't always join
chats, I think your ability to join chats might time out, not sure.
Chat's and Conference's are different things in Yahoo. A conference is
sort of a private chat, and almost like a multiparty IM. (you have to
send everyone its to in every packet) A chat on the other hand is public
and accessable from chat.yahoo.com.
In order to join a chat, you have to change the word Conference to Chat
in the dialog and type a room name from the website, with a :1 on the
end. (or :2 to join the 2nd room, etc) Sometimes it doesn't work, seems
to be after you've been online a while, still looking into it.
Also you could just have someone invite you. (that also doesn't work
when joining doesn't work though)
Anyway, here's what I got so far.
--Tim
--- gaim-0.63/src/protocols/yahoo/yahoo.c 2003-05-14 14:18:50.000000000
-0500
+++ ../gaim-0.63/src/protocols/yahoo/yahoo.c 2003-05-29
22:49:52.000000000 -0500
@@ -1,6 +1,38 @@
/*
* gaim
*
+ * Some code copyright 2003 Tim Ringenbach <omarvo@...>
+ * (marv on irc.freenode.net)
+ *
+ * Some code borrowed from libyahoo2, which has the following copyright
+ * notice:
+ ************************************************************************
+ * libyahoo2: libyahoo2.c
+ *
+ * Some code copyright (C) 2002, Philip S Tellis <philip . tellis AT
gmx . net>
+ *
+ * Much of this code was taken and adapted from the yahoo module for
+ * gaim released under the GNU GPL. This code is also released under the
+ * GNU GPL.
+ *
+ * This code is derivitive of Gaim <http://gaim.sourceforge.net>
+ * copyright (C) 1998-1999, Mark Spencer <markster@...>
+ * 1998-1999, Adam Fritzler <afritz@...>
+ * 1998-2002, Rob Flynn <rob@...>
+ * 2000-2002, Eric Warmenhoven <eric@...>
+ * 2001-2002, Brian Macke <macke@...>
+ * 2001, Anand Biligiri S <abiligiri@...>
+ * 2001, Valdis Kletnieks
+ * 2002, Sean Egan <bj91704@...>
+ * 2002, Toby Gray <toby.gray@...>
+ *
+ * This library also uses code from other libraries, namely:
+ * Portions from libfaim copyright 1998, 1999 Adam Fritzler
+ * <afritz@...>
+ * Portions of Sylpheed copyright 2000-2002 Hiroyuki Yamamoto
+ * <hiro-y@...>
+ *********************************************************************
+ *
* Some code copyright (C) 1998-1999, Mark Spencer <markster@...>
* libfaim code copyright 1998, 1999 Adam Fritzler <afritz@...>
*
@@ -53,6 +85,7 @@
extern char *yahoo_crypt(char *, char *);
+
/* for win32 compatability */
G_MODULE_IMPORT GSList *connections;
@@ -86,7 +119,7 @@
YAHOO_SERVICE_ADDIDENT, /* 0x10 */
YAHOO_SERVICE_ADDIGNORE,
YAHOO_SERVICE_PING,
- YAHOO_SERVICE_GROUPRENAME,
+ YAHOO_SERVICE_GOTGROUPRENAME,
YAHOO_SERVICE_SYSMESSAGE = 0x14,
YAHOO_SERVICE_PASSTHROUGH2 = 0x16,
YAHOO_SERVICE_CONFINVITE = 0x18,
@@ -102,12 +135,31 @@
YAHOO_SERVICE_GAMELOGOFF,
YAHOO_SERVICE_GAMEMSG = 0x2a,
YAHOO_SERVICE_FILETRANSFER = 0x46,
+ YAHOO_SERVICE_VOICECHAT = 0x4A,
YAHOO_SERVICE_NOTIFY = 0x4B,
+ YAHOO_SERVICE_VERIFY,
+ YAHOO_SERVICE_P2PFILEXFER,
+ YAHOO_SERVICE_PEERTOPEER = 0x4F, /* Checks if P2P possible */
+ YAHOO_SERVICE_WEBCAM,
YAHOO_SERVICE_AUTHRESP = 0x54,
YAHOO_SERVICE_LIST = 0x55,
YAHOO_SERVICE_AUTH = 0x57,
YAHOO_SERVICE_ADDBUDDY = 0x83,
- YAHOO_SERVICE_REMBUDDY = 0x84
+ YAHOO_SERVICE_REMBUDDY = 0x84,
+ YAHOO_SERVICE_IGNORECONTACT, /* > 1, 7, 13 < 1, 66, 13, 0*/
+ YAHOO_SERVICE_REJECTCONTACT,
+ YAHOO_SERVICE_GROUPRENAME = 0x89, /* > 1, 65(new), 66(0), 67(old) */
+ YAHOO_SERVICE_CHATONLINE = 0x96, /* > 109(id), 1, 6(abcde) < 0,1*/
+ YAHOO_SERVICE_CHATGOTO,
+ YAHOO_SERVICE_CHATJOIN, /* > 1 104-room 129-1600326591 62-2 */
+ YAHOO_SERVICE_CHATLEAVE,
+ YAHOO_SERVICE_CHATEXIT = 0x9b,
+ YAHOO_SERVICE_CHATADDINVITE = 0x9d,
+ YAHOO_SERVICE_CHATLOGOUT = 0xa0,
+ YAHOO_SERVICE_CHATPING,
+ YAHOO_SERVICE_COMMENT = 0xa8
+
+
};
enum yahoo_status {
@@ -137,6 +189,8 @@
GHashTable *games;
int current_status;
gboolean logged_in;
+ GSList *confs;
+ int chat_id;
};
struct yahoo_pair {
@@ -150,9 +204,57 @@
guint32 id;
GSList *hash;
};
+/* TODO: actually use this.
+struct yahoo_chat_member {
+ char *id;
+ int age;
+ int attribs;
+ char *alias;
+ char *location;
+};
+*/
#define YAHOO_PACKET_HDRLEN (4 + 2 + 2 + 2 + 2 + 4 + 4)
+static int chat_id_counter = 1;
+static void yahoo_process_conference(struct gaim_connection *gc, struct
yahoo_packet *pkt);
+static void yahoo_process_chat(struct gaim_connection *gc, struct
yahoo_packet *pkt);
+static void yahoo_chatjoin(struct gaim_connection *gc, struct
yahoo_data *yd, char *room, char *topic);
+/*
+
+<marv> i don't suppose gaim has a function to fetch a text file over
http for interal use?
+<ChipX86|Coding> I think it does
+<ChipX86|Coding> check gtkprefs.c. Grep for smilies
+<ChipX86|Coding> maybe it's in html.c that this happens
+<ChipX86|Coding> I think I'll make a snack run soon
+
+
+
+<ChipX86> the only things UI-like it can use are gaim_notify_* and
gaim_request_
+*/
+
+
+static char *ansi_to_html(char *x)
+{
+ char *m, *msg;
+ int i, j;
+ /* borrwoed from the IM code, strips ansi color codes
+ FIXME: make this change them to html instead */
+ m = msg = g_strdup(x);
+
+ for (i = 0, j = 0; m[i]; i++) {
+ if (m[i] == 033) {
+ while (m[i] && (m[i] != 'm'))
+ i++;
+ if (!m[i])
+ i--;
+ continue;
+ }
+ msg[j++] = m[i];
+ }
+ msg[j] = 0;
+ return msg;
+}
static struct yahoo_packet *yahoo_packet_new(enum yahoo_service
service, enum yahoo_status status, int id)
{
struct yahoo_packet *pkt = g_new0(struct yahoo_packet, 1);
@@ -316,7 +418,7 @@
gaim_debug(GAIM_DEBUG_MISC, "yahoo", "");
}
- if (isprint(data[i]))
+ if (isprint(data[i]) && !(data[i] & 0xa0))
gaim_debug(GAIM_DEBUG_MISC, NULL, "%c ", data[i]);
else
gaim_debug(GAIM_DEBUG_MISC, NULL, ". ");
@@ -350,7 +452,9 @@
yahoo_packet_write(pkt, data + pos);
+ gaim_debug(GAIM_DEBUG_MISC, "yahoo", "Start of outgoing packet.\n");
yahoo_packet_dump(data, len);
+ gaim_debug(GAIM_DEBUG_MISC, "yahoo", "End of outgoing packet.\n");
ret = write(yd->fd, data, len);
g_free(data);
@@ -368,6 +472,22 @@
g_free(pkt);
}
+static void yahoo_chat_online(struct gaim_connection *gc)
+{
+ struct yahoo_data *yd = gc->proto_data;
+ struct yahoo_packet *pkt;
+
+
+ pkt = yahoo_packet_new(YAHOO_SERVICE_CHATONLINE,
YAHOO_STATUS_AVAILABLE,0);
+ yahoo_packet_hash(pkt, 1, gc->displayname);
+ yahoo_packet_hash(pkt, 109, gc->displayname);
+ yahoo_packet_hash(pkt, 6, "abcde");
+
+ yahoo_send_packet(yd, pkt);
+
+ yahoo_packet_free(pkt);
+}
+
static void yahoo_process_status(struct gaim_connection *gc, struct
yahoo_packet *pkt)
{
struct yahoo_data *yd = gc->proto_data;
@@ -376,7 +496,7 @@
int state = 0;
int gamestate = 0;
char *msg = NULL;
-
+
while (l) {
struct yahoo_pair *pair = l->data;
@@ -392,7 +512,7 @@
/* this requests the list. i have a feeling that this is very evil
*
- * scs.yahoo.com sends you the list before this packet without it
being
+ * scs.yahoo.com sends you the list before this packet without it
being
* requested
*
* do_import(gc, NULL);
@@ -400,7 +520,7 @@
* yahoo_send_packet(yd, newpkt);
* yahoo_packet_free(newpkt);
*/
-
+ yahoo_chat_online(gc);
}
break;
case 8: /* how many online buddies we have */
@@ -530,7 +650,7 @@
if (!msg)
return;
-
+
if (!g_ascii_strncasecmp(msg, "TYPING", strlen("TYPING"))) {
if (*stat == '1')
serv_got_typing(gc, from, 0, TYPING);
@@ -571,7 +691,7 @@
char *from = NULL;
time_t tm = time(NULL);
GSList *l = pkt->hash;
-
+
while (l) {
struct yahoo_pair *pair = l->data;
if (pair->key == 4)
@@ -584,22 +704,11 @@
}
if (pkt->status <= 1 || pkt->status == 5) {
- char *m;
- int i, j;
strip_linefeed(msg);
- m = msg;
- for (i = 0, j = 0; m[i]; i++) {
- if (m[i] == 033) {
- while (m[i] && (m[i] != 'm'))
- i++;
- if (!m[i])
- i--;
- continue;
- }
- msg[j++] = m[i];
- }
- msg[j] = 0;
+ msg = ansi_to_html(msg);
+
serv_got_im(gc, from, g_strdup(msg), 0, tm, -1);
+ g_free(msg);
} else if (pkt->status == 2) {
do_error_dialog(_("Your Yahoo! message did not get sent."), NULL,
GAIM_ERROR);
}
@@ -626,7 +735,7 @@
who = pair->value;
else if (pair->key == 14)
msg = pair->value;
- else if (pair->key == 7)
+ else if (pair->key == 7)
name = pair->value;
else if (pair->key == 10)
state = strtol(pair->value, NULL, 10);
@@ -722,7 +831,7 @@
char *sn = NULL;
GSList *l = pkt->hash;
struct yahoo_data *yd = gc->proto_data;
-
+
while (l) {
struct yahoo_pair *pair = l->data;
if (pair->key == 94)
@@ -731,13 +840,13 @@
sn = pair->value;
l = l->next;
}
-
+
if (seed) {
struct yahoo_packet *pack;
-
+
/* So, Yahoo has stopped supporting its older clients in India, and
undoubtedly
* will soon do so in the rest of the world.
- *
+ *
* The new clients use this authentication method. I warn you in
advance, it's
* bizzare, convoluted, inordinately complicated. It's also no more
secure than
* crypt() was. The only purpose this scheme could serve is to
prevent third
@@ -745,7 +854,7 @@
*
* Sorry, Yahoo.
*/
-
+
md5_byte_t result[16];
md5_state_t ctx;
char *crypt_result;
@@ -753,11 +862,11 @@
char *crypt_hash = g_malloc(25);
char *hash_string_p = g_malloc(50 + strlen(sn));
char *hash_string_c = g_malloc(50 + strlen(sn));
-
+
char checksum;
-
+
int sv;
-
+
char *result6 = g_malloc(25);
char *result96 = g_malloc(25);
@@ -768,9 +877,9 @@
md5_append(&ctx, gc->password, strlen(gc->password));
md5_finish(&ctx, result);
to_y64(password_hash, result, 16);
-
+
md5_init(&ctx);
- crypt_result = yahoo_crypt(gc->password, "$1$_2S43d5f$");
+ crypt_result = yahoo_crypt(gc->password, "$1$_2S43d5f$");
md5_append(&ctx, crypt_result, strlen(crypt_result));
md5_finish(&ctx, result);
to_y64(crypt_hash, result, 16);
@@ -815,13 +924,13 @@
"%c%s%s%s", checksum, crypt_hash, gc->username, seed);
break;
}
-
- md5_init(&ctx);
+
+ md5_init(&ctx);
md5_append(&ctx, hash_string_p, strlen(hash_string_p));
md5_finish(&ctx, result);
to_y64(result6, result, 16);
- md5_init(&ctx);
+ md5_init(&ctx);
md5_append(&ctx, hash_string_c, strlen(hash_string_c));
md5_finish(&ctx, result);
to_y64(result96, result, 16);
@@ -831,9 +940,9 @@
yahoo_packet_hash(pack, 6, result6);
yahoo_packet_hash(pack, 96, result96);
yahoo_packet_hash(pack, 1, gc->username);
-
+
yahoo_send_packet(yd, pack);
-
+
g_free(result6);
g_free(result96);
g_free(password_hash);
@@ -849,12 +958,16 @@
{
switch (pkt->service)
{
+
+ /* case YAHOO_SERVICE_USERSTAT: */
case YAHOO_SERVICE_LOGON:
case YAHOO_SERVICE_LOGOFF:
case YAHOO_SERVICE_ISAWAY:
case YAHOO_SERVICE_ISBACK:
case YAHOO_SERVICE_GAMELOGON:
case YAHOO_SERVICE_GAMELOGOFF:
+ /* case YAHOO_SERVICE_IDACT: */
+ /* case YAHOO_SERVICE_IDDEACT: */
yahoo_process_status(gc, pkt);
break;
case YAHOO_SERVICE_NOTIFY:
@@ -862,6 +975,7 @@
break;
case YAHOO_SERVICE_MESSAGE:
case YAHOO_SERVICE_GAMEMSG:
+ /* case YAHOO_SERVICE_SYSMESSAGE: */
yahoo_process_message(gc, pkt);
break;
case YAHOO_SERVICE_NEWMAIL:
@@ -876,6 +990,27 @@
case YAHOO_SERVICE_AUTH:
yahoo_process_auth(gc, pkt);
break;
+ case YAHOO_SERVICE_CONFINVITE:
+ case YAHOO_SERVICE_CONFADDINVITE:
+ case YAHOO_SERVICE_CONFDECLINE:
+ case YAHOO_SERVICE_CONFLOGON:
+ case YAHOO_SERVICE_CONFLOGOFF:
+ case YAHOO_SERVICE_CONFMSG:
+ yahoo_process_conference(gc, pkt);
+ break;
+ case YAHOO_SERVICE_CHATONLINE:
+ case YAHOO_SERVICE_CHATGOTO:
+ case YAHOO_SERVICE_CHATJOIN:
+ case YAHOO_SERVICE_CHATLEAVE:
+ case YAHOO_SERVICE_CHATEXIT:
+ case YAHOO_SERVICE_CHATLOGOUT:
+ case YAHOO_SERVICE_CHATPING:
+ case YAHOO_SERVICE_COMMENT:
+ case YAHOO_SERVICE_CHATINVITE:
+ case YAHOO_SERVICE_CHATADDINVITE:
+ yahoo_process_chat(gc, pkt);
+ break;
+
default:
gaim_debug(GAIM_DEBUG_ERROR, "yahoo",
"Unhandled service 0x%02x\n", pkt->service);
@@ -1034,6 +1169,7 @@
yd->rxlen = 0;
if (gc->inpa)
gaim_input_remove(gc->inpa);
+ g_slist_free(yd->confs);
g_free(yd);
}
@@ -1169,7 +1305,7 @@
while (*room && *room != '\t') /* skip to the tab */
room++;
t = room++; /* room as now at the name */
- while (*t != '\n')
+ while (*t != '\n')
t++; /* replace the \n with a space */
*t = ' ';
g_snprintf(buf2, sizeof buf2, "%s", room);
@@ -1179,7 +1315,7 @@
m = g_list_append(m, pbm);
}
}
-
+
return m;
}
@@ -1227,7 +1363,7 @@
yahoo_send_packet(yd, pkt);
yahoo_packet_free(pkt);
-
+
return 1;
}
@@ -1405,6 +1541,648 @@
yahoo_packet_free(pkt);
}
+static struct gaim_conversation *yahoo_find_chat(struct gaim_connection
*gc, const char *name)
+{
+ GSList *bcs = gc->buddy_chats;
+
+ while (bcs) {
+ struct gaim_conversation *b = bcs->data;
+ if (!gaim_utf8_strcasecmp(b->name, name))
+ return b;
+ bcs = bcs->next;
+ }
+ return NULL;
+}
+
+static void concatlist(gpointer a, gpointer d)
+{
+ gpointer *b = d;
+ char *n;
+ n = g_strjoin("\n", *b, a, NULL);
+ g_free(*b);
+ *b = n;
+}
+
+/* mostly copied from libyahoo2.c of libyahoo2 */
+static void yahoo_process_conference(struct gaim_connection *gc, struct
yahoo_packet *pkt)
+{
+ struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data;
+ char *msg = NULL;
+ char *host = NULL;
+ char *who = NULL;
+ char *room = NULL;
+ char *id = NULL;
+ int utf8 = 0;
+ GList *members = NULL;
+ int free_members = 1;
+ GSList *l;
+ GList *dl;
+
+ for (l = pkt->hash; l; l = l->next) {
+ struct yahoo_pair *pair = l->data;
+ if (pair->key == 50)
+ host = pair->value;
+
+ if (pair->key == 53) /* logon */
+ who = pair->value;
+ if (pair->key == 54) /* decline */
+ who = pair->value;
+ if (pair->key == 55) /* unavailable (status == 2) */
+ who = pair->value;
+ if (pair->key == 56) /* logoff */
+ who = pair->value;
+
+ if (pair->key == 57)
+ room = pair->value;
+
+ if (pair->key == 58) /* join message */
+ msg = pair->value;
+ if (pair->key == 14) /* decline/conf message */
+ msg = pair->value;
+
+ if (pair->key == 13)
+ ;
+ if (pair->key == 16) /* error */
+ msg = pair->value;
+
+ if (pair->key == 1) /* my id */
+ id = pair->value;
+ if (pair->key == 3) /* message sender */
+ who = pair->value;
+
+
+ if (pair->key == 52) { /* invite */
+ char *member;
+ member = g_strdup(pair->value);
+ for (dl = members; dl; dl = dl->next) {
+ char * w = dl->data;
+ if (!strcmp(w, member)) {
+ g_free(member);
+ break;
+ }
+ }
+ if (!dl)
+ members = g_list_append(members, member);
+ }
+
+ if (pair->key == 97)
+ utf8 = atoi(pair->value);
+ }
+
+ if (!who && host)
+ who = host;
+
+ if (!room)
+ return;
+
+ if (host) {
+ for (dl = members; dl; dl = dl->next) {
+ char * w = dl->data;
+ if (!strcmp(w, host))
+ break;
+ }
+ if (!dl)
+ members = g_list_append(members, g_strdup(host));
+ }
+ /* invite, decline, join, left, message -> status == 1 */
+
+
+ switch (pkt->service) {
+ case YAHOO_SERVICE_CONFINVITE:
+ case YAHOO_SERVICE_CONFADDINVITE:
+ if (pkt->status == 2)
+ ;
+ else {
+ GHashTable *components;
+
+ components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
g_free);
+ g_hash_table_replace(components, g_strdup("room"), g_strdup(room));
+ if (msg)
+ g_hash_table_replace(components, g_strdup("topic"), g_strdup(msg));
+ g_hash_table_replace(components, g_strdup("type"),
g_strdup("Conference"));
+ if (members) {
+ char *m = g_malloc0(1);
+ g_list_foreach(members, concatlist, &m);
+ g_hash_table_replace(components, g_strdup("members"), g_strdup(m));
+ g_free(m);
+ }
+ serv_got_chat_invite(gc, room, who, msg, components);
+
+ }
+
+ break;
+ case YAHOO_SERVICE_CONFDECLINE:
+ if (who)
+ ; /* do something here to let the user know */
+ break;
+ case YAHOO_SERVICE_CONFLOGON:
+ if (who) {
+ struct gaim_conversation *c = yahoo_find_chat(gc, room);
+ gaim_chat_add_user(GAIM_CHAT(c), who, NULL);
+ }
+ break;
+ case YAHOO_SERVICE_CONFLOGOFF:
+ if (who) {
+ struct gaim_conversation *c = yahoo_find_chat(gc, room);
+ gaim_chat_remove_user(GAIM_CHAT(c), who, NULL);
+ }
+ break;
+ case YAHOO_SERVICE_CONFMSG:
+ if (who) {
+ /* utf8 is set if the message is utf8, but um, what is it if its not
utf8? */
+ struct gaim_conversation *c = yahoo_find_chat(gc, room);
+
+ msg = ansi_to_html(msg);
+ serv_got_chat_in(gc, gaim_chat_get_id(GAIM_CHAT(c)), who, 0, msg,
time(NULL));
+ g_free(msg);
+ }
+ break;
+ }
+
+ if (members && free_members) {
+ for (dl = members; dl; dl = dl->next)
+ g_free(dl->data);
+ g_list_free(members);
+ }
+
+}
+
+
+static void yahoo_process_chat(struct gaim_connection *gc, struct
yahoo_packet *pkt)
+{
+ struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data;
+ char *me = NULL;
+ char *msg = NULL;
+ char *who = NULL;
+ char *room = NULL;
+ char *topic = NULL;
+ GList *members = NULL;
+ char *currentmember = NULL;
+ int msgtype = 1;
+ int utf8 = 0;
+ int firstjoin = 0;
+ int membercount = 0;
+ GSList *l;
+ GList *dl;
+
+
+ for (l = pkt->hash; l; l = l->next) {
+ struct yahoo_pair *pair = l->data;
+
+ if (pair->key == 104) {
+ /* Room name */
+ room = pair->value;
+ }
+
+ if (pair->key == 105) {
+ /* Room topic */
+ topic = pair->value;
+ }
+
+ if (pair->key == 108) {
+ /* Number of members in this packet */
+ membercount = atoi(pair->value);
+ }
+
+ if (pair->key == 109) {
+ /* message sender */
+ who = pair->value;
+
+ if (pkt->service == YAHOO_SERVICE_CHATJOIN) {
+ currentmember = pair->value;
+ members = g_list_append(members, currentmember);
+ }
+ }
+
+ if (pair->key == 118)
+ me = pair->value;
+
+ if (pair->key == 119)
+ who = pair->value;
+#if 0
+ if (pair->key == 110) {
+ /* age */
+ if (pkt->service == YAHOO_SERVICE_CHATJOIN)
+ currentmember->age = atoi(pair->value);
+ }
+
+ if (pair->key == 113) {
+ /* attribs */
+ if (pkt->service == YAHOO_SERVICE_CHATJOIN)
+ currentmember->attribs = atoi(pair->value);
+ }
+
+ if (pair->key == 141) {
+ /* alias */
+ if (pkt->service == YAHOO_SERVICE_CHATJOIN)
+ currentmember->alias = strdup(pair->value);
+ }
+
+ if (pair->key == 142) {
+ /* location */
+ if (pkt->service == YAHOO_SERVICE_CHATJOIN)
+ currentmember->location = strdup(pair->value);
+ }
+#endif
+
+ if (pair->key == 130) {
+ /* first join */
+ firstjoin = 1;
+ }
+
+ if (pair->key == 117) {
+ /* message */
+ msg = pair->value;
+ }
+
+ if (pair->key == 124) {
+ /* Message type */
+ msgtype = atoi(pair->value);
+ }
+ }
+
+ if (!room) {
+ return;
+ }
+
+ switch (pkt->service) {
+ case YAHOO_SERVICE_CHATADDINVITE:
+ if (room && who) {
+ GHashTable *components;
+
+ components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
g_free);
+ g_hash_table_replace(components, g_strdup("room"), g_strdup(room));
+ if (topic)
+ g_hash_table_replace(components, g_strdup("topic"), g_strdup(topic));
+ g_hash_table_replace(components, g_strdup("type"), g_strdup("Chat"));
+ serv_got_chat_invite(gc, room, who, topic, components);
+ break;
+ }
+ case YAHOO_SERVICE_CHATJOIN:
+ if (firstjoin && members) {
+ int id = yd->chat_id;
+ struct gaim_conversation *c;
+
+ c = gaim_find_chat(gc, id);
+ if (topic)
+ gaim_chat_set_topic(GAIM_CHAT(c), who, topic);
+ for (dl = members; dl; dl = dl->next) {
+ currentmember = dl->data;
+ if (strcmp(currentmember, gc->displayname))
+ gaim_chat_add_user(GAIM_CHAT(c), currentmember, NULL);
+ }
+
+ } else if (who) {
+ /* this should only ever have one, but just in case
+ actually in my experence it has more than one */
+ struct gaim_conversation *c = yahoo_find_chat(gc, room);
+ for (dl = members; dl; dl = dl->next) {
+ currentmember = members->data;
+ if (strcmp(currentmember, gc->displayname))
+ gaim_chat_add_user(GAIM_CHAT(c), currentmember, NULL);
+ }
+ }
+ break;
+ case YAHOO_SERVICE_CHATEXIT:
+ if (who) {
+ struct gaim_conversation *c = yahoo_find_chat(gc, room);
+ gaim_chat_remove_user(GAIM_CHAT(c), who, NULL);
+ }
+ break;
+ case YAHOO_SERVICE_COMMENT:
+ if(who) {
+ struct gaim_conversation *c = yahoo_find_chat(gc, room);
+ msg = ansi_to_html(msg);
+ serv_got_chat_in(gc, gaim_chat_get_id(GAIM_CHAT(c)), who, 0, msg,
time(NULL));
+ g_free(msg);
+ /* FIXME: handle msgtype to do action and think */
+ }
+ break;
+ }
+
+ if (members)
+ g_list_free(members);
+}
+
+
+
+static void yahoo_conf_leave(struct gaim_connection *gc, int id)
+{
+ struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data;;
+ struct yahoo_packet *pkt;
+ GList *who;
+ struct gaim_conversation *c;
+
+ c = gaim_find_chat(gc, id);
+ if (!c)
+ return;
+
+ who = GAIM_CHAT(c)->in_room;
+
+ pkt = yahoo_packet_new(YAHOO_SERVICE_CONFLOGOFF,
YAHOO_STATUS_AVAILABLE, 0);
+
+ yahoo_packet_hash(pkt, 1, (gc->displayname));
+ for(; who; who = who->next) {
+ yahoo_packet_hash(pkt, 3, (char *)who->data);
+ }
+ yahoo_packet_hash(pkt, 57, c->name);
+
+ yahoo_send_packet(yd, pkt);
+
+ yahoo_packet_free(pkt);
+
+ serv_got_chat_left(gc, id);
+}
+
+static void yahoo_chat_leave(struct gaim_connection *gc, int id)
+{
+ struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data;
+ struct yahoo_packet *pkt;
+ struct gaim_conversation *c;
+
+ if (g_slist_find(yd->confs, (gpointer) id)) {
+ yahoo_conf_leave(gc, id);
+ return;
+ }
+
+ c = gaim_find_chat(gc, id);
+ if (!c)
+ return;
+
+ pkt = yahoo_packet_new(YAHOO_SERVICE_CHATEXIT, YAHOO_STATUS_AVAILABLE, 0);
+
+ yahoo_packet_hash(pkt, 104, c->name);
+ yahoo_packet_hash(pkt, 109, (gc->displayname));
+ yahoo_packet_hash(pkt, 108, "1");
+ yahoo_packet_hash(pkt, 112, "0"); /* what does this one mean? */
+
+ yahoo_send_packet(yd, pkt);
+
+ yahoo_packet_free(pkt);
+
+ serv_got_chat_left(gc, id);
+}
+
+static int yahoo_conf_send(struct gaim_connection *gc, int id, char *what)
+{
+ struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data;
+ struct yahoo_packet *pkt;
+ GList *who;
+ struct gaim_conversation *c;
+ if(!yd)
+ return -1;
+ c = gaim_find_chat(gc, id);
+ if (!c)
+ return -1;
+ who = GAIM_CHAT(c)->in_room;
+
+ pkt = yahoo_packet_new(YAHOO_SERVICE_CONFMSG, YAHOO_STATUS_AVAILABLE, 0);
+
+ yahoo_packet_hash(pkt, 1, gc->displayname);
+ for(; who; who = who->next) {
+ yahoo_packet_hash(pkt, 53, (char *)who->data);
+ }
+ yahoo_packet_hash(pkt, 57, c->name);
+ yahoo_packet_hash(pkt, 14, what);
+ yahoo_packet_hash(pkt, 97, "1"); /* utf-8 */
+
+ yahoo_send_packet(yd, pkt);
+
+ yahoo_packet_free(pkt);
+ return 0;
+}
+
+static int yahoo_chat_send(struct gaim_connection *gc, int id, char *what)
+{
+ struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data;
+ struct yahoo_packet *pkt;
+ struct gaim_conversation *c;
+
+ if (g_slist_find(yd->confs, (gpointer) id)) {
+ return yahoo_conf_send(gc, id, what);
+ }
+
+ if (!yd)
+ return -1;
+ c = gaim_find_chat(gc, id);
+ if (!c || !c->name)
+ return -1;
+
+ pkt = yahoo_packet_new(YAHOO_SERVICE_COMMENT, YAHOO_STATUS_AVAILABLE, 0);
+
+ yahoo_packet_hash(pkt, 1, gc->displayname);
+ yahoo_packet_hash(pkt, 104, c->name);
+ yahoo_packet_hash(pkt, 117, what);
+ yahoo_packet_hash(pkt, 124, "1");
+
+ yahoo_send_packet(yd, pkt);
+
+ yahoo_packet_free(pkt);
+
+ serv_got_chat_in(gc, gaim_chat_get_id(GAIM_CHAT(c)), gc->displayname,
0, what, time(NULL));
+ return 0;
+}
+
+static GList *yahoo_chat_info(struct gaim_connection *gc)
+{
+ GList *m = NULL;
+ struct proto_chat_entry *pce;
+
+ pce = g_new0(struct proto_chat_entry, 1);
+ pce->label = _("Room:");
+ pce->identifier = "room";
+ m = g_list_append(m, pce);
+
+ pce = g_new0(struct proto_chat_entry, 1);
+ pce->label = _("Topic:");
+ pce->identifier = "topic";
+ m = g_list_append(m, pce);
+
+ pce = g_new0(struct proto_chat_entry, 1);
+ pce->label = _("Conference or Chat?");
+ pce->identifier = "type";
+ pce->def = "Conference";
+ m = g_list_append(m, pce);
+
+ return m;
+}
+
+static void yahoo_join_conf(struct gaim_connection *gc, GHashTable *data)
+{
+ struct yahoo_data *yd;
+ struct yahoo_packet *pkt;
+ int id = chat_id_counter++;
+ struct gaim_conversation *c;
+ char *room = NULL;
+ char *topic = NULL;
+ char *members = NULL;
+ char **memarr = NULL;
+ int i;
+
+ yd = (struct yahoo_data *) gc->proto_data;
+ if(!yd)
+ return;
+
+ room = g_hash_table_lookup(data, "room");
+ if (!room)
+ return;
+ topic = g_hash_table_lookup(data, "topic");
+ if (!topic)
+ topic = "";
+ members = g_hash_table_lookup(data, "members");
+ if (members)
+ memarr = g_strsplit(members, "\n", 0);
+
+
+ yd->confs = g_slist_prepend(yd->confs, (gpointer) id);
+ serv_got_joined_chat(gc, id, room);
+ c = gaim_find_chat(gc, id);
+ gaim_chat_set_topic(GAIM_CHAT(c), gc->displayname, topic);
+
+
+ pkt = yahoo_packet_new(YAHOO_SERVICE_CONFLOGON,
YAHOO_STATUS_AVAILABLE, 0);
+
+ yahoo_packet_hash(pkt, 1, gc->displayname);
+ yahoo_packet_hash(pkt, 3, gc->displayname);
+ yahoo_packet_hash(pkt, 57, room);
+ if (memarr) {
+ for(i = 0 ; memarr[i]; i++) {
+ if (!strcmp(memarr[i], gc->displayname) || !strcmp(memarr[i], ""))
+ continue;
+ yahoo_packet_hash(pkt, 3, memarr[i]);
+ gaim_chat_add_user(GAIM_CHAT(c), memarr[i], NULL);
+ }
+ }
+ yahoo_send_packet(yd, pkt);
+
+ yahoo_packet_free(pkt);
+
+ if (memarr) {
+ g_strfreev(memarr);
+ }
+}
+
+static void yahoo_chatjoin(struct gaim_connection *gc, struct
yahoo_data *yd, char *room, char *topic)
+{
+ struct yahoo_packet *pkt;
+ int id;
+ struct gaim_conversation *c;
+
+ if (!topic)
+ topic = "";
+
+ if (yd->chat_id)
+ yahoo_chat_leave(gc, yd->chat_id);
+
+ id = chat_id_counter++;
+ yd->chat_id = id;
+ serv_got_joined_chat(gc, id, room);
+ c = gaim_find_chat(gc, id);
+ gaim_chat_set_topic(GAIM_CHAT(c), gc->displayname, topic);
+ gaim_chat_add_user(GAIM_CHAT(c), gc->displayname, NULL);
+
+ pkt = yahoo_packet_new(YAHOO_SERVICE_CHATJOIN, YAHOO_STATUS_AVAILABLE, 0);
+
+ yahoo_packet_hash(pkt, 62, "2");
+ yahoo_packet_hash(pkt, 104, room);
+ yahoo_packet_hash(pkt, 129, "0");
+
+ yahoo_send_packet(yd, pkt);
+
+ yahoo_packet_free(pkt);
+}
+
+static void yahoo_join_chat(struct gaim_connection *gc, GHashTable *data)
+{
+ struct yahoo_data *yd;
+ char *room = NULL;
+ char *topic = NULL;
+
+ if (!strcmp(g_hash_table_lookup(data, "type"), "Conference")) {
+ yahoo_join_conf(gc, data);
+ return;
+ }
+
+
+
+ yd = (struct yahoo_data *) gc->proto_data;
+ if(!yd)
+ return;
+
+ room = g_hash_table_lookup(data, "room");
+ if (!room)
+ return; /* FIXME: display error */
+
+ topic = g_hash_table_lookup(data, "topic");
+ if (!topic)
+ topic = "";
+
+ yahoo_chatjoin(gc, yd, room, topic);
+}
+
+static void yahoo_conf_invite(struct gaim_connection *gc, int id, const
char *msg, const char *name)
+{
+ struct yahoo_data *yd;
+ struct yahoo_packet *pkt;
+ struct gaim_conversation *c;
+ GList *members;
+
+ yd = (struct yahoo_data *) gc->proto_data;
+ if(!yd)
+ return;
+
+ c = gaim_find_chat(gc, id);
+ members = GAIM_CHAT(c)->in_room;
+
+ pkt = yahoo_packet_new(YAHOO_SERVICE_CONFADDINVITE,
YAHOO_STATUS_AVAILABLE, 0);
+
+ yahoo_packet_hash(pkt, 1, gc->displayname);
+ yahoo_packet_hash(pkt, 51, name);
+ yahoo_packet_hash(pkt, 57, c->name);
+ if (!msg)
+ msg = "";
+ yahoo_packet_hash(pkt, 58, msg);
+ yahoo_packet_hash(pkt, 13, "0");
+ for(; members; members = members->next) {
+ if (!strcmp(members->data, gc->displayname))
+ continue;
+ yahoo_packet_hash(pkt, 52, (char *)members->data);
+ yahoo_packet_hash(pkt, 53, (char *)members->data);
+ }
+ yahoo_send_packet(yd, pkt);
+
+ yahoo_packet_free(pkt);
+}
+
+static void yahoo_chat_invite(struct gaim_connection *gc, int id, const
char *msg, const char *name)
+{
+ struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data;
+ struct yahoo_packet *pkt;
+ struct gaim_conversation *c;
+
+ if (g_slist_find(yd->confs, (gpointer) id)) {
+ yahoo_conf_invite(gc, id, msg, name);
+ return;
+ }
+
+ c = gaim_find_chat(gc, id);
+ if (!c || !c->name)
+ return;
+
+ pkt = yahoo_packet_new(YAHOO_SERVICE_CHATADDINVITE,
YAHOO_STATUS_AVAILABLE, 0);
+
+ yahoo_packet_hash(pkt, 1, gc->displayname);
+ yahoo_packet_hash(pkt, 118, name);
+ yahoo_packet_hash(pkt, 104, c->name);
+ yahoo_packet_hash(pkt, 117, (msg?msg:""));
+ yahoo_packet_hash(pkt, 129, "0");
+
+ yahoo_send_packet(yd, pkt);
+ yahoo_packet_free(pkt);
+}
+
+
+
static GaimPlugin *my_protocol = NULL;
#if 0
@@ -1445,6 +2223,8 @@
my_protocol = ret;
}
+
+
#ifndef STATIC
G_MODULE_EXPORT void gaim_prpl_init(struct prpl *prpl)
@@ -1459,7 +2239,7 @@
static GaimPluginProtocolInfo prpl_info =
{
GAIM_PROTO_YAHOO,
- OPT_PROTO_MAIL_CHECK | OPT_PROTO_USE_POINTSIZE,
+ OPT_PROTO_MAIL_CHECK | OPT_PROTO_USE_POINTSIZE | OPT_PROTO_CHAT_TOPIC,
NULL,
NULL,
yahoo_list_icon,
@@ -1469,7 +2249,7 @@
yahoo_away_states,
yahoo_actions,
yahoo_buddy_menu,
- NULL,
+ yahoo_chat_info, /* chat_info */
yahoo_login,
yahoo_close,
yahoo_send_im,
@@ -1493,11 +2273,11 @@
NULL,
NULL,
NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
+ yahoo_join_chat, /* join_chat */
+ yahoo_chat_invite, /* chat_invite */
+ yahoo_chat_leave, /* chat_leave */
+ NULL, /* chat_whisper */
+ yahoo_chat_send, /* chat_send */
yahoo_keepalive,
NULL,
NULL,
|