?? htformat.c
字號(hào):
HTCharsets = list;}PUBLIC HTList * HTFormat_charset (void){ return HTCharsets;}/*** Convenience function to clean up*/PUBLIC void HTFormat_deleteAll (void){ if (HTConversions) { HTConversion_deleteAll(HTConversions); HTConversions = NULL; } if (HTLanguages) { HTLanguage_deleteAll(HTLanguages); HTLanguages = NULL; } if (HTContentCoders) { HTCoding_deleteAll(HTContentCoders); HTContentCoders = NULL; } if (HTTransferCoders) { HTCoding_deleteAll(HTTransferCoders); HTTransferCoders = NULL; } if (HTCharsets) { HTCharset_deleteAll(HTCharsets); HTCharsets = NULL; }}/* ------------------------------------------------------------------------- *//* STREAM STACKS *//* ------------------------------------------------------------------------- */PRIVATE BOOL better_match (HTFormat f, HTFormat g){ const char *p, *q; if (f && g && (p = HTAtom_name(f)) && (q = HTAtom_name(g))) { int i,j; for(i=0 ; *p; p++) if (*p == '*') i++; for(j=0 ; *q; q++) if (*q == '*') j++; if (i < j) return YES; } return NO;}/* Create a Content Type filter stack** ----------------------------------** If a wildcard match is made, a temporary HTPresentation** structure is made to hold the destination format while the** new stack is generated. This is just to pass the out format to** MIME so far. Storing the format of a stream in the stream might** be a lot neater.**** The star/star format is special, in that if you can take** that you can take anything.*/PUBLIC HTStream * HTStreamStack (HTFormat rep_in, HTFormat rep_out, HTStream * output_stream, HTRequest * request, BOOL guess){ HTList * conversion[2]; int which_list; double best_quality = -1e30; /* Pretty bad! */ HTPresentation *pres, *best_match=NULL; if (rep_out == WWW_RAW) { HTTRACE(CORE_TRACE, "StreamStack. Raw output...\n"); return output_stream ? output_stream : HTErrorStream(); } if (rep_out == rep_in) { HTTRACE(CORE_TRACE, "StreamStack. Identical input/output format (%s)\n" _ HTAtom_name(rep_out)); return output_stream ? output_stream : HTErrorStream(); }#ifdef HTDEBUG if (CORE_TRACE) { const char *p = HTAtom_name(rep_in); const char *q = HTAtom_name(rep_out); HTTRACE(CORE_TRACE, "StreamStack. Constructing stream stack for %s to %s\n" _ p ? p : "<NULL>" _ q ? q : "<NULL>"); }#endif /* HTDEBUG */ conversion[0] = HTRequest_conversion(request); conversion[1] = HTConversions; for(which_list = 0; which_list<2; which_list++) { HTList * cur = conversion[which_list]; while ((pres = (HTPresentation*)HTList_nextObject(cur))) { if ((pres->rep==rep_in || HTMIMEMatch(pres->rep, rep_in)) && (pres->rep_out==rep_out || HTMIMEMatch(pres->rep_out,rep_out))){ if (!best_match || better_match(pres->rep, best_match->rep) || (!better_match(best_match->rep, pres->rep) && pres->quality > best_quality)) {#ifdef HAVE_SYSTEM int result=0; if (pres->test_command) { result = system(pres->test_command); HTTRACE(CORE_TRACE, "StreamStack. system(%s) returns %d\n" _ pres->test_command _ result); } if (!result) { best_match = pres; best_quality = pres->quality; }#else best_match = pres; best_quality = pres->quality;#endif /* HAVE_SYSTEM */ } } } } if (best_match) { if (rep_out == WWW_SOURCE && best_match->rep_out != WWW_SOURCE) { HTTRACE(CORE_TRACE, "StreamStack. Source output\n"); return output_stream ? output_stream : HTErrorStream(); } return (*best_match->converter)(request, best_match->command, rep_in, rep_out, output_stream); } if (rep_out == WWW_SOURCE) { HTTRACE(CORE_TRACE, "StreamStack. Source output\n"); return output_stream ? output_stream : HTErrorStream(); } HTTRACE(CORE_TRACE, "StreamStack. NOT FOUND - error!\n"); return HTBlackHole();} /* Find the cost of a filter stack** -------------------------------**** Must return the cost of the same stack which StreamStack would set up.**** On entry,** length The size of the data to be converted*/PUBLIC double HTStackValue (HTList * theseConversions, HTFormat rep_in, HTFormat rep_out, double initial_value, long int length){ int which_list; HTList* conversion[2]; HTTRACE(CORE_TRACE, "StackValue.. Evaluating stream stack for %s worth %.3f to %s\n" _ HTAtom_name(rep_in) _ initial_value _ HTAtom_name(rep_out)); if (rep_out == WWW_SOURCE || rep_out == rep_in) return 0.0; conversion[0] = theseConversions; conversion[1] = HTConversions; for(which_list = 0; which_list<2; which_list++) if (conversion[which_list]) { HTList * cur = conversion[which_list]; HTPresentation * pres; while ((pres = (HTPresentation*)HTList_nextObject(cur))) { if (pres->rep == rep_in && (pres->rep_out == rep_out || HTMIMEMatch(pres->rep_out, rep_out))) { double value = initial_value * pres->quality; if (HTMaxSecs != 0.0) value = value - (length*pres->secs_per_byte + pres->secs) /HTMaxSecs; return value; } } } return NO_VALUE_FOUND; /* Really bad */}/* Create a new coder and insert it into stream chain** --------------------------------------------------** Creating the content decoding stack is not based on quality factors as** we don't have the freedom as with content types. Specify whether you** you want encoding or decoding using the BOOL "encode" flag.*/PUBLIC HTStream * HTContentCodingStack (HTEncoding encoding, HTStream * target, HTRequest * request, void * param, BOOL encode){ HTList * coders[2]; HTStream * top = target; HTCoding * pres = NULL; HTCoding * best_match = NULL; double best_quality = -1e30; /* Pretty bad! */ int cnt; if (!encoding || !request) { HTTRACE(CORE_TRACE, "Codings... Nothing applied...\n"); return target ? target : HTErrorStream(); } coders[0] = HTRequest_encoding(request); coders[1] = HTContentCoders; HTTRACE(CORE_TRACE, "C-E......... Looking for `%s\'\n" _ HTAtom_name(encoding)); for (cnt=0; cnt < 2; cnt++) { HTList * cur = coders[cnt]; while ((pres = (HTCoding *) HTList_nextObject(cur))) { if ((pres->encoding == encoding || HTMIMEMatch(pres->encoding, encoding)) && pres->quality > best_quality) { best_match = pres; best_quality = pres->quality; } } } if (best_match) { HTTRACE(CORE_TRACE, "C-E......... Found `%s\'\n" _ HTAtom_name(best_match->encoding)); if (encode) { if (best_match->encoder) top = (*best_match->encoder)(request, param, encoding, top); } else { if (best_match->decoder) top = (*best_match->decoder)(request, param, encoding, top); } } else if (!HTFormat_isUnityContent(encoding)) { /* ** If this is not a unity coding and we didn't find any coders ** that could handle it then put in a local file save stream ** instead of the stream that we got. */ if (encode) { HTTRACE(CORE_TRACE, "C-E......... NOT FOUND - can't encode stream!\n"); } else { HTTRACE(CORE_TRACE, "C-E......... NOT FOUND - error!\n"); top = HTBlackHole(); } } return top;}/*** Here you can provide a complete list instead of a single token.** The list has to filled up in the order the _encodings_ are to be applied*/PUBLIC HTStream * HTContentEncodingStack (HTList * encodings, HTStream * target, HTRequest * request, void * param){ if (encodings) { HTList * cur = encodings; HTEncoding pres; HTStream * top = target; while ((pres = (HTEncoding) HTList_nextObject(cur))) { top = HTContentCodingStack(pres, top, request, param, YES); if (top == HTBlackHole()) break; } return top; } return HTErrorStream();}/*** Here you can provide a complete list instead of a single token.** The list has to be in the order the _encodings_ were applied - that** is, the same way that _encodings_ are to be applied. This is all consistent** with the order of the Content-Encoding header.*/PUBLIC HTStream * HTContentDecodingStack (HTList * encodings, HTStream * target, HTRequest * request, void * param){ if (encodings) { HTEncoding pres; int cnt = HTList_count(encodings); HTStream * top = target; while (cnt > 0) { pres = (HTEncoding) HTList_objectAt(encodings, --cnt); top = HTContentCodingStack(pres, top, request, param, NO); if (top == HTBlackHole()) break; } return top; } return HTErrorStream();}/* Create a new coder and insert it into stream chain** --------------------------------------------------** Creating the transfer decoding stack is not based on quality factors as** we don't have the freedom as with content types. Specify whether you** you want encoding or decoding using the BOOL "encode" flag.*/PUBLIC HTStream * HTTransferCodingStack (HTEncoding encoding, HTStream * target, HTRequest * request, void * param, BOOL encode){ HTList * coders[2]; HTStream * top = target; HTCoding * pres = NULL; int cnt; if (!encoding || !request) { HTTRACE(CORE_TRACE, "Codings... Nothing applied...\n"); return target ? target : HTErrorStream(); } coders[0] = HTRequest_transfer(request); coders[1] = HTTransferCoders; HTTRACE(CORE_TRACE, "C-E......... Looking for `%s\'\n" _ HTAtom_name(encoding)); for (cnt=0; cnt < 2; cnt++) { HTList * cur = coders[cnt]; while ((pres = (HTCoding *) HTList_nextObject(cur))) { if (pres->encoding == encoding || HTMIMEMatch(pres->encoding, encoding)) { HTTRACE(CORE_TRACE, "C-E......... Found...\n"); if (encode) { if (pres->encoder) top = (*pres->encoder)(request, param, encoding, top); break; } else if (pres->decoder) { top = (*pres->decoder)(request, param, encoding, top); break; } } } } /* ** If this is not a unity coding and we didn't find any coders ** that could handle it then put in a local file save stream ** instead of the stream that we got. */ if (!HTFormat_isUnityContent(encoding) && target==top) { if (encode) { HTTRACE(CORE_TRACE, "C-E......... NOT FOUND - can't encode stream!\n"); } else { HTTRACE(CORE_TRACE, "C-E......... NOT FOUND - error!\n"); top = HTBlackHole(); } } return top;}/*** Here you can provide a complete list instead of a single token.** The list has to filled up in the order the _encodings_ are to be applied*/PUBLIC HTStream * HTTransferEncodingStack (HTList * encodings, HTStream * target, HTRequest * request, void * param){ if (encodings) { HTList * cur = encodings; HTEncoding pres; HTStream * top = target; while ((pres = (HTEncoding) HTList_nextObject(cur))) { top = HTTransferCodingStack(pres, top, request, param, YES); if (top == HTBlackHole()) break; } return top; } return HTErrorStream();}/*** Here you can provide a complete list instead of a single token.** The list has to be in the order the _encodings_ were applied - that** is, the same way that _encodings_ are to be applied. This is all consistent** with the order of the Content-Encoding header.*/PUBLIC HTStream * HTTransferDecodingStack (HTList * encodings, HTStream * target, HTRequest * request, void * param){ if (encodings) { HTEncoding pres; int cnt = HTList_count(encodings); HTStream * top = target; while (cnt > 0) { pres = (HTEncoding) HTList_objectAt(encodings, --cnt); top = HTTransferCodingStack(pres, top, request, param, NO); if (top == HTBlackHole()) break; } return top; } return HTErrorStream();}/* Create a new transfer coder and insert it into stream chain** -----------------------------------------------------------** Creating the content decoding stack is not based on quality factors as** we don't have the freedom as with content types. Specify whether you** you want encoding or decoding using the BOOL "encode" flag.*/PUBLIC HTStream * HTContentTransferCodingStack (HTEncoding encoding, HTStream * target, HTRequest * request, void * param, BOOL encode){ HTList * coders[2]; HTStream * top = target; HTCoding * pres = NULL; int cnt; if (!encoding || !request) { HTTRACE(CORE_TRACE, "C-T-E..... Nothing applied...\n"); return target ? target : HTErrorStream(); } /* ** We use the same encoders/decoders as for Transfer-Encodings */ coders[0] = HTRequest_transfer(request); coders[1] = HTTransferCoders; HTTRACE(CORE_TRACE, "C-T-E....... Looking for %s\n" _ HTAtom_name(encoding)); for (cnt=0; cnt < 2; cnt++) { HTList * cur = coders[cnt]; while ((pres = (HTCoding *) HTList_nextObject(cur))) { if (pres->encoding == encoding) { HTTRACE(CORE_TRACE, "C-T-E....... Found...\n"); if (encode) { if (pres->encoder) top = (*pres->encoder)(request, param, encoding, top); break; } else if (pres->decoder) { top = (*pres->decoder)(request, param, encoding, top); break; } } } } /* ** If this is not a unity coding and we didn't find any coders ** that could handle it then put in a local file save stream ** instead of the stream that we got. */ if (!HTFormat_isUnityTransfer(encoding) && target==top) { if (encode) { HTTRACE(CORE_TRACE, "C-T-E....... NOT FOUND - removing encoding!\n"); HTAnchor_setContentTransferEncoding(HTRequest_anchor(request), NULL); } else { HTTRACE(CORE_TRACE, "C-T-E....... NOT FOUND - error!\n"); top = HTBlackHole(); } } return top;}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -