1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* Copyright (c) University of Cambridge 1995 - 2009 */
6 /* See the file NOTICE for conditions of use and distribution. */
10 #include "lf_functions.h"
13 /*************************************************
14 * Add string to result, quoting if necessary *
15 *************************************************/
17 /* This function is called by some lookups that create name=value result
18 strings, to handle the quoting of the data. It adds "name=" to the result,
19 followed by appropriately quoted data, followed by a single space.
24 vlength the data length
25 result the result pointer
26 asize points to the size variable
27 aoffset points to the offset variable
29 Returns: the result pointer (possibly updated)
33 lf_quote(uschar *name, uschar *value, int vlength, uschar *result, int *asize,
36 result = string_append(result, asize, aoffset, 2, name, US"=");
38 /* NULL is handled as an empty string */
40 if (value == NULL) value = US"";
42 /* Quote the value if it is empty, contains white space, or starts with a quote
45 if (value[0] == 0 || Ustrpbrk(value, " \t\n\r") != NULL || value[0] == '\"')
48 result = string_cat(result, asize, aoffset, US"\"", 1);
49 for (j = 0; j < vlength; j++)
51 if (value[j] == '\"' || value[j] == '\\')
52 result = string_cat(result, asize, aoffset, US"\\", 1);
53 result = string_cat(result, asize, aoffset, US value+j, 1);
55 result = string_cat(result, asize, aoffset, US"\"", 1);
59 result = string_cat(result, asize, aoffset, US value, vlength);
62 return string_cat(result, asize, aoffset, US" ", 1);
65 /* End of lf_quote.c */