1 | //======================================================================== |
2 | // |
3 | // CurlPDFDocBuilder.cc |
4 | // |
5 | // This file is licensed under the GPLv2 or later |
6 | // |
7 | // Copyright 2010 Hib Eris <hib@hiberis.nl> |
8 | // Copyright 2010, 2017, 2022 Albert Astals Cid <aacid@kde.org> |
9 | // Copyright 2021 Oliver Sander <oliver.sander@tu-dresden.de> |
10 | // |
11 | //======================================================================== |
12 | |
13 | #include <config.h> |
14 | |
15 | #include "CurlPDFDocBuilder.h" |
16 | |
17 | #include "CachedFile.h" |
18 | #include "CurlCachedFile.h" |
19 | #include "ErrorCodes.h" |
20 | |
21 | //------------------------------------------------------------------------ |
22 | // CurlPDFDocBuilder |
23 | //------------------------------------------------------------------------ |
24 | |
25 | std::unique_ptr<PDFDoc> CurlPDFDocBuilder::buildPDFDoc(const GooString &uri, const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword, void *guiDataA) |
26 | { |
27 | CachedFile *cachedFile = new CachedFile(new CurlCachedFileLoader(uri.toStr())); |
28 | |
29 | if (cachedFile->getLength() == ((unsigned int)-1)) { |
30 | cachedFile->decRefCnt(); |
31 | return PDFDoc::ErrorPDFDoc(errOpenFile, fileNameA: std::unique_ptr<GooString>(uri.copy())); |
32 | } |
33 | |
34 | BaseStream *str = new CachedFileStream(cachedFile, 0, false, cachedFile->getLength(), Object(objNull)); |
35 | |
36 | return std::make_unique<PDFDoc>(args&: str, args: ownerPassword, args: userPassword, args&: guiDataA); |
37 | } |
38 | |
39 | bool CurlPDFDocBuilder::supports(const GooString &uri) |
40 | { |
41 | if (uri.cmpN(sA: "http://" , n: 7) == 0 || uri.cmpN(sA: "https://" , n: 8) == 0) { |
42 | return true; |
43 | } else { |
44 | return false; |
45 | } |
46 | } |
47 | |