#include <Python.h>
#include <eggdrop/eggdrop.h>
#include "pythonscript.h"
Go to the source code of this file.
Defines | |
#define | Return_None |
#define | CheckSelf |
Functions | |
static PyObject * | Egguser_New (PyTypeObject *Type, PyObject *args, PyObject *kwds) |
static PyObject * | Repr (PyObject *self) |
static int | Compare (PyObject *self, PyObject *other) |
static long | Hash (PyObject *self) |
static PyObject * | GetUid (PyObject *self, void *ignored) |
static PyObject * | GetHandle (PyObject *self, void *ignored) |
static PyObject * | GetIrcMasks (PyObject *self, void *ignored) |
static PyObject * | Delete (PyObject *self, PyObject *na) |
static PyObject * | AddMask (PyObject *self, PyObject *args) |
static PyObject * | DelMask (PyObject *self, PyObject *args) |
static PyObject * | Get (PyObject *self, PyObject *args) |
static PyObject * | Set (PyObject *self, PyObject *args) |
static PyObject * | GetFlags (PyObject *self, PyObject *args) |
static PyObject * | SetFlags (PyObject *self, PyObject *args) |
static PyObject * | MatchFlags (PyObject *self, PyObject *args) |
static PyObject * | MatchFlagsOr (PyObject *self, PyObject *args) |
static PyObject * | HasPass (PyObject *self, PyObject *args) |
static PyObject * | CheckPass (PyObject *self, PyObject *args) |
static PyObject * | SetPass (PyObject *self, PyObject *args) |
Variables | |
static const char | rcsid [] = "$Id: myegguser.c,v 1.1 2006-01-05 20:42:42 sven Exp $" |
static PyMethodDef | Methods [] |
static PyGetSetDef | GetSeter [] |
PyTypeObject | Egguser_Type |
#define CheckSelf |
Value:
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;\ }
Definition at line 34 of file myegguser.c.
Referenced by AddMask(), CheckPass(), Compare(), Delete(), DelMask(), Get(), GetFlags(), GetHandle(), GetIrcMasks(), GetUid(), Hash(), HasPass(), MatchFlags(), MatchFlagsOr(), Set(), SetFlags(), and SetPass().
#define Return_None |
Value:
do {\ Py_INCREF(Py_None);\ return Py_None;\ } while (0)
Definition at line 29 of file myegguser.c.
Referenced by AddMask(), Delete(), DelMask(), Set(), SetFlags(), and SetPass().
static PyObject* AddMask | ( | PyObject * | self, | |
PyObject * | args | |||
) | [static] |
Definition at line 128 of file myegguser.c.
References CheckSelf, Return_None, and user_add_ircmask().
00128 { 00129 const char *mask; 00130 CheckSelf 00131 00132 if (!PyArg_ParseTuple(args, "s", &mask)) return 0; 00133 user_add_ircmask(user, mask); 00134 Return_None; 00135 }
static PyObject* CheckPass | ( | PyObject * | self, | |
PyObject * | args | |||
) | [static] |
Definition at line 241 of file myegguser.c.
References CheckSelf, and user_check_pass().
00241 { 00242 const char *pass; 00243 CheckSelf 00244 00245 if (!PyArg_ParseTuple(args, "s", &pass)) return 0; 00246 return PyInt_FromLong(user_check_pass(user, pass)); 00247 }
static int Compare | ( | PyObject * | self, | |
PyObject * | other | |||
) | [static] |
Definition at line 79 of file myegguser.c.
References CheckSelf, Egguser_Check, user::flags, user::uid, EgguserObject::user, and USER_DELETED.
00079 { 00080 user_t *u2; 00081 EgguserObject *O2 = (EgguserObject *) other; 00082 CheckSelf 00083 00084 if (!Egguser_Check(other)) return -1; 00085 u2 = O2->user; 00086 if (!u2 || (u2->flags & USER_DELETED)) { 00087 PyErr_SetString(PyExc_RuntimeError, "This user has been deleted."); 00088 return -1; 00089 } 00090 return user->uid < u2->uid ? -1 : user->uid != u2->uid; 00091 }
static PyObject* Delete | ( | PyObject * | self, | |
PyObject * | na | |||
) | [static] |
Definition at line 121 of file myegguser.c.
References CheckSelf, Return_None, and user_delete().
00121 { 00122 CheckSelf 00123 00124 user_delete(user); 00125 Return_None; 00126 }
static PyObject* DelMask | ( | PyObject * | self, | |
PyObject * | args | |||
) | [static] |
Definition at line 137 of file myegguser.c.
References CheckSelf, Return_None, and user_del_ircmask().
00137 { 00138 const char *mask; 00139 CheckSelf 00140 00141 if (!PyArg_ParseTuple(args, "s", &mask)) return 0; 00142 if (user_del_ircmask(user, mask)) { 00143 PyErr_Format(PyExc_RuntimeError, "Could not delete IRC mask %s from user %s: No such mask.", mask, user->handle); 00144 return 0; 00145 } 00146 Return_None; 00147 }
static PyObject* Egguser_New | ( | PyTypeObject * | Type, | |
PyObject * | args, | |||
PyObject * | kwds | |||
) | [static] |
Definition at line 42 of file myegguser.c.
References Egguser_Check, EgguserObject::user, user_lookup_by_handle(), and user_lookup_by_uid().
00042 { 00043 user_t *user = 0; 00044 PyObject *Para; 00045 EgguserObject *Egguser; 00046 00047 if (args) { 00048 if (!PyArg_ParseTuple(args, "O", &Para)) return 0; 00049 if (Egguser_Check(Para)) { 00050 Egguser = (EgguserObject *) Para; 00051 user = Egguser->user; 00052 } else if (PyInt_Check(Para)) { 00053 user = user_lookup_by_uid(PyInt_AsLong(Para)); 00054 } else if (PyString_Check(Para)) { 00055 user = user_lookup_by_handle(PyString_AsString(Para)); 00056 } else { 00057 PyErr_Format(PyExc_TypeError, "Expected eggdrop.egguser or int or str got %s.", Para->ob_type->tp_name); 00058 return 0; 00059 } 00060 if (!user) { 00061 PyErr_SetString(PyExc_RuntimeError, "No such user."); 00062 return 0; 00063 } 00064 } 00065 if (!(Egguser = (EgguserObject *) Type->tp_alloc(Type, 0))) return 0; 00066 Egguser->user = user; 00067 return (PyObject *) Egguser; 00068 }
static PyObject* Get | ( | PyObject * | self, | |
PyObject * | args | |||
) | [static] |
Definition at line 149 of file myegguser.c.
References c_to_python_var(), CheckSelf, script_var_b::len, SCRIPT_STRING, script_var_b::type, user_get_setting(), and script_var_b::value.
00149 { 00150 const char *setting, *chan = 0; 00151 script_var_t retval; 00152 CheckSelf 00153 00154 if (!PyArg_ParseTuple(args, "s|s", &setting, &chan)) return 0; 00155 if (user_get_setting(user, chan, setting, (char **) &retval.value)) { 00156 PyErr_Format(PyExc_RuntimeError, "Could not get setting %s from user %s.", setting, user->handle); 00157 return 0; 00158 } 00159 retval.type = SCRIPT_STRING; 00160 retval.len = -1; 00161 return c_to_python_var(&retval); 00162 }
static PyObject* GetFlags | ( | PyObject * | self, | |
PyObject * | args | |||
) | [static] |
Definition at line 173 of file myegguser.c.
References c_to_python_var(), CheckSelf, flag_to_str(), script_var_b::len, SCRIPT_STRING, script_var_b::type, user_get_flags(), and script_var_b::value.
00173 { 00174 const char *chan = 0; 00175 flags_t flags; 00176 char flagstr[64]; 00177 script_var_t retval; 00178 CheckSelf 00179 00180 if (!PyArg_ParseTuple(args, "|s", &chan)) return 0; 00181 00182 if (user_get_flags(user, chan, &flags)) { 00183 PyErr_Format(PyExc_RuntimeError, "Could not get flags for user %s.", user->handle); 00184 return 0; 00185 } 00186 flag_to_str(&flags, flagstr); 00187 retval.type = SCRIPT_STRING; 00188 retval.value = flagstr; 00189 retval.len = -1; 00190 return c_to_python_var(&retval); 00191 }
static PyObject* GetHandle | ( | PyObject * | self, | |
void * | ignored | |||
) | [static] |
static PyObject* GetIrcMasks | ( | PyObject * | self, | |
void * | ignored | |||
) | [static] |
Definition at line 111 of file myegguser.c.
References c_to_python_var(), CheckSelf, script_var_b::len, SCRIPT_ARRAY, SCRIPT_STRING, script_var_b::type, and script_var_b::value.
00111 { 00112 script_var_t retval; 00113 CheckSelf 00114 00115 retval.type = SCRIPT_ARRAY | SCRIPT_STRING; 00116 retval.len = user->nircmasks; 00117 retval.value = user->ircmasks; 00118 return c_to_python_var(&retval); 00119 }
static PyObject* GetUid | ( | PyObject * | self, | |
void * | ignored | |||
) | [static] |
static long Hash | ( | PyObject * | self | ) | [static] |
static PyObject* HasPass | ( | PyObject * | self, | |
PyObject * | args | |||
) | [static] |
Definition at line 235 of file myegguser.c.
References CheckSelf, and user_has_pass().
00235 { 00236 CheckSelf 00237 00238 return PyInt_FromLong(user_has_pass(user)); 00239 }
static PyObject* MatchFlags | ( | PyObject * | self, | |
PyObject * | args | |||
) | [static] |
Definition at line 203 of file myegguser.c.
References CheckSelf, flag_from_str(), flag_match_subset(), and user_get_flags().
00203 { 00204 const char *chan = 0, *flags; 00205 flags_t flags_left, flags_right; 00206 int r = 0; 00207 CheckSelf 00208 00209 if (!PyArg_ParseTuple(args, "s|s", &flags, &chan)) return 0; 00210 if (user_get_flags(user, chan, &flags_right)) { 00211 PyErr_Format(PyExc_RuntimeError, "Could not get flags for user %s.", user->handle); 00212 return 0; 00213 } 00214 flag_from_str(&flags_left, flags); 00215 r = flag_match_subset(&flags_left, &flags_right); 00216 return PyInt_FromLong(r); 00217 }
static PyObject* MatchFlagsOr | ( | PyObject * | self, | |
PyObject * | args | |||
) | [static] |
Definition at line 219 of file myegguser.c.
References CheckSelf, flag_from_str(), flag_match_partial(), and user_get_flags().
00219 { 00220 const char *chan = 0, *flags; 00221 flags_t flags_left, flags_right; 00222 int r = 0; 00223 CheckSelf 00224 00225 if (!PyArg_ParseTuple(args, "s|s", &flags, &chan)) return 0; 00226 if (user_get_flags(user, chan, &flags_right)) { 00227 PyErr_Format(PyExc_RuntimeError, "Could not get flags for user %s.", user->handle); 00228 return 0; 00229 } 00230 flag_from_str(&flags_left, flags); 00231 r = flag_match_partial(&flags_left, &flags_right); 00232 return PyInt_FromLong(r); 00233 }
static PyObject* Repr | ( | PyObject * | self | ) | [static] |
Definition at line 70 of file myegguser.c.
References user::uid, and EgguserObject::user.
00070 { 00071 EgguserObject *Obj = (EgguserObject *) self; 00072 user_t *user = Obj->user; 00073 00074 // if (!user) return PyString_FromString("<Deleted eggdrop user. Drop this reference.>"); 00075 // return PyString_FromFormat("<Eggdrop user \"%s\" with uid %d>", user->handle, user->uid); 00076 return PyString_FromFormat("eggdrop.egguser(%d)", user->uid); 00077 }
static PyObject* Set | ( | PyObject * | self, | |
PyObject * | args | |||
) | [static] |
Definition at line 164 of file myegguser.c.
References CheckSelf, Return_None, and user_set_setting().
00164 { 00165 const char *setting, *value, *chan = 0; 00166 CheckSelf 00167 00168 if (!PyArg_ParseTuple(args, "ss|s", &setting, &value, &chan)) return 0; 00169 user_set_setting(user, chan, setting, value); 00170 Return_None; 00171 }
static PyObject* SetFlags | ( | PyObject * | self, | |
PyObject * | args | |||
) | [static] |
Definition at line 193 of file myegguser.c.
References CheckSelf, Return_None, and user_set_flags_str().
00193 { 00194 const char *chan = 0, *flags; 00195 CheckSelf 00196 00197 if (!PyArg_ParseTuple(args, "s|s", &flags, &chan)) return 0; 00198 00199 user_set_flags_str(user, chan, flags); 00200 Return_None; 00201 }
static PyObject* SetPass | ( | PyObject * | self, | |
PyObject * | args | |||
) | [static] |
Definition at line 249 of file myegguser.c.
References CheckSelf, Return_None, and user_set_pass().
00249 { 00250 const char *pass = 0; 00251 CheckSelf 00252 00253 if (!PyArg_ParseTuple(args, "|s", &pass)) return 0; 00254 user_set_pass(user, pass); 00255 Return_None; 00256 }
PyTypeObject Egguser_Type |
Definition at line 284 of file myegguser.c.
Referenced by c_to_python_var(), and pythonscript_LTX_start().
PyGetSetDef GetSeter[] [static] |
Initial value:
{ {"uid", GetUid, 0, 0, 0}, {"handle", GetHandle, 0, 0, 0}, {"ircmasks", GetIrcMasks, 0, 0, 0}, {0} }
Definition at line 277 of file myegguser.c.
PyMethodDef Methods[] [static] |
Initial value:
{ {"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} }
Definition at line 258 of file myegguser.c.
const char rcsid[] = "$Id: myegguser.c,v 1.1 2006-01-05 20:42:42 sven Exp $" [static] |
Definition at line 21 of file myegguser.c.