/* little helper function to get the original request path code borrowed from request.c and util_script.c */ static const char *ap_xsendfile_get_orginal_path(request_rec *rec) { const char *rv = rec->the_request, *last; int dir = 0; size_t uri_len; /* skip method && spaces */ while (*rv && !apr_isspace(*rv)) { ++rv; } while (apr_isspace(*rv)) { ++rv; } /* first space is the request end */ last = rv; while (*last && !apr_isspace(*last)) { ++last; } uri_len = last - rv; if (!uri_len) { return NULL; } /* alright, lets see if the request_uri changed! */ if (strncmp(rv, rec->uri, uri_len) == 0) { rv = apr_pstrdup(rec->pool, rec->filename); dir = rec->finfo.filetype == APR_DIR; } else { /* need to lookup the url again as it changed */ request_rec *sr = ap_sub_req_lookup_uri( apr_pstrmemdup(rec->pool, rv, uri_len), rec, NULL ); if (!sr) { return NULL; } rv = apr_pstrdup(rec->pool, sr->filename); dir = rec->finfo.filetype == APR_DIR; ap_destroy_sub_req(sr); } /* now we need to truncate so we only have the directory */ if (!dir && (last = ap_strrchr(rv, '/')) != NULL) { *((char*)last + 1) = '\0'; } return rv; }
static char* zipread_getcontenttype(request_rec *r, const char *pi) { request_rec *newRequest; char *pc = apr_pstrdup(r->pool, pi); char *p; if ((p = ap_strrchr(pc, '/'))) p++; else p = pc; newRequest = ap_sub_req_lookup_file(p, r, NULL); // ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "mod_zipread subreq mime: %s", newRequest->content_type); if (newRequest->content_type) return (char*)newRequest->content_type; return "text/plain"; }
static void zipread_showentry(request_rec *r, const char *filepath, const char *filename, int dir_found, int pi_start) { if (dir_found) { ap_rputs("<img src=\"/icons/folder.gif\" alt=\"[DIR]\" />",r); } else { // there has to be a better way to do this char *ex = ap_strrchr(filename, '.'); if (ex && (strcmp(ex,".htm") == 0 || strcmp(ex,".html") == 0)) { ap_rputs("<img src=\"/icons/text.gif\" alt=\"[TXT]\" />",r); } else { ap_rputs("<img src=\"/icons/unknown.gif\" alt=\"[UNK]\" />",r); } } ap_rprintf (r, "<a href=\"%s/%s\">%s</a>\n", apr_pstrndup(r->pool, r->uri, pi_start), filepath, filename); }
static void* log_fluentd_writer_init(apr_pool_t *p, server_rec *s, const char *name) { fluentd_t *fluentd; fluentd_log *log; int error = 0; int fluentdWriter = 1; if (name != NULL && strstr(name, "fluentd") == NULL) { fluentdWriter = 0; } if (!(log = apr_hash_get(fluentd_hash, name, APR_HASH_KEY_STRING))) { log = apr_palloc(p, sizeof(fluentd_log)); if (fluentdWriter == 1) { char *uri = NULL; char *c = NULL; uri = apr_pstrdup(p,name); fluentd = apr_palloc(p, sizeof(fluentd_t)); log->host = "127.0.0.1"; log->port = 24224; log->tag = "debug.test"; log->tag_len = strlen(log->tag); c = ap_strrchr(uri, ':'); if (c != NULL) { if (c != uri+6) { log->port = apr_atoi64(c+1); *c = '\0'; } } c = ap_strrchr(uri, '@'); if (c != NULL) { *c++ = '\0'; log->host = c; } c = ap_strrchr(uri, ':'); if (c != NULL) { *c++ = '\0'; log->tag = c; log->tag_len = strlen(log->tag); } error = fluentd_open(fluentd, log->host, log->port); log->uri = uri; log->fluentd = fluentd; log->write_local = 0; log->normal_handle = NULL; pthread_create(&thread,NULL, (void*)run_fluentd,NULL); } else { log->write_local = 1; log->normal_handle = normal_log_writer_init(p, s, name); } apr_hash_set(fluentd_hash, name, APR_HASH_KEY_STRING, log); } return log; }
/* * Canonicalise http-like URLs. * scheme is the scheme for the URL * url is the URL starting with the first '/' * def_port is the default port for this scheme. */ static int proxy_fcgi_canon(request_rec *r, char *url) { char *host, sport[7]; const char *err; char *path; apr_port_t port, def_port; fcgi_req_config_t *rconf = NULL; const char *pathinfo_type = NULL; if (strncasecmp(url, "fcgi:", 5) == 0) { url += 5; } else { return DECLINED; } port = def_port = ap_proxy_port_of_scheme("fcgi"); ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "canonicalising URL %s", url); err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port); if (err) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01059) "error parsing URL %s: %s", url, err); return HTTP_BAD_REQUEST; } if (port != def_port) apr_snprintf(sport, sizeof(sport), ":%d", port); else sport[0] = '\0'; if (ap_strchr_c(host, ':')) { /* if literal IPv6 address */ host = apr_pstrcat(r->pool, "[", host, "]", NULL); } if (apr_table_get(r->notes, "proxy-nocanon")) { path = url; /* this is the raw path */ } else { path = ap_proxy_canonenc(r->pool, url, strlen(url), enc_path, 0, r->proxyreq); } if (path == NULL) return HTTP_BAD_REQUEST; r->filename = apr_pstrcat(r->pool, "proxy:fcgi://", host, sport, "/", path, NULL); ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01060) "set r->filename to %s", r->filename); rconf = ap_get_module_config(r->request_config, &proxy_fcgi_module); if (rconf == NULL) { rconf = apr_pcalloc(r->pool, sizeof(fcgi_req_config_t)); ap_set_module_config(r->request_config, &proxy_fcgi_module, rconf); } if (NULL != (pathinfo_type = apr_table_get(r->subprocess_env, "proxy-fcgi-pathinfo"))) { /* It has to be on disk for this to work */ if (!strcasecmp(pathinfo_type, "full")) { rconf->need_dirwalk = 1; ap_unescape_url_keep2f(path, 0); } else if (!strcasecmp(pathinfo_type, "first-dot")) { char *split = ap_strchr(path, '.'); if (split) { char *slash = ap_strchr(split, '/'); if (slash) { r->path_info = apr_pstrdup(r->pool, slash); ap_unescape_url_keep2f(r->path_info, 0); *slash = '\0'; /* truncate path */ } } } else if (!strcasecmp(pathinfo_type, "last-dot")) { char *split = ap_strrchr(path, '.'); if (split) { char *slash = ap_strchr(split, '/'); if (slash) { r->path_info = apr_pstrdup(r->pool, slash); ap_unescape_url_keep2f(r->path_info, 0); *slash = '\0'; /* truncate path */ } } } else { /* before proxy-fcgi-pathinfo had multi-values. This requires the * the FCGI server to fixup PATH_INFO because it's the entire path */ r->path_info = apr_pstrcat(r->pool, "/", path, NULL); if (!strcasecmp(pathinfo_type, "unescape")) { ap_unescape_url_keep2f(r->path_info, 0); } ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01061) "set r->path_info to %s", r->path_info); } } return OK; }