/* Define the representation associated with a file suffix ** ------------------------------------------------------- ** ** Calling this with suffix set to "*" will set the default ** representation. ** Calling this with suffix set to "*.*" will set the default ** representation for unknown suffix files which contain a ".". */ PUBLIC void HTSetSuffix ARGS4( WWW_CONST char *, suffix, WWW_CONST char *, representation, WWW_CONST char *, encoding, float, value) { HTSuffix * suff; if (strcmp(suffix, "*")==0) suff = &no_suffix; else if (strcmp(suffix, "*.*")==0) suff = &unknown_suffix; else { suff = (HTSuffix*) calloc(1, sizeof(HTSuffix)); if (suff == NULL) outofmem(__FILE__, "HTSetSuffix"); if (!HTSuffixes) HTSuffixes = HTList_new(); HTList_addObject(HTSuffixes, suff); StrAllocCopy(suff->suffix, suffix); } suff->rep = HTAtom_for(representation); { char *enc = NULL, *p; StrAllocCopy(enc, encoding); for (p=enc; *p; p++) *p = TOLOWER(*p); suff->encoding = HTAtom_for(enc); free (enc); } suff->quality = value; }
/* ** Remove a conversion routine from the presentation list. ** The conversion routine must match up with the given args. */ PUBLIC void HTRemoveConversion ARGS3( WWW_CONST char *, representation_in, WWW_CONST char *, representation_out, HTConverter*, converter ){ int numberOfPresentations; HTPresentation * pres; HTAtom *rep_in, *rep_out; int x; numberOfPresentations = HTList_count(HTPresentations); rep_in = HTAtom_for(representation_in); rep_out = HTAtom_for(representation_out); for (x = 0; x < numberOfPresentations; x++) { pres = HTList_objectAt(HTPresentations, x); if (pres) { if ((!strcmp(pres->rep->name,rep_in->name)) && (!strcmp(pres->rep_out->name,rep_out->name)) && (pres->converter == converter)) { HTList_removeObject(HTPresentations,pres); } } } }
/* Define a built-in function for a content-type ** --------------------------------------------- */ PUBLIC void HTSetConversion ARGS7( HTList *, conversions, CONST char *, representation_in, CONST char *, representation_out, HTConverter*, converter, float, quality, float, secs, float, secs_per_byte ){ HTPresentation * pres = (HTPresentation *)malloc(sizeof(HTPresentation)); if (pres == NULL) outofmem(__FILE__, "HTSetPresentation"); pres->rep = HTAtom_for(representation_in); pres->rep_out = HTAtom_for(representation_out); pres->converter = converter; pres->command = NULL; /* Fixed */ pres->quality = quality; pres->secs = secs; pres->secs_per_byte = secs_per_byte; pres->command = 0; /* if (!HTPresentations) HTPresentations = HTList_new(); */ #ifdef OLD_CODE if (strcmp(representation_in, "*")==0) { if (default_presentation) free(default_presentation); default_presentation = pres; } else #endif HTList_addObject(conversions, pres); }
/* Define a presentation system command for a content-type ** ------------------------------------------------------- */ PUBLIC void HTSetPresentation ARGS5( WWW_CONST char *, representation, WWW_CONST char *, command, float, quality, float, secs, float, secs_per_byte ){ HTPresentation * pres = (HTPresentation *)malloc(sizeof(HTPresentation)); pres->rep = HTAtom_for(representation); pres->rep_out = WWW_PRESENT; /* Fixed for now ... :-) */ pres->converter = HTSaveAndExecute; /* Fixed for now ... */ pres->quality = quality; pres->secs = secs; pres->secs_per_byte = secs_per_byte; pres->rep = HTAtom_for(representation); pres->command = 0; StrAllocCopy(pres->command, command); if (!HTPresentations) HTPresentations = HTList_new(); if (strcmp(representation, "*")==0) { if (default_presentation) free(default_presentation); default_presentation = pres; } else { HTList_addObjectAtEnd(HTPresentations, pres); } }
/* Define a built-in function for a content-type ** --------------------------------------------- */ PUBLIC void HTSetConversion ARGS6( WWW_CONST char *, representation_in, WWW_CONST char *, representation_out, HTConverter*, converter, float, quality, float, secs, float, secs_per_byte ){ HTPresentation * pres = (HTPresentation *)malloc(sizeof(HTPresentation)); pres->rep = HTAtom_for(representation_in); pres->rep_out = HTAtom_for(representation_out); pres->converter = converter; pres->command = NULL; /* Fixed */ pres->quality = quality; pres->secs = secs; pres->secs_per_byte = secs_per_byte; pres->command = 0; if (!HTPresentations) HTPresentations = HTList_new(); if (strcmp(representation_in, "*")==0) { if (default_presentation) free(default_presentation); default_presentation = pres; } else { HTList_addObject(HTPresentations, pres); } }
/* Define a presentation system command for a content-type ** ------------------------------------------------------- */ PUBLIC void HTSetPresentation ARGS6( HTList *, conversions, CONST char *, representation, CONST char *, command, float, quality, float, secs, float, secs_per_byte ){ HTPresentation * pres = (HTPresentation *)malloc(sizeof(HTPresentation)); if (pres == NULL) outofmem(__FILE__, "HTSetPresentation"); pres->rep = HTAtom_for(representation); pres->rep_out = WWW_PRESENT; /* Fixed for now ... :-) */ pres->converter = HTSaveAndExecute; /* Fixed for now ... */ pres->quality = quality; pres->secs = secs; pres->secs_per_byte = secs_per_byte; pres->rep = HTAtom_for(representation); pres->command = 0; StrAllocCopy(pres->command, command); /* if (!HTPresentations) HTPresentations = HTList_new(); */ #ifdef OLD_CODE if (strcmp(representation, "*")==0) { if (default_presentation) free(default_presentation); default_presentation = pres; } else #endif HTList_addObject(conversions, pres); }
/* Define a presentation system command for a content-type ** ------------------------------------------------------- ** INPUT: ** conversions: The list of conveters and presenters ** representation: the MIME-style format name ** command: the MAILCAP-style command template ** quality: A degradation faction [0..1] ** maxbytes: A limit on the length acceptable as input (0 infinite) ** maxsecs: A limit on the time user will wait (0 for infinity) */ PUBLIC void HTPresentation_add (HTList * conversions, const char * representation, const char * command, const char * test_command, double quality, double secs, double secs_per_byte) { HTPresentation * pres; if (presentation_converter) { if ((pres = (HTPresentation *) HT_CALLOC(1,sizeof(HTPresentation))) == NULL) HT_OUTOFMEM("HTSetPresentation"); pres->rep = HTAtom_for(representation); pres->rep_out = WWW_PRESENT; /* Fixed for now ... :-) */ pres->converter = presentation_converter; pres->quality = quality; pres->secs = secs; pres->secs_per_byte = secs_per_byte; pres->rep = HTAtom_for(representation); pres->command = NULL; StrAllocCopy(pres->command, command); pres->test_command = NULL; StrAllocCopy(pres->test_command, test_command); HTTRACE(CORE_TRACE, "Presentation Adding `%s\' with quality %.2f\n" _ command _ quality); HTList_addObject(conversions, pres); } }
PUBLIC int HTMIME_contentType (HTRequest * request, HTResponse * response, char * token, char * value) { char * field; if ((field = HTNextField(&value)) != NULL) { /* Get the Content-Type */ char *lc = field; while ((*lc = TOLOWER(*lc))) lc++; HTResponse_setFormat(response, HTAtom_for(field)); /* Get all the parameters to the Content-Type */ { char * param; while ((field = HTNextField(&value)) != NULL && (param = HTNextField(&value)) != NULL) { lc = field; while ((*lc = TOLOWER(*lc))) lc++; lc = param; while ((*lc = TOLOWER(*lc))) lc++; HTResponse_addFormatParam(response, field, param); } } } return HT_OK; }
/* ** Charset parameter to Content-Type */ PUBLIC HTCharset HTResponse_charset (HTResponse * me) { if (me && me->type_parameters) { char * charset = HTAssocList_findObject(me->type_parameters,"charset"); return HTAtom_for(charset); } return NULL; }
/* ** Level parameter to Content-Type */ PUBLIC HTLevel HTAnchor_level (HTParentAnchor * me) { if (me && me->type_parameters) { char * level = HTAssocList_findObject(me->type_parameters, "level"); return HTAtom_for(level); } return NULL; }
PUBLIC int HTMIME_contentTransferEncoding (HTRequest * request, HTResponse * response, char * token, char * value) { char * field; if ((field = HTNextField(&value)) != NULL) { char *lc = field; while ((*lc = TOLOWER(*lc))) lc++; HTResponse_setContentTransferEncoding(response, HTAtom_for(field)); } return HT_OK; }
PRIVATE HTRequest * create_request (void) { HTRequest * me = HTRequest_new(); /* set output and debug streans */ HTRequest_setOutputStream(me, HTFWriter_new(me, stdout, YES)); HTRequest_setDebugStream(me, HTFWriter_new(me, stderr, YES)); HTRequest_setOutputFormat(me,HTAtom_for("text/xml")); HTRequest_setDebugFormat(me,WWW_SOURCE); return me; }
/* Define a built-in function for a content-type ** --------------------------------------------- */ PUBLIC void HTConversion_add (HTList * conversions, const char * representation_in, const char * representation_out, HTConverter * converter, double quality, double secs, double secs_per_byte) { HTPresentation * pres; if ((pres = (HTPresentation*) HT_CALLOC(1,sizeof(HTPresentation))) == NULL) HT_OUTOFMEM("HTSetPresentation"); pres->rep = HTAtom_for(representation_in); pres->rep_out = HTAtom_for(representation_out); pres->converter = converter; pres->command = NULL; /* Fixed */ pres->test_command = NULL; pres->quality = quality; pres->secs = secs; pres->secs_per_byte = secs_per_byte; HTTRACE(CORE_TRACE, "Conversions. Adding %p with quality %.2f\n" _ converter _ quality); HTList_addObject(conversions, pres); }
/* ** LOCK requests */ PRIVATE BOOL lock_request (Cmdline * arg) { HTDAVHeaders * headers = HTDAVHeaders_new(); HTRequest * request = create_request (); HTAnchor * dst = HTAnchor_findAddress(arg->request_uri); HTParentAnchor * src = NULL; HTParentAnchor * base = NULL; BOOL status = NO; char * data = NULL; if (arg->I) { HTPrint ("Adding If header %s\n",arg->I); HTDAV_setIfHeader (headers,arg->I); } if (arg->arg1) { data = create_body (arg->arg1); HTPrint ("xml body %s\n",data); /* chose the func */ if (arg->func==1) { src = HTTmpAnchor(NULL); HTAnchor_setDocument(src, data); HTAnchor_setFormat(src, HTAtom_for ("text/xml")); HTAnchor_setLength(src, strlen(data)); } } if (arg->base_str && *(arg->base_str)) base = (HTParentAnchor *) HTAnchor_findAddress(arg->base_str); if (arg->D) HTDAV_setDepthHeader (headers,arg->D); if (arg->T) HTDAV_setTimeoutHeader (headers,arg->T); HTPrint ("function %d src? %s\n",arg->func,(src)?"yes":"no"); switch (arg->func) { case 1: status = HTLOCKDocumentAnchor (request,dst,src,headers); break; case 2: status = HTLOCKAnchor (request,dst,data,headers); break; case 3: status = HTLOCKAbsolute (request,arg->request_uri,data,headers); break; case 4: status = HTLOCKRelative (request,arg->request_uri,base,data,headers); break; } return status; }
PUBLIC void HTAcceptLanguage ARGS3(HTList *, list, char *, lang, float, quality) { HTAcceptNode * node; if (!list || !lang || !*lang) return; node = (HTAcceptNode*)calloc(1, sizeof(HTAcceptNode)); if (!node) outofmem(__FILE__, "HTAcceptLanguage"); HTList_addObject(list, (void*)node); node->atom = HTAtom_for(lang); node->quality = quality; }
/* Define a built-in function for a content-type ** --------------------------------------------- */ PUBLIC void HTSetConversion ARGS7( CONST char *, representation_in, CONST char *, representation_out, HTConverter*, converter, float, quality, float, secs, float, secs_per_byte, long int, maxbytes) { HTPresentation * pres = typecalloc(HTPresentation); if (pres == NULL) outofmem(__FILE__, "HTSetConversion"); pres->rep = HTAtom_for(representation_in); pres->rep_out = HTAtom_for(representation_out); pres->converter = converter; pres->command = NULL; /* Fixed */ pres->quality = quality; pres->secs = secs; pres->secs_per_byte = secs_per_byte; pres->maxbytes = maxbytes; pres->command = NULL; /* * Memory Leak fixed. * 05-28-94 Lynx 2-3-1 Garrett Arch Blythe */ if (!HTPresentations) { HTPresentations = HTList_new(); #ifdef LY_FIND_LEAKS atexit(HTFreePresentations); #endif } HTList_addObject(HTPresentations, pres); }
/* Determine file format from file name -- string version ** ------------------------------------------------------ */ PUBLIC char *HTFileMimeType ARGS2 ( WWW_CONST char *, filename, WWW_CONST char *, default_type) { HTAtom *pencoding; HTFormat format; int compressed; format = HTFileFormat (filename, &pencoding, HTAtom_for (default_type), &compressed); if (HTAtom_name (format)) return HTAtom_name (format); else return default_type; }
PUBLIC void HTLanguage_add (HTList * list, const char * lang, double quality) { HTAcceptNode * node; if (!list || !lang || !*lang) { HTTRACE(CORE_TRACE, "Languages... Bad argument\n"); return; } if ((node = (HTAcceptNode *) HT_CALLOC(1, sizeof(HTAcceptNode))) == NULL) HT_OUTOFMEM("HTAcceptLanguage"); HTList_addObject(list, (void*)node); node->atom = HTAtom_for(lang); node->quality = quality; }
PUBLIC void HTCharset_add (HTList * list, const char * charset, double quality) { HTAcceptNode * node; if (!list || !charset || !*charset) { HTTRACE(CORE_TRACE, "Charset..... Bad argument\n"); return; } if ((node = (HTAcceptNode *) HT_CALLOC(1, sizeof(HTAcceptNode))) == NULL) HT_OUTOFMEM("HTAcceptCharsetuage"); HTList_addObject(list, (void*)node); node->atom = HTAtom_for(charset); node->quality = quality; }
/* ** MOVE requests */ PRIVATE BOOL move_request ( Cmdline * arg ) { HTDAVHeaders * headers = HTDAVHeaders_new(); HTRequest * request = create_request (); HTAnchor * src = HTAnchor_findAddress(arg->request_uri); HTParentAnchor * body = NULL; HTParentAnchor * base = NULL; BOOL status = NO; if (arg->arg1) { HTPrint ("Adding Destination header %s\n",arg->arg1); HTDAV_setDestinationHeader (headers,arg->arg1); } if (arg->I) { HTPrint ("Adding If header %s\n",arg->I); HTDAV_setIfHeader (headers,arg->I); } /* chose the func */ if (arg->func==2 && arg->arg2 ) { body = HTTmpAnchor(NULL); HTAnchor_setDocument(body, arg->arg2); HTAnchor_setFormat(body, HTAtom_for ("text/xml")); HTAnchor_setLength(body, strlen(arg->arg2)); } if (arg->base_str && *(arg->base_str)) base = (HTParentAnchor *) HTAnchor_findAddress(arg->base_str); if (arg->D) HTDAV_setDepthHeader (headers,arg->D); if (arg->O == 'T') HTDAV_setOverwriteHeader (headers,YES); else if (arg->O == 'F') HTDAV_setOverwriteHeader (headers,NO); switch (arg->func) { case 1: status = HTMOVEAnchor (request,src,arg->arg2,headers); break; case 2: status = HTMOVEDocumentAnchor (request,src,body,headers); break; case 3: status = HTMOVEAbsolute (request,arg->request_uri,arg->arg2, headers); break; case 4: status = HTMOVERelative (request,arg->request_uri,base,arg->arg2,headers); break; } return status; }
/* ** PROPFIND requests */ PRIVATE BOOL propfind_request (Cmdline * arg) { BOOL status = NO; HTDAVHeaders * headers = HTDAVHeaders_new(); HTRequest * request = create_request (); HTAnchor * dst = HTAnchor_findAddress(arg->request_uri); HTParentAnchor *base = NULL; HTParentAnchor *src = NULL; char * xmlbody = NULL; /* chose the func */ HTPrint ("should we set the xml body?\n"); if (arg->arg1 && *(arg->arg1)) { if (!strcasecomp (arg->arg1,"allprop") || !strcasecomp (arg->arg1,"propname")) xmlbody = create_propbody (arg->arg1); else xmlbody = arg->arg1; HTPrint ("xml body %s\n",xmlbody); } if (arg->func==2 && xmlbody && *xmlbody) { src = HTTmpAnchor(NULL); HTAnchor_setDocument(src, xmlbody); HTAnchor_setFormat(src, HTAtom_for ("text/xml")); HTAnchor_setLength(src, strlen(xmlbody)); } if (arg->base_str && *(arg->base_str)) base = (HTParentAnchor *) HTAnchor_findAddress(arg->base_str); HTPrint ("setting headers\n"); if (arg->D) HTDAV_setDepthHeader (headers,arg->D); switch (arg->func) { case 1: status = HTPROPFINDAnchor (request,dst,xmlbody,headers); break; case 2: status = HTPROPFINDDocumentAnchor (request,dst,src,headers); break; case 3: status = HTPROPFINDAbsolute (request,arg->request_uri,xmlbody,headers); break; case 4: status = HTPROPFINDRelative (request,arg->request_uri,base,xmlbody,headers); break; } return status; }
/* ** PROPPATCH requests */ PRIVATE BOOL proppatch_request (Cmdline * arg) { BOOL status = NO; HTDAVHeaders * headers = HTDAVHeaders_new(); HTRequest * request = create_request (); HTAnchor * dst = HTAnchor_findAddress(arg->request_uri); HTParentAnchor *base = NULL; HTParentAnchor *src = NULL; char * xmlbody = NULL; if (arg->arg1 && *(arg->arg1)) xmlbody = arg->arg1; else return NO; HTPrint ("xml body **%s**\n",xmlbody); if (arg->func==2) { src = HTTmpAnchor(NULL); HTAnchor_setDocument(src, xmlbody); HTAnchor_setFormat(src, HTAtom_for ("text/xml")); HTAnchor_setLength(src, strlen(xmlbody)); } if (arg->base_str && *(arg->base_str)) base = (HTParentAnchor *) HTAnchor_findAddress(arg->base_str); HTPrint ("setting headers\n"); if (arg->I && *(arg->I)) { HTPrint ("Adding If header %s\n",arg->I); HTDAV_setIfHeader (headers,arg->I); } HTPrint ("Chosing func\n"); switch (arg->func) { case 1: status = HTPROPPATCHAnchor (request,dst,xmlbody,headers); break; case 2: status = HTPROPPATCHDocumentAnchor (request,dst,src,headers); break; case 3: status = HTPROPPATCHAbsolute (request,arg->request_uri,xmlbody,headers); break; case 4: status = HTPROPPATCHRelative (request,arg->request_uri,base,xmlbody,headers); break; } return status; }
/* ** Content Language */ PUBLIC HTList * HTAnchor_language (HTParentAnchor * me) { if (me) { if (me->content_language == NULL && me->headers) { char * value = HTAssocList_findObject(me->headers, "content-language"); char * field; if (!me->content_language) me->content_language = HTList_new(); while ((field = HTNextField(&value)) != NULL) { char * lc = field; while ((*lc = TOLOWER(*lc))) lc++; HTList_addObject(me->content_language, HTAtom_for(field)); } } return me->content_language; } return NULL; }
PUBLIC void HTAcceptEncoding ARGS3(HTList *, list, char *, enc, float, quality) { HTAcceptNode * node; char * cur; if (!list || !enc || !*enc) return; for(cur=enc; *cur; cur++) *cur=TOLOWER(*cur); node = (HTAcceptNode*)calloc(1, sizeof(HTAcceptNode)); if (!node) outofmem(__FILE__, "HTAcceptEncoding"); HTList_addObject(list, (void*)node); node->atom = HTAtom_for(enc); node->quality = quality; }
int LYLoadKeymap( char *arg, HTParentAnchor *anAnchor, HTFormat format_out, HTStream *sink ) { HTFormat format_in = HTAtom_for( "text/html" ); HTStream *target; char *buf = 0; int i; target = HTStreamStack( format_in, format_out, &sink[0]._HTStream, anAnchor ); if ( target == 0 || target == 0 ) { HTSprintf0( &buf, gettext( "Sorry, no known way of converting %s to %s." ), format_in->name, format_out->name ); HTAlert( buf ); if ( buf ) { free( buf ); buf = 0; } return -29999; } else { anAnchor->no_cache = 1; HTSprintf0( &buf, "<html>\n<head>\n<title>%s</title>\n</head>\n<body>\n", gettext( "Current Key Map" ) ); ebx( target, buf, strlen( buf ) ); HTSprintf0( &buf, "<pre>\n" ); ebx( target, buf, strlen( buf ) ); i = 98; for ( ; i <= 123; i++ ) { print_binding( target, i, 1 ); // i++; } i = 1; for ( ; i <= 660; i++ ) { if ( ( i > 127 || i <= 32 || !( *(short*)(*(int*)(__ctype_b_loc( )) + ( ( i + -1 ) * 2 )) & 1024 ) ) && ( LYUseMouse || keymap[ i ] != 84 ) ) print_binding( target, i, 0 ); // i++; } HTSprintf0( &buf, "</pre>\n</body>\n</html>\n" ); ebx( target, buf, strlen( buf ) ); ; } }
/* 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 float HTStackValue ARGS4( HTFormat, format_in, HTFormat, rep_out, float, initial_value, long int, length) { HTAtom * wildcard = HTAtom_for("*"); #ifndef DISABLE_TRACE if (www2Trace) fprintf(stderr, "HTFormat: Evaluating stream stack for %s worth %.3f to %s\n", HTAtom_name(format_in), initial_value, HTAtom_name(rep_out)); #endif if (rep_out == WWW_SOURCE || rep_out == format_in) return 0.0; if (!HTPresentations) HTFormatInit(); /* set up the list */ { int n = HTList_count(HTPresentations); int i; HTPresentation * pres; for(i=0; i<n; i++) { pres = HTList_objectAt(HTPresentations, i); if (pres->rep == format_in && ( pres->rep_out == rep_out || pres->rep_out == wildcard)) { float value = initial_value * pres->quality; if (HTMaxSecs != 0.0) value = value - (length*pres->secs_per_byte + pres->secs) /HTMaxSecs; return value; } } } return -1e30; /* Really bad */ }
PUBLIC BOOL HTCoding_add (HTList * list, const char * encoding, HTCoder * encoder, HTCoder * decoder, double quality) { if (list && encoding && (encoder || decoder)) { HTCoding * me; if ((me = (HTCoding *) HT_CALLOC(1, sizeof(HTCoding))) == NULL) HT_OUTOFMEM("HTCoding_add"); me->encoding = HTAtom_for(encoding); me->encoder = encoder; me->decoder = decoder; me->quality = quality; HTTRACE(CORE_TRACE, "Codings..... Adding %s with quality %.2f\n" _ encoding _ quality); return HTList_addObject(list, (void *) me); } HTTRACE(CORE_TRACE, "Codings..... Bad argument\n"); return NO; }
/* Define a presentation system command for a content-type ** ------------------------------------------------------- */ PUBLIC void HTSetPresentation ARGS6( CONST char *, representation, CONST char *, command, double, quality, double, secs, double, secs_per_byte, long int, maxbytes) { HTPresentation * pres = typecalloc(HTPresentation); if (pres == NULL) outofmem(__FILE__, "HTSetPresentation"); pres->rep = HTAtom_for(representation); pres->rep_out = WWW_PRESENT; /* Fixed for now ... :-) */ pres->converter = HTSaveAndExecute; /* Fixed for now ... */ pres->quality = (float) quality; pres->secs = (float) secs; pres->secs_per_byte = (float) secs_per_byte; pres->maxbytes = maxbytes; pres->command = NULL; StrAllocCopy(pres->command, command); /* * Memory leak fixed. * 05-28-94 Lynx 2-3-1 Garrett Arch Blythe */ if (!HTPresentations) { HTPresentations = HTList_new(); #ifdef LY_FIND_LEAKS atexit(HTFreePresentations); #endif } if (strcmp(representation, "*")==0) { FREE(default_presentation); default_presentation = pres; } else { HTList_addObject(HTPresentations, pres); } }
PRIVATE int HTGuess_flush (HTStream * me) { if (!me->transparent) { HTResponse * response = me->response; /* ** First we look for magic tokens and evaluate the contents of the buffer ** that we are investigating. */ if (me->cnt) { HTTRACE(STREAM_TRACE, "GUESSING.... Result of content analysis: Text=%d%% Newlines=%d%% Ctrl=%d%% High=%d%%\n" _ (int)(100*me->text_cnt/me->cnt + 0.5) _ (int)(100*me->lf_cnt /me->cnt + 0.5) _ (int)(100*me->ctrl_cnt/me->cnt + 0.5) _ (int)(100*me->high_cnt/me->cnt + 0.5)); } if (!me->ctrl_cnt || me->text_cnt + me->lf_cnt >= 16 * (me->ctrl_cnt + me->high_cnt)) { char *ptr; /* some kind of text */ *me->write_ptr = 0; /* terminate buffer */ if (me->high_cnt > 0) HTResponse_setContentTransferEncoding(response, WWW_CODING_8BIT); else HTResponse_setContentTransferEncoding(response, WWW_CODING_7BIT); if (is_html(me->buffer)) HTResponse_setFormat(response, HTAtom_for("text/html")); else if (!strncmp(me->buffer, "%!", 2)) HTResponse_setFormat(response, HTAtom_for("application/postscript")); else if (strstr(me->buffer, "#define") && strstr(me->buffer, "_width") && strstr(me->buffer, "_bits")) HTResponse_setFormat(response, HTAtom_for("image/x-xbitmap")); else if ((ptr = strstr(me->buffer, "converted with BinHex"))!=NULL) HTResponse_setContentTransferEncoding(response, WWW_CODING_MACBINHEX); else if (!strncmp(me->buffer, "begin ", 6)) HTResponse_setContentTransferEncoding(response, WWW_CODING_BASE64); else HTResponse_setFormat(response, WWW_PLAINTEXT); } else { if (!strncmp(me->buffer, "GIF", 3)) HTResponse_setFormat(response, WWW_GIF); else if (!strncmp(me->buffer, "\377\330\377\340", 4)) HTResponse_setFormat(response, WWW_JPEG); else if (!strcmp(me->buffer, "MM")) /* MM followed by a zero */ HTResponse_setFormat(response, WWW_TIFF); else if (!strncmp(me->buffer, "\211PNG\r\n\032\n", 8)) HTResponse_setFormat(response, WWW_PNG); else if (!strncmp(me->buffer, ".snd", 4)) HTResponse_setFormat(response, WWW_AUDIO); else if (!strncmp(me->buffer, "\037\235", 2)) HTResponse_addEncoding(response, WWW_CODING_COMPRESS); else if (!strncmp(me->buffer, "\037\213", 2)) HTResponse_addEncoding(response, WWW_CODING_GZIP); else HTResponse_setFormat(response, WWW_BINARY); } /* ** If we couldn't find any magic tokens then we try and look at the suffix ** of the URL file name and use our own bindings to see if that gives any ** results. */ if (HTResponse_format(response) == WWW_UNKNOWN) { HTParentAnchor * anchor = HTRequest_anchor(me->request); char * addr = HTAnchor_physical(anchor); HTTRACE(STREAM_TRACE, "GUESSING.... Hmm - trying local bindings\n"); HTBind_getResponseBindings (response, addr); } /* ** If nothing worked then give up and say binary... */ if (HTResponse_format(response) == WWW_UNKNOWN) { HTTRACE(STREAM_TRACE, "GUESSING.... That's it - I'm giving up!\n"); HTResponse_setFormat(response, WWW_BINARY); } HTTRACE(STREAM_TRACE, "Guessed..... Content-Type `%s\'\n" _ HTAtom_name(HTResponse_format(response))); /* ** Set up the new stream stack with the type we figured out */ if ((me->target = HTStreamStack(HTResponse_format(response), me->output_format, me->output_stream, me->request, NO)) == NULL) { HTTRACE(STREAM_TRACE, "HTGuess..... Can't convert media type\n"); me->target = HTErrorStream(); } me->transparent = YES; return PUT_BLOCK(me->buffer, me->cnt); } return HT_OK; }
/* Create a 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. */ PUBLIC HTStream * HTStreamStack ARGS5( HTFormat, format_in, HTFormat, rep_out, int, compressed, HTStream*, sink, HTParentAnchor*, anchor) { HTAtom * wildcard = HTAtom_for("*"); HTPresentation temp; /* Inherit force_dump_to_file from mo-www.c. */ extern int force_dump_to_file; #ifndef DISABLE_TRACE if (www2Trace) fprintf(stderr, "[HTStreamStack] Constructing stream stack for %s to %s\n", HTAtom_name(format_in), HTAtom_name(rep_out)); #endif #ifndef DISABLE_TRACE if (www2Trace) fprintf (stderr, " Compressed is %d\n", compressed); #endif if (rep_out == WWW_SOURCE || rep_out == format_in) { #ifndef DISABLE_TRACE if (www2Trace) fprintf (stderr, "[HTStreamStack] rep_out == WWW_SOURCE | rep_out == format_in; returning sink\n"); #endif return sink; } if (!HTPresentations) HTFormatInit(); /* set up the list */ if (force_dump_to_file && format_in != WWW_MIME) { return HTSaveAndExecute (NULL, anchor, sink, format_in, compressed); } { int n = HTList_count(HTPresentations); int i; HTPresentation * pres; for(i=0; i<n; i++) { pres = HTList_objectAt(HTPresentations, i); #ifndef DISABLE_TRACE if (www2Trace) { fprintf (stderr, "HTFormat: looking at pres '%s'\n", HTAtom_name (pres->rep)); if (pres->command) fprintf (stderr, "HTFormat: pres->command is '%s'\n", pres->command); else fprintf (stderr, "HTFormat: pres->command doesn't exist\n"); } #endif if (pres->rep == format_in || partial_wildcard_matches (pres->rep, format_in)) { if (pres->command && strstr (pres->command, "mosaic-internal-present")) { #ifndef DISABLE_TRACE if (www2Trace) fprintf (stderr, "[HTStreamStack] HEY HEY HEY caught internal-present\n"); #endif return HTPlainPresent (pres, anchor, sink, format_in, compressed); } if (pres->rep_out == rep_out) { #ifndef DISABLE_TRACE if (www2Trace) fprintf (stderr, "[HTStreamStack] pres->rep_out == rep_out\n"); #endif return (*pres->converter)(pres, anchor, sink, format_in, compressed); } if (pres->rep_out == wildcard) { #ifndef DISABLE_TRACE if (www2Trace) fprintf (stderr, "[HTStreamStack] pres->rep_out == wildcard\n"); #endif temp = *pres;/* make temp conversion to needed fmt */ temp.rep_out = rep_out; /* yuk */ return (*pres->converter)(&temp, anchor, sink, format_in, compressed); } } } } #ifndef DISABLE_TRACE if (www2Trace) { fprintf (stderr, "[HTStreamStack] Returning NULL at bottom.\n"); } #endif return NULL; }