static int check_header(const struct strbuf *line, struct strbuf *hdr_data[], int overwrite) { int i, ret = 0, len; struct strbuf sb = STRBUF_INIT; /* search for the interesting parts */ for (i = 0; header[i]; i++) { int len = strlen(header[i]); if ((!hdr_data[i] || overwrite) && cmp_header(line, header[i])) { /* Unwrap inline B and Q encoding, and optionally * normalize the meta information to utf8. */ strbuf_add(&sb, line->buf + len + 2, line->len - len - 2); decode_header(&sb); handle_header(&hdr_data[i], &sb); ret = 1; goto check_header_out; } } /* Content stuff */ if (cmp_header(line, "Content-Type")) { len = strlen("Content-Type: "); strbuf_add(&sb, line->buf + len, line->len - len); decode_header(&sb); strbuf_insert(&sb, 0, "Content-Type: ", len); handle_content_type(&sb); ret = 1; goto check_header_out; } if (cmp_header(line, "Content-Transfer-Encoding")) { len = strlen("Content-Transfer-Encoding: "); strbuf_add(&sb, line->buf + len, line->len - len); decode_header(&sb); handle_content_transfer_encoding(&sb); ret = 1; goto check_header_out; } /* for inbody stuff */ if (!prefixcmp(line->buf, ">From") && isspace(line->buf[5])) { ret = 1; /* Should this return 0? */ goto check_header_out; } if (!prefixcmp(line->buf, "[PATCH]") && isspace(line->buf[7])) { for (i = 0; header[i]; i++) { if (!memcmp("Subject", header[i], 7)) { handle_header(&hdr_data[i], line); ret = 1; goto check_header_out; } } } check_header_out: strbuf_release(&sb); return ret; }
static int check_header(struct mailinfo *mi, const struct strbuf *line, struct strbuf *hdr_data[], int overwrite) { int i, ret = 0, len; struct strbuf sb = STRBUF_INIT; /* search for the interesting parts */ for (i = 0; header[i]; i++) { int len = strlen(header[i]); if ((!hdr_data[i] || overwrite) && cmp_header(line, header[i])) { /* Unwrap inline B and Q encoding, and optionally * normalize the meta information to utf8. */ strbuf_add(&sb, line->buf + len + 2, line->len - len - 2); decode_header(mi, &sb); handle_header(&hdr_data[i], &sb); ret = 1; goto check_header_out; } } /* Content stuff */ if (cmp_header(line, "Content-Type")) { len = strlen("Content-Type: "); strbuf_add(&sb, line->buf + len, line->len - len); decode_header(mi, &sb); strbuf_insert(&sb, 0, "Content-Type: ", len); handle_content_type(mi, &sb); ret = 1; goto check_header_out; } if (cmp_header(line, "Content-Transfer-Encoding")) { len = strlen("Content-Transfer-Encoding: "); strbuf_add(&sb, line->buf + len, line->len - len); decode_header(mi, &sb); handle_content_transfer_encoding(mi, &sb); ret = 1; goto check_header_out; } if (cmp_header(line, "Message-Id")) { len = strlen("Message-Id: "); strbuf_add(&sb, line->buf + len, line->len - len); decode_header(mi, &sb); if (mi->add_message_id) mi->message_id = strbuf_detach(&sb, NULL); ret = 1; goto check_header_out; } check_header_out: strbuf_release(&sb); return ret; }
static int check_header(char *line, unsigned linesize, char **hdr_data, int overwrite) { int i; /* search for the interesting parts */ for (i = 0; header[i]; i++) { int len = strlen(header[i]); if ((!hdr_data[i] || overwrite) && !strncasecmp(line, header[i], len) && line[len] == ':' && isspace(line[len + 1])) { /* Unwrap inline B and Q encoding, and optionally * normalize the meta information to utf8. */ decode_header(line + len + 2, linesize - len - 2); hdr_data[i] = xmalloc(1000 * sizeof(char)); if (! handle_header(line, hdr_data[i], len + 2)) { return 1; } } } /* Content stuff */ if (!strncasecmp(line, "Content-Type", 12) && line[12] == ':' && isspace(line[12 + 1])) { decode_header(line + 12 + 2, linesize - 12 - 2); if (! handle_content_type(line)) { return 1; } } if (!strncasecmp(line, "Content-Transfer-Encoding", 25) && line[25] == ':' && isspace(line[25 + 1])) { decode_header(line + 25 + 2, linesize - 25 - 2); if (! handle_content_transfer_encoding(line)) { return 1; } } /* for inbody stuff */ if (!memcmp(">From", line, 5) && isspace(line[5])) return 1; if (!memcmp("[PATCH]", line, 7) && isspace(line[7])) { for (i = 0; header[i]; i++) { if (!memcmp("Subject: ", header[i], 9)) { if (! handle_header(line, hdr_data[i], 0)) { return 1; } } } } /* no match */ return 0; }
int static_file_handle(request_t *req, response_t *resp, handler_ctx_t *ctx) { mod_static_conf_t *conf; char path[2048]; int fd = -1, res, use_301; struct stat st; size_t len, pathlen, filesize, fileoffset; ctx_state_t val; conf = (mod_static_conf_t*) ctx->conf; len = strlen(conf->root); strncpy(path, conf->root, 2048); if (path[len - 1] == '/') { path[len - 1] = '\0'; } if (req->path[0] != '/') { return response_send_status(resp, STATUS_BAD_REQUEST); } strncat(path, req->path, 2048 - len); debug("Request path: %s, real file path: %s", req->path, path); res = try_open_file(path, &fd, &st); if (res < 0) { return static_file_handle_error(resp, fd); } else if (res > 0) { // Is a directory, try index files. pathlen = strlen(path); use_301 = 0; if (path[pathlen - 1] != '/') { path[pathlen] = '/'; path[pathlen + 1] = '\0'; pathlen++; use_301 = 1; } //for (i = 0; i < 10 && res != 0 && conf->index[i] != NULL; i++) { // path[pathlen] = '\0'; // strncat(path, conf->index[i], 2048 - pathlen); // res = try_open_file(path, &fd, &st); //} path[pathlen] = '\0'; strncat(path, conf->index, 2048 - pathlen); res = try_open_file(path, &fd, &st); path[pathlen] = '\0'; if (res != 0) { if (conf->enable_list_dir) { if (use_301) { // TODO Support HTTPS snprintf(path, 2048, "http://%s%s/", req->host, req->path); response_set_header(resp, "Location", path); resp->status = STATUS_MOVED; resp->content_length = 0; response_send_headers(resp, NULL); return HANDLER_DONE; } show_hidden_file = conf->show_hidden_file; return static_file_listdir(resp, req->path, path); } else { return static_file_handle_error(resp, fd); } } } fileoffset = 0; filesize = st.st_size; res = handle_range(req, resp, &fileoffset, &filesize); if (res < 0) { resp->status = STATUS_OK; } else if (res == 0) { resp->status = STATUS_PARTIAL_CONTENT; } else { return response_send_status(resp, STATUS_RANGE_NOT_SATISFIABLE); } resp->content_length = filesize; handle_content_type(resp, path); if (handle_cache(req, resp, &st, conf)) { return response_send_status(resp, STATUS_NOT_MODIFIED); } val.as_int = fd; context_push(ctx, val); val.as_long = fileoffset; context_push(ctx, val); val.as_long = filesize; context_push(ctx, val); debug("sending headers"); response_send_headers(resp, static_file_write_content); return HANDLER_UNFISHED; }