[Extras-wsdlpull-svn] SF.net SVN: extras-wsdlpull:[189] trunk/wsdlpull
Status: Beta
Brought to you by:
denis_arnaud
From: <den...@us...> - 2010-06-12 12:15:05
|
Revision: 189 http://extras-wsdlpull.svn.sourceforge.net/extras-wsdlpull/?rev=189&view=rev Author: denis_arnaud Date: 2010-06-12 12:12:11 +0000 (Sat, 12 Jun 2010) Log Message: ----------- [Upstream] Upstream integration (version 1.24). Modified Paths: -------------- trunk/wsdlpull/AUTHORS trunk/wsdlpull/CHANGES trunk/wsdlpull/src/schemaparser/SchemaParser.cpp trunk/wsdlpull/src/schemaparser/SchemaValidator.cpp trunk/wsdlpull/src/tools/wsdl.cpp trunk/wsdlpull/src/wsdlparser/WsdlInvoker.cpp trunk/wsdlpull/src/wsdlparser/WsdlParser.cpp trunk/wsdlpull/src/xmlpull/XmlUtils.cpp trunk/wsdlpull/src/xmlpull/XmlUtils.h Modified: trunk/wsdlpull/AUTHORS =================================================================== --- trunk/wsdlpull/AUTHORS 2009-06-22 20:08:41 UTC (rev 188) +++ trunk/wsdlpull/AUTHORS 2010-06-12 12:12:11 UTC (rev 189) @@ -2,8 +2,10 @@ 1. Vivek Krishna <viv...@us...> Other contributors +Daniel Rodriguez (for the xpath implementation) +Meindert Oldenburger (for making wsdlpull more thread safe) Scott Chun (Windows DLL export) Philip Helger (Windows makefile) Thomas Steinel -Stefan Fleiter +Stefan Fleiter Igor Polyakov Modified: trunk/wsdlpull/CHANGES =================================================================== --- trunk/wsdlpull/CHANGES 2009-06-22 20:08:41 UTC (rev 188) +++ trunk/wsdlpull/CHANGES 2010-06-12 12:12:11 UTC (rev 189) @@ -1,3 +1,10 @@ +1.24 +Generate single empty tag for nillable complex elements i.e <name/> instead of <name><fname/><lname/></name> +Pass the correct schema parser when types are imported +Options to parse schemas from the web/filesystem +Thread safety fixes while fetching temp files +Updated AUTHORS.txt file + 1.23 Fixed the getAsXpath method Changed the SOAP 1.2 uri in Soap.cpp to point to correct schema Modified: trunk/wsdlpull/src/schemaparser/SchemaParser.cpp =================================================================== --- trunk/wsdlpull/src/schemaparser/SchemaParser.cpp 2009-06-22 20:08:41 UTC (rev 188) +++ trunk/wsdlpull/src/schemaparser/SchemaParser.cpp 2010-06-12 12:12:11 UTC (rev 189) @@ -1524,10 +1524,11 @@ return parseInclude();//sometimes import is used to import schemas in same ns. //treat it internally like include + // if (loc.empty()) // loc = ns; //try using the namespace as schemalocation - // FV Sat Dec 22 15:33:09 CET 2007 I added the absolute path and the file:/ use-cases in the the test + // if ( !loc.empty() && loc.find("http://") == std::string::npos) // loc = uri_ + loc; @@ -1566,6 +1567,8 @@ } } + + if(sp->parseSchemaTag()) addImport(sp); else Modified: trunk/wsdlpull/src/schemaparser/SchemaValidator.cpp =================================================================== --- trunk/wsdlpull/src/schemaparser/SchemaValidator.cpp 2009-06-22 20:08:41 UTC (rev 188) +++ trunk/wsdlpull/src/schemaparser/SchemaValidator.cpp 2010-06-12 12:12:11 UTC (rev 189) @@ -232,7 +232,7 @@ ContentModel* cm=ct->getContents(); ContentModel * bCm = 0; if (bt) - bCm = bt ->getContents(); + bCm = bt->getContents(); if(cm) validateContentModel(xpp, cm, @@ -296,7 +296,8 @@ int t = btCnt->getTypeId(); const ComplexType* ct = static_cast<const ComplexType*>(btCnt->schemaParser()->getType(t)); bCm = ct->getContents(); - bci =bCm->begin(); + if (bCm) + bci =bCm->begin(); } switch (cm->getCompositor()) { Modified: trunk/wsdlpull/src/tools/wsdl.cpp =================================================================== --- trunk/wsdlpull/src/tools/wsdl.cpp 2009-06-22 20:08:41 UTC (rev 188) +++ trunk/wsdlpull/src/tools/wsdl.cpp 2010-06-12 12:12:11 UTC (rev 189) @@ -48,6 +48,8 @@ std::cout<<" -t requesttimeout in seconds"<<std::endl; std::cout<<" -e set SOAP headers in input"<<std::endl; std::cout<<" -g generate sample SOAP message for the invocation"<<std::endl; + std::cout<<" -w get soap,encoding and wsdl schemas from the web"<<std::endl; + std::cout<<" -f get soap,encoding and wsdl schemas from the filesystem"<<std::endl; std::cout<<" -r Validate the response message with schema even when xpath selector is used(default is off)"<<std::endl; std::cout<<"With no arguments,wsdl starts in the interactive mode accepting operation name and parameters from the standard input."<<std::endl<<std::endl; std::cout<<"An xpath expression can be used to extract elements from web service response.If the expression points to an element or an attribute,the element's text or attribute value will be returned.The expression will match all occurrences in the xml tree"<<std::endl; @@ -116,7 +118,6 @@ WsdlPull::WsdlParser::useLocalSchema_ = false; #endif - int i =1; for (;i<argc && !brkloop;){ switch(argv[i][0]){ @@ -207,6 +208,14 @@ else if(opt == "r"){ processResponse = true; } + else if (opt == "w"){ + + WsdlPull::WsdlParser::useLocalSchema_ = false; + } + else if (opt == "f"){ + + WsdlPull::WsdlParser::useLocalSchema_ = true; + } else{ std::cerr<<"Unknown option "<<argv[i]<<std::endl; usage(); Modified: trunk/wsdlpull/src/wsdlparser/WsdlInvoker.cpp =================================================================== --- trunk/wsdlpull/src/wsdlparser/WsdlInvoker.cpp 2009-06-22 20:08:41 UTC (rev 188) +++ trunk/wsdlpull/src/wsdlparser/WsdlInvoker.cpp 2010-06-12 12:12:11 UTC (rev 189) @@ -447,6 +447,10 @@ if (prt == Part::Elem){ const Element * e = p->element(); + if (e->getTypeNamespace() != sParser->getNamespace()) { + sParser = wParser_->getSchemaParser(e->getTypeNamespace()); + } + //the above can happen when the actual type/element is defined in someother namespace via imports serializeType((Schema::Type)e->getType(),e->getName(),sParser,1,1,parents,e->getTypeNamespace(),true); } else{ @@ -1667,9 +1671,9 @@ #elif _WIN32 - char* sResults = 0; + char* sResults = (char*)0; XmlUtils::winPost(location_,username,passwd,postData,action_,sResults); - strResults_ = std::string(sResults); + strResults_ = (sResults != (char*)0) ? std::string(sResults) : ""; #endif if(verbose_ && !strResults_.empty()){ Modified: trunk/wsdlpull/src/wsdlparser/WsdlParser.cpp =================================================================== --- trunk/wsdlpull/src/wsdlparser/WsdlParser.cpp 2009-06-22 20:08:41 UTC (rev 188) +++ trunk/wsdlpull/src/wsdlparser/WsdlParser.cpp 2010-06-12 12:12:11 UTC (rev 189) @@ -164,18 +164,8 @@ xmlStream.close(); // delete all the temp files - oslink::directory dir("."); - while (dir) { - std::string fname = dir.next(); - if (fname.find(".wp-tmp") != std::string::npos) - { -#ifdef WIN32 - ::DeleteFile(fname.c_str()); -#else - unlink(fname.c_str()); -#endif - } - } + XmlUtils::delUriFiles(); + } const Binding * Modified: trunk/wsdlpull/src/xmlpull/XmlUtils.cpp =================================================================== --- trunk/wsdlpull/src/xmlpull/XmlUtils.cpp 2009-06-22 20:08:41 UTC (rev 188) +++ trunk/wsdlpull/src/xmlpull/XmlUtils.cpp 2010-06-12 12:12:11 UTC (rev 189) @@ -35,6 +35,8 @@ #include <termios.h> #include <unistd.h> #include <errno.h> +#include <pthread.h> +#include <stdlib.h> #endif #ifdef WITH_CURL @@ -45,12 +47,23 @@ #include <cstdlib> #include <cstring> #include <fstream> +#include <sstream> #include <map> +#include <list> + #include "xmlpull/XmlUtils.h" -const std::string ALPHA = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; -std::map<std::string,std::string> urlCache_; +// Global variables +#ifdef _WIN32 +CRITICAL_SECTION cs; +#else +static pthread_mutex_t url_mutex; +#endif +// key is uri+ProcId+ThreadId +// elem is string with the uri +std::map<std::string, std::string> urlCache_; + //put all I/O and std::string manip utiliy functions here int @@ -99,74 +112,234 @@ return str << std::endl << "*************" << std::endl; } + +// get file name +std::string +XmlUtils::getFileName(std::string uri) +{ + std::string filename; + + // unique key url + suffix, see also XmlUtils::creUriFile + std::string map_key(uri + XmlUtils::getSuffix()); + + // Lock actions on urlCache + XmlUtils::MutexLock(); + + if (urlCache_.find(map_key) != urlCache_.end()) { + filename = urlCache_[map_key]; + } + else { + filename = ""; + } + + // Unlock actions on urlCache + XmlUtils::MutexUnlock(); + + return filename; +} + + +// Create unique file +std::string +XmlUtils::creUriFile(std::string uri) +{ + // unique key url + suffix, see also XmlUtils::getFileName + std::string map_key(uri + XmlUtils::getSuffix()); + +#ifdef _WIN32 + char uniqueFile[MAX_PATH]; + GetTempFileName(".", "uri", 0, (LPSTR)uniqueFile); +#else + char uniqueFile[PATH_MAX]; + char ufile[] = "/tmp/wsdl_uri_XXXXXX"; + int fd = mkstemp(ufile); + close(fd); + strcpy(uniqueFile, ufile); +#endif + + // Lock actions on urlCache + XmlUtils::MutexLock(); + + urlCache_[map_key] = uniqueFile; + + // Unlock actions on urlCache + XmlUtils::MutexUnlock(); + + return uniqueFile; +} + + +// Only files belonging to current proces and thread are deleted +void +XmlUtils::delUriFiles() +{ + std::map<std::string, std::string>::iterator iter; + std::list<std::string> uris; + + // Lock actions on urlCache + XmlUtils::MutexLock(); + + for (iter = urlCache_.begin(); iter != urlCache_.end(); iter++) { + if ((iter->first).find(XmlUtils::getSuffix()) != std::string::npos) { +#ifdef _WIN32 + ::DeleteFile((LPCSTR)iter->second.c_str()); +#else + unlink(iter->second.c_str()); +#endif + // remember the key to delete the items in the map + uris.push_back(iter->first); + } + } + + // delete items in the map + while (!uris.empty()) { + iter = urlCache_.find(uris.front()); + urlCache_.erase(iter); + uris.pop_front(); + } + + // Unlock actions on urlCache + XmlUtils::MutexUnlock(); + +} + + +// File name suffix is constructed of ProcessId and ThreadId +std::string +XmlUtils::getSuffix() +{ + std::stringstream ssuffix; +#ifdef _WIN32 + ssuffix << GetCurrentProcessId() << "_" << GetCurrentThreadId(); +#else + ssuffix << getpid() << "_" << pthread_self(); +#endif + + return ssuffix.str(); +} + +void +uri_init() +{ + /* initialise mutex for map operations */ +#ifdef _WIN32 + InitializeCriticalSection(&cs); +#else + pthread_mutex_init(&url_mutex, NULL); +#endif +} + + +void +XmlUtils::MutexInit() +{ +#ifdef _WIN32 + static volatile int initialized = 0; + static HANDLE mtx; + + if (!initialized) { + if (!mtx) { + HANDLE mymtx; + mymtx = CreateMutex(NULL, 0, NULL); + if (InterlockedCompareExchangePointer(&mtx, mymtx, NULL) != NULL) + CloseHandle(mymtx); + } + + WaitForSingleObject(mtx, 0); + if (!initialized) { + uri_init(); + initialized = 1; + } + ReleaseMutex(mtx); + } +#else + static pthread_once_t url_once = PTHREAD_ONCE_INIT; + pthread_once(&url_once, uri_init); +#endif +} + + +void +XmlUtils::MutexLock() +{ +#ifdef _WIN32 + // Request ownership of the critical section. + EnterCriticalSection(&cs); +#else + // mutex_start + pthread_mutex_lock(&url_mutex); +#endif +} + + +void +XmlUtils::MutexUnlock() +{ +#ifdef _WIN32 + // Release ownership of the critical section. + LeaveCriticalSection(&cs); +#else + // mutex_end + pthread_mutex_unlock(&url_mutex); +#endif +} + + /* -* Fetch a document at the given URI and store it in a file -*/ - + * Fetch a document at the given URI and store it in a file + */ bool WSDLPULL_EXPORT XmlUtils::fetchUri(std::string uri, std::string& filename) { - if(uri.find("http://")!=std::string::npos || - uri.find("https://")!=std::string::npos || - uri.find("ftp://") !=std::string::npos) - { - - if (urlCache_.find(uri) != urlCache_.end()) { - filename=urlCache_[uri]; - std::ifstream tfs; - tfs.open(filename.c_str()); - if (tfs.fail()) { - urlCache_.erase(uri); - }else { - - return true; - } + if (uri.find("http://") != std::string::npos || + uri.find("https://") != std::string::npos || + uri.find("ftp://") != std::string::npos) { + + // mutex init for url map operations + XmlUtils::MutexInit(); + + // initial status is that file does not excist + bool file_cached = false; + + // verify if the file already cached and fysical exists + filename = XmlUtils::getFileName(uri); + if (!filename.empty()) { + std::ifstream tfs; + tfs.open(filename.c_str()); + file_cached = !tfs.fail(); + tfs.close(); } -#ifndef _WIN32 - filename=uri.substr(uri.rfind('/')+1); - if (filename.empty()) { - //for *nix try to use the name from the url -#endif - // Generate a random "[8 chars].[3 chars]" filename - srand(time(NULL)); - filename.clear(); - for (int i = 0; i < 8; i++){ - - filename += ALPHA.at(rand()%52); + // if not cached create new file and cach it + if (!file_cached) { + filename = XmlUtils::creUriFile(uri); } - filename.append(".wp-tmp"); -#ifndef _WIN32 + // return if the file is already cached + else { + return true; } - std::string dir="/tmp/"; - filename = dir + filename; -#endif - urlCache_[uri]=filename; #ifdef WITH_CURL - CURL * curl = NULL; + CURL * curl; CURLcode res; curl=curl_easy_init(); - FILE * file = NULL; + FILE * file; if(curl){ file=fopen(filename.c_str(),"w"); if (file == NULL) { fprintf(stderr, "Can't open file %s: %s\n", filename.c_str(), strerror(errno)); - // TODO: an exception should maybe thrown, to replace the exit(-1), - // instead of the simple 'return false' - // exit(-1); - return false; + exit(-1); } - curl_easy_setopt(curl, CURLOPT_URL, uri.c_str()); - curl_easy_setopt(curl, CURLOPT_FILE, (void*)file); - curl_easy_setopt(curl, CURLOPT_TIMEOUT, 60); + curl_easy_setopt(curl, CURLOPT_URL,uri.c_str()); + curl_easy_setopt(curl,CURLOPT_FILE,(void*)file); + curl_easy_setopt(curl,CURLOPT_TIMEOUT,60); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); @@ -217,6 +390,7 @@ // - use-case with a single '/' added (I am not sure this is conform to spec) // #ifdef _WIN32 #if !defined(_WIN32) + /* unsigned int p; if ((p=uri.find("file:///"))!=std::string::npos) { @@ -230,6 +404,13 @@ { uri = uri.substr(p+5, uri.length()-p-5); } + */ + std::string::size_type p; + p = uri.find("file:"); + if ( p !=std::string::npos) + { + uri = uri.substr(5); + } #endif filename=uri; Modified: trunk/wsdlpull/src/xmlpull/XmlUtils.h =================================================================== --- trunk/wsdlpull/src/xmlpull/XmlUtils.h 2009-06-22 20:08:41 UTC (rev 188) +++ trunk/wsdlpull/src/xmlpull/XmlUtils.h 2010-06-12 12:12:11 UTC (rev 189) @@ -32,6 +32,13 @@ //put all miscellaneous utiliy functions here namespace XmlUtils { + std::string getSuffix(); + std::string getFileName(std::string); + std::string creUriFile(std::string); + void delUriFiles(); + void MutexInit(); + void MutexLock(); + void MutexUnlock(); int parseInt (std::string s, int radix = 10); std::ostream & dbsp (std::ostream & str); std::ostream & blk (std::ostream & str); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |