Pārlūkot izejas kodu

Merge branch 'master' of https://github.com/acplt/open62541

ichrispa 9 gadi atpakaļ
vecāks
revīzija
3fb3ca804e

+ 0 - 7
CMakeLists.txt

@@ -295,13 +295,6 @@ if(ENABLE_MULTITHREADING)
   target_link_libraries(open62541-static urcu-cds urcu urcu-common pthread)
   target_link_libraries(open62541-static urcu-cds urcu urcu-common pthread)
 endif()
 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
 # coverage
 option(ENABLE_COVERAGE "Enable gcov coverage" OFF)
 option(ENABLE_COVERAGE "Enable gcov coverage" OFF)
 if(ENABLE_COVERAGE)
 if(ENABLE_COVERAGE)

+ 0 - 39
bindings/CMakeLists.txt

@@ -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 lua)
-    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 python)
-    set_target_properties(open62541-python PROPERTIES
-                                           LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/python
-                                           OUTPUT_NAME _open62541 PREFIX "")
-endif()

+ 0 - 64
bindings/open62541.i

@@ -1,64 +0,0 @@
-%module open62541
-%{
-#include "ua_types.h"
-#include "ua_server.h"
-%}
-
-#if defined(SWIGPYTHON)
-%{
-/* avoid no previous prototype warning/error */
-#if PY_VERSION_HEX >= 0x03000000
-PyObject*
-#else
-void
-#endif
-SWIG_init (void);
-%}
-#endif
-
-#if defined(SWIGLUA)
-%{
-/* avoid no previous prototype warning/error */
-SWIGEXPORT int SWIG_init (lua_State* L);
-%}
-#endif
-
-%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"

+ 822 - 0
deps/tweetnacl.c

