/** * Strip the ;jsessionid */ static int cse_strip(request_rec *r) { config_t *config = cse_get_module_config(r); const char *uri = r->uri; if (config == NULL || ! uri) return DECLINED; if (config->session_url_prefix) { char buffer[8192]; char *new_uri; new_uri = strstr(uri, config->session_url_prefix); if (new_uri) { *new_uri = 0; /* Strip session encoding from static files. */ if (r->filename) { char *url_rewrite = strstr(r->filename, config->session_url_prefix); if (url_rewrite) { *url_rewrite = 0; /* if (stat(r->filename, &r->finfo) < 0) r->finfo.st_mode = 0; */ } } if (r->args) { sprintf(buffer, "%s?%s", r->uri, r->args); apr_table_setn(r->headers_out, "Location", ap_construct_url(r->pool, buffer, r)); } else { apr_table_setn(r->headers_out, "Location", ap_construct_url(r->pool, r->uri, r)); } return HTTP_MOVED_PERMANENTLY; } } return DECLINED; }
static am_status_t get_request_url(am_request_t *rq) { request_rec *r = (request_rec *) (rq != NULL ? rq->ctx : NULL); if (r == NULL) return AM_EINVAL; rq->orig_url = ap_construct_url(r->pool, r->unparsed_uri, r); if (rq->orig_url == NULL) return AM_EINVAL; return AM_SUCCESS; }
apr_status_t dav_svn__location_header_filter(ap_filter_t *f, apr_bucket_brigade *bb) { request_rec *r = f->r; const char *master_uri; const char *location, *start_foo = NULL; /* Don't filter if we're in a subrequest or we aren't setup to proxy anything. */ master_uri = dav_svn__get_master_uri(r); master_uri = svn_path_uri_encode(master_uri, r->pool); if (r->main || !master_uri) { ap_remove_output_filter(f); return ap_pass_brigade(f->next, bb); } location = apr_table_get(r->headers_out, "Location"); if (location) { start_foo = ap_strstr_c(location, master_uri); } if (start_foo) { const char *new_uri; start_foo += strlen(master_uri); new_uri = ap_construct_url(r->pool, apr_pstrcat(r->pool, dav_svn__get_root_dir(r), "/", start_foo, SVN_VA_NULL), r); apr_table_set(r->headers_out, "Location", new_uri); } return ap_pass_brigade(f->next, bb); }
static const char * format_location(request_rec * r, const char * url, const char *login) { const char * out = ""; const char * p = url; const char * append = NULL; while (*p) { if (*p == '%') { if (*(p + 1) == '%') { append = "%"; } else if (*(p + 1) == 's') { append = ap_construct_url(r->pool, r->uri, r); if (r->args) { append = apr_pstrcat(r->pool, append, "?", r->args, NULL); } } else if (*(p + 1) == 'u') { append = login; } } if (append) { char * prefix = ""; if (p != url) { prefix = apr_pstrndup(r->pool, url, p - url); } out = apr_pstrcat(r->pool, out, prefix, ap_escape_urlencoded(r->pool, append), NULL); p++; url = p + 1; append = NULL; } p++; } if (p != url) { out = apr_pstrcat(r->pool, out, url, NULL); } return out; }
int papi_post_handler (request_rec *r, papi_dir_config *d, const char *post) { char *uri = ap_construct_url (r->pool, r->unparsed_uri, r); char *ptr = strchr (uri, '?'); if (ptr) *ptr = '\0'; papi_post_data_t *papi_post_data = apr_pcalloc (r->pool, sizeof (papi_post_data_t)); curl_global_init (CURL_GLOBAL_ALL); CURL *curl = curl_easy_init(); curl_easy_setopt (curl, CURLOPT_URL, uri); curl_easy_setopt (curl, CURLOPT_POST, 1); curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, papi_post_read_data); curl_easy_setopt (curl, CURLOPT_WRITEDATA, (void *)papi_post_data); // Copy saved header in request. int i; const apr_array_header_t *headers_in = apr_table_elts (r->headers_in); struct curl_slist *headers_out = NULL; for (i=0; i < headers_in->nelts; i++) { apr_table_entry_t *entry = ((apr_table_entry_t *)headers_in->elts)+i; char *header; if (!strcmp (entry->key, "Content-Length")) { header = apr_psprintf (r->pool, "Content-Length: %d", (int)strlen(post)); } else { header = apr_pstrcat (r->pool, entry->key, ": ", entry->val, NULL); } headers_out = curl_slist_append (headers_out, header); } curl_easy_setopt (curl, CURLOPT_HTTPHEADER, headers_out); curl_easy_setopt (curl, CURLOPT_POSTFIELDS, post); int res = curl_easy_perform (curl); if (res == CURLE_OK) { char *ct; curl_easy_getinfo (curl, CURLINFO_CONTENT_TYPE, &ct); ap_set_content_type (r, apr_pstrdup (r->pool, ct)); } curl_easy_cleanup (curl); curl_global_cleanup(); ap_rputs (papi_post_data->data, r); free (papi_post_data->data); return DONE; }
static int papi_cookie_checked (request_rec *r, papi_dir_config *d) { int valid_date; char *code; poa_request_t *request = NULL; char *req_id = papi_test_gpoa_url (r, d, &code, &valid_date); if (req_id) { request = papi_load_request (r, d, req_id); } if (request == NULL) { char *redir = apr_pstrcat (r->pool, "http://", r->hostname, d->loc, NULL); APACHE_LOG (APLOG_ERR, "Invalid requestID received from GPoA/AS"); return papi_redirect_url (r, redir); } char *url = papi_uri_get_arg (r->pool, request->args, "URL"); char *data = papi_uri_get_arg (r->pool, request->args, "DATA"); if (valid_date == 0) { APACHE_LOG (APLOG_WARNING, "Invalid GPoA/AS answer for %s", ap_construct_url (r->pool, r->unparsed_uri, r)); return papi_redirect_error_url (r, d, url, data); } char *userdata = papi_gen_user_data (r, d, url, code); char *rdata = papi_encrypt_gen_code (r, d, userdata, valid_date, data); url = papi_uri_add_arg (r->pool, url, "ACTION", "CHECKED"); url = papi_uri_add_arg (r->pool, url, "DATA", rdata); if (valid_date > 1) { char *lcook = papi_gen_lcook (r, d, (int)time(NULL), code); APACHE_LOG (APLOG_DEBUG, "(%s:%d) New Lcook: %s", __FILE__, __LINE__, lcook); return papi_redirect_with_cookies (r, url, lcook); } return papi_redirect_url (r, url); }
/* handle the conversion of URLs in the ProxyPassReverse function */ static const char *proxy_location_reverse_map(request_rec *r, const char *url) { void *sconf; proxy_server_conf *conf; struct proxy_alias *ent; int i, l1, l2; char *u; sconf = r->server->module_config; conf = (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module); l1 = strlen(url); ent = (struct proxy_alias *)conf->raliases->elts; for (i = 0; i < conf->raliases->nelts; i++) { l2 = strlen(ent[i].real); if (l1 >= l2 && strncmp(ent[i].real, url, l2) == 0) { u = ap_pstrcat(r->pool, ent[i].fake, &url[l2], NULL); return ap_construct_url(r->pool, u, r); } } return url; }
static int check_speling(request_rec *r) { spconfig *cfg; char *good, *bad, *postgood, *url; apr_finfo_t dirent; int filoc, dotloc, urlen, pglen; apr_array_header_t *candidates = NULL; apr_dir_t *dir; cfg = ap_get_module_config(r->per_dir_config, &speling_module); if (!cfg->enabled) { return DECLINED; } /* We only want to worry about GETs */ if (r->method_number != M_GET) { return DECLINED; } /* We've already got a file of some kind or another */ if (r->finfo.filetype != APR_NOFILE) { return DECLINED; } /* Not a file request */ if (r->proxyreq || !r->filename) { return DECLINED; } /* This is a sub request - don't mess with it */ if (r->main) { return DECLINED; } /* * The request should end up looking like this: * r->uri: /correct-url/mispelling/more * r->filename: /correct-file/mispelling r->path_info: /more * * So we do this in steps. First break r->filename into two pieces */ filoc = ap_rind(r->filename, '/'); /* * Don't do anything if the request doesn't contain a slash, or * requests "/" */ if (filoc == -1 || strcmp(r->uri, "/") == 0) { return DECLINED; } /* good = /correct-file */ good = apr_pstrndup(r->pool, r->filename, filoc); /* bad = mispelling */ bad = apr_pstrdup(r->pool, r->filename + filoc + 1); /* postgood = mispelling/more */ postgood = apr_pstrcat(r->pool, bad, r->path_info, NULL); urlen = strlen(r->uri); pglen = strlen(postgood); /* Check to see if the URL pieces add up */ if (strcmp(postgood, r->uri + (urlen - pglen))) { return DECLINED; } /* url = /correct-url */ url = apr_pstrndup(r->pool, r->uri, (urlen - pglen)); /* Now open the directory and do ourselves a check... */ if (apr_dir_open(&dir, good, r->pool) != APR_SUCCESS) { /* Oops, not a directory... */ return DECLINED; } candidates = apr_array_make(r->pool, 2, sizeof(misspelled_file)); dotloc = ap_ind(bad, '.'); if (dotloc == -1) { dotloc = strlen(bad); } while (apr_dir_read(&dirent, APR_FINFO_DIRENT, dir) == APR_SUCCESS) { sp_reason q; /* * If we end up with a "fixed" URL which is identical to the * requested one, we must have found a broken symlink or some such. * Do _not_ try to redirect this, it causes a loop! */ if (strcmp(bad, dirent.name) == 0) { apr_dir_close(dir); return OK; } /* * miscapitalization errors are checked first (like, e.g., lower case * file, upper case request) */ else if (strcasecmp(bad, dirent.name) == 0) { misspelled_file *sp_new; sp_new = (misspelled_file *) apr_array_push(candidates); sp_new->name = apr_pstrdup(r->pool, dirent.name); sp_new->quality = SP_MISCAPITALIZED; } /* * simple typing errors are checked next (like, e.g., * missing/extra/transposed char) */ else if ((cfg->check_case_only == 0) && ((q = spdist(bad, dirent.name)) != SP_VERYDIFFERENT)) { misspelled_file *sp_new; sp_new = (misspelled_file *) apr_array_push(candidates); sp_new->name = apr_pstrdup(r->pool, dirent.name); sp_new->quality = q; } /* * The spdist() should have found the majority of the misspelled * requests. It is of questionable use to continue looking for * files with the same base name, but potentially of totally wrong * type (index.html <-> index.db). * * If you're using MultiViews, and have a file named foobar.html, * which you refer to as "foobar", and someone tried to access * "Foobar", without CheckBasenameMatch, mod_speling won't find it, * because it won't find anything matching that spelling. * With the extension-munging, it would locate "foobar.html". */ else if ((cfg->check_case_only == 0) && (cfg->check_basename_match == 1)) { /* * Okay... we didn't find anything. Now we take out the hard-core * power tools. There are several cases here. Someone might have * entered a wrong extension (.htm instead of .html or vice * versa) or the document could be negotiated. At any rate, now * we just compare stuff before the first dot. If it matches, we * figure we got us a match. This can result in wrong things if * there are files of different content types but the same prefix * (e.g. foo.gif and foo.html) This code will pick the first one * it finds. Better than a Not Found, though. */ int entloc = ap_ind(dirent.name, '.'); if (entloc == -1) { entloc = strlen(dirent.name); } if ((dotloc == entloc) && !strncasecmp(bad, dirent.name, dotloc)) { misspelled_file *sp_new; sp_new = (misspelled_file *) apr_array_push(candidates); sp_new->name = apr_pstrdup(r->pool, dirent.name); sp_new->quality = SP_VERYDIFFERENT; } } } apr_dir_close(dir); if (candidates->nelts != 0) { /* Wow... we found us a mispelling. Construct a fixed url */ char *nuri; const char *ref; misspelled_file *variant = (misspelled_file *) candidates->elts; int i; ref = apr_table_get(r->headers_in, "Referer"); qsort((void *) candidates->elts, candidates->nelts, sizeof(misspelled_file), sort_by_quality); /* * Conditions for immediate redirection: * a) the first candidate was not found by stripping the suffix * AND b) there exists only one candidate OR the best match is not * ambiguous * then return a redirection right away. */ if (variant[0].quality != SP_VERYDIFFERENT && (candidates->nelts == 1 || variant[0].quality != variant[1].quality)) { nuri = ap_escape_uri(r->pool, apr_pstrcat(r->pool, url, variant[0].name, r->path_info, NULL)); if (r->parsed_uri.query) nuri = apr_pstrcat(r->pool, nuri, "?", r->parsed_uri.query, NULL); apr_table_setn(r->headers_out, "Location", ap_construct_url(r->pool, nuri, r)); ap_log_rerror(APLOG_MARK, APLOG_INFO, APR_SUCCESS, r, ref ? "Fixed spelling: %s to %s from %s" : "Fixed spelling: %s to %s%s", r->uri, nuri, (ref ? ref : "")); return HTTP_MOVED_PERMANENTLY; } /* * Otherwise, a "[300] Multiple Choices" list with the variants is * returned. */ else { apr_pool_t *p; apr_table_t *notes; apr_pool_t *sub_pool; apr_array_header_t *t; apr_array_header_t *v; if (r->main == NULL) { p = r->pool; notes = r->notes; } else { p = r->main->pool; notes = r->main->notes; } if (apr_pool_create(&sub_pool, p) != APR_SUCCESS) return DECLINED; t = apr_array_make(sub_pool, candidates->nelts * 8 + 8, sizeof(char *)); v = apr_array_make(sub_pool, candidates->nelts * 5, sizeof(char *)); /* Generate the response text. */ *(const char **)apr_array_push(t) = "The document name you requested (<code>"; *(const char **)apr_array_push(t) = ap_escape_html(sub_pool, r->uri); *(const char **)apr_array_push(t) = "</code>) could not be found on this server.\n" "However, we found documents with names similar " "to the one you requested.<p>" "Available documents:\n<ul>\n"; for (i = 0; i < candidates->nelts; ++i) { char *vuri; const char *reason; reason = sp_reason_str[(int) (variant[i].quality)]; /* The format isn't very neat... */ vuri = apr_pstrcat(sub_pool, url, variant[i].name, r->path_info, (r->parsed_uri.query != NULL) ? "?" : "", (r->parsed_uri.query != NULL) ? r->parsed_uri.query : "", NULL); *(const char **)apr_array_push(v) = "\""; *(const char **)apr_array_push(v) = ap_escape_uri(sub_pool, vuri); *(const char **)apr_array_push(v) = "\";\""; *(const char **)apr_array_push(v) = reason; *(const char **)apr_array_push(v) = "\""; *(const char **)apr_array_push(t) = "<li><a href=\""; *(const char **)apr_array_push(t) = ap_escape_uri(sub_pool, vuri); *(const char **)apr_array_push(t) = "\">"; *(const char **)apr_array_push(t) = ap_escape_html(sub_pool, vuri); *(const char **)apr_array_push(t) = "</a> ("; *(const char **)apr_array_push(t) = reason; *(const char **)apr_array_push(t) = ")\n"; /* * when we have printed the "close matches" and there are * more "distant matches" (matched by stripping the suffix), * then we insert an additional separator text to suggest * that the user LOOK CLOSELY whether these are really the * files she wanted. */ if (i > 0 && i < candidates->nelts - 1 && variant[i].quality != SP_VERYDIFFERENT && variant[i + 1].quality == SP_VERYDIFFERENT) { *(const char **)apr_array_push(t) = "</ul>\nFurthermore, the following related " "documents were found:\n<ul>\n"; } } *(const char **)apr_array_push(t) = "</ul>\n"; /* If we know there was a referring page, add a note: */ if (ref != NULL) { *(const char **)apr_array_push(t) = "Please consider informing the owner of the " "<a href=\""; *(const char **)apr_array_push(t) = ap_escape_uri(sub_pool, ref); *(const char **)apr_array_push(t) = "\">referring page</a> " "about the broken link.\n"; } /* Pass our apr_table_t to http_protocol.c (see mod_negotiation): */ apr_table_setn(notes, "variant-list", apr_array_pstrcat(p, t, 0)); apr_table_mergen(r->subprocess_env, "VARIANTS", apr_array_pstrcat(p, v, ',')); apr_pool_destroy(sub_pool); ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, ref ? "Spelling fix: %s: %d candidates from %s" : "Spelling fix: %s: %d candidates%s", r->uri, candidates->nelts, (ref ? ref : "")); return HTTP_MULTIPLE_CHOICES; } } return OK; }
static int mod_mapcache_request_handler(request_rec *r) { apr_table_t *params; mapcache_request *request = NULL; mapcache_context_apache_request *apache_ctx = NULL; mapcache_http_response *http_response = NULL; mapcache_context *global_ctx = NULL; if (!r->handler || strcmp(r->handler, "mapcache")) { return DECLINED; } if (r->method_number != M_GET) { return HTTP_METHOD_NOT_ALLOWED; } apache_ctx = apache_request_context_create(r); global_ctx = (mapcache_context*)apache_ctx; params = mapcache_http_parse_param_string(global_ctx, r->args); mapcache_service_dispatch_request(global_ctx,&request,r->path_info,params,global_ctx->config); if(GC_HAS_ERROR(global_ctx) || !request) { return write_http_response(apache_ctx, mapcache_core_respond_to_error(global_ctx)); } if(request->type == MAPCACHE_REQUEST_GET_CAPABILITIES) { mapcache_request_get_capabilities *req_caps = (mapcache_request_get_capabilities*)request; request_rec *original; char *url; if(r->main) original = r->main; else original = r; url = ap_construct_url(r->pool,original->uri,original); /* * remove the path_info from the end of the url (we want the url of the base of the service) * TODO: is there an apache api to access this ? */ if(*(original->path_info) && strcmp(original->path_info,"/")) { char *end = strstr(url,original->path_info); if(end) { /* make sure our url ends with a single '/' */ if(*end == '/') { char *slash = end; while((*(--slash))=='/') end--; end++; } *end = '\0'; } } http_response = mapcache_core_get_capabilities(global_ctx,request->service,req_caps, url,original->path_info,global_ctx->config); } else if( request->type == MAPCACHE_REQUEST_GET_TILE) { mapcache_request_get_tile *req_tile = (mapcache_request_get_tile*)request; http_response = mapcache_core_get_tile(global_ctx,req_tile); } else if( request->type == MAPCACHE_REQUEST_PROXY ) { mapcache_request_proxy *req_proxy = (mapcache_request_proxy*)request; http_response = mapcache_core_proxy_request(global_ctx, req_proxy); } else if( request->type == MAPCACHE_REQUEST_GET_MAP) { mapcache_request_get_map *req_map = (mapcache_request_get_map*)request; http_response = mapcache_core_get_map(global_ctx,req_map); } else if( request->type == MAPCACHE_REQUEST_GET_FEATUREINFO) { mapcache_request_get_feature_info *req_fi = (mapcache_request_get_feature_info*)request; http_response = mapcache_core_get_featureinfo(global_ctx,req_fi); } else { global_ctx->set_error(global_ctx,500,"###BUG### unknown request type"); } if(GC_HAS_ERROR(global_ctx)) { return write_http_response(apache_ctx, mapcache_core_respond_to_error(global_ctx)); } return write_http_response(apache_ctx,http_response); }
static int mod_mapcache_request_handler(request_rec *r) { apr_table_t *params; mapcache_request *request = NULL; mapcache_context_apache_request *apache_ctx = NULL; mapcache_http_response *http_response = NULL; mapcache_context *global_ctx = NULL; if (!r->handler || strcmp(r->handler, "mapcache")) { return DECLINED; } if (r->method_number != M_GET && r->method_number != M_POST) { return HTTP_METHOD_NOT_ALLOWED; } apache_ctx = apache_request_context_create(r); global_ctx = (mapcache_context*)apache_ctx; global_ctx->supports_redirects = 1; global_ctx->headers_in = r->headers_in; params = mapcache_http_parse_param_string(global_ctx, r->args); mapcache_service_dispatch_request(global_ctx,&request,r->path_info,params,global_ctx->config); if(GC_HAS_ERROR(global_ctx) || !request) { return write_http_response(apache_ctx, mapcache_core_respond_to_error(global_ctx)); } if(request->type == MAPCACHE_REQUEST_GET_CAPABILITIES) { mapcache_request_get_capabilities *req_caps = (mapcache_request_get_capabilities*)request; request_rec *original; char *url; if(r->main) original = r->main; else original = r; url = ap_construct_url(r->pool,original->uri,original); /* * remove the path_info from the end of the url (we want the url of the base of the service) * TODO: is there an apache api to access this ? */ if(*(original->path_info) && strcmp(original->path_info,"/")) { char *end = strstr(url,original->path_info); if(end) { /* make sure our url ends with a single '/' */ if(*end == '/') { char *slash = end; while((*(--slash))=='/') end--; end++; } *end = '\0'; } } http_response = mapcache_core_get_capabilities(global_ctx,request->service,req_caps, url,original->path_info,global_ctx->config); } else if( request->type == MAPCACHE_REQUEST_GET_TILE) { mapcache_request_get_tile *req_tile = (mapcache_request_get_tile*)request; http_response = mapcache_core_get_tile(global_ctx,req_tile); } else if( request->type == MAPCACHE_REQUEST_PROXY ) { const char *buf; mapcache_request_proxy *req_proxy = (mapcache_request_proxy*)request; if(r->method_number == M_POST) { read_post_body(apache_ctx, req_proxy); if(GC_HAS_ERROR(global_ctx)) { return write_http_response(apache_ctx, mapcache_core_respond_to_error(global_ctx)); } if(!req_proxy->headers) { req_proxy->headers = apr_table_make(global_ctx->pool, 2); } apr_table_set(req_proxy->headers, "Content-Type", r->content_type); if((buf = apr_table_get(r->headers_in,"X-Forwarded-For"))) { #if (AP_SERVER_MAJORVERSION_NUMBER == 2) && (AP_SERVER_MINORVERSION_NUMBER < 4) apr_table_set(req_proxy->headers, "X-Forwarded-For", apr_psprintf(global_ctx->pool,"%s, %s", buf, r->connection->remote_ip)); #else apr_table_set(req_proxy->headers, "X-Forwarded-For", apr_psprintf(global_ctx->pool,"%s, %s", buf, r->connection->client_ip)); #endif } else { #if (AP_SERVER_MAJORVERSION_NUMBER == 2) && (AP_SERVER_MINORVERSION_NUMBER < 4) apr_table_set(req_proxy->headers, "X-Forwarded-For", r->connection->remote_ip); #else apr_table_set(req_proxy->headers, "X-Forwarded-For", r->connection->client_ip); #endif } if ((buf = apr_table_get(r->headers_in, "Host"))) { const char *buf2; if((buf2 = apr_table_get(r->headers_in,"X-Forwarded-Host"))) { apr_table_set(req_proxy->headers, "X-Forwarded-Host", apr_psprintf(global_ctx->pool,"%s, %s",buf2,buf)); } else { apr_table_set(req_proxy->headers, "X-Forwarded-Host", buf); } } if ((buf = apr_table_get(r->headers_in, "X-Forwarded-Server"))) { apr_table_set(req_proxy->headers, "X-Forwarded-Server", apr_psprintf(global_ctx->pool, "%s, %s", buf, r->server->server_hostname)); } else { apr_table_set(req_proxy->headers, "X-Forwarded-Server", r->server->server_hostname); } } http_response = mapcache_core_proxy_request(global_ctx, req_proxy); } else if( request->type == MAPCACHE_REQUEST_GET_MAP) { mapcache_request_get_map *req_map = (mapcache_request_get_map*)request; http_response = mapcache_core_get_map(global_ctx,req_map); } else if( request->type == MAPCACHE_REQUEST_GET_FEATUREINFO) { mapcache_request_get_feature_info *req_fi = (mapcache_request_get_feature_info*)request; http_response = mapcache_core_get_featureinfo(global_ctx,req_fi); } else { global_ctx->set_error(global_ctx,500,"###BUG### unknown request type"); } if(GC_HAS_ERROR(global_ctx)) { return write_http_response(apache_ctx, mapcache_core_respond_to_error(global_ctx)); } return write_http_response(apache_ctx,http_response); }
static int mediarss_index_directory(request_rec* r) { apr_status_t status; apr_dir_t* dir; apr_finfo_t dirent; if ((status = apr_dir_open(&dir, r->filename, r->pool)) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, "Can't open directory for index: %s", r->filename); return HTTP_FORBIDDEN; } /* Content header */ char* url; url = ap_construct_url(r->pool, r->uri, r); ap_set_content_type(r, "text/xml; charset=utf-8"); ap_rputs("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n\n", r); if (strcmp(r->args, "format=mediarss") == 0) { ap_rputs("<rss version=\"2.0\" xmlns:media=\"http://search.yahoo.com/mrss/\">\n", r); } else { ap_rputs("<rss version=\"2.0\">\n", r); } ap_rputs(" <channel>\n", r); ap_rvputs(r, " <title>Index of ", url, "</title>\n", NULL); ap_rvputs(r, " <link>", url, "</link>\n", NULL); /* Collect information about the files in the directory */ while (1) { status = apr_dir_read(&dirent, APR_FINFO_MIN | APR_FINFO_NAME, dir); if (APR_STATUS_IS_INCOMPLETE(status)) { continue; /* ignore un-stat()able files */ } else if (status != APR_SUCCESS) { break; } /* We are only interested in regular files. TODO Deal with symlinks. */ if (dirent.filetype == APR_REG) { request_rec* rr; rr = ap_sub_req_lookup_dirent(&dirent, r, AP_SUBREQ_NO_ARGS, NULL); if (rr != NULL) { if (rr->finfo.filetype == APR_REG && rr->status == HTTP_OK) { /* In case of media rss, only include the item if it is a media type */ if (strcmp(r->args, "format=mediarss") == 0 && mediarss_is_media_content(rr->content_type) == 0) { continue; } char size[16]; snprintf(size, sizeof(size), "%d", dirent.size); char date[APR_RFC822_DATE_LEN]; apr_rfc822_date(date, dirent.mtime); char* guid = ap_md5(r->pool, (unsigned char*) apr_pstrcat(r->pool, url, dirent.name, NULL)); ap_rputs(" <item>\n", r); ap_rvputs(r, " <guid>", guid, "</guid>\n", NULL); ap_rvputs(r, " <title>", dirent.name, "</title>\n", NULL); ap_rvputs(r, " <pubDate>", date, "</pubDate>\n", NULL); ap_rvputs(r, " <enclosure url=\"", url, dirent.name, "\" length=\"", size, "\"\n", NULL); ap_rvputs(r, " type=\"", rr->content_type, "\"/>\n", NULL); if (strcmp(r->args, "format=mediarss") == 0) { ap_rvputs(r, " <media:content url=\"", url, dirent.name, "\" fileSize=\"", size, "\"\n", NULL); ap_rvputs(r, " type=\"", rr->content_type, "\"/>\n", NULL); } ap_rputs(" </item>\n", r); } ap_destroy_sub_req(rr); } } } /* Content footer */ ap_rputs(" </channel>\n", r); ap_rputs("</rss>\n", r); apr_dir_close(dir); return OK; }
CStr qEnvApache::MapURL(const char *path) { return ap_construct_url(myReq->pool, path, myReq); }