view src/protocols/oscar/odir.c @ 7011:4375bf2d9020

[gaim-migrate @ 7574] The user-visible changes? Gaim now shows peep's away messages in their tooltip for AIM over oscar. Things to do: -Make sure this doesn't screw up with huge buddy lists -Replace %n with your screen name, etc. in the tooltip -Leave in b, i, u tags in the tooltip -Fix the 2 8 byte memleaks in locate.c Client authors that aren't me will want to read the following pretty closely... I made some internal libfaim changes. I desire to make libfaim cleaner. I don't know if this really helps or not. Here's what I've done: Changed all the SNAC-sending functions in info.c to NOT take a conn argument. The connection is looked up from the session. I'm trying to make oscar.c less-aware of connections. Added aim_locate_finduserinfo() - Use for getting the aim_userinfo_t for the given screenname. Added aim_locate_getinfoshort() - Use this to request that the servers send you profile info, away message, caps, or a combination of the above. It's like aim_locate_getinfo() but less rate limited. Renamed aim_bos_reqlocaterights() to aim_locate_reqrights() Renamed aim_getinfo() to aim_locate_getinfo() Renamed aim_setdirectoryinfo() to aim_locate_setdirinfo() Renamed aim_0002_000b() to aim_locate_000b() Renamed aim_setuserinterests() to aim_locate_setinterests() Removed aim_userinfo_sn() Removed aim_userinfo_flags() Removed aim_userinfo_idle() Removed aim_userinfo_warnlevel() Removed aim_userinfo_createtime() Removed aim_userinfo_membersince() Removed aim_userinfo_onlinesince() Removed aim_userinfo_sessionlen() Removed aim_userinfo_hascap() Renamed info.c to locate.c Made locate.c keep a static, linked list of nodes of sn, away message, available message, user info. This list is maintained by libfaim automatically. Now clients don't have to keep track of all this stuff themselves, and users won't have to wait for away message/info retrieval if the person is in your buddy list. libfaim uses the iChat way of retrieving stuff, which is not nearly as rate limited as the old way. I actually have a feeling WinAIM uses the same SNAC now (although I didn't check), but I like pluggin iChat because it's innovative. Moved sess->emailinfo to a static variable inside email.c. Removed evilhack from oscar.c I think that's about everything... committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 29 Sep 2003 12:30:03 +0000
parents 594682101ba6
children 6d3d8f11e765
line wrap: on
line source

/*
 * Family 0x000f - Newer Search Method
 *
 * Used for searching for other AIM users by email address, name, 
 * location, commmon interests, and a few other similar things.
 *
 */

#define FAIM_INTERNAL
#include <aim.h>

/**
 * Subtype 0x0002 - Submit a User Search Request
 *
 * Search for an AIM screen name based on their email address.
 *
 * @param sess The oscar session.
 * @param region Should be "us-ascii" unless you know what you're doing.
 * @param email The email address you want to search for.
 * @return Return 0 if no errors, otherwise return the error number.
 */
faim_export int aim_odir_email(aim_session_t *sess, const char *region, const char *email)
{
	aim_conn_t *conn;
	aim_frame_t *fr;
	aim_snacid_t snacid;
	aim_tlvlist_t *tl = NULL;

	if (!sess || !(conn = aim_conn_findbygroup(sess, 0x000f)) || !region || !email)
		return -EINVAL;

	/* Create a TLV chain, write it to the outgoing frame, then free the chain */
	aim_addtlvtochain_raw(&tl, 0x001c, strlen(region), region);
	aim_addtlvtochain16(&tl, 0x000a, 0x0001); /* Type of search */
	aim_addtlvtochain_raw(&tl, 0x0005, strlen(email), email);

	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_sizetlvchain(&tl))))
		return -ENOMEM;
	snacid = aim_cachesnac(sess, 0x000f, 0x0002, 0x0000, NULL, 0);
	aim_putsnac(&fr->data, 0x000f, 0x0002, 0x0000, snacid);

	aim_writetlvchain(&fr->data, &tl);
	aim_freetlvchain(&tl);

	aim_tx_enqueue(sess, fr);

	return 0;
}


/**
 * Subtype 0x0002 - Submit a User Search Request
 *
 * Search for an AIM screen name based on various info 
 * about the person.
 *
 * @param sess The oscar session.
 * @param region Should be "us-ascii" unless you know what you're doing.
 * @param first The first name of the person you want to search for.
 * @param middle The middle name of the person you want to search for.
 * @param last The last name of the person you want to search for.
 * @param maiden The maiden name of the person you want to search for.
 * @param nick The nick name of the person you want to search for.
 * @param city The city where the person you want to search for resides.
 * @param state The state where the person you want to search for resides.
 * @param country The country where the person you want to search for resides.
 * @param zip The zip code where the person you want to search for resides.
 * @param address The street address where the person you want to seach for resides.
 * @return Return 0 if no errors, otherwise return the error number.
 */
