[PATCH 1/10] rlm_python: 01---sanitize-rlm-python-t.patch

Paul P Komkoff Jr i at stingr.net
Mon Jan 30 23:17:50 CET 2006


- Sanitize rlm_python_t
- Remove typedef
- Introduce global PyObject radiusd_module
  (anyway we have only one interpreter)

---
commit 20b0202331f6bc26c46d3c91caf3c209a5958e01
tree 11c4bc223c448c60c4adce48e3fa56840be53e6d
parent fef24dfbd7872636bc466bb28637578b1f8604ca
author <stingray at boxster64.stingr.net> Sun, 29 Jan 2006 14:44:46 +0300
committer <stingray at boxster64.stingr.net> Sun, 29 Jan 2006 14:44:46 +0300

 src/modules/rlm_python/rlm_python.c |  128 ++++++++++++++++-------------------
 1 files changed, 60 insertions(+), 68 deletions(-)

diff --git a/src/modules/rlm_python/rlm_python.c b/src/modules/rlm_python/rlm_python.c
--- a/src/modules/rlm_python/rlm_python.c
+++ b/src/modules/rlm_python/rlm_python.c
@@ -42,55 +42,43 @@ static const char rcsid[] = "$Id: rlm_py
  *	a lot cleaner to do so, and a pointer to the structure can
  *	be used as the instance handle.
  */
-typedef struct rlm_python_t {
-    /* Config section */
 
-    /* Names of modules */
-    char
-        *mod_instantiate,
-        *mod_authorize,
-	*mod_authenticate,
-	*mod_preacct,
-	*mod_accounting,
-	*mod_checksimul,
-	*mod_detach,
-
-    /* Names of functions */
-        *func_instantiate,
-        *func_authorize,
-	*func_authenticate,
-	*func_preacct,
-	*func_accounting,
-	*func_checksimul,
-	*func_detach;
-
-
-    /* End Config section */
-
-
-    /* Python objects for modules */
-    PyObject
-        *pModule_builtin,
-        *pModule_instantiate,
-        *pModule_authorize,
-	*pModule_authenticate,
-	*pModule_preacct,
-	*pModule_accounting,
-	*pModule_checksimul,
-	*pModule_detach,
-
-
-	/* Functions */
-
-	*pFunc_instantiate,
-	*pFunc_authorize,
-	*pFunc_authenticate,
-	*pFunc_preacct,
-	*pFunc_accounting,
-	*pFunc_checksimul,
-	*pFunc_detach;
+struct rlm_python_t {
+        char    *mod_instantiate;
+        char    *mod_authorize;
+        char    *mod_authenticate;
+        char    *mod_preacct;
+        char    *mod_accounting;
+        char    *mod_checksimul;
+        char    *mod_detach;
+
+        /* Names of functions */
+        char    *func_instantiate;
+        char    *func_authorize;
+        char    *func_authenticate;
+        char    *func_preacct;
+        char    *func_accounting;
+        char    *func_checksimul;
+        char    *func_detach;
+
+        PyObject *pModule_instantiate;
+        PyObject *pModule_authorize;
+        PyObject *pModule_authenticate;
+        PyObject *pModule_preacct;
+        PyObject *pModule_accounting;
+        PyObject *pModule_checksimul;
+        PyObject *pModule_detach;
+
+        /* Functions */
+        PyObject *pFunc_instantiate;
+        PyObject *pFunc_authorize;
+        PyObject *pFunc_authenticate;
+        PyObject *pFunc_preacct;
+        PyObject *pFunc_accounting;
+        PyObject *pFunc_checksimul;
+        PyObject *pFunc_detach;
+};
 
-} rlm_python_t;
 
 /*
  *	A mapping of configuration file names to internal variables.
@@ -103,44 +91,49 @@ typedef struct rlm_python_t {
  */
 static CONF_PARSER module_config[] = {
   { "mod_instantiate",  PW_TYPE_STRING_PTR,
-    offsetof(rlm_python_t, mod_instantiate), NULL,  NULL},
+    offsetof(struct rlm_python_t, mod_instantiate), NULL,  NULL},
   { "func_instantiate",  PW_TYPE_STRING_PTR,
-    offsetof(rlm_python_t, func_instantiate), NULL,  NULL},
+    offsetof(struct rlm_python_t, func_instantiate), NULL,  NULL},
 
   { "mod_authorize",  PW_TYPE_STRING_PTR,
-    offsetof(rlm_python_t, mod_authorize), NULL,  NULL},
+    offsetof(struct rlm_python_t, mod_authorize), NULL,  NULL},
   { "func_authorize",  PW_TYPE_STRING_PTR,
-    offsetof(rlm_python_t, func_authorize), NULL,  NULL},
+    offsetof(struct rlm_python_t, func_authorize), NULL,  NULL},
 
   { "mod_authenticate",  PW_TYPE_STRING_PTR,
-    offsetof(rlm_python_t, mod_authenticate), NULL,  NULL},
+    offsetof(struct rlm_python_t, mod_authenticate), NULL,  NULL},
   { "func_authenticate",  PW_TYPE_STRING_PTR,
-    offsetof(rlm_python_t, func_authenticate), NULL,  NULL},
+    offsetof(struct rlm_python_t, func_authenticate), NULL,  NULL},
 
   { "mod_preacct",  PW_TYPE_STRING_PTR,
-    offsetof(rlm_python_t, mod_preacct), NULL,  NULL},
+    offsetof(struct rlm_python_t, mod_preacct), NULL,  NULL},
   { "func_preacct",  PW_TYPE_STRING_PTR,
-    offsetof(rlm_python_t, func_preacct), NULL,  NULL},
+    offsetof(struct rlm_python_t, func_preacct), NULL,  NULL},
 
   { "mod_accounting",  PW_TYPE_STRING_PTR,
-    offsetof(rlm_python_t, mod_accounting), NULL,  NULL},
+    offsetof(struct rlm_python_t, mod_accounting), NULL,  NULL},
   { "func_accounting",  PW_TYPE_STRING_PTR,
-    offsetof(rlm_python_t, func_accounting), NULL,  NULL},
+    offsetof(struct rlm_python_t, func_accounting), NULL,  NULL},
 
   { "mod_checksimul",  PW_TYPE_STRING_PTR,
-    offsetof(rlm_python_t, mod_checksimul), NULL,  NULL},
+    offsetof(struct rlm_python_t, mod_checksimul), NULL,  NULL},
   { "func_checksimul",  PW_TYPE_STRING_PTR,
-    offsetof(rlm_python_t, func_checksimul), NULL,  NULL},
+    offsetof(struct rlm_python_t, func_checksimul), NULL,  NULL},
 
   { "mod_detach",  PW_TYPE_STRING_PTR,
-    offsetof(rlm_python_t, mod_detach), NULL,  NULL},
+    offsetof(struct rlm_python_t, mod_detach), NULL,  NULL},
   { "func_detach",  PW_TYPE_STRING_PTR,
-    offsetof(rlm_python_t, func_detach), NULL,  NULL},
+    offsetof(struct rlm_python_t, func_detach), NULL,  NULL},
 
 
   { NULL, -1, 0, NULL, NULL }		/* end the list */
 };
 
