-
Notifications
You must be signed in to change notification settings - Fork 0
/
soapService.cpp
283 lines (248 loc) · 7.57 KB
/
soapService.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/* soapService.cpp
Generated by gSOAP 2.8.60 for hello.h
gSOAP XML Web services tools
Copyright (C) 2000-2018, Robert van Engelen, Genivia Inc. All Rights Reserved.
The soapcpp2 tool and its generated software are released under the GPL.
This program is released under the GPL with the additional exemption that
compiling, linking, and/or using OpenSSL is allowed.
--------------------------------------------------------------------------------
A commercial use license is available from Genivia Inc., [email protected]
--------------------------------------------------------------------------------
*/
#include "soapService.h"
Service::Service()
{ this->soap = soap_new();
this->soap_own = true;
Service_init(SOAP_IO_DEFAULT, SOAP_IO_DEFAULT);
}
Service::Service(const Service& rhs)
{ this->soap = rhs.soap;
this->soap_own = false;
}
Service::Service(struct soap *_soap)
{ this->soap = _soap;
this->soap_own = false;
Service_init(_soap->imode, _soap->omode);
}
Service::Service(soap_mode iomode)
{ this->soap = soap_new();
this->soap_own = true;
Service_init(iomode, iomode);
}
Service::Service(soap_mode imode, soap_mode omode)
{ this->soap = soap_new();
this->soap_own = true;
Service_init(imode, omode);
}
Service::~Service()
{ if (this->soap_own)
soap_free(this->soap);
}
void Service::Service_init(soap_mode imode, soap_mode omode)
{ soap_imode(this->soap, imode);
soap_omode(this->soap, omode);
static const struct Namespace namespaces[] = {
{"SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/", "http://www.w3.org/*/soap-envelope", NULL},
{"SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/", "http://www.w3.org/*/soap-encoding", NULL},
{"xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/*/XMLSchema-instance", NULL},
{"xsd", "http://www.w3.org/2001/XMLSchema", "http://www.w3.org/*/XMLSchema", NULL},
{"ns", "http://tempuri.org/ns.xsd", NULL, NULL},
{NULL, NULL, NULL, NULL}
};
soap_set_namespaces(this->soap, namespaces);
}
void Service::destroy()
{ soap_destroy(this->soap);
soap_end(this->soap);
}
void Service::reset()
{ this->destroy();
soap_done(this->soap);
soap_initialize(this->soap);
Service_init(SOAP_IO_DEFAULT, SOAP_IO_DEFAULT);
}
#ifndef WITH_PURE_VIRTUAL
Service *Service::copy()
{ Service *dup = SOAP_NEW_UNMANAGED(Service);
if (dup)
soap_copy_context(dup->soap, this->soap);
return dup;
}
#endif
Service& Service::operator=(const Service& rhs)
{ if (this->soap != rhs.soap)
{ if (this->soap_own)
soap_free(this->soap);
this->soap = rhs.soap;
this->soap_own = false;
}
return *this;
}
int Service::soap_close_socket()
{ return soap_closesock(this->soap);
}
int Service::soap_force_close_socket()
{ return soap_force_closesock(this->soap);
}
int Service::soap_senderfault(const char *string, const char *detailXML)
{ return ::soap_sender_fault(this->soap, string, detailXML);
}
int Service::soap_senderfault(const char *subcodeQName, const char *string, const char *detailXML)
{ return ::soap_sender_fault_subcode(this->soap, subcodeQName, string, detailXML);
}
int Service::soap_receiverfault(const char *string, const char *detailXML)
{ return ::soap_receiver_fault(this->soap, string, detailXML);
}
int Service::soap_receiverfault(const char *subcodeQName, const char *string, const char *detailXML)
{ return ::soap_receiver_fault_subcode(this->soap, subcodeQName, string, detailXML);
}
void Service::soap_print_fault(FILE *fd)
{ ::soap_print_fault(this->soap, fd);
}
#ifndef WITH_LEAN
#ifndef WITH_COMPAT
void Service::soap_stream_fault(std::ostream& os)
{ ::soap_stream_fault(this->soap, os);
}
#endif
char *Service::soap_sprint_fault(char *buf, size_t len)
{ return ::soap_sprint_fault(this->soap, buf, len);
}
#endif
void Service::soap_noheader()
{ this->soap->header = NULL;
}
::SOAP_ENV__Header *Service::soap_header()
{ return this->soap->header;
}
#ifndef WITH_NOIO
int Service::run(int port)
{ if (!soap_valid_socket(this->soap->master) && !soap_valid_socket(this->bind(NULL, port, 100)))
return this->soap->error;
for (;;)
{ if (!soap_valid_socket(this->accept()))
{ if (this->soap->errnum == 0) // timeout?
this->soap->error = SOAP_OK;
break;
}
if (this->serve())
break;
this->destroy();
}
return this->soap->error;
}
#if defined(WITH_OPENSSL) || defined(WITH_GNUTLS)
int Service::ssl_run(int port)
{ if (!soap_valid_socket(this->soap->master) && !soap_valid_socket(this->bind(NULL, port, 100)))
return this->soap->error;
for (;;)
{ if (!soap_valid_socket(this->accept()))
{ if (this->soap->errnum == 0) // timeout?
this->soap->error = SOAP_OK;
break;
}
if (this->ssl_accept() || this->serve())
break;
this->destroy();
}
return this->soap->error;
}
#endif
SOAP_SOCKET Service::bind(const char *host, int port, int backlog)
{ return soap_bind(this->soap, host, port, backlog);
}
SOAP_SOCKET Service::accept()
{ return soap_accept(this->soap);
}
#if defined(WITH_OPENSSL) || defined(WITH_GNUTLS)
int Service::ssl_accept()
{ return soap_ssl_accept(this->soap);
}
#endif
#endif
int Service::serve()
{
#ifndef WITH_FASTCGI
this->soap->keep_alive = this->soap->max_keep_alive + 1;
#endif
do
{
#ifndef WITH_FASTCGI
if (this->soap->keep_alive > 0 && this->soap->max_keep_alive > 0)
this->soap->keep_alive--;
#endif
if (soap_begin_serve(this->soap))
{ if (this->soap->error >= SOAP_STOP)
continue;
return this->soap->error;
}
if ((dispatch() || (this->soap->fserveloop && this->soap->fserveloop(this->soap))) && this->soap->error && this->soap->error < SOAP_STOP)
{
#ifdef WITH_FASTCGI
soap_send_fault(this->soap);
#else
return soap_send_fault(this->soap);
#endif
}
#ifdef WITH_FASTCGI
soap_destroy(this->soap);
soap_end(this->soap);
} while (1);
#else
} while (this->soap->keep_alive);
#endif
return SOAP_OK;
}
static int serve_ns__hello(struct soap*, Service*);
int Service::dispatch()
{ return dispatch(this->soap);
}
int Service::dispatch(struct soap* soap)
{
Service_init(soap->imode, soap->omode);
soap_peek_element(soap);
if (!soap_match_tag(soap, soap->tag, "ns:hello"))
return serve_ns__hello(soap, this);
return soap->error = SOAP_NO_METHOD;
}
static int serve_ns__hello(struct soap *soap, Service *service)
{ struct ns__hello soap_tmp_ns__hello;
struct ns__helloResponse soap_tmp_ns__helloResponse;
soap_default_ns__helloResponse(soap, &soap_tmp_ns__helloResponse);
soap_default_ns__hello(soap, &soap_tmp_ns__hello);
if (!soap_get_ns__hello(soap, &soap_tmp_ns__hello, "ns:hello", NULL))
return soap->error;
if (soap_body_end_in(soap)
|| soap_envelope_end_in(soap)
|| soap_end_recv(soap))
return soap->error;
soap->error = service->hello(soap_tmp_ns__hello.input, soap_tmp_ns__helloResponse.output);
if (soap->error)
return soap->error;
soap->encodingStyle = NULL;
soap_serializeheader(soap);
soap_serialize_ns__helloResponse(soap, &soap_tmp_ns__helloResponse);
if (soap_begin_count(soap))
return soap->error;
if (soap->mode & SOAP_IO_LENGTH)
{ if (soap_envelope_begin_out(soap)
|| soap_putheader(soap)
|| soap_body_begin_out(soap)
|| soap_put_ns__helloResponse(soap, &soap_tmp_ns__helloResponse, "ns:helloResponse", "")
|| soap_body_end_out(soap)
|| soap_envelope_end_out(soap))
return soap->error;
};
if (soap_end_count(soap)
|| soap_response(soap, SOAP_OK)
|| soap_envelope_begin_out(soap)
|| soap_putheader(soap)
|| soap_body_begin_out(soap)
|| soap_put_ns__helloResponse(soap, &soap_tmp_ns__helloResponse, "ns:helloResponse", "")
|| soap_body_end_out(soap)
|| soap_envelope_end_out(soap)
|| soap_end_send(soap))
return soap->error;
return soap_closesock(soap);
}
/* End of server object code */