1 /*
2 * Part of Very Secure FTPd
3 * Licence: GPL v2
4 * Author: Dmitriy Balashov
5 * http_msg.c
6 *
7 * HTTP messages.
8 */
9
10 #include "defs.h"
11 #include "http_msg.h"
12 #include "tunables.h"
13 #include "str.h"
14 #include "filestr.h"
15 #include "utility.h"
16 #include "sysutil.h"
17 //#include "logging.h"
18
19 static void http_message_set(struct mystr* p_str, const char* p_filename, const char* p_default);
20
21 static struct mystr msg_forbidden_server = INIT_MYSTR;
22 static struct mystr msg_forbidden_object = INIT_MYSTR;
23 static struct mystr msg_not_found = INIT_MYSTR;
24 static struct mystr msg_browse = INIT_MYSTR;
25 struct mystr msg_browse_line = INIT_MYSTR;
26 static char* forbidden = "<h1>Forbidden<h1>";
27 static char* not_found = "<h1>Not Found<h1>";
28 static char* browse = "<h1>Index of %r</h1><table border=0 cellspacing=2 cellpadding=2>%b</table>";
29 static char* browse_line = "<tr><td>%f</td><td><a href='%l'>%i</a></td><td>%s</td><td>%T</td></tr>";
30
31 void
vsf_http_messages_load()32 vsf_http_messages_load()
33 {
34 http_message_set(&msg_forbidden_server, tunable_http_error_403_server_tpl, forbidden);
35 http_message_set(&msg_forbidden_object, tunable_http_error_403_tpl, forbidden);
36 http_message_set(&msg_not_found, tunable_http_error_404_tpl, not_found);
37 http_message_set(&msg_browse, tunable_http_browse_tpl, browse);
38 http_message_set(&msg_browse_line, tunable_http_browse_line_tpl, browse_line);
39 }
40
41 const char*
vsf_http_messages_get(const enum EVSFHttpMsgType p_msg_type)42 vsf_http_messages_get(const enum EVSFHttpMsgType p_msg_type)
43 {
44 switch (p_msg_type)
45 {
46 case kVSFHttpMsgType403Serv:
47 return str_getbuf(&msg_forbidden_server);
48 break;
49 case kVSFHttpMsgType403:
50 return str_getbuf(&msg_forbidden_object);
51 break;
52 case kVSFHttpMsgType404:
53 return str_getbuf(&msg_not_found);
54 break;
55 case kVSFHttpMsgType200Browse:
56 return str_getbuf(&msg_browse);
57 break;
58 default:
59 bug("unknown message type in vsf_http_messages_get");
60 break;
61 }
62 return 0;
63 }
64
65 static void
http_message_set(struct mystr * p_str,const char * p_filename,const char * p_default)66 http_message_set(struct mystr* p_str, const char* p_filename, const char* p_default)
67 {
68 int retval = 0;
69 if (p_filename)
70 {
71 retval = str_fileread(p_str, p_filename, VSFTP_DATA_BUFSIZE);
72 }
73 if (!p_filename || vsf_sysutil_retval_is_error(retval))
74 {
75 str_alloc_text(p_str, p_default);
76 }
77 }
78
79