• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 
19 #ifndef RTSP_PAR_COM_MESSAGE_DS_H_
20 #define RTSP_PAR_COM_MESSAGE_DS_H_
21 
22 #include "oscl_base.h"
23 #include "rtsp_par_com_tunable.h"
24 #include "rtsp_par_com_basic_ds.h"
25 #include "rtsp_transport.h"
26 #include "rtsp_time_formats.h"
27 
28 class RTSPGenericMessage
29 {
30     protected:
31 
32         // for internal manipulation
33         //
34         char          secondaryBuffer[ RTSP_MAX_FULL_REQUEST_SIZE +1 ];
35         char *        secondaryBufferSpace;
36         int           secondaryBufferSizeUsed;
37 
38         StrCSumPtrLen   fieldKeys[ RTSP_MAX_NUMBER_OF_FIELDS ];
39         StrPtrLen       fieldVals[ RTSP_MAX_NUMBER_OF_FIELDS ];
40         uint16                      numPtrFields;
41 
42     public:
43 
44         RTSPMsgType       msgType;
45 
46         RTSPMethod        method;   // for requests
47         RTSPStatusCode  statusCode; // for responses
48 
49         StrPtrLen     methodString;
50         StrPtrLen     reasonString;
51 
52         uint32              cseq;
53         bool                  cseqIsSet;
54 
55         uint32          bufferSize;
56         bool            bufferSizeIsSet;
57 
58         uint32              authorizationFlag;
59         bool                authorizationFlagIsSet;
60 
61         //      RTSPTransport     transport;
62         RtspTransport     transport[RTSP_MAX_NUMBER_OF_TRANSPORT_ENTRIES];
63         uint32          numOfTransportEntries;
64 
65 
66         //      RTSPRange           range;
67         RtspRangeType       range;
68         bool                  rangeIsSet;
69 
70         RTSPSessionId     sessionId;
71         bool                  sessionIdIsSet;
72 
73 
74         RTSPRTPInfo     rtpInfo[ RTSP_MAX_NUMBER_OF_RTP_INFO_ENTRIES ];
75         uint32          numOfRtpInfoEntries;
76 
77 
78         // **************************************
79         // items related to an entity body
80         // to be filled out by Parser
81         //
82 
83         StrPtrLen   contentType;
84         bool                contentTypeIsSet;
85 
86         StrPtrLen   contentBase;
87         enum ContentBaseModeType {NO_CONTENT_BASE = 0, CONTENT_BASE_SET, INCLUDE_TRAILING_SLASH};
88         ContentBaseModeType             contentBaseMode;
89 
90         // for Content-Length
91         uint32          contentLength;
92         bool                contentLengthIsSet;
93 
94         // some more recognized fields
95         StrPtrLen  userAgent;
96         bool          userAgentIsSet;
97 
98         StrPtrLen  accept;
99         bool          acceptIsSet;
100 
101         StrPtrLen  require;
102         bool          requireIsSet;
103 
104         // original requested URI
105         StrPtrLen  originalURI;
106 #ifdef RTSP_PLAYLIST_SUPPORT
107         bool methodEosIsSet;
108         bool comPvServerPlaylistIsSet;
109 #endif
110 
111         StrPtrLen               eofField;
112         bool                  eofFieldIsSet;
113         char XMLBufferPtr[ RTSP_MAX_FULL_REQUEST_SIZE];
114         bool XMLIsSet;
115 
116         uint32  timeout;
117     public:
118 
119         OSCL_IMPORT_REF void          reset();
120 
121         OSCL_IMPORT_REF const StrPtrLen *   queryField(const StrCSumPtrLen & query) const;
122 };
123 
124 
125 class RTSPIncomingMessage
126         : public RTSPGenericMessage
127 {
128     protected:
129 
130         RTSPStructureStatus amMalformed;
131 
132         uint32                  totalFields;
133         uint32                  totalFieldsParsed;
134         void                    parseRange(char *rangeString, RtspRangeType *range);
135 
136 #ifdef RTSP_PLAYLIST_SUPPORT
137         void          parseSupported(const char *supportedString, int length);
138 #endif /* RTSP_PLAYLIST_SUPPORT */
139 
140         void          parseTransport(uint16);
141         void          parseOneTransportEntry(char * &, char *);
142 
143         void          parseRTPInfo(uint16);
144         void          parseOneRTPInfoEntry(char * &, char *);
145 
146     public:
147 
148 
149         // original requested URI without the last part
150         StrPtrLen     originalURIBase;
151 
152         // the control portion of the original URI
153         StrPtrLen     originalURIControlCandidate;
154 
155         // for remapped URI
156         StrPtrLen     remappedURI;
157 
158 #ifdef RTSP_PLAYLIST_SUPPORT
159         StrPtrLen playlistRangeField;
160         bool playlistRangeFieldIsSet;
161         // need to figure out how to store all the error fields.. we may not actually need to
162         StrPtrLen playlistErrorField[RTSP_MAX_NUMBER_OF_PLAYLIST_ERROR_ENTRIES];
163         bool playlistErrorFieldIsSet;
164         int32 playlistErrorFieldCount;
165         StrPtrLen     supportedField[ RTSP_MAX_NUMBER_OF_SUPPORTED_ENTRIES ];
166         uint32          numOfSupportedEntries;
167         bool supportedFieldIsSet;
168 
169         StrPtrLen playlistRangeUrl;
170         int32 playlistRangeClipIndex;
171         int32 playlistRangeClipOffset;
172         int32 playlistRangeNptTime;
173 #endif
174         // *************************************
175         // general API
176         //
177 
178 
179         StrCSumPtrLen   rtspVersionString;
180 
181         OSCL_IMPORT_REF void            reset();
isMalformed()182         OSCL_IMPORT_REF     RTSPStructureStatus isMalformed()
183         {
184             return amMalformed;
185         }
186 
187     protected:
188 
189         void parseFirstFields();
190 
191 
192     public:
193 
RTSPIncomingMessage()194         RTSPIncomingMessage()
195         {
196             reset();
197         }
198 
199         OSCL_IMPORT_REF bool
200         parseEntityBody(RTSPEntityBody * entityBody);
201 
202         // *************************************
203         // for handling requests with too many
204         // fields
205         //
getTotalFields()206         uint32 getTotalFields()
207         {
208             return totalFields;
209         }
getTotalFieldsParsed()210         uint32 getTotalFieldsParsed()
211         {
212             return totalFieldsParsed;
213         }
214         // field to save channel id of the RTP data
215         uint8 channelID;
216 
217     private:
218         bool     parseNextPortion();
219 
220 
221     public:
222 
223         friend class RTSPParser;
224 };
225 
226 
227 class RTSPOutgoingMessage
228         : public RTSPGenericMessage
229 {
230     protected:
231 
232         RTSPIncomingMessage * boundMessage;
233 
234         StrPtrLen  fullRequestPLS;
235         void       composeTransport(char* trans, RtspTransport* rtspTrans);
236     public:
237 
238 
239         // null-terminated buffer with the original
240         // RTSP request
241         char            fullRequestBuffer[ RTSP_MAX_FULL_REQUEST_SIZE +1 ];
242         char *        fullRequestBufferSpace;
243         int                     fullRequestBufferSizeUsed;
244 
245 
246         char      rtpInfoUrlBuffer[ RTSP_MAX_NUMBER_OF_RTP_INFO_ENTRIES ][200+1];
247 
248 
RTSPOutgoingMessage()249         RTSPOutgoingMessage()
250         {
251             reset();
252         }
253 
254         // ****************************************
255         // for binding to RTSPIncomingMessage
256         //
257         OSCL_IMPORT_REF void    bind(const RTSPIncomingMessage & theMessage);
258 
259         // ****************************************
260         // for adding generic fields
261         //
262         OSCL_IMPORT_REF bool
263         addField(StrCSumPtrLen * newFieldName,
264                  const StrPtrLen * newFieldValue
265                 );
266         OSCL_IMPORT_REF bool
267         addField(StrCSumPtrLen * newFieldName,
268                  const char * newValue
269                 );
270 
271         // ****************************************
272         // for requesting composition
273         //
274         OSCL_IMPORT_REF bool
275         compose();
276 
277         // ***************************************
278         // for retrieving composed buffer
279         //
280         OSCL_IMPORT_REF StrPtrLen *
281         retrieveComposedBuffer();
282 
283         void
284         OSCL_IMPORT_REF reset();
285 };
286 
287 #endif // RTSP_PAR_COM_MESSAGE_DS_H_
288