[ekg2-commit] r3883 - in trunk: ekg plugins/mail plugins/perl/common: trunk/ekg/commands.c trunk/ekg/configfile.c trunk/ekg/ekg.c trunk/ekg/plugins.c trunk/ekg/plugins.h trunk/ekg/sessions.c trunk/ekg/stuff.c trunk/ekg/stuff.h trunk/plugins/mail/main.c trunk/plugins/perl/common/Command.xs trunk/plugins/perl/common/Plugin.xs trunk/plugins/perl/common/Timer.xs trunk/plugins/perl/common/Variable.xs trunk/plugins/perl/common/Watch.xs

SVN commit svn w toxygen.net
Nie, 9 Mar 2008, 21:27:24 CET


Author: peres
Date: 2008-03-09 21:27:23 +0100 (Sun, 09 Mar 2008)
New Revision: 3883

Modified:
   trunk/ekg/commands.c
   trunk/ekg/configfile.c
   trunk/ekg/ekg.c
   trunk/ekg/plugins.c
   trunk/ekg/plugins.h
   trunk/ekg/sessions.c
   trunk/ekg/stuff.c
   trunk/ekg/stuff.h
   trunk/plugins/mail/main.c
   trunk/plugins/perl/common/Command.xs
   trunk/plugins/perl/common/Plugin.xs
   trunk/plugins/perl/common/Timer.xs
   trunk/plugins/perl/common/Variable.xs
   trunk/plugins/perl/common/Watch.xs
Log:

Timers.



