1 /******************************************************************************/
2 /* pfixtools: a collection of postfix related tools */
4 /* ________________________________________________________________________ */
6 /* Redistribution and use in source and binary forms, with or without */
7 /* modification, are permitted provided that the following conditions */
10 /* 1. Redistributions of source code must retain the above copyright */
11 /* notice, this list of conditions and the following disclaimer. */
12 /* 2. Redistributions in binary form must reproduce the above copyright */
13 /* notice, this list of conditions and the following disclaimer in the */
14 /* documentation and/or other materials provided with the distribution. */
15 /* 3. The names of its contributors may not be used to endorse or promote */
16 /* products derived from this software without specific prior written */
19 /* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS */
20 /* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY */
23 /* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL */
24 /* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS */
25 /* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
26 /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, */
27 /* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN */
28 /* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
29 /* POSSIBILITY OF SUCH DAMAGE. */
31 /* Copyright (c) 2006-2008 the Authors */
32 /* see AUTHORS and source files for details */
33 /******************************************************************************/
36 * Copyright © 2007 Pierre Habouzit
37 * Copyright © 2008 Florent Bruneau
40 #ifndef PFIXTOOLS_QUERY_H
41 #define PFIXTOOLS_QUERY_H
46 #include "policy_tokens.h"
51 SMTP_HELO = SMTP_EHLO,
62 extern const static_str_t smtp_state_names[SMTP_count];
64 /* \see http://www.postfix.org/SMTPD_POLICY_README.html */
65 typedef struct query_t {
69 static_str_t helo_name;
70 static_str_t queue_id;
72 static_str_t recipient;
73 static_str_t recipient_count;
74 static_str_t client_address;
75 static_str_t client_name;
76 static_str_t reverse_client_name;
77 static_str_t instance;
79 /* useful data extracted from previous ones */
80 static_str_t sender_domain;
81 static_str_t recipient_domain;
84 static_str_t sasl_method;
85 static_str_t sasl_username;
86 static_str_t sasl_sender;
88 static_str_t ccert_subject;
89 static_str_t ccert_issuer;
90 static_str_t ccert_fingerprint;
93 static_str_t encryption_protocol;
94 static_str_t encryption_cipher;
95 static_str_t encryption_keysize;
96 static_str_t etrn_domain;
104 /** Parse the content of the text to fill the query.
105 * The text pointed by \p p is segmented (and modified to add
106 * a \0 at the end of each segment) and used to fill the query
109 __attribute__((nonnull(1,2)))
110 bool query_parse(query_t *query, char *p);
112 /** Return the value of the field with the given name.
114 __attribute__((nonnull(1,2)))
115 const static_str_t *query_field_for_name(const query_t *query, const char *name);
117 /** Returns the value of the field with the given id.
119 __attribute__((nonnull))
120 const static_str_t *query_field_for_id(const query_t *query, postlicyd_token id);
122 /** Formats the given string by replacing ${field_name} with the content
124 * Unknown and empty fields are filled with (null).
126 __attribute__((nonnull(3)))
127 ssize_t query_format(char *dest, size_t len, const char* fmt, const query_t *query);
129 /** Writes a query-formated string in a buffer.
131 __attribute__((nonnull(1,2)))
132 bool query_format_buffer(buffer_t *buf, const char *fmt, const query_t *query);
134 /** Check the query-format string.
136 #define query_format_check(fmt) (query_format(NULL, 0, fmt, NULL) >= 0)