static char* proxenet_python_execute_function(PyObject* pFuncRef, request_t *request) { PyObject *pArgs, *pResult; char *buffer, *result; int ret; Py_ssize_t len; char *uri = request->http_infos.uri; result = buffer = NULL; len = -1; pArgs = Py_BuildValue(PYTHON_VALUE_FORMAT, request->id, request->data, request->size, uri); if (!pArgs) { xlog_python(LOG_ERROR, "%s\n", "Failed to build args"); PyErr_Print(); return result; } pResult = PyObject_CallObject(pFuncRef, pArgs); if (!pResult) { xlog_python(LOG_ERROR, "%s\n", "Failed during func call"); PyErr_Print(); return result; } if (PyBytes_Check(pResult)) { ret = PyBytes_AsStringAndSize(pResult, &buffer, &len); if (ret<0) { PyErr_Print(); result = NULL; } else { result = proxenet_xstrdup(buffer, len); request->size = len; request->data = result; } } else { #if _PYTHON_MAJOR_ == 3 xlog_python(LOG_ERROR, "Incorrect return type (expected: %s)\n", "ByteArray"); #else xlog_python(LOG_ERROR, "Incorrect return type (expected: %s)\n", "String"); #endif result = NULL; } Py_DECREF(pResult); Py_DECREF(pArgs); return result; }
static char* proxenet_tcl_execute_function(interpreter_t* interpreter, request_t *request) { char *buf, *uri; Tcl_Interp* tcl_interpreter; Tcl_Obj* tcl_cmds_ptr; size_t len; int i; uri = request->http_infos.uri; if (!uri) return NULL; tcl_interpreter = (Tcl_Interp*) interpreter->vm; /* create the list of commands to be executed by TCL interpreter */ tcl_cmds_ptr = Tcl_NewListObj (0, NULL); Tcl_IncrRefCount(tcl_cmds_ptr); if (request->type == REQUEST) Tcl_ListObjAppendElement(tcl_interpreter, tcl_cmds_ptr, Tcl_NewStringObj(CFG_REQUEST_PLUGIN_FUNCTION, -1)); else Tcl_ListObjAppendElement(tcl_interpreter, tcl_cmds_ptr, Tcl_NewStringObj(CFG_RESPONSE_PLUGIN_FUNCTION, -1)); /* pushing arguments */ Tcl_ListObjAppendElement(tcl_interpreter, tcl_cmds_ptr, Tcl_NewIntObj(request->id)); Tcl_ListObjAppendElement(tcl_interpreter, tcl_cmds_ptr, Tcl_NewStringObj(request->data, request->size)); Tcl_ListObjAppendElement(tcl_interpreter, tcl_cmds_ptr, Tcl_NewStringObj(uri, -1)); /* execute the commands */ if (Tcl_EvalObjEx(tcl_interpreter, tcl_cmds_ptr, TCL_EVAL_DIRECT) != TCL_OK) { return NULL; } /* get the result */ Tcl_DecrRefCount(tcl_cmds_ptr); buf = Tcl_GetStringFromObj( Tcl_GetObjResult(tcl_interpreter), &i); if (!buf || i<=0) return NULL; len = (size_t)i; buf = proxenet_xstrdup(buf, len); if (!buf) return NULL; request->size = len; return buf; }
static char* proxenet_lua_execute_function(interpreter_t* interpreter, request_t *request) { const char *lRet; char *buf; lua_State* lua_interpreter; size_t len; char *uri; uri = request->http_infos.uri; if (!uri) return NULL; lua_interpreter = (lua_State*) interpreter->vm; if (request->type == REQUEST) lua_getglobal(lua_interpreter, CFG_REQUEST_PLUGIN_FUNCTION); else lua_getglobal(lua_interpreter, CFG_RESPONSE_PLUGIN_FUNCTION); lua_pushnumber(lua_interpreter, request->id); lua_pushlstring(lua_interpreter, request->data, request->size); lua_pushlstring(lua_interpreter, uri, strlen(uri)); lua_call(lua_interpreter, 3, 1); lRet = lua_tolstring(lua_interpreter, -1, &len); if (!lRet) return NULL; buf = proxenet_xstrdup(lRet, len); if (!buf) return NULL; request->size = len; return buf; }
/** * Wrapper for proxenet_xstrdup() using strlen() for determining argument length. * Should not be used if NULL bytes are in data. * * @param data : the source buffer to duplicate */ char* proxenet_xstrdup2(const char *data) { return proxenet_xstrdup(data, strlen(data)); }