Index: trunk/src/sh_fifo.c
===================================================================
--- trunk/src/sh_fifo.c	(revision 582)
+++ trunk/src/sh_fifo.c	(revision 1)
@@ -32,7 +32,4 @@
 #include "sh_mem.h"
 #include "sh_unix.h"
-#include "sh_utils.h"
-#include "sh_string.h"
-#include "sh_fifo.h"
 
 #if defined(HAVE_MLOCK) && !defined(HAVE_BROKEN_MLOCK)
@@ -40,159 +37,23 @@
 #endif
 
-#define SH_FIFO_TAGGED 1
-#define SH_FIFO_M_FAIL 2
-#define SH_FIFO_MARKED 4
-
-/* Prepare an email message and return it. Iterate over list on stack and
- * check for each if it is valid for recipient 'tag'. If yes, add to the
- * returned string.
- * okNull == False means that item->s_xtra must be defined
- */
-sh_string * tag_list (SH_FIFO * fifo, char * tag,
-		      int(*valid)(int, const char*, const char*, const void*),
-		      const void * info, int okNull)
-{
-  struct dlist * item;
-  sh_string * result = NULL;
-
-  if (fifo && fifo->fifo_cts > 0)
-    {
-      item = fifo->head_ptr;
-
-      while (item)
-	{
-	  /* Same recipient, or no recipient ( := all )
-	   */
-	  if ( (tag && item->s_xtra && 0 == strcmp(item->s_xtra, tag)) ||
-	       ((okNull == S_TRUE) && !(item->s_xtra)) )
-	    {
-	      if (valid == NULL)
-		{
-		  item->transact |= SH_FIFO_TAGGED;
-		}
-	      else
-		{
-		  /* level, message, recipient, list */
-		  if (!valid(item->i_xtra, item->data, tag, info))
-		    goto skipped;
-		  item->transact |= SH_FIFO_TAGGED;
-		}
-	      if (!result)
-		{
-		  result = sh_string_new_from_lchar(item->data, strlen(item->data));
-		}
-	      else
-		{
-		  result = sh_string_cat_lchar(result, "\r\n", 2);
-		  result = sh_string_add_from_char(result, item->data);
-		}
-	    }
-	skipped:
-	  item = item->next;
-	}
-    }
-  return result;
-}
-
-void rollback_list (SH_FIFO * fifo)
-{
-  struct dlist * item;
-
-  if (fifo && fifo->fifo_cts > 0)
-    {
-      item = fifo->head_ptr;
-
-      while (item && 0 != (item->transact & SH_FIFO_TAGGED))
-	{
-	  item->transact |= SH_FIFO_M_FAIL;
-	  item = item->next;
-	}
-    }
-}
-
-void mark_list (SH_FIFO * fifo)
-{
-  struct dlist * item;
-
-  if (fifo && fifo->fifo_cts > 0)
-    {
-      item = fifo->head_ptr;
-
-      while (item && 0 != (item->transact & SH_FIFO_TAGGED))
-	{
-	  item->transact |= SH_FIFO_MARKED;
-	  item = item->next;
-	}
-    }
-}
-
-void reset_list (SH_FIFO * fifo)
-{
-  struct dlist * item;
-
-  if (fifo && fifo->fifo_cts > 0)
-    {
-      item = fifo->head_ptr;
-
-      while (item)
-	{
-	  item->transact = 0;
-	  item = item->next;
-	}
-    }
-}
-
-int commit_list (SH_FIFO * fifo)
-{
-  struct dlist * item;
-  struct dlist * getit;
-  int    retval = 0;
-
-  if (fifo && fifo->fifo_cts > 0)
-    {
-      item = fifo->head_ptr;
-
-      while (item)
-	{
-	  getit = NULL;
-
-	  if ( 0 != (item->transact & SH_FIFO_MARKED) && /* sent              */
-	       0 == (item->transact & SH_FIFO_M_FAIL) )  /* no recipient fail */
-	    {
-	      if (item == fifo->head_ptr)
-		fifo->head_ptr   = item->next;
-	      if (item == fifo->tail_ptr)
-		fifo->tail_ptr   = item->prev;
-	      if (item->prev)
-		item->prev->next = item->next;
-	      if (item->next)
-		item->next->prev = item->prev;
-	      --(fifo->fifo_cts);
-	      getit = item;
-	    }
-	  item  = item->next;
-
-	  /* Delete it
-	   */
-	  if (getit)
-	    {
-	      size_t len = sl_strlen(getit->data);
-	      memset(getit->data, 0, len);
-	      if (NULL != sl_strstr (getit->data, _("LOGKEY")))
-		MUNLOCK(getit->data, (len+1));
-	      if (getit->s_xtra)
-		SH_FREE(getit->s_xtra);
-	      SH_FREE(getit->data);
-	      SH_FREE(getit);
-	      ++retval;
-	    }
-	}
-    }
-  return retval;
-}
+#define SH_FIFO_MAX 128
+
+struct dlist {
+  /*@null@*//*@dependent@*/ struct dlist * next;
+  char         * data;
+  /*@null@*//*@dependent@*/ struct dlist * prev;
+};
+
+typedef struct fifo_str {
+  /*@null@*//*@dependent@*/ struct dlist * head_ptr;
+  /*@null@*//*@dependent@*/ struct dlist * tail_ptr;
+  int            fifo_cts;
+} SH_FIFO;
+
+
 
 /* push an item on the head of the list
  */