faim_export int aim_odir_name(aim_session_t *sess, const char *region, const char *first, const char *middle, const char *last, const char *maiden, const char *nick, const char *city, const char *state, const char *country, const char *zip, const char *address)
{
	aim_conn_t *conn;
	aim_frame_t *fr;
	aim_snacid_t snacid;
	aim_tlvlist_t *tl = NULL;

	if (!sess || !(conn = aim_conn_findbygroup(sess, 0x000f)) || !region)
		return -EINVAL;

	/* Create a TLV chain, write it to the outgoing frame, then free the chain */
	aim_addtlvtochain_raw(&tl, 0x001c, strlen(region), region);
	aim_addtlvtochain16(&tl, 0x000a, 0x0000); /* Type of search */
	if (first)
		aim_addtlvtochain_raw(&tl, 0x0001, strlen(first), first);
	if (last)
		aim_addtlvtochain_raw(&tl, 0x0002, strlen(last), last);
	if (middle)
		aim_addtlvtochain_raw(&tl, 0x0003, strlen(middle), middle);
	if (maiden)
		aim_addtlvtochain_raw(&tl, 0x0004, strlen(maiden), maiden);
	if (country)
		aim_addtlvtochain_raw(&tl, 0x0006, strlen(country), country);
	if (state)
		aim_addtlvtochain_raw(&tl, 0x0007, strlen(state), state);
	if (city)
		aim_addtlvtochain_raw(&tl, 0x0008, strlen(city), city);
	if (nick)
		aim_addtlvtochain_raw(&tl, 0x000c, strlen(nick), nick);
	if (zip)
		aim_addtlvtochain_raw(&tl, 0x000d, strlen(zip), zip);
	if (address)
		aim_addtlvtochain_raw(&tl, 0x0021, strlen(address), address);

	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_sizetlvchain(&tl))))
		return -ENOMEM;
	snacid = aim_cachesnac(sess, 0x000f, 0x0002, 0x0000, NULL, 0);
	aim_putsnac(&fr->data, 0x000f, 0x0002, 0x0000, snacid);

	aim_writetlvchain(&fr->data, &tl);
	aim_freetlvchain(&tl);

	aim_tx_enqueue(sess, fr);

	return 0;
}


/**
 * Subtype 0x0002 - Submit a User Search Request
 *
 * @param sess The oscar session.
 * @param interest1 An interest you want to search for.
 * @return Return 0 if no errors, otherwise return the error number.
 */
faim_export int aim_odir_interest(aim_session_t *sess, const char *region, const char *interest)
{
	aim_conn_t *conn;
	aim_frame_t *fr;
	aim_snacid_t snacid;
	aim_tlvlist_t *tl = NULL;

	if (!sess || !(conn = aim_conn_findbygroup(sess, 0x000f)) || !region)
		return -EINVAL;

	/* Create a TLV chain, write it to the outgoing frame, then free the chain */
	aim_addtlvtochain_raw(&tl, 0x001c, strlen(region), region);
	aim_addtlvtochain16(&tl, 0x000a, 0x0001); /* Type of search */
	if (interest)
		aim_addtlvtochain_raw(&tl, 0x0001, strlen(interest), interest);

	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_sizetlvchain(&tl))))
		return -ENOMEM;
	snacid = aim_cachesnac(sess, 0x000f, 0x0002, 0x0000, NULL, 0);
	aim_putsnac(&fr->data, 0x000f, 0x0002, 0x0000, snacid);

	aim_writetlvchain(&fr->data, &tl);
	aim_freetlvchain(&tl);

	aim_tx_enqueue(sess, fr);

	return 0;
}


/**
 * Subtype 0x0003 - Receive Reply From a User Search
 *
 */
static int parseresults(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
{
	int ret = 0;
	aim_rxcallback_t userfunc;
	fu16_t tmp, numresults;
	struct aim_odir *results = NULL;

	tmp = aimbs_get16(bs); /* Unknown */
	tmp = aimbs_get16(bs); /* Unknown */
	aim_bstream_advance(bs, tmp);

	numresults = aimbs_get16(bs); /* Number of results to follow */

	/* Allocate a linked list, 1 node per result */
	while (numresults) {
		struct aim_odir *new;
		aim_tlvlist_t *tl = aim_readtlvchain_num(bs, aimbs_get16(bs));
		new = (struct aim_odir *)malloc(sizeof(struct aim_odir));
		new->first = aim_gettlv_str(tl, 0x0001, 1);
		new->last = aim_gettlv_str(tl, 0x0002, 1);
		new->middle = aim_gettlv_str(tl, 0x0003, 1);
		new->maiden = aim_gettlv_str(tl, 0x0004, 1);
		new->email = aim_gettlv_str(tl, 0x0005, 1);
		new->country = aim_gettlv_str(tl, 0x0006, 1);
		new->state = aim_gettlv_str(tl, 0x0007, 1);
		new->city = aim_gettlv_str(tl, 0x0008, 1);
		new->sn = aim_gettlv_str(tl, 0x0009, 1);
		new->interest = aim_gettlv_str(tl, 0x000b, 1);
		new->nick = aim_gettlv_str(tl, 0x000c, 1);
		new->zip = aim_gettlv_str(tl, 0x000d, 1);
		new->region = aim_gettlv_str(tl, 0x001c, 1);
		new->address = aim_gettlv_str(tl, 0x0021, 1);
		new->next = results;
		results = new;
		numresults--;
	}

	if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
		ret = userfunc(sess, rx, results);

	/* Now free everything from above */
	while (results) {
		struct aim_odir *del = results;
		results = results->next;
		free(del->first);
		free(del->last);
		free(del->middle);
		free(del->maiden);
		free(del->email);
		free(del->country);
		free(del->state);
		free(del->city);
		free(del->sn);
		free(del->interest);
		free(del->nick);
		free(del->zip);
		free(del->region);
		free(del->address);
		free(del);
	}

	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 == 0x0003)
		return parseresults(sess, mod, rx, snac, bs);

	return 0;
}

faim_internal int odir_modfirst(aim_session_t *sess, aim_module_t *mod)
{

	mod->family = 0x000f;
	mod->version = 0x0001;
	mod->toolid = 0x0010;
	mod->toolversion = 0x0629;
	mod->flags = 0;
	strncpy(mod->name, "odir", sizeof(mod->name));
	mod->snachandler = snachandler;

	return 0;
}