Debian Codegraph @

src/xmlrpcpp/XmlRpcUtil.h

raw
1 // ----------------------------------------------------------------------------
2 //
3 // flxmlrpc Copyright (c) 2015 by W1HKJ, Dave Freese <[email protected]>
4 //
5 // XmlRpc++ Copyright (c) 2002-2008 by Chris Morley
6 //
7 // This file is part of fldigi
8 //
9 // flxmlrpc is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU Lesser General Public License as published by
11 // the Free Software Foundation; either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ----------------------------------------------------------------------------
17
18 #ifndef _XMLRPCUTIL_H_
19 #define _XMLRPCUTIL_H_
20 #if defined(_MSC_VER)
21 # pragma warning(disable:4786) // identifier was truncated in debug info
22 #endif
23
24 #include <string>
25
26 #if defined(_MSC_VER)
27 # define snprintf _snprintf
28 # define vsnprintf _vsnprintf
29 # define strcasecmp _stricmp
30 # define strncasecmp _strnicmp
31 #elif defined(__BORLANDC__)
32 # define strcasecmp stricmp
33 # define strncasecmp strnicmp
34 #endif
35
36 namespace XmlRpc {
37
38 //! Utilities for XML parsing, encoding, and decoding and message handlers.
39 class XmlRpcUtil {
40 public:
41
42 //! Parses the specified tag. No attributes are parsed, no validation is done.
43 //! Sets val to the contents between <tag> and </tag>, or an empty string if <tag/> is found.
44 //! Returns true if the tag is parsed. Updates offset to char after </tag>
45 static bool parseTag(const char* tag, std::string const& xml, int* offset, std::string &val);
46
47 //! Returns true if the tag is found and updates offset to the char after the tag.
48 //! If the tag is of the form <tag/>, emptyTag is set to true.
49 static bool findTag(const char* tag, std::string const& xml, int* offset, bool* emptyTag);
50
51 //! Returns true if the tag is found at the specified offset (modulo any whitespace)
52 //! and updates offset to the char after the tag. If an empty tag is found (eg,
53 //! <tag/>), true is returned, offset is updated to be after the close of the tag, and
54 //! emptyTag is set to true.
55 static bool nextTagIs(const char* tag, std::string const& xml, int* offset, bool* emptyTag);
56
57 //! Passes over the next tag found at the specified offset is </tag>,
58 //! offset is updated to be after the close of the tag.
59 //! Will skip over all characters until < is seen.
60 static bool nextTagIsEnd(const char* tag, std::string const& xml, int* offset);
61
62
63 //! Convert raw text to encoded xml.
64 static std::string xmlEncode(const std::string& raw);
65
66 //! Convert encoded xml to raw text
67 static std::string xmlDecode(const std::string& encoded);
68
69
70 //! Dump messages somewhere
71 static void log(int level, const char* fmt, ...);
72
73 //! Dump error messages somewhere
74 static void error(const char* fmt, ...);
75
76 };
77 } // namespace XmlRpc
78
79 #endif // _XMLRPCUTIL_H_