@cryptotaxi247 / netdata-1 / commits / 97da3cf73

more object renames in registry

Costa Tsaousis (ktsaou) committed Dec 31, 2016 at 13:37 UTC 97da3cf73b6e55e4f33282db75e0503c90f21399
1 file changed +39 -38
src/registry.c
+39 -38
@@ -124,9 +124,9 @@ typedef struct registry_url REGISTRY_URL;
124 // For each MACHINE-URL pair we keep this
125 struct registry_machine_url {
126 REGISTRY_URL *url; // de-duplicated URL
127 -// DICTIONARY *persons; // dictionary of PERSON *
127
128 uint8_t flags;
129 +
130 uint32_t first_t; // the first time we saw this
131 uint32_t last_t; // the last time we saw this
132 uint32_t usages; // how many times this has been accessed
@@ -137,9 +137,9 @@ typedef struct registry_machine_url REGISTRY_MACHINE_URL;
137 struct registry_machine {
138 char guid[GUID_LEN + 1]; // the GUID
139
140 - uint32_t links; // the number of PERSON_URLs linked to this machine
140 + uint32_t links; // the number of REGISTRY_PERSON_URL linked to this machine
141
142 - DICTIONARY *urls; // MACHINE_URL *
142 + DICTIONARY *machine_urls; // MACHINE_URL *
143
144 uint32_t first_t; // the first time we saw this
145 uint32_t last_t; // the last time we saw this
@@ -152,25 +152,26 @@ typedef struct registry_machine REGISTRY_MACHINE;
152 // PERSON structures
153
154 // for each PERSON-URL pair we keep this
155 -struct person_url {
155 +struct registry_person_url {
156 REGISTRY_URL *url; // de-duplicated URL
157 REGISTRY_MACHINE *machine; // link the MACHINE of this URL
158
159 uint8_t flags;
160 +
161 uint32_t first_t; // the first time we saw this
162 uint32_t last_t; // the last time we saw this
163 uint32_t usages; // how many times this has been accessed
164
164 - char name[1]; // the name of the URL, as known by the user
165 + char machine_name[1]; // the name of the machine, as known by the user
166 // dynamically allocated to fit properly
167 };
167 -typedef struct person_url REGISTRY_PERSON_URL;
168 +typedef struct registry_person_url REGISTRY_PERSON_URL;
169
170 // A person
171 struct registry_person {
172 char guid[GUID_LEN + 1]; // the person GUID
173
173 - DICTIONARY *urls; // dictionary of PERSON_URL *
174 + DICTIONARY *person_urls; // dictionary of PERSON_URL *
175
176 uint32_t first_t; // the first time we saw this
177 uint32_t last_t; // the last time we saw this
@@ -401,7 +402,7 @@ static inline REGISTRY_MACHINE_URL *registry_machine_url_allocate(REGISTRY_MACHI
402 registry.machines_urls_memory += sizeof(REGISTRY_MACHINE_URL);
403
404 debug(D_REGISTRY, "registry_machine_link_to_url('%s', '%s'): indexing URL in machine", m->guid, u->url);
404 - dictionary_set(m->urls, u->url, mu, sizeof(REGISTRY_MACHINE_URL));
405 + dictionary_set(m->machine_urls, u->url, mu, sizeof(REGISTRY_MACHINE_URL));
406 registry_url_link_nolock(u);
407
408 return mu;
@@ -415,7 +416,7 @@ static inline REGISTRY_MACHINE *registry_machine_allocate(const char *machine_gu
416 strncpyz(m->guid, machine_guid, GUID_LEN);
417
418 debug(D_REGISTRY, "Registry: registry_machine_allocate('%s'): creating dictionary of urls", machine_guid);
418 - m->urls = dictionary_create(DICTIONARY_FLAGS);
419 + m->machine_urls = dictionary_create(DICTIONARY_FLAGS);
420
421 m->first_t = m->last_t = (uint32_t)when;
422 m->usages = 0;
@@ -474,7 +475,7 @@ static inline REGISTRY_PERSON_URL *registry_person_url_allocate(REGISTRY_PERSON
475
476 // a simple strcpy() should do the job
477 // but I prefer to be safe, since the caller specified urllen
477 - strncpyz(pu->name, name, namelen);
478 + strncpyz(pu->machine_name, name, namelen);
479
480 pu->machine = m;
481 pu->first_t = pu->last_t = when;
@@ -486,7 +487,7 @@ static inline REGISTRY_PERSON_URL *registry_person_url_allocate(REGISTRY_PERSON
487 registry.persons_urls_memory += sizeof(REGISTRY_PERSON_URL) + namelen;
488
489 debug(D_REGISTRY, "registry_person_url_allocate('%s', '%s', '%s'): indexing URL in person", p->guid, m->guid, u->url);
489 - dictionary_set(p->urls, u->url, pu, sizeof(REGISTRY_PERSON_URL));
490 + dictionary_set(p->person_urls, u->url, pu, sizeof(REGISTRY_PERSON_URL));
491 registry_url_link_nolock(u);
492
493 return pu;
@@ -506,7 +507,7 @@ static inline REGISTRY_PERSON_URL *registry_person_url_reallocate(REGISTRY_PERSO
507 // ok, these are a hack - since the registry_person_url_allocate() is
508 // adding these, we have to subtract them
509 tpu->machine->links--;
509 - registry.persons_urls_memory -= sizeof(REGISTRY_PERSON_URL) + strlen(pu->name);
510 + registry.persons_urls_memory -= sizeof(REGISTRY_PERSON_URL) + strlen(pu->machine_name);
511 registry_url_unlink_nolock(u);
512
513 freez(pu);
@@ -540,7 +541,7 @@ static inline REGISTRY_PERSON *registry_person_allocate(const char *person_guid,
541 strncpyz(p->guid, person_guid, GUID_LEN);
542
543 debug(D_REGISTRY, "Registry: registry_person_allocate('%s'): creating dictionary of urls", p->guid);
543 - p->urls = dictionary_create(DICTIONARY_FLAGS);
544 + p->person_urls = dictionary_create(DICTIONARY_FLAGS);
545
546 p->first_t = p->last_t = when;
547 p->usages = 0;
@@ -589,7 +590,7 @@ static inline REGISTRY_PERSON_URL *registry_person_link_to_url(REGISTRY_PERSON *
590
591 registry_person_urls_lock(p);
592
592 - REGISTRY_PERSON_URL *pu = dictionary_get(p->urls, u->url);
593 + REGISTRY_PERSON_URL *pu = dictionary_get(p->person_urls, u->url);
594 if(!pu) {
595 debug(D_REGISTRY, "registry_person_link_to_url('%s', '%s', '%s'): not found", p->guid, m->guid, u->url);
596 pu = registry_person_url_allocate(p, m, u, name, namelen, when);
@@ -601,7 +602,7 @@ static inline REGISTRY_PERSON_URL *registry_person_link_to_url(REGISTRY_PERSON *
602 if(likely(pu->last_t < (uint32_t)when)) pu->last_t = when;
603
604 if(pu->machine != m) {
604 - REGISTRY_MACHINE_URL *mu = dictionary_get(pu->machine->urls, u->url);
605 + REGISTRY_MACHINE_URL *mu = dictionary_get(pu->machine->machine_urls, u->url);
606 if(mu) {
607 info("registry_person_link_to_url('%s', '%s', '%s'): URL switched machines (old was '%s') - expiring it from previous machine.",
608 p->guid, m->guid, u->url, pu->machine->guid);
@@ -616,7 +617,7 @@ static inline REGISTRY_PERSON_URL *registry_person_link_to_url(REGISTRY_PERSON *
617 pu->machine = m;
618 }
619
619 - if(strcmp(pu->name, name)) {
620 + if(strcmp(pu->machine_name, name)) {
621 // the name of the PERSON_URL has changed !
622 pu = registry_person_url_reallocate(p, m, u, name, namelen, when, pu);
623 }
@@ -640,7 +641,7 @@ static inline REGISTRY_MACHINE_URL *registry_machine_link_to_url(REGISTRY_PERSON
641
642 registry_machine_urls_lock(m);
643
643 - REGISTRY_MACHINE_URL *mu = dictionary_get(m->urls, u->url);
644 + REGISTRY_MACHINE_URL *mu = dictionary_get(m->machine_urls, u->url);
645 if(!mu) {
646 debug(D_REGISTRY, "registry_machine_link_to_url('%s', '%s', '%s'): not found", p->guid, m->guid, u->url);
647 mu = registry_machine_url_allocate(m, u, when);
@@ -887,7 +888,7 @@ REGISTRY_PERSON_URL *registry_verify_request(char *person_guid, char *machine_gu
888 }
889 if(pp) *pp = p;
890
890 - REGISTRY_PERSON_URL *pu = dictionary_get(p->urls, url);
891 + REGISTRY_PERSON_URL *pu = dictionary_get(p->person_urls, url);
892 if(!pu) {
893 info("Registry Request Verification: URL not found for person, person: '%s', machine '%s', url '%s'", person_guid, machine_guid, url);
894 return NULL;
@@ -914,7 +915,7 @@ REGISTRY_PERSON *registry_request_delete(char *person_guid, char *machine_guid,
915
916 registry_person_urls_lock(p);
917
917 - REGISTRY_PERSON_URL *dpu = dictionary_get(p->urls, delete_url);
918 + REGISTRY_PERSON_URL *dpu = dictionary_get(p->person_urls, delete_url);
919 if(!dpu) {
920 info("Registry Delete Request: URL not found for person: '%s', machine '%s', url '%s', delete url '%s'", p->guid, m->guid, pu->url->url, delete_url);
921 registry_person_urls_unlock(p);
@@ -923,7 +924,7 @@ REGISTRY_PERSON *registry_request_delete(char *person_guid, char *machine_guid,
924
925 registry_log('D', p, m, pu->url, dpu->url->url);
926
926 - dictionary_del(p->urls, dpu->url->url);
927 + dictionary_del(p->person_urls, dpu->url->url);
928 registry_url_unlink_nolock(dpu->url);
929 freez(dpu);
930
@@ -985,7 +986,7 @@ REGISTRY_MACHINE *registry_request_machine(char *person_guid, char *machine_guid
986
987 // request a walk through on the dictionary
988 // no need for locking here, the underlying dictionary has its own
988 - dictionary_get_all(p->urls, machine_request_callback, &rdata);
989 + dictionary_get_all(p->person_urls, machine_request_callback, &rdata);
990
991 if(rdata.result)
992 return m;
@@ -1074,7 +1075,7 @@ static inline int registry_json_person_url_callback(void *entry, void *data) {
1075 buffer_strcat(w->response.data, ",");
1076
1077 buffer_sprintf(w->response.data, "\n\t\t[ \"%s\", \"%s\", %u000, %u, \"%s\" ]",
1077 - pu->machine->guid, pu->url->url, pu->last_t, pu->usages, pu->name);
1078 + pu->machine->guid, pu->url->url, pu->last_t, pu->usages, pu->machine_name);
1079
1080 return 1;
1081 }
@@ -1116,7 +1117,7 @@ int registry_request_access_json(struct web_client *w, char *person_guid, char *
1117
1118 buffer_sprintf(w->response.data, ",\n\t\"person_guid\": \"%s\",\n\t\"urls\": [", p->guid);
1119 struct registry_json_walk_person_urls_callback c = { p, NULL, w, 0 };
1119 - dictionary_get_all(p->urls, registry_json_person_url_callback, &c);
1120 + dictionary_get_all(p->person_urls, registry_json_person_url_callback, &c);
1121 buffer_strcat(w->response.data, "\n\t]\n");
1122
1123 registry_json_footer(w);
@@ -1157,7 +1158,7 @@ int registry_request_search_json(struct web_client *w, char *person_guid, char *
1158
1159 buffer_strcat(w->response.data, ",\n\t\"urls\": [");
1160 struct registry_json_walk_person_urls_callback c = { NULL, m, w, 0 };
1160 - dictionary_get_all(m->urls, registry_json_machine_url_callback, &c);
1161 + dictionary_get_all(m->machine_urls, registry_json_machine_url_callback, &c);
1162 buffer_strcat(w->response.data, "\n\t]\n");
1163
1164 registry_json_footer(w);
@@ -1213,7 +1214,7 @@ int registry_request_switch_json(struct web_client *w, char *person_guid, char *
1214 struct registry_person_url_callback_verify_machine_exists_data data = { m, 0 };
1215
1216 // verify the old person has access to this machine
1216 - dictionary_get_all(op->urls, registry_person_url_callback_verify_machine_exists, &data);
1217 + dictionary_get_all(op->person_urls, registry_person_url_callback_verify_machine_exists, &data);
1218 if(!data.count) {
1219 registry_json_header(w, "switch", REGISTRY_STATUS_FAILED);
1220 registry_json_footer(w);
@@ -1222,7 +1223,7 @@ int registry_request_switch_json(struct web_client *w, char *person_guid, char *
1223
1224 // verify the new person has access to this machine
1225 data.count = 0;
1225 - dictionary_get_all(np->urls, registry_person_url_callback_verify_machine_exists, &data);
1226 + dictionary_get_all(np->person_urls, registry_person_url_callback_verify_machine_exists, &data);
1227 if(!data.count) {
1228 registry_json_header(w, "switch", REGISTRY_STATUS_FAILED);
1229 registry_json_footer(w);
@@ -1344,7 +1345,7 @@ int registry_machine_save(void *entry, void *file) {
1345 );
1346
1347 if(ret >= 0) {
1347 - int ret2 = dictionary_get_all(m->urls, registry_machine_save_url, fp);
1348 + int ret2 = dictionary_get_all(m->machine_urls, registry_machine_save_url, fp);
1349 if(ret2 < 0) return ret2;
1350 ret += ret2;
1351 }
@@ -1366,7 +1367,7 @@ static inline int registry_person_save_url(void *entry, void *file) {
1367 pu->usages,
1368 pu->flags,
1369 pu->machine->guid,
1369 - pu->name,
1370 + pu->machine_name,
1371 pu->url->url
1372 );
1373
@@ -1389,7 +1390,7 @@ static inline int registry_person_save(void *entry, void *file) {
1390 );
1391
1392 if(ret >= 0) {
1392 - int ret2 = dictionary_get_all(p->urls, registry_person_save_url, fp);
1393 + int ret2 = dictionary_get_all(p->person_urls, registry_person_save_url, fp);
1394 if (ret2 < 0) return ret2;
1395 ret += ret2;
1396 }
@@ -1610,7 +1611,7 @@ static inline size_t registry_load(void) {
1611 pu->last_t = strtoul(&s[11], NULL, 16);
1612 pu->usages = strtoul(&s[20], NULL, 16);
1613 pu->flags = strtoul(&s[29], NULL, 16);
1613 - debug(D_REGISTRY, "Registry loaded person URL '%s' with name '%s' of machine '%s', first: %u, last: %u, usages: %u, flags: %02x", u->url, pu->name, m->guid, pu->first_t, pu->last_t, pu->usages, pu->flags);
1614 + debug(D_REGISTRY, "Registry loaded person URL '%s' with name '%s' of machine '%s', first: %u, last: %u, usages: %u, flags: %02x", u->url, pu->machine_name, m->guid, pu->first_t, pu->last_t, pu->usages, pu->flags);
1615 break;
1616
1617 case 'V': // machine URL
@@ -1745,13 +1746,13 @@ void registry_free(void) {
1746
1747 // fprintf(stderr, "\nPERSON: '%s', first: %u, last: %u, usages: %u\n", p->guid, p->first_t, p->last_t, p->usages);
1748
1748 - while(p->urls->values_index.root) {
1749 - REGISTRY_PERSON_URL *pu = ((NAME_VALUE *)p->urls->values_index.root)->value;
1749 + while(p->person_urls->values_index.root) {
1750 + REGISTRY_PERSON_URL *pu = ((NAME_VALUE *)p->person_urls->values_index.root)->value;
1751
1752 // fprintf(stderr, "\tURL: '%s', first: %u, last: %u, usages: %u, flags: 0x%02x\n", pu->url->url, pu->first_t, pu->last_t, pu->usages, pu->flags);
1753
1754 debug(D_REGISTRY, "Registry: deleting url '%s' from person '%s'", pu->url->url, p->guid);
1754 - dictionary_del(p->urls, pu->url->url);
1755 + dictionary_del(p->person_urls, pu->url->url);
1756
1757 debug(D_REGISTRY, "Registry: unlinking url '%s' from person", pu->url->url);
1758 registry_url_unlink_nolock(pu->url);
@@ -1764,7 +1765,7 @@ void registry_free(void) {
1765 dictionary_del(registry.persons, p->guid);
1766
1767 debug(D_REGISTRY, "Registry: destroying URL dictionary of person '%s'", p->guid);
1767 - dictionary_destroy(p->urls);
1768 + dictionary_destroy(p->person_urls);
1769
1770 debug(D_REGISTRY, "Registry: freeing person '%s'", p->guid);
1771 freez(p);
@@ -1775,8 +1776,8 @@ void registry_free(void) {
1776
1777 // fprintf(stderr, "\nMACHINE: '%s', first: %u, last: %u, usages: %u\n", m->guid, m->first_t, m->last_t, m->usages);
1778
1778 - while(m->urls->values_index.root) {
1779 - REGISTRY_MACHINE_URL *mu = ((NAME_VALUE *)m->urls->values_index.root)->value;
1779 + while(m->machine_urls->values_index.root) {
1780 + REGISTRY_MACHINE_URL *mu = ((NAME_VALUE *)m->machine_urls->values_index.root)->value;
1781
1782 // fprintf(stderr, "\tURL: '%s', first: %u, last: %u, usages: %u, flags: 0x%02x\n", mu->url->url, mu->first_t, mu->last_t, mu->usages, mu->flags);
1783
@@ -1784,7 +1785,7 @@ void registry_free(void) {
1785 //dictionary_destroy(mu->persons);
1786
1787 debug(D_REGISTRY, "Registry: deleting url '%s' from person '%s'", mu->url->url, m->guid);
1787 - dictionary_del(m->urls, mu->url->url);
1788 + dictionary_del(m->machine_urls, mu->url->url);
1789
1790 debug(D_REGISTRY, "Registry: unlinking url '%s' from machine", mu->url->url);
1791 registry_url_unlink_nolock(mu->url);
@@ -1797,7 +1798,7 @@ void registry_free(void) {
1798 dictionary_del(registry.machines, m->guid);
1799
1800 debug(D_REGISTRY, "Registry: destroying URL dictionary of machine '%s'", m->guid);
1800 - dictionary_destroy(m->urls);
1801 + dictionary_destroy(m->machine_urls);
1802
1803 debug(D_REGISTRY, "Registry: freeing machine '%s'", m->guid);
1804 freez(m);