Mercurial > pidgin
view src/protocols/oscar/chatnav.c @ 12645:fc28451f5d96
[gaim-migrate @ 14983]
SF Patch #1314512 from Sadrul (who has a patch for everything)
"This patch introduces a flag for protocol plugins that
support offline messages (like Y!M and ICQ). This was
encouraged by the following conversation:
<sadrul> should offline buddies be listed/enabled in
the send-to menu?
<rekkanoryo> i would think only for protocols that
support offline messaging, if it's indicated that the
buddy is offline
-- <snip> --
<Bleeter> sadrul: personally, I'd like to see a
'supports offline' flag of some description
<Bleeter> one could then redirect (via plugins) through
email or alternative methods
<Bleeter> just a thought
<Paco-Paco> yeah, that sounds like a reasonble thing to have
This patch uses this flag to disable the buddies in the
send-to menu who are offline and the protocol doesn't
support offline messages."
I made this make the label insensitive instead of the whole menuitem. This
should address SimGuy's concerns about inconsistency (i.e. you could create a
conversation with someone via the buddy list that you couldn't create via the
Send To menu). I also hacked up some voodoo to show the label as sensitive when
moused-over, as that looks better (given the label-insensitive thing is itself a
hack). I think this works quite well.
BUG NOTE:
This makes more obvious an existing bug. The Send To menu isn't updated when
buddies sign on or off or change status (at least under some circumstances).
We need to fix that anyway, so I'm not going to let it hold up this commit.
Switching tabs will clear it up. I'm thinking we just might want to build the
contents of that menu when it is selected. That would save us a mess of
inefficient signal callbacks that update the Send To menus in open windows all
the time.
AIM NOTE:
This assumes that AIM can't offline message. That's not strictly true. You can
message invisible users on AIM. However, by design, we can't tell when a user
is invisible without resorting to dirty hackery. In practice, this isn't a
problem, as you can still select the AIM user from the menu. And really, how
often will you be choosing the Invisible contact, rather than the user going
Invisible in the middle of a conversation or IMing you while they're Invisible?
JABBER NOTE:
This assumes that Jabber can always offline message. This isn't strictly true.
Sadrul said:
I have updated Jabber according to this link which seems to
talk about how to determine the existence offline-message
support in a server:
http://www.jabber.org/jeps/jep-0013.html#discover
However, jabber.org doesn't seem to send the required
info. So I am not sure about it.
He later said:
I talked to Nathan and he said offline message support is
mostly assumed for most jabber servers. GTalk doesn't yet
support it, but they are working on it. So I have made
jabber to always return TRUE.
If there is truly no way to detect offline messaging capability, then this is
an acceptable solution. We could special case Google Talk because of its
popularity, and remove that later. It's probably not worth it though.
MSN NOTE:
This assumes that MSN can never offline message. That's effectively true, but
to be technically correct, MSN can offline message if there's already a
switchboard conversation open with a user. We could write an offline_message
function in the MSN prpl to detect that, but it'd be of limited usefulness,
especially given that under most circumstances (where this might matter), the
switchboard connection will be closed almost immediately.
CVS NOTE:
I'm writing to share a tragic little story.
I have a PC that I use for Gaim development. One day, I was writing a commit
message on it, when all of a suddent it went berserk. The screen started
flashing, and the whole commit message just disappeared. All of it. And it was
a good commit message! I had to cram and rewrite it really quickly. Needless to
say, my rushed commit message wasn't nearly as good, and I blame the PC for that.
Seriously, though, what kind of version control system loses your commit
message on a broken connection to the server? Stupid!
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Fri, 23 Dec 2005 19:26:04 +0000 |
parents | 59207955adc2 |
children |
line wrap: on
line source
/* * Family 0x000d - Handle ChatNav. * * The ChatNav(igation) service does various things to keep chat * alive. It provides room information, room searching and creating, * as well as giving users the right ("permission") to use chat. * */ #define FAIM_INTERNAL #include <aim.h> /* * Subtype 0x0002 * * conn must be a chatnav connection! * */ faim_export int aim_chatnav_reqrights(aim_session_t *sess, aim_conn_t *conn) { return aim_genericreq_n_snacid(sess, conn, 0x000d, 0x0002); } /* * Subtype 0x0008 */ faim_export int aim_chatnav_createroom(aim_session_t *sess, aim_conn_t *conn, const char *name, fu16_t exchange) { static const char ck[] = {"create"}; static const char lang[] = {"en"}; static const char charset[] = {"us-ascii"}; aim_frame_t *fr; aim_snacid_t snacid; aim_tlvlist_t *tl = NULL; if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152))) return -ENOMEM; snacid = aim_cachesnac(sess, 0x000d, 0x0008, 0x0000, NULL, 0); aim_putsnac(&fr->data, 0x000d, 0x0008, 0x0000, snacid); /* exchange */ aimbs_put16(&fr->data, exchange); /* * This looks to be a big hack. You'll note that this entire * SNAC is just a room info structure, but the hard room name, * here, is set to "create". * * Either this goes on the "list of questions concerning * why-the-hell-did-you-do-that", or this value is completely * ignored. Without experimental evidence, but a good knowledge of * AOL style, I'm going to guess that it is the latter, and that * the value of the room name in create requests is ignored. */ aimbs_put8(&fr->data, strlen(ck)); aimbs_putstr(&fr->data, ck); /* * instance * * Setting this to 0xffff apparently assigns the last instance. * */ aimbs_put16(&fr->data, 0xffff); /* detail level */ aimbs_put8(&fr->data, 0x01); aim_tlvlist_add_str(&tl, 0x00d3, name); aim_tlvlist_add_str(&tl, 0x00d6, charset); aim_tlvlist_add_str(&tl, 0x00d7, lang); /* tlvcount */ aimbs_put16(&fr->data, aim_tlvlist_count(&tl)); aim_tlvlist_write(&fr->data, &tl); aim_tlvlist_free(&tl); aim_tx_enqueue(sess, fr); return 0; } static int parseinfo_perms(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs, aim_snac_t *snac2) { aim_rxcallback_t userfunc; int ret = 0; struct aim_chat_exchangeinfo *exchanges = NULL; int curexchange; aim_tlv_t *exchangetlv; fu8_t maxrooms = 0; aim_tlvlist_t *tlvlist, *innerlist; tlvlist = aim_tlvlist_read(bs); /* * Type 0x0002: Maximum concurrent rooms. */ if (aim_tlv_gettlv(tlvlist, 0x0002, 1)) maxrooms = aim_tlv_get8(tlvlist, 0x0002, 1); /* * Type 0x0003: Exchange information * * There can be any number of these, each one * representing another exchange. * */ for (curexchange = 0; ((exchangetlv = aim_tlv_gettlv(tlvlist, 0x0003, curexchange+1))); ) { aim_bstream_t tbs; aim_bstream_init(&tbs, exchangetlv->value, exchangetlv->length); curexchange++; exchanges = realloc(exchanges, curexchange * sizeof(struct aim_chat_exchangeinfo)); /* exchange number */ exchanges[curexchange-1].number = aimbs_get16(&tbs); innerlist = aim_tlvlist_read(&tbs); #if 0 /* * Type 0x000a: Unknown. * * Usually three bytes: 0x0114 (exchange 1) or 0x010f (others). * */ if (aim_tlv_gettlv(innerlist, 0x000a, 1)) { /* Unhandled */ } /* * Type 0x000d: Unknown. */ if (aim_tlv_gettlv(innerlist, 0x000d, 1)) { /* Unhandled */ } /* * Type 0x0004: Unknown */ if (aim_tlv_gettlv(innerlist, 0x0004, 1)) { /* Unhandled */ } #endif /* * Type 0x0002: Unknown */ if (aim_tlv_gettlv(innerlist, 0x0002, 1)) { fu16_t classperms; classperms = aim_tlv_get16(innerlist, 0x0002, 1); gaim_debug_misc("oscar", "faim: class permissions %x\n", classperms); } /* * Type 0x00c9: Flags * * 1 Evilable * 2 Nav Only * 4 Instancing Allowed * 8 Occupant Peek Allowed * */ if (aim_tlv_gettlv(innerlist, 0x00c9, 1)) exchanges[curexchange-1].flags = aim_tlv_get16(innerlist, 0x00c9, 1); #if 0 /* * Type 0x00ca: Creation Date */ if (aim_tlv_gettlv(innerlist, 0x00ca, 1)) { /* Unhandled */ } /* * Type 0x00d0: Mandatory Channels? */ if (aim_tlv_gettlv(innerlist, 0x00d0, 1)) { /* Unhandled */ } /* * Type 0x00d1: Maximum Message length */ if (aim_tlv_gettlv(innerlist, 0x00d1, 1)) { /* Unhandled */ } /* * Type 0x00d2: Maximum Occupancy? */ if (aim_tlv_gettlv(innerlist, 0x00d2, 1)) { /* Unhandled */ } #endif /* * Type 0x00d3: Exchange Description */ if (aim_tlv_gettlv(innerlist, 0x00d3, 1)) exchanges[curexchange-1].name = aim_tlv_getstr(innerlist, 0x00d3, 1); else exchanges[curexchange-1].name = NULL; #if 0 /* * Type 0x00d4: Exchange Description URL */ if (aim_tlv_gettlv(innerlist, 0x00d4, 1)) { /* Unhandled */ } #endif /* * Type 0x00d5: Creation Permissions * * 0 Creation not allowed * 1 Room creation allowed * 2 Exchange creation allowed * */ if (aim_tlv_gettlv(innerlist, 0x00d5, 1)) { fu8_t createperms; createperms = aim_tlv_get8(innerlist, 0x00d5, 1); } /* * Type 0x00d6: Character Set (First Time) */ if (aim_tlv_gettlv(innerlist, 0x00d6, 1)) exchanges[curexchange-1].charset1 = aim_tlv_getstr(innerlist, 0x00d6, 1); else exchanges[curexchange-1].charset1 = NULL; /* * Type 0x00d7: Language (First Time) */ if (aim_tlv_gettlv(innerlist, 0x00d7, 1)) exchanges[curexchange-1].lang1 = aim_tlv_getstr(innerlist, 0x00d7, 1); else exchanges[curexchange-1].lang1 = NULL; /* * Type 0x00d8: Character Set (Second Time) */ if (aim_tlv_gettlv(innerlist, 0x00d8, 1)) exchanges[curexchange-1].charset2 = aim_tlv_getstr(innerlist, 0x00d8, 1); else exchanges[curexchange-1].charset2 = NULL; /* * Type 0x00d9: Language (Second Time) */ if (aim_tlv_gettlv(innerlist, 0x00d9, 1)) exchanges[curexchange-1].lang2 = aim_tlv_getstr(innerlist, 0x00d9, 1); else exchanges[curexchange-1].lang2 = NULL; #if 0 /* * Type 0x00da: Unknown */ if (aim_tlv_gettlv(innerlist, 0x00da, 1)) { /* Unhandled */ } #endif aim_tlvlist_free(&innerlist); } /* * Call client. */ if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) ret = userfunc(sess, rx, snac2->type, maxrooms, curexchange, exchanges); for (curexchange--; curexchange >= 0; curexchange--) { free(exchanges[curexchange].name); free(exchanges[curexchange].charset1); free(exchanges[curexchange].lang1); free(exchanges[curexchange].charset2); free(exchanges[curexchange].lang2); } free(exchanges); aim_tlvlist_free(&tlvlist); return ret; } static int parseinfo_create(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs, aim_snac_t *snac2) { aim_rxcallback_t userfunc; aim_tlvlist_t *tlvlist, *innerlist; char *ck = NULL, *fqcn = NULL, *name = NULL; fu16_t exchange = 0, instance = 0, unknown = 0, flags = 0, maxmsglen = 0, maxoccupancy = 0; fu32_t createtime = 0; fu8_t createperms = 0, detaillevel; int cklen; aim_tlv_t *bigblock; int ret = 0; aim_bstream_t bbbs; tlvlist = aim_tlvlist_read(bs); if (!(bigblock = aim_tlv_gettlv(tlvlist, 0x0004, 1))) { gaim_debug_misc("oscar", "no bigblock in top tlv in create room response\n"); aim_tlvlist_free(&tlvlist); return 0; } aim_bstream_init(&bbbs, bigblock->value, bigblock->length); exchange = aimbs_get16(&bbbs); cklen = aimbs_get8(&bbbs); ck = aimbs_getstr(&bbbs, cklen); instance = aimbs_get16(&bbbs); detaillevel = aimbs_get8(&bbbs); if (detaillevel != 0x02) { gaim_debug_misc("oscar", "unknown detaillevel in create room response (0x%02x)\n", detaillevel); aim_tlvlist_free(&tlvlist); free(ck); return 0; } unknown = aimbs_get16(&bbbs); innerlist = aim_tlvlist_read(&bbbs); if (aim_tlv_gettlv(innerlist, 0x006a, 1)) fqcn = aim_tlv_getstr(innerlist, 0x006a, 1); if (aim_tlv_gettlv(innerlist, 0x00c9, 1)) flags = aim_tlv_get16(innerlist, 0x00c9, 1); if (aim_tlv_gettlv(innerlist, 0x00ca, 1)) createtime = aim_tlv_get32(innerlist, 0x00ca, 1); if (aim_tlv_gettlv(innerlist, 0x00d1, 1)) maxmsglen = aim_tlv_get16(innerlist, 0x00d1, 1); if (aim_tlv_gettlv(innerlist, 0x00d2, 1)) maxoccupancy = aim_tlv_get16(innerlist, 0x00d2, 1); if (aim_tlv_gettlv(innerlist, 0x00d3, 1)) name = aim_tlv_getstr(innerlist, 0x00d3, 1); if (aim_tlv_gettlv(innerlist, 0x00d5, 1)) createperms = aim_tlv_get8(innerlist, 0x00d5, 1); if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) { ret = userfunc(sess, rx, snac2->type, fqcn, instance, exchange, flags, createtime, maxmsglen, maxoccupancy, createperms, unknown, name, ck); } free(ck); free(name); free(fqcn); aim_tlvlist_free(&innerlist); aim_tlvlist_free(&tlvlist); return ret; } /* * Subtype 0x0009 * * Since multiple things can trigger this callback, we must lookup the * snacid to determine the original snac subtype that was called. * * XXX This isn't really how this works. But this is: Every d/9 response * has a 16bit value at the beginning. That matches to: * Short Desc = 1 * Full Desc = 2 * Instance Info = 4 * Nav Short Desc = 8 * Nav Instance Info = 16 * And then everything is really asynchronous. There is no specific * attachment of a response to a create room request, for example. Creating * the room yields no different a response than requesting the room's info. * */ static int parseinfo(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) { aim_snac_t *snac2; int ret = 0; if (!(snac2 = aim_remsnac(sess, snac->id))) { gaim_debug_misc("oscar", "faim: chatnav_parse_info: received response to unknown request! (%08lx)\n", snac->id); return 0; } if (snac2->family != 0x000d) { gaim_debug_misc("oscar", "faim: chatnav_parse_info: recieved response that maps to corrupt request! (fam=%04x)\n", snac2->family); return 0; } /* * We now know what the original SNAC subtype was. */ if (snac2->type == 0x0002) /* request chat rights */ ret = parseinfo_perms(sess, mod, rx, snac, bs, snac2); else if (snac2->type == 0x0003) /* request exchange info */ gaim_debug_misc("oscar", "chatnav_parse_info: resposne to exchange info\n"); else if (snac2->type == 0x0004) /* request room info */ gaim_debug_misc("oscar", "chatnav_parse_info: response to room info\n"); else if (snac2->type == 0x0005) /* request more room info */ gaim_debug_misc("oscar", "chatnav_parse_info: response to more room info\n"); else if (snac2->type == 0x0006) /* request occupant list */ gaim_debug_misc("oscar", "chatnav_parse_info: response to occupant info\n"); else if (snac2->type == 0x0007) /* search for a room */ gaim_debug_misc("oscar", "chatnav_parse_info: search results\n"); else if (snac2->type == 0x0008) /* create room */ ret = parseinfo_create(sess, mod, rx, snac, bs, snac2); else gaim_debug_misc("oscar", "chatnav_parse_info: unknown request subtype (%04x)\n", snac2->type); if (snac2) free(snac2->data); free(snac2); return ret; } static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) { if (snac->subtype == 0x0009) return parseinfo(sess, mod, rx, snac, bs); return 0; } faim_internal int chatnav_modfirst(aim_session_t *sess, aim_module_t *mod) { mod->family = 0x000d; mod->version = 0x0001; mod->toolid = 0x0010; mod->toolversion = 0x0629; mod->flags = 0; strncpy(mod->name, "chatnav", sizeof(mod->name)); mod->snachandler = snachandler; return 0; }