• 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 #ifndef PVDL_CONFIG_FILE_H
19 #define PVDL_CONFIG_FILE_H
20 
21 #ifndef OSCL_MEM_H_INCLUDED
22 #include "oscl_mem.h"
23 #endif
24 #ifndef OSCL_FILE_IO_H_INCLUDED
25 #include "oscl_file_io.h"
26 #endif
27 #ifndef OSCLCONFIG_IO_H_INCLUDED
28 #include "osclconfig_io.h"
29 #endif
30 #ifndef PVLOGGER_H_INCLUDED
31 #include "pvlogger.h"
32 #endif
33 #ifndef OSCL_STRING_H_INCLUDED
34 #include "oscl_string.h"
35 #endif
36 #ifndef OSCL_STRING_CONTAINERS_H_INCLUDED
37 #include "oscl_string_containers.h"
38 #endif
39 
40 class PVDlCfgFile
41 {
42     public:
43 
44         enum LoadConfigStatus
45         {
46             LoadConfigStatus_NoError = 0,
47             LoadConfigStatus_CriticalError = -1, // object creation failure, open file failure
48             LoadConfigStatus_NonCriticalError = -2 // read failure, url mismatch, headers unavailable
49         };
50 
51         OSCL_IMPORT_REF PVDlCfgFile();
52         OSCL_IMPORT_REF virtual ~PVDlCfgFile();
53 
SetConfigFileName(OSCL_wString & aFileName)54         void SetConfigFileName(OSCL_wString &aFileName)
55         {
56             iConfigFileName = aFileName;
57         };
58         OSCL_IMPORT_REF int32 LoadConfig(void);
59         OSCL_IMPORT_REF bool SaveConfig(void);
60 
61         OSCL_IMPORT_REF void SetDownloadType(bool aIsFastTrack);
62         OSCL_IMPORT_REF bool IsFastTrack(void);
63 
64         OSCL_IMPORT_REF void SetDonwloadComplete(void);
65         OSCL_IMPORT_REF bool IsDownloadComplete(void);
66 
67         enum TPVDLPlaybackMode
68         {
69             EPVDL_ASAP = 0,
70             EPVDL_PLAYBACK_AFTER_DOWNLOAD,
71             EPVDL_DOWNLOAD_ONLY
72         };
73         OSCL_IMPORT_REF void SetPlaybackMode(TPVDLPlaybackMode aPlaybackMode);
74         OSCL_IMPORT_REF TPVDLPlaybackMode GetPlaybackMode(void);
75 
SetUrl(OSCL_String & aUrl)76         void SetUrl(OSCL_String &aUrl)
77         {
78             iUrl = aUrl;
79         };
GetUrl(void)80         OSCL_String& GetUrl(void)
81         {
82             return iUrl;
83         };
84 
SetProxyName(OSCL_String & aProxyName)85         void SetProxyName(OSCL_String &aProxyName)
86         {
87             iProxyName = aProxyName;
88         };
GetProxyName(void)89         OSCL_String& GetProxyName(void)
90         {
91             return iProxyName;
92         };
93 
SetProxyPort(uint32 aProxyPort)94         void SetProxyPort(uint32 aProxyPort)
95         {
96             iProxyPort = aProxyPort;
97         };
GetProxyPort(void)98         uint32 GetProxyPort(void)
99         {
100             return iProxyPort;
101         };
102 
SetMaxAllowedFileSize(uint32 aFileSize)103         void SetMaxAllowedFileSize(uint32 aFileSize)
104         {
105             iMaxAllowedFileSize = aFileSize;
106         };
GetMaxAllowedFileSize(void)107         uint32 GetMaxAllowedFileSize(void)
108         {
109             return iMaxAllowedFileSize;
110         };
111 
SetOverallFileSize(uint32 aFileSize)112         void SetOverallFileSize(uint32 aFileSize)
113         {
114             iOverallFileSize = aFileSize;
115         };
GetOverallFileSize(void)116         uint32 GetOverallFileSize(void)
117         {
118             return iOverallFileSize;
119         };
120 
SetCurrentFileSize(uint32 aFileSize)121         void SetCurrentFileSize(uint32 aFileSize)
122         {
123             iCurrentFileSize = aFileSize;
124         };
GetCurrentFileSize(void)125         uint32 GetCurrentFileSize(void)
126         {
127             return iCurrentFileSize;
128         };
129 
SetNetworkTimeouts(int32 aConnectTimeout,int32 aSendTimeout,int32 aRecvTimeout)130         void SetNetworkTimeouts(int32 aConnectTimeout, int32 aSendTimeout, int32 aRecvTimeout)
131         {
132             iConnectTimeout = aConnectTimeout;
133             iSendTimeout = aSendTimeout;
134             iRecvTimeout = aRecvTimeout;
135         };
GetNetworkTimeouts(int32 & aConnectTimeout,int32 & aSendTimeout,int32 & aRecvTimeout)136         void GetNetworkTimeouts(int32 &aConnectTimeout, int32 &aSendTimeout, int32 &aRecvTimeout)
137         {
138             aConnectTimeout = iConnectTimeout;
139             aSendTimeout = iSendTimeout;
140             aRecvTimeout = iRecvTimeout;
141         };
142 
SetRangeStartTime(uint32 aTimeInMillisec)143         void SetRangeStartTime(uint32 aTimeInMillisec)
144         {
145             iRangeStartTime = aTimeInMillisec;
146         };
GetRangeStartTime(void)147         uint32 GetRangeStartTime(void)
148         {
149             return iRangeStartTime;
150         };
151 
SetSelectedFastTracks(Oscl_Vector<int32,OsclMemAllocator> & aSelectedTrackIDs)152         void SetSelectedFastTracks(Oscl_Vector<int32, OsclMemAllocator>& aSelectedTrackIDs)
153         {
154             iSelectedTrackIDs = aSelectedTrackIDs;
155         }
GetSelectedFastTracks(void)156         Oscl_Vector<int32, OsclMemAllocator>& GetSelectedFastTracks(void)
157         {
158             return iSelectedTrackIDs;
159         }
160 
SetPlayerVersion(OSCL_String & aPlayerVersion)161         void SetPlayerVersion(OSCL_String &aPlayerVersion)
162         {
163             iPlayerVersion = aPlayerVersion;
164         };
165 
SetUserAgent(OSCL_String & aUserAgent)166         void SetUserAgent(OSCL_String &aUserAgent)
167         {
168             iUserAgent = aUserAgent;
169         };
GetUserAgent(void)170         OSCL_String& GetUserAgent(void)
171         {
172             return iUserAgent;
173         };
174 
SetUserNetwork(OSCL_String & aUserNetwork)175         void SetUserNetwork(OSCL_String &aUserNetwork)
176         {
177             iUserNetwork = aUserNetwork;
178         };
GetUserNetwork(void)179         OSCL_String& GetUserNetwork(void)
180         {
181             return iUserNetwork;
182         };
183 
SetDeviceInfo(OSCL_String & aDeviceInfo)184         void SetDeviceInfo(OSCL_String &aDeviceInfo)
185         {
186             iDeviceInfo = aDeviceInfo;
187         };
GetDeviceInfo(void)188         OSCL_String& GetDeviceInfo(void)
189         {
190             return iDeviceInfo;
191         };
192 
SetUserId(OSCL_String & aUserId)193         void SetUserId(OSCL_String &aUserId)
194         {
195             iUserId = aUserId;
196         };
GetUserId(void)197         OSCL_String& GetUserId(void)
198         {
199             return iUserId;
200         };
201 
SetUserAuth(OSCL_String & aUserAuth)202         void SetUserAuth(OSCL_String &aUserAuth)
203         {
204             iUserAuth = aUserAuth;
205         };
GetUserAuth(void)206         OSCL_String& GetUserAuth(void)
207         {
208             return iUserAuth;
209         };
210 
SetExpiration(OSCL_String & aExpiration)211         void SetExpiration(OSCL_String &aExpiration)
212         {
213             iExpiration = aExpiration;
214         };
GetExpiration(void)215         OSCL_String& GetExpiration(void)
216         {
217             return iExpiration;
218         };
219 
SetAppString(OSCL_String & aAppString)220         void SetAppString(OSCL_String &aAppString)
221         {
222             iAppString = aAppString;
223         };
GetAppString(void)224         OSCL_String& GetAppString(void)
225         {
226             return iAppString;
227         };
228 
SetFiller(OSCL_String & aFiller)229         void SetFiller(OSCL_String &aFiller)
230         {
231             iFiller = aFiller;
232         };
GetFiller(void)233         OSCL_String& GetFiller(void)
234         {
235             return iFiller;
236         };
237 
SetSign(OSCL_String & aSign)238         void SetSign(OSCL_String &aSign)
239         {
240             iSign = aSign;
241         };
GetSign(void)242         OSCL_String& GetSign(void)
243         {
244             return iSign;
245         };
246 
SetUnmodifiedDateStart(OSCL_String & aDate)247         void SetUnmodifiedDateStart(OSCL_String &aDate)
248         {
249             iUnmodifiedDateStart = aDate;
250         };
GetUnmodifiedDateStart(void)251         OSCL_String& GetUnmodifiedDateStart(void)
252         {
253             return iUnmodifiedDateStart;
254         };
255 
setHttpVersion(uint32 aVersion)256         void setHttpVersion(uint32 aVersion)
257         {
258             iHttpVersionNum = aVersion;
259         }
getHttpVersion()260         uint32 getHttpVersion()
261         {
262             return iHttpVersionNum;
263         }
264 
265         //for integratity check and also argument passing
SetDownloadFileName(OSCL_wString & aFileName)266         void SetDownloadFileName(OSCL_wString &aFileName)
267         {
268             iDownloadFileName = aFileName;
269         };
GetDownloadFileName(void)270         OSCL_wString& GetDownloadFileName(void)
271         {
272             return iDownloadFileName;
273         };
274         OSCL_IMPORT_REF bool Validate();
IsNewSession(void)275         bool IsNewSession(void)
276         {
277             return bIsNewSession;
278         };
279         void SetNewSession(const bool aNewSession = true)
280         {
281             bIsNewSession = aNewSession;
282         }
283 
HasContentLength()284         bool HasContentLength() const
285         {
286             return (iHasContentLength > 0);
287         }
288         void setHasContentLengthFlag(const bool aHasContentLength = true)
289         {
290             iHasContentLength = (uint32)aHasContentLength;
291         }
292 
SetExtensionHeaderKey(OSCL_String & aKey)293         void SetExtensionHeaderKey(OSCL_String &aKey)
294         {
295             OSCL_HeapString<OsclMemAllocator> fieldKey(aKey);
296             int32 err = 0;
297             OSCL_TRY(err, iExtensionHeaderKeys.push_back(fieldKey););
298         }
SetExtensionHeaderValue(OSCL_String & aValue)299         void SetExtensionHeaderValue(OSCL_String &aValue)
300         {
301             OSCL_HeapString<OsclMemAllocator> fieldValue(aValue);
302             int32 err = 0;
303             OSCL_TRY(err, iExtensionHeaderValues.push_back(fieldValue););
304         }
SetHTTPMethodMaskForExtensionHeader(const uint32 bitMask)305         void SetHTTPMethodMaskForExtensionHeader(const uint32 bitMask)
306         {
307             int32 err = 0;
308             OSCL_TRY(err, iMethodMaskForExtensionHeaders.push_back(bitMask););
309         }
310         void SetExtensionHeaderPurgeOnRediect(const bool aPurgeOnRedirect = true)
311         {
312             int32 err = 0;
313             OSCL_TRY(err, iExtensionHeadersPurgeOnRedirect.push_back(aPurgeOnRedirect););
314         }
getExtensionHeaderKeys()315         Oscl_Vector<OSCL_HeapString<OsclMemAllocator>, OsclMemAllocator> &getExtensionHeaderKeys()
316         {
317             return iExtensionHeaderKeys;
318         }
getExtensionHeaderValues()319         Oscl_Vector<OSCL_HeapString<OsclMemAllocator>, OsclMemAllocator> &getExtensionHeaderValues()
320         {
321             return iExtensionHeaderValues;
322         }
getHTTPMethodMasksForExtensionHeader()323         Oscl_Vector<uint32, OsclMemAllocator> &getHTTPMethodMasksForExtensionHeader()
324         {
325             return iMethodMaskForExtensionHeaders;
326         }
getExtensionHeadersPurgeOnRedirect()327         Oscl_Vector<bool, OsclMemAllocator> &getExtensionHeadersPurgeOnRedirect()
328         {
329             return iExtensionHeadersPurgeOnRedirect;
330         }
331 
332         // flag of disabling HTTP HEAD request
333         void setHttpHeadRequestDisabled(const bool aDisableHeadRequest = true)
334         {
335             iDisableHeadRequest = aDisableHeadRequest;
336         }
getHttpHeadRequestDisabled()337         bool getHttpHeadRequestDisabled() const
338         {
339             return iDisableHeadRequest;
340         }
341 
342 
343     private:
344         void composeFixedHeader(uint8 *aBuf);
345 
346     private:
347         uint8 *iTmpBuf;
348 
349         Oscl_FileServer iFileServer;
350         Oscl_File   *iFile;
351 
352         //memory allocator type for this node.
353         typedef OsclMemAllocator PVDlCfgFileAllocator;
354 
355         OSCL_wHeapString<PVDlCfgFileAllocator> iConfigFileName;
356         OSCL_wHeapString<PVDlCfgFileAllocator> iDownloadFileName;
357 
358         OSCL_HeapString<PVDlCfgFileAllocator> iUrl;
359         //if proxy is in use, it is the proxy address
360         OSCL_HeapString<PVDlCfgFileAllocator> iProxyName;
361         //if proxy is in use, it is the proxy address len
362         uint32  iProxyPort;
363 
364         //client only downloads the clip which is smaller than this size
365         uint32 iMaxAllowedFileSize;
366         //the file size after it is completly downloaded.
367         uint32  iOverallFileSize;
368         //for FastTrack, this would be the accumulated bytes downloaded
369         uint32  iCurrentFileSize;
370         //flag of whether to have content length for the previous download
371         // boolean variable, but intentionally choose uint32 instead of bool, for consistency with other variables
372         uint32 iHasContentLength;
373 
374         int32 iConnectTimeout;
375         int32 iSendTimeout;
376         int32 iRecvTimeout;
377 
378         uint32  iRangeStartTime; //in ms
379 
380         OSCL_HeapString<PVDlCfgFileAllocator> iPlayerVersion;
381         OSCL_HeapString<PVDlCfgFileAllocator> iUserAgent;
382         OSCL_HeapString<PVDlCfgFileAllocator> iUserNetwork;
383         OSCL_HeapString<PVDlCfgFileAllocator> iDeviceInfo;
384         OSCL_HeapString<PVDlCfgFileAllocator> iUserId;
385         OSCL_HeapString<PVDlCfgFileAllocator> iUserAuth;
386         OSCL_HeapString<PVDlCfgFileAllocator> iExpiration;
387         OSCL_HeapString<PVDlCfgFileAllocator> iAppString;
388         OSCL_HeapString<PVDlCfgFileAllocator> iFiller;
389         OSCL_HeapString<PVDlCfgFileAllocator> iSign;
390         OSCL_HeapString<PVDlCfgFileAllocator> iUnmodifiedDateStart;
391 
392         Oscl_Vector<int32, PVDlCfgFileAllocator> iSelectedTrackIDs;
393 
394         const uint32 iMagic32;
395         const uint32 iVersion;
396         uint32  iFlag;
397         const uint32 iTotalFixedHeaderSize; //bytes from iMagic32 to iSignLen in bytes
398         const uint32 PVDL_CFG_FILE_CACHE_BUF;
399         PVLogger* iLogger;
400         bool bIsNewSession;
401         uint32 iHttpVersionNum;
402 
403         Oscl_Vector<OSCL_HeapString<OsclMemAllocator>, OsclMemAllocator> iExtensionHeaderKeys;
404         Oscl_Vector<OSCL_HeapString<OsclMemAllocator>, OsclMemAllocator> iExtensionHeaderValues;
405         Oscl_Vector<uint32, OsclMemAllocator> iMethodMaskForExtensionHeaders; // bit 0 = 1 => HTTP GET method
406         // bit 1 = 1 => HTTP POST method
407         Oscl_Vector<bool, OsclMemAllocator> iExtensionHeadersPurgeOnRedirect;
408         bool iDisableHeadRequest;
409 };
410 
411 #endif //#ifndef PVDL_CONFIG_FILE_H
412 
413