📄 htmime.c
字号:
case miSERVER: case miSET_COOKIE1: case miSET_COOKIE2: case miTITLE: case miTRANSFER_ENCODING: case miUPGRADE: case miURI: case miVARY: case miVIA: case miWARNING: case miWWW_AUTHENTICATE: me->field = me->state; /* remember it */ me->state = miSKIP_GET_VALUE; /* Fall through! */ case miSKIP_GET_VALUE: if (c == '\n') { me->fold_state = me->state; me->state = miNEWLINE; break; } if (WHITE(c)) /* ** Skip white space. */ break; me->value_pointer = me->value; me->state = miGET_VALUE; /* Fall through to store first character */ case miGET_VALUE: GET_VALUE: if (c != '\n') { /* Not end of line */ if (me->value_pointer < me->value + VALUE_SIZE - 1) { *me->value_pointer++ = c; break; } else { goto value_too_long; } } /* Fall through (if end of line) */ case miJUNK_LINE: if (c == '\n') { me->fold_state = me->state; me->state = miNEWLINE; } break; } /* switch on state*/ return;value_too_long: CTRACE((tfp, "HTMIME: *** Syntax error. (string too long)\n"));bad_field_name: /* Ignore it */ me->state = miJUNK_LINE; return;}/* String handling** ---------------**** Strings must be smaller than this buffer size.*/PRIVATE void HTMIME_put_string ARGS2( HTStream *, me, CONST char *, s){ CONST char * p; if (me->state == MIME_TRANSPARENT) { /* Optimisation */ (*me->targetClass.put_string)(me->target,s); } else if (me->state != MIME_IGNORE) { CTRACE((tfp, "HTMIME: %s\n", s)); for (p=s; *p; p++) HTMIME_put_character(me, *p); }}/* Buffer write. Buffers can (and should!) be big.** ------------*/PRIVATE void HTMIME_write ARGS3( HTStream *, me, CONST char *, s, int, l){ CONST char * p; if (me->state == MIME_TRANSPARENT) { /* Optimisation */ (*me->targetClass.put_block)(me->target, s, l); } else { CTRACE((tfp, "HTMIME: %.*s\n", l, s)); for (p = s; p < s+l; p++) HTMIME_put_character(me, *p); }}/* Free an HTML object** -------------------***/PRIVATE void HTMIME_free ARGS1( HTStream *, me){ if (me) { FREE(me->location); FREE(me->compression_encoding); if (me->target) (*me->targetClass._free)(me->target); FREE(me); }}/* End writing*/PRIVATE void HTMIME_abort ARGS2( HTStream *, me, HTError, e){ if (me) { FREE(me->location); FREE(me->compression_encoding); if (me->target) (*me->targetClass._abort)(me->target, e); FREE(me); }}/* Structured Object Class** -----------------------*/PRIVATE CONST HTStreamClass HTMIME ={ "MIMEParser", HTMIME_free, HTMIME_abort, HTMIME_put_character, HTMIME_put_string, HTMIME_write};/* Subclass-specific Methods** -------------------------*/PUBLIC HTStream* HTMIMEConvert ARGS3( HTPresentation *, pres, HTParentAnchor *, anchor, HTStream *, sink){ HTStream* me; me = typecalloc(HTStream); if (me == NULL) outofmem(__FILE__, "HTMIMEConvert"); me->isa = &HTMIME; me->sink = sink; me->anchor = anchor; me->anchor->safe = FALSE; me->anchor->no_cache = FALSE; FREE(me->anchor->cache_control); FREE(me->anchor->SugFname); FREE(me->anchor->charset); FREE(me->anchor->content_language); FREE(me->anchor->content_encoding); FREE(me->anchor->content_base); FREE(me->anchor->content_disposition); FREE(me->anchor->content_location); FREE(me->anchor->content_md5); me->anchor->content_length = 0; FREE(me->anchor->date); FREE(me->anchor->expires); FREE(me->anchor->last_modified); FREE(me->anchor->ETag); FREE(me->anchor->server); me->target = NULL; me->state = miBEGINNING_OF_LINE; /* * Sadly enough, change this to always default to WWW_HTML * to parse all text as HTML for the users. * GAB 06-30-94 * Thanks to Robert Rowland robert@cyclops.pei.edu * * After discussion of the correct handline, should be application/octet- * stream or unknown; causing servers to send a correct content * type. * * The consequence of using WWW_UNKNOWN is that you end up downloading * as a binary file what 99.9% of the time is an HTML file, which should * have been rendered or displayed. So sadly enough, I'm changing it * back to WWW_HTML, and it will handle the situation like Mosaic does, * and as Robert Rowland suggested, because being functionally correct * 99.9% of the time is better than being technically correct but * functionally nonsensical. - FM *//*** me->format = WWW_UNKNOWN; ***/ me->format = WWW_HTML; me->targetRep = pres->rep_out; me->boundary = NULL; /* Not set yet */ me->set_cookie = NULL; /* Not set yet */ me->set_cookie2 = NULL; /* Not set yet */ me->refresh_url = NULL; /* Not set yet */ me->encoding = 0; /* Not set yet */ me->compression_encoding = NULL; /* Not set yet */ me->net_ascii = NO; /* Local character set */ HTAnchor_setUCInfoStage(me->anchor, current_char_set, UCT_STAGE_STRUCTURED, UCT_SETBY_DEFAULT); HTAnchor_setUCInfoStage(me->anchor, current_char_set, UCT_STAGE_HTEXT, UCT_SETBY_DEFAULT); return me;}PUBLIC HTStream* HTNetMIME ARGS3( HTPresentation *, pres, HTParentAnchor *, anchor, HTStream *, sink){ HTStream* me = HTMIMEConvert(pres,anchor, sink); if (!me) return NULL; me->net_ascii = YES; return me;}PUBLIC HTStream* HTMIMERedirect ARGS3( HTPresentation *, pres, HTParentAnchor *, anchor, HTStream *, sink){ HTStream* me = HTMIMEConvert(pres,anchor, sink); if (!me) return NULL; me->pickup_redirection = YES; if (me->targetRep == WWW_DEBUG && sink) me->no_streamstack = YES; return me;}/* Japanese header handling functions** ==================================**** K&Rized and added 07-Jun-96 by FM, based on:**////////////////////////////////////////////////////////////////////////**** ISO-2022-JP handling routines** &** MIME decode routines (quick hack just for ISO-2022-JP)**** Thu Jan 25 10:11:42 JST 1996**** Copyright (C) 1994, 1995, 1996** Shuichi Ichikawa (ichikawa@nuee.nagoya-u.ac.jp)**** This program is free software; you can redistribute it and/or modify** it under the terms of the GNU General Public License as published by** the Free Software Foundation; either versions 2, or (at your option)** any later version.**** This program is distributed in the hope that it will be useful** but WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the** GNU General Public License for more details.**** You should have received a copy of the GNU General Public License** along with SKK, see the file COPYING. If not, write to the Free** Software Foundation Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*//*** MIME decoding routines**** Written by S. Ichikawa,** partially inspired by encdec.c of <jh@efd.lth.se>.** Assume caller's buffer is LINE_LENGTH bytes, these decode to** no longer than the input strings.*/#define LINE_LENGTH 512 /* Maximum length of line of ARTICLE etc */#ifdef ESC#undef ESC#endif /* ESC */#include <LYCharVals.h> /* S/390 -- gil -- 0163 */#define ESC CH_ESCPRIVATE char HTmm64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" ;PRIVATE char HTmmquote[] = "0123456789ABCDEF";PRIVATE int HTmmcont = 0;PUBLIC void HTmmdec_base64 ARGS2( char *, t, char *, s){ int d, count, j, val; char buf[LINE_LENGTH], *bp, nw[4], *p; for (bp = buf; *s; s += 4) { val = 0; if (s[2] == '=') count = 1; else if (s[3] == '=') count = 2; else count = 3; for (j = 0; j <= count; j++) { if (!(p = strchr(HTmm64, s[j]))) { return; } d = p - HTmm64; d <<= (3-j)*6; val += d; } for (j = 2; j >= 0; j--) { nw[j] = (char) (val & 255); val >>= 8; } if (count--) *bp++ = nw[0]; if (count--) *bp++ = nw[1]; if (count) *bp++ = nw[2]; } *bp = '\0'; strcpy(t, buf);}PUBLIC void HTmmdec_quote ARGS2( char *, t, char *, s){ char buf[LINE_LENGTH], cval, *bp, *p; for (bp = buf; *s; ) { if (*s == '=') { cval = 0; if (s[1] && (p = strchr(HTmmquote, s[1]))) { cval += (char) (p - HTmmquote); } else { *bp++ = *s++; continue; } if (s[2] && (p = strchr(HTmmquote, s[2]))) { cval <<= 4; cval += (char) (p - HTmmquote); *bp++ = cval; s += 3; } else { *bp++ = *s++; } } else if (*s == '_') { *bp++ = 0x20; s++; } else { *bp++ = *s++; } } *bp = '\0'; strcpy(t, buf);}/*** HTmmdecode for ISO-2022-JP - FM*/PUBLIC void HTmmdecode ARGS2( char *, trg, char *, str){ char buf[LINE_LENGTH], mmbuf[LINE_LENGTH]; char *s, *t, *u; int base64, quote; buf[0] = '\0'; for (s = str, u = buf; *s; ) { if (!strncasecomp(s, "=?ISO-2022-JP?B?", 16)) { base64 = 1; } else { base64 = 0; } if (!strncasecomp(s, "=?ISO-2022-JP?Q?", 16)) { quote = 1; } else { quote = 0; } if (base64 || quote) { if (HTmmcont) { for (t = s - 1; t >= str && (*t == ' ' || *t == '\t'); t--) { u--; } } for (s += 16, t = mmbuf; *s; ) { if (s[0] == '?' && s[1] == '=') { break; } else { *t++ = *s++; } } if (s[0] != '?' || s[1] != '=') { goto end; } else { s += 2; *t = '\0'; } if (base64) HTmmdec_base64(mmbuf, mmbuf); if (quote) HTmmdec_quote(mmbuf, mmbuf); for (t = mmbuf; *t; ) *u++ = *t++; HTmmcont = 1; /* if (*s == ' ' || *s == '\t') *u++ = *s; */ /* for ( ; *s == ' ' || *s == '\t'; s++) ; */ } else { if (*s != ' ' && *s != '\t') HTmmcont = 0; *u++ = *s++; } } *u = '\0';end: strcpy(trg, buf);}/*** Insert ESC where it seems lost.** (The author of this function "rjis" is S. Ichikawa.)*/PUBLIC int HTrjis ARGS2( char *, t, char *, s){ char *p, buf[LINE_LENGTH]; int kanji = 0; if (strchr(s, ESC) || !strchr(s, '$')) { if (s != t) strcpy(t, s); return 1; } for (p = buf; *s; ) { if (!kanji && s[0] == '$' && (s[1] == '@' || s[1] == 'B')) { if (HTmaybekanji((int)s[2], (int)s[3])) { kanji = 1; *p++ = ESC; *p++ = *s++; *p++ = *s++; *p++ = *s++; *p++ = *s++; continue; } *p++ = *s++; continue; } if (kanji && s[0] == '(' && (s[1] == 'J' || s[1] == 'B')) { kanji = 0; *p++ = ESC; *p++ = *s++; *p++ = *s++; continue; } *p++ = *s++; } *p = *s; /* terminate string */ strcpy(t, buf); return 0;}/*** The following function "maybekanji" is derived from** RJIS-1.0 by Mr. Hironobu Takahashi.** Maybekanji() is included here under the courtesy of the author.** The original comment of rjis.c is also included here.*//* * RJIS ( Recover JIS code from broken file ) * $Header: rjis.c,v 0.2 92/09/04 takahasi Exp $ * Copyright (C) 1992 1994 * Hironobu Takahashi (takahasi@tiny.or.jp) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either versions 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with SKK, see the file COPYING. If not, write to the Free * Software Foundation Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */PUBLIC int HTmaybekanji ARGS2( int, c1, int, c2){ if ((c2 < 33) || (c2 > 126)) return 0; if ((c1 < 33) || ((40 < c1) && (c1 < 48)) || (116 < c1)) return 0; c2 -= 32; switch(c1-32) { case 2: if ((14 < c2) && ( c2 < 26)) return 0; if ((33 < c2) && ( c2 < 42)) return 0; if ((48 < c2) && ( c2 < 60)) return 0; if ((74 < c2) && ( c2 < 82)) return 0; if ((89 < c2) && ( c2 < 94)) return 0; break; case 3: if (c2 < 16) return 0; if ((25 < c2) && ( c2 < 33)) return 0; if ((58 < c2) && ( c2 < 65)) return 0; if (90 < c2) return 0; break; case 4: if (83 < c2) return 0; break; case 5: if (86 < c2) return 0; break; case 6: if ((24 < c2) && ( c2 < 33)) return 0; if (56 < c2) return 0; break; case 7: if ((33 < c2) && ( c2 < 49)) return 0; if (81 < c2) return 0; break; case 8: if (32 < c2) return 0; break; case 47: if (51 < c2) return 0; break; case 84: if (6 < c2) return 0; break; } return 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -