summaryrefslogtreecommitdiffstats
path: root/src/raptor_www_libfetch.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:40:05 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:40:05 +0000
commit4038ab95a094b363f1748f3dcb51511a1217475d (patch)
tree7f393d66a783f91ddd263c78d681e485cf4f45ca /src/raptor_www_libfetch.c
parentInitial commit. (diff)
downloadraptor2-4038ab95a094b363f1748f3dcb51511a1217475d.tar.xz
raptor2-4038ab95a094b363f1748f3dcb51511a1217475d.zip
Adding upstream version 2.0.16.upstream/2.0.16upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/raptor_www_libfetch.c')
-rw-r--r--src/raptor_www_libfetch.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/raptor_www_libfetch.c b/src/raptor_www_libfetch.c
new file mode 100644
index 0000000..55f85a5
--- /dev/null
+++ b/src/raptor_www_libfetch.c
@@ -0,0 +1,97 @@
+/* -*- Mode: c; c-basic-offset: 2 -*-
+ *
+ * raptor_www_libfetch.c - Raptor WWW retrieval via libfetch
+ *
+ * Copyright (C) 2003-2006, David Beckett http://www.dajobe.org/
+ * Copyright (C) 2003-2004, University of Bristol, UK http://www.bristol.ac.uk/
+ *
+ * This package is Free Software and part of Redland http://librdf.org/
+ *
+ * It is licensed under the following three licenses as alternatives:
+ * 1. GNU Lesser General Public License (LGPL) V2.1 or any newer version
+ * 2. GNU General Public License (GPL) V2 or any newer version
+ * 3. Apache License, V2.0 or any newer version
+ *
+ * You may not use this file except in compliance with at least one of
+ * the above three licenses.
+ *
+ * See LICENSE.html or LICENSE.txt at the top of this package for the
+ * complete terms and further detail along with the license texts for
+ * the licenses in COPYING.LIB, COPYING and LICENSE-2.0.txt respectively.
+ *
+ *
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <raptor_config.h>
+#endif
+
+#ifdef RAPTOR_WWW_LIBFETCH
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <errno.h>
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+#include <fetch.h>
+
+/* Raptor includes */
+#include "raptor2.h"
+#include "raptor_internal.h"
+
+void
+raptor_www_libfetch_init(raptor_www *www)
+{
+}
+
+
+void
+raptor_www_libfetch_free(raptor_www *www)
+{
+}
+
+
+int
+raptor_www_libfetch_fetch(raptor_www *www)
+{
+ FILE *stream;
+
+ if(www->proxy) {
+ setenv("HTTP_PROXY", www->proxy, 0);
+ setenv("FTP_PROXY", www->proxy, 0);
+ }
+
+ if(www->user_agent)
+ setenv("HTTP_USER_AGENT", www->user_agent, 0);
+
+ stream = fetchXGetURL((const char*)raptor_uri_as_string(www->uri), NULL, NULL);
+ if(!stream) {
+ www->failed = 1;
+ raptor_www_error(www, "%s", fetchLastErrString);
+ return 1;
+ }
+
+ /* fetch does not give us access to this */
+ www->status_code = 200;
+
+ while(!feof(stream)) {
+ size_t len = fread(www->buffer, 1, RAPTOR_WWW_BUFFER_SIZE, stream);
+
+ www->total_bytes += len;
+
+ if(www->write_bytes)
+ www->write_bytes(www, www->write_bytes_userdata, www->buffer, len, 1);
+
+ if(len < RAPTOR_WWW_BUFFER_SIZE)
+ break;
+ }
+ fclose(stream);
+
+ return www->failed;
+}
+
+#endif /* RAPTOR_WWW_LIBFETCH */