-int push_list (SH_FIFO * fifo, const char * indat, int in_i, const char * in_str)
+int push_list (SH_FIFO * fifo, char * indat)
 {
   struct dlist * item;
@@ -218,18 +79,14 @@
     }
   item            = SH_ALLOC(sizeof(struct dlist));
-  item->data      = SH_ALLOC(len+1);
+  /*@i@*/ item->data      = SH_ALLOC(len+1);
   
   if (NULL != sl_strstr (indat, _("LOGKEY")))
-    MLOCK(item->data, (len+1));
-
-  sl_strlcpy (item->data, indat, len+1);
+    {
+      MLOCK(item->data, (len+1));
+      ;
+    }
+
+  strcpy (item->data, indat);                   /* known to fit  */
   item->data[len] = '\0';
-
-  item->i_xtra = in_i;
-  if (in_str)
-    item->s_xtra = sh_util_strdup(in_str);
-  else
-    item->s_xtra = NULL;
-  item->transact = 0;
 
   if (fifo->tail_ptr == NULL)
@@ -240,5 +97,5 @@
   else
     {
-      fifo->head_ptr->prev = item;
+      /*@i@*/ fifo->head_ptr->prev = item;
       item->prev           = NULL;
     }
@@ -254,5 +111,5 @@
 /* push an item on the tail of the list
  */
-int push_tail_list (SH_FIFO * fifo, const char * indat, int in_i, const char * in_str)
+int push_tail_list (SH_FIFO * fifo, char * indat)
 {
   struct dlist * item;
@@ -278,18 +135,14 @@
 
   item            = SH_ALLOC(sizeof(struct dlist));
-  item->data      = SH_ALLOC(len+1);
+  /*@i@*/item->data      = SH_ALLOC(len+1);
 
   if (NULL != sl_strstr (indat, _("LOGKEY")))
-    MLOCK(item->data, (len+1));
-
-  sl_strlcpy (item->data, indat, len+1);
+    {
+      MLOCK(item->data, (len+1));
+      ;
+    }
+
+  strcpy (item->data, indat);                          /* known to fit  */
   item->data[len] = '\0';
-
-  item->i_xtra = in_i;
-  if (in_str)
-    item->s_xtra = sh_util_strdup(in_str);
-  else
-    item->s_xtra = NULL;
-  item->transact = 0;
 
   if (fifo->head_ptr == NULL)
@@ -309,5 +162,5 @@
   ++(fifo->fifo_cts);
 
-  SL_RETURN((fifo->fifo_cts), _("push_tail_list"));
+  SL_RETURN((0), _("push_tail_list"));
 }
 
