00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00038 #include <ulxmlrpcpp/ulxr_log4j.h>
00039
00040 #ifndef ULXR_H
00041 #define ULXR_H
00042
00043
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00068
00069
00070 #ifdef _MSC_VER
00071 # define _CRT_SECURE_NO_DEPRECATE
00072 # include <ulxmlrpcpp/ulxr_config-msvc.h>
00073 #elif defined(__BORLANDC__)
00074 # include <ulxmlrpcpp/ulxr_config-bcb5.h>
00075 #elif defined(__CYGWIN__)
00076 # include <ulxmlrpcpp/ulxr_config-cygwin.h>
00077 #else
00078 # ifdef ULXR_HAVE_CONFIG_H
00079 # include <config.h>
00080 # else
00081 # include <ulxmlrpcpp/ulxr_config.h>
00082 # endif
00083 #endif
00084
00085
00086 # ifdef _MSC_VER
00087
00088 # pragma warning (disable:4786) // this warning occurs when VC6 truncate a debug symbol which is longer than 255 chars.
00089 # pragma warning (disable:4251) // this warning occurs when a class member doesn't have a dll-interface.
00090 # pragma warning (disable:4180)
00091 # pragma warning (disable:4355)
00092 # endif // _MSC_VER
00093
00094
00095 #if defined(HAVE_ICONV_H) || defined(HAVE_ICONV)
00096 # include <iconv.h>
00097 #endif
00098
00100
00101
00102 #ifdef verify
00103 #error "<verify> must not be #defined within mockpp sources"
00104 #endif
00105
00106 #ifdef check
00107 #error "<check> must not be #defined within mockpp sources"
00108 #endif
00109
00110 #ifdef require
00111 #error "<require> must not be #defined within mockpp sources"
00112 #endif
00113
00115 #define ULXR_USE_STD_EXCEPTION
00116
00117 #ifdef ULXR_USE_WXSTRING
00118
00119 # ifdef _MSC_VER
00120 # pragma message("Using wxString")
00121 # endif
00122
00123 # define __WXMSW__
00124 # define __WXDEBUG__
00125 # define WXUSINGDLL
00126
00127 # include <wx/string.h>
00128
00133 namespace ulxr
00134 {
00135
00136 typedef wxwindows::string Cpp8BitString;
00137 #if defined (ULXR_UNICODE) || defined(ULXR_UNICODE_ONLY_HELPERS)
00138 typedef wxwindows::wstring Cpp16BitString;
00139 #endif
00140
00141 }
00142
00143 # ifdef _MSC_VER
00144 # pragma comment( lib, "wx23_1d" ) // auto include the wxWindows 2.3.1
00145 # endif
00146
00147 #else // ULXR_USE_WXSTRING
00148
00149 # ifdef _MSC_VER
00150 # pragma message("Using std::string")
00151 # endif
00152
00153 # if defined(__BORLANDC__) || defined (_MSC_VER)
00154 # define HAVE_WSTRING
00155 # endif
00156
00157 # include <string>
00158
00159 #ifdef __BORLANDC__
00160 # define ULXR_INT64 INT64
00161 #elif defined(_MSC_VER)
00162 # define ULXR_INT64 __int64
00163 #else
00164 # define ULXR_INT64 __int64_t
00165 #endif
00166
00167 namespace ulxr
00168 {
00169 #if defined (ULXR_UNICODE) || defined(ULXR_UNICODE_ONLY_HELPERS)
00170
00171 # if !defined(HAVE_WSTRING)
00172 typedef std::basic_string<wchar_t> Cpp16BitString;
00173 # else
00174 typedef std::wstring Cpp16BitString;
00175 # endif
00176
00177 #endif
00178
00179 typedef std::string Cpp8BitString;
00180 }
00181
00182 #endif // ULXR_USE_WXSTRING
00183
00184
00185 #ifdef __sun__
00186 #ifndef __SUN__
00187 #define __SUN__
00188 #endif
00189 #endif
00190
00191 #if defined(__BORLANDC__) || defined (_MSC_VER)
00192
00193 # ifndef __WIN32__
00194 # define __WIN32__
00195 # endif //__WIN32__
00196
00197 # ifdef __BORLANDC__
00198 # include <io.h>
00199
00200 # ifndef __MT__
00201 # error MultiThreaded compilation is HIGHLY recommended, change at own risk
00202 # endif
00203
00204 # ifndef _RTLDLL
00205 # error Linking with dynamic RTL is HIGHLY recommended, change at own risk
00206 # endif
00207
00208 # endif
00209
00210 # if defined (_MSC_VER)
00211
00212
00213 # if defined(ULXR_STATIC_LIB)
00214 # define ULXR_API_DECL(type) type
00215 # define ULXR_API_DECL0
00216 # define ULXR_API_IMPL(type) type
00217 # define ULXR_API_IMPL0
00218 # pragma message("*** ULXMLRPCPP: Static ***")
00219 # else //ULXR_STATIC_LIB
00220
00221 # if defined(ULXR_NEED_EXPORTS)
00222 # define ULXR_API_DECL(type) __declspec(dllexport) type
00223 # define ULXR_API_DECL0 __declspec(dllexport)
00224 # define ULXR_API_IMPL(type) __declspec(dllexport) type
00225 # define ULXR_API_IMPL0 __declspec(dllexport)
00226 # pragma message("*** ULXMLRPCPP: DllExport ***")
00227
00228 # else // ULXR_NEED_EXPORTS
00229
00230 # define ULXR_API_DECL(type) __declspec(dllimport) type
00231 # define ULXR_API_DECL0 __declspec(dllimport)
00232 # define ULXR_API_IMPL(type) __declspec(dllimport) type
00233 # define ULXR_API_IMPL0 __declspec(dllimport)
00234 # pragma message("*** ULXMLRPCPP: DllImport ***")
00235 # endif // ULXR_NEED_EXPORTS
00236
00237 # endif //ULXR_STATIC_LIB
00238
00239 # else // __BORLANDC__
00240
00241 # if defined(ULXR_NEED_EXPORTS)
00242 # define ULXR_API_DECL0 __declspec(dllexport)
00243 # define ULXR_API_IMPL0 __declspec(dllexport)
00244 # define ULXR_API_DECL(type) __declspec(dllexport) type
00245 # define ULXR_API_IMPL(type) __declspec(dllexport) type
00246 # else
00247 # define ULXR_API_DECL0 __declspec(dllimport)
00248 # define ULXR_API_IMPL0
00249 # define ULXR_API_DECL(type) __declspec(dllimport) type
00250 # define ULXR_API_IMPL(type) type
00251 # endif
00252
00253 # endif
00254
00255 #else // __BORLANDC__ || _MSC_VER
00256
00257 # include <unistd.h>
00258 # define ULXR_API_DECL0
00259 # define ULXR_API_IMPL0
00260 # define ULXR_API_DECL(type) type
00261 # define ULXR_API_IMPL(type) type
00262
00263 #endif
00264
00265
00266 #if defined(ULXR_DEBUG_OUTPUT)
00267
00268 #include <iostream>
00269 #include <sstream>
00270
00271 # if defined (_MSC_VER)
00272
00273 # define ULXR_DTRACE(x) { ULXR_CERR << ULXR_GET_STRING(__FILE__) << "," << __LINE__ << ":" << x << ULXR_PCHAR("\n"); }
00274 # define ULXR_DOUT(x) { ULXR_CERR << x << ULXR_PCHAR("\n"); }
00275 # define ULXR_DWRITE(b, l) { ULXR_CERR << "ULXR_DWRITE not yet implemented" << ULXR_PCHAR("\n"); }
00276
00277 # else //_MSC_VER
00278
00279 #ifdef ULXR_LOG4J
00280
00281 # define ULXR_DTRACE(x) \
00282 { if (ulxr::getLogger4J() != 0) \
00283 { \
00284 ulxr::CppOStringStream os; \
00285 os << x; \
00286 ulxr::getLogger4J()->send(ULXR_GET_STRING(ULXR_PCHAR("TRACE")), os.str(), ULXR_GET_STRING(__FILE__), __LINE__ ); \
00287 } \
00288 }
00289
00290 # define ULXR_DOUT(x) \
00291 { if (ulxr::getLogger4J() != 0) \
00292 { \
00293 ulxr::CppOStringStream os; \
00294 os << x; \
00295 ulxr::getLogger4J()->send(ULXR_GET_STRING(ULXR_PCHAR("DEBUG")), os.str() ); \
00296 } \
00297 }
00298
00299 # define ULXR_DWRITE(b, l) \
00300 { if (ulxr::getLogger4J() != 0) \
00301 { \
00302 std::string s0(b, l); \
00303 ulxr::getLogger4J()->send(ULXR_GET_STRING(ULXR_PCHAR("DEBUG")), ULXR_GET_STRING(s0)); \
00304 } \
00305 }
00306
00307 #else
00308
00309 # define ULXR_DTRACE(x) { ULXR_CERR << ULXR_GET_STRING(__FILE__) << "," << __LINE__ << ": " << x << ULXR_PCHAR("\n"); }
00310 # define ULXR_DOUT(x) { ULXR_CERR << x << ULXR_PCHAR("\n"); }
00311 # define ULXR_DWRITE(b, l) { ::write(2, b, l); ULXR_CERR << ULXR_PCHAR("\n");}
00312
00313 #endif
00314
00315 # endif //_MSC_VER
00316
00317 #else // DEBUG
00318
00319 # define ULXR_DWRITE(b, l)
00320 # define ULXR_DTRACE(x)
00321 # define ULXR_DOUT(x)
00322
00323 #endif // DEBUG
00324
00326
00327
00328
00329 #ifdef ULXR_SHOW_TRACE
00330 #define ULXR_TRACE(x) ULXR_DTRACE(x)
00331 #else
00332 #define ULXR_TRACE(x)
00333 #endif
00334
00335
00336 #ifdef ULXR_SHOW_XML
00337 #define ULXR_DOUT_XML(x) ULXR_DOUT(ULXR_PCHAR("xml:\n") << x)
00338 #else
00339 #define ULXR_DOUT_XML(x)
00340 #endif
00341
00342
00343 #ifdef ULXR_SHOW_HTTP
00344 #define ULXR_DOUT_HTTP(x) ULXR_DOUT(x)
00345 #else
00346 #define ULXR_DOUT_HTTP(x)
00347 #endif
00348
00349
00350 #ifdef ULXR_SHOW_CONTENT
00351 #define ULXR_DOUT_REQ(x) ULXR_DOUT(x)
00352 #define ULXR_DOUT_RESP(x) ULXR_DOUT(x)
00353 #else
00354 #define ULXR_DOUT_REQ(x)
00355 #define ULXR_DOUT_RESP(x)
00356 #endif
00357
00358
00359 #ifdef ULXR_SHOW_WRITE
00360 #define ULXR_DOUT_WRITE(x) ULXR_DOUT(x)
00361 #define ULXR_DWRITE_WRITE(p,l) ULXR_DWRITE(p,l)
00362 #else
00363 #define ULXR_DOUT_WRITE(x)
00364 #define ULXR_DWRITE_WRITE(p,l)
00365 #endif
00366
00367
00368 #ifdef ULXR_SHOW_READ
00369 #define ULXR_DOUT_READ(x) ULXR_DOUT(x)
00370 #define ULXR_DWRITE_READ(p,l) ULXR_DWRITE(p,l)
00371 #else
00372 #define ULXR_DOUT_READ(x)
00373 #define ULXR_DWRITE_READ(p,l)
00374
00375 #endif
00376
00377
00379
00380
00381 #define ULXR_RECV_BUFFER_SIZE 50 // keep rather small, otherwise two messages
00382
00383 #define ULXR_SEND_BUFFER_SIZE 2000
00384
00385 namespace ulxr {
00386
00387 class Log4JSender;
00388
00389
00390
00391
00392 const int NotWellformedError = -32700;
00393 const int UnsupportedEncodingError = -32701;
00394 const int InvalidCharacterError = -32702;
00395
00396
00397 const int NotConformingError = -32600;
00398 const int MethodNotFoundError = -32601;
00399 const int InvalidMethodParameterError = -32602;
00400 const int InternalXmlRpcError = -32603;
00401
00402
00403 const int ApplicationError = -32500;
00404 const int SystemError = -32400;
00405 const int TransportError = -32300;
00406
00407 #ifdef ULXR_UNICODE
00408
00409 typedef std::wostringstream CppOStringStream;
00410 typedef Cpp16BitString CppString;
00411 typedef wchar_t Char;
00412
00414 # define ULXR_CHAR(x) L##x
00415
00417 # define ULXR_PCHAR(x) L##x
00418
00419 # define ULXR_COUT std::wcout
00420 # define ULXR_CERR std::wcerr
00421
00422 #else
00423
00424 typedef std::ostringstream CppOStringStream;
00425 typedef std::string CppString;
00426 typedef char Char;
00428 # define ULXR_CHAR(x) x
00429
00431 # define ULXR_PCHAR(x) x
00432
00433 # define ULXR_COUT std::cout
00434 # define ULXR_CERR std::cerr
00435
00436 #endif
00437
00438
00446 ULXR_API_DECL(void) getVersion (int &major, int &minor, int &patch, bool &debug, CppString &info);
00447
00452 ULXR_API_DECL(CppString) stripWS(const CppString &s);
00453
00459 ULXR_API_DECL(CppString) encodeBase64(const CppString &normstr, bool add_crlf = true);
00460
00466 ULXR_API_DECL(CppString) decodeBase64(const CppString &b64str, bool errcheck = true);
00467
00475 ULXR_API_DECL(CppString) xmlEscape(const CppString &str, bool supp = false);
00476
00481 ULXR_API_DECL(CppString) xmlUnEscape(const CppString &str);
00482
00487 ULXR_API_DECL(void) makeLower(CppString &str);
00488
00493 ULXR_API_DECL(void) makeUpper(CppString &str);
00494
00495 #if defined (ULXR_UNICODE) || defined(ULXR_UNICODE_ONLY_HELPERS)
00496
00502 ULXR_API_DECL(Cpp16BitString) utf8ToUnicode(const Cpp8BitString &val);
00503
00509 ULXR_API_DECL(Cpp8BitString) unicodeToUtf8(const Cpp16BitString &val);
00510
00511 #endif
00512
00522 ULXR_API_DECL(Cpp8BitString) asciiToUtf8(const Cpp8BitString &val);
00523
00533 ULXR_API_DECL(Cpp8BitString) utf8ToAscii(const Cpp8BitString &val);
00534
00540 ULXR_API_DECL(Cpp8BitString) unicodeToUtf8(const unsigned c);
00541
00542 #if defined(HAVE_ICONV_H) || defined(HAVE_ICONV)
00543
00552 ULXR_API_DECL(Cpp8BitString) encodingToUtf8(const Cpp8BitString &val, const char *encoding);
00553
00562 ULXR_API_DECL(Cpp8BitString) utf8ToEncoding(const Cpp8BitString &val, const char *encoding);
00563
00574 ULXR_API_DECL(Cpp8BitString) convertEncoding(const Cpp8BitString &val, iconv_t con);
00575
00576 #endif
00577
00578
00579 #if defined (ULXR_UNICODE) || defined(ULXR_UNICODE_ONLY_HELPERS)
00580
00588 ULXR_API_DECL(Cpp16BitString) getUnicode(const std::string &latin1);
00589
00590
00597 inline ULXR_API_DECL(Cpp16BitString) getUnicode(const Cpp16BitString &uni)
00598 {
00599 return uni;
00600 }
00601
00609 ULXR_API_DECL(std::string) getLatin1(const Cpp16BitString &uni);
00610
00611 #endif
00612
00619 inline ULXR_API_DECL(std::string) getLatin1(const std::string &latin1)
00620 {
00621 return latin1;
00622 }
00623
00628 ULXR_API_DECL(std::string) getWbXmlString(const CppString &inp);
00629
00636 ULXR_API_DECL(CppString) wbXmlToString(std::string &inp);
00637
00642 ULXR_API_DECL(std::string) getWbXmlExtInt(long int i);
00643
00650 ULXR_API_DECL(long int) wbXmlToInt(std::string &inp);
00651
00656 ULXR_API_DECL(CppString) binaryDebugOutput (const std::string &s);
00657
00663 ULXR_API_DECL(CppString) getLastErrorString(unsigned errornum);
00664
00669 ULXR_API_DECL(void) intializeLog4J(const std::string &appname,
00670 const CppString &loghost = ULXR_PCHAR("localhost"));
00671
00676 ULXR_API_DECL(Log4JSender *) getLogger4J();
00677
00682 ULXR_API_DECL(int) getRand();
00683
00687 ULXR_API_DECL(void) enableXmlPrettyPrint(bool pretty);
00688
00693 ULXR_API_DECL(CppString) getXmlLinefeed();
00694
00700 ULXR_API_DECL(CppString) getXmlIndent(unsigned indent);
00701
00702 class Mutex;
00703
00704 #ifndef ULXR_OMIT_REENTRANT_PROTECTOR
00705
00706 extern ULXR_API_DECL(Mutex) strerrorMutex;
00707 extern ULXR_API_DECL(Mutex) ctimeMutex;
00708 extern ULXR_API_DECL(Mutex) localtimeMutex;
00709 extern ULXR_API_DECL(Mutex) gethostbynameMutex;
00710 extern ULXR_API_DECL(Mutex) gethostbyaddrMutex;
00711 extern ULXR_API_DECL(Mutex) randMutex;
00712 #endif
00713
00714 }
00715
00716
00717 #ifdef ULXR_DOXYGEN_SHOULD_INCLUDE_THIS
00718
00722 #define ULXR_OMIT_REENTRANT_PROTECTOR
00723
00724 #endif
00725
00726
00728 #define ULXR_STRING(x) ulxr::CppString(x)
00729
00730 #ifndef ULXR_I18N_NOOP
00732 #define ULXR_I18N_NOOP(x) x
00733 #endif
00734
00735 #ifndef ulxr_i18n
00737 #define ulxr_i18n(x) x
00738 #endif
00739
00740
00741 #if defined (ULXR_UNICODE)
00743 # define ULXR_GET_STRING(x) ulxr::getUnicode(x)
00744 #else
00746 # define ULXR_GET_STRING(x) ulxr::getLatin1(x)
00747 #endif
00748
00749
00770 #ifdef __unix__
00771 #define ULXR_DIRSEP ULXR_PCHAR("/")
00772 #else
00773 #define ULXR_DIRSEP ULXR_PCHAR("\\")
00774 #endif
00775
00776 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ < 3))
00777 # define ulxr_FILE FILE
00778 # define ulxr_isspace isspace
00779 # define ulxr_tolower tolower
00780 # define ulxr_isdigit isdigit
00781 # define ulxr_toupper toupper
00782 # define ulxr_fopen fopen
00783 # define ulxr_abs abs
00784 # define ulxr_fabs fabs
00785 # define ulxr_atoi atoi
00786 # define ulxr_eof eof
00787 # define ulxr_feof feof
00788 # define ulxr_ferror ferror
00789 # define ulxr_fputc fputc
00790 # define ulxr_fread fread
00791 # define ulxr_fwrite fwrite
00792
00793 #if defined(_MSC_VER)
00794 # define ulxr_access _access
00795 #else
00796 # define ulxr_access access
00797 #endif
00798
00799 # define ulxr_remove remove
00800 # define ulxr_fclose fclose
00801 # define ulxr_sprintf sprintf
00802
00803 #if defined(_MSC_VER)
00804 # define ulxr_snprintf _snprintf
00805 #else
00806 # define ulxr_snprintf snprintf
00807 #endif
00808
00809 # define ulxr_swprintf swprintf
00810 # define ulxr_time_t time_t
00811 # define ulxr_tm tm
00812 # define ulxr_ctime ctime
00813 # define ulxr_localtime localtime
00814 # define ulxr_time time
00815 # define ulxr_stricmp stricmp
00816
00817 #else
00818
00819 # define ulxr_FILE std::FILE
00820 # define ulxr_toupper std::toupper
00821 # define ulxr_isspace std::isspace
00822 # define ulxr_tolower std::tolower
00823 # define ulxr_isdigit std::isdigit
00824 # define ulxr_fopen std::fopen
00825 # define ulxr_eof std::eof
00826 # define ulxr_abs std::abs
00827 # define ulxr_fabs std::fabs
00828 # define ulxr_atoi std::atoi
00829 # define ulxr_feof std::feof
00830 # define ulxr_ferror std::ferror
00831 # define ulxr_fputc std::fputc
00832 # define ulxr_fread fread
00833 # define ulxr_fwrite fwrite
00834 # define ulxr_access access
00835 # define ulxr_remove std::remove
00836 # define ulxr_fclose std::fclose
00837 # define ulxr_sprintf std::sprintf
00838
00839 #if defined(__CYGWIN__)
00840 # define ulxr_snprintf snprintf
00841 #else
00842 # define ulxr_snprintf std::snprintf
00843 #endif
00844
00845 # define ulxr_swprintf std::swprintf
00846 # define ulxr_time_t std::time_t
00847 # define ulxr_ctime std::ctime
00848 # define ulxr_localtime std::localtime
00849 # define ulxr_time std::time
00850 # define ulxr_tm std::tm
00851 # define ulxr_stricmp std::stricmp
00852 #endif
00853
00854
00855 #if defined (_MSC_VER)
00856
00857 #include <iosfwd>
00858
00859 inline std::ostream& operator<< (std::ostream& strm, const ulxr::Cpp8BitString &s)
00860 {
00861 char* p=(char*)s.c_str();
00862 return (strm << p);
00863 }
00864
00865 #if defined (ULXR_UNICODE) || defined(ULXR_UNICODE_ONLY_HELPERS)
00866
00867 inline std::wostream& operator<< (std::wostream& strm, const ulxr::Cpp16BitString &s)
00868 {
00869 wchar_t* p=(wchar_t*)s.c_str();
00870 return (strm << p);
00871 }
00872
00873 #endif
00874
00875 #endif
00876
00877 #endif // ULXR_H