Merge branch 'list_safety'
[exim.git] / src / src / header.c
index 2cac551c686e30913e7b6fcb84bc9a1c6a81777e..8136c69fe507b7c2e1a98c4cd973175e6a368a81 100644 (file)
@@ -1,10 +1,8 @@
-/* $Cambridge: exim/src/src/header.c,v 1.1 2004/10/07 10:39:01 ph10 Exp $ */
-
 /*************************************************
 *     Exim - an Internet mail transport agent    *
 *************************************************/
 
-/* Copyright (c) University of Cambridge 1995 - 2004 */
+/* Copyright (c) University of Cambridge 1995 - 2009 */
 /* See the file NOTICE for conditions of use and distribution. */
 
 
@@ -30,7 +28,7 @@ Returns:    TRUE or FALSE
 */
 
 BOOL
-header_testname(header_line *h, uschar *name, int len, BOOL notdel)
+header_testname(header_line *h, const uschar *name, int len, BOOL notdel)
 {
 uschar *tt;
 if (h->type == '*' && notdel) return FALSE;
@@ -40,6 +38,19 @@ while (*tt == ' ' || *tt == '\t') tt++;
 return *tt == ':';
 }
 
+/* This is a copy of the function above, only that it is possible to pass
+   only the beginning of a header name. It simply does a front-anchored
+   substring match. Arguments and Return codes are the same as for
+   header_testname() above. */
+
+BOOL
+header_testname_incomplete(header_line *h, const uschar *name,
+    int len, BOOL notdel)
+{
+if (h->type == '*' && notdel) return FALSE;
+if (h->text == NULL || strncmpic(h->text, name, len) != 0) return FALSE;
+return TRUE;
+}
 
 
 /*************************************************
@@ -80,7 +91,7 @@ Returns:    nothing
 
 static void
 header_add_backend(BOOL after, uschar *name, BOOL topnot, int type,
-  char *format, va_list ap)
+  const char *format, va_list ap)
 {
 header_line *h, *new;
 header_line **hptr;
@@ -106,7 +117,14 @@ if (name == NULL)
   else
     {
     hptr = &header_list;
-    h = header_list;
+
+    /* header_list->text can be NULL if we get here between when the new
+    received header is allocated and when it is acutally filled in. We want
+    that header to be first, so skip it for now. */
+
+    if (header_list->text == NULL)
+      hptr = &header_list->next;
+    h = *hptr;
     }
   }
 
@@ -194,7 +212,7 @@ Returns:    nothing
 
 void
 header_add_at_position(BOOL after, uschar *name, BOOL topnot, int type,
-  char *format, ...)
+  const char *format, ...)
 {
 va_list ap;
 va_start(ap, format);
@@ -219,7 +237,7 @@ Returns:    nothing
 */
 
 void
-header_add(int type, char *format, ...)
+header_add(int type, const char *format, ...)
 {
 va_list ap;
 va_start(ap, format);
@@ -245,7 +263,7 @@ Returns:        nothing
 */
 
 void
-header_remove(int occ, uschar *name)
+header_remove(int occ, const uschar *name)
 {
 header_line *h;
 int hcount = 0;