Guilhem suggested that a_check_kml_file() be added
instead of using a_check_html_file() for the
kml files.  I redid the patch with that change.
As he suggested, all I did was copy the a_check_html_file()
function and I used just the one check that was previously
added to a_check_html_file().  Someone who knows kml files
better than I should add more checks to make sure one
is getting the right kml stuff.

Guilhem mentioned that "Go to Location" (as opposed to UTM or Latlong)
was broken, so I took out the googlesearch.c changes.  Those
seem not be used by "magic scissors", but I wasn't sure
that that would be the case.  Hopefully it is not.

It seems to work for me so far...  Perhaps this will help
everyone involved in the next release of Viking get magic
scissors fixed properly.

Attached is the patch file.

        Harry McGavran
        



*** ./viking-0.9.9/src/datasource_google.c.orig	Tue Sep  8 14:42:35 2009
--- ./viking-0.9.9/src/datasource_google.c	Wed Sep 16 20:21:32 2009
***************
*** 31,37 ****
  #include "gpx.h"
  #include "acquire.h"
  
! #define GOOGLE_DIRECTIONS_STRING "maps.google.com/maps?q=from:%s+to:%s&output=js"
  
  typedef struct {
    GtkWidget *from_entry, *to_entry;
--- 31,37 ----
  #include "gpx.h"
  #include "acquire.h"
  
! #define GOOGLE_DIRECTIONS_STRING "maps.google.com/maps?q=from:%s+to:%s&output=kml"
  
  typedef struct {
    GtkWidget *from_entry, *to_entry;
***************
*** 100,106 ****
    to_quoted = g_strjoinv( "%20", to_split);
  
    *cmd = g_strdup_printf( GOOGLE_DIRECTIONS_STRING, from_quoted, to_quoted );
!   *input_file_type = g_strdup("google");
  
    g_free(last_from_str);
    g_free(last_to_str);
--- 100,106 ----
    to_quoted = g_strjoinv( "%20", to_split);
  
    *cmd = g_strdup_printf( GOOGLE_DIRECTIONS_STRING, from_quoted, to_quoted );
!   *input_file_type = g_strdup("kml");
  
    g_free(last_from_str);
    g_free(last_to_str);
*** ./viking-0.9.9/src/viktrwlayer.c.orig	Wed Sep  9 14:16:18 2009
--- ./viking-0.9.9/src/viktrwlayer.c	Wed Sep 16 20:21:32 2009
***************
*** 71,77 ****
  static g_hash_table_remove_all (GHashTable *ght) { g_hash_table_foreach_remove ( ght, (GHRFunc) return_true, FALSE ); }
  #endif
  
! #define GOOGLE_DIRECTIONS_STRING "maps.google.com/maps?q=from:%s,%s+to:%s,%s&output=js"
  #define VIK_TRW_LAYER_TRACK_GC 13
  #define VIK_TRW_LAYER_TRACK_GC_RATES 10
  #define VIK_TRW_LAYER_TRACK_GC_MIN 0
--- 71,77 ----
  static g_hash_table_remove_all (GHashTable *ght) { g_hash_table_foreach_remove ( ght, (GHRFunc) return_true, FALSE ); }
  #endif
  
! #define GOOGLE_DIRECTIONS_STRING "maps.google.com/maps?q=from:%s,%s+to:%s,%s&output=kml"
  #define VIK_TRW_LAYER_TRACK_GC 13
  #define VIK_TRW_LAYER_TRACK_GC_RATES 10
  #define VIK_TRW_LAYER_TRACK_GC_MIN 0
***************
*** 3653,3659 ****
                            g_ascii_dtostr (startlon, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) start.lon),
                            g_ascii_dtostr (endlat, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) end.lat),
                            g_ascii_dtostr (endlon, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) end.lon));
!     a_babel_convert_from_url ( vtl, url, "google", NULL, NULL );
      g_free ( url );
  
      /* see if anything was done -- a track was added or appended to */
--- 3653,3659 ----
                            g_ascii_dtostr (startlon, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) start.lon),
                            g_ascii_dtostr (endlat, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) end.lat),
                            g_ascii_dtostr (endlon, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) end.lon));
!     a_babel_convert_from_url ( vtl, url, "kml", NULL, NULL );
      g_free ( url );
  
      /* see if anything was done -- a track was added or appended to */
*** ./viking-0.9.9/src/download.h.orig	Tue Sep  8 14:42:35 2009
--- ./viking-0.9.9/src/download.h	Wed Sep 16 20:28:02 2009
***************
*** 28,33 ****
--- 28,34 ----
  typedef gboolean (*VikFileContentCheckerFunc) (FILE*);
  gboolean a_check_map_file(FILE*);
  gboolean a_check_html_file(FILE*);
+ gboolean a_check_kml_file(FILE*);
  
  typedef struct {
    /**
*** ./viking-0.9.9/src/download.c.orig	Tue Sep  8 14:42:35 2009
--- ./viking-0.9.9/src/download.c	Wed Sep 16 20:33:50 2009
***************
*** 72,77 ****
--- 72,107 ----
    return !a_check_html_file(f);
  }
  
+ gboolean a_check_kml_file(FILE* f)
+ {
+   gchar **s;
+   gchar *bp;
+   fpos_t pos;
+   gchar buf[33];
+   size_t nr;
+   gchar * html_str[] = {
+     "<?xml",
+     NULL
+   };
+ 
+   memset(buf, 0, sizeof(buf));
+   fgetpos(f, &pos);
+   rewind(f);
+   nr = fread(buf, 1, sizeof(buf) - 1, f);
+   fsetpos(f, &pos);
+   for (bp = buf; (bp < (buf + sizeof(buf) - 1)) && (nr > (bp - buf)); bp++) {
+     if (!(isspace(*bp)))
+       break;
+   }
+   if ((bp >= (buf + sizeof(buf) -1)) || ((bp - buf) >= nr))
+     return FALSE;
+   for (s = html_str; *s; s++) {
+     if (strncasecmp(*s, bp, strlen(*s)) == 0)
+       return TRUE;
+   }
+   return FALSE;
+ }
+ 
  static int download( const char *hostname, const char *uri, const char *fn, DownloadOptions *options, gboolean ftp)
  {
    FILE *f;
*** ./viking-0.9.9/src/babel.c.orig	Tue Sep  8 14:42:35 2009
--- ./viking-0.9.9/src/babel.c	Wed Sep 16 20:31:11 2009
***************
*** 276,282 ****
  
  gboolean a_babel_convert_from_url ( VikTrwLayer *vt, const char *url, const char *input_type, BabelStatusFunc cb, gpointer user_data )
  {
!   static DownloadOptions options = {NULL, 0, a_check_html_file};
    gint fd_src;
    int fetch_ret;
    gboolean ret = FALSE;
--- 276,282 ----
  
  gboolean a_babel_convert_from_url ( VikTrwLayer *vt, const char *url, const char *input_type, BabelStatusFunc cb, gpointer user_data )
  {
!   static DownloadOptions options = {NULL, 0, a_check_kml_file};
    gint fd_src;
    int fetch_ret;
    gboolean ret = FALSE;
Harry G. McGavran, Jr.

E-mail: w5...@arrl.net

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Viking-devel mailing list
Viking-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/viking-devel
Viking home page: http://viking.sf.net/

Reply via email to