• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef HEADER_CURL_DYNBUF_H
2 #define HEADER_CURL_DYNBUF_H
3 /***************************************************************************
4  *                                  _   _ ____  _
5  *  Project                     ___| | | |  _ \| |
6  *                             / __| | | | |_) | |
7  *                            | (__| |_| |  _ <| |___
8  *                             \___|\___/|_| \_\_____|
9  *
10  * Copyright (C) 2020, 2021, 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  ***************************************************************************/
24 
25 #ifndef BUILDING_LIBCURL
26 /* this renames the functions so that the tool code can use the same code
27    without getting symbol collisions */
28 #define Curl_dyn_init(a,b) curlx_dyn_init(a,b)
29 #define Curl_dyn_add(a,b) curlx_dyn_add(a,b)
30 #define Curl_dyn_addn(a,b,c) curlx_dyn_addn(a,b,c)
31 #define Curl_dyn_addf curlx_dyn_addf
32 #define Curl_dyn_vaddf curlx_dyn_vaddf
33 #define Curl_dyn_free(a) curlx_dyn_free(a)
34 #define Curl_dyn_ptr(a) curlx_dyn_ptr(a)
35 #define Curl_dyn_uptr(a) curlx_dyn_uptr(a)
36 #define Curl_dyn_len(a) curlx_dyn_len(a)
37 #define Curl_dyn_reset(a) curlx_dyn_reset(a)
38 #define Curl_dyn_tail(a,b) curlx_dyn_tail(a,b)
39 #define curlx_dynbuf dynbuf /* for the struct name */
40 #endif
41 
42 struct dynbuf {
43   char *bufr;    /* point to a null-terminated allocated buffer */
44   size_t leng;   /* number of bytes *EXCLUDING* the zero terminator */
45   size_t allc;   /* size of the current allocation */
46   size_t toobig; /* size limit for the buffer */
47 #ifdef DEBUGBUILD
48   int init;     /* detect API usage mistakes */
49 #endif
50 };
51 
52 void Curl_dyn_init(struct dynbuf *s, size_t toobig);
53 void Curl_dyn_free(struct dynbuf *s);
54 CURLcode Curl_dyn_addn(struct dynbuf *s, const void *mem, size_t len)
55   WARN_UNUSED_RESULT;
56 CURLcode Curl_dyn_add(struct dynbuf *s, const char *str)
57   WARN_UNUSED_RESULT;
58 CURLcode Curl_dyn_addf(struct dynbuf *s, const char *fmt, ...)
59   WARN_UNUSED_RESULT;
60 CURLcode Curl_dyn_vaddf(struct dynbuf *s, const char *fmt, va_list ap)
61   WARN_UNUSED_RESULT;
62 void Curl_dyn_reset(struct dynbuf *s);
63 CURLcode Curl_dyn_tail(struct dynbuf *s, size_t trail);
64 char *Curl_dyn_ptr(const struct dynbuf *s);
65 unsigned char *Curl_dyn_uptr(const struct dynbuf *s);
66 size_t Curl_dyn_len(const struct dynbuf *s);
67 
68 /* returns 0 on success, -1 on error */
69 /* The implementation of this function exists in mprintf.c */
70 int Curl_dyn_vprintf(struct dynbuf *dyn, const char *format, va_list ap_save);
71 
72 /* Dynamic buffer max sizes */
73 #define DYN_DOH_RESPONSE    3000
74 #define DYN_DOH_CNAME       256
75 #define DYN_PAUSE_BUFFER    (64 * 1024 * 1024)
76 #define DYN_HAXPROXY        2048
77 #define DYN_HTTP_REQUEST    (1024*1024)
78 #define DYN_H2_HEADERS      (128*1024)
79 #define DYN_H2_TRAILERS     (128*1024)
80 #define DYN_APRINTF         8000000
81 #define DYN_RTSP_REQ_HEADER (64*1024)
82 #define DYN_TRAILERS        (64*1024)
83 #define DYN_PROXY_CONNECT_HEADERS 16384
84 #define DYN_QLOG_NAME       1024
85 #define DYN_H1_TRAILER      4096
86 #define DYN_PINGPPONG_CMD   (64*1024)
87 #define DYN_IMAP_CMD        (64*1024)
88 #endif
89