27#pragma comment(lib, "wininet.lib")
76 for (
int i = 0; i < len; i++) {
78 if (s[i] <=
'9' && s[i] >=
'0')
79 value = (i == 0) ? (s[i] -
'0') : radix * value + (s[i] -
'0');
84 else if (radix == 16) {
86 if (s[i] <=
'9' && s[i] >= 0)
87 value = (i == 0) ? (s[i] -
'0') : radix * value + (s[i] -
'0');
89 else if (s[i] <=
'F' && s[i] >=
'A')
92 0) ? (s[i] -
'A') + 10 : radix * value + (s[i] -
'A') + 10;
94 else if (s[i] <=
'f' && s[i] >=
'a')
95 value =(i ==0) ? (s[i] -
'a') + 10 : radix * value + (s[i] -
'a') + 10;
112 return str << std::endl <<
"*************" << std::endl;
120 std::string filename;
150 char uniqueFile[MAX_PATH];
151 GetTempFileName(
".",
"uri", 0, (LPSTR)uniqueFile);
153 char uniqueFile[PATH_MAX];
154 char ufile[] =
"/tmp/wsdl_uri_XXXXXX";
155 int fd = mkstemp(ufile);
157 strcpy(uniqueFile, ufile);
176 std::map<std::string, std::string>::iterator iter;
177 std::list<std::string> uris;
185 ::DeleteFile((LPCSTR)iter->second.c_str());
187 unlink(iter->second.c_str());
190 uris.push_back(iter->first);
195 while (!uris.empty()) {
211 std::stringstream ssuffix;
213 ssuffix << GetCurrentProcessId() <<
"_" << GetCurrentThreadId();
215 ssuffix << getpid() <<
"_" << pthread_self();
218 return ssuffix.str();
226 InitializeCriticalSection(&cs);
237 static volatile int initialized = 0;
243 mymtx = CreateMutex(NULL, 0, NULL);
244 if (InterlockedCompareExchangePointer(&mtx, mymtx, NULL) != NULL)
248 WaitForSingleObject(mtx, 0);
256 static pthread_once_t url_once = PTHREAD_ONCE_INIT;
267 EnterCriticalSection(&cs);
280 LeaveCriticalSection(&cs);
294 std::string& filename)
298 if (uri.find(
"http://") != std::string::npos ||
299 uri.find(
"https://") != std::string::npos ||
300 uri.find(
"ftp://") != std::string::npos) {
306 bool file_cached =
false;
310 if (!filename.empty()) {
312 tfs.open(filename.c_str());
313 file_cached = !tfs.fail();
329 curl=curl_easy_init();
332 file=fopen(filename.c_str(),
"w");
335 fprintf(stderr,
"Can't open file %s: %s\n", filename.c_str(),
340 curl_easy_setopt(curl, CURLOPT_URL,uri.c_str());
341 curl_easy_setopt(curl,CURLOPT_FILE,(
void*)file);
342 curl_easy_setopt(curl,CURLOPT_TIMEOUT,60);
343 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
344 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
349 curl_easy_setopt(curl,CURLOPT_PROXYUSERPWD,tmp.c_str());
351 res = curl_easy_perform(curl);
353 curl_easy_cleanup(curl);
361 std::ofstream ofs(filename.c_str());
365 if(w3.Connect(uri.c_str())){
366 if(w3.Request(w3.GetURI())){
367 unsigned char buf[1024]=
"\0";
368 while((nread=w3.Response(buf, 1023))){
408 std::string::size_type p;
409 p = uri.find(
"file:");
410 if ( p !=std::string::npos)
418 ifs.open(filename.c_str(),std::ios::in);
436 std::cerr<<field<<
": ";
441 tcgetattr(STDIN_FILENO, &term);
442 oflags = term.c_lflag;
443 term.c_lflag = oflags & ~(ECHO | ECHOK | ICANON);
444 term.c_cc[VTIME] = 1;
445 tcsetattr(STDIN_FILENO, TCSANOW, &term);
447 scanf(
"%s", password);
449 term.c_lflag = oflags;
450 term.c_cc[VTIME] = 0;
451 tcsetattr(STDIN_FILENO, TCSANOW, &term);
453 scanf(
"%s", password);
460XmlUtils::winPost(
const std::string uri,
const std::string username,
461 const std::string password,
const std::string data,
462 std::string action,
char* &results)
466 const char* d = data.c_str() ;
467 if(w3.Connect(uri.c_str())){
468 w3.InitializePostArguments();
469 w3.setContentType(
"Content-Type: text/xml; charset=UTF-8\r\n");
470 w3.setAcceptTypes(
"Accept: text/xml\r\n");
471 w3.AddPostArgument(d,data.length());
472 std::string tmp=
"SOAPAction: ";
477 w3.setSoapAction(tmp.c_str());
479 if(w3.RequestPost(w3.GetURI())){
480 unsigned long nread = 0,tot=0;
483 while((nread=w3.Response(
reinterpret_cast<unsigned char *
>(buf), 1023))){
487 results = (
char*)malloc(
sizeof(
unsigned char) * (nread+1));
490 results = (
char*) realloc(results,
sizeof(
unsigned char) * (nread + tot+1));
492 memcpy (results+tot,buf,nread);
static pthread_mutex_t url_mutex
std::map< std::string, std::string > urlCache_
static std::string g_sProxyUser
static std::string g_sProxyHost
static std::string g_sProxyPass
std::ostream & blk(std::ostream &str)
bool WSDLPULL_EXPORT getProxy()
std::string WSDLPULL_EXPORT getProxyHost()
int parseInt(std::string s, int radix=10)
std::string creUriFile(std::string)
void WSDLPULL_EXPORT setProxyPass(const std::string &sProxyPass)
bool WSDLPULL_EXPORT fetchUri(std::string uri, std::string &path)
std::string WSDLPULL_EXPORT acceptSecretKey(const std::string &field)
void WSDLPULL_EXPORT setProxy(const bool bProxy)
std::string WSDLPULL_EXPORT getProxyUser()
void WSDLPULL_EXPORT setProxyUser(const std::string &sProxyUser)
std::string WSDLPULL_EXPORT getProxyPass()
void WSDLPULL_EXPORT setProxyHost(const std::string &sProxyHost)
std::string getFileName(std::string)
std::ostream & dbsp(std::ostream &str)