4 // Copyright (c) 1996-2018 by the citadel.org team
6 // This program is open source software. It runs great on the
7 // Linux operating system (and probably elsewhere). You can use,
8 // copy, and run it under the terms of the GNU General Public
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
19 // remove escaped strings from i.e. the url string (like %20 for blanks)
20 int unescape_input(char *buf) {
28 while ((buflen > 0) && (isspace(buf[buflen - 1]))) {
38 // don't let % chars through, rather truncate the input.
52 memmove(&buf[a + 1], &buf[a + 3], len);
63 // Supplied with a unix timestamp, generate a textual time/date stamp.
64 // Caller owns the returned memory.
65 char *http_datestring(time_t xtime) {
67 // HTTP Months - do not translate - these are not for human consumption
68 static char *httpdate_months[] = {
69 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
70 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
73 // HTTP Weekdays - do not translate - these are not for human consumption
74 static char *httpdate_weekdays[] = {
75 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
82 char *buf = malloc(n);
87 localtime_r(&xtime, &t);
89 // Convert "seconds west of GMT" to "hours/minutes offset"
98 offset = ((offset / 3600) * 100) + (offset % 60);
100 snprintf(buf, n, "%s, %02d %s %04d %02d:%02d:%02d %c%04ld",
101 httpdate_weekdays[t.tm_wday],
102 t.tm_mday, httpdate_months[t.tm_mon], t.tm_year + 1900, t.tm_hour, t.tm_min, t.tm_sec, offsign, offset);