CLEANUP: Use ist2(const void*, size_t) whenever possible

Refactoring performed with the following Coccinelle patch:

    @@
    struct ist i;
    expression p, l;
    @@

    - i.ptr = p;
    - i.len = l;
    + i = ist2(p, l);
This commit is contained in:
Tim Duesterhus 2021-02-28 16:11:36 +01:00 committed by Christopher Faulet
parent 9e647e5af7
commit 92c696e663
8 changed files with 18 additions and 32 deletions

View File

@ -242,8 +242,8 @@ static void _51d_set_headers(struct sample *smp, fiftyoneDegreesWorkset *ws)
ALREADY_CHECKED(htx);
for (i = 0; i < global_51degrees.header_count; i++) {
name.ptr = (global_51degrees.header_names + i)->area;
name.len = (global_51degrees.header_names + i)->data;
name = ist2((global_51degrees.header_names + i)->area,
(global_51degrees.header_names + i)->data);
ctx.blk = NULL;
if (http_find_header(htx, name, &ctx, 1)) {
@ -281,8 +281,8 @@ static void _51d_set_device_offsets(struct sample *smp, fiftyoneDegreesDeviceOff
ALREADY_CHECKED(htx);
for (i = 0; i < global_51degrees.header_count; i++) {
name.ptr = (global_51degrees.header_names + i)->area;
name.len = (global_51degrees.header_names + i)->data;
name = ist2((global_51degrees.header_names + i)->area,
(global_51degrees.header_names + i)->data);
ctx.blk = NULL;
if (http_find_header(htx, name, &ctx, 1)) {

View File

@ -105,8 +105,7 @@ int dns_send_nameserver(struct dns_nameserver *ns, void *buf, size_t len)
if (errno == EAGAIN) {
struct ist myist;
myist.ptr = buf;
myist.len = len;
myist = ist2(buf, len);
ret = ring_write(ns->dgram->ring_req, DNS_TCP_MSG_MAX_SIZE, NULL, 0, &myist, 1);
if (!ret) {
ns->counters->snd_error++;
@ -125,8 +124,7 @@ int dns_send_nameserver(struct dns_nameserver *ns, void *buf, size_t len)
else if (ns->stream) {
struct ist myist;
myist.ptr = buf;
myist.len = len;
myist = ist2(buf, len);
ret = ring_write(ns->stream->ring_req, DNS_TCP_MSG_MAX_SIZE, NULL, 0, &myist, 1);
if (!ret) {
ns->counters->snd_error++;
@ -1123,8 +1121,7 @@ static struct task *dns_process_req(struct task *t, void *context, unsigned shor
len = b_getblk(buf, dns_msg_trash, msg_len, ofs + cnt);
myist.ptr = dns_msg_trash;
myist.len = len;
myist = ist2(dns_msg_trash, len);
ads = NULL;
/* try to push request into active sess with free slot */

View File

@ -770,8 +770,7 @@ static int smp_fetch_fhdr(const struct arg *args, struct sample *smp, const char
if (args[0].type != ARGT_STR)
return 0;
name.ptr = args[0].data.str.area;
name.len = args[0].data.str.data;
name = ist2(args[0].data.str.area, args[0].data.str.data);
if (args[1].type == ARGT_SINT)
occ = args[1].data.sint;
@ -817,11 +816,9 @@ static int smp_fetch_fhdr_cnt(const struct arg *args, struct sample *smp, const
return 0;
if (args->type == ARGT_STR) {
name.ptr = args->data.str.area;
name.len = args->data.str.data;
name = ist2(args->data.str.area, args->data.str.data);
} else {
name.ptr = NULL;
name.len = 0;
name = ist2(NULL, 0);
}
ctx.blk = NULL;
@ -899,8 +896,7 @@ static int smp_fetch_hdr(const struct arg *args, struct sample *smp, const char
if (args[0].type != ARGT_STR)
return 0;
name.ptr = args[0].data.str.area;
name.len = args[0].data.str.data;
name = ist2(args[0].data.str.area, args[0].data.str.data);
if (args[1].type == ARGT_SINT)
occ = args[1].data.sint;
@ -956,11 +952,9 @@ static int smp_fetch_hdr_cnt(const struct arg *args, struct sample *smp, const c
return 0;
if (args->type == ARGT_STR) {
name.ptr = args->data.str.area;
name.len = args->data.str.data;
name = ist2(args->data.str.area, args->data.str.data);
} else {
name.ptr = NULL;
name.len = 0;
name = ist2(NULL, 0);
}
ctx.blk = NULL;

View File

@ -2915,8 +2915,7 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t
while (spc < end && !HTTP_IS_SPHT(*spc))
spc++;
path.ptr = uri;
path.len = spc - uri;
path = ist2(uri, spc - uri);
// extract relative path without query params from url
path = iststop(http_get_path(path), '?');

View File

@ -3585,8 +3585,7 @@ static int add_hdr_case_adjust(const char *from, const char *to, char **err)
}
entry->node.key = strdup(from);
entry->name.ptr = strdup(to);
entry->name.len = strlen(to);
entry->name = ist2(strdup(to), strlen(to));
if (!entry->node.key || !entry->name.ptr) {
free(entry->node.key);
istfree(&entry->name);

View File

@ -5366,8 +5366,7 @@ static size_t h2s_bck_make_req_headers(struct h2s *h2s, struct htx *htx)
uri.len -= len + 3;
/* find the auth part of the URI */
auth.ptr = uri.ptr;
auth.len = 0;
auth = ist2(uri.ptr, 0);
while (auth.len < uri.len && auth.ptr[auth.len] != '/')
auth.len++;

View File

@ -216,8 +216,7 @@ void __trace(enum trace_level level, uint64_t mask, struct trace_source *src,
b_reset(&trace_buf);
b_istput(&trace_buf, msg);
cb(level, mask, src, where, ist_func, a1, a2, a3, a4);
line[words].ptr = trace_buf.area;
line[words].len = trace_buf.data;
line[words] = ist2(trace_buf.area, trace_buf.data);
words++;
}
else {

View File

@ -742,8 +742,7 @@ static const char *ha_wurfl_retrieve_header(const char *header_name, const void
return NULL;
}
name.ptr = (char *)header_name;
name.len = strlen(header_name);
name = ist2((char *)header_name, strlen(header_name));
// If 4th param is set, it works on full-line headers in whose comma is not a delimiter but is
// part of the syntax