]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: buffer: make b_getblk_nc() take const pointers
authorWilly Tarreau <w@1wt.eu>
Thu, 14 Jun 2018 13:27:31 +0000 (15:27 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 19 Jul 2018 14:23:41 +0000 (16:23 +0200)
Now that there are no more users requiring to modify the buffer anymore,
switch these ones to const char and const buffer. This will make it more
obvious next time send functions are tempted to modify the buffer's output
count. Minor adaptations were necessary at a few call places which were
using char due to the function's previous prototype.

include/common/buf.h
include/proto/channel.h
src/channel.c
src/hlua.c
src/mux_h2.c

index be196f17857dfc34a7ee4bf26f8b4bfdb58cf463..488c4064fe9cbd9b0c220feec823ebc375aece69 100644 (file)
@@ -352,7 +352,7 @@ static inline size_t b_getblk(const struct buffer *buf, char *blk, size_t len, s
  *   =0 : not enough data available. <blk*> are left undefined.
  * The buffer is left unaffected. Unused buffers are left in an undefined state.
  */
-static inline size_t b_getblk_nc(struct buffer *buf, char **blk1, int *len1, char **blk2, int *len2, size_t ofs, size_t max)
+static inline size_t b_getblk_nc(const struct buffer *buf, const char **blk1, int *len1, const char **blk2, int *len2, size_t ofs, size_t max)
 {
        size_t l1;
 
index fdbcc9415ae048ef1e27b1c876cb19d25fe7deff..eedeaaea9d5e144ad8b6af7b69f7d524d9d5386b 100644 (file)
@@ -53,8 +53,8 @@ int ci_getblk_nc(const struct channel *chn, char **blk1, int *len1, char **blk2,
 int co_inject(struct channel *chn, const char *msg, int len);
 int co_getline(const struct channel *chn, char *str, int len);
 int co_getblk(const struct channel *chn, char *blk, int len, int offset);
-int co_getline_nc(const struct channel *chn, char **blk1, int *len1, char **blk2, int *len2);
-int co_getblk_nc(const struct channel *chn, char **blk1, int *len1, char **blk2, int *len2);
+int co_getline_nc(const struct channel *chn, const char **blk1, int *len1, const char **blk2, int *len2);
+int co_getblk_nc(const struct channel *chn, const char **blk1, int *len1, const char **blk2, int *len2);
 
 
 /* returns a pointer to the stream the channel belongs to */
index b7200246d5e80ffcec781b7c262f9225fb03ea08..3b0592f507a5665c3584e1c9520d02bacddfb8ce 100644 (file)
@@ -312,7 +312,7 @@ int co_getblk(const struct channel *chn, char *blk, int len, int offset)
  * The channel status is not changed. The caller must call co_skip() to
  * update it. Unused buffers are left in an undefined state.
  */
-int co_getblk_nc(const struct channel *chn, char **blk1, int *len1, char **blk2, int *len2)
+int co_getblk_nc(const struct channel *chn, const char **blk1, int *len1, const char **blk2, int *len2)
 {
        if (unlikely(chn->buf->o == 0)) {
                if (chn->flags & CF_SHUTW)
@@ -333,8 +333,8 @@ int co_getblk_nc(const struct channel *chn, char **blk1, int *len1, char **blk2,
  * the '\n'. Unused buffers are left in an undefined state.
  */
 int co_getline_nc(const struct channel *chn,
-                  char **blk1, int *len1,
-                  char **blk2, int *len2)
+                  const char **blk1, int *len1,
+                  const char **blk2, int *len2)
 {
        int retcode;
        int l;
index 967f05e3ab66592ecb544bc6703c0955d01a1367..eb27ebc7ea16f484374d984ab5315fec2ba49397 100644 (file)
@@ -1738,9 +1738,9 @@ __LJMP static int hlua_socket_receive_yield(struct lua_State *L, int status, lua
        struct appctx *appctx;
        int len;
        int nblk;
-       char *blk1;
+       const char *blk1;
        int len1;
-       char *blk2;
+       const char *blk2;
        int len2;
        int skip_at_end = 0;
        struct channel *oc;
@@ -3633,9 +3633,9 @@ __LJMP static int hlua_applet_tcp_getline_yield(lua_State *L, int status, lua_KC
        struct hlua_appctx *appctx = MAY_LJMP(hlua_checkapplet_tcp(L, 1));
        struct stream_interface *si = appctx->appctx->owner;
        int ret;
-       char *blk1;
+       const char *blk1;
        int len1;
-       char *blk2;
+       const char *blk2;
        int len2;
 
        /* Read the maximum amount of data avalaible. */
@@ -3688,9 +3688,9 @@ __LJMP static int hlua_applet_tcp_recv_yield(lua_State *L, int status, lua_KCont
        struct stream_interface *si = appctx->appctx->owner;
        int len = MAY_LJMP(luaL_checkinteger(L, 2));
        int ret;
-       char *blk1;
+       const char *blk1;
        int len1;
-       char *blk2;
+       const char *blk2;
        int len2;
 
        /* Read the maximum amount of data avalaible. */
@@ -4096,9 +4096,9 @@ __LJMP static int hlua_applet_http_getline_yield(lua_State *L, int status, lua_K
        struct stream_interface *si = appctx->appctx->owner;
        struct channel *chn = si_ic(si);
        int ret;
-       char *blk1;
+       const char *blk1;
        int len1;
-       char *blk2;
+       const char *blk2;
        int len2;
 
        /* Maybe we cant send a 100-continue ? */
@@ -4182,9 +4182,9 @@ __LJMP static int hlua_applet_http_recv_yield(lua_State *L, int status, lua_KCon
        int len = MAY_LJMP(luaL_checkinteger(L, 2));
        struct channel *chn = si_ic(si);
        int ret;
-       char *blk1;
+       const char *blk1;
        int len1;
-       char *blk2;
+       const char *blk2;
        int len2;
 
        /* Maybe we cant send a 100-continue ? */
@@ -6626,9 +6626,9 @@ static void hlua_applet_http_fct(struct appctx *ctx)
        struct act_rule *rule = ctx->rule;
        struct proxy *px = strm->be;
        struct hlua *hlua = ctx->ctx.hlua_apphttp.hlua;
-       char *blk1;
+       const char *blk1;
        int len1;
-       char *blk2;
+       const char *blk2;
        int len2;
        int ret;
 
index ce39aea0039782e7d68058421c9e65ae6957617a..ec5554b178c3c6fc1680050bc8bc8ba06cf6f93b 100644 (file)
@@ -2945,7 +2945,7 @@ static int h2_rcv_buf(struct conn_stream *cs, struct buffer *buf, int count)
  * number of bytes sent. The caller must check the stream's status to detect
  * any error which might have happened subsequently to a successful send.
  */
-static size_t h2s_frt_make_resp_headers(struct h2s *h2s, struct buffer *buf, size_t ofs, size_t max)
+static size_t h2s_frt_make_resp_headers(struct h2s *h2s, const struct buffer *buf, size_t ofs, size_t max)
 {
        struct http_hdr list[MAX_HTTP_HDR];
        struct h2c *h2c = h2s->h2c;
@@ -3118,7 +3118,7 @@ static size_t h2s_frt_make_resp_headers(struct h2s *h2s, struct buffer *buf, siz
  * the number of bytes sent. The caller must check the stream's status to
  * detect any error which might have happened subsequently to a successful send.
  */
-static size_t h2s_frt_make_resp_data(struct h2s *h2s, struct buffer *buf, size_t ofs, size_t max)
+static size_t h2s_frt_make_resp_data(struct h2s *h2s, const struct buffer *buf, size_t ofs, size_t max)
 {
        struct h2c *h2c = h2s->h2c;
        struct h1m *h1m = &h2s->res;
@@ -3127,7 +3127,7 @@ static size_t h2s_frt_make_resp_data(struct h2s *h2s, struct buffer *buf, size_t
        size_t total = 0;
        int es_now = 0;
        int size = 0;
-       char *blk1, *blk2;
+       const char *blk1, *blk2;
        int len1, len2;
 
        if (h2c_mux_busy(h2c, h2s)) {