[cvslog] Module eggdrop1.7: Change committed

cvslog cvs at tsss.org
Wed Oct 17 01:09:01 CST 2001


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.7
Commit time: 2001-10-17 06:08:22 UTC
Commited by: stdarg <stdarg at techmonkeys.org>

Modified files:
     src/egg_timer.c src/main.c src/script_api.h src/tclmisc.c
     src/mod/perlscript.mod/perlscript.c
     src/mod/tclscript.mod/tclscript.c

Log message:

Updates to timer code.
Added USER and CALLBACK types to perl module.

---------------------- diff included ----------------------
Index: eggdrop1.7/src/egg_timer.c
diff -u eggdrop1.7/src/egg_timer.c:1.2 eggdrop1.7/src/egg_timer.c:1.3
--- eggdrop1.7/src/egg_timer.c:1.2	Mon Oct 15 04:27:08 2001
+++ eggdrop1.7/src/egg_timer.c	Wed Oct 17 01:08:11 2001
@@ -3,6 +3,8 @@
 
 typedef int (*Function)();
 #include "egg_timer.h"
+#include "script_api.h"
+#include "script.h"
 
 /* Internal use only. */
 typedef struct egg_timer_b {
@@ -19,6 +21,22 @@
 static egg_timer_t *timer_list_head = NULL;
 static unsigned int timer_next_id = 1;
 
+static int script_single_timer(int sec, int usec, script_callback_t *callback);
+static int script_repeat_timer(int sec, int usec, script_callback_t *callback);
+
+static script_simple_command_t script_cmds[] = {
+	{"", NULL, NULL, NULL, 0},
+	{"timer", script_single_timer, "iic", "seconds microseconds callback", SCRIPT_INTEGER},
+	{"rtimer", script_repeat_timer, "iic", "seconds microseconds callback", SCRIPT_INTEGER},
+	{"killtimer", timer_destroy, "i", "timer-id", SCRIPT_INTEGER},
+	0
+};
+
+void timer_init()
+{
+	script_create_simple_cmd_table(script_cmds);
+}
+
 /* Based on TclpGetTime from Tcl 8.3.3 */
 int timer_get_time(egg_timeval_t *curtime)
 {
@@ -133,6 +151,8 @@
 		timer_get_time(&curtime);
 		if (timer->trigger_time.sec > curtime.sec || (timer->trigger_time.sec == curtime.sec && timer->trigger_time.usec > curtime.usec)) break;
 
+		timer_list_head = timer_list_head->next;
+
 		callback = timer->callback;
 		client_data = timer->client_data;
 
@@ -143,8 +163,6 @@
 			timer->trigger_time.sec += timer->howlong.sec;
 			timer->trigger_time.usec += timer->howlong.usec;
 
-			timer_list_head = timer_list_head->next;
-
 			prev = NULL;
 			for (tptr = timer_list_head; tptr; tptr = tptr->next) {
 				if (tptr->trigger_time.sec > timer->trigger_time.sec || (tptr->trigger_time.sec == timer->trigger_time.sec && tptr->trigger_time.usec > timer->trigger_time.usec)) break;
@@ -160,11 +178,33 @@
 			}
 		}
 		else {
-			timer_list_head = timer_list_head->next;
 			free(timer);
 		}
-
 		callback(client_data);
 	}
 	return(0);
+}
+
+static int script_timer(int sec, int usec, script_callback_t *callback, int flags)
+{
+	egg_timeval_t howlong;
+	int id;
+
+	howlong.sec = sec;
+	howlong.usec = usec;
+	callback->syntax = (char *)malloc(1);
+	callback->syntax[0] = 0;
+	id = timer_create_complex(&howlong, callback->callback, callback, flags);
+	return(id);
+}
+
+static int script_single_timer(int sec, int usec, script_callback_t *callback)
+{
+	callback->flags |= SCRIPT_CALLBACK_ONCE;
+	return script_timer(sec, usec, callback, 0);
+}
+
+static int script_repeat_timer(int sec, int usec, script_callback_t *callback)
+{
+	return script_timer(sec, usec, callback, TIMER_REPEAT);
 }
Index: eggdrop1.7/src/main.c
diff -u eggdrop1.7/src/main.c:1.88 eggdrop1.7/src/main.c:1.89
--- eggdrop1.7/src/main.c:1.88	Tue Oct 16 22:28:16 2001
+++ eggdrop1.7/src/main.c	Wed Oct 17 01:08:11 2001
@@ -5,7 +5,7 @@
  *   command line arguments
  *   context and assert debugging
  *
