📄 htmime.c
字号:
** Indicate in anchor. - FM */ StrAllocCopy(me->anchor->content_base, me->value); break; case miCONTENT_DISPOSITION: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Content-Disposition: '%s'\n", me->value)); if (!(me->value && *me->value)) break; /* ** Indicate in anchor. - FM */ StrAllocCopy(me->anchor->content_disposition, me->value); /* ** It's not clear yet from existing RFCs and IDs ** whether we should be looking for file;, attachment;, ** and/or inline; before the filename=value, so we'll ** just search for "filename" followed by '=' and just ** hope we get the intended value. It is purely a ** suggested name, anyway. - FM */ cp = me->anchor->content_disposition; while (*cp != '\0' && strncasecomp(cp, "filename", 8)) cp++; if (*cp == '\0') break; cp += 8; while ((*cp != '\0') && (WHITE(*cp) || *cp == '=')) cp++; if (*cp == '\0') break; while (*cp != '\0' && WHITE(*cp)) cp++; if (*cp == '\0') break; StrAllocCopy(me->anchor->SugFname, cp); if (*me->anchor->SugFname == '\"') { if ((cp = strchr((me->anchor->SugFname + 1), '\"')) != NULL) { *(cp + 1) = '\0'; HTMIME_TrimDoubleQuotes(me->anchor->SugFname); } else { FREE(me->anchor->SugFname); break; } } cp = me->anchor->SugFname; while (*cp != '\0' && !WHITE(*cp)) cp++; *cp = '\0'; if (*me->anchor->SugFname == '\0') FREE(me->anchor->SugFname); break; case miCONTENT_ENCODING: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Content-Encoding: '%s'\n", me->value)); if (!(me->value && *me->value) || !strcasecomp(me->value, "identity")) break; /* ** Convert to lowercase and indicate in anchor. - FM */ LYLowerCase(me->value); StrAllocCopy(me->anchor->content_encoding, me->value); FREE(me->compression_encoding); if (content_is_compressed(me)) { /* ** Save it to use as a flag for setting ** up a "www/compressed" target. - FM */ StrAllocCopy(me->compression_encoding, me->value); } else { /* ** Some server indicated "8bit", "7bit" or "binary" ** inappropriately. We'll ignore it. - FM */ CTRACE((tfp, " Ignoring it!\n")); } break; case miCONTENT_FEATURES: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Content-Features: '%s'\n", me->value)); break; case miCONTENT_LANGUAGE: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Content-Language: '%s'\n", me->value)); if (!(me->value && *me->value)) break; /* ** Convert to lowercase and indicate in anchor. - FM */ LYLowerCase(me->value); StrAllocCopy(me->anchor->content_language, me->value); break; case miCONTENT_LENGTH: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Content-Length: '%s'\n", me->value)); if (!(me->value && *me->value)) break; /* ** Convert to integer and indicate in anchor. - FM */ me->anchor->content_length = atoi(me->value); if (me->anchor->content_length < 0) me->anchor->content_length = 0; CTRACE((tfp, " Converted to integer: '%d'\n", me->anchor->content_length)); break; case miCONTENT_LOCATION: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Content-Location: '%s'\n", me->value)); if (!(me->value && *me->value)) break; /* ** Indicate in anchor. - FM */ StrAllocCopy(me->anchor->content_location, me->value); break; case miCONTENT_MD5: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Content-MD5: '%s'\n", me->value)); if (!(me->value && *me->value)) break; /* ** Indicate in anchor. - FM */ StrAllocCopy(me->anchor->content_md5, me->value); break; case miCONTENT_RANGE: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Content-Range: '%s'\n", me->value)); break; case miCONTENT_TRANSFER_ENCODING: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Content-Transfer-Encoding: '%s'\n", me->value)); if (!(me->value && *me->value)) break; /* ** Force the Content-Transfer-Encoding value ** to all lower case. - FM */ LYLowerCase(me->value); me->encoding = HTAtom_for(me->value); break; case miCONTENT_TYPE: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Content-Type: '%s'\n", me->value)); if (!(me->value && *me->value)) break; /* ** Force the Content-Type value to all lower case ** and strip spaces and double-quotes. - FM */ for (i = 0, j = 0; me->value[i]; i++) { if (me->value[i] != ' ' && me->value[i] != '\"') { me->value[j++] = (char) TOLOWER(me->value[i]); } } me->value[j] = '\0'; me->format = HTAtom_for(me->value); break; case miDATE: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Date: '%s'\n", me->value)); if (!(me->value && *me->value)) break; /* ** Indicate in anchor. - FM */ StrAllocCopy(me->anchor->date, me->value); break; case miETAG: /* Do not trim double quotes: * an entity tag consists of an opaque quoted string, * possibly prefixed by a weakness indicator. */ CTRACE((tfp, "HTMIME: PICKED UP ETag: %s\n", me->value)); if (!(me->value && *me->value)) break; /* ** Indicate in anchor. - FM */ StrAllocCopy(me->anchor->ETag, me->value); break; case miEXPIRES: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Expires: '%s'\n", me->value)); if (!(me->value && *me->value)) break; /* ** Indicate in anchor. - FM */ StrAllocCopy(me->anchor->expires, me->value); break; case miKEEP_ALIVE: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Keep-Alive: '%s'\n", me->value)); break; case miLAST_MODIFIED: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Last-Modified: '%s'\n", me->value)); if (!(me->value && *me->value)) break; /* ** Indicate in anchor. - FM */ StrAllocCopy(me->anchor->last_modified, me->value); break; case miLINK: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Link: '%s'\n", me->value)); break; case miLOCATION: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Location: '%s'\n", me->value)); if (me->pickup_redirection && !me->location) { StrAllocCopy(me->location, me->value); } else { CTRACE((tfp, "HTMIME: *** Ignoring Location!\n")); } break; case miPRAGMA: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Pragma: '%s'\n", me->value)); if (!(me->value && *me->value)) break; /* ** Check whether to set no_cache for the anchor. - FM */ if (!strcmp(me->value, "no-cache")) me->anchor->no_cache = TRUE; break; case miPROXY_AUTHENTICATE: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Proxy-Authenticate: '%s'\n", me->value)); break; case miPUBLIC: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Public: '%s'\n", me->value)); break; case miREFRESH: /* nonstandard: Netscape */ HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Refresh: '%s'\n", me->value)); StrAllocCopy(me->refresh_url, me->value); break; case miRETRY_AFTER: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Retry-After: '%s'\n", me->value)); break; case miSAFE: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Safe: '%s'\n", me->value)); if (!(me->value && *me->value)) break; /* ** Indicate in anchor if "YES" or "TRUE". - FM */ if (!strcasecomp(me->value, "YES") || !strcasecomp(me->value, "TRUE")) { me->anchor->safe = TRUE; } else if (!strcasecomp(me->value, "NO") || !strcasecomp(me->value, "FALSE")) { /* ** If server explicitly tells us that it has changed ** its mind, reset flag in anchor. - kw */ me->anchor->safe = FALSE; } break; case miSERVER: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Server: '%s'\n", me->value)); if (!(me->value && *me->value)) break; /* ** Indicate in anchor. - FM */ StrAllocCopy(me->anchor->server, me->value); break; case miSET_COOKIE1: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Set-Cookie: '%s'\n", me->value)); if (me->set_cookie == NULL) { StrAllocCopy(me->set_cookie, me->value); } else { StrAllocCat(me->set_cookie, ", "); StrAllocCat(me->set_cookie, me->value); } break; case miSET_COOKIE2: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Set-Cookie2: '%s'\n", me->value)); if (me->set_cookie2 == NULL) { StrAllocCopy(me->set_cookie2, me->value); } else { StrAllocCat(me->set_cookie2, ", "); StrAllocCat(me->set_cookie2, me->value); } break; case miTITLE: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Title: '%s'\n", me->value)); break; case miTRANSFER_ENCODING: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Transfer-Encoding: '%s'\n", me->value)); break; case miUPGRADE: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Upgrade: '%s'\n", me->value)); break; case miURI: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP URI: '%s'\n", me->value)); break; case miVARY: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Vary: '%s'\n", me->value)); break; case miVIA: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Via: '%s'\n", me->value)); break; case miWARNING: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP Warning: '%s'\n", me->value)); break; case miWWW_AUTHENTICATE: HTMIME_TrimDoubleQuotes(me->value); CTRACE((tfp, "HTMIME: PICKED UP WWW-Authenticate: '%s'\n", me->value)); break; default: /* Should never get here */ return HT_ERROR; } return HT_OK;}/*_________________________________________________________________________**** A C T I O N R O U T I N E S*//* Character handling** ------------------**** This is a FSM parser. It ignores field names it does not understand.** Folded header fields are recognized. Lines without a fieldname at** the beginning (that are not folded continuation lines) are ignored** as unknown field names. Fields with empty values are not picked up.*/PRIVATE void HTMIME_put_character ARGS2( HTStream *, me, char, c){ if (me->state == MIME_TRANSPARENT) { (*me->targetClass.put_character)(me->target, c);/* MUST BE FAST */ return; } /* ** This slightly simple conversion just strips CR and turns LF to ** newline. On unix LF is \n but on Mac \n is CR for example. ** See NetToText for an implementation which preserves single CR or LF. */ if (me->net_ascii) { /* ** <sigh> This is evidence that at one time, this code supported ** local character sets other than ASCII. But there is so much ** code in HTTP.c that depends on line_buffer's having been ** translated to local character set that I needed to put the ** FROMASCII translation there, leaving this translation purely ** destructive. -- gil */ /* S/390 -- gil -- 0118 */#ifndef NOT_ASCII c = FROMASCII(c);#endif /* NOT_ASCII */ if (c == CR) return; else if (c == LF) c = '\n'; } switch(me->state) { case MIME_IGNORE: return; case MIME_TRANSPARENT: /* Not reached see above */ (*me->targetClass.put_character)(me->target, c); return; case MIME_NET_ASCII: (*me->targetClass.put_character)(me->target, c); /* MUST BE FAST */ return; case miNEWLINE: if (c != '\n' && WHITE(c)) { /* Folded line */ me->state = me->fold_state; /* pop state before newline */ if (me->state == miGET_VALUE && me->value_pointer && me->value_pointer != me->value && !WHITE(*(me->value_pointer-1))) { c = ' '; goto GET_VALUE; /* will add space to value if it fits - kw */ } break; } else if (me->fold_state == miGET_VALUE) { /* Got a field, and now we know it's complete - so * act on it. - kw */ dispatchField(me); } /* FALLTHRU */ case miBEGINNING_OF_LINE: me->net_ascii = YES; switch (c) { case 'a': case 'A': me->state = miA; CTRACE((tfp, "HTMIME: Got 'A' at beginning of line, state now A\n")); break; case 'c': case 'C': me->state = miC; CTRACE((tfp, "HTMIME: Got 'C' at beginning of line, state now C\n")); break; case 'd': case 'D': me->check_pointer = "ate:"; me->if_ok = miDATE; me->state = miCHECK; CTRACE((tfp, "HTMIME: Got 'D' at beginning of line, checking for 'ate:'\n")); break; case 'e': case 'E': me->state = miE; CTRACE((tfp, "HTMIME: Got 'E' at beginning of line, state now E\n")); break; case 'k': case 'K': me->check_pointer = "eep-alive:"; me->if_ok = miKEEP_ALIVE; me->state = miCHECK; CTRACE((tfp, "HTMIME: Got 'K' at beginning of line, checking for 'eep-alive:'\n")); break; case 'l': case 'L': me->state = miL; CTRACE((tfp, "HTMIME: Got 'L' at beginning of line, state now L\n")); break; case 'p': case 'P': me->state = miP; CTRACE((tfp, "HTMIME: Got 'P' at beginning of line, state now P\n")); break; case 'r': case 'R': me->state = miR; CTRACE((tfp, "HTMIME: Got 'R' at beginning of line, state now R\n")); break; case 's': case 'S': me->state = miS; CTRACE((tfp, "HTMIME: Got 'S' at beginning of line, state now S\n")); break; case 't': case 'T': me->state = miT; CTRACE((tfp, "HTMIME: Got 'T' at beginning of line, state now T\n")); break; case 'u': case 'U': me->state = miU; CTRACE((tfp, "HTMIME: Got 'U' at beginning of line, state now U\n")); break; case 'v': case 'V': me->state = miV; CTRACE((tfp, "HTMIME: Got 'V' at beginning of line, state now V\n")); break; case 'w': case 'W': me->state = miW; CTRACE((tfp, "HTMIME: Got 'W' at beginning of line, state now W\n")); break; case '\n': /* Blank line: End of Header! */ { me->net_ascii = NO; pumpData(me); } break; default: goto bad_field_name; } /* switch on character */ break; case miA: /* Check for 'c','g' or 'l' */ switch (c) { case 'c': case 'C': me->check_pointer = "cept-ranges:"; me->if_ok = miACCEPT_RANGES; me->state = miCHECK; CTRACE((tfp, "HTMIME: Was A, found C, checking for 'cept-ranges:'\n")); break; case 'g': case 'G': me->check_pointer = "e:"; me->if_ok = miAGE; me->state = miCHECK; CTRACE((tfp, "HTMIME: Was A, found G, checking for 'e:'\n")); break; case 'l': case 'L': me->state = miAL; CTRACE((tfp, "HTMIME: Was A, found L, state now AL'\n")); break; default: CTRACE((tfp, "HTMIME: Bad character `%c' found where `%s' expected\n", c, "'g' or 'l'")); goto bad_field_name; } /* switch on character */ break; case miAL: /* Check for 'l' or 't' */ switch (c) { case 'l': case 'L': me->check_pointer = "ow:"; me->if_ok = miALLOW; me->state = miCHECK; CTRACE((tfp, "HTMIME: Was AL, found L, checking for 'ow:'\n")); break; case 't': case 'T': me->check_pointer = "ernates:";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -