ua_xml.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * ua_xml.h
  3. *
  4. * Created on: 03.05.2014
  5. * Author: mrt
  6. */
  7. #ifndef __UA_XML_H__
  8. #define __UA_XML_H__
  9. #include <expat.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h> // strlen
  13. #include <ctype.h> // isspace
  14. #include <unistd.h> // read
  15. #include "opcua.h"
  16. #include "ua_namespace.h"
  17. UA_Int32 UA_Boolean_copycstring(cstring src, UA_Boolean* dst);
  18. UA_Int32 UA_Int16_copycstring(cstring src, UA_Int16* dst);
  19. UA_Int32 UA_UInt16_copycstring(cstring src, UA_UInt16* dst) ;
  20. UA_Boolean UA_NodeId_isBuiltinType(UA_NodeId* nodeid);
  21. void print_node(UA_Node const * node);
  22. /** @brief an object to hold a typed array */
  23. typedef struct UA_TypedArray {
  24. UA_Int32 size;
  25. UA_VTable* vt;
  26. void** elements;
  27. } UA_TypedArray;
  28. /** @brief init typed array with size=-1 and an UA_INVALIDTYPE */
  29. UA_Int32 UA_TypedArray_init(UA_TypedArray* p);
  30. /** @brief allocate memory for the array header only */
  31. UA_Int32 UA_TypedArray_new(UA_TypedArray** p);
  32. UA_Int32 UA_TypedArray_setType(UA_TypedArray* p, UA_Int32 type);
  33. UA_Int32 UA_TypedArray_decodeXML(XML_Stack* s, XML_Attr* attr, UA_TypedArray* dst, _Bool isStart);
  34. UA_Int32 UA_NodeSetAlias_init(UA_NodeSetAlias* p);
  35. UA_Int32 UA_NodeSetAlias_new(UA_NodeSetAlias** p);
  36. UA_Int32 UA_NodeSetAlias_decodeXML(XML_Stack* s, XML_Attr* attr, UA_NodeSetAlias* dst, _Bool isStart);
  37. UA_Int32 UA_NodeSetAliases_init(UA_NodeSetAliases* p);
  38. UA_Int32 UA_NodeSetAliases_new(UA_NodeSetAliases** p);
  39. UA_Int32 UA_NodeSetAliases_println(cstring label, UA_NodeSetAliases *p);
  40. UA_Int32 UA_NodeSetAliases_decodeXML(XML_Stack* s, XML_Attr* attr, UA_NodeSetAliases* dst, _Bool isStart);
  41. typedef struct UA_NodeSet {
  42. Namespace* ns;
  43. UA_NodeSetAliases aliases;
  44. } UA_NodeSet;
  45. /** @brief init typed array with size=-1 and an UA_INVALIDTYPE */
  46. UA_Int32 UA_NodeSet_init(UA_NodeSet* p, UA_UInt32 nsid);
  47. UA_Int32 UA_NodeSet_new(UA_NodeSet** p, UA_UInt32 nsid);
  48. UA_Int32 UA_NodeId_copycstring(cstring src, UA_NodeId* dst, UA_NodeSetAliases* aliases);
  49. UA_Int32 UA_NodeSet_decodeXML(XML_Stack* s, XML_Attr* attr, UA_NodeSet* dst, _Bool isStart);
  50. UA_Int32 UA_ExpandedNodeId_copycstring(cstring src, UA_ExpandedNodeId* dst, UA_NodeSetAliases* aliases);
  51. void XML_Stack_init(XML_Stack* p, UA_UInt32 nsid, cstring name);
  52. void XML_Stack_print(XML_Stack* s);
  53. /** @brief add a reference to a handler (@see XML_Stack_addChildHandler) for text data
  54. *
  55. * Assume a XML structure such as
  56. * <LocalizedText>
  57. * <Locale></Locale>
  58. * <Text>Server</Text>
  59. * </LocalizedText>
  60. * which might be abbreviated as
  61. * <LocalizedText>Server</LocalizedText>
  62. *
  63. * We would add two (@ref XML_Stack_addChildHandler), one for Locale (index 0) and one for Text (index 1),
  64. * both to be handled by (@ref UA_String_decodeXML) with elements "Data" and "Length". To handle the
  65. * abbreviation we add
  66. * XML_Stack_handleTextAsElementOf(s,"Data",1)
  67. *
  68. * @param[in] s the stack
  69. * @param[in] textAttrib the name of the element of the handler at position textAttribIdx
  70. * @param[in] textAttribIdx the index of the handler
  71. */
  72. void XML_Stack_handleTextAsElementOf(XML_Stack* p, cstring textAttrib, unsigned int textAttribIdx);
  73. /** @brief make a handler known to the XML-stack on the current level
  74. *
  75. * The current level is given by s->depth, the maximum number of children is a predefined constant.
  76. * A combination of type=UA_INVALIDTYPE and dst=UA_NULL is valid for special handlers only
  77. *
  78. * @param[in] s the stack
  79. * @param[in] name the name of the element
  80. * @param[in] nameLength the length of the element name
  81. * @param[in] handler the decoder routine for this element
  82. * @param[in] type the open62541-type of the element, UA_INVALIDTYPE if not in the VTable
  83. * @param[out] dst the address of the object for the data, handlers will allocate object if UA_NULL
  84. */
  85. void XML_Stack_addChildHandler(XML_Stack* p, cstring name, UA_Int32 nameLength, XML_decoder handler, UA_Int32 type, void* dst);
  86. void XML_Stack_startElement(void * data, const char *el, const char **attr);
  87. UA_Int32 XML_isSpace(cstring s, int len);
  88. void XML_Stack_handleText(void * data, const char *txt, int len);
  89. void XML_Stack_endElement(void *data, const char *el);
  90. /** @brief load a namespace from an XML-File
  91. *
  92. * @param[in/out] ns the address of the namespace ptr
  93. * @param[in] namespaceId the numeric id of the namespace
  94. * @param[in] rootName the name of the root element of the hierarchy (not used?)
  95. * @param[in] fileName the name of an existing file, e.g. Opc.Ua.NodeSet2.xml
  96. */
  97. UA_Int32 Namespace_loadFromFile(Namespace **ns,UA_UInt32 namespaceId,const char* rootName,const char* fileName);
  98. #endif // __UA_XML_H__