Diff of /trunk/src/gpx.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 34 by harbaum, Wed Jul 29 19:24:15 2009 UTC revision 204 by harbaum, Mon Nov 23 18:32:06 2009 UTC
# Line 42  void gpx_free_wpt(wpt_t *wpt) { Line 42  void gpx_free_wpt(wpt_t *wpt) {
42    free(wpt);    free(wpt);
43  }  }
44    
45    void gpx_free_user(user_t *user) {
46      if(user->name) xmlFree(user->name);
47      free(user);
48    }
49    
50  void gpx_free_log(log_t *log) {  void gpx_free_log(log_t *log) {
51    if(log->finder)  xmlFree(log->finder);    if(log->finder)  gpx_free_user(log->finder);
52    if(log->text)    xmlFree(log->text);    if(log->text)    xmlFree(log->text);
53    free(log);    free(log);
54  }  }
# Line 61  void gpx_free_cache(cache_t *cache) { Line 66  void gpx_free_cache(cache_t *cache) {
66    
67    if(cache->id)                xmlFree(cache->id);    if(cache->id)                xmlFree(cache->id);
68    if(cache->name)              xmlFree(cache->name);    if(cache->name)              xmlFree(cache->name);
69    if(cache->owner)             xmlFree(cache->owner);    if(cache->owner)             gpx_free_user(cache->owner);
70    if(cache->short_description) xmlFree(cache->short_description);    if(cache->short_description) xmlFree(cache->short_description);
71    if(cache->long_description)  xmlFree(cache->long_description);    if(cache->long_description)  xmlFree(cache->long_description);
72    if(cache->hint)              xmlFree(cache->hint);    if(cache->hint)              xmlFree(cache->hint);
# Line 114  void gpx_free_all(gpx_t *gpx) { Line 119  void gpx_free_all(gpx_t *gpx) {
119  }  }
120    
121  static const char *cache_type_str[] = { "<Unknown>",  static const char *cache_type_str[] = { "<Unknown>",
122    "Traditional Cache|Traditional|Geocache", "Multi-cache|Multi",    "Traditional Cache|Traditional|Geocache", "Multi-cache|Multi|Multicache",
123    "Unknown Cache|Other",    "Unknown Cache|Other|Unknown",
124    "Virtual Cache|Virtual", "Webcam Cache|Webcam", "Event Cache|Event|Geocoins:",    "Virtual Cache|Virtual", "Webcam Cache|Webcam", "Event Cache|Event|Geocoins:",
125    "Letterbox Hybrid|Letterbox", "Earthcache", "Wherigo Cache",    "Letterbox Hybrid|Letterbox", "Earthcache", "Wherigo Cache",
126    "Mega-Event Cache", "Cache In Trash Out Event",    "Mega-Event Cache", "Cache In Trash Out Event",
# Line 267  void gpx_display_log(log_t *log) { Line 272  void gpx_display_log(log_t *log) {
272    printf("  Log:\n");    printf("  Log:\n");
273    printf("    date:     %d.%d.%d\n", log->day, log->month, log->year);    printf("    date:     %d.%d.%d\n", log->day, log->month, log->year);
274    printf("    type:     %s\n", log_type_str[log->type+1]);    printf("    type:     %s\n", log_type_str[log->type+1]);
275    printf("    finder:   %s\n", log->finder);    printf("    finder:   %s\n", log->finder->name);
276      printf("    id:       #%u\n", log->id);
277    //  printf("    text:     %s\n", log->text);    //  printf("    text:     %s\n", log->text);
278  }  }
279    
# Line 279  void gpx_display_cache(cache_t *cache) { Line 285  void gpx_display_cache(cache_t *cache) {
285    printf("  name:       %s\n", cache->name);    printf("  name:       %s\n", cache->name);
286    printf("  latitude:   %f\n", cache->pos.lat);    printf("  latitude:   %f\n", cache->pos.lat);
287    printf("  longitude:  %f\n", cache->pos.lon);    printf("  longitude:  %f\n", cache->pos.lon);
288    printf("  owner:      %s\n", cache->owner);    printf("  owner:      %s\n", cache->owner->name);
289    printf("  type:       %s\n", cache_type_str[cache->type+1]);    printf("  type:       %s\n", cache_type_str[cache->type+1]);
290    printf("  container:  %s\n", cache_container_str[cache->container+1]);    printf("  container:  %s\n", cache_container_str[cache->container+1]);
291    printf("  difficulty: %.1f\n", cache->difficulty);    printf("  difficulty: %.1f\n", cache->difficulty);
# Line 326  static float xml_get_prop_float(xmlTextR Line 332  static float xml_get_prop_float(xmlTextR
332    return ret;    return ret;
333  }  }
334    
335    static unsigned int xml_get_prop_id(xmlTextReaderPtr reader) {
336      unsigned int ret = 0;
337      char *prop;
338      if((prop = (char*)xmlTextReaderGetAttribute(reader, BAD_CAST "id"))) {
339        ret = atoi(prop);
340        xmlFree(prop);
341      }
342      return ret;
343    }
344    
345  static int xml_prop_is(xmlTextReaderPtr reader, char *name, char *value,  static int xml_prop_is(xmlTextReaderPtr reader, char *name, char *value,
346                         int def_value) {                         int def_value) {
347    int match = def_value;    int match = def_value;
# Line 360  static gboolean skip_element(xmlTextRead Line 376  static gboolean skip_element(xmlTextRead
376    
377  static char *process_text(xmlTextReaderPtr reader) {  static char *process_text(xmlTextReaderPtr reader) {
378    char *text = NULL;    char *text = NULL;
   int depth = xmlTextReaderDepth(reader);  
   int ret = xmlTextReaderRead(reader);  
   while((ret == 1) &&  
         ((xmlTextReaderNodeType(reader) != XML_READER_TYPE_END_ELEMENT) ||  
          (xmlTextReaderDepth(reader) != depth))) {  
379    
380      /* found a text fragment */    if(!xmlTextReaderIsEmptyElement(reader)) {
381      if((xmlTextReaderNodeType(reader) == XML_READER_TYPE_TEXT) ||  
382         (xmlTextReaderNodeType(reader) == XML_READER_TYPE_CDATA)) {      int depth = xmlTextReaderDepth(reader);
383        char *frag = (char*)xmlTextReaderConstValue(reader);      int ret = xmlTextReaderRead(reader);
384        while((ret == 1) &&
385        if(!text) text = strdup(frag);            ((xmlTextReaderNodeType(reader) != XML_READER_TYPE_END_ELEMENT) ||
386        else {             (xmlTextReaderDepth(reader) != depth))) {
387          char *old = text;  
388          text = malloc(strlen(old) + strlen(frag) + 1);        /* found a text fragment */
389          strcpy(text, old);        if((xmlTextReaderNodeType(reader) == XML_READER_TYPE_TEXT) ||
390          strcat(text, frag);           (xmlTextReaderNodeType(reader) == XML_READER_TYPE_CDATA)) {
391          free(old);          char *frag = (char*)xmlTextReaderConstValue(reader);
392    
393            if(!text) text = strdup(frag);
394            else {
395              char *old = text;
396              text = malloc(strlen(old) + strlen(frag) + 1);
397              strcpy(text, old);
398              strcat(text, frag);
399              free(old);
400            }
401        }        }
402          ret = xmlTextReaderRead(reader);
403      }      }
     ret = xmlTextReaderRead(reader);  
404    }    }
405    
406    return text;    return text;
# Line 415  static void xml_get_date(xmlTextReaderPt Line 435  static void xml_get_date(xmlTextReaderPt
435    }    }
436  }  }
437    
438  static log_t *process_gpx_wpt_gc_logs_log(xmlTextReaderPtr reader) {  static log_t *process_gpx_wpt_gc_logs_log(xmlTextReaderPtr reader,
439                                              char *username, cache_t *cache) {
440    
441      gboolean by_user = FALSE;
442    
443    if(xmlTextReaderIsEmptyElement(reader))    if(xmlTextReaderIsEmptyElement(reader))
444      return NULL;      return NULL;
445    
446    /* create a new log entry */    /* create a new log entry */
447    log_t *log = malloc(sizeof(log_t));    log_t *log = g_new0(log_t, 1);
448    memset(log, 0, sizeof(log_t));  
449      char *prop = (char*)xmlTextReaderGetAttribute(reader, BAD_CAST "id");
450      if(prop)
451        log->id = atoi(prop);
452    
453    /* process all sub-nodes */    /* process all sub-nodes */
454    int depth = xmlTextReaderDepth(reader);    int depth = xmlTextReaderDepth(reader);
# Line 442  static log_t *process_gpx_wpt_gc_logs_lo Line 468  static log_t *process_gpx_wpt_gc_logs_lo
468            log->type = xml_str_search(reader, log_type_str, "log", 0);            log->type = xml_str_search(reader, log_type_str, "log", 0);
469          } else if((strcasecmp(name, "finder") == 0) ||          } else if((strcasecmp(name, "finder") == 0) ||
470                    (strcasecmp(name, "geocacher") == 0)) {                    (strcasecmp(name, "geocacher") == 0)) {
471            if(!log->finder) log->finder = process_text(reader);            if(!log->finder) {
472                log->finder = g_new0(user_t, 1);
473                log->finder->name = process_text(reader);
474                log->finder->id = xml_get_prop_id(reader);
475    
476                /* is this a log by us? */
477                if(username && !strcasecmp(username, log->finder->name))
478                  by_user = TRUE;
479              }
480          } else if(strcasecmp(name, "text") == 0) {          } else if(strcasecmp(name, "text") == 0) {
481            if(!log->text) log->text = process_text(reader);            if(!log->text) log->text = process_text(reader);
482          } else          } else
# Line 452  static log_t *process_gpx_wpt_gc_logs_lo Line 486  static log_t *process_gpx_wpt_gc_logs_lo
486        break;        break;
487    
488      case XML_READER_TYPE_END_ELEMENT:      case XML_READER_TYPE_END_ELEMENT:
489          if(by_user && log->type == LOG_TYPE_FOUND)
490            cache->found = TRUE;
491    
492        /* end element must be for the current element */        /* end element must be for the current element */
493        g_assert(xmlTextReaderDepth(reader) == depth);        g_assert(xmlTextReaderDepth(reader) == depth);
494        return log;        return log;
# Line 463  static log_t *process_gpx_wpt_gc_logs_lo Line 500  static log_t *process_gpx_wpt_gc_logs_lo
500      ret = xmlTextReaderRead(reader);      ret = xmlTextReaderRead(reader);
501    }    }
502    
503    g_assert(0);    gpx_free_log(log);
504    return log;    return NULL;
505  }  }
506    
507  static log_t *process_gpx_wpt_gc_logs(xmlTextReaderPtr reader) {  static log_t *process_gpx_wpt_gc_logs(xmlTextReaderPtr reader, char *username,
508                                          cache_t *cache) {
509    log_t *log_chain = NULL;    log_t *log_chain = NULL;
510    
511    if(xmlTextReaderIsEmptyElement(reader))    if(xmlTextReaderIsEmptyElement(reader))
# Line 485  static log_t *process_gpx_wpt_gc_logs(xm Line 523  static log_t *process_gpx_wpt_gc_logs(xm
523        if(strrchr(name, ':')) name = strrchr(name, ':')+1;        if(strrchr(name, ':')) name = strrchr(name, ':')+1;
524        if(name) {        if(name) {
525          if(strcasecmp(name, "log") == 0) {          if(strcasecmp(name, "log") == 0) {
526            log_t *log = process_gpx_wpt_gc_logs_log(reader);            log_t *log = process_gpx_wpt_gc_logs_log(reader, username, cache);
527            if(log) {            if(log) {
528              /* add log to chain */              /* add log to chain */
529              log_t **cur = &log_chain;              log_t **cur = &log_chain;
# Line 513  static log_t *process_gpx_wpt_gc_logs(xm Line 551  static log_t *process_gpx_wpt_gc_logs(xm
551      ret = xmlTextReaderRead(reader);      ret = xmlTextReaderRead(reader);
552    }    }
553    
554    g_assert(0);    /* free the entire log chain */
555    return log_chain;    while(log_chain) {
556        log_t *next = log_chain->next;
557        gpx_free_log(log_chain);
558        log_chain = next;
559      }
560    
561      return NULL;
562  }  }
563    
564  static tb_t *process_gpx_wpt_gc_tbs_travelbug(xmlTextReaderPtr reader) {  static tb_t *process_gpx_wpt_gc_tbs_travelbug(xmlTextReaderPtr reader) {
# Line 532  static tb_t *process_gpx_wpt_gc_tbs_trav Line 576  static tb_t *process_gpx_wpt_gc_tbs_trav
576    else    else
577      tb->ref = strdup("<NONE>");      tb->ref = strdup("<NONE>");
578    
579      if((prop = (char*)xmlTextReaderGetAttribute(reader, BAD_CAST "id")))
580        tb->id = atoi(prop);
581    
582    /* process all sub-nodes */    /* process all sub-nodes */
583    int depth = xmlTextReaderDepth(reader);    int depth = xmlTextReaderDepth(reader);
584    int ret = xmlTextReaderRead(reader);    int ret = xmlTextReaderRead(reader);
# Line 563  static tb_t *process_gpx_wpt_gc_tbs_trav Line 610  static tb_t *process_gpx_wpt_gc_tbs_trav
610      ret = xmlTextReaderRead(reader);      ret = xmlTextReaderRead(reader);
611    }    }
612    
613    g_assert(0);    gpx_free_tb(tb);
614    return tb;    return NULL;
615  }  }
616    
617  static tb_t *process_gpx_wpt_gc_tbs(xmlTextReaderPtr reader) {  static tb_t *process_gpx_wpt_gc_tbs(xmlTextReaderPtr reader) {
# Line 605  static tb_t *process_gpx_wpt_gc_tbs(xmlT Line 652  static tb_t *process_gpx_wpt_gc_tbs(xmlT
652      ret = xmlTextReaderRead(reader);      ret = xmlTextReaderRead(reader);
653    }    }
654    
655    g_assert(0);    while(tb) {
656    return tb;      tb_t *next = tb;
657        gpx_free_tb(tb);
658        tb = next;
659      }
660    
661      return NULL;
662  }  }
663    
664  static void process_gpx_wpt_gc(xmlTextReaderPtr reader, cache_t *cache) {  static void process_gpx_wpt_gc(xmlTextReaderPtr reader,
665                                   cache_t *cache, char *username) {
666    cache->available = xml_prop_is(reader, "available", "true", TRUE);    cache->available = xml_prop_is(reader, "available", "true", TRUE);
667    cache->archived = xml_prop_is(reader, "archived", "true", FALSE);    cache->archived = xml_prop_is(reader, "archived", "true", FALSE);
668    
# Line 630  static void process_gpx_wpt_gc(xmlTextRe Line 683  static void process_gpx_wpt_gc(xmlTextRe
683          if(strcasecmp(name, "name") == 0) {          if(strcasecmp(name, "name") == 0) {
684            if(!cache->name) cache->name = process_text(reader);            if(!cache->name) cache->name = process_text(reader);
685          } else if(strcasecmp(name, "owner") == 0) {          } else if(strcasecmp(name, "owner") == 0) {
686            if(!cache->owner) cache->owner = process_text(reader);            if(!cache->owner) {
687                cache->owner = g_new0(user_t, 1);
688                cache->owner->name = process_text(reader);
689                cache->owner->id = xml_get_prop_id(reader);
690              }
691          } else if(strcasecmp(name, "type") == 0) {          } else if(strcasecmp(name, "type") == 0) {
692            cache->type = xml_str_search(reader, cache_type_str,            cache->type = xml_str_search(reader, cache_type_str,
693                                         "cache type", CACHE_TYPE_UNKNOWN);                                         "cache type", CACHE_TYPE_UNKNOWN);
# Line 653  static void process_gpx_wpt_gc(xmlTextRe Line 710  static void process_gpx_wpt_gc(xmlTextRe
710                    (strcasecmp(name, "hints") == 0))     {                    (strcasecmp(name, "hints") == 0))     {
711            if(!cache->hint) {            if(!cache->hint) {
712              cache->hint = process_text(reader);              cache->hint = process_text(reader);
713    
714              /* often hints aren't more than just a bunch of blanks ... */              /* often hints aren't more than just a bunch of blanks ... */
715              if(cache->hint && all_is_white(cache->hint)) {              if(cache->hint && all_is_white(cache->hint)) {
716                free(cache->hint);                free(cache->hint);
# Line 665  static void process_gpx_wpt_gc(xmlTextRe Line 723  static void process_gpx_wpt_gc(xmlTextRe
723          } else if(strcasecmp(name, "terrain") == 0) {          } else if(strcasecmp(name, "terrain") == 0) {
724            cache->terrain = xml_float(reader, 0.0);            cache->terrain = xml_float(reader, 0.0);
725          } else if(strcasecmp(name, "logs") == 0) {          } else if(strcasecmp(name, "logs") == 0) {
726            if(!cache->log) cache->log = process_gpx_wpt_gc_logs(reader);            if(!cache->log) cache->log =
727                        process_gpx_wpt_gc_logs(reader, username, cache);
728          } else if(strcasecmp(name, "travelbugs") == 0) {          } else if(strcasecmp(name, "travelbugs") == 0) {
729            if(!cache->tb) cache->tb = process_gpx_wpt_gc_tbs(reader);            if(!cache->tb) cache->tb = process_gpx_wpt_gc_tbs(reader);
730          } else {          } else {
# Line 691  static void process_gpx_wpt_gc(xmlTextRe Line 750  static void process_gpx_wpt_gc(xmlTextRe
750    
751  /* parse waypoint entry */  /* parse waypoint entry */
752  static cache_t *process_gpx_wpt(xmlTextReaderPtr reader,  gpx_dialog_t *dialog,  static cache_t *process_gpx_wpt(xmlTextReaderPtr reader,  gpx_dialog_t *dialog,
753                                  gpx_t *gpx) {                                  gpx_t *gpx, char *username) {
754    char *cmt = NULL, *desc = NULL;    char *cmt = NULL, *desc = NULL;
755    char *sym = NULL;    char *sym = NULL;
756    
# Line 731  static cache_t *process_gpx_wpt(xmlTextR Line 790  static cache_t *process_gpx_wpt(xmlTextR
790            if(!cache->url) cache->url = process_text(reader);            if(!cache->url) cache->url = process_text(reader);
791          } else if((strcasecmp(name, "cache") == 0) ||          } else if((strcasecmp(name, "cache") == 0) ||
792                    (strcasecmp(name, "geocache") == 0)) {                    (strcasecmp(name, "geocache") == 0)) {
793            process_gpx_wpt_gc(reader, cache);            process_gpx_wpt_gc(reader, cache, username);
794    
795            /* the following are used if the current entry is a waypoint */            /* the following are used if the current entry is a waypoint */
796          } else if(strcasecmp(name, "cmt") == 0) {          } else if(strcasecmp(name, "cmt") == 0) {
# Line 831  static cache_t *process_gpx_wpt(xmlTextR Line 890  static cache_t *process_gpx_wpt(xmlTextR
890      ret = xmlTextReaderRead(reader);      ret = xmlTextReaderRead(reader);
891    }    }
892    
893    g_assert(0);    gpx_free_cache(cache);
894    return cache;    return NULL;
895  }  }
896    
897  static void process_gpx(xmlTextReaderPtr reader, gpx_dialog_t *dialog,  static gboolean process_gpx(xmlTextReaderPtr reader, gpx_dialog_t *dialog,
898                          gpx_t *gpx) {                              gpx_t *gpx, char *username) {
899    
900    /* no attributes of interest */    /* no attributes of interest */
901    
# Line 847  static void process_gpx(xmlTextReaderPtr Line 906  static void process_gpx(xmlTextReaderPtr
906    while(*cache) cache = &(*cache)->next;    while(*cache) cache = &(*cache)->next;
907    
908    const xmlChar *name = xmlTextReaderConstName(reader);    const xmlChar *name = xmlTextReaderConstName(reader);
909    g_assert(name);    if(!name) return FALSE;
910    
911    /* read next node */    /* read next node */
912    int ret = xmlTextReaderRead(reader);    int ret = xmlTextReaderRead(reader);
# Line 866  static void process_gpx(xmlTextReaderPtr Line 925  static void process_gpx(xmlTextReaderPtr
925                           (strcasecmp(name, "date") == 0))) {                           (strcasecmp(name, "date") == 0))) {
926          xml_get_date(reader, &gpx->year, &gpx->month, &gpx->day);          xml_get_date(reader, &gpx->year, &gpx->month, &gpx->day);
927        } else if(name && strcasecmp(name, "wpt") == 0) {        } else if(name && strcasecmp(name, "wpt") == 0) {
928          *cache = process_gpx_wpt(reader, dialog, gpx);          *cache = process_gpx_wpt(reader, dialog, gpx, username);
929          if(*cache) cache = &(*cache)->next;          if(*cache) cache = &(*cache)->next;
930        } else {        } else {
931          //      printf("something unknown (%s) found\n", name);          //      printf("something unknown (%s) found\n", name);
# Line 877  static void process_gpx(xmlTextReaderPtr Line 936  static void process_gpx(xmlTextReaderPtr
936      case XML_READER_TYPE_END_ELEMENT:      case XML_READER_TYPE_END_ELEMENT:
937        /* end element must be for the current element */        /* end element must be for the current element */
938        g_assert(xmlTextReaderDepth(reader) == 0);        g_assert(xmlTextReaderDepth(reader) == 0);
939        return;        return TRUE;
940        break;        break;
941    
942      default:      default:
# Line 886  static void process_gpx(xmlTextReaderPtr Line 945  static void process_gpx(xmlTextReaderPtr
945      ret = xmlTextReaderRead(reader);      ret = xmlTextReaderRead(reader);
946    }    }
947    
948    g_assert(0);    return FALSE;
949  }  }
950    
951  /* parse loc waypoint entry */  /* parse loc waypoint entry */
# Line 993  static void process_loc(xmlTextReaderPtr Line 1052  static void process_loc(xmlTextReaderPtr
1052  }  }
1053    
1054  static gpx_t *process_root(xmlTextReaderPtr reader, gpx_dialog_t *dialog,  static gpx_t *process_root(xmlTextReaderPtr reader, gpx_dialog_t *dialog,
1055                             char *fname, gpx_t *in) {                             char *fname, gpx_t *in, char *username) {
1056    
1057    /* no gpx entry given, create a new one */    /* no gpx entry given, create a new one */
1058    gpx_t *gpx = NULL;    gpx_t *gpx = NULL;
# Line 1012  static gpx_t *process_root(xmlTextReader Line 1071  static gpx_t *process_root(xmlTextReader
1071        g_assert(xmlTextReaderDepth(reader) == 0);        g_assert(xmlTextReaderDepth(reader) == 0);
1072        char *name = (char*)xmlTextReaderConstName(reader);        char *name = (char*)xmlTextReaderConstName(reader);
1073        if(name && strcasecmp(name, "gpx") == 0) {        if(name && strcasecmp(name, "gpx") == 0) {
1074          process_gpx(reader, dialog, gpx);          process_gpx(reader, dialog, gpx, username);
1075        } else if(name && strcasecmp(name, "loc") == 0) {        } else if(name && strcasecmp(name, "loc") == 0) {
1076          process_loc(reader, dialog, gpx);          process_loc(reader, dialog, gpx);
1077        } else {        } else {
# Line 1048  static gpx_t *process_root(xmlTextReader Line 1107  static gpx_t *process_root(xmlTextReader
1107    return gpx;    return gpx;
1108  }  }
1109    
1110  static gpx_t *gpx_parse_file(gpx_dialog_t *dialog, char *filename) {  static gpx_t *gpx_parse_file(gpx_dialog_t *dialog,
1111                                 char *filename, char *username) {
1112    gpx_t *gpx = NULL;    gpx_t *gpx = NULL;
1113    
1114    LIBXML_TEST_VERSION;    LIBXML_TEST_VERSION;
# Line 1057  static gpx_t *gpx_parse_file(gpx_dialog_ Line 1117  static gpx_t *gpx_parse_file(gpx_dialog_
1117    
1118    xmlTextReaderPtr reader = xmlReaderForFile(filename, NULL, 0);    xmlTextReaderPtr reader = xmlReaderForFile(filename, NULL, 0);
1119    if (reader != NULL) {    if (reader != NULL) {
1120      gpx = process_root(reader, dialog, filename, NULL);      gpx = process_root(reader, dialog, filename, NULL, username);
1121      xmlFreeTextReader(reader);      xmlFreeTextReader(reader);
1122    } else {    } else {
1123      fprintf(stderr, "Unable to open %s\n", filename);      fprintf(stderr, "Unable to open %s\n", filename);
# Line 1073  static gpx_t *gpx_parse_file(gpx_dialog_ Line 1133  static gpx_t *gpx_parse_file(gpx_dialog_
1133      if(g_file_test(wpts_name,  G_FILE_TEST_EXISTS)) {      if(g_file_test(wpts_name,  G_FILE_TEST_EXISTS)) {
1134        xmlTextReaderPtr reader = xmlReaderForFile(wpts_name, NULL, 0);        xmlTextReaderPtr reader = xmlReaderForFile(wpts_name, NULL, 0);
1135        if (reader != NULL) {        if (reader != NULL) {
1136          gpx = process_root(reader, dialog, wpts_name, gpx);          gpx = process_root(reader, dialog, wpts_name, gpx, username);
1137          xmlFreeTextReader(reader);          xmlFreeTextReader(reader);
1138        } else {        } else {
1139          fprintf(stderr, "Unable to open %s\n", filename);          fprintf(stderr, "Unable to open %s\n", filename);
# Line 1086  static gpx_t *gpx_parse_file(gpx_dialog_ Line 1146  static gpx_t *gpx_parse_file(gpx_dialog_
1146    
1147  static gpx_t *decompress_file(unzFile file, gpx_dialog_t *dialog,  static gpx_t *decompress_file(unzFile file, gpx_dialog_t *dialog,
1148                                char *name, char *filename,                                char *name, char *filename,
1149                                gpx_t *gpx_in) {                                gpx_t *gpx_in, char *username) {
1150    unz_file_info info;    unz_file_info info;
1151    gpx_t *gpx = NULL;    gpx_t *gpx = NULL;
1152    
# Line 1130  static gpx_t *decompress_file(unzFile fi Line 1190  static gpx_t *decompress_file(unzFile fi
1190      xmlReaderForMemory(buffer, info.uncompressed_size,      xmlReaderForMemory(buffer, info.uncompressed_size,
1191                         NULL, NULL, 0);                         NULL, NULL, 0);
1192    if (reader != NULL) {    if (reader != NULL) {
1193      gpx = process_root(reader, dialog, filename, gpx_in);      gpx = process_root(reader, dialog, filename, gpx_in, username);
1194      xmlFreeTextReader(reader);      xmlFreeTextReader(reader);
1195    } else {    } else {
1196      fprintf(stderr, "Unable to open %s\n", filename);      fprintf(stderr, "Unable to open %s\n", filename);
# Line 1141  static gpx_t *decompress_file(unzFile fi Line 1201  static gpx_t *decompress_file(unzFile fi
1201    return gpx;    return gpx;
1202  }  }
1203    
1204  static gpx_t *decompress_zip(gpx_dialog_t *dialog, char *filename) {  static gpx_t *decompress_zip(gpx_dialog_t *dialog,
1205                                 char *filename, char *username) {
1206    char *gpx_name, *fbase;    char *gpx_name, *fbase;
1207    gpx_t *gpx = NULL;    gpx_t *gpx = NULL;
1208    
# Line 1165  static gpx_t *decompress_zip(gpx_dialog_ Line 1226  static gpx_t *decompress_zip(gpx_dialog_
1226    strcpy(gpx_name+strlen(gpx_name)-4, ".gpx");    strcpy(gpx_name+strlen(gpx_name)-4, ".gpx");
1227    printf("gpx file name is %s\n", gpx_name);    printf("gpx file name is %s\n", gpx_name);
1228    
1229    gpx = decompress_file(file, dialog, gpx_name, filename, NULL);    gpx = decompress_file(file, dialog, gpx_name, filename, NULL, username);
1230    
1231    /* try to open -wpts.gpx file inside */    /* try to open -wpts.gpx file inside */
1232    strcpy(gpx_name, fbase);    strcpy(gpx_name, fbase);
1233    strcpy(gpx_name+strlen(gpx_name)-4, "-wpts.gpx");    strcpy(gpx_name+strlen(gpx_name)-4, "-wpts.gpx");
1234    printf("gpx wpts file name is %s\n", gpx_name);    printf("gpx wpts file name is %s\n", gpx_name);
1235    
1236    gpx = decompress_file(file, dialog, gpx_name, filename, gpx);    gpx = decompress_file(file, dialog, gpx_name, filename, gpx, username);
1237    
1238    unzClose(file);    unzClose(file);
1239    free(gpx_name);    free(gpx_name);
1240    return gpx;    return gpx;
1241  }  }
1242    
1243  gpx_t *gpx_parse(gpx_dialog_t *dialog, char *filename) {  gpx_t *gpx_parse(gpx_dialog_t *dialog, char *filename, char *username) {
1244    gpx_t *gpx = NULL;    gpx_t *gpx = NULL;
1245    
1246    /* show busy dialog */    /* show busy dialog */
# Line 1189  gpx_t *gpx_parse(gpx_dialog_t *dialog, c Line 1250  gpx_t *gpx_parse(gpx_dialog_t *dialog, c
1250       !strcasecmp(filename+strlen(filename)-4, ".zip")) {       !strcasecmp(filename+strlen(filename)-4, ".zip")) {
1251      printf("trying to load a zip file!\n");      printf("trying to load a zip file!\n");
1252    
1253      gpx = decompress_zip(dialog, filename);      gpx = decompress_zip(dialog, filename, username);
1254    } else    } else
1255      gpx = gpx_parse_file(dialog, filename);      gpx = gpx_parse_file(dialog, filename, username);
1256    
1257    return gpx;    return gpx;
1258  }  }
1259    
1260  /* scan entire directory */  /* scan entire directory */
1261  gpx_t *gpx_parse_dir(gpx_dialog_t *dialog, char *dirname) {  gpx_t *gpx_parse_dir(gpx_dialog_t *dialog, char *dirname, char *username) {
1262    GnomeVFSResult result;    GnomeVFSResult result;
1263    GnomeVFSDirectoryHandle *handle;    GnomeVFSDirectoryHandle *handle;
1264    GnomeVFSFileInfo *finfo = gnome_vfs_file_info_new();;    GnomeVFSFileInfo *finfo = gnome_vfs_file_info_new();;
# Line 1234  gpx_t *gpx_parse_dir(gpx_dialog_t *dialo Line 1295  gpx_t *gpx_parse_dir(gpx_dialog_t *dialo
1295    
1296          xmlTextReaderPtr reader = xmlReaderForFile(filename, NULL, 0);          xmlTextReaderPtr reader = xmlReaderForFile(filename, NULL, 0);
1297          if (reader != NULL) {          if (reader != NULL) {
1298            gpx = process_root(reader, dialog, filename, gpx);            gpx = process_root(reader, dialog, filename, gpx, username);
1299            xmlFreeTextReader(reader);            xmlFreeTextReader(reader);
1300          } else {          } else {
1301            fprintf(stderr, "Unable to open %s\n", filename);            fprintf(stderr, "Unable to open %s\n", filename);
# Line 1281  int gpx_total_caches(gpx_t *gpx) { Line 1342  int gpx_total_caches(gpx_t *gpx) {
1342    }    }
1343    
1344    return num;    return num;
1345    }
1346    
1347    /* return number of caches in all gpx files */
1348    int gpx_total_caches_global(gpx_t *gpx) {
1349      int num = 0;
1350      while(gpx) {
1351        num += gpx_total_caches(gpx);
1352        gpx = gpx->next;
1353      }
1354    
1355      return num;
1356  }  }
1357    
1358  int gpx_number_of_waypoints(wpt_t *wpt) {  int gpx_number_of_waypoints(wpt_t *wpt) {

Legend:
Removed from v.34  
changed lines
  Added in v.204