/src/httpd/server/eor_bucket.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Licensed to the Apache Software Foundation (ASF) under one or more |
2 | | * contributor license agreements. See the NOTICE file distributed with |
3 | | * this work for additional information regarding copyright ownership. |
4 | | * The ASF licenses this file to You under the Apache License, Version 2.0 |
5 | | * (the "License"); you may not use this file except in compliance with |
6 | | * the License. You may obtain a copy of the License at |
7 | | * |
8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | * |
10 | | * Unless required by applicable law or agreed to in writing, software |
11 | | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | * See the License for the specific language governing permissions and |
14 | | * limitations under the License. |
15 | | */ |
16 | | |
17 | | #include "httpd.h" |
18 | | #include "http_request.h" |
19 | | #include "http_protocol.h" |
20 | | #include "scoreboard.h" |
21 | | |
22 | | typedef struct { |
23 | | apr_bucket_refcount refcount; |
24 | | request_rec *r; |
25 | | } ap_bucket_eor; |
26 | | |
27 | | static apr_status_t eor_bucket_cleanup(void *data) |
28 | 0 | { |
29 | 0 | request_rec **rp = data; |
30 | |
|
31 | 0 | if (*rp) { |
32 | 0 | request_rec *r = *rp; |
33 | | /* |
34 | | * If eor_bucket_destroy is called after us, this prevents |
35 | | * eor_bucket_destroy from trying to destroy the pool again. |
36 | | */ |
37 | 0 | *rp = NULL; |
38 | | /* Update child status and log the transaction */ |
39 | 0 | ap_update_child_status(r->connection->sbh, SERVER_BUSY_LOG, r); |
40 | 0 | ap_run_log_transaction(r); |
41 | 0 | if (ap_extended_status) { |
42 | 0 | ap_increment_counts(r->connection->sbh, r); |
43 | 0 | } |
44 | 0 | } |
45 | 0 | return APR_SUCCESS; |
46 | 0 | } |
47 | | |
48 | | static apr_status_t eor_bucket_read(apr_bucket *b, const char **str, |
49 | | apr_size_t *len, apr_read_type_e block) |
50 | 0 | { |
51 | 0 | *str = NULL; |
52 | 0 | *len = 0; |
53 | 0 | return APR_SUCCESS; |
54 | 0 | } |
55 | | |
56 | | AP_DECLARE(apr_bucket *) ap_bucket_eor_make(apr_bucket *b, request_rec *r) |
57 | 0 | { |
58 | 0 | ap_bucket_eor *h; |
59 | |
|
60 | 0 | h = apr_bucket_alloc(sizeof(*h), b->list); |
61 | 0 | h->r = r; |
62 | |
|
63 | 0 | b = apr_bucket_shared_make(b, h, 0, 0); |
64 | 0 | b->type = &ap_bucket_type_eor; |
65 | 0 | return b; |
66 | 0 | } |
67 | | |
68 | | AP_DECLARE(apr_bucket *) ap_bucket_eor_create(apr_bucket_alloc_t *list, |
69 | | request_rec *r) |
70 | 0 | { |
71 | 0 | apr_bucket *b = apr_bucket_alloc(sizeof(*b), list); |
72 | |
|
73 | 0 | APR_BUCKET_INIT(b); |
74 | 0 | b->free = apr_bucket_free; |
75 | 0 | b->list = list; |
76 | 0 | b = ap_bucket_eor_make(b, r); |
77 | 0 | if (r) { |
78 | 0 | ap_bucket_eor *h = b->data; |
79 | | /* |
80 | | * Register a cleanup for the request pool as the eor bucket could |
81 | | * have been allocated from a different pool then the request pool |
82 | | * e.g. the parent pool of the request pool. In this case |
83 | | * eor_bucket_destroy might be called at a point of time when the |
84 | | * request pool had been already destroyed. |
85 | | * We need to use a pre-cleanup here because a module may create a |
86 | | * sub-pool which is still needed during the log_transaction hook. |
87 | | */ |
88 | 0 | apr_pool_pre_cleanup_register(r->pool, &h->r, eor_bucket_cleanup); |
89 | 0 | } |
90 | 0 | return b; |
91 | 0 | } |
92 | | |
93 | | AP_DECLARE(request_rec *) ap_bucket_eor_request(apr_bucket *b) |
94 | 0 | { |
95 | 0 | ap_bucket_eor *h = b->data; |
96 | 0 | AP_DEBUG_ASSERT(AP_BUCKET_IS_EOR(b)); |
97 | 0 | return h->r; |
98 | 0 | } |
99 | | |
100 | | static void eor_bucket_destroy(void *data) |
101 | 0 | { |
102 | 0 | ap_bucket_eor *h = data; |
103 | |
|
104 | 0 | if (apr_bucket_shared_destroy(h)) { |
105 | 0 | request_rec *r = h->r; |
106 | 0 | if (r) { |
107 | | /* eor_bucket_cleanup will be called when the pool gets destroyed */ |
108 | 0 | apr_pool_destroy(r->pool); |
109 | 0 | } |
110 | 0 | apr_bucket_free(h); |
111 | 0 | } |
112 | 0 | } |
113 | | |
114 | | AP_DECLARE_DATA const apr_bucket_type_t ap_bucket_type_eor = { |
115 | | "EOR", 5, APR_BUCKET_METADATA, |
116 | | eor_bucket_destroy, |
117 | | eor_bucket_read, |
118 | | apr_bucket_setaside_noop, |
119 | | apr_bucket_split_notimpl, |
120 | | apr_bucket_shared_copy |
121 | | }; |
122 | | |