From: Guilhem Bonnefille Date: Mon, 16 Apr 2007 20:12:04 +0000 (+0000) Subject: Add libcurl X-Git-Url: https://git.street.me.uk/andy/viking.git/commitdiff_plain/3292ba8bb8e85babc44cb4f831f9b758089f1cfc Add libcurl --- diff --git a/configure.ac b/configure.ac index bf078289..fb949b41 100644 --- a/configure.ac +++ b/configure.ac @@ -27,6 +27,9 @@ AC_CHECK_FUNCS([bzero floor gethostbyname memset mkdir pow realpath socket sqrt # Expat AM_WITH_EXPAT +# Curl +LIBCURL_CHECK_CONFIG([yes],[],[AM_CONDITIONAL([LIBCURL],[true])],[AM_CONDITIONAL([LIBCURL],[false])]) + AC_CHECK_PROG([GDK_PIXBUF_CSOURCE],gdk-pixbuf-csource,[yes]) if test $GDK_PIXBUF_CSOURCE != "yes" then diff --git a/src/Makefile.am b/src/Makefile.am index cf2cec56..46a26fb4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -27,7 +27,6 @@ viking_SOURCES = main.c \ file.c file.h \ authors.h \ dialog.c dialog.h \ - http.c http.h \ download.c download.h \ viktreeview.c viktreeview.h \ viktrwlayer.c viktrwlayer.h viktrwlayer_pixmap.h \ @@ -59,6 +58,14 @@ viking_SOURCES = main.c \ datasource_gc.c \ datasources.h +if LIBCURL +viking_SOURCES += \ + curl_download.c curl_download.h +else +viking_SOURCES += \ + http.c http.h +endif + if GOOGLE viking_SOURCES += \ khmaps.c khmaps.h \ @@ -76,6 +83,6 @@ viking_SOURCES += \ expedia.c expedia.h endif -INCLUDES = @GTK_CFLAGS@ @EXPAT_CFLAGS@ -LDADD = @GTK_LIBS@ @EXPAT_LIBS@ +INCLUDES = @GTK_CFLAGS@ @EXPAT_CFLAGS@ @LIBCURL_CPPFLAGS@ +LDADD = @GTK_LIBS@ @EXPAT_LIBS@ @LIBCURL@ AM_CFLAGS = -Wall -g diff --git a/src/curl_download.c b/src/curl_download.c new file mode 100644 index 00000000..8921281c --- /dev/null +++ b/src/curl_download.c @@ -0,0 +1,63 @@ +/* + * viking -- GPS Data and Topo Analyzer, Explorer, and Manager + * + * Copyright (C) 2003-2005, Evan Battaglia + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#ifdef HAVE_LIBCURL +#include +#endif + +#include "curl_download.h" + +int curl_download_uri ( const char *uri, FILE *f ) +{ +#ifdef HAVE_LIBCURL + CURL *curl; + CURLcode res; + + curl = curl_easy_init (); + if ( curl ) + { + curl_easy_setopt ( curl, CURLOPT_URL, uri ); + curl_easy_setopt ( curl, CURLOPT_FILE, f ); + res = curl_easy_perform ( curl ); + curl_easy_cleanup ( curl ); + } +#endif +} + +int curl_download_get_url ( const char *hostname, const char *uri, FILE *f ) +{ + int ret; + gchar *full = NULL; + + /* Compose the full url */ + full = g_strdup_printf ( "http://%s%s", hostname, uri ); + ret = curl_download_uri ( full, f ); + g_free ( full ); + full = NULL; + + return ret; +} diff --git a/src/curl_download.h b/src/curl_download.h new file mode 100644 index 00000000..0a8cc910 --- /dev/null +++ b/src/curl_download.h @@ -0,0 +1,29 @@ +/* + * viking -- GPS Data and Topo Analyzer, Explorer, and Manager + * + * Copyright (C) 2003-2005, Evan Battaglia + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef _VIKING_CURL_DOWNLOAD_H +#define _VIKING_CURL_DOWNLOAD_H + +#include + +int curl_download_get_url ( const char *hostname, const char *uri, FILE *f ); + +#endif diff --git a/src/download.c b/src/download.c index 314b7652..e23e7863 100644 --- a/src/download.c +++ b/src/download.c @@ -19,6 +19,10 @@ * */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include @@ -26,7 +30,12 @@ #include #include "download.h" + +#ifdef HAVE_LIBCURL +#include "curl_download.h" +#else #include "http.h" +#endif #ifdef WINDOWS @@ -83,7 +92,11 @@ static int download( const char *hostname, const char *uri, const char *fn, int } /* Call the backend function */ +#ifdef HAVE_LIBCURL + ret = curl_download_get_url ( hostname, uri, f ); +#else ret = http_download_get_url ( hostname, uri, f, 0, sendhostname ); +#endif if (ret == -1 || ret == 1 || ret == -2) { diff --git a/src/http.c b/src/http.c index d9e935bb..b8e0dab5 100644 --- a/src/http.c +++ b/src/http.c @@ -88,7 +88,6 @@ int http_get_line(int sock, char *buf, int len) return 1; } -/* makes directory if neccessary */ int http_download_get_url ( const char *hostname, const char *uri, FILE *f, int already_redirected, int sendhostname ) { static char input_buffer[1024];