Procházet zdrojové kódy

Merge pull request #3080 from jpfr/merge_10_5

Merge 1.0
Stefan Profanter před 5 roky
rodič
revize
c686f873c4

+ 6 - 0
README.md

@@ -70,6 +70,12 @@ On most systems, open62541 requires the C standard library only. For dependencie
 - Default Plugins: The default plugins use the POSIX interfaces for networking and accessing the system clock. Ports to different (embedded) architectures are achieved by customizing the plugins.
 - Building and Code Generation: The build environment is generated via CMake. Some code is auto-generated from XML definitions that are part of the OPC UA standard. The code generation scripts run with both Python 2 and 3.
 
+**Note:**
+Specific optional features are dependent on third-party libraries. These are all listed under the `deps/` folder.
+Depending on the selected feature set, some of these libraries will be included in the resulting library.
+
+More information on the third-party libraries can be found in the corresponding [deps/README.md](deps/README.md)
+
 ### Code Quality
 
 We emphasize code quality. The following quality metrics are continuously checked and are ensured to hold before an official release is made:

+ 1 - 1
debian/compat

@@ -1 +1 @@
-7
+9

+ 1 - 8
debian/control-template

@@ -1,7 +1,7 @@
 Source: open62541
 Priority: optional
 Maintainer: open62541 Team <open62541-core@googlegroups.com>
-Build-Depends: debhelper (>= 7.0.50~),
+Build-Depends: debhelper (>= 9),
  cmake (>= 2.8),
  git,
  graphviz,
@@ -27,10 +27,3 @@ Depends: ${shlibs:Depends}, ${misc:Depends}
 Description: Open source implementation of OPC UA (OPC Unified Architecture) aka IEC 62541
  open62541 is an open source C (C99) implementation of the OPC UA standard
 
-Package: libopen62541-<soname>-dbg
-Section: debug
-Architecture: any
-Priority: extra
-Depends: libopen62541-<soname> (= ${binary:Version}), ${misc:Depends}
-Description: Debugging symbols for open62541
- open62541 is an open source C (C99) implementation of the OPC UA standard

+ 80 - 87
debian/copyright

@@ -5,71 +5,65 @@ Source: https://open62541.org/
 
 Files: *
 Copyright: 2019 open62541 Team <open62541-core@googlegroups.com>
