-
Notifications
You must be signed in to change notification settings - Fork 0
/
stdsoap2.cpp
16531 lines (16107 loc) · 475 KB
/
stdsoap2.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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
stdsoap2.c[pp] 2.8.13
gSOAP runtime engine
gSOAP XML Web services tools
Copyright (C) 2000-2013, Robert van Engelen, Genivia Inc., All Rights Reserved.
This part of the software is released under ONE of the following licenses:
GPL, or the gSOAP public license, or Genivia's license for commercial use.
--------------------------------------------------------------------------------
Contributors:
Wind River Systems Inc., for the following additions under gSOAP public license:
- vxWorks compatible options
--------------------------------------------------------------------------------
gSOAP public license.
The contents of this file are subject to the gSOAP Public License Version 1.3
(the "License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at
http://www.cs.fsu.edu/~engelen/soaplicense.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the License.
The Initial Developer of the Original Code is Robert A. van Engelen.
Copyright (C) 2000-2013, Robert van Engelen, Genivia Inc., All Rights Reserved.
--------------------------------------------------------------------------------
GPL license.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program 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 GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
Author contact information:
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]
--------------------------------------------------------------------------------
*/
#define GSOAP_LIB_VERSION 20813
#ifdef AS400
# pragma convert(819) /* EBCDIC to ASCII */
#endif
#include "stdsoap2.h"
#if defined(VXWORKS) && defined(WM_SECURE_KEY_STORAGE)
#include <ipcom_key_db.h>
#endif
#if GSOAP_VERSION != GSOAP_LIB_VERSION
# error "GSOAP VERSION MISMATCH IN LIBRARY: PLEASE REINSTALL PACKAGE"
#endif
#ifdef __BORLANDC__
# pragma warn -8060
#else
# ifdef WIN32
# ifdef UNDER_CE
# pragma comment(lib, "ws2.lib") /* WinCE */
# else
# pragma comment(lib, "ws2_32.lib")
# endif
# pragma warning(disable : 4996) /* disable deprecation warnings */
# endif
#endif
#ifdef __cplusplus
SOAP_SOURCE_STAMP("@(#) stdsoap2.cpp ver 2.8.13 2013-01-21 00:00:00 GMT")
extern "C" {
#else
SOAP_SOURCE_STAMP("@(#) stdsoap2.c ver 2.8.13 2013-01-21 00:00:00 GMT")
#endif
/* 8bit character representing unknown/nonrepresentable character data (e.g. not supported by current locale with multibyte support enabled) */
#ifndef SOAP_UNKNOWN_CHAR
#define SOAP_UNKNOWN_CHAR (127)
#endif
/* EOF=-1 */
#define SOAP_LT (soap_wchar)(-2) /* XML-specific '<' */
#define SOAP_TT (soap_wchar)(-3) /* XML-specific '</' */
#define SOAP_GT (soap_wchar)(-4) /* XML-specific '>' */
#define SOAP_QT (soap_wchar)(-5) /* XML-specific '"' */
#define SOAP_AP (soap_wchar)(-6) /* XML-specific ''' */
#define soap_blank(c) ((c)+1 > 0 && (c) <= 32)
#define soap_notblank(c) ((c) > 32)
#if defined(WIN32) && !defined(UNDER_CE)
#define soap_hash_ptr(p) ((PtrToUlong(p) >> 3) & (SOAP_PTRHASH - 1))
#else
#define soap_hash_ptr(p) ((size_t)(((unsigned long)(p) >> 3) & (SOAP_PTRHASH-1)))
#endif
#if !defined(WITH_LEAN) || defined(SOAP_DEBUG)
static void soap_init_logs(struct soap*);
#endif
#ifdef SOAP_DEBUG
static void soap_close_logfile(struct soap*, int);
static void soap_set_logfile(struct soap*, int, const char*);
#endif
#ifdef SOAP_MEM_DEBUG
static void soap_init_mht(struct soap*);
static void soap_free_mht(struct soap*);
static void soap_track_unlink(struct soap*, const void*);
#endif
#ifndef PALM_2
static int soap_set_error(struct soap*, const char*, const char*, const char*, const char*, int);
static int soap_copy_fault(struct soap*, const char*, const char*, const char*, const char*);
static int soap_getattrval(struct soap*, char*, size_t, soap_wchar);
#endif
#ifndef PALM_1
static void soap_free_ns(struct soap *soap);
static soap_wchar soap_char(struct soap*);
static soap_wchar soap_get_pi(struct soap*);
static int soap_isxdigit(int);
static void *fplugin(struct soap*, const char*);
static size_t soap_count_attachments(struct soap *soap);
static int soap_try_connect_command(struct soap*, int http_command, const char *endpoint, const char *action);
#ifdef WITH_NTLM
static int soap_ntlm_handshake(struct soap *soap, int command, const char *endpoint, const char *host, int port);
#endif
#ifndef WITH_NOIDREF
static int soap_has_copies(struct soap*, const char*, const char*);
static void soap_init_iht(struct soap*);
static void soap_free_iht(struct soap*);
static void soap_init_pht(struct soap*);
static void soap_free_pht(struct soap*);
#endif
#endif
#ifndef WITH_LEAN
static const char *soap_set_validation_fault(struct soap*, const char*, const char*);
static int soap_isnumeric(struct soap*, const char*);
static struct soap_nlist *soap_push_ns(struct soap *soap, const char *id, const char *ns, short utilized);
static void soap_utilize_ns(struct soap *soap, const char *tag);
#endif
#ifndef WITH_LEANER
#ifndef PALM_1
static struct soap_multipart *soap_new_multipart(struct soap*, struct soap_multipart**, struct soap_multipart**, char*, size_t);
static int soap_putdimefield(struct soap*, const char*, size_t);
static char *soap_getdimefield(struct soap*, size_t);
static void soap_select_mime_boundary(struct soap*);
static int soap_valid_mime_boundary(struct soap*);
static void soap_resolve_attachment(struct soap*, struct soap_multipart*);
#endif
#endif
#ifdef WITH_GZIP
static int soap_getgziphdr(struct soap*);
#endif
#ifdef WITH_OPENSSL
# ifndef SOAP_SSL_RSA_BITS
# define SOAP_SSL_RSA_BITS 2048
# endif
static int soap_ssl_init_done = 0;
static int ssl_auth_init(struct soap*);
static int ssl_verify_callback(int, X509_STORE_CTX*);
static int ssl_verify_callback_allow_expired_certificate(int, X509_STORE_CTX*);
static int ssl_password(char*, int, int, void *);
#endif
#ifdef WITH_GNUTLS
# ifndef SOAP_SSL_RSA_BITS
# define SOAP_SSL_RSA_BITS 2048
# endif
static int soap_ssl_init_done = 0;
static const char *ssl_verify(struct soap *soap, const char *host);
# if defined(HAVE_PTHREAD_H)
# include <pthread.h>
/* make GNUTLS thread safe with pthreads */
GCRY_THREAD_OPTION_PTHREAD_IMPL;
# elif defined(HAVE_PTH_H)
#include <pth.h>
/* make GNUTLS thread safe with PTH */
GCRY_THREAD_OPTION_PTH_IMPL;
# endif
#endif
#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER)
#ifndef PALM_1
static const char *soap_decode(char*, size_t, const char*, const char*);
#endif
#endif
#ifndef WITH_NOHTTP
#ifndef PALM_1
static soap_wchar soap_getchunkchar(struct soap*);
static const char *http_error(struct soap*, int);
static int http_get(struct soap*);
static int http_405(struct soap*);
static int http_200(struct soap*);
static int http_post(struct soap*, const char*, const char*, int, const char*, const char*, size_t);
static int http_send_header(struct soap*, const char*);
static int http_post_header(struct soap*, const char*, const char*);
static int http_response(struct soap*, int, size_t);
static int http_parse(struct soap*);
static int http_parse_header(struct soap*, const char*, const char*);
#endif
#endif
#ifndef WITH_NOIO
#ifndef PALM_1
static int fsend(struct soap*, const char*, size_t);
static size_t frecv(struct soap*, char*, size_t);
static int tcp_init(struct soap*);
static const char *tcp_error(struct soap*);
#ifndef WITH_IPV6
static int tcp_gethost(struct soap*, const char *addr, struct in_addr *inaddr);
#endif
static SOAP_SOCKET tcp_connect(struct soap*, const char *endpoint, const char *host, int port);
static SOAP_SOCKET tcp_accept(struct soap*, SOAP_SOCKET, struct sockaddr*, int*);
static int tcp_select(struct soap*, SOAP_SOCKET, int, int);
static int tcp_disconnect(struct soap*);
static int tcp_closesocket(struct soap*, SOAP_SOCKET);
static int tcp_shutdownsocket(struct soap*, SOAP_SOCKET, int);
static const char *soap_strerror(struct soap*);
#endif
#define SOAP_TCP_SELECT_RCV 0x1
#define SOAP_TCP_SELECT_SND 0x2
#define SOAP_TCP_SELECT_ERR 0x4
#define SOAP_TCP_SELECT_ALL 0x7
#if defined(WIN32)
#define SOAP_SOCKBLOCK(fd) \
{ u_long blocking = 0; \
ioctlsocket(fd, FIONBIO, &blocking); \
}
#define SOAP_SOCKNONBLOCK(fd) \
{ u_long nonblocking = 1; \
ioctlsocket(fd, FIONBIO, &nonblocking); \
}
#elif defined(VXWORKS)
#define SOAP_SOCKBLOCK(fd) \
{ u_long blocking = 0; \
ioctl(fd, FIONBIO, (int)(&blocking)); \
}
#define SOAP_SOCKNONBLOCK(fd) \
{ u_long nonblocking = 1; \
ioctl(fd, FIONBIO, (int)(&nonblocking)); \
}
#elif defined(__VMS)
#define SOAP_SOCKBLOCK(fd) \
{ int blocking = 0; \
ioctl(fd, FIONBIO, &blocking); \
}
#define SOAP_SOCKNONBLOCK(fd) \
{ int nonblocking = 1; \
ioctl(fd, FIONBIO, &nonblocking); \
}
#elif defined(PALM)
#define SOAP_SOCKBLOCK(fd) fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0)&~O_NONBLOCK);
#define SOAP_SOCKNONBLOCK(fd) fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0)|O_NONBLOCK);
#elif defined(SYMBIAN)
#define SOAP_SOCKBLOCK(fd) \
{ long blocking = 0; \
ioctl(fd, 0/*FIONBIO*/, &blocking); \
}
#define SOAP_SOCKNONBLOCK(fd) \
{ long nonblocking = 1; \
ioctl(fd, 0/*FIONBIO*/, &nonblocking); \
}
#else
#define SOAP_SOCKBLOCK(fd) fcntl(fd, F_SETFL, fcntl(fd, F_GETFL)&~O_NONBLOCK);
#define SOAP_SOCKNONBLOCK(fd) fcntl(fd, F_SETFL, fcntl(fd, F_GETFL)|O_NONBLOCK);
#endif
#endif
#if defined(PALM) && !defined(PALM_2)
unsigned short errno;
#endif
#ifndef PALM_1
static const char soap_env1[42] = "http://schemas.xmlsoap.org/soap/envelope/";
static const char soap_enc1[42] = "http://schemas.xmlsoap.org/soap/encoding/";
static const char soap_env2[40] = "http://www.w3.org/2003/05/soap-envelope";
static const char soap_enc2[40] = "http://www.w3.org/2003/05/soap-encoding";
static const char soap_rpc[35] = "http://www.w3.org/2003/05/soap-rpc";
#endif
#ifndef PALM_1
const union soap_double_nan soap_double_nan = {{0xFFFFFFFF, 0xFFFFFFFF}};
const char soap_base64o[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const char soap_base64i[81] = "\76XXX\77\64\65\66\67\70\71\72\73\74\75XXXXXXX\00\01\02\03\04\05\06\07\10\11\12\13\14\15\16\17\20\21\22\23\24\25\26\27\30\31XXXXXX\32\33\34\35\36\37\40\41\42\43\44\45\46\47\50\51\52\53\54\55\56\57\60\61\62\63";
#endif
#ifndef WITH_LEAN
static const char soap_indent[11] = "\n\t\t\t\t\t\t\t\t\t";
/* Alternative indentation form for SOAP_XML_INDENT:
static const char soap_indent[21] = "\n ";
*/
#endif
#ifndef SOAP_CANARY
# define SOAP_CANARY (0xC0DE)
#endif
static const char soap_padding[4] = "\0\0\0";
#define SOAP_STR_PADDING (soap_padding)
#define SOAP_STR_EOS (soap_padding)
#define SOAP_NON_NULL (soap_padding)
#ifndef WITH_LEAN
static const struct soap_code_map html_entity_codes[] = /* entities for XHTML parsing */
{ { 160, "nbsp" },
{ 161, "iexcl" },
{ 162, "cent" },
{ 163, "pound" },
{ 164, "curren" },
{ 165, "yen" },
{ 166, "brvbar" },
{ 167, "sect" },
{ 168, "uml" },
{ 169, "copy" },
{ 170, "ordf" },
{ 171, "laquo" },
{ 172, "not" },
{ 173, "shy" },
{ 174, "reg" },
{ 175, "macr" },
{ 176, "deg" },
{ 177, "plusmn" },
{ 178, "sup2" },
{ 179, "sup3" },
{ 180, "acute" },
{ 181, "micro" },
{ 182, "para" },
{ 183, "middot" },
{ 184, "cedil" },
{ 185, "sup1" },
{ 186, "ordm" },
{ 187, "raquo" },
{ 188, "frac14" },
{ 189, "frac12" },
{ 190, "frac34" },
{ 191, "iquest" },
{ 192, "Agrave" },
{ 193, "Aacute" },
{ 194, "Acirc" },
{ 195, "Atilde" },
{ 196, "Auml" },
{ 197, "Aring" },
{ 198, "AElig" },
{ 199, "Ccedil" },
{ 200, "Egrave" },
{ 201, "Eacute" },
{ 202, "Ecirc" },
{ 203, "Euml" },
{ 204, "Igrave" },
{ 205, "Iacute" },
{ 206, "Icirc" },
{ 207, "Iuml" },
{ 208, "ETH" },
{ 209, "Ntilde" },
{ 210, "Ograve" },
{ 211, "Oacute" },
{ 212, "Ocirc" },
{ 213, "Otilde" },
{ 214, "Ouml" },
{ 215, "times" },
{ 216, "Oslash" },
{ 217, "Ugrave" },
{ 218, "Uacute" },
{ 219, "Ucirc" },
{ 220, "Uuml" },
{ 221, "Yacute" },
{ 222, "THORN" },
{ 223, "szlig" },
{ 224, "agrave" },
{ 225, "aacute" },
{ 226, "acirc" },
{ 227, "atilde" },
{ 228, "auml" },
{ 229, "aring" },
{ 230, "aelig" },
{ 231, "ccedil" },
{ 232, "egrave" },
{ 233, "eacute" },
{ 234, "ecirc" },
{ 235, "euml" },
{ 236, "igrave" },
{ 237, "iacute" },
{ 238, "icirc" },
{ 239, "iuml" },
{ 240, "eth" },
{ 241, "ntilde" },
{ 242, "ograve" },
{ 243, "oacute" },
{ 244, "ocirc" },
{ 245, "otilde" },
{ 246, "ouml" },
{ 247, "divide" },
{ 248, "oslash" },
{ 249, "ugrave" },
{ 250, "uacute" },
{ 251, "ucirc" },
{ 252, "uuml" },
{ 253, "yacute" },
{ 254, "thorn" },
{ 255, "yuml" },
{ 0, NULL }
};
#endif
#ifndef WITH_NOIO
#ifndef WITH_LEAN
static const struct soap_code_map h_error_codes[] =
{
#ifdef HOST_NOT_FOUND
{ HOST_NOT_FOUND, "Host not found" },
#endif
#ifdef TRY_AGAIN
{ TRY_AGAIN, "Try Again" },
#endif
#ifdef NO_RECOVERY
{ NO_RECOVERY, "No Recovery" },
#endif
#ifdef NO_DATA
{ NO_DATA, "No Data" },
#endif
#ifdef NO_ADDRESS
{ NO_ADDRESS, "No Address" },
#endif
{ 0, NULL }
};
#endif
#endif
#ifndef WITH_NOHTTP
#ifndef WITH_LEAN
static const struct soap_code_map h_http_error_codes[] =
{ { 200, "OK" },
{ 201, "Created" },
{ 202, "Accepted" },
{ 203, "Non-Authoritative Information" },
{ 204, "No Content" },
{ 205, "Reset Content" },
{ 206, "Partial Content" },
{ 300, "Multiple Choices" },
{ 301, "Moved Permanently" },
{ 302, "Found" },
{ 303, "See Other" },
{ 304, "Not Modified" },
{ 305, "Use Proxy" },
{ 307, "Temporary Redirect" },
{ 400, "Bad Request" },
{ 401, "Unauthorized" },
{ 402, "Payment Required" },
{ 403, "Forbidden" },
{ 404, "Not Found" },
{ 405, "Method Not Allowed" },
{ 406, "Not Acceptable" },
{ 407, "Proxy Authentication Required" },
{ 408, "Request Time-out" },
{ 409, "Conflict" },
{ 410, "Gone" },
{ 411, "Length Required" },
{ 412, "Precondition Failed" },
{ 413, "Request Entity Too Large" },
{ 414, "Request-URI Too Large" },
{ 415, "Unsupported Media Type" },
{ 416, "Requested range not satisfiable" },
{ 417, "Expectation Failed" },
{ 500, "Internal Server Error" },
{ 501, "Not Implemented" },
{ 502, "Bad Gateway" },
{ 503, "Service Unavailable" },
{ 504, "Gateway Time-out" },
{ 505, "HTTP Version not supported" },
{ 0, NULL }
};
#endif
#endif
#ifdef WITH_OPENSSL
static const struct soap_code_map h_ssl_error_codes[] =
{
#define _SSL_ERROR(e) { e, #e }
_SSL_ERROR(SSL_ERROR_SSL),
_SSL_ERROR(SSL_ERROR_ZERO_RETURN),
_SSL_ERROR(SSL_ERROR_WANT_READ),
_SSL_ERROR(SSL_ERROR_WANT_WRITE),
_SSL_ERROR(SSL_ERROR_WANT_CONNECT),
_SSL_ERROR(SSL_ERROR_WANT_X509_LOOKUP),
_SSL_ERROR(SSL_ERROR_SYSCALL),
{ 0, NULL }
};
#endif
#ifndef WITH_LEANER
static const struct soap_code_map mime_codes[] =
{ { SOAP_MIME_7BIT, "7bit" },
{ SOAP_MIME_8BIT, "8bit" },
{ SOAP_MIME_BINARY, "binary" },
{ SOAP_MIME_QUOTED_PRINTABLE, "quoted-printable" },
{ SOAP_MIME_BASE64, "base64" },
{ SOAP_MIME_IETF_TOKEN, "ietf-token" },
{ SOAP_MIME_X_TOKEN, "x-token" },
{ 0, NULL }
};
#endif
#ifdef WIN32
static int tcp_done = 0;
#endif
#if defined(HP_UX) && defined(HAVE_GETHOSTBYNAME_R)
extern int h_errno;
#endif
/******************************************************************************/
#ifndef WITH_NOIO
#ifndef PALM_1
static int
fsend(struct soap *soap, const char *s, size_t n)
{ register int nwritten, err;
SOAP_SOCKET sk;
#if defined(__cplusplus) && !defined(WITH_LEAN) && !defined(WITH_COMPAT)
if (soap->os)
{ soap->os->write(s, (std::streamsize)n);
if (soap->os->good())
return SOAP_OK;
soap->errnum = 0;
return SOAP_EOF;
}
#endif
sk = soap->sendsk;
if (!soap_valid_socket(sk))
sk = soap->socket;
while (n)
{ if (soap_valid_socket(sk))
{
if (soap->send_timeout)
{ for (;;)
{ register int r;
#ifdef WITH_OPENSSL
if (soap->ssl)
r = tcp_select(soap, sk, SOAP_TCP_SELECT_ALL, soap->send_timeout);
else
#endif
#ifdef WITH_GNUTLS
if (soap->session)
r = tcp_select(soap, sk, SOAP_TCP_SELECT_ALL, soap->send_timeout);
else
#endif
r = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->send_timeout);
if (r > 0)
break;
if (!r)
return SOAP_EOF;
err = soap->errnum;
if (!err)
return soap->error;
if (err != SOAP_EINTR && err != SOAP_EAGAIN && err != SOAP_EWOULDBLOCK)
return SOAP_EOF;
}
}
#ifdef WITH_OPENSSL
if (soap->ssl)
nwritten = SSL_write(soap->ssl, s, (int)n);
else if (soap->bio)
nwritten = BIO_write(soap->bio, s, (int)n);
else
#endif
#ifdef WITH_GNUTLS
if (soap->session)
nwritten = gnutls_record_send(soap->session, s, n);
else
#endif
#ifndef WITH_LEAN
if ((soap->omode & SOAP_IO_UDP))
{ if (soap->peerlen)
nwritten = sendto(sk, (char*)s, (SOAP_WINSOCKINT)n, soap->socket_flags, (struct sockaddr*)&soap->peer, (SOAP_WINSOCKINT)soap->peerlen);
else
nwritten = send(sk, s, (SOAP_WINSOCKINT)n, soap->socket_flags);
/* retry and back-off algorithm */
/* TODO: this is not very clear from specs so verify and limit conditions under which we should loop (e.g. ENOBUFS) */
if (nwritten < 0)
{ int udp_repeat;
int udp_delay;
if ((soap->connect_flags & SO_BROADCAST))
udp_repeat = 2; /* SOAP-over-UDP MULTICAST_UDP_REPEAT - 1 */
else
udp_repeat = 1; /* SOAP-over-UDP UNICAST_UDP_REPEAT - 1 */
udp_delay = ((unsigned int)soap_random % 201) + 50; /* UDP_MIN_DELAY .. UDP_MAX_DELAY */
do
{ tcp_select(soap, sk, SOAP_TCP_SELECT_ERR, -1000 * udp_delay);
if (soap->peerlen)
nwritten = sendto(sk, (char*)s, (SOAP_WINSOCKINT)n, soap->socket_flags, (struct sockaddr*)&soap->peer, (SOAP_WINSOCKINT)soap->peerlen);
else
nwritten = send(sk, s, (SOAP_WINSOCKINT)n, soap->socket_flags);
udp_delay <<= 1;
if (udp_delay > 500) /* UDP_UPPER_DELAY */
udp_delay = 500;
}
while (nwritten < 0 && --udp_repeat > 0);
}
if (nwritten < 0)
{ err = soap_socket_errno(sk);
if (err && err != SOAP_EINTR)
{ soap->errnum = err;
return SOAP_EOF;
}
nwritten = 0; /* and call write() again */
}
}
else
#endif
#if !defined(PALM) && !defined(AS400)
nwritten = send(sk, s, (int)n, soap->socket_flags);
#else
nwritten = send(sk, (void*)s, n, soap->socket_flags);
#endif
if (nwritten <= 0)
{
register int r = 0;
err = soap_socket_errno(sk);
#ifdef WITH_OPENSSL
if (soap->ssl && (r = SSL_get_error(soap->ssl, nwritten)) != SSL_ERROR_NONE && r != SSL_ERROR_WANT_READ && r != SSL_ERROR_WANT_WRITE)
{ soap->errnum = err;
return SOAP_EOF;
}
#endif
#ifdef WITH_GNUTLS
if (soap->session)
{ if (nwritten == GNUTLS_E_INTERRUPTED)
err = SOAP_EINTR;
else if (nwritten == GNUTLS_E_AGAIN)
err = SOAP_EAGAIN;
}
#endif
if (err == SOAP_EWOULDBLOCK || err == SOAP_EAGAIN)
{
#if defined(WITH_OPENSSL)
if (soap->ssl && r == SSL_ERROR_WANT_READ)
r = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, soap->send_timeout ? soap->send_timeout : -10000);
else
#elif defined(WITH_GNUTLS)
if (soap->session && !gnutls_record_get_direction(soap->session))
r = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, soap->send_timeout ? soap->send_timeout : -10000);
else
#endif
r = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->send_timeout ? soap->send_timeout : -10000);
if (!r && soap->send_timeout)
return SOAP_EOF;
if (r < 0 && soap->errnum != SOAP_EINTR)
return SOAP_EOF;
}
else if (err && err != SOAP_EINTR)
{ soap->errnum = err;
return SOAP_EOF;
}
nwritten = 0; /* and call write() again */
}
}
else
{
#ifdef WITH_FASTCGI
nwritten = fwrite((void*)s, 1, n, stdout);
fflush(stdout);
#else
#ifdef UNDER_CE
nwritten = fwrite(s, 1, n, soap->sendfd);
#else
#ifdef VXWORKS
#ifdef WMW_RPM_IO
if (soap->rpmreqid)
nwritten = (httpBlockPut(soap->rpmreqid, (char*)s, n) == 0) ? n : -1;
else
#endif
nwritten = fwrite(s, sizeof(char), n, fdopen(soap->sendfd, "w"));
#else
#ifdef WIN32
nwritten = _write(soap->sendfd, s, (unsigned int)n);
#else
nwritten = write(soap->sendfd, s, (unsigned int)n);
#endif
#endif
#endif
#endif
if (nwritten <= 0)
{
#ifndef WITH_FASTCGI
err = soap_errno;
#else
err = EOF;
#endif
if (err && err != SOAP_EINTR && err != SOAP_EWOULDBLOCK && err != SOAP_EAGAIN)
{ soap->errnum = err;
return SOAP_EOF;
}
nwritten = 0; /* and call write() again */
}
}
n -= nwritten;
s += nwritten;
}
return SOAP_OK;
}
#endif
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_send_raw(struct soap *soap, const char *s, size_t n)
{ if (!n)
return SOAP_OK;
#ifndef WITH_LEANER
if (soap->fpreparesend && (soap->mode & SOAP_IO) != SOAP_IO_STORE && (soap->mode & SOAP_IO_LENGTH) && (soap->error = soap->fpreparesend(soap, s, n)))
return soap->error;
if (soap->ffiltersend && (soap->error = soap->ffiltersend(soap, &s, &n)))
return soap->error;
#endif
if (soap->mode & SOAP_IO_LENGTH)
soap->count += n;
else if (soap->mode & SOAP_IO)
{ register size_t i = SOAP_BUFLEN - soap->bufidx;
while (n >= i)
{ memcpy(soap->buf + soap->bufidx, s, i);
soap->bufidx = SOAP_BUFLEN;
if (soap_flush(soap))
return soap->error;
s += i;
n -= i;
i = SOAP_BUFLEN;
}
memcpy(soap->buf + soap->bufidx, s, n);
soap->bufidx += n;
}
else
return soap_flush_raw(soap, s, n);
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_flush(struct soap *soap)
{ register size_t n = soap->bufidx;
if (n)
{
#ifndef WITH_LEANER
if ((soap->mode & SOAP_IO) == SOAP_IO_STORE)
{ register int r;
if (soap->fpreparesend && (r = soap->fpreparesend(soap, soap->buf, n)))
return soap->error = r;
}
#endif
soap->bufidx = 0;
#ifdef WITH_ZLIB
if (soap->mode & SOAP_ENC_ZLIB)
{ soap->d_stream->next_in = (Byte*)soap->buf;
soap->d_stream->avail_in = (unsigned int)n;
#ifdef WITH_GZIP
soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)n);
#endif
do
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflating %u bytes\n", soap->d_stream->avail_in));
if (deflate(soap->d_stream, Z_NO_FLUSH) != Z_OK)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to deflate: %s\n", soap->d_stream->msg ? soap->d_stream->msg : SOAP_STR_EOS));
return soap->error = SOAP_ZLIB_ERROR;
}
if (!soap->d_stream->avail_out)
{ if (soap_flush_raw(soap, soap->z_buf, SOAP_BUFLEN))
return soap->error;
soap->d_stream->next_out = (Byte*)soap->z_buf;
soap->d_stream->avail_out = SOAP_BUFLEN;
}
} while (soap->d_stream->avail_in);
}
else
#endif
return soap_flush_raw(soap, soap->buf, n);
}
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_flush_raw(struct soap *soap, const char *s, size_t n)
{ if ((soap->mode & SOAP_IO) == SOAP_IO_STORE)
{ register char *t;
if (!(t = (char*)soap_push_block(soap, NULL, n)))
return soap->error = SOAP_EOM;
memcpy(t, s, n);
return SOAP_OK;
}
#ifndef WITH_LEANER
if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK)
{ char t[16];
sprintf(t, &"\r\n%lX\r\n"[soap->chunksize ? 0 : 2], (unsigned long)n);
DBGMSG(SENT, t, strlen(t));
if ((soap->error = soap->fsend(soap, t, strlen(t))))
return soap->error;
soap->chunksize += n;
}
DBGMSG(SENT, s, n);
#endif
return soap->error = soap->fsend(soap, s, n);
}
#endif
/******************************************************************************/
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_send(struct soap *soap, const char *s)
{ if (s)
return soap_send_raw(soap, s, strlen(s));
return SOAP_OK;
}
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_send2(struct soap *soap, const char *s1, const char *s2)
{ if (soap_send(soap, s1))
return soap->error;
return soap_send(soap, s2);
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_LEANER
#ifndef PALM_1
SOAP_FMAC1
int
SOAP_FMAC2
soap_send3(struct soap *soap, const char *s1, const char *s2, const char *s3)
{ if (soap_send(soap, s1)
|| soap_send(soap, s2))
return soap->error;
return soap_send(soap, s3);
}
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIO
#ifndef PALM_1
static size_t
frecv(struct soap *soap, char *s, size_t n)
{ register int r;
register int retries = 100; /* max 100 retries with non-blocking sockets */
SOAP_SOCKET sk;
soap->errnum = 0;
#if defined(__cplusplus) && !defined(WITH_LEAN) && !defined(WITH_COMPAT)
if (soap->is)
{ if (soap->is->good())
return soap->is->read(s, (std::streamsize)n).gcount();
return 0;
}
#endif
sk = soap->recvsk;
if (!soap_valid_socket(sk))
sk = soap->socket;
if (soap_valid_socket(sk))
{ for (;;)
{
#ifdef WITH_OPENSSL
register int err = 0;
#endif
#ifdef WITH_OPENSSL
if (soap->recv_timeout && !soap->ssl) /* SSL: sockets are nonblocking */
#else
if (soap->recv_timeout)
#endif
{ for (;;)
{ r = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, soap->recv_timeout);
if (r > 0)
break;
if (!r)
return 0;
r = soap->errnum;
if (r != SOAP_EINTR && r != SOAP_EAGAIN && r != SOAP_EWOULDBLOCK)
return 0;
}
}
#ifdef WITH_OPENSSL
if (soap->ssl)
{ r = SSL_read(soap->ssl, s, (int)n);
if (r > 0)
return (size_t)r;
err = SSL_get_error(soap->ssl, r);
if (err != SSL_ERROR_NONE && err != SSL_ERROR_WANT_READ && err != SSL_ERROR_WANT_WRITE)
return 0;
}
else if (soap->bio)
{ r = BIO_read(soap->bio, s, (int)n);
if (r > 0)
return (size_t)r;
return 0;
}
else
#endif
#ifdef WITH_GNUTLS
if (soap->session)
{ r = (int)gnutls_record_recv(soap->session, s, n);
if (r >= 0)
return (size_t)r;
}
else
#endif
{
#ifndef WITH_LEAN
if ((soap->omode & SOAP_IO_UDP))
{ SOAP_SOCKLEN_T k = (SOAP_SOCKLEN_T)sizeof(soap->peer);
memset((void*)&soap->peer, 0, sizeof(soap->peer));
r = recvfrom(sk, s, (SOAP_WINSOCKINT)n, soap->socket_flags, (struct sockaddr*)&soap->peer, &k); /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */
soap->peerlen = (size_t)k;
#ifndef WITH_IPV6
soap->ip = ntohl(soap->peer.sin_addr.s_addr);
#endif
}
else
#endif
r = recv(sk, s, (int)n, soap->socket_flags);
#ifdef PALM
/* CycleSyncDisplay(curStatusMsg); */
#endif
if (r >= 0)
return (size_t)r;
r = soap_socket_errno(sk);
if (r != SOAP_EINTR && r != SOAP_EAGAIN && r != SOAP_EWOULDBLOCK)
{ soap->errnum = r;
return 0;
}
}
#if defined(WITH_OPENSSL)
if (soap->ssl && err == SSL_ERROR_WANT_WRITE)
r = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->recv_timeout ? soap->recv_timeout : 5);
else
#elif defined(WITH_GNUTLS)
if (soap->session && gnutls_record_get_direction(soap->session))
r = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->recv_timeout ? soap->recv_timeout : 5);
else
#endif
r = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, soap->recv_timeout ? soap->recv_timeout : 5);
if (!r && soap->recv_timeout)
return 0;
if (r < 0)
{ r = soap->errnum;
if (r != SOAP_EINTR && r != SOAP_EAGAIN && r != SOAP_EWOULDBLOCK)
return 0;
}
if (retries-- <= 0)
return 0;
#ifdef PALM
r = soap_socket_errno(sk);
if (r != SOAP_EINTR && retries-- <= 0)
{ soap->errnum = r;
return 0;
}
#endif
}
}
#ifdef WITH_FASTCGI
return fread(s, 1, n, stdin);
#else
#ifdef UNDER_CE
return fread(s, 1, n, soap->recvfd);
#else