From 4038ab95a094b363f1748f3dcb51511a1217475d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 07:40:05 +0200 Subject: Adding upstream version 2.0.16. Signed-off-by: Daniel Baumann --- src/raptor_www_libfetch.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/raptor_www_libfetch.c (limited to 'src/raptor_www_libfetch.c') 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 +#endif + +#ifdef RAPTOR_WWW_LIBFETCH + +#include +#include +#include +#include + +#ifdef HAVE_SYS_PARAM_H +#include +#endif +#include + +/* 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 */ -- cgit v1.2.3