]> granicus.if.org Git - apache/blob - modules/http2/h2_push.h
correct copyright/license headers
[apache] / modules / http2 / h2_push.h
1 /* Copyright 2015 greenbytes GmbH (https://www.greenbytes.de)
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef __mod_h2__h2_push__
16 #define __mod_h2__h2_push__
17
18 #include "h2.h"
19
20 struct h2_request;
21 struct h2_headers;
22 struct h2_ngheader;
23 struct h2_session;
24 struct h2_stream;
25
26 typedef struct h2_push {
27     const struct h2_request *req;
28     h2_priority *priority;
29 } h2_push;
30
31 typedef enum {
32     H2_PUSH_DIGEST_APR_HASH,
33     H2_PUSH_DIGEST_SHA256
34 } h2_push_digest_type;
35
36 typedef struct h2_push_diary h2_push_diary;
37
38 typedef void h2_push_digest_calc(h2_push_diary *diary, apr_uint64_t *phash, h2_push *push);
39
40 struct h2_push_diary {
41     apr_array_header_t  *entries;
42     int         NMax; /* Maximum for N, should size change be necessary */
43     int         N;    /* Current maximum number of entries, power of 2 */
44     apr_uint64_t         mask; /* mask for relevant bits */
45     unsigned int         mask_bits; /* number of relevant bits */
46     const char          *authority;
47     h2_push_digest_type  dtype;
48     h2_push_digest_calc *dcalc;
49 };
50
51 /**
52  * Determine the list of h2_push'es to send to the client on behalf of
53  * the given request/response pair.
54  *
55  * @param p the pool to use
56  * @param req the requst from the client
57  * @param res the response from the server
58  * @return array of h2_push addresses or NULL
59  */
60 apr_array_header_t *h2_push_collect(apr_pool_t *p, 
61                                     const struct h2_request *req, 
62                                     int push_policy, 
63                                     const struct h2_headers *res);
64
65 /**
66  * Create a new push diary for the given maximum number of entries.
67  * 
68  * @param p the pool to use
69  * @param N the max number of entries, rounded up to 2^x
70  * @return the created diary, might be NULL of max_entries is 0
71  */
72 h2_push_diary *h2_push_diary_create(apr_pool_t *p, int N);
73
74 /**
75  * Filters the given pushes against the diary and returns only those pushes
76  * that were newly entered in the diary.
77  */
78 apr_array_header_t *h2_push_diary_update(struct h2_session *session, apr_array_header_t *pushes);
79
80 /**
81  * Collect pushes for the given request/response pair, enter them into the
82  * diary and return those pushes newly entered.
83  */
84 apr_array_header_t *h2_push_collect_update(struct h2_stream *stream, 
85                                            const struct h2_request *req, 
86                                            const struct h2_headers *res);
87 /**
88  * Get a cache digest as described in 
89  * https://datatracker.ietf.org/doc/draft-kazuho-h2-cache-digest/
90  * from the contents of the push diary.
91  * 
92  * @param diary the diary to calculdate the digest from
93  * @param p the pool to use
94  * @param authority the authority to get the data for, use NULL/"*" for all
95  * @param pdata on successful return, the binary cache digest
96  * @param plen on successful return, the length of the binary data
97  */
98 apr_status_t h2_push_diary_digest_get(h2_push_diary *diary, apr_pool_t *p, 
99                                       int maxP, const char *authority, 
100                                       const char **pdata, apr_size_t *plen);
101
102 /**
103  * Initialize the push diary by a cache digest as described in 
104  * https://datatracker.ietf.org/doc/draft-kazuho-h2-cache-digest/
105  * .
106  * @param diary the diary to set the digest into
107  * @param authority the authority to set the data for
108  * @param data the binary cache digest
109  * @param len the length of the cache digest
110  * @return APR_EINVAL if digest was not successfully parsed
111  */
112 apr_status_t h2_push_diary_digest_set(h2_push_diary *diary, const char *authority, 
113                                       const char *data, apr_size_t len);
114
115 apr_status_t h2_push_diary_digest64_set(h2_push_diary *diary, const char *authority, 
116                                         const char *data64url, apr_pool_t *pool);
117
118 #endif /* defined(__mod_h2__h2_push__) */