Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : /*
7 : Implementation for a file system RDF data store.
8 : */
9 :
10 : #include "nsFileSystemDataSource.h"
11 :
12 : #include <ctype.h> // for toupper()
13 : #include <stdio.h>
14 : #include "nsArrayEnumerator.h"
15 : #include "nsCOMArray.h"
16 : #include "nsIRDFDataSource.h"
17 : #include "nsIRDFObserver.h"
18 : #include "nsIServiceManager.h"
19 : #include "nsXPIDLString.h"
20 : #include "nsRDFCID.h"
21 : #include "rdfutil.h"
22 : #include "rdf.h"
23 : #include "nsEnumeratorUtils.h"
24 : #include "nsIURL.h"
25 : #include "nsIFileURL.h"
26 : #include "nsNetUtil.h"
27 : #include "nsIInputStream.h"
28 : #include "nsIChannel.h"
29 : #include "nsIFile.h"
30 : #include "nsEscape.h"
31 : #include "nsCRTGlue.h"
32 : #include "nsAutoPtr.h"
33 : #include "prtime.h"
34 :
35 : #ifdef XP_WIN
36 : #include "windef.h"
37 : #include "winbase.h"
38 : #include "nsILineInputStream.h"
39 : #include "nsDirectoryServiceDefs.h"
40 : #endif
41 :
42 : #define NS_MOZICON_SCHEME "moz-icon:"
43 :
44 : static const char kFileProtocol[] = "file://";
45 :
46 : bool
47 0 : FileSystemDataSource::isFileURI(nsIRDFResource *r)
48 : {
49 0 : bool isFileURIFlag = false;
50 0 : const char *uri = nullptr;
51 :
52 0 : r->GetValueConst(&uri);
53 0 : if ((uri) && (!strncmp(uri, kFileProtocol, sizeof(kFileProtocol) - 1)))
54 : {
55 : // XXX HACK HACK HACK
56 0 : if (!strchr(uri, '#'))
57 : {
58 0 : isFileURIFlag = true;
59 : }
60 : }
61 0 : return(isFileURIFlag);
62 : }
63 :
64 :
65 :
66 : bool
67 0 : FileSystemDataSource::isDirURI(nsIRDFResource* source)
68 : {
69 : nsresult rv;
70 0 : const char *uri = nullptr;
71 :
72 0 : rv = source->GetValueConst(&uri);
73 0 : if (NS_FAILED(rv)) return(false);
74 :
75 0 : nsCOMPtr<nsIFile> aDir;
76 :
77 0 : rv = NS_GetFileFromURLSpec(nsDependentCString(uri), getter_AddRefs(aDir));
78 0 : if (NS_FAILED(rv)) return(false);
79 :
80 0 : bool isDirFlag = false;
81 :
82 0 : rv = aDir->IsDirectory(&isDirFlag);
83 0 : if (NS_FAILED(rv)) return(false);
84 :
85 0 : return(isDirFlag);
86 : }
87 :
88 :
89 : nsresult
90 0 : FileSystemDataSource::Init()
91 : {
92 : nsresult rv;
93 :
94 0 : mRDFService = do_GetService("@mozilla.org/rdf/rdf-service;1");
95 0 : NS_ENSURE_TRUE(mRDFService, NS_ERROR_FAILURE);
96 :
97 0 : rv = mRDFService->GetResource(NS_LITERAL_CSTRING("NC:FilesRoot"),
98 0 : getter_AddRefs(mNC_FileSystemRoot));
99 0 : nsresult tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "child"),
100 0 : getter_AddRefs(mNC_Child));
101 0 : if (NS_FAILED(tmp)) {
102 0 : rv = tmp;
103 : }
104 0 : tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Name"),
105 0 : getter_AddRefs(mNC_Name));
106 0 : if (NS_FAILED(tmp)) {
107 0 : rv = tmp;
108 : }
109 0 : tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "URL"),
110 0 : getter_AddRefs(mNC_URL));
111 0 : if (NS_FAILED(tmp)) {
112 0 : rv = tmp;
113 : }
114 0 : tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Icon"),
115 0 : getter_AddRefs(mNC_Icon));
116 0 : if (NS_FAILED(tmp)) {
117 0 : rv = tmp;
118 : }
119 0 : tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Content-Length"),
120 0 : getter_AddRefs(mNC_Length));
121 0 : if (NS_FAILED(tmp)) {
122 0 : rv = tmp;
123 : }
124 0 : tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "IsDirectory"),
125 0 : getter_AddRefs(mNC_IsDirectory));
126 0 : if (NS_FAILED(tmp)) {
127 0 : rv = tmp;
128 : }
129 0 : tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(WEB_NAMESPACE_URI "LastModifiedDate"),
130 0 : getter_AddRefs(mWEB_LastMod));
131 0 : if (NS_FAILED(tmp)) {
132 0 : rv = tmp;
133 : }
134 0 : tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "FileSystemObject"),
135 0 : getter_AddRefs(mNC_FileSystemObject));
136 0 : if (NS_FAILED(tmp)) {
137 0 : rv = tmp;
138 : }
139 0 : tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "pulse"),
140 0 : getter_AddRefs(mNC_pulse));
141 0 : if (NS_FAILED(tmp)) {
142 0 : rv = tmp;
143 : }
144 0 : tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "instanceOf"),
145 0 : getter_AddRefs(mRDF_InstanceOf));
146 0 : if (NS_FAILED(tmp)) {
147 0 : rv = tmp;
148 : }
149 0 : tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "type"),
150 0 : getter_AddRefs(mRDF_type));
151 :
152 : static const char16_t kTrue[] = {'t','r','u','e','\0'};
153 : static const char16_t kFalse[] = {'f','a','l','s','e','\0'};
154 :
155 0 : tmp = mRDFService->GetLiteral(kTrue, getter_AddRefs(mLiteralTrue));
156 0 : if (NS_FAILED(tmp)) {
157 0 : rv = tmp;
158 : }
159 0 : tmp = mRDFService->GetLiteral(kFalse, getter_AddRefs(mLiteralFalse));
160 0 : if (NS_FAILED(tmp)) {
161 0 : rv = tmp;
162 : }
163 0 : NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
164 :
165 : #ifdef USE_NC_EXTENSION
166 0 : rv = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "extension"),
167 0 : getter_AddRefs(mNC_extension));
168 0 : NS_ENSURE_SUCCESS(rv, rv);
169 : #endif
170 :
171 : #ifdef XP_WIN
172 : rv = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "IEFavorite"),
173 : getter_AddRefs(mNC_IEFavoriteObject));
174 : tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "IEFavoriteFolder"),
175 : getter_AddRefs(mNC_IEFavoriteFolder));
176 : if (NS_FAILED(tmp)) {
177 : rv = tmp;
178 : }
179 : NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
180 :
181 : nsCOMPtr<nsIFile> file;
182 : NS_GetSpecialDirectory(NS_WIN_FAVORITES_DIR, getter_AddRefs(file));
183 : if (file)
184 : {
185 : nsCOMPtr<nsIURI> furi;
186 : NS_NewFileURI(getter_AddRefs(furi), file);
187 : NS_ENSURE_TRUE(furi, NS_ERROR_FAILURE);
188 :
189 : file->GetNativePath(ieFavoritesDir);
190 : }
191 : #endif
192 :
193 0 : return NS_OK;
194 : }
195 :
196 : //static
197 : nsresult
198 0 : FileSystemDataSource::Create(nsISupports* aOuter, const nsIID& aIID, void **aResult)
199 : {
200 0 : NS_ENSURE_NO_AGGREGATION(aOuter);
201 :
202 0 : RefPtr<FileSystemDataSource> self = new FileSystemDataSource();
203 0 : if (!self)
204 0 : return NS_ERROR_OUT_OF_MEMORY;
205 :
206 0 : nsresult rv = self->Init();
207 0 : NS_ENSURE_SUCCESS(rv, rv);
208 :
209 0 : return self->QueryInterface(aIID, aResult);
210 : }
211 :
212 0 : NS_IMPL_ISUPPORTS(FileSystemDataSource, nsIRDFDataSource)
213 :
214 : NS_IMETHODIMP
215 0 : FileSystemDataSource::GetURI(char **uri)
216 : {
217 0 : NS_PRECONDITION(uri != nullptr, "null ptr");
218 0 : if (! uri)
219 0 : return NS_ERROR_NULL_POINTER;
220 :
221 0 : if ((*uri = NS_strdup("rdf:files")) == nullptr)
222 0 : return NS_ERROR_OUT_OF_MEMORY;
223 :
224 0 : return NS_OK;
225 : }
226 :
227 :
228 :
229 : NS_IMETHODIMP
230 0 : FileSystemDataSource::GetSource(nsIRDFResource* property,
231 : nsIRDFNode* target,
232 : bool tv,
233 : nsIRDFResource** source /* out */)
234 : {
235 0 : NS_PRECONDITION(property != nullptr, "null ptr");
236 0 : if (! property)
237 0 : return NS_ERROR_NULL_POINTER;
238 :
239 0 : NS_PRECONDITION(target != nullptr, "null ptr");
240 0 : if (! target)
241 0 : return NS_ERROR_NULL_POINTER;
242 :
243 0 : NS_PRECONDITION(source != nullptr, "null ptr");
244 0 : if (! source)
245 0 : return NS_ERROR_NULL_POINTER;
246 :
247 0 : *source = nullptr;
248 0 : return NS_RDF_NO_VALUE;
249 : }
250 :
251 :
252 :
253 : NS_IMETHODIMP
254 0 : FileSystemDataSource::GetSources(nsIRDFResource *property,
255 : nsIRDFNode *target,
256 : bool tv,
257 : nsISimpleEnumerator **sources /* out */)
258 : {
259 : // NS_NOTYETIMPLEMENTED("write me");
260 0 : return NS_ERROR_NOT_IMPLEMENTED;
261 : }
262 :
263 :
264 :
265 : NS_IMETHODIMP
266 0 : FileSystemDataSource::GetTarget(nsIRDFResource *source,
267 : nsIRDFResource *property,
268 : bool tv,
269 : nsIRDFNode **target /* out */)
270 : {
271 0 : NS_PRECONDITION(source != nullptr, "null ptr");
272 0 : if (! source)
273 0 : return NS_ERROR_NULL_POINTER;
274 :
275 0 : NS_PRECONDITION(property != nullptr, "null ptr");
276 0 : if (! property)
277 0 : return NS_ERROR_NULL_POINTER;
278 :
279 0 : NS_PRECONDITION(target != nullptr, "null ptr");
280 0 : if (! target)
281 0 : return NS_ERROR_NULL_POINTER;
282 :
283 0 : *target = nullptr;
284 :
285 0 : nsresult rv = NS_RDF_NO_VALUE;
286 :
287 : // we only have positive assertions in the file system data source.
288 0 : if (! tv)
289 0 : return NS_RDF_NO_VALUE;
290 :
291 0 : if (source == mNC_FileSystemRoot)
292 : {
293 0 : if (property == mNC_pulse)
294 : {
295 : nsIRDFLiteral *pulseLiteral;
296 0 : mRDFService->GetLiteral(u"12", &pulseLiteral);
297 0 : *target = pulseLiteral;
298 0 : return NS_OK;
299 : }
300 : }
301 0 : else if (isFileURI(source))
302 : {
303 0 : if (property == mNC_Name)
304 : {
305 0 : nsCOMPtr<nsIRDFLiteral> name;
306 0 : rv = GetName(source, getter_AddRefs(name));
307 0 : if (NS_FAILED(rv)) return(rv);
308 0 : if (!name) rv = NS_RDF_NO_VALUE;
309 0 : if (rv == NS_RDF_NO_VALUE) return(rv);
310 0 : return name->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target);
311 : }
312 0 : else if (property == mNC_URL)
313 : {
314 0 : nsCOMPtr<nsIRDFLiteral> url;
315 0 : rv = GetURL(source, nullptr, getter_AddRefs(url));
316 0 : if (NS_FAILED(rv)) return(rv);
317 0 : if (!url) rv = NS_RDF_NO_VALUE;
318 0 : if (rv == NS_RDF_NO_VALUE) return(rv);
319 :
320 0 : return url->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target);
321 : }
322 0 : else if (property == mNC_Icon)
323 : {
324 0 : nsCOMPtr<nsIRDFLiteral> url;
325 0 : bool isFavorite = false;
326 0 : rv = GetURL(source, &isFavorite, getter_AddRefs(url));
327 0 : if (NS_FAILED(rv)) return(rv);
328 0 : if (isFavorite || !url) rv = NS_RDF_NO_VALUE;
329 0 : if (rv == NS_RDF_NO_VALUE) return(rv);
330 :
331 0 : const char16_t *uni = nullptr;
332 0 : url->GetValueConst(&uni);
333 0 : if (!uni) return(NS_RDF_NO_VALUE);
334 0 : nsAutoString urlStr;
335 0 : urlStr.AssignLiteral(NS_MOZICON_SCHEME);
336 0 : urlStr.Append(uni);
337 :
338 0 : rv = mRDFService->GetLiteral(urlStr.get(), getter_AddRefs(url));
339 0 : if (NS_FAILED(rv) || !url) return(NS_RDF_NO_VALUE);
340 0 : return url->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target);
341 : }
342 0 : else if (property == mNC_Length)
343 : {
344 0 : nsCOMPtr<nsIRDFInt> fileSize;
345 0 : rv = GetFileSize(source, getter_AddRefs(fileSize));
346 0 : if (NS_FAILED(rv)) return(rv);
347 0 : if (!fileSize) rv = NS_RDF_NO_VALUE;
348 0 : if (rv == NS_RDF_NO_VALUE) return(rv);
349 :
350 0 : return fileSize->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target);
351 : }
352 0 : else if (property == mNC_IsDirectory)
353 : {
354 0 : *target = (isDirURI(source)) ? mLiteralTrue : mLiteralFalse;
355 0 : NS_ADDREF(*target);
356 0 : return NS_OK;
357 : }
358 0 : else if (property == mWEB_LastMod)
359 : {
360 0 : nsCOMPtr<nsIRDFDate> lastMod;
361 0 : rv = GetLastMod(source, getter_AddRefs(lastMod));
362 0 : if (NS_FAILED(rv)) return(rv);
363 0 : if (!lastMod) rv = NS_RDF_NO_VALUE;
364 0 : if (rv == NS_RDF_NO_VALUE) return(rv);
365 :
366 0 : return lastMod->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target);
367 : }
368 0 : else if (property == mRDF_type)
369 : {
370 0 : nsCString type;
371 0 : rv = mNC_FileSystemObject->GetValueUTF8(type);
372 0 : if (NS_FAILED(rv)) return(rv);
373 :
374 : #ifdef XP_WIN
375 : // under Windows, if its an IE favorite, return that type
376 : if (!ieFavoritesDir.IsEmpty())
377 : {
378 : nsCString uri;
379 : rv = source->GetValueUTF8(uri);
380 : if (NS_FAILED(rv)) return(rv);
381 :
382 : NS_ConvertUTF8toUTF16 theURI(uri);
383 :
384 : if (theURI.Find(ieFavoritesDir) == 0)
385 : {
386 : if (theURI[theURI.Length() - 1] == '/')
387 : {
388 : rv = mNC_IEFavoriteFolder->GetValueUTF8(type);
389 : }
390 : else
391 : {
392 : rv = mNC_IEFavoriteObject->GetValueUTF8(type);
393 : }
394 : if (NS_FAILED(rv)) return(rv);
395 : }
396 : }
397 : #endif
398 :
399 0 : NS_ConvertUTF8toUTF16 url(type);
400 0 : nsCOMPtr<nsIRDFLiteral> literal;
401 0 : mRDFService->GetLiteral(url.get(), getter_AddRefs(literal));
402 0 : rv = literal->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target);
403 0 : return(rv);
404 : }
405 0 : else if (property == mNC_pulse)
406 : {
407 0 : nsCOMPtr<nsIRDFLiteral> pulseLiteral;
408 0 : mRDFService->GetLiteral(u"12", getter_AddRefs(pulseLiteral));
409 0 : rv = pulseLiteral->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target);
410 0 : return(rv);
411 : }
412 0 : else if (property == mNC_Child)
413 : {
414 : // Oh this is evil. Somebody kill me now.
415 0 : nsCOMPtr<nsISimpleEnumerator> children;
416 0 : rv = GetFolderList(source, false, true, getter_AddRefs(children));
417 0 : if (NS_FAILED(rv) || (rv == NS_RDF_NO_VALUE)) return(rv);
418 :
419 : bool hasMore;
420 0 : rv = children->HasMoreElements(&hasMore);
421 0 : if (NS_FAILED(rv)) return(rv);
422 :
423 0 : if (hasMore)
424 : {
425 0 : nsCOMPtr<nsISupports> isupports;
426 0 : rv = children->GetNext(getter_AddRefs(isupports));
427 0 : if (NS_FAILED(rv)) return(rv);
428 :
429 0 : return isupports->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target);
430 : }
431 : }
432 : #ifdef USE_NC_EXTENSION
433 0 : else if (property == mNC_extension)
434 : {
435 0 : nsCOMPtr<nsIRDFLiteral> extension;
436 0 : rv = GetExtension(source, getter_AddRefs(extension));
437 0 : if (!extension) rv = NS_RDF_NO_VALUE;
438 0 : if (rv == NS_RDF_NO_VALUE) return(rv);
439 0 : return extension->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target);
440 : }
441 : #endif
442 : }
443 :
444 0 : return(NS_RDF_NO_VALUE);
445 : }
446 :
447 :
448 :
449 : NS_IMETHODIMP
450 0 : FileSystemDataSource::GetTargets(nsIRDFResource *source,
451 : nsIRDFResource *property,
452 : bool tv,
453 : nsISimpleEnumerator **targets /* out */)
454 : {
455 0 : NS_PRECONDITION(source != nullptr, "null ptr");
456 0 : if (! source)
457 0 : return NS_ERROR_NULL_POINTER;
458 :
459 0 : NS_PRECONDITION(property != nullptr, "null ptr");
460 0 : if (! property)
461 0 : return NS_ERROR_NULL_POINTER;
462 :
463 0 : NS_PRECONDITION(targets != nullptr, "null ptr");
464 0 : if (! targets)
465 0 : return NS_ERROR_NULL_POINTER;
466 :
467 0 : *targets = nullptr;
468 :
469 : // we only have positive assertions in the file system data source.
470 0 : if (! tv)
471 0 : return NS_RDF_NO_VALUE;
472 :
473 : nsresult rv;
474 :
475 0 : if (source == mNC_FileSystemRoot)
476 : {
477 0 : if (property == mNC_Child)
478 : {
479 0 : return GetVolumeList(targets);
480 : }
481 0 : else if (property == mNC_pulse)
482 : {
483 0 : nsCOMPtr<nsIRDFLiteral> pulseLiteral;
484 0 : mRDFService->GetLiteral(u"12",
485 0 : getter_AddRefs(pulseLiteral));
486 0 : return NS_NewSingletonEnumerator(targets, pulseLiteral);
487 : }
488 : }
489 0 : else if (isFileURI(source))
490 : {
491 0 : if (property == mNC_Child)
492 : {
493 0 : return GetFolderList(source, false, false, targets);
494 : }
495 0 : else if (property == mNC_Name)
496 : {
497 0 : nsCOMPtr<nsIRDFLiteral> name;
498 0 : rv = GetName(source, getter_AddRefs(name));
499 0 : if (NS_FAILED(rv)) return rv;
500 :
501 0 : return NS_NewSingletonEnumerator(targets, name);
502 : }
503 0 : else if (property == mNC_URL)
504 : {
505 0 : nsCOMPtr<nsIRDFLiteral> url;
506 0 : rv = GetURL(source, nullptr, getter_AddRefs(url));
507 0 : if (NS_FAILED(rv)) return rv;
508 :
509 0 : return NS_NewSingletonEnumerator(targets, url);
510 : }
511 0 : else if (property == mRDF_type)
512 : {
513 0 : nsCString uri;
514 0 : rv = mNC_FileSystemObject->GetValueUTF8(uri);
515 0 : if (NS_FAILED(rv)) return rv;
516 :
517 0 : NS_ConvertUTF8toUTF16 url(uri);
518 :
519 0 : nsCOMPtr<nsIRDFLiteral> literal;
520 0 : rv = mRDFService->GetLiteral(url.get(), getter_AddRefs(literal));
521 0 : if (NS_FAILED(rv)) return rv;
522 :
523 0 : return NS_NewSingletonEnumerator(targets, literal);
524 : }
525 0 : else if (property == mNC_pulse)
526 : {
527 0 : nsCOMPtr<nsIRDFLiteral> pulseLiteral;
528 0 : rv = mRDFService->GetLiteral(u"12",
529 0 : getter_AddRefs(pulseLiteral));
530 0 : if (NS_FAILED(rv)) return rv;
531 :
532 0 : return NS_NewSingletonEnumerator(targets, pulseLiteral);
533 : }
534 : }
535 :
536 0 : return NS_NewEmptyEnumerator(targets);
537 : }
538 :
539 :
540 :
541 : NS_IMETHODIMP
542 0 : FileSystemDataSource::Assert(nsIRDFResource *source,
543 : nsIRDFResource *property,
544 : nsIRDFNode *target,
545 : bool tv)
546 : {
547 0 : return NS_RDF_ASSERTION_REJECTED;
548 : }
549 :
550 :
551 :
552 : NS_IMETHODIMP
553 0 : FileSystemDataSource::Unassert(nsIRDFResource *source,
554 : nsIRDFResource *property,
555 : nsIRDFNode *target)
556 : {
557 0 : return NS_RDF_ASSERTION_REJECTED;
558 : }
559 :
560 :
561 :
562 : NS_IMETHODIMP
563 0 : FileSystemDataSource::Change(nsIRDFResource* aSource,
564 : nsIRDFResource* aProperty,
565 : nsIRDFNode* aOldTarget,
566 : nsIRDFNode* aNewTarget)
567 : {
568 0 : return NS_RDF_ASSERTION_REJECTED;
569 : }
570 :
571 :
572 :
573 : NS_IMETHODIMP
574 0 : FileSystemDataSource::Move(nsIRDFResource* aOldSource,
575 : nsIRDFResource* aNewSource,
576 : nsIRDFResource* aProperty,
577 : nsIRDFNode* aTarget)
578 : {
579 0 : return NS_RDF_ASSERTION_REJECTED;
580 : }
581 :
582 :
583 :
584 : NS_IMETHODIMP
585 0 : FileSystemDataSource::HasAssertion(nsIRDFResource *source,
586 : nsIRDFResource *property,
587 : nsIRDFNode *target,
588 : bool tv,
589 : bool *hasAssertion /* out */)
590 : {
591 0 : NS_PRECONDITION(source != nullptr, "null ptr");
592 0 : if (! source)
593 0 : return NS_ERROR_NULL_POINTER;
594 :
595 0 : NS_PRECONDITION(property != nullptr, "null ptr");
596 0 : if (! property)
597 0 : return NS_ERROR_NULL_POINTER;
598 :
599 0 : NS_PRECONDITION(target != nullptr, "null ptr");
600 0 : if (! target)
601 0 : return NS_ERROR_NULL_POINTER;
602 :
603 0 : NS_PRECONDITION(hasAssertion != nullptr, "null ptr");
604 0 : if (! hasAssertion)
605 0 : return NS_ERROR_NULL_POINTER;
606 :
607 : // we only have positive assertions in the file system data source.
608 0 : *hasAssertion = false;
609 :
610 0 : if (! tv) {
611 0 : return NS_OK;
612 : }
613 :
614 0 : if ((source == mNC_FileSystemRoot) || isFileURI(source))
615 : {
616 0 : if (property == mRDF_type)
617 : {
618 0 : nsCOMPtr<nsIRDFResource> resource( do_QueryInterface(target) );
619 0 : if (resource.get() == mRDF_type)
620 : {
621 0 : *hasAssertion = true;
622 : }
623 : }
624 : #ifdef USE_NC_EXTENSION
625 0 : else if (property == mNC_extension)
626 : {
627 : // Cheat just a little here by making dirs always match
628 0 : if (isDirURI(source))
629 : {
630 0 : *hasAssertion = true;
631 : }
632 : else
633 : {
634 0 : nsCOMPtr<nsIRDFLiteral> extension;
635 0 : GetExtension(source, getter_AddRefs(extension));
636 0 : if (extension.get() == target)
637 : {
638 0 : *hasAssertion = true;
639 : }
640 : }
641 : }
642 : #endif
643 0 : else if (property == mNC_IsDirectory)
644 : {
645 0 : bool isDir = isDirURI(source);
646 0 : bool isEqual = false;
647 0 : target->EqualsNode(mLiteralTrue, &isEqual);
648 0 : if (isEqual)
649 : {
650 0 : *hasAssertion = isDir;
651 : }
652 : else
653 : {
654 0 : target->EqualsNode(mLiteralFalse, &isEqual);
655 0 : if (isEqual)
656 0 : *hasAssertion = !isDir;
657 : }
658 : }
659 : }
660 :
661 0 : return NS_OK;
662 : }
663 :
664 :
665 :
666 : NS_IMETHODIMP
667 0 : FileSystemDataSource::HasArcIn(nsIRDFNode *aNode, nsIRDFResource *aArc, bool *result)
668 : {
669 0 : return NS_ERROR_NOT_IMPLEMENTED;
670 : }
671 :
672 :
673 :
674 : NS_IMETHODIMP
675 0 : FileSystemDataSource::HasArcOut(nsIRDFResource *aSource, nsIRDFResource *aArc, bool *result)
676 : {
677 0 : *result = false;
678 :
679 0 : if (aSource == mNC_FileSystemRoot)
680 : {
681 0 : *result = (aArc == mNC_Child || aArc == mNC_pulse);
682 : }
683 0 : else if (isFileURI(aSource))
684 : {
685 0 : if (aArc == mNC_pulse)
686 : {
687 0 : *result = true;
688 : }
689 0 : else if (isDirURI(aSource))
690 : {
691 : #ifdef XP_WIN
692 : *result = isValidFolder(aSource);
693 : #else
694 0 : *result = true;
695 : #endif
696 : }
697 0 : else if (aArc == mNC_pulse || aArc == mNC_Name || aArc == mNC_Icon ||
698 0 : aArc == mNC_URL || aArc == mNC_Length || aArc == mWEB_LastMod ||
699 0 : aArc == mNC_FileSystemObject || aArc == mRDF_InstanceOf ||
700 0 : aArc == mRDF_type)
701 : {
702 0 : *result = true;
703 : }
704 : }
705 0 : return NS_OK;
706 : }
707 :
708 :
709 :
710 : NS_IMETHODIMP
711 0 : FileSystemDataSource::ArcLabelsIn(nsIRDFNode *node,
712 : nsISimpleEnumerator ** labels /* out */)
713 : {
714 : // NS_NOTYETIMPLEMENTED("write me");
715 0 : return NS_ERROR_NOT_IMPLEMENTED;
716 : }
717 :
718 :
719 :
720 : NS_IMETHODIMP
721 0 : FileSystemDataSource::ArcLabelsOut(nsIRDFResource *source,
722 : nsISimpleEnumerator **labels /* out */)
723 : {
724 0 : NS_PRECONDITION(source != nullptr, "null ptr");
725 0 : if (! source)
726 0 : return NS_ERROR_NULL_POINTER;
727 :
728 0 : NS_PRECONDITION(labels != nullptr, "null ptr");
729 0 : if (! labels)
730 0 : return NS_ERROR_NULL_POINTER;
731 :
732 0 : if (source == mNC_FileSystemRoot)
733 : {
734 0 : nsCOMArray<nsIRDFResource> resources;
735 0 : resources.SetCapacity(2);
736 :
737 0 : resources.AppendObject(mNC_Child);
738 0 : resources.AppendObject(mNC_pulse);
739 :
740 0 : return NS_NewArrayEnumerator(labels, resources);
741 : }
742 0 : else if (isFileURI(source))
743 : {
744 0 : nsCOMArray<nsIRDFResource> resources;
745 0 : resources.SetCapacity(2);
746 :
747 0 : if (isDirURI(source))
748 : {
749 : #ifdef XP_WIN
750 : if (isValidFolder(source))
751 : {
752 : resources.AppendObject(mNC_Child);
753 : }
754 : #else
755 0 : resources.AppendObject(mNC_Child);
756 : #endif
757 0 : resources.AppendObject(mNC_pulse);
758 : }
759 :
760 0 : return NS_NewArrayEnumerator(labels, resources);
761 : }
762 :
763 0 : return NS_NewEmptyEnumerator(labels);
764 : }
765 :
766 :
767 :
768 : NS_IMETHODIMP
769 0 : FileSystemDataSource::GetAllResources(nsISimpleEnumerator** aCursor)
770 : {
771 0 : NS_NOTYETIMPLEMENTED("sorry!");
772 0 : return NS_ERROR_NOT_IMPLEMENTED;
773 : }
774 :
775 :
776 :
777 : NS_IMETHODIMP
778 0 : FileSystemDataSource::AddObserver(nsIRDFObserver *n)
779 : {
780 0 : return NS_ERROR_NOT_IMPLEMENTED;
781 : }
782 :
783 :
784 :
785 : NS_IMETHODIMP
786 0 : FileSystemDataSource::RemoveObserver(nsIRDFObserver *n)
787 : {
788 0 : return NS_ERROR_NOT_IMPLEMENTED;
789 : }
790 :
791 :
792 :
793 : NS_IMETHODIMP
794 0 : FileSystemDataSource::GetAllCmds(nsIRDFResource* source,
795 : nsISimpleEnumerator/*<nsIRDFResource>*/** commands)
796 : {
797 0 : return(NS_NewEmptyEnumerator(commands));
798 : }
799 :
800 :
801 :
802 : NS_IMETHODIMP
803 0 : FileSystemDataSource::IsCommandEnabled(nsISupports/*<nsIRDFResource>*/* aSources,
804 : nsIRDFResource* aCommand,
805 : nsISupports/*<nsIRDFResource>*/* aArguments,
806 : bool* aResult)
807 : {
808 0 : return(NS_ERROR_NOT_IMPLEMENTED);
809 : }
810 :
811 :
812 :
813 : NS_IMETHODIMP
814 0 : FileSystemDataSource::DoCommand(nsISupports/*<nsIRDFResource>*/* aSources,
815 : nsIRDFResource* aCommand,
816 : nsISupports/*<nsIRDFResource>*/* aArguments)
817 : {
818 0 : return(NS_ERROR_NOT_IMPLEMENTED);
819 : }
820 :
821 :
822 :
823 : NS_IMETHODIMP
824 0 : FileSystemDataSource::BeginUpdateBatch()
825 : {
826 0 : return NS_OK;
827 : }
828 :
829 :
830 :
831 : NS_IMETHODIMP
832 0 : FileSystemDataSource::EndUpdateBatch()
833 : {
834 0 : return NS_OK;
835 : }
836 :
837 :
838 :
839 : nsresult
840 0 : FileSystemDataSource::GetVolumeList(nsISimpleEnumerator** aResult)
841 : {
842 0 : nsCOMArray<nsIRDFResource> volumes;
843 0 : nsCOMPtr<nsIRDFResource> vol;
844 :
845 : #ifdef XP_WIN
846 :
847 : int32_t driveType;
848 : wchar_t drive[32];
849 : int32_t volNum;
850 :
851 : for (volNum = 0; volNum < 26; volNum++)
852 : {
853 : swprintf_s(drive, 32, L"%c:\\", volNum + (char16_t)'A');
854 :
855 : driveType = GetDriveTypeW(drive);
856 : if (driveType != DRIVE_UNKNOWN && driveType != DRIVE_NO_ROOT_DIR)
857 : {
858 : nsAutoCString url;
859 : url.AppendPrintf("file:///%c|/", volNum + 'A');
860 : nsresult rv = mRDFService->GetResource(url, getter_AddRefs(vol));
861 : if (NS_FAILED(rv))
862 : return rv;
863 :
864 : volumes.AppendObject(vol);
865 : }
866 : }
867 : #endif
868 :
869 : #ifdef XP_UNIX
870 0 : mRDFService->GetResource(NS_LITERAL_CSTRING("file:///"), getter_AddRefs(vol));
871 0 : volumes.AppendObject(vol);
872 : #endif
873 :
874 0 : return NS_NewArrayEnumerator(aResult, volumes);
875 : }
876 :
877 :
878 :
879 : #ifdef XP_WIN
880 : bool
881 : FileSystemDataSource::isValidFolder(nsIRDFResource *source)
882 : {
883 : bool isValid = true;
884 : if (ieFavoritesDir.IsEmpty()) return(isValid);
885 :
886 : nsresult rv;
887 : nsCString uri;
888 : rv = source->GetValueUTF8(uri);
889 : if (NS_FAILED(rv)) return(isValid);
890 :
891 : NS_ConvertUTF8toUTF16 theURI(uri);
892 : if (theURI.Find(ieFavoritesDir) == 0)
893 : {
894 : isValid = false;
895 :
896 : nsCOMPtr<nsISimpleEnumerator> folderEnum;
897 : if (NS_SUCCEEDED(rv = GetFolderList(source, true, false, getter_AddRefs(folderEnum))))
898 : {
899 : bool hasAny = false, hasMore;
900 : while (NS_SUCCEEDED(folderEnum->HasMoreElements(&hasMore)) &&
901 : hasMore)
902 : {
903 : hasAny = true;
904 :
905 : nsCOMPtr<nsISupports> isupports;
906 : if (NS_FAILED(rv = folderEnum->GetNext(getter_AddRefs(isupports))))
907 : break;
908 : nsCOMPtr<nsIRDFResource> res = do_QueryInterface(isupports);
909 : if (!res) break;
910 :
911 : nsCOMPtr<nsIRDFLiteral> nameLiteral;
912 : if (NS_FAILED(rv = GetName(res, getter_AddRefs(nameLiteral))))
913 : break;
914 :
915 : const char16_t *uniName;
916 : if (NS_FAILED(rv = nameLiteral->GetValueConst(&uniName)))
917 : break;
918 : nsAutoString name(uniName);
919 :
920 : // An empty folder, or a folder that contains just "desktop.ini",
921 : // is considered to be a IE Favorite; otherwise, its a folder
922 : if (!name.LowerCaseEqualsLiteral("desktop.ini"))
923 : {
924 : isValid = true;
925 : break;
926 : }
927 : }
928 : if (!hasAny) isValid = true;
929 : }
930 : }
931 : return(isValid);
932 : }
933 : #endif
934 :
935 :
936 :
937 : nsresult
938 0 : FileSystemDataSource::GetFolderList(nsIRDFResource *source, bool allowHidden,
939 : bool onlyFirst, nsISimpleEnumerator** aResult)
940 : {
941 0 : if (!isDirURI(source))
942 0 : return(NS_RDF_NO_VALUE);
943 :
944 : nsresult rv;
945 :
946 0 : const char *parentURI = nullptr;
947 0 : rv = source->GetValueConst(&parentURI);
948 0 : if (NS_FAILED(rv))
949 0 : return(rv);
950 0 : if (!parentURI)
951 0 : return(NS_ERROR_UNEXPECTED);
952 :
953 0 : nsCOMPtr<nsIURI> aIURI;
954 0 : if (NS_FAILED(rv = NS_NewURI(getter_AddRefs(aIURI), nsDependentCString(parentURI))))
955 0 : return(rv);
956 :
957 0 : nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(aIURI);
958 0 : if (!fileURL)
959 0 : return NS_OK;
960 :
961 0 : nsCOMPtr<nsIFile> aDir;
962 0 : if (NS_FAILED(rv = fileURL->GetFile(getter_AddRefs(aDir))))
963 0 : return(rv);
964 :
965 : // ensure that we DO NOT resolve aliases
966 0 : aDir->SetFollowLinks(false);
967 :
968 0 : nsCOMPtr<nsISimpleEnumerator> dirContents;
969 0 : if (NS_FAILED(rv = aDir->GetDirectoryEntries(getter_AddRefs(dirContents))))
970 0 : return(rv);
971 0 : if (!dirContents)
972 0 : return(NS_ERROR_UNEXPECTED);
973 :
974 0 : nsCOMArray<nsIRDFResource> resources;
975 : bool hasMore;
976 0 : while(NS_SUCCEEDED(rv = dirContents->HasMoreElements(&hasMore)) &&
977 : hasMore)
978 : {
979 0 : nsCOMPtr<nsISupports> isupports;
980 0 : if (NS_FAILED(rv = dirContents->GetNext(getter_AddRefs(isupports))))
981 0 : break;
982 :
983 0 : nsCOMPtr<nsIFile> aFile = do_QueryInterface(isupports);
984 0 : if (!aFile)
985 0 : break;
986 :
987 0 : if (!allowHidden)
988 : {
989 0 : bool hiddenFlag = false;
990 0 : if (NS_FAILED(rv = aFile->IsHidden(&hiddenFlag)))
991 0 : break;
992 0 : if (hiddenFlag)
993 0 : continue;
994 : }
995 :
996 0 : nsAutoString leafStr;
997 0 : if (NS_FAILED(rv = aFile->GetLeafName(leafStr)))
998 0 : break;
999 0 : if (leafStr.IsEmpty())
1000 0 : continue;
1001 :
1002 0 : nsAutoCString fullURI;
1003 0 : fullURI.Assign(parentURI);
1004 0 : if (fullURI.Last() != '/')
1005 : {
1006 0 : fullURI.Append('/');
1007 : }
1008 :
1009 0 : nsAutoCString leaf;
1010 0 : bool escaped = NS_Escape(NS_ConvertUTF16toUTF8(leafStr), leaf, url_Path);
1011 0 : leafStr.Truncate();
1012 :
1013 0 : if (!escaped) {
1014 0 : continue;
1015 : }
1016 :
1017 : // using nsEscape() [above] doesn't escape slashes, so do that by hand
1018 : int32_t aOffset;
1019 0 : while ((aOffset = leaf.FindChar('/')) >= 0)
1020 : {
1021 0 : leaf.Cut((uint32_t)aOffset, 1);
1022 0 : leaf.Insert("%2F", (uint32_t)aOffset);
1023 : }
1024 :
1025 : // append the encoded name
1026 0 : fullURI.Append(leaf);
1027 :
1028 0 : bool dirFlag = false;
1029 0 : rv = aFile->IsDirectory(&dirFlag);
1030 0 : if (NS_SUCCEEDED(rv) && dirFlag)
1031 : {
1032 0 : fullURI.Append('/');
1033 : }
1034 :
1035 0 : nsCOMPtr<nsIRDFResource> fileRes;
1036 0 : mRDFService->GetResource(fullURI, getter_AddRefs(fileRes));
1037 :
1038 0 : resources.AppendObject(fileRes);
1039 :
1040 0 : if (onlyFirst)
1041 0 : break;
1042 : }
1043 :
1044 0 : return NS_NewArrayEnumerator(aResult, resources);
1045 : }
1046 :
1047 : nsresult
1048 0 : FileSystemDataSource::GetLastMod(nsIRDFResource *source, nsIRDFDate **aResult)
1049 : {
1050 0 : *aResult = nullptr;
1051 :
1052 : nsresult rv;
1053 0 : const char *uri = nullptr;
1054 :
1055 0 : rv = source->GetValueConst(&uri);
1056 0 : if (NS_FAILED(rv)) return(rv);
1057 0 : if (!uri)
1058 0 : return(NS_ERROR_UNEXPECTED);
1059 :
1060 0 : nsCOMPtr<nsIURI> aIURI;
1061 0 : if (NS_FAILED(rv = NS_NewURI(getter_AddRefs(aIURI), nsDependentCString(uri))))
1062 0 : return(rv);
1063 :
1064 0 : nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(aIURI);
1065 0 : if (!fileURL)
1066 0 : return NS_OK;
1067 :
1068 0 : nsCOMPtr<nsIFile> aFile;
1069 0 : if (NS_FAILED(rv = fileURL->GetFile(getter_AddRefs(aFile))))
1070 0 : return(rv);
1071 0 : if (!aFile)
1072 0 : return(NS_ERROR_UNEXPECTED);
1073 :
1074 : // ensure that we DO NOT resolve aliases
1075 0 : aFile->SetFollowLinks(false);
1076 :
1077 : PRTime lastModDate;
1078 0 : if (NS_FAILED(rv = aFile->GetLastModifiedTime(&lastModDate)))
1079 0 : return(rv);
1080 :
1081 : // convert from milliseconds to seconds
1082 0 : mRDFService->GetDateLiteral(lastModDate * PR_MSEC_PER_SEC, aResult);
1083 :
1084 0 : return(NS_OK);
1085 : }
1086 :
1087 :
1088 :
1089 : nsresult
1090 0 : FileSystemDataSource::GetFileSize(nsIRDFResource *source, nsIRDFInt **aResult)
1091 : {
1092 0 : *aResult = nullptr;
1093 :
1094 : nsresult rv;
1095 0 : const char *uri = nullptr;
1096 :
1097 0 : rv = source->GetValueConst(&uri);
1098 0 : if (NS_FAILED(rv))
1099 0 : return(rv);
1100 0 : if (!uri)
1101 0 : return(NS_ERROR_UNEXPECTED);
1102 :
1103 0 : nsCOMPtr<nsIURI> aIURI;
1104 0 : if (NS_FAILED(rv = NS_NewURI(getter_AddRefs(aIURI), nsDependentCString(uri))))
1105 0 : return(rv);
1106 :
1107 0 : nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(aIURI);
1108 0 : if (!fileURL)
1109 0 : return NS_OK;
1110 :
1111 0 : nsCOMPtr<nsIFile> aFile;
1112 0 : if (NS_FAILED(rv = fileURL->GetFile(getter_AddRefs(aFile))))
1113 0 : return(rv);
1114 0 : if (!aFile)
1115 0 : return(NS_ERROR_UNEXPECTED);
1116 :
1117 : // ensure that we DO NOT resolve aliases
1118 0 : aFile->SetFollowLinks(false);
1119 :
1120 : // don't do anything with directories
1121 0 : bool isDir = false;
1122 0 : if (NS_FAILED(rv = aFile->IsDirectory(&isDir)))
1123 0 : return(rv);
1124 0 : if (isDir)
1125 0 : return(NS_RDF_NO_VALUE);
1126 :
1127 : int64_t aFileSize64;
1128 0 : if (NS_FAILED(rv = aFile->GetFileSize(&aFileSize64)))
1129 0 : return(rv);
1130 :
1131 : // convert 64bits to 32bits
1132 0 : int32_t aFileSize32 = int32_t(aFileSize64);
1133 0 : mRDFService->GetIntLiteral(aFileSize32, aResult);
1134 :
1135 0 : return(NS_OK);
1136 : }
1137 :
1138 :
1139 :
1140 : nsresult
1141 0 : FileSystemDataSource::GetName(nsIRDFResource *source, nsIRDFLiteral **aResult)
1142 : {
1143 : nsresult rv;
1144 0 : const char *uri = nullptr;
1145 :
1146 0 : rv = source->GetValueConst(&uri);
1147 0 : if (NS_FAILED(rv))
1148 0 : return(rv);
1149 0 : if (!uri)
1150 0 : return(NS_ERROR_UNEXPECTED);
1151 :
1152 0 : nsCOMPtr<nsIURI> aIURI;
1153 0 : if (NS_FAILED(rv = NS_NewURI(getter_AddRefs(aIURI), nsDependentCString(uri))))
1154 0 : return(rv);
1155 :
1156 0 : nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(aIURI);
1157 0 : if (!fileURL)
1158 0 : return NS_OK;
1159 :
1160 0 : nsCOMPtr<nsIFile> aFile;
1161 0 : if (NS_FAILED(rv = fileURL->GetFile(getter_AddRefs(aFile))))
1162 0 : return(rv);
1163 0 : if (!aFile)
1164 0 : return(NS_ERROR_UNEXPECTED);
1165 :
1166 : // ensure that we DO NOT resolve aliases
1167 0 : aFile->SetFollowLinks(false);
1168 :
1169 0 : nsAutoString name;
1170 0 : if (NS_FAILED(rv = aFile->GetLeafName(name)))
1171 0 : return(rv);
1172 0 : if (name.IsEmpty())
1173 0 : return(NS_ERROR_UNEXPECTED);
1174 :
1175 : #ifdef XP_WIN
1176 : // special hack for IE favorites under Windows; strip off the
1177 : // trailing ".url" or ".lnk" at the end of IE favorites names
1178 : int32_t nameLen = name.Length();
1179 : if ((strncmp(uri, ieFavoritesDir.get(), ieFavoritesDir.Length()) == 0) && (nameLen > 4))
1180 : {
1181 : nsAutoString extension;
1182 : name.Right(extension, 4);
1183 : if (extension.LowerCaseEqualsLiteral(".url") ||
1184 : extension.LowerCaseEqualsLiteral(".lnk"))
1185 : {
1186 : name.Truncate(nameLen - 4);
1187 : }
1188 : }
1189 : #endif
1190 :
1191 0 : mRDFService->GetLiteral(name.get(), aResult);
1192 :
1193 0 : return NS_OK;
1194 : }
1195 :
1196 :
1197 :
1198 : #ifdef USE_NC_EXTENSION
1199 : nsresult
1200 0 : FileSystemDataSource::GetExtension(nsIRDFResource *source, nsIRDFLiteral **aResult)
1201 : {
1202 0 : nsCOMPtr<nsIRDFLiteral> name;
1203 0 : nsresult rv = GetName(source, getter_AddRefs(name));
1204 0 : if (NS_FAILED(rv))
1205 0 : return rv;
1206 :
1207 : const char16_t* unicodeLeafName;
1208 0 : rv = name->GetValueConst(&unicodeLeafName);
1209 0 : if (NS_FAILED(rv))
1210 0 : return rv;
1211 :
1212 0 : nsAutoString filename(unicodeLeafName);
1213 0 : int32_t lastDot = filename.RFindChar('.');
1214 0 : if (lastDot == -1)
1215 : {
1216 0 : mRDFService->GetLiteral(EmptyString().get(), aResult);
1217 : }
1218 : else
1219 : {
1220 0 : nsAutoString extension;
1221 0 : filename.Right(extension, (filename.Length() - lastDot));
1222 0 : mRDFService->GetLiteral(extension.get(), aResult);
1223 : }
1224 :
1225 0 : return NS_OK;
1226 : }
1227 : #endif
1228 :
1229 : #ifdef XP_WIN
1230 : nsresult
1231 : FileSystemDataSource::getIEFavoriteURL(nsIRDFResource *source, nsString aFileURL, nsIRDFLiteral **urlLiteral)
1232 : {
1233 : nsresult rv = NS_OK;
1234 :
1235 : *urlLiteral = nullptr;
1236 :
1237 : nsCOMPtr<nsIFile> f;
1238 : NS_GetFileFromURLSpec(NS_ConvertUTF16toUTF8(aFileURL), getter_AddRefs(f));
1239 :
1240 : bool value;
1241 :
1242 : if (NS_SUCCEEDED(f->IsDirectory(&value)) && value)
1243 : {
1244 : if (isValidFolder(source))
1245 : return(NS_RDF_NO_VALUE);
1246 : aFileURL.AppendLiteral("desktop.ini");
1247 : }
1248 : else if (aFileURL.Length() > 4)
1249 : {
1250 : nsAutoString extension;
1251 :
1252 : aFileURL.Right(extension, 4);
1253 : if (!extension.LowerCaseEqualsLiteral(".url"))
1254 : {
1255 : return(NS_RDF_NO_VALUE);
1256 : }
1257 : }
1258 :
1259 : nsCOMPtr<nsIInputStream> strm;
1260 : NS_NewLocalFileInputStream(getter_AddRefs(strm),f);
1261 : nsCOMPtr<nsILineInputStream> linereader = do_QueryInterface(strm, &rv);
1262 :
1263 : nsAutoString line;
1264 : nsAutoCString cLine;
1265 : while(NS_SUCCEEDED(rv))
1266 : {
1267 : bool isEOF;
1268 : rv = linereader->ReadLine(cLine, &isEOF);
1269 : CopyASCIItoUTF16(cLine, line);
1270 :
1271 : if (isEOF)
1272 : {
1273 : if (line.Find("URL=", true) == 0)
1274 : {
1275 : line.Cut(0, 4);
1276 : rv = mRDFService->GetLiteral(line.get(), urlLiteral);
1277 : break;
1278 : }
1279 : else if (line.Find("CDFURL=", true) == 0)
1280 : {
1281 : line.Cut(0, 7);
1282 : rv = mRDFService->GetLiteral(line.get(), urlLiteral);
1283 : break;
1284 : }
1285 : line.Truncate();
1286 : }
1287 : }
1288 :
1289 : return(rv);
1290 : }
1291 : #endif
1292 :
1293 :
1294 :
1295 : nsresult
1296 0 : FileSystemDataSource::GetURL(nsIRDFResource *source, bool *isFavorite, nsIRDFLiteral** aResult)
1297 : {
1298 0 : if (isFavorite) *isFavorite = false;
1299 :
1300 : nsresult rv;
1301 0 : nsCString uri;
1302 :
1303 0 : rv = source->GetValueUTF8(uri);
1304 0 : if (NS_FAILED(rv))
1305 0 : return(rv);
1306 :
1307 0 : NS_ConvertUTF8toUTF16 url(uri);
1308 :
1309 : #ifdef XP_WIN
1310 : // under Windows, if its an IE favorite, munge the URL
1311 : if (!ieFavoritesDir.IsEmpty())
1312 : {
1313 : if (url.Find(ieFavoritesDir) == 0)
1314 : {
1315 : if (isFavorite) *isFavorite = true;
1316 : rv = getIEFavoriteURL(source, url, aResult);
1317 : return(rv);
1318 : }
1319 : }
1320 : #endif
1321 :
1322 : // if we fall through to here, its not any type of bookmark
1323 : // stored in the platform native file system, so just set the URL
1324 :
1325 0 : mRDFService->GetLiteral(url.get(), aResult);
1326 :
1327 0 : return(NS_OK);
1328 : }
|