示例#1
0
int
aim_chat_readroominfo(ByteStream *bs, struct aim_chat_roominfo *outinfo)
{
	if (!bs || !outinfo)
		return 0;

	outinfo->exchange = byte_stream_get16(bs);
	outinfo->namelen = byte_stream_get8(bs);
	outinfo->name = (char *)byte_stream_getraw(bs, outinfo->namelen);
	outinfo->instance = byte_stream_get16(bs);

	return 0;
}
示例#2
0
/*
 * Subtype 0x0007
 *
 * Middle handler for 0017/0007 SNACs.  Contains the auth key prefixed
 * by only its length in a two byte word.
 *
 * Calls the client, which should then use the value to call aim_send_login.
 *
 */
static int
keyparse(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
{
	int keylen, ret = 1;
	aim_rxcallback_t userfunc;
	char *keystr;
	GSList *tlvlist;
	gboolean truncate_pass;

	keylen = byte_stream_get16(bs);
	keystr = byte_stream_getstr(bs, keylen);
	tlvlist = aim_tlvlist_read(bs);

	/*
	 * If the truncate_pass TLV exists then we should truncate the
	 * user's password to 8 characters.  This flag is sent to us
	 * when logging in with an AOL user's username.
	 */
	truncate_pass = aim_tlv_gettlv(tlvlist, 0x0026, 1) != NULL;

	/* XXX - When GiantGrayPanda signed on AIM I got a thing asking me to register
	 * for the netscape network.  This SNAC had a type 0x0058 TLV with length 10.
	 * Data is 0x0007 0004 3e19 ae1e 0006 0004 0000 0005 */

	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
		ret = userfunc(od, conn, frame, keystr, (int)truncate_pass);

	g_free(keystr);
	aim_tlvlist_free(tlvlist);

	return ret;
}
示例#3
0
文件: tlv.c 项目: Mons/libpurple-mini
static GSList *
aim_tlv_read(GSList *list, ByteStream *bs)
{
	guint16 type, length;
	aim_tlv_t *tlv;

	type = byte_stream_get16(bs);
	length = byte_stream_get16(bs);

#if 0
	/*
	 * This code hasn't been needed in years.  It's been commented
	 * out since 2003, at the latest.  It seems likely that it was
	 * just a bug in their server code that has since been fixed.
	 * In any case, here's the orignal comment, kept for historical
	 * purposes:
	 *
	 * Okay, so now AOL has decided that any TLV of
	 * type 0x0013 can only be two bytes, despite
	 * what the actual given length is.  So here
	 * we dump any invalid TLVs of that sort.  Hopefully
	 * there's no special cases to this special case.
	 *   - mid (30jun2000)
	 */
	if ((type == 0x0013) && (length != 0x0002)) {
		length = 0x0002;
		return list;
	}
#endif
	if (length > byte_stream_empty(bs)) {
		aim_tlvlist_free(list);
		return NULL;
	}

	tlv = createtlv(type, length, NULL);
	if (tlv->length > 0) {
		tlv->value = byte_stream_getraw(bs, length);
		if (!tlv->value) {
			freetlv(tlv);
			aim_tlvlist_free(list);
			return NULL;
		}
	}

	return g_slist_prepend(list, tlv);
}
示例#4
0
static void
parse_snac(OscarData *od, FlapConnection *conn, FlapFrame *frame)
{
	aim_module_t *cur;
	aim_modsnac_t snac;

	if (byte_stream_bytes_left(&frame->data) < 10)
		return;

	snac.family = byte_stream_get16(&frame->data);
	snac.subtype = byte_stream_get16(&frame->data);
	snac.flags = byte_stream_get16(&frame->data);
	snac.id = byte_stream_get32(&frame->data);

	/* SNAC flags are apparently uniform across all SNACs, so we handle them here */
	if (snac.flags & 0x0001) {
		/*
		 * This means the SNAC will be followed by another SNAC with
		 * related information.  We don't need to do anything about
		 * this here.
		 */
	}
	if (snac.flags & 0x8000) {
		/*
		 * This packet contains the version of the family that this SNAC is
		 * in.  You get this when your SSI module is version 2 or higher.
		 * For now we have no need for this, but you could always save
		 * it as a part of aim_modnsac_t, or something.  The format is...
		 * 2 byte length of total mini-header (which is 6 bytes), then TLV
		 * of  type 0x0001, length 0x0002, value is the 2 byte version
		 * number
		 */
		byte_stream_advance(&frame->data, byte_stream_get16(&frame->data));
	}

	for (cur = (aim_module_t *)od->modlistv; cur; cur = cur->next) {

		if (!(cur->flags & AIM_MODFLAG_MULTIFAMILY) &&
				(cur->family != snac.family))
			continue;

		if (cur->snachandler(od, conn, cur, frame, &snac, &frame->data))
			return;
	}
}
static int
error(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
{
	int ret = 0;
	aim_snac_t *snac2;
	guint16 error, chatnav_error;
	GSList *tlvlist;

	snac2 = aim_remsnac(od, snac->id);
	if (!snac2) {
		purple_debug_warning("oscar", "chatnav error: received response to unknown request (%08x)\n", snac->id);
		return 0;
	}

	if (snac2->family != SNAC_FAMILY_CHATNAV) {
		purple_debug_warning("oscar", "chatnav error: received response that maps to corrupt request (fam=%04x)\n", snac2->family);
		g_free(snac2->data);
		g_free(snac2);
		return 0;
	}

	/*
	 * We now know what the original SNAC subtype was.
	 */
	if (snac2->type == 0x0008) /* create room */
	{
		error = byte_stream_get16(bs);
		tlvlist = aim_tlvlist_read(bs);
		chatnav_error = aim_tlv_get16(tlvlist, 0x0008, 1);

		purple_debug_warning("oscar",
				"Could not join room, error=0x%04hx, chatnav_error=0x%04hx\n",
				error, chatnav_error);
		purple_notify_error(od->gc, NULL, _("Could not join chat room"),
			chatnav_error == 0x0033 ? _("Invalid chat room name") :
				_("Unknown error"),
			purple_request_cpar_from_connection(od->gc));

		ret = 1;
	}

	g_free(snac2->data);
	g_free(snac2);

	return ret;
}
示例#6
0
/*
 * Subtype 0x0002 - General room information.  Lots of stuff.
 *
 * Values I know are in here but I haven't attached
 * them to any of the 'Unknown's:
 *	- Language (English)
 *
 */
static int
infoupdate(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
{
	aim_rxcallback_t userfunc;
	int ret = 0;
	guint8 detaillevel = 0;
	struct aim_chat_roominfo roominfo;
	GSList *tlvlist;
	guint16 maxmsglen, maxvisiblemsglen;

	aim_chat_readroominfo(bs, &roominfo);

	detaillevel = byte_stream_get8(bs);

	if (detaillevel != 0x02) {
		purple_debug_misc("oscar", "faim: chat_roomupdateinfo: detail level %d not supported\n", detaillevel);
		return 1;
	}

	byte_stream_get16(bs); /* skip the TLV count */

	/*
	 * Everything else are TLVs.
	 */
	tlvlist = aim_tlvlist_read(bs);

	/*
	 * Type 0x00d1: Maximum Message Length
	 */
	maxmsglen = aim_tlv_get16(tlvlist, 0x00d1, 1);

	/*
	 * Type 0x00da: Maximum visible message length
	 */
	maxvisiblemsglen = aim_tlv_get16(tlvlist, 0x00da, 1);

	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) {
		ret = userfunc(od, conn, frame, maxmsglen, maxvisiblemsglen);
	}

	g_free(roominfo.name);

	aim_tlvlist_free(tlvlist);

	return ret;
}
示例#7
0
/*
 * Subtype 0x0001
 */
static int
error(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
{
	int ret = 0;
	aim_rxcallback_t userfunc;
	aim_snac_t *snac2;
	guint16 reason;
	char *sn;
	int was_explicit;

	if (!(snac2 = aim_remsnac(od, snac->id))) {
		purple_debug_misc("oscar", "faim: locate.c, error(): received response from unknown request!\n");
		return 0;
	}

	if ((snac2->family != 0x0002) && (snac2->type != 0x0015)) {
		purple_debug_misc("oscar", "faim: locate.c, error(): received response from invalid request! %d\n", snac2->family);
		return 0;
	}

	if (!(sn = snac2->data)) {
		purple_debug_misc("oscar", "faim: locate.c, error(): received response from request without a screen name!\n");
		return 0;
	}

	reason = byte_stream_get16(bs);

	/*
	 * Remove this screen name from our queue.  If the client requested
	 * this buddy's info explicitly, then notify them that we do not have
	 * info for this buddy.
	 */
	was_explicit = aim_locate_gotuserinfo(od, conn, sn);
	if (was_explicit == TRUE)
		if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
			ret = userfunc(od, conn, frame, reason, sn);

	if (snac2)
		g_free(snac2->data);
	g_free(snac2);

	return ret;
}
示例#8
0
/*
 * Subtype 0x0001
 */
static int
error(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
{
	int ret = 0;
	aim_rxcallback_t userfunc;
	aim_snac_t *snac2;
	guint16 reason;
	char *bn;

	if (!(snac2 = aim_remsnac(od, snac->id))) {
		purple_debug_misc("oscar", "locate error: received response from unknown request!\n");
		return 0;
	}

	if ((snac2->family != SNAC_FAMILY_LOCATE) && (snac2->type != 0x0015)) {
		purple_debug_misc("oscar", "locate error: received response from invalid request! %d\n", snac2->family);
		g_free(snac2->data);
		g_free(snac2);
		return 0;
	}

	if (!(bn = snac2->data)) {
		purple_debug_misc("oscar", "locate error: received response from request without a buddy name!\n");
		g_free(snac2);
		return 0;
	}

	reason = byte_stream_get16(bs);

	/* Notify the user that we do not have info for this buddy */
	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
		ret = userfunc(od, conn, frame, reason, bn);

	if (snac2)
		g_free(snac2->data);
	g_free(snac2);

	return ret;
}
/*
 * Subtype 0x0001
 */
static int
error(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
{
	aim_snac_t *snac2;
	guint16 reason;
	char *bn;

	snac2 = aim_remsnac(od, snac->id);
	if (!snac2) {
		purple_debug_misc("oscar", "locate error: received response from unknown request!\n");
		return 0;
	}

	if ((snac2->family != SNAC_FAMILY_LOCATE) && (snac2->type != 0x0015)) {
		purple_debug_misc("oscar", "locate error: received response from invalid request! %d\n", snac2->family);
		g_free(snac2->data);
		g_free(snac2);
		return 0;
	}

	bn = snac2->data;
	if (!bn) {
		purple_debug_misc("oscar", "locate error: received response from request without a buddy name!\n");
		g_free(snac2);
		return 0;
	}

	reason = byte_stream_get16(bs);

	oscar_user_info_display_error(od, reason, bn);

	g_free(snac2->data);
	g_free(snac2);

	return 1;
}
示例#10
0
/*
 * AIM is fairly regular about providing user info.  This is a generic
 * routine to extract it in its standard form.
 */
int
aim_info_extract(OscarData *od, ByteStream *bs, aim_userinfo_t *outinfo)
{
	int curtlv, tlvcnt;
	guint8 bnlen;

	if (!bs || !outinfo)
		return -EINVAL;

	/* Clear out old data first */
	memset(outinfo, 0x00, sizeof(aim_userinfo_t));

	/*
	 * Username.  Stored as an unterminated string prepended with a
	 * byte containing its length.
	 */
	bnlen = byte_stream_get8(bs);
	outinfo->bn = byte_stream_getstr(bs, bnlen);

	/*
	 * Warning Level.  Stored as an unsigned short.
	 */
	outinfo->warnlevel = byte_stream_get16(bs);

	/*
	 * TLV Count. Unsigned short representing the number of
	 * Type-Length-Value triples that follow.
	 */
	tlvcnt = byte_stream_get16(bs);

	/*
	 * Parse out the Type-Length-Value triples as they're found.
	 */
	for (curtlv = 0; curtlv < tlvcnt; curtlv++) {
		guint16 type, length;
		int endpos;

		type = byte_stream_get16(bs);
		length = byte_stream_get16(bs);

		endpos = byte_stream_curpos(bs) + MIN(length, byte_stream_empty(bs));

		if (type == 0x0001) {
			/*
			 * User flags
			 *
			 * Specified as any of the following ORed together:
			 *      0x0001  Unconfirmed account
			 *      0x0002  Unknown bit 2
			 *      0x0004  AOL Main Service user
			 *      0x0008  Unknown bit 4
			 *      0x0010  Free (AIM) user
			 *      0x0020  Away
			 *      0x0040  ICQ user (AIM bit also set)
			 *      0x0080  Mobile device
			 *      0x0400  Bot (like ActiveBuddy)
			 */
			outinfo->flags = byte_stream_get16(bs);
			outinfo->present |= AIM_USERINFO_PRESENT_FLAGS;

		} else if (type == 0x0002) {
			/*
			 * Account creation time
			 *
			 * The time/date that the user originally registered for
			 * the service, stored in time_t format.
			 *
			 * I'm not sure how this differs from type 5 ("member
			 * since").
			 *
			 * Note: This is the field formerly known as "member
			 * since".  All these years and I finally found out
			 * that I got the name wrong.
			 */
			outinfo->createtime = byte_stream_get32(bs);
			outinfo->present |= AIM_USERINFO_PRESENT_CREATETIME;

		} else if (type == 0x0003) {
			/*
			 * On-Since date
			 *
			 * The time/date that the user started their current
			 * session, stored in time_t format.
			 */
			outinfo->onlinesince = byte_stream_get32(bs);
			outinfo->present |= AIM_USERINFO_PRESENT_ONLINESINCE;

		} else if (type == 0x0004) {
			/*
			 * Idle time
			 *
			 * Number of minutes since the user actively used the
			 * service.
			 *
			 * Note that the client tells the server when to start
			 * counting idle times, so this may or may not be
			 * related to reality.
			 */
			outinfo->idletime = byte_stream_get16(bs);
			outinfo->present |= AIM_USERINFO_PRESENT_IDLE;

		} else if (type == 0x0005) {
			/*
			 * Member since date
			 *
			 * The time/date that the user originally registered for
			 * the service, stored in time_t format.
			 *
			 * This is sometimes sent instead of type 2 ("account
			 * creation time"), particularly in the self-info.
			 * And particularly for ICQ?
			 */
			outinfo->membersince = byte_stream_get32(bs);
			outinfo->present |= AIM_USERINFO_PRESENT_MEMBERSINCE;

		} else if (type == 0x0006) {
			/*
			 * ICQ Online Status
			 *
			 * ICQ's Away/DND/etc "enriched" status. Some decoding
			 * of values done by Scott <*****@*****.**>
			 */
			byte_stream_get16(bs);
			outinfo->icqinfo.status = byte_stream_get16(bs);
			outinfo->present |= AIM_USERINFO_PRESENT_ICQEXTSTATUS;

		} else if (type == 0x0008) {
			/*
			 * Client type, or some such.
			 */

		} else if (type == 0x000a) {
			/*
			 * ICQ User IP Address
			 *
			 * Ahh, the joy of ICQ security.
			 */
			outinfo->icqinfo.ipaddr = byte_stream_get32(bs);
			outinfo->present |= AIM_USERINFO_PRESENT_ICQIPADDR;

		} else if (type == 0x000c) {
			/*
			 * Random crap containing the IP address,
			 * apparently a port number, and some Other Stuff.
			 *
			 * Format is:
			 * 4 bytes - Our IP address, 0xc0 a8 01 2b for 192.168.1.43
			 */
			byte_stream_getrawbuf(bs, outinfo->icqinfo.crap, 0x25);
			outinfo->present |= AIM_USERINFO_PRESENT_ICQDATA;

		} else if (type == 0x000d) {
			/*
			 * OSCAR Capability information
			 */
			outinfo->capabilities |= aim_locate_getcaps(od, bs, length);
			outinfo->present |= AIM_USERINFO_PRESENT_CAPABILITIES;

		} else if (type == 0x000e) {
			/*
			 * AOL capability information
			 */

		} else if ((type == 0x000f) || (type == 0x0010)) {
			/*
			 * Type = 0x000f: Session Length. (AIM)
			 * Type = 0x0010: Session Length. (AOL)
			 *
			 * The duration, in seconds, of the user's current
			 * session.
			 *
			 * Which TLV type this comes in depends on the
			 * service the user is using (AIM or AOL).
			 */
			outinfo->sessionlen = byte_stream_get32(bs);
			outinfo->present |= AIM_USERINFO_PRESENT_SESSIONLEN;

		} else if (type == 0x0014) {
			/*
			 * My instance number.
			 */
			guint8 instance_number;
			instance_number = byte_stream_get8(bs);

		} else if (type == 0x0019) {
			/*
			 * OSCAR short capability information.  A shortened
			 * form of the normal capabilities.
			 */
			outinfo->capabilities |= aim_locate_getcaps_short(od, bs, length);
			outinfo->present |= AIM_USERINFO_PRESENT_CAPABILITIES;

		} else if (type == 0x001a) {
			/*
			 * Type = 0x001a
			 *
			 * AOL short capability information.  A shortened
			 * form of the normal capabilities.
			 */

		} else if (type == 0x001b) {
			/*
			 * Encryption certification MD5 checksum.
			 */

		} else if (type == 0x001d) {
			/*
			 * Buddy icon information and status/available messages.
			 *
			 * This almost seems like the AIM protocol guys gave
			 * the iChat guys a Type, and the iChat guys tried to
			 * cram as much cool shit into it as possible.  Then
			 * the Windows AIM guys were like, "hey, that's
			 * pretty neat, let's copy those prawns."
			 *
			 * In that spirit, this can contain a custom message,
			 * kind of like an away message, but you're not away
			 * (it's called an "available" message).  Or it can
			 * contain information about the buddy icon the user
			 * has stored on the server.
			 */
			guint16 type2;
			guint8 number2, length2;
			int endpos2;

			/*
			 * Continue looping as long as we're able to read type2,
			 * number2, and length2.
			 */
			while (byte_stream_curpos(bs) + 4 <= endpos) {
				type2 = byte_stream_get16(bs);
				number2 = byte_stream_get8(bs);
				length2 = byte_stream_get8(bs);

				endpos2 = byte_stream_curpos(bs) + MIN(length2, byte_stream_empty(bs));

				switch (type2) {
					case 0x0000: { /* This is an official buddy icon? */
						/* This is always 5 bytes of "0x02 01 d2 04 72"? */
					} break;

					case 0x0001: { /* A buddy icon checksum */
						if ((length2 > 0) && ((number2 == 0x00) || (number2 == 0x01))) {
							g_free(outinfo->iconcsum);
							outinfo->iconcsumtype = number2;
							outinfo->iconcsum = byte_stream_getraw(bs, length2);
							outinfo->iconcsumlen = length2;
						}
					} break;

					case 0x0002: { /* A status/available message */
						g_free(outinfo->status);
						g_free(outinfo->status_encoding);
						if (length2 >= 4) {
							outinfo->status_len = byte_stream_get16(bs);
							outinfo->status = byte_stream_getstr(bs, outinfo->status_len);
							if (byte_stream_get16(bs) == 0x0001) { /* We have an encoding */
								byte_stream_get16(bs);
								outinfo->status_encoding = byte_stream_getstr(bs, byte_stream_get16(bs));
							} else {
								/* No explicit encoding, client should use UTF-8 */
								outinfo->status_encoding = NULL;
							}
						} else {
							byte_stream_advance(bs, length2);
							outinfo->status_len = 0;
							outinfo->status = g_strdup("");
							outinfo->status_encoding = NULL;
						}
					} break;

					case 0x0009: { /* An iTunes Music Store link */
						g_free(outinfo->itmsurl);
						g_free(outinfo->itmsurl_encoding);
						if (length2 >= 4) {
							outinfo->itmsurl_len = byte_stream_get16(bs);
							outinfo->itmsurl = byte_stream_getstr(bs, outinfo->itmsurl_len);
							if (byte_stream_get16(bs) == 0x0001) {
								/* We have an encoding */
								byte_stream_get16(bs);
								outinfo->itmsurl_encoding = byte_stream_getstr(bs, byte_stream_get16(bs));
							} else {
								/* No explicit encoding, client should use UTF-8 */
								outinfo->itmsurl_encoding = NULL;
							}
						} else {
							byte_stream_advance(bs, length2);
							outinfo->itmsurl_len = 0;
							outinfo->itmsurl = g_strdup("");
							outinfo->itmsurl_encoding = NULL;
						}
					} break;
				}

				/* Save ourselves. */
				byte_stream_setpos(bs, endpos2);
			}

		} else if (type == 0x001e) {
			/*
			 * Always four bytes, but it doesn't look like an int.
			 */

		} else if (type == 0x001f) {
			/*
			 * Upper bytes of user flags.  Can be any size
			 *
			 * Seen on a buddy using DeadAIM.  Data was 4 bytes:
			 * 0x00 00 00 10
			 */

		} else if (type == 0x0023) {
			/*
			 * Last Buddy Feed update time, in seconds since the epoch.
			 */

		} else if (type == 0x0026) {
			/*
			 * Time that the profile was set, in seconds since the epoch.
			 */

		} else if (type == 0x0027) {
			/*
			 * Time that the away message was set, in seconds since the epoch.
			 */

		} else if (type == 0x002a) {
			/*
			 * Country code based on GeoIP data.
			 */

		} else {

			/*
			 * Reaching here indicates that either AOL has
			 * added yet another TLV for us to deal with,
			 * or the parsing has gone Terribly Wrong.
			 *
			 * Either way, inform the owner and attempt
			 * recovery.
			 *
			 */
#ifdef LOG_UNKNOWN_TLV
			purple_debug_misc("oscar", "userinfo: **warning: unexpected TLV:\n");
			purple_debug_misc("oscar", "userinfo:   bn    =%s\n", outinfo->bn);
			dumptlv(od, type, bs, length);
#endif
		}

		/* Save ourselves. */
		byte_stream_setpos(bs, endpos);
	}

	aim_locate_adduserinfo(od, outinfo);

	return 0;
}
static int
parseinfo_create(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs, aim_snac_t *snac2)
{
	aim_rxcallback_t userfunc;
	GSList *tlvlist, *innerlist;
	char *ck = NULL, *fqcn = NULL, *name = NULL;
	guint16 exchange = 0, instance = 0, unknown = 0, flags = 0, maxmsglen = 0, maxoccupancy = 0;
	guint32 createtime = 0;
	guint8 createperms = 0, detaillevel;
	int cklen;
	aim_tlv_t *bigblock;
	int ret = 0;
	ByteStream bbbs;

	tlvlist = aim_tlvlist_read(bs);

	if (!(bigblock = aim_tlv_gettlv(tlvlist, 0x0004, 1))) {
		purple_debug_misc("oscar", "no bigblock in top tlv in create room response\n");
		aim_tlvlist_free(tlvlist);
		return 0;
	}

	byte_stream_init(&bbbs, bigblock->value, bigblock->length);

	exchange = byte_stream_get16(&bbbs);
	cklen = byte_stream_get8(&bbbs);
	ck = byte_stream_getstr(&bbbs, cklen);
	instance = byte_stream_get16(&bbbs);
	detaillevel = byte_stream_get8(&bbbs);

	if (detaillevel != 0x02) {
		purple_debug_misc("oscar", "unknown detaillevel in create room response (0x%02x)\n", detaillevel);
		aim_tlvlist_free(tlvlist);
		g_free(ck);
		return 0;
	}

	unknown = byte_stream_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(od, snac->family, snac->subtype))) {
		ret = userfunc(od, conn, frame, snac2->type, fqcn, instance, exchange, flags, createtime, maxmsglen, maxoccupancy, createperms, unknown, name, ck);
	}

	g_free(ck);
	g_free(name);
	g_free(fqcn);
	aim_tlvlist_free(innerlist);
	aim_tlvlist_free(tlvlist);

	return ret;
}
static int
parseinfo_perms(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs, aim_snac_t *snac2)
{
	aim_rxcallback_t userfunc;
	int ret = 0;
	struct aim_chat_exchangeinfo *exchanges = NULL;
	int curexchange;
	aim_tlv_t *exchangetlv;
	guint8 maxrooms = 0;
	GSList *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))); ) {
		ByteStream tbs;

		byte_stream_init(&tbs, exchangetlv->value, exchangetlv->length);

		curexchange++;

		exchanges = g_realloc(exchanges, curexchange * sizeof(struct aim_chat_exchangeinfo));

		/* exchange number */
		exchanges[curexchange-1].number = byte_stream_get16(&tbs);
		innerlist = aim_tlvlist_read(&tbs);

		/*
		 * Type 0x0002: Unknown
		 */
		if (aim_tlv_gettlv(innerlist, 0x0002, 1)) {
			guint16 classperms;

			classperms = aim_tlv_get16(innerlist, 0x0002, 1);

			purple_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);

		/*
		 * 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;

		/*
		 * Type 0x00d5: Creation Permissions
		 *
		 * 0  Creation not allowed
		 * 1  Room creation allowed
		 * 2  Exchange creation allowed
		 *
		 */
		if (aim_tlv_gettlv(innerlist, 0x00d5, 1))
			aim_tlv_get8(innerlist, 0x00d5, 1); /* createperms */

		/*
		 * 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;

		aim_tlvlist_free(innerlist);
	}

	/*
	 * Call client.
	 */
	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
		ret = userfunc(od, conn, frame, snac2->type, maxrooms, curexchange, exchanges);

	for (curexchange--; curexchange >= 0; curexchange--) {
		g_free(exchanges[curexchange].name);
		g_free(exchanges[curexchange].charset1);
		g_free(exchanges[curexchange].lang1);
		g_free(exchanges[curexchange].charset2);
		g_free(exchanges[curexchange].lang2);
	}
	g_free(exchanges);
	aim_tlvlist_free(tlvlist);

	return ret;
}
示例#13
0
/**
 * Handle an incoming peer proxy negotiation frame.
 */
