1 /** @file
2
3 A brief file description
4
5 @section license License
6
7 Licensed to the Apache Software Foundation (ASF) under one
8 or more contributor license agreements. See the NOTICE file
9 distributed with this work for additional information
10 regarding copyright ownership. The ASF licenses this file
11 to you under the Apache License, Version 2.0 (the
12 "License"); you may not use this file except in compliance
13 with the License. You may obtain a copy of the License at
14
15 http://www.apache.org/licenses/LICENSE-2.0
16
17 Unless required by applicable law or agreed to in writing, software
18 distributed under the License is distributed on an "AS IS" BASIS,
19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 See the License for the specific language governing permissions and
21 limitations under the License.
22 */
23
24 #pragma once
25
26 #include "P_EventSystem.h"
27 #include "HTTP.h"
28 #include "InkAPIInternal.h"
29
30 #define TRANSFORM_READ_READY (TRANSFORM_EVENTS_START + 0)
31
32 typedef struct _RangeRecord {
_RangeRecord_RangeRecord33 _RangeRecord() {}
34 int64_t _start = -1;
35 int64_t _end = -1;
36 int64_t _done_byte = -1;
37 } RangeRecord;
38
39 class TransformProcessor
40 {
41 public:
42 void start();
43
44 public:
45 VConnection *open(Continuation *cont, APIHook *hooks);
46 INKVConnInternal *null_transform(ProxyMutex *mutex);
47 INKVConnInternal *range_transform(ProxyMutex *mutex, RangeRecord *ranges, int, HTTPHdr *, const char *content_type,
48 int content_type_len, int64_t content_length);
49 };
50
51 #if TS_HAS_TESTS
52 class TransformTest
53 {
54 public:
55 static void run();
56 };
57 #endif
58
59 /** A protocol class.
60 This provides transform VC specific methods for external access
61 without exposing internals or requiring extra includes.
62 */
63 class TransformVCChain : public VConnection
64 {
65 protected:
66 /// Required constructor
67 TransformVCChain(ProxyMutex *m);
68
69 public:
70 /** Compute the backlog. This is the amount of data ready to read
71 for each element of the chain. If @a limit is non-negative then
72 the method will return as soon as the computed backlog is at
73 least that large. This provides for more efficient checking if
74 the caller is interested only in whether the backlog is at least
75 @a limit. The default is to accurately compute the backlog.
76 */
77 virtual uint64_t backlog(uint64_t limit = UINT64_MAX ///< Maximum value of interest
78 ) = 0;
79 };
80
TransformVCChain(ProxyMutex * m)81 inline TransformVCChain::TransformVCChain(ProxyMutex *m) : VConnection(m) {}
82
83 ///////////////////////////////////////////////////////////////////
84 /// RangeTransform implementation
85 /// handling Range requests from clients
86 ///////////////////////////////////////////////////////////////////
87
88 /*-------------------------------------------------------------------------
89 -------------------------------------------------------------------------*/
90
91 inline static int
num_chars_for_int(int64_t i)92 num_chars_for_int(int64_t i)
93 {
94 int k = 1;
95
96 if (i < 0) {
97 return 0;
98 }
99
100 while ((i /= 10) != 0) {
101 ++k;
102 }
103
104 return k;
105 }
106
107 extern TransformProcessor transformProcessor;
108