fujuntang
2022-04-28 51ccd8155f029d66366d0df8e2baf886ffd50000
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
/*
        wsaapi.c
 
        WS-Addressing plugin.
 
gSOAP XML Web services tools
Copyright (C) 2000-2015, 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.
--------------------------------------------------------------------------------
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-2015, 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:
engelen@genivia.com / engelen@acm.org
 
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., contact@genivia.com
--------------------------------------------------------------------------------
*/
 
/**
 
@mainpage
 
- @ref wsa_0 documents the wsa plugin for WS-Addressing (2003/2004/2005
  standards) support.
 
*/
 
/**
 
@page wsa_0 The WS-Addressing Plugin
 
[TOC]
 
@section wsa_1 WS-Addressing Setup
 
The material in this section relates to the WS-Addressing specification.
 
To use the wsa plugin:
-# Run wsdl2h -t typemap.dat on a WSDL of a service that requires WS-Addressing
   headers. The typemap.dat file included in the gSOAP package is used to
   recognize and translate Addressing header blocks.
-# Run soapcpp2 -a on the header file produced by wsdl2h. To enable
   addressing-based service operation selection, you MUST use soapcpp2 option
   -a. This allows the service to dispatch methods based on the WS-Addressing
   action information header value (when the wsa plugin is registered).
-# (Re-)compile and link stdsoap2.c/pp or libgsoap, (dom.c/pp when needed),
   wsaapi.c and the soapcpp2-generated source files.
-# Use the wsa plugin API functions described below.
 
An example wsa client/server application can be found in `gsoap/samples/wsa`.
 
A gSOAP service definitions header file with a `#import "wsa.h"` to support
WS-Addressing is automatically generated by wsdl2h for a set of WSDLs that use
WS-Addressing. The wsdl2h-generated header file should be further processed by
soapcpp2 to generate the binding code. The wsaapi.h and wsaapi.c implement the
WS-Addressing API described in this document.
 
A wsdl2h-generated service definitions header file might include the following
imports:
 
@code
    #import "soap12.h"
    #import "wsa.h" // or wsa3.h (2003/03), wsa4.h (2004/03), wsa5.h (2005/03)
@endcode
 
The wsa.h header file is imported from import/wsa.h when soapcpp2 is run on
this file. The wsa.h import can be manually added to enable WS-Addressing when
needed. The gSOAP service definitions header file is processed with soapcpp2 to
generate the client-side and/or server-side binding code.
 
Note that the wsa.h, wsa3.h, wsa4.h, and wsa5.h header files are located in the
import directory of the gSOAP package. These files define the WS-Addressing
information header elements and types. The soap12.h header file enables SOAP
1.2 messaging.
 
For developers: the WS-Addressing header blocks in wsa.h (and others) were
generated from the WS-Addressing schema with the wsdl2h tool and
WS/WS-typemap.dat as follows:
 
    wsdl2h -cegy -o wsa.h -t WS/WS-typemap.dat WS/WS-Addressing.xsd
 
Refer to wsa.h for more details.
 
@section wsa_2 Client-side Usage
 
@subsection wsa_2_1 Constructing WS-Addressing Information Headers
 
To associate WS-Addressing information headers with service operations, the
SOAP Header struct `SOAP_ENV__Header` must have been defined and for each service
operation that uses WS-Addressing method-header-part directives should be used
in the gSOAP service definitions header file as follows:
 
@code
    #import "wsa.h"
    //gsoap ns service method-header-part: example wsa__MessageID
    //gsoap ns service method-header-part: example wsa__RelatesTo
    //gsoap ns service method-header-part: example wsa__From
    //gsoap ns service method-header-part: example wsa__ReplyTo
    //gsoap ns service method-header-part: example wsa__FaultTo
    //gsoap ns service method-header-part: example wsa__To
    //gsoap ns service method-header-part: example wsa__Action
    //gsoap ns service method-action: example urn:example/examplePort/example
    int ns__example(char *in, struct ns__exampleResponse *out);
@endcode
 
Note that the use of wsa versions determines the wsa prefix, e.g. use `wsa5`
for the latest WS-Addressing as in `wsa5__MessageID`.
 
In the client-side code, the WS-Addressing information headers are set with
`soap_wsa_request` by passing an optional message UUID string, a mandatory
destination address URI string, and a mandatory request action URI string. The
wsa plugin should be registered with the current soap struct context. An
optional source address information header can be added with
`soap_wsa_add_From` (must be invoked after the `soap_wsa_request` call).
 
For example:
 
@code
    #include "wsaapi.h"
    soap_register_plugin(soap, soap_wsa);
 
    if (soap_wsa_request(soap, RequestMessageID, ToAddress, RequestAction))
     || soap_wsa_add_From(soap, FromAddress)) // optional: add a 'From' address
      ... // error: out of memory
 
    if (soap_call_ns__example(soap, ToAddress, NULL, ...))
      soap_print_fault(soap, stderr); // an error occurred
    else
      // process the response 
@endcode
 
To generate a UUID for the RequestMessageID, use:
 
@code
    const char *RequestMessageID = soap_wsa_rand_uuid(soap);
@endcode
 
@subsection wsa_2_2 Information Headers for Relaying Server Responses
 
To relay the response to another destination, the WS-Addressing ReplyTo
information header is added with `soap_wsa_add_ReplyTo` by passing a reply
address URI string. The service returns "HTTP 200 OK" or "HTTP 202 ACCEPTED" to
the client when the response message relay was successful.
 
For example:
 
@code
    #include "wsaapi.h"
    soap_register_plugin(soap, soap_wsa);
 
    if (soap_wsa_request(soap, RequestMessageID, ToAddress, RequestAction)
     || soap_wsa_add_From(soap, FromAddress) // optional: add a 'From' address
     || soap_wsa_add_ReplyTo(soap, ReplyToAddress))
      ... // error: out of memory
 
    if (soap_call_ns__example(soap, ToAddress, NULL, ...))
    {
      if (soap->error == 200 || soap->error == 202) // HTTP OK or ACCEPTED
        printf("Request was accepted and results were forwarded\n");
      else
        soap_print_fault(soap, stderr); // an error occurred
    }
    else
      // unexpected OK: for some reason the response was not relayed
@endcode
 
Note: the response message will be relayed when the From address is absent or
different than the ReplyTo address
 
@subsection wsa_2_3 Information Headers for Relaying Server Faults
 
To relay a server fault message to another destination, the WS-Addressing
FaultTo information header is added with `soap_wsa_add_FaultTo` by passing a
relay address URI string. The service returns "HTTP 200 OK" or "HTTP 202
ACCEPTED" to the client when the fault was relayed.
 
For example:
 
@code
    #include "wsaapi.h"
    soap_register_plugin(soap, soap_wsa);
 
    if (soap_wsa_request(soap, RequestMessageID, ToAddress, RequestAction)
     || soap_wsa_add_From(soap, FromAddress) // optional: add a 'From' address
     || soap_wsa_add_FaultTo(soap, FaultToAddress))
      ... // error: out of memory
 
    if (soap_call_ns__example(soap, ToAddress, NULL, ...))
    {
      if (soap->error == 200 || soap->error == 202) // HTTP OK or ACCEPTED
        printf("A fault occurred and the fault details were forwarded\n");
      else
        soap_print_fault(soap, stderr); // a connection error occurred
    }
    else
      ... // process response 
@endcode
 
Note that the call can still return a fault, such as a connection error when
the service is not responding. In addition to the fault relay, the responses
can be relayed with `soap_wsa_add_ReplyTo`.
 
@subsection wsa_2_4 Error Handling
 
SOAP and HTTP errors set the soap->error attribute, as shown in this example:
 
@code
    if (soap_call_ns__example(soap, ToAddress, NULL, ...))
    {
      if (soap->error == 200 || soap->error == 202) // HTTP OK or ACCEPTED
        printf("A fault occurred and the fault details were forwarded\n");
      else
        soap_print_fault(soap, stderr); // a connection error occurred
    }
    else
      ... // process response 
@endcode
 
When a WS-Addressing error occurred, the wsa error code is stored in the SOAP
Fault Subcode field. This information can be retrieved with:
 
@code
    wsa__FaultSubcodeValues fault;
    if (soap_wsa_check_fault(soap, &fault))
    {
      switch (fault)
      {
        case wsa__InvalidMessageInformationHeader: ...
        case wsa__MessageInformationHeaderRequired: ...
        case wsa__DestinationUreachable: ...
        case wsa__ActionNotSupported: ...
        case wsa__EndpointUnavailable: ...
      }
    }
@endcode
 
When using wsa5.h, please refer to the standards and fault codes for this
implementation. For the wsa5.h 2005/03 standard, several faults have an
additional parameter (SOAP Fault detail):
 
@code
    wsa5__FaultCodesType fault;
    char *info;
    if (soap_wsa_check_fault(soap, &fault, &info))
    {
      switch (fault)
      {
        case wsa5__InvalidAddressingHeader:
          if (info)
            printf("The invalid addressing header element is %s\n", info);
        ...
      }
    }
@endcode
 
@subsection wsa_2_5 Combining WS-Addressing with WS-Security
 
WS-Security can be combined with WS-Addressing. To sign WS-Addressing header
blocks, use the `soap_wsse_set_wsu_id` WSSE-plugin call to set the wsu:Id
attribute and signing of these attributed elements. For example, suppose we use
WS-Addressing 2005 headers (which are activated with an `#import "wsa5.h"` in
the header file for soapcpp2):
 
@code
    #include "wsaapi.h"
    #include "wsseapi.h"
    soap_register_plugin(soap, soap_wsa);
    soap_register_plugin(soap, soap_wsse);
 
    soap_wsse_set_wsu_id(soap, "wsa5:From wsa5:To wsa5:ReplyTo wsa5:FaultTo wsa5:Action wsa5:MessageID");
    if (soap_wsa_request(soap, RequestMessageID, ToAddress, RequestAction)
     || soap_wsa_add_From(soap, FromAddress) // optional: add a 'From' address
     || soap_wsa_add_FaultTo(soap, FaultToAddress))
      ... // error: out of memory
    if (soap_call_ns__example(soap, ToAddress, NULL, ...))
      ... // error
@endcode
 
If your are using WS-Addressing 2004 (which is activated with an
`#import "wsa.h"` in the header file for soapcpp2) then change one line:
 
@code
    soap_wsse_set_wsu_id(soap, "wsa:From wsa:To wsa:ReplyTo wsa:FaultTo wsa:Action wsa:MessageID");
@endcode
 
Note: `soap_wsse_set_wsu_id` should only be set once. Each new call overrides
the previous.
 
For more details on WS-Security, please see the
[WS-Security plugin documentation](../../wsse/html/index.html).
 
@section wsa_3 Server-side Usage
 
The wsa plugin should be registered with:
 
@code
    soap_register_plugin(soap, soap_wsa);
@endcode
 
Once the plugin is registered, the `soap_bind`, `soap_accept`, and `soap_serve`
functions can be called to process requests and semi-automatically handle the
WS-Addressing header blocks.
 
Important: to dispatch service operations based on the WS-Addressing wsa:Action
information header, you must use soapcpp2 option `-a`. The generates a new
dispatcher (in soapServer.c) based on the action value.
 
A service operation implementation should use `soap_wsa_check` at the start of
its execution to verify the validity of the WS-Addressing information headers
in the SOAP request message. To allow response message to be automatically
relayed based on the ReplyTo information header, the service operation should
return `soap_wsa_reply` with an optional message UUID string and a mandatory
response action string. The response action string is documented in the
wsdl2h-generated .h file for this service operation.
 
For example:
 
@code
    int ns__example(struct soap *soap, char *in, struct ns__exampleResponse *out)
    {
      if (soap_wsa_check(soap))
        return soap->error;
      // ... service logic
      return soap_wsa_reply(soap, ResponseMessageID, ResponseAction);
    }
@endcode
 
To return a SOAP fault that is automatically relayed to a fault service based
on the FaultTo information header, the `soap_wsa_sender_fault`,
`soap_wsa_receiver_fault`, `soap_wsa_sender_fault_subcode`, and
`soap_wsa_receiver_fault_subcode` functions should be used instead of the
usual `soap_sender_fault`, `soap_receiver_fault`, `soap_sender_fault_subcode`,
and `soap_receiver_fault_subcode`, respectively:
  
In case a Action must be associated with a SOAP Fault, use the
`soap_wsa_sender_fault_subcode_action` and
`soap_wsa_receiver_fault_subcode_action` functions to set the WS-Addressing
Action (and HTTP SOAP Action header as well).
 
For example, the following service operation illustrates the use of
`soap_wsa_check` to verify and process WS-Addressing header blocks and
`soap_wsa_reply` to enable responses to be relayed as per ReplyTo address in
the WS-Addressing header:
 
@code
    int ns__example(struct soap *soap, char *in, struct ns__exampleResponse *out)
    {
      if (soap_wsa_check(soap))
        return soap->error;
      // ... service logic
      // ... an error occurred, need to return fault possibly to fault service:
        return soap_wsa_sender_fault(soap, "Exception in service operation", NULL);
      // ... normal execution continues
      return soap_wsa_reply(soap, ResponseMessageID, ResponseAction);
    }
@endcode
 
@section wsa_4 HTTPS Server-side Usage
 
To enable HTTPS (SSL/TSL) servers, compile the sources with -DWITH_OPENSSL (and
link with libgsoapssl, libssl, and libcrypto). Because WS-Addressing may relay
messages over HTTPS as a sender (client), you must initialize the SSL context
for server and client uses. Therefore, the context must have access to all the
certificates need to verify the authenticity of the ReplyTo and FaultTo HTTPS
servers. To do so, use the following SSL initialization before `soap_bind`:
 
@code
    struct soap *soap = soap_new();
    if (soap_ssl_server_context(soap,
      SOAP_SSL_DEFAULT,
      "server.pem", // the keyfile (server should authenticate)
      "password",   // password to read the key file
      "cacert.pem", // cacert file to store trusted certificates (role as client)
      NULL,         // optional capath
      NULL,         // DH file name or DH param key len bits, when NULL use RSA
      NULL,         // file with random data to seed randomness
      "myserver"    // unique server identification for SSL session cache
    ))
    {
      soap_print_fault(soap, stderr);
      ...
    }
    soap->bind_flags = SO_REUSEADDR;
    if (!soap_valid_socket(soap_bind(soap, NULL, port, 100)))
    {
      soap_print_fault(soap, stderr);
      ...
    }
@endcode
 
@section wsa_5 Implementing a Server for Handling ReplyTo Response Messages
 
To implement a separate server for handling relayed SOAP response messages
based on the ReplyTo information header in the request message, the gSOAP
header file should include a one-way service operation for the response
message. These one-way response service operations are automatically generated
with wsdl2h option `-b`.
 
For example, suppose a service operation returns an exampleResponse message. We
declare the one-way exampleResponse operation as follows:
 
@code
    #import "wsa.h"
    //gsoap ns service method-header-part: exampleResult wsa__MessageID
    //gsoap ns service method-header-part: exampleResult wsa__RelatesTo
    //gsoap ns service method-header-part: exampleResult wsa__From
    //gsoap ns service method-header-part: exampleResult wsa__ReplyTo
    //gsoap ns service method-header-part: exampleResult wsa__FaultTo
    //gsoap ns service method-header-part: exampleResult wsa__To
    //gsoap ns service method-header-part: exampleResult wsa__Action
    //gsoap ns service method-action: exampleResult urn:example/examplePort/exampleResponse
    int ns__exampleResponse(char *out, void);
@endcode
 
Note that the action information is important, because it is used by the
service dispatcher (assuming soapcpp2 option `-a` is used).
 
The implementation in the server code uses soap_wsa_check() to check the
presense and validity of the WS-Addressing information header in the message.
The `soap_send_empty_response` function should be used to return an
acknowledgment HTTP header with "HTTP 202 ACCEPTED" to the sender:
 
@code
    int ns__exampleResponse(struct soap *soap, char *out)
    {
      if (soap_wsa_check(soap))
        return soap_send_empty_response(soap, 500); // HTTP 500 Internal Server Error
      // ... service logic
      return soap_send_empty_response(soap, SOAP_OK); // HTTP 202 ACCEPTED
    }
@endcode
 
@section wsa_6 Implementing a Server for Handling FaultTo Fault Messages
 
To implement a separate server for handling relayed SOAP fault messages based
on the FaultTo information header in the request message, the gSOAP header file
for soapcpp2 should include a SOAP fault service operation. This operation
accepts fault messages that are relayed by other services.
 
Basically, we use a trick to generate the SOAP-ENV:Fault struct via a one-way
service operation. This allows us both to implement a one-way service operation
that accepts faults and to automatically generate the fault struct for fault
data storage and manipulation. 
 
The fault operation in the WS-Addressing files (wsa5.h etc.) is declared as
follows (here shown for the 2004/08 standard):
 
@code
    //gsoap SOAP_ENV service method-action: Fault http://schemas.xmlsoap.org/ws/2004/08/addressing/fault
    int SOAP_ENV__Fault
    (
            _QName                       faultcode,             // SOAP 1.1
            char                        *faultstring,           // SOAP 1.1
            char                        *faultactor,            // SOAP 1.1
            struct SOAP_ENV__Detail     *detail,                // SOAP 1.1
            struct SOAP_ENV__Code       *SOAP_ENV__Code,        // SOAP 1.2
            struct SOAP_ENV__Reason     *SOAP_ENV__Reason,      // SOAP 1.2
            char                        *SOAP_ENV__Node,        // SOAP 1.2
            char                        *SOAP_ENV__Role,        // SOAP 1.2
            struct SOAP_ENV__Detail     *SOAP_ENV__Detail,      // SOAP 1.2
            void
    );
@endcode
 
Because each service operation has a struct to hold its input parameters, we
automatically generate the (original) `SOAP_ENV__Fault` struct on the fly!
 
It is important to associate the wsa fault action with this operation as shown
above.
 
The implementation of the Fault service operation in your server code should be
similar to:
 
@code
    int SOAP_ENV__Fault(struct soap *soap, char *faultcode, char *faultstring, char *faultactor, struct SOAP_ENV__Detail *detail, struct SOAP_ENV__Code *SOAP_ENV__Code, struct SOAP_ENV__Reason *SOAP_ENV__Reason, char *SOAP_ENV__Node, char *SOAP_ENV__Role, struct SOAP_ENV__Detail *SOAP_ENV__Detail)
    { 
      ... = faultcode; // SOAP 1.1 fault code string (QName)
      ... = faultstring; // SOAP 1.1 fault string
      ... = faultactor; // SOAP 1.1 fault actor string
      ... = detail; // SOAP 1.1 fault detail struct
      ... = SOAP_ENV__Code; // SOAP 1.2 fault code struct
      ... = SOAP_ENV__Reason; // SOAP 1.2 reason struct
      ... = SOAP_ENV__Node; // SOAP 1.2 node string
      ... = SOAP_ENV__Role; // SOAP 1.2 role string
      ... = SOAP_ENV__Detail; // SOAP 1.2 detail struct
      return SOAP_OK;
    }
@endcode
 
Note that SOAP 1.1 or SOAP 1.2 parameters are set based on the 1.1/1.2
messaging requirements.
 
@section wsa_7 Using the WS-Addressing plugin with the Apache gSOAP module
 
The WS-Addressing plugin may be used with the Apache `mod_gsoap` module.  The
server-side logic is the same.  However, registering the WS-Addressing plugin
requires a parameter `SOAP_WSA_NEW_TRANSFER`:
 
@code
    #include "plugin/wsaapi.h"
    #include "apache_gsoap.h"
    void mod_gsoap_init(struct soap *soap, request_rec *r)
    {
      soap_register_plugin_arg(soap, http_wsa, SOAP_WSA_NEW_TRANSFER) 
    }
    IMPLEMENT_GSOAP_SERVER_INIT(mod_gsoap_init)
@endcode
 
*/
 
