#include <Python.h>
#include "includes.h"
+#include "python/py3compat.h"
#include "libcli/util/pyerrors.h"
#include "python/modules.h"
#include "../libcli/nbt/libnbt.h"
static void py_nbt_node_dealloc(nbt_node_Object *self)
{
talloc_free(self->mem_ctx);
- self->ob_type->tp_free(self);
+ Py_TYPE(self)->tp_free(self);
}
static PyObject *py_nbt_node_init(PyTypeObject *self, PyObject *args, PyObject *kwargs)
static bool PyObject_AsDestinationTuple(PyObject *obj, const char **dest_addr, uint16_t *dest_port)
{
- if (PyString_Check(obj)) {
- *dest_addr = PyString_AsString(obj);
+ if (PyStr_Check(obj)) {
+ *dest_addr = PyStr_AsString(obj);
*dest_port = NBT_NAME_SERVICE_PORT;
return true;
}
return false;
}
- if (!PyString_Check(PyTuple_GetItem(obj, 0))) {
+ if (!PyStr_Check(PyTuple_GetItem(obj, 0))) {
PyErr_SetString(PyExc_TypeError, "Destination tuple first element not string");
return false;
}
- *dest_addr = PyString_AsString(obj);
+ *dest_addr = PyStr_AsString(obj);
if (PyTuple_Size(obj) == 1) {
*dest_port = NBT_NAME_SERVICE_PORT;
{
if (PyTuple_Check(obj)) {
if (PyTuple_Size(obj) == 2) {
- name->name = PyString_AsString(PyTuple_GetItem(obj, 0));
+ name->name = PyStr_AsString(PyTuple_GetItem(obj, 0));
name->type = PyInt_AsLong(PyTuple_GetItem(obj, 1));
name->scope = NULL;
return true;
} else if (PyTuple_Size(obj) == 3) {
- name->name = PyString_AsString(PyTuple_GetItem(obj, 0));
- name->scope = PyString_AsString(PyTuple_GetItem(obj, 1));
+ name->name = PyStr_AsString(PyTuple_GetItem(obj, 0));
+ name->scope = PyStr_AsString(PyTuple_GetItem(obj, 1));
name->type = PyInt_AsLong(PyTuple_GetItem(obj, 2));
return true;
} else {
}
}
- if (PyString_Check(obj)) {
+ if (PyStr_Check(obj)) {
/* FIXME: Parse string to be able to interpret things like RHONWYN<02> ? */
- name->name = PyString_AsString(obj);
+ name->name = PyStr_AsString(obj);
name->scope = NULL;
name->type = 0;
return true;
ret = PyTuple_New(3);
if (ret == NULL)
return NULL;
- PyTuple_SetItem(ret, 0, PyString_FromString(io.out.reply_from));
+ PyTuple_SetItem(ret, 0, PyStr_FromString(io.out.reply_from));
py_name = PyObject_FromNBTName(node->socket, &io.out.name);
if (py_name == NULL)
}
for (i = 0; i < io.out.num_addrs; i++) {
- PyList_SetItem(reply_addrs, i, PyString_FromString(io.out.reply_addrs[i]));
+ PyList_SetItem(reply_addrs, i, PyStr_FromString(io.out.reply_addrs[i]));
}
PyTuple_SetItem(ret, 2, reply_addrs);
ret = PyTuple_New(3);
if (ret == NULL)
return NULL;
- PyTuple_SetItem(ret, 0, PyString_FromString(io.out.reply_from));
+ PyTuple_SetItem(ret, 0, PyStr_FromString(io.out.reply_from));
py_name = PyObject_FromNBTName(node->socket, &io.out.name);
if (py_name == NULL)
ret = PyTuple_New(4);
if (ret == NULL)
return NULL;
- PyTuple_SetItem(ret, 0, PyString_FromString(io.out.reply_from));
+ PyTuple_SetItem(ret, 0, PyStr_FromString(io.out.reply_from));
py_name = PyObject_FromNBTName(node->socket, &io.out.name);
if (py_name == NULL)
PyTuple_SetItem(ret, 1, py_name);
- PyTuple_SetItem(ret, 2, PyString_FromString(io.out.reply_addr));
+ PyTuple_SetItem(ret, 2, PyStr_FromString(io.out.reply_addr));
PyTuple_SetItem(ret, 3, PyInt_FromLong(io.out.rcode));
ret = PyTuple_New(3);
if (ret == NULL)
return NULL;
- PyTuple_SetItem(ret, 0, PyString_FromString(io.out.reply_from));
+ PyTuple_SetItem(ret, 0, PyStr_FromString(io.out.reply_from));
py_name = PyObject_FromNBTName(node->socket, &io.out.name);
if (py_name == NULL)
PyTuple_SetItem(ret, 1, py_name);
- PyTuple_SetItem(ret, 2, PyString_FromString(io.out.reply_addr));
+ PyTuple_SetItem(ret, 2, PyStr_FromString(io.out.reply_addr));
PyTuple_SetItem(ret, 3, PyInt_FromLong(io.out.rcode));
};
PyTypeObject nbt_node_Type = {
- PyObject_HEAD_INIT(NULL) 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "netbios.Node",
.tp_basicsize = sizeof(nbt_node_Object),
.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
"Create a new NetBIOS node\n"
};
-void initnetbios(void)
+static struct PyModuleDef moduledef = {
+ PyModuleDef_HEAD_INIT,
+ .m_name = "netbios",
+ .m_doc = "NetBIOS over TCP/IP support",
+ .m_size = -1,
+ .m_methods = NULL,
+};
+
+MODULE_INIT_FUNC(netbios)
{
- PyObject *mod;
+ PyObject *mod = NULL;
if (PyType_Ready(&nbt_node_Type) < 0)
- return;
+ return mod;
+
+ mod = PyModule_Create(&moduledef);
- mod = Py_InitModule3("netbios", NULL, "NetBIOS over TCP/IP support");
Py_INCREF((PyObject *)&nbt_node_Type);
PyModule_AddObject(mod, "Node", (PyObject *)&nbt_node_Type);
+ return mod;
}