int secure_headers_add(request_rec *r) { mod_cfg *c; mod_server_cfg *s; char *stsHeaderValue; ap_log_rerror(__FILE__, __LINE__, APLOG_DEBUG, 0, r, "Processing request for %s", r->filename); if(!r->handler) { return DECLINED; } c = (mod_cfg*)ap_get_module_config(r->per_dir_config, &secure_headers_module); s = (mod_server_cfg*)ap_get_module_config(r->server->module_config, &secure_headers_module); /* Do we add the X-Content-Type-Options header? */ if(!c->mimeSniff) { ap_log_rerror(__FILE__, __LINE__, APLOG_DEBUG, 0, r, "Adding header X-Content-Type-Options: nosniff"); apr_table_add(r->headers_out, "X-Content-Type-Options", "nosniff"); } /* Do we add Strict-Transport-Security? */ if(s->stsTimeout > 0) { stsHeaderValue = apr_psprintf(r->pool, "max-age=%d", s->stsTimeout); if(s->includeSubDomains) { stsHeaderValue = apr_psprintf(r->pool, "%s; includeSubDomains", stsHeaderValue); } ap_log_rerror(__FILE__, __LINE__, APLOG_DEBUG, 0, r, "Adding header Strict-Transport-Security: %s", stsHeaderValue); apr_table_add(r->headers_out, "Strict-Transport-Security", stsHeaderValue); } return OK; }
static void table_add(abts_case *tc, void *data) { const char *val; apr_table_add(t1, "addkey", "bar"); apr_table_add(t1, "addkey", "foo"); val = apr_table_get(t1, "addkey"); ABTS_STR_EQUAL(tc, "bar", val); }
static am_status_t set_cookie(am_request_t *rq, const char *header) { request_rec *r = (request_rec *) (rq != NULL ? rq->ctx : NULL); const char *c; if (r == NULL || !ISVALID(header)) return AM_EINVAL; apr_table_add(r->err_headers_out, "Set-Cookie", header); c = apr_table_get(r->headers_in, "Cookie"); if (c == NULL) { apr_table_add(r->headers_in, "Cookie", header); } else { apr_table_set(r->headers_in, "Cookie", apr_pstrcat(r->pool, header, ";", c, NULL)); } return AM_SUCCESS; }
static int cookies_handle_load(cookies_pair_t pair, void *data, apr_pool_t *pool) { apr_table_t *table = (apr_table_t*)data; apr_table_add(table, cookies_pair_key(pair, pool), cookies_pair_value(pair, pool)); return 0; }
void parseMetadata(mapcache_context *ctx, ezxml_t node, apr_table_t *metadata) { ezxml_t cur_node; for(cur_node = node->child; cur_node; cur_node = cur_node->sibling) { apr_table_add(metadata,cur_node->name, cur_node->txt); } }
aos_status_t *oss_append_object_from_buffer(const oss_request_options_t *options, const aos_string_t *bucket, const aos_string_t *object, int64_t position, aos_list_t *buffer, aos_table_t *headers, aos_table_t **resp_headers) { aos_status_t *s = NULL; aos_http_request_t *req = NULL; aos_http_response_t *resp = NULL; aos_table_t *query_params = NULL; /* init query_params */ query_params = aos_table_create_if_null(options, query_params, 2); apr_table_add(query_params, OSS_APPEND, ""); aos_table_add_int64(query_params, OSS_POSITION, position); /* init headers */ headers = aos_table_create_if_null(options, headers, 1); set_content_type(NULL, object->data, headers); oss_init_object_request(options, bucket, object, HTTP_POST, &req, query_params, headers, &resp); oss_write_request_body_from_buffer(buffer, req); s = oss_process_request(options, req, resp); *resp_headers = resp->headers; return s; }
static int output_headers(request_rec *r, AV *headers) { dTHX; SV *key_sv, *val_sv; char *key; r->content_type = NULL; while (av_len(headers) > -1) { key_sv = av_shift(headers); val_sv = av_shift(headers); if (key_sv == NULL || val_sv == NULL) break; key = SvPV_nolen(key_sv); if (strcmp(key, "Content-Type") == 0) { r->content_type = apr_pstrdup(r->pool, SvPV_nolen(val_sv)); } else if (strcmp(key, "Content-Length") == 0) { ap_set_content_length(r, SvIV(val_sv)); } else if (strcmp(key, "Status") == 0) { server_error(r, "headers must not contain a Status"); return HTTP_INTERNAL_SERVER_ERROR; } else { apr_table_add(r->headers_out, key, SvPV_nolen(val_sv)); } SvREFCNT_dec(key_sv); SvREFCNT_dec(val_sv); } return OK; }
aos_status_t *oss_get_bucket_acl(const oss_request_options_t *options, const aos_string_t *bucket, aos_string_t *oss_acl, aos_table_t **resp_headers) { aos_status_t *s; int res; aos_http_request_t *req; aos_http_response_t *resp; aos_table_t *query_params; aos_table_t *headers; //init query_params query_params = aos_table_make(options->pool, 1); apr_table_add(query_params, OSS_ACL, ""); //init headers headers = aos_table_make(options->pool, 0); oss_init_bucket_request(options, bucket, HTTP_GET, &req, query_params, headers, &resp); s = oss_process_request(options, req, resp); *resp_headers = resp->headers; if (!aos_status_is_ok(s)) { return s; } res = oss_acl_parse_from_body(options->pool, &resp->body, oss_acl); if (res != AOSE_OK) { aos_xml_error_status_set(s, res); } return s; }
aos_status_t *oss_put_bucket_lifecycle(const oss_request_options_t *options, const aos_string_t *bucket, aos_list_t *lifecycle_rule_list, aos_table_t **resp_headers) { aos_status_t *s; aos_http_request_t *req; aos_http_response_t *resp; apr_table_t *query_params; aos_table_t *headers; aos_list_t body; //init query_params query_params = aos_table_make(options->pool, 1); apr_table_add(query_params, OSS_LIFECYCLE, ""); //init headers headers = aos_table_make(options->pool, 5); oss_init_bucket_request(options, bucket, HTTP_PUT, &req, query_params, headers, &resp); build_lifecycle_body(options->pool, lifecycle_rule_list, &body); oss_write_request_body_from_buffer(&body, req); s = oss_process_request(options, req, resp); *resp_headers = resp->headers; return s; }
static int access_checker(request_rec *r) { /* * We decline when we are in a subrequest. The Authorization header * would already be present if it was added in the main request. */ if (!ap_is_initial_req(r)) return DECLINED; ap_module_trace_rcall(r); //r_info(r, "uri: %s", r->uri); /* checking for tls authentification for this reqeust */ if (!ap_auth_type(r) || strcasecmp(ap_auth_type(r), "TLS-AAA")) return DECLINED; struct req *req = ap_req_config_get(r); struct srv *srv = ap_srv_config_get(r); struct aaa *aaa = srv->aaa; struct user *user = &req->user; user->name = aaa_attr_get(aaa, "user.name"); user->uuid = aaa_attr_get(aaa, "user.uuid"); http_authentication_signal(r); /* * We return HTTP_UNAUTHORIZED (401) because the client may wish * to authenticate using a different scheme, or a different * user. If this works, they can be granted access. If we * returned HTTP_FORBIDDEN (403) then they don't get a second * chance. */ if (r->method_number == M_POST) { apr_table_setn(r->err_headers_out, "X-AAA-ID", "http://aaa.rtfm.cz/auth"); apr_table_setn(r->err_headers_out, "X-AAA-HANDLER", "qrcode"); r_info(r, "AAA-NEGOTIATE"); //return HTTP_UNAUTHORIZED; } if (user->name) apr_table_add(r->subprocess_env, "REMOTE_USER", user->name); const char *sec = aaa_attr_get(aaa, "sess.sec"); //r_info(r, "sess.id: %s", aaa_attr_get(aaa, "sess.id")); if (sec) r_info(r, "sess.sec: %s", sec); //r_info(r, "user.uuid: %s", user->uuid); if (user->name) r_info(r, "user.name: %s", user->name); return DECLINED; }
// ## void AprTable.add(String key, String val) static KMETHOD AprTable_Add(KonohaContext *kctx, KonohaStack *sfp) { kAprTable *self = (kAprTable *) sfp[0].asObject; const char *key = kString_text(sfp[1].asString); const char *val = kString_text(sfp[2].asString); apr_table_add(self->tbl, key, val); KReturnVoid(); }
CAMLprim value netcgi2_apache_table_add (value tv, value key, value val) { CAMLparam3 (tv, key, val); table *t = Table_val (tv); apr_table_add (t, String_val (key), String_val (val)); CAMLreturn (Val_unit); }
/* Given a username and password, expected to return AUTH_GRANTED if we can validate this user/password combination. */ static authn_status authn_crowd_check_password(request_rec *r, const char *user, const char *password) { authnz_crowd_dir_config *config = get_config(r); if (config == NULL) { return AUTH_GENERAL_ERROR; } apr_array_header_t *basic_auth_xlates = config->basic_auth_xlates; int i; for (i = 0; i < basic_auth_xlates->nelts; i++) { apr_xlate_t *xlate = APR_ARRAY_IDX(basic_auth_xlates, i, apr_xlate_t *); char xlated_user[XLATE_BUFFER_SIZE] = {}; char xlated_password[XLATE_BUFFER_SIZE] = {}; if (!xlate_string(xlate, user, xlated_user) || !xlate_string(xlate, password, xlated_password)) { ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, "Failed to translate basic authentication credentials"); } else { crowd_authenticate_result result = CROWD_AUTHENTICATE_NOT_ATTEMPTED; if (config->create_sso) { crowd_cookie_config_t *cookie_config = crowd_get_cookie_config(r, config->crowd_config); if (cookie_config != NULL && (!cookie_config->secure || is_https(r))) { const char *token; result = crowd_create_session(r, config->crowd_config, xlated_user, xlated_password, &token); if (result == CROWD_AUTHENTICATE_SUCCESS && token != NULL) { char *domain = ""; if (cookie_config->domain != NULL && cookie_config->domain[0] == '.') { int domainlen = strlen(cookie_config->domain); int hostlen = strlen(r->hostname); if (hostlen > domainlen && strcmp(cookie_config->domain, r->hostname + hostlen - domainlen) == 0) { domain = apr_psprintf(r->pool, ";Domain=%s", cookie_config->domain); } } char *cookie = log_ralloc(r, apr_psprintf(r->pool, "%s=%s%s%s;Version=1", cookie_config->cookie_name, token, domain, cookie_config->secure ? ";Secure" : "")); if (cookie != NULL) { apr_table_add(r->err_headers_out, "Set-Cookie", cookie); } } } } if (result == CROWD_AUTHENTICATE_NOT_ATTEMPTED) { result = crowd_authenticate(r, config->crowd_config, xlated_user, xlated_password); } switch (result) { case CROWD_AUTHENTICATE_SUCCESS: ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "Authenticated '%s'.", xlated_user); return AUTH_GRANTED; case CROWD_AUTHENTICATE_FAILURE: break; default: ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, "Crowd authentication failed due to system exception"); } } } return AUTH_DENIED; }
int output_status_json(output_t* output){ apr_table_add(output->headers,"Access-Control-Allow-Origin", "*"); apr_cpystrn((char*)output->content_type, "application/json", 255); apr_brigade_puts(output->bucket_brigade, NULL,NULL, "{\n"); error_messages_print_json_bb(output->error_messages, output->pool,output->bucket_brigade); apr_brigade_puts(output->bucket_brigade, NULL,NULL,"\n}\n"); return 0; }
void ApacheReply::commitHeader( const Falcon::String& name, const Falcon::String& value ) { Falcon::AutoCString cvalue( value ); if ( name.compareIgnoreCase( "Content-Type" ) == 0 ) { m_request->content_type = apr_pstrdup ( m_request->pool, cvalue.c_str() ); } else { Falcon::AutoCString cname( name ); apr_table_add( m_request->headers_out, cname.c_str(), cvalue.c_str() ); } }
static int php_apache_sapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers) { php_struct *ctx; char *val, *ptr; ctx = SG(server_context); switch(op) { case SAPI_HEADER_DELETE: apr_table_unset(ctx->r->headers_out, sapi_header->header); return 0; case SAPI_HEADER_DELETE_ALL: apr_table_clear(ctx->r->headers_out); return 0; case SAPI_HEADER_ADD: case SAPI_HEADER_REPLACE: val = strchr(sapi_header->header, ':'); if (!val) { sapi_free_header(sapi_header); return 0; } ptr = val; *val = '\0'; do { val++; } while (*val == ' '); if (!strcasecmp(sapi_header->header, "content-type")) ctx->r->content_type = apr_pstrdup(ctx->r->pool, val); else if (!strcasecmp(sapi_header->header, "content-length")) ap_set_content_length(ctx->r, strtol(val, (char **)NULL, 10)); else if (op == SAPI_HEADER_REPLACE) apr_table_set(ctx->r->headers_out, sapi_header->header, val); else apr_table_add(ctx->r->headers_out, sapi_header->header, val); *ptr = ':'; return SAPI_HEADER_ADD; default: return 0; } }
aos_status_t *oss_list_object(const oss_request_options_t *options, const aos_string_t *bucket, oss_list_object_params_t *params, aos_table_t **resp_headers) { int res; aos_status_t *s; aos_http_request_t *req; aos_http_response_t *resp; aos_table_t *query_params; aos_table_t *headers; //init query_params query_params = aos_table_make(options->pool, 4); apr_table_add(query_params, OSS_PREFIX, params->prefix.data); apr_table_add(query_params, OSS_DELIMITER, params->delimiter.data); apr_table_add(query_params, OSS_MARKER, params->marker.data); aos_table_add_int(query_params, OSS_MAX_KEYS, params->max_ret); //init headers headers = aos_table_make(options->pool, 0); oss_init_bucket_request(options, bucket, HTTP_GET, &req, query_params, headers, &resp); s = oss_process_request(options, req, resp); *resp_headers = resp->headers; if (!aos_status_is_ok(s)) { return s; } res = oss_list_objects_parse_from_body(options->pool, &resp->body, ¶ms->object_list, ¶ms->common_prefix_list, ¶ms->next_marker, ¶ms->truncated); if (res != AOSE_OK) { aos_xml_error_status_set(s, res); } return s; }
static void flush_headers(slash_context_t* ctx) { sl_response_key_value_t* headers; size_t header_count, i; if(!ctx->headers_sent) { ctx->r->status = sl_response_get_status(ctx->vm); ctx->r->status_line = ap_get_status_line(ctx->r->status); headers = sl_response_get_headers(ctx->vm, &header_count); for(i = 0; i < header_count; i++) { apr_table_add(ctx->r->headers_out, headers[i].name, headers[i].value); } ctx->headers_sent = 1; } }
static apr_table_t *deep_table_copy(apr_pool_t *p, const apr_table_t *table) { const apr_array_header_t *array = apr_table_elts(table); apr_table_entry_t *elts = (apr_table_entry_t *) array->elts; apr_table_t *copy = apr_table_make(p, array->nelts); int i; for (i = 0; i < array->nelts; i++) { if (elts[i].key) { apr_table_add(copy, elts[i].key, elts[i].val); } } return copy; }
static const char * export_public_key(request_rec *r) { char *cert = ssl_var_lookup(ssl_lookup_args, "SSL_SERVER_CERT"); char *pub = ap_x509_pubkey_from_cert(r->pool, cert, strlen(cert)); if (!pub) return NULL; apr_table_t *t = r->subprocess_env; apr_table_add(t, "SERVER_PUBLIC_KEY", pub); fixups_publickey(pub, strlen(pub)); return pub; }
static ngx_inline ngx_int_t ngx_http_modsecurity_save_headers_out(ngx_http_request_t *r) { ngx_http_modsecurity_ctx_t *ctx; ngx_http_upstream_t *upstream; ctx = ngx_http_get_module_ctx(r, ngx_http_modsecurity); /* r->chunked = ctx->req->chunked; */ ngx_http_clean_header(r); upstream = r->upstream; r->upstream = &ngx_http_modsecurity_upstream; /* case SecServerSignature was used, the "Server: ..." header is added * here, overwriting the default header supplied by nginx. */ if (modsecIsServerSignatureAvailale() != NULL) { apr_table_add(ctx->req->headers_out, "Server", modsecIsServerSignatureAvailale()); } if (apr_table_do(ngx_http_modsecurity_save_headers_out_visitor, r, ctx->req->headers_out, NULL) == 0) { ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "ModSecurity: save headers out error"); return NGX_ERROR; } r->upstream = upstream; r->headers_out.status = ctx->req->status; r->headers_out.status_line.data = (u_char *)ctx->req->status_line; r->headers_out.status_line.len = ctx->req->status_line ? ngx_strlen(ctx->req->status_line) : 0; r->headers_out.content_length_n = ctx->req->clength; r->headers_out.last_modified_time = apr_time_sec(ctx->req->mtime); ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "ModSecurity: save headers out done"); return NGX_OK; }
static am_status_t add_header_in_response(am_request_t *rq, const char *key, const char *value) { am_status_t status = AM_ERROR; request_rec *r = (request_rec *) (rq != NULL ? rq->ctx : NULL); if (r == NULL || !ISVALID(key)) return AM_EINVAL; if (!ISVALID(value)) { /*value is empty, sdk is setting a cookie in response*/ status = set_cookie(rq, key); } else { /* Apache HTTPD keeps two separate server response header tables in the request * record — one for normal response headers and one for error headers. * The difference between them is the error headers are sent to * the client even (not only) on an error response (REDIRECT is one of them) */ apr_table_add(r->err_headers_out, key, value); status = AM_SUCCESS; } return status; }
static void table_getm(abts_case *tc, void *data) { const char *orig, *val; apr_pool_t *subp; apr_pool_create(&subp, p); orig = "bar"; apr_table_setn(t1, "foo", orig); val = apr_table_getm(subp, t1, "foo"); ABTS_PTR_EQUAL(tc, orig, val); ABTS_STR_EQUAL(tc, "bar", val); apr_table_add(t1, "foo", "baz"); val = apr_table_getm(subp, t1, "foo"); ABTS_STR_EQUAL(tc, "bar,baz", val); apr_pool_destroy(subp); }
/* Add a load balancer IP Address to the allowable ip addresses */ static const char* mod_zeus_conf_load_balancer_ip( cmd_parms *cmd, void *sconf_, const char *ip ) { struct in_addr addr; server_rec *s = cmd->server; mod_zeus_server_conf *conf = (mod_zeus_server_conf *) ap_get_module_config( s->module_config, &zeus_module ); if( strcmp( ip, "*" ) == 0 ) { conf->trust_all = 1; return NULL; } if( inet_aton( ip, &addr ) == 0 ) { return "Invalid IP Address"; } apr_table_add( conf->trusted_ips, ip, "1" ); return NULL; }
static am_status_t set_custom_response(am_request_t *rq, const char *text, const char *cont_type) { request_rec *r = (request_rec *) (rq != NULL ? rq->ctx : NULL); if (r == NULL || !ISVALID(text)) return AM_EINVAL; if (rq->status == AM_INTERNAL_REDIRECT) { ap_internal_redirect(text, r); rq->status = AM_DONE; } else if (rq->status == AM_REDIRECT) { apr_table_add(r->headers_out, "Location", text); ap_custom_response(r, HTTP_MOVED_TEMPORARILY, text); } else { if (rq->status == AM_PDP_DONE) { request_rec *sr = ap_sub_req_method_uri(am_method_num_to_str(rq->method), rq->post_data_url, r, NULL); sr->headers_in = r->headers_in; sr->notes = r->notes; am_log_debug(rq->instance_id, "set_custom_response(): issuing sub-request %s to %s", sr->method, rq->post_data_url); ap_run_sub_req(sr); ap_destroy_sub_req(sr); rq->status = AM_DONE; } else { size_t tl = strlen(text); if (ISVALID(cont_type)) { ap_set_content_type(r, cont_type); } ap_set_content_length(r, tl); ap_rwrite(text, (int) tl, r); ap_custom_response(r, am_status_value(rq->status == AM_SUCCESS || rq->status == AM_DONE ? AM_SUCCESS : rq->status), text); ap_rflush(r); } } am_log_info(rq->instance_id, "set_custom_response(): status: %s", am_strerror(rq->status)); return AM_SUCCESS; }
int output_dirsync_status(music_query_t* music_query){ int i = 0; apr_bucket_brigade* output_bb = music_query->output->bucket_brigade; apr_table_add(music_query->output->headers,"Access-Control-Allow-Origin", "*"); apr_cpystrn((char*)music_query->output->content_type, "application/json", 255); apr_brigade_puts(music_query->output->bucket_brigade, NULL,NULL, "{\n"); //Print Status if(music_query->globals->music_dirs != NULL){ apr_brigade_puts(output_bb, NULL,NULL,"\t\"dir_sync_status\" : {\n"); for(i = 0; i < music_query->globals->music_dirs->nelts; i++){ dir_t* dir = &(((dir_t*)music_query->globals->music_dirs->elts)[i]); apr_brigade_printf(output_bb, NULL, NULL, "\t\t\"%s\" : {\n",dir->path); apr_brigade_printf(output_bb, NULL,NULL, "\t\t\"Progress\" : \"%.2f\",\n",dir->stats->sync_progress); apr_brigade_printf(output_bb, NULL,NULL, "\t\t\"Files Scanned\" : \"%d\"\n", dir->stats->files_scanned); apr_brigade_printf(output_bb, NULL, NULL, "\t\t}"); if(i < (music_query->globals->music_dirs->nelts - 1)){ apr_brigade_printf(output_bb, NULL, NULL, ","); } } apr_brigade_puts(output_bb, NULL,NULL,"\t},\n"); } apr_brigade_puts(output_bb, NULL,NULL,"\t\"db_status\" : "); output_db_result_json(music_query->results,music_query->db_query,music_query->output); apr_brigade_puts(output_bb, NULL,NULL,"\n,"); print_error_messages(music_query->pool,output_bb, music_query->error_messages); apr_brigade_puts(output_bb, NULL,NULL,"\n}\n"); return 0; }
aos_status_t *oss_append_object_from_file(const oss_request_options_t *options, const aos_string_t *bucket, const aos_string_t *object, int64_t position, const aos_string_t *append_file, aos_table_t *headers, aos_table_t **resp_headers) { aos_status_t *s = NULL; aos_http_request_t *req = NULL; aos_http_response_t *resp = NULL; aos_table_t *query_params = NULL; int res = AOSE_OK; /* init query_params */ query_params = aos_table_create_if_null(options, query_params, 2); apr_table_add(query_params, OSS_APPEND, ""); aos_table_add_int64(query_params, OSS_POSITION, position); /* init headers */ headers = aos_table_create_if_null(options, headers, 1); set_content_type(append_file->data, object->data, headers); oss_init_object_request(options, bucket, object, HTTP_POST, &req, query_params, headers, &resp); res = oss_write_request_body_from_file(options->pool, append_file, req); s = aos_status_create(options->pool); if (res != AOSE_OK) { aos_file_error_status_set(s, res); return s; } s = oss_process_request(options, req, resp); *resp_headers = resp->headers; return s; }
aos_status_t *oss_delete_bucket_lifecycle(const oss_request_options_t *options, const aos_string_t *bucket, aos_table_t **resp_headers) { aos_status_t *s; aos_http_request_t *req; aos_http_response_t *resp; aos_table_t *query_params; aos_table_t *headers; //init query_params query_params = aos_table_make(options->pool, 1); apr_table_add(query_params, OSS_LIFECYCLE, ""); //init headers headers = aos_table_make(options->pool, 5); oss_init_bucket_request(options, bucket, HTTP_DELETE, &req, query_params, headers, &resp); s = oss_process_request(options, req, resp); *resp_headers = resp->headers; return s; }
static apr_status_t read_table(cache_handle_t *handle, request_rec *r, apr_table_t *table, apr_file_t *file) { char w[MAX_STRING_LEN]; char *l; int p; apr_status_t rv; while (1) { /* ### What about APR_EOF? */ rv = apr_file_gets(w, MAX_STRING_LEN - 1, file); if (rv != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "Premature end of cache headers."); return rv; } /* Delete terminal (CR?)LF */ p = strlen(w); /* Indeed, the host's '\n': '\012' for UNIX; '\015' for MacOS; '\025' for OS/390 -- whatever the script generates. */ if (p > 0 && w[p - 1] == '\n') { if (p > 1 && w[p - 2] == CR) { w[p - 2] = '\0'; } else { w[p - 1] = '\0'; } } /* If we've finished reading the headers, break out of the loop. */ if (w[0] == '\0') { break; } #if APR_CHARSET_EBCDIC /* Chances are that we received an ASCII header text instead of * the expected EBCDIC header lines. Try to auto-detect: */ if (!(l = strchr(w, ':'))) { int maybeASCII = 0, maybeEBCDIC = 0; unsigned char *cp, native; apr_size_t inbytes_left, outbytes_left; for (cp = w; *cp != '\0'; ++cp) { native = apr_xlate_conv_byte(ap_hdrs_from_ascii, *cp); if (apr_isprint(*cp) && !apr_isprint(native)) ++maybeEBCDIC; if (!apr_isprint(*cp) && apr_isprint(native)) ++maybeASCII; } if (maybeASCII > maybeEBCDIC) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, "CGI Interface Error: Script headers apparently ASCII: (CGI = %s)", r->filename); inbytes_left = outbytes_left = cp - w; apr_xlate_conv_buffer(ap_hdrs_from_ascii, w, &inbytes_left, w, &outbytes_left); } } #endif /*APR_CHARSET_EBCDIC*/ /* if we see a bogus header don't ignore it. Shout and scream */ if (!(l = strchr(w, ':'))) { return APR_EGENERAL; } *l++ = '\0'; while (*l && apr_isspace(*l)) { ++l; } apr_table_add(table, w, l); } return APR_SUCCESS; }
static int php_apache_sapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers) { php_struct *ctx; char *val, *ptr; ctx = SG(server_context); switch (op) { case SAPI_HEADER_DELETE: apr_table_unset(ctx->r->headers_out, sapi_header->header); return 0; case SAPI_HEADER_DELETE_ALL: apr_table_clear(ctx->r->headers_out); return 0; case SAPI_HEADER_ADD: case SAPI_HEADER_REPLACE: val = strchr(sapi_header->header, ':'); if (!val) { return 0; } ptr = val; *val = '\0'; do { val++; } while (*val == ' '); if (!strcasecmp(sapi_header->header, "content-type")) { if (ctx->content_type) { efree(ctx->content_type); } ctx->content_type = estrdup(val); } else if (!strcasecmp(sapi_header->header, "content-length")) { apr_off_t clen = 0; if (APR_SUCCESS != apr_strtoff(&clen, val, (char **) NULL, 10)) { /* We'll fall back to strtol, since that's what we used to * do anyway. */ clen = (apr_off_t) strtol(val, (char **) NULL, 10); } ap_set_content_length(ctx->r, clen); } else if (op == SAPI_HEADER_REPLACE) { apr_table_set(ctx->r->headers_out, sapi_header->header, val); } else { apr_table_add(ctx->r->headers_out, sapi_header->header, val); } *ptr = ':'; return SAPI_HEADER_ADD; default: return 0; } }