Commit b9dd12cc authored by Almer S. Tigelaar's avatar Almer S. Tigelaar Committed by Almer S. Tigelaar

Make more error proof and insert protection for invalid filenames.

2000-10-02  Almer S. Tigelaar  <almer1@dds.nl>

	* src/file-autoft.c:
	(template_list_load): Make more error proof and insert
	protection for invalid filenames.
parent f44c0ae3
2000-10-02 Almer S. Tigelaar <almer1@dds.nl>
* src/file-autoft.c:
(template_list_load): Make more error proof and insert
protection for invalid filenames.
2000-10-01 Almer S. Tigelaar <almer1@dds.nl>
* templates/autoformat/, templates/autoformat/Makefile.am:
......
2000-10-02 Almer S. Tigelaar <almer1@dds.nl>
* src/file-autoft.c:
(template_list_load): Make more error proof and insert
protection for invalid filenames.
2000-10-01 Almer S. Tigelaar <almer1@dds.nl>
* templates/autoformat/, templates/autoformat/Makefile.am:
......
2000-10-02 Almer S. Tigelaar <almer1@dds.nl>
* src/file-autoft.c:
(template_list_load): Make more error proof and insert
protection for invalid filenames.
2000-10-01 Almer S. Tigelaar <almer1@dds.nl>
* templates/autoformat/, templates/autoformat/Makefile.am:
......
2000-10-02 Almer S. Tigelaar <almer1@dds.nl>
* src/file-autoft.c:
(template_list_load): Make more error proof and insert
protection for invalid filenames.
2000-10-01 Almer S. Tigelaar <almer1@dds.nl>
* templates/autoformat/, templates/autoformat/Makefile.am:
......
2000-10-02 Almer S. Tigelaar <almer1@dds.nl>
* src/file-autoft.c:
(template_list_load): Make more error proof and insert
protection for invalid filenames.
2000-10-01 Almer S. Tigelaar <almer1@dds.nl>
* templates/autoformat/, templates/autoformat/Makefile.am:
......
2000-10-02 Almer S. Tigelaar <almer1@dds.nl>
* src/file-autoft.c:
(template_list_load): Make more error proof and insert
protection for invalid filenames.
2000-10-01 Almer S. Tigelaar <almer1@dds.nl>
* templates/autoformat/, templates/autoformat/Makefile.am:
......
2000-10-02 Almer S. Tigelaar <almer1@dds.nl>
* src/file-autoft.c:
(template_list_load): Make more error proof and insert
protection for invalid filenames.
2000-10-01 Almer S. Tigelaar <almer1@dds.nl>
* templates/autoformat/, templates/autoformat/Makefile.am:
......
......@@ -20,6 +20,7 @@
*/
#include <dirent.h>
#include <string.h>
#include <errno.h>
#include "file-autoft.h"
......@@ -61,23 +62,93 @@ template_list_load (void)
GList *list = NULL;
dir = opendir (GNUMERIC_AUTOFORMATDIR);
if (dir == NULL && errno == ENOENT) {
g_warning ("The autoformat template directory %s, does not exist!", GNUMERIC_AUTOFORMATDIR);
if (dir == NULL) {
g_warning ("Error while trying to open the autoformat template directory %s : %s", GNUMERIC_AUTOFORMATDIR, g_strerror (errno));
return NULL;
}
errno = 0;
while ((ent = readdir (dir))) {
if (strcmp (ent->d_name, ".") != 0 && strcmp (ent->d_name, "..") != 0) {
list = g_list_append (list, g_strdup_printf ("%s/%s", GNUMERIC_AUTOFORMATDIR, ent->d_name));
count++;
/*
* Look if the name is actually a valid filename
* A valid filename is "autoformat.<Category>.<name>.xml";
* The result of g_strsplit should always be 4 strings and than a \0
*/
if (ent->d_name && strcmp (ent->d_name, ".") != 0 && strcmp (ent->d_name, "..") != 0) {
char **array = g_strsplit (ent->d_name, ".", -1);
gboolean valid = TRUE;
int elements = 0;
/*
* Count number of elements in array
*/
while (array[elements]) {
elements++;
}
if (elements == 4) {
/*
* The first part should always be "autoformat"
*/
if (array[0]) {
g_strdown (array[0]);
if (strcmp (array[0], "autoformat") != 0)
valid = FALSE;
} else {
valid = FALSE;
}
/*
* Now a category should come
*/
if (!array[1]) {
valid = FALSE;
}
/*
* After that the name of the template
*/
if (!array[2]) {
valid = FALSE;
}
/*
* And last but not least "xml"
*/
if (array[3]) {
g_strdown (array[3]);
if (strcmp (array[3], "xml") != 0)
valid = FALSE;
} else {
valid = FALSE;
}
} else {
valid = FALSE;
}
/*
* Only add it if valid, otherwise print an error
*/
if (valid) {
list = g_list_append (list, g_strdup_printf ("%s/%s", GNUMERIC_AUTOFORMATDIR, ent->d_name));
count++;
} else {
g_warning ("The file %s encountered in %s is an invalid file, please remove it from your autoformat directory",
ent->d_name, GNUMERIC_AUTOFORMATDIR);
}
g_strfreev (array);
}
errno = 0;
}
if (errno) {
g_warning ("Error while reading listing of %s", GNUMERIC_AUTOFORMATDIR);
g_warning ("Error while reading listing of %s", GNUMERIC_AUTOFORMATDIR);
closedir (dir);
g_list_free (list);
return NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment