author | Sebastian Brannstrom <sebastianb@symbian.org> |
Fri, 12 Nov 2010 15:59:01 +0100 | |
branch | RCL_3 |
changeset 330 | 4cf89a7d3476 |
parent 321 | 7a0fb290f9c6 |
child 342 | 9441fb8fd60d |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* Copyright (c) 2007-2010 Sebastian Brannstrom, Lars Persson, EmbedDev AB |
|
3 |
* |
|
4 |
* All rights reserved. |
|
5 |
* This component and the accompanying materials are made available |
|
6 |
* under the terms of the License "Eclipse Public License v1.0" |
|
7 |
* which accompanies this distribution, and is available |
|
8 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 |
* |
|
10 |
* Initial Contributors: |
|
11 |
* EmbedDev AB - initial contribution. |
|
12 |
* |
|
13 |
* Contributors: |
|
14 |
* |
|
15 |
* Description: |
|
16 |
* |
|
17 |
*/ |
|
18 |
||
19 |
#include "FeedParser.h" |
|
20 |
#include <f32file.h> |
|
21 |
#include <bautils.h> |
|
22 |
#include <s32file.h> |
|
23 |
#include <charconv.h> |
|
24 |
#include <xml/stringdictionarycollection.h> |
|
25 |
#include <utf.h> |
|
26 |
#include <tinternetdate.h> |
|
258
f02d87cb8d1f
Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
255
diff
changeset
|
27 |
#include <e32hashtab.h> |
2 | 28 |
#include "debug.h" |
123 | 29 |
#include "podcastutils.h" |
2 | 30 |
|
31 |
using namespace Xml; |
|
32 |
const TInt KMaxParseBuffer = 1024; |
|
33 |
const TInt KMaxStringBuffer = 100; |
|
34 |
||
35 |
CFeedParser::CFeedParser(MFeedParserObserver& aCallbacks, RFs& aFs) : iCallbacks(aCallbacks), iRfs(aFs) |
|
36 |
{ |
|
37 |
} |
|
38 |
||
39 |
CFeedParser::~CFeedParser() |
|
40 |
{ |
|
41 |
} |
|
42 |
||
43 |
void CFeedParser::ParseFeedL(const TFileName &feedFileName, CFeedInfo *info, TUint aMaxItems) |
|
44 |
{ |
|
45 |
//DP1("ParseFeedL BEGIN: %S", &feedFileName); |
|
46 |
||
47 |
_LIT8(KXmlMimeType, "text/xml"); |
|
48 |
// Contruct the parser object |
|
49 |
CParser* parser = CParser::NewLC(KXmlMimeType, *this); |
|
50 |
iActiveFeed = info; |
|
51 |
iFeedState = EStateRoot; |
|
52 |
iActiveShow = NULL; |
|
53 |
iItemsParsed = 0; |
|
54 |
iMaxItems = aMaxItems; |
|
55 |
iStoppedParsing = EFalse; |
|
56 |
iEncoding = ELatin1; |
|
57 |
||
58 |
ParseL(*parser, iRfs, feedFileName); |
|
59 |
||
60 |
CleanupStack::PopAndDestroy(parser); |
|
61 |
||
62 |
//DP("ParseFeedL END"); |
|
63 |
} |
|
64 |
||
65 |
// from MContentHandler |
|
66 |
void CFeedParser::OnStartDocumentL(const RDocumentParameters& aDocParam, TInt /*aErrorCode*/) |
|
67 |
{ |
|
68 |
DP("OnStartDocumentL()"); |
|
69 |
HBufC* charset = HBufC::NewLC(KMaxParseBuffer); |
|
70 |
charset->Des().Copy(aDocParam.CharacterSetName().DesC()); |
|
71 |
iEncoding = EUtf8; |
|
72 |
if (charset->CompareF(_L("utf-8")) == 0) { |
|
73 |
DP("setting UTF8"); |
|
74 |
iEncoding = EUtf8; |
|
75 |
} else if (charset->CompareF(_L("ISO-8859-1")) == 0) { |
|
76 |
iEncoding = EUtf8; //Latin1; |
|
77 |
} else { |
|
78 |
DP1("unknown charset: %S", &charset); |
|
79 |
} |
|
80 |
CleanupStack::PopAndDestroy(charset);//buffer |
|
81 |
} |
|
82 |
||
83 |
void CFeedParser::OnEndDocumentL(TInt /*aErrorCode*/) |
|
84 |
{ |
|
85 |
//DP("OnEndDocumentL()"); |
|
86 |
iCallbacks.ParsingCompleteL(iActiveFeed); |
|
87 |
} |
|
88 |
||
89 |
void CFeedParser::OnStartElementL(const RTagInfo& aElement, const RAttributeArray& aAttributes, TInt /*aErrorCode*/) |
|
90 |
{ |
|
91 |
if (iStoppedParsing) { |
|
92 |
iActiveShow = NULL; |
|
93 |
return; |
|
94 |
} |
|
95 |
||
96 |
TBuf<KMaxStringBuffer> str; |
|
97 |
str.Copy(aElement.LocalName().DesC()); |
|
98 |
//DP2("OnStartElementL START state=%d, element=%S", iFeedState, &str); |
|
99 |
iBuffer.Zero(); |
|
100 |
switch (iFeedState) { |
|
101 |
case EStateRoot: |
|
102 |
// <channel> |
|
103 |
if (str.CompareF(KTagChannel) == 0) { |
|
104 |
iFeedState = EStateChannel; |
|
105 |
} |
|
106 |
break; |
|
107 |
case EStateChannel: |
|
108 |
// <channel> <item> |
|
109 |
if(str.CompareF(KTagItem) == 0) { |
|
110 |
//DP("New item"); |
|
111 |
iFeedState=EStateItem; |
|
112 |
||
113 |
iActiveShow = NULL; |
|
114 |
iActiveShow = CShowInfo::NewL(); |
|
115 |
if (iActiveShow == NULL) { |
|
116 |
DP("Out of memory!"); |
|
117 |
iStoppedParsing = ETrue; |
|
118 |
return; |
|
119 |
} |
|
120 |
iActiveShow->SetFeedUid(iActiveFeed->Uid()); |
|
121 |
||
122 |
// <channel> <lastBuildDate> |
|
123 |
} else if (str.CompareF(KTagLastBuildDate) == 0) { |
|
124 |
DP("LastBuildDate BEGIN"); |
|
125 |
iFeedState=EStateChannelLastBuildDate; |
|
126 |
// <channel> <link> |
|
127 |
}else if (str.CompareF(KTagTitle) == 0) { |
|
128 |
iFeedState=EStateChannelTitle; |
|
129 |
// <channel> <link> |
|
130 |
} else if (str.CompareF(KTagLink) == 0) { |
|
131 |
iFeedState = EStateChannelLink; |
|
132 |
// <channel> <description> |
|
133 |
} else if (str.CompareF(KTagDescription) == 0) { |
|
134 |
iFeedState=EStateChannelDescription; |
|
135 |
// <channel> <image> |
|
136 |
} else if (str.CompareF(KTagImage) == 0) { |
|
137 |
for (int i=0;i<aAttributes.Count();i++) { |
|
138 |
RAttribute attr = aAttributes[i]; |
|
139 |
TBuf<KMaxStringBuffer> attr16; |
|
140 |
attr16.Copy(attr.Attribute().LocalName().DesC().Left(KMaxStringBuffer)); |
|
141 |
HBufC* val16 = CnvUtfConverter::ConvertToUnicodeFromUtf8L(attr.Value().DesC().Left(KMaxParseBuffer)); |
|
142 |
CleanupStack::PushL(val16); |
|
143 |
||
144 |
// href=... |
|
145 |
if (attr16.Compare(KTagHref) == 0) { |
|
146 |
iActiveFeed->SetImageUrlL(*val16); |
|
147 |
} |
|
148 |
CleanupStack::PopAndDestroy(val16); |
|
149 |
} |
|
150 |
||
151 |
iFeedState=EStateChannelImage; |
|
152 |
} |
|
153 |
break; |
|
154 |
case EStateChannelImage: |
|
155 |
// <channel> <image> <url> |
|
156 |
if (str.CompareF(KTagUrl) == 0) { |
|
157 |
iFeedState=EStateChannelImageUrl; |
|
158 |
} else { |
|
159 |
iFeedState=EStateChannelImage; |
|
160 |
} |
|
161 |
break; |
|
162 |
case EStateItem: |
|
258
f02d87cb8d1f
Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
255
diff
changeset
|
163 |
iUid = 0; |
2 | 164 |
// <channel> <item> <title> |
165 |
if (str.CompareF(KTagTitle) == 0) { |
|
166 |
iFeedState=EStateItemTitle; |
|
167 |
// <channel> <item> <link> |
|
168 |
} else if (str.CompareF(KTagLink) == 0) { |
|
169 |
iFeedState=EStateItemLink; |
|
170 |
// <channel> <item> <enclosure ...> |
|
171 |
} else if (str.CompareF(KTagEnclosure) == 0) { |
|
172 |
//DP("Enclosure START"); |
|
173 |
for (int i=0;i<aAttributes.Count();i++) { |
|
174 |
RAttribute attr = aAttributes[i]; |
|
175 |
TBuf<KMaxStringBuffer> attr16; |
|
176 |
attr16.Copy(attr.Attribute().LocalName().DesC()); |
|
177 |
// url=... |
|
178 |
if (attr16.Compare(KTagUrl) == 0) { |
|
179 |
HBufC* val16 = HBufC::NewLC(KMaxParseBuffer); |
|
180 |
val16->Des().Copy(attr.Value().DesC()); |
|
181 |
iActiveShow->SetUrlL(*val16); |
|
123 | 182 |
|
183 |
if (PodcastUtils::IsVideoShow(*val16)) { |
|
184 |
iActiveShow->SetShowType(EVideoPodcast); |
|
185 |
} |
|
2 | 186 |
CleanupStack::PopAndDestroy(val16); |
187 |
// length=... |
|
188 |
} else if (attr16.Compare(KTagLength) == 0) { |
|
189 |
TLex8 lex(attr.Value().DesC()); |
|
190 |
TUint size = 0; |
|
191 |
lex.Val(size, EDecimal); |
|
192 |
iActiveShow->SetShowSize(size); |
|
193 |
} |
|
194 |
} |
|
195 |
// <channel> <item> <description> |
|
196 |
} else if (str.CompareF(KTagDescription) == 0) { |
|
197 |
iFeedState=EStateItemDescription; |
|
198 |
// <channel> <item> <pubdate> |
|
199 |
} else if (str.CompareF(KTagPubDate) == 0) { |
|
200 |
//DP("LastBuildDate BEGIN"); |
|
201 |
iFeedState = EStateItemPubDate; |
|
258
f02d87cb8d1f
Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
255
diff
changeset
|
202 |
// <channel> <item> <guid> |
f02d87cb8d1f
Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
255
diff
changeset
|
203 |
} else if (str.CompareF(KTagGuid) == 0) { |
f02d87cb8d1f
Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
255
diff
changeset
|
204 |
iFeedState = EStateItemGuid; |
2 | 205 |
} |
206 |
break; |
|
207 |
default: |
|
208 |
//DP2("Ignoring tag %S when in state %d", &str, iFeedState); |
|
209 |
break; |
|
210 |
} |
|
211 |
// DP1("OnStartElementL END state=%d", iFeedState); |
|
212 |
} |
|
213 |
||
214 |
void CFeedParser::OnEndElementL(const RTagInfo& aElement, TInt /*aErrorCode*/) |
|
215 |
{ |
|
216 |
||
217 |
if (iStoppedParsing) { |
|
218 |
return; |
|
219 |
} |
|
220 |
||
221 |
iBuffer.Trim(); |
|
222 |
||
223 |
TDesC8 lName = aElement.LocalName().DesC(); |
|
224 |
TBuf<KMaxStringBuffer> str; |
|
225 |
str.Copy(aElement.LocalName().DesC()); |
|
226 |
||
227 |
//DP2("OnEndElementL START state=%d, element=%S", iFeedState, &str); |
|
228 |
||
229 |
switch (iFeedState) { |
|
230 |
case EStateChannelTitle: |
|
231 |
if(str.CompareF(KTagTitle) == 0) { |
|
232 |
if (iActiveFeed->CustomTitle() == EFalse) { |
|
233 |
iActiveFeed->SetTitleL(iBuffer); |
|
234 |
} |
|
235 |
iFeedState = EStateChannel; |
|
236 |
} |
|
237 |
break; |
|
238 |
case EStateChannelLink: |
|
239 |
iActiveFeed->SetLinkL(iBuffer); |
|
240 |
iFeedState = EStateChannel; |
|
241 |
break; |
|
242 |
case EStateChannelDescription: |
|
243 |
iActiveFeed->SetDescriptionL(iBuffer); |
|
244 |
iFeedState = EStateChannel; |
|
245 |
break; |
|
246 |
case EStateChannelLastBuildDate: |
|
247 |
{ |
|
248 |
//DP("LastBuildDate END"); |
|
249 |
TInternetDate internetDate; |
|
250 |
TBuf8<128> temp; |
|
251 |
temp.Copy(iBuffer); |
|
252 |
||
253 |
TRAPD(parseError, internetDate.SetDateL(temp)); |
|
254 |
if(parseError == KErrNone) { |
|
255 |
if (TTime(internetDate.DateTime()) > iActiveFeed->BuildDate()) { |
|
256 |
DP("Successfully parsed build date"); |
|
257 |
iActiveFeed->SetBuildDate(TTime(internetDate.DateTime())); |
|
258 |
} else { |
|
259 |
DP("*** Nothing new, aborting parsing"); |
|
260 |
iStoppedParsing = ETrue; |
|
261 |
} |
|
262 |
} else { |
|
263 |
DP("Failed to parse last build date"); |
|
264 |
} |
|
265 |
iFeedState = EStateChannel; |
|
266 |
} |
|
267 |
break; |
|
268 |
case EStateChannelImageUrl: |
|
269 |
//DP1("Image url: %S", &iBuffer); |
|
270 |
iActiveFeed->SetImageUrlL(iBuffer); |
|
271 |
iFeedState = EStateChannelImage; |
|
272 |
break; |
|
273 |
case EStateChannelImage: |
|
274 |
if(str.CompareF(KTagImage) == 0) { |
|
275 |
iFeedState = EStateChannel; |
|
276 |
} |
|
277 |
break; |
|
278 |
case EStateItem: |
|
279 |
if (str.CompareF(KTagItem) == 0) |
|
254
042bb9038b32
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
126
diff
changeset
|
280 |
{ |
042bb9038b32
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
126
diff
changeset
|
281 |
// check if we have a valid pubdate |
042bb9038b32
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
126
diff
changeset
|
282 |
if (iActiveShow->PubDate().Int64() == 0) |
042bb9038b32
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
126
diff
changeset
|
283 |
{ |
042bb9038b32
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
126
diff
changeset
|
284 |
// set pubDate to present time |
042bb9038b32
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
126
diff
changeset
|
285 |
TTime now; |
042bb9038b32
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
126
diff
changeset
|
286 |
now.UniversalTime(); |
042bb9038b32
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
126
diff
changeset
|
287 |
|
042bb9038b32
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
126
diff
changeset
|
288 |
// but we want reverse sorting, so let's do a little trick... |
042bb9038b32
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
126
diff
changeset
|
289 |
TTimeIntervalHours delta; |
042bb9038b32
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
126
diff
changeset
|
290 |
delta = iItemsParsed; |
042bb9038b32
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
126
diff
changeset
|
291 |
|
042bb9038b32
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
126
diff
changeset
|
292 |
// ... remove an hour per show we've parsed so far |
042bb9038b32
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
126
diff
changeset
|
293 |
now -= delta; |
042bb9038b32
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
126
diff
changeset
|
294 |
|
042bb9038b32
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
126
diff
changeset
|
295 |
iActiveShow->SetPubDate(now); |
042bb9038b32
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
126
diff
changeset
|
296 |
} |
042bb9038b32
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
126
diff
changeset
|
297 |
|
258
f02d87cb8d1f
Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
255
diff
changeset
|
298 |
if (iUid) |
f02d87cb8d1f
Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
255
diff
changeset
|
299 |
{ |
f02d87cb8d1f
Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
255
diff
changeset
|
300 |
iActiveShow->SetUid(iUid); |
f02d87cb8d1f
Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
255
diff
changeset
|
301 |
} |
254
042bb9038b32
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
126
diff
changeset
|
302 |
|
2 | 303 |
iCallbacks.NewShowL(*iActiveShow); |
304 |
||
305 |
delete iActiveShow; |
|
306 |
||
307 |
// We should now be finished with the show. |
|
308 |
iActiveShow = NULL; |
|
309 |
||
310 |
iItemsParsed++; |
|
126 | 311 |
DP2("iItemsParsed: %d, iMaxItems: %d", iItemsParsed, iMaxItems); |
321
7a0fb290f9c6
Re-enabled max items parsed, because disabling this causes shows to turn up as new multiple times. This again breaks feeds that add new shows at the bottom, so we need to solve this properly.
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
258
diff
changeset
|
312 |
if (iItemsParsed >= iMaxItems) |
7a0fb290f9c6
Re-enabled max items parsed, because disabling this causes shows to turn up as new multiple times. This again breaks feeds that add new shows at the bottom, so we need to solve this properly.
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
258
diff
changeset
|
313 |
{ |
7a0fb290f9c6
Re-enabled max items parsed, because disabling this causes shows to turn up as new multiple times. This again breaks feeds that add new shows at the bottom, so we need to solve this properly.
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
258
diff
changeset
|
314 |
iStoppedParsing = ETrue; |
7a0fb290f9c6
Re-enabled max items parsed, because disabling this causes shows to turn up as new multiple times. This again breaks feeds that add new shows at the bottom, so we need to solve this properly.
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
258
diff
changeset
|
315 |
DP("*** Too many items, aborting parsing"); |
7a0fb290f9c6
Re-enabled max items parsed, because disabling this causes shows to turn up as new multiple times. This again breaks feeds that add new shows at the bottom, so we need to solve this properly.
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
258
diff
changeset
|
316 |
} |
2 | 317 |
|
318 |
iFeedState=EStateChannel; |
|
319 |
} |
|
320 |
break; |
|
321 |
case EStateItemPubDate: |
|
322 |
DP1("PubDate END: iBuffer='%S'", &iBuffer); |
|
323 |
if (str.CompareF(KTagPubDate) == 0) { |
|
330
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
324 |
DP1("iBuffer.Length()=%d", iBuffer.Length()); |
2 | 325 |
|
330
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
326 |
if (iBuffer.Length() > 6) |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
327 |
{ |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
328 |
// hack for feeds that don't always write day as two digits |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
329 |
TChar five(iBuffer[5]); |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
330 |
TChar six(iBuffer[6]); |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
331 |
|
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
332 |
if (five.IsDigit() && !six.IsDigit()) { |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
333 |
TBuf<KMaxStringBuffer> fix; |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
334 |
fix.Copy(iBuffer.Left(4)); |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
335 |
fix.Append(_L(" 0")); |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
336 |
fix.Append(iBuffer.Mid(5)); |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
337 |
iBuffer.Copy(fix); |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
338 |
} |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
339 |
// end hack |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
340 |
} |
2 | 341 |
|
330
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
342 |
if (iBuffer.Length() > 11) |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
343 |
{ |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
344 |
// hack for feeds that write out months in full |
2 | 345 |
|
330
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
346 |
if (iBuffer[11] != ' ') { |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
347 |
TPtrC midPtr = iBuffer.Mid(8); |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
348 |
|
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
349 |
int spacePos = midPtr.Find(_L(" ")); |
2 | 350 |
|
330
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
351 |
if (spacePos != KErrNotFound) { |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
352 |
//DP1("Month: %S", &midPtr.Left(spacePos)); |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
353 |
|
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
354 |
TBuf16<KBufferLength> newBuffer; |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
355 |
newBuffer.Copy(iBuffer.Left(11)); |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
356 |
newBuffer.Append(_L(" ")); |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
357 |
newBuffer.Append(iBuffer.Mid(11+spacePos)); |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
358 |
//DP1("newBuffer: %S", &newBuffer); |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
359 |
iBuffer.Copy(newBuffer); |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
360 |
} |
2 | 361 |
} |
330
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
362 |
|
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
363 |
// hack for feeds that write days and months as UPPERCASE |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
364 |
TChar one(iBuffer[1]); |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
365 |
TChar two(iBuffer[2]); |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
366 |
TChar nine(iBuffer[9]); |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
367 |
TChar ten(iBuffer[10]); |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
368 |
|
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
369 |
one.LowerCase(); |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
370 |
two.LowerCase(); |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
371 |
nine.LowerCase(); |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
372 |
ten.LowerCase(); |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
373 |
|
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
374 |
iBuffer[1] = one; |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
375 |
iBuffer[2] = two; |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
376 |
iBuffer[9] = nine; |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
377 |
iBuffer[10] = ten; |
4cf89a7d3476
Fix for bug 3911 - Podcatcher still crashes when trying to update some feeds
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
321
diff
changeset
|
378 |
} |
2 | 379 |
|
380 |
TBuf8<128> temp; |
|
381 |
temp.Copy(iBuffer); |
|
382 |
TInternetDate internetDate; |
|
383 |
TRAPD(parseError, internetDate.SetDateL(temp)); |
|
384 |
if(parseError == KErrNone) { |
|
385 |
//DP1("PubDate parse success: '%S'", &iBuffer); |
|
386 |
iActiveShow->SetPubDate(TTime(internetDate.DateTime())); |
|
387 |
||
388 |
||
389 |
DP6("Successfully parsed pubdate %d/%d/%d %d:%d:%d", |
|
390 |
iActiveShow->PubDate().DateTime().Year(), |
|
391 |
iActiveShow->PubDate().DateTime().Month(), |
|
392 |
iActiveShow->PubDate().DateTime().Day(), |
|
393 |
iActiveShow->PubDate().DateTime().Hour(), |
|
394 |
iActiveShow->PubDate().DateTime().Minute(), |
|
395 |
iActiveShow->PubDate().DateTime().Second()); |
|
396 |
||
397 |
} else { |
|
398 |
DP2("Pubdate parse error: '%S', error=%d", &iBuffer, parseError); |
|
399 |
} |
|
400 |
} |
|
401 |
iFeedState=EStateItem; |
|
402 |
break; |
|
258
f02d87cb8d1f
Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
255
diff
changeset
|
403 |
case EStateItemGuid: |
f02d87cb8d1f
Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
255
diff
changeset
|
404 |
iUid = DefaultHash::Des16(iBuffer); |
f02d87cb8d1f
Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
255
diff
changeset
|
405 |
iFeedState=EStateItem; |
f02d87cb8d1f
Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
255
diff
changeset
|
406 |
break; |
2 | 407 |
case EStateItemTitle: |
408 |
//DP1("title: %S", &iBuffer); |
|
409 |
iActiveShow->SetTitleL(iBuffer); |
|
410 |
iFeedState = EStateItem; |
|
411 |
break; |
|
412 |
case EStateItemLink: |
|
413 |
if (iActiveShow->Url().Length() == 0) { |
|
414 |
iActiveShow->SetUrlL(iBuffer); |
|
123 | 415 |
|
416 |
if (PodcastUtils::IsVideoShow(iBuffer)) { |
|
417 |
iActiveShow->SetShowType(EVideoPodcast); |
|
418 |
} |
|
2 | 419 |
} |
420 |
iFeedState = EStateItem; |
|
421 |
break; |
|
422 |
case EStateItemDescription: |
|
423 |
iActiveShow->SetDescriptionL(iBuffer); |
|
424 |
iFeedState = EStateItem; |
|
425 |
break; |
|
426 |
default: |
|
427 |
// fall back to channel level when in doubt |
|
428 |
iFeedState = EStateChannel; |
|
429 |
//DP2("Don't know how to handle end tag %S when in state %d", &str, iFeedState); |
|
430 |
break; |
|
431 |
} |
|
432 |
||
433 |
//DP1("OnEndElementL END state=%d", iFeedState); |
|
434 |
} |
|
435 |
||
436 |
void CFeedParser::OnContentL(const TDesC8& aBytes, TInt /*aErrorCode*/) |
|
437 |
{ |
|
438 |
TBuf<KBufferLength> temp; |
|
439 |
if (iEncoding == EUtf8) { |
|
440 |
CnvUtfConverter::ConvertToUnicodeFromUtf8(temp, aBytes); |
|
441 |
} else { |
|
442 |
temp.Copy(aBytes); |
|
443 |
} |
|
444 |
||
445 |
if(temp.Length() + iBuffer.Length() < KBufferLength) { |
|
446 |
iBuffer.Append(temp); |
|
447 |
} |
|
448 |
} |
|
449 |
||
450 |
void CFeedParser::OnStartPrefixMappingL(const RString& /*aPrefix*/, const RString& /*aUri*/, TInt /*aErrorCode*/) |
|
451 |
{ |
|
452 |
DP("OnStartPrefixMappingL()"); |
|
453 |
} |
|
454 |
||
455 |
void CFeedParser::OnEndPrefixMappingL(const RString& /*aPrefix*/, TInt /*aErrorCode*/) |
|
456 |
{ |
|
457 |
DP("OnEndPrefixMappingL()"); |
|
458 |
} |
|
459 |
||
460 |
void CFeedParser::OnIgnorableWhiteSpaceL(const TDesC8& /*aBytes*/, TInt /*aErrorCode*/) |
|
461 |
{ |
|
462 |
DP("OnIgnorableWhiteSpaceL()"); |
|
463 |
} |
|
464 |
||
465 |
void CFeedParser::OnSkippedEntityL(const RString& /*aName*/, TInt /*aErrorCode*/) |
|
466 |
{ |
|
467 |
DP("OnSkippedEntityL()"); |
|
468 |
} |
|
469 |
||
470 |
void CFeedParser::OnProcessingInstructionL(const TDesC8& /*aTarget*/, const TDesC8& /*aData*/, TInt /*aErrorCode*/) |
|
471 |
{ |
|
472 |
DP("OnProcessingInstructionL()"); |
|
473 |
} |
|
474 |
||
475 |
void CFeedParser::OnError(TInt aErrorCode) |
|
476 |
{ |
|
477 |
DP1("CFeedParser::OnError %d", aErrorCode); |
|
478 |
} |
|
479 |
||
480 |
TAny* CFeedParser::GetExtendedInterface(const TInt32 /*aUid*/) |
|
481 |
{ |
|
482 |
DP("GetExtendedInterface()"); |
|
483 |
return NULL; |
|
484 |
} |
|
485 |
||
486 |
CFeedInfo& CFeedParser::ActiveFeed() |
|
487 |
{ |
|
488 |
return *iActiveFeed; |
|
489 |
} |