diff --git a/CMakeLists.txt b/CMakeLists.txt index a13d8b2b1fe..e45804eeb24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -190,13 +190,6 @@ if(WIN32) target_link_libraries(open62541 ws2_32) #since networklayer_tcp is linked into the amalgate endif() -# build language bindings for the library -option(ENABLE_BINDING_LUA "Build Lua bindings" OFF) -option(ENABLE_BINDING_PYTHON "Build Python bindings" OFF) -if(ENABLE_BINDING_LUA OR ENABLE_BINDING_PYTHON) - add_subdirectory(bindings) -endif() - # coverage option(ENABLE_COVERAGE "Enable gcov coverage" OFF) if(ENABLE_COVERAGE) diff --git a/bindings/CMakeLists.txt b/bindings/CMakeLists.txt deleted file mode 100644 index f4113bd792a..00000000000 --- a/bindings/CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -FIND_PACKAGE(SWIG REQUIRED) -INCLUDE(UseSWIG) - -if(ENABLE_BINDING_LUA) - FIND_PACKAGE(Lua51) - file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/lua) - add_custom_command (OUTPUT ${PROJECT_BINARY_DIR}/lua/lua_wrap.c - COMMAND ${SWIG_EXECUTABLE} -lua - -I${PROJECT_SOURCE_DIR}/include - -o ${PROJECT_BINARY_DIR}/lua/lua_wrap.c - ${PROJECT_SOURCE_DIR}/bindings/open62541.i - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/open62541.i) - add_library(open62541-lua SHARED ${PROJECT_BINARY_DIR}/lua/lua_wrap.c) - set_target_properties(open62541-lua PROPERTIES COMPILE_FLAGS "-Wno-error") - target_include_directories(open62541-lua PUBLIC ${LUA_INCLUDE_DIR} ${PROJECT_SOURCE_DIR}/include - ${PROJECT_BINARY_DIR}/src_generated) - target_link_libraries(open62541-lua open62541-static) - set_target_properties(open62541-lua PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lua - OUTPUT_NAME open62541 PREFIX "") -endif() - -if(ENABLE_BINDING_PYTHON) - FIND_PACKAGE(PythonLibs) - file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/python) - add_custom_command (OUTPUT ${PROJECT_BINARY_DIR}/python/python_wrap.c - COMMAND ${SWIG_EXECUTABLE} -python - -I${PROJECT_SOURCE_DIR}/include - -o ${PROJECT_BINARY_DIR}/python/python_wrap.c - ${PROJECT_SOURCE_DIR}/bindings/open62541.i - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/open62541.i) - add_library(open62541-python SHARED ${PROJECT_BINARY_DIR}/python/python_wrap.c) - set_target_properties(open62541-python PROPERTIES COMPILE_FLAGS "-Wno-error") - target_include_directories(open62541-python PUBLIC ${PYTHON_INCLUDE_DIR} ${PROJECT_SOURCE_DIR}/include - ${PROJECT_BINARY_DIR}/src_generated) - target_link_libraries(open62541-python open62541-static) - set_target_properties(open62541-python PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/python - OUTPUT_NAME _open62541 PREFIX "") -endif() diff --git a/bindings/open62541.i b/bindings/open62541.i deleted file mode 100644 index eaeca7f464e..00000000000 --- a/bindings/open62541.i +++ /dev/null @@ -1,45 +0,0 @@ -%module open62541 -%{ -#include "ua_types.h" -#include "ua_server.h" -%} - -%define UA_TYPE_HANDLING_FUNCTIONS_SWIG(TYPE) - TYPE * TYPE##_new(void); - void TYPE##_init(TYPE * p); - void TYPE##_delete(TYPE * p); - void TYPE##_deleteMembers(TYPE * p); - UA_StatusCode TYPE##_copy(const TYPE *src, TYPE *dst); -%enddef - -%define UA_EXPORT -%enddef - -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_Boolean) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_SByte) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_Byte) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_Int16) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_UInt16) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_Int32) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_UInt32) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_Int64) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_UInt64) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_Float) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_Double) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_String) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_DateTime) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_Guid) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_ByteString) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_XmlElement) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_NodeId) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_ExpandedNodeId) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_StatusCode) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_QualifiedName) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_LocalizedText) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_ExtensionObject) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_DataValue) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_Variant) -UA_TYPE_HANDLING_FUNCTIONS_SWIG(UA_DiagnosticInfo) - -%include "ua_types.h" -%include "ua_server.h" diff --git a/src/ongoing/generateSam.c b/src/ongoing/generateSam.c deleted file mode 100644 index eb220861080..00000000000 --- a/src/ongoing/generateSam.c +++ /dev/null @@ -1,281 +0,0 @@ -#include "ua_xml.h" -#include "ua_namespace.h" -#include "ua_namespace_xml.h" -#include "ua_types_generated.h" -#include // tolower - -/** @brief we need a variable global to the module to make it possible for the visitors to access the namespace */ -static Namespace* theNamespace; - -UA_Int32 UA_Node_getParent(const UA_Node* node, const UA_Node** parent) { - UA_Int32 i = 0; - DBG(printf("// UA_Node_getParent - node={i=%d}",node->nodeId.identifier.numeric)); - // FIXME: the data model is crap! we should have a single memory location which holds the parent NodeId - for (; i < node->referencesSize; i++ ) { - UA_Int32 refId = node->references[i].referenceTypeId.identifier.numeric; - UA_Int32 isInverse = node->references[i].isInverse; - if (isInverse && (refId == 47 || refId == 46)) { - UA_Int32 retval = Namespace_get(theNamespace, &(node->references[i].targetId.nodeId),parent); - if (retval == UA_SUCCESS) { - DBG(printf(" has parent={i=%d}\n",(*parent)->nodeId.identifier.numeric)); - } else { - DBG(printf(" has non-existing parent={i=%d}\n", node->references[i].targetId.nodeId.identifier.numeric)); - } - return retval; - } - } - // there is no parent, we are root - DBG(printf(" is root\n")); - *parent = UA_NULL; - return UA_SUCCESS; -} - -/** @brief recurse down to root and return root node */ -UA_Int32 UA_Node_getRoot(const UA_Node* node, const UA_Node** root) { - UA_Int32 retval = UA_SUCCESS; - const UA_Node* parent = UA_NULL; - if ( (retval = UA_Node_getParent(node,&parent)) == UA_SUCCESS ) { - if (parent != UA_NULL) { // recurse down to root node - retval = UA_Node_getRoot(parent,root); - } else { // node is root, terminate recursion - *root = node; - } - } - return retval; -} - -/** @brief check if VariableNode needs a memory object. This is the - * case if the parent is of type object and the root is type object - **/ -_Bool UA_VariableNode_needsObject(const UA_VariableNode* node) { - const UA_Node* parent = UA_NULL; - if ( UA_Node_getParent((UA_Node*)node,&parent) == UA_SUCCESS ) { - if (parent == UA_NULL) - return UA_TRUE; - if (parent->nodeClass == UA_NODECLASS_OBJECT ) { - const UA_Node* root; - if (UA_Node_getRoot(parent,&root) == UA_SUCCESS) - if (root == UA_NULL || root->nodeClass == UA_NODECLASS_OBJECT ) - return UA_TRUE; - } - } - return UA_FALSE; -} - -/** @brief recurse down to root and get full qualified name */ -UA_Int32 UA_Node_getPath(const UA_Node* node, UA_list_List* list) { - UA_Int32 retval = UA_SUCCESS; - const UA_Node* parent = UA_NULL; - if ( (retval = UA_Node_getParent(node,&parent)) == UA_SUCCESS ) { - if (parent != UA_NULL) { - // recurse down to root node - UA_Int32 retval = UA_Node_getPath(parent,list); - // and add our own name when we come back - if (retval == UA_SUCCESS) { - UA_list_addPayloadToBack(list,(void*)&(node->browseName.name)); - DBG(printf("// UA_Node_getPath - add id={i=%d},class=%d",node->nodeId.identifier.numeric,node->nodeClass)); - DBG(UA_String_printf(",name=",&(node->browseName.name))); - } - } else { - // node is root, terminate recursion by adding own name - UA_list_addPayloadToBack(list,(void*)&node->browseName.name); - DBG(printf("// UA_Node_getPath - add id={i=%d},class=%d",node->nodeId.identifier.numeric,node->nodeClass)); - DBG(UA_String_printf(",name=",&(node->browseName.name))); - } - } - return retval; -} - - -/** @brief some macros to lowercase the first character without copying around */ -#define F_cls "%c%.*s" -#define LC_cls(str) tolower((str).data[0]), (str).length-1, &((str).data[1]) - -void listPrintName(void * payload) { - UA_ByteString* name = (UA_ByteString*) payload; - if (name->length > 0) { - printf("_" F_cls, LC_cls(*name)); - } -} - -/** @brief declares all the top level objects in the server's application memory */ -void sam_declareAttribute(UA_Node const * node) { - if (node->nodeClass == UA_NODECLASS_VARIABLE && UA_VariableNode_needsObject((UA_VariableNode*)node)) { - UA_list_List list; UA_list_init(&list); - UA_Int32 retval = UA_Node_getPath(node,&list); - if (retval == UA_SUCCESS) { - UA_VariableNode* vn = (UA_VariableNode*) node; - printf("\t%s ", UA_.types[UA_ns0ToVTableIndex(&vn->nodeId)].name); - UA_list_iteratePayload(&list,listPrintName); - printf("; // i=%d\n", node->nodeId.identifier.numeric); - } else { - printf("// could not determine path for i=%d\n",node->nodeId.identifier.numeric); - } - UA_list_destroy(&list,UA_NULL); - } -} - -/** @brief declares all the buffers for string variables - * FIXME: shall traverse down to the root object and create a unique name such as cstr_serverState_buildInfo_version - */ -void sam_declareBuffer(UA_Node const * node) { - if (node != UA_NULL && node->nodeClass == UA_NODECLASS_VARIABLE) { - UA_VariableNode* vn = (UA_VariableNode*) node; - switch (vn->dataType.identifier.numeric) { - case UA_BYTESTRING_NS0: - case UA_STRING_NS0: - case UA_LOCALIZEDTEXT_NS0: - case UA_QUALIFIEDNAME_NS0: - printf("UA_Byte cstr_" F_cls "[] = \"\"\n",LC_cls(vn->browseName.name)); - break; - default: - break; - } - } -} - -/** @brief assigns the c-strings to the ua type strings. - * FIXME: traverse down to top level objects and create a unique name such as cstr_serverState_buildInfo_version - */ -void sam_assignBuffer(UA_Node const * node) { - if (node != UA_NULL && node->nodeClass == UA_NODECLASS_VARIABLE) { - UA_VariableNode* vn = (UA_VariableNode*) node; - switch (vn->dataType.identifier.numeric) { - case UA_BYTESTRING_NS0: - case UA_STRING_NS0: - printf("\tSAM_ASSIGN_CSTRING(cstr_" F_cls ",sam." F_cls ");\n",LC_cls(vn->browseName.name),LC_cls(vn->browseName.name)); - break; - case UA_LOCALIZEDTEXT_NS0: - printf("\tSAM_ASSIGN_CSTRING(cstr_" F_cls ",sam." F_cls ".text);\n",LC_cls(vn->browseName.name),LC_cls(vn->browseName.name)); - break; - case UA_QUALIFIEDNAME_NS0: - printf("\tSAM_ASSIGN_CSTRING(cstr_" F_cls ",sam." F_cls ".name);\n",LC_cls(vn->browseName.name),LC_cls(vn->browseName.name)); - break; - default: - break; - } - } -} - -void sam_attachToNamespace(UA_Node const * node) { - if (node != UA_NULL && node->nodeClass == UA_NODECLASS_VARIABLE) { - UA_VariableNode* vn = (UA_VariableNode*) node; - printf("\tsam_attach(ns,%d,%s,&sam." F_cls ");\n",node->nodeId.identifier.numeric,UA_.types[UA_ns0ToVTableIndex(&vn->dataType)].name, LC_cls(vn->browseName.name)); - } -} - -UA_Int32 Namespace_getNumberOfComponents(Namespace const * ns, UA_NodeId const * id, UA_Int32* number) { - UA_Int32 retval = UA_SUCCESS; - UA_Node const * node; - if ((retval = Namespace_get(ns,id,&node)) != UA_SUCCESS) - return UA_ERR_INVALID_VALUE; - UA_Int32 i, n; - for (i = 0, n = 0; i < node->referencesSize; i++ ) { - if (node->references[i].referenceTypeId.identifier.numeric == 47 && node->references[i].isInverse != UA_TRUE) { - n++; - } - } - Namespace_releaseManagedNode(node); - *number = n; - return retval; -} - -UA_Int32 Namespace_getComponent(Namespace const * ns, UA_NodeId const * id, UA_Int32 idx, UA_NodeId** result) { - UA_Int32 retval = UA_SUCCESS; - - UA_Node const * node; - if ((retval = Namespace_get(ns,id,&node)) != UA_SUCCESS) - return retval; - - UA_Int32 i, n; - for (i = 0, n = 0; i < node->referencesSize; i++ ) { - if (node->references[i].referenceTypeId.identifier.numeric == 47 && node->references[i].isInverse != UA_TRUE) { - n++; - if (n == idx) { - *result = &(node->references[i].targetId.nodeId); - Namespace_releaseManagedNode(node); - return retval; - } - } - } - Namespace_releaseManagedNode(node); - return UA_ERR_INVALID_VALUE; -} - - -UA_Int32 UAX_NodeId_encodeBinaryByMetaData(Namespace const * ns, UA_NodeId const * id, UA_UInt32* pos, UA_ByteString *dst) { - UA_Int32 i, retval = UA_SUCCESS; - if (UA_NodeId_isBasicType(id)) { - const UA_Node * result; - if ((retval = Namespace_get(ns,id,&result)) == UA_SUCCESS) { - UA_Variant_encodeBinary(&((UA_VariableNode *) result)->value,dst,pos); - Namespace_releaseManagedNode(result); - } - } else { - UA_Int32 nComp = 0; - if ((retval = Namespace_getNumberOfComponents(ns,id,&nComp)) == UA_SUCCESS) { - for (i=0; i < nComp; i++) { - UA_NodeId* comp = UA_NULL; - Namespace_getComponent(ns,id,i,&comp); - UAX_NodeId_encodeBinaryByMetaData(ns,comp, pos, dst); - } - } - } - return retval; -} - -UA_Int32 UAX_NodeId_encodeBinary(Namespace const * ns, UA_NodeId const * id, UA_ByteString *dst, UA_UInt32* offset) { - UA_Int32 retval = UA_SUCCESS; - UA_Node const * node; - if ((retval = Namespace_get(ns,id,&node)) == UA_SUCCESS) { - if (node->nodeClass == UA_NODECLASS_VARIABLE) { - retval = UA_Variant_encodeBinary(&((UA_VariableNode*) node)->value,dst,offset); - } - Namespace_releaseManagedNode(node); - } - return retval; -} - - -/** @ brief poor man's text template processor - * for p in patterns: print p.s, iterate over namespace with p.v */ -typedef struct pattern { - char* s; - Namespace_nodeVisitor v; -} pattern; - -pattern p[] = { -{ "/** server application memory - generated but manually adapted */\n",UA_NULL }, -{ "#define SAM_ASSIGN_CSTRING(src,dst) do { dst.length = strlen(src)-1; dst.data = (UA_Byte*) src; } while(0)\n",UA_NULL }, -{ "struct sam {\n", sam_declareAttribute }, -{ "} sam;\n", UA_NULL }, -{ UA_NULL, sam_declareBuffer }, -{ "void sam_init(Namespace* ns) {\n", sam_assignBuffer }, -{ UA_NULL, sam_attachToNamespace }, -{ "}\n", UA_NULL }, -{UA_NULL, UA_NULL} // terminal node : both elements UA_NULL -}; - -int main(int argc, char** argv) { - if (argc != 2) { - printf("usage: %s filename\n",argv[0]); - } else { - Namespace* ns; - if (Namespace_loadFromFile(&ns,0,"ROOT",argv[1]) != UA_SUCCESS) { - printf("error loading file {%s}\n", argv[1]); - } else { - theNamespace = ns; - for (pattern* pi = &p[0]; pi->s != UA_NULL || pi->v != UA_NULL; ++pi) { - if (pi->s) { - printf("%s",pi->s); - } - if (pi->v) { - Namespace_iterate(ns, pi->v); - } - } - // FIXME: crashes with a seg fault - // Namespace_delete(ns); - } - } - return 0; -} diff --git a/src/ongoing/opcuaServerMini.c b/src/ongoing/opcuaServerMini.c deleted file mode 100644 index 8b5d021a8b1..00000000000 --- a/src/ongoing/opcuaServerMini.c +++ /dev/null @@ -1,344 +0,0 @@ -/* - * This work is licensed under a Creative Commons CCZero 1.0 Universal License. - * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. - */ - -/************************************************************** - * opcuaServerMini is a pathologically unstructured bare bone - * implementation of the 62541 communications w/o any structures - * or comfort. Furthermore, the implementation assumes a - * little endian target and consequently ignores all the rules - * of 62541 towards security. - * - * The nice thing about this approach is that you can easily see - * that the memory footprint of a simple server can be held - * quite small and memory allocation capabilities is not needed - * as long as features are consequently minimized. - ****************************************************************/ - -#include -#include -#include -#include // errno, EINTR - - -#include "ua_statuscodes.h" -#include "ua_transport.h" -#include "ua_transport_binary.h" -#include "networklayer.h" - -#ifdef LINUX - -#include -#include -#include -#include -#include - -void server_run(); - -#endif - -#define PORT 16664 -#define MAXMSG 512 -#define BUFFER_SIZE 8192 - -int main(void) { - -#ifdef LINUX - printf("Starting open62541 demo server on port %d\n", PORT); - server_run(); -#endif - - return EXIT_SUCCESS; -} - -#ifdef LINUX - -UA_Byte ack_msg_buf[] = { 0x41, 0x43, /* AC */ -0x4b, 0x46, 0x1c, 0x00, 0x00, 0x00, 0xff, 0xff, /* KF...... */ -0xff, 0xff, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, /* ... ... */ -0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, /* ...@.... */ -0x00, 0x00 /* .. */ -}; -UA_ByteString ack_msg = { sizeof(ack_msg_buf), ack_msg_buf }; -UA_ByteString* ack_msg_gb[] = { &ack_msg }; - - -UA_Byte opn_msg_buf[] = { 0x4f, 0x50, /* OP */ -0x4e, 0x46, 0x88, 0x00, 0x00, 0x00, 0x19, 0x00, /* NF...... */ -0x00, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x68, 0x74, /* ../...ht */ -0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x6f, 0x70, 0x63, /* tp://opc */ -0x66, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, 0x69, /* foundati */ -0x6f, 0x6e, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x55, /* on.org/U */ -0x41, 0x2f, 0x53, 0x65, 0x63, 0x75, 0x72, 0x69, /* A/Securi */ -0x74, 0x79, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, /* tyPolicy */ -0x23, 0x4e, 0x6f, 0x6e, 0x65, 0xff, 0xff, 0xff, /* #None... */ -0xff, 0xff, 0xff, 0xff, 0xff, 0x33, 0x00, 0x00, /* .....3.. */ -0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0xc1, /* ........ */ -0x01, 0x10, 0x56, 0x73, 0x9e, 0xdf, 0x63, 0xcf, /* ..Vs..c. */ -0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */ -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */ -0x00, 0xff, 0xff, 0xff, 0xff, 0x19, 0x00, 0x00, /* ........ */ -0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */ -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */ -0x00, 0x01, 0x00, 0x00, 0x00, 0x48 /* .....H */ -}; - -UA_ByteString opn_msg = { sizeof(opn_msg_buf), opn_msg_buf }; -UA_ByteString* opn_msg_gb[] = { &opn_msg }; - -UA_Byte scm_msg_buf[] = { 0x4d, 0x53, /* MS */ -0x47, 0x46, 0x8b, 0x01, 0x00, 0x00, 0x19, 0x00, /* GF.. */ // = msglen. TODO: should be set or checked by writer? -0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x34, 0x00, /* ......4. */ -0x00, 0x00, 0x02, 0x00, 0x00, 0x00 /* ...... */ -}; -UA_Byte rsp_msg_buf[] = { 0x01, 0x00, /* ........ */ -0xaf, 0x01, 0x2c, 0xc1, 0x73, 0x9e, 0xdf, 0x63, /* <> = response nS0-ID -0xcf, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, /* X>.... = timestamp, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* A>...... */ // = statuscode -0x00, 0x00 /* .. */ -}; - -UA_Byte gep_msg_buf[] = { - 0x01, 0x00, 0x00, 0x00, 0x1b, 0x00, /* ...... */ -0x00, 0x00, 0x6f, 0x70, 0x63, 0x2e, 0x74, 0x63, /* ..opc.tc */ -0x70, 0x3a, 0x2f, 0x2f, 0x31, 0x30, 0x2e, 0x30, /* p://10.0 */ -0x2e, 0x35, 0x33, 0x2e, 0x31, 0x39, 0x38, 0x3a, /* .53.198: */ -0x31, 0x36, 0x36, 0x36, 0x34, 0x27, 0x00, 0x00, /* 16664'.. */ -0x00, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, /* .http:// */ -0x6f, 0x70, 0x65, 0x6e, 0x36, 0x32, 0x35, 0x34, /* open6254 */ -0x31, 0x2e, 0x69, 0x6e, 0x66, 0x6f, 0x2f, 0x61, /* 1.info/a */ -0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, /* pplicati */ -0x6f, 0x6e, 0x73, 0x2f, 0x34, 0x37, 0x31, 0x31, /* ons/4711 */ -0x25, 0x00, 0x00, 0x00, 0x68, 0x74, 0x74, 0x70, /* %...http */ -0x3a, 0x2f, 0x2f, 0x6f, 0x70, 0x65, 0x6e, 0x36, /* ://open6 */ -0x32, 0x35, 0x34, 0x31, 0x2e, 0x69, 0x6e, 0x66, /* 2541.inf */ -0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, /* o/produc */ -0x74, 0x2f, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, /* t/releas */ -0x65, 0x03, 0x02, 0x00, 0x00, 0x00, 0x45, 0x4e, /* e.....EN */ -0x19, 0x00, 0x00, 0x00, 0x54, 0x68, 0x65, 0x20, /* ....The */ -0x6f, 0x70, 0x65, 0x6e, 0x36, 0x32, 0x35, 0x34, /* open6254 */ -0x31, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, /* 1 applic */ -0x61, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, /* ation... */ -0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* ........ */ -0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, /* ........ */ -0xff, 0x01, 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00, /* ...../.. */ -0x00, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, /* .http:// */ -0x6f, 0x70, 0x63, 0x66, 0x6f, 0x75, 0x6e, 0x64, /* opcfound */ -0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x6f, 0x72, /* ation.or */ -0x67, 0x2f, 0x55, 0x41, 0x2f, 0x53, 0x65, 0x63, /* g/UA/Sec */ -0x75, 0x72, 0x69, 0x74, 0x79, 0x50, 0x6f, 0x6c, /* urityPol */ -0x69, 0x63, 0x79, 0x23, 0x4e, 0x6f, 0x6e, 0x65, /* icy#None */ -0x01, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, /* ........ */ -0x6d, 0x79, 0x2d, 0x61, 0x6e, 0x6f, 0x6e, 0x79, /* my-anony */ -0x6d, 0x6f, 0x75, 0x73, 0x2d, 0x70, 0x6f, 0x6c, /* mous-pol */ -0x69, 0x63, 0x79, 0x00, 0x00, 0x00, 0x00, 0xff, /* icy..... */ -0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* ........ */ -0xff, 0xff, 0xff, 0x41, 0x00, 0x00, 0x00, 0x68, /* ...A...h */ -0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x6f, 0x70, /* ttp://op */ -0x63, 0x66, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, /* cfoundat */ -0x69, 0x6f, 0x6e, 0x2e, 0x6f, 0x72, 0x67, 0x2f, /* ion.org/ */ -0x55, 0x41, 0x2d, 0x50, 0x72, 0x6f, 0x66, 0x69, /* UA-Profi */ -0x6c, 0x65, 0x2f, 0x54, 0x72, 0x61, 0x6e, 0x73, /* le/Trans */ -0x70, 0x6f, 0x72, 0x74, 0x2f, 0x75, 0x61, 0x74, /* port/uat */ -0x63, 0x70, 0x2d, 0x75, 0x61, 0x73, 0x63, 0x2d, /* cp-uasc- */ -0x75, 0x61, 0x62, 0x69, 0x6e, 0x61, 0x72, 0x79, /* uabinary */ -0x00 /* . */ -}; - -UA_Byte csr_msg_buf[] = { - 0x01, 0x01, 0x9a, 0x02, 0x00, 0x00, /* .. */ // = sessionID -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */ -0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* ........ */ -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */ -0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* ........ */ -0x00, 0x00, 0x00, 0x00 /* .... */ -}; - -UA_Byte asr_msg_buf[] = { - 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, /* ...... */ -0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* ...... */ -}; -UA_ByteString scm_msg = { sizeof(scm_msg_buf), scm_msg_buf }; -UA_ByteString rsp_msg = { sizeof(rsp_msg_buf), rsp_msg_buf }; -UA_ByteString* sf_msg_gb[] = { &scm_msg, &rsp_msg }; // servicefault - -UA_ByteString gep_msg = { sizeof(gep_msg_buf), gep_msg_buf }; -UA_ByteString* gep_msg_gb[] = { &scm_msg, &rsp_msg, &gep_msg }; //getendpoint response - -UA_ByteString csr_msg = { sizeof(csr_msg_buf), csr_msg_buf }; -UA_ByteString* csr_msg_gb[] = { &scm_msg, &rsp_msg, &csr_msg }; // create session response - -UA_ByteString asr_msg = { sizeof(asr_msg_buf), asr_msg_buf }; -UA_ByteString* asr_msg_gb[] = { &scm_msg, &rsp_msg, &asr_msg }; // activate session response - -UA_Int32 myProcess(TL_Connection* connection, const UA_ByteString* msg) { - switch (*((UA_Int32*) &(msg->data[0]))) { // compare first four bytes - case 0x464c4548: // HELF - connection->writerCallback(connection, (const UA_ByteString**) &ack_msg_gb, 1); - break; - case 0x464e504f: // OPNF - connection->writerCallback(connection, (const UA_ByteString**) &opn_msg_gb, 1); - break; - case 0x464f4c43: // CLOF - connection->connectionState = CONNECTIONSTATE_CLOSE; - break; - case 0x4647534d: // MSGF - switch (*((UA_Int16*) &(msg->data[26]))) { - case 428: // GetEndpointsRequest -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" - printf("server_run - GetEndpointsRequest\n"); - *(UA_Int32*) (&scm_msg_buf[4]) = sizeof(scm_msg_buf) + sizeof(rsp_msg_buf) + sizeof(gep_msg_buf); - *(UA_Int16*) (&rsp_msg_buf[2]) = *(UA_Int16*) (&msg->data[26]) + 3; - *(UA_Int32*) (&rsp_msg_buf[16]) = UA_STATUSCODE_GOOD; - connection->writerCallback(connection, (const UA_ByteString**) &gep_msg_gb, 3); - break; - case 461: // CreateSessionRequest - printf("server_run - CreateSessionRequest\n"); - *(UA_Int32*) (&scm_msg_buf[4]) = sizeof(scm_msg_buf) + sizeof(rsp_msg_buf) + sizeof(csr_msg_buf); - *(UA_Int16*) (&rsp_msg_buf[2]) = *(UA_Int16*) (&msg->data[26]) + 3; - *(UA_Int32*) (&rsp_msg_buf[16]) = UA_STATUSCODE_GOOD; - connection->writerCallback(connection, (const UA_ByteString**) &csr_msg_gb, 3); - break; - case 467: // FIXME: ActivateSessionRequest - printf("server_run - ActivateSessionRequest\n"); - *(UA_Int32*) (&scm_msg_buf[4]) = sizeof(scm_msg_buf) + sizeof(rsp_msg_buf) + sizeof(asr_msg_buf); - *(UA_Int16*) (&rsp_msg_buf[2]) = *(UA_Int16*) (&msg->data[26]) + 3; - *(UA_Int32*) (&rsp_msg_buf[16]) = UA_STATUSCODE_GOOD; - connection->writerCallback(connection, (const UA_ByteString**) &asr_msg_gb, 3); - break; - default: // unknown service - send a simple response header of type UA_SERVICEFAULT - *(UA_Int32*) (&scm_msg_buf[4]) = sizeof(scm_msg_buf) + sizeof(rsp_msg_buf); - *(UA_Int16*) (&rsp_msg_buf[2]) = UA_SERVICEFAULT_NS0 + 2; // encodingBinary - *(UA_Int32*) (&rsp_msg_buf[16]) = UA_STATUSCODE_BADNOTIMPLEMENTED; -#pragma GCC diagnostic pop - printf("server_run - unknown request %d\n", *((UA_Int16*) &(msg->data[26]))); - connection->writerCallback(connection, (const UA_ByteString**) &sf_msg_gb, 2); - break; - } - break; - } - return UA_SUCCESS; -} - -/** write message provided in the gather buffers to a tcp transport layer connection */ -UA_Int32 myWriter(struct TL_Connection const * c, UA_ByteString const * const * gather_buf, UA_UInt32 gather_len) { - - struct iovec iov[gather_len]; - UA_UInt32 total_len = 0; - for(UA_UInt32 i=0;idata; - iov[i].iov_len = gather_buf[i]->length; - total_len += gather_buf[i]->length; - } - - struct msghdr message; - message.msg_name = UA_NULL; - message.msg_namelen = 0; - message.msg_iov = iov; - message.msg_iovlen = gather_len; - message.msg_control = UA_NULL; - message.msg_controllen = 0; - message.msg_flags = 0; - - UA_UInt32 nWritten = 0; - while (nWritten < total_len) { - int n=0; - do { - DBG_VERBOSE(printf("myWriter - enter write with %d bytes to write\n",total_len)); - n = sendmsg(c->connectionHandle, &message, 0); - DBG_VERBOSE(printf("myWriter - leave write with n=%d,errno={%d,%s}\n",n,(n>0)?0:errno,(n>0)?"":strerror(errno))); - } while (n == -1L && errno == EINTR); - if (n >= 0) { - nWritten += n; - break; - // TODO: handle incompletely send messages - } else { - break; - // TODO: error handling - } - } - return UA_SUCCESS; -} - -void server_run() { - TL_Connection connection; - connection.connectionState = CONNECTIONSTATE_CLOSED; - connection.writerCallback = (TL_Writer) myWriter; - connection.localConf.maxChunkCount = 1; - connection.localConf.maxMessageSize = BUFFER_SIZE; - connection.localConf.protocolVersion = 0; - connection.localConf.recvBufferSize = BUFFER_SIZE; - connection.localConf.recvBufferSize = BUFFER_SIZE; - - UA_ByteString slMessage = { -1, UA_NULL }; - - int optval = 1; - int sockfd, newsockfd, portno, clilen; - char buffer[BUFFER_SIZE]; - struct sockaddr_in serv_addr, cli_addr; - int n; - - /* First call to socket() function */ - sockfd = socket(PF_INET, SOCK_STREAM, 0); - if (sockfd < 0) { - perror("ERROR opening socket"); - exit(1); - } - - /* Initialize socket structure */ - memset((void *) &serv_addr, 0, sizeof(serv_addr)); - portno = PORT; - serv_addr.sin_family = AF_INET; - serv_addr.sin_addr.s_addr = INADDR_ANY; - serv_addr.sin_port = htons(portno); - - if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval) == -1) { - perror("setsockopt"); - exit(1); - } - - /* Now bind the host address using bind() call.*/ - if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) { - perror("ERROR on binding"); - exit(1); - } - - /* Now start listening for the clients, here process will - * go in sleep mode and will wait for the incoming connection - */ - while (listen(sockfd, 5) != -1) { - clilen = sizeof(cli_addr); - /* Accept actual connection from the client */ - newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t*) &clilen); - if (newsockfd < 0) { - perror("ERROR on accept"); - exit(1); - } - - printf("server_run - connection accepted: %i, state: %i\n", newsockfd, connection.connectionState); - connection.connectionHandle = newsockfd; - do { - memset(buffer, 0, BUFFER_SIZE); - n = read(newsockfd, buffer, BUFFER_SIZE); - if (n > 0) { - slMessage.data = (UA_Byte*) buffer; - slMessage.length = n; - DBG(printf("server_run - received=%d\n",n)); - myProcess(&connection, &slMessage); - } else if (n <= 0) { - perror("ERROR reading from socket1"); - connection.connectionState = CONNECTIONSTATE_CLOSE; - } - } while(connection.connectionState != CONNECTIONSTATE_CLOSE); - shutdown(newsockfd,2); - close(newsockfd); - connection.connectionState = CONNECTIONSTATE_CLOSED; - } - shutdown(sockfd,2); - close(sockfd); -} - -#endif diff --git a/src/ongoing/ua_base64.c b/src/ongoing/ua_base64.c deleted file mode 100644 index 8f952ee94a5..00000000000 --- a/src/ongoing/ua_base64.c +++ /dev/null @@ -1,149 +0,0 @@ -/* - begin library headers - */ - -/* - cdecode.h - c header for a base64 decoding algorithm - - This is part of the libb64 project, and has been placed in the public domain. - For details, see http://sourceforge.net/projects/libb64 - */ -#ifndef BASE64_CDECODE_H -#define BASE64_CDECODE_H - -typedef enum { - step_a, step_b, step_c, step_d -} base64_decodestep; - -typedef struct { - base64_decodestep step; - char plainchar; -} base64_decodestate; - -void base64_init_decodestate(base64_decodestate *state_in); - -int base64_decode_value(char value_in); - -int base64_decode_block(const char *code_in, const int length_in, char *plaintext_out, - base64_decodestate *state_in); - -#endif /* BASE64_CDECODE_H */ - -/* - end library headers - */ - -#include "ua_base64.h" - -UA_Int32 UA_base64_getDecodedSize(UA_String *const base64EncodedData) { - //note that base64-encoded data length is always divisible by 4 - UA_Int32 temp = base64EncodedData->length * 3 / 4; - - //subtract padding - if(base64EncodedData->data[base64EncodedData->length-1] == '=') { - temp--; - if(base64EncodedData->data[base64EncodedData->length-2] == '=') - temp--; - } - - return temp; -} - -UA_Int32 UA_base64_decode(UA_String *const base64EncodedData, UA_Byte *target) { - if(target == UA_NULL) - return UA_ERROR; - base64_decodestate state; - base64_init_decodestate(&state); - base64_decode_block((char *)(base64EncodedData->data), base64EncodedData->length, (char *)target, &state); - return UA_NO_ERROR; -} - -/* - begin library code - */ - -/* - cdecoder.c - c source to a base64 decoding algorithm implementation - - This is part of the libb64 project, and has been placed in the public domain. - For details, see http://sourceforge.net/projects/libb64 - */ - -int base64_decode_value(char value_in) { - static const char decoding[] = - { 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -2, -1, -1, -1, 0, 1, 2, 3, - 4, 5, - 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, - 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 }; - static const char decoding_size = sizeof(decoding); - value_in -= 43; - if(value_in > decoding_size) return -1; - return decoding[(int)value_in]; -} - -void base64_init_decodestate(base64_decodestate *state_in) { - state_in->step = step_a; - state_in->plainchar = 0; -} - -int base64_decode_block(const char *code_in, const int length_in, char *plaintext_out, - base64_decodestate *state_in) { - const char *codechar = code_in; - char *plainchar = plaintext_out; - signed char fragment; - - *plainchar = state_in->plainchar; - - switch(state_in->step) { - while(1) { - case step_a: - do { - if(codechar == code_in+length_in) { - state_in->step = step_a; - state_in->plainchar = *plainchar; - return plainchar - plaintext_out; - } - fragment = (char)base64_decode_value(*codechar++); - } while(fragment < 0); - *plainchar = (fragment & 0x03f) << 2; - - case step_b: - do { - if(codechar == code_in+length_in) { - state_in->step = step_b; - state_in->plainchar = *plainchar; - return plainchar - plaintext_out; - } - fragment = (char)base64_decode_value(*codechar++); - } while(fragment < 0); - *plainchar++ |= (fragment & 0x030) >> 4; - *plainchar = (fragment & 0x00f) << 4; - - case step_c: - do { - if(codechar == code_in+length_in) { - state_in->step = step_c; - state_in->plainchar = *plainchar; - return plainchar - plaintext_out; - } - fragment = (char)base64_decode_value(*codechar++); - } while(fragment < 0); - *plainchar++ |= (fragment & 0x03c) >> 2; - *plainchar = (fragment & 0x003) << 6; - - case step_d: - do { - if(codechar == code_in+length_in) { - state_in->step = step_d; - state_in->plainchar = *plainchar; - return plainchar - plaintext_out; - } - fragment = (char)base64_decode_value(*codechar++); - } while(fragment < 0); - *plainchar++ |= (fragment & 0x03f); - } - } - /* control should not reach here */ - return plainchar - plaintext_out; -} - diff --git a/src/ongoing/ua_base64.h b/src/ongoing/ua_base64.h deleted file mode 100644 index 69b58138f9a..00000000000 --- a/src/ongoing/ua_base64.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * ua_base64.h - * - * Created on: Jun 10, 2014 - * Author: sten - */ - -#ifndef UA_BASE64_H_ -#define UA_BASE64_H_ - -#include "ua_types.h" -#include "ua_util.h" - -/** @brief calculates the exact size for the binary data that is encoded in base64 encoded string */ -UA_Int32 UA_base64_getDecodedSize(UA_String *const base64EncodedData); - -/** @brief decodes base64 encoded string into target, target should be at least of the size returned by UA_base64_getDecodedSizeUB */ -UA_Int32 UA_base64_decode(UA_String *const base64EncodedData, UA_Byte *target); - -#endif /* UA_BASE64_H_ */ diff --git a/src/ongoing/ua_namespace_xml.c b/src/ongoing/ua_namespace_xml.c deleted file mode 100644 index 26193ae305f..00000000000 --- a/src/ongoing/ua_namespace_xml.c +++ /dev/null @@ -1,85 +0,0 @@ -#include "ua_namespace_xml.h" -#include // open, O_RDONLY - -typedef UA_Int32 (*XML_Stack_Loader) (char* buf, int len); - -#define XML_BUFFER_LEN 1024 -UA_Int32 Namespace_loadXml(Namespace **ns,UA_UInt32 nsid,const char* rootName, XML_Stack_Loader getNextBufferFull) { - UA_Int32 retval = UA_SUCCESS; - char buf[XML_BUFFER_LEN]; - int len; /* len is the number of bytes in the current bufferful of data */ - - XML_Stack s; - XML_Stack_init(&s, 0, rootName); - - UA_NodeSet n; - UA_NodeSet_init(&n, 0); - *ns = n.ns; - - XML_Stack_addChildHandler(&s, "UANodeSet", strlen("UANodeSet"), (XML_decoder) UA_NodeSet_decodeXmlFromStack, UA_INVALIDTYPE, &n); - XML_Parser parser = XML_ParserCreate(UA_NULL); - XML_SetUserData(parser, &s); - XML_SetElementHandler(parser, XML_Stack_startElement, XML_Stack_endElement); - XML_SetCharacterDataHandler(parser, XML_Stack_handleText); - while ((len = getNextBufferFull(buf, XML_BUFFER_LEN)) > 0) { - if (XML_Parse(parser, buf, len, (len < XML_BUFFER_LEN)) == XML_STATUS_ERROR) { - retval = UA_ERR_INVALID_VALUE; - break; - } - } - XML_ParserFree(parser); - - DBG_VERBOSE(printf("Namespace_loadXml - aliases addr=%p, size=%d\n", (void*) &(n.aliases), n.aliases.size)); - DBG_VERBOSE(UA_NodeSetAliases_println("Namespace_loadXml - elements=", &n.aliases)); - - return retval; -} - -static int theFile = 0; -UA_Int32 readFromTheFile(char*buf,int len) { - return read(theFile,buf,len); -} - -/** @brief load a namespace from an XML-File - * - * @param[in/out] ns the address of the namespace ptr - * @param[in] namespaceIndex the numeric id of the namespace - * @param[in] rootName the name of the root element of the hierarchy (not used?) - * @param[in] fileName the name of an existing file, e.g. Opc.Ua.NodeSet2.xml - */ -UA_Int32 Namespace_loadFromFile(Namespace **ns,UA_UInt32 nsid,const char* rootName,const char* fileName) { - if (fileName == UA_NULL) - theFile = 0; // stdin - else if ((theFile = open(fileName, O_RDONLY)) == -1) - return UA_ERR_INVALID_VALUE; - - UA_Int32 retval = Namespace_loadXml(ns,nsid,rootName,readFromTheFile); - close(theFile); - return retval; -} - -static const char* theBuffer = UA_NULL; -static const char* theBufferEnd = UA_NULL; -UA_Int32 readFromTheBuffer(char*buf,int len) { - if (len == 0) return 0; - if (theBuffer + XML_BUFFER_LEN > theBufferEnd) - len = theBufferEnd - theBuffer + 1; - else - len = XML_BUFFER_LEN; - memcpy(buf,theBuffer,len); - theBuffer = theBuffer + len; - return len; -} - -/** @brief load a namespace from a string - * - * @param[in/out] ns the address of the namespace ptr - * @param[in] namespaceIndex the numeric id of the namespace - * @param[in] rootName the name of the root element of the hierarchy (not used?) - * @param[in] buffer the xml string - */ -UA_Int32 Namespace_loadFromString(Namespace **ns,UA_UInt32 nsid,const char* rootName,const char* buffer) { - theBuffer = buffer; - theBufferEnd = buffer + strlen(buffer) - 1; - return Namespace_loadXml(ns,nsid,rootName,readFromTheBuffer); -} diff --git a/src/ongoing/ua_namespace_xml.h b/src/ongoing/ua_namespace_xml.h deleted file mode 100644 index db2aafecc09..00000000000 --- a/src/ongoing/ua_namespace_xml.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef __UA_NAMESPACE_XML_H -#define __UA_NAMESPACE_XML_H - -#include "ua_xml.h" -#include "ua_types_generated.h" -#include "ua_namespace.h" - -void print_node(UA_Node const * node); -UA_Int32 UA_NodeSetAlias_init(UA_NodeSetAlias* p); -UA_Int32 UA_NodeSetAlias_new(UA_NodeSetAlias** p); -//UA_Int32 UA_NodeSetAlias_decodeXML(XML_Stack* s, XML_Attr* attr, UA_NodeSetAlias* dst, _Bool isStart); - -UA_Int32 UA_NodeSetAliases_init(UA_NodeSetAliases* p); -UA_Int32 UA_NodeSetAliases_new(UA_NodeSetAliases** p); -UA_Int32 UA_NodeSetAliases_println(cstring label, UA_NodeSetAliases *p); -//UA_Int32 UA_NodeSetAliases_decodeXML(XML_Stack* s, XML_Attr* attr, UA_NodeSetAliases* dst, _Bool isStart); - -typedef struct UA_NodeSet { - Namespace* ns; - UA_NodeSetAliases aliases; -} UA_NodeSet; - -/** @brief init typed array with size=-1 and an UA_INVALIDTYPE */ -UA_Int32 UA_NodeSet_init(UA_NodeSet* p, UA_UInt32 nsid); -UA_Int32 UA_NodeSet_new(UA_NodeSet** p, UA_UInt32 nsid); -UA_Int32 UA_NodeId_copycstring(cstring src, UA_NodeId* dst, UA_NodeSetAliases* aliases); -UA_Int32 UA_NodeSet_decodeXmlFromStack(XML_Stack* s, XML_Attr* attr, UA_NodeSet* dst, _Bool isStart); - -UA_Int32 UA_ExpandedNodeId_copycstring(cstring src, UA_ExpandedNodeId* dst, UA_NodeSetAliases* aliases); - -/** @brief load a namespace from an XML-File - * - * @param[in/out] ns the address of the namespace ptr - * @param[in] namespaceIndex the numeric id of the namespace - * @param[in] rootName the name of the root element of the hierarchy (not used?) - * @param[in] fileName the name of an existing file, e.g. Opc.Ua.NodeSet2.xml - */ -UA_Int32 Namespace_loadFromFile(Namespace **ns,UA_UInt32 namespaceIndex,const char* rootName,const char* fileName); -UA_Int32 Namespace_loadFromString(Namespace **ns,UA_UInt32 nsid,const char* rootName,const char* buffer); - -#endif /* __UA_NAMESPACE_XML_H */ diff --git a/src/ongoing/ua_services_monitoreditems.c b/src/ongoing/ua_services_monitoreditems.c deleted file mode 100644 index 0d18b30047d..00000000000 --- a/src/ongoing/ua_services_monitoreditems.c +++ /dev/null @@ -1,27 +0,0 @@ -#include "ua_services.h" -#include "ua_namespace_0.h" -#include "ua_statuscodes.h" - -void Service_CreateMonitoredItems(UA_Server *server, UA_Session *session, - const UA_CreateMonitoredItemsRequest *request, - UA_CreateMonitoredItemsResponse *response) { - if(request->itemsToCreateSize <= 0) - return; - - //mock up - response->resultsSize = request->itemsToCreateSize; - UA_Array_new((void**)&response->results, response->resultsSize, &UA_[UA_MONITOREDITEMCREATERESULT]); - for(int i = 0;request->itemsToCreateSize > 0 && i < request->itemsToCreateSize;i++) { - //FIXME: search the object in the namespace - if(request->itemsToCreate[i].itemToMonitor.nodeId.identifier.numeric == 2253) { // server - response->results[i].statusCode = UA_STATUSCODE_GOOD; - response->results[i].monitoredItemId = 1; - response->results[i].revisedSamplingInterval = 4294967295; - response->results[i].revisedQueueSize = 0; - continue; - } else { - // response->results[i]->statusCode = UA_STATUSCODE_BAD_NODEIDUNKNOWN; - response->results[i].statusCode = -1; - } - } -} diff --git a/src/ongoing/ua_services_subscription.c b/src/ongoing/ua_services_subscription.c deleted file mode 100644 index a113591e630..00000000000 --- a/src/ongoing/ua_services_subscription.c +++ /dev/null @@ -1,30 +0,0 @@ -#include "ua_services.h" -#include "ua_statuscodes.h" -#include "ua_util.h" - -UA_Int32 Service_CreateSubscription(UA_Server *server, UA_Session *session, - const UA_CreateSubscriptionRequest *request, - UA_CreateSubscriptionResponse *response) { - response->subscriptionId = 42; - response->revisedPublishingInterval = 100000; - response->revisedLifetimeCount = 120000; - response->revisedMaxKeepAliveCount = 50; - return UA_SUCCESS; -} - -UA_Int32 Service_Publish(UA_Server *server, UA_Session *session, const UA_PublishRequest *request, - UA_PublishResponse *response) { - response->subscriptionId = 42; - response->notificationMessage.sequenceNumber = 1; - response->notificationMessage.publishTime = UA_DateTime_now(); - return UA_SUCCESS; -} - -UA_Int32 Service_SetPublishingMode(UA_Server *server, UA_Session *session, - const UA_SetPublishingModeRequest *request, - UA_SetPublishingModeResponse *response) { - response->diagnosticInfos = UA_NULL; - response->results = UA_NULL; - response->resultsSize = 0; - return UA_SUCCESS; -} diff --git a/src/ongoing/ua_types_encoding_json.c b/src/ongoing/ua_types_encoding_json.c deleted file mode 100644 index 6c916989d14..00000000000 --- a/src/ongoing/ua_types_encoding_json.c +++ /dev/null @@ -1,4 +0,0 @@ -#include "ua_types_encoding_json.h" - -// TODO: Implement encoding of the builtin types (in ua_types.h). Then add JSON -// encoding to the structure generation in tools/generate_builtin.py diff --git a/src/ongoing/ua_types_encoding_json.h b/src/ongoing/ua_types_encoding_json.h deleted file mode 100644 index c71e06a0eea..00000000000 --- a/src/ongoing/ua_types_encoding_json.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef UA_TYPES_ENCODING_JSON_H_ -#define UA_TYPES_ENCODING_JSON_H_ - -#include "util/ua_util.h" -#include "ua_types.h" - -/** - * @ingroup encoding - * @defgroup encoding_json JSON Encoding - * - * @brief Encoding of UA datatypes in JSON. This extends the IEC 62541 standard - * and is only included in the "extended" profile. The extension is intended to - * be used with a webserver that transmits JSON over HTTP. - * - * @{ - */ - -#define UA_TYPE_CALCSIZEJSON_AS(TYPE, TYPE_AS) \ - UA_Int32 TYPE##_calcSizeJSON(TYPE const *p) { \ - return TYPE_AS##_calcSizeJSON((TYPE_AS *)p); \ - } - -#define UA_TYPE_ENCODEJSON_AS(TYPE, TYPE_AS) \ - UA_Int32 TYPE##_encodeJSON(TYPE const *src, UA_ByteString *dst, UA_UInt32 *offset) { \ - return TYPE_AS##_encodeJSON((TYPE_AS *)src, dst, offset); \ - } - -#define UA_TYPE_DECODEJSON_AS(TYPE, TYPE_AS) \ - UA_Int32 TYPE##_decodeJSON(UA_ByteString const *src, UA_UInt32 *offset, TYPE *dst) { \ - return TYPE_AS##_decodeJSON(src, offset, (TYPE_AS *)dst); \ - } -#define UA_TYPE_JSON_ENCODING_AS(TYPE, TYPE_AS) \ - UA_TYPE_CALCSIZEJSON_AS(TYPE, TYPE_AS) \ - UA_TYPE_ENCODEJSON_AS(TYPE, TYPE_AS) \ - UA_TYPE_DECODEJSON_AS(TYPE, TYPE_AS) - -#define UA_TYPE_JSON_ENCODING(TYPE) \ - UA_Int32 TYPE##_calcSizeJSON(TYPE const *p); \ - UA_Int32 TYPE##_encodeJSON(TYPE const *src, UA_ByteString *dst, UA_UInt32 *offset); \ - UA_Int32 TYPE##_decodeJSON(UA_ByteString const *src, UA_UInt32 *offset, TYPE *dst); - -UA_TYPE_JSON_ENCODING(UA_Boolean) -UA_TYPE_JSON_ENCODING(UA_SByte) -UA_TYPE_JSON_ENCODING(UA_Byte) -UA_TYPE_JSON_ENCODING(UA_Int16) -UA_TYPE_JSON_ENCODING(UA_UInt16) -UA_TYPE_JSON_ENCODING(UA_Int32) -UA_TYPE_JSON_ENCODING(UA_UInt32) -UA_TYPE_JSON_ENCODING(UA_Int64) -UA_TYPE_JSON_ENCODING(UA_UInt64) -UA_TYPE_JSON_ENCODING(UA_Float) -UA_TYPE_JSON_ENCODING(UA_Double) -UA_TYPE_JSON_ENCODING(UA_String) -UA_TYPE_JSON_ENCODING(UA_DateTime) -UA_TYPE_JSON_ENCODING(UA_Guid) -UA_TYPE_JSON_ENCODING(UA_ByteString) -UA_TYPE_JSON_ENCODING(UA_XmlElement) -UA_TYPE_JSON_ENCODING(UA_NodeId) -UA_TYPE_JSON_ENCODING(UA_ExpandedNodeId) -UA_TYPE_JSON_ENCODING(UA_StatusCode) -UA_TYPE_JSON_ENCODING(UA_QualifiedName) -UA_TYPE_JSON_ENCODING(UA_LocalizedText) -UA_TYPE_JSON_ENCODING(UA_ExtensionObject) -UA_TYPE_JSON_ENCODING(UA_DataValue) -UA_TYPE_JSON_ENCODING(UA_Variant) -UA_TYPE_JSON_ENCODING(UA_DiagnosticInfo) - -/* Not built-in types */ -UA_TYPE_JSON_ENCODING(UA_InvalidType) - -/// @} /* end of group */ - -#endif /* UA_TYPES_ENCODING_JSON_H_ */ diff --git a/src/ongoing/ua_types_encoding_xml.c b/src/ongoing/ua_types_encoding_xml.c deleted file mode 100644 index efaac904fd2..00000000000 --- a/src/ongoing/ua_types_encoding_xml.c +++ /dev/null @@ -1,447 +0,0 @@ -#include "ua_types_encoding_xml.h" -#include "ua_util.h" -#include "ua_namespace_0.h" -#include "ua_xml.h" - -/* Boolean */ - -UA_Int32 UA_Boolean_copycstring(cstring src, UA_Boolean *dst) { - *dst = UA_FALSE; - if(0 == strncmp(src, "true", 4) || 0 == strncmp(src, "TRUE", 4)) - *dst = UA_TRUE; - return UA_SUCCESS; -} - -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_Boolean) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_Boolean) -UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_Boolean) -/* UA_Int32 UA_Boolean_decodeXML(XML_Stack *s, XML_Attr *attr, UA_Boolean *dst, _Bool isStart) { */ -/* DBG_VERBOSE(printf("UA_Boolean entered with dst=%p,isStart=%d\n", (void * )dst, isStart)); */ -/* if(isStart) { */ -/* if(dst == UA_NULL) { */ -/* UA_Boolean_new(&dst); */ -/* s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void *)dst; */ -/* } */ -/* UA_Boolean_copycstring((cstring)attr[1], dst); */ -/* } */ -/* return UA_SUCCESS; */ -/* } */ - -/* SByte */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_SByte) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_SByte) -UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_SByte) - -/* Byte */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_Byte) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_Byte) -UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_Byte) - -/* Int16 */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_Int16) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_Int16) - -UA_Int32 UA_Int16_copycstring(cstring src, UA_Int16 *dst) { - *dst = atoi(src); - return UA_SUCCESS; -} - -UA_Int32 UA_UInt16_copycstring(cstring src, UA_UInt16 *dst) { - *dst = atoi(src); - return UA_SUCCESS; -} - -UA_Int32 UA_Int16_decodeXmlFromStack(XML_Stack *s, XML_Attr *attr, UA_Int16 *dst, _Bool isStart) { - DBG_VERBOSE(printf("UA_Int32 entered with dst=%p,isStart=%d\n", (void * )dst, isStart)); - if(isStart) { - if(dst == UA_NULL) { - UA_Int16_new(&dst); - s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void *)dst; - } - UA_Int16_copycstring((cstring)attr[1], dst); - } - return UA_SUCCESS; -} - -UA_TYPE_DECODEXML_FROM_BYTESTRING(UA_Int16) - -/* UInt16 */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_UInt16) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_UInt16) -UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_UInt16) - -/* Int32 */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_Int32) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_Int32) - -UA_Int32 UA_Int32_decodeXmlFromStack(XML_Stack *s, XML_Attr *attr, UA_Int32 *dst, _Bool isStart) { - DBG_VERBOSE(printf("UA_Int32 entered with dst=%p,isStart=%d\n", (void * )dst, isStart)); - if(isStart) { - if(dst == UA_NULL) { - UA_Int32_new(&dst); - s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void *)dst; - } - *dst = atoi(attr[1]); - } - return UA_SUCCESS; -} -UA_TYPE_DECODEXML_FROM_BYTESTRING(UA_Int32) - -/* UInt32 */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_UInt32) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_UInt32) -UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_UInt32) - -/* Int64 */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_Int64) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_Int64) -UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_Int64) - -/* UInt64 */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_UInt64) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_UInt64) -UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_UInt64) - -/* Float */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_Float) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_Float) -UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_Float) - -/* Double */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_Double) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_Double) -UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_Double) - -/* String */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_String) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_String) - -UA_Int32 UA_String_decodeXmlFromStack(XML_Stack *s, XML_Attr *attr, UA_String *dst, _Bool isStart) { - DBG_VERBOSE(printf("UA_String entered with dst=%p,isStart=%d\n", (void * )dst, isStart)); - UA_UInt32 i; - if(isStart) { - if(dst == UA_NULL) { - UA_String_new(&dst); - s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void *)dst; - } - s->parent[s->depth].len = 0; - XML_Stack_addChildHandler(s, "Data", strlen("Data"), (XML_decoder)UA_Text_decodeXmlFromStack, UA_BYTE, - &(dst->data)); - XML_Stack_addChildHandler(s, "Length", strlen("Length"), (XML_decoder)UA_Int32_decodeXmlFromStack, UA_INT32, - &(dst->length)); - XML_Stack_handleTextAsElementOf(s, "Data", 0); - - // set attributes - for(i = 0;attr[i];i += 2) { - if(0 == strncmp("Data", attr[i], strlen("Data"))) - UA_String_copycstring(attr[i + 1], dst); - else - printf("UA_String_decodeXml - Unknown attribute - name=%s, value=%s\n", attr[i], attr[i+1]); - } - } else { - switch(s->parent[s->depth - 1].activeChild) { - case 0: - if(dst != UA_NULL && dst->data != UA_NULL && dst->length == -1) - dst->length = strlen((char const *)dst->data); - break; - } - } - return UA_SUCCESS; -} - -UA_TYPE_DECODEXML_FROM_BYTESTRING(UA_String) - -/* DateTime */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_DateTime) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_DateTime) -UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_DateTime) - -/* Guid */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_Guid) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_Guid) -UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_Guid) - -/* ByteString */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_ByteString) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_ByteString) -UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_ByteString) - -/* XmlElement */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_XmlElement) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_XmlElement) -UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_XmlElement) - -/* NodeId */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_NodeId) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_NodeId) - -UA_Int32 UA_NodeId_decodeXmlFromStack(XML_Stack *s, XML_Attr *attr, UA_NodeId *dst, _Bool isStart) { - DBG_VERBOSE(printf("UA_NodeId entered with dst=%p,isStart=%d\n", (void * )dst, isStart)); - UA_UInt32 i; - if(isStart) { - if(dst == UA_NULL) { - UA_NodeId_new(&dst); - s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void *)dst; - } - s->parent[s->depth].len = 0; - XML_Stack_addChildHandler(s, "Namespace", strlen( - "Namespace"), (XML_decoder)UA_Int16_decodeXmlFromStack, UA_INT16, - &(dst->namespaceIndex)); - XML_Stack_addChildHandler(s, "Numeric", strlen( - "Numeric"), (XML_decoder)UA_Int32_decodeXmlFromStack, UA_INT32, - &(dst->identifier.numeric)); - XML_Stack_addChildHandler(s, "Identifier", strlen( - "Identifier"), (XML_decoder)UA_String_decodeXmlFromStack, UA_STRING, UA_NULL); - XML_Stack_handleTextAsElementOf(s, "Data", 2); - - // set attributes - for(i = 0; attr[i]; i += 2) { - if(0 == strncmp("Namespace", attr[i], strlen("Namespace"))) - dst->namespaceIndex = atoi(attr[i + 1]); - else if(0 == strncmp("Numeric", attr[i], strlen("Numeric"))) { - dst->identifierType = UA_NODEIDTYPE_NUMERIC; - dst->identifier.numeric = atoi(attr[i + 1]); - } else - printf("UA_NodeId_decodeXml - Unknown attribute name=%s, value=%s\n", attr[i], attr[i+1]); - } - } else { - if(s->parent[s->depth - 1].activeChild == 2) - UA_NodeId_copycstring((cstring)((UA_String *)attr)->data, dst, s->aliases); - } - return UA_SUCCESS; -} - -UA_TYPE_DECODEXML_FROM_BYTESTRING(UA_NodeId) - -/* ExpandedNodeId */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_ExpandedNodeId) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_ExpandedNodeId) - -UA_Int32 UA_ExpandedNodeId_decodeXmlFromStack(XML_Stack *s, XML_Attr *attr, UA_ExpandedNodeId *dst, _Bool isStart) { - DBG_VERBOSE(printf("UA_ExpandedNodeId entered with dst=%p,isStart=%d\n", (void * )dst, isStart)); - UA_UInt32 i; - if(isStart) { - if(dst == UA_NULL) { - UA_ExpandedNodeId_new(&dst); - s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void *)dst; - } - s->parent[s->depth].len = 0; - XML_Stack_addChildHandler(s, "NodeId", strlen( - "NodeId"), (XML_decoder)UA_NodeId_decodeXmlFromStack, UA_NODEID, &(dst->nodeId)); - XML_Stack_addChildHandler(s, "Namespace", strlen("Namespace"), - (XML_decoder)UA_Int16_decodeXmlFromStack, UA_INT16, - &(dst->nodeId.namespaceIndex)); - XML_Stack_addChildHandler(s, "Numeric", strlen("Numeric"), (XML_decoder)UA_Int32_decodeXmlFromStack, UA_INT32, - &(dst->nodeId.identifier.numeric)); - XML_Stack_addChildHandler(s, "Id", strlen("Id"), (XML_decoder)UA_String_decodeXmlFromStack, UA_STRING, UA_NULL); - XML_Stack_handleTextAsElementOf(s, "Data", 3); - - // set attributes - for(i = 0; attr[i]; i += 2) { - if(0 == strncmp("Namespace", attr[i], strlen("Namespace"))) - UA_UInt16_copycstring((cstring)attr[i + 1], &(dst->nodeId.namespaceIndex)); - else if(0 == strncmp("Numeric", attr[i], strlen("Numeric"))) { - UA_NodeId_copycstring((cstring)attr[i + 1], &(dst->nodeId), s->aliases); - } else if(0 == strncmp("NodeId", attr[i], strlen("NodeId"))) - UA_NodeId_copycstring((cstring)attr[i + 1], &(dst->nodeId), s->aliases); - else - printf("UA_ExpandedNodeId_decodeXml - unknown attribute name=%s, value=%s\n", attr[i], attr[i+1]); - } - } - return UA_SUCCESS; -} - -UA_TYPE_DECODEXML_FROM_BYTESTRING(UA_ExpandedNodeId) - -/* StatusCode */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_StatusCode) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_StatusCode) -UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_StatusCode) -/* UA_Int32 UA_StatusCode_decodeXML(XML_Stack *s, XML_Attr *attr, UA_StatusCode *dst, _Bool isStart) { */ -/* DBG_VERBOSE(printf("UA_StatusCode_decodeXML entered with dst=%p,isStart=%d\n", (void * )dst, isStart)); */ -/* return UA_ERR_NOT_IMPLEMENTED; */ -/* } */ - -/* QualifiedName */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_QualifiedName) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_QualifiedName) - -UA_Int32 UA_QualifiedName_decodeXmlFromStack(XML_Stack *s, XML_Attr *attr, UA_QualifiedName *dst, _Bool isStart) { - DBG_VERBOSE(printf("UA_QualifiedName entered with dst=%p,isStart=%d\n", (void * )dst, isStart)); - UA_UInt32 i; - if(isStart) { - if(dst == UA_NULL) { - UA_QualifiedName_new(&dst); - s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void *)dst; - } - s->parent[s->depth].len = 0; - XML_Stack_addChildHandler(s, "Name", strlen("Name"), (XML_decoder)UA_String_decodeXmlFromStack, UA_STRING, - &(dst->name)); - XML_Stack_addChildHandler(s, "NamespaceIndex", strlen( - "NamespaceIndex"), (XML_decoder)UA_Int16_decodeXmlFromStack, UA_STRING, - &(dst->namespaceIndex)); - XML_Stack_handleTextAsElementOf(s, "Data", 0); - - // set attributes - for(i = 0;attr[i];i += 2) { - if(0 == strncmp("NamespaceIndex", attr[i], strlen("NamespaceIndex"))) - dst->namespaceIndex = atoi(attr[i + 1]); - else if(0 == strncmp("Name", attr[i], strlen("Name"))) - UA_String_copycstring(attr[i + 1], &(dst->name)); - else - perror("Unknown attribute"); - } - } - return UA_SUCCESS; -} - -UA_TYPE_DECODEXML_FROM_BYTESTRING(UA_QualifiedName) - -/* LocalizedText */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_LocalizedText) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_LocalizedText) - -UA_Int32 UA_LocalizedText_decodeXmlFromStack(XML_Stack *s, XML_Attr *attr, UA_LocalizedText *dst, _Bool isStart) { - DBG_VERBOSE(printf("UA_LocalizedText entered with dst=%p,isStart=%d\n", (void * )dst, isStart)); - UA_UInt32 i; - if(isStart) { - if(dst == UA_NULL) { - UA_LocalizedText_new(&dst); - s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void *)dst; - } - // s->parent[s->depth].len = 0; - XML_Stack_addChildHandler(s, "Text", strlen("Text"), (XML_decoder)UA_String_decodeXmlFromStack, UA_STRING, - &(dst->text)); - XML_Stack_addChildHandler(s, "Locale", strlen( - "Locale"), (XML_decoder)UA_String_decodeXmlFromStack, UA_STRING, &(dst->locale)); - XML_Stack_handleTextAsElementOf(s, "Data", 0); - - // set attributes - for(i = 0;attr[i];i += 2) { - if(0 == strncmp("Text", attr[i], strlen("Text"))) { - UA_String_copycstring(attr[i + 1], &dst->text); - } else if(0 == strncmp("Locale", attr[i], strlen("Locale"))) { - UA_String_copycstring(attr[i + 1], &dst->locale); - } else - perror("Unknown attribute"); - } - } else { - switch(s->parent[s->depth - 1].activeChild) { - case 0: - //dst->encodingMask |= UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT; - break; - - case 1: - //dst->encodingMask |= UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_LOCALE; - break; - - default: - break; - } - } - return UA_SUCCESS; -} - -UA_TYPE_DECODEXML_FROM_BYTESTRING(UA_LocalizedText) - -/* ExtensionObject */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_ExtensionObject) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_ExtensionObject) - -UA_Int32 UA_ExtensionObject_decodeXmlFromStack(XML_Stack *s, XML_Attr *attr, UA_ExtensionObject *dst, _Bool isStart) { - DBG_VERBOSE(printf("UA_ExtensionObject entered with dst=%p,isStart=%d\n", (void * )dst, isStart)); - UA_UInt32 i; - - if(isStart) { - // create a new object if called with UA_NULL - if(dst == UA_NULL) { - UA_ExtensionObject_new(&dst); - s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void *)dst; - } - - s->parent[s->depth].len = 0; - XML_Stack_addChildHandler(s, "TypeId", strlen( - "TypeId"), (XML_decoder)UA_NodeId_decodeXmlFromStack, UA_NODEID, &(dst->typeId)); - // XML_Stack_addChildHandler(s, "Body", strlen("Body"), (XML_decoder) UA_Body_decodeXml, UA_LOCALIZEDTEXT, UA_NULL); - - // set attributes - for(i = 0;attr[i];i += 2) { - { - DBG_ERR(XML_Stack_print(s)); - DBG_ERR(printf("%s - unknown attribute\n", attr[i])); - } - } - } - return UA_SUCCESS; -} - -UA_TYPE_DECODEXML_FROM_BYTESTRING(UA_ExtensionObject) - -/* DataValue */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_DataValue) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_DataValue) -UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_DataValue) - -/* Variant */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_Variant) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_Variant) - -UA_Int32 UA_Variant_decodeXmlFromStack(XML_Stack *s, XML_Attr *attr, UA_Variant *dst, _Bool isStart) { - DBG_VERBOSE(printf("UA_Variant entered with dst=%p,isStart=%d\n", (void * )dst, isStart)); - UA_UInt32 i; - - if(isStart) { - // create a new object if called with UA_NULL - if(dst == UA_NULL) { - UA_Variant_new(&dst); - s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void *)dst; - } - - s->parent[s->depth].len = 0; - XML_Stack_addChildHandler(s, "ListOfExtensionObject", strlen( - "ListOfExtensionObject"), (XML_decoder)UA_TypedArray_decodeXmlFromStack, - UA_EXTENSIONOBJECT, UA_NULL); - XML_Stack_addChildHandler(s, "ListOfLocalizedText", strlen( - "ListOfLocalizedText"), (XML_decoder)UA_TypedArray_decodeXmlFromStack, - UA_LOCALIZEDTEXT, UA_NULL); - - // set attributes - for(i = 0;attr[i];i += 2) { - { - DBG_ERR(XML_Stack_print(s)); - DBG_ERR(printf("%s - unknown attribute\n", attr[i])); - } - } - } else { - if(s->parent[s->depth - 1].activeChild == 0 && attr != UA_NULL ) { // ExtensionObject - UA_TypedArray *array = (UA_TypedArray *)attr; - DBG_VERBOSE(printf("UA_Variant_decodeXml - finished array: references=%p, size=%d\n", (void *)array, - (array == UA_NULL) ? -1 : array->size)); - dst->arrayLength = array->size; - dst->data = array->elements; - dst->vt = &UA_.types[UA_EXTENSIONOBJECT]; - s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = UA_NULL; - } else if(s->parent[s->depth - 1].activeChild == 1 && attr != UA_NULL ) { // LocalizedText - UA_TypedArray *array = (UA_TypedArray *)attr; - DBG_VERBOSE(printf("UA_Variant_decodeXml - finished array: references=%p, size=%d\n", (void *)array, - (array == UA_NULL) ? -1 : array->size)); - dst->arrayLength = array->size; - dst->data = array->elements; - dst->vt = &UA_.types[UA_LOCALIZEDTEXT]; - s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = UA_NULL; - } - } - return UA_SUCCESS; -} - -UA_TYPE_DECODEXML_FROM_BYTESTRING(UA_Variant) - -/* DiagnosticInfo */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_DiagnosticInfo) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_DiagnosticInfo) -UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_DiagnosticInfo) - -/* InvalidType */ -UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(UA_InvalidType) -UA_TYPE_METHOD_ENCODEXML_NOTIMPL(UA_InvalidType) -UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_InvalidType) diff --git a/src/ongoing/ua_types_encoding_xml.h b/src/ongoing/ua_types_encoding_xml.h deleted file mode 100644 index f678f8c8981..00000000000 --- a/src/ongoing/ua_types_encoding_xml.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef UA_TYPES_ENCODING_XML_H_ -#define UA_TYPES_ENCODING_XML_H_ - -#include "ua_xml.h" -#include "ua_types.h" - -#define UA_TYPE_XML_ENCODING(TYPE) \ - UA_Int32 TYPE##_calcSizeXml(const void * p); \ - UA_Int32 TYPE##_encodeXml(const TYPE *src, UA_ByteString *dst, UA_UInt32 *offset); \ - UA_Int32 TYPE##_decodeXml(UA_ByteString *src, UA_UInt32 *offset, TYPE *dst); \ - UA_Int32 TYPE##_encodeXmlToStack(const TYPE *src, XML_Stack *s, XML_Attr *attr); \ - UA_Int32 TYPE##_decodeXmlFromStack(XML_Stack* s, XML_Attr* attr, TYPE* dst, UA_Boolean isStart); - -#define UA_TYPE_METHOD_CALCSIZEXML_NOTIMPL(TYPE) \ - UA_Int32 TYPE##_calcSizeXml(const void * p) { \ - return -1; \ - } - -#define UA_TYPE_METHOD_ENCODEXML_NOTIMPL(TYPE) \ - UA_Int32 TYPE##_encodeXml(const TYPE *src, UA_ByteString *dst, UA_UInt32 *offset) { \ - return UA_ERR_NOT_IMPLEMENTED; \ - } \ - UA_Int32 TYPE##_encodeXmlToStack(const TYPE *src, XML_Stack *s, XML_Attr *attr) { \ - DBG_VERBOSE(printf(#TYPE "_encodeXML entered with src=%p\n", (void* ) src)); \ - return UA_ERR_NOT_IMPLEMENTED;\ - } - -#define UA_TYPE_METHOD_DECODEXML_NOTIMPL(TYPE) \ - UA_Int32 TYPE##_decodeXml(UA_ByteString *src, UA_UInt32 *offset, TYPE *dst) { \ - return UA_ERR_NOT_IMPLEMENTED; \ - } \ - \ - UA_Int32 TYPE##_decodeXmlFromStack(XML_Stack* s, XML_Attr* attr, TYPE* dst, UA_Boolean isStart) { \ - DBG_VERBOSE(printf(#TYPE "_decodeXML entered with dst=%p,isStart=%d\n", (void* ) dst, (_Bool) isStart)); \ - return UA_ERR_NOT_IMPLEMENTED; \ - } - -#define UA_TYPE_DECODEXML_FROM_BYTESTRING(TYPE) \ - UA_Int32 TYPE##_decodeXml(UA_ByteString *src, UA_UInt32 *offset, TYPE *dst) { \ - /* // Init Stack here \ - UA_Stack *stack; \ - UA_Attr *attr; \ - TYPE##decodeXmlFromStack(stack, attr, dst, UA_TRUE); \ - */ \ - return UA_ERR_NOT_IMPLEMENTED; \ -} - -UA_TYPE_XML_ENCODING(UA_Boolean) -UA_TYPE_XML_ENCODING(UA_SByte) -UA_TYPE_XML_ENCODING(UA_Byte) -UA_TYPE_XML_ENCODING(UA_Int16) -UA_TYPE_XML_ENCODING(UA_UInt16) -UA_TYPE_XML_ENCODING(UA_Int32) -UA_TYPE_XML_ENCODING(UA_UInt32) -UA_TYPE_XML_ENCODING(UA_Int64) -UA_TYPE_XML_ENCODING(UA_UInt64) -UA_TYPE_XML_ENCODING(UA_Float) -UA_TYPE_XML_ENCODING(UA_Double) -UA_TYPE_XML_ENCODING(UA_String) -UA_TYPE_XML_ENCODING(UA_DateTime) -UA_TYPE_XML_ENCODING(UA_Guid) -UA_TYPE_XML_ENCODING(UA_ByteString) -UA_TYPE_XML_ENCODING(UA_XmlElement) -UA_TYPE_XML_ENCODING(UA_NodeId) -UA_TYPE_XML_ENCODING(UA_ExpandedNodeId) -UA_TYPE_XML_ENCODING(UA_StatusCode) -UA_TYPE_XML_ENCODING(UA_QualifiedName) -UA_TYPE_XML_ENCODING(UA_LocalizedText) -UA_TYPE_XML_ENCODING(UA_ExtensionObject) -UA_TYPE_XML_ENCODING(UA_DataValue) -UA_TYPE_XML_ENCODING(UA_Variant) -UA_TYPE_XML_ENCODING(UA_DiagnosticInfo) - -/* Not built-in types */ -UA_TYPE_XML_ENCODING(UA_InvalidType) - -#endif /* UA_TYPES_ENCODING_XML_H_ */ diff --git a/src/ongoing/ua_xml.c b/src/ongoing/ua_xml.c deleted file mode 100644 index b8b3d09dc0f..00000000000 --- a/src/ongoing/ua_xml.c +++ /dev/null @@ -1,980 +0,0 @@ -#include "ua_types_generated.h" -#include "ua_types_encoding_xml.h" -#include "ua_xml.h" -#include "ua_namespace_xml.h" -#include // open, O_RDONLY - -UA_Int32 UA_TypedArray_init(UA_TypedArray *p) { - p->size = -1; - p->vt = &UA_.types[UA_INVALIDTYPE]; - p->elements = UA_NULL; - return UA_SUCCESS; -} - -UA_Int32 UA_TypedArray_new(UA_TypedArray **p) { - UA_alloc((void ** )p, sizeof(UA_TypedArray)); - UA_TypedArray_init(*p); - return UA_SUCCESS; -} - -UA_Int32 UA_TypedArray_setType(UA_TypedArray *p, UA_Int32 type) { - UA_Int32 retval = UA_ERR_INVALID_VALUE; - if(type >= UA_BOOLEAN && type <= UA_INVALIDTYPE) { - p->vt = &UA_.types[type]; - retval = UA_SUCCESS; - } - return retval; -} - -// FIXME: We might want to have these classes and their methods -// defined in opcua.h via generate_builtin and the plugin-concept -// or in ua_basictypes.c - -UA_Int32 UA_NodeSetAlias_init(UA_NodeSetAlias *p) { - UA_String_init(&(p->alias)); - UA_String_init(&(p->value)); - return UA_SUCCESS; -} - -UA_Int32 UA_NodeSetAlias_new(UA_NodeSetAlias **p) { - UA_alloc((void ** )p, sizeof(UA_NodeSetAlias)); - UA_NodeSetAlias_init(*p); - return UA_SUCCESS; -} - -UA_Int32 UA_NodeSetAliases_init(UA_NodeSetAliases *p) { - p->size = -1; - p->aliases = UA_NULL; - return UA_SUCCESS; -} - -UA_Int32 UA_NodeSetAliases_new(UA_NodeSetAliases **p) { - UA_alloc((void ** )p, sizeof(UA_NodeSetAliases)); - UA_NodeSetAliases_init(*p); - return UA_SUCCESS; -} - -UA_Int32 UA_NodeSetAliases_println(cstring label, UA_NodeSetAliases *p) { - UA_Int32 i; - for(i = 0;i < p->size;i++) { - UA_NodeSetAlias *a = p->aliases[i]; - printf("%s{addr=%p", label, (void *)a); - if(a) - printf(",alias='%.*s', value='%.*s'", a->alias.length, a->alias.data, a->value.length, a->value.data); - printf("}\n"); - } - return UA_SUCCESS; -} - -UA_Int32 UA_NodeSet_init(UA_NodeSet *p, UA_UInt32 nsid) { - Namespace_new(&p->ns, nsid); - p->aliases.size = -1; - p->aliases.aliases = UA_NULL; - return UA_SUCCESS; -} - -UA_Int32 UA_NodeSet_new(UA_NodeSet **p, UA_UInt32 nsid) { - UA_alloc((void ** )p, sizeof(UA_NodeSet)); - UA_NodeSet_init(*p, nsid); - return UA_SUCCESS; -} - -UA_Int32 _UA_NodeId_copycstring(cstring src, UA_NodeId* dst, UA_NodeSetAliases* aliases) { - UA_Int32 retval = UA_SUCCESS; - if (src != UA_NULL && dst != UA_NULL ) { - if (src[0] == 'i' && src[1] == '=') { // namespace zero numeric identifier - dst->identifier.numeric = atoi(&src[2]); - } else if (src[0] == 'n' && src[1] == 's' && src[2] == '=') { // namespace - dst->namespaceIndex = atoi(&src[3]); - src = strchr(&src[3],';'); - if (src != UA_NULL) - retval = _UA_NodeId_copycstring(src+1,dst,aliases); // +1 to start beyond ; - else - retval = UA_ERR_INVALID_VALUE; - } else if (aliases != UA_NULL ) { // try for aliases - UA_Int32 i; - for (i = 0; i < aliases->size && dst->identifier.numeric == 0; ++i) { - if (0 == strncmp((char const*) src, (char const*) aliases->aliases[i]->alias.data, - aliases->aliases[i]->alias.length)) { - _UA_NodeId_copycstring((cstring)aliases->aliases[i]->alias.data,dst,UA_NULL); // substitute text of alias - } - } - } else { - retval = UA_ERR_NOT_IMPLEMENTED; - } - } else { - retval = UA_ERR_INVALID_VALUE; - } - DBG_VERBOSE(printf("UA_NodeId_copycstring src=%s,id=%d\n", src, dst->identifier.numeric)); - return retval; -} - -UA_Int32 UA_NodeId_copycstring(cstring src, UA_NodeId* dst, UA_NodeSetAliases* aliases) { - dst->identifierType = UA_NODEIDTYPE_NUMERIC; - dst->namespaceIndex = 0; - dst->identifier.numeric = 0; - return _UA_NodeId_copycstring(src,dst,aliases); -} - -UA_Int32 UA_ReferenceNode_println(cstring label, UA_ReferenceNode *a) { - printf("%s{referenceType=%d, target=%d, isInverse=%d}\n", - label, - a->referenceTypeId.identifier.numeric, - a->targetId.nodeId.identifier.numeric, - a->isInverse); - return UA_SUCCESS; -} - -UA_Int32 UA_ExpandedNodeId_copycstring(cstring src, UA_ExpandedNodeId *dst, UA_NodeSetAliases *aliases) { - dst->nodeId.namespaceIndex = 0; - dst->nodeId.identifierType = UA_NODEIDTYPE_NUMERIC; - dst->nodeId.identifier.numeric = 0; - UA_NodeId_copycstring(src, &(dst->nodeId), aliases); - DBG_VERBOSE(printf("UA_ExpandedNodeId_copycstring src=%s,id=%d\n", src, dst->nodeId.identifier.numeric)); - return UA_SUCCESS; -} - -void XML_Stack_init(XML_Stack* p, UA_UInt32 nsid, cstring name) { - unsigned int i, j; - p->depth = 0; - for(i = 0;i < XML_STACK_MAX_DEPTH;i++) { - p->parent[i].name = UA_NULL; - p->parent[i].len = 0; - p->parent[i].activeChild = -1; - p->parent[i].textAttrib = UA_NULL; - p->parent[i].textAttribIdx = -1; - /* p->parent[i].totalGatherLength = -1; */ - /* UA_list_init(&(p->parent[i].textGatherList)); */ - for (j = 0; j < XML_STACK_MAX_CHILDREN; j++) { - p->parent[i].children[j].name = UA_NULL; - p->parent[i].children[j].length = -1; - p->parent[i].children[j].elementHandler = UA_NULL; - p->parent[i].children[j].type = UA_INVALIDTYPE; - p->parent[i].children[j].obj = UA_NULL; - } - } - /* p->nsid = nsid; */ - p->parent[0].name = name; -} - -char path_buffer[1024]; -char *XML_Stack_path(XML_Stack *s) { - UA_Int32 i; - char *p = &path_buffer[0]; - for(i = 0;i <= s->depth;i++) { - strcpy(p, s->parent[i].name); - p += strlen(s->parent[i].name); - *p = '/'; - p++; - } - *p = 0; - return &path_buffer[0]; -} - -void XML_Stack_print(XML_Stack *s) { - printf("%s", XML_Stack_path(s)); -} - -// FIXME: we might want to calculate textAttribIdx from a string and the information given on the stack -void XML_Stack_handleTextAsElementOf(XML_Stack *p, cstring textAttrib, unsigned int textAttribIdx) { - p->parent[p->depth].textAttrib = textAttrib; - p->parent[p->depth].textAttribIdx = textAttribIdx; -} - -void XML_Stack_addChildHandler(XML_Stack *p, cstring name, UA_Int32 length, XML_decoder handler, UA_Int32 type, - void *dst) { - unsigned int len = p->parent[p->depth].len; - p->parent[p->depth].children[len].name = name; - p->parent[p->depth].children[len].length = length; - p->parent[p->depth].children[len].elementHandler = handler; - p->parent[p->depth].children[len].type = type; - p->parent[p->depth].children[len].obj = dst; - p->parent[p->depth].len++; -} - -UA_Int32 UA_Text_decodeXmlFromStack(XML_Stack *s, XML_Attr *attr, UA_Byte **dst, _Bool isStart) { - DBG_VERBOSE(printf("UA_String entered with dst=%p,isStart=%d\n", (void * )dst, isStart)); - UA_UInt32 i; - if(isStart) { - if(dst == UA_NULL) { - UA_alloc((void **)&dst, sizeof(void *)); - s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void *)dst; - } - // set attributes - for(i = 0;attr[i];i += 2) { - if(0 == strncmp("Data", attr[i], strlen("Data"))) { - char *tmp; - UA_alloc((void **)&tmp, strlen(attr[i+1])+1); - strncpy(tmp, attr[i+1], strlen(attr[i+1])); - tmp[strlen(attr[i+1])] = 0; - *dst = (UA_Byte *)tmp; - } else - printf("UA_Text_decodeXml - Unknown attribute - name=%s, value=%s\n", attr[i], attr[i+1]); - } - } - return UA_SUCCESS; -} - -// Gets generated in ua_types_generated.h and .c. But currently only as stubs -/* UA_Int32 UA_ReferenceNode_decodeXmlFromStack(XML_Stack* s, XML_Attr* attr, UA_ReferenceNode* dst, _Bool isStart) { */ -/* DBG_VERBOSE(printf("UA_ReferenceNode_decodeXML entered with dst=%p,isStart=%d\n", (void* ) dst, isStart)); */ -/* if (isStart) { */ -/* // create if necessary */ -/* if (dst == UA_NULL) { */ -/* UA_ReferenceNode_new(&dst); */ -/* s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void*) dst; */ -/* } */ -/* // set handlers */ -/* s->parent[s->depth].len = 0; */ -/* XML_Stack_addChildHandler(s, "ReferenceType", strlen("ReferenceType"),(XML_decoder) UA_NodeId_decodeXmlFromStack, UA_NODEID, &(dst->referenceTypeId)); */ -/* XML_Stack_addChildHandler(s, "IsForward", strlen("IsForward"), (XML_decoder) UA_Boolean_decodeXmlFromStack, UA_BOOLEAN, &(dst->isInverse)); */ -/* XML_Stack_addChildHandler(s, "Target", strlen("Target"), (XML_decoder) UA_ExpandedNodeId_decodeXmlFromStack, UA_EXPANDEDNODEID, &(dst->targetId)); */ -/* XML_Stack_handleTextAsElementOf(s, "NodeId", 2); */ - -/* // set attributes */ -/* UA_Int32 i; */ -/* for (i = 0; attr[i]; i += 2) { */ -/* if (0 == strncmp("ReferenceType", attr[i], strlen("ReferenceType"))) { */ -/* UA_NodeId_copycstring(attr[i + 1], &(dst->referenceTypeId), s->aliases); */ -/* } else if (0 == strncmp("IsForward", attr[i], strlen("IsForward"))) { */ -/* UA_Boolean_copycstring(attr[i + 1], &(dst->isInverse)); */ -/* dst->isInverse = !dst->isInverse; */ -/* } else if (0 == strncmp("Target", attr[i], strlen("Target"))) { */ -/* UA_ExpandedNodeId_copycstring(attr[i + 1], &(dst->targetId), s->aliases); */ -/* } else { */ -/* DBG_ERR(XML_Stack_print(s));DBG_ERR(printf("%s - unknown attribute\n", attr[i])); */ -/* } */ -/* } */ -/* } */ -/* return UA_SUCCESS; */ -/* } */ - -UA_Int32 UA_TypedArray_decodeXmlFromStack(XML_Stack* s, XML_Attr* attr, UA_TypedArray* dst, _Bool isStart) { - UA_Int32 type = s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].type; - /* DBG_VERBOSE(printf("UA_TypedArray_decodeXML - entered with dst=%p,isStart=%d,type={%d,%s},name=%s\n", (void* ) dst, isStart,type,UA_[type].name, names)); */ - if (isStart) { - if (dst == UA_NULL) { - UA_TypedArray_new(&dst); - UA_TypedArray_setType(dst, type); - s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = dst; - } - // need to map from ArrayName to member name - // References - Reference - // Aliases - Alias - // ListOfXX - XX - DBG(UA_Int32 length = 0; - cstring names = s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].name; - if (0 == strncmp("ListOf",names,strlen("ListOf"))) { - names = &names[strlen("ListOf")]; - length = strlen(names); - } else if ( 0 == strncmp("References",names,strlen("References"))){ - length = strlen(names) - 1; - } else if ( 0 == strncmp("Aliases",names,strlen("Aliases"))){ - length = strlen(names) - 2; - } - printf("UA_TypedArray_decodeXML - add handler for {%.*s}\n", length, names)); - // this is problematic as the standard encoding functions in the vtable take a bytestring as the input - /* XML_Stack_addChildHandler(s, names, length, (XML_decoder) UA_.types[type].encodings[1].decode, type, UA_NULL); */ - } else { - // sub element is ready, add to array - if (dst->size < 0 || dst->size == 0) { - dst->size = 1; - UA_alloc((void** )&(dst->elements), dst->size * sizeof(void*)); - DBG(printf("UA_TypedArray_decodeXML - allocate elements:dst=%p, aliases=%p, size=%d\n", (void* )dst, (void* )(dst->elements),dst->size)); - } else { - dst->size++; - dst->elements = realloc(dst->elements, dst->size * sizeof(void*)); - DBG(printf("UA_TypedArray_decodeXML - reallocate elements:dst=%p, aliases=%p, size=%d\n", (void* )dst,(void* )(dst->elements), dst->size)); - } - // index starts with 0, therefore size-1 - DBG_VERBOSE(printf("UA_TypedArray_decodeXML - assign element[%d], src=%p\n", dst->size - 1, (void* )attr)); - /* dst->elements[dst->size - 1] = (void*) attr; */ - DBG_VERBOSE(printf("UA_TypedArray_decodeXML - clear %p\n",(void* ) (s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj))); - s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = UA_NULL; - } - return UA_SUCCESS; -} - -// Gets generated in ua_types_generated.h and .c. But currently only as stubs -/* UA_Int32 UA_DataTypeNode_decodeXmlFromStack(XML_Stack* s, XML_Attr* attr, UA_DataTypeNode* dst, _Bool isStart) { */ -/* DBG_VERBOSE(printf("UA_DataTypeNode entered with dst=%p,isStart=%d\n", (void* ) dst, isStart)); */ -/* UA_UInt32 i; */ - -/* if (isStart) { */ -/* // create a new object if called with UA_NULL */ -/* if (dst == UA_NULL) { */ -/* UA_DataTypeNode_new(&dst); */ -/* s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void*) dst; */ -/* } */ - -/* s->parent[s->depth].len = 0; */ -/* XML_Stack_addChildHandler(s, "DisplayName", strlen("DisplayName"), (XML_decoder) UA_LocalizedText_decodeXmlFromStack, UA_LOCALIZEDTEXT, &(dst->displayName)); */ -/* XML_Stack_addChildHandler(s, "Description", strlen("Description"),(XML_decoder) UA_LocalizedText_decodeXmlFromStack, UA_LOCALIZEDTEXT, &(dst->description)); */ -/* XML_Stack_addChildHandler(s, "BrowseName", strlen("BrowseName"),(XML_decoder) UA_QualifiedName_decodeXmlFromStack, UA_QUALIFIEDNAME, &(dst->description)); */ -/* XML_Stack_addChildHandler(s, "IsAbstract", strlen("IsAbstract"),(XML_decoder) UA_Boolean_decodeXmlFromStack, UA_BOOLEAN, &(dst->description)); */ -/* XML_Stack_addChildHandler(s, "References", strlen("References"),(XML_decoder) UA_TypedArray_decodeXmlFromStack, UA_REFERENCENODE, UA_NULL); */ - -/* // set missing default attributes */ -/* dst->nodeClass = UA_NODECLASS_DATATYPE; */ - -/* // set attributes */ -/* for (i = 0; attr[i]; i += 2) { */ -/* if (0 == strncmp("NodeId", attr[i], strlen("NodeId"))) { */ -/* UA_NodeId_copycstring(attr[i + 1], &(dst->nodeId), s->aliases); */ -/* } else if (0 == strncmp("BrowseName", attr[i], strlen("BrowseName"))) { */ -/* UA_String_copycstring(attr[i + 1], &(dst->browseName.name)); */ -/* dst->browseName.namespaceIndex = 0; */ -/* } else if (0 == strncmp("DisplayName", attr[i], strlen("DisplayName"))) { */ -/* UA_String_copycstring(attr[i + 1], &(dst->displayName.text)); */ -/* dst->displayName.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT; */ -/* } else if (0 == strncmp("IsAbstract", attr[i], strlen("IsAbstract"))) { */ -/* UA_Boolean_copycstring(attr[i + 1], &(dst->isAbstract)); */ -/* dst->displayName.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT; */ -/* } else if (0 == strncmp("Description", attr[i], strlen("Description"))) { */ -/* UA_String_copycstring(attr[i + 1], &(dst->description.text)); */ -/* dst->description.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT; */ -/* } else { */ -/* DBG_ERR(XML_Stack_print(s));DBG_ERR(printf("%s - unknown attribute\n", attr[i])); */ -/* } */ -/* } */ -/* } else { */ -/* switch (s->parent[s->depth - 1].activeChild) { */ -/* case 4: // References */ -/* if (attr != UA_NULL) { */ -/* UA_TypedArray* array = (UA_TypedArray *) attr; */ -/* DBG_VERBOSE(printf("finished aliases: references=%p, size=%d\n",(void*)array,(array==UA_NULL)?-1:array->size)); */ -/* dst->referencesSize = array->size; */ -/* /\* dst->references = (UA_ReferenceNode**) array->elements; *\/ */ -/* } */ -/* break; */ -/* } */ -/* } */ -/* return UA_SUCCESS; */ -/* } */ - -// Gets generated in ua_types_generated.h and .c. But currently only as stubs -/* UA_Int32 UA_ObjectTypeNode_decodeXmlFromStack(XML_Stack* s, XML_Attr* attr, UA_ObjectTypeNode* dst, _Bool isStart) { */ -/* DBG_VERBOSE(printf("UA_DataTypeNode entered with dst=%p,isStart=%d\n", (void* ) dst, isStart)); */ -/* UA_UInt32 i; */ - -/* if (isStart) { */ -/* // create a new object if called with UA_NULL */ -/* if (dst == UA_NULL) { */ -/* UA_ObjectTypeNode_new(&dst); */ -/* s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void*) dst; */ -/* } */ - -/* s->parent[s->depth].len = 0; */ -/* XML_Stack_addChildHandler(s, "DisplayName", strlen("DisplayName"), (XML_decoder) UA_LocalizedText_decodeXmlFromStack, UA_LOCALIZEDTEXT, &(dst->displayName)); */ -/* XML_Stack_addChildHandler(s, "Description", strlen("Description"),(XML_decoder) UA_LocalizedText_decodeXmlFromStack, UA_LOCALIZEDTEXT, &(dst->description)); */ -/* XML_Stack_addChildHandler(s, "BrowseName", strlen("BrowseName"),(XML_decoder) UA_QualifiedName_decodeXmlFromStack, UA_QUALIFIEDNAME, &(dst->description)); */ -/* XML_Stack_addChildHandler(s, "IsAbstract", strlen("IsAbstract"),(XML_decoder) UA_Boolean_decodeXmlFromStack, UA_BOOLEAN, &(dst->description)); */ -/* XML_Stack_addChildHandler(s, "References", strlen("References"),(XML_decoder) UA_TypedArray_decodeXmlFromStack, UA_REFERENCENODE, UA_NULL); */ - -/* // set missing default attributes */ -/* dst->nodeClass = UA_NODECLASS_OBJECTTYPE; */ - -/* // set attributes */ -/* for (i = 0; attr[i]; i += 2) { */ -/* if (0 == strncmp("NodeId", attr[i], strlen("NodeId"))) { */ -/* UA_NodeId_copycstring(attr[i + 1], &(dst->nodeId), s->aliases); */ -/* } else if (0 == strncmp("BrowseName", attr[i], strlen("BrowseName"))) { */ -/* UA_String_copycstring(attr[i + 1], &(dst->browseName.name)); */ -/* dst->browseName.namespaceIndex = 0; */ -/* } else if (0 == strncmp("DisplayName", attr[i], strlen("DisplayName"))) { */ -/* UA_String_copycstring(attr[i + 1], &(dst->displayName.text)); */ -/* dst->displayName.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT; */ -/* } else if (0 == strncmp("IsAbstract", attr[i], strlen("IsAbstract"))) { */ -/* UA_Boolean_copycstring(attr[i + 1], &(dst->isAbstract)); */ -/* dst->displayName.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT; */ -/* } else if (0 == strncmp("Description", attr[i], strlen("Description"))) { */ -/* UA_String_copycstring(attr[i + 1], &(dst->description.text)); */ -/* dst->description.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT; */ -/* } else { */ -/* DBG_ERR(XML_Stack_print(s));DBG_ERR(printf("%s - unknown attribute\n", attr[i])); */ -/* } */ -/* } */ -/* } else { */ -/* switch (s->parent[s->depth - 1].activeChild) { */ -/* case 4: // References */ -/* if (attr != UA_NULL) { */ -/* UA_TypedArray* array = (UA_TypedArray *) attr; */ -/* DBG_VERBOSE(printf("finished aliases: references=%p, size=%d\n",(void*)array,(array==UA_NULL)?-1:array->size)); */ -/* dst->referencesSize = array->size; */ -/* /\* dst->references = (UA_ReferenceNode**) array->elements; *\/ */ -/* } */ -/* break; */ -/* } */ -/* } */ -/* return UA_SUCCESS; */ -/* } */ - -// Gets generated in ua_types_generated.h and .c. But currently only as stubs -/* UA_Int32 UA_VariableTypeNode_decodeXmlFromStack(XML_Stack* s, XML_Attr* attr, UA_VariableTypeNode* dst, _Bool isStart) { */ -/* DBG_VERBOSE(printf("UA_DataTypeNode entered with dst=%p,isStart=%d\n", (void* ) dst, isStart)); */ -/* UA_UInt32 i; */ - -/* if (isStart) { */ -/* // create a new object if called with UA_NULL */ -/* if (dst == UA_NULL) { */ -/* UA_VariableTypeNode_new(&dst); */ -/* s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void*) dst; */ -/* } */ - -/* s->parent[s->depth].len = 0; */ -/* XML_Stack_addChildHandler(s, "DisplayName", strlen("DisplayName"), (XML_decoder) UA_LocalizedText_decodeXmlFromStack, UA_LOCALIZEDTEXT, &(dst->displayName)); */ -/* XML_Stack_addChildHandler(s, "Description", strlen("Description"),(XML_decoder) UA_LocalizedText_decodeXmlFromStack, UA_LOCALIZEDTEXT, &(dst->description)); */ -/* XML_Stack_addChildHandler(s, "BrowseName", strlen("BrowseName"),(XML_decoder) UA_QualifiedName_decodeXmlFromStack, UA_QUALIFIEDNAME, &(dst->description)); */ -/* XML_Stack_addChildHandler(s, "IsAbstract", strlen("IsAbstract"),(XML_decoder) UA_Boolean_decodeXmlFromStack, UA_BOOLEAN, &(dst->description)); */ -/* XML_Stack_addChildHandler(s, "References", strlen("References"),(XML_decoder) UA_TypedArray_decodeXmlFromStack, UA_REFERENCENODE, UA_NULL); */ - -/* // set missing default attributes */ -/* dst->nodeClass = UA_NODECLASS_VARIABLETYPE; */ - -/* // set attributes */ -/* for (i = 0; attr[i]; i += 2) { */ -/* if (0 == strncmp("NodeId", attr[i], strlen("NodeId"))) { */ -/* UA_NodeId_copycstring(attr[i + 1], &(dst->nodeId), s->aliases); */ -/* } else if (0 == strncmp("BrowseName", attr[i], strlen("BrowseName"))) { */ -/* UA_String_copycstring(attr[i + 1], &(dst->browseName.name)); */ -/* dst->browseName.namespaceIndex = 0; */ -/* } else if (0 == strncmp("DisplayName", attr[i], strlen("DisplayName"))) { */ -/* UA_String_copycstring(attr[i + 1], &(dst->displayName.text)); */ -/* dst->displayName.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT; */ -/* } else if (0 == strncmp("IsAbstract", attr[i], strlen("IsAbstract"))) { */ -/* UA_Boolean_copycstring(attr[i + 1], &(dst->isAbstract)); */ -/* dst->displayName.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT; */ -/* } else if (0 == strncmp("Description", attr[i], strlen("Description"))) { */ -/* UA_String_copycstring(attr[i + 1], &(dst->description.text)); */ -/* dst->description.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT; */ -/* } else { */ -/* DBG_ERR(XML_Stack_print(s));DBG_ERR(printf("%s - unknown attribute\n", attr[i])); */ -/* } */ -/* } */ -/* } else { */ -/* switch (s->parent[s->depth - 1].activeChild) { */ -/* case 4: // References */ -/* if (attr != UA_NULL) { */ -/* UA_TypedArray* array = (UA_TypedArray *) attr; */ -/* DBG_VERBOSE(printf("finished aliases: references=%p, size=%d\n",(void*)array,(array==UA_NULL)?-1:array->size)); */ -/* dst->referencesSize = array->size; */ -/* /\* dst->references = (UA_ReferenceNode**) array->elements; *\/ */ -/* } */ -/* break; */ -/* } */ -/* } */ -/* return UA_SUCCESS; */ -/* } */ - -// Gets generated in ua_types_generated.h and .c. But currently only as stubs -/* UA_Int32 UA_ObjectNode_decodeXmlFromStack(XML_Stack* s, XML_Attr* attr, UA_ObjectNode* dst, _Bool isStart) { */ -/* DBG_VERBOSE(printf("UA_ObjectNode entered with dst=%p,isStart=%d\n", (void* ) dst, isStart)); */ -/* UA_UInt32 i; */ - -/* if (isStart) { */ -/* // create a new object if called with UA_NULL */ -/* if (dst == UA_NULL) { */ -/* UA_ObjectNode_new(&dst); */ -/* s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void*) dst; */ -/* } */ - -/* XML_Stack_addChildHandler(s, "DisplayName", strlen("DisplayName"), (XML_decoder) UA_LocalizedText_decodeXmlFromStack, UA_LOCALIZEDTEXT, &(dst->displayName)); */ -/* XML_Stack_addChildHandler(s, "Description", strlen("Description"), (XML_decoder) UA_LocalizedText_decodeXmlFromStack, UA_LOCALIZEDTEXT, &(dst->description)); */ -/* XML_Stack_addChildHandler(s, "BrowseName", strlen("BrowseName"), (XML_decoder) UA_QualifiedName_decodeXmlFromStack, UA_QUALIFIEDNAME, &(dst->browseName)); */ -/* XML_Stack_addChildHandler(s, "SymbolicName", strlen("SymbolicName"), (XML_decoder) UA_QualifiedName_decodeXmlFromStack, UA_QUALIFIEDNAME,&(dst->browseName)); */ -/* XML_Stack_addChildHandler(s, "References", strlen("References"), (XML_decoder) UA_TypedArray_decodeXmlFromStack, UA_REFERENCENODE, UA_NULL); */ - -/* // set missing default attributes */ -/* dst->nodeClass = UA_NODECLASS_OBJECT; */ - -/* // set attributes */ -/* for (i = 0; attr[i]; i += 2) { */ -/* if (0 == strncmp("NodeId", attr[i], strlen("NodeId"))) { */ -/* UA_NodeId_copycstring(attr[i + 1], &(dst->nodeId), s->aliases); */ -/* } else if (0 == strncmp("SymbolicName", attr[i], strlen("SymbolicName"))) { */ -/* UA_String_copycstring(attr[i + 1], &(dst->browseName.name)); */ -/* dst->browseName.namespaceIndex = 0; */ -/* } else if (0 == strncmp("BrowseName", attr[i], strlen("BrowseName"))) { */ -/* UA_String_copycstring(attr[i + 1], &(dst->browseName.name)); */ -/* dst->browseName.namespaceIndex = 0; */ -/* } else if (0 == strncmp("DisplayName", attr[i], strlen("DisplayName"))) { */ -/* UA_String_copycstring(attr[i + 1], &(dst->displayName.text)); */ -/* dst->displayName.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT; */ -/* } else if (0 == strncmp("Description", attr[i], strlen("Description"))) { */ -/* UA_String_copycstring(attr[i + 1], &(dst->description.text)); */ -/* dst->description.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT; */ -/* } else { */ -/* DBG_ERR(XML_Stack_print(s));DBG_ERR(printf("%s - unknown attribute\n", attr[i])); */ -/* } */ -/* } */ -/* } else { */ -/* if (s->parent[s->depth - 1].activeChild == 4 && attr != UA_NULL ) { // References Array */ -/* UA_TypedArray* array = (UA_TypedArray*) attr; */ -/* DBG(printf("UA_ObjectNode_decodeXML finished references: references=%p, size=%d\n",(void*)array,(array==UA_NULL)?-1:array->size)); */ -/* dst->referencesSize = array->size; */ -/* /\* dst->references = (UA_ReferenceNode**) array->elements; *\/ */ -/* s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = UA_NULL; */ -/* } */ -/* } */ -/* return UA_SUCCESS; */ -/* } */ - - -// Gets generated in ua_types_generated.h and .c. But currently only as stubs -/* UA_Int32 UA_Variant_decodeXmlFromStack(XML_Stack* s, XML_Attr* attr, UA_Variant* dst, _Bool isStart) { */ -/* DBG_VERBOSE(printf("UA_Variant entered with dst=%p,isStart=%d\n", (void* ) dst, isStart)); */ -/* UA_UInt32 i; */ - -/* if (isStart) { */ -/* // create a new object if called with UA_NULL */ -/* if (dst == UA_NULL) { */ -/* UA_Variant_new(&dst); */ -/* s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void*) dst; */ -/* } */ - -/* s->parent[s->depth].len = 0; */ -/* XML_Stack_addChildHandler(s, "ListOfExtensionObject", strlen("ListOfExtensionObject"), (XML_decoder) UA_TypedArray_decodeXmlFromStack, UA_EXTENSIONOBJECT, UA_NULL); */ -/* XML_Stack_addChildHandler(s, "ListOfLocalizedText", strlen("ListOfLocalizedText"), (XML_decoder) UA_TypedArray_decodeXmlFromStack, UA_LOCALIZEDTEXT, UA_NULL); */ - -/* // set attributes */ -/* for (i = 0; attr[i]; i += 2) { */ -/* { */ -/* DBG_ERR(XML_Stack_print(s)); */ -/* DBG_ERR(printf("%s - unknown attribute\n", attr[i])); */ -/* } */ -/* } */ -/* } else { */ -/* if (s->parent[s->depth - 1].activeChild == 0 && attr != UA_NULL ) { // ExtensionObject */ -/* UA_TypedArray* array = (UA_TypedArray*) attr; */ -/* DBG_VERBOSE(printf("UA_Variant_decodeXML - finished array: references=%p, size=%d\n",(void*)array,(array==UA_NULL)?-1:array->size)); */ -/* dst->arrayLength = array->size; */ -/* dst->data = array->elements; */ -/* dst->vt = &UA_.types[UA_EXTENSIONOBJECT]; */ -/* dst->encodingMask = UA_EXTENSIONOBJECT_NS0 & UA_VARIANT_ENCODINGMASKTYPE_ARRAY; */ -/* s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = UA_NULL; */ -/* } else if (s->parent[s->depth - 1].activeChild == 1 && attr != UA_NULL ) { // LocalizedText */ -/* UA_TypedArray* array = (UA_TypedArray*) attr; */ -/* DBG_VERBOSE(printf("UA_Variant_decodeXML - finished array: references=%p, size=%d\n",(void*)array,(array==UA_NULL)?-1:array->size)); */ -/* dst->arrayLength = array->size; */ -/* dst->data = array->elements; */ -/* dst->vt = &UA_.types[UA_LOCALIZEDTEXT]; */ -/* dst->encodingMask = UA_LOCALIZEDTEXT_NS0 & UA_VARIANT_ENCODINGMASKTYPE_ARRAY; */ -/* s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = UA_NULL; */ -/* } */ -/* } */ -/* return UA_SUCCESS; */ -/* } */ - -// Gets generated in ua_types_generated.h and .c. But currently only as stubs -/* UA_Int32 UA_ExtensionObject_decodeXmlFromStack(XML_Stack* s, XML_Attr* attr, UA_ExtensionObject* dst, _Bool isStart) { */ -/* DBG_VERBOSE(printf("UA_ExtensionObject entered with dst=%p,isStart=%d\n", (void* ) dst, isStart)); */ -/* UA_UInt32 i; */ - -/* if (isStart) { */ -/* // create a new object if called with UA_NULL */ -/* if (dst == UA_NULL) { */ -/* UA_ExtensionObject_new(&dst); */ -/* s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void*) dst; */ -/* } */ - -/* s->parent[s->depth].len = 0; */ -/* XML_Stack_addChildHandler(s, "TypeId", strlen("TypeId"), (XML_decoder) UA_NodeId_decodeXmlFromStack, UA_NODEID, &(dst->typeId)); */ -/* // XML_Stack_addChildHandler(s, "Body", strlen("Body"), (XML_decoder) UA_Body_decodeXML, UA_LOCALIZEDTEXT, UA_NULL); */ - -/* // set attributes */ -/* for (i = 0; attr[i]; i += 2) { */ -/* { */ -/* DBG_ERR(XML_Stack_print(s)); */ -/* DBG_ERR(printf("%s - unknown attribute\n", attr[i])); */ -/* } */ -/* } */ -/* } */ -/* return UA_SUCCESS; */ -/* } */ - -_Bool UA_NodeId_isBuiltinType(UA_NodeId* nodeid) { - return (nodeid->namespaceIndex == 0 && nodeid->identifier.numeric >= UA_BOOLEAN_NS0 && - nodeid->identifier.numeric <= UA_DIAGNOSTICINFO_NS0 - ); -} - -// Gets generated in ua_types_generated.h and .c. But currently only as stubs -/* UA_Int32 UA_VariableNode_decodeXmlFromStack(XML_Stack* s, XML_Attr* attr, UA_VariableNode* dst, _Bool isStart) { */ -/* DBG_VERBOSE(printf("UA_VariableNode entered with dst=%p,isStart=%d\n", (void* ) dst, isStart)); */ -/* UA_UInt32 i; */ - -/* if (isStart) { */ -/* // create a new object if called with UA_NULL */ -/* if (dst == UA_NULL) { */ -/* UA_VariableNode_new(&dst); */ -/* s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void*) dst; */ -/* } */ - -/* s->parent[s->depth].len = 0; */ -/* XML_Stack_addChildHandler(s, "DisplayName", strlen("DisplayName"), (XML_decoder) UA_LocalizedText_decodeXmlFromStack, UA_LOCALIZEDTEXT, */ -/* &(dst->displayName)); */ -/* XML_Stack_addChildHandler(s, "Description", strlen("Description"),(XML_decoder) UA_LocalizedText_decodeXmlFromStack, UA_LOCALIZEDTEXT, */ -/* &(dst->description)); */ -/* XML_Stack_addChildHandler(s, "DataType", strlen("DataType"),(XML_decoder) UA_NodeId_decodeXmlFromStack, UA_NODEID, &(dst->dataType)); */ -/* XML_Stack_addChildHandler(s, "ValueRank", strlen("ValueRank"),(XML_decoder) UA_Int32_decodeXmlFromStack, UA_INT32, &(dst->valueRank)); */ -/* XML_Stack_addChildHandler(s, "Value", strlen("Value"),(XML_decoder) UA_Variant_decodeXmlFromStack, UA_VARIANT, &(dst->value)); */ -/* XML_Stack_addChildHandler(s, "References", strlen("References"), (XML_decoder) UA_TypedArray_decodeXmlFromStack, UA_REFERENCENODE, */ -/* UA_NULL); */ - -/* // set missing default attributes */ -/* dst->nodeClass = UA_NODECLASS_VARIABLE; */ - -/* // set attributes */ -/* for (i = 0; attr[i]; i += 2) { */ -/* if (0 == strncmp("NodeId", attr[i], strlen("NodeId"))) { */ -/* UA_NodeId_copycstring(attr[i + 1], &(dst->nodeId), s->aliases); */ -/* } else if (0 == strncmp("DataType", attr[i], strlen("DataType"))) { */ -/* UA_NodeId_copycstring(attr[i + 1], &(dst->dataType), s->aliases); */ -/* if (UA_NodeId_isBuiltinType(&(dst->dataType))) { */ -/* dst->value.encodingMask = dst->dataType.identifier.numeric; */ -/* dst->value.vt = &UA_.types[UA_ns0ToVTableIndex(&dst->dataType)]; */ -/* } else { */ -/* dst->value.encodingMask = UA_EXTENSIONOBJECT_NS0; */ -/* dst->value.vt = &UA_.types[UA_EXTENSIONOBJECT]; */ -/* } */ -/* } else if (0 == strncmp("ValueRank", attr[i], strlen("ValueRank"))) { */ -/* dst->valueRank = atoi(attr[i + 1]); */ -/* } else if (0 == strncmp("ParentNodeId", attr[i], strlen("ParentNodeId"))) { */ -/* // FIXME: this seems to be redundant to the hasProperty-reference */ -/* } else if (0 == strncmp("BrowseName", attr[i], strlen("BrowseName"))) { */ -/* UA_String_copycstring(attr[i + 1], &(dst->browseName.name)); */ -/* dst->browseName.namespaceIndex = 0; */ -/* } else if (0 == strncmp("DisplayName", attr[i], strlen("DisplayName"))) { */ -/* UA_String_copycstring(attr[i + 1], &(dst->displayName.text)); */ -/* dst->displayName.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT; */ -/* } else if (0 == strncmp("Description", attr[i], strlen("Description"))) { */ -/* UA_String_copycstring(attr[i + 1], &(dst->description.text)); */ -/* dst->description.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT; */ -/* } else { */ -/* DBG_ERR(XML_Stack_print(s)); */ -/* DBG_ERR(printf("%s - unknown attribute\n", attr[i])); */ -/* } */ -/* } */ -/* } else { */ -/* if (s->parent[s->depth - 1].activeChild == 5 && attr != UA_NULL) { // References */ -/* UA_TypedArray* array = (UA_TypedArray*) attr; */ -/* DBG(printf("UA_VariableNode_decodeXML - finished references=%p, size=%d\n",(void*)array,(array==UA_NULL)?-1:array->size)); */ -/* dst->referencesSize = array->size; */ -/* /\* dst->references = (UA_ReferenceNode**) array->elements; *\/ */ -/* s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = UA_NULL; */ -/* } */ -/* } */ -/* return UA_SUCCESS; */ -/* } */ - -#ifdef DEBUG -void print_node(UA_Node const * node) { - if (node != UA_NULL) { - UA_NodeId_printf("node.nodeId=", &(node->nodeId)); - printf("\t.browseName='%.*s'\n", node->browseName.name.length, node->browseName.name.data); - printf("\t.displayName='%.*s'\n", node->displayName.text.length, node->displayName.text.data); - printf("\t.description='%.*s%s'\n", node->description.text.length > 40 ? 40 : node->description.text.length, - node->description.text.data, node->description.text.length > 40 ? "..." : ""); - printf("\t.nodeClass=%d\n", node->nodeClass); - printf("\t.writeMask=%d\n", node->writeMask); - printf("\t.userWriteMask=%d\n", node->userWriteMask); - printf("\t.references.size=%d\n", node->referencesSize); - UA_Int32 i; - for(i = 0;i < node->referencesSize;i++) { - printf("\t\t.element[%d]", i); - UA_ReferenceNode_println("=", &node->references[i]); - } - switch(node->nodeClass) { - case UA_NODECLASS_VARIABLE: - { - UA_VariableNode const *p = (UA_VariableNode const *)node; - printf("\t----- UA_VariableNode ----- \n"); - UA_NodeId_printf("\t.dataType=", &(p->dataType)); - printf("\t.valueRank=%d\n", p->valueRank); - printf("\t.accessLevel=%d\n", p->accessLevel); - printf("\t.userAccessLevel=%d\n", p->userAccessLevel); - printf("\t.arrayDimensionsSize=%d\n", p->arrayDimensionsSize); - printf("\t.minimumSamplingInterval=%f\n", p->minimumSamplingInterval); - printf("\t.historizing=%d\n", p->historizing); - printf("\t----- UA_Variant ----- \n"); - printf("\t.value.type.name=%s\n", p->value.vt->name); - printf("\t.value.array.length=%d\n", p->value.arrayLength); - UA_Int32 i; - UA_Byte *data = (UA_Byte *)p->value.data; - for(i = 0;i < p->value.arrayLength || (p->value.arrayLength == -1 && i == 0);++i) { - UA_Byte *currentData = data + (i*p->value.vt->memSize); - printf("\t.value.array.element[%d]=%p", i, currentData); - switch(p->value.vt->typeId.identifier.numeric) { - case UA_LOCALIZEDTEXT_NS0: - { - if(p->value.data != UA_NULL) { - UA_LocalizedText *ltp = (UA_LocalizedText *)currentData; - printf(",locale={%d,{%.*s}},text={%d,{%.*s}}", ltp->locale.length, - ltp->locale.length, ltp->locale.data, ltp->text.length, - ltp->text.length, ltp->text.data); - } - } - break; - - case UA_EXTENSIONOBJECT_NS0: - { - if(p->value.data != UA_NULL) { - UA_ExtensionObject *eo = (UA_ExtensionObject *)currentData; - if(eo == UA_NULL) - printf(",(null)"); - else - printf(",enc=%d,typeId={i=%d}", eo->encoding, eo->typeId.identifier.numeric); - } - } - break; - - default: - break; - } - printf("\n"); - } - } - break; - - // case UA_NODECLASS_DATATYPE: - default: - break; - } - } -} -#endif - -UA_Int32 UA_NodeSetAlias_decodeXmlFromStack(XML_Stack *s, XML_Attr *attr, UA_NodeSetAlias *dst, _Bool isStart) { - DBG_VERBOSE(printf("UA_NodeSetAlias entered with dst=%p,isStart=%d\n", (void * )dst, isStart)); - if(isStart) { - // create if necessary - if(dst == UA_NULL) { - UA_NodeSetAlias_new(&dst); - s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void *)dst; - } - // set handlers - s->parent[s->depth].len = 0; - XML_Stack_addChildHandler(s, "Alias", strlen("Alias"), (XML_decoder)UA_String_decodeXmlFromStack, UA_STRING, - &(dst->alias)); - XML_Stack_addChildHandler(s, "Value", strlen("Value"), (XML_decoder)UA_String_decodeXmlFromStack, UA_STRING, - &(dst->value)); - XML_Stack_handleTextAsElementOf(s, "Data", 1); - - // set attributes - UA_Int32 i; - for(i = 0;attr[i];i += 2) { - if(0 == strncmp("Alias", attr[i], strlen("Alias"))) - UA_String_copycstring(attr[i + 1], &(dst->alias)); - else if(0 == strncmp("Value", attr[i], strlen("Value"))) - UA_String_copycstring(attr[i + 1], &(dst->value)); - else { - DBG_ERR(XML_Stack_print(s)); DBG_ERR(printf("%s - unknown attribute\n", attr[i])); - } - } - } - return UA_SUCCESS; -} - -UA_Int32 UA_NodeSetAliases_decodeXmlFromStack(XML_Stack *s, XML_Attr *attr, UA_NodeSetAliases *dst, _Bool isStart) { - DBG_VERBOSE(printf("UA_NodeSetALiases entered with dst=%p,isStart=%d\n", (void * )dst, isStart)); - if(isStart) { - if(dst == UA_NULL) { - UA_NodeSetAliases_new(&dst); - s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void *)dst; - } - s->parent[s->depth].len = 0; - XML_Stack_addChildHandler(s, "Alias", strlen( - "Alias"), (XML_decoder)UA_NodeSetAlias_decodeXmlFromStack, UA_INVALIDTYPE, - UA_NULL); - } else { - // sub element is ready, add to array - if(dst->size < 0 || dst->size == 0) { - dst->size = 1; - UA_alloc((void ** )&(dst->aliases), dst->size * sizeof(UA_NodeSetAlias *)); - DBG_VERBOSE( - printf("allocate aliases:dst=%p, aliases=%p, size=%d\n", (void * )dst, (void * )(dst->aliases), - dst->size)); - } else { - dst->size++; - dst->aliases = realloc(dst->aliases, dst->size * sizeof(UA_NodeSetAlias *)); - DBG_VERBOSE( - printf("reallocate aliases:dst=%p, aliases=%p, size=%d\n", (void * )dst, (void * )(dst->aliases), - dst->size)); - } - // index starts with 0, therefore size-1 - DBG_VERBOSE(printf("assign alias:dst=%p, src=%p\n", (void * )dst->aliases[dst->size - 1], (void * )attr)); - dst->aliases[dst->size - 1] = (UA_NodeSetAlias *)attr; - DBG_VERBOSE(printf("UA_NodeSetAliases clears %p\n", - (void * )(s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj))); - s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = UA_NULL; - } - return UA_SUCCESS; -} - -UA_Int32 UA_NodeSet_decodeXmlFromStack(XML_Stack *s, XML_Attr *attr, UA_NodeSet *dst, _Bool isStart) { - DBG_VERBOSE(printf("UA_NodeSet entered with dst=%p,isStart=%d\n", (void * )dst, isStart)); - if(isStart) { - if(dst == UA_NULL) { - UA_NodeSet_new(&dst, 99); // we don't really need the namespaceid for this..' - s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void *)dst; - } - s->parent[s->depth].len = 0; - XML_Stack_addChildHandler(s, "Aliases", strlen( - "Aliases"), (XML_decoder)UA_NodeSetAliases_decodeXmlFromStack, UA_INVALIDTYPE, - &(dst->aliases)); - XML_Stack_addChildHandler(s, "UADataType", strlen( - "UADataType"), (XML_decoder)UA_DataTypeNode_decodeXmlFromStack, UA_DATATYPENODE, - UA_NULL); - XML_Stack_addChildHandler(s, "UAVariableType", strlen( - "UAVariableType"), (XML_decoder)UA_VariableTypeNode_decodeXmlFromStack, - UA_VARIABLETYPENODE, UA_NULL); - XML_Stack_addChildHandler(s, "UAVariable", strlen( - "UAVariable"), (XML_decoder)UA_VariableNode_decodeXmlFromStack, UA_VARIABLENODE, - UA_NULL); - XML_Stack_addChildHandler(s, "UAObjectType", strlen( - "UAObjectType"), (XML_decoder)UA_ObjectTypeNode_decodeXmlFromStack, - UA_OBJECTTYPENODE, UA_NULL); - XML_Stack_addChildHandler(s, "UAObject", strlen( - "UAObject"), (XML_decoder)UA_ObjectNode_decodeXmlFromStack, UA_OBJECTNODE, - UA_NULL); - } else { - if(s->parent[s->depth - 1].activeChild == 0 && attr != UA_NULL) { - UA_NodeSetAliases *aliases = (UA_NodeSetAliases *)attr; - DBG(printf("UA_NodeSet_decodeXml - finished aliases: aliases=%p, size=%d\n", (void *)aliases, - (aliases == UA_NULL) ? -1 : aliases->size)); - s->aliases = aliases; - s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = UA_NULL; - } else { - UA_Node* node = (UA_Node*) attr; - DBG(printf("UA_NodeSet_decodeXML - finished node: node=%p\n", (void* )node)); - Namespace_insert(dst->ns, &node, 0); - DBG(printf("UA_NodeSet_decodeXml - Inserting ")); - s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = UA_NULL; - } - } - return UA_SUCCESS; -} - -/** lookup if element is a known child of parent, if yes go for it otherwise ignore */ -void XML_Stack_startElement(void *data, const char *el, const char **attr) { - XML_Stack *s = (XML_Stack *)data; - int i; - -// scan expected children - XML_Parent *cp = &s->parent[s->depth]; - for(i = 0;i < cp->len;i++) { - if(0 == strncmp(cp->children[i].name, el, cp->children[i].length)) { - DBG_VERBOSE(XML_Stack_print(s)); - DBG_VERBOSE(printf("%s - processing\n", el)); - - cp->activeChild = i; - - s->depth++; - s->parent[s->depth].name = el; - s->parent[s->depth].len = 0; - s->parent[s->depth].textAttribIdx = -1; - s->parent[s->depth].activeChild = -1; - - // finally call the elementHandler and return - cp->children[i].elementHandler(data, attr, cp->children[i].obj, TRUE); - return; - } - } -// if we come here we rejected the processing of el - DBG_VERBOSE(XML_Stack_print(s)); - DBG_VERBOSE(printf("%s - rejected\n", el)); - s->depth++; - s->parent[s->depth].name = el; -// this should be sufficient to reject the children as well - s->parent[s->depth].len = 0; -} - -UA_Int32 XML_isSpace(cstring s, int len) { - int i; - for(i = 0;i < len;i++) { - if(!isspace(s[i])) - return UA_FALSE; - } - return UA_TRUE; -} - -/* gather text */ -void XML_Stack_handleText(void * data, const char *txt, int len) { - /* XML_Stack* s = (XML_Stack*) data; */ - - if (len > 0 && !XML_isSpace(txt, len)) { - /* XML_Parent* cp = &(s->parent[s->depth]); // determine current element */ - UA_ByteString src = { len+1, (UA_Byte*) txt }; - UA_ByteString *dst; - UA_ByteString_new(&dst); // alloc dst - UA_ByteString_copy(&src,dst); // alloc dst->data and copy txt - dst->data[len] = 0; // add terminating zero to handle single line efficiently - /* UA_list_addPayloadToBack(&(cp->textGatherList), (void*) dst); */ - /* if (cp->totalGatherLength == -1) { */ - /* cp->totalGatherLength = len; */ - /* } else { */ - /* cp->totalGatherLength += len; */ - /* } */ - } -} - -char* theGatherBuffer; -void textGatherListTotalLength(void* payload) { - UA_ByteString* b = (UA_ByteString*) payload; - #ifdef DEBUG - UA_ByteString_printf("\t",b); - #endif - UA_memcpy(theGatherBuffer,b->data,b->length-1); // remove trailing zero - theGatherBuffer += (b->length-1); -} -/** if we are an activeChild of a parent we call the child-handler */ -void XML_Stack_endElement(void *data, const char *el) { - /* XML_Stack *s = (XML_Stack *)data; */ - - /* XML_Parent* ce = &(s->parent[s->depth]); */ - /* if (ce->textAttribIdx >= 0 && ce->totalGatherLength > 0 ) { */ - /* ce->activeChild = ce->textAttribIdx; */ - /* char* buf; */ - /* if (UA_list_getFirst(&(ce->textGatherList)) == UA_list_getLast(&(ce->textGatherList)) ) { */ - /* buf = (char*) ((UA_ByteString*) UA_list_getFirst(&(ce->textGatherList))->payload)->data; */ - /* } else { */ - /* printf("XML_Stack_endElement - more than one text snippet with total length=%d:\n",ce->totalGatherLength); */ - /* UA_alloc((void**)&theGatherBuffer,ce->totalGatherLength+1); */ - /* buf = theGatherBuffer; */ - /* UA_list_iteratePayload(&(ce->textGatherList), textGatherListTotalLength); */ - /* buf[ce->totalGatherLength] = 0; */ - /* printf("XML_Stack_endElement - gatherBuffer %s:\n",buf); */ - /* } */ - /* XML_Attr attr[3] = { ce->textAttrib, buf, UA_NULL }; */ - /* DBG(printf("handleText @ %s calls start elementHandler %s with dst=%p, buf={%s}\n", XML_Stack_path(s),ce->children[ce->activeChild].name, ce->children[ce->activeChild].obj, buf)); */ - /* ce->children[ce->activeChild].elementHandler(s, attr, ce->children[ce->activeChild].obj, TRUE); */ - /* if (s->parent[s->depth-1].activeChild > 0) { */ - /* XML_child* c = &(s->parent[s->depth-1].children[s->parent[s->depth-1].activeChild]); */ - /* c->elementHandler(s, UA_NULL, c->obj, FALSE); */ - /* } */ - /* if (UA_list_getFirst(&(ce->textGatherList)) != UA_list_getLast(&(ce->textGatherList)) ) { */ - /* UA_free(buf); */ - /* } */ - /* UA_list_destroy(&(ce->textGatherList),(UA_list_PayloadVisitor) UA_ByteString_delete); */ - /* UA_list_init(&(ce->textGatherList)); // don't know if destroy leaves the list in usable state... */ - /* ce->totalGatherLength = -1; */ - /* } */ - - /* // the parent of the parent (pop) of the element knows the elementHandler, therefore depth-2! */ - /* if (s->depth > 1) { */ - /* // inform parents elementHandler that everything is done */ - /* XML_Parent *cp = &(s->parent[s->depth - 1]); */ - /* XML_Parent *cpp = &(s->parent[s->depth - 2]); */ - /* if(cpp->activeChild >= 0 && cp->activeChild >= 0) { */ - /* DBG_VERBOSE(XML_Stack_print(s)); */ - /* DBG_VERBOSE( */ - /* printf(" - inform pop %s, arg=%p\n", cpp->children[cpp->activeChild].name, */ - /* (void * )cp->children[cp->activeChild].obj)); */ - /* cpp->children[cpp->activeChild].elementHandler(s, (XML_Attr *)cp->children[cp->activeChild].obj, */ - /* cpp->children[cpp->activeChild].obj, FALSE); */ - /* } */ - /* // reset */ - /* cp->activeChild = -1; */ - /* } */ - /* s->depth--; */ -} diff --git a/src/ongoing/ua_xml.h b/src/ongoing/ua_xml.h deleted file mode 100644 index f80f15c45c1..00000000000 --- a/src/ongoing/ua_xml.h +++ /dev/null @@ -1,134 +0,0 @@ -#ifndef __UA_XML_H -#define __UA_XML_H - -#include -#include -#include -#include // strlen -#include // isspace -#include // read - -#include "ua_types.h" - -struct XML_Stack; -typedef char const *const XML_Attr; -typedef char const *cstring; -#define XML_STACK_MAX_DEPTH 10 -#define XML_STACK_MAX_CHILDREN 40 -typedef UA_Int32 (*XML_decoder)(struct XML_Stack *s, XML_Attr *attr, void *dst, UA_Boolean isStart); - -/** @brief A readable shortcut for NodeIds. A list of aliases is intensively used in the namespace0-xml-files */ -typedef struct UA_NodeSetAlias { - UA_String alias; - UA_String value; -} UA_NodeSetAlias; -//UA_TYPE_PROTOTYPES(UA_NodeSetAlias) - -/** @brief UA_NodeSetAliases - a list of aliases */ -typedef struct UA_NodeSetAliases { - UA_Int32 size; - UA_NodeSetAlias **aliases; -} UA_NodeSetAliases; -//UA_TYPE_PROTOTYPES(UA_NodeSetAliases) - -typedef struct XML_child { - cstring name; - UA_Int32 length; - UA_Int32 type; - XML_decoder elementHandler; - void *obj; -} XML_child; - -typedef struct XML_Parent { - cstring name; - int textAttribIdx; // -1 - not set - cstring textAttrib; - int activeChild; // -1 - no active child - int len; // -1 - empty set - XML_child children[XML_STACK_MAX_CHILDREN]; -} XML_Parent; - -typedef struct XML_Stack { - int depth; - XML_Parent parent[XML_STACK_MAX_DEPTH]; - UA_NodeSetAliases *aliases; // shall point to the aliases of the NodeSet after reading -} XML_Stack; - -UA_Int32 UA_Boolean_copycstring(cstring src, UA_Boolean *dst); -UA_Int32 UA_Int16_copycstring(cstring src, UA_Int16 *dst); -UA_Int32 UA_UInt16_copycstring(cstring src, UA_UInt16 *dst); -UA_Boolean UA_NodeId_isBuiltinType(UA_NodeId *nodeid); - -/** @brief an object to hold a typed array */ -typedef struct UA_TypedArray { - UA_Int32 size; - UA_VTable_Entry *vt; - void *elements; -} UA_TypedArray; - -/** @brief init typed array with size=-1 and an UA_INVALIDTYPE */ -UA_Int32 UA_TypedArray_init(UA_TypedArray *p); - -/** @brief allocate memory for the array header only */ -UA_Int32 UA_TypedArray_new(UA_TypedArray **p); -UA_Int32 UA_TypedArray_setType(UA_TypedArray *p, UA_Int32 type); -//UA_Int32 UA_TypedArray_decodeXML(XML_Stack *s, XML_Attr *attr, UA_TypedArray *dst, UA_Boolean isStart); - -UA_Int32 UA_NodeSetAlias_init(UA_NodeSetAlias* p); -UA_Int32 UA_NodeSetAlias_new(UA_NodeSetAlias** p); - -UA_Int32 UA_NodeSetAliases_init(UA_NodeSetAliases* p); -UA_Int32 UA_NodeSetAliases_new(UA_NodeSetAliases** p); -UA_Int32 UA_NodeSetAliases_println(cstring label, UA_NodeSetAliases *p); - -UA_Int32 UA_ExpandedNodeId_copycstring(cstring src, UA_ExpandedNodeId* dst, UA_NodeSetAliases* aliases); - -void XML_Stack_init(XML_Stack* p, UA_UInt32 nsid, cstring name); -void XML_Stack_print(XML_Stack* s); - -/** @brief add a reference to a handler (@see XML_Stack_addChildHandler) for text data - * - * Assume a XML structure such as - * - * - * Server - * - * which might be abbreviated as - * Server - * - * We would add two (@ref XML_Stack_addChildHandler), one for Locale (index 0) and one for Text (index 1), - * both to be handled by (@ref UA_String_decodeXML) with elements "Data" and "Length". To handle the - * abbreviation we add - * XML_Stack_handleTextAsElementOf(s,"Data",1) - * - * @param[in] s the stack - * @param[in] textAttrib the name of the element of the handler at position textAttribIdx - * @param[in] textAttribIdx the index of the handler - */ -void XML_Stack_handleTextAsElementOf(XML_Stack *p, cstring textAttrib, unsigned int textAttribIdx); - -/** @brief make a handler known to the XML-stack on the current level - * - * The current level is given by s->depth, the maximum number of children is a predefined constant. - * A combination of type=UA_INVALIDTYPE and dst=UA_NULL is valid for special handlers only - * - * @param[in] s the stack - * @param[in] name the name of the element - * @param[in] nameLength the length of the element name - * @param[in] handler the decoder routine for this element - * @param[in] type the open62541-type of the element, UA_INVALIDTYPE if not in the VTable - * @param[out] dst the address of the object for the data, handlers will allocate object if UA_NULL - */ -void XML_Stack_addChildHandler(XML_Stack *p, cstring name, UA_Int32 nameLength, XML_decoder handler, UA_Int32 type, - void *dst); - -void XML_Stack_startElement(void *data, const char *el, const char **attr); -UA_Int32 XML_isSpace(cstring s, int len); -void XML_Stack_handleText(void *data, const char *txt, int len); -void XML_Stack_endElement(void *data, const char *el); - -UA_Int32 UA_Text_decodeXmlFromStack(XML_Stack *s, XML_Attr *attr, UA_Byte **dst, _Bool isStart); -UA_Int32 UA_NodeId_copycstring(cstring src, UA_NodeId *dst, UA_NodeSetAliases *aliases); -UA_Int32 UA_TypedArray_decodeXmlFromStack(XML_Stack *s, XML_Attr *attr, UA_TypedArray *dst, _Bool isStart); - -#endif // __UA_XML_H__ diff --git a/src/ongoing/xml2ns0.c b/src/ongoing/xml2ns0.c deleted file mode 100644 index 215d3e871e4..00000000000 --- a/src/ongoing/xml2ns0.c +++ /dev/null @@ -1,210 +0,0 @@ -#include // open, O_RDONLY -#include "ua_types.h" -//#include "ua_types_generated.h" -#include "ua_namespace.h" -#include "ua_xml.h" -#include "ua_namespace_xml.h" -#include "ua_types_encoding_xml.h" -#include "util/ua_util.h" - -// FIXME: most of the following code should be generated as a template from the ns0-defining xml-files -/** @brief sam (abbr. for server_application_memory) is a flattened memory structure of the UAVariables in ns0 */ -struct sam { - UA_ServerStatusDataType serverStatus; -} sam; - -char* productName = "xml2ns0"; -char* productUri = "http://open62541.org/xml2ns0/"; -char* manufacturerName = "open62541"; -char* softwareVersion = "0.01"; -char* buildNumber = "999-" __DATE__ "-001" ; - -#define SAM_ASSIGN_CSTRING(src,dst) do { \ - dst.length = strlen(src)-1; \ - dst.data = (UA_Byte*) src; \ -} while(0) - -void sam_attach(Namespace *ns,UA_UInt32 ns0id,UA_Int32 type, void* p) { - UA_NodeId nodeid; - nodeid.namespace = 0; // we cannot access ns->namespaceIndex; - nodeid.identifier.numeric = ns0id; - nodeid.encodingByte = UA_NODEIDTYPE_FOURBYTE; - const UA_Node* result; - UA_Int32 retval = Namespace_get(ns,&nodeid,&result); - if (retval == UA_SUCCESS) { - if (result->nodeId.identifier.numeric == ns0id) { - if (result->nodeClass == UA_NODECLASS_VARIABLE) { - UA_VariableNode* variable = (UA_VariableNode*) result; - if (variable->dataType.identifier.numeric == UA_.types[type].typeId.identifier.numeric) { - variable->value.arrayLength = 1; - variable->value.data = p; - } else { - UA_alloc((void**)&variable->value.data, sizeof(UA_ExtensionObject)); - UA_ExtensionObject* eo = (UA_ExtensionObject*) variable->value.data; - eo->typeId = variable->dataType; - eo->encoding = UA_EXTENSIONOBJECT_ENCODINGMASK_BODYISBYTESTRING; - // FIXME: This code is valid for ns0 and numeric identifiers only - eo->body.length = UA_.types[UA_ns0ToVTableIndex(&variable->dataType)].memSize; - eo->body.data = p; - } - } - } - Namespace_releaseManagedNode(result); - } -} - /* } else { */ - /* perror("Namespace_getWritable returned wrong node class"); */ - /* } */ - /* } else { */ - /* printf("retrieving node={i=%d} returned node={i=%d}\n", ns0id, result->nodeId.identifier.numeric); */ - /* } */ - /* Namespace_Entry_Lock_release(lock); */ - /* } else { */ - /* printf("retrieving node={i=%d} returned error code %d\n",ns0id,retval); */ - /* } */ - -void sam_init(Namespace* ns) { - // Initialize the strings - SAM_ASSIGN_CSTRING(productName,sam.serverStatus.buildInfo.productName); - SAM_ASSIGN_CSTRING(productUri,sam.serverStatus.buildInfo.productUri); - SAM_ASSIGN_CSTRING(manufacturerName,sam.serverStatus.buildInfo.manufacturerName); - SAM_ASSIGN_CSTRING(softwareVersion,sam.serverStatus.buildInfo.softwareVersion); - SAM_ASSIGN_CSTRING(buildNumber,sam.serverStatus.buildInfo.buildNumber); - - // Attach server application memory to ns0 - sam_attach(ns,2256,UA_SERVERSTATUSDATATYPE,&sam.serverStatus); // this is the head of server status! - sam.serverStatus.startTime = sam.serverStatus.currentTime = UA_DateTime_now(); - sam_attach(ns,2257,UA_DATETIME, &sam.serverStatus.startTime); - sam_attach(ns,2258,UA_DATETIME, &sam.serverStatus.currentTime); - sam_attach(ns,2259,UA_SERVERSTATE, &sam.serverStatus.state); - sam_attach(ns,2260,UA_BUILDINFO, &sam.serverStatus.buildInfo); // start of build Info - sam_attach(ns,2261,UA_STRING, &sam.serverStatus.buildInfo.productName); - sam_attach(ns,2262,UA_STRING, &sam.serverStatus.buildInfo.productUri); - sam_attach(ns,2263,UA_STRING, &sam.serverStatus.buildInfo.manufacturerName); - sam_attach(ns,2264,UA_STRING, &sam.serverStatus.buildInfo.softwareVersion); - sam_attach(ns,2265,UA_STRING, &sam.serverStatus.buildInfo.buildNumber); - sam_attach(ns,2266,UA_DATETIME, &sam.serverStatus.buildInfo.buildDate); - sam_attach(ns,2992,UA_UINT32, &sam.serverStatus.secondsTillShutdown); - sam_attach(ns,2993,UA_LOCALIZEDTEXT,&sam.serverStatus.shutdownReason); -} - -UA_Int32 Namespace_getNumberOfComponents(Namespace const * ns, UA_NodeId const * id, UA_Int32* number) { - UA_Int32 retval = UA_SUCCESS; - UA_Node const * node; - if ((retval = Namespace_get(ns,id,&node)) != UA_SUCCESS) - return retval; - if (node == UA_NULL) - return UA_ERR_INVALID_VALUE; - UA_Int32 i, n; - for (i = 0, n = 0; i < node->referencesSize; i++ ) { - if (node->references[i].referenceTypeId.identifier.numeric == 47 && node->references[i].isInverse != UA_TRUE) { - n++; - } - } - Namespace_releaseManagedNode(node); - *number = n; - return retval; -} - -UA_Int32 Namespace_getComponent(Namespace const * ns, UA_NodeId const * id, UA_Int32 idx, UA_NodeId** result) { - UA_Int32 retval = UA_SUCCESS; - - UA_Node const * node; - if ((retval = Namespace_get(ns,id,&node)) != UA_SUCCESS) - return retval; - - UA_Int32 i, n; - for (i = 0, n = 0; i < node->referencesSize; i++ ) { - if (node->references[i].referenceTypeId.identifier.numeric == 47 && node->references[i].isInverse != UA_TRUE) { - n++; - if (n == idx) { - *result = &(node->references[i].targetId.nodeId); - Namespace_releaseManagedNode(node); - return retval; - } - } - } - - Namespace_releaseManagedNode(node); - return UA_ERR_INVALID_VALUE; -} - - -UA_Int32 UAX_NodeId_encodeBinaryByMetaData(Namespace const * ns, UA_NodeId const * id, UA_ByteString *dst, UA_UInt32* offset) { - UA_Int32 i, retval = UA_SUCCESS; - if (UA_NodeId_isBasicType(id)) { - UA_Node const * result; - if ((retval = Namespace_get(ns,id,&result)) == UA_SUCCESS) { - UA_Variant_encodeBinary(&((UA_VariableNode *) result)->value,dst,offset); - Namespace_releaseManagedNode(result); - } - } else { - UA_Int32 nComp = 0; - if ((retval = Namespace_getNumberOfComponents(ns,id,&nComp)) == UA_SUCCESS) { - for (i=0; i < nComp; i++) { - UA_NodeId* comp = UA_NULL; - Namespace_getComponent(ns,id,i,&comp); - UAX_NodeId_encodeBinaryByMetaData(ns,comp, dst, offset); - } - } - } - return retval; -} - -UA_Int32 UAX_NodeId_encodeBinary(Namespace const * ns, UA_NodeId const * id, UA_ByteString *dst, UA_UInt32* offset) { - UA_Int32 retval = UA_SUCCESS; - UA_Node const * node; - if ((retval = Namespace_get(ns,id,&node)) == UA_SUCCESS) { - if (node->nodeClass == UA_NODECLASS_VARIABLE) { - retval = UA_Variant_encodeBinary(&((UA_VariableNode*) node)->value,dst,offset); - } - Namespace_releaseManagedNode(node); - } - return retval; -} - -int main() { - Namespace* ns; - UA_Int32 retval; - - retval = Namespace_loadFromFile(&ns, 0, "ROOT", UA_NULL); - - sam_init(ns); - // Namespace_iterate(ns, print_node); - - // encoding buffer - char buf[1024]; - UA_ByteString buffer = { 1024, (UA_Byte*) buf }; - UA_UInt32 pos = 0; - - UA_NodeId nodeid; - nodeid.encodingByte = UA_NODEIDTYPE_FOURBYTE; - nodeid.namespace = 0; - nodeid.identifier.numeric = 2256; // ServerStatus - - UA_Int32 i=0; - retval=UA_SUCCESS; - UA_DateTime tStart = UA_DateTime_now(); - // encoding takes roundabout 10 µs on my virtual machine with -O0, so 1E5 takes a second - for (i=0;i<1E5 && retval == UA_SUCCESS;i++) { - pos = 0; - sam.serverStatus.currentTime = UA_DateTime_now(); - retval |= UAX_NodeId_encodeBinary(ns,&nodeid,&buffer,&pos); - } - UA_DateTime tEnd = UA_DateTime_now(); - // tStart, tEnd count in 100 ns steps, so 10 steps = 1 µs - UA_Double tDelta = ( tEnd - tStart ) / ( 10.0 * i ); - - printf("encode server node %d times, retval=%d: time/enc=%f us, enc/s=%f\n",i, retval, tDelta, 1.0E6 / tDelta); - DBG(buffer.length=pos); - DBG(UA_ByteString_printx(", result=", &buffer)); - - // Design alternative two : use meta data - // pos = 0; - // buffer.length = 1024; - // UAX_NodeId_encodeBinary(n.ns,&nodeid,&pos,&buffer); - // buffer.length = pos; - // UA_ByteString_printx("namespace based encoder result=", &buffer); - - return 0; -}