diff --git a/miltermodule.c b/miltermodule.c index fd140c6..cb5ccc5 100644 --- a/miltermodule.c +++ b/miltermodule.c @@ -35,6 +35,10 @@ $ python setup.py help libraries=["milter","smutil","resolv"] * $Log$ + * Revision 1.31 2012/04/12 23:32:50 customdesigned + * Replace redundant callback array with macros. If this doesn't break anything, + * macros can be eliminated with code changes. + * * Revision 1.30 2012/04/12 23:08:06 customdesigned * Support RFC2553 on BSD * @@ -327,7 +331,7 @@ static struct MilterCallback { { NULL , NULL } }; -staticforward struct smfiDesc description; /* forward declaration */ +static struct smfiDesc description; /* forward declaration */ static PyObject *MilterError; /* The interpreter instance that called milter.main */ @@ -339,7 +343,7 @@ typedef struct { static milter_Diag diag; -staticforward PyTypeObject milter_ContextType; +static PyTypeObject milter_ContextType; typedef struct { PyObject_HEAD @@ -676,7 +680,7 @@ _generic_wrapper(milter_ContextObject *self, PyObject *cb, PyObject *arglist) { result = PyEval_CallObject(cb, arglist); Py_DECREF(arglist); if (result == NULL) return _report_exception(self); - if (!PyInt_Check(result)) { + if (!PyLong_Check(result)) { const struct MilterCallback *p; const char *cbname = "milter"; char buf[40]; @@ -691,7 +695,7 @@ _generic_wrapper(milter_ContextObject *self, PyObject *cb, PyObject *arglist) { PyErr_SetString(MilterError,buf); return _report_exception(self); } - retval = PyInt_AS_LONG(result); + retval = PyLong_AS_LONG(result); Py_DECREF(result); _release_thread(self->t); return retval; @@ -708,7 +712,7 @@ makeipaddr(struct sockaddr_in *addr) { sprintf(buf, "%d.%d.%d.%d", (int) (x>>24) & 0xff, (int) (x>>16) & 0xff, (int) (x>> 8) & 0xff, (int) (x>> 0) & 0xff); - return PyString_FromString(buf); + return PyUnicode_FromString(buf); } #ifdef HAVE_IPV6_SUPPORT @@ -716,8 +720,8 @@ static PyObject * makeip6addr(struct sockaddr_in6 *addr) { char buf[100]; /* must be at least INET6_ADDRSTRLEN + 1 */ const char *s = inet_ntop(AF_INET6, &addr->sin6_addr, buf, sizeof buf); - if (s) return PyString_FromString(s); - return PyString_FromString("inet6:unknown"); + if (s) return PyUnicode_FromString(s); + return PyUnicode_FromString("inet6:unknown"); } #endif @@ -808,7 +812,7 @@ generic_env_wrapper(SMFICTX *ctx, PyObject*cb, char **argv) { for (i=0;i/libmilter/README for details on setting it up.\n"; static void setitem(PyObject *d,const char *name,long val) { - PyObject *v = PyInt_FromLong(val); + PyObject *v = PyLong_FromLong(val); PyDict_SetItemString(d,name,v); Py_DECREF(v); } -void -initmilter(void) { +static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + "milter", /* m_name */ + milter_documentation,/* m_doc */ + -1, /* m_size */ + milter_methods, /* m_methods */ + NULL, /* m_reload */ + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL, /* m_free */ +}; + +PyMODINIT_FUNC PyInit_milter(void) { PyObject *m, *d; - m = Py_InitModule4("milter", milter_methods, milter_documentation, - (PyObject*)NULL, PYTHON_API_VERSION); + m = PyModule_Create(&moduledef); d = PyModule_GetDict(m); MilterError = PyErr_NewException("milter.error", NULL, NULL); PyDict_SetItemString(d,"error", MilterError); @@ -1647,6 +1662,13 @@ initmilter(void) { #endif #ifdef SMFIF_SETSMLIST setitem(d,"SETSMLIST",SMFIF_SETSMLIST); + setitem(d,"M_CONNECT",SMFIM_CONNECT);/* connect */ + setitem(d,"M_HELO",SMFIM_HELO); /* HELO/EHLO */ + setitem(d,"M_ENVFROM",SMFIM_ENVFROM);/* MAIL From */ + setitem(d,"M_ENVRCPT",SMFIM_ENVRCPT);/* RCPT To */ + setitem(d,"M_DATA",SMFIM_DATA); /* DATA */ + setitem(d,"M_EOM",SMFIM_EOM); /* end of message (final dot) */ + setitem(d,"M_EOH",SMFIM_EOH); /* end of header */ #endif #ifdef SMFIS_ALL_OPTS setitem(d,"P_RCPT_REJ",SMFIP_RCPT_REJ); @@ -1679,4 +1701,5 @@ initmilter(void) { setitem(d,"DISCARD", SMFIS_DISCARD); setitem(d,"ACCEPT", SMFIS_ACCEPT); setitem(d,"TEMPFAIL", SMFIS_TEMPFAIL); + return m; }