diff options
Diffstat (limited to 'dep')
-rw-r--r-- | dep/PackageList.txt | 8 | ||||
-rw-r--r-- | dep/gsoap/soapC.cpp | 143 | ||||
-rw-r--r-- | dep/gsoap/soapH.h | 225 | ||||
-rw-r--r-- | dep/gsoap/soapServer.cpp | 14 | ||||
-rw-r--r-- | dep/gsoap/soapStub.h | 26 | ||||
-rw-r--r-- | dep/gsoap/stdsoap2.cpp | 1758 | ||||
-rw-r--r-- | dep/gsoap/stdsoap2.h | 258 | ||||
-rw-r--r-- | dep/jemalloc/ChangeLog | 24 | ||||
-rw-r--r-- | dep/jemalloc/VERSION | 2 | ||||
-rw-r--r-- | dep/jemalloc/include/jemalloc/internal/hash.h | 2 | ||||
-rw-r--r-- | dep/jemalloc/include/jemalloc/internal/huge.h | 8 | ||||
-rw-r--r-- | dep/jemalloc/include/jemalloc/internal/jemalloc_internal.h | 10 | ||||
-rw-r--r-- | dep/jemalloc/include/jemalloc/internal/private_namespace.h | 1 | ||||
-rw-r--r-- | dep/jemalloc/include/jemalloc/jemalloc.h | 8 | ||||
-rw-r--r-- | dep/jemalloc/src/arena.c | 5 | ||||
-rw-r--r-- | dep/jemalloc/src/huge.c | 26 | ||||
-rw-r--r-- | dep/jemalloc/src/jemalloc.c | 2 | ||||
-rw-r--r-- | dep/jemalloc/src/prof.c | 5 | ||||
-rw-r--r-- | dep/recastnavigation/Detour/CMakeLists.txt | 13 | ||||
-rw-r--r-- | dep/recastnavigation/Detour/Include/DetourAlloc.h (renamed from dep/recastnavigation/Detour/DetourAlloc.h) | 0 | ||||
-rw-r--r-- | dep/recastnavigation/Detour/Include/DetourAssert.h (renamed from dep/recastnavigation/Detour/DetourAssert.h) | 0 | ||||
-rw-r--r-- | dep/recastnavigation/Detour/Include/DetourCommon.h (renamed from dep/recastnavigation/Detour/DetourCommon.h) | 0 | ||||
-rw-r--r-- | dep/recastnavigation/Detour/Include/DetourNavMesh.h (renamed from dep/recastnavigation/Detour/DetourNavMesh.h) | 19 | ||||
-rw-r--r-- | dep/recastnavigation/Detour/Include/DetourNavMeshBuilder.h (renamed from dep/recastnavigation/Detour/DetourNavMeshBuilder.h) | 0 | ||||
-rw-r--r-- | dep/recastnavigation/Detour/Include/DetourNavMeshQuery.h (renamed from dep/recastnavigation/Detour/DetourNavMeshQuery.h) | 54 | ||||
-rw-r--r-- | dep/recastnavigation/Detour/Include/DetourNode.h (renamed from dep/recastnavigation/Detour/DetourNode.h) | 19 | ||||
-rw-r--r-- | dep/recastnavigation/Detour/Include/DetourStatus.h (renamed from dep/recastnavigation/Detour/DetourStatus.h) | 0 | ||||
-rw-r--r-- | dep/recastnavigation/Detour/Source/DetourAlloc.cpp (renamed from dep/recastnavigation/Detour/DetourAlloc.cpp) | 0 | ||||
-rw-r--r-- | dep/recastnavigation/Detour/Source/DetourCommon.cpp (renamed from dep/recastnavigation/Detour/DetourCommon.cpp) | 0 | ||||
-rw-r--r-- | dep/recastnavigation/Detour/Source/DetourNavMesh.cpp (renamed from dep/recastnavigation/Detour/DetourNavMesh.cpp) | 0 | ||||
-rw-r--r-- | dep/recastnavigation/Detour/Source/DetourNavMeshBuilder.cpp (renamed from dep/recastnavigation/Detour/DetourNavMeshBuilder.cpp) | 0 | ||||
-rw-r--r-- | dep/recastnavigation/Detour/Source/DetourNavMeshQuery.cpp (renamed from dep/recastnavigation/Detour/DetourNavMeshQuery.cpp) | 352 | ||||
-rw-r--r-- | dep/recastnavigation/Detour/Source/DetourNode.cpp (renamed from dep/recastnavigation/Detour/DetourNode.cpp) | 26 | ||||
-rw-r--r-- | dep/recastnavigation/Readme.txt | 76 | ||||
-rw-r--r-- | dep/recastnavigation/Recast/CMakeLists.txt | 22 | ||||
-rw-r--r-- | dep/recastnavigation/Recast/Include/Recast.h (renamed from dep/recastnavigation/Recast/Recast.h) | 17 | ||||
-rw-r--r-- | dep/recastnavigation/Recast/Include/RecastAlloc.h (renamed from dep/recastnavigation/Recast/RecastAlloc.h) | 0 | ||||
-rw-r--r-- | dep/recastnavigation/Recast/Include/RecastAssert.h (renamed from dep/recastnavigation/Recast/RecastAssert.h) | 0 | ||||
-rw-r--r-- | dep/recastnavigation/Recast/Source/Recast.cpp (renamed from dep/recastnavigation/Recast/Recast.cpp) | 0 | ||||
-rw-r--r-- | dep/recastnavigation/Recast/Source/RecastAlloc.cpp (renamed from dep/recastnavigation/Recast/RecastAlloc.cpp) | 0 | ||||
-rw-r--r-- | dep/recastnavigation/Recast/Source/RecastArea.cpp (renamed from dep/recastnavigation/Recast/RecastArea.cpp) | 0 | ||||
-rw-r--r-- | dep/recastnavigation/Recast/Source/RecastContour.cpp (renamed from dep/recastnavigation/Recast/RecastContour.cpp) | 535 | ||||
-rw-r--r-- | dep/recastnavigation/Recast/Source/RecastFilter.cpp (renamed from dep/recastnavigation/Recast/RecastFilter.cpp) | 0 | ||||
-rw-r--r-- | dep/recastnavigation/Recast/Source/RecastLayers.cpp (renamed from dep/recastnavigation/Recast/RecastLayers.cpp) | 2 | ||||
-rw-r--r-- | dep/recastnavigation/Recast/Source/RecastMesh.cpp (renamed from dep/recastnavigation/Recast/RecastMesh.cpp) | 86 | ||||
-rw-r--r-- | dep/recastnavigation/Recast/Source/RecastMeshDetail.cpp (renamed from dep/recastnavigation/Recast/RecastMeshDetail.cpp) | 279 | ||||
-rw-r--r-- | dep/recastnavigation/Recast/Source/RecastRasterization.cpp (renamed from dep/recastnavigation/Recast/RecastRasterization.cpp) | 0 | ||||
-rw-r--r-- | dep/recastnavigation/Recast/Source/RecastRegion.cpp (renamed from dep/recastnavigation/Recast/RecastRegion.cpp) | 427 | ||||
-rw-r--r-- | dep/recastnavigation/TODO.txt | 20 | ||||
-rw-r--r-- | dep/recastnavigation/recast_hotfix1.diff | 13 | ||||
-rw-r--r-- | dep/recastnavigation/recast_hotfix2.diff | 38 | ||||
-rw-r--r-- | dep/recastnavigation/recastnavigation.diff | 448 |
52 files changed, 3654 insertions, 1317 deletions
diff --git a/dep/PackageList.txt b/dep/PackageList.txt index 602e9f12bb8..3fa0143a584 100644 --- a/dep/PackageList.txt +++ b/dep/PackageList.txt @@ -14,7 +14,7 @@ G3D (a commercial-grade C++ 3D engine available as Open Source (BSD License) jemalloc (a general-purpose scalable concurrent malloc-implementation) http://www.canonware.com/jemalloc/ - Version: 3.5.1 + Version: 3.6.0 libMPQ (a library for reading MPQ files) https://libmpq.org/ @@ -38,8 +38,8 @@ zlib (A Massively Spiffy Yet Delicately Unobtrusive Compression Library) gSOAP (a portable development toolkit for C and C++ XML Web services and XML data bindings) http://gsoap2.sourceforge.net/ - Version: 2.8.10 + Version: 2.8.17r recastnavigation (Recast is state of the art navigation mesh construction toolset for games) - http://code.google.com/p/recastnavigation/ - Version: 1.4 + https://github.com/memononen/recastnavigation + Version: 42b96b7306d39bb7680ddb0f89d480a8296c83ff diff --git a/dep/gsoap/soapC.cpp b/dep/gsoap/soapC.cpp index 2c675cc339d..321cae0299b 100644 --- a/dep/gsoap/soapC.cpp +++ b/dep/gsoap/soapC.cpp @@ -1,9 +1,9 @@ /* soapC.cpp - Generated by gSOAP 2.8.10 from gsoap.stub + Generated by gSOAP 2.8.17r from gsoap.stub -Copyright(C) 2000-2012, Robert van Engelen, Genivia Inc. All Rights Reserved. +Copyright(C) 2000-2013, Robert van Engelen, Genivia Inc. All Rights Reserved. The generated code is released under one of the following licenses: -1) GPL or 2) Genivia's license for commercial use. +GPL or Genivia's license for commercial use. This program is released under the GPL with the additional exemption that compiling, linking, and/or using OpenSSL is allowed. */ @@ -15,7 +15,7 @@ compiling, linking, and/or using OpenSSL is allowed. #include "soapH.h" -SOAP_SOURCE_STAMP("@(#) soapC.cpp ver 2.8.10 2012-09-02 20:48:00 GMT") +SOAP_SOURCE_STAMP("@(#) soapC.cpp ver 2.8.17r 2014-06-21 21:43:17 GMT") #ifndef WITH_NOGLOBAL @@ -30,7 +30,7 @@ SOAP_FMAC3 int SOAP_FMAC4 soap_getheader(struct soap *soap) SOAP_FMAC3 int SOAP_FMAC4 soap_putheader(struct soap *soap) { - if (soap->header) + if (soap->version && soap->header) { soap->part = SOAP_IN_HEADER; if (soap_out_SOAP_ENV__Header(soap, "SOAP-ENV:Header", 0, soap->header, NULL)) return soap->error; @@ -41,13 +41,13 @@ SOAP_FMAC3 int SOAP_FMAC4 soap_putheader(struct soap *soap) SOAP_FMAC3 void SOAP_FMAC4 soap_serializeheader(struct soap *soap) { - if (soap->header) + if (soap->version && soap->header) soap_serialize_SOAP_ENV__Header(soap, soap->header); } SOAP_FMAC3 void SOAP_FMAC4 soap_header(struct soap *soap) { - if (!soap->header) + if (soap->header == NULL) { if ((soap->header = soap_new_SOAP_ENV__Header(soap, -1))) soap_default_SOAP_ENV__Header(soap, soap->header); } @@ -55,9 +55,9 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_header(struct soap *soap) SOAP_FMAC3 void SOAP_FMAC4 soap_fault(struct soap *soap) { - if (!soap->fault) + if (soap->fault == NULL) { soap->fault = soap_new_SOAP_ENV__Fault(soap, -1); - if (!soap->fault) + if (soap->fault == NULL) return; soap_default_SOAP_ENV__Fault(soap, soap->fault); } @@ -102,7 +102,7 @@ SOAP_FMAC3 const char ** SOAP_FMAC4 soap_faultsubcode(struct soap *soap) { soap_fault(soap); if (soap->version == 2) - { if (!soap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode) + { if (soap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode == NULL) { soap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode = soap_new_SOAP_ENV__Code(soap, -1); soap_default_SOAP_ENV__Code(soap, soap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode); } @@ -133,18 +133,18 @@ SOAP_FMAC3 const char ** SOAP_FMAC4 soap_faultstring(struct soap *soap) SOAP_FMAC3 const char ** SOAP_FMAC4 soap_faultdetail(struct soap *soap) { soap_fault(soap); - if (soap->version == 1) - { if (!soap->fault->detail) - { soap->fault->detail = (struct SOAP_ENV__Detail*)soap_malloc(soap, sizeof(struct SOAP_ENV__Detail)); - soap_default_SOAP_ENV__Detail(soap, soap->fault->detail); + if (soap->version == 2) + { if (soap->fault->SOAP_ENV__Detail == NULL) + { soap->fault->SOAP_ENV__Detail = soap_new_SOAP_ENV__Detail(soap, -1); + soap_default_SOAP_ENV__Detail(soap, soap->fault->SOAP_ENV__Detail); } - return (const char**)&soap->fault->detail->__any; + return (const char**)&soap->fault->SOAP_ENV__Detail->__any; } - if (!soap->fault->SOAP_ENV__Detail) - { soap->fault->SOAP_ENV__Detail = soap_new_SOAP_ENV__Detail(soap, -1); - soap_default_SOAP_ENV__Detail(soap, soap->fault->SOAP_ENV__Detail); + if (soap->fault->detail == NULL) + { soap->fault->detail = soap_new_SOAP_ENV__Detail(soap, -1); + soap_default_SOAP_ENV__Detail(soap, soap->fault->detail); } - return (const char**)&soap->fault->SOAP_ENV__Detail->__any; + return (const char**)&soap->fault->detail->__any; } SOAP_FMAC3 const char * SOAP_FMAC4 soap_check_faultdetail(struct soap *soap) @@ -176,8 +176,6 @@ SOAP_FMAC3 int SOAP_FMAC4 soap_getindependent(struct soap *soap) } #endif -#ifndef WITH_NOIDREF - #ifdef __cplusplus extern "C" { #endif @@ -185,6 +183,7 @@ SOAP_FMAC3 void * SOAP_FMAC4 soap_getelement(struct soap *soap, int *type) { (void)type; if (soap_peek_element(soap)) return NULL; +#ifndef WITH_NOIDREF if (!*soap->id || !(*type = soap_lookup_type(soap, soap->id))) *type = soap_lookup_type(soap, soap->href); switch (*type) @@ -210,6 +209,9 @@ SOAP_FMAC3 void * SOAP_FMAC4 soap_getelement(struct soap *soap, int *type) return s ? *s : NULL; } default: +#else + *type = 0; +#endif { const char *t = soap->type; if (!*t) t = soap->tag; @@ -242,7 +244,9 @@ SOAP_FMAC3 void * SOAP_FMAC4 soap_getelement(struct soap *soap, int *type) return s ? *s : NULL; } t = soap->tag; +#ifndef WITH_NOIDREF } +#endif } soap->error = SOAP_TAG_MISMATCH; return NULL; @@ -251,7 +255,6 @@ SOAP_FMAC3 void * SOAP_FMAC4 soap_getelement(struct soap *soap, int *type) #ifdef __cplusplus } #endif -#endif SOAP_FMAC3 int SOAP_FMAC4 soap_ignore_element(struct soap *soap) { @@ -298,8 +301,6 @@ SOAP_FMAC3 int SOAP_FMAC4 soap_putindependent(struct soap *soap) } #endif -#ifndef WITH_NOIDREF - #ifdef __cplusplus extern "C" { #endif @@ -328,7 +329,6 @@ SOAP_FMAC3 int SOAP_FMAC4 soap_putelement(struct soap *soap, const void *ptr, co #ifdef __cplusplus } #endif -#endif #ifndef WITH_NOIDREF @@ -551,6 +551,7 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_default_SOAP_ENV__Fault(struct soap *soap, struc SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_SOAP_ENV__Fault(struct soap *soap, const struct SOAP_ENV__Fault *a) { +#ifndef WITH_NOIDREF (void)soap; (void)a; /* appease -Wall -Werror */ soap_serialize__QName(soap, &a->faultcode); soap_serialize_string(soap, &a->faultstring); @@ -561,6 +562,7 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_SOAP_ENV__Fault(struct soap *soap, con soap_serialize_string(soap, &a->SOAP_ENV__Node); soap_serialize_string(soap, &a->SOAP_ENV__Role); soap_serialize_PointerToSOAP_ENV__Detail(soap, &a->SOAP_ENV__Detail); +#endif } SOAP_FMAC3 int SOAP_FMAC4 soap_out_SOAP_ENV__Fault(struct soap *soap, const char *tag, int id, const struct SOAP_ENV__Fault *a, const char *type) @@ -703,15 +705,13 @@ SOAP_FMAC1 struct SOAP_ENV__Fault * SOAP_FMAC2 soap_instantiate_SOAP_ENV__Fault( *size = sizeof(struct SOAP_ENV__Fault); } else - { cp->ptr = (void*)SOAP_NEW(struct SOAP_ENV__Fault[n]); - if (!cp->ptr) - { soap->error = SOAP_EOM; - return NULL; - } + { cp->ptr = (void*)SOAP_NEW_ARRAY(struct SOAP_ENV__Fault, n); if (size) *size = n * sizeof(struct SOAP_ENV__Fault); } DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Instantiated location=%p\n", cp->ptr)); + if (!cp->ptr) + soap->error = SOAP_EOM; return (struct SOAP_ENV__Fault*)cp->ptr; } @@ -734,8 +734,10 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_default_SOAP_ENV__Reason(struct soap *soap, stru SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_SOAP_ENV__Reason(struct soap *soap, const struct SOAP_ENV__Reason *a) { +#ifndef WITH_NOIDREF (void)soap; (void)a; /* appease -Wall -Werror */ soap_serialize_string(soap, &a->SOAP_ENV__Text); +#endif } SOAP_FMAC3 int SOAP_FMAC4 soap_out_SOAP_ENV__Reason(struct soap *soap, const char *tag, int id, const struct SOAP_ENV__Reason *a, const char *type) @@ -815,15 +817,13 @@ SOAP_FMAC1 struct SOAP_ENV__Reason * SOAP_FMAC2 soap_instantiate_SOAP_ENV__Reaso *size = sizeof(struct SOAP_ENV__Reason); } else - { cp->ptr = (void*)SOAP_NEW(struct SOAP_ENV__Reason[n]); - if (!cp->ptr) - { soap->error = SOAP_EOM; - return NULL; - } + { cp->ptr = (void*)SOAP_NEW_ARRAY(struct SOAP_ENV__Reason, n); if (size) *size = n * sizeof(struct SOAP_ENV__Reason); } DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Instantiated location=%p\n", cp->ptr)); + if (!cp->ptr) + soap->error = SOAP_EOM; return (struct SOAP_ENV__Reason*)cp->ptr; } @@ -848,8 +848,10 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_default_SOAP_ENV__Detail(struct soap *soap, stru SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_SOAP_ENV__Detail(struct soap *soap, const struct SOAP_ENV__Detail *a) { +#ifndef WITH_NOIDREF (void)soap; (void)a; /* appease -Wall -Werror */ soap_markelement(soap, a->fault, a->__type); +#endif } SOAP_FMAC3 int SOAP_FMAC4 soap_out_SOAP_ENV__Detail(struct soap *soap, const char *tag, int id, const struct SOAP_ENV__Detail *a, const char *type) @@ -934,15 +936,13 @@ SOAP_FMAC1 struct SOAP_ENV__Detail * SOAP_FMAC2 soap_instantiate_SOAP_ENV__Detai *size = sizeof(struct SOAP_ENV__Detail); } else - { cp->ptr = (void*)SOAP_NEW(struct SOAP_ENV__Detail[n]); - if (!cp->ptr) - { soap->error = SOAP_EOM; - return NULL; - } + { cp->ptr = (void*)SOAP_NEW_ARRAY(struct SOAP_ENV__Detail, n); if (size) *size = n * sizeof(struct SOAP_ENV__Detail); } DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Instantiated location=%p\n", cp->ptr)); + if (!cp->ptr) + soap->error = SOAP_EOM; return (struct SOAP_ENV__Detail*)cp->ptr; } @@ -966,9 +966,11 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_default_SOAP_ENV__Code(struct soap *soap, struct SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_SOAP_ENV__Code(struct soap *soap, const struct SOAP_ENV__Code *a) { +#ifndef WITH_NOIDREF (void)soap; (void)a; /* appease -Wall -Werror */ soap_serialize__QName(soap, &a->SOAP_ENV__Value); soap_serialize_PointerToSOAP_ENV__Code(soap, &a->SOAP_ENV__Subcode); +#endif } SOAP_FMAC3 int SOAP_FMAC4 soap_out_SOAP_ENV__Code(struct soap *soap, const char *tag, int id, const struct SOAP_ENV__Code *a, const char *type) @@ -1055,15 +1057,13 @@ SOAP_FMAC1 struct SOAP_ENV__Code * SOAP_FMAC2 soap_instantiate_SOAP_ENV__Code(st *size = sizeof(struct SOAP_ENV__Code); } else - { cp->ptr = (void*)SOAP_NEW(struct SOAP_ENV__Code[n]); - if (!cp->ptr) - { soap->error = SOAP_EOM; - return NULL; - } + { cp->ptr = (void*)SOAP_NEW_ARRAY(struct SOAP_ENV__Code, n); if (size) *size = n * sizeof(struct SOAP_ENV__Code); } DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Instantiated location=%p\n", cp->ptr)); + if (!cp->ptr) + soap->error = SOAP_EOM; return (struct SOAP_ENV__Code*)cp->ptr; } @@ -1085,7 +1085,9 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_default_SOAP_ENV__Header(struct soap *soap, stru SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_SOAP_ENV__Header(struct soap *soap, const struct SOAP_ENV__Header *a) { +#ifndef WITH_NOIDREF (void)soap; (void)a; /* appease -Wall -Werror */ +#endif } SOAP_FMAC3 int SOAP_FMAC4 soap_out_SOAP_ENV__Header(struct soap *soap, const char *tag, int id, const struct SOAP_ENV__Header *a, const char *type) @@ -1155,15 +1157,13 @@ SOAP_FMAC1 struct SOAP_ENV__Header * SOAP_FMAC2 soap_instantiate_SOAP_ENV__Heade *size = sizeof(struct SOAP_ENV__Header); } else - { cp->ptr = (void*)SOAP_NEW(struct SOAP_ENV__Header[n]); - if (!cp->ptr) - { soap->error = SOAP_EOM; - return NULL; - } + { cp->ptr = (void*)SOAP_NEW_ARRAY(struct SOAP_ENV__Header, n); if (size) *size = n * sizeof(struct SOAP_ENV__Header); } DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Instantiated location=%p\n", cp->ptr)); + if (!cp->ptr) + soap->error = SOAP_EOM; return (struct SOAP_ENV__Header*)cp->ptr; } @@ -1184,8 +1184,10 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_default_ns1__executeCommand(struct soap *soap, s SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_ns1__executeCommand(struct soap *soap, const struct ns1__executeCommand *a) { +#ifndef WITH_NOIDREF (void)soap; (void)a; /* appease -Wall -Werror */ soap_serialize_string(soap, &a->command); +#endif } SOAP_FMAC3 int SOAP_FMAC4 soap_out_ns1__executeCommand(struct soap *soap, const char *tag, int id, const struct ns1__executeCommand *a, const char *type) @@ -1263,15 +1265,13 @@ SOAP_FMAC1 struct ns1__executeCommand * SOAP_FMAC2 soap_instantiate_ns1__execute *size = sizeof(struct ns1__executeCommand); } else - { cp->ptr = (void*)SOAP_NEW(struct ns1__executeCommand[n]); - if (!cp->ptr) - { soap->error = SOAP_EOM; - return NULL; - } + { cp->ptr = (void*)SOAP_NEW_ARRAY(struct ns1__executeCommand, n); if (size) *size = n * sizeof(struct ns1__executeCommand); } DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Instantiated location=%p\n", cp->ptr)); + if (!cp->ptr) + soap->error = SOAP_EOM; return (struct ns1__executeCommand*)cp->ptr; } @@ -1290,8 +1290,10 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_default_ns1__executeCommandResponse(struct soap SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_ns1__executeCommandResponse(struct soap *soap, const struct ns1__executeCommandResponse *a) { +#ifndef WITH_NOIDREF (void)soap; (void)a; /* appease -Wall -Werror */ soap_serialize_PointerTostring(soap, &a->result); +#endif } SOAP_FMAC3 int SOAP_FMAC4 soap_out_ns1__executeCommandResponse(struct soap *soap, const char *tag, int id, const struct ns1__executeCommandResponse *a, const char *type) @@ -1369,15 +1371,13 @@ SOAP_FMAC1 struct ns1__executeCommandResponse * SOAP_FMAC2 soap_instantiate_ns1_ *size = sizeof(struct ns1__executeCommandResponse); } else - { cp->ptr = (void*)SOAP_NEW(struct ns1__executeCommandResponse[n]); - if (!cp->ptr) - { soap->error = SOAP_EOM; - return NULL; - } + { cp->ptr = (void*)SOAP_NEW_ARRAY(struct ns1__executeCommandResponse, n); if (size) *size = n * sizeof(struct ns1__executeCommandResponse); } DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Instantiated location=%p\n", cp->ptr)); + if (!cp->ptr) + soap->error = SOAP_EOM; return (struct ns1__executeCommandResponse*)cp->ptr; } @@ -1392,8 +1392,10 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_copy_ns1__executeCommandResponse(struct soap *so SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_PointerToSOAP_ENV__Reason(struct soap *soap, struct SOAP_ENV__Reason *const*a) { +#ifndef WITH_NOIDREF if (!soap_reference(soap, *a, SOAP_TYPE_SOAP_ENV__Reason)) soap_serialize_SOAP_ENV__Reason(soap, *a); +#endif } SOAP_FMAC3 int SOAP_FMAC4 soap_out_PointerToSOAP_ENV__Reason(struct soap *soap, const char *tag, int id, struct SOAP_ENV__Reason *const*a, const char *type) @@ -1414,8 +1416,6 @@ SOAP_FMAC3 struct SOAP_ENV__Reason ** SOAP_FMAC4 soap_in_PointerToSOAP_ENV__Reas *a = NULL; if (!soap->null && *soap->href != '#') { soap_revert(soap); - *a = (struct SOAP_ENV__Reason *)soap_malloc(soap, sizeof(struct SOAP_ENV__Reason)); - soap_default_SOAP_ENV__Reason(soap, *a); if (!(*a = soap_in_SOAP_ENV__Reason(soap, tag, *a, type))) return NULL; } @@ -1449,8 +1449,10 @@ SOAP_FMAC3 struct SOAP_ENV__Reason ** SOAP_FMAC4 soap_get_PointerToSOAP_ENV__Rea SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_PointerToSOAP_ENV__Detail(struct soap *soap, struct SOAP_ENV__Detail *const*a) { +#ifndef WITH_NOIDREF if (!soap_reference(soap, *a, SOAP_TYPE_SOAP_ENV__Detail)) soap_serialize_SOAP_ENV__Detail(soap, *a); +#endif } SOAP_FMAC3 int SOAP_FMAC4 soap_out_PointerToSOAP_ENV__Detail(struct soap *soap, const char *tag, int id, struct SOAP_ENV__Detail *const*a, const char *type) @@ -1471,8 +1473,6 @@ SOAP_FMAC3 struct SOAP_ENV__Detail ** SOAP_FMAC4 soap_in_PointerToSOAP_ENV__Deta *a = NULL; if (!soap->null && *soap->href != '#') { soap_revert(soap); - *a = (struct SOAP_ENV__Detail *)soap_malloc(soap, sizeof(struct SOAP_ENV__Detail)); - soap_default_SOAP_ENV__Detail(soap, *a); if (!(*a = soap_in_SOAP_ENV__Detail(soap, tag, *a, type))) return NULL; } @@ -1506,8 +1506,10 @@ SOAP_FMAC3 struct SOAP_ENV__Detail ** SOAP_FMAC4 soap_get_PointerToSOAP_ENV__Det SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_PointerToSOAP_ENV__Code(struct soap *soap, struct SOAP_ENV__Code *const*a) { +#ifndef WITH_NOIDREF if (!soap_reference(soap, *a, SOAP_TYPE_SOAP_ENV__Code)) soap_serialize_SOAP_ENV__Code(soap, *a); +#endif } SOAP_FMAC3 int SOAP_FMAC4 soap_out_PointerToSOAP_ENV__Code(struct soap *soap, const char *tag, int id, struct SOAP_ENV__Code *const*a, const char *type) @@ -1528,8 +1530,6 @@ SOAP_FMAC3 struct SOAP_ENV__Code ** SOAP_FMAC4 soap_in_PointerToSOAP_ENV__Code(s *a = NULL; if (!soap->null && *soap->href != '#') { soap_revert(soap); - *a = (struct SOAP_ENV__Code *)soap_malloc(soap, sizeof(struct SOAP_ENV__Code)); - soap_default_SOAP_ENV__Code(soap, *a); if (!(*a = soap_in_SOAP_ENV__Code(soap, tag, *a, type))) return NULL; } @@ -1561,8 +1561,10 @@ SOAP_FMAC3 struct SOAP_ENV__Code ** SOAP_FMAC4 soap_get_PointerToSOAP_ENV__Code( SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_PointerTostring(struct soap *soap, char **const*a) { +#ifndef WITH_NOIDREF if (!soap_reference(soap, *a, SOAP_TYPE_string)) soap_serialize_string(soap, *a); +#endif } SOAP_FMAC3 int SOAP_FMAC4 soap_out_PointerTostring(struct soap *soap, const char *tag, int id, char **const*a, const char *type) @@ -1610,6 +1612,13 @@ SOAP_FMAC3 char *** SOAP_FMAC4 soap_get_PointerTostring(struct soap *soap, char return p; } +SOAP_FMAC3 void SOAP_FMAC4 soap_serialize__QName(struct soap *soap, char *const*a) +{ +#ifndef WITH_NOIDREF + soap_reference(soap, *a, SOAP_TYPE__QName); +#endif +} + SOAP_FMAC3 int SOAP_FMAC4 soap_out__QName(struct soap *soap, const char *tag, int id, char *const*a, const char *type) { return soap_outstring(soap, tag, id, a, type, SOAP_TYPE__QName); @@ -1649,7 +1658,9 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_default_string(struct soap *soap, char **a) SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_string(struct soap *soap, char *const*a) { +#ifndef WITH_NOIDREF soap_reference(soap, *a, SOAP_TYPE_string); +#endif } SOAP_FMAC3 int SOAP_FMAC4 soap_out_string(struct soap *soap, const char *tag, int id, char *const*a, const char *type) diff --git a/dep/gsoap/soapH.h b/dep/gsoap/soapH.h index 06e9ec21239..a73b369fe90 100644 --- a/dep/gsoap/soapH.h +++ b/dep/gsoap/soapH.h @@ -1,9 +1,9 @@ /* soapH.h - Generated by gSOAP 2.8.10 from gsoap.stub + Generated by gSOAP 2.8.17r from gsoap.stub -Copyright(C) 2000-2012, Robert van Engelen, Genivia Inc. All Rights Reserved. +Copyright(C) 2000-2013, Robert van Engelen, Genivia Inc. All Rights Reserved. The generated code is released under one of the following licenses: -1) GPL or 2) Genivia's license for commercial use. +GPL or Genivia's license for commercial use. This program is released under the GPL with the additional exemption that compiling, linking, and/or using OpenSSL is allowed. */ @@ -17,8 +17,6 @@ compiling, linking, and/or using OpenSSL is allowed. extern "C" { #endif SOAP_FMAC3 void SOAP_FMAC4 soap_markelement(struct soap*, const void*, int); -SOAP_FMAC3 int SOAP_FMAC4 soap_putelement(struct soap*, const void*, const char*, int, int); -SOAP_FMAC3 void *SOAP_FMAC4 soap_getelement(struct soap*, int*); #ifdef __cplusplus } @@ -26,8 +24,20 @@ SOAP_FMAC3 void *SOAP_FMAC4 soap_getelement(struct soap*, int*); SOAP_FMAC3 int SOAP_FMAC4 soap_putindependent(struct soap*); SOAP_FMAC3 int SOAP_FMAC4 soap_getindependent(struct soap*); #endif + +#ifdef __cplusplus +extern "C" { +#endif +SOAP_FMAC3 void *SOAP_FMAC4 soap_getelement(struct soap*, int*); +SOAP_FMAC3 int SOAP_FMAC4 soap_putelement(struct soap*, const void*, const char*, int, int); + +#ifdef __cplusplus +} +#endif SOAP_FMAC3 int SOAP_FMAC4 soap_ignore_element(struct soap*); +SOAP_FMAC3 const char ** SOAP_FMAC4 soap_faultcode(struct soap *soap); + SOAP_FMAC3 void * SOAP_FMAC4 soap_instantiate(struct soap*, int, const char*, const char*, size_t*); SOAP_FMAC3 int SOAP_FMAC4 soap_fdelete(struct soap_clist*); SOAP_FMAC3 void* SOAP_FMAC4 soap_class_id_enter(struct soap*, const char*, void*, int, size_t, const char*, const char*); @@ -39,18 +49,18 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_default_byte(struct soap*, char *); SOAP_FMAC3 int SOAP_FMAC4 soap_out_byte(struct soap*, const char*, int, const char *, const char*); SOAP_FMAC3 char * SOAP_FMAC4 soap_in_byte(struct soap*, const char*, char *, const char*); +SOAP_FMAC3 int SOAP_FMAC4 soap_put_byte(struct soap*, const char *, const char*, const char*); + #ifndef soap_write_byte -#define soap_write_byte(soap, data) ( soap_begin_send(soap) || soap_put_byte(soap, data, "byte", NULL) || soap_end_send(soap) ) +#define soap_write_byte(soap, data) ( soap_free_temp(soap), soap_begin_send(soap) || (soap_serialize_byte(soap, data),0) || soap_put_byte(soap, data, "byte", NULL) || soap_end_send(soap), (soap)->error ) #endif - -SOAP_FMAC3 int SOAP_FMAC4 soap_put_byte(struct soap*, const char *, const char*, const char*); +SOAP_FMAC3 char * SOAP_FMAC4 soap_get_byte(struct soap*, char *, const char*, const char*); #ifndef soap_read_byte -#define soap_read_byte(soap, data) ( soap_begin_recv(soap) || !soap_get_byte(soap, data, NULL, NULL) || soap_end_recv(soap) ) +#define soap_read_byte(soap, data) ( soap_begin_recv(soap) || !soap_get_byte(soap, data, NULL, NULL) || soap_end_recv(soap), (soap)->error ) #endif -SOAP_FMAC3 char * SOAP_FMAC4 soap_get_byte(struct soap*, char *, const char*, const char*); #ifndef SOAP_TYPE_int #define SOAP_TYPE_int (1) @@ -59,18 +69,18 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_default_int(struct soap*, int *); SOAP_FMAC3 int SOAP_FMAC4 soap_out_int(struct soap*, const char*, int, const int *, const char*); SOAP_FMAC3 int * SOAP_FMAC4 soap_in_int(struct soap*, const char*, int *, const char*); +SOAP_FMAC3 int SOAP_FMAC4 soap_put_int(struct soap*, const int *, const char*, const char*); + #ifndef soap_write_int -#define soap_write_int(soap, data) ( soap_begin_send(soap) || soap_put_int(soap, data, "int", NULL) || soap_end_send(soap) ) +#define soap_write_int(soap, data) ( soap_free_temp(soap), soap_begin_send(soap) || (soap_serialize_int(soap, data),0) || soap_put_int(soap, data, "int", NULL) || soap_end_send(soap), (soap)->error ) #endif - -SOAP_FMAC3 int SOAP_FMAC4 soap_put_int(struct soap*, const int *, const char*, const char*); +SOAP_FMAC3 int * SOAP_FMAC4 soap_get_int(struct soap*, int *, const char*, const char*); #ifndef soap_read_int -#define soap_read_int(soap, data) ( soap_begin_recv(soap) || !soap_get_int(soap, data, NULL, NULL) || soap_end_recv(soap) ) +#define soap_read_int(soap, data) ( soap_begin_recv(soap) || !soap_get_int(soap, data, NULL, NULL) || soap_end_recv(soap), (soap)->error ) #endif -SOAP_FMAC3 int * SOAP_FMAC4 soap_get_int(struct soap*, int *, const char*, const char*); #ifndef WITH_NOGLOBAL @@ -82,25 +92,28 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_SOAP_ENV__Fault(struct soap*, const st SOAP_FMAC3 int SOAP_FMAC4 soap_out_SOAP_ENV__Fault(struct soap*, const char*, int, const struct SOAP_ENV__Fault *, const char*); SOAP_FMAC3 struct SOAP_ENV__Fault * SOAP_FMAC4 soap_in_SOAP_ENV__Fault(struct soap*, const char*, struct SOAP_ENV__Fault *, const char*); +SOAP_FMAC3 int SOAP_FMAC4 soap_put_SOAP_ENV__Fault(struct soap*, const struct SOAP_ENV__Fault *, const char*, const char*); + #ifndef soap_write_SOAP_ENV__Fault -#define soap_write_SOAP_ENV__Fault(soap, data) ( soap_begin_send(soap) || (soap_serialize_SOAP_ENV__Fault(soap, data), 0) || soap_put_SOAP_ENV__Fault(soap, data, "SOAP-ENV:Fault", NULL) || soap_end_send(soap) ) +#define soap_write_SOAP_ENV__Fault(soap, data) ( soap_free_temp(soap), soap_begin_send(soap) || (soap_serialize_SOAP_ENV__Fault(soap, data),0) || soap_put_SOAP_ENV__Fault(soap, data, "SOAP-ENV:Fault", NULL) || soap_end_send(soap), (soap)->error ) #endif - -SOAP_FMAC3 int SOAP_FMAC4 soap_put_SOAP_ENV__Fault(struct soap*, const struct SOAP_ENV__Fault *, const char*, const char*); +SOAP_FMAC3 struct SOAP_ENV__Fault * SOAP_FMAC4 soap_get_SOAP_ENV__Fault(struct soap*, struct SOAP_ENV__Fault *, const char*, const char*); #ifndef soap_read_SOAP_ENV__Fault -#define soap_read_SOAP_ENV__Fault(soap, data) ( soap_begin_recv(soap) || !soap_get_SOAP_ENV__Fault(soap, data, NULL, NULL) || soap_end_recv(soap) ) +#define soap_read_SOAP_ENV__Fault(soap, data) ( soap_begin_recv(soap) || !soap_get_SOAP_ENV__Fault(soap, data, NULL, NULL) || soap_end_recv(soap), (soap)->error ) #endif -SOAP_FMAC3 struct SOAP_ENV__Fault * SOAP_FMAC4 soap_get_SOAP_ENV__Fault(struct soap*, struct SOAP_ENV__Fault *, const char*, const char*); +SOAP_FMAC1 struct SOAP_ENV__Fault * SOAP_FMAC2 soap_instantiate_SOAP_ENV__Fault(struct soap*, int, const char*, const char*, size_t*); -#define soap_new_SOAP_ENV__Fault(soap, n) soap_instantiate_SOAP_ENV__Fault(soap, n, NULL, NULL, NULL) +inline struct SOAP_ENV__Fault * soap_new_SOAP_ENV__Fault(struct soap *soap, int n = -1) { return soap_instantiate_SOAP_ENV__Fault(soap, n, NULL, NULL, NULL); } +inline struct SOAP_ENV__Fault * soap_new_req_SOAP_ENV__Fault(struct soap *soap) { struct SOAP_ENV__Fault *_p = soap_instantiate_SOAP_ENV__Fault(soap, -1, NULL, NULL, NULL); if (_p) { soap_default_SOAP_ENV__Fault(soap, _p); } return _p; } -#define soap_delete_SOAP_ENV__Fault(soap, p) soap_delete(soap, p) +inline struct SOAP_ENV__Fault * soap_new_set_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) { struct SOAP_ENV__Fault *_p = soap_instantiate_SOAP_ENV__Fault(soap, -1, NULL, NULL, NULL); if (_p) { soap_default_SOAP_ENV__Fault(soap, _p); _p->faultcode = faultcode; _p->faultstring = faultstring; _p->faultactor = faultactor; _p->detail = detail; _p->SOAP_ENV__Code = SOAP_ENV__Code; _p->SOAP_ENV__Reason = SOAP_ENV__Reason; _p->SOAP_ENV__Node = SOAP_ENV__Node; _p->SOAP_ENV__Role = SOAP_ENV__Role; _p->SOAP_ENV__Detail = SOAP_ENV__Detail; } return _p; } + +inline void soap_delete_SOAP_ENV__Fault(struct soap *soap, struct SOAP_ENV__Fault *p) { soap_delete(soap, p); } -SOAP_FMAC1 struct SOAP_ENV__Fault * SOAP_FMAC2 soap_instantiate_SOAP_ENV__Fault(struct soap*, int, const char*, const char*, size_t*); SOAP_FMAC3 void SOAP_FMAC4 soap_copy_SOAP_ENV__Fault(struct soap*, int, int, void*, size_t, const void*, size_t); #endif @@ -115,25 +128,28 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_SOAP_ENV__Reason(struct soap*, const s SOAP_FMAC3 int SOAP_FMAC4 soap_out_SOAP_ENV__Reason(struct soap*, const char*, int, const struct SOAP_ENV__Reason *, const char*); SOAP_FMAC3 struct SOAP_ENV__Reason * SOAP_FMAC4 soap_in_SOAP_ENV__Reason(struct soap*, const char*, struct SOAP_ENV__Reason *, const char*); +SOAP_FMAC3 int SOAP_FMAC4 soap_put_SOAP_ENV__Reason(struct soap*, const struct SOAP_ENV__Reason *, const char*, const char*); + #ifndef soap_write_SOAP_ENV__Reason -#define soap_write_SOAP_ENV__Reason(soap, data) ( soap_begin_send(soap) || (soap_serialize_SOAP_ENV__Reason(soap, data), 0) || soap_put_SOAP_ENV__Reason(soap, data, "SOAP-ENV:Reason", NULL) || soap_end_send(soap) ) +#define soap_write_SOAP_ENV__Reason(soap, data) ( soap_free_temp(soap), soap_begin_send(soap) || (soap_serialize_SOAP_ENV__Reason(soap, data),0) || soap_put_SOAP_ENV__Reason(soap, data, "SOAP-ENV:Reason", NULL) || soap_end_send(soap), (soap)->error ) #endif - -SOAP_FMAC3 int SOAP_FMAC4 soap_put_SOAP_ENV__Reason(struct soap*, const struct SOAP_ENV__Reason *, const char*, const char*); +SOAP_FMAC3 struct SOAP_ENV__Reason * SOAP_FMAC4 soap_get_SOAP_ENV__Reason(struct soap*, struct SOAP_ENV__Reason *, const char*, const char*); #ifndef soap_read_SOAP_ENV__Reason -#define soap_read_SOAP_ENV__Reason(soap, data) ( soap_begin_recv(soap) || !soap_get_SOAP_ENV__Reason(soap, data, NULL, NULL) || soap_end_recv(soap) ) +#define soap_read_SOAP_ENV__Reason(soap, data) ( soap_begin_recv(soap) || !soap_get_SOAP_ENV__Reason(soap, data, NULL, NULL) || soap_end_recv(soap), (soap)->error ) #endif -SOAP_FMAC3 struct SOAP_ENV__Reason * SOAP_FMAC4 soap_get_SOAP_ENV__Reason(struct soap*, struct SOAP_ENV__Reason *, const char*, const char*); +SOAP_FMAC1 struct SOAP_ENV__Reason * SOAP_FMAC2 soap_instantiate_SOAP_ENV__Reason(struct soap*, int, const char*, const char*, size_t*); -#define soap_new_SOAP_ENV__Reason(soap, n) soap_instantiate_SOAP_ENV__Reason(soap, n, NULL, NULL, NULL) +inline struct SOAP_ENV__Reason * soap_new_SOAP_ENV__Reason(struct soap *soap, int n = -1) { return soap_instantiate_SOAP_ENV__Reason(soap, n, NULL, NULL, NULL); } +inline struct SOAP_ENV__Reason * soap_new_req_SOAP_ENV__Reason(struct soap *soap) { struct SOAP_ENV__Reason *_p = soap_instantiate_SOAP_ENV__Reason(soap, -1, NULL, NULL, NULL); if (_p) { soap_default_SOAP_ENV__Reason(soap, _p); } return _p; } -#define soap_delete_SOAP_ENV__Reason(soap, p) soap_delete(soap, p) +inline struct SOAP_ENV__Reason * soap_new_set_SOAP_ENV__Reason(struct soap *soap, char *SOAP_ENV__Text) { struct SOAP_ENV__Reason *_p = soap_instantiate_SOAP_ENV__Reason(soap, -1, NULL, NULL, NULL); if (_p) { soap_default_SOAP_ENV__Reason(soap, _p); _p->SOAP_ENV__Text = SOAP_ENV__Text; } return _p; } + +inline void soap_delete_SOAP_ENV__Reason(struct soap *soap, struct SOAP_ENV__Reason *p) { soap_delete(soap, p); } -SOAP_FMAC1 struct SOAP_ENV__Reason * SOAP_FMAC2 soap_instantiate_SOAP_ENV__Reason(struct soap*, int, const char*, const char*, size_t*); SOAP_FMAC3 void SOAP_FMAC4 soap_copy_SOAP_ENV__Reason(struct soap*, int, int, void*, size_t, const void*, size_t); #endif @@ -148,25 +164,28 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_SOAP_ENV__Detail(struct soap*, const s SOAP_FMAC3 int SOAP_FMAC4 soap_out_SOAP_ENV__Detail(struct soap*, const char*, int, const struct SOAP_ENV__Detail *, const char*); SOAP_FMAC3 struct SOAP_ENV__Detail * SOAP_FMAC4 soap_in_SOAP_ENV__Detail(struct soap*, const char*, struct SOAP_ENV__Detail *, const char*); +SOAP_FMAC3 int SOAP_FMAC4 soap_put_SOAP_ENV__Detail(struct soap*, const struct SOAP_ENV__Detail *, const char*, const char*); + #ifndef soap_write_SOAP_ENV__Detail -#define soap_write_SOAP_ENV__Detail(soap, data) ( soap_begin_send(soap) || (soap_serialize_SOAP_ENV__Detail(soap, data), 0) || soap_put_SOAP_ENV__Detail(soap, data, "SOAP-ENV:Detail", NULL) || soap_end_send(soap) ) +#define soap_write_SOAP_ENV__Detail(soap, data) ( soap_free_temp(soap), soap_begin_send(soap) || (soap_serialize_SOAP_ENV__Detail(soap, data),0) || soap_put_SOAP_ENV__Detail(soap, data, "SOAP-ENV:Detail", NULL) || soap_end_send(soap), (soap)->error ) #endif - -SOAP_FMAC3 int SOAP_FMAC4 soap_put_SOAP_ENV__Detail(struct soap*, const struct SOAP_ENV__Detail *, const char*, const char*); +SOAP_FMAC3 struct SOAP_ENV__Detail * SOAP_FMAC4 soap_get_SOAP_ENV__Detail(struct soap*, struct SOAP_ENV__Detail *, const char*, const char*); #ifndef soap_read_SOAP_ENV__Detail -#define soap_read_SOAP_ENV__Detail(soap, data) ( soap_begin_recv(soap) || !soap_get_SOAP_ENV__Detail(soap, data, NULL, NULL) || soap_end_recv(soap) ) +#define soap_read_SOAP_ENV__Detail(soap, data) ( soap_begin_recv(soap) || !soap_get_SOAP_ENV__Detail(soap, data, NULL, NULL) || soap_end_recv(soap), (soap)->error ) #endif -SOAP_FMAC3 struct SOAP_ENV__Detail * SOAP_FMAC4 soap_get_SOAP_ENV__Detail(struct soap*, struct SOAP_ENV__Detail *, const char*, const char*); +SOAP_FMAC1 struct SOAP_ENV__Detail * SOAP_FMAC2 soap_instantiate_SOAP_ENV__Detail(struct soap*, int, const char*, const char*, size_t*); -#define soap_new_SOAP_ENV__Detail(soap, n) soap_instantiate_SOAP_ENV__Detail(soap, n, NULL, NULL, NULL) +inline struct SOAP_ENV__Detail * soap_new_SOAP_ENV__Detail(struct soap *soap, int n = -1) { return soap_instantiate_SOAP_ENV__Detail(soap, n, NULL, NULL, NULL); } +inline struct SOAP_ENV__Detail * soap_new_req_SOAP_ENV__Detail(struct soap *soap, int __type, void *fault) { struct SOAP_ENV__Detail *_p = soap_instantiate_SOAP_ENV__Detail(soap, -1, NULL, NULL, NULL); if (_p) { soap_default_SOAP_ENV__Detail(soap, _p); _p->__type = __type; _p->fault = fault; } return _p; } -#define soap_delete_SOAP_ENV__Detail(soap, p) soap_delete(soap, p) +inline struct SOAP_ENV__Detail * soap_new_set_SOAP_ENV__Detail(struct soap *soap, char *__any, int __type, void *fault) { struct SOAP_ENV__Detail *_p = soap_instantiate_SOAP_ENV__Detail(soap, -1, NULL, NULL, NULL); if (_p) { soap_default_SOAP_ENV__Detail(soap, _p); _p->__any = __any; _p->__type = __type; _p->fault = fault; } return _p; } + +inline void soap_delete_SOAP_ENV__Detail(struct soap *soap, struct SOAP_ENV__Detail *p) { soap_delete(soap, p); } -SOAP_FMAC1 struct SOAP_ENV__Detail * SOAP_FMAC2 soap_instantiate_SOAP_ENV__Detail(struct soap*, int, const char*, const char*, size_t*); SOAP_FMAC3 void SOAP_FMAC4 soap_copy_SOAP_ENV__Detail(struct soap*, int, int, void*, size_t, const void*, size_t); #endif @@ -181,25 +200,28 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_SOAP_ENV__Code(struct soap*, const str SOAP_FMAC3 int SOAP_FMAC4 soap_out_SOAP_ENV__Code(struct soap*, const char*, int, const struct SOAP_ENV__Code *, const char*); SOAP_FMAC3 struct SOAP_ENV__Code * SOAP_FMAC4 soap_in_SOAP_ENV__Code(struct soap*, const char*, struct SOAP_ENV__Code *, const char*); +SOAP_FMAC3 int SOAP_FMAC4 soap_put_SOAP_ENV__Code(struct soap*, const struct SOAP_ENV__Code *, const char*, const char*); + #ifndef soap_write_SOAP_ENV__Code -#define soap_write_SOAP_ENV__Code(soap, data) ( soap_begin_send(soap) || (soap_serialize_SOAP_ENV__Code(soap, data), 0) || soap_put_SOAP_ENV__Code(soap, data, "SOAP-ENV:Code", NULL) || soap_end_send(soap) ) +#define soap_write_SOAP_ENV__Code(soap, data) ( soap_free_temp(soap), soap_begin_send(soap) || (soap_serialize_SOAP_ENV__Code(soap, data),0) || soap_put_SOAP_ENV__Code(soap, data, "SOAP-ENV:Code", NULL) || soap_end_send(soap), (soap)->error ) #endif - -SOAP_FMAC3 int SOAP_FMAC4 soap_put_SOAP_ENV__Code(struct soap*, const struct SOAP_ENV__Code *, const char*, const char*); +SOAP_FMAC3 struct SOAP_ENV__Code * SOAP_FMAC4 soap_get_SOAP_ENV__Code(struct soap*, struct SOAP_ENV__Code *, const char*, const char*); #ifndef soap_read_SOAP_ENV__Code -#define soap_read_SOAP_ENV__Code(soap, data) ( soap_begin_recv(soap) || !soap_get_SOAP_ENV__Code(soap, data, NULL, NULL) || soap_end_recv(soap) ) +#define soap_read_SOAP_ENV__Code(soap, data) ( soap_begin_recv(soap) || !soap_get_SOAP_ENV__Code(soap, data, NULL, NULL) || soap_end_recv(soap), (soap)->error ) #endif -SOAP_FMAC3 struct SOAP_ENV__Code * SOAP_FMAC4 soap_get_SOAP_ENV__Code(struct soap*, struct SOAP_ENV__Code *, const char*, const char*); +SOAP_FMAC1 struct SOAP_ENV__Code * SOAP_FMAC2 soap_instantiate_SOAP_ENV__Code(struct soap*, int, const char*, const char*, size_t*); -#define soap_new_SOAP_ENV__Code(soap, n) soap_instantiate_SOAP_ENV__Code(soap, n, NULL, NULL, NULL) +inline struct SOAP_ENV__Code * soap_new_SOAP_ENV__Code(struct soap *soap, int n = -1) { return soap_instantiate_SOAP_ENV__Code(soap, n, NULL, NULL, NULL); } +inline struct SOAP_ENV__Code * soap_new_req_SOAP_ENV__Code(struct soap *soap) { struct SOAP_ENV__Code *_p = soap_instantiate_SOAP_ENV__Code(soap, -1, NULL, NULL, NULL); if (_p) { soap_default_SOAP_ENV__Code(soap, _p); } return _p; } -#define soap_delete_SOAP_ENV__Code(soap, p) soap_delete(soap, p) +inline struct SOAP_ENV__Code * soap_new_set_SOAP_ENV__Code(struct soap *soap, char *SOAP_ENV__Value, struct SOAP_ENV__Code *SOAP_ENV__Subcode) { struct SOAP_ENV__Code *_p = soap_instantiate_SOAP_ENV__Code(soap, -1, NULL, NULL, NULL); if (_p) { soap_default_SOAP_ENV__Code(soap, _p); _p->SOAP_ENV__Value = SOAP_ENV__Value; _p->SOAP_ENV__Subcode = SOAP_ENV__Subcode; } return _p; } + +inline void soap_delete_SOAP_ENV__Code(struct soap *soap, struct SOAP_ENV__Code *p) { soap_delete(soap, p); } -SOAP_FMAC1 struct SOAP_ENV__Code * SOAP_FMAC2 soap_instantiate_SOAP_ENV__Code(struct soap*, int, const char*, const char*, size_t*); SOAP_FMAC3 void SOAP_FMAC4 soap_copy_SOAP_ENV__Code(struct soap*, int, int, void*, size_t, const void*, size_t); #endif @@ -214,25 +236,28 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_SOAP_ENV__Header(struct soap*, const s SOAP_FMAC3 int SOAP_FMAC4 soap_out_SOAP_ENV__Header(struct soap*, const char*, int, const struct SOAP_ENV__Header *, const char*); SOAP_FMAC3 struct SOAP_ENV__Header * SOAP_FMAC4 soap_in_SOAP_ENV__Header(struct soap*, const char*, struct SOAP_ENV__Header *, const char*); +SOAP_FMAC3 int SOAP_FMAC4 soap_put_SOAP_ENV__Header(struct soap*, const struct SOAP_ENV__Header *, const char*, const char*); + #ifndef soap_write_SOAP_ENV__Header -#define soap_write_SOAP_ENV__Header(soap, data) ( soap_begin_send(soap) || (soap_serialize_SOAP_ENV__Header(soap, data), 0) || soap_put_SOAP_ENV__Header(soap, data, "SOAP-ENV:Header", NULL) || soap_end_send(soap) ) +#define soap_write_SOAP_ENV__Header(soap, data) ( soap_free_temp(soap), soap_begin_send(soap) || (soap_serialize_SOAP_ENV__Header(soap, data),0) || soap_put_SOAP_ENV__Header(soap, data, "SOAP-ENV:Header", NULL) || soap_end_send(soap), (soap)->error ) #endif - -SOAP_FMAC3 int SOAP_FMAC4 soap_put_SOAP_ENV__Header(struct soap*, const struct SOAP_ENV__Header *, const char*, const char*); +SOAP_FMAC3 struct SOAP_ENV__Header * SOAP_FMAC4 soap_get_SOAP_ENV__Header(struct soap*, struct SOAP_ENV__Header *, const char*, const char*); #ifndef soap_read_SOAP_ENV__Header -#define soap_read_SOAP_ENV__Header(soap, data) ( soap_begin_recv(soap) || !soap_get_SOAP_ENV__Header(soap, data, NULL, NULL) || soap_end_recv(soap) ) +#define soap_read_SOAP_ENV__Header(soap, data) ( soap_begin_recv(soap) || !soap_get_SOAP_ENV__Header(soap, data, NULL, NULL) || soap_end_recv(soap), (soap)->error ) #endif -SOAP_FMAC3 struct SOAP_ENV__Header * SOAP_FMAC4 soap_get_SOAP_ENV__Header(struct soap*, struct SOAP_ENV__Header *, const char*, const char*); +SOAP_FMAC1 struct SOAP_ENV__Header * SOAP_FMAC2 soap_instantiate_SOAP_ENV__Header(struct soap*, int, const char*, const char*, size_t*); -#define soap_new_SOAP_ENV__Header(soap, n) soap_instantiate_SOAP_ENV__Header(soap, n, NULL, NULL, NULL) +inline struct SOAP_ENV__Header * soap_new_SOAP_ENV__Header(struct soap *soap, int n = -1) { return soap_instantiate_SOAP_ENV__Header(soap, n, NULL, NULL, NULL); } +inline struct SOAP_ENV__Header * soap_new_req_SOAP_ENV__Header(struct soap *soap) { struct SOAP_ENV__Header *_p = soap_instantiate_SOAP_ENV__Header(soap, -1, NULL, NULL, NULL); if (_p) { soap_default_SOAP_ENV__Header(soap, _p); } return _p; } -#define soap_delete_SOAP_ENV__Header(soap, p) soap_delete(soap, p) +inline struct SOAP_ENV__Header * soap_new_set_SOAP_ENV__Header(struct soap *soap) { struct SOAP_ENV__Header *_p = soap_instantiate_SOAP_ENV__Header(soap, -1, NULL, NULL, NULL); if (_p) { soap_default_SOAP_ENV__Header(soap, _p); } return _p; } + +inline void soap_delete_SOAP_ENV__Header(struct soap *soap, struct SOAP_ENV__Header *p) { soap_delete(soap, p); } -SOAP_FMAC1 struct SOAP_ENV__Header * SOAP_FMAC2 soap_instantiate_SOAP_ENV__Header(struct soap*, int, const char*, const char*, size_t*); SOAP_FMAC3 void SOAP_FMAC4 soap_copy_SOAP_ENV__Header(struct soap*, int, int, void*, size_t, const void*, size_t); #endif @@ -245,25 +270,28 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_ns1__executeCommand(struct soap*, cons SOAP_FMAC3 int SOAP_FMAC4 soap_out_ns1__executeCommand(struct soap*, const char*, int, const struct ns1__executeCommand *, const char*); SOAP_FMAC3 struct ns1__executeCommand * SOAP_FMAC4 soap_in_ns1__executeCommand(struct soap*, const char*, struct ns1__executeCommand *, const char*); +SOAP_FMAC3 int SOAP_FMAC4 soap_put_ns1__executeCommand(struct soap*, const struct ns1__executeCommand *, const char*, const char*); + #ifndef soap_write_ns1__executeCommand -#define soap_write_ns1__executeCommand(soap, data) ( soap_begin_send(soap) || (soap_serialize_ns1__executeCommand(soap, data), 0) || soap_put_ns1__executeCommand(soap, data, "ns1:executeCommand", NULL) || soap_end_send(soap) ) +#define soap_write_ns1__executeCommand(soap, data) ( soap_free_temp(soap), soap_begin_send(soap) || (soap_serialize_ns1__executeCommand(soap, data),0) || soap_put_ns1__executeCommand(soap, data, "ns1:executeCommand", NULL) || soap_end_send(soap), (soap)->error ) #endif - -SOAP_FMAC3 int SOAP_FMAC4 soap_put_ns1__executeCommand(struct soap*, const struct ns1__executeCommand *, const char*, const char*); +SOAP_FMAC3 struct ns1__executeCommand * SOAP_FMAC4 soap_get_ns1__executeCommand(struct soap*, struct ns1__executeCommand *, const char*, const char*); #ifndef soap_read_ns1__executeCommand -#define soap_read_ns1__executeCommand(soap, data) ( soap_begin_recv(soap) || !soap_get_ns1__executeCommand(soap, data, NULL, NULL) || soap_end_recv(soap) ) +#define soap_read_ns1__executeCommand(soap, data) ( soap_begin_recv(soap) || !soap_get_ns1__executeCommand(soap, data, NULL, NULL) || soap_end_recv(soap), (soap)->error ) #endif -SOAP_FMAC3 struct ns1__executeCommand * SOAP_FMAC4 soap_get_ns1__executeCommand(struct soap*, struct ns1__executeCommand *, const char*, const char*); +SOAP_FMAC1 struct ns1__executeCommand * SOAP_FMAC2 soap_instantiate_ns1__executeCommand(struct soap*, int, const char*, const char*, size_t*); -#define soap_new_ns1__executeCommand(soap, n) soap_instantiate_ns1__executeCommand(soap, n, NULL, NULL, NULL) +inline struct ns1__executeCommand * soap_new_ns1__executeCommand(struct soap *soap, int n = -1) { return soap_instantiate_ns1__executeCommand(soap, n, NULL, NULL, NULL); } +inline struct ns1__executeCommand * soap_new_req_ns1__executeCommand(struct soap *soap) { struct ns1__executeCommand *_p = soap_instantiate_ns1__executeCommand(soap, -1, NULL, NULL, NULL); if (_p) { soap_default_ns1__executeCommand(soap, _p); } return _p; } -#define soap_delete_ns1__executeCommand(soap, p) soap_delete(soap, p) +inline struct ns1__executeCommand * soap_new_set_ns1__executeCommand(struct soap *soap, char *command) { struct ns1__executeCommand *_p = soap_instantiate_ns1__executeCommand(soap, -1, NULL, NULL, NULL); if (_p) { soap_default_ns1__executeCommand(soap, _p); _p->command = command; } return _p; } + +inline void soap_delete_ns1__executeCommand(struct soap *soap, struct ns1__executeCommand *p) { soap_delete(soap, p); } -SOAP_FMAC1 struct ns1__executeCommand * SOAP_FMAC2 soap_instantiate_ns1__executeCommand(struct soap*, int, const char*, const char*, size_t*); SOAP_FMAC3 void SOAP_FMAC4 soap_copy_ns1__executeCommand(struct soap*, int, int, void*, size_t, const void*, size_t); #ifndef SOAP_TYPE_ns1__executeCommandResponse @@ -274,25 +302,28 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_ns1__executeCommandResponse(struct soa SOAP_FMAC3 int SOAP_FMAC4 soap_out_ns1__executeCommandResponse(struct soap*, const char*, int, const struct ns1__executeCommandResponse *, const char*); SOAP_FMAC3 struct ns1__executeCommandResponse * SOAP_FMAC4 soap_in_ns1__executeCommandResponse(struct soap*, const char*, struct ns1__executeCommandResponse *, const char*); +SOAP_FMAC3 int SOAP_FMAC4 soap_put_ns1__executeCommandResponse(struct soap*, const struct ns1__executeCommandResponse *, const char*, const char*); + #ifndef soap_write_ns1__executeCommandResponse -#define soap_write_ns1__executeCommandResponse(soap, data) ( soap_begin_send(soap) || (soap_serialize_ns1__executeCommandResponse(soap, data), 0) || soap_put_ns1__executeCommandResponse(soap, data, "ns1:executeCommandResponse", NULL) || soap_end_send(soap) ) +#define soap_write_ns1__executeCommandResponse(soap, data) ( soap_free_temp(soap), soap_begin_send(soap) || (soap_serialize_ns1__executeCommandResponse(soap, data),0) || soap_put_ns1__executeCommandResponse(soap, data, "ns1:executeCommandResponse", NULL) || soap_end_send(soap), (soap)->error ) #endif - -SOAP_FMAC3 int SOAP_FMAC4 soap_put_ns1__executeCommandResponse(struct soap*, const struct ns1__executeCommandResponse *, const char*, const char*); +SOAP_FMAC3 struct ns1__executeCommandResponse * SOAP_FMAC4 soap_get_ns1__executeCommandResponse(struct soap*, struct ns1__executeCommandResponse *, const char*, const char*); #ifndef soap_read_ns1__executeCommandResponse -#define soap_read_ns1__executeCommandResponse(soap, data) ( soap_begin_recv(soap) || !soap_get_ns1__executeCommandResponse(soap, data, NULL, NULL) || soap_end_recv(soap) ) +#define soap_read_ns1__executeCommandResponse(soap, data) ( soap_begin_recv(soap) || !soap_get_ns1__executeCommandResponse(soap, data, NULL, NULL) || soap_end_recv(soap), (soap)->error ) #endif -SOAP_FMAC3 struct ns1__executeCommandResponse * SOAP_FMAC4 soap_get_ns1__executeCommandResponse(struct soap*, struct ns1__executeCommandResponse *, const char*, const char*); +SOAP_FMAC1 struct ns1__executeCommandResponse * SOAP_FMAC2 soap_instantiate_ns1__executeCommandResponse(struct soap*, int, const char*, const char*, size_t*); -#define soap_new_ns1__executeCommandResponse(soap, n) soap_instantiate_ns1__executeCommandResponse(soap, n, NULL, NULL, NULL) +inline struct ns1__executeCommandResponse * soap_new_ns1__executeCommandResponse(struct soap *soap, int n = -1) { return soap_instantiate_ns1__executeCommandResponse(soap, n, NULL, NULL, NULL); } +inline struct ns1__executeCommandResponse * soap_new_req_ns1__executeCommandResponse(struct soap *soap) { struct ns1__executeCommandResponse *_p = soap_instantiate_ns1__executeCommandResponse(soap, -1, NULL, NULL, NULL); if (_p) { soap_default_ns1__executeCommandResponse(soap, _p); } return _p; } -#define soap_delete_ns1__executeCommandResponse(soap, p) soap_delete(soap, p) +inline struct ns1__executeCommandResponse * soap_new_set_ns1__executeCommandResponse(struct soap *soap, char **result) { struct ns1__executeCommandResponse *_p = soap_instantiate_ns1__executeCommandResponse(soap, -1, NULL, NULL, NULL); if (_p) { soap_default_ns1__executeCommandResponse(soap, _p); _p->result = result; } return _p; } + +inline void soap_delete_ns1__executeCommandResponse(struct soap *soap, struct ns1__executeCommandResponse *p) { soap_delete(soap, p); } -SOAP_FMAC1 struct ns1__executeCommandResponse * SOAP_FMAC2 soap_instantiate_ns1__executeCommandResponse(struct soap*, int, const char*, const char*, size_t*); SOAP_FMAC3 void SOAP_FMAC4 soap_copy_ns1__executeCommandResponse(struct soap*, int, int, void*, size_t, const void*, size_t); #ifndef WITH_NOGLOBAL @@ -303,18 +334,18 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_copy_ns1__executeCommandResponse(struct soap*, i SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_PointerToSOAP_ENV__Reason(struct soap*, struct SOAP_ENV__Reason *const*); SOAP_FMAC3 int SOAP_FMAC4 soap_out_PointerToSOAP_ENV__Reason(struct soap*, const char *, int, struct SOAP_ENV__Reason *const*, const char *); SOAP_FMAC3 struct SOAP_ENV__Reason ** SOAP_FMAC4 soap_in_PointerToSOAP_ENV__Reason(struct soap*, const char*, struct SOAP_ENV__Reason **, const char*); +SOAP_FMAC3 int SOAP_FMAC4 soap_put_PointerToSOAP_ENV__Reason(struct soap*, struct SOAP_ENV__Reason *const*, const char*, const char*); #ifndef soap_write_PointerToSOAP_ENV__Reason -#define soap_write_PointerToSOAP_ENV__Reason(soap, data) ( soap_begin_send(soap) || (soap_serialize_PointerToSOAP_ENV__Reason(soap, data), 0) || soap_put_PointerToSOAP_ENV__Reason(soap, data, "SOAP-ENV:Reason", NULL) || soap_end_send(soap) ) +#define soap_write_PointerToSOAP_ENV__Reason(soap, data) ( soap_free_temp(soap), soap_begin_send(soap) || (soap_serialize_PointerToSOAP_ENV__Reason(soap, data),0) || soap_put_PointerToSOAP_ENV__Reason(soap, data, "SOAP-ENV:Reason", NULL) || soap_end_send(soap), (soap)->error ) #endif -SOAP_FMAC3 int SOAP_FMAC4 soap_put_PointerToSOAP_ENV__Reason(struct soap*, struct SOAP_ENV__Reason *const*, const char*, const char*); +SOAP_FMAC3 struct SOAP_ENV__Reason ** SOAP_FMAC4 soap_get_PointerToSOAP_ENV__Reason(struct soap*, struct SOAP_ENV__Reason **, const char*, const char*); #ifndef soap_read_PointerToSOAP_ENV__Reason -#define soap_read_PointerToSOAP_ENV__Reason(soap, data) ( soap_begin_recv(soap) || !soap_get_PointerToSOAP_ENV__Reason(soap, data, NULL, NULL) || soap_end_recv(soap) ) +#define soap_read_PointerToSOAP_ENV__Reason(soap, data) ( soap_begin_recv(soap) || !soap_get_PointerToSOAP_ENV__Reason(soap, data, NULL, NULL) || soap_end_recv(soap), (soap)->error ) #endif -SOAP_FMAC3 struct SOAP_ENV__Reason ** SOAP_FMAC4 soap_get_PointerToSOAP_ENV__Reason(struct soap*, struct SOAP_ENV__Reason **, const char*, const char*); #endif @@ -326,18 +357,18 @@ SOAP_FMAC3 struct SOAP_ENV__Reason ** SOAP_FMAC4 soap_get_PointerToSOAP_ENV__Rea SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_PointerToSOAP_ENV__Detail(struct soap*, struct SOAP_ENV__Detail *const*); SOAP_FMAC3 int SOAP_FMAC4 soap_out_PointerToSOAP_ENV__Detail(struct soap*, const char *, int, struct SOAP_ENV__Detail *const*, const char *); SOAP_FMAC3 struct SOAP_ENV__Detail ** SOAP_FMAC4 soap_in_PointerToSOAP_ENV__Detail(struct soap*, const char*, struct SOAP_ENV__Detail **, const char*); +SOAP_FMAC3 int SOAP_FMAC4 soap_put_PointerToSOAP_ENV__Detail(struct soap*, struct SOAP_ENV__Detail *const*, const char*, const char*); #ifndef soap_write_PointerToSOAP_ENV__Detail -#define soap_write_PointerToSOAP_ENV__Detail(soap, data) ( soap_begin_send(soap) || (soap_serialize_PointerToSOAP_ENV__Detail(soap, data), 0) || soap_put_PointerToSOAP_ENV__Detail(soap, data, "SOAP-ENV:Detail", NULL) || soap_end_send(soap) ) +#define soap_write_PointerToSOAP_ENV__Detail(soap, data) ( soap_free_temp(soap), soap_begin_send(soap) || (soap_serialize_PointerToSOAP_ENV__Detail(soap, data),0) || soap_put_PointerToSOAP_ENV__Detail(soap, data, "SOAP-ENV:Detail", NULL) || soap_end_send(soap), (soap)->error ) #endif -SOAP_FMAC3 int SOAP_FMAC4 soap_put_PointerToSOAP_ENV__Detail(struct soap*, struct SOAP_ENV__Detail *const*, const char*, const char*); +SOAP_FMAC3 struct SOAP_ENV__Detail ** SOAP_FMAC4 soap_get_PointerToSOAP_ENV__Detail(struct soap*, struct SOAP_ENV__Detail **, const char*, const char*); #ifndef soap_read_PointerToSOAP_ENV__Detail -#define soap_read_PointerToSOAP_ENV__Detail(soap, data) ( soap_begin_recv(soap) || !soap_get_PointerToSOAP_ENV__Detail(soap, data, NULL, NULL) || soap_end_recv(soap) ) +#define soap_read_PointerToSOAP_ENV__Detail(soap, data) ( soap_begin_recv(soap) || !soap_get_PointerToSOAP_ENV__Detail(soap, data, NULL, NULL) || soap_end_recv(soap), (soap)->error ) #endif -SOAP_FMAC3 struct SOAP_ENV__Detail ** SOAP_FMAC4 soap_get_PointerToSOAP_ENV__Detail(struct soap*, struct SOAP_ENV__Detail **, const char*, const char*); #endif @@ -349,18 +380,18 @@ SOAP_FMAC3 struct SOAP_ENV__Detail ** SOAP_FMAC4 soap_get_PointerToSOAP_ENV__Det SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_PointerToSOAP_ENV__Code(struct soap*, struct SOAP_ENV__Code *const*); SOAP_FMAC3 int SOAP_FMAC4 soap_out_PointerToSOAP_ENV__Code(struct soap*, const char *, int, struct SOAP_ENV__Code *const*, const char *); SOAP_FMAC3 struct SOAP_ENV__Code ** SOAP_FMAC4 soap_in_PointerToSOAP_ENV__Code(struct soap*, const char*, struct SOAP_ENV__Code **, const char*); +SOAP_FMAC3 int SOAP_FMAC4 soap_put_PointerToSOAP_ENV__Code(struct soap*, struct SOAP_ENV__Code *const*, const char*, const char*); #ifndef soap_write_PointerToSOAP_ENV__Code -#define soap_write_PointerToSOAP_ENV__Code(soap, data) ( soap_begin_send(soap) || (soap_serialize_PointerToSOAP_ENV__Code(soap, data), 0) || soap_put_PointerToSOAP_ENV__Code(soap, data, "SOAP-ENV:Code", NULL) || soap_end_send(soap) ) +#define soap_write_PointerToSOAP_ENV__Code(soap, data) ( soap_free_temp(soap), soap_begin_send(soap) || (soap_serialize_PointerToSOAP_ENV__Code(soap, data),0) || soap_put_PointerToSOAP_ENV__Code(soap, data, "SOAP-ENV:Code", NULL) || soap_end_send(soap), (soap)->error ) #endif -SOAP_FMAC3 int SOAP_FMAC4 soap_put_PointerToSOAP_ENV__Code(struct soap*, struct SOAP_ENV__Code *const*, const char*, const char*); +SOAP_FMAC3 struct SOAP_ENV__Code ** SOAP_FMAC4 soap_get_PointerToSOAP_ENV__Code(struct soap*, struct SOAP_ENV__Code **, const char*, const char*); #ifndef soap_read_PointerToSOAP_ENV__Code -#define soap_read_PointerToSOAP_ENV__Code(soap, data) ( soap_begin_recv(soap) || !soap_get_PointerToSOAP_ENV__Code(soap, data, NULL, NULL) || soap_end_recv(soap) ) +#define soap_read_PointerToSOAP_ENV__Code(soap, data) ( soap_begin_recv(soap) || !soap_get_PointerToSOAP_ENV__Code(soap, data, NULL, NULL) || soap_end_recv(soap), (soap)->error ) #endif -SOAP_FMAC3 struct SOAP_ENV__Code ** SOAP_FMAC4 soap_get_PointerToSOAP_ENV__Code(struct soap*, struct SOAP_ENV__Code **, const char*, const char*); #endif @@ -370,18 +401,18 @@ SOAP_FMAC3 struct SOAP_ENV__Code ** SOAP_FMAC4 soap_get_PointerToSOAP_ENV__Code( SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_PointerTostring(struct soap*, char **const*); SOAP_FMAC3 int SOAP_FMAC4 soap_out_PointerTostring(struct soap*, const char *, int, char **const*, const char *); SOAP_FMAC3 char *** SOAP_FMAC4 soap_in_PointerTostring(struct soap*, const char*, char ***, const char*); +SOAP_FMAC3 int SOAP_FMAC4 soap_put_PointerTostring(struct soap*, char **const*, const char*, const char*); #ifndef soap_write_PointerTostring -#define soap_write_PointerTostring(soap, data) ( soap_begin_send(soap) || (soap_serialize_PointerTostring(soap, data), 0) || soap_put_PointerTostring(soap, data, "byte", NULL) || soap_end_send(soap) ) +#define soap_write_PointerTostring(soap, data) ( soap_free_temp(soap), soap_begin_send(soap) || (soap_serialize_PointerTostring(soap, data),0) || soap_put_PointerTostring(soap, data, "byte", NULL) || soap_end_send(soap), (soap)->error ) #endif -SOAP_FMAC3 int SOAP_FMAC4 soap_put_PointerTostring(struct soap*, char **const*, const char*, const char*); +SOAP_FMAC3 char *** SOAP_FMAC4 soap_get_PointerTostring(struct soap*, char ***, const char*, const char*); #ifndef soap_read_PointerTostring -#define soap_read_PointerTostring(soap, data) ( soap_begin_recv(soap) || !soap_get_PointerTostring(soap, data, NULL, NULL) || soap_end_recv(soap) ) +#define soap_read_PointerTostring(soap, data) ( soap_begin_recv(soap) || !soap_get_PointerTostring(soap, data, NULL, NULL) || soap_end_recv(soap), (soap)->error ) #endif -SOAP_FMAC3 char *** SOAP_FMAC4 soap_get_PointerTostring(struct soap*, char ***, const char*, const char*); #ifndef SOAP_TYPE__QName #define SOAP_TYPE__QName (5) @@ -389,23 +420,21 @@ SOAP_FMAC3 char *** SOAP_FMAC4 soap_get_PointerTostring(struct soap*, char ***, #define soap_default__QName(soap, a) soap_default_string(soap, a) - -#define soap_serialize__QName(soap, a) soap_serialize_string(soap, a) - +SOAP_FMAC3 void SOAP_FMAC4 soap_serialize__QName(struct soap*, char *const*); SOAP_FMAC3 int SOAP_FMAC4 soap_out__QName(struct soap*, const char*, int, char*const*, const char*); SOAP_FMAC3 char * * SOAP_FMAC4 soap_in__QName(struct soap*, const char*, char **, const char*); +SOAP_FMAC3 int SOAP_FMAC4 soap_put__QName(struct soap*, char *const*, const char*, const char*); #ifndef soap_write__QName -#define soap_write__QName(soap, data) ( soap_begin_send(soap) || (soap_serialize__QName(soap, data), 0) || soap_put__QName(soap, data, "byte", NULL) || soap_end_send(soap) ) +#define soap_write__QName(soap, data) ( soap_free_temp(soap), soap_begin_send(soap) || (soap_serialize__QName(soap, data),0) || soap_put__QName(soap, data, "byte", NULL) || soap_end_send(soap), (soap)->error ) #endif -SOAP_FMAC3 int SOAP_FMAC4 soap_put__QName(struct soap*, char *const*, const char*, const char*); +SOAP_FMAC3 char ** SOAP_FMAC4 soap_get__QName(struct soap*, char **, const char*, const char*); #ifndef soap_read__QName -#define soap_read__QName(soap, data) ( soap_begin_recv(soap) || !soap_get__QName(soap, data, NULL, NULL) || soap_end_recv(soap) ) +#define soap_read__QName(soap, data) ( soap_begin_recv(soap) || !soap_get__QName(soap, data, NULL, NULL) || soap_end_recv(soap), (soap)->error ) #endif -SOAP_FMAC3 char ** SOAP_FMAC4 soap_get__QName(struct soap*, char **, const char*, const char*); #ifndef SOAP_TYPE_string #define SOAP_TYPE_string (4) @@ -414,18 +443,18 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_default_string(struct soap*, char **); SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_string(struct soap*, char *const*); SOAP_FMAC3 int SOAP_FMAC4 soap_out_string(struct soap*, const char*, int, char*const*, const char*); SOAP_FMAC3 char * * SOAP_FMAC4 soap_in_string(struct soap*, const char*, char **, const char*); +SOAP_FMAC3 int SOAP_FMAC4 soap_put_string(struct soap*, char *const*, const char*, const char*); #ifndef soap_write_string -#define soap_write_string(soap, data) ( soap_begin_send(soap) || (soap_serialize_string(soap, data), 0) || soap_put_string(soap, data, "byte", NULL) || soap_end_send(soap) ) +#define soap_write_string(soap, data) ( soap_free_temp(soap), soap_begin_send(soap) || (soap_serialize_string(soap, data),0) || soap_put_string(soap, data, "byte", NULL) || soap_end_send(soap), (soap)->error ) #endif -SOAP_FMAC3 int SOAP_FMAC4 soap_put_string(struct soap*, char *const*, const char*, const char*); +SOAP_FMAC3 char ** SOAP_FMAC4 soap_get_string(struct soap*, char **, const char*, const char*); #ifndef soap_read_string -#define soap_read_string(soap, data) ( soap_begin_recv(soap) || !soap_get_string(soap, data, NULL, NULL) || soap_end_recv(soap) ) +#define soap_read_string(soap, data) ( soap_begin_recv(soap) || !soap_get_string(soap, data, NULL, NULL) || soap_end_recv(soap), (soap)->error ) #endif -SOAP_FMAC3 char ** SOAP_FMAC4 soap_get_string(struct soap*, char **, const char*, const char*); #endif diff --git a/dep/gsoap/soapServer.cpp b/dep/gsoap/soapServer.cpp index b6304a3e525..6e5c8040165 100644 --- a/dep/gsoap/soapServer.cpp +++ b/dep/gsoap/soapServer.cpp @@ -1,9 +1,9 @@ /* soapServer.cpp - Generated by gSOAP 2.8.10 from gsoap.stub + Generated by gSOAP 2.8.17r from gsoap.stub -Copyright(C) 2000-2012, Robert van Engelen, Genivia Inc. All Rights Reserved. +Copyright(C) 2000-2013, Robert van Engelen, Genivia Inc. All Rights Reserved. The generated code is released under one of the following licenses: -1) GPL or 2) Genivia's license for commercial use. +GPL or Genivia's license for commercial use. This program is released under the GPL with the additional exemption that compiling, linking, and/or using OpenSSL is allowed. */ @@ -14,10 +14,10 @@ compiling, linking, and/or using OpenSSL is allowed. #endif #include "soapH.h" -SOAP_SOURCE_STAMP("@(#) soapServer.cpp ver 2.8.10 2012-09-02 20:48:00 GMT") +SOAP_SOURCE_STAMP("@(#) soapServer.cpp ver 2.8.17r 2014-06-21 21:43:17 GMT") -SOAP_FMAC5 int SOAP_FMAC6 soap_serve(struct soap *soap) +extern "C" SOAP_FMAC5 int SOAP_FMAC6 soap_serve(struct soap *soap) { #ifndef WITH_FASTCGI unsigned int k = soap->max_keep_alive; @@ -53,7 +53,7 @@ SOAP_FMAC5 int SOAP_FMAC6 soap_serve(struct soap *soap) } #ifndef WITH_NOSERVEREQUEST -SOAP_FMAC5 int SOAP_FMAC6 soap_serve_request(struct soap *soap) +extern "C" SOAP_FMAC5 int SOAP_FMAC6 soap_serve_request(struct soap *soap) { soap_peek_element(soap); if (!soap_match_tag(soap, soap->tag, "ns1:executeCommand")) @@ -70,7 +70,6 @@ SOAP_FMAC5 int SOAP_FMAC6 soap_serve_ns1__executeCommand(struct soap *soap) soap_tmp_string = NULL; soap_tmp_ns1__executeCommandResponse.result = &soap_tmp_string; soap_default_ns1__executeCommand(soap, &soap_tmp_ns1__executeCommand); - soap->encodingStyle = NULL; if (!soap_get_ns1__executeCommand(soap, &soap_tmp_ns1__executeCommand, "ns1:executeCommand", NULL)) return soap->error; if (soap_body_end_in(soap) @@ -80,6 +79,7 @@ SOAP_FMAC5 int SOAP_FMAC6 soap_serve_ns1__executeCommand(struct soap *soap) soap->error = ns1__executeCommand(soap, soap_tmp_ns1__executeCommand.command, soap_tmp_ns1__executeCommandResponse.result); if (soap->error) return soap->error; + soap->encodingStyle = NULL; soap_serializeheader(soap); soap_serialize_ns1__executeCommandResponse(soap, &soap_tmp_ns1__executeCommandResponse); if (soap_begin_count(soap)) diff --git a/dep/gsoap/soapStub.h b/dep/gsoap/soapStub.h index fbdd170e0f4..38374561cde 100644 --- a/dep/gsoap/soapStub.h +++ b/dep/gsoap/soapStub.h @@ -1,9 +1,9 @@ /* soapStub.h - Generated by gSOAP 2.8.10 from gsoap.stub + Generated by gSOAP 2.8.17r from gsoap.stub -Copyright(C) 2000-2012, Robert van Engelen, Genivia Inc. All Rights Reserved. +Copyright(C) 2000-2013, Robert van Engelen, Genivia Inc. All Rights Reserved. The generated code is released under one of the following licenses: -1) GPL or 2) Genivia's license for commercial use. +GPL or Genivia's license for commercial use. This program is released under the GPL with the additional exemption that compiling, linking, and/or using OpenSSL is allowed. */ @@ -11,7 +11,7 @@ compiling, linking, and/or using OpenSSL is allowed. #ifndef soapStub_H #define soapStub_H #include "stdsoap2.h" -#if GSOAP_VERSION != 20810 +#if GSOAP_VERSION != 20817 # error "GSOAP VERSION MISMATCH IN GENERATED CODE: PLEASE REINSTALL PACKAGE" #endif @@ -48,6 +48,8 @@ struct ns1__executeCommandResponse { public: char **result; /* SOAP 1.2 RPC return element (when namespace qualified) */ /* optional element of type xsd:string */ +public: + int soap_type() const { return 9; } /* = unique type id SOAP_TYPE_ns1__executeCommandResponse */ }; #endif @@ -58,6 +60,8 @@ struct ns1__executeCommand { public: char *command; /* optional element of type xsd:string */ +public: + int soap_type() const { return 10; } /* = unique type id SOAP_TYPE_ns1__executeCommand */ }; #endif @@ -68,6 +72,8 @@ public: /* SOAP Header: */ struct SOAP_ENV__Header { +public: + int soap_type() const { return 11; } /* = unique type id SOAP_TYPE_SOAP_ENV__Header */ #ifdef WITH_NOEMPTYSTRUCT private: char dummy; /* dummy member to enable compilation */ @@ -87,6 +93,8 @@ struct SOAP_ENV__Code public: char *SOAP_ENV__Value; /* optional element of type xsd:QName */ struct SOAP_ENV__Code *SOAP_ENV__Subcode; /* optional element of type SOAP-ENV:Code */ +public: + int soap_type() const { return 12; } /* = unique type id SOAP_TYPE_SOAP_ENV__Code */ }; #endif @@ -103,6 +111,8 @@ public: char *__any; int __type; /* any type of element <fault> (defined below) */ void *fault; /* transient */ +public: + int soap_type() const { return 14; } /* = unique type id SOAP_TYPE_SOAP_ENV__Detail */ }; #endif @@ -117,6 +127,8 @@ struct SOAP_ENV__Reason { public: char *SOAP_ENV__Text; /* optional element of type xsd:string */ +public: + int soap_type() const { return 17; } /* = unique type id SOAP_TYPE_SOAP_ENV__Reason */ }; #endif @@ -139,6 +151,8 @@ public: char *SOAP_ENV__Node; /* optional element of type xsd:string */ char *SOAP_ENV__Role; /* optional element of type xsd:string */ struct SOAP_ENV__Detail *SOAP_ENV__Detail; /* optional element of type SOAP-ENV:Detail */ +public: + int soap_type() const { return 18; } /* = unique type id SOAP_TYPE_SOAP_ENV__Fault */ }; #endif @@ -183,9 +197,9 @@ SOAP_FMAC5 int SOAP_FMAC6 ns1__executeCommand(struct soap*, char *command, char * * \******************************************************************************/ -SOAP_FMAC5 int SOAP_FMAC6 soap_serve(struct soap*); +extern "C" SOAP_FMAC5 int SOAP_FMAC6 soap_serve(struct soap*); -SOAP_FMAC5 int SOAP_FMAC6 soap_serve_request(struct soap*); +extern "C" SOAP_FMAC5 int SOAP_FMAC6 soap_serve_request(struct soap*); SOAP_FMAC5 int SOAP_FMAC6 soap_serve_ns1__executeCommand(struct soap*); diff --git a/dep/gsoap/stdsoap2.cpp b/dep/gsoap/stdsoap2.cpp index 36a8901dcab..6186f8904e3 100644 --- a/dep/gsoap/stdsoap2.cpp +++ b/dep/gsoap/stdsoap2.cpp @@ -1,10 +1,10 @@ /* - stdsoap2.c[pp] 2.8.10 + stdsoap2.c[pp] 2.8.17r gSOAP runtime engine gSOAP XML Web services tools -Copyright (C) 2000-2012, Robert van Engelen, Genivia Inc., All Rights Reserved. +Copyright (C) 2000-2013, Robert van Engelen, Genivia Inc., All Rights Reserved. This part of the software is released under ONE of the following licenses: GPL, or the gSOAP public license, or Genivia's license for commercial use. -------------------------------------------------------------------------------- @@ -24,7 +24,7 @@ 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-2012, Robert van Engelen, Genivia Inc., All Rights Reserved. +Copyright (C) 2000-2013, Robert van Engelen, Genivia Inc., All Rights Reserved. -------------------------------------------------------------------------------- GPL license. @@ -51,13 +51,16 @@ A commercial use license is available from Genivia, Inc., contact@genivia.com -------------------------------------------------------------------------------- */ -#define GSOAP_LIB_VERSION 20810 +#define GSOAP_LIB_VERSION 20817 #ifdef AS400 # pragma convert(819) /* EBCDIC to ASCII */ #endif #include "stdsoap2.h" +#if defined(VXWORKS) && defined(WM_SECURE_KEY_STORAGE) +#include <ipcom_key_db.h> +#endif #if GSOAP_VERSION != GSOAP_LIB_VERSION # error "GSOAP VERSION MISMATCH IN LIBRARY: PLEASE REINSTALL PACKAGE" #endif @@ -76,10 +79,10 @@ A commercial use license is available from Genivia, Inc., contact@genivia.com #endif #ifdef __cplusplus -SOAP_SOURCE_STAMP("@(#) stdsoap2.cpp ver 2.8.10 2012-08-16 00:00:00 GMT") +SOAP_SOURCE_STAMP("@(#) stdsoap2.cpp ver 2.8.17r 2013-12-18 00:00:00 GMT") extern "C" { #else -SOAP_SOURCE_STAMP("@(#) stdsoap2.c ver 2.8.10 2012-08-16 00:00:00 GMT") +SOAP_SOURCE_STAMP("@(#) stdsoap2.c ver 2.8.17r 2013-12-18 00:00:00 GMT") #endif /* 8bit character representing unknown/nonrepresentable character data (e.g. not supported by current locale with multibyte support enabled) */ @@ -570,7 +573,7 @@ fsend(struct soap *soap, const char *s, size_t n) err = soap->errnum; if (!err) return soap->error; - if (err != SOAP_EINTR && err != SOAP_EAGAIN && err != SOAP_EWOULDBLOCK) + if (err != SOAP_EAGAIN && err != SOAP_EWOULDBLOCK) return SOAP_EOF; } } @@ -614,6 +617,14 @@ fsend(struct soap *soap, const char *s, size_t n) } while (nwritten < 0 && --udp_repeat > 0); } + if (nwritten < 0) + { err = soap_socket_errno(sk); + if (err && err != SOAP_EINTR) + { soap->errnum = err; + return SOAP_EOF; + } + nwritten = 0; /* and call write() again */ + } } else #endif @@ -654,7 +665,7 @@ fsend(struct soap *soap, const char *s, size_t n) r = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->send_timeout ? soap->send_timeout : -10000); if (!r && soap->send_timeout) return SOAP_EOF; - if (r < 0 && soap->errnum != SOAP_EINTR) + if (r < 0) return SOAP_EOF; } else if (err && err != SOAP_EINTR) @@ -809,13 +820,18 @@ soap_flush_raw(struct soap *soap, const char *s, size_t n) #ifndef WITH_LEANER if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK) { char t[16]; - sprintf(t, "\r\n%lX\r\n" + (soap->chunksize ? 0 : 2), (unsigned long)n); +#ifdef HAVE_SNPRINTF + soap_snprintf(t, sizeof(t), &"\r\n%lX\r\n"[soap->chunksize ? 0 : 2], (unsigned long)n); +#else + sprintf(t, &"\r\n%lX\r\n"[soap->chunksize ? 0 : 2], (unsigned long)n); +#endif DBGMSG(SENT, t, strlen(t)); if ((soap->error = soap->fsend(soap, t, strlen(t)))) 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, soap->socket, soap->sendfd)); #endif return soap->error = soap->fsend(soap, s, n); } @@ -899,7 +915,7 @@ frecv(struct soap *soap, char *s, size_t n) if (!r) return 0; r = soap->errnum; - if (r != SOAP_EINTR && r != SOAP_EAGAIN && r != SOAP_EWOULDBLOCK) + if (r != SOAP_EAGAIN && r != SOAP_EWOULDBLOCK) return 0; } } @@ -955,11 +971,11 @@ frecv(struct soap *soap, char *s, size_t n) } #if defined(WITH_OPENSSL) if (soap->ssl && err == SSL_ERROR_WANT_WRITE) - r = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->recv_timeout ? soap->recv_timeout : 5); + r = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->recv_timeout ? soap->recv_timeout : 5); else #elif defined(WITH_GNUTLS) if (soap->session && gnutls_record_get_direction(soap->session)) - r = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->recv_timeout ? soap->recv_timeout : 5); + r = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->recv_timeout ? soap->recv_timeout : 5); else #endif r = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, soap->recv_timeout ? soap->recv_timeout : 5); @@ -967,7 +983,7 @@ frecv(struct soap *soap, char *s, size_t n) return 0; if (r < 0) { r = soap->errnum; - if (r != SOAP_EINTR && r != SOAP_EAGAIN && r != SOAP_EWOULDBLOCK) + if (r != SOAP_EAGAIN && r != SOAP_EWOULDBLOCK) return 0; } if (retries-- <= 0) @@ -1108,12 +1124,12 @@ zlib_again: t = tmp; if (!soap->chunkbuflen) { soap->chunkbuflen = ret = soap->frecv(soap, soap->buf, SOAP_BUFLEN); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes (chunked) from socket %d\n", (unsigned int)ret, soap->socket)); + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes (chunked) from socket=%d\n", (unsigned int)ret, soap->socket)); DBGMSG(RECV, soap->buf, ret); soap->bufidx = 0; if (!ret) { soap->ahead = EOF; - return EOF; + return EOF; } } else @@ -1123,7 +1139,7 @@ zlib_again: while (!soap_isxdigit((int)(c = soap_getchunkchar(soap)))) { if ((int)c == EOF) { soap->ahead = EOF; - return EOF; + return EOF; } } do @@ -1217,6 +1233,7 @@ zlib_again: return soap->error = r; #endif soap->count += ret; + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read count=%lu (+%lu)\n", (unsigned long)soap->count, (unsigned long)ret)); return !ret; } #endif @@ -1637,9 +1654,9 @@ soap_get_pi(struct soap *soap) SOAP_FMAC1 int SOAP_FMAC2 -soap_move(struct soap *soap, long n) -{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Moving %ld bytes forward\n", (long)n)); - for (; n > 0; n--) +soap_move(struct soap *soap, size_t n) +{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Moving %lu bytes forward\n", (unsigned long)n)); + for (; n; n--) if ((int)soap_getchar(soap) == EOF) return SOAP_EOF; return SOAP_OK; @@ -1697,8 +1714,12 @@ soap_pututf8(struct soap *soap, register unsigned long c) *t++ = (char)(0x80 | (c & 0x3F)); *t = '\0'; } + else +#endif +#ifdef HAVE_SNPRINTF + soap_snprintf(tmp, sizeof(tmp), "&#%lu;", c); #else - sprintf(tmp, "&#%lu;", c); + sprintf(tmp, "&#%lu;", c); #endif return soap_send(soap, tmp); } @@ -1712,7 +1733,7 @@ SOAP_FMAC2 soap_getutf8(struct soap *soap) { register soap_wchar c, c1, c2, c3, c4; c = soap->ahead; - if (c) + if (c >= 0x80) soap->ahead = 0; else c = soap_get(soap); @@ -1930,8 +1951,8 @@ soap_getbase64(struct soap *soap, int *n, int malloc_flag) register int j = 0; do { register soap_wchar c = soap_get(soap); - if (c < SOAP_AP) - c &= 0x7FFFFFFF; + if (c < SOAP_AP) + c &= 0x7FFFFFFF; if (c == '=' || c < 0) { unsigned char *p; switch (j) @@ -2527,27 +2548,70 @@ SOAP_FMAC1 char * SOAP_FMAC2 soap_putsizesoffsets(struct soap *soap, const char *type, const int *size, const int *offset, int dim) -{ int i; - if (!type) +{ register int i; + register size_t l; + if (!type || strlen(type) + 13 > sizeof(soap->type)) /* prevent overruns */ return NULL; if (soap->version == 2) - { sprintf(soap->type, "%s[%d", type, size[0]); + { +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->type, sizeof(soap->type) - 1, "%s[%d", type, size[0]); +#else + sprintf(soap->type, "%s[%d", type, size[0]); +#endif for (i = 1; i < dim; i++) - sprintf(soap->type + strlen(soap->type), " %d", size[i]); + { +#ifdef HAVE_SNPRINTF + l = strlen(soap->type); + soap_snprintf(soap->type + l, sizeof(soap->type) - l - 1, " %d", size[i]); +#else + if ((l = strlen(soap->type)) + 13 > sizeof(soap->type)) + return NULL; + sprintf(soap->type + l, " %d", size[i]); +#endif + } } else { if (offset) - { sprintf(soap->type, "%s[%d", type, size[0] + offset[0]); + { +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->type, sizeof(soap->type) - 1, "%s[%d", type, size[0] + offset[0]); +#else + sprintf(soap->type, "%s[%d", type, size[0] + offset[0]); +#endif for (i = 1; i < dim; i++) - sprintf(soap->type + strlen(soap->type), ",%d", size[i] + offset[i]); + { +#ifdef HAVE_SNPRINTF + l = strlen(soap->type); + soap_snprintf(soap->type + l, sizeof(soap->type) - l - 1, ",%d", size[i] + offset[i]); +#else + if ((l = strlen(soap->type)) + 13 > sizeof(soap->type)) + return NULL; + sprintf(soap->type + l, ",%d", size[i] + offset[i]); +#endif + } } else - { sprintf(soap->type, "%s[%d", type, size[0]); + { +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->type, sizeof(soap->type) - 1, "%s[%d", type, size[0]); +#else + sprintf(soap->type, "%s[%d", type, size[0]); +#endif for (i = 1; i < dim; i++) - sprintf(soap->type + strlen(soap->type), ",%d", size[i]); + { +#ifdef HAVE_SNPRINTF + l = strlen(soap->type); + soap_snprintf(soap->type + l, sizeof(soap->type) - l - 1, ",%d", size[i]); +#else + if ((l = strlen(soap->type)) + 13 > sizeof(soap->type)) + return NULL; + sprintf(soap->type + l, ",%d", size[i]); +#endif + } } - strcat(soap->type, "]"); } + strcat(soap->type, "]"); return soap->type; } #endif @@ -2569,9 +2633,25 @@ char * SOAP_FMAC2 soap_putoffsets(struct soap *soap, const int *offset, int dim) { register int i; + register size_t l; +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->arrayOffset, sizeof(soap->arrayOffset) - 1, "[%d", offset[0]); +#else + if (sizeof(soap->arrayOffset) < 13) /* prevent overruns */ + return NULL; sprintf(soap->arrayOffset, "[%d", offset[0]); +#endif for (i = 1; i < dim; i++) - sprintf(soap->arrayOffset + strlen(soap->arrayOffset), ",%d", offset[i]); + { +#ifdef HAVE_SNPRINTF + l = strlen(soap->arrayOffset); + soap_snprintf(soap->arrayOffset + l, sizeof(soap->arrayOffset) - l - 1, ",%d", offset[i]); +#else + if ((l = strlen(soap->arrayOffset)) + 13 > sizeof(soap->arrayOffset)) + return NULL; + sprintf(soap->arrayOffset + l, ",%d", offset[i]); +#endif + } strcat(soap->arrayOffset, "]"); return soap->arrayOffset; } @@ -2901,6 +2981,11 @@ soap_match_tag(struct soap *soap, const char *tag1, const char *tag2) return err; } } + else if (!t[1]) + { err = soap_match_namespace(soap, tag1, tag2, 0, t - tag2); + if (err == SOAP_NAMESPACE) + return SOAP_TAG_MISMATCH; + } else if (SOAP_STRCMP(tag1, t + 1)) { return SOAP_TAG_MISMATCH; } @@ -2970,9 +3055,16 @@ soap_rand() SOAP_FMAC1 int SOAP_FMAC2 +#if defined(VXWORKS) && defined(WM_SECURE_KEY_STORAGE) +soap_ssl_server_context(struct soap *soap, unsigned short flags, const char *keyfile, const char *keyid, const char *password, const char *cafile, const char *capath, const char *dhfile, const char *randfile, const char *sid) +#else soap_ssl_server_context(struct soap *soap, unsigned short flags, const char *keyfile, const char *password, const char *cafile, const char *capath, const char *dhfile, const char *randfile, const char *sid) +#endif { int err; soap->keyfile = keyfile; +#if defined(VXWORKS) && defined(WM_SECURE_KEY_STORAGE) + soap->keyid = keyid; +#endif soap->password = password; soap->cafile = cafile; soap->capath = capath; @@ -3038,8 +3130,15 @@ soap_ssl_server_context(struct soap *soap, unsigned short flags, const char *key SOAP_FMAC1 int SOAP_FMAC2 +#if defined(VXWORKS) && defined(WM_SECURE_KEY_STORAGE) +soap_ssl_client_context(struct soap *soap, unsigned short flags, const char *keyfile, const char *keyid, const char *password, const char *cafile, const char *capath, const char *randfile) +#else soap_ssl_client_context(struct soap *soap, unsigned short flags, const char *keyfile, const char *password, const char *cafile, const char *capath, const char *randfile) +#endif { soap->keyfile = keyfile; +#if defined(VXWORKS) && defined(WM_SECURE_KEY_STORAGE) + soap->keyid = keyid; +#endif soap->password = password; soap->cafile = cafile; soap->capath = capath; @@ -3130,13 +3229,16 @@ soap_ssl_error(struct soap *soap, int ret) else { switch (ret) { case 0: - strcpy(soap->msgbuf, "EOF was observed that violates the protocol. The client probably provided invalid authentication information."); + strcpy(soap->msgbuf, "EOF was observed that violates the SSL/TLS protocol. The client probably provided invalid authentication information."); break; case -1: #ifdef HAVE_SNPRINTF - soap_snprintf(soap->msgbuf, sizeof(soap->msgbuf), "Error observed by underlying BIO: %s", strerror(errno)); + soap_snprintf(soap->msgbuf, sizeof(soap->msgbuf), "Error observed by underlying SSL/TLS BIO: %s", strerror(errno)); #else - sprintf(soap->msgbuf, "Error observed by underlying BIO: %s", strerror(errno)); + { const char *s = strerror(errno); + size_t l = strlen(s); + sprintf(soap->msgbuf, "Error observed by underlying SSL/TLS BIO: %s", l + 44 < sizeof(soap->msgbuf) ? s : SOAP_STR_EOS); + } #endif break; } @@ -3159,6 +3261,9 @@ ssl_auth_init(struct soap *soap) #ifdef WITH_OPENSSL long flags; int mode; +#if defined(VXWORKS) && defined(WM_SECURE_KEY_STORAGE) + EVP_PKEY* pkey; +#endif if (!soap_ssl_init_done) soap_ssl_init(); ERR_clear_error(); @@ -3194,7 +3299,17 @@ ssl_auth_init(struct soap *soap) } if (!SSL_CTX_use_PrivateKey_file(soap->ctx, soap->keyfile, SSL_FILETYPE_PEM)) return soap_set_receiver_error(soap, "SSL/TLS error", "Can't read key file", SOAP_SSL_ERROR); +#ifndef WM_SECURE_KEY_STORAGE + if (!SSL_CTX_use_PrivateKey_file(soap->ctx, soap->keyfile, SSL_FILETYPE_PEM)) + return soap_set_receiver_error(soap, "SSL/TLS error", "Can't read key file", SOAP_SSL_ERROR); +#endif } +#if defined(VXWORKS) && defined(WM_SECURE_KEY_STORAGE) + if (NULL == (pkey = ipcom_key_db_pkey_get(soap->keyid))) + return soap_set_receiver_error(soap, "SSL error", "Can't find key", SOAP_SSL_ERROR); + if (0 == SSL_CTX_use_PrivateKey(soap->ctx, pkey)) + return soap_set_receiver_error(soap, "SSL error", "Can't read key", SOAP_SSL_ERROR); +#endif /* Suggested alternative approach to check the key file for certs (cafile=NULL):*/ #if 0 if (soap->password) @@ -3225,7 +3340,11 @@ ssl_auth_init(struct soap *soap) int n = (int)soap_strtoul(soap->dhfile, &s, 10); /* if dhfile is numeric, treat it as a key length to generate DH params which can take a while */ if (n >= 512 && s && *s == '\0') +#if defined(VXWORKS) + DH_generate_parameters_ex(dh, n, 2/*or 5*/, NULL); +#else dh = DH_generate_parameters(n, 2/*or 5*/, NULL, NULL); +#endif else { BIO *bio; bio = BIO_new_file(soap->dhfile, "r"); @@ -3478,7 +3597,7 @@ soap_ssl_accept(struct soap *soap) s = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, -100000); else s = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, -100000); - if (s < 0 && soap->errnum != SOAP_EINTR) + if (s < 0) break; } else @@ -3533,7 +3652,7 @@ soap_ssl_accept(struct soap *soap) s = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, -100000); else s = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, -100000); - if (s < 0 && soap->errnum != SOAP_EINTR) + if (s < 0) break; } else @@ -3611,7 +3730,12 @@ tcp_error(struct soap *soap) msg = soap_code_str(h_error_codes, soap->errnum); if (!msg) #endif - { sprintf(soap->msgbuf, "TCP/UDP IP error %d", soap->errnum); + { +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->msgbuf, sizeof(soap->msgbuf), "TCP/UDP IP error %d", soap->errnum); +#else + sprintf(soap->msgbuf, "TCP/UDP IP error %d", soap->errnum); +#endif msg = soap->msgbuf; } } @@ -3647,7 +3771,7 @@ tcp_gethost(struct soap *soap, const char *addr, struct in_addr *inaddr) { memcpy(inaddr, &iadd, sizeof(iadd)); return SOAP_OK; } -#if defined(__GLIBC__) || (defined(HAVE_GETHOSTBYNAME_R) && (defined(FREEBSD) || defined(__FreeBSD__))) +#if defined(__GLIBC__) || (defined(HAVE_GETHOSTBYNAME_R) && (defined(FREEBSD) || defined(__FreeBSD__))) || defined(__ANDROID__) if (gethostbyname_r(addr, &hostent, soap->buf, SOAP_BUFLEN, &host, &soap->errnum) < 0) host = NULL; #elif defined(_AIX43) || ((defined(TRU64) || defined(HP_UX)) && defined(HAVE_GETHOSTBYNAME_R)) @@ -3915,7 +4039,7 @@ again: } #endif #endif - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Opening socket %d to host='%s' port=%d\n", sk, host, port)); + DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Opening socket=%d to host='%s' port=%d\n", sk, host, port)); #ifndef WITH_IPV6 soap->peerlen = sizeof(soap->peer); memset((void*)&soap->peer, 0, sizeof(soap->peer)); @@ -3988,7 +4112,7 @@ again: #endif return SOAP_INVALID_SOCKET; } - r = soap->errnum; + r = soap->errnum = soap_socket_errno(sk); if (r != SOAP_EINTR) { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n")); soap_set_sender_error(soap, tcp_error(soap), "connect failed in tcp_connect()", SOAP_TCP_ERROR); @@ -4057,7 +4181,7 @@ again: short keep_alive = soap->keep_alive; /* save the KA status */ soap->omode &= ~SOAP_ENC; /* mask IO and ENC */ soap->omode |= SOAP_IO_BUFFER; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connecting to %s proxy server\n", soap->proxy_http_version)); + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connecting to %s proxy server %s for destination endpoint %s\n", soap->proxy_http_version, soap->proxy_host, endpoint)); #ifdef WITH_NTLM if (soap->ntlm_challenge) { if (soap_ntlm_handshake(soap, SOAP_CONNECT, endpoint, host, port)) @@ -4071,7 +4195,7 @@ again: soap->status = SOAP_CONNECT; soap->keep_alive = 1; if ((soap->error = soap->fpost(soap, endpoint, host, port, NULL, NULL, 0)) - || soap_end_send(soap)) + || soap_end_send_flush(soap)) { soap->fclosesocket(soap, sk); return SOAP_INVALID_SOCKET; } @@ -4095,7 +4219,9 @@ again: return SOAP_INVALID_SOCKET; } if (endpoint) - strncpy(soap->endpoint, endpoint, sizeof(soap->endpoint)-1); /* restore */ + { strncpy(soap->endpoint, endpoint, sizeof(soap->endpoint)); /* restore */ + soap->endpoint[sizeof(soap->endpoint) - 1] = '\0'; + } soap->mode = m; } #ifdef WITH_OPENSSL @@ -4146,7 +4272,7 @@ again: s = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, -100000); else s = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, -100000); - if (s < 0 && soap->errnum != SOAP_EINTR) + if (s < 0) { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "SSL_connect/select error in tcp_connect\n")); soap_set_sender_error(soap, soap_ssl_error(soap, r), "SSL_connect failed in tcp_connect()", SOAP_TCP_ERROR); soap->fclosesocket(soap, sk); @@ -4178,15 +4304,20 @@ again: } if (!(soap->ssl_flags & SOAP_SSL_SKIP_HOST_CHECK)) { X509_NAME *subj; + STACK_OF(CONF_VALUE) *val = NULL; +#if (OPENSSL_VERSION_NUMBER >= 0x0090800fL) + GENERAL_NAMES *names = NULL; +#else int ext_count; +#endif int ok = 0; - X509 *peer; - peer = SSL_get_peer_certificate(soap->ssl); + X509 *peer = SSL_get_peer_certificate(soap->ssl); if (!peer) { soap_set_sender_error(soap, "SSL/TLS error", "No SSL/TLS certificate was presented by the peer in tcp_connect()", SOAP_SSL_ERROR); soap->fclosesocket(soap, sk); return SOAP_INVALID_SOCKET; } +#if (OPENSSL_VERSION_NUMBER < 0x0090800fL) ext_count = X509_get_ext_count(peer); if (ext_count > 0) { int i; @@ -4195,36 +4326,42 @@ again: const char *ext_str = OBJ_nid2sn(OBJ_obj2nid(X509_EXTENSION_get_object(ext))); if (ext_str && !strcmp(ext_str, "subjectAltName")) { X509V3_EXT_METHOD *meth = (X509V3_EXT_METHOD*)X509V3_EXT_get(ext); - void *ext_data; -#if (OPENSSL_VERSION_NUMBER >= 0x0090800fL) - const unsigned char *data; -#else unsigned char *data; -#endif - STACK_OF(CONF_VALUE) *val; - int j; if (!meth) break; data = ext->value->data; + if (data) + { #if (OPENSSL_VERSION_NUMBER > 0x00907000L) - if (meth->it) - ext_data = ASN1_item_d2i(NULL, &data, ext->value->length, ASN1_ITEM_ptr(meth->it)); - else - { /* OpenSSL not perfectly portable at this point (?): - Some compilers appear to prefer - meth->d2i(NULL, (const unsigned char**)&data, ... - and others prefer - meth->d2i(NULL, &data, ext->value->length); - */ - ext_data = meth->d2i(NULL, &data, ext->value->length); - } + void *ext_data; + if (meth->it) + ext_data = ASN1_item_d2i(NULL, &data, ext->value->length, ASN1_ITEM_ptr(meth->it)); + else + { /* OpenSSL is not portable at this point (?): + Some compilers appear to prefer + meth->d2i(NULL, (const unsigned char**)&data, ... + and others prefer + meth->d2i(NULL, &data, ext->value->length); + */ + ext_data = meth->d2i(NULL, &data, ext->value->length); + } + if (ext_data) + val = meth->i2v(meth, ext_data, NULL); + else + val = NULL; + if (meth->it) + ASN1_item_free((ASN1_VALUE*)ext_data, ASN1_ITEM_ptr(meth->it)); + else + meth->ext_free(ext_data); #else - ext_data = meth->d2i(NULL, &data, ext->value->length); + void *ext_data = meth->d2i(NULL, &data, ext->value->length); + if (ext_data) + val = meth->i2v(meth, ext_data, NULL); + meth->ext_free(ext_data); #endif - if (ext_data) - { val = meth->i2v(meth, ext_data, NULL); if (val) - { for (j = 0; j < sk_CONF_VALUE_num(val); j++) + { int j; + for (j = 0; j < sk_CONF_VALUE_num(val); j++) { CONF_VALUE *nval = sk_CONF_VALUE_value(val, j); if (nval && !strcmp(nval->name, "DNS") && !strcmp(nval->value, host)) { ok = 1; @@ -4233,20 +4370,30 @@ again: } sk_CONF_VALUE_pop_free(val, X509V3_conf_free); } -#if (OPENSSL_VERSION_NUMBER > 0x00907000L) - if (meth->it) - ASN1_item_free((ASN1_VALUE*)ext_data, ASN1_ITEM_ptr(meth->it)); - else - meth->ext_free(ext_data); -#else - meth->ext_free(ext_data); -#endif } } if (ok) break; } } +#else + names = (GENERAL_NAMES*)X509_get_ext_d2i(peer, NID_subject_alt_name, NULL, NULL); + if (names) + { val = i2v_GENERAL_NAMES(NULL, names, val); + sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free); + } + if (val) + { int j; + for (j = 0; j < sk_CONF_VALUE_num(val); j++) + { CONF_VALUE *nval = sk_CONF_VALUE_value(val, j); + if (nval && !strcmp(nval->name, "DNS") && !strcmp(nval->value, host)) + { ok = 1; + break; + } + } + sk_CONF_VALUE_pop_free(val, X509V3_conf_free); + } +#endif if (!ok && (subj = X509_get_subject_name(peer))) { int i = -1; do @@ -4310,7 +4457,7 @@ again: s = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, -100000); else s = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, -100000); - if (s < 0 && soap->errnum != SOAP_EINTR) + if (s < 0) break; } else @@ -4352,9 +4499,11 @@ again: #ifndef PALM_1 static int tcp_select(struct soap *soap, SOAP_SOCKET sk, int flags, int timeout) -{ register int r; +{ int r; struct timeval tv; fd_set fd[3], *rfd, *sfd, *efd; + int retries = 0; + int eintr = SOAP_MAXEINTR; soap->errnum = 0; #ifndef WIN32 #if !defined(FD_SETSIZE) || defined(__QNX__) || defined(QNX) @@ -4366,7 +4515,6 @@ tcp_select(struct soap *soap, SOAP_SOCKET sk, int flags, int timeout) #endif #ifdef HAVE_POLL { struct pollfd pollfd; - int retries = 0; pollfd.fd = (int)sk; pollfd.events = 0; if (flags & SOAP_TCP_SELECT_RCV) @@ -4375,16 +4523,17 @@ tcp_select(struct soap *soap, SOAP_SOCKET sk, int flags, int timeout) pollfd.events |= POLLOUT; if (flags & SOAP_TCP_SELECT_ERR) pollfd.events |= POLLERR; - if (timeout < 0) + if (timeout <= 0) timeout /= -1000; /* -usec -> ms */ - else if (timeout <= 1000000) /* avoid overflow */ - timeout *= 1000; /* sec -> ms */ else - { retries = timeout / 1000000; - timeout = 1000000000; + { retries = timeout - 1; + timeout = 1000; } - do r = poll(&pollfd, 1, timeout); - while (r == 0 && retries--); + do + { r = poll(&pollfd, 1, timeout); + if (r < 0 && (soap->errnum = soap_socket_errno(sk)) == SOAP_EINTR && eintr--) + continue; + } while (r == 0 && retries--); if (r > 0) { r = 0; if ((flags & SOAP_TCP_SELECT_RCV) && (pollfd.revents & POLLIN)) @@ -4394,8 +4543,6 @@ tcp_select(struct soap *soap, SOAP_SOCKET sk, int flags, int timeout) if ((flags & SOAP_TCP_SELECT_ERR) && (pollfd.revents & POLLERR)) r |= SOAP_TCP_SELECT_ERR; } - else if (r < 0) - soap->errnum = soap_socket_errno(s); return r; } #else @@ -4404,31 +4551,37 @@ tcp_select(struct soap *soap, SOAP_SOCKET sk, int flags, int timeout) } #endif #endif - rfd = sfd = efd = NULL; - if (flags & SOAP_TCP_SELECT_RCV) - { rfd = &fd[0]; - FD_ZERO(rfd); - FD_SET(sk, rfd); - } - if (flags & SOAP_TCP_SELECT_SND) - { sfd = &fd[1]; - FD_ZERO(sfd); - FD_SET(sk, sfd); - } - if (flags & SOAP_TCP_SELECT_ERR) - { efd = &fd[2]; - FD_ZERO(efd); - FD_SET(sk, efd); - } - if (timeout >= 0) - { tv.tv_sec = timeout; - tv.tv_usec = 0; - } - else - { tv.tv_sec = -timeout / 1000000; - tv.tv_usec = -timeout % 1000000; - } - r = select((int)sk + 1, rfd, sfd, efd, &tv); + if (timeout > 0) + retries = timeout - 1; + do + { rfd = sfd = efd = NULL; + if (flags & SOAP_TCP_SELECT_RCV) + { rfd = &fd[0]; + FD_ZERO(rfd); + FD_SET(sk, rfd); + } + if (flags & SOAP_TCP_SELECT_SND) + { sfd = &fd[1]; + FD_ZERO(sfd); + FD_SET(sk, sfd); + } + if (flags & SOAP_TCP_SELECT_ERR) + { efd = &fd[2]; + FD_ZERO(efd); + FD_SET(sk, efd); + } + if (timeout <= 0) + { tv.tv_sec = -timeout / 1000000; + tv.tv_usec = -timeout % 1000000; + } + else + { tv.tv_sec = 1; + tv.tv_usec = 0; + } + r = select((int)sk + 1, rfd, sfd, efd, &tv); + if (r < 0 && (soap->errnum = soap_socket_errno(sk)) == SOAP_EINTR && eintr--) + continue; + } while (r == 0 && retries--); if (r > 0) { r = 0; if ((flags & SOAP_TCP_SELECT_RCV) && FD_ISSET(sk, rfd)) @@ -4438,8 +4591,6 @@ tcp_select(struct soap *soap, SOAP_SOCKET sk, int flags, int timeout) if ((flags & SOAP_TCP_SELECT_ERR) && FD_ISSET(sk, efd)) r |= SOAP_TCP_SELECT_ERR; } - else if (r < 0) - soap->errnum = soap_socket_errno(s); return r; } #endif @@ -4509,7 +4660,7 @@ tcp_disconnect(struct soap *soap) timeout) */ r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, 5); - if (r <= 0 && soap->errnum != SOAP_EINTR) + if (r <= 0) { soap->errnum = 0; DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connection lost...\n")); soap->fclosesocket(soap, soap->socket); @@ -4565,7 +4716,7 @@ tcp_disconnect(struct soap *soap) static int tcp_closesocket(struct soap *soap, SOAP_SOCKET sk) { (void)soap; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Close socket %d\n", (int)sk)); + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Close socket=%d\n", (int)sk)); return soap_closesocket(sk); } #endif @@ -4577,7 +4728,7 @@ tcp_closesocket(struct soap *soap, SOAP_SOCKET sk) static int tcp_shutdownsocket(struct soap *soap, SOAP_SOCKET sk, int how) { (void)soap; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Shutdown socket %d how=%d\n", (int)sk, how)); + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Shutdown socket=%d how=%d\n", (int)sk, how)); return shutdown(sk, how); } #endif @@ -4788,11 +4939,13 @@ soap_poll(struct soap *soap) } else #endif + { int t; if (soap_valid_socket(soap->socket) && (r & SOAP_TCP_SELECT_SND) && (!(r & SOAP_TCP_SELECT_RCV) - || recv(soap->socket, soap->tmpbuf, 1, MSG_PEEK) > 0)) + || recv(soap->socket, (char*)&t, 1, MSG_PEEK) > 0)) return SOAP_OK; + } } else if (r < 0) { if ((soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) && soap_socket_errno(soap->master) != SOAP_EINTR) @@ -4878,10 +5031,14 @@ soap_accept(struct soap *soap) soap->port = soap_strtol(port, NULL, 10); #else soap->ip = ntohl(soap->peer.sin_addr.s_addr); +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->host, sizeof(soap->host), "%u.%u.%u.%u", (int)(soap->ip>>24)&0xFF, (int)(soap->ip>>16)&0xFF, (int)(soap->ip>>8)&0xFF, (int)soap->ip&0xFF); +#else sprintf(soap->host, "%u.%u.%u.%u", (int)(soap->ip>>24)&0xFF, (int)(soap->ip>>16)&0xFF, (int)(soap->ip>>8)&0xFF, (int)soap->ip&0xFF); +#endif soap->port = (int)ntohs(soap->peer.sin_port); /* does not return port number on some systems */ #endif - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Accept socket %d at port %d from IP %s\n", soap->socket, soap->port, soap->host)); + DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Accept socket=%d at port=%d from IP='%s'\n", soap->socket, soap->port, soap->host)); #ifndef WITH_LEAN if (soap->accept_flags == SO_LINGER) { struct linger linger; @@ -4971,17 +5128,20 @@ soap_closesock(struct soap *soap) soap->keep_alive = 0; } #ifdef WITH_ZLIB - if (soap->zlib_state == SOAP_ZLIB_DEFLATE) - deflateEnd(soap->d_stream); - else if (soap->zlib_state == SOAP_ZLIB_INFLATE) - inflateEnd(soap->d_stream); - soap->zlib_state = SOAP_ZLIB_NONE; + if (!(soap->mode & SOAP_MIME_POSTCHECK)) + { if (soap->zlib_state == SOAP_ZLIB_DEFLATE) + deflateEnd(soap->d_stream); + else if (soap->zlib_state == SOAP_ZLIB_INFLATE) + inflateEnd(soap->d_stream); + soap->zlib_state = SOAP_ZLIB_NONE; + } #endif return soap->error = status; } #endif /******************************************************************************/ +#ifndef WITH_NOIO #ifndef PALM_1 SOAP_FMAC1 int @@ -4993,6 +5153,7 @@ soap_force_closesock(struct soap *soap) return SOAP_OK; } #endif +#endif /******************************************************************************/ #ifndef WITH_NOIO @@ -5024,7 +5185,7 @@ soap_done(struct soap *soap) #endif if (soap_check_state(soap)) return; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Done with context\n")); + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Done with context%s\n", soap->state == SOAP_COPY ? " copy" : "")); soap_free_temp(soap); while (soap->clist) { struct soap_clist *p = soap->clist->next; @@ -5034,6 +5195,8 @@ soap_done(struct soap *soap) if (soap->state == SOAP_INIT) soap->omode &= ~SOAP_IO_UDP; /* to force close the socket */ soap->keep_alive = 0; /* to force close the socket */ + if (soap->master == soap->socket) /* do not close twice */ + soap->master = SOAP_INVALID_SOCKET; soap_closesock(soap); #ifdef WITH_COOKIES soap_free_cookies(soap); @@ -5194,14 +5357,13 @@ soap_done(struct soap *soap) /******************************************************************************/ #ifndef WITH_NOHTTP #ifndef PALM_1 -int +static int http_parse(struct soap *soap) { char header[SOAP_HDRLEN], *s; unsigned short httpcmd = 0; int status = 0; DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Waiting for HTTP request/response...\n")); *soap->endpoint = '\0'; - soap->length = 0; #ifdef WITH_NTLM if (!soap->ntlm_challenge) #endif @@ -5213,11 +5375,13 @@ http_parse(struct soap *soap) soap->ntlm_challenge = NULL; #endif soap->proxy_from = NULL; - soap->http_content = NULL; - soap->action = NULL; - soap->status = 0; do - { if (soap_getline(soap, soap->msgbuf, sizeof(soap->msgbuf))) + { soap->length = 0; + soap->http_content = NULL; + soap->action = NULL; + soap->status = 0; + soap->body = 1; + if (soap_getline(soap, soap->msgbuf, sizeof(soap->msgbuf))) { if (soap->error == SOAP_EOF) return SOAP_EOF; return soap->error = 414; @@ -5271,9 +5435,7 @@ http_parse(struct soap *soap) { if (soap->keep_alive == 1) soap->keep_alive = 0; if (soap->status == 0 && (soap->omode & SOAP_IO) == SOAP_IO_CHUNK) /* soap->status == 0 for HTTP request */ - { soap->imode |= SOAP_IO_CHUNK; - soap->omode = (soap->omode & ~SOAP_IO) | SOAP_IO_STORE; - } + soap->omode = (soap->omode & ~SOAP_IO) | SOAP_IO_STORE; /* HTTP 1.0 does not support chunked transfers */ } if (soap->keep_alive < 0) soap->keep_alive = 1; @@ -5297,12 +5459,16 @@ http_parse(struct soap *soap) if (s && httpcmd) { size_t m = strlen(soap->endpoint); size_t n = m + (s - soap->msgbuf) - l - 1; - if (m > n) - m = n; + size_t k; if (n >= sizeof(soap->endpoint)) n = sizeof(soap->endpoint) - 1; - strncpy(soap->path, soap->msgbuf + l, n - m); - soap->path[n - m] = '\0'; + if (m > n) + m = n; + k = n - m + 1; + if (k > sizeof(soap->path)) + k = sizeof(soap->path); + strncpy(soap->path, soap->msgbuf + l, k); + soap->path[k - 1] = '\0'; if (*soap->path && *soap->path != '/') *soap->endpoint = '\0'; strcat(soap->endpoint, soap->path); @@ -5329,28 +5495,27 @@ http_parse(struct soap *soap) return soap->error = status; else if (s) return soap->error = 405; - } - /* Status OK (HTTP 200) */ - if (soap->status == 0 || soap->status == 200) return SOAP_OK; - /* Status 201 (Created), 202 (Accepted), ... and HTTP 400 and 500 errors - may not have a body. When content length, content type, or chunking is - used assume there is a message to parse, either XML or HTTP. - */ + } +#if 0 if (soap->length > 0 || (soap->http_content && (!soap->keep_alive || soap->recv_timeout)) || (soap->imode & SOAP_IO) == SOAP_IO_CHUNK) - { if ((soap->status > 200 && soap->status <= 299) - || soap->status == 400 - || soap->status == 500) +#endif + if (soap->body) + { if ((soap->status >= 200 && soap->status <= 299) /* OK, Accepted, etc */ + || soap->status == 400 /* Bad Request */ + || soap->status == 500) /* Internal Server Error */ return SOAP_OK; /* force close afterwards in soap_closesock() */ soap->keep_alive = 0; #ifndef WITH_LEAN /* read HTTP body for error details */ - s = soap_get_http_body(soap); + s = soap_get_http_body(soap, NULL); if (s) return soap_set_receiver_error(soap, soap->msgbuf, s, soap->status); #endif } + else if (soap->status >= 200 && soap->status <= 299) + return soap->error = soap->status; DBGLOG(TEST,SOAP_MESSAGE(fdebug, "HTTP error %d\n", soap->status)); return soap_set_receiver_error(soap, "HTTP Error", soap->msgbuf, soap->status); } @@ -5371,7 +5536,6 @@ http_parse_header(struct soap *soap, const char *key, const char *val) #endif strcpy(soap->endpoint, "http://"); strncat(soap->endpoint, val, sizeof(soap->endpoint) - 8); - soap->endpoint[sizeof(soap->endpoint) - 1] = '\0'; } #ifndef WITH_LEANER else if (!soap_tag_cmp(key, "Content-Type")) @@ -5389,7 +5553,8 @@ http_parse_header(struct soap *soap, const char *key, const char *val) if (action) { if (*action == '"') { soap->action = soap_strdup(soap, action + 1); - soap->action[strlen(soap->action) - 1] = '\0'; + if (*soap->action) + soap->action[strlen(soap->action) - 1] = '\0'; } else soap->action = soap_strdup(soap, action); @@ -5398,6 +5563,8 @@ http_parse_header(struct soap *soap, const char *key, const char *val) #endif else if (!soap_tag_cmp(key, "Content-Length")) { soap->length = soap_strtoul(val, NULL, 10); + if (!soap->length) + soap->body = 0; } else if (!soap_tag_cmp(key, "Content-Encoding")) { if (!soap_tag_cmp(val, "deflate")) @@ -5439,8 +5606,14 @@ http_parse_header(struct soap *soap, const char *key, const char *val) soap->keep_alive = 0; } #ifndef WITH_LEAN - else if (!soap_tag_cmp(key, "Authorization")) - { if (!soap_tag_cmp(val, "Basic *")) + else if (!soap_tag_cmp(key, "Authorization") || !soap_tag_cmp(key, "Proxy-Authorization")) + { +#ifdef WITH_NTLM + if (!soap_tag_cmp(val, "NTLM*")) + soap->ntlm_challenge = soap_strdup(soap, val + 4); + else +#endif + if (!soap_tag_cmp(val, "Basic *")) { int n; char *s; soap_base642s(soap, val + 6, soap->tmpbuf, sizeof(soap->tmpbuf) - 1, &n); @@ -5472,7 +5645,8 @@ http_parse_header(struct soap *soap, const char *key, const char *val) else if (!soap_tag_cmp(key, "SOAPAction")) { if (*val == '"') { soap->action = soap_strdup(soap, val + 1); - soap->action[strlen(soap->action) - 1] = '\0'; + if (*soap->action) + soap->action[strlen(soap->action) - 1] = '\0'; } else soap->action = soap_strdup(soap, val); @@ -5555,24 +5729,28 @@ static const char* soap_decode(char *buf, size_t len, const char *val, const char *sep) { const char *s; char *t = buf; + size_t i = len; for (s = val; *s; s++) if (*s != ' ' && *s != '\t' && !strchr(sep, *s)) break; - if (*s == '"') - { s++; - while (*s && *s != '"' && --len) - *t++ = *s++; - } - else - { while (*s && !soap_blank((soap_wchar)*s) && !strchr(sep, *s) && --len) - { if (*s == '%') - { *t++ = ((s[1] >= 'A' ? (s[1] & 0x7) + 9 : s[1] - '0') << 4) - + (s[2] >= 'A' ? (s[2] & 0x7) + 9 : s[2] - '0'); - s += 3; - } - else + if (len > 0) + { if (*s == '"') + { s++; + while (*s && *s != '"' && --i) *t++ = *s++; } + else + { while (*s && !soap_blank((soap_wchar)*s) && !strchr(sep, *s) && --i) + { if (*s == '%' && s[1] && s[2]) + { *t++ = ((s[1] >= 'A' ? (s[1] & 0x7) + 9 : s[1] - '0') << 4) + + (s[2] >= 'A' ? (s[2] & 0x7) + 9 : s[2] - '0'); + s += 3; + } + else + *t++ = *s++; + } + } + buf[len - 1] = '\0'; /* appease */ } *t = '\0'; while (*s && !strchr(sep, *s)) @@ -5617,8 +5795,8 @@ http_get(struct soap *soap) #ifndef PALM_1 static int http_405(struct soap *soap) -{ return 405; - (void)soap; +{ (void)soap; + return 405; } #endif #endif @@ -5663,14 +5841,33 @@ http_post(struct soap *soap, const char *endpoint, const char *host, int port, c if (!endpoint || (soap_tag_cmp(endpoint, "http:*") && soap_tag_cmp(endpoint, "https:*") && strncmp(endpoint, "httpg:", 6))) #endif return SOAP_OK; - if (strlen(endpoint) + strlen(soap->http_version) > sizeof(soap->tmpbuf) - 80) - return soap->error = SOAP_EOM; /* prevent overrun */ + if (strlen(endpoint) + strlen(soap->http_version) > sizeof(soap->tmpbuf) - 80 + || strlen(host) + strlen(soap->http_version) > sizeof(soap->tmpbuf) - 80) + return soap->error = SOAP_EOM; /* prevent overrun (note that 'host' and 'soap->host' are substrings of 'endpoint') */ if (soap->status == SOAP_CONNECT) + { +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "%s %s:%d HTTP/%s", s, soap->host, soap->port, soap->http_version); +#else sprintf(soap->tmpbuf, "%s %s:%d HTTP/%s", s, soap->host, soap->port, soap->http_version); +#endif + } else if (soap->proxy_host && endpoint) + { +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "%s %s HTTP/%s", s, endpoint, soap->http_version); +#else sprintf(soap->tmpbuf, "%s %s HTTP/%s", s, endpoint, soap->http_version); +#endif + } else + { +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "%s /%s HTTP/%s", s, (*path == '/' ? path + 1 : path), soap->http_version); +#else sprintf(soap->tmpbuf, "%s /%s HTTP/%s", s, (*path == '/' ? path + 1 : path), soap->http_version); +#endif + } if ((err = soap->fposthdr(soap, soap->tmpbuf, NULL))) return err; #ifdef WITH_OPENSSL @@ -5681,13 +5878,38 @@ http_post(struct soap *soap, const char *endpoint, const char *host, int port, c { #ifdef WITH_IPV6 if (*host != '[' && strchr(host, ':')) + { +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "[%s]:%d", host, port); /* RFC 2732 */ +#else sprintf(soap->tmpbuf, "[%s]:%d", host, port); /* RFC 2732 */ +#endif + } else #endif + { +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "%s:%d", host, port); +#else sprintf(soap->tmpbuf, "%s:%d", host, port); +#endif + } } else - strcpy(soap->tmpbuf, host); + { +#ifdef WITH_IPV6 + if (*host != '[' && strchr(host, ':')) + { +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "[%s]", host); /* RFC 2732 */ +#else + sprintf(soap->tmpbuf, "[%s]", host); /* RFC 2732 */ +#endif + } + else +#endif + strcpy(soap->tmpbuf, host); + } if ((err = soap->fposthdr(soap, "Host", soap->tmpbuf))) return err; if ((err = soap->fposthdr(soap, "User-Agent", "gSOAP/2.8"))) @@ -5703,34 +5925,51 @@ http_post(struct soap *soap, const char *endpoint, const char *host, int port, c return err; #endif #ifndef WITH_LEAN - if (soap->userid && soap->passwd && strlen(soap->userid) + strlen(soap->passwd) < 761) - { #ifdef WITH_NTLM - if (soap->ntlm_challenge && strlen(soap->ntlm_challenge) + 6 < sizeof(soap->tmpbuf)) + if (soap->ntlm_challenge && strlen(soap->ntlm_challenge) + 6 < sizeof(soap->tmpbuf)) + { if (*soap->ntlm_challenge) + { +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "NTLM %s", soap->ntlm_challenge); +#else sprintf(soap->tmpbuf, "NTLM %s", soap->ntlm_challenge); - else #endif - { strcpy(soap->tmpbuf, "Basic "); - sprintf(soap->tmpbuf + 262, "%s:%s", soap->userid, soap->passwd); - soap_s2base64(soap, (const unsigned char*)(soap->tmpbuf + 262), soap->tmpbuf + 6, (int)strlen(soap->tmpbuf + 262)); + if (soap->proxy_host) + { if ((err = soap->fposthdr(soap, "Proxy-Authorization", soap->tmpbuf))) + return err; + } + else if ((err = soap->fposthdr(soap, "Authorization", soap->tmpbuf))) + return err; } + } + else + { +#endif + if (soap->userid && soap->passwd && strlen(soap->userid) + strlen(soap->passwd) < 761) + { strcpy(soap->tmpbuf, "Basic "); +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf + 262, sizeof(soap->tmpbuf) - 262, "%s:%s", soap->userid, soap->passwd); +#else + sprintf(soap->tmpbuf + 262, "%s:%s", soap->userid, soap->passwd); +#endif + soap_s2base64(soap, (const unsigned char*)(soap->tmpbuf + 262), soap->tmpbuf + 6, (int)strlen(soap->tmpbuf + 262)); if ((err = soap->fposthdr(soap, "Authorization", soap->tmpbuf))) return err; } if (soap->proxy_userid && soap->proxy_passwd && strlen(soap->proxy_userid) + strlen(soap->proxy_passwd) < 761) - { -#ifdef WITH_NTLM - if (soap->ntlm_challenge && strlen(soap->ntlm_challenge) + 6 < sizeof(soap->tmpbuf)) - sprintf(soap->tmpbuf, "NTLM %s", soap->ntlm_challenge); - else + { strcpy(soap->tmpbuf, "Basic "); +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf + 262, sizeof(soap->tmpbuf) - 262, "%s:%s", soap->proxy_userid, soap->proxy_passwd); +#else + sprintf(soap->tmpbuf + 262, "%s:%s", soap->proxy_userid, soap->proxy_passwd); #endif - { strcpy(soap->tmpbuf, "Basic "); - sprintf(soap->tmpbuf + 262, "%s:%s", soap->proxy_userid, soap->proxy_passwd); - soap_s2base64(soap, (const unsigned char*)(soap->tmpbuf + 262), soap->tmpbuf + 6, (int)strlen(soap->tmpbuf + 262)); - } + soap_s2base64(soap, (const unsigned char*)(soap->tmpbuf + 262), soap->tmpbuf + 6, (int)strlen(soap->tmpbuf + 262)); if ((err = soap->fposthdr(soap, "Proxy-Authorization", soap->tmpbuf))) return err; } +#ifdef WITH_NTLM + } +#endif #endif #ifdef WITH_COOKIES #ifdef WITH_OPENSSL @@ -5742,7 +5981,12 @@ http_post(struct soap *soap, const char *endpoint, const char *host, int port, c #endif #endif if (action && soap->status != SOAP_GET && soap->status != SOAP_DEL) - { sprintf(soap->tmpbuf, "\"%s\"", action && strlen(action) < sizeof(soap->tmpbuf) - 3 ? action : SOAP_STR_EOS); + { +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "\"%s\"", action); +#else + sprintf(soap->tmpbuf, "\"%s\"", strlen(action) < sizeof(soap->tmpbuf) - 3 ? action : SOAP_STR_EOS); +#endif if ((err = soap->fposthdr(soap, "SOAPAction", soap->tmpbuf))) return err; } @@ -5792,68 +6036,69 @@ http_post_header(struct soap *soap, const char *key, const char *val) static int http_response(struct soap *soap, int status, size_t count) { register int err; + char http[10]; + int code = status; + const char *line; #ifdef WMW_RPM_IO if (soap->rpmreqid) httpOutputEnable(soap->rpmreqid); #endif - if (strlen(soap->http_version) > 4) + if (!soap->http_version || strlen(soap->http_version) > 4) return soap->error = SOAP_EOM; - if (!status || status == SOAP_HTML || status == SOAP_FILE) - { const char *s; - if (count || ((soap->omode & SOAP_IO) == SOAP_IO_CHUNK)) - s = "200 OK"; - else - s = "202 Accepted"; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Status = %s\n", s)); #ifdef WMW_RPM_IO - if (soap->rpmreqid || soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* RPM behaves as if standalone */ + if (soap->rpmreqid || soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* RPM behaves as if standalone */ #else - if (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* standalone application (socket) or CGI (stdin/out)? */ + if (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* standalone application (socket) or CGI (stdin/out)? */ #endif - { sprintf(soap->tmpbuf, "HTTP/%s %s", soap->http_version, s); - if ((err = soap->fposthdr(soap, soap->tmpbuf, NULL))) - return err; - } - else if ((err = soap->fposthdr(soap, "Status", s))) /* CGI header */ - return err; - } - else if (status >= 200 && status < 600) - { sprintf(soap->tmpbuf, "HTTP/%s %d %s", soap->http_version, status, http_error(soap, status)); - if ((err = soap->fposthdr(soap, soap->tmpbuf, NULL))) - return err; -#ifndef WITH_LEAN - if (status == 401) - { sprintf(soap->tmpbuf, "Basic realm=\"%s\"", (soap->authrealm && strlen(soap->authrealm) < sizeof(soap->tmpbuf) - 14) ? soap->authrealm : "gSOAP Web Service"); - if ((err = soap->fposthdr(soap, "WWW-Authenticate", soap->tmpbuf))) - return err; - } - else if ((status >= 301 && status <= 303) || status == 307) - { if ((err = soap->fposthdr(soap, "Location", soap->endpoint))) - return err; - } + { +#ifdef HAVE_SNPRINTF + soap_snprintf(http, sizeof(http), "HTTP/%s", soap->http_version); +#else + sprintf(http, "HTTP/%s", soap->http_version); #endif } else + strcpy(http, "Status:"); + if (!status || status == SOAP_HTML || status == SOAP_FILE) + { if (count || ((soap->omode & SOAP_IO) == SOAP_IO_CHUNK)) + code = 200; + else + code = 202; + } + else if (status < 200 || status >= 600) { const char *s = *soap_faultcode(soap); if (status >= SOAP_GET_METHOD && status <= SOAP_HTTP_METHOD) - s = "405 Method Not Allowed"; + code = 405; else if (soap->version == 2 && (!s || !strcmp(s, "SOAP-ENV:Sender"))) - s = "400 Bad Request"; + code = 400; else - s = "500 Internal Server Error"; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error %s (status=%d)\n", s, status)); -#ifdef WMW_RPM_IO - if (soap->rpmreqid || soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* RPM behaves as if standalone */ + code = 500; + } + line = http_error(soap, code); + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "HTTP Status = %d %s\n", code, line)); +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "%s %d %s", http, code, line); #else - if (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* standalone application */ + sprintf(soap->tmpbuf, "%s %d %s", http, code, line); #endif - { sprintf(soap->tmpbuf, "HTTP/%s %s", soap->http_version, s); - if ((err = soap->fposthdr(soap, soap->tmpbuf, NULL))) - return err; - } - else if ((err = soap->fposthdr(soap, "Status", s))) /* CGI */ + if ((err = soap->fposthdr(soap, soap->tmpbuf, NULL))) + return err; +#ifndef WITH_LEAN + if (status == 401) + { +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "Basic realm=\"%s\"", (soap->authrealm && strlen(soap->authrealm) < sizeof(soap->tmpbuf) - 14) ? soap->authrealm : "gSOAP Web Service"); +#else + sprintf(soap->tmpbuf, "Basic realm=\"%s\"", (soap->authrealm && strlen(soap->authrealm) < sizeof(soap->tmpbuf) - 14) ? soap->authrealm : "gSOAP Web Service"); +#endif + if ((err = soap->fposthdr(soap, "WWW-Authenticate", soap->tmpbuf))) + return err; + } + else if ((status >= 301 && status <= 303) || status == 307) + { if ((err = soap->fposthdr(soap, "Location", soap->endpoint))) return err; } +#endif if ((err = soap->fposthdr(soap, "Server", "gSOAP/2.8")) || (err = soap_puthttphdr(soap, status, count))) return err; @@ -5901,18 +6146,26 @@ soap_response(struct soap *soap, int status) } #endif -/******************************************************************************\ - * - * HTTP Cookies - * -\******************************************************************************/ +/******************************************************************************/ +#ifndef PALM_1 +SOAP_FMAC1 +const char* +SOAP_FMAC2 +soap_url(struct soap *soap, const char *s, const char *t) +{ if (!t || (*t != '/' && *t != '?') || strlen(s) + strlen(t) >= sizeof(soap->msgbuf)) + return s; + strcpy(soap->msgbuf, s); + strcat(soap->msgbuf, t); + return soap->msgbuf; +} +#endif -#ifdef WITH_COOKIES /******************************************************************************/ +#ifndef PALM_1 SOAP_FMAC1 size_t SOAP_FMAC2 -soap_encode_cookie(const char *s, char *t, size_t len) +soap_encode_url(const char *s, char *t, size_t len) { register int c; register size_t n = len; while ((c = *s++) && --n > 0) @@ -5931,8 +6184,34 @@ soap_encode_cookie(const char *s, char *t, size_t len) *t = '\0'; return len - n; } +#endif /******************************************************************************/ +#ifndef PALM_1 +SOAP_FMAC1 +const char* +SOAP_FMAC2 +soap_encode_url_string(struct soap *soap, const char *s) +{ if (s) + { size_t n = 3*strlen(s)+1; + char *t = (char*)soap_malloc(soap, n); + if (t) + { soap_encode_url(s, t, n); + return t; + } + } + return SOAP_STR_EOS; +} +#endif + +/******************************************************************************\ + * + * HTTP Cookies + * +\******************************************************************************/ + +#ifdef WITH_COOKIES +/******************************************************************************/ SOAP_FMAC1 struct soap_cookie* SOAP_FMAC2 @@ -5946,9 +6225,9 @@ soap_cookie(struct soap *soap, const char *name, const char *domain, const char path = SOAP_STR_EOS; else if (*path == '/') path++; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Search cookie %s domain=%s path=%s\n", name, domain ? domain : "(null)", path ? path : "(null)")); + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Search cookie='%s' domain='%s' path='%s'\n", name, domain ? domain : "(null)", path ? path : "(null)")); for (p = soap->cookies; p; p = p->next) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie in database: %s=%s domain=%s path=%s env=%hd\n", p->name, p->value ? p->value : "(null)", p->domain ? p->domain : "(null)", p->path ? p->path : "(null)", p->env)); + { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie in database: %s='%s' domain='%s' path='%s' env=%hd\n", p->name, p->value ? p->value : "(null)", p->domain ? p->domain : "(null)", p->path ? p->path : "(null)", p->env)); if (!strcmp(p->name, name) && p->domain && p->path @@ -5975,7 +6254,7 @@ soap_set_cookie(struct soap *soap, const char *name, const char *value, const ch else if (*path == '/') path++; q = soap_cookie(soap, name, domain, path); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set %scookie: %s=%s domain=%s path=%s\n", q ? SOAP_STR_EOS : "new ", name, value ? value : "(null)", domain ? domain : "(null)", path ? path : "(null)")); + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set %scookie: %s='%s' domain='%s' path='%s'\n", q ? SOAP_STR_EOS : "new ", name, value ? value : "(null)", domain ? domain : "(null)", path ? path : "(null)")); if (!q) { if ((q = (struct soap_cookie*)SOAP_MALLOC(soap, sizeof(struct soap_cookie)))) { if ((q->name = (char*)SOAP_MALLOC(soap, strlen(name)+1))) @@ -6044,13 +6323,13 @@ soap_clr_cookie(struct soap *soap, const char *name, const char *domain, const c if (!domain) domain = soap->cookie_domain; if (!domain) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error in clear cookie %s: cookie domain not set\n", name ? name : "(null)")); + { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error in clear cookie='%s': cookie domain not set\n", name ? name : "(null)")); return; } if (!path) path = soap->cookie_path; if (!path) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error in clear cookie %s: cookie path not set\n", name ? name : "(null)")); + { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error in clear cookie='%s': cookie path not set\n", name ? name : "(null)")); return; } if (*path == '/') @@ -6110,7 +6389,7 @@ int SOAP_FMAC2 soap_set_cookie_expire(struct soap *soap, const char *name, long expire, const char *domain, const char *path) { struct soap_cookie *p; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set cookie expiration max-age %ld: %s domain=%s path=%s\n", expire, name, domain ? domain : "(null)", path ? path : "(null)")); + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set cookie expiration max-age=%ld: cookie='%s' domain='%s' path='%s'\n", expire, name, domain ? domain : "(null)", path ? path : "(null)")); if ((p = soap_cookie(soap, name, domain, path))) { p->maxage = expire; p->modified = 1; @@ -6164,10 +6443,10 @@ soap_putsetcookies(struct soap *soap) ) { s = tmp; if (p->name) - s += soap_encode_cookie(p->name, s, tmp-s+4064); + s += soap_encode_url(p->name, s, tmp-s+4064); if (p->value && *p->value) { *s++ = '='; - s += soap_encode_cookie(p->value, s, tmp-s+4064); + s += soap_encode_url(p->value, s, tmp-s+4064); } if (p->domain && (int)strlen(p->domain) < tmp-s+4064) { strcpy(s, ";Domain="); @@ -6192,15 +6471,25 @@ soap_putsetcookies(struct soap *soap) s += strlen(s); } else - s += soap_encode_cookie(t, s, tmp-s+4064); + s += soap_encode_url(t, s, tmp-s+4064); } } if (p->version > 0 && s-tmp < 4060) - { sprintf(s, ";Version=%u", p->version); + { +#ifdef HAVE_SNPRINTF + soap_snprintf(s, 4096 - (s-tmp), ";Version=%u", p->version); +#else + sprintf(s, ";Version=%u", p->version); +#endif s += strlen(s); } if (p->maxage >= 0 && s-tmp < 4060) - { sprintf(s, ";Max-Age=%ld", p->maxage); + { +#ifdef HAVE_SNPRINTF + soap_snprintf(s, 4096 - (s-tmp), ";Max-Age=%ld", p->maxage); +#else + sprintf(s, ";Max-Age=%ld", p->maxage); +#endif s += strlen(s); } if (s-tmp < 4073 @@ -6231,7 +6520,7 @@ soap_putcookies(struct soap *soap, const char *domain, const char *path, int sec return SOAP_OK; s = tmp; p = &soap->cookies; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Sending cookies for domain=%s path=%s\n", domain, path)); + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Sending cookies for domain='%s' path='%s'\n", domain, path)); if (*path == '/') path++; while ((q = *p)) @@ -6277,45 +6566,60 @@ soap_putcookies(struct soap *soap, const char *domain, const char *path, int sec && (!q->path || !strncmp(q->path, path, strlen(q->path))) && (!q->secure || secure)) { size_t n = 12; - if (q->name) - n += 3*strlen(q->name); - if (q->value && *q->value) - n += 3*strlen(q->value) + 1; + if (q->name) + n += 3*strlen(q->name); + if (q->value && *q->value) + n += 3*strlen(q->value) + 1; if (q->path && *q->path) - n += strlen(q->path) + 9; - if (q->domain) - n += strlen(q->domain) + 11; - if (tmp - s + n > sizeof(tmp)) + n += strlen(q->path) + 9; + if (q->domain) + n += strlen(q->domain) + 11; + if (tmp - s + n > sizeof(tmp)) { if (s == tmp) - return SOAP_OK; /* HTTP header size overflow */ - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie: %s\n", tmp)); + return SOAP_OK; /* HTTP header size overflow */ + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie: %s\n", tmp)); if ((soap->error = soap->fposthdr(soap, "Cookie", tmp))) return soap->error; - s = tmp; - } - else if (s != tmp) - { strcat(s, " "); - s++; - } - if (q->version != version) - { sprintf(s, "$Version=%u;", q->version); + s = tmp; + } + else if (s != tmp) + { strcat(s, " "); + s++; + } + if (q->version != version && s-tmp < 4060) + { +#ifdef HAVE_SNPRINTF + soap_snprintf(s, 4096 - (s-tmp), "$Version=%u;", q->version); +#else + sprintf(s, "$Version=%u;", q->version); +#endif version = q->version; s += strlen(s); } if (q->name) - s += soap_encode_cookie(q->name, s, tmp+sizeof(tmp)-s-16); + s += soap_encode_url(q->name, s, tmp+sizeof(tmp)-s-16); if (q->value && *q->value) { *s++ = '='; - s += soap_encode_cookie(q->value, s, tmp+sizeof(tmp)-s-16); + s += soap_encode_url(q->value, s, tmp+sizeof(tmp)-s-16); } - if (q->path) - { sprintf(s, ";$Path=\"/%s\"", (*q->path == '/' ? q->path + 1 : q->path)); + if (q->path && (s-tmp) + strlen(q->path) < 4060) + { +#ifdef HAVE_SNPRINTF + soap_snprintf(s, 4096 - (s-tmp), ";$Path=\"/%s\"", (*q->path == '/' ? q->path + 1 : q->path)); +#else + sprintf(s, ";$Path=\"/%s\"", (*q->path == '/' ? q->path + 1 : q->path)); +#endif s += strlen(s); } - if (q->domain) - { sprintf(s, ";$Domain=\"%s\"", q->domain); + if (q->domain && (s-tmp) + strlen(q->domain) < 4060) + { +#ifdef HAVE_SNPRINTF + soap_snprintf(s, 4096 - (s-tmp), ";$Domain=\"%s\"", q->domain); +#else + sprintf(s, ";$Domain=\"%s\"", q->domain); +#endif s += strlen(s); - } + } } p = &q->next; } @@ -6452,7 +6756,7 @@ soap_getcookies(struct soap *soap, const char *val) p->secure = 1; else { if (p) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Got environment cookie %s=%s domain=%s path=%s expire=%ld secure=%d\n", p->name, p->value ? p->value : "(null)", p->domain ? p->domain : "(null)", p->path ? p->path : "(null)", p->expire, p->secure)); + { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Got environment cookie='%s' value='%s' domain='%s' path='%s' expire=%ld secure=%d\n", p->name, p->value ? p->value : "(null)", p->domain ? p->domain : "(null)", p->path ? p->path : "(null)", p->expire, p->secure)); if ((q = soap_set_cookie(soap, p->name, p->value, p->domain, p->path))) { q->version = p->version; q->expire = p->expire; @@ -6504,7 +6808,7 @@ soap_getcookies(struct soap *soap, const char *val) } } if (p) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Got environment cookie %s=%s domain=%s path=%s expire=%ld secure=%d\n", p->name, p->value ? p->value : "(null)", p->domain ? p->domain : "(null)", p->path ? p->path : "(null)", p->expire, p->secure)); + { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Got environment cookie='%s' value='%s' domain='%s' path='%s' expire=%ld secure=%d\n", p->name, p->value ? p->value : "(null)", p->domain ? p->domain : "(null)", p->path ? p->path : "(null)", p->expire, p->secure)); if ((q = soap_set_cookie(soap, p->name, p->value, p->domain, p->path))) { q->version = p->version; q->expire = p->expire; @@ -6694,6 +6998,7 @@ SOAP_FMAC2 soap_embed(struct soap *soap, const void *p, const struct soap_array *a, int n, const char *tag, int type) { register int i; struct soap_plist *pp; + (void)soap; if (soap->version == 2) soap->encoding = 1; if (a) @@ -6707,7 +7012,6 @@ soap_embed(struct soap *soap, const void *p, const struct soap_array *a, int n, soap_set_embedded(soap, pp); } return i; - (void)soap; } #endif #endif @@ -6745,6 +7049,7 @@ SOAP_FMAC2 soap_pointer_enter(struct soap *soap, const void *p, const struct soap_array *a, int n, int type, struct soap_plist **ppp) { register size_t h; register struct soap_plist *pp; + (void)n; if (!soap->pblk || soap->pidx >= SOAP_PTRBLK) { register struct soap_pblk *pb = (struct soap_pblk*)SOAP_MALLOC(soap, sizeof(struct soap_pblk)); if (!pb) @@ -6770,7 +7075,6 @@ soap_pointer_enter(struct soap *soap, const void *p, const struct soap_array *a, soap->pht[h] = pp; pp->id = ++soap->idnum; return pp->id; - (void)n; } #endif #endif @@ -6840,8 +7144,6 @@ soap_begin_count(struct soap *soap) soap->mode |= SOAP_IO_STORE; } #endif - if (!soap->encodingStyle && !(soap->mode & SOAP_XML_GRAPH)) - soap->mode |= SOAP_XML_TREE; #ifndef WITH_LEANER if ((soap->mode & SOAP_ENC_MTOM) && (soap->mode & SOAP_ENC_DIME)) soap->mode |= SOAP_ENC_MIME; @@ -6863,13 +7165,13 @@ soap_begin_count(struct soap *soap) soap->idnum = 0; soap_clr_attr(soap); soap_set_local_namespaces(soap); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin count phase (socket=%d mode=0x%x count=%lu)\n", soap->socket, (unsigned int)soap->mode, (unsigned long)soap->count)); #ifndef WITH_LEANER soap->dime.count = 0; /* count # of attachments */ soap->dime.size = 0; /* accumulate total size of attachments */ if (soap->fprepareinitsend && (soap->mode & SOAP_IO) != SOAP_IO_STORE && (soap->error = soap->fprepareinitsend(soap))) return soap->error; #endif + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin count phase (socket=%d mode=0x%x count=%lu)\n", soap->socket, (unsigned int)soap->mode, (unsigned long)soap->count)); return SOAP_OK; } #endif @@ -6897,7 +7199,7 @@ SOAP_FMAC1 int SOAP_FMAC2 soap_begin_send(struct soap *soap) -{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing for output\n")); +{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing for output to socket=%d/fd=%d\n", soap->socket, soap->sendfd)); soap_free_ns(soap); soap->error = SOAP_OK; soap->mode = soap->omode | (soap->mode & (SOAP_IO_LENGTH | SOAP_ENC_DIME)); @@ -6928,8 +7230,6 @@ soap_begin_send(struct soap *soap) return soap->error; if (!(soap->mode & SOAP_IO_KEEPALIVE)) soap->keep_alive = 0; - if (!soap->encodingStyle && !(soap->mode & SOAP_XML_GRAPH)) - soap->mode |= SOAP_XML_TREE; #ifndef WITH_LEANER if ((soap->mode & SOAP_ENC_MTOM) && (soap->mode & SOAP_ENC_DIME)) { soap->mode |= SOAP_ENC_MIME; @@ -7036,7 +7336,7 @@ int SOAP_FMAC2 soap_reference(struct soap *soap, const void *p, int t) { struct soap_plist *pp; - if (!p || (soap->mode & SOAP_XML_TREE)) + if (!p || (!soap->encodingStyle && !(soap->omode & (SOAP_ENC_DIME|SOAP_ENC_MIME|SOAP_ENC_MTOM|SOAP_XML_GRAPH))) || (soap->omode & SOAP_XML_TREE)) return 1; if (soap_pointer_lookup(soap, p, t, &pp)) { if (pp->mark1 == 0) @@ -7044,11 +7344,7 @@ soap_reference(struct soap *soap, const void *p, int t) pp->mark2 = 2; } } - else if (soap_pointer_enter(soap, p, NULL, 0, t, &pp)) - { pp->mark1 = 0; - pp->mark2 = 0; - } - else + else if (!soap_pointer_enter(soap, p, NULL, 0, t, &pp)) return 1; DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Reference %p type=%d (%d %d)\n", p, t, (int)pp->mark1, (int)pp->mark2)); return pp->mark1; @@ -7063,12 +7359,10 @@ SOAP_FMAC1 int SOAP_FMAC2 soap_array_reference(struct soap *soap, const void *p, const struct soap_array *a, int n, int t) -{ register int i; - struct soap_plist *pp; - if (!p || !a->__ptr) +{ struct soap_plist *pp; + if (!p || !a->__ptr || (!soap->encodingStyle && !(soap->omode & (SOAP_ENC_DIME|SOAP_ENC_MIME|SOAP_ENC_MTOM|SOAP_XML_GRAPH))) || (soap->omode & SOAP_XML_TREE)) return 1; - i = soap_array_pointer_lookup(soap, p, a, n, t, &pp); - if (i) + if (soap_array_pointer_lookup(soap, p, a, n, t, &pp)) { if (pp->mark1 == 0) { pp->mark1 = 2; pp->mark2 = 2; @@ -7076,10 +7370,6 @@ soap_array_reference(struct soap *soap, const void *p, const struct soap_array * } else if (!soap_pointer_enter(soap, p, a, n, t, &pp)) return 1; - else - { pp->mark1 = 0; - pp->mark2 = 0; - } DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array reference %p ptr=%p dim=%d type=%d (%d %d)\n", p, a->__ptr, n, t, (int)pp->mark1, (int)pp->mark2)); return pp->mark1; } @@ -7094,10 +7384,10 @@ int SOAP_FMAC2 soap_embedded_id(struct soap *soap, int id, const void *p, int t) { struct soap_plist *pp = NULL; - if (soap->mode & SOAP_XML_TREE) + if (!id || (!soap->encodingStyle && !(soap->omode & SOAP_XML_GRAPH)) || (soap->omode & SOAP_XML_TREE)) return id; DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Embedded_id %p type=%d id=%d\n", p, t, id)); - if (soap->version == 1 && soap->encodingStyle && !(soap->mode & SOAP_XML_GRAPH) && soap->part != SOAP_IN_HEADER) + if (soap->version == 1 && soap->part != SOAP_IN_HEADER) { if (id < 0) { id = soap_pointer_lookup(soap, p, t, &pp); if (id) @@ -7209,7 +7499,12 @@ soap_attachment(struct soap *soap, const char *tag, int id, const void *p, const if (id <= 0) id = i; if (!aid) - { sprintf(soap->tmpbuf, soap->dime_id_format, id); + { +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), soap->dime_id_format, id); +#else + sprintf(soap->tmpbuf, soap->dime_id_format, id); +#endif aid = soap_strdup(soap, soap->tmpbuf); } /* Add MTOM xop:Include element when necessary */ @@ -7325,8 +7620,8 @@ soap_enter(struct soap *soap, const char *id) register struct soap_ilist *ip; ip = (struct soap_ilist*)SOAP_MALLOC(soap, sizeof(struct soap_ilist) + strlen(id)); if (ip) - { h = soap_hash(id); - strcpy((char*)ip->id, id); + { strcpy((char*)ip->id, id); + h = soap_hash(id); /* h = (HASH(id) % SOAP_IDHASH) so soap->iht[h] is safe */ ip->next = soap->iht[h]; soap->iht[h] = ip; } @@ -7619,6 +7914,22 @@ soap_delegate_deletion(struct soap *soap, struct soap *soap_to) *q = (char*)soap_to->alist; soap_to->alist = soap->alist; soap->alist = NULL; +#ifdef SOAP_MEM_DEBUG + cp = soap->clist; + while (cp) + { h = soap_hash_ptr(cp); + for (mp = &soap->mht[h]; *mp; mp = &(*mp)->next) + { if ((*mp)->ptr == cp) + { mq = *mp; + *mp = mq->next; + mq->next = soap_to->mht[h]; + soap_to->mht[h] = mq; + break; + } + } + cp = cp->next; + } +#endif cp = soap_to->clist; if (cp) { while (cp->next) @@ -7950,7 +8261,17 @@ soap_end_send(struct soap *soap) if (err) return err; #endif - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End send mode=0x%x\n", soap->mode)); + return soap_end_send_flush(soap); +} +#endif + +/******************************************************************************/ +#ifndef PALM_1 +SOAP_FMAC1 +int +SOAP_FMAC2 +soap_end_send_flush(struct soap *soap) +{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End send mode=0x%x\n", soap->mode)); if (soap->mode & SOAP_IO) /* need to flush the remaining data in buffer */ { if (soap_flush(soap)) #ifdef WITH_ZLIB @@ -8022,16 +8343,20 @@ soap_end_send(struct soap *soap) #endif for (p = soap_first_block(soap, NULL); p; p = soap_next_block(soap, NULL)) { DBGMSG(SENT, p, soap_block_size(soap, NULL)); + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Send %u bytes to socket=%d/fd=%d\n", (unsigned int)soap_block_size(soap, NULL), soap->socket, soap->sendfd)); if ((soap->error = soap->fsend(soap, p, soap_block_size(soap, NULL)))) { soap_end_block(soap, NULL); return soap->error; } } soap_end_block(soap, NULL); + if (soap->fpreparefinalsend && (soap->error = soap->fpreparefinalsend(soap))) + return soap->error; } #ifndef WITH_LEANER else if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK) { DBGMSG(SENT, "\r\n0\r\n\r\n", 7); + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Send 7 bytes to socket=%d/fd=%d\n", soap->socket, soap->sendfd)); if ((soap->error = soap->fsend(soap, "\r\n0\r\n\r\n", 7))) return soap->error; } @@ -8193,13 +8518,9 @@ soap_free_temp(struct soap *soap) if (ns) { for (; ns->id; ns++) { if (ns->out) - { if (soap->encodingStyle == ns->out) - soap->encodingStyle = SOAP_STR_EOS; - SOAP_FREE(soap, ns->out); + { SOAP_FREE(soap, ns->out); ns->out = NULL; } - if (soap->encodingStyle == ns->ns) - soap->encodingStyle = SOAP_STR_EOS; } SOAP_FREE(soap, soap->local_namespaces); soap->local_namespaces = NULL; @@ -8299,34 +8620,37 @@ soap_set_logfile(struct soap *soap, int i, const char *logfile) #endif /******************************************************************************/ -#ifdef SOAP_DEBUG SOAP_FMAC1 void SOAP_FMAC2 soap_set_recv_logfile(struct soap *soap, const char *logfile) -{ soap_set_logfile(soap, SOAP_INDEX_RECV, logfile); -} +{ +#ifdef SOAP_DEBUG + soap_set_logfile(soap, SOAP_INDEX_RECV, logfile); #endif +} /******************************************************************************/ -#ifdef SOAP_DEBUG SOAP_FMAC1 void SOAP_FMAC2 soap_set_sent_logfile(struct soap *soap, const char *logfile) -{ soap_set_logfile(soap, SOAP_INDEX_SENT, logfile); -} +{ +#ifdef SOAP_DEBUG + soap_set_logfile(soap, SOAP_INDEX_SENT, logfile); #endif +} /******************************************************************************/ -#ifdef SOAP_DEBUG SOAP_FMAC1 void SOAP_FMAC2 soap_set_test_logfile(struct soap *soap, const char *logfile) -{ soap_set_logfile(soap, SOAP_INDEX_TEST, logfile); -} +{ +#ifdef SOAP_DEBUG + soap_set_logfile(soap, SOAP_INDEX_TEST, logfile); #endif +} /******************************************************************************/ #ifndef PALM_1 @@ -8382,12 +8706,10 @@ soap_copy_context(struct soap *copy, const struct soap *soap) soap_set_sent_logfile(copy, soap->logfile[SOAP_INDEX_SENT]); soap_set_recv_logfile(copy, soap->logfile[SOAP_INDEX_RECV]); #endif - copy->namespaces = NULL; + copy->namespaces = soap->local_namespaces; copy->local_namespaces = NULL; - if (soap->local_namespaces) - soap_set_namespaces(copy, soap->local_namespaces); - else - soap_set_namespaces(copy, soap->namespaces); + soap_set_local_namespaces(copy); /* copy content of soap->local_namespaces */ + copy->namespaces = soap->namespaces; /* point to shared read-only namespaces table */ #ifdef WITH_C_LOCALE # ifdef WIN32 copy->c_locale = _create_locale(LC_ALL, "C"); @@ -8455,6 +8777,7 @@ soap_copy_stream(struct soap *copy, struct soap *soap) { struct soap_attribute *tp = NULL, *tq; if (copy == soap) return; + copy->header = soap->header; copy->mode = soap->mode; copy->imode = soap->imode; copy->omode = soap->omode; @@ -8524,6 +8847,7 @@ soap_copy_stream(struct soap *copy, struct soap *soap) /* copy XML parser state */ soap_free_ns(copy); soap_set_local_namespaces(copy); + copy->version = soap->version; if (soap->nlist && soap->local_namespaces) { register struct soap_nlist *np = NULL, *nq; /* copy reversed nlist */ @@ -8616,6 +8940,16 @@ soap_free_stream(struct soap *soap) SOAP_FMAC1 void SOAP_FMAC2 +soap_initialize(struct soap *soap) +{ soap_versioning(soap_init)(soap, SOAP_IO_DEFAULT, SOAP_IO_DEFAULT); +} +#endif + +/******************************************************************************/ +#ifndef PALM_1 +SOAP_FMAC1 +void +SOAP_FMAC2 soap_versioning(soap_init)(struct soap *soap, soap_mode imode, soap_mode omode) { size_t i; soap->state = SOAP_INIT; @@ -8667,8 +9001,8 @@ soap_versioning(soap_init)(struct soap *soap, soap_mode imode, soap_mode omode) soap->fconnect = NULL; soap->fdisconnect = NULL; #ifndef WITH_NOIO - soap->ipv6_multicast_if = 0; - soap->ipv4_multicast_if = NULL; + soap->ipv6_multicast_if = 0; /* in_addr_t value */ + soap->ipv4_multicast_if = NULL; /* points to struct in_addr or in_addr_t */ soap->ipv4_multicast_ttl = 0; /* 0: use default */ #ifndef WITH_IPV6 soap->fresolve = tcp_gethost; @@ -8746,7 +9080,7 @@ soap_versioning(soap_init)(struct soap *soap, soap_mode imode, soap_mode omode) soap->labbuf = NULL; soap->lablen = 0; soap->labidx = 0; - soap->encodingStyle = SOAP_STR_EOS; + soap->encodingStyle = NULL; #ifndef WITH_NONAMESPACES soap->namespaces = namespaces; #else @@ -8835,6 +9169,7 @@ soap_versioning(soap_init)(struct soap *soap, soap_mode imode, soap_mode omode) soap->session = NULL; soap->ssl_flags = SOAP_SSL_DEFAULT; soap->keyfile = NULL; + soap->keyid = NULL; soap->password = NULL; soap->cafile = NULL; soap->capath = NULL; @@ -8853,6 +9188,7 @@ soap_versioning(soap_init)(struct soap *soap, soap_mode imode, soap_mode omode) soap->session = NULL; soap->ssl_flags = SOAP_SSL_DEFAULT; soap->keyfile = NULL; + soap->keyid = NULL; soap->password = NULL; soap->cafile = NULL; soap->capath = NULL; @@ -8926,6 +9262,7 @@ soap_begin(struct soap *soap) soap->idnum = 0; soap->level = 0; soap->endpoint[0] = '\0'; + soap->encodingStyle = SOAP_STR_EOS; #ifndef WITH_LEANER soap->dime.chunksize = 0; soap->dime.buflen = 0; @@ -8962,6 +9299,27 @@ soap_end(struct soap *soap) /******************************************************************************/ #ifndef PALM_1 SOAP_FMAC1 +void +SOAP_FMAC2 +soap_set_version(struct soap *soap, short version) +{ soap_set_local_namespaces(soap); + if (soap->version != version) + { if (version == 1) + { soap->local_namespaces[0].ns = soap_env1; + soap->local_namespaces[1].ns = soap_enc1; + } + else if (version == 2) + { soap->local_namespaces[0].ns = soap_env2; + soap->local_namespaces[1].ns = soap_enc2; + } + soap->version = version; + } +} +#endif + +/******************************************************************************/ +#ifndef PALM_1 +SOAP_FMAC1 int SOAP_FMAC2 soap_set_namespaces(struct soap *soap, const struct Namespace *p) @@ -9034,7 +9392,7 @@ soap_set_local_namespaces(struct soap *soap) if (ns2[0].ns) { if (!strcmp(ns2[0].ns, soap_env1)) soap->version = 1; - else + else if (!strcmp(ns2[0].ns, soap_env2)) soap->version = 2; } soap->local_namespaces = ns2; @@ -9145,11 +9503,14 @@ soap_utilize_ns(struct soap *soap, const char *tag) size_t n = 0; const char *t = strchr(tag, ':'); if (t) - n = t - tag; + { n = t - tag; + if (n >= sizeof(soap->tmpbuf)) + n = sizeof(soap->tmpbuf) - 1; + } np = soap_lookup_ns(soap, tag, n); DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Utilizing namespace of '%s'\n", tag)); if (np) - { if (np->index == 0) + { if (np->index <= 0) soap_push_ns(soap, np->id, np->ns, 1); } else if (strncmp(tag, "xml", 3)) @@ -9191,8 +9552,8 @@ soap_element(struct soap *soap, const char *tag, int id, const char *type) for (np = soap->nlist; np; np = np->next) { if (np->index == 2) { struct soap_nlist *np1 = soap_push_ns(soap, np->id, np->ns, 1); - if (np1) - np1->index = 0; + if (np1) + np1->index = 0; } } soap->evlev = soap->level; @@ -9268,17 +9629,34 @@ soap_element(struct soap *soap, const char *tag, int id, const char *type) } #endif if (!soap->ns) - { struct Namespace *ns; + { struct Namespace *ns = soap->local_namespaces; int k = -1; + if (ns) + { #ifndef WITH_LEAN - if ((soap->mode & SOAP_XML_DEFAULTNS)) - k = 4; /* only produce the first four required entries */ + if ((soap->mode & SOAP_XML_DEFAULTNS)) + { if (soap->version) + k = 4; /* first four required entries */ + else if (!(soap->mode & SOAP_XML_NOTYPE) || (soap->mode & SOAP_XML_NIL)) + { ns += 2; + k = 2; /* next two entries */ + } + else + k = 0; /* no entries */ + } #endif - for (ns = soap->local_namespaces; ns && ns->id && k; ns++, k--) - { if (*ns->id && (ns->out || ns->ns)) - { sprintf(soap->tmpbuf, "xmlns:%s", ns->id); - if (soap_attribute(soap, soap->tmpbuf, ns->out ? ns->out : ns->ns)) - return soap->error; + while (k-- && ns->id) + { if (*ns->id && (ns->out || ns->ns)) + { +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "xmlns:%s", ns->id); +#else + sprintf(soap->tmpbuf, "xmlns:%s", ns->id); +#endif + if (soap_attribute(soap, soap->tmpbuf, ns->out ? ns->out : ns->ns)) + return soap->error; + } + ns++; } } } @@ -9288,8 +9666,17 @@ soap_element(struct soap *soap, const char *tag, int id, const char *type) soap_utilize_ns(soap, tag); #endif if (id > 0) - { sprintf(soap->tmpbuf, "_%d", id); - if (soap_attribute(soap, "id", soap->tmpbuf)) + { +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "_%d", id); +#else + sprintf(soap->tmpbuf, "_%d", id); +#endif + if (soap->version == 2) + { if (soap_attribute(soap, "SOAP-ENC:id", soap->tmpbuf)) + return soap->error; + } + else if (soap_attribute(soap, "id", soap->tmpbuf)) return soap->error; } if (type && *type && !(soap->mode & SOAP_XML_NOTYPE) && soap->part != SOAP_IN_HEADER) @@ -9312,9 +9699,20 @@ soap_element(struct soap *soap, const char *tag, int id, const char *type) } if (soap->null && soap->position > 0) { register int i; +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf) - 1, "[%d", soap->positions[0]); +#else sprintf(soap->tmpbuf, "[%d", soap->positions[0]); +#endif for (i = 1; i < soap->position; i++) - sprintf(soap->tmpbuf + strlen(soap->tmpbuf), ",%d", soap->positions[i]); + { register size_t l = strlen(soap->tmpbuf); +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf + l, sizeof(soap->tmpbuf)-l-1, ",%d", soap->positions[i]); +#else + if (l + 13 < sizeof(soap->tmpbuf)) + sprintf(soap->tmpbuf + l, ",%d", soap->positions[i]); +#endif + } strcat(soap->tmpbuf, "]"); if (soap_attribute(soap, "SOAP-ENC:position", soap->tmpbuf)) return soap->error; @@ -9329,7 +9727,7 @@ soap_element(struct soap *soap, const char *tag, int id, const char *type) soap->mustUnderstand = 0; } if (soap->encoding) - { if (soap->encodingStyle && soap->local_namespaces) + { if (soap->encodingStyle && soap->local_namespaces && soap->local_namespaces[0].id && soap->local_namespaces[1].id) { if (!*soap->encodingStyle) { if (soap->local_namespaces[1].out) soap->encodingStyle = soap->local_namespaces[1].out; @@ -9339,6 +9737,8 @@ soap_element(struct soap *soap, const char *tag, int id, const char *type) if (soap->encodingStyle && soap_attribute(soap, "SOAP-ENV:encodingStyle", soap->encodingStyle)) return soap->error; } + else + soap->encodingStyle = NULL; soap->encoding = 0; } soap->null = 0; @@ -9495,13 +9895,19 @@ soap_array_begin_out(struct soap *soap, const char *tag, int id, const char *typ if (soap->version == 2) { const char *s; s = soap_strrchr(type, '['); - if ((size_t)(s - type) < sizeof(soap->tmpbuf)) + if (s && (size_t)(s - type) < sizeof(soap->tmpbuf)) { strncpy(soap->tmpbuf, type, s - type); soap->tmpbuf[s - type] = '\0'; if (soap_attribute(soap, "SOAP-ENC:itemType", soap->tmpbuf)) return soap->error; - if (s && (soap_attribute(soap, "SOAP-ENC:arraySize", s + 1))) - return soap->error; + s++; + if (*s) + { strncpy(soap->tmpbuf, s, sizeof(soap->tmpbuf)); + soap->tmpbuf[sizeof(soap->tmpbuf) - 1] = '\0'; + soap->tmpbuf[strlen(soap->tmpbuf) - 1] = '\0'; + if (soap_attribute(soap, "SOAP-ENC:arraySize", soap->tmpbuf)) + return soap->error; + } } } else @@ -9534,7 +9940,16 @@ soap_element_start_end_out(struct soap *soap, const char *tag) } for (np = soap->nlist; np; np = np->next) { if (np->index == 1 && np->ns) - { sprintf(soap->tmpbuf, *(np->id) ? "xmlns:%s" : "xmlns", np->id); + { if (*(np->id)) + { +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "xmlns:%s", np->id); +#else + sprintf(soap->tmpbuf, "xmlns:%s", np->id); +#endif + } + else + strcpy(soap->tmpbuf, "xmlns"); DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Enabling utilized binding (level=%u) %s='%s'\n", np->level, soap->tmpbuf, np->ns)); soap_set_attr(soap, soap->tmpbuf, np->ns, 1); np->index = 2; @@ -9658,13 +10073,19 @@ SOAP_FMAC1 int SOAP_FMAC2 soap_element_ref(struct soap *soap, const char *tag, int id, int href) -{ register int n = 0; - const char *s = "href"; - if (soap->version == 2) - { s = "SOAP-ENC:ref"; - n = 1; +{ register const char *s = "ref"; + register int n = 1; + if (soap->version == 1) + { s = "href"; + n = 0; } + else if (soap->version == 2) + s = "SOAP-ENC:ref"; +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->href, sizeof(soap->href), "#_%d", href); +#else sprintf(soap->href, "#_%d", href); +#endif return soap_element_href(soap, tag, id, s, soap->href + n); } #endif @@ -9714,7 +10135,7 @@ int SOAP_FMAC2 soap_element_nil(struct soap *soap, const char *tag) { if (soap_element(soap, tag, -1, NULL) - || soap_attribute(soap, "xsi:nil", "true")) + || ((soap->mode & SOAP_XML_NIL) && soap_attribute(soap, "xsi:nil", "true"))) return soap->error; return soap_element_start_end_out(soap, tag); } @@ -9727,11 +10148,11 @@ int SOAP_FMAC2 soap_element_id(struct soap *soap, const char *tag, int id, const void *p, const struct soap_array *a, int n, const char *type, int t) { if (!p) - { soap_element_null(soap, tag, id, type); + { soap->error = soap_element_null(soap, tag, id, type); return -1; } #ifndef WITH_NOIDREF - if (soap->mode & SOAP_XML_TREE) + if ((!soap->encodingStyle && !(soap->omode & SOAP_XML_GRAPH)) || (soap->omode & SOAP_XML_TREE)) return 0; if (id < 0) { struct soap_plist *pp; @@ -9988,7 +10409,7 @@ soap_set_attr(struct soap *soap, const char *name, const char *value, int flag) if ((soap->mode & SOAP_XML_CANONICAL)) { struct soap_attribute **tpp = &soap->attributes; const char *s = strchr(name, ':'); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inserting attribute %s for c14n\n", name)) + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inserting attribute %s for c14n\n", name)); if (!strncmp(name, "xmlns", 5)) { for (; *tpp; tpp = &(*tpp)->next) if (strncmp((*tpp)->name, "xmlns", 5) || strcmp((*tpp)->name + 5, name + 5) > 0) @@ -10054,7 +10475,7 @@ soap_set_attr(struct soap *soap, const char *name, const char *value, int flag) if (!strcmp(name, "wsu:Id")) { soap->event = SOAP_SEC_BEGIN; strncpy(soap->id, value, sizeof(soap->id)); - soap->id[sizeof(soap->id)-1] = '\0'; + soap->id[sizeof(soap->id) - 1] = '\0'; } #endif } @@ -10139,7 +10560,9 @@ soap_getattrval(struct soap *soap, char *s, size_t n, soap_wchar d) } default: if ((int)c == EOF) + { *s = '\0'; return soap->error = SOAP_CHK_EOF; + } *s++ = (char)c; } } @@ -10169,12 +10592,12 @@ SOAP_FMAC2 soap_append_lab(struct soap *soap, const char *s, size_t n) { if (soap->labidx + n >= soap->lablen) { register char *t = soap->labbuf; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Enlarging look-aside buffer to append data, old size=%lu", (unsigned long)soap->lablen)); + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Enlarging look-aside buffer to append data, size=%lu\n", (unsigned long)soap->lablen)); if (soap->lablen == 0) soap->lablen = SOAP_LABLEN; while (soap->labidx + n >= soap->lablen) soap->lablen <<= 1; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, ", new size=%lu\n", (unsigned long)soap->lablen)); + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "New look-aside buffer size=%lu\n", (unsigned long)soap->lablen)); soap->labbuf = (char*)SOAP_MALLOC(soap, soap->lablen); if (!soap->labbuf) { if (t) @@ -10271,7 +10694,7 @@ soap_peek_element(struct soap *soap) { *soap->tag = '\0'; if ((int)c == EOF) return soap->error = SOAP_CHK_EOF; - soap_unget(soap, c > 0 ? c | 0x80000000 : c); + soap_unget(soap, c); #ifdef WITH_DOM /* whitespace leading to end tag is significant for DOM */ if ((soap->mode & SOAP_XML_DOM) && soap->dom) @@ -10283,18 +10706,18 @@ soap_peek_element(struct soap *soap) #endif return soap->error = SOAP_NO_TAG; } - s = soap->tag; do c = soap_get1(soap); while (soap_blank(c)); + s = soap->tag; i = sizeof(soap->tag); while (c != '>' && c != '/' && soap_notblank(c) && (int)c != EOF) { if (--i > 0) *s++ = (char)c; c = soap_get1(soap); } + *s = '\0'; while (soap_blank(c)) c = soap_get1(soap); - *s = '\0'; #ifdef WITH_DOM if (soap->mode & SOAP_XML_DOM) { register struct soap_dom_element *elt; @@ -10503,27 +10926,35 @@ soap_peek_element(struct soap *soap) { #ifndef WITH_NOIDREF if (!strcmp(tp->name, "id")) - { if ((soap->version > 0 && !(soap->mode & SOAP_XML_TREE)) + { if ((soap->version > 0 && !(soap->imode & SOAP_XML_TREE)) || (soap->mode & SOAP_XML_GRAPH)) { *soap->id = '#'; strncpy(soap->id + 1, tp->value, sizeof(soap->id) - 2); - soap->id[sizeof(soap->id)-1] = '\0'; + soap->id[sizeof(soap->id) - 1] = '\0'; } } else if (!strcmp(tp->name, "href")) - { if (soap->version == 1 + { if ((soap->version == 1 && !(soap->imode & SOAP_XML_TREE)) || (soap->mode & SOAP_XML_GRAPH) || (soap->mode & SOAP_ENC_MTOM) || (soap->mode & SOAP_ENC_DIME)) { strncpy(soap->href, tp->value, sizeof(soap->href) - 1); - soap->href[sizeof(soap->href)-1] = '\0'; + soap->href[sizeof(soap->href) - 1] = '\0'; + } + } + else if (!strcmp(tp->name, "ref")) + { if ((soap->version == 2 && !(soap->imode & SOAP_XML_TREE)) + || (soap->mode & SOAP_XML_GRAPH)) + { *soap->href = '#'; + strncpy(soap->href + (*tp->value != '#'), tp->value, sizeof(soap->href) - 2); + soap->href[sizeof(soap->href) - 1] = '\0'; } } else #endif if (!soap_match_tag(soap, tp->name, "xsi:type")) { strncpy(soap->type, tp->value, sizeof(soap->type) - 1); - soap->type[sizeof(soap->type)-1] = '\0'; + soap->type[sizeof(soap->type) - 1] = '\0'; } else if ((!soap_match_tag(soap, tp->name, "xsi:null") || !soap_match_tag(soap, tp->name, "xsi:nil")) @@ -10537,12 +10968,12 @@ soap_peek_element(struct soap *soap) if (s && (size_t)(s - tp->value) < sizeof(soap->arrayType)) { strncpy(soap->arrayType, tp->value, s - tp->value); soap->arrayType[s - tp->value] = '\0'; - strncpy(soap->arraySize, s, sizeof(soap->arraySize) - 1); + strncpy(soap->arraySize, s, sizeof(soap->arraySize)); } else - strncpy(soap->arrayType, tp->value, sizeof(soap->arrayType) - 1); - soap->arraySize[sizeof(soap->arrayType)-1] = '\0'; - soap->arrayType[sizeof(soap->arrayType)-1] = '\0'; + strncpy(soap->arrayType, tp->value, sizeof(soap->arrayType)); + soap->arraySize[sizeof(soap->arraySize) - 1] = '\0'; + soap->arrayType[sizeof(soap->arrayType) - 1] = '\0'; } else if (!soap_match_tag(soap, tp->name, "SOAP-ENC:offset")) strncpy(soap->arrayOffset, tp->value, sizeof(soap->arrayOffset)); @@ -10562,11 +10993,15 @@ soap_peek_element(struct soap *soap) else if (soap->version == 2) { #ifndef WITH_NOIDREF - if (!strcmp(tp->name, "ref") - || !soap_match_tag(soap, tp->name, "SOAP-ENC:ref")) + if (!soap_match_tag(soap, tp->name, "SOAP-ENC:id")) + { *soap->id = '#'; + strncpy(soap->id + 1, tp->value, sizeof(soap->id) - 2); + soap->id[sizeof(soap->id) - 1] = '\0'; + } + else if (!soap_match_tag(soap, tp->name, "SOAP-ENC:ref")) { *soap->href = '#'; - strncpy(soap->href + 1, tp->value, sizeof(soap->href) - 2); - soap->href[sizeof(soap->href)-1] = '\0'; + strncpy(soap->href + (*tp->value != '#'), tp->value, sizeof(soap->href) - 2); + soap->href[sizeof(soap->href) - 1] = '\0'; } else #endif @@ -10694,7 +11129,7 @@ soap_string_out(struct soap *soap, const char *s, int flag) { wchar_t wc; register int m = mbtowc(&wc, t - 1, MB_CUR_MAX); if (m > 0 && !((soap_wchar)wc == c && m == 1 && c < 0x80)) - { if (soap_send_raw(soap, s, t - s - 1) || soap_pututf8(soap, wc)) + { if (soap_send_raw(soap, s, t - s - 1) || soap_pututf8(soap, (unsigned long)wc)) return soap->error; s = t += m - 1; continue; @@ -10740,8 +11175,8 @@ soap_string_in(struct soap *soap, int flag, long minlen, long maxlen) DBGLOG(TEST,SOAP_MESSAGE(fdebug, "String content includes tag '%s' and attributes\n", soap->tag)); t = soap->tmpbuf; *t = '<'; - t[sizeof(soap->tmpbuf)-1] = '\0'; strncpy(t + 1, soap->tag, sizeof(soap->tmpbuf) - 2); + t[sizeof(soap->tmpbuf) - 1] = '\0'; t += strlen(t); for (tp = soap->attributes; tp; tp = tp->next) { if (tp->visible) @@ -10810,7 +11245,7 @@ soap_string_in(struct soap *soap, int flag, long minlen, long maxlen) { soap_unget(soap, c); c = soap_getutf8(soap); } - if ((c & 0x7FFFFFFF) >= 0x80 && (soap->mode & SOAP_C_UTFSTRING)) + if ((c & 0x7FFFFFFF) >= 0x80 && (!flag || (soap->mode & SOAP_C_UTFSTRING))) { c &= 0x7FFFFFFF; t = buf; if (c < 0x0800) @@ -10868,7 +11303,7 @@ soap_string_in(struct soap *soap, int flag, long minlen, long maxlen) case 5: if (c == '>') state = 0; - else + else if (c != ']') state = 1; *s++ = (char)c; continue; @@ -10883,7 +11318,7 @@ soap_string_in(struct soap *soap, int flag, long minlen, long maxlen) case 7: if (c == '>') state = 0; - else + else if (c != '-') state = 2; *s++ = (char)c; continue; @@ -10891,7 +11326,7 @@ soap_string_in(struct soap *soap, int flag, long minlen, long maxlen) case 8: if (c == '>') state = 0; - else + else if (c != '?') state = 3; *s++ = (char)c; continue; @@ -11039,7 +11474,12 @@ soap_string_in(struct soap *soap, int flag, long minlen, long maxlen) m--; continue; } - if (soap->mode & SOAP_C_UTFSTRING) +#ifndef WITH_CDATA + if (!flag) + c = soap_getchar(soap); + else +#endif + if ((soap->mode & SOAP_C_UTFSTRING)) { if (((c = soap_get(soap)) & 0x80000000) && c >= -0x7FFFFF80 && c < SOAP_AP) { c &= 0x7FFFFFFF; t = buf; @@ -11100,9 +11540,16 @@ soap_string_in(struct soap *soap, int flag, long minlen, long maxlen) break; case '/': if (n > 0) - { c = soap_get(soap); - if (c == SOAP_GT) - n--; + { if (!flag) + { c = soap_getchar(soap); + if (c == '>') + n--; + } + else + { c = soap_get(soap); + if (c == SOAP_GT) + n--; + } soap_unget(soap, c); } *s++ = '/'; @@ -11155,6 +11602,25 @@ soap_string_in(struct soap *soap, int flag, long minlen, long maxlen) default: if ((int)c == EOF) goto end; +#ifndef WITH_CDATA + if (c == '<' && !flag) + { if (f && n == 0) + goto end; + c = soap_getchar(soap); + soap_unget(soap, c); + if (c == '/') + { c = SOAP_TT; + if (n == 0) + goto end; + n--; + } + else + n++; + *s++ = '<'; + break; + } + else +#endif #ifndef WITH_LEANER #ifdef HAVE_WCTOMB if (soap->mode & SOAP_C_MBSTRING) @@ -11188,7 +11654,7 @@ end: #ifdef WITH_FAST t = soap_strdup(soap, soap->labbuf); #else - soap_size_block(soap, NULL, i+1); + soap_size_block(soap, NULL, i + 1); t = soap_save_block(soap, NULL, 0); #endif if (l < minlen) @@ -11275,11 +11741,12 @@ soap_wstring_out(struct soap *soap, const wchar_t *s, int flag) if (soap_send_raw(soap, &tmp, 1)) return soap->error; } - else /* check UTF16 encoding when wchar_t is too small to hold UCS */ - { if (sizeof(wchar_t) < 4 && (c & 0xD800) == 0xD800) - { /* http://unicode.org/faq/utf_bom.html#utf16-2 */ - if ((*s & 0xD800) == 0xD800) - c = (c << 10) + *s++ + 0x10000 - (0xD800 << 10) - 0xDC00; + else + { /* check for UTF16 encoding when wchar_t is too small to hold UCS */ + if (sizeof(wchar_t) < 4 && (c & 0xFC00) == 0xD800) + { register soap_wchar d = *s++; + if ((d & 0xFC00) == 0xDC00) + c = ((c - 0xD800) << 10) + (d - 0xDC00) + 0x10000; else c = 0xFFFD; /* Malformed */ } @@ -11316,8 +11783,8 @@ soap_wstring_in(struct soap *soap, int flag, long minlen, long maxlen) struct soap_attribute *tp; t = soap->tmpbuf; *t = '<'; - t[sizeof(soap->tmpbuf)-1] = '\0'; strncpy(t + 1, soap->tag, sizeof(soap->tmpbuf) - 2); + t[sizeof(soap->tmpbuf) - 1] = '\0'; t += strlen(t); for (tp = soap->attributes; tp; tp = tp->next) { if (tp->visible) @@ -11422,9 +11889,9 @@ soap_wstring_in(struct soap *soap, int flag, long minlen, long maxlen) default: if ((int)c == EOF) goto end; + /* use UTF16 encoding when wchar_t is too small to hold UCS */ if (sizeof(wchar_t) < 4 && c > 0xFFFF) - { soap_wchar c1, c2; - /* http://unicode.org/faq/utf_bom.html#utf16-2 */ + { register soap_wchar c1, c2; c1 = 0xD800 - (0x10000 >> 10) + (c >> 10); c2 = 0xDC00 + (c & 0x3FF); c = c1; @@ -11552,7 +12019,12 @@ SOAP_FMAC1 const char* SOAP_FMAC2 soap_long2s(struct soap *soap, long n) -{ sprintf(soap->tmpbuf, "%ld", n); +{ +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "%ld", n); +#else + sprintf(soap->tmpbuf, "%ld", n); +#endif return soap->tmpbuf; } #endif @@ -11635,7 +12107,12 @@ SOAP_FMAC1 const char* SOAP_FMAC2 soap_LONG642s(struct soap *soap, LONG64 n) -{ sprintf(soap->tmpbuf, SOAP_LONG_FORMAT, n); +{ +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), SOAP_LONG_FORMAT, n); +#else + sprintf(soap->tmpbuf, SOAP_LONG_FORMAT, n); +#endif return soap->tmpbuf; } #endif @@ -11881,16 +12358,19 @@ soap_float2s(struct soap *soap, float n) return "INF"; if (soap_isninff(n)) return "-INF"; - s = soap->tmpbuf; #if defined(HAVE_SPRINTF_L) # ifdef WIN32 - _sprintf_s_l(s, _countof(soap->tmpbuf), soap->float_format, soap->c_locale, n); + _sprintf_s_l(soap->tmpbuf, _countof(soap->tmpbuf), soap->float_format, soap->c_locale, n); # else - sprintf_l(s, soap->c_locale, soap->float_format, n); + sprintf_l(soap->tmpbuf, soap->c_locale, soap->float_format, n); # endif #else - sprintf(s, soap->float_format, n); - s = strchr(s, ','); /* convert decimal comma to DP */ +# ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), soap->float_format, n); +# else + sprintf(soap->tmpbuf, soap->float_format, n); +# endif + s = strchr(soap->tmpbuf, ','); /* convert decimal comma to DP */ if (s) *s = '.'; #endif @@ -11954,10 +12434,10 @@ soap_s2float(struct soap *soap, const char *s, float *p) #endif { #if defined(HAVE_SSCANF_L) && !defined(HAVE_STRTOF_L) && !defined(HAVE_STRTOD_L) - if (sscanf_l(s, soap->c_locale, "%g", p) != 1) + if (sscanf_l(s, soap->c_locale, "%f", p) != 1) soap->error = SOAP_TYPE; #elif defined(HAVE_SSCANF) - if (sscanf(s, "%g", p) != 1) + if (sscanf(s, "%f", p) != 1) soap->error = SOAP_TYPE; #else soap->error = SOAP_TYPE; @@ -12035,16 +12515,19 @@ soap_double2s(struct soap *soap, double n) return "INF"; if (soap_isninfd(n)) return "-INF"; - s = soap->tmpbuf; #if defined(HAVE_SPRINTF_L) # ifdef WIN32 - _sprintf_s_l(s, _countof(soap->tmpbuf), soap->double_format, soap->c_locale, n); + _sprintf_s_l(soap->tmpbuf, _countof(soap->tmpbuf), soap->double_format, soap->c_locale, n); # else - sprintf_l(s, soap->c_locale, soap->double_format, n); + sprintf_l(soap->tmpbuf, soap->c_locale, soap->double_format, n); # endif #else - sprintf(s, soap->double_format, n); - s = strchr(s, ','); /* convert decimal comma to DP */ +# ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), soap->double_format, n); +#else + sprintf(soap->tmpbuf, soap->double_format, n); +#endif + s = strchr(soap->tmpbuf, ','); /* convert decimal comma to DP */ if (s) *s = '.'; #endif @@ -12099,10 +12582,10 @@ soap_s2double(struct soap *soap, const char *s, double *p) #endif { #if defined(HAVE_SSCANF_L) && !defined(HAVE_STRTOF_L) && !defined(HAVE_STRTOD_L) - if (sscanf_l(s, soap->c_locale, "%lg", p) != 1) + if (sscanf_l(s, soap->c_locale, "%lf", p) != 1) soap->error = SOAP_TYPE; #elif defined(HAVE_SSCANF) - if (sscanf(s, "%lg", p) != 1) + if (sscanf(s, "%lf", p) != 1) soap->error = SOAP_TYPE; #else soap->error = SOAP_TYPE; @@ -12370,7 +12853,12 @@ SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedLong2s(struct soap *soap, unsigned long n) -{ sprintf(soap->tmpbuf, "%lu", n); +{ +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "%lu", n); +#else + sprintf(soap->tmpbuf, "%lu", n); +#endif return soap->tmpbuf; } #endif @@ -12453,7 +12941,12 @@ SOAP_FMAC1 const char* SOAP_FMAC2 soap_ULONG642s(struct soap *soap, ULONG64 n) -{ sprintf(soap->tmpbuf, SOAP_ULONG_FORMAT, n); +{ +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), SOAP_ULONG_FORMAT, n); +#else + sprintf(soap->tmpbuf, SOAP_ULONG_FORMAT, n); +#endif return soap->tmpbuf; } #endif @@ -12590,8 +13083,8 @@ soap_s2QName(struct soap *soap, const char *s, char **t, long minlen, long maxle while (s[n] && !soap_blank((soap_wchar)s[n])) n++; np = soap->nlist; - /* if there is no namespace stack, or prefix is "xml" then copy string */ - if (!np || !strncmp(s, "xml:", 4)) + /* if there is no namespace stack, or prefix is "#" or "xml" then copy string */ + if (!np || *s == '#' || !strncmp(s, "xml:", 4)) { soap_append_lab(soap, s, n); } else /* we normalize the QName by replacing its prefix */ @@ -12628,7 +13121,7 @@ soap_s2QName(struct soap *soap, const char *s, char **t, long minlen, long maxle soap_append_lab(soap, "\"", 1); } else - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "\nNamespace prefix of '%s' not defined (index=%d, URI=%s)\n", s, np->index, np->ns ? np->ns : SOAP_STR_EOS)); + { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "\nNamespace prefix of '%s' not defined (index=%d, URI='%s')\n", s, np->index, np->ns ? np->ns : SOAP_STR_EOS)); return soap->error = SOAP_NAMESPACE; } } @@ -12676,11 +13169,19 @@ soap_QName2s(struct soap *soap, const char *s) n++; /* normal prefix: pass string as is */ if (*s != '"') - { soap_append_lab(soap, s, n); + { #ifndef WITH_LEAN if ((soap->mode & SOAP_XML_CANONICAL)) soap_utilize_ns(soap, s); + if ((soap->mode & SOAP_XML_DEFAULTNS)) + { const char *r = strchr(s, ':'); + if (r && soap->nlist && !strncmp(soap->nlist->id, s, r-s) && !soap->nlist->id[r-s]) + { n -= r-s + 1; + s = r + 1; + } + } #endif + soap_append_lab(soap, s, n); } else /* URL-based string prefix */ { const char *q; @@ -12700,12 +13201,22 @@ soap_QName2s(struct soap *soap, const char *s) } /* URL is in the namespace table? */ if (p && p->id) - { soap_append_lab(soap, p->id, strlen(p->id)); + { const char *r = p->id; +#ifndef WITH_LEAN + if ((soap->mode & SOAP_XML_DEFAULTNS) && soap->nlist && !strcmp(soap->nlist->id, r)) + q++; + else +#endif + soap_append_lab(soap, r, strlen(r)); } else /* not in namespace table: create xmlns binding */ { char *r = soap_strdup(soap, s); r[q-s] = '\0'; +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "xmlns:_%d", soap->idnum++); +#else sprintf(soap->tmpbuf, "xmlns:_%d", soap->idnum++); +#endif soap_set_attr(soap, soap->tmpbuf, r, 1); soap_append_lab(soap, soap->tmpbuf + 6, strlen(soap->tmpbuf + 6)); } @@ -13004,6 +13515,20 @@ soap_dateTime2s(struct soap *soap, time_t n) #elif defined(HAVE_GMTIME) if ((pT = gmtime(&n))) strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%SZ", pT); +#elif defined(HAVE_TM_GMTOFF) || defined(HAVE_STRUCT_TM_TM_GMTOFF) || defined(HAVE_STRUCT_TM___TM_GMTOFF) +#if defined(HAVE_LOCALTIME_R) + if (localtime_r(&n, pT)) + { strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S%z", pT); + memmove(soap->tmpbuf + 23, soap->tmpbuf + 22, 3); /* 2000-03-01T02:00:00+0300 */ + soap->tmpbuf[22] = ':'; /* 2000-03-01T02:00:00+03:00 */ + } +#else + if ((pT = localtime(&n))) + { strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S%z", pT); + memmove(soap->tmpbuf + 23, soap->tmpbuf + 22, 3); /* 2000-03-01T02:00:00+0300 */ + soap->tmpbuf[22] = ':'; /* 2000-03-01T02:00:00+03:00 */ + } +#endif #elif defined(HAVE_GETTIMEOFDAY) struct timezone tz; memset((void*)&tz, 0, sizeof(tz)); @@ -13012,14 +13537,22 @@ soap_dateTime2s(struct soap *soap, time_t n) { struct timeval tv; gettimeofday(&tv, &tz); strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT); +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf + strlen(soap->tmpbuf), sizeof(soap->tmpbuf) - strlen(soap->tmpbuf), "%+03d:%02d", -tz.tz_minuteswest/60+(pT->tm_isdst!=0), abs(tz.tz_minuteswest)%60); +#else sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -tz.tz_minuteswest/60+(pT->tm_isdst!=0), abs(tz.tz_minuteswest)%60); +#endif } #else if ((pT = localtime(&n))) { struct timeval tv; gettimeofday(&tv, &tz); strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT); +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf + strlen(soap->tmpbuf), sizeof(soap->tmpbuf) - strlen(soap->tmpbuf), "%+03d:%02d", -tz.tz_minuteswest/60+(pT->tm_isdst!=0), abs(tz.tz_minuteswest)%60); +#else sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -tz.tz_minuteswest/60+(pT->tm_isdst!=0), abs(tz.tz_minuteswest)%60); +#endif } #endif #elif defined(HAVE_FTIME) @@ -13034,7 +13567,11 @@ soap_dateTime2s(struct soap *soap, time_t n) ftime(&t); #endif strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT); +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf + strlen(soap->tmpbuf), sizeof(soap->tmpbuf) - strlen(soap->tmpbuf), "%+03d:%02d", -t.timezone/60+(pT->tm_isdst!=0), abs(t.timezone)%60); +#else sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -t.timezone/60+(pT->tm_isdst!=0), abs(t.timezone)%60); +#endif } #else if ((pT = localtime(&n))) @@ -13045,7 +13582,11 @@ soap_dateTime2s(struct soap *soap, time_t n) ftime(&t); #endif strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT); +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf + strlen(soap->tmpbuf), sizeof(soap->tmpbuf) - strlen(soap->tmpbuf), "%+03d:%02d", -t.timezone/60+(pT->tm_isdst!=0), abs(t.timezone)%60); +#else sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -t.timezone/60+(pT->tm_isdst!=0), abs(t.timezone)%60); +#endif } #endif #elif defined(HAVE_LOCALTIME_R) @@ -13189,8 +13730,11 @@ soap_outliteral(struct soap *soap, const char *tag, char *const*p, const char *t const char *t = NULL; if (tag && *tag != '-') { if (soap->local_namespaces && (t = strchr(tag, ':'))) - { strncpy(soap->tmpbuf, tag, t-tag); - soap->tmpbuf[t-tag] = '\0'; + { size_t n = t - tag; + if (n >= sizeof(soap->tmpbuf)) + n = sizeof(soap->tmpbuf) - 1; + strncpy(soap->tmpbuf, tag, n); + soap->tmpbuf[n] = '\0'; for (i = 0; soap->local_namespaces[i].id; i++) if (!strcmp(soap->tmpbuf, soap->local_namespaces[i].id)) break; @@ -13207,7 +13751,7 @@ soap_outliteral(struct soap *soap, const char *tag, char *const*p, const char *t } } if (p && *p) - { if (soap_send(soap, *p)) + { if (soap_send(soap, *p)) /* send as-is */ return soap->error; } if (t) @@ -13261,8 +13805,11 @@ soap_outwliteral(struct soap *soap, const char *tag, wchar_t *const*p, const cha const char *t = NULL; if (tag && *tag != '-') { if (soap->local_namespaces && (t = strchr(tag, ':'))) - { strncpy(soap->tmpbuf, tag, t-tag); - soap->tmpbuf[t-tag] = '\0'; + { size_t n = t - tag; + if (n >= sizeof(soap->tmpbuf)) + n = sizeof(soap->tmpbuf) - 1; + strncpy(soap->tmpbuf, tag, n); + soap->tmpbuf[n] = '\0'; for (i = 0; soap->local_namespaces[i].id; i++) if (!strcmp(soap->tmpbuf, soap->local_namespaces[i].id)) break; @@ -13277,14 +13824,12 @@ soap_outwliteral(struct soap *soap, const char *tag, wchar_t *const*p, const cha if (soap_element_begin_out(soap, t, 0, type)) return soap->error; } - if (soap_send(soap, soap->tmpbuf)) - return soap->error; } if (p) { wchar_t c; const wchar_t *s = *p; while ((c = *s++)) - { if (soap_pututf8(soap, (unsigned long)c)) + { if (soap_pututf8(soap, (unsigned long)c)) /* send as-is in UTF8 */ return soap->error; } } @@ -13359,6 +13904,7 @@ soap_value(struct soap *soap) break; } s[1] = '\0'; + soap->tmpbuf[sizeof(soap->tmpbuf) - 1] = '\0'; /* appease */ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element content value='%s'\n", soap->tmpbuf)); if (c == SOAP_TT || c == SOAP_LT || (int)c == EOF) soap_unget(soap, c); @@ -13392,11 +13938,11 @@ soap_getline(struct soap *soap, char *s, int len) return soap->error = SOAP_CHK_EOF; *s++ = (char)c; } + *s = '\0'; if (c != '\n') c = soap_getchar(soap); /* got \r or something else, now get \n */ if (c == '\n') - { *s = '\0'; - if (i+1 == len) /* empty line: end of HTTP/MIME header */ + { if (i + 1 == len) /* empty line: end of HTTP/MIME header */ break; c = soap_get0(soap); if (c != ' ' && c != '\t') /* HTTP line continuation? */ @@ -13404,7 +13950,7 @@ soap_getline(struct soap *soap, char *s, int len) } else if ((int)c == EOF) return soap->error = SOAP_CHK_EOF; - if (i < 0) + if (i <= 0) return soap->error = SOAP_HDR; } return SOAP_OK; @@ -13464,7 +14010,7 @@ soap_count_attachments(struct soap *soap) /* count \r\n--boundary-- */ count += 6 + n; } - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "New count is %lu bytes\n", (unsigned long)count)); + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "New count=%lu\n", (unsigned long)count)); return count; #else return soap->count; @@ -13662,7 +14208,7 @@ soap_getdimefield(struct soap *soap, size_t n) *s++ = (char)c; } *s = '\0'; - if ((soap->error = soap_move(soap, -(long)n&3))) + if ((soap->error = soap_move(soap, (size_t)(-(long)n&3)))) return NULL; } else @@ -13689,7 +14235,7 @@ soap_getdimehdr(struct soap *soap) return soap->error = SOAP_DIME_END; DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get DIME header\n")); if (soap->dime.buflen || soap->dime.chunksize) - { if (soap_move(soap, (long)(soap->dime.size - soap_tell(soap)))) + { if (soap_move(soap, soap->dime.size - soap_tell(soap))) return soap->error = SOAP_CHK_EOF; soap_unget(soap, soap_getchar(soap)); /* skip padding and get hdr */ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "... From chunked\n")); @@ -13707,7 +14253,7 @@ soap_getdimehdr(struct soap *soap) optlen = (tmp[2] << 8) | tmp[3]; idlen = (tmp[4] << 8) | tmp[5]; typelen = (tmp[6] << 8) | tmp[7]; - soap->dime.size = (tmp[8] << 24) | (tmp[9] << 16) | (tmp[10] << 8) | tmp[11]; + soap->dime.size = ((size_t)tmp[8] << 24) | ((size_t)tmp[9] << 16) | ((size_t)tmp[10] << 8) | ((size_t)tmp[11]); DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DIME size=%lu flags=0x%X\n", (unsigned long)soap->dime.size, soap->dime.flags)); if (!(soap->dime.options = soap_getdimefield(soap, optlen)) && soap->error) return soap->error; @@ -13715,7 +14261,7 @@ soap_getdimehdr(struct soap *soap) return soap->error; if (!(soap->dime.type = soap_getdimefield(soap, typelen)) && soap->error) return soap->error; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DIME id=%s, type=%s, options=%s\n", soap->dime.id ? soap->dime.id : SOAP_STR_EOS, soap->dime.type ? soap->dime.type : "", soap->dime.options ? soap->dime.options+4 : SOAP_STR_EOS)); + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DIME id='%s', type='%s', options='%s'\n", soap->dime.id ? soap->dime.id : SOAP_STR_EOS, soap->dime.type ? soap->dime.type : "", soap->dime.options ? soap->dime.options+4 : SOAP_STR_EOS)); if (soap->dime.flags & SOAP_DIME_ME) soap->mode &= ~SOAP_ENC_DIME; return SOAP_OK; @@ -13733,10 +14279,10 @@ soap_getdime(struct soap *soap) { while (soap->dime.flags & SOAP_DIME_CF) { if (soap_getdimehdr(soap)) return soap->error; - if (soap_move(soap, (long)soap->dime.size)) + if (soap_move(soap, soap->dime.size)) return soap->error = SOAP_EOF; } - if (soap_move(soap, (long)(((soap->dime.size+3)&(~3))-soap_tell(soap)))) + if (soap_move(soap, (size_t)(((soap->dime.size+3)&(~3)) - soap_tell(soap)))) return soap->error = SOAP_EOF; for (;;) { register struct soap_multipart *content; @@ -13768,7 +14314,7 @@ soap_getdime(struct soap *soap) goto end; } } - if (soap_move(soap, -(long)soap->dime.size&3)) + if (soap_move(soap, (size_t)(-(long)soap->dime.size&3))) { soap->error = SOAP_EOF; break; } @@ -13796,6 +14342,10 @@ end: { register soap_wchar c; register size_t i; register char *s; + if (soap->dime.size > SOAP_MAXDIMESIZE) + { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DIME size=%lu exceeds SOAP_MAXDIMESIZE=%lu\n", (unsigned long)soap->dime.size, (unsigned long)SOAP_MAXDIMESIZE)); + return soap->error = SOAP_DIME_ERROR; + } s = (char*)soap_push_block(soap, NULL, soap->dime.size); if (!s) return soap->error = SOAP_EOM; @@ -13804,17 +14354,17 @@ end: return soap->error = SOAP_EOF; *s++ = (char)c; } - if (soap_move(soap, -(long)soap->dime.size&3)) + if (soap_move(soap, (size_t)(-(long)soap->dime.size&3))) return soap->error = SOAP_EOF; if (!(soap->dime.flags & SOAP_DIME_CF)) break; if (soap_getdimehdr(soap)) return soap->error; } - soap->dime.size = soap->blist->size++; /* allocate one more for '\0' */ + soap->dime.size = soap->blist->size++; /* allocate one more byte in blist for the terminating '\0' */ if (!(soap->dime.ptr = soap_save_block(soap, NULL, NULL, 0))) return soap->error; - soap->dime.ptr[soap->dime.size] = '\0'; /* force 0-terminated */ + soap->dime.ptr[soap->dime.size] = '\0'; /* make 0-terminated */ soap->dime.id = id; soap->dime.type = type; soap->dime.options = options; @@ -13967,7 +14517,7 @@ soap_get_mime_attachment(struct soap *soap, void *handle) return NULL; } } - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Parsing MIME content id=%s type=%s\n", content->id ? content->id : SOAP_STR_EOS, content->type ? content->type : SOAP_STR_EOS)); + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Parsing MIME content id='%s' type='%s'\n", content->id ? content->id : SOAP_STR_EOS, content->type ? content->type : SOAP_STR_EOS)); if (!content->ptr && soap_new_block(soap) == NULL) { soap->error = SOAP_EOM; return NULL; @@ -13988,7 +14538,9 @@ soap_get_mime_attachment(struct soap *soap, void *handle) { if (!flag) { c = soap_get1(soap); if ((int)c == EOF) - { soap->error = SOAP_CHK_EOF; + { if (content->ptr && soap->fmimewriteclose) + soap->fmimewriteclose(soap, (void*)content->ptr); + soap->error = SOAP_CHK_EOF; return NULL; } } @@ -14001,7 +14553,9 @@ soap_get_mime_attachment(struct soap *soap, void *handle) do c = soap_getchar(soap); while (c == *t++); if ((int)c == EOF) - { soap->error = SOAP_CHK_EOF; + { if (content->ptr && soap->fmimewriteclose) + soap->fmimewriteclose(soap, (void*)content->ptr); + soap->error = SOAP_CHK_EOF; return NULL; } if (!*--t) @@ -14021,7 +14575,7 @@ soap_get_mime_attachment(struct soap *soap, void *handle) } } end: - *s = '\0'; /* force 0-terminated */ + *s = '\0'; /* make 0-terminated */ if (content->ptr) { if (!soap->error && soap->fmimewrite) soap->error = soap->fmimewrite(soap, (void*)content->ptr, soap->tmpbuf, i); @@ -14031,7 +14585,7 @@ end: return NULL; } else - { content->size = soap_size_block(soap, NULL, i+1)-1; + { content->size = soap_size_block(soap, NULL, i+1) - 1; /* last block with '\0' */ content->ptr = soap_save_block(soap, NULL, NULL, 0); } soap_resolve_attachment(soap, content); @@ -14095,11 +14649,11 @@ static void soap_resolve_attachment(struct soap *soap, struct soap_multipart *content) { if (content->id) { register struct soap_xlist **xp = &soap->xlist; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving attachment data for id=%s\n", content->id)); + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving attachment data for id='%s'\n", content->id)); while (*xp) { register struct soap_xlist *xq = *xp; if (!soap_match_cid(soap, xq->id, content->id)) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Found matching attachment %s for content id=%s\n", xq->id, content->id)); + { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Found matching attachment id='%s' for content id='%s'\n", xq->id, content->id)); *xp = xq->next; *xq->ptr = (unsigned char*)content->ptr; *xq->size = (int)content->size; @@ -14126,7 +14680,7 @@ int SOAP_FMAC2 soap_putmimehdr(struct soap *soap, struct soap_multipart *content) { const char *s; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "MIME attachment type=%s\n", content->type ? content->type : SOAP_STR_EOS)); + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "MIME attachment type='%s'\n", content->type ? content->type : SOAP_STR_EOS)); if (soap_send3(soap, "\r\n--", soap->mime.boundary, "\r\n")) return soap->error; if (content->type && soap_send3(soap, "Content-Type: ", content->type, "\r\n")) @@ -14489,7 +15043,7 @@ int SOAP_FMAC2 soap_begin_recv(struct soap *soap) { register soap_wchar c; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing for input\n")); + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing for input from socket=%d/fd=%d\n", soap->socket, soap->recvfd)); soap->error = SOAP_OK; soap->filterstop = SOAP_OK; soap_free_temp(soap); @@ -14513,6 +15067,7 @@ soap_begin_recv(struct soap *soap) soap->level = 0; soap->part = SOAP_BEGIN; soap->alloced = 0; + soap->body = 1; soap->count = 0; soap->length = 0; soap->cdata = 0; @@ -14625,8 +15180,8 @@ soap_begin_recv(struct soap *soap) return soap->error = SOAP_CHK_EOF; soap_unget(soap, c); #ifndef WITH_NOHTTP - /* if not XML or MIME/DIME/ZLIB, assume HTTP header */ - if (c != '<' && !(soap->mode & (SOAP_ENC_MIME | SOAP_ENC_DIME | SOAP_ENC_ZLIB))) + /* if not XML/MIME/DIME/ZLIB, assume HTTP method or status line */ + if (((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) && !(soap->mode & (SOAP_ENC_MIME | SOAP_ENC_DIME | SOAP_ENC_ZLIB | SOAP_ENC_XML))) { soap_mode m = soap->imode; soap->mode &= ~SOAP_IO; soap->error = soap->fparse(soap); @@ -14653,17 +15208,19 @@ soap_begin_recv(struct soap *soap) soap->chunksize = 0; } /* Note: fparse should not use soap_unget to push back last char */ - if (soap_get0(soap) == (int)EOF) - { if (soap->status == 200) - return soap->error = SOAP_NO_DATA; /* HTTP OK: always expect data */ +#if 0 + if (soap->status > 200 && soap->length == 0 && !(soap->http_content && (!soap->keep_alive || soap->recv_timeout)) && (soap->imode & SOAP_IO) != SOAP_IO_CHUNK) +#endif + if (soap->status && !soap->body) return soap->error = soap->status; - } #ifdef WITH_ZLIB if (soap->zlib_in != SOAP_ZLIB_NONE) { #ifdef WITH_GZIP if (soap->zlib_in != SOAP_ZLIB_DEFLATE) { c = soap_get1(soap); + if (c == (int)EOF) + return soap->error = SOAP_EOF; if (c == 0x1F) { if (soap_getgziphdr(soap)) return soap->error; @@ -14702,10 +15259,16 @@ soap_begin_recv(struct soap *soap) #ifndef WITH_LEANER if (soap->fpreparerecv && (soap->mode & SOAP_IO) != SOAP_IO_CHUNK && soap->buflen > soap->bufidx) { int r; + DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Invoking fpreparerecv\n")); if ((r = soap->fpreparerecv(soap, soap->buf + soap->bufidx, soap->buflen - soap->bufidx))) return soap->error = r; } #endif + if (soap_get0(soap) == (int)EOF) + { if (soap->status == 0 || soap->status == 200) + return soap->error = SOAP_NO_DATA; /* HTTP OK: always expect data */ + return soap->error = soap->status; + } if (soap->error) { if (soap->error == SOAP_FORM && soap->fform) { soap->error = soap->fform(soap); @@ -14779,7 +15342,11 @@ soap_envelope_begin_out(struct soap *soap) s = "application/xop+xml; charset=utf-8; type=\"text/xml\""; else s = "text/xml; charset=utf-8"; +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "--%s\r\nContent-Type: %s\r\nContent-Transfer-Encoding: binary\r\nContent-ID: %s\r\n\r\n", soap->mime.boundary, s, soap->mime.start); +#else sprintf(soap->tmpbuf, "--%s\r\nContent-Type: %s\r\nContent-Transfer-Encoding: binary\r\nContent-ID: %s\r\n\r\n", soap->mime.boundary, s, soap->mime.start); +#endif n = strlen(soap->tmpbuf); if (soap_send_raw(soap, soap->tmpbuf, n)) return soap->error; @@ -14791,6 +15358,8 @@ soap_envelope_begin_out(struct soap *soap) return soap->error; } #endif + if (soap->version == 0) + return SOAP_OK; soap->part = SOAP_IN_ENVELOPE; return soap_element_begin_out(soap, "SOAP-ENV:Envelope", 0, NULL); } @@ -14802,13 +15371,19 @@ SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_end_out(struct soap *soap) -{ if (soap_element_end_out(soap, "SOAP-ENV:Envelope") +{ if (soap->version == 0) + return SOAP_OK; + if (soap_element_end_out(soap, "SOAP-ENV:Envelope") || soap_send_raw(soap, "\r\n", 2)) /* 2.8: always emit \r\n */ return soap->error; #ifndef WITH_LEANER if ((soap->mode & SOAP_IO_LENGTH) && (soap->mode & SOAP_ENC_DIME) && !(soap->mode & SOAP_ENC_MTOM)) { soap->dime.size = soap->count - soap->dime.size; /* DIME in MIME correction */ +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->id, sizeof(soap->id), soap->dime_id_format, 0); +#else sprintf(soap->id, soap->dime_id_format, 0); +#endif soap->dime.id = soap->id; if (soap->local_namespaces) { if (soap->local_namespaces[0].out) @@ -14836,17 +15411,19 @@ soap_envelope_end_out(struct soap *soap) SOAP_FMAC1 char* SOAP_FMAC2 -soap_get_http_body(struct soap *soap) -{ +soap_get_http_body(struct soap *soap, size_t *len) +{ if (len) + *len = 0; #ifndef WITH_LEAN register size_t l = 0, n = 0; register char *s; - /* get HTML body of HTTP error content */ + /* get HTTP body length */ if (!(soap->mode & SOAP_ENC_ZLIB) && (soap->mode & SOAP_IO) != SOAP_IO_CHUNK) { n = soap->length; if (!n) return NULL; } + DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Parsing HTTP body (mode=0x%x,len=%lu)\n", soap->mode, (unsigned long)n)); #ifdef WITH_FAST soap->labidx = 0; /* use look-aside buffer */ #else @@ -14872,7 +15449,7 @@ soap_get_http_body(struct soap *soap) l++; if (n > 0 && l > n) goto end; - c = soap_getchar(soap); + c = soap_get1(soap); if ((int)c == EOF) goto end; *s++ = (char)(c & 0xFF); @@ -14880,8 +15457,11 @@ soap_get_http_body(struct soap *soap) } end: *s = '\0'; + if (len) + *len = l - 1; /* len excludes terminating \0 */ #ifdef WITH_FAST - s = soap_strdup(soap, soap->labbuf); + if ((s = (char*)soap_malloc(soap, l))) + memcpy(s, soap->labbuf, l); #else soap_size_block(soap, NULL, i+1); s = soap_save_block(soap, NULL, 0); @@ -14903,9 +15483,13 @@ soap_envelope_begin_in(struct soap *soap) { register struct Namespace *p; soap->part = SOAP_IN_ENVELOPE; if (soap_element_begin_in(soap, "SOAP-ENV:Envelope", 0, NULL)) - { if (soap->error == SOAP_TAG_MISMATCH - && !soap_element_begin_in(soap, "Envelope", 0, NULL)) - soap->error = SOAP_VERSIONMISMATCH; + { if (soap->error == SOAP_TAG_MISMATCH) + { if (!soap_element_begin_in(soap, "Envelope", 0, NULL)) + soap->error = SOAP_VERSIONMISMATCH; + else if (soap->status == 0 || (soap->status >= 200 && soap->status <= 299)) + return SOAP_OK; /* allow non-SOAP XML content to be captured */ + soap->error = soap->status; + } else if (soap->status) soap->error = soap->status; return soap->error; @@ -14940,7 +15524,9 @@ SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_end_in(struct soap *soap) -{ soap->part = SOAP_END_ENVELOPE; +{ if (soap->version == 0) + return SOAP_OK; + soap->part = SOAP_END_ENVELOPE; return soap_element_end_in(soap, "SOAP-ENV:Envelope"); } #endif @@ -14951,13 +15537,15 @@ SOAP_FMAC1 int SOAP_FMAC2 soap_body_begin_out(struct soap *soap) -{ soap->part = SOAP_IN_BODY; - if (soap->version == 1) +{ if (soap->version == 1) soap->encoding = 1; #ifndef WITH_LEAN if ((soap->mode & SOAP_SEC_WSUID) && soap_set_attr(soap, "wsu:Id", "Body", 1)) return soap->error; #endif + if (soap->version == 0) + return SOAP_OK; + soap->part = SOAP_IN_BODY; return soap_element_begin_out(soap, "SOAP-ENV:Body", 0, NULL); } #endif @@ -14968,7 +15556,9 @@ SOAP_FMAC1 int SOAP_FMAC2 soap_body_end_out(struct soap *soap) -{ if (soap_element_end_out(soap, "SOAP-ENV:Body")) +{ if (soap->version == 0) + return SOAP_OK; + if (soap_element_end_out(soap, "SOAP-ENV:Body")) return soap->error; soap->part = SOAP_END_BODY; return SOAP_OK; @@ -14981,7 +15571,9 @@ SOAP_FMAC1 int SOAP_FMAC2 soap_body_begin_in(struct soap *soap) -{ soap->part = SOAP_IN_BODY; +{ if (soap->version == 0) + return SOAP_OK; + soap->part = SOAP_IN_BODY; if (soap_element_begin_in(soap, "SOAP-ENV:Body", 0, NULL)) return soap->error; if (!soap->body) @@ -14996,7 +15588,9 @@ SOAP_FMAC1 int SOAP_FMAC2 soap_body_end_in(struct soap *soap) -{ if (soap->part == SOAP_NO_BODY) +{ if (soap->version == 0) + return SOAP_OK; + if (soap->part == SOAP_NO_BODY) return soap->error = SOAP_OK; soap->part = SOAP_END_BODY; return soap_element_end_in(soap, "SOAP-ENV:Body"); @@ -15036,7 +15630,7 @@ soap_set_endpoint(struct soap *soap, const char *endpoint) if (!soap_tag_cmp(endpoint, "https:*")) soap->port = 443; #endif - strncpy(soap->endpoint, endpoint, sizeof(soap->endpoint) - 1); + strncpy(soap->endpoint, endpoint, sizeof(soap->endpoint)); soap->endpoint[sizeof(soap->endpoint) - 1] = '\0'; s = strchr(endpoint, ':'); if (s && s[1] == '/' && s[2] == '/') @@ -15198,7 +15792,7 @@ soap_try_connect_command(struct soap *soap, int http_command, const char *endpoi soap->mode = k; } if (http_command == SOAP_GET || http_command == SOAP_DEL) - return soap_end_send(soap); + return soap_end_send_flush(soap); #endif return SOAP_OK; } @@ -15222,6 +15816,8 @@ soap_ntlm_handshake(struct soap *soap, int command, const char *endpoint, const size_t c = soap->count; soap_mode m = soap->mode, o = soap->omode; int s = soap->status; + char *a = soap->action; + short v = soap->version; DBGLOG(TEST,SOAP_MESSAGE(fdebug, "NTLM '%s'\n", soap->ntlm_challenge)); if (!*soap->ntlm_challenge) { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "NTLM S->C Type 1: received NTLM authentication challenge from server\n")); @@ -15240,7 +15836,7 @@ soap_ntlm_handshake(struct soap *soap, int command, const char *endpoint, const soap->keep_alive = 1; soap->status = command; if (soap->fpost(soap, endpoint, host, port, soap->path, soap->action, 0) - || soap_end_send(soap)) + || soap_end_send_flush(soap)) return soap->error; soap->mode = m; soap->keep_alive = k; @@ -15248,7 +15844,7 @@ soap_ntlm_handshake(struct soap *soap, int command, const char *endpoint, const oldheader = soap->header; if (soap_begin_recv(soap)) if (soap->error == SOAP_EOF) - return soap->error; + return soap->error; soap_end_recv(soap); soap->header = oldheader; soap->length = l; @@ -15266,12 +15862,18 @@ soap_ntlm_handshake(struct soap *soap, int command, const char *endpoint, const /* C -> S GET ... Authorization: NTLM TlRMTVNTUAADAAAAGAAYAHIAAAAYABgAigAAABQAFABAAAAADAAMAFQAAAASABIAYAAAAAAAAACiAAAAAYIAAFUAUgBTAEEALQBNAEkATgBPAFIAWgBhAHAAaABvAGQATABJAEcASABUAEMASQBUAFkArYfKbe/jRoW5xDxHeoxC1gBmfWiS5+iX4OAN4xBKG/IFPwfH3agtPEia6YnhsADT */ + soap->userid = NULL; + soap->passwd = NULL; + soap->proxy_userid = NULL; + soap->proxy_passwd = NULL; soap->keep_alive = k; soap->length = l; soap->count = c; soap->mode = m; soap->omode = o; soap->status = s; + soap->action = a; + soap->version = v; } return SOAP_OK; } @@ -15304,13 +15906,13 @@ soap_s2base64(struct soap *soap, const unsigned char *s, char *t, int n) t += 4; } t[0] = '\0'; - if (n > 0) + if (n > 0) /* 0 < n <= 2 implies that t[0..4] is allocated (base64 scaling formula) */ { m = 0; for (i = 0; i < n; i++) m = (m << 8) | *s++; for (; i < 3; i++) m <<= 8; - for (i++; i > 0; m >>= 6) + for (i = 4; i > 0; m >>= 6) t[--i] = soap_base64o[m & 0x3F]; for (i = 3; i > n; i--) t[i] = '='; @@ -15346,58 +15948,57 @@ soap_base642s(struct soap *soap, const char *s, char *t, size_t l, int *n) p = t; if (n) *n = 0; - for (;;) - { for (i = 0; i < SOAP_BLKLEN; i++) - { m = 0; - j = 0; - while (j < 4) - { c = *s++; - if (c == '=' || !c) - { i *= 3; - switch (j) + for (i = 0; ; i += 3, l -= 3) + { m = 0; + j = 0; + while (j < 4) + { c = *s++; + if (c == '=' || !c) + { if (l >= j - 1) + { switch (j) { case 2: *t++ = (char)((m >> 4) & 0xFF); i++; + l--; break; case 3: *t++ = (char)((m >> 10) & 0xFF); *t++ = (char)((m >> 2) & 0xFF); i += 2; + l -= 2; } - if (n) - *n += (int)i; - if (l >= j) - *t = '\0'; - return p; - } - c -= '+'; - if (c >= 0 && c <= 79) - { int b = soap_base64i[c]; - if (b >= 64) - { soap->error = SOAP_TYPE; - return NULL; - } - m = (m << 6) + b; - j++; } - else if (!soap_blank(c + '+')) + if (n) + *n = (int)i; + if (l) + *t = '\0'; + return p; + } + c -= '+'; + if (c >= 0 && c <= 79) + { int b = soap_base64i[c]; + if (b >= 64) { soap->error = SOAP_TYPE; return NULL; } + m = (m << 6) + b; + j++; } - if (l < 3) - { if (n) - *n += (int)i; - *t = '\0'; - return p; + else if (!soap_blank(c + '+')) + { soap->error = SOAP_TYPE; + return NULL; } - *t++ = (char)((m >> 16) & 0xFF); - *t++ = (char)((m >> 8) & 0xFF); - *t++ = (char)(m & 0xFF); - l -= 3; } - if (n) - *n += 3 * SOAP_BLKLEN; + if (l < 3) + { if (n) + *n = (int)i; + if (l) + *t = '\0'; + return p; + } + *t++ = (char)((m >> 16) & 0xFF); + *t++ = (char)((m >> 8) & 0xFF); + *t++ = (char)(m & 0xFF); } } #endif @@ -15481,7 +16082,7 @@ soap_puthttphdr(struct soap *soap, int status, size_t count) #ifndef WITH_LEANER register const char *r = NULL; #endif - if ((status == SOAP_FILE || soap->status == SOAP_PUT || soap->status == SOAP_POST_FILE) && soap->http_content) + if ((status == SOAP_FILE || soap->status == SOAP_PUT || soap->status == SOAP_POST_FILE) && soap->http_content && !strchr(s, 10) && !strchr(s, 13)) s = soap->http_content; else if (status == SOAP_HTML) s = "text/html; charset=utf-8"; @@ -15502,31 +16103,42 @@ soap_puthttphdr(struct soap *soap, int status, size_t count) s = "application/dime"; } if ((soap->mode & SOAP_ENC_MIME) && soap->mime.boundary && strlen(soap->mime.boundary) + strlen(soap->mime.start ? soap->mime.start : SOAP_STR_EOS) < sizeof(soap->tmpbuf) - 80) - { register const char *t = strchr(s, ';'); + { register const char *t; +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "multipart/related; charset=utf-8; boundary=\"%s\"; type=\"", soap->mime.boundary); +#else sprintf(soap->tmpbuf, "multipart/related; charset=utf-8; boundary=\"%s\"; type=\"", soap->mime.boundary); +#endif + t = strchr(s, ';'); if (t) - { strncat(soap->tmpbuf, s, t - s); - soap->tmpbuf[sizeof(soap->tmpbuf)-1] = '\0'; - } + strncat(soap->tmpbuf, s, t - s); else strcat(soap->tmpbuf, s); - if (soap->mime.start) + if (soap->mime.start && strlen(soap->tmpbuf) + strlen(soap->mime.start) + 11 < sizeof(soap->tmpbuf)) { strcat(soap->tmpbuf, "\"; start=\""); strcat(soap->tmpbuf, soap->mime.start); } strcat(soap->tmpbuf, "\""); - if (r) + if (r && strlen(soap->tmpbuf) + strlen(r) + 15 < sizeof(soap->tmpbuf)) { strcat(soap->tmpbuf, "; start-info=\""); strcat(soap->tmpbuf, r); strcat(soap->tmpbuf, "\""); } - s = soap->tmpbuf; } else - s = strcpy(soap->tmpbuf, s); + strncpy(soap->tmpbuf, s, sizeof(soap->tmpbuf)); + soap->tmpbuf[sizeof(soap->tmpbuf) - 1] = '\0'; + s = soap->tmpbuf; if (status == SOAP_OK && soap->version == 2 && soap->action && strlen(soap->action) + strlen(s) < sizeof(soap->tmpbuf) - 80) + { +#ifdef HAVE_SNPRINTF + size_t l = strlen(s); + soap_snprintf(soap->tmpbuf + l, sizeof(soap->tmpbuf) - l, "; action=\"%s\"", soap->action); +#else sprintf(soap->tmpbuf + strlen(s), "; action=\"%s\"", soap->action); #endif + } +#endif if ((err = soap->fposthdr(soap, "Content-Type", s))) return err; #ifdef WITH_ZLIB @@ -15547,7 +16159,12 @@ soap_puthttphdr(struct soap *soap, int status, size_t count) else #endif if (s) - { sprintf(soap->tmpbuf, "%lu", (unsigned long)count); + { +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "%lu", (unsigned long)count); +#else + sprintf(soap->tmpbuf, "%lu", (unsigned long)count); +#endif err = soap->fposthdr(soap, "Content-Length", soap->tmpbuf); } if (err) @@ -15562,18 +16179,30 @@ soap_puthttphdr(struct soap *soap, int status, size_t count) #ifndef WITH_LEAN static const char* soap_set_validation_fault(struct soap *soap, const char *s, const char *t) -{ if (*soap->tag) +{ if (!t) + t = SOAP_STR_EOS; + if (*soap->tag) + { #ifdef HAVE_SNPRINTF soap_snprintf(soap->msgbuf, sizeof(soap->msgbuf), "Validation constraint violation: %s%s in element '%s'", s, t ? t : SOAP_STR_EOS, soap->tag); #else - sprintf(soap->msgbuf, "Validation constraint violation: %s%s in element '%s'", s, t ? t : SOAP_STR_EOS, soap->tag); + if (strlen(soap->tag) + strlen(t) < sizeof(soap->msgbuf) - 100) + sprintf(soap->msgbuf, "Validation constraint violation: %s%s in element '%s'", s, t, soap->tag); + else + sprintf(soap->msgbuf, "Validation constraint violation: %s", s); #endif + } else + { #ifdef HAVE_SNPRINTF soap_snprintf(soap->msgbuf, sizeof(soap->msgbuf), "Validation constraint violation: %s%s", s, t ? t : SOAP_STR_EOS); #else - sprintf(soap->msgbuf, "Validation constraint violation: %s%s", s, t ? t : SOAP_STR_EOS); + if (strlen(soap->tag) + strlen(t) < sizeof(soap->msgbuf) - 100) + sprintf(soap->msgbuf, "Validation constraint violation: %s%s", s, t); + else + sprintf(soap->msgbuf, "Validation constraint violation: %s", s); #endif + } return soap->msgbuf; } #endif @@ -15622,7 +16251,8 @@ soap_set_fault(struct soap *soap) #ifdef HAVE_SNPRINTF soap_snprintf(soap->msgbuf, sizeof(soap->msgbuf), "The data in element '%s' must be understood but cannot be handled", soap->tag); #else - sprintf(soap->msgbuf, "The data in element '%s' must be understood but cannot be handled", soap->tag); + strncpy(soap->msgbuf, soap->tag, sizeof(soap->msgbuf)); + soap->msgbuf[sizeof(soap->msgbuf) - 1] = '\0'; #endif *s = soap->msgbuf; break; @@ -15679,7 +16309,7 @@ soap_set_fault(struct soap *soap) *s = soap_set_validation_fault(soap, "nil not allowed", NULL); break; case SOAP_DUPLICATE_ID: - *s = soap_set_validation_fault(soap, "multiple definitions (use the SOAP_XML_TREE flag) of the same id ", soap->id); + *s = soap_set_validation_fault(soap, "multiple elements (use the SOAP_XML_TREE flag) with duplicate id ", soap->id); if (soap->version == 2) *soap_faultsubcode(soap) = "SOAP-ENC:DuplicateID"; break; @@ -15689,7 +16319,7 @@ soap_set_fault(struct soap *soap) *soap_faultsubcode(soap) = "SOAP-ENC:MissingID"; break; case SOAP_HREF: - *s = soap_set_validation_fault(soap, "incompatible object type ref/id pair ", soap->id); + *s = soap_set_validation_fault(soap, "incompatible object type id-ref ", soap->id); break; case SOAP_FAULT: break; @@ -15718,7 +16348,7 @@ soap_set_fault(struct soap *soap) *s = "Plugin registry error"; break; case SOAP_DIME_ERROR: - *s = "DIME format error"; + *s = "DIME format error or max DIME size exceeds SOAP_MAXDIMESIZE"; break; case SOAP_DIME_HREF: *s = "DIME href to missing attachment"; @@ -15774,14 +16404,13 @@ soap_set_fault(struct soap *soap) #endif case SOAP_EOF: #ifndef WITH_NOIO - strcpy(soap->msgbuf, soap_strerror(soap)); + *s = soap_strerror(soap); /* *s = soap->msgbuf */ #ifndef WITH_LEAN if (strlen(soap->msgbuf) + 25 < sizeof(soap->msgbuf)) { memmove(soap->msgbuf + 25, soap->msgbuf, strlen(soap->msgbuf) + 1); memcpy(soap->msgbuf, "End of file or no input: ", 25); } #endif - *s = soap->msgbuf; break; #else *s = "End of file or no input"; @@ -15802,7 +16431,12 @@ soap_set_fault(struct soap *soap) else #endif #endif - { sprintf(soap->msgbuf, "Error %d", soap->error); + { +#ifdef HAVE_SNPRINTF + soap_snprintf(soap->msgbuf, sizeof(soap->msgbuf), "Error %d", soap->error); +#else + sprintf(soap->msgbuf, "Error %d", soap->error); +#endif *s = soap->msgbuf; } } @@ -15816,7 +16450,7 @@ int SOAP_FMAC2 soap_send_fault(struct soap *soap) { register int status = soap->error; - if (status == SOAP_STOP) + if (status == SOAP_OK || status == SOAP_STOP) return soap_closesock(soap); DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Sending back fault struct for error code %d\n", soap->error)); soap->keep_alive = 0; /* to terminate connection */ @@ -15824,7 +16458,7 @@ soap_send_fault(struct soap *soap) if (soap->error < 200 && soap->error != SOAP_FAULT) soap->header = NULL; if (status != SOAP_EOF || (!soap->recv_timeout && !soap->send_timeout)) - { int r = 1; + { register int r = 1; #ifndef WITH_NOIO if (soap->fpoll && soap->fpoll(soap)) r = 0; @@ -15832,9 +16466,10 @@ soap_send_fault(struct soap *soap) else if (soap_valid_socket(soap->socket)) { r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_SND, 0); if (r > 0) - { if (!(r & SOAP_TCP_SELECT_SND) + { int t; + if (!(r & SOAP_TCP_SELECT_SND) || ((r & SOAP_TCP_SELECT_RCV) - && recv(soap->socket, soap->tmpbuf, 1, MSG_PEEK) < 0)) + && recv(soap->socket, (char*)&t, 1, MSG_PEEK) < 0)) r = 0; } } @@ -15842,6 +16477,7 @@ soap_send_fault(struct soap *soap) #endif if (r > 0) { soap->error = SOAP_OK; + soap->encodingStyle = NULL; /* no encodingStyle in Faults */ soap_serializeheader(soap); soap_serializefault(soap); soap_begin_count(soap); @@ -15884,6 +16520,8 @@ soap_recv_fault(struct soap *soap, int check) && (soap->error != SOAP_TAG_MISMATCH || soap->level != 2)) return soap->error; } + else if (soap->version == 0) /* check == 1 but no SOAP: do not parse SOAP Fault */ + return SOAP_OK; soap->error = SOAP_OK; if (soap_getfault(soap)) { /* check flag set: check if SOAP Fault is present, if not just return */ @@ -15929,8 +16567,9 @@ soap_send_empty_response(struct soap *soap, int httpstatuscode) { soap->count = 0; if ((m & SOAP_IO) == SOAP_IO_CHUNK) soap->omode = (m & ~SOAP_IO) | SOAP_IO_BUFFER; - if (!soap_response(soap, httpstatuscode) && !soap_end_send(soap)) - soap->error = SOAP_STOP; /* stops the server's processing of request */ + soap_response(soap, httpstatuscode); + soap_end_send(soap); /* force end of sends */ + soap->error = SOAP_STOP; /* stops the server (from returning a response) */ soap->omode = m; } return soap_closesock(soap); @@ -15947,7 +16586,13 @@ SOAP_FMAC2 soap_recv_empty_response(struct soap *soap) { if (!(soap->omode & SOAP_IO_UDP)) { if (!soap_begin_recv(soap)) + { +#ifndef WITH_LEAN + if (soap->body) + soap_get_http_body(soap, NULL); /* read (empty?) HTTP body and discard */ +#endif soap_end_recv(soap); + } else if (soap->error == SOAP_NO_DATA || soap->error == 202) soap->error = SOAP_OK; } @@ -15962,11 +16607,16 @@ soap_recv_empty_response(struct soap *soap) static const char* soap_strerror(struct soap *soap) { register int err = soap->errnum; + *soap->msgbuf = '\0'; if (err) { #ifndef WIN32 # ifdef HAVE_STRERROR_R - strerror_r(err, soap->msgbuf, sizeof(soap->msgbuf)); +# ifdef _GNU_SOURCE + return strerror_r(err, soap->msgbuf, sizeof(soap->msgbuf)); /* GNU-specific */ +# else + strerror_r(err, soap->msgbuf, sizeof(soap->msgbuf)); /* XSI-compliant */ +# endif # else return strerror(err); # endif @@ -16005,10 +16655,24 @@ soap_strerror(struct soap *soap) su = 'u'; } if (rt) - sprintf(s + strlen(s), " (%d%cs receive delay)", rt, ru); + { +#ifdef HAVE_SNPRINTF + size_t l = strlen(s); + soap_snprintf(s + l, sizeof(soap->msgbuf) - l, " (%d%cs recv delay)", rt, ru); +#else + sprintf(s + strlen(s), " (%d%cs recv delay)", rt, ru); +#endif + } if (st) + { +#ifdef HAVE_SNPRINTF + size_t l = strlen(s); + soap_snprintf(s + l, sizeof(soap->msgbuf) - l, " (%d%cs send delay)", st, su); +#else sprintf(s + strlen(s), " (%d%cs send delay)", st, su); #endif + } +#endif } return soap->msgbuf; } @@ -16175,7 +16839,9 @@ char* SOAP_FMAC2 soap_sprint_fault(struct soap *soap, char *buf, size_t len) { if (soap_check_state(soap)) - strncpy(buf, "Error: soap struct not initialized", len); + { strncpy(buf, "Error: soap struct not initialized", len); + buf[len - 1] = '\0'; + } else if (soap->error) { const char **c, *v = NULL, *s, *d; c = soap_faultcode(soap); diff --git a/dep/gsoap/stdsoap2.h b/dep/gsoap/stdsoap2.h index 87185924135..31aece07f1a 100644 --- a/dep/gsoap/stdsoap2.h +++ b/dep/gsoap/stdsoap2.h @@ -1,10 +1,10 @@ /* - stdsoap2.h 2.8.10 + stdsoap2.h 2.8.17r gSOAP runtime engine gSOAP XML Web services tools -Copyright (C) 2000-2012, Robert van Engelen, Genivia Inc., All Rights Reserved. +Copyright (C) 2000-2013, Robert van Engelen, Genivia Inc., All Rights Reserved. This part of the software is released under ONE of the following licenses: GPL, or the gSOAP public license, or Genivia's license for commercial use. -------------------------------------------------------------------------------- @@ -24,7 +24,7 @@ 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-2012, Robert van Engelen, Genivia Inc., All Rights Reserved. +Copyright (C) 2000-2013, Robert van Engelen, Genivia Inc., All Rights Reserved. -------------------------------------------------------------------------------- GPL license. @@ -51,7 +51,7 @@ A commercial use license is available from Genivia, Inc., contact@genivia.com -------------------------------------------------------------------------------- */ -#define GSOAP_VERSION 20810 +#define GSOAP_VERSION 20817 #ifdef WITH_SOAPDEFS_H # include "soapdefs.h" /* include user-defined stuff */ @@ -216,7 +216,9 @@ A commercial use license is available from Genivia, Inc., contact@genivia.com # define WITH_LEAN # define HAVE_SSCANF # elif defined(WIN32) -# define HAVE_SNPRINTF +# if _MSC_VER >= 1400 +# define HAVE_SNPRINTF +# endif # define HAVE_STRRCHR # define HAVE_STRTOD # define HAVE_SSCANF @@ -225,8 +227,8 @@ A commercial use license is available from Genivia, Inc., contact@genivia.com # define HAVE_STRTOL # define HAVE_STRTOUL # if _MSC_VER >= 1300 -# define HAVE_STRTOLL // use _strtoi64 -# define HAVE_STRTOULL // use _strtoui64 +# define HAVE_STRTOLL /* use _strtoi64 */ +# define HAVE_STRTOULL /* use _strtoui64 */ # endif # define HAVE_SYS_TIMEB_H # define HAVE_FTIME @@ -264,11 +266,14 @@ A commercial use license is available from Genivia, Inc., contact@genivia.com # define HAVE_STRTOUL # define HAVE_RAND_R # define HAVE_GMTIME_R +# define HAVE_TM_GMTOFF +# define HAVE_GETTIMEOFDAY # define HAVE_LOCALTIME_R # define HAVE_STRERROR_R # define HAVE_TIMEGM # define HAVE_WCTOMB # define HAVE_MBTOWC +# define HAVE_INTTYPES_H # elif defined(_AIX43) # define HAVE_SNPRINTF # define HAVE_STRRCHR @@ -482,10 +487,6 @@ A commercial use license is available from Genivia, Inc., contact@genivia.com # define HAVE_STRERROR_R # define HAVE_WCTOMB # define HAVE_MBTOWC -# define LONG64 long -# define ULONG64 unsigned LONG64 -# define SOAP_LONG_FORMAT "%ld" -# define SOAP_ULONG_FORMAT "%lu" # elif defined(SUN_OS) # define HAVE_SNPRINTF # define HAVE_STRRCHR @@ -543,7 +544,7 @@ A commercial use license is available from Genivia, Inc., contact@genivia.com #endif /* native Win, HP-UX, and AIX compilers don't like empty structs */ -#if defined(WIN32) || defined(HP_UX) || defined(_AIX41) || defined(_AIX43) || defined(VXWORKS) +#if defined(WIN32) || defined(HP_UX) || defined(_AIX) || defined(AIX) || defined(VXWORKS) # define WITH_NOEMPTYSTRUCT #endif @@ -579,7 +580,7 @@ A commercial use license is available from Genivia, Inc., contact@genivia.com # undef HAVE_SPRINTF_L #endif -#ifdef TANDEM_NONSTOP +#ifdef TANDEM_NONSTOP /* Support for Guardian */ # define SOAP_BUFLEN (32767) /*# define WITH_NOSTDLIB */ /* uncommment to remove stdlib dependences */ # define WITH_NOIO /* no IO dependences, e.g. remove TCP/IP */ @@ -610,6 +611,9 @@ A commercial use license is available from Genivia, Inc., contact@genivia.com # include <cextdecs.h(TIME,FILE_CLOSE_,AWAITIOX,DELAY,FILEINFO,FILE_GETINFO_)> # define INET_ERROR 4294967295 #pragma list +#elif defined(__TANDEM) /* Support for OSS */ +# define int32_t int +# define SOAP_BUFLEN (32767) #endif #ifndef WITH_NOSTDLIB @@ -723,17 +727,18 @@ A commercial use license is available from Genivia, Inc., contact@genivia.com # include <io.h> # include <fcntl.h> # endif -// When you get macro redefinition errors when compiling the code below: -// try arrange your include list that <windows.h> is included after "stdsoap2.h" -// or define _WINSOCKAPI_ first: -// #define _WINSOCKAPI_ // stops windows.h including winsock.h -// #include <windows.h> -// #include "stdsoap2.h" -# include <winsock2.h> /* Visual Studio 2005 users: install Platform SDK (R2) */ +// When you get macro redefinition errors when compiling the code below, then: +// a) try arrange your includes so <windows.h> is included after "stdsoap2.h" +// b) or define _WINSOCKAPI_ first: +// #define _WINSOCKAPI_ // stops windows.h including winsock.h +// #include <windows.h> +// #include "stdsoap2.h" +// c) or compile with the -DWIN32_LEAN_AND_MEAN switch +# include <winsock2.h> // Visual Studio 2005 users: install Platform SDK (R2) # include <ws2tcpip.h> -// # define _WSPIAPI_COUNTOF /* DEV NOTE: enble to fix problems with VC6 */ +// # define _WSPIAPI_COUNTOF // DEV NOTE: enble to fix problems with VC6 // # include <wspiapi.h> -# include <ws2spi.h> /* DEV NOTE: replaces older wspiapi.h above */ +# include <ws2spi.h> // DEV NOTE: replaces older wspiapi.h above # ifdef WITH_IPV6 # define SOAP_GAI_STRERROR gai_strerrorA # endif @@ -815,14 +820,16 @@ A commercial use license is available from Genivia, Inc., contact@genivia.com # endif #endif -/* #define DEBUG */ /* Uncomment to debug sending (in file SENT.log) receiving (in file RECV.log) and messages (in file TEST.log) */ +/* #define DEBUG */ /* Uncomment to debug sending (in file SENT.log) receiving (in file RECV.log) and internal operations (in file TEST.log) */ + +/* #define DEBUG_STAMP */ /* Uncomment to debug sending (in file SENT.log) receiving (in file RECV.log) and time-stamped operations (in file TEST.log) */ #ifdef __cplusplus extern "C" { #endif /* Portability: define SOAP_SOCKLEN_T */ -#if defined(_AIX) +#if defined(_AIX) || defined(AIX) # if defined(_AIX43) # define SOAP_SOCKLEN_T socklen_t # else @@ -830,7 +837,7 @@ extern "C" { # endif #elif defined(SOCKLEN_T) # define SOAP_SOCKLEN_T SOCKLEN_T -#elif defined(__socklen_t_defined) || defined(_SOCKLEN_T) || defined(CYGWIN) || defined(FREEBSD) || defined(__FreeBSD__) || defined(OPENBSD) || defined(__QNX__) || defined(QNX) || defined(OS390) +#elif defined(__socklen_t_defined) || defined(_SOCKLEN_T) || defined(CYGWIN) || defined(FREEBSD) || defined(__FreeBSD__) || defined(OPENBSD) || defined(__QNX__) || defined(QNX) || defined(OS390) || defined(__ANDROID__) # define SOAP_SOCKLEN_T socklen_t #elif defined(IRIX) || defined(WIN32) || defined(__APPLE__) || defined(SUN_OS) || defined(OPENSERVER) || defined(TRU64) || defined(VXWORKS) || defined(HP_UX) # define SOAP_SOCKLEN_T int @@ -868,12 +875,29 @@ extern "C" { # define SOAP_CHK_EOF (soap->error ? soap->error : SOAP_EOF) #endif +#ifdef __cplusplus +# ifndef __STDC_FORMAT_MACROS +# define __STDC_FORMAT_MACROS +# endif +#endif + #if defined(SYMBIAN) # define LONG64 long # define ULONG64 unsigned LONG64 #elif !defined(WIN32) || defined(CYGWIN) || defined(__GLIBC__) || defined(__GNU__) # ifndef LONG64 -# if defined(HAVE_STDINT_H) +# if defined(HAVE_INTTYPES_H) +# ifdef HAVE_STDINT_H +# include <stdint.h> +# endif +# include <inttypes.h> +# define LONG64 int64_t +# define ULONG64 uint64_t +# elif defined(HAVE_SYS_INTTYPES_H) +# include <sys/inttypes.h> +# define LONG64 int64_t +# define ULONG64 uint64_t +# elif defined(HAVE_STDINT_H) # include <stdint.h> # define LONG64 int64_t # define ULONG64 uint64_t @@ -905,6 +929,18 @@ extern "C" { # define ULONG64 unsigned LONG64 #endif +#ifdef PRId64 +# ifndef SOAP_LONG_FORMAT +# define SOAP_LONG_FORMAT "%" PRId64 +# endif +#endif + +#ifdef PRIu64 +# ifndef SOAP_ULONG_FORMAT +# define SOAP_ULONG_FORMAT "%" PRIu64 +# endif +#endif + #ifndef SOAP_LONG_FORMAT # define SOAP_LONG_FORMAT "%lld" /* printf format for 64 bit ints */ #endif @@ -919,7 +955,7 @@ extern "C" { # define soap_int32 long #elif defined(PALM) # define soap_int32 Int32 -#elif defined(_AIX) +#elif defined(_AIX) || defined(AIX) # if defined(_AIX43) # define soap_int32 int32_t # else @@ -1035,6 +1071,12 @@ extern "C" { # define SOAP_INDEX_TEST (2) #endif +/* Max number of EINTR while poll/select on a socket */ +/* Each EINTR can lengthen the I/O blocking time by at most one second */ +#ifndef SOAP_MAXEINTR +# define SOAP_MAXEINTR (10) +#endif + /* Max iterations in soap_serve() to keep server connection alive */ #ifndef SOAP_MAXKEEPALIVE # define SOAP_MAXKEEPALIVE (100) @@ -1047,6 +1089,14 @@ extern "C" { # define SOAP_MAXARRAYSIZE (1000000) #endif +/* Trusted max size of inbound DIME data. + Increase if necessary to allow larger attachments, or decrease when server + resources are limited. +*/ +#ifndef SOAP_MAXDIMESIZE +# define SOAP_MAXDIMESIZE (8388608) /* 8 MB */ +#endif + #ifdef VXWORKS # ifdef WMW_RPM_IO # include "httpLib.h" @@ -1180,13 +1230,15 @@ extern const char soap_base64o[], soap_base64i[]; #ifdef HAVE_SNPRINTF # ifdef WIN32 -# define soap_snprintf _snprintf +# define soap_snprintf(buf, len, ...) (_snprintf((buf), (len), __VA_ARGS__), (buf)[(len)-1] = '\0') # else # define soap_snprintf snprintf # endif #endif -/* gSOAP error codes */ +/* gSOAP status/error codes */ + +typedef soap_int32 soap_status; #define SOAP_EOF EOF #define SOAP_ERR EOF @@ -1306,14 +1358,14 @@ typedef soap_int32 soap_mode; #define SOAP_ENC_ZLIB 0x00000400 #define SOAP_ENC_SSL 0x00000800 -#define SOAP_XML_STRICT 0x00001000 /* in: strict validation */ +#define SOAP_XML_STRICT 0x00001000 /* in: strict validation */ #define SOAP_XML_INDENT 0x00002000 /* out: emit indented XML */ -#define SOAP_XML_IGNORENS 0x00004000 /* in: ignore namespaces */ +#define SOAP_XML_IGNORENS 0x00004000 /* in: ignore namespaces */ #define SOAP_XML_DEFAULTNS 0x00008000 /* out: emit xmlns="..." */ #define SOAP_XML_CANONICAL 0x00010000 /* out: excC14N canonical XML */ -#define SOAP_XML_TREE 0x00020000 /* out: XML tree (no id/ref) */ +#define SOAP_XML_TREE 0x00020000 /* in/out: XML tree (no id/ref) */ #define SOAP_XML_NIL 0x00040000 /* out: NULLs as xsi:nil */ -#define SOAP_XML_NOTYPE 0x00080000 /* out: NULLs as xsi:nil */ +#define SOAP_XML_NOTYPE 0x00080000 /* out: do not add xsi:type */ #define SOAP_DOM_TREE 0x00100000 /* see DOM manual */ #define SOAP_DOM_NODE 0x00200000 @@ -1325,7 +1377,7 @@ typedef soap_int32 soap_mode; #define SOAP_C_NILSTRING 0x08000000 /* serialize empty strings as nil (omitted) */ #define SOAP_XML_DOM 0x10000000 /* enable internal DOM */ -#define SOAP_XML_GRAPH 0x20000000 /* id-ref graph in DOM */ +#define SOAP_XML_GRAPH 0x20000000 /* force id-ref XML graph */ #define SOAP_MIME_POSTCHECK 0x40000000 /* MIME flag (internal) */ @@ -1383,6 +1435,11 @@ typedef soap_int32 soap_mode; /* DEBUG macros */ #ifndef WITH_LEAN +# ifdef DEBUG_STAMP +# ifndef DEBUG +# define DEBUG +# endif +# endif # ifdef DEBUG # ifndef SOAP_DEBUG # define SOAP_DEBUG @@ -1410,20 +1467,40 @@ typedef soap_int32 soap_mode; # define SOAP_FREE(soap, ptr) free(ptr) #endif -#ifndef SOAP_NEW /* use C++ new operator */ -# if (defined(__GNUC__) && (__GNUC__ <= 2) && !defined(__BORLANDC__)) || defined(__clang__) || defined(_AIX) -# define SOAP_NEW(type) new type /* old form w/o parenthesis */ -# else -# define SOAP_NEW(type) new (type) /* prefer with parenthesis */ -# endif +#if defined(__GNUC__) && (__GNUC__ <= 2) +# define SOAP_NOTHROW +#elif !defined(WITH_LEAN) && !defined(WITH_COMPAT) && !defined(SOAP_NOTHROW) +# define SOAP_NOTHROW (std::nothrow) +#else +# define SOAP_NOTHROW #endif -#ifndef SOAP_PLACEMENT_NEW -# define SOAP_PLACEMENT_NEW(buf, type) new (buf) type +#if (defined(__GNUC__) && (__GNUC__ <= 2) && !defined(__BORLANDC__)) || defined(__clang__) || defined(_AIX) || defined(AIX) +/* old form w/o parenthesis */ +# ifndef SOAP_NEW +# define SOAP_NEW(type) new SOAP_NOTHROW type +# endif +# ifndef SOAP_NEW_ARRAY +# define SOAP_NEW_ARRAY(type, n) new SOAP_NOTHROW type[n] +# endif +# ifndef SOAP_PLACEMENT_NEW +# define SOAP_PLACEMENT_NEW(buf, type) new (buf) type +# endif +#else +/* new form with parenthesis */ +# ifndef SOAP_NEW +# define SOAP_NEW(type) new SOAP_NOTHROW (type) +# endif +# ifndef SOAP_NEW_ARRAY +# define SOAP_NEW_ARRAY(type, n) new SOAP_NOTHROW type[n] +# endif +# ifndef SOAP_PLACEMENT_NEW +# define SOAP_PLACEMENT_NEW(buf, type) new (buf) (type) +# endif #endif #ifndef SOAP_NEW_COPY /* use C++ new operator for ::copy() */ -# define SOAP_NEW_COPY(clas) new clas /* prefer w/o parenthesis */ +# define SOAP_NEW_COPY(clas) new SOAP_NOTHROW clas #endif #ifndef SOAP_DELETE /* use C++ delete operator */ @@ -1439,17 +1516,53 @@ typedef soap_int32 soap_mode; # define SOAP_MESSAGE fprintf # endif # ifndef DBGLOG -# define DBGLOG(DBGFILE, CMD) \ +# ifdef DEBUG_STAMP +# ifdef WIN32 +# define DBGLOG(DBGFILE, CMD) \ { if (soap)\ { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ soap_open_logfile((struct soap*)soap, SOAP_INDEX_##DBGFILE);\ if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ { FILE *fdebug = soap->fdebug[SOAP_INDEX_##DBGFILE];\ + SYSTEMTIME _localTime;\ + ::GetLocalTime(&_localTime); \ + fprintf(fdebug, "%02d%02d%02d %02d:%02d:%02d.%03d|", _localTime.wYear%100, _localTime.wMonth, _localTime.wDay, _localTime.wHour, _localTime.wMinute, _localTime.wSecond, _localTime.wMilliseconds);\ CMD;\ fflush(fdebug);\ }\ }\ } +# else +# define DBGLOG(DBGFILE, CMD) \ +{ if (soap)\ + { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ + soap_open_logfile((struct soap*)soap, SOAP_INDEX_##DBGFILE);\ + if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ + { FILE *fdebug = soap->fdebug[SOAP_INDEX_##DBGFILE];\ + struct timeval _tv;\ + struct tm _tm;\ + gettimeofday(&_tv, NULL);\ + localtime_r(&_tv.tv_sec, &_tm);\ + fprintf(fdebug, "%02d%02d%02d %02d:%02d:%02d.%06d|", _tm.tm_year%100, _tm.tm_mon+1, _tm.tm_mday, _tm.tm_hour, _tm.tm_min, _tm.tm_sec, _tv.tv_usec);\ + CMD;\ + fflush(fdebug);\ + }\ + }\ +} +# endif +# else +# define DBGLOG(DBGFILE, CMD) \ +{ if (soap)\ + { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ + soap_open_logfile((struct soap*)soap, SOAP_INDEX_##DBGFILE);\ + if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ + { FILE *fdebug = soap->fdebug[SOAP_INDEX_##DBGFILE];\ + CMD;\ + fflush(fdebug);\ + }\ + }\ +} +# endif # endif # ifndef DBGMSG # define DBGMSG(DBGFILE, MSG, LEN) \ @@ -1465,9 +1578,9 @@ typedef soap_int32 soap_mode; # endif # ifndef DBGFUN # define DBGFUN(FNAME) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s()\n", __FILE__, __LINE__, FNAME)) -# define DBGFUN1(FNAME, FMT, ARG) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s("FMT")\n", __FILE__, __LINE__, FNAME, (ARG))) -# define DBGFUN2(FNAME, FMT1, ARG1, FMT2, ARG2) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s("FMT1", "FMT2")\n", __FILE__, __LINE__, FNAME, (ARG1), (ARG2))) -# define DBGFUN3(FNAME, FMT1, ARG1, FMT2, ARG2, FMT3, ARG3) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s("FMT1", "FMT2", "FMT3")\n", __FILE__, __LINE__, FNAME, (ARG1), (ARG2), (ARG3))) +# define DBGFUN1(FNAME, FMT, ARG) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s(" FMT ")\n", __FILE__, __LINE__, FNAME, (ARG))) +# define DBGFUN2(FNAME, FMT1, ARG1, FMT2, ARG2) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s(" FMT1 ", " FMT2 ")\n", __FILE__, __LINE__, FNAME, (ARG1), (ARG2))) +# define DBGFUN3(FNAME, FMT1, ARG1, FMT2, ARG2, FMT3, ARG3) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s(" FMT1 ", " FMT2 ", " FMT3 ")\n", __FILE__, __LINE__, FNAME, (ARG1), (ARG2), (ARG3))) # endif # ifndef DBGHEX # define DBGHEX(DBGFILE, MSG, LEN) \ @@ -1533,7 +1646,7 @@ struct soap_plist const struct soap_array *array; int type; int id; - char mark1; + char mark1; /* 0=single-ref, 1=embedded-multi-ref (SOAP1.1), 2=multi-ref, 3=attachment */ char mark2; }; @@ -1819,7 +1932,7 @@ extern "C" { struct SOAP_STD_API soap { short state; /* 0 = uninitialized, 1 = initialized, 2 = copy of another soap struct */ - short version; /* 1 = SOAP1.1 and 2 = SOAP1.2 (set automatically from namespace URI in nsmap table) */ + short version; /* 1 = SOAP1.1 and 2 = SOAP1.2 (set automatically from namespace URI in nsmap table), 0 indicates non-SOAP content */ soap_mode mode; soap_mode imode; soap_mode omode; @@ -1828,7 +1941,7 @@ struct SOAP_STD_API soap const char *dime_id_format; /* user-definable format string for integer DIME id (<SOAP_TAGLEN chars) */ const char *http_version; /* HTTP version used "1.0" or "1.1" */ const char *http_content; /* optional custom response content type (with SOAP_FILE) */ - const char *encodingStyle; /* default = NULL which means that SOAP encoding is used */ + const char *encodingStyle; /* default = "" which means that SOAP encoding is used */ const char *actor; /* SOAP-ENV:actor or role attribute value */ const char *lang; /* xml:lang attribute value of SOAP-ENV:Text */ int recv_timeout; /* when > 0, gives socket recv timeout in seconds, < 0 in usec */ @@ -1846,10 +1959,12 @@ struct SOAP_STD_API soap struct soap_blist *blist; /* block allocation stack */ struct soap_clist *clist; /* class instance allocation list */ void *alist; /* memory allocation (malloc) list */ +#if !defined(WITH_LEAN) || !defined(WITH_NOIDREF) struct soap_ilist *iht[SOAP_IDHASH]; struct soap_plist *pht[SOAP_PTRHASH]; struct soap_pblk *pblk; /* plist block allocation */ short pidx; /* plist block allocation */ +#endif struct SOAP_ENV__Header *header; struct SOAP_ENV__Fault *fault; int idnum; @@ -1941,7 +2056,7 @@ struct SOAP_STD_API soap size_t buflen; /* length of soap.buf[] content */ soap_wchar ahead; /* parser lookahead */ short cdata; /* CDATA parser state */ - short body; /* parsed XML element has a body or not */ + short body; /* HTTP or XML element has a body (1) or not (0) */ unsigned int level; /* XML nesting level */ size_t count; /* message length counter */ size_t length; /* message length as set by HTTP header */ @@ -2017,7 +2132,7 @@ struct SOAP_STD_API soap int cookie_max; #endif #ifndef WITH_NOIO - int ipv6_multicast_if; /* in6addr->sin6_scope_id IPv6 value */ + unsigned int ipv6_multicast_if; /* in_addr_t in6addr->sin6_scope_id IPv6 value */ char* ipv4_multicast_if; /* IP_MULTICAST_IF IPv4 setsockopt interface_addr */ unsigned char ipv4_multicast_ttl; /* IP_MULTICAST_TTL value 0..255 */ #ifdef WITH_IPV6 @@ -2057,6 +2172,7 @@ struct SOAP_STD_API soap #endif unsigned short ssl_flags; const char *keyfile; + const char *keyid; const char *password; const char *cafile; const char *capath; @@ -2139,9 +2255,7 @@ struct soap_plugin void (*fdelete)(struct soap *soap, struct soap_plugin *p); /* should delete fields of plugin only and not free(p) */ }; -#ifndef WITH_NONAMESPACES extern SOAP_NMAC struct Namespace namespaces[]; -#endif #ifndef WITH_LEAN # define soap_get0(soap) (((soap)->bufidx>=(soap)->buflen && soap_recv(soap)) ? EOF : (unsigned char)(soap)->buf[(soap)->bufidx]) @@ -2151,6 +2265,9 @@ soap_wchar soap_get0(struct soap*); soap_wchar soap_get1(struct soap*); #endif +#define SOAP_XSTRINGIFY(s) SOAP_STRINGIFY(s) +#define SOAP_STRINGIFY(s) #s + #define soap_versioning_paste(name, ext) name##_LIBRARY_VERSION_REQUIRED_##ext #define soap_versioning_ext(name, ext) soap_versioning_paste(name, ext) #define soap_versioning(name) soap_versioning_ext(name, GSOAP_VERSION) @@ -2195,13 +2312,13 @@ soap_wchar soap_get1(struct soap*); SOAP_FMAC1 unsigned long SOAP_FMAC2 soap_strtoul(const char *s, char **t, int b); #endif -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) # define soap_strtoll _strtoi64 #else # define soap_strtoll strtoll #endif -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) # define soap_strtoull _strtoui64 #else # define soap_strtoull strtoull @@ -2229,8 +2346,6 @@ SOAP_FMAC1 int SOAP_FMAC2 soap_rand(void); # define soap_lookup_type(s, i) (0) # define soap_getindependent(s) (0) # define soap_putindependent(s) (0) -# define soap_getelement(s, n) (n) -# define soap_putelement(s, p, t, i, n) (0) # define soap_markelement(s, p, n) (0) #endif @@ -2240,7 +2355,6 @@ typedef void soap_walker(struct soap*, void*, int, const char*, const char*); SOAP_FMAC5 int SOAP_FMAC6 soap_serve(struct soap *soap); SOAP_FMAC5 int SOAP_FMAC6 soap_serve_request(struct soap *soap); -#ifndef WITH_NOGLOBAL SOAP_FMAC3 void SOAP_FMAC4 soap_header(struct soap*); SOAP_FMAC3 void SOAP_FMAC4 soap_fault(struct soap*); SOAP_FMAC3 const char** SOAP_FMAC4 soap_faultcode(struct soap*); @@ -2250,7 +2364,6 @@ SOAP_FMAC3 const char** SOAP_FMAC4 soap_faultdetail(struct soap*); SOAP_FMAC3 const char* SOAP_FMAC4 soap_check_faultsubcode(struct soap*); SOAP_FMAC3 const char* SOAP_FMAC4 soap_check_faultdetail(struct soap*); SOAP_FMAC3 void SOAP_FMAC4 soap_serializefault(struct soap*); -#endif SOAP_FMAC1 void SOAP_FMAC2 soap_serializeheader(struct soap*); SOAP_FMAC1 int SOAP_FMAC2 soap_getheader(struct soap*); @@ -2267,8 +2380,16 @@ SOAP_FMAC1 SOAP_SOCKET SOAP_FMAC2 soap_accept(struct soap*); SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_accept(struct soap*); SOAP_FMAC1 const char * SOAP_FMAC2 soap_ssl_error(struct soap*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_server_context(struct soap*, unsigned short, const char*, const char*, const char*, const char*, const char*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_client_context(struct soap*, unsigned short, const char*, const char*, const char*, const char*, const char*); +#if defined(VXWORKS) && defined(WM_SECURE_KEY_STORAGE) +SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_server_context(struct soap *soap, unsigned short flags, const char *keyfile, const char *keyid, const char *password, const char *cafile, const char *capath, const char *dhfile, const char *randfile, const char *sid); +#else +SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_server_context(struct soap *soap, unsigned short flags, const char *keyfile, const char *password, const char *cafile, const char *capath, const char *dhfile, const char *randfile, const char *sid); +#endif +#if defined(VXWORKS) && defined(WM_SECURE_KEY_STORAGE) +SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_client_context(struct soap *soap, unsigned short flags, const char *keyfile, const char *keyid, const char *password, const char *cafile, const char *capath, const char *randfile); +#else +SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_client_context(struct soap *soap, unsigned short flags, const char *keyfile, const char *password, const char *cafile, const char *capath, const char *randfile); +#endif SOAP_FMAC1 int SOAP_FMAC2 soap_puthttphdr(struct soap*, int status, size_t count); @@ -2333,6 +2454,7 @@ SOAP_FMAC1 int SOAP_FMAC2 soap_begin_count(struct soap*); SOAP_FMAC1 int SOAP_FMAC2 soap_end_count(struct soap*); SOAP_FMAC1 int SOAP_FMAC2 soap_begin_send(struct soap*); SOAP_FMAC1 int SOAP_FMAC2 soap_end_send(struct soap*); +SOAP_FMAC1 int SOAP_FMAC2 soap_end_send_flush(struct soap*); SOAP_FMAC1 const struct soap_code_map* SOAP_FMAC2 soap_code(const struct soap_code_map*, const char*); SOAP_FMAC1 long SOAP_FMAC2 soap_code_int(const struct soap_code_map*, const char*, long); @@ -2385,6 +2507,7 @@ SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_copy_context(struct soap*, const struct SOAP_FMAC1 void SOAP_FMAC2 soap_copy_stream(struct soap*, struct soap*); SOAP_FMAC1 void SOAP_FMAC2 soap_free_stream(struct soap*); SOAP_FMAC1 void SOAP_FMAC2 soap_versioning(soap_init)(struct soap*, soap_mode, soap_mode); +SOAP_FMAC1 void SOAP_FMAC2 soap_initialize(struct soap*); SOAP_FMAC1 void SOAP_FMAC2 soap_done(struct soap*); SOAP_FMAC1 void SOAP_FMAC2 soap_cleanup(struct soap*); SOAP_FMAC1 void SOAP_FMAC2 soap_begin(struct soap*); @@ -2443,6 +2566,7 @@ SOAP_FMAC1 wchar_t* SOAP_FMAC2 soap_wstring_in(struct soap*, int, long, long); SOAP_FMAC1 int SOAP_FMAC2 soap_match_namespace(struct soap*, const char *, const char*, size_t n1, size_t n2); +SOAP_FMAC1 void SOAP_FMAC2 soap_set_version(struct soap*, short); SOAP_FMAC1 int SOAP_FMAC2 soap_set_namespaces(struct soap*, const struct Namespace*); SOAP_FMAC1 void SOAP_FMAC2 soap_set_local_namespaces(struct soap*); @@ -2467,9 +2591,9 @@ SOAP_FMAC1 void SOAP_FMAC2 soap_end_block(struct soap*, struct soap_blist*); SOAP_FMAC1 void SOAP_FMAC2 soap_update_pointers(struct soap *soap, char *start, char *end, char *p1, char *p2); SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_begin_out(struct soap*); -SOAP_FMAC1 int soap_envelope_end_out(struct soap*); +SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_end_out(struct soap*); -SOAP_FMAC1 char * SOAP_FMAC2 soap_get_http_body(struct soap*); +SOAP_FMAC1 char * SOAP_FMAC2 soap_get_http_body(struct soap*, size_t *len); SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_begin_in(struct soap*); SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_end_in(struct soap*); @@ -2598,7 +2722,7 @@ SOAP_FMAC1 int SOAP_FMAC2 soap_outwliteral(struct soap*, const char *tag, wchar_ #ifndef WITH_LEANER SOAP_FMAC1 int SOAP_FMAC2 soap_attachment(struct soap *, const char*, int, const void*, const struct soap_array*, const char*, const char*, const char*, int, const char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_move(struct soap*, long); +SOAP_FMAC1 int SOAP_FMAC2 soap_move(struct soap*, size_t); SOAP_FMAC1 size_t SOAP_FMAC2 soap_tell(struct soap*); SOAP_FMAC1 char* SOAP_FMAC2 soap_dime_option(struct soap*, unsigned short, const char*); SOAP_FMAC1 int SOAP_FMAC2 soap_getdimehdr(struct soap*); @@ -2628,9 +2752,11 @@ SOAP_FMAC1 const char* SOAP_FMAC2 soap_attr_value(struct soap *soap, const char SOAP_FMAC1 int SOAP_FMAC2 soap_set_attr(struct soap *soap, const char *name, const char *value, int flag); SOAP_FMAC1 void SOAP_FMAC2 soap_clr_attr(struct soap *soap); +SOAP_FMAC1 const char* SOAP_FMAC2 soap_url(struct soap *soap, const char*, const char*); +SOAP_FMAC1 size_t SOAP_FMAC2 soap_encode_url(const char*, char*, size_t); +SOAP_FMAC1 const char* SOAP_FMAC2 soap_encode_url_string(struct soap*, const char*); #ifdef WITH_COOKIES SOAP_FMAC1 void SOAP_FMAC2 soap_getcookies(struct soap *soap, const char *val); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_encode_cookie(const char*, char*, size_t); SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_set_cookie(struct soap*, const char*, const char*, const char*, const char*); SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_cookie(struct soap*, const char*, const char*, const char*); SOAP_FMAC1 extern char* SOAP_FMAC2 soap_cookie_value(struct soap*, const char*, const char*, const char*); diff --git a/dep/jemalloc/ChangeLog b/dep/jemalloc/ChangeLog index c0ca338b076..d56ee999e69 100644 --- a/dep/jemalloc/ChangeLog +++ b/dep/jemalloc/ChangeLog @@ -5,6 +5,30 @@ found in the git revision history: https://github.com/jemalloc/jemalloc +* 3.6.0 (March 31, 2014) + + This version contains a critical bug fix for a regression present in 3.5.0 and + 3.5.1. + + Bug fixes: + - Fix a regression in arena_chunk_alloc() that caused crashes during + small/large allocation if chunk allocation failed. In the absence of this + bug, chunk allocation failure would result in allocation failure, e.g. NULL + return from malloc(). This regression was introduced in 3.5.0. + - Fix backtracing for gcc intrinsics-based backtracing by specifying + -fno-omit-frame-pointer to gcc. Note that the application (and all the + libraries it links to) must also be compiled with this option for + backtracing to be reliable. + - Use dss allocation precedence for huge allocations as well as small/large + allocations. + - Fix test assertion failure message formatting. This bug did not manifect on + x86_64 systems because of implementation subtleties in va_list. + - Fix inconsequential test failures for hash and SFMT code. + + New features: + - Support heap profiling on FreeBSD. This feature depends on the proc + filesystem being mounted during heap profile dumping. + * 3.5.1 (February 25, 2014) This version primarily addresses minor bugs in test code. diff --git a/dep/jemalloc/VERSION b/dep/jemalloc/VERSION index 24870eef790..dace31ba7b6 100644 --- a/dep/jemalloc/VERSION +++ b/dep/jemalloc/VERSION @@ -1 +1 @@ -3.5.1-0-g7709a64c59daf0b1f938be49472fcc499e1bd136 +3.6.0-0-g46c0af68bd248b04df75e4f92d5fb804c3d75340 diff --git a/dep/jemalloc/include/jemalloc/internal/hash.h b/dep/jemalloc/include/jemalloc/internal/hash.h index 09b69df515b..c7183ede82d 100644 --- a/dep/jemalloc/include/jemalloc/internal/hash.h +++ b/dep/jemalloc/include/jemalloc/internal/hash.h @@ -320,7 +320,7 @@ hash_x64_128(const void *key, const int len, const uint32_t seed, JEMALLOC_INLINE void hash(const void *key, size_t len, const uint32_t seed, size_t r_hash[2]) { -#if (LG_SIZEOF_PTR == 3) +#if (LG_SIZEOF_PTR == 3 && !defined(JEMALLOC_BIG_ENDIAN)) hash_x64_128(key, len, seed, (uint64_t *)r_hash); #else uint64_t hashes[2]; diff --git a/dep/jemalloc/include/jemalloc/internal/huge.h b/dep/jemalloc/include/jemalloc/internal/huge.h index ddf13138ad7..a2b9c779191 100644 --- a/dep/jemalloc/include/jemalloc/internal/huge.h +++ b/dep/jemalloc/include/jemalloc/internal/huge.h @@ -17,18 +17,20 @@ extern size_t huge_allocated; /* Protects chunk-related data structures. */ extern malloc_mutex_t huge_mtx; -void *huge_malloc(size_t size, bool zero); -void *huge_palloc(size_t size, size_t alignment, bool zero); +void *huge_malloc(size_t size, bool zero, dss_prec_t dss_prec); +void *huge_palloc(size_t size, size_t alignment, bool zero, + dss_prec_t dss_prec); bool huge_ralloc_no_move(void *ptr, size_t oldsize, size_t size, size_t extra); void *huge_ralloc(void *ptr, size_t oldsize, size_t size, size_t extra, - size_t alignment, bool zero, bool try_tcache_dalloc); + size_t alignment, bool zero, bool try_tcache_dalloc, dss_prec_t dss_prec); #ifdef JEMALLOC_JET typedef void (huge_dalloc_junk_t)(void *, size_t); extern huge_dalloc_junk_t *huge_dalloc_junk; #endif void huge_dalloc(void *ptr, bool unmap); size_t huge_salloc(const void *ptr); +dss_prec_t huge_dss_prec_get(arena_t *arena); prof_ctx_t *huge_prof_ctx_get(const void *ptr); void huge_prof_ctx_set(const void *ptr, prof_ctx_t *ctx); bool huge_boot(void); diff --git a/dep/jemalloc/include/jemalloc/internal/jemalloc_internal.h b/dep/jemalloc/include/jemalloc/internal/jemalloc_internal.h index b64cc4bed87..cf171326c29 100644 --- a/dep/jemalloc/include/jemalloc/internal/jemalloc_internal.h +++ b/dep/jemalloc/include/jemalloc/internal/jemalloc_internal.h @@ -801,7 +801,7 @@ imalloct(size_t size, bool try_tcache, arena_t *arena) if (size <= arena_maxclass) return (arena_malloc(arena, size, false, try_tcache)); else - return (huge_malloc(size, false)); + return (huge_malloc(size, false, huge_dss_prec_get(arena))); } JEMALLOC_ALWAYS_INLINE void * @@ -818,7 +818,7 @@ icalloct(size_t size, bool try_tcache, arena_t *arena) if (size <= arena_maxclass) return (arena_malloc(arena, size, true, try_tcache)); else - return (huge_malloc(size, true)); + return (huge_malloc(size, true, huge_dss_prec_get(arena))); } JEMALLOC_ALWAYS_INLINE void * @@ -844,9 +844,9 @@ ipalloct(size_t usize, size_t alignment, bool zero, bool try_tcache, ret = arena_palloc(choose_arena(arena), usize, alignment, zero); } else if (alignment <= chunksize) - ret = huge_malloc(usize, zero); + ret = huge_malloc(usize, zero, huge_dss_prec_get(arena)); else - ret = huge_palloc(usize, alignment, zero); + ret = huge_palloc(usize, alignment, zero, huge_dss_prec_get(arena)); } assert(ALIGNMENT_ADDR2BASE(ret, alignment) == ret); @@ -1015,7 +1015,7 @@ iralloct(void *ptr, size_t size, size_t extra, size_t alignment, bool zero, try_tcache_dalloc)); } else { return (huge_ralloc(ptr, oldsize, size, extra, - alignment, zero, try_tcache_dalloc)); + alignment, zero, try_tcache_dalloc, huge_dss_prec_get(arena))); } } diff --git a/dep/jemalloc/include/jemalloc/internal/private_namespace.h b/dep/jemalloc/include/jemalloc/internal/private_namespace.h index a99bf7293ac..35c3b0c6c74 100644 --- a/dep/jemalloc/include/jemalloc/internal/private_namespace.h +++ b/dep/jemalloc/include/jemalloc/internal/private_namespace.h @@ -197,6 +197,7 @@ #define huge_boot JEMALLOC_N(huge_boot) #define huge_dalloc JEMALLOC_N(huge_dalloc) #define huge_dalloc_junk JEMALLOC_N(huge_dalloc_junk) +#define huge_dss_prec_get JEMALLOC_N(huge_dss_prec_get) #define huge_malloc JEMALLOC_N(huge_malloc) #define huge_mtx JEMALLOC_N(huge_mtx) #define huge_ndalloc JEMALLOC_N(huge_ndalloc) diff --git a/dep/jemalloc/include/jemalloc/jemalloc.h b/dep/jemalloc/include/jemalloc/jemalloc.h index 84e2e7294d1..b8ea851e525 100644 --- a/dep/jemalloc/include/jemalloc/jemalloc.h +++ b/dep/jemalloc/include/jemalloc/jemalloc.h @@ -7,12 +7,12 @@ extern "C" { #include <limits.h> #include <strings.h> -#define JEMALLOC_VERSION "3.5.1-0-g7709a64c59daf0b1f938be49472fcc499e1bd136" +#define JEMALLOC_VERSION "3.6.0-0-g46c0af68bd248b04df75e4f92d5fb804c3d75340" #define JEMALLOC_VERSION_MAJOR 3 -#define JEMALLOC_VERSION_MINOR 5 -#define JEMALLOC_VERSION_BUGFIX 1 +#define JEMALLOC_VERSION_MINOR 6 +#define JEMALLOC_VERSION_BUGFIX 0 #define JEMALLOC_VERSION_NREV 0 -#define JEMALLOC_VERSION_GID "7709a64c59daf0b1f938be49472fcc499e1bd136" +#define JEMALLOC_VERSION_GID "46c0af68bd248b04df75e4f92d5fb804c3d75340" # define MALLOCX_LG_ALIGN(la) (la) # if LG_SIZEOF_PTR == 2 diff --git a/dep/jemalloc/src/arena.c b/dep/jemalloc/src/arena.c index 390ab0f8230..dad707b63d0 100644 --- a/dep/jemalloc/src/arena.c +++ b/dep/jemalloc/src/arena.c @@ -614,8 +614,11 @@ arena_chunk_alloc(arena_t *arena) if (arena->spare != NULL) chunk = arena_chunk_init_spare(arena); - else + else { chunk = arena_chunk_init_hard(arena); + if (chunk == NULL) + return (NULL); + } /* Insert the run into the runs_avail tree. */ arena_avail_insert(arena, chunk, map_bias, chunk_npages-map_bias, diff --git a/dep/jemalloc/src/huge.c b/dep/jemalloc/src/huge.c index 6d86aed881b..d72f2135702 100644 --- a/dep/jemalloc/src/huge.c +++ b/dep/jemalloc/src/huge.c @@ -16,14 +16,14 @@ malloc_mutex_t huge_mtx; static extent_tree_t huge; void * -huge_malloc(size_t size, bool zero) +huge_malloc(size_t size, bool zero, dss_prec_t dss_prec) { - return (huge_palloc(size, chunksize, zero)); + return (huge_palloc(size, chunksize, zero, dss_prec)); } void * -huge_palloc(size_t size, size_t alignment, bool zero) +huge_palloc(size_t size, size_t alignment, bool zero, dss_prec_t dss_prec) { void *ret; size_t csize; @@ -48,8 +48,7 @@ huge_palloc(size_t size, size_t alignment, bool zero) * it is possible to make correct junk/zero fill decisions below. */ is_zeroed = zero; - ret = chunk_alloc(csize, alignment, false, &is_zeroed, - chunk_dss_prec_get()); + ret = chunk_alloc(csize, alignment, false, &is_zeroed, dss_prec); if (ret == NULL) { base_node_dealloc(node); return (NULL); @@ -98,7 +97,7 @@ huge_ralloc_no_move(void *ptr, size_t oldsize, size_t size, size_t extra) void * huge_ralloc(void *ptr, size_t oldsize, size_t size, size_t extra, - size_t alignment, bool zero, bool try_tcache_dalloc) + size_t alignment, bool zero, bool try_tcache_dalloc, dss_prec_t dss_prec) { void *ret; size_t copysize; @@ -113,18 +112,18 @@ huge_ralloc(void *ptr, size_t oldsize, size_t size, size_t extra, * space and copying. */ if (alignment > chunksize) - ret = huge_palloc(size + extra, alignment, zero); + ret = huge_palloc(size + extra, alignment, zero, dss_prec); else - ret = huge_malloc(size + extra, zero); + ret = huge_malloc(size + extra, zero, dss_prec); if (ret == NULL) { if (extra == 0) return (NULL); /* Try again, this time without extra. */ if (alignment > chunksize) - ret = huge_palloc(size, alignment, zero); + ret = huge_palloc(size, alignment, zero, dss_prec); else - ret = huge_malloc(size, zero); + ret = huge_malloc(size, zero, dss_prec); if (ret == NULL) return (NULL); @@ -264,6 +263,13 @@ huge_salloc(const void *ptr) return (ret); } +dss_prec_t +huge_dss_prec_get(arena_t *arena) +{ + + return (arena_dss_prec_get(choose_arena(arena))); +} + prof_ctx_t * huge_prof_ctx_get(const void *ptr) { diff --git a/dep/jemalloc/src/jemalloc.c b/dep/jemalloc/src/jemalloc.c index 563d99f8816..204778bc89d 100644 --- a/dep/jemalloc/src/jemalloc.c +++ b/dep/jemalloc/src/jemalloc.c @@ -2076,7 +2076,7 @@ a0alloc(size_t size, bool zero) if (size <= arena_maxclass) return (arena_malloc(arenas[0], size, zero, false)); else - return (huge_malloc(size, zero)); + return (huge_malloc(size, zero, huge_dss_prec_get(arenas[0]))); } void * diff --git a/dep/jemalloc/src/prof.c b/dep/jemalloc/src/prof.c index 1d8ccbd60ae..7722b7b4373 100644 --- a/dep/jemalloc/src/prof.c +++ b/dep/jemalloc/src/prof.c @@ -935,9 +935,12 @@ prof_dump_maps(bool propagate_err) char filename[PATH_MAX + 1]; cassert(config_prof); - +#ifdef __FreeBSD__ + malloc_snprintf(filename, sizeof(filename), "/proc/curproc/map"); +#else malloc_snprintf(filename, sizeof(filename), "/proc/%d/maps", (int)getpid()); +#endif mfd = open(filename, O_RDONLY); if (mfd != -1) { ssize_t nread; diff --git a/dep/recastnavigation/Detour/CMakeLists.txt b/dep/recastnavigation/Detour/CMakeLists.txt index b7c0853efc4..5f3542e96b9 100644 --- a/dep/recastnavigation/Detour/CMakeLists.txt +++ b/dep/recastnavigation/Detour/CMakeLists.txt @@ -9,13 +9,14 @@ # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. set(Detour_STAT_SRCS - DetourAlloc.cpp - DetourCommon.cpp - DetourNavMesh.cpp - DetourNavMeshBuilder.cpp - DetourNavMeshQuery.cpp - DetourNode.cpp + Source/DetourAlloc.cpp + Source/DetourCommon.cpp + Source/DetourNavMesh.cpp + Source/DetourNavMeshBuilder.cpp + Source/DetourNavMeshQuery.cpp + Source/DetourNode.cpp ) +include_directories(Include) if(WIN32) include_directories( diff --git a/dep/recastnavigation/Detour/DetourAlloc.h b/dep/recastnavigation/Detour/Include/DetourAlloc.h index e814b62a716..e814b62a716 100644 --- a/dep/recastnavigation/Detour/DetourAlloc.h +++ b/dep/recastnavigation/Detour/Include/DetourAlloc.h diff --git a/dep/recastnavigation/Detour/DetourAssert.h b/dep/recastnavigation/Detour/Include/DetourAssert.h index 3cf652288fa..3cf652288fa 100644 --- a/dep/recastnavigation/Detour/DetourAssert.h +++ b/dep/recastnavigation/Detour/Include/DetourAssert.h diff --git a/dep/recastnavigation/Detour/DetourCommon.h b/dep/recastnavigation/Detour/Include/DetourCommon.h index 0888614ea9b..0888614ea9b 100644 --- a/dep/recastnavigation/Detour/DetourCommon.h +++ b/dep/recastnavigation/Detour/Include/DetourCommon.h diff --git a/dep/recastnavigation/Detour/DetourNavMesh.h b/dep/recastnavigation/Detour/Include/DetourNavMesh.h index cdd473f1aff..782ddbc2edd 100644 --- a/dep/recastnavigation/Detour/DetourNavMesh.h +++ b/dep/recastnavigation/Detour/Include/DetourNavMesh.h @@ -119,6 +119,25 @@ enum dtStraightPathOptions DT_STRAIGHTPATH_ALL_CROSSINGS = 0x02, ///< Add a vertex at every polygon edge crossing. }; + +/// Options for dtNavMeshQuery::findPath +enum dtFindPathOptions +{ + DT_FINDPATH_LOW_QUALITY_FAR = 0x01, ///< [provisional] trade quality for performance far from the origin. The idea is that by then a new query will be issued + DT_FINDPATH_ANY_ANGLE = 0x02, ///< use raycasts during pathfind to "shortcut" (raycast still consider costs) +}; + +/// Options for dtNavMeshQuery::raycast +enum dtRaycastOptions +{ + DT_RAYCAST_USE_COSTS = 0x01, ///< Raycast should calculate movement cost along the ray and fill RaycastHit::cost +}; + + +/// Limit raycasting during any angle pahfinding +/// The limit is given as a multiple of the character radius +static const float DT_RAY_CAST_LIMIT_PROPORTIONS = 50.0f; + /// Flags representing the type of a navigation mesh polygon. enum dtPolyTypes { diff --git a/dep/recastnavigation/Detour/DetourNavMeshBuilder.h b/dep/recastnavigation/Detour/Include/DetourNavMeshBuilder.h index c80d1717630..c80d1717630 100644 --- a/dep/recastnavigation/Detour/DetourNavMeshBuilder.h +++ b/dep/recastnavigation/Detour/Include/DetourNavMeshBuilder.h diff --git a/dep/recastnavigation/Detour/DetourNavMeshQuery.h b/dep/recastnavigation/Detour/Include/DetourNavMeshQuery.h index 4a5112c9eb9..c7b360dcdc6 100644 --- a/dep/recastnavigation/Detour/DetourNavMeshQuery.h +++ b/dep/recastnavigation/Detour/Include/DetourNavMeshQuery.h @@ -41,6 +41,10 @@ class dtQueryFilter public: dtQueryFilter(); +#ifdef DT_VIRTUAL_QUERYFILTER + virtual ~dtQueryFilter() { } +#endif + /// Returns true if the polygon can be visited. (I.e. Is traversable.) /// @param[in] ref The reference id of the polygon test. /// @param[in] tile The tile containing the polygon. @@ -115,6 +119,34 @@ public: }; + + +/// Provides information about raycast hit +/// filled by dtNavMeshQuery::raycast +/// @ingroup detour +struct dtRaycastHit +{ + /// The hit parameter. (FLT_MAX if no wall hit.) + float t; + + /// hitNormal The normal of the nearest wall hit. [(x, y, z)] + float hitNormal[3]; + + /// Pointer to an array of reference ids of the visited polygons. [opt] + dtPolyRef* path; + + /// The number of visited polygons. [opt] + int pathCount; + + /// The maximum number of polygons the @p path array can hold. + int maxPath; + + /// The cost of the path until hit. + float pathCost; +}; + + + /// Provides the ability to perform pathfinding related queries against /// a navigation mesh. /// @ingroup detour @@ -179,10 +211,11 @@ public: /// @param[in] startPos A position within the start polygon. [(x, y, z)] /// @param[in] endPos A position within the end polygon. [(x, y, z)] /// @param[in] filter The polygon filter to apply to the query. + /// @param[in] options query options (see: #dtFindPathOptions) /// @returns The status flags for the query. dtStatus initSlicedFindPath(dtPolyRef startRef, dtPolyRef endRef, const float* startPos, const float* endPos, - const dtQueryFilter* filter); + const dtQueryFilter* filter, const unsigned int options = 0); /// Updates an in-progress sliced path query. /// @param[in] maxIter The maximum number of iterations to perform. @@ -308,6 +341,7 @@ public: /// Casts a 'walkability' ray along the surface of the navigation mesh from /// the start position toward the end position. + /// @note A wrapper around raycast(..., RaycastHit*). Retained for backward compatibility. /// @param[in] startRef The reference id of the start polygon. /// @param[in] startPos A position within the start polygon representing /// the start of the ray. [(x, y, z)] @@ -323,6 +357,22 @@ public: const dtQueryFilter* filter, float* t, float* hitNormal, dtPolyRef* path, int* pathCount, const int maxPath) const; + /// Casts a 'walkability' ray along the surface of the navigation mesh from + /// the start position toward the end position. + /// @param[in] startRef The reference id of the start polygon. + /// @param[in] startPos A position within the start polygon representing + /// the start of the ray. [(x, y, z)] + /// @param[in] endPos The position to cast the ray toward. [(x, y, z)] + /// @param[in] filter The polygon filter to apply to the query. + /// @param[in] flags govern how the raycast behaves. See dtRaycastOptions + /// @param[out] hit Pointer to a raycast hit structure which will be filled by the results. + /// @param[in] prevRef parent of start ref. Used during for cost calculation [opt] + /// @returns The status flags for the query. + dtStatus raycast(dtPolyRef startRef, const float* startPos, const float* endPos, + const dtQueryFilter* filter, const unsigned int options, + dtRaycastHit* hit, dtPolyRef prevRef = 0) const; + + /// Finds the distance from the specified position to the nearest polygon wall. /// @param[in] startRef The reference id of the polygon containing @p centerPos. /// @param[in] centerPos The center of the search circle. [(x, y, z)] @@ -463,6 +513,8 @@ private: dtPolyRef startRef, endRef; float startPos[3], endPos[3]; const dtQueryFilter* filter; + unsigned int options; + float raycastLimitSqr; }; dtQueryData m_query; ///< Sliced query state. diff --git a/dep/recastnavigation/Detour/DetourNode.h b/dep/recastnavigation/Detour/Include/DetourNode.h index b68c922d038..6fefdc8e0f3 100644 --- a/dep/recastnavigation/Detour/DetourNode.h +++ b/dep/recastnavigation/Detour/Include/DetourNode.h @@ -25,6 +25,7 @@ enum dtNodeFlags { DT_NODE_OPEN = 0x01, DT_NODE_CLOSED = 0x02, + DT_NODE_PARENT_DETACHED = 0x04, // parent of the node is not adjacent. Found using raycast. }; typedef unsigned short dtNodeIndex; @@ -35,12 +36,17 @@ struct dtNode float pos[3]; ///< Position of the node. float cost; ///< Cost from previous node to current node. float total; ///< Cost up to the node. - unsigned int pidx : 30; ///< Index to parent node. - unsigned int flags : 2; ///< Node flags 0/open/closed. + unsigned int pidx : 24; ///< Index to parent node. + unsigned int state : 2; ///< extra state information. A polyRef can have multiple nodes with different extra info. see DT_MAX_STATES_PER_NODE + unsigned int flags : 3; ///< Node flags. A combination of dtNodeFlags. dtPolyRef id; ///< Polygon ref the node corresponds to. }; +static const int DT_MAX_STATES_PER_NODE = 4; // number of extra states per node. See dtNode::state + + + class dtNodePool { public: @@ -48,8 +54,12 @@ public: ~dtNodePool(); inline void operator=(const dtNodePool&) {} void clear(); - dtNode* getNode(dtPolyRef id); - dtNode* findNode(dtPolyRef id); + + // Get a dtNode by ref and extra state information. If there is none then - allocate + // There can be more than one node for the same polyRef but with different extra state information + dtNode* getNode(dtPolyRef id, unsigned char state=0); + dtNode* findNode(dtPolyRef id, unsigned char state); + unsigned int findNodes(dtPolyRef id, dtNode** nodes, const int maxNodes); inline unsigned int getNodeIdx(const dtNode* node) const { @@ -82,6 +92,7 @@ public: inline int getHashSize() const { return m_hashSize; } inline dtNodeIndex getFirst(int bucket) const { return m_first[bucket]; } inline dtNodeIndex getNext(int i) const { return m_next[i]; } + inline int getNodeCount() const { return m_nodeCount; } private: diff --git a/dep/recastnavigation/Detour/DetourStatus.h b/dep/recastnavigation/Detour/Include/DetourStatus.h index af822c4a92d..af822c4a92d 100644 --- a/dep/recastnavigation/Detour/DetourStatus.h +++ b/dep/recastnavigation/Detour/Include/DetourStatus.h diff --git a/dep/recastnavigation/Detour/DetourAlloc.cpp b/dep/recastnavigation/Detour/Source/DetourAlloc.cpp index 5f671df5bdb..5f671df5bdb 100644 --- a/dep/recastnavigation/Detour/DetourAlloc.cpp +++ b/dep/recastnavigation/Detour/Source/DetourAlloc.cpp diff --git a/dep/recastnavigation/Detour/DetourCommon.cpp b/dep/recastnavigation/Detour/Source/DetourCommon.cpp index b5700f5930b..b5700f5930b 100644 --- a/dep/recastnavigation/Detour/DetourCommon.cpp +++ b/dep/recastnavigation/Detour/Source/DetourCommon.cpp diff --git a/dep/recastnavigation/Detour/DetourNavMesh.cpp b/dep/recastnavigation/Detour/Source/DetourNavMesh.cpp index 51740509950..51740509950 100644 --- a/dep/recastnavigation/Detour/DetourNavMesh.cpp +++ b/dep/recastnavigation/Detour/Source/DetourNavMesh.cpp diff --git a/dep/recastnavigation/Detour/DetourNavMeshBuilder.cpp b/dep/recastnavigation/Detour/Source/DetourNavMeshBuilder.cpp index 9d8471b96a1..9d8471b96a1 100644 --- a/dep/recastnavigation/Detour/DetourNavMeshBuilder.cpp +++ b/dep/recastnavigation/Detour/Source/DetourNavMeshBuilder.cpp diff --git a/dep/recastnavigation/Detour/DetourNavMeshQuery.cpp b/dep/recastnavigation/Detour/Source/DetourNavMeshQuery.cpp index f1709dfd4cf..ec3a2946ea5 100644 --- a/dep/recastnavigation/Detour/DetourNavMeshQuery.cpp +++ b/dep/recastnavigation/Detour/Source/DetourNavMeshQuery.cpp @@ -1011,7 +1011,13 @@ dtStatus dtNavMeshQuery::findPath(dtPolyRef startRef, dtPolyRef endRef, if (!filter->passFilter(neighbourRef, neighbourTile, neighbourPoly)) continue; - dtNode* neighbourNode = m_nodePool->getNode(neighbourRef); + // deal explicitly with crossing tile boundaries + unsigned char crossSide = 0; + if (bestTile->links[i].side != 0xff) + crossSide = bestTile->links[i].side >> 1; + + // get the node + dtNode* neighbourNode = m_nodePool->getNode(neighbourRef, crossSide); if (!neighbourNode) { status |= DT_OUT_OF_NODES; @@ -1139,7 +1145,7 @@ dtStatus dtNavMeshQuery::findPath(dtPolyRef startRef, dtPolyRef endRef, /// dtStatus dtNavMeshQuery::initSlicedFindPath(dtPolyRef startRef, dtPolyRef endRef, const float* startPos, const float* endPos, - const dtQueryFilter* filter) + const dtQueryFilter* filter, const unsigned int options) { dtAssert(m_nav); dtAssert(m_nodePool); @@ -1153,6 +1159,8 @@ dtStatus dtNavMeshQuery::initSlicedFindPath(dtPolyRef startRef, dtPolyRef endRef dtVcopy(m_query.startPos, startPos); dtVcopy(m_query.endPos, endPos); m_query.filter = filter; + m_query.options = options; + m_query.raycastLimitSqr = FLT_MAX; if (!startRef || !endRef) return DT_FAILURE | DT_INVALID_PARAM; @@ -1161,6 +1169,16 @@ dtStatus dtNavMeshQuery::initSlicedFindPath(dtPolyRef startRef, dtPolyRef endRef if (!m_nav->isValidPolyRef(startRef) || !m_nav->isValidPolyRef(endRef)) return DT_FAILURE | DT_INVALID_PARAM; + // trade quality with performance? + if (options & DT_FINDPATH_ANY_ANGLE) + { + // limiting to several times the character radius yields nice results. It is not sensitive + // so it is enough to compute it from the first tile. + const dtMeshTile* tile = m_nav->getTileByRef(startRef); + float agentRadius = tile->header->walkableRadius; + m_query.raycastLimitSqr = dtSqr(agentRadius * DT_RAY_CAST_LIMIT_PROPORTIONS); + } + if (startRef == endRef) { m_query.status = DT_SUCCESS; @@ -1197,6 +1215,9 @@ dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter, int* doneIters) m_query.status = DT_FAILURE; return DT_FAILURE; } + + dtRaycastHit rayHit; + rayHit.maxPath = 0; int iter = 0; while (iter < maxIter && !m_openList->empty()) @@ -1233,15 +1254,22 @@ dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter, int* doneIters) return m_query.status; } - // Get parent poly and tile. - dtPolyRef parentRef = 0; + // Get parent and grand parent poly and tile. + dtPolyRef parentRef = 0, grandpaRef = 0; const dtMeshTile* parentTile = 0; const dtPoly* parentPoly = 0; + dtNode* parentNode = 0; if (bestNode->pidx) - parentRef = m_nodePool->getNodeAtIdx(bestNode->pidx)->id; + { + parentNode = m_nodePool->getNodeAtIdx(bestNode->pidx); + parentRef = parentNode->id; + if (parentNode->pidx) + grandpaRef = m_nodePool->getNodeAtIdx(parentNode->pidx)->id; + } if (parentRef) { - if (dtStatusFailed(m_nav->getTileAndPolyByRef(parentRef, &parentTile, &parentPoly))) + bool invalidParent = dtStatusFailed(m_nav->getTileAndPolyByRef(parentRef, &parentTile, &parentPoly)); + if (invalidParent || (grandpaRef && !m_nav->isValidPolyRef(grandpaRef)) ) { // The polygon has disappeared during the sliced query, fail. m_query.status = DT_FAILURE; @@ -1250,6 +1278,14 @@ dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter, int* doneIters) return m_query.status; } } + + // decide whether to test raycast to previous nodes + bool tryLOS = false; + if (m_query.options & DT_FINDPATH_ANY_ANGLE) + { + if ((parentRef != 0) && (dtVdistSqr(parentNode->pos, bestNode->pos) < m_query.raycastLimitSqr)) + tryLOS = true; + } for (unsigned int i = bestPoly->firstLink; i != DT_NULL_LINK; i = bestTile->links[i].next) { @@ -1268,13 +1304,22 @@ dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter, int* doneIters) if (!m_query.filter->passFilter(neighbourRef, neighbourTile, neighbourPoly)) continue; - dtNode* neighbourNode = m_nodePool->getNode(neighbourRef); + // deal explicitly with crossing tile boundaries + unsigned char crossSide = 0; + if (bestTile->links[i].side != 0xff) + crossSide = bestTile->links[i].side >> 1; + + dtNode* neighbourNode = m_nodePool->getNode(neighbourRef, crossSide); if (!neighbourNode) { m_query.status |= DT_OUT_OF_NODES; continue; } + // do not expand to nodes that were already visited from the same parent + if (neighbourNode->pidx != 0 && neighbourNode->pidx == bestNode->pidx) + continue; + // If the node is visited the first time, calculate node position. if (neighbourNode->flags == 0) { @@ -1287,30 +1332,44 @@ dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter, int* doneIters) float cost = 0; float heuristic = 0; - // Special case for last node. - if (neighbourRef == m_query.endRef) + // raycast parent + bool foundShortCut = false; + rayHit.pathCost = rayHit.t = 0; + if (tryLOS) { - // Cost + raycast(parentRef, parentNode->pos, neighbourNode->pos, m_query.filter, DT_RAYCAST_USE_COSTS, &rayHit, grandpaRef); + foundShortCut = rayHit.t >= 1.0f; + } + + // update move cost + if (foundShortCut) + { + // shortcut found using raycast. Using shorter cost instead + cost = parentNode->cost + rayHit.pathCost; + } + else + { + // No shortcut found. const float curCost = m_query.filter->getCost(bestNode->pos, neighbourNode->pos, parentRef, parentTile, parentPoly, - bestRef, bestTile, bestPoly, - neighbourRef, neighbourTile, neighbourPoly); + bestRef, bestTile, bestPoly, + neighbourRef, neighbourTile, neighbourPoly); + cost = bestNode->cost + curCost; + } + + // Special case for last node. + if (neighbourRef == m_query.endRef) + { const float endCost = m_query.filter->getCost(neighbourNode->pos, m_query.endPos, bestRef, bestTile, bestPoly, neighbourRef, neighbourTile, neighbourPoly, 0, 0, 0); - cost = bestNode->cost + curCost + endCost; + cost = cost + endCost; heuristic = 0; } else { - // Cost - const float curCost = m_query.filter->getCost(bestNode->pos, neighbourNode->pos, - parentRef, parentTile, parentPoly, - bestRef, bestTile, bestPoly, - neighbourRef, neighbourTile, neighbourPoly); - cost = bestNode->cost + curCost; heuristic = dtVdist(neighbourNode->pos, m_query.endPos)*H_SCALE; } @@ -1324,11 +1383,13 @@ dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter, int* doneIters) continue; // Add or update the node. - neighbourNode->pidx = m_nodePool->getNodeIdx(bestNode); + neighbourNode->pidx = foundShortCut ? bestNode->pidx : m_nodePool->getNodeIdx(bestNode); neighbourNode->id = neighbourRef; - neighbourNode->flags = (neighbourNode->flags & ~DT_NODE_CLOSED); + neighbourNode->flags = (neighbourNode->flags & ~(DT_NODE_CLOSED | DT_NODE_PARENT_DETACHED)); neighbourNode->cost = cost; neighbourNode->total = total; + if (foundShortCut) + neighbourNode->flags = (neighbourNode->flags | DT_NODE_PARENT_DETACHED); if (neighbourNode->flags & DT_NODE_OPEN) { @@ -1392,11 +1453,15 @@ dtStatus dtNavMeshQuery::finalizeSlicedFindPath(dtPolyRef* path, int* pathCount, dtNode* prev = 0; dtNode* node = m_query.lastBestNode; + int prevRay = 0; do { dtNode* next = m_nodePool->getNodeAtIdx(node->pidx); node->pidx = m_nodePool->getNodeIdx(prev); prev = node; + int nextRay = node->flags & DT_NODE_PARENT_DETACHED; // keep track of whether parent is not adjacent (i.e. due to raycast shortcut) + node->flags = (node->flags & ~DT_NODE_PARENT_DETACHED) | prevRay; // and store it in the reversed path's node + prevRay = nextRay; node = next; } while (node); @@ -1405,13 +1470,31 @@ dtStatus dtNavMeshQuery::finalizeSlicedFindPath(dtPolyRef* path, int* pathCount, node = prev; do { - path[n++] = node->id; - if (n >= maxPath) + dtNode* next = m_nodePool->getNodeAtIdx(node->pidx); + dtStatus status = 0; + if (node->flags & DT_NODE_PARENT_DETACHED) { - m_query.status |= DT_BUFFER_TOO_SMALL; + float t, normal[3]; + int m; + status = raycast(node->id, node->pos, next->pos, m_query.filter, &t, normal, path+n, &m, maxPath-n); + n += m; + // raycast ends on poly boundary and the path might include the next poly boundary. + if (path[n-1] == next->id) + n--; // remove to avoid duplicates + } + else + { + path[n++] = node->id; + if (n >= maxPath) + status = DT_BUFFER_TOO_SMALL; + } + + if (status & DT_STATUS_DETAIL_MASK) + { + m_query.status |= status & DT_STATUS_DETAIL_MASK; break; } - node = m_nodePool->getNodeAtIdx(node->pidx); + node = next; } while (node); } @@ -1457,7 +1540,7 @@ dtStatus dtNavMeshQuery::finalizeSlicedFindPathPartial(const dtPolyRef* existing dtNode* node = 0; for (int i = existingSize-1; i >= 0; --i) { - node = m_nodePool->findNode(existing[i]); + m_nodePool->findNodes(existing[i], &node, 1); if (node) break; } @@ -1470,11 +1553,15 @@ dtStatus dtNavMeshQuery::finalizeSlicedFindPathPartial(const dtPolyRef* existing } // Reverse the path. + int prevRay = 0; do { dtNode* next = m_nodePool->getNodeAtIdx(node->pidx); node->pidx = m_nodePool->getNodeIdx(prev); prev = node; + int nextRay = node->flags & DT_NODE_PARENT_DETACHED; // keep track of whether parent is not adjacent (i.e. due to raycast shortcut) + node->flags = (node->flags & ~DT_NODE_PARENT_DETACHED) | prevRay; // and store it in the reversed path's node + prevRay = nextRay; node = next; } while (node); @@ -1483,13 +1570,31 @@ dtStatus dtNavMeshQuery::finalizeSlicedFindPathPartial(const dtPolyRef* existing node = prev; do { - path[n++] = node->id; - if (n >= maxPath) + dtNode* next = m_nodePool->getNodeAtIdx(node->pidx); + dtStatus status = 0; + if (node->flags & DT_NODE_PARENT_DETACHED) + { + float t, normal[3]; + int m; + status = raycast(node->id, node->pos, next->pos, m_query.filter, &t, normal, path+n, &m, maxPath-n); + n += m; + // raycast ends on poly boundary and the path might include the next poly boundary. + if (path[n-1] == next->id) + n--; // remove to avoid duplicates + } + else + { + path[n++] = node->id; + if (n >= maxPath) + status = DT_BUFFER_TOO_SMALL; + } + + if (status & DT_STATUS_DETAIL_MASK) { - m_query.status |= DT_BUFFER_TOO_SMALL; + m_query.status |= status & DT_STATUS_DETAIL_MASK; break; } - node = m_nodePool->getNodeAtIdx(node->pidx); + node = next; } while (node); } @@ -2161,6 +2266,8 @@ dtStatus dtNavMeshQuery::getEdgeMidPoint(dtPolyRef from, const dtPoly* fromPoly, return DT_SUCCESS; } + + /// @par /// /// This method is meant to be used for quick, short distance checks. @@ -2203,73 +2310,144 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons const dtQueryFilter* filter, float* t, float* hitNormal, dtPolyRef* path, int* pathCount, const int maxPath) const { - dtAssert(m_nav); + dtRaycastHit hit; + hit.path = path; + hit.maxPath = maxPath; + + dtStatus status = raycast(startRef, startPos, endPos, filter, 0, &hit); - *t = 0; + *t = hit.t; + if (hitNormal) + dtVcopy(hitNormal, hit.hitNormal); if (pathCount) - *pathCount = 0; + *pathCount = hit.pathCount; + + return status; +} + + +/// @par +/// +/// This method is meant to be used for quick, short distance checks. +/// +/// If the path array is too small to hold the result, it will be filled as +/// far as possible from the start postion toward the end position. +/// +/// <b>Using the Hit Parameter t of RaycastHit</b> +/// +/// If the hit parameter is a very high value (FLT_MAX), then the ray has hit +/// the end position. In this case the path represents a valid corridor to the +/// end position and the value of @p hitNormal is undefined. +/// +/// If the hit parameter is zero, then the start position is on the wall that +/// was hit and the value of @p hitNormal is undefined. +/// +/// If 0 < t < 1.0 then the following applies: +/// +/// @code +/// distanceToHitBorder = distanceToEndPosition * t +/// hitPoint = startPos + (endPos - startPos) * t +/// @endcode +/// +/// <b>Use Case Restriction</b> +/// +/// The raycast ignores the y-value of the end position. (2D check.) This +/// places significant limits on how it can be used. For example: +/// +/// Consider a scene where there is a main floor with a second floor balcony +/// that hangs over the main floor. So the first floor mesh extends below the +/// balcony mesh. The start position is somewhere on the first floor. The end +/// position is on the balcony. +/// +/// The raycast will search toward the end position along the first floor mesh. +/// If it reaches the end position's xz-coordinates it will indicate FLT_MAX +/// (no wall hit), meaning it reached the end position. This is one example of why +/// this method is meant for short distance checks. +/// +dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, const float* endPos, + const dtQueryFilter* filter, const unsigned int options, + dtRaycastHit* hit, dtPolyRef prevRef) const +{ + dtAssert(m_nav); + hit->t = 0; + hit->pathCount = 0; + hit->pathCost = 0; + // Validate input if (!startRef || !m_nav->isValidPolyRef(startRef)) return DT_FAILURE | DT_INVALID_PARAM; + if (prevRef && !m_nav->isValidPolyRef(prevRef)) + return DT_FAILURE | DT_INVALID_PARAM; - dtPolyRef curRef = startRef; - float verts[DT_VERTS_PER_POLYGON*3]; + float dir[3], curPos[3], lastPos[3]; + float verts[DT_VERTS_PER_POLYGON*3+3]; int n = 0; - - hitNormal[0] = 0; - hitNormal[1] = 0; - hitNormal[2] = 0; - + + dtVcopy(curPos, startPos); + dtVsub(dir, endPos, startPos); + dtVset(hit->hitNormal, 0, 0, 0); + dtStatus status = DT_SUCCESS; - + + const dtMeshTile* prevTile, *tile, *nextTile; + const dtPoly* prevPoly, *poly, *nextPoly; + dtPolyRef curRef, nextRef; + + // The API input has been checked already, skip checking internal data. + nextRef = curRef = startRef; + tile = 0; + poly = 0; + m_nav->getTileAndPolyByRefUnsafe(curRef, &tile, &poly); + nextTile = prevTile = tile; + nextPoly = prevPoly = poly; + if (prevRef) + m_nav->getTileAndPolyByRefUnsafe(prevRef, &prevTile, &prevPoly); + while (curRef) { // Cast ray against current polygon. - // The API input has been cheked already, skip checking internal data. - const dtMeshTile* tile = 0; - const dtPoly* poly = 0; - m_nav->getTileAndPolyByRefUnsafe(curRef, &tile, &poly); - // Collect vertices. int nv = 0; for (int i = 0; i < (int)poly->vertCount; ++i) { dtVcopy(&verts[nv*3], &tile->verts[poly->verts[i]*3]); nv++; - } + } float tmin, tmax; int segMin, segMax; if (!dtIntersectSegmentPoly2D(startPos, endPos, verts, nv, tmin, tmax, segMin, segMax)) { // Could not hit the polygon, keep the old t and report hit. - if (pathCount) - *pathCount = n; + hit->pathCount = n; return status; } // Keep track of furthest t so far. - if (tmax > *t) - *t = tmax; + if (tmax > hit->t) + hit->t = tmax; // Store visited polygons. - if (n < maxPath) - path[n++] = curRef; + if (n < hit->maxPath) + hit->path[n++] = curRef; else status |= DT_BUFFER_TOO_SMALL; - + // Ray end is completely inside the polygon. if (segMax == -1) { - *t = FLT_MAX; - if (pathCount) - *pathCount = n; + hit->t = FLT_MAX; + hit->pathCount = n; + + // add the cost + if (options & DT_RAYCAST_USE_COSTS) + hit->pathCost += filter->getCost(curPos, endPos, prevRef, prevTile, prevPoly, curRef, tile, poly, curRef, tile, poly); return status; } - + // Follow neighbours. - dtPolyRef nextRef = 0; + nextRef = 0; for (unsigned int i = poly->firstLink; i != DT_NULL_LINK; i = tile->links[i].next) { @@ -2280,8 +2458,8 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons continue; // Get pointer to the next polygon. - const dtMeshTile* nextTile = 0; - const dtPoly* nextPoly = 0; + nextTile = 0; + nextPoly = 0; m_nav->getTileAndPolyByRefUnsafe(link->ref, &nextTile, &nextPoly); // Skip off-mesh connections. @@ -2349,6 +2527,24 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons } } + // add the cost + if (options & DT_RAYCAST_USE_COSTS) + { + // compute the intersection point at the furthest end of the polygon + // and correct the height (since the raycast moves in 2d) + dtVcopy(lastPos, curPos); + dtVmad(curPos, startPos, dir, hit->t); + float* e1 = &verts[segMax*3]; + float* e2 = &verts[((segMax+1)%nv)*3]; + float eDir[3], diff[3]; + dtVsub(eDir, e2, e1); + dtVsub(diff, curPos, e1); + float s = dtSqr(eDir[0]) > dtSqr(eDir[2]) ? diff[0] / eDir[0] : diff[2] / eDir[2]; + curPos[1] = e1[1] + eDir[1] * s; + + hit->pathCost += filter->getCost(lastPos, curPos, prevRef, prevTile, prevPoly, curRef, tile, poly, nextRef, nextTile, nextPoly); + } + if (!nextRef) { // No neighbour, we hit a wall. @@ -2360,22 +2556,25 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons const float* vb = &verts[b*3]; const float dx = vb[0] - va[0]; const float dz = vb[2] - va[2]; - hitNormal[0] = dz; - hitNormal[1] = 0; - hitNormal[2] = -dx; - dtVnormalize(hitNormal); + hit->hitNormal[0] = dz; + hit->hitNormal[1] = 0; + hit->hitNormal[2] = -dx; + dtVnormalize(hit->hitNormal); - if (pathCount) - *pathCount = n; + hit->pathCount = n; return status; } - + // No hit, advance to neighbour polygon. + prevRef = curRef; curRef = nextRef; + prevTile = tile; + tile = nextTile; + prevPoly = poly; + poly = nextPoly; } - if (pathCount) - *pathCount = n; + hit->pathCount = n; return status; } @@ -3333,6 +3532,15 @@ bool dtNavMeshQuery::isValidPolyRef(dtPolyRef ref, const dtQueryFilter* filter) bool dtNavMeshQuery::isInClosedList(dtPolyRef ref) const { if (!m_nodePool) return false; - const dtNode* node = m_nodePool->findNode(ref); - return node && node->flags & DT_NODE_CLOSED; + + dtNode* nodes[DT_MAX_STATES_PER_NODE]; + int n= m_nodePool->findNodes(ref, nodes, DT_MAX_STATES_PER_NODE); + + for (int i=0; i<n; i++) + { + if (nodes[i]->flags & DT_NODE_CLOSED) + return true; + } + + return false; } diff --git a/dep/recastnavigation/Detour/DetourNode.cpp b/dep/recastnavigation/Detour/Source/DetourNode.cpp index 4c8215e20d0..1d1897708f4 100644 --- a/dep/recastnavigation/Detour/DetourNode.cpp +++ b/dep/recastnavigation/Detour/Source/DetourNode.cpp @@ -71,27 +71,46 @@ void dtNodePool::clear() m_nodeCount = 0; } -dtNode* dtNodePool::findNode(dtPolyRef id) +unsigned int dtNodePool::findNodes(dtPolyRef id, dtNode** nodes, const int maxNodes) { + int n = 0; unsigned int bucket = dtHashRef(id) & (m_hashSize-1); dtNodeIndex i = m_first[bucket]; while (i != DT_NULL_IDX) { if (m_nodes[i].id == id) + { + if (n >= maxNodes) + return n; + nodes[n++] = &m_nodes[i]; + } + i = m_next[i]; + } + + return n; +} + +dtNode* dtNodePool::findNode(dtPolyRef id, unsigned char state) +{ + unsigned int bucket = dtHashRef(id) & (m_hashSize-1); + dtNodeIndex i = m_first[bucket]; + while (i != DT_NULL_IDX) + { + if (m_nodes[i].id == id && m_nodes[i].state == state) return &m_nodes[i]; i = m_next[i]; } return 0; } -dtNode* dtNodePool::getNode(dtPolyRef id) +dtNode* dtNodePool::getNode(dtPolyRef id, unsigned char state) { unsigned int bucket = dtHashRef(id) & (m_hashSize-1); dtNodeIndex i = m_first[bucket]; dtNode* node = 0; while (i != DT_NULL_IDX) { - if (m_nodes[i].id == id) + if (m_nodes[i].id == id && m_nodes[i].state == state) return &m_nodes[i]; i = m_next[i]; } @@ -108,6 +127,7 @@ dtNode* dtNodePool::getNode(dtPolyRef id) node->cost = 0; node->total = 0; node->id = id; + node->state = state; node->flags = 0; m_next[i] = m_first[bucket]; diff --git a/dep/recastnavigation/Readme.txt b/dep/recastnavigation/Readme.txt index 0c2f7b1675f..1383b01d582 100644 --- a/dep/recastnavigation/Readme.txt +++ b/dep/recastnavigation/Readme.txt @@ -32,9 +32,6 @@ the regions as simple polygons. The toolset code is located in the Recast folder and demo application using the Recast toolset is located in the RecastDemo folder. -The project files with this distribution can be compiled with Microsoft Visual C++ 2008 -(you can download it for free) and XCode 3.1. - Detour @@ -43,78 +40,7 @@ Recast is accompanied with Detour, path-finding and spatial reasoning toolkit. Y Detour offers simple static navigation mesh which is suitable for many simple cases, as well as tiled navigation mesh which allows you to plug in and out pieces of the mesh. The tiled mesh allows to create systems where you stream new navigation data in and out as the player progresses the level, or you may regenerate tiles as the world changes. -Latest code available at http://code.google.com/p/recastnavigation/ - - --- - -Release Notes - ----------------- -* Recast 1.4 - Released August 24th, 2009 - -- Added detail height mesh generation (RecastDetailMesh.cpp) for single, - tiled statmeshes as well as tilemesh. -- Added feature to contour tracing which detects extra vertices along - tile edges which should be removed later. -- Changed the tiled stat mesh preprocess, so that it first generated - polymeshes per tile and finally combines them. -- Fixed bug in the GUI code where invisible buttons could be pressed. - ----------------- -* Recast 1.31 - Released July 24th, 2009 - -- Better cost and heuristic functions. -- Fixed tile navmesh raycast on tile borders. - ----------------- -* Recast 1.3 - Released July 14th, 2009 - -- Added dtTileNavMesh which allows to dynamically add and remove navmesh pieces at runtime. -- Renamed stat navmesh types to dtStat* (i.e. dtPoly is now dtStatPoly). -- Moved common code used by tile and stat navmesh to DetourNode.h/cpp and DetourCommon.h/cpp. -- Refactores the demo code. - ----------------- -* Recast 1.2 - Released June 17th, 2009 - -- Added tiled mesh generation. The tiled generation allows to generate navigation for - much larger worlds, it removes some of the artifacts that comes from distance fields - in open areas, and allows later streaming and dynamic runtime generation -- Improved and added some debug draw modes -- API change: The helper function rcBuildNavMesh does not exists anymore, - had to change few internal things to cope with the tiled processing, - similar API functionality will be added later once the tiled process matures -- The demo is getting way too complicated, need to split demos -- Fixed several filtering functions so that the mesh is tighter to the geometry, - sometimes there could be up error up to tow voxel units close to walls, - now it should be just one. - ----------------- -* Recast 1.1 - Released April 11th, 2009 - -This is the first release of Detour. - ----------------- -* Recast 1.0 - Released March 29th, 2009 - -This is the first release of Recast. - -The process is not always as robust as I would wish. The watershed phase sometimes swallows tiny islands -which are close to edges. These droppings are handled in rcBuildContours, but the code is not -particularly robust either. - -Another non-robust case is when portal contours (contours shared between two regions) are always -assumed to be straight. That can lead to overlapping contours specially when the level has -large open areas. - - +Latest code available at https://github.com/memononen/recastnavigation Mikko Mononen memon@inside.org diff --git a/dep/recastnavigation/Recast/CMakeLists.txt b/dep/recastnavigation/Recast/CMakeLists.txt index 10028f8535f..f4869bf8773 100644 --- a/dep/recastnavigation/Recast/CMakeLists.txt +++ b/dep/recastnavigation/Recast/CMakeLists.txt @@ -9,18 +9,20 @@ # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. set(Recast_STAT_SRCS - Recast.cpp - RecastAlloc.cpp - RecastArea.cpp - RecastContour.cpp - RecastFilter.cpp - RecastLayers.cpp - RecastMesh.cpp - RecastMeshDetail.cpp - RecastRasterization.cpp - RecastRegion.cpp + Source/Recast.cpp + Source/RecastAlloc.cpp + Source/RecastArea.cpp + Source/RecastContour.cpp + Source/RecastFilter.cpp + Source/RecastLayers.cpp + Source/RecastMesh.cpp + Source/RecastMeshDetail.cpp + Source/RecastRasterization.cpp + Source/RecastRegion.cpp ) +include_directories(Include) + if(WIN32) include_directories( ${CMAKE_SOURCE_DIR}/dep/zlib diff --git a/dep/recastnavigation/Recast/Recast.h b/dep/recastnavigation/Recast/Include/Recast.h index 3f4ae96d1c9..66974cdbcc3 100644 --- a/dep/recastnavigation/Recast/Recast.h +++ b/dep/recastnavigation/Recast/Include/Recast.h @@ -338,7 +338,7 @@ struct rcHeightfieldLayer int maxy; ///< The maximum y-bounds of usable data. (Along the z-axis.) int hmin; ///< The minimum height bounds of usable data. (Along the y-axis.) int hmax; ///< The maximum height bounds of usable data. (Along the y-axis.) - unsigned char* heights; ///< The heightfield. [Size: (width - borderSize*2) * (h - borderSize*2)] + unsigned char* heights; ///< The heightfield. [Size: width * height] unsigned char* areas; ///< Area ids. [Size: Same as #heights] unsigned char* cons; ///< Packed neighbor connection information. [Size: Same as #heights] }; @@ -969,7 +969,7 @@ void rcMarkCylinderArea(rcContext* ctx, const float* pos, /// @returns True if the operation completed successfully. bool rcBuildDistanceField(rcContext* ctx, rcCompactHeightfield& chf); -/// Builds region data for the heightfield using watershed partitioning. +/// Builds region data for the heightfield using watershed partitioning. /// @ingroup recast /// @param[in,out] ctx The build context to use during the operation. /// @param[in,out] chf A populated compact heightfield. @@ -983,6 +983,18 @@ bool rcBuildDistanceField(rcContext* ctx, rcCompactHeightfield& chf); bool rcBuildRegions(rcContext* ctx, rcCompactHeightfield& chf, const int borderSize, const int minRegionArea, const int mergeRegionArea); +/// Builds region data for the heightfield by partitioning the heightfield in non-overlapping layers. +/// @ingroup recast +/// @param[in,out] ctx The build context to use during the operation. +/// @param[in,out] chf A populated compact heightfield. +/// @param[in] borderSize The size of the non-navigable border around the heightfield. +/// [Limit: >=0] [Units: vx] +/// @param[in] minRegionArea The minimum number of cells allowed to form isolated island areas. +/// [Limit: >=0] [Units: vx]. +/// @returns True if the operation completed successfully. +bool rcBuildLayerRegions(rcContext* ctx, rcCompactHeightfield& chf, + const int borderSize, const int minRegionArea); + /// Builds region data for the heightfield using simple monotone partitioning. /// @ingroup recast /// @param[in,out] ctx The build context to use during the operation. @@ -997,7 +1009,6 @@ bool rcBuildRegions(rcContext* ctx, rcCompactHeightfield& chf, bool rcBuildRegionsMonotone(rcContext* ctx, rcCompactHeightfield& chf, const int borderSize, const int minRegionArea, const int mergeRegionArea); - /// Sets the neighbor connection data for the specified direction. /// @param[in] s The span to update. /// @param[in] dir The direction to set. [Limits: 0 <= value < 4] diff --git a/dep/recastnavigation/Recast/RecastAlloc.h b/dep/recastnavigation/Recast/Include/RecastAlloc.h index 438be9ea56b..438be9ea56b 100644 --- a/dep/recastnavigation/Recast/RecastAlloc.h +++ b/dep/recastnavigation/Recast/Include/RecastAlloc.h diff --git a/dep/recastnavigation/Recast/RecastAssert.h b/dep/recastnavigation/Recast/Include/RecastAssert.h index 2aca0d9a14f..2aca0d9a14f 100644 --- a/dep/recastnavigation/Recast/RecastAssert.h +++ b/dep/recastnavigation/Recast/Include/RecastAssert.h diff --git a/dep/recastnavigation/Recast/Recast.cpp b/dep/recastnavigation/Recast/Source/Recast.cpp index b9d86036c3f..b9d86036c3f 100644 --- a/dep/recastnavigation/Recast/Recast.cpp +++ b/dep/recastnavigation/Recast/Source/Recast.cpp diff --git a/dep/recastnavigation/Recast/RecastAlloc.cpp b/dep/recastnavigation/Recast/Source/RecastAlloc.cpp index b5ec1516146..b5ec1516146 100644 --- a/dep/recastnavigation/Recast/RecastAlloc.cpp +++ b/dep/recastnavigation/Recast/Source/RecastAlloc.cpp diff --git a/dep/recastnavigation/Recast/RecastArea.cpp b/dep/recastnavigation/Recast/Source/RecastArea.cpp index 1a338cd9b8c..1a338cd9b8c 100644 --- a/dep/recastnavigation/Recast/RecastArea.cpp +++ b/dep/recastnavigation/Recast/Source/RecastArea.cpp diff --git a/dep/recastnavigation/Recast/RecastContour.cpp b/dep/recastnavigation/Recast/Source/RecastContour.cpp index 5c324bcedfe..8aa9d1d92a1 100644 --- a/dep/recastnavigation/Recast/RecastContour.cpp +++ b/dep/recastnavigation/Recast/Source/RecastContour.cpp @@ -20,6 +20,7 @@ #include <math.h> #include <string.h> #include <stdio.h> +#include <stdlib.h> #include "Recast.h" #include "RecastAlloc.h" #include "RecastAssert.h" @@ -36,7 +37,7 @@ static int getCornerHeight(int x, int y, int i, int dir, unsigned int regs[4] = {0,0,0,0}; // Combine region and area codes in order to prevent - // border vertices which are in between two areas to be removed. + // border vertices which are in between two areas to be removed. regs[0] = chf.spans[i].reg | (chf.areas[i] << 16); if (rcGetCon(s, dir) != RC_NOT_CONNECTED) @@ -187,27 +188,6 @@ static float distancePtSeg(const int x, const int z, const int px, const int pz, const int qx, const int qz) { -/* float pqx = (float)(qx - px); - float pqy = (float)(qy - py); - float pqz = (float)(qz - pz); - float dx = (float)(x - px); - float dy = (float)(y - py); - float dz = (float)(z - pz); - float d = pqx*pqx + pqy*pqy + pqz*pqz; - float t = pqx*dx + pqy*dy + pqz*dz; - if (d > 0) - t /= d; - if (t < 0) - t = 0; - else if (t > 1) - t = 1; - - dx = px + t*pqx - x; - dy = py + t*pqy - y; - dz = pz + t*pqz - z; - - return dx*dx + dy*dy + dz*dz;*/ - float pqx = (float)(qx - px); float pqz = (float)(qz - pz); float dx = (float)(x - px); @@ -257,13 +237,13 @@ static void simplifyContour(rcIntArray& points, rcIntArray& simplified, simplified.push(points[i*4+2]); simplified.push(i); } - } + } } if (simplified.size() == 0) { // If there is no connections at all, - // create some initial points for the simplification process. + // create some initial points for the simplification process. // Find lower-left and upper-right vertices of the contour. int llx = points[0]; int lly = points[1]; @@ -311,19 +291,19 @@ static void simplifyContour(rcIntArray& points, rcIntArray& simplified, { int ii = (i+1) % (simplified.size()/4); - const int ax = simplified[i*4+0]; - const int az = simplified[i*4+2]; - const int ai = simplified[i*4+3]; - - const int bx = simplified[ii*4+0]; - const int bz = simplified[ii*4+2]; - const int bi = simplified[ii*4+3]; + int ax = simplified[i*4+0]; + int az = simplified[i*4+2]; + int ai = simplified[i*4+3]; + + int bx = simplified[ii*4+0]; + int bz = simplified[ii*4+2]; + int bi = simplified[ii*4+3]; // Find maximum deviation from the segment. float maxd = 0; int maxi = -1; int ci, cinc, endi; - + // Traverse the segment in lexilogical order so that the // max deviation is calculated similarly when traversing // opposite segments. @@ -338,6 +318,8 @@ static void simplifyContour(rcIntArray& points, rcIntArray& simplified, cinc = pn-1; ci = (bi+cinc) % pn; endi = ai; + rcSwap(ax, bx); + rcSwap(az, bz); } // Tessellate only outer edges or edges between areas. @@ -397,11 +379,11 @@ static void simplifyContour(rcIntArray& points, rcIntArray& simplified, const int bx = simplified[ii*4+0]; const int bz = simplified[ii*4+2]; const int bi = simplified[ii*4+3]; - + // Find maximum deviation from the segment. int maxi = -1; int ci = (ai+1) % pn; - + // Tessellate only outer edges or edges between areas. bool tess = false; // Wall edges. @@ -469,32 +451,6 @@ static void simplifyContour(rcIntArray& points, rcIntArray& simplified, } -static void removeDegenerateSegments(rcIntArray& simplified) -{ - // Remove adjacent vertices which are equal on xz-plane, - // or else the triangulator will get confused. - for (int i = 0; i < simplified.size()/4; ++i) - { - int ni = i+1; - if (ni >= (simplified.size()/4)) - ni = 0; - - if (simplified[i*4+0] == simplified[ni*4+0] && - simplified[i*4+2] == simplified[ni*4+2]) - { - // Degenerate segment, remove. - for (int j = i; j < simplified.size()/4-1; ++j) - { - simplified[j*4+0] = simplified[(j+1)*4+0]; - simplified[j*4+1] = simplified[(j+1)*4+1]; - simplified[j*4+2] = simplified[(j+1)*4+2]; - simplified[j*4+3] = simplified[(j+1)*4+3]; - } - simplified.resize(simplified.size()-4); - } - } -} - static int calcAreaOfPolygon2D(const int* verts, const int nverts) { int area = 0; @@ -507,54 +463,155 @@ static int calcAreaOfPolygon2D(const int* verts, const int nverts) return (area+1) / 2; } -inline bool ileft(const int* a, const int* b, const int* c) +// TODO: these are the same as in RecastMesh.cpp, consider using the same. + +inline int prev(int i, int n) { return i-1 >= 0 ? i-1 : n-1; } +inline int next(int i, int n) { return i+1 < n ? i+1 : 0; } + +inline int area2(const int* a, const int* b, const int* c) +{ + return (b[0] - a[0]) * (c[2] - a[2]) - (c[0] - a[0]) * (b[2] - a[2]); +} + +// Exclusive or: true iff exactly one argument is true. +// The arguments are negated to ensure that they are 0/1 +// values. Then the bitwise Xor operator may apply. +// (This idea is due to Michael Baldwin.) +inline bool xorb(bool x, bool y) +{ + return !x ^ !y; +} + +// Returns true iff c is strictly to the left of the directed +// line through a to b. +inline bool left(const int* a, const int* b, const int* c) +{ + return area2(a, b, c) < 0; +} + +inline bool leftOn(const int* a, const int* b, const int* c) +{ + return area2(a, b, c) <= 0; +} + +inline bool collinear(const int* a, const int* b, const int* c) +{ + return area2(a, b, c) == 0; +} + +// Returns true iff ab properly intersects cd: they share +// a point interior to both segments. The properness of the +// intersection is ensured by using strict leftness. +static bool intersectProp(const int* a, const int* b, const int* c, const int* d) +{ + // Eliminate improper cases. + if (collinear(a,b,c) || collinear(a,b,d) || + collinear(c,d,a) || collinear(c,d,b)) + return false; + + return xorb(left(a,b,c), left(a,b,d)) && xorb(left(c,d,a), left(c,d,b)); +} + +// Returns T iff (a,b,c) are collinear and point c lies +// on the closed segement ab. +static bool between(const int* a, const int* b, const int* c) +{ + if (!collinear(a, b, c)) + return false; + // If ab not vertical, check betweenness on x; else on y. + if (a[0] != b[0]) + return ((a[0] <= c[0]) && (c[0] <= b[0])) || ((a[0] >= c[0]) && (c[0] >= b[0])); + else + return ((a[2] <= c[2]) && (c[2] <= b[2])) || ((a[2] >= c[2]) && (c[2] >= b[2])); +} + +// Returns true iff segments ab and cd intersect, properly or improperly. +static bool intersect(const int* a, const int* b, const int* c, const int* d) +{ + if (intersectProp(a, b, c, d)) + return true; + else if (between(a, b, c) || between(a, b, d) || + between(c, d, a) || between(c, d, b)) + return true; + else + return false; +} + +static bool vequal(const int* a, const int* b) +{ + return a[0] == b[0] && a[2] == b[2]; +} + +static bool intersectSegCountour(const int* d0, const int* d1, int i, int n, const int* verts) { - return (b[0] - a[0]) * (c[2] - a[2]) - (c[0] - a[0]) * (b[2] - a[2]) <= 0; + // For each edge (k,k+1) of P + for (int k = 0; k < n; k++) + { + int k1 = next(k, n); + // Skip edges incident to i. + if (i == k || i == k1) + continue; + const int* p0 = &verts[k * 4]; + const int* p1 = &verts[k1 * 4]; + if (vequal(d0, p0) || vequal(d1, p0) || vequal(d0, p1) || vequal(d1, p1)) + continue; + + if (intersect(d0, d1, p0, p1)) + return true; + } + return false; } -static void getClosestIndices(const int* vertsa, const int nvertsa, - const int* vertsb, const int nvertsb, - int& ia, int& ib) +static bool inCone(int i, int n, const int* verts, const int* pj) { - int closestDist = 0xfffffff; - ia = -1, ib = -1; - for (int i = 0; i < nvertsa; ++i) + const int* pi = &verts[i * 4]; + const int* pi1 = &verts[next(i, n) * 4]; + const int* pin1 = &verts[prev(i, n) * 4]; + + // If P[i] is a convex vertex [ i+1 left or on (i-1,i) ]. + if (leftOn(pin1, pi, pi1)) + return left(pi, pj, pin1) && left(pj, pi, pi1); + // Assume (i-1,i,i+1) not collinear. + // else P[i] is reflex. + return !(leftOn(pi, pj, pi1) && leftOn(pj, pi, pin1)); +} + + +static void removeDegenerateSegments(rcIntArray& simplified) +{ + // Remove adjacent vertices which are equal on xz-plane, + // or else the triangulator will get confused. + int npts = simplified.size()/4; + for (int i = 0; i < npts; ++i) { - const int in = (i+1) % nvertsa; - const int ip = (i+nvertsa-1) % nvertsa; - const int* va = &vertsa[i*4]; - const int* van = &vertsa[in*4]; - const int* vap = &vertsa[ip*4]; + int ni = next(i, npts); - for (int j = 0; j < nvertsb; ++j) + if (vequal(&simplified[i*4], &simplified[ni*4])) { - const int* vb = &vertsb[j*4]; - // vb must be "infront" of va. - if (ileft(vap,va,vb) && ileft(va,van,vb)) + // Degenerate segment, remove. + for (int j = i; j < simplified.size()/4-1; ++j) { - const int dx = vb[0] - va[0]; - const int dz = vb[2] - va[2]; - const int d = dx*dx + dz*dz; - if (d < closestDist) - { - ia = i; - ib = j; - closestDist = d; - } + simplified[j*4+0] = simplified[(j+1)*4+0]; + simplified[j*4+1] = simplified[(j+1)*4+1]; + simplified[j*4+2] = simplified[(j+1)*4+2]; + simplified[j*4+3] = simplified[(j+1)*4+3]; } + simplified.resize(simplified.size()-4); + npts--; } } } + static bool mergeContours(rcContour& ca, rcContour& cb, int ia, int ib) { const int maxVerts = ca.nverts + cb.nverts + 2; int* verts = (int*)rcAlloc(sizeof(int)*maxVerts*4, RC_ALLOC_PERM); if (!verts) return false; - + int nv = 0; - + // Copy contour A. for (int i = 0; i <= ca.nverts; ++i) { @@ -582,7 +639,7 @@ static bool mergeContours(rcContour& ca, rcContour& cb, int ia, int ib) rcFree(ca.verts); ca.verts = verts; ca.nverts = nv; - + rcFree(cb.verts); cb.verts = 0; cb.nverts = 0; @@ -590,18 +647,179 @@ static bool mergeContours(rcContour& ca, rcContour& cb, int ia, int ib) return true; } +struct rcContourHole +{ + rcContour* contour; + int minx, minz, leftmost; +}; + +struct rcContourRegion +{ + rcContour* outline; + rcContourHole* holes; + int nholes; +}; + +struct rcPotentialDiagonal +{ + int vert; + int dist; +}; + +// Finds the lowest leftmost vertex of a contour. +static void findLeftMostVertex(rcContour* contour, int* minx, int* minz, int* leftmost) +{ + *minx = contour->verts[0]; + *minz = contour->verts[2]; + *leftmost = 0; + for (int i = 1; i < contour->nverts; i++) + { + const int x = contour->verts[i*4+0]; + const int z = contour->verts[i*4+2]; + if (x < *minx || (x == *minx && z < *minz)) + { + *minx = x; + *minz = z; + *leftmost = i; + } + } +} + +static int compareHoles(const void* va, const void* vb) +{ + const rcContourHole* a = (const rcContourHole*)va; + const rcContourHole* b = (const rcContourHole*)vb; + if (a->minx == b->minx) + { + if (a->minz < b->minz) + return -1; + if (a->minz > b->minz) + return 1; + } + else + { + if (a->minx < b->minx) + return -1; + if (a->minx > b->minx) + return 1; + } + return 0; +} + + +static int compareDiagDist(const void* va, const void* vb) +{ + const rcPotentialDiagonal* a = (const rcPotentialDiagonal*)va; + const rcPotentialDiagonal* b = (const rcPotentialDiagonal*)vb; + if (a->dist < b->dist) + return -1; + if (a->dist > b->dist) + return 1; + return 0; +} + + +static void mergeRegionHoles(rcContext* ctx, rcContourRegion& region) +{ + // Sort holes from left to right. + for (int i = 0; i < region.nholes; i++) + findLeftMostVertex(region.holes[i].contour, ®ion.holes[i].minx, ®ion.holes[i].minz, ®ion.holes[i].leftmost); + + qsort(region.holes, region.nholes, sizeof(rcContourHole), compareHoles); + + int maxVerts = region.outline->nverts; + for (int i = 0; i < region.nholes; i++) + maxVerts += region.holes[i].contour->nverts; + + rcScopedDelete<rcPotentialDiagonal> diags = (rcPotentialDiagonal*)rcAlloc(sizeof(rcPotentialDiagonal)*maxVerts, RC_ALLOC_TEMP); + if (!diags) + { + ctx->log(RC_LOG_WARNING, "mergeRegionHoles: Failed to allocated diags %d.", maxVerts); + return; + } + + rcContour* outline = region.outline; + + // Merge holes into the outline one by one. + for (int i = 0; i < region.nholes; i++) + { + rcContour* hole = region.holes[i].contour; + + int index = -1; + int bestVertex = region.holes[i].leftmost; + for (int iter = 0; iter < hole->nverts; iter++) + { + // Find potential diagonals. + // The 'best' vertex must be in the cone described by 3 cosequtive vertices of the outline. + // ..o j-1 + // | + // | * best + // | + // j o-----o j+1 + // : + int ndiags = 0; + const int* corner = &hole->verts[bestVertex*4]; + for (int j = 0; j < outline->nverts; j++) + { + if (inCone(j, outline->nverts, outline->verts, corner)) + { + int dx = outline->verts[j*4+0] - corner[0]; + int dz = outline->verts[j*4+2] - corner[2]; + diags[ndiags].vert = j; + diags[ndiags].dist = dx*dx + dz*dz; + ndiags++; + } + } + // Sort potential diagonals by distance, we want to make the connection as short as possible. + qsort(diags, ndiags, sizeof(rcPotentialDiagonal), compareDiagDist); + + // Find a diagonal that is not intersecting the outline not the remaining holes. + index = -1; + for (int j = 0; j < ndiags; j++) + { + const int* pt = &outline->verts[diags[j].vert*4]; + bool intersect = intersectSegCountour(pt, corner, diags[i].vert, outline->nverts, outline->verts); + for (int k = i; k < region.nholes && !intersect; k++) + intersect |= intersectSegCountour(pt, corner, -1, region.holes[k].contour->nverts, region.holes[k].contour->verts); + if (!intersect) + { + index = diags[j].vert; + break; + } + } + // If found non-intersecting diagonal, stop looking. + if (index != -1) + break; + // All the potential diagonals for the current vertex were intersecting, try next vertex. + bestVertex = (bestVertex + 1) % hole->nverts; + } + + if (index == -1) + { + ctx->log(RC_LOG_WARNING, "mergeHoles: Failed to find merge points for %p and %p.", region.outline, hole); + continue; + } + if (!mergeContours(*region.outline, *hole, index, bestVertex)) + { + ctx->log(RC_LOG_WARNING, "mergeHoles: Failed to merge contours %p and %p.", region.outline, hole); + continue; + } + } +} + + /// @par /// /// The raw contours will match the region outlines exactly. The @p maxError and @p maxEdgeLen /// parameters control how closely the simplified contours will match the raw contours. /// -/// Simplified contours are generated such that the vertices for portals between areas match up. +/// Simplified contours are generated such that the vertices for portals between areas match up. /// (They are considered mandatory vertices.) /// /// Setting @p maxEdgeLength to zero will disabled the edge length feature. -/// +/// /// See the #rcConfig documentation for more information on the configuration parameters. -/// +/// /// @see rcAllocContourSet, rcCompactHeightfield, rcContourSet, rcConfig bool rcBuildContours(rcContext* ctx, rcCompactHeightfield& chf, const float maxError, const int maxEdgeLen, @@ -704,17 +922,17 @@ bool rcBuildContours(rcContext* ctx, rcCompactHeightfield& chf, verts.resize(0); simplified.resize(0); - + ctx->startTimer(RC_TIMER_BUILD_CONTOURS_TRACE); walkContour(x, y, i, chf, flags, verts); ctx->stopTimer(RC_TIMER_BUILD_CONTOURS_TRACE); - + ctx->startTimer(RC_TIMER_BUILD_CONTOURS_SIMPLIFY); simplifyContour(verts, simplified, maxError, maxEdgeLen, buildFlags); removeDegenerateSegments(simplified); ctx->stopTimer(RC_TIMER_BUILD_CONTOURS_SIMPLIFY); - + // Store region->contour remap info. // Create contour. if (simplified.size()/4 >= 3) @@ -722,7 +940,7 @@ bool rcBuildContours(rcContext* ctx, rcCompactHeightfield& chf, if (cset.nconts >= maxContours) { // Allocate more contours. - // This can happen when there are tiny holes in the heightfield. + // This happens when a region has holes. const int oldMax = maxContours; maxContours *= 2; rcContour* newConts = (rcContour*)rcAlloc(sizeof(rcContour)*maxContours, RC_ALLOC_PERM); @@ -735,10 +953,10 @@ bool rcBuildContours(rcContext* ctx, rcCompactHeightfield& chf, } rcFree(cset.conts); cset.conts = newConts; - + ctx->log(RC_LOG_WARNING, "rcBuildContours: Expanding max contours from %d to %d.", oldMax, maxContours); } - + rcContour* cont = &cset.conts[cset.nconts++]; cont->nverts = simplified.size()/4; @@ -779,17 +997,6 @@ bool rcBuildContours(rcContext* ctx, rcCompactHeightfield& chf, } } -/* cont->cx = cont->cy = cont->cz = 0; - for (int i = 0; i < cont->nverts; ++i) - { - cont->cx += cont->verts[i*4+0]; - cont->cy += cont->verts[i*4+1]; - cont->cz += cont->verts[i*4+2]; - } - cont->cx /= cont->nverts; - cont->cy /= cont->nverts; - cont->cz /= cont->nverts;*/ - cont->reg = reg; cont->area = area; } @@ -797,52 +1004,100 @@ bool rcBuildContours(rcContext* ctx, rcCompactHeightfield& chf, } } - // Check and merge droppings. - // Sometimes the previous algorithms can fail and create several contours - // per area. This pass will try to merge the holes into the main region. - for (int i = 0; i < cset.nconts; ++i) + // Merge holes if needed. + if (cset.nconts > 0) { - rcContour& cont = cset.conts[i]; - // Check if the contour is would backwards. - if (calcAreaOfPolygon2D(cont.verts, cont.nverts) < 0) + // Calculate winding of all polygons. + rcScopedDelete<char> winding = (char*)rcAlloc(sizeof(char)*cset.nconts, RC_ALLOC_TEMP); + if (!winding) { - // Find another contour which has the same region ID. - int mergeIdx = -1; - for (int j = 0; j < cset.nconts; ++j) + ctx->log(RC_LOG_ERROR, "rcBuildContours: Out of memory 'hole' (%d).", cset.nconts); + return false; + } + int nholes = 0; + for (int i = 0; i < cset.nconts; ++i) + { + rcContour& cont = cset.conts[i]; + // If the contour is wound backwards, it is a hole. + winding[i] = calcAreaOfPolygon2D(cont.verts, cont.nverts) < 0 ? -1 : 1; + if (winding[i] < 0) + nholes++; + } + + if (nholes > 0) + { + // Collect outline contour and holes contours per region. + // We assume that there is one outline and multiple holes. + const int nregions = chf.maxRegions+1; + rcScopedDelete<rcContourRegion> regions = (rcContourRegion*)rcAlloc(sizeof(rcContourRegion)*nregions, RC_ALLOC_TEMP); + if (!regions) + { + ctx->log(RC_LOG_ERROR, "rcBuildContours: Out of memory 'regions' (%d).", nregions); + return false; + } + memset(regions, 0, sizeof(rcContourRegion)*nregions); + + rcScopedDelete<rcContourHole> holes = (rcContourHole*)rcAlloc(sizeof(rcContourHole)*cset.nconts, RC_ALLOC_TEMP); + if (!holes) + { + ctx->log(RC_LOG_ERROR, "rcBuildContours: Out of memory 'holes' (%d).", cset.nconts); + return false; + } + memset(holes, 0, sizeof(rcContourHole)*cset.nconts); + + for (int i = 0; i < cset.nconts; ++i) { - if (i == j) continue; - if (cset.conts[j].nverts && cset.conts[j].reg == cont.reg) + rcContour& cont = cset.conts[i]; + // Positively would contours are outlines, negative holes. + if (winding[i] > 0) { - // Make sure the polygon is correctly oriented. - if (calcAreaOfPolygon2D(cset.conts[j].verts, cset.conts[j].nverts)) - { - mergeIdx = j; - break; - } + if (regions[cont.reg].outline) + ctx->log(RC_LOG_ERROR, "rcBuildContours: Multiple outlines for region %d.", cont.reg); + regions[cont.reg].outline = &cont; + } + else + { + regions[cont.reg].nholes++; } } - if (mergeIdx == -1) + int index = 0; + for (int i = 0; i < nregions; i++) { - ctx->log(RC_LOG_WARNING, "rcBuildContours: Could not find merge target for bad contour %d.", i); + if (regions[i].nholes > 0) + { + regions[i].holes = &holes[index]; + index += regions[i].nholes; + regions[i].nholes = 0; + } } - else + for (int i = 0; i < cset.nconts; ++i) + { + rcContour& cont = cset.conts[i]; + rcContourRegion& reg = regions[cont.reg]; + if (winding[i] < 0) + reg.holes[reg.nholes++].contour = &cont; + } + + // Finally merge each regions holes into the outline. + for (int i = 0; i < nregions; i++) { - rcContour& mcont = cset.conts[mergeIdx]; - // Merge by closest points. - int ia = 0, ib = 0; - getClosestIndices(mcont.verts, mcont.nverts, cont.verts, cont.nverts, ia, ib); - if (ia == -1 || ib == -1) + rcContourRegion& reg = regions[i]; + if (!reg.nholes) continue; + + if (reg.outline) { - ctx->log(RC_LOG_WARNING, "rcBuildContours: Failed to find merge points for %d and %d.", i, mergeIdx); - continue; + mergeRegionHoles(ctx, reg); } - if (!mergeContours(mcont, cont, ia, ib)) + else { - ctx->log(RC_LOG_WARNING, "rcBuildContours: Failed to merge contours %d and %d.", i, mergeIdx); - continue; + // The region does not have an outline. + // This can happen if the contour becaomes selfoverlapping because of + // too aggressive simplification settings. + ctx->log(RC_LOG_ERROR, "rcBuildContours: Bad outline for region %d, contour simplification is likely too aggressive.", i); } } } + } ctx->stopTimer(RC_TIMER_BUILD_CONTOURS); diff --git a/dep/recastnavigation/Recast/RecastFilter.cpp b/dep/recastnavigation/Recast/Source/RecastFilter.cpp index bf985c362c9..bf985c362c9 100644 --- a/dep/recastnavigation/Recast/RecastFilter.cpp +++ b/dep/recastnavigation/Recast/Source/RecastFilter.cpp diff --git a/dep/recastnavigation/Recast/RecastLayers.cpp b/dep/recastnavigation/Recast/Source/RecastLayers.cpp index 204f72e8cb2..cb1a39f4bda 100644 --- a/dep/recastnavigation/Recast/RecastLayers.cpp +++ b/dep/recastnavigation/Recast/Source/RecastLayers.cpp @@ -38,7 +38,7 @@ struct rcLayerRegion unsigned char layerId; // Layer ID unsigned char nlayers; // Layer count unsigned char nneis; // Neighbour count - unsigned char base; // Flag indicating if the region is hte base of merged regions. + unsigned char base; // Flag indicating if the region is the base of merged regions. }; diff --git a/dep/recastnavigation/Recast/RecastMesh.cpp b/dep/recastnavigation/Recast/Source/RecastMesh.cpp index 8af609b79fb..e4f9c4b3629 100644 --- a/dep/recastnavigation/Recast/RecastMesh.cpp +++ b/dep/recastnavigation/Recast/Source/RecastMesh.cpp @@ -288,6 +288,53 @@ static bool diagonal(int i, int j, int n, const int* verts, int* indices) return inCone(i, j, n, verts, indices) && diagonalie(i, j, n, verts, indices); } + +static bool diagonalieLoose(int i, int j, int n, const int* verts, int* indices) +{ + const int* d0 = &verts[(indices[i] & 0x0fffffff) * 4]; + const int* d1 = &verts[(indices[j] & 0x0fffffff) * 4]; + + // For each edge (k,k+1) of P + for (int k = 0; k < n; k++) + { + int k1 = next(k, n); + // Skip edges incident to i or j + if (!((k == i) || (k1 == i) || (k == j) || (k1 == j))) + { + const int* p0 = &verts[(indices[k] & 0x0fffffff) * 4]; + const int* p1 = &verts[(indices[k1] & 0x0fffffff) * 4]; + + if (vequal(d0, p0) || vequal(d1, p0) || vequal(d0, p1) || vequal(d1, p1)) + continue; + + if (intersectProp(d0, d1, p0, p1)) + return false; + } + } + return true; +} + +static bool inConeLoose(int i, int j, int n, const int* verts, int* indices) +{ + const int* pi = &verts[(indices[i] & 0x0fffffff) * 4]; + const int* pj = &verts[(indices[j] & 0x0fffffff) * 4]; + const int* pi1 = &verts[(indices[next(i, n)] & 0x0fffffff) * 4]; + const int* pin1 = &verts[(indices[prev(i, n)] & 0x0fffffff) * 4]; + + // If P[i] is a convex vertex [ i+1 left or on (i-1,i) ]. + if (leftOn(pin1, pi, pi1)) + return leftOn(pi, pj, pin1) && leftOn(pj, pi, pi1); + // Assume (i-1,i,i+1) not collinear. + // else P[i] is reflex. + return !(leftOn(pi, pj, pi1) && leftOn(pj, pi, pin1)); +} + +static bool diagonalLoose(int i, int j, int n, const int* verts, int* indices) +{ + return inConeLoose(i, j, n, verts, indices) && diagonalieLoose(i, j, n, verts, indices); +} + + static int triangulate(int n, const int* verts, int* indices, int* tris) { int ntris = 0; @@ -328,14 +375,41 @@ static int triangulate(int n, const int* verts, int* indices, int* tris) if (mini == -1) { - // Should not happen. -/* printf("mini == -1 ntris=%d n=%d\n", ntris, n); + // We might get here because the contour has overlapping segments, like this: + // + // A o-o=====o---o B + // / |C D| \ + // o o o o + // : : : : + // We'll try to recover by loosing up the inCone test a bit so that a diagonal + // like A-B or C-D can be found and we can continue. + minLen = -1; + mini = -1; for (int i = 0; i < n; i++) { - printf("%d ", indices[i] & 0x0fffffff); + int i1 = next(i, n); + int i2 = next(i1, n); + if (diagonalLoose(i, i2, n, verts, indices)) + { + const int* p0 = &verts[(indices[i] & 0x0fffffff) * 4]; + const int* p2 = &verts[(indices[next(i2, n)] & 0x0fffffff) * 4]; + int dx = p2[0] - p0[0]; + int dy = p2[2] - p0[2]; + int len = dx*dx + dy*dy; + + if (minLen < 0 || len < minLen) + { + minLen = len; + mini = i; + } + } + } + if (mini == -1) + { + // The contour is messed up. This sometimes happens + // if the contour simplification is too aggressive. + return -ntris; } - printf("\n");*/ - return -ntris; } int i = mini; @@ -1463,7 +1537,7 @@ bool rcCopyPolyMesh(rcContext* ctx, const rcPolyMesh& src, rcPolyMesh& dst) ctx->log(RC_LOG_ERROR, "rcCopyPolyMesh: Out of memory 'dst.flags' (%d).", src.npolys); return false; } - memcpy(dst.flags, src.flags, sizeof(unsigned char)*src.npolys); + memcpy(dst.flags, src.flags, sizeof(unsigned short)*src.npolys); return true; } diff --git a/dep/recastnavigation/Recast/RecastMeshDetail.cpp b/dep/recastnavigation/Recast/Source/RecastMeshDetail.cpp index 8325b883707..5cc2adf0320 100644 --- a/dep/recastnavigation/Recast/RecastMeshDetail.cpp +++ b/dep/recastnavigation/Recast/Source/RecastMeshDetail.cpp @@ -56,7 +56,7 @@ inline float vdist2(const float* p, const float* q) } inline float vcross2(const float* p1, const float* p2, const float* p3) -{ +{ const float u1 = p2[0] - p1[0]; const float v1 = p2[2] - p1[2]; const float u2 = p3[0] - p1[0]; @@ -68,21 +68,27 @@ static bool circumCircle(const float* p1, const float* p2, const float* p3, float* c, float& r) { static const float EPS = 1e-6f; + // Calculate the circle relative to p1, to avoid some precision issues. + const float v1[3] = {0,0,0}; + float v2[3], v3[3]; + rcVsub(v2, p2,p1); + rcVsub(v3, p3,p1); - const float cp = vcross2(p1, p2, p3); + const float cp = vcross2(v1, v2, v3); if (fabsf(cp) > EPS) { - const float p1Sq = vdot2(p1,p1); - const float p2Sq = vdot2(p2,p2); - const float p3Sq = vdot2(p3,p3); - c[0] = (p1Sq*(p2[2]-p3[2]) + p2Sq*(p3[2]-p1[2]) + p3Sq*(p1[2]-p2[2])) / (2*cp); - c[2] = (p1Sq*(p3[0]-p2[0]) + p2Sq*(p1[0]-p3[0]) + p3Sq*(p2[0]-p1[0])) / (2*cp); - r = vdist2(c, p1); + const float v1Sq = vdot2(v1,v1); + const float v2Sq = vdot2(v2,v2); + const float v3Sq = vdot2(v3,v3); + c[0] = (v1Sq*(v2[2]-v3[2]) + v2Sq*(v3[2]-v1[2]) + v3Sq*(v1[2]-v2[2])) / (2*cp); + c[1] = 0; + c[2] = (v1Sq*(v3[0]-v2[0]) + v2Sq*(v1[0]-v3[0]) + v3Sq*(v2[0]-v1[0])) / (2*cp); + r = vdist2(c, v1); + rcVadd(c, c, p1); return true; } - - c[0] = p1[0]; - c[2] = p1[2]; + + rcVcopy(c, p1); r = 0; return false; } @@ -93,7 +99,7 @@ static float distPtTri(const float* p, const float* a, const float* b, const flo rcVsub(v0, c,a); rcVsub(v1, b,a); rcVsub(v2, p,a); - + const float dot00 = vdot2(v0, v0); const float dot01 = vdot2(v0, v1); const float dot02 = vdot2(v0, v2); @@ -178,7 +184,7 @@ static float distToTriMesh(const float* p, const float* verts, const int /*nvert static float distToPoly(int nvert, const float* verts, const float* p) { - + float dmin = FLT_MAX; int i, j, c = 0; for (i = 0, j = nvert-1; i < nvert; j = i++) @@ -216,22 +222,13 @@ static unsigned short getHeight(const float fx, const float fy, const float fz, if (nx < 0 || nz < 0 || nx >= hp.width || nz >= hp.height) continue; const unsigned short nh = hp.data[nx+nz*hp.width]; if (nh == RC_UNSET_HEIGHT) continue; - + const float d = fabsf(nh*ch - fy); if (d < dmin) { h = nh; dmin = d; } - -/* const float dx = (nx+0.5f)*cs - fx; - const float dz = (nz+0.5f)*cs - fz; - const float d = dx*dx+dz*dz; - if (d < dmin) - { - h = nh; - dmin = d; - } */ } } return h; @@ -263,7 +260,7 @@ static int addEdge(rcContext* ctx, int* edges, int& nedges, const int maxEdges, return UNDEF; } - // Add edge if not already in the triangulation. + // Add edge if not already in the triangulation. int e = findEdge(edges, nedges, s, t); if (e == UNDEF) { @@ -286,7 +283,7 @@ static void updateLeftFace(int* e, int s, int t, int f) e[2] = f; else if (e[1] == s && e[0] == t && e[3] == UNDEF) e[3] = f; -} +} static int overlapSegSeg2d(const float* a, const float* b, const float* c, const float* d) { @@ -298,7 +295,7 @@ static int overlapSegSeg2d(const float* a, const float* b, const float* c, const float a4 = a3 + a2 - a1; if (a3 * a4 < 0.0f) return 1; - } + } return 0; } @@ -320,7 +317,7 @@ static bool overlapEdges(const float* pts, const int* edges, int nedges, int s1, static void completeFacet(rcContext* ctx, const float* pts, int npts, int* edges, int& nedges, const int maxEdges, int& nfaces, int e) { static const float EPS = 1e-5f; - + int* edge = &edges[e*4]; // Cache s and t. @@ -337,11 +334,11 @@ static void completeFacet(rcContext* ctx, const float* pts, int npts, int* edges } else { - // Edge already completed. + // Edge already completed. return; } - // Find best point on left of edge. + // Find best point on left of edge. int pt = npts; float c[3] = {0,0,0}; float r = -1; @@ -385,20 +382,20 @@ static void completeFacet(rcContext* ctx, const float* pts, int npts, int* edges } } - // Add new triangle or update edge info if s-t is on hull. + // Add new triangle or update edge info if s-t is on hull. if (pt < npts) { - // Update face information of edge being completed. + // Update face information of edge being completed. updateLeftFace(&edges[e*4], s, t, nfaces); - // Add new edge or update face info of old edge. + // Add new edge or update face info of old edge. e = findEdge(edges, nedges, pt, s); if (e == UNDEF) addEdge(ctx, edges, nedges, maxEdges, pt, s, nfaces, UNDEF); else updateLeftFace(&edges[e*4], pt, s, nfaces); - // Add new edge or update face info of old edge. + // Add new edge or update face info of old edge. e = findEdge(edges, nedges, t, pt); if (e == UNDEF) addEdge(ctx, edges, nedges, maxEdges, t, pt, nfaces, UNDEF); @@ -434,7 +431,7 @@ static void delaunayHull(rcContext* ctx, const int npts, const float* pts, completeFacet(ctx, pts, npts, &edges[0], nedges, maxEdges, nfaces, currentEdge); currentEdge++; } - + // Create tris tris.resize(nfaces*4); for (int i = 0; i < nfaces*4; ++i) @@ -489,6 +486,103 @@ static void delaunayHull(rcContext* ctx, const int npts, const float* pts, } } +// Calculate minimum extend of the polygon. +static float polyMinExtent(const float* verts, const int nverts) +{ + float minDist = FLT_MAX; + for (int i = 0; i < nverts; i++) + { + const int ni = (i+1) % nverts; + const float* p1 = &verts[i*3]; + const float* p2 = &verts[ni*3]; + float maxEdgeDist = 0; + for (int j = 0; j < nverts; j++) + { + if (j == i || j == ni) continue; + float d = distancePtSeg2d(&verts[j*3], p1,p2); + maxEdgeDist = rcMax(maxEdgeDist, d); + } + minDist = rcMin(minDist, maxEdgeDist); + } + return rcSqrt(minDist); +} + +inline int next(int i, int n) +{ + return (i+1) % n; +} + +inline int prev(int i, int n) +{ + return (i + n-1) % n; +} + +static void triangulateHull(const int nverts, const float* verts, const int nhull, const int* hull, rcIntArray& tris) +{ + int start = 0, left = 1, right = nhull-1; + + // Start from an ear with shortest perimeter. + // This tends to favor well formed triangles as starting point. + float dmin = 0; + for (int i = 0; i < nhull; i++) + { + int pi = prev(i, nhull); + int ni = next(i, nhull); + const float* pv = &verts[hull[pi]*3]; + const float* cv = &verts[hull[i]*3]; + const float* nv = &verts[hull[ni]*3]; + const float d = vdist2(pv,cv) + vdist2(cv,nv) + vdist2(nv,pv); + if (d < dmin) + { + start = i; + left = ni; + right = pi; + dmin = d; + } + } + + // Add first triangle + tris.push(hull[start]); + tris.push(hull[left]); + tris.push(hull[right]); + tris.push(0); + + // Triangulate the polygon by moving left or right, + // depending on which triangle has shorter perimeter. + // This heuristic was chose emprically, since it seems + // handle tesselated straight edges well. + while (next(left, nhull) != right) + { + // Check to see if se should advance left or right. + int nleft = next(left, nhull); + int nright = prev(right, nhull); + + const float* cvleft = &verts[hull[left]*3]; + const float* nvleft = &verts[hull[nleft]*3]; + const float* cvright = &verts[hull[right]*3]; + const float* nvright = &verts[hull[nright]*3]; + const float dleft = vdist2(cvleft, nvleft) + vdist2(nvleft, cvright); + const float dright = vdist2(cvright, nvright) + vdist2(cvleft, nvright); + + if (dleft < dright) + { + tris.push(hull[left]); + tris.push(hull[nleft]); + tris.push(hull[right]); + tris.push(0); + left = nleft; + } + else + { + tris.push(hull[left]); + tris.push(hull[nright]); + tris.push(hull[right]); + tris.push(0); + right = nright; + } + } +} + inline float getJitterX(const int i) { @@ -512,16 +606,22 @@ static bool buildPolyDetail(rcContext* ctx, const float* in, const int nin, float edge[(MAX_VERTS_PER_EDGE+1)*3]; int hull[MAX_VERTS]; int nhull = 0; - + nverts = 0; - + for (int i = 0; i < nin; ++i) rcVcopy(&verts[i*3], &in[i*3]); nverts = nin; + edges.resize(0); + tris.resize(0); + const float cs = chf.cs; const float ics = 1.0f/cs; + // Calculate minimum extents of the polygon based on input data. + float minExtent = polyMinExtent(verts, nverts); + // Tessellate outlines. // This is done in separate pass in order to ensure // seamless height values across the ply boundaries. @@ -628,27 +728,26 @@ static bool buildPolyDetail(rcContext* ctx, const float* in, const int nin, } } - + // If the polygon minimum extent is small (sliver or small triangle), do not try to add internal points. + if (minExtent < sampleDist*2) + { + triangulateHull(nverts, verts, nhull, hull, tris); + return true; + } + // Tessellate the base mesh. - edges.resize(0); - tris.resize(0); - - delaunayHull(ctx, nverts, verts, nhull, hull, tris, edges); + // We're using the triangulateHull instead of delaunayHull as it tends to + // create a bit better triangulation for long thing triangles when there + // are no internal points. + triangulateHull(nverts, verts, nhull, hull, tris); if (tris.size() == 0) { // Could not triangulate the poly, make sure there is some valid data there. - ctx->log(RC_LOG_WARNING, "buildPolyDetail: Could not triangulate polygon, adding default data."); - for (int i = 2; i < nverts; ++i) - { - tris.push(0); - tris.push(i-1); - tris.push(i); - tris.push(0); - } + ctx->log(RC_LOG_WARNING, "buildPolyDetail: Could not triangulate polygon (%d verts).", nverts); return true; } - + if (sampleDist > 0) { // Create sample locations in a grid. @@ -681,7 +780,7 @@ static bool buildPolyDetail(rcContext* ctx, const float* in, const int nin, samples.push(0); // Not added } } - + // Add the samples starting from the one that has the most // error. The procedure stops when all samples are added // or when the max error is within treshold. @@ -690,7 +789,7 @@ static bool buildPolyDetail(rcContext* ctx, const float* in, const int nin, { if (nverts >= MAX_VERTS) break; - + // Find sample with most error. float bestpt[3] = {0,0,0}; float bestd = 0; @@ -728,24 +827,24 @@ static bool buildPolyDetail(rcContext* ctx, const float* in, const int nin, edges.resize(0); tris.resize(0); delaunayHull(ctx, nverts, verts, nhull, hull, tris, edges); - } + } } - + const int ntris = tris.size()/4; if (ntris > MAX_TRIS) { tris.resize(MAX_TRIS*4); ctx->log(RC_LOG_ERROR, "rcBuildPolyMeshDetail: Shrinking triangle count from %d to max %d.", ntris, MAX_TRIS); } - + return true; } static void getHeightDataSeedsFromVertices(const rcCompactHeightfield& chf, - const unsigned short* poly, const int npoly, - const unsigned short* verts, const int bs, - rcHeightPatch& hp, rcIntArray& stack) + const unsigned short* poly, const int npoly, + const unsigned short* verts, const int bs, + rcHeightPatch& hp, rcIntArray& stack) { // Floodfill the heightfield to get 2D height data, // starting at vertex locations as seeds. @@ -849,7 +948,7 @@ static void getHeightDataSeedsFromVertices(const rcCompactHeightfield& chf, continue; const int ai = (int)chf.cells[(ax+bs)+(ay+bs)*chf.width].index + rcGetCon(cs, dir); - + int idx = ax-hp.xmin+(ay-hp.ymin)*hp.width; hp.data[idx] = 1; @@ -858,9 +957,9 @@ static void getHeightDataSeedsFromVertices(const rcCompactHeightfield& chf, stack.push(ai); } } - + memset(hp.data, 0xff, sizeof(unsigned short)*hp.width*hp.height); - + // Mark start locations. for (int i = 0; i < stack.size(); i += 3) { @@ -870,8 +969,8 @@ static void getHeightDataSeedsFromVertices(const rcCompactHeightfield& chf, int idx = cx-hp.xmin+(cy-hp.ymin)*hp.width; const rcCompactSpan& cs = chf.spans[ci]; hp.data[idx] = cs.y; - - // getHeightData seeds are given in coordinates with borders + + // getHeightData seeds are given in coordinates with borders stack[i+0] += bs; stack[i+1] += bs; } @@ -888,12 +987,12 @@ static void getHeightData(const rcCompactHeightfield& chf, { // Note: Reads to the compact heightfield are offset by border size (bs) // since border size offset is already removed from the polymesh vertices. - + stack.resize(0); memset(hp.data, 0xff, sizeof(unsigned short)*hp.width*hp.height); bool empty = true; - + // Copy the height from the same region, and mark region borders // as seed points to fill the rest. for (int hy = 0; hy < hp.height; hy++) @@ -911,7 +1010,7 @@ static void getHeightData(const rcCompactHeightfield& chf, // Store height hp.data[hx + hy*hp.width] = s.y; empty = false; - + // If any of the neighbours is not in same region, // add the current location as flood fill start bool border = false; @@ -940,8 +1039,8 @@ static void getHeightData(const rcCompactHeightfield& chf, } } } - } - + } + // if the polygon does not contian any points from the current region (rare, but happens) // then use the cells closest to the polygon vertices as seeds to fill the height field if (empty) @@ -963,7 +1062,7 @@ static void getHeightData(const rcCompactHeightfield& chf, memmove(&stack[0], &stack[RETRACT_SIZE*3], sizeof(int)*(stack.size()-RETRACT_SIZE*3)); stack.resize(stack.size()-RETRACT_SIZE*3); } - + const rcCompactSpan& cs = chf.spans[ci]; for (int dir = 0; dir < 4; ++dir) { @@ -982,9 +1081,9 @@ static void getHeightData(const rcCompactHeightfield& chf, const int ai = (int)chf.cells[ax + ay*chf.width].index + rcGetCon(cs, dir); const rcCompactSpan& as = chf.spans[ai]; - + hp.data[hx + hy*hp.width] = as.y; - + stack.push(ax); stack.push(ay); stack.push(ai); @@ -999,7 +1098,7 @@ static unsigned char getEdgeFlags(const float* va, const float* vb, static const float thrSqr = rcSqr(0.001f); for (int i = 0, j = npoly-1; i < npoly; j=i++) { - if (distancePtSeg2d(va, &vpoly[j*3], &vpoly[i*3]) < thrSqr && + if (distancePtSeg2d(va, &vpoly[j*3], &vpoly[i*3]) < thrSqr && distancePtSeg2d(vb, &vpoly[j*3], &vpoly[i*3]) < thrSqr) return 1; } @@ -1028,7 +1127,7 @@ bool rcBuildPolyMeshDetail(rcContext* ctx, const rcPolyMesh& mesh, const rcCompa rcAssert(ctx); ctx->startTimer(RC_TIMER_BUILD_POLYMESHDETAIL); - + if (mesh.nverts == 0 || mesh.npolys == 0) return true; @@ -1107,10 +1206,10 @@ bool rcBuildPolyMeshDetail(rcContext* ctx, const rcPolyMesh& mesh, const rcCompa ctx->log(RC_LOG_ERROR, "rcBuildPolyMeshDetail: Out of memory 'dmesh.meshes' (%d).", dmesh.nmeshes*4); return false; } - + int vcap = nPolyVerts+nPolyVerts/2; int tcap = vcap*2; - + dmesh.nverts = 0; dmesh.verts = (float*)rcAlloc(sizeof(float)*vcap*3, RC_ALLOC_PERM); if (!dmesh.verts) @@ -1119,7 +1218,7 @@ bool rcBuildPolyMeshDetail(rcContext* ctx, const rcPolyMesh& mesh, const rcCompa return false; } dmesh.ntris = 0; - dmesh.tris = (unsigned char*)rcAlloc(sizeof(unsigned char*)*tcap*4, RC_ALLOC_PERM); + dmesh.tris = (unsigned char*)rcAlloc(sizeof(unsigned char)*tcap*4, RC_ALLOC_PERM); if (!dmesh.tris) { ctx->log(RC_LOG_ERROR, "rcBuildPolyMeshDetail: Out of memory 'dmesh.tris' (%d).", tcap*4); @@ -1158,7 +1257,7 @@ bool rcBuildPolyMeshDetail(rcContext* ctx, const rcPolyMesh& mesh, const rcCompa { return false; } - + // Move detail verts to world space. for (int j = 0; j < nverts; ++j) { @@ -1173,21 +1272,21 @@ bool rcBuildPolyMeshDetail(rcContext* ctx, const rcPolyMesh& mesh, const rcCompa poly[j*3+1] += orig[1]; poly[j*3+2] += orig[2]; } - + // Store detail submesh. const int ntris = tris.size()/4; - + dmesh.meshes[i*4+0] = (unsigned int)dmesh.nverts; dmesh.meshes[i*4+1] = (unsigned int)nverts; dmesh.meshes[i*4+2] = (unsigned int)dmesh.ntris; - dmesh.meshes[i*4+3] = (unsigned int)ntris; + dmesh.meshes[i*4+3] = (unsigned int)ntris; // Store vertices, allocate more memory if necessary. if (dmesh.nverts+nverts > vcap) { while (dmesh.nverts+nverts > vcap) vcap += 256; - + float* newv = (float*)rcAlloc(sizeof(float)*vcap*3, RC_ALLOC_PERM); if (!newv) { @@ -1233,9 +1332,9 @@ bool rcBuildPolyMeshDetail(rcContext* ctx, const rcPolyMesh& mesh, const rcCompa dmesh.ntris++; } } - + ctx->stopTimer(RC_TIMER_BUILD_POLYMESHDETAIL); - + return true; } @@ -1245,11 +1344,11 @@ bool rcMergePolyMeshDetails(rcContext* ctx, rcPolyMeshDetail** meshes, const int rcAssert(ctx); ctx->startTimer(RC_TIMER_MERGE_POLYMESHDETAIL); - + int maxVerts = 0; int maxTris = 0; int maxMeshes = 0; - + for (int i = 0; i < nmeshes; ++i) { if (!meshes[i]) continue; @@ -1257,7 +1356,7 @@ bool rcMergePolyMeshDetails(rcContext* ctx, rcPolyMeshDetail** meshes, const int maxTris += meshes[i]->ntris; maxMeshes += meshes[i]->nmeshes; } - + mesh.nmeshes = 0; mesh.meshes = (unsigned int*)rcAlloc(sizeof(unsigned int)*maxMeshes*4, RC_ALLOC_PERM); if (!mesh.meshes) @@ -1265,7 +1364,7 @@ bool rcMergePolyMeshDetails(rcContext* ctx, rcPolyMeshDetail** meshes, const int ctx->log(RC_LOG_ERROR, "rcBuildPolyMeshDetail: Out of memory 'pmdtl.meshes' (%d).", maxMeshes*4); return false; } - + mesh.ntris = 0; mesh.tris = (unsigned char*)rcAlloc(sizeof(unsigned char)*maxTris*4, RC_ALLOC_PERM); if (!mesh.tris) @@ -1273,7 +1372,7 @@ bool rcMergePolyMeshDetails(rcContext* ctx, rcPolyMeshDetail** meshes, const int ctx->log(RC_LOG_ERROR, "rcBuildPolyMeshDetail: Out of memory 'dmesh.tris' (%d).", maxTris*4); return false; } - + mesh.nverts = 0; mesh.verts = (float*)rcAlloc(sizeof(float)*maxVerts*3, RC_ALLOC_PERM); if (!mesh.verts) @@ -1297,7 +1396,7 @@ bool rcMergePolyMeshDetails(rcContext* ctx, rcPolyMeshDetail** meshes, const int dst[3] = src[3]; mesh.nmeshes++; } - + for (int k = 0; k < dm->nverts; ++k) { rcVcopy(&mesh.verts[mesh.nverts*3], &dm->verts[k*3]); @@ -1312,7 +1411,7 @@ bool rcMergePolyMeshDetails(rcContext* ctx, rcPolyMeshDetail** meshes, const int mesh.ntris++; } } - + ctx->stopTimer(RC_TIMER_MERGE_POLYMESHDETAIL); return true; diff --git a/dep/recastnavigation/Recast/RecastRasterization.cpp b/dep/recastnavigation/Recast/Source/RecastRasterization.cpp index 45a7d35bf3e..45a7d35bf3e 100644 --- a/dep/recastnavigation/Recast/RecastRasterization.cpp +++ b/dep/recastnavigation/Recast/Source/RecastRasterization.cpp diff --git a/dep/recastnavigation/Recast/RecastRegion.cpp b/dep/recastnavigation/Recast/Source/RecastRegion.cpp index 589fac29203..38bc4ff476f 100644 --- a/dep/recastnavigation/Recast/RecastRegion.cpp +++ b/dep/recastnavigation/Recast/Source/RecastRegion.cpp @@ -315,6 +315,7 @@ static bool floodRegion(int x, int y, int i, srcReg[ci] = 0; continue; } + count++; // Expand neighbours. @@ -516,7 +517,11 @@ struct rcRegion id(i), areaType(0), remap(false), - visited(false) + visited(false), + overlap(false), + connectsToBorder(false), + ymin(0xffff), + ymax(0) {} int spanCount; // Number of spans belonging to this region @@ -524,6 +529,9 @@ struct rcRegion unsigned char areaType; // Are type. bool remap; bool visited; + bool overlap; + bool connectsToBorder; + unsigned short ymin, ymax; rcIntArray connections; rcIntArray floors; }; @@ -768,10 +776,11 @@ static void walkContour(int x, int y, int i, int dir, } } -static bool filterSmallRegions(rcContext* ctx, int minRegionArea, int mergeRegionSize, - unsigned short& maxRegionId, - rcCompactHeightfield& chf, - unsigned short* srcReg) + +static bool mergeAndFilterRegions(rcContext* ctx, int minRegionArea, int mergeRegionSize, + unsigned short& maxRegionId, + rcCompactHeightfield& chf, + unsigned short* srcReg, rcIntArray& overlaps) { const int w = chf.width; const int h = chf.height; @@ -780,7 +789,7 @@ static bool filterSmallRegions(rcContext* ctx, int minRegionArea, int mergeRegio rcRegion* regions = (rcRegion*)rcAlloc(sizeof(rcRegion)*nreg, RC_ALLOC_TEMP); if (!regions) { - ctx->log(RC_LOG_ERROR, "filterSmallRegions: Out of memory 'regions' (%d).", nreg); + ctx->log(RC_LOG_ERROR, "mergeAndFilterRegions: Out of memory 'regions' (%d).", nreg); return false; } @@ -803,7 +812,6 @@ static bool filterSmallRegions(rcContext* ctx, int minRegionArea, int mergeRegio rcRegion& reg = regions[r]; reg.spanCount++; - // Update floors. for (int j = (int)c.index; j < ni; ++j) { @@ -811,6 +819,8 @@ static bool filterSmallRegions(rcContext* ctx, int minRegionArea, int mergeRegio unsigned short floorId = srcReg[j]; if (floorId == 0 || floorId >= nreg) continue; + if (floorId == r) + reg.overlap = true; addUniqueFloorRegion(reg, floorId); } @@ -906,7 +916,7 @@ static bool filterSmallRegions(rcContext* ctx, int minRegionArea, int mergeRegio } } } - + // Merge too small regions to neighbour regions. int mergeCount = 0 ; do @@ -916,7 +926,9 @@ static bool filterSmallRegions(rcContext* ctx, int minRegionArea, int mergeRegio { rcRegion& reg = regions[i]; if (reg.id == 0 || (reg.id & RC_BORDER_REG)) - continue; + continue; + if (reg.overlap) + continue; if (reg.spanCount == 0) continue; @@ -933,7 +945,7 @@ static bool filterSmallRegions(rcContext* ctx, int minRegionArea, int mergeRegio { if (reg.connections[j] & RC_BORDER_REG) continue; rcRegion& mreg = regions[reg.connections[j]]; - if (mreg.id == 0 || (mreg.id & RC_BORDER_REG)) continue; + if (mreg.id == 0 || (mreg.id & RC_BORDER_REG) || mreg.overlap) continue; if (mreg.spanCount < smallest && canMergeWithRegion(reg, mreg) && canMergeWithRegion(mreg, reg)) @@ -1003,6 +1015,224 @@ static bool filterSmallRegions(rcContext* ctx, int minRegionArea, int mergeRegio if ((srcReg[i] & RC_BORDER_REG) == 0) srcReg[i] = regions[srcReg[i]].id; } + + // Return regions that we found to be overlapping. + for (int i = 0; i < nreg; ++i) + if (regions[i].overlap) + overlaps.push(regions[i].id); + + for (int i = 0; i < nreg; ++i) + regions[i].~rcRegion(); + rcFree(regions); + + + return true; +} + + +static void addUniqueConnection(rcRegion& reg, int n) +{ + for (int i = 0; i < reg.connections.size(); ++i) + if (reg.connections[i] == n) + return; + reg.connections.push(n); +} + +static bool mergeAndFilterLayerRegions(rcContext* ctx, int minRegionArea, + unsigned short& maxRegionId, + rcCompactHeightfield& chf, + unsigned short* srcReg, rcIntArray& overlaps) +{ + const int w = chf.width; + const int h = chf.height; + + const int nreg = maxRegionId+1; + rcRegion* regions = (rcRegion*)rcAlloc(sizeof(rcRegion)*nreg, RC_ALLOC_TEMP); + if (!regions) + { + ctx->log(RC_LOG_ERROR, "mergeAndFilterLayerRegions: Out of memory 'regions' (%d).", nreg); + return false; + } + + // Construct regions + for (int i = 0; i < nreg; ++i) + new(®ions[i]) rcRegion((unsigned short)i); + + // Find region neighbours and overlapping regions. + rcIntArray lregs(32); + for (int y = 0; y < h; ++y) + { + for (int x = 0; x < w; ++x) + { + const rcCompactCell& c = chf.cells[x+y*w]; + + lregs.resize(0); + + for (int i = (int)c.index, ni = (int)(c.index+c.count); i < ni; ++i) + { + const rcCompactSpan& s = chf.spans[i]; + const unsigned short ri = srcReg[i]; + if (ri == 0 || ri >= nreg) continue; + rcRegion& reg = regions[ri]; + + reg.spanCount++; + + reg.ymin = rcMin(reg.ymin, s.y); + reg.ymax = rcMax(reg.ymax, s.y); + + // Collect all region layers. + lregs.push(ri); + + // Update neighbours + for (int dir = 0; dir < 4; ++dir) + { + if (rcGetCon(s, dir) != RC_NOT_CONNECTED) + { + const int ax = x + rcGetDirOffsetX(dir); + const int ay = y + rcGetDirOffsetY(dir); + const int ai = (int)chf.cells[ax+ay*w].index + rcGetCon(s, dir); + const unsigned short rai = srcReg[ai]; + if (rai > 0 && rai < nreg && rai != ri) + addUniqueConnection(reg, rai); + if (rai & RC_BORDER_REG) + reg.connectsToBorder = true; + } + } + + } + + // Update overlapping regions. + for (int i = 0; i < lregs.size()-1; ++i) + { + for (int j = i+1; j < lregs.size(); ++j) + { + if (lregs[i] != lregs[j]) + { + rcRegion& ri = regions[lregs[i]]; + rcRegion& rj = regions[lregs[j]]; + addUniqueFloorRegion(ri, lregs[j]); + addUniqueFloorRegion(rj, lregs[i]); + } + } + } + + } + } + + // Create 2D layers from regions. + unsigned short layerId = 1; + + for (int i = 0; i < nreg; ++i) + regions[i].id = 0; + + // Merge montone regions to create non-overlapping areas. + rcIntArray stack(32); + for (int i = 1; i < nreg; ++i) + { + rcRegion& root = regions[i]; + // Skip already visited. + if (root.id != 0) + continue; + + // Start search. + root.id = layerId; + + stack.resize(0); + stack.push(i); + + while (stack.size() > 0) + { + // Pop front + rcRegion& reg = regions[stack[0]]; + for (int j = 0; j < stack.size()-1; ++j) + stack[j] = stack[j+1]; + stack.resize(stack.size()-1); + + const int ncons = (int)reg.connections.size(); + for (int j = 0; j < ncons; ++j) + { + const int nei = reg.connections[j]; + rcRegion& regn = regions[nei]; + // Skip already visited. + if (regn.id != 0) + continue; + // Skip if the neighbour is overlapping root region. + bool overlap = false; + for (int k = 0; k < root.floors.size(); k++) + { + if (root.floors[k] == nei) + { + overlap = true; + break; + } + } + if (overlap) + continue; + + // Deepen + stack.push(nei); + + // Mark layer id + regn.id = layerId; + // Merge current layers to root. + for (int k = 0; k < regn.floors.size(); ++k) + addUniqueFloorRegion(root, regn.floors[k]); + root.ymin = rcMin(root.ymin, regn.ymin); + root.ymax = rcMax(root.ymax, regn.ymax); + root.spanCount += regn.spanCount; + regn.spanCount = 0; + root.connectsToBorder = root.connectsToBorder || regn.connectsToBorder; + } + } + + layerId++; + } + + // Remove small regions + for (int i = 0; i < nreg; ++i) + { + if (regions[i].spanCount > 0 && regions[i].spanCount < minRegionArea && !regions[i].connectsToBorder) + { + unsigned short reg = regions[i].id; + for (int j = 0; j < nreg; ++j) + if (regions[j].id == reg) + regions[j].id = 0; + } + } + + // Compress region Ids. + for (int i = 0; i < nreg; ++i) + { + regions[i].remap = false; + if (regions[i].id == 0) continue; // Skip nil regions. + if (regions[i].id & RC_BORDER_REG) continue; // Skip external regions. + regions[i].remap = true; + } + + unsigned short regIdGen = 0; + for (int i = 0; i < nreg; ++i) + { + if (!regions[i].remap) + continue; + unsigned short oldId = regions[i].id; + unsigned short newId = ++regIdGen; + for (int j = i; j < nreg; ++j) + { + if (regions[j].id == oldId) + { + regions[j].id = newId; + regions[j].remap = false; + } + } + } + maxRegionId = regIdGen; + + // Remap regions. + for (int i = 0; i < chf.spanCount; ++i) + { + if ((srcReg[i] & RC_BORDER_REG) == 0) + srcReg[i] = regions[srcReg[i]].id; + } for (int i = 0; i < nreg; ++i) regions[i].~rcRegion(); @@ -1011,6 +1241,8 @@ static bool filterSmallRegions(rcContext* ctx, int minRegionArea, int mergeRegio return true; } + + /// @par /// /// This is usually the second to the last step in creating a fully built @@ -1256,13 +1488,17 @@ bool rcBuildRegionsMonotone(rcContext* ctx, rcCompactHeightfield& chf, } } + ctx->startTimer(RC_TIMER_BUILD_REGIONS_FILTER); - // Filter out small regions. + // Merge regions and filter out small regions. + rcIntArray overlaps; chf.maxRegions = id; - if (!filterSmallRegions(ctx, minRegionArea, mergeRegionArea, chf.maxRegions, chf, srcReg)) + if (!mergeAndFilterRegions(ctx, minRegionArea, mergeRegionArea, chf.maxRegions, chf, srcReg, overlaps)) return false; + // Monotone partitioning does not generate overlapping regions. + ctx->stopTimer(RC_TIMER_BUILD_REGIONS_FILTER); // Store the result out. @@ -1407,11 +1643,18 @@ bool rcBuildRegions(rcContext* ctx, rcCompactHeightfield& chf, ctx->startTimer(RC_TIMER_BUILD_REGIONS_FILTER); - // Filter out small regions. + // Merge regions and filter out smalle regions. + rcIntArray overlaps; chf.maxRegions = regionId; - if (!filterSmallRegions(ctx, minRegionArea, mergeRegionArea, chf.maxRegions, chf, srcReg)) + if (!mergeAndFilterRegions(ctx, minRegionArea, mergeRegionArea, chf.maxRegions, chf, srcReg, overlaps)) return false; - + + // If overlapping regions were found during merging, split those regions. + if (overlaps.size() > 0) + { + ctx->log(RC_LOG_ERROR, "rcBuildRegions: %d overlapping regions.", overlaps.size()); + } + ctx->stopTimer(RC_TIMER_BUILD_REGIONS_FILTER); // Write the result out. @@ -1424,3 +1667,157 @@ bool rcBuildRegions(rcContext* ctx, rcCompactHeightfield& chf, } +bool rcBuildLayerRegions(rcContext* ctx, rcCompactHeightfield& chf, + const int borderSize, const int minRegionArea) +{ + rcAssert(ctx); + + ctx->startTimer(RC_TIMER_BUILD_REGIONS); + + const int w = chf.width; + const int h = chf.height; + unsigned short id = 1; + + rcScopedDelete<unsigned short> srcReg = (unsigned short*)rcAlloc(sizeof(unsigned short)*chf.spanCount, RC_ALLOC_TEMP); + if (!srcReg) + { + ctx->log(RC_LOG_ERROR, "rcBuildRegionsMonotone: Out of memory 'src' (%d).", chf.spanCount); + return false; + } + memset(srcReg,0,sizeof(unsigned short)*chf.spanCount); + + const int nsweeps = rcMax(chf.width,chf.height); + rcScopedDelete<rcSweepSpan> sweeps = (rcSweepSpan*)rcAlloc(sizeof(rcSweepSpan)*nsweeps, RC_ALLOC_TEMP); + if (!sweeps) + { + ctx->log(RC_LOG_ERROR, "rcBuildRegionsMonotone: Out of memory 'sweeps' (%d).", nsweeps); + return false; + } + + + // Mark border regions. + if (borderSize > 0) + { + // Make sure border will not overflow. + const int bw = rcMin(w, borderSize); + const int bh = rcMin(h, borderSize); + // Paint regions + paintRectRegion(0, bw, 0, h, id|RC_BORDER_REG, chf, srcReg); id++; + paintRectRegion(w-bw, w, 0, h, id|RC_BORDER_REG, chf, srcReg); id++; + paintRectRegion(0, w, 0, bh, id|RC_BORDER_REG, chf, srcReg); id++; + paintRectRegion(0, w, h-bh, h, id|RC_BORDER_REG, chf, srcReg); id++; + + chf.borderSize = borderSize; + } + + rcIntArray prev(256); + + // Sweep one line at a time. + for (int y = borderSize; y < h-borderSize; ++y) + { + // Collect spans from this row. + prev.resize(id+1); + memset(&prev[0],0,sizeof(int)*id); + unsigned short rid = 1; + + for (int x = borderSize; x < w-borderSize; ++x) + { + const rcCompactCell& c = chf.cells[x+y*w]; + + for (int i = (int)c.index, ni = (int)(c.index+c.count); i < ni; ++i) + { + const rcCompactSpan& s = chf.spans[i]; + if (chf.areas[i] == RC_NULL_AREA) continue; + + // -x + unsigned short previd = 0; + if (rcGetCon(s, 0) != RC_NOT_CONNECTED) + { + const int ax = x + rcGetDirOffsetX(0); + const int ay = y + rcGetDirOffsetY(0); + const int ai = (int)chf.cells[ax+ay*w].index + rcGetCon(s, 0); + if ((srcReg[ai] & RC_BORDER_REG) == 0 && chf.areas[i] == chf.areas[ai]) + previd = srcReg[ai]; + } + + if (!previd) + { + previd = rid++; + sweeps[previd].rid = previd; + sweeps[previd].ns = 0; + sweeps[previd].nei = 0; + } + + // -y + if (rcGetCon(s,3) != RC_NOT_CONNECTED) + { + const int ax = x + rcGetDirOffsetX(3); + const int ay = y + rcGetDirOffsetY(3); + const int ai = (int)chf.cells[ax+ay*w].index + rcGetCon(s, 3); + if (srcReg[ai] && (srcReg[ai] & RC_BORDER_REG) == 0 && chf.areas[i] == chf.areas[ai]) + { + unsigned short nr = srcReg[ai]; + if (!sweeps[previd].nei || sweeps[previd].nei == nr) + { + sweeps[previd].nei = nr; + sweeps[previd].ns++; + prev[nr]++; + } + else + { + sweeps[previd].nei = RC_NULL_NEI; + } + } + } + + srcReg[i] = previd; + } + } + + // Create unique ID. + for (int i = 1; i < rid; ++i) + { + if (sweeps[i].nei != RC_NULL_NEI && sweeps[i].nei != 0 && + prev[sweeps[i].nei] == (int)sweeps[i].ns) + { + sweeps[i].id = sweeps[i].nei; + } + else + { + sweeps[i].id = id++; + } + } + + // Remap IDs + for (int x = borderSize; x < w-borderSize; ++x) + { + const rcCompactCell& c = chf.cells[x+y*w]; + + for (int i = (int)c.index, ni = (int)(c.index+c.count); i < ni; ++i) + { + if (srcReg[i] > 0 && srcReg[i] < rid) + srcReg[i] = sweeps[srcReg[i]].id; + } + } + } + + + ctx->startTimer(RC_TIMER_BUILD_REGIONS_FILTER); + + // Merge monotone regions to layers and remove small regions. + rcIntArray overlaps; + chf.maxRegions = id; + if (!mergeAndFilterLayerRegions(ctx, minRegionArea, chf.maxRegions, chf, srcReg, overlaps)) + return false; + + ctx->stopTimer(RC_TIMER_BUILD_REGIONS_FILTER); + + + // Store the result out. + for (int i = 0; i < chf.spanCount; ++i) + chf.spans[i].reg = srcReg[i]; + + ctx->stopTimer(RC_TIMER_BUILD_REGIONS); + + return true; +} diff --git a/dep/recastnavigation/TODO.txt b/dep/recastnavigation/TODO.txt deleted file mode 100644 index b911c0e4720..00000000000 --- a/dep/recastnavigation/TODO.txt +++ /dev/null @@ -1,20 +0,0 @@ -TODO/Roadmap - -Summer/Autumn 2009 - -- Off mesh links (jump links) -- Area annotations -- Embed extra data per polygon -- Height conforming navmesh - - -Autumn/Winter 2009/2010 - -- Detour path following -- More dynamic example with tile navmesh -- Faster small tile process - - -More info at http://digestingduck.blogspot.com/2009/07/recast-and-detour-roadmap.html - -- diff --git a/dep/recastnavigation/recast_hotfix1.diff b/dep/recastnavigation/recast_hotfix1.diff deleted file mode 100644 index d370b0a68c8..00000000000 --- a/dep/recastnavigation/recast_hotfix1.diff +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/dep/recastnavigation/Detour/DetourNavMesh.h b/dep/recastnavigation/Detour/DetourNavMesh.h -index 52d2c50..99e30c7 100644 ---- a/dep/recastnavigation/Detour/DetourNavMesh.h -+++ b/dep/recastnavigation/Detour/DetourNavMesh.h -@@ -21,7 +21,7 @@ - - #include "DetourAlloc.h" - --#ifdef WIN32 -+#if defined(WIN32) && !defined(__MINGW32__) - typedef unsigned __int64 uint64; - #else - #include <stdint.h> diff --git a/dep/recastnavigation/recast_hotfix2.diff b/dep/recastnavigation/recast_hotfix2.diff deleted file mode 100644 index cd73165dcb7..00000000000 --- a/dep/recastnavigation/recast_hotfix2.diff +++ /dev/null @@ -1,38 +0,0 @@ -diff --git a/dep/recastnavigation/Detour/DetourNavMesh.h b/dep/recastnavigation/Detour/DetourNavMesh.h -index c094e41..9c61a9b 100644 ---- a/dep/recastnavigation/Detour/DetourNavMesh.h -+++ b/dep/recastnavigation/Detour/DetourNavMesh.h -@@ -25,7 +25,8 @@ - - // Edited by TC - #if defined(WIN32) && !defined(__MINGW32__) --typedef unsigned __int64 uint64; -+/// Do not rename back to uint64. Otherwise mac complains about typedef redefinition -+typedef unsigned __int64 uint64_d; - #else - #include <stdint.h> - #ifndef uint64_t -@@ -33,7 +34,8 @@ typedef unsigned __int64 uint64; - #include <linux/types.h> - #endif - #endif --typedef uint64_t uint64; -+/// Do not rename back to uint64. Otherwise mac complains about typedef redefinition -+typedef uint64_t uint64_d; - #endif - - // Note: If you want to use 64-bit refs, change the types of both dtPolyRef & dtTileRef. -@@ -48,11 +50,11 @@ static const int STATIC_POLY_BITS = 31; - - /// A handle to a polygon within a navigation mesh tile. - /// @ingroup detour --typedef uint64 dtPolyRef; // Edited by TC -+typedef uint64_d dtPolyRef; // Edited by TC - - /// A handle to a tile within a navigation mesh. - /// @ingroup detour --typedef uint64 dtTileRef; // Edited by TC -+typedef uint64_d dtTileRef; // Edited by TC - - /// The maximum number of vertices per navigation polygon. - /// @ingroup detour diff --git a/dep/recastnavigation/recastnavigation.diff b/dep/recastnavigation/recastnavigation.diff new file mode 100644 index 00000000000..42bab6474e3 --- /dev/null +++ b/dep/recastnavigation/recastnavigation.diff @@ -0,0 +1,448 @@ +From b84e9ffbd1d1e1fb2f5d78cc53d2bb7b56c3fce3 Mon Sep 17 00:00:00 2001 +From: jackpoz <giacomopoz@gmail.com> +Date: Fri, 20 Jun 2014 23:15:04 +0200 +Subject: [PATCH] Add custom trinitycore changes + +--- + Detour/Include/DetourNavMesh.h | 76 ++++++++------------------ + Detour/Source/DetourCommon.cpp | 4 +- + Detour/Source/DetourNavMesh.cpp | 32 ++++------- + Detour/Source/DetourNavMeshBuilder.cpp | 6 +- + Detour/Source/DetourNavMeshQuery.cpp | 9 +-- + Detour/Source/DetourNode.cpp | 29 +++------- + DetourCrowd/Source/DetourObstacleAvoidance.cpp | 6 +- + Recast/Include/Recast.h | 8 +-- + 8 files changed, 59 insertions(+), 111 deletions(-) + +diff --git a/Detour/Include/DetourNavMesh.h b/Detour/Include/DetourNavMesh.h +index 1060845..782ddbc 100644 +--- a/Detour/Include/DetourNavMesh.h ++++ b/Detour/Include/DetourNavMesh.h +@@ -22,39 +22,35 @@ + #include "DetourAlloc.h" + #include "DetourStatus.h" + +-// Undefine (or define in a build cofnig) the following line to use 64bit polyref. +-// Generally not needed, useful for very large worlds. +-// Note: tiles build using 32bit refs are not compatible with 64bit refs! +-//#define DT_POLYREF64 1 +- +-#ifdef DT_POLYREF64 +-// TODO: figure out a multiplatform version of uint64_t +-// - maybe: https://code.google.com/p/msinttypes/ +-// - or: http://www.azillionmonkeys.com/qed/pstdint.h ++ ++// Edited by TC ++#if defined(WIN32) && !defined(__MINGW32__) ++/// Do not rename back to uint64. Otherwise mac complains about typedef redefinition ++typedef unsigned __int64 uint64_d; ++#else + #include <stdint.h> ++#ifndef uint64_t ++#ifdef __linux__ ++#include <linux/types.h> ++#endif + #endif ++/// Do not rename back to uint64. Otherwise mac complains about typedef redefinition ++typedef uint64_t uint64_d; ++#endif + + // Note: If you want to use 64-bit refs, change the types of both dtPolyRef & dtTileRef. + // It is also recommended that you change dtHashRef() to a proper 64-bit hash. + ++// Edited by TC ++// We cannot have over 31 bits for either tile nor poly ++// without changing polyCount to use 64bits too. + /// A handle to a polygon within a navigation mesh tile. + /// @ingroup detour +-#ifdef DT_POLYREF64 +-static const unsigned int DT_SALT_BITS = 16; +-static const unsigned int DT_TILE_BITS = 28; +-static const unsigned int DT_POLY_BITS = 20; +-typedef uint64_t dtPolyRef; +-#else +-typedef unsigned int dtPolyRef; +-#endif ++typedef uint64_d dtPolyRef; // Edited by TC + + /// A handle to a tile within a navigation mesh. + /// @ingroup detour +-#ifdef DT_POLYREF64 +-typedef uint64_t dtTileRef; +-#else +-typedef unsigned int dtTileRef; +-#endif ++typedef uint64_d dtTileRef; // Edited by TC + + /// The maximum number of vertices per navigation polygon. + /// @ingroup detour +@@ -94,6 +90,12 @@ static const unsigned int DT_OFFMESH_CON_BIDIR = 1; + /// @ingroup detour + static const int DT_MAX_AREAS = 64; + ++static const int STATIC_SALT_BITS = 12; ++static const int STATIC_TILE_BITS = 21; ++static const int STATIC_POLY_BITS = 31; ++// we cannot have over 31 bits for either tile nor poly ++// without changing polyCount to use 64bits too. ++ + /// Tile flags used for various functions and fields. + /// For an example, see dtNavMesh::addTile(). + enum dtTileFlags +@@ -511,11 +513,7 @@ public: + /// @param[in] ip The index of the polygon within the tile. + inline dtPolyRef encodePolyId(unsigned int salt, unsigned int it, unsigned int ip) const + { +-#ifdef DT_POLYREF64 +- return ((dtPolyRef)salt << (DT_POLY_BITS+DT_TILE_BITS)) | ((dtPolyRef)it << DT_POLY_BITS) | (dtPolyRef)ip; +-#else + return ((dtPolyRef)salt << (m_polyBits+m_tileBits)) | ((dtPolyRef)it << m_polyBits) | (dtPolyRef)ip; +-#endif + } + + /// Decodes a standard polygon reference. +@@ -527,21 +525,12 @@ public: + /// @see #encodePolyId + inline void decodePolyId(dtPolyRef ref, unsigned int& salt, unsigned int& it, unsigned int& ip) const + { +-#ifdef DT_POLYREF64 +- const dtPolyRef saltMask = ((dtPolyRef)1<<DT_SALT_BITS)-1; +- const dtPolyRef tileMask = ((dtPolyRef)1<<DT_TILE_BITS)-1; +- const dtPolyRef polyMask = ((dtPolyRef)1<<DT_POLY_BITS)-1; +- salt = (unsigned int)((ref >> (DT_POLY_BITS+DT_TILE_BITS)) & saltMask); +- it = (unsigned int)((ref >> DT_POLY_BITS) & tileMask); +- ip = (unsigned int)(ref & polyMask); +-#else + const dtPolyRef saltMask = ((dtPolyRef)1<<m_saltBits)-1; + const dtPolyRef tileMask = ((dtPolyRef)1<<m_tileBits)-1; + const dtPolyRef polyMask = ((dtPolyRef)1<<m_polyBits)-1; + salt = (unsigned int)((ref >> (m_polyBits+m_tileBits)) & saltMask); + it = (unsigned int)((ref >> m_polyBits) & tileMask); + ip = (unsigned int)(ref & polyMask); +-#endif + } + + /// Extracts a tile's salt value from the specified polygon reference. +@@ -550,13 +539,8 @@ public: + /// @see #encodePolyId + inline unsigned int decodePolyIdSalt(dtPolyRef ref) const + { +-#ifdef DT_POLYREF64 +- const dtPolyRef saltMask = ((dtPolyRef)1<<DT_SALT_BITS)-1; +- return (unsigned int)((ref >> (DT_POLY_BITS+DT_TILE_BITS)) & saltMask); +-#else + const dtPolyRef saltMask = ((dtPolyRef)1<<m_saltBits)-1; + return (unsigned int)((ref >> (m_polyBits+m_tileBits)) & saltMask); +-#endif + } + + /// Extracts the tile's index from the specified polygon reference. +@@ -565,13 +549,8 @@ public: + /// @see #encodePolyId + inline unsigned int decodePolyIdTile(dtPolyRef ref) const + { +-#ifdef DT_POLYREF64 +- const dtPolyRef tileMask = ((dtPolyRef)1<<DT_TILE_BITS)-1; +- return (unsigned int)((ref >> DT_POLY_BITS) & tileMask); +-#else + const dtPolyRef tileMask = ((dtPolyRef)1<<m_tileBits)-1; + return (unsigned int)((ref >> m_polyBits) & tileMask); +-#endif + } + + /// Extracts the polygon's index (within its tile) from the specified polygon reference. +@@ -580,13 +559,8 @@ public: + /// @see #encodePolyId + inline unsigned int decodePolyIdPoly(dtPolyRef ref) const + { +-#ifdef DT_POLYREF64 +- const dtPolyRef polyMask = ((dtPolyRef)1<<DT_POLY_BITS)-1; +- return (unsigned int)(ref & polyMask); +-#else + const dtPolyRef polyMask = ((dtPolyRef)1<<m_polyBits)-1; + return (unsigned int)(ref & polyMask); +-#endif + } + + /// @} +@@ -645,11 +619,9 @@ private: + dtMeshTile* m_nextFree; ///< Freelist of tiles. + dtMeshTile* m_tiles; ///< List of tiles. + +-#ifndef DT_POLYREF64 + unsigned int m_saltBits; ///< Number of salt bits in the tile ID. + unsigned int m_tileBits; ///< Number of tile bits in the tile ID. + unsigned int m_polyBits; ///< Number of poly bits in the tile ID. +-#endif + }; + + /// Allocates a navigation mesh object using the Detour allocator. +diff --git a/Detour/Source/DetourCommon.cpp b/Detour/Source/DetourCommon.cpp +index a98d8c8..b5700f5 100644 +--- a/Detour/Source/DetourCommon.cpp ++++ b/Detour/Source/DetourCommon.cpp +@@ -16,14 +16,14 @@ + // 3. This notice may not be removed or altered from any source distribution. + // + ++#include <math.h> + #include "DetourCommon.h" +-#include "DetourMath.h" + + ////////////////////////////////////////////////////////////////////////////////////////// + + float dtSqrt(float x) + { +- return dtMathSqrtf(x); ++ return sqrtf(x); + } + + void dtClosestPtPointTriangle(float* closest, const float* p, +diff --git a/Detour/Source/DetourNavMesh.cpp b/Detour/Source/DetourNavMesh.cpp +index 9d627be..5174050 100644 +--- a/Detour/Source/DetourNavMesh.cpp ++++ b/Detour/Source/DetourNavMesh.cpp +@@ -16,13 +16,13 @@ + // 3. This notice may not be removed or altered from any source distribution. + // + ++#include <math.h> + #include <float.h> + #include <string.h> + #include <stdio.h> + #include "DetourNavMesh.h" + #include "DetourNode.h" + #include "DetourCommon.h" +-#include "DetourMath.h" + #include "DetourAlloc.h" + #include "DetourAssert.h" + #include <new> +@@ -193,13 +193,11 @@ dtNavMesh::dtNavMesh() : + m_tileLutMask(0), + m_posLookup(0), + m_nextFree(0), +- m_tiles(0) ++ m_tiles(0), ++ m_saltBits(0), ++ m_tileBits(0), ++ m_polyBits(0) + { +-#ifndef DT_POLYREF64 +- m_saltBits = 0; +- m_tileBits = 0; +- m_polyBits = 0; +-#endif + memset(&m_params, 0, sizeof(dtNavMeshParams)); + m_orig[0] = 0; + m_orig[1] = 0; +@@ -250,17 +248,11 @@ dtStatus dtNavMesh::init(const dtNavMeshParams* params) + m_nextFree = &m_tiles[i]; + } + +- // Init ID generator values. +-#ifndef DT_POLYREF64 +- m_tileBits = dtIlog2(dtNextPow2((unsigned int)params->maxTiles)); +- m_polyBits = dtIlog2(dtNextPow2((unsigned int)params->maxPolys)); +- // Only allow 31 salt bits, since the salt mask is calculated using 32bit uint and it will overflow. +- m_saltBits = dtMin((unsigned int)31, 32 - m_tileBits - m_polyBits); +- +- if (m_saltBits < 10) +- return DT_FAILURE | DT_INVALID_PARAM; +-#endif +- ++ // Edited by TC ++ m_tileBits = STATIC_TILE_BITS; ++ m_polyBits = STATIC_POLY_BITS; ++ m_saltBits = STATIC_SALT_BITS; ++ + return DT_SUCCESS; + } + +@@ -1242,11 +1234,7 @@ dtStatus dtNavMesh::removeTile(dtTileRef ref, unsigned char** data, int* dataSiz + tile->offMeshCons = 0; + + // Update salt, salt should never be zero. +-#ifdef DT_POLYREF64 +- tile->salt = (tile->salt+1) & ((1<<DT_SALT_BITS)-1); +-#else + tile->salt = (tile->salt+1) & ((1<<m_saltBits)-1); +-#endif + if (tile->salt == 0) + tile->salt++; + +diff --git a/Detour/Source/DetourNavMeshBuilder.cpp b/Detour/Source/DetourNavMeshBuilder.cpp +index 1bf271b..9d8471b 100644 +--- a/Detour/Source/DetourNavMeshBuilder.cpp ++++ b/Detour/Source/DetourNavMeshBuilder.cpp +@@ -16,13 +16,13 @@ + // 3. This notice may not be removed or altered from any source distribution. + // + ++#include <math.h> + #include <stdio.h> + #include <stdlib.h> + #include <string.h> + #include <float.h> + #include "DetourNavMesh.h" + #include "DetourCommon.h" +-#include "DetourMath.h" + #include "DetourNavMeshBuilder.h" + #include "DetourAlloc.h" + #include "DetourAssert.h" +@@ -202,8 +202,8 @@ static int createBVTree(const unsigned short* verts, const int /*nverts*/, + if (z > it.bmax[2]) it.bmax[2] = z; + } + // Remap y +- it.bmin[1] = (unsigned short)dtMathFloorf((float)it.bmin[1]*ch/cs); +- it.bmax[1] = (unsigned short)dtMathCeilf((float)it.bmax[1]*ch/cs); ++ it.bmin[1] = (unsigned short)floorf((float)it.bmin[1]*ch/cs); ++ it.bmax[1] = (unsigned short)ceilf((float)it.bmax[1]*ch/cs); + } + + int curNode = 0; +diff --git a/Detour/Source/DetourNavMeshQuery.cpp b/Detour/Source/DetourNavMeshQuery.cpp +index 9debb4d..ec3a294 100644 +--- a/Detour/Source/DetourNavMeshQuery.cpp ++++ b/Detour/Source/DetourNavMeshQuery.cpp +@@ -16,13 +16,13 @@ + // 3. This notice may not be removed or altered from any source distribution. + // + ++#include <math.h> + #include <float.h> + #include <string.h> + #include "DetourNavMeshQuery.h" + #include "DetourNavMesh.h" + #include "DetourNode.h" + #include "DetourCommon.h" +-#include "DetourMath.h" + #include "DetourAlloc.h" + #include "DetourAssert.h" + #include <new> +@@ -99,8 +99,9 @@ inline float dtQueryFilter::getCost(const float* pa, const float* pb, + return dtVdist(pa, pb) * m_areaCost[curPoly->getArea()]; + } + #endif +- +-static const float H_SCALE = 0.999f; // Search heuristic scale. ++ ++// Edited by TC ++static const float H_SCALE = 2.0f; // Search heuristic scale. + + + dtNavMeshQuery* dtAllocNavMeshQuery() +@@ -3504,7 +3505,7 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen + dtVsub(hitNormal, centerPos, hitPos); + dtVnormalize(hitNormal); + +- *hitDist = dtMathSqrtf(radiusSqr); ++ *hitDist = sqrtf(radiusSqr); + + return status; + } +diff --git a/Detour/Source/DetourNode.cpp b/Detour/Source/DetourNode.cpp +index 5cf6548..1d18977 100644 +--- a/Detour/Source/DetourNode.cpp ++++ b/Detour/Source/DetourNode.cpp +@@ -22,30 +22,17 @@ + #include "DetourCommon.h" + #include <string.h> + +-#ifdef DT_POLYREF64 +-// From Thomas Wang, https://gist.github.com/badboy/6267743 + inline unsigned int dtHashRef(dtPolyRef a) + { +- a = (~a) + (a << 18); // a = (a << 18) - a - 1; +- a = a ^ (a >> 31); +- a = a * 21; // a = (a + (a << 2)) + (a << 4); +- a = a ^ (a >> 11); +- a = a + (a << 6); +- a = a ^ (a >> 22); +- return (unsigned int)a; ++ // Edited by TC ++ a = (~a) + (a << 18); ++ a = a ^ (a >> 31); ++ a = a * 21; ++ a = a ^ (a >> 11); ++ a = a + (a << 6); ++ a = a ^ (a >> 22); ++ return (unsigned int)a; + } +-#else +-inline unsigned int dtHashRef(dtPolyRef a) +-{ +- a += ~(a<<15); +- a ^= (a>>10); +- a += (a<<3); +- a ^= (a>>6); +- a += ~(a<<11); +- a ^= (a>>16); +- return (unsigned int)a; +-} +-#endif + + ////////////////////////////////////////////////////////////////////////////////////////// + dtNodePool::dtNodePool(int maxNodes, int hashSize) : +diff --git a/DetourCrowd/Source/DetourObstacleAvoidance.cpp b/DetourCrowd/Source/DetourObstacleAvoidance.cpp +index 0fad9ef..d3f90b7 100644 +--- a/DetourCrowd/Source/DetourObstacleAvoidance.cpp ++++ b/DetourCrowd/Source/DetourObstacleAvoidance.cpp +@@ -18,10 +18,10 @@ + + #include "DetourObstacleAvoidance.h" + #include "DetourCommon.h" +-#include "DetourMath.h" + #include "DetourAlloc.h" + #include "DetourAssert.h" + #include <string.h> ++#include <math.h> + #include <float.h> + #include <new> + +@@ -58,7 +58,7 @@ static int isectRaySeg(const float* ap, const float* u, + dtVsub(v,bq,bp); + dtVsub(w,ap,bp); + float d = dtVperp2D(u,v); +- if (dtMathFabs(d) < 1e-6f) return 0; ++ if (fabsf(d) < 1e-6f) return 0; + d = 1.0f/d; + t = dtVperp2D(v,w) * d; + if (t < 0 || t > 1) return 0; +@@ -482,7 +482,7 @@ int dtObstacleAvoidanceQuery::sampleVelocityAdaptive(const float* pos, const flo + const int nd = dtClamp(ndivs, 1, DT_MAX_PATTERN_DIVS); + const int nr = dtClamp(nrings, 1, DT_MAX_PATTERN_RINGS); + const float da = (1.0f/nd) * DT_PI*2; +- const float dang = dtMathAtan2f(dvel[2], dvel[0]); ++ const float dang = atan2f(dvel[2], dvel[0]); + + // Always add sample at zero + pat[npat*2+0] = 0; +diff --git a/Recast/Include/Recast.h b/Recast/Include/Recast.h +index 83ca606..66974cd 100644 +--- a/Recast/Include/Recast.h ++++ b/Recast/Include/Recast.h +@@ -243,7 +243,7 @@ struct rcConfig + }; + + /// Defines the number of bits allocated to rcSpan::smin and rcSpan::smax. +-static const int RC_SPAN_HEIGHT_BITS = 13; ++static const int RC_SPAN_HEIGHT_BITS = 16; // EDITED BY TC + /// Defines the maximum value for rcSpan::smin and rcSpan::smax. + static const int RC_SPAN_MAX_HEIGHT = (1<<RC_SPAN_HEIGHT_BITS)-1; + +@@ -255,9 +255,9 @@ static const int RC_SPANS_PER_POOL = 2048; + /// @see rcHeightfield + struct rcSpan + { +- unsigned int smin : 13; ///< The lower limit of the span. [Limit: < #smax] +- unsigned int smax : 13; ///< The upper limit of the span. [Limit: <= #RC_SPAN_MAX_HEIGHT] +- unsigned int area : 6; ///< The area id assigned to the span. ++ unsigned int smin : 16; ///< The lower limit of the span. [Limit: < #smax] ++ unsigned int smax : 16; ///< The upper limit of the span. [Limit: <= #RC_SPAN_MAX_HEIGHT] ++ unsigned char area; ///< The area id assigned to the span. + rcSpan* next; ///< The next span higher up in column. + }; + +-- +1.9.0.msysgit.0 + |