[cvslog] (2006-01-05 20:42:52 UTC) Module eggdrop1.9: Change committed!

cvslog cvs at tsss.org
Thu Jan 5 14:42:52 CST 2006


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.9
Commit time: 2006-01-05 20:42:52 UTC
Commited by: sven

Modified files:
     AUTHORS lib/eggdrop/binds.c lib/eggdrop/memutil.c
     modules/pythonscript/Makefile.am modules/pythonscript/config.m4
     modules/pythonscript/mycallable.c
     modules/pythonscript/pythonscript.c
     modules/pythonscript/pythonscript.h

Added files:
     modules/pythonscript/myegguser.c

Log message:

 * fixed the "break" thingy
 * fixed a va_list crash on AMD64
 * improved pythonscript module:
   * used the correct CFLAGS as defined in lib/python2.x/config/Makefile
   * cleared the exception indicator after loading a script
   * implemented eggdrop users as a python object instead of an int (3 attributes, 12 methods)
   * exported the egguser and stdio types into the eggdrop module

---------------------- diff included ----------------------
Index: eggdrop1.9/AUTHORS
diff -u eggdrop1.9/AUTHORS:1.18 eggdrop1.9/AUTHORS:1.19
--- eggdrop1.9/AUTHORS:1.18	Mon Jul  5 00:20:57 2004
+++ eggdrop1.9/AUTHORS	Thu Jan  5 14:42:42 2006
@@ -1,7 +1,7 @@
-$Id: AUTHORS,v 1.18 2004-07-05 05:20:57 wcc Exp $
+$Id: AUTHORS,v 1.19 2006-01-05 20:42:42 sven Exp $
 
 Eggdrop Developers and Contributers
-Last revised: March 9, 2002
+Last revised: January 5, 2006
      _________________________________________________________________
 
                     Eggdrop Developers and Contributers
@@ -47,6 +47,7 @@
     RebuM      Martin Matuska
     rtc        Peter 'Rattacresh' Backes
     SegFault   Ryan Butler
+    SET        Sven Trenkel
     Shaun      Shaun Braun
     slennox    Shayne Lennox
     stdarg
