diff --git a/.gitmodules b/.gitmodules index 610ceb2c4ed05ea783780a8e111d2775e04598b9..aedea207c5a65527e210e0d33195f800b136fbf0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,42 +2,3 @@ path = cellframe-sdk url = https://gitlab.demlabs.net/cellframe/cellframe-sdk branch = master -[submodule "cellframe-sdk-python/libdap-chain-common-python"] - path = cellframe-sdk-python/libdap-chain-common-python - url = https://gitlab.demlabs.net/cellframe/libdap-chain-common-python.git/ - branch = master -[submodule "cellframe-sdk-python/libdap-server-core-python"] - path = cellframe-sdk-python/libdap-server-core-python - url = https://gitlab.demlabs.net/cellframe/libdap-server-core-python.git/ - branch = master -[submodule "cellframe-sdk-python/libdap-python"] - path = cellframe-sdk-python/libdap-python - url = https://gitlab.demlabs.net/cellframe/libdap-python.git/ - branch = master -[submodule "cellframe-sdk-python/libdap-crypto-python"] - path = cellframe-sdk-python/libdap-crypto-python - url = https://gitlab.demlabs.net/cellframe/libdap-crypto-python.git/ - branch = master -[submodule "cellframe-sdk-python/libdap-chain-python"] - path = cellframe-sdk-python/libdap-chain-python - url = https://gitlab.demlabs.net/cellframe/libdap-chain-python.git/ - branch = master -[submodule "cellframe-sdk-python/libdap-chain-net-python"] - path = cellframe-sdk-python/libdap-chain-net-python - url = https://gitlab.demlabs.net/cellframe/libdap-chain-net-python.git/ - branch = master -[submodule "cellframe-sdk-python/libdap-chain-gdb-python"] - path = cellframe-sdk-python/libdap-chain-gdb-python - url = https://gitlab.demlabs.net/cellframe/libdap-chain-gdb-python.git/ - branch = master -[submodule "cellframe-sdk-python/libdap-client-python"] - path = cellframe-sdk-python/libdap-client-python - url = https://gitlab.demlabs.net/cellframe/libdap-client-python.git/ - branch = master -[submodule "cellframe-sdk-python/libdap-app-cli-python"] - path = cellframe-sdk-python/libdap-app-cli-python - url = https://gitlab.demlabs.net/cellframe/libdap-app-cli-python.git - branch = master -[submodule "cellframe-sdk-python/libdap-chain-wallet-python"] - path = cellframe-sdk-python/libdap-chain-wallet-python - url = https://gitlab.demlabs.net/cellframe/libdap-chain-wallet-python.git diff --git a/cellframe-sdk-python/libdap-app-cli-python b/cellframe-sdk-python/libdap-app-cli-python deleted file mode 160000 index a974d1f228b82ba6471eb449d848f8c28368283e..0000000000000000000000000000000000000000 --- a/cellframe-sdk-python/libdap-app-cli-python +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a974d1f228b82ba6471eb449d848f8c28368283e diff --git a/cellframe-sdk-python/libdap-app-cli-python/CMakeLists.txt b/cellframe-sdk-python/libdap-app-cli-python/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..1d0fdf2134f8da1096da1c62b4dca2bed963d999 --- /dev/null +++ b/cellframe-sdk-python/libdap-app-cli-python/CMakeLists.txt @@ -0,0 +1,35 @@ +project(dap_app_cli_python_module C) +cmake_minimum_required(VERSION 2.8) + +set(CMAKE_VERBOSE_MAKEFILE ON) +set(CMAKE_COLOR_MAKEFILE ON) +set(CMAKE_C_STANDARD 11) +#set(SUBMODULES_NO_BUILD ON) +add_definitions("-fpic") +add_definitions("-DDAP_LOG_MT") + +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 APP_CLI_PYTHON_SRCS src/*.c) +file(GLOB APP_CLI_PYTHON_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 ${APP_CLI_PYTHON_SRCS} ${APP_CLI_PYTHON_HEADERS}) + +target_link_libraries(${PROJECT_NAME}) + +target_link_libraries(${PROJECT_NAME} dap_core dap_app_cli ) + +target_include_directories(${PROJECT_NAME} PUBLIC include/ ) + diff --git a/cellframe-sdk-python/libdap-app-cli-python/README.md b/cellframe-sdk-python/libdap-app-cli-python/README.md new file mode 100644 index 0000000000000000000000000000000000000000..9b401e83d7b55d3d3c21c1d9223a264861cf9a36 --- /dev/null +++ b/cellframe-sdk-python/libdap-app-cli-python/README.md @@ -0,0 +1,2 @@ +# libdap-chain-cli-python + diff --git a/cellframe-sdk-python/libdap-app-cli-python/include/libdap-app-cli-python.h b/cellframe-sdk-python/libdap-app-cli-python/include/libdap-app-cli-python.h new file mode 100644 index 0000000000000000000000000000000000000000..4d555157448a59161e86dc3b0a67523c433c6e88 --- /dev/null +++ b/cellframe-sdk-python/libdap-app-cli-python/include/libdap-app-cli-python.h @@ -0,0 +1,73 @@ +#pragma once + +#define PY_SSIZE_T_CLEAN +#include <Python.h> +#include "dap_common.h" +#include "dap_app_cli.h" +#include "dap_strfuncs.h" + + +typedef struct PyAppCli{ + PyObject_HEAD +}PyAppCliObject; + + +PyObject* dap_app_cli_main_py(PyObject *self, PyObject *args); + +static PyMethodDef AppCliMethods[] = { + {"main", dap_app_cli_main_py, METH_VARARGS | METH_STATIC, "Main CLI function"}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapAppCli_dapAppCliType = { + PyVarObject_HEAD_INIT(NULL, 0) + "AppCli", /* tp_name */ + sizeof(PyAppCliObject), /* 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 */ + "AppCli object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + AppCliMethods, /* 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 */ + 0, /* tp_free */ + 0, /* tp_is_gc*/ + 0, /* tp_bases*/ + 0, /* tp_mro */ + 0, /* tp_cache */ + 0, /* tp_subclasses */ + 0, /* tp_weaklist */ + 0, /* tp_del */ + 0, /* tp_version_tag*/ + 0, /* tp_finalize*/ +}; + diff --git a/cellframe-sdk-python/libdap-app-cli-python/src/libdap-app-cli-python.c b/cellframe-sdk-python/libdap-app-cli-python/src/libdap-app-cli-python.c new file mode 100644 index 0000000000000000000000000000000000000000..c4643ada50aa424b2a28e9fcda6fb705fef7095b --- /dev/null +++ b/cellframe-sdk-python/libdap-app-cli-python/src/libdap-app-cli-python.c @@ -0,0 +1,43 @@ +#include "dap_common.h" +#include "libdap-app-cli-python.h" + +#define LOG_TAG "libdap-app-cli-crypto" + +/** + * @brief dap_app_cli_main_py + * @param self + * @param args + * @return + */ +PyObject* dap_app_cli_main_py(PyObject *self, PyObject *args) +{ + (void) self; + char *l_app_name = NULL; + char *l_socket_path = NULL; + int l_argc = 0; + char **l_argv = NULL; + PyObject *l_argv_py = NULL; + + PyObject *l_from_list_obj = NULL; + PyObject *l_value_obj = NULL; + if (!PyArg_ParseTuple(args, "ssO", &l_app_name, &l_socket_path, & l_argv_py)) + return NULL; + Py_ssize_t l_argv_size_py = PyList_Size(l_argv_py); + l_argc = (int)l_argv_size_py; + if (l_argv_size_py > 1){ + l_argv = PyMem_Calloc((size_t)l_argv_size_py, sizeof(char**)); + for (Py_ssize_t i=0; i < l_argv_size_py; i++){ + l_from_list_obj = PyList_GetItem(l_argv_py, i); + l_value_obj = PyList_GetItem(l_argv_py, i); + l_argv[i] = dap_strdup(PyUnicode_AsUTF8(l_value_obj)); + } + int res = dap_app_cli_main(l_app_name, l_socket_path, l_argc, l_argv); + for (Py_ssize_t i=0; i < l_argv_size_py; i++){ + DAP_FREE(l_argv[i]); + } + PyMem_Free(l_argv); + return PyLong_FromLong(res); + } + else + return PyLong_FromLong(-1024); +} diff --git a/cellframe-sdk-python/libdap-chain-common-python b/cellframe-sdk-python/libdap-chain-common-python deleted file mode 160000 index 97158dabda11b65023dfb13bb5ee229c05855cec..0000000000000000000000000000000000000000 --- a/cellframe-sdk-python/libdap-chain-common-python +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 97158dabda11b65023dfb13bb5ee229c05855cec diff --git a/cellframe-sdk-python/libdap-chain-common-python/.gitignore b/cellframe-sdk-python/libdap-chain-common-python/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..f0bb5faa29b568a9fea0a9119a999c787de9bbd1 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-common-python/.gitignore @@ -0,0 +1,2 @@ +build/ +*.user diff --git a/cellframe-sdk-python/libdap-chain-common-python/CMakeLists.txt b/cellframe-sdk-python/libdap-chain-common-python/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..12a82ebe2eb81ae8e8d2b5bbcbc9329de2b3cbf0 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-common-python/CMakeLists.txt @@ -0,0 +1,214 @@ +project(dap_chain_common_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(UNIX) + add_definitions("-DDAP_OS_UNIX") +endif() + +if (NOT (${SUBMODULES_NO_BUILD} MATCHES ON)) + set (SUBMODULES_NO_BUILD ON) + if (NOT (TARGET dap_core)) + add_subdirectory(libdap) + target_compile_options( + dap_core PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_crypto)) + add_subdirectory(libdap-crypto) + target_compile_options( + dap_crypto PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_common)) + add_subdirectory(libdap-chain-common) + target_compile_options( + dap_chain_common PRIVATE + "-fpic" + ) + endif() + #if (NOT (TARGET dap_chain_coommon)) + # add_subdirectory(libdap-chain-common) + # target_compile_options( + # dap_chain_common PRIVATE + # "-fpic" + # ) + #endif() + #if (NOT (TARGET dap_chain)) + # add_subdirectory(libdap-chain) + # target_compile_options( + # dap_chain PRIVATE + # "-fpic" + # ) + #endif() + #if (NOT (TARGET dap_chain_crypto)) + # add_subdirectory(libdap-chain-crypto) + # target_compile_options( + # dap_chain_crypto PRIVATE + # "-fpic" + # ) + #endif() + #if (NOT (TARGET dap_chain_mempool)) + # add_subdirectory(libdap-chain-mempool) + # target_compile_options( + # dap_chain_mempool PRIVATE + # "-fpic" + # ) + #endif() + #if (NOT (TARGET dap_chain_net)) + # add_subdirectory(libdap-chain-net) + # target_compile_options( + # dap_chain_net PRIVATE + # "-fpic" + # ) + #endif() + #if (NOT (TARGET dap_server_core)) + # add_subdirectory(libdap-server-core) + # target_compile_options( + # dap_server_core PRIVATE + # "-fpic" + # ) + #endif() + #if (NOT (TARGET dap_chain_global_db)) + # add_subdirectory(libdap-chain-global-db) + # target_compile_options( + # dap_chain_global_db PRIVATE + # "-fpic" + # ) + #endif() + #if (NOT (TARGET dap_client)) + # add_subdirectory(libdap-client) + # target_compile_options( + # dap_client PRIVATE + # "-fpic" + # ) + #endif() + #if (NOT (TARGET libdap-server)) + # add_subdirectory(libdap-server) +# # target_compile_options( +# # libdap-server PRIVATE +# # "-fpic" +# # ) + #endif() + #if (NOT (TARGET dap_stream)) + # add_subdirectory(libdap-stream) + # target_compile_options( + # dap_stream PRIVATE + # "-fpic" + # ) + #endif() + #if (NOT (TARGET dap_stream_ch)) + # add_subdirectory(libdap-stream-ch) + # target_compile_options( + # dap_stream_ch PRIVATE + # "-fpic" + # ) + #endif() + #if (NOT (TARGET dap_stream_ch_chain)) + # add_subdirectory(libdap-stream-ch-chain) + # target_compile_options( + # dap_stream_ch_chain PRIVATE + # "-fpic" + # ) + #endif() + #if (NOT (TARGET dap_stream_ch_chain_net)) + # add_subdirectory(libdap-stream-ch-chain-net) + # target_compile_options( + # dap_stream_ch_chain_net PRIVATE + # "-fpic" + # ) + #endif() + #if (NOT (TARGET dap_udp_server)) + # add_subdirectory(libdap-server-udp) + # target_compile_options( + # dap_udp_server PRIVATE + # "-fpic" + # ) + #endif() + #if (NOT (TARGET dap_chain_wallet)) + # add_subdirectory(libdap-chain-wallet) + # target_compile_options( + # dap_chain_wallet PRIVATE + # "-fpic" + # ) + #endif() + #if (NOT (TARGET dap_chain_net_srv)) + # add_subdirectory(libdap-chain-net-srv) + # target_compile_options( + # dap_chain_net_srv PRIVATE + # "-fpic" + # ) + #endif() + #if (NOT (TARGET dap_server_http_db_auth)) + # add_subdirectory(libdap-server-http-db-auth) + # target_compile_options( + # dap_server_http_db_auth PRIVATE + # "-fpic" + # ) + #endif() + #if (NOT (TARGET dap_chain_gdb)) + # add_subdirectory(libdap-chain-gdb) + # target_compile_options( + # dap_chain_gdb PRIVATE + # "-fpic" + # ) + #endif() + # if (NOT (TARGET dap_chain_net_srv_vpn)) + # add_subdirectory(libdap-chain-net-srv-vpn) + # target_compile_options( + # dap_chain_net_srv_vpn PRIVATE + # "-fpic" + # ) + #endif() + #if (NOT (TARGET dap_server_http_db)) + # add_subdirectory(libdap-server-http-db) + # target_compile_options( + # dap_server_http_db PRIVATE + # "-fpic" + # ) + #endif() + #if (NOT (TARGET (dap_python_module))) + # add_subdirectory(libdap-python) + # target_compile_options( + # dap_python_module PRIVATE + # "-fpic" + # ) + #endif() + #if (NOT (TARGET (dap_chain_python_module))) + # add_subdirectory(libdap-chain-python) + # target_compile_options( + # dap_chain_python_module PRIVATE + # "-fpic" + # ) + #endif() + if (NOT (TARGET (dap_crypto_python_module))) + add_subdirectory(libdap-crypto-python) + target_compile_options( + dap_crypto_python_module PRIVATE + "-fpic" + ) + endif() +endif() + + +file(GLOB CHAIN_COMMON_PYTHON_SRCS src/*.c) +file(GLOB CHAIN_COMMON_PYTHON_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 ${CHAIN_COMMON_PYTHON_SRCS} ${CHAIN_COMMON_PYTHON_HEADERS}) + +target_link_libraries(${PROJECT_NAME}) + +target_link_libraries(${PROJECT_NAME} dap_chain_common dap_core dap_crypto dap_crypto_python_module) + +target_include_directories(${PROJECT_NAME} PUBLIC include/ ) + diff --git a/cellframe-sdk-python/libdap-chain-common-python/README.md b/cellframe-sdk-python/libdap-chain-common-python/README.md new file mode 100644 index 0000000000000000000000000000000000000000..92ca68ba881f19168f200ec8768cd95090afe53b --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-common-python/README.md @@ -0,0 +1,2 @@ +# libdap-chain-common-python + diff --git a/cellframe-sdk-python/libdap-chain-common-python/include/wrapping_dap_chain_common.h b/cellframe-sdk-python/libdap-chain-common-python/include/wrapping_dap_chain_common.h new file mode 100644 index 0000000000000000000000000000000000000000..16c3783616bac4d8dba5f9394c0b9c942290777e --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-common-python/include/wrapping_dap_chain_common.h @@ -0,0 +1,506 @@ +#ifndef _WRAPPING_DAP_CHAIN_COMMON_ +#define _WRAPPING_DAP_CHAIN_COMMON_ +#include <Python.h> +#include "dap_chain_common.h" +#include "libdap_crypto_key_python.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Chain hash slow */ +typedef struct PyDapChainHashSlow{ + PyObject_HEAD + dap_chain_hash_slow_t *hash_slow; +}PyDapChainHashSlowObject; + +PyObject *dap_chain_hash_slow_to_str_py(PyObject *self, PyObject *args); + +static PyMethodDef DapChainHashSlowMethod[] = { + {"toStr", (PyCFunction)dap_chain_hash_slow_to_str_py, METH_VARARGS | METH_STATIC, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapChainHashSlowObject_DapChainHashSlowObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.HashSlow", /* tp_name */ + sizeof(PyDapChainHashSlowObject),/* 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 */ + "Chain hash slow object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapChainHashSlowMethod, /* 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 */ +}; + + +/*=================*/ + +/* Chain addr */ +typedef struct PyDapChainAddr{ + PyObject_HEAD + dap_chain_addr_t *addr; +}PyDapChainAddrObject; + +PyObject *dap_chain_addr_to_str_py(PyObject *self, PyObject *args); +PyObject *dap_chain_addr_from_str_py(PyObject *self, PyObject *args); +PyObject *dap_chain_addr_fill_py(PyObject *self, PyObject *args); +PyObject *dap_chain_addr_check_sum_py(PyObject *self, PyObject *args); + +static PyMethodDef DapChainAddrMethods[] = { + {"toStr", (PyCFunction)dap_chain_addr_to_str_py, METH_VARARGS, ""}, + {"fromStr", (PyCFunction)dap_chain_addr_from_str_py, METH_VARARGS | METH_STATIC, ""}, + {"fill", (PyCFunction)dap_chain_addr_fill_py, METH_VARARGS, ""}, + {"checkSum", (PyCFunction)dap_chain_addr_check_sum_py, METH_VARARGS, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapChainAddrObject_DapChainAddrObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.Addr", /* tp_name */ + sizeof(PyDapChainAddrObject),/* 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 */ + "Chain addr object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapChainAddrMethods, /* 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 */ +}; + + +/*=================*/ + +/* Chain net id */ + +typedef struct PyDapChainNetId{ + PyObject_HEAD + dap_chain_net_id_t net_id; +}PyDapChainNetIdObject; + +PyObject *dap_chain_net_id_from_str_py(PyObject *self, PyObject *args); + +static PyMethodDef DapChainNetIdObjectMethods[] = { + {"fromStr", (PyCFunction)dap_chain_net_id_from_str_py, METH_VARARGS | METH_STATIC, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapChainNetIdObject_DapChainNetIdObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.NetID", /* tp_name */ + sizeof(PyDapChainNetIdObject), /* 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 */ + "Chain net id object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapChainNetIdObjectMethods, /* 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 */ +}; + +/*=================*/ + +/* Chain net srv uid */ + +typedef struct PyDapChainNetSrvUID{ + PyObject_HEAD + dap_chain_net_srv_uid_t net_srv_uid; +}PyDapChainNetSrvUIDObject; + +PyObject *dap_chain_net_srv_uid_from_str_py(PyObject *self, PyObject *args); + +static PyMethodDef DapChainNetSrvUIDObject[] = { + {"fromStr", (PyCFunction)dap_chain_net_srv_uid_from_str_py, METH_VARARGS | METH_STATIC, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapChainNetSrvUIDObject_DapChainNetSrvUIDObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.ChainNetSrvUID", /* tp_name */ + sizeof(dap_chain_net_srv_uid_t), /* 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 */ + "Chain net srv uid object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapChainNetSrvUIDObject, /* 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 */ +}; + +/*=================*/ + +/* Chain net srv uid */ +typedef struct PyDapChainNetSrvPriceUnitUID{ + PyObject_HEAD + dap_chain_net_srv_price_unit_uid_t price_unit_uid; +}PyDapChainNetSrvPriceUnitUIDObject; + +static PyTypeObject DapChainNetSrvPriceUnitUIDObject_DapChainNetSrvPriceUnitUIDObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.ChainNetSrvPriceUnitUID", /* tp_name */ + sizeof(PyDapChainNetSrvPriceUnitUIDObject), /* 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 */ + "Chain net srv price unit uid object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* 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 */ +}; +/*=================*/ + +/* Chain cell id */ +typedef struct PyDapChainID{ + PyObject_HEAD + dap_chain_id_t *chain_id; +}PyDapChainIDObject; + +static PyTypeObject DapChainIDObject_DapChainIDType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.ChainID" , /* tp_name */ + sizeof(PyDapChainIDObject), /* 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 */ + "Chain id object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* 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 */ +}; + + +/*=================*/ + +/* Chain cell id */ +typedef struct PyDapChainCellID{ + PyObject_HEAD + dap_chain_cell_id_t cell_id; +}PyDapChainCellIDObject; + +static PyTypeObject DapChainCellIDObject_DapChainCellIDType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.ChainCellID" , /* tp_name */ + sizeof(PyDapChainCellIDObject), /* 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 */ + "Chain cell id object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* 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 */ +}; + + +/*=================*/ + +/* Chain cell id */ +typedef struct PyDapChainNodeAddr{ + PyObject_HEAD + dap_chain_node_addr_t *node_addr; +}PyDapChainNodeAddrObject; + +static PyTypeObject DapChainNodeAddrObject_DapChainNodeAddrObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.ChainNodeAddr" , /* tp_name */ + sizeof(PyDapChainCellIDObject), /* 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 */ + "Chain node addr object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* 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 */ +}; + + +/*=================*/ + +/* Chain cell id */ +typedef struct PyDapChainHashSlowKind{ + PyObject_HEAD + dap_chain_hash_slow_kind_t *slow_kind; +}PyDapChainHashSlowKindObject; + +static PyTypeObject DapChainSlowKindObject_DapChainSlowKindType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.ChainSlowKind" , /* tp_name */ + sizeof(PyDapChainHashSlowKindObject), /* 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 */ + "Chain slow kind object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* 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 +#endif //_WRAPPING_DAP_CHAIN_COMMON_ diff --git a/cellframe-sdk-python/libdap-chain-common-python/include/wrapping_dap_chain_datum.h b/cellframe-sdk-python/libdap-chain-common-python/include/wrapping_dap_chain_datum.h new file mode 100644 index 0000000000000000000000000000000000000000..2b4cc890f70a2c2a1b5bbd6b60820158b26d6412 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-common-python/include/wrapping_dap_chain_datum.h @@ -0,0 +1,169 @@ +#ifndef _WRAPPING_DAP_CHAIN_DATUM_ +#define _WRAPPING_DAP_CHAIN_DATUM_ +#include "Python.h" +#include "dap_chain_datum.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* DAP Chain datum type id */ +typedef struct PyDapChainDatumTypeId{ + PyObject_HEAD + dap_chain_datum_typeid_t *type_id; +}PyDapChainDatumTypeIdObject; + +static PyTypeObject DapChainDatumTypeIdObject_DapChainDatumTypeIdObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.DatumTypeId", /* tp_name */ + sizeof(PyDapChainDatumTypeIdObject), /* 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 */ + "Chain datum type id object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* 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 */ +}; +/* -------------------------------- */ + +typedef struct PyDapChainDatum{ + PyObject_HEAD + dap_chain_datum_t *datum; +}PyDapChainDatumObject; + +//void PyDapChainDatumObject_dealloc(PyDapChainDatumObject* object); +PyObject *PyDapChainDatumObject_new(PyTypeObject *type_object, PyObject *args, PyObject *kwds); +PyObject *dap_chain_datum_size_py(PyObject *self, PyObject *args); + +static PyMethodDef DapChainDatumMethods[] = { + {"size", dap_chain_datum_size_py, METH_VARARGS, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapChainDatumObject_DapChainDatumObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.Datum", /* tp_name */ + sizeof(PyDapChainDatumObject), /* 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 */ + "Chain datum object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* 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 */ + PyDapChainDatumObject_new, /* tp_new */ +}; +/* -------------------------------- */ + +/* DAP Chain datum iter*/ +typedef struct PyDapChainDatumIter{ + PyObject_HEAD + dap_chain_datum_iter_t *datum_iter; +}PyDapChainDatumIterObject; + +static PyTypeObject DapChainDatumIterObject_DapChainDatumIterObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.DatumIter", /* tp_name */ + sizeof(PyDapChainDatumIterObject), /* 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 */ + "Chain datum iter object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* 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 + +#endif //_WRAPPING_DAP_CHAIN_DATUM_ diff --git a/cellframe-sdk-python/libdap-chain-common-python/include/wrapping_dap_chain_datum_hashtree_roots.h b/cellframe-sdk-python/libdap-chain-common-python/include/wrapping_dap_chain_datum_hashtree_roots.h new file mode 100644 index 0000000000000000000000000000000000000000..957f9f48e736fd44de4764adf686963cc1c3d216 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-common-python/include/wrapping_dap_chain_datum_hashtree_roots.h @@ -0,0 +1,98 @@ +#ifndef _WRAPPING_DAP_CHAIN_DATUM_HASHTREE_ROOTS_ +#define _WRAPPING_DAP_CHAIN_DATUM_HASHTREE_ROOTS_ +#include <Python.h> + +typedef struct PyDapChainBlockRootsV1{ + PyObject_HEAD +}PyDapChainBlockRootsV1Object; + +static PyTypeObject DapChainBlockRootsV1Object_DapChainBlockRootsV1Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.ChainBlockRootsV1Object", /* tp_name */ + sizeof(PyDapChainBlockRootsV1Object), /* 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 */ + "Chain block roots v1 object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* 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 */ +}; + +typedef struct PyDapChainBlockRootsV2{ + PyObject_HEAD +}PyDapChainBlockRootsV2Object; + +static PyTypeObject DapChainBlockRootsV2Object_DapChainBlockRootsV2Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.ChainBlockRootsV2Object", /* tp_name */ + sizeof(PyDapChainBlockRootsV2Object), /* 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 */ + "Chain block roots v2 object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* 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 */ +}; + + +#endif //_WRAPPING_DAP_CHAIN_DATUM_HASHTREE_ROOTS_ diff --git a/cellframe-sdk-python/libdap-chain-common-python/include/wrapping_dap_chain_datum_token.h b/cellframe-sdk-python/libdap-chain-common-python/include/wrapping_dap_chain_datum_token.h new file mode 100644 index 0000000000000000000000000000000000000000..727f8eaebb5d3ad377396985ed3d93641b7a2433 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-common-python/include/wrapping_dap_chain_datum_token.h @@ -0,0 +1,117 @@ +#ifndef _WRAPPING_DAP_CHAIN_DATUM_TOKEN_ +#define _WRAPPING_DAP_CHAIN_DATUM_TOKEN_ + +#include "Python.h" +#include "dap_chain_datum_token.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* DAP chain datum token */ + +typedef struct PyDapChainDatumToken{ + PyObject_HEAD + dap_chain_datum_token_t *token; +}PyDapChainDatumTokenObject; + +static PyTypeObject DapChainDatumToken_DapChainDatumTokenObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.DatumTokenObject", /* tp_name */ + sizeof(PyDapChainDatumTokenObject), /* 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 */ + "Chain datum token object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* 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 */ +}; + +/* ------------------------------------------- */ + +/* DAP chain datum token emission */ + +typedef struct PyDapChainDatumTokenEmission{ + PyObject_HEAD + dap_chain_datum_token_emission_t *token_emission; +}PyDapChainDatumTokenEmissionObject; + +static PyTypeObject DapChainDatumTokenEmission_DapChainDatumTokenEmissionObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.DatumTokenEmission", /* tp_name */ + sizeof(PyDapChainDatumTokenEmissionObject), /* 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 */ + "Chain datum token emission object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* 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 + +#endif //_WRAPPING_DAP_CHAIN_DATUM_TOKEN_ diff --git a/cellframe-sdk-python/libdap-chain-common-python/include/wrapping_dap_chain_datum_tx.h b/cellframe-sdk-python/libdap-chain-common-python/include/wrapping_dap_chain_datum_tx.h new file mode 100644 index 0000000000000000000000000000000000000000..4991798eb2d39b716231306ad6ae0f6b19da2937 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-common-python/include/wrapping_dap_chain_datum_tx.h @@ -0,0 +1,271 @@ +#ifndef _WRAPPING_DAP_CHAIN_DATUM_TX_ +#define _WRAPPING_DAP_CHAIN_DATUM_TX_ + +#include "Python.h" +#include "wrapping_dap_chain_common.h" +#include "libdap_crypto_key_python.h" +#include "dap_chain_datum_tx_out_cond.h" +#include "wrapping_dap_hash.h" +#include "dap_chain_datum_tx_items.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* DAP chain tx iter type */ +typedef struct PyDapChainTxItemType{ + PyObject_HEAD +}PyDapChainTxItemTypeObject; + +PyObject *TX_ITEM_TYPE_IN_PY(void); +PyObject *TX_ITEM_TYPE_OUT_PY(void); +PyObject *TX_ITEM_TYPE_PKEY_PY(void); +PyObject *TX_ITEM_TYPE_SIG_PY(void); +PyObject *TX_ITEM_TYPE_TOKEN_PY(void); +PyObject *TX_ITEM_TYPE_IN_COND_PY(void); +PyObject *TX_ITEM_TYPE_OUT_COND_PY(void); +PyObject *TX_ITEM_TYPE_RECEIPT_PY(void); + +static PyMethodDef PyDapChainTxItemTypeObjectMethods[] ={ + {"TX_ITEM_TYPE_IN", (PyCFunction)TX_ITEM_TYPE_IN_PY, METH_NOARGS | METH_STATIC, ""}, + {"TX_ITEM_TYPE_OUT", (PyCFunction)TX_ITEM_TYPE_OUT_PY, METH_NOARGS | METH_STATIC, ""}, + {"TX_ITEM_TYPE_PKEY", (PyCFunction)TX_ITEM_TYPE_PKEY_PY, METH_NOARGS | METH_STATIC, ""}, + {"TX_ITEM_TYPE_SIG", (PyCFunction)TX_ITEM_TYPE_SIG_PY, METH_NOARGS | METH_STATIC, ""}, + {"TX_ITEM_TYPE_TOKEN", (PyCFunction)TX_ITEM_TYPE_TOKEN_PY, METH_NOARGS | METH_STATIC, ""}, + {"TX_ITEM_TYPE_IN_COND", (PyCFunction)TX_ITEM_TYPE_IN_COND_PY, METH_NOARGS | METH_STATIC, ""}, + {"TX_ITEM_TYPE_OUT_COND", (PyCFunction)TX_ITEM_TYPE_OUT_COND_PY, METH_NOARGS | METH_STATIC, ""}, + {"TX_ITEM_TYPE_RECEIPT", (PyCFunction)TX_ITEM_TYPE_RECEIPT_PY, + METH_NOARGS | METH_STATIC, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapChainTxItemObject_DapChainTxItemTypeObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.TxItemType", /* tp_name */ + sizeof(PyDapChainTxItemTypeObject), /* 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 */ + "Chain tx item type object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + PyDapChainTxItemTypeObjectMethods, /* 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 */ +}; + +/* -------------------------------------- */ + +/* DAP chain tx cond type */ +typedef struct PyDapChainTxCondType{ + PyObject_HEAD + dap_chain_tx_cond_type_t tx_cond_type_t; +}PyDapChainTxCondTypeObject; + +PyObject *COND_SERVICE_PROVIDE_PY(); +PyObject *COND_SERVICE_BILL_PY(); + +static PyMethodDef DapChainTxCondTypeMethods[] = { + {"COND_SERVICE_PROVIDE", COND_SERVICE_PROVIDE_PY, METH_NOARGS | METH_STATIC, ""}, + {"COND_SERVICE_BILL", COND_SERVICE_BILL_PY, METH_NOARGS | METH_STATIC, ""}, + {NULL, NULL,0, NULL} +}; + +static PyTypeObject DapChainTxCondType_DapChainTxCondTypeObject = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.TxCondType", /* tp_name */ + sizeof(PyDapChainTxCondTypeObject),/* 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 */ + "Chain tx cond type object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapChainTxCondTypeMethods, /* 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 */ +}; + +/* -------------------------------------- */ + +/* DAP chain datum tx */ +typedef struct PyDapChainDatumTx{ + PyObject_HEAD + dap_chain_datum_tx_t *datum_tx; +}PyDapChainDatumTxObject; + +PyObject *PyDapChainDatumTxObject_create(PyTypeObject *type_object, PyObject *args, PyObject *kwds); +void PyDapChainDatumTxObject_delete(PyDapChainDatumTxObject* datumTx); +PyObject *dap_chain_datum_tx_get_size_py(PyObject *self, PyObject *args); +PyObject *dap_chain_datum_tx_add_item_py(PyObject *self, PyObject *args); +PyObject *dap_chain_datum_tx_add_in_item_py(PyObject *self, PyObject *args); +PyObject *dap_chain_datum_tx_add_in_cond_item_py(PyObject *self, PyObject *args); +PyObject *dap_chain_datum_tx_add_out_item_py(PyObject *self, PyObject *args); +PyObject *dap_chain_datum_tx_add_out_cond_item_py(PyObject *self, PyObject *args); +PyObject *dap_chain_datum_tx_add_sign_item_py(PyObject *self, PyObject *args); +PyObject *dap_chain_datum_tx_verify_sign_py(PyObject *self, PyObject *args); + +static PyMethodDef PyDapChainDatumTxObjectMethods[] ={ + {"getSize", (PyCFunction)dap_chain_datum_tx_get_size_py, METH_VARARGS, ""}, + {"addItem", (PyCFunction)dap_chain_datum_tx_add_item_py, METH_VARARGS, ""}, + {"addInItem", (PyCFunction)dap_chain_datum_tx_add_in_item_py, METH_VARARGS, ""}, + {"addInCondItem", (PyCFunction)dap_chain_datum_tx_add_in_cond_item_py, METH_VARARGS, ""}, + {"addOutItem", (PyCFunction)dap_chain_datum_tx_add_out_item_py, METH_VARARGS, ""}, + {"addOutCond", (PyCFunction)dap_chain_datum_tx_add_out_cond_item_py, METH_VARARGS, ""}, + {"addSignItem", (PyCFunction)dap_chain_datum_tx_add_sign_item_py, METH_VARARGS, ""}, + {"verifySign", (PyCFunction)dap_chain_datum_tx_verify_sign_py, METH_VARARGS, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapChainDatumTx_DapChainDatumTxObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.DatumTx", /* tp_name */ + sizeof(PyDapChainDatumTxObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)PyDapChainDatumTxObject_delete, /* 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 */ + "Chain datum tx object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + PyDapChainDatumTxObjectMethods, /* 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 */ + PyDapChainDatumTxObject_create, /* tp_new */ +}; + +/* -------------------------------------- */ + +typedef struct PyDapChainTxOutCond{ + PyObject_HEAD + dap_chain_tx_out_cond_t *out_cond; +}PyDapChainTxOutCondObject; + +static PyTypeObject DapChainTxOutCond_DapChainTxOutCondObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.TxOutCond", /* tp_name */ + sizeof(PyDapChainTxOutCondObject), /* 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 */ + "Chain tx out cond object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* 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 + +#endif //_WRAPPING_DAP_CHAIN_DATUM_TX_ diff --git a/cellframe-sdk-python/libdap-chain-common-python/include/wrapping_dap_chain_tx_token.h b/cellframe-sdk-python/libdap-chain-common-python/include/wrapping_dap_chain_tx_token.h new file mode 100644 index 0000000000000000000000000000000000000000..1c80cdd362d3d22bdfad83dfa931fbdb1ab7a9dc --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-common-python/include/wrapping_dap_chain_tx_token.h @@ -0,0 +1,59 @@ +#ifndef _WRAPPING_DAP_CHAIN_TX_TOKEN_ +#define _WRAPPING_DAP_CHAIN_TX_TOKEN_ + +#include <Python.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PyDapChainTxToken{ + PyObject_HEAD +}PyDapChainTxTokenObject; + +static PyTypeObject DapChainTxToken_DapChainTxTokenType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.ChainTxToken", /* tp_name */ + sizeof(PyDapChainTxTokenObject), /* 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 */ + "Chain tx token object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* 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 +#endif //_WRAPPING_DAP_CHAIN_TX_TOKEN_ diff --git a/cellframe-sdk-python/libdap-chain-common-python/src/wrapping_dap_chain_common.c b/cellframe-sdk-python/libdap-chain-common-python/src/wrapping_dap_chain_common.c new file mode 100644 index 0000000000000000000000000000000000000000..b6984985f3c9dee8c61e2456a1a2cc4d92ef32b0 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-common-python/src/wrapping_dap_chain_common.c @@ -0,0 +1,61 @@ +#include "wrapping_dap_chain_common.h" + +PyObject *dap_chain_hash_slow_to_str_py(PyObject *self, PyObject *args){ + PyObject *obj_hash_slow; + char *str; + size_t str_max; + if (!PyArg_ParseTuple(args, "O|s|n", &obj_hash_slow, &str, &str_max)) + return NULL; + size_t res = dap_chain_hash_slow_to_str(((PyDapChainHashSlowObject*)obj_hash_slow)->hash_slow, str, str_max); + return Py_BuildValue("ns", res, str_max); +} + +PyObject *dap_chain_addr_to_str_py(PyObject *self, PyObject *args){ + PyObject *obj_chain_addr; + if (!PyArg_ParseTuple(args, "O", &obj_chain_addr)) + return NULL; + const dap_chain_addr_t *addr = ((PyDapChainAddrObject*)obj_chain_addr)->addr; + char *res = dap_chain_addr_to_str(addr); + return Py_BuildValue("s", res); +} + +PyObject *dap_chain_addr_from_str_py(PyObject *self, PyObject *args){ + const char *str; + if (!PyArg_ParseTuple(args, "s", &str)) + return NULL; + PyObject *obj = _PyObject_New(&DapChainAddrObject_DapChainAddrObjectType); + ((PyDapChainAddrObject*)obj)->addr = dap_chain_addr_from_str(str); + return Py_BuildValue("O", obj); +} + +PyObject *dap_chain_addr_fill_py(PyObject *self, PyObject *args){ + PyObject *key; + PyObject *net_id; + if (!PyArg_ParseTuple(args, "O|O", &key, &net_id)) + return NULL; + dap_chain_addr_fill(((PyDapChainAddrObject*)self)->addr, ((PyCryptoKeyObject*)key)->key, &(((PyDapChainNetIdObject*)net_id)->net_id)); + return self; +} + +PyObject *dap_chain_addr_check_sum_py(PyObject *self, PyObject *args){ + int res = dap_chain_addr_check_sum(((PyDapChainAddrObject*)self)->addr); + return PyLong_FromLong(res); +} + +PyObject *dap_chain_net_id_from_str_py(PyObject *self, PyObject *args){ + const char *str; + if (!PyArg_ParseTuple(args, "s", &str)) + return NULL; + PyObject *obj_net_id = _PyObject_New(&DapChainNetIdObject_DapChainNetIdObjectType); + ((PyDapChainNetIdObject*)obj_net_id)->net_id = dap_chain_net_id_from_str(str); + return Py_BuildValue("O", obj_net_id); +} + +PyObject *dap_chain_net_srv_uid_from_str_py(PyObject *self, PyObject *args){ + const char *str; + if (!PyArg_ParseTuple(args, "s", &str)) + return NULL; + PyObject *obj = _PyObject_New(&DapChainNetSrvUIDObject_DapChainNetSrvUIDObjectType); + ((PyDapChainNetSrvUIDObject*)obj)->net_srv_uid = dap_chain_net_srv_uid_from_str(str); + return Py_BuildValue("O", obj); +} diff --git a/cellframe-sdk-python/libdap-chain-common-python/src/wrapping_dap_chain_datum.c b/cellframe-sdk-python/libdap-chain-common-python/src/wrapping_dap_chain_datum.c new file mode 100644 index 0000000000000000000000000000000000000000..a9ece2389e88ac1e16abac4af7ec39c91b6f05e2 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-common-python/src/wrapping_dap_chain_datum.c @@ -0,0 +1,21 @@ +#include "wrapping_dap_chain_datum.h" + +//void PyDapChainDatumObject_dealloc(PyDapChainDatumObject* object){ +//} + +PyObject *PyDapChainDatumObject_new(PyTypeObject *type_object, PyObject *args, PyObject *kwds){ + uint16_t type_id; + PyBytesObject *bytes; + size_t data_size; + if (!PyArg_ParseTuple(args, "H|S|n", &type_id, &bytes, &data_size)) + return NULL; + PyDapChainDatumObject *obj = (PyDapChainDatumObject*)PyType_GenericNew(type_object, args, kwds); + void* bytes_v = (void *)PyBytes_AsString((PyObject*)bytes); + obj->datum = dap_chain_datum_create(type_id, bytes_v, data_size); + return (PyObject *)obj; +} + +PyObject *dap_chain_datum_size_py(PyObject *self, PyObject *args){ + size_t size = dap_chain_datum_size(((PyDapChainDatumObject*)self)->datum); + return PyLong_FromSize_t(size); +} diff --git a/cellframe-sdk-python/libdap-chain-common-python/src/wrapping_dap_chain_datum_tx.c b/cellframe-sdk-python/libdap-chain-common-python/src/wrapping_dap_chain_datum_tx.c new file mode 100644 index 0000000000000000000000000000000000000000..5241612dc97960223d856bc7f9c5de0bf405b7bb --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-common-python/src/wrapping_dap_chain_datum_tx.c @@ -0,0 +1,137 @@ +#include "wrapping_dap_chain_datum_tx.h" + +/* DAP chain tx iter type */ + +PyObject *TX_ITEM_TYPE_IN_PY(void){ + return PyLong_FromLong(TX_ITEM_TYPE_IN); +} +PyObject *TX_ITEM_TYPE_OUT_PY(void){ + return PyLong_FromLong(TX_ITEM_TYPE_OUT); +} +PyObject *TX_ITEM_TYPE_PKEY_PY(void){ + return PyLong_FromLong(TX_ITEM_TYPE_PKEY); +} +PyObject *TX_ITEM_TYPE_SIG_PY(void){ + return PyLong_FromLong(TX_ITEM_TYPE_SIG); +} +PyObject *TX_ITEM_TYPE_TOKEN_PY(void){ + return PyLong_FromLong(TX_ITEM_TYPE_TOKEN); +} +PyObject *TX_ITEM_TYPE_IN_COND_PY(void){ + return PyLong_FromLong(TX_ITEM_TYPE_IN_COND); +} +PyObject *TX_ITEM_TYPE_OUT_COND_PY(void){ + return PyLong_FromLong(TX_ITEM_TYPE_OUT_COND); +} +PyObject *TX_ITEM_TYPE_RECEIPT_PY(void){ + return PyLong_FromLong(TX_ITEM_TYPE_RECEIPT); +} + +/* -------------------------------------- */ + +/* DAP chain tx cond type */ +PyObject *COND_SERVICE_PROVIDE_PY(){ + PyObject *obj = _PyObject_New(&DapChainTxCondType_DapChainTxCondTypeObject); + ((PyDapChainTxCondTypeObject*)obj)->tx_cond_type_t = COND_SERVICE_PROVIDE; + return Py_BuildValue("O", obj); +} +PyObject *COND_SERVICE_BILL_PY(){ + PyObject *obj = _PyObject_New(&DapChainTxCondType_DapChainTxCondTypeObject); + ((PyDapChainTxCondTypeObject*)obj)->tx_cond_type_t = COND_SERVICE_BILL; + return Py_BuildValue("O", obj); +} +/* -------------------------------------- */ + +/* DAP chain datum tx */ +PyObject *PyDapChainDatumTxObject_create(PyTypeObject *type_object, PyObject *args, PyObject *kwds){ + PyDapChainDatumTxObject *obj = (PyDapChainDatumTxObject*)PyType_GenericNew(type_object, args, kwds); + obj->datum_tx = dap_chain_datum_tx_create(); + return (PyObject *)obj; +} +void PyDapChainDatumTxObject_delete(PyDapChainDatumTxObject* datumTx){ + dap_chain_datum_tx_delete(datumTx->datum_tx); + Py_TYPE(datumTx)->tp_free((PyObject*)datumTx); +} + +PyObject *dap_chain_datum_tx_get_size_py(PyObject *self, PyObject *args){ + (void)args; + size_t size = dap_chain_datum_tx_get_size(((PyDapChainDatumTxObject*)self)->datum_tx); + return PyLong_FromSize_t(size); +} +PyObject *dap_chain_datum_tx_add_item_py(PyObject *self, PyObject *args){ + uint8_t *a_item; + if (!PyArg_ParseTuple(args, "b", &a_item)) + return NULL; + int res = dap_chain_datum_tx_add_item(&(((PyDapChainDatumTxObject*)self)->datum_tx), a_item); + return PyLong_FromLong(res); +} +PyObject *dap_chain_datum_tx_add_in_item_py(PyObject *self, PyObject *args){ + PyObject *in_obj_hash_fast; + uint32_t in_tx_out_pref_idx; + if (!PyArg_ParseTuple(args, "O|I", &in_obj_hash_fast, &in_tx_out_pref_idx)) + return NULL; + int res = dap_chain_datum_tx_add_in_item(&(((PyDapChainDatumTxObject*)self)->datum_tx), + ((PyDapHashFastObject*)in_obj_hash_fast)->hash_fast, + in_tx_out_pref_idx); + return PyLong_FromLong(res); +} + +PyObject *dap_chain_datum_tx_add_in_cond_item_py(PyObject *self, PyObject *args){ + PyObject *in_chain_hash_fast; + unsigned int in_tx_out_prev_idx; + unsigned int in_receipt_idx; + if (!PyArg_ParseTuple(args, "O|I|I", &in_chain_hash_fast, &in_tx_out_prev_idx, &in_receipt_idx)) + return NULL; + int res = dap_chain_datum_tx_add_in_cond_item(&(((PyDapChainDatumTxObject*)self)->datum_tx), + ((PyDapHashFastObject*)in_chain_hash_fast)->hash_fast, + in_tx_out_prev_idx, + in_receipt_idx); + return PyLong_FromLong(res); +} + +PyObject *dap_chain_datum_tx_add_out_item_py(PyObject *self, PyObject *args){ + PyObject *in_addr; + uint64_t value; + if (!PyArg_ParseTuple(args, "O|k", &in_addr, &value)) + return NULL; + int res = dap_chain_datum_tx_add_out_item(&(((PyDapChainDatumTxObject*)self)->datum_tx), + ((PyDapChainAddrObject*)in_addr)->addr, + value); + return PyLong_FromLong(res); +} +PyObject *dap_chain_datum_tx_add_out_cond_item_py(PyObject *self, PyObject *args){ + PyObject *obj_key; + PyObject *obj_srv_uid; + uint64_t value; + uint64_t value_max_per_unit; + PyObject *obj_srv_price_unit_uid; + PyObject *obj_cond_bytes; + Py_ssize_t cond_size; + if (!PyArg_ParseTuple(args, "O|O|k|k|O|O|n", &obj_key, &obj_srv_uid, &value, &value_max_per_unit, + &obj_srv_price_unit_uid, &obj_cond_bytes, &cond_size)) + return NULL; + void *cond = (void*)PyBytes_AsString(obj_cond_bytes); + int res = dap_chain_datum_tx_add_out_cond_item(&(((PyDapChainDatumTxObject*)self)->datum_tx), + ((PyCryptoKeyObject*)obj_key)->key, + ((PyDapChainNetSrvUIDObject*)obj_srv_uid)->net_srv_uid, + value, value_max_per_unit, + ((PyDapChainNetSrvPriceUnitUIDObject*)obj_srv_price_unit_uid)->price_unit_uid, + cond, (size_t)cond_size); + return PyLong_FromLong(res); +} +PyObject *dap_chain_datum_tx_add_sign_item_py(PyObject *self, PyObject *args){ + PyObject *obj_key; + if (!PyArg_ParseTuple(args, "O", &obj_key)) + return NULL; + int res = dap_chain_datum_tx_add_sign_item(&(((PyDapChainDatumTxObject*)self)->datum_tx), + ((PyCryptoKeyObject*)obj_key)->key); + return PyLong_FromLong(res); +} + +PyObject *dap_chain_datum_tx_verify_sign_py(PyObject *self, PyObject *args){ + (void)args; + int res = dap_chain_datum_tx_verify_sign(((PyDapChainDatumTxObject*)self)->datum_tx); + return PyLong_FromLong(res); +} + +/* -------------------------------------- */ diff --git a/cellframe-sdk-python/libdap-chain-gdb-python b/cellframe-sdk-python/libdap-chain-gdb-python deleted file mode 160000 index 510c499d547f0457e1ec9e7a109e3716a0f2e415..0000000000000000000000000000000000000000 --- a/cellframe-sdk-python/libdap-chain-gdb-python +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 510c499d547f0457e1ec9e7a109e3716a0f2e415 diff --git a/cellframe-sdk-python/libdap-chain-gdb-python/.gitignore b/cellframe-sdk-python/libdap-chain-gdb-python/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..da1d64b79984de1880866132a6ca6e5e171894f3 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-gdb-python/.gitignore @@ -0,0 +1,2 @@ +*.user +build/ diff --git a/cellframe-sdk-python/libdap-chain-gdb-python/CMakeLists.txt b/cellframe-sdk-python/libdap-chain-gdb-python/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e599cb79f57f1d1ea2ed48aacf23a2bae94f2f60 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-gdb-python/CMakeLists.txt @@ -0,0 +1,213 @@ +project(dap_chain_gdb_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(UNIX) + add_definitions("-DDAP_OS_UNIX") +endif() + +if (NOT (${SUBMODULES_NO_BUILD} MATCHES ON)) + set (SUBMODULES_NO_BUILD ON) + if (NOT (TARGET dap_core)) + add_subdirectory(libdap) + target_compile_options( + dap_core PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_crypto)) + add_subdirectory(libdap-crypto) + target_compile_options( + dap_crypto PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_coommon)) + add_subdirectory(libdap-chain-common) + target_compile_options( + dap_chain_common PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain)) + add_subdirectory(libdap-chain) + target_compile_options( + dap_chain PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_crypto)) + add_subdirectory(libdap-chain-crypto) + target_compile_options( + dap_chain_crypto PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_mempool)) + add_subdirectory(libdap-chain-mempool) + target_compile_options( + dap_chain_mempool PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_net)) + add_subdirectory(libdap-chain-net) + target_compile_options( + dap_chain_net PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_server_core)) + add_subdirectory(libdap-server-core) + target_compile_options( + dap_server_core PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_global_db)) + add_subdirectory(libdap-chain-global-db) + target_compile_options( + dap_chain_global_db PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_client)) + add_subdirectory(libdap-client) + target_compile_options( + dap_client PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET libdap-server)) + add_subdirectory(libdap-server) +# target_compile_options( +# libdap-server PRIVATE +# "-fpic" +# ) + endif() + if (NOT (TARGET dap_stream)) + add_subdirectory(libdap-stream) + target_compile_options( + dap_stream PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_stream_ch)) + add_subdirectory(libdap-stream-ch) + target_compile_options( + dap_stream_ch PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_stream_ch_chain)) + add_subdirectory(libdap-stream-ch-chain) + target_compile_options( + dap_stream_ch_chain PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_stream_ch_chain_net)) + add_subdirectory(libdap-stream-ch-chain-net) + target_compile_options( + dap_stream_ch_chain_net PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_udp_server)) + add_subdirectory(libdap-server-udp) + target_compile_options( + dap_udp_server PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_wallet)) + add_subdirectory(libdap-chain-wallet) + target_compile_options( + dap_chain_wallet PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_net_srv)) + add_subdirectory(libdap-chain-net-srv) + target_compile_options( + dap_chain_net_srv PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_server_http_db_auth)) + add_subdirectory(libdap-server-http-db-auth) + target_compile_options( + dap_server_http_db_auth PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_gdb)) + add_subdirectory(libdap-chain-gdb) + target_compile_options( + dap_chain_gdb PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_net_srv_vpn)) + add_subdirectory(libdap-chain-net-srv-vpn) + target_compile_options( + dap_chain_net_srv_vpn PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_server_http_db)) + add_subdirectory(libdap-server-http-db) + target_compile_options( + dap_server_http_db PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET (dap_python_module))) + add_subdirectory(libdap-python) + target_compile_options( + dap_python_module PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET (dap_chain_python_module))) + add_subdirectory(libdap-chain-python) + target_compile_options( + dap_chain_python_module PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET (dap_crypto_python_module))) + add_subdirectory(libdap-crypto-python) + target_compile_options( + dap_crypto_python_module PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET (dap_chain_common_python_module))) + add_subdirectory(libdap-chain-common-python) + target_compile_options( + dap_chain_common_python_module PRIVATE + "-fpic" + ) + endif() +endif() + + +file(GLOB CHAIN_GDB_PYTHON_SRCS src/*.c) +file(GLOB CHAIN_GDB_PYTHON_HEADERS include/*.h) + +set(Python_ADDITIONAL_VERSIONS 3.7) +find_package (PythonLibs REQUIRED) +include_directories(${PYTHON_INCLUDE_DIR} include/) + +add_library(${PROJECT_NAME} STATIC ${CHAIN_GDB_PYTHON_SRCS} ${CHAIN_GDB_PYTHON_HEADERS}) + +target_link_libraries(${PROJECT_NAME}) + +target_link_libraries(${PROJECT_NAME} dap_chain_gdb dap_core dap_chain dap_chain_global_db dap_chain_mempool dap_chain_net dap_chain_python_module) + +target_include_directories(${PROJECT_NAME} PUBLIC include/ ) + diff --git a/cellframe-sdk-python/libdap-chain-gdb-python/README.md b/cellframe-sdk-python/libdap-chain-gdb-python/README.md new file mode 100644 index 0000000000000000000000000000000000000000..0effa3b5edea96018dcb62ec7ee275656bddb38e --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-gdb-python/README.md @@ -0,0 +1,2 @@ +# libdap-chain-gdb-python + diff --git a/cellframe-sdk-python/libdap-chain-gdb-python/include/wrapping_dap_chain_gdb.h b/cellframe-sdk-python/libdap-chain-gdb-python/include/wrapping_dap_chain_gdb.h new file mode 100644 index 0000000000000000000000000000000000000000..e81068f2f1afe1068fc7a79ea18f3aedd280d249 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-gdb-python/include/wrapping_dap_chain_gdb.h @@ -0,0 +1,74 @@ +#ifndef _WRAPPING_DAP_CHAIN_GDB_ +#define _WRAPPING_DAP_CHAIN_GDB_ +#include <Python.h> +#include "dap_chain_gdb.h" +#include "libdap-chain-python.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PyDapChainGDB{ + PyObject_HEAD +}PyDapChainGDBObject; + +int dap_chain_gdb_init_py(void); + +PyObject* dap_chain_gdb_new_py(PyObject* self, PyObject *args); + +PyObject *dap_chain_gdb_delete_py(PyObject *self, PyObject *args); +PyObject *dap_chain_gdb_get_group_py(PyObject *self, PyObject *args); + +static PyMethodDef DapChainGDBMethod[] = { + {"new", (PyCFunction)dap_chain_gdb_new_py, METH_VARARGS | METH_STATIC, ""}, + {"delete", (PyCFunction)dap_chain_gdb_delete_py, METH_VARARGS | METH_STATIC, ""}, + {"getGroup", (PyCFunction)dap_chain_gdb_get_group_py, METH_VARARGS | METH_STATIC, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapChainGDBObject_DapChainGDBType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.ChainGDB", /* tp_name */ + sizeof(PyDapChainGDBObject), /* 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 */ + "Chain gdb object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapChainGDBMethod, /* 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 +#endif // _WRAPPING_DAP_CHAIN_GDB_ diff --git a/cellframe-sdk-python/libdap-chain-gdb-python/src/wrapping_dap_chain_gdb.c b/cellframe-sdk-python/libdap-chain-gdb-python/src/wrapping_dap_chain_gdb.c new file mode 100644 index 0000000000000000000000000000000000000000..5bf53efab530d8aeab89d39b269c95c14159a641 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-gdb-python/src/wrapping_dap_chain_gdb.c @@ -0,0 +1,29 @@ +#include "wrapping_dap_chain_gdb.h" + +int dap_chain_gdb_init_py(void){ + return dap_chain_gdb_init(); +} + +PyObject* dap_chain_gdb_new_py(PyObject* self, PyObject *args){ + PyObject *obj_chain; + if (!PyArg_ParseTuple(args, "O", &obj_chain)) + return NULL; + int res = dap_chain_gdb_new(((PyDapChainObject*)obj_chain)->chain_t, g_config); + return PyLong_FromLong(res); +} + +PyObject *dap_chain_gdb_delete_py(PyObject *self, PyObject *args){ + PyObject *obj_chain; + if (!PyArg_ParseTuple(args, "O", &obj_chain)) + return NULL; + dap_chain_gdb_delete(((PyDapChainObject*)obj_chain)->chain_t); + return PyLong_FromLong(0); +} + +PyObject *dap_chain_gdb_get_group_py(PyObject *self, PyObject *args){ + PyObject *obj_chain; + if (!PyArg_ParseTuple(args, "O", &obj_chain)) + return NULL; + const char *res = dap_chain_gdb_get_group(((PyDapChainObject*)obj_chain)->chain_t); + return Py_BuildValue("s", res); +} diff --git a/cellframe-sdk-python/libdap-chain-net-python b/cellframe-sdk-python/libdap-chain-net-python deleted file mode 160000 index 0b135fbdaa7fdb217afddf76469e84fe87d68871..0000000000000000000000000000000000000000 --- a/cellframe-sdk-python/libdap-chain-net-python +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0b135fbdaa7fdb217afddf76469e84fe87d68871 diff --git a/cellframe-sdk-python/libdap-chain-net-python/.gitignore b/cellframe-sdk-python/libdap-chain-net-python/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..aee8394a251c6490851a86230f74a7029abb796e --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-net-python/.gitignore @@ -0,0 +1,3 @@ +*.text +CMakeLists.txt.user* +*.autosave \ No newline at end of file diff --git a/cellframe-sdk-python/libdap-chain-net-python/CMakeLists.txt b/cellframe-sdk-python/libdap-chain-net-python/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..1fa0f234e1e7825e61a56aa788ac62568456e403 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-net-python/CMakeLists.txt @@ -0,0 +1,223 @@ +project(dap_chain_net_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(UNIX) + add_definitions("-DDAP_OS_UNIX") +endif() + +if(NOT (${SUBMODULES_NO_BUILD} MATCHES ON)) + set (SUBMODULES_NO_BUILD ON) + if (NOT (TARGET dap_core)) + add_subdirectory(libdap) + target_compile_options( + dap_core PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_crypto)) + add_subdirectory(libdap-crypto) + target_compile_options( + dap_crypto PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain)) + add_subdirectory(libdap-chain) + target_compile_options( + dap_chain PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_crypto)) + add_subdirectory(libdap-chain-crypto) + target_compile_options( + dap_chain_crypto PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_mempool)) + add_subdirectory(libdap-chain-mempool) + target_compile_options( + dap_chain_mempool PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_net)) + add_subdirectory(libdap-chain-net) + target_compile_options( + dap_chain_net PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_server_core)) + add_subdirectory(libdap-server-core) + target_compile_options( + dap_server_core PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_global_db)) + add_subdirectory(libdap-chain-global-db) + target_compile_options( + dap_chain_global_db PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_client)) + add_subdirectory(libdap-client) + target_compile_options( + dap_client PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET libdap-server)) + add_subdirectory(libdap-server) +# target_compile_options( +# libdap-server PRIVATE +# "-fpic" +# ) + endif() + if (NOT (TARGET dap_stream)) + add_subdirectory(libdap-stream) + target_compile_options( + dap_stream PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_stream_ch)) + add_subdirectory(libdap-stream-ch) + target_compile_options( + dap_stream_ch PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_stream_ch_chain)) + add_subdirectory(libdap-stream-ch-chain) + target_compile_options( + dap_stream_ch_chain PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_stream_ch_chain_net)) + add_subdirectory(libdap-stream-ch-chain-net) + target_compile_options( + dap_stream_ch_chain_net PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_udp_server)) + add_subdirectory(libdap-server-udp) + target_compile_options( + dap_udp_server PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_net_srv)) + add_subdirectory(libdap-chain-net-srv) + target_compile_options( + dap_chain_net_srv PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_wallet)) + add_subdirectory(libdap-chain-wallet) + target_compile_options( + dap_chain_wallet PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_gdb)) + add_subdirectory(libdap-chain-gdb) + target_compile_options( + dap_chain_gdb PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_python_module)) + add_subdirectory(libdap-python) + target_compile_options( + dap_python_module PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_crypto_python_module)) + add_subdirectory(libdap-crypto-python) + target_compile_options( + dap_crypto_python_module PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_net_srv_vpn)) + add_subdirectory(libdap-chain-net-srv-vpn) + target_compile_options( + dap_chain_net_srv_vpn PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_python_module)) + add_subdirectory(libdap-chain-python) + target_compile_options( + dap_chain_python_module PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_client_python_module)) + add_subdirectory(libdap-client-python) + target_compile_options( + dap_client_python_module PRIVATE + "-fpic" + ) + endif() +endif() +#add_definitions("-DDAP_APP_NAME=\"TestPRJ\" -DSYSTEM_CONFIGS_DIR=\"${CMAKE_CURRENT_BINARY_DIR}\"") + +file(GLOB CHAIN_NET_PYTHON_SRCS src/*.c) +file(GLOB CHAIN_NET_PYTHON_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 ${CHAIN_NET_PYTHON_SRCS} ${CHAIN_NET_PYTHON_HEADERS}) + +target_link_libraries(${PROJECT_NAME}) + +#target_compile_options( +# dap_core PRIVATE +# "-fpic" +#) +#target_compile_options( +# dap_crypto PRIVATE +# "-fpic" +#) + + +target_link_libraries(${PROJECT_NAME} dap_core dap_crypto dap_chain dap_chain_crypto dap_server_core dap_chain_net dap_chain_python_module dap_client_python_module) +#target_link_libraries(${PROJECT_NAME} dap_core dap_crypto dap_chain dap_chain_global_db dap_chain_crypto dap_chain_mempool +# +# ) #dap_chain_crypto dap_chain_mempool dap_chain_global_db ) +#target_link_libraries(${PROJECT_NAME} dap_core dap_crypto) + +target_include_directories(${PROJECT_NAME} PUBLIC include/ ) + +#if(BUILD_DAP_CRYPTO_PYTHON_TESTS) +# add_subdirectory(test) +# file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/test_b58.py +# DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test/) +# file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/test_b64.py +# DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test/) +# file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/test_iaes256_cbc.py +# DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test/) +# file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/test_iaes256_cbc.py +# DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test/) +# file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/test_oaes.py +# DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test/) + + +#endif() + diff --git a/cellframe-sdk-python/libdap-chain-net-python/README.md b/cellframe-sdk-python/libdap-chain-net-python/README.md new file mode 100644 index 0000000000000000000000000000000000000000..602aa919a77aa1212841feded19b26c802fa1cd2 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-net-python/README.md @@ -0,0 +1,2 @@ +# libdap-chain-net-python + diff --git a/cellframe-sdk-python/libdap-chain-net-python/include/libdap_chain_net_python.h b/cellframe-sdk-python/libdap-chain-net-python/include/libdap_chain_net_python.h new file mode 100644 index 0000000000000000000000000000000000000000..378d71bf0b0718b99d5027274864ec925330b0a5 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-net-python/include/libdap_chain_net_python.h @@ -0,0 +1,123 @@ +#ifndef _WRAPPING_DAP_NET_PYTHON_ +#define _WRAPPING_DAP_NET_PYTHON_ + +#define PY_SSIZE_T_CLEAN +#include "Python.h" +#include "dap_chain_net.h" +#include "wrapping_dap_chain_net_state.h" +//#include "wrapping_dap_chain_net_state.h" +#include "wrapping_dap_chain_common.h" +#include "wrapping_dap_chain_ledger.h" +#include "libdap-chain-python.h" +#include "libdap_chain_type_python.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +typedef struct PyDapChainNet{ + PyObject_HEAD + dap_chain_net_t *chain_net; +}PyDapChainNetObject; + +int dap_chain_net_init_py(void); +void dap_chain_net_deinit_py(void); + +PyObject *dap_chain_net_load_all_py(PyObject *self, PyObject *args); +PyObject *dap_chain_net_state_go_to_py(PyObject *self, PyObject *args); +PyObject *dap_chain_net_start_py(PyObject *self, PyObject *args); +PyObject *dap_chain_net_stop_py(PyObject *self, PyObject *args); +PyObject *dap_chain_net_links_establish_py(PyObject *self, PyObject *args); +PyObject *dap_chain_net_sync_chains_py(PyObject *self, PyObject *args); +PyObject *dap_chain_net_sync_gdb_py(PyObject *self, PyObject *args); +PyObject *dap_chain_net_sync_all_py(PyObject *self, PyObject *args); + +PyObject *dap_chain_net_proc_datapool_py(PyObject *self, PyObject *args); + +PyObject *dap_chain_net_by_name_py(PyObject *self, PyObject *args); +PyObject *dap_chain_net_by_id_py(PyObject *self, PyObject *args); +PyObject *dap_chain_net_id_by_name_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_by_net_name_py(PyObject *self, PyObject *args); + +PyObject *dap_chain_net_get_chain_by_name_py(PyObject *self, PyObject *args); + +PyObject *dap_chain_net_get_cur_addr_py(PyObject *self, PyObject *args); +PyObject *dap_chain_net_get_cur_cell_py(PyObject *self, PyObject *args); +PyObject *dap_chain_net_get_cur_addr_int_py(PyObject *self, PyObject *args); + +PyObject *dap_chain_net_get_gdb_group_mempool_py(PyObject *self, PyObject *args); +PyObject *dap_chain_net_get_gdb_group_mempool_by_chain_type_py(PyObject *self, PyObject *args); +PyObject *dap_chain_net_links_connect_py(PyObject *self, PyObject *args); +PyObject *dap_chain_net_get_chain_by_chain_type_py(PyObject *self, PyObject *args); + +static PyMethodDef DapChainNetMethods[] = { + {"loadAll", dap_chain_net_load_all_py, METH_NOARGS | METH_STATIC, ""}, + {"stateGoTo", dap_chain_net_state_go_to_py, METH_VARARGS, ""}, + {"start", dap_chain_net_start_py, METH_VARARGS, ""}, + {"stop", dap_chain_net_stop_py, METH_VARARGS, ""}, + {"linksEstablish", dap_chain_net_links_establish_py, METH_VARARGS, ""}, + {"syncChains", dap_chain_net_sync_all_py, METH_VARARGS, ""}, + {"syncGdb", dap_chain_net_sync_gdb_py, METH_VARARGS, ""}, + {"syncAll", dap_chain_net_sync_all_py, METH_VARARGS, ""}, + {"procDatapool", dap_chain_net_proc_datapool_py, METH_VARARGS, ""}, + {"byName", dap_chain_net_by_name_py, METH_VARARGS | METH_STATIC, ""}, + {"byId", dap_chain_net_by_id_py, METH_VARARGS | METH_STATIC, ""}, + {"idByName", dap_chain_net_id_by_name_py, METH_VARARGS | METH_STATIC, ""}, + {"ledgerByNetName", dap_chain_ledger_by_net_name_py, METH_VARARGS | METH_STATIC, ""}, + {"getChainByName", dap_chain_net_get_chain_by_name_py, METH_VARARGS, ""}, + {"getCurAddr", dap_chain_net_get_cur_addr_py, METH_VARARGS, ""}, + {"getCurCell", dap_chain_net_get_cur_cell_py, METH_VARARGS, ""}, + {"getGdbGroupMempool", dap_chain_net_get_gdb_group_mempool_py, METH_VARARGS | METH_STATIC, ""}, + {"getGdbGroupMempoolByChainType", dap_chain_net_get_gdb_group_mempool_by_chain_type_py, METH_VARARGS, ""}, + {"linksConnect", dap_chain_net_links_connect_py, METH_VARARGS, ""}, + {"getChainByChainType", dap_chain_net_get_chain_by_chain_type_py, METH_VARARGS, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapChainNetObject_DapChainNetObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.ChainNet", /* tp_name */ + sizeof(PyDapChainNetObject), /* 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 */ + "Chain net object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapChainNetMethods, /* 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 + +#endif //_WRAPPING_DAP_NET_PYTHON_ diff --git a/cellframe-sdk-python/libdap-chain-net-python/include/wrapping_dap_app_cli_server.h b/cellframe-sdk-python/libdap-chain-net-python/include/wrapping_dap_app_cli_server.h new file mode 100644 index 0000000000000000000000000000000000000000..c7322598de1ff58d893976ee40694e180deb3af7 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-net-python/include/wrapping_dap_app_cli_server.h @@ -0,0 +1,108 @@ +#pragma once + +#include <Python.h> +#include "dap_config.h" +#include "dap_chain_node_cli.h" +#include "dap_chain_node_cli_cmd.h" +#include "wrapping_dap_chain_common.h" +#include "wrapping_dap_chain_net_node.h" +#include "utlist.h" + +typedef struct PyDapAppCliServer{ + PyObject_HEAD + cmdfunc_t *func; +}PyDapAppCliServerObject; + +typedef struct element_str_reply{ + char **str_reply; + size_t id; + struct element_str_reply *next; +}element_str_reply_t; + +static element_str_reply_t *l_str_reply_list; +size_t elements_str_reply_add(char** str_reply); +int elements_str_reply_cmp_by_id(element_str_reply_t *e1, element_str_reply_t *e2); +char** elements_str_reply_get_by_id(size_t id); +void elements_str_reply_delete(size_t id); +void elements_str_reply_delete_all(); + +typedef struct element_py_func{ + char *name; + PyObject *func; + struct element_py_func *next; +}element_py_func_t; + +static element_py_func_t *l_element_py_func_list; + +void element_py_func_add(const char *name, PyObject *func); +int element_py_func_cmp_by_name(element_py_func_t *e1, element_py_func_t *e2); +PyObject *element_py_func_get(char *name); +void element_py_func_del_by_name(char *name); +void element_py_func_del_all(); + + +//static PyObject *binded_object_cmdfunc = NULL; +//static char** l_str_reply = NULL; + +int dap_chain_node_cli_init_py(dap_config_t *g_config); +void dap_chain_node_cli_delete_py(void); + +PyObject *DapChainNodeCliObject_new(PyTypeObject *type_object, PyObject *args, PyObject *kwds); + +PyObject *dap_chain_node_cli_cmd_item_create_py(PyObject *a_self, PyObject *a_args); +PyObject *dap_chain_node_cli_set_reply_text_py(PyObject *self, PyObject *args); + +PyObject *dap_chain_node_addr_get_by_alias_py(PyObject *self, PyObject *args); + +static PyMethodDef DapChainNodeCliMethods[] = { + {"cmdItemCreate", dap_chain_node_cli_cmd_item_create_py, METH_VARARGS| METH_STATIC, ""}, + {"setReplyText", dap_chain_node_cli_set_reply_text_py, METH_VARARGS| METH_STATIC, ""}, + {"getByAlias", dap_chain_node_addr_get_by_alias_py, METH_VARARGS | METH_STATIC, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapChainNodeCliObject_DapChainNodeCliObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "AppCliServer", /* tp_name */ + sizeof(PyDapAppCliServerObject), /* 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 */ + "Chain net node cli object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapChainNodeCliMethods, /* 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 */ + DapChainNodeCliObject_new, /* tp_new */ +}; + +char **PyListToString(PyObject *list); +//PyObject *stringToPyList(char **list); +PyObject *stringToPyList(int argc, char **list); diff --git a/cellframe-sdk-python/libdap-chain-net-python/include/wrapping_dap_chain_net_node.h b/cellframe-sdk-python/libdap-chain-net-python/include/wrapping_dap_chain_net_node.h new file mode 100644 index 0000000000000000000000000000000000000000..34fbb96260902ebe2ebfc65ce44e44ac2ad9e944 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-net-python/include/wrapping_dap_chain_net_node.h @@ -0,0 +1,70 @@ +#ifndef _WRAPPING_DAP_CHAIN_NET_NODE_ +#define _WRAPPING_DAP_CHAIN_NET_NODE_ + +#include <Python.h> +#include "dap_chain_node.h" +#include "wrapping_dap_chain_common.h" +#include "libdap_chain_net_python.h" + +typedef struct PyDapChainNode{ + PyObject_HEAD +}PyDapChainNodeObject; + +PyObject *dap_chain_node_gen_addr_py(PyObject *self, PyObject *args); +PyObject *dap_chain_node_check_addr_py(PyObject *self, PyObject *args); +PyObject *dap_chain_node_alias_find_py(PyObject *self, PyObject *args); +PyObject *dap_chain_node_alias_register_py(PyObject *self, PyObject *args); +PyObject *dap_chain_node_alias_delete_py(PyObject *self, PyObject *args); + +static PyMethodDef DapChainNetNodeMethods[] = { + {"genAddr", dap_chain_node_gen_addr_py, METH_VARARGS | METH_STATIC, ""}, + {"checkAddr", dap_chain_node_check_addr_py, METH_VARARGS | METH_STATIC, ""}, + {"aliasFind", dap_chain_node_alias_find_py, METH_VARARGS | METH_STATIC, ""}, + {"aliasRegister", dap_chain_node_alias_register_py, METH_VARARGS | METH_STATIC, ""}, + {"aliasDelete", dap_chain_node_alias_delete_py, METH_VARARGS | METH_STATIC, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapChainNetNodeObject_DapChainNetNodeObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.Node", /* tp_name */ + sizeof(PyDapChainNodeObject), /* 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 */ + "Chain net node object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapChainNetNodeMethods, /* 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 */ +}; + +#endif //_WRAPPING_DAP_CHAIN_NET_NODE_ diff --git a/cellframe-sdk-python/libdap-chain-net-python/include/wrapping_dap_chain_net_node_client.h b/cellframe-sdk-python/libdap-chain-net-python/include/wrapping_dap_chain_net_node_client.h new file mode 100644 index 0000000000000000000000000000000000000000..c940a7a4a9083d0814b5a80225642775a0d78efa --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-net-python/include/wrapping_dap_chain_net_node_client.h @@ -0,0 +1,85 @@ +#ifndef _WRAPPING_DAP_CHAIN_NODE_CLIENT_ +#define _WRAPPING_DAP_CHAIN_NODE_CLIENT_ + +#include <Python.h> +#include "dap_chain_node_client.h" +#include "wrapping_dap_chain_net_node_info.h" +#include "libdap_client_python.h" +#include "wrapping_dap_client_stage.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +typedef struct PyDapChainNodeClient{ + PyObject_HEAD + dap_chain_node_client_t *node_client; +}PyDapChainNodeClientObject; + +int dap_chain_node_client_init_py(void); +void dap_chain_node_client_deinit_py(void); + +PyObject *dap_chain_client_connect_py(PyObject *self, PyObject *args); +PyObject *dap_chain_node_client_connect_py(PyObject *self, PyObject *args); +PyObject *dap_chain_node_client_close_py(PyObject *self, PyObject *args); +PyObject *dap_chain_node_client_send_ch_pkt_py(PyObject *self, PyObject *args); +PyObject *dap_chain_node_client_wait_py(PyObject *self, PyObject *args); +PyObject *dap_chain_node_client_set_callbacks_py(PyObject *self, PyObject *args); + +static PyMethodDef DapChainNodeClientMethods[] = { + {"clientConnect", dap_chain_client_connect_py, METH_VARARGS | METH_STATIC, ""}, + {"nodeClientConnect", (PyCFunction)dap_chain_node_client_connect_py, METH_VARARGS | METH_STATIC, ""}, + {"close", (PyCFunction)dap_chain_node_client_close_py, METH_VARARGS, ""}, + {"sendChPkt", (PyCFunction)dap_chain_node_client_send_ch_pkt_py, METH_VARARGS, ""}, + {"wait", (PyCFunction)dap_chain_node_client_wait_py, METH_VARARGS, ""}, + {"setCallbacks", (PyCFunction)dap_chain_node_client_set_callbacks_py, METH_VARARGS | METH_STATIC, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapChainNodeClientObject_DapChainNodeClientObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.Node.Client", /* tp_name */ + sizeof(PyDapChainNodeClientObject), /* 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 */ + "Chain net node client object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapChainNodeClientMethods, /* 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 + +#endif //_WRAPPING_DAP_CHAIN_NODE_CLIENT_ diff --git a/cellframe-sdk-python/libdap-chain-net-python/include/wrapping_dap_chain_net_node_info.h b/cellframe-sdk-python/libdap-chain-net-python/include/wrapping_dap_chain_net_node_info.h new file mode 100644 index 0000000000000000000000000000000000000000..aa49697ed63a7c97a3372da74c5d4dc4447dbe59 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-net-python/include/wrapping_dap_chain_net_node_info.h @@ -0,0 +1,72 @@ +#ifndef _WRAPPING_DAP_CHAIN_NODE_INFO +#define _WRAPPING_DAP_CHAIN_NODE_INFO +#include <Python.h> +#include "dap_chain_node.h" +#include "libdap_chain_net_python.h" +#include "wrapping_dap_chain_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PyDapChainNodeInfo{ + PyObject_HEAD + dap_chain_node_info_t *node_info; +}PyDapChainNodeInfoObject; + +PyObject *dap_chain_node_info_save_py(PyObject *self, PyObject *args); +PyObject *dap_chain_node_info_read_py(PyObject *self, PyObject *args); + +static PyMethodDef DapChainNetNodeInfoMethods[] = { + {"save", dap_chain_node_info_save_py, METH_VARARGS, ""}, + {"read", dap_chain_node_info_read_py, METH_VARARGS | METH_STATIC, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapChainNodeInfoObject_DapChainNodeInfoObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.Node.Info", /* tp_name */ + sizeof(PyDapChainNodeInfoObject), /* 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 */ + "Chain net node info object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapChainNetNodeInfoMethods, /* 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 + +#endif //_WRAPPING_DAP_CHAIN_NODE_INFO diff --git a/cellframe-sdk-python/libdap-chain-net-python/include/wrapping_dap_chain_net_state.h b/cellframe-sdk-python/libdap-chain-net-python/include/wrapping_dap_chain_net_state.h new file mode 100644 index 0000000000000000000000000000000000000000..880a4f51640720bc6159560183740ad046955323 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-net-python/include/wrapping_dap_chain_net_state.h @@ -0,0 +1,85 @@ +#ifndef _WRAPPING_DAP_CHAIN_NET_STATE_ +#define _WRAPPING_DAP_CHAIN_NET_STATE_ +#include <Python.h> +#include "dap_chain_net.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +typedef struct PyDapChainNetState{ + PyObject_HEAD + dap_chain_net_state_t state; +}PyDapChainNetStateObject; + +PyObject *NET_STATE_OFFLINE_PY(void); +PyObject *NET_STATE_LINKS_PREPARE_PY(void); +PyObject *NET_STATE_LINKS_CONNECTING_PY(void); +PyObject *NET_STATE_LINKS_ESTABLISHED_PY(void); +PyObject *NET_STATE_ADDR_REQUEST_PY(void); // Waiting for address assign +PyObject *NET_STATE_ONLINE_PY(void); +PyObject *NET_STATE_SYNC_GDB_PY(void); +PyObject *NET_STATE_SYNC_CHAINS_PY(void); + +static PyMethodDef PyDapChainNetStateMethods[] = { + {"NET_STATE_OFFLINE", (PyCFunction)NET_STATE_OFFLINE_PY, METH_NOARGS | METH_STATIC, ""}, + {"NET_STATE_LINKS_PREPARE", (PyCFunction)NET_STATE_LINKS_PREPARE_PY, METH_NOARGS | METH_STATIC, ""}, + {"NET_STATE_LINKS_CONNECTING", (PyCFunction)NET_STATE_LINKS_CONNECTING_PY, METH_NOARGS | METH_STATIC, ""}, + {"NET_STATE_LINKS_ESTABLISHED", (PyCFunction)NET_STATE_LINKS_ESTABLISHED_PY, METH_NOARGS | METH_STATIC, ""}, + {"NET_STATE_ADDR_REQUEST", (PyCFunction)NET_STATE_ADDR_REQUEST_PY, METH_NOARGS | METH_STATIC, ""}, + {"NET_STATE_SYNC_GDB", (PyCFunction)NET_STATE_SYNC_GDB_PY, METH_NOARGS | METH_STATIC, ""}, + {"NET_STATE_SYNC_CHAINS", (PyCFunction)NET_STATE_SYNC_CHAINS_PY, METH_NOARGS | METH_STATIC, ""}, + /*{"csAdd", (PyCFunction)dap_chain_cs_add_py, METH_VARARGS, ""}, + {"csCreate", (PyCFunction)dap_chain_cs_create_py, METH_VARARGS, ""}, + {"classAdd", (PyCFunction)dap_chain_class_add_py, METH_VARARGS, ""}, + {"classCreate", (PyCFunction)dap_chain_class_create_py, METH_VARARGS, ""},*/ + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapChainNetStateObject_DapChainNetStateObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.ChainNetState", /* tp_name */ + sizeof(PyDapChainNetStateObject), /* 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 */ + "Chain net staties object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + PyDapChainNetStateMethods, /* 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 + +#endif // _WRAPPING_DAP_CHAIN_NET_STATE_ diff --git a/cellframe-sdk-python/libdap-chain-net-python/src/libdap_chain_net_python.c b/cellframe-sdk-python/libdap-chain-net-python/src/libdap_chain_net_python.c new file mode 100644 index 0000000000000000000000000000000000000000..18f0d5db8233e098cf3fc06b2ee52641c7a7ebb8 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-net-python/src/libdap_chain_net_python.c @@ -0,0 +1,140 @@ +#include "libdap_chain_net_python.h" + +int dap_chain_net_init_py(void){ + int res = dap_chain_net_init(); + return res; +} +void dap_chain_net_deinit_py(void){ + dap_chain_net_deinit(); +} + +PyObject *dap_chain_net_load_all_py(PyObject *self, PyObject *args){ + dap_chain_net_load_all(); + return PyLong_FromLong(0); +} +PyObject *dap_chain_net_state_go_to_py(PyObject *self, PyObject *args){ + PyObject *obj_net_state; + if (!PyArg_ParseTuple(args, "O", &obj_net_state)) + return NULL; + int res = dap_chain_net_state_go_to(((PyDapChainNetObject*)self)->chain_net, ((PyDapChainNetStateObject*)obj_net_state)->state); + return PyLong_FromLong(res); +} +PyObject *dap_chain_net_start_py(PyObject *self, PyObject *args){ + int res = dap_chain_net_start(((PyDapChainNetObject*)self)->chain_net); + return PyLong_FromLong(res); +} +PyObject *dap_chain_net_stop_py(PyObject *self, PyObject *args){ + int res = dap_chain_net_stop(((PyDapChainNetObject*)self)->chain_net); + return PyLong_FromLong(res); +} +PyObject *dap_chain_net_links_establish_py(PyObject *self, PyObject *args){ + int res = dap_chain_net_links_establish(((PyDapChainNetObject*)self)->chain_net); + return PyLong_FromLong(res); +} +PyObject *dap_chain_net_sync_chains_py(PyObject *self, PyObject *args){ + int res = dap_chain_net_sync_chains(((PyDapChainNetObject*)self)->chain_net); + return PyLong_FromLong(res); +} +PyObject *dap_chain_net_sync_gdb_py(PyObject *self, PyObject *args){ + int res = dap_chain_net_sync_gdb(((PyDapChainNetObject*)self)->chain_net); + return PyLong_FromLong(res); +} +PyObject *dap_chain_net_sync_all_py(PyObject *self, PyObject *args){ + int res = dap_chain_net_sync_all(((PyDapChainNetObject*)self)->chain_net); + return PyLong_FromLong(res); +} + +PyObject *dap_chain_net_proc_datapool_py(PyObject *self, PyObject *args){ + //dap_chain_net_proc_datapool(((PyDapChainNetObject*)self)->chain_net); + //return PyLong_FromLong(0); + return NULL; +} + +PyObject *dap_chain_net_by_name_py(PyObject *self, PyObject *args){ + const char *a_name; + if (!PyArg_ParseTuple(args, "s", &a_name)) + return NULL; + PyObject *obj_chain_net = _PyObject_New(&DapChainNetObject_DapChainNetObjectType); + ((PyDapChainNetObject*)obj_chain_net)->chain_net = dap_chain_net_by_name(a_name); + return Py_BuildValue("O", obj_chain_net); +} +PyObject *dap_chain_net_by_id_py(PyObject *self, PyObject *args){ + PyObject *obj_net_id; + if (!PyArg_ParseTuple(args, "O", &obj_net_id)) + return NULL; + PyObject *obj_net = _PyObject_New(&DapChainNetObject_DapChainNetObjectType); + ((PyDapChainNetObject*)obj_net)->chain_net = dap_chain_net_by_id(((PyDapChainNetIdObject*)obj_net_id)->net_id); + return Py_BuildValue("O", obj_net); +} +PyObject *dap_chain_net_id_by_name_py(PyObject *self, PyObject *args){ + const char *name; + if (!PyArg_ParseTuple(args, "s", &name)) + return NULL; + PyObject *obj_net_id = _PyObject_New(&DapChainNetIdObject_DapChainNetIdObjectType); + ((PyDapChainNetIdObject*)obj_net_id)->net_id = dap_chain_net_id_by_name(name); + return Py_BuildValue("O", obj_net_id); +} +PyObject *dap_chain_ledger_by_net_name_py(PyObject *self, PyObject *args){ + const char *net_name; + if (!PyArg_ParseTuple(args, "s", &net_name)) + return NULL; + PyObject *obj_ledger = _PyObject_New(&DapChainLedger_DapChainLedgerType); + ((PyDapChainLedgerObject*)obj_ledger)->ledger = dap_chain_ledger_by_net_name(net_name); + return Py_BuildValue("O", obj_ledger); +} + +PyObject *dap_chain_net_get_chain_by_name_py(PyObject *self, PyObject *args){ + const char* chain_name; + if (!PyArg_ParseTuple(args, "s", &chain_name)) + return NULL; + PyObject *obj_chain = _PyObject_New(&dapChainObject_dapChainType); + ((PyDapChainObject*)obj_chain)->chain_t = dap_chain_net_get_chain_by_name(((PyDapChainNetObject*)self)->chain_net, chain_name); + return Py_BuildValue("O", obj_chain); +} + +PyObject *dap_chain_net_get_cur_addr_py(PyObject *self, PyObject *args){ + PyObject *obj_node_addr = _PyObject_New(&DapChainNodeAddrObject_DapChainNodeAddrObjectType); + ((PyDapChainNodeAddrObject*)obj_node_addr)->node_addr = dap_chain_net_get_cur_addr(((PyDapChainNetObject*)self)->chain_net); + return Py_BuildValue("O", obj_node_addr); +} +PyObject *dap_chain_net_get_cur_cell_py(PyObject *self, PyObject *args){ + PyObject *obj_cell_id = _PyObject_New(&DapChainNodeAddrObject_DapChainNodeAddrObjectType); + ((PyDapChainCellIDObject*)obj_cell_id)->cell_id = *(dap_chain_net_get_cur_cell(((PyDapChainNetObject*)self)->chain_net)); + return Py_BuildValue("O", obj_cell_id); +} +PyObject *dap_chain_net_get_cur_addr_int_py(PyObject *self, PyObject *args){ + uint64_t res = dap_chain_net_get_cur_addr_int(((PyDapChainNetObject*)self)->chain_net); + return PyLong_FromUnsignedLongLong(res); +} + +PyObject *dap_chain_net_get_gdb_group_mempool_py(PyObject *self, PyObject *args){ + PyObject *obj_chain; + if (!PyArg_ParseTuple(args, "O", &obj_chain)) + return NULL; + char *res = dap_chain_net_get_gdb_group_mempool(((PyDapChainObject*)obj_chain)->chain_t); + return Py_BuildValue("s", res); +} +PyObject *dap_chain_net_get_gdb_group_mempool_by_chain_type_py(PyObject *self, PyObject *args){ + PyObject *obj_chain_type; + if (!PyArg_ParseTuple(args, "O", &obj_chain_type)) + return NULL; + char *res = dap_chain_net_get_gdb_group_mempool_by_chain_type(((PyDapChainNetObject*)self)->chain_net, + ((PyChainTypeObject*)obj_chain_type)->chain_type); + return Py_BuildValue("s", res); + +} +PyObject *dap_chain_net_links_connect_py(PyObject *self, PyObject *args){ +// dap_chain_net_links_connect(((PyDapChainNetObject*)self)->chain_net); +// PyLong_FromLong(0); + return NULL; +} +PyObject *dap_chain_net_get_chain_by_chain_type_py(PyObject *self, PyObject *args){ + PyObject *obj_chain_type; + if(!PyArg_ParseTuple(args, "O", &obj_chain_type)) + return NULL; + PyObject *obj_chain = _PyObject_New(&dapChainObject_dapChainType); + ((PyDapChainObject*)obj_chain)->chain_t = dap_chain_net_get_chain_by_chain_type( + ((PyDapChainNetObject*)self)->chain_net, + ((PyChainTypeObject*)obj_chain_type)->chain_type); + return Py_BuildValue("O", obj_chain); +} diff --git a/cellframe-sdk-python/libdap-chain-net-python/src/wrapping_dap_app_cli_server.c b/cellframe-sdk-python/libdap-chain-net-python/src/wrapping_dap_app_cli_server.c new file mode 100644 index 0000000000000000000000000000000000000000..733da1226698a444f56905722427f580c53c2abd --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-net-python/src/wrapping_dap_app_cli_server.c @@ -0,0 +1,181 @@ +#include "wrapping_dap_app_cli_server.h" + +#define LOG_TAG "wrapping_dap_app_cli_server" + +int dap_chain_node_cli_init_py(dap_config_t *g_config){ + log_it(L_DEBUG, "Init app cli server"); + dap_chain_node_cli_init(g_config); + l_str_reply_list = NULL; + l_element_py_func_list = NULL; + return 0; +} +void dap_chain_node_cli_delete_py(void){ + element_py_func_del_all(); + elements_str_reply_delete_all(); + dap_chain_node_cli_delete(); +} + +size_t elements_str_reply_add(char** str_reply){ + size_t max_index = 0; + element_str_reply_t *el; + LL_FOREACH(l_str_reply_list, el){ + if (max_index < el->id) + max_index = el->id; + } + size_t new_index = max_index+1; + element_str_reply_t *new_el = DAP_NEW(element_str_reply_t); + new_el->str_reply = str_reply; + new_el->id = new_index; + LL_APPEND(l_str_reply_list, new_el); + return new_index; +} +int elements_str_reply_cmp_by_id(element_str_reply_t *e1, element_str_reply_t *e2){ + if (e1->id == e2->id) + return 0; + else + return 1; +} +char** elements_str_reply_get_by_id(size_t id){ + element_str_reply_t *el, *tmp; + tmp = DAP_NEW(element_str_reply_t); + tmp->id = id; + LL_SEARCH(l_str_reply_list, el, tmp, elements_str_reply_cmp_by_id); + DAP_FREE(tmp); + if (el) + return el->str_reply; + return NULL; +} +void elements_str_reply_delete(size_t id){ + element_str_reply_t *el, *tmp; + LL_FOREACH_SAFE(l_str_reply_list, el, tmp){ + if (id == el->id){ + LL_DELETE(l_str_reply_list, el); + DAP_FREE(el); + } + } +} +void elements_str_reply_delete_all(){ + element_str_reply_t *el, *tmp; + LL_FOREACH_SAFE(l_str_reply_list, el, tmp){ + LL_DELETE(l_str_reply_list, el); + DAP_FREE(el); + } +} + +void element_py_func_add(const char *name, PyObject *func){ + element_py_func_t *el = DAP_NEW(element_py_func_t); + el->name = name; + el->func = func; + Py_XINCREF(el->func); + LL_APPEND(l_element_py_func_list, el); +} +int element_py_func_cmp_by_name(element_py_func_t *e1, element_py_func_t *e2){ + return dap_strcmp(e1->name, e2->name); +} +PyObject *element_py_func_get(char *name){ + element_py_func_t *el, *like; + like = DAP_NEW(element_py_func_t); + like->name = name; + LL_SEARCH(l_element_py_func_list, el, like, element_py_func_cmp_by_name); + DAP_FREE(like); + return el->func; +} +void element_py_func_del_by_name(char *name){ + element_py_func_t *el, *like; + like = DAP_NEW(element_py_func_t); + like->name = name; + LL_SEARCH(l_element_py_func_list, el, like, element_py_func_cmp_by_name); + DAP_FREE(like); + LL_DELETE(l_element_py_func_list, el); + Py_XDECREF(el->func); + DAP_FREE(el); +} +void element_py_func_del_all(){ + element_py_func_t *el, *tmp; + LL_FOREACH_SAFE(l_element_py_func_list, el, tmp){ + LL_DELETE(l_element_py_func_list, el); + Py_XDECREF(el->func); + DAP_FREE(el); + } +} + +static int wrapping_cmdfunc(int argc, char **argv, char **str_reply){ + size_t id_str_replay = elements_str_reply_add(str_reply); + PyObject *obj_argv = stringToPyList(argc, argv); + PyObject *obj_id_str_replay = PyLong_FromSize_t(id_str_replay); + PyObject *arglist = Py_BuildValue("OO", obj_argv, obj_id_str_replay); + Py_XINCREF(arglist); + PyObject *binden_obj_cmdfunc = element_py_func_get(argv[0]); + PyObject *result = PyObject_CallObject(binden_obj_cmdfunc, arglist); + if (!result){ + log_it(L_DEBUG, "Function can't called"); + PyErr_Print(); + } + Py_XDECREF(arglist); + Py_XDECREF(obj_argv); + elements_str_reply_delete(id_str_replay); + return 0; +} + +PyObject *DapChainNodeCliObject_new(PyTypeObject *type_object, PyObject *args, PyObject *kwds){ + PyDapAppCliServerObject *obj = (PyDapAppCliServerObject*)PyType_GenericNew(type_object, args, kwds); + obj->func = wrapping_cmdfunc; + return (PyObject *)obj; +} + +PyObject *dap_chain_node_cli_cmd_item_create_py(PyObject *a_self, PyObject *a_args){ + (void) a_self; + const char *name, *doc, *doc_ex; + PyObject *obj_cmdfunc; + if (!PyArg_ParseTuple(a_args, "s|O|s|s", &name, &obj_cmdfunc, &doc, &doc_ex)){ + return NULL; + }else { + if (!PyCallable_Check(obj_cmdfunc)){ + PyErr_SetString(PyExc_TypeError, "parameter must be callable"); + return NULL; + } + } + element_py_func_add(name, obj_cmdfunc); + dap_chain_node_cli_cmd_item_create(name, wrapping_cmdfunc, NULL, doc, doc_ex); + return PyLong_FromLong(0); +} + +PyObject *dap_chain_node_cli_set_reply_text_py(PyObject *self, PyObject *args){ + (void) self; + PyObject *obj_id_str_reply; + const char *str_reply_text; + if (!PyArg_ParseTuple(args, "sO", &str_reply_text, &obj_id_str_reply)) + return NULL; + size_t id_str_reply = PyLong_AsSize_t(obj_id_str_reply); + dap_chain_node_cli_set_reply_text(elements_str_reply_get_by_id(id_str_reply), str_reply_text); + return PyLong_FromLong(0); +} + +PyObject *dap_chain_node_addr_get_by_alias_py(PyObject *self, PyObject *args){ + (void) self; + PyObject *chain_net; + const char *alias; + if (!PyArg_ParseTuple(args, "O|s", &chain_net, &alias)) + return NULL; + PyObject *obj_node_addr = _PyObject_New(&DapChainNodeAddrObject_DapChainNodeAddrObjectType); + ((PyDapChainNodeAddrObject*)obj_node_addr)->node_addr = dap_chain_node_addr_get_by_alias(((PyDapChainNetObject*)chain_net)->chain_net, alias); + return Py_BuildValue("O", obj_node_addr); +} + +char **PyListToString(PyObject *list){ + Py_ssize_t size = PyList_Size(list); + char **result = DAP_NEW_SIZE(char*, size); + for (Py_ssize_t i=0; i<size;i++){ + PyObject *element = PyList_GetItem(list, i); + result[i] = dap_strdup(PyUnicode_AsUTF8(element)); + } + return result; +} + +PyObject *stringToPyList(int argc, char **list){ + PyObject *obj_list = PyList_New(0); + for (int i=0; i < argc; i++){ + PyList_Append(obj_list, PyUnicode_FromString(list[i])); + } + return obj_list; +} diff --git a/cellframe-sdk-python/libdap-chain-net-python/src/wrapping_dap_chain_net_node.c b/cellframe-sdk-python/libdap-chain-net-python/src/wrapping_dap_chain_net_node.c new file mode 100644 index 0000000000000000000000000000000000000000..6dbd5e98a32e34a1e0c8aa63645cd62adad44ffd --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-net-python/src/wrapping_dap_chain_net_node.c @@ -0,0 +1,55 @@ +#include "wrapping_dap_chain_net_node.h" + +PyObject *dap_chain_node_gen_addr_py(PyObject *self, PyObject *args){ + PyObject *obj_net; + PyObject *obj_cell_id; + if (!PyArg_ParseTuple(args, "O|O", &obj_net, &obj_cell_id)) + return NULL; + PyObject *obj_node_addr = _PyObject_New(&DapChainNodeAddrObject_DapChainNodeAddrObjectType); + ((PyDapChainNodeAddrObject*)obj_node_addr)->node_addr = dap_chain_node_gen_addr(((PyDapChainNetObject*)obj_net)->chain_net, &(((PyDapChainCellIDObject*)obj_cell_id)->cell_id)); + return Py_BuildValue("O", obj_node_addr); +} +PyObject *dap_chain_node_check_addr_py(PyObject *self, PyObject *args){ + PyObject *obj_chain_net; + PyObject *obj_node_addr; + PyObject *obj_cell_id; + if (!PyArg_ParseTuple(args, "O|O|O", &obj_chain_net, &obj_node_addr, &obj_cell_id)) + return NULL; + bool ret = dap_chain_node_check_addr(((PyDapChainNetObject*)obj_chain_net)->chain_net, ((PyDapChainNodeAddrObject*)obj_node_addr)->node_addr, &(((PyDapChainCellIDObject*)obj_cell_id)->cell_id)); + if (ret) + return Py_BuildValue("O", Py_True); + else + return Py_BuildValue("O", Py_False); +} +PyObject *dap_chain_node_alias_find_py(PyObject *self, PyObject *args){ + PyObject *obj_chain_net; + const char *alias; + if (!PyArg_ParseTuple(args, "O|s", &obj_chain_net, &alias)) + return NULL; + PyObject *obj_node_addr = _PyObject_New(&DapChainNodeAddrObject_DapChainNodeAddrObjectType); + ((PyDapChainNodeAddrObject*)obj_node_addr)->node_addr = dap_chain_node_alias_find(((PyDapChainNetObject*)obj_node_addr)->chain_net, alias); + return Py_BuildValue("O", &obj_node_addr); +} +PyObject *dap_chain_node_alias_register_py(PyObject *self, PyObject *args){ + PyObject *obj_chain_net; + const char *alias; + PyObject *obj_node_addr; + if (!PyArg_ParseTuple(args, "O|s|O", &obj_chain_net, &alias, &obj_node_addr)) + return NULL; + bool ret = dap_chain_node_alias_register(((PyDapChainNetObject*)obj_chain_net)->chain_net, alias, ((PyDapChainNodeAddrObject*)obj_node_addr)->node_addr); + if (ret) + return Py_BuildValue("O", Py_True); + else + return Py_BuildValue("O", Py_False); +} +PyObject *dap_chain_node_alias_delete_py(PyObject *self, PyObject *args){ + PyObject *obj_chain_net; + const char *alias; + if (!PyArg_ParseTuple(args, "O|s", &obj_chain_net, &alias)) + return NULL; + bool ret = dap_chain_node_alias_delete(((PyDapChainNetObject*)obj_chain_net)->chain_net, alias); + if (ret) + return Py_BuildValue("O", Py_True); + else + return Py_BuildValue("O", Py_False); +} diff --git a/cellframe-sdk-python/libdap-chain-net-python/src/wrapping_dap_chain_net_node_client.c b/cellframe-sdk-python/libdap-chain-net-python/src/wrapping_dap_chain_net_node_client.c new file mode 100644 index 0000000000000000000000000000000000000000..4a2e5b08ed538a426b61e6362aee6f5f15971b17 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-net-python/src/wrapping_dap_chain_net_node_client.c @@ -0,0 +1,66 @@ +#include "wrapping_dap_chain_net_node_client.h" + +int dap_chain_node_client_init_py(void){ + return dap_chain_node_client_init(); +} +void dap_chain_node_client_deinit_py(void){ + dap_chain_node_client_deinit(); +} + +PyObject *dap_chain_client_connect_py(PyObject *self, PyObject *args){ + PyObject *obj_node_info; + PyObject *obj_client_stage; + const char *active_channels; + if (!PyArg_ParseTuple(args, "O|O|s", &obj_node_info, &obj_client_stage, &active_channels)) + return NULL; + PyObject *obj_node_client = _PyObject_New(&DapChainNodeClientObject_DapChainNodeClientObjectType); + ((PyDapChainNodeClientObject*)obj_node_client)->node_client =dap_chain_client_connect( + ((PyDapChainNodeInfoObject*)obj_node_info)->node_info, + ((PyDapClientStageObject*)obj_client_stage)->stage, active_channels); + return Py_BuildValue("O", obj_node_client); +} +PyObject *dap_chain_node_client_connect_py(PyObject *self, PyObject *args){ + if (self != NULL){ + PyErr_SetString(PyExc_SyntaxWarning, "This is method called statically"); + return NULL; + } + PyObject *obj_node_info; + if (!PyArg_ParseTuple(args, "O", &obj_node_info)) + return NULL; + PyObject *obj_node_client = _PyObject_New(&DapChainNodeClientObject_DapChainNodeClientObjectType); + ((PyDapChainNodeClientObject*)obj_node_client)->node_client = dap_chain_node_client_connect(((PyDapChainNodeInfoObject*)obj_node_info)->node_info); + return Py_BuildValue("O", obj_node_client); +} +PyObject *dap_chain_node_client_close_py(PyObject *self, PyObject *args){ + dap_chain_node_client_close(((PyDapChainNodeClientObject*)self)->node_client); + return PyLong_FromLong(0); +} +PyObject *dap_chain_node_client_send_ch_pkt_py(PyObject *self, PyObject *args){ + uint8_t ch_id; + uint8_t type; + PyObject *obj_buf; + void *buf; + size_t buf_size; + if (!PyArg_ParseTuple(args, "b|b|O", &ch_id, &type, &obj_buf)) + return NULL; + buf = PyBytes_AsString(obj_buf); + buf_size = (size_t)PyBytes_Size(buf); + int res = dap_chain_node_client_send_ch_pkt(((PyDapChainNodeClientObject*)self)->node_client, ch_id, type, buf, buf_size); + return PyLong_FromLong(res); +} +PyObject *dap_chain_node_client_wait_py(PyObject *self, PyObject *args){ + int waited_state; + int timeout_ms; + if (!PyArg_ParseTuple(args, "i|i", &waited_state, &timeout_ms)) + return NULL; + int res = dap_chain_node_client_wait(((PyDapChainNodeClientObject*)self)->node_client, waited_state, timeout_ms); + return PyLong_FromLong(res); +} +PyObject *dap_chain_node_client_set_callbacks_py(PyObject *self, PyObject *args){ + PyObject *obj_dap_client; + uint8_t ch_id; + if (!PyArg_ParseTuple(args, "O|b", &obj_dap_client, &ch_id)) + return NULL; + int res = dap_chain_node_client_set_callbacks(((PyDapClientObject*)obj_dap_client)->client, ch_id); + return PyLong_FromLong(res); +} diff --git a/cellframe-sdk-python/libdap-chain-net-python/src/wrapping_dap_chain_net_node_info.c b/cellframe-sdk-python/libdap-chain-net-python/src/wrapping_dap_chain_net_node_info.c new file mode 100644 index 0000000000000000000000000000000000000000..36e1915a3f1ca5d2178d0efe0ee7a45f5b521203 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-net-python/src/wrapping_dap_chain_net_node_info.c @@ -0,0 +1,19 @@ +#include "wrapping_dap_chain_net_node_info.h" + +PyObject *dap_chain_node_info_save_py(PyObject *self, PyObject *args){ + PyObject *obj_net; + if (!PyArg_ParseTuple(args, "O", &obj_net)) + return NULL; + int res = dap_chain_node_info_save(((PyDapChainNetObject*)obj_net)->chain_net, ((PyDapChainNodeInfoObject*)self)->node_info); + return PyLong_FromLong(res); +} + +PyObject *dap_chain_node_info_read_py(PyObject *self, PyObject *args){ + PyObject *obj_net; + PyObject *obj_node_addr; + if (!PyArg_ParseTuple(args, "O|O", &obj_net, &obj_node_addr)) + return NULL; + PyObject *obj_node_info = _PyObject_New(&DapChainNodeInfoObject_DapChainNodeInfoObjectType); + ((PyDapChainNodeInfoObject*)obj_node_info)->node_info = dap_chain_node_info_read(((PyDapChainNetObject*)obj_net)->chain_net, ((PyDapChainNodeAddrObject*)obj_node_addr)->node_addr); + return Py_BuildValue("O", &obj_node_info); +} diff --git a/cellframe-sdk-python/libdap-chain-net-python/src/wrapping_dap_chain_net_state.c b/cellframe-sdk-python/libdap-chain-net-python/src/wrapping_dap_chain_net_state.c new file mode 100644 index 0000000000000000000000000000000000000000..1042393fe4411d0da97437332de294f709eb26b4 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-net-python/src/wrapping_dap_chain_net_state.c @@ -0,0 +1,42 @@ +#include "wrapping_dap_chain_net_state.h" + +PyObject *NET_STATE_OFFLINE_PY(void){ + PyObject *obj = _PyObject_New(&DapChainNetStateObject_DapChainNetStateObjectType); + ((PyDapChainNetStateObject*)obj)->state = NET_STATE_OFFLINE; + return Py_BuildValue("O", obj); +} +PyObject *NET_STATE_LINKS_PREPARE_PY(void){ + PyObject *obj = _PyObject_New(&DapChainNetStateObject_DapChainNetStateObjectType); + ((PyDapChainNetStateObject*)obj)->state = NET_STATE_LINKS_PREPARE; + return Py_BuildValue("O", obj); +} +PyObject *NET_STATE_LINKS_CONNECTING_PY(void){ + PyObject *obj = _PyObject_New(&DapChainNetStateObject_DapChainNetStateObjectType); + ((PyDapChainNetStateObject*)obj)->state = NET_STATE_LINKS_CONNECTING; + return Py_BuildValue("O", obj); +} +PyObject *NET_STATE_LINKS_ESTABLISHED_PY(void){ + PyObject *obj = _PyObject_New(&DapChainNetStateObject_DapChainNetStateObjectType); + ((PyDapChainNetStateObject*)obj)->state = NET_STATE_LINKS_ESTABLISHED; + return Py_BuildValue("O", obj); +} +PyObject *NET_STATE_ADDR_REQUEST_PY(void){ // Waiting for address assign + PyObject *obj = _PyObject_New(&DapChainNetStateObject_DapChainNetStateObjectType); + ((PyDapChainNetStateObject*)obj)->state = NET_STATE_ADDR_REQUEST; + return Py_BuildValue("O", obj); +} +PyObject *NET_STATE_ONLINE_PY(void){ + PyObject *obj = _PyObject_New(&DapChainNetStateObject_DapChainNetStateObjectType); + ((PyDapChainNetStateObject*)obj)->state = NET_STATE_ONLINE; + return Py_BuildValue("O", obj); +} +PyObject *NET_STATE_SYNC_GDB_PY(void){ + PyObject *obj = _PyObject_New(&DapChainNetStateObject_DapChainNetStateObjectType); + ((PyDapChainNetStateObject*)obj)->state = NET_STATE_SYNC_GDB; + return Py_BuildValue("O", obj); +} +PyObject *NET_STATE_SYNC_CHAINS_PY(void){ + PyObject *obj = _PyObject_New(&DapChainNetStateObject_DapChainNetStateObjectType); + ((PyDapChainNetStateObject*)obj)->state = NET_STATE_SYNC_CHAINS; + return Py_BuildValue("O", obj); +} diff --git a/cellframe-sdk-python/libdap-chain-python b/cellframe-sdk-python/libdap-chain-python deleted file mode 160000 index c8bd568fe810165cf12fa55e96503ef955e09120..0000000000000000000000000000000000000000 --- a/cellframe-sdk-python/libdap-chain-python +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c8bd568fe810165cf12fa55e96503ef955e09120 diff --git a/cellframe-sdk-python/libdap-chain-python/.gitignore b/cellframe-sdk-python/libdap-chain-python/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..a752edf4c581d5a2b4fa518a38f5f0128d4e5e3d --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-python/.gitignore @@ -0,0 +1,55 @@ +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +#Build directory +build/ + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf diff --git a/cellframe-sdk-python/libdap-chain-python/CMakeLists.txt b/cellframe-sdk-python/libdap-chain-python/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..03a632ae051f3f2397a002a4c67a8b33e7580f40 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-python/CMakeLists.txt @@ -0,0 +1,208 @@ +project(dap_chain_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") +add_definitions("-DDAP_LOG_MT") + +if(UNIX) + add_definitions("-DDAP_OS_UNIX") +endif() + +if (NOT (${SUBMODULES_NO_BUILD} MATCHES ON)) + set (SUBMODULES_NO_BUILD ON) + if (NOT (TARGET dap_core)) + add_subdirectory(libdap) + target_compile_options( + dap_core PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_crypto)) + add_subdirectory(libdap-crypto) + target_compile_options( + dap_crypto PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain)) + add_subdirectory(libdap-chain) + target_compile_options( + dap_chain PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_crypto)) + add_subdirectory(libdap-chain-crypto) + target_compile_options( + dap_chain_crypto PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_common)) + add_subdirectory(libdap-chain-common) + target_compile_options( + dap_chain_common PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_mempool)) + add_subdirectory(libdap-chain-mempool) + target_compile_options( + dap_chain_mempool PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_net)) + add_subdirectory(libdap-chain-net) + target_compile_options( + dap_chain_net PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_server_core)) + add_subdirectory(libdap-server-core) + target_compile_options( + dap_server_core PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_global_db)) + add_subdirectory(libdap-chain-global-db) + target_compile_options( + dap_chain_global_db PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_client)) + add_subdirectory(libdap-client) + target_compile_options( + dap_client PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET libdap-server)) + add_subdirectory(libdap-server) +# target_compile_options( +# libdap-server PRIVATE +# "-fpic" +# ) + endif() + if (NOT (TARGET dap_stream)) + add_subdirectory(libdap-stream) + target_compile_options( + dap_stream PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_stream_ch)) + add_subdirectory(libdap-stream-ch) + target_compile_options( + dap_stream_ch PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_stream_ch_chain)) + add_subdirectory(libdap-stream-ch-chain) + target_compile_options( + dap_stream_ch_chain PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_stream_ch_chain_net)) + add_subdirectory(libdap-stream-ch-chain-net) + target_compile_options( + dap_stream_ch_chain_net PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_udp_server)) + add_subdirectory(libdap-server-udp) + target_compile_options( + dap_udp_server PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_wallet)) + add_subdirectory(libdap-chain-wallet) + target_compile_options( + dap_chain_wallet PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_net_srv)) + add_subdirectory(libdap-chain-net-srv) + target_compile_options( + dap_chain_net_srv PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_server_http_db_auth)) + add_subdirectory(libdap-server-http-db-auth) + target_compile_options( + dap_server_http_db_auth PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_gdb)) + add_subdirectory(libdap-chain-gdb) + target_compile_options( + dap_chain_gdb PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_python_module)) + add_subdirectory(libdap-python) + target_compile_options( + dap_python_module PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_crypto_python_module)) + add_subdirectory(libdap-crypto-python) + target_compile_options( + dap_crypto_python_module PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_net_srv_vpn)) + add_subdirectory(libdap-chain-net-srv-vpn) + target_compile_options( + dap_chain_net_srv_vpn PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_server_http_db)) + add_subdirectory(libdap-server-http-db) + target_compile_options( + dap_server_http_db PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_chain_common_python_module)) + add_subdirectory(libdap-chain-common-python) + target_compile_options( + dap_chain_common_python_module PRIVATE + "-fpic" + ) + endif() +endif() +#add_definitions("-DDAP_APP_NAME=\"TestPRJ\" -DSYSTEM_CONFIGS_DIR=\"${CMAKE_CURRENT_BINARY_DIR}\"") + +file(GLOB CHAIN_PYTHON_SRCS src/*.c) +file(GLOB CHAIN_PYTHON_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 ${CHAIN_PYTHON_SRCS} ${CHAIN_PYTHON_HEADERS}) + +target_link_libraries(${PROJECT_NAME}) + +target_link_libraries(${PROJECT_NAME} dap_core dap_crypto dap_chain dap_chain_crypto dap_server_core dap_chain_net dap_crypto_python_module dap_python_module dap_chain_common_python_module) + +target_include_directories(${PROJECT_NAME} PUBLIC include/ ) + diff --git a/cellframe-sdk-python/libdap-chain-python/LICENSE b/cellframe-sdk-python/libdap-chain-python/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..f288702d2fa16d3cdf0035b15a9fcbc552cd88e7 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-python/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + <program> Copyright (C) <year> <name of author> + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +<https://www.gnu.org/licenses/>. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +<https://www.gnu.org/licenses/why-not-lgpl.html>. diff --git a/cellframe-sdk-python/libdap-chain-python/README.md b/cellframe-sdk-python/libdap-chain-python/README.md new file mode 100644 index 0000000000000000000000000000000000000000..35111e4959837546a7ae3f166a5a3fd141e4b04c --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-python/README.md @@ -0,0 +1,2 @@ +# libdap-chain-python +Chains bindings (including libdap, libdap-crypto, libdap-server, libdap-server-core, libdap-stream, libdap-stream-ch and etc ) diff --git a/cellframe-sdk-python/libdap-chain-python/include/libdap-chain-python.h b/cellframe-sdk-python/libdap-chain-python/include/libdap-chain-python.h new file mode 100644 index 0000000000000000000000000000000000000000..3dee0e47cef6444023caa6ff756f9f8f77f602dc --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-python/include/libdap-chain-python.h @@ -0,0 +1,88 @@ +#pragma once + +#define PY_SSIZE_T_CLEAN + +#include "Python.h" +//#define DAP_APP_NAME "BINDING_CHAIN_PYTHON" +#include "dap_chain.h" +#include "dap_chain_node_client.h" +#include "wrapping_dap_chain_ledger.h" +#include "wrapping_dap_chain_common.h" + + +typedef struct PyDapChain{ + PyObject_HEAD + dap_chain_t *chain_t; +} PyDapChainObject; + +int init_chain_py(); +void deinit_chain_py(); + +void PyDapChainObject_dealloc(PyDapChainObject* chain); +PyObject *PyDapChainObject_new(PyTypeObject *type_object, PyObject *args, PyObject *kwds); + + +PyObject *dap_chain_find_by_id_py(PyObject *self, PyObject *args); +//PyObject *dap_chain_load_from_cfg_py(PyObject *self, PyObject *args); +PyObject *dap_chain_has_file_store_py(PyObject *self, PyObject *args); +PyObject *dap_chain_save_all_py(PyObject *self, PyObject *args); +PyObject *dap_chain_load_all_py(PyObject *self, PyObject *args); +PyObject *dap_chain_load_from_cfg_py(PyObject *self, PyObject *args); +//PyObject *dap_chain_init_net_cfg_name_py(PyObject *self, PyObject *args); //dap_chain_init_net_cfg_name +//PyObject *dap_chain_close_py(PyObject *self, PyObject *args); +//PyObject *dap_chain_info_dump_log_py(PyObject *self, PyObject *args); //dap_chain_info_dump_log + +static PyMethodDef DapChainMethods[] = { + {"findById", (PyCFunction)dap_chain_find_by_id_py, METH_VARARGS|METH_STATIC, ""}, + {"loadFromCfg", (PyCFunction)dap_chain_has_file_store_py, METH_VARARGS|METH_STATIC, ""}, + {"hasFileStore", (PyCFunction)dap_chain_has_file_store_py, METH_NOARGS, ""}, + {"saveAll", (PyCFunction)dap_chain_save_all, METH_NOARGS, ""}, + {"loadAll", (PyCFunction)dap_chain_load_all_py, METH_NOARGS, ""}, + //{"close", (PyCFunction)dap_chain_close_py, METH_NOARGS, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject dapChainObject_dapChainType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain", /* tp_name */ + sizeof(PyDapChainObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)PyDapChainObject_dealloc, /* 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 */ + "Chain objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapChainMethods, /* 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 */ + PyDapChainObject_new, /* tp_new */ + +}; + + diff --git a/cellframe-sdk-python/libdap-chain-python/include/libdap_chain_atom_iter_python.h b/cellframe-sdk-python/libdap-chain-python/include/libdap_chain_atom_iter_python.h new file mode 100644 index 0000000000000000000000000000000000000000..9e9b22a77f09ebbdfb27afa7ce06d2f5b8ef7b64 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-python/include/libdap_chain_atom_iter_python.h @@ -0,0 +1,66 @@ +#ifndef _LIBDAP_CHAIN_ATOM_ITER_PYTHON_ +#define _LIBDAP_CHAIN_ATOM_ITER_PYTHON_ +#include "Python.h" +#include "dap_chain.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PyChainAtomPtr{ + PyObject_HEAD + dap_chain_atom_iter_t *atom_iter; +} PyChainAtomIterObject; + +static PyMethodDef DapChainAtomIterMethods[] = { + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject dapChainAtomPtr_dapChainAtomPtrType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.AtomIter", /* tp_name */ + sizeof(PyChainAtomIterObject), /* 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 */ + "Chain atom iter objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapChainAtomIterMethods, /* 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 + +#endif //_LIBDAP_CHAIN_ATOM_ITER_PYTHON_ diff --git a/cellframe-sdk-python/libdap-chain-python/include/libdap_chain_type_python.h b/cellframe-sdk-python/libdap-chain-python/include/libdap_chain_type_python.h new file mode 100644 index 0000000000000000000000000000000000000000..3c935f5145293fe064ac1bf9984ddc13ddec42df --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-python/include/libdap_chain_type_python.h @@ -0,0 +1,77 @@ +#ifndef _LIBDAP_CHAIN_TYPE_PYTHON_ +#define _LIBDAP_CHAIN_TYPE_PYTHON_ +#include "Python.h" +#include "dap_chain.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PyChainType{ + PyObject_HEAD + dap_chain_type_t chain_type; +} PyChainTypeObject; + +PyObject* CHAIN_TYPE_FIRST_PY(); +PyObject* CHAIN_TYPE_TOKEN_PY(); +PyObject* CHAIN_TYPE_EMISSION_PY(); +PyObject* CHAIN_TYPE_TX_PY(); +PyObject* CHAIN_TYPE_LAST_PY(); + +static PyMethodDef DapChainTypeMethods[] = { + {"CHAIN_TYPE_FIRST", (PyCFunction)CHAIN_TYPE_FIRST_PY, METH_NOARGS|METH_STATIC, ""}, + {"CHAIN_TYPE_TOKEN", (PyCFunction)CHAIN_TYPE_TOKEN_PY, METH_NOARGS|METH_STATIC, ""}, + {"CHAIN_TYPE_EMISSION", (PyCFunction)CHAIN_TYPE_EMISSION_PY, METH_NOARGS|METH_STATIC, ""}, + {"CHAIN_TYPE_TX", (PyCFunction)CHAIN_TYPE_TX_PY, METH_NOARGS|METH_STATIC, ""}, + {"CHAIN_TYPE_LAST", (PyCFunction)CHAIN_TYPE_LAST_PY, METH_NOARGS|METH_STATIC, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject dapChainTypeObject_dapChainTypeType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.Type", /* tp_name */ + sizeof(PyChainTypeObject), /* 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 */ + "Chain type objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapChainTypeMethods, /* 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 + +#endif //_LIBDAP_CHAIN_TYPE_PYTHON_ diff --git a/cellframe-sdk-python/libdap-chain-python/include/wrapping_dap_chain_cell.h b/cellframe-sdk-python/libdap-chain-python/include/wrapping_dap_chain_cell.h new file mode 100644 index 0000000000000000000000000000000000000000..f25d82973055a3a12c537d5a76a1bf627ab58ca1 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-python/include/wrapping_dap_chain_cell.h @@ -0,0 +1,175 @@ +#ifndef _WRAPPING_DAP_CHAIN_CELL_ +#define _WRAPPING_DAP_CHAIN_CELL_ +#include "Python.h" +#include "dap_chain_cell.h" +#include "libdap-chain-python.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int init(void); + +/* DAP chain cell */ +typedef struct PyDapChainCell{ + PyObject_HEAD + dap_chain_cell_t *cell; +}PyDapChainCellObject; + +void DapChainCellObject_delete(PyDapChainCellObject* object); +PyObject *DapChainCellObject_create(PyTypeObject *type_object, PyObject *args, PyObject *kwds); + +PyObject *dap_chain_cell_load_py(PyObject *self, PyObject *args); +PyObject *dap_chain_cell_file_update_py(PyObject *self, PyObject *args); +PyObject *dap_chain_cell_file_append_py(PyObject *self, PyObject *args); + +static PyMethodDef PyDapChainCellObjectMethods[] ={ + {"load", dap_chain_cell_load_py, METH_VARARGS | METH_STATIC, ""}, + {"update", dap_chain_cell_file_update_py, METH_VARARGS, ""}, + {"append", dap_chain_cell_file_append_py, METH_VARARGS, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapChainCell_DapChainCellObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.Cell", /* tp_name */ + sizeof(PyDapChainCellObject), /* 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 */ + "Chain cell object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + PyDapChainCellObjectMethods, /* 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 */ +}; + +/* ------------------------------------------- */ + +typedef struct PyDapChainCellDeclReq{ + PyObject_HEAD + dap_chain_cell_decl_req_t *decl_req; +}PyDapChainCellDeclReqObject; + +static PyTypeObject DapChainCellDeclReq_DapChainCellDeclReqObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.DapChainCellDeclReq", /* tp_name */ + sizeof(PyDapChainCellDeclReqObject), /* 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 */ + "Chain cell decl req object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* 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 */ +}; + +typedef struct PyDapChainCellDecl{ + PyObject_HEAD + dap_chain_cell_decl_t* decl; +}PyDapChainDeclObject; + +static PyTypeObject DapChainDecl_DapChainDeclObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.DapChainCellDecl", /* tp_name */ + sizeof(PyDapChainDeclObject), /* 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 */ + "Chain cell decl object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* 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 + +#endif //_WRAPPING_DAP_CHAIN_CELL_ diff --git a/cellframe-sdk-python/libdap-chain-python/include/wrapping_dap_chain_cs.h b/cellframe-sdk-python/libdap-chain-python/include/wrapping_dap_chain_cs.h new file mode 100644 index 0000000000000000000000000000000000000000..2ddf02f33d16a31b6829c21a04fd49c3bb9979bb --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-python/include/wrapping_dap_chain_cs.h @@ -0,0 +1,85 @@ +#ifndef _WRAPPING_DAP_CHAIN_CS_ +#define _WRAPPING_DAP_CHAIN_CS_ + +#include "Python.h" +#include "dap_chain_cs.h" +#include "libdap-chain-python.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PyDapChainCs{ + PyObject_HEAD + dap_chain_cs_t *cs; + dap_chain_callback_new_cfg_t callback_new_cfg; +}PyDapChainCsObject; +static PyObject *binded_object_callback_new_cfg = NULL; + +PyObject *DapChainCSObject_new(PyTypeObject *type_object, PyObject *args, PyObject *kwds); + +int dap_chain_cs_init_py(void); +void dap_chain_cs_deinit_py(void); + +PyObject *dap_chain_cs_add_py (PyObject *self, PyObject *args); +PyObject *dap_chain_cs_create_py(PyObject *self, PyObject *args); + +PyObject *dap_chain_class_add_py (PyObject *self, PyObject *args); +PyObject *dap_chain_class_create_py(PyObject *self, PyObject *args); + +static PyMethodDef DapChainCSMethods[] = { + {"csAdd", (PyCFunction)dap_chain_cs_add_py, METH_VARARGS, ""}, + {"csCreate", (PyCFunction)dap_chain_cs_create_py, METH_VARARGS, ""}, + {"classAdd", (PyCFunction)dap_chain_class_add_py, METH_VARARGS, ""}, + {"classCreate", (PyCFunction)dap_chain_class_create_py, METH_VARARGS, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapChainCsObject_DapChainCsObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.CS", /* tp_name */ + sizeof(PyDapChainCsObject), /* 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 */ + "Chain cs object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapChainCSMethods, /* 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 */ + DapChainCSObject_new, /* tp_new */ +}; + + +#ifdef __cplusplus +} +#endif + +#endif //_WRAPPING_DAP_CHAIN_CS_ diff --git a/cellframe-sdk-python/libdap-chain-python/include/wrapping_dap_chain_ledger.h b/cellframe-sdk-python/libdap-chain-python/include/wrapping_dap_chain_ledger.h new file mode 100644 index 0000000000000000000000000000000000000000..160ea180a80c9a4d4a5a45db229f127f61b31e57 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-python/include/wrapping_dap_chain_ledger.h @@ -0,0 +1,130 @@ +#ifndef _WRAPPING_DAP_CHAIN_LEDGER_ +#define _WRAPPING_DAP_CHAIN_LEDGER_ + +#include "Python.h" +#include "dap_chain_ledger.h" +#include "wrapping_dap_chain_common.h" +#include "wrapping_dap_chain_datum_tx.h" +#include "wrapping_dap_chain_datum_token.h" +#include "wrapping_dap_hash.h" +#include "libdap-python.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PyDapChainLedger{ + PyObject_HEAD + dap_ledger_t *ledger; +}PyDapChainLedgerObject; + +//construct +PyObject *DapChainLedgerObject_create(PyTypeObject *type_object, PyObject *args, PyObject *kwds); +//destructor +void DapChainLedgerObject_free(PyDapChainLedgerObject* object); + +PyObject *dap_chain_ledger_set_local_cell_id_py(PyObject *self, PyObject *args); +PyObject *dap_chain_node_datum_tx_calc_hash_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_tx_add_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_token_add_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_token_emission_add_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_token_emission_find_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_tx_get_token_ticker_by_hash_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_addr_get_token_ticker_all_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_addr_get_token_ticker_all_fast_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_tx_cache_check_py(PyObject *self, PyObject *args); +PyObject *dap_chain_node_datum_tx_cache_check_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_tx_remove_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_purge_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_count_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_count_from_to_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_tx_hash_is_used_out_item_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_calc_balance_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_calc_balance_full_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_tx_find_by_hash_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_tx_find_by_addr_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_tx_find_by_pkey_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_tx_cache_find_out_cond_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_tx_cache_get_out_cond_value_py(PyObject *self, PyObject *args); + +static PyMethodDef DapChainLedgerMethods[] = { + {"setLocalCellId", (PyCFunction)dap_chain_ledger_set_local_cell_id_py, METH_VARARGS, ""}, + {"nodeDatumTxCalcHash", (PyCFunction)dap_chain_node_datum_tx_calc_hash_py, METH_VARARGS, ""}, + {"txAdd", (PyCFunction)dap_chain_ledger_tx_add_py, METH_VARARGS, ""}, + {"tokenAdd", (PyCFunction)dap_chain_ledger_token_add_py, METH_VARARGS, ""}, + {"tokenEmissionAdd", (PyCFunction)dap_chain_ledger_token_emission_add_py, METH_VARARGS, ""}, + {"tokenEmissionFind", (PyCFunction)dap_chain_ledger_token_emission_find_py, METH_VARARGS, ""}, + {"txGetTokenTickerByHash", (PyCFunction)dap_chain_ledger_tx_get_token_ticker_by_hash_py, METH_VARARGS, ""}, + {"addrGetTokenTickerAll", (PyCFunction)dap_chain_ledger_addr_get_token_ticker_all_py, METH_VARARGS, ""}, + {"addrGetTokenTickerAllFast", (PyCFunction)dap_chain_ledger_addr_get_token_ticker_all_fast_py, METH_VARARGS, ""}, + {"txCacheCheck", (PyCFunction)dap_chain_ledger_tx_cache_check_py, METH_VARARGS, ""}, + {"datumTxCacheCheck", (PyCFunction)dap_chain_node_datum_tx_cache_check_py, METH_VARARGS, ""}, + {"txRemove", (PyCFunction)dap_chain_ledger_tx_remove_py, METH_VARARGS, ""}, + {"purge", (PyCFunction)dap_chain_ledger_purge_py, METH_VARARGS, ""}, + {"count", (PyCFunction)dap_chain_ledger_count_py, METH_VARARGS, ""}, + {"countFromTo", (PyCFunction)dap_chain_ledger_count_from_to_py, METH_VARARGS, ""}, + {"txHashIsUsedOutItem", (PyCFunction)dap_chain_ledger_tx_hash_is_used_out_item_py, METH_VARARGS, ""}, + {"calcBalance", (PyCFunction)dap_chain_ledger_calc_balance_py, METH_VARARGS, ""}, + {"calcBalanceFull", (PyCFunction)dap_chain_ledger_calc_balance_full_py, METH_VARARGS, ""}, + {"txFindByHash", (PyCFunction)dap_chain_ledger_tx_find_by_hash_py, METH_VARARGS, ""}, + {"txFindByAddr", (PyCFunction)dap_chain_ledger_tx_find_by_addr_py, METH_VARARGS, ""}, + {"txFindByPkey", (PyCFunction)dap_chain_ledger_tx_find_by_pkey_py, METH_VARARGS, ""}, + {"txCacheFindOutCond", (PyCFunction)dap_chain_ledger_tx_cache_find_out_cond_py, METH_VARARGS, ""}, + {"txCacheGetOutCondValue", (PyCFunction)dap_chain_ledger_tx_cache_get_out_cond_value_py, METH_VARARGS, ""}, + + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapChainLedger_DapChainLedgerType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.Ledger", /* tp_name */ + sizeof(PyDapChainLedgerObject), /* 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 */ + "Chain ledger objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapChainLedgerMethods, /* 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 */ + +}; + +static char*** ListStringToArrayStringFormatChar(PyObject *list); +static size_t *ListIntToSizeT(PyObject *list); + + +#ifdef __cplusplus +} +#endif + +#endif //_WRAPPING_DAP_CHAIN_LEDGER_ diff --git a/cellframe-sdk-python/libdap-chain-python/src/libdap-chain-python.c b/cellframe-sdk-python/libdap-chain-python/src/libdap-chain-python.c new file mode 100644 index 0000000000000000000000000000000000000000..397740e9c1125f04cc550231143202ffd41612f4 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-python/src/libdap-chain-python.c @@ -0,0 +1,79 @@ +#include "libdap-chain-python.h" + +#define LOG_TAG "libdap-chain-python" + + +int init_chain_py(){ + return dap_chain_init(); +} + +void deinit_chain_py(){ + dap_chain_deinit(); +} + +PyObject *dap_chain_find_by_id_py(PyObject *self, PyObject *args){ + PyObject *obj_net_id; + PyObject *obj_chain_id; + if (!PyArg_ParseTuple(args, "O|O", &obj_net_id, &obj_chain_id)) + return NULL; + PyObject *new_obj = _PyObject_New(&dapChainObject_dapChainType); + ((PyDapChainObject*)new_obj)->chain_t = dap_chain_find_by_id(((PyDapChainNetIdObject*)obj_net_id)->net_id, + *(((PyDapChainIDObject*)obj_chain_id)->chain_id)); + return Py_BuildValue("O", &new_obj); +} + +//PyObject *dap_chain_load_from_cfg_py(PyObject *self, PyObject *args){ +//return NULL; +//} + +PyObject *dap_chain_has_file_store_py(PyObject *self, PyObject *args){ + bool res = dap_chain_has_file_store(((PyDapChainObject*)self)->chain_t); + if (res) + return Py_BuildValue("O", Py_True); + else + return Py_BuildValue("O", Py_False); +} + +PyObject *dap_chain_save_all_py(PyObject *self, PyObject *args){ + return PyLong_FromLong( dap_chain_save_all(((PyDapChainObject*)self)->chain_t) ); +} + +PyObject *dap_chain_load_all_py(PyObject *self, PyObject *args){ + return PyLong_FromLong(dap_chain_load_all(((PyDapChainObject*)self)->chain_t)); +} + +PyObject *dap_chain_load_from_cfg_py(PyObject *self, PyObject *args){ + PyObject *obj_ledger; + const char *chain_net_name; + PyObject *obj_net_id; + const char *cfg_name; + if (!PyArg_ParseTuple(args, "O|s|O|s", &obj_ledger, &chain_net_name, &obj_net_id, &cfg_name)) + return NULL; + PyObject *res_obj = _PyObject_New(&dapChainObject_dapChainType); + ((PyDapChainObject*)res_obj)->chain_t = dap_chain_load_from_cfg(((PyDapChainLedgerObject*)obj_ledger)->ledger, chain_net_name, ((PyDapChainNetIdObject*)obj_net_id)->net_id, cfg_name); + return Py_BuildValue("O", &res_obj); +} + +//PyObject *dap_chain_init_net_cfg_name_py(PyObject *self, PyObject *args){ +//return NULL; +//} + +//PyObject *dap_chain_close_py(PyObject *self, PyObject *args){ +// dap_chain_close(((PyDapChainObject*)self)->chain_t); +// return PyLong_FromLong(0); +//} + +//PyObject *dap_chain_info_dump_log_py(PyObject *self, PyObject *args){ +//return NULL; +//} + + +PyObject *PyDapChainObject_new(PyTypeObject *type_object, PyObject *args, PyObject *kwds){ + PyDapChainObject *obj = (PyDapChainObject*)PyType_GenericNew(type_object, args, kwds); + return (PyObject *)obj; +} + +void PyDapChainObject_dealloc(PyDapChainObject* chain){ + dap_chain_delete(chain->chain_t); + Py_TYPE(chain)->tp_free((PyObject*)chain); +} diff --git a/cellframe-sdk-python/libdap-chain-python/src/libdap_chain_type_python.c b/cellframe-sdk-python/libdap-chain-python/src/libdap_chain_type_python.c new file mode 100644 index 0000000000000000000000000000000000000000..2ce46a8ecd38485dbe4c82820c771641d0ff382a --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-python/src/libdap_chain_type_python.c @@ -0,0 +1,27 @@ +#include "libdap_chain_type_python.h" + +PyObject* CHAIN_TYPE_FIRST_PY(){ + PyObject *dap_chain_obj = _PyObject_New(&dapChainTypeObject_dapChainTypeType); + ((PyChainTypeObject*)dap_chain_obj)->chain_type = CHAIN_TYPE_FIRST; + return Py_BuildValue("O", &dap_chain_obj); +} +PyObject* CHAIN_TYPE_TOKEN_PY(){ + PyObject *dap_chain_obj = _PyObject_New(&dapChainTypeObject_dapChainTypeType); + ((PyChainTypeObject*)dap_chain_obj)->chain_type = CHAIN_TYPE_TOKEN; + return Py_BuildValue("O", &dap_chain_obj); +} +PyObject* CHAIN_TYPE_EMISSION_PY(){ + PyObject *dap_chain_obj = _PyObject_New(&dapChainTypeObject_dapChainTypeType); + ((PyChainTypeObject*)dap_chain_obj)->chain_type = CHAIN_TYPE_EMISSION; + return Py_BuildValue("O", &dap_chain_obj); +} +PyObject* CHAIN_TYPE_TX_PY(){ + PyObject *dap_chain_obj = _PyObject_New(&dapChainTypeObject_dapChainTypeType); + ((PyChainTypeObject*)dap_chain_obj)->chain_type = CHAIN_TYPE_TX; + return Py_BuildValue("O", &dap_chain_obj); +} +PyObject* CHAIN_TYPE_LAST_PY(){ + PyObject *dap_chain_obj = _PyObject_New(&dapChainTypeObject_dapChainTypeType); + ((PyChainTypeObject*)dap_chain_obj)->chain_type = CHAIN_TYPE_LAST; + return Py_BuildValue("O", &dap_chain_obj); +} diff --git a/cellframe-sdk-python/libdap-chain-python/src/wrapping_dap_chain_cell.c b/cellframe-sdk-python/libdap-chain-python/src/wrapping_dap_chain_cell.c new file mode 100644 index 0000000000000000000000000000000000000000..6d1369b415a738df0ca915262c0c771e88545db7 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-python/src/wrapping_dap_chain_cell.c @@ -0,0 +1,33 @@ +#include "wrapping_dap_chain_cell.h" + +void DapChainCellObject_delete(PyDapChainCellObject* object){ + dap_chain_cell_delete(object->cell); + Py_TYPE(object)->tp_free((PyObject*)object); +} +PyObject *DapChainCellObject_create(PyTypeObject *type_object, PyObject *args, PyObject *kwds){ + PyDapChainCellObject *obj = (PyDapChainCellObject*)PyType_GenericNew(type_object, args, kwds); + obj->cell = dap_chain_cell_create(); + return (PyObject *)obj; +} + +PyObject *dap_chain_cell_load_py(PyObject *self, PyObject *args){ + PyObject *obj_chain; + const char *cell_file_path; + if (!PyArg_ParseTuple(args, "O|s", &obj_chain, &cell_file_path)) + return NULL; + int res = dap_chain_cell_load(((PyDapChainObject*)obj_chain)->chain_t, cell_file_path); + return PyLong_FromLong(res); +} +PyObject *dap_chain_cell_file_update_py(PyObject *self, PyObject *args){ + int res = dap_chain_cell_file_update(((PyDapChainCellObject*)self)->cell); + return PyLong_FromLong(res); +} +PyObject *dap_chain_cell_file_append_py(PyObject *self, PyObject *args){ + PyObject *atom_bytes; + size_t atom_size; + if (!PyArg_ParseTuple(args, "S|n", &atom_bytes, &atom_size)) + return NULL; + void *atom = PyBytes_AsString(atom_bytes); + int res = dap_chain_cell_file_append(((PyDapChainCellObject*)self)->cell, atom, atom_size); + return PyLong_FromLong(res); +} diff --git a/cellframe-sdk-python/libdap-chain-python/src/wrapping_dap_chain_cs.c b/cellframe-sdk-python/libdap-chain-python/src/wrapping_dap_chain_cs.c new file mode 100644 index 0000000000000000000000000000000000000000..12aa1316240ce72d85ffea9cd25a457d9aaefdbf --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-python/src/wrapping_dap_chain_cs.c @@ -0,0 +1,85 @@ +#include "wrapping_dap_chain_cs.h" + +/* Callback created */ +static int wrapping_dap_chain_callback_new_cfg(dap_chain_t* chain, dap_config_t* cfg) +{ + PyObject *arglist; + PyObject *result; + PyObject *obj_chain= _PyObject_New(&dapChainObject_dapChainType); + ((PyDapChainObject*)obj_chain)->chain_t = chain; + arglist = Py_BuildValue("O", obj_chain); + result = PyObject_CallObject(binded_object_callback_new_cfg, arglist); + Py_DECREF(arglist); + int r = -1; + if (PyLong_Check(result)){ + r = (int)PyLong_AsLong(result); + } + Py_DECREF(result); + return r; +} +/*--------------------------------*/ +int dap_chain_cs_init_py(void){ + return dap_chain_cs_init(); +} +void dap_chain_cs_deinit_py(void){ + dap_chain_cs_deinit(); +} + +PyObject *DapChainCSObject_new(PyTypeObject *type_object, PyObject *args, PyObject *kwds) +{ + PyDapChainCsObject *obj = (PyDapChainCsObject*)PyType_GenericNew(type_object, args, kwds); + obj->callback_new_cfg = wrapping_dap_chain_callback_new_cfg; + return (PyObject *)obj; +} + +PyObject *dap_chain_cs_add_py (PyObject *self, PyObject *args){ + const char* cs_str; + PyObject *obj_callback_init; + if (!PyArg_ParseTuple(args, "s|O:set_callback", &cs_str, &obj_callback_init)){ + return NULL; + } else { + if (!PyCallable_Check(obj_callback_init)) + { + PyErr_SetString(PyExc_TypeError, "paramentr must be callable"); + return NULL; + } + } + Py_XINCREF(obj_callback_init); + Py_XDECREF(binded_object_callback_new_cfg); + binded_object_callback_new_cfg = obj_callback_init; + dap_chain_cs_add(cs_str, ((PyDapChainCsObject*)self)->callback_new_cfg); + return PyLong_FromLong(0); +} +PyObject *dap_chain_cs_create_py(PyObject *self, PyObject *args){ + PyObject *obj_chain; + if (!PyArg_ParseTuple(args, "O", &obj_chain)) + return NULL; + int res = dap_chain_cs_create(((PyDapChainObject*)obj_chain)->chain_t, g_config); + return PyLong_FromLong(res); +} + +PyObject *dap_chain_class_add_py (PyObject *self, PyObject *args){ + const char* cs_str; + PyObject *obj_callback_init; + if (!PyArg_ParseTuple(args, "s|O:set_callback", &cs_str, &obj_callback_init)){ + return NULL; + } else { + if (!PyCallable_Check(obj_callback_init)) + { + PyErr_SetString(PyExc_TypeError, "paramentr must be callable"); + return NULL; + } + } + Py_XINCREF(obj_callback_init); + Py_XDECREF(binded_object_callback_new_cfg); + binded_object_callback_new_cfg = obj_callback_init; + dap_chain_class_add(cs_str, ((PyDapChainCsObject*)self)->callback_new_cfg); + return PyLong_FromLong(0); +} +PyObject *dap_chain_class_create_py(PyObject *self, PyObject *args){ + PyObject *obj_chain; + if (!PyArg_ParseTuple(args, "O", &obj_chain)) + return NULL; + int res = dap_chain_class_create(((PyDapChainObject*)obj_chain)->chain_t, g_config); + return PyLong_FromLong(res); +} diff --git a/cellframe-sdk-python/libdap-chain-python/src/wrapping_dap_chain_ledger.c b/cellframe-sdk-python/libdap-chain-python/src/wrapping_dap_chain_ledger.c new file mode 100644 index 0000000000000000000000000000000000000000..7ae3dc6c8891e82d3037cae26dc17ae84677958a --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-python/src/wrapping_dap_chain_ledger.c @@ -0,0 +1,274 @@ +#include "wrapping_dap_chain_ledger.h" + +PyObject *DapChainLedgerObject_create(PyTypeObject *type_object, PyObject *args, PyObject *kwds){ + uint16_t check_flag; + if (!PyArg_ParseTuple(args, "H", &check_flag)) + return NULL; + PyDapChainLedgerObject *obj = (PyDapChainLedgerObject *)PyType_GenericNew(type_object, args, kwds); + obj->ledger = dap_chain_ledger_create(check_flag); + return (PyObject *)obj; +} +void DapChainLedgerObject_free(PyDapChainLedgerObject* object){ + dap_chain_ledger_handle_free(object->ledger); + Py_TYPE(object)->tp_free(object); +} + +PyObject *dap_chain_ledger_set_local_cell_id_py(PyObject *self, PyObject *args){ + PyObject *obj_local_cell_id; + if (!PyArg_ParseTuple(args, "O", &obj_local_cell_id)) + return NULL; + dap_chain_ledger_set_local_cell_id(((PyDapChainLedgerObject*)self)->ledger, + ((PyDapChainCellIDObject*)obj_local_cell_id)->cell_id); + return PyLong_FromLong(0); +} +PyObject *dap_chain_node_datum_tx_calc_hash_py(PyObject *self, PyObject *args){ + (void)self; + PyObject *obj_tx; + if (!PyArg_ParseTuple(args, "O", &obj_tx)) + return NULL; + PyObject *obj_h_fast = _PyObject_New(&DapHashFastObject_DapHashFastObjectType); + ((PyDapHashFastObject*)obj_h_fast)->hash_fast = dap_chain_node_datum_tx_calc_hash(((PyDapChainDatumTxObject*)obj_tx)->datum_tx); + return Py_BuildValue("O", obj_h_fast); + +} +PyObject *dap_chain_ledger_tx_add_py(PyObject *self, PyObject *args){ + PyObject *obj_datum_tx; + if (!PyArg_ParseTuple(args, "O", &obj_datum_tx)) + return NULL; + int res = dap_chain_ledger_tx_add(((PyDapChainLedgerObject*)self)->ledger, ((PyDapChainDatumTxObject*)obj_datum_tx)->datum_tx); + return PyLong_FromLong(res); +} +PyObject *dap_chain_ledger_token_add_py(PyObject *self, PyObject *args) +{ + PyObject *token; + size_t token_size; + if (!PyArg_ParseTuple(args, "O|n", &token, &token_size)) + return NULL; + int res = dap_chain_ledger_token_add(((PyDapChainLedgerObject*)self)->ledger, + ((PyDapChainDatumTokenObject*)token)->token, token_size); + return PyLong_FromLong(res); +} +PyObject *dap_chain_ledger_token_emission_add_py(PyObject *self, PyObject *args){ + PyObject *token_emission; + size_t token_emissiom_size; + if (!PyArg_ParseTuple(args, "O|n", &token_emission, &token_emissiom_size)) + return NULL; + int res = dap_chain_ledger_token_emission_add(((PyDapChainLedgerObject*)self)->ledger, ((PyDapChainDatumTokenEmissionObject*)token_emission)->token_emission, token_emissiom_size); + return PyLong_FromLong(res); +} +PyObject *dap_chain_ledger_token_emission_find_py(PyObject *self, PyObject *args){ + PyObject *h_fast; + const char *token_ticker; + if (!PyArg_ParseTuple(args, "s|O", &token_ticker, &h_fast)) + return NULL; + PyObject *token_emission = _PyObject_New(&DapChainDatumTokenEmission_DapChainDatumTokenEmissionObjectType); + ((PyDapChainDatumTokenEmissionObject*)token_emission)->token_emission = dap_chain_ledger_token_emission_find( + ((PyDapChainLedgerObject*)self)->ledger, token_ticker, ((PyDapHashFastObject*)h_fast)->hash_fast); + return Py_BuildValue("O", &token_emission); +} +PyObject *dap_chain_ledger_tx_get_token_ticker_by_hash_py(PyObject *self, PyObject *args){ + //TODO + //Missing implementation of dap_chain_ledger_tx_get_token_ticker_by_hash function in dap_chain_ledger + return NULL; +// PyObject *obj_tx_hash; +// if (!PyArg_ParseTuple(args, "O", &obj_tx_hash)) +// return NULL; +// const char *res = dap_chain_ledger_tx_get_token_ticker_by_hash(((PyDapChainHashFastObject*)obj_tx_hash)->hash_fast); +// return Py_BuildValue("s", res); +} +PyObject *dap_chain_ledger_addr_get_token_ticker_all_py(PyObject *self, PyObject *args){ + PyObject *obj_addr; + PyObject *obj_tickers; + PyObject *obj_tickers_size; + if (!PyArg_ParseTuple(args, "O|O|O", &obj_addr, &obj_tickers, &obj_tickers_size)) + return NULL; + char ***tickers = ListStringToArrayStringFormatChar(obj_tickers); + size_t *tickers_size = ListIntToSizeT(obj_tickers_size); + dap_chain_ledger_addr_get_token_ticker_all(((PyDapChainLedgerObject*)self)->ledger, ((PyDapChainAddrObject*)obj_addr)->addr, tickers, tickers_size); + return PyLong_FromLong(0); +} +PyObject *dap_chain_ledger_addr_get_token_ticker_all_fast_py(PyObject *self, PyObject *args){ + PyObject *obj_addr; + PyObject *obj_tickers; + PyObject *obj_tickers_size; + if (!PyArg_ParseTuple(args, "O|O|O", &obj_addr, &obj_tickers, &obj_tickers_size)) + return NULL; + char ***tickers = ListStringToArrayStringFormatChar(obj_tickers); + size_t *tickers_size = ListIntToSizeT(obj_tickers_size); + dap_chain_ledger_addr_get_token_ticker_all_fast(((PyDapChainLedgerObject*)self)->ledger, ((PyDapChainAddrObject*)obj_addr)->addr, tickers, tickers_size); + return PyLong_FromLong(0); +} +PyObject *dap_chain_ledger_tx_cache_check_py(PyObject *self, PyObject *args){ + PyObject *obj_datum_tx; + PyObject *list_bound_items; + PyObject *list_tx_out; + if (!PyArg_ParseTuple(args, "O|O|O", &obj_datum_tx, &list_bound_items, &list_tx_out)) + return NULL; + Py_ssize_t size_list_bound_item = PyList_Size(list_bound_items); + dap_list_t **bound_items = calloc(sizeof(dap_list_t**), (size_t)size_list_bound_item); + for (Py_ssize_t i = 0; i < size_list_bound_item;i++){ + PyObject *obj = PyList_GetItem(list_bound_items, i); + dap_list_t *l = pyListToDapList(obj); + bound_items[i] = l; + } + Py_ssize_t size_tx_out = PyList_Size(list_tx_out); + dap_list_t **tx_out = calloc(sizeof(dap_list_t**), (size_t)size_tx_out); + for (Py_ssize_t i = 0; i < size_tx_out;i++){ + PyObject *obj = PyList_GetItem(list_bound_items, i); + dap_list_t *l = pyListToDapList(obj); + tx_out[i] = l; + } + int res = dap_chain_ledger_tx_cache_check(((PyDapChainLedgerObject*)self)->ledger, ((PyDapChainDatumTxObject*)obj_datum_tx)->datum_tx, bound_items, tx_out); + return PyLong_FromLong(res); +} +PyObject *dap_chain_node_datum_tx_cache_check_py(PyObject *self, PyObject *args){ + //TODO + //Missing implementation of dap_chain_node_datum_tx_cache_check function in dap_chain_ledger + return NULL; +// PyObject *obj_datum_tx; +// PyObject *list_bound_items; +// if (!PyArg_ParseTuple(args, "O|O", &obj_datum_tx, &list_bound_items)) +// return NULL; +// Py_ssize_t size = PyList_Size(list_bound_items); +// dap_list_t **bound_items = calloc(sizeof (dap_list_t**), (size_t)size); +// for (int i = 0; i < size ; i++){ +// PyObject *obj = PyList_GetItem(list_bound_items, i); +// dap_list_t *l = pyListToDapList(obj); +// bound_items[i] = l; +// } +// int res = dap_chain_node_datum_tx_cache_check(((PyDapChainDatumTxObject*)obj_datum_tx)->datum_tx, bound_items); +// return PyLong_FromLong(res); +} +PyObject *dap_chain_ledger_tx_remove_py(PyObject *self, PyObject *args){ + PyObject *obj_h_fast; + if (!PyArg_ParseTuple(args, "O", &obj_h_fast)) + return NULL; + int res = dap_chain_ledger_tx_remove(((PyDapChainLedgerObject*)self)->ledger, ((PyDapHashFastObject*)obj_h_fast)->hash_fast); + return PyLong_FromLong(res); +} +PyObject *dap_chain_ledger_purge_py(PyObject *self, PyObject *args){ + dap_chain_ledger_purge(((PyDapChainLedgerObject*)self)->ledger); + return PyLong_FromLong(0); +} +PyObject *dap_chain_ledger_count_py(PyObject *self, PyObject *args){ + long long res = (long long)dap_chain_ledger_count(((PyDapChainLedgerObject*)self)->ledger); + return PyLong_FromLongLong(res); +} +PyObject *dap_chain_ledger_count_from_to_py(PyObject *self, PyObject *args){ + long ts_from, ts_to; + if (!PyArg_ParseTuple(args, "l|l", &ts_from, &ts_to)) + return NULL; + uint64_t res = dap_chain_ledger_count_from_to(((PyDapChainLedgerObject*)self)->ledger, (time_t)ts_from, (time_t)ts_to); + return PyLong_FromUnsignedLongLong(res); +} +PyObject *dap_chain_ledger_tx_hash_is_used_out_item_py(PyObject *self, PyObject *args){ + PyObject *obj_h_fast; + int idx_out; + if (!PyArg_ParseTuple(args, "O|i", &obj_h_fast, &idx_out)) + return NULL; + bool res = dap_chain_ledger_tx_hash_is_used_out_item(((PyDapChainLedgerObject*)self)->ledger, ((PyDapHashFastObject*)obj_h_fast)->hash_fast, idx_out); + if (res) + return Py_BuildValue("O", Py_True); + else + return Py_BuildValue("O", Py_False); +} +PyObject *dap_chain_ledger_calc_balance_py(PyObject *self, PyObject *args){ + PyObject *addr; + const char *token_ticker; + if (!PyArg_ParseTuple(args, "O|s", &addr, &token_ticker)) + return NULL; + uint64_t res = dap_chain_ledger_calc_balance(((PyDapChainLedgerObject*)self)->ledger, ((PyDapChainAddrObject*)addr)->addr, token_ticker); + return Py_BuildValue("k", res); +} +PyObject *dap_chain_ledger_calc_balance_full_py(PyObject *self, PyObject *args){ + PyObject *addr; + const char *token_ticker; + if (!PyArg_ParseTuple(args, "O|s", &addr, &token_ticker)) + return NULL; + uint64_t res = dap_chain_ledger_calc_balance_full(((PyDapChainLedgerObject*)self)->ledger, ((PyDapChainAddrObject*)addr)->addr, token_ticker); + return Py_BuildValue("k", res); +} +PyObject *dap_chain_ledger_tx_find_by_hash_py(PyObject *self, PyObject *args){ + PyObject *h_fast; + if (!PyArg_ParseTuple(args, "O", &h_fast)) + return NULL; + PyObject *res = _PyObject_New(&DapChainDatumTx_DapChainDatumTxObjectType); + ((PyDapChainDatumTxObject*)res)->datum_tx = dap_chain_ledger_tx_find_by_hash(((PyDapChainLedgerObject*)self)->ledger, ((PyDapHashFastObject*)h_fast)->hash_fast); + return Py_BuildValue("O", res); +} +PyObject *dap_chain_ledger_tx_find_by_addr_py(PyObject *self, PyObject *args){ + const char *token; + PyObject *addr; + PyObject *first_hash; + if (!PyArg_ParseTuple(args, "s|O|O", &token, &addr, &first_hash)) + return NULL; + PyObject *res = _PyObject_New(&DapChainDatumTx_DapChainDatumTxObjectType); + ((PyDapChainDatumTxObject*)res)->datum_tx = dap_chain_ledger_tx_find_by_addr(((PyDapChainLedgerObject*)self)->ledger, token, ((PyDapChainAddrObject*)addr)->addr, ((PyDapHashFastObject*)first_hash)->hash_fast); + return Py_BuildValue("O", res); +} +PyObject *dap_chain_ledger_tx_find_by_pkey_py(PyObject *self, PyObject *args){ + char *p_key; + size_t p_key_size; + PyObject *obj_first_hash; + if (!PyArg_ParseTuple(args, "s|n|O", &p_key, &p_key_size, &obj_first_hash)) + return NULL; + PyObject *res = _PyObject_New(&DapChainDatumTx_DapChainDatumTxObjectType); + ((PyDapChainDatumTxObject*)res)->datum_tx = (dap_chain_datum_tx_t*)dap_chain_ledger_tx_find_by_pkey( + ((PyDapChainLedgerObject*)self)->ledger, + p_key, + p_key_size, + ((PyDapHashFastObject*)obj_first_hash)->hash_fast); + return Py_BuildValue("O", res); +} +PyObject *dap_chain_ledger_tx_cache_find_out_cond_py(PyObject *self, PyObject *args){ + PyObject *obj_addr; + PyObject *obj_first_hash; + if (!PyArg_ParseTuple(args, "O|O", &obj_addr, &obj_first_hash)) + return NULL; + PyObject *res = _PyObject_New(&DapChainDatumTx_DapChainDatumTxObjectType); + ((PyDapChainDatumTxObject*)res)->datum_tx = (dap_chain_datum_tx_t*)dap_chain_ledger_tx_cache_find_out_cond( + ((PyDapChainLedgerObject*)self)->ledger, + ((PyDapChainAddrObject*)obj_addr)->addr, + ((PyDapHashFastObject*)obj_first_hash)->hash_fast); + return Py_BuildValue("O", res); +} +PyObject *dap_chain_ledger_tx_cache_get_out_cond_value_py(PyObject *self, PyObject *args){ + PyObject *obj_addr; + if (!PyArg_ParseTuple(args, "O", &obj_addr)) + return NULL; + dap_chain_tx_out_cond_t **out_conds = NULL; + uint64_t res = dap_chain_ledger_tx_cache_get_out_cond_value(((PyDapChainLedgerObject*)self)->ledger, + ((PyDapChainAddrObject*)obj_addr)->addr, + out_conds); + PyObject *obj_out_conds = _PyObject_New(&DapChainTxOutCond_DapChainTxOutCondObjectType); + ((PyDapChainTxOutCondObject*)obj_out_conds)->out_cond = *out_conds; + PyObject *obj_res = PyLong_FromUnsignedLongLong(res); + return Py_BuildValue("OO", obj_res, obj_out_conds); +} + +static char*** ListStringToArrayStringFormatChar(PyObject *list){ + Py_ssize_t size = PyList_Size(list); + char ***data = calloc(sizeof(char**), (size_t)size); + for (Py_ssize_t i = 0; i < size; i++){ + PyObject *obj_two = PyList_GetItem(list,i); + Py_ssize_t size_seentenses = PyList_Size(obj_two); + char **sentences = calloc(sizeof(char**), (size_t)size_seentenses); + for (int j=0; j < size_seentenses;j++){ + PyObject *obj_byte = PyList_GetItem(obj_two, j); + char *word = PyBytes_AsString(obj_byte); + sentences[j] = word; + } + data[i] = sentences; + } + return data; +} + +static size_t *ListIntToSizeT(PyObject *list){ + Py_ssize_t size = PyList_Size(list); + size_t *res_size_t = calloc(sizeof(size_t), (size_t)size); + for (Py_ssize_t i=0; i<size;i++){ + PyObject *obj = PyList_GetItem(list, i); + res_size_t[i] = (size_t)PyLong_AsSsize_t(obj); + } + return res_size_t; +} diff --git a/cellframe-sdk-python/libdap-chain-wallet-python b/cellframe-sdk-python/libdap-chain-wallet-python deleted file mode 160000 index 591cf4502be97766a9ac800bb66de761890c1c9f..0000000000000000000000000000000000000000 --- a/cellframe-sdk-python/libdap-chain-wallet-python +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 591cf4502be97766a9ac800bb66de761890c1c9f diff --git a/cellframe-sdk-python/libdap-chain-wallet-python/CMakeLists.txt b/cellframe-sdk-python/libdap-chain-wallet-python/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5f27c0e7d0eea587e87e5b3b5959debdcd9eaeb7 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-wallet-python/CMakeLists.txt @@ -0,0 +1,30 @@ +project(dap_chain_wallet_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") +add_definitions("-DDAP_LOG_MT") + +file(GLOB CHAIN_WALLET_PYTHON_SRCS src/*.c) +file(GLOB CHAIN_WALLET_PYTHON_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 ${CHAIN_WALLET_PYTHON_SRCS} ${CHAIN_WALLET_PYTHON_HEADERS}) + +target_link_libraries(${PROJECT_NAME}) + +target_link_libraries(${PROJECT_NAME} dap_core + dap_crypto + dap_crypto_python_module + dap_chain dap_chain_crypto + dap_chain_python_module + dap_chain_net + dap_chain_wallet ) + +target_include_directories(${PROJECT_NAME} PUBLIC include/ ) + diff --git a/cellframe-sdk-python/libdap-chain-wallet-python/README.md b/cellframe-sdk-python/libdap-chain-wallet-python/README.md new file mode 100644 index 0000000000000000000000000000000000000000..98bd3b661178416c9ea418cdb1e6dfa8e4d5e116 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-wallet-python/README.md @@ -0,0 +1,2 @@ +# libdap-chain-wallet-python + diff --git a/cellframe-sdk-python/libdap-chain-wallet-python/include/dap_chain_wallet_python.h b/cellframe-sdk-python/libdap-chain-wallet-python/include/dap_chain_wallet_python.h new file mode 100644 index 0000000000000000000000000000000000000000..d0b43398dbd38190121524277b5343c9b58f3a57 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-wallet-python/include/dap_chain_wallet_python.h @@ -0,0 +1,117 @@ +#ifndef _DAP_CHAIN_WALLET_PYTHON_ +#define _DAP_CHAIN_WALLET_PYTHON_ + +#include <Python.h> +#include "dap_common.h" +#include "dap_chain_wallet.h" +#include "wrapping_dap_chain_common.h" +#include "libdap_crypto_key_python.h" +#include "wrapping_dap_sign.h" +#include "wrapping_dap_pkey.h" +#include "wrapping_cert.h" + +#ifdef __cplusplus +extern "C"{ +#endif + + +typedef struct PyDapChainWallet{ + PyObject_HEAD + dap_chain_wallet_t *wallet; +}PyDapChainWalletObject; + +int dap_chain_wallet_init_py(void); +void dap_chain_wallet_deinit_py(void); + +PyObject *dap_chain_wallet_get_path_py(PyObject *self, PyObject *argv); + +PyObject *dap_chain_wallet_create_with_seed_py(PyObject *self, PyObject *argv); +PyObject *dap_chain_wallet_create_py(PyTypeObject *type, PyObject *argv, PyObject *kwds); +PyObject *dap_chain_wallet_open_file_py(PyObject *self, PyObject *argv); +PyObject *dap_chain_wallet_open_py(PyObject *self, PyObject *argv); +PyObject *dap_chain_wallet_save_py(PyObject *self, PyObject *argv); + +void dap_chain_wallet_close_py(PyDapChainWalletObject *self); + +PyObject *dap_cert_to_addr_py(PyObject *self, PyObject *argv); + +PyObject *dap_chain_wallet_get_addr_py(PyObject *self, PyObject *argv); +PyObject *dap_chain_wallet_get_certs_number_py(PyObject *self, PyObject *argv); +PyObject *dap_chain_wallet_get_pkey_py(PyObject *self, PyObject *argv); +PyObject *dap_chain_wallet_get_key_py(PyObject *self, PyObject *argv); + +//PyObject *dap_chain_wallet_save_file_py(PyObject *self, PyObject *argv); + +static PyMethodDef ChainWalletMethods[] = { + {"getPath", (PyCFunction)dap_chain_wallet_get_path_py, METH_VARARGS | METH_STATIC, ""}, + {"createWithSeed", (PyCFunction)dap_chain_wallet_create_with_seed_py, METH_VARARGS | METH_STATIC, ""}, + {"openFile", (PyCFunction)dap_chain_wallet_open_file_py, METH_VARARGS | METH_STATIC, ""}, + {"open", (PyCFunction)dap_chain_wallet_open_py, METH_VARARGS | METH_STATIC, ""}, + {"save", (PyCFunction)dap_chain_wallet_save_py, METH_NOARGS, ""}, + {"certToAddr", (PyCFunction)dap_cert_to_addr_py, METH_VARARGS | METH_STATIC, ""}, + {"getAddr", (PyCFunction)dap_chain_wallet_get_addr_py, METH_VARARGS, ""}, + {"getCertsNumber", (PyCFunction)dap_chain_wallet_get_certs_number_py, METH_NOARGS, ""}, + {"getPKey", (PyCFunction)dap_chain_wallet_get_pkey_py, METH_VARARGS, ""}, + {"getKey", (PyCFunction)dap_chain_wallet_get_key_py, METH_VARARGS, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapChainWallet_dapChainWalletType = { + PyVarObject_HEAD_INIT(NULL, 0) + "ChainWallet", /* tp_name */ + sizeof(PyDapChainWalletObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)dap_chain_wallet_close_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 */ + "Chain wallet object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + ChainWalletMethods, /* 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 */ + dap_chain_wallet_create_py,/* tp_new */ + 0, /* tp_free */ + 0, /* tp_is_gc*/ + 0, /* tp_bases*/ + 0, /* tp_mro */ + 0, /* tp_cache */ + 0, /* tp_subclasses */ + 0, /* tp_weaklist */ + 0, /* tp_del */ + 0, /* tp_version_tag*/ + 0, /* tp_finalize*/ +}; + + +#ifdef __cplusplus +} +#endif + + +#endif // _DAP_CHAIN_WALLET_PYTHON_ diff --git a/cellframe-sdk-python/libdap-chain-wallet-python/src/dap_chain_wallet_python.c b/cellframe-sdk-python/libdap-chain-wallet-python/src/dap_chain_wallet_python.c new file mode 100644 index 0000000000000000000000000000000000000000..bea9ed3ecb26b375a7fae3d0c28354fac67224b9 --- /dev/null +++ b/cellframe-sdk-python/libdap-chain-wallet-python/src/dap_chain_wallet_python.c @@ -0,0 +1,138 @@ +#include "dap_chain_wallet_python.h" +#define LOG_TAG "dap_chain_wallet_python" + +int dap_chain_wallet_init_py(void){ + return dap_chain_wallet_init(); +} +void dap_chain_wallet_deinit_py(void){ + dap_chain_wallet_deinit(); +} + +PyObject *dap_chain_wallet_get_path_py(PyObject *self, PyObject *argv){ + (void)self; + (void)argv; + const char *path = dap_chain_wallet_get_path(g_config); + return Py_BuildValue("(s)", path); +} + +PyObject *dap_chain_wallet_create_with_seed_py(PyObject *self, PyObject *argv){ + (void)self; + const char *wallet_name; + const char *path_wallets; + PyObject *obj_sig_type; + PyObject *obj_seed; + if (!PyArg_ParseTuple(argv, "ssOO", &wallet_name, &path_wallets, &obj_sig_type, &obj_seed)) + return NULL; + if (PyBytes_Check(obj_seed)){ + PyErr_SetString(PyExc_TypeError, "Fourth argument to not have a Bytes object type"); + return NULL; + } + void *seed = (void *)PyBytes_AsString(obj_seed); + size_t seed_size = PyBytes_Size(obj_seed); + PyObject *obj_wallet = _PyObject_New(&DapChainWallet_dapChainWalletType); + ((PyDapChainWalletObject*)obj_wallet)->wallet = dap_chain_wallet_create_with_seed( + wallet_name, + path_wallets, + *((PyDapSignTypeObject*)obj_sig_type)->sign_type, + seed, + seed_size); + return Py_BuildValue("(O)", obj_wallet); +} +PyObject *dap_chain_wallet_create_py(PyTypeObject *type, PyObject *argv, PyObject *kwds){ + (void)kwds; + PyDapChainWalletObject *self; + const char *wallet_name; + const char *path_wallets; + PyObject *obj_sign_type; + if (!PyArg_ParseTuple(argv, "ssO", &wallet_name, &path_wallets, &obj_sign_type)) + return NULL; + self = (PyDapChainWalletObject*)type->tp_alloc(type, 0); + if (self != NULL){ + self->wallet = dap_chain_wallet_create(wallet_name, path_wallets, *((PyDapSignTypeObject*)obj_sign_type)->sign_type); + if (self->wallet == NULL){ + Py_XDECREF(self); + return NULL; + } + } + return (PyObject*)self; +} +PyObject *dap_chain_wallet_open_file_py(PyObject *self, PyObject *argv){ + (void)self; + const char *file_path; + if (!PyArg_ParseTuple(argv, "s", &file_path)) + return NULL; + PyObject *obj_wallet = _PyObject_New(&DapChainWallet_dapChainWalletType); + ((PyDapChainWalletObject*)obj_wallet)->wallet = dap_chain_wallet_open_file(file_path); + return Py_BuildValue("(O)", obj_wallet); +} +PyObject *dap_chain_wallet_open_py(PyObject *self, PyObject *argv){ + (void)self; + const char *wallet_name; + const char *wallet_path; + if (!PyArg_ParseTuple(argv, "ss", &wallet_name, &wallet_path)) + return NULL; + PyObject *obj_wallet = _PyObject_New(&DapChainWallet_dapChainWalletType); + ((PyDapChainWalletObject*)obj_wallet)->wallet = dap_chain_wallet_open(wallet_name, wallet_path); + return Py_BuildValue("(O)", obj_wallet); +} +PyObject *dap_chain_wallet_save_py(PyObject *self, PyObject *argv){ + (void)argv; + int result = dap_chain_wallet_save(((PyDapChainWalletObject*)self)->wallet); + return PyLong_FromLong(result); +} + +void dap_chain_wallet_close_py(PyDapChainWalletObject *self){ + dap_chain_wallet_close(self->wallet); + Py_TYPE(self)->tp_free((PyObject*)self); +} + +PyObject *dap_cert_to_addr_py(PyObject *self, PyObject *argv){ + (void)self; + PyObject *obj_cert; + PyObject *obj_net_id; + if (!PyArg_ParseTuple(argv, "OO", &obj_cert, &obj_net_id)) + return NULL; + PyObject *obj_addr = _PyObject_New(&DapChainAddrObject_DapChainAddrObjectType); + ((PyDapChainAddrObject*)obj_addr)->addr = dap_cert_to_addr( + ((PyCryptoCertObject*)obj_cert)->cert, + ((PyDapChainNetIdObject*)obj_net_id)->net_id + ); + return Py_BuildValue("(O)", obj_addr); +} + +PyObject *dap_chain_wallet_get_addr_py(PyObject *self, PyObject *argv){ + PyObject *obj_net_id; + if (!PyArg_ParseTuple(argv, "O", &obj_net_id)) + return NULL; + PyObject *obj_addr = _PyObject_New(&DapChainAddrObject_DapChainAddrObjectType); + ((PyDapChainAddrObject*)obj_addr)->addr = dap_chain_wallet_get_addr( + ((PyDapChainWalletObject*)self)->wallet, + ((PyDapChainNetIdObject*)obj_net_id)->net_id + ); + return Py_BuildValue("(O)", obj_addr); +} +PyObject *dap_chain_wallet_get_certs_number_py(PyObject *self, PyObject *argv){ + (void)argv; + size_t result = dap_chain_wallet_get_certs_number(((PyDapChainWalletObject*)self)->wallet); + return PyLong_FromLong(result); +} +PyObject *dap_chain_wallet_get_pkey_py(PyObject *self, PyObject *argv){ + uint32_t key_idx; + if (!PyArg_ParseTuple(argv, "I", &key_idx)) + return NULL; + PyObject *obj_pkey = _PyObject_New(&DapPkeyObject_DapPkeyObjectType); + ((PyDapPkeyObject*)obj_pkey)->pkey = dap_chain_wallet_get_pkey(((PyDapChainWalletObject*)self)->wallet, + key_idx); + return Py_BuildValue("(O)", obj_pkey); +} +PyObject *dap_chain_wallet_get_key_py(PyObject *self, PyObject *argv){ + uint32_t key_idx; + if (!PyArg_ParseTuple(argv, "I", &key_idx)) + return NULL; + PyObject *obj_key = _PyObject_New(&PyCryptoKeyObject_PyCryptoKeyType); + ((PyCryptoKeyObject*)obj_key)->key = dap_chain_wallet_get_key( + ((PyDapChainWalletObject*)self)->wallet, + key_idx + ); + return Py_BuildValue("(O)", obj_key); +} diff --git a/cellframe-sdk-python/libdap-client-python b/cellframe-sdk-python/libdap-client-python deleted file mode 160000 index 43c5689af4d7f4bf2a5bbbcecb165bc6c68d4cec..0000000000000000000000000000000000000000 --- a/cellframe-sdk-python/libdap-client-python +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 43c5689af4d7f4bf2a5bbbcecb165bc6c68d4cec diff --git a/cellframe-sdk-python/libdap-client-python/CMakeLists.txt b/cellframe-sdk-python/libdap-client-python/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6e8684460129b596adf57d2f6a274c0de022d57c --- /dev/null +++ b/cellframe-sdk-python/libdap-client-python/CMakeLists.txt @@ -0,0 +1,88 @@ +project(dap_client_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(UNIX) + add_definitions("-DDAP_OS_UNIX") +endif() + +if (NOT (${SUBMODULES_NO_BUILD} MATCHES ON)) + set (SUBMODULES_NO_BUILD ON) + if (NOT (TARGET dap_core)) + add_subdirectory(libdap) + target_compile_options( + dap_core PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_crypto)) + add_subdirectory(libdap-crypto) + target_compile_options( + dap_crypto PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_server_core)) + add_subdirectory(libdap-server-core) + target_compile_options( + dap_server_core PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET libdap-server)) + add_subdirectory(libdap-server) +# target_compile_options( +# libdap-server PRIVATE +# "-fpic" +# ) + endif() + if (NOT (TARGET dap_stream)) + add_subdirectory(libdap-stream) + target_compile_options( + dap_stream PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_stream_ch)) + add_subdirectory(libdap-stream-ch) + target_compile_options( + dap_stream_ch PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_udp_server)) + add_subdirectory(libdap-server-udp) + target_compile_options( + dap_udp_server PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_client)) + add_subdirectory(libdap-client) + target_compile_options( + dap_client PRIVATE + "-fpic" + ) + endif() +endif() +#add_definitions("-DDAP_APP_NAME=\"TestPRJ\" -DSYSTEM_CONFIGS_DIR=\"${CMAKE_CURRENT_BINARY_DIR}\"") + +file(GLOB CLIENT_PYTHON_SRCS src/*.c) +file(GLOB CLIENT_PYTHON_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 ${CLIENT_PYTHON_SRCS} ${CLIENT_PYTHON_HEADERS}) + +target_link_libraries(${PROJECT_NAME}) + +target_link_libraries(${PROJECT_NAME} dap_core dap_crypto dap_client ) + +target_include_directories(${PROJECT_NAME} PUBLIC include/ ) + diff --git a/cellframe-sdk-python/libdap-client-python/README.md b/cellframe-sdk-python/libdap-client-python/README.md new file mode 100644 index 0000000000000000000000000000000000000000..18d673714d24b7ef23b69142dea14c2224463f9a --- /dev/null +++ b/cellframe-sdk-python/libdap-client-python/README.md @@ -0,0 +1,2 @@ +# libdap-client-python + diff --git a/cellframe-sdk-python/libdap-client-python/include/libdap_client_python.h b/cellframe-sdk-python/libdap-client-python/include/libdap_client_python.h new file mode 100644 index 0000000000000000000000000000000000000000..9a95fbf75234b16249550749214b3156fddb9325 --- /dev/null +++ b/cellframe-sdk-python/libdap-client-python/include/libdap_client_python.h @@ -0,0 +1,98 @@ +#define PY_SSIZE_T_CLEAN +#include <Python.h> +#include "dap_client.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PyDapClient{ + PyObject_HEAD + dap_client_t *client; +}PyDapClientObject; + +int dap_client_init_py(); +void dap_client_deinit_py(); + +//PyObject *dap_client_new_py(PyObject *) +PyObject *dap_client_delete_py(PyObject *self, PyObject *args); + +PyObject *dao_client_set_uplink_py(PyObject *self, PyObject *args); +PyObject *dap_client_get_uplink_addr_py(PyObject *self, PyObject *args); +PyObject *dap_client_get_uplink_port_py(PyObject *self, PyObject *args); + +PyObject *dap_client_get_key_stream_py(PyObject *self, PyObject *args); +PyObject *dap_client_go_stage_py(PyObject *self, PyObject *args); +PyObject *dap_client_reset_py(PyObject *self, PyObject *args); +PyObject *dap_client_request_enc_py(PyObject *self, PyObject *args); +PyObject *dap_client_request_py(PyObject *self, PyObject *args); +PyObject *dap_client_disconnect_py(PyObject *self, PyObject *args); + +PyObject *dap_client_get_stage_str_py(PyObject *self, PyObject *args); +PyObject *dap_client_stage_str_py(PyObject *self, PyObject *args); + +PyObject *dap_client_get_stage_status_str_py(PyObject *self, PyObject *args); +PyObject *dap_client_stage_status_str_py(PyObject *self, PyObject *args); +PyObject *dap_client_error_str_py(PyObject *self, PyObject *args); +PyObject *dap_client_get_error_str_py(PyObject *self, PyObject *args); + +PyObject *dap_client_get_auth_cookie_py(PyObject *self, PyObject *args); +PyObject *dap_client_get_stream_py(PyObject *self, PyObject *args); +PyObject *dap_client_get_stream_ch_py(PyObject *self, PyObject *args); +PyObject *dap_client_get_stream_id_py(PyObject *self, PyObject *args); +PyObject *dap_client_set_active_channels_py(PyObject *self, PyObject *args); + +PyObject *dap_client_get_stage_py(PyObject *self, PyObject *args); +PyObject *dap_client_get_stage_status_py(PyObject *self, PyObject *args); + +static PyMethodDef DapClientMethods[] = { + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject dapClientObject_dapClientType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Client", /* tp_name */ + sizeof(PyDapClientObject), /* 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 */ + "Client objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapClientMethods, /* 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 + diff --git a/cellframe-sdk-python/libdap-client-python/include/wrapping_dap_client_stage.h b/cellframe-sdk-python/libdap-client-python/include/wrapping_dap_client_stage.h new file mode 100644 index 0000000000000000000000000000000000000000..bb3a9fe88d21ab26d2ad4b53a439d0e9e0cc278a --- /dev/null +++ b/cellframe-sdk-python/libdap-client-python/include/wrapping_dap_client_stage.h @@ -0,0 +1,84 @@ +#ifndef _WRAPPING_DAP_CLIENT_STAGE_ +#define _WRAPPING_DAP_CLIENT_STAGE_ +#include <Python.h> +#include "dap_client.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +typedef struct PyDapClientStage{ + PyObject_HEAD + dap_client_stage_t stage; +}PyDapClientStageObject; + +PyObject *STAGE_BEGIN_PY(); +PyObject *STAGE_ENC_INIT_PY(); +PyObject *STAGE_STREAM_CTL_PY(); +PyObject *STAGE_STREAM_SESSION_PY(); +PyObject *STAGE_STREAM_CONNECTED_PY(); +PyObject *STAGE_STREAM_STREAMING_PY(); +PyObject *STAGE_STREAM_ABORT_PY(); + +static PyMethodDef DapClientStageMethods[] = { + {"STAGE_BEGIN", (PyCFunction)STAGE_BEGIN_PY, METH_NOARGS | METH_STATIC, ""}, + {"STAGE_ENC_INIT", (PyCFunction)STAGE_ENC_INIT_PY, METH_NOARGS | METH_STATIC, ""}, + {"STAGE_STREAM_CTL", (PyCFunction)STAGE_STREAM_CTL_PY, METH_NOARGS | METH_STATIC, ""}, + {"STAGE_STREAM_SESSION", (PyCFunction)STAGE_STREAM_SESSION_PY, METH_NOARGS | METH_STATIC, ""}, + {"STAGE_STREAM_CONNECTED", (PyCFunction)STAGE_STREAM_CONNECTED_PY, METH_NOARGS | METH_STATIC, ""}, + {"STAGE_STREAM_STREAMING", (PyCFunction)STAGE_STREAM_STREAMING_PY, METH_NOARGS | METH_STATIC, ""}, + {"STAGE_STREAM_ABORT",(PyCFunction) STAGE_STREAM_ABORT_PY, METH_NOARGS | METH_STATIC, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject dapClientStageObject_dapClientStageType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.ClientStage", /* tp_name */ + sizeof(PyDapClientStageObject), /* 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 */ + "Client stage objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapClientStageMethods, /* 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 + +#endif // _WRAPPING_DAP_CLIENT_STAGE_ \ No newline at end of file diff --git a/cellframe-sdk-python/libdap-client-python/include/wrapping_dap_client_stage_status.h b/cellframe-sdk-python/libdap-client-python/include/wrapping_dap_client_stage_status.h new file mode 100644 index 0000000000000000000000000000000000000000..8b33546fbec58bcf03add34be043c4c8b5035551 --- /dev/null +++ b/cellframe-sdk-python/libdap-client-python/include/wrapping_dap_client_stage_status.h @@ -0,0 +1,83 @@ +#ifndef _WRAPPING_DAP_CLIENT_STAGE_STATUS_ +#define _WRAPPING_DAP_CLIENT_STAGE_STATUS_ + +#include <Python.h> +#include "dap_client.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +typedef struct PyDapClientStageStatus{ + PyObject_HEAD + dap_client_stage_status_t stage_status; +}PyDapClientStageStatusObject; + +PyObject *STAGE_STATUS_NONE_PY(); +// Enc init stage +PyObject *STAGE_STATUS_IN_PROGRESS_PY(); +PyObject *STAGE_STATUS_ABORTING_PY(); +PyObject *STAGE_STATUS_ERROR_PY(); +PyObject *STAGE_STATUS_DONE_PY(); + + +PyMethodDef DapClientStageStatusMethods[] = { + {"STAGE_STATUS_NONE", STAGE_STATUS_NONE_PY, METH_NOARGS, ""}, + // Enc init stage + {"STAGE_STATUS_IN_PROGRESS", STAGE_STATUS_IN_PROGRESS_PY, METH_NOARGS | METH_STATIC, ""}, + {"STAGE_STATUS_ABORTING", STAGE_STATUS_ABORTING_PY, METH_NOARGS | METH_STATIC, ""}, + {"STAGE_STATUS_ERROR", STAGE_STATUS_ERROR_PY, METH_NOARGS | METH_STATIC, ""}, + {"STAGE_STATUS_DONE", STAGE_STATUS_DONE_PY, METH_NOARGS | METH_STATIC, ""}, + + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject dapClientStageStatusObject_dapClientStageStatusType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.ClientStageStatus", /* tp_name */ + sizeof(PyDapClientStageStatusObject), /* 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 */ + "Client stage status objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapClientStageStatusMethods, /* 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 + +#endif //_WRAPPING_DAP_CLIENT_STAGE_STATUS_ \ No newline at end of file diff --git a/cellframe-sdk-python/libdap-client-python/src/libdap_client_python.c b/cellframe-sdk-python/libdap-client-python/src/libdap_client_python.c new file mode 100644 index 0000000000000000000000000000000000000000..a6950eeaaf41cf9e97efa8364cbd6683bb42f7ae --- /dev/null +++ b/cellframe-sdk-python/libdap-client-python/src/libdap_client_python.c @@ -0,0 +1,206 @@ +#include "libdap_client_python.h" + +int dap_client_init_py(){ + return dap_client_init(); +} +void dap_client_deinit_py(){ + dap_client_deinit(); +} + +PyObject *dao_client_set_uplink_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject *dap_client_get_uplink_addr_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject *dap_client_get_uplink_port_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject *dap_client_get_key_stream_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject *dap_client_go_stage_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject *dap_client_reset_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject *dap_client_request_enc_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject *dap_client_request_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject *dap_client_disconnect_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject *dap_client_get_stage_str_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject *dap_client_stage_str_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject *dap_client_get_stage_status_str_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject *dap_client_stage_status_str_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject *dap_client_error_str_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject *dap_client_get_error_str_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject *dap_client_get_auth_cookie_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject *dap_client_get_stream_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject *dap_client_get_stream_ch_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject *dap_client_get_stream_id_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject *dap_client_set_active_channels_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject *dap_client_get_stage_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject *dap_client_get_stage_status_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} diff --git a/cellframe-sdk-python/libdap-client-python/src/wrapping_dap_client_stage.c b/cellframe-sdk-python/libdap-client-python/src/wrapping_dap_client_stage.c new file mode 100644 index 0000000000000000000000000000000000000000..25cc196673915741813f4ff7b2e78e5393ee4e09 --- /dev/null +++ b/cellframe-sdk-python/libdap-client-python/src/wrapping_dap_client_stage.c @@ -0,0 +1,37 @@ +#include "wrapping_dap_client_stage.h" + +PyObject *STAGE_BEGIN_PY(){ + PyDapClientStageObject *obj_stage = (PyDapClientStageObject*)_PyObject_New(&dapClientStageObject_dapClientStageType); + obj_stage->stage = STAGE_BEGIN; + return (PyObject *)obj_stage; +} +PyObject *STAGE_ENC_INIT_PY(){ + PyDapClientStageObject *obj_stage = (PyDapClientStageObject*)_PyObject_New(&dapClientStageObject_dapClientStageType); + obj_stage->stage = STAGE_ENC_INIT; + return (PyObject *)obj_stage; +} +PyObject *STAGE_STREAM_CTL_PY(){ + PyDapClientStageObject *obj_stage = (PyDapClientStageObject*)_PyObject_New(&dapClientStageObject_dapClientStageType); + obj_stage->stage = STAGE_STREAM_CTL; + return (PyObject *)obj_stage; +} +PyObject *STAGE_STREAM_SESSION_PY(){ + PyDapClientStageObject *obj_stage = (PyDapClientStageObject*)_PyObject_New(&dapClientStageObject_dapClientStageType); + obj_stage->stage = STAGE_STREAM_SESSION; + return (PyObject *)obj_stage; +} +PyObject *STAGE_STREAM_CONNECTED_PY(){ + PyDapClientStageObject *obj_stage = (PyDapClientStageObject*)_PyObject_New(&dapClientStageObject_dapClientStageType); + obj_stage->stage = STAGE_STREAM_CONNECTED; + return (PyObject *)obj_stage; +} +PyObject *STAGE_STREAM_STREAMING_PY(){ + PyDapClientStageObject *obj_stage = (PyDapClientStageObject*)_PyObject_New(&dapClientStageObject_dapClientStageType); + obj_stage->stage = STAGE_STREAM_STREAMING; + return (PyObject *)obj_stage; +} +PyObject *STAGE_STREAM_ABORT_PY(){ + PyDapClientStageObject *obj_stage = (PyDapClientStageObject*)_PyObject_New(&dapClientStageObject_dapClientStageType); + obj_stage->stage = STAGE_STREAM_ABORT; + return (PyObject *)obj_stage; +} \ No newline at end of file diff --git a/cellframe-sdk-python/libdap-client-python/src/wrapping_dap_client_stage_status.c b/cellframe-sdk-python/libdap-client-python/src/wrapping_dap_client_stage_status.c new file mode 100644 index 0000000000000000000000000000000000000000..ff1603ab0c656b38cb381eebadd580dc0b14c866 --- /dev/null +++ b/cellframe-sdk-python/libdap-client-python/src/wrapping_dap_client_stage_status.c @@ -0,0 +1,33 @@ +#include "wrapping_dap_client_stage_status.h" + +PyObject *STAGE_STATUS_NONE_PY(){ + PyDapClientStageStatusObject *obj_stage_status = (PyDapClientStageStatusObject*)_PyObject_New( + &dapClientStageStatusObject_dapClientStageStatusType); + obj_stage_status->stage_status = STAGE_STATUS_NONE; + return (PyObject *)obj_stage_status; +} +// Enc init stage +PyObject *STAGE_STATUS_IN_PROGRESS_PY(){ + PyDapClientStageStatusObject *obj_stage_status = (PyDapClientStageStatusObject*)_PyObject_New( + &dapClientStageStatusObject_dapClientStageStatusType); + obj_stage_status->stage_status = STAGE_STATUS_IN_PROGRESS; + return (PyObject *)obj_stage_status; +} +PyObject *STAGE_STATUS_ABORTING_PY(){ + PyDapClientStageStatusObject *obj_stage_status = (PyDapClientStageStatusObject*)_PyObject_New( + &dapClientStageStatusObject_dapClientStageStatusType); + obj_stage_status->stage_status = STAGE_STATUS_ABORTING; + return (PyObject *)obj_stage_status; +} +PyObject *STAGE_STATUS_ERROR_PY(){ + PyDapClientStageStatusObject *obj_stage_status = (PyDapClientStageStatusObject*)_PyObject_New( + &dapClientStageStatusObject_dapClientStageStatusType); + obj_stage_status->stage_status = STAGE_STATUS_ERROR; + return (PyObject *)obj_stage_status; +} +PyObject *STAGE_STATUS_DONE_PY(){ + PyDapClientStageStatusObject *obj_stage_status = (PyDapClientStageStatusObject*)_PyObject_New( + &dapClientStageStatusObject_dapClientStageStatusType); + obj_stage_status->stage_status = STAGE_STATUS_DONE; + return (PyObject *)obj_stage_status; +} \ No newline at end of file diff --git a/cellframe-sdk-python/libdap-crypto-python b/cellframe-sdk-python/libdap-crypto-python deleted file mode 160000 index 1ef04620dc5df45ef8da6a080c2f40c295514b42..0000000000000000000000000000000000000000 --- a/cellframe-sdk-python/libdap-crypto-python +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1ef04620dc5df45ef8da6a080c2f40c295514b42 diff --git a/cellframe-sdk-python/libdap-crypto-python/.gitignore b/cellframe-sdk-python/libdap-crypto-python/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..894a44cc066a027465cd26d634948d56d13af9af --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/.gitignore @@ -0,0 +1,104 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ diff --git a/cellframe-sdk-python/libdap-crypto-python/.travis.yml b/cellframe-sdk-python/libdap-crypto-python/.travis.yml new file mode 100644 index 0000000000000000000000000000000000000000..7227c9af5ba74d205a5f05d993287b98e5aecd53 --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/.travis.yml @@ -0,0 +1,38 @@ +sudo: required +language: python +python: + - "3.7-dev" +compiler: gcc +dist: xenial +notifications: + email: false + +before_install: + - git submodule init + - git submodule update + +install: + - sudo apt-get install gcc make + +script: + - sudo service network-manager start + - mkdir build + - cd build + - cmake ../ + - make + - cp ../test/test_b58.py ./ + - cp ../test/test_b64.py ./ + - cp ../test/test_iaes256_cbc.py ./ + - cp ../test/test_oaes.py ./ + - python3.7 test_b58.py + - python3.7 test_b64.py + - python3.7 test_iaes256_cbc.py + - python3.7 test_oaes.py + + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - network-manager diff --git a/cellframe-sdk-python/libdap-crypto-python/CMakeLists.txt b/cellframe-sdk-python/libdap-crypto-python/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..f2aa8716e0b79ce25d73127adafc1b5c63da871e --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/CMakeLists.txt @@ -0,0 +1,58 @@ +project(dap_crypto_python_module C) +cmake_minimum_required(VERSION 2.8) + +set(CMAKE_VERBOSE_MAKEFILE ON) +set(CMAKE_COLOR_MAKEFILE ON) +set(CMAKE_C_STANDARD 11) +#set(SUBMODULES_NO_BUILD ON) +add_definitions("-fpic") +add_definitions("-DDAP_LOG_MT") + +if(NOT (${SUBMODULES_NO_BUILD} MATCHES ON)) + if (NOT (TARGET dap_core)) + add_subdirectory(libdap) + target_compile_options( + dap_core PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_crypto)) + add_subdirectory(libdap-crypto) + target_compile_options( + dap_crypto PRIVATE + "-fpic" + ) + endif() +endif() + +file(GLOB CRYPTO_PYTHON_SRCS src/*.c) +file(GLOB CRYPTO_PYTHON_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 ${CRYPTO_PYTHON_SRCS} ${CRYPTO_PYTHON_HEADERS}) + +target_link_libraries(${PROJECT_NAME}) + +target_link_libraries(${PROJECT_NAME} dap_core dap_crypto) + +target_include_directories(${PROJECT_NAME} PUBLIC include/ ) + +if(BUILD_DAP_CRYPTO_PYTHON_TESTS) + add_subdirectory(test) + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/test_b58.py + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test/) + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/test_b64.py + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test/) + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/test_iaes256_cbc.py + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test/) + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/test_iaes256_cbc.py + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test/) + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/test_oaes.py + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test/) + + +endif() + diff --git a/cellframe-sdk-python/libdap-crypto-python/LICENSE b/cellframe-sdk-python/libdap-crypto-python/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..f288702d2fa16d3cdf0035b15a9fcbc552cd88e7 --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + <program> Copyright (C) <year> <name of author> + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +<https://www.gnu.org/licenses/>. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +<https://www.gnu.org/licenses/why-not-lgpl.html>. diff --git a/cellframe-sdk-python/libdap-crypto-python/README.md b/cellframe-sdk-python/libdap-crypto-python/README.md new file mode 100644 index 0000000000000000000000000000000000000000..160dbc91a99d3aba423ef9a16bf4c9fb9d9f1e1c --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/README.md @@ -0,0 +1,17 @@ +# libdap-crypto-python +libdap-crypto python binding + +[](https://travis-ci.com/cellframe/libdap-crypto-python) + +## Build and Run tests: +``` +mkdir build +cd build +cmake -BUILD_DAP_CRYPTO_PYTHON_TESTS=ON ../ +make +cd test +python3.7 test_b58.py +python3.7 test_b64.py +python3.7 test_iaes256_cbc.py +python3.7 test_oaes.py +``` diff --git a/cellframe-sdk-python/libdap-crypto-python/include/libdap-crypto-python.h b/cellframe-sdk-python/libdap-crypto-python/include/libdap-crypto-python.h new file mode 100644 index 0000000000000000000000000000000000000000..b17cb127d9baae109fcc4e4b4eb4e648300e59ed --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/include/libdap-crypto-python.h @@ -0,0 +1,125 @@ +/* + * Authors: + * Alexey Stratulat <alexey.stratulat@demlabs.net> + * Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * CellFrame https://cellframe.net + * Sources https://gitlab.demlabs.net/cellframe + * Copyright (c) 2017-2020 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ +#pragma once +#define PY_SSIZE_T_CLEAN + +#include <Python.h> +#include "dap_enc.h" +#include "dap_enc_key.h" +#include "dap_common.h" +#include "wrapping_cert.h" +#include "wrapping_base58.h" +#include "wrapping_base64.h" +#include "wrapping_dap_enc_key.h" +#include "wrapping_dap_enc_iaes.h" +#include "wrapping_dap_enc_oaes.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct PyCrypto{ + PyObject_HEAD +}PyCryptoObject; + +int dap_crypto_init(void); + +void dap_crypto_deinit(void); + +static PyMethodDef g_crypto_methods_py[] = { + {"encodeBase58", dap_encode_base58_py, METH_VARARGS | METH_STATIC, "Encrypts information using the base58 algorithm from the DAP crypto library"}, + {"decodeBase58", dap_decode_base58_py, METH_VARARGS | METH_STATIC, "Dencrypts information using the base58 algorithm from the DAP crypto library"}, + {"encodeBase64", dap_encode_base64_py, METH_VARARGS | METH_STATIC, "Encrypts information using the base64 algorithm from the DAP crypto library"}, + {"decodeBase64", dap_decode_base64_py, METH_VARARGS | METH_STATIC, "Dencrypts information using the base64 algorithm from the DAP crypto library"}, + {"newKey", dap_enc_key_new_py, METH_VARARGS | METH_STATIC, "The function creates a new key, and returns it with PyObject."}, + {"generateNewKey", dap_enc_key_new_generate_py, METH_VARARGS | METH_STATIC, ""}, + {"getEncSizeKey", dap_enc_key_get_enc_size_py, METH_VARARGS | METH_STATIC, ""}, + {"getDecSizeKey", dap_enc_key_get_dec_size_py, METH_VARARGS | METH_STATIC, ""}, + /*IAES256*/ + {"newKeyIAES", dap_enc_iaes_key_new_py, METH_VARARGS | METH_STATIC, ""}, + {"deleteKeyIAES", dap_enc_iaes_key_delete_py, METH_VARARGS | METH_STATIC, ""}, + {"generateKeyIAES", dap_enc_iaes_key_generate_py, METH_VARARGS | METH_STATIC, ""}, + {"encodeSizeIAES256", dap_enc_iaes256_calc_encode_size_py, METH_VARARGS | METH_STATIC, ""}, + {"decodeSizeIAES256", dap_enc_iaes256_calc_decode_size_py, METH_VARARGS | METH_STATIC, ""}, + {"encryptIAES256CBCFast", dap_enc_iaes256_cbc_encrypt_fast_py, METH_VARARGS | METH_STATIC, ""}, + {"decryptIAES256CBCFast", dap_enc_iaes256_cbc_decrypt_fast_py, METH_VARARGS | METH_STATIC, ""}, + /*OAES*/ + {"newKeyOAES", dap_enc_oaes_key_new_py, METH_VARARGS | METH_STATIC, ""}, + {"deleteKeyOAES", dap_enc_oaes_key_delete_py, METH_VARARGS | METH_STATIC, ""}, + {"generateKeyOAES", dap_enc_oaes_key_generate_py, METH_VARARGS | METH_STATIC, ""}, + {"encodeSizeOAES", dap_enc_oaes_calc_encode_size_py, METH_VARARGS | METH_STATIC, ""}, + {"decodeSizeOAES", dap_enc_oaes_calc_decode_size_py, METH_VARARGS | METH_STATIC, ""}, + {"encryptOAESFast", dap_enc_oaes_encrypt_fast_py, METH_VARARGS | METH_STATIC, ""}, + {"decryptOAESFast", dap_enc_oaes_decrypt_fast_py, METH_VARARGS | METH_STATIC, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject g_crypto_type_py = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Crypto", /* tp_name */ + sizeof(PyCryptoObject), /* 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 */ + "Crypto objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + g_crypto_methods_py, /* 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 diff --git a/cellframe-sdk-python/libdap-crypto-python/include/libdap_crypto_data_type.h b/cellframe-sdk-python/libdap-crypto-python/include/libdap_crypto_data_type.h new file mode 100644 index 0000000000000000000000000000000000000000..541e8693f7da211d5b19722f38bf0700de7eeaee --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/include/libdap_crypto_data_type.h @@ -0,0 +1,100 @@ +/* + * Authors: + * Alexey Stratulat <alexey.stratulat@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * CellFrame https://cellframe.net + * Sources https://gitlab.demlabs.net/cellframe + * Copyright (c) 2017-2020 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ + +#pragma once +#include "Python.h" +#include "dap_enc_key.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PyCryptoDataType{ + PyObject_HEAD +}PyCryptoDataTypeObjecy; + +static PyObject *get_ENC_DATA_TYPE_RAW(){ + return PyLong_FromLong(DAP_ENC_DATA_TYPE_RAW); +} +static PyObject *get_ENC_DATA_TYPE_B64(){ + return PyLong_FromLong(DAP_ENC_DATA_TYPE_B64); +} +static PyObject *get_ENC_DATA_TYPE_B64_URLSAFE(){ + return PyLong_FromLong(DAP_ENC_DATA_TYPE_B64_URLSAFE); +} + +static PyMethodDef PyCryptoDataTypeObjecyMethods[] = { + {"DAP_ENC_DATA_TYPE_RAW", (PyCFunction)get_ENC_DATA_TYPE_RAW, METH_NOARGS | METH_STATIC, ""}, + {"DAP_ENC_DATA_TYPE_B64", (PyCFunction)get_ENC_DATA_TYPE_B64, METH_NOARGS | METH_STATIC, ""}, + {"DAP_ENC_DATA_TYPE_B64_URLSAFE", (PyCFunction)get_ENC_DATA_TYPE_B64_URLSAFE, METH_NOARGS | METH_STATIC, ""}, + + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject CryptoDataTypeObjecy_CryptoDataTypeObjecyType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.CryptoDataType", /* tp_name */ + sizeof(PyCryptoDataTypeObjecy), /* 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 */ + "Crypto data type objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + PyCryptoDataTypeObjecyMethods, /* 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 diff --git a/cellframe-sdk-python/libdap-crypto-python/include/libdap_crypto_key_python.h b/cellframe-sdk-python/libdap-crypto-python/include/libdap_crypto_key_python.h new file mode 100644 index 0000000000000000000000000000000000000000..109776d211761d0e9e1d525c370f4f7fadfc6e3a --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/include/libdap_crypto_key_python.h @@ -0,0 +1,48 @@ +#ifndef LIBDAP_CRYPTO_KEY_PYTHON_H_ +#define LIBDAP_CRYPTO_KEY_PYTHON_H_ + +#include "Python.h" +#include "dap_enc_key.h" +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PyCryptoKey{ + PyObject_HEAD + dap_enc_key_t *key; +}PyCryptoKeyObject; + +static void PyCryptoKeyObject_dealloc(PyCryptoKeyObject *cryptoObject){ + dap_enc_key_delete(cryptoObject->key); + Py_TYPE(cryptoObject)->tp_free((PyObject*)cryptoObject); +} + +static PyTypeObject PyCryptoKeyObject_PyCryptoKeyType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Crypto.Key", /* tp_name */ + sizeof(PyCryptoKeyObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)PyCryptoKeyObject_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + 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, /* tp_flags */ + "Crypto key objects", /* tp_doc */ +}; + +#ifdef __cplusplus +} +#endif + +#endif //LIBDAP_CRYPTO_KEY_PYTHON_H_ diff --git a/cellframe-sdk-python/libdap-crypto-python/include/libdap_crypto_key_type_python.h b/cellframe-sdk-python/libdap-crypto-python/include/libdap_crypto_key_type_python.h new file mode 100644 index 0000000000000000000000000000000000000000..248d39e80addd6c758e2f116a353dde90d8500f4 --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/include/libdap_crypto_key_type_python.h @@ -0,0 +1,125 @@ +/* + * Authors: + * Alexey Stratulat <alexey.stratulat@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * CellFrame https://cellframe.net + * Sources https://gitlab.demlabs.net/cellframe + * Copyright (c) 2017-2020 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ + +#pragma once +#include "Python.h" +#include "dap_enc_key.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PyCryptoKeyType{ + PyObject_HEAD +}PyCryptoKeyTypeObjecy; + +PyObject *get_ENC_KEY_TYPE_IAES(); +PyObject *get_ENC_KEY_TYPE_OAES(); +PyObject *get_ENC_KEY_TYPE_RLWE_NEWHOPE(); +PyObject *get_ENC_KEY_TYPE_SIDH_CLN16(); +PyObject *get_ENC_KEY_TYPE_DEFEO(); +PyObject *get_ENC_KEY_TYPE_MSRLN(); +PyObject *get_ENC_KEY_TYPE_MSRLN16(); +PyObject *get_ENC_KEY_TYPE_RLWE_BCNS15(); +PyObject *get_ENC_KEY_TYPE_LWE_FRODO(); +PyObject *get_ENC_KEY_TYPE_SIDH_IQC_REF(); +PyObject *get_ENC_KEY_TYPE_CODE_MCBITS(); +PyObject *get_ENC_KEY_TYPE_NTRU(); +PyObject *get_ENC_KEY_TYPE_MLWE_KYBER(); +PyObject *get_ENC_KEY_TYPE_SIG_PICNIC(); +PyObject *get_ENC_KEY_TYPE_SIG_BLISS(); +PyObject *get_ENC_KEY_TYPE_SIG_TESLA(); +PyObject *get_ENC_KEY_TYPE_SIG_DILITHIUM(); +PyObject *get_ENC_KEY_TYPE_NULL(); + +static PyMethodDef PyCryptoKeyTypeObjecyMethods[] = { + {"DAP_ENC_KEY_TYPE_IAES", (PyCFunction)get_ENC_KEY_TYPE_IAES, METH_NOARGS | METH_STATIC, ""}, + {"DAP_ENC_KEY_TYPE_OAES", (PyCFunction)get_ENC_KEY_TYPE_OAES, METH_NOARGS | METH_STATIC, ""}, + {"DAP_ENC_KEY_TYPE_RLWE_NEWHOPE", (PyCFunction)get_ENC_KEY_TYPE_RLWE_NEWHOPE, METH_NOARGS | METH_STATIC, ""}, + {"DAP_ENC_KEY_TYPE_SIDH_CLN16", (PyCFunction)get_ENC_KEY_TYPE_SIDH_CLN16, METH_NOARGS | METH_STATIC, ""}, + {"DAP_ENC_KEY_TYPE_DEFEO", (PyCFunction)get_ENC_KEY_TYPE_DEFEO, METH_NOARGS | METH_STATIC, ""}, + {"DAP_ENC_KEY_TYPE_MSRLN", (PyCFunction)get_ENC_KEY_TYPE_MSRLN, METH_NOARGS | METH_STATIC, ""}, + {"DAP_ENC_KEY_TYPE_MSRLN16", (PyCFunction)get_ENC_KEY_TYPE_MSRLN16, METH_NOARGS | METH_STATIC, ""}, + {"DAP_ENC_KEY_TYPE_RLWE_BCNS15", (PyCFunction)get_ENC_KEY_TYPE_RLWE_BCNS15, METH_NOARGS | METH_STATIC, ""}, + {"DAP_ENC_KEY_TYPE_LWE_FRODO", (PyCFunction)get_ENC_KEY_TYPE_LWE_FRODO, METH_NOARGS | METH_STATIC, ""}, + {"DAP_ENC_KEY_TYPE_SIDH_IQC_REF", (PyCFunction)get_ENC_KEY_TYPE_SIDH_IQC_REF, METH_NOARGS | METH_STATIC, ""}, + {"DAP_ENC_KEY_TYPE_CODE_MCBITS", (PyCFunction)get_ENC_KEY_TYPE_CODE_MCBITS, METH_NOARGS | METH_STATIC, ""}, + {"DAP_ENC_KEY_TYPE_NTRU", (PyCFunction)get_ENC_KEY_TYPE_NTRU, METH_NOARGS | METH_STATIC, ""}, + {"DAP_ENC_KEY_TYPE_MLWE_KYBER", (PyCFunction)get_ENC_KEY_TYPE_MLWE_KYBER, METH_NOARGS | METH_STATIC, ""}, + {"DAP_ENC_KEY_TYPE_SIG_PICNIC", (PyCFunction)get_ENC_KEY_TYPE_SIG_PICNIC, METH_NOARGS | METH_STATIC, ""}, + {"DAP_ENC_KEY_TYPE_SIG_BLISS", (PyCFunction)get_ENC_KEY_TYPE_SIG_BLISS, METH_NOARGS | METH_STATIC, ""}, + {"DAP_ENC_KEY_TYPE_SIG_TESLA", (PyCFunction)get_ENC_KEY_TYPE_SIG_TESLA, METH_NOARGS | METH_STATIC, ""}, + {"DAP_ENC_KEY_TYPE_SIG_DILITHIUM", (PyCFunction)get_ENC_KEY_TYPE_SIG_DILITHIUM, METH_NOARGS | METH_STATIC, ""}, + {"DAP_ENC_KEY_TYPE_NULL", (PyCFunction)get_ENC_KEY_TYPE_NULL, METH_NOARGS | METH_STATIC, ""}, + + + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject CryptoKeyTypeObjecy_CryptoKeyTypeObjecyType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.CryptoKeyType", /* tp_name */ + sizeof(PyCryptoKeyTypeObjecy), /* 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 */ + "Crypto keys type objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + PyCryptoKeyTypeObjecyMethods, /* 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 diff --git a/cellframe-sdk-python/libdap-crypto-python/include/wrapping_base58.h b/cellframe-sdk-python/libdap-crypto-python/include/wrapping_base58.h new file mode 100644 index 0000000000000000000000000000000000000000..2fdfb8635147e85173ce48ec191bd9f6534ac8eb --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/include/wrapping_base58.h @@ -0,0 +1,40 @@ +/* + * Authors: + * Alexey Stratulat <alexey.stratulat@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * CellFrame https://cellframe.net + * Sources https://gitlab.demlabs.net/cellframe + * Copyright (c) 2017-2020 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ +#pragma once +#include "Python.h" +#include "dap_enc_base58.h" +#include "dap_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +PyObject *dap_encode_base58_py(PyObject *self, PyObject *args); + +PyObject *dap_decode_base58_py(PyObject *self, PyObject *args); + +#ifdef __cplusplus +} +#endif diff --git a/cellframe-sdk-python/libdap-crypto-python/include/wrapping_base64.h b/cellframe-sdk-python/libdap-crypto-python/include/wrapping_base64.h new file mode 100644 index 0000000000000000000000000000000000000000..50ed6fd7da44259366c6912665ed0914ee3cacc2 --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/include/wrapping_base64.h @@ -0,0 +1,41 @@ +/* + * Authors: + * Alexey Stratulat <alexey.stratulat@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * CellFrame https://cellframe.net + * Sources https://gitlab.demlabs.net/cellframe + * Copyright (c) 2017-2020 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ +#pragma once + +#include "Python.h" +#include "dap_enc_base64.h" +#include "dap_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +PyObject *dap_encode_base64_py(PyObject *self, PyObject *args); + +PyObject *dap_decode_base64_py(PyObject *self, PyObject *args); + +#ifdef __cplusplus +} +#endif diff --git a/cellframe-sdk-python/libdap-crypto-python/include/wrapping_cert.h b/cellframe-sdk-python/libdap-crypto-python/include/wrapping_cert.h new file mode 100644 index 0000000000000000000000000000000000000000..97e77964db37a3f8e4b24daae7af1d3d2d896285 --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/include/wrapping_cert.h @@ -0,0 +1,128 @@ +/* + * Authors: + * Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * CellFrame https://cellframe.net + * Sources https://gitlab.demlabs.net/cellframe + * Copyright (c) 2017-2020 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ +#pragma once +#define PY_SSIZE_T_CLEAN + +#include <Python.h> +#include "dap_common.h" +#include "dap_cert.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PyCryptoCert{ + PyObject_HEAD; + dap_cert_t * cert; +}PyCryptoCertObject; + +int dap_cert_init_py(); +void dap_cert_deinit_py(); + +PyObject* dap_cert_generate_py(PyObject *self, PyObject *args); +PyObject* dap_cert_dump_py(PyObject *self, PyObject *args); +PyObject* dap_cert_pkey_py(PyObject *self, PyObject *args); +PyObject* dap_cert_find_py(PyObject *self, PyObject *args); +PyObject* dap_cert_sign_py(PyObject *self, PyObject *args); +PyObject* dap_cert_cert_sign_add_py(PyObject *self, PyObject *args); +PyObject* dap_cert_cert_signs_py(PyObject *self, PyObject *args); +PyObject* dap_cert_compare_py(PyObject *self, PyObject *args); +PyObject* dap_cert_save_py(PyObject *self, PyObject *args); +PyObject* dap_cert_load_py(PyObject *self, PyObject *args); +void dap_cert_delete_py(PyObject *self); +PyObject* dap_cert_folder_add_py(PyObject *self, PyObject *args); +PyObject* dap_cert_folder_get_py(PyObject *self, PyObject *args); + +static PyMethodDef g_crypto_cert_methods_py[] = { + {"generate",dap_cert_generate_py , METH_VARARGS | METH_STATIC, "Generate from seed or randomly the new certificate"}, + {"find", dap_cert_find_py, METH_VARARGS | METH_STATIC, ""}, + {"folderAdd", dap_cert_folder_add_py, METH_VARARGS | METH_STATIC, "Add folders with .dcert files in it"}, + {"folderGet", dap_cert_folder_get_py, METH_VARARGS | METH_STATIC, "Get folder by number or the default one"}, + {"load", dap_cert_load_py, METH_VARARGS | METH_STATIC ,""}, + {"dump", dap_cert_dump_py, METH_VARARGS , ""}, + {"pkey", dap_cert_pkey_py, METH_VARARGS , ""}, + {"sign", dap_cert_sign_py, METH_VARARGS , ""}, + {"certSignAdd", dap_cert_cert_sign_add_py, METH_VARARGS, ""}, + {"certSigns", dap_cert_cert_signs_py, METH_VARARGS , ""}, + {"compare", dap_cert_compare_py, METH_VARARGS, ""}, + {"save", dap_cert_save_py, METH_VARARGS , "Save to the first directory in cert folders list"}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject g_crypto_cert_type_py = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Cert", /* tp_name */ + sizeof(PyCryptoCertObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + dap_cert_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 */ + "Crypto cert object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + g_crypto_cert_methods_py, /* 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 */ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 +}; + +#ifdef __cplusplus +} +#endif diff --git a/cellframe-sdk-python/libdap-crypto-python/include/wrapping_dap_enc_iaes.h b/cellframe-sdk-python/libdap-crypto-python/include/wrapping_dap_enc_iaes.h new file mode 100644 index 0000000000000000000000000000000000000000..1ab725f93e30d5462d554972df5137788db2ec76 --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/include/wrapping_dap_enc_iaes.h @@ -0,0 +1,55 @@ +/* + * Authors: + * Alexey Stratulat <alexey.stratulat@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * CellFrame https://cellframe.net + * Sources https://gitlab.demlabs.net/cellframe + * Copyright (c) 2017-2020 + * All rights reserved. + + This file is part of CellFrame SDK the open source project + + CellFrame SDK is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + CellFrame SDK is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any CellFrame SDK based project. If not, see <http://www.gnu.org/licenses/>. +*/ +#pragma once + +#include "Python.h" +#include "dap_enc_iaes.h" +#include "dap_common.h" +#include "libdap_crypto_key_python.h" + +#ifdef __cplusplus +extern "C" { +#endif + +PyObject* dap_enc_iaes_key_new_py(PyObject *self, PyObject *args); + +PyObject* dap_enc_iaes_key_delete_py(PyObject *self, PyObject *args); +PyObject* dap_enc_iaes_key_generate_py(PyObject *self, PyObject *args); + +PyObject* dap_enc_iaes256_calc_decode_size_py(PyObject *self, PyObject *args); +PyObject* dap_enc_iaes256_calc_encode_size_py(PyObject *self, PyObject *args); + +PyObject* dap_enc_iaes256_cbc_decrypt_py(PyObject *self, PyObject *args); //TODO +PyObject* dap_enc_iaes256_cbc_encrypt_py(PyObject *self, PyObject *args); //TODO + +// Writes result ( out ) in already allocated buffer +PyObject* dap_enc_iaes256_cbc_decrypt_fast_py(PyObject *self, PyObject *args); +// if "a_in size mod IAES_BLOCK_SIZE = 0" encryption will be faster +PyObject* dap_enc_iaes256_cbc_encrypt_fast_py(PyObject *self, PyObject *args); + +#ifdef __cplusplus +} +#endif + diff --git a/cellframe-sdk-python/libdap-crypto-python/include/wrapping_dap_enc_key.h b/cellframe-sdk-python/libdap-crypto-python/include/wrapping_dap_enc_key.h new file mode 100644 index 0000000000000000000000000000000000000000..9ccc8b6e946a96af8db42421dedb9b0a9ddcd22d --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/include/wrapping_dap_enc_key.h @@ -0,0 +1,63 @@ +/* + * Authors: + * Alexey Stratulat <alexey.stratulat@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * CellFrame https://cellframe.net + * Sources https://gitlab.demlabs.net/cellframe + * Copyright (c) 2017-2020 + * All rights reserved. + + This file is part of CellFrame SDK the open source project + + CellFrame SDK is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + CellFrame SDK is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any CellFrame SDK based project. If not, see <http://www.gnu.org/licenses/>. +*/ +#pragma once + +#include "dap_enc_key.h" +#include "Python.h" +#include "dap_common.h" +#include "libdap_crypto_key_python.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +PyObject* dap_enc_key_get_enc_size_py(PyObject *self, PyObject *args);//dap_enc_key_t * a_key, const size_t buf_in_size); -> size_t +PyObject* dap_enc_key_get_dec_size_py(PyObject *self, PyObject *args);//dap_enc_key_t * a_key, const size_t buf_in_size); -> size_t + + +// allocate memory for key struct +PyObject* dap_enc_key_new_py(PyObject *self, PyObject *args);//dap_enc_key_type_t a_key_type); ->dap_enc_key_t* + + +// default gen key +PyObject *dap_enc_key_new_generate_py(PyObject *self, PyObject *args);//dap_enc_key_type_t key_type, const void *kex_buf, ->dap_enc_key_t* + //size_t kex_size, const void* seed, + //size_t seed_size, size_t key_size); + +// update struct dap_enc_key_t after insert foreign keys +PyObject* dap_enc_key_update_py(PyObject *self, PyObject *args);//dap_enc_key_t *a_key); ->void + +// for asymmetric gen public key +PyObject *dap_enc_gen_pub_key_from_priv_py(PyObject *self, PyObject *args);//struct dap_enc_key *a_key, void **priv_key, size_t *alice_msg_len); ->dap_enc_key_t * + + +PyObject *dap_enc_gen_key_public_size_py(PyObject *self, PyObject *args);//dap_enc_key_t *a_key); ->size_t +PyObject *dap_enc_gen_key_public_py(PyObject *self, PyObject *args);//dap_enc_key_t *a_key, void * a_output); ->int + + +#ifdef __cplusplus +} +#endif diff --git a/cellframe-sdk-python/libdap-crypto-python/include/wrapping_dap_enc_oaes.h b/cellframe-sdk-python/libdap-crypto-python/include/wrapping_dap_enc_oaes.h new file mode 100644 index 0000000000000000000000000000000000000000..8d324e6d049f621774f124f78f3bea26461068ab --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/include/wrapping_dap_enc_oaes.h @@ -0,0 +1,58 @@ +/* + * Authors: + * Alexey Stratulat <alexey.stratulat@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * CellFrame https://cellframe.net + * Sources https://gitlab.demlabs.net/cellframe + * Copyright (c) 2017-2020 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ + +#pragma once + +#include "Python.h" +#include "dap_enc_oaes.h" +#include "dap_common.h" +#include "libdap_crypto_key_python.h" + +#ifdef __cplusplus +extern "C" { +#endif + +PyObject *dap_enc_oaes_key_new_py(PyObject *self, PyObject *args); +PyObject *dap_enc_oaes_key_delete_py(PyObject *self, PyObject *args); +PyObject *dap_enc_oaes_key_generate_py(PyObject *self, PyObject *args); + +PyObject *dap_enc_oaes_calc_decode_size_py(PyObject *self, PyObject *args); +PyObject *dap_enc_oaes_calc_encode_size_py(PyObject *self, PyObject *args); + +PyObject *dap_enc_oaes_decrypt_py(PyObject *self, PyObject *args); +PyObject *dap_enc_oaes_encrypt_py(PyObject *self, PyObject *args); + +// Writes result ( out ) in already allocated buffer +PyObject *dap_enc_oaes_decrypt_fast_py(PyObject *self, PyObject *args); +// Writes result ( out ) in already allocated buffer +PyObject *dap_enc_oaes_encrypt_fast_py(PyObject *self, PyObject *args); + + + +#ifdef __cplusplus +} +#endif + + diff --git a/cellframe-sdk-python/libdap-crypto-python/include/wrapping_dap_hash.h b/cellframe-sdk-python/libdap-crypto-python/include/wrapping_dap_hash.h new file mode 100644 index 0000000000000000000000000000000000000000..d161aae3d66e2fca97716efe20eebd04c7453036 --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/include/wrapping_dap_hash.h @@ -0,0 +1,159 @@ +/* + * Authors: + * Alexey Stratulat <alexey.stratulat@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * CellFrame https://cellframe.net + * Sources https://gitlab.demlabs.net/cellframe + * Copyright (c) 2017-2020 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ + +#pragma once +#include <Python.h> +#include "dap_hash.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PyDapHashType{ + PyObject_HEAD + dap_hash_type_t hash_type; +}PyDapHashTypeObject; + +PyObject *DAP_HASH_TYPE_KECCAK_PY(); +PyObject *DAP_HASH_TYPE_SLOW_0_PY(); + +static PyMethodDef DapHashTypeMethods[] = { + {"DAP_HASH_TYPE_KECCAK", (PyCFunction)DAP_HASH_TYPE_KECCAK_PY, METH_NOARGS | METH_STATIC, ""}, + {"DAP_HASH_TYPE_SLOW_0", (PyCFunction)DAP_HASH_TYPE_SLOW_0_PY, METH_NOARGS | METH_STATIC, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapHashTypeObject_DapChainHashTypeObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.HashType", /* tp_name */ + sizeof(PyDapHashTypeObject), /* 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 */ + "Hash type object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapHashTypeMethods, /* 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 */ +}; + +/*=================*/ + +/* Chain hash fast */ +typedef struct PyDapHashFast{ + PyObject_HEAD + dap_chain_hash_fast_t *hash_fast; +}PyDapHashFastObject; + +PyObject *dap_chain_str_to_hash_fast_py(PyObject *self, PyObject *args); +PyObject *dap_hash_fast_py(PyObject *self, PyObject *args); +PyObject *dap_hash_fast_compare_py(PyObject *self, PyObject *args); +PyObject *dap_hash_fast_is_blank_py(PyObject *self, PyObject *args); +PyObject *dap_chain_hash_fast_to_str_py(PyObject *self, PyObject *args); +PyObject *dap_chain_hash_fast_to_str_new_py(PyObject *self, PyObject *args); + +static PyMethodDef DapHashFastMethods[] = { + {"strToHashFast", (PyCFunction)dap_chain_str_to_hash_fast_py, METH_VARARGS | METH_STATIC, ""}, + {"hashFast", (PyCFunction)dap_hash_fast_py, METH_VARARGS, ""}, + {"compare", (PyCFunction)dap_hash_fast_compare_py, METH_VARARGS | METH_STATIC, ""}, + {"isBlank", (PyCFunction)dap_hash_fast_is_blank_py, METH_VARARGS, ""}, + {"toStr", (PyCFunction)dap_chain_hash_fast_to_str_py, METH_VARARGS, ""}, + {"toStrNew", (PyCFunction)dap_chain_hash_fast_to_str_new_py, METH_VARARGS, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapHashFastObject_DapHashFastObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.HashFast", /* tp_name */ + sizeof(PyDapHashFastObject), /* 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 */ + "Hash fast object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapHashFastMethods, /* 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 diff --git a/cellframe-sdk-python/libdap-crypto-python/include/wrapping_dap_pkey.h b/cellframe-sdk-python/libdap-crypto-python/include/wrapping_dap_pkey.h new file mode 100644 index 0000000000000000000000000000000000000000..088e244db134d5b7456cf9684d1741bd21bc40b0 --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/include/wrapping_dap_pkey.h @@ -0,0 +1,105 @@ +#ifndef _WRAPPING_DAP_PKEY_ +#define _WRAPPING_DAP_PKEY_ + +#include <Python.h> +#include "dap_pkey.h" + +typedef struct PyDapPkeyType{ + PyObject_HEAD + dap_pkey_type_t *pkey_type; +}PyDapPkeyTypeObject; + +static PyTypeObject DapPkeyTypeObject_DapPkeyTypeObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.PkeyType", /* tp_name */ + sizeof(PyDapPkeyTypeObject),/* 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 */ + "Pkey type object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* 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 */ +}; + +/* ----------------------------------- */ + +typedef struct PyDapPkey{ + PyObject_HEAD + dap_pkey_t *pkey; +}PyDapPkeyObject; + +static PyTypeObject DapPkeyObject_DapPkeyObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Pkey", /* tp_name */ + sizeof(PyDapPkeyObject),/* 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 */ + "Pkey object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* 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 */ +}; + +/* ----------------------------------- */ + +#endif //_WRAPPING_DAP_PKEY_ diff --git a/cellframe-sdk-python/libdap-crypto-python/include/wrapping_dap_sign.h b/cellframe-sdk-python/libdap-crypto-python/include/wrapping_dap_sign.h new file mode 100644 index 0000000000000000000000000000000000000000..1c9442099e69e707c50bc471b6c77b2514281f40 --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/include/wrapping_dap_sign.h @@ -0,0 +1,54 @@ +#ifndef _WRAPPING_DAP_SIGN_ +#define _WRAPPING_DAP_SIGN_ + +#include <Python.h> +#include "dap_sign.h" + +typedef struct PyDapSignType{ + PyObject_HEAD + dap_sign_type_t *sign_type; +}PyDapSignTypeObject; + +static PyTypeObject DapSignTypeObject_DapSignTypeObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.SignType", /* tp_name */ + sizeof(PyDapSignTypeObject),/* 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 */ + "Sign type object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* 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 */ +}; + +#endif // _WRAPPING_DAP_SIGN_ diff --git a/cellframe-sdk-python/libdap-crypto-python/src/libdap-crypto-python.c b/cellframe-sdk-python/libdap-crypto-python/src/libdap-crypto-python.c new file mode 100644 index 0000000000000000000000000000000000000000..d3c0e9232c498477bd8e0a51dc54f21bc66731c8 --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/src/libdap-crypto-python.c @@ -0,0 +1,47 @@ +/* + * Authors: + * Alexey Stratulat <alexey.stratulat@demlabs.net> + * Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * CellFrame https://cellframe.net + * Sources https://gitlab.demlabs.net/cellframe + * Copyright (c) 2017-2020 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "libdap-crypto-python.h" + +#define LOG_TAG "dap_crypto_python" + +int dap_crypto_init(void){ + if(dap_enc_init()!=0){ + log_it(L_CRITICAL,"Can't init encryption module"); + return -1; + } + if(dap_enc_key_init()!=0){ + log_it(L_CRITICAL,"Can't init encryption key module"); + return -2; + } + PyCryptoKeyObject_PyCryptoKeyType.tp_new = PyType_GenericNew; + return 0; +} + +void dap_crypto_deinit(void){ + dap_enc_key_deinit(); + dap_enc_deinit(); +} diff --git a/cellframe-sdk-python/libdap-crypto-python/src/libdap_crypto_key_type_python.c b/cellframe-sdk-python/libdap-crypto-python/src/libdap_crypto_key_type_python.c new file mode 100644 index 0000000000000000000000000000000000000000..f0ac5f0f660915b408a174d772f51eb78f50bd20 --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/src/libdap_crypto_key_type_python.c @@ -0,0 +1,56 @@ +#include "libdap_crypto_key_type_python.h" + +PyObject *get_ENC_KEY_TYPE_IAES(){ + return PyLong_FromLong(DAP_ENC_KEY_TYPE_IAES); +} +PyObject *get_ENC_KEY_TYPE_OAES(){ + return PyLong_FromLong(DAP_ENC_KEY_TYPE_OAES); +} +PyObject *get_ENC_KEY_TYPE_RLWE_NEWHOPE(){ + return PyLong_FromLong(DAP_ENC_KEY_TYPE_RLWE_NEWHOPE); +} +PyObject *get_ENC_KEY_TYPE_SIDH_CLN16(){ + return PyLong_FromLong(DAP_ENC_KEY_TYPE_SIDH_CLN16); +} +PyObject *get_ENC_KEY_TYPE_DEFEO(){ + return PyLong_FromLong(DAP_ENC_KEY_TYPE_DEFEO); +} +PyObject *get_ENC_KEY_TYPE_MSRLN(){ + return PyLong_FromLong(DAP_ENC_KEY_TYPE_MSRLN); +} +PyObject *get_ENC_KEY_TYPE_MSRLN16(){ + return PyLong_FromLong(DAP_ENC_KEY_TYPE_RLWE_MSRLN16); +} +PyObject *get_ENC_KEY_TYPE_RLWE_BCNS15(){ + return PyLong_FromLong(DAP_ENC_KEY_TYPE_RLWE_BCNS15); +} +PyObject *get_ENC_KEY_TYPE_LWE_FRODO(){ + return PyLong_FromLong(DAP_ENC_KEY_TYPE_LWE_FRODO); +} +PyObject *get_ENC_KEY_TYPE_SIDH_IQC_REF(){ + return PyLong_FromLong(DAP_ENC_KEY_TYPE_SIDH_IQC_REF); +} +PyObject *get_ENC_KEY_TYPE_CODE_MCBITS(){ + return PyLong_FromLong(DAP_ENC_KEY_TYPE_CODE_MCBITS); +} +PyObject *get_ENC_KEY_TYPE_NTRU(){ + return PyLong_FromLong(DAP_ENC_KEY_TYPE_NTRU); +} +PyObject *get_ENC_KEY_TYPE_MLWE_KYBER(){ + return PyLong_FromLong(DAP_ENC_KEY_TYPE_MLWE_KYBER); +} +PyObject *get_ENC_KEY_TYPE_SIG_PICNIC(){ + return PyLong_FromLong(DAP_ENC_KEY_TYPE_SIG_PICNIC); +} +PyObject *get_ENC_KEY_TYPE_SIG_BLISS(){ + return PyLong_FromLong(DAP_ENC_KEY_TYPE_SIG_BLISS); +} +PyObject *get_ENC_KEY_TYPE_SIG_TESLA(){ + return PyLong_FromLong(DAP_ENC_KEY_TYPE_SIG_TESLA); +} +PyObject *get_ENC_KEY_TYPE_SIG_DILITHIUM(){ + return PyLong_FromLong(DAP_ENC_KEY_TYPE_SIG_DILITHIUM); +} +PyObject *get_ENC_KEY_TYPE_NULL(){ + return PyLong_FromLong(DAP_ENC_KEY_TYPE_NULL); +} diff --git a/cellframe-sdk-python/libdap-crypto-python/src/wrapping_base58.c b/cellframe-sdk-python/libdap-crypto-python/src/wrapping_base58.c new file mode 100644 index 0000000000000000000000000000000000000000..738dd2ce19e7a26f3c48c6c1a364fec989a621dc --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/src/wrapping_base58.c @@ -0,0 +1,24 @@ +#include "wrapping_base58.h" + +PyObject *dap_encode_base58_py(PyObject *self, PyObject *args){ + PyBytesObject *obj; + if (!PyArg_ParseTuple(args, "S", &obj)){ + return NULL; + } + void *in_void = PyBytes_AsString((PyObject*)obj); + size_t pySize = (size_t)PyBytes_GET_SIZE(obj); + char result[DAP_ENC_BASE58_ENCODE_SIZE(pySize)]; + dap_enc_base58_encode(in_void, pySize, result); + return Py_BuildValue("s", result); +} + +PyObject *dap_decode_base58_py(PyObject *self, PyObject *args){ + const char *in_str; + if (!PyArg_ParseTuple(args, "s", &in_str)){ + return NULL; + } + void *res = DAP_NEW_SIZE(void*, DAP_ENC_BASE58_DECODE_SIZE(strlen(in_str))); + size_t decrypted_size = dap_enc_base58_decode(in_str, res); + PyBytesObject *return_object = (PyBytesObject*)PyBytes_FromStringAndSize(res, (Py_ssize_t)decrypted_size); + return Py_BuildValue("O", return_object); +} diff --git a/cellframe-sdk-python/libdap-crypto-python/src/wrapping_base64.c b/cellframe-sdk-python/libdap-crypto-python/src/wrapping_base64.c new file mode 100644 index 0000000000000000000000000000000000000000..53d562025ec07ebb6e240d67e2b095be02f97ba0 --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/src/wrapping_base64.c @@ -0,0 +1,32 @@ +#include "wrapping_base64.h" + + PyObject *dap_encode_base64_py(PyObject *self, PyObject *args){ + PyObject *in_data; + short int l_dap_enc_data_type; + if (!PyArg_ParseTuple(args, "S|h", &in_data, &l_dap_enc_data_type)){ + return NULL; + } + if (l_dap_enc_data_type < 1 || l_dap_enc_data_type > 2){ + return NULL; + } + void *in_void = PyBytes_AsString((PyObject*)in_data); + size_t pySize = (size_t)PyBytes_GET_SIZE(in_data); + char result[DAP_ENC_BASE64_ENCODE_SIZE(pySize)]; + dap_enc_base64_encode(in_void, pySize, result, l_dap_enc_data_type); + return Py_BuildValue("s", result); +} + + PyObject *dap_decode_base64_py(PyObject *self, PyObject *args){ + const char *in_str; + short int l_dap_enc_data_type=1; + if (!PyArg_ParseTuple(args, "s|h", &in_str, &l_dap_enc_data_type)) { + return NULL; + } + if (l_dap_enc_data_type < 1 || l_dap_enc_data_type > 2){ + return NULL; + } + void *res = DAP_NEW_SIZE(void*, DAP_ENC_BASE64_ENCODE_SIZE(strlen(in_str))); + size_t decrypted_size = dap_enc_base64_decode(in_str, strlen(in_str), res, l_dap_enc_data_type); + PyBytesObject *return_object = (PyBytesObject*)PyBytes_FromStringAndSize(res, (Py_ssize_t)decrypted_size); + return Py_BuildValue("O", return_object); +} diff --git a/cellframe-sdk-python/libdap-crypto-python/src/wrapping_cert.c b/cellframe-sdk-python/libdap-crypto-python/src/wrapping_cert.c new file mode 100644 index 0000000000000000000000000000000000000000..ff401fa87502206db4f3bbff67dac9b6f9cd6635 --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/src/wrapping_cert.c @@ -0,0 +1,189 @@ +/* + * Authors: + * Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * CellFrame https://cellframe.net + * Sources https://gitlab.demlabs.net/cellframe + * Copyright (c) 2017-2020 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ +#include "dap_common.h" +#include "dap_cert.h" +#include "dap_strfuncs.h" + +#include "wrapping_cert.h" +#include "libdap_crypto_key_type_python.h" +#define LOG_TAG "wrapping_cert" + + +PyObject* dap_cert_generate_py(PyObject *self, PyObject *args) +{ + const char *l_cert_name = NULL; + const char * l_seed = NULL; + + const char *l_arg_cert_name = NULL; + dap_enc_key_type_t l_arg_cert_key_type = DAP_ENC_KEY_TYPE_SIG_DILITHIUM; + const char *l_arg_seed_string = NULL; + + if (!PyArg_ParseTuple(args, "sis", &l_arg_cert_name, &l_arg_cert_key_type, &l_arg_seed_string) ){ + PyErr_SetString(PyExc_SyntaxError, "Wrong arguments list in function call"); + return NULL; + } + + if (l_arg_cert_name != 0) + l_cert_name = l_arg_cert_name; + else { + PyErr_SetString(PyExc_SyntaxError, "Certificate name is NULL"); + return NULL; + } + + if (l_arg_seed_string != 0) + l_seed = l_arg_seed_string; + + PyCryptoCertObject *obj_cert = (PyCryptoCertObject*)_PyObject_New(&g_crypto_cert_type_py); + obj_cert->cert = l_seed ? dap_cert_generate_mem_with_seed( l_cert_name, l_arg_cert_key_type, l_seed, strlen(l_seed) ) + :dap_cert_generate_mem( l_cert_name,l_arg_cert_key_type ); + return Py_BuildValue("O", (PyObject*)obj_cert); +} + +PyObject* dap_cert_dump_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject* dap_cert_pkey_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject* dap_cert_find_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject* dap_cert_sign_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject* dap_cert_cert_sign_add_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject* dap_cert_cert_signs_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject* dap_cert_compare_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject* dap_cert_save_py(PyObject *self, PyObject *args) +{ + (void) args; + int res = dap_cert_save_to_folder(((PyCryptoCertObject*)self)->cert, dap_cert_get_folder(0) ); + return PyLong_FromLong(res); +} + +PyObject* dap_cert_load_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject* dap_cert_close_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + + +void dap_cert_delete_py(PyObject *self) +{ + PyCryptoCertObject *certObject = (PyCryptoCertObject *)self; + dap_cert_delete( certObject->cert ); + Py_TYPE(certObject)->tp_free((PyObject*)certObject); +} + + +PyObject* dap_cert_folder_add_py(PyObject *self, PyObject *args) +{ + (void) self; + (void) args; + /// TODO: Implement it! + PyErr_SetString(PyExc_TypeError, "Unimplemented function"); + return NULL; +} + +PyObject* dap_cert_folder_get_py(PyObject *self, PyObject *args) +{ + (void)self; + const char *a_folder_path; + if(!PyArg_ParseTuple(args, "s", &a_folder_path)) + return NULL; + dap_cert_add_folder(a_folder_path); + return PyLong_FromLong(0); +} + +int dap_cert_init_py(void) +{ + return dap_cert_init(); +} + +void dap_cert_deinit_py(void) +{ + dap_cert_deinit(); +} + diff --git a/cellframe-sdk-python/libdap-crypto-python/src/wrapping_dap_enc_iaes.c b/cellframe-sdk-python/libdap-crypto-python/src/wrapping_dap_enc_iaes.c new file mode 100644 index 0000000000000000000000000000000000000000..51cbbc22bb55afe647bb0e06d213f949bc072ded --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/src/wrapping_dap_enc_iaes.c @@ -0,0 +1,141 @@ +/* + * Authors: + * Alexey Stratulat <alexey.stratulat@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * CellFrame https://cellframe.net + * Sources https://gitlab.demlabs.net/cellframe + * Copyright (c) 2017-2020 + * All rights reserved. + + This file is part of CellFrame SDK the open source project + + CellFrame SDK is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + CellFrame SDK is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any CellFrame SDK based project. If not, see <http://www.gnu.org/licenses/>. +*/ +#include "wrapping_dap_enc_iaes.h" + +#define LOG_TAG "wrapping-dap-enc-iaes" + + +PyObject* dap_enc_iaes_key_new_py(PyObject *self, PyObject *args){ + PyObject *obj_key; + if (PyArg_ParseTuple(args, "O", &obj_key)){ + return NULL; + } + dap_enc_aes_key_new(((PyCryptoKeyObject*)obj_key)->key); + return PyLong_FromLong(0); +} + +PyObject* dap_enc_iaes_key_delete_py(PyObject *self, PyObject *args){ + PyObject *obj_key; + if (PyArg_ParseTuple(args, "O", &obj_key)){ + return NULL; + } + dap_enc_aes_key_delete(((PyCryptoKeyObject*)obj_key)->key); + return PyLong_FromLong(0); +} + +PyObject* dap_enc_iaes_key_generate_py(PyObject *self, PyObject *args){ + // TODO + PyObject* in_key; + PyBytesObject *in_kex_buf; + size_t in_kex_size; + PyBytesObject *in_seed; + size_t in_seed_size; + if (PyArg_ParseTuple(args, "O|S|n|S|n", &in_key, &in_kex_buf, &in_kex_size, &in_seed, &in_seed_size)){ + return NULL; + } + size_t key_size = sizeof(((PyCryptoKeyObject*)in_key)->key); + void* kex_buf = NULL; + PyBytes_AsStringAndSize((PyObject*)in_kex_buf, kex_buf, (Py_ssize_t*)in_kex_size); + void* seed_buf = NULL; + PyBytes_AsStringAndSize((PyObject*)in_seed, seed_buf, (Py_ssize_t*)in_seed_size); + dap_enc_aes_key_generate(((PyCryptoKeyObject*)in_key)->key, kex_buf, in_kex_size, seed_buf, in_seed_size, key_size); + return PyLong_FromLong(0); +} + +PyObject* dap_enc_iaes256_calc_encode_size_py(PyObject *self, PyObject *args) +{ + UNUSED(self); + size_t size; + if (!PyArg_ParseTuple(args, "n", &size)){ + return NULL; + } + size_t new_size = dap_enc_iaes256_calc_encode_size(size); + return PyLong_FromSize_t(new_size); +} + + +PyObject* dap_enc_iaes256_calc_decode_size_py(PyObject *self, PyObject *args) +{ + UNUSED(self); + size_t size; + if (!PyArg_ParseTuple(args, "n", &size)){ + return NULL; + } + size_t new_size = dap_enc_iaes256_calc_decode_max_size(size); + return PyLong_FromSize_t(new_size); +} + +PyObject* dap_enc_iaes256_cbc_decrypt_py(PyObject *self, PyObject *args) +{ + UNUSED(self); + UNUSED(args); + + //TODO + return PyLong_FromLong(0); +} +PyObject* dap_enc_iaes256_cbc_encrypt_py(PyObject *self, PyObject *args) +{ + UNUSED(self); + UNUSED(args); + //TODO + return PyLong_FromLong(0); +} + +// Writes result ( out ) in already allocated buffer +PyObject* dap_enc_iaes256_cbc_decrypt_fast_py(PyObject *self, PyObject *args) +{ + UNUSED(self); + PyObject* in_key; + PyBytesObject *a_in; + size_t a_in_size; + size_t buf_out_size; + if (!PyArg_ParseTuple(args, "O|S|n|n", &in_key, &a_in, &a_in_size, &buf_out_size)){ + return NULL; + } + void *in = PyBytes_AsString((PyObject*)a_in); + void *out = DAP_NEW_SIZE(void*, buf_out_size); + size_t res_denc_size = dap_enc_iaes256_cbc_decrypt_fast(((PyCryptoKeyObject*)in_key)->key, in, a_in_size, out, buf_out_size); + PyBytesObject *bytes_out = (PyBytesObject*)PyBytes_FromStringAndSize(out, (Py_ssize_t)res_denc_size); + return Py_BuildValue("S", bytes_out); +} + +// if "a_in size mod IAES_BLOCK_SIZE = 0" encryption will be faster +PyObject* dap_enc_iaes256_cbc_encrypt_fast_py(PyObject *self, PyObject *args) +{ + UNUSED(self); + PyObject *in_key; + PyBytesObject *a_in; + size_t a_in_size; + size_t buf_out_size; + if (!PyArg_ParseTuple(args, "O|S|n|n", &in_key, &a_in, &a_in_size, &buf_out_size)){ + return NULL; + } + void *in = PyBytes_AsString((PyObject*)a_in); + void *out = DAP_NEW_SIZE(void*, buf_out_size); + size_t res_enc_size = dap_enc_iaes256_cbc_encrypt_fast(((PyCryptoKeyObject*)in_key)->key, in, a_in_size, out, buf_out_size); + PyBytesObject *bytes_out = (PyBytesObject*)PyBytes_FromStringAndSize(out, (Py_ssize_t)res_enc_size); + return Py_BuildValue("S", bytes_out); +} + diff --git a/cellframe-sdk-python/libdap-crypto-python/src/wrapping_dap_enc_key.c b/cellframe-sdk-python/libdap-crypto-python/src/wrapping_dap_enc_key.c new file mode 100644 index 0000000000000000000000000000000000000000..19f11f9de00b3f83c7a93d8b15889635413d5d47 --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/src/wrapping_dap_enc_key.c @@ -0,0 +1,145 @@ +/* + * Authors: + * Alexey Stratulat <alexey.stratulat@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * CellFrame https://cellframe.net + * Sources https://gitlab.demlabs.net/cellframe + * Copyright (c) 2017-2020 + * All rights reserved. + + This file is part of CellFrame SDK the open source project + + CellFrame SDK is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + CellFrame SDK is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any CellFrame SDK based project. If not, see <http://www.gnu.org/licenses/>. +*/ +#include "wrapping_dap_enc_key.h" + +#define LOG_TAG "wrapping-dap-enc-key" + +PyObject* dap_enc_key_get_enc_size_py(PyObject *self, PyObject *args){ + PyObject *in_key; + size_t buff_in_size; + if (!PyArg_ParseTuple(args, "O|i", &in_key, &buff_in_size)){ + return NULL; + } +// dap_enc_key_t *key = key_list_get_key(keys, key_id); +// if (key == NULL) +// return NULL; + size_t size_buff = dap_enc_key_get_enc_size(((PyCryptoKeyObject*)in_key)->key, buff_in_size); + if (size_buff == 0) + return NULL; + return PyLong_FromSize_t(size_buff); +} + +PyObject* dap_enc_key_get_dec_size_py(PyObject *self, PyObject *args){ + PyObject *in_key; + size_t buff_in_size; + if (!PyArg_ParseTuple(args, "O|i", &in_key, &buff_in_size)){ + return NULL; + } +// dap_enc_key_t *key = key_list_get_key(keys, key_id); +// if (key == NULL) +// return NULL; + size_t size_buff = dap_enc_key_get_dec_size(((PyCryptoKeyObject*)in_key)->key, buff_in_size); + if (size_buff == 0) + return NULL; + return PyLong_FromSize_t(size_buff); +} + +// allocate memory for key struct +PyObject* dap_enc_key_new_py(PyObject *self, PyObject *args){ + uint8_t type_key; + if(!PyArg_ParseTuple(args, "h", &type_key)){ + return NULL; + } + if (type_key > 16){ + return PyLong_FromLong(-1); + } + dap_enc_key_t *new_key = dap_enc_key_new(type_key); + PyObject *obj = _PyObject_New(&PyCryptoKeyObject_PyCryptoKeyType); + ((PyCryptoKeyObject*)obj)->key = new_key; + return Py_BuildValue("O", obj); +} + +/// default gen key +PyObject *dap_enc_key_new_generate_py(PyObject *self, PyObject *args){ + uint8_t in_type_key; + PyBytesObject *in_kex_buf; + size_t in_kex_size; + PyBytesObject *in_seed; + size_t in_seed_size; + size_t in_key_size; + if (!PyArg_ParseTuple(args, "h|S|n|S|n|n", &in_type_key, &in_kex_buf, &in_kex_size, &in_seed, + &in_seed_size, &in_key_size)){ + return NULL; + } + if (in_type_key > 16){ + return PyLong_FromLong(-1); + } + void *kex_buf = NULL; + void *seed = NULL; + if (in_kex_size != 0) + kex_buf = PyBytes_AsString((PyObject*)in_kex_buf); + if (in_seed_size != 0) + seed = PyBytes_AsString((PyObject*)in_seed); + PyCryptoKeyObject *obj_key = (PyCryptoKeyObject*)_PyObject_New(&PyCryptoKeyObject_PyCryptoKeyType); + obj_key->key = dap_enc_key_new_generate(in_type_key, kex_buf, in_kex_size, seed, in_seed_size, in_key_size); + return Py_BuildValue("O", (PyObject*)obj_key); +} + +// update struct dap_enc_key_t after insert foreign keys +PyObject* dap_enc_key_update_py(PyObject *self, PyObject *args){ + PyObject *in_key; + if (!PyArg_ParseTuple(args, "O", &in_key)){ + return NULL; + } +// dap_enc_key_t *key = key_list_get_key(keys, key_id); +// if (key == NULL) { +// return NULL; +// } + dap_enc_key_update(((PyCryptoKeyObject*)in_key)->key); + return PyLong_FromLong(0); +} + +// for asymmetric gen public key +PyObject *dap_enc_gen_pub_key_from_priv_py(PyObject *self, PyObject *args){ //NOTE libdap-crypto/src/libdap-crypto.c + return PyLong_FromLong(0); +} + + +PyObject *dap_enc_gen_key_public_size_py(PyObject *self, PyObject *args){ + PyObject *in_key; + if (PyArg_ParseTuple(args, "h", &in_key)){ + return NULL; + } +// dap_enc_key_t *key = key_list_get_key(keys, key_id); +// if (key == NULL){ +// return NULL; +// } + size_t size = dap_enc_gen_key_public_size(((PyCryptoKeyObject*)in_key)->key); + return PyLong_FromSize_t(size); +} + +PyObject *dap_enc_gen_key_public_py(PyObject *self, PyObject *args){ + PyObject *in_key; + PyObject *obj; + if (PyArg_ParseTuple(args, "O|O", &in_key, &obj)){ + return NULL; + } +// dap_enc_key_t *key = key_list_get_key(keys, key_id); +// if (key == NULL){ +// return NULL; +// } + int size = dap_enc_gen_key_public(((PyCryptoKeyObject*)in_key)->key, obj); + return PyLong_FromLong(size); +} diff --git a/cellframe-sdk-python/libdap-crypto-python/src/wrapping_dap_enc_oaes.c b/cellframe-sdk-python/libdap-crypto-python/src/wrapping_dap_enc_oaes.c new file mode 100644 index 0000000000000000000000000000000000000000..e3ed4bd9ade18d5f8f83d712d835b83a7095e0a8 --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/src/wrapping_dap_enc_oaes.c @@ -0,0 +1,93 @@ +#include "wrapping_dap_enc_oaes.h" + + +PyObject *dap_enc_oaes_key_new_py(PyObject *self, PyObject *args){ + PyObject *in_key; + if (PyArg_ParseTuple(args, "O", &in_key)){ + return NULL; + } + dap_enc_oaes_key_new(((PyCryptoKeyObject*)in_key)->key); + return PyLong_FromLong(0); +} +PyObject *dap_enc_oaes_key_delete_py(PyObject *self, PyObject *args){ + PyObject *in_key; + if (PyArg_ParseTuple(args, "O", &in_key)){ + return NULL; + } + dap_enc_oaes_key_delete(((PyCryptoKeyObject*)in_key)->key); + return PyLong_FromLong(0); +} +PyObject *dap_enc_oaes_key_generate_py(PyObject *self, PyObject *args){ + PyObject *in_key; + PyBytesObject *in_kex_buf; + size_t in_kex_size; + PyBytesObject *in_seed; + size_t in_seed_size; + if (PyArg_ParseTuple(args, "O|S|n|S|n", &in_key, &in_kex_buf, &in_kex_size, &in_seed, &in_seed_size)){ + return NULL; + } + size_t key_size = sizeof(((PyCryptoKeyObject*)in_key)->key); + void* kex_buf = NULL; + PyBytes_AsStringAndSize((PyObject*)in_kex_buf, kex_buf, (Py_ssize_t*)in_kex_size); + void* seed_buf = NULL; + PyBytes_AsStringAndSize((PyObject*)in_seed, seed_buf, (Py_ssize_t*)in_seed_size); + dap_enc_oaes_key_generate(((PyCryptoKeyObject*)in_key)->key, kex_buf, in_kex_size, seed_buf, in_seed_size, key_size); + return PyLong_FromLong(0); +} + +PyObject *dap_enc_oaes_calc_decode_size_py(PyObject *self, PyObject *args){ + size_t size; + if (!PyArg_ParseTuple(args, "n", &size)){ + return NULL; + } + size_t new_size = dap_enc_oaes_calc_decode_size(size); + return PyLong_FromSize_t(new_size); +} +PyObject *dap_enc_oaes_calc_encode_size_py(PyObject *self, PyObject *args){ + size_t size; + if (!PyArg_ParseTuple(args, "n", &size)){ + return NULL; + } + size_t new_size = dap_enc_oaes_calc_encode_size(size); + return PyLong_FromSize_t(new_size); +} + +PyObject *dap_enc_oaes_decrypt_py(PyObject *self, PyObject *args){ + //TODO + return PyLong_FromLong(0); +} +PyObject *dap_enc_oaes_encrypt_py(PyObject *self, PyObject *args){ + //TODO + return PyLong_FromLong(0); +} + +// Writes result ( out ) in already allocated buffer +PyObject *dap_enc_oaes_decrypt_fast_py(PyObject *self, PyObject *args){ + PyObject *in_key; + PyBytesObject *a_in; + size_t a_in_size; + size_t buf_out_size; + if (!PyArg_ParseTuple(args, "O|S|n|n", &in_key, &a_in, &a_in_size, &buf_out_size)){ + return NULL; + } + void *in = PyBytes_AsString((PyObject*)a_in); + void *out = DAP_NEW_SIZE(void*, buf_out_size); + size_t res_denc_size = dap_enc_oaes_decrypt_fast(((PyCryptoKeyObject*)in_key)->key, in, a_in_size, out, buf_out_size); + PyBytesObject *bytes_out = (PyBytesObject*)PyBytes_FromStringAndSize(out, (Py_ssize_t)res_denc_size); + return Py_BuildValue("S", bytes_out); +} +// Writes result ( out ) in already allocated buffer +PyObject *dap_enc_oaes_encrypt_fast_py(PyObject *self, PyObject *args){ + PyObject *in_key; + PyBytesObject *a_in; + size_t a_in_size; + size_t buf_out_size; + if (!PyArg_ParseTuple(args, "O|S|n|n", &in_key, &a_in, &a_in_size, &buf_out_size)){ + return NULL; + } + void *in = PyBytes_AsString((PyObject*)a_in); + void *out = DAP_NEW_SIZE(void*, buf_out_size); + size_t res_enc_size = dap_enc_oaes_encrypt_fast(((PyCryptoKeyObject*)in_key)->key, in, a_in_size, out, buf_out_size); + PyBytesObject *bytes_out = (PyBytesObject*)PyBytes_FromStringAndSize(out, (Py_ssize_t)res_enc_size); + return Py_BuildValue("S", bytes_out); +} diff --git a/cellframe-sdk-python/libdap-crypto-python/src/wrapping_dap_hash.c b/cellframe-sdk-python/libdap-crypto-python/src/wrapping_dap_hash.c new file mode 100644 index 0000000000000000000000000000000000000000..5a1bab5ad6c068a7b7e1f1af917e8e3383335efe --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/src/wrapping_dap_hash.c @@ -0,0 +1,68 @@ +#include "wrapping_dap_hash.h" + +PyObject *DAP_HASH_TYPE_KECCAK_PY(){ + PyObject *obj = _PyObject_New(&DapHashTypeObject_DapChainHashTypeObjectType); + ((PyDapHashTypeObject*)obj)->hash_type = DAP_HASH_TYPE_KECCAK; + return Py_BuildValue("O", obj); +} +PyObject *DAP_HASH_TYPE_SLOW_0_PY(){ + PyObject *obj = _PyObject_New(&DapHashTypeObject_DapChainHashTypeObjectType); + ((PyDapHashTypeObject*)obj)->hash_type = DAP_HASH_TYPE_SLOW_0; + return Py_BuildValue("O", obj); +} + +PyObject *dap_chain_str_to_hash_fast_py(PyObject *self, PyObject *args){ + const char *hash_str; + PyObject *obj_hash_fast; + if (!PyArg_ParseTuple(args, "s|O", &hash_str, &obj_hash_fast)) + return NULL; + int res = dap_chain_str_to_hash_fast(hash_str, ((PyDapHashFastObject*)obj_hash_fast)->hash_fast); + return Py_BuildValue("nO", res, obj_hash_fast); +} + +PyObject *dap_hash_fast_py(PyObject *self, PyObject *args){ + PyObject *obj_bytes; + size_t data_in_size; + if (!PyArg_ParseTuple(args, "O|n", &obj_bytes, &data_in_size)) + return NULL; + const void *bytes = (void*)PyBytes_AsString(obj_bytes); + bool res = dap_hash_fast(bytes, data_in_size, ((PyDapHashFastObject*)self)->hash_fast); + if (res) + return Py_BuildValue("O", Py_True); + else + return Py_BuildValue("O", Py_False); +} + +PyObject *dap_hash_fast_compare_py(PyObject *self, PyObject *args){ + PyObject *hash1; + PyObject *hash2; + if (!PyArg_ParseTuple(args, "O|O", &hash1, &hash2)) + return NULL; + bool res = dap_hash_fast_compare(((PyDapHashFastObject*)hash1)->hash_fast, ((PyDapHashFastObject*)hash2)->hash_fast); + if (res) + return Py_BuildValue("O", Py_True); + else + return Py_BuildValue("O", Py_False); +} + +PyObject *dap_hash_fast_is_blank_py(PyObject *self, PyObject *args){ + bool res = dap_hash_fast_is_blank(((PyDapHashFastObject*)self)->hash_fast); + if (res) + return Py_BuildValue("O", Py_True); + else + return Py_BuildValue("O", Py_False); +} + +PyObject *dap_chain_hash_fast_to_str_py(PyObject *self, PyObject *args){ + char *str; + size_t str_max; + if (!PyArg_ParseTuple(args, "s|n", &str, &str_max)) + return NULL; + int res = dap_chain_hash_fast_to_str(((PyDapHashFastObject*)self)->hash_fast, str, str_max); + return Py_BuildValue("sn", &str, &str_max); +} + +PyObject *dap_chain_hash_fast_to_str_new_py(PyObject *self, PyObject *args){ + char *res = dap_chain_hash_fast_to_str_new(((PyDapHashFastObject*)self)->hash_fast); + return Py_BuildValue("s", res); +} diff --git a/cellframe-sdk-python/libdap-crypto-python/test/CMakeLists.txt b/cellframe-sdk-python/libdap-crypto-python/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5af5f169d93f062fd3c9ba6defa1cd7593cec620 --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/test/CMakeLists.txt @@ -0,0 +1,19 @@ +project(TPO C) +cmake_minimum_required(VERSION 2.8) + +set(CMAKE_VERBOSE_MAKEFILE ON) +set(CMAKE_COLOR_MAKEFILE ON) +set(CMAKE_C_STANDARD 11) + +set(Python_ADDITIONAL_VERSIONS 3.7) +find_package (PythonLibs REQUIRED) +include_directories(${PYTHON_INCLUDE_DIR} include/) + +file(GLOB TPO_INCLUDES include/*.h) +file(GLOB TPO_SRCS src/*.c) + +add_library(${PROJECT_NAME} SHARED ${TPO_INCLUDES} ${TPO_SRCS} ) + +target_link_libraries(${PROJECT_NAME} ${PYTHON_LIBRARIES}) + +target_link_libraries(${PROJECT_NAME} dap_crypto_python_module) diff --git a/cellframe-sdk-python/libdap-crypto-python/test/dap_enc_key_test.py b/cellframe-sdk-python/libdap-crypto-python/test/dap_enc_key_test.py new file mode 100644 index 0000000000000000000000000000000000000000..17a5476a3bdec1391a1019485f6153519e37fd9b --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/test/dap_enc_key_test.py @@ -0,0 +1,11 @@ +import libdap_crypto_python_module as crypto + +print ("Start dap_enc_key_test") +print ("Crypto init") +crypto.init() +print ("Create KEY") +key = crypto.newKey(1) +print ("Dellete key") +crypto.delKey(key) +print ("Crypto deinit") +crypto.deinit diff --git a/cellframe-sdk-python/libdap-crypto-python/test/include/tpo.h b/cellframe-sdk-python/libdap-crypto-python/test/include/tpo.h new file mode 100644 index 0000000000000000000000000000000000000000..610a133560775742ec7f2f2fca205450183c08b2 --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/test/include/tpo.h @@ -0,0 +1,51 @@ +#define PY_SSIZE_T_CLEAN +#include "Python.h" +#include "libdap-crypto-python.h" +#include "libdap_crypto_data_type.h" +#include "libdap_crypto_key_type_python.h" + +#ifdef __cplusplus +extern "C" { +#endif + +PyObject *TPO_init(PyObject *self, PyObject *args); +PyObject *TPO_deinit(PyObject *self, PyObject *args); + +static PyMethodDef TPOPythonMethods[] = { + {"init", TPO_init, METH_VARARGS, "Initialization of the python-cellframe interface DAP (Deus Applicaions Prototypes)"}, + {"deinit", TPO_deinit, METH_VARARGS, "Deinitialization of the python-cellframe interface DAP (Deus Applicaions Prototypes)"}, +// {"setLogLevel", (PyCFunction)dap_set_log_level, METH_VARARGS, "Setting the logging level"}, +// {"logIt", (PyCFunction)dap_log_it, METH_VARARGS, "The wrapper of the log_it function for the libdap library"}, +// {"logItDebug", (PyCFunction)dap_log_it_debug, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level DEBUG"}, +// {"logItInfo", (PyCFunction)dap_log_it_info, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level INFO"}, +// {"logItNotice", (PyCFunction)dap_log_it_notice, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level NOTICE"}, +// {"logItMessage", (PyCFunction)dap_log_it_message, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level MESSAGE"}, +// {"logItDap", (PyCFunction)dap_log_it_dap, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level DAP"}, +// {"logItWarning", (PyCFunction)dap_log_it_warning, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level WARNING"}, +// {"logItAtt", (PyCFunction)dap_log_it_att, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level ATT"}, +// {"logItError", (PyCFunction)dap_log_it_error, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level ERROR"}, +// {"logItCritical", (PyCFunction)dap_log_it_critical, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level CRITICAL"}, +// {"configGetItem", (PyCFunction)py_m_dap_config_get_item, METH_VARARGS, ""}, +// {"configGetItemDefault", (PyCFunction)py_m_dap_config_get_item_default, METH_VARARGS, ""}, + //{"deinit", dap_server_core_deinit, METH_NOARGS, "Deinitialization of the DAP (Deus Applicaions Prototypes) server core library"}, + //{"loop", dap_server_core_loop, METH_VARARGS, ""}, + //{"listen", dap_server_core_listen, METH_VARARGS, ""}, + {NULL, NULL, 0, NULL} +}; + +static struct PyModuleDef TPOModule = { + PyModuleDef_HEAD_INIT, + "libTPO", /* name of module */ + NULL, /* module documentation, may be NULL */ + -1, /* size of per-interpreter state of the module, + or -1 if the module keeps state in global variables. */ + TPOPythonMethods +}; + +PyMODINIT_FUNC PyInit_libTPO(void); + + +#ifdef __cplusplus +} +#endif + diff --git a/cellframe-sdk-python/libdap-crypto-python/test/src/tpo.c b/cellframe-sdk-python/libdap-crypto-python/test/src/tpo.c new file mode 100644 index 0000000000000000000000000000000000000000..0721d93cd5da13fce2f77e6f6f0a2ee9eeec4121 --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/test/src/tpo.c @@ -0,0 +1,26 @@ +#include "tpo.h" + +PyObject *TPO_init(PyObject *self, PyObject *args){ + if (dap_crypto_init() != 0) + return NULL; + return PyLong_FromLong(0); +} +PyObject *TPO_deinit(PyObject *self, PyObject *args){ + dap_common_deinit(); + return PyLong_FromLong(0); +} + +PyMODINIT_FUNC PyInit_libTPO(void){ + + if (PyType_Ready(&dapCrypto_dapCryptoType) < 0 || + PyType_Ready(&CryptoKeyTypeObjecy_CryptoKeyTypeObjecyType) < 0 || + PyType_Ready(&CryptoDataTypeObjecy_CryptoDataTypeObjecyType) < 0) + return NULL; + + PyObject *module = PyModule_Create(&TPOModule); + PyModule_AddObject(module, "Crypto", (PyObject*)&dapCrypto_dapCryptoType); + PyModule_AddObject(module, "CryptoKeyType", (PyObject*)&CryptoKeyTypeObjecy_CryptoKeyTypeObjecyType); + PyModule_AddObject(module, "CryptoDataType", (PyObject*)&CryptoDataTypeObjecy_CryptoDataTypeObjecyType); + return module; +} + diff --git a/cellframe-sdk-python/libdap-crypto-python/test/test.py b/cellframe-sdk-python/libdap-crypto-python/test/test.py new file mode 100644 index 0000000000000000000000000000000000000000..1221f48cbf4145be164c3c99de29930157552820 --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/test/test.py @@ -0,0 +1,21 @@ +import libdap_crypto_python_module as crypto +import unittest + +class TestLibdapCryptoPythonModule(unittest.TestCase): + def test_ini(self): + self.assertTrue(crypto.init() == 0, "Failed init libdap crypto python") + def test_deinit(self): + self.assertTrue(crypto.deinit() == 0, "Failed deinit libdap crypto python") + def test_b58(self): + s = "REvgshguqwt76thuioh1`lwi0-8i-d0hjwpeocnpgh89efty7ug" + crypt = crypto.encodeBase58(s) + decrypt = crypto.decodeBase58(crypt) + self.assertTrue(s == decrypt, "Encoding and decoded information using the base58 algorithm does not match the original") + def test_b64(self): + s = "LindyfekrngFHJFGR23356fer" + crypt = crypto.encodeBase64(bytes(s, "utf-8"), 1) + decrypt = crypto.decodeBase64(crypt, 1) + self.assertTrue(bytes(s, "utf-8") == decrypt, "Encoding and decoded information using the base64 algorithm does not match the original") + +if __name__ == '__main__': + unittest.main() diff --git a/cellframe-sdk-python/libdap-crypto-python/test/test_b58.py b/cellframe-sdk-python/libdap-crypto-python/test/test_b58.py new file mode 100644 index 0000000000000000000000000000000000000000..ff02326fd15342cec3a9bb331f48a3351341637f --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/test/test_b58.py @@ -0,0 +1,23 @@ +import libTPO +import pickle +import sys + +print ("Start test crypto base58") +s = """Test! I will crush Base58!""" +base_in = pickle.dumps(s) +print ("Input data: "+s) +print (base_in) +crypt = libTPO.Crypto.encodeBase58(base_in) +print ("Encrypted data: \t") +print(crypt) +decrypt = libTPO.Crypto.decodeBase58(crypt) +print ("Decoded data: \t") +print(decrypt) +out_data = pickle.loads(decrypt) +if s == out_data: + print ("TEST 1. Encode/Decode base58 done") +else: + print ("TEST 1. Encode/Decode base58 faild") + sys.exit(1) + +sys.exit(0) diff --git a/cellframe-sdk-python/libdap-crypto-python/test/test_b64.py b/cellframe-sdk-python/libdap-crypto-python/test/test_b64.py new file mode 100644 index 0000000000000000000000000000000000000000..a4270ebbc22ed2288d5c7af76fae0b7cf214c4a7 --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/test/test_b64.py @@ -0,0 +1,30 @@ +import libTPO +import sys + +print ("Start test crypto b64") +s = "Test! I will crush Base64!" +print ("Input data: "+s) +crypt = libTPO.Crypto.encodeBase64(bytes(s, "utf-8"), libTPO.CryptoDataType.DAP_ENC_DATA_TYPE_B64()) +print ("Encrypted data: \t") +print(crypt) +decrypt = libTPO.Crypto.decodeBase64(crypt, libTPO.CryptoDataType.DAP_ENC_DATA_TYPE_B64()) +print ("Decoded data: \t") +print(decrypt) +if bytes(s, "utf-8") == decrypt: + print ("TEST 1. Encode/Decode base64 done") +else: + print ("TEST 1. Encode/Decode base64 faild") + sys.exit(1) + +print ("Test Base64 URLSAFE") +u = "http://kelvin.foundation/" +crypt_u = libTPO.Crypto.encodeBase64(bytes(u, "utf-8"), libTPO.CryptoDataType.DAP_ENC_DATA_TYPE_B64_URLSAFE()) +decrypt_u = libTPO.Crypto.decodeBase64(crypt_u, libTPO.CryptoDataType.DAP_ENC_DATA_TYPE_B64_URLSAFE()) +if bytes(u, "utf-8") == decrypt_u: + print ("TEST 2. Encode/Decode base64 urlsafe done") +else: + print ("TEST 2. Encode/Decode base64 urlsafe faild") + sys.exit(2) + +sys.exit(0) + diff --git a/cellframe-sdk-python/libdap-crypto-python/test/test_iaes256_cbc.py b/cellframe-sdk-python/libdap-crypto-python/test/test_iaes256_cbc.py new file mode 100644 index 0000000000000000000000000000000000000000..1a2cc6248a749f0e2f5a26286d311806d4c9e545 --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/test/test_iaes256_cbc.py @@ -0,0 +1,24 @@ +import libTPO +import sys + +print ("Start test crypto iaes256 CBC") +s = "Test! I will crush iaes256!" +kex_buff = bytes("123", "utf-8") +size_kex_buff = len(kex_buff) +seed = bytes(112771128) +seed_size = len(seed) +libTPO.init() +key_id = libTPO.Crypto.generateNewKey(0, kex_buff, size_kex_buff, seed, seed_size, 0) +source = bytes(s, "utf-8") +enc = libTPO.Crypto.encryptIAES256CBCFast(key_id, source, len(source), 2048) +decrypt = libTPO.Crypto.decryptIAES256CBCFast(key_id, enc, len(enc), 2048) + +if bytes(s, "utf-8") == decrypt: + print ("TEST 1. Encode/Decode IAES256 CBC FAST done") +else: + print ("TEST 1. Encode/Decode IAES256 CBC FAST faild") + sys.exit(1) + + +sys.exit(0) + diff --git a/cellframe-sdk-python/libdap-crypto-python/test/test_oaes.py b/cellframe-sdk-python/libdap-crypto-python/test/test_oaes.py new file mode 100644 index 0000000000000000000000000000000000000000..2c36e8e0bbd69239cfe5530368f68a0ce034e09a --- /dev/null +++ b/cellframe-sdk-python/libdap-crypto-python/test/test_oaes.py @@ -0,0 +1,23 @@ +import libTPO +import sys + +print ("Start test crypto OAES") +s = "Test! I will crush OAES!" +kex_buff = bytes("114151400014314485131FGXVGHcJFIH", "utf-8") +size_kex_buff = len(kex_buff) +seed = bytes(112771128) +seed_size = len(seed) +libTPO.init() +key = libTPO.Crypto.generateNewKey(libTPO.CryptoKeyType.DAP_ENC_KEY_TYPE_OAES(), kex_buff, size_kex_buff, seed, seed_size, 32) +source = bytes(s, "utf-8") +enc = libTPO.Crypto.encryptOAESFast(key, source, len(source), 2048) +decrypt = libTPO.Crypto.decryptOAESFast(key, enc, len(enc), 2048) + +if bytes(s, "utf-8") == decrypt: + print ("TEST 1. Encode/Decode OAES FAST done") +else: + print ("TEST 1. Encode/Decode OAES CBC FAST faild") + sys.exit(1) + +sys.exit(0) + diff --git a/cellframe-sdk-python/libdap-python b/cellframe-sdk-python/libdap-python deleted file mode 160000 index 4702d3590df6894778c48dc3195399cea432d08a..0000000000000000000000000000000000000000 --- a/cellframe-sdk-python/libdap-python +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4702d3590df6894778c48dc3195399cea432d08a diff --git a/cellframe-sdk-python/libdap-python/.gitignore b/cellframe-sdk-python/libdap-python/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..c6127b38c1aa25968a88db3940604d41529e4cf5 --- /dev/null +++ b/cellframe-sdk-python/libdap-python/.gitignore @@ -0,0 +1,52 @@ +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf diff --git a/cellframe-sdk-python/libdap-python/.travis.yml b/cellframe-sdk-python/libdap-python/.travis.yml new file mode 100644 index 0000000000000000000000000000000000000000..8ad3151fc89f4fa2fc0d33ad751955559a6a67bd --- /dev/null +++ b/cellframe-sdk-python/libdap-python/.travis.yml @@ -0,0 +1,31 @@ +sudo: required +language: python +python: + - "3.7-dev" +compiler: gcc +dist: xenial +notifications: + email: false + +before_install: + - git submodule init + - git submodule update + +install: + - sudo apt-get install gcc make + +script: + - sudo service network-manager start + - mkdir build + - cd build + - cmake -DBUILD_DAP_PYTHON_TESTS=ON ../ + - make + - python3.7 main_test.py + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - network-manager + diff --git a/cellframe-sdk-python/libdap-python/CMakeLists.txt b/cellframe-sdk-python/libdap-python/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..4493f287d3a0446124b6a3fc01916f1d1ec3caf3 --- /dev/null +++ b/cellframe-sdk-python/libdap-python/CMakeLists.txt @@ -0,0 +1,44 @@ +project(dap_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 CORE_SRCS src/*.c) +file(GLOB CORE_HEADERS src/*.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 ${CORE_SRCS} ${CORE_UNIX_SRCS}) + +target_link_libraries(${PROJECT_NAME} ${PYTHON_LIBRARIES}) + +target_compile_options( + dap_core PRIVATE + "-fpic" +) + +target_link_libraries(${PROJECT_NAME} dap_core ${PYTHON_LIBRARIES}) + +target_include_directories(${PROJECT_NAME} PUBLIC src/ ) + +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() + diff --git a/cellframe-sdk-python/libdap-python/LICENSE b/cellframe-sdk-python/libdap-python/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..f288702d2fa16d3cdf0035b15a9fcbc552cd88e7 --- /dev/null +++ b/cellframe-sdk-python/libdap-python/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + <program> Copyright (C) <year> <name of author> + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +<https://www.gnu.org/licenses/>. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +<https://www.gnu.org/licenses/why-not-lgpl.html>. diff --git a/cellframe-sdk-python/libdap-python/README.md b/cellframe-sdk-python/libdap-python/README.md new file mode 100644 index 0000000000000000000000000000000000000000..60b37469ab5c8efc7bad5b52764a693b0ce1c383 --- /dev/null +++ b/cellframe-sdk-python/libdap-python/README.md @@ -0,0 +1,15 @@ +# libdap-python +Python binding for libdap + +[](https://travis-ci.com/cellframe/libdap-python) + +## Build and Run tests: +``` +git submodule update --init +mkdir build +cd build +cmake -DBUILD_DAP_PYTHON_TESTS=ON ../ +make +cd test +python3.7 main_test.py +``` diff --git a/cellframe-sdk-python/libdap-python/src/libdap-python.c b/cellframe-sdk-python/libdap-python/src/libdap-python.c new file mode 100644 index 0000000000000000000000000000000000000000..67fe53a56aff4b76949c870fc18ca1032b03274f --- /dev/null +++ b/cellframe-sdk-python/libdap-python/src/libdap-python.c @@ -0,0 +1,146 @@ +#include "libdap-python.h" + +#define LOG_TAG "libdap-python" + +PyObject *dap_set_log_level(PyObject *self, PyObject *args){ + short int new_log_level; + if (!PyArg_ParseTuple(args, "h", &new_log_level)) + return NULL; + if (new_log_level < 0 || new_log_level > 10 ) { + return PyLong_FromLong(-1); + } else { + dap_log_level_set(new_log_level); + return PyLong_FromLong(0); + } +} + +PyObject* dap_log_it(PyObject* self, PyObject* args){ + short int log_level; + const char* string_output; + if (!PyArg_ParseTuple(args, "h|s", &log_level, &string_output)) + return NULL; + if (log_level < 0 || log_level > 10 ) { + return PyLong_FromLong(-1); + } else { + log_it(log_level, string_output); + return PyLong_FromLong(0); + } +} + +PyObject* dap_log_it_debug(PyObject* self, PyObject* args){ + const char* string_output; + if (!PyArg_ParseTuple(args, "s", &string_output)){ + return NULL; + } + log_it(L_DEBUG, string_output); + return PyLong_FromLong(0); +} +PyObject* dap_log_it_info(PyObject* self, PyObject* args){ + const char* string_output; + if (!PyArg_ParseTuple(args, "s", &string_output)){ + return NULL; + } + log_it(L_INFO, string_output); + return PyLong_FromLong(0); +} +PyObject* dap_log_it_notice(PyObject* self, PyObject* args){ + const char* string_output; + if (!PyArg_ParseTuple(args, "s", &string_output)){ + return NULL; + } + log_it(L_NOTICE, string_output); + return PyLong_FromLong(0); +} +PyObject* dap_log_it_message(PyObject* self, PyObject* args){ + const char* string_output; + if (!PyArg_ParseTuple(args, "s", &string_output)){ + return NULL; + } + log_it(L_MSG, string_output); + return PyLong_FromLong(0); +} +PyObject* dap_log_it_dap(PyObject* self, PyObject* args){ + const char* string_output; + if (!PyArg_ParseTuple(args, "s", &string_output)){ + return NULL; + } + log_it(L_DAP, string_output); + return PyLong_FromLong(0); +} +PyObject* dap_log_it_warning(PyObject* self, PyObject* args){ + const char* string_output; + if (!PyArg_ParseTuple(args, "s", &string_output)){ + return NULL; + } + log_it(L_WARNING, string_output); + return PyLong_FromLong(0); +} +PyObject* dap_log_it_att(PyObject* self, PyObject* args){ + const char* string_output; + if (!PyArg_ParseTuple(args, "s", &string_output)){ + return NULL; + } + log_it(L_ATT, string_output); + return PyLong_FromLong(0); +} +PyObject* dap_log_it_error(PyObject* self, PyObject* args){ + const char* string_output; + if (!PyArg_ParseTuple(args, "s", &string_output)){ + return NULL; + } + log_it(L_ERROR, string_output); + return PyLong_FromLong(0); +} +PyObject* dap_log_it_critical(PyObject* self, PyObject* args){ + const char* string_output; + if (!PyArg_ParseTuple(args, "s", &string_output)){ + return NULL; + } + log_it(L_CRITICAL, string_output); + return PyLong_FromLong(0); +} + +PyObject* py_m_dap_config_get_item(PyObject *self, PyObject *args){ + const char *section_path; + const char *item_name; + if (!PyArg_ParseTuple(args, "s|s", §ion_path, &item_name)) + return NULL; + const char *res = dap_config_get_item_str(g_config, section_path, item_name); + if (res == NULL){ + PyErr_SetString(PyExc_ValueError, "The value could not be obtained. Or there is no section. Or missing key in the section."); + return NULL; + } + return Py_BuildValue("s", res); +} + +PyObject* py_m_dap_config_get_item_default(PyObject *self, PyObject *args){ + const char *section_path; + const char *item_name; + const char *def; + if (!PyArg_ParseTuple(args, "s|s|s", §ion_path, &item_name, &def)) + return NULL; + const char *res = dap_config_get_item_str_default(g_config, section_path, item_name, def); + return Py_BuildValue("s", res); +} + +PyObject *dapListToPyList(dap_list_t *list ){ + unsigned int len = dap_list_length(list); + PyObject *obj = PyList_New((Py_ssize_t)len); + for (unsigned int l = 0; l <len; l++){ + void *data = dap_list_nth_data(list, l); + PyObject *obj_data = PyBytes_FromString((const char*)data); + PyList_Append(obj, obj_data); + } + return obj; +} + +dap_list_t *pyListToDapList(PyObject *list ){ + Py_ssize_t len = PyList_Size(list); + dap_list_t *dap_list = dap_list_alloc(); + for (Py_ssize_t i = 0; i < len; i++){ + PyObject *obj = PyList_GetItem(list, i); + void *data = PyBytes_AsString(obj); + dap_list = dap_list_append(dap_list, data); + } + return dap_list; +} diff --git a/cellframe-sdk-python/libdap-python/src/libdap-python.h b/cellframe-sdk-python/libdap-python/src/libdap-python.h new file mode 100644 index 0000000000000000000000000000000000000000..5ef71241b04a310b64ec8f73f085312bb23b8089 --- /dev/null +++ b/cellframe-sdk-python/libdap-python/src/libdap-python.h @@ -0,0 +1,88 @@ +#pragma once +#define PY_SSIZE_T_CLEAN +#include <Python.h> +#include "dap_config.h" +#include "dap_common.h" +#include "dap_list.h" + +typedef struct PyDap{ + PyObject_HEAD +}PyDapObject; + +PyObject *dap_set_log_level(PyObject *self, PyObject *args); + +PyObject* dap_log_it(PyObject* self, PyObject* args); + +PyObject* dap_log_it_debug(PyObject* self, PyObject* args); +PyObject* dap_log_it_info(PyObject* self, PyObject* args); +PyObject* dap_log_it_notice(PyObject* self, PyObject* args); +PyObject* dap_log_it_message(PyObject* self, PyObject* args); +PyObject* dap_log_it_dap(PyObject* self, PyObject* args); +PyObject* dap_log_it_warning(PyObject* self, PyObject* args); +PyObject* dap_log_it_att(PyObject* self, PyObject* args); +PyObject* dap_log_it_error(PyObject* self, PyObject* args); +PyObject* dap_log_it_critical(PyObject* self, PyObject* args); + +PyObject* py_m_dap_config_get_item(PyObject *self, PyObject *args); + +PyObject* py_m_dap_config_get_item_default(PyObject *self, PyObject *args); + +static PyMethodDef DapCoreMethods[] = { + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapCoreObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "Dap", /* tp_name */ + sizeof(PyDapObject), /* 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 objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapCoreMethods, /* 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 */ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +}; +PyObject *dapListToPyList(dap_list_t *list); + +dap_list_t *pyListToDapList(PyObject *list); + diff --git a/cellframe-sdk-python/libdap-python/test/CMakeLists.txt b/cellframe-sdk-python/libdap-python/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..bca400efd1cb6cb428b41dd287cc76411982b26e --- /dev/null +++ b/cellframe-sdk-python/libdap-python/test/CMakeLists.txt @@ -0,0 +1,19 @@ +project(TPO C) +cmake_minimum_required(VERSION 2.8) + +set(CMAKE_VERBOSE_MAKEFILE ON) +set(CMAKE_COLOR_MAKEFILE ON) +set(CMAKE_C_STANDARD 11) + +set(Python_ADDITIONAL_VERSIONS 3.7) +find_package (PythonLibs REQUIRED) +include_directories(${PYTHON_INCLUDE_DIR} include/) + +file(GLOB TPO_INCLUDES include/*.h) +file(GLOB TPO_SRCS src/*.c) + +add_library(${PROJECT_NAME} SHARED ${TPO_INCLUDES} ${TPO_SRCS} ) + +target_link_libraries(${PROJECT_NAME} ${PYTHON_LIBRARIES}) + +target_link_libraries(${PROJECT_NAME} dap_python_module) diff --git a/cellframe-sdk-python/libdap-python/test/include/tpo.h b/cellframe-sdk-python/libdap-python/test/include/tpo.h new file mode 100644 index 0000000000000000000000000000000000000000..d71f3b4ee74e8ac6c04ef96440f436feb73b9948 --- /dev/null +++ b/cellframe-sdk-python/libdap-python/test/include/tpo.h @@ -0,0 +1,49 @@ +#define PY_SSIZE_T_CLEAN +#include "Python.h" +#include "libdap-python.h" + +#ifdef __cplusplus +extern "C" { +#endif + +PyObject *TPO_init(PyObject *self, PyObject *args); +PyObject *TPO_deinit(PyObject *self, PyObject *args); + +static PyMethodDef TPOPythonMethods[] = { + {"init", TPO_init, METH_VARARGS, "Initialization of the python-cellframe interface DAP (Deus Applicaions Prototypes)"}, + {"deinit", TPO_deinit, METH_VARARGS, "Deinitialization of the python-cellframe interface DAP (Deus Applicaions Prototypes)"}, + {"setLogLevel", (PyCFunction)dap_set_log_level, METH_VARARGS, "Setting the logging level"}, + {"logIt", (PyCFunction)dap_log_it, METH_VARARGS, "The wrapper of the log_it function for the libdap library"}, + {"logItDebug", (PyCFunction)dap_log_it_debug, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level DEBUG"}, + {"logItInfo", (PyCFunction)dap_log_it_info, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level INFO"}, + {"logItNotice", (PyCFunction)dap_log_it_notice, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level NOTICE"}, + {"logItMessage", (PyCFunction)dap_log_it_message, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level MESSAGE"}, + {"logItDap", (PyCFunction)dap_log_it_dap, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level DAP"}, + {"logItWarning", (PyCFunction)dap_log_it_warning, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level WARNING"}, + {"logItAtt", (PyCFunction)dap_log_it_att, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level ATT"}, + {"logItError", (PyCFunction)dap_log_it_error, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level ERROR"}, + {"logItCritical", (PyCFunction)dap_log_it_critical, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level CRITICAL"}, + {"configGetItem", (PyCFunction)py_m_dap_config_get_item, METH_VARARGS, ""}, + {"configGetItemDefault", (PyCFunction)py_m_dap_config_get_item_default, METH_VARARGS, ""}, + //{"deinit", dap_server_core_deinit, METH_NOARGS, "Deinitialization of the DAP (Deus Applicaions Prototypes) server core library"}, + //{"loop", dap_server_core_loop, METH_VARARGS, ""}, + //{"listen", dap_server_core_listen, METH_VARARGS, ""}, + {NULL, NULL, 0, NULL} +}; + +static struct PyModuleDef TPOModule = { + PyModuleDef_HEAD_INIT, + "libTPO", /* name of module */ + NULL, /* module documentation, may be NULL */ + -1, /* size of per-interpreter state of the module, + or -1 if the module keeps state in global variables. */ + TPOPythonMethods +}; + +PyMODINIT_FUNC PyInit_libTPO(void); + + +#ifdef __cplusplus +} +#endif + diff --git a/cellframe-sdk-python/libdap-python/test/main_test.py b/cellframe-sdk-python/libdap-python/test/main_test.py new file mode 100644 index 0000000000000000000000000000000000000000..f56c995df04184baa79a580d4ff58b0d7c0db7b6 --- /dev/null +++ b/cellframe-sdk-python/libdap-python/test/main_test.py @@ -0,0 +1,34 @@ +from libTPO import * +import os +import sys + +def create_config_file(app_name): + f = open(app_name+".cfg", "w") + f.write("[server]\nlisten_address=0.0.0.0\n") + f.close() + +print("Start main test") +app_name = "TestAPP" +print("Create config file") +create_config_file(app_name) +path = os.getcwd() + +init(app_name, app_name, path, "DEBUG") +logIt(INFO, "Initialization of the DAP done") +setLogLevel(DEBUG) +logIt(INFO,"Level logging ""DEBUG"" done") +logIt(DEBUG, "Test. Outputting a string using the log_it function in the libdap library") +logIt(INFO,"Outputting a string using the log_it function done") +res1 = configGetItem("server", "listen_address") +logIt(INFO, "Output [server] 'listen_address' = "+res1+"\n") +res2 = configGetItemDefault("server1", "listen_address", "8.8.8.8") +logIt(INFO, "Output default value '8.8.8.8' [server1] 'listen_address' = "+res2+"\n") +logIt(INFO, "TEST. Get default config done") +deinit() +logIt(INFO, "Deinitialization done") + +os.remove(app_name+".cfg") +logIt(INFO, "Dellete config file") +logIt(INFO, "Main test done"); + +sys.exit(0) diff --git a/cellframe-sdk-python/libdap-python/test/src/tpo.c b/cellframe-sdk-python/libdap-python/test/src/tpo.c new file mode 100644 index 0000000000000000000000000000000000000000..602eba1b2a09dbe1f0cf4be2520a15a735f27a07 --- /dev/null +++ b/cellframe-sdk-python/libdap-python/test/src/tpo.c @@ -0,0 +1,62 @@ +#include "tpo.h" + +PyObject *TPO_init(PyObject *self, PyObject *args){ + const char *app_name, *file_name_log, *config_dir, *s_log_level; + if (!PyArg_ParseTuple(args, "s|s|s|s", &app_name, &file_name_log, &config_dir, &s_log_level)){ + return NULL; + } + if (dap_common_init(app_name, file_name_log) != 0){ + return NULL; + } + dap_config_init(config_dir); + if ((g_config = dap_config_open(app_name) ) == NULL){ + return NULL; + } + + if (strcmp(s_log_level, "DEBUG") == 0 ){ + dap_log_level_set(L_DEBUG); + } else if (strcmp(s_log_level, "INFO") == 0) { + dap_log_level_set(L_INFO); + } else if (strcmp(s_log_level, "NOTICE") == 0) { + dap_log_level_set(L_NOTICE); + }else if (strcmp(s_log_level, "MESSAGE") == 0) { + dap_log_level_set(L_MSG); + }else if (strcmp(s_log_level, "DAP") == 0) { + dap_log_level_set(L_DAP); + }else if (strcmp(s_log_level, "WARNING") == 0) { + dap_log_level_set(L_WARNING); + }else if (strcmp(s_log_level, "ATT") == 0) { + dap_log_level_set(L_ATT); + }else if (strcmp(s_log_level, "ERROR") == 0) { + dap_log_level_set(L_ERROR); + } else if (strcmp(s_log_level, "CRITICAL") == 0) { + dap_log_level_set(L_CRITICAL); + } else { + dap_log_level_set(L_DEBUG); + } + return PyLong_FromLong(0); +} +PyObject *TPO_deinit(PyObject *self, PyObject *args){ + dap_config_close(g_config); + dap_config_deinit(); + return PyLong_FromLong(0); +} + +PyMODINIT_FUNC PyInit_libTPO(void){ + + if (PyType_Ready(&DapObject_DapObjectType) < 0 ) + return NULL; + + PyObject *module = PyModule_Create(&TPOModule); + PyModule_AddObject(module, "DEBUG", PyLong_FromLong(L_DEBUG)); + PyModule_AddObject(module, "INFO", PyLong_FromLong(L_INFO)); + PyModule_AddObject(module, "NOTICE", PyLong_FromLong(L_NOTICE)); + PyModule_AddObject(module, "MESSAGE", PyLong_FromLong(L_MSG)); + PyModule_AddObject(module, "DAP", PyLong_FromLong(L_DAP)); + PyModule_AddObject(module, "WARNING", PyLong_FromLong(L_WARNING)); + PyModule_AddObject(module, "ATT", PyLong_FromLong(L_ATT)); + PyModule_AddObject(module, "ERROR", PyLong_FromLong(L_ERROR)); + PyModule_AddObject(module, "CRITICAL", PyLong_FromLong(L_CRITICAL)); + return module; +} + diff --git a/cellframe-sdk-python/libdap-server-core-python b/cellframe-sdk-python/libdap-server-core-python deleted file mode 160000 index 016333e1d04750e13373fd6a87ba051c0297eb7e..0000000000000000000000000000000000000000 --- a/cellframe-sdk-python/libdap-server-core-python +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 016333e1d04750e13373fd6a87ba051c0297eb7e diff --git a/cellframe-sdk-python/libdap-server-core-python/.gitignore b/cellframe-sdk-python/libdap-server-core-python/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..c6127b38c1aa25968a88db3940604d41529e4cf5 --- /dev/null +++ b/cellframe-sdk-python/libdap-server-core-python/.gitignore @@ -0,0 +1,52 @@ +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf diff --git a/cellframe-sdk-python/libdap-server-core-python/CMakeLists.txt b/cellframe-sdk-python/libdap-server-core-python/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5ee70c777487840dc6a851a6a4b327659a6e15da --- /dev/null +++ b/cellframe-sdk-python/libdap-server-core-python/CMakeLists.txt @@ -0,0 +1,51 @@ +project(dap_server_core_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)) + set(SUBMODULES_NO_BUILD ON) + if (NOT (TARGET dap_core)) + add_subdirectory(libdap) + target_compile_options( + dap_core PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap_crypto)) + add_subdirectory(libdap-crypto) + target_compile_options( + dap_crypto PRIVATE + "-fpic" + ) + endif() + if (NOT (TARGET dap-server-core)) + add_subdirectory(libdap-server-core) + target_compile_options( + dap_server_core PRIVATE + "-fpic" + ) + endif() +endif() + + + +file(GLOB SERVER_CORE_PYTHON_SRCS src/*.c) +file(GLOB SERVER_CORE_PYTHON_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_CORE_PYTHON_SRCS} ${SERVER_CORE_PYTHON_HEADERS}) + +target_link_libraries(${PROJECT_NAME}) + + +target_link_libraries(${PROJECT_NAME} dap_core dap_crypto dap_server_core) + +target_include_directories(${PROJECT_NAME} PUBLIC include/ ) + diff --git a/cellframe-sdk-python/libdap-server-core-python/LICENSE b/cellframe-sdk-python/libdap-server-core-python/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..f288702d2fa16d3cdf0035b15a9fcbc552cd88e7 --- /dev/null +++ b/cellframe-sdk-python/libdap-server-core-python/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + <program> Copyright (C) <year> <name of author> + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +<https://www.gnu.org/licenses/>. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +<https://www.gnu.org/licenses/why-not-lgpl.html>. diff --git a/cellframe-sdk-python/libdap-server-core-python/README.md b/cellframe-sdk-python/libdap-server-core-python/README.md new file mode 100644 index 0000000000000000000000000000000000000000..4b652319a05ec471080ee6197587c0b413870486 --- /dev/null +++ b/cellframe-sdk-python/libdap-server-core-python/README.md @@ -0,0 +1,2 @@ +# libdap-server-core-python +libdap-server-core python bindings diff --git a/cellframe-sdk-python/libdap-server-core-python/include/dap_events_python.h b/cellframe-sdk-python/libdap-server-core-python/include/dap_events_python.h new file mode 100644 index 0000000000000000000000000000000000000000..c79f86dff81b5cec4933be34e3461b9c1da8fa66 --- /dev/null +++ b/cellframe-sdk-python/libdap-server-core-python/include/dap_events_python.h @@ -0,0 +1,79 @@ +#pragma once + +#include "Python.h" +#include "dap_events.h" +#include "dap_events_socket_python.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PyDapEvents{ + PyObject_HEAD + dap_events_t *t_events; +}PyDapEventsObject; + +void PyDapEventsObject_dealloc(PyDapEventsObject *eventsObject); + +PyObject *PyDapEventsObject_new(PyTypeObject *type_object, PyObject *args, PyObject *kwds); +PyObject *dap_events_socket_remove_and_delete_py(PyDapEventsObject *self, PyObject *args); + +PyObject *dap_events_socket_kill_socket_py(PyDapEventsObject *self, PyObject *args); + +PyObject *dap_events_start_py(PyDapEventsObject *self); +PyObject *dap_events_wait_py(PyDapEventsObject *self); + +static PyMethodDef PyDapEventsObject_methods[] = { + {"start", (PyCFunction)dap_events_start_py, METH_NOARGS, ""}, + {"wait", (PyCFunction)dap_events_wait_py, METH_NOARGS, ""}, + {"killSocket", (PyCFunction)dap_events_socket_kill_socket_py, METH_VARARGS, ""}, + {"removeAndDeleteSocket", (PyCFunction)dap_events_socket_remove_and_delete_py, METH_VARARGS, ""}, + {NULL, NULL, 0, NULL} /* Sentinel */ +}; + +static PyTypeObject dapEvents_dapEventsType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.ServerCore.DapEvents", /* tp_name */ + sizeof(PyDapEventsObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)PyDapEventsObject_dealloc, /* 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 */ + "DapEvents objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + PyDapEventsObject_methods, /* 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 */ + PyDapEventsObject_new, /* tp_new */ +}; + +#ifdef __cplusplus +} +#endif diff --git a/cellframe-sdk-python/libdap-server-core-python/include/dap_events_socket_python.h b/cellframe-sdk-python/libdap-server-core-python/include/dap_events_socket_python.h new file mode 100644 index 0000000000000000000000000000000000000000..09309cd35b2b70d8280a809bd1897e7a8bc2bac2 --- /dev/null +++ b/cellframe-sdk-python/libdap-server-core-python/include/dap_events_socket_python.h @@ -0,0 +1,88 @@ +#pragma once + +#include "Python.h" +#include "dap_events_socket.h" +#include "dap_events_python.h" +#include "dap_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PyDapEventsSocket{ + PyObject_HEAD + dap_events_socket_t *t_events_socket; +}PyDapEventsSocketObject; + +PyObject *dap_events_socket_create_after_py(PyDapEventsSocketObject *self); + +PyObject *dap_events_socket_find_py(PyDapEventsSocketObject *self, PyObject *args);// Find client by socket +PyObject *dap_events_socket_set_readable_py(PyDapEventsSocketObject *self, PyObject *args); +PyObject *dap_events_socket_set_writable_py(PyDapEventsSocketObject *self, PyObject *args); + +PyObject *dap_events_socket_write_py(PyDapEventsSocketObject *self, PyObject *args); +PyObject *dap_events_socket_write_f_py(PyDapEventsSocketObject *self, PyObject *args); +PyObject *dap_events_socket_read_py(PyDapEventsSocketObject *self, PyObject *args); + +PyObject *dap_events_socket_delete_py(PyDapEventsSocketObject *self, PyObject *args);// Removes the client from the list + +PyObject *dap_events_socket_shrink_buf_in_py(PyDapEventsSocketObject *self, PyObject *args); + +static PyMethodDef PyDapEventsObjectSocket_methods[] = { + {"createAfter", (PyCFunction)dap_events_socket_create_after_py, METH_NOARGS, ""}, + {"find", (PyCFunction)dap_events_socket_find_py, METH_VARARGS, ""}, + {"setReadable", (PyCFunction)dap_events_socket_set_readable_py, METH_VARARGS, ""}, + {"setWritable", (PyCFunction)dap_events_socket_set_writable_py, METH_VARARGS, ""}, + {"write", (PyCFunction)dap_events_socket_write_py, METH_VARARGS, ""}, + {"writeF", (PyCFunction)dap_events_socket_write_f_py, METH_VARARGS, ""}, + {"read", (PyCFunction)dap_events_socket_read_py, METH_VARARGS, ""}, + {"delete", (PyCFunction)dap_events_socket_delete_py, METH_VARARGS, ""}, + {"shringBufIn", (PyCFunction)dap_events_socket_shrink_buf_in_py, METH_VARARGS, ""}, + {NULL, NULL, 0, NULL} /* Sentinel */ +}; + +static PyTypeObject dapEventsSocket_dapEventsSocketType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.ServerCore.DapEventsSocket", /* tp_name */ + sizeof(PyDapEventsSocketObject), /* 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 */ + "DapEventsSocket objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + PyDapEventsObjectSocket_methods, /* 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 diff --git a/cellframe-sdk-python/libdap-server-core-python/include/dap_server_python.h b/cellframe-sdk-python/libdap-server-core-python/include/dap_server_python.h new file mode 100644 index 0000000000000000000000000000000000000000..d208b5a033572a4bfdad713110fc1a22e8abd2fb --- /dev/null +++ b/cellframe-sdk-python/libdap-server-core-python/include/dap_server_python.h @@ -0,0 +1,42 @@ +#ifndef _DAP_SERVER_PYTHON_ +#define _DAP_SERVER_PYTHON_ +#include "Python.h" +#include "dap_server.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PyDapServer { + PyObject_HEAD + dap_server_t *t_server; +}PyDapServerObject; + +static PyTypeObject dapServer_dapServerType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.ServerCore.DapServer", /* tp_name */ + sizeof(PyDapServerObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + 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, /* tp_flags */ + "DapServer objects", /* tp_doc */ +}; + +#ifdef __cplusplus +} +#endif +#endif //_DAP_SERVER_PYTHON_ diff --git a/cellframe-sdk-python/libdap-server-core-python/include/libdap-server-core-python.h b/cellframe-sdk-python/libdap-server-core-python/include/libdap-server-core-python.h new file mode 100644 index 0000000000000000000000000000000000000000..a6d44efd29083b667ced411937b21422bd93cc8b --- /dev/null +++ b/cellframe-sdk-python/libdap-server-core-python/include/libdap-server-core-python.h @@ -0,0 +1,79 @@ +#define PY_SSIZE_T_CLEAN +#include "Python.h" +#include "dap_server_python.h" +#include "dap_server.h" +#include "dap_client_remote.h" +#include "dap_events.h" +#include "dap_common.h" +#include "dap_events_python.h" +#include "dap_events_socket_python.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SeverCore{ + PyObject_HEAD +}PyServerCoreObject; + +int dap_server_core_init(uint32_t l_thread_cnt, size_t conn_t); +void dap_server_core_deinit(void); + +PyObject *dap_server_core_loop(PyObject *self, PyObject *args); +PyObject *dap_server_core_listen(PyObject *self, PyObject *args); + +static PyMethodDef ServerCorePythonMethods[] = { + {"loop", dap_server_core_loop, METH_VARARGS | METH_STATIC, ""}, + {"listen", dap_server_core_listen, METH_VARARGS | METH_STATIC, ""}, + {NULL, NULL, 0, NULL} +}; + + +static PyTypeObject ServerCore_ServerCoreType = { + PyVarObject_HEAD_INIT(NULL, 0) + "ServerCore", /* tp_name */ + sizeof(PyServerCoreObject), /* 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 */ + "ServerCore objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + ServerCorePythonMethods, /* 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 diff --git a/cellframe-sdk-python/libdap-server-core-python/src/dap_events_python.c b/cellframe-sdk-python/libdap-server-core-python/src/dap_events_python.c new file mode 100644 index 0000000000000000000000000000000000000000..f922588e78ef2f61e0213ce3af1d5bdef8d57127 --- /dev/null +++ b/cellframe-sdk-python/libdap-server-core-python/src/dap_events_python.c @@ -0,0 +1,43 @@ +#include "dap_events_python.h" + +PyObject *PyDapEventsObject_new(PyTypeObject *type_object, PyObject *args, PyObject *kwds){ + PyDapEventsObject *new_EO = (PyDapEventsObject*)PyType_GenericNew(type_object, args, kwds); + new_EO->t_events = dap_events_new(); + return (PyObject *)new_EO; +} + +void PyDapEventsObject_dealloc(PyDapEventsObject *eventsObject){ + dap_events_delete(eventsObject->t_events); + Py_TYPE(eventsObject)->tp_free((PyObject*)eventsObject); +} + +PyObject *dap_events_socket_remove_and_delete_py(PyDapEventsObject *self, PyObject *args){ + PyObject *in_obj; + PyObject *in_bool; + if (!PyArg_ParseTuple(args, "O|O", &in_obj, &in_bool)){ + return NULL; + } + bool preserve_inheritor = true; + if (in_bool == Py_False) + preserve_inheritor = false; + dap_events_socket_remove_and_delete(((PyDapEventsSocketObject*)in_obj)->t_events_socket, preserve_inheritor); + return PyLong_FromLong(0); +} + +PyObject *dap_events_socket_kill_socket_py(PyDapEventsObject *self, PyObject *args){ + PyObject *in_obj; + if (!PyArg_ParseTuple(args, "O", &in_obj)){ + return NULL; + } + dap_events_socket_kill_socket(((PyDapEventsSocketObject*)in_obj)->t_events_socket); + return PyLong_FromLong(0); +} + +PyObject *dap_events_start_py(PyDapEventsObject *self){ + int32_t result = dap_events_start(self->t_events); + return PyLong_FromLong(result); +} +PyObject *dap_events_wait_py(PyDapEventsObject *self){ + int32_t result = dap_events_wait(self->t_events); + return PyLong_FromLong(result); +} diff --git a/cellframe-sdk-python/libdap-server-core-python/src/dap_events_socket_python.c b/cellframe-sdk-python/libdap-server-core-python/src/dap_events_socket_python.c new file mode 100644 index 0000000000000000000000000000000000000000..2c2badfc2a801def721e1f989a84a8f6d773b7a0 --- /dev/null +++ b/cellframe-sdk-python/libdap-server-core-python/src/dap_events_socket_python.c @@ -0,0 +1,124 @@ +#include "dap_events_socket_python.h" + +#define LOG_TAG "dap_events_socket_python" + +PyObject *dap_events_socket_create_after_py(PyDapEventsSocketObject *self){ + if (self->t_events_socket == NULL){ + return NULL; + } + dap_events_socket_create_after(self->t_events_socket); + return PyLong_FromLong(0); +} + +PyObject *dap_events_socket_find_py(PyDapEventsSocketObject *self, PyObject *args){ + if (self->t_events_socket != NULL){ + return NULL; + } + int socket; + PyObject *in_object; + if (!PyArg_ParseTuple(args, "i|O", &socket, &in_object)){ + return NULL; + } + self->t_events_socket = dap_events_socket_find(socket, ((PyDapEventsObject*)in_object)->t_events); + return PyLong_FromLong(0); +} +PyObject *dap_events_socket_set_readable_py(PyDapEventsSocketObject *self, PyObject *args){ + if (self->t_events_socket == NULL){ + return NULL; + } + PyObject *l_is_ready; + if (!PyArg_ParseTuple(args, "O", &l_is_ready)){ + return NULL; + } + bool is_ready = true; + if (l_is_ready == Py_False) + is_ready = false; + dap_events_socket_set_readable(self->t_events_socket, is_ready); + return PyLong_FromLong(0); +} +PyObject *dap_events_socket_set_writable_py(PyDapEventsSocketObject *self, PyObject *args){ + if (self->t_events_socket == NULL){ + return NULL; + } + PyObject *l_is_ready; + if (!PyArg_ParseTuple(args, "O", &l_is_ready)){ + return NULL; + } + bool is_ready = true; + if (l_is_ready == Py_False) + is_ready = false; + dap_events_socket_set_writable(self->t_events_socket, is_ready); + return PyLong_FromLong(0); +} + +PyObject *dap_events_socket_write_py(PyDapEventsSocketObject *self, PyObject *args){ + if (self->t_events_socket == NULL){ + return NULL; + } + PyBytesObject *in_bytes; + size_t in_size; + if (!PyArg_ParseTuple(args, "S|n", &in_bytes, &in_size)){ + return NULL; + } + char *in_v_bytes = PyBytes_AsString((PyObject*)in_bytes); + size_t res_size = dap_events_socket_write(self->t_events_socket, + in_v_bytes, in_size); + return Py_BuildValue("n", res_size); +} +PyObject *dap_events_socket_write_f_py(PyDapEventsSocketObject *self, PyObject *args){ + if (self->t_events_socket == NULL){ + return NULL; + } + const char *format; + PyTupleObject *pto; + if (!PyArg_ParseTuple(args, "s|O", &format, &pto)){ + return NULL; + } + va_list ap; + if (!PyArg_VaParse(args, format, ap)){ + return NULL; + } + size_t res_size = dap_events_socket_write_f(self->t_events_socket, format, ap); + return Py_BuildValue("n", res_size); +} +PyObject *dap_events_socket_read_py(PyDapEventsSocketObject *self, PyObject *args){ + if (self->t_events_socket == NULL){ + return NULL; + } + size_t in_size; + if (!PyArg_ParseTuple(args, "n", &in_size)){ + return NULL; + } + void *res = DAP_NEW_SIZE(void*, in_size); + size_t res_size = dap_events_socket_read(self->t_events_socket, res, in_size); + PyBytesObject *res_obj = (PyBytesObject*)PyBytes_FromString(res); + return Py_BuildValue("nS", res_size, res_obj); +} + +PyObject *dap_events_socket_delete_py(PyDapEventsSocketObject *self, PyObject *args){ + if (self->t_events_socket == NULL){ + return NULL; + } + PyObject *in_bool; + if (!PyArg_ParseTuple(args, "O", &in_bool)){ + return NULL; + } + bool boolean = true; + if (in_bool == Py_False) + boolean = false; + dap_events_socket_delete(self->t_events_socket, boolean); + return PyLong_FromLong(0); +} + +PyObject *dap_events_socket_shrink_buf_in_py(PyDapEventsSocketObject *self, PyObject *args){ + if (self->t_events_socket == NULL){ + return NULL; + } + size_t in_size; + if(!PyArg_ParseTuple(args, "n", &in_size)){ + return NULL; + } + dap_events_socket_shrink_buf_in(self->t_events_socket, in_size); + return PyLong_FromLong(0); +} + diff --git a/cellframe-sdk-python/libdap-server-core-python/src/libdap-server-core-python.c b/cellframe-sdk-python/libdap-server-core-python/src/libdap-server-core-python.c new file mode 100644 index 0000000000000000000000000000000000000000..e38c6e6226bd10513e75e86ad0ef8f41a699e5f4 --- /dev/null +++ b/cellframe-sdk-python/libdap-server-core-python/src/libdap-server-core-python.c @@ -0,0 +1,43 @@ +#include "libdap-server-core-python.h" + +#define LOG_TAG "libdap-server-core-python" + +int dap_server_core_init(uint32_t l_thread_cnt, size_t conn_t){ + int result = dap_server_init(l_thread_cnt); + if ( result != 0 ) { + log_it( L_CRITICAL, "Can't init socket server module" ); + } + dap_events_init(l_thread_cnt, conn_t); + dap_client_remote_init(); + return result; +} + +void dap_server_core_deinit(void){ + dap_client_remote_deinit(); + dap_server_deinit(); + dap_events_deinit(); +} + +PyObject *dap_server_core_loop(PyObject *self, PyObject *args){ + PyObject *obj_server; + if (!PyArg_ParseTuple(args, "O", &obj_server)){ + return NULL; + } + int32_t result = dap_server_loop(((PyDapServerObject*)obj_server)->t_server); + log_it( result ? L_CRITICAL : L_NOTICE, "Server loop stopped with return code %d", ((PyDapServerObject*)obj_server)->t_server ); + return PyLong_FromLong(result); +} + +PyObject *dap_server_core_listen(PyObject *self, PyObject *args){ + const char *addr; + uint16_t port; + uint16_t type; + if (!PyArg_ParseTuple(args, "s|H|H", &addr, &port, &type)){ + return NULL; + } + if (type > 1) + return NULL; + PyObject *obj = _PyObject_New(&dapServer_dapServerType); + ((PyDapServerObject*)obj)->t_server = dap_server_listen(addr, port, type); + return Py_BuildValue("O", obj); +} diff --git a/cellframe-sdk-python/libdap-server-core-python/test/test.py b/cellframe-sdk-python/libdap-server-core-python/test/test.py new file mode 100644 index 0000000000000000000000000000000000000000..4f48404824177add2a2bd50e4d5065967cb954a9 --- /dev/null +++ b/cellframe-sdk-python/libdap-server-core-python/test/test.py @@ -0,0 +1,6 @@ +import libDapServerCore as server + +print ("Start wrapping libdap server core python module") +res_i = server.init(1, 0, "TestServer", "TestServer.txt") +rc = server.listen("0.0.0.0", 3307, 0) +server.deinit()