+void python_handle_del_user(struct userNode *user, struct userNode *killer, const char *why, UNUSED_ARG(void *extra)) {
+ PyObject *usr = NULL, *killr = NULL, *name = NULL;
+ PyObject *reason = NULL, *retval = NULL;
+ char const* err = NULL;
+
+ if (handler_object == NULL) {
+ err = "No Python handler is allocated. Ignoring python_handle_server_link.";
+ goto cleanup;
+ }
+
+ if (user == NULL) {
+ Py_INCREF(Py_None);
+ usr = Py_None;
+ } else {
+ usr = pyobj_from_usernode(user);
+ if (usr == NULL) {
+ err = "unable to allocate usernode for user";
+ goto cleanup;
+ }
+ }
+
+ if (killer == NULL) {
+ Py_INCREF(Py_None);
+ killr = Py_None;
+ } else {
+ killr = pyobj_from_usernode(killer);
+ if (killr == NULL) {
+ err = "unable to allocate usernode for killer";
+ goto cleanup;
+ }
+ }
+
+ if (why == NULL) {
+ Py_INCREF(Py_None);
+ reason = Py_None;
+ } else {
+ reason = PyString_FromString(why);
+ if (reason == NULL) {
+ err = "unable to allocate memory for reason";
+ goto cleanup;
+ }
+ }
+
+ name = PyString_FromString("del_user");
+ if (name == NULL) {
+ err = "unable to allocate memory for handler function name";
+ goto cleanup;
+ }
+
+ retval = PyObject_CallMethodObjArgs(handler_object, name, usr, killr, reason, NULL);
+ if (retval == NULL) {
+ err = "error calling del_user handler";
+ goto cleanup;
+ }
+
+cleanup:
+ Py_XDECREF(usr);
+ Py_XDECREF(killr);
+ Py_XDECREF(name);
+ Py_XDECREF(reason);
+ Py_XDECREF(retval);
+
+ if (err != NULL)
+ log_module(PY_LOG, LOG_WARNING, "%s", err);
+}
+
+int python_handle_topic(struct userNode *who, struct chanNode *chan, const char *old_topic, UNUSED_ARG(void *extra)) {
+ PyObject* pwho = NULL, *pchan = NULL, *oldtopic = NULL;
+ PyObject* name = NULL, *retval = NULL;
+ const char* err = NULL;
+ int i = 0;
+
+ if (who == NULL) {
+ Py_INCREF(Py_None);
+ pwho = Py_None;
+ } else {
+ if ((pwho = pyobj_from_usernode(who)) == NULL) {
+ err = "unable to allocate usernode";
+ goto cleanup;
+ }
+ }
+
+ if ((pchan = pyobj_from_channode(chan)) == NULL) {
+ err = "unable to allocate channode";
+ goto cleanup;
+ }
+
+ if (old_topic == NULL) {
+ Py_INCREF(Py_None);
+ oldtopic = Py_None;
+ } else {
+ oldtopic = PyString_FromString(old_topic);
+ if (oldtopic == NULL) {
+ err = "unable to allocate memory for old topic string";
+ goto cleanup;
+ }
+ }
+
+ name = PyString_FromString("topic");
+ if (name == NULL) {
+ err = "unable to allocate memory for topic handler function name";
+ goto cleanup;
+ }
+
+ retval = PyObject_CallMethodObjArgs(handler_object, name, pwho, pchan, oldtopic, NULL);
+ if (retval == NULL) {
+ err = "error calling topic handler";
+ goto cleanup;
+ }
+
+cleanup:
+ Py_XDECREF(pwho);
+ Py_XDECREF(pchan);
+ Py_XDECREF(oldtopic);
+ Py_XDECREF(name);
+
+ if (retval != NULL && PyInt_Check(retval))
+ i = (int)PyInt_AsLong(retval);
+
+ Py_XDECREF(retval);
+
+ if (err != NULL)
+ log_module(PY_LOG, LOG_WARNING, "%s", err);
+
+ return i;
+}