Skip to content

Commit 030e6ab

Browse files
pwhelanedsiper
authored andcommitted
in_calyptia_fleet: use more understandable variable names.
Signed-off-by: Phillip Whelan <[email protected]>
1 parent 87ca611 commit 030e6ab

File tree

1 file changed

+51
-39
lines changed

1 file changed

+51
-39
lines changed

plugins/in_calyptia_fleet/in_calyptia_fleet.c

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -81,60 +81,61 @@ struct flb_in_calyptia_fleet_config {
8181
int collect_fd;
8282
};
8383

84-
static char *find_case_header(struct flb_http_client *c, const char *header)
84+
static char *find_case_header(struct flb_http_client *cli, const char *header)
8585
{
86-
char *p;
86+
char *ptr;
8787
char *headstart;
8888

8989

90-
headstart = strstr(c->resp.data, "\r\n");
90+
headstart = strstr(cli->resp.data, "\r\n");
9191

9292
if (headstart == NULL) {
9393
return NULL;
9494
}
9595

9696
/* Lookup the beginning of the header */
97-
for (p = headstart; p != NULL && p+2 < c->resp.payload; p = strstr(p, "\r\n")) {
97+
for (ptr = headstart; ptr != NULL && ptr+2 < cli->resp.payload; ptr = strstr(ptr, "\r\n")) {
9898

99-
if (p + 4 < c->resp.payload && strcmp(p, "\r\n\r\n") == 0) {
99+
if (ptr + 4 < cli->resp.payload && strcmp(ptr, "\r\n\r\n") == 0) {
100100
return NULL;
101101
}
102102

103-
p+=2;
103+
ptr+=2;
104104

105105
// no space left for header
106-
if (p + strlen(header)+2 >= c->resp.payload) {
106+
if (ptr + strlen(header)+2 >= cli->resp.payload) {
107107
return NULL;
108108
}
109109

110110
// matched header and the delimiter
111-
if (strncasecmp(p, header, strlen(header)) == 0) {
111+
if (strncasecmp(ptr, header, strlen(header)) == 0) {
112112

113-
if (p[strlen(header)] == ':' && p[strlen(header)+1] == ' ') {
114-
return p;
113+
if (ptr[strlen(header)] == ':' && ptr[strlen(header)+1] == ' ') {
114+
return ptr;
115115
}
116116
}
117117
}
118+
118119
return NULL;
119120
}
120121

121122
/* Try to find a header value in the buffer. Copied from flb_http_client.c. */
122-
static int case_header_lookup(struct flb_http_client *c,
123+
static int case_header_lookup(struct flb_http_client *cli,
123124
const char *header, int header_len,
124125
const char **out_val, int *out_len)
125126
{
126-
char *p;
127+
char *ptr;
127128
char *crlf;
128129
char *end;
129130

130-
if (!c->resp.data) {
131+
if (!cli->resp.data) {
131132
return -1;
132133
}
133134

134-
p = find_case_header(c, header);
135-
end = strstr(c->resp.data, "\r\n\r\n");
135+
ptr = find_case_header(cli, header);
136+
end = strstr(cli->resp.data, "\r\n\r\n");
136137

137-
if (!p) {
138+
if (!ptr) {
138139

139140
if (end) {
140141
/* The headers are complete but the header is not there */
@@ -146,21 +147,21 @@ static int case_header_lookup(struct flb_http_client *c,
146147
}
147148

148149
/* Exclude matches in the body */
149-
if (end && p > end) {
150+
if (end && ptr > end) {
150151
return -1;
151152
}
152153

153154
/* Lookup CRLF (end of line \r\n) */
154-
crlf = strstr(p, "\r\n");
155+
crlf = strstr(ptr, "\r\n");
155156

156157
if (!crlf) {
157158
return -1;
158159
}
159160

160-
p += header_len + 2;
161+
ptr += header_len + 2;
161162

162-
*out_val = p;
163-
*out_len = (crlf - p);
163+
*out_val = ptr;
164+
*out_len = (crlf - ptr);
164165

165166
return 0;
166167
}
@@ -177,10 +178,12 @@ static flb_sds_t fleet_config_filename(struct flb_in_calyptia_fleet_config *ctx,
177178
cfgname = flb_sds_create_size(4096);
178179

179180
if (ctx->fleet_name != NULL) {
180-
flb_sds_printf(&cfgname, "%s" PATH_SEPARATOR "%s" PATH_SEPARATOR "%s.ini", ctx->config_dir, ctx->fleet_name, fname);
181+
flb_sds_printf(&cfgname, "%s" PATH_SEPARATOR "%s" PATH_SEPARATOR "%s.ini",
182+
ctx->config_dir, ctx->fleet_name, fname);
181183
}
182184
else {
183-
flb_sds_printf(&cfgname, "%s" PATH_SEPARATOR "%s" PATH_SEPARATOR "%s.ini", ctx->config_dir, ctx->fleet_id, fname);
185+
flb_sds_printf(&cfgname, "%s" PATH_SEPARATOR "%s" PATH_SEPARATOR "%s.ini",
186+
ctx->config_dir, ctx->fleet_id, fname);
184187
}
185188

186189
return cfgname;
@@ -289,10 +292,12 @@ static int exists_cur_fleet_config(struct flb_in_calyptia_fleet_config *ctx)
289292
static void *do_reload(void *data)
290293
{
291294
struct reload_ctx *reload = (struct reload_ctx *)data;
295+
292296
// avoid reloading the current configuration... just use our new one!
293297
flb_context_set(reload->flb);
294298
reload->flb->config->enable_hot_reload = FLB_TRUE;
295299
reload->flb->config->conf_path_file = reload->cfg_path;
300+
296301
sleep(5);
297302
kill(getpid(), SIGHUP);
298303

@@ -302,7 +307,7 @@ static void *do_reload(void *data)
302307
static int test_config_is_valid(flb_sds_t cfgpath)
303308
{
304309
struct flb_config *config;
305-
struct flb_cf *cf;
310+
struct flb_cf *conf;
306311
int ret = FLB_FALSE;
307312

308313

@@ -312,19 +317,19 @@ static int test_config_is_valid(flb_sds_t cfgpath)
312317
goto config_init_error;
313318
}
314319

315-
cf = flb_cf_create();
320+
conf = flb_cf_create();
316321

317-
if (cf == NULL) {
322+
if (conf == NULL) {
318323
goto cf_create_error;
319324
}
320325

321-
cf = flb_cf_create_from_file(cf, cfgpath);
326+
conf = flb_cf_create_from_file(conf, cfgpath);
322327

323-
if (cf == NULL) {
328+
if (conf == NULL) {
324329
goto cf_create_from_file_error;
325330
}
326331

327-
if (flb_config_load_config_format(config, cf)) {
332+
if (flb_config_load_config_format(config, conf)) {
328333
goto cf_load_config_format_error;
329334
}
330335

@@ -337,7 +342,7 @@ static int test_config_is_valid(flb_sds_t cfgpath)
337342
cf_property_check_error:
338343
cf_load_config_format_error:
339344
cf_create_from_file_error:
340-
flb_cf_destroy(cf);
345+
flb_cf_destroy(conf);
341346
cf_create_error:
342347
flb_config_exit(config);
343348
config_init_error:
@@ -399,7 +404,7 @@ static flb_sds_t parse_api_key_json(struct flb_in_calyptia_fleet_config *ctx,
399404
msgpack_object_kv *cur;
400405
msgpack_object_str *key;
401406
flb_sds_t project_id;
402-
int i = 0;
407+
int idx = 0;
403408

404409
/* Initialize packer */
405410
flb_pack_state_init(&pack_state);
@@ -426,8 +431,8 @@ static flb_sds_t parse_api_key_json(struct flb_in_calyptia_fleet_config *ctx,
426431
while (msgpack_unpack_next(&result, pack, out_size, &off) == MSGPACK_UNPACK_SUCCESS) {
427432

428433
if (result.data.type == MSGPACK_OBJECT_MAP) {
429-
for (i = 0; i < result.data.via.map.size; i++) {
430-
cur = &result.data.via.map.ptr[i];
434+
for (idx = 0; idx < result.data.via.map.size; idx++) {
435+
cur = &result.data.via.map.ptr[idx];
431436
key = &cur->key.via.str;
432437

433438
if (strncmp(key->ptr, "ProjectID", key->size) == 0) {
@@ -437,10 +442,13 @@ static flb_sds_t parse_api_key_json(struct flb_in_calyptia_fleet_config *ctx,
437442
msgpack_unpacked_destroy(&result);
438443
return NULL;
439444
}
445+
440446
project_id = flb_sds_create_len(cur->val.via.str.ptr,
441447
cur->val.via.str.size);
448+
442449
msgpack_unpacked_destroy(&result);
443450
flb_free(pack);
451+
444452
return project_id;
445453
}
446454
}
@@ -465,7 +473,7 @@ static ssize_t parse_fleet_search_json(struct flb_in_calyptia_fleet_config *ctx,
465473
msgpack_object_array *results;
466474
msgpack_object_kv *cur;
467475
msgpack_object_str *key;
468-
int i = 0;
476+
int idx = 0;
469477

470478
/* Initialize packer */
471479
flb_pack_state_init(&pack_state);
@@ -495,8 +503,9 @@ static ssize_t parse_fleet_search_json(struct flb_in_calyptia_fleet_config *ctx,
495503
results = &result.data.via.array;
496504

497505
if (results->ptr[0].type == MSGPACK_OBJECT_MAP) {
498-
for (i = 0; i < results->ptr[0].via.map.size; i++) {
499-
cur = &results->ptr[0].via.map.ptr[i];
506+
507+
for (idx = 0; idx < results->ptr[0].via.map.size; idx++) {
508+
cur = &results->ptr[0].via.map.ptr[idx];
500509
key = &cur->key.via.str;
501510

502511
if (strncasecmp(key->ptr, "id", key->size) == 0) {
@@ -506,6 +515,7 @@ static ssize_t parse_fleet_search_json(struct flb_in_calyptia_fleet_config *ctx,
506515
msgpack_unpacked_destroy(&result);
507516
return -1;
508517
}
518+
509519
ctx->fleet_id = flb_sds_create_len(cur->val.via.str.ptr,
510520
cur->val.via.str.size);
511521
break;
@@ -796,7 +806,8 @@ static int in_calyptia_fleet_collect(struct flb_input_instance *ins,
796806
flb_sds_destroy(cfgcurname);
797807
flb_sds_destroy(cfgoldname);
798808
goto reload_error;
799-
} else {
809+
}
810+
else {
800811
FLB_INPUT_RETURN(0);
801812
}
802813
}
@@ -846,7 +857,8 @@ static void load_fleet_config(struct flb_in_calyptia_fleet_config *ctx)
846857
// check which one and load it
847858
if (exists_cur_fleet_config(ctx) == FLB_TRUE) {
848859
execute_reload(ctx, cur_fleet_config_filename(ctx));
849-
} else if (exists_new_fleet_config(ctx) == FLB_TRUE) {
860+
}
861+
else if (exists_new_fleet_config(ctx) == FLB_TRUE) {
850862
execute_reload(ctx, new_fleet_config_filename(ctx));
851863
}
852864
}
@@ -968,7 +980,7 @@ static void cb_in_calyptia_fleet_resume(void *data, struct flb_config *config)
968980
static int in_calyptia_fleet_exit(void *data, struct flb_config *config)
969981
{
970982
(void) *config;
971-
struct flb_in_calyptia_fleet_config *ctx = data;
983+
struct flb_in_calyptia_fleet_config *ctx = (struct flb_in_calyptia_fleet_config *)data;
972984

973985
flb_input_collector_delete(ctx->collect_fd, ctx->ins);
974986
flb_upstream_destroy(ctx->u);

0 commit comments

Comments
 (0)