1 /* Copyright 2015 greenbytes GmbH (https://www.greenbytes.de)
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
15 #ifndef __mod_h2__h2_push__
16 #define __mod_h2__h2_push__
26 typedef struct h2_push {
27 const struct h2_request *req;
28 h2_priority *priority;
32 H2_PUSH_DIGEST_APR_HASH,
34 } h2_push_digest_type;
36 typedef struct h2_push_diary h2_push_diary;
38 typedef void h2_push_digest_calc(h2_push_diary *diary, apr_uint64_t *phash, h2_push *push);
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;
52 * Determine the list of h2_push'es to send to the client on behalf of
53 * the given request/response pair.
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
60 apr_array_header_t *h2_push_collect(apr_pool_t *p,
61 const struct h2_request *req,
63 const struct h2_headers *res);
66 * Create a new push diary for the given maximum number of entries.
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
72 h2_push_diary *h2_push_diary_create(apr_pool_t *p, int N);
75 * Filters the given pushes against the diary and returns only those pushes
76 * that were newly entered in the diary.
78 apr_array_header_t *h2_push_diary_update(struct h2_session *session, apr_array_header_t *pushes);
81 * Collect pushes for the given request/response pair, enter them into the
82 * diary and return those pushes newly entered.
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);
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.
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
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);
103 * Initialize the push diary by a cache digest as described in
104 * https://datatracker.ietf.org/doc/draft-kazuho-h2-cache-digest/
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
112 apr_status_t h2_push_diary_digest_set(h2_push_diary *diary, const char *authority,
113 const char *data, apr_size_t len);
115 apr_status_t h2_push_diary_digest64_set(h2_push_diary *diary, const char *authority,
116 const char *data64url, apr_pool_t *pool);
118 #endif /* defined(__mod_h2__h2_push__) */