int proxenet_ruby_initialize_function(plugin_t* plugin, req_t type) { /* checks */ if (!plugin->name) { xlog(LOG_ERROR, "%s\n", "null plugin name"); return -1; } if (proxenet_ruby_load_file(plugin) < 0) { xlog(LOG_ERROR, "Failed to load %s\n", plugin->filename); return -1; } /* get function ID */ switch(type) { case REQUEST: if (plugin->pre_function) { xlog(LOG_WARNING, "Pre-hook function already defined for '%s'\n", plugin->name); return 0; } plugin->pre_function = (void*) rb_intern(CFG_REQUEST_PLUGIN_FUNCTION); if (plugin->pre_function) { #ifdef DEBUG xlog(LOG_DEBUG, "Loaded %s:%s\n", plugin->filename, CFG_REQUEST_PLUGIN_FUNCTION); #endif return 0; } break; case RESPONSE: if (plugin->post_function) { xlog(LOG_WARNING, "Post-hook function already defined for '%s'\n", plugin->name); return 0; } plugin->post_function = (void*) rb_intern(CFG_RESPONSE_PLUGIN_FUNCTION); if (plugin->post_function) { #ifdef DEBUG xlog(LOG_DEBUG, "Loaded %s:%s\n", plugin->filename, CFG_RESPONSE_PLUGIN_FUNCTION); #endif return 0; } break; default: xlog(LOG_CRITICAL, "%s\n", "Should never be here, autokill !"); abort(); break; } xlog(LOG_ERROR, "%s\n", "Failed to find function"); return -1; }
void proxenet_initialize_plugins() { plugin_t *plugin = plugins_list; plugin_t *prec_plugin = NULL; plugin_t *next_plugin = NULL; while(plugin) { /* plugin already loaded, move on */ if(plugin->state == ACTIVE){ plugin = plugin->next; continue; } switch (plugin->type) { #ifdef _PYTHON_PLUGIN case _PYTHON_: if (!proxenet_python_initialize_vm(plugin) && !proxenet_python_load_file(plugin)) proxenet_plugin_set_state(plugin, ACTIVE); break; #endif #ifdef _C_PLUGIN case _C_: if (!proxenet_c_initialize_vm(plugin) && !proxenet_c_load_file(plugin)) proxenet_plugin_set_state(plugin, ACTIVE); break; #endif #ifdef _RUBY_PLUGIN case _RUBY_: if (!proxenet_ruby_initialize_vm(plugin) && !proxenet_ruby_load_file(plugin)) proxenet_plugin_set_state(plugin, ACTIVE); break; #endif #ifdef _PERL_PLUGIN case _PERL_: if (!proxenet_perl_initialize_vm(plugin) && !proxenet_perl_load_file(plugin)) proxenet_plugin_set_state(plugin, ACTIVE); break; #endif #ifdef _LUA_PLUGIN case _LUA_: if (!proxenet_lua_initialize_vm(plugin) && !proxenet_lua_load_file(plugin)) proxenet_plugin_set_state(plugin, ACTIVE); break; #endif #ifdef _TCL_PLUGIN case _TCL_: if (!proxenet_tcl_initialize_vm(plugin) && !proxenet_tcl_load_file(plugin)) proxenet_plugin_set_state(plugin, ACTIVE); break; #endif #ifdef _JAVA_PLUGIN case _JAVA_: if (!proxenet_java_initialize_vm(plugin) && !proxenet_java_load_file(plugin)) proxenet_plugin_set_state(plugin, ACTIVE); break; #endif default: break; } if (plugin->state == ACTIVE){ if (cfg->verbose > 1) xlog(LOG_INFO, "Successfully initialized '%s'\n", plugin->filename); prec_plugin = plugin; plugin = plugin->next; continue; } proxenet_plugin_set_state(plugin, INACTIVE); if(prec_plugin) prec_plugin->next = plugin->next; else plugins_list = plugin->next; if (cfg->verbose > 1) xlog(LOG_ERROR, "Removing '%s' from plugin list\n", plugin->filename); next_plugin = plugin->next; proxenet_free_plugin(plugin); plugin = next_plugin; } }