'#EXIT:' and empty line handling for REPLACE and REMOVE
authorChristian Thaeter <ct@pipapo.org>
Thu, 25 Oct 2007 01:40:13 +0000 (03:40 +0200)
committerChristian Thaeter <ct@pipapo.org>
Thu, 25 Oct 2007 01:40:13 +0000 (03:40 +0200)
src/rxpd_connection_cmd.c

index 62649b5..becc429 100644 (file)
@@ -131,22 +131,27 @@ rxpd_connection_cmd_REMOVE (struct rxpd_connection* self)
   char* line;
   while ((line = rxpd_buffer_readline (&self->in)))
     {
-      pth_rwlock_acquire (&self->file->lock, PTH_RWLOCK_RW, FALSE, NULL);
-      LLIST_FOREACH (&self->file->rules, n)
+      if (*line && strncmp (line, "#EXIT:", sizeof ("#EXIT:")-1))
         {
-          struct rxpd_rule* rule = (struct rxpd_rule*)n;
-          if (strcmp (rule->string, line) == 0)
+          pth_rwlock_acquire (&self->file->lock, PTH_RWLOCK_RW, FALSE, NULL);
+          LLIST_FOREACH (&self->file->rules, n)
             {
-              LList tmp = llist_prev (n);
-              rxpd_rule_delete (rule);
-              n = tmp;
-              rxpd_buffer_printf (&self->out, "#OK:\n");
-              goto done;
+              struct rxpd_rule* rule = (struct rxpd_rule*)n;
+              if (strcmp (rule->string, line) == 0)
+                {
+                  LList tmp = llist_prev (n);
+                  rxpd_rule_delete (rule);
+                  n = tmp;
+                  rxpd_buffer_printf (&self->out, "#OK:\n");
+                  goto done;
+                }
             }
+          rxpd_buffer_printf (&self->out, "#ERROR: line not found\n");
+        done:
+          pth_rwlock_release (&self->file->lock);
         }
-      rxpd_buffer_printf (&self->out, "#ERROR: line not found\n");
-    done:
-      pth_rwlock_release (&self->file->lock);
+      else
+        break;  /* exit at empty line, error or whatever */
     }
 
   if (rxpd_buffer_state (&self->in) == RXPD_ERROR)
@@ -191,21 +196,22 @@ rxpd_connection_cmd_REPLACE (struct rxpd_connection* self)
   char* line;
   while ((line = rxpd_buffer_readline (&self->in)))
     {
-      if (self->tmp_str)
+      if (*line && strncmp (line, "#EXIT:", sizeof ("#EXIT:")-1))
         {
-          if (*line)
+          if (self->tmp_str)
             {
               struct rxpd_rule* rule;
               rule = rxpd_rule_new (line);
-              if (!rule)
-                abort();
-
-              llist_insert_tail (&self->tmp_list, &rule->node);
+              if (rule)
+                llist_insert_tail (&self->tmp_list, &rule->node);
+              else
+                rxpd_buffer_printf (&self->out, "#ERROR: illegal rule '%s'\n", line);
             }
-          /* TODO handle empty lines? */
+          else
+            self->tmp_str = rxpd_strdup (line);
         }
       else
-        self->tmp_str = rxpd_strdup (line);
+        break;  /* exit at empty line, error or whatever */
     }
 
   pth_rwlock_release (&self->file->lock);