[ekg2-commit] r3879 - in trunk: ekg plugins/gg plugins/jabber: trunk/ekg/protocol.c trunk/ekg/protocol.h trunk/plugins/gg/dcc.c trunk/plugins/jabber/jabber_dcc.c

SVN commit svn w toxygen.net
Nie, 9 Mar 2008, 14:04:21 CET


Author: peres
Date: 2008-03-09 14:04:20 +0100 (Sun, 09 Mar 2008)
New Revision: 3879

Modified:
   trunk/ekg/protocol.c
   trunk/ekg/protocol.h
   trunk/plugins/gg/dcc.c
   trunk/plugins/jabber/jabber_dcc.c
Log:

DCC to list3.



Modified: trunk/ekg/protocol.c
===================================================================
--- trunk/ekg/protocol.c	2008-03-09 12:29:56 UTC (rev 3878)
+++ trunk/ekg/protocol.c	2008-03-09 13:04:20 UTC (rev 3879)
@@ -53,7 +53,7 @@
 #include "queries.h"
 
 static int auto_find_limit = 100; /* counter of persons who we were looking for when autofind */
-list_t dccs = NULL;
+dcc_t *dccs = NULL;
 
 static QUERY(protocol_disconnected);
 static QUERY(protocol_connected);
@@ -906,14 +906,11 @@
 dcc_t *dcc_add(session_t *session, const char *uid, dcc_type_t type, void *priv) {
 	dcc_t *d;
 	int id = 1, id_ok;
-	list_t l;
 
 	do {
 		id_ok = 1;
 
-		for (l = dccs; l; l = l->next) {
-			dcc_t *d = l->data;
-	
+		for (d = dccs; d; d = d->next) {
 			if (d->id == id) {
 				id++;
 				id_ok = 0;
@@ -934,24 +931,26 @@
 	d->started = time(NULL);
 	d->id = id;
 
-	list_add(&dccs, d);
+	LIST_ADD2(&dccs, d);
 
 	return d;
 }
 
+static LIST_FREE_ITEM(dcc_free_item, dcc_t *) {
+	if (data->close_handler)
+		data->close_handler(data);
+
+	xfree(data->uid);
+	xfree(data->filename);
+}
+
 int dcc_close(dcc_t *d)
 {
 	if (!d)
 		return -1;
 
-	if (d->close_handler)
-		d->close_handler(d);
+	LIST_REMOVE2(&dccs, d, dcc_free_item);
 
-	xfree(d->uid);
-	xfree(d->filename);
-
-	list_remove(&dccs, d, 1);
-
 	return 0;
 }
 

Modified: trunk/ekg/protocol.h
===================================================================
--- trunk/ekg/protocol.h	2008-03-09 12:29:56 UTC (rev 3878)
+++ trunk/ekg/protocol.h	2008-03-09 13:04:20 UTC (rev 3879)
@@ -96,6 +96,8 @@
 typedef void (*dcc_close_handler_t)(struct dcc_s *);
 
 typedef struct dcc_s {
+	struct dcc_s	*next;
+
 	session_t	*session;		/* ktora sesja? */
 	char		*uid;			/* z kim połączenie */
 	dcc_type_t	type;			/* rodzaj połączenia */
@@ -131,7 +133,7 @@
 const char *dcc_filename_get(dcc_t *);
 dcc_type_t dcc_type_get(dcc_t *);
 
-extern list_t dccs;
+extern dcc_t *dccs;
 
 #endif
 

Modified: trunk/plugins/gg/dcc.c
===================================================================
--- trunk/plugins/gg/dcc.c	2008-03-09 12:29:56 UTC (rev 3878)
+++ trunk/plugins/gg/dcc.c	2008-03-09 13:04:20 UTC (rev 3879)
@@ -86,9 +86,8 @@
 		}
 		va_end(ap);
 		{ 
-			list_t l;
-			for (l = dccs; l; l = l->next) {
-				dcc_t *d = l->data;
+			dcc_t *d;
+			for (d = dccs; d; d = d->next) {
 				if (d->id == dccid) {
 					priv->dcc = d;
 					break;
@@ -481,7 +480,7 @@
 	
 	/* get, resume */
 	if (params[0] && (!xstrncasecmp(params[0], "g", 1) || !xstrncasecmp(params[0], "re", 2))) {
-		dcc_t *d = NULL;
+		dcc_t *d = NULL, *D;
 		struct gg_common *g;
 		char *path;
 		list_t l;
@@ -489,8 +488,7 @@
 		int fd;
 		unsigned int offset = 0;
 		
-		for (l = dccs; l; l = l->next) {
-			dcc_t *D = l->data;
+		for (D = dccs; D; D = D->next) {
 			userlist_t *u;
 
 			if (!dcc_private_get(D) || !dcc_filename_get(D) || dcc_type_get(D) != DCC_GET)
@@ -634,11 +632,9 @@
  */
 dcc_t *gg_dcc_find(void *d)
 {
-	list_t l;
+	dcc_t *D;
 
-	for (l = dccs; l; l = l->next) {
-		dcc_t *D = l->data;
-
+	for (D = dccs; D; D = D->next) {
 		if (D && D->priv == d)
 			return D;
 	}
@@ -766,7 +762,7 @@
 	struct gg_event *e;
 	struct gg_dcc *d = data;
 	int again = 1;
-	list_t l;
+	dcc_t *D;
 
 	if (type != 0)
 		return 0;
@@ -858,15 +854,12 @@
 		{
 			int found = 0;
 			char peer[16];
-			list_t l;
 			
 			debug("[gg] GG_EVENT_DCC_CALLBACK\n");
 
 			snprintf(peer, sizeof(peer), "gg:%d", d->peer_uin);
 			
-			for (l = dccs; l; l = l->next) {
-				dcc_t *D = l->data;
-
+			for (D = dccs; D; D = D->next) {
 				debug("[gg] dcc id=%d, uid=%d, type=%d\n", dcc_id_get(D), dcc_uid_get(D), dcc_type_get(D));
 
 				if (!xstrcmp(dcc_uid_get(D), peer) && !dcc_private_get(D)) {
@@ -892,13 +885,9 @@
 
 		case GG_EVENT_DCC_NEED_FILE_INFO:
 		{
-			list_t l;
-
 			debug("[gg] GG_EVENT_DCC_NEED_FILE_INFO\n");
 
-			for (l = dccs; l; l = l->next) {
-				dcc_t *D = l->data;
-
+			for (D = dccs; D; D = D->next) {
 				if (dcc_private_get(D) != d)
 					continue;
 
@@ -922,7 +911,6 @@
 			char *path, *p;
 			char uin[16];
 			struct stat st;
-			dcc_t *D;
 
 			debug("[gg] GG_EVENT_DCC_NEED_FILE_ACK\n");
 		        snprintf(uin, sizeof(uin), "gg:%d", d->uin);
@@ -999,7 +987,6 @@
 			break;
 		case GG_EVENT_DCC_DONE:
 		{
-			dcc_t *D;
 			char uin[16];
 
 			debug("[gg] GG_EVENT_DCC_DONE\n");
@@ -1079,9 +1066,7 @@
 	}
 
 	/* uaktualnij statystyki */
-	for (l = dccs; l; l = l->next) {
-		dcc_t *D = l->data;
-
+	for (D = dccs; D; D = D->next) {
 		if (dcc_private_get(D) != d)
 			continue;
 

Modified: trunk/plugins/jabber/jabber_dcc.c
===================================================================
--- trunk/plugins/jabber/jabber_dcc.c	2008-03-09 12:29:56 UTC (rev 3878)
+++ trunk/plugins/jabber/jabber_dcc.c	2008-03-09 13:04:20 UTC (rev 3879)
@@ -213,11 +213,10 @@
 		char req[47];
 
 		dcc_t *d = NULL;
-		list_t l;
+		dcc_t *D;
 		int i;
 
-		for (l=dccs; l; l = l->next) {
-			dcc_t *D	= l->data;
+		for (D=dccs; D; D = D->next) {
 			jabber_dcc_t *p = D->priv;
 
 			char *this_sha1;
@@ -377,11 +376,10 @@
 
 dcc_t *jabber_dcc_find(const char *uin, /* without xmpp: */ const char *id, const char *sid) {
 #define DCC_RULE(x) (!xstrncmp(x->uid, "xmpp:", 5) && !xstrcmp(x->uid+5, uin))
-	list_t l;
+	dcc_t *d;
 	if (!id && !sid) { debug_error("jabber_dcc_find() neither id nor sid passed.. Returning NULL\n"); return NULL; }
 
-	for (l = dccs; l; l = l->next) {
-		dcc_t *d = l->data;
+	for (d = dccs; d; d = d->next) {
 		jabber_dcc_t *p = d->priv;
 
 		if (DCC_RULE(d) && (!sid || !xstrcmp(p->sid, sid)) && (!id || !xstrcmp(p->req, id))) {



Więcej informacji o liście dyskusyjnej ekg2-commit