@@ -0,0 +1,822 @@
+ /*
+  * http://tweetnacl.cr.yp.to/
+  * TweetNaCl was put in the public domain by the authors Bernstein et al.
+  * The API is th same as for NaCl (http://nacl.cr.yp.to/).
+  */
+
+#include "tweetnacl.h"
+#define FOR(i,n) for (i = 0;i < n;++i)
+#define sv static void
+
+/* Manual change from TweetNaCl version 20140427: Use C99 integer types
+typedef unsigned char u8;
+typedef unsigned long u32;
+typedef unsigned long long u64;
+typedef long long i64; */
+#include <inttypes.h>
+typedef uint8_t u8;
+typedef uint32_t u32;
+typedef uint64_t u64;
+typedef int64_t i64;
+/* end manual change */
+typedef i64 gf[16];
+extern void randombytes(u8 *,u64);
+
+static const u8
+  _0[16],
+  _9[32] = {9};
+static const gf
+  gf0,
+  gf1 = {1},
+  _121665 = {0xDB41,1},
+  D = {0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203},
+  D2 = {0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406},
+  X = {0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169},
+  Y = {0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666},
+  I = {0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83};
+
+static u32 L32(u32 x,int c) { return (x << c) | ((x&0xffffffff) >> (32 - c)); }
+
+static u32 ld32(const u8 *x)
+{
+  u32 u = x[3];
+  u = (u<<8)|x[2];
+  u = (u<<8)|x[1];
+  return (u<<8)|x[0];
+}
+
+static u64 dl64(const u8 *x)
+{
+  u64 i,u=0;
+  FOR(i,8) u=(u<<8)|x[i];
+  return u;
+}
+
+sv st32(u8 *x,u32 u)
+{
+  int i;
+  FOR(i,4) { x[i] = u; u >>= 8; }
+}
+
+sv ts64(u8 *x,u64 u)
+{
+  int i;
+  for (i = 7;i >= 0;--i) { x[i] = u; u >>= 8; }
+}
+
+static int vn(const u8 *x,const u8 *y,int n)
+{
+  u32 i,d = 0;
+  FOR(i,n) d |= x[i]^y[i];
+  return (1 & ((d - 1) >> 8)) - 1;
+}
+
+int crypto_verify_16(const u8 *x,const u8 *y)
+{
+  return vn(x,y,16);
+}
+
+int crypto_verify_32(const u8 *x,const u8 *y)
+{
+  return vn(x,y,32);
+}
+
+sv core(u8 *out,const u8 *in,const u8 *k,const u8 *c,int h)
+{
+  u32 w[16],x[16],y[16],t[4];
+  int i,j,m;
+
+  FOR(i,4) {
+    x[5*i] = ld32(c+4*i);
+    x[1+i] = ld32(k+4*i);
+    x[6+i] = ld32(in+4*i);
+    x[11+i] = ld32(k+16+4*i);
+  }
+
+  FOR(i,16) y[i] = x[i];
+
+  FOR(i,20) {
+    FOR(j,4) {
+      FOR(m,4) t[m] = x[(5*j+4*m)%16];
+      t[1] ^= L32(t[0]+t[3], 7);
+      t[2] ^= L32(t[1]+t[0], 9);
+      t[3] ^= L32(t[2]+t[1],13);
+      t[0] ^= L32(t[3]+t[2],18);
+      FOR(m,4) w[4*j+(j+m)%4] = t[m];
+    }
+    FOR(m,16) x[m] = w[m];
+  }
+
+  if (h) {
+    FOR(i,16) x[i] += y[i];
+    FOR(i,4) {
+      x[5*i] -= ld32(c+4*i);
+      x[6+i] -= ld32(in+4*i);
+    }
+    FOR(i,4) {
+      st32(out+4*i,x[5*i]);
+      st32(out+16+4*i,x[6+i]);
+    }
+  } else
+    FOR(i,16) st32(out + 4 * i,x[i] + y[i]);
+}
+
+int crypto_core_salsa20(u8 *out,const u8 *in,const u8 *k,const u8 *c)
+{
+  core(out,in,k,c,0);
+  return 0;
+}
+
+int crypto_core_hsalsa20(u8 *out,const u8 *in,const u8 *k,const u8 *c)
+{
+  core(out,in,k,c,1);
+  return 0;
+}
+
+static const u8 sigma[16] = "expand 32-byte k";
+
+int crypto_stream_salsa20_xor(u8 *c,const u8 *m,u64 b,const u8 *n,const u8 *k)
+{
+  u8 z[16],x[64];
+  u32 u,i;
+  if (!b) return 0;
+  FOR(i,16) z[i] = 0;
+  FOR(i,8) z[i] = n[i];
+  while (b >= 64) {
+    crypto_core_salsa20(x,z,k,sigma);
+    FOR(i,64) c[i] = (m?m[i]:0) ^ x[i];
+    u = 1;
+    for (i = 8;i < 16;++i) {
+      u += (u32) z[i];
+      z[i] = u;
+      u >>= 8;
+    }
+    b -= 64;
+    c += 64;
+    if (m) m += 64;
+  }
+  if (b) {
+    crypto_core_salsa20(x,z,k,sigma);
+    FOR(i,b) c[i] = (m?m[i]:0) ^ x[i];
+  }
+  return 0;
+}
+
+int crypto_stream_salsa20(u8 *c,u64 d,const u8 *n,const u8 *k)
+{
+  return crypto_stream_salsa20_xor(c,0,d,n,k);
+}
+
+int crypto_stream(u8 *c,u64 d,const u8 *n,const u8 *k)
+{
+  u8 s[32];
+  crypto_core_hsalsa20(s,n,k,sigma);
+  return crypto_stream_salsa20(c,d,n+16,s);
+}
+
+int crypto_stream_xor(u8 *c,const u8 *m,u64 d,const u8 *n,const u8 *k)
+{
+  u8 s[32];
+  crypto_core_hsalsa20(s,n,k,sigma);
+  return crypto_stream_salsa20_xor(c,m,d,n+16,s);
+}
+
+sv add1305(u32 *h,const u32 *c)
+{
+  u32 j,u = 0;
+  FOR(j,17) {
+    u += h[j] + c[j];
+    h[j] = u & 255;
+    u >>= 8;
+  }
+}
+
+static const u32 minusp[17] = {
+  5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 252
+} ;
+
+int crypto_onetimeauth(u8 *out,const u8 *m,u64 n,const u8 *k)
+{
+  u32 s,i,j,u,x[17],r[17],h[17],c[17],g[17];
+
+  FOR(j,17) r[j]=h[j]=0;
+  FOR(j,16) r[j]=k[j];
+  r[3]&=15;
+  r[4]&=252;
+  r[7]&=15;
+  r[8]&=252;
+  r[11]&=15;
+  r[12]&=252;
+  r[15]&=15;
+
+  while (n > 0) {
+    FOR(j,17) c[j] = 0;
+    for (j = 0;(j < 16) && (j < n);++j) c[j] = m[j];
+    c[j] = 1;
+    m += j; n -= j;
+    add1305(h,c);
+    FOR(i,17) {
+      x[i] = 0;
+      FOR(j,17) x[i] += h[j] * ((j <= i) ? r[i - j] : 320 * r[i + 17 - j]);
+    }
+    FOR(i,17) h[i] = x[i];
+    u = 0;
+    FOR(j,16) {
+      u += h[j];
+      h[j] = u & 255;
+      u >>= 8;
+    }
+    u += h[16]; h[16] = u & 3;
+    u = 5 * (u >> 2);
+    FOR(j,16) {
+      u += h[j];
+      h[j] = u & 255;
+      u >>= 8;
+    }
+    u += h[16]; h[16] = u;
+  }
+
+  FOR(j,17) g[j] = h[j];
+  add1305(h,minusp);
+  s = -(h[16] >> 7);
+  FOR(j,17) h[j] ^= s & (g[j] ^ h[j]);
+
+  FOR(j,16) c[j] = k[j + 16];
+  c[16] = 0;
+  add1305(h,c);
+  FOR(j,16) out[j] = h[j];
+  return 0;
+}
+
+int crypto_onetimeauth_verify(const u8 *h,const u8 *m,u64 n,const u8 *k)
+{
+  u8 x[16];
+  crypto_onetimeauth(x,m,n,k);
+  return crypto_verify_16(h,x);
+}
+
+int crypto_secretbox(u8 *c,const u8 *m,u64 d,const u8 *n,const u8 *k)
+{
+  int i;
+  if (d < 32) return -1;
+  crypto_stream_xor(c,m,d,n,k);
+  crypto_onetimeauth(c + 16,c + 32,d - 32,c);
+  FOR(i,16) c[i] = 0;
+  return 0;
+}
+
+int crypto_secretbox_open(u8 *m,const u8 *c,u64 d,const u8 *n,const u8 *k)
+{
+  int i;
+  u8 x[32];
+  if (d < 32) return -1;
+  crypto_stream(x,32,n,k);
+  if (crypto_onetimeauth_verify(c + 16,c + 32,d - 32,x) != 0) return -1;
+  crypto_stream_xor(m,c,d,n,k);
+  FOR(i,32) m[i] = 0;
+  return 0;
+}
+
+sv set25519(gf r, const gf a)
+{
+  int i;
+  FOR(i,16) r[i]=a[i];
+}
+
+sv car25519(gf o)
+{
+  int i;
+  i64 c;
+  FOR(i,16) {
+    o[i]+=(1LL<<16);
+    c=o[i]>>16;
+    o[(i+1)*(i<15)]+=c-1+37*(c-1)*(i==15);
+    o[i]-=c<<16;
+  }
+}
+
+sv sel25519(gf p,gf q,int b)
+{
+  i64 t,i,c=~(b-1);
+  FOR(i,16) {
+    t= c&(p[i]^q[i]);
+    p[i]^=t;
+    q[i]^=t;
+  }
+}
+
+sv pack25519(u8 *o,const gf n)
+{
+  int i,j,b;
+  gf m,t;
+  FOR(i,16) t[i]=n[i];
+  car25519(t);
+  car25519(t);
+  car25519(t);
+  FOR(j,2) {
+    m[0]=t[0]-0xffed;
+    for(i=1;i<15;i++) {
+      m[i]=t[i]-0xffff-((m[i-1]>>16)&1);
+      m[i-1]&=0xffff;
+    }
+    m[15]=t[15]-0x7fff-((m[14]>>16)&1);
+    b=(m[15]>>16)&1;
+    m[14]&=0xffff;
+    sel25519(t,m,1-b);
+  }
+  FOR(i,16) {
+    o[2*i]=t[i]&0xff;
+    o[2*i+1]=t[i]>>8;
+  }
+}
+
+static int neq25519(const gf a, const gf b)
+{
+  u8 c[32],d[32];
+  pack25519(c,a);
+  pack25519(d,b);
+  return crypto_verify_32(c,d);
+}
+
+static u8 par25519(const gf a)
+{
+  u8 d[32];
+  pack25519(d,a);
+  return d[0]&1;
+}
+
+sv unpack25519(gf o, const u8 *n)
+{
+  int i;
+  FOR(i,16) o[i]=n[2*i]+((i64)n[2*i+1]<<8);
+  o[15]&=0x7fff;
+}
+
+sv A(gf o,const gf a,const gf b)
+{
+  int i;
+  FOR(i,16) o[i]=a[i]+b[i];
+}
+
+sv Z(gf o,const gf a,const gf b)
+{
+  int i;
+  FOR(i,16) o[i]=a[i]-b[i];
+}
+
+sv M(gf o,const gf a,const gf b)
+{
+  i64 i,j,t[31];
+  FOR(i,31) t[i]=0;
+  FOR(i,16) FOR(j,16) t[i+j]+=a[i]*b[j];
+  FOR(i,15) t[i]+=38*t[i+16];
+  FOR(i,16) o[i]=t[i];
+  car25519(o);
+  car25519(o);
+}
+
+sv S(gf o,const gf a)
+{
+  M(o,a,a);
+}
+
+sv inv25519(gf o,const gf i)
+{
+  gf c;
+  int a;
+  FOR(a,16) c[a]=i[a];
+  for(a=253;a>=0;a--) {
+    S(c,c);
+    if(a!=2&&a!=4) M(c,c,i);
+  }
+  FOR(a,16) o[a]=c[a];
+}
+
+sv pow2523(gf o,const gf i)
+{
+  gf c;
+  int a;
+  FOR(a,16) c[a]=i[a];
+  for(a=250;a>=0;a--) {
+    S(c,c);
+    if(a!=1) M(c,c,i);
+  }
+  FOR(a,16) o[a]=c[a];
+}
+
+int crypto_scalarmult(u8 *q,const u8 *n,const u8 *p)
+{
+  u8 z[32];
+  i64 x[80],r,i;
+  gf a,b,c,d,e,f;
+  FOR(i,31) z[i]=n[i];
+  z[31]=(n[31]&127)|64;
+  z[0]&=248;
+  unpack25519(x,p);
+  FOR(i,16) {
+    b[i]=x[i];
+    d[i]=a[i]=c[i]=0;
+  }
+  a[0]=d[0]=1;
+  for(i=254;i>=0;--i) {
+    r=(z[i>>3]>>(i&7))&1;
+    sel25519(a,b,r);
+    sel25519(c,d,r);
+    A(e,a,c);
+    Z(a,a,c);
+    A(c,b,d);
+    Z(b,b,d);
+    S(d,e);
+    S(f,a);
+    M(a,c,a);
+    M(c,b,e);
+    A(e,a,c);
+    Z(a,a,c);
+    S(b,a);
+    Z(c,d,f);
+    M(a,c,_121665);
+    A(a,a,d);
+    M(c,c,a);
+    M(a,d,f);
+    M(d,b,x);
+    S(b,e);
+    sel25519(a,b,r);
+    sel25519(c,d,r);
+  }
+  FOR(i,16) {
+    x[i+16]=a[i];
+    x[i+32]=c[i];
+    x[i+48]=b[i];
+    x[i+64]=d[i];
+  }
+  inv25519(x+32,x+32);
+  M(x+16,x+16,x+32);
+  pack25519(q,x+16);
+  return 0;
+}
+
+int crypto_scalarmult_base(u8 *q,const u8 *n)
+{ 
+  return crypto_scalarmult(q,n,_9);
+}
+
+int crypto_box_keypair(u8 *y,u8 *x)
+{
+  randombytes(x,32);
+  return crypto_scalarmult_base(y,x);
+}
+
+int crypto_box_beforenm(u8 *k,const u8 *y,const u8 *x)
+{
+  u8 s[32];
+  crypto_scalarmult(s,x,y);
+  return crypto_core_hsalsa20(k,_0,s,sigma);
+}
+
+int crypto_box_afternm(u8 *c,const u8 *m,u64 d,const u8 *n,const u8 *k)
+{
+  return crypto_secretbox(c,m,d,n,k);
+}
+
+int crypto_box_open_afternm(u8 *m,const u8 *c,u64 d,const u8 *n,const u8 *k)
+{
+  return crypto_secretbox_open(m,c,d,n,k);
+}
+
+int crypto_box(u8 *c,const u8 *m,u64 d,const u8 *n,const u8 *y,const u8 *x)
+{
+  u8 k[32];
+  crypto_box_beforenm(k,y,x);
+  return crypto_box_afternm(c,m,d,n,k);
+}
+
+int crypto_box_open(u8 *m,const u8 *c,u64 d,const u8 *n,const u8 *y,const u8 *x)
+{
+  u8 k[32];
+  crypto_box_beforenm(k,y,x);
+  return crypto_box_open_afternm(m,c,d,n,k);
+}
+
+static u64 R(u64 x,int c) { return (x >> c) | (x << (64 - c)); }
+static u64 Ch(u64 x,u64 y,u64 z) { return (x & y) ^ (~x & z); }
+static u64 Maj(u64 x,u64 y,u64 z) { return (x & y) ^ (x & z) ^ (y & z); }
+static u64 Sigma0(u64 x) { return R(x,28) ^ R(x,34) ^ R(x,39); }
+static u64 Sigma1(u64 x) { return R(x,14) ^ R(x,18) ^ R(x,41); }
+static u64 sigma0(u64 x) { return R(x, 1) ^ R(x, 8) ^ (x >> 7); }
+static u64 sigma1(u64 x) { return R(x,19) ^ R(x,61) ^ (x >> 6); }
+
+static const u64 K[80] = 
+{
+  0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL, 0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL,
+  0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL, 0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL,
+  0xd807aa98a3030242ULL, 0x12835b0145706fbeULL, 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL,
+  0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL, 0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL,
+  0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL, 0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL,
+  0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL, 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL,
+  0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL, 0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL,
+  0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL, 0x06ca6351e003826fULL, 0x142929670a0e6e70ULL,
+  0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL, 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL,
+  0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL, 0x81c2c92e47edaee6ULL, 0x92722c851482353bULL,
+  0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL, 0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL,
+  0xd192e819d6ef5218ULL, 0xd69906245565a910ULL, 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL,
+  0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL, 0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL,
+  0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL, 0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL,
+  0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL, 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL,
+  0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL, 0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL,
+  0xca273eceea26619cULL, 0xd186b8c721c0c207ULL, 0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL,
+  0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL, 0x113f9804bef90daeULL, 0x1b710b35131c471bULL,
+  0x28db77f523047d84ULL, 0x32caab7b40c72493ULL, 0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL,
+  0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL, 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL
+};
+
+int crypto_hashblocks(u8 *x,const u8 *m,u64 n)
+{
+  u64 z[8],b[8],a[8],w[16],t;
+  int i,j;
+
+  FOR(i,8) z[i] = a[i] = dl64(x + 8 * i);
+
+  while (n >= 128) {
+    FOR(i,16) w[i] = dl64(m + 8 * i);
+
+    FOR(i,80) {
+      FOR(j,8) b[j] = a[j];
+      t = a[7] + Sigma1(a[4]) + Ch(a[4],a[5],a[6]) + K[i] + w[i%16];
+      b[7] = t + Sigma0(a[0]) + Maj(a[0],a[1],a[2]);
+      b[3] += t;
+      FOR(j,8) a[(j+1)%8] = b[j];
+      if (i%16 == 15)
+	FOR(j,16)
+	  w[j] += w[(j+9)%16] + sigma0(w[(j+1)%16]) + sigma1(w[(j+14)%16]);
+    }
+
+    FOR(i,8) { a[i] += z[i]; z[i] = a[i]; }
+
+    m += 128;
+    n -= 128;
+  }
+
+  FOR(i,8) ts64(x+8*i,z[i]);
+
+  return n;
+}
+
+static const u8 iv[64] = {
+  0x6a,0x09,0xe6,0x67,0xf3,0xbc,0xc9,0x08,
+  0xbb,0x67,0xae,0x85,0x84,0xca,0xa7,0x3b,
+  0x3c,0x6e,0xf3,0x72,0xfe,0x94,0xf8,0x2b,
+  0xa5,0x4f,0xf5,0x3a,0x5f,0x1d,0x36,0xf1,
+  0x51,0x0e,0x52,0x7f,0xad,0xe6,0x82,0xd1,
+  0x9b,0x05,0x68,0x8c,0x2b,0x3e,0x6c,0x1f,
+  0x1f,0x83,0xd9,0xab,0xfb,0x41,0xbd,0x6b,
+  0x5b,0xe0,0xcd,0x19,0x13,0x7e,0x21,0x79
+} ;
+
+int crypto_hash(u8 *out,const u8 *m,u64 n)
+{
+  u8 h[64],x[256];
+  u64 i,b = n;
+
+  FOR(i,64) h[i] = iv[i];
+
+  crypto_hashblocks(h,m,n);
+  m += n;
+  n &= 127;
+  m -= n;
+
+  FOR(i,256) x[i] = 0;
+  FOR(i,n) x[i] = m[i];
+  x[n] = 128;
+
+  n = 256-128*(n<112);
+  x[n-9] = b >> 61;
+  ts64(x+n-8,b<<3);
+  crypto_hashblocks(h,x,n);
+
+  FOR(i,64) out[i] = h[i];
+
+  return 0;
+}
+
+sv add(gf p[4],gf q[4])
+{
+  gf a,b,c,d,t,e,f,g,h;
+  
+  Z(a, p[1], p[0]);
+  Z(t, q[1], q[0]);
+  M(a, a, t);
+  A(b, p[0], p[1]);
+  A(t, q[0], q[1]);
+  M(b, b, t);
+  M(c, p[3], q[3]);
+  M(c, c, D2);
+  M(d, p[2], q[2]);
+  A(d, d, d);
+  Z(e, b, a);
+  Z(f, d, c);
+  A(g, d, c);
+  A(h, b, a);
+
+  M(p[0], e, f);
+  M(p[1], h, g);
+  M(p[2], g, f);
+  M(p[3], e, h);
+}
+
+sv cswap(gf p[4],gf q[4],u8 b)
+{
+  int i;
+  FOR(i,4)
+    sel25519(p[i],q[i],b);
+}
+
+sv pack(u8 *r,gf p[4])
+{
+  gf tx, ty, zi;
+  inv25519(zi, p[2]); 
+  M(tx, p[0], zi);
+  M(ty, p[1], zi);
+  pack25519(r, ty);
+  r[31] ^= par25519(tx) << 7;
+}
+
+sv scalarmult(gf p[4],gf q[4],const u8 *s)
+{
+  int i;
+  set25519(p[0],gf0);
+  set25519(p[1],gf1);
+  set25519(p[2],gf1);
+  set25519(p[3],gf0);
+  for (i = 255;i >= 0;--i) {
+    u8 b = (s[i/8]>>(i&7))&1;
+    cswap(p,q,b);
+    add(q,p);
+    add(p,p);
+    cswap(p,q,b);
+  }
+}
+
+sv scalarbase(gf p[4],const u8 *s)
+{
+  gf q[4];
+  set25519(q[0],X);
+  set25519(q[1],Y);
+  set25519(q[2],gf1);
+  M(q[3],X,Y);
+  scalarmult(p,q,s);
+}
+
+int crypto_sign_keypair(u8 *pk, u8 *sk)
+{
+  u8 d[64];
+  gf p[4];
+  int i;
+
+  randombytes(sk, 32);
+  crypto_hash(d, sk, 32);
+  d[0] &= 248;
+  d[31] &= 127;
+  d[31] |= 64;
+
+  scalarbase(p,d);
+  pack(pk,p);
+
+  FOR(i,32) sk[32 + i] = pk[i];
+  return 0;
+}
+
+static const u64 L[32] = {0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10};
+
+sv modL(u8 *r,i64 x[64])
+{
+  i64 carry,i,j;
+  for (i = 63;i >= 32;--i) {
+    carry = 0;
+    for (j = i - 32;j < i - 12;++j) {
+      x[j] += carry - 16 * x[i] * L[j - (i - 32)];
+      carry = (x[j] + 128) >> 8;
+      x[j] -= carry << 8;
+    }
+    x[j] += carry;
+    x[i] = 0;
+  }
+  carry = 0;
+  FOR(j,32) {
+    x[j] += carry - (x[31] >> 4) * L[j];
+    carry = x[j] >> 8;
+    x[j] &= 255;
+  }
+  FOR(j,32) x[j] -= carry * L[j];
+  FOR(i,32) {
+    x[i+1] += x[i] >> 8;
+    r[i] = x[i] & 255;
+  }
+}
+
+sv reduce(u8 *r)
+{
+  i64 x[64],i;
+  FOR(i,64) x[i] = (u64) r[i];
+  FOR(i,64) r[i] = 0;
+  modL(r,x);
+}
+
+int crypto_sign(u8 *sm,u64 *smlen,const u8 *m,u64 n,const u8 *sk)
+{
+  u8 d[64],h[64],r[64];
+  i64 i,j,x[64];
+  gf p[4];
+
+  crypto_hash(d, sk, 32);
+  d[0] &= 248;
+  d[31] &= 127;
+  d[31] |= 64;
+
+  *smlen = n+64;
+  FOR(i,n) sm[64 + i] = m[i];
+  FOR(i,32) sm[32 + i] = d[32 + i];
+
+  crypto_hash(r, sm+32, n+32);
+  reduce(r);
+  scalarbase(p,r);
+  pack(sm,p);
+
+  FOR(i,32) sm[i+32] = sk[i+32];
+  crypto_hash(h,sm,n + 64);
+  reduce(h);
+
+  FOR(i,64) x[i] = 0;
+  FOR(i,32) x[i] = (u64) r[i];
+  FOR(i,32) FOR(j,32) x[i+j] += h[i] * (u64) d[j];
+  modL(sm + 32,x);
+
+  return 0;
+}
+
+static int unpackneg(gf r[4],const u8 p[32])
+{
+  gf t, chk, num, den, den2, den4, den6;
+  set25519(r[2],gf1);
+  unpack25519(r[1],p);
+  S(num,r[1]);
+  M(den,num,D);
+  Z(num,num,r[2]);
+  A(den,r[2],den);
+
+  S(den2,den);
+  S(den4,den2);
+  M(den6,den4,den2);
+  M(t,den6,num);
+  M(t,t,den);
+
+  pow2523(t,t);
+  M(t,t,num);
+  M(t,t,den);
+  M(t,t,den);
+  M(r[0],t,den);
+
+  S(chk,r[0]);
+  M(chk,chk,den);
+  if (neq25519(chk, num)) M(r[0],r[0],I);
+
+  S(chk,r[0]);
+  M(chk,chk,den);
+  if (neq25519(chk, num)) return -1;
+
+  if (par25519(r[0]) == (p[31]>>7)) Z(r[0],gf0,r[0]);
+
+  M(r[3],r[0],r[1]);
+  return 0;
+}
+
+int crypto_sign_open(u8 *m,u64 *mlen,const u8 *sm,u64 n,const u8 *pk)
+{
+  int i;
+  u8 t[32],h[64];
+  gf p[4],q[4];
+
+  *mlen = -1;
+  if (n < 64) return -1;
+
+  if (unpackneg(q,pk)) return -1;
+
+  FOR(i,n) m[i] = sm[i];
+  FOR(i,32) m[i+32] = pk[i];
+  crypto_hash(h,m,n);
+  reduce(h);
+  scalarmult(p,q,h);
+
+  scalarbase(q,sm + 32);
+  add(p,q);
+  pack(t,p);
+
+  n -= 64;
+  if (crypto_verify_32(sm, t)) {
+    FOR(i,n) m[i] = 0;
+    return -1;
+  }
+
+  FOR(i,n) m[i] = sm[i + 64];
+  *mlen = n;
+  return 0;
+}

