From a6bcffcfc51fc61051fc37dc73bc4c4bb58f754c Mon Sep 17 00:00:00 2001 From: bel Date: Tue, 29 Sep 2015 22:45:24 +0200 Subject: [PATCH] Rename rel_uri to local_uri (#197) --- VS2012/civetweb_lua/civetweb_lua.vcxproj | 4 +- include/civetweb.h | 8 +-- src/civetweb.c | 65 ++++++++++++------------ src/mod_lua.inl | 4 +- 4 files changed, 42 insertions(+), 39 deletions(-) diff --git a/VS2012/civetweb_lua/civetweb_lua.vcxproj b/VS2012/civetweb_lua/civetweb_lua.vcxproj index bc23eaa6..e4d46382 100644 --- a/VS2012/civetweb_lua/civetweb_lua.vcxproj +++ b/VS2012/civetweb_lua/civetweb_lua.vcxproj @@ -133,7 +133,7 @@ Level3 Disabled USE_DUKTAPE;USE_IPV6;LUA_COMPAT_ALL;USE_LUA;USE_LUA_SQLITE3;USE_LUA_FILE_SYSTEM;USE_WEBSOCKET;WIN32;CONSOLE;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - $(ProjectDir)..\..\include;$(ProjectDir)..\..\src\third_party;$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\include;$(ProjectDir)..\..\src\third_party;$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;$(ProjectDir)..\..\src\third_party\duktape-1.3.0\src;%(AdditionalIncludeDirectories) Console @@ -177,7 +177,7 @@ true true USE_DUKTAPE;USE_IPV6;LUA_COMPAT_ALL;USE_LUA;USE_LUA_SQLITE3;USE_LUA_FILE_SYSTEM;USE_WEBSOCKET;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - $(ProjectDir)..\..\include;$(ProjectDir)..\..\src\third_party;$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\include;$(ProjectDir)..\..\src\third_party;$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;$(ProjectDir)..\..\src\third_party\duktape-1.3.0\src;%(AdditionalIncludeDirectories) Windows diff --git a/include/civetweb.h b/include/civetweb.h index 4d252360..24da6f07 100644 --- a/include/civetweb.h +++ b/include/civetweb.h @@ -55,9 +55,11 @@ struct mg_connection; /* Handle for the individual connection */ struct mg_request_info { const char *request_method; /* "GET", "POST", etc */ const char *request_uri; /* URL-decoded URI (absolute or relative, - * as in the request) */ - const char *rel_uri; /* URL-decoded URI (relative) */ - const char *uri; /* Deprecated: use rel_uri instead */ + * as in the request) */ + const char *local_uri; /* URL-decoded URI (relative). Can be NULL + * if the request_uri does not address a + * resource at the server host. */ + const char *uri; /* Deprecated: use local_uri instead */ const char *http_version; /* E.g. "1.0", "1.1" */ const char *query_string; /* URL part after '?', not including '?', or NULL */ diff --git a/src/civetweb.c b/src/civetweb.c index 1f003c9d..c80ea15b 100755 --- a/src/civetweb.c +++ b/src/civetweb.c @@ -4088,7 +4088,7 @@ interpret_uri(struct mg_connection *conn, /* in: request */ size_t filename_buf_len, /* in: size of filename buffer */ struct file *filep, /* out: file structure */ int *is_found, /* out: file is found (directly) */ - int *is_script_ressource, /* out: handled by a script? */ + int *is_script_resource, /* out: handled by a script? */ int *is_websocket_request, /* out: websocket connetion? */ int *is_put_or_delete_request /* out: put/delete a file? */ ) @@ -4097,7 +4097,7 @@ interpret_uri(struct mg_connection *conn, /* in: request */ if (conn && conn->ctx) { #if !defined(NO_FILES) - const char *uri = conn->request_info.rel_uri; + const char *uri = conn->request_info.local_uri; const char *root = conn->ctx->config[DOCUMENT_ROOT]; const char *rewrite; struct vec a, b; @@ -4115,7 +4115,7 @@ interpret_uri(struct mg_connection *conn, /* in: request */ memset(filep, 0, sizeof(*filep)); *filename = 0; *is_found = 0; - *is_script_ressource = 0; + *is_script_resource = 0; *is_put_or_delete_request = is_put_or_delete_method(conn); #if defined(USE_WEBSOCKET) @@ -4209,7 +4209,7 @@ interpret_uri(struct mg_connection *conn, /* in: request */ * Requests that read or write from/to a resource, like GET and * POST requests, should call the script and return the * generated response. */ - *is_script_ressource = !*is_put_or_delete_request; + *is_script_resource = !*is_put_or_delete_request; } #endif /* !defined(NO_CGI) || defined(USE_LUA) || defined(USE_DUKTAPE) */ *is_found = 1; @@ -4284,7 +4284,7 @@ interpret_uri(struct mg_connection *conn, /* in: request */ memmove(p + 2, p + 1, strlen(p + 1) + 1); /* +1 is for * trailing \0 */ p[1] = '/'; - *is_script_ressource = 1; + *is_script_resource = 1; break; } else { *p = '/'; @@ -4302,7 +4302,7 @@ interpret_cleanup: memset(filep, 0, sizeof(*filep)); *filename = 0; *is_found = 0; - *is_script_ressource = 0; + *is_script_resource = 0; #endif } @@ -4990,7 +4990,7 @@ static int check_authorization(struct mg_connection *conn, const char *path) list = conn->ctx->config[PROTECT_URI]; while ((list = next_option(list, &uri_vec, &filename_vec)) != NULL) { - if (!memcmp(conn->request_info.rel_uri, uri_vec.ptr, uri_vec.len)) { + if (!memcmp(conn->request_info.local_uri, uri_vec.ptr, uri_vec.len)) { mg_snprintf(conn, &truncated, fname, @@ -5438,7 +5438,7 @@ static void print_dir_entry(struct de *de) mg_printf(de->conn, "%s%s" " %s  %s\n", - de->conn->request_info.rel_uri, + de->conn->request_info.local_uri, href, de->file.is_directory ? "/" : "", de->file_name, @@ -5706,8 +5706,8 @@ static void handle_directory_request(struct mg_connection *conn, "Modified" "Size" "
", - conn->request_info.rel_uri, - conn->request_info.rel_uri, + conn->request_info.local_uri, + conn->request_info.local_uri, sort_direction, sort_direction, sort_direction); @@ -5717,7 +5717,7 @@ static void handle_directory_request(struct mg_connection *conn, mg_printf(conn, "%s" " %s  %s\n", - conn->request_info.rel_uri, + conn->request_info.local_uri, "..", "Parent directory", "-", @@ -6481,15 +6481,15 @@ static void prepare_cgi_environment(struct mg_connection *conn, addenv(env, "REQUEST_METHOD=%s", conn->request_info.request_method); addenv(env, "REMOTE_PORT=%d", conn->request_info.remote_port); - /* TODO: Check if request_uri or rel_uri should be used */ + /* TODO: Check if request_uri or local_uri should be used */ addenv(env, "REQUEST_URI=%s", conn->request_info.request_uri); /* SCRIPT_NAME */ addenv(env, "SCRIPT_NAME=%.*s", - (int)strlen(conn->request_info.rel_uri) - + (int)strlen(conn->request_info.local_uri) - ((conn->path_info == NULL) ? 0 : (int)strlen(conn->path_info)), - conn->request_info.rel_uri); + conn->request_info.local_uri); addenv(env, "SCRIPT_FILENAME=%s", prog); if (conn->path_info == NULL) { @@ -7501,7 +7501,7 @@ static void print_dav_dir_entry(struct de *de, void *data) href, sizeof(href), "%s%s", - conn->request_info.rel_uri, + conn->request_info.local_uri, de->file_name); if (!truncated) { @@ -7541,7 +7541,7 @@ static void handle_propfind(struct mg_connection *conn, "\n"); /* Print properties for the requested resource itself */ - print_props(conn, conn->request_info.rel_uri, filep); + print_props(conn, conn->request_info.local_uri, filep); /* If it is a directory, print directory entries too if Depth is not 0 */ if (filep && conn->ctx && filep->is_directory && @@ -8512,7 +8512,7 @@ static void redirect_to_https_port(struct mg_connection *conn, int ssl_index) host, (int)ntohs( conn->ctx->listening_sockets[ssl_index].lsa.sin.sin_port), - conn->request_info.rel_uri, + conn->request_info.local_uri, (conn->request_info.query_string == NULL) ? "" : "?", (conn->request_info.query_string == NULL) ? "" @@ -8684,7 +8684,7 @@ static int get_request_handler(struct mg_connection *conn, { const struct mg_request_info *request_info = mg_get_request_info(conn); if (request_info) { - const char *uri = request_info->rel_uri; + const char *uri = request_info->local_uri; size_t urilen = strlen(uri); struct mg_request_handler_info *tmp_rh; @@ -8838,20 +8838,20 @@ static void handle_request(struct mg_connection *conn) NULL) { *((char *)conn->request_info.query_string++) = '\0'; } - uri_len = (int)strlen(ri->rel_uri); + uri_len = (int)strlen(ri->local_uri); /* 1.2. decode url (if config says so) */ if (should_decode_url(conn)) { mg_url_decode( - ri->rel_uri, uri_len, (char *)ri->rel_uri, uri_len + 1, 0); + ri->local_uri, uri_len, (char *)ri->local_uri, uri_len + 1, 0); } /* 1.3. clean URIs, so a path like allowed_dir/../forbidden_file is not * possible */ - remove_double_dots_and_double_slashes((char *)ri->rel_uri); + remove_double_dots_and_double_slashes((char *)ri->local_uri); /* step 1. completed, the url is known now */ - DEBUG_TRACE("URL: %s", ri->rel_uri); + DEBUG_TRACE("URL: %s", ri->local_uri); /* 2. do a https redirect, if required */ if (!conn->client.is_ssl && conn->client.ssl_redir) { @@ -8872,7 +8872,7 @@ static void handle_request(struct mg_connection *conn) /* 3. if this ip has limited speed, set it for this connection */ conn->throttle = set_throttle( - conn->ctx->config[THROTTLE], get_remote_ip(conn), ri->rel_uri); + conn->ctx->config[THROTTLE], get_remote_ip(conn), ri->local_uri); /* 4. call a "handle everything" callback, if registered */ if (conn->ctx->callbacks.begin_request != NULL) { @@ -9105,7 +9105,7 @@ static void handle_request(struct mg_connection *conn) } /* 12. Directories uris should end with a slash */ - if (file.is_directory && ri->rel_uri[uri_len - 1] != '/') { + if (file.is_directory && ri->local_uri[uri_len - 1] != '/') { gmt_time_string(date, sizeof(date), &curtime); mg_printf(conn, "HTTP/1.1 301 Moved Permanently\r\n" @@ -9992,9 +9992,9 @@ static void reset_per_request_attributes(struct mg_connection *conn) conn->request_info.remote_user = NULL; conn->request_info.request_method = NULL; conn->request_info.request_uri = NULL; - conn->request_info.rel_uri = NULL; + conn->request_info.local_uri = NULL; conn->request_info.uri = NULL; /* TODO: cleanup uri, - * rel_uri and request_uri */ + * local_uri and request_uri */ conn->request_info.http_version = NULL; conn->request_info.num_headers = 0; conn->data_len = 0; @@ -10776,11 +10776,12 @@ static void process_new_connection(struct mg_connection *conn) switch (uri_type) { case 1: /* Asterisk */ - conn->request_info.rel_uri = NULL; + conn->request_info.local_uri = NULL; break; case 2: /* relative uri */ - conn->request_info.rel_uri = conn->request_info.request_uri; + conn->request_info.local_uri = + conn->request_info.request_uri; break; case 3: case 4: @@ -10788,9 +10789,9 @@ static void process_new_connection(struct mg_connection *conn) hostend = get_rel_url_at_current_server( conn->request_info.request_uri, conn); if (hostend) { - conn->request_info.rel_uri = hostend; + conn->request_info.local_uri = hostend; } else { - conn->request_info.rel_uri = NULL; + conn->request_info.local_uri = NULL; } break; default: @@ -10804,8 +10805,8 @@ static void process_new_connection(struct mg_connection *conn) break; } - /* TODO: cleanup uri, rel_uri and request_uri */ - conn->request_info.uri = conn->request_info.rel_uri; + /* TODO: cleanup uri, local_uri and request_uri */ + conn->request_info.uri = conn->request_info.local_uri; } if (ebuf[0] == '\0') { diff --git a/src/mod_lua.inl b/src/mod_lua.inl index 70f43c50..5d94bb6f 100644 --- a/src/mod_lua.inl +++ b/src/mod_lua.inl @@ -488,7 +488,7 @@ static int lsp_redirect(lua_State *L) const char *target = (num_args == 1) ? lua_tostring(L, 1) : NULL; if (target) { - conn->request_info.rel_uri = target; + conn->request_info.local_uri = target; handle_request(conn); lsp_abort(L); } else { @@ -1048,7 +1048,7 @@ static void prepare_lua_request_info(struct mg_connection *conn, lua_State *L) lua_newtable(L); reg_string(L, "request_method", conn->request_info.request_method); reg_string(L, "request_uri", conn->request_info.request_uri); - reg_string(L, "uri", conn->request_info.rel_uri); + reg_string(L, "uri", conn->request_info.local_uri); reg_string(L, "http_version", conn->request_info.http_version); reg_string(L, "query_string", conn->request_info.query_string); #if defined(MG_LEGACY_INTERFACE)