-License: MPL-2.0
-
-Files: debian/*
-Copyright: 2019 open62541 Team <open62541-core@googlegroups.com>
-License: MPL-2.0
-
 License: MPL-2.0
  Mozilla Public License Version 2.0
  ==================================
-
+ .
  1. Definitions
  --------------
-
+ .
  1.1. "Contributor"
      means each individual or legal entity that creates, contributes to
      the creation of, or owns Covered Software.
-
+ .
  1.2. "Contributor Version"
      means the combination of the Contributions of others (if any) used
      by a Contributor and that particular Contributor's Contribution.
-
+ .
  1.3. "Contribution"
      means Covered Software of a particular Contributor.
-
+ .
  1.4. "Covered Software"
      means Source Code Form to which the initial Contributor has attached
      the notice in Exhibit A, the Executable Form of such Source Code
      Form, and Modifications of such Source Code Form, in each case
      including portions thereof.
-
+ .
  1.5. "Incompatible With Secondary Licenses"
      means
-
+ .
      (a) that the initial Contributor has attached the notice described
          in Exhibit B to the Covered Software; or
-
+ .
      (b) that the Covered Software was made available under the terms of
          version 1.1 or earlier of the License, but not also under the
          terms of a Secondary License.
-
+ .
  1.6. "Executable Form"
      means any form of the work other than Source Code Form.
-
+ .
  1.7. "Larger Work"
      means a work that combines Covered Software with other material, in
      a separate file or files, that is not Covered Software.
-
+ .
  1.8. "License"
      means this document.
-
+ .
  1.9. "Licensable"
      means having the right to grant, to the maximum extent possible,
      whether at the time of the initial grant or subsequently, any and
      all of the rights conveyed by this License.
-
+ .
  1.10. "Modifications"
      means any of the following:
-
+ .
      (a) any file in Source Code Form that results from an addition to,
          deletion from, or modification of the contents of Covered
          Software; or
-
+ .
      (b) any new file in Source Code Form that contains any Covered
          Software.
-
+ .
  1.11. "Patent Claims" of a Contributor
      means any patent claim(s), including without limitation, method,
      process, and apparatus claims, in any patent Licensable by such
@@ -77,16 +71,16 @@ License: MPL-2.0
      License, by the making, using, selling, offering for sale, having
      made, import, or transfer of either its Contributions or its
      Contributor Version.
-
+ .
  1.12. "Secondary License"
      means either the GNU General Public License, Version 2.0, the GNU
      Lesser General Public License, Version 2.1, the GNU Affero General
      Public License, Version 3.0, or any later versions of those
      licenses.
-
+ .
  1.13. "Source Code Form"
      means the form of the work preferred for making modifications.
-
+ .
  1.14. "You" (or "Your")
      means an individual or a legal entity exercising rights under this
      License. For legal entities, "You" includes any entity that
@@ -96,83 +90,83 @@ License: MPL-2.0
      whether by contract or otherwise, or (b) ownership of more than
      fifty percent (50%) of the outstanding shares or beneficial
      ownership of such entity.
-
+ .
  2. License Grants and Conditions
  --------------------------------
-
+ .
  2.1. Grants
-
+ .
  Each Contributor hereby grants You a world-wide, royalty-free,
  non-exclusive license:
-
+ .
  (a) under intellectual property rights (other than patent or trademark)
      Licensable by such Contributor to use, reproduce, make available,
      modify, display, perform, distribute, and otherwise exploit its
      Contributions, either on an unmodified basis, with Modifications, or
      as part of a Larger Work; and
-
+ .
  (b) under Patent Claims of such Contributor to make, use, sell, offer
      for sale, have made, import, and otherwise transfer either its
      Contributions or its Contributor Version.
-
+ .
  2.2. Effective Date
-
+ .
  The licenses granted in Section 2.1 with respect to any Contribution
  become effective for each Contribution on the date the Contributor first
  distributes such Contribution.
-
+ .
  2.3. Limitations on Grant Scope
-
+ .
  The licenses granted in this Section 2 are the only rights granted under
  this License. No additional rights or licenses will be implied from the
  distribution or licensing of Covered Software under this License.
  Notwithstanding Section 2.1(b) above, no patent license is granted by a
  Contributor:
-
+ .
  (a) for any code that a Contributor has removed from Covered Software;
      or
-
+ .
  (b) for infringements caused by: (i) Your and any other third party's
      modifications of Covered Software, or (ii) the combination of its
      Contributions with other software (except as part of its Contributor
      Version); or
-
+ .
  (c) under Patent Claims infringed by Covered Software in the absence of
      its Contributions.
-
+ .
  This License does not grant any rights in the trademarks, service marks,
  or logos of any Contributor (except as may be necessary to comply with
  the notice requirements in Section 3.4).
-
+ .
  2.4. Subsequent Licenses
-
+ .
  No Contributor makes additional grants as a result of Your choice to
  distribute the Covered Software under a subsequent version of this
  License (see Section 10.2) or under the terms of a Secondary License (if
  permitted under the terms of Section 3.3).
-
+ .
  2.5. Representation
-
+ .
  Each Contributor represents that the Contributor believes its
  Contributions are its original creation(s) or it has sufficient rights
  to grant the rights to its Contributions conveyed by this License.
-
+ .
  2.6. Fair Use
-
+ .
  This License is not intended to limit any rights You have under
  applicable copyright doctrines of fair use, fair dealing, or other
  equivalents.
-
+ .
  2.7. Conditions
-
+ .
  Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
  in Section 2.1.
-
+ .
  3. Responsibilities
  -------------------
-
+ .
  3.1. Distribution of Source Form
-
+ .
  All distribution of Covered Software in Source Code Form, including any
  Modifications that You create or to which You contribute, must be under
  the terms of this License. You must inform recipients that the Source
@@ -180,24 +174,24 @@ License: MPL-2.0
  License, and how they can obtain a copy of this License. You may not
  attempt to alter or restrict the recipients' rights in the Source Code
  Form.
-
+ .
  3.2. Distribution of Executable Form
-
+ .
  If You distribute Covered Software in Executable Form then:
-
+ .
  (a) such Covered Software must also be made available in Source Code
      Form, as described in Section 3.1, and You must inform recipients of
      the Executable Form how they can obtain a copy of such Source Code
      Form by reasonable means in a timely manner, at a charge no more
      than the cost of distribution to the recipient; and
-
+ .
  (b) You may distribute such Executable Form under the terms of this
      License, or sublicense it under different terms, provided that the
      license for the Executable Form does not attempt to limit or alter
      the recipients' rights in the Source Code Form under this License.
-
+ .
  3.3. Distribution of a Larger Work
-
+ .
  You may create and distribute a Larger Work under terms of Your choice,
  provided that You also comply with the requirements of this License for
  the Covered Software. If the Larger Work is a combination of Covered
@@ -208,17 +202,17 @@ License: MPL-2.0
  the Larger Work may, at their option, further distribute the Covered
  Software under the terms of either this License or such Secondary
  License(s).
-
+ .
  3.4. Notices
-
+ .
  You may not remove or alter the substance of any license notices
  (including copyright notices, patent notices, disclaimers of warranty,
  or limitations of liability) contained within the Source Code Form of
  the Covered Software, except that You may alter any license notices to
  the extent required to remedy known factual inaccuracies.
-
+ .
  3.5. Application of Additional Terms
-
+ .
  You may choose to offer, and to charge a fee for, warranty, support,
  indemnity or liability obligations to one or more recipients of Covered
  Software. However, You may do so only on Your own behalf, and not on
@@ -229,10 +223,10 @@ License: MPL-2.0
  indemnity or liability terms You offer. You may include additional
  disclaimers of warranty and limitations of liability specific to any
  jurisdiction.
-
+ .
  4. Inability to Comply Due to Statute or Regulation
  ---------------------------------------------------
-
+ .
  If it is impossible for You to comply with any of the terms of this
  License with respect to some or all of the Covered Software due to
  statute, judicial order, or regulation then You must: (a) comply with
@@ -242,10 +236,10 @@ License: MPL-2.0
  Software under this License. Except to the extent prohibited by statute
  or regulation, such description must be sufficiently detailed for a
  recipient of ordinary skill to be able to understand it.
-
+ .
  5. Termination
  --------------
-
+ .
  5.1. The rights granted under this License will terminate automatically
  if You fail to comply with any of its terms. However, if You become
  compliant, then the rights granted under this License from a particular
@@ -259,19 +253,19 @@ License: MPL-2.0
  first time You have received notice of non-compliance with this License
  from such Contributor, and You become compliant prior to 30 days after
  Your receipt of the notice.
-
+ .
  5.2. If You initiate litigation against any entity by asserting a patent
  infringement claim (excluding declaratory judgment actions,
  counter-claims, and cross-claims) alleging that a Contributor Version
  directly or indirectly infringes any patent, then the rights granted to
  You by any and all Contributors for the Covered Software under Section
  2.1 of this License shall terminate.
-
+ .
  5.3. In the event of termination under Sections 5.1 or 5.2 above, all
  end user license agreements (excluding distributors and resellers) which
  have been validly granted by You or Your distributors under this License
  prior to termination shall survive termination.
-
+ .
  ************************************************************************
  *                                                                      *
  *  6. Disclaimer of Warranty                                           *
@@ -290,7 +284,7 @@ License: MPL-2.0
  *  authorized under this License except under this disclaimer.         *
  *                                                                      *
  ************************************************************************
-
+ .
  ************************************************************************
  *                                                                      *
  *  7. Limitation of Liability                                          *
@@ -313,76 +307,75 @@ License: MPL-2.0
  *  limitation may not apply to You.                                    *
  *                                                                      *
  ************************************************************************
-
+ .
  8. Litigation
  -------------
-
+ .
  Any litigation relating to this License may be brought only in the
  courts of a jurisdiction where the defendant maintains its principal
  place of business and such litigation shall be governed by laws of that
  jurisdiction, without reference to its conflict-of-law provisions.
  Nothing in this Section shall prevent a party's ability to bring
  cross-claims or counter-claims.
-
+ .
  9. Miscellaneous
  ----------------
-
+ .
  This License represents the complete agreement concerning the subject
  matter hereof. If any provision of this License is held to be
  unenforceable, such provision shall be reformed only to the extent
  necessary to make it enforceable. Any law or regulation which provides
  that the language of a contract shall be construed against the drafter
  shall not be used to construe this License against a Contributor.
-
+ .
  10. Versions of the License
  ---------------------------
-
+ .
  10.1. New Versions
-
+ .
  Mozilla Foundation is the license steward. Except as provided in Section
  10.3, no one other than the license steward has the right to modify or
  publish new versions of this License. Each version will be given a
  distinguishing version number.
-
+ .
  10.2. Effect of New Versions
-
+ .
  You may distribute the Covered Software under the terms of the version
  of the License under which You originally received the Covered Software,
  or under the terms of any subsequent version published by the license
  steward.
-
+ .
  10.3. Modified Versions
-
+ .
  If you create software not governed by this License, and you want to
  create a new license for such software, you may create and use a
  modified version of this License if you rename the license and remove
  any references to the name of the license steward (except to note that
  such modified license differs from this License).
-
+ .
  10.4. Distributing Source Code Form that is Incompatible With Secondary
  Licenses
-
+ .
  If You choose to distribute Source Code Form that is Incompatible With
  Secondary Licenses under the terms of this version of the License, the
  notice described in Exhibit B of this License must be attached.
-
+ .
  Exhibit A - Source Code Form License Notice
  -------------------------------------------
-
+ .
    This Source Code Form is subject to the terms of the Mozilla Public
    License, v. 2.0. If a copy of the MPL was not distributed with this
    file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
+ .
  If it is not possible or desirable to put the notice in a particular
  file, then You may include the notice in a location (such as a LICENSE
  file in a relevant directory) where a recipient would be likely to look
  for such a notice.
-
+ .
  You may add additional accurate notices of copyright ownership.
-
+ .
  Exhibit B - "Incompatible With Secondary Licenses" Notice
  ---------------------------------------------------------
-
+ .
    This Source Code Form is "Incompatible With Secondary Licenses", as
    defined by the Mozilla Public License, v. 2.0.
-

+ 1 - 1
debian/libopen62541-dev.install-template

@@ -1,5 +1,5 @@
 usr/include
-usr/lib/*/{*.a,*.so}
+usr/lib/*/*.so
 usr/lib/*/cmake/open62541/*
 usr/lib/*/pkgconfig/open62541.pc
 usr/share/open62541/*

+ 0 - 3
debian/rules-template

@@ -10,9 +10,6 @@ override_dh_auto_configure:
 override_dh_auto_test:
 	dh_auto_test -- ARGS+=--output-on-failure
 
-override_dh_strip:
-	dh_strip --dbg-package=libopen62541-<soname>-dbg
-
 %:
 	dh $@ --buildsystem=cmake --parallel
 

+ 24 - 0
deps/README.md

@@ -0,0 +1,24 @@
+# open62541 Third-Party libraries
+
+Specific optional features are dependent on third-party libraries. 
+Any third-party library which may be used is inside this `/deps` folder.
+
+Up to now all these libraries have a less strict License compared to MPL 2.0.
+Anyways you should make sure that the corresponding third-party license matches your needs.
+
+Here's a list of third party libraries:
+
+| Library         | License          | Description                                   |
+|-----------------|------------------|-----------------------------------------------|
+| jsmn            | MIT              | json parser                                   |
+| mdnsd           | BSD-3-Clause     | mDNS library                                  |
+| musl            | MIT              | libc extensions                               |
+| ua-nodeset      | MIT              | Official OPC UA Nodeset files by the OPCF     |
+| atoi            | MIT              | Char to int conversion, from musl             |
+| base64          | BSD              | Base64 encoding and decoding                  |
+| itoa            | MIT              | Int to char conversion                        |
+| ms_stdint       | BSD-3-Clause     | Replacement for stdint on older Visual Studio |
+| open62541_queue | BSD-3-Clause     | FIFO and LIFO queue implementation            |
+| pcg_basic       | Apache License 2 | Random Number Generation                      |
+| string_escape   | MIT              | utf8 encoding and decoding                    |
+| ziptree         | MPL 2.0          | Reusable zip tree implementation              |

+ 20 - 0
deps/jsmn/LICENSE

@@ -0,0 +1,20 @@
+Copyright (c) 2010 Serge A. Zaitsev
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+

+ 10 - 31
deps/libc_time.c

@@ -16,7 +16,6 @@ int __secs_to_tm(long long t, struct mytm *tm) {
     int remdays, remsecs, remyears;
     int qc_cycles, c_cycles, q_cycles;
     int months;
-    int wday, yday, leap;
     static const char days_in_month[] = {31,30,31,30,31,31,30,31,30,31,31,29};
 
     /* Reject time_t values whose year would overflow int */
