+PyDoc_STRVAR(emb_kick__doc__,
+ "kick(who, target, message)\n\n"
+ "Kicks a given target as if the who user kicked them using the given message.");
+
+static PyObject* emb_kick(UNUSED_ARG(PyObject* self), PyObject* args) {
+ struct userNode* who, *target;
+ struct chanNode* channel;
+ char const* msg;
+
+ char const* who_s, *target_s, *channel_s;
+
+ if (!PyArg_ParseTuple(args, "ssss", &who_s, &target_s, &channel_s, &msg))
+ return NULL;
+
+ if ((who = GetUserH(who_s)) == NULL) {
+ PyErr_SetString(PyExc_Exception, "no such user");
+ return NULL;
+ }
+
+ if ((target = GetUserH(target_s)) == NULL) {
+ PyErr_SetString(PyExc_Exception, "no such target");
+ return NULL;
+ }
+
+ if ((channel = GetChannel(channel_s)) == NULL) {
+ PyErr_SetString(PyExc_Exception, "no such channel");
+ return NULL;
+ }
+
+ irc_kick(who, target, channel, msg);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+PyDoc_STRVAR(emb_channel_mode__doc__,
+ "channel_mode(who, channel, modes)\n\n"
+ "Lets a current server's user set a specified channel's modes as specified.");
+
+static PyObject* emb_channel_mode(UNUSED_ARG(PyObject* self_), PyObject* args) {
+ struct userNode* who;
+ struct chanNode* channel;
+ char const* modes;
+
+ char const* who_s, *channel_s;
+
+ if (!PyArg_ParseTuple(args, "sss", &who_s, &channel_s, &modes))
+ return NULL;
+
+ if ((who = GetUserH(who_s)) == NULL) {
+ PyErr_SetString(PyExc_Exception, "unknown user");
+ return NULL;
+ }
+
+ if (who->uplink != self) {
+ PyErr_SetString(PyExc_Exception, "user not on current server");
+ return NULL;
+ }
+
+ if ((channel = GetChannel(channel_s)) == NULL) {
+ PyErr_SetString(PyExc_Exception, "unknown channel");
+ return NULL;
+ }
+
+ irc_mode(who, channel, modes);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+PyDoc_STRVAR(emb_user_mode__doc__,
+ "user_mode(target, modes)\n\n"
+ "Sets target's modes as specified. The modes are in normal +f-n syntax.");
+
+static PyObject* emb_user_mode(UNUSED_ARG(PyObject* self), PyObject* args) {
+ struct userNode* target;
+ char const* modes;
+
+ char const* target_s;
+
+ if (!PyArg_ParseTuple(args, "ss", &target_s, &modes))
+ return NULL;
+
+ if ((target = GetUserH(target_s)) == NULL) {
+ PyErr_SetString(PyExc_Exception, "unknown user");
+ return NULL;
+ }
+
+ irc_umode(target, modes);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+PyDoc_STRVAR(emb_fakehost__doc__,
+ "fakehost(target, host)\n\n"
+ "Sets the fakehost of a given user to the specified host.");
+
+static PyObject* emb_fakehost(UNUSED_ARG(PyObject* self), PyObject* args) {
+ struct userNode* target;
+ char const* host;
+
+ char const* target_s;
+
+ if (!PyArg_ParseTuple(args, "ss", &target_s, &host))
+ return NULL;
+
+ if ((target = GetUserH(target_s)) == NULL) {
+ PyErr_SetString(PyExc_Exception, "unknown user");
+ return NULL;
+ }
+
+ irc_fakehost(target, host);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+PyDoc_STRVAR(emb_svsnick__doc__,
+ "svsnick(from, target, newnick)\n\n"
+ "The from nick must be on the service server.");
+
+static PyObject*
+emb_svsnick(UNUSED_ARG(PyObject* self_), PyObject* args) {
+ struct userNode* from, *target;
+ const char* newnick;
+
+ const char* from_s, *target_s;
+
+ if (!PyArg_ParseTuple(args, "sss", &from_s, &target_s, &newnick))
+ return NULL;
+
+ if ((from = GetUserH(from_s)) == NULL) {
+ PyErr_SetString(PyExc_Exception, "unknown from user");
+ return NULL;
+ }
+
+ if ((target = GetUserH(target_s)) == NULL) {
+ PyErr_SetString(PyExc_Exception, "unknown target user");
+ return NULL;
+ }
+
+ if (from->uplink != self) {
+ PyErr_SetString(PyExc_Exception, "from user is not on service server");
+ return NULL;
+ }
+
+ irc_svsnick(from, target, newnick);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+PyDoc_STRVAR(emb_svsquit__doc__,
+ "svsquit(from, target, reason)\n\n"
+ "The from user must be on the service server.");
+
+static PyObject*
+emb_svsquit(UNUSED_ARG(PyObject* self_), PyObject* args) {
+ struct userNode* from, *target;
+ char const* reason;
+
+ char const* from_s, *target_s;
+
+ if (!PyArg_ParseTuple(args, "sss", &from_s, &target_s, &reason))
+ return NULL;
+
+ if ((from = GetUserH(from_s)) == NULL) {
+ PyErr_SetString(PyExc_Exception, "unknown from user");
+ return NULL;
+ }
+
+ if (from->uplink != self) {
+ PyErr_SetString(PyExc_Exception, "from user is not on service server");
+ return NULL;
+ }
+
+ if ((target = GetUserH(target_s)) == NULL) {
+ PyErr_SetString(PyExc_Exception, "unknown target user");
+ return NULL;
+ }
+
+ irc_svsquit(from, target, reason);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+PyDoc_STRVAR(emb_svsjoin__doc__,
+ "svsjoin(from, target, to)\n\n"
+ "From user from must a user on the service server.\n"
+ "To must be an existing channel name.");
+
+static PyObject*
+emb_svsjoin(UNUSED_ARG(PyObject* self_), PyObject* args) {
+ struct userNode* from, *target;
+ struct chanNode* to;
+
+ const char* from_s, *target_s, *to_s;
+
+ if (!PyArg_ParseTuple(args, "sss", &from_s, &target_s, &to_s))
+ return NULL;
+
+ if ((from = GetUserH(from_s)) == NULL) {
+ PyErr_SetString(PyExc_Exception, "unknown from user");
+ return NULL;
+ }
+
+ if (from->uplink != self) {
+ PyErr_SetString(PyExc_Exception, "from user is not on service server");
+ return NULL;
+ }
+
+ if ((target = GetUserH(target_s)) == NULL) {
+ PyErr_SetString(PyExc_Exception, "unknown target user");
+ return NULL;
+ }
+
+ if ((to = GetChannel(to_s)) == NULL)
+ to = AddChannel(to_s, now, NULL, NULL, NULL);
+
+ irc_svsjoin(from, target, to);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+PyDoc_STRVAR(emb_adduser__doc__,
+ "adduser(nick, ident, hostname, description, modes) -> dict with user information\n\n"
+ "Adds a new local user with the given information.");
+
+static PyObject*
+emb_adduser(UNUSED_ARG(PyObject* self_), PyObject* args) {
+ char const* nick, *ident, *hostname, *desc, *modes;
+ struct userNode* user;
+ PyObject* retval;
+
+ if (!PyArg_ParseTuple(args, "sssss", &nick, &ident, &hostname, &desc, &modes))
+ return NULL;
+
+ user = AddLocalUser(nick, ident, hostname, desc, modes);
+
+ retval = pyobj_from_usernode(user);
+
+ return retval;
+}
+
+/* TODO: Add the rest of the service members to the dict */
+static PyObject*
+pyobj_from_service(struct service* serv) {
+ PyObject* bot, *retval;
+
+ bot = pyobj_from_usernode(serv->bot);
+ if (bot == NULL)
+ goto cleanup;
+
+ retval = Py_BuildValue("{s:O,s:c,s:I}",
+ "bot", bot,
+ "trigger", serv->trigger,
+ "privileged", serv->privileged);
+ if (retval == NULL)
+ goto cleanup;
+
+ return retval;
+
+cleanup:
+ Py_XDECREF(bot);
+ return NULL;
+}
+
+PyDoc_STRVAR(emb_service_register__doc__,
+ "service_register(nick)\n\n"
+ "Registers nick as a service. The specified nick must be on the local server.");
+
+static PyObject*
+emb_service_register(UNUSED_ARG(PyObject* self_), PyObject* args) {
+ struct userNode* user;
+ char const* user_s;
+
+ if (!PyArg_ParseTuple(args, "s", &user_s))
+ return NULL;
+
+ if ((user = GetUserH(user_s)) == NULL) {
+ PyErr_SetString(PyExc_Exception, "unknown user");
+ return NULL;
+ }
+
+ if (user->uplink != self) {
+ PyErr_SetString(PyExc_Exception, "user is not on service server");
+ return NULL;
+ }
+
+ return pyobj_from_service(service_register(user));
+}
+
+size_t logs_size = 0;
+static struct log_type **logs_list = NULL;
+
+PyDoc_STRVAR(emb_log_register_type__doc__,
+ "registers a log source to write event data to.");
+static PyObject* emb_log_register_type(UNUSED_ARG(PyObject *self), PyObject* args) {
+ const char* logName;
+ const char* defaultLog;
+ struct log_type* log;
+ struct log_type** newlogs;
+
+ if (!PyArg_ParseTuple(args, "ss", &logName, &defaultLog))
+ return NULL;
+
+ newlogs = realloc(logs_list, (logs_size+1)*sizeof(struct log_type*));
+ if (newlogs == NULL) {
+ PyErr_SetString(PyExc_Exception, "unable to allocate memory for log structures. aborting.");
+ return NULL;
+ }
+ logs_list = newlogs;
+
+ log = log_register_type(logName, defaultLog);
+ if (log == NULL) {
+ PyErr_SetString(PyExc_Exception, "unable to register log");
+ return NULL;
+ }
+
+ logs_list[logs_size++] = log;
+
+ return Py_BuildValue("O", PyCObject_FromVoidPtr(log, NULL));
+}
+
+PyDoc_STRVAR(emb_module_register__doc__, "registers a module");
+PyObject* emb_module_register(UNUSED_ARG(PyObject* self), PyObject* args) {
+ PyObject* pylog;
+ char const *name, *helpfile;
+ struct log_type* log;
+ struct module* mod;
+
+ if (!PyArg_ParseTuple(args, "sOs", &name, &pylog, &helpfile))
+ return NULL;
+
+ log = PyCObject_AsVoidPtr(pylog);
+
+ mod = module_register(name, log, helpfile, NULL);
+
+ if (mod == NULL) {
+ PyErr_SetString(PyExc_Exception, "unable to register module");
+ return NULL;
+ }
+
+ return Py_BuildValue("O", PyCObject_FromVoidPtr(mod, NULL));
+}
+