initial load of upstream version 1.06.32
[xmlrpc-c] / src / cpp / libwww.cpp
1 /*=============================================================================
2                                 libwww.cpp
3 ===============================================================================
4   This is the Libwww XML transport of the C++ XML-RPC client library for
5   Xmlrpc-c.
6 =============================================================================*/
7
8 #include <stdlib.h>
9 #include <cassert>
10 #include <string>
11
12 #include "xmlrpc-c/girerr.hpp"
13 using girerr::error;
14 using girerr::throwf;
15 #include "xmlrpc-c/girmem.hpp"
16 using girmem::autoObjectPtr;
17 using girmem::autoObject;
18 #include "env_wrap.hpp"
19 #include "xmlrpc-c/base.h"
20 #include "xmlrpc-c/client.h"
21 #include "xmlrpc-c/transport.h"
22 #include "xmlrpc-c/base_int.h"
23
24 #include "xmlrpc_libwww_transport.h"
25
26 /* transport_config.h defines MUST_BUILD_LIBWWW_CLIENT */
27 #include "transport_config.h"
28
29 #include "xmlrpc-c/client_transport.hpp"
30
31
32 using namespace std;
33 using namespace xmlrpc_c;
34
35
36 namespace {
37
38 class globalConstant {
39 public:
40     globalConstant();
41     ~globalConstant();
42 };
43
44
45
46 globalConstant::globalConstant() {
47
48     // Not thread safe
49
50     xmlrpc_transport_setup setupFn;
51
52 #if MUST_BUILD_LIBWWW_CLIENT
53     setupFn = xmlrpc_libwww_transport_ops.setup_global_const;
54 #else
55     setupFn = NULL;
56 #endif
57     if (setupFn) {
58         env_wrap env;
59
60         setupFn(&env.env_c); // Not thread safe
61
62         if (env.env_c.fault_occurred)
63             throwf("Failed to do global initialization "
64                    "of Libwww transport code.  %s", env.env_c.fault_string);
65     }
66 }
67
68
69
70 globalConstant::~globalConstant() {
71
72     // Not thread safe
73
74     xmlrpc_transport_teardown teardownFn;
75
76 #if MUST_BUILD_LIBWWW_CLIENT
77     teardownFn = xmlrpc_libwww_transport_ops.teardown_global_const;
78 #else
79     teardownFn = NULL;
80 #endif
81     if (teardownFn)
82         teardownFn();  // not thread safe
83 }
84
85
86 globalConstant globalConst;
87     // This object is never accessed.  Its whole purpose to to be born and
88     // to die, which it does automatically as part of C++ program
89     // program initialization and termination.
90
91 } // namespace
92
93
94 namespace xmlrpc_c {
95
96 carriageParm_libwww0::carriageParm_libwww0(
97     string const serverUrl
98     ) {
99
100     this->instantiate(serverUrl);
101 }
102
103
104
105 carriageParm_libwww0Ptr::carriageParm_libwww0Ptr() {
106     // Base class constructor will construct pointer that points to nothing
107 }
108
109
110
111 carriageParm_libwww0Ptr::carriageParm_libwww0Ptr(
112     carriageParm_libwww0 * const carriageParmP) {
113     this->point(carriageParmP);
114 }
115
116
117
118 carriageParm_libwww0 *
119 carriageParm_libwww0Ptr::operator->() const {
120
121     autoObject * const p(this->objectP);
122     return dynamic_cast<carriageParm_libwww0 *>(p);
123 }
124
125
126
127 #if MUST_BUILD_LIBWWW_CLIENT
128
129 clientXmlTransport_libwww::clientXmlTransport_libwww(
130     string const appname,
131     string const appversion) {
132
133     this->c_transportOpsP = &xmlrpc_libwww_transport_ops;
134
135     env_wrap env;
136
137     xmlrpc_libwww_transport_ops.create(
138         &env.env_c, 0, appname.c_str(), appversion.c_str(), NULL, 0,
139         &this->c_transportP);
140
141     if (env.env_c.fault_occurred)
142         throw(error(env.env_c.fault_string));
143 }
144
145 #else  // MUST_BUILD_LIBWWW_CLIENT
146  clientXmlTransport_libwww::clientXmlTransport_libwww(string, string) {
147
148     throw(error("There is no Libwww client XML transport "
149                 "in this XML-RPC client library"));
150 }
151
152 #endif
153
154
155 clientXmlTransport_libwww::~clientXmlTransport_libwww() {
156
157     this->c_transportOpsP->destroy(this->c_transportP);
158 }
159
160 } // namespace