void BaseHarnessHandlers::printFile(XMLURL& url) { if(XMLString::equals(url.getURLText(), dummy)) return; BinInputStream* stream=url.makeNewStream(); if(stream==NULL) { XERCES_STD_QUALIFIER cout << "File " << StrX(url.getURLText()) << " is missing" << XERCES_STD_QUALIFIER endl; return; } XERCES_STD_QUALIFIER cout << "Content of file " << StrX(url.getURLText()) << XERCES_STD_QUALIFIER endl; XMLByte buffer[256]; XMLSize_t nRead; while((nRead=stream->readBytes(buffer, 255)) >0) { buffer[nRead]=0; // sending data containing \n\r to cout generates \n\n\r, so strip any \r XMLSize_t idx=0; while(true) { int cr=XMLString::indexOf((const char*)buffer, '\r', idx); if(cr==-1) break; memmove(&buffer[cr], &buffer[cr+1], XMLString::stringLen((const char*)&buffer[cr+1])+1); idx=cr; if(buffer[idx]==0) break; } XERCES_STD_QUALIFIER cout << (const char*)buffer; } XERCES_STD_QUALIFIER cout << XERCES_STD_QUALIFIER endl; delete stream; }
BinURLInputStream::BinURLInputStream(const XMLURL& urlSource) : fBuffer(0) , fBufferSize(0) , fBufferIndex(0) , fRemoteFileSize(0) , fAnchor(0) , fBytesProcessed(0) , fMemoryManager(urlSource.getMemoryManager()) { fBuffer = (XMLByte*) fMemoryManager->allocate ( URLISBUFMAXSIZE * sizeof(XMLByte) );//new XMLByte[URLISBUFMAXSIZE]; const XMLCh* uri = urlSource.getURLText(); char* uriAsCharStar = localTranscode(uri, fMemoryManager); // // First find the size of the remote resource being asked for. // We use the ContentCounter stream provided by libWWW. // fAnchor = HTAnchor_findAddress(uriAsCharStar); HTRequest* request = HTRequest_new(); HTRequest_setOutputFormat(request, WWW_SOURCE); HTStream* counterStrm = HTContentCounter(HTBlackHole(), request, 0xFFFF); BOOL status = HTLoadToStream(uriAsCharStar, counterStrm, request); if (status == YES) { HTParentAnchor * anchor = HTRequest_anchor(request); fRemoteFileSize=HTAnchor_length(anchor); if(fRemoteFileSize < 0) { // Patch by Artur Klauser // When a redirection is processed in libWWW, it seems that // HTAnchor_length(anchor) == -1 on the original anchor, whereas // HTResponse_length(response) gives the correct content length of // the redirection target. This has confused fRemoteFileSize and it was // not checked for a -1 response at all. HTResponse * response = HTRequest_response (request); fRemoteFileSize = HTResponse_length(response); if (fRemoteFileSize < 0) { ThrowXMLwithMemMgr(NetAccessorException, XMLExcepts::NetAcc_LengthError, fMemoryManager); } } } // Cleanup, before you throw any errors. fMemoryManager->deallocate(uriAsCharStar); HTRequest_delete(request); // Don't know whether I am supposed to delete counterStrm. if (status == NO) { ThrowXMLwithMemMgr(NetAccessorException, XMLExcepts::NetAcc_LengthError, fMemoryManager); } }
XERCES_CPP_NAMESPACE_BEGIN URLAccessBinInputStream::URLAccessBinInputStream(const XMLURL& urlSource) : mBytesProcessed(0), mURLReference(NULL), mBuffer(NULL), mBufPos(NULL), mBufAvailable(0) { OSStatus status = noErr; // Get the full URL from the source char* url = XMLString::transcode(urlSource.getURLText(), urlSource.getMemoryManager()); ArrayJanitor<char> janBuf(url, urlSource.getMemoryManager()); // Create a URL reference from the URL status = URLNewReference(url, &mURLReference); // Begin the transfer if (status == noErr) status = URLOpen( mURLReference, NULL, // FSSpec* (not reading to file) 0, // URLOpenFlags NULL, // URLNotifyUPP 0, // URLEventMask 0); // userContext // If we failed, we throw switch (status) { case noErr: break; case kURLInvalidURLError: ThrowXML(MalformedURLException, XMLExcepts::URL_MalformedURL); break; case kURLUnsupportedSchemeError: ThrowXML(MalformedURLException, XMLExcepts::URL_UnsupportedProto); break; default: ThrowXML1(NetAccessorException, XMLExcepts::NetAcc_ConnSocket, urlSource.getURLText()); break; } }
bool XMLURL::operator==(const XMLURL& toCompare) const { // // Compare the two complete URLs (which have been processed the same // way so they should now be the same even if they came in via different // relative parts. // if (!XMLString::equals(getURLText(), toCompare.getURLText())) return false; return true; }
static bool checkBasicResult(const XMLURL& testURL , const BasicTestEntry& testInfo) { // // Check each part to insure that its what its supposed to be. Since // any of them can be a null pointer, we have a little helper function // that spits out the actual testing code for each one. // if (!checkAField(testURL.getURLText(), testInfo.fullText, L"Full Text")) return false; if (!checkAField(testURL.getFragment(), testInfo.fragment, L"Fragment")) return false; if (!checkAField(testURL.getHost(), testInfo.host, L"Host")) return false; if (testURL.getPortNum() != testInfo.portNum) { XERCES_STD_QUALIFIER wcout << L"Expected port number: " << testInfo.portNum << L" but got: " << testURL.getPortNum() << XERCES_STD_QUALIFIER endl; return false; } if (!checkAField(testURL.getPath(), testInfo.path, L"Path")) return false; if (!checkAField(testURL.getPassword(), testInfo.password, L"Password")) return false; if (!checkAField(testURL.getQuery(), testInfo.query, L"Query")) return false; if (!checkAField(testURL.getUser(), testInfo.user, L"User")) return false; return true; }
CurlURLInputStream::CurlURLInputStream(const XMLURL& urlSource, const XMLNetHTTPInfo* httpInfo/*=0*/) : fMulti(0) , fEasy(0) , fMemoryManager(urlSource.getMemoryManager()) , fURLSource(urlSource) , fURL(0) , fTotalBytesRead(0) , fWritePtr(0) , fBytesRead(0) , fBytesToRead(0) , fDataAvailable(false) , fBufferHeadPtr(fBuffer) , fBufferTailPtr(fBuffer) , m_log(logging::Category::getInstance(XMLTOOLING_LOGCAT".libcurl.NetAccessor")) { // Allocate the curl multi handle fMulti = curl_multi_init(); // Allocate the curl easy handle fEasy = curl_easy_init(); // Get the text of the URL we're going to use fURL.reset(XMLString::transcode(fURLSource.getURLText(), fMemoryManager), fMemoryManager); m_log.debug("libcurl trying to fetch %s", fURL.get()); // Set URL option curl_easy_setopt(fEasy, CURLOPT_URL, fURL.get()); curl_easy_setopt(fEasy, CURLOPT_WRITEDATA, this); // Pass this pointer to write function curl_easy_setopt(fEasy, CURLOPT_WRITEFUNCTION, staticWriteCallback); // Our static write function curl_easy_setopt(fEasy, CURLOPT_CONNECTTIMEOUT, 30); curl_easy_setopt(fEasy, CURLOPT_TIMEOUT, 60); curl_easy_setopt(fEasy, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); curl_easy_setopt(fEasy, CURLOPT_SSL_VERIFYHOST, 0); curl_easy_setopt(fEasy, CURLOPT_SSL_VERIFYPEER, 0); curl_easy_setopt(fEasy, CURLOPT_NOPROGRESS, 1); curl_easy_setopt(fEasy, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(fEasy, CURLOPT_FAILONERROR, 1); // Add easy handle to the multi stack curl_multi_add_handle(fMulti, fEasy); }
bool XMLURL::conglomerateWithBase(const XMLURL& baseURL, bool useExceptions) { // The base URL cannot be relative if (baseURL.isRelative()) { if (useExceptions) ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_RelativeBaseURL, fMemoryManager); else return false; } // // Check a special case. If all we have is a fragment, then we want // to just take the base host and path, plus our fragment. // if ((fProtocol == Unknown) && !fHost && !fPath && fFragment) { // Just in case, make sure we don't leak the user or password values fMemoryManager->deallocate(fUser);//delete [] fUser; fUser = 0; fMemoryManager->deallocate(fPassword);//delete [] fPassword; fPassword = 0; // Copy over the protocol and port number as is fProtocol = baseURL.fProtocol; fPortNum = baseURL.fPortNum; // Replicate the base fields that are provided fHost = XMLString::replicate(baseURL.fHost, fMemoryManager); fUser = XMLString::replicate(baseURL.fUser, fMemoryManager); fPassword = XMLString::replicate(baseURL.fPassword, fMemoryManager); fPath = XMLString::replicate(baseURL.fPath, fMemoryManager); return true; } // // All we have to do is run up through our fields and, for each one // that we don't have, use the based URL's. Once we hit one field // that we have, we stop. // if (fProtocol != Unknown) return true; fProtocol = baseURL.fProtocol; // // If the protocol is not file, and we either already have our own // host, or the base does not have one, then we are done. // if (fProtocol != File) { if (fHost || !baseURL.fHost) return true; } // Replicate all of the hosty stuff if the base has one if (baseURL.fHost) { // Just in case, make sure we don't leak a user or password field fMemoryManager->deallocate(fUser);//delete [] fUser; fUser = 0; fMemoryManager->deallocate(fPassword);//delete [] fPassword; fPassword = 0; fMemoryManager->deallocate(fHost);//delete [] fHost; fHost = 0; fHost = XMLString::replicate(baseURL.fHost, fMemoryManager); fUser = XMLString::replicate(baseURL.fUser, fMemoryManager); fPassword = XMLString::replicate(baseURL.fPassword, fMemoryManager); fPortNum = baseURL.fPortNum; } // If we have a path and its absolute, then we are done const bool hadPath = (fPath != 0); if (hadPath) { if (*fPath == chForwardSlash) return true; } // Its a relative path, so weave them together. if (baseURL.fPath) { XMLCh* temp = XMLPlatformUtils::weavePaths(baseURL.fPath, fPath ,fMemoryManager); fMemoryManager->deallocate(fPath);//delete [] fPath; fPath = temp; } // If we had any original path, then we are done if (hadPath) return true; // We had no original path, so go on to deal with the query/fragment parts if (fQuery || !baseURL.fQuery) return true; fQuery = XMLString::replicate(baseURL.fQuery, fMemoryManager); if (fFragment || !baseURL.fFragment) return true; fFragment = XMLString::replicate(baseURL.fFragment, fMemoryManager); return true; }
static bool basicURLTest() { static BasicTestEntry testList[] = { { L"file://*****:*****@host/path1/path2/file.txt?query#fragment" , L"file://*****:*****@host/path1/path2/file.txt?query#fragment" , XMLURL::File , 0 , L"fragment" , L"host" , L"/path1/path2/file.txt" , L"password" , L"query" , L"user" } , { L"file:///path2/file.txt?query#fragment" , L"file:///path2/file.txt?query#fragment" , XMLURL::File , 0 , L"fragment" , 0 , L"/path2/file.txt" , 0 , L"query" , 0 } , { L"#fragment" , L"#fragment" , XMLURL::Unknown , 0 , L"fragment" , 0 , 0 , 0 , 0 , 0 } , { L"file://user@host/path1/path2/file.txt#fragment" , L"file://user@host/path1/path2/file.txt#fragment" , XMLURL::File , 0 , L"fragment" , L"host" , L"/path1/path2/file.txt" , 0 , 0 , L"user" } , { L" file://user@host/path1/path2/file.txt#fragment" , L"file://user@host/path1/path2/file.txt#fragment" , XMLURL::File , 0 , L"fragment" , L"host" , L"/path1/path2/file.txt" , 0 , 0 , L"user" } , { L"http://*****:*****@" , L"ftp://user@" , XMLURL::FTP , 21 , 0 , 0 , 0 , 0 , 0 , L"user" } }; const unsigned int testCount = sizeof(testList) / sizeof(testList[0]); bool retVal = true; // // Do a run where we construct the URL over and over for each // test. // unsigned int index; for (index = 0; index < testCount; index++) { // Force full destruction each time { XMLURL testURL(testList[index].orgURL); // Call the comparison function if (!checkBasicResult(testURL, testList[index])) retVal = false; } } // // Do a run where we use a single URL object and just reset it over // and over again. // XMLURL testURL; for (index = 0; index < testCount; index++) { testURL.setURL(testList[index].orgURL); // Call the comparison function if (!checkBasicResult(testURL, testList[index])) retVal = false; } return retVal; }
BinHTTPURLInputStream::BinHTTPURLInputStream(const XMLURL& urlSource, const XMLNetHTTPInfo* httpInfo /*=0*/) : fSocketHandle(0) , fBytesProcessed(0) { if(!fInitialized) { if (!fInitMutex) { XMLMutex* tmpMutex = new XMLMutex(); if (XMLPlatformUtils::compareAndSwap((void**)&fInitMutex, tmpMutex, 0)) { // Someone beat us to it, so let's clean up ours delete tmpMutex; } } XMLMutexLock lock(fInitMutex); if (!fInitialized) { Initialize(urlSource.getMemoryManager()); } } fMemoryManager = urlSource.getMemoryManager(); // // Pull all of the parts of the URL out of th urlSource object, and transcode them // and transcode them back to ASCII. // const XMLCh* hostName = urlSource.getHost(); char* hostNameAsCharStar = XMLString::transcode(hostName, urlSource.getMemoryManager()); ArrayJanitor<char> janBuf1(hostNameAsCharStar, urlSource.getMemoryManager()); const XMLCh* path = urlSource.getPath(); char* pathAsCharStar = XMLString::transcode(path, urlSource.getMemoryManager()); ArrayJanitor<char> janBuf2(pathAsCharStar, urlSource.getMemoryManager()); const XMLCh* fragment = urlSource.getFragment(); char* fragmentAsCharStar = 0; if (fragment) fragmentAsCharStar = XMLString::transcode(fragment, urlSource.getMemoryManager()); ArrayJanitor<char> janBuf3(fragmentAsCharStar, urlSource.getMemoryManager()); const XMLCh* query = urlSource.getQuery(); char* queryAsCharStar = 0; if (query) queryAsCharStar = XMLString::transcode(query, urlSource.getMemoryManager()); ArrayJanitor<char> janBuf4(queryAsCharStar, urlSource.getMemoryManager()); unsigned short portNumber = (unsigned short) urlSource.getPortNum(); // // Set up a socket. // struct hostent* hostEntPtr = 0; struct sockaddr_in sa; if ((hostEntPtr = gethostbyname(hostNameAsCharStar)) == NULL) { unsigned long numAddress = inet_addr(hostNameAsCharStar); if (numAddress == INADDR_NONE) { // Call WSAGetLastError() to get the error number. ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_TargetResolution, hostName, fMemoryManager); } if ((hostEntPtr = gethostbyaddr((const char *) &numAddress, sizeof(unsigned long), AF_INET)) == NULL) { // Call WSAGetLastError() to get the error number. ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_TargetResolution, hostName, fMemoryManager); } } memcpy((void *) &sa.sin_addr, (const void *) hostEntPtr->h_addr, hostEntPtr->h_length); sa.sin_family = hostEntPtr->h_addrtype; sa.sin_port = htons(portNumber); SOCKET s = socket(hostEntPtr->h_addrtype, SOCK_STREAM, 0); if (s == INVALID_SOCKET) { // Call WSAGetLastError() to get the error number. ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_CreateSocket, urlSource.getURLText(), fMemoryManager); } if (connect(s, (struct sockaddr *) &sa, sizeof(sa)) == SOCKET_ERROR) { // Call WSAGetLastError() to get the error number. ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ConnSocket, urlSource.getURLText(), fMemoryManager); } // Set a flag so we know that the headers have not been read yet. bool fHeaderRead = false; // The port is open and ready to go. // Build up the http GET command to send to the server. // To do: We should really support http 1.1. This implementation // is weak. memset(fBuffer, 0, sizeof(fBuffer)); if(httpInfo==0) strcpy(fBuffer, "GET "); else { switch(httpInfo->fHTTPMethod) { case XMLNetHTTPInfo::GET: strcpy(fBuffer, "GET "); break; case XMLNetHTTPInfo::PUT: strcpy(fBuffer, "PUT "); break; case XMLNetHTTPInfo::POST: strcpy(fBuffer, "POST "); break; } } strcat(fBuffer, pathAsCharStar); if (queryAsCharStar != 0) { // Tack on a ? before the fragment strcat(fBuffer,"?"); strcat(fBuffer, queryAsCharStar); } if (fragmentAsCharStar != 0) { strcat(fBuffer, fragmentAsCharStar); } strcat(fBuffer, " HTTP/1.0\r\n"); strcat(fBuffer, "Host: "); strcat(fBuffer, hostNameAsCharStar); if (portNumber != 80) { strcat(fBuffer, ":"); int i = strlen(fBuffer); _itoa(portNumber, fBuffer+i, 10); } strcat(fBuffer, "\r\n"); if(httpInfo!=0 && httpInfo->fHeaders!=0) strncat(fBuffer,httpInfo->fHeaders,httpInfo->fHeadersLen); strcat(fBuffer, "\r\n"); // Send the http request int lent = strlen(fBuffer); int aLent = 0; if ((aLent = send(s, fBuffer, lent, 0)) != lent) { // Call WSAGetLastError() to get the error number. ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_WriteSocket, urlSource.getURLText(), fMemoryManager); } if(httpInfo!=0 && httpInfo->fPayload!=0) { int aLent = 0; if ((aLent = send(s, httpInfo->fPayload, httpInfo->fPayloadLen, 0)) != httpInfo->fPayloadLen) { // Call WSAGetLastError() to get the error number. ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_WriteSocket, urlSource.getURLText(), fMemoryManager); } } // // get the response, check the http header for errors from the server. // memset(fBuffer, 0, sizeof(fBuffer)); aLent = recv(s, fBuffer, sizeof(fBuffer)-1, 0); if (aLent == SOCKET_ERROR || aLent == 0) { // Call WSAGetLastError() to get the error number. ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, urlSource.getURLText(), fMemoryManager); } fBufferEnd = fBuffer+aLent; *fBufferEnd = 0; do { // Find the break between the returned http header and any data. // (Delimited by a blank line) // Hang on to any data for use by the first read from this BinHTTPURLInputStream. // fBufferPos = strstr(fBuffer, "\r\n\r\n"); if (fBufferPos != 0) { fBufferPos += 4; *(fBufferPos-2) = 0; fHeaderRead = true; } else { fBufferPos = strstr(fBuffer, "\n\n"); if (fBufferPos != 0) { fBufferPos += 2; *(fBufferPos-1) = 0; fHeaderRead = true; } else { // // Header is not yet read, do another recv() to get more data... aLent = recv(s, fBufferEnd, (sizeof(fBuffer) - 1) - (fBufferEnd - fBuffer), 0); if (aLent == SOCKET_ERROR || aLent == 0) { // Call WSAGetLastError() to get the error number. ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, urlSource.getURLText(), fMemoryManager); } fBufferEnd = fBufferEnd + aLent; *fBufferEnd = 0; } } } while(fHeaderRead == false); // Make sure the header includes an HTTP 200 OK response. // char *p = strstr(fBuffer, "HTTP"); if (p == 0) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, urlSource.getURLText(), fMemoryManager); } p = strchr(p, ' '); if (p == 0) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, urlSource.getURLText(), fMemoryManager); } int httpResponse = atoi(p); if (httpResponse != 200) { // Most likely a 404 Not Found error. // Should recognize and handle the forwarding responses. // ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::File_CouldNotOpenFile, urlSource.getURLText(), fMemoryManager); } fSocketHandle = (unsigned int) s; }
int BinHTTPInputStreamCommon::sendRequest(const XMLURL &url, const XMLNetHTTPInfo *httpInfo) { // // Constants in ASCII to send/check in the HTTP request/response // static const char *CRLF2X = "\r\n\r\n"; static const char *LF2X = "\n\n"; // The port is open and ready to go. // Build up the http GET command to send to the server. CharBuffer requestBuffer(1023, fMemoryManager); createHTTPRequest(url, httpInfo, requestBuffer); // Send the http request if(!send(requestBuffer.getRawBuffer(), requestBuffer.getLen())) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_WriteSocket, url.getURLText(), fMemoryManager); } if(httpInfo && httpInfo->fPayload) { if(!send(httpInfo->fPayload, httpInfo->fPayloadLen)) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_WriteSocket, url.getURLText(), fMemoryManager); } } // // get the response, check the http header for errors from the server. // char tmpBuf[1024]; int ret; fBuffer.reset(); while(true) { ret = receive(tmpBuf, sizeof(tmpBuf)); if(ret == -1) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, url.getURLText(), fMemoryManager); } fBuffer.append(tmpBuf, ret); fBufferPos = strstr(fBuffer.getRawBuffer(), CRLF2X); if(fBufferPos != 0) { fBufferPos += 4; *(fBufferPos - 2) = 0; break; } fBufferPos = strstr(fBuffer.getRawBuffer(), LF2X); if(fBufferPos != 0) { fBufferPos += 2; *(fBufferPos - 1) = 0; break; } } // Parse the response status char *p = strstr(fBuffer.getRawBuffer(), "HTTP"); if(p == 0) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, url.getURLText(), fMemoryManager); } p = strchr(p, chSpace); if(p == 0) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, url.getURLText(), fMemoryManager); } return atoi(p); }
void BinHTTPInputStreamCommon::createHTTPRequest(const XMLURL &urlSource, const XMLNetHTTPInfo *httpInfo, CharBuffer &buffer) { static const char *GET = "GET "; static const char *PUT = "PUT "; static const char *POST = "POST "; static const char *HTTP10 = " HTTP/1.0\r\n"; static const char *HOST = "Host: "; static const char *AUTHORIZATION = "Authorization: Basic "; static const char *COLON = ":"; XMLTransService::Codes failReason; const XMLSize_t blockSize = 2048; XMLTranscoder* trans = XMLPlatformUtils::fgTransService->makeNewTranscoderFor("ISO8859-1", failReason, blockSize, fMemoryManager); Janitor<XMLTranscoder> janTrans(trans); TranscodeToStr hostName(urlSource.getHost(), trans, fMemoryManager); TranscodeToStr path(urlSource.getPath(), trans, fMemoryManager); TranscodeToStr fragment(urlSource.getFragment(), trans, fMemoryManager); TranscodeToStr query(urlSource.getQuery(), trans, fMemoryManager); // Build up the http GET command to send to the server. // To do: We should really support http 1.1. This implementation // is weak. if(httpInfo) { switch(httpInfo->fHTTPMethod) { case XMLNetHTTPInfo::GET: buffer.append(GET); break; case XMLNetHTTPInfo::PUT: buffer.append(PUT); break; case XMLNetHTTPInfo::POST: buffer.append(POST); break; } } else { buffer.append(GET); } if(path.str() != 0) { buffer.append((char*)path.str()); } else { buffer.append("/"); } if(query.str() != 0) { buffer.append("?"); buffer.append((char*)query.str()); } if(fragment.str() != 0) { buffer.append((char*)fragment.str()); } buffer.append(HTTP10); buffer.append(HOST); buffer.append((char*)hostName.str()); if(urlSource.getPortNum() != 80) { buffer.append(COLON); buffer.appendDecimalNumber(urlSource.getPortNum()); } buffer.append(CRLF); const XMLCh *username = urlSource.getUser(); const XMLCh *password = urlSource.getPassword(); if(username && password) { XMLBuffer userPassBuf(256, fMemoryManager); userPassBuf.append(username); userPassBuf.append(chColon); userPassBuf.append(password); TranscodeToStr userPass(userPassBuf.getRawBuffer(), trans, fMemoryManager); XMLSize_t len; XMLByte* encodedData = Base64::encode(userPass.str(), userPass.length(), &len, fMemoryManager); ArrayJanitor<XMLByte> janBuf2(encodedData, fMemoryManager); if(encodedData) { // HTTP doesn't want the 0x0A separating the data in chunks of 76 chars per line XMLByte* authData = (XMLByte*)fMemoryManager->allocate((len+1)*sizeof(XMLByte)); ArrayJanitor<XMLByte> janBuf(authData, fMemoryManager); XMLByte *cursor = authData; for(XMLSize_t i = 0; i < len; ++i) if(encodedData[i] != chLF) *cursor++ = encodedData[i]; *cursor++ = 0; buffer.append(AUTHORIZATION); buffer.append((char*)authData); buffer.append(CRLF); } } if(httpInfo && httpInfo->fHeaders) buffer.append(httpInfo->fHeaders, httpInfo->fHeadersLen); buffer.append(CRLF); }
Sequence FunctionUnparsedText::createSequence(DynamicContext* context, int flags) const { Item::Ptr uriArg = getParamNumber(1, context)->next(context); if(uriArg.isNull()) { return Sequence(context->getMemoryManager()); } const XMLCh *uri = uriArg->asString(context); if(!XPath2Utils::isValidURI(uri, context->getMemoryManager())) XQThrow(FunctionException, X("FunctionUnparsedText::createSequence"), X("The argument to fn:unparsed-text() is not a valid URI [err:XTDE1170]")); // TBD Implement a URIResolver method for resolving unparsed text - jpcs const XMLCh *baseUri = context->getBaseURI(); InputSource *srcToUse = 0; if(context->getXMLEntityResolver()){ XMLResourceIdentifier resourceIdentifier(XMLResourceIdentifier::UnKnown, uri, 0, XMLUni::fgZeroLenString, baseUri); srcToUse = context->getXMLEntityResolver()->resolveEntity(&resourceIdentifier); } if(srcToUse == 0) { try { // Resolve the uri against the base uri XMLURL urlTmp; if(baseUri && *baseUri) { urlTmp.setURL(baseUri, uri); } else { urlTmp.setURL(uri); } srcToUse = new URLInputSource(urlTmp); } catch(const MalformedURLException &e) { } } if(srcToUse == 0) { // It's not a URL, so let's assume it's a local file name. if(baseUri && *baseUri) { AutoDeallocate<XMLCh> tmpBuf(XMLPlatformUtils::weavePaths(baseUri, uri), XMLPlatformUtils::fgMemoryManager); srcToUse = new LocalFileInputSource(tmpBuf); } else { srcToUse = new LocalFileInputSource(uri); } } Janitor<InputSource> janIS(srcToUse); if(getNumArgs() == 2) { const XMLCh *encoding = getParamNumber(2, context)->next(context)->asString(context); srcToUse->setEncoding(encoding); } XMLBuffer result; try { BinInputStream *stream = srcToUse->makeStream(); if(stream == NULL) { XMLBuffer buf; buf.set(X("Cannot read unparsed content from ")); buf.append(uri); buf.append(X(" [err:XTDE1170]")); XQThrow2(FunctionException,X("FunctionUnparsedText::createSequence"), buf.getRawBuffer()); } Janitor<BinInputStream> janStream(stream); #ifdef HAVE_GETCONTENTTYPE if(FunctionMatches::matches(stream->getContentType(), X("(text|application)/(xml|[^ +;]+\\+xml)"), X("i"))) { srcToUse->setEncoding(0); srcToUse->setEncoding(FindXMLEncoding().start(*srcToUse, context)); } #endif XPath2Utils::readSource(stream, context->getMemoryManager(), result, srcToUse->getEncoding()); } catch(XMLException &e) { XMLBuffer buf; buf.set(X("Exception reading unparsed content: ")); buf.append(e.getMessage()); buf.append(X(" [err:XTDE1190]")); XQThrow2(FunctionException,X("FunctionUnparsedText::createSequence"), buf.getRawBuffer()); } return Sequence(context->getItemFactory()->createString(result.getRawBuffer(), context), context->getMemoryManager()); }
XERCES_CPP_NAMESPACE_BEGIN URLAccessCFBinInputStream::URLAccessCFBinInputStream(const XMLURL& urlSource) : mBytesProcessed(0), mDataRef(NULL) { // Figure out what we're dealing with const XMLCh* urlText = urlSource.getURLText(); unsigned int urlLength = XMLString::stringLen(urlText); // Create a CFString from the path CFStringRef stringRef = NULL; if (urlText) { stringRef = CFStringCreateWithCharacters( kCFAllocatorDefault, urlText, urlLength ); } // Create a URLRef from the CFString CFURLRef urlRef = NULL; if (stringRef) { urlRef = CFURLCreateWithString( kCFAllocatorDefault, stringRef, NULL // CFURLRef baseURL ); } // Fetch the data mDataRef = NULL; SInt32 errorCode = 0; Boolean success = false; if (stringRef) { success = CFURLCreateDataAndPropertiesFromResource( kCFAllocatorDefault, urlRef, &mDataRef, NULL, // CFDictionaryRef *properties, NULL, // CFArrayRef desiredProperties, &errorCode ); } // Cleanup temporary stuff if (stringRef) CFRelease(stringRef); if (urlRef) CFRelease(urlRef); // Check for an error in fetching the data if (!success || errorCode) { // Dispose any potential dataRef if (mDataRef) { CFRelease(mDataRef); mDataRef = NULL; } // Do a best attempt at mapping some errors switch (errorCode) { case kCFURLUnknownSchemeError: ThrowXML(MalformedURLException, XMLExcepts::URL_UnsupportedProto); break; case kCFURLRemoteHostUnavailableError: ThrowXML1(NetAccessorException, XMLExcepts::NetAcc_TargetResolution, urlSource.getHost()); break; case kCFURLUnknownError: ThrowXML1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, urlText); break; case kCFURLResourceNotFoundError: case kCFURLResourceAccessViolationError: case kCFURLTimeoutError: ThrowXML1(NetAccessorException, XMLExcepts::File_CouldNotOpenFile, urlText); break; case kCFURLImproperArgumentsError: case kCFURLUnknownPropertyKeyError: case kCFURLPropertyKeyUnavailableError: default: ThrowXML1(NetAccessorException, XMLExcepts::NetAcc_InternalError, urlText); break; } } }
XERCES_CPP_NAMESPACE_BEGIN CurlURLInputStream::CurlURLInputStream(const XMLURL& urlSource, const XMLNetHTTPInfo* httpInfo/*=0*/) : fMulti(0) , fEasy(0) , fMemoryManager(urlSource.getMemoryManager()) , fURLSource(urlSource) , fTotalBytesRead(0) , fWritePtr(0) , fBytesRead(0) , fBytesToRead(0) , fDataAvailable(false) , fBufferHeadPtr(fBuffer) , fBufferTailPtr(fBuffer) , fPayload(0) , fPayloadLen(0) , fContentType(0) { // Allocate the curl multi handle fMulti = curl_multi_init(); // Allocate the curl easy handle fEasy = curl_easy_init(); // Set URL option TranscodeToStr url(fURLSource.getURLText(), "ISO8859-1", fMemoryManager); curl_easy_setopt(fEasy, CURLOPT_URL, (char*)url.str()); // Set up a way to recieve the data curl_easy_setopt(fEasy, CURLOPT_WRITEDATA, this); // Pass this pointer to write function curl_easy_setopt(fEasy, CURLOPT_WRITEFUNCTION, staticWriteCallback); // Our static write function // Do redirects curl_easy_setopt(fEasy, CURLOPT_FOLLOWLOCATION, (long)1); curl_easy_setopt(fEasy, CURLOPT_MAXREDIRS, (long)6); // Add username and password if authentication is required const XMLCh *username = urlSource.getUser(); const XMLCh *password = urlSource.getPassword(); if(username && password) { XMLBuffer userPassBuf(256, fMemoryManager); userPassBuf.append(username); userPassBuf.append(chColon); userPassBuf.append(password); TranscodeToStr userPass(userPassBuf.getRawBuffer(), "ISO8859-1", fMemoryManager); curl_easy_setopt(fEasy, CURLOPT_HTTPAUTH, (long)CURLAUTH_ANY); curl_easy_setopt(fEasy, CURLOPT_USERPWD, (char*)userPass.str()); } if(httpInfo) { // Set the correct HTTP method switch(httpInfo->fHTTPMethod) { case XMLNetHTTPInfo::GET: break; case XMLNetHTTPInfo::PUT: curl_easy_setopt(fEasy, CURLOPT_UPLOAD, (long)1); break; case XMLNetHTTPInfo::POST: curl_easy_setopt(fEasy, CURLOPT_POST, (long)1); break; } // Add custom headers if(httpInfo->fHeaders) { struct curl_slist *headersList = 0; const char *headersBuf = httpInfo->fHeaders; const char *headersBufEnd = httpInfo->fHeaders + httpInfo->fHeadersLen; const char *headerStart = headersBuf; while(headersBuf < headersBufEnd) { if(*headersBuf == '\r' && (headersBuf + 1) < headersBufEnd && *(headersBuf + 1) == '\n') { XMLSize_t length = headersBuf - headerStart; ArrayJanitor<char> header((char*)fMemoryManager->allocate((length + 1) * sizeof(char)), fMemoryManager); memcpy(header.get(), headerStart, length); header.get()[length] = 0; headersList = curl_slist_append(headersList, header.get()); headersBuf += 2; headerStart = headersBuf; continue; } ++headersBuf; } curl_easy_setopt(fEasy, CURLOPT_HTTPHEADER, headersList); curl_slist_free_all(headersList); } // Set up the payload if(httpInfo->fPayload) { fPayload = httpInfo->fPayload; fPayloadLen = httpInfo->fPayloadLen; curl_easy_setopt(fEasy, CURLOPT_READDATA, this); curl_easy_setopt(fEasy, CURLOPT_READFUNCTION, staticReadCallback); curl_easy_setopt(fEasy, CURLOPT_INFILESIZE_LARGE, (curl_off_t)fPayloadLen); } } // Add easy handle to the multi stack curl_multi_add_handle(fMulti, fEasy); // Start reading, to get the content type while(fBufferHeadPtr == fBuffer) { int runningHandles = 0; readMore(&runningHandles); if(runningHandles == 0) break; } // Find the content type char *contentType8 = 0; curl_easy_getinfo(fEasy, CURLINFO_CONTENT_TYPE, &contentType8); if(contentType8) fContentType = TranscodeFromStr((XMLByte*)contentType8, XMLString::stringLen(contentType8), "ISO8859-1", fMemoryManager).adopt(); }
UnixHTTPURLInputStream::UnixHTTPURLInputStream(const XMLURL& urlSource, const XMLNetHTTPInfo* httpInfo/*=0*/) : BinHTTPInputStreamCommon(urlSource.getMemoryManager()), fSocket(0) { // // Convert the hostName to the platform's code page for gethostbyname and // inet_addr functions. // MemoryManager *memoryManager = urlSource.getMemoryManager(); const XMLCh* hostName = urlSource.getHost(); if (hostName == 0) ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::File_CouldNotOpenFile, urlSource.getURLText(), memoryManager); char* hostNameAsCharStar = XMLString::transcode(hostName, memoryManager); ArrayJanitor<char> janHostNameAsCharStar(hostNameAsCharStar, memoryManager); XMLURL url(urlSource); int redirectCount = 0; SocketJanitor janSock(0); do { // // Set up a socket. // #if HAVE_GETADDRINFO struct addrinfo hints, *res, *ai; CharBuffer portBuffer(10, memoryManager); portBuffer.appendDecimalNumber(url.getPortNum()); memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; int n = getaddrinfo(hostNameAsCharStar,portBuffer.getRawBuffer(),&hints, &res); if(n != 0) { hints.ai_flags = AI_NUMERICHOST; n = getaddrinfo(hostNameAsCharStar,portBuffer.getRawBuffer(),&hints, &res); if(n != 0) ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_TargetResolution, hostName, memoryManager); } janSock.reset(); for (ai = res; ai != NULL; ai = ai->ai_next) { // Open a socket with the correct address family for this address. fSocket = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); if (fSocket < 0) continue; janSock.reset(&fSocket); if (connect(fSocket, ai->ai_addr, ai->ai_addrlen) < 0) { freeaddrinfo(res); ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ConnSocket, url.getURLText(), memoryManager); } break; } freeaddrinfo(res); if (fSocket < 0) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_CreateSocket, url.getURLText(), memoryManager); } #else struct hostent *hostEntPtr = 0; struct sockaddr_in sa; // Use the hostName in the local code page .... if((hostEntPtr = gethostbyname(hostNameAsCharStar)) == NULL) { unsigned long numAddress = inet_addr(hostNameAsCharStar); if ((hostEntPtr = gethostbyaddr((char *) &numAddress, sizeof(unsigned long), AF_INET)) == NULL) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_TargetResolution, hostName, memoryManager); } } memset(&sa, '\0', sizeof(sockaddr_in)); // iSeries fix ?? memcpy((void *) &sa.sin_addr, (const void *) hostEntPtr->h_addr, hostEntPtr->h_length); sa.sin_family = hostEntPtr->h_addrtype; sa.sin_port = htons((unsigned short)url.getPortNum()); janSock.reset(); fSocket = socket(hostEntPtr->h_addrtype, SOCK_STREAM, 0); if(fSocket < 0) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_CreateSocket, url.getURLText(), memoryManager); } janSock.reset(&fSocket); if(connect(fSocket, (struct sockaddr *) &sa, sizeof(sa)) < 0) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ConnSocket, url.getURLText(), memoryManager); } #endif int status = sendRequest(url, httpInfo); if(status == 200) { // HTTP 200 OK response means we're done. break; } // a 3xx response means there was an HTTP redirect else if(status >= 300 && status <= 307) { redirectCount++; XMLCh *newURLString = findHeader("Location"); ArrayJanitor<XMLCh> janNewURLString(newURLString, memoryManager); if(newURLString == 0 || *newURLString == 0) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::File_CouldNotOpenFile, url.getURLText(), memoryManager); } XMLURL newURL(memoryManager); newURL.setURL(url, newURLString); if(newURL.getProtocol() != XMLURL::HTTP) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::File_CouldNotOpenFile, newURL.getURLText(), memoryManager); } url = newURL; hostName = newURL.getHost(); if (hostName == 0) ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::File_CouldNotOpenFile, newURL.getURLText(), memoryManager); janHostNameAsCharStar.release(); hostNameAsCharStar = XMLString::transcode(hostName, memoryManager); janHostNameAsCharStar.reset(hostNameAsCharStar, memoryManager); } else { // Most likely a 404 Not Found error. ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::File_CouldNotOpenFile, url.getURLText(), memoryManager); } } while(redirectCount < 6); janSock.release(); }
XERCES_CPP_NAMESPACE_BEGIN UnixHTTPURLInputStream::UnixHTTPURLInputStream(const XMLURL& urlSource, const XMLNetHTTPInfo* httpInfo/*=0*/) : fSocket(0) , fBytesProcessed(0) , fMemoryManager(urlSource.getMemoryManager()) { // // Constants in ASCII to send/check in the HTTP request/response // const char GET[] = { chLatin_G, chLatin_E, chLatin_T, chSpace, chNull }; const char PUT[] = { chLatin_P, chLatin_U, chLatin_T, chSpace, chNull }; const char POST[] = { chLatin_P, chLatin_O, chLatin_S, chLatin_T, chSpace, chNull }; const char HTTP[] = { chLatin_H, chLatin_T, chLatin_T, chLatin_P, chNull }; const char HTTP10[] = { chSpace, chLatin_H, chLatin_T, chLatin_T, chLatin_P, chForwardSlash, chDigit_1, chPeriod, chDigit_0, chCR, chLF, chNull }; const char CRLF[] = { chCR, chLF, chNull }; const char CRLF2X[] = { chCR, chLF, chCR, chLF, chNull }; const char LF2X[] = { chLF, chLF, chNull }; const char HOST[] = { chLatin_H, chLatin_o, chLatin_s, chLatin_t, chColon, chSpace, chNull }; const char COLON[] = { chColon, chNull }; const char resp200 [] = { chSpace, chDigit_2, chDigit_0, chDigit_0, chSpace, chNull }; unsigned int charsEaten; unsigned int transSize; XMLTransService::Codes failReason; const unsigned int blockSize = 2048; const unsigned int bufSize = 5; static XMLCh portBuffer[bufSize+1]; // // Pull all of the parts of the URL out of the urlSource object // const XMLCh* hostName = urlSource.getHost(); const XMLCh* path = urlSource.getPath(); const XMLCh* fragment = urlSource.getFragment(); const XMLCh* query = urlSource.getQuery(); // // Convert the hostName to the platform's code page for gethostbyname and // inet_addr functions. // char* hostNameAsCharStar = XMLString::transcode(hostName, fMemoryManager); ArrayJanitor<char> janBuf1(hostNameAsCharStar, fMemoryManager); // // Convert all the parts of the urlSource object to ASCII so they can be // sent to the remote host in that format // transSize = XMLString::stringLen(hostName)+1; char* hostNameAsASCII = (char*) fMemoryManager->allocate ( (transSize+1) * sizeof(char) );//new char[transSize+1]; ArrayJanitor<char> janBuf2(hostNameAsASCII, fMemoryManager); XMLTranscoder* trans = XMLPlatformUtils::fgTransService->makeNewTranscoderFor("ISO8859-1", failReason, blockSize, fMemoryManager); trans->transcodeTo(hostName, transSize, (unsigned char *) hostNameAsASCII, transSize, charsEaten, XMLTranscoder::UnRep_Throw); char* pathAsASCII = 0; ArrayJanitor<char> janBuf3(pathAsASCII, fMemoryManager); if (path) { transSize = XMLString::stringLen(path)+1; pathAsASCII = (char*) fMemoryManager->allocate ( (transSize+1) * sizeof(char) );//new char[transSize+1]; trans->transcodeTo(path, transSize, (unsigned char *) pathAsASCII, transSize, charsEaten, XMLTranscoder::UnRep_Throw); } char* fragmentAsASCII = 0; ArrayJanitor<char> janBuf4(fragmentAsASCII, fMemoryManager); if (fragment) { transSize = XMLString::stringLen(fragment)+1; fragmentAsASCII = (char*) fMemoryManager->allocate ( (transSize+1) * sizeof(char) );//new char[transSize+1]; trans->transcodeTo(fragment, transSize, (unsigned char *) fragmentAsASCII, transSize, charsEaten, XMLTranscoder::UnRep_Throw); } char* queryAsASCII = 0; ArrayJanitor<char> janBuf5(queryAsASCII, fMemoryManager); if (query) { transSize = XMLString::stringLen(query)+1; queryAsASCII = (char*) fMemoryManager->allocate ( (transSize+1) * sizeof(char) );//new char[transSize+1]; trans->transcodeTo(query, transSize, (unsigned char *) queryAsASCII, transSize, charsEaten, XMLTranscoder::UnRep_Throw); } unsigned short portNumber = (unsigned short) urlSource.getPortNum(); // // Convert port number integer to unicode so we can transcode it to ASCII // XMLString::binToText((unsigned int) portNumber, portBuffer, bufSize, 10, fMemoryManager); transSize = XMLString::stringLen(portBuffer)+1; char* portAsASCII = (char*) fMemoryManager->allocate ( (transSize+1) * sizeof(char) );//new char[transSize+1]; trans->transcodeTo(portBuffer, transSize, (unsigned char *) portAsASCII, transSize, charsEaten, XMLTranscoder::UnRep_Throw); delete trans; // // Set up a socket. // struct hostent* hostEntPtr = 0; struct sockaddr_in sa; // Use the hostName in the local code page .... if ((hostEntPtr = gethostbyname(hostNameAsCharStar)) == NULL) { unsigned long numAddress = inet_addr(hostNameAsCharStar); if (numAddress < 0) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_TargetResolution, hostName, fMemoryManager); } if ((hostEntPtr = gethostbyaddr((char *) &numAddress, sizeof(unsigned long), AF_INET)) == NULL) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_TargetResolution, hostName, fMemoryManager); } } memset(&sa, '\0', sizeof(sockaddr_in)); // iSeries fix ?? memcpy((void *) &sa.sin_addr, (const void *) hostEntPtr->h_addr, hostEntPtr->h_length); sa.sin_family = hostEntPtr->h_addrtype; sa.sin_port = htons(portNumber); int s = socket(hostEntPtr->h_addrtype, SOCK_STREAM, 0); if (s < 0) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_CreateSocket, urlSource.getURLText(), fMemoryManager); } if (connect(s, (struct sockaddr *) &sa, sizeof(sa)) < 0) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ConnSocket, urlSource.getURLText(), fMemoryManager); } // The port is open and ready to go. // Build up the http GET command to send to the server. // To do: We should really support http 1.1. This implementation // is weak. if(httpInfo==0) strcpy(fBuffer, GET); else switch(httpInfo->fHTTPMethod) { case XMLNetHTTPInfo::GET: strcpy(fBuffer, GET); break; case XMLNetHTTPInfo::PUT: strcpy(fBuffer, PUT); break; case XMLNetHTTPInfo::POST: strcpy(fBuffer, POST); break; } if (pathAsASCII != 0) { strcat(fBuffer, pathAsASCII); } if (queryAsASCII != 0) { size_t n = strlen(fBuffer); fBuffer[n] = chQuestion; fBuffer[n+1] = chNull; strcat(fBuffer, queryAsASCII); } if (fragmentAsASCII != 0) { strcat(fBuffer, fragmentAsASCII); } strcat(fBuffer, HTTP10); strcat(fBuffer, HOST); strcat(fBuffer, hostNameAsASCII); if (portNumber != 80) { strcat(fBuffer,COLON); strcat(fBuffer,portAsASCII); } strcat(fBuffer, CRLF); if(httpInfo!=0 && httpInfo->fHeaders!=0) strncat(fBuffer,httpInfo->fHeaders,httpInfo->fHeadersLen); strcat(fBuffer, CRLF); // Send the http request int lent = strlen(fBuffer); int aLent = 0; if ((aLent = write(s, (void *) fBuffer, lent)) != lent) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_WriteSocket, urlSource.getURLText(), fMemoryManager); } if(httpInfo!=0 && httpInfo->fPayload!=0) { int aLent = 0; if ((aLent = write(s, (void *) httpInfo->fPayload, httpInfo->fPayloadLen)) != httpInfo->fPayloadLen) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_WriteSocket, urlSource.getURLText(), fMemoryManager); } } // // get the response, check the http header for errors from the server. // aLent = read(s, (void *)fBuffer, sizeof(fBuffer)-1); if (aLent <= 0) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, urlSource.getURLText(), fMemoryManager); } fBufferEnd = fBuffer+aLent; *fBufferEnd = 0; // Find the break between the returned http header and any data. // (Delimited by a blank line) // Hang on to any data for use by the first read from this BinHTTPURLInputStream. // fBufferPos = strstr(fBuffer, CRLF2X); if (fBufferPos != 0) { fBufferPos += 4; *(fBufferPos-2) = 0; } else { fBufferPos = strstr(fBuffer, LF2X); if (fBufferPos != 0) { fBufferPos += 2; *(fBufferPos-1) = 0; } else fBufferPos = fBufferEnd; } // Make sure the header includes an HTTP 200 OK response. // char *p = strstr(fBuffer, HTTP); if (p == 0) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, urlSource.getURLText(), fMemoryManager); } p = strchr(p, chSpace); if (p == 0) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, urlSource.getURLText(), fMemoryManager); } if (memcmp(p, resp200, strlen(resp200))) { // Most likely a 404 Not Found error. // Should recognize and handle the forwarding responses. // ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::File_CouldNotOpenFile, urlSource.getURLText(), fMemoryManager); } fSocket = s; }