+
+/* Let assume that radiusd module is only one since we have only one intepreter */
+
+static PyObject *radiusd_module = NULL;
+
 /*
  * radiusd Python functions
  */
@@ -570,8 +563,7 @@ static int load_python_function(const ch
  */
 static int python_instantiate(CONF_SECTION *conf, void **instance)
 {
-    rlm_python_t *data;
-    PyObject *module;
+    struct rlm_python_t *data;
     int idx;
 
     /*
@@ -598,7 +590,7 @@ static int python_instantiate(CONF_SECTI
      */
 
     /* Code */
-    if ((module = data->pModule_builtin =
+    if ((radiusd_module =
 	 Py_InitModule3("radiusd", radiusd_methods,
 			"FreeRADIUS Module.")) == NULL) {
 
@@ -611,7 +603,7 @@ static int python_instantiate(CONF_SECTI
      * Load constants into module
      */
     for (idx=0; constants[idx].name; idx++)
-	if ((PyModule_AddIntConstant(module, constants[idx].name, constants[idx].value)) == -1) {
+	if ((PyModule_AddIntConstant(radiusd_module, constants[idx].name, constants[idx].value)) == -1) {
 
 	    radlog(L_ERR, "Python AddIntConstant failed");
 	}
@@ -717,15 +709,15 @@ static int python_detach(void *instance)
     /* Default return value is failure */
     return_value = -1;
 
-    if (((rlm_python_t *)instance)->pFunc_detach &&
-	PyCallable_Check(((rlm_python_t *)instance)->pFunc_detach)) {
+    if (((struct rlm_python_t *)instance)->pFunc_detach &&
+	PyCallable_Check(((struct rlm_python_t *)instance)->pFunc_detach)) {
 
 	PyObject *pArgs, *pValue;
 
 	/* call the function with an empty tuple */
 
 	pArgs = PyTuple_New(0);
-	pValue = PyObject_CallObject(((rlm_python_t *)instance)->pFunc_detach,
+	pValue = PyObject_CallObject(((struct rlm_python_t *)instance)->pFunc_detach,
 				     pArgs);
 
 	if (pValue == NULL) {
-- 
Paul P 'Stingray' Komkoff Jr // http://stingr.net/key <- my pgp key
 This message represents the official view of the voices in my head



More information about the Freeradius-Devel mailing list