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

📄 ssi.c

📁 oscar message protocol stack
💻 C
📖 第 1 页 / 共 4 页
字号:
				} else					sess->ssi.pending = new;			}		}	}	/* Deletions */	if (!sess->ssi.pending) {		for (cur1=sess->ssi.official; cur1; cur1=cur1->next) {			if (!aim_ssi_itemlist_find(sess->ssi.local, cur1->gid, cur1->bid)) {				new = (struct aim_ssi_tmp *)malloc(sizeof(struct aim_ssi_tmp));				new->action = AIM_CB_SSI_DEL;				new->ack = 0xffff;				new->name = NULL;				new->item = cur1;				new->next = NULL;				if (sess->ssi.pending) {					for (cur=sess->ssi.pending; cur->next; cur=cur->next);					cur->next = new;				} else					sess->ssi.pending = new;			}		}	}	/* Modifications */	if (!sess->ssi.pending) {		for (cur1=sess->ssi.local; cur1; cur1=cur1->next) {			cur2 = aim_ssi_itemlist_find(sess->ssi.official, cur1->gid, cur1->bid);			if (cur2 && (aim_ssi_itemlist_cmp(cur1, cur2))) {				new = (struct aim_ssi_tmp *)malloc(sizeof(struct aim_ssi_tmp));				new->action = AIM_CB_SSI_MOD;				new->ack = 0xffff;				new->name = NULL;				new->item = cur1;				new->next = NULL;				if (sess->ssi.pending) {					for (cur=sess->ssi.pending; cur->next; cur=cur->next);					cur->next = new;				} else					sess->ssi.pending = new;			}		}	}	/* We're out of stuff to do, so tell the AIM servers we're done and exit */	if (!sess->ssi.pending) {		aim_ssi_modend(sess);		return 0;	}	/* Make sure we don't send anything else between now 	 * and when we receive the ack for the following operation */	sess->ssi.waiting_for_ack = 1;	/* Now go mail off our data and wait 4 to 6 weeks */	aim_ssi_addmoddel(sess);	return 0;}/** * Free all SSI data. * * This doesn't remove it from the server, that's different. * * @param sess The oscar session. * @return Return 0 if no errors, otherwise return the error number. */static int aim_ssi_freelist(aim_session_t *sess){	struct aim_ssi_item *cur, *del;	struct aim_ssi_tmp *curtmp, *deltmp;	cur = sess->ssi.official;	while (cur) {		del = cur;		cur = cur->next;		free(del->name);		aim_tlvlist_free(&del->data);		free(del);	}	cur = sess->ssi.local;	while (cur) {		del = cur;		cur = cur->next;		free(del->name);		aim_tlvlist_free(&del->data);		free(del);	}	curtmp = sess->ssi.pending;	while (curtmp) {		deltmp = curtmp;		curtmp = curtmp->next;		free(deltmp);	}	sess->ssi.numitems = 0;	sess->ssi.official = NULL;	sess->ssi.local = NULL;	sess->ssi.pending = NULL;	sess->ssi.timestamp = (time_t)0;	return 0;}/** * Delete all SSI data. * * @param sess The oscar session. * @return Return 0 if no errors, otherwise return the error number. */faim_export int aim_ssi_deletelist(aim_session_t *sess){	struct aim_ssi_item *cur, *del;	if (!sess)		return -EINVAL;	/* Free the local list */	cur = sess->ssi.local;	while (cur) {		del = cur;		cur = cur->next;		free(del->name);		aim_tlvlist_free(&del->data);		free(del);	}	sess->ssi.local = NULL;	/* Sync our local list with the server list */	aim_ssi_sync(sess);	return 0;}/** * This "cleans" the ssi list.  It does the following: * 1) Makes sure all buddies, permits, and denies have names. * 2) Makes sure that all buddies are in a group that exist. * 3) Deletes any empty groups * * @param sess The oscar session. * @return Return 0 if no errors, otherwise return the error number. */faim_export int aim_ssi_cleanlist(aim_session_t *sess){	struct aim_ssi_item *cur, *next;	if (!sess)		return -EINVAL;	/* Delete any buddies, permits, or denies with empty names. */	/* If there are any buddies directly in the master group, add them to a real group. */	/* DESTROY any buddies that are directly in the master group. */	/* Do the same for buddies that are in a non-existant group. */	/* This will kind of mess up if you hit the item limit, but this function isn't too critical */	cur = sess->ssi.local;	while (cur) {		next = cur->next;		if (!cur->name) {			if (cur->type == AIM_SSI_TYPE_BUDDY)				aim_ssi_delbuddy(sess, NULL, NULL);			else if (cur->type == AIM_SSI_TYPE_PERMIT)				aim_ssi_delpermit(sess, NULL);			else if (cur->type == AIM_SSI_TYPE_DENY)				aim_ssi_deldeny(sess, NULL);		} else if ((cur->type == AIM_SSI_TYPE_BUDDY) && ((cur->gid == 0x0000) || (!aim_ssi_itemlist_find(sess->ssi.local, cur->gid, 0x0000)))) {			aim_ssi_addbuddy(sess, cur->name, "orphans", NULL, NULL, NULL, 0);			aim_ssi_delbuddy(sess, cur->name, NULL);		}		cur = next;	}	/* Check if there are empty groups and delete them */	cur = sess->ssi.local;	while (cur) {		next = cur->next;		if (cur->type == AIM_SSI_TYPE_GROUP) {			aim_tlv_t *tlv = aim_tlv_gettlv(cur->data, 0x00c8, 1);			if (!tlv || !tlv->length)				aim_ssi_itemlist_del(&sess->ssi.local, cur);		}		cur = next;	}	/* Check if the master group is empty */	if ((cur = aim_ssi_itemlist_find(sess->ssi.local, 0x0000, 0x0000)) && (!cur->data))		aim_ssi_itemlist_del(&sess->ssi.local, cur);	return 0;}/** * Add a buddy to the list. * * @param sess The oscar session. * @param name The name of the item. * @param group The group of the item. * @param alias The alias/nickname of the item, or NULL. * @param comment The buddy comment for the item, or NULL. * @param smsnum The locally assigned SMS number, or NULL. * @return Return 0 if no errors, otherwise return the error number. */faim_export int aim_ssi_addbuddy(aim_session_t *sess, const char *name, const char *group, const char *alias, const char *comment, const char *smsnum, int needauth){	struct aim_ssi_item *parent;	aim_tlvlist_t *data = NULL;	if (!sess || !name || !group)		return -EINVAL;	/* Find the parent */	if (!(parent = aim_ssi_itemlist_finditem(sess->ssi.local, group, NULL, AIM_SSI_TYPE_GROUP))) {		/* Find the parent's parent (the master group) */		if (!(parent = aim_ssi_itemlist_find(sess->ssi.local, 0x0000, 0x0000)))			if (!(parent = aim_ssi_itemlist_add(&sess->ssi.local, NULL, 0x0000, 0x0000, AIM_SSI_TYPE_GROUP, NULL)))				return -ENOMEM;		/* Add the parent */		if (!(parent = aim_ssi_itemlist_add(&sess->ssi.local, group, 0xFFFF, 0x0000, AIM_SSI_TYPE_GROUP, NULL)))			return -ENOMEM;		/* Modify the parent's parent (the master group) */		aim_ssi_itemlist_rebuildgroup(sess->ssi.local, NULL);	}	/* Create a TLV list for the new buddy */	if (needauth)		aim_tlvlist_add_noval(&data, 0x0066);	if (alias)		aim_tlvlist_add_raw(&data, 0x0131, strlen(alias), alias);	if (smsnum)		aim_tlvlist_add_raw(&data, 0x013a, strlen(smsnum), smsnum);	if (comment)		aim_tlvlist_add_raw(&data, 0x013c, strlen(comment), comment);	/* Add that bad boy */	aim_ssi_itemlist_add(&sess->ssi.local, name, parent->gid, 0xFFFF, AIM_SSI_TYPE_BUDDY, data);	aim_tlvlist_free(&data);	/* Modify the parent group */	aim_ssi_itemlist_rebuildgroup(sess->ssi.local, group);	/* Sync our local list with the server list */	aim_ssi_sync(sess);	return 0;}/** * Add a permit buddy to the list. * * @param sess The oscar session. * @param name The name of the item.. * @return Return 0 if no errors, otherwise return the error number. */faim_export int aim_ssi_addpermit(aim_session_t *sess, const char *name){	if (!sess || !name)		return -EINVAL;	/* Add that bad boy */	aim_ssi_itemlist_add(&sess->ssi.local, name, 0x0000, 0xFFFF, AIM_SSI_TYPE_PERMIT, NULL);	/* Sync our local list with the server list */	aim_ssi_sync(sess);	return 0;}/** * Add a deny buddy to the list. * * @param sess The oscar session. * @param name The name of the item.. * @return Return 0 if no errors, otherwise return the error number. */faim_export int aim_ssi_adddeny(aim_session_t *sess, const char *name){	if (!sess || !name)		return -EINVAL;	/* Add that bad boy */	aim_ssi_itemlist_add(&sess->ssi.local, name, 0x0000, 0xFFFF, AIM_SSI_TYPE_DENY, NULL);	/* Sync our local list with the server list */	aim_ssi_sync(sess);	return 0;}/** * Deletes a buddy from the list. * * @param sess The oscar session. * @param name The name of the item, or NULL. * @param group The group of the item, or NULL. * @return Return 0 if no errors, otherwise return the error number. */faim_export int aim_ssi_delbuddy(aim_session_t *sess, const char *name, const char *group){	struct aim_ssi_item *del;	if (!sess)		return -EINVAL;	/* Find the buddy */	if (!(del = aim_ssi_itemlist_finditem(sess->ssi.local, group, name, AIM_SSI_TYPE_BUDDY)))		return -EINVAL;	/* Remove the item from the list */	aim_ssi_itemlist_del(&sess->ssi.local, del);	/* Modify the parent group */	aim_ssi_itemlist_rebuildgroup(sess->ssi.local, group);	/* Check if we should delete the parent group */	if ((del = aim_ssi_itemlist_finditem(sess->ssi.local, group, NULL, AIM_SSI_TYPE_GROUP)) && (!del->data)) {		aim_ssi_itemlist_del(&sess->ssi.local, del);		/* Modify the parent group */		aim_ssi_itemlist_rebuildgroup(sess->ssi.local, NULL);		/* Check if we should delete the parent's parent (the master group) */		if ((del = aim_ssi_itemlist_find(sess->ssi.local, 0x0000, 0x0000)) && (!del->data)) {			aim_ssi_itemlist_del(&sess->ssi.local, del);		}	}	/* Sync our local list with the server list */	aim_ssi_sync(sess);	return 0;}/** * Deletes a permit buddy from the list. * * @param sess The oscar session. * @param name The name of the item, or NULL. * @return Return 0 if no errors, otherwise return the error number. */faim_export int aim_ssi_delpermit(aim_session_t *sess, const char *name){	struct aim_ssi_item *del;	if (!sess)		return -EINVAL;	/* Find the item */	if (!(del = aim_ssi_itemlist_finditem(sess->ssi.local, NULL, name, AIM_SSI_TYPE_PERMIT)))		return -EINVAL;	/* Remove the item from the list */	aim_ssi_itemlist_del(&sess->ssi.local, del);	/* Sync our local list with the server list */	aim_ssi_sync(sess);	return 0;}/** * Deletes a deny buddy from the list. * * @param sess The oscar session. * @param name The name of the item, or NULL. * @return Return 0 if no errors, otherwise return the error number. */faim_export int aim_ssi_deldeny(aim_session_t *sess, const char *name){	struct aim_ssi_item *del;	if (!sess)		return -EINVAL;	/* Find the item */	if (!(del = aim_ssi_itemlist_finditem(sess->ssi.local, NULL, name, AIM_SSI_TYPE_DENY)))		return -EINVAL;	/* Remove the item from the list */	aim_ssi_itemlist_del(&sess->ssi.local, del);	/* Sync our local list with the server list */	aim_ssi_sync(sess);	return 0;}/** * Move a buddy from one group to another group.  This basically just deletes the  * buddy and re-adds it. * * @param sess The oscar session. * @param oldgn The group that the buddy is currently in. * @param newgn The group that the buddy should be moved in to. * @param sn The name of the buddy to be moved. * @return Return 0 if no errors, otherwise return the error number. */faim_export int aim_ssi_movebuddy(aim_session_t *sess, const char *oldgn, const char *newgn, const char *sn){	aim_ssi_addbuddy(sess, sn, newgn, aim_ssi_getalias(sess->ssi.local, oldgn, sn), NULL, NULL, aim_ssi_waitingforauth(sess->ssi.local, oldgn, sn));	aim_ssi_delbuddy(sess, sn, oldgn);	return 0;}/** * Change the alias stored on the server for a given buddy. * * @param sess The oscar session. * @param gn The group that the buddy is currently in. * @param sn The screen name of the buddy. * @param alias The new alias for the buddy, or NULL if you want to remove  *        a buddy's comment. * @return Return 0 if no errors, otherwise return the error number. */faim_export int aim_ssi_aliasbuddy(aim_session_t *sess, const char *gn, const char *sn, const char *alias){	struct aim_ssi_item *tmp;	if (!sess || !gn || !sn)		return -EINVAL;	if (!(tmp = aim_ssi_itemlist_finditem(sess->ssi.local, gn, sn, AIM_SSI_TYPE_BUDDY)))		return -EINVAL;	/* Either add or remove the 0x0131 TLV from the TLV chain */	if ((alias != NULL) && (strlen(alias) > 0))		aim_tlvlist_replace_raw(&tmp->data, 0x0131, strlen(alias), alias);	else		aim_tlvlist_remove(&tmp->data, 0x0131);	/* Sync our local list with the server list */	aim_ssi_sync(sess);	return 0;}/** * Change the comment stored on the server for a given buddy. * * @param sess The oscar session. * @param gn The group that the buddy is currently in. * @param sn The screen name of the buddy. * @param alias The new comment for the buddy, or NULL if you want to remove  *        a buddy's comment. * @return Return 0 if no errors, otherwise return the error number. */faim_export int aim_ssi_editcomment(aim_session_t *sess, const char *gn, const char *sn, const char *comment){	struct aim_ssi_item *tmp;	if (!sess || !gn || !sn)		return -EINVAL;	if (!(tmp = aim_ssi_itemlist_finditem(sess->ssi.local, gn, sn, AIM_SSI_TYPE_BUDDY)))		return -EINVAL;	/* Either add or remove the 0x0131 TLV from the TLV chain */	if ((comment != NULL) && (strlen(comment) > 0))		aim_tlvlist_replace_raw(&tmp->data, 0x013c, strlen(comment), comment);	else		aim_tlvlist_remove(&tmp->data, 0x013c);	/* Sync our local list with the server list */	aim_ssi_sync(sess);	return 0;}/** * Rename a group. * * @param sess The oscar session. * @param oldgn The old group name. * @param newgn The new group name. * @return Return 0 if no errors, otherwise return the error number. */faim_export int aim_ssi_rename_group(aim_session_t *sess, const char *oldgn, const char *newgn){	struct aim_ssi_item *group;	if (!sess || !oldgn || !newgn)		return -EINVAL;	if (!(group = aim_ssi_itemlist_finditem(sess->ssi.local, oldgn, NULL, AIM_SSI_TYPE_GROUP)))		return -EINVAL;

⌨️ 快捷键说明

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