INN commit: branches/2.4/nnrpd (python.c)
INN Commit
Russ_Allbery at isc.org
Sun Jun 22 10:24:42 UTC 2008
Date: Sunday, June 22, 2008 @ 03:24:42
Author: iulius
Revision: 7893
No need to check the existence of methods not used by the hooked script.
Modified:
branches/2.4/nnrpd/python.c
----------+
python.c | 68 ++++++++++++++++++++++++++++++++-----------------------------
1 file changed, 36 insertions(+), 32 deletions(-)
Modified: python.c
===================================================================
--- python.c 2008-06-22 10:20:13 UTC (rev 7892)
+++ python.c 2008-06-22 10:24:42 UTC (rev 7893)
@@ -611,34 +611,38 @@
** the corresponding PyObject, or NULL if not found.
*/
void
-PYdefonemethod(PyFile *fp, int type, int method, char *methname) {
+PYdefonemethod(PyFile *fp, int type, int method, char *methname, int realtype) {
PyObject **methptr;
methptr = &fp->procs[type][method];
+ /* There is no need to check the existence of methods useless for our realtype. */
+ if (type == realtype) {
+ /*
+ ** We check with HasAttrString() the existence of the method because
+ ** otherwise, in case it does not exist, an exception is raised by Python,
+ ** although the result of the function is NULL.
+ */
+ if (PyObject_HasAttrString(PYAuthObject, (char *) methname) == 1) {
+ /* Get a pointer to given method. */
+ *methptr = PyObject_GetAttrString(PYAuthObject, (char *) methname);
+ } else {
+ *methptr = NULL;
+ }
- /*
- ** We check with HasAttrString() the existence of the method because
- ** otherwise, in case it does not exist, an exception is raised by Python,
- ** although the result of the function is NULL.
- */
- if (PyObject_HasAttrString(PYAuthObject, (char *) methname) == 1) {
- /* Get a pointer to given method. */
- *methptr = PyObject_GetAttrString(PYAuthObject, (char *) methname);
+ /* See if such method is defined */
+ if (*methptr == NULL)
+ syslog(L_NOTICE, "python method %s not found", methname);
+ else {
+ /* See if it is callable */
+ if (PyCallable_Check(*methptr) == 0) {
+ syslog(L_ERROR, "python object %s found but not a function", methname);
+ Py_DECREF(*methptr);
+ *methptr = NULL;
+ }
+ }
} else {
*methptr = NULL;
}
-
- /* See if such method is defined */
- if (*methptr == NULL)
- syslog(L_NOTICE, "python method %s not found", methname);
- else {
- /* See if it is callable */
- if (PyCallable_Check(*methptr) == 0) {
- syslog(L_ERROR, "python object %s found but not a function", methname);
- Py_DECREF(*methptr);
- *methptr = NULL;
- }
- }
}
@@ -647,34 +651,34 @@
** pointers to them so that we could call them from nnrpd.
*/
void
-PYdefmethods(PyFile *fp)
+PYdefmethods(PyFile *fp, int realtype)
{
/* Get a reference to authenticate() method */
- PYdefonemethod(fp, PYTHONauthen, PYTHONmain, "authenticate");
+ PYdefonemethod(fp, PYTHONauthen, PYTHONmain, "authenticate", realtype);
/* Get a reference to authen_init() method */
- PYdefonemethod(fp, PYTHONauthen, PYTHONinit, "authen_init");
+ PYdefonemethod(fp, PYTHONauthen, PYTHONinit, "authen_init", realtype);
/* Get a reference to authen_close() method */
- PYdefonemethod(fp, PYTHONauthen, PYTHONclose, "authen_close");
+ PYdefonemethod(fp, PYTHONauthen, PYTHONclose, "authen_close", realtype);
/* Get a reference to access() method */
- PYdefonemethod(fp, PYTHONaccess, PYTHONmain, "access");
+ PYdefonemethod(fp, PYTHONaccess, PYTHONmain, "access", realtype);
/* Get a reference to access_init() method */
- PYdefonemethod(fp, PYTHONaccess, PYTHONinit, "access_init");
+ PYdefonemethod(fp, PYTHONaccess, PYTHONinit, "access_init", realtype);
/* Get a reference to access_close() method */
- PYdefonemethod(fp, PYTHONaccess, PYTHONclose, "access_close");
+ PYdefonemethod(fp, PYTHONaccess, PYTHONclose, "access_close", realtype);
/* Get a reference to dynamic() method */
- PYdefonemethod(fp, PYTHONdynamic, PYTHONmain, "dynamic");
+ PYdefonemethod(fp, PYTHONdynamic, PYTHONmain, "dynamic", realtype);
/* Get a reference to dynamic_init() method */
- PYdefonemethod(fp, PYTHONdynamic, PYTHONinit, "dynamic_init");
+ PYdefonemethod(fp, PYTHONdynamic, PYTHONinit, "dynamic_init", realtype);
/* Get a reference to dynamic_close() method */
- PYdefonemethod(fp, PYTHONdynamic, PYTHONclose, "dynamic_close");
+ PYdefonemethod(fp, PYTHONdynamic, PYTHONclose, "dynamic_close", realtype);
}
@@ -708,7 +712,7 @@
ExitWithStats(1, false);
} else {
/* Set up pointers to known Python methods */
- PYdefmethods(fp);
+ PYdefmethods(fp, type);
}
hash_insert(files, file, fp);
More information about the inn-committers
mailing list