@@ -31,9 +30,6 @@ int __secs_to_tm(long long t, struct mytm *tm) {
         --days;
     }
 
-    wday = (int)((3+days)%7);
-    if (wday < 0) wday += 7;
-
     qc_cycles = (int)(days / DAYS_PER_400Y);
     remdays = (int)(days % DAYS_PER_400Y);
     if (remdays < 0) {
@@ -53,10 +49,6 @@ int __secs_to_tm(long long t, struct mytm *tm) {
     if (remyears == 4) --remyears;
     remdays -= remyears * 365;
 
-    leap = !remyears && (q_cycles || !c_cycles);
-    yday = remdays + 31 + 28 + leap;
-    if (yday >= 365+leap) yday -= 365+leap;
-
     years = remyears + 4*q_cycles + 100*c_cycles + 400LL*qc_cycles;
 
     for (months=0; days_in_month[months] <= remdays; ++months)
@@ -72,9 +64,6 @@ int __secs_to_tm(long long t, struct mytm *tm) {
         ++tm->tm_year;
     }
     tm->tm_mday = remdays + 1;
-    tm->tm_wday = wday;
-    tm->tm_yday = yday;
-
     tm->tm_hour = remsecs / 3600;
     tm->tm_min = remsecs / 60 % 60;
     tm->tm_sec = remsecs % 60;
@@ -82,42 +71,32 @@ int __secs_to_tm(long long t, struct mytm *tm) {
     return 0;
 }
 
-int __month_to_secs(int month, int is_leap) {
-    static const int secs_through_month[] =
-        {0, 31*86400, 59*86400, 90*86400,
-         120*86400, 151*86400, 181*86400, 212*86400,
-         243*86400, 273*86400, 304*86400, 334*86400 };
+static const int secs_through_month[] =
+    {0, 31*86400, 59*86400, 90*86400,
+     120*86400, 151*86400, 181*86400, 212*86400,
+     243*86400, 273*86400, 304*86400, 334*86400 };
+
+static int
+__month_to_secs(int month, int is_leap) {
     int t = secs_through_month[month];
     if (is_leap && month >= 2)
         t+=86400;
     return t;
 }
 
-long long __year_to_secs(long long year, int *is_leap) {
-    if (year-(int)2ULL <= 136) {
-        long long y = (int)year;
-        long long leaps = (y-68)>>2;
-        if (!((y-8)&3)) {
-            leaps--;
-            if (is_leap) *is_leap = 1;
-        } else if (is_leap) *is_leap = 0;
-        return 31536000*(y-70) + 86400*leaps;
-    }
-
+static long long
+__year_to_secs(const long long year, int *is_leap) {
     int cycles, centuries, leaps, rem;
-
-    //if (!is_leap) is_leap = &(int){0};
     int is_leap_val = 0;
     if (!is_leap) {
         is_leap = &is_leap_val;
     }
     cycles = (int)((year-100) / 400);
     rem = (int)((year-100) % 400);
-    /* Comparison is always false because rem >= 0.
     if (rem < 0) {
         cycles--;
         rem += 400;
-    } */
+    }
     if (!rem) {
         *is_leap = 1;
         centuries = 0;

+ 0 - 4
deps/libc_time.h

@@ -8,13 +8,9 @@ struct mytm {
     int tm_mday;
     int tm_mon;
     int tm_year;
-    int tm_wday;
-    int tm_yday;
 };
 
 int __secs_to_tm(long long t, struct mytm *tm);
-int __month_to_secs(int month, int is_leap);
-long long __year_to_secs(long long year, int *is_leap);
 long long __tm_to_secs(const struct mytm *tm);
 
 #endif /* LIBC_TIME_H_ */

+ 6 - 0
doc/installing.rst

@@ -104,3 +104,9 @@ Install them with:
     sudo add-apt-repository ppa:open62541-team/ppa
     sudo apt-get update
     sudo apt-get install libopen62541-dev
+
+Arch packages are available in the AUR
+
+ * Stable Builds: https://aur.archlinux.org/packages/open62541/
+ * Unstable Builds (current master): https://aur.archlinux.org/packages/open62541-git/
+ * In order to add custom build options (:ref:`build_options`), you can set the environment variable ``OPEN62541_CMAKE_FLAGS``

+ 10 - 6
include/open62541/types.h

@@ -112,8 +112,8 @@ typedef int64_t UA_Int64;
  * ^^^^^^
  * An integer value between 0 and 18 446 744 073 709 551 615. */
 typedef uint64_t UA_UInt64;
-#define UA_UINT64_MIN (int64_t)0
-#define UA_UINT64_MAX (int64_t)18446744073709551615
+#define UA_UINT64_MIN (uint64_t)0
+#define UA_UINT64_MAX (uint64_t)18446744073709551615
 
 /**
  * Float
@@ -187,8 +187,12 @@ UA_STRING(char *chars) {
  * which represents the number of 100 nanosecond intervals since January 1, 1601
  * (UTC).
  *
- * The methods providing an interface to the system clock are provided by a
- * "plugin" that is statically linked with the library. */
+ * The methods providing an interface to the system clock are architecture-
+ * specific. Usually, they provide a UTC clock that includes leap seconds. The
+ * OPC UA standard allows the use of International Atomic Time (TAI) for the
+ * DateTime instead. But this is still unusual and not implemented for most
+ * SDKs. Currently (2019), UTC and TAI are 37 seconds apart due to leap
+ * seconds. */
 
 typedef int64_t UA_DateTime;
 
@@ -215,8 +219,8 @@ typedef struct UA_DateTimeStruct {
     UA_UInt16 sec;
     UA_UInt16 min;
     UA_UInt16 hour;
-    UA_UInt16 day;
-    UA_UInt16 month;
+    UA_UInt16 day;   /* From 1 to 31 */
+    UA_UInt16 month; /* From 1 to 12 */
     UA_UInt16 year;
 } UA_DateTimeStruct;
 

+ 13 - 1
src/server/ua_services_nodemanagement.c

@@ -645,8 +645,20 @@ AddNode_addRefs(UA_Server *server, UA_Session *session, const UA_NodeId *nodeId,
         }
     }
 
+    UA_StatusCode retval;
+    /* Make sure newly created node does not have itself as parent */
+    if (UA_NodeId_equal(nodeId, parentNodeId)) {
+        UA_LOG_NODEID_WRAP(nodeId, UA_LOG_INFO_SESSION(&server->config.logger, session,
+                                                       "AddNodes: The node %.*s can not have "
+                                                       "itself as parent",
+                                                       (int)nodeIdStr.length, nodeIdStr.data));
+        retval = UA_STATUSCODE_BADINVALIDARGUMENT;
+        goto cleanup;
+    }
+
+
     /* Check parent reference. Objects may have no parent. */
-    UA_StatusCode retval = checkParentReference(server, session, node->nodeClass,
+    retval = checkParentReference(server, session, node->nodeClass,
                                                 parentNodeId, referenceTypeId);
     if(retval != UA_STATUSCODE_GOOD) {
         UA_LOG_NODEID_WRAP(nodeId, UA_LOG_INFO_SESSION(&server->config.logger, session,

+ 11 - 5
src/ua_types.c

@@ -170,13 +170,19 @@ UA_DateTimeStruct
 UA_DateTime_toStruct(UA_DateTime t) {
     /* Calculating the the milli-, micro- and nanoseconds */
     UA_DateTimeStruct dateTimeStruct;
-    dateTimeStruct.nanoSec  = (u16)((t % 10) * 100);
-    dateTimeStruct.microSec = (u16)((t % 10000) / 10);
-    dateTimeStruct.milliSec = (u16)((t % 10000000) / 10000);
+    if(t >= 0) {
+        dateTimeStruct.nanoSec  = (u16)((t % 10) * 100);
+        dateTimeStruct.microSec = (u16)((t % 10000) / 10);
+        dateTimeStruct.milliSec = (u16)((t % 10000000) / 10000);
+    } else {
+        dateTimeStruct.nanoSec  = (u16)(((t % 10 + t) % 10) * 100);
+        dateTimeStruct.microSec = (u16)(((t % 10000 + t) % 10000) / 10);
+        dateTimeStruct.milliSec = (u16)(((t % 10000000 + t) % 10000000) / 10000);
+    }
 
     /* Calculating the unix time with #include <time.h> */
-    long long secSinceUnixEpoch = (long long)
-        ((t - UA_DATETIME_UNIX_EPOCH) / UA_DATETIME_SEC);
+    long long secSinceUnixEpoch = (long long)(t / UA_DATETIME_SEC)
+        - (long long)(UA_DATETIME_UNIX_EPOCH / UA_DATETIME_SEC);
     struct mytm ts;
     memset(&ts, 0, sizeof(struct mytm));
     __secs_to_tm(secSinceUnixEpoch, &ts);

+ 1 - 1
tests/pubsub/check_pubsub_encoding_json.c

@@ -97,7 +97,7 @@ START_TEST(UA_PubSub_EncodeAllOptionalFields) {
     // then
     ck_assert_int_eq(rv, UA_STATUSCODE_GOOD);
 
-    char* result = "{\"MessageId\":\"ABCDEFGH\",\"MessageType\":\"ua-data\",\"PublisherId\":65535,\"DataSetClassId\":\"00000001-0002-0003-0000-000000000000\",\"Messages\":[{\"DataSetWriterId\":12345,\"SequenceNumber\":4711,\"MetaDataVersion\":{\"MajorVersion\":42,\"MinorVersion\":7},\"Timestamp\":\"1601-01-13T20:38:32.1111111Z\",\"Status\":2764857,\"Payload\":{\"Field1\":{\"Type\":7,\"Body\":27}}}]}";
+    char* result = "{\"MessageId\":\"ABCDEFGH\",\"MessageType\":\"ua-data\",\"PublisherId\":65535,\"DataSetClassId\":\"00000001-0002-0003-0000-000000000000\",\"Messages\":[{\"DataSetWriterId\":12345,\"SequenceNumber\":4711,\"MetaDataVersion\":{\"MajorVersion\":42,\"MinorVersion\":7},\"Timestamp\":\"1601-01-13T20:38:31.1111111Z\",\"Status\":2764857,\"Payload\":{\"Field1\":{\"Type\":7,\"Body\":27}}}]}";
     ck_assert_str_eq(result, (char*)buffer.data);
 
     UA_ByteString_deleteMembers(&buffer);