-
Notifications
You must be signed in to change notification settings - Fork 0
/
stdsoap2.c
23653 lines (22708 loc) · 645 KB
/
stdsoap2.c
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.129
gSOAP runtime engine
gSOAP XML Web services tools
Copyright (C) 2000-2023, 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.
--------------------------------------------------------------------------------
Contributors:
Wind River Systems, Inc., for the following addition licensed under the gSOAP
public license:
- vxWorks compatible, enabled with compiler option -DVXWORKS
--------------------------------------------------------------------------------
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-2023, 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 208129
/* silence GNU's warnings on format nonliteral strings and truncation (snprintf truncates on purpose for safety) */
#ifdef __GNUC__
# define GCC_VERSION_AT_LEAST(major, minor, patch) (GCC_VERSION >= (major * 10000 + minor * 100 + patch))
# pragma GCC diagnostic ignored "-Wformat-nonliteral"
# if GCC_VERSION_AT_LEAST(7, 0, 0)
# pragma GCC diagnostic ignored "-Wformat-truncation"
# endif
#endif
/* convert EBCDIC to ASCII */
#ifdef AS400
# pragma convert(819)
#endif
#if defined(__gnu_linux__) && !defined(_GNU_SOURCE)
# define _GNU_SOURCE 1
#endif
#include "stdsoap2.h"
#if GSOAP_VERSION != GSOAP_LIB_VERSION
# error "GSOAP VERSION MISMATCH IN LIBRARY: PLEASE REINSTALL PACKAGE"
#endif
#if defined(VXWORKS) && defined(WM_SECURE_KEY_STORAGE)
# include <ipcom_key_db.h> /* vxWorks compatible */
#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 visual studio POSIX deprecation warnings */
# endif
#endif
#ifdef __cplusplus
SOAP_SOURCE_STAMP("@(#) stdsoap2.cpp ver 2.8.129 2023-06-11 00:00:00 GMT")
extern "C" {
#else
SOAP_SOURCE_STAMP("@(#) stdsoap2.c ver 2.8.129 2023-06-11 00:00:00 GMT")
#endif
/* 8bit character representing unknown character entity or multibyte data */
#ifndef SOAP_UNKNOWN_CHAR
# define SOAP_UNKNOWN_CHAR (0x7F)
#endif
/* unicode character representing unknown characters outside the XML 1.0 UTF8 unicode space */
#ifdef WITH_REPLACE_ILLEGAL_UTF8
# ifndef SOAP_UNKNOWN_UNICODE_CHAR
# define SOAP_UNKNOWN_UNICODE_CHAR (0xFFFD)
# endif
#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_coblank(c) ((c)+1 > 0 && (c) <= 32)
#if defined(WIN32) && !defined(UNDER_CE)
#define soap_hash_ptr(p) ((size_t)((PtrToUlong(p) >> 3) & (SOAP_PTRHASH - 1)))
#else
#define soap_hash_ptr(p) ((size_t)(((unsigned long)(p) >> 3) & (SOAP_PTRHASH-1)))
#endif
#ifdef SOAP_DEBUG
static void soap_init_logs(struct soap*);
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
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);
static void soap_version(struct soap*);
static void soap_free_ns(struct soap*);
static soap_wchar soap_char(struct soap*);
static soap_wchar soap_getpi(struct soap*);
static int soap_isxdigit(int);
static void *fplugin(struct soap*, const char*);
static ULONG64 soap_count_attachments(struct soap*);
static int soap_try_connect_command(struct soap*, int http_command, const char *endpoint, const char *action);
static int soap_init_send(struct soap*);
#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 int soap_type_punned(struct soap*, const struct soap_ilist*);
static int soap_is_shaky(struct soap*, void*);
static void soap_init_iht(struct soap*);
static void soap_free_iht(struct soap*);
#endif
static void soap_init_pht(struct soap*);
static void soap_free_pht(struct soap*);
#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, short isearly);
static void soap_utilize_ns(struct soap *soap, const char *tag, short isearly);
static const wchar_t* soap_wstring(struct soap *soap, const char *s, int flag, long minlen, long maxlen, const char *pattern);
static wchar_t* soap_wcollapse(struct soap *soap, wchar_t *s, int flag, int insitu);
#endif
static const char* soap_string(struct soap *soap, const char *s, int flag, long minlen, long maxlen, const char *pattern);
static char* soap_collapse(struct soap *soap, char *s, int flag, int insitu);
static const char* soap_QName(struct soap *soap, const char *s, long minlen, long maxlen, const char *pattern);
#ifndef WITH_LEANER
static int soap_begin_attachments(struct soap*);
static int soap_end_attachments(struct soap *soap);
static struct soap_multipart *soap_alloc_multipart(struct soap*, struct soap_multipart**, struct soap_multipart**, const 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
#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 int ssl_auth_init(struct soap*);
static const char *ssl_verify(struct soap *soap, const char *host);
# if GNUTLS_VERSION_NUMBER < 0x020b00
# 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
#endif
#ifdef WITH_WOLFSSL
static int soap_ssl_init_done = 0;
static int ssl_auth_init(struct soap*);
static int ssl_verify_callback(int, WOLFSSL_X509_STORE_CTX*);
static int ssl_verify_callback_allow_expired_certificate(int, WOLFSSL_X509_STORE_CTX*);
static int ssl_password(char*, int, int, void*);
#endif
#ifdef WITH_SYSTEMSSL
static int soap_ssl_init_done = 0;
static int ssl_auth_init(struct soap*);
static int ssl_recv(int sk, void *s, int n, char *user);
static int ssl_send(int sk, void *s, int n, char *user);
#endif
#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER)
static const char * soap_decode(char*, size_t, const char*, const char*);
#endif
#ifndef WITH_NOHTTP
static soap_wchar soap_getchunkchar(struct soap*);
static const char *http_error(struct soap*, int);
static int http_get(struct soap*);
static int http_put(struct soap*);
static int http_patch(struct soap*);
static int http_del(struct soap*);
static int http_200(struct soap*);
static int http_post(struct soap*, const char*, const char*, int, const char*, const char*, ULONG64);
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, ULONG64);
static int http_parse(struct soap*);
static int http_parse_header(struct soap*, const char*, const char*);
#endif
#ifndef WITH_NOIO
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*);
#if !defined(WITH_IPV6)
static int tcp_gethost(struct soap*, const char *addr, struct in_addr *inaddr);
#endif
#if !defined(WITH_IPV6) || defined(WITH_COOKIES)
static int tcp_gethostbyname(struct soap*, const char *addr, struct hostent *hostent, 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*);
#define SOAP_TCP_SELECT_RCV 0x1
#define SOAP_TCP_SELECT_SND 0x2
#define SOAP_TCP_SELECT_ERR 0x4
#define SOAP_TCP_SELECT_ALL 0x7
#define SOAP_TCP_SELECT_PIP 0x8
#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, (void*)(&blocking)); \
}
#define SOAP_SOCKNONBLOCK(fd) \
{ \
u_long nonblocking = 1; \
ioctl(fd, FIONBIO, (void*)(&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(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) (void)fcntl(fd, F_SETFL, fcntl(fd, F_GETFL)&~O_NONBLOCK);
#define SOAP_SOCKNONBLOCK(fd) (void)fcntl(fd, F_SETFL, fcntl(fd, F_GETFL)|O_NONBLOCK);
#endif
#endif
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";
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";
#ifndef WITH_LEAN
static const char soap_indent[21] = "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
/* Alternative indentation form for SOAP_XML_INDENT with spaces instead of tabs:
static const char soap_indent[41] = "\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[] =
{
{ 100, "Continue" },
{ 101, "Switching Protocols" },
{ 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" },
{ 422, "Unprocessable Entity" },
{ 426, "Upgrade Required" },
{ 428, "Precondition Required" },
{ 429, "Too Many Requests" },
{ 431, "Request Header Fields Too Large" },
{ 500, "Internal Server Error" },
{ 501, "Not Implemented" },
{ 502, "Bad Gateway" },
{ 503, "Service Unavailable" },
{ 504, "Gateway Time-out" },
{ 505, "HTTP Version not supported" },
{ 511, "Network Authentication Required" },
{ 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(_AIX43) || defined(TRU64) || defined(HP_UX)) && defined(HAVE_GETHOSTBYNAME_R)
#ifndef h_errno
extern int h_errno;
#endif
#endif
/******************************************************************************/
#ifndef WITH_NOIO
static int
fsend(struct soap *soap, const char *s, size_t n)
{
int nwritten, err;
SOAP_SOCKET sk;
soap->errnum = 0;
#if defined(__cplusplus) && !defined(WITH_COMPAT)
if (soap->os)
{
soap->os->write(s, (std::streamsize)n);
if (soap->os->good())
return SOAP_OK;
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 (;;)
{
int r;
#ifdef WITH_SELF_PIPE
#ifdef WITH_OPENSSL
if (soap->ssl)
r = tcp_select(soap, sk, SOAP_TCP_SELECT_ALL | SOAP_TCP_SELECT_PIP, soap->send_timeout);
else
#endif
#ifdef WITH_GNUTLS
if (soap->session)
r = tcp_select(soap, sk, SOAP_TCP_SELECT_ALL | SOAP_TCP_SELECT_PIP, soap->send_timeout);
else
#endif
#ifdef WITH_WOLFSSL
if (soap->ssl)
r = tcp_select(soap, sk, SOAP_TCP_SELECT_ALL | SOAP_TCP_SELECT_PIP, soap->send_timeout);
else
#endif
#ifdef WITH_SYSTEMSSL
if (soap->ssl)
r = tcp_select(soap, sk, SOAP_TCP_SELECT_ALL | SOAP_TCP_SELECT_PIP, soap->send_timeout);
else
#endif
r = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR | SOAP_TCP_SELECT_PIP, soap->send_timeout);
if ((r & SOAP_TCP_SELECT_PIP)) /* abort if data is pending on pipe */
{
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connection closed by self pipe\n"));
return SOAP_EOF;
}
#else
#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
#ifdef WITH_WOLFSSL
if (soap->ssl)
r = tcp_select(soap, sk, SOAP_TCP_SELECT_ALL, soap->send_timeout);
else
#endif
#ifdef WITH_SYSTEMSSL
if (soap->ssl)
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);
#endif
if (r > 0)
break;
if (!r)
return SOAP_EOF;
err = soap->errnum;
if (!err)
return soap->error;
if (err != SOAP_EAGAIN && err != SOAP_EWOULDBLOCK)
return SOAP_EOF;
}
}
#ifndef WITH_LEAN
if (soap->transfer_timeout)
{
time_t now = time(NULL);
if ((soap->transfer_timeout > 0 && difftime(now, (time_t)soap->start) > (double)soap->transfer_timeout)
|| (soap->transfer_timeout < 0 && difftime(now, (time_t)soap->start) > -1000000.0 * (double)soap->transfer_timeout))
return SOAP_EOF;
}
#endif
#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
#ifdef WITH_WOLFSSL
if (soap->ssl)
nwritten = wolfSSL_write(soap->ssl, s, n);
else
#endif
#ifdef WITH_SYSTEMSSL
if (soap->ssl)
{
err = gsk_secure_socket_write(soap->ssl, (char*)s, n, &nwritten);
if (err != GSK_OK)
nwritten = 0;
}
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, &soap->peer.addr, (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, &soap->peer.addr, (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-- > 1);
}
if (nwritten < 0)
{
err = soap_socket_errno;
if (err && err != SOAP_EINTR)
{
soap->errnum = err;
return SOAP_EOF;
}
nwritten = 0; /* and call write() again */
}
}
else
#endif
#if !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)
{
int r = 0;
err = soap_socket_errno;
#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
#ifdef WITH_WOLFSSL
if (soap->ssl && (r = wolfSSL_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
if (err == SOAP_EWOULDBLOCK || err == SOAP_EAGAIN)
{
#ifdef 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
#endif
#ifdef 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
#ifdef WITH_WOLFSSL
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
#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)
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 WMW_RPM_IO
/* vxWorks compatible */
if (soap->rpmreqid)
nwritten = (httpBlockPut(soap->rpmreqid, (char*)s, n) == 0) ? n : -1;
else
#endif
#ifdef WIN32
nwritten = _write(soap->sendfd, s, (unsigned int)n);
#else
nwritten = write(soap->sendfd, s, (unsigned int)n);
#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
/******************************************************************************/
SOAP_FMAC1
int
SOAP_FMAC2
soap_send_raw(struct soap *soap, const char *s, size_t n)
{
if (!s || !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)) != SOAP_OK)
return soap->error;
if (soap->ffiltersend && (soap->error = soap->ffiltersend(soap, &s, &n)) != SOAP_OK)
return soap->error;
#endif
if ((soap->mode & SOAP_IO_LENGTH))
{
soap->count += n;
}
else if ((soap->mode & SOAP_IO))
{
size_t i = sizeof(soap->buf) - soap->bufidx;
while (n >= i)
{
(void)soap_memcpy((void*)(soap->buf + soap->bufidx), i, (const void*)s, i);
soap->bufidx = sizeof(soap->buf);
if (soap_flush(soap))
return soap->error;
s += i;
n -= i;
i = sizeof(soap->buf);
}
(void)soap_memcpy((void*)(soap->buf + soap->bufidx), sizeof(soap->buf) - soap->bufidx, (const void*)s, n);
soap->bufidx += n;
}
else
{
return soap_flush_raw(soap, s, n);
}
return SOAP_OK;
}
/******************************************************************************/
SOAP_FMAC1
int
SOAP_FMAC2
soap_flush(struct soap *soap)
{
size_t n = soap->bufidx;
if (!n)
return soap->error = soap->fsend(soap, SOAP_STR_EOS, 0); /* force a zero send for HTTP GET and DELETE */
#ifndef WITH_LEANER
if ((soap->mode & SOAP_IO) == SOAP_IO_STORE)
{
int r;
if (soap->fpreparesend && (r = soap->fpreparesend(soap, soap->buf, n)) != SOAP_OK)
return soap->error = r;
}
#endif
soap->bufidx = 0;
#ifdef WITH_ZLIB
if ((soap->mode & SOAP_ENC_ZLIB) && soap->d_stream)
{
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, sizeof(soap->buf)))
return soap->error;
soap->d_stream->next_out = (Byte*)soap->z_buf;
soap->d_stream->avail_out = sizeof(soap->buf);
}
} while (soap->d_stream->avail_in);
return SOAP_OK;
}
#endif
return soap_flush_raw(soap, soap->buf, n);
}
/******************************************************************************/
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)
{
void *t;
t = soap_push_block(soap, NULL, n);
if (!t)
return soap->error = SOAP_EOM;
(void)soap_memcpy(t, n, (const void*)s, n);
return SOAP_OK;
}
#ifndef WITH_LEANER
if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK)
{
char t[24];
(SOAP_SNPRINTF(t, sizeof(t), 20), &"\r\n%lX\r\n"[soap->chunksize ? 0 : 2], (unsigned long)n);
DBGMSG(SENT, t, strlen(t));
soap->error = soap->fsend(soap, t, strlen(t));
if (soap->error)
return soap->error;
soap->chunksize += n;
}
DBGMSG(SENT, s, n);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Send %u bytes to socket=%d/fd=%d\n", (unsigned int)n, (int)soap->socket, soap->sendfd));
#endif
return soap->error = soap->fsend(soap, s, n);
}
/******************************************************************************/
SOAP_FMAC1
int
SOAP_FMAC2
soap_send(struct soap *soap, const char *s)
{
if (!s)
return SOAP_OK;
return soap_send_raw(soap, s, strlen(s));