range* range_from_function(range_request* rr, const char* funcname, const range** r) { range* returned_ret; range* passed_ret; range* (*f)(range_request*, const range**); const char* plugin_module; libcrange* lr = range_request_lr(rr); // is this a perl function? plugin_module = libcrange_get_perl_module(lr, funcname); if (plugin_module) { return perl_function(rr, funcname, r); } // or python? plugin_module = libcrange_get_python_module(lr, funcname); if (plugin_module) { returned_ret = python_function(rr, funcname, r, &passed_ret); return passed_ret; } // or C? f = libcrange_get_function(lr, funcname); if (!f) { range_request_warn_type(rr, "NO_FUNCTION", funcname); return range_new(rr); } return (*f)(rr, r); }
/* * Do any per-module initialization that is separate to each * configured instance of the module. e.g. set up connections * to external databases, read configuration files, set up * dictionary entries, etc. * * If configuration information is given in the config section * that must be referenced in later calls, store a handle to it * in *instance otherwise put a null pointer there. * */ static int python_instantiate(CONF_SECTION *conf, void **instance) { struct rlm_python_t *data = NULL; /* * Set up a storage area for instance data */ if ((data = malloc(sizeof(*data))) == NULL) return -1; memset(data, 0, sizeof(*data)); if (python_init() != 0) { free(data); return -1; } /* * If the configuration parameters can't be parsed, then * fail. */ if (cf_section_parse(conf, data, module_config) < 0) { free(data); return -1; } #define A(x) if (python_load_function(&data->x) < 0) goto failed A(instantiate); A(authenticate); A(authorize); A(preacct); A(accounting); A(checksimul); A(pre_proxy); A(post_proxy); A(post_auth); #ifdef WITH_COA A(recv_coa); A(send_coa); #endif A(detach); #undef A *instance = data; /* * Call the instantiate function. No request. Use the * return value. */ return python_function(NULL, data->instantiate.function, "instantiate"); failed: python_error(); python_instance_clear(data); free(data); return -1; }
static int python_detach(void *instance) { struct rlm_python_t *data = (struct rlm_python_t *) instance; int ret; ret = python_function(NULL, data->detach.function, "detach"); python_instance_clear(data); free(data); return ret; }