[Xfce4-commits] <orage:master> 4.7.4.5: Added check that selected os tz timezone exists also in ical database.

Juha Kautto juha at xfce.org
Fri Sep 11 11:26:01 CEST 2009


Updating branch refs/heads/master
         to 852a34e4033487810b9e7484cc5ab65f336e1903 (commit)
       from a3c5d30aa75ab587ff5406697bbc43b2e3af3d31 (commit)

commit 852a34e4033487810b9e7484cc5ab65f336e1903
Author: Juha Kautto <juha at xfce.org>
Date:   Fri Sep 11 12:20:02 2009 +0300

    4.7.4.5: Added check that selected os tz timezone exists also in ical database.
    
    Timezone selection is based on operating system tz data but Orage uses internal
    ical timezone data. So added test, which makes it possible to only show those
    timezones that are available in ical. This test is not needed in the panel
    plugin nor in globaltime as those use truely os timeinfo data.
    Also fixed a big memory leak when switching display format.

 configure.in.in          |    2 +-
 src/timezone_selection.c |    2 +-
 src/tz_zoneinfo_read.c   |  174 +++++++++++++++++++++++++++++++++-------------
 src/tz_zoneinfo_read.h   |    2 +-
 4 files changed, 128 insertions(+), 52 deletions(-)

diff --git a/configure.in.in b/configure.in.in
index b805328..b75fbbb 100644
--- a/configure.in.in
+++ b/configure.in.in
@@ -9,7 +9,7 @@ dnl Written for Xfce by Juha Kautto <juha at xfce.org>
 dnl
 
 dnl Version information
-m4_define([orage_version], [4.7.4.4-test])
+m4_define([orage_version], [4.7.4.5-test])
 
 m4_define([gtk_minimum_version], [2.10.0])
 m4_define([xfce_minimum_version], [4.6.0])
diff --git a/src/timezone_selection.c b/src/timezone_selection.c
index 9a566b9..baeae91 100644
--- a/src/timezone_selection.c
+++ b/src/timezone_selection.c
@@ -88,7 +88,7 @@ static GtkTreeStore *tz_button_create_store(gboolean details)
             , G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING
             , G_TYPE_STRING, G_TYPE_STRING);
     strcpy(area_old, "S T a R T"); /* this never matches */
-    tz_a = get_orage_timezones(details);
+    tz_a = get_orage_timezones(details, 1);
     /*
     g_print(P_N "number of timezones %d\n", tz_a.count);
     */
diff --git a/src/tz_zoneinfo_read.c b/src/tz_zoneinfo_read.c
index b3a08d4..a97a8eb 100644
--- a/src/tz_zoneinfo_read.c
+++ b/src/tz_zoneinfo_read.c
@@ -59,65 +59,72 @@
 
 
 /** This is the toplevel directory where the timezone data is installed in. */
-#define ORAGE_ZONEINFO_DIRECTORY  PACKAGE_DATA_DIR "/orage/zoneinfo"
+#define ORAGE_ZONEINFO_DIRECTORY  PACKAGE_DATA_DIR "/orage/zoneinfo/"
 
 /** This is the filename of the file containing tz_convert parameters
  * This file contains the location of the os zoneinfo data.
  * the same than the above DEFAULT_OS_ZONEINFO_DIRECTORY */
 #define TZ_CONVERT_PAR_FILENAME  "tz_convert.par"
-#define TZ_CONVERT_PAR_FILE_LOC  ORAGE_ZONEINFO_DIRECTORY "/" TZ_CONVERT_PAR_FILENAME
+#define TZ_CONVERT_PAR_FILE_LOC  ORAGE_ZONEINFO_DIRECTORY TZ_CONVERT_PAR_FILENAME
 
+/** This is the filename of the file containing orage ical timezone names */
+#define ICAL_ZONES_TAB_FILENAME  "zones.tab"
+#define ICAL_ZONES_TAB_FILE_LOC  ORAGE_ZONEINFO_DIRECTORY ICAL_ZONES_TAB_FILENAME
 
 
 /* this contains all timezone data */
 orage_timezone_array tz_array={0, NULL, NULL, NULL, NULL, NULL, NULL};
 
