+
+ return pyobj_from_usernode(user);
+}
+
+static PyObject*
+pyobj_from_server(struct server* srv) {
+ size_t n, idx;
+ PyObject* tmp = NULL;
+ PyObject* retval = NULL;
+ PyObject* users = PyTuple_New(srv->clients);
+
+ if (users == NULL)
+ return NULL;
+
+ idx = 0;
+ for (n = 0; n < srv->num_mask; ++n) {
+ if (srv->users[n] == NULL)
+ continue;
+
+ tmp = PyString_FromString(srv->users[n]->nick);
+ if (tmp == NULL)
+ goto cleanup;
+
+ if (PyTuple_SetItem(users, idx++, tmp))
+ goto cleanup;
+ }
+
+ retval = Py_BuildValue("{"
+ "s:s," /* name */
+ "s:l," /* boot */
+ "s:l," /* link_time */
+ "s:s," /* description */
+ "s:s," /* numeric */
+ "s:I," /* num_mask */
+ "s:I," /* hops */
+ "s:I," /* clients */
+ "s:I," /* max_clients */
+ "s:I," /* burst */
+ "s:I," /* self_burst */
+ "s:s" /* uplink */
+ "s:O" /* users */
+ /* TODO: Children */
+ "}",
+ "name", srv->name,
+ "boot", srv->boot,
+ "link_time", srv->link_time,
+ "description", srv->description,
+ "numeric", srv->numeric,
+ "num_mask", srv->num_mask,
+ "hops", srv->hops,
+ "clients", srv->clients,
+ "max_clients", srv->max_clients,
+ "burst", srv->burst,
+ "self_burst", srv->self_burst,
+ "uplink", srv->uplink ? srv->uplink->name : NULL,
+ "users", users
+ );
+
+ if (retval == NULL)
+ goto cleanup;
+
+ return retval;
+
+cleanup:
+ Py_XDECREF(retval);
+ pyobj_release_tuple(users, idx);
+
+ return NULL;
+}
+
+static PyObject*
+emb_get_server(UNUSED_ARG(PyObject* self), PyObject* args) {
+ struct server* srv;
+ char const* name;
+
+ if (!PyArg_ParseTuple(args, "s", &name))
+ return NULL;
+
+ if (name == NULL || strlen(name) == 0) {
+ PyErr_SetString(PyExc_Exception, "invalid server name");
+ return NULL;
+ }
+
+ if ((srv = GetServerH(name)) == NULL) {
+ PyErr_SetString(PyExc_Exception, "unknown server");
+ return NULL;
+ }
+
+ return pyobj_from_server(srv);
+}
+
+static PyObject*
+pyobj_from_modelist(struct modeList* mode) {
+ size_t n;
+ PyObject* tmp;
+ PyObject* retval = PyTuple_New(mode->used);
+
+ if (retval == NULL)
+ return NULL;
+
+ for (n = 0; n < mode->used; ++n) {
+ struct modeNode* mn = mode->list[n];
+ tmp = PyString_FromString(mn->user->nick);
+ if (tmp == NULL) {
+ pyobj_release_tuple(retval, n);
+ return NULL;
+ }
+
+ if (PyTuple_SetItem(retval, n, tmp)) {
+ pyobj_release_tuple(retval, n);
+ return NULL;
+ }