- * $Id: main.c,v 1.88 2001/10/17 03:28:16 stdarg Exp $
+ * $Id: main.c,v 1.89 2001/10/17 06:08:11 stdarg Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -631,6 +631,7 @@
 
 int init_dcc_max(), init_userent(), init_misc(), init_net(),
  init_modules(), init_tcl(int, char **);
+void timer_init();
 void botnet_init();
 void dns_init();
 void script_init();
@@ -751,6 +752,7 @@
     fatal(_("ERROR: Eggdrop will not run as root!"), 0);
 
   script_init();
+  timer_init();
   dns_init();
   binds_init();
   core_binds_init();
Index: eggdrop1.7/src/mod/perlscript.mod/perlscript.c
diff -u eggdrop1.7/src/mod/perlscript.mod/perlscript.c:1.1 eggdrop1.7/src/mod/perlscript.mod/perlscript.c:1.2
--- eggdrop1.7/src/mod/perlscript.mod/perlscript.c:1.1	Tue Oct 16 00:08:45 2001
+++ eggdrop1.7/src/mod/perlscript.mod/perlscript.c	Wed Oct 17 01:08:12 2001
@@ -14,10 +14,6 @@
 
 static PerlInterpreter *ginterp; /* Our global interpreter. */
 
-typedef struct {
-	AV *result;
-} my_walking_data;
-
 static XS(my_command_handler);
 
 static int my_load_script(registry_entry_t * entry, char *fname)
@@ -47,6 +43,57 @@
 	return(0);
 }
 
