dynbuf.h (3376B)
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, <daniel@haxx.se>, 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 27 #include <curl/curl.h> 28 29 struct dynbuf { 30 char *bufr; /* point to a null-terminated allocated buffer */ 31 size_t leng; /* number of bytes *EXCLUDING* the null-terminator */ 32 size_t allc; /* size of the current allocation */ 33 size_t toobig; /* size limit for the buffer */ 34 #ifdef DEBUGBUILD 35 int init; /* detect API usage mistakes */ 36 #endif 37 }; 38 39 void curlx_dyn_init(struct dynbuf *s, size_t toobig); 40 void curlx_dyn_free(struct dynbuf *s); 41 CURLcode curlx_dyn_addn(struct dynbuf *s, const void *mem, size_t len) 42 WARN_UNUSED_RESULT; 43 CURLcode curlx_dyn_add(struct dynbuf *s, const char *str) 44 WARN_UNUSED_RESULT; 45 CURLcode curlx_dyn_addf(struct dynbuf *s, const char *fmt, ...) 46 WARN_UNUSED_RESULT CURL_PRINTF(2, 3); 47 CURLcode curlx_dyn_vaddf(struct dynbuf *s, const char *fmt, va_list ap) 48 WARN_UNUSED_RESULT CURL_PRINTF(2, 0); 49 void curlx_dyn_reset(struct dynbuf *s); 50 CURLcode curlx_dyn_tail(struct dynbuf *s, size_t trail); 51 CURLcode curlx_dyn_setlen(struct dynbuf *s, size_t set); 52 char *curlx_dyn_ptr(const struct dynbuf *s); 53 unsigned char *curlx_dyn_uptr(const struct dynbuf *s); 54 size_t curlx_dyn_len(const struct dynbuf *s); 55 56 /* returns 0 on success, -1 on error */ 57 /* The implementation of this function exists in mprintf.c */ 58 int curlx_dyn_vprintf(struct dynbuf *dyn, const char *format, va_list ap_save); 59 60 /* Take the buffer out of the dynbuf. Caller has ownership and 61 * dynbuf resets to initial state. */ 62 char *curlx_dyn_take(struct dynbuf *s, size_t *plen); 63 64 /* Dynamic buffer max sizes */ 65 #define MAX_DYNBUF_SIZE (SIZE_T_MAX/2) 66 67 #define DYN_DOH_RESPONSE 3000 68 #define DYN_DOH_CNAME 256 69 #define DYN_PAUSE_BUFFER (64 * 1024 * 1024) 70 #define DYN_HAXPROXY 2048 71 #define DYN_HTTP_REQUEST (1024*1024) 72 #define DYN_APRINTF 8000000 73 #define DYN_RTSP_REQ_HEADER (64*1024) 74 #define DYN_TRAILERS (64*1024) 75 #define DYN_PROXY_CONNECT_HEADERS 16384 76 #define DYN_QLOG_NAME 1024 77 #define DYN_H1_TRAILER 4096 78 #define DYN_PINGPPONG_CMD (64*1024) 79 #define DYN_IMAP_CMD (64*1024) 80 #define DYN_MQTT_RECV (64*1024) 81 #define DYN_MQTT_SEND 0xFFFFFFF 82 #define DYN_CRLFILE_SIZE (400*1024*1024) /* 400mb */ 83 #define DYN_CERTFILE_SIZE (100*1024) /* 100KiB */ 84 #define DYN_KEYFILE_SIZE (100*1024) /* 100KiB */ 85 #endif