⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 family_locate.c

📁 Linux下的多协议即时通讯程序源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
	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;}/* * Subtype 0x0002 * * Request Location services rights. * */intaim_locate_reqrights(OscarData *od){	FlapConnection *conn;	if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE)))		return -EINVAL;	aim_genericreq_n_snacid(od, conn, SNAC_FAMILY_LOCATE, SNAC_SUBTYPE_LOCATE_REQRIGHTS);	return 0;}/* * Subtype 0x0003 * * Normally contains: *   t(0001)  - short containing max profile length (value = 1024) *   t(0002)  - short - unknown (value = 16) [max MIME type length?] *   t(0003)  - short - unknown (value = 10) *   t(0004)  - short - unknown (value = 2048) [ICQ only?] */static intrights(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs){	GSList *tlvlist;	aim_rxcallback_t userfunc;	int ret = 0;	guint16 maxsiglen = 0;	tlvlist = aim_tlvlist_read(bs);	if (aim_tlv_gettlv(tlvlist, 0x0001, 1))		maxsiglen = aim_tlv_get16(tlvlist, 0x0001, 1);	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))		ret = userfunc(od, conn, frame, maxsiglen);	aim_tlvlist_free(tlvlist);	return ret;}/* * Subtype 0x0004 * * Gives BOS your profile. * * profile_encoding and awaymsg_encoding MUST be set if profile or * away are set, respectively, and their value may or may not be * restricted to a few choices.  I am currently aware of: * * us-ascii		Just that * unicode-2-0		UCS2-BE * * profile_len and awaymsg_len MUST be set similarly, and they MUST * be the length of their respective strings in bytes. * * To get the previous behavior of awaymsg == "" un-setting the away * message, set awaymsg non-NULL and awaymsg_len to 0 (this is the * obvious equivalent). * */intaim_locate_setprofile(OscarData *od,				  const char *profile_encoding, const gchar *profile, const int profile_len,				  const char *awaymsg_encoding, const gchar *awaymsg, const int awaymsg_len){	FlapConnection *conn;	FlapFrame *frame;	aim_snacid_t snacid;	GSList *tlvlist = NULL;	char *encoding;	static const char defencoding[] = {"text/aolrtf; charset=\"%s\""};	if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE)))		return -EINVAL;	if (!profile && !awaymsg)		return -EINVAL;	if ((profile && profile_encoding == NULL) || (awaymsg && awaymsg_len && awaymsg_encoding == NULL)) {		return -EINVAL;	}	/* Build the packet first to get real length */	if (profile) {		/* no + 1 here because of %s */		encoding = g_malloc(strlen(defencoding) + strlen(profile_encoding));		snprintf(encoding, strlen(defencoding) + strlen(profile_encoding), defencoding, profile_encoding);		aim_tlvlist_add_str(&tlvlist, 0x0001, encoding);		aim_tlvlist_add_raw(&tlvlist, 0x0002, profile_len, (const guchar *)profile);		g_free(encoding);	}	/*	 * So here's how this works:	 *   - You are away when you have a non-zero-length type 4 TLV stored.	 *   - You become unaway when you clear the TLV with a zero-length	 *       type 4 TLV.	 *   - If you do not send the type 4 TLV, your status does not change	 *       (that is, if you were away, you'll remain away).	 */	if (awaymsg) {		if (awaymsg_len) {			encoding = g_malloc(strlen(defencoding) + strlen(awaymsg_encoding));			snprintf(encoding, strlen(defencoding) + strlen(awaymsg_encoding), defencoding, awaymsg_encoding);			aim_tlvlist_add_str(&tlvlist, 0x0003, encoding);			aim_tlvlist_add_raw(&tlvlist, 0x0004, awaymsg_len, (const guchar *)awaymsg);			g_free(encoding);		} else			aim_tlvlist_add_noval(&tlvlist, 0x0004);	}	frame = flap_frame_new(od, 0x02, 10 + aim_tlvlist_size(tlvlist));	snacid = aim_cachesnac(od, 0x0002, 0x0004, 0x0000, NULL, 0);	aim_putsnac(&frame->data, 0x0002, 0x004, 0x0000, snacid);	aim_tlvlist_write(&frame->data, &tlvlist);	aim_tlvlist_free(tlvlist);	flap_connection_send(conn, frame);	return 0;}/* * Subtype 0x0004 - Set your client's capabilities. */intaim_locate_setcaps(OscarData *od, guint32 caps){	FlapConnection *conn;	FlapFrame *frame;	aim_snacid_t snacid;	GSList *tlvlist = NULL;	if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE)))		return -EINVAL;	aim_tlvlist_add_caps(&tlvlist, 0x0005, caps);	frame = flap_frame_new(od, 0x02, 10 + aim_tlvlist_size(tlvlist));	snacid = aim_cachesnac(od, 0x0002, 0x0004, 0x0000, NULL, 0);	aim_putsnac(&frame->data, 0x0002, 0x004, 0x0000, snacid);	aim_tlvlist_write(&frame->data, &tlvlist);	aim_tlvlist_free(tlvlist);	flap_connection_send(conn, frame);	return 0;}/* * Subtype 0x0005 - Request info of another AIM user. * * @param sn The screenname whose info you wish to request. * @param infotype The type of info you wish to request. *        0x0001 - Info/profile *        0x0003 - Away message *        0x0004 - Capabilities */intaim_locate_getinfo(OscarData *od, const char *sn, guint16 infotype){	FlapConnection *conn;	FlapFrame *frame;	aim_snacid_t snacid;	if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE)) || !sn)		return -EINVAL;	frame = flap_frame_new(od, 0x02, 12+1+strlen(sn));	snacid = aim_cachesnac(od, 0x0002, 0x0005, 0x0000, NULL, 0);	aim_putsnac(&frame->data, 0x0002, 0x0005, 0x0000, snacid);	byte_stream_put16(&frame->data, infotype);	byte_stream_put8(&frame->data, strlen(sn));	byte_stream_putstr(&frame->data, sn);	flap_connection_send(conn, frame);	return 0;}/* Subtype 0x0006 */static intuserinfo(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs){	int ret = 0;	aim_rxcallback_t userfunc;	aim_userinfo_t *userinfo, *userinfo2;	GSList *tlvlist;	aim_tlv_t *tlv = NULL;	int was_explicit;	userinfo = (aim_userinfo_t *)g_malloc(sizeof(aim_userinfo_t));	aim_info_extract(od, bs, userinfo);	tlvlist = aim_tlvlist_read(bs);	/* Profile will be 1 and 2 */	userinfo->info_encoding = aim_tlv_getstr(tlvlist, 0x0001, 1);	if ((tlv = aim_tlv_gettlv(tlvlist, 0x0002, 1))) {		userinfo->info = (char *)g_malloc(tlv->length);		memcpy(userinfo->info, tlv->value, tlv->length);		userinfo->info_len = tlv->length;	}	/* Away message will be 3 and 4 */	userinfo->away_encoding = aim_tlv_getstr(tlvlist, 0x0003, 1);	if ((tlv = aim_tlv_gettlv(tlvlist, 0x0004, 1))) {		userinfo->away = (char *)g_malloc(tlv->length);		memcpy(userinfo->away, tlv->value, tlv->length);		userinfo->away_len = tlv->length;	}	/* Caps will be 5 */	if ((tlv = aim_tlv_gettlv(tlvlist, 0x0005, 1))) {		ByteStream cbs;		byte_stream_init(&cbs, tlv->value, tlv->length);		userinfo->capabilities = aim_locate_getcaps(od, &cbs, tlv->length);		userinfo->present = AIM_USERINFO_PRESENT_CAPABILITIES;	}	aim_tlvlist_free(tlvlist);	aim_locate_adduserinfo(od, userinfo);	userinfo2 = aim_locate_finduserinfo(od, userinfo->sn);	aim_info_free(userinfo);	g_free(userinfo);	/*	 * Remove this screen name from our queue.  If the client requested	 * this buddy's info explicitly, then notify them that we have info	 * for this buddy.	 */	was_explicit = aim_locate_gotuserinfo(od, conn, userinfo2->sn);	if (was_explicit == TRUE)		if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))			ret = userfunc(od, conn, frame, userinfo2);	return ret;}/* * Subtype 0x0009 - Set directory profile data. * * This is not the same as aim_location_setprofile! * privacy: 1 to allow searching, 0 to disallow. * */int aim_locate_setdirinfo(OscarData *od, const char *first, const char *middle, const char *last, const char *maiden, const char *nickname, const char *street, const char *city, const char *state, const char *zip, int country, guint16 privacy){	FlapConnection *conn;	FlapFrame *frame;	aim_snacid_t snacid;	GSList *tlvlist = NULL;	if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE)))		return -EINVAL;	aim_tlvlist_add_16(&tlvlist, 0x000a, privacy);	if (first)		aim_tlvlist_add_str(&tlvlist, 0x0001, first);	if (last)		aim_tlvlist_add_str(&tlvlist, 0x0002, last);	if (middle)		aim_tlvlist_add_str(&tlvlist, 0x0003, middle);	if (maiden)		aim_tlvlist_add_str(&tlvlist, 0x0004, maiden);	if (state)		aim_tlvlist_add_str(&tlvlist, 0x0007, state);	if (city)		aim_tlvlist_add_str(&tlvlist, 0x0008, city);	if (nickname)		aim_tlvlist_add_str(&tlvlist, 0x000c, nickname);	if (zip)		aim_tlvlist_add_str(&tlvlist, 0x000d, zip);	if (street)		aim_tlvlist_add_str(&tlvlist, 0x0021, street);	frame = flap_frame_new(od, 0x02, 10+aim_tlvlist_size(tlvlist));	snacid = aim_cachesnac(od, 0x0002, 0x0009, 0x0000, NULL, 0);	aim_putsnac(&frame->data, 0x0002, 0x0009, 0x0000, snacid);	aim_tlvlist_write(&frame->data, &tlvlist);	aim_tlvlist_free(tlvlist);	flap_connection_send(conn, frame);	return 0;}/* * Subtype 0x000b - Huh? What is this? */int aim_locate_000b(OscarData *od, const char *sn){	FlapConnection *conn;	FlapFrame *frame;	aim_snacid_t snacid;		return -EINVAL;	if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE)) || !sn)		return -EINVAL;	frame = flap_frame_new(od, 0x02, 10+1+strlen(sn));	snacid = aim_cachesnac(od, 0x0002, 0x000b, 0x0000, NULL, 0);	aim_putsnac(&frame->data, 0x0002, 0x000b, 0x0000, snacid);	byte_stream_put8(&frame->data, strlen(sn));	byte_stream_putstr(&frame->data, sn);	flap_connection_send(conn, frame);	return 0;}/* * Subtype 0x000f * * XXX pass these in better * */intaim_locate_setinterests(OscarData *od, const char *interest1, const char *interest2, const char *interest3, const char *interest4, const char *interest5, guint16 privacy){	FlapConnection *conn;	FlapFrame *frame;	aim_snacid_t snacid;	GSList *tlvlist = NULL;	if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE)))		return -EINVAL;	/* ?? privacy ?? */	aim_tlvlist_add_16(&tlvlist, 0x000a, privacy);	if (interest1)		aim_tlvlist_add_str(&tlvlist, 0x0000b, interest1);	if (interest2)		aim_tlvlist_add_str(&tlvlist, 0x0000b, interest2);	if (interest3)		aim_tlvlist_add_str(&tlvlist, 0x0000b, interest3);	if (interest4)		aim_tlvlist_add_str(&tlvlist, 0x0000b, interest4);	if (interest5)		aim_tlvlist_add_str(&tlvlist, 0x0000b, interest5);	frame = flap_frame_new(od, 0x02, 10+aim_tlvlist_size(tlvlist));	snacid = aim_cachesnac(od, 0x0002, 0x000f, 0x0000, NULL, 0);	aim_putsnac(&frame->data, 0x0002, 0x000f, 0x0000, 0);	aim_tlvlist_write(&frame->data, &tlvlist);	aim_tlvlist_free(tlvlist);	flap_connection_send(conn, frame);	return 0;}/* * Subtype 0x0015 - Request the info a user using the short method.  This is * what iChat uses.  It normally is VERY leniently rate limited. * * @param sn The screen name whose info you wish to request. * @param flags The bitmask which specifies the type of info you wish to request. *        0x00000001 - Info/profile. *        0x00000002 - Away message. *        0x00000004 - Capabilities. *        0x00000008 - Certification. * @return Return 0 if no errors, otherwise return the error number. */intaim_locate_getinfoshort(OscarData *od, const char *sn, guint32 flags){	FlapConnection *conn;	ByteStream data;	aim_snacid_t snacid;	if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE)) || !sn)		return -EINVAL;	byte_stream_new(&data, 4 + 1 + strlen(sn));	byte_stream_put32(&data, flags);	byte_stream_put8(&data, strlen(sn));	byte_stream_putstr(&data, sn);	snacid = aim_cachesnac(od, 0x0002, 0x0015, 0x0000, sn, strlen(sn)+1);	flap_connection_send_snac(od, conn, 0x0002, 0x0015, 0x0000, snacid, &data);	g_free(data.data);	return 0;}static intsnachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs){	if (snac->subtype == 0x0001)		return error(od, conn, mod, frame, snac, bs);	else if (snac->subtype == 0x0003)		return rights(od, conn, mod, frame, snac, bs);	else if (snac->subtype == 0x0006)		return userinfo(od, conn, mod, frame, snac, bs);	return 0;}static voidlocate_shutdown(OscarData *od, aim_module_t *mod){	aim_userinfo_t *del;	while (od->locate.userinfo) {		del = od->locate.userinfo;		od->locate.userinfo = od->locate.userinfo->next;		aim_info_free(del);		g_free(del);	}}intlocate_modfirst(OscarData *od, aim_module_t *mod){	mod->family = SNAC_FAMILY_LOCATE;	mod->version = 0x0001;	mod->toolid = 0x0110;	mod->toolversion = 0x0629;	mod->flags = 0;	strncpy(mod->name, "locate", sizeof(mod->name));	mod->snachandler = snachandler;	mod->shutdown = locate_shutdown;	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -