1 /* $Cambridge: exim/src/src/lookups/lf_quote.c,v 1.1 2004/10/07 13:10:01 ph10 Exp $ */
3 /*************************************************
4 * Exim - an Internet mail transport agent *
5 *************************************************/
7 /* Copyright (c) University of Cambridge 1995 - 2004 */
8 /* See the file NOTICE for conditions of use and distribution. */
12 #include "lf_functions.h"
15 /*************************************************
16 * Add string to result, quoting if necessary *
17 *************************************************/
19 /* This function is called by some lookups that create name=value result
20 strings, to handle the quoting of the data. It adds "name=" to the result,
21 followed by appropriately quoted data, followed by a single space.
26 vlength the data length
27 result the result pointer
28 asize points to the size variable
29 aoffset points to the offset variable
31 Returns: the result pointer (possibly updated)
35 lf_quote(uschar *name, uschar *value, int vlength, uschar *result, int *asize,
38 result = string_append(result, asize, aoffset, 2, name, US"=");
40 /* NULL is handled as an empty string */
42 if (value == NULL) value = US"";
44 /* Quote the value if it is empty, contains white space, or starts with a quote
47 if (value[0] == 0 || Ustrpbrk(value, " \t\n\r") != NULL || value[0] == '\"')
50 result = string_cat(result, asize, aoffset, US"\"", 1);
51 for (j = 0; j < vlength; j++)
53 if (value[j] == '\"' || value[j] == '\\')
54 result = string_cat(result, asize, aoffset, US"\\", 1);
55 result = string_cat(result, asize, aoffset, US value+j, 1);
57 result = string_cat(result, asize, aoffset, US"\"", 1);
61 result = string_cat(result, asize, aoffset, US value, vlength);
64 return string_cat(result, asize, aoffset, US" ", 1);
67 /* End of lf_quote.c */