static ret_t parse_if (cherokee_buffer_t *buf, const char *if_entry, size_t len_entry, cherokee_boolean_t show) { char *begin; char *end; cherokee_buffer_t token = CHEROKEE_BUF_INIT; cherokee_buffer_add_str (&token, "%if "); cherokee_buffer_add (&token, if_entry, len_entry); cherokee_buffer_add_str (&token, "%"); begin = strstr (buf->buf, token.buf); if (begin == NULL) goto error; end = strstr (begin, "%fi%"); if (end == NULL) goto error; if (show) { cherokee_buffer_remove_chunk (buf, end - buf->buf, 4); cherokee_buffer_remove_chunk (buf, begin - buf->buf, token.len); } else { cherokee_buffer_remove_chunk (buf, begin - buf->buf, (end+4) - begin); } cherokee_buffer_mrproper (&token); return ret_ok; error: cherokee_buffer_mrproper (&token); return ret_error; }
static ret_t remove_surplus (cherokee_post_t *post, cherokee_connection_t *conn) { ret_t ret; cuint_t header_len; cint_t surplus_len; /* Get the HTTP request length */ ret = cherokee_header_get_length (&conn->header, &header_len); if (unlikely(ret != ret_ok)) { return ret; } /* Get the POST length */ if (post->len > 0) { /* Plain post: read what's pointed by Content-Length */ surplus_len = MIN (conn->incoming_header.len - header_len, post->len); } else { /* Chunked: Assume everything after the header is POST */ surplus_len = conn->incoming_header.len - header_len; } if (surplus_len <= 0) { return ret_ok; } TRACE (ENTRIES, "POST surplus: moving %d bytes\n", surplus_len); /* Move the surplus */ cherokee_buffer_add (&post->header_surplus, conn->incoming_header.buf + header_len, surplus_len); cherokee_buffer_remove_chunk (&conn->incoming_header, header_len, surplus_len); TRACE (ENTRIES, "POST surplus: incoming_header is %d bytes (header len=%d)\n", conn->incoming_header.len, header_len); return ret_ok; }
static ret_t remove_header (cherokee_buffer_t *buffer, cherokee_buffer_t *header) { char *p, *s; p = strcasestr (buffer->buf, header->buf); if (p == NULL) return ret_not_found; if (p[header->len] != ':') return ret_not_found; s = strchr (p, '\r'); if (s == NULL) return ret_eof; cherokee_buffer_remove_chunk (buffer, p - buffer->buf, s-p +2); return ret_ok; }