summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHib Eris <hib@hiberis.nl>2010-02-23 02:29:26 +0100
committerAlbert Astals Cid <aacid@kde.org>2010-04-05 15:56:04 +0100
commit08a3435e67ebf21beac2fefcbd21ad65f9293fd1 (patch)
treeeb443fa04ffecdfb01575099614d8f412c8b4aad
parenta87abf6ad9fb66d35a70c9412adc5d8ba2889b96 (diff)
Add HTTP support using libcurl
With libcurl, poppler can handle documents over http.
-rw-r--r--CMakeLists.txt18
-rw-r--r--config.h.cmake6
-rw-r--r--configure.ac16
-rw-r--r--poppler/CurlCachedFile.cc95
-rw-r--r--poppler/CurlCachedFile.h39
-rw-r--r--poppler/Makefile.am20
-rw-r--r--poppler/poppler-config.h.cmake5
-rw-r--r--poppler/poppler-config.h.in5
-rw-r--r--utils/pdfinfo.cc16
9 files changed, 219 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7922dadf..70b0e06d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -29,6 +29,7 @@ option(ENABLE_CPP "Compile poppler cpp wrapper." ON)
option(ENABLE_ABIWORD "Build the Abiword backend." ON)
option(ENABLE_LIBOPENJPEG "Use libopenjpeg for JPX streams." ON)
option(ENABLE_LCMS "Use liblcms for color management." ON)
+option(ENABLE_LIBCURL "Build libcurl based HTTP support." OFF)
option(ENABLE_ZLIB "Build with zlib (not totally safe)." OFF)
option(USE_EXCEPTIONS "Throw exceptions to deal with not enough memory and similar problems." OFF)
option(USE_FIXEDPOINT "Use fixed point arithmetic in the Splash backend" OFF)
@@ -132,6 +133,11 @@ if(ENABLE_LCMS)
find_package(LCMS)
set(USE_CMS ${LCMS_FOUND})
endif(ENABLE_LCMS)
+if(ENABLE_LIBCURL)
+ find_package(CURL)
+ include_directories(${CURL_INCLUDE_DIR})
+ set(POPPLER_HAS_CURL_SUPPORT ON)
+endif(ENABLE_LIBCURL)
add_definitions(-DHAVE_CONFIG_H=1)
if(FONTCONFIG_FOUND)
@@ -311,6 +317,12 @@ if(ENABLE_ZLIB)
)
set(poppler_LIBS ${poppler_LIBS} ${ZLIB_LIBRARIES})
endif(ENABLE_ZLIB)
+if(ENABLE_LIBCURL)
+ set(poppler_SRCS ${poppler_SRCS}
+ poppler/CurlCachedFile.cc
+ )
+ set(poppler_LIBS ${poppler_LIBS} ${CURL_LIBRARIES})
+endif(ENABLE_LIBCURL)
if(LIBOPENJPEG_FOUND)
set(poppler_SRCS ${poppler_SRCS}
poppler/JPEG2000Stream.cc
@@ -442,6 +454,11 @@ if(ENABLE_XPDF_HEADERS)
fofi/FoFiType1.h
fofi/FoFiType1C.h
DESTINATION include/poppler/fofi)
+ if(ENABLE_LIBCURL)
+ install(FILES
+ poppler/CurlCachedFile.h
+ DESTINATION include/poppler)
+ endif(ENABLE_LIBCURL)
if(LIBOPENJPEG_FOUND)
install(FILES
poppler/JPEG2000Stream.h
@@ -552,6 +569,7 @@ show_end_message("use gtk-doc" "not supported with this CMake build system")
show_end_message_yesno("use libjpeg" ENABLE_LIBJPEG)
show_end_message_yesno("use libpng" ENABLE_LIBPNG)
show_end_message_yesno("use zlib" ENABLE_ZLIB)
+show_end_message_yesno("use curl" ENABLE_LIBCURL)
show_end_message_yesno("use libopenjpeg" LIBOPENJPEG_FOUND)
show_end_message_yesno("use cms" USE_CMS)
show_end_message_yesno("command line utils" ENABLE_UTILS)
diff --git a/config.h.cmake b/config.h.cmake
index 70d8d5d2..0879aeb5 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -1,5 +1,8 @@
/* config.h. Generated from config.h.cmake by cmake. */
+/* Build against libcurl. */
+#cmakedefine ENABLE_LIBCURL 1
+
/* Use libjpeg instead of builtin jpeg decoder. */
#cmakedefine ENABLE_LIBJPEG 1
@@ -153,6 +156,9 @@
/* Poppler data dir */
#define POPPLER_DATADIR "${CMAKE_INSTALL_PREFIX}/share/poppler"
+/* Support for curl based doc builder is compiled in. */
+#cmakedefine POPPLER_HAS_CURL_SUPPORT 1
+
/* Have GDK */
#cmakedefine POPPLER_WITH_GDK 1
diff --git a/configure.ac b/configure.ac
index 68509eee..72041d51 100644
--- a/configure.ac
+++ b/configure.ac
@@ -210,6 +210,21 @@ AM_CONDITIONAL(BUILD_ZLIB, test x$enable_zlib = xyes)
AH_TEMPLATE([ENABLE_ZLIB],
[Use zlib instead of builtin zlib decoder.])
+dnl Test for libcurl
+AC_ARG_ENABLE(libcurl,
+ AC_HELP_STRING([--enable-libcurl],
+ [Build with libcurl based HTTP support.]),
+ enable_libcurl=$enableval,
+ enable_libcurl="no")
+
+if test x$enable_libcurl = xyes; then
+ PKG_CHECK_MODULES(LIBCURL, libcurl)
+ AC_DEFINE(ENABLE_LIBCURL, 1, [Build against libcurl.])
+ AC_DEFINE(POPPLER_HAS_CURL_SUPPORT, 1,
+ [Support for curl based doc builder is compiled in.])
+fi
+
+AM_CONDITIONAL(BUILD_LIBCURL, test x$enable_libcurl = xyes)
dnl Test for libjpeg
AC_ARG_ENABLE(libjpeg,
@@ -651,6 +666,7 @@ echo " use gtk-doc: $enable_gtk_doc"
echo " use libjpeg: $enable_libjpeg"
echo " use libpng: $enable_libpng"
echo " use zlib: $enable_zlib"
+echo " use libcurl: $enable_libcurl"
echo " use libopenjpeg: $enable_libopenjpeg"
echo " use cms: $enable_cms"
echo " command line utils: $enable_utils"
diff --git a/poppler/CurlCachedFile.cc b/poppler/CurlCachedFile.cc
new file mode 100644
index 00000000..b326fb7d
--- /dev/null
+++ b/poppler/CurlCachedFile.cc
@@ -0,0 +1,95 @@
+//========================================================================
+//
+// CurlCachedFile.cc
+//
+// This file is licensed under the GPLv2 or later
+//
+// Copyright 2009 Stefan Thomas <thomas@eload24.com>
+// Copyright 2010 Hib Eris <hib@hiberis.nl>
+//
+//========================================================================
+
+#include <config.h>
+
+#include "CurlCachedFile.h"
+
+#include "goo/GooString.h"
+#include "goo/GooVector.h"
+
+//------------------------------------------------------------------------
+
+CurlCachedFileLoader::CurlCachedFileLoader()
+{
+ url = NULL;
+ cachedFile = NULL;
+ curl = NULL;
+}
+
+CurlCachedFileLoader::~CurlCachedFileLoader() {
+ curl_easy_cleanup(curl);
+}
+
+static size_t
+noop_cb(char *ptr, size_t size, size_t nmemb, void *ptr2)
+{
+ return size*nmemb;
+}
+
+size_t
+CurlCachedFileLoader::init(GooString *urlA, CachedFile *cachedFileA)
+{
+ long code = NULL;
+ double contentLength = -1;
+ size_t size;
+
+ url = urlA;
+ cachedFile = cachedFileA;
+ curl = curl_easy_init();
+
+ curl_easy_setopt(curl, CURLOPT_URL, url->getCString());
+ curl_easy_setopt(curl, CURLOPT_HEADER, 1);
+ curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &noop_cb);
+ curl_easy_perform(curl);
+ curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
+ curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &contentLength);
+ curl_easy_reset(curl);
+
+ size = contentLength;
+
+ return size;
+}
+
+static
+size_t load_cb(const char *ptr, size_t size, size_t nmemb, void *data)
+{
+ CachedFileWriter *writer = (CachedFileWriter *) data;
+ return (writer->write) (ptr, size*nmemb);
+}
+
+int CurlCachedFileLoader::load(GooVector<ByteRange> *ranges, CachedFileWriter *writer)
+{
+ CURLcode r = CURLE_OK;
+ size_t fromByte, toByte;
+ for (size_t i = 0; i < (*ranges).size(); i++) {
+
+ fromByte = (*ranges)[i].offset;
+ toByte = fromByte + (*ranges)[i].length - 1;
+ GooString *range = GooString::format("{0:ud}-{1:ud}", fromByte, toByte);
+
+ curl_easy_setopt(curl, CURLOPT_URL, url->getCString());
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, load_cb);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, writer);
+ curl_easy_setopt(curl, CURLOPT_RANGE, range->getCString());
+ r = curl_easy_perform(curl);
+ curl_easy_reset(curl);
+
+ delete range;
+
+ if (r != CURLE_OK) break;
+ }
+ return r;
+}
+
+//------------------------------------------------------------------------
+
diff --git a/poppler/CurlCachedFile.h b/poppler/CurlCachedFile.h
new file mode 100644
index 00000000..b18b7f86
--- /dev/null
+++ b/poppler/CurlCachedFile.h
@@ -0,0 +1,39 @@
+//========================================================================
+//
+// CurlCachedFile.h
+//
+// This file is licensed under the GPLv2 or later
+//
+// Copyright 2010 Hib Eris <hib@hiberis.nl>
+//
+//========================================================================
+
+#ifndef CURLCACHELOADER_H
+#define CURLCACHELOADER_H
+
+#include "poppler-config.h"
+#include "CachedFile.h"
+
+#include <curl/curl.h>
+
+//------------------------------------------------------------------------
+
+class CurlCachedFileLoader : public CachedFileLoader {
+
+public:
+
+ CurlCachedFileLoader();
+ ~CurlCachedFileLoader();
+ size_t init(GooString *url, CachedFile* cachedFile);
+ int load(GooVector<ByteRange> *ranges, CachedFileWriter *writer);
+
+private:
+
+ GooString *url;
+ CachedFile *cachedFile;
+ CURL *curl;
+
+};
+
+#endif
+
diff --git a/poppler/Makefile.am b/poppler/Makefile.am
index a6bb9e97..5cd68a41 100644
--- a/poppler/Makefile.am
+++ b/poppler/Makefile.am
@@ -102,6 +102,22 @@ zlib_libs = \
endif
+if BUILD_LIBCURL
+
+libcurl_libs = \
+ $(LIBCURL_LIBS)
+
+libcurl_includes = \
+ $(LIBCURL_CFLAGS)
+
+curl_headers = \
+ CurlCachedFile.h
+
+curl_sources = \
+ CurlCachedFile.cc
+
+endif
+
if BUILD_ABIWORD_OUTPUT
abiword_sources = \
@@ -130,6 +146,7 @@ INCLUDES = \
$(arthur_includes) \
$(abiword_includes) \
$(libpng_includes) \
+ $(libcurl_includes) \
$(FREETYPE_CFLAGS) \
$(FONTCONFIG_CFLAGS)
@@ -149,6 +166,7 @@ libpoppler_la_LIBADD = \
$(libjpeg_libs) \
$(libpng_libs) \
$(zlib_libs) \
+ $(libcurl_libs) \
$(libjpeg2000_libs) \
$(abiword_libs) \
$(FREETYPE_LIBS) \
@@ -163,6 +181,7 @@ if ENABLE_XPDF_HEADERS
poppler_includedir = $(includedir)/poppler
poppler_include_HEADERS = \
$(splash_headers) \
+ $(curl_headers) \
Annot.h \
Array.h \
BuiltinFont.h \
@@ -237,6 +256,7 @@ libpoppler_la_SOURCES = \
$(zlib_sources) \
$(libjpeg2000_sources) \
$(abiword_sources) \
+ $(curl_sources) \
Annot.cc \
Array.cc \
BuiltinFont.cc \
diff --git a/poppler/poppler-config.h.cmake b/poppler/poppler-config.h.cmake
index 7656e4f0..95e95ccd 100644
--- a/poppler/poppler-config.h.cmake
+++ b/poppler/poppler-config.h.cmake
@@ -49,6 +49,11 @@
#cmakedefine WITH_FONTCONFIGURATION_WIN32 1
#endif
+/* Support for curl is compiled in. */
+#ifndef POPPLER_HAS_CURL_SUPPORT
+#cmakedefine POPPLER_HAS_CURL_SUPPORT 1
+#endif
+
// Also, there's a couple of preprocessor symbols in the header files
// that are used but never defined: DISABLE_OUTLINE, DEBUG_MEM and
diff --git a/poppler/poppler-config.h.in b/poppler/poppler-config.h.in
index f8db4ba4..7b0644c6 100644
--- a/poppler/poppler-config.h.in
+++ b/poppler/poppler-config.h.in
@@ -49,6 +49,11 @@
#undef WITH_FONTCONFIGURATION_WIN32
#endif
+/* Support for curl is compiled in. */
+#ifndef POPPLER_HAS_CURL_SUPPORT
+#undef POPPLER_HAS_CURL_SUPPORT
+#endif
+
// Also, there's a couple of preprocessor symbols in the header files
// that are used but never defined: DISABLE_OUTLINE, DEBUG_MEM and
diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc
index ceddd47d..48504d2c 100644
--- a/utils/pdfinfo.cc
+++ b/utils/pdfinfo.cc
@@ -49,6 +49,9 @@
#include "Error.h"
#include "DateInfo.h"
#include "StdinCachedFile.h"
+#if ENABLE_LIBCURL
+#include "CurlCachedFile.h"
+#endif
static void printInfoString(Dict *infoDict, char *key, char *text,
UnicodeMap *uMap);
@@ -160,7 +163,18 @@ int main(int argc, char *argv[]) {
userPW = NULL;
}
- if(fileName->cmp("-") != 0) {
+#if ENABLE_LIBCURL
+ if (fileName->cmpN("http://", 7) == 0 ||
+ fileName->cmpN("https://", 8) == 0) {
+ Object obj;
+
+ obj.initNull();
+ CachedFile *cachedFile = new CachedFile(new CurlCachedFileLoader(), fileName);
+ doc = new PDFDoc(new CachedFileStream(cachedFile, 0, gFalse, 0, &obj),
+ ownerPW, userPW);
+ } else
+#endif
+ if (fileName->cmp("-") != 0) {
doc = new PDFDoc(fileName, ownerPW, userPW);
} else {
Object obj;