Annotation of embedaddon/lighttpd/src/buffer.h, revision 1.1.1.2

1.1       misho       1: #ifndef _BUFFER_H_
                      2: #define _BUFFER_H_
                      3: 
                      4: #ifdef HAVE_CONFIG_H
                      5: # include "config.h"
                      6: #endif
                      7: 
                      8: #include "settings.h"
                      9: 
                     10: #include <stdlib.h>
                     11: #include <sys/types.h>
                     12: 
                     13: typedef struct {
                     14:        char *ptr;
                     15: 
                     16:        size_t used;
                     17:        size_t size;
                     18: } buffer;
                     19: 
                     20: typedef struct {
                     21:        buffer **ptr;
                     22: 
                     23:        size_t used;
                     24:        size_t size;
                     25: } buffer_array;
                     26: 
                     27: typedef struct {
                     28:        char *ptr;
                     29: 
                     30:        size_t offset; /* input-pointer */
                     31: 
                     32:        size_t used;   /* output-pointer */
                     33:        size_t size;
                     34: } read_buffer;
                     35: 
                     36: buffer_array* buffer_array_init(void);
                     37: void buffer_array_free(buffer_array *b);
                     38: void buffer_array_reset(buffer_array *b);
                     39: buffer *buffer_array_append_get_buffer(buffer_array *b);
                     40: 
                     41: buffer* buffer_init(void);
                     42: buffer* buffer_init_buffer(buffer *b);
                     43: buffer* buffer_init_string(const char *str);
                     44: void buffer_free(buffer *b);
                     45: void buffer_reset(buffer *b);
                     46: 
                     47: int buffer_prepare_copy(buffer *b, size_t size);
                     48: int buffer_prepare_append(buffer *b, size_t size);
                     49: 
                     50: int buffer_copy_string(buffer *b, const char *s);
                     51: int buffer_copy_string_len(buffer *b, const char *s, size_t s_len);
                     52: int buffer_copy_string_buffer(buffer *b, const buffer *src);
                     53: int buffer_copy_string_hex(buffer *b, const char *in, size_t in_len);
                     54: 
                     55: int buffer_copy_long(buffer *b, long val);
                     56: 
                     57: int buffer_copy_memory(buffer *b, const char *s, size_t s_len);
                     58: 
                     59: int buffer_append_string(buffer *b, const char *s);
                     60: int buffer_append_string_len(buffer *b, const char *s, size_t s_len);
                     61: int buffer_append_string_buffer(buffer *b, const buffer *src);
                     62: int buffer_append_string_lfill(buffer *b, const char *s, size_t maxlen);
                     63: int buffer_append_string_rfill(buffer *b, const char *s, size_t maxlen);
                     64: 
                     65: int buffer_append_long_hex(buffer *b, unsigned long len);
                     66: int buffer_append_long(buffer *b, long val);
                     67: 
                     68: #if defined(SIZEOF_LONG) && (SIZEOF_LONG == SIZEOF_OFF_T)
                     69: #define buffer_copy_off_t(x, y)                buffer_copy_long(x, y)
                     70: #define buffer_append_off_t(x, y)      buffer_append_long(x, y)
                     71: #else
                     72: int buffer_copy_off_t(buffer *b, off_t val);
                     73: int buffer_append_off_t(buffer *b, off_t val);
                     74: #endif
                     75: 
                     76: int buffer_append_memory(buffer *b, const char *s, size_t s_len);
                     77: 
                     78: char * buffer_search_string_len(buffer *b, const char *needle, size_t len);
                     79: 
                     80: int buffer_is_empty(buffer *b);
                     81: int buffer_is_equal(buffer *a, buffer *b);
                     82: int buffer_is_equal_right_len(buffer *a, buffer *b, size_t len);
                     83: int buffer_is_equal_string(buffer *a, const char *s, size_t b_len);
                     84: int buffer_is_equal_caseless_string(buffer *a, const char *s, size_t b_len);
                     85: int buffer_caseless_compare(const char *a, size_t a_len, const char *b, size_t b_len);
                     86: 
                     87: typedef enum {
                     88:        ENCODING_UNSET,
                     89:        ENCODING_REL_URI, /* for coding a rel-uri (/with space/and%percent) nicely as part of a href */
                     90:        ENCODING_REL_URI_PART, /* same as ENC_REL_URL plus coding / too as %2F */
                     91:        ENCODING_HTML,         /* & becomes &amp; and so on */
                     92:        ENCODING_MINIMAL_XML,  /* minimal encoding for xml */
                     93:        ENCODING_HEX,          /* encode string as hex */
                     94:        ENCODING_HTTP_HEADER   /* encode \n with \t\n */
                     95: } buffer_encoding_t;
                     96: 
                     97: int buffer_append_string_encoded(buffer *b, const char *s, size_t s_len, buffer_encoding_t encoding);
                     98: 
                     99: int buffer_urldecode_path(buffer *url);
                    100: int buffer_urldecode_query(buffer *url);
                    101: int buffer_path_simplify(buffer *dest, buffer *src);
                    102: 
                    103: int buffer_to_lower(buffer *b);
                    104: int buffer_to_upper(buffer *b);
                    105: 
                    106: /** deprecated */
                    107: int LI_ltostr(char *buf, long val);
                    108: char hex2int(unsigned char c);
                    109: char int2hex(char i);
                    110: 
                    111: int light_isdigit(int c);
                    112: int light_isxdigit(int c);
                    113: int light_isalpha(int c);
                    114: int light_isalnum(int c);
                    115: 
                    116: #define BUFFER_APPEND_STRING_CONST(x, y) \
                    117:        buffer_append_string_len(x, y, sizeof(y) - 1)
                    118: 
                    119: #define BUFFER_COPY_STRING_CONST(x, y) \
                    120:        buffer_copy_string_len(x, y, sizeof(y) - 1)
                    121: 
                    122: #define BUFFER_APPEND_SLASH(x) \
                    123:        if (x->used > 1 && x->ptr[x->used - 2] != '/') { BUFFER_APPEND_STRING_CONST(x, "/"); }
                    124: 
                    125: #define CONST_STR_LEN(x) x, x ? sizeof(x) - 1 : 0
                    126: #define CONST_BUF_LEN(x) x->ptr, x->used ? x->used - 1 : 0
                    127: 
                    128: 
                    129: #define UNUSED(x) ( (void)(x) )
                    130: 
1.1.1.2 ! misho     131: void log_failed_assert(const char *filename, unsigned int line, const char *msg) LI_NORETURN;
        !           132: #define force_assert(x) do { if (!(x)) log_failed_assert(__FILE__, __LINE__, "assertion failed: " #x); } while(0)
        !           133: #define SEGFAULT() log_failed_assert(__FILE__, __LINE__, "aborted");
        !           134: 
1.1       misho     135: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>