AP_DECLARE(void) ap_add_cgi_vars(request_rec *r) { apr_table_t *e = r->subprocess_env; apr_table_setn(e, "GATEWAY_INTERFACE", "CGI/1.1"); apr_table_setn(e, "SERVER_PROTOCOL", r->protocol); apr_table_setn(e, "REQUEST_METHOD", r->method); apr_table_setn(e, "QUERY_STRING", r->args ? r->args : ""); apr_table_setn(e, "REQUEST_URI", original_uri(r)); /* Note that the code below special-cases scripts run from includes, * because it "knows" that the sub_request has been hacked to have the * args and path_info of the original request, and not any that may have * come with the script URI in the include command. Ugh. */ if (!strcmp(r->protocol, "INCLUDED")) { apr_table_setn(e, "SCRIPT_NAME", r->uri); if (r->path_info && *r->path_info) { apr_table_setn(e, "PATH_INFO", r->path_info); } } else if (!r->path_info || !*r->path_info) { apr_table_setn(e, "SCRIPT_NAME", r->uri); } else { int path_info_start = ap_find_path_info(r->uri, r->path_info); apr_table_setn(e, "SCRIPT_NAME", apr_pstrndup(r->pool, r->uri, path_info_start)); apr_table_setn(e, "PATH_INFO", r->path_info); } if (r->path_info && r->path_info[0]) { /* * To get PATH_TRANSLATED, treat PATH_INFO as a URI path. * Need to re-escape it for this, since the entire URI was * un-escaped before we determined where the PATH_INFO began. */ request_rec *pa_req; pa_req = ap_sub_req_lookup_uri(ap_escape_uri(r->pool, r->path_info), r, NULL); if (pa_req->filename) { char *pt = apr_pstrcat(r->pool, pa_req->filename, pa_req->path_info, NULL); #ifdef WIN32 /* We need to make this a real Windows path name */ apr_filepath_merge(&pt, "", pt, APR_FILEPATH_NATIVE, r->pool); #endif apr_table_setn(e, "PATH_TRANSLATED", pt); } ap_destroy_sub_req(pa_req); } }
char *ApacheRequest_script_name(ApacheRequest *req) { request_rec *r = req->r; char *tmp; if (r->path_info && *r->path_info) { int path_info_start = ap_find_path_info(r->uri, r->path_info); tmp = ap_pstrndup(r->pool, r->uri, path_info_start); } else { tmp = r->uri; } return tmp; }
static int zipread_showlist(request_rec *r, const char *filter) { const char *filename = r->filename; const char *pathinfo = r->path_info; unsigned int len_filter = filter ? strlen(filter) : 0; ZZIP_DIRENT dirent; int pi_start; char *ppdir; apr_array_header_t * arr = apr_array_make(r->pool, 0, sizeof(char *)); // open the zip file ZZIP_DIR *dir = zzip_dir_open(filename, 0); if (!dir) return HTTP_NOT_FOUND; r->content_type = "text/html"; zipread_showheader(r, r->uri); if (filter && *filter == '/') { filter++; len_filter--; } // figure out the parent directory ppdir = apr_pstrdup(r->pool, ""); if (pathinfo && strlen(pathinfo) >= 2) { int i; for (i = strlen(pathinfo)-2 ; i >= 1 ; i--) { if (pathinfo[i] == '/') { ppdir = apr_pstrndup(r->pool, pathinfo, i); break; } } } else { // the parent dir is outside of the zip file. ppdir = "/.."; } // find the start of pathinfo in r->uri if (pathinfo) pi_start = ap_find_path_info(r->uri, r->path_info); else pi_start = strlen(r->uri); ap_rprintf(r,"<img src=\"/icons/back.gif\" alt=\"[BCK]\" /><a href=\"%s%s/\">%s</a>\n", apr_pstrndup(r->pool, r->uri, pi_start), ppdir, "Parent Directory"); while ( zzip_dir_read(dir, &dirent) ) { if (!filter || strncmp(dirent.d_name, filter, len_filter) == 0) { char **n = apr_array_push(arr); *n = apr_pstrdup(r->pool, dirent.d_name); } } { char **list = (char **)arr->elts; char *old = ""; int i; // Sort the list of files we contructed qsort((void *)list, arr->nelts, sizeof(char *), zipread_cmp); // Show the list of files: get first path part and remove the duplicates if (1 && filter) { for (i = 0; i < arr->nelts; i++) { int dir_found = 0; char *p1; // cut off anything after the first / if ((p1 = strchr(list[i] + len_filter, '/'))) { dir_found = 1; *(p1+1) = '\0'; } if (strcmp(list[i], old) != 0) { if (list[i][strlen(list[i])-1] == '/') { dir_found = 1; // skip the base filter directory entry if (strcmp(list[i], filter) == 0) continue; } zipread_showentry(r, list[i], list[i] + len_filter, dir_found, pi_start); old = apr_pstrdup(r->pool, list[i]); } } } else { // just list all paths unfiltered for (i = 0; i < arr->nelts; i++) { int dir_found = 0; if (list[i][strlen(list[i])-1] == '/') { dir_found = 1; } zipread_showentry(r, list[i], list[i], dir_found, pi_start); } } } ap_rputs("<hr /></pre>mod_zipread on Apache 2.0 (built on "__DATE__ " " __TIME__ ")\n</body></html>", r); zzip_dir_close (dir); return OK; }