Patch : filter_load
- From: Emmanuel <e allaud wanadoo fr>
- To: balsa-list gnome org
- Subject: Patch : filter_load
- Date: Fri, 22 Jun 2001 11:04:10 +0200
Hi all,
here is a patch (against 1.1.5, sorry, but I think there were no change
in that file anyway) to implement the load of filters.
The other patch for filter_funcs.c is in filter_new to initialize the
name member to NULL.
Comments are welcome
Manu
--- filter-file.c Fri Oct 6 17:50:50 2000
+++ filter-file.c.corr Fri Jun 22 10:44:39 2001
@@ -54,8 +54,10 @@
gint filter_load(GList * filter_list, gchar * filter_file)
{
FILE *fp;
- gchar *buf;
+ gchar *buf,*cur,*p;
+ filter *new_filter;
size_t len;
+ gboolean syn_error=FALSE;
if ((!filter_file) || (filter_file[0] == '\0')) {
filter_errno = FILTER_ENOFILE;
@@ -74,9 +76,113 @@
return (-FILTER_ENOREAD);
}
+ filter_errno=FILTER_NOERR;
len = libbalsa_readfile(fp, &buf);
+ cur=buf;
+ while (!syn_error && *cur) {
+ new_filter=filter_new();
+ /* First we read the fixed part of the filter (all but the regex list */
+ field=1;
+ while (!syn_error && (field<=11)) {
+ p=strchr(cur,'\n');
+ if (p) {
+ *p='\0';
+ /* We read the field */
+ switch (field) {
+ case 1:
+ new_filter->group=atoi(cur);
+ /* FIXME : chek value ????*/
+ break;
+ case 2:
+ new_filter->name=g_strdup(cur);
+ break;
+ case 3:
+ new_filter->type=atoi(cur);
+ syn_error=
+ (new_filter->type<FILTER_NONE)
+ || (new_filter->type>FILTER_EXEC);
+ break;
+ case 4:
+ new_filter->match_when=atoi(cur);
+ syn_error=
+ (new_filter->match_when<FILTER_MATCHES)
+ || (new_filter->match_when>FILTER_ALWAYS);
+ break;
+ case 5:
+ new_filter->flags=atoi(cur);
+ /* FIXME : chek value ????*/
+ break;
+ case 6:
+ strncpy(new_filter->match.string,cur,1024);
+ /* Be sure it's null terminated */
+ new_filter->match.string[1023]='\0';
+ break;
+ case 7:
+ if (new_filter->type==FILTER_SIMPLE) {
+ new_filter->type=atoi(cur);
+ break
+ }
+ /* If filter is not of type FILTER_SIMPLE
+ we pass directly to next field */
+ else field++;
+ case 8:
+ strncpy(new_filter->sound,cur,PATH_MAX);
+ /* Be sure it's null terminated */
+ new_filter->sound[PATH_MAX-1]='\0';
+ /* FIXME : Verify sound path??? */
+ break;
+ case 9:
+ strncpy(new_filter->popup_text,cur,256);
+ /* Be sure it's null terminated */
+ new_filter->popup_text[255]='\0';
+ break;
+ case 10:
+ new_filter->action=atoi(cur);
+ syn_error=
+ (new_filter->type<FILTER_NOTHING)
+ || (new_filter->type>FILTER_TRASH);
+ break;
+ case 11:
+ strncpy(new_filter->action_string,cur,PATH_MAX);
+ /* Be sure it's null terminated */
+ new_filter->action_string[PATH_MAX-1]='\0';
+ break;
+ }
+ /* Next field */
+ cur=p++;field++;
+ }
+ /* Syntax error : we lack fields */
+ else syn_error=TRUE;
+ }
+ /*If syntax is still correct, we read the regex list */
+ if (!syn_error) {
+ while (*cur && (filter_errno==FILTER_NOERR) &&
+ (strncmp(cur,"END OF REGEX LIST",17)!=0)) {
+ p=strchr(cur,'\n');
+ if (p) {
+ *p='\0';
+ /* We authorize the regex list of the last filter
+ not to be terminated by "END OF REGEX LIST */
+ filter_errno=filter_append_regex(new_filter,cur);
+ /* Next regex */
+ cur=p++;
+ }
+ /* File must finish by a \n */
+ else syn_error=TRUE;
+ }
+ }
+ /* We append the new filter even if it is not correct because
+ of a syntax error, anyway it will be freed in that case (see below) */
+ filter_list=g_list_append(filter_list,new_filter);
+ }
+ g_free(buf);
fclose(fp);
-
+ if (syn_error || (filter_errno!=FILTER_NOERR)) {
+ filter_clear_filters(filter_list);
+ filter_errno=
+ (filter_errno!=FILTER_NOERR) ? filter_errno : FILTER_EFILESYN;
+ return -filter_errno;
+ }
return (0);
}
@@ -94,6 +200,32 @@
* gint - 0 for success, -1 for error. Sets filter_errno on error.
*/
gint filter_save(GList * filter_list, gchar * filter_file)
-{
+{typedef struct _filter {
+ gint group;
+ gchar *name;
+ filter_match_type type;
+ filter_when_type match_when;
+ guint flags;
+
+ /* The match type fields */
+ union _match {
+ gchar string[1024]; /* for FILTER_SIMPLE */
+ gchar command[1024]; /* for FILTER_EXEC */
+ } match;
+ guint match_fields; /* for FILTER_SIMPLE filters */
+
+ /* The notification fields */
+ gchar sound[PATH_MAX];
+ gchar popup_text[256];
+
+ /* The action */
+ filter_action_type action;
+ gchar action_string[PATH_MAX];
+
+ /* other options I haven't thought of yet */
+
+ /* the regex list */
+ GList *regex;
+} filter;
return 0;
}
--- filter-funcs.c Fri Oct 6 17:50:50 2000
+++ filter-funcs.c.corr Fri Jun 22 08:48:24 2001
@@ -158,6 +158,7 @@
return (NULL);
}
+ newfil->name=NULL;
newfil->type = FILTER_NONE;
newfil->flags = FILTER_EMPTY;
newfil->match_fields = FILTER_EMPTY;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]