From 64b02adcae4bafa3205d7dd3c65124dc68f69b57 Mon Sep 17 00:00:00 2001 From: "alexey.stratulat" <alexey.stratulat@demlabs.net> Date: Wed, 18 Dec 2019 15:56:00 +0700 Subject: [PATCH] [+] Added initialize modules Http, EncHttp, Stream, StreamCtl --- include/python-cellframe.h | 6 +++++ libdap-stream-ch-chain-net-srv | 1 + src/python-cellframe.c | 49 +++++++++++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 1 deletion(-) create mode 160000 libdap-stream-ch-chain-net-srv diff --git a/include/python-cellframe.h b/include/python-cellframe.h index 69e90ba4..7f93a390 100644 --- a/include/python-cellframe.h +++ b/include/python-cellframe.h @@ -26,6 +26,12 @@ #include "wrapping_dap_chain_net_node_info.h" #include "wrapping_dap_chain_net_state.h" // ============ + +#include "wrapping_http.h" +#include "wrapping_dap_enc_http.h" +#include "wrapping_dap_stream.h" +#include "wrapping_dap_stream_ctl.h" + #include "dap_common.h" diff --git a/libdap-stream-ch-chain-net-srv b/libdap-stream-ch-chain-net-srv new file mode 160000 index 00000000..1f34d256 --- /dev/null +++ b/libdap-stream-ch-chain-net-srv @@ -0,0 +1 @@ +Subproject commit 1f34d25645ec14af02ea9e79df4acdf4256f0682 diff --git a/src/python-cellframe.c b/src/python-cellframe.c index 432eab7d..f5e61409 100644 --- a/src/python-cellframe.c +++ b/src/python-cellframe.c @@ -107,6 +107,43 @@ static PyObject *python_cellframe_init(PyObject *self, PyObject *args){ return NULL; } } + if (strcmp(c_value, "Http") == 0){ + if(dap_http_init() != 0){ + PyErr_SetString(CellFrame_error, "Failed to initialize Http module. "); + return NULL; + } + } + if (strcmp(c_value, "EncHttp") == 0){ + if(enc_http_init() != 0){ + PyErr_SetString(CellFrame_error, "Failed to initialize EncHttp module. "); + return NULL; + } + } + if (strcmp(c_value, "Stream") == 0){ + PyObject* getStreamData = PyDict_GetItemString(result, "Stream"); + if (getStreamData == NULL){ + PyErr_SetString(CellFrame_error, "Initialization failed. Stream object not found in JSON." + " No settings are specified for initializing libdap-stream-python."); + return NULL; + } + PyObject *debugDumpStreamHeadersObj = PyDict_GetItemString(getStreamData, "DebugDumpStreamHeaders"); + if (debugDumpStreamHeadersObj == NULL || !PyBool_Check(debugDumpStreamHeadersObj)){ + PyErr_SetString(CellFrame_error, "Failed to initialize Stream. " + "Fields DebugDumpStreamHeaders are not boolean type."); + return NULL; + } + bool res_bollean = (debugDumpStreamHeadersObj == Py_True) ? true : false; + if(dap_stream_init(res_bollean) != 0){ + PyErr_SetString(CellFrame_error, "Failed to initialize Stream module. "); + return NULL; + } + } + if (strcmp(c_value, "StreamCtl") == 0){ + if (dap_stream_ctl_init(DAP_ENC_KEY_TYPE_OAES, 32) != 0){ + PyErr_SetString(CellFrame_error, "Failed to initialize StreamCtl module. "); + return NULL; + } + } } return PyLong_FromLong(0); } @@ -151,8 +188,13 @@ PyMODINIT_FUNC PyInit_CellFrame(void){ PyType_Ready(&DapChainNodeClientObject_DapChainNodeClientObjectType) < 0 || PyType_Ready(&DapChainNodeInfoObject_DapChainNodeInfoObjectType) < 0 || PyType_Ready(&DapChainNetNodeObject_DapChainNetNodeObjectType) < 0 || - PyType_Ready(&DapChainNetStateObject_DapChainNetStateObjectType) < 0 + PyType_Ready(&DapChainNetStateObject_DapChainNetStateObjectType) < 0 || // ============= + + PyType_Ready(&DapHTTP_DapHTTPType) < 0 || + PyType_Ready(&DapEncHTTP_DapEncHTTPType) < 0 || + PyType_Ready(&DapStream_DapStreamType) < 0 || + PyType_Ready(&DapStreamCtl_DapStreamCtlType) < 0 ) return NULL; @@ -216,6 +258,11 @@ PyMODINIT_FUNC PyInit_CellFrame(void){ PyModule_AddObject(module, "ChainNetState", (PyObject*)&DapChainNetStateObject_DapChainNetStateObjectType); // ============= + PyModule_AddObject(module, "Http", (PyObject*)&DapHTTP_DapHTTPType); + PyModule_AddObject(module, "EncHttp", (PyObject*)&DapEncHTTP_DapEncHTTPType); + PyModule_AddObject(module, "Stream", (PyObject*)&DapStream_DapStreamType); + PyModule_AddObject(module, "StreamCtl", (PyObject*)&DapStreamCtl_DapStreamCtlType); + return module; } -- GitLab