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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __mod_h2__h2_push__
18 #define __mod_h2__h2_push__
28 typedef struct h2_push {
29 const struct h2_request *req;
30 h2_priority *priority;
34 H2_PUSH_DIGEST_APR_HASH,
36 } h2_push_digest_type;
38 typedef struct h2_push_diary h2_push_diary;
40 typedef void h2_push_digest_calc(h2_push_diary *diary, apr_uint64_t *phash, h2_push *push);
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;
54 * Determine the list of h2_push'es to send to the client on behalf of
55 * the given request/response pair.
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
62 apr_array_header_t *h2_push_collect(apr_pool_t *p,
63 const struct h2_request *req,
65 const struct h2_headers *res);
68 * Create a new push diary for the given maximum number of entries.
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
74 h2_push_diary *h2_push_diary_create(apr_pool_t *p, int N);
77 * Filters the given pushes against the diary and returns only those pushes
78 * that were newly entered in the diary.
80 apr_array_header_t *h2_push_diary_update(struct h2_session *session, apr_array_header_t *pushes);
83 * Collect pushes for the given request/response pair, enter them into the
84 * diary and return those pushes newly entered.
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);
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.
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
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);
105 * Initialize the push diary by a cache digest as described in
106 * https://datatracker.ietf.org/doc/draft-kazuho-h2-cache-digest/
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
114 apr_status_t h2_push_diary_digest_set(h2_push_diary *diary, const char *authority,
115 const char *data, apr_size_t len);
117 apr_status_t h2_push_diary_digest64_set(h2_push_diary *diary, const char *authority,
118 const char *data64url, apr_pool_t *pool);
120 #endif /* defined(__mod_h2__h2_push__) */