1 /* spmfilter - mail filtering framework
2  * Copyright (C) 2009-2012 Axel Steiner and SpaceNet AG
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 3 of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /*!
19  * @file smf_session.h
20  * @brief Defines SMFSession_T datatype and related functions.
21  * @details Each message is processed in a new session, with unique session id.
22  *          The session data itself is stored in a SMFSession_T object, whereas the
23  *          email content is stored on disk instead, but connection informations
24  *          and message headers are hold in memory. If you need to modify an
25  *          email in the current session, you have to use the session functions.
26  * @details If a header of a session object has been modified, the session will
27  *          be marked as "dirty" - that means the header will be flushed to disk
28  *          before the final delivery is initialized, to keep the message in sync
29  *          with the modified data.
30  */
31 
32 #ifndef _SMF_SESSION_H
33 #define _SMF_SESSION_H
34 
35 #include "smf_envelope.h"
36 #include "smf_list.h"
37 #include "smf_dict.h"
38 
39 typedef struct {
40   char *email;
41   SMFDict_T *data;
42 } SMFUserData_T;
43 
44 /*!
45  * @struct SMFSession_T
46  * @brief Holds spmfilter session data
47  */
48 typedef struct {
49   SMFEnvelope_T *envelope; /**< message envelope */
50   size_t message_size; /**< size of message body */
51   char *message_file; /**< path to message */
52   char *helo; /**< client's helo */
53   char *xforward_addr; /**< xforward data */
54   char *response_msg; /**< custom response message */
55   int sock; /**< socket */
56   char *id; /**< session id **/
57   SMFList_T *local_users; /**< list with local user data */
58 } SMFSession_T;
59 
60 /*!
61  * @fn SMFSession_T *smf_session_new(void)
62  * @brief Create a new SMFSession_T object
63  * @returns a newly allocated SMFSession_T object
64  */
65 SMFSession_T *smf_session_new(void);
66 
67 /*!
68  * @fn void smf_session_free(SMFSession_T *session)
69  * @brief Free a SMFSession_T object
70  * @param session a SMFSession_T object
71  */
72 void smf_session_free(SMFSession_T *session);
73 
74 /*!
75  * @fn void smf_session_set_helo(SMFSession_T *session, char *helo)
76  * @brief Set helo for session
77  * @param session SMFSession_T object
78  * @param helo helo message
79  */
80 void smf_session_set_helo(SMFSession_T *session, char *helo);
81 
82 /*!
83  * @fn char *smf_session_get_helo(SMFSession_T *session)
84  * @brief Get session helo
85  * @param session SMFSession_T object
86  * @returns helo
87  */
88 char *smf_session_get_helo(SMFSession_T *session);
89 
90 /*!
91  * @fn void smf_session_set_xforward_addr(SMFSession_T *session, char *xfwd)
92  * @brief Set xforward addr
93  * @param session SMFSession_T object
94  * @param xfwd xforward address
95  */
96 void smf_session_set_xforward_addr(SMFSession_T *session, char *xfwd);
97 
98 /*!
99  * @fn char *smf_session_get_xforward_addr(SMFSession_T *session)
100  * @brief Get xforward address
101  * @param session SMFSession_T object
102  * @returns xforward address
103  */
104 char *smf_session_get_xforward_addr(SMFSession_T *session);
105 
106 /*!
107  * @fn void smf_session_set_response_msg(SMFSession_T *session, char *rmsg)
108  * @brief Set response message
109  * @param session SMFSession_T object
110  * @param rmsg response message
111  */
112 void smf_session_set_response_msg(SMFSession_T *session, char *rmsg);
113 
114 /*!
115  * @fn char *smf_session_get_response_msg(SMFSession_T *session)
116  * @brief Get response message
117  * @param session SMFSession_T object
118  * @returns response_message
119  */
120 char *smf_session_get_response_msg(SMFSession_T *session);
121 
122 /*!
123  * @fn SMFEnvelope_T *smf_session_get_envelope(SMFSession_T *session)
124  * @brief Retrieve the SMFEnvelope_T object from the
125  *  current session.
126  * @param session a SMFSession_T object
127  * @returns SMFEnvelope_T object
128  */
129 SMFEnvelope_T *smf_session_get_envelope(SMFSession_T *session);
130 
131 /*!
132  * @fn void smf_session_set_message_file(SMFSession_T *session, char *fp)
133  * @brief Set path for message file
134  * @param session SMFSession_T object
135  * @param fp message file path
136  */
137 void smf_session_set_message_file(SMFSession_T *session, char *fp);
138 
139 /*!
140  * @fn char *smf_session_get_message_file(SMFSession_T *session)
141  * @brief Get message file
142  * @param session SMFSession_T object
143  * @returns path to message file
144  */
145 char *smf_session_get_message_file(SMFSession_T *session);
146 
147 /*!
148  * @fn char *smf_session_get_id(SMFSession_T *session)
149  * @brief Get session id
150  * @param session SMFSession_T object
151  * @returns session id
152  */
153 char *smf_session_get_id(SMFSession_T *session);
154 
155 /*!
156  * @fn int smf_session_is_local(SMFSession_T *session, const char *user)
157  * @brief Check if given user is found in local lookup database
158  * @param session SMFSession_T object
159  * @param user string with users email address, to look for
160  * @return returns 1 if user is local, otherwise 0
161  */
162 int smf_session_is_local(SMFSession_T *session, const char *user);
163 
164 /*!
165  * @fn SMFDict_T *smf_session_get_user_data(SMFSession_T *session, const char *user)
166  * @brief Get data stored in local database for given user
167  * @param session SMFSession_T object
168  * @param user string with users email address, to look for
169  * @return returns SMFDict_T with user data, NULL if given user is not found
170  */
171 SMFDict_T *smf_session_get_user_data(SMFSession_T *session, const char *user);
172 
173 #endif  /* _SMF_SESSION_H */
174 
175