+ 278 - 0
deps/tweetnacl.h

@@ -0,0 +1,278 @@
+ /*
+  * http://tweetnacl.cr.yp.to/
+  * TweetNaCl was put in the public domain by the authors Bernstein et al.
+  * The API is th same as for NaCl (http://nacl.cr.yp.to/).
+  */
+
+#ifndef TWEETNACL_H
+#define TWEETNACL_H
+#define crypto_auth_PRIMITIVE "hmacsha512256"
+#define crypto_auth crypto_auth_hmacsha512256
+#define crypto_auth_verify crypto_auth_hmacsha512256_verify
+#define crypto_auth_BYTES crypto_auth_hmacsha512256_BYTES
+#define crypto_auth_KEYBYTES crypto_auth_hmacsha512256_KEYBYTES
+#define crypto_auth_IMPLEMENTATION crypto_auth_hmacsha512256_IMPLEMENTATION
+#define crypto_auth_VERSION crypto_auth_hmacsha512256_VERSION
+#define crypto_auth_hmacsha512256_tweet_BYTES 32
+#define crypto_auth_hmacsha512256_tweet_KEYBYTES 32
+extern int crypto_auth_hmacsha512256_tweet(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
+extern int crypto_auth_hmacsha512256_tweet_verify(const unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
+#define crypto_auth_hmacsha512256_tweet_VERSION "-"
+#define crypto_auth_hmacsha512256 crypto_auth_hmacsha512256_tweet
+#define crypto_auth_hmacsha512256_verify crypto_auth_hmacsha512256_tweet_verify
+#define crypto_auth_hmacsha512256_BYTES crypto_auth_hmacsha512256_tweet_BYTES
+#define crypto_auth_hmacsha512256_KEYBYTES crypto_auth_hmacsha512256_tweet_KEYBYTES
+#define crypto_auth_hmacsha512256_VERSION crypto_auth_hmacsha512256_tweet_VERSION
+#define crypto_auth_hmacsha512256_IMPLEMENTATION "crypto_auth/hmacsha512256/tweet"
+#define crypto_box_PRIMITIVE "curve25519xsalsa20poly1305"
+#define crypto_box crypto_box_curve25519xsalsa20poly1305
+#define crypto_box_open crypto_box_curve25519xsalsa20poly1305_open
+#define crypto_box_keypair crypto_box_curve25519xsalsa20poly1305_keypair
+#define crypto_box_beforenm crypto_box_curve25519xsalsa20poly1305_beforenm
+#define crypto_box_afternm crypto_box_curve25519xsalsa20poly1305_afternm
+#define crypto_box_open_afternm crypto_box_curve25519xsalsa20poly1305_open_afternm
+#define crypto_box_PUBLICKEYBYTES crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES
+#define crypto_box_SECRETKEYBYTES crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES
+#define crypto_box_BEFORENMBYTES crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES
+#define crypto_box_NONCEBYTES crypto_box_curve25519xsalsa20poly1305_NONCEBYTES
+#define crypto_box_ZEROBYTES crypto_box_curve25519xsalsa20poly1305_ZEROBYTES
+#define crypto_box_BOXZEROBYTES crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES
+#define crypto_box_IMPLEMENTATION crypto_box_curve25519xsalsa20poly1305_IMPLEMENTATION
+#define crypto_box_VERSION crypto_box_curve25519xsalsa20poly1305_VERSION
+#define crypto_box_curve25519xsalsa20poly1305_tweet_PUBLICKEYBYTES 32
+#define crypto_box_curve25519xsalsa20poly1305_tweet_SECRETKEYBYTES 32
+#define crypto_box_curve25519xsalsa20poly1305_tweet_BEFORENMBYTES 32
+#define crypto_box_curve25519xsalsa20poly1305_tweet_NONCEBYTES 24
+#define crypto_box_curve25519xsalsa20poly1305_tweet_ZEROBYTES 32
+#define crypto_box_curve25519xsalsa20poly1305_tweet_BOXZEROBYTES 16
+extern int crypto_box_curve25519xsalsa20poly1305_tweet(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *,const unsigned char *);
+extern int crypto_box_curve25519xsalsa20poly1305_tweet_open(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *,const unsigned char *);
+extern int crypto_box_curve25519xsalsa20poly1305_tweet_keypair(unsigned char *,unsigned char *);
+extern int crypto_box_curve25519xsalsa20poly1305_tweet_beforenm(unsigned char *,const unsigned char *,const unsigned char *);
+extern int crypto_box_curve25519xsalsa20poly1305_tweet_afternm(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
+extern int crypto_box_curve25519xsalsa20poly1305_tweet_open_afternm(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
+#define crypto_box_curve25519xsalsa20poly1305_tweet_VERSION "-"
+#define crypto_box_curve25519xsalsa20poly1305 crypto_box_curve25519xsalsa20poly1305_tweet
+#define crypto_box_curve25519xsalsa20poly1305_open crypto_box_curve25519xsalsa20poly1305_tweet_open
+#define crypto_box_curve25519xsalsa20poly1305_keypair crypto_box_curve25519xsalsa20poly1305_tweet_keypair
+#define crypto_box_curve25519xsalsa20poly1305_beforenm crypto_box_curve25519xsalsa20poly1305_tweet_beforenm
+#define crypto_box_curve25519xsalsa20poly1305_afternm crypto_box_curve25519xsalsa20poly1305_tweet_afternm
+#define crypto_box_curve25519xsalsa20poly1305_open_afternm crypto_box_curve25519xsalsa20poly1305_tweet_open_afternm
+#define crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES crypto_box_curve25519xsalsa20poly1305_tweet_PUBLICKEYBYTES
+#define crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES crypto_box_curve25519xsalsa20poly1305_tweet_SECRETKEYBYTES
+#define crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES crypto_box_curve25519xsalsa20poly1305_tweet_BEFORENMBYTES
+#define crypto_box_curve25519xsalsa20poly1305_NONCEBYTES crypto_box_curve25519xsalsa20poly1305_tweet_NONCEBYTES
+#define crypto_box_curve25519xsalsa20poly1305_ZEROBYTES crypto_box_curve25519xsalsa20poly1305_tweet_ZEROBYTES
+#define crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES crypto_box_curve25519xsalsa20poly1305_tweet_BOXZEROBYTES
+#define crypto_box_curve25519xsalsa20poly1305_VERSION crypto_box_curve25519xsalsa20poly1305_tweet_VERSION
+#define crypto_box_curve25519xsalsa20poly1305_IMPLEMENTATION "crypto_box/curve25519xsalsa20poly1305/tweet"
+#define crypto_core_PRIMITIVE "salsa20"
+#define crypto_core crypto_core_salsa20
+#define crypto_core_OUTPUTBYTES crypto_core_salsa20_OUTPUTBYTES
+#define crypto_core_INPUTBYTES crypto_core_salsa20_INPUTBYTES
+#define crypto_core_KEYBYTES crypto_core_salsa20_KEYBYTES
+#define crypto_core_CONSTBYTES crypto_core_salsa20_CONSTBYTES
+#define crypto_core_IMPLEMENTATION crypto_core_salsa20_IMPLEMENTATION
+#define crypto_core_VERSION crypto_core_salsa20_VERSION
+#define crypto_core_salsa20_tweet_OUTPUTBYTES 64
+#define crypto_core_salsa20_tweet_INPUTBYTES 16
+#define crypto_core_salsa20_tweet_KEYBYTES 32
+#define crypto_core_salsa20_tweet_CONSTBYTES 16
+extern int crypto_core_salsa20_tweet(unsigned char *,const unsigned char *,const unsigned char *,const unsigned char *);
+#define crypto_core_salsa20_tweet_VERSION "-"
+#define crypto_core_salsa20 crypto_core_salsa20_tweet
+#define crypto_core_salsa20_OUTPUTBYTES crypto_core_salsa20_tweet_OUTPUTBYTES
+#define crypto_core_salsa20_INPUTBYTES crypto_core_salsa20_tweet_INPUTBYTES
+#define crypto_core_salsa20_KEYBYTES crypto_core_salsa20_tweet_KEYBYTES
+#define crypto_core_salsa20_CONSTBYTES crypto_core_salsa20_tweet_CONSTBYTES
+#define crypto_core_salsa20_VERSION crypto_core_salsa20_tweet_VERSION
+#define crypto_core_salsa20_IMPLEMENTATION "crypto_core/salsa20/tweet"
+#define crypto_core_hsalsa20_tweet_OUTPUTBYTES 32
+#define crypto_core_hsalsa20_tweet_INPUTBYTES 16
+#define crypto_core_hsalsa20_tweet_KEYBYTES 32
+#define crypto_core_hsalsa20_tweet_CONSTBYTES 16
+extern int crypto_core_hsalsa20_tweet(unsigned char *,const unsigned char *,const unsigned char *,const unsigned char *);
+#define crypto_core_hsalsa20_tweet_VERSION "-"
+#define crypto_core_hsalsa20 crypto_core_hsalsa20_tweet
+#define crypto_core_hsalsa20_OUTPUTBYTES crypto_core_hsalsa20_tweet_OUTPUTBYTES
+#define crypto_core_hsalsa20_INPUTBYTES crypto_core_hsalsa20_tweet_INPUTBYTES
+#define crypto_core_hsalsa20_KEYBYTES crypto_core_hsalsa20_tweet_KEYBYTES
+#define crypto_core_hsalsa20_CONSTBYTES crypto_core_hsalsa20_tweet_CONSTBYTES
+#define crypto_core_hsalsa20_VERSION crypto_core_hsalsa20_tweet_VERSION
+#define crypto_core_hsalsa20_IMPLEMENTATION "crypto_core/hsalsa20/tweet"
+#define crypto_hashblocks_PRIMITIVE "sha512"
+#define crypto_hashblocks crypto_hashblocks_sha512
+#define crypto_hashblocks_STATEBYTES crypto_hashblocks_sha512_STATEBYTES
+#define crypto_hashblocks_BLOCKBYTES crypto_hashblocks_sha512_BLOCKBYTES
+#define crypto_hashblocks_IMPLEMENTATION crypto_hashblocks_sha512_IMPLEMENTATION
+#define crypto_hashblocks_VERSION crypto_hashblocks_sha512_VERSION
+#define crypto_hashblocks_sha512_tweet_STATEBYTES 64
+#define crypto_hashblocks_sha512_tweet_BLOCKBYTES 128
+extern int crypto_hashblocks_sha512_tweet(unsigned char *,const unsigned char *,unsigned long long);
+#define crypto_hashblocks_sha512_tweet_VERSION "-"
+#define crypto_hashblocks_sha512 crypto_hashblocks_sha512_tweet
+#define crypto_hashblocks_sha512_STATEBYTES crypto_hashblocks_sha512_tweet_STATEBYTES
+#define crypto_hashblocks_sha512_BLOCKBYTES crypto_hashblocks_sha512_tweet_BLOCKBYTES
+#define crypto_hashblocks_sha512_VERSION crypto_hashblocks_sha512_tweet_VERSION
+#define crypto_hashblocks_sha512_IMPLEMENTATION "crypto_hashblocks/sha512/tweet"
+#define crypto_hashblocks_sha256_tweet_STATEBYTES 32
+#define crypto_hashblocks_sha256_tweet_BLOCKBYTES 64
+extern int crypto_hashblocks_sha256_tweet(unsigned char *,const unsigned char *,unsigned long long);
+#define crypto_hashblocks_sha256_tweet_VERSION "-"
+#define crypto_hashblocks_sha256 crypto_hashblocks_sha256_tweet
+#define crypto_hashblocks_sha256_STATEBYTES crypto_hashblocks_sha256_tweet_STATEBYTES
+#define crypto_hashblocks_sha256_BLOCKBYTES crypto_hashblocks_sha256_tweet_BLOCKBYTES
+#define crypto_hashblocks_sha256_VERSION crypto_hashblocks_sha256_tweet_VERSION
+#define crypto_hashblocks_sha256_IMPLEMENTATION "crypto_hashblocks/sha256/tweet"
+#define crypto_hash_PRIMITIVE "sha512"
+#define crypto_hash crypto_hash_sha512
+#define crypto_hash_BYTES crypto_hash_sha512_BYTES
+#define crypto_hash_IMPLEMENTATION crypto_hash_sha512_IMPLEMENTATION
+#define crypto_hash_VERSION crypto_hash_sha512_VERSION
+#define crypto_hash_sha512_tweet_BYTES 64
+extern int crypto_hash_sha512_tweet(unsigned char *,const unsigned char *,unsigned long long);
+#define crypto_hash_sha512_tweet_VERSION "-"
+#define crypto_hash_sha512 crypto_hash_sha512_tweet
+#define crypto_hash_sha512_BYTES crypto_hash_sha512_tweet_BYTES
+#define crypto_hash_sha512_VERSION crypto_hash_sha512_tweet_VERSION
+#define crypto_hash_sha512_IMPLEMENTATION "crypto_hash/sha512/tweet"
+#define crypto_hash_sha256_tweet_BYTES 32
+extern int crypto_hash_sha256_tweet(unsigned char *,const unsigned char *,unsigned long long);
+#define crypto_hash_sha256_tweet_VERSION "-"
+#define crypto_hash_sha256 crypto_hash_sha256_tweet
+#define crypto_hash_sha256_BYTES crypto_hash_sha256_tweet_BYTES
+#define crypto_hash_sha256_VERSION crypto_hash_sha256_tweet_VERSION
+#define crypto_hash_sha256_IMPLEMENTATION "crypto_hash/sha256/tweet"
+#define crypto_onetimeauth_PRIMITIVE "poly1305"
+#define crypto_onetimeauth crypto_onetimeauth_poly1305
+#define crypto_onetimeauth_verify crypto_onetimeauth_poly1305_verify
+#define crypto_onetimeauth_BYTES crypto_onetimeauth_poly1305_BYTES
+#define crypto_onetimeauth_KEYBYTES crypto_onetimeauth_poly1305_KEYBYTES
+#define crypto_onetimeauth_IMPLEMENTATION crypto_onetimeauth_poly1305_IMPLEMENTATION
+#define crypto_onetimeauth_VERSION crypto_onetimeauth_poly1305_VERSION
+#define crypto_onetimeauth_poly1305_tweet_BYTES 16
+#define crypto_onetimeauth_poly1305_tweet_KEYBYTES 32
+extern int crypto_onetimeauth_poly1305_tweet(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
+extern int crypto_onetimeauth_poly1305_tweet_verify(const unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
+#define crypto_onetimeauth_poly1305_tweet_VERSION "-"
+#define crypto_onetimeauth_poly1305 crypto_onetimeauth_poly1305_tweet
+#define crypto_onetimeauth_poly1305_verify crypto_onetimeauth_poly1305_tweet_verify
+#define crypto_onetimeauth_poly1305_BYTES crypto_onetimeauth_poly1305_tweet_BYTES
+#define crypto_onetimeauth_poly1305_KEYBYTES crypto_onetimeauth_poly1305_tweet_KEYBYTES
+#define crypto_onetimeauth_poly1305_VERSION crypto_onetimeauth_poly1305_tweet_VERSION
+#define crypto_onetimeauth_poly1305_IMPLEMENTATION "crypto_onetimeauth/poly1305/tweet"
+#define crypto_scalarmult_PRIMITIVE "curve25519"
+#define crypto_scalarmult crypto_scalarmult_curve25519
+#define crypto_scalarmult_base crypto_scalarmult_curve25519_base
+#define crypto_scalarmult_BYTES crypto_scalarmult_curve25519_BYTES
+#define crypto_scalarmult_SCALARBYTES crypto_scalarmult_curve25519_SCALARBYTES
+#define crypto_scalarmult_IMPLEMENTATION crypto_scalarmult_curve25519_IMPLEMENTATION
+#define crypto_scalarmult_VERSION crypto_scalarmult_curve25519_VERSION
+#define crypto_scalarmult_curve25519_tweet_BYTES 32
+#define crypto_scalarmult_curve25519_tweet_SCALARBYTES 32
+extern int crypto_scalarmult_curve25519_tweet(unsigned char *,const unsigned char *,const unsigned char *);
+extern int crypto_scalarmult_curve25519_tweet_base(unsigned char *,const unsigned char *);
+#define crypto_scalarmult_curve25519_tweet_VERSION "-"
+#define crypto_scalarmult_curve25519 crypto_scalarmult_curve25519_tweet
+#define crypto_scalarmult_curve25519_base crypto_scalarmult_curve25519_tweet_base
+#define crypto_scalarmult_curve25519_BYTES crypto_scalarmult_curve25519_tweet_BYTES
+#define crypto_scalarmult_curve25519_SCALARBYTES crypto_scalarmult_curve25519_tweet_SCALARBYTES
+#define crypto_scalarmult_curve25519_VERSION crypto_scalarmult_curve25519_tweet_VERSION
+#define crypto_scalarmult_curve25519_IMPLEMENTATION "crypto_scalarmult/curve25519/tweet"
+#define crypto_secretbox_PRIMITIVE "xsalsa20poly1305"
+#define crypto_secretbox crypto_secretbox_xsalsa20poly1305
+#define crypto_secretbox_open crypto_secretbox_xsalsa20poly1305_open
+#define crypto_secretbox_KEYBYTES crypto_secretbox_xsalsa20poly1305_KEYBYTES
+#define crypto_secretbox_NONCEBYTES crypto_secretbox_xsalsa20poly1305_NONCEBYTES
+#define crypto_secretbox_ZEROBYTES crypto_secretbox_xsalsa20poly1305_ZEROBYTES
+#define crypto_secretbox_BOXZEROBYTES crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES
+#define crypto_secretbox_IMPLEMENTATION crypto_secretbox_xsalsa20poly1305_IMPLEMENTATION
+#define crypto_secretbox_VERSION crypto_secretbox_xsalsa20poly1305_VERSION
+#define crypto_secretbox_xsalsa20poly1305_tweet_KEYBYTES 32
+#define crypto_secretbox_xsalsa20poly1305_tweet_NONCEBYTES 24
+#define crypto_secretbox_xsalsa20poly1305_tweet_ZEROBYTES 32
+#define crypto_secretbox_xsalsa20poly1305_tweet_BOXZEROBYTES 16
+extern int crypto_secretbox_xsalsa20poly1305_tweet(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
+extern int crypto_secretbox_xsalsa20poly1305_tweet_open(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
+#define crypto_secretbox_xsalsa20poly1305_tweet_VERSION "-"
+#define crypto_secretbox_xsalsa20poly1305 crypto_secretbox_xsalsa20poly1305_tweet
+#define crypto_secretbox_xsalsa20poly1305_open crypto_secretbox_xsalsa20poly1305_tweet_open
+#define crypto_secretbox_xsalsa20poly1305_KEYBYTES crypto_secretbox_xsalsa20poly1305_tweet_KEYBYTES
+#define crypto_secretbox_xsalsa20poly1305_NONCEBYTES crypto_secretbox_xsalsa20poly1305_tweet_NONCEBYTES
+#define crypto_secretbox_xsalsa20poly1305_ZEROBYTES crypto_secretbox_xsalsa20poly1305_tweet_ZEROBYTES
+#define crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES crypto_secretbox_xsalsa20poly1305_tweet_BOXZEROBYTES
+#define crypto_secretbox_xsalsa20poly1305_VERSION crypto_secretbox_xsalsa20poly1305_tweet_VERSION
+#define crypto_secretbox_xsalsa20poly1305_IMPLEMENTATION "crypto_secretbox/xsalsa20poly1305/tweet"
+#define crypto_sign_PRIMITIVE "ed25519"
+#define crypto_sign crypto_sign_ed25519
+#define crypto_sign_open crypto_sign_ed25519_open
+#define crypto_sign_keypair crypto_sign_ed25519_keypair
+#define crypto_sign_BYTES crypto_sign_ed25519_BYTES
+#define crypto_sign_PUBLICKEYBYTES crypto_sign_ed25519_PUBLICKEYBYTES
+#define crypto_sign_SECRETKEYBYTES crypto_sign_ed25519_SECRETKEYBYTES
+#define crypto_sign_IMPLEMENTATION crypto_sign_ed25519_IMPLEMENTATION
+#define crypto_sign_VERSION crypto_sign_ed25519_VERSION
+#define crypto_sign_ed25519_tweet_BYTES 64
+#define crypto_sign_ed25519_tweet_PUBLICKEYBYTES 32
+#define crypto_sign_ed25519_tweet_SECRETKEYBYTES 64
+extern int crypto_sign_ed25519_tweet(unsigned char *,unsigned long long *,const unsigned char *,unsigned long long,const unsigned char *);
+extern int crypto_sign_ed25519_tweet_open(unsigned char *,unsigned long long *,const unsigned char *,unsigned long long,const unsigned char *);
+extern int crypto_sign_ed25519_tweet_keypair(unsigned char *,unsigned char *);
+#define crypto_sign_ed25519_tweet_VERSION "-"
+#define crypto_sign_ed25519 crypto_sign_ed25519_tweet
+#define crypto_sign_ed25519_open crypto_sign_ed25519_tweet_open
+#define crypto_sign_ed25519_keypair crypto_sign_ed25519_tweet_keypair
+#define crypto_sign_ed25519_BYTES crypto_sign_ed25519_tweet_BYTES
+#define crypto_sign_ed25519_PUBLICKEYBYTES crypto_sign_ed25519_tweet_PUBLICKEYBYTES
+#define crypto_sign_ed25519_SECRETKEYBYTES crypto_sign_ed25519_tweet_SECRETKEYBYTES
+#define crypto_sign_ed25519_VERSION crypto_sign_ed25519_tweet_VERSION
+#define crypto_sign_ed25519_IMPLEMENTATION "crypto_sign/ed25519/tweet"
+#define crypto_stream_PRIMITIVE "xsalsa20"
+#define crypto_stream crypto_stream_xsalsa20
+#define crypto_stream_xor crypto_stream_xsalsa20_xor
+#define crypto_stream_KEYBYTES crypto_stream_xsalsa20_KEYBYTES
+#define crypto_stream_NONCEBYTES crypto_stream_xsalsa20_NONCEBYTES
+#define crypto_stream_IMPLEMENTATION crypto_stream_xsalsa20_IMPLEMENTATION
+#define crypto_stream_VERSION crypto_stream_xsalsa20_VERSION
+#define crypto_stream_xsalsa20_tweet_KEYBYTES 32
+#define crypto_stream_xsalsa20_tweet_NONCEBYTES 24
+extern int crypto_stream_xsalsa20_tweet(unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
+extern int crypto_stream_xsalsa20_tweet_xor(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
+#define crypto_stream_xsalsa20_tweet_VERSION "-"
+#define crypto_stream_xsalsa20 crypto_stream_xsalsa20_tweet
+#define crypto_stream_xsalsa20_xor crypto_stream_xsalsa20_tweet_xor
+#define crypto_stream_xsalsa20_KEYBYTES crypto_stream_xsalsa20_tweet_KEYBYTES
+#define crypto_stream_xsalsa20_NONCEBYTES crypto_stream_xsalsa20_tweet_NONCEBYTES
+#define crypto_stream_xsalsa20_VERSION crypto_stream_xsalsa20_tweet_VERSION
+#define crypto_stream_xsalsa20_IMPLEMENTATION "crypto_stream/xsalsa20/tweet"
+#define crypto_stream_salsa20_tweet_KEYBYTES 32
+#define crypto_stream_salsa20_tweet_NONCEBYTES 8
+extern int crypto_stream_salsa20_tweet(unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
+extern int crypto_stream_salsa20_tweet_xor(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
+#define crypto_stream_salsa20_tweet_VERSION "-"
+#define crypto_stream_salsa20 crypto_stream_salsa20_tweet
+#define crypto_stream_salsa20_xor crypto_stream_salsa20_tweet_xor
+#define crypto_stream_salsa20_KEYBYTES crypto_stream_salsa20_tweet_KEYBYTES
+#define crypto_stream_salsa20_NONCEBYTES crypto_stream_salsa20_tweet_NONCEBYTES
+#define crypto_stream_salsa20_VERSION crypto_stream_salsa20_tweet_VERSION
+#define crypto_stream_salsa20_IMPLEMENTATION "crypto_stream/salsa20/tweet"
+#define crypto_verify_PRIMITIVE "16"
+#define crypto_verify crypto_verify_16
+#define crypto_verify_BYTES crypto_verify_16_BYTES
+#define crypto_verify_IMPLEMENTATION crypto_verify_16_IMPLEMENTATION
+#define crypto_verify_VERSION crypto_verify_16_VERSION
+#define crypto_verify_16_tweet_BYTES 16
+extern int crypto_verify_16_tweet(const unsigned char *,const unsigned char *);
+#define crypto_verify_16_tweet_VERSION "-"
+#define crypto_verify_16 crypto_verify_16_tweet
+#define crypto_verify_16_BYTES crypto_verify_16_tweet_BYTES
+#define crypto_verify_16_VERSION crypto_verify_16_tweet_VERSION
+#define crypto_verify_16_IMPLEMENTATION "crypto_verify/16/tweet"
+#define crypto_verify_32_tweet_BYTES 32
+extern int crypto_verify_32_tweet(const unsigned char *,const unsigned char *);
+#define crypto_verify_32_tweet_VERSION "-"
+#define crypto_verify_32 crypto_verify_32_tweet
+#define crypto_verify_32_BYTES crypto_verify_32_tweet_BYTES
+#define crypto_verify_32_VERSION crypto_verify_32_tweet_VERSION
+#define crypto_verify_32_IMPLEMENTATION "crypto_verify/32/tweet"
+#endif

+ 0 - 51
ports/WAGO-750-860.patch

@@ -1,51 +0,0 @@
-From 97515341454f26fcd14e50d5980f5f0361307814 Mon Sep 17 00:00:00 2001
-From: FlorianPalm <f.palm@plt.rwth-aachen.de>
-Date: Mon, 12 Jan 2015 18:45:01 +0100
-Subject: [PATCH] fixes to the patch
-
----
- CMakeLists.txt | 19 ++++++++-----------
- src/ua_util.h  |  2 +-
- 2 files changed, 9 insertions(+), 12 deletions(-)
-
-diff --git a/CMakeLists.txt b/CMakeLists.txt
-index c785182..9e66da0 100644
---- a/CMakeLists.txt
-+++ b/CMakeLists.txt
-@@ -47,19 +47,16 @@ set(lib_sources src/ua_types.c
- 
- # compiler flags
- if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
--add_definitions(-std=c99 -pipe -Wall -Wextra -Werror -Wformat
--                -Wno-unused-parameter -Wno-unused-function -Wno-unused-label -Wpointer-arith -Wreturn-type -Wsign-compare -Wmultichar
--                -Wshadow -Wcast-qual -Wmissing-prototypes -Wstrict-prototypes # -Wconversion
--                -Winit-self -Wuninitialized -Wno-deprecated -Wformat-security -ffunction-sections -fdata-sections)
-+add_definitions(-std=c99 -fomit-frame-pointer -pipe -msoft-float -fno-builtin -DEMBED -fno-strict-aliasing)
-     if(NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
-         add_definitions(-Wformat-nonliteral)
--        set (CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--gc-sections")
--        set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections")
-+        set (CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-elf2flt -msoft-float")
-+        set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}  -Wl,-elf2flt -msoft-float")
-     else()
-         add_definitions(-Wno-gnu-statement-expression)
-     endif()
- 	if(NOT WIN32)
--	    add_definitions(-fstack-protector -fPIC -fvisibility=hidden)
-+	   # add_definitions(-fPIC)
- 	endif()
- endif()
- 
-@@ -90,11 +90,7 @@ else()
- endif()
- 
- add_library(open62541-objects OBJECT ${lib_sources})
--add_library(open62541 SHARED $<TARGET_OBJECTS:open62541-objects>)
--add_library(open62541-static STATIC $<TARGET_OBJECTS:open62541-objects>)
--SET_TARGET_PROPERTIES(open62541-static PROPERTIES OUTPUT_NAME open62541 CLEAN_DIRECT_OUTPUT 1) # static version that exports all symbols
--target_compile_definitions(open62541-objects PRIVATE UA_DYNAMIC_LINKING)
--target_compile_definitions(open62541-static PRIVATE UA_DYNAMIC_LINKING)
-+add_library(open62541 $<TARGET_OBJECTS:open62541-objects>)
- 
- ## logging
- set(UA_LOGLEVEL 300 CACHE STRING "Level at which logs shall be reported")

+ 0 - 281
src/ongoing/generateSam.c

@@ -1,281 +0,0 @@
-#include "ua_xml.h"
-#include "ua_namespace.h"
-#include "ua_namespace_xml.h"
-#include "ua_types_generated.h"
-#include <ctype.h> // 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;
-}

+ 0 - 85
src/ongoing/ua_namespace_xml.c

@@ -1,85 +0,0 @@
-#include "ua_namespace_xml.h"
-#include <fcntl.h> // 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);
-}

+ 0 - 41
src/ongoing/ua_namespace_xml.h

@@ -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 */

+ 0 - 447
src/ongoing/ua_types_encoding_xml.c

@@ -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)

+ 0 - 77
src/ongoing/ua_types_encoding_xml.h

@@ -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_ */

+ 0 - 980
src/ongoing/ua_xml.c

@@ -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 <fcntl.h> // 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--; */
-}

+ 0 - 134
src/ongoing/ua_xml.h

@@ -1,134 +0,0 @@
-#ifndef __UA_XML_H
-#define __UA_XML_H
-
-#include <expat.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h> // strlen
-#include <ctype.h>  // isspace
-#include <unistd.h> // 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
- *     <LocalizedText>
- *          <Locale></Locale>
- *          <Text>Server</Text>
- *     </LocalizedText>
- * which might be abbreviated as
- *     <LocalizedText>Server</LocalizedText>
- *
- * 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__

+ 0 - 210
src/ongoing/xml2ns0.c

@@ -1,210 +0,0 @@
-#include <fcntl.h> // 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;
-}