]> git.street.me.uk Git - andy/viking.git/blobdiff - src/download.c
Fix magic scissors
[andy/viking.git] / src / download.c
index 27b123f25e6a6d70d98ca333b912dc98f9275303..9aefb479b31ef802835c11890c19c0f2ba84c1b4 100644 (file)
@@ -72,6 +72,36 @@ gboolean a_check_map_file(FILE* f)
   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;