Skip to content
Snippets Groups Projects
Commit 8bbc0a61 authored by alexey.stratulat's avatar alexey.stratulat
Browse files

[+] Added Crypto object from libdap-crypto-python library.

parent 95543400
No related branches found
No related tags found
1 merge request!1Features 2466
#define PY_SSIZE_T_CLEAN #define PY_SSIZE_T_CLEAN
#include "Python.h" #include "Python.h"
#include "libdap-python.h" #include "libdap-python.h"
#include "libdap-crypto-python.h"
#include "dap_common.h" #include "dap_common.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#undef LOG_TAG
#define LOG_TAG "python-cellframe"
static bool init_crypto;
static PyObject* CellFrame_error; static PyObject* CellFrame_error;
static PyObject *python_cellframe_init(PyObject *self, PyObject *args); static PyObject *python_cellframe_init(PyObject *self, PyObject *args);
......
#include "python-cellframe.h" #include "python-cellframe.h"
PyMODINIT_FUNC PyInit_libCellFrame(void){ PyMODINIT_FUNC PyInit_libCellFrame(void){
if (PyType_Ready(&DapObject_DapObjectType) < 0 ) if (PyType_Ready(&DapObject_DapObjectType) < 0 || PyType_Ready(&dapCrypto_dapCryptoType) < 0)
return NULL; return NULL;
PyObject *module = PyModule_Create(&CellFramePythonModule); PyObject *module = PyModule_Create(&CellFramePythonModule);
...@@ -19,6 +20,8 @@ PyMODINIT_FUNC PyInit_libCellFrame(void){ ...@@ -19,6 +20,8 @@ PyMODINIT_FUNC PyInit_libCellFrame(void){
PyModule_AddObject(module, "ERROR", PyLong_FromLong(L_ERROR)); PyModule_AddObject(module, "ERROR", PyLong_FromLong(L_ERROR));
PyModule_AddObject(module, "CRITICAL", PyLong_FromLong(L_CRITICAL)); PyModule_AddObject(module, "CRITICAL", PyLong_FromLong(L_CRITICAL));
PyModule_AddObject(module, "Crypto", (PyObject*)&dapCrypto_dapCryptoType);
//PyModule_AddObject(module, "Dap", (PyObject*)&DapObject_DapObjectType); //PyModule_AddObject(module, "Dap", (PyObject*)&DapObject_DapObjectType);
return module; return module;
} }
...@@ -29,14 +32,14 @@ static PyObject *python_cellframe_init(PyObject *self, PyObject *args){ ...@@ -29,14 +32,14 @@ static PyObject *python_cellframe_init(PyObject *self, PyObject *args){
const char *config_dir; const char *config_dir;
const char *log_level; const char *log_level;
const char *JSON_str; const char *JSON_str;
init_crypto = false;
if (!PyArg_ParseTuple(args, "s", &JSON_str)){ if (!PyArg_ParseTuple(args, "s", &JSON_str)){
return NULL; return NULL;
} }
// PyObject* JSONModuleString = PyUnicode_FromString("json");
PyObject *JSON_Module = PyImport_ImportModule("json"); PyObject *JSON_Module = PyImport_ImportModule("json");
if (JSON_Module == NULL) { if (JSON_Module == NULL) {
printf("ERROR importing module"); PyErr_SetString(CellFrame_error, "ERROR importing module");
return NULL; return NULL;
} }
PyObject* JSONLoadsFunction = PyObject_GetAttrString(JSON_Module, "loads"); PyObject* JSONLoadsFunction = PyObject_GetAttrString(JSON_Module, "loads");
...@@ -69,16 +72,40 @@ static PyObject *python_cellframe_init(PyObject *self, PyObject *args){ ...@@ -69,16 +72,40 @@ static PyObject *python_cellframe_init(PyObject *self, PyObject *args){
PyErr_SetString(CellFrame_error, "Can't init common functions module"); PyErr_SetString(CellFrame_error, "Can't init common functions module");
return NULL; return NULL;
} }
dap_config_init(config_dir); dap_config_init(config_dir);
if ((g_config = dap_config_open(app_name) ) == NULL){ if ((g_config = dap_config_open(app_name) ) == NULL){
PyErr_SetString(CellFrame_error, "Can't init general configurations"); PyErr_SetString(CellFrame_error, "Can't init general configurations");
return NULL; return NULL;
} }
//Init modules
log_it(L_INFO, "Initializing modules ...");
if (!PyList_Check(getModules)){
PyErr_SetString(CellFrame_error, "Can't find an array of module names");
return NULL;
}
Py_ssize_t size_list = PyList_Size(getModules);
for (int i=0; i < size_list;i++){
PyObject *value = PyList_GetItem(getModules, i);
const char *c_value = PyUnicode_AsUTF8(value);
if (strcmp(c_value, "crypto") == 0){ //Init crypto
log_it(L_INFO, "Initializing the %s module", c_value);
init_crypto = true;
if (dap_crypto_init() != 0){
PyErr_SetString(CellFrame_error, "An error occurred while initializing the libdap-crypto-python module.");
return NULL;
}
}
}
return PyLong_FromLong(0); return PyLong_FromLong(0);
} }
static PyObject *python_cellframe_deinit(PyObject *self, PyObject *args){ static PyObject *python_cellframe_deinit(PyObject *self, PyObject *args){
const char *in; dap_config_close(g_config);
dap_config_deinit();
if (init_crypto)
dap_crypto_deinit();
//dap_common_deinit();
return PyLong_FromLong(0); return PyLong_FromLong(0);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment