/src/PcapPlusPlus/Packet++/header/SdpLayer.h
Line | Count | Source (jump to first uncovered line) |
1 | | #pragma once |
2 | | |
3 | | #include "IpAddress.h" |
4 | | #include "TextBasedProtocol.h" |
5 | | #include <vector> |
6 | | |
7 | | /// @file |
8 | | |
9 | | /** |
10 | | * \namespace pcpp |
11 | | * \brief The main namespace for the PcapPlusPlus lib |
12 | | */ |
13 | | namespace pcpp |
14 | | { |
15 | | |
16 | | /** Protocol version (v) */ |
17 | 150 | #define PCPP_SDP_PROTOCOL_VERSION_FIELD "v" |
18 | | /** Originator and session identifier (o) */ |
19 | 75 | #define PCPP_SDP_ORIGINATOR_FIELD "o" |
20 | | /** Session name (s) */ |
21 | 0 | #define PCPP_SDP_SESSION_NAME_FIELD "s" |
22 | | /** Session title, media title or short information (i) */ |
23 | | #define PCPP_SDP_INFO_FIELD "i" |
24 | | /** URI of description (u) */ |
25 | | #define PCPP_SDP_URI_FIELD "u" |
26 | | /** Email address with optional name of contacts (e) */ |
27 | | #define PCPP_SDP_EMAIL_FIELD "e" |
28 | | /** Phone number with optional name of contacts (p) */ |
29 | | #define PCPP_SDP_PHONE_FIELD "p" |
30 | | /** Connection information (c) */ |
31 | 0 | #define PCPP_SDP_CONNECTION_INFO_FIELD "c" |
32 | | /** Bandwidth information (b) */ |
33 | | #define PCPP_SDP_BANDWIDTH_FIELD "b" |
34 | | /** Time the session is active (t) */ |
35 | 0 | #define PCPP_SDP_TIME_FIELD "t" |
36 | | /** Repeat times (r) */ |
37 | | #define PCPP_SDP_REPEAT_TIMES_FIELD "r" |
38 | | /** Time zone adjustments (z) */ |
39 | | #define PCPP_SDP_TIME_ZONE_FIELD "z" |
40 | | /** Encryption key (k) */ |
41 | | #define PCPP_SDP_ENCRYPTION_KEY_FIELD "k" |
42 | | /** Media attribute (a) */ |
43 | 2 | #define PCPP_SDP_MEDIA_ATTRIBUTE_FIELD "a" |
44 | | /** Media name and transport address (m) */ |
45 | 3.29k | #define PCPP_SDP_MEDIA_NAME_FIELD "m" |
46 | | |
47 | | /** |
48 | | * @class SdpLayer |
49 | | * Represents a SDP (Session Description Protocol) message. SDP is a text-based protocol described by a series of fields, one per line (lines are separated by CRLF). |
50 | | * The form of each field is as follows:<BR> |
51 | | * @code |
52 | | * [character]=[value] |
53 | | * @endcode |
54 | | * Each character represents a certain type of field. All field type are represented as macros in SdpLayer.h file |
55 | | * (for example: PCPP_SDP_ORIGINATOR_FIELD is a macro for the originator field (o=) ).<BR> |
56 | | * For more details about SDP structure please refer to its Wikipedia page: https://en.wikipedia.org/wiki/Session_Description_Protocol |
57 | | */ |
58 | | class SdpLayer : public TextBasedProtocolMessage |
59 | | { |
60 | | public: |
61 | | |
62 | | /** A constructor that creates the layer from an existing packet raw data |
63 | | * @param[in] data A pointer to the raw data |
64 | | * @param[in] dataLen Size of the data in bytes |
65 | | * @param[in] prevLayer A pointer to the previous layer |
66 | | * @param[in] packet A pointer to the Packet instance where layer will be stored in |
67 | | */ |
68 | | SdpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet); |
69 | | |
70 | | /** |
71 | | * An empty c'tor which initialize an empty message with no fields |
72 | | */ |
73 | | SdpLayer(); |
74 | | |
75 | | /** |
76 | | * A c'tor which initializes a message with the minimum required fields.<BR> |
77 | | * After this c'tor the message will look like this: |
78 | | * |
79 | | * @code |
80 | | * v=0 |
81 | | * o=[username] [sessionID] [sessionVersion] IN IP4 [ipAddress] |
82 | | * s=[sessionName] |
83 | | * c=IN IP4 [ipAddress] |
84 | | * t=[startTime] [endTime] |
85 | | * @endcode |
86 | | * |
87 | | * @param[in] username User's login on the originating host |
88 | | * @param[in] sessionID A globally unique identifier for the session |
89 | | * @param[in] sessionVersion A version number for this session description |
90 | | * @param[in] ipAddress The address of the machine from which the session is created |
91 | | * @param[in] sessionName A textual session name |
92 | | * @param[in] startTime The start time of the session |
93 | | * @param[in] stopTime The stop time of the session |
94 | | */ |
95 | | SdpLayer(const std::string& username, long sessionID, long sessionVersion, IPv4Address ipAddress, const std::string& sessionName, long startTime, long stopTime); |
96 | | |
97 | 0 | ~SdpLayer() {} |
98 | | |
99 | | /** |
100 | | * A copy constructor for this layer. Inherits the base copy constructor and doesn't add |
101 | | * anything else |
102 | | * @param[in] other The instance to copy from |
103 | | */ |
104 | 75 | SdpLayer(const SdpLayer& other) : TextBasedProtocolMessage(other) {} |
105 | | |
106 | | /** |
107 | | * An assignment operator overload for this layer. Inherits the base assignment operator |
108 | | * and doesn't add anything else |
109 | | * @param[in] other The instance to copy from |
110 | | */ |
111 | 0 | SdpLayer& operator=(const SdpLayer& other) { TextBasedProtocolMessage::operator=(other); return *this; } |
112 | | |
113 | | /** |
114 | | * The 'originator' field (o=) contains the IP address of the the machine from which the session is created. |
115 | | * This IP address can be used to track the RTP data relevant for the call. This method extracts this IP address from the 'originator' field and returns it. |
116 | | * A value of IPv4Address#Zero will be returned in the following cases: (1) if 'originator' field doesn't exist; (2) if it doesn't contain the IP address; |
117 | | * (3) if it contains a non-IPv4 address |
118 | | * @return The IP address of the the machine from which the session is created |
119 | | */ |
120 | | IPv4Address getOwnerIPv4Address() const; |
121 | | |
122 | | /** |
123 | | * The 'media-description' field (m=) contains the transport port to which the media stream is sent. This port can be used to track the RTP data relevant for the call. |
124 | | * This method extracts this port from the 'media-description' field and returns it. Since a SDP message can contain several 'media-description' fields, one for each media type |
125 | | * (e.g audio, image, etc.), the user is required to provide the media type. A value of 0 will be returned in the following cases: (1) if 'media-description' field doesn't |
126 | | * exist; (2) if provided media type was not found; (3) if 'media-description' field didn't contain a port |
127 | | * @param[in] mediaType The media type to search in |
128 | | * @return The transport port to which the media stream is sent |
129 | | */ |
130 | | uint16_t getMediaPort(const std::string& mediaType) const; |
131 | | |
132 | | /** |
133 | | * Adds a 'media-description' field (m=) with all necessary data and attribute fields (a=) with data relevant for this media.<BR> |
134 | | * After this method is run the following block of fields will be added at the end of the message: |
135 | | * |
136 | | * @code |
137 | | * m=[mediaType] [mediaPort] [mediaProtocol] [mediaFormat] |
138 | | * a=[1st media attribute] |
139 | | * a=[2nd media attribute] |
140 | | * ... |
141 | | * @endcode |
142 | | * |
143 | | * @param[in] mediaType The media type, usually "audio", "video", "text" or "image" |
144 | | * @param[in] mediaPort The transport port to which the media stream is sent |
145 | | * @param[in] mediaProtocol The transport protocol, usually "udp", "RTP/AVP" or "RTP/SAVP" |
146 | | * @param[in] mediaFormat A space-separated list of media format description. For example: "8 96" |
147 | | * @param[in] mediaAttributes A vector of media attributes. Each string in this vector will be |
148 | | * translated into a 'media-attribute' field (a=) |
149 | | * @return True if all fields were added properly or false if at least one field was failed to be added |
150 | | */ |
151 | | bool addMediaDescription(const std::string& mediaType, uint16_t mediaPort, const std::string& mediaProtocol, const std::string& mediaFormat, const std::vector<std::string> &mediaAttributes); |
152 | | |
153 | | // overridden methods |
154 | | |
155 | 75 | OsiModelLayer getOsiModelLayer() const { return OsiModelSesionLayer; } |
156 | | |
157 | | std::string toString() const; |
158 | | |
159 | | protected: |
160 | | |
161 | | // implementation of abstract methods |
162 | 579 | char getHeaderFieldNameValueSeparator() const { return '='; } |
163 | 579 | bool spacesAllowedBetweenHeaderFieldNameAndValue() const { return false; } |
164 | | |
165 | | }; |
166 | | } |