static void
peer_proxy_recv_frame(PeerConnection *conn, ProxyFrame *frame)
{
	purple_debug_info("oscar", "Incoming peer proxy frame with "
			"type=0x%04hx, unknown=0x%08x, "
			"flags=0x%04hx, and payload length=%hd\n", frame->type,
			frame->unknown, frame->flags, frame->payload.len);

	if (frame->type == PEER_PROXY_TYPE_CREATED)
	{
		/*
		 * Read in 2 byte port then 4 byte IP and tell the
		 * remote user to connect to it by sending an ICBM.
		 */
		guint16 pin;
		int i;
		guint8 ip[4];

		pin = byte_stream_get16(&frame->payload);
		for (i = 0; i < 4; i++)
			ip[i] = byte_stream_get8(&frame->payload);
		if (conn->type == OSCAR_CAPABILITY_DIRECTIM)
			aim_im_sendch2_odc_requestproxy(conn->od,
					conn->cookie,
					conn->bn, ip, pin, ++conn->lastrequestnumber);
		else if (conn->type == OSCAR_CAPABILITY_SENDFILE)
		{
			aim_im_sendch2_sendfile_requestproxy(conn->od,
					conn->cookie, conn->bn,
					ip, pin, ++conn->lastrequestnumber,
					(const gchar *)conn->xferdata.name,
					conn->xferdata.size, conn->xferdata.totfiles);
		}
	}
	else if (frame->type == PEER_PROXY_TYPE_READY)
	{
		purple_input_remove(conn->watcher_incoming);
		conn->watcher_incoming = 0;

		peer_connection_finalize_connection(conn);
	}
	else if (frame->type == PEER_PROXY_TYPE_ERROR)
	{
		if (byte_stream_empty(&frame->payload) >= 2)
		{
			guint16 error;
			const char *msg;
			error = byte_stream_get16(&frame->payload);
			if (error == 0x000d)
				msg = "bad request";
			else if (error == 0x0010)
				msg = "initial request timed out";
			else if (error == 0x001a)
				msg ="accept period timed out";
			else
				msg = "unknown reason";
			purple_debug_info("oscar", "Proxy negotiation failed with "
					"error 0x%04hx: %s\n", error, msg);
		}
		else
		{
			purple_debug_warning("oscar", "Proxy negotiation failed with "
					"an unknown error\n");
		}
		peer_connection_trynext(conn);
	}
	else
	{
		purple_debug_warning("oscar", "Unknown peer proxy frame type 0x%04hx.\n",
				frame->type);
	}
}
示例#14
0
文件: rxhandlers.c 项目: VoxOx/VoxOx
/*
 * Bleck functions get called when there's no non-bleck functions
 * around to cleanup the mess...
 */