@@ -342,13 +195,15 @@
   len         = sl_strlen(getit->data);
   retval      = SH_ALLOC(len+1);
-  sl_strlcpy (retval, getit->data, len+1);
+  strcpy (retval, getit->data);                        /* known to fit  */
+  retval[len] = '\0';
  
   memset(getit->data, 0, len);
 
   if (NULL != sl_strstr (retval, _("LOGKEY")))
-    MUNLOCK(getit->data, (len+1));
-
-  if (getit->s_xtra)
-    SH_FREE(getit->s_xtra);
+    {
+      MUNLOCK(getit->data, (len+1));
+      ;
+    }
+
   SH_FREE(getit->data);
   SH_FREE(getit);
@@ -360,82 +215,4 @@
 
 
-#ifdef SH_CUTEST
-#include "CuTest.h"
-
-void Test_fifo (CuTest *tc) {
-
-  SH_FIFO ff;
-  int ret;
-  char * p;
-
-  fifo_init(&ff);
-
-  p = sh_fifo_pop(&ff);
-  CuAssertPtrEquals(tc, NULL, p);
-
-  /* first sequence */
-  ret = sh_fifo_push(&ff, "one");
-  CuAssertIntEquals(tc,1,ret);
-  ret = sh_fifo_push(&ff, "two");
-  CuAssertIntEquals(tc,2,ret);
-  ret = sh_fifo_push(&ff, "three");
-  CuAssertIntEquals(tc,3,ret);
-
-  p = sh_fifo_pop(&ff);
-  CuAssertPtrNotNull(tc, p);
-  CuAssertStrEquals(tc,"one", p);
-  p = sh_fifo_pop(&ff);
-  CuAssertPtrNotNull(tc, p);
-  CuAssertStrEquals(tc,"two", p);
-  p = sh_fifo_pop(&ff);
-  CuAssertPtrNotNull(tc, p);
-  CuAssertStrEquals(tc,"three", p);
-  p = sh_fifo_pop(&ff);
-  CuAssertPtrEquals(tc, NULL, p);
-
-  /* second sequence */
-  ret = sh_fifo_push(&ff, "one");
-  CuAssertIntEquals(tc,1,ret);
-  p = sh_fifo_pop(&ff);
-  CuAssertPtrNotNull(tc, p);
-  CuAssertStrEquals(tc,"one", p);
-  ret = sh_fifo_push_tail(&ff, "one");
-  CuAssertIntEquals(tc,1,ret);
-  p = sh_fifo_pop(&ff);
-  CuAssertPtrNotNull(tc, p);
-  CuAssertStrEquals(tc,"one", p);
-  p = sh_fifo_pop(&ff);
-  CuAssertPtrEquals(tc, NULL, p);
-
-  /* third sequence */
-  ret = sh_fifo_push(&ff, "one");
-  CuAssertIntEquals(tc,1,ret);
-  ret = sh_fifo_push(&ff, "two");
-  CuAssertIntEquals(tc,2,ret);
-  ret = sh_fifo_push(&ff, "three");
-  CuAssertIntEquals(tc,3,ret);
-
-  p = sh_fifo_pop(&ff);
-  CuAssertPtrNotNull(tc, p);
-  CuAssertStrEquals(tc,"one", p);
-  ret = sh_fifo_push_tail(&ff, p);
-  CuAssertIntEquals(tc,3,ret);
-
-  p = sh_fifo_pop(&ff);
-  CuAssertPtrNotNull(tc, p);
-  CuAssertStrEquals(tc,"one", p);
-  p = sh_fifo_pop(&ff);
-  CuAssertPtrNotNull(tc, p);
-  CuAssertStrEquals(tc,"two", p);
-  p = sh_fifo_pop(&ff);
-  CuAssertPtrNotNull(tc, p);
-  CuAssertStrEquals(tc,"three", p);
-  p = sh_fifo_pop(&ff);
-  CuAssertPtrEquals(tc, NULL, p);
-}
-
-#endif
-
-
-
-
+
+
