* { 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:3289
Author:victor
Date:2008-05-31 00:15:47 +0300 (Sat, 31 May 2008)
Comment:Implemented XML encoding for NXCP messages
Changes
A trunk/include/base64.h
U trunk/include/nms_util.h
U trunk/include/nxcpapi.h
U trunk/netxms.dsw
U trunk/src/libnetxms/Makefile.am
A trunk/src/libnetxms/base64.cpp
U trunk/src/libnetxms/libnetxms.dsp
U trunk/src/libnetxms/message.cpp
A trunk/src/libnetxms/xml.cpp
A trunk/src/nxcptest/
A trunk/src/nxcptest/Makefile.am
A trunk/src/nxcptest/nxcptest.cpp
A trunk/src/nxcptest/nxcptest.dsp
A trunk/src/nxcptest/nxcptest.dsw
A trunk/src/nxcptest/nxcptest.h
Diff
Added: trunk/include/base64.h
===================================================================
--- trunk/include/base64.h (rev 0)
+++ trunk/include/base64.h 2008-05-30 21:15:47 UTC (rev 3289)
@@ -0,0 +1,42 @@
+/* base64.h -- Encode binary data using printable characters.
+ Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
+ Written by Simon Josefsson.
+
+ 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
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#ifndef BASE64_H
+#define BASE64_H
+
+/* Get size_t. */
+#include <stddef.h>
+
+/* This uses that the expression (n+(k-1))/k means the smallest
+ integer >= n/k, i.e., the ceiling of n/k. */
+#define BASE64_LENGTH(inlen) ((((inlen) + 2) / 3) * 4)
+
+BOOL LIBNETXMS_EXPORTABLE isbase64 (char ch);
+
+void LIBNETXMS_EXPORTABLE base64_encode (const char *in, size_t inlen,
+ char *out, size_t outlen);
+
+size_t LIBNETXMS_EXPORTABLE base64_encode_alloc (const char *in, size_t inlen, char **out);
+
+BOOL LIBNETXMS_EXPORTABLE base64_decode (const char *in, size_t inlen,
+ char *out, size_t *outlen);
+
+BOOL LIBNETXMS_EXPORTABLE base64_decode_alloc (const char *in, size_t inlen,
+ char **out, size_t *outlen);
+
+#endif /* BASE64_H */
Modified: trunk/include/nms_util.h
===================================================================
--- trunk/include/nms_util.h 2008-05-26 21:46:43 UTC (rev 3288)
+++ trunk/include/nms_util.h 2008-05-30 21:15:47 UTC (rev 3289)
@@ -44,9 +44,11 @@
#include <byteswap.h>
#endif
+#include <base64.h>
+
//
-// Sirial communications
+// Serial communications
//
#ifdef _WIN32
@@ -483,6 +485,8 @@
BOOL LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsBool(const TCHAR *optString, const TCHAR *option, BOOL defVal);
long LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsInt(const TCHAR *optString, const TCHAR *option, long defVal);
+ TCHAR LIBNETXMS_EXPORTABLE *EscapeStringForXML(const TCHAR *string, int length);
+
#ifdef _WIN32
TCHAR LIBNETXMS_EXPORTABLE *GetSystemErrorText(DWORD dwError, TCHAR *pszBuffer, int iBufSize);
#endif
Modified: trunk/include/nxcpapi.h
===================================================================
--- trunk/include/nxcpapi.h 2008-05-26 21:46:43 UTC (rev 3288)
+++ trunk/include/nxcpapi.h 2008-05-30 21:15:47 UTC (rev 3289)
@@ -1,7 +1,7 @@
/*
** NetXMS - Network Management System
** NXCP API
-** Copyright (C) 2003, 2004 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
@@ -68,9 +68,13 @@
CSCPMessage(int nVersion = NXCP_VERSION);
CSCPMessage(CSCPMessage *pMsg);
CSCPMessage(CSCP_MESSAGE *pMsg, int nVersion = NXCP_VERSION);
+ CSCPMessage(char *xml);
~CSCPMessage();
CSCP_MESSAGE *CreateMessage(void);
+ char *CreateXML(void);
+ void ProcessXMLToken(void *state, const char **attrs);
+ void ProcessXMLData(void *state);
WORD GetCode(void) { return m_wCode; }
void SetCode(WORD wCode) { m_wCode = wCode; }
Modified: trunk/netxms.dsw
===================================================================
--- trunk/netxms.dsw 2008-05-26 21:46:43 UTC (rev 3288)
+++ trunk/netxms.dsw 2008-05-30 21:15:47 UTC (rev 3289)
@@ -483,6 +483,21 @@
###############################################################################
+Project: "nxcptest"=.\src\nxcptest\nxcptest.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+ Begin Project Dependency
+ Project_Dep_Name libnetxms
+ End Project Dependency
+}}}
+
+###############################################################################
+
Project: "nxdbmgr"=.\src\server\tools\nxdbmgr\nxdbmgr.dsp - Package Owner=<4>
Package=<5>
Modified: trunk/src/libnetxms/Makefile.am
===================================================================
--- trunk/src/libnetxms/Makefile.am 2008-05-26 21:46:43 UTC (rev 3288)
+++ trunk/src/libnetxms/Makefile.am 2008-05-30 21:15:47 UTC (rev 3289)
@@ -1,5 +1,5 @@
INCLUDES=-I_at_top_srcdir@/include
-SOURCES = 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
+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
if BUILD_UNICODE_LIBS
lib_LTLIBRARIES = libnetxms.la libnetxmsw.la
Added: trunk/src/libnetxms/base64.cpp
===================================================================
--- trunk/src/libnetxms/base64.cpp (rev 0)
+++ trunk/src/libnetxms/base64.cpp 2008-05-30 21:15:47 UTC (rev 3289)
@@ -0,0 +1,419 @@
+/* base64.c -- Encode binary data using printable characters.
+ Copyright (C) 1999, 2000, 2001, 2004, 2005, 2006 Free Software
+ Foundation, Inc.
+
+ 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
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+/* Written by Simon Josefsson. Partially adapted from GNU MailUtils
+ * (mailbox/filter_trans.c, as of 2004-11-28). Improved by review
+ * from Paul Eggert, Bruno Haible, and Stepan Kasal.
+ *
+ * See also RFC 3548 <http://www.ietf.org/rfc/rfc3548.txt>.
+ *
+ * Be careful with error checking. Here is how you would typically
+ * use these functions:
+ *
+ * BOOL ok = base64_decode_alloc (in, inlen, &out, &outlen);
+ * if (!ok)
+ * FAIL: input was not valid base64
+ * if (out == NULL)
+ * FAIL: memory allocation error
+ * OK: data in OUT/OUTLEN
+ *
+ * size_t outlen = base64_encode_alloc (in, inlen, &out);
+ * if (out == NULL && outlen == 0 && inlen != 0)
+ * FAIL: input too long
+ * if (out == NULL)
+ * FAIL: memory allocation error
+ * OK: data in OUT/OUTLEN.
+ *
+ */
+
+#include "libnetxms.h"
+
+/* Get UCHAR_MAX. */
+#include <limits.h>
+
+/* C89 compliant way to cast 'char' to 'unsigned char'. */
+static inline unsigned char
+to_uchar (char ch)
+{
+ return ch;
+}
+
+/* Base64 encode IN array of size INLEN into OUT array of size OUTLEN.
+ If OUTLEN is less than BASE64_LENGTH(INLEN), write as many bytes as
+ possible. If OUTLEN is larger than BASE64_LENGTH(INLEN), also zero
+ terminate the output buffer. */
+void LIBNETXMS_EXPORTABLE
+base64_encode (const char *in, size_t inlen,
+ char *out, size_t outlen)
+{
+ static const char b64str[65] =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+ while (inlen && outlen)
+ {
+ *out++ = b64str[(to_uchar (in[0]) >> 2) & 0x3f];
+ if (!--outlen)
+ break;
+ *out++ = b64str[((to_uchar (in[0]) << 4)
+ + (--inlen ? to_uchar (in[1]) >> 4 : 0))
+ & 0x3f];
+ if (!--outlen)
+ break;
+ *out++ =
+ (inlen
+ ? b64str[((to_uchar (in[1]) << 2)
+ + (--inlen ? to_uchar (in[2]) >> 6 : 0))
+ & 0x3f]
+ : '=');
+ if (!--outlen)
+ break;
+ *out++ = inlen ? b64str[to_uchar (in[2]) & 0x3f] : '=';
+ if (!--outlen)
+ break;
+ if (inlen)
+ inlen--;
+ if (inlen)
+ in += 3;
+ }
+
+ if (outlen)
+ *out = '\0';
+}
+
+/* Allocate a buffer and store zero terminated base64 encoded data
+ from array IN of size INLEN, returning BASE64_LENGTH(INLEN), i.e.,
+ the length of the encoded data, excluding the terminating zero. On
+ return, the OUT variable will hold a pointer to newly allocated
+ memory that must be deallocated by the caller. If output string
+ length would overflow, 0 is returned and OUT is set to NULL. If
+ memory allocation failed, OUT is set to NULL, and the return value
+ indicates length of the requested memory block, i.e.,
+ BASE64_LENGTH(inlen) + 1. */
+size_t LIBNETXMS_EXPORTABLE
+base64_encode_alloc (const char *in, size_t inlen, char **out)
+{
+ size_t outlen = 1 + BASE64_LENGTH (inlen);
+
+ /* Check for overflow in outlen computation.
+ *
+ * If there is no overflow, outlen >= inlen.
+ *
+ * If the operation (inlen + 2) overflows then it yields at most +1, so
+ * outlen is 0.
+ *
+ * If the multiplication overflows, we lose at least half of the
+ * correct value, so the result is < ((inlen + 2) / 3) * 2, which is
+ * less than (inlen + 2) * 0.66667, which is less than inlen as soon as
+ * (inlen > 4).
+ */
+ if (inlen > outlen)
+ {
+ *out = NULL;
+ return 0;
+ }
+
+ *out = (char *)malloc (outlen);
+ if (!*out)
+ return outlen;
+
+ base64_encode (in, inlen, *out, outlen);
+
+ return outlen - 1;
+}
+
+/* With this approach this file works independent of the charset used
+ (think EBCDIC). However, it does assume that the characters in the
+ Base64 alphabet (A-Za-z0-9+/) are encoded in 0..255. POSIX
+ 1003.1-2001 require that char and unsigned char are 8-bit
+ quantities, though, taking care of that problem. But this may be a
+ potential problem on non-POSIX C99 platforms.
+
+ IBM C V6 for AIX mishandles "#define B64(x) ...'x'...", so use "_"
+ as the formal parameter rather than "x". */
+#define B64(_) \
+ ((_) == 'A' ? 0 \
+ : (_) == 'B' ? 1 \
+ : (_) == 'C' ? 2 \
+ : (_) == 'D' ? 3 \
+ : (_) == 'E' ? 4 \
+ : (_) == 'F' ? 5 \
+ : (_) == 'G' ? 6 \
+ : (_) == 'H' ? 7 \
+ : (_) == 'I' ? 8 \
+ : (_) == 'J' ? 9 \
+ : (_) == 'K' ? 10 \
+ : (_) == 'L' ? 11 \
+ : (_) == 'M' ? 12 \
+ : (_) == 'N' ? 13 \
+ : (_) == 'O' ? 14 \
+ : (_) == 'P' ? 15 \
+ : (_) == 'Q' ? 16 \
+ : (_) == 'R' ? 17 \
+ : (_) == 'S' ? 18 \
+ : (_) == 'T' ? 19 \
+ : (_) == 'U' ? 20 \
+ : (_) == 'V' ? 21 \
+ : (_) == 'W' ? 22 \
+ : (_) == 'X' ? 23 \
+ : (_) == 'Y' ? 24 \
+ : (_) == 'Z' ? 25 \
+ : (_) == 'a' ? 26 \
+ : (_) == 'b' ? 27 \
+ : (_) == 'c' ? 28 \
+ : (_) == 'd' ? 29 \
+ : (_) == 'e' ? 30 \
+ : (_) == 'f' ? 31 \
+ : (_) == 'g' ? 32 \
+ : (_) == 'h' ? 33 \
+ : (_) == 'i' ? 34 \
+ : (_) == 'j' ? 35 \
+ : (_) == 'k' ? 36 \
+ : (_) == 'l' ? 37 \
+ : (_) == 'm' ? 38 \
+ : (_) == 'n' ? 39 \
+ : (_) == 'o' ? 40 \
+ : (_) == 'p' ? 41 \
+ : (_) == 'q' ? 42 \
+ : (_) == 'r' ? 43 \
+ : (_) == 's' ? 44 \
+ : (_) == 't' ? 45 \
+ : (_) == 'u' ? 46 \
+ : (_) == 'v' ? 47 \
+ : (_) == 'w' ? 48 \
+ : (_) == 'x' ? 49 \
+ : (_) == 'y' ? 50 \
+ : (_) == 'z' ? 51 \
+ : (_) == '0' ? 52 \
+ : (_) == '1' ? 53 \
+ : (_) == '2' ? 54 \
+ : (_) == '3' ? 55 \
+ : (_) == '4' ? 56 \
+ : (_) == '5' ? 57 \
+ : (_) == '6' ? 58 \
+ : (_) == '7' ? 59 \
+ : (_) == '8' ? 60 \
+ : (_) == '9' ? 61 \
+ : (_) == '+' ? 62 \
+ : (_) == '/' ? 63 \
+ : -1)
+
+static const signed char b64[0x100] = {
+ B64 (0), B64 (1), B64 (2), B64 (3),
+ B64 (4), B64 (5), B64 (6), B64 (7),
+ B64 (8), B64 (9), B64 (10), B64 (11),
+ B64 (12), B64 (13), B64 (14), B64 (15),
+ B64 (16), B64 (17), B64 (18), B64 (19),
+ B64 (20), B64 (21), B64 (22), B64 (23),
+ B64 (24), B64 (25), B64 (26), B64 (27),
+ B64 (28), B64 (29), B64 (30), B64 (31),
+ B64 (32), B64 (33), B64 (34), B64 (35),
+ B64 (36), B64 (37), B64 (38), B64 (39),
+ B64 (40), B64 (41), B64 (42), B64 (43),
+ B64 (44), B64 (45), B64 (46), B64 (47),
+ B64 (48), B64 (49), B64 (50), B64 (51),
+ B64 (52), B64 (53), B64 (54), B64 (55),
+ B64 (56), B64 (57), B64 (58), B64 (59),
+ B64 (60), B64 (61), B64 (62), B64 (63),
+ B64 (64), B64 (65), B64 (66), B64 (67),
+ B64 (68), B64 (69), B64 (70), B64 (71),
+ B64 (72), B64 (73), B64 (74), B64 (75),
+ B64 (76), B64 (77), B64 (78), B64 (79),
+ B64 (80), B64 (81), B64 (82), B64 (83),
+ B64 (84), B64 (85), B64 (86), B64 (87),
+ B64 (88), B64 (89), B64 (90), B64 (91),
+ B64 (92), B64 (93), B64 (94), B64 (95),
+ B64 (96), B64 (97), B64 (98), B64 (99),
+ B64 (100), B64 (101), B64 (102), B64 (103),
+ B64 (104), B64 (105), B64 (106), B64 (107),
+ B64 (108), B64 (109), B64 (110), B64 (111),
+ B64 (112), B64 (113), B64 (114), B64 (115),
+ B64 (116), B64 (117), B64 (118), B64 (119),
+ B64 (120), B64 (121), B64 (122), B64 (123),
+ B64 (124), B64 (125), B64 (126), B64 (127),
+ B64 (128), B64 (129), B64 (130), B64 (131),
+ B64 (132), B64 (133), B64 (134), B64 (135),
+ B64 (136), B64 (137), B64 (138), B64 (139),
+ B64 (140), B64 (141), B64 (142), B64 (143),
+ B64 (144), B64 (145), B64 (146), B64 (147),
+ B64 (148), B64 (149), B64 (150), B64 (151),
+ B64 (152), B64 (153), B64 (154), B64 (155),
+ B64 (156), B64 (157), B64 (158), B64 (159),
+ B64 (160), B64 (161), B64 (162), B64 (163),
+ B64 (164), B64 (165), B64 (166), B64 (167),
+ B64 (168), B64 (169), B64 (170), B64 (171),
+ B64 (172), B64 (173), B64 (174), B64 (175),
+ B64 (176), B64 (177), B64 (178), B64 (179),
+ B64 (180), B64 (181), B64 (182), B64 (183),
+ B64 (184), B64 (185), B64 (186), B64 (187),
+ B64 (188), B64 (189), B64 (190), B64 (191),
+ B64 (192), B64 (193), B64 (194), B64 (195),
+ B64 (196), B64 (197), B64 (198), B64 (199),
+ B64 (200), B64 (201), B64 (202), B64 (203),
+ B64 (204), B64 (205), B64 (206), B64 (207),
+ B64 (208), B64 (209), B64 (210), B64 (211),
+ B64 (212), B64 (213), B64 (214), B64 (215),
+ B64 (216), B64 (217), B64 (218), B64 (219),
+ B64 (220), B64 (221), B64 (222), B64 (223),
+ B64 (224), B64 (225), B64 (226), B64 (227),
+ B64 (228), B64 (229), B64 (230), B64 (231),
+ B64 (232), B64 (233), B64 (234), B64 (235),
+ B64 (236), B64 (237), B64 (238), B64 (239),
+ B64 (240), B64 (241), B64 (242), B64 (243),
+ B64 (244), B64 (245), B64 (246), B64 (247),
+ B64 (248), B64 (249), B64 (250), B64 (251),
+ B64 (252), B64 (253), B64 (254), B64 (255)
+};
+
+#if UCHAR_MAX == 255
+# define uchar_in_range(c) true
+#else
+# define uchar_in_range(c) ((c) <= 255)
+#endif
+
+/* Return true if CH is a character from the Base64 alphabet, and
+ false otherwise. Note that '=' is padding and not considered to be
+ part of the alphabet. */
+BOOL LIBNETXMS_EXPORTABLE
+isbase64 (char ch)
+{
+ return uchar_in_range (to_uchar (ch)) && 0 <= b64[to_uchar (ch)];
+}
+
+/* Decode base64 encoded input array IN of length INLEN to output
+ array OUT that can hold *OUTLEN bytes. Return true if decoding was
+ successful, i.e. if the input was valid base64 data, false
+ otherwise. If *OUTLEN is too small, as many bytes as possible will
+ be written to OUT. On return, *OUTLEN holds the length of decoded
+ bytes in OUT. Note that as soon as any non-alphabet characters are
+ encountered, decoding is stopped and false is returned. This means
+ that, when applicable, you must remove any line terminators that is
+ part of the data stream before calling this function. */
+BOOL LIBNETXMS_EXPORTABLE
+base64_decode (const char *in, size_t inlen,
+ char *out, size_t *outlen)
+{
+ size_t outleft = *outlen;
+
+ while (inlen >= 2)
+ {
+ if (!isbase64 (in[0]) || !isbase64 (in[1]))
+ break;
+
+ if (outleft)
+ {
+ *out++ = ((b64[to_uchar (in[0])] << 2)
+ | (b64[to_uchar (in[1])] >> 4));
+ outleft--;
+ }
+
+ if (inlen == 2)
+ break;
+
+ if (in[2] == '=')
+ {
+ if (inlen != 4)
+ break;
+
+ if (in[3] != '=')
+ break;
+
+ }
+ else
+ {
+ if (!isbase64 (in[2]))
+ break;
+
+ if (outleft)
+ {
+ *out++ = (((b64[to_uchar (in[1])] << 4) & 0xf0)
+ | (b64[to_uchar (in[2])] >> 2));
+ outleft--;
+ }
+
+ if (inlen == 3)
+ break;
+
+ if (in[3] == '=')
+ {
+ if (inlen != 4)
+ break;
+ }
+ else
+ {
+ if (!isbase64 (in[3]))
+ break;
+
+ if (outleft)
+ {
+ *out++ = (((b64[to_uchar (in[2])] << 6) & 0xc0)
+ | b64[to_uchar (in[3])]);
+ outleft--;
+ }
+ }
+ }
+
+ in += 4;
+ inlen -= 4;
+ }
+
+ *outlen -= outleft;
+
+ if (inlen != 0)
+ return false;
+
+ return true;
+}
+
+/* Allocate an output buffer in *OUT, and decode the base64 encoded
+ data stored in IN of size INLEN to the *OUT buffer. On return, the
+ size of the decoded data is stored in *OUTLEN. OUTLEN may be NULL,
+ if the caller is not interested in the decoded length. *OUT may be
+ NULL to indicate an out of memory error, in which case *OUTLEN
+ contains the size of the memory block needed. The function returns
+ true on successful decoding and memory allocation errors. (Use the
+ *OUT and *OUTLEN parameters to differentiate between successful
+ decoding and memory error.) The function returns false if the
+ input was invalid, in which case *OUT is NULL and *OUTLEN is
+ undefined. */
+BOOL LIBNETXMS_EXPORTABLE
+base64_decode_alloc (const char *in, size_t inlen, char **out,
+ size_t *outlen)
+{
+ /* This may allocate a few bytes too much, depending on input,
+ but it's not worth the extra CPU time to compute the exact amount.
+ The exact amount is 3 * inlen / 4, minus 1 if the input ends
+ with "=" and minus another 1 if the input ends with "==".
+ Dividing before multiplying avoids the possibility of overflow. */
+ size_t needlen = 3 * (inlen / 4) + 2;
+
+ *out = (char *)malloc (needlen);
+ if (!*out)
+ return true;
+
+ if (!base64_decode (in, inlen, *out, &needlen))
+ {
+ free (*out);
+ *out = NULL;
+ return false;
+ }
+
+ if (outlen)
+ *outlen = needlen;
+
+ return true;
+}
Modified: trunk/src/libnetxms/libnetxms.dsp
===================================================================
--- trunk/src/libnetxms/libnetxms.dsp 2008-05-26 21:46:43 UTC (rev 3288)
+++ trunk/src/libnetxms/libnetxms.dsp 2008-05-30 21:15:47 UTC (rev 3289)
@@ -57,7 +57,7 @@
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib libeay32.lib dbghelp.lib crypt32.lib /nologo /version:0.2 /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib libeay32.lib dbghelp.lib crypt32.lib libexpat.lib /nologo /version:0.2 /dll /debug /machine:I386 /pdbtype:sept
# Begin Special Build Tool
SOURCE="$(InputPath)"
PostBuild_Desc=Copy files
@@ -88,7 +88,7 @@
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib libeay32.lib dbghelp.lib crypt32.lib /nologo /version:0.1 /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib libeay32.lib dbghelp.lib crypt32.lib libexpat.lib /nologo /version:0.1 /dll /debug /machine:I386 /pdbtype:sept
# SUBTRACT LINK32 /pdb:none
# Begin Special Build Tool
SOURCE="$(InputPath)"
@@ -188,7 +188,7 @@
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib /nologo /version:0.1 /dll /debug /machine:I386 /pdbtype:sept
# SUBTRACT BASE LINK32 /pdb:none
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib libeay32.lib dbghelp.lib crypt32.lib /nologo /version:0.1 /dll /debug /machine:I386 /out:"Debug_UNICODE/libnetxmsw.dll" /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib libeay32.lib dbghelp.lib crypt32.lib libexpatw.lib /nologo /version:0.1 /dll /debug /machine:I386 /out:"Debug_UNICODE/libnetxmsw.dll" /pdbtype:sept
# SUBTRACT LINK32 /pdb:none
# Begin Special Build Tool
SOURCE="$(InputPath)"
@@ -221,7 +221,7 @@
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib ntdll.lib /nologo /version:0.1 /dll /machine:I386
-# ADD LINK32 gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib libeay32.lib dbghelp.lib crypt32.lib /nologo /version:0.1 /dll /debug /machine:I386 /out:"Release_UNICODE/libnetxmsw.dll" /pdbtype:sept
+# ADD LINK32 gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib libeay32.lib dbghelp.lib crypt32.lib libexpatw.lib /nologo /version:0.1 /dll /debug /machine:I386 /out:"Release_UNICODE/libnetxmsw.dll" /pdbtype:sept
# Begin Special Build Tool
SOURCE="$(InputPath)"
PostBuild_Desc=Copy files
@@ -243,6 +243,10 @@
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
+SOURCE=.\base64.cpp
+# End Source File
+# Begin Source File
+
SOURCE=.\config.cpp
# End Source File
# Begin Source File
@@ -365,12 +369,20 @@
SOURCE=.\uuid.c
# End Source File
+# Begin Source File
+
+SOURCE=.\xml.cpp
+# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
+SOURCE=..\..\include\base64.h
+# End Source File
+# Begin Source File
+
SOURCE=.\libnetxms.h
# End Source File
# Begin Source File
Modified: trunk/src/libnetxms/message.cpp
===================================================================
--- trunk/src/libnetxms/message.cpp 2008-05-26 21:46:43 UTC (rev 3288)
+++ trunk/src/libnetxms/message.cpp 2008-05-30 21:15:47 UTC (rev 3289)
@@ -2,7 +2,7 @@
/*
** NetXMS - Network Management System
** NetXMS Foundation Library
-** 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
@@ -23,9 +23,33 @@
**/
#include "libnetxms.h"
+#include <expat.h>
//
+// Parser state for creating CSCPMessage object from XML
+//
+
+#define XML_STATE_INIT -1
+#define XML_STATE_END -2
+#define XML_STATE_ERROR -255
+#define XML_STATE_NXCP 0
+#define XML_STATE_MESSAGE 1
+#define XML_STATE_VARIABLE 2
+#define XML_STATE_VALUE 3
+
+typedef struct
+{
+ CSCPMessage *msg;
+ int state;
+ int valueLen;
+ char *value;
+ int varType;
+ DWORD varId;
+} XML_PARSER_STATE;
+
+
+//
// Calculate variable size
//
@@ -177,6 +201,214 @@
//
+// Create CSCPMessage object from XML document
+//
+
+static void StartElement(void *userData, const char *name, const char **attrs)
+{
+ if (!strcmp(name, "nxcp"))
+ {
+ ((XML_PARSER_STATE *)userData)->state = XML_STATE_NXCP;
+ }
+ else if (!strcmp(name, "message"))
+ {
+ ((XML_PARSER_STATE *)userData)->state = XML_STATE_MESSAGE;
+ }
+ else if (!strcmp(name, "variable"))
+ {
+ ((XML_PARSER_STATE *)userData)->state = XML_STATE_VARIABLE;
+ }
+ else if (!strcmp(name, "value"))
+ {
+ ((XML_PARSER_STATE *)userData)->valueLen = 1;
+ ((XML_PARSER_STATE *)userData)->value = NULL;
+ ((XML_PARSER_STATE *)userData)->state = XML_STATE_VALUE;
+ }
+ else
+ {
+ ((XML_PARSER_STATE *)userData)->state = XML_STATE_ERROR;
+ }
+ if (((XML_PARSER_STATE *)userData)->state != XML_STATE_ERROR)
+ ((XML_PARSER_STATE *)userData)->msg->ProcessXMLToken(userData, attrs);
+}
+
+static void EndElement(void *userData, const char *name)
+{
+ if (!strcmp(name, "nxcp"))
+ {
+ ((XML_PARSER_STATE *)userData)->state = XML_STATE_END;
+ }
+ else if (!strcmp(name, "message"))
+ {
+ ((XML_PARSER_STATE *)userData)->state = XML_STATE_NXCP;
+ }
+ else if (!strcmp(name, "variable"))
+ {
+ ((XML_PARSER_STATE *)userData)->state = XML_STATE_MESSAGE;
+ }
+ else if (!strcmp(name, "value"))
+ {
+ ((XML_PARSER_STATE *)userData)->msg->ProcessXMLData(userData);
+ safe_free(((XML_PARSER_STATE *)userData)->value);
+ ((XML_PARSER_STATE *)userData)->state = XML_STATE_VARIABLE;
+ }
+}
+
+static void CharData(void *userData, const XML_Char *s, int len)
+{
+ XML_PARSER_STATE *ps = (XML_PARSER_STATE *)userData;
+
+ if (ps->state != XML_STATE_VALUE)
+ return;
+
+ ps->value = (char *)realloc(ps->value, ps->valueLen + len);
+ memcpy(&ps->value[ps->valueLen - 1], s, len);
+ ps->valueLen += len;
+ ps->value[ps->valueLen - 1] = 0;
+}
+
+CSCPMessage::CSCPMessage(char *xml)
+{
+ XML_Parser parser = XML_ParserCreate(NULL);
+ XML_PARSER_STATE state;
+
+ // Default values
+ m_wCode = 0;
+ m_dwId = 0;
+ m_dwNumVar = 0;
+ m_ppVarList = NULL;
+ m_wFlags = 0;
+ m_nVersion = NXCP_VERSION;
+
+ // Parse XML
+ state.msg = this;
+ state.state = -1;
+ XML_SetUserData(parser, &state);
+ XML_SetElementHandler(parser, StartElement, EndElement);
+ XML_SetCharacterDataHandler(parser, CharData);
+ if (XML_Parse(parser, xml, strlen(xml), TRUE) == XML_STATUS_ERROR)
+ {
+fprintf(stderr,
+ "%s at line %d\n",
+ XML_ErrorString(XML_GetErrorCode(parser)),
+ XML_GetCurrentLineNumber(parser));
+ }
+ XML_ParserFree(parser);
+}
+
+static const char *GetAttr(const char **attrs, const char *name)
+{
+ int i;
+
+ for(i = 0; attrs[i] != NULL; i += 2)
+ {
+ if (!stricmp(attrs[i], name))
+ return attrs[i + 1];
+ }
+ return NULL;
+}
+
+static int GetAttrInt(const char **attrs, const char *name, int defVal)
+{
+ const char *value;
+
+ value = GetAttr(attrs, name);
+ return (value != NULL) ? strtol(value, NULL, 0) : defVal;
+}
+
+static int GetAttrDWORD(const char **attrs, const char *name, DWORD defVal)
+{
+ const char *value;
+
+ value = GetAttr(attrs, name);
+ return (value != NULL) ? strtoul(value, NULL, 0) : defVal;
+}
+
+void CSCPMessage::ProcessXMLToken(void *state, const char **attrs)
+{
+ XML_PARSER_STATE *ps = (XML_PARSER_STATE *)state;
+ const char *type;
+ static const char *types[] = { "int32", "string", "int64", "int16", "binary", "float", NULL };
+
+ switch(ps->state)
+ {
+ case XML_STATE_NXCP:
+ m_nVersion = GetAttrInt(attrs, "version", m_nVersion);
+ break;
+ case XML_STATE_MESSAGE:
+ m_dwId = GetAttrDWORD(attrs, "id", m_dwId);
+ m_wCode = (WORD)GetAttrDWORD(attrs, "code", m_wCode);
+ break;
+ case XML_STATE_VARIABLE:
+ ps->varId = GetAttrDWORD(attrs, "id", 0);
+ type = GetAttr(attrs, "type");
+ if (type != NULL)
+ {
+ int i;
+
+ for(i = 0; types[i] != NULL; i++)
+ if (!stricmp(types[i], type))
+ {
+ ps->varType = i;
+ break;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void CSCPMessage::ProcessXMLData(void *state)
+{
+ XML_PARSER_STATE *ps = (XML_PARSER_STATE *)state;
+ char *binData;
+ size_t binLen;
+#ifdef UNICODE
+ WCHAR *temp;
+#endif
+
+ if (ps->value == NULL)
+ return;
+
+ switch(ps->varType)
+ {
+ case CSCP_DT_INTEGER:
+ SetVariable(ps->varId, strtoul(ps->value, NULL, 0));
+ break;
+ case CSCP_DT_INT16:
+ SetVariable(ps->varId, (WORD)strtoul(ps->value, NULL, 0));
+ break;
+ case CSCP_DT_INT64:
+ SetVariable(ps->varId, strtoull(ps->value, NULL, 0));
+ break;
+ case CSCP_DT_FLOAT:
+ SetVariable(ps->varId, strtod(ps->value, NULL));
+ break;
+ case CSCP_DT_STRING:
+#ifdef UNICODE
+ temp = WideStringFromUTF8String(ps->value);
+ SetVariable(ps->varId, temp);
+ free(temp);
+#else
+ SetVariable(ps->varId, ps->value);
+#endif
+ break;
+ case CSCP_DT_BINARY:
+ if (base64_decode_alloc(ps->value, ps->valueLen, &binData, &binLen))
+ {
+ if (binData != NULL)
+ {
+ SetVariable(ps->varId, (BYTE *)binData, binLen);
+ free(binData);
+ }
+ }
+ break;
+ }
+}
+
+
+//
// Destructor for CSCPMessage
//
@@ -615,3 +847,82 @@
}
return bResult;
}
+
+
+//
+// Create XML document
+//
+
+char *CSCPMessage::CreateXML(void)
+{
+ String xml;
+ DWORD i;
+ char *out, *bdata;
+ size_t blen;
+#ifdef UNICODE
+ WCHAR *tempStr;
+#else
+ int bytes;
+ char *tempStr;
+#endif
+ static const TCHAR *dtString[] = { _T("int32"), _T("string"), _T("int64"), _T("int16"), _T("binary"), _T("float") };
+
+ xml.AddFormattedString(_T("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<nxcp version=\"%d\">\r\n <message code=\"%s\" id=\"%d\">\r\n"), m_nVersion, m_wCode, m_dwId);
+ for(i = 0; i < m_dwNumVar; i++)
+ {
+ xml.AddFormattedString(_T(" <variable id=\"%d\" type=\"%s\">\r\n <value>"),
+ m_ppVarList[i]->dwVarId, dtString[m_ppVarList[i]->bType]);
+ switch(m_ppVarList[i]->bType)
+ {
+ case CSCP_DT_INTEGER:
+ xml.AddFormattedString(_T("%d"), m_ppVarList[i]->data.dwInteger);
+ break;
+ case CSCP_DT_INT16:
+ xml.AddFormattedString(_T("%d"), m_ppVarList[i]->wInt16);
+ break;
+ case CSCP_DT_INT64:
+ xml.AddFormattedString(INT64_FMT, m_ppVarList[i]->data.qwInt64);
+ break;
+ case CSCP_DT_STRING:
+#ifdef UNICODE
+ xml.AddDynamicString(EscapeStringForXML(m_ppVarList[i]->data.string.szValue, m_ppVarList[i]->data.string.dwLen));
+#else
+ bytes = WideCharToMultiByte(CP_UTF8, 0, m_ppVarList[i]->data.string.szValue,
+ m_ppVarList[i]->data.string.dwLen, NULL, 0, NULL, NULL);
+ tempStr = (char *)malloc(bytes + 1);
+ bytes = WideCharToMultiByte(CP_UTF8, 0, m_ppVarList[i]->data.string.szValue,
+ m_ppVarList[i]->data.string.dwLen, tempStr, bytes + 1, NULL, NULL);
+ xml.AddDynamicString(EscapeStringForXML(tempStr, bytes));
+ free(tempStr);
+#endif
+ break;
+ case CSCP_DT_BINARY:
+ blen = base64_encode_alloc((char *)m_ppVarList[i]->data.string.szValue,
+ m_ppVarList[i]->data.string.dwLen, &bdata);
+ if ((blen != 0) && (bdata != NULL))
+ {
+#ifdef UNICODE
+ tempStr = (WCHAR *)malloc((blen + 1) * sizeof(WCHAR));
+ MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, bdata, blen, tempStr, blen);
+ tempStr[blen] = 0;
+ xml.AddDynamicString(tempStr);
+#else
+ xml.AddString(bdata, blen);
+#endif
+ }
+ safe_free(bdata);
+ break;
+ default:
+ break;
+ }
+ xml += _T(" </value>\r\n </variable>\r\n");
+ }
+ xml += _T(" </message>\r\n</nxcp>\r\n");
+
+#ifdef UNICODE
+ out = UTF8StringFromWideString(xml);
+#else
+ out = strdup(xml);
+#endif
+ return out;
+}
Added: trunk/src/libnetxms/xml.cpp
===================================================================
--- trunk/src/libnetxms/xml.cpp (rev 0)
+++ trunk/src/libnetxms/xml.cpp 2008-05-30 21:15:47 UTC (rev 3289)
@@ -0,0 +1,76 @@
+/* $Id$ */
+/*
+** NetXMS - Network Management System
+** 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
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: xml.cpp
+**
+**/
+
+#include "libnetxms.h"
+
+
+//
+// Encode string for XML
+//
+
+TCHAR LIBNETXMS_EXPORTABLE *EscapeStringForXML(const TCHAR *string, int length)
+{
+ TCHAR *out;
+ const TCHAR *in;
+ int inLen, outLen, pos;
+
+ // Calculate length
+ inLen = (length == -1) ? _tcslen(string) : length;
+ for(in = string, outLen = 0; (inLen > 0) && (*in != 0); in++, outLen++, inLen--)
+ if ((*in == _T('&')) || (*in == _T('<')) ||
+ (*in == _T('>')) || (*in == _T('"')))
+ outLen += 5;
+ outLen++;
+
+ // Convert string
+ out = (TCHAR *)malloc(outLen * sizeof(TCHAR));
+ inLen = (length == -1) ? _tcslen(string) : length;
+ for(in = string, pos = 0; inLen > 0; in++, inLen--)
+ {
+ switch(*in)
+ {
+ case _T('&'):
+ _tcscat(&out[pos], _T("&amp;"));
+ pos += 5;
+ break;
+ case _T('<'):
+ _tcscat(&out[pos], _T("&lt;"));
+ pos += 4;
+ break;
+ case _T('>'):
+ _tcscat(&out[pos], _T("&gt;"));
+ pos += 4;
+ break;
+ case _T('"'):
+ _tcscat(&out[pos], _T("&quot;"));
+ pos += 6;
+ break;
+ default:
+ out[pos++] = *in;
+ break;
+ }
+ }
+ out[pos] = 0;
+
+ return out;
+}
Added: trunk/src/nxcptest/Makefile.am
===================================================================
--- trunk/src/nxcptest/Makefile.am (rev 0)
+++ trunk/src/nxcptest/Makefile.am 2008-05-30 21:15:47 UTC (rev 3289)
@@ -0,0 +1,17 @@
+# Copyright (C) 2004 NetXMS Team <bugs_at_netxms.org>
+#
+# This file is free software; as a special exception the author gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+INCLUDES=-I_at_top_srcdir@/include
+
+bin_PROGRAMS = nxcptest
+nxcptest_SOURCES = nxcptest.cpp
+nxcptest_LDADD = ../libnetxms/libnetxms.la
+
+EXTRA_DIST = nxcptest.dsp nxcptest.dsw nxcptest.h
Added: trunk/src/nxcptest/nxcptest.cpp
===================================================================
--- trunk/src/nxcptest/nxcptest.cpp (rev 0)
+++ trunk/src/nxcptest/nxcptest.cpp 2008-05-30 21:15:47 UTC (rev 3289)
@@ -0,0 +1,171 @@
+/* $Id: nxscript.cpp 3272 2008-05-14 01:40:18Z alk $ */
+/*
+** NetXMS - Network Management System
+** NetXMS Scripting Host
+** Copyright (C) 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
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: nxcptest.cpp
+**
+**/
+
+#include "nxcptest.h"
+
+
+//
+// Help text
+//
+
+static char m_szHelpText[] =
+ "NetXMS Communication Protocol Tester Version " NETXMS_VERSION_STRING "\n"
+ "Copyright (c) 2008 Victor Kirhenshtein\n\n"
+ "Usage:\n"
+ " nxcptest [options] host\n\n"
+ "Where valid options are:\n"
+ " -h : Show this help\n"
+ " -p port : Port to connect (default 4700)\n"
+ " -v : Show version and exit\n"
+ "\n";
+
+
+//
+// Read XML document from stdin
+//
+
+static BOOL ReadXML(String &xml)
+{
+ char buffer[8192];
+
+ xml = "";
+ while(1)
+ {
+ fgets(buffer, 8192, stdin);
+ if (feof(stdin))
+ return FALSE;
+ if (!strcmp(buffer, "%%\n"))
+ break;
+ xml += buffer;
+ }
+ return TRUE;
+}
+
+
+//
+// Do protocol excahnge
+//
+
+static void Exchange(SOCKET hSocket)
+{
+ String xml;
+ CSCPMessage *msg;
+ CSCP_MESSAGE *rawMsg;
+
+ printf("Enter XML messages separated by %%%% string\n");
+ while(1)
+ {
+ if (!ReadXML(xml))
+ break;
+ msg = new CSCPMessage(xml);
+ rawMsg = msg->CreateMessage();
+ delete msg;
+ SendEx(hSocket, rawMsg, ntohl(rawMsg->dwSize), 0);
+ free(rawMsg);
+ }
+}
+
+
+//
+// main()
+//
+
+int main(int argc, char *argv[])
+{
+ struct sockaddr_in sa;
+ int port = 4700, ch;
+ SOCKET hSocket;
+
+ // Parse command line
+ opterr = 1;
+ while((ch = getopt(argc, argv, "hp:v")) != -1)
+ {
+ switch(ch)
+ {
+ case 'h':
+ printf(m_szHelpText);
+ return 0;
+ case 'v':
+ printf("NetXMS Communication Protocol Tester Version " NETXMS_VERSION_STRING "\n"
+ "Copyright (c) 2008 Victor Kirhenshtein\n\n");
+ return 0;
+ case 'p':
+ port = strtol(optarg, NULL, 0);
+ break;
+ case '?':
+ return 1;
+ default:
+ break;
+ }
+ }
+
+ if (argc - optind < 1)
+ {
+ printf("Required arguments missing\n");
+ return 1;
+ }
+
+#ifdef _WIN32
+ WSADATA wsaData;
+
+ if (WSAStartup(2, &wsaData) != 0)
+ {
+ _tprintf(_T("Unable to initialize Windows sockets\n"));
+ return 4;
+ }
+#endif
+
+ // Create socket
+ hSocket = socket(AF_INET, SOCK_STREAM, 0);
+ if (hSocket == -1)
+ {
+ printf("Call to socket() failed");
+ goto connect_cleanup;
+ }
+
+ // Fill in address structure
+ memset(&sa, 0, sizeof(sa));
+ sa.sin_family = AF_INET;
+ sa.sin_addr.s_addr = ResolveHostName(argv[optind]);
+ sa.sin_port = htons((WORD)port);
+ if ((sa.sin_addr.s_addr == INADDR_ANY) || (sa.sin_addr.s_addr == INADDR_NONE))
+ {
+ printf("Cannot resolve host name or invalid IP address\n");
+ goto connect_cleanup;
+ }
+
+ // Connect to server
+ if (connect(hSocket, (struct sockaddr *)&sa, sizeof(sa)) == -1)
+ {
+ printf("Cannot establish connection with %s:%d\n", argv[optind], port);
+ goto connect_cleanup;
+ }
+
+ Exchange(hSocket);
+
+connect_cleanup:
+ if (hSocket != -1)
+ closesocket(hSocket);
+ return 0;
+}
Added: trunk/src/nxcptest/nxcptest.dsp
===================================================================
--- trunk/src/nxcptest/nxcptest.dsp (rev 0)
+++ trunk/src/nxcptest/nxcptest.dsp 2008-05-30 21:15:47 UTC (rev 3289)
@@ -0,0 +1,144 @@
+# Microsoft Developer Studio Project File - Name="nxcptest" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=nxcptest - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "nxcptest.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "nxcptest.mak" CFG="nxcptest - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "nxcptest - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "nxcptest - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "nxcptest - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /O2 /I "..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libnetxms.lib libnxsl.lib ws2_32.lib /nologo /subsystem:console /machine:I386 /libpath:"..\libnetxms\Release" /libpath:"..\libnxsl\Release"
+# Begin Special Build Tool
+SOURCE="$(InputPath)"
+PostBuild_Desc=Copy files
+PostBuild_Cmds=copy Release\nxcptest.exe C:\NetXMS\bin
+# End Special Build Tool
+
+!ELSEIF "$(CFG)" == "nxcptest - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libnetxms.lib libnxsl.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\libnetxms\Debug" /libpath:"..\libnxsl\Debug"
+# Begin Special Build Tool
+SOURCE="$(InputPath)"
+PostBuild_Desc=Copy files
+PostBuild_Cmds=copy Debug\nxcptest.exe ..\..\bin
+# End Special Build Tool
+
+!ENDIF
+
+# Begin Target
+
+# Name "nxcptest - Win32 Release"
+# Name "nxcptest - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\nxcptest.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=..\..\include\nms_common.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\include\nms_cscp.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\include\nms_threads.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\include\nms_util.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\nxcptest.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\include\nxsl.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\include\nxsl_classes.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\include\unicode.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
Added: trunk/src/nxcptest/nxcptest.dsw
===================================================================
--- trunk/src/nxcptest/nxcptest.dsw (rev 0)
+++ trunk/src/nxcptest/nxcptest.dsw 2008-05-30 21:15:47 UTC (rev 3289)
@@ -0,0 +1,29 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "nxcptest"=.\nxcptest.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
Added: trunk/src/nxcptest/nxcptest.h
===================================================================
--- trunk/src/nxcptest/nxcptest.h (rev 0)
+++ trunk/src/nxcptest/nxcptest.h 2008-05-30 21:15:47 UTC (rev 3289)
@@ -0,0 +1,35 @@
+/*
+** NetXMS - Network Management System
+** NetXMS Scripting Host
+** Copyright (C) 2005 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
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: nxcptest.h
+**
+**/
+
+#ifndef _nxcptest_h_
+#define _nxcptest_h_
+
+#include <nms_common.h>
+#include <nms_util.h>
+#include <nxcpapi.h>
+
+#if HAVE_GETOPT_H
+#include <getopt.h>
+#endif
+
+#endif
Received on Sat May 31 2008 - 00:15:49 EEST
This archive was generated by hypermail 2.2.0 : Sat May 31 2008 - 00:13:44 EEST