Example #1
0
static PyObject *py_socket_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
	int family, sock_type, protocol;
	int *sock;
	PyObject *pysocket;

	if (!PyArg_ParseTuple(args, "iii:socket", &family, &sock_type, &protocol)) {
		return NULL;
	}

	sock = talloc_zero(NULL, int);
	if (sock == NULL) {
		return PyErr_NoMemory();
	}

	*sock = swrap_socket(family, sock_type, protocol);
	if (*sock < 0) {
		return PyErr_SetFromErrno(py_socket_error);
	}

	if ((pysocket = pytalloc_steal(type, sock)) == NULL) {
		return PyErr_NoMemory();
	}

	return pysocket;
}
Example #2
0
static PyObject *py_socket_accept(pytalloc_Object *self, PyObject *args)
{
	int *sock, *new_sock;
	struct sockaddr addr;
	socklen_t addrlen;
	PyObject *pysocket;
	PyObject *pyaddr;
	PyObject *pyret;

	sock = pytalloc_get_ptr(self);

	new_sock = talloc_zero(NULL, int);
	if (new_sock == NULL) {
		return PyErr_NoMemory();
	}

	*new_sock = swrap_accept(*sock, &addr, &addrlen);
	if (*new_sock < 0) {
		return PyErr_SetFromErrno(py_socket_error);
	}

	if ((pysocket = pytalloc_steal(&PySocket, new_sock)) == NULL) {
		return PyErr_NoMemory();
	}

	pyret = PyTuple_New(2);
	if (pyret == NULL) {
		Py_DECREF(pysocket);
		return PyErr_NoMemory();
	}

	pyaddr = py_socket_addr_to_tuple(&addr, addrlen);
	if (pyaddr == NULL) {
		Py_DECREF(pysocket);
		Py_DECREF(pysocket);
		return NULL;
	}

	PyTuple_SetItem(pyret, 0, pysocket);
	PyTuple_SetItem(pyret, 1, pyaddr);
	return pyret;
}
Example #3
0
static PyObject *py_socket_dup(pytalloc_Object *self, PyObject *args)
{
	int *sock, *new_sock;
	PyObject *pysocket;

	sock = pytalloc_get_ptr(self);

	new_sock = talloc_zero(NULL, int);
	if (new_sock == NULL) {
		return PyErr_NoMemory();
	}

	*new_sock = swrap_dup(*sock);
	if (*new_sock < 0) {
		return PyErr_SetFromErrno(py_socket_error);
	}

	pysocket = pytalloc_steal(&PySocket, new_sock);
	if (pysocket == NULL) {
		return PyErr_NoMemory();
	}

	return pysocket;
}
Example #4
0
static PyObject *py_creds_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
	return pytalloc_steal(type, cli_credentials_init(NULL));
}
Example #5
0
static PyObject *testpytalloc_new(PyTypeObject *mod)
{
	char *obj = talloc_strdup(NULL, "This is a test string");;
	return pytalloc_steal(pytalloc_GetObjectType(), obj);
}