4 * Copyright (c) 1996-2018 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3.
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
12 * GNU General Public License for more details.
19 * remove escaped strings from i.e. the url string (like %20 for blanks)
21 int unescape_input(char *buf)
30 while ((buflen > 0) && (isspace(buf[buflen - 1]))) {
40 /* don't let % chars through, rather truncate the input. */
53 memmove(&buf[a + 1], &buf[a + 3], len);
65 * Supplied with a unix timestamp, generate a textual time/date stamp.
66 * Caller owns the returned memory.
68 char *http_datestring(time_t xtime)
71 /* HTTP Months - do not translate - these are not for human consumption */
72 static char *httpdate_months[] = {
73 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
74 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
77 /* HTTP Weekdays - do not translate - these are not for human consumption */
78 static char *httpdate_weekdays[] = {
79 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
86 char *buf = malloc(n);
90 localtime_r(&xtime, &t);
92 /* Convert "seconds west of GMT" to "hours/minutes offset" */
100 offset = ((offset / 3600) * 100) + (offset % 60);
102 snprintf(buf, n, "%s, %02d %s %04d %02d:%02d:%02d %c%04ld",
103 httpdate_weekdays[t.tm_wday],
104 t.tm_mday, httpdate_months[t.tm_mon], t.tm_year + 1900, t.tm_hour, t.tm_min, t.tm_sec, offsign, offset);