-char *zone_tab_buf = NULL, *country_buf = NULL;
+static char *zone_tab_buf = NULL, *country_buf = NULL, *zones_tab_buf = NULL;
 
-int debug = 0; /* bigger number => more output */
-char version[] = "1.4.4";
-int file_cnt = 0; /* number of processed files */
+static int debug = 0; /* bigger number => more output */
+static char version[] = "1.4.4";
+static int file_cnt = 0; /* number of processed files */
 
-unsigned char *in_buf, *in_head, *in_tail;
-int in_file_base_offset = 0;
+static unsigned char *in_buf, *in_head, *in_tail;
+static int in_file_base_offset = 0;
 
-int details;
+static int details;     /* show extra data (country and next change time) */
+static int check_ical;  /* check that we have also the ical timezone data */
 
-char *in_file = NULL, *out_file = NULL;
-int in_file_is_dir = 0;
-int excl_dir_cnt = -1;
-char **excl_dir = NULL;
+static char *in_file = NULL, *out_file = NULL;
+static int in_file_is_dir = 0;
+static int excl_dir_cnt = -1;
+static char **excl_dir = NULL;
 
 /* in_timezone_name is the real timezone name from the infile 
  * we are processing.
- * in_timezone_name is the timezone we are writing. Usually it is the same
+ * timezone_name is the timezone we are writing. Usually it is the same
  * than in_timezone_name. 
- * timezone name is for example Europe/Helsinki */
-char *timezone_name = NULL;  
-char *in_timezone_name = NULL;
+ * timezone_name is for example Europe/Helsinki */
+/* FIXME: we do nto need both timezone_name and in_timezone_name here.
+ * Remove one */
+static char *timezone_name = NULL;  
+static char *in_timezone_name = NULL;
 
-int ignore_older = 1970; /* Ignore rules which are older or equal than this */
+/* Ignore rules which are older or equal than this */
+static int ignore_older = 1970; 
 
 /* time change table starts here */
-unsigned char *begin_timechanges;           
+static unsigned char *begin_timechanges;           
 
 /* time change type index table starts here */
-unsigned char *begin_timechangetypeindexes; 
+static unsigned char *begin_timechangetypeindexes; 
 
 /* time change type table starts here */
-unsigned char *begin_timechangetypes;       
+static unsigned char *begin_timechangetypes;       
 
 /* timezone name table */
-unsigned char *begin_timezonenames;         
+static unsigned char *begin_timezonenames;         
 
-unsigned long gmtcnt;
-unsigned long stdcnt;
-unsigned long leapcnt;
-unsigned long timecnt;  /* points when time changes */
-unsigned long typecnt;  /* table of different time changes = types */
-unsigned long charcnt;  /* length of timezone name table */
+static unsigned long gmtcnt;
+static unsigned long stdcnt;
+static unsigned long leapcnt;
+static unsigned long timecnt;  /* points when time changes */
+static unsigned long typecnt;  /* table of different time changes = types */
+static unsigned long charcnt;  /* length of timezone name table */
 
-void read_file(const char *file_name, const struct stat *file_stat)
+static void read_file(const char *file_name, const struct stat *file_stat)
 {
     FILE *file;
 
@@ -136,7 +143,7 @@ void read_file(const char *file_name, const struct stat *file_stat)
         printf("read_file: end\n");
 }
 
-long get_long()
+static long get_long()
 {
     unsigned long tmp;
 
@@ -148,7 +155,7 @@ long get_long()
     return(tmp);
 }
 
-int process_header()
+static int process_header()
 {
     if (debug > 2)
         printf("file id: %s\n", in_head);
@@ -180,7 +187,7 @@ int process_header()
     return(0);
 }
 
-process_local_time_table()
+static process_local_time_table()
 { /* points when time changes */
     unsigned long tmp;
     int i;
@@ -199,7 +206,7 @@ process_local_time_table()
     }
 }
 
-process_local_time_type_table()
+static process_local_time_type_table()
 { /* pointers to table, which explain how time changes */
     unsigned char tmp;
     int i;
@@ -215,7 +222,7 @@ process_local_time_type_table()
     }
 }
 
-process_ttinfo_table()
+static process_ttinfo_table()
 { /* table of different time changes = types */
     long tmp;
     unsigned char tmp2, tmp3;
@@ -236,7 +243,7 @@ process_ttinfo_table()
     }
 }
 
