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.
20 * remove escaped strings from i.e. the url string (like %20 for blanks)
22 int unescape_input(char *buf)
31 while ((buflen > 0) && (isspace(buf[buflen - 1]))) {
41 /* don't let % chars through, rather truncate the input. */
54 memmove(&buf[a + 1], &buf[a + 3], len);
66 * Supplied with a unix timestamp, generate a textual time/date stamp.
67 * Caller owns the returned memory.
69 char *http_datestring(time_t xtime)
72 /* HTTP Months - do not translate - these are not for human consumption */
73 static char *httpdate_months[] = {
74 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
75 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
78 /* HTTP Weekdays - do not translate - these are not for human consumption */
79 static char *httpdate_weekdays[] = {
80 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
87 char *buf = malloc(n);
91 localtime_r(&xtime, &t);
93 /* Convert "seconds west of GMT" to "hours/minutes offset" */
101 offset = ((offset / 3600) * 100) + (offset % 60);
103 snprintf(buf, n, "%s, %02d %s %04d %02d:%02d:%02d %c%04ld",
104 httpdate_weekdays[t.tm_wday],
105 t.tm_mday, httpdate_months[t.tm_mon], t.tm_year + 1900, t.tm_hour, t.tm_min, t.tm_sec, offsign, offset);