X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/6d4db0bf4b67e65708637466d4f0d306ed1dfe53..cfb291f03e0882cba9037be2a2756a6af41fb76a:/passphrase.c diff --git a/passphrase.c b/passphrase.c index 93a2073..424bcc9 100644 --- a/passphrase.c +++ b/passphrase.c @@ -1,13 +1,11 @@ /* -*-c-*- * - * $Id$ - * * Reading and writing passphrases * * (c) 2005 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of the Python interface to Catacomb. * @@ -15,12 +13,12 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * Catacomb/Python is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with Catacomb/Python; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -56,11 +54,11 @@ end: static PyObject *pixie_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) { pixie_pyobj *rc = 0; - char *kwlist[] = { "socket", 0 }; + static const char *const kwlist[] = { "socket", 0 }; char *sock = 0; int fd; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "|s:new", kwlist, &sock)) + if (!PyArg_ParseTupleAndKeywords(arg, kw, "|s:new", KWLIST, &sock)) goto end; if ((fd = pixie_open(sock)) < 0) OSERR(sock); @@ -73,19 +71,19 @@ end: static void pixie_pydealloc(PyObject *me) { close(PIXIE_FD(me)); - FREEOBJ(me); + FREEOBJ(me); } static PyObject *pixmeth_read(PyObject *me, PyObject *arg, PyObject *kw) { unsigned mode = PMODE_READ; char *tag; - char *kwlist[] = { "tag", "mode", 0 }; + static const char *const kwlist[] = { "tag", "mode", 0 }; PyObject *rc = 0; int r; char buf[1024]; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "s|O&:read", kwlist, + if (!PyArg_ParseTupleAndKeywords(arg, kw, "s|O&:read", KWLIST, &tag, convuint, &mode)) goto end; r = pixie_read(PIXIE_FD(me), tag, mode, buf, sizeof(buf)); @@ -94,7 +92,7 @@ static PyObject *pixmeth_read(PyObject *me, PyObject *arg, PyObject *kw) else if (r > 0) RETURN_NONE; else - rc = PyString_FromString(buf); + rc = BIN_FROMSTR(buf); end: return (rc); } @@ -104,7 +102,7 @@ static PyObject *pixmeth_set(PyObject *me, PyObject *arg) char *tag; char *phrase; - if (!PyArg_ParseTuple(arg, "ss:set", &tag, &phrase)) + if (!PyArg_ParseTuple(arg, "s"Y":set", &tag, &phrase)) return (0); pixie_set(PIXIE_FD(me), tag, phrase); RETURN_ME; @@ -120,7 +118,7 @@ static PyObject *pixmeth_cancel(PyObject *me, PyObject *arg) RETURN_ME; } -static PyMethodDef pixie_pymethods[] = { +static const PyMethodDef pixie_pymethods[] = { #define METHNAME(name) pixmeth_##name KWMETH(read, "P.read(TAG, [mode = PMODE_READ]) -> STRING") METH (set, "P.set(TAG, PHRASE)") @@ -129,9 +127,9 @@ static PyMethodDef pixie_pymethods[] = { { 0 } }; -static PyTypeObject pixie_pytype_skel = { - PyObject_HEAD_INIT(0) 0, /* Header */ - "catacomb.Pixie", /* @tp_name@ */ +static const PyTypeObject pixie_pytype_skel = { + PyVarObject_HEAD_INIT(0, 0) /* Header */ + "Pixie", /* @tp_name@ */ sizeof(pixie_pyobj), /* @tp_basicsize@ */ 0, /* @tp_itemsize@ */ @@ -154,15 +152,15 @@ static PyTypeObject pixie_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"Passphrase pixie connection.", + "Pixie([socket = ?]): passphrase pixie connection.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ 0, /* @tp_richcompare@ */ 0, /* @tp_weaklistoffset@ */ 0, /* @tp_iter@ */ - 0, /* @tp_iternexr@ */ - pixie_pymethods, /* @tp_methods@ */ + 0, /* @tp_iternext@ */ + PYMETHODS(pixie), /* @tp_methods@ */ 0, /* @tp_members@ */ 0, /* @tp_getset@ */ 0, /* @tp_base@ */ @@ -179,20 +177,25 @@ static PyTypeObject pixie_pytype_skel = { /*----- Main code ---------------------------------------------------------*/ +static const struct nameval consts[] = { + CONST(PMODE_READ), CONST(PMODE_VERIFY), + { 0 } +}; + static PyObject *meth_ppread(PyObject *me, PyObject *arg, PyObject *kw) { char *tag; unsigned f = PMODE_READ; PyObject *rc = 0; - char *kwlist[] = { "tag", "mode", 0 }; + static const char *const kwlist[] = { "tag", "mode", 0 }; char buf[1024]; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "s|O&:ppread", kwlist, + if (!PyArg_ParseTupleAndKeywords(arg, kw, "s|O&:ppread", KWLIST, &tag, convuint, &f)) goto end; if (passphrase_read(tag, f, buf, sizeof(buf))) SYSERR("passphrase read failed"); - rc = PyString_FromString(buf); + rc = BIN_FROMSTR(buf); end: return (rc); } @@ -217,16 +220,16 @@ static PyObject *meth_getpass(PyObject *me, PyObject *arg) goto end; if (pixie_getpass(prompt, buf, sizeof(buf))) OSERR(0); - rc = PyString_FromString(buf); + rc = BIN_FROMSTR(buf); end: return (rc); } -static PyMethodDef methods[] = { +static const PyMethodDef methods[] = { #define METHNAME(name) meth_##name - KWMETH(ppread, "ppread(TAG, [mode = PMODE_READ]) -> STRING") - METH (ppcancel, "ppcancel(TAG)") - METH (getpass, "getpass(PROMPT) -> STRING") + KWMETH(ppread, "ppread(TAG, [mode = PMODE_READ]) -> STRING") + METH (ppcancel, "ppcancel(TAG)") + METH (getpass, "getpass(PROMPT) -> STRING") #undef METHNAME { 0 } }; @@ -240,6 +243,7 @@ void passphrase_pyinit(void) void passphrase_pyinsert(PyObject *mod) { INSERT("Pixie", pixie_pytype); + setconstants(mod, consts); } /*----- That's all, folks -------------------------------------------------*/