]> granicus.if.org Git - apache/blob - modules/http2/h2_push.h
On the 2.4.x branch:
[apache] / modules / http2 / h2_push.h
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 #ifndef __mod_h2__h2_push__
18 #define __mod_h2__h2_push__
19
20 #include "h2.h"
21
22 struct h2_request;
23 struct h2_headers;
24 struct h2_ngheader;
25 struct h2_session;
26 struct h2_stream;
27
28 typedef struct h2_push {
29     const struct h2_request *req;
30     h2_priority *priority;
31 } h2_push;
32
33 typedef enum {
34     H2_PUSH_DIGEST_APR_HASH,
35     H2_PUSH_DIGEST_SHA256
36 } h2_push_digest_type;
37
38 typedef struct h2_push_diary h2_push_diary;
39
40 typedef void h2_push_digest_calc(h2_push_diary *diary, apr_uint64_t *phash, h2_push *push);
41
42 struct h2_push_diary {
43     apr_array_header_t  *entries;
44     int         NMax; /* Maximum for N, should size change be necessary */
45     int         N;    /* Current maximum number of entries, power of 2 */
46     apr_uint64_t         mask; /* mask for relevant bits */
47     unsigned int         mask_bits; /* number of relevant bits */
48     const char          *authority;
49     h2_push_digest_type  dtype;
50     h2_push_digest_calc *dcalc;
51 };
52
53 /**
54  * Determine the list of h2_push'es to send to the client on behalf of
55  * the given request/response pair.
56  *
57  * @param p the pool to use
58  * @param req the requst from the client
59  * @param res the response from the server
60  * @return array of h2_push addresses or NULL
61  */
62 apr_array_header_t *h2_push_collect(apr_pool_t *p, 
63                                     const struct h2_request *req, 
64                                     int push_policy, 
65                                     const struct h2_headers *res);
66
67 /**
68  * Create a new push diary for the given maximum number of entries.
69  * 
70  * @param p the pool to use
71  * @param N the max number of entries, rounded up to 2^x
72  * @return the created diary, might be NULL of max_entries is 0
73  */
74 h2_push_diary *h2_push_diary_create(apr_pool_t *p, int N);
75
76 /**
77  * Filters the given pushes against the diary and returns only those pushes
78  * that were newly entered in the diary.
79  */
80 apr_array_header_t *h2_push_diary_update(struct h2_session *session, apr_array_header_t *pushes);
81
82 /**
83  * Collect pushes for the given request/response pair, enter them into the
84  * diary and return those pushes newly entered.
85  */
86 apr_array_header_t *h2_push_collect_update(struct h2_stream *stream, 
87                                            const struct h2_request *req, 
88                                            const struct h2_headers *res);
89 /**
90  * Get a cache digest as described in 
91  * https://datatracker.ietf.org/doc/draft-kazuho-h2-cache-digest/
92  * from the contents of the push diary.
93  * 
94  * @param diary the diary to calculdate the digest from
95  * @param p the pool to use
96  * @param authority the authority to get the data for, use NULL/"*" for all
97  * @param pdata on successful return, the binary cache digest
98  * @param plen on successful return, the length of the binary data
99  */
100 apr_status_t h2_push_diary_digest_get(h2_push_diary *diary, apr_pool_t *p, 
101                                       int maxP, const char *authority, 
102                                       const char **pdata, apr_size_t *plen);
103
104 /**
105  * Initialize the push diary by a cache digest as described in 
106  * https://datatracker.ietf.org/doc/draft-kazuho-h2-cache-digest/
107  * .
108  * @param diary the diary to set the digest into
109  * @param authority the authority to set the data for
110  * @param data the binary cache digest
111  * @param len the length of the cache digest
112  * @return APR_EINVAL if digest was not successfully parsed
113  */
114 apr_status_t h2_push_diary_digest_set(h2_push_diary *diary, const char *authority, 
115                                       const char *data, apr_size_t len);
116
117 apr_status_t h2_push_diary_digest64_set(h2_push_diary *diary, const char *authority, 
118                                         const char *data64url, apr_pool_t *pool);
119
120 #endif /* defined(__mod_h2__h2_push__) */