X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=lib%2Fpython%2Fdolmod.c;h=eb2c405defaa546209ec9478f3722cf760132883;hb=3616b334bc6426e973e08b612a5e8fd30ad80a5f;hp=edae7ae702ef416d14e90a19fe2f7012aa36146c;hpb=fbe30a6da13729c16770608bb5a7f11d79b22fb2;p=doldaconnect.git diff --git a/lib/python/dolmod.c b/lib/python/dolmod.c index edae7ae..eb2c405 100644 --- a/lib/python/dolmod.c +++ b/lib/python/dolmod.c @@ -134,14 +134,13 @@ static struct respobj *makeresp(struct dc_response *resp) static PyObject *mod_connect(PyObject *self, PyObject *args) { char *host; - int port; - port = -1; - if(!PyArg_ParseTuple(args, "s|i", &host, &port)) + host = NULL; + if(!PyArg_ParseTuple(args, "|s", &host)) return(NULL); if(fd >= 0) dc_disconnect(); - if((fd = dc_connect(host, port)) < 0) { + if((fd = dc_connect(host)) < 0) { PyErr_SetFromErrno(PyExc_OSError); return(NULL); } @@ -241,12 +240,15 @@ static PyObject *mod_qcmd(PyObject *self, PyObject *args, PyObject *kwargs) toks = NULL; tokssize = toksdata = 0; cmd = NULL; + ret = NULL; for(i = 0; i < PySequence_Size(args); i++) { - c = PySequence_GetItem(args, i); + if((c = PySequence_GetItem(args, i)) == NULL) + goto out; if(!PyUnicode_Check(c)) { n = PyUnicode_FromObject(c); Py_DECREF(c); - c = n; + if((c = n) == NULL) + goto out; } tok = smalloc((toksize = (PyUnicode_GetSize(c) + 1)) * sizeof(*tok)); tok[PyUnicode_AsWideChar((PyUnicodeObject *)c, tok, toksize)] = L'\0'; @@ -258,7 +260,7 @@ static PyObject *mod_qcmd(PyObject *self, PyObject *args, PyObject *kwargs) } if(cmd == NULL) { PyErr_SetString(PyExc_TypeError, "qcmd needs at least 1 argument"); - return(NULL); + goto out; } addtobuf(toks, NULL); ret = NULL; @@ -273,8 +275,11 @@ static PyObject *mod_qcmd(PyObject *self, PyObject *args, PyObject *kwargs) } else { ret = PyInt_FromLong(dc_queuecmd(NULL, NULL, cmd, L"%%a", toks, NULL)); } + +out: dc_freewcsarr(toks); - free(cmd); + if(cmd != NULL) + free(cmd); return(ret); } @@ -376,6 +381,14 @@ static PyObject *mod_lexsexpr(PyObject *self, PyObject *args) return(ret); } +static PyObject *mod_wantwrite(PyObject *self) +{ + if(dc_wantwrite()) + Py_RETURN_TRUE; + else + Py_RETURN_FALSE; +} + static PyMethodDef methods[] = { {"connect", mod_connect, METH_VARARGS, "Connect to a Dolda Connect server"}, @@ -393,6 +406,8 @@ static PyMethodDef methods[] = { "Perform an asynchronous login procedure"}, {"lexsexpr", mod_lexsexpr, METH_VARARGS, "Use a standard algorithm to lex a search expression"}, + {"wantwrite", (PyCFunction)mod_wantwrite, METH_NOARGS, + "Return a boolean indicating whether there is output to be fed to the server"}, {NULL, NULL, 0, NULL} };