[ekg2-commit] r3864 - trunk/ekg: trunk/ekg/msgqueue.c trunk/ekg/msgqueue.h trunk/ekg/plugins.h

SVN commit svn w toxygen.net
Sob, 8 Mar 2008, 20:00:36 CET


Author: peres
Date: 2008-03-08 20:00:36 +0100 (Sat, 08 Mar 2008)
New Revision: 3864

Modified:
   trunk/ekg/msgqueue.c
   trunk/ekg/msgqueue.h
   trunk/ekg/plugins.h
Log:

Now msgqueue, and optimize it a bit.

XXX: add its' support to jabber.



Modified: trunk/ekg/msgqueue.c
===================================================================
--- trunk/ekg/msgqueue.c	2008-03-08 18:38:02 UTC (rev 3863)
+++ trunk/ekg/msgqueue.c	2008-03-08 19:00:36 UTC (rev 3864)
@@ -38,7 +38,7 @@
 #include "stuff.h"
 #include "xmalloc.h"
 
-list_t msg_queue = NULL;
+msg_queue_t *msg_queue = NULL;
 
 /*
  * msg_queue_add()
@@ -62,7 +62,7 @@
 	m->seq 		= xstrdup(seq);
 	m->time 	= time(NULL);
 
-	return (list_add(&msg_queue, m) ? 0 : -1);
+	return (LIST_ADD2(&msg_queue, m) ? 0 : -1);
 }
 
 static LIST_FREE_ITEM(list_msg_queue_free, msg_queue_t *) {
@@ -70,7 +70,6 @@
 	xfree(data->rcpts);
 	xfree(data->message);
 	xfree(data->seq);
-	xfree(data);
 }
 
 /*
@@ -85,18 +84,18 @@
  */
 int msg_queue_remove_uid(const char *uid)
 {
-	list_t l;
+	msg_queue_t *m;
 	int res = -1;
 
-	for (l = msg_queue; l; ) {
-		msg_queue_t *m = l->data;
+	for (m = msg_queue; m; ) {
+		msg_queue_t *next = m->next;
 
-		l = l->next;
-
 		if (!xstrcasecmp(m->rcpts, uid)) {
-			LIST_REMOVE(&msg_queue, m, list_msg_queue_free);
+			LIST_REMOVE2(&msg_queue, m, list_msg_queue_free);
 			res = 0;
 		}
+
+		m = next;
 	}
 
 	return res;
@@ -114,20 +113,20 @@
 int msg_queue_remove_seq(const char *seq)
 {
 	int res = -1;
-	list_t l;
+	msg_queue_t *m;
 
 	if (!seq) 
 		return -1;
 
-	for (l = msg_queue; l; ) {
-		msg_queue_t *m = l->data;
+	for (m = msg_queue; m; ) {
+		msg_queue_t *next = m->next;
 
-		l = l->next;
-
 		if (!xstrcasecmp(m->seq, seq)) {
-			LIST_REMOVE(&msg_queue, m, list_msg_queue_free);
+			LIST_REMOVE2(&msg_queue, m, list_msg_queue_free);
 			res = 0;
 		}
+
+		m = next;
 	}
 
 	return res;
@@ -139,7 +138,7 @@
  * zwalnia pamięć po kolejce wiadomości.
  */
 void msg_queue_free() {
-	LIST_DESTROY(msg_queue, list_msg_queue_free);
+	LIST_DESTROY2(msg_queue, list_msg_queue_free);
 	msg_queue = NULL;
 }
 
@@ -153,45 +152,41 @@
  */
 int msg_queue_flush(const char *session)
 {
-	list_t l;
-	int sent = 0;
+	msg_queue_t *m;
+	int ret = -1;
 
 	if (!msg_queue)
 		return -2;
 
-	for (l = msg_queue; l; l = l->next) {
-		msg_queue_t *m = l->data;
-
+	for (m = msg_queue; m; m = m->next)
 		m->mark = 1;
-	}
 
-	for (l = msg_queue; l;) {
-		msg_queue_t *m = l->data;
+	for (m = msg_queue; m;) {
 		session_t *s;
+		msg_queue_t *next = m->next;
 
-		l = l->next;
-
 		/* czy wiadomość dodano w trakcie opróżniania kolejki? */
 		if (!m->mark)
 			continue;
 
-		/* wiadomość wysyłana z nieistniejącej już sesji? usuwamy. */
-		if (!(s = session_find(m->session))) {
-			LIST_REMOVE(&msg_queue, m, list_msg_queue_free);
-			continue;
-		}
 
 		if (session && xstrcmp(m->session, session)) 
 			continue;
+				/* wiadomość wysyłana z nieistniejącej już sesji? usuwamy. */
+		else if (!(s = session_find(m->session))) {
+			LIST_REMOVE2(&msg_queue, m, list_msg_queue_free);
+			continue;
+		}
 
 		command_exec_format(NULL, s, 1, ("/msg \"%s\" %s"), m->rcpts, m->message);
 
-		LIST_REMOVE(&msg_queue, m, list_msg_queue_free);
+		LIST_REMOVE2(&msg_queue, m, list_msg_queue_free);
 
-		sent = 1;
+		ret = 0;
+		m = next;
 	}
 
-	return (sent) ? 0 : -1;
+	return ret;
 }
 
 /*
@@ -203,12 +198,10 @@
  */
 int msg_queue_count_session(const char *uid)
 {
-	list_t l;
+	msg_queue_t *m;
 	int count = 0;
 
-	for (l = msg_queue; l; l = l->next) {
-		msg_queue_t *m = l->data;
-
+	for (m = msg_queue; m; m = m->next) {
 		if (!xstrcasecmp(m->session, uid))
 			count++;
 	}
@@ -225,7 +218,7 @@
  */
 int msg_queue_write()
 {
-	list_t l;
+	msg_queue_t *m;
 	int num = 0;
 
 	if (!msg_queue)
@@ -234,8 +227,7 @@
 	if (mkdir_recursive(prepare_pathf("queue"), 1))		/* create ~/.ekg2/[PROFILE/]queue/ */
 		return -1;
 
-	for (l = msg_queue; l; l = l->next) {
-		msg_queue_t *m = l->data;
+	for (m = msg_queue; m; m = m->next) {
 		const char *fn;
 		FILE *f;
 
@@ -341,7 +333,7 @@
 
 		m.message = string_free(msg, 0);
 
-		list_add(&msg_queue, xmemdup(&m, sizeof(m)));
+		LIST_ADD2(&msg_queue, xmemdup(&m, sizeof(m)));
 
 		fclose(f);
 		unlink(fn);

Modified: trunk/ekg/msgqueue.h
===================================================================
--- trunk/ekg/msgqueue.h	2008-03-08 18:38:02 UTC (rev 3863)
+++ trunk/ekg/msgqueue.h	2008-03-08 19:00:36 UTC (rev 3864)
@@ -26,7 +26,9 @@
 
 #include "dynstuff.h"
 
-typedef struct {
+typedef struct msg_queue {
+	struct msg_queue	*next;
+
 	char		*session;		/* do której sesji należy */
 	char		*rcpts;			/* uidy odbiorców */
 	char		*message;		/* treść */
@@ -35,7 +37,7 @@
 	unsigned int	mark		: 1;	/* if added during cleanup */
 } msg_queue_t;
 
-extern list_t msg_queue;
+extern msg_queue_t *msg_queue;
 
 int msg_queue_add(const char *session, const char *rcpts, const char *message, const char *seq);
 void msg_queue_free();

Modified: trunk/ekg/plugins.h
===================================================================
--- trunk/ekg/plugins.h	2008-03-08 18:38:02 UTC (rev 3863)
+++ trunk/ekg/plugins.h	2008-03-08 19:00:36 UTC (rev 3864)
@@ -26,7 +26,7 @@
 #include "dynstuff.h"
 #include "sessions.h"
 
-#define EKG_ABI_VER 3862
+#define EKG_ABI_VER 3864
 
 #define EXPORT __attribute__ ((visibility("default")))
 



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