-process_abbr_table()
+static process_abbr_table()
 {
     unsigned char *tmp;
     int i;
@@ -253,7 +260,7 @@ process_abbr_table()
     in_head += charcnt;
 }
 
-process_leap_table()
+static process_leap_table()
 {
     unsigned long tmp, tmp2;
     int i;
@@ -269,7 +276,7 @@ process_leap_table()
     }
 }
 
-process_std_table()
+static process_std_table()
 {
     unsigned char tmp;
     int i;
@@ -284,7 +291,7 @@ process_std_table()
     }
 }
 
-process_gmt_table()
+static process_gmt_table()
 {
     unsigned char tmp;
     int i;
@@ -301,7 +308,7 @@ process_gmt_table()
 
 /* go through the contents of the file and find the positions of 
  * needed data. Uses global pointer: in_head */
-int process_file(const char *file_name)
+static int process_file(const char *file_name)
 {
     if (debug > 1)
         printf("\n\nprocess_file: start\n");
@@ -323,7 +330,7 @@ int process_file(const char *file_name)
     return(0); /* ok */
 }
 
-void get_country()
+static void get_country()
 { /* tz_array.city[tz_array.count] contains the city name.
      We will find corresponding country and fill it to the table */
     char *str, *str_nl;
@@ -358,9 +365,21 @@ void get_country()
     tz_array.country[tz_array.count][(str_nl - str)] = '\0';
 }
 
+static int timezone_exists_in_ical()
+{ /* in_timezone_name contains the timezone name.
+     We will search if it exists also in the ical zones.tab file */
+    char *str;
+
+    if (str = strstr(zones_tab_buf, in_timezone_name))
+        return(1); /* yes, it is there */
+    else 
+        return(0); /* not found */
+}
+
 /* FIXME: need to check that if OUTFILE is given as a parameter,
  * INFILE is not a directory (or make outfile to act like directory also ? */
-int write_ical_file(const char *in_file_name, const struct stat *in_file_stat)
+static int write_ical_file(const char *in_file_name
+        , const struct stat *in_file_stat)
 {
     int i;
     unsigned int tct_i, abbr_i;
@@ -441,7 +460,7 @@ int write_ical_file(const char *in_file_name, const struct stat *in_file_stat)
 }
 
 /* The main code. This is called once per each file found */
-int file_call(const char *file_name, const struct stat *sb, int flags
+static int file_call(const char *file_name, const struct stat *sb, int flags
         , struct FTW *f)
 {
     int i;
@@ -453,14 +472,22 @@ int file_call(const char *file_name, const struct stat *sb, int flags
     if (flags == FTW_F) { /* we got file */
         if (debug > 0)
             printf("\t\tfile_call: processing file=(%s)\n", file_name);
+        in_timezone_name = strdup(&file_name[in_file_base_offset 
+                + strlen("zoneinfo/")]);
+        timezone_name = strdup(in_timezone_name);
+        if (check_ical && !timezone_exists_in_ical()) {
+            printf("\t\tfile_call: skipped file=(%s)\n", file_name);
+            free(in_timezone_name);
+            free(timezone_name);
+            return(FTW_CONTINUE);
+        }
         read_file(file_name, sb);
         if (process_file(file_name)) { /* we skipped this file */
+            free(in_timezone_name);
+            free(timezone_name);
             free(in_buf);
             return(FTW_CONTINUE);
         }
-        in_timezone_name = strdup(&file_name[in_file_base_offset 
-                + strlen("zoneinfo/")]);
-        timezone_name = strdup(in_timezone_name);
         write_ical_file(file_name, sb);
 
         free(in_buf);
@@ -499,7 +526,7 @@ int file_call(const char *file_name, const struct stat *sb, int flags
 }
 
 /* check the parameters and use defaults when possible */
-int check_parameters()
+static int check_parameters()
 {
     char *s_tz, *last_tz = NULL, tz[]="/zoneinfo", tz2[]="zoneinfo/";
     int tz_len, i;
@@ -630,7 +657,8 @@ int check_parameters()
     return(0); /* continue */
 }
 
-void read_countries()
+
+static void read_countries()
 {
     char *tz_dir, *zone_tab_file_name, *country_file_name;
     int zoneinfo_len=strlen("zoneinfo/");
@@ -730,7 +758,40 @@ void read_countries()
     fclose(country_file);
 }
 
-orage_timezone_array get_orage_timezones(int show_details)
+static void read_ical_timezones()
+{
+    FILE *zones_tab_file;
+    struct stat zones_tab_file_stat;
+
+    /****** zones.tab file ******/
+    if (!(zones_tab_file = fopen(ICAL_ZONES_TAB_FILE_LOC, "r"))) {
+        printf("read_ical_timezones: zones.tab file open failed (%s)\n"
+                , ICAL_ZONES_TAB_FILE_LOC);
+        perror("\tfopen");
+        return;
+    }
+    if (stat(ICAL_ZONES_TAB_FILE_LOC, &zones_tab_file_stat) == -1) {
+        printf("read_ical_timezones: zones.tab file stat failed (%s)\n"
+                , ICAL_ZONES_TAB_FILE_LOC);
+        fclose(zones_tab_file);
+        perror("\tstat");
+        return;
+    }
+    zones_tab_buf = malloc(zones_tab_file_stat.st_size+1);
+    fread(zones_tab_buf, 1, zones_tab_file_stat.st_size, zones_tab_file);
+    if (ferror(zones_tab_file)) {
+        printf("read_ical_timezones: zones.tab file read failed (%s)\n"
+                , ICAL_ZONES_TAB_FILE_LOC);
+        perror("\tfread");
+        return;
+    }
+    zones_tab_buf[zones_tab_file_stat.st_size] = '\0';
+    printf("read_ical_timezones: zones.tab file read (%s) (%d bytes)\n"
+                , ICAL_ZONES_TAB_FILE_LOC, strlen(zones_tab_buf));
+    fclose(zones_tab_file);
+}
+
+orage_timezone_array get_orage_timezones(int show_details, int ical)
 {
     int tz_array_size = 1000; /* FIXME: this needs to be counted */
     /*
@@ -740,6 +801,7 @@ orage_timezone_array get_orage_timezones(int show_details)
    */
 
     details = show_details;
+    check_ical = ical;
     if (tz_array.count == 0) {
         tz_array.city = (char **)malloc(sizeof(char *)*(tz_array_size+2));
         tz_array.utc_offset = (int *)malloc(sizeof(int)*(tz_array_size+2));
@@ -756,6 +818,8 @@ orage_timezone_array get_orage_timezones(int show_details)
             printf("Processing %s files\n", in_file);
         if (details)
             read_countries();
+        if (check_ical)
+            read_ical_timezones();
         if (nftw(in_file, file_call, 10, FTW_PHYS | FTW_ACTIONRETVAL) == -1) {
             perror("nftw error in file handling");
             exit(EXIT_FAILURE);
@@ -781,7 +845,7 @@ orage_timezone_array get_orage_timezones(int show_details)
         tz_array.cc[tz_array.count] = NULL;
         tz_array.city[tz_array.count++] = strdup("floating");
     }
-    return (tz_array);
+    return(tz_array);
 }
 
 void free_orage_timezones(int show_details)
@@ -809,5 +873,17 @@ void free_orage_timezones(int show_details)
     free(tz_array.cc);
     tz_array.count = 0;
     timezone_name = NULL;
+    if (zone_tab_buf) {
+        free(zone_tab_buf);
+        zone_tab_buf = NULL;
+    }
+    if (country_buf) {
+        free(country_buf);
+        country_buf = NULL;
+    }
+    if (zones_tab_buf) {
+        free(zones_tab_buf);
+        zones_tab_buf = NULL;
+    }
     file_cnt = 0; /* number of processed files */
 }
diff --git a/src/tz_zoneinfo_read.h b/src/tz_zoneinfo_read.h
index 9002f44..8e05e1b 100644
--- a/src/tz_zoneinfo_read.h
+++ b/src/tz_zoneinfo_read.h
@@ -30,5 +30,5 @@ typedef struct _orage_timezone_array
     char **cc;        /* pointer to country code strings */
 } orage_timezone_array;
 
-orage_timezone_array get_orage_timezones(int details);
+orage_timezone_array get_orage_timezones(int details, int ical);
 void free_orage_timezones(int details);



More information about the Xfce4-commits mailing list