sipxtacklib  Version 3.3
HttpBody.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005-2008 SIPez LLC.
3 // Licensed to SIPfoundry under a Contributor Agreement.
4 //
5 // Copyright (C) 2004-2008 SIPfoundry Inc.
6 // Licensed by SIPfoundry under the LGPL license.
7 //
8 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
9 // Licensed to SIPfoundry under a Contributor Agreement.
10 //
11 // $$
13 // Author: Dan Petrie (dpetrie AT SIPez DOT com)
14 
15 
16 #ifndef _HttpBody_h_
17 #define _HttpBody_h_
18 
19 // SYSTEM INCLUDES
20 //#include <...>
21 
22 // APPLICATION INCLUDES
23 #include <utl/UtlString.h>
24 #include <utl/UtlDList.h>
25 
26 // DEFINES
27 #define CONTENT_TYPE_TEXT_PLAIN "text/plain"
28 #define CONTENT_TYPE_TEXT_HTML "text/html"
29 #define CONTENT_SMIME_PKCS7 "application/pkcs7-mime"
30 #define CONTENT_TYPE_PIDF "application/pidf+xml"
31 #define CONTENT_TYPE_MULTIPART "multipart/"
32 #define CONTENT_TYPE_MULTIPART_RELATED "multipart/related"
33 #define CONTENT_TYPE_CONTENT_INDIRECTION "message/external-body"
34 #define DIALOG_EVENT_CONTENT_TYPE "application/dialog-info+xml"
35 
36 #define MULTIPART_BOUNDARY_PARAMETER "boundary"
37 
38 #define MAX_HTTP_BODY_PARTS 20
39 
40 // MACROS
41 // EXTERNAL FUNCTIONS
42 // EXTERNAL VARIABLES
43 // CONSTANTS
44 // STRUCTS
45 // TYPEDEFS
46 // FORWARD DECLARATIONS
47 class MimeBodyPart;
48 
50 
55 class HttpBody : public UtlString
56 {
57  friend class HttpBodyMultipart;
58 
59 /* //////////////////////////// PUBLIC //////////////////////////////////// */
60 public:
61 
63  {
70  };
71 
72 /* ============================ CREATORS ================================== */
73 
74  HttpBody(const char* bytes = NULL,
75  int length = -1,
76  const char* contentType = NULL);
77  //: Construct an HttpBody from a bunch of bytes
78 
79  HttpBody(const char* contentType);
80  //: Construct a multipart HttpBody with zero parts.
81  // contentType should have no "boundary" parameter.
82 
83  HttpBody(const HttpBody& rHttpBody);
84  //:Copy constructor
85 
86  virtual
87  ~HttpBody();
88  //:Destructor
89 
90 /* ============================ MANIPULATORS ============================== */
91 
92  HttpBody& operator=(const HttpBody& rhs);
93  //:Assignment operator
94 
96  static HttpBody* copyBody(const HttpBody& sourceBody);
97 
99  static HttpBody* createBody(const char* bodyBytes,
100  int bodyBytesLength,
101  const char* contentType,
102  const char* contentEncoding);
103 
105  void appendBodyPart(const HttpBody& body,
106  const UtlDList& parameters);
107 
108 /* ============================ ACCESSORS ================================= */
109 
110  virtual int getLength() const;
111 
112  // Note: for convenience, bytes is null terminated
113  // However depending upon the content type, the body may
114  // contain more than one null character.
115  // *bytes != NULL, even if *length == 0.
116  virtual void getBytes(const char** bytes, int* length) const;
117  virtual void getBytes(UtlString* bytes, int* length) const;
118  virtual const char* getBytes() const;
119 
120  UtlBoolean getMultipartBytes(int partIndex,
121  const char** bytes,
122  int* length,
123  int* start) const;
124 
125  const MimeBodyPart* getMultipart(int partIndex) const;
126 
127  int getMultipartCount() const;
128 
130 
132  // Valid while HttpBody exists and is not modified.
133  const char* getMultipartBoundary() const;
134 
136  // Valid while HttpBody exists and is not modified.
137  const char* getContentType() const;
138 
139 /* ============================ INQUIRY =================================== */
140 
141  UtlBoolean isMultipart() const;
142 
143 /* //////////////////////////// PROTECTED ///////////////////////////////// */
144 protected:
145 
147  UtlString mBody;
152 
153 /* //////////////////////////// PRIVATE /////////////////////////////////// */
154 private:
155 
156  // The counter for generating boundary values.
157  static unsigned boundaryCounter;
158  // Generate the next boundary value.
159  static void nextBoundary(UtlString& boundary);
160 };
161 
162 
163 // Carrier class to provide a constructor that would otherwise conflict
164 // with an existing constructor for HttpBody.
166 {
167  public:
168 
169  HttpBodyMultipart(const char* contentType);
170  //: Construct a multipart HttpBody with zero parts.
171  // contentType should have no "boundary" parameter.
172 };
173 
174 
175 /* ============================ INLINE METHODS ============================ */
176 
177 #endif // _HttpBody_h_
Definition: HttpBody.h:64
UtlBoolean getMultipartBytes(int partIndex, const char **bytes, int *length, int *start) const
Definition: HttpBody.cpp:496
virtual const char * getBytes() const
Definition: HttpBody.cpp:476
UtlString mMultipartBoundary
Definition: HttpBody.h:148
int mBodyPartCount
Definition: HttpBody.h:149
int bodyLength
Definition: HttpBody.h:146
MimeBodyPart * mpBodyParts[MAX_HTTP_BODY_PARTS]
Definition: HttpBody.h:150
Definition: HttpBody.h:69
int getMultipartCount() const
Definition: HttpBody.cpp:577
friend class HttpBodyMultipart
Definition: HttpBody.h:57
Definition: HttpBody.h:68
Definition: HttpBody.h:65
static HttpBody * copyBody(const HttpBody &sourceBody)
Copy the source HttpBody using the correct derived class constructor.
Definition: HttpBody.cpp:247
HttpBody(const char *bytes=NULL, int length=-1, const char *contentType=NULL)
Definition: HttpBody.cpp:53
virtual ~HttpBody()
Definition: HttpBody.cpp:200
BodyClassTypes getClassType() const
Definition: HttpBody.cpp:481
BodyClassTypes
Definition: HttpBody.h:62
#define MAX_HTTP_BODY_PARTS
Definition: HttpBody.h:38
Definition: HttpBody.h:66
Definition: HttpBody.h:165
const char * getMultipartBoundary() const
Get the multipart boundary string.
Definition: HttpBody.cpp:486
Definition: HttpBody.h:67
void appendBodyPart(const HttpBody &body, const UtlDList &parameters)
Append a multipart body part to an existing multiparty body.
Definition: HttpBody.cpp:342
UtlBoolean isMultipart() const
Definition: HttpBody.cpp:583
BodyClassTypes mClassType
Definition: HttpBody.h:151
const MimeBodyPart * getMultipart(int partIndex) const
Definition: HttpBody.cpp:566
virtual int getLength() const
Definition: HttpBody.cpp:443
UtlString mBody
Definition: HttpBody.h:147
const char * getContentType() const
Get the content type string.
Definition: HttpBody.cpp:491
class to contain an HTTP body
Definition: HttpBody.h:55
Definition: MimeBodyPart.h:34
static HttpBody * createBody(const char *bodyBytes, int bodyBytesLength, const char *contentType, const char *contentEncoding)
Pseudo body factory.
Definition: HttpBody.cpp:291
HttpBody & operator=(const HttpBody &rhs)
Definition: HttpBody.cpp:217

sipXtackLib home page