* - then, if there are no parameters on type, add the default charset
* - return type
*/
-static const char *make_content_type(request_rec *r, const char *type) {
+static const char *make_content_type(request_rec *r, const char *type)
+{
static const char *needcset[] = {
"text/plain",
"text/html",
NULL };
const char **pcset;
- core_dir_config *conf = (core_dir_config *)ap_get_module_config(
- r->per_dir_config, &core_module);
+ core_dir_config *conf =
+ (core_dir_config *)ap_get_module_config(r->per_dir_config,
+ &core_module);
- if (!type)
- type = ap_default_type(r);
- if (conf->add_default_charset != ADD_DEFAULT_CHARSET_ON)
- return type;
+ if (!type) {
+ type = ap_default_type(r);
+ }
+ if (conf->add_default_charset != ADD_DEFAULT_CHARSET_ON) {
+ return type;
+ }
if (ap_strcasestr(type, "charset=") != NULL) {
/* already has parameter, do nothing */
/* XXX we don't check the validity */
;
- } else {
+ }
+ else {
/* see if it makes sense to add the charset. At present,
* we only add it if the Content-type is one of needcset[]
*/
- for (pcset = needcset; *pcset ; pcset++)
+ for (pcset = needcset; *pcset ; pcset++) {
if (ap_strcasestr(type, *pcset) != NULL) {
type = apr_pstrcat(r->pool, type, "; charset=",
- conf->add_default_charset_name, NULL);
+ conf->add_default_charset_name, NULL);
break;
}
+ }
}
return type;
}
*/
(void) checked_bputstrs(r, CRLF "--", r->boundary, "--" CRLF,
NULL);
- } else {
+ }
+ else {
*tlength += 4 + strlen(r->boundary) + 4;
}
}
*
* Note that the condition evaluation order is extremely important.
*/
- if ((r->connection->keepalive != -1) &&
- ((r->status == HTTP_NOT_MODIFIED) ||
- (r->status == HTTP_NO_CONTENT) ||
- r->header_only ||
- apr_table_get(r->headers_out, "Content-Length") ||
- ap_find_last_token(r->pool,
- apr_table_get(r->headers_out, "Transfer-Encoding"),
- "chunked") ||
- ((r->proto_num >= HTTP_VERSION(1,1)) &&
- (r->chunked = 1))) && /* THIS CODE IS CORRECT, see comment above. */
- r->server->keep_alive &&
- (r->server->keep_alive_timeout > 0) &&
- ((r->server->keep_alive_max == 0) ||
- (r->server->keep_alive_max > r->connection->keepalives)) &&
- !ap_status_drops_connection(r->status) &&
- !wimpy &&
- !ap_find_token(r->pool, conn, "close") &&
- (!apr_table_get(r->subprocess_env, "nokeepalive") ||
- apr_table_get(r->headers_in, "Via")) &&
- ((ka_sent = ap_find_token(r->pool, conn, "keep-alive")) ||
- (r->proto_num >= HTTP_VERSION(1,1)))
- ) {
+ if ((r->connection->keepalive != -1)
+ && ((r->status == HTTP_NOT_MODIFIED)
+ || (r->status == HTTP_NO_CONTENT)
+ || r->header_only
+ || apr_table_get(r->headers_out, "Content-Length")
+ || ap_find_last_token(r->pool,
+ apr_table_get(r->headers_out,
+ "Transfer-Encoding"),
+ "chunked")
+ || ((r->proto_num >= HTTP_VERSION(1,1))
+ && (r->chunked = 1))) /* THIS CODE IS CORRECT, see comment above. */
+ && r->server->keep_alive
+ && (r->server->keep_alive_timeout > 0)
+ && ((r->server->keep_alive_max == 0)
+ || (r->server->keep_alive_max > r->connection->keepalives))
+ && !ap_status_drops_connection(r->status)
+ && !wimpy
+ && !ap_find_token(r->pool, conn, "close")
+ && (!apr_table_get(r->subprocess_env, "nokeepalive")
+ || apr_table_get(r->headers_in, "Via"))
+ && ((ka_sent = ap_find_token(r->pool, conn, "keep-alive"))
+ || (r->proto_num >= HTTP_VERSION(1,1)))) {
int left = r->server->keep_alive_max - r->connection->keepalives;
r->connection->keepalive = 1;
* respond with a status of 412 (Precondition Failed).
*/
if ((if_match = apr_table_get(r->headers_in, "If-Match")) != NULL) {
- if (if_match[0] != '*' &&
- (etag == NULL || etag[0] == 'W' ||
- !ap_find_list_item(r->pool, if_match, etag))) {
+ if (if_match[0] != '*'
+ && (etag == NULL || etag[0] == 'W'
+ || !ap_find_list_item(r->pool, if_match, etag))) {
return HTTP_PRECONDITION_FAILED;
}
}
if_nonematch = apr_table_get(r->headers_in, "If-None-Match");
if (if_nonematch != NULL) {
if (r->method_number == M_GET) {
- if (if_nonematch[0] == '*')
- return HTTP_NOT_MODIFIED;
+ if (if_nonematch[0] == '*') {
+ return HTTP_NOT_MODIFIED;
+ }
if (etag != NULL) {
if (apr_table_get(r->headers_in, "Range")) {
- if (etag[0] != 'W' &&
- ap_find_list_item(r->pool, if_nonematch, etag)) {
+ if (etag[0] != 'W'
+ && ap_find_list_item(r->pool, if_nonematch, etag)) {
return HTTP_NOT_MODIFIED;
}
}
}
}
}
- else if (if_nonematch[0] == '*' ||
- (etag != NULL &&
- ap_find_list_item(r->pool, if_nonematch, etag))) {
+ else if (if_nonematch[0] == '*'
+ || (etag != NULL
+ && ap_find_list_item(r->pool, if_nonematch, etag))) {
return HTTP_PRECONDITION_FAILED;
}
}
*/
else if ((r->method_number == M_GET)
&& ((if_modified_since =
- apr_table_get(r->headers_in, "If-Modified-Since")) != NULL)) {
+ apr_table_get(r->headers_in,
+ "If-Modified-Since")) != NULL)) {
apr_time_t ims = ap_parseHTTPdate(if_modified_since);
if ((ims >= mtime) && (ims <= r->request_time)) {
* would be incorrect.
*/
- weak = ((r->request_time - r->mtime > APR_USEC_PER_SEC) && !force_weak) ? "" : "W/";
+ weak = ((r->request_time - r->mtime > APR_USEC_PER_SEC)
+ && !force_weak) ? "" : "W/";
if (r->finfo.protection != 0) {
etag = apr_psprintf(r->pool,
- "%s\"%lx-%lx-%lx\"", weak,
- (unsigned long) r->finfo.inode,
- (unsigned long) r->finfo.size,
- (unsigned long) r->mtime);
+ "%s\"%lx-%lx-%lx\"", weak,
+ (unsigned long) r->finfo.inode,
+ (unsigned long) r->finfo.size,
+ (unsigned long) r->mtime);
}
else {
etag = apr_psprintf(r->pool, "%s\"%lx\"", weak,
- (unsigned long) r->mtime);
+ (unsigned long) r->mtime);
}
return etag;
* Turn a known method number into a name. Doesn't work for
* extension methods, obviously.
*/
-API_EXPORT(const char *) ap_method_name_of(int methnum) {
+API_EXPORT(const char *) ap_method_name_of(int methnum)
+{
static const char *AP_HTTP_METHODS[METHODS] = { NULL };
/*
* it much easier to check field values for exact matches, and
* saves memory as well. Terminate string at end of line.
*/
- while (pos > (s + 1) && (*(pos - 1) == ' ' || *(pos - 1) == '\t')) {
+ while (pos > (s + 1) && (*(pos - 1) == ' '
+ || *(pos - 1) == '\t')) {
--pos; /* trim extra trailing spaces or tabs */
--total; /* but not one at the beginning of line */
++n;
--total;
++n;
}
- else
- break; /* if not, input line exceeded buffer size */
-
+ else {
+ break; /* if not, input line exceeded buffer size */
+ }
/* Continue appending if line folding is desired and
* the last line was not empty and we have room in the buffer and
* the next line begins with a continuation character.
*/
- } while (fold && (retval != 1) && (n > 1)
- && (next = ap_blookc(in))
- && ((next == ' ') || (next == '\t')));
+ } while (fold
+ && (retval != 1) && (n > 1)
+ && (next = ap_blookc(in))
+ && ((next == ' ') || (next == '\t')));
#ifdef APACHE_XLATE
/* restore translation handle */
if (r->method_number == M_CONNECT) {
status = ap_parse_hostinfo_components(r->pool, uri, &r->parsed_uri);
- } else {
+ }
+ else {
/* Simple syntax Errors in URLs are trapped by parse_uri_components(). */
status = ap_parse_uri_components(r->pool, uri, &r->parsed_uri);
}
if (r->parsed_uri.scheme
&& !strcasecmp(r->parsed_uri.scheme, ap_http_method(r))) {
r->hostname = r->parsed_uri.hostname;
- } else if (r->method_number == M_CONNECT) {
+ }
+ else if (r->method_number == M_CONNECT) {
r->hostname = r->parsed_uri.hostname;
}
r->args = r->parsed_uri.query;
(++fields_read > r->server->limit_req_fields)) {
r->status = HTTP_BAD_REQUEST;
apr_table_setn(r->notes, "error-notes",
- "The number of request header fields exceeds "
- "this server's limit.<P>\n");
+ "The number of request header fields exceeds "
+ "this server's limit.<P>\n");
return;
}
/* getline returns (size of max buffer - 1) if it fills up the
*/
if (len > r->server->limit_req_fieldsize) {
r->status = HTTP_BAD_REQUEST;
- apr_table_setn(r->notes, "error-notes", apr_pstrcat(r->pool,
- "Size of a request header field exceeds server limit.<P>\n"
- "<PRE>\n", ap_escape_html(r->pool, field), "</PRE>\n", NULL));
+ apr_table_setn(r->notes, "error-notes",
+ apr_pstrcat(r->pool,
+ "Size of a request header field "
+ "exceeds server limit.<P>\n"
+ "<PRE>\n",
+ ap_escape_html(r->pool, field),
+ "</PRE>\n", NULL));
return;
}
copy = apr_palloc(r->pool, len + 1);
if (!(value = strchr(copy, ':'))) { /* Find the colon separator */
r->status = HTTP_BAD_REQUEST; /* or abort the bad request */
- apr_table_setn(r->notes, "error-notes", apr_pstrcat(r->pool,
- "Request header field is missing colon separator.<P>\n"
- "<PRE>\n", ap_escape_html(r->pool, copy), "</PRE>\n", NULL));
+ apr_table_setn(r->notes, "error-notes",
+ apr_pstrcat(r->pool,
+ "Request header field is missing "
+ "colon separator.<P>\n"
+ "<PRE>\n",
+ ap_escape_html(r->pool, copy),
+ "</PRE>\n", NULL));
return;
}
*value = '\0';
++value;
- while (*value == ' ' || *value == '\t')
+ while (*value == ' ' || *value == '\t') {
++value; /* Skip to start of value */
+ }
apr_table_addn(tmp_headers, copy, value);
}
if (!read_request_line(r)) {
if (r->status == HTTP_REQUEST_URI_TOO_LARGE) {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
- "request failed: URI too long");
+ "request failed: URI too long");
ap_send_error_response(r, 0);
ap_run_log_transaction(r);
return r;
}
if (r->connection->keptalive) {
ap_bsetopt(r->connection->client, BO_TIMEOUT,
- &r->server->timeout);
+ &r->server->timeout);
}
if (!r->assbackwards) {
get_mime_headers(r);
if (r->status != HTTP_REQUEST_TIME_OUT) {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
- "request failed: error reading the headers");
+ "request failed: error reading the headers");
ap_send_error_response(r, 0);
ap_run_log_transaction(r);
return r;
if (!ap_auth_name(r)) {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR,
- 0, r, "need AuthName: %s", r->uri);
+ 0, r, "need AuthName: %s", r->uri);
return HTTP_INTERNAL_SERVER_ERROR;
}
if (strcasecmp(ap_getword(r->pool, &auth_line, ' '), "Basic")) {
/* Client tried to authenticate using wrong auth scheme */
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
- "client used wrong authentication scheme: %s", r->uri);
+ "client used wrong authentication scheme: %s", r->uri);
ap_note_basic_auth_failure(r);
return HTTP_UNAUTHORIZED;
}
- while (*auth_line== ' ' || *auth_line== '\t')
+ while (*auth_line== ' ' || *auth_line== '\t') {
auth_line++;
+ }
t = ap_pbase64decode(r->pool, auth_line);
/* Note that this allocation has to be made from r->connection->pool
status -= 100;
if (status < 100) {
pos = (status + shortcut[i]);
- if (pos < shortcut[i + 1])
+ if (pos < shortcut[i + 1]) {
return pos;
- else
+ }
+ else {
return LEVEL_500; /* status unknown (falls in gap) */
+ }
}
}
return LEVEL_500; /* 600 or above is also illegal */
protocol = "HTTP/1.0";
r->connection->keepalive = -1;
}
- else
+ else {
protocol = AP_SERVER_PROTOCOL;
+ }
#ifdef APACHE_XLATE
{ AP_PUSH_OUTPUTCONVERSION_STATE(r->connection->client,
}
}
if (i == values->nelts) { /* if not found */
- *(char **)apr_push_array(values) = start;
+ *(char **)apr_push_array(values) = start;
}
} while (*e != '\0');
if (varies->nelts > 0) {
apr_table_setn(r->headers_out, "Vary",
- apr_array_pstrcat(r->pool, varies, ','));
+ apr_array_pstrcat(r->pool, varies, ','));
}
}
ap_add_filter("CHUNK", NULL, r);
}
- if (r->byterange > 1)
+ if (r->byterange > 1) {
apr_table_setn(r->headers_out, "Content-Type",
- apr_pstrcat(r->pool, "multipart", use_range_x(r) ? "/x-" : "/",
- "byteranges; boundary=", r->boundary, NULL));
- else apr_table_setn(r->headers_out, "Content-Type", make_content_type(r,
- r->content_type));
+ apr_pstrcat(r->pool, "multipart",
+ use_range_x(r) ? "/x-" : "/",
+ "byteranges; boundary=",
+ r->boundary, NULL));
+ }
+ else {
+ apr_table_setn(r->headers_out, "Content-Type",
+ make_content_type(r, r->content_type));
+ }
- if (r->content_encoding)
- apr_table_setn(r->headers_out, "Content-Encoding", r->content_encoding);
+ if (r->content_encoding) {
+ apr_table_setn(r->headers_out, "Content-Encoding",
+ r->content_encoding);
+ }
if (r->content_languages && r->content_languages->nelts) {
for (i = 0; i < r->content_languages->nelts; ++i) {
apr_table_mergen(r->headers_out, "Content-Language",
- ((char **) (r->content_languages->elts))[i]);
+ ((char **) (r->content_languages->elts))[i]);
}
}
- else if (r->content_language)
- apr_table_setn(r->headers_out, "Content-Language", r->content_language);
+ else if (r->content_language) {
+ apr_table_setn(r->headers_out, "Content-Language",
+ r->content_language);
+ }
/*
* Control cachability for non-cachable responses if not already set by
}
apr_table_do((int (*) (void *, const char *, const char *)) ap_send_header_field,
- (void *) r, r->headers_out, NULL);
+ (void *) r, r->headers_out, NULL);
terminate_header(r);
-
ap_bsetopt(r->connection->client, BO_BYTECT, &zero);
r->sent_bodyct = 1; /* Whatever follows is real body stuff... */
/* Set buffer flags for the body */
- if (r->chunked)
+ if (r->chunked) {
ap_bsetflag(r->connection->client, B_CHUNK, 1);
+ }
#ifdef APACHE_XLATE
AP_POP_OUTPUTCONVERSION_STATE(r->connection->client); }
#endif /*APACHE_XLATE*/
if (tenc) {
if (strcasecmp(tenc, "chunked")) {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
- "Unknown Transfer-Encoding %s", tenc);
+ "Unknown Transfer-Encoding %s", tenc);
return HTTP_NOT_IMPLEMENTED;
}
if (r->read_body == REQUEST_CHUNKED_ERROR) {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
- "chunked Transfer-Encoding forbidden: %s", r->uri);
+ "chunked Transfer-Encoding forbidden: %s", r->uri);
return (lenp) ? HTTP_BAD_REQUEST : HTTP_LENGTH_REQUIRED;
}
else if (lenp) {
const char *pos = lenp;
- while (apr_isdigit(*pos) || apr_isspace(*pos))
+ while (apr_isdigit(*pos) || apr_isspace(*pos)) {
++pos;
+ }
if (*pos != '\0') {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
- "Invalid Content-Length %s", lenp);
+ "Invalid Content-Length %s", lenp);
return HTTP_BAD_REQUEST;
}
if ((r->read_body == REQUEST_NO_BODY) &&
(r->read_chunked || (r->remaining > 0))) {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
- "%s with body is not allowed for %s", r->method, r->uri);
+ "%s with body is not allowed for %s", r->method, r->uri);
return HTTP_REQUEST_ENTITY_TOO_LARGE;
}
max_body = ap_get_limit_req_body(r);
if (max_body && (r->remaining > max_body)) {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
- "Request content-length of %s is larger than the configured "
- "limit of %lu", lenp, max_body);
+ "Request content-length of %s is larger than "
+ "the configured limit of %lu", lenp, max_body);
return HTTP_REQUEST_ENTITY_TOO_LARGE;
}
while (apr_isxdigit(*b)) {
int xvalue = 0;
- if (*b >= '0' && *b <= '9')
+ if (*b >= '0' && *b <= '9') {
xvalue = *b - '0';
- else if (*b >= 'A' && *b <= 'F')
+ }
+ else if (*b >= 'A' && *b <= 'F') {
xvalue = *b - 'A' + 0xa;
- else if (*b >= 'a' && *b <= 'f')
+ }
+ else if (*b >= 'a' && *b <= 'f') {
xvalue = *b - 'a' + 0xa;
+ }
chunksize = (chunksize << 4) | xvalue;
++b;
max_body = ap_get_limit_req_body(r);
if (max_body && (r->read_length > max_body)) {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
- "Chunked request body is larger than the configured limit of %lu",
- max_body);
+ "Chunked request body is larger than the "
+ "configured limit of %lu", max_body);
r->connection->keepalive = -1;
return -1;
}
apr_snprintf(buffer, bufsiz, "%ld", r->read_length);
apr_table_unset(r->headers_in, "Transfer-Encoding");
apr_table_setn(r->headers_in, "Content-Length",
- apr_pstrdup(r->pool, buffer));
+ apr_pstrdup(r->pool, buffer));
return 0;
}
r->remaining = -1; /* Indicate footers in-progress */
if (r->remaining == -1) { /* reading footers until empty line */
len_read = chunk_start;
- while ((bufsiz > 1) && ((len_read =
- getline(buffer, bufsiz, r->connection->client, 1)) > 0)) {
+ while ((bufsiz > 1)
+ && ((len_read = getline(buffer, bufsiz, r->connection->client,
+ 1)) > 0)) {
if (len_read != (bufsiz - 1)) {
buffer[len_read++] = CR; /* Restore footer line end */
}
while (!r->connection->aborted) {
- if ((length > 0) && (total_bytes_sent + IOBUFSIZE) > length)
+ if ((length > 0) && (total_bytes_sent + IOBUFSIZE) > length) {
n = length - total_bytes_sent;
- else
+ }
+ else {
n = IOBUFSIZE;
+ }
do {
rv = apr_read(fd, buf, &n);
}
o = ap_rwrite(buf, n, r);
- if (o < 0)
+ if (o < 0) {
break;
+ }
total_bytes_sent += o;
}
ap_bucket *b;
char c2 = (char)c;
- if (r->connection->aborted)
- return EOF;
+ if (r->connection->aborted) {
+ return EOF;
+ }
bb = ap_brigade_create(r->pool);
b = ap_bucket_create_transient(&c2, 1);
if (status == HTTP_NOT_MODIFIED) {
if (!apr_is_empty_table(r->err_headers_out))
r->headers_out = apr_overlay_tables(r->pool, r->err_headers_out,
- r->headers_out);
+ r->headers_out);
ap_basic_http_header(r);
ap_set_keepalive(r);
case HTTP_BAD_REQUEST:
ap_rputs("Your browser sent a request that "
"this server could not understand.<P>\n", r);
- if ((error_notes = apr_table_get(r->notes, "error-notes")) != NULL) {
+ if ((error_notes = apr_table_get(r->notes, "error-notes"))
+ != NULL) {
ap_rvputs(r, error_notes, "<P>\n", NULL);
}
break;
case HTTP_LENGTH_REQUIRED:
ap_rvputs(r, "A request of the requested method ", r->method,
" requires a valid Content-length.<P>\n", NULL);
- if ((error_notes = apr_table_get(r->notes, "error-notes")) != NULL) {
+ if ((error_notes = apr_table_get(r->notes, "error-notes"))
+ != NULL) {
ap_rvputs(r, error_notes, "<P>\n", NULL);
}
break;
ap_rvputs(r, ap_escape_html(r->pool, r->method), " to ",
ap_escape_html(r->pool, r->uri),
" not supported.<P>\n", NULL);
- if ((error_notes = apr_table_get(r->notes, "error-notes")) != NULL) {
+ if ((error_notes = apr_table_get(r->notes, "error-notes"))
+ != NULL) {
ap_rvputs(r, error_notes, "<P>\n", NULL);
}
break;
case HTTP_BAD_GATEWAY:
ap_rputs("The proxy server received an invalid" CRLF
"response from an upstream server.<P>" CRLF, r);
- if ((error_notes = apr_table_get(r->notes, "error-notes")) != NULL) {
+ if ((error_notes = apr_table_get(r->notes, "error-notes"))
+ != NULL) {
ap_rvputs(r, error_notes, "<P>\n", NULL);
}
break;
case HTTP_REQUEST_URI_TOO_LARGE:
ap_rputs("The requested URL's length exceeds the capacity\n"
"limit for this server.<P>\n", r);
- if ((error_notes = apr_table_get(r->notes, "error-notes")) != NULL) {
+ if ((error_notes = apr_table_get(r->notes, "error-notes"))
+ != NULL) {
ap_rvputs(r, error_notes, "<P>\n", NULL);
}
break;