static int bleck(OscarData *od, FlapFrame *frame, ...)
{
	guint16 family, subtype;
	guint16 maxf, maxs;

	static const char *channels[6] = {
		"Invalid (0)",
		"FLAP Version",
		"SNAC",
		"Invalid (3)",
		"Negotiation",
		"FLAP NOP"
	};
	static const int maxchannels = 5;

	/* XXX: this is ugly. and big just for debugging. */
	static const char *literals[14][25] = {
		{"Invalid",
		 NULL
		},
		{"General",
		 "Invalid",
		 "Error",
		 "Client Ready",
		 "Server Ready",
		 "Service Request",
		 "Redirect",
		 "Rate Information Request",
		 "Rate Information",
		 "Rate Information Ack",
		 NULL,
		 "Rate Information Change",
		 "Server Pause",
		 NULL,
		 "Server Resume",
		 "Request Personal User Information",
		 "Personal User Information",
		 "Evil Notification",
		 NULL,
		 "Migration notice",
		 "Message of the Day",
		 "Set Privacy Flags",
		 "Well Known URL",
		 "NOP"
		},
		{"Location",
		 "Invalid",
		 "Error",
		 "Request Rights",
		 "Rights Information",
		 "Set user information",
		 "Request User Information",
		 "User Information",
		 "Watcher Sub Request",
		 "Watcher Notification"
		},
		{"Buddy List Management",
		 "Invalid",
		 "Error",
		 "Request Rights",
		 "Rights Information",
		 "Add Buddy",
		 "Remove Buddy",
		 "Watcher List Query",
		 "Watcher List Response",
		 "Watcher SubRequest",
		 "Watcher Notification",
		 "Reject Notification",
		 "Oncoming Buddy",
		 "Offgoing Buddy"
		},
		{"Messeging",
		 "Invalid",
		 "Error",
		 "Add ICBM Parameter",
		 "Remove ICBM Parameter",
		 "Request Parameter Information",
		 "Parameter Information",
		 "Outgoing Message",
		 "Incoming Message",
		 "Evil Request",
		 "Evil Reply",
		 "Missed Calls",
		 "Message Error",
		 "Host Ack"
		},
		{"Advertisements",
		 "Invalid",
		 "Error",
		 "Request Ad",
		 "Ad Data (GIFs)"
		},
		{"Invitation / Client-to-Client",
		 "Invalid",
		 "Error",
		 "Invite a Friend",
		 "Invitation Ack"
		},
		{"Administrative",
		 "Invalid",
		 "Error",
		 "Information Request",
		 "Information Reply",
		 "Information Change Request",
		 "Information Chat Reply",
		 "Account Confirm Request",
		 "Account Confirm Reply",
		 "Account Delete Request",
		 "Account Delete Reply"
		},
		{"Popups",
		 "Invalid",
		 "Error",
		 "Display Popup"
		},
		{"BOS",
		 "Invalid",
		 "Error",
		 "Request Rights",
		 "Rights Response",
		 "Set group permission mask",
		 "Add permission list entries",
		 "Delete permission list entries",
		 "Add deny list entries",
		 "Delete deny list entries",
		 "Server Error"
		},
		{"User Lookup",
		 "Invalid",
		 "Error",
		 "Search Request",
		 "Search Response"
		},
		{"Stats",
		 "Invalid",
		 "Error",
		 "Set minimum report interval",
		 "Report Events"
		},
		{"Translate",
		 "Invalid",
		 "Error",
		 "Translate Request",
		 "Translate Reply",
		},
		{"Chat Navigation",
		 "Invalid",
		 "Error",
		 "Request rights",
		 "Request Exchange Information",
		 "Request Room Information",
		 "Request Occupant List",
		 "Search for Room",
		 "Outgoing Message",
		 "Incoming Message",
		 "Evil Request",
		 "Evil Reply",
		 "Chat Error",
		}
	};

	maxf = sizeof(literals) / sizeof(literals[0]);
	maxs = sizeof(literals[0]) / sizeof(literals[0][0]);

	if (frame->channel == 0x02) {

		family = byte_stream_get16(&frame->data);
		subtype = byte_stream_get16(&frame->data);

		if ((family < maxf) && (subtype+1 < maxs) && (literals[family][subtype] != NULL))
			gaim_debug_misc("oscar", "bleck: channel %s: null handler for %04x/%04x (%s)\n", channels[frame->channel], family, subtype, literals[family][subtype+1]);
		else
			gaim_debug_misc("oscar", "bleck: channel %s: null handler for %04x/%04x (no literal)\n", channels[frame->channel], family, subtype);
	} else {

		if (frame->channel <= maxchannels)
			gaim_debug_misc("oscar", "bleck: channel %s (0x%02x)\n", channels[frame->channel], frame->channel);
		else
			gaim_debug_misc("oscar", "bleck: unknown channel 0x%02x\n", frame->channel);

	}

	return 1;
}
示例#15
0
/*
 * Subtype 0x0006
 *
 * We could probably include this in the normal ICBM parsing
 * code as channel 0x0003, however, since only the start
 * would be the same, we might as well do it here.
 *
 * General outline of this SNAC:
 *   snac
 *   cookie
 *   channel id
 *   tlvlist
 *     unknown
 *     source user info
 *       name
 *       evility
 *       userinfo tlvs
 *         online time
 *         etc
 *     message metatlv
 *       message tlv
 *         message string
 *       possibly others
 *
 */
