dynbuf.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #ifndef HEADER_CURL_DYNBUF_H
  2. #define HEADER_CURL_DYNBUF_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at https://curl.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. * SPDX-License-Identifier: curl
  24. *
  25. ***************************************************************************/
  26. #include <curl/curl.h>
  27. struct dynbuf {
  28. char *bufr; /* point to a null-terminated allocated buffer */
  29. size_t leng; /* number of bytes *EXCLUDING* the null-terminator */
  30. size_t allc; /* size of the current allocation */
  31. size_t toobig; /* size limit for the buffer */
  32. #ifdef DEBUGBUILD
  33. int init; /* detect API usage mistakes */
  34. #endif
  35. };
  36. void curlx_dyn_init(struct dynbuf *s, size_t toobig);
  37. void curlx_dyn_free(struct dynbuf *s);
  38. CURLcode curlx_dyn_addn(struct dynbuf *s, const void *mem, size_t len)
  39. WARN_UNUSED_RESULT;
  40. CURLcode curlx_dyn_add(struct dynbuf *s, const char *str)
  41. WARN_UNUSED_RESULT;
  42. CURLcode curlx_dyn_addf(struct dynbuf *s, const char *fmt, ...)
  43. WARN_UNUSED_RESULT CURL_PRINTF(2, 3);
  44. CURLcode curlx_dyn_vaddf(struct dynbuf *s, const char *fmt, va_list ap)
  45. WARN_UNUSED_RESULT CURL_PRINTF(2, 0);
  46. void curlx_dyn_reset(struct dynbuf *s);
  47. CURLcode curlx_dyn_tail(struct dynbuf *s, size_t trail);
  48. CURLcode curlx_dyn_setlen(struct dynbuf *s, size_t set);
  49. char *curlx_dyn_ptr(const struct dynbuf *s);
  50. unsigned char *curlx_dyn_uptr(const struct dynbuf *s);
  51. size_t curlx_dyn_len(const struct dynbuf *s);
  52. /* returns 0 on success, -1 on error */
  53. /* The implementation of this function exists in mprintf.c */
  54. int curlx_dyn_vprintf(struct dynbuf *dyn, const char *format, va_list ap_save);
  55. /* Take the buffer out of the dynbuf. Caller has ownership and
  56. * dynbuf resets to initial state. */
  57. char *curlx_dyn_take(struct dynbuf *s, size_t *plen);
  58. /* Dynamic buffer max sizes */
  59. #define MAX_DYNBUF_SIZE (SIZE_T_MAX/2)
  60. #define DYN_DOH_RESPONSE 3000
  61. #define DYN_DOH_CNAME 256
  62. #define DYN_PAUSE_BUFFER (64 * 1024 * 1024)
  63. #define DYN_HAXPROXY 2048
  64. #define DYN_HTTP_REQUEST (1024*1024)
  65. #define DYN_APRINTF 8000000
  66. #define DYN_RTSP_REQ_HEADER (64*1024)
  67. #define DYN_TRAILERS (64*1024)
  68. #define DYN_PROXY_CONNECT_HEADERS 16384
  69. #define DYN_QLOG_NAME 1024
  70. #define DYN_H1_TRAILER 4096
  71. #define DYN_PINGPPONG_CMD (64*1024)
  72. #define DYN_IMAP_CMD (64*1024)
  73. #define DYN_MQTT_RECV (64*1024)
  74. #define DYN_MQTT_SEND 0xFFFFFFF
  75. #define DYN_CRLFILE_SIZE (400*1024*1024) /* 400mb */
  76. #define DYN_CERTFILE_SIZE (100*1024) /* 100KiB */
  77. #define DYN_KEYFILE_SIZE (100*1024) /* 100KiB */
  78. #endif