[Commits] clamav_plugin.c 1.1.2.5 1.1.2.6 clamav_plugin_gtk.c 1.1.2.7 1.1.2.8

miras at claws-mail.org miras at claws-mail.org
Sun Dec 16 13:29:10 CET 2012


Update of /home/claws-mail/plugins/clamd/src
In directory srv:/tmp/cvs-serv9358/src

Modified Files:
      Tag: gtk2
	clamav_plugin.c clamav_plugin_gtk.c 
Log Message:
2012-12-16 [michael]	3.5.5cvs2

	* libclamd/clamd-plugin.c
	* src/clamav_plugin.c
	* src/clamav_plugin_gtk.c
	    Fix bug 2838. Numerous changes made due to
	    plugin in special cases could be activated
	    with an incomplete configuration. 

Index: clamav_plugin_gtk.c
===================================================================
RCS file: /home/claws-mail/plugins/clamd/src/Attic/clamav_plugin_gtk.c,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -u -d -r1.1.2.7 -r1.1.2.8
--- clamav_plugin_gtk.c	6 Jan 2012 14:20:39 -0000	1.1.2.7
+++ clamav_plugin_gtk.c	16 Dec 2012 12:29:07 -0000	1.1.2.8
@@ -131,17 +131,19 @@
 }
 
 static void clamav_show_config(Config* config) {
-	if (config->ConfigType == MANUAL) {
-		gtk_widget_hide(hbox_auto1);
-		gtk_widget_hide(hbox_auto2);
-		gtk_widget_show(hbox_manual1);
-		gtk_widget_show(hbox_manual2);
-	}
-	else {
-		gtk_widget_hide(hbox_manual1);
-		gtk_widget_hide(hbox_manual2);
-		gtk_widget_show(hbox_auto1);
-		gtk_widget_show(hbox_auto2);
+	if (config) {
+		if (config->ConfigType == MANUAL) {
+			gtk_widget_hide(hbox_auto1);
+			gtk_widget_hide(hbox_auto2);
+			gtk_widget_show(hbox_manual1);
+			gtk_widget_show(hbox_manual2);
+		}
+		else {
+			gtk_widget_hide(hbox_manual1);
+			gtk_widget_hide(hbox_manual2);
+			gtk_widget_show(hbox_auto1);
+			gtk_widget_show(hbox_auto2);
+		}
 	}
 }
 
@@ -150,45 +152,58 @@
 	struct ClamAvPage *page = (struct ClamAvPage *) data;
 	Config* c;
 	gint newpos = 0;
+	gboolean tmp_conf = FALSE;
 
-	/* Reset configuration */
-	debug_print("Resetting configuration\n");
-	gtk_editable_delete_text(GTK_EDITABLE(page->config_folder), 0, -1);
-	gtk_editable_delete_text(GTK_EDITABLE(page->config_host), 0, -1);
-	gtk_editable_delete_text(GTK_EDITABLE(page->config_port), 0, -1);
-	clamav_save_config();
-
-	c = clamd_config_new();
-	if (state) {
-		/* Automatic configuration */
-		debug_print("Setting clamd to automatic configuration\n");
-		if (clamd_find_socket()) {
-			clamd_config_free(c);
-			c = clamd_get_config();
-			if (c->ConfigType == AUTOMATIC) {
-				gtk_editable_insert_text(GTK_EDITABLE(page->config_folder),
-					c->automatic.folder, strlen(c->automatic.folder), &newpos);
-				clamav_save_config();
-			}
+	if (page && page->page.widget) {
+		/* Reset configuration */
+		debug_print("Resetting configuration\n");
+		gtk_editable_delete_text(GTK_EDITABLE(page->config_folder), 0, -1);
+		gtk_editable_delete_text(GTK_EDITABLE(page->config_host), 0, -1);
+		gtk_editable_delete_text(GTK_EDITABLE(page->config_port), 0, -1);
+		clamav_save_config();
+	
+		c = clamd_get_config();
+		if (!c) {
 			c = clamd_config_new();
+			tmp_conf = TRUE;
 		}
-		c->ConfigType = AUTOMATIC;
-		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->config_type), TRUE);
-	}
-	else {
-		/* Manual configuration */
-		debug_print("Setting clamd to manual configuration\n");
-		c->ConfigType = MANUAL;
-		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->config_type), FALSE);
+		if (state) {
+			/* Automatic configuration */
+			debug_print("Setting clamd to automatic configuration\n");
+			if (clamd_find_socket()) {
+				if (tmp_conf) {
+					Config* clamd_conf = clamd_get_config();
+					if (clamd_conf->automatic.folder)
+						c->automatic.folder = g_strdup(clamd_conf->automatic.folder);
+					else
+						c->automatic.folder = g_strdup("");
+				}
+				if (c->ConfigType == AUTOMATIC) {
+					gtk_editable_insert_text(GTK_EDITABLE(page->config_folder),
+						c->automatic.folder, strlen(c->automatic.folder), &newpos);
+					clamav_save_config();
+				}
+			}
+			c->ConfigType = AUTOMATIC;
+			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->config_type), TRUE);
+		}
+		else {
+			/* Manual configuration */
+			debug_print("Setting clamd to manual configuration\n");
+			c->ConfigType = MANUAL;
+			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->config_type), FALSE);
+		}
+		clamav_show_config(c);
+		if (tmp_conf)
+			clamd_config_free(c);
 	}
