From f901dcdf910009cfbd7e008450c6dd49e4ba3570 Mon Sep 17 00:00:00 2001 From: Guilhem Bonnefille Date: Mon, 20 Aug 2007 21:17:21 +0000 Subject: [PATCH] libcurl is a requirement It is no more a optional feature, but an "hard" requirement. The main reason is that it is time consuming to maintain code to work with and without libcurl. Furthermore, libcurl is available in a lot of distributions now. --- ChangeLog | 4 ++ configure.ac | 2 +- src/Makefile.am | 9 +-- src/curl_download.c | 2 - src/download.c | 8 --- src/download.h | 5 -- src/expedia.c | 2 +- src/google.c | 2 +- src/googlemaps.c | 2 +- src/googlesearch.c | 2 +- src/http.c | 199 ---------------------------------------------------- src/http.h | 31 -------- src/khmaps.c | 2 +- src/main.c | 2 - src/osm.c | 3 +- src/terraserver.c | 2 +- 16 files changed, 13 insertions(+), 264 deletions(-) delete mode 100644 src/http.c delete mode 100644 src/http.h diff --git a/ChangeLog b/ChangeLog index b7443034..c0df49f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,8 @@ 2007-08-20 +Guilhem Bonnefille : + * libcurl is a requirement + +2007-08-20 Quy Tonthat : * Fix bugs that cause crashes on layers copy/paste/delete. * Fix bug in Google search that caused viking jump to wrong location diff --git a/configure.ac b/configure.ac index 447b4252..8a6370e7 100644 --- a/configure.ac +++ b/configure.ac @@ -28,7 +28,7 @@ AC_CHECK_FUNCS([bzero floor gethostbyname memset mkdir pow realpath socket sqrt AM_WITH_EXPAT # Curl -LIBCURL_CHECK_CONFIG([yes],[],[AM_CONDITIONAL([LIBCURL],[true])],[AM_CONDITIONAL([LIBCURL],[false])]) +LIBCURL_CHECK_CONFIG([yes],[],[],[AC_MSG_ERROR([libcurl is needed but not found])]) AC_CHECK_PROG([GDK_PIXBUF_CSOURCE],gdk-pixbuf-csource,[yes]) if test $GDK_PIXBUF_CSOURCE != "yes" diff --git a/src/Makefile.am b/src/Makefile.am index 7b0c2cd0..739e3d37 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,6 +15,7 @@ BUILT_SOURCES = authors.h viking_SOURCES = main.c \ modules.h modules.c \ + curl_download.c curl_download.h \ menu.xml.h \ degrees_converters.c degrees_converters.h \ viking.h globals.h mapcoord.h config.h \ @@ -64,14 +65,6 @@ viking_SOURCES = main.c \ vikfilelist.c vikfilelist.h \ dems.c dems.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 \ diff --git a/src/curl_download.c b/src/curl_download.c index c287fe7b..5082744c 100644 --- a/src/curl_download.c +++ b/src/curl_download.c @@ -27,7 +27,6 @@ #include -#ifdef HAVE_LIBCURL #include #include "file.h" @@ -112,4 +111,3 @@ int curl_download_get_url ( const char *hostname, const char *uri, FILE *f, Down return (ret ? -2 : 0); /* -2 HTTP error */ } -#endif /* HAVE_LIB_CURL */ diff --git a/src/download.c b/src/download.c index 871c0ee5..42a1e7b5 100644 --- a/src/download.c +++ b/src/download.c @@ -34,11 +34,7 @@ #include "download.h" -#ifdef HAVE_LIBCURL #include "curl_download.h" -#else -#include "http.h" -#endif #ifdef WINDOWS @@ -141,11 +137,7 @@ static int download( const char *hostname, const char *uri, const char *fn, Down } /* Call the backend function */ -#ifdef HAVE_LIBCURL ret = curl_download_get_url ( hostname, uri, f, options ); -#else - ret = http_download_get_url ( hostname, uri, f, 0, options ); -#endif if (ret == -1 || ret == 1 || ret == -2 || check_map_file(f)) { diff --git a/src/download.h b/src/download.h index d31776ae..7f400948 100644 --- a/src/download.h +++ b/src/download.h @@ -24,11 +24,6 @@ typedef struct { /** - * Indicates if we should send hostname on the GET request. - * (see http.c) - */ - int sendhostname; - /** * The REFERER string to use. * Could be NULL. */ diff --git a/src/expedia.c b/src/expedia.c index 6352559e..93783e27 100644 --- a/src/expedia.c +++ b/src/expedia.c @@ -37,7 +37,7 @@ static gboolean expedia_coord_to_mapcoord ( const VikCoord *src, gdouble xzoom, static void expedia_mapcoord_to_center_coord ( MapCoord *src, VikCoord *dest ); static int expedia_download ( MapCoord *src, const gchar *dest_fn ); -static DownloadOptions expedia_options = { 0, NULL }; +static DownloadOptions expedia_options = { NULL }; void expedia_init() { VikMapsLayer_MapType map_type = { 5, 0, 0, VIK_VIEWPORT_DRAWMODE_EXPEDIA, expedia_coord_to_mapcoord, expedia_mapcoord_to_center_coord, expedia_download }; diff --git a/src/google.c b/src/google.c index 8bc227a6..331fa0b9 100644 --- a/src/google.c +++ b/src/google.c @@ -40,7 +40,7 @@ static int google_kh_download ( MapCoord *src, const gchar *dest_fn ); static void google_mapcoord_to_center_coord ( MapCoord *src, VikCoord *dest ); static gboolean google_coord_to_mapcoord ( const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest ); -static DownloadOptions google_options = { 1, "http://maps.google.com/" }; +static DownloadOptions google_options = { "http://maps.google.com/" }; void google_init () { VikMapsLayer_MapType google_1 = { 7, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, google_coord_to_mapcoord, google_mapcoord_to_center_coord, google_download }; diff --git a/src/googlemaps.c b/src/googlemaps.c index 87795fdf..150108a6 100644 --- a/src/googlemaps.c +++ b/src/googlemaps.c @@ -30,7 +30,7 @@ #include "googlemaps.h" -static DownloadOptions googlemaps_options = { 1, "http://maps.google.com/" }; +static DownloadOptions googlemaps_options = { "http://maps.google.com/" }; /* initialisation */ void googlemaps_init () { diff --git a/src/googlesearch.c b/src/googlesearch.c index e616d053..7c9cbc1f 100644 --- a/src/googlesearch.c +++ b/src/googlesearch.c @@ -35,7 +35,7 @@ static gchar *last_search_str = NULL; static VikCoord *last_coord = NULL; static gchar *last_successful_search_str = NULL; -static DownloadOptions googlesearch_options = { 0, "http://maps.google.com/" }; +static DownloadOptions googlesearch_options = { "http://maps.google.com/" }; gchar * a_googlesearch_get_search_string_for_this_place(VikWindow *vw) { diff --git a/src/http.c b/src/http.c deleted file mode 100644 index 56bd1647..00000000 --- a/src/http.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - * 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 - * - */ - -#include -#include -#include -#include - -#ifdef WINDOWS -#include -#else -#include -#include -#include -#include -#endif - -#include "http.h" - -int http_connect(const char *hostname, int port) -{ - int sock; - struct sockaddr_in server; - struct hostent *host_addr; - - /* create a socket of type AF_INET, and SOCK_STREAM (TCP) */ - sock = socket(AF_INET, SOCK_STREAM, 0); - - /* get an IP from a domain name -- essential */ - host_addr = gethostbyname(hostname); - if (host_addr == NULL) - return(-1); - - server.sin_family = AF_INET; - /* 110 is the standard POP port. Host TO Network order. */ - server.sin_port = htons(port); - /* get the IP address. */ - server.sin_addr = *((struct in_addr *) host_addr->h_addr); - /* padding unused in sockaddr_in */ -#ifndef WINDOWS - bzero(&(server.sin_zero), 8); -#endif - - if ((connect(sock, (struct sockaddr *) &server, sizeof(struct sockaddr))) == -1) - return(-2); - - return(sock); -} - -int http_get_line(int sock, char *buf, int len) -{ - static char lilbuf; - int size, count; - - count = 1; - size = 1; - lilbuf = 'a'; - while (size != 0 && lilbuf != '\n' && count < len) - { - size = recv(sock, &lilbuf, 1, 0); - if (size == 0 && count == 1 ) - return 0; - - if (size > 0) - *buf++ = lilbuf; - count++; - } - *buf = '\0'; - - return 1; -} - -int http_download_get_url ( const char *hostname, const char *uri, FILE *f, int already_redirected, DownloadOptions *options ) -{ - static char input_buffer[1024]; - int sock; - int len; - FILE *tmp_f; - /* int hnlen = strlen ( hostname ); */ - -#ifdef WINDOWS - WSADATA usadata; - WSAStartup ( MAKEWORD(2,2), &usadata ); -#endif - - sock = http_connect ( hostname, 80 ); - if (sock < 0) - { - return -1; - } - - - if ( options != NULL && options->sendhostname ) { - send ( sock, "GET http://", 11, 0); - send ( sock, hostname, strlen(hostname), 0 ); - send ( sock, uri, strlen ( uri ), 0 ); - send ( sock, " HTTP/1.0\r\n\r\n", 13, 0 ); - } else { - send ( sock, "GET ", 4, 0 ); - send ( sock, uri, strlen ( uri ), 0 ); - send ( sock, "\r\n\r\n", 4, 0 ); - } - - /* next, skip through all headers EXCEPT content length., - that is, if it begins with "Content-Length: " (strncasecmp), - atoi that line from +16 (+17 ?), read that many bytes directly - into file (IF we can open it, else return error) and we're done. - */ - - /* "HTTP/1.x 200 OK" check */ - if ( recv ( sock, input_buffer, 12, 0 ) < 12 || input_buffer[9] != '2' || input_buffer[10] != '0' || input_buffer[11] != '0' ) - { - /* maybe it's a redirect */ - if ( ! already_redirected ) - do - { - if ( http_get_line ( sock, input_buffer, 1024 ) == 0 ) - break; - - /* Location: http://abc.def/bla */ - if ( strncmp(input_buffer, "Location: ", 10) == 0 && strlen(input_buffer) > 17 ) - { - char *uri_start; - - int rv; - uri_start = strchr(input_buffer+17,'/'); - - if ( uri_start ) - { - char *newhost = g_strndup ( input_buffer + 17, uri_start - input_buffer - 17 ); - char *newuri = strdup ( uri_start ); - close ( sock ); - - if ( options != NULL ) - rv = http_download_get_url ( newhost, newuri, f, 1, options->sendhostname ); - else - rv = http_download_get_url ( newhost, newuri, f, 1, 0 ); - - free ( newhost ); - free ( newuri ); - return rv; - } - } - } while (input_buffer[0] != '\r' ); - - /* Something went wrong */ - return 1; - } - - do - { - if ( http_get_line ( sock, input_buffer, 1024 ) == 0 ) - { - close ( sock ); - return -2; - } - } while (input_buffer[0] != '\r' ); - - tmp_f = tmpfile(); - - do { - len = recv ( sock, input_buffer, 1024, 0 ); - if ( len > 0 ) - fwrite ( input_buffer, 1, len, tmp_f ); - } while ( len > 0 ); - - rewind(tmp_f); - - while ( ! feof(tmp_f) ) - { - len = fread ( input_buffer, 1, 1024, tmp_f ); - fwrite ( input_buffer, 1, len, f); - } - fclose ( tmp_f ); - - close ( sock ); -#ifdef WINDOWS - WSACleanup(); /* they sure make winsock programming easy. */ -#endif - return 0; -} diff --git a/src/http.h b/src/http.h deleted file mode 100644 index d9aac4ab..00000000 --- a/src/http.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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_HTTP_H -#define _VIKING_HTTP_H - -#include - -#include "download.h" - -int http_download_get_url ( const char *hostname, const char *uri, FILE *f, int already_redirected, DownloadOptions *options ); - -#endif diff --git a/src/khmaps.c b/src/khmaps.c index 5921c987..0177d180 100644 --- a/src/khmaps.c +++ b/src/khmaps.c @@ -31,7 +31,7 @@ #include "khmaps.h" -static DownloadOptions khmaps_options = { 1, NULL }; +static DownloadOptions khmaps_options = { NULL }; void khmaps_init () { VikMapsLayer_MapType map_type = { 8, 256, 256, VIK_VIEWPORT_DRAWMODE_KH, khmaps_coord_to_mapcoord, khmaps_mapcoord_to_center_coord, khmaps_download }; diff --git a/src/main.c b/src/main.c index 44e4a543..1ed6f23e 100644 --- a/src/main.c +++ b/src/main.c @@ -92,9 +92,7 @@ int main( int argc, char *argv[] ) gtk_init (&argc, &argv); -#ifdef HAVE_LIBCURL curl_download_init(); -#endif /* Init modules/plugins */ modules_init(); diff --git a/src/osm.c b/src/osm.c index 5fd04697..0116fc6e 100644 --- a/src/osm.c +++ b/src/osm.c @@ -25,7 +25,6 @@ #include "coords.h" #include "vikcoord.h" #include "mapcoord.h" -#include "http.h" #include "vikmapslayer.h" #include "osm.h" @@ -38,7 +37,7 @@ static int osm_maplint_download ( MapCoord *src, const gchar *dest_fn ); static int osm_mapnik_download ( MapCoord *src, const gchar *dest_fn ); static int osm_osmarender_download ( MapCoord *src, const gchar *dest_fn ); -static DownloadOptions osm_options = { 1, NULL }; +static DownloadOptions osm_options = { NULL }; /* initialisation */ void osm_init () { diff --git a/src/terraserver.c b/src/terraserver.c index 68c77b8f..85d7a61a 100644 --- a/src/terraserver.c +++ b/src/terraserver.c @@ -41,7 +41,7 @@ static int terraserver_urban_download ( MapCoord *src, const gchar *dest_fn ); static void terraserver_mapcoord_to_center_coord ( MapCoord *src, VikCoord *dest ); -static DownloadOptions terraserver_options = { 0, NULL }; +static DownloadOptions terraserver_options = { NULL }; void terraserver_init () { VikMapsLayer_MapType map_type_1 = { 2, 200, 200, VIK_VIEWPORT_DRAWMODE_UTM, terraserver_topo_coord_to_mapcoord, terraserver_mapcoord_to_center_coord, terraserver_topo_download }; -- 2.11.4.GIT