#include "wsaapi.h"
 
#ifdef __cplusplus
extern "C" {
#endif
 
/** Plugin identification for plugin registry */
const char soap_wsa_id[] = SOAP_WSA_ID;
 
#if defined(SOAP_WSA_2003)
/** Anonymous Reply/To endpoint address */
const char *soap_wsa_anonymousURI = "http://schemas.xmlsoap.org/ws/2003/03/addressing/role/anonymous";
/** Specifies no Reply endpoint address (no reply) */
const char *soap_wsa_noneURI = "addressing/none not supported";
const char *soap_wsa_faultAction = "http://schemas.xmlsoap.org/ws/2003/03/addressing/fault";
#elif defined(SOAP_WSA_2004)
/** Anonymous Reply/To endpoint address */
const char *soap_wsa_anonymousURI = "http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous";
/** Specifies no Reply endpoint address (no reply) */
const char *soap_wsa_noneURI = "addressing/none not supported";
const char *soap_wsa_faultAction = "http://schemas.xmlsoap.org/ws/2004/03/addressing/fault";
#elif defined(SOAP_WSA_2005)
/** Anonymous Reply/To endpoint address */
const char *soap_wsa_anonymousURI = "http://www.w3.org/2005/08/addressing/anonymous";
/** Specifies no Reply endpoint address (no reply) */
const char *soap_wsa_noneURI = "http://www.w3.org/2005/08/addressing/none";
const char *soap_wsa_faultAction = "http://www.w3.org/2005/08/addressing/soap/fault";
#else
/** Anonymous Reply/To endpoint address */
const char *soap_wsa_anonymousURI = "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous";
/** Specifies no Reply endpoint address (no reply) */
const char *soap_wsa_noneURI = "addressing/none not supported";
const char *soap_wsa_faultAction = "http://schemas.xmlsoap.org/ws/2004/08/addressing/fault";
#endif
 
/** anonymous URI of 2004 and 2005 schemas */
const char *soap_wsa_allAnonymousURI = "http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous http://www.w3.org/2005/08/addressing/anonymous";
 
/******************************************************************************\
 *
 *      Static protos
 *
\******************************************************************************/
 
static int soap_wsa_init(struct soap *soap, struct soap_wsa_data *data, void *arg);
static void soap_wsa_delete(struct soap *soap, struct soap_plugin *p);
 
static int soap_wsa_header(struct soap *soap);
static void soap_wsa_set_error(struct soap *soap, const char **c, const char **s);
static int soap_wsa_response(struct soap *soap, int status, ULONG64 count);
static int soap_wsa_disconnect(struct soap *soap);
 
static int soap_wsa_alloc_header(struct soap *soap);
 
/******************************************************************************\
 *
 *      UUID
 *
\******************************************************************************/
 
/**
@fn const char *soap_wsa_rand_uuid(struct soap *soap)
@brief Generates a random UUID (UUID algorithm version 4). Compile all source
codes with -DWITH_OPENSSL for better randomness.
@param soap context
@return UUID "urn:uuid:xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx" or NULL if out of memory
*/
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_wsa_rand_uuid(struct soap *soap)
{
  return soap_strdup(soap, soap_rand_uuid(soap, "urn:uuid:"));
}
 
/******************************************************************************\
 *
 *      Client-side Request
 *
\******************************************************************************/
 
/**
@fn int soap_wsa_request(struct soap *soap, const char *id, const char *to, const char *action)
@brief Sets the WS-Addressing information header for the next request message
with MessageID (optional), To (optional), and Action (required).
@param soap context
@param[in] id is the message ID (optional)
@param[in] to is the target endpoint (optional, set to anonymous when NULL)
@param[in] action is the target action (required)
@return SOAP_OK or error
 
Note: use soap_wsa_add_From, soap_wsa_add_ReplyTo, soap_wsa_add_FaultTo to add
other addressing fields following this function call.
*/
SOAP_FMAC1
int
SOAP_FMAC2
soap_wsa_request(struct soap *soap, const char *id, const char *to, const char *action)
{
  DBGFUN3("soap_wsa_request", "id=%s", id?id:"(null)", "to=%s", to?to:"(null)", "action=%s", action?action:"(null)");
  if (soap_wsa_alloc_header(soap))
    return soap->error;
  soap->header->SOAP_WSA(MessageID) = soap_strdup(soap, id);
  if (to)
    soap->header->SOAP_WSA(To) = soap_strdup(soap, to);
  else /* this is optional */
    soap->header->SOAP_WSA(To) = (char*)soap_wsa_anonymousURI;
  soap->header->SOAP_WSA(Action) = soap_strdup(soap, action);
  soap->header->SOAP_WSA(RelatesTo) = NULL;
  soap->header->SOAP_WSA(From) = NULL;
  soap->header->SOAP_WSA(FaultTo) = NULL;
  soap_wsa_add_ReplyTo(soap, NULL);
  return soap_wsa_check(soap);
}
 
/******************************************************************************/
 
/**
@fn int soap_wsa_add_From(struct soap *soap, const char *from)
@brief Sets WS-Addressing From header for request message.
@param soap context
@param[in] from endpoint URI 
@return SOAP_OK or SOAP_ERR
 
Use soap_wsa_request to populate the WS-Addressing header first.
*/
SOAP_FMAC1
int
SOAP_FMAC2
soap_wsa_add_From(struct soap *soap, const char *from)
{
  if (!soap->header)
    return SOAP_ERR;
  soap->header->SOAP_WSA(From) = (SOAP_WSA_(,From)*)soap_malloc(soap, sizeof(SOAP_WSA_(,From)));
  SOAP_WSA_(soap_default,EndpointReferenceType)(soap, soap->header->SOAP_WSA(From));
  soap->header->SOAP_WSA(From)->Address = soap_strdup(soap, from);
  return SOAP_OK;
}
 
/******************************************************************************/
 
/**
@fn int soap_wsa_add_NoReply(struct soap *soap)
@brief Sets WS-Addressing ReplyTo header to 'none' (no reply)
@param soap context
@return SOAP_OK or SOAP_ERR
 
Note: WS-Addressing 2005/08 standard.
 
Use soap_wsa_request to populate the WS-Addressing header.
*/
SOAP_FMAC1
int
SOAP_FMAC2
soap_wsa_add_NoReply(struct soap *soap)
{
  return soap_wsa_add_ReplyTo(soap, soap_wsa_noneURI); 
}
 
/******************************************************************************/
 
/**
@fn int soap_wsa_add_ReplyTo(struct soap *soap, const char *replyTo)
@brief Sets WS-Addressing ReplyTo header for request message.
@param soap context
@param[in] replyTo endpoint URI or NULL for anonymous
@return SOAP_OK or SOAP_ERR
 
Use soap_wsa_request to populate the WS-Addressing header.
*/
SOAP_FMAC1
int
SOAP_FMAC2
soap_wsa_add_ReplyTo(struct soap *soap, const char *replyTo)
{
  if (!soap->header)
    return SOAP_ERR;
#ifndef SOAP_WSA_2005
  if (!replyTo)
    replyTo = soap_wsa_anonymousURI;
#endif
  if (replyTo)
  {
    soap->header->SOAP_WSA(ReplyTo) = (SOAP_WSA_(,ReplyTo)*)soap_malloc(soap, sizeof(SOAP_WSA_(,ReplyTo)));
    SOAP_WSA_(soap_default,EndpointReferenceType)(soap, soap->header->SOAP_WSA(ReplyTo));
    soap->header->SOAP_WSA(ReplyTo)->Address = soap_strdup(soap, replyTo);
  }
  else
    soap->header->SOAP_WSA(ReplyTo) = NULL;
  return SOAP_OK;
}
 
/******************************************************************************/
 
/**
@fn int soap_wsa_add_FaultTo(struct soap *soap, const char *faultTo)
@brief Sets WS-Addressing FaultTo header for request message.
@param soap context
@param[in] faultTo endpoint URI or NULL for remove faultTo
@return SOAP_OK or SOAP_ERR
 
Use soap_wsa_request to populate the WS-Addressing header first.
*/
SOAP_FMAC1
int
SOAP_FMAC2
soap_wsa_add_FaultTo(struct soap *soap, const char *faultTo)
{
  if (!soap->header)
    return SOAP_ERR;
  if (faultTo)
  {
    soap->header->SOAP_WSA(FaultTo) = (SOAP_WSA_(,FaultTo)*)soap_malloc(soap, sizeof(SOAP_WSA_(,FaultTo)));
    SOAP_WSA_(soap_default,EndpointReferenceType)(soap, soap->header->SOAP_WSA(FaultTo));
    soap->header->SOAP_WSA(FaultTo)->Address = soap_strdup(soap, faultTo);
  }
  else
    soap->header->SOAP_WSA(FaultTo) = NULL;
  return SOAP_OK;
}
 
/******************************************************************************/
 
/**
@fn int soap_wsa_add_RelatesTo(struct soap *soap, const char *relatesTo)
@brief Sets WS-Addressing RelatesTo header.
@param soap context
@param[in] relatesTo endpoint URI 
@return SOAP_OK or SOAP_ERR
 
Use soap_wsa_request to populate the WS-Addressing header.
*/
SOAP_FMAC1
int
SOAP_FMAC2
soap_wsa_add_RelatesTo(struct soap *soap, const char *relatesTo)
{
  if (!soap->header)
    return SOAP_ERR;
  if (relatesTo)
  {
    soap->header->SOAP_WSA(RelatesTo) = (SOAP_WSA_(,RelatesTo)*)soap_malloc(soap, sizeof(SOAP_WSA_(,RelatesTo)));
    SOAP_WSA_(soap_default_,RelatesTo)(soap, soap->header->SOAP_WSA(RelatesTo));
    soap->header->SOAP_WSA(RelatesTo)->__item = soap_strdup(soap, relatesTo);
  }
  return SOAP_OK;
}
 
/******************************************************************************/
 
/**
@fn const char *soap_wsa_From(struct soap *soap)
@brief Returns WS-Addressing From header.
@param soap context
@return From string or NULL
*/
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_wsa_From(struct soap *soap)
{
  if (!soap->header || !soap->header->SOAP_WSA(From))
    return NULL;
  return soap->header->SOAP_WSA(From)->Address;
}
 
/******************************************************************************/
 
/**
@fn const char *soap_wsa_ReplyTo(struct soap *soap)
@brief Returns WS-Addressing ReplyTo header.
@param soap context
@return From string or NULL
*/
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_wsa_ReplyTo(struct soap *soap)
{
  if (!soap->header || !soap->header->SOAP_WSA(ReplyTo))
    return NULL;
  return soap->header->SOAP_WSA(ReplyTo)->Address;
}
 
/******************************************************************************/
 
/**
@fn const char *soap_wsa_FaultTo(struct soap *soap)
@brief Returns WS-Addressing FaultTo header.
@param soap context
@return From string or NULL
*/
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_wsa_FaultTo(struct soap *soap)
{
  if (!soap->header || !soap->header->SOAP_WSA(FaultTo))
    return NULL;
  return soap->header->SOAP_WSA(FaultTo)->Address;
}
 
/******************************************************************************/
 
/**
@fn const char *soap_wsa_RelatesTo(struct soap *soap)
@brief Returns WS-Addressing RelatesTo header.
@param soap context
@return From string or NULL
*/
SOAP_FMAC1
const char*
SOAP_FMAC2
soap_wsa_RelatesTo(struct soap *soap)
{
  if (!soap->header || !soap->header->SOAP_WSA(RelatesTo))
    return NULL;
  return soap->header->SOAP_WSA(RelatesTo)->__item;
}
 
/******************************************************************************\
 *
 *      Server-side Check and Reply
 *
\******************************************************************************/
 
/**
@fn int soap_wsa_check(struct soap *soap)
@brief Checks the presence and validity of WS-Addressing information headers.
@param soap context
@return SOAP_OK or fault
*/
SOAP_FMAC1
int
SOAP_FMAC2
soap_wsa_check(struct soap *soap)
{
  DBGFUN("soap_wsa_check");
  if (!soap->header || !soap->header->SOAP_WSA(Action))
#if defined(SOAP_WSA_2005)
    return soap_wsa_error(soap, wsa5__MessageAddressingHeaderRequired, NULL);
#elif defined(SOAP_WSA_2003)
    return soap_wsa_error(soap, "WS-Addressing header missing");
#else
    return soap_wsa_error(soap, SOAP_WSA(MessageInformationHeaderRequired));
#endif
  return SOAP_OK;
}
 
/******************************************************************************/
 
/**
@fn int soap_wsa_reply(struct soap *soap, const char *id, const char *action)
@brief Sets WS-Addressing header fields for server response. Automatically
relays the response to the ReplyTo address (when ReplyTo != to From and ReplyTo
!= 'none') and returns HTTP 202 Accept to sender when relay was successful.
@param soap context
@param[in] id is the messageID (optional)
@param[in] action is the target action (required)
@return SOAP_OK or fault
*/
SOAP_FMAC1
int
SOAP_FMAC2
soap_wsa_reply(struct soap *soap, const char *id, const char *action)
{
  struct soap_wsa_data *data = (struct soap_wsa_data*)soap_lookup_plugin(soap, soap_wsa_id);
  struct SOAP_ENV__Header *oldheader, *newheader;
  DBGFUN1("soap_wsa_reply", "action=%s", action?action:"(null)");
  if (!data)
    return soap->error = SOAP_PLUGIN_ERROR;
  oldheader = soap->header;
  soap->header = NULL;
  /* if endpoint address for reply is 'none' return immediately and STOP engine */
  if (oldheader && oldheader->SOAP_WSA(ReplyTo) && oldheader->SOAP_WSA(ReplyTo)->Address && !strcmp(oldheader->SOAP_WSA(ReplyTo)->Address, soap_wsa_noneURI))
    return soap_send_empty_response(soap, SOAP_OK);
  /* allocate a new header */
  if (soap_wsa_alloc_header(soap))
    return soap->error;
  newheader = soap->header;
  /* copy members to new header, except WSA data */
  if (oldheader)
    *newheader = *oldheader;
  newheader->SOAP_WSA(MessageID) = soap_strdup(soap, id);
  newheader->SOAP_WSA(Action) = soap_strdup(soap, action);
  newheader->SOAP_WSA(RelatesTo) = NULL;
  newheader->SOAP_WSA(From) = NULL;
  newheader->SOAP_WSA(To) = NULL;
  newheader->SOAP_WSA(ReplyTo) = NULL;
  newheader->SOAP_WSA(FaultTo) = NULL;
  /* check current header content */
  if (oldheader && oldheader->SOAP_WSA(MessageID))
  {
    newheader->SOAP_WSA(RelatesTo) = (SOAP_WSA_(,RelatesTo)*)soap_malloc(soap, sizeof(SOAP_WSA_(,RelatesTo)));
    SOAP_WSA_(soap_default_,RelatesTo)(soap, newheader->SOAP_WSA(RelatesTo));
    newheader->SOAP_WSA(RelatesTo)->__item = oldheader->SOAP_WSA(MessageID);
  }
#ifdef SOAP_WSA_2005 
  /* WCF Interoperability:
     ChannelInstance is required when the WCF Application hosts multiple
     Callback Channels within the same application. The
     ReferenceParameters->ChannelInstance element serves as a hint to the WCF
     Client dispatcher, as to which WCF callback instance a received SOAP
     Envelope belongs to ChannelInstance is declared as a pointer, so it is
     essentially an optional element. Tests with Applications not requiring
     ChannelInstance have also been done for the following fix.
  */
  if (oldheader && oldheader->SOAP_WSA(ReplyTo) && oldheader->SOAP_WSA(ReplyTo)->ReferenceParameters && oldheader->SOAP_WSA(ReplyTo)->ReferenceParameters->chan__ChannelInstance)
  {
    if (!newheader->chan__ChannelInstance)
    {
      newheader->chan__ChannelInstance = (struct chan__ChannelInstanceType*)soap_malloc(soap, sizeof(struct chan__ChannelInstanceType));
      if (newheader->chan__ChannelInstance)
      {
    soap_default_chan__ChannelInstanceType(soap, newheader->chan__ChannelInstance);
    newheader->chan__ChannelInstance->__item = *(oldheader->SOAP_WSA(ReplyTo)->ReferenceParameters->chan__ChannelInstance);
    newheader->chan__ChannelInstance->wsa5__IsReferenceParameter = _wsa5__IsReferenceParameter__true;
      }
    }
    else
    {
      newheader->chan__ChannelInstance->__item = *(oldheader->SOAP_WSA(ReplyTo)->ReferenceParameters->chan__ChannelInstance);
      newheader->chan__ChannelInstance->wsa5__IsReferenceParameter = _wsa5__IsReferenceParameter__true;
    }
  }
#endif
  if (oldheader && oldheader->SOAP_WSA(ReplyTo) && oldheader->SOAP_WSA(ReplyTo)->Address && !soap_tagsearch(soap_wsa_allAnonymousURI, oldheader->SOAP_WSA(ReplyTo)->Address))
  {
    newheader->SOAP_WSA(To) = oldheader->SOAP_WSA(ReplyTo)->Address;
    /* (re)connect to ReplyTo endpoint if From != ReplyTo */
    if (!oldheader->SOAP_WSA(From) || !oldheader->SOAP_WSA(From)->Address || strcmp(oldheader->SOAP_WSA(From)->Address, oldheader->SOAP_WSA(ReplyTo)->Address))
    {
      struct soap *reply_soap = soap_new();
      if (reply_soap)
      {
        soap_mode omode = soap->omode;
        /* get the default callbacks */
        int (*fposthdr)(struct soap*, const char*, const char*) = reply_soap->fposthdr;
        int (*fparse)(struct soap*) = reply_soap->fparse;
        int (*fparsehdr)(struct soap*, const char*, const char*) = reply_soap->fparsehdr;
        int (*fresolve)(struct soap*, const char*, struct in_addr* inaddr) = reply_soap->fresolve;
        int (*fconnect)(struct soap*, const char*, const char*, int) = reply_soap->fconnect;
        int (*fclosesocket)(struct soap*, SOAP_SOCKET) = reply_soap->fclosesocket;
        int (*fshutdownsocket)(struct soap*, SOAP_SOCKET, int) = reply_soap->fshutdownsocket;
        SOAP_SOCKET (*fopen)(struct soap*, const char*, const char*, int) = reply_soap->fopen;
        int (*fclose)(struct soap*) = reply_soap->fclose;
        int (*fsend)(struct soap*, const char*, size_t) = reply_soap->fsend;
        size_t (*frecv)(struct soap*, char*, size_t) = reply_soap->frecv;
        int (*fpoll)(struct soap*) = reply_soap->fpoll;
        /* copy the context and active stream */
        soap_copy_context(reply_soap, soap);
        soap_copy_stream(reply_soap, soap);
        /* prevent close in soap_connect() below */
        soap_free_stream(soap);
        soap->omode |= SOAP_ENC_PLAIN; /* omit HTTP header ("encode XML body only") */
        if (data->transfer)
        {
          /* save callbacks */
          data->fposthdr = soap->fposthdr;
          data->fparse = soap->fparse;
          data->fparsehdr = soap->fparsehdr;
          data->fresolve = soap->fresolve;
          data->fconnect = soap->fconnect;
          data->fclosesocket = soap->fclosesocket;
          data->fshutdownsocket = soap->fshutdownsocket;
          data->fopen = soap->fopen;
          data->fclose = soap->fclose;
          data->fsend = soap->fsend;
          data->frecv = soap->frecv;
          data->fpoll = soap->fpoll;
          /* assign default callbacks */
          soap->fposthdr = fposthdr;
          soap->fparse = fparse;
          soap->fparsehdr = fparsehdr;
          soap->fresolve = fresolve;
          soap->fconnect = fconnect;
          soap->fclosesocket = fclosesocket;
          soap->fshutdownsocket = fshutdownsocket;
          soap->fopen = fopen;
          soap->fclose = fclose;
          soap->fsend = fsend;
          soap->frecv = frecv;
          soap->fpoll = fpoll;
        }
        if (soap_connect(soap, newheader->SOAP_WSA(To), newheader->SOAP_WSA(Action)))
        {
          int err;
          if (data->transfer)
          {
            /* restore callbacks */
            soap->fposthdr = data->fposthdr;
            soap->fparse = data->fparse;
            soap->fparsehdr = data->fparsehdr;
            soap->fresolve = data->fresolve;
            soap->fconnect = data->fconnect;
            soap->fclosesocket = data->fclosesocket;
            soap->fshutdownsocket = data->fshutdownsocket;
            soap->fopen = data->fopen;
            soap->fclose = data->fclose;
            soap->fsend = data->fsend;
            soap->frecv = data->frecv;
            soap->fpoll = data->fpoll;
          }
          soap_copy_stream(soap, reply_soap);
          soap_free_stream(reply_soap);
          soap_end(reply_soap);
          soap_free(reply_soap);
          soap->header = oldheader;
          soap->omode = omode; /* restore omode */
#if defined(SOAP_WSA_2005)
          err = soap_wsa_error(soap, SOAP_WSA(DestinationUnreachable), newheader->SOAP_WSA(To));
#elif defined(SOAP_WSA_2003)
          err = soap_wsa_error(soap, "WS-Addessing destination unreachable");
#else
          err = soap_wsa_error(soap, SOAP_WSA(DestinationUnreachable));
#endif
          soap->header = NULL;
          return err;
        }
        if (soap_valid_socket(reply_soap->socket))
          soap_send_empty_response(reply_soap, SOAP_OK); /* HTTP ACCEPTED */
        soap->header = newheader;
        soap_end(reply_soap);
        soap_free(reply_soap);
        data->fresponse = soap->fresponse;
        soap->fresponse = soap_wsa_response;    /* response will be a POST */
        soap->omode = omode; /* restore omode */
      }
    }
  }
  else if (oldheader && oldheader->SOAP_WSA(From))
  {
    newheader->SOAP_WSA(To) = oldheader->SOAP_WSA(From)->Address;
  }
  else
  {
    newheader->SOAP_WSA(To) = (char*)soap_wsa_anonymousURI;
  }
  soap->header = newheader;
  soap->action = newheader->SOAP_WSA(Action);
  return SOAP_OK;
}
 
/******************************************************************************\
 *
 *      Server-side SOAP Fault
 *
\******************************************************************************/
 
/**
@fn int soap_wsa_fault_subcode(struct soap *soap, int flag, const char *faultsubcode, const char *faultstring, const char *faultdetail)
@brief Sets sender/receiver SOAP Fault (sub)code for server fault response.
@param soap context
@param[in] flag 0=receiver, 1=sender
@param[in] faultsubcode sub code string
@param[in] faultstring fault string
@param[in] faultdetail detail string
@return SOAP_FAULT
*/
SOAP_FMAC1
int
SOAP_FMAC2
soap_wsa_fault_subcode(struct soap *soap, int flag, const char *faultsubcode, const char *faultstring, const char *faultdetail)
{
  return soap_wsa_fault_subcode_action(soap, flag, faultsubcode, faultstring, faultdetail, NULL); 
}
 
/******************************************************************************/
 
/**
@fn int soap_wsa_fault_subcode_action(struct soap *soap, int flag, const char *faultsubcode, const char *faultstring, const char *faultdetail, const char *action)
@brief Sets sender/receiver SOAP Fault (sub)code and action for server fault response.
@param soap context
@param[in] flag 0=receiver, 1=sender
@param[in] faultsubcode sub code string
@param[in] faultstring fault string
@param[in] faultdetail detail string
@param[in] action WS-Addressing action string
@return SOAP_FAULT
*/
SOAP_FMAC1
int
SOAP_FMAC2
soap_wsa_fault_subcode_action(struct soap *soap, int flag, const char *faultsubcode, const char *faultstring, const char *faultdetail, const char *action)
{
  struct SOAP_ENV__Header *oldheader, *newheader;
  DBGFUN2("soap_wsa_fault_subcode_action", "faultsubcode=%s", faultsubcode ? faultsubcode : "(null)", "faultstring=%s", faultstring ? faultstring : "(null)");
  oldheader = soap->header;
  /* no FaultTo: use ReplyTo */
  if (oldheader && oldheader->SOAP_WSA(ReplyTo) && (!oldheader->SOAP_WSA(FaultTo) || soap_tagsearch(soap_wsa_allAnonymousURI, oldheader->SOAP_WSA(FaultTo)->Address)))
  {
    if (!oldheader->SOAP_WSA(FaultTo))
    {
      oldheader->SOAP_WSA(FaultTo) = (SOAP_WSA_(,FaultTo)*)soap_malloc(soap, sizeof(SOAP_WSA_(,FaultTo)));
      if (oldheader->SOAP_WSA(FaultTo))
    SOAP_WSA_(soap_default,EndpointReferenceType)(soap, soap->header->SOAP_WSA(FaultTo));
    }
    if (oldheader->SOAP_WSA(FaultTo))
      oldheader->SOAP_WSA(FaultTo)->Address = oldheader->SOAP_WSA(ReplyTo)->Address;
  }
  /* use FaultTo */
  if (oldheader && oldheader->SOAP_WSA(FaultTo) && oldheader->SOAP_WSA(FaultTo)->Address && !strcmp(oldheader->SOAP_WSA(FaultTo)->Address, soap_wsa_noneURI))
    return soap_send_empty_response(soap, SOAP_OK);     /* HTTP ACCEPTED */
  soap->header = NULL;
  /* allocate a new header */
  soap_header(soap);
  newheader = soap->header;
  if (newheader)
  {
    soap_default_SOAP_ENV__Header(soap, newheader); /* remove/clear SOAP Header */
    /* check header */
    if (oldheader && oldheader->SOAP_WSA(MessageID))
    {
      newheader->SOAP_WSA(RelatesTo) = (SOAP_WSA_(,RelatesTo)*)soap_malloc(soap, sizeof(SOAP_WSA_(,RelatesTo)));
      SOAP_WSA_(soap_default_,RelatesTo)(soap, newheader->SOAP_WSA(RelatesTo));
      newheader->SOAP_WSA(RelatesTo)->__item = oldheader->SOAP_WSA(MessageID);
    }
    /* header->wsa__MessageID = "..."; */
    newheader->SOAP_WSA(Action) = (char*)soap_wsa_faultAction;
    if (oldheader && oldheader->SOAP_WSA(FaultTo) && oldheader->SOAP_WSA(FaultTo)->Address && !soap_tagsearch(soap_wsa_allAnonymousURI, oldheader->SOAP_WSA(FaultTo)->Address))
    {
      newheader->SOAP_WSA(To) = oldheader->SOAP_WSA(FaultTo)->Address;
      /* (re)connect to FaultTo endpoint if From != FaultTo */
      if (!oldheader->SOAP_WSA(From) || !oldheader->SOAP_WSA(From)->Address || strcmp(oldheader->SOAP_WSA(From)->Address, oldheader->SOAP_WSA(FaultTo)->Address))
      {
    struct soap_wsa_data *data = (struct soap_wsa_data*)soap_lookup_plugin(soap, soap_wsa_id);
    if (!data)
      return soap->error = SOAP_PLUGIN_ERROR;
    soap->keep_alive = 0;
    soap_send_empty_response(soap, SOAP_OK);  /* HTTP ACCEPTED */
        if (data->transfer)
        {
          struct soap reply_soap;
          soap_init(&reply_soap);
          /* save callbacks */
          data->fposthdr = soap->fposthdr;
          data->fparse = soap->fparse;
          data->fparsehdr = soap->fparsehdr;
          data->fresolve = soap->fresolve;
          data->fconnect = soap->fconnect;
          data->fclosesocket = soap->fclosesocket;
          data->fshutdownsocket = soap->fshutdownsocket;
          data->fopen = soap->fopen;
          data->fclose = soap->fclose;
          data->fsend = soap->fsend;
          data->frecv = soap->frecv;
          data->fpoll = soap->fpoll;
          /* assign default callbacks */
          soap->fposthdr = reply_soap.fposthdr;
          soap->fparse = reply_soap.fparse;
          soap->fparsehdr = reply_soap.fparsehdr;
          soap->fresolve = reply_soap.fresolve;
          soap->fconnect = reply_soap.fconnect;
          soap->fclosesocket = reply_soap.fclosesocket;
          soap->fshutdownsocket = reply_soap.fshutdownsocket;
          soap->fopen = reply_soap.fopen;
          soap->fclose = reply_soap.fclose;
          soap->fsend = reply_soap.fsend;
          soap->frecv = reply_soap.frecv;
          soap->fpoll = reply_soap.fpoll;
 
          soap_end(&reply_soap);
          soap_done(&reply_soap);
        }
    if (soap_connect(soap, newheader->SOAP_WSA(To), newheader->SOAP_WSA(Action)))
        {
          if (data->transfer)
          {
            /* restore callbacks */
            soap->fposthdr = data->fposthdr;
            soap->fparse = data->fparse;
            soap->fparsehdr = data->fparsehdr;
            soap->fresolve = data->fresolve;
            soap->fconnect = data->fconnect;
            soap->fclosesocket = data->fclosesocket;
            soap->fshutdownsocket = data->fshutdownsocket;
            soap->fopen = data->fopen;
            soap->fclose = data->fclose;
            soap->fsend = data->fsend;
            soap->frecv = data->frecv;
            soap->fpoll = data->fpoll;
          }
      return soap->error = SOAP_STOP; /* nowhere to go */
        }
    soap_set_endpoint(soap, newheader->SOAP_WSA(To));
    if (action)
      soap->action = (char*)action;
    else
      soap->action = newheader->SOAP_WSA(Action);
    data->fresponse = soap->fresponse;
    soap->fresponse = soap_wsa_response;      /* response will be a POST */
      }
    }
    else if (oldheader && oldheader->SOAP_WSA(From))
    {
      newheader->SOAP_WSA(To) = oldheader->SOAP_WSA(From)->Address;
    }
    else
    {
      newheader->SOAP_WSA(To) = (char*)soap_wsa_anonymousURI;
    }
    soap->header = newheader;
  }
  if (flag)
    return soap_sender_fault_subcode(soap, faultsubcode, faultstring, faultdetail);
  return soap_receiver_fault_subcode(soap, faultsubcode, faultstring, faultdetail);
}
 
/******************************************************************************/
 
/**
@fn int soap_wsa_sender_fault_subcode(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail)
@brief Sets sender SOAP Fault (sub)code for server fault response.
@param soap context
@param[in] faultsubcode sub code string
@param[in] faultstring fault string
@param[in] faultdetail detail string
@return SOAP_FAULT
*/
SOAP_FMAC1
int
SOAP_FMAC2
soap_wsa_sender_fault_subcode(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail)
{
  return soap_wsa_fault_subcode(soap, 1, faultsubcode, faultstring, faultdetail);
}
 
/******************************************************************************/
 
/**
@fn int soap_wsa_sender_fault_subcode_action(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail, const char *action)
@brief Sets sender SOAP Fault (sub)code for server fault response.
@param soap context
@param[in] faultsubcode sub code string
@param[in] faultstring fault string
@param[in] faultdetail detail string
@param[in] action WS-Addressing action string
@return SOAP_FAULT
*/
SOAP_FMAC1
int
SOAP_FMAC2
soap_wsa_sender_fault_subcode_action(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail, const char *action)
{
  return soap_wsa_fault_subcode_action(soap, 1, faultsubcode, faultstring, faultdetail, action);
}
 
/******************************************************************************/
 
/**
@fn int soap_wsa_receiver_fault_subcode(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail)
@brief Sets receiver SOAP Fault (sub)code for server fault response.
@param soap context
@param[in] faultsubcode sub code string
@param[in] faultstring fault string
@param[in] faultdetail detail string
@return SOAP_FAULT
*/
SOAP_FMAC1
int
SOAP_FMAC2
soap_wsa_receiver_fault_subcode(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail)
{
  return soap_wsa_fault_subcode(soap, 0, faultsubcode, faultstring, faultdetail);
}
 
/******************************************************************************/
 
/**
@fn int soap_wsa_receiver_fault_subcode_action(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail, const char *action)
@brief Sets receiver SOAP Fault (sub)code for server fault response.
@param soap context
@param[in] faultsubcode sub code string
@param[in] faultstring fault string
@param[in] faultdetail detail string
@param[in] action WS-Addressing action string
@return SOAP_FAULT
*/
SOAP_FMAC1
int
SOAP_FMAC2
soap_wsa_receiver_fault_subcode_action(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail, const char *action)
{
  return soap_wsa_fault_subcode_action(soap, 0, faultsubcode, faultstring, faultdetail, action);
}
 
/******************************************************************************/
 
/**
@fn int soap_wsa_sender_fault(struct soap *soap, const char *faultstring, const char *faultdetail)
@brief Sets sender SOAP Fault for server fault response.
@param soap context
@param[in] faultstring fault string
@param[in] faultdetail detail string
@return SOAP_FAULT
*/
SOAP_FMAC1
int
SOAP_FMAC2
soap_wsa_sender_fault(struct soap *soap, const char *faultstring, const char *faultdetail)
{
  return soap_wsa_fault_subcode(soap, 1, NULL, faultstring, faultdetail);
}
 
/******************************************************************************/
 
/**
@fn int soap_wsa_receiver_fault(struct soap *soap, const char *faultstring, const char *faultdetail)
@brief Sets receiver SOAP Fault for server fault response.
@param soap context
@param[in] faultstring fault string
@param[in] faultdetail detail string
@return SOAP_FAULT
*/
SOAP_FMAC1
int
SOAP_FMAC2
soap_wsa_receiver_fault(struct soap *soap, const char *faultstring, const char *faultdetail)
{
  return soap_wsa_fault_subcode(soap, 0, NULL, faultstring, faultdetail);
}
 
/******************************************************************************\
 *
 *      WS-Addressing Faults
 *
\******************************************************************************/
 
#if defined(SOAP_WSA_2005)
 
/**
@fn int soap_wsa_check_fault(struct soap *soap, SOAP_WSA(FaultCodesType) *fault, const char **info)
@brief Checks the presence of a WS-Addressing fault
@param soap context
@param[out] fault code
@param[out] info string pointer related to the wsa fault (or set to NULL)
@return SOAP_OK (no fault) or fault code
*/
SOAP_FMAC1
int
SOAP_FMAC2
soap_wsa_check_fault(struct soap *soap, SOAP_WSA(FaultCodesType) *fault, const char **info)
{
  if (soap->error && soap->fault && soap->fault->SOAP_ENV__Code)
  {
    const char *code = soap_fault_subcode(soap);
    if (code)
    {
      SOAP_WSA__(soap_s2,FaultCodesType)(soap, code, fault);
      if (info)
      {
        struct SOAP_ENV__Detail *detail;
        *info = NULL;
        if (soap->fault->detail)
          detail = soap->fault->detail;
        else
          detail = soap->fault->SOAP_ENV__Detail;
        if (detail)
        {
          switch (detail->__type)
          {
            case SOAP_WSA_(SOAP_TYPE_,ProblemHeaderQName):
            case SOAP_WSA_(SOAP_TYPE_,ProblemIRI):
              *info = (char*)detail->fault;
              break;
            case SOAP_WSA_(SOAP_TYPE_,ProblemAction):
              *info = ((SOAP_WSA_(,ProblemAction)*)detail->fault)->Action;
              break;
            default:
              break;
          }
        }
      }
      return soap->error;
    } 
  }
  return SOAP_OK;
}
 
#elif defined(SOAP_WSA_2003)
 
SOAP_FMAC1
int
SOAP_FMAC2
soap_wsa_check_fault(struct soap *soap, char **fault)
{
  struct SOAP_ENV__Detail detail;
  *fault = NULL;
  if (soap->error && soap->fault)
  {
    if (soap->fault->detail)
      detail = soap->fault->detail;
    else
      detail = soap->fault->SOAP_ENV__Detail;
  }
  if (detail)
  {
    *fault = detail->__any;
    if (*fault)
      return soap->error;
  }
  return SOAP_OK;
}
 
#else
 
/**
@fn int soap_wsa_check_fault(struct soap *soap, SOAP_WSA(FaultSubcodeValues) *fault)
@brief Checks the presence of a WS-Addressing fault
@param soap context
@param[out] fault code
@return SOAP_OK (no fault) or fault code
*/
SOAP_FMAC1
int
SOAP_FMAC2
soap_wsa_check_fault(struct soap *soap, SOAP_WSA(FaultSubcodeValues) *fault)
{
  if (soap->error && soap->fault && soap->fault->SOAP_ENV__Code)
  {
    const char *code = soap_fault_subcode(soap);
    if (code)
    {
      SOAP_WSA__(soap_s2,FaultSubcodeValues)(soap, code, fault);
      return soap->error;
    } 
  }
  return SOAP_OK;
}
#endif
 
#if defined(SOAP_WSA_2005)
 
/**
@fn int soap_wsa_error(struct soap *soap, SOAP_WSA(FaultCodesType) fault, const char *info)
@brief Sets SOAP Fault (sub)code for server WS-Addressing fault response.
@param soap context
@param[in] fault is one of wsa:FaultCodesType enumeration values
@param[in] info is the value of the element in the Fault detail field
@return SOAP_FAULT
*/
SOAP_FMAC1
int
SOAP_FMAC2
soap_wsa_error(struct soap *soap, SOAP_WSA(FaultCodesType) fault, const char *info)
{
  const char *code = SOAP_WSA_(soap,FaultCodesType2s)(soap, fault);
  /* populate the SOAP Fault as per WS-Addressing spec */
  switch (fault)
  {
    case SOAP_WSA(InvalidAddressingHeader):
      soap_faultdetail(soap);
      if (soap->version == 1)
      {
        soap->fault->detail->__type = SOAP_WSA_(SOAP_TYPE_,ProblemHeaderQName);
        soap->fault->detail->fault = (void*)info;
      }
      else if (soap->version == 2)
      {
        soap->fault->SOAP_ENV__Detail->__type = SOAP_WSA_(SOAP_TYPE_,ProblemHeaderQName);
        soap->fault->SOAP_ENV__Detail->fault = (void*)info;
      }
      soap_wsa_sender_fault_subcode(soap, code, "A header representing a Message Addressing Property is not valid and the message cannot be processed.", NULL);
      break;
    case SOAP_WSA(InvalidAddress):
      soap_wsa_sender_fault_subcode(soap, code, "Invalid address.", NULL);
      break;
    case SOAP_WSA(InvalidEPR):
      soap_wsa_sender_fault_subcode(soap, code, "Invalid EPR.", NULL);
      break;
    case SOAP_WSA(InvalidCardinality):
      soap_wsa_sender_fault_subcode(soap, code, "Invalid cardinality of headers.", NULL);
      break;
    case SOAP_WSA(MissingAddressInEPR):
      soap_wsa_sender_fault_subcode(soap, code, "Missing EPR address.", NULL);
      break;
    case SOAP_WSA(DuplicateMessageID):
      soap_wsa_sender_fault_subcode(soap, code, "Message contains the message ID of a message already received.", NULL);
      break;
    case SOAP_WSA(ActionMismatch):
      soap_wsa_sender_fault_subcode(soap, code, "Action and SOAP action of the message do not match.", NULL);
      break;
    case SOAP_WSA(MessageAddressingHeaderRequired):
      soap_faultdetail(soap);
      if (soap->version == 1)
      {
        soap->fault->detail->__type = SOAP_WSA_(SOAP_TYPE_,ProblemHeaderQName);
        soap->fault->detail->fault = (void*)info;
      }
      else if (soap->version == 2)
      {
        soap->fault->SOAP_ENV__Detail->__type = SOAP_WSA_(SOAP_TYPE_,ProblemHeaderQName);
        soap->fault->SOAP_ENV__Detail->fault = (void*)info;
      }
      soap_wsa_sender_fault_subcode(soap, code, "A required header representing a Message Addressing Property is not present.", NULL);
      break;
    case SOAP_WSA(DestinationUnreachable):
      soap_faultdetail(soap);
      if (soap->version == 1)
      {
        soap->fault->detail->__type = SOAP_WSA_(SOAP_TYPE_,ProblemIRI);
        soap->fault->detail->fault = (void*)info;
      }
      else if (soap->version == 2)
      {
        soap->fault->SOAP_ENV__Detail->__type = SOAP_WSA_(SOAP_TYPE_,ProblemIRI);
        soap->fault->SOAP_ENV__Detail->fault = (void*)info;
      }
      soap_wsa_sender_fault_subcode(soap, code, "No route can be determined to reach [destination]", NULL);
      break;
    case SOAP_WSA(ActionNotSupported):
      soap_faultdetail(soap);
      if (soap->version == 1)
      {
        soap->fault->detail->__type = SOAP_WSA_(SOAP_TYPE_,ProblemAction);
        soap->fault->detail->fault = (void*)soap_malloc(soap, sizeof(SOAP_WSA_(,ProblemAction)));
        SOAP_WSA_(soap_default_,ProblemAction)(soap, (SOAP_WSA_(,ProblemAction)*)soap->fault->detail->fault);
        ((SOAP_WSA_(,ProblemAction)*)soap->fault->detail->fault)->Action = (char*)info;
      }
      else if (soap->version == 2)
      {
        soap->fault->SOAP_ENV__Detail->__type = SOAP_WSA_(SOAP_TYPE_,ProblemAction);
        soap->fault->SOAP_ENV__Detail->fault = (void*)soap_malloc(soap, sizeof(SOAP_WSA_(,ProblemAction)));
        SOAP_WSA_(soap_default_,ProblemAction)(soap, (SOAP_WSA_(,ProblemAction)*)soap->fault->SOAP_ENV__Detail->fault);
        ((SOAP_WSA_(,ProblemAction)*)soap->fault->SOAP_ENV__Detail->fault)->Action = (char*)info;
      }
      soap_wsa_sender_fault_subcode(soap, code, "The [action] cannot be processed at the receiver.", NULL);
      break;
    case SOAP_WSA(EndpointUnavailable):
      soap_faultdetail(soap);
      if (soap->version == 1)
      {
        soap->fault->detail->__type = SOAP_WSA_(SOAP_TYPE_,ProblemIRI);
        soap->fault->detail->fault = (void*)info;
      }
      else if (soap->version == 2)
      {
        soap->fault->SOAP_ENV__Detail->__type = SOAP_WSA_(SOAP_TYPE_,ProblemIRI);
        soap->fault->SOAP_ENV__Detail->fault = (void*)info;
      }
      soap_wsa_receiver_fault_subcode(soap, code, "The endpoint is unable to process the message at this time.", NULL);
      break;
    default:
      break;
  }
  return SOAP_FAULT;
}
 
#elif defined(SOAP_WSA_2003)
 
SOAP_FMAC1
int
SOAP_FMAC2
soap_wsa_error(struct soap *soap, const char *fault)
{
  return soap_wsa_sender_fault_subcode(soap, NULL, fault, NULL);
}
 
#else
 
/**
@fn int soap_wsa_error(struct soap *soap, SOAP_WSA(FaultSubcodeValues) fault)
@brief Sets SOAP Fault (sub)code for server WS-Addressing fault response.
@param soap context
@param[in] fault is one of wsa:FaultSubcodeValues
@return SOAP_FAULT
*/
SOAP_FMAC1
int
SOAP_FMAC2
soap_wsa_error(struct soap *soap, SOAP_WSA(FaultSubcodeValues) fault)
{
  const char *code = SOAP_WSA_(soap,FaultSubcodeValues2s)(soap, fault);
  /* populate the SOAP Fault as per WS-Addressing spec */
  switch (fault)
  {
    case SOAP_WSA(InvalidMessageInformationHeader):
      return soap_wsa_sender_fault_subcode(soap, code, "A message information header is not valid and the message cannot be processed. The validity failure can be either structural or semantic, e.g. a [destination] that is not a URI or a [relationship] to a [message id] that was never issued.", "Invalid header");
    case SOAP_WSA(MessageInformationHeaderRequired):
      return soap_wsa_sender_fault_subcode(soap, code, "A required message information header, To, MessageID, or Action, is not present.", "Missing Header QName");
    case SOAP_WSA(DestinationUnreachable):
      return soap_wsa_sender_fault_subcode(soap, code, "No route can be determined to reach the destination role defined by the WS-Addressing To.", NULL);
    case SOAP_WSA(ActionNotSupported):
      return soap_wsa_sender_fault_subcode(soap, code, "The [action] cannot be processed at the receiver.", soap->action);
    case SOAP_WSA(EndpointUnavailable):
      return soap_wsa_receiver_fault_subcode(soap, code, "The endpoint is unable to process the message at this time.", NULL);
    default:
      break;
  }
  return SOAP_FAULT;
}
 
#endif
 
/******************************************************************************\
 *
 *      Plugin registry functions
 *
\******************************************************************************/
 
/**
@fn int soap_wsa(struct soap *soap, struct soap_plugin *p, void *arg)
@brief Plugin registry function, used with soap_register_plugin and soap_register_plugin_arg.
@param soap context
@param[in,out] p plugin created in registry
@param[in] arg passed from soap_register_plugin_arg
@return SOAP_OK
*/
SOAP_FMAC1
int
SOAP_FMAC2
soap_wsa(struct soap *soap, struct soap_plugin *p, void *arg)
{
  DBGFUN("soap_wsa");
  p->id = soap_wsa_id;
  p->data = (void*)SOAP_MALLOC(soap, sizeof(struct soap_wsa_data));
  p->fcopy = NULL;
  p->fdelete = soap_wsa_delete;
  if (!p->data)
    return SOAP_EOM;
  if (soap_wsa_init(soap, (struct soap_wsa_data*)p->data, arg))
  {
    SOAP_FREE(soap, p->data);
    return SOAP_EOM;
  }
  return SOAP_OK;
}
 
/******************************************************************************/
 
/**
@fn int soap_wsa_init(struct soap *soap, struct soap_wsa_data *data)
@brief Initializes plugin data.
@param soap context
@param[in,out] data plugin data
@return SOAP_OK
*/
static int
soap_wsa_init(struct soap *soap, struct soap_wsa_data *data, void *arg)
{
  DBGFUN("soap_wsa_init");
  data->fheader = soap->fheader;
  data->fseterror = soap->fseterror;
  soap->fheader = soap_wsa_header;
  soap->fseterror = soap_wsa_set_error;
  data->fresponse = NULL;
  data->fdisconnect = NULL;
  data->transfer = arg;
  data->fsend = NULL;
  data->frecv = NULL;
  data->fpoll = NULL;
  return SOAP_OK;
}
 
/******************************************************************************/
 
/**
@fn void soap_wsa_delete(struct soap *soap, struct soap_plugin *p)
@brief Deletes plugin data.
@param soap context
@param[in,out] p plugin
@return SOAP_OK
*/
static void
soap_wsa_delete(struct soap *soap, struct soap_plugin *p)
{
  (void)soap;
  DBGFUN("soap_wsa_delete");
  SOAP_FREE(soap, p->data);
}
 
/******************************************************************************\
 *
 *      Callbacks registered by plugin
 *
\******************************************************************************/
 
/**
@fn int soap_wsa_header(struct soap *soap)
@brief Copies WS-Addressing action to SOAP action
@param soap context
@return SOAP_OK or fault
 
This callback is invoked to copy the WS-Addressing action to the SOAP action
before invoking the service operation.
*/
static int
soap_wsa_header(struct soap *soap)
{
  struct soap_wsa_data *data = (struct soap_wsa_data*)soap_lookup_plugin(soap, soap_wsa_id);
  DBGFUN("soap_wsa_header");
  if (!data)
    return soap->error = SOAP_PLUGIN_ERROR;
  if (data->fheader && data->fheader(soap))
    return soap->error;
  if (soap->header && soap->header->SOAP_WSA(Action))
  {
    soap->action = soap->header->SOAP_WSA(Action);
    DBGLOG(TEST, SOAP_MESSAGE(fdebug, "WSA action='%s'\n", soap->action));
  }
  return SOAP_OK;
}
 
/******************************************************************************/
 
/**
@fn void soap_wsa_set_error(struct soap *soap, const char **c, const char **s)
@brief Copies WS-Addressing action to SOAP action
@param soap context
@param c fault code
@param s fault string
*/
static void
soap_wsa_set_error(struct soap *soap, const char **c, const char **s)
{
  struct soap_wsa_data *data = (struct soap_wsa_data*)soap_lookup_plugin(soap, soap_wsa_id);
  DBGFUN2("soap_wsa_set_error", "code=%s", c && *c ? *c : "(null)", "string=%s", s && *s ? *s : "(null)");
  if (!data)
    return;
  if (data->fseterror)
    data->fseterror(soap, c, s);
  if (soap->error == SOAP_NO_METHOD || (soap->error == SOAP_TAG_MISMATCH && soap->level == 2))
  {
#if defined(SOAP_WSA_2005)
    soap->error = soap_wsa_error(soap, SOAP_WSA(ActionNotSupported), soap->action);
#elif defined(SOAP_WSA_2003)
    soap->error = soap_wsa_error(soap, "Action not supported");
#else
    soap->error = soap_wsa_error(soap, SOAP_WSA(ActionNotSupported));
#endif
  }
}
 
/******************************************************************************/
 
/**
@fn int soap_wsa_response(struct soap *soap, int status, ULONG64 count)
@brief Overrides the HTTP response operations to send an HTTP POST
@param soap context
@param status code
@param count message length (if non-chunked)
*/
static int
soap_wsa_response(struct soap *soap, int status, ULONG64 count)
{
  struct soap_wsa_data *data = (struct soap_wsa_data*)soap_lookup_plugin(soap, soap_wsa_id);
  (void)status;
  DBGFUN2("soap_wsa_response", "status=%d", status, "count=%lu", (unsigned long)count);
  if (!data)
    return SOAP_PLUGIN_ERROR;
  soap->fresponse = data->fresponse;    /* reset (HTTP response) */
  data->fdisconnect = soap->fdisconnect;
  soap->fdisconnect = soap_wsa_disconnect; /* to accept HTTP 200 or 202 */
  return soap->fpost(soap, soap_strdup(soap, soap->endpoint), soap->host, soap->port, soap->path, soap->action, count);
}
 
/******************************************************************************/
 
/**
@fn int soap_wsa_disconnect(struct soap *soap)
@brief Accepts HTTP 200 or 202 response upon HTTP POST response relay
@param soap context
*/
static int
soap_wsa_disconnect(struct soap *soap)
{
  int err;
  struct soap_wsa_data *data = (struct soap_wsa_data*)soap_lookup_plugin(soap, soap_wsa_id);
  DBGFUN("soap_wsa_disconnect");
  if (!data)
    return SOAP_PLUGIN_ERROR;
  soap->fdisconnect = data->fdisconnect; /* reset */
  err = soap_recv_empty_response(soap);
  if (data->transfer)
  {
    /* restore callbacks */
    soap->fposthdr = data->fposthdr;
    soap->fparse = data->fparse;
    soap->fparsehdr = data->fparsehdr;
    soap->fresolve = data->fresolve;
    soap->fconnect = data->fconnect;
    soap->fclosesocket = data->fclosesocket;
    soap->fshutdownsocket = data->fshutdownsocket;
    soap->fopen = data->fopen;
    soap->fclose = data->fclose;
    soap->fsend = data->fsend;
    soap->frecv = data->frecv;
    soap->fpoll = data->fpoll;
  }
  return err;
}
 
/******************************************************************************\
 *
 *      Misc.
 *
\******************************************************************************/
 
/**
@fn int soap_wsa_alloc_header(struct soap *soap)
@brief Adds SOAP Header if not present.
@param soap context
@return SOAP_OK
*/
static int
soap_wsa_alloc_header(struct soap *soap)
{
  if (soap->header)
    return SOAP_OK;
  soap_header(soap);
  if (soap->header)
    return SOAP_OK;
  return soap->error = SOAP_EOM;
}
 
/******************************************************************************/
 
#ifdef __cplusplus
}
#endif