Browse Source

[core] C99 restrict on some base funcs

buffer.[ch], chunk.[ch], request.[ch], sock_addr.[ch]
personal/stbuehler/ci-build
Glenn Strauss 1 year ago
parent
commit
9914bb297b
  1. 32
      src/buffer.c
  2. 38
      src/buffer.h
  3. 36
      src/chunk.c
  4. 26
      src/chunk.h
  5. 18
      src/request.c
  6. 2
      src/request.h
  7. 21
      src/sock_addr.c
  8. 41
      src/sock_addr.h

32
src/buffer.c

@ -62,7 +62,7 @@ void buffer_reset(buffer *b) {
if (b->size > BUFFER_MAX_REUSE_SIZE) buffer_free_ptr(b);
}
void buffer_move(buffer *b, buffer *src) {
void buffer_move(buffer * restrict b, buffer * restrict src) {
buffer tmp;
force_assert(NULL != b);
force_assert(NULL != src);
@ -156,11 +156,11 @@ void buffer_commit(buffer *b, size_t size)
b->ptr[b->used - 1] = '\0';
}
void buffer_copy_string(buffer *b, const char *s) {
void buffer_copy_string(buffer * restrict b, const char * restrict s) {
buffer_copy_string_len(b, s, NULL != s ? strlen(s) : 0);
}
void buffer_copy_string_len(buffer * const b, const char * const s, const size_t s_len) {
void buffer_copy_string_len(buffer * const restrict b, const char * const restrict s, const size_t s_len) {
if (NULL == b || s_len >= b->size) buffer_alloc_replace(b, s_len);
b->used = s_len + 1;
@ -168,7 +168,7 @@ void buffer_copy_string_len(buffer * const b, const char * const s, const size_t
if (0 != s_len) memcpy(b->ptr, s, s_len); /*(s might be NULL)*/
}
void buffer_append_string(buffer *b, const char *s) {
void buffer_append_string(buffer * restrict b, const char * restrict s) {
buffer_append_string_len(b, s, NULL != s ? strlen(s) : 0);
}
@ -183,7 +183,7 @@ void buffer_append_string(buffer *b, const char *s) {
* @param s_len size of the string (without the terminating \0)
*/
void buffer_append_string_len(buffer * const b, const char * const s, const size_t s_len) {
void buffer_append_string_len(buffer * const restrict b, const char * const restrict s, const size_t s_len) {
char * const target_buf = buffer_string_prepare_append(b, s_len);
b->used += s_len + (0 == b->used); /*(must include '\0' for append)*/
target_buf[s_len] = '\0';
@ -192,7 +192,7 @@ void buffer_append_string_len(buffer * const b, const char * const s, const size
if (s_len) memcpy(target_buf, s, s_len);
}
void buffer_append_path_len(buffer *b, const char *a, size_t alen) {
void buffer_append_path_len(buffer * restrict b, const char * restrict a, size_t alen) {
size_t blen = buffer_string_length(b);
int aslash = (alen && a[0] == '/');
buffer_string_prepare_append(b, alen+2); /*(+ '/' and + '\0' if 0 == blen)*/
@ -266,7 +266,7 @@ void buffer_append_int(buffer *b, intmax_t val) {
buffer_append_string_len(b, str, buf_end - str);
}
void buffer_append_strftime(buffer *b, const char *format, const struct tm *tm) {
void buffer_append_strftime(buffer * const restrict b, const char * const restrict format, const struct tm * const restrict tm) {
size_t rv;
char* buf;
force_assert(NULL != format);
@ -403,7 +403,7 @@ int buffer_is_equal_right_len(const buffer *b1, const buffer *b2, size_t len) {
}
void li_tohex_lc(char *buf, size_t buf_len, const char *s, size_t s_len) {
void li_tohex_lc(char * const restrict buf, size_t buf_len, const char * const restrict s, size_t s_len) {
force_assert(2 * s_len > s_len);
force_assert(2 * s_len < buf_len);
@ -414,7 +414,7 @@ void li_tohex_lc(char *buf, size_t buf_len, const char *s, size_t s_len) {
buf[2*s_len] = '\0';
}
void li_tohex_uc(char *buf, size_t buf_len, const char *s, size_t s_len) {
void li_tohex_uc(char * const restrict buf, size_t buf_len, const char * const restrict s, size_t s_len) {
force_assert(2 * s_len > s_len);
force_assert(2 * s_len < buf_len);
@ -426,8 +426,8 @@ void li_tohex_uc(char *buf, size_t buf_len, const char *s, size_t s_len) {
}
void buffer_substr_replace (buffer * const b, const size_t offset,
const size_t len, const buffer * const replace)
void buffer_substr_replace (buffer * const restrict b, const size_t offset,
const size_t len, const buffer * const restrict replace)
{
const size_t blen = buffer_string_length(b);
const size_t rlen = buffer_string_length(replace);
@ -446,7 +446,7 @@ void buffer_substr_replace (buffer * const b, const size_t offset,
}
void buffer_append_string_encoded_hex_lc(buffer *b, const char *s, size_t len) {
void buffer_append_string_encoded_hex_lc(buffer * const restrict b, const char * const restrict s, size_t len) {
unsigned char * const p =
(unsigned char*) buffer_string_prepare_append(b, len*2);
buffer_commit(b, len*2); /* fill below */
@ -456,7 +456,7 @@ void buffer_append_string_encoded_hex_lc(buffer *b, const char *s, size_t len) {
}
}
void buffer_append_string_encoded_hex_uc(buffer *b, const char *s, size_t len) {
void buffer_append_string_encoded_hex_uc(buffer * const restrict b, const char * const restrict s, size_t len) {
unsigned char * const p =
(unsigned char*) buffer_string_prepare_append(b, len*2);
buffer_commit(b, len*2); /* fill below */
@ -559,7 +559,7 @@ static const char encoded_chars_minimal_xml[] = {
void buffer_append_string_encoded(buffer *b, const char *s, size_t s_len, buffer_encoding_t encoding) {
void buffer_append_string_encoded(buffer * const restrict b, const char * const restrict s, size_t s_len, buffer_encoding_t encoding) {
unsigned char *ds, *d;
size_t d_len, ndx;
const char *map = NULL;
@ -631,7 +631,7 @@ void buffer_append_string_encoded(buffer *b, const char *s, size_t s_len, buffer
}
}
void buffer_append_string_c_escaped(buffer *b, const char *s, size_t s_len) {
void buffer_append_string_c_escaped(buffer * const restrict b, const char * const restrict s, size_t s_len) {
unsigned char *ds, *d;
size_t d_len, ndx;
@ -688,7 +688,7 @@ void buffer_append_string_c_escaped(buffer *b, const char *s, size_t s_len) {
}
void buffer_copy_string_encoded_cgi_varnames(buffer *b, const char *s, size_t s_len, int is_http_header) {
void buffer_copy_string_encoded_cgi_varnames(buffer * const restrict b, const char * const restrict s, size_t s_len, int is_http_header) {
size_t i, j = 0;
force_assert(NULL != b);

38
src/buffer.h

@ -39,7 +39,7 @@ void buffer_free(buffer *b); /* b can be NULL */
void buffer_reset(buffer *b); /* b can be NULL */
/* reset b. if NULL != b && NULL != src, move src content to b. reset src. */
void buffer_move(buffer *b, buffer *src);
void buffer_move(buffer * restrict b, buffer * restrict src);
/* make sure buffer is large enough to store a string of given size
* and a terminating zero.
@ -79,19 +79,19 @@ void buffer_string_set_length(buffer *b, uint32_t len);
*/
static inline void buffer_clear(buffer *b);
void buffer_copy_string(buffer *b, const char *s);
void buffer_copy_string_len(buffer *b, const char *s, size_t s_len);
static inline void buffer_copy_buffer(buffer *b, const buffer *src);
void buffer_copy_string(buffer * restrict b, const char * restrict s);
void buffer_copy_string_len(buffer * restrict b, const char * restrict s, size_t s_len);
static inline void buffer_copy_buffer(buffer * restrict b, const buffer * restrict src);
void buffer_append_string(buffer *b, const char *s);
void buffer_append_string_len(buffer *b, const char *s, size_t s_len);
static inline void buffer_append_string_buffer(buffer *b, const buffer *src);
void buffer_append_string(buffer * restrict b, const char * restrict s);
void buffer_append_string_len(buffer * restrict b, const char * restrict s, size_t s_len);
static inline void buffer_append_string_buffer(buffer * restrict b, const buffer * restrict src);
#define buffer_append_uint_hex(b,len) buffer_append_uint_hex_lc((b),(len))
void buffer_append_uint_hex_lc(buffer *b, uintmax_t len);
void buffer_append_int(buffer *b, intmax_t val);
void buffer_append_strftime(buffer *b, const char *format, const struct tm *tm);
void buffer_append_strftime(buffer * restrict b, const char * restrict format, const struct tm * restrict tm);
/* '-', log_10 (2^bits) = bits * log 2 / log 10 < bits * 0.31, terminating 0 */
#define LI_ITOSTRING_LENGTH (2 + (8 * sizeof(intmax_t) * 31 + 99) / 100)
@ -101,8 +101,8 @@ size_t li_utostrn(char *buf, size_t buf_len, uintmax_t val);
/* buf must be (at least) 2*s_len + 1 big. uses lower-case hex letters. */
#define li_tohex(buf,buf_len,s,s_len) li_tohex_lc((buf),(buf_len),(s),(s_len))
void li_tohex_lc(char *buf, size_t buf_len, const char *s, size_t s_len);
void li_tohex_uc(char *buf, size_t buf_len, const char *s, size_t s_len);
void li_tohex_lc(char * restrict buf, size_t buf_len, const char * restrict s, size_t s_len);
void li_tohex_uc(char * restrict buf, size_t buf_len, const char * restrict s, size_t s_len);
/* NULL buffer or empty buffer (used == 0);
* unset "string" (buffer) config options are initialized to used == 0,
@ -138,10 +138,10 @@ int buffer_is_equal_string(const buffer *a, const char *s, size_t b_len);
__attribute_pure__
int buffer_is_equal_caseless_string(const buffer *a, const char *s, size_t b_len);
void buffer_substr_replace (buffer *b, size_t offset, size_t len, const buffer *replace);
void buffer_substr_replace (buffer * restrict b, size_t offset, size_t len, const buffer * restrict replace);
void buffer_append_string_encoded_hex_lc(buffer *b, const char *s, size_t len);
void buffer_append_string_encoded_hex_uc(buffer *b, const char *s, size_t len);
void buffer_append_string_encoded_hex_lc(buffer * restrict b, const char * restrict s, size_t len);
void buffer_append_string_encoded_hex_uc(buffer * restrict b, const char * restrict s, size_t len);
typedef enum {
ENCODING_REL_URI, /* for coding a rel-uri (/with space/and%percent) nicely as part of a href */
@ -150,13 +150,13 @@ typedef enum {
ENCODING_MINIMAL_XML /* minimal encoding for xml */
} buffer_encoding_t;
void buffer_append_string_encoded(buffer *b, const char *s, size_t s_len, buffer_encoding_t encoding);
void buffer_append_string_encoded(buffer * restrict b, const char * restrict s, size_t s_len, buffer_encoding_t encoding);
/* escape non-printable characters; simple escapes for \t, \r, \n; fallback to \xCC */
void buffer_append_string_c_escaped(buffer *b, const char *s, size_t s_len);
void buffer_append_string_c_escaped(buffer * restrict b, const char * restrict s, size_t s_len);
/* to upper case, replace non alpha-numerics with '_'; if is_http_header prefix with "HTTP_" unless s is "content-type" */
void buffer_copy_string_encoded_cgi_varnames(buffer *b, const char *s, size_t s_len, int is_http_header);
void buffer_copy_string_encoded_cgi_varnames(buffer * restrict b, const char * restrict s, size_t s_len, int is_http_header);
void buffer_urldecode_path(buffer *url);
void buffer_urldecode_query(buffer *url);
@ -203,7 +203,7 @@ __attribute_pure__
static inline uint32_t buffer_string_space(const buffer *b); /* maximum length of string that can be stored without reallocating */
static inline void buffer_append_slash(buffer *b); /* append '/' no non-empty strings not ending in '/' */
void buffer_append_path_len(buffer *b, const char *a, size_t alen); /* join strings with '/', if '/' not present */
void buffer_append_path_len(buffer * restrict b, const char * restrict a, size_t alen); /* join strings with '/', if '/' not present */
#define BUFFER_APPEND_STRING_CONST(x, y) \
buffer_append_string_len(x, y, sizeof(y) - 1)
@ -242,11 +242,11 @@ static inline uint32_t buffer_string_space(const buffer *b) {
return NULL != b && b->size ? b->size - (b->used | (0 == b->used)) : 0;
}
static inline void buffer_copy_buffer(buffer *b, const buffer *src) {
static inline void buffer_copy_buffer(buffer * restrict b, const buffer * restrict src) {
buffer_copy_string_len(b, CONST_BUF_LEN(src));
}
static inline void buffer_append_string_buffer(buffer *b, const buffer *src) {
static inline void buffer_append_string_buffer(buffer * restrict b, const buffer * restrict src) {
buffer_append_string_len(b, CONST_BUF_LEN(src));
}

36
src/chunk.c

@ -242,12 +242,12 @@ void chunkqueue_free(chunkqueue *cq) {
free(cq);
}
static void chunkqueue_prepend_chunk(chunkqueue *cq, chunk *c) {
static void chunkqueue_prepend_chunk(chunkqueue * const restrict cq, chunk * const restrict c) {
if (NULL == (c->next = cq->first)) cq->last = c;
cq->first = c;
}
static void chunkqueue_append_chunk(chunkqueue *cq, chunk *c) {
static void chunkqueue_append_chunk(chunkqueue * const restrict cq, chunk * const restrict c) {
c->next = NULL;
*(cq->last ? &cq->last->next : &cq->first) = c;
cq->last = c;
@ -268,7 +268,7 @@ static chunk * chunkqueue_append_mem_chunk(chunkqueue *cq, size_t sz) {
}
__attribute_returns_nonnull__
static chunk * chunkqueue_append_file_chunk(chunkqueue *cq, const buffer *fn, off_t offset, off_t len) {
static chunk * chunkqueue_append_file_chunk(chunkqueue * const restrict cq, const buffer * const restrict fn, off_t offset, off_t len) {
chunk *c = chunk_acquire(buffer_string_length(fn)+1);
chunkqueue_append_chunk(cq, c);
c->type = FILE_CHUNK;
@ -286,7 +286,7 @@ void chunkqueue_reset(chunkqueue *cq) {
cq->tempdir_idx = 0;
}
void chunkqueue_append_file_fd(chunkqueue *cq, const buffer *fn, int fd, off_t offset, off_t len) {
void chunkqueue_append_file_fd(chunkqueue * const restrict cq, const buffer * const restrict fn, int fd, off_t offset, off_t len) {
if (len > 0) {
(chunkqueue_append_file_chunk(cq, fn, offset, len))->file.fd = fd;
}
@ -295,14 +295,14 @@ void chunkqueue_append_file_fd(chunkqueue *cq, const buffer *fn, int fd, off_t o
}
}
void chunkqueue_append_file(chunkqueue *cq, const buffer *fn, off_t offset, off_t len) {
void chunkqueue_append_file(chunkqueue * const restrict cq, const buffer * const restrict fn, off_t offset, off_t len) {
if (len > 0) {
chunkqueue_append_file_chunk(cq, fn, offset, len);
}
}
static int chunkqueue_append_mem_extend_chunk(chunkqueue *cq, const char *mem, size_t len) {
static int chunkqueue_append_mem_extend_chunk(chunkqueue * const restrict cq, const char * const restrict mem, size_t len) {
chunk *c = cq->last;
if (0 == len) return 1;
if (c != NULL && c->type == MEM_CHUNK
@ -315,7 +315,7 @@ static int chunkqueue_append_mem_extend_chunk(chunkqueue *cq, const char *mem, s
}
void chunkqueue_append_buffer(chunkqueue *cq, buffer *mem) {
void chunkqueue_append_buffer(chunkqueue * const restrict cq, buffer * const restrict mem) {
chunk *c;
size_t len = buffer_string_length(mem);
if (len < 256 && chunkqueue_append_mem_extend_chunk(cq, mem->ptr, len)) return;
@ -326,7 +326,7 @@ void chunkqueue_append_buffer(chunkqueue *cq, buffer *mem) {
}
void chunkqueue_append_mem(chunkqueue *cq, const char * mem, size_t len) {
void chunkqueue_append_mem(chunkqueue * const restrict cq, const char * const restrict mem, size_t len) {
chunk *c;
if (len < chunk_buf_sz && chunkqueue_append_mem_extend_chunk(cq, mem, len))
return;
@ -337,7 +337,7 @@ void chunkqueue_append_mem(chunkqueue *cq, const char * mem, size_t len) {
}
void chunkqueue_append_mem_min(chunkqueue *cq, const char * mem, size_t len) {
void chunkqueue_append_mem_min(chunkqueue * const restrict cq, const char * const restrict mem, size_t len) {
chunk *c;
if (len < chunk_buf_sz && chunkqueue_append_mem_extend_chunk(cq, mem, len))
return;
@ -349,7 +349,7 @@ void chunkqueue_append_mem_min(chunkqueue *cq, const char * mem, size_t len) {
}
void chunkqueue_append_chunkqueue(chunkqueue *cq, chunkqueue *src) {
void chunkqueue_append_chunkqueue(chunkqueue * const restrict cq, chunkqueue * const restrict src) {
if (src == NULL || NULL == src->first) return;
if (NULL == cq->first) {
@ -401,7 +401,7 @@ void chunkqueue_append_buffer_commit(chunkqueue *cq) {
static void chunkqueue_remove_empty_chunks(chunkqueue *cq);
char * chunkqueue_get_memory(chunkqueue *cq, size_t *len) {
char * chunkqueue_get_memory(chunkqueue * const restrict cq, size_t * const restrict len) {
size_t sz = *len ? *len : (chunk_buf_sz >> 1);
buffer *b;
chunk *c = cq->last;
@ -421,7 +421,7 @@ char * chunkqueue_get_memory(chunkqueue *cq, size_t *len) {
return b->ptr;
}
void chunkqueue_use_memory(chunkqueue *cq, chunk *ckpt, size_t len) {
void chunkqueue_use_memory(chunkqueue * const restrict cq, chunk *ckpt, size_t len) {
buffer *b = cq->last->mem;
if (len > 0) {
@ -450,7 +450,7 @@ void chunkqueue_set_tempdirs_default (const array *tempdirs, off_t upload_temp_f
: upload_temp_file_size;
}
void chunkqueue_set_tempdirs(chunkqueue *cq, const array *tempdirs, off_t upload_temp_file_size) {
void chunkqueue_set_tempdirs(chunkqueue * const restrict cq, const array * const restrict tempdirs, off_t upload_temp_file_size) {
force_assert(NULL != cq);
cq->tempdirs = tempdirs;
cq->upload_temp_file_size
@ -460,7 +460,7 @@ void chunkqueue_set_tempdirs(chunkqueue *cq, const array *tempdirs, off_t upload
cq->tempdir_idx = 0;
}
void chunkqueue_steal(chunkqueue *dest, chunkqueue *src, off_t len) {
void chunkqueue_steal(chunkqueue * const restrict dest, chunkqueue * const restrict src, off_t len) {
while (len > 0) {
chunk *c = src->first;
off_t clen = 0, use;
@ -507,7 +507,7 @@ void chunkqueue_steal(chunkqueue *dest, chunkqueue *src, off_t len) {
}
}
static chunk *chunkqueue_get_append_tempfile(chunkqueue *cq, log_error_st *errh) {
static chunk *chunkqueue_get_append_tempfile(chunkqueue * const restrict cq, log_error_st * const restrict errh) {
chunk *c;
buffer *template = buffer_init_string("/var/tmp/lighttpd-upload-XXXXXX");
int fd = -1;
@ -544,7 +544,7 @@ static chunk *chunkqueue_get_append_tempfile(chunkqueue *cq, log_error_st *errh)
return c;
}
int chunkqueue_append_mem_to_tempfile(chunkqueue *dest, const char *mem, size_t len, log_error_st *errh) {
int chunkqueue_append_mem_to_tempfile(chunkqueue * const restrict dest, const char * restrict mem, size_t len, log_error_st * const restrict errh) {
chunk *dst_c;
ssize_t written;
@ -637,7 +637,7 @@ int chunkqueue_append_mem_to_tempfile(chunkqueue *dest, const char *mem, size_t
return -1;
}
int chunkqueue_steal_with_tempfiles(chunkqueue *dest, chunkqueue *src, off_t len, log_error_st *errh) {
int chunkqueue_steal_with_tempfiles(chunkqueue * const restrict dest, chunkqueue * const restrict src, off_t len, log_error_st * const restrict errh) {
while (len > 0) {
chunk *c = src->first;
off_t clen = 0, use;
@ -783,7 +783,7 @@ void chunkqueue_compact_mem(chunkqueue *cq, size_t clen) {
* no data added/removed from chunkqueue; consolidated only */
}
int chunkqueue_open_file_chunk(chunkqueue *cq, log_error_st *errh) {
int chunkqueue_open_file_chunk(chunkqueue * const restrict cq, log_error_st * const restrict errh) {
chunk* const c = cq->first;
off_t offset, toSend;
struct stat st;

26
src/chunk.h

@ -63,13 +63,13 @@ chunkqueue *chunkqueue_init(void);
void chunkqueue_set_chunk_size (size_t sz);
void chunkqueue_set_tempdirs_default_reset (void);
void chunkqueue_set_tempdirs_default (const array *tempdirs, off_t upload_temp_file_size);
void chunkqueue_set_tempdirs(chunkqueue *cq, const array *tempdirs, off_t upload_temp_file_size);
void chunkqueue_append_file(chunkqueue *cq, const buffer *fn, off_t offset, off_t len); /* copies "fn" */
void chunkqueue_append_file_fd(chunkqueue *cq, const buffer *fn, int fd, off_t offset, off_t len); /* copies "fn" */
void chunkqueue_append_mem(chunkqueue *cq, const char *mem, size_t len); /* copies memory */
void chunkqueue_append_mem_min(chunkqueue *cq, const char * mem, size_t len); /* copies memory */
void chunkqueue_append_buffer(chunkqueue *cq, buffer *mem); /* may reset "mem" */
void chunkqueue_append_chunkqueue(chunkqueue *cq, chunkqueue *src);
void chunkqueue_set_tempdirs(chunkqueue * restrict cq, const array * restrict tempdirs, off_t upload_temp_file_size);
void chunkqueue_append_file(chunkqueue * restrict cq, const buffer * restrict fn, off_t offset, off_t len); /* copies "fn" */
void chunkqueue_append_file_fd(chunkqueue * restrict cq, const buffer * restrict fn, int fd, off_t offset, off_t len); /* copies "fn" */
void chunkqueue_append_mem(chunkqueue * restrict cq, const char * restrict mem, size_t len); /* copies memory */
void chunkqueue_append_mem_min(chunkqueue * restrict cq, const char * restrict mem, size_t len); /* copies memory */
void chunkqueue_append_buffer(chunkqueue * restrict cq, buffer * restrict mem); /* may reset "mem" */
void chunkqueue_append_chunkqueue(chunkqueue * restrict cq, chunkqueue * restrict src);
__attribute_returns_nonnull__
buffer * chunkqueue_prepend_buffer_open_sz(chunkqueue *cq, size_t sz);
@ -87,7 +87,7 @@ buffer * chunkqueue_append_buffer_open(chunkqueue *cq);
void chunkqueue_append_buffer_commit(chunkqueue *cq);
int chunkqueue_append_mem_to_tempfile(chunkqueue *cq, const char *mem, size_t len, struct log_error_st *errh);
int chunkqueue_append_mem_to_tempfile(chunkqueue * restrict cq, const char * restrict mem, size_t len, struct log_error_st * const restrict errh);
/* functions to handle buffers to read into: */
/* obtain/reserve memory in chunkqueue at least len (input) size,
@ -98,9 +98,9 @@ int chunkqueue_append_mem_to_tempfile(chunkqueue *cq, const char *mem, size_t le
* pass 0 in len for mem at least half of chunk_buf_sz
*/
__attribute_returns_nonnull__
char * chunkqueue_get_memory(chunkqueue *cq, size_t *len);
char * chunkqueue_get_memory(chunkqueue * restrict cq, size_t * restrict len);
/* commit len bytes of mem obtained from chunkqueue_get_memory() */
void chunkqueue_use_memory(chunkqueue *cq, chunk *ckpt, size_t len);
void chunkqueue_use_memory(chunkqueue * restrict cq, chunk *ckpt, size_t len);
/* mark first "len" bytes as written (incrementing chunk offsets)
* and remove finished chunks
@ -109,10 +109,10 @@ void chunkqueue_mark_written(chunkqueue *cq, off_t len);
void chunkqueue_remove_finished_chunks(chunkqueue *cq);
void chunkqueue_steal(chunkqueue *dest, chunkqueue *src, off_t len);
int chunkqueue_steal_with_tempfiles(chunkqueue *dest, chunkqueue *src, off_t len, struct log_error_st *errh);
void chunkqueue_steal(chunkqueue * restrict dest, chunkqueue * restrict src, off_t len);
int chunkqueue_steal_with_tempfiles(chunkqueue * restrict dest, chunkqueue * restrict src, off_t len, struct log_error_st * const restrict errh);
int chunkqueue_open_file_chunk(chunkqueue *cq, struct log_error_st *errh);
int chunkqueue_open_file_chunk(chunkqueue * restrict cq, struct log_error_st * const restrict errh);
void chunkqueue_compact_mem(chunkqueue *cq, size_t clen);

18
src/request.c

@ -346,7 +346,7 @@ static int request_uri_is_valid_char(const unsigned char c) {
__attribute_cold__
__attribute_noinline__
static int http_request_header_line_invalid(request_st * const r, const int status, const char * const msg) {
static int http_request_header_line_invalid(request_st * const restrict r, const int status, const char * const restrict msg) {
if (r->conf.log_request_header_on_error) {
if (msg) log_error(r->conf.errh, __FILE__, __LINE__, "%s", msg);
}
@ -355,7 +355,7 @@ static int http_request_header_line_invalid(request_st * const r, const int stat
__attribute_cold__
__attribute_noinline__
static int http_request_header_char_invalid(request_st * const r, const char ch, const char * const msg) {
static int http_request_header_char_invalid(request_st * const restrict r, const char ch, const char * const restrict msg) {
if (r->conf.log_request_header_on_error) {
if ((unsigned char)ch > 32 && ch != 127) {
log_error(r->conf.errh, __FILE__, __LINE__, "%s ('%c')", msg, ch);
@ -373,7 +373,7 @@ static int http_request_header_char_invalid(request_st * const r, const char ch,
*
* returns 0 on success, HTTP status on error
*/
static int http_request_parse_single_header(request_st * const r, const enum http_header_e id, const char * const k, const size_t klen, const char * const v, const size_t vlen) {
static int http_request_parse_single_header(request_st * const restrict r, const enum http_header_e id, const char * const restrict k, const size_t klen, const char * const restrict v, const size_t vlen) {
buffer **saveb = NULL;
/*
@ -486,7 +486,7 @@ static int http_request_parse_single_header(request_st * const r, const enum htt
}
__attribute_cold__
static int http_request_parse_proto_loose(request_st * const r, const char * const ptr, const size_t len, const unsigned int http_parseopts) {
static int http_request_parse_proto_loose(request_st * const restrict r, const char * const restrict ptr, const size_t len, const unsigned int http_parseopts) {
const char * proto = memchr(ptr, ' ', len);
if (NULL == proto)
return http_request_header_line_invalid(r, 400, "incomplete request line -> 400");
@ -516,7 +516,7 @@ static int http_request_parse_proto_loose(request_st * const r, const char * con
}
__attribute_cold__
static const char * http_request_parse_uri_alt(request_st * const r, const char * const uri, const size_t len, const unsigned int http_parseopts) {
static const char * http_request_parse_uri_alt(request_st * const restrict r, const char * const restrict uri, const size_t len, const unsigned int http_parseopts) {
const char *nuri;
if ((len > 7 && buffer_eq_icase_ssn(uri, "http://", 7)
&& NULL != (nuri = memchr(uri + 7, '/', len-7)))
@ -544,7 +544,7 @@ static const char * http_request_parse_uri_alt(request_st * const r, const char
}
}
static int http_request_parse_reqline(request_st * const r, const char * const ptr, const unsigned short * const hoff, const unsigned int http_parseopts) {
static int http_request_parse_reqline(request_st * const restrict r, const char * const restrict ptr, const unsigned short * const restrict hoff, const unsigned int http_parseopts) {
size_t len = hoff[2];
/* parse the first line of the request
@ -644,7 +644,7 @@ static int http_request_parse_reqline(request_st * const r, const char * const p
__attribute_cold__
__attribute_noinline__
static int http_request_parse_header_other(request_st * const r, const char * const k, const int klen, const unsigned int http_header_strict) {
static int http_request_parse_header_other(request_st * const restrict r, const char * const restrict k, const int klen, const unsigned int http_header_strict) {
for (int i = 0; i < klen; ++i) {
if (light_isalpha(k[i]) || k[i] == '-') continue; /*(common cases)*/
/**
@ -682,7 +682,7 @@ static int http_request_parse_header_other(request_st * const r, const char * co
return 0;
}
static int http_request_parse_headers(request_st * const r, char * const ptr, const unsigned short * const hoff, const unsigned int http_parseopts) {
static int http_request_parse_headers(request_st * const restrict r, char * const restrict ptr, const unsigned short * const restrict hoff, const unsigned int http_parseopts) {
const unsigned int http_header_strict = (http_parseopts & HTTP_PARSEOPT_HEADER_STRICT);
#if 0 /*(not checked here; will later result in invalid label for HTTP header)*/
@ -790,7 +790,7 @@ static int http_request_parse_headers(request_st * const r, char * const ptr, co
return 0;
}
int http_request_parse(request_st * const r, char * const hdrs, const unsigned short * const hoff, const int scheme_port) {
int http_request_parse(request_st * const restrict r, char * const restrict hdrs, const unsigned short * const restrict hoff, const int scheme_port) {
/*
* Request: "^(GET|POST|HEAD|...) ([^ ]+(\\?[^ ]+|)) (HTTP/1\\.[01])$"
* Header : "^([-a-zA-Z]+): (.+)$"

2
src/request.h

@ -177,7 +177,7 @@ struct request_st {
};
int http_request_parse(request_st *r, char *hdrs, const unsigned short *hloffsets, int scheme_port);
int http_request_parse(request_st * restrict r, char * restrict hdrs, const unsigned short * restrict hloffsets, int scheme_port);
int http_request_host_normalize(buffer *b, int scheme_port);
int http_request_host_policy(buffer *b, unsigned int http_parseopts, int scheme_port);

21
src/sock_addr.c

@ -185,7 +185,7 @@ int sock_addr_is_addr_eq_bits(const sock_addr *a, const sock_addr *b, int bits)
}
int sock_addr_assign (sock_addr *saddr, int family, unsigned short nport, const void *naddr)
int sock_addr_assign (sock_addr * const restrict saddr, int family, unsigned short nport, const void * const restrict naddr)
{
switch (family) {
case AF_INET:
@ -223,7 +223,8 @@ int sock_addr_assign (sock_addr *saddr, int family, unsigned short nport, const
}
int sock_addr_inet_pton(sock_addr *saddr, const char *str,
int sock_addr_inet_pton(sock_addr * const restrict saddr,
const char * const restrict str,
int family, unsigned short port)
{
switch (family) {
@ -250,7 +251,7 @@ int sock_addr_inet_pton(sock_addr *saddr, const char *str,
}
const char * sock_addr_inet_ntop(const sock_addr *saddr, char *buf, socklen_t sz)
const char * sock_addr_inet_ntop(const sock_addr * const restrict saddr, char * const restrict buf, socklen_t sz)
{
switch (saddr->plain.sa_family) {
case AF_INET:
@ -274,7 +275,7 @@ const char * sock_addr_inet_ntop(const sock_addr *saddr, char *buf, socklen_t sz
}
int sock_addr_inet_ntop_copy_buffer(buffer *b, const sock_addr *saddr)
int sock_addr_inet_ntop_copy_buffer(buffer * const restrict b, const sock_addr * const restrict saddr)
{
/*(incur cost of extra copy to avoid potential extra memory allocation)*/
char buf[UNIX_PATH_MAX];
@ -285,7 +286,7 @@ int sock_addr_inet_ntop_copy_buffer(buffer *b, const sock_addr *saddr)
}
int sock_addr_inet_ntop_append_buffer(buffer *b, const sock_addr *saddr)
int sock_addr_inet_ntop_append_buffer(buffer * const restrict b, const sock_addr * const restrict saddr)
{
/*(incur cost of extra copy to avoid potential extra memory allocation)*/
char buf[UNIX_PATH_MAX];
@ -295,7 +296,7 @@ int sock_addr_inet_ntop_append_buffer(buffer *b, const sock_addr *saddr)
return 0;
}
int sock_addr_stringify_append_buffer(buffer *b, const sock_addr *saddr)
int sock_addr_stringify_append_buffer(buffer * const restrict b, const sock_addr * const restrict saddr)
{
switch (saddr->plain.sa_family) {
case AF_INET:
@ -330,7 +331,7 @@ int sock_addr_stringify_append_buffer(buffer *b, const sock_addr *saddr)
}
int sock_addr_nameinfo_append_buffer(buffer *b, const sock_addr *saddr, log_error_st *errh)
int sock_addr_nameinfo_append_buffer(buffer * const restrict b, const sock_addr * const restrict saddr, log_error_st * const restrict errh)
{
/*(this routine originates from
* http-header-glue.c:http_response_redirect_to_directory())*/
@ -377,7 +378,7 @@ int sock_addr_nameinfo_append_buffer(buffer *b, const sock_addr *saddr, log_erro
}
int sock_addr_from_str_hints(sock_addr *saddr, socklen_t *len, const char *str, int family, unsigned short port, log_error_st *errh)
int sock_addr_from_str_hints(sock_addr * const restrict saddr, socklen_t * const restrict len, const char * const restrict str, int family, unsigned short port, log_error_st * const restrict errh)
{
/*(note: name resolution here is *blocking*)*/
switch(family) {
@ -559,7 +560,7 @@ int sock_addr_from_str_hints(sock_addr *saddr, socklen_t *len, const char *str,
}
int sock_addr_from_str_numeric(sock_addr *saddr, const char *str, log_error_st *errh)
int sock_addr_from_str_numeric(sock_addr * const restrict saddr, const char * const restrict str, log_error_st * const restrict errh)
{
/*(note: does not handle port if getaddrinfo() is not available)*/
/*(note: getaddrinfo() is stricter than inet_aton() in what is accepted)*/
@ -622,7 +623,7 @@ int sock_addr_from_str_numeric(sock_addr *saddr, const char *str, log_error_st *
}
int sock_addr_from_buffer_hints_numeric(sock_addr *saddr, socklen_t *len, const buffer *b, int family, unsigned short port, log_error_st *errh)
int sock_addr_from_buffer_hints_numeric(sock_addr * const restrict saddr, socklen_t * const restrict len, const buffer * const restrict b, int family, unsigned short port, log_error_st * const restrict errh)
{
/*(this routine originates from mod_fastcgi.c and mod_scgi.c)*/
if (buffer_string_is_empty(b)) {

41
src/sock_addr.h

@ -21,31 +21,48 @@ union sock_addr {
};
__attribute_pure__
static inline int sock_addr_get_family (const sock_addr *saddr);
static inline int sock_addr_get_family (const sock_addr *saddr) {
return saddr->plain.sa_family;
}
__attribute_pure__
unsigned short sock_addr_get_port (const sock_addr *saddr);
__attribute_pure__
int sock_addr_is_addr_wildcard (const sock_addr *saddr);
__attribute_pure__
int sock_addr_is_family_eq (const sock_addr *saddr1, const sock_addr *saddr2);
__attribute_pure__
int sock_addr_is_port_eq (const sock_addr *saddr1, const sock_addr *saddr2);
__attribute_pure__
int sock_addr_is_addr_eq (const sock_addr *saddr1, const sock_addr *saddr2);
/*int sock_addr_is_addr_port_eq (const sock_addr *saddr1, const sock_addr *saddr2);*/
int sock_addr_is_addr_eq_bits(const sock_addr *a, const sock_addr *b, int bits);
int sock_addr_assign (sock_addr *saddr, int family, unsigned short nport, const void *naddr);
int sock_addr_inet_pton(sock_addr *saddr, const char *str, int family, unsigned short port);
#if 0
__attribute_pure__
int sock_addr_is_addr_port_eq (const sock_addr *saddr1, const sock_addr *saddr2);
#endif
__attribute_pure__
int sock_addr_is_addr_eq_bits(const sock_addr * restrict a, const sock_addr * restrict b, int bits);
int sock_addr_assign (sock_addr * restrict saddr, int family, unsigned short nport, const void * restrict naddr);
int sock_addr_inet_pton(sock_addr * restrict saddr, const char * restrict str, int family, unsigned short port);
const char * sock_addr_inet_ntop(const sock_addr *saddr, char *buf, socklen_t sz);
int sock_addr_inet_ntop_copy_buffer(buffer *b, const sock_addr *saddr);
int sock_addr_inet_ntop_append_buffer(buffer *b, const sock_addr *saddr);
int sock_addr_stringify_append_buffer(buffer *b, const sock_addr *saddr);
int sock_addr_nameinfo_append_buffer(buffer *b, const sock_addr *saddr, log_error_st *errh);
const char * sock_addr_inet_ntop(const sock_addr * restrict saddr, char * restrict buf, socklen_t sz);
int sock_addr_inet_ntop_copy_buffer(buffer * restrict b, const sock_addr * restrict saddr);
int sock_addr_inet_ntop_append_buffer(buffer * restrict b, const sock_addr * restrict saddr);
int sock_addr_stringify_append_buffer(buffer * restrict b, const sock_addr * restrict saddr);
int sock_addr_nameinfo_append_buffer(buffer * restrict b, const sock_addr * restrict saddr, log_error_st * restrict errh);
int sock_addr_from_buffer_hints_numeric(sock_addr *saddr, socklen_t *len, const buffer *b, int family, unsigned short port, log_error_st *errh);
int sock_addr_from_str_hints(sock_addr *saddr, socklen_t *len, const char *str, int family, unsigned short port, log_error_st *errh);
int sock_addr_from_str_numeric(sock_addr *saddr, const char *str, log_error_st *errh);
int sock_addr_from_buffer_hints_numeric(sock_addr * restrict saddr, socklen_t * restrict len, const buffer * restrict b, int family, unsigned short port, log_error_st * restrict errh);
int sock_addr_from_str_hints(sock_addr * restrict saddr, socklen_t * restrict len, const char * restrict str, int family, unsigned short port, log_error_st * restrict errh);
int sock_addr_from_str_numeric(sock_addr * restrict saddr, const char * restrict str, log_error_st * restrict errh);
#endif
Loading…
Cancel
Save