Index: eggdrop1.9/lib/eggdrop/binds.c
diff -u eggdrop1.9/lib/eggdrop/binds.c:1.26 eggdrop1.9/lib/eggdrop/binds.c:1.27
--- eggdrop1.9/lib/eggdrop/binds.c:1.26	Mon Jan  2 20:39:36 2006
+++ eggdrop1.9/lib/eggdrop/binds.c	Thu Jan  5 14:42:42 2006
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: binds.c,v 1.26 2006-01-03 02:39:36 guppy Exp $";
+static const char rcsid[] = "$Id: binds.c,v 1.27 2006-01-05 20:42:42 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -178,7 +178,7 @@
 /* Look up a bind entry based on either function name or id. */
 bind_entry_t *bind_entry_lookup(bind_table_t *table, int id, const char *mask, const char *function_name, Function callback)
 {
-	bind_entry_t *entry;
+	bind_entry_t *entry = NULL;
 	int hit, searchall = 0;
 
 	if (!table) {
@@ -290,7 +290,6 @@
 		while (bind_entry_lookup(0, next_id, 0, 0, 0)) {
 			next_id++;
 			if (next_id < 1) next_id = 1;
-			break;
 		}
 	}
 
Index: eggdrop1.9/lib/eggdrop/memutil.c
diff -u eggdrop1.9/lib/eggdrop/memutil.c:1.21 eggdrop1.9/lib/eggdrop/memutil.c:1.22
--- eggdrop1.9/lib/eggdrop/memutil.c:1.21	Mon May 30 22:35:07 2005
+++ eggdrop1.9/lib/eggdrop/memutil.c	Thu Jan  5 14:42:42 2006
@@ -19,7 +19,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: memutil.c,v 1.21 2005-05-31 03:35:07 stdarg Exp $";
+static const char rcsid[] = "$Id: memutil.c,v 1.22 2006-01-05 20:42:42 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -71,8 +71,12 @@
 		len = 512;
 	}
 	while (1) {
+		va_list temp_args;
+
 		len -= 10;
-		n = vsnprintf(output, len, format, args);
+		va_copy(temp_args, args);
+		n = vsnprintf(output, len, format, temp_args);
+		va_end(temp_args);
 		if (n > -1 && n < len) break;
 		if (n > len) len = n+1;
 		else len *= 2;
Index: eggdrop1.9/modules/pythonscript/Makefile.am
diff -u eggdrop1.9/modules/pythonscript/Makefile.am:1.2 eggdrop1.9/modules/pythonscript/Makefile.am:1.3
--- eggdrop1.9/modules/pythonscript/Makefile.am:1.2	Fri Dec 16 19:25:06 2005
+++ eggdrop1.9/modules/pythonscript/Makefile.am	Thu Jan  5 14:42:42 2006
@@ -1,11 +1,11 @@
-# $Id: Makefile.am,v 1.2 2005-12-17 01:25:06 sven Exp $
+# $Id: Makefile.am,v 1.3 2006-01-05 20:42:42 sven Exp $
 
 include $(top_srcdir)/$(ac_aux_dir)/module.mk
 
 pkglib_LTLIBRARIES	= pythonscript.la
 
-pythonscript_la_CFLAGS	= -I at PYTHON_INCLUDE@
-pythonscript_la_SOURCES	= pythonscript.c pythonscript.h mycallable.c mydict.c mymodule.c mystdio.c
+pythonscript_la_CFLAGS	= @PYTHON_CFLAGS@
+pythonscript_la_SOURCES	= pythonscript.c pythonscript.h mycallable.c mydict.c mymodule.c mystdio.c myegguser.c
 pythonscript_la_LDFLAGS	= -module -avoid-version -no-undefined
 pythonscript_la_LIBADD	= @PYTHON_LDFLAGS@ @LIBS@ \
 			$(top_builddir)/lib/eggdrop/libeggdrop.la
Index: eggdrop1.9/modules/pythonscript/config.m4
diff -u eggdrop1.9/modules/pythonscript/config.m4:1.2 eggdrop1.9/modules/pythonscript/config.m4:1.3
--- eggdrop1.9/modules/pythonscript/config.m4:1.2	Fri Dec 16 19:25:06 2005
+++ eggdrop1.9/modules/pythonscript/config.m4	Thu Jan  5 14:42:42 2006
@@ -16,7 +16,7 @@
 dnl along with this program; if not, write to the Free Software
 dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 dnl
-dnl $Id: config.m4,v 1.2 2005-12-17 01:25:06 sven Exp $
+dnl $Id: config.m4,v 1.3 2006-01-05 20:42:42 sven Exp $
 dnl
 
 EGG_MODULE_START(pythonscript, [python scripting support], "yes")
@@ -44,10 +44,12 @@
 		py_liblocalmod=`grep '^LOCALMODLIBS=' $PYTHON_LIB_DIR/config/Makefile | sed -e 's/^.*=\t*//'`
 		py_libbasemod=`grep '^BASEMODLIBS=' $PYTHON_LIB_DIR/config/Makefile | sed -e 's/^.*=\t*//'`
 		py_linkerflags=`grep '^LINKFORSHARED=' $PYTHON_LIB_DIR/config/Makefile | sed -e 's/^.*=\t*//'`
+		py_basecflags=`grep '^BASECFLAGS=' $PYTHON_LIB_DIR/config/Makefile | sed -e 's/^.*=\t*//'`
 
 		PYTHON_LDFLAGS="-L$PYTHON_LIB_DIR/config $py_libs $py_libc $py_libm -lpython$PYTHON_VERSION $py_liblocalmod $py_libbasemod $py_linkerflags"
 
-		AC_SUBST(PYTHON_INCLUDE)
+		PYTHON_CFLAGS="-I$PYTHON_INCLUDE $py_basecflags"
+		AC_SUBST(PYTHON_CFLAGS)
   	AC_SUBST(PYTHON_LDFLAGS)
 		EGG_MOD_ENABLED="yes"
 	else
Index: eggdrop1.9/modules/pythonscript/mycallable.c
diff -u eggdrop1.9/modules/pythonscript/mycallable.c:1.3 eggdrop1.9/modules/pythonscript/mycallable.c:1.4
--- eggdrop1.9/modules/pythonscript/mycallable.c:1.3	Wed Dec 28 11:27:31 2005
+++ eggdrop1.9/modules/pythonscript/mycallable.c	Thu Jan  5 14:42:42 2006
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: mycallable.c,v 1.3 2005-12-28 17:27:31 sven Exp $";
+static const char rcsid[] = "$Id: mycallable.c,v 1.4 2006-01-05 20:42:42 sven Exp $";
 #endif
 
 #include <Python.h>
@@ -33,7 +33,7 @@
 	if (Type == SCRIPT_UNSIGNED) return "an integer (or a small long)";
 	if (Type == SCRIPT_POINTER) return "a C pointer (what's that good for?)";
 	if (Type == SCRIPT_CALLBACK) return "a python function";
-	if (Type == SCRIPT_USER) return "an eggdrop user (ATM this is just an int)";
+	if (Type == SCRIPT_USER) return "an eggdrop user";
 	if (Type == SCRIPT_PARTIER) return "a partyline user (ATM this is just an int)";
 	if (Type == SCRIPT_BYTES) return "a string containing binary data";
 	if (Type == SCRIPT_VAR) return "no idea";
@@ -67,6 +67,7 @@
 
 	cmd->callback(cmd->client_data, &args, &retval);
 	if (retval.type & SCRIPT_ERROR) {
+		if (PyErr_Occurred()) return 0;
 		if (retval.type & SCRIPT_STRING) PyErr_SetString(PyExc_RuntimeError, retval.value);
 		else PyErr_SetString(PyExc_TypeError, "error message unavailable");
 		return 0;
@@ -74,7 +75,7 @@
 	return c_to_python_var(&retval);
 }
 
-PyObject *Repr(PyObject *self) {
+static PyObject *Repr(PyObject *self) {
 	PyObject *Ret, *Repr;
 	CallableObject *Obj = (CallableObject *) self;
 	script_linked_var_t *var = Obj->client_data;
@@ -125,6 +126,8 @@
 				NextPos = strchr(Pos, ' ');
 				if (NextPos) *NextPos = 0;
 				++NextPos;
+			} else {
+				NextPos = 0;
 			}
 			if (Pos && *Pos == '?') opt = " This parameter is optional.";
 			else opt = "";
Index: eggdrop1.9/modules/pythonscript/myegguser.c
diff -u /dev/null eggdrop1.9/modules/pythonscript/myegguser.c:1.1
--- /dev/null	Thu Jan  5 14:42:52 2006
+++ eggdrop1.9/modules/pythonscript/myegguser.c	Thu Jan  5 14:42:42 2006
@@ -0,0 +1,324 @@
+/* myegguser.c: Python scripting support - custom object representing an eggdrop user
+ *
+ * Copyright (C) 2001, 2002, 2003, 2004 Eggheads Development Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifndef lint
+static const char rcsid[] = "$Id: myegguser.c,v 1.1 2006-01-05 20:42:42 sven Exp $";
+#endif
+
+#include <Python.h>
+#include <eggdrop/eggdrop.h>
+
+#include "pythonscript.h"
+
+#define Return_None do {\
+	Py_INCREF(Py_None);\
+	return Py_None;\
+} while (0)
+
+#define CheckSelf user_t *user;\
+	EgguserObject *O = (EgguserObject *) self;\
+	user = O->user;\
+	if (!user || (user->flags & USER_DELETED)) {\
+		PyErr_SetString(PyExc_RuntimeError, "This user has been deleted.");\
+		return 0;\
+	}
+
+static PyObject *Egguser_New(PyTypeObject *Type, PyObject *args, PyObject *kwds) {
+	user_t *user = 0;
+	PyObject *Para;
+	EgguserObject *Egguser;
+
+	if (args) {
+		if (!PyArg_ParseTuple(args, "O", &Para)) return 0;
+		if (Egguser_Check(Para)) {
+			Egguser = (EgguserObject *) Para;
+			user = Egguser->user;
+		} else if (PyInt_Check(Para)) {
+			user = user_lookup_by_uid(PyInt_AsLong(Para));
+		} else if (PyString_Check(Para)) {
+			user = user_lookup_by_handle(PyString_AsString(Para));
+		} else {
+			PyErr_Format(PyExc_TypeError, "Expected eggdrop.egguser or int or str got %s.", Para->ob_type->tp_name);
+			return 0;
+		}
+		if (!user) {
+			PyErr_SetString(PyExc_RuntimeError, "No such user.");
+			return 0;
+		}
+	}
+	if (!(Egguser = (EgguserObject *) Type->tp_alloc(Type, 0))) return 0;
+	Egguser->user = user;
+	return (PyObject *) Egguser;
+}
+
+static PyObject *Repr(PyObject *self) {
+	EgguserObject *Obj = (EgguserObject *) self;
+	user_t *user = Obj->user;
+
+//	if (!user) return PyString_FromString("<Deleted eggdrop user. Drop this reference.>");
+//	return PyString_FromFormat("<Eggdrop user \"%s\" with uid %d>", user->handle, user->uid);
+	return PyString_FromFormat("eggdrop.egguser(%d)", user->uid);
+}
+
+static int Compare(PyObject *self, PyObject *other) {
+	user_t *u2;
+	EgguserObject *O2 = (EgguserObject *) other;
+	CheckSelf
+
+	if (!Egguser_Check(other)) return -1;
+	u2 = O2->user;
+	if (!u2 || (u2->flags & USER_DELETED)) {
+		PyErr_SetString(PyExc_RuntimeError, "This user has been deleted.");
+		return -1;
+	}
+	return user->uid < u2->uid ? -1 : user->uid != u2->uid;
+}
+
+static long Hash(PyObject *self) {
+	CheckSelf
+
+	return user->uid * 15485863;
+}
+
+static PyObject *GetUid(PyObject *self, void *ignored) {
+	CheckSelf
+
+	return PyInt_FromLong(user->uid);
+}
+
+static PyObject *GetHandle(PyObject *self, void *ignored) {
+	CheckSelf
+
+	return PyString_FromString(user->handle);
+}
+
+static PyObject *GetIrcMasks(PyObject *self, void *ignored) {
+	script_var_t retval;
+	CheckSelf
+
+	retval.type = SCRIPT_ARRAY | SCRIPT_STRING;
+	retval.len = user->nircmasks;
+	retval.value = user->ircmasks;
+	return c_to_python_var(&retval);
+}
+
+static PyObject *Delete(PyObject *self, PyObject *na) {
+	CheckSelf
+
+	user_delete(user);
+	Return_None;
+}
+
+static PyObject *AddMask(PyObject *self, PyObject *args) {
+	const char *mask;
+	CheckSelf
+
+	if (!PyArg_ParseTuple(args, "s", &mask)) return 0;
+	user_add_ircmask(user, mask);
+	Return_None;
+}
+
+static PyObject *DelMask(PyObject *self, PyObject *args) {
+	const char *mask;
+	CheckSelf
+
+	if (!PyArg_ParseTuple(args, "s", &mask)) return 0;
+	if (user_del_ircmask(user, mask)) {
+		PyErr_Format(PyExc_RuntimeError, "Could not delete IRC mask %s from user %s: No such mask.", mask, user->handle);
+		return 0;
+	}
+	Return_None;
+}
+
+static PyObject *Get(PyObject *self, PyObject *args) {
+	const char *setting, *chan = 0;
+	script_var_t retval;
+	CheckSelf
+
+	if (!PyArg_ParseTuple(args, "s|s", &setting, &chan)) return 0;
+	if (user_get_setting(user, chan, setting, (char **) &retval.value)) {
+		PyErr_Format(PyExc_RuntimeError, "Could not get setting %s from user %s.", setting, user->handle);
+		return 0;
+	}
+	retval.type = SCRIPT_STRING;
+	retval.len = -1;
+	return c_to_python_var(&retval);
+}
+
+static PyObject *Set(PyObject *self, PyObject *args) {
+	const char *setting, *value, *chan = 0;
+	CheckSelf
+
+	if (!PyArg_ParseTuple(args, "ss|s", &setting, &value, &chan)) return 0;
+	user_set_setting(user, chan, setting, value);
+	Return_None;
+}
+
+static PyObject *GetFlags(PyObject *self, PyObject *args) {
+	const char *chan = 0;
+	flags_t flags;
+	char flagstr[64];
+	script_var_t retval;
+	CheckSelf
+
+	if (!PyArg_ParseTuple(args, "|s", &chan)) return 0;
+
+	if (user_get_flags(user, chan, &flags)) {
+		PyErr_Format(PyExc_RuntimeError, "Could not get flags for user %s.", user->handle);
+		return 0;
+	}
+	flag_to_str(&flags, flagstr);
+	retval.type = SCRIPT_STRING;
+	retval.value = flagstr;
+	retval.len = -1;
+	return c_to_python_var(&retval);
+}
+
+static PyObject *SetFlags(PyObject *self, PyObject *args) {
+	const char *chan = 0, *flags;
+	CheckSelf
+
+	if (!PyArg_ParseTuple(args, "s|s", &flags, &chan)) return 0;
+
+	user_set_flags_str(user, chan, flags);
+	Return_None;
+}
+
+static PyObject *MatchFlags(PyObject *self, PyObject *args) {
+	const char *chan = 0, *flags;
+	flags_t flags_left, flags_right;
+	int r = 0;
+	CheckSelf
+
+	if (!PyArg_ParseTuple(args, "s|s", &flags, &chan)) return 0;
+	if (user_get_flags(user, chan, &flags_right)) {
+		PyErr_Format(PyExc_RuntimeError, "Could not get flags for user %s.", user->handle);
+		return 0;
+	}
+	flag_from_str(&flags_left, flags);
+	r = flag_match_subset(&flags_left, &flags_right);
+	return PyInt_FromLong(r);
+}
+
+static PyObject *MatchFlagsOr(PyObject *self, PyObject *args) {
+	const char *chan = 0, *flags;
+	flags_t flags_left, flags_right;
+	int r = 0;
+	CheckSelf
+
+	if (!PyArg_ParseTuple(args, "s|s", &flags, &chan)) return 0;
+	if (user_get_flags(user, chan, &flags_right)) {
+		PyErr_Format(PyExc_RuntimeError, "Could not get flags for user %s.", user->handle);
+		return 0;
+	}
+	flag_from_str(&flags_left, flags);
+	r = flag_match_partial(&flags_left, &flags_right);
+	return PyInt_FromLong(r);
+}
+
+static PyObject *HasPass(PyObject *self, PyObject *args) {
+	CheckSelf
+
+	return PyInt_FromLong(user_has_pass(user));
+}
+
+static PyObject *CheckPass(PyObject *self, PyObject *args) {
+	const char *pass;
+	CheckSelf
+
+	if (!PyArg_ParseTuple(args, "s", &pass)) return 0;
+	return PyInt_FromLong(user_check_pass(user, pass));
+}
+
+static PyObject *SetPass(PyObject *self, PyObject *args) {
+	const char *pass = 0;
+	CheckSelf
+
+	if (!PyArg_ParseTuple(args, "|s", &pass)) return 0;
+	user_set_pass(user, pass);
+	Return_None;
+}
+
+static PyMethodDef Methods[] = {
+	{"delete", Delete, METH_NOARGS, "This method will delete this user and all his data. "
+	                                "If he is currently on the partyline he will be booted. "
+	                                "Useing this object or any other object referring to the same user "
+	                                "after calling this method will raise an exception."},
+	{"addmask", AddMask, METH_VARARGS, "Adds an IRC hostmask to this user."},
+	{"delmask", DelMask, METH_VARARGS, "Deletes an IRC hostmask from this user."},
+	{"get", Get, METH_VARARGS, ""},
+	{"set", Set, METH_VARARGS, ""},
+	{"getflags", GetFlags, METH_VARARGS, ""},
+	{"setflags", SetFlags, METH_VARARGS, ""},
+	{"matchflags", MatchFlags, METH_VARARGS, ""},
+	{"matchflags_or", MatchFlagsOr, METH_VARARGS, ""},
+	{"haspass", HasPass, METH_NOARGS, ""},
+	{"checkpass", CheckPass, METH_VARARGS, ""},
+	{"setpass", SetPass, METH_VARARGS, ""},
+	{0}
+};
+
+static PyGetSetDef GetSeter[] = {
+	{"uid", GetUid, 0, 0, 0},
+	{"handle", GetHandle, 0, 0, 0},
+	{"ircmasks", GetIrcMasks, 0, 0, 0},
+	{0}
+};
+
+PyTypeObject Egguser_Type = {
+	PyObject_HEAD_INIT(0)        /* required by law */
+	0,                           /* ob_size, obsolete, always 0 */
+	"eggdrop.egguser",           /* tp_name, type callable in module eggdrop */
+	sizeof(EgguserObject),       /* tp_basicsize, size of the C struct belonging to this type */
+	0,                           /* tp_itemsize, only for variable types, always 0 */ 
+	0,                           /* tp_dealloc, the destructor, we don't need one */
+	0,                           /* tp_print, don't write me into a file */
+	0,                           /* tp_getattr, deprecated, we'll use tp_getattro */
+	0,                           /* tp_setattr, deprecated, we'll use tp_setattro */
+	Compare,                     /* tp_compare */
+	Repr,                        /* tp_repr, should there be one */
+	0,                           /* tp_as_number*/
+	0,                           /* tp_as_sequence*/
+	0,                           /* tp_as_mapping*/
+	Hash,                           /* tp_hash */
+	0,                           /* tp_call */
+	0,                           /* tp_str */
+	0,                           /* tp_getattro */
+	0,                           /* tp_setattro */
+	0,                           /* tp_as_buffer */
+	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,   /* tp_flags */
+	"an eggdrop user",           /* tp_doc */
+	0,                           /* tp_traverse */
+	0,                           /* tp_clear */
+	0,                           /* tp_richcompare */
+	0,                           /* tp_weaklistoffset */
+	0,                           /* tp_iter */
+	0,                           /* tp_iternext */
+	Methods,                     /* tp_methods */
+	0,                           /* tp_members */
+	GetSeter,                    /* tp_getset */
+	0,                           /* tp_base */
+	0,                           /* tp_dict */
+	0,                           /* tp_descr_get */
+	0,                           /* tp_descr_set */
+	0,                           /* tp_dictoffset */
+	0,                           /* tp_init */
+	0,                           /* tp_alloc */
+	Egguser_New                  /* tp_new */
+};
Index: eggdrop1.9/modules/pythonscript/pythonscript.c
diff -u eggdrop1.9/modules/pythonscript/pythonscript.c:1.3 eggdrop1.9/modules/pythonscript/pythonscript.c:1.4
--- eggdrop1.9/modules/pythonscript/pythonscript.c:1.3	Wed Dec 28 11:27:31 2005
+++ eggdrop1.9/modules/pythonscript/pythonscript.c	Thu Jan  5 14:42:42 2006
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: pythonscript.c,v 1.3 2005-12-28 17:27:31 sven Exp $";
+static const char rcsid[] = "$Id: pythonscript.c,v 1.4 2006-01-05 20:42:42 sven Exp $";
 #endif
 
 #include <Python.h>
@@ -37,7 +37,7 @@
 static int my_delete_command(void *ignore, script_raw_command_t *info);
 static int my_get_arg(void *ignore, script_args_t *args, int num, script_var_t *var, int type);
 
-static int my_python_cb_delete(event_owner_t *owner, script_callback_t *me);
+static int my_python_cb_delete(event_owner_t *owner, void *client_data);
 
 script_module_t my_script_interface = {
 	"Python", NULL,
@@ -92,6 +92,7 @@
 
 	CommonDict = PyObject_GetAttrString(CommonModule, name);
 	if (!CommonDict) {
+		PyErr_Clear();
 		CommonDict = PyDict_New();
 		PyModule_AddObject(CommonModule, name, CommonDict);   /* CommonModule steals a reference to CommonDict */
 	} else {
@@ -187,7 +188,8 @@
 }
 
 /* This implements the delete() member of Python script callbacks. */
-static int my_python_cb_delete(event_owner_t *owner, script_callback_t *me) {
+static int my_python_cb_delete(event_owner_t *owner, void *client_data) {
+	script_callback_t *me = client_data;
 	PyObject *Callback = me->callback_data;
 
 	Py_DECREF(Callback);
@@ -341,7 +343,9 @@
 			user_t *u = v->value;
 
 			if (u) {
-				result = PyInt_FromLong(u->uid);
+				EgguserObject *O = (EgguserObject *) Egguser_Type.tp_new(&Egguser_Type, 0, 0);
+				O->user = u;
+				result = (PyObject *) O;
 			} else {
 				Py_INCREF(Py_None);
 				result = Py_None;
@@ -381,7 +385,10 @@
 			PyObject *FunctionName, *ModuleName;
 			char *CFuncName = 0, *CModName = 0;
 
-			if (!PyCallable_Check(obj)) return 1;
+			if (!PyCallable_Check(obj)) {
+				PyErr_Format(PyExc_TypeError, "Object of type %s is not callable.", obj->ob_type->tp_name);
+				return 1;
+			}
 			cback = malloc(sizeof(*cback));
 			cback->callback = (Function) my_python_callbacker;
 			cback->callback_data = obj;
@@ -451,16 +458,17 @@
 		}
 #endif
 		case SCRIPT_USER: {
-			user_t *u;
-			int uid;
+			EgguserObject *O = (EgguserObject *) obj;
 
-			uid = PyInt_AsLong(obj);
-			u = user_lookup_by_uid(uid);
-			var->value = u;
-			if (!u) {
-				PyErr_SetString(PyExc_LookupError, "User not found");
+			if (!Egguser_Check(obj)) {
+				PyErr_Format(PyExc_TypeError, "Expected eggdrop.egguser, got %s", obj->ob_type->tp_name);
+				return 1;
+			}
+			if (!O->user || (O->user->flags & USER_DELETED)) {
+				PyErr_SetString(PyExc_RuntimeError, "This user has been deleted.");
 				return 1;
 			}
+			var->value = O->user;
 			return 0;
 		}
 	}
@@ -575,7 +583,8 @@
 	PyType_Ready(&MyDict_Type);
 	PyType_Ready(&Callable_Type);
 	PyType_Ready(&Stdio_Type);
-	
+	PyType_Ready(&Egguser_Type);
+
 	MinInt = PyInt_FromLong(INT_MIN);
 	MaxInt = PyInt_FromLong(INT_MAX);
 	MinUInt = PyInt_FromLong(0);
@@ -600,6 +609,11 @@
 		return -4;
 	}
 
+	Py_INCREF(&Stdio_Type);
+	Py_INCREF(&Egguser_Type);
+	PyModule_AddObject(EggdropModule, "stdio", (PyObject *) &Stdio_Type);
+	PyModule_AddObject(EggdropModule, "egguser", (PyObject *) &Egguser_Type);
+
 	Para = Py_BuildValue("(i)", 1);
 	Stdout = Stdio_Type.tp_new(&Stdio_Type, Para, 0);
 	Py_DECREF(Para);
Index: eggdrop1.9/modules/pythonscript/pythonscript.h
diff -u eggdrop1.9/modules/pythonscript/pythonscript.h:1.2 eggdrop1.9/modules/pythonscript/pythonscript.h:1.3
--- eggdrop1.9/modules/pythonscript/pythonscript.h:1.2	Fri Dec 16 19:25:06 2005
+++ eggdrop1.9/modules/pythonscript/pythonscript.h	Thu Jan  5 14:42:42 2006
@@ -16,13 +16,14 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
- * $Id: pythonscript.h,v 1.2 2005-12-17 01:25:06 sven Exp $
+ * $Id: pythonscript.h,v 1.3 2006-01-05 20:42:42 sven Exp $
  */
 
 #define PYTHON_VAR 1
 #define PYTHON_FUNC 2
 
 #define Callable_Check(op) PyObject_TypeCheck(op, &Callable_Type)
+#define Egguser_Check(op) PyObject_TypeCheck(op, &Egguser_Type)
 
 #define FlushAll() do {\
   Flush(0);\
@@ -36,6 +37,11 @@
 } CallableObject;
 
 typedef struct {
+	PyObject_HEAD
+	user_t *user;
+} EgguserObject;
+
+typedef struct {
 	PyDictObject dict;
 } MyDictObject;
 
@@ -52,5 +58,5 @@
 PyObject *MyModule_Add(char *name, char *doc);
 PyObject *MyDict_New(PyTypeObject *Type, PyObject *args, PyObject *kwds);
 
-PyTypeObject Callable_Type, MyDict_Type, Stdio_Type;
+PyTypeObject Callable_Type, MyDict_Type, Stdio_Type, Egguser_Type;
 PyObject *EggdropModule;
----------------------- End of diff -----------------------



More information about the Changes mailing list