[SVN-NetXMS] revision 3290

From: NetXMS.org SVN Server <svn_at_DOMAIN_REMOVED>
Date: Sat, 31 May 2008 13:08:28 +0300

* { font-family: Consolas, Lucida Console, Courier New; font-size: 100%; }
h1 { font-size: 150%; }
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
pre { line-height: 100%; width: 100%; }
.highlight span { width: 100%; display:-moz-inline-stack; display:inline-block; zoom:1; *display:inline; }
body { background: #ffffff; }
body .c { color: #999988; font-style: italic } /* Comment */
body .err { color: #a61717; background-color: #e3d2d2 } /* Error */
body .k { font-weight: bold } /* Keyword */
body .o { font-weight: bold } /* Operator */
body .cm { color: #999988; font-style: italic } /* Comment.Multiline */
body .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
body .c1 { color: #999988; font-style: italic } /* Comment.Single */
body .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
body .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
body .ge { font-style: italic } /* Generic.Emph */
body .gr { color: #aa0000 } /* Generic.Error */
body .gh { color: #999999 } /* Generic.Heading */
body .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
body .go { color: #888888 } /* Generic.Output */
body .gp { color: #555555 } /* Generic.Prompt */
body .gs { font-weight: bold } /* Generic.Strong */
body .gu { color: #aaaaaa } /* Generic.Subheading */
body .gt { color: #aa0000 } /* Generic.Traceback */
body .kc { font-weight: bold } /* Keyword.Constant */
body .kd { font-weight: bold } /* Keyword.Declaration */
body .kp { font-weight: bold } /* Keyword.Pseudo */
body .kr { font-weight: bold } /* Keyword.Reserved */
body .kt { color: #445588; font-weight: bold } /* Keyword.Type */
body .m { color: #009999 } /* Literal.Number */
body .s { color: #bb8844 } /* Literal.String */
body .na { color: #008080 } /* Name.Attribute */
body .nb { color: #999999 } /* Name.Builtin */
body .nc { color: #445588; font-weight: bold } /* Name.Class */
body .no { color: #008080 } /* Name.Constant */
body .ni { color: #800080 } /* Name.Entity */
body .ne { color: #990000; font-weight: bold } /* Name.Exception */
body .nf { color: #990000; font-weight: bold } /* Name.Function */
body .nn { color: #555555 } /* Name.Namespace */
body .nt { color: #000080 } /* Name.Tag */
body .nv { color: #008080 } /* Name.Variable */
body .ow { font-weight: bold } /* Operator.Word */
body .w { color: #bbbbbb } /* Text.Whitespace */
body .mf { color: #009999 } /* Literal.Number.Float */
body .mh { color: #009999 } /* Literal.Number.Hex */
body .mi { color: #009999 } /* Literal.Number.Integer */
body .mo { color: #009999 } /* Literal.Number.Oct */
body .sb { color: #bb8844 } /* Literal.String.Backtick */
body .sc { color: #bb8844 } /* Literal.String.Char */
body .sd { color: #bb8844 } /* Literal.String.Doc */
body .s2 { color: #bb8844 } /* Literal.String.Double */
body .se { color: #bb8844 } /* Literal.String.Escape */
body .sh { color: #bb8844 } /* Literal.String.Heredoc */
body .si { color: #bb8844 } /* Literal.String.Interpol */
body .sx { color: #bb8844 } /* Literal.String.Other */
body .sr { color: #808000 } /* Literal.String.Regex */
body .s1 { color: #bb8844 } /* Literal.String.Single */
body .ss { color: #bb8844 } /* Literal.String.Symbol */
body .bp { color: #999999 } /* Name.Builtin.Pseudo */
body .vc { color: #008080 } /* Name.Variable.Class */
body .vg { color: #008080 } /* Name.Variable.Global */
body .vi { color: #008080 } /* Name.Variable.Instance */
body .il { color: #009999 } /* Literal.Number.Integer.Long */

Info

Revision:3290
Author:victor

Date:2008-05-31 13:08:26 +0300 (Sat, 31 May 2008)

Comment:- nxcptest fully functional
- minor fixes

Changes
U trunk/ChangeLog
U trunk/include/nms_util.h
U trunk/src/agent/core/nxagentd.h
U trunk/src/agent/core/win32.cpp
U trunk/src/libnetxms/Makefile.am
U trunk/src/libnetxms/libnetxms.dsp
U trunk/src/libnetxms/message.cpp
U trunk/src/libnetxms/strtoll.c
U trunk/src/libnetxms/strtoull.c
A trunk/src/libnetxms/wcstoll.c
A trunk/src/libnetxms/wcstoull.c
U trunk/src/libnetxms/xml.cpp
U trunk/src/nxcptest/nxcptest.cpp

Diff
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2008-05-30 21:15:47 UTC (rev 3289)
+++ trunk/ChangeLog 2008-05-31 10:08:26 UTC (rev 3290)
@@ -1,8 +1,8 @@
 *
-* 1.0.0
+* 0.2.22
 *
 
-- Stable release
+- Implemented XML encoding for NXCP messages
 - Fixed issues: #201
 
 

Modified: trunk/include/nms_util.h
===================================================================
--- trunk/include/nms_util.h 2008-05-30 21:15:47 UTC (rev 3289)
+++ trunk/include/nms_util.h 2008-05-31 10:08:26 UTC (rev 3290)
@@ -550,12 +550,6 @@
 
 #ifdef UNICODE
 
-#if !HAVE_WCSTOLL
- INT64 LIBNETXMS_EXPORTABLE wcstoll(const WCHAR *nptr, WCHAR **endptr, int base);
-#endif
-#if !HAVE_WCSTOULL
- QWORD LIBNETXMS_EXPORTABLE wcstoull(const WCHAR *nptr, WCHAR **endptr, int base);
-#endif
 #if !HAVE_WFOPEN
         FILE LIBNETXMS_EXPORTABLE *wfopen(const WCHAR *_name, const WCHAR *_type);
 #endif
@@ -568,15 +562,23 @@
 #if !HAVE_WGETENV
         WCHAR *wgetenv(const WCHAR *_string);
 #endif
-#else /* UNICODE */
+
+#endif /* UNICODE */
+
 #if !HAVE_STRTOLL
         INT64 LIBNETXMS_EXPORTABLE strtoll(const char *nptr, char **endptr, int base);
 #endif
 #if !HAVE_STRTOULL
         QWORD LIBNETXMS_EXPORTABLE strtoull(const char *nptr, char **endptr, int base);
 #endif
-#endif /* UNICODE */
 
+#if !HAVE_WCSTOLL
+ INT64 LIBNETXMS_EXPORTABLE wcstoll(const WCHAR *nptr, WCHAR **endptr, int base);
+#endif
+#if !HAVE_WCSTOULL
+ QWORD LIBNETXMS_EXPORTABLE wcstoull(const WCHAR *nptr, WCHAR **endptr, int base);
+#endif
+
 #ifdef _WIN32
 #ifndef SWIGPERL
     DIR LIBNETXMS_EXPORTABLE *opendir(const char *filename);

Modified: trunk/src/agent/core/nxagentd.h
===================================================================
--- trunk/src/agent/core/nxagentd.h 2008-05-30 21:15:47 UTC (rev 3289)
+++ trunk/src/agent/core/nxagentd.h 2008-05-31 10:08:26 UTC (rev 3290)
@@ -1,6 +1,6 @@
 /*
 ** NetXMS multiplatform core agent
-** Copyright (C) 2003, 2004, 2005, 2006 Victor Kirhenshtein
+** Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Victor Kirhenshtein
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 **
-** $module: nxagentd.h
+** File: nxagentd.h
 **
 **/
 

Modified: trunk/src/agent/core/win32.cpp
===================================================================
--- trunk/src/agent/core/win32.cpp 2008-05-30 21:15:47 UTC (rev 3289)
+++ trunk/src/agent/core/win32.cpp 2008-05-31 10:08:26 UTC (rev 3290)
@@ -224,7 +224,7 @@
          break;
    }
 
- sprintf(value, &quot;Windows %s %d.%d.%d %s %s\r\n&quot;, computerName, versionInfo.dwMajorVersion,
+ sprintf(value, &quot;Windows %s %d.%d.%d %s %s&quot;, computerName, versionInfo.dwMajorVersion,
            versionInfo.dwMinorVersion, versionInfo.dwBuildNumber, osVersion, cpuType);
    return SYSINFO_RC_SUCCESS;
 }

Modified: trunk/src/libnetxms/Makefile.am
===================================================================
--- trunk/src/libnetxms/Makefile.am 2008-05-30 21:15:47 UTC (rev 3289)
+++ trunk/src/libnetxms/Makefile.am 2008-05-31 10:08:26 UTC (rev 3290)
@@ -1,5 +1,9 @@
 INCLUDES=-I_at_top_srcdir@/include
-SOURCES = base64.cpp config.cpp crypto.cpp gen_uuid.c dload.cpp hash.cpp icmp.cpp inline.cpp main.cpp md5.cpp message.cpp msgwq.cpp nxcp.cpp qsort.c queue.cpp rwlock.cpp scandir.c serial.cpp sha1.cpp string.cpp strmap.cpp strtoll.c strtoull.c table.cpp threads.cpp tools.cpp unicode.cpp uuid.c xml.cpp
+SOURCES = base64.cpp config.cpp crypto.cpp gen_uuid.c dload.cpp hash.cpp \
+ icmp.cpp inline.cpp main.cpp md5.cpp message.cpp msgwq.cpp \
+ nxcp.cpp qsort.c queue.cpp rwlock.cpp scandir.c serial.cpp \
+ sha1.cpp string.cpp strmap.cpp strtoll.c strtoull.c table.cpp \
+ threads.cpp tools.cpp unicode.cpp uuid.c wcstoll.c wcstoull.c xml.cpp
 
 if BUILD_UNICODE_LIBS
 lib_LTLIBRARIES = libnetxms.la libnetxmsw.la

Modified: trunk/src/libnetxms/libnetxms.dsp
===================================================================
--- trunk/src/libnetxms/libnetxms.dsp 2008-05-30 21:15:47 UTC (rev 3289)
+++ trunk/src/libnetxms/libnetxms.dsp 2008-05-31 10:08:26 UTC (rev 3290)
@@ -371,6 +371,14 @@
 # End Source File
 # Begin Source File
 
+SOURCE=.\wcstoll.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\wcstoull.c
+# End Source File
+# Begin Source File
+
 SOURCE=.\xml.cpp
 # End Source File
 # End Group

Modified: trunk/src/libnetxms/message.cpp
===================================================================
--- trunk/src/libnetxms/message.cpp 2008-05-30 21:15:47 UTC (rev 3289)
+++ trunk/src/libnetxms/message.cpp 2008-05-31 10:08:26 UTC (rev 3290)
@@ -867,7 +867,7 @@
 #endif
         static const TCHAR *dtString[] = { _T(&quot;int32&quot;), _T(&quot;string&quot;), _T(&quot;int64&quot;), _T(&quot;int16&quot;), _T(&quot;binary&quot;), _T(&quot;float&quot;) };
 
- xml.AddFormattedString(_T(&quot;&lt;?xml version=\&quot;1.0\&quot; encoding=\&quot;UTF-8\&quot;?&gt;\r\n&lt;nxcp version=\&quot;%d\&quot;&gt;\r\n &lt;message code=\&quot;%s\&quot; id=\&quot;%d\&quot;&gt;\r\n&quot;), m_nVersion, m_wCode, m_dwId);
+ xml.AddFormattedString(_T(&quot;&lt;?xml version=\&quot;1.0\&quot; encoding=\&quot;UTF-8\&quot;?&gt;\r\n&lt;nxcp version=\&quot;%d\&quot;&gt;\r\n &lt;message code=\&quot;%d\&quot; id=\&quot;%d\&quot;&gt;\r\n&quot;), m_nVersion, m_wCode, m_dwId);
         for(i = 0; i &lt; m_dwNumVar; i++)
         {
                 xml.AddFormattedString(_T(&quot; &lt;variable id=\&quot;%d\&quot; type=\&quot;%s\&quot;&gt;\r\n &lt;value&gt;&quot;),
@@ -888,10 +888,10 @@
                                 xml.AddDynamicString(EscapeStringForXML(m_ppVarList[i]-&gt;data.string.szValue, m_ppVarList[i]-&gt;data.string.dwLen));
 #else
                                 bytes = WideCharToMultiByte(CP_UTF8, 0, m_ppVarList[i]-&gt;data.string.szValue,
- m_ppVarList[i]-&gt;data.string.dwLen, NULL, 0, NULL, NULL);
+ m_ppVarList[i]-&gt;data.string.dwLen / 2, NULL, 0, NULL, NULL);
                                 tempStr = (char *)malloc(bytes + 1);
                                 bytes = WideCharToMultiByte(CP_UTF8, 0, m_ppVarList[i]-&gt;data.string.szValue,
- m_ppVarList[i]-&gt;data.string.dwLen, tempStr, bytes + 1, NULL, NULL);
+ m_ppVarList[i]-&gt;data.string.dwLen / 2, tempStr, bytes + 1, NULL, NULL);
                                 xml.AddDynamicString(EscapeStringForXML(tempStr, bytes));
                                 free(tempStr);
 #endif
@@ -915,7 +915,7 @@
                         default:
                                 break;
                 }
- xml += _T(&quot; &lt;/value&gt;\r\n &lt;/variable&gt;\r\n&quot;);
+ xml += _T(&quot;&lt;/value&gt;\r\n &lt;/variable&gt;\r\n&quot;);
         }
         xml += _T(&quot; &lt;/message&gt;\r\n&lt;/nxcp&gt;\r\n&quot;);
 

Modified: trunk/src/libnetxms/strtoll.c
===================================================================
--- trunk/src/libnetxms/strtoll.c 2008-05-30 21:15:47 UTC (rev 3289)
+++ trunk/src/libnetxms/strtoll.c 2008-05-31 10:08:26 UTC (rev 3290)
@@ -29,7 +29,7 @@
 
 #include &quot;libnetxms.h&quot;
 
-#if (!defined(UNICODE) &amp;&amp; !(HAVE_STRTOLL)) || (defined(UNICODE) &amp;&amp; !(HAVE_WCSTOLL))
+#if !(HAVE_STRTOLL)
 
 #ifndef UNDER_CE
 #include &lt;sys/types.h&gt;
@@ -46,19 +46,11 @@
  * alphabets and digits are each contiguous.
  */
 
-#ifdef UNICODE
-INT64 LIBNETXMS_EXPORTABLE wcstoll(const WCHAR *nptr, WCHAR **endptr, int base)
-#else
 INT64 LIBNETXMS_EXPORTABLE strtoll(const char *nptr, char **endptr, int base)
-#endif
 {
- const TCHAR *s;
+ const char *s;
         INT64 acc, cutoff;
-#ifdef UNICODE
- _TINT c;
-#else
    int c;
-#endif
         int neg, any, cutlim;
 
         /*
@@ -69,23 +61,23 @@
         s = nptr;
         do {
                 c = *s++;
- } while (_istspace(c));
- if (c == _T(&#39;-&#39;)) {
+ } while (isspace(c));
+ if (c == &#39;-&#39;) {
                 neg = 1;
                 c = *s++;
         } else {
                 neg = 0;
- if (c == _T(&#39;+&#39;))
+ if (c == &#39;+&#39;)
                         c = *s++;
         }
         if ((base == 0 || base == 16) &amp;&amp;
- c == _T(&#39;0&#39;) &amp;&amp; (*s == _T(&#39;x&#39;) || *s == &#39;X&#39;)) {
+ c == &#39;0&#39; &amp;&amp; (*s == &#39;x&#39; || *s == &#39;X&#39;)) {
                 c = s[1];
                 s += 2;
                 base = 16;
         }
         if (base == 0)
- base = c == _T(&#39;0&#39;) ? 8 : 10;
+ base = c == &#39;0&#39; ? 8 : 10;
 
         /*
          * Compute the cutoff value between legal numbers and illegal
@@ -116,10 +108,10 @@
                 cutlim = -cutlim;
         }
         for (acc = 0, any = 0;; c = *s++) {
- if (_istdigit(c))
- c -= _T(&#39;0&#39;);
- else if (_istalpha(c))
- c -= _istupper(c) ? _T(&#39;A&#39;) - 10 : _T(&#39;a&#39;) - 10;
+ if (isdigit(c))
+ c -= &#39;0&#39;;
+ else if (isalpha(c))
+ c -= isupper(c) ? &#39;A&#39; - 10 : &#39;a&#39; - 10;
                 else
                         break;
                 if (c &gt;= base)
@@ -153,7 +145,7 @@
                 }
         }
         if (endptr != 0)
- *endptr = (TCHAR *) (any ? s - 1 : nptr);
+ *endptr = (char *) (any ? s - 1 : nptr);
         return (acc);
 }
 

Modified: trunk/src/libnetxms/strtoull.c
===================================================================
--- trunk/src/libnetxms/strtoull.c 2008-05-30 21:15:47 UTC (rev 3289)
+++ trunk/src/libnetxms/strtoull.c 2008-05-31 10:08:26 UTC (rev 3290)
@@ -29,7 +29,7 @@
 
 #include &quot;libnetxms.h&quot;
 
-#if (!defined(UNICODE) &amp;&amp; !(HAVE_STRTOULL)) || (defined(UNICODE) &amp;&amp; !(HAVE_WCSTOULL))
+#if !(HAVE_STRTOULL)
 
 #ifndef UNDER_CE
 #include &lt;sys/types.h&gt;
@@ -47,19 +47,11 @@
  * alphabets and digits are each contiguous.
  */
 
-#ifdef UNICODE
-QWORD LIBNETXMS_EXPORTABLE wcstoull(const WCHAR *nptr, WCHAR **endptr, int base)
-#else
 QWORD LIBNETXMS_EXPORTABLE strtoull(const char *nptr, char **endptr, int base)
-#endif
 {
- const TCHAR *s;
+ const char *s;
         QWORD acc, cutoff;
-#ifdef UNICODE
- _TINT c;
-#else
    int c;
-#endif
         int neg, any, cutlim;
 
         /*
@@ -68,31 +60,31 @@
         s = nptr;
         do {
                 c = *s++;
- } while (_istspace(c));
- if (c == _T(&#39;-&#39;)) {
+ } while (isspace(c));
+ if (c == &#39;-&#39;) {
                 neg = 1;
                 c = *s++;
         } else {
                 neg = 0;
- if (c == _T(&#39;+&#39;))
+ if (c == &#39;+&#39;)
                         c = *s++;
         }
         if ((base == 0 || base == 16) &amp;&amp;
- c == _T(&#39;0&#39;) &amp;&amp; (*s == _T(&#39;x&#39;) || *s == _T(&#39;X&#39;))) {
+ c == &#39;0&#39; &amp;&amp; (*s == &#39;x&#39; || *s == &#39;X&#39;)) {
                 c = s[1];
                 s += 2;
                 base = 16;
         }
         if (base == 0)
- base = c == _T(&#39;0&#39;) ? 8 : 10;
+ base = c == &#39;0&#39; ? 8 : 10;
 
         cutoff = ULLONG_MAX / (QWORD)base;
         cutlim = (int)(ULLONG_MAX % (QWORD)base);
         for (acc = 0, any = 0;; c = *s++) {
- if (_istdigit(c))
- c -= _T(&#39;0&#39;);
- else if (_istalpha(c))
- c -= _istupper(c) ? _T(&#39;A&#39;) - 10 : _T(&#39;a&#39;) - 10;
+ if (isdigit(c))
+ c -= &#39;0&#39;;
+ else if (isalpha(c))
+ c -= isupper(c) ? &#39;A&#39; - 10 : &#39;a&#39; - 10;
                 else
                         break;
                 if (c &gt;= base)
@@ -114,7 +106,7 @@
         if (neg &amp;&amp; any &gt; 0)
                 acc = ~acc + 1;
         if (endptr != 0)
- *endptr = (TCHAR *) (any ? s - 1 : nptr);
+ *endptr = (char *) (any ? s - 1 : nptr);
         return (acc);
 }
 

Added: trunk/src/libnetxms/wcstoll.c
===================================================================
--- trunk/src/libnetxms/wcstoll.c (rev 0)
+++ trunk/src/libnetxms/wcstoll.c 2008-05-31 10:08:26 UTC (rev 3290)
@@ -0,0 +1,152 @@
+/*-
+ * Copyright (c) 1992 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS&#39;&#39; AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include &quot;libnetxms.h&quot;
+
+#if !(HAVE_WCSTOLL)
+
+#ifndef UNDER_CE
+#include &lt;sys/types.h&gt;
+#include &lt;errno.h&gt;
+#endif
+
+#include &lt;ctype.h&gt;
+#include &lt;stdlib.h&gt;
+
+/*
+ * Convert a string to a long long.
+ *
+ * Ignores `locale&#39; stuff. Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+
+INT64 LIBNETXMS_EXPORTABLE wcstoll(const WCHAR *nptr, WCHAR **endptr, int base)
+{
+ const WCHAR *s;
+ INT64 acc, cutoff;
+ wint_t c;
+ int neg, any, cutlim;
+
+ /*
+ * Skip white space and pick up leading +/- sign if any.
+ * If base is 0, allow 0x for hex and 0 for octal, else
+ * assume decimal; if base is already 16, allow 0x.
+ */
+ s = nptr;
+ do {
+ c = *s++;
+ } while (iswspace(c));
+ if (c == L&#39;-&#39;) {
+ neg = 1;
+ c = *s++;
+ } else {
+ neg = 0;
+ if (c == L&#39;+&#39;)
+ c = *s++;
+ }
+ if ((base == 0 || base == 16) &amp;&amp;
+ c == L&#39;0&#39; &amp;&amp; (*s == L&#39;x&#39; || *s == L&#39;X&#39;)) {
+ c = s[1];
+ s += 2;
+ base = 16;
+ }
+ if (base == 0)
+ base = c == L&#39;0&#39; ? 8 : 10;
+
+ /*
+ * Compute the cutoff value between legal numbers and illegal
+ * numbers. That is the largest legal value, divided by the
+ * base. An input number that is greater than this value, if
+ * followed by a legal input character, is too big. One that
+ * is equal to this value may be valid or not; the limit
+ * between valid and invalid numbers is then based on the last
+ * digit. For instance, if the range for long longs is
+ * [-9223372036854775808..9223372036854775807] and the input base
+ * is 10, cutoff will be set to 922337203685477580 and cutlim to
+ * either 7 (neg==0) or 8 (neg==1), meaning that if we have
+ * accumulated a value &gt; 922337203685477580, or equal but the
+ * next digit is &gt; 7 (or 8), the number is too big, and we will
+ * return a range error.
+ *
+ * Set any if any `digits&#39; consumed; make it negative to indicate
+ * overflow.
+ */
+ cutoff = neg ? LLONG_MIN : LLONG_MAX;
+ cutlim = (int)(cutoff % base);
+ cutoff /= base;
+ if (neg) {
+ if (cutlim &gt; 0) {
+ cutlim -= base;
+ cutoff += 1;
+ }
+ cutlim = -cutlim;
+ }
+ for (acc = 0, any = 0;; c = *s++) {
+ if (iswdigit(c))
+ c -= L&#39;0&#39;;
+ else if (iswalpha(c))
+ c -= iswupper(c) ? L&#39;A&#39; - 10 : L&#39;a&#39; - 10;
+ else
+ break;
+ if (c &gt;= base)
+ break;
+ if (any &lt; 0)
+ continue;
+ if (neg) {
+ if (acc &lt; cutoff || (acc == cutoff &amp;&amp; c &gt; cutlim)) {
+ any = -1;
+ acc = LLONG_MIN;
+#ifndef UNDER_CE
+ errno = ERANGE;
+#endif
+ } else {
+ any = 1;
+ acc *= base;
+ acc -= c;
+ }
+ } else {
+ if (acc &gt; cutoff || (acc == cutoff &amp;&amp; c &gt; cutlim)) {
+ any = -1;
+ acc = LLONG_MAX;
+#ifndef UNDER_CE
+ errno = ERANGE;
+#endif
+ } else {
+ any = 1;
+ acc *= base;
+ acc += c;
+ }
+ }
+ }
+ if (endptr != 0)
+ *endptr = (WCHAR *) (any ? s - 1 : nptr);
+ return (acc);
+}
+
+#endif /* !(HAVE_STRTOLL) */

Added: trunk/src/libnetxms/wcstoull.c
===================================================================
--- trunk/src/libnetxms/wcstoull.c (rev 0)
+++ trunk/src/libnetxms/wcstoull.c 2008-05-31 10:08:26 UTC (rev 3290)
@@ -0,0 +1,113 @@
+/*-
+ * Copyright (c) 1992 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS&#39;&#39; AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include &quot;libnetxms.h&quot;
+
+#if !(HAVE_WCSTOULL)
+
+#ifndef UNDER_CE
+#include &lt;sys/types.h&gt;
+#include &lt;errno.h&gt;
+#endif
+
+#include &lt;ctype.h&gt;
+#include &lt;limits.h&gt;
+#include &lt;stdlib.h&gt;
+
+/*
+ * Convert a string to an 64 bit unsigned integer.
+ *
+ * Ignores `locale&#39; stuff. Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+
+QWORD LIBNETXMS_EXPORTABLE wcstoull(const WCHAR *nptr, WCHAR **endptr, int base)
+{
+ const WCHAR *s;
+ QWORD acc, cutoff;
+ wint_t c;
+ int neg, any, cutlim;
+
+ /*
+ * See strtoq for comments as to the logic used.
+ */
+ s = nptr;
+ do {
+ c = *s++;
+ } while (iswspace(c));
+ if (c == L&#39;-&#39;) {
+ neg = 1;
+ c = *s++;
+ } else {
+ neg = 0;
+ if (c == L&#39;+&#39;)
+ c = *s++;
+ }
+ if ((base == 0 || base == 16) &amp;&amp;
+ c == L&#39;0&#39; &amp;&amp; (*s == L&#39;x&#39; || *s == L&#39;X&#39;)) {
+ c = s[1];
+ s += 2;
+ base = 16;
+ }
+ if (base == 0)
+ base = c == L&#39;0&#39; ? 8 : 10;
+
+ cutoff = ULLONG_MAX / (QWORD)base;
+ cutlim = (int)(ULLONG_MAX % (QWORD)base);
+ for (acc = 0, any = 0;; c = *s++) {
+ if (iswdigit(c))
+ c -= L&#39;0&#39;;
+ else if (iswalpha(c))
+ c -= iswupper(c) ? L&#39;A&#39; - 10 : L&#39;a&#39; - 10;
+ else
+ break;
+ if (c &gt;= base)
+ break;
+ if (any &lt; 0)
+ continue;
+ if (acc &gt; cutoff || (acc == cutoff &amp;&amp; c &gt; cutlim)) {
+ any = -1;
+ acc = ULLONG_MAX;
+#ifndef UNDER_CE
+ errno = ERANGE;
+#endif
+ } else {
+ any = 1;
+ acc *= (QWORD)base;
+ acc += c;
+ }
+ }
+ if (neg &amp;&amp; any &gt; 0)
+ acc = ~acc + 1;
+ if (endptr != 0)
+ *endptr = (WCHAR *) (any ? s - 1 : nptr);
+ return (acc);
+}
+
+#endif /* !(HAVE_STRTOULL) */

Modified: trunk/src/libnetxms/xml.cpp
===================================================================
--- trunk/src/libnetxms/xml.cpp 2008-05-30 21:15:47 UTC (rev 3289)
+++ trunk/src/libnetxms/xml.cpp 2008-05-31 10:08:26 UTC (rev 3290)
@@ -38,7 +38,8 @@
         inLen = (length == -1) ? _tcslen(string) : length;
         for(in = string, outLen = 0; (inLen &gt; 0) &amp;&amp; (*in != 0); in++, outLen++, inLen--)
                 if ((*in == _T(&#39;&amp;&#39;)) || (*in == _T(&#39;&lt;&#39;)) ||
- (*in == _T(&#39;&gt;&#39;)) || (*in == _T(&#39;&quot;&#39;)))
+ (*in == _T(&#39;&gt;&#39;)) || (*in == _T(&#39;&quot;&#39;)) ||
+ (*in &lt; 32))
                         outLen += 5;
         outLen++;
         
@@ -50,23 +51,35 @@
                 switch(*in)
                 {
                         case _T(&#39;&amp;&#39;):
- _tcscat(&amp;out[pos], _T(&quot;&amp;amp;&quot;));
+ _tcscpy(&amp;out[pos], _T(&quot;&amp;amp;&quot;));
                                 pos += 5;
                                 break;
                         case _T(&#39;&lt;&#39;):
- _tcscat(&amp;out[pos], _T(&quot;&amp;lt;&quot;));
+ _tcscpy(&amp;out[pos], _T(&quot;&amp;lt;&quot;));
                                 pos += 4;
                                 break;
                         case _T(&#39;&gt;&#39;):
- _tcscat(&amp;out[pos], _T(&quot;&amp;gt;&quot;));
+ _tcscpy(&amp;out[pos], _T(&quot;&amp;gt;&quot;));
                                 pos += 4;
                                 break;
                         case _T(&#39;&quot;&#39;):
- _tcscat(&amp;out[pos], _T(&quot;&amp;quot;&quot;));
+ _tcscpy(&amp;out[pos], _T(&quot;&amp;quot;&quot;));
                                 pos += 6;
                                 break;
+ case _T(&#39;\&#39;&#39;):
+ _tcscpy(&amp;out[pos], _T(&quot;&amp;apos;&quot;));
+ pos += 6;
+ break;
                         default:
- out[pos++] = *in;
+ if (*in &lt; 32)
+ {
+ _stprintf(&amp;out[pos], _T(&quot;&amp;#x%02d;&quot;), *in);
+ pos += 6;
+ }
+ else
+ {
+ out[pos++] = *in;
+ }
                                 break;
                 }
         }

Modified: trunk/src/nxcptest/nxcptest.cpp
===================================================================
--- trunk/src/nxcptest/nxcptest.cpp 2008-05-30 21:15:47 UTC (rev 3289)
+++ trunk/src/nxcptest/nxcptest.cpp 2008-05-31 10:08:26 UTC (rev 3290)
@@ -26,6 +26,13 @@
 
 
 //
+// Constants
+//
+
+#define RAW_MSG_SIZE 262144
+
+
+//
 // Help text
 //
 
@@ -42,6 +49,87 @@
 
 
 //
+// Receiver thread
+//
+
+static THREAD_RESULT THREAD_CALL RecvThread(void *arg)
+{
+ CSCP_MESSAGE *pRawMsg;
+ CSCPMessage *pMsg;
+ CSCP_BUFFER *pMsgBuffer;
+ CSCP_ENCRYPTION_CONTEXT *pCtx = NULL;
+ BYTE *pDecryptionBuffer = NULL;
+ int iErr;
+ char *xml;
+ WORD wFlags;
+
+ // Initialize raw message receiving function
+ pMsgBuffer = (CSCP_BUFFER *)malloc(sizeof(CSCP_BUFFER));
+ RecvNXCPMessage(0, NULL, pMsgBuffer, 0, NULL, NULL, 0);
+
+ pRawMsg = (CSCP_MESSAGE *)malloc(RAW_MSG_SIZE);
+#ifdef _WITH_ENCRYPTION
+ pDecryptionBuffer = (BYTE *)malloc(RAW_MSG_SIZE);
+#endif
+ while(1)
+ {
+ if ((iErr = RecvNXCPMessage((SOCKET)arg, pRawMsg, pMsgBuffer, RAW_MSG_SIZE,
+ &amp;pCtx, pDecryptionBuffer, INFINITE)) &lt;= 0)
+ {
+ break;
+ }
+
+ // Check if message is too large
+ if (iErr == 1)
+ {
+ printf(&quot;RECV ERROR: message is too large\n&quot;);
+ continue;
+ }
+
+ // Check for decryption failure
+ if (iErr == 2)
+ {
+ printf(&quot;RECV ERROR: decryption failure\n&quot;);
+ continue;
+ }
+
+ // Check that actual received packet size is equal to encoded in packet
+ if ((int)ntohl(pRawMsg-&gt;dwSize) != iErr)
+ {
+ printf(&quot;RECV ERROR: Actual message size doesn&#39;t match wSize value (%d,%d)\n&quot;, iErr, ntohl(pRawMsg-&gt;dwSize));
+ continue; // Bad packet, wait for next
+ }
+
+ wFlags = ntohs(pRawMsg-&gt;wFlags);
+ if (wFlags &amp; MF_BINARY)
+ {
+ printf(&quot;WARNING: Binary message received\n&quot;);
+ }
+ else
+ {
+ // Create message object from raw message
+ pMsg = new CSCPMessage(pRawMsg);
+ xml = pMsg-&gt;CreateXML();
+ if (xml != NULL)
+ {
+ puts(xml);
+ free(xml);
+ }
+ }
+ }
+ if (iErr &lt; 0)
+ printf(&quot;Session terminated (socket error %d)\n&quot;, WSAGetLastError());
+ free(pMsgBuffer);
+ free(pRawMsg);
+#ifdef _WITH_ENCRYPTION
+ free(pDecryptionBuffer);
+#endif
+
+ return THREAD_OK;
+}
+
+
+//
 // Read XML document from stdin
 //
 
@@ -73,6 +161,7 @@
         CSCPMessage *msg;
         CSCP_MESSAGE *rawMsg;
 
+ ThreadCreate(RecvThread, 0, (void *)hSocket);
         printf(&quot;Enter XML messages separated by %%%% string\n&quot;);
         while(1)
         {
@@ -84,6 +173,7 @@
                 SendEx(hSocket, rawMsg, ntohl(rawMsg-&gt;dwSize), 0);
                 free(rawMsg);
         }
+ shutdown(hSocket, 2);
 }
 
 
Received on Sat May 31 2008 - 13:08:28 EEST

This archive was generated by hypermail 2.2.0 : Sat May 31 2008 - 13:06:22 EEST