Hi Cleanups from lib continue. These three patches only mark up some functions as static; the changed lines count is high only because they had to be moved higher in the files.
- Lauri
>From aa5cb4ef34cf2d1c785d9538091f5f0a4e5ed5e2 Mon Sep 17 00:00:00 2001 From: Lauri Kasanen <[email protected]> Date: Sun, 17 Jun 2012 17:12:35 +0300 Subject: [PATCH 1/3] http: Mark mk_http_directory_redirect_check as static Signed-off-by: Lauri Kasanen <[email protected]> --- src/include/mk_http.h | 2 - src/mk_http.c | 140 ++++++++++++++++++++++++------------------------ 2 files changed, 70 insertions(+), 72 deletions(-) diff --git a/src/include/mk_http.h b/src/include/mk_http.h index 2335981..48b2d63 100644 --- a/src/include/mk_http.h +++ b/src/include/mk_http.h @@ -72,8 +72,6 @@ mk_pointer mk_http_protocol_check_str(int protocol); int mk_http_init(struct client_session *cs, struct session_request *sr); int mk_http_keepalive_check(struct client_session *cs); -int mk_http_directory_redirect_check(struct client_session *cs, - struct session_request *sr); int mk_http_range_set(struct session_request *sr, long file_size); int mk_http_range_parse(struct session_request *sr); diff --git a/src/mk_http.c b/src/mk_http.c index 0cdefb0..af889df 100644 --- a/src/mk_http.c +++ b/src/mk_http.c @@ -153,6 +153,76 @@ mk_pointer mk_http_protocol_check_str(int protocol) return mk_http_protocol_null_p; } +static int mk_http_directory_redirect_check(struct client_session *cs, + struct session_request *sr) +{ + int port_redirect = 0; + char *host; + char *location = 0; + char *real_location = 0; + unsigned long len; + + /* + * We have to check if exist an slash to the end of + * this string, if doesn't exist we send a redirection header + */ + if (sr->uri_processed.data[sr->uri_processed.len - 1] == '/') { + return 0; + } + + host = mk_pointer_to_buf(sr->host); + + /* + * Add ending slash to the location string + */ + location = mk_mem_malloc(sr->uri_processed.len + 2); + memcpy(location, sr->uri_processed.data, sr->uri_processed.len); + location[sr->uri_processed.len] = '/'; + location[sr->uri_processed.len + 1] = '\0'; + + /* FIXME: should we done something similar for SSL = 443 */ + if (sr->host.data && sr->port > 0) { + if (sr->port != config->standard_port) { + port_redirect = sr->port; + } + } + + if (port_redirect > 0) { + mk_string_build(&real_location, &len, "%s://%s:%i%s", + config->transport, host, port_redirect, location); + } + else { + mk_string_build(&real_location, &len, "%s://%s%s", + config->transport, host, location); + } + +#ifdef TRACE + MK_TRACE("Redirecting to '%s'", real_location); +#endif + + mk_mem_free(host); + + mk_header_set_http_status(sr, MK_REDIR_MOVED); + sr->headers.content_length = 0; + + mk_pointer_reset(&sr->headers.content_type); + sr->headers.location = real_location; + sr->headers.cgi = SH_NOCGI; + sr->headers.pconnections_left = + (config->max_keep_alive_request - cs->counter_connections); + + mk_header_send(cs->socket, cs, sr); + mk_socket_set_cork_flag(cs->socket, TCP_CORK_OFF); + + /* + * we do not free() real_location + * as it's freed by iov + */ + mk_mem_free(location); + sr->headers.location = NULL; + return -1; +} + int mk_http_init(struct client_session *cs, struct session_request *sr) { int ret; @@ -434,76 +504,6 @@ int mk_http_send_file(struct client_session *cs, struct session_request *sr) return sr->bytes_to_send; } -int mk_http_directory_redirect_check(struct client_session *cs, - struct session_request *sr) -{ - int port_redirect = 0; - char *host; - char *location = 0; - char *real_location = 0; - unsigned long len; - - /* - * We have to check if exist an slash to the end of - * this string, if doesn't exist we send a redirection header - */ - if (sr->uri_processed.data[sr->uri_processed.len - 1] == '/') { - return 0; - } - - host = mk_pointer_to_buf(sr->host); - - /* - * Add ending slash to the location string - */ - location = mk_mem_malloc(sr->uri_processed.len + 2); - memcpy(location, sr->uri_processed.data, sr->uri_processed.len); - location[sr->uri_processed.len] = '/'; - location[sr->uri_processed.len + 1] = '\0'; - - /* FIXME: should we done something similar for SSL = 443 */ - if (sr->host.data && sr->port > 0) { - if (sr->port != config->standard_port) { - port_redirect = sr->port; - } - } - - if (port_redirect > 0) { - mk_string_build(&real_location, &len, "%s://%s:%i%s", - config->transport, host, port_redirect, location); - } - else { - mk_string_build(&real_location, &len, "%s://%s%s", - config->transport, host, location); - } - -#ifdef TRACE - MK_TRACE("Redirecting to '%s'", real_location); -#endif - - mk_mem_free(host); - - mk_header_set_http_status(sr, MK_REDIR_MOVED); - sr->headers.content_length = 0; - - mk_pointer_reset(&sr->headers.content_type); - sr->headers.location = real_location; - sr->headers.cgi = SH_NOCGI; - sr->headers.pconnections_left = - (config->max_keep_alive_request - cs->counter_connections); - - mk_header_send(cs->socket, cs, sr); - mk_socket_set_cork_flag(cs->socket, TCP_CORK_OFF); - - /* - * we do not free() real_location - * as it's freed by iov - */ - mk_mem_free(location); - sr->headers.location = NULL; - return -1; -} - /* * Check if a connection can continue open using as criteria * the keepalive headers vars and Monkey configuration -- 1.7.2.1
_______________________________________________ Monkey mailing list [email protected] http://lists.monkey-project.com/listinfo/monkey
