summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormalosek <malosek@fastmq.com>2009-09-15 09:44:44 +0200
committermalosek <malosek@fastmq.com>2009-09-15 09:44:44 +0200
commit364281343ce0fd03b25bc6b1b451ee7ba8db436b (patch)
tree32cd09900e2ecdc31d6a8f2a47a68fe128980169
parentbdf22e9c2fe82366283f4edc02fd59c37fdb2c4b (diff)
parentf7ad4a203ad184d97002111f4ffb8bfe6a8f7c01 (diff)
Merge branch 'master' of git@github.com:sustrik/zeromq2
-rw-r--r--Makefile.am4
-rw-r--r--c/zmq.h25
-rw-r--r--configure.in39
-rw-r--r--devices/Makefile.am6
-rw-r--r--devices/forwarder/Makefile.am9
-rw-r--r--devices/forwarder/forwarder.cpp122
-rw-r--r--foreign/xmlParser/xmlParser.cpp2898
-rw-r--r--foreign/xmlParser/xmlParser.hpp762
-rw-r--r--java/Socket.cpp116
-rw-r--r--java/org/zmq/Socket.java58
-rw-r--r--msvc/forwarder/forwarder.vcproj174
-rw-r--r--msvc/libzmq/libzmq.vcproj4
-rw-r--r--msvc/msvc.sln9
-rw-r--r--python/pyzmq.cpp3
-rw-r--r--ruby/rbzmq.cpp3
-rw-r--r--src/Makefile.am2
-rw-r--r--src/app_thread.cpp5
-rw-r--r--src/options.cpp5
-rw-r--r--src/options.hpp1
-rw-r--r--src/pub.cpp39
-rw-r--r--src/pub.hpp41
-rw-r--r--src/select.cpp4
-rw-r--r--src/socket_base.cpp18
-rw-r--r--src/sub.cpp12
-rw-r--r--src/sub.hpp2
-rw-r--r--src/zmq_decoder.cpp13
-rw-r--r--src/zmq_listener_init.cpp7
27 files changed, 4218 insertions, 163 deletions
diff --git a/Makefile.am b/Makefile.am
index 18636c0..b1aa70d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -14,8 +14,8 @@ if BUILD_PERF
DIR_PERF = perf
endif
-SUBDIRS = src $(DIR_P) $(DIR_R) $(DIR_J) $(DIR_PERF)
-DIST_SUBDIRS = src python ruby java perf
+SUBDIRS = src $(DIR_P) $(DIR_R) $(DIR_J) $(DIR_PERF) devices
+DIST_SUBDIRS = src python ruby java perf devices
EXTRA_DIST = $(top_srcdir)/foreign/openpgm/@pgm_basename@.tar.bz2
diff --git a/c/zmq.h b/c/zmq.h
index 0a1b064..d2ca20a 100644
--- a/c/zmq.h
+++ b/c/zmq.h
@@ -44,16 +44,15 @@ extern "C" {
#define ZMQ_VSM 32
// Socket options.
-#define ZMQ_HWM 1
-#define ZMQ_LWM 2
-#define ZMQ_SWAP 3
-#define ZMQ_MASK 4
-#define ZMQ_AFFINITY 5
-#define ZMQ_IDENTITY 6
-#define ZMQ_SUBSCRIBE 7
-#define ZMQ_UNSUBSCRIBE 8
-#define ZMQ_RATE 9
-#define ZMQ_RECOVERY_IVL 10
+#define ZMQ_HWM 1 // int64_t
+#define ZMQ_LWM 2 // int64_t
+#define ZMQ_SWAP 3 // int64_t
+#define ZMQ_AFFINITY 4 // int64_t
+#define ZMQ_IDENTITY 5 // string
+#define ZMQ_SUBSCRIBE 6 // string
+#define ZMQ_UNSUBSCRIBE 7 // string
+#define ZMQ_RATE 8 // int64_t
+#define ZMQ_RECOVERY_IVL 9 // int64_t
// The operation should be performed in non-blocking mode. I.e. if it cannot
// be processed immediately, error should be returned with errno set to EAGAIN.
@@ -186,12 +185,12 @@ ZMQ_EXPORT int zmq_connect (void *s, const char *addr);
//
// Errors: EAGAIN - message cannot be sent at the moment (applies only to
// non-blocking send).
-// ENOTSUP - function isn't supported by particular socket type.
+// EFAULT - function isn't supported by particular socket type.
ZMQ_EXPORT int zmq_send (void *s, struct zmq_msg_t *msg, int flags);
// Flush the messages that were send using ZMQ_NOFLUSH flag down the stream.
//
-// Errors: ENOTSUP - function isn't supported by particular socket type.
+// Errors: FAULT - function isn't supported by particular socket type.
ZMQ_EXPORT int zmq_flush (void *s);
// Send a message from the socket 's'. 'flags' argument can be combination
@@ -200,7 +199,7 @@ ZMQ_EXPORT int zmq_flush (void *s);
//
// Errors: EAGAIN - message cannot be received at the moment (applies only to
// non-blocking receive).
-// ENOTSUP - function isn't supported by particular socket type.
+// EFAULT - function isn't supported by particular socket type.
ZMQ_EXPORT int zmq_recv (void *s, struct zmq_msg_t *msg, int flags);
// Helper functions used by perf tests so that they don't have to care
diff --git a/configure.in b/configure.in
index 1cde153..dd6d7ea 100644
--- a/configure.in
+++ b/configure.in
@@ -441,6 +441,16 @@ if test "x$with_pgm_ext" != "xno"; then
pgm_ext="yes"
fi
+# forwarder device
+forwarder="no"
+AC_ARG_WITH([forwarder], [AS_HELP_STRING([--with-forwarder],
+ [build forwarder device [default=no]])], [with_forwarder=yes], [with_forwarder=no])
+
+if test "x$with_forwarder" != "xno"; then
+ forwarder="yes"
+fi
+
+
# Perf
perf="no"
AC_ARG_WITH([perf], [AS_HELP_STRING([--with-perf],
@@ -462,6 +472,7 @@ AM_CONDITIONAL(BUILD_RUBY, test "x$rbzmq" = "xyes")
AM_CONDITIONAL(BUILD_C, test "x$czmq" = "xyes")
AM_CONDITIONAL(BUILD_CPP, test "x$cppzmq" = "xyes")
AM_CONDITIONAL(BUILD_PGM, test "x$pgm_ext" = "xyes")
+AM_CONDITIONAL(BUILD_FORWARDER, test "x$forwarder" = "xyes")
AM_CONDITIONAL(BUILD_PERF, test "x$perf" = "xyes")
AC_SUBST(stdint)
@@ -479,7 +490,8 @@ AC_CHECK_FUNCS(perror gettimeofday memset socket getifaddrs freeifaddrs)
AC_OUTPUT(Makefile src/Makefile python/Makefile python/setup.py ruby/Makefile \
java/Makefile perf/Makefile perf/c/Makefile perf/cpp/Makefile \
- perf/python/Makefile perf/ruby/Makefile perf/java/Makefile src/libzmq.pc)
+ perf/python/Makefile perf/ruby/Makefile perf/java/Makefile src/libzmq.pc \
+ devices/Makefile devices/forwarder/Makefile)
AC_MSG_RESULT([])
AC_MSG_RESULT([ ******************************************************** ])
@@ -492,19 +504,26 @@ AC_MSG_RESULT([ license text. ])
AC_MSG_RESULT([ ******************************************************** ])
AC_MSG_RESULT([])
AC_MSG_RESULT([ 0MQ install dir: $prefix])
-AC_MSG_RESULT([ C language binding: $czmq])
-AC_MSG_RESULT([ C++ language binding: $cppzmq])
-AC_MSG_RESULT([ Python language binding: $pyzmq])
-AC_MSG_RESULT([ Ruby language binding: $rbzmq])
+AC_MSG_RESULT([ Language bindings:])
+AC_MSG_RESULT([ C: $czmq])
+AC_MSG_RESULT([ C++: $cppzmq])
+AC_MSG_RESULT([ Java: $jzmq])
+AC_MSG_RESULT([ Python: $pyzmq])
+AC_MSG_RESULT([ Ruby: $rbzmq])
if test "x$rbzmq" = "xyes"; then
-AC_MSG_RESULT([ Ruby library install dir: $rubydir])
+AC_MSG_RESULT([ Ruby library install dir: $rubydir])
fi
-AC_MSG_RESULT([ Java language binding: $jzmq])
+AC_MSG_RESULT([ Network protocols:])
+AC_MSG_RESULT([ TCP: yes])
if test "x$pgm_ext" = "xyes"; then
-AC_MSG_RESULT([ PGM extension: $pgm_ext ($pgm_name)])
+AC_MSG_RESULT([ PGM: $pgm_ext ($pgm_name)])
else
-AC_MSG_RESULT([ PGM extension: $pgm_ext])
+AC_MSG_RESULT([ PGM: $pgm_ext])
fi
-AC_MSG_RESULT([ performance tests: $perf])
+AC_MSG_RESULT([ Devices:])
+AC_MSG_RESULT([ forwarder: $forwarder])
+AC_MSG_RESULT([ Performance tests: $perf])
+AC_MSG_RESULT([])
+AC_MSG_RESULT([ ******************************************************** ])
AC_MSG_RESULT([])
diff --git a/devices/Makefile.am b/devices/Makefile.am
new file mode 100644
index 0000000..b5bbd37
--- /dev/null
+++ b/devices/Makefile.am
@@ -0,0 +1,6 @@
+if BUILD_FORWARDER
+FORWARDER_DIR = forwarder
+endif
+
+SUBDIRS = $(FORWARDER_DIR)
+DIST_SUBDIRS = forwarder
diff --git a/devices/forwarder/Makefile.am b/devices/forwarder/Makefile.am
new file mode 100644
index 0000000..63230c4
--- /dev/null
+++ b/devices/forwarder/Makefile.am
@@ -0,0 +1,9 @@
+INCLUDES = -I$(top_builddir)/c -I$(top_builddir)/cpp
+
+bin_PROGRAMS = forwarder
+
+forwarder_LDADD = $(top_builddir)/src/libzmq.la
+forwarder_SOURCES = forwarder.cpp
+forwarder_CXXFLAGS = -Wall -pedantic -Werror
+
+
diff --git a/devices/forwarder/forwarder.cpp b/devices/forwarder/forwarder.cpp
new file mode 100644
index 0000000..8acbc85
--- /dev/null
+++ b/devices/forwarder/forwarder.cpp
@@ -0,0 +1,122 @@
+/*
+ Copyright (c) 2007-2009 FastMQ Inc.
+
+ This file is part of 0MQ.
+
+ 0MQ is free software; you can redistribute it and/or modify it under
+ the terms of the Lesser GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ 0MQ 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
+ Lesser GNU General Public License for more details.
+
+ You should have received a copy of the Lesser GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "../../cpp/zmq.hpp"
+#include "../../foreign/xmlParser/xmlParser.cpp"
+
+int main (int argc, char *argv [])
+{
+ if (argc != 2) {
+ fprintf (stderr, "usage: forwarder <config-file>\n");
+ return 1;
+ }
+
+ XMLNode root = XMLNode::parseFile (argv [1]);
+ if (root.isEmpty ()) {
+ fprintf (stderr, "configuration file not found\n");
+ return 1;
+ }
+
+ if (strcmp (root.getName (), "forwarder") != 0) {
+ fprintf (stderr, "root element in the configuration file should be "
+ "named 'forwarder'\n");
+ return 1;
+ }
+
+ XMLNode in_node = root.getChildNode ("in");
+ if (in_node.isEmpty ()) {
+ fprintf (stderr, "'in' node is missing in the configuration file\n");
+ return 1;
+ }
+
+ XMLNode out_node = root.getChildNode ("out");
+ if (out_node.isEmpty ()) {
+ fprintf (stderr, "'out' node is missing in the configuration file\n");
+ return 1;
+ }
+
+ // TODO: make the number of I/O threads configurable.
+ zmq::context_t ctx (1, 1);
+ zmq::socket_t in_socket (ctx, ZMQ_P2P);
+ zmq::socket_t out_socket (ctx, ZMQ_P2P);
+
+ int n = 0;
+ while (true) {
+ XMLNode bind = in_node.getChildNode ("bind", n);
+ if (bind.isEmpty ())
+ break;
+ const char *addr = bind.getAttribute ("addr");
+ if (!addr) {
+ fprintf (stderr, "'bind' node is missing 'addr' attribute\n");
+ return 1;
+ }
+ in_socket.bind (addr);
+ n++;
+ }
+
+ n = 0;
+ while (true) {
+ XMLNode connect = in_node.getChildNode ("connect", n);
+ if (connect.isEmpty ())
+ break;
+ const char *addr = connect.getAttribute ("addr");
+ if (!addr) {
+ fprintf (stderr, "'connect' node is missing 'addr' attribute\n");
+ return 1;
+ }
+ in_socket.connect (addr);
+ n++;
+ }
+
+ n = 0;
+ while (true) {
+ XMLNode bind = out_node.getChildNode ("bind", n);
+ if (bind.isEmpty ())
+ break;
+ const char *addr = bind.getAttribute ("addr");
+ if (!addr) {
+ fprintf (stderr, "'bind' node is missing 'addr' attribute\n");
+ return 1;
+ }
+ out_socket.bind (addr);
+ n++;
+ }
+
+ n = 0;
+ while (true) {
+ XMLNode connect = out_node.getChildNode ("connect", n);
+ if (connect.isEmpty ())
+ break;
+ const char *addr = connect.getAttribute ("addr");
+ if (!addr) {
+ fprintf (stderr, "'connect' node is missing 'addr' attribute\n");
+ return 1;
+ }
+ out_socket.connect (addr);
+ n++;
+ }
+
+ zmq::message_t msg;
+ while (true) {
+ in_socket.recv (&msg);
+ out_socket.send (msg);
+ }
+
+ return 0;
+}
diff --git a/foreign/xmlParser/xmlParser.cpp b/foreign/xmlParser/xmlParser.cpp
new file mode 100644
index 0000000..b9ebe54
--- /dev/null
+++ b/foreign/xmlParser/xmlParser.cpp
@@ -0,0 +1,2898 @@
+/**
+ ****************************************************************************
+ * <P> XML.c - implementation file for basic XML parser written in ANSI C++
+ * for portability. It works by using recursion and a node tree for breaking
+ * down the elements of an XML document. </P>
+ *
+ * @version V2.39
+ * @author Frank Vanden Berghen
+ *
+ * NOTE:
+ *
+ * If you add "#define STRICT_PARSING", on the first line of this file
+ * the parser will see the following XML-stream:
+ * <a><b>some text</b><b>other text </a>
+ * as an error. Otherwise, this tring will be equivalent to:
+ * <a><b>some text</b><b>other text</b></a>
+ *
+ * NOTE:
+ *
+ * If you add "#define APPROXIMATE_PARSING" on the first line of this file
+ * the parser will see the following XML-stream:
+ * <data name="n1">
+ * <data name="n2">
+ * <data name="n3" />
+ * as equivalent to the following XML-stream:
+ * <data name="n1" />
+ * <data name="n2" />
+ * <data name="n3" />
+ * This can be useful for badly-formed XML-streams but prevent the use
+ * of the following XML-stream (problem is: tags at contiguous levels
+ * have the same names):
+ * <data name="n1">
+ * <data name="n2">
+ * <data name="n3" />
+ * </data>
+ * </data>
+ *
+ * NOTE:
+ *
+ * If you add "#define _XMLPARSER_NO_MESSAGEBOX_" on the first line of this file
+ * the "openFileHelper" function will always display error messages inside the
+ * console instead of inside a message-box-window. Message-box-windows are
+ * available on windows 9x/NT/2000/XP/Vista only.
+ *
+ * Copyright (c) 2002, Frank Vanden Berghen
+ * All rights reserved.
+ *
+ * The following license terms apply to projects that are in some way related to
+ * the "ZeroMQ project", including applications
+ * using "ZeroMQ project" and tools developed
+ * for enhancing "ZeroMQ project". All other projects
+ * (not related to "ZeroMQ project") have to use this
+ * code under the Aladdin Free Public License (AFPL)
+ * See the file "AFPL-license.txt" for more informations about the AFPL license.
+ * (see http://www.artifex.com/downloads/doc/Public.htm for detailed AFPL terms)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of Frank Vanden Berghen 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 Frank Vanden Berghen ``AS IS'' 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 <copyright holder> 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.
+ *
+ ****************************************************************************
+ */
+
+#if defined _MSC_VER
+#pragma warning (push)
+#pragma warning (disable:4996)
+#endif
+
+#ifndef _CRT_SECURE_NO_DEPRECATE
+#define _CRT_SECURE_NO_DEPRECATE
+#endif
+#include "xmlParser.hpp"
+#ifdef _XMLWINDOWS
+//#ifdef _DEBUG
+//#define _CRTDBG_MAP_ALLOC
+//#include <crtdbg.h>
+//#endif
+#define WIN32_LEAN_AND_MEAN
+#include <Windows.h> // to have IsTextUnicode, MultiByteToWideChar, WideCharToMultiByte to handle unicode files
+ // to have "MessageBoxA" to display error messages for openFilHelper
+#endif
+
+#include <memory.h>
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+XMLCSTR XMLNode::getVersion() { return _CXML("v2.39"); }
+void freeXMLString(XMLSTR t){if(t)free(t);}
+
+static XMLNode::XMLCharEncoding characterEncoding=XMLNode::char_encoding_UTF8;
+static char guessWideCharChars=1, dropWhiteSpace=1, removeCommentsInMiddleOfText=1;
+
+inline int mmin( const int t1, const int t2 ) { return t1 < t2 ? t1 : t2; }
+
+// You can modify the initialization of the variable "XMLClearTags" below
+// to change the clearTags that are currently recognized by the library.
+// The number on the second columns is the length of the string inside the
+// first column. The "<!DOCTYPE" declaration must be the second in the list.
+// The "<!--" declaration must be the third in the list.
+typedef struct { XMLCSTR lpszOpen; int openTagLen; XMLCSTR lpszClose;} ALLXMLClearTag;
+static ALLXMLClearTag XMLClearTags[] =
+{
+ { _CXML("<![CDATA["),9, _CXML("]]>") },
+ { _CXML("<!DOCTYPE"),9, _CXML(">") },
+ { _CXML("<!--") ,4, _CXML("-->") },
+ { _CXML("<PRE>") ,5, _CXML("</PRE>") },
+// { _CXML("<Script>") ,8, _CXML("</Script>")},
+ { NULL ,0, NULL }
+};
+
+// You can modify the initialization of the variable "XMLEntities" below
+// to change the character entities that are currently recognized by the library.
+// The number on the second columns is the length of the string inside the
+// first column. Additionally, the syntaxes "&#xA0;" and "&#160;" are recognized.
+typedef struct { XMLCSTR s; int l; XMLCHAR c;} XMLCharacterEntity;
+static XMLCharacterEntity XMLEntities[] =
+{
+ { _CXML("&amp;" ), 5, _CXML('&' )},
+ { _CXML("&lt;" ), 4, _CXML('<' )},
+ { _CXML("&gt;" ), 4, _CXML('>' )},
+ { _CXML("&quot;"), 6, _CXML('\"')},
+ { _CXML("&apos;"), 6, _CXML('\'')},
+ { NULL , 0, '\0' }
+};
+
+// When rendering the XMLNode to a string (using the "createXMLString" function),
+// you can ask for a beautiful formatting. This formatting is using the
+// following indentation character:
+#define INDENTCHAR _CXML('\t')
+
+// The following function parses the XML errors into a user friendly string.
+// You can edit this to change the output language of the library to something else.
+XMLCSTR XMLNode::getError(XMLError xerror)
+{
+ switch (xerror)
+ {
+ case eXMLErrorNone: return _CXML("No error");
+ case eXMLErrorMissingEndTag: return _CXML("Warning: Unmatched end tag");
+ case eXMLErrorNoXMLTagFound: return _CXML("Warning: No XML tag found");
+ case eXMLErrorEmpty: return _CXML("Error: No XML data");
+ case eXMLErrorMissingTagName: return _CXML("Error: Missing start tag name");
+ case eXMLErrorMissingEndTagName: return _CXML("Error: Missing end tag name");
+ case eXMLErrorUnmatchedEndTag: return _CXML("Error: Unmatched end tag");
+ case eXMLErrorUnmatchedEndClearTag: return _CXML("Error: Unmatched clear tag end");
+ case eXMLErrorUnexpectedToken: return _CXML("Error: Unexpected token found");
+ case eXMLErrorNoElements: return _CXML("Error: No elements found");
+ case eXMLErrorFileNotFound: return _CXML("Error: File not found");
+ case eXMLErrorFirstTagNotFound: return _CXML("Error: First Tag not found");
+ case eXMLErrorUnknownCharacterEntity:return _CXML("Error: Unknown character entity");
+ case eXMLErrorCharacterCodeAbove255: return _CXML("Error: Character code above 255 is forbidden in MultiByte char mode.");
+ case eXMLErrorCharConversionError: return _CXML("Error: unable to convert between WideChar and MultiByte chars");
+ case eXMLErrorCannotOpenWriteFile: return _CXML("Error: unable to open file for writing");
+ case eXMLErrorCannotWriteFile: return _CXML("Error: cannot write into file");
+
+ case eXMLErrorBase64DataSizeIsNotMultipleOf4: return _CXML("Warning: Base64-string length is not a multiple of 4");
+ case eXMLErrorBase64DecodeTruncatedData: return _CXML("Warning: Base64-string is truncated");
+ case eXMLErrorBase64DecodeIllegalCharacter: return _CXML("Error: Base64-string contains an illegal character");
+ case eXMLErrorBase64DecodeBufferTooSmall: return _CXML("Error: Base64 decode output buffer is too small");
+ };
+ return _CXML("Unknown");
+}
+
+/////////////////////////////////////////////////////////////////////////
+// Here start the abstraction layer to be OS-independent //
+/////////////////////////////////////////////////////////////////////////
+
+// Here is an abstraction layer to access some common string manipulation functions.
+// The abstraction layer is currently working for gcc, Microsoft Visual Studio 6.0,
+// Microsoft Visual Studio .NET, CC (sun compiler) and Borland C++.
+// If you plan to "port" the library to a new system/compiler, all you have to do is
+// to edit the following lines.
+#ifdef XML_NO_WIDE_CHAR
+char myIsTextWideChar(const void *b, int len) { return FALSE; }
+#else
+ #if defined (UNDER_CE) || !defined(_XMLWINDOWS)
+ char myIsTextWideChar(const void *b, int len) // inspired by the Wine API: RtlIsTextUnicode
+ {
+#ifdef sun
+ // for SPARC processors: wchar_t* buffers must always be alligned, otherwise it's a char* buffer.
+ if ((((unsigned long)b)%sizeof(wchar_t))!=0) return FALSE;
+#endif
+ const wchar_t *s=(const wchar_t*)b;
+
+ // buffer too small:
+ if (len<(int)sizeof(wchar_t)) return FALSE;
+
+ // odd length test
+ if (len&1) return FALSE;
+
+ /* only checks the first 256 characters */
+ len=mmin(256,len/sizeof(wchar_t));
+
+ // Check for the special byte order:
+ if (*((unsigned short*)s) == 0xFFFE) return TRUE; // IS_TEXT_UNICODE_REVERSE_SIGNATURE;
+ if (*((unsigned short*)s) == 0xFEFF) return TRUE; // IS_TEXT_UNICODE_SIGNATURE
+
+ // checks for ASCII characters in the UNICODE stream
+ int i,stats=0;
+ for (i=0; i<len; i++) if (s[i]<=(unsigned short)255) stats++;
+ if (stats>len/2) return TRUE;
+
+ // Check for UNICODE NULL chars
+ for (i=0; i<len; i++) if (!s[i]) return TRUE;
+
+ return FALSE;
+ }
+ #else
+ char myIsTextWideChar(const void *b,int l) { return (char)IsTextUnicode((CONST LPVOID)b,l,NULL); };
+ #endif
+#endif
+
+#ifdef _XMLWINDOWS
+// for Microsoft Visual Studio 6.0 and Microsoft Visual Studio .NET and Borland C++ Builder 6.0
+ #ifdef _XMLWIDECHAR
+ wchar_t *myMultiByteToWideChar(const char *s, XMLNode::XMLCharEncoding ce)
+ {
+ int i;
+ if (ce==XMLNode::char_encoding_UTF8) i=(int)MultiByteToWideChar(CP_UTF8,0 ,s,-1,NULL,0);
+ else i=(int)MultiByteToWideChar(CP_ACP ,MB_PRECOMPOSED,s,-1,NULL,0);
+ if (i<0) return NULL;
+ wchar_t *d=(wchar_t *)malloc((i+1)*sizeof(XMLCHAR));
+ if (ce==XMLNode::char_encoding_UTF8) i=(int)MultiByteToWideChar(CP_UTF8,0 ,s,-1,d,i);
+ else i=(int)MultiByteToWideChar(CP_ACP ,MB_PRECOMPOSED,s,-1,d,i);
+ d[i]=0;
+ return d;
+ }
+ static inline FILE *xfopen(XMLCSTR filename,XMLCSTR mode) { return _wfopen(filename,mode); }
+ static inline int xstrlen(XMLCSTR c) { return (int)wcslen(c); }
+ static inline int xstrnicmp(XMLCSTR c1, XMLCSTR c2, int l) { return _wcsnicmp(c1,c2,l);}
+ static inline int xstrncmp(XMLCSTR c1, XMLCSTR c2, int l) { return wcsncmp(c1,c2,l);}
+ static inline int xstricmp(XMLCSTR c1, XMLCSTR c2) { return _wcsicmp(c1,c2); }
+ static inline XMLSTR xstrstr(XMLCSTR c1, XMLCSTR c2) { return (XMLSTR)wcsstr(c1,c2); }
+ static inline XMLSTR xstrcpy(XMLSTR c1, XMLCSTR c2) { return (XMLSTR)wcscpy(c1,c2); }
+ #else
+ char *myWideCharToMultiByte(const wchar_t *s)
+ {
+ UINT codePage=CP_ACP; if (characterEncoding==XMLNode::char_encoding_UTF8) codePage=CP_UTF8;
+ int i=(int)WideCharToMultiByte(codePage, // code page
+ 0, // performance and mapping flags
+ s, // wide-character string
+ -1, // number of chars in string
+ NULL, // buffer for new string
+ 0, // size of buffer
+ NULL, // default for unmappable chars
+ NULL // set when default char used
+ );
+ if (i<0) return NULL;
+ char *d=(char*)malloc(i+1);
+ WideCharToMultiByte(codePage, // code page
+ 0, // performance and mapping flags
+ s, // wide-character string
+ -1, // number of chars in string
+ d, // buffer for new string
+ i, // size of buffer
+ NULL, // default for unmappable chars
+ NULL // set when default char used
+ );
+ d[i]=0;
+ return d;
+ }
+ static inline FILE *xfopen(XMLCSTR filename,XMLCSTR mode) { return fopen(filename,mode); }
+ static inline int xstrlen(XMLCSTR c) { return (int)strlen(c); }
+ #ifdef __BORLANDC__
+ static inline int xstrnicmp(XMLCSTR c1, XMLCSTR c2, int l) { return strnicmp(c1,c2,l);}
+ static inline int xstricmp(XMLCSTR c1, XMLCSTR c2) { return stricmp(c1,c2); }
+ #else
+ static inline int xstrnicmp(XMLCSTR c1, XMLCSTR c2, int l) { return _strnicmp(c1,c2,l);}
+ static inline int xstricmp(XMLCSTR c1, XMLCSTR c2) { return _stricmp(c1,c2); }
+ #endif
+ static inline int xstrncmp(XMLCSTR c1, XMLCSTR c2, int l) { return strncmp(c1,c2,l);}
+ static inline XMLSTR xstrstr(XMLCSTR c1, XMLCSTR c2) { return (XMLSTR)strstr(c1,c2); }
+ static inline XMLSTR xstrcpy(XMLSTR c1, XMLCSTR c2) { return (XMLSTR)strcpy(c1,c2); }
+ #endif
+#else
+// for gcc and CC
+ #ifdef XML_NO_WIDE_CHAR
+ char *myWideCharToMultiByte(const wchar_t *s) { return NULL; }
+ #else
+ char *myWideCharToMultiByte(const wchar_t *s)
+ {
+ const wchar_t *ss=s;
+ int i=(int)wcsrtombs(NULL,&ss,0,NULL);
+ if (i<0) return NULL;
+ char *d=(char *)malloc(i+1);
+ wcsrtombs(d,&s,i,NULL);
+ d[i]=0;
+ return d;
+ }
+ #endif
+ #ifdef _XMLWIDECHAR
+ wchar_t *myMultiByteToWideChar(const char *s, XMLNode::XMLCharEncoding ce)
+ {
+ const char *ss=s;
+ int i=(int)mbsrtowcs(NULL,&ss,0,NULL);
+ if (i<0) return NULL;
+ wchar_t *d=(wchar_t *)malloc((i+1)*sizeof(wchar_t));
+ mbsrtowcs(d,&s,i,NULL);
+ d[i]=0;
+ return d;
+ }
+ int xstrlen(XMLCSTR c) { return wcslen(c); }
+ #ifdef sun
+ // for CC
+ #include <widec.h>
+ static inline int xstrnicmp(XMLCSTR c1, XMLCSTR c2, int l) { return wsncasecmp(c1,c2,l);}
+ static inline int xstrncmp(XMLCSTR c1, XMLCSTR c2, int l) { return wsncmp(c1,c2,l);}
+ static inline int xstricmp(XMLCSTR c1, XMLCSTR c2) { return wscasecmp(c1,c2); }
+ #else
+ // for gcc
+ static inline int xstrnicmp(XMLCSTR c1, XMLCSTR c2, int l) { return wcsncasecmp(c1,c2,l);}
+ static inline int xstrncmp(XMLCSTR c1, XMLCSTR c2, int l) { return wcsncmp(c1,c2,l);}
+ static inline int xstricmp(XMLCSTR c1, XMLCSTR c2) { return wcscasecmp(c1,c2); }
+ #endif
+ static inline XMLSTR xstrstr(XMLCSTR c1, XMLCSTR c2) { return (XMLSTR)wcsstr(c1,c2); }
+ static inline XMLSTR xstrcpy(XMLSTR c1, XMLCSTR c2) { return (XMLSTR)wcscpy(c1,c2); }
+ static inline FILE *xfopen(XMLCSTR filename,XMLCSTR mode)
+ {
+ char *filenameAscii=myWideCharToMultiByte(filename);
+ FILE *f;
+ if (mode[0]==_CXML('r')) f=fopen(filenameAscii,"rb");
+ else f=fopen(filenameAscii,"wb");
+ free(filenameAscii);
+ return f;
+ }
+ #else
+ static inline FILE *xfopen(XMLCSTR filename,XMLCSTR mode) { return fopen(filename,mode); }
+ static inline int xstrlen(XMLCSTR c) { return strlen(c); }
+ static inline int xstrnicmp(XMLCSTR c1, XMLCSTR c2, int l) { return strncasecmp(c1,c2,l);}
+ static inline int xstrncmp(XMLCSTR c1, XMLCSTR c2, int l) { return strncmp(c1,c2,l);}
+ static inline int xstricmp(XMLCSTR c1, XMLCSTR c2) { return strcasecmp(c1,c2); }
+ static inline XMLSTR xstrstr(XMLCSTR c1, XMLCSTR c2) { return (XMLSTR)strstr(c1,c2); }
+ static inline XMLSTR xstrcpy(XMLSTR c1, XMLCSTR c2) { return (XMLSTR)strcpy(c1,c2); }
+ #endif
+ static inline int _strnicmp(const char *c1,const char *c2, int l) { return strncasecmp(c1,c2,l);}
+#endif
+
+
+///////////////////////////////////////////////////////////////////////////////
+// the "xmltoc,xmltob,xmltoi,xmltol,xmltof,xmltoa" functions //
+///////////////////////////////////////////////////////////////////////////////
+// These 6 functions are not used inside the XMLparser.
+// There are only here as "convenience" functions for the user.
+// If you don't need them, you can delete them without any trouble.
+#ifdef _XMLWIDECHAR
+ #ifdef _XMLWINDOWS
+ // for Microsoft Visual Studio 6.0 and Microsoft Visual Studio .NET and Borland C++ Builder 6.0
+ char xmltob(XMLCSTR t,int v){ if (t&&(*t)) return (char)_wtoi(t); return v; }
+ int xmltoi(XMLCSTR t,int v){ if (t&&(*t)) return _wtoi(t); return v; }
+ long xmltol(XMLCSTR t,long v){ if (t&&(*t)) return _wtol(t); return v; }
+ double xmltof(XMLCSTR t,double v){ if (t&&(*t)) wscanf(t, "%f", &v); /*v=_wtof(t);*/ return v; }
+ #else
+ #ifdef sun
+ // for CC
+ #include <widec.h>
+ char xmltob(XMLCSTR t,int v){ if (t) return (char)wstol(t,NULL,10); return v; }
+ int xmltoi(XMLCSTR t,int v){ if (t) return (int)wstol(t,NULL,10); return v; }
+ long xmltol(XMLCSTR t,long v){ if (t) return wstol(t,NULL,10); return v; }
+ #else
+ // for gcc
+ char xmltob(XMLCSTR t,int v){ if (t) return (char)wcstol(t,NULL,10); return v; }
+ int xmltoi(XMLCSTR t,int v){ if (t) return (int)wcstol(t,NULL,10); return v; }
+ long xmltol(XMLCSTR t,long v){ if (t) return wcstol(t,NULL,10); return v; }
+ #endif
+ double xmltof(XMLCSTR t,double v){ if (t&&(*t)) wscanf(t, "%f", &v); /*v=_wtof(t);*/ return v; }
+ #endif
+#else
+ char xmltob(XMLCSTR t,char v){ if (t&&(*t)) return (char)atoi(t); return v; }
+ int xmltoi(XMLCSTR t,int v){ if (t&&(*t)) return atoi(t); return v; }
+ long xmltol(XMLCSTR t,long v){ if (t&&(*t)) return atol(t); return v; }
+ double xmltof(XMLCSTR t,double v){ if (t&&(*t)) return atof(t); return v; }
+#endif
+XMLCSTR xmltoa(XMLCSTR t,XMLCSTR v){ if (t) return t; return v; }
+XMLCHAR xmltoc(XMLCSTR t,XMLCHAR v){ if (t&&(*t)) return *t; return v; }
+
+/////////////////////////////////////////////////////////////////////////
+// the "openFileHelper" function //
+/////////////////////////////////////////////////////////////////////////
+
+// Since each application has its own way to report and deal with errors, you should modify & rewrite
+// the following "openFileHelper" function to get an "error reporting mechanism" tailored to your needs.
+XMLNode XMLNode::openFileHelper(XMLCSTR filename, XMLCSTR tag)
+{
+ // guess the value of the global parameter "characterEncoding"
+ // (the guess is based on the first 200 bytes of the file).
+ FILE *f=xfopen(filename,_CXML("rb"));
+ if (f)
+ {
+ char bb[205];
+ int l=(int)fread(bb,1,200,f);
+ setGlobalOptions(guessCharEncoding(bb,l),guessWideCharChars,dropWhiteSpace,removeCommentsInMiddleOfText);
+ fclose(f);
+ }
+
+ // parse the file
+ XMLResults pResults;
+ XMLNode xnode=XMLNode::parseFile(filename,tag,&pResults);
+
+ // display error message (if any)
+ if (pResults.error != eXMLErrorNone)
+ {
+ // create message
+ char message[2000],*s1=(char*)"",*s3=(char*)""; XMLCSTR s2=_CXML("");
+ if (pResults.error==eXMLErrorFirstTagNotFound) { s1=(char*)"First Tag should be '"; s2=tag; s3=(char*)"'.\n"; }
+ sprintf(message,
+#ifdef _XMLWIDECHAR
+ "XML Parsing error inside file '%S'.\n%S\nAt