static int
incomingim_ch3(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
{
	int ret = 0, i;
	aim_rxcallback_t userfunc;
	aim_userinfo_t userinfo;
	guint8 cookie[8];
	guint16 channel;
	GSList *tlvlist;
	char *msg = NULL;
	int len = 0;
	char *encoding = NULL, *language = NULL;
	IcbmCookie *ck;
	aim_tlv_t *tlv;
	ByteStream tbs;

	memset(&userinfo, 0, sizeof(aim_userinfo_t));

	/*
	 * Read ICBM Cookie.
	 */
	for (i = 0; i < 8; i++)
		cookie[i] = byte_stream_get8(bs);

	if ((ck = aim_uncachecookie(od, cookie, AIM_COOKIETYPE_CHAT))) {
		g_free(ck->data);
		g_free(ck);
	}

	/*
	 * Channel ID
	 *
	 * Channel 0x0003 is used for chat messages.
	 *
	 */
	channel = byte_stream_get16(bs);

	if (channel != 0x0003) {
		purple_debug_misc("oscar", "faim: chat_incoming: unknown channel! (0x%04x)\n", channel);
		return 0;
	}

	/*
	 * Start parsing TLVs right away.
	 */
	tlvlist = aim_tlvlist_read(bs);

	/*
	 * Type 0x0003: Source User Information
	 */
	tlv = aim_tlv_gettlv(tlvlist, 0x0003, 1);
	if (tlv != NULL)
	{
		byte_stream_init(&tbs, tlv->value, tlv->length);
		aim_info_extract(od, &tbs, &userinfo);
	}

	/*
	 * Type 0x0005: Message Block.  Conains more TLVs.
	 */
	tlv = aim_tlv_gettlv(tlvlist, 0x0005, 1);
	if (tlv != NULL)
	{
		GSList *inner_tlvlist;
		aim_tlv_t *inner_tlv;

		byte_stream_init(&tbs, tlv->value, tlv->length);
		inner_tlvlist = aim_tlvlist_read(&tbs);

		/*
		 * Type 0x0001: Message.
		 */
		inner_tlv = aim_tlv_gettlv(inner_tlvlist, 0x0001, 1);
		if (inner_tlv != NULL)
		{
			len = inner_tlv->length;
			msg = aim_tlv_getvalue_as_string(inner_tlv);
		}

		/*
		 * Type 0x0002: Encoding.
		 */
		encoding = aim_tlv_getstr(inner_tlvlist, 0x0002, 1);

		/*
		 * Type 0x0003: Language.
		 */
		language = aim_tlv_getstr(inner_tlvlist, 0x0003, 1);

		aim_tlvlist_free(inner_tlvlist);
	}

	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
		ret = userfunc(od, conn, frame, &userinfo, len, msg, encoding, language);

	aim_info_free(&userinfo);
	g_free(msg);
	g_free(encoding);
	g_free(language);
	aim_tlvlist_free(tlvlist);

	return ret;
}