/* HTMIME_anchor2response * Copies the anchor HTTP headers into a response object by means * of the generic _dispatchParsers function. Written so that we can * copy the HTTP headers stored in the cache to the response object. */ PRIVATE void HTMIME_anchor2response (HTRequest * req) { char * token; char * value; HTAssocList * header; HTAssoc * pres; HTResponse * res; HTParentAnchor * anchor; if (!req) return; anchor = HTRequest_anchor (req); header = HTAnchor_header (anchor); if (!anchor || !header) return; while ((pres = (HTAssoc *) HTAssocList_nextObject (header))) { token = HTAssoc_name (pres); value = HTAssoc_value (pres); _dispatchParsers (req, token, value); } /* ** Notify the response object not to delete the lists that we ** have inherited from the anchor object */ res = HTRequest_response (req); HTResponse_isCached (res, YES); }
PUBLIC HTStream * HTBoundary (HTRequest * request, void * param, HTFormat input_format, HTFormat output_format, HTStream * output_stream) { HTResponse * response = HTRequest_response(request); HTParentAnchor * anchor = HTRequest_anchor(request); HTAssocList * type_param = response ? HTResponse_formatParam(response) : HTAnchor_formatParam(anchor); char * boundary = HTAssocList_findObject(type_param, "boundary"); if (boundary) { HTStream * me; if ((me = (HTStream *) HT_CALLOC(1, sizeof(HTStream))) == NULL) HT_OUTOFMEM("HTBoundary"); me->isa = &HTBoundaryClass; me->request = request; me->format = output_format; me->orig_target = output_stream; me->debug = HTRequest_debugStream(request); me->state = EOL_FLF; StrAllocCopy(me->boundary, boundary); /* Local copy */ me->bpos = me->boundary; HTTRACE(STREAM_TRACE, "Boundary.... Stream created with boundary '%s\'\n" _ me->boundary); return me; } else { HTTRACE(STREAM_TRACE, "Boundary.... UNKNOWN boundary!\n"); return HTErrorStream(); } }
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); } }
PUBLIC HTStream * HTGuess_new (HTRequest * request, void * param, HTFormat input_format, HTFormat output_format, HTStream * output_stream) { HTStream * me; if ((me = (HTStream *) HT_CALLOC(1,sizeof(HTStream))) == NULL) HT_OUTOFMEM("HTGuess_new"); me->isa = &HTGuessClass; me->request = request; me->response = HTRequest_response(request); me->output_format = output_format; me->output_stream = output_stream; me->write_ptr = me->buffer; return me; }
/* ** Search registered parsers to find suitable one for this token ** If a parser isn't found, the function returns HT_OK */ PUBLIC int HTMIMEParseSet_dispatch (HTMIMEParseSet * me, HTRequest * request, char * token, char * value, BOOL * pFound) { int hash; HTResponse * response = HTRequest_response(request); HTMIMEParseEl * pEl; if (pFound) *pFound = NO; /* ** Get a hash value for this token. This has is a function of the hash ** size given when the MIME header parse set was created. */ hash = HTMIMEParseSet_hash(me, token); /* ** Search for an exact match */ for (pEl = me->parsers[hash]; pEl; pEl = pEl->next) { if ((pEl->caseSensitive && !strcmp(pEl->token, token)) || (!pEl->caseSensitive && !strcasecomp(pEl->token, token))) { if (pFound) *pFound = YES; if (!pEl->pFunk) return HT_OK; /* registered with no callback*/ return (*pEl->pFunk)(request, response, token, value); } } /* ** Search for best match using regular expressions. */ for (pEl = me->regexParsers; pEl; pEl = pEl->next) { if ((pEl->caseSensitive && HTStrMatch(pEl->token, token)) || (!pEl->caseSensitive && HTStrCaseMatch(pEl->token, token))) { if (pFound) *pFound = YES; if (!pEl->pFunk) return HT_OK; /* registered with no callback*/ return (*pEl->pFunk)(request, response, token, value); } } return HT_OK; }
/* MIME header parser stream. ** ------------------------- ** This stream parses a complete MIME header and if a content type header ** is found then the stream stack is called. Any left over data is pumped ** right through the stream */ PUBLIC HTStream* HTMIMEConvert (HTRequest * request, void * param, HTFormat input_format, HTFormat output_format, HTStream * output_stream) { HTStream * me; if ((me = (HTStream *) HT_CALLOC(1, sizeof(* me))) == NULL) HT_OUTOFMEM("HTMIMEConvert"); me->isa = &HTMIME; me->request = request; me->response = HTRequest_response(request); me->net = HTRequest_net(request); me->target = output_stream; me->target_format = output_format; me->save_stream = LocalSaveStream ? LocalSaveStream : HTBlackHoleConverter; me->token = HTChunk_new(256); me->value = HTChunk_new(256); me->hash = 0; me->EOLstate = EOL_BEGIN; me->haveToken = NO; return me; }