PcapPlusPlus  19.12
SipLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_SIP_LAYER
2 #define PACKETPP_SIP_LAYER
3 
4 #include "TextBasedProtocol.h"
5 
7 
12 namespace pcpp
13 {
14 // some popular SIP header fields
15 
17 #define PCPP_SIP_FROM_FIELD "From"
18 
19 #define PCPP_SIP_TO_FIELD "To"
20 
21 #define PCPP_SIP_VIA_FIELD "Via"
22 
23 #define PCPP_SIP_CALL_ID_FIELD "Call-ID"
24 
25 #define PCPP_SIP_CONTENT_TYPE_FIELD "Content-Type"
26 
27 #define PCPP_SIP_CONTENT_LENGTH_FIELD "Content-Length"
28 
29 #define PCPP_SIP_CONTENT_DISPOSITION_FIELD "Content-Disposition"
30 
31 #define PCPP_SIP_CONTENT_ENCODING_FIELD "Content-Encoding"
32 
33 #define PCPP_SIP_CONTENT_LANGUAGE_FIELD "Content-Language"
34 
35 #define PCPP_SIP_CSEQ_FIELD "CSeq"
36 
37 #define PCPP_SIP_CONTACT_FIELD "Contact"
38 
39 #define PCPP_SIP_MAX_FORWARDS_FIELD "Max-Forwards"
40 
41 #define PCPP_SIP_USER_AGENT_FIELD "User-Agent"
42 
43 #define PCPP_SIP_ACCEPT_FIELD "Accept"
44 
45 #define PCPP_SIP_ACCEPT_ENCODING_FIELD "Accept-Encoding"
46 
47 #define PCPP_SIP_ACCEPT_LANGUAGE_FIELD "Accept-Language"
48 
49 #define PCPP_SIP_ALLOW_FIELD "Allow"
50 
51 #define PCPP_SIP_AUTHORIZATION_FIELD "Authorization"
52 
53 #define PCPP_SIP_DATE_FIELD "Date"
54 
55 #define PCPP_SIP_MIME_VERSION_FIELD "MIME-Version"
56 
57 #define PCPP_SIP_REASON_FIELD "Reason"
58 
59 #define PCPP_SIP_SUPPORTED_FIELD "Supported"
60 
61 #define PCPP_SIP_SERVER_FIELD "Server"
62 
63 #define PCPP_SIP_WWW_AUTHENTICATE_FIELD "WWW-Authenticate"
64 
65 #define PCPP_SIP_RETRY_AFTER_FIELD "Retry-After"
66 
67 #define PCPP_SIP_RECORD_ROUTE_FIELD "Record-Route"
68 
69 
75  {
76  public:
77 
83  int getContentLength() const;
84 
98  HeaderField* setContentLength(int contentLength, const std::string prevFieldName = "");
99 
100  // Overridden methods
101 
103 
108  void parseNextLayer();
109 
113  void computeCalculateFields();
114 
115  protected:
116  SipLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : TextBasedProtocolMessage(data, dataLen, prevLayer, packet) {}
117  SipLayer() : TextBasedProtocolMessage() {}
118  SipLayer(const SipLayer& other) : TextBasedProtocolMessage(other) {}
119  SipLayer& operator=(const SipLayer& other) { TextBasedProtocolMessage::operator=(other); return *this; }
120 
121  // implementation of abstract methods
122  char getHeaderFieldNameValueSeparator() const { return ':'; }
123  bool spacesAllowedBetweenHeaderFieldNameAndValue() const { return true; }
124  };
125 
126 
127 
128  class SipRequestFirstLine;
129 
130 
140  class SipRequestLayer : public SipLayer
141  {
142  friend class SipRequestFirstLine;
143 
144  public:
149  {
180  };
181 
188  SipRequestLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
189 
197  SipRequestLayer(SipMethod method, std::string requestUri, std::string version = "SIP/2.0");
198 
199  ~SipRequestLayer();
200 
206  SipRequestLayer(const SipRequestLayer& other);
207 
214 
218  SipRequestFirstLine* getFirstLine() const { return m_FirstLine; }
219 
220  // implement Layer's abstract methods
221 
222  std::string toString() const;
223 
224  private:
225  SipRequestFirstLine* m_FirstLine;
226  };
227 
228 
229 
230 
231  class SipResponseFirstLine;
232 
233 
243  class SipResponseLayer : public SipLayer
244  {
245  friend class SipResponseFirstLine;
246  public:
247 
252  {
403  };
404 
411  SipResponseLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
412 
423  SipResponseLayer(SipResponseLayer::SipResponseStatusCode statusCode, std::string statusCodeString = "", std::string sipVersion = "SIP/2.0");
424 
425  virtual ~SipResponseLayer();
426 
432  SipResponseLayer(const SipResponseLayer& other);
433 
440 
444  SipResponseFirstLine* getFirstLine() const { return m_FirstLine; }
445 
446  // implement Layer's abstract methods
447 
448  std::string toString() const;
449 
450  private:
451  SipResponseFirstLine* m_FirstLine;
452  };
453 
454 
455 
467  {
468  friend class SipRequestLayer;
469  public:
470 
474  SipRequestLayer::SipMethod getMethod() const { return m_Method; }
475 
481  bool setMethod(SipRequestLayer::SipMethod newMethod);
482 
486  std::string getUri() const;
487 
493  bool setUri(std::string newUri);
494 
498  std::string getVersion() const { return m_Version; }
499 
506  static SipRequestLayer::SipMethod parseMethod(char* data, size_t dataLen);
507 
511  int getSize() const { return m_FirstLineEndOffset; }
512 
519  bool isComplete() const { return m_IsComplete; }
520 
527  class SipRequestFirstLineException : public std::exception
528  {
529  public:
530  ~SipRequestFirstLineException() throw() {}
531  void setMessage(std::string message) { m_Message = message; }
532  virtual const char* what() const throw()
533  {
534  return m_Message.c_str();
535  }
536  private:
537  std::string m_Message;
538  };
539 
540  private:
542  SipRequestFirstLine(SipRequestLayer* sipRequest, SipRequestLayer::SipMethod method, std::string version, std::string uri);
543  //throw(SipRequestFirstLineException); // Deprecated in C++17
544 
545  void parseVersion();
546 
547  SipRequestLayer* m_SipRequest;
549  std::string m_Version;
550  int m_VersionOffset;
551  int m_UriOffset;
552  int m_FirstLineEndOffset;
553  bool m_IsComplete;
554  SipRequestFirstLineException m_Exception;
555  };
556 
557 
558 
559 
570  {
571  friend class SipResponseLayer;
572  public:
577 
581  int getStatusCodeAsInt() const;
582 
586  std::string getStatusCodeString() const;
587 
594  bool setStatusCode(SipResponseLayer::SipResponseStatusCode newStatusCode, std::string statusCodeString = "");
595 
599  std::string getVersion() const { return m_Version; }
600 
605  void setVersion(std::string newVersion);
606 
613  static SipResponseLayer::SipResponseStatusCode parseStatusCode(char* data, size_t dataLen);
614 
618  int getSize() const { return m_FirstLineEndOffset; }
619 
626  bool isComplete() const { return m_IsComplete; }
627 
634  class SipResponseFirstLineException : public std::exception
635  {
636  public:
637  ~SipResponseFirstLineException() throw() {}
638  void setMessage(std::string message) { m_Message = message; }
639  virtual const char* what() const throw()
640  {
641  return m_Message.c_str();
642  }
643  private:
644  std::string m_Message;
645  };
646 
647  private:
649  SipResponseFirstLine(SipResponseLayer* sipResponse, std::string version, SipResponseLayer::SipResponseStatusCode statusCode, std::string statusCodeString = "");
650 
651  static std::string parseVersion(char* data, size_t dataLen);
652  static SipResponseLayer::SipResponseStatusCode validateStatusCode(char* data, size_t dataLen, SipResponseLayer::SipResponseStatusCode potentialCode);
653 
654 
655  SipResponseLayer* m_SipResponse;
656  std::string m_Version;
658  int m_FirstLineEndOffset;
659  bool m_IsComplete;
660  SipResponseFirstLineException m_Exception;
661  };
662 
663 }
664 
665 #endif // PACKETPP_SIP_LAYER
pcpp::SipLayer::parseNextLayer
void parseNextLayer()
pcpp::SipResponseLayer::Sip470ConsentNeeded
Definition: SipLayer.h:348
pcpp::SipLayer::getContentLength
int getContentLength() const
pcpp::OsiModelLayer
OsiModelLayer
Definition: ProtocolType.h:224
pcpp::SipResponseFirstLine::isComplete
bool isComplete() const
Definition: SipLayer.h:626
pcpp::SipResponseFirstLine::setVersion
void setVersion(std::string newVersion)
pcpp::SipResponseLayer::Sip305UseProxy
Definition: SipLayer.h:278
pcpp::Packet
Definition: Packet.h:26
pcpp::SipRequestFirstLine::SipRequestFirstLineException
Definition: SipLayer.h:527
pcpp::SipResponseLayer::Sip424BadLocationInformation
Definition: SipLayer.h:326
pcpp::SipRequestLayer::SipINFO
Definition: SipLayer.h:171
pcpp::SipResponseLayer::Sip421ExtensionRequired
Definition: SipLayer.h:320
pcpp::SipResponseLayer::Sip415UnsupportedMediaType
Definition: SipLayer.h:312
pcpp::SipResponseLayer::Sip604DoesNotExistAnywhere
Definition: SipLayer.h:396
pcpp::SipResponseFirstLine::getStatusCodeAsInt
int getStatusCodeAsInt() const
pcpp::SipRequestFirstLine::getSize
int getSize() const
Definition: SipLayer.h:511
pcpp::SipRequestFirstLine::isComplete
bool isComplete() const
Definition: SipLayer.h:519
pcpp::SipResponseLayer::Sip414RequestURITooLong
Definition: SipLayer.h:310
pcpp::SipResponseLayer::Sip469BadInfoPackage
Definition: SipLayer.h:346
pcpp::SipResponseLayer::Sip430FlowFailed
Definition: SipLayer.h:332
pcpp::SipResponseLayer::Sip487RequestTerminated
Definition: SipLayer.h:364
pcpp::SipRequestFirstLine::setMethod
bool setMethod(SipRequestLayer::SipMethod newMethod)
pcpp::SipResponseLayer::Sip429ProvideReferrerIdentity
Definition: SipLayer.h:330
pcpp::SipResponseLayer::Sip440MaxBreadthExceeded
Definition: SipLayer.h:344
pcpp::SipResponseLayer::Sip438InvalidIdentityHeader
Definition: SipLayer.h:340
pcpp::SipRequestLayer::SipCANCEL
Definition: SipLayer.h:157
pcpp::SipResponseLayer::Sip401Unauthorized
Definition: SipLayer.h:284
pcpp::SipResponseLayer::Sip416UnsupportedURIScheme
Definition: SipLayer.h:314
pcpp::SipResponseFirstLine::getVersion
std::string getVersion() const
Definition: SipLayer.h:599
pcpp::SipResponseLayer::Sip403Forbidden
Definition: SipLayer.h:288
pcpp::SipResponseLayer::Sip580PreconditionFailure
Definition: SipLayer.h:390
pcpp::SipResponseLayer::Sip486BusyHere
Definition: SipLayer.h:362
pcpp::SipResponseLayer::SipResponseLayer
SipResponseLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
pcpp::SipRequestLayer::SipREFER
Definition: SipLayer.h:173
pcpp::SipRequestLayer::SipINVITE
Definition: SipLayer.h:151
pcpp::SipResponseLayer::Sip204NoNotification
Definition: SipLayer.h:270
pcpp::SipLayer::getOsiModelLayer
OsiModelLayer getOsiModelLayer() const
Definition: SipLayer.h:102
pcpp::SipResponseLayer
Definition: SipLayer.h:243
pcpp::SipResponseLayer::Sip488NotAcceptableHere
Definition: SipLayer.h:366
pcpp::SipResponseLayer::Sip405MethodNotAllowed
Definition: SipLayer.h:292
pcpp::SipResponseFirstLine::getStatusCode
SipResponseLayer::SipResponseStatusCode getStatusCode() const
Definition: SipLayer.h:576
pcpp::SipResponseLayer::Sip410Gone
Definition: SipLayer.h:302
pcpp::SipResponseLayer::operator=
SipResponseLayer & operator=(const SipResponseLayer &other)
pcpp::SipRequestFirstLine::getMethod
SipRequestLayer::SipMethod getMethod() const
Definition: SipLayer.h:474
pcpp::SipRequestFirstLine::parseMethod
static SipRequestLayer::SipMethod parseMethod(char *data, size_t dataLen)
pcpp::SipResponseLayer::Sip433AnonymityDisallowed
Definition: SipLayer.h:334
pcpp::SipRequestFirstLine::setUri
bool setUri(std::string newUri)
pcpp::SipResponseLayer::Sip301MovedPermanently
Definition: SipLayer.h:274
pcpp::SipRequestLayer::getFirstLine
SipRequestFirstLine * getFirstLine() const
Definition: SipLayer.h:218
pcpp::SipRequestLayer::SipBYE
Definition: SipLayer.h:155
pcpp::SipResponseFirstLine
Definition: SipLayer.h:569
pcpp::SipResponseLayer::Sip484AddressIncomplete
Definition: SipLayer.h:358
pcpp::SipResponseLayer::Sip402PaymentRequired
Definition: SipLayer.h:286
pcpp::SipResponseLayer::Sip607Unwanted
Definition: SipLayer.h:400
pcpp::SipResponseLayer::Sip482LoopDetected
Definition: SipLayer.h:354
pcpp::SipResponseLayer::Sip417UnknownResourcePriority
Definition: SipLayer.h:316
pcpp::SipResponseLayer::Sip413RequestEntityTooLarge
Definition: SipLayer.h:308
pcpp::SipResponseLayer::Sip422SessionIntervalTooSmall
Definition: SipLayer.h:322
pcpp::SipResponseLayer::Sip489BadEvent
Definition: SipLayer.h:368
pcpp::SipResponseLayer::Sip412ConditionalRequestFailed
Definition: SipLayer.h:306
pcpp::SipLayer::setContentLength
HeaderField * setContentLength(int contentLength, const std::string prevFieldName="")
pcpp::SipResponseLayer::Sip501NotImplemented
Definition: SipLayer.h:378
pcpp::SipResponseLayer::Sip423IntervalTooBrief
Definition: SipLayer.h:324
pcpp::SipResponseLayer::Sip200OK
Definition: SipLayer.h:266
pcpp::SipLayer
Definition: SipLayer.h:74
pcpp::SipResponseLayer::Sip409Conflict
Definition: SipLayer.h:300
pcpp::SipResponseLayer::Sip505VersionNotSupported
Definition: SipLayer.h:386
pcpp::SipResponseLayer::Sip180Ringing
Definition: SipLayer.h:256
pcpp::SipRequestLayer
Definition: SipLayer.h:140
pcpp::SipRequestLayer::SipOPTIONS
Definition: SipLayer.h:163
pcpp::SipResponseLayer::toString
std::string toString() const
pcpp::SipRequestLayer::operator=
SipRequestLayer & operator=(const SipRequestLayer &other)
pcpp::SipResponseLayer::Sip406NotAcceptable
Definition: SipLayer.h:294
pcpp::SipResponseLayer::Sip500ServerInternalError
Definition: SipLayer.h:376
pcpp::SipResponseLayer::Sip400BadRequest
Definition: SipLayer.h:282
pcpp::SipResponseFirstLine::parseStatusCode
static SipResponseLayer::SipResponseStatusCode parseStatusCode(char *data, size_t dataLen)
pcpp::SipResponseLayer::SipResponseStatusCode
SipResponseStatusCode
Definition: SipLayer.h:251
pcpp::SipResponseLayer::Sip513MessageTooLarge
Definition: SipLayer.h:388
pcpp::SipRequestLayer::SipUPDATE
Definition: SipLayer.h:177
pcpp::SipResponseLayer::Sip420BadExtension
Definition: SipLayer.h:318
pcpp::SipRequestLayer::SipNOTIFY
Definition: SipLayer.h:167
pcpp::SipResponseLayer::Sip502BadGateway
Definition: SipLayer.h:380
pcpp::TextBasedProtocolMessage
Definition: TextBasedProtocol.h:106
pcpp::SipResponseLayer::Sip181CallisBeingForwarded
Definition: SipLayer.h:258
pcpp::SipResponseLayer::Sip436BadIdentityInfo
Definition: SipLayer.h:336
pcpp
The main namespace for the PcapPlusPlus lib.
pcpp::SipResponseLayer::Sip100Trying
Definition: SipLayer.h:254
pcpp::OsiModelSesionLayer
Definition: ProtocolType.h:235
pcpp::SipResponseLayer::Sip485Ambiguous
Definition: SipLayer.h:360
pcpp::SipResponseLayer::Sip600BusyEverywhere
Definition: SipLayer.h:392
pcpp::SipLayer::computeCalculateFields
void computeCalculateFields()
pcpp::Layer
Definition: Layer.h:70
pcpp::SipRequestFirstLine::getUri
std::string getUri() const
pcpp::SipResponseLayer::Sip300MultipleChoices
Definition: SipLayer.h:272
pcpp::SipResponseLayer::Sip494SecurityAgreementRequired
Definition: SipLayer.h:374
pcpp::SipResponseLayer::Sip481Call_TransactionDoesNotExist
Definition: SipLayer.h:352
pcpp::SipRequestLayer::SipMESSAGE
Definition: SipLayer.h:175
pcpp::SipResponseLayer::Sip504ServerTimeout
Definition: SipLayer.h:384
pcpp::HeaderField
Definition: TextBasedProtocol.h:31
pcpp::SipResponseLayer::Sip439FirstHopLacksOutboundSupport
Definition: SipLayer.h:342
pcpp::SipResponseLayer::Sip202Accepted
Definition: SipLayer.h:268
pcpp::SipResponseLayer::Sip380AlternativeService
Definition: SipLayer.h:280
pcpp::SipResponseLayer::Sip199EarlyDialogTerminated
Definition: SipLayer.h:264
pcpp::SipRequestLayer::SipRequestLayer
SipRequestLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
pcpp::SipResponseFirstLine::getSize
int getSize() const
Definition: SipLayer.h:618
pcpp::SipResponseLayer::Sip182Queued
Definition: SipLayer.h:260
pcpp::SipResponseLayer::SipStatusCodeUnknown
Definition: SipLayer.h:402
pcpp::SipResponseFirstLine::getStatusCodeString
std::string getStatusCodeString() const
pcpp::SipResponseLayer::Sip437UnsupportedCertificate
Definition: SipLayer.h:338
pcpp::SipResponseLayer::getFirstLine
SipResponseFirstLine * getFirstLine() const
Definition: SipLayer.h:444
pcpp::SipRequestLayer::toString
std::string toString() const
pcpp::SipResponseLayer::Sip503ServiceUnavailable
Definition: SipLayer.h:382
pcpp::SipResponseFirstLine::setStatusCode
bool setStatusCode(SipResponseLayer::SipResponseStatusCode newStatusCode, std::string statusCodeString="")
pcpp::SipRequestLayer::SipREGISTER
Definition: SipLayer.h:159
pcpp::SipResponseLayer::Sip428UseIdentityHeader
Definition: SipLayer.h:328
TextBasedProtocol.h
pcpp::SipRequestLayer::SipACK
Definition: SipLayer.h:153
pcpp::SipResponseLayer::Sip491RequestPending
Definition: SipLayer.h:370
pcpp::SipRequestLayer::SipPUBLISH
Definition: SipLayer.h:169
pcpp::SipResponseFirstLine::SipResponseFirstLineException
Definition: SipLayer.h:634
pcpp::SipResponseLayer::Sip493Undecipherable
Definition: SipLayer.h:372
pcpp::SipResponseLayer::Sip302MovedTemporarily
Definition: SipLayer.h:276
pcpp::SipRequestFirstLine::getVersion
std::string getVersion() const
Definition: SipLayer.h:498
pcpp::SipResponseLayer::Sip408RequestTimeout
Definition: SipLayer.h:298
pcpp::SipRequestLayer::SipMethod
SipMethod
Definition: SipLayer.h:148
pcpp::SipResponseLayer::Sip183SessioninProgress
Definition: SipLayer.h:262
pcpp::SipResponseLayer::Sip407ProxyAuthenticationRequired
Definition: SipLayer.h:296
pcpp::SipRequestFirstLine
Definition: SipLayer.h:466
pcpp::SipResponseLayer::Sip480TemporarilyUnavailable
Definition: SipLayer.h:350
pcpp::SipResponseLayer::Sip411LengthRequired
Definition: SipLayer.h:304
pcpp::SipRequestLayer::SipMethodUnknown
Definition: SipLayer.h:179
pcpp::SipRequestLayer::SipPRACK
Definition: SipLayer.h:161
pcpp::SipRequestLayer::SipSUBSCRIBE
Definition: SipLayer.h:165
pcpp::SipResponseLayer::Sip483TooManyHops
Definition: SipLayer.h:356
pcpp::SipResponseLayer::Sip606NotAcceptable
Definition: SipLayer.h:398
pcpp::SipResponseLayer::Sip603Decline
Definition: SipLayer.h:394
pcpp::SipResponseLayer::Sip404NotFound
Definition: SipLayer.h:290