WIP: pth, cleanup, transistion mostly done
[rxpd] / src / rxpd_rule.c
index 287774224cc1e964c6daef6c30592691318313ba..f59ed0ec3688967cba03560f20ed6aa636a19488 100644 (file)
@@ -31,33 +31,49 @@ rxpd_rule_new (const char* buf)
   if (*buf != '#')
     {
       int err;
-      char* rxstart = strchr (buf, ':');
+      char* namestart = strchr (buf, ':');
+      char* rxstart = namestart? strchr (namestart+1, ':') : NULL;
 
       if (!rxstart)
         self->string = rxpd_strdup ("#ERROR: Syntax error, line was neither a comment nor a rule");
       else
         {
+          if (namestart == buf)
+            /* No atime given */
+            self->atime = (time_t)-1;
+          else
+            {
+              /* atime given */
+              self->atime = atoi (buf);
+              if (!self->atime)
+                /* atime was zero or not set */
+                self->atime = time (NULL)-1;
+            }
+
           // TODO regflags from base
           err = regcomp (&self->rx, rxstart+1, REG_EXTENDED|REG_ICASE|REG_NOSUB);
 
           if (!err)
-            self->string = rxpd_strdup (buf);
+            self->string = rxpd_strdup (namestart+1);
           else
             {
               regfree (&self->rx);
               char ebuf[256];
               size_t len = regerror (err, NULL, ebuf, 256);
-              self->string = rxpd_malloc (len + strlen(buf) + 14);
+              self->string = rxpd_malloc (len + strlen(namestart+1) + 14);
               strcpy (self->string, "#ERROR: ");
               strcat (self->string, ebuf);
               strcat (self->string, " in '");
-              strcat (self->string, buf);
+              strcat (self->string, namestart+1);
               strcat (self->string, "'");
             }
         }
     }
   else
-    self->string = rxpd_strdup (buf);
+    {
+      self->atime = (time_t)-1;
+      self->string = rxpd_strdup (buf);
+    }
 
   return self;
 }