Modified: trunk/ekg/commands.c
===================================================================
--- trunk/ekg/commands.c	2008-03-09 18:15:38 UTC (rev 3882)
+++ trunk/ekg/commands.c	2008-03-09 20:27:23 UTC (rev 3883)
@@ -2948,7 +2948,7 @@
 
 static COMMAND(cmd_at)
 {
-	list_t l;
+	struct timer *t;
 
 	if (match_arg(params[0], 'a', ("add"), 2)) {
 		const char *p, *a_name = NULL;
@@ -2969,9 +2969,7 @@
 				return -1;
 			}
 
-			for (l = timers; l; l = l->next) {
-				t = l->data;
-
+			for (t = timers; t; t = t->next) {
 				if (!xstrcasecmp(t->name, a_name)) {
 					printq("at_exist", a_name);
 					return -1;
@@ -3180,8 +3178,7 @@
 		else if (params[0])
 			a_name = params[0];
 
-		for (l = timers; l; l = l->next) {
-			struct timer *t = l->data;
+		for (t = timers; t; t = t->next) {
 			struct timeval tv;
 			struct tm *at_time;
 			char tmp[100], tmp2[150];
@@ -3264,7 +3261,7 @@
 
 static COMMAND(cmd_timer)
 {
-	list_t l;
+	struct timer *t;
 
 	if (match_arg(params[0], 'a', ("add"), 2)) {
 		const char *t_name = NULL, *p;
@@ -3286,9 +3283,7 @@
 				return -1;
 			}
 
-			for (l = timers; l; l = l->next) {
-				t = l->data;
-
+			for (t = timers; t; t = t->next) {
 				if (!t->at && !xstrcasecmp(t->name, t_name)) {
 					printq("timer_exist", t_name);
 					return -1;
@@ -3402,8 +3397,7 @@
 		else if (params[0])
 			t_name = params[0];
 
-		for (l = timers; l; l = l->next) {
-			struct timer *t = l->data;
+		for (t = timers; t; t = t->next) {
 			struct timeval tv;
 			char *tmp;
 			long usec, sec, minutes = 0, hours = 0, days = 0;

Modified: trunk/ekg/configfile.c
===================================================================
--- trunk/ekg/configfile.c	2008-03-09 18:15:38 UTC (rev 3882)
+++ trunk/ekg/configfile.c	2008-03-09 20:27:23 UTC (rev 3883)
@@ -428,45 +428,48 @@
                 fprintf(f, "bind-set %s %s\n", d->binding->key, d->sequence);
         }
 
-	for (l = timers; l; l = l->next) {
-		struct timer *t = l->data;
-		const char *name = NULL;
+	{
+		struct timer *t;
 
-		if (t->function != timer_handle_command)
-			continue;
+		for (t = timers; t; t = t->next) {
+			const char *name = NULL;
 
-		/* nie ma sensu zapisywać */
-		if (!t->persist && t->ends.tv_sec - time(NULL) < 5)
-			continue;
+			if (t->function != timer_handle_command)
+				continue;
 
-		/* posortuje, jeśli nie ma nazwy */
-		if (t->name && !xisdigit(t->name[0]))
-			name = t->name;
-		else
-			name = "(null)";
+			/* nie ma sensu zapisywać */
+			if (!t->persist && t->ends.tv_sec - time(NULL) < 5)
+				continue;
 
-		if (t->at) {
-			char buf[100];
-			time_t foo = (time_t) t->ends.tv_sec;
-			struct tm *tt = localtime(&foo);
+			/* posortuje, jeśli nie ma nazwy */
+			if (t->name && !xisdigit(t->name[0]))
+				name = t->name;
+			else
+				name = "(null)";
 
-			strftime(buf, sizeof(buf), "%G%m%d%H%M.%S", tt);
+			if (t->at) {
+				char buf[100];
+				time_t foo = (time_t) t->ends.tv_sec;
+				struct tm *tt = localtime(&foo);
 
-			if (t->persist)
-				fprintf(f, "at %s %s/%s %s\n", name, buf, itoa(t->period), (char*)(t->data));
-			else
-				fprintf(f, "at %s %s %s\n", name, buf, (char*)(t->data));
-		} else {
-			char *foo;
+				strftime(buf, sizeof(buf), "%G%m%d%H%M.%S", tt);
 
-			if (t->persist)
-				foo = saprintf("*/%s", itoa(t->period));
-			else
-				foo = saprintf("%s", itoa(t->ends.tv_sec));
+				if (t->persist)
+					fprintf(f, "at %s %s/%s %s\n", name, buf, itoa(t->period), (char*)(t->data));
+				else
+					fprintf(f, "at %s %s %s\n", name, buf, (char*)(t->data));
+			} else {
+				char *foo;
 
-			fprintf(f, "timer %s %s %s\n", name, foo, (char*)(t->data));
+				if (t->persist)
+					foo = saprintf("*/%s", itoa(t->period));
+				else
+					foo = saprintf("%s", itoa(t->ends.tv_sec));
 
-			xfree(foo);
+				fprintf(f, "timer %s %s %s\n", name, foo, (char*)(t->data));
+
+				xfree(foo);
+			}
 		}
 	}
 }

Modified: trunk/ekg/ekg.c
===================================================================
--- trunk/ekg/ekg.c	2008-03-09 18:15:38 UTC (rev 3882)
+++ trunk/ekg/ekg.c	2008-03-09 20:27:23 UTC (rev 3883)
@@ -137,27 +137,31 @@
 	gettimeofday(&tv, NULL);
 
 	{
-                /* przejrzyj timery użytkownika, ui, skryptów */
-                for (l = timers; l; ) {
-                        struct timer *t = l->data;
-                        l = l->next;
+		{		/* przejrzyj timery użytkownika, ui, skryptów */
+			struct timer *t;
+			
+			for (t = timers; t; ) {
+				struct timer *next = t->next;
 
-                        if (tv.tv_sec > t->ends.tv_sec || (tv.tv_sec == t->ends.tv_sec && tv.tv_usec >= t->ends.tv_usec)) {
-				int ispersist = t->persist;
-				
-                                if (ispersist) {
-                                        memcpy(&t->ends, &tv, sizeof(tv));
-                                        t->ends.tv_sec += t->period;
-                                }
+				if (tv.tv_sec > t->ends.tv_sec || (tv.tv_sec == t->ends.tv_sec && tv.tv_usec >= t->ends.tv_usec)) {
+					int ispersist = t->persist;
+					
+					if (ispersist) {
+						memcpy(&t->ends, &tv, sizeof(tv));
+						t->ends.tv_sec += t->period;
+					}
 
-				if ((t->function(0, t->data) == -1) || !ispersist)
-					timer_free(t);
-                        }
-                }
+					if ((t->function(0, t->data) == -1) || !ispersist)
+						timer_free(t);
+				}
 
-		{
+				t = next;
+			}
+		}
+
+		{		/* removed 'w->removed' watches, timeout checking moved below select() */
 			watch_t *w;
-				/* removed 'w->removed' watches, timeout checking moved below select() */
+
 			for (w = watches; w;) {
 				watch_t *next = w->next;
 
@@ -286,26 +290,29 @@
 
 		stv.tv_sec = 1;
 		stv.tv_usec = 0;
-		for (l = timers; l; l = l->next) {
-			struct timer *t = l->data;
-			int usec = 0;
+		{
+			struct timer *t;
 
-			/* zeby uniknac przekrecenia licznika mikrosekund przy
-			 * wiekszych czasach, pomijamy dlugie timery */
-			if (t->ends.tv_sec - tv.tv_sec > 1)
-				continue;
+			for (t = timers; t; t = t->next) {
+				int usec = 0;
 
-			/* zobacz, ile zostalo do wywolania timera */
-			usec = (t->ends.tv_sec - tv.tv_sec) * 1000000 + (t->ends.tv_usec - tv.tv_usec);
+				/* zeby uniknac przekrecenia licznika mikrosekund przy
+				 * wiekszych czasach, pomijamy dlugie timery */
+				if (t->ends.tv_sec - tv.tv_sec > 1)
+					continue;
 
-			/* jesli wiecej niz sekunda, to nie ma znacznia */
-			if (usec >= 1000000)
-				continue;
-			
-			/* jesli mniej niz aktualny timeout, zmniejsz */
-			if (stv.tv_sec * 1000000 + stv.tv_usec > usec) {
-				stv.tv_sec = 0;
-				stv.tv_usec = usec;
+				/* zobacz, ile zostalo do wywolania timera */
+				usec = (t->ends.tv_sec - tv.tv_sec) * 1000000 + (t->ends.tv_usec - tv.tv_usec);
+
+				/* jesli wiecej niz sekunda, to nie ma znacznia */
+				if (usec >= 1000000)
+					continue;
+				
+				/* jesli mniej niz aktualny timeout, zmniejsz */
+				if (stv.tv_sec * 1000000 + stv.tv_usec > usec) {
+					stv.tv_sec = 0;
+					stv.tv_usec = usec;
+				}
 			}
 		}
 	
@@ -1195,12 +1202,16 @@
 	emoticon_free();
 	command_free();
 
-	for (l = timers; l;) {
-		struct timer *t = l->data;
-		
-		l = l->next;
+	{
+		struct timer *t;
 
-		timer_free(t);
+		for (t = timers; t;) {
+			struct timer *next = t->next;
+
+			timer_free(t);
+
+			t = next;
+		}
 	}
 
 	binding_free();

Modified: trunk/ekg/plugins.c
===================================================================
--- trunk/ekg/plugins.c	2008-03-09 18:15:38 UTC (rev 3882)
+++ trunk/ekg/plugins.c	2008-03-09 20:27:23 UTC (rev 3883)
@@ -529,13 +529,17 @@
 		}
 	}
 
-	for (l = timers; l; ) {
-		struct timer *t = l->data;
+	{
+		struct timer *t;
 
-		l = l->next;
+		for (t = timers; t; ) {
+			struct timer *next = t->next;
 
-		if (t->plugin == p)
-			timer_free(t);
+			if (t->plugin == p)
+				timer_free(t);
+
+			t = next;
+		}
 	}
 
 	{

Modified: trunk/ekg/plugins.h
===================================================================
--- trunk/ekg/plugins.h	2008-03-09 18:15:38 UTC (rev 3882)
+++ trunk/ekg/plugins.h	2008-03-09 20:27:23 UTC (rev 3883)
@@ -26,7 +26,7 @@
 #include "dynstuff.h"
 #include "sessions.h"
 
-#define EKG_ABI_VER 3881
+#define EKG_ABI_VER 3883
 
 #define EXPORT __attribute__ ((visibility("default")))
 

Modified: trunk/ekg/sessions.c
===================================================================
--- trunk/ekg/sessions.c	2008-03-09 18:15:38 UTC (rev 3882)
+++ trunk/ekg/sessions.c	2008-03-09 20:27:23 UTC (rev 3883)
@@ -303,13 +303,17 @@
 		}
 	}
 
-	for (l = timers; l;) {
-		struct timer *t = l->data;
+	{
+		struct timer *t;
 
-		l = l->next;
+		for (t = timers; t;) {
+			struct timer *next = t->next;
 
-		if (t->is_session && t->data == s)
-			timer_free(t);
+			if (t->is_session && t->data == s)
+				timer_free(t);
+
+			t = next;
+		}
 	}
 
 	tmp = xstrdup(uid);
@@ -1478,13 +1482,17 @@
 		}
 	}
 
-	for (l = timers; l;) {
-		struct timer *t = l->data;
+	{
+		struct timer *t;
 
-		l = l->next;
+		for (t = timers; t;) {
+			struct timer *next = t->next;
 
-		if (t->is_session)
-			timer_free(t);
+			if (t->is_session)
+				timer_free(t);
+
+			t = next;
+		}
 	}
 
 /* it's sessions, not 'l' because we emit SESSION_REMOVED, which might want to search over sessions list...

Modified: trunk/ekg/stuff.c
===================================================================
--- trunk/ekg/stuff.c	2008-03-09 18:15:38 UTC (rev 3882)
+++ trunk/ekg/stuff.c	2008-03-09 20:27:23 UTC (rev 3883)
@@ -86,7 +86,7 @@
 alias_t *aliases = NULL;
 list_t autofinds = NULL;
 list_t bindings = NULL;		/**< list_t struct timer <b>all</b> ekg2 timers */
-list_t timers = NULL;
+struct timer *timers = NULL;
 list_t conferences = NULL;
 list_t newconferences = NULL;
 #ifdef HAVE_ICONV
@@ -1898,13 +1898,10 @@
 		int i;
 
 		for (i = 1; !name; i++) {
-			list_t l;
 			int gotit = 0;
 
-			for (l = timers; l; l = l->next) {
-				struct timer *tt = l->data;
-
-				if (!xstrcmp(tt->name, itoa(i))) {
+			for (t = timers; t; t = t->next) {
+				if (!xstrcmp(t->name, itoa(i))) {
 					gotit = 1;
 					break;
 				}
@@ -1925,7 +1922,7 @@
 	t->data = data;
 	t->plugin = plugin;
 
-	list_add(&timers, t);
+	LIST_ADD2(&timers, t);
 	return t;
 }
 
@@ -1942,13 +1939,16 @@
 	return t;
 }
 
+static LIST_FREE_ITEM(timer_free_item, struct timer *) {
+	data->function(1, data->data); 
+	xfree(data->name);
+}
+
 int timer_free(struct timer *t) {
 	if (!t) 
 		return -1;
 
-	t->function(1, t->data); 
-	xfree(t->name);
-	list_remove(&timers, t, 1);
+	LIST_REMOVE2(&timers, t, timer_free_item);
 	return 0;
 }
 
@@ -1964,32 +1964,30 @@
  */
 int timer_remove(plugin_t *plugin, const char *name)
 {
-	list_t l;
+	struct timer *t;
 	int removed = 0;
 
-	for (l = timers; l; ) {
-		struct timer *t = l->data;
+	for (t = timers; t; ) {
+		struct timer *next = t->next;
 
-		l = l->next;
-
 		if (t->plugin == plugin && !xstrcasecmp(name, t->name)) {
 			timer_free(t);
 			removed++;
 		}
+
+		t = next;
 	}
 
 	return ((removed) ? 0 : -1);
 }
 
 struct timer *timer_find_session(session_t *session, const char *name) {
-	list_t l;
+	struct timer *t;
 
 	if (!session)
 		return NULL;
 	
-	for (l = timers; l; l = l->next) {
-		struct timer *t = l->data;
-
+	for (t = timers; t; t = t->next) {
 		if (t->is_session && t->data == session && !xstrcmp(name, t->name))
 			return t;
 	}
@@ -1999,22 +1997,22 @@
 
 int timer_remove_session(session_t *session, const char *name)
 {
-	list_t l;
+	struct timer *t;
 	plugin_t *p;
 	int removed = 0;
 
 	if (!session || (!(p = session->plugin)))
 		return -1;
 
-	for (l = timers; l; ) {
-		struct timer *t = l->data;
+	for (t = timers; t; ) {
+		struct timer *next = t->next;
 
-		l = l->next;
-
 		if (t->is_session && t->data == session && !xstrcmp(name, t->name)) {
 			timer_free(t);
 			removed++;
 		}
+
+		t = next;
 	}
 
 	return ((removed) ? 0 : -1);
@@ -2045,18 +2043,18 @@
  */
 int timer_remove_user(int at)
 {
-	list_t l;
+	struct timer *t;
 	int removed = 0;
 
-	for (l = timers; l; ) {
-		struct timer *t = l->data;
+	for (t = timers; t; ) {
+		struct timer *next = t->next;
 
-		l = l->next;
-
 		if (t->at == at && t->function == timer_handle_command) { 
 			timer_free(t);
 			removed = 1;
 		}
+
+		t = next;
 	}
 
 	return ((removed) ? 0 : -1);

Modified: trunk/ekg/stuff.h
===================================================================
--- trunk/ekg/stuff.h	2008-03-09 18:15:38 UTC (rev 3882)
+++ trunk/ekg/stuff.h	2008-03-09 20:27:23 UTC (rev 3883)
@@ -78,7 +78,6 @@
 
 	char		*name;		/* nazwa aliasu */
 	list_t		commands;	/* commands->data to (char*) */
-		/* XXX: maybe commands to *char[]? */
 } alias_t;
 #endif
 
@@ -113,6 +112,8 @@
 #define TIMER_SESSION(x)	int x(int type, session_t *s)
 
 struct timer {
+	struct timer	*next;
+
 	char		*name;			/* nazwa timera */
 	plugin_t	*plugin;		/* wtyczka obsługująca deksryptor */
 	struct timeval	ends;			/* kiedy się kończy? */
@@ -152,16 +153,15 @@
 
 #ifndef EKG2_WIN32_NOFUNCTION
 extern child_t *children;
+extern alias_t *aliases;
 extern list_t autofinds;
-extern alias_t *aliases;
 extern list_t bindings;
-extern list_t bindings_added;
-extern list_t timers;
+extern struct timer *timers;
 extern list_t conferences;
 extern list_t newconferences;
-
 extern list_t buffer_debug;
 extern list_t buffer_speech;
+extern list_t bindings_added;
 
 extern time_t last_save;
 extern char *config_profile;

Modified: trunk/plugins/mail/main.c
===================================================================
--- trunk/plugins/mail/main.c	2008-03-09 18:15:38 UTC (rev 3882)
+++ trunk/plugins/mail/main.c	2008-03-09 20:27:23 UTC (rev 3883)
@@ -493,14 +493,12 @@
 static void changed_check_mail(const char *var)
 {
 	if (config_check_mail) {
-		list_t l;
+		struct timer *t;
 
 		/* konieczne, jeśli była zmiana typu skrzynek */
 		changed_check_mail_folders(("check_mail_folders"));
 
-		for (l = timers; l; l = l->next) {
-			struct timer *t = l->data;
-
+		for (t = timers; t; t = t->next) {
 			if (!xstrcmp(t->name, "mail-check")) {
 				t->period = config_check_mail_frequency;
 				return;

Modified: trunk/plugins/perl/common/Command.xs
===================================================================
--- trunk/plugins/perl/common/Command.xs	2008-03-09 18:15:38 UTC (rev 3882)
+++ trunk/plugins/perl/common/Command.xs	2008-03-09 20:27:23 UTC (rev 3883)
@@ -5,10 +5,10 @@
 
 void commands()
 PREINIT:
-        list_t l;
+        command_t *c;
 PPCODE:
-        for (l = commands; l; l = l->next) {
-                XPUSHs(sv_2mortal(bless_command( (command_t *) l->data)));
+        for (c = commands; c; c = c->next) {
+                XPUSHs(sv_2mortal(bless_command( c)));
         }
 
 int command(char *what)

Modified: trunk/plugins/perl/common/Plugin.xs
===================================================================
--- trunk/plugins/perl/common/Plugin.xs	2008-03-09 18:15:38 UTC (rev 3882)
+++ trunk/plugins/perl/common/Plugin.xs	2008-03-09 20:27:23 UTC (rev 3883)
@@ -11,10 +11,10 @@
 	
 void plugins()
 PREINIT:
-        list_t l;
+        plugin_t *p;
 PPCODE:
-        for (l = plugins; l; l = l->next) {
-                XPUSHs(sv_2mortal(bless_plugin( (plugin_t *) l->data)));
+        for (p = plugins; p; p = p->next) {
+                XPUSHs(sv_2mortal(bless_plugin( p )));
         }
 
 int plugin_load(const char *name)

Modified: trunk/plugins/perl/common/Timer.xs
===================================================================
--- trunk/plugins/perl/common/Timer.xs	2008-03-09 18:15:38 UTC (rev 3882)
+++ trunk/plugins/perl/common/Timer.xs	2008-03-09 20:27:23 UTC (rev 3883)
@@ -5,10 +5,10 @@
 
 void timers()
 PREINIT:
-        list_t l;
+        struct timer *t;
 PPCODE:
-        for (l = timers; l; l = l->next) {
-                XPUSHs(sv_2mortal(bless_timer( (struct timer *) l->data)));
+        for (t = timers; t; t = t->next) {
+                XPUSHs(sv_2mortal(bless_timer( t )));
         }
 
 # Ekg2::Timer timer_find(const char *uid)

Modified: trunk/plugins/perl/common/Variable.xs
===================================================================
--- trunk/plugins/perl/common/Variable.xs	2008-03-09 18:15:38 UTC (rev 3882)
+++ trunk/plugins/perl/common/Variable.xs	2008-03-09 20:27:23 UTC (rev 3883)
@@ -7,10 +7,10 @@
 
 void variables()
 PREINIT:
-        list_t l;
+        variable_t *v;
 PPCODE:
-        for (l = variables; l; l = l->next) {
-                XPUSHs(sv_2mortal(bless_variable( (variable_t *) l->data)));
+        for (v = variables; v; v = v->next) {
+                XPUSHs(sv_2mortal(bless_variable( v )));
         }
 
 void variables_free()

Modified: trunk/plugins/perl/common/Watch.xs
===================================================================
--- trunk/plugins/perl/common/Watch.xs	2008-03-09 18:15:38 UTC (rev 3882)
+++ trunk/plugins/perl/common/Watch.xs	2008-03-09 20:27:23 UTC (rev 3883)
@@ -5,9 +5,9 @@
 
 void watches()
 PREINIT:
-        list_t l;
+        watch_t *w;
 PPCODE:
-        for (l = watches; l; l = l->next) {
-		XPUSHs(sv_2mortal(bless_watch( (watch_t *) l->data)));
+        for (w = watches; w; w = w->next) {
+		XPUSHs(sv_2mortal(bless_watch( w )));
         }
 



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