+static int my_perl_callbacker(script_callback_t *me, ...)
+{
+	int retval, i, n;
+	script_var_t var;
+	void **al;
+	dSP;
+
+	ENTER;
+	SAVETMPS;
+	PUSHMARK(SP);
+
+	al = (int *)&me;
+	al++;
+	if (me->syntax) n = strlen(me->syntax);
+	else n = 0;
+	for (i = 0; i < n; i++) {
+		var.type = me->syntax[i];
+		var.value = (void *)al[i];
+		var.len = -1;
+		arg = my_resolve_variable(&var);
+		XPUSHs(sv_2mortal(arg));
+	}
+	PUTBACK;
+
+	count = call_pv(me->name, G_SCALAR);
+
+	SPAGAIN;
+
+	if (count > 0) {
+		retval = POPi;
+	}
+	else retval = 0;
+
+	PUTBACK;
+	FREETMPS;
+	LEAVE;
+
+	/* If it's a one-time callback, delete it. */
+	if (me->flags & SCRIPT_CALLBACK_ONCE) me->delete(me);
+
+	return(retval);
+}
+
+static int my_perl_cb_delete(script_callback_t *me)
+{
+	if (me->syntax) free(me->syntax);
+	if (me->name) free(me->name);
+	free(me);
+	return(0);
+}
+
 static int my_create_cmd(void *ignore, script_command_t *info)
 {
 	char *cmdname;
@@ -142,23 +189,42 @@
 	syntax = cmd->syntax;
 	for (i = 0; i < items; i++) {
 		switch (*syntax++) {
-			case SCRIPT_BYTES:	/* Byte-arrays. */
-			case SCRIPT_STRING: {
+			case SCRIPT_BYTES: /* Byte-array. */
+			case SCRIPT_STRING: { /* String. */
 				char *val;
 				val = SvPV(ST(i), len);
 				mstack_push(args, (void *)val);
 				break;
 			}
-			case SCRIPT_INTEGER: {	/* Integer. */
+			case SCRIPT_INTEGER: { /* Integer. */
 				int val;
 				val = SvIV(ST(i));
 				mstack_push(args, (void *)val);
 				break;
 			}
-			case SCRIPT_CALLBACK:	/* Callback. */
-				/* No callbacks yet. */
-				mstack_push(args, NULL);
+			case SCRIPT_CALLBACK: { /* Callback. */
+				script_callback_t *cback;
+				char *name;
+
+				cback = (script_callback_t *)calloc(1, sizeof(*cback));
+				cback->callback = (Function) my_perl_callbacker;
+				cback->delete = (Function) my_perl_cb_delete;
+				name = SvPV(ST(i), len);
+				malloc_strcpy(cback->name, name);
+				cback->callback_data = name;
+				mstack_push(args, cback);
 				break;
+			}
+			case SCRIPT_USER: { /* User. */
+				struct userrec *u;
+				char *handle;
+
+				handle = SvPV(ST(i), len);
+				if (handle) u = get_user_by_handle(userlist, handle);
+				else u = NULL;
+				mstack_push(args, u);
+				break;
+			}
 			case 'l':
 				/* Length of previous string or byte-array. */
 				mstack_push(args, (void *)len);
Index: eggdrop1.7/src/mod/tclscript.mod/tclscript.c
diff -u eggdrop1.7/src/mod/tclscript.mod/tclscript.c:1.7 eggdrop1.7/src/mod/tclscript.mod/tclscript.c:1.8
--- eggdrop1.7/src/mod/tclscript.mod/tclscript.c:1.7	Tue Oct 16 00:08:45 2001
+++ eggdrop1.7/src/mod/tclscript.mod/tclscript.c	Wed Oct 17 01:08:12 2001
@@ -135,6 +135,9 @@
 	result = Tcl_GetObjResult(cd->myinterp);
 	Tcl_GetIntFromObj(cd->myinterp, result, &retval);
 
+	/* If it's a one-time callback, delete it. */
+	if (me->flags & SCRIPT_CALLBACK_ONCE) me->delete(me);
+
 	return(retval);
 }
 
@@ -322,7 +325,9 @@
 	void *ptr;
 	int i;
 
-	while (!mstack_pop(argstack->bufs, &ptr)) free(ptr);
+	for (i = 0; i < argstack->bufs->len; i++) {
+		free((void *)argstack->bufs->stack[i]);
+	}
 	mstack_destroy(argstack->bufs);
 	mstack_destroy(argstack->args);
 	return(0);
Index: eggdrop1.7/src/script_api.h
diff -u eggdrop1.7/src/script_api.h:1.4 eggdrop1.7/src/script_api.h:1.5
--- eggdrop1.7/src/script_api.h:1.4	Mon Oct 15 21:42:32 2001
+++ eggdrop1.7/src/script_api.h	Wed Oct 17 01:08:11 2001
@@ -25,6 +25,9 @@
 #define SCRIPT_WANTS_CD	1
 #define SCRIPT_COMPLEX	2
 
+/* Flags for callbacks. */
+#define SCRIPT_CALLBACK_ONCE	1
+
 /* Flags for linked variables. */
 #define SCRIPT_READ_ONLY	1
 
@@ -49,6 +52,7 @@
 	void *delete_data;
 	char *syntax;
 	char *name;
+	int flags;
 } script_callback_t;
 
 typedef struct script_var_b {
Index: eggdrop1.7/src/tclmisc.c
diff -u eggdrop1.7/src/tclmisc.c:1.32 eggdrop1.7/src/tclmisc.c:1.33
--- eggdrop1.7/src/tclmisc.c:1.32	Tue Oct 16 22:28:16 2001
+++ eggdrop1.7/src/tclmisc.c	Wed Oct 17 01:08:11 2001
@@ -3,7 +3,7 @@
  *   Tcl stubs for file system commands
  *   Tcl stubs for everything else
  *
- * $Id: tclmisc.c,v 1.32 2001/10/17 03:28:16 stdarg Exp $
+ * $Id: tclmisc.c,v 1.33 2001/10/17 06:08:11 stdarg Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -29,13 +29,11 @@
 #include "modules.h"
 #include "tandem.h"
 #include "md5.h"
-#include "egg_timer.h"
 #ifdef HAVE_UNAME
 #include <sys/utsname.h>
 #endif
 
 extern p_tcl_bind_list	 bind_table_list;
-extern tcl_timer_t	*timer, *utimer;
 extern struct dcc_t	*dcc;
 extern char		 origbotname[], botnetnick[], quit_msg[];
 extern struct userrec	*userlist;
@@ -135,121 +133,6 @@
   return TCL_OK;
 }
 
-typedef struct {
-  Tcl_Interp *irp;
-  char *script;
-} tcl_timer_cdata;
-
-static int tcl_timer_callback(tcl_timer_cdata *cdata)
-{
-  Tcl_Eval(cdata->irp, cdata->script);
-  free(cdata->script);
-  free(cdata);
-  return(0);
-}
-
-static int tcl_timer STDVAR
-{
-  unsigned long x;
-  char s[16];
-
-  BADARGS(3, 3, " minutes command");
-  if (atoi(argv[1]) < 0) {
-    Tcl_AppendResult(irp, "time value must be positive", NULL);
-    return TCL_ERROR;
-  }
-  if (argv[2][0] != '#') {
-    tcl_timer_cdata *cdata;
-    egg_timeval_t howlong;
-
-    cdata = (tcl_timer_cdata *)malloc(sizeof(*cdata));
-    cdata->irp = irp;
-    malloc_strcpy(cdata->script, argv[2]);
-    howlong.sec = 60 * atoi(argv[1]);
-    howlong.usec = 0;
-    x = timer_create_complex(&howlong, tcl_timer_callback, cdata, 0);
-    egg_snprintf(s, sizeof s, "timer%lu", x);
-    Tcl_AppendResult(irp, s, NULL);
-  }
-  return TCL_OK;
-}
-
-static int tcl_utimer STDVAR
-{
-  unsigned long x;
-  char s[16];
-
-  BADARGS(3, 3, " seconds command");
-  if (atoi(argv[1]) < 0) {
-    Tcl_AppendResult(irp, "time value must be positive", NULL);
-    return TCL_ERROR;
-  }
-  if (argv[2][0] != '#') {
-    tcl_timer_cdata *cdata;
-    egg_timeval_t howlong;
-
-    cdata = (tcl_timer_cdata *)malloc(sizeof(*cdata));
-    cdata->irp = irp;
-    malloc_strcpy(cdata->script, argv[2]);
-    howlong.sec = atoi(argv[1]);
-    howlong.usec = 0;
-    x = timer_create_complex(&howlong, tcl_timer_callback, cdata, 0);
-    egg_snprintf(s, sizeof s, "timer%lu", x);
-    Tcl_AppendResult(irp, s, NULL);
-  }
-  return TCL_OK;
-}
-
-static int tcl_mutimer STDVAR
-{
-  unsigned long x;
-  char s[16];
-
-  BADARGS(3, 3, " microseconds command");
-  if (atoi(argv[1]) < 0) {
-    Tcl_AppendResult(irp, "time value must be positive", NULL);
-    return TCL_ERROR;
-  }
-  if (argv[2][0] != '#') {
-    tcl_timer_cdata *cdata;
-    egg_timeval_t howlong;
-
-    cdata = (tcl_timer_cdata *)malloc(sizeof(*cdata));
-    cdata->irp = irp;
-    malloc_strcpy(cdata->script, argv[2]);
-    howlong.sec = atoi(argv[1]) / 1000000;
-    howlong.usec = atoi(argv[1]) % 1000000;
-    x = timer_create_complex(&howlong, tcl_timer_callback, cdata, 0);
-    egg_snprintf(s, sizeof s, "timer%lu", x);
-    Tcl_AppendResult(irp, s, NULL);
-  }
-  return TCL_OK;
-}
-
-static int tcl_killtimer STDVAR
-{
-  BADARGS(2, 2, " timerID");
-  return TCL_OK;
-}
-
-static int tcl_killutimer STDVAR
-{
-  BADARGS(2, 2, " timerID");
-  return TCL_OK;
-}
-
-static int tcl_timers STDVAR
-{
-  BADARGS(1, 1, "");
-  return TCL_OK;
-}
-
-static int tcl_utimers STDVAR
-{
-  BADARGS(1, 1, "");
-  return TCL_OK;
-}
-
 static int tcl_duration STDVAR
 {
   char s[70];
@@ -597,13 +480,6 @@
   {"putcmdlog",		tcl_putcmdlog},
   {"putxferlog",	tcl_putxferlog},
   {"putloglev",		tcl_putloglev},
-  {"timer",		tcl_timer},
-  {"utimer",		tcl_utimer},
-  {"mutimer",		tcl_mutimer},
-  {"killtimer",		tcl_killtimer},
-  {"killutimer",	tcl_killutimer},
-  {"timers",		tcl_timers},
-  {"utimers",		tcl_utimers},
   {"unixtime",		tcl_unixtime},
   {"strftime",          tcl_strftime},
   {"ctime",		tcl_ctime},
----------------------- End of diff -----------------------



More information about the Changes mailing list