Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cellframe/python-cellframe
1 result
Show changes
Commits on Source (2)
Showing
with 763 additions and 34 deletions
......@@ -35,6 +35,8 @@ add_subdirectory(modules/dap-sdk/core)
add_subdirectory(modules/dap-sdk/crypto)
add_subdirectory(modules/dap-sdk/net/core)
add_subdirectory(modules/dap-sdk/net/client)
add_subdirectory(modules/dap-sdk/net/server/enc)
add_subdirectory(modules/dap-sdk/net/server/http)
add_subdirectory(modules/cellframe-sdk/common)
add_subdirectory(modules/cellframe-sdk/net)
add_subdirectory(modules/cellframe-sdk/gdb)
......@@ -54,6 +56,7 @@ add_subdirectory(modules/cellframe-sdk/wallet)
target_compile_options(dap_core PRIVATE "-fpic")
target_compile_options(dap_core_unix PRIVATE "-fpic")
target_compile_options(dap_app_cli PRIVATE "-fpic")
target_compile_options(dap_crypto PRIVATE "-fpic")
target_compile_options(dap_chain PRIVATE "-fpic")
......@@ -71,6 +74,7 @@ target_compile_options(dap_stream_ch PRIVATE "-fpic" )
target_compile_options(dap_stream_ch_chain_net PRIVATE "-fpic" )
target_compile_options(dap_stream_ch_chain PRIVATE "-fpic" )
target_compile_options(dap_chain_net_srv PRIVATE "-fpic" )
target_compile_options(dap_chain_net_srv_stake PRIVATE "-fpic")
if(NOT WIN32)
target_compile_options(dap_chain_net_srv_vpn PRIVATE "-fpic" )
endif()
......@@ -86,10 +90,12 @@ target_compile_options(dap_chain_cs_dag_pos PRIVATE "-fpic")
if (SUPPORT_PYTHON_PLUGINS)
file (GLOB APP_CONTEXT_HEADER
modules/plugins/include/dap_plugins_python_app_context.h)
add_definitions("-fpic")
add_definitions("-DDAP_SUPPORT_PYTHON_PLUGINS")
add_library(${PROJECT_NAME} STATIC ${PYTHON_CELLFRAME_SRCS} ${PYTHON_CELLFRAME_HEADERS})
add_library(${PROJECT_NAME} STATIC ${PYTHON_CELLFRAME_SRCS} ${APP_CONTEXT_HEADER} ${PYTHON_CELLFRAME_HEADERS})
else()
......@@ -156,6 +162,7 @@ target_compile_options(dap_stream_ch_chain_net_srv PRIVATE "-fpic")
target_compile_options(dap_chain_cs_dag PRIVATE "-fpic")
target_compile_options(dap_chain_cs_dag_poa PRIVATE "-fpic")
target_compile_options(dap_chain_cs_dag_pos PRIVATE "-fpic")
target_compile_options(dap_server_core_python_module PRIVATE "-fpic")
if (WIN32)
......@@ -166,6 +173,8 @@ endif()
target_link_libraries(${PROJECT_NAME} cellframe-sdk dap_python_module
dap_crypto_python_module
dap_server_core_python_module
dap_enc_server_python_module
dap_server_http_python_module
dap_chain_python_module
dap_chain_net_python_module
dap_chain_gdb_python_module
......
......@@ -414,13 +414,20 @@ PyMODINIT_FUNC PyInit_libCellFrame(void){
PyType_Ready(&DapChainGDBObject_DapChainGDBType) < 0 ||
PyType_Ready(&DapHTTP_DapHTTPType) < 0 ||
PyType_Ready(&DapEncHTTP_DapEncHTTPType) < 0 ||
PyType_Ready(&DapEncServer_DapEncServerType) < 0 ||
PyType_Ready(&DapStream_DapStreamType) < 0 ||
PyType_Ready(&DapStreamCtl_DapStreamCtlType) < 0 ||
PyType_Ready(&DapMempool_DapMempoolType) < 0 ||
// ====
PyType_Ready(&DapAppCli_dapAppCliType ) < 0 ||
PyType_Ready(&DapChainWallet_dapChainWalletType) < 0
PyType_Ready(&DapChainWallet_dapChainWalletType) < 0 ||
PyType_Ready(&HTTPCode_HTTPCodeType) < 0 ||
#ifdef DAP_SUPPORT_PYTHON_PLUGINS
PyType_Ready(&DapHTTPSimple_DapHTTPSimpleType) < 0 ||
PyType_Ready(&dapAppContext_dapAppContextType) < 0
#else
PyType_Ready(&DapHTTPSimple_DapHTTPSimpleType) < 0
#endif
){
log_it(L_CRITICAL,"Not all py modules are ready for init");
return NULL;
......@@ -494,7 +501,9 @@ PyMODINIT_FUNC PyInit_libCellFrame(void){
PyModule_AddObject(module, "ChainWallet", (PyObject*)&DapChainWallet_dapChainWalletType);
PyModule_AddObject(module, "Http", (PyObject*)&DapHTTP_DapHTTPType);
PyModule_AddObject(module, "EncHttp", (PyObject*)&DapEncHTTP_DapEncHTTPType);
PyModule_AddObject(module, "HttpSimple", (PyObject*)&DapHTTPSimple_DapHTTPSimpleType);
PyModule_AddObject(module, "HttpCode", (PyObject*)&HTTPCode_HTTPCodeType);
PyModule_AddObject(module, "EncHttp", (PyObject*)&DapEncServer_DapEncServerType);
PyModule_AddObject(module, "Stream", (PyObject*)&DapStream_DapStreamType);
PyModule_AddObject(module, "StreamCtl", (PyObject*)&DapStreamCtl_DapStreamCtlType);
PyModule_AddObject(module, "Mempool", (PyObject*)&DapMempool_DapMempoolType);
......@@ -502,6 +511,9 @@ PyMODINIT_FUNC PyInit_libCellFrame(void){
// ==============
PyModule_AddObject(module, "AppCli", (PyObject*)&DapAppCli_dapAppCliType);
PyModule_AddObject(module, "AppCliServer", (PyObject*)&DapChainNodeCliObject_DapChainNodeCliObjectType);
#ifdef DAP_SUPPORT_PYTHON_PLUGINS
PyModule_AddObject(module, "AppContext", (PyObject*)&dapAppContext_dapAppContextType);
#endif
return module;
}
......
#include "wrapping_dap_enc_http.h"
PyObject *enc_http_add_proc_py(PyObject *self, PyObject *args){
PyObject *obj_server;
const char *HTTP_URL;
if (!PyArg_ParseTuple(args, "O|s", &obj_server, &HTTP_URL))
return NULL;
enc_http_add_proc(DAP_HTTP(((PyDapServerObject*)obj_server)->t_server), HTTP_URL);
return PyLong_FromLong(0);
}
Subproject commit 2cf9459cd7f5faca341a3793433fbf17e6c84afa
Subproject commit eec40837af57d515dee388bfee64c3f06abcbb0b
......@@ -67,6 +67,12 @@
BOOL WINAPI consoleHandler(DWORD);
#else
#include "signal.h"
#include "wrapping_http_status_code.h"
#include "wrapping_dap_http_simple.h"
#ifdef DAP_SUPPORT_PYTHON_PLUGINS
#include "../modules/plugins/include/dap_plugins_python_app_context.h"
#endif
void sigfunc(int sig);
#endif
......
project(dap_enc_server_python_module C)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_COLOR_MAKEFILE ON)
set(CMAKE_C_STANDARD 11)
add_definitions("-fpic")
if(NOT (${SUBMODULES_NO_BUILD} MATCHES ON))
if (NOT (TARGET dap_core))
add_subdirectory(libdap)
target_compile_options(
dap_core PRIVATE
"-fpic"
)
endif()
endif()
file(GLOB ENC_SERVER_SRCS src/*.c)
file(GLOB ENC_SERVER_HEADERS include/*.h)
set(Python_ADDITIONAL_VERSIONS 3.7 3.6 3.5 3.4)
find_package (PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIR} include/ )
add_library(${PROJECT_NAME} STATIC ${ENC_SERVER_SRCS} ${ENC_SERVER_HEADERS})
target_link_libraries(${PROJECT_NAME} ${PYTHON_LIBRARIES})
target_compile_options(
dap_core PRIVATE
"-fpic"
)
target_link_libraries(${PROJECT_NAME} dap_core dap_http_server dap_enc_server dap_server_core_python_module dap_server_http_python_module ${PYTHON_LIBRARIES})
target_include_directories(${PROJECT_NAME} PUBLIC include/ )
#if(BUILD_DAP_PYTHON_TESTS)
# add_subdirectory(test)
# file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/main_test.py
# DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test/)
#endif()
#pragma once
#include "dap_common.h"
#include "dap_enc_http.h"
#include "dap_server_python.h"
#include "dap_http.h"
#include "dap_http_simple.h"
#include "wrapping_dap_http_simple.h"
#include "Python.h"
typedef struct PyDapEncServer{
PyObject_HEAD
enc_http_delegate_t *enc_http_delegate;
}PyDapEncServerObject;
PyObject *enc_http_reply_py(PyObject *self, PyObject *args);
PyObject *enc_http_request_decode_py(PyObject *self, PyObject *args);
PyObject *enc_http_is_null_py(PyObject *self, PyObject *args);
PyObject *enc_http_reply_encode_py(PyObject *self, PyObject *args);
void enc_http_delegate_delete_py(PyObject *self);
PyObject *enc_http_add_proc_py(PyObject *self, PyObject *args);
static PyMethodDef PyDapEncServerMethods[] = {
{"requestDecode", enc_http_request_decode_py, METH_VARARGS | METH_STATIC, ""},
{"isNull", enc_http_is_null_py, METH_NOARGS, ""},
{"reply", enc_http_reply_py, METH_VARARGS, ""},
{"replyEncode", enc_http_reply_encode_py, METH_VARARGS, ""},
{"addProc", enc_http_add_proc_py, METH_VARARGS | METH_STATIC, ""},
{NULL, NULL, 0, NULL}
};
PyObject *enc_http_get_action_py(PyDapEncServerObject *self, void *clouser);
PyObject *enc_http_get_request_py(PyDapEncServerObject *self, void *clouser);
PyObject *enc_http_get_url_path_py(PyDapEncServerObject *self, void *clouser);
PyObject *enc_http_get_in_query_py(PyDapEncServerObject *self, void *clouser);
static PyGetSetDef PyDapEncServerGetSet[] = {
{"action", (getter)enc_http_get_action_py, NULL, "Return action request", NULL},
{"request", (getter)enc_http_get_request_py, NULL, "Return request in view bytes", NULL},
{"urlPath", (getter)enc_http_get_url_path_py, NULL, "Return request in view bytes", NULL},
{"query", (getter)enc_http_get_in_query_py, NULL, "Return request in view bytes", NULL},
{NULL}
};
static PyTypeObject DapEncServer_DapEncServerType = {
PyVarObject_HEAD_INIT(NULL, 0)
"CellFrame.EncHttp", /* tp_name */
sizeof(PyDapEncServerObject), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)enc_http_delegate_delete_py, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT |
Py_TPFLAGS_BASETYPE, /* tp_flags */
"Dap enc server object", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
PyDapEncServerMethods, /* tp_methods */
0, /* tp_members */
PyDapEncServerGetSet, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
PyType_GenericNew, /* tp_new */
};
#include "wrapping_dap_enc_http.h"
PyObject *enc_http_reply_py(PyObject *self, PyObject *args){
PyObject *l_obj_bytes;
if (!PyArg_ParseTuple(args, "O", &l_obj_bytes)){
return NULL;
}
size_t l_bytes_size = (size_t)PyBytes_Size(l_obj_bytes);
void *l_bytes = PyBytes_AsString(l_obj_bytes);
size_t l_len = enc_http_reply(((PyDapEncServerObject*)self)->enc_http_delegate, l_bytes, l_bytes_size);
return PyLong_FromLong(l_len);
}
PyObject *enc_http_request_decode_py(PyObject *self, PyObject *args){
(void)self;
PyObject *obj_sh;
if (!PyArg_ParseTuple(args, "O", &obj_sh)){
return NULL;
}
PyDapEncServerObject *obj_enc_delegate = PyObject_NEW(PyDapEncServerObject, &DapEncServer_DapEncServerType);
PyObject_Dir((PyObject*)obj_enc_delegate);
obj_enc_delegate->enc_http_delegate = enc_http_request_decode(((PyDapHttpSimpleObject*)obj_sh)->sh);
return Py_BuildValue("O", obj_enc_delegate);
}
PyObject *enc_http_is_null_py(PyObject *self, PyObject *args){
(void)args;
if (((PyDapEncServerObject*)self)->enc_http_delegate)
return Py_BuildValue("O", Py_False);
else
return Py_BuildValue("O", Py_True);
}
PyObject *enc_http_reply_encode_py(PyObject *self, PyObject *args){
PyObject *l_obj_sh;
if (!PyArg_ParseTuple(args, "O", &l_obj_sh)){
return NULL;
}
enc_http_reply_encode(((PyDapHttpSimpleObject*)l_obj_sh)->sh, ((PyDapEncServerObject*)self)->enc_http_delegate);
return Py_BuildValue("(O)", Py_None);
}
void enc_http_delegate_delete_py(PyObject *self){
PyTypeObject *tp = Py_TYPE(self);
if (((PyDapEncServerObject*)self)->enc_http_delegate){
enc_http_delegate_delete(((PyDapEncServerObject*)self)->enc_http_delegate);
}
tp->tp_free(self);
Py_DECREF(self);
}
PyObject *enc_http_add_proc_py(PyObject *self, PyObject *args){
(void)self;
PyObject *obj_server;
const char *HTTP_URL;
if (!PyArg_ParseTuple(args, "O|s", &obj_server, &HTTP_URL))
return NULL;
enc_http_add_proc(DAP_HTTP(((PyDapServerObject*)obj_server)->t_server), HTTP_URL);
return PyLong_FromLong(0);
}
PyObject *enc_http_get_action_py(PyDapEncServerObject *self, void *clouser){
(void)clouser;
return Py_BuildValue("s", self->enc_http_delegate->action);
}
PyObject *enc_http_get_request_py(PyDapEncServerObject *self, void *clouser){
(void)clouser;
if (self->enc_http_delegate->request){
return PyBytes_FromString(self->enc_http_delegate->request);
}else{
return Py_None;
}
}
PyObject *enc_http_get_url_path_py(PyDapEncServerObject *self, void *clouser){
(void)clouser;
return Py_BuildValue("s", self->enc_http_delegate->url_path);
}
PyObject *enc_http_get_in_query_py(PyDapEncServerObject *self, void *clouser){
(void)clouser;
return Py_BuildValue("s", self->enc_http_delegate->in_query);
}
project(dap_server_http_python_module C)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_COLOR_MAKEFILE ON)
set(CMAKE_C_STANDARD 11)
add_definitions("-fpic")
if(NOT (${SUBMODULES_NO_BUILD} MATCHES ON))
if (NOT (TARGET dap_core))
add_subdirectory(libdap)
target_compile_options(
dap_core PRIVATE
"-fpic"
)
endif()
endif()
file(GLOB SERVER_HTTP_SIMPLE_SRCS src/*.c)
file(GLOB SERVER_HTTP_SIMPLE_HEADERS include/*.h)
set(Python_ADDITIONAL_VERSIONS 3.7 3.6 3.5 3.4)
find_package (PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIR} include/ )
add_library(${PROJECT_NAME} STATIC ${SERVER_HTTP_SIMPLE_SRCS} ${SERVER_HTTP_SIMPLE_HEADERS} ${CORE_UNIX_SRCS})
target_link_libraries(${PROJECT_NAME} ${PYTHON_LIBRARIES})
target_compile_options(
dap_core PRIVATE
"-fpic"
)
target_link_libraries(${PROJECT_NAME} dap_core dap_http_server dap_server_core_python_module ${PYTHON_LIBRARIES})
target_include_directories(${PROJECT_NAME} PUBLIC include/ )
#if(BUILD_DAP_PYTHON_TESTS)
# add_subdirectory(test)
# file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/main_test.py
# DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test/)
#endif()
#pragma once
#include "dap_common.h"
#include "dap_strfuncs.h"
#include "dap_http_simple.h"
#include "Python.h"
#include "wrapping_http.h"
#include "wrapping_http_status_code.h"
#include "libdap-server-core-python.h"
#include "uthash.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct PyDapHttpSimple{
PyObject_HEAD
dap_http_simple_t *sh;
}PyDapHttpSimpleObject;
PyObject *dap_http_simple_add_proc_py(PyObject *self, PyObject *args);
PyObject *dap_http_simple_module_init_py(PyObject *self, PyObject *args);
PyObject *dap_http_simple_module_deinit_py(PyObject *self, PyObject *args);
PyObject *dap_http_simple_set_supported_user_agents_py(PyObject *self, PyObject *args);
PyObject *dap_http_simple_set_pass_unknown_user_agents_py(PyObject *self, PyObject *args);
PyObject *dap_http_simple_reply_py(PyObject *self, PyObject *args);
static PyMethodDef PyDapHttpSimpleMethods[] = {
//{"addProc", enc_http_add_proc_py, METH_VARARGS | METH_STATIC, ""},
{"init", dap_http_simple_module_init_py, METH_NOARGS | METH_STATIC, "Initialization module http simple"},
{"deinit", dap_http_simple_module_deinit_py, METH_NOARGS | METH_STATIC, "Deinitialization module http simple"},
{"addProc", dap_http_simple_add_proc_py, METH_VARARGS | METH_STATIC, "Add HTTP URL"},
{"setPassUnknownUserAgents", dap_http_simple_set_pass_unknown_user_agents_py, METH_VARARGS | METH_STATIC, ""},
{"replyAdd", dap_http_simple_reply_py, METH_VARARGS, "Reply for request"},
{NULL, NULL, 0, NULL}
};
/* Attributes */
PyObject *dap_http_simple_method_py(PyDapHttpSimpleObject *self, void *clouser);
PyObject *dap_http_simple_request_py(PyDapHttpSimpleObject *self, void *clouser);
PyObject *dap_http_simple_url_path_py(PyDapHttpSimpleObject *self, void *clouser);
PyObject *dap_http_simple_query_py(PyDapHttpSimpleObject *self, void *clouser);
static PyGetSetDef PyDapHttpSimpleGetSetDef[] = {
{"action", (getter)dap_http_simple_method_py, NULL, "Return action request", NULL},
{"request", (getter)dap_http_simple_request_py, NULL, "Return request in view bytes", NULL},
{"urlPath", (getter)dap_http_simple_url_path_py, NULL, "Return request in view bytes", NULL},
{"query", (getter)dap_http_simple_query_py, NULL, "Return request in view bytes", NULL},
{NULL}
};
/*------------*/
static PyTypeObject DapHTTPSimple_DapHTTPSimpleType = {
PyVarObject_HEAD_INIT(NULL, 0)
"CellFrame.HttpSimple", /* tp_name */
sizeof(PyDapHttpSimpleObject), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT |
Py_TPFLAGS_BASETYPE, /* tp_flags */
"Dap http simple object", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
PyDapHttpSimpleMethods, /* tp_methods */
0, /* tp_members */
PyDapHttpSimpleGetSetDef, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
PyType_GenericNew, /* tp_new */
};
#ifdef __cplusplus
}
#endif
......@@ -5,8 +5,13 @@
#include "dap_http.h"
#include "dap_server_python.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct PyDapHttp{
PyObject_HEAD
struct dap_http *http;
}PyDapHttpObject;
PyObject *dap_http_new_py(PyObject *self, PyObject *args);
......@@ -38,7 +43,7 @@ static PyTypeObject DapHTTP_DapHTTPType = {
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT |
Py_TPFLAGS_BASETYPE, /* tp_flags */
"Dap hHttp object", /* tp_doc */
"Dap Http object", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
......@@ -58,4 +63,8 @@ static PyTypeObject DapHTTP_DapHTTPType = {
PyType_GenericNew, /* tp_new */
};
#ifdef __cplusplus
}
#endif
#endif // _WRAPPING_HTTP_
#pragma once
#include "dap_common.h"
#include "http_status_code.h"
#include "Python.h"
#define LOG_TAG "wrapping_http_status_code"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct PyHTTPStatusCode{
PyObject_HEAD
http_status_code_t http_status;
}PyHttpStatusCodeObject;
static http_status_code_t _get_status_code_from_init(int a_code){
switch (a_code) {
// case
/*####### 1xx - Informational #######*/
case 100: return Http_Status_OK;
case 101: return Http_Status_SwitchingProtocols;
case 102: return Http_Status_Processing;
case 103: return Http_Status_EarlyHints;
/*####### 2xx - Successful #######*/
case 200: return Http_Status_OK;
case 201: return Http_Status_Created;
case 202: return Http_Status_Accepted;
case 203: return Http_Status_NonAuthoritativeInformation;
case 204: return Http_Status_NoContent;
case 205: return Http_Status_ResetContent;
case 206: return Http_Status_PartialContent;
case 207: return Http_Status_MultiStatus;
case 208: return Http_Status_AlreadyReported;
case 226: return Http_Status_IMUsed;
/*####### 3xx - Redirection #######*/
case 300: return Http_Status_MultipleChoices;
case 301: return Http_Status_MovedPermanently;
case 302: return Http_Status_Found;
case 303: return Http_Status_SeeOther;
case 304: return Http_Status_NotModified;
case 305: return Http_Status_UseProxy;
case 307: return Http_Status_TemporaryRedirect;
case 308: return Http_Status_PermanentRedirect;
/*####### 4xx - Client Error #######*/
case 400: return Http_Status_BadRequest;
case 401: return Http_Status_Unauthorized;
case 402: return Http_Status_PaymentRequired;
case 403: return Http_Status_Forbidden;
case 404: return Http_Status_NotFound;
case 405: return Http_Status_MethodNotAllowed;
case 406: return Http_Status_NotAcceptable;
case 407: return Http_Status_ProxyAuthenticationRequired;
case 408: return Http_Status_RequestTimeout;
case 409: return Http_Status_Conflict;
case 410: return Http_Status_Gone;
case 411: return Http_Status_LengthRequired;
case 412: return Http_Status_PreconditionFailed;
case 413: return Http_Status_PayloadTooLarge;
case 414: return Http_Status_URITooLong;
case 415: return Http_Status_UnsupportedMediaType;
case 416: return Http_Status_RangeNotSatisfiable;
case 417: return Http_Status_ExpectationFailed;
case 418: return Http_Status_ImATeapot;
case 422: return Http_Status_UnprocessableEntity;
case 423: return Http_Status_Locked;
case 424: return Http_Status_FailedDependency;
case 426: return Http_Status_UpgradeRequired;
case 428: return Http_Status_PreconditionRequired;
case 429: return Http_Status_TooManyRequests;
case 431: return Http_Status_RequestHeaderFieldsTooLarge;
case 451: return Http_Status_UnavailableForLegalReasons;
/*####### 5xx - Server Error #######*/
case 500: return Http_Status_InternalServerError;
case 501: return Http_Status_NotImplemented;
case 502: return Http_Status_BadGateway;
case 503: return Http_Status_ServiceUnavailable;
case 504: return Http_Status_GatewayTimeout;
case 505: return Http_Status_HTTPVersionNotSupported;
case 506: return Http_Status_VariantAlsoNegotiates;
case 507: return Http_Status_InsufficientStorage;
case 508: return Http_Status_LoopDetected;
case 510: return Http_Status_NotExtended;
default:
log_it(L_ERROR, "Unknown status code %d. Returned default status: Internal Server Error", a_code);
return Http_Status_InternalServerError;
}
}
static PyObject *wrapping_http_status_code_set_py(PyObject *self, PyObject *args){
PyObject *l_obj_status_code;
if (!PyArg_ParseTuple(args, "O", &l_obj_status_code)){
return NULL;
}
if (PyLong_Check(l_obj_status_code)){
int code = PyLong_AsLong(l_obj_status_code);
((PyHttpStatusCodeObject*)self)->http_status = _get_status_code_from_init(code);
}
return Py_None;
}
static PyObject *wrapping_http_code_set_ok(PyObject *self, PyObject *args){
(void)args;
((PyHttpStatusCodeObject*)self)->http_status = Http_Status_OK;
return Py_None;
}
static PyObject *wrapping_http_code_set_bad_request(PyObject *self, PyObject *args){
(void)args;
((PyHttpStatusCodeObject*)self)->http_status = Http_Status_BadRequest;
return Py_None;
}
static PyMethodDef PyDapHttpCodeMethods[] = {
{"set", wrapping_http_status_code_set_py, METH_VARARGS, "Set status code Http response"},
{"OK", wrapping_http_code_set_ok, METH_NOARGS, "Set status code OK for this object"},
{"BadRequest", wrapping_http_code_set_bad_request, METH_NOARGS, "Set status code Bad request for this object"},
{NULL, NULL, 0, NULL}
};
static PyTypeObject HTTPCode_HTTPCodeType = {
PyVarObject_HEAD_INIT(NULL, 0)
"CellFrame.HTTPCode", /* tp_name */
sizeof(PyHttpStatusCodeObject), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT |
Py_TPFLAGS_BASETYPE, /* tp_flags */
"Dap http code", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
PyDapHttpCodeMethods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
PyType_GenericNew, /* tp_new */
};
#ifdef __cplusplus
}
#endif
#include "wrapping_dap_http_simple.h"
#define LOG_TAG "wrapping_dap_http_simple"
typedef struct wrapping_dap_http_simple_proc{
char *url;
PyObject *func_call;
UT_hash_handle hh;
}wrapping_dap_http_simple_proc_t;
static wrapping_dap_http_simple_proc_t *s_simple_proc = NULL;
void _w_simple_proc_add(const char *url, PyObject *func_call){
wrapping_dap_http_simple_proc_t *l_simple_proc = DAP_NEW(wrapping_dap_http_simple_proc_t);
l_simple_proc->url = dap_strdup(url);
l_simple_proc->func_call = func_call;
Py_XINCREF(l_simple_proc->func_call);
HASH_ADD_STR(s_simple_proc, url, l_simple_proc);
}
PyObject *_w_simple_proc_find(const char *url){
wrapping_dap_http_simple_proc_t *l_http_simple_proc = NULL;
HASH_FIND_STR(s_simple_proc, url, l_http_simple_proc);
return l_http_simple_proc->func_call;
}
void wrapping_dap_http_simple_callback(dap_http_simple_t *sh, void *obj){
log_it(L_DEBUG, "Handling C module request");
PyObject *obj_func = _w_simple_proc_find(sh->http_client->url_path);
PyDapHttpSimpleObject *obj_http_simple = PyObject_NEW(PyDapHttpSimpleObject, &DapHTTPSimple_DapHTTPSimpleType);
PyObject *obj_http_status_code = _PyObject_New(&HTTPCode_HTTPCodeType);
((PyDapHttpSimpleObject*)obj_http_simple)->sh = sh;
PyObject_Dir((PyObject*)obj_http_simple);
http_status_code_t *ret = (http_status_code_t*)obj;
((PyHttpStatusCodeObject*)obj_http_status_code)->http_status = *ret;
PyObject_Dir((PyObject*)obj_http_status_code);
PyObject *obj_argv = Py_BuildValue("OO", obj_http_simple, obj_http_status_code);
PyObject *result = PyObject_CallObject(obj_func, obj_argv);
if (!result){
log_it(L_DEBUG, "Function can't called");
PyErr_Print();
*ret = Http_Status_InternalServerError;
}
*ret = ((PyHttpStatusCodeObject*)obj_http_status_code)->http_status;
// Py_XDECREF(obj_argv);
// Py_XDECREF(obj_http_status_code);
// Py_XDECREF(obj_http_simple);
}
PyObject *dap_http_simple_add_proc_py(PyObject *self, PyObject *args){
(void)self;
PyObject *obj_server;
char *url;
size_t reply_size_max;
PyObject *func_callback;
if (!PyArg_ParseTuple(args, "OsKO", &obj_server, &url, &reply_size_max, &func_callback)){
return NULL;
} else {
if (!PyCallable_Check(func_callback)){
PyErr_SetString(PyExc_TypeError, "parameter must be callable");
return NULL;
}
}
_w_simple_proc_add(url, func_callback);
dap_http_t *l_http = DAP_HTTP(((PyDapServerObject*)obj_server)->t_server);
dap_http_simple_proc_add(l_http,
url,
reply_size_max,
wrapping_dap_http_simple_callback);
log_it(L_NOTICE, "Add proc URL %s, python plugin", url);
return Py_BuildValue("(O)", Py_None);
}
PyObject *dap_http_simple_module_init_py(PyObject *self, PyObject *args){
(void)self;
(void)args;
int res = dap_http_simple_module_init();
return PyLong_FromLong(res);
}
PyObject *dap_http_simple_module_deinit_py(PyObject *self, PyObject *args){
(void)self;
(void)args;
dap_http_simple_module_deinit();
return Py_BuildValue("(O)", Py_None);
}
PyObject *dap_http_simple_set_supported_user_agents_py(PyObject *self, PyObject *args){
(void)self;
// TODO: Implement
return NULL;
}
PyObject *dap_http_simple_set_pass_unknown_user_agents_py(PyObject *self, PyObject *args){
(void)self;
bool res = false;
if (!PyArg_ParseTuple(args, "p", &res)){
return NULL;
}
dap_http_simple_set_pass_unknown_user_agents(res);
return Py_BuildValue("(O)", Py_None);
}
PyObject *dap_http_simple_reply_py(PyObject *self, PyObject *args){
PyObject *l_obj_bytes;
if (!PyArg_ParseTuple(args, "O", &l_obj_bytes)){
return NULL;
}
if (!PyBytes_Check(l_obj_bytes)){
PyErr_SetString(PyExc_TypeError, "The passed parameter is not byte");
return NULL;
}
size_t l_bytes_size = (size_t)PyBytes_Size(l_obj_bytes);
void *l_bytes = PyBytes_AsString(l_obj_bytes);
size_t l_size = dap_http_simple_reply(((PyDapHttpSimpleObject*)self)->sh, l_bytes, l_bytes_size);
// DAP_FREE(l_bytes);
return PyLong_FromLong(l_size);
}
PyObject *dap_http_simple_method_py(PyDapHttpSimpleObject *self, void *clouser){
(void)clouser;
return Py_BuildValue("s", self->sh->http_client->action);
}
PyObject *dap_http_simple_request_py(PyDapHttpSimpleObject *self, void *clouser){
(void)clouser;
if (self->sh->request)
return PyBytes_FromString(self->sh->request);
else
return Py_None;
}
PyObject *dap_http_simple_url_path_py(PyDapHttpSimpleObject *self, void *clouser){
(void)clouser;
return Py_BuildValue("s", self->sh->http_client->url_path);
}
PyObject *dap_http_simple_query_py(PyDapHttpSimpleObject *self, void *clouser){
(void)clouser;
return Py_BuildValue("s", self->sh->http_client->in_query_string);
}
#include "wrapping_http.h"
PyObject *dap_http_new_py(PyObject *self, PyObject *args){
PyObject *obj_server;
const char * name;
......
#ifndef _WRAPPING_DAP_ENC_HTTP_
#define _WRAPPING_DAP_ENC_HTTP_
#pragma once
#include <Python.h>
#include "dap_common.h"
#include "dap_server.h"
#include "dap_server_python.h"
#include "dap_enc_http.h"
#include "dap_http.h"
#include "wrapping_http.h"
#include <Python.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct dap_plugins_python_app_context{
dap_server_t *server;
}dap_plugins_python_app_context_t;
typedef struct PyDapEncHttp{
int dap_plugins_python_app_content_init(dap_server_t *a_server);
typedef struct PyDapAppContext{
PyObject_HEAD
}PyDapEncHttpObject;
}PyDapAppContextObject;
PyObject *enc_http_add_proc_py(PyObject *self, PyObject *args);
PyObject *dap_plugins_python_app_context_get_server(PyObject *self, PyObject *args);
PyObject *dap_plugins_python_app_context_get_http(PyObject *self, PyObject *args);
static PyMethodDef DapEncHttpMethods[] = {
{"addProc", enc_http_add_proc_py, METH_VARARGS | METH_STATIC, ""},
static PyMethodDef DapAppContextMethods[] = {
{"getServer", (PyCFunction)dap_plugins_python_app_context_get_server, METH_VARARGS | METH_STATIC, "Get main server from node"},
{"getHttp", (PyCFunction)dap_plugins_python_app_context_get_http, METH_NOARGS | METH_STATIC, "Get main server from node"},
{NULL, NULL, 0, NULL}
};
static PyTypeObject DapEncHTTP_DapEncHTTPType = {
static PyTypeObject dapAppContext_dapAppContextType = {
PyVarObject_HEAD_INIT(NULL, 0)
"CellFrame.DapEncHttp", /* tp_name */
sizeof(PyDapEncHttpObject), /* tp_basicsize */
"CellFrame.AppContext", /* tp_name */
sizeof(PyDapAppContextObject), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
......@@ -39,14 +52,14 @@ static PyTypeObject DapEncHTTP_DapEncHTTPType = {
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT |
Py_TPFLAGS_BASETYPE, /* tp_flags */
"Dap enc http object", /* tp_doc */
"Dap App Context object", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
DapEncHttpMethods, /* tp_methods */
DapAppContextMethods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
......@@ -59,5 +72,6 @@ static PyTypeObject DapEncHTTP_DapEncHTTPType = {
PyType_GenericNew, /* tp_new */
};
#endif // _WRAPPING_DAP_ENC_HTTP_
#ifdef __cplusplus
}
#endif
......@@ -25,7 +25,7 @@ int dap_chain_plugins_init(dap_config_t *a_config){
log_it(L_ERROR, "The directory %s was not found.", s_plugins_root_path);
return -1;
}
PyImport_AppendInittab("CellFrame", PyInit_libCellFrame);
PyImport_AppendInittab("API_CellFrame", PyInit_libCellFrame);
Py_Initialize();
PyObject *l_sys_module = PyImport_ImportModule("sys");
s_sys_path = PyObject_GetAttrString(l_sys_module, "path");
......@@ -114,6 +114,7 @@ void dap_chain_plugins_load_plugin(const char *a_dir_path, const char *a_name){
PyList_Append(s_sys_path, l_obj_dir_path);
Py_XDECREF(l_obj_dir_path);
PyObject *l_module = PyImport_ImportModule(a_name);
PyErr_Print();
PyObject *l_func_init = PyObject_GetAttrString(l_module, "init");
PyObject *l_func_deinit = PyObject_GetAttrString(l_module, "deinit");
PyObject *l_res_int = NULL;
......@@ -128,6 +129,7 @@ void dap_chain_plugins_load_plugin(const char *a_dir_path, const char *a_name){
log_it(L_ERROR, "Code error %i at initialization %s plugin", _PyLong_AsInt(l_res_int), a_name);
}
} else {
PyErr_Print();
log_it(L_ERROR, "Function initialization %s plugin don't reterned integer value", a_name);
}
Py_XDECREF(l_res_int);
......
#include "dap_plugins_python_app_context.h"
dap_plugins_python_app_context_t *s_app_context = NULL;
int dap_plugins_python_app_content_init(dap_server_t *a_server){
s_app_context = DAP_NEW(dap_plugins_python_app_context_t);
s_app_context->server = a_server;
return 0;
}
PyObject *dap_plugins_python_app_context_get_server(PyObject *self, PyObject *args){
(void)self;
PyObject *l_obj_serverCore;
if (!PyArg_ParseTuple(args, "O", &l_obj_serverCore)){
return NULL;
}
((PyDapServerObject*)l_obj_serverCore)->t_server = s_app_context->server;
return Py_BuildValue("(O)", Py_None);
}
PyObject *dap_plugins_python_app_context_get_http(PyObject *self, PyObject *args){
(void)self;
(void)args;
PyDapHttpObject *l_obj_http = PyObject_NEW(PyDapHttpObject, &DapHTTP_DapHTTPType);
l_obj_http->http = DAP_HTTP(s_app_context->server);
return Py_BuildValue("(O)", l_obj_http);
}