2008-07-01 18:56:59 +00:00
|
|
|
#ifndef _LIGHTTPD_HTTP_HEADERS_H_
|
|
|
|
#define _LIGHTTPD_HTTP_HEADERS_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-07-01 18:56:59 +00:00
|
|
|
|
2009-10-09 13:38:12 +00:00
|
|
|
#define LI_HEADER_VALUE(h) \
|
|
|
|
(&(h)->data->str[(h)->keylen + 2])
|
2008-09-09 14:38:40 +00:00
|
|
|
|
2009-10-09 13:38:12 +00:00
|
|
|
#define LI_HEADER_VALUE_LEN(h) \
|
|
|
|
(&(h)->data->str[(h)->keylen + 2]), ((h)->data->len - ((h)->keylen + 2))
|
|
|
|
|
|
|
|
#define LI_HEADER_KEY_LEN(h) \
|
|
|
|
((h)->data->str), ((h)->keylen)
|
2008-09-09 14:38:40 +00:00
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
struct liHttpHeader {
|
2008-09-09 14:38:40 +00:00
|
|
|
guint keylen; /** length of "headername" in data */
|
|
|
|
GString *data; /** "headername: value" */
|
2008-08-06 22:26:17 +00:00
|
|
|
};
|
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
struct liHttpHeaders {
|
2008-09-09 14:38:40 +00:00
|
|
|
GQueue entries;
|
2008-07-01 18:56:59 +00:00
|
|
|
};
|
|
|
|
|
2009-09-13 15:46:02 +00:00
|
|
|
/* strings always get copied, so you should free key and value yourself */
|
2008-07-01 18:56:59 +00:00
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
LI_API liHttpHeaders* li_http_headers_new();
|
|
|
|
LI_API void li_http_headers_reset(liHttpHeaders* headers);
|
|
|
|
LI_API void li_http_headers_free(liHttpHeaders* headers);
|
2008-07-01 18:56:59 +00:00
|
|
|
|
|
|
|
/** If header does not exist, just insert normal header. If it exists, append (", %s", value) */
|
2009-07-09 20:17:24 +00:00
|
|
|
LI_API void li_http_header_append(liHttpHeaders *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen);
|
2009-09-28 18:56:28 +00:00
|
|
|
|
|
|
|
/** Add new entry to list ("%s: %s", key, value) */
|
2009-07-09 20:17:24 +00:00
|
|
|
LI_API void li_http_header_insert(liHttpHeaders *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen);
|
2009-09-28 18:56:28 +00:00
|
|
|
|
2008-07-01 18:56:59 +00:00
|
|
|
/** If header does not exist, just insert normal header. If it exists, overwrite the value */
|
2009-07-09 20:17:24 +00:00
|
|
|
LI_API void li_http_header_overwrite(liHttpHeaders *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen);
|
2009-09-28 18:56:28 +00:00
|
|
|
|
|
|
|
/** Remove all header entries with specified key */
|
2009-07-09 20:17:24 +00:00
|
|
|
LI_API gboolean li_http_header_remove(liHttpHeaders *headers, const gchar *key, size_t keylen);
|
2009-09-28 18:56:28 +00:00
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
LI_API void li_http_header_remove_link(liHttpHeaders *headers, GList *l);
|
2008-07-01 18:56:59 +00:00
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
LI_API liHttpHeader* li_http_header_lookup(liHttpHeaders *headers, const gchar *key, size_t keylen);
|
2008-08-06 23:23:04 +00:00
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
LI_API GList* li_http_header_find_first(liHttpHeaders *headers, const gchar *key, size_t keylen);
|
|
|
|
LI_API GList* li_http_header_find_next(GList *l, const gchar *key, size_t keylen);
|
|
|
|
LI_API GList* li_http_header_find_last(liHttpHeaders *headers, const gchar *key, size_t keylen);
|
2008-08-06 23:23:04 +00:00
|
|
|
|
|
|
|
/** Use lowercase keys! values are compared case-insensitive */
|
2009-07-09 20:17:24 +00:00
|
|
|
LI_API gboolean li_http_header_is(liHttpHeaders *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen);
|
2008-08-06 23:23:04 +00:00
|
|
|
|
2009-09-13 15:46:02 +00:00
|
|
|
/** concats all headers with key with ', ' - empty if no header exists */
|
|
|
|
LI_API void li_http_header_get_all(GString *dest, liHttpHeaders *headers, const gchar *key, size_t keylen);
|
2008-08-07 12:12:51 +00:00
|
|
|
|
2009-10-09 13:38:12 +00:00
|
|
|
INLINE gboolean li_http_header_key_is(liHttpHeader *h, const gchar *key, size_t keylen) {
|
2008-09-09 14:38:40 +00:00
|
|
|
return (h->keylen == keylen && 0 == g_ascii_strncasecmp(key, h->data->str, keylen));
|
|
|
|
}
|
|
|
|
|
2008-07-01 18:56:59 +00:00
|
|
|
#endif
|