Coverage Report

Created: 2023-01-17 06:15

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