2008-08-05 15:08:32 +00:00
|
|
|
#ifndef _LIGHTTPD_UTILS_H_
|
|
|
|
#define _LIGHTTPD_UTILS_H_
|
|
|
|
|
2008-10-28 21:11:50 +00:00
|
|
|
#ifndef _LIGHTTPD_BASE_H_
|
2008-11-16 20:33:53 +00:00
|
|
|
#error Please include <lighttpd/base.h> instead of this file
|
2008-10-28 21:11:50 +00:00
|
|
|
#endif
|
2008-08-05 15:08:32 +00:00
|
|
|
|
2008-11-03 14:10:25 +00:00
|
|
|
typedef enum {
|
|
|
|
COUNTER_TIME,
|
|
|
|
COUNTER_BYTES,
|
|
|
|
COUNTER_UNITS
|
|
|
|
} counter_type;
|
|
|
|
|
2008-11-12 01:09:52 +00:00
|
|
|
|
|
|
|
|
2008-08-05 15:08:32 +00:00
|
|
|
LI_API void fatal(const gchar* msg);
|
|
|
|
|
|
|
|
/* set O_NONBLOCK and FD_CLOEXEC */
|
|
|
|
LI_API void fd_init(int fd);
|
2008-08-06 18:46:42 +00:00
|
|
|
LI_API void ev_io_add_events(struct ev_loop *loop, ev_io *watcher, int events);
|
|
|
|
LI_API void ev_io_rem_events(struct ev_loop *loop, ev_io *watcher, int events);
|
|
|
|
LI_API void ev_io_set_events(struct ev_loop *loop, ev_io *watcher, int events);
|
2008-08-05 15:08:32 +00:00
|
|
|
|
2008-08-09 15:20:12 +00:00
|
|
|
|
|
|
|
/* URL inplace decode: replace %XX with character \xXX; replace control characters with '_' (< 32 || == 127) */
|
|
|
|
LI_API void url_decode(GString *path);
|
|
|
|
|
|
|
|
LI_API void path_simplify(GString *path);
|
|
|
|
|
2008-10-02 15:38:57 +00:00
|
|
|
/* returns the description for a given http status code and sets the len to the length of the returned string */
|
|
|
|
LI_API gchar *http_status_string(guint status_code, guint *len);
|
2008-12-10 15:36:38 +00:00
|
|
|
/* returns the http method as a string and sets len to the length of the returned string */
|
|
|
|
LI_API gchar *http_method_string(http_method_t method, guint *len);
|
2009-01-06 22:25:07 +00:00
|
|
|
/* returns the http version as a string and sets len to the length of the returned string */
|
|
|
|
LI_API gchar *http_version_string(http_version_t method, guint *len);
|
2008-10-02 15:38:57 +00:00
|
|
|
/* converts a given 3 digit http status code to a gchar[3] string. e.g. 403 to {'4','0','3'} */
|
|
|
|
LI_API void http_status_to_str(gint status_code, gchar status_str[]);
|
2008-08-13 00:18:35 +00:00
|
|
|
|
2009-03-13 22:16:21 +00:00
|
|
|
/* formats a given guint64 for output. if dest is NULL, a new string is allocated */
|
|
|
|
LI_API GString *counter_format(guint64 count, counter_type t, GString *dest);
|
2008-08-13 23:05:15 +00:00
|
|
|
|
2008-08-15 16:21:21 +00:00
|
|
|
LI_API gchar *ev_backend_string(guint backend);
|
|
|
|
|
2008-09-24 21:55:20 +00:00
|
|
|
LI_API void string_destroy_notify(gpointer str);
|
|
|
|
|
2008-10-02 00:37:36 +00:00
|
|
|
/* expects a pointer to a 32bit value */
|
2008-10-02 00:33:51 +00:00
|
|
|
LI_API guint hash_ipv4(gconstpointer key);
|
2008-10-02 00:37:36 +00:00
|
|
|
/* expects a pointer to a 128bit value */
|
2008-10-02 00:33:51 +00:00
|
|
|
LI_API guint hash_ipv6(gconstpointer key);
|
|
|
|
|
2008-10-02 19:46:06 +00:00
|
|
|
/* looks up the mimetype for a filename by comparing suffixes. first match is returned. do not free the result */
|
2008-10-25 16:01:02 +00:00
|
|
|
LI_API GString *mimetype_get(vrequest *vr, GString *filename);
|
2008-10-02 19:46:06 +00:00
|
|
|
|
2008-11-03 14:10:25 +00:00
|
|
|
/* converts a sock_addr to a human readable string. ipv4 and ipv6 supported. if dest is NULL, a new string will be allocated */
|
2009-04-03 12:29:55 +00:00
|
|
|
LI_API GString *sockaddr_to_string(sockaddr_t addr, GString *dest, gboolean showport);
|
2008-11-03 14:10:25 +00:00
|
|
|
|
2009-04-03 12:29:55 +00:00
|
|
|
LI_API sockaddr_t sockaddr_from_string(GString *str, guint tcp_default_port);
|
|
|
|
LI_API sockaddr_t sockaddr_local_from_socket(gint fd);
|
|
|
|
LI_API sockaddr_t sockaddr_remote_from_socket(gint fd);
|
|
|
|
LI_API void sockaddr_clear(sockaddr_t *saddr);
|
2009-01-01 15:44:42 +00:00
|
|
|
|
2009-01-06 22:25:07 +00:00
|
|
|
LI_API void gstring_replace_char_with_str_len(GString *gstr, gchar c, gchar *str, guint len);
|
|
|
|
|
2009-01-10 12:30:58 +00:00
|
|
|
LI_API gboolean l_g_strncase_equal(GString *str, const gchar *s, guint len);
|
|
|
|
|
2009-03-01 20:22:15 +00:00
|
|
|
LI_API GString *l_g_string_assign_len(GString *string, const gchar *val, gssize len);
|
|
|
|
|
2009-03-08 15:45:50 +00:00
|
|
|
LI_API gboolean l_g_string_prefix(GString *str, const gchar *s, gsize len);
|
|
|
|
LI_API gboolean l_g_string_suffix(GString *str, const gchar *s, gsize len);
|
|
|
|
|
2009-03-17 10:44:44 +00:00
|
|
|
LI_API void l_g_string_append_int(GString *dest, gint64 val);
|
2009-03-16 21:24:14 +00:00
|
|
|
|
2009-03-04 01:48:55 +00:00
|
|
|
LI_API gsize dirent_buf_size(DIR * dirp);
|
|
|
|
|
2008-08-05 15:08:32 +00:00
|
|
|
#endif
|