Factor out newer_privoxy_version_required() and improve the logic
authorFabian Keil <fk@fabiankeil.de>
Sat, 4 Jan 2025 05:48:04 +0000 (06:48 +0100)
committerFabian Keil <fk@fabiankeil.de>
Sun, 5 Jan 2025 07:45:58 +0000 (08:45 +0100)
Previously 3.0.11 was considered newer than 4.0.0.

actions.c

index 9fd3249..00c38b6 100644 (file)
--- a/actions.c
+++ b/actions.c
@@ -1210,6 +1210,45 @@ static int action_spec_is_valid(struct client_state *csp, const struct action_sp
 }
 
 
+/*********************************************************************
+ *
+ * Function    :  newer_privoxy_version_required
+ *
+ * Description :  Figures out whether or not an action file requires
+ *                a more recent Privoxy version.
+ *
+ * Parameters  :
+ *          1  :  required_major = Required major version.
+ *          2  :  required_minor = Required minor version, or NULL.
+ *          3  :  required_point = Required point release, or NULL.
+ *
+ * Returns     :  1 => Yes, 0 => No.
+ *
+ *********************************************************************/
+static int newer_privoxy_version_required(const char *required_major,
+   const char *required_minor, const char *required_point)
+{
+   if (atoi(required_major) > VERSION_MAJOR)
+   {
+      return 1;
+   }
+   if (atoi(required_major) < VERSION_MAJOR)
+   {
+      return 0;
+   }
+   if ((required_minor == NULL) || (atoi(required_minor) < VERSION_MINOR))
+   {
+      return 0;
+   }
+   if ((required_point == NULL) || (atoi(required_point) <= VERSION_POINT))
+   {
+      return 0;
+   }
+
+   return 1;
+}
+
+
 /*********************************************************************
  *
  * Function    :  load_one_actions_file
@@ -1489,9 +1528,7 @@ int load_one_actions_file(struct client_state *csp, int fileid)
                  "While loading actions file '%s': invalid line (%lu): %s",
                   csp->config->actions_file[fileid], linenum, buf);
             }
-            else if (                  (atoi(fields[0]) > VERSION_MAJOR)
-               || ((num_fields > 1) && (atoi(fields[1]) > VERSION_MINOR))
-               || ((num_fields > 2) && (atoi(fields[2]) > VERSION_POINT)))
+            else if (newer_privoxy_version_required(fields[0], fields[1], fields[2]))
             {
                fclose(fp);
                log_error(LOG_LEVEL_FATAL,