]> granicus.if.org Git - apache/blob - modules/http2/h2_bucket_eos.c
rework of output handling on stream/session close, rework of cleartext (http:) output...
[apache] / modules / http2 / h2_bucket_eos.c
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 <assert.h>
18 #include <stddef.h>
19
20 #include <httpd.h>
21 #include <http_core.h>
22 #include <http_connection.h>
23 #include <http_log.h>
24
25 #include "h2_private.h"
26 #include "h2_mplx.h"
27 #include "h2_stream.h"
28 #include "h2_bucket_eos.h"
29
30 typedef struct {
31     apr_bucket_refcount refcount;
32     h2_stream *stream;
33 } h2_bucket_eos;
34
35 static apr_status_t bucket_cleanup(void *data)
36 {
37     h2_stream **pstream = data;
38
39     if (*pstream) {
40         /*
41          * If bucket_destroy is called after us, this prevents
42          * bucket_destroy from trying to destroy the pool again.
43          */
44         *pstream = NULL;
45     }
46     return APR_SUCCESS;
47 }
48
49 static apr_status_t bucket_read(apr_bucket *b, const char **str,
50                                 apr_size_t *len, apr_read_type_e block)
51 {
52     *str = NULL;
53     *len = 0;
54     return APR_SUCCESS;
55 }
56
57 AP_DECLARE(apr_bucket *) h2_bucket_eos_make(apr_bucket *b, 
58                                                    h2_stream *stream)
59 {
60     h2_bucket_eos *h;
61
62     h = apr_bucket_alloc(sizeof(*h), b->list);
63     h->stream = stream;
64
65     b = apr_bucket_shared_make(b, h, 0, 0);
66     b->type = &ap_bucket_type_h2_eos;
67     
68     return b;
69 }
70
71 AP_DECLARE(apr_bucket *) h2_bucket_eos_create(apr_bucket_alloc_t *list,
72                                                      h2_stream *stream)
73 {
74     apr_bucket *b = apr_bucket_alloc(sizeof(*b), list);
75
76     APR_BUCKET_INIT(b);
77     b->free = apr_bucket_free;
78     b->list = list;
79     b = h2_bucket_eos_make(b, stream);
80     if (stream) {
81         h2_bucket_eos *h = b->data;
82         apr_pool_pre_cleanup_register(stream->pool, &h->stream, bucket_cleanup);
83     }
84     return b;
85 }
86
87 static void bucket_destroy(void *data)
88 {
89     h2_bucket_eos *h = data;
90
91     if (apr_bucket_shared_destroy(h)) {
92         h2_stream *stream = h->stream;
93         if (stream) {
94             h2_stream_cleanup(stream);
95         }
96         apr_bucket_free(h);
97     }
98 }
99
100 AP_DECLARE_DATA const apr_bucket_type_t ap_bucket_type_h2_eos = {
101     "H2EOS", 5, APR_BUCKET_METADATA,
102     bucket_destroy,
103     bucket_read,
104     apr_bucket_setaside_noop,
105     apr_bucket_split_notimpl,
106     apr_bucket_shared_copy
107 };
108