• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/uhttpd/utils.h

  1 /*
  2  * uhttpd - Tiny single-threaded httpd
  3  *
  4  *   Copyright (C) 2010-2013 Jo-Philipp Wich <xm@subsignal.org>
  5  *   Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
  6  *
  7  * Permission to use, copy, modify, and/or distribute this software for any
  8  * purpose with or without fee is hereby granted, provided that the above
  9  * copyright notice and this permission notice appear in all copies.
 10  *
 11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 18  */
 19 
 20 #ifndef _UHTTPD_UTILS_
 21 
 22 #include <sys/stat.h>
 23 
 24 #include <stdarg.h>
 25 #include <fcntl.h>
 26 #include <pwd.h>
 27 #include <stdio.h>
 28 #include <string.h>
 29 #include <errno.h>
 30 #include <stdlib.h>
 31 #include <alloca.h>
 32 #include <time.h>
 33 #include <unistd.h>
 34 
 35 struct uh_addr {
 36         uint8_t family;
 37         uint16_t port;
 38         union {
 39                 struct in_addr in;
 40                 struct in6_addr in6;
 41         };
 42 };
 43 
 44 #define min(x, y) (((x) < (y)) ? (x) : (y))
 45 #define max(x, y) (((x) > (y)) ? (x) : (y))
 46 
 47 #define array_size(x) \
 48         (sizeof(x) / sizeof(x[0]))
 49 
 50 #define fd_cloexec(fd) \
 51         fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC)
 52 
 53 #ifdef __APPLE__
 54 static inline void clearenv(void)
 55 {
 56         extern char **environ;
 57         *environ = NULL;
 58 }
 59 
 60 time_t timegm (struct tm *tm);
 61 
 62 #endif
 63 
 64 #ifdef __GNUC__
 65 #define __printf(a, b) __attribute__((format(printf, a, b)))
 66 #else
 67 #define __printf(a, b)
 68 #endif
 69 
 70 enum { /* chartypes flags */
 71         CT_ALPHA  = (1 << 0),
 72         CT_CTL    = (1 << 1),
 73         CT_DIGIT  = (1 << 2),
 74         CT_HEXDIG = (1 << 3),
 75         CT_VCHAR  = (1 << 4),
 76         CT_WSP    = (1 << 5),
 77         CT_DELIM  = (1 << 6),
 78         CT_VDELIM = CT_DELIM | CT_VCHAR,
 79         CT_VALPHA = CT_ALPHA | CT_VCHAR,
 80         CT_XALPHA = CT_ALPHA | CT_HEXDIG | CT_VCHAR,
 81         CT_XDIGIT = CT_DIGIT | CT_HEXDIG | CT_VCHAR,
 82 };
 83 
 84 extern uint8_t chartypes[256];
 85 
 86 /* RFC 9110 character class helpers */
 87 #define uh_is_tchar(c)  ((chartypes[(uint8_t)(c)] & (CT_VCHAR | CT_DELIM)) == CT_VCHAR)
 88 #define uh_is_wsp(c)    (chartypes[(uint8_t)(c)] & CT_WSP)
 89 #define uh_is_ctl(c)    (chartypes[(uint8_t)(c)] & CT_CTL)
 90 #define uh_is_digit(c)  (chartypes[(uint8_t)(c)] & CT_DIGIT)
 91 #define uh_is_hexdig(c) (chartypes[(uint8_t)(c)] & CT_HEXDIG)
 92 
 93 int uh_urldecode(char *buf, int blen, const char *src, int slen);
 94 int uh_urlencode(char *buf, int blen, const char *src, int slen);
 95 int uh_b64decode(char *buf, int blen, const void *src, int slen);
 96 bool uh_path_match(const char *prefix, const char *url);
 97 char *uh_split_header(char *str, size_t len);
 98 bool uh_addr_rfc1918(struct uh_addr *addr);
 99 char *uh_htmlescape(const char *src);
100 
101 #endif
102 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt