]> git.street.me.uk Git - andy/viking.git/commitdiff
Add libcurl
authorGuilhem Bonnefille <guilhem.bonnefille@gmail.com>
Mon, 16 Apr 2007 20:12:04 +0000 (20:12 +0000)
committerGuilhem Bonnefille <guilhem.bonnefille@gmail.com>
Mon, 16 Apr 2007 20:12:04 +0000 (20:12 +0000)
configure.ac
src/Makefile.am
src/curl_download.c [new file with mode: 0644]
src/curl_download.h [new file with mode: 0644]
src/download.c
src/http.c

index bf07828949a37d8e52e5df85654f9c8c6a7d1ab0..fb949b419423cac97917bd7402db44ba49589ea9 100644 (file)
@@ -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
index cf2cec561a0e0fbdb5ae99b20c82f59f8d8ff7d8..46a26fb4680e594326bd543802123018d7493961 100644 (file)
@@ -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 (file)
index 0000000..8921281
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
+ *
+ * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
+ *
+ * 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 <gtk/gtk.h>
+
+#ifdef HAVE_LIBCURL
+#include <curl/curl.h>
+#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 (file)
index 0000000..0a8cc91
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
+ *
+ * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
+ *
+ * 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 <stdio.h>
+
+int curl_download_get_url ( const char *hostname, const char *uri, FILE *f );
+
+#endif
index 314b76523854556e845f3a6e3a538b95e2c9b719..e23e7863becb0d42be52f7dbda54f6af9bafa4b2 100644 (file)
  *
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <stdio.h>
 #include <errno.h>
 #include <gtk/gtk.h>
 #include <sys/types.h>
 
 #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)
   {
index d9e935bb636729ba2210ac5b44161e7df17514be..b8e0dab54531083ce9d2daf65175fbde78bd4203 100644 (file)
@@ -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];