Update version number and copyright year.
[exim.git] / src / src / lookups / lf_quote.c
CommitLineData
184e8823 1/* $Cambridge: exim/src/src/lookups/lf_quote.c,v 1.4 2007/01/08 10:50:19 ph10 Exp $ */
0756eb3c
PH
2
3/*************************************************
4* Exim - an Internet mail transport agent *
5*************************************************/
6
184e8823 7/* Copyright (c) University of Cambridge 1995 - 2007 */
0756eb3c
PH
8/* See the file NOTICE for conditions of use and distribution. */
9
10
11#include "../exim.h"
12#include "lf_functions.h"
13
14
15/*************************************************
16* Add string to result, quoting if necessary *
17*************************************************/
18
19/* This function is called by some lookups that create name=value result
20strings, to handle the quoting of the data. It adds "name=" to the result,
21followed by appropriately quoted data, followed by a single space.
22
23Arguments:
24 name the field name
25 value the data value
26 vlength the data length
27 result the result pointer
28 asize points to the size variable
29 aoffset points to the offset variable
30
31Returns: the result pointer (possibly updated)
32*/
33
34uschar *
35lf_quote(uschar *name, uschar *value, int vlength, uschar *result, int *asize,
36 int *aoffset)
37{
38result = string_append(result, asize, aoffset, 2, name, US"=");
39
40/* NULL is handled as an empty string */
41
42if (value == NULL) value = US"";
43
44/* Quote the value if it is empty, contains white space, or starts with a quote
45character. */
46
47if (value[0] == 0 || Ustrpbrk(value, " \t\n\r") != NULL || value[0] == '\"')
48 {
49 int j;
50 result = string_cat(result, asize, aoffset, US"\"", 1);
51 for (j = 0; j < vlength; j++)
52 {
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);
56 }
57 result = string_cat(result, asize, aoffset, US"\"", 1);
58 }
59else
60 {
61 result = string_cat(result, asize, aoffset, US value, vlength);
62 }
63
64return string_cat(result, asize, aoffset, US" ", 1);
65}
66
67/* End of lf_quote.c */