lighttpd 1.4.x https://www.lighttpd.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.3 KiB

fix buffer, chunk and http_chunk API * remove unused structs and functions (buffer_array, read_buffer) * change return type from int to void for many functions, as the return value (indicating error/success) was never checked, and the function would only fail on programming errors and not on invalid input; changed functions to use force_assert instead of returning an error. * all "len" parameters now are the real size of the memory to be read. the length of strings is given always without the terminating 0. * the "buffer" struct still counts the terminating 0 in ->used, provide buffer_string_length() to get the length of a string in a buffer. unset config "strings" have used == 0, which is used in some places to distinguish unset values from "" (empty string) values. * most buffer usages should now use it as string container. * optimise some buffer copying by "moving" data to other buffers * use (u)intmax_t for generic int-to-string functions * remove unused enum values: UNUSED_CHUNK, ENCODING_UNSET * converted BUFFER_APPEND_SLASH to inline function (no macro feature needed) * refactor: create chunkqueue_steal: moving (partial) chunks into another queue * http_chunk: added separate function to terminate chunked body instead of magic handling in http_chunk_append_mem(). http_chunk_append_* now handle empty chunks, and never terminate the chunked body. From: Stefan Bühler <stbuehler@web.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2975 152afb58-edef-0310-8abb-c4023f1b3aa9
7 years ago
  1. #include "first.h"
  2. #include "array.h"
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. static data_unset *data_array_copy(const data_unset *s) {
  7. data_array *src = (data_array *)s;
  8. data_array *ds = data_array_init();
  9. buffer_copy_buffer(ds->key, src->key);
  10. array_free(ds->value);
  11. ds->value = array_init_array(src->value);
  12. ds->is_index_key = src->is_index_key;
  13. return (data_unset *)ds;
  14. }
  15. static void data_array_free(data_unset *d) {
  16. data_array *ds = (data_array *)d;
  17. buffer_free(ds->key);
  18. array_free(ds->value);
  19. free(d);
  20. }
  21. static void data_array_reset(data_unset *d) {
  22. data_array *ds = (data_array *)d;
  23. /* reused array elements */
  24. buffer_reset(ds->key);
  25. array_reset(ds->value);
  26. }
  27. static int data_array_insert_dup(data_unset *dst, data_unset *src) {
  28. UNUSED(dst);
  29. src->free(src);
  30. return 0;
  31. }
  32. static void data_array_print(const data_unset *d, int depth) {
  33. data_array *ds = (data_array *)d;
  34. array_print(ds->value, depth);
  35. }
  36. data_array *data_array_init(void) {
  37. data_array *ds;
  38. ds = calloc(1, sizeof(*ds));
  39. force_assert(NULL != ds);
  40. ds->key = buffer_init();
  41. ds->value = array_init();
  42. ds->copy = data_array_copy;
  43. ds->free = data_array_free;
  44. ds->reset = data_array_reset;
  45. ds->insert_dup = data_array_insert_dup;
  46. ds->print = data_array_print;
  47. ds->type = TYPE_ARRAY;
  48. return ds;
  49. }