@cryptotaxi247 / netdata-1 / commits / 63696cf07

work-around for dictionary_get_all() not returning the valid count

Costa Tsaousis (ktsaou) committed May 14, 2016 at 18:32 UTC 63696cf075bf2577e8447c297e6a803e5b8cb4d0
1 file changed +20 -15
src/registry.c
+20 -15
@@ -1169,19 +1169,21 @@ int registry_request_search_json(struct web_client *w, char *person_guid, char *
1169 return 200;
1170 }
1171
1172 +// structure used be the callbacks below
1173 +struct registry_person_url_callback_verify_machine_exists_data {
1174 + MACHINE *m;
1175 + int count;
1176 +};
1177
1173 -int registry_person_url_callback_verify_machine_exists(void *entry, void *machine) {
1178 +int registry_person_url_callback_verify_machine_exists(void *entry, void *data) {
1179 + struct registry_person_url_callback_verify_machine_exists_data *d = (struct registry_person_url_callback_verify_machine_exists_data *)data;
1180 PERSON_URL *pu = (PERSON_URL *)entry;
1175 - MACHINE *m = (MACHINE *)machine;
1181 + MACHINE *m = d->m;
1182
1177 - if(pu->machine == m) {
1178 - info("registry_person_url_callback_verify_machine_exists('%s', '%s'): no", pu->machine->guid, m->guid);
1179 - return 1;
1180 - }
1181 - else {
1182 - info("registry_person_url_callback_verify_machine_exists('%s', '%s'): yes", pu->machine->guid, m->guid);
1183 - return 0;
1184 - }
1183 + if(pu->machine == m)
1184 + d->count++;
1185 +
1186 + return 0;
1187 }
1188
1189 // the main method for switching user identity
@@ -1213,17 +1215,20 @@ int registry_request_switch_json(struct web_client *w, char *person_guid, char *
1215 return 432;
1216 }
1217
1218 + struct registry_person_url_callback_verify_machine_exists_data data = { m, 0 };
1219 +
1220 // verify the old person has access to this machine
1217 - int count = dictionary_get_all(op->urls, registry_person_url_callback_verify_machine_exists, m);
1218 - if(!count) {
1221 + dictionary_get_all(op->urls, registry_person_url_callback_verify_machine_exists, &data);
1222 + if(!data.count) {
1223 registry_json_header(w, "switch", REGISTRY_STATUS_FAILED);
1224 registry_json_footer(w);
1225 return 433;
1226 }
1227
1228 // verify the new person has access to this machine
1225 - count = dictionary_get_all(np->urls, registry_person_url_callback_verify_machine_exists, m);
1226 - if(!count) {
1229 + data.count = 0;
1230 + dictionary_get_all(np->urls, registry_person_url_callback_verify_machine_exists, &data);
1231 + if(!data.count) {
1232 registry_json_header(w, "switch", REGISTRY_STATUS_FAILED);
1233 registry_json_footer(w);
1234 return 434;
@@ -1652,7 +1657,7 @@ int registry_init(void) {
1657 registry.save_registry_every_entries = config_get_number("registry", "registry save db every new entries", 1000000);
1658 registry.persons_expiration = config_get_number("registry", "registry expire idle persons days", 365) * 86400;
1659 registry.registry_domain = config_get("registry", "registry domain", "");
1655 - registry.registry_to_announce = config_get("registry", "registry to announce", "https://registry.my-netdata.io");
1660 + registry.registry_to_announce = config_get("registry", "registry to announce", "//registry.my-netdata.io");
1661 registry.hostname = config_get("registry", "registry hostname", config_get("global", "hostname", hostname));
1662
1663 registry.max_url_length = config_get_number("registry", "max URL length", 1024);