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

📄 family_feedbag.c

📁 Linux下的多协议即时通讯程序源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
		if ((del = aim_ssi_itemlist_find(od->ssi.local, gid, bid)))			aim_ssi_itemlist_del(&od->ssi.local, del);		if ((del = aim_ssi_itemlist_find(od->ssi.official, gid, bid)))			aim_ssi_itemlist_del(&od->ssi.official, del);		if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))			ret = userfunc(od, conn, frame);	}	return ret;}/* * Subtype 0x000e - SSI Add/Mod/Del Ack. * * Response to add, modify, or delete SNAC (sent with aim_ssi_addmoddel). * */static int parseack(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs){	int ret = 0;	aim_rxcallback_t userfunc;	struct aim_ssi_tmp *cur, *del;	/* Read in the success/failure flags from the ack SNAC */	cur = od->ssi.pending;	while (cur && (byte_stream_empty(bs)>0)) {		cur->ack = byte_stream_get16(bs);		cur = cur->next;	}	/*	 * If outcome is 0, then add the item to the item list, or replace the other item,	 * or remove the old item.  If outcome is non-zero, then remove the item from the	 * local list, or unmodify it, or add it.	 */	for (cur=od->ssi.pending; (cur && (cur->ack != 0xffff)); cur=cur->next) {	if (cur->item) {		if (cur->ack) {			/* Our action was unsuccessful, so change the local list back to how it was */			if (cur->action == SNAC_SUBTYPE_FEEDBAG_ADD) {				/* Remove the item from the local list */				/* Make sure cur->item is still valid memory */				if (aim_ssi_itemlist_valid(od->ssi.local, cur->item)) {					if (cur->item->name) {						cur->name = (char *)g_malloc((strlen(cur->item->name)+1)*sizeof(char));						strcpy(cur->name, cur->item->name);					}					aim_ssi_itemlist_del(&od->ssi.local, cur->item);				}				cur->item = NULL;			} else if (cur->action == SNAC_SUBTYPE_FEEDBAG_MOD) {				/* Replace the local item with the item from the official list */				if (aim_ssi_itemlist_valid(od->ssi.local, cur->item)) {					struct aim_ssi_item *cur1;					if ((cur1 = aim_ssi_itemlist_find(od->ssi.official, cur->item->gid, cur->item->bid))) {						g_free(cur->item->name);						if (cur1->name) {							cur->item->name = (char *)g_malloc((strlen(cur1->name)+1)*sizeof(char));							strcpy(cur->item->name, cur1->name);						} else							cur->item->name = NULL;						aim_tlvlist_free(cur->item->data);						cur->item->data = aim_tlvlist_copy(cur1->data);					}				} else					cur->item = NULL;			} else if (cur->action == SNAC_SUBTYPE_FEEDBAG_DEL) {				/* Add the item back into the local list */				if (aim_ssi_itemlist_valid(od->ssi.official, cur->item)) {					aim_ssi_itemlist_add(&od->ssi.local, cur->item->name, cur->item->gid, cur->item->bid, cur->item->type, cur->item->data);				} else					cur->item = NULL;			}		} else {			/* Do the exact opposite */			if (cur->action == SNAC_SUBTYPE_FEEDBAG_ADD) {			/* Add the local item to the official list */				if (aim_ssi_itemlist_valid(od->ssi.local, cur->item)) {					aim_ssi_itemlist_add(&od->ssi.official, cur->item->name, cur->item->gid, cur->item->bid, cur->item->type, cur->item->data);				} else					cur->item = NULL;			} else if (cur->action == SNAC_SUBTYPE_FEEDBAG_MOD) {				/* Replace the official item with the item from the local list */				if (aim_ssi_itemlist_valid(od->ssi.local, cur->item)) {					struct aim_ssi_item *cur1;					if ((cur1 = aim_ssi_itemlist_find(od->ssi.official, cur->item->gid, cur->item->bid))) {						g_free(cur1->name);						if (cur->item->name) {							cur1->name = (char *)g_malloc((strlen(cur->item->name)+1)*sizeof(char));							strcpy(cur1->name, cur->item->name);						} else							cur1->name = NULL;						aim_tlvlist_free(cur1->data);						cur1->data = aim_tlvlist_copy(cur->item->data);					}				} else					cur->item = NULL;			} else if (cur->action == SNAC_SUBTYPE_FEEDBAG_DEL) {				/* Remove the item from the official list */				if (aim_ssi_itemlist_valid(od->ssi.official, cur->item))					aim_ssi_itemlist_del(&od->ssi.official, cur->item);				cur->item = NULL;			}		}	} /* End if (cur->item) */	} /* End for loop */	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))		ret = userfunc(od, conn, frame, od->ssi.pending);	/* Free all aim_ssi_tmp's with an outcome */	cur = od->ssi.pending;	while (cur && (cur->ack != 0xffff)) {		del = cur;		cur = cur->next;		g_free(del->name);		g_free(del);	}	od->ssi.pending = cur;	/* If we're not waiting for any more acks, then send more SNACs */	if (!od->ssi.pending) {		od->ssi.waiting_for_ack = FALSE;		aim_ssi_sync(od);	}	return ret;}/* * Subtype 0x000f - SSI Data Unchanged. * * Response to aim_ssi_reqifchanged() if the server-side data is not newer than * posted local stamp/revision. * */static int parsedataunchanged(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs){	int ret = 0;	aim_rxcallback_t userfunc;	od->ssi.received_data = TRUE;	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))		ret = userfunc(od, conn, frame);	return ret;}/* * Subtype 0x0011 - SSI Begin Data Modification. * * Tell the server you're going to start modifying data.  This marks * the beginning of a transaction. */int aim_ssi_modbegin(OscarData *od){	FlapConnection *conn;	if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_FEEDBAG)))		return -EINVAL;	aim_genericreq_n(od, conn, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_EDITSTART);	return 0;}/* * Subtype 0x0012 - SSI End Data Modification. * * Tell the server you're finished modifying data.  The marks the end * of a transaction. */int aim_ssi_modend(OscarData *od){	FlapConnection *conn;	if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_FEEDBAG)))		return -EINVAL;	aim_genericreq_n(od, conn, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_EDITSTOP);	return 0;}/* * Subtype 0x0014 - Grant authorization * * Authorizes a contact so they can add you to their contact list. * */int aim_ssi_sendauth(OscarData *od, char *sn, char *msg){	FlapConnection *conn;	FlapFrame *frame;	aim_snacid_t snacid;	if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_FEEDBAG)) || !sn)		return -EINVAL;	frame = flap_frame_new(od, 0x02, 10+1+strlen(sn)+2+(msg ? strlen(msg)+1 : 0)+2);	snacid = aim_cachesnac(od, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_SENDAUTH, 0x0000, NULL, 0);	aim_putsnac(&frame->data, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_SENDAUTH, 0x0000, snacid);	/* Screen name */	byte_stream_put8(&frame->data, strlen(sn));	byte_stream_putstr(&frame->data, sn);	/* Message (null terminated) */	byte_stream_put16(&frame->data, msg ? strlen(msg) : 0);	if (msg) {		byte_stream_putstr(&frame->data, msg);		byte_stream_put8(&frame->data, 0x00);	}	/* Unknown */	byte_stream_put16(&frame->data, 0x0000);	flap_connection_send(conn, frame);	return 0;}/* * Subtype 0x0015 - Receive an authorization grant */static int receiveauthgrant(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs){	int ret = 0;	aim_rxcallback_t userfunc;	guint16 tmp;	char *sn, *msg;	/* Read screen name */	if ((tmp = byte_stream_get8(bs)))		sn = byte_stream_getstr(bs, tmp);	else		sn = NULL;	/* Read message (null terminated) */	if ((tmp = byte_stream_get16(bs)))		msg = byte_stream_getstr(bs, tmp);	else		msg = NULL;	/* Unknown */	tmp = byte_stream_get16(bs);	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))		ret = userfunc(od, conn, frame, sn, msg);	g_free(sn);	g_free(msg);	return ret;}/* * Subtype 0x0018 - Send authorization request * * Sends a request for authorization to the given contact.  The request will either be * granted, denied, or dropped. * */int aim_ssi_sendauthrequest(OscarData *od, char *sn, const char *msg){	FlapConnection *conn;	FlapFrame *frame;	aim_snacid_t snacid;	if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_FEEDBAG)) || !sn)		return -EINVAL;	frame = flap_frame_new(od, 0x02, 10+1+strlen(sn)+2+(msg ? strlen(msg)+1 : 0)+2);	snacid = aim_cachesnac(od, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_SENDAUTHREQ, 0x0000, NULL, 0);	aim_putsnac(&frame->data, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_SENDAUTHREQ, 0x0000, snacid);	/* Screen name */	byte_stream_put8(&frame->data, strlen(sn));	byte_stream_putstr(&frame->data, sn);	/* Message (null terminated) */	byte_stream_put16(&frame->data, msg ? strlen(msg) : 0);	if (msg) {		byte_stream_putstr(&frame->data, msg);		byte_stream_put8(&frame->data, 0x00);	}	/* Unknown */	byte_stream_put16(&frame->data, 0x0000);	flap_connection_send(conn, frame);	return 0;}/* * Subtype 0x0019 - Receive an authorization request */static int receiveauthrequest(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs){	int ret = 0;	aim_rxcallback_t userfunc;	guint16 tmp;	char *sn, *msg;	/* Read screen name */	if ((tmp = byte_stream_get8(bs)))		sn = byte_stream_getstr(bs, tmp);	else		sn = NULL;	/* Read message (null terminated) */	if ((tmp = byte_stream_get16(bs)))		msg = byte_stream_getstr(bs, tmp);	else		msg = NULL;	/* Unknown */	tmp = byte_stream_get16(bs);	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))		ret = userfunc(od, conn, frame, sn, msg);	g_free(sn);	g_free(msg);	return ret;}/* * Subtype 0x001a - Send authorization reply * * Sends a reply to a request for authorization.  The reply can either * grant authorization or deny authorization. * * if reply=0x00 then deny * if reply=0x01 then grant * */int aim_ssi_sendauthreply(OscarData *od, char *sn, guint8 reply, const char *msg){	FlapConnection *conn;	FlapFrame *frame;	aim_snacid_t snacid;	if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_FEEDBAG)) || !sn)		return -EINVAL;	frame = flap_frame_new(od, 0x02, 10 + 1+strlen(sn) + 1 + 2+(msg ? strlen(msg)+1 : 0) + 2);	snacid = aim_cachesnac(od, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_SENDAUTHREP, 0x0000, NULL, 0);	aim_putsnac(&frame->data, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_SENDAUTHREP, 0x0000, snacid);	/* Screen name */	byte_stream_put8(&frame->data, strlen(sn));	byte_stream_putstr(&frame->data, sn);	/* Grant or deny */	byte_stream_put8(&frame->data, reply);	/* Message (null terminated) */	byte_stream_put16(&frame->data, msg ? (strlen(msg)+1) : 0);	if (msg) {		byte_stream_putstr(&frame->data, msg);		byte_stream_put8(&frame->data, 0x00);	}	/* Unknown */	byte_stream_put16(&frame->data, 0x0000);	flap_connection_send(conn, frame);	return 0;}/* * Subtype 0x001b - Receive an authorization reply * * You get this bad boy when other people respond to the authorization * request that you have previously sent them. */static int receiveauthreply(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs){	int ret = 0;	aim_rxcallback_t userfunc;	guint16 tmp;	guint8 reply;	char *sn, *msg;	/* Read screen name */	if ((tmp = byte_stream_get8(bs)))		sn = byte_stream_getstr(bs, tmp);	else		sn = NULL;	/* Read reply */	reply = byte_stream_get8(bs);	/* Read message (null terminated) */	if ((tmp = byte_stream_get16(bs)))		msg = byte_stream_getstr(bs, tmp);	else		msg = NULL;	/* Unknown */	tmp = byte_stream_get16(bs);	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))		ret = userfunc(od, conn, frame, sn, reply, msg);	g_free(sn);	g_free(msg);	return ret;}/* * Subtype 0x001c - Receive a message telling you someone added you to their list. */static int receiveadded(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs){	int ret = 0;	aim_rxcallback_t userfunc;	guint16 tmp;	char *sn;	/* Read screen name */	if ((tmp = byte_stream_get8(bs)))		sn = byte_stream_getstr(bs, tmp);	else		sn = NULL;	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))		ret = userfunc(od, conn, frame, sn);	g_free(sn);	return ret;}static intsnachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs){	if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_RIGHTSINFO)		return parserights(od, conn, mod, frame, snac, bs);	else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_LIST)		return parsedata(od, conn, mod, frame, snac, bs);	else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_ADD)		return parseadd(od, conn, mod, frame, snac, bs);	else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_MOD)		return parsemod(od, conn, mod, frame, snac, bs);	else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_DEL)		return parsedel(od, conn, mod, frame, snac, bs);	else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_SRVACK)		return parseack(od, conn, mod, frame, snac, bs);	else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_NOLIST)		return parsedataunchanged(od, conn, mod, frame, snac, bs);	else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_RECVAUTH)		return receiveauthgrant(od, conn, mod, frame, snac, bs);	else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_RECVAUTHREQ)		return receiveauthrequest(od, conn, mod, frame, snac, bs);	else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_RECVAUTHREP)		return receiveauthreply(od, conn, mod, frame, snac, bs);	else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_ADDED)		return receiveadded(od, conn, mod, frame, snac, bs);	return 0;}static voidssi_shutdown(OscarData *od, aim_module_t *mod){	aim_ssi_freelist(od);}intssi_modfirst(OscarData *od, aim_module_t *mod){	mod->family = SNAC_FAMILY_FEEDBAG;	mod->version = 0x0004;	mod->toolid = 0x0110;	mod->toolversion = 0x0629;	mod->flags = 0;	strncpy(mod->name, "feedbag", sizeof(mod->name));	mod->snachandler = snachandler;	mod->shutdown = ssi_shutdown;	return 0;}

⌨️ 快捷键说明

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