1 /*
2  * wzdftpd - a modular and cool ftp server
3  * Copyright (C) 2002-2004  Pierre Chifflier
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  *
19  * As a special exemption, Pierre Chifflier
20  * and other respective copyright holders give permission to link this program
21  * with OpenSSL, and distribute the resulting executable, without including
22  * the source code for OpenSSL in the source distribution.
23  */
24 
25 #ifndef __WZD_MESSAGES__
26 #define __WZD_MESSAGES__
27 
28 void init_default_messages(void);
29 void free_messages(void);
30 
31 /* must_free == 1 if calling function MUST free return with wzd_free after use */
32 const char * getMessage(int code, int *must_free);
33 
34 /* be carefull: the function does NOT copy string, it just stores its adress ! */
35 void setMessage(const char *newMessage, int code);
36 
37 /* message sending functions */
38 int send_message(int code, wzd_context_t * context);
39 int send_message_with_args(int code, wzd_context_t * context, ...);
40 int send_message_raw(const char *msg, wzd_context_t * context);
41 
42 /** \brief send formatted reply to client
43  *
44  * This will replace all previous functions to send messages
45  */
46 int send_message_formatted(int code, wzd_context_t * context, const char * format, ...)
47 #ifdef __GNUC__
48   __attribute__((__format__(printf,3,4)))
49 #endif
50 ;
51 
52 struct wzd_reply_t {
53   int code; /**< the current reply code, or 0 if no reply is set */
54   wzd_string_t * _reply;
55   int sent; /**< 1 if the reply has already been sent */
56 };
57 
58 /** \brief Allocate memory for a struct wzd_reply_t */
59 struct wzd_reply_t * reply_alloc(void);
60 
61 /** \brief Free memory used by struct wzd_reply_t */
62 void reply_free(struct wzd_reply_t * reply);
63 
64 /** \brief Clear the stored reply */
65 void reply_clear(wzd_context_t * context);
66 
67 /** \brief Set the current reply code */
68 void reply_set_code(wzd_context_t * context, int code);
69 
70 /** \brief Get the current reply code */
71 int reply_get_code(wzd_context_t * context);
72 
73 /** \brief Add a message to the stored reply */
74 int reply_push(wzd_context_t * context, const char * s);
75 
76 /** \brief Send formatted reply to client.
77  *
78  * \a code must be set
79  */
80 int reply_send(wzd_context_t * context);
81 
82 #endif /* __WZD_MESSAGES__ */
83