mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 07:37:02 +02:00
CLEANUP: Use the ist() macro whenever possible
Refactoring performed with the following Coccinelle patch: @@ char *s; @@ ( - ist2(s, strlen(s)) + ist(s) | - ist2(strdup(s), strlen(s)) + ist(strdup(s)) ) Note that this replacement is safe even in the strdup() case, because `ist()` will not call `strlen()` on a `NULL` pointer. Instead is inserts a length of `0`, effectively resulting in `IST_NULL`.
This commit is contained in:
parent
f8b4292560
commit
dcf753aabe
@ -1851,7 +1851,7 @@ static int srv_parse_check_proto(char **args, int *cur_arg,
|
||||
memprintf(err, "'%s' : missing value", args[*cur_arg]);
|
||||
goto error;
|
||||
}
|
||||
newsrv->check.mux_proto = get_mux_proto(ist2(args[*cur_arg + 1], strlen(args[*cur_arg + 1])));
|
||||
newsrv->check.mux_proto = get_mux_proto(ist(args[*cur_arg + 1]));
|
||||
if (!newsrv->check.mux_proto) {
|
||||
memprintf(err, "'%s' : unknown MUX protocol '%s'", args[*cur_arg], args[*cur_arg+1]);
|
||||
goto error;
|
||||
|
@ -854,7 +854,7 @@ static int cfg_parse_fcgi_app(const char *file, int linenum, char **args, int kw
|
||||
if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
|
||||
goto out;
|
||||
istfree(&curapp->docroot);
|
||||
curapp->docroot = ist2(strdup(args[1]), strlen(args[1]));
|
||||
curapp->docroot = ist(strdup(args[1]));
|
||||
if (!isttest(curapp->docroot)) {
|
||||
ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
|
||||
err_code |= ERR_ALERT | ERR_ABORT;
|
||||
@ -887,7 +887,7 @@ static int cfg_parse_fcgi_app(const char *file, int linenum, char **args, int kw
|
||||
if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
|
||||
goto out;
|
||||
istfree(&curapp->index);
|
||||
curapp->index = ist2(strdup(args[1]), strlen(args[1]));
|
||||
curapp->index = ist(strdup(args[1]));
|
||||
if (!isttest(curapp->index)) {
|
||||
ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
|
||||
err_code |= ERR_ALERT | ERR_ABORT;
|
||||
|
@ -2733,7 +2733,7 @@ int http_res_set_status(unsigned int status, struct ist reason, struct stream *s
|
||||
/* Do we have a custom reason format string? */
|
||||
if (!isttest(reason)) {
|
||||
const char *str = http_get_reason(status);
|
||||
reason = ist2(str, strlen(str));
|
||||
reason = ist(str);
|
||||
}
|
||||
|
||||
if (!http_replace_res_status(htx, ist2(trash.area, trash.data), reason))
|
||||
|
@ -1496,7 +1496,7 @@ static int bind_parse_proto(char **args, int cur_arg, struct proxy *px, struct b
|
||||
return ERR_ALERT | ERR_FATAL;
|
||||
}
|
||||
|
||||
proto = ist2(args[cur_arg + 1], strlen(args[cur_arg + 1]));
|
||||
proto = ist(args[cur_arg + 1]);
|
||||
conf->mux_proto = get_mux_proto(proto);
|
||||
if (!conf->mux_proto) {
|
||||
memprintf(err, "'%s' : unknown MUX protocol '%s'", args[cur_arg], args[cur_arg+1]);
|
||||
|
@ -1269,7 +1269,7 @@ static int fcgi_set_default_param(struct fcgi_conn *fconn, struct fcgi_strm *fst
|
||||
if (addr_to_str(cli_conn->dst, b_tail(params->p), b_room(params->p)) != -1)
|
||||
ptr = b_tail(params->p);
|
||||
if (ptr) {
|
||||
params->srv_name = ist2(ptr, strlen(ptr));
|
||||
params->srv_name = ist(ptr);
|
||||
params->p->data += params->srv_name.len;
|
||||
}
|
||||
}
|
||||
@ -1281,7 +1281,7 @@ static int fcgi_set_default_param(struct fcgi_conn *fconn, struct fcgi_strm *fst
|
||||
if (addr_to_str(cli_conn->src, b_tail(params->p), b_room(params->p)) != -1)
|
||||
ptr = b_tail(params->p);
|
||||
if (ptr) {
|
||||
params->rem_addr = ist2(ptr, strlen(ptr));
|
||||
params->rem_addr = ist(ptr);
|
||||
params->p->data += params->rem_addr.len;
|
||||
}
|
||||
}
|
||||
|
@ -3585,7 +3585,7 @@ static int add_hdr_case_adjust(const char *from, const char *to, char **err)
|
||||
}
|
||||
|
||||
entry->node.key = strdup(from);
|
||||
entry->name = ist2(strdup(to), strlen(to));
|
||||
entry->name = ist(strdup(to));
|
||||
if (!entry->node.key || !isttest(entry->name)) {
|
||||
free(entry->node.key);
|
||||
istfree(&entry->name);
|
||||
|
@ -551,7 +551,7 @@ static int srv_parse_proto(char **args, int *cur_arg,
|
||||
memprintf(err, "'%s' : missing value", args[*cur_arg]);
|
||||
return ERR_ALERT | ERR_FATAL;
|
||||
}
|
||||
proto = ist2(args[*cur_arg + 1], strlen(args[*cur_arg + 1]));
|
||||
proto = ist(args[*cur_arg + 1]);
|
||||
newsrv->mux_proto = get_mux_proto(proto);
|
||||
if (!newsrv->mux_proto) {
|
||||
memprintf(err, "'%s' : unknown MUX protocol '%s'", args[*cur_arg], args[*cur_arg+1]);
|
||||
|
@ -4057,7 +4057,7 @@ static int stats_send_http_headers(struct stream_interface *si, struct htx *htx)
|
||||
|
||||
if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) {
|
||||
const char *refresh = U2A(uri->refresh);
|
||||
if (!htx_add_header(htx, ist("Refresh"), ist2(refresh, strlen(refresh))))
|
||||
if (!htx_add_header(htx, ist("Refresh"), ist(refresh)))
|
||||
goto full;
|
||||
}
|
||||
|
||||
|
@ -2273,7 +2273,7 @@ struct tcpcheck_rule *parse_tcpcheck_connect(char **args, int cur_arg, struct pr
|
||||
memprintf(errmsg, "'%s' expects a MUX protocol as argument.", args[cur_arg]);
|
||||
goto error;
|
||||
}
|
||||
mux_proto = get_mux_proto(ist2(args[cur_arg+1], strlen(args[cur_arg+1])));
|
||||
mux_proto = get_mux_proto(ist(args[cur_arg + 1]));
|
||||
if (!mux_proto) {
|
||||
memprintf(errmsg, "'%s' : unknown MUX protocol '%s'.", args[cur_arg], args[cur_arg+1]);
|
||||
goto error;
|
||||
@ -2439,7 +2439,7 @@ struct tcpcheck_rule *parse_tcpcheck_send(char **args, int cur_arg, struct proxy
|
||||
|
||||
switch (chk->send.type) {
|
||||
case TCPCHK_SEND_STRING:
|
||||
chk->send.data = ist2(strdup(data), strlen(data));
|
||||
chk->send.data = ist(strdup(data));
|
||||
if (!isttest(chk->send.data)) {
|
||||
memprintf(errmsg, "out of memory");
|
||||
goto error;
|
||||
@ -2535,8 +2535,8 @@ struct tcpcheck_rule *parse_tcpcheck_send_http(char **args, int cur_arg, struct
|
||||
strcasecmp(args[cur_arg+1], "transfer-encoding") == 0)
|
||||
goto skip_hdr;
|
||||
|
||||
hdrs[i].n = ist2(args[cur_arg+1], strlen(args[cur_arg+1]));
|
||||
hdrs[i].v = ist2(args[cur_arg+2], strlen(args[cur_arg+2]));
|
||||
hdrs[i].n = ist(args[cur_arg + 1]);
|
||||
hdrs[i].v = ist(args[cur_arg + 2]);
|
||||
i++;
|
||||
skip_hdr:
|
||||
cur_arg += 2;
|
||||
@ -2605,7 +2605,7 @@ struct tcpcheck_rule *parse_tcpcheck_send_http(char **args, int cur_arg, struct
|
||||
}
|
||||
}
|
||||
else {
|
||||
chk->send.http.uri = ist2(strdup(uri), strlen(uri));
|
||||
chk->send.http.uri = ist(strdup(uri));
|
||||
if (!isttest(chk->send.http.uri)) {
|
||||
memprintf(errmsg, "out of memory");
|
||||
goto error;
|
||||
@ -2613,7 +2613,7 @@ struct tcpcheck_rule *parse_tcpcheck_send_http(char **args, int cur_arg, struct
|
||||
}
|
||||
}
|
||||
if (vsn) {
|
||||
chk->send.http.vsn = ist2(strdup(vsn), strlen(vsn));
|
||||
chk->send.http.vsn = ist(strdup(vsn));
|
||||
if (!isttest(chk->send.http.vsn)) {
|
||||
memprintf(errmsg, "out of memory");
|
||||
goto error;
|
||||
@ -2649,7 +2649,7 @@ struct tcpcheck_rule *parse_tcpcheck_send_http(char **args, int cur_arg, struct
|
||||
}
|
||||
}
|
||||
else {
|
||||
chk->send.http.body = ist2(strdup(body), strlen(body));
|
||||
chk->send.http.body = ist(strdup(body));
|
||||
if (!isttest(chk->send.http.body)) {
|
||||
memprintf(errmsg, "out of memory");
|
||||
goto error;
|
||||
@ -3174,7 +3174,7 @@ struct tcpcheck_rule *parse_tcpcheck_expect(char **args, int cur_arg, struct pro
|
||||
}
|
||||
case TCPCHK_EXPECT_STRING:
|
||||
case TCPCHK_EXPECT_HTTP_BODY:
|
||||
chk->expect.data = ist2(strdup(pattern), strlen(pattern));
|
||||
chk->expect.data = ist(strdup(pattern));
|
||||
if (!isttest(chk->expect.data)) {
|
||||
memprintf(errmsg, "out of memory");
|
||||
goto error;
|
||||
@ -3229,7 +3229,7 @@ struct tcpcheck_rule *parse_tcpcheck_expect(char **args, int cur_arg, struct pro
|
||||
}
|
||||
}
|
||||
else {
|
||||
chk->expect.hdr.name = ist2(strdup(npat), strlen(npat));
|
||||
chk->expect.hdr.name = ist(strdup(npat));
|
||||
if (!isttest(chk->expect.hdr.name)) {
|
||||
memprintf(errmsg, "out of memory");
|
||||
goto error;
|
||||
@ -3259,7 +3259,7 @@ struct tcpcheck_rule *parse_tcpcheck_expect(char **args, int cur_arg, struct pro
|
||||
}
|
||||
}
|
||||
else {
|
||||
chk->expect.hdr.value = ist2(strdup(vpat), strlen(vpat));
|
||||
chk->expect.hdr.value = ist(strdup(vpat));
|
||||
if (!isttest(chk->expect.hdr.value)) {
|
||||
memprintf(errmsg, "out of memory");
|
||||
goto error;
|
||||
@ -3621,7 +3621,7 @@ int add_tcpcheck_expect_str(struct tcpcheck_rules *rules, const char *str)
|
||||
expect->ok_status = HCHK_STATUS_L7OKD;
|
||||
expect->err_status = HCHK_STATUS_L7RSP;
|
||||
expect->tout_status = HCHK_STATUS_L7TOUT;
|
||||
expect->data = ist2(strdup(str), strlen(str));
|
||||
expect->data = ist(strdup(str));
|
||||
if (!isttest(expect->data)) {
|
||||
pool_free(pool_head_tcpcheck_rule, tcpcheck);
|
||||
return 0;
|
||||
@ -4766,14 +4766,14 @@ static struct tcpcheck_rule *proxy_parse_httpchk_req(char **args, int cur_arg, s
|
||||
}
|
||||
}
|
||||
if (uri) {
|
||||
chk->send.http.uri = ist2(strdup(uri), strlen(uri));
|
||||
chk->send.http.uri = ist(strdup(uri));
|
||||
if (!isttest(chk->send.http.uri)) {
|
||||
memprintf(errmsg, "out of memory");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
if (vsn) {
|
||||
chk->send.http.vsn = ist2(strdup(vsn), strlen(vsn));
|
||||
chk->send.http.vsn = ist(strdup(vsn));
|
||||
if (!isttest(chk->send.http.vsn)) {
|
||||
memprintf(errmsg, "out of memory");
|
||||
goto error;
|
||||
@ -4820,7 +4820,7 @@ static struct tcpcheck_rule *proxy_parse_httpchk_req(char **args, int cur_arg, s
|
||||
|
||||
/* Copy the body */
|
||||
if (body) {
|
||||
chk->send.http.body = ist2(strdup(body), strlen(body));
|
||||
chk->send.http.body = ist(strdup(body));
|
||||
if (!isttest(chk->send.http.body)) {
|
||||
memprintf(errmsg, "out of memory");
|
||||
goto error;
|
||||
|
Loading…
Reference in New Issue
Block a user