/src/trafficserver/include/ts/ts.h
Line | Count | Source |
1 | | /** @file |
2 | | |
3 | | Traffic Server SDK API header file |
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 | | @section developers Developers |
24 | | |
25 | | Developers, when adding a new element to an enum, append it. DO NOT |
26 | | insert it. Otherwise, binary compatibility of plugins will be broken! |
27 | | |
28 | | */ |
29 | | |
30 | | #pragma once |
31 | | |
32 | | #if !defined(__cplusplus) || __cplusplus < 201703L |
33 | | #error "Must compile ATS plugin code with C++ version 17 or later." |
34 | | #endif |
35 | | |
36 | | #include <type_traits> |
37 | | #include <string_view> |
38 | | #include <vector> |
39 | | |
40 | | #include "tsutil/DbgCtl.h" |
41 | | #include "ts/apidefs.h" |
42 | | |
43 | | class DiagsConfigState; |
44 | | |
45 | | /* -------------------------------------------------------------------------- |
46 | | Memory */ |
47 | | void *_TSmalloc(size_t size, const char *path); |
48 | | void *_TSrealloc(void *ptr, size_t size, const char *path); |
49 | | char *_TSstrdup(const char *str, int64_t length, const char *path); |
50 | | size_t TSstrlcpy(char *dst, const char *str, size_t siz); |
51 | | size_t TSstrlcat(char *dst, const char *str, size_t siz); |
52 | | void TSfree(void *ptr); |
53 | | |
54 | | inline void * |
55 | | TSmalloc(size_t s) |
56 | 0 | { |
57 | 0 | return _TSmalloc(s, TS_RES_MEM_PATH); |
58 | 0 | } |
59 | | inline void * |
60 | | TSrealloc(void *p, size_t s) |
61 | 0 | { |
62 | 0 | return _TSrealloc(p, s, TS_RES_MEM_PATH); |
63 | 0 | } |
64 | | inline char * |
65 | | TSstrdup(const char *p) |
66 | 0 | { |
67 | 0 | return _TSstrdup(p, -1, TS_RES_MEM_PATH); |
68 | 0 | } |
69 | | inline char * |
70 | | TSstrndup(const char *p, int64_t n) |
71 | 0 | { |
72 | 0 | return _TSstrdup(p, n, TS_RES_MEM_PATH); |
73 | 0 | } |
74 | | |
75 | | /* -------------------------------------------------------------------------- |
76 | | Component object handles */ |
77 | | /** |
78 | | Releases the TSMLoc mloc created from the TSMLoc parent. |
79 | | If there is no parent TSMLoc, use TS_NULL_MLOC. |
80 | | |
81 | | @param bufp marshal buffer containing the TSMLoc handle to be |
82 | | released. |
83 | | @param parent location of the parent object from which the handle |
84 | | was created. |
85 | | @param mloc location of the handle to be released. |
86 | | |
87 | | */ |
88 | | TSReturnCode TSHandleMLocRelease(TSMBuffer bufp, TSMLoc parent, TSMLoc mloc); |
89 | | |
90 | | /* -------------------------------------------------------------------------- |
91 | | Install and plugin locations */ |
92 | | /** |
93 | | Gets the path of the directory in which Traffic Server is installed. |
94 | | Use this function to specify the location of files that the |
95 | | plugin uses. |
96 | | |
97 | | @return pointer to Traffic Server install directory. |
98 | | |
99 | | */ |
100 | | const char *TSInstallDirGet(void); |
101 | | |
102 | | /** |
103 | | Gets the path of the directory of Traffic Server configuration. |
104 | | |
105 | | @return pointer to Traffic Server configuration directory. |
106 | | |
107 | | */ |
108 | | const char *TSConfigDirGet(void); |
109 | | |
110 | | /** |
111 | | Gets the path of the directory of Traffic Server runtime. |
112 | | |
113 | | @return pointer to Traffic Server runtime directory. |
114 | | |
115 | | */ |
116 | | const char *TSRuntimeDirGet(void); |
117 | | |
118 | | /** |
119 | | Gets the path of the plugin directory relative to the Traffic Server |
120 | | install directory. For example, to open the file "config_ui.txt" in |
121 | | the plugin directory: |
122 | | |
123 | | @code |
124 | | TSfopen("TSPluginInstallDirGet()/TSPluginDirGet()/config_ui.txt"); |
125 | | @endcode |
126 | | |
127 | | @return pointer to plugin directory relative to Traffic Server install |
128 | | directory. |
129 | | |
130 | | */ |
131 | | const char *TSPluginDirGet(void); |
132 | | |
133 | | /* -------------------------------------------------------------------------- |
134 | | Traffic Server Version */ |
135 | | /** |
136 | | Gets the version of Traffic Server currently running. Use this |
137 | | function to make sure that the plugin version and Traffic Server |
138 | | version are compatible. See the SDK sample code for usage. |
139 | | |
140 | | @return pointer to version of Traffic Server running the plugin. |
141 | | |
142 | | */ |
143 | | const char *TSTrafficServerVersionGet(void); |
144 | | |
145 | | /** Get the major version of Traffic Server currently running. |
146 | | This is the same as the first element of the string |
147 | | returned by @c TSTrafficServerVersionGet |
148 | | |
149 | | @return The major version as an integer. |
150 | | */ |
151 | | int TSTrafficServerVersionGetMajor(void); |
152 | | |
153 | | /** Get the minor version of Traffic Server currently running. |
154 | | This is the same as the second element of the string |
155 | | returned by @c TSTrafficServerVersionGet |
156 | | |
157 | | @return The minor version as an integer. |
158 | | */ |
159 | | int TSTrafficServerVersionGetMinor(void); |
160 | | |
161 | | /** Get the patch version of Traffic Server currently running. |
162 | | This is the same as the third element of the string |
163 | | returned by @c TSTrafficServerVersionGet |
164 | | |
165 | | @return The patch version as an integer. |
166 | | */ |
167 | | int TSTrafficServerVersionGetPatch(void); |
168 | | |
169 | | /* -------------------------------------------------------------------------- |
170 | | Plugin registration */ |
171 | | |
172 | | /** |
173 | | This function registers your plugin with a particular version |
174 | | of Traffic Server SDK. Use this function to make sure that the |
175 | | Traffic Server version currently running also supports your plugin. |
176 | | See the SDK sample code for usage. |
177 | | |
178 | | @param plugin_info contains registration information about your |
179 | | plugin. See TSPluginRegistrationInfo. |
180 | | @return TS_ERROR if the plugin registration failed. |
181 | | |
182 | | */ |
183 | | TSReturnCode TSPluginRegister(const TSPluginRegistrationInfo *plugin_info); |
184 | | |
185 | | /** |
186 | | This function provides the ability to enable/disable programmatically |
187 | | the plugin dynamic reloading when the same Dynamic Shared Object (DSO) |
188 | | is also used as a remap plugin. This overrides `proxy.config.plugin.dynamic_reload_mode` |
189 | | configuration variable. |
190 | | |
191 | | @param enabled boolean flag. 0/false will disable the reload on the caller plugin. |
192 | | @return TS_ERROR if the function is not called from within TSPluginInit or if TS is |
193 | | unable to get the canonical path from the plugin's path. TS_SUCCESS otherwise. |
194 | | |
195 | | @note This function should be called from within TSPluginInit |
196 | | */ |
197 | | TSReturnCode TSPluginDSOReloadEnable(int enabled); |
198 | | |
199 | | /* -------------------------------------------------------------------------- |
200 | | Files */ |
201 | | /** |
202 | | Opens a file for reading or writing and returns a descriptor for |
203 | | accessing the file. The current implementation cannot open a file |
204 | | for both reading or writing. See the SDK Programmer's Guide for |
205 | | sample code. |
206 | | |
207 | | @param filename file to be opened. |
208 | | @param mode specifies whether to open the file for reading or |
209 | | writing. If mode is "r" then the file is opened for reading. |
210 | | If mode is "w" then the file is opened for writing. Currently |
211 | | "r" and "w" are the only two valid modes for opening a file. |
212 | | @return descriptor for the file that TSfopen opens. Descriptors of |
213 | | type TSFile can be greater than 256. |
214 | | |
215 | | */ |
216 | | TSFile TSfopen(const char *filename, const char *mode); |
217 | | |
218 | | /** |
219 | | Closes the file to which filep points and frees the data structures |
220 | | and buffers associated with it. If the file was opened for writing, |
221 | | any pending data is flushed. |
222 | | |
223 | | @param filep file to be closed. |
224 | | |
225 | | */ |
226 | | void TSfclose(TSFile filep); |
227 | | |
228 | | /** |
229 | | Attempts to read length bytes of data from the file pointed to by |
230 | | filep into the buffer buf. |
231 | | |
232 | | @param filep name of the file to read from. |
233 | | @param buf buffer to read into. |
234 | | @param length amount of data to read, in bytes. |
235 | | @return number of bytes read. If end of the file, it returns 0. |
236 | | If the file was not opened for reading or if an error occurs |
237 | | while reading the file, it returns -1. |
238 | | |
239 | | */ |
240 | | ssize_t TSfread(TSFile filep, void *buf, size_t length); |
241 | | |
242 | | /** |
243 | | Attempts to write length bytes of data from the buffer buf |
244 | | to the file filep. Make sure that filep is open for writing. |
245 | | You might want to check the number of bytes written (TSfwrite() |
246 | | returns this value) against the value of length. If it is less, |
247 | | there might be insufficient space on disk, for example. |
248 | | |
249 | | @param filep file to write into. |
250 | | @param buf buffer containing the data to be written. |
251 | | @param length amount of data to write to filep, in bytes. |
252 | | @return number of bytes written to filep. If the file was not |
253 | | opened for writing, it returns -1. If an error occurs while |
254 | | writing, it returns the number of bytes successfully written. |
255 | | |
256 | | */ |
257 | | ssize_t TSfwrite(TSFile filep, const void *buf, size_t length); |
258 | | |
259 | | /** |
260 | | Flushes pending data that has been buffered up in memory from |
261 | | previous calls to TSfwrite(). |
262 | | |
263 | | @param filep file to flush. |
264 | | |
265 | | */ |
266 | | void TSfflush(TSFile filep); |
267 | | |
268 | | /** |
269 | | Reads a line from the file pointed to by filep into the buffer buf. |
270 | | Lines are terminated by a line feed character, '\n'. The line |
271 | | placed in the buffer includes the line feed character and is |
272 | | terminated with a null. If the line is longer than length bytes |
273 | | then only the first length-minus-1 bytes are placed in buf. |
274 | | |
275 | | @param filep file to read from. |
276 | | @param buf buffer to read into. |
277 | | @param length size of the buffer to read into. |
278 | | @return pointer to the string read into the buffer buf. |
279 | | |
280 | | */ |
281 | | char *TSfgets(TSFile filep, char *buf, size_t length); |
282 | | |
283 | | /* -------------------------------------------------------------------------- |
284 | | Error logging */ |
285 | | /** |
286 | | Writes printf-style error messages to the Traffic Server error |
287 | | log. One advantage of TSError over printf is that each call is |
288 | | atomically placed into the error log and is not garbled with other |
289 | | error entries. This is not an issue in single-threaded programs |
290 | | but is a definite nuisance in multi-threaded programs. |
291 | | |
292 | | @param fmt printf format description. |
293 | | @param ... argument for the printf format description. |
294 | | |
295 | | Note: Your log monitoring (e.g. Splunk) needs to alert Ops of log |
296 | | messages that contain ' ALERT: ' or ' EMERGENCY: ', these require |
297 | | immediate attention. |
298 | | |
299 | | */ |
300 | | void TSStatus(const char *fmt, ...) TS_PRINTFLIKE(1, 2); // Log information |
301 | | void TSNote(const char *fmt, ...) TS_PRINTFLIKE(1, 2); // Log significant information |
302 | | void TSWarning(const char *fmt, ...) TS_PRINTFLIKE(1, 2); // Log concerning information |
303 | | void TSError(const char *fmt, ...) TS_PRINTFLIKE(1, 2); // Log operational failure, fail CI |
304 | | void TSFatal(const char *fmt, ...) TS_PRINTFLIKE(1, 2); // Log recoverable crash, fail CI, exit & restart |
305 | | void TSAlert(const char *fmt, ...) TS_PRINTFLIKE(1, 2); // Log recoverable crash, fail CI, exit & restart, Ops attention |
306 | | void TSEmergency(const char *fmt, ...) TS_PRINTFLIKE(1, 2); // Log unrecoverable crash, fail CI, exit, Ops attention |
307 | | |
308 | | /* -------------------------------------------------------------------------- |
309 | | Assertions */ |
310 | | void _TSReleaseAssert(const char *txt, const char *f, int l) TS_NORETURN; |
311 | | int _TSAssert(const char *txt, const char *f, int l); |
312 | | |
313 | | #define TSReleaseAssert(EX) ((void)((EX) ? (void)0 : _TSReleaseAssert(#EX, __FILE__, __LINE__))) |
314 | | |
315 | | #define TSAssert(EX) (void)((EX) || (_TSAssert(#EX, __FILE__, __LINE__))) |
316 | | |
317 | | /* -------------------------------------------------------------------------- |
318 | | Marshal buffers */ |
319 | | /** |
320 | | Creates a new marshal buffer and initializes the reference count |
321 | | to 1. |
322 | | |
323 | | */ |
324 | | TSMBuffer TSMBufferCreate(void); |
325 | | |
326 | | /** |
327 | | Ignores the reference count and destroys the marshal buffer bufp. |
328 | | The internal data buffer associated with the marshal buffer is |
329 | | also destroyed if the marshal buffer allocated it. |
330 | | |
331 | | @param bufp marshal buffer to be destroyed. |
332 | | |
333 | | */ |
334 | | TSReturnCode TSMBufferDestroy(TSMBuffer bufp); |
335 | | |
336 | | /* -------------------------------------------------------------------------- |
337 | | URLs */ |
338 | | /** |
339 | | Creates a new URL within the marshal buffer bufp. Returns a |
340 | | location for the URL within the marshal buffer. |
341 | | |
342 | | @param bufp marshal buffer containing the new URL. |
343 | | @param locp pointer to a TSMLoc to store the MLoc into. |
344 | | |
345 | | */ |
346 | | TSReturnCode TSUrlCreate(TSMBuffer bufp, TSMLoc *locp); |
347 | | |
348 | | /** |
349 | | Copies the URL located at src_url within src_bufp to a URL |
350 | | location within the marshal buffer dest_bufp, and returns the |
351 | | TSMLoc location of the copied URL. Unlike TSUrlCopy(), you do |
352 | | not have to create the destination URL before cloning. Release |
353 | | the returned TSMLoc handle with a call to TSHandleMLocRelease(). |
354 | | |
355 | | @param dest_bufp marshal buffer containing the cloned URL. |
356 | | @param src_bufp marshal buffer containing the URL to be cloned. |
357 | | @param src_url location of the URL to be cloned, within the marshal |
358 | | buffer src_bufp. |
359 | | @param locp pointer to a TSMLoc to store the MLoc into. |
360 | | |
361 | | */ |
362 | | TSReturnCode TSUrlClone(TSMBuffer dest_bufp, TSMBuffer src_bufp, TSMLoc src_url, TSMLoc *locp); |
363 | | |
364 | | /** |
365 | | Copies the contents of the URL at location src_loc within the |
366 | | marshal buffer src_bufp to the location dest_loc within the marshal |
367 | | buffer dest_bufp. TSUrlCopy() works correctly even if src_bufp |
368 | | and dest_bufp point to different marshal buffers. Important: create |
369 | | the destination URL before copying into it. Use TSUrlCreate(). |
370 | | |
371 | | @param dest_bufp marshal buffer to contain the copied URL. |
372 | | @param dest_offset location of the URL to be copied. |
373 | | @param src_bufp marshal buffer containing the source URL. |
374 | | @param src_offset location of the source URL within src_bufp. |
375 | | |
376 | | */ |
377 | | TSReturnCode TSUrlCopy(TSMBuffer dest_bufp, TSMLoc dest_offset, TSMBuffer src_bufp, TSMLoc src_offset); |
378 | | |
379 | | /** |
380 | | Formats a URL stored in an TSMBuffer into an TSIOBuffer. |
381 | | |
382 | | @param bufp marshal buffer contain the URL to be printed. |
383 | | @param offset location of the URL within bufp. |
384 | | @param iobufp destination TSIOBuffer for the URL. |
385 | | |
386 | | */ |
387 | | void TSUrlPrint(TSMBuffer bufp, TSMLoc offset, TSIOBuffer iobufp); |
388 | | |
389 | | /** |
390 | | Parses a URL. The start pointer is both an input and an output |
391 | | parameter and marks the start of the URL to be parsed. After |
392 | | a successful parse, the start pointer equals the end pointer. |
393 | | The end pointer must be one byte after the last character you |
394 | | want to parse. The URL parsing routine assumes that everything |
395 | | between start and end is part of the URL. It is up to higher level |
396 | | parsing routines, such as TSHttpHdrParseReq(), to determine the |
397 | | actual end of the URL. Returns TS_PARSE_ERROR if an error occurs, |
398 | | otherwise TS_PARSE_DONE is returned to indicate success. |
399 | | |
400 | | @param bufp marshal buffer containing the URL to be parsed. |
401 | | @param offset location of the URL to be parsed. |
402 | | @param start points to the start of the URL to be parsed AND at |
403 | | the end of a successful parse it will equal the end pointer. |
404 | | @param end must be one byte after the last character. |
405 | | @return TS_PARSE_ERROR or TS_PARSE_DONE. |
406 | | |
407 | | */ |
408 | | TSParseResult TSUrlParse(TSMBuffer bufp, TSMLoc offset, const char **start, const char *end); |
409 | | |
410 | | /** |
411 | | Calculates the length of the URL located at url_loc within the |
412 | | marshal buffer bufp if it were returned as a string. This length |
413 | | is the same as the length returned by TSUrlStringGet(). |
414 | | |
415 | | @param bufp marshal buffer containing the URL whose length you want. |
416 | | @param offset location of the URL within the marshal buffer bufp. |
417 | | @return string length of the URL. |
418 | | |
419 | | */ |
420 | | int TSUrlLengthGet(TSMBuffer bufp, TSMLoc offset); |
421 | | |
422 | | /** |
423 | | Constructs a string representation of the URL located at url_loc |
424 | | within bufp. TSUrlStringGet() stores the length of the allocated |
425 | | string in the parameter length. This is the same length that |
426 | | TSUrlLengthGet() returns. The returned string is allocated by a |
427 | | call to TSmalloc(). It should be freed by a call to TSfree(). |
428 | | The length parameter must be present, providing storage for the |
429 | | URL string length value. |
430 | | Note: To get the effective URL from a request, use the alternative |
431 | | TSHttpTxnEffectiveUrlStringGet or |
432 | | TSHttpHdrEffectiveUrlBufGet APIs. |
433 | | |
434 | | @param bufp marshal buffer containing the URL you want to get. |
435 | | @param offset location of the URL within bufp. |
436 | | @param length string length of the URL. |
437 | | @return The URL as a string. |
438 | | |
439 | | */ |
440 | | char *TSUrlStringGet(TSMBuffer bufp, TSMLoc offset, int *length); |
441 | | |
442 | | /** |
443 | | Retrieves the scheme portion of the URL located at url_loc within |
444 | | the marshal buffer bufp. TSUrlSchemeGet() places the length of |
445 | | the string in the length argument. If the length is null then no |
446 | | attempt is made to dereference it. |
447 | | |
448 | | @param bufp marshal buffer storing the URL. |
449 | | @param offset location of the URL within bufp. |
450 | | @param length length of the returned string. |
451 | | @return The scheme portion of the URL, as a string. |
452 | | |
453 | | */ |
454 | | const char *TSUrlRawSchemeGet(TSMBuffer bufp, TSMLoc offset, int *length); |
455 | | |
456 | | /** |
457 | | Retrieves the scheme portion of the URL located at url_loc within |
458 | | the marshal buffer bufp. TSUrlSchemeGet() places the length of |
459 | | the string in the length argument. If the length is null then no |
460 | | attempt is made to dereference it. If there is no explicit scheme, |
461 | | a scheme of http is returned if the URL type is HTTP, and a scheme |
462 | | of https is returned if the URL type is HTTPS. |
463 | | |
464 | | @param bufp marshal buffer storing the URL. |
465 | | @param offset location of the URL within bufp. |
466 | | @param length length of the returned string. |
467 | | @return The scheme portion of the URL, as a string. |
468 | | |
469 | | */ |
470 | | const char *TSUrlSchemeGet(TSMBuffer bufp, TSMLoc offset, int *length); |
471 | | |
472 | | /** |
473 | | Sets the scheme portion of the URL located at url_loc within |
474 | | the marshal buffer bufp to the string value. If length is -1 |
475 | | then TSUrlSchemeSet() assumes that value is null-terminated. |
476 | | Otherwise, the length of the string value is taken to be length. |
477 | | TSUrlSchemeSet() copies the string to within bufp, so it is OK |
478 | | to modify or delete value after calling TSUrlSchemeSet(). |
479 | | |
480 | | @param bufp marshal buffer containing the URL. |
481 | | @param offset location of the URL. |
482 | | @param value value to set the URL's scheme to. |
483 | | @param length string stored in value. |
484 | | |
485 | | */ |
486 | | TSReturnCode TSUrlSchemeSet(TSMBuffer bufp, TSMLoc offset, const char *value, int length); |
487 | | |
488 | | /* -------------------------------------------------------------------------- |
489 | | Internet specific URLs */ |
490 | | /** |
491 | | Retrieves the user portion of the URL located at url_loc |
492 | | within bufp. Note: the returned string is not guaranteed to |
493 | | be null-terminated. |
494 | | |
495 | | @param bufp marshal buffer containing the URL. |
496 | | @param offset location of the URL. |
497 | | @param length length of the returned string. |
498 | | @return user portion of the URL. |
499 | | |
500 | | */ |
501 | | const char *TSUrlUserGet(TSMBuffer bufp, TSMLoc offset, int *length); |
502 | | |
503 | | /** |
504 | | Sets the user portion of the URL located at url_loc within bufp |
505 | | to the string value. If length is -1 then TSUrlUserSet() assumes |
506 | | that value is null-terminated. Otherwise, the length of the string |
507 | | value is taken to be length. TSUrlUserSet() copies the string to |
508 | | within bufp, so it is OK to modify or delete value after calling |
509 | | TSUrlUserSet(). |
510 | | |
511 | | @param bufp marshal buffer containing the URL. |
512 | | @param offset location of the URL whose user is to be set. |
513 | | @param value holds the new user name. |
514 | | @param length string length of value. |
515 | | |
516 | | */ |
517 | | TSReturnCode TSUrlUserSet(TSMBuffer bufp, TSMLoc offset, const char *value, int length); |
518 | | |
519 | | /** |
520 | | Retrieves the password portion of the URL located at url_loc |
521 | | within bufp. TSUrlPasswordGet() places the length of the returned |
522 | | string in the length argument. Note: the returned string is |
523 | | not guaranteed to be null-terminated. |
524 | | |
525 | | @param bufp marshal buffer containing the URL. |
526 | | @param offset |
527 | | @param length of the returned password string. |
528 | | @return password portion of the URL. |
529 | | |
530 | | */ |
531 | | const char *TSUrlPasswordGet(TSMBuffer bufp, TSMLoc offset, int *length); |
532 | | |
533 | | /** |
534 | | Sets the password portion of the URL located at url_loc within |
535 | | bufp to the string value. If length is -1 then TSUrlPasswordSet() |
536 | | assumes that value is null-terminated. Otherwise, the length |
537 | | of value is taken to be length. TSUrlPasswordSet() copies the |
538 | | string to within bufp, so it is okay to modify or delete value |
539 | | after calling TSUrlPasswordSet(). |
540 | | |
541 | | @param bufp marshal buffer containing the URL. |
542 | | @param offset |
543 | | @param value new password. |
544 | | @param length of the new password. |
545 | | |
546 | | */ |
547 | | TSReturnCode TSUrlPasswordSet(TSMBuffer bufp, TSMLoc offset, const char *value, int length); |
548 | | |
549 | | /** |
550 | | Retrieves the host portion of the URL located at url_loc |
551 | | within bufp. Note: the returned string is not guaranteed to be |
552 | | null-terminated. |
553 | | |
554 | | @param bufp marshal buffer containing the URL. |
555 | | @param offset location of the URL. |
556 | | @param length of the returned string. |
557 | | @return Host portion of the URL. |
558 | | |
559 | | */ |
560 | | const char *TSUrlHostGet(TSMBuffer bufp, TSMLoc offset, int *length); |
561 | | |
562 | | /** |
563 | | Sets the host portion of the URL at url_loc to the string value. |
564 | | If length is -1 then TSUrlHostSet() assumes that value is |
565 | | null-terminated. Otherwise, the length of the string value is |
566 | | taken to be length. The string is copied to within bufp, so you |
567 | | can modify or delete value after calling TSUrlHostSet(). |
568 | | |
569 | | @param bufp marshal buffer containing the URL to modify. |
570 | | @param offset location of the URL. |
571 | | @param value new host name for the URL. |
572 | | @param length string length of the new host name of the URL. |
573 | | |
574 | | */ |
575 | | TSReturnCode TSUrlHostSet(TSMBuffer bufp, TSMLoc offset, const char *value, int length); |
576 | | |
577 | | /** |
578 | | Returns the port portion of the URL located at url_loc if explicitly present, |
579 | | otherwise the canonical port for the URL. |
580 | | |
581 | | @param bufp marshal buffer containing the URL. |
582 | | @param offset location of the URL. |
583 | | @return port portion of the URL. |
584 | | |
585 | | */ |
586 | | int TSUrlPortGet(TSMBuffer bufp, TSMLoc offset); |
587 | | |
588 | | /** |
589 | | Returns the port portion of the URL located at url_loc if explicitly present, |
590 | | otherwise 0. |
591 | | |
592 | | @param bufp marshal buffer containing the URL. |
593 | | @param offset location of the URL. |
594 | | @return port portion of the URL. |
595 | | |
596 | | */ |
597 | | int TSUrlRawPortGet(TSMBuffer bufp, TSMLoc offset); |
598 | | |
599 | | /** |
600 | | Sets the port portion of the URL located at url_loc. |
601 | | |
602 | | @param bufp marshal buffer containing the URL. |
603 | | @param offset location of the URL. |
604 | | @param port new port setting for the URL. |
605 | | |
606 | | */ |
607 | | TSReturnCode TSUrlPortSet(TSMBuffer bufp, TSMLoc offset, int port); |
608 | | |
609 | | /* -------------------------------------------------------------------------- |
610 | | HTTP specific URLs */ |
611 | | /** |
612 | | Retrieves the path portion of the URL located at url_loc within |
613 | | bufp. TSUrlPathGet() places the length of the returned string in |
614 | | the length argument. Note: the returned string is not guaranteed to |
615 | | be null-terminated. |
616 | | |
617 | | @param bufp marshal buffer containing the URL. |
618 | | @param offset location of the URL. |
619 | | @param length of the returned string. |
620 | | @return path portion of the URL. |
621 | | |
622 | | */ |
623 | | const char *TSUrlPathGet(TSMBuffer bufp, TSMLoc offset, int *length); |
624 | | |
625 | | /** |
626 | | Sets the path portion of the URL located at url_loc within bufp |
627 | | to the string value. If length is -1 then TSUrlPathSet() assumes |
628 | | that value is null-terminated. Otherwise, the length of the value |
629 | | is taken to be length. TSUrlPathSet() copies the string into bufp, |
630 | | so you can modify or delete value after calling TSUrlPathSet(). |
631 | | |
632 | | @param bufp marshal buffer containing the URL. |
633 | | @param offset location of the URL. |
634 | | @param value new path string for the URL. |
635 | | @param length of the new path string. |
636 | | |
637 | | */ |
638 | | TSReturnCode TSUrlPathSet(TSMBuffer bufp, TSMLoc offset, const char *value, int length); |
639 | | |
640 | | /* -------------------------------------------------------------------------- |
641 | | FTP specific URLs */ |
642 | | /** |
643 | | Retrieves the FTP type of the URL located at url_loc within bufp. |
644 | | |
645 | | @param bufp marshal buffer containing the URL. |
646 | | @param offset location of the URL. |
647 | | @return FTP type of the URL. |
648 | | |
649 | | */ |
650 | | int TSUrlFtpTypeGet(TSMBuffer bufp, TSMLoc offset); |
651 | | |
652 | | /** |
653 | | Sets the FTP type portion of the URL located at url_loc within |
654 | | bufp to the value type. |
655 | | |
656 | | @param bufp marshal buffer containing the URL. |
657 | | @param offset location of the URL to modify. |
658 | | @param type new FTP type for the URL. |
659 | | |
660 | | */ |
661 | | TSReturnCode TSUrlFtpTypeSet(TSMBuffer bufp, TSMLoc offset, int type); |
662 | | |
663 | | /* -------------------------------------------------------------------------- |
664 | | HTTP specific URLs */ |
665 | | |
666 | | /** |
667 | | Retrieves the HTTP query portion of the URL located at url_loc |
668 | | within bufp. The length of the returned string is in the length |
669 | | argument. Note: the returned string is not guaranteed to be |
670 | | null-terminated. |
671 | | |
672 | | @param bufp marshal buffer containing the URL. |
673 | | @param offset location of the URL. |
674 | | @param length of the returned string. |
675 | | @return HTTP query portion of the URL. |
676 | | |
677 | | */ |
678 | | const char *TSUrlHttpQueryGet(TSMBuffer bufp, TSMLoc offset, int *length); |
679 | | |
680 | | /** |
681 | | Sets the HTTP query portion of the URL located at url_loc within |
682 | | bufp to value. If length is -1, the string value is assumed to |
683 | | be null-terminated; otherwise, the length of value is taken to be |
684 | | length. TSUrlHttpQuerySet() copies the string to within bufp, so |
685 | | you can modify or delete value after calling TSUrlHttpQuerySet(). |
686 | | |
687 | | @param bufp marshal buffer containing the URL. |
688 | | @param offset location of the URL within bufp. |
689 | | @param value new HTTP query string for the URL. |
690 | | @param length of the new HTTP query string. |
691 | | |
692 | | */ |
693 | | TSReturnCode TSUrlHttpQuerySet(TSMBuffer bufp, TSMLoc offset, const char *value, int length); |
694 | | |
695 | | /** |
696 | | Retrieves the HTTP fragment portion of the URL located at url_loc |
697 | | within bufp. The length of the returned string is in the length |
698 | | argument. Note: the returned string is not guaranteed to be |
699 | | null-terminated. |
700 | | |
701 | | @param bufp marshal buffer containing the URL. |
702 | | @param offset location of the URL. |
703 | | @param length of the returned string. |
704 | | @return HTTP fragment portion of the URL. |
705 | | |
706 | | */ |
707 | | const char *TSUrlHttpFragmentGet(TSMBuffer bufp, TSMLoc offset, int *length); |
708 | | |
709 | | /** |
710 | | Sets the HTTP fragment portion of the URL located at url_loc |
711 | | within bufp to value. If length is -1, the string value is |
712 | | assumed to be null-terminated; otherwise, the length of value |
713 | | is taken to be length. TSUrlHttpFragmentSet() copies the string |
714 | | to within bufp, so you can modify or delete value after calling |
715 | | TSUrlHttpFragmentSet(). |
716 | | |
717 | | @param bufp marshal buffer containing the URL. |
718 | | @param offset location of the URL within bufp. |
719 | | @param value new HTTP fragment string for the URL. |
720 | | @param length of the new HTTP query string. |
721 | | |
722 | | */ |
723 | | TSReturnCode TSUrlHttpFragmentSet(TSMBuffer bufp, TSMLoc offset, const char *value, int length); |
724 | | |
725 | | /** |
726 | | Perform percent-encoding of the string in the buffer, storing the |
727 | | new string in the destination buffer. The length parameter will be |
728 | | set to the new (encoded) string length, or 0 if the encoding failed. |
729 | | |
730 | | @param str the string buffer to encode. |
731 | | @param str_len length of the string buffer. |
732 | | @param dst destination buffer. |
733 | | @param dst_size size of the destination buffer. |
734 | | @param length amount of data written to the destination buffer. |
735 | | @param map optional (can be null) map of characters to encode. |
736 | | |
737 | | */ |
738 | | TSReturnCode TSStringPercentEncode(const char *str, int str_len, char *dst, size_t dst_size, size_t *length, |
739 | | const unsigned char *map); |
740 | | |
741 | | /** |
742 | | Similar to TSStringPercentEncode(), but works on a URL object. |
743 | | |
744 | | @param bufp marshal buffer containing the URL. |
745 | | @param offset location of the URL within bufp. |
746 | | @param dst destination buffer. |
747 | | @param dst_size size of the destination buffer. |
748 | | @param length amount of data written to the destination buffer. |
749 | | @param map optional (can be null) map of characters to encode. |
750 | | |
751 | | */ |
752 | | TSReturnCode TSUrlPercentEncode(TSMBuffer bufp, TSMLoc offset, char *dst, size_t dst_size, size_t *length, |
753 | | const unsigned char *map); |
754 | | |
755 | | /** |
756 | | Perform percent-decoding of the string in the buffer, writing |
757 | | to the output buffer. The source and destination can be the same, |
758 | | in which case they overwrite. The decoded string is always |
759 | | guaranteed to be no longer than the source string. |
760 | | |
761 | | @param str the string to decode (and possibly write to). |
762 | | @param str_len length of the input string (or 0). |
763 | | @param dst output buffer (can be the same as src). |
764 | | @param dst_len size of the output buffer. |
765 | | @param length amount of data written to the destination buffer. |
766 | | |
767 | | */ |
768 | | TSReturnCode TSStringPercentDecode(const char *str, size_t str_len, char *dst, size_t dst_size, size_t *length); |
769 | | |
770 | | /* -------------------------------------------------------------------------- |
771 | | MIME headers */ |
772 | | |
773 | | /** |
774 | | Creates a MIME parser. The parser's data structure contains |
775 | | information about the header being parsed. A single MIME |
776 | | parser can be used multiple times, though not simultaneously. |
777 | | Before being used again, the parser must be cleared by calling |
778 | | TSMimeParserClear(). |
779 | | |
780 | | */ |
781 | | TSMimeParser TSMimeParserCreate(void); |
782 | | |
783 | | /** |
784 | | Clears the specified MIME parser so that it can be used again. |
785 | | |
786 | | @param parser to be cleared. |
787 | | |
788 | | */ |
789 | | void TSMimeParserClear(TSMimeParser parser); |
790 | | |
791 | | /** |
792 | | Destroys the specified MIME parser and frees the associated memory. |
793 | | |
794 | | @param parser to destroy. |
795 | | */ |
796 | | void TSMimeParserDestroy(TSMimeParser parser); |
797 | | |
798 | | /** |
799 | | Parse a MIME header date string. Candidate for deprecation in v10.0.0 |
800 | | */ |
801 | | time_t TSMimeParseDate(char const *const value_str, int const value_len); |
802 | | |
803 | | /** |
804 | | Creates a new MIME header within bufp. Release with a call to |
805 | | TSHandleMLocRelease(). |
806 | | |
807 | | @param bufp marshal buffer to contain the new MIME header. |
808 | | @param locp buffer pointer to contain the MLoc |
809 | | |
810 | | */ |
811 | | TSReturnCode TSMimeHdrCreate(TSMBuffer bufp, TSMLoc *locp); |
812 | | |
813 | | /** |
814 | | Destroys the MIME header located at hdr_loc within bufp. |
815 | | |
816 | | @param bufp marshal buffer containing the MIME header to destroy. |
817 | | @param offset location of the MIME header. |
818 | | |
819 | | */ |
820 | | TSReturnCode TSMimeHdrDestroy(TSMBuffer bufp, TSMLoc offset); |
821 | | |
822 | | /** |
823 | | Copies a specified MIME header to a specified marshal buffer, |
824 | | and returns the location of the copied MIME header within the |
825 | | destination marshal buffer. Unlike TSMimeHdrCopy(), you do not |
826 | | have to create the destination MIME header before cloning. Release |
827 | | the returned TSMLoc handle with a call to TSHandleMLocRelease(). |
828 | | |
829 | | @param dest_bufp destination marshal buffer. |
830 | | @param src_bufp source marshal buffer. |
831 | | @param src_hdr location of the source MIME header. |
832 | | @param locp where to store the location of the copied MIME header. |
833 | | |
834 | | */ |
835 | | TSReturnCode TSMimeHdrClone(TSMBuffer dest_bufp, TSMBuffer src_bufp, TSMLoc src_hdr, TSMLoc *locp); |
836 | | |
837 | | /** |
838 | | Copies the contents of the MIME header located at src_loc |
839 | | within src_bufp to the MIME header located at dest_loc within |
840 | | dest_bufp. TSMimeHdrCopy() works correctly even if src_bufp and |
841 | | dest_bufp point to different marshal buffers. Important: you must |
842 | | create the destination MIME header before copying into it--use |
843 | | TSMimeHdrCreate(). |
844 | | |
845 | | @param dest_bufp is the destination marshal buffer. |
846 | | @param dest_offset |
847 | | @param src_bufp is the source marshal buffer. |
848 | | @param src_offset |
849 | | |
850 | | */ |
851 | | TSReturnCode TSMimeHdrCopy(TSMBuffer dest_bufp, TSMLoc dest_offset, TSMBuffer src_bufp, TSMLoc src_offset); |
852 | | |
853 | | /** |
854 | | Formats the MIME header located at hdr_loc into the |
855 | | TSIOBuffer iobufp. |
856 | | |
857 | | @param offset The offset of the header to be copied to a TSIOBuffer. |
858 | | @param iobufp target TSIOBuffer. |
859 | | |
860 | | */ |
861 | | void TSMimeHdrPrint(TSMLoc offset, TSIOBuffer iobufp); |
862 | | |
863 | | /** |
864 | | Parses a MIME header. The MIME header must have already been |
865 | | allocated and both bufp and hdr_loc must point within that header. |
866 | | It is possible to parse a MIME header a single byte at a time |
867 | | using repeated calls to TSMimeHdrParse(). As long as an error |
868 | | does not occur, TSMimeHdrParse() consumes each single byte and |
869 | | asks for more. |
870 | | |
871 | | @param parser parses the specified MIME header. |
872 | | @param bufp marshal buffer containing the MIME header to be parsed. |
873 | | @param offset |
874 | | @param start both an input and output. On input, the start |
875 | | argument points to the current position of the buffer being |
876 | | parsed. On return, start is modified to point past the last |
877 | | character parsed. |
878 | | @param end points to one byte after the end of the buffer. |
879 | | @return One of 3 possible int values: |
880 | | - TS_PARSE_ERROR if there is a parsing error. |
881 | | - TS_PARSE_DONE is returned when a "\r\n\r\n" pattern is |
882 | | encountered, indicating the end of the header. |
883 | | - TS_PARSE_CONT is returned if parsing of the header stopped |
884 | | because the end of the buffer was reached. |
885 | | |
886 | | */ |
887 | | TSParseResult TSMimeHdrParse(TSMimeParser parser, TSMBuffer bufp, TSMLoc offset, const char **start, const char *end); |
888 | | |
889 | | /** |
890 | | Calculates the length of the MIME header located at hdr_loc if it |
891 | | were returned as a string. This the length of the MIME header in |
892 | | its unparsed form. |
893 | | |
894 | | @param bufp marshal buffer containing the MIME header. |
895 | | @param offset location of the MIME header. |
896 | | @return string length of the MIME header located at hdr_loc. |
897 | | |
898 | | */ |
899 | | int TSMimeHdrLengthGet(TSMBuffer bufp, TSMLoc offset); |
900 | | |
901 | | /** |
902 | | Removes and destroys all the MIME fields within the MIME header |
903 | | located at hdr_loc within the marshal buffer bufp. |
904 | | |
905 | | @param bufp marshal buffer containing the MIME header. |
906 | | @param offset location of the MIME header. |
907 | | |
908 | | */ |
909 | | TSReturnCode TSMimeHdrFieldsClear(TSMBuffer bufp, TSMLoc offset); |
910 | | |
911 | | /** |
912 | | Returns a count of the number of MIME fields within the MIME header |
913 | | located at hdr_loc within the marshal buffer bufp. |
914 | | |
915 | | @param bufp marshal buffer containing the MIME header. |
916 | | @param offset location of the MIME header within bufp. |
917 | | @return number of MIME fields within the MIME header located |
918 | | at hdr_loc. |
919 | | |
920 | | */ |
921 | | int TSMimeHdrFieldsCount(TSMBuffer bufp, TSMLoc offset); |
922 | | |
923 | | /** |
924 | | Retrieves the location of a specified MIME field within the |
925 | | MIME header located at hdr_loc within bufp. The idx parameter |
926 | | specifies which field to retrieve. The fields are numbered from 0 |
927 | | to TSMimeHdrFieldsCount(bufp, hdr_loc) - 1. If idx does not lie |
928 | | within that range then TSMimeHdrFieldGet returns 0. Release the |
929 | | returned handle with a call to TSHandleMLocRelease. |
930 | | |
931 | | @param bufp marshal buffer containing the MIME header. |
932 | | @param hdr location of the MIME header. |
933 | | @param idx index of the field to get with base at 0. |
934 | | @return location of the specified MIME field. |
935 | | |
936 | | */ |
937 | | TSMLoc TSMimeHdrFieldGet(TSMBuffer bufp, TSMLoc hdr, int idx); |
938 | | |
939 | | /** |
940 | | Retrieves the TSMLoc location of a specified MIME field from within |
941 | | the MIME header located at hdr. The name and length parameters |
942 | | specify which field to retrieve. For each MIME field in the MIME |
943 | | header, a case insensitive string comparison is done between |
944 | | the field name and name. If TSMimeHdrFieldFind() cannot find the |
945 | | requested field, it returns TS_NULL_MLOC. Release the returned |
946 | | TSMLoc handle with a call to TSHandleMLocRelease(). |
947 | | |
948 | | @param bufp marshal buffer containing the MIME header field to find. |
949 | | @param hdr location of the MIME header containing the field. |
950 | | @param name of the field to retrieve. |
951 | | @param length string length of the string name. If length is -1, |
952 | | then name is assumed to be null-terminated. |
953 | | @return location of the requested MIME field. If the field could |
954 | | not be found, returns TS_NULL_MLOC. |
955 | | |
956 | | */ |
957 | | TSMLoc TSMimeHdrFieldFind(TSMBuffer bufp, TSMLoc hdr, const char *name, int length); |
958 | | |
959 | | /** |
960 | | Appends a MIME field to a header. The field is typically newly created via |
961 | | @a TSMimeHdrFieldCreateNamed. If the field was found via @a |
962 | | TSMimeHdrFieldFind and it existed already in the header, then this function |
963 | | call is effectively a no-op. If the field is newly created via @a |
964 | | TSMimeHdrFieldCreateNamed and a field with the same name already exists in |
965 | | the header, then the new field is added as a duplicate field. |
966 | | |
967 | | @param bufp marshal buffer containing the MIME header. Must be modifiable. |
968 | | @param hdr location of the MIME header to append the field to. |
969 | | @param field location of the MIME field to append to the header. |
970 | | @return TS_SUCCESS if the field was successfully appended to the header, |
971 | | TS_ERROR if the operation failed (e.g., if the buffer is read-only). |
972 | | |
973 | | */ |
974 | | TSReturnCode TSMimeHdrFieldAppend(TSMBuffer bufp, TSMLoc hdr, TSMLoc field); |
975 | | |
976 | | /** |
977 | | Removes the MIME field located at field within bufp from the |
978 | | header located at hdr within bufp. If the specified field cannot |
979 | | be found in the list of fields associated with the header then |
980 | | nothing is done. |
981 | | |
982 | | Note: removing the field does not destroy the field, it only |
983 | | detaches the field, hiding it from the printed output. The field |
984 | | can be reattached with a call to TSMimeHdrFieldAppend(). If you |
985 | | do not use the detached field you should destroy it with a call to |
986 | | TSMimeHdrFieldDestroy() and release the handle field with a call |
987 | | to TSHandleMLocRelease(). |
988 | | |
989 | | @param bufp contains the MIME field to remove. |
990 | | @param hdr location of the header containing the MIME field to |
991 | | be removed. This header could be an HTTP header or MIME header. |
992 | | @param field is the location of the field to remove. |
993 | | |
994 | | */ |
995 | | TSReturnCode TSMimeHdrFieldRemove(TSMBuffer bufp, TSMLoc hdr, TSMLoc field); |
996 | | |
997 | | TSReturnCode TSMimeHdrFieldCreate(TSMBuffer bufp, TSMLoc hdr, TSMLoc *locp); |
998 | | |
999 | | /**************************************************************************** |
1000 | | * Create a new field and assign it a name all in one call |
1001 | | ****************************************************************************/ |
1002 | | TSReturnCode TSMimeHdrFieldCreateNamed(TSMBuffer bufp, TSMLoc mh_mloc, const char *name, int name_len, TSMLoc *locp); |
1003 | | |
1004 | | /** |
1005 | | Destroys the MIME field located at field within bufp. You must |
1006 | | release the TSMLoc field with a call to TSHandleMLocRelease(). |
1007 | | |
1008 | | @param bufp contains the MIME field to be destroyed. |
1009 | | @param hdr location of the parent header containing the field |
1010 | | to be destroyed. This could be the location of a MIME header or |
1011 | | HTTP header. |
1012 | | @param field location of the field to be destroyed. |
1013 | | |
1014 | | */ |
1015 | | TSReturnCode TSMimeHdrFieldDestroy(TSMBuffer bufp, TSMLoc hdr, TSMLoc field); |
1016 | | |
1017 | | TSReturnCode TSMimeHdrFieldClone(TSMBuffer dest_bufp, TSMLoc dest_hdr, TSMBuffer src_bufp, TSMLoc src_hdr, TSMLoc src_field, |
1018 | | TSMLoc *locp); |
1019 | | TSReturnCode TSMimeHdrFieldCopy(TSMBuffer dest_bufp, TSMLoc dest_hdr, TSMLoc dest_field, TSMBuffer src_bufp, TSMLoc src_hdr, |
1020 | | TSMLoc src_field); |
1021 | | TSReturnCode TSMimeHdrFieldCopyValues(TSMBuffer dest_bufp, TSMLoc dest_hdr, TSMLoc dest_field, TSMBuffer src_bufp, TSMLoc src_hdr, |
1022 | | TSMLoc src_field); |
1023 | | TSMLoc TSMimeHdrFieldNext(TSMBuffer bufp, TSMLoc hdr, TSMLoc field); |
1024 | | TSMLoc TSMimeHdrFieldNextDup(TSMBuffer bufp, TSMLoc hdr, TSMLoc field); |
1025 | | int TSMimeHdrFieldLengthGet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field); |
1026 | | const char *TSMimeHdrFieldNameGet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int *length); |
1027 | | TSReturnCode TSMimeHdrFieldNameSet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, const char *name, int length); |
1028 | | |
1029 | | TSReturnCode TSMimeHdrFieldValuesClear(TSMBuffer bufp, TSMLoc hdr, TSMLoc field); |
1030 | | int TSMimeHdrFieldValuesCount(TSMBuffer bufp, TSMLoc hdr, TSMLoc field); |
1031 | | |
1032 | | const char *TSMimeHdrFieldValueStringGet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx, int *value_len_ptr); |
1033 | | int TSMimeHdrFieldValueIntGet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx); |
1034 | | int64_t TSMimeHdrFieldValueInt64Get(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx); |
1035 | | unsigned int TSMimeHdrFieldValueUintGet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx); |
1036 | | time_t TSMimeHdrFieldValueDateGet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field); |
1037 | | TSReturnCode TSMimeHdrFieldValueStringSet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx, const char *value, int length); |
1038 | | TSReturnCode TSMimeHdrFieldValueIntSet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx, int value); |
1039 | | TSReturnCode TSMimeHdrFieldValueInt64Set(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx, int64_t value); |
1040 | | TSReturnCode TSMimeHdrFieldValueUintSet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx, unsigned int value); |
1041 | | TSReturnCode TSMimeHdrFieldValueDateSet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, time_t value); |
1042 | | |
1043 | | TSReturnCode TSMimeHdrFieldValueAppend(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx, const char *value, int length); |
1044 | | /* These Insert() APIs should be considered. Use the corresponding Set() API instead */ |
1045 | | TSReturnCode TSMimeHdrFieldValueStringInsert(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx, const char *value, int length); |
1046 | | TSReturnCode TSMimeHdrFieldValueIntInsert(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx, int value); |
1047 | | TSReturnCode TSMimeHdrFieldValueUintInsert(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx, unsigned int value); |
1048 | | TSReturnCode TSMimeHdrFieldValueDateInsert(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, time_t value); |
1049 | | |
1050 | | TSReturnCode TSMimeHdrFieldValueDelete(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx); |
1051 | | const char *TSMimeHdrStringToWKS(const char *str, int length); |
1052 | | |
1053 | | /* |
1054 | | * Print as a MIME header date string. |
1055 | | */ |
1056 | | TSReturnCode TSMimeFormatDate(time_t const value_time, char *const value_str, int *const value_len); |
1057 | | |
1058 | | /* -------------------------------------------------------------------------- |
1059 | | HTTP headers */ |
1060 | | TSHttpParser TSHttpParserCreate(void); |
1061 | | void TSHttpParserClear(TSHttpParser parser); |
1062 | | void TSHttpParserDestroy(TSHttpParser parser); |
1063 | | |
1064 | | /** |
1065 | | Parses an HTTP request header. The HTTP header must have already |
1066 | | been created, and must reside inside the marshal buffer bufp. |
1067 | | The start argument points to the current position of the string |
1068 | | buffer being parsed. The end argument points to one byte after the |
1069 | | end of the buffer to be parsed. On return, TSHttpHdrParseReq() |
1070 | | modifies start to point past the last character parsed. |
1071 | | |
1072 | | It is possible to parse an HTTP request header a single byte at |
1073 | | a time using repeated calls to TSHttpHdrParseReq(). As long as |
1074 | | an error does not occur, the TSHttpHdrParseReq() function will |
1075 | | consume that single byte and ask for more. |
1076 | | |
1077 | | @param parser parses the HTTP header. |
1078 | | @param bufp marshal buffer containing the HTTP header to be parsed. |
1079 | | @param offset location of the HTTP header within bufp. |
1080 | | @param start both an input and output. On input, it points to the |
1081 | | current position of the string buffer being parsed. On return, |
1082 | | start is modified to point past the last character parsed. |
1083 | | @param end points to one byte after the end of the buffer to be parsed. |
1084 | | @return status of the parse: |
1085 | | - TS_PARSE_ERROR means there was a parsing error. |
1086 | | - TS_PARSE_DONE means that the end of the header was reached |
1087 | | (the parser encountered a "\r\n\r\n" pattern). |
1088 | | - TS_PARSE_CONT means that parsing of the header stopped because |
1089 | | the parser reached the end of the buffer (large headers can |
1090 | | span multiple buffers). |
1091 | | |
1092 | | */ |
1093 | | TSParseResult TSHttpHdrParseReq(TSHttpParser parser, TSMBuffer bufp, TSMLoc offset, const char **start, const char *end); |
1094 | | |
1095 | | TSParseResult TSHttpHdrParseResp(TSHttpParser parser, TSMBuffer bufp, TSMLoc offset, const char **start, const char *end); |
1096 | | |
1097 | | TSMLoc TSHttpHdrCreate(TSMBuffer bufp); |
1098 | | |
1099 | | /** |
1100 | | Destroys the HTTP header located at hdr_loc within the marshal |
1101 | | buffer bufp. Do not forget to release the handle hdr_loc with a |
1102 | | call to TSHandleMLocRelease(). |
1103 | | |
1104 | | */ |
1105 | | void TSHttpHdrDestroy(TSMBuffer bufp, TSMLoc offset); |
1106 | | |
1107 | | TSReturnCode TSHttpHdrClone(TSMBuffer dest_bufp, TSMBuffer src_bufp, TSMLoc src_hdr, TSMLoc *locp); |
1108 | | |
1109 | | /** |
1110 | | Copies the contents of the HTTP header located at src_loc within |
1111 | | src_bufp to the HTTP header located at dest_loc within dest_bufp. |
1112 | | TSHttpHdrCopy() works correctly even if src_bufp and dest_bufp |
1113 | | point to different marshal buffers. Make sure that you create the |
1114 | | destination HTTP header before copying into it. |
1115 | | |
1116 | | Note: TSHttpHdrCopy() appends the port number to the domain |
1117 | | of the URL portion of the header. For example, a copy of |
1118 | | http://www.example.com appears as http://www.example.com:80 in |
1119 | | the destination buffer. |
1120 | | |
1121 | | @param dest_bufp marshal buffer to contain the copied header. |
1122 | | @param dest_offset location of the copied header. |
1123 | | @param src_bufp marshal buffer containing the source header. |
1124 | | @param src_offset location of the source header. |
1125 | | |
1126 | | */ |
1127 | | TSReturnCode TSHttpHdrCopy(TSMBuffer dest_bufp, TSMLoc dest_offset, TSMBuffer src_bufp, TSMLoc src_offset); |
1128 | | |
1129 | | void TSHttpHdrPrint(TSMBuffer bufp, TSMLoc offset, TSIOBuffer iobufp); |
1130 | | |
1131 | | int TSHttpHdrLengthGet(TSMBuffer bufp, TSMLoc offset); |
1132 | | |
1133 | | TSHttpType TSHttpHdrTypeGet(TSMBuffer bufp, TSMLoc offset); |
1134 | | TSReturnCode TSHttpHdrTypeSet(TSMBuffer bufp, TSMLoc offset, TSHttpType type); |
1135 | | |
1136 | | int TSHttpHdrVersionGet(TSMBuffer bufp, TSMLoc offset); |
1137 | | TSReturnCode TSHttpHdrVersionSet(TSMBuffer bufp, TSMLoc offset, int ver); |
1138 | | |
1139 | | const char *TSHttpHdrMethodGet(TSMBuffer bufp, TSMLoc offset, int *length); |
1140 | | TSReturnCode TSHttpHdrMethodSet(TSMBuffer bufp, TSMLoc offset, const char *value, int length); |
1141 | | const char *TSHttpHdrHostGet(TSMBuffer bufp, TSMLoc offset, int *length); |
1142 | | TSReturnCode TSHttpHdrUrlGet(TSMBuffer bufp, TSMLoc offset, TSMLoc *locp); |
1143 | | TSReturnCode TSHttpHdrUrlSet(TSMBuffer bufp, TSMLoc offset, TSMLoc url); |
1144 | | |
1145 | | TSHttpStatus TSHttpHdrStatusGet(TSMBuffer bufp, TSMLoc offset); |
1146 | | /** This is a candidate for deprecation in v10.0.0 in favor of the version that takes the setter. */ |
1147 | | TSReturnCode TSHttpHdrStatusSet(TSMBuffer bufp, TSMLoc offset, TSHttpStatus status); |
1148 | | TSReturnCode TSHttpHdrStatusSet(TSMBuffer bufp, TSMLoc offset, TSHttpStatus status, TSHttpTxn txnp, std::string_view setter); |
1149 | | const char *TSHttpHdrReasonGet(TSMBuffer bufp, TSMLoc offset, int *length); |
1150 | | TSReturnCode TSHttpHdrReasonSet(TSMBuffer bufp, TSMLoc offset, const char *value, int length); |
1151 | | const char *TSHttpHdrReasonLookup(TSHttpStatus status); |
1152 | | |
1153 | | /* -------------------------------------------------------------------------- |
1154 | | Threads */ |
1155 | | TSThread TSThreadCreate(TSThreadFunc func, void *data); |
1156 | | TSThread TSThreadInit(void); |
1157 | | void TSThreadDestroy(TSThread thread); |
1158 | | void TSThreadWait(TSThread thread); |
1159 | | TSThread TSThreadSelf(void); |
1160 | | TSEventThread TSEventThreadSelf(void); |
1161 | | |
1162 | | /* -------------------------------------------------------------------------- |
1163 | | Mutexes */ |
1164 | | TSMutex TSMutexCreate(void); |
1165 | | void TSMutexDestroy(TSMutex mutexp); |
1166 | | void TSMutexLock(TSMutex mutexp); |
1167 | | TSReturnCode TSMutexLockTry(TSMutex mutexp); |
1168 | | |
1169 | | void TSMutexUnlock(TSMutex mutexp); |
1170 | | |
1171 | | /* -------------------------------------------------------------------------- |
1172 | | cachekey */ |
1173 | | /** |
1174 | | Creates (allocates memory for) a new cache key. |
1175 | | */ |
1176 | | TSCacheKey TSCacheKeyCreate(void); |
1177 | | |
1178 | | /** |
1179 | | Generates a key for an object to be cached (written to the cache). |
1180 | | |
1181 | | @param key to be associated with the cached object. Before |
1182 | | calling TSCacheKeySetDigest() you must create the key with |
1183 | | TSCacheKeyCreate(). |
1184 | | @param input string that uniquely identifies the object. In most |
1185 | | cases, it is the URL of the object. |
1186 | | @param length of the string input. |
1187 | | |
1188 | | */ |
1189 | | TSReturnCode TSCacheKeyDigestSet(TSCacheKey key, const char *input, int length); |
1190 | | |
1191 | | TSReturnCode TSCacheKeyDigestFromUrlSet(TSCacheKey key, TSMLoc url); |
1192 | | |
1193 | | /** |
1194 | | Associates a host name to the cache key. Use this function if the |
1195 | | cache has been partitioned by hostname. The hostname tells the |
1196 | | cache which volume to use for the object. |
1197 | | |
1198 | | @param key of the cached object. |
1199 | | @param hostname to associate with the cache key. |
1200 | | @param host_len length of the string hostname. |
1201 | | |
1202 | | */ |
1203 | | TSReturnCode TSCacheKeyHostNameSet(TSCacheKey key, const char *hostname, int host_len); |
1204 | | |
1205 | | TSReturnCode TSCacheKeyPinnedSet(TSCacheKey key, time_t pin_in_cache); |
1206 | | |
1207 | | /** |
1208 | | Destroys a cache key. You must destroy cache keys when you are |
1209 | | finished with them, i.e. after all reads and writes are completed. |
1210 | | |
1211 | | @param key to be destroyed. |
1212 | | |
1213 | | */ |
1214 | | TSReturnCode TSCacheKeyDestroy(TSCacheKey key); |
1215 | | |
1216 | | /* -------------------------------------------------------------------------- |
1217 | | cache url */ |
1218 | | TSReturnCode TSCacheUrlSet(TSHttpTxn txnp, const char *url, int length); |
1219 | | |
1220 | | TSReturnCode TSCacheKeyDataTypeSet(TSCacheKey key, TSCacheDataType type); |
1221 | | |
1222 | | /* -------------------------------------------------------------------------- |
1223 | | Configuration */ |
1224 | | unsigned int TSConfigSet(unsigned int id, void *data, TSConfigDestroyFunc funcp); |
1225 | | TSConfig TSConfigGet(unsigned int id); |
1226 | | void TSConfigRelease(unsigned int id, TSConfig configp); |
1227 | | void *TSConfigDataGet(TSConfig configp); |
1228 | | |
1229 | | TSReturnCode TSMgmtConfigFileAdd(const char *parent, const char *fileName); |
1230 | | |
1231 | | /* -------------------------------------------------------------------------- |
1232 | | Management */ |
1233 | | void TSMgmtUpdateRegister(TSCont contp, const char *plugin_name, const char *plugin_file_name = nullptr); |
1234 | | TSReturnCode TSMgmtIntGet(const char *var_name, TSMgmtInt *result); |
1235 | | TSReturnCode TSMgmtCounterGet(const char *var_name, TSMgmtCounter *result); |
1236 | | TSReturnCode TSMgmtFloatGet(const char *var_name, TSMgmtFloat *result); |
1237 | | TSReturnCode TSMgmtStringGet(const char *var_name, TSMgmtString *result); |
1238 | | TSReturnCode TSMgmtSourceGet(const char *var_name, TSMgmtSource *source); |
1239 | | TSReturnCode TSMgmtConfigFileAdd(const char *parent, const char *fileName); |
1240 | | TSReturnCode TSMgmtDataTypeGet(const char *var_name, TSRecordDataType *result); |
1241 | | |
1242 | | /* -------------------------------------------------------------------------- |
1243 | | TSHRTime, this is a candidate for deprecation in v10.0.0 */ |
1244 | | TSHRTime TShrtime(void); |
1245 | | |
1246 | | /* -------------------------------------------------------------------------- |
1247 | | Continuations */ |
1248 | | TSCont TSContCreate(TSEventFunc funcp, TSMutex mutexp); |
1249 | | void TSContDestroy(TSCont contp); |
1250 | | void TSContDataSet(TSCont contp, void *data); |
1251 | | void *TSContDataGet(TSCont contp); |
1252 | | TSAction TSContScheduleOnPool(TSCont contp, TSHRTime timeout, TSThreadPool tp); |
1253 | | TSAction TSContScheduleOnThread(TSCont contp, TSHRTime timeout, TSEventThread ethread); |
1254 | | std::vector<TSAction> TSContScheduleOnEntirePool(TSCont contp, TSHRTime timeout, TSThreadPool tp); |
1255 | | TSAction TSContScheduleEveryOnPool(TSCont contp, TSHRTime every /* millisecs */, TSThreadPool tp); |
1256 | | TSAction TSContScheduleEveryOnThread(TSCont contp, TSHRTime every /* millisecs */, TSEventThread ethread); |
1257 | | std::vector<TSAction> TSContScheduleEveryOnEntirePool(TSCont contp, TSHRTime every /* millisecs */, TSThreadPool tp); |
1258 | | TSReturnCode TSContThreadAffinitySet(TSCont contp, TSEventThread ethread); |
1259 | | TSEventThread TSContThreadAffinityGet(TSCont contp); |
1260 | | void TSContThreadAffinityClear(TSCont contp); |
1261 | | TSAction TSHttpSchedule(TSCont contp, TSHttpTxn txnp, TSHRTime timeout); |
1262 | | int TSContCall(TSCont contp, TSEvent event, void *edata); |
1263 | | TSMutex TSContMutexGet(TSCont contp); |
1264 | | |
1265 | | /* -------------------------------------------------------------------------- |
1266 | | Plugin lifecycle hooks */ |
1267 | | void TSLifecycleHookAdd(TSLifecycleHookID id, TSCont contp); |
1268 | | /* -------------------------------------------------------------------------- |
1269 | | HTTP hooks */ |
1270 | | void TSHttpHookAdd(TSHttpHookID id, TSCont contp); |
1271 | | |
1272 | | /* -------------------------------------------------------------------------- |
1273 | | HTTP sessions */ |
1274 | | void TSHttpSsnHookAdd(TSHttpSsn ssnp, TSHttpHookID id, TSCont contp); |
1275 | | void TSHttpSsnReenable(TSHttpSsn ssnp, TSEvent event); |
1276 | | int TSHttpSsnTransactionCount(TSHttpSsn ssnp); |
1277 | | /* Get the TSVConn from a session. */ |
1278 | | TSVConn TSHttpSsnClientVConnGet(TSHttpSsn ssnp); |
1279 | | TSVConn TSHttpSsnServerVConnGet(TSHttpSsn ssnp); |
1280 | | /* Get the TSVConn from a transaction. */ |
1281 | | TSVConn TSHttpTxnServerVConnGet(TSHttpTxn txnp); |
1282 | | |
1283 | | /* -------------------------------------------------------------------------- |
1284 | | SSL connections */ |
1285 | | /* Re-enable an SSL connection from a hook. |
1286 | | This must be called exactly once before the SSL connection will resume. */ |
1287 | | void TSVConnReenable(TSVConn sslvcp); |
1288 | | /* Extended version that allows for passing a status event on reenabling |
1289 | | */ |
1290 | | void TSVConnReenableEx(TSVConn sslvcp, TSEvent event); |
1291 | | /* Set the connection to go into blind tunnel mode */ |
1292 | | TSReturnCode TSVConnTunnel(TSVConn sslp); |
1293 | | /* Return the SSL object associated with the connection */ |
1294 | | TSSslConnection TSVConnSslConnectionGet(TSVConn sslp); |
1295 | | /* Return the file descriptoer associated with the connection */ |
1296 | | int TSVConnFdGet(TSVConn sslp); |
1297 | | /* Return the intermediate X509StoreCTX object that references the certificate being validated */ |
1298 | | TSSslVerifyCTX TSVConnSslVerifyCTXGet(TSVConn sslp); |
1299 | | /* Fetch a SSL context from the global lookup table */ |
1300 | | TSSslContext TSSslContextFindByName(const char *name); |
1301 | | TSSslContext TSSslContextFindByAddr(struct sockaddr const *); |
1302 | | /* Fetch SSL client contexts from the global lookup table */ |
1303 | | TSReturnCode TSSslClientContextsNamesGet(int n, const char **result, int *actual); |
1304 | | TSSslContext TSSslClientContextFindByName(const char *ca_paths, const char *ck_paths); |
1305 | | |
1306 | | /* Update SSL certs in internal storage from given path */ |
1307 | | TSReturnCode TSSslClientCertUpdate(const char *cert_path, const char *key_path); |
1308 | | TSReturnCode TSSslServerCertUpdate(const char *cert_path, const char *key_path); |
1309 | | |
1310 | | /* Update the transient secret table for SSL_CTX loading */ |
1311 | | TSReturnCode TSSslSecretSet(const char *secret_name, int secret_name_length, const char *secret_data, int secret_data_length); |
1312 | | |
1313 | | /* Returns secret with given name (not null terminted). If there is no secret with the given name, return value will |
1314 | | ** be null and secret_data_lenght will be zero. Calling code must free data buffer by calling TSfree(). */ |
1315 | | char *TSSslSecretGet(const char *secret_name, int secret_name_length, int *secret_data_length); |
1316 | | |
1317 | | TSReturnCode TSSslSecretUpdate(const char *secret_name, int secret_name_length); |
1318 | | |
1319 | | /* Create a new SSL context based on the settings in records.yaml */ |
1320 | | TSSslContext TSSslServerContextCreate(TSSslX509 cert, const char *certname, const char *rsp_file); |
1321 | | void TSSslContextDestroy(TSSslContext ctx); |
1322 | | TSReturnCode TSSslTicketKeyUpdate(char *ticketData, int ticketDataLen); |
1323 | | TSAcceptor TSAcceptorGet(TSVConn sslp); |
1324 | | TSAcceptor TSAcceptorGetbyID(int ID); |
1325 | | int TSAcceptorCount(); |
1326 | | int TSAcceptorIDGet(TSAcceptor acceptor); |
1327 | | TSReturnCode TSVConnProtocolDisable(TSVConn connp, const char *protocol_name); |
1328 | | TSReturnCode TSVConnProtocolEnable(TSVConn connp, const char *protocol_name); |
1329 | | |
1330 | | /* Returns 1 if the sslp argument refers to a SSL connection */ |
1331 | | int TSVConnIsSsl(TSVConn sslp); |
1332 | | /* Returns 1 if a certificate was provided in the TLS handshake, 0 otherwise. |
1333 | | */ |
1334 | | int TSVConnProvidedSslCert(TSVConn sslp); |
1335 | | const char *TSVConnSslSniGet(TSVConn sslp, int *length); |
1336 | | |
1337 | | TSSslSession TSSslSessionGet(const TSSslSessionID *session_id); |
1338 | | int TSSslSessionGetBuffer(const TSSslSessionID *session_id, char *buffer, int *len_ptr); |
1339 | | TSReturnCode TSSslSessionInsert(const TSSslSessionID *session_id, TSSslSession add_session, TSSslConnection ssl_conn); |
1340 | | TSReturnCode TSSslSessionRemove(const TSSslSessionID *session_id); |
1341 | | |
1342 | | /* -------------------------------------------------------------------------- |
1343 | | HTTP transactions */ |
1344 | | void TSHttpTxnHookAdd(TSHttpTxn txnp, TSHttpHookID id, TSCont contp); |
1345 | | TSHttpSsn TSHttpTxnSsnGet(TSHttpTxn txnp); |
1346 | | |
1347 | | /* Gets the client request header for a specified HTTP transaction. */ |
1348 | | TSReturnCode TSHttpTxnClientReqGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *offset); |
1349 | | /* Gets the client response header for a specified HTTP transaction. */ |
1350 | | TSReturnCode TSHttpTxnClientRespGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *offset); |
1351 | | /* Gets the server request header from a specified HTTP transaction. */ |
1352 | | TSReturnCode TSHttpTxnServerReqGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *offset); |
1353 | | /* Gets the server response header from a specified HTTP transaction. */ |
1354 | | TSReturnCode TSHttpTxnServerRespGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *offset); |
1355 | | /* Gets the cached request header for a specified HTTP transaction. */ |
1356 | | TSReturnCode TSHttpTxnCachedReqGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *offset); |
1357 | | /* Gets the cached response header for a specified HTTP transaction. */ |
1358 | | TSReturnCode TSHttpTxnCachedRespGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *offset); |
1359 | | |
1360 | | TSReturnCode TSHttpTxnPristineUrlGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *url_loc); |
1361 | | |
1362 | | /** |
1363 | | * @brief Gets the number of transactions between the Traffic Server proxy and the origin server from a single session. |
1364 | | * Any value greater than zero indicates connection reuse. |
1365 | | * |
1366 | | * @param txnp The transaction |
1367 | | * @return int The number of transactions between the Traffic Server proxy and the origin server from a single session |
1368 | | */ |
1369 | | int TSHttpTxnServerSsnTransactionCount(TSHttpTxn txnp); |
1370 | | |
1371 | | /** Get the effective URL for the transaction. |
1372 | | The effective URL is the URL taking in to account both the explicit |
1373 | | URL in the request and the HOST field. |
1374 | | |
1375 | | A possibly non-null terminated string is returned. |
1376 | | |
1377 | | @note The returned string is allocated and must be freed by the caller |
1378 | | after use with @c TSfree. |
1379 | | */ |
1380 | | char *TSHttpTxnEffectiveUrlStringGet(TSHttpTxn txnp, int *length /**< String length return, may be @c nullptr. */ |
1381 | | ); |
1382 | | |
1383 | | /** Get the effective URL for in the header (if any), with the scheme and host normalized to lower case letter. |
1384 | | The effective URL is the URL taking in to account both the explicit |
1385 | | URL in the request and the HOST field. |
1386 | | |
1387 | | A possibly non-null terminated string is returned. |
1388 | | |
1389 | | @return TS_SUCCESS if successful, TS_ERROR if no URL in header or other error. |
1390 | | */ |
1391 | | TSReturnCode TSHttpHdrEffectiveUrlBufGet(TSMBuffer hdr_buf, TSMLoc hdr_loc, char *buf, int64_t size, int64_t *length); |
1392 | | |
1393 | | void TSHttpTxnRespCacheableSet(TSHttpTxn txnp, int flag); |
1394 | | void TSHttpTxnReqCacheableSet(TSHttpTxn txnp, int flag); |
1395 | | |
1396 | | /** Set flag indicating whether or not to cache the server response for |
1397 | | given TSHttpTxn |
1398 | | |
1399 | | @note This should be done in the HTTP_READ_RESPONSE_HDR_HOOK or earlier. |
1400 | | |
1401 | | @note If TSHttpTxnRespCacheableSet() is not working the way you expect, |
1402 | | this may be the function you should use instead. |
1403 | | |
1404 | | @param txnp The transaction whose server response you do not want to store. |
1405 | | @param flag Set 0 to allow storing and 1 to disable storing. |
1406 | | |
1407 | | @return TS_SUCCESS. |
1408 | | */ |
1409 | | TSReturnCode TSHttpTxnServerRespNoStoreSet(TSHttpTxn txnp, int flag); |
1410 | | |
1411 | | /** Get flag indicating whether or not to cache the server response for |
1412 | | given TSHttpTxn |
1413 | | @param txnp The transaction whose server response you do not want to store. |
1414 | | |
1415 | | @return TS_SUCCESS. |
1416 | | */ |
1417 | | bool TSHttpTxnServerRespNoStoreGet(TSHttpTxn txnp); |
1418 | | TSReturnCode TSFetchPageRespGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *offset); |
1419 | | char *TSFetchRespGet(TSHttpTxn txnp, int *length); |
1420 | | TSReturnCode TSHttpTxnCacheLookupStatusGet(TSHttpTxn txnp, int *lookup_status); |
1421 | | |
1422 | | TSReturnCode TSHttpTxnTransformRespGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *offset); |
1423 | | |
1424 | | /** Set the @a port value for the inbound (user agent) connection in the transaction @a txnp. |
1425 | | This is used primarily where the connection is synthetic and therefore does not have a port. |
1426 | | @note @a port is in @b host @b order. |
1427 | | */ |
1428 | | void TSHttpTxnClientIncomingPortSet(TSHttpTxn txnp, int port); |
1429 | | |
1430 | | /** Get client address for transaction @a txnp. |
1431 | | Retrieves the socket address of the remote client that has |
1432 | | connected to Traffic Server for transaction @a txnp. The |
1433 | | return structure is the generic socket address storage in |
1434 | | order to be address-family agnostic. The user of this function |
1435 | | can then go on to do the appropriate thing with the type |
1436 | | specified in the ss_family field of the structure whether |
1437 | | that be for IPv4, IPv6, or any other address family. |
1438 | | |
1439 | | @return Client address for connection to client in transaction @a txnp. |
1440 | | |
1441 | | */ |
1442 | | struct sockaddr const *TSHttpTxnClientAddrGet(TSHttpTxn txnp); |
1443 | | /** Get the incoming address. |
1444 | | |
1445 | | @note The pointer is valid only for the current callback. Clients |
1446 | | that need to keep the value across callbacks must maintain their |
1447 | | own storage. |
1448 | | |
1449 | | @return Local address of the client connection for transaction @a txnp. |
1450 | | */ |
1451 | | struct sockaddr const *TSHttpTxnIncomingAddrGet(TSHttpTxn txnp); |
1452 | | /** Get the outgoing address. |
1453 | | |
1454 | | @note The pointer is valid only for the current callback. Clients |
1455 | | that need to keep the value across callbacks must maintain their |
1456 | | own storage. |
1457 | | |
1458 | | @return Local address of the server connection for transaction @a txnp. |
1459 | | */ |
1460 | | struct sockaddr const *TSHttpTxnOutgoingAddrGet(TSHttpTxn txnp); |
1461 | | /** Get the origin server address. |
1462 | | * |
1463 | | @note The pointer is valid only for the current callback. Clients |
1464 | | that need to keep the value across callbacks must maintain their |
1465 | | own storage. |
1466 | | |
1467 | | @return The address of the origin server for transaction @a txnp. |
1468 | | */ |
1469 | | struct sockaddr const *TSHttpTxnServerAddrGet(TSHttpTxn txnp); |
1470 | | /** Set the origin server address. |
1471 | | |
1472 | | This must be invoked before the origin server address is looked up. |
1473 | | If called no lookup is done, the address @a addr is used instead. |
1474 | | |
1475 | | @return @c TS_SUCCESS if the origin server address is set, @c TS_ERROR otherwise. |
1476 | | */ |
1477 | | TSReturnCode TSHttpTxnServerAddrSet(TSHttpTxn txnp, struct sockaddr const *addr /**< Address for origin server. */ |
1478 | | ); |
1479 | | |
1480 | | /** Get the next hop address. |
1481 | | * |
1482 | | @note The pointer is valid only for the current callback. Clients |
1483 | | that need to keep the value across callbacks must maintain their |
1484 | | own storage. |
1485 | | |
1486 | | @return The address of the next hop for transaction @a txnp. |
1487 | | */ |
1488 | | struct sockaddr const *TSHttpTxnNextHopAddrGet(TSHttpTxn txnp); |
1489 | | |
1490 | | /** Get the next hop name. |
1491 | | * |
1492 | | @note The pointer is valid only for the current callback. Clients |
1493 | | that need to keep the value across callbacks must maintain their |
1494 | | own storage. |
1495 | | |
1496 | | @return The name of the next hop for transaction @a txnp. |
1497 | | */ |
1498 | | const char *TSHttpTxnNextHopNameGet(TSHttpTxn txnp); |
1499 | | |
1500 | | /** Get the next hop port. |
1501 | | * |
1502 | | Retrieves the next hop parent port. |
1503 | | Returns -1 if not valid. |
1504 | | |
1505 | | @return The port of the next hop for transaction @a txnp. |
1506 | | |
1507 | | */ |
1508 | | int TSHttpTxnNextHopPortGet(TSHttpTxn txnp); |
1509 | | |
1510 | | TSReturnCode TSHttpTxnClientFdGet(TSHttpTxn txnp, int *fdp); |
1511 | | TSReturnCode TSHttpTxnOutgoingAddrSet(TSHttpTxn txnp, struct sockaddr const *addr); |
1512 | | TSReturnCode TSHttpTxnOutgoingTransparencySet(TSHttpTxn txnp, int flag); |
1513 | | TSReturnCode TSHttpTxnServerFdGet(TSHttpTxn txnp, int *fdp); |
1514 | | |
1515 | | /* TS-1008: the above TXN calls for the Client conn should work with SSN */ |
1516 | | struct sockaddr const *TSHttpSsnClientAddrGet(TSHttpSsn ssnp); |
1517 | | struct sockaddr const *TSHttpSsnIncomingAddrGet(TSHttpSsn ssnp); |
1518 | | TSReturnCode TSHttpSsnClientFdGet(TSHttpSsn ssnp, int *fdp); |
1519 | | /* TS-1008 END */ |
1520 | | |
1521 | | /** Change packet firewall mark for the client side connection |
1522 | | * |
1523 | | @note The change takes effect immediately |
1524 | | |
1525 | | @return TS_SUCCESS if the client connection was modified |
1526 | | */ |
1527 | | TSReturnCode TSHttpTxnClientPacketMarkSet(TSHttpTxn txnp, int mark); |
1528 | | |
1529 | | /** Change packet firewall mark for the server side connection |
1530 | | * |
1531 | | @note The change takes effect immediately, if no OS connection has been |
1532 | | made, then this sets the mark that will be used IF an OS connection |
1533 | | is established |
1534 | | |
1535 | | @return TS_SUCCESS if the (future?) server connection was modified |
1536 | | */ |
1537 | | TSReturnCode TSHttpTxnServerPacketMarkSet(TSHttpTxn txnp, int mark); |
1538 | | |
1539 | | /** Change packet DSCP for the client side connection |
1540 | | * |
1541 | | @note The change takes effect immediately |
1542 | | |
1543 | | @return TS_SUCCESS if the client connection was modified |
1544 | | */ |
1545 | | TSReturnCode TSHttpTxnClientPacketDscpSet(TSHttpTxn txnp, int dscp); |
1546 | | |
1547 | | /** Change packet DSCP for the server side connection |
1548 | | * |
1549 | | |
1550 | | @note The change takes effect immediately, if no OS connection has been |
1551 | | made, then this sets the mark that will be used IF an OS connection |
1552 | | is established |
1553 | | |
1554 | | @return TS_SUCCESS if the (future?) server connection was modified |
1555 | | */ |
1556 | | TSReturnCode TSHttpTxnServerPacketDscpSet(TSHttpTxn txnp, int dscp); |
1557 | | |
1558 | | /** |
1559 | | Sets an error type body to a transaction. Note that both string arguments |
1560 | | must be allocated with TSmalloc() or TSstrdup(). The mimetype argument is |
1561 | | optional, if not provided it defaults to "text/html". Sending an empty |
1562 | | string would prevent setting a content type header (but that is not advised). |
1563 | | |
1564 | | @param txnp HTTP transaction whose parent proxy to get. |
1565 | | @param buf The body message (must be heap allocated). |
1566 | | @param buflength Length of the body message. |
1567 | | @param mimetype The MIME type to set the response to (can be null, but must |
1568 | | be heap allocated if non-null). |
1569 | | */ |
1570 | | void TSHttpTxnErrorBodySet(TSHttpTxn txnp, char *buf, size_t buflength, char *mimetype); |
1571 | | |
1572 | | /** |
1573 | | Retrives the error body, if any, from a transaction. This would be a body as set |
1574 | | via the API body. |
1575 | | |
1576 | | @param txnp HTTP transaction whose parent proxy to get. |
1577 | | @param buflength Optional outpu pointer to the length of the body message. |
1578 | | @param mimetype Optional output pointer to the MIME type of the response. |
1579 | | */ |
1580 | | char *TSHttpTxnErrorBodyGet(TSHttpTxn txnp, size_t *buflength, char **mimetype); |
1581 | | |
1582 | | /** |
1583 | | Sets the Transaction's Next Hop Parent Strategy. |
1584 | | Calling this after TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK will |
1585 | | result in bad behavior. |
1586 | | |
1587 | | You can get this strategy pointer by calling TSHttpTxnParentStrategyGet(). |
1588 | | |
1589 | | @param txnp HTTP transaction whose parent strategy to set. |
1590 | | @param pointer to the given strategy. |
1591 | | |
1592 | | */ |
1593 | | void TSHttpTxnNextHopStrategySet(TSHttpTxn txnp, void const *strategy); |
1594 | | |
1595 | | /** |
1596 | | Retrieves a pointer to the current next hop selection strategy. |
1597 | | This value may be a nullptr due to: |
1598 | | - parent proxying not enabled |
1599 | | - no parent selection strategy (using parent.config) |
1600 | | |
1601 | | @param txnp HTTP transaction whose next hop strategy to get. |
1602 | | |
1603 | | */ |
1604 | | void const *TSHttpTxnNextHopStrategyGet(TSHttpTxn txnp); |
1605 | | |
1606 | | /** |
1607 | | Returns either null pointer or null terminated pointer to name. |
1608 | | DO NOT FREE. |
1609 | | |
1610 | | This value may be a nullptr due to: |
1611 | | - parent proxying not enabled |
1612 | | - no parent selection strategy (using parent.config) |
1613 | | |
1614 | | @param txnp HTTP transaction whose next hop strategy to get. |
1615 | | |
1616 | | */ |
1617 | | char const *TSHttpNextHopStrategyNameGet(void const *strategy); |
1618 | | |
1619 | | /** |
1620 | | Retrieves a pointer to the named strategy in the strategy table. |
1621 | | Returns nullptr if no strategy is set. |
1622 | | This uses the current transaction's state machine to get |
1623 | | access to UrlRewrite's NextHopStrategyFactory. |
1624 | | |
1625 | | @param txnp HTTP transaction which holds the strategy table. |
1626 | | @param name of the strategy to look up. |
1627 | | |
1628 | | */ |
1629 | | void const *TSHttpTxnNextHopNamedStrategyGet(TSHttpTxn txnp, const char *name); |
1630 | | |
1631 | | /** |
1632 | | Sets the parent proxy name and port. The string hostname is copied |
1633 | | into the TSHttpTxn; you can modify or delete the string after |
1634 | | calling TSHttpTxnParentProxySet(). |
1635 | | |
1636 | | @param txnp HTTP transaction whose parent proxy to set. |
1637 | | @param hostname parent proxy host name string. |
1638 | | @param port parent proxy port to set. |
1639 | | |
1640 | | */ |
1641 | | void TSHttpTxnParentProxySet(TSHttpTxn txnp, const char *hostname, int port); |
1642 | | |
1643 | | /** |
1644 | | Retrieves the parent proxy hostname and port, if parent |
1645 | | proxying is enabled. If parent proxying is not enabled, |
1646 | | TSHttpTxnParentProxyGet() sets hostname to nullptr and port to -1. |
1647 | | |
1648 | | @param txnp HTTP transaction whose parent proxy to get. |
1649 | | @param hostname of the parent proxy. |
1650 | | @param port parent proxy's port. |
1651 | | |
1652 | | */ |
1653 | | TSReturnCode TSHttpTxnParentProxyGet(TSHttpTxn txnp, const char **hostname, int *port); |
1654 | | |
1655 | | /** |
1656 | | Sets the parent proxy name and port. The string hostname is copied |
1657 | | into the TSHttpTxn; you can modify or delete the string after |
1658 | | calling TSHttpTxnParentProxySet(). |
1659 | | |
1660 | | @param txnp HTTP transaction whose parent proxy to set. |
1661 | | @param hostname parent proxy host name string. |
1662 | | @param port parent proxy port to set. |
1663 | | |
1664 | | */ |
1665 | | void TSHttpTxnParentProxySet(TSHttpTxn txnp, const char *hostname, int port); |
1666 | | |
1667 | | TSReturnCode TSHttpTxnParentSelectionUrlGet(TSHttpTxn txnp, TSMBuffer bufp, TSMLoc obj); |
1668 | | TSReturnCode TSHttpTxnParentSelectionUrlSet(TSHttpTxn txnp, TSMBuffer bufp, TSMLoc obj); |
1669 | | |
1670 | | void TSHttpTxnUntransformedRespCache(TSHttpTxn txnp, int on); |
1671 | | void TSHttpTxnTransformedRespCache(TSHttpTxn txnp, int on); |
1672 | | |
1673 | | /** |
1674 | | Notifies the HTTP transaction txnp that the plugin is |
1675 | | finished processing the current hook. The plugin tells the |
1676 | | transaction to either continue (TS_EVENT_HTTP_CONTINUE) or stop |
1677 | | (TS_EVENT_HTTP_ERROR). |
1678 | | |
1679 | | You must always reenable the HTTP transaction after the processing |
1680 | | of each transaction event. However, never reenable twice. |
1681 | | Reenabling twice is a serious error. |
1682 | | |
1683 | | @param txnp transaction to be reenabled. |
1684 | | @param event tells the transaction how to continue: |
1685 | | - TS_EVENT_HTTP_CONTINUE, which means that the transaction |
1686 | | should continue. |
1687 | | - TS_EVENT_HTTP_ERROR which terminates the transaction |
1688 | | and sends an error to the client if no response has already |
1689 | | been sent. |
1690 | | |
1691 | | */ |
1692 | | void TSHttpTxnReenable(TSHttpTxn txnp, TSEvent event); |
1693 | | TSReturnCode TSHttpCacheReenable(TSCacheTxn txnp, const TSEvent event, const void *data, const uint64_t size); |
1694 | | |
1695 | | /* The reserve API should only be use in TSAPI plugins, during plugin initialization! |
1696 | | The lookup methods can be used anytime, but are best used during initialization as well, |
1697 | | or at least "cache" the results for best performance. */ |
1698 | | TSReturnCode TSUserArgIndexReserve(TSUserArgType type, const char *name, const char *description, int *arg_idx); |
1699 | | TSReturnCode TSUserArgIndexNameLookup(TSUserArgType type, const char *name, int *arg_idx, const char **description); |
1700 | | TSReturnCode TSUserArgIndexLookup(TSUserArgType type, int arg_idx, const char **name, const char **description); |
1701 | | void TSUserArgSet(void *data, int arg_idx, void *arg); |
1702 | | void *TSUserArgGet(void *data, int arg_idx); |
1703 | | |
1704 | | /** Set the HTTP status code for a transaction. |
1705 | | * |
1706 | | * Sets the transaction's internal status state, triggering Traffic Server's |
1707 | | * error handling system. This is typically used for access control, |
1708 | | * authentication failures, and early transaction processing. Traffic Server |
1709 | | * will automatically generate an appropriate error response body. |
1710 | | * |
1711 | | * @note This is a candidate for deprecation in v10.0.0 in favor of the version |
1712 | | * that takes the setter. |
1713 | | * |
1714 | | * @param[in] txnp The associated transaction for the new status. |
1715 | | * @param[in] status The HTTP status code to set. |
1716 | | */ |
1717 | | void TSHttpTxnStatusSet(TSHttpTxn txnp, TSHttpStatus status); |
1718 | | |
1719 | | /** Set the HTTP status code for a transaction and track the entity that set it. |
1720 | | * |
1721 | | * Sets the transaction's internal status state, triggering Traffic Server's |
1722 | | * error handling system. This is typically used for access control, |
1723 | | * authentication failures, and early transaction processing. Traffic Server |
1724 | | * will automatically generate an appropriate error response body. |
1725 | | * |
1726 | | * @param[in] txnp The associated transaction for the new status. |
1727 | | * @param[in] status The HTTP status code to set. |
1728 | | * @param[in] setter Identifying label for the entity setting the status |
1729 | | * (e.g., plugin name). If empty, clears the current setter information. |
1730 | | */ |
1731 | | void TSHttpTxnStatusSet(TSHttpTxn txnp, TSHttpStatus status, std::string_view setter); |
1732 | | |
1733 | | TSHttpStatus TSHttpTxnStatusGet(TSHttpTxn txnp); |
1734 | | |
1735 | | void TSHttpTxnActiveTimeoutSet(TSHttpTxn txnp, int timeout); |
1736 | | void TSHttpTxnConnectTimeoutSet(TSHttpTxn txnp, int timeout); |
1737 | | void TSHttpTxnDNSTimeoutSet(TSHttpTxn txnp, int timeout); |
1738 | | void TSHttpTxnNoActivityTimeoutSet(TSHttpTxn txnp, int timeout); |
1739 | | |
1740 | | TSServerState TSHttpTxnServerStateGet(TSHttpTxn txnp); |
1741 | | |
1742 | | /* -------------------------------------------------------------------------- |
1743 | | Transaction specific debugging control */ |
1744 | | |
1745 | | /** |
1746 | | Set the transaction specific debugging flag for this transaction. |
1747 | | When turned on, internal debug messages related to this transaction |
1748 | | will be written even if the debug tag isn't on. |
1749 | | |
1750 | | @param txnp transaction to change. |
1751 | | @param on set to 1 to turn on, 0 to turn off. |
1752 | | */ |
1753 | | void TSHttpTxnDebugSet(TSHttpTxn txnp, int on); |
1754 | | /** |
1755 | | Returns the transaction specific debugging flag for this transaction. |
1756 | | |
1757 | | @param txnp transaction to check. |
1758 | | @return 1 if enabled, 0 otherwise. |
1759 | | */ |
1760 | | int TSHttpTxnDebugGet(TSHttpTxn txnp); |
1761 | | /** |
1762 | | Set the session specific debugging flag for this client session. |
1763 | | When turned on, internal debug messages related to this session and all transactions |
1764 | | in the session will be written even if the debug tag isn't on. |
1765 | | |
1766 | | @param ssnp Client session to change. |
1767 | | @param on set to 1 to turn on, 0 to turn off. |
1768 | | */ |
1769 | | void TSHttpSsnDebugSet(TSHttpSsn ssnp, int on); |
1770 | | /** |
1771 | | Returns the transaction specific debugging flag for this client session. |
1772 | | |
1773 | | @param txnp Client session to check. |
1774 | | @return 1 if enabled, 0 otherwise. |
1775 | | */ |
1776 | | int TSHttpSsnDebugGet(TSHttpSsn ssnp, int *on); |
1777 | | |
1778 | | /* -------------------------------------------------------------------------- |
1779 | | Intercepting Http Transactions */ |
1780 | | |
1781 | | /** |
1782 | | Allows a plugin take over the servicing of the request as though |
1783 | | it was the origin server. contp will be sent TS_EVENT_NET_ACCEPT. |
1784 | | The edata passed with TS_NET_EVENT_ACCEPT is an TSVConn just as |
1785 | | it would be for a normal accept. The plugin must act as if it is |
1786 | | an http server and read the http request and body off the TSVConn |
1787 | | and send an http response header and body. |
1788 | | |
1789 | | TSHttpTxnIntercept() must be called be called from only |
1790 | | TS_HTTP_READ_REQUEST_HOOK. Using TSHttpTxnIntercept will |
1791 | | bypass the Traffic Server cache. If response sent by the plugin |
1792 | | should be cached, use TSHttpTxnServerIntercept() instead. |
1793 | | TSHttpTxnIntercept() primary use is allow plugins to serve data |
1794 | | about their functioning directly. |
1795 | | |
1796 | | TSHttpTxnIntercept() must only be called once per transaction. |
1797 | | |
1798 | | @param contp continuation called to handle the interception. |
1799 | | @param txnp transaction to be intercepted. |
1800 | | |
1801 | | */ |
1802 | | void TSHttpTxnIntercept(TSCont contp, TSHttpTxn txnp); |
1803 | | |
1804 | | /** |
1805 | | Allows a plugin take over the servicing of the request as though |
1806 | | it was the origin server. In the event a request needs to be |
1807 | | made to the server for transaction txnp, contp will be sent |
1808 | | TS_EVENT_NET_ACCEPT. The edata passed with TS_NET_EVENT_ACCEPT |
1809 | | is an TSVConn just as it would be for a normal accept. The plugin |
1810 | | must act as if it is an http server and read the http request and |
1811 | | body off the TSVConn and send an http response header and body. |
1812 | | |
1813 | | TSHttpTxnInterceptServer() must be not be called after |
1814 | | the connection to the server has taken place. The last hook |
1815 | | last hook in that TSHttpTxnIntercept() can be called from is |
1816 | | TS_HTTP_READ_CACHE_HDR_HOOK. If a connection to the server is |
1817 | | not necessary, contp is not called. |
1818 | | |
1819 | | The response from the plugin is cached subject to standard |
1820 | | and configured http caching rules. Should the plugin wish the |
1821 | | response not be cached, the plugin must use appropriate http |
1822 | | response headers to prevent caching. The primary purpose of |
1823 | | TSHttpTxnInterceptServer() is allow plugins to provide gateways |
1824 | | to other protocols or to allow to plugin to it's own transport for |
1825 | | the next hop to the server. TSHttpTxnInterceptServer() overrides |
1826 | | parent cache configuration. |
1827 | | |
1828 | | TSHttpTxnInterceptServer() must only be called once per |
1829 | | transaction. |
1830 | | |
1831 | | @param contp continuation called to handle the interception |
1832 | | @param txnp transaction to be intercepted. |
1833 | | |
1834 | | */ |
1835 | | void TSHttpTxnServerIntercept(TSCont contp, TSHttpTxn txnp); |
1836 | | |
1837 | | /* -------------------------------------------------------------------------- |
1838 | | Initiate Http Connection */ |
1839 | | |
1840 | | /** |
1841 | | Allows the plugin to initiate an http connection. The TSVConn the |
1842 | | plugin receives as the result of successful operates identically to |
1843 | | one created through TSNetConnect. Aside from allowing the plugin |
1844 | | to set the client ip and port for logging, the functionality of |
1845 | | TSHttpConnect() is identical to connecting to localhost on the |
1846 | | proxy port with TSNetConnect(). TSHttpConnect() is more efficient |
1847 | | than TSNetConnect() to localhost since it avoids the overhead of |
1848 | | passing the data through the operating system. |
1849 | | |
1850 | | This returns a VConn that connected to the transaction. |
1851 | | |
1852 | | @param options a TSHttpConnectPluginOptions structure that specifies options. |
1853 | | */ |
1854 | | TSVConn TSHttpConnectPlugin(TSHttpConnectOptions *options); |
1855 | | |
1856 | | /** Backwards compatible version. |
1857 | | This function calls This provides a @a buffer_index of 8 and a @a buffer_water_mark of 0. |
1858 | | |
1859 | | @param addr Target address of the origin server. |
1860 | | @param tag A logging tag that can be accessed via the pitag field. May be @c nullptr. |
1861 | | @param id A logging id that can be access via the piid field. |
1862 | | */ |
1863 | | TSVConn TSHttpConnectWithPluginId(struct sockaddr const *addr, const char *tag, int64_t id); |
1864 | | |
1865 | | /** Backwards compatible version. |
1866 | | This provides a @a tag of "plugin" and an @a id of 0. |
1867 | | */ |
1868 | | TSVConn TSHttpConnect(struct sockaddr const *addr); |
1869 | | |
1870 | | /** |
1871 | | Get an instance of TSHttpConnectOptions with default values. |
1872 | | */ |
1873 | | TSHttpConnectOptions TSHttpConnectOptionsGet(TSConnectType connect_type); |
1874 | | |
1875 | | /** |
1876 | | Get the value of proxy.config.plugin.vc.default_buffer_index from the TSHttpTxn |
1877 | | */ |
1878 | | TSIOBufferSizeIndex TSPluginVCIOBufferIndexGet(TSHttpTxn txnp); |
1879 | | |
1880 | | /** |
1881 | | Get the value of proxy.config.plugin.vc.default_buffer_water_mark from the TSHttpTxn |
1882 | | */ |
1883 | | TSIOBufferWaterMark TSPluginVCIOBufferWaterMarkGet(TSHttpTxn txnp); |
1884 | | |
1885 | | /* -------------------------------------------------------------------------- |
1886 | | Initiate Transparent Http Connection */ |
1887 | | /** |
1888 | | Allows the plugin to initiate a transparent http connection. This operates |
1889 | | identically to TSHttpConnect except that it is treated as an intercepted |
1890 | | transparent connection by the session and transaction state machines. |
1891 | | |
1892 | | @param client_addr the address that the resulting connection will be seen as |
1893 | | coming from |
1894 | | @param server_addr the address that the resulting connection will be seen as |
1895 | | attempting to connect to when intercepted |
1896 | | @param vc will be set to point to the new TSVConn on success. |
1897 | | |
1898 | | */ |
1899 | | TSVConn TSHttpConnectTransparent(struct sockaddr const *client_addr, struct sockaddr const *server_addr); |
1900 | | |
1901 | | TSFetchSM TSFetchUrl(const char *request, int request_len, struct sockaddr const *addr, TSCont contp, |
1902 | | TSFetchWakeUpOptions callback_options, TSFetchEvent event); |
1903 | | void TSFetchPages(TSFetchUrlParams_t *params); |
1904 | | |
1905 | | /** |
1906 | | * Extended FetchSM's AIPs |
1907 | | */ |
1908 | | |
1909 | | /* |
1910 | | * Create FetchSM, this API will enable stream IO automatically. |
1911 | | * |
1912 | | * @param contp: continuation to be callbacked. |
1913 | | * @param method: request method. |
1914 | | * @param url: scheme://host[:port]/path. |
1915 | | * @param version: client http version, eg: "HTTP/1.1". |
1916 | | * @param client_addr: client addr sent to log. |
1917 | | * @param flags: can be bitwise OR of several TSFetchFlags. |
1918 | | * |
1919 | | * return TSFetchSM which should be destroyed by TSFetchDestroy(). |
1920 | | */ |
1921 | | TSFetchSM TSFetchCreate(TSCont contp, const char *method, const char *url, const char *version, struct sockaddr const *client_addr, |
1922 | | int flags); |
1923 | | |
1924 | | /* |
1925 | | * Set fetch flags to FetchSM Context |
1926 | | * |
1927 | | * @param fetch_sm: returned value of TSFetchCreate(). |
1928 | | * @param flags: can be bitwise OR of several TSFetchFlags. |
1929 | | * |
1930 | | * return void |
1931 | | */ |
1932 | | void TSFetchFlagSet(TSFetchSM fetch_sm, int flags); |
1933 | | |
1934 | | /* |
1935 | | * Create FetchSM, this API will enable stream IO automatically. |
1936 | | * |
1937 | | * @param fetch_sm: returned value of TSFetchCreate(). |
1938 | | * @param name: name of header. |
1939 | | * @param name_len: len of name. |
1940 | | * @param value: value of header. |
1941 | | * @param name_len: len of value. |
1942 | | * |
1943 | | * return TSFetchSM which should be destroyed by TSFetchDestroy(). |
1944 | | */ |
1945 | | void TSFetchHeaderAdd(TSFetchSM fetch_sm, const char *name, int name_len, const char *value, int value_len); |
1946 | | |
1947 | | /* |
1948 | | * Write data to FetchSM |
1949 | | * |
1950 | | * @param fetch_sm: returned value of TSFetchCreate(). |
1951 | | * @param data/len: data to be written to fetch sm. |
1952 | | */ |
1953 | | void TSFetchWriteData(TSFetchSM fetch_sm, const void *data, size_t len); |
1954 | | |
1955 | | /* |
1956 | | * Read up to *len* bytes from FetchSM into *buf*. |
1957 | | * |
1958 | | * @param fetch_sm: returned value of TSFetchCreate(). |
1959 | | * @param buf/len: buffer to contain data from fetch sm. |
1960 | | */ |
1961 | | ssize_t TSFetchReadData(TSFetchSM fetch_sm, void *buf, size_t len); |
1962 | | |
1963 | | /* |
1964 | | * Launch FetchSM to do http request, before calling this API, |
1965 | | * you should append http request header into fetch sm through |
1966 | | * TSFetchWriteData() API |
1967 | | * |
1968 | | * @param fetch_sm: comes from returned value of TSFetchCreate(). |
1969 | | */ |
1970 | | void TSFetchLaunch(TSFetchSM fetch_sm); |
1971 | | |
1972 | | /* |
1973 | | * Destroy FetchSM |
1974 | | * |
1975 | | * @param fetch_sm: returned value of TSFetchCreate(). |
1976 | | */ |
1977 | | void TSFetchDestroy(TSFetchSM fetch_sm); |
1978 | | |
1979 | | /* |
1980 | | * Set user-defined data in FetchSM |
1981 | | */ |
1982 | | void TSFetchUserDataSet(TSFetchSM fetch_sm, void *data); |
1983 | | |
1984 | | /* |
1985 | | * Get user-defined data in FetchSM |
1986 | | */ |
1987 | | void *TSFetchUserDataGet(TSFetchSM fetch_sm); |
1988 | | |
1989 | | /* |
1990 | | * Get client response hdr mbuffer |
1991 | | */ |
1992 | | TSMBuffer TSFetchRespHdrMBufGet(TSFetchSM fetch_sm); |
1993 | | |
1994 | | /* |
1995 | | * Get client response hdr mloc |
1996 | | */ |
1997 | | TSMLoc TSFetchRespHdrMLocGet(TSFetchSM fetch_sm); |
1998 | | |
1999 | | /* Check if HTTP State machine is internal or not */ |
2000 | | int TSHttpTxnIsInternal(TSHttpTxn txnp); |
2001 | | int TSHttpSsnIsInternal(TSHttpSsn ssnp); |
2002 | | |
2003 | | /* -------------------------------------------------------------------------- |
2004 | | HTTP alternate selection */ |
2005 | | TSReturnCode TSHttpAltInfoClientReqGet(TSHttpAltInfo infop, TSMBuffer *bufp, TSMLoc *offset); |
2006 | | TSReturnCode TSHttpAltInfoCachedReqGet(TSHttpAltInfo infop, TSMBuffer *bufp, TSMLoc *offset); |
2007 | | TSReturnCode TSHttpAltInfoCachedRespGet(TSHttpAltInfo infop, TSMBuffer *bufp, TSMLoc *offset); |
2008 | | void TSHttpAltInfoQualitySet(TSHttpAltInfo infop, float quality); |
2009 | | |
2010 | | /* -------------------------------------------------------------------------- |
2011 | | Actions */ |
2012 | | void TSActionCancel(TSAction actionp); |
2013 | | int TSActionDone(TSAction actionp); |
2014 | | |
2015 | | /* -------------------------------------------------------------------------- |
2016 | | VConnections */ |
2017 | | TSVIO TSVConnReadVIOGet(TSVConn connp); |
2018 | | TSVIO TSVConnWriteVIOGet(TSVConn connp); |
2019 | | int TSVConnClosedGet(TSVConn connp); |
2020 | | |
2021 | | TSVIO TSVConnRead(TSVConn connp, TSCont contp, TSIOBuffer bufp, int64_t nbytes); |
2022 | | TSVIO TSVConnWrite(TSVConn connp, TSCont contp, TSIOBufferReader readerp, int64_t nbytes); |
2023 | | void TSVConnClose(TSVConn connp); |
2024 | | void TSVConnAbort(TSVConn connp, int error); |
2025 | | void TSVConnShutdown(TSVConn connp, int read, int write); |
2026 | | |
2027 | | /* -------------------------------------------------------------------------- |
2028 | | Cache VConnections */ |
2029 | | int64_t TSVConnCacheObjectSizeGet(TSVConn connp); |
2030 | | |
2031 | | /* -------------------------------------------------------------------------- |
2032 | | Transformations */ |
2033 | | TSVConn TSTransformCreate(TSEventFunc event_funcp, TSHttpTxn txnp); |
2034 | | TSVConn TSTransformOutputVConnGet(TSVConn connp); |
2035 | | |
2036 | | /* -------------------------------------------------------------------------- |
2037 | | Net VConnections */ |
2038 | | struct sockaddr const *TSNetVConnRemoteAddrGet(TSVConn vc); |
2039 | | struct sockaddr const *TSNetVConnClientAddrGet(TSVConn vc); |
2040 | | |
2041 | | /** |
2042 | | Opens a network connection to the host specified by ip on the port |
2043 | | specified by port. If the connection is successfully opened, contp |
2044 | | is called back with the event TS_EVENT_NET_CONNECT and the new |
2045 | | network vconnection will be passed in the event data parameter. |
2046 | | If the connection is not successful, contp is called back with |
2047 | | the event TS_EVENT_NET_CONNECT_FAILED. |
2048 | | |
2049 | | @return something allows you to check if the connection is complete, |
2050 | | or cancel the attempt to connect. |
2051 | | |
2052 | | */ |
2053 | | TSAction TSNetConnect( |
2054 | | TSCont contp, /**< continuation that is called back when the attempted net connection either succeeds or fails. */ |
2055 | | struct sockaddr const *to /**< Address to which to connect. */ |
2056 | | ); |
2057 | | |
2058 | | /** |
2059 | | * Retrieves the continuation associated with creating the TSVConn |
2060 | | */ |
2061 | | TSCont TSNetInvokingContGet(TSVConn conn); |
2062 | | |
2063 | | /** |
2064 | | * Retrieves the transaction associated with creating the TSVConn |
2065 | | */ |
2066 | | TSHttpTxn TSNetInvokingTxnGet(TSVConn conn); |
2067 | | |
2068 | | TSAction TSNetAccept(TSCont contp, int port, int domain, int accept_threads); |
2069 | | |
2070 | | /** |
2071 | | Attempt to attach the contp continuation to sockets that have already been |
2072 | | opened by the traffic Server and defined as belonging to plugins (based on |
2073 | | records.yaml configuration). If a connection is successfully accepted, |
2074 | | the TS_EVENT_NET_ACCEPT is delivered to the continuation. The event |
2075 | | data will be a valid TSVConn bound to the accepted connection. |
2076 | | In order to configure such a socket, add the "plugin" keyword to a port |
2077 | | in proxy.config.http.server_ports like "8082:plugin" |
2078 | | Transparency/IP settings can also be defined, but a port cannot have |
2079 | | both the "ssl" or "plugin" keywords configured. |
2080 | | |
2081 | | Need to update records.yaml comments on proxy.config.http.server_ports |
2082 | | when this option is promoted from experimental. |
2083 | | */ |
2084 | | TSReturnCode TSPluginDescriptorAccept(TSCont contp); |
2085 | | |
2086 | | /** |
2087 | | Listen on all SSL ports for connections for the specified protocol name. |
2088 | | |
2089 | | TSNetAcceptNamedProtocol registers the specified protocol for all |
2090 | | statically configured TLS ports. When a client using the TLS Next Protocol |
2091 | | Negotiation extension negotiates the requested protocol, TrafficServer will |
2092 | | route the request to the given handler. Note that the protocol is not |
2093 | | registered on ports opened by other plugins. |
2094 | | |
2095 | | The event and data provided to the handler are the same as for |
2096 | | TSNetAccept(). If a connection is successfully accepted, the event code |
2097 | | will be TS_EVENT_NET_ACCEPT and the event data will be a valid TSVConn |
2098 | | bound to the accepted connection. |
2099 | | |
2100 | | Neither contp nor protocol are copied. They must remain valid for the |
2101 | | lifetime of the plugin. |
2102 | | |
2103 | | TSNetAcceptNamedProtocol fails if the requested protocol cannot be |
2104 | | registered on all of the configured TLS ports. If it fails, the protocol |
2105 | | will not be registered on any ports (ie.. no partial failure). |
2106 | | */ |
2107 | | TSReturnCode TSNetAcceptNamedProtocol(TSCont contp, const char *protocol); |
2108 | | |
2109 | | /** |
2110 | | Create a new port from the string specification used by the |
2111 | | proxy.config.http.server_ports configuration value. |
2112 | | */ |
2113 | | TSPortDescriptor TSPortDescriptorParse(const char *descriptor); |
2114 | | |
2115 | | /** |
2116 | | Start listening on the given port descriptor. If a connection is |
2117 | | successfully accepted, the TS_EVENT_NET_ACCEPT is delivered to the |
2118 | | continuation. The event data will be a valid TSVConn bound to the accepted |
2119 | | connection. |
2120 | | */ |
2121 | | TSReturnCode TSPortDescriptorAccept(TSPortDescriptor, TSCont); |
2122 | | |
2123 | | /* -------------------------------------------------------------------------- |
2124 | | DNS Lookups */ |
2125 | | TSAction TSHostLookup(TSCont contp, const char *hostname, size_t namelen); |
2126 | | /** Retrieve an address from the host lookup. |
2127 | | * |
2128 | | * @param lookup_result Result handle passed to event callback. |
2129 | | * @return A @c sockaddr with the address if successful, a @c nullptr if not. |
2130 | | */ |
2131 | | struct sockaddr const *TSHostLookupResultAddrGet(TSHostLookupResult lookup_result); |
2132 | | |
2133 | | /* TODO: Eventually, we might want something like this as well, but it requires |
2134 | | support for building the HostDBInfo struct: |
2135 | | void TSHostLookupResultSet(TSHttpTxn txnp, TSHostLookupResult result); |
2136 | | */ |
2137 | | |
2138 | | /* -------------------------------------------------------------------------- |
2139 | | Cache VConnections */ |
2140 | | /** |
2141 | | Asks the Traffic Server cache if the object corresponding to key |
2142 | | exists in the cache and can be read. If the object can be read, |
2143 | | the Traffic Server cache calls the continuation contp back with |
2144 | | the event TS_EVENT_CACHE_OPEN_READ. In this case, the cache also |
2145 | | passes contp a cache vconnection and contp can then initiate a |
2146 | | read operation on that vconnection using TSVConnRead. |
2147 | | |
2148 | | If the object cannot be read, the cache calls contp back with |
2149 | | the event TS_EVENT_CACHE_OPEN_READ_FAILED. The user (contp) |
2150 | | has the option to cancel the action returned by TSCacheRead. |
2151 | | Note that reentrant calls are possible, i.e. the cache can call |
2152 | | back the user (contp) in the same call. |
2153 | | |
2154 | | @param contp continuation to be called back if a read operation |
2155 | | is permissible. |
2156 | | @param key cache key corresponding to the object to be read. |
2157 | | @return something allowing the user to cancel or schedule the |
2158 | | cache read. |
2159 | | |
2160 | | */ |
2161 | | TSAction TSCacheRead(TSCont contp, TSCacheKey key); |
2162 | | |
2163 | | /** |
2164 | | Asks the Traffic Server cache if contp can start writing the |
2165 | | object (corresponding to key) to the cache. If the object |
2166 | | can be written, the cache calls contp back with the event |
2167 | | TS_EVENT_CACHE_OPEN_WRITE. In this case, the cache also passes |
2168 | | contp a cache vconnection and contp can then initiate a write |
2169 | | operation on that vconnection using TSVConnWrite. The object |
2170 | | is not committed to the cache until the vconnection is closed. |
2171 | | When all data has been transferred, the user (contp) must do |
2172 | | an TSVConnClose. In case of any errors, the user MUST do an |
2173 | | TSVConnAbort(contp, 0). |
2174 | | |
2175 | | If the object cannot be written, the cache calls contp back with |
2176 | | the event TS_EVENT_CACHE_OPEN_WRITE_FAILED. This can happen, |
2177 | | for example, if there is another object with the same key being |
2178 | | written to the cache. The user (contp) has the option to cancel |
2179 | | the action returned by TSCacheWrite. |
2180 | | |
2181 | | Note that reentrant calls are possible, i.e. the cache can call |
2182 | | back the user (contp) in the same call. |
2183 | | |
2184 | | @param contp continuation that the cache calls back (telling it |
2185 | | whether the write operation can proceed or not). |
2186 | | @param key cache key corresponding to the object to be cached. |
2187 | | @return something allowing the user to cancel or schedule the |
2188 | | cache write. |
2189 | | |
2190 | | */ |
2191 | | TSAction TSCacheWrite(TSCont contp, TSCacheKey key); |
2192 | | |
2193 | | /** |
2194 | | Removes the object corresponding to key from the cache. If the |
2195 | | object was removed successfully, the cache calls contp back |
2196 | | with the event TS_EVENT_CACHE_REMOVE. If the object was not |
2197 | | found in the cache, the cache calls contp back with the event |
2198 | | TS_EVENT_CACHE_REMOVE_FAILED. |
2199 | | |
2200 | | In both of these callbacks, the user (contp) does not have to do |
2201 | | anything. The user does not get any vconnection from the cache, |
2202 | | since no data needs to be transferred. When the cache calls |
2203 | | contp back with TS_EVENT_CACHE_REMOVE, the remove has already |
2204 | | been committed. |
2205 | | |
2206 | | @param contp continuation that the cache calls back reporting the |
2207 | | success or failure of the remove. |
2208 | | @param key cache key corresponding to the object to be removed. |
2209 | | @return something allowing the user to cancel or schedule the |
2210 | | remove. |
2211 | | |
2212 | | */ |
2213 | | TSAction TSCacheRemove(TSCont contp, TSCacheKey key); |
2214 | | TSReturnCode TSCacheReady(int *is_ready); |
2215 | | TSAction TSCacheScan(TSCont contp, TSCacheKey key, int KB_per_second); |
2216 | | |
2217 | | /* Cache APIs that are not yet fully supported and/or frozen nor complete. */ |
2218 | | TSReturnCode TSCacheBufferInfoGet(TSCacheTxn txnp, uint64_t *length, uint64_t *offset); |
2219 | | |
2220 | | TSCacheHttpInfo TSCacheHttpInfoCreate(); |
2221 | | void TSCacheHttpInfoReqGet(TSCacheHttpInfo infop, TSMBuffer *bufp, TSMLoc *obj); |
2222 | | void TSCacheHttpInfoRespGet(TSCacheHttpInfo infop, TSMBuffer *bufp, TSMLoc *obj); |
2223 | | void TSCacheHttpInfoReqSet(TSCacheHttpInfo infop, TSMBuffer bufp, TSMLoc obj); |
2224 | | void TSCacheHttpInfoRespSet(TSCacheHttpInfo infop, TSMBuffer bufp, TSMLoc obj); |
2225 | | void TSCacheHttpInfoKeySet(TSCacheHttpInfo infop, TSCacheKey key); |
2226 | | void TSCacheHttpInfoSizeSet(TSCacheHttpInfo infop, int64_t size); |
2227 | | int TSCacheHttpInfoVector(TSCacheHttpInfo infop, void *data, int length); |
2228 | | int64_t TSCacheHttpInfoSizeGet(TSCacheHttpInfo infop); |
2229 | | |
2230 | | void TSVConnCacheHttpInfoSet(TSVConn connp, TSCacheHttpInfo infop); |
2231 | | |
2232 | | TSCacheHttpInfo TSCacheHttpInfoCopy(TSCacheHttpInfo infop); |
2233 | | void TSCacheHttpInfoReqGet(TSCacheHttpInfo infop, TSMBuffer *bufp, TSMLoc *offset); |
2234 | | void TSCacheHttpInfoRespGet(TSCacheHttpInfo infop, TSMBuffer *bufp, TSMLoc *offset); |
2235 | | void TSCacheHttpInfoDestroy(TSCacheHttpInfo infop); |
2236 | | |
2237 | | time_t TSCacheHttpInfoReqSentTimeGet(TSCacheHttpInfo infop); |
2238 | | time_t TSCacheHttpInfoRespReceivedTimeGet(TSCacheHttpInfo infop); |
2239 | | TSReturnCode TSHttpTxnCachedRespTimeGet(TSHttpTxn txnp, time_t *resp_time); |
2240 | | |
2241 | | /* -------------------------------------------------------------------------- |
2242 | | VIOs */ |
2243 | | void TSVIOReenable(TSVIO viop); |
2244 | | TSIOBuffer TSVIOBufferGet(TSVIO viop); |
2245 | | TSIOBufferReader TSVIOReaderGet(TSVIO viop); |
2246 | | int64_t TSVIONBytesGet(TSVIO viop); |
2247 | | void TSVIONBytesSet(TSVIO viop, int64_t nbytes); |
2248 | | int64_t TSVIONDoneGet(TSVIO viop); |
2249 | | void TSVIONDoneSet(TSVIO viop, int64_t ndone); |
2250 | | int64_t TSVIONTodoGet(TSVIO viop); |
2251 | | TSMutex TSVIOMutexGet(TSVIO viop); |
2252 | | TSCont TSVIOContGet(TSVIO viop); |
2253 | | TSVConn TSVIOVConnGet(TSVIO viop); |
2254 | | |
2255 | | /* -------------------------------------------------------------------------- |
2256 | | Buffers */ |
2257 | | TSIOBuffer TSIOBufferCreate(void); |
2258 | | |
2259 | | /** |
2260 | | Creates a new TSIOBuffer of the specified size. With this function, |
2261 | | you can create smaller buffers than the 32K buffer created by |
2262 | | TSIOBufferCreate(). In some situations using smaller buffers can |
2263 | | improve performance. |
2264 | | |
2265 | | @param index size of the new TSIOBuffer to be created. |
2266 | | @param new TSIOBuffer of the specified size. |
2267 | | |
2268 | | */ |
2269 | | TSIOBuffer TSIOBufferSizedCreate(TSIOBufferSizeIndex index); |
2270 | | |
2271 | | /** |
2272 | | The watermark of an TSIOBuffer is the minimum number of bytes |
2273 | | of data that have to be in the buffer before calling back any |
2274 | | continuation that has initiated a read operation on this buffer. |
2275 | | TSIOBufferWaterMarkGet() will provide the size of the watermark, |
2276 | | in bytes, for a specified TSIOBuffer. |
2277 | | |
2278 | | @param bufp buffer whose watermark the function gets. |
2279 | | |
2280 | | */ |
2281 | | int64_t TSIOBufferWaterMarkGet(TSIOBuffer bufp); |
2282 | | |
2283 | | /** |
2284 | | The watermark of an TSIOBuffer is the minimum number of bytes |
2285 | | of data that have to be in the buffer before calling back any |
2286 | | continuation that has initiated a read operation on this buffer. |
2287 | | As a writer feeds data into the TSIOBuffer, no readers are called |
2288 | | back until the amount of data reaches the watermark. Setting |
2289 | | a watermark can improve performance because it avoids frequent |
2290 | | callbacks to read small amounts of data. TSIOBufferWaterMarkSet() |
2291 | | assigns a watermark to a particular TSIOBuffer. |
2292 | | |
2293 | | @param bufp buffer whose water mark the function sets. |
2294 | | @param water_mark watermark setting, as a number of bytes. |
2295 | | |
2296 | | */ |
2297 | | void TSIOBufferWaterMarkSet(TSIOBuffer bufp, int64_t water_mark); |
2298 | | |
2299 | | void TSIOBufferDestroy(TSIOBuffer bufp); |
2300 | | TSIOBufferBlock TSIOBufferStart(TSIOBuffer bufp); |
2301 | | int64_t TSIOBufferCopy(TSIOBuffer bufp, TSIOBufferReader readerp, int64_t length, int64_t offset); |
2302 | | |
2303 | | /** |
2304 | | Writes length bytes of data contained in the string buf to the |
2305 | | TSIOBuffer bufp. Returns the number of bytes of data successfully |
2306 | | written to the TSIOBuffer. |
2307 | | |
2308 | | @param bufp is the TSIOBuffer to write into. |
2309 | | @param buf string to write into the TSIOBuffer. |
2310 | | @param length of the string buf. |
2311 | | @return length of data successfully copied into the buffer, |
2312 | | in bytes. |
2313 | | |
2314 | | */ |
2315 | | int64_t TSIOBufferWrite(TSIOBuffer bufp, const void *buf, int64_t length); |
2316 | | void TSIOBufferProduce(TSIOBuffer bufp, int64_t nbytes); |
2317 | | |
2318 | | TSIOBufferBlock TSIOBufferBlockNext(TSIOBufferBlock blockp); |
2319 | | const char *TSIOBufferBlockReadStart(TSIOBufferBlock blockp, TSIOBufferReader readerp, int64_t *avail); |
2320 | | int64_t TSIOBufferBlockReadAvail(TSIOBufferBlock blockp, TSIOBufferReader readerp); |
2321 | | char *TSIOBufferBlockWriteStart(TSIOBufferBlock blockp, int64_t *avail); |
2322 | | int64_t TSIOBufferBlockWriteAvail(TSIOBufferBlock blockp); |
2323 | | |
2324 | | TSIOBufferReader TSIOBufferReaderAlloc(TSIOBuffer bufp); |
2325 | | TSIOBufferReader TSIOBufferReaderClone(TSIOBufferReader readerp); |
2326 | | void TSIOBufferReaderFree(TSIOBufferReader readerp); |
2327 | | TSIOBufferBlock TSIOBufferReaderStart(TSIOBufferReader readerp); |
2328 | | void TSIOBufferReaderConsume(TSIOBufferReader readerp, int64_t nbytes); |
2329 | | int64_t TSIOBufferReaderAvail(TSIOBufferReader readerp); |
2330 | | int64_t TSIOBufferReaderCopy(TSIOBufferReader readerp, void *buf, int64_t length); |
2331 | | |
2332 | | struct sockaddr const *TSNetVConnLocalAddrGet(TSVConn vc); |
2333 | | |
2334 | | /* -------------------------------------------------------------------------- |
2335 | | Stats and configs based on librecords raw stats (this is preferred API until we |
2336 | | rewrite stats). |
2337 | | |
2338 | | This is available as of Apache TS v2.2.*/ |
2339 | | enum TSStatPersistence { |
2340 | | TS_STAT_PERSISTENT = 1, |
2341 | | TS_STAT_NON_PERSISTENT, |
2342 | | }; |
2343 | | |
2344 | | enum TSStatSync { |
2345 | | TS_STAT_SYNC_SUM = 0, |
2346 | | TS_STAT_SYNC_COUNT, |
2347 | | TS_STAT_SYNC_AVG, |
2348 | | TS_STAT_SYNC_TIMEAVG, |
2349 | | }; |
2350 | | |
2351 | | /* APIs to create new records.yaml configurations */ |
2352 | | TSReturnCode TSMgmtStringCreate(TSRecordType rec_type, const char *name, const TSMgmtString data_default, |
2353 | | TSRecordUpdateType update_type, TSRecordCheckType check_type, const char *check_regex, |
2354 | | TSRecordAccessType access_type); |
2355 | | TSReturnCode TSMgmtIntCreate(TSRecordType rec_type, const char *name, TSMgmtInt data_default, TSRecordUpdateType update_type, |
2356 | | TSRecordCheckType check_type, const char *check_regex, TSRecordAccessType access_type); |
2357 | | |
2358 | | /* Note that only TS_RECORDDATATYPE_INT is supported at this point. */ |
2359 | | int TSStatCreate(const char *the_name, TSRecordDataType the_type, TSStatPersistence persist, TSStatSync sync); |
2360 | | |
2361 | | void TSStatIntIncrement(int the_stat, TSMgmtInt amount); |
2362 | | void TSStatIntDecrement(int the_stat, TSMgmtInt amount); |
2363 | | /* Currently not supported. */ |
2364 | | /* void TSStatFloatIncrement(int the_stat, float amount); */ |
2365 | | /* void TSStatFloatDecrement(int the_stat, float amount); */ |
2366 | | |
2367 | | TSMgmtInt TSStatIntGet(int the_stat); |
2368 | | void TSStatIntSet(int the_stat, TSMgmtInt value); |
2369 | | /* Currently not supported. */ |
2370 | | /* TSReturnCode TSStatFloatGet(int the_stat, float* value); */ |
2371 | | /* TSReturnCode TSStatFloatSet(int the_stat, float value); */ |
2372 | | |
2373 | | TSReturnCode TSStatFindName(const char *name, int *idp); |
2374 | | |
2375 | | /** |
2376 | | Records.yaml file handling API. |
2377 | | |
2378 | | If you need to parse a records.yaml file and need to handle each node separately then |
2379 | | this API should be used, an example of this would be the conf_remap plugin. |
2380 | | |
2381 | | TSYAMLRecNodeHandler |
2382 | | |
2383 | | Callback function for the caller to deal with each parsed node. ``cfg`` holds |
2384 | | the details of the parsed field. `data` can be used to pass information along. |
2385 | | */ |
2386 | | using TSYAMLRecNodeHandler = TSReturnCode (*)(const TSYAMLRecCfgFieldData *cfg, void *data); |
2387 | | /** |
2388 | | Parse a YAML node following the record structure internals. On every scalar node |
2389 | | the @a handler callback will be invoked with the appropriate parsed fields. @a data |
2390 | | can be used to pass information along to every callback, this could be handy when |
2391 | | you need to read/set data inside the @c TSYAMLRecNodeHandler to be read at a later stage. |
2392 | | |
2393 | | This will return TS_ERROR if there was an issue while parsing the file. Particular node errors |
2394 | | should be handled by the @c TSYAMLRecNodeHandler implementation. |
2395 | | */ |
2396 | | TSReturnCode TSRecYAMLConfigParse(TSYaml node, TSYAMLRecNodeHandler handler, void *data); |
2397 | | |
2398 | | /* -------------------------------------------------------------------------- |
2399 | | logging api */ |
2400 | | |
2401 | | /** |
2402 | | The following enum values are flags, so they should be powers |
2403 | | of two. With the exception of TS_LOG_MODE_INVALID_FLAG, they |
2404 | | are all used to configure the creation of an TSTextLogObject |
2405 | | through the mode argument to TSTextLogObjectCreate(). |
2406 | | TS_LOG_MODE_INVALID_FLAG is used internally to check the validity |
2407 | | of this argument. Insert new flags before TS_LOG_MODE_INVALID_FLAG, |
2408 | | and set TS_LOG_MODE_INVALID_FLAG to the largest power of two of |
2409 | | the enum. |
2410 | | |
2411 | | */ |
2412 | | enum { |
2413 | | TS_LOG_MODE_ADD_TIMESTAMP = 1, |
2414 | | TS_LOG_MODE_DO_NOT_RENAME = 2, |
2415 | | TS_LOG_MODE_INVALID_FLAG = 4, |
2416 | | }; |
2417 | | |
2418 | | /** |
2419 | | This type represents a custom log file that you create with |
2420 | | TSTextLogObjectCreate(). Your plugin writes entries into this |
2421 | | log file using TSTextLogObjectWrite(). |
2422 | | |
2423 | | */ |
2424 | | using TSTextLogObject = struct tsapi_textlogobject *; |
2425 | | |
2426 | | using TSRecordDumpCb = void (*)(TSRecordType rec_type, void *edata, int registered, const char *name, TSRecordDataType data_type, |
2427 | | TSRecordData *datum); |
2428 | | |
2429 | | void TSRecordDump(int rec_type, TSRecordDumpCb callback, void *edata); |
2430 | | |
2431 | | /** |
2432 | | |
2433 | | Creates a new custom log file that your plugin can write to. You |
2434 | | can design the fields and inputs to the log file using the |
2435 | | TSTextLogObjectWrite() function. The logs you create are treated |
2436 | | like ordinary logs; they are rolled if log rolling is enabled. |
2437 | | |
2438 | | @param filename new log file being created. The new log file |
2439 | | is created in the logs directory. You can specify a path to a |
2440 | | subdirectory within the log directory, e.g. subdir/filename, |
2441 | | but make sure you create the subdirectory first. If you do |
2442 | | not specify a file name extension, the extension ".log" is |
2443 | | automatically added. |
2444 | | @param mode is one (or both) of the following: |
2445 | | - TS_LOG_MODE_ADD_TIMESTAMP Whenever the plugin makes a log |
2446 | | entry using TSTextLogObjectWrite (see below), it prepends |
2447 | | the entry with a timestamp. |
2448 | | - TS_LOG_MODE_DO_NOT_RENAME This means that if there is a |
2449 | | filename conflict, Traffic Server should not attempt to rename |
2450 | | the custom log. The consequence of a name conflict is that the |
2451 | | custom log will simply not be created, e.g. suppose you call: |
2452 | | @code |
2453 | | log = TSTextLogObjectCreate("squid" , mode, nullptr, &error); |
2454 | | @endcode |
2455 | | If mode is TS_LOG_MODE_DO_NOT_RENAME, you will NOT get a new |
2456 | | log (you'll get a null pointer) if squid.log already exists. |
2457 | | If mode is not TS_LOG_MODE_DO_NOT_RENAME, Traffic Server |
2458 | | tries to rename the log to a new name (it will try squid_1.log). |
2459 | | @param new_log_obj new custom log file. |
2460 | | @return error code: |
2461 | | - TS_LOG_ERROR_NO_ERROR No error; the log object has been |
2462 | | created successfully. |
2463 | | - TS_LOG_ERROR_OBJECT_CREATION Log object not created. This |
2464 | | error is rare and would most likely be caused by the system |
2465 | | running out of memory. |
2466 | | - TS_LOG_ERROR_FILENAME_CONFLICTS You get this error if mode = |
2467 | | TS_LOG_MODE_DO_NOT_RENAME, and if there is a naming conflict. |
2468 | | The log object is not created. |
2469 | | - TS_LOG_ERROR_FILE_ACCESS Log object not created because of |
2470 | | a file access problem (for example, no write permission to the |
2471 | | logging directory, or a specified subdirectory for the log file |
2472 | | does not exist). |
2473 | | |
2474 | | */ |
2475 | | TSReturnCode TSTextLogObjectCreate(const char *filename, int mode, TSTextLogObject *new_log_obj); |
2476 | | |
2477 | | /** |
2478 | | Writes a printf-style formatted statement to an TSTextLogObject |
2479 | | (a plugin custom log). |
2480 | | |
2481 | | @param the_object log object to write to. You must first create |
2482 | | this object with TSTextLogObjectCreate(). |
2483 | | @param format printf-style formatted statement to be printed. |
2484 | | @param ... parameters in the formatted statement. A newline is |
2485 | | automatically added to the end. |
2486 | | @return one of the following errors: |
2487 | | - TS_LOG_ERROR_NO_ERROR Means that the write was successful. |
2488 | | - TS_LOG_ERROR_LOG_SPACE_EXHAUSTED Means that Traffic Server |
2489 | | ran out of disk space for logs. If you see this error you might |
2490 | | want to roll logs more often. |
2491 | | - TS_LOG_ERROR_INTERNAL_ERROR Indicates some internal problem |
2492 | | with a log entry (such as an entry larger than the size of the |
2493 | | log write buffer). This error is very unusual. |
2494 | | |
2495 | | */ |
2496 | | TSReturnCode TSTextLogObjectWrite(TSTextLogObject the_object, const char *format, ...) TS_PRINTFLIKE(2, 3); |
2497 | | |
2498 | | /** |
2499 | | This immediately flushes the contents of the log write buffer for |
2500 | | the_object to disk. Use this call only if you want to make sure that |
2501 | | log entries are flushed immediately. This call has a performance |
2502 | | cost. Traffic Server flushes the log buffer automatically about |
2503 | | every 1 second. |
2504 | | |
2505 | | @param the_object custom log file whose write buffer is to be |
2506 | | flushed. |
2507 | | |
2508 | | */ |
2509 | | void TSTextLogObjectFlush(TSTextLogObject the_object); |
2510 | | |
2511 | | /** |
2512 | | Destroys a log object and releases the memory allocated to it. |
2513 | | Use this call if you are done with the log. |
2514 | | |
2515 | | @param the_object custom log to be destroyed. |
2516 | | |
2517 | | */ |
2518 | | TSReturnCode TSTextLogObjectDestroy(TSTextLogObject the_object); |
2519 | | |
2520 | | /** |
2521 | | Set log header. |
2522 | | |
2523 | | */ |
2524 | | void TSTextLogObjectHeaderSet(TSTextLogObject the_object, const char *header); |
2525 | | |
2526 | | /** |
2527 | | Enable/disable rolling. |
2528 | | |
2529 | | @param rolling_enabled a valid proxy.config.log.rolling_enabled value. |
2530 | | |
2531 | | */ |
2532 | | TSReturnCode TSTextLogObjectRollingEnabledSet(TSTextLogObject the_object, int rolling_enabled); |
2533 | | |
2534 | | /** |
2535 | | Set the rolling interval. |
2536 | | |
2537 | | */ |
2538 | | void TSTextLogObjectRollingIntervalSecSet(TSTextLogObject the_object, int rolling_interval_sec); |
2539 | | |
2540 | | /** |
2541 | | Set the rolling offset. rolling_offset_hr specifies the hour (between 0 and 23) when log rolling |
2542 | | should take place. |
2543 | | |
2544 | | */ |
2545 | | void TSTextLogObjectRollingOffsetHrSet(TSTextLogObject the_object, int rolling_offset_hr); |
2546 | | |
2547 | | /** |
2548 | | Set the rolling size. rolling_size_mb specifies the size in MB when log rolling |
2549 | | should take place. |
2550 | | |
2551 | | */ |
2552 | | void TSTextLogObjectRollingSizeMbSet(TSTextLogObject the_object, int rolling_size_mb); |
2553 | | |
2554 | | /** |
2555 | | Async disk IO read |
2556 | | |
2557 | | @return TS_SUCCESS or TS_ERROR. |
2558 | | */ |
2559 | | TSReturnCode TSAIORead(int fd, off_t offset, char *buf, size_t buffSize, TSCont contp); |
2560 | | |
2561 | | /** |
2562 | | Async disk IO buffer get |
2563 | | |
2564 | | @return char* to the buffer |
2565 | | */ |
2566 | | char *TSAIOBufGet(TSAIOCallback data); |
2567 | | |
2568 | | /** |
2569 | | Async disk IO get number of bytes |
2570 | | |
2571 | | @return the number of bytes |
2572 | | */ |
2573 | | int TSAIONBytesGet(TSAIOCallback data); |
2574 | | |
2575 | | /** |
2576 | | Async disk IO write |
2577 | | |
2578 | | @return TS_SUCCESS or TS_ERROR. |
2579 | | */ |
2580 | | TSReturnCode TSAIOWrite(int fd, off_t offset, char *buf, size_t bufSize, TSCont contp); |
2581 | | |
2582 | | /** |
2583 | | Async disk IO set number of threads |
2584 | | |
2585 | | @return TS_SUCCESS or TS_ERROR. |
2586 | | */ |
2587 | | TSReturnCode TSAIOThreadNumSet(int thread_num); |
2588 | | |
2589 | | /** |
2590 | | Check if transaction was aborted (due client/server errors etc.) |
2591 | | Client_abort is set as True, in case the abort was caused by the Client. |
2592 | | |
2593 | | @return 1 if transaction was aborted |
2594 | | */ |
2595 | | TSReturnCode TSHttpTxnAborted(TSHttpTxn txnp, bool *client_abort); |
2596 | | |
2597 | | TSVConn TSVConnCreate(TSEventFunc event_funcp, TSMutex mutexp); |
2598 | | TSVConn TSVConnFdCreate(int fd); |
2599 | | |
2600 | | /* api functions to access stats */ |
2601 | | /* ClientResp APIs exist as well and are exposed in PrivateFrozen */ |
2602 | | int TSHttpTxnClientReqHdrBytesGet(TSHttpTxn txnp); |
2603 | | int64_t TSHttpTxnClientReqBodyBytesGet(TSHttpTxn txnp); |
2604 | | int TSHttpTxnServerReqHdrBytesGet(TSHttpTxn txnp); |
2605 | | int64_t TSHttpTxnServerReqBodyBytesGet(TSHttpTxn txnp); |
2606 | | int TSHttpTxnPushedRespHdrBytesGet(TSHttpTxn txnp); |
2607 | | int64_t TSHttpTxnPushedRespBodyBytesGet(TSHttpTxn txnp); |
2608 | | int TSHttpTxnServerRespHdrBytesGet(TSHttpTxn txnp); |
2609 | | int64_t TSHttpTxnServerRespBodyBytesGet(TSHttpTxn txnp); |
2610 | | int TSHttpTxnClientRespHdrBytesGet(TSHttpTxn txnp); |
2611 | | int64_t TSHttpTxnClientRespBodyBytesGet(TSHttpTxn txnp); |
2612 | | int TSVConnIsSslReused(TSVConn sslp); |
2613 | | |
2614 | | /**************************************************************************** |
2615 | | * Allow to set the body of a POST request. |
2616 | | ****************************************************************************/ |
2617 | | void TSHttpTxnServerRequestBodySet(TSHttpTxn txnp, char *buf, int64_t buflength); |
2618 | | |
2619 | | /** |
2620 | | Return the current (if set) SSL Cipher. This is still owned by the |
2621 | | core, and must not be free'd. |
2622 | | |
2623 | | @param sslp The connection pointer |
2624 | | |
2625 | | @return the SSL Cipher |
2626 | | */ |
2627 | | const char *TSVConnSslCipherGet(TSVConn sslp); |
2628 | | |
2629 | | /** |
2630 | | Return the current (if set) SSL Protocol. This is still owned by the |
2631 | | core, and must not be free'd. |
2632 | | |
2633 | | @param sslp The connection pointer |
2634 | | |
2635 | | @return the SSL Protocol |
2636 | | */ |
2637 | | const char *TSVConnSslProtocolGet(TSVConn sslp); |
2638 | | |
2639 | | /** |
2640 | | Return the current (if set) SSL Curve. This is still owned by the |
2641 | | core, and must not be free'd. |
2642 | | |
2643 | | @param txnp the transaction pointer |
2644 | | |
2645 | | @return the SSL Curve |
2646 | | */ |
2647 | | const char *TSVConnSslCurveGet(TSVConn sslp); |
2648 | | |
2649 | | /* NetVC timeout APIs. */ |
2650 | | void TSVConnInactivityTimeoutSet(TSVConn connp, TSHRTime timeout); |
2651 | | void TSVConnInactivityTimeoutCancel(TSVConn connp); |
2652 | | void TSVConnActiveTimeoutSet(TSVConn connp, TSHRTime timeout); |
2653 | | void TSVConnActiveTimeoutCancel(TSVConn connp); |
2654 | | |
2655 | | /* |
2656 | | ability to skip the remap phase of the State Machine |
2657 | | this only really makes sense in TS_HTTP_READ_REQUEST_HDR_HOOK |
2658 | | */ |
2659 | | void TSSkipRemappingSet(TSHttpTxn txnp, int flag); |
2660 | | |
2661 | | /* |
2662 | | Set or get various overridable configurations, for a transaction. This should |
2663 | | probably be done as early as possible, e.g. TS_HTTP_READ_REQUEST_HDR_HOOK. |
2664 | | */ |
2665 | | TSReturnCode TSHttpTxnConfigIntSet(TSHttpTxn txnp, TSOverridableConfigKey conf, TSMgmtInt value); |
2666 | | TSReturnCode TSHttpTxnConfigIntGet(TSHttpTxn txnp, TSOverridableConfigKey conf, TSMgmtInt *value); |
2667 | | TSReturnCode TSHttpTxnConfigFloatSet(TSHttpTxn txnp, TSOverridableConfigKey conf, TSMgmtFloat value); |
2668 | | TSReturnCode TSHttpTxnConfigFloatGet(TSHttpTxn txnp, TSOverridableConfigKey conf, TSMgmtFloat *value); |
2669 | | TSReturnCode TSHttpTxnConfigStringSet(TSHttpTxn txnp, TSOverridableConfigKey conf, const char *value, int length); |
2670 | | TSReturnCode TSHttpTxnConfigStringGet(TSHttpTxn txnp, TSOverridableConfigKey conf, const char **value, int *length); |
2671 | | |
2672 | | TSReturnCode TSHttpTxnConfigFind(const char *name, int length, TSOverridableConfigKey *conf, TSRecordDataType *type); |
2673 | | |
2674 | | /** |
2675 | | This is a generalization of the old TSHttpTxnFollowRedirect(), but gives finer |
2676 | | control over the behavior. Instead of using the Location: header for the new |
2677 | | destination, this API takes the new URL as a parameter. Calling this API |
2678 | | transfers the ownership of the URL from the plugin to the core, so you must |
2679 | | make sure it is heap allocated, and that you do not free it. |
2680 | | |
2681 | | Calling this API implicitly also enables the "Follow Redirect" feature, so |
2682 | | there is no need to set that overridable configuration as well. |
2683 | | |
2684 | | @param txnp the transaction pointer |
2685 | | @param url a heap allocated string with the URL |
2686 | | @param url_len the length of the URL |
2687 | | */ |
2688 | | void TSHttpTxnRedirectUrlSet(TSHttpTxn txnp, const char *url, const int url_len); |
2689 | | |
2690 | | /** |
2691 | | Return the current (if set) redirection URL string. This is still owned by the |
2692 | | core, and must not be free'd. |
2693 | | |
2694 | | @param txnp the transaction pointer |
2695 | | @param url_len_ptr a pointer to where the URL length is to be stored |
2696 | | |
2697 | | @return the url string |
2698 | | */ |
2699 | | const char *TSHttpTxnRedirectUrlGet(TSHttpTxn txnp, int *url_len_ptr); |
2700 | | |
2701 | | /** |
2702 | | Return the number of redirection retries we have done. This starts off |
2703 | | at zero, and can be used to select different URLs based on which attempt this |
2704 | | is. This can be useful for example when providing a list of URLs to try, and |
2705 | | do so in order until one succeeds. |
2706 | | |
2707 | | @param txnp the transaction pointer |
2708 | | |
2709 | | @return the redirect try count |
2710 | | */ |
2711 | | int TSHttpTxnRedirectRetries(TSHttpTxn txnp); |
2712 | | |
2713 | | /* Get current HTTP connection stats */ |
2714 | | int TSHttpCurrentClientConnectionsGet(void); |
2715 | | int TSHttpCurrentActiveClientConnectionsGet(void); |
2716 | | int TSHttpCurrentIdleClientConnectionsGet(void); |
2717 | | int TSHttpCurrentCacheConnectionsGet(void); |
2718 | | int TSHttpCurrentServerConnectionsGet(void); |
2719 | | |
2720 | | /* ===== Http Transactions ===== */ |
2721 | | TSReturnCode TSHttpTxnCachedRespModifiableGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *offset); |
2722 | | TSReturnCode TSHttpTxnCacheLookupStatusSet(TSHttpTxn txnp, int cachelookup); |
2723 | | TSReturnCode TSHttpTxnCacheLookupUrlGet(TSHttpTxn txnp, TSMBuffer bufp, TSMLoc obj); |
2724 | | TSReturnCode TSHttpTxnCacheLookupUrlSet(TSHttpTxn txnp, TSMBuffer bufp, TSMLoc obj); |
2725 | | TSReturnCode TSHttpTxnPrivateSessionSet(TSHttpTxn txnp, int private_session); |
2726 | | const char *TSHttpTxnCacheDiskPathGet(TSHttpTxn txnp, int *length); |
2727 | | int TSHttpTxnBackgroundFillStarted(TSHttpTxn txnp); |
2728 | | int TSHttpTxnIsWebsocket(TSHttpTxn txnp); |
2729 | | |
2730 | | /* Get the Txn's (HttpSM's) unique identifier, which is a sequence number since server start) */ |
2731 | | uint64_t TSHttpTxnIdGet(TSHttpTxn txnp); |
2732 | | |
2733 | | /* Get the Ssn's unique identifier */ |
2734 | | int64_t TSHttpSsnIdGet(TSHttpSsn ssnp); |
2735 | | |
2736 | | /* Expose internal Base64 Encoding / Decoding */ |
2737 | | TSReturnCode TSBase64Decode(const char *str, size_t str_len, unsigned char *dst, size_t dst_size, size_t *length); |
2738 | | TSReturnCode TSBase64Encode(const char *str, size_t str_len, char *dst, size_t dst_size, size_t *length); |
2739 | | |
2740 | | /* Get milestone timers, useful for measuring where we are spending time in the transaction processing */ |
2741 | | /** |
2742 | | Return the particular milestone timer for the transaction. If 0 is returned, it means |
2743 | | the transaction has not yet reached that milestone. Asking for an "unknown" milestone is |
2744 | | an error. |
2745 | | |
2746 | | @param txnp the transaction pointer |
2747 | | @param milestone the requested milestone timer |
2748 | | was created. |
2749 | | @param time a pointer to a TSHRTime where we will store the timer |
2750 | | |
2751 | | @return @c TS_SUCCESS if the milestone is supported, TS_ERROR otherwise |
2752 | | |
2753 | | */ |
2754 | | TSReturnCode TSHttpTxnMilestoneGet(TSHttpTxn txnp, TSMilestonesType milestone, TSHRTime *time); |
2755 | | |
2756 | | /** |
2757 | | Test whether a request / response header pair would be cacheable under the current |
2758 | | configuration. This would typically be used in TS_HTTP_READ_RESPONSE_HDR_HOOK, when |
2759 | | you have both the client request and server response ready. |
2760 | | |
2761 | | @param txnp the transaction pointer |
2762 | | @param request the client request header. If null, use the transactions client request. |
2763 | | @param response the server response header. If null, use the transactions origin response. |
2764 | | |
2765 | | @return 1 if the request / response is cacheable, 0 otherwise |
2766 | | */ |
2767 | | int TSHttpTxnIsCacheable(TSHttpTxn txnp, TSMBuffer request, TSMBuffer response); |
2768 | | |
2769 | | /** |
2770 | | Get the maximum age in seconds as indicated by the origin server. |
2771 | | This would typically be used in TS_HTTP_READ_RESPONSE_HDR_HOOK, when you have |
2772 | | the server response ready. |
2773 | | |
2774 | | @param txnp the transaction pointer |
2775 | | @param response the server response header. If null, use the transactions origin response. |
2776 | | |
2777 | | @return the age in seconds if specified by Cache-Control, -1 otherwise |
2778 | | */ |
2779 | | int TSHttpTxnGetMaxAge(TSHttpTxn txnp, TSMBuffer response); |
2780 | | |
2781 | | /** |
2782 | | Return a string representation for a TSServerState value. This is useful for plugin debugging. |
2783 | | |
2784 | | @param state the value of this TSServerState |
2785 | | |
2786 | | @return the string representation of the state |
2787 | | */ |
2788 | | const char *TSHttpServerStateNameLookup(TSServerState state); |
2789 | | |
2790 | | /** |
2791 | | Return a string representation for a TSHttpHookID value. This is useful for plugin debugging. |
2792 | | |
2793 | | @param hook the value of this TSHttpHookID |
2794 | | |
2795 | | @return the string representation of the hook ID |
2796 | | */ |
2797 | | const char *TSHttpHookNameLookup(TSHttpHookID hook); |
2798 | | |
2799 | | /** |
2800 | | Return a string representation for a TSEvent value. This is useful for plugin debugging. |
2801 | | |
2802 | | @param event the value of this TSHttpHookID |
2803 | | |
2804 | | @return the string representation of the event |
2805 | | */ |
2806 | | const char *TSHttpEventNameLookup(TSEvent event); |
2807 | | |
2808 | | /* APIs for dealing with UUIDs, either self made, or the system wide process UUID. See |
2809 | | https://docs.trafficserver.apache.org/en/latest/developer-guide/api/functions/TSUuidCreate.en.html |
2810 | | */ |
2811 | | TSUuid TSUuidCreate(void); |
2812 | | TSReturnCode TSUuidInitialize(TSUuid uuid, TSUuidVersion v); |
2813 | | void TSUuidDestroy(TSUuid uuid); |
2814 | | TSReturnCode TSUuidCopy(TSUuid dest, const TSUuid src); |
2815 | | const char *TSUuidStringGet(const TSUuid uuid); |
2816 | | TSUuidVersion TSUuidVersionGet(const TSUuid uuid); |
2817 | | TSReturnCode TSUuidStringParse(TSUuid uuid, const char *uuid_str); |
2818 | | TSReturnCode TSClientRequestUuidGet(TSHttpTxn txnp, char *uuid_str); |
2819 | | |
2820 | | /* Get the process global UUID, resets on every startup */ |
2821 | | TSUuid TSProcessUuidGet(void); |
2822 | | |
2823 | | /** |
2824 | | Returns the plugin_tag. |
2825 | | */ |
2826 | | const char *TSHttpTxnPluginTagGet(TSHttpTxn txnp); |
2827 | | |
2828 | | /* |
2829 | | * Return information about the client protocols. |
2830 | | */ |
2831 | | TSReturnCode TSHttpTxnClientProtocolStackGet(TSHttpTxn txnp, int count, const char **result, int *actual); |
2832 | | TSReturnCode TSHttpSsnClientProtocolStackGet(TSHttpSsn ssnp, int count, const char **result, int *actual); |
2833 | | const char *TSHttpTxnClientProtocolStackContains(TSHttpTxn txnp, char const *tag); |
2834 | | const char *TSHttpSsnClientProtocolStackContains(TSHttpSsn ssnp, char const *tag); |
2835 | | const char *TSNormalizedProtocolTag(char const *tag); |
2836 | | const char *TSRegisterProtocolTag(char const *tag); |
2837 | | |
2838 | | /* |
2839 | | * Return information about the server protocols. |
2840 | | */ |
2841 | | TSReturnCode TSHttpTxnServerProtocolStackGet(TSHttpTxn txnp, int count, const char **result, int *actual); |
2842 | | const char *TSHttpTxnServerProtocolStackContains(TSHttpTxn txnp, char const *tag); |
2843 | | |
2844 | | // If, for the given transaction, the URL has been remapped, this function puts the memory location of the "from" URL object in |
2845 | | // the variable pointed to by urlLocp, and returns TS_SUCCESS. (The URL object will be within memory allocated to the |
2846 | | // transaction object.) Otherwise, the function returns TS_ERROR. |
2847 | | // |
2848 | | TSReturnCode TSRemapFromUrlGet(TSHttpTxn txnp, TSMLoc *urlLocp); |
2849 | | |
2850 | | // If, for the given transaction, the URL has been remapped, this function puts the memory location of the "to" URL object in the |
2851 | | // variable pointed to by urlLocp, and returns TS_SUCCESS. (The URL object will be within memory allocated to the transaction |
2852 | | // object.) Otherwise, the function returns TS_ERROR. |
2853 | | // |
2854 | | TSReturnCode TSRemapToUrlGet(TSHttpTxn txnp, TSMLoc *urlLocp); |
2855 | | |
2856 | | // Get some plugin details from the TSRemapPluginInfo |
2857 | | void *TSRemapDLHandleGet(TSRemapPluginInfo plugin_info); |
2858 | | |
2859 | | // Override response behavior, and hard-set the state machine for whether to succeed or fail, and how. |
2860 | | void TSHttpTxnResponseActionSet(TSHttpTxn txnp, TSResponseAction *action); |
2861 | | |
2862 | | // Get the overridden response behavior set by previously called plugins. |
2863 | | void TSHttpTxnResponseActionGet(TSHttpTxn txnp, TSResponseAction *action); |
2864 | | |
2865 | | /* |
2866 | | * Get a TSIOBufferReader to read the buffered body. The return value needs to be freed. |
2867 | | */ |
2868 | | TSIOBufferReader TSHttpTxnPostBufferReaderGet(TSHttpTxn txnp); |
2869 | | |
2870 | | /** |
2871 | | * @brief Get the client error received from the transaction |
2872 | | * |
2873 | | * @param txnp The transaction where the error code is stored |
2874 | | * @param error_class Either session/connection or stream/transaction error |
2875 | | * @param error_code Error code received from the client |
2876 | | */ |
2877 | | void TSHttpTxnClientReceivedErrorGet(TSHttpTxn txnp, uint32_t *error_class, uint64_t *error_code); |
2878 | | |
2879 | | /** |
2880 | | * @brief Get the client error sent from the transaction |
2881 | | * |
2882 | | * @param txnp The transaction where the error code is stored |
2883 | | * @param error_class Either session/connection or stream/transaction error |
2884 | | * @param error_code Error code sent to the client |
2885 | | */ |
2886 | | void TSHttpTxnClientSentErrorGet(TSHttpTxn txnp, uint32_t *error_class, uint64_t *error_code); |
2887 | | |
2888 | | /** |
2889 | | * @brief Get the server error received from the transaction |
2890 | | * |
2891 | | * @param txnp The transaction where the error code is stored |
2892 | | * @param error_class Either session/connection or stream/transaction error |
2893 | | * @param error_code Error code sent from the server |
2894 | | */ |
2895 | | void TSHttpTxnServerReceivedErrorGet(TSHttpTxn txnp, uint32_t *error_class, uint64_t *error_code); |
2896 | | |
2897 | | /** |
2898 | | * @brief Get the server error sent from the transaction |
2899 | | * |
2900 | | * @param txnp The transaction where the error code is stored |
2901 | | * @param error_class Either session/connection or stream/transaction error |
2902 | | * @param error_code Error code sent to the server |
2903 | | */ |
2904 | | void TSHttpTxnServerSentErrorGet(TSHttpTxn txnp, uint32_t *error_class, uint64_t *error_code); |
2905 | | |
2906 | | /** |
2907 | | * Initiate an HTTP/2 Server Push preload request. |
2908 | | * Use this api to register a URL that you want to preload with HTTP/2 Server Push. |
2909 | | * |
2910 | | * @param url the URL string to preload. |
2911 | | * @param url_len the length of the URL string. |
2912 | | */ |
2913 | | TSReturnCode TSHttpTxnServerPush(TSHttpTxn txnp, const char *url, int url_len); |
2914 | | |
2915 | | /** Retrieve the client side stream id for the stream of which the |
2916 | | * provided transaction is a part. |
2917 | | * |
2918 | | * @param[in] txnp The Transaction for which the stream id should be retrieved. |
2919 | | * @param[out] stream_id The stream id for this transaction. |
2920 | | * |
2921 | | * @return TS_ERROR if a stream id cannot be retrieved for the given |
2922 | | * transaction given its protocol. For instance, if txnp is an HTTP/1.1 |
2923 | | * transaction, then a TS_ERROR will be returned because HTTP/1.1 does not |
2924 | | * implement streams. |
2925 | | */ |
2926 | | TSReturnCode TSHttpTxnClientStreamIdGet(TSHttpTxn txnp, uint64_t *stream_id); |
2927 | | |
2928 | | /** Retrieve the client side priority for the stream of which the |
2929 | | * provided transaction is a part. |
2930 | | * |
2931 | | * @param[in] txnp The Transaction for which the stream id should be retrieved. |
2932 | | * @param[out] priority The priority for the stream in this transaction. |
2933 | | * |
2934 | | * @return TS_ERROR if a priority cannot be retrieved for the given |
2935 | | * transaction given its protocol. For instance, if txnp is an HTTP/1.1 |
2936 | | * transaction, then a TS_ERROR will be returned because HTTP/1.1 does not |
2937 | | * implement stream priorities. |
2938 | | */ |
2939 | | TSReturnCode TSHttpTxnClientStreamPriorityGet(TSHttpTxn txnp, TSHttpPriority *priority); |
2940 | | |
2941 | | /* |
2942 | | * Returns TS_SUCCESS if hostname is this machine, as used for parent and remap self-detection. |
2943 | | * Returns TS_ERROR if hostname is not this machine. |
2944 | | */ |
2945 | | TSReturnCode TSHostnameIsSelf(const char *hostname, size_t hostname_len); |
2946 | | |
2947 | | /* |
2948 | | * Gets the status of hostname in the outparam status, and the status reason in the outparam reason. |
2949 | | * The reason is a logical-or combination of the reasons in TSHostStatusReason. |
2950 | | * If either outparam is null, it will not be set and no error will be returned. |
2951 | | * Returns TS_SUCCESS if the hostname was a parent and existed in the HostStatus, else TS_ERROR. |
2952 | | */ |
2953 | | TSReturnCode TSHostStatusGet(const char *hostname, const size_t hostname_len, TSHostStatus *status, unsigned int *reason); |
2954 | | |
2955 | | /* |
2956 | | * Sets the status of hostname in status, down_time, and reason. |
2957 | | * The reason is a logical-or combination of the reasons in TSHostStatusReason. |
2958 | | */ |
2959 | | void TSHostStatusSet(const char *hostname, const size_t hostname_len, TSHostStatus status, const unsigned int down_time, |
2960 | | const unsigned int reason); |
2961 | | |
2962 | | /** |
2963 | | * Add one or more IP addresses or CIDR ranges to the per-client connection limit exempt list. |
2964 | | * This function allows plugins to programmatically add to the list of IP addresses |
2965 | | * that should be exempt from per-client connection limits (see |
2966 | | * proxy.config.net.per_client.max_connections_in). |
2967 | | * |
2968 | | * @param ip_ranges The IP address or CIDR range to exempt, or a comma-separated list of ranges. |
2969 | | * @return TS_SUCCESS if the exempt list was successfully updated, TS_ERROR otherwise. |
2970 | | */ |
2971 | | TSReturnCode TSConnectionLimitExemptListAdd(std::string_view ip_ranges); |
2972 | | |
2973 | | /** |
2974 | | * Remove one or more IP addresses or CIDR ranges from the per-client connection limit exempt list. |
2975 | | * This function allows plugins to programmatically remove from the list of IP addresses |
2976 | | * that should be exempt from per-client connection limits (see |
2977 | | * proxy.config.net.per_client.max_connections_in). |
2978 | | * |
2979 | | * @param ip_ranges The IP address or CIDR range to remove, or a comma-separated list of ranges. |
2980 | | * @return TS_SUCCESS if the exempt list was successfully updated, TS_ERROR otherwise. |
2981 | | */ |
2982 | | TSReturnCode TSConnectionLimitExemptListRemove(std::string_view ip_ranges); |
2983 | | |
2984 | | /** |
2985 | | * Clear the per-client connection limit exempt list. |
2986 | | * This function allows plugins to programmatically clear the list of IP addresses |
2987 | | * that should be exempt from per-client connection limits (see |
2988 | | * proxy.config.net.per_client.max_connections_in). |
2989 | | */ |
2990 | | void TSConnectionLimitExemptListClear(); |
2991 | | |
2992 | | /* |
2993 | | * Set or get various HTTP Transaction control settings. |
2994 | | */ |
2995 | | bool TSHttpTxnCntlGet(TSHttpTxn txnp, TSHttpCntlType ctrl); |
2996 | | TSReturnCode TSHttpTxnCntlSet(TSHttpTxn txnp, TSHttpCntlType ctrl, bool data); |
2997 | | |
2998 | | /** |
2999 | | * JSONRPC callback signature for method calls. |
3000 | | */ |
3001 | | using TSRPCMethodCb = void (*)(const char *id, TSYaml params); |
3002 | | /** |
3003 | | * JSONRPC callback signature for notification calls |
3004 | | */ |
3005 | | using TSRPCNotificationCb = void (*)(TSYaml params); |
3006 | | |
3007 | | /** |
3008 | | * @brief Method to perform a registration and validation when a plugin is expected to handle JSONRPC calls. |
3009 | | * |
3010 | | * @note YAMLCPP The JSONRPC library will only provide binary compatibility within the life-span of a major release. Plugins must |
3011 | | * check-in if they intent to handle RPC commands, passing their yamlcpp library version this function will validate it against |
3012 | | * the one used internally in TS. |
3013 | | * |
3014 | | * @param provider_name The name of the provider. |
3015 | | * @param provider_len The length of the provider string. |
3016 | | * @param yamlcpp_lib_version a string with the yamlcpp library version. |
3017 | | * @param yamlcpp_lib_len The length of the yamlcpp_lib_len string. |
3018 | | * @return A new TSRPCProviderHandle, nullptr if the yamlcpp_lib_version was not set, or the yamlcpp version does not match with |
3019 | | * the one used internally in TS. The returned TSRPCProviderHandle will be set with the provider's name. The caller should pass |
3020 | | * the returned TSRPCProviderHandle object to each subsequent TSRPCRegisterMethod/Notification* call. |
3021 | | */ |
3022 | | TSRPCProviderHandle TSRPCRegister(const char *provider_name, size_t provider_len, const char *yamlcpp_lib_version, |
3023 | | size_t yamlcpp_lib_len); |
3024 | | |
3025 | | /** |
3026 | | * @brief Add new registered method handler to the JSON RPC engine. |
3027 | | * |
3028 | | * @param name Call name to be exposed by the RPC Engine, this should match the incoming request. i.e: If you register 'get_stats' |
3029 | | * then the incoming jsonrpc call should have this very same name in the 'method' field. .. {...'method': |
3030 | | * 'get_stats'...} . |
3031 | | * @param name_len The length of the name string. |
3032 | | * @param callback The function to be registered. See @c TSRPCMethodCb |
3033 | | * @param info TSRPCProviderHandle pointer, this will be used to provide more context information about this call. This object |
3034 | | * ideally should be the one returned by the TSRPCRegister API. |
3035 | | * @param opt Pointer to @c TSRPCHandlerOptions object. This will be used to store specifics about a particular call, the rpc |
3036 | | * manager will use this object to perform certain actions. A copy of this object wil be stored by the rpc manager. |
3037 | | * |
3038 | | * @return TS_SUCCESS if the handler was successfully registered, TS_ERROR if the handler is already registered. |
3039 | | */ |
3040 | | TSReturnCode TSRPCRegisterMethodHandler(const char *name, size_t name_len, TSRPCMethodCb callback, TSRPCProviderHandle info, |
3041 | | const TSRPCHandlerOptions *opt); |
3042 | | |
3043 | | /** |
3044 | | * @brief Add new registered notification handler to the JSON RPC engine. |
3045 | | * |
3046 | | * @param name Call name to be exposed by the RPC Engine, this should match the incoming request. i.e: If you register 'get_stats' |
3047 | | * then the incoming jsonrpc call should have this very same name in the 'method' field. .. {...'method': |
3048 | | * 'get_stats'...} . |
3049 | | * @param name_len The length of the name string. |
3050 | | * @param callback The function to be registered. See @c TSRPCNotificationCb |
3051 | | * @param info TSRPCProviderHandle pointer, this will be used to provide more description for instance, when logging before or |
3052 | | * after a call. This object ideally should be the one returned by the TSRPCRegister API. |
3053 | | * @param opt Pointer to @c TSRPCHandlerOptions object. This will be used to store specifics about a particular call, the rpc |
3054 | | * manager will use this object to perform certain actions. A copy of this object wil be stored by the rpc manager. |
3055 | | * @return TS_SUCCESS if the handler was successfully registered, TS_ERROR if the handler is already registered. |
3056 | | */ |
3057 | | TSReturnCode TSRPCRegisterNotificationHandler(const char *name, size_t name_len, TSRPCNotificationCb callback, |
3058 | | TSRPCProviderHandle info, const TSRPCHandlerOptions *opt); |
3059 | | |
3060 | | /** |
3061 | | * @brief Function to notify the JSONRPC engine that the current handler is done working. |
3062 | | * |
3063 | | * This function must be used when implementing a 'method' rpc handler. Once the work is done and the response is ready to be sent |
3064 | | * back to the client, this function should be called. Is expected to set the YAML node as response. If the response is empty a |
3065 | | * 'success' message will be added to the client's response. |
3066 | | * |
3067 | | * @note This should not be used if you registered your handler as a notification: @c TSRPCNotificationCb |
3068 | | * @param resp The YAML node that contains the call response. |
3069 | | * @return TS_SUCCESS if no issues. TS_ERROR otherwise. |
3070 | | */ |
3071 | | TSReturnCode TSRPCHandlerDone(TSYaml resp); |
3072 | | |
3073 | | /** |
3074 | | * @brief Function to notify the JSONRPC engine that the current handler is done working and an error has arisen. |
3075 | | * |
3076 | | * @note This should not be used if you registered your handler as a notification: @c TSRPCNotificationCb |
3077 | | * call. |
3078 | | * @param code Error code. |
3079 | | * @param descr A text with a description of the error. |
3080 | | * @param descr_len The length of the description string. |
3081 | | * @note The @c code and @c descr will be part of the @c 'data' field in the jsonrpc error response. |
3082 | | * @return TS_SUCCESS if no issues. TS_ERROR otherwise. |
3083 | | */ |
3084 | | TSReturnCode TSRPCHandlerError(int code, const char *descr, size_t descr_len); |
3085 | | |
3086 | | /** Do another cache lookup with a different cache key. |
3087 | | * |
3088 | | * @param txnp Transaction. |
3089 | | * @param url URL to use for cache key. |
3090 | | * @param length Length of the string in @a url |
3091 | | * |
3092 | | * @return @c TS_SUCCESS on success, @c TS_ERROR if the @a txnp is invalid or the @a url is |
3093 | | * not a valid URL. |
3094 | | * |
3095 | | * If @a length is negative, @c strlen will be used to determine the length of @a url. |
3096 | | * |
3097 | | * @a url must be syntactically a URL, but otherwise it is just a string and does not need to |
3098 | | * be retrievable. |
3099 | | * |
3100 | | * This can only be called in a @c TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK callback. To set the cache |
3101 | | * key for the first lookup, use @c TSCacheUrlSet. |
3102 | | * |
3103 | | * @see TSCacheUrlSet |
3104 | | */ |
3105 | | TSReturnCode TSHttpTxnRedoCacheLookup(TSHttpTxn txnp, const char *url, int length); |
3106 | | |
3107 | | /* IP addr parsing. This is a candidate for deprecation in v10.0.0, in favor of libswoc */ |
3108 | | TSReturnCode TSIpStringToAddr(const char *str, size_t str_len, struct sockaddr *addr); |
3109 | | |
3110 | | /** |
3111 | | * Return information about the type of the transaction. Is it a tunnel transaction or fully parsed? |
3112 | | * If tunneled is it due to parse failures and TR_PASS or is it due to an explicit configuration. |
3113 | | * |
3114 | | * @param[in] txnp The Transaction for which the type should be retrieved. |
3115 | | * |
3116 | | * @return enun value of type TSTxnType |
3117 | | */ |
3118 | | TSTxnType TSHttpTxnTypeGet(TSHttpTxn txnp); |
3119 | | |
3120 | | TSReturnCode TSHttpTxnVerifiedAddrSet(TSHttpTxn txnp, const struct sockaddr *addr); |
3121 | | |
3122 | | TSReturnCode TSHttpTxnVerifiedAddrGet(TSHttpTxn txnp, const struct sockaddr **addr); |
3123 | | |
3124 | | /* Get Arbitrary Txn info such as cache lookup details etc as defined in TSHttpTxnInfoKey */ |
3125 | | /** |
3126 | | Return the particular txn info requested. |
3127 | | |
3128 | | @param txnp the transaction pointer |
3129 | | @param key the requested txn info. |
3130 | | @param TSMgmtInt a pointer to a integer where the return value is stored |
3131 | | |
3132 | | @return @c TS_SUCCESS if the requested info is supported, TS_ERROR otherwise |
3133 | | |
3134 | | */ |
3135 | | TSReturnCode TSHttpTxnInfoIntGet(TSHttpTxn txnp, TSHttpTxnInfoKey key, TSMgmtInt *value); |
3136 | | |
3137 | | /* Get Arbitrary Ssn info such as total transaction count etc as defined in TSHttpSsnInfoKey */ |
3138 | | /** |
3139 | | Return the particular ssn info requested. |
3140 | | |
3141 | | @param ssnp the transaction pointer |
3142 | | @param key the requested ssn info. |
3143 | | @param TSMgmtInt a pointer to a integer where the return value is stored |
3144 | | |
3145 | | @return @c TS_SUCCESS if the requested info is supported, TS_ERROR otherwise |
3146 | | |
3147 | | */ |
3148 | | TSReturnCode TSHttpSsnInfoIntGet(TSHttpSsn ssnp, TSHttpSsnInfoKey key, TSMgmtInt *value, uint64_t sub_key = 0); |
3149 | | |
3150 | | /**************************************************************************** |
3151 | | * TSHttpTxnCacheLookupCountGet |
3152 | | * Return: TS_SUCCESS/TS_ERROR |
3153 | | ****************************************************************************/ |
3154 | | TSReturnCode TSHttpTxnCacheLookupCountGet(TSHttpTxn txnp, int *lookup_count); |
3155 | | TSReturnCode TSHttpTxnServerRespIgnore(TSHttpTxn txnp); |
3156 | | TSReturnCode TSHttpTxnShutDown(TSHttpTxn txnp, TSEvent event); |
3157 | | TSReturnCode TSHttpTxnCloseAfterResponse(TSHttpTxn txnp, int should_close); |
3158 | | |
3159 | | int TSHttpTxnClientReqIsServerStyle(TSHttpTxn txnp); |
3160 | | TSReturnCode TSHttpTxnUpdateCachedObject(TSHttpTxn txnp); |
3161 | | |
3162 | | /** |
3163 | | Opens a network connection to the host specified by the 'to' sockaddr |
3164 | | spoofing the client addr to equal the 'from' sockaddr. |
3165 | | If the connection is successfully opened, contp |
3166 | | is called back with the event TS_EVENT_NET_CONNECT and the new |
3167 | | network vconnection will be passed in the event data parameter. |
3168 | | If the connection is not successful, contp is called back with |
3169 | | the event TS_EVENT_NET_CONNECT_FAILED. |
3170 | | |
3171 | | Note: It is possible to receive TS_EVENT_NET_CONNECT |
3172 | | even if the connection failed, because of the implementation of |
3173 | | network sockets in the underlying operating system. There is an |
3174 | | exception: if a plugin tries to open a connection to a port on |
3175 | | its own host machine, then TS_EVENT_NET_CONNECT is sent only |
3176 | | if the connection is successfully opened. In general, however, |
3177 | | your plugin needs to look for an TS_EVENT_VCONN_WRITE_READY to |
3178 | | be sure that the connection is successfully opened. |
3179 | | |
3180 | | @return TSAction which allows you to check if the connection is complete, |
3181 | | or cancel the attempt to connect. |
3182 | | |
3183 | | */ |
3184 | | TSAction TSNetConnectTransparent( |
3185 | | TSCont contp, /**< continuation that is called back when the attempted net connection either succeeds or fails. */ |
3186 | | struct sockaddr const *from, /**< Address to spoof as connection origin */ |
3187 | | struct sockaddr const *to /**< Address to which to connect. */ |
3188 | | ); |
3189 | | |
3190 | | /** |
3191 | | Allocates contiguous, aligned, raw (no construction) memory for a given number number of instances of type T. |
3192 | | |
3193 | | @return Pointer to raw (in spite of pointer type) memory for first instance. |
3194 | | */ |
3195 | | template <typename T> |
3196 | | T * |
3197 | | TSRalloc(size_t count = 1 /**< Number of instances of T to allocate storage for. */ |
3198 | | ) |
3199 | | { |
3200 | | return static_cast<std::remove_cv_t<T> *>(TSmalloc(count * sizeof(T))); |
3201 | | } |
3202 | | |
3203 | | /** |
3204 | | Return the particular PROXY protocol info requested. |
3205 | | |
3206 | | @param vconn the vconection pointer |
3207 | | @param key the requested PROXY protocol info. One of TSVConnPPInfoKey or TLV type ID |
3208 | | @param value a pointer to a const char pointer where the return value is stored |
3209 | | @param length a pointer to a integer where the length of return value is stored |
3210 | | |
3211 | | @return @c TS_SUCCESS if the requested info is supported, TS_ERROR otherwise |
3212 | | |
3213 | | */ |
3214 | | TSReturnCode TSVConnPPInfoGet(TSVConn vconn, uint16_t key, const char **value, int *length); |
3215 | | |
3216 | | /** |
3217 | | Return the particular PROXY protocol info requested. |
3218 | | |
3219 | | @param vconn the vconection pointer |
3220 | | @param key the requested PROXY protocol info. One of TSVConnPPInfoKey or TLV type ID |
3221 | | @param value a pointer to a integer where the return value is stored |
3222 | | |
3223 | | @return @c TS_SUCCESS if the requested info is supported, TS_ERROR otherwise |
3224 | | |
3225 | | */ |
3226 | | TSReturnCode TSVConnPPInfoIntGet(TSVConn vconn, uint16_t key, TSMgmtInt *value); |