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

📄 ssi.c

📁 oscar message protocol stack
💻 C
📖 第 1 页 / 共 4 页
字号:
	return ret;}/* * Subtype 0x000e - SSI Add/Mod/Del Ack. * * Response to add, modify, or delete SNAC (sent with aim_ssi_addmoddel). * */static int parseack(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;	struct aim_ssi_tmp *cur, *del;	/* Read in the success/failure flags from the ack SNAC */	cur = sess->ssi.pending;	while (cur && (aim_bstream_empty(bs)>0)) {		cur->ack = aimbs_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=sess->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 == AIM_CB_SSI_ADD) {				/* Remove the item from the local list */				/* Make sure cur->item is still valid memory */				if (aim_ssi_itemlist_valid(sess->ssi.local, cur->item)) {					if (cur->item->name) {						cur->name = (char *)malloc((strlen(cur->item->name)+1)*sizeof(char));						strcpy(cur->name, cur->item->name);					}					aim_ssi_itemlist_del(&sess->ssi.local, cur->item);				}				cur->item = NULL;			} else if (cur->action == AIM_CB_SSI_MOD) {				/* Replace the local item with the item from the official list */				if (aim_ssi_itemlist_valid(sess->ssi.local, cur->item)) {					struct aim_ssi_item *cur1;					if ((cur1 = aim_ssi_itemlist_find(sess->ssi.official, cur->item->gid, cur->item->bid))) {						free(cur->item->name);						if (cur1->name) {							cur->item->name = (char *)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 == AIM_CB_SSI_DEL) {				/* Add the item back into the local list */				if (aim_ssi_itemlist_valid(sess->ssi.official, cur->item)) {					aim_ssi_itemlist_add(&sess->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 == AIM_CB_SSI_ADD) {			/* Add the local item to the official list */				if (aim_ssi_itemlist_valid(sess->ssi.local, cur->item)) {					aim_ssi_itemlist_add(&sess->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 == AIM_CB_SSI_MOD) {				/* Replace the official item with the item from the local list */				if (aim_ssi_itemlist_valid(sess->ssi.local, cur->item)) {					struct aim_ssi_item *cur1;					if ((cur1 = aim_ssi_itemlist_find(sess->ssi.official, cur->item->gid, cur->item->bid))) {						free(cur1->name);						if (cur->item->name) {							cur1->name = (char *)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 == AIM_CB_SSI_DEL) {				/* Remove the item from the official list */				if (aim_ssi_itemlist_valid(sess->ssi.official, cur->item))					aim_ssi_itemlist_del(&sess->ssi.official, cur->item);				cur->item = NULL;			}		}	} /* End if (cur->item) */	} /* End for loop */	if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))		ret = userfunc(sess, rx, sess->ssi.pending);	/* Free all aim_ssi_tmp's with an outcome */	cur = sess->ssi.pending;	while (cur && (cur->ack != 0xffff)) {		del = cur;		cur = cur->next;		free(del->name);		free(del);	}	sess->ssi.pending = cur;	/* If we're not waiting for any more acks, then send more SNACs */	if (!sess->ssi.pending) {		sess->ssi.pending = NULL;		sess->ssi.waiting_for_ack = 0;		aim_ssi_sync(sess);	}	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(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;	sess->ssi.received_data = 1;	if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))		ret = userfunc(sess, rx);	return ret;}/* * Subtype 0x0011 - SSI Begin Data Modification. * * Tells the server you're going to start modifying data. *  */faim_export int aim_ssi_modbegin(aim_session_t *sess){	aim_conn_t *conn;	if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_SSI)))		return -EINVAL;	return aim_genericreq_n(sess, conn, AIM_CB_FAM_SSI, AIM_CB_SSI_EDITSTART);}/* * Subtype 0x0012 - SSI End Data Modification. * * Tells the server you're finished modifying data. * */faim_export int aim_ssi_modend(aim_session_t *sess){	aim_conn_t *conn;	if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_SSI)))		return -EINVAL;	return aim_genericreq_n(sess, conn, AIM_CB_FAM_SSI, AIM_CB_SSI_EDITSTOP);}/* * Subtype 0x0014 - Grant authorization * * Authorizes a contact so they can add you to their contact list. * */faim_export int aim_ssi_sendauth(aim_session_t *sess, char *sn, char *msg){	aim_conn_t *conn;	aim_frame_t *fr;	aim_snacid_t snacid;	if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_SSI)) || !sn)		return -EINVAL;	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)+2+(msg ? strlen(msg)+1 : 0)+2)))		return -ENOMEM;	snacid = aim_cachesnac(sess, AIM_CB_FAM_SSI, AIM_CB_SSI_SENDAUTH, 0x0000, NULL, 0);	aim_putsnac(&fr->data, AIM_CB_FAM_SSI, AIM_CB_SSI_SENDAUTH, 0x0000, snacid);	/* Screen name */	aimbs_put8(&fr->data, strlen(sn));	aimbs_putraw(&fr->data, sn, strlen(sn));	/* Message (null terminated) */	aimbs_put16(&fr->data, msg ? strlen(msg) : 0);	if (msg) {		aimbs_putraw(&fr->data, msg, strlen(msg));		aimbs_put8(&fr->data, 0x00);	}	/* Unknown */	aimbs_put16(&fr->data, 0x0000);	aim_tx_enqueue(sess, fr);	return 0;}/* * Subtype 0x0015 - Receive an authorization grant */static int receiveauthgrant(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;	char *sn, *msg;	/* Read screen name */	if ((tmp = aimbs_get8(bs)))		sn = aimbs_getstr(bs, tmp);	else		sn = NULL;	/* Read message (null terminated) */	if ((tmp = aimbs_get16(bs)))		msg = aimbs_getstr(bs, tmp);	else		msg = NULL;	/* Unknown */	tmp = aimbs_get16(bs);	if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))		ret = userfunc(sess, rx, sn, msg);	free(sn);	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. * */faim_export int aim_ssi_sendauthrequest(aim_session_t *sess, char *sn, char *msg){	aim_conn_t *conn;	aim_frame_t *fr;	aim_snacid_t snacid;	if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_SSI)) || !sn)		return -EINVAL;	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)+2+(msg ? strlen(msg)+1 : 0)+2)))		return -ENOMEM;	snacid = aim_cachesnac(sess, AIM_CB_FAM_SSI, AIM_CB_SSI_SENDAUTHREQ, 0x0000, NULL, 0);	aim_putsnac(&fr->data, AIM_CB_FAM_SSI, AIM_CB_SSI_SENDAUTHREQ, 0x0000, snacid);	/* Screen name */	aimbs_put8(&fr->data, strlen(sn));	aimbs_putraw(&fr->data, sn, strlen(sn));	/* Message (null terminated) */	aimbs_put16(&fr->data, msg ? strlen(msg) : 0);	if (msg) {		aimbs_putraw(&fr->data, msg, strlen(msg));		aimbs_put8(&fr->data, 0x00);	}	/* Unknown */	aimbs_put16(&fr->data, 0x0000);	aim_tx_enqueue(sess, fr);	return 0;}/* * Subtype 0x0019 - Receive an authorization request */static int receiveauthrequest(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;	char *sn, *msg;	/* Read screen name */	if ((tmp = aimbs_get8(bs)))		sn = aimbs_getstr(bs, tmp);	else		sn = NULL;	/* Read message (null terminated) */	if ((tmp = aimbs_get16(bs)))		msg = aimbs_getstr(bs, tmp);	else		msg = NULL;	/* Unknown */	tmp = aimbs_get16(bs);	if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))		ret = userfunc(sess, rx, sn, msg);	free(sn);	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 * */faim_export int aim_ssi_sendauthreply(aim_session_t *sess, char *sn, fu8_t reply, char *msg){	aim_conn_t *conn;	aim_frame_t *fr;	aim_snacid_t snacid;	if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_SSI)) || !sn)		return -EINVAL;	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 1+strlen(sn) + 1 + 2+(msg ? strlen(msg)+1 : 0) + 2)))		return -ENOMEM;	snacid = aim_cachesnac(sess, AIM_CB_FAM_SSI, AIM_CB_SSI_SENDAUTHREP, 0x0000, NULL, 0);	aim_putsnac(&fr->data, AIM_CB_FAM_SSI, AIM_CB_SSI_SENDAUTHREP, 0x0000, snacid);	/* Screen name */	aimbs_put8(&fr->data, strlen(sn));	aimbs_putraw(&fr->data, sn, strlen(sn));	/* Grant or deny */	aimbs_put8(&fr->data, reply);	/* Message (null terminated) */	aimbs_put16(&fr->data, msg ? (strlen(msg)+1) : 0);	if (msg) {		aimbs_putraw(&fr->data, msg, strlen(msg));		aimbs_put8(&fr->data, 0x00);	}	/* Unknown */	aimbs_put16(&fr->data, 0x0000);	aim_tx_enqueue(sess, fr);	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(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;	fu8_t reply;	char *sn, *msg;	/* Read screen name */	if ((tmp = aimbs_get8(bs)))		sn = aimbs_getstr(bs, tmp);	else		sn = NULL;	/* Read reply */	reply = aimbs_get8(bs);	/* Read message (null terminated) */	if ((tmp = aimbs_get16(bs)))		msg = aimbs_getstr(bs, tmp);	else		msg = NULL;	/* Unknown */	tmp = aimbs_get16(bs);	if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))		ret = userfunc(sess, rx, sn, reply, msg);	free(sn);	free(msg);	return ret;}/* * Subtype 0x001c - Receive a message telling you someone added you to their list. */static int receiveadded(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;	char *sn;	/* Read screen name */	if ((tmp = aimbs_get8(bs)))		sn = aimbs_getstr(bs, tmp);	else		sn = NULL;	if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))		ret = userfunc(sess, rx, sn);	free(sn);	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 == AIM_CB_SSI_RIGHTSINFO)		return parserights(sess, mod, rx, snac, bs);	else if (snac->subtype == AIM_CB_SSI_LIST)		return parsedata(sess, mod, rx, snac, bs);	else if (snac->subtype == AIM_CB_SSI_ADD)		return parseadd(sess, mod, rx, snac, bs);	else if (snac->subtype == AIM_CB_SSI_MOD)		return parsemod(sess, mod, rx, snac, bs);	else if (snac->subtype == AIM_CB_SSI_DEL)		return parsedel(sess, mod, rx, snac, bs);	else if (snac->subtype == AIM_CB_SSI_SRVACK)		return parseack(sess, mod, rx, snac, bs);	else if (snac->subtype == AIM_CB_SSI_NOLIST)		return parsedataunchanged(sess, mod, rx, snac, bs);	else if (snac->subtype == AIM_CB_SSI_RECVAUTH)		return receiveauthgrant(sess, mod, rx, snac, bs);	else if (snac->subtype == AIM_CB_SSI_RECVAUTHREQ)		return receiveauthrequest(sess, mod, rx, snac, bs);	else if (snac->subtype == AIM_CB_SSI_RECVAUTHREP)		return receiveauthreply(sess, mod, rx, snac, bs);	else if (snac->subtype == AIM_CB_SSI_ADDED)		return receiveadded(sess, mod, rx, snac, bs);	return 0;}static void ssi_shutdown(aim_session_t *sess, aim_module_t *mod){	aim_ssi_freelist(sess);}faim_internal int ssi_modfirst(aim_session_t *sess, aim_module_t *mod){	mod->family = AIM_CB_FAM_SSI;	mod->version = 0x0004;	mod->toolid = 0x0110;	mod->toolversion = 0x0629;	mod->flags = 0;	strncpy(mod->name, "ssi", sizeof(mod->name));	mod->snachandler = snachandler;	mod->shutdown = ssi_shutdown;	return 0;}

⌨️ 快捷键说明

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