File: TSClientProtocolStack.en.rst

package info (click to toggle)
trafficserver 9.2.5%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 53,008 kB
  • sloc: cpp: 345,484; ansic: 31,134; python: 24,200; sh: 7,271; makefile: 3,045; perl: 2,261; java: 277; pascal: 119; sql: 94; xml: 2
file content (120 lines) | stat: -rw-r--r-- 5,659 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
.. Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed
   with this work for additional information regarding copyright
   ownership.  The ASF licenses this file to you under the Apache
   License, Version 2.0 (the "License"); you may not use this file
   except in compliance with the License.  You may obtain a copy of
   the License at

      http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
   implied.  See the License for the specific language governing
   permissions and limitations under the License.


.. include:: ../../../common.defs

.. default-domain:: c

TSClientProtocolStack
*********************

Synopsis
========

.. code-block:: cpp

    #include <ts/ts.h>

.. function:: TSReturnCode TSHttpTxnClientProtocolStackGet(TSHttpTxn txnp, int count, char const** result, int* actual)

.. function:: TSReturnCode TSHttpTxnServerProtocolStackGet(TSHttpTxn txnp, int count, const char** result, int* actual)

.. function:: TSReturnCode TSHttpSsnClientProtocolStackGet(TSHttpSsn ssnp, int count, char const** result, int* actual)

.. function:: char const* TSHttpTxnClientProtocolStackContains(TSHttpTxn txnp)

.. function:: const char* TSHttpTxnServerProtocolStackContains(TSHttpTxn txnp, char const* tag)

.. function:: char const* TSHttpSsnClientProtocolStackContains(TSHttpSsn ssnp)

.. function:: char const* TSNormalizedProtocolTag(char const* tag)

.. function:: char const* TSRegisterProtocolTag(char const* tag)

Description
===========

These functions are used to explore the protocol stack of either the client (user agent) or origin server connection to
|TS|. The functions :func:`TSHttpTxnClientProtocolStackGet` and
:func:`TSHttpSsnClientProtocolStackGet` can be used to retrieve the entire protocol stack for the
user agent connection. The :func:`TSHttpTxnServerProtocolStackGet` can be used
to retrieve the entire protocol stack for
the origin server connection. :func:`TSHttpTxnClientProtocolStackContains`,
:func:`TSHttpSsnClientProtocolStackContains`, and
:func:`TSHttpTxnServerProtocolStackContains`  will check for a specific
protocol :arg:`tag` being present in the stack.

Each protocol is represented by tag which is a null terminated string. A particular tag will always
be returned as the same character pointer and so protocols can be reliably checked with pointer
comparisons. :func:`TSNormalizedProtocolTag` will return this character pointer for a specific
:arg:`tag`. A return value of :const:`NULL` indicates the provided :arg:`tag` is not registered as
a known protocol tag. :func:`TSRegisterProtocolTag` registers the :arg:`tag` and then returns its
normalized value. This is useful for plugins that provide custom protocols for user agents.

The protocols are ordered from higher level protocols to the lower level ones on which the higher
operate. For instance a stack might look like "http/1.1,tls/1.2,tcp,ipv4". For
:func:`TSHttpTxnClientProtocolStackGet`, :func:`TSHttpSsnClientProtocolStackGet`, and :func:`TSHttpTxnServerProtocolStackGet` these values
are placed in the array :arg:`result`. :arg:`count` is the maximum number of elements of
:arg:`result` that may be modified by the function call. If :arg:`actual` is not :const:`NULL` then
the actual number of elements in the protocol stack will be returned. If this is equal or less than
:arg:`count` then all elements were returned. If it is larger then some layers were omitted from
:arg:`result`. If the full stack is required :arg:`actual` can be used to resize :arg:`result` to
be sufficient to hold all of the elements and the function called again with updated :arg:`count`
and :arg:`result`. In practice the maximum number of elements is almost certain to be less
than 10 which therefore should suffice. These functions return :const:`TS_SUCCESS` on success and
:const:`TS_ERROR` on failure which should only occur if :arg:`txnp` or :arg:`ssnp` are invalid.

The :func:`TSHttpTxnClientProtocolStackContains`, :func:`TSHttpSsnClientProtocolStackContains`, and :func:`TSHttpTxnServerProtocolStackContains`
functions are provided for the convenience when only the presence of a protocol is of interest, not
its location or the presence of other protocols. These functions return :const:`NULL` if the protocol
:arg:`tag` is not present, and a pointer to the normalized tag if it is present. The strings are
matched with an anchor prefix search, as with debug tags. For instance if :arg:`tag` is "tls" then it
will match "tls/1.2" or "tls/1.3". This makes checking for TLS or IP more convenient. If more precision
is required the entire protocol stack can be retrieved and processed more thoroughly.

.. _protocol_tags:

The protocol tags defined by |TS|.

=========== =========
Protocol    Tag
=========== =========
HTTP/1.1    http/1.1
HTTP/1.0    http/1.0
HTTP/2      h2
WebSocket   ws
TLS 1.3     tls/1.3
TLS 1.2     tls/1.2
TLS 1.1     tls/1.1
TLS 1.0     tls/1.0
TCP         tcp
UDP         udp
IPv4        ipv4
IPv6        ipv6
QUIC        quic
=========== =========

Examples
--------

The example below is excerpted from `example/plugins/c-api/protocol_stack/protocol_stack.cc`
in the Traffic Server source distribution. It demonstrates how to
use :func:`TSHttpTxnClientProtocolStackGet` and :func:`TSHttpTxnClientProtocolStackContains`

.. literalinclude:: ../../../../example/plugins/c-api/protocol_stack/protocol_stack.cc
  :language: c
  :lines: 31-46