-	clamav_show_config(c);
-	clamd_config_free(c);
 }
 
 static void clamav_create_widget_func(PrefsPage * _page, GtkWindow *window, gpointer data)
 {
 	struct ClamAvPage *page = (struct ClamAvPage *) _page;
 	ClamAvConfig *config;
+	Config		 *clamd_config;
  	 
 	GtkWidget *vbox1, *vbox2;
 	GtkWidget *enable_clamav;
@@ -215,6 +230,7 @@
 	GtkTooltips *tooltips;
 
 	tooltips = gtk_tooltips_new();
+	enable_clamav = page->enable_clamav;
 
 	vbox1 = gtk_vbox_new (FALSE, VSPACING);
 	gtk_widget_show (vbox1);
@@ -400,35 +416,61 @@
 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(recv_infected), config->clamav_recv_infected);
 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(setting_type), config->clamd_config_type);
 
-	Config* c = clamd_get_config();
+	clamd_config = clamd_get_config();
+		
 	if (config->clamav_save_folder != NULL)
 		gtk_entry_set_text(GTK_ENTRY(save_folder), config->clamav_save_folder);
-	if (config->clamd_host && strlen(config->clamd_host) > 0 && config->clamd_port > 0) {
+	if (!config->clamd_config_type) {
+	/*if (config->clamd_host && strlen(config->clamd_host) > 0 && config->clamd_port > 0) {*/
 		gtk_entry_set_text(GTK_ENTRY(config_host), config->clamd_host);
 		gchar* s = int2char(config->clamd_port);
 		gtk_entry_set_text(GTK_ENTRY(config_port), s);
 		g_free(s);
 		/* activate manual checkbox and blind folder */
 		debug_print("Showing manual configuration and hiding automatic configuration\n");
-		clamav_show_config(c);
+		if (! clamd_config) {
+			clamd_config = clamd_config_new();
+			clamd_config->ConfigType = MANUAL;
+			clamav_show_config(clamd_config);
+			clamd_config_free(clamd_config);
+		}
+		else
+			clamav_show_config(clamd_config);
 	}
-	else if (config->clamd_config_folder == NULL || strlen(config->clamd_config_folder) == 0) {
+	else {
+	//else if (config->clamd_config_folder == NULL || strlen(config->clamd_config_folder) == 0) {
 		if (clamd_find_socket()) {
 			Config* c = clamd_get_config();
-			if (c->ConfigType == AUTOMATIC) {
-				config->clamd_config_folder = c->automatic.folder;
+			if (c && c->ConfigType == AUTOMATIC) {
+				config->clamd_config_folder = g_strdup(c->automatic.folder);
 				/* deactivate manual checkbox and blind host and port */
 				debug_print("Showing automatic configuration and hiding manual configuration\n");
 				clamav_show_config(c);
+				gint newpos = 0;
+				gtk_editable_delete_text(GTK_EDITABLE(config_folder), 0, -1);
+				gtk_editable_insert_text(GTK_EDITABLE(config_folder), 
+					config->clamd_config_folder, strlen(config->clamd_config_folder), &newpos);
+			}
+			else if (c && c->ConfigType == MANUAL) {
+				/* deactivate automatic automatic configuration */
+				debug_print("Showing manual configuration and hiding automatic configuration\n");
+				clamav_show_config(c);
 			}
 		}
 	}
-	else {
+/*	else {
 		gtk_entry_set_text(GTK_ENTRY(config_folder), config->clamd_config_folder);
-		/* deactivate manual checkbox and blind host and port */
+		// deactivate manual checkbox and blind host and port
 		debug_print("Showing automatic configuration and hiding manual configuration\n");
-		clamav_show_config(c);
-	}
+		if (! clamd_config) {
+			clamd_config = clamd_config_new();
+			clamd_config->ConfigType = AUTOMATIC;
+			clamav_show_config(clamd_config);
+			clamd_config_free(clamd_config);
+		}
+		else
+			clamav_show_config(clamd_config);
+	}*/
 
 	page->enable_clamav = enable_clamav;
 /*	page->enable_arc = enable_arc;*/
@@ -440,6 +482,8 @@
 	page->config_host = config_host;
 	page->config_port = config_port;
 	page->page.widget = vbox1;
+	
+	clamav_save_config();
 }
 
 static void clamav_destroy_widget_func(PrefsPage *_page)

Index: clamav_plugin.c
===================================================================
RCS file: /home/claws-mail/plugins/clamd/src/Attic/clamav_plugin.c,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -u -d -r1.1.2.5 -r1.1.2.6
--- clamav_plugin.c	3 Oct 2010 14:50:49 -0000	1.1.2.5
+++ clamav_plugin.c	16 Dec 2012 12:29:07 -0000	1.1.2.6
@@ -174,17 +174,26 @@
 
 Clamd_Stat clamd_prepare(void) {
 	debug_print("Creating socket\n");
-	if (config.clamd_host != NULL && config.clamd_port > 0) {
+	if (!config.clamd_config_type || (config.clamd_host != NULL && config.clamd_port > 0)) {
+		if (config.clamd_host == NULL || config.clamd_port < 1) {
+			/* error */
+			return NO_SOCKET;
+		}
 		/* Manual configuration has highest priority */
 		debug_print("Using user input: %s:%d\n",
 			config.clamd_host, config.clamd_port);
 		clamd_create_config_manual(config.clamd_host, config.clamd_port);
 	}
-	else if (config.clamd_config_folder != NULL) {
+	else if (config.clamd_config_type || config.clamd_config_folder != NULL) {
+		if (config.clamd_config_folder == NULL) {
+			/* error */
+			return NO_SOCKET;
+		}
 		debug_print("Using clamd.conf: %s\n", config.clamd_config_folder);
 		clamd_create_config_automatic(config.clamd_config_folder);
 	}
 	else {
+		/* Fall back. Try enable anyway */
 		if (! clamd_find_socket())
 			return NO_SOCKET;
 	}



More information about the Commits mailing list