Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* MDF [conf] enable bridge retain flag in old conf #795

Merged
merged 12 commits into from
Jan 6, 2024
89 changes: 64 additions & 25 deletions src/supplemental/nanolib/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2340,21 +2340,23 @@ conf_bridge_node_parse_subs(
return;
}

char key[128] = "";
char * remote_topic = NULL;
char * local_topic = NULL;
char key[128] = "";
char *remote_topic = NULL;
char *local_topic = NULL;
uint8_t qos = 0;
uint8_t rap = 0; // only 1/0
uint8_t rhandling = 0; // only 0/1/2
uint8_t rap = 0; // only 1/0
uint8_t rhandling = 0; // only 0/1/2
uint8_t retain = NO_RETAIN; // only 0|1|2
size_t sub_index = 1;
bool get_remote_topic = false;
bool get_local_topic = false;
bool get_qos = false;
bool get_rap = false;
bool get_rhandling = false;
char * line = NULL;
bool get_retain = false;
char *line = NULL;
size_t sz = 0;
char * value = NULL;
char *value = NULL;

node->sub_count = 0;
while (nano_getline(&line, &sz, fp) != -1) {
Expand All @@ -2380,6 +2382,20 @@ conf_bridge_node_parse_subs(
goto check;
}

snprintf(key, 128,
"%s%s.subscription.%ld.retain", prefix, name,
sub_index);
if (!get_retain &&
(value = get_conf_value(line, sz, key)) != NULL) {
retain = (uint8_t) atoi(value);
if(retain != 0 || retain != 1) {
retain = NO_RETAIN;
}
free(value);
get_retain = true;
goto check;
}

snprintf(key, 128, "%s%s.subscription.%ld.qos", prefix,
name, sub_index);
if (!get_qos &&
Expand Down Expand Up @@ -2414,7 +2430,8 @@ conf_bridge_node_parse_subs(

check:
if (node->proto_ver == MQTT_PROTOCOL_VERSION_v5) {
if (get_remote_topic && get_local_topic && get_qos && get_rap && get_rhandling) {
if (get_remote_topic && get_local_topic && get_qos &&
get_rap && get_rhandling && get_retain) {
sub_index++;
node->sub_count++;
topics *s = NNI_ALLOC_STRUCT(s);
Expand All @@ -2426,6 +2443,7 @@ conf_bridge_node_parse_subs(
s->qos = qos;
s->retain_as_published = rap;
s->retain_handling = rhandling;
s->retain = retain;

for (int i=0; i<(int)s->local_topic_len; ++i)
if (s->local_topic[i] == '+' || s->local_topic[i] == '#') {
Expand All @@ -2440,23 +2458,25 @@ conf_bridge_node_parse_subs(
s->stream_id = sub_index;
#endif
cvector_push_back(node->sub_list, s);
get_remote_topic = false;
get_local_topic = false;
get_qos = false;
get_rap = false;
get_rhandling = false;
get_remote_topic = false;
get_local_topic = false;
get_qos = false;
get_rap = false;
get_rhandling = false;
get_retain = false;
}
} else {
if (get_remote_topic && get_local_topic && get_qos) {
if (get_remote_topic && get_local_topic && get_qos && get_retain) {
sub_index++;
node->sub_count++;
topics *s = NNI_ALLOC_STRUCT(s);
s->stream_id = 0;
topics *s = NNI_ALLOC_STRUCT(s);
s->stream_id = 0;
s->remote_topic = remote_topic;
s->local_topic = local_topic;
s->remote_topic_len = strlen(remote_topic);
s->local_topic_len = strlen(local_topic);
s->qos = qos;
s->qos = qos;
s->retain = retain;

for (int i=0; i<(int)s->local_topic_len; ++i)
if (s->local_topic[i] == '+' || s->local_topic[i] == '#') {
Expand All @@ -2473,7 +2493,8 @@ conf_bridge_node_parse_subs(
cvector_push_back(node->sub_list, s);
get_remote_topic = false;
get_local_topic = false;
get_qos = false;
get_qos = false;
get_retain = false;
}
}
}
Expand All @@ -2500,14 +2521,16 @@ conf_bridge_node_parse_forwards(
return;
}

char key[128] = "";
char * remote_topic = NULL;
char * local_topic = NULL;
char key[128] = "";
char *remote_topic = NULL;
char *local_topic = NULL;
uint8_t retain = NO_RETAIN;
bool get_remote_topic = false;
bool get_local_topic = false;
char * line = NULL;
bool get_retain = false;
char *line = NULL;
size_t sz = 0;
char * value = NULL;
char *value = NULL;
size_t fwd_index = 1;

node->forwards_count = 0;
Expand All @@ -2532,18 +2555,33 @@ conf_bridge_node_parse_forwards(
goto check;
}

snprintf(key, 128,
"%s%s.forwards.%ld.retain", prefix, name,
fwd_index);
if (!get_retain &&
(value = get_conf_value(line, sz, key)) != NULL) {
retain = (uint8_t) atoi(value);
wanghaEMQ marked this conversation as resolved.
Show resolved Hide resolved
if(retain != 0 || retain != 1) {
retain = NO_RETAIN;
}
free(value);
get_retain = true;
goto check;
}

free(line);
line = NULL;

check:
if (get_remote_topic && get_local_topic) {
if (get_remote_topic && get_local_topic && get_retain) {
fwd_index++;
node->forwards_count++;
topics *s = NNI_ALLOC_STRUCT(s);
topics *s = NNI_ALLOC_STRUCT(s);
s->remote_topic = remote_topic;
s->local_topic = local_topic;
s->remote_topic_len = strlen(remote_topic);
s->local_topic_len = strlen(local_topic);
s->retain = retain;

for (int i=0; i<(int)s->remote_topic_len; ++i)
if (s->remote_topic[i] == '+' || s->remote_topic[i] == '#') {
Expand All @@ -2556,6 +2594,7 @@ conf_bridge_node_parse_forwards(
cvector_push_back(node->forwards_list, s);
get_remote_topic = false;
get_local_topic = false;
get_retain = false;
}
}

Expand Down
22 changes: 14 additions & 8 deletions src/supplemental/nanolib/conf_ver2.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,20 +633,24 @@ conf_auth_http_req_parse_ver2(conf_auth_http_req *config, cJSON *jso)
hocon_read_str(config, method, jso);
cJSON *jso_headers = hocon_get_obj("headers", jso);
cJSON *jso_header = NULL;
size_t cnt = 0;
cJSON_ArrayForEach(jso_header, jso_headers)
{
conf_http_header *config_header =
NNI_ALLOC_STRUCT(config_header);
config_header->key = nng_strdup(jso_header->string);
config_header->value = nng_strdup(jso_header->valuestring);
cvector_push_back(config->headers, config_header);
cnt++;
config->headers =
realloc(config->headers, cnt * sizeof(conf_http_header *));
config->headers[cnt - 1] = calloc(1, sizeof(conf_http_header));
config->headers[cnt - 1]->key = nng_strdup(jso_header->string);
config->headers[cnt - 1]->value = nng_strdup(jso_header->valuestring);
}
config->header_count = cvector_size(config->headers);
config->header_count = cnt;

cJSON *jso_params = hocon_get_obj("params", jso);
cJSON *jso_param = NULL;
cnt = 0;
cJSON_ArrayForEach(jso_param, jso_params)
{
cnt++;
conf_http_param *param = NNI_ALLOC_STRUCT(param);
param->name = nng_strdup(jso_param->string);
char c = 0;
Expand Down Expand Up @@ -688,13 +692,15 @@ conf_auth_http_req_parse_ver2(conf_auth_http_req *config, cJSON *jso)
default:
break;
}
cvector_push_back(config->params, param);
config->params = realloc(
config->params, cnt * sizeof(conf_http_param *));
config->params[cnt - 1] = param;
} else {
nng_strfree(param->name);
NNI_FREE_STRUCT(param);
}
}
config->param_count = cvector_size(config->params);
config->param_count = cnt;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

???


cJSON * jso_http_req_tls = hocon_get_obj("ssl", jso);
conf_tls *http_req_tls = &(config->tls);
Expand Down