@cryptotaxi247 / netdata-1 / commits / 70ec29d81

object renames in registry

Costa Tsaousis (ktsaou) committed Dec 31, 2016 at 13:21 UTC 70ec29d81a87656871cf3db67e2df6c77a081618
1 file changed +131 -130
src/registry.c
+131 -130
@@ -32,7 +32,6 @@
32 //
33 // - embed avl structures directly into registry objects, instead of DICTIONARY
34 // - store GUIDs in memory as UUID instead of char *
35 -// (this will also remove the index hash, since UUIDs can be compared directly)
35 // - do not track persons using the demo machines only
36 // (i.e. start tracking them only when they access a non-demo machine)
37 // - [DONE] do not track custom dashboards by default
@@ -42,13 +41,15 @@
41
42 #define DICTIONARY_FLAGS DICTIONARY_FLAG_VALUE_LINK_DONT_CLONE | DICTIONARY_FLAG_NAME_LINK_DONT_CLONE
43
44 +#define GUID_LEN 36
45 +
46 // ----------------------------------------------------------------------------
47 // COMMON structures
48
49 struct registry {
50 int enabled;
51
51 - char machine_guid[36 + 1];
52 + char machine_guid[GUID_LEN + 1];
53
54 // entries counters / statistics
55 unsigned long long persons_count;
@@ -109,20 +110,20 @@ struct registry {
110 // so instead of storing URLs all over the place
111 // we store them here and we keep pointers elsewhere
112
112 -struct url {
113 +struct registry_url {
114 uint32_t links; // the number of links to this URL - when none is left, we free it
115 uint16_t len; // the length of the URL in bytes
116 char url[1]; // the URL - dynamically allocated to more size
117 };
117 -typedef struct url ND_URL;
118 +typedef struct registry_url REGISTRY_URL;
119
120
121 // ----------------------------------------------------------------------------
122 // MACHINE structures
123
124 // For each MACHINE-URL pair we keep this
124 -struct machine_url {
125 - ND_URL *url; // de-duplicated URL
125 +struct registry_machine_url {
126 + REGISTRY_URL *url; // de-duplicated URL
127 // DICTIONARY *persons; // dictionary of PERSON *
128
129 uint8_t flags;
@@ -130,11 +131,11 @@ struct machine_url {
131 uint32_t last_t; // the last time we saw this
132 uint32_t usages; // how many times this has been accessed
133 };
133 -typedef struct machine_url ND_MACHINE_URL;
134 +typedef struct registry_machine_url REGISTRY_MACHINE_URL;
135
136 // A machine
136 -struct machine {
137 - char guid[36 + 1]; // the GUID
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
141
@@ -144,7 +145,7 @@ struct machine {
145 uint32_t last_t; // the last time we saw this
146 uint32_t usages; // how many times this has been accessed
147 };
147 -typedef struct machine ND_MACHINE;
148 +typedef struct registry_machine REGISTRY_MACHINE;
149
150
151 // ----------------------------------------------------------------------------
@@ -152,8 +153,8 @@ typedef struct machine ND_MACHINE;
153
154 // for each PERSON-URL pair we keep this
155 struct person_url {
155 - ND_URL *url; // de-duplicated URL
156 - ND_MACHINE *machine; // link the MACHINE of this URL
156 + REGISTRY_URL *url; // de-duplicated URL
157 + REGISTRY_MACHINE *machine; // link the MACHINE of this URL
158
159 uint8_t flags;
160 uint32_t first_t; // the first time we saw this
@@ -163,11 +164,11 @@ struct person_url {
164 char name[1]; // the name of the URL, as known by the user
165 // dynamically allocated to fit properly
166 };
166 -typedef struct person_url ND_PERSON_URL;
167 +typedef struct person_url REGISTRY_PERSON_URL;
168
169 // A person
169 -struct person {
170 - char guid[36 + 1]; // the person GUID
170 +struct registry_person {
171 + char guid[GUID_LEN + 1]; // the person GUID
172
173 DICTIONARY *urls; // dictionary of PERSON_URL *
174
@@ -175,7 +176,7 @@ struct person {
176 uint32_t last_t; // the last time we saw this
177 uint32_t usages; // how many times this has been accessed
178 };
178 -typedef struct person ND_PERSON;
179 +typedef struct registry_person REGISTRY_PERSON;
180
181
182 // ----------------------------------------------------------------------------
@@ -209,12 +210,12 @@ static inline void registry_urls_unlock(void) {
210 // updating a person's urls.
211 // however, to save the memory required for keeping a
212 // mutex (40 bytes) per person, we do...
212 -static inline void registry_person_urls_lock(ND_PERSON *p) {
213 +static inline void registry_person_urls_lock(REGISTRY_PERSON *p) {
214 (void)p;
215 pthread_mutex_lock(&registry.person_urls_lock);
216 }
217
217 -static inline void registry_person_urls_unlock(ND_PERSON *p) {
218 +static inline void registry_person_urls_unlock(REGISTRY_PERSON *p) {
219 (void)p;
220 pthread_mutex_unlock(&registry.person_urls_lock);
221 }
@@ -223,12 +224,12 @@ static inline void registry_person_urls_unlock(ND_PERSON *p) {
224 // updating a machine's urls.
225 // however, to save the memory required for keeping a
226 // mutex (40 bytes) per machine, we do...
226 -static inline void registry_machine_urls_lock(ND_MACHINE *m) {
227 +static inline void registry_machine_urls_lock(REGISTRY_MACHINE *m) {
228 (void)m;
229 pthread_mutex_lock(&registry.machine_urls_lock);
230 }
231
231 -static inline void registry_machine_urls_unlock(ND_MACHINE *m) {
232 +static inline void registry_machine_urls_unlock(REGISTRY_MACHINE *m) {
233 (void)m;
234 pthread_mutex_unlock(&registry.machine_urls_lock);
235 }
@@ -306,20 +307,20 @@ static inline char *registry_fix_url(char *url, size_t *len) {
307 // ----------------------------------------------------------------------------
308 // forward definition of functions
309
309 -extern ND_PERSON *registry_request_access(char *person_guid, char *machine_guid, char *url, char *name, time_t when);
310 -extern ND_PERSON *registry_request_delete(char *person_guid, char *machine_guid, char *url, char *delete_url, time_t when);
310 +extern REGISTRY_PERSON *registry_request_access(char *person_guid, char *machine_guid, char *url, char *name, time_t when);
311 +extern REGISTRY_PERSON *registry_request_delete(char *person_guid, char *machine_guid, char *url, char *delete_url, time_t when);
312
313
314 // ----------------------------------------------------------------------------
315 // URL
316
316 -static inline ND_URL *registry_url_allocate_nolock(const char *url, size_t urllen) {
317 +static inline REGISTRY_URL *registry_url_allocate_nolock(const char *url, size_t urllen) {
318 // protection from too big URLs
319 if(urllen > registry.max_url_length)
320 urllen = registry.max_url_length;
321
321 - debug(D_REGISTRY, "Registry: registry_url_allocate_nolock('%s'): allocating %zu bytes", url, sizeof(ND_URL) + urllen);
322 - ND_URL *u = mallocz(sizeof(ND_URL) + urllen);
322 + debug(D_REGISTRY, "Registry: registry_url_allocate_nolock('%s'): allocating %zu bytes", url, sizeof(REGISTRY_URL) + urllen);
323 + REGISTRY_URL *u = mallocz(sizeof(REGISTRY_URL) + urllen);
324
325 // a simple strcpy() should do the job
326 // but I prefer to be safe, since the caller specified urllen
@@ -327,18 +328,18 @@ static inline ND_URL *registry_url_allocate_nolock(const char *url, size_t urlle
328 strncpyz(u->url, url, u->len);
329 u->links = 0;
330
330 - registry.urls_memory += sizeof(ND_URL) + urllen;
331 + registry.urls_memory += sizeof(REGISTRY_URL) + urllen;
332
333 debug(D_REGISTRY, "Registry: registry_url_allocate_nolock('%s'): indexing it", url);
333 - dictionary_set(registry.urls, u->url, u, sizeof(ND_URL));
334 + dictionary_set(registry.urls, u->url, u, sizeof(REGISTRY_URL));
335
336 return u;
337 }
338
338 -static inline ND_URL *registry_url_get_nolock(const char *url, size_t urllen) {
339 +static inline REGISTRY_URL *registry_url_get_nolock(const char *url, size_t urllen) {
340 debug(D_REGISTRY, "Registry: registry_url_get_nolock('%s')", url);
341
341 - ND_URL *u = dictionary_get(registry.urls, url);
342 + REGISTRY_URL *u = dictionary_get(registry.urls, url);
343 if(!u) {
344 u = registry_url_allocate_nolock(url, urllen);
345 registry.urls_count++;
@@ -347,24 +348,24 @@ static inline ND_URL *registry_url_get_nolock(const char *url, size_t urllen) {
348 return u;
349 }
350
350 -static inline ND_URL *registry_url_get(const char *url, size_t urllen) {
351 +static inline REGISTRY_URL *registry_url_get(const char *url, size_t urllen) {
352 debug(D_REGISTRY, "Registry: registry_url_get('%s')", url);
353
354 registry_urls_lock();
355
355 - ND_URL *u = registry_url_get_nolock(url, urllen);
356 + REGISTRY_URL *u = registry_url_get_nolock(url, urllen);
357
358 registry_urls_unlock();
359
360 return u;
361 }
362
362 -static inline void registry_url_link_nolock(ND_URL *u) {
363 +static inline void registry_url_link_nolock(REGISTRY_URL *u) {
364 u->links++;
365 debug(D_REGISTRY, "Registry: registry_url_link_nolock('%s'): URL has now %u links", u->url, u->links);
366 }
367
367 -static inline void registry_url_unlink_nolock(ND_URL *u) {
368 +static inline void registry_url_unlink_nolock(REGISTRY_URL *u) {
369 u->links--;
370 if(!u->links) {
371 debug(D_REGISTRY, "Registry: registry_url_unlink_nolock('%s'): No more links for this URL", u->url);
@@ -379,15 +380,15 @@ static inline void registry_url_unlink_nolock(ND_URL *u) {
380 // ----------------------------------------------------------------------------
381 // MACHINE
382
382 -static inline ND_MACHINE *registry_machine_find(const char *machine_guid) {
383 +static inline REGISTRY_MACHINE *registry_machine_find(const char *machine_guid) {
384 debug(D_REGISTRY, "Registry: registry_machine_find('%s')", machine_guid);
385 return dictionary_get(registry.machines, machine_guid);
386 }
387
387 -static inline ND_MACHINE_URL *registry_machine_url_allocate(ND_MACHINE *m, ND_URL *u, time_t when) {
388 - debug(D_REGISTRY, "registry_machine_link_to_url('%s', '%s'): allocating %zu bytes", m->guid, u->url, sizeof(ND_MACHINE_URL));
388 +static inline REGISTRY_MACHINE_URL *registry_machine_url_allocate(REGISTRY_MACHINE *m, REGISTRY_URL *u, time_t when) {
389 + debug(D_REGISTRY, "registry_machine_link_to_url('%s', '%s'): allocating %zu bytes", m->guid, u->url, sizeof(REGISTRY_MACHINE_URL));
390
390 - ND_MACHINE_URL *mu = mallocz(sizeof(ND_MACHINE_URL));
391 + REGISTRY_MACHINE_URL *mu = mallocz(sizeof(REGISTRY_MACHINE_URL));
392
393 // mu->persons = dictionary_create(DICTIONARY_FLAGS);
394 // dictionary_set(mu->persons, p->guid, p, sizeof(PERSON));
@@ -397,21 +398,21 @@ static inline ND_MACHINE_URL *registry_machine_url_allocate(ND_MACHINE *m, ND_UR
398 mu->url = u;
399 mu->flags = REGISTRY_URL_FLAGS_DEFAULT;
400
400 - registry.machines_urls_memory += sizeof(ND_MACHINE_URL);
401 + registry.machines_urls_memory += sizeof(REGISTRY_MACHINE_URL);
402
403 debug(D_REGISTRY, "registry_machine_link_to_url('%s', '%s'): indexing URL in machine", m->guid, u->url);
403 - dictionary_set(m->urls, u->url, mu, sizeof(ND_MACHINE_URL));
404 + dictionary_set(m->urls, u->url, mu, sizeof(REGISTRY_MACHINE_URL));
405 registry_url_link_nolock(u);
406
407 return mu;
408 }
409
409 -static inline ND_MACHINE *registry_machine_allocate(const char *machine_guid, time_t when) {
410 - debug(D_REGISTRY, "Registry: registry_machine_allocate('%s'): creating new machine, sizeof(MACHINE)=%zu", machine_guid, sizeof(ND_MACHINE));
410 +static inline REGISTRY_MACHINE *registry_machine_allocate(const char *machine_guid, time_t when) {
411 + debug(D_REGISTRY, "Registry: registry_machine_allocate('%s'): creating new machine, sizeof(MACHINE)=%zu", machine_guid, sizeof(REGISTRY_MACHINE));
412
412 - ND_MACHINE *m = mallocz(sizeof(ND_MACHINE));
413 + REGISTRY_MACHINE *m = mallocz(sizeof(REGISTRY_MACHINE));
414
414 - strncpyz(m->guid, machine_guid, 36);
415 + strncpyz(m->guid, machine_guid, GUID_LEN);
416
417 debug(D_REGISTRY, "Registry: registry_machine_allocate('%s'): creating dictionary of urls", machine_guid);
418 m->urls = dictionary_create(DICTIONARY_FLAGS);
@@ -419,10 +420,10 @@ static inline ND_MACHINE *registry_machine_allocate(const char *machine_guid, ti
420 m->first_t = m->last_t = (uint32_t)when;
421 m->usages = 0;
422
422 - registry.machines_memory += sizeof(ND_MACHINE);
423 + registry.machines_memory += sizeof(REGISTRY_MACHINE);
424
425 registry.machines_count++;
425 - dictionary_set(registry.machines, m->guid, m, sizeof(ND_MACHINE));
426 + dictionary_set(registry.machines, m->guid, m, sizeof(REGISTRY_MACHINE));
427
428 return m;
429 }
@@ -430,14 +431,14 @@ static inline ND_MACHINE *registry_machine_allocate(const char *machine_guid, ti
431 // 1. validate machine GUID
432 // 2. if it is valid, find it or create it and return it
433 // 3. if it is not valid, return NULL
433 -static inline ND_MACHINE *registry_machine_get(const char *machine_guid, time_t when) {
434 - ND_MACHINE *m = NULL;
434 +static inline REGISTRY_MACHINE *registry_machine_get(const char *machine_guid, time_t when) {
435 + REGISTRY_MACHINE *m = NULL;
436
437 registry_machines_lock();
438
439 if(likely(machine_guid && *machine_guid)) {
440 // validate it is a GUID
440 - char buf[36 + 1];
441 + char buf[GUID_LEN + 1];
442 if(unlikely(registry_regenerate_guid(machine_guid, buf) == -1))
443 info("Registry: machine guid '%s' is not a valid guid. Ignoring it.", machine_guid);
444 else {
@@ -456,20 +457,20 @@ static inline ND_MACHINE *registry_machine_get(const char *machine_guid, time_t
457 // ----------------------------------------------------------------------------
458 // PERSON
459
459 -static inline ND_PERSON *registry_person_find(const char *person_guid) {
460 +static inline REGISTRY_PERSON *registry_person_find(const char *person_guid) {
461 debug(D_REGISTRY, "Registry: registry_person_find('%s')", person_guid);
462 return dictionary_get(registry.persons, person_guid);
463 }
464
464 -static inline ND_PERSON_URL *registry_person_url_allocate(ND_PERSON *p, ND_MACHINE *m, ND_URL *u, char *name, size_t namelen, time_t when) {
465 +static inline REGISTRY_PERSON_URL *registry_person_url_allocate(REGISTRY_PERSON *p, REGISTRY_MACHINE *m, REGISTRY_URL *u, char *name, size_t namelen, time_t when) {
466 // protection from too big names
467 if(namelen > registry.max_name_length)
468 namelen = registry.max_name_length;
469
470 debug(D_REGISTRY, "registry_person_url_allocate('%s', '%s', '%s'): allocating %zu bytes", p->guid, m->guid, u->url,
470 - sizeof(ND_PERSON_URL) + namelen);
471 + sizeof(REGISTRY_PERSON_URL) + namelen);
472
472 - ND_PERSON_URL *pu = mallocz(sizeof(ND_PERSON_URL) + namelen);
473 + REGISTRY_PERSON_URL *pu = mallocz(sizeof(REGISTRY_PERSON_URL) + namelen);
474
475 // a simple strcpy() should do the job
476 // but I prefer to be safe, since the caller specified urllen
@@ -482,22 +483,22 @@ static inline ND_PERSON_URL *registry_person_url_allocate(ND_PERSON *p, ND_MACHI
483 pu->flags = REGISTRY_URL_FLAGS_DEFAULT;
484 m->links++;
485
485 - registry.persons_urls_memory += sizeof(ND_PERSON_URL) + namelen;
486 + registry.persons_urls_memory += sizeof(REGISTRY_PERSON_URL) + namelen;
487
488 debug(D_REGISTRY, "registry_person_url_allocate('%s', '%s', '%s'): indexing URL in person", p->guid, m->guid, u->url);
488 - dictionary_set(p->urls, u->url, pu, sizeof(ND_PERSON_URL));
489 + dictionary_set(p->urls, u->url, pu, sizeof(REGISTRY_PERSON_URL));
490 registry_url_link_nolock(u);
491
492 return pu;
493 }
494
494 -static inline ND_PERSON_URL *registry_person_url_reallocate(ND_PERSON *p, ND_MACHINE *m, ND_URL *u, char *name, size_t namelen, time_t when, ND_PERSON_URL *pu) {
495 +static inline REGISTRY_PERSON_URL *registry_person_url_reallocate(REGISTRY_PERSON *p, REGISTRY_MACHINE *m, REGISTRY_URL *u, char *name, size_t namelen, time_t when, REGISTRY_PERSON_URL *pu) {
496 // this function is needed to change the name of a PERSON_URL
497
498 debug(D_REGISTRY, "registry_person_url_reallocate('%s', '%s', '%s'): allocating %zu bytes", p->guid, m->guid, u->url,
498 - sizeof(ND_PERSON_URL) + namelen);
499 + sizeof(REGISTRY_PERSON_URL) + namelen);
500
500 - ND_PERSON_URL *tpu = registry_person_url_allocate(p, m, u, name, namelen, when);
501 + REGISTRY_PERSON_URL *tpu = registry_person_url_allocate(p, m, u, name, namelen, when);
502 tpu->first_t = pu->first_t;
503 tpu->last_t = pu->last_t;
504 tpu->usages = pu->usages;
@@ -505,7 +506,7 @@ static inline ND_PERSON_URL *registry_person_url_reallocate(ND_PERSON *p, ND_MAC
506 // ok, these are a hack - since the registry_person_url_allocate() is
507 // adding these, we have to subtract them
508 tpu->machine->links--;
508 - registry.persons_urls_memory -= sizeof(ND_PERSON_URL) + strlen(pu->name);
509 + registry.persons_urls_memory -= sizeof(REGISTRY_PERSON_URL) + strlen(pu->name);
510 registry_url_unlink_nolock(u);
511
512 freez(pu);
@@ -513,12 +514,12 @@ static inline ND_PERSON_URL *registry_person_url_reallocate(ND_PERSON *p, ND_MAC
514 return tpu;
515 }
516
516 -static inline ND_PERSON *registry_person_allocate(const char *person_guid, time_t when) {
517 - ND_PERSON *p = NULL;
517 +static inline REGISTRY_PERSON *registry_person_allocate(const char *person_guid, time_t when) {
518 + REGISTRY_PERSON *p = NULL;
519
519 - debug(D_REGISTRY, "Registry: registry_person_allocate('%s'): allocating new person, sizeof(PERSON)=%zu", (person_guid)?person_guid:"", sizeof(ND_PERSON));
520 + debug(D_REGISTRY, "Registry: registry_person_allocate('%s'): allocating new person, sizeof(PERSON)=%zu", (person_guid)?person_guid:"", sizeof(REGISTRY_PERSON));
521
521 - p = mallocz(sizeof(ND_PERSON));
522 + p = mallocz(sizeof(REGISTRY_PERSON));
523
524 if(!person_guid) {
525 for (; ;) {
@@ -536,7 +537,7 @@ static inline ND_PERSON *registry_person_allocate(const char *person_guid, time_
537 }
538 }
539 else
539 - strncpyz(p->guid, person_guid, 36);
540 + strncpyz(p->guid, person_guid, GUID_LEN);
541
542 debug(D_REGISTRY, "Registry: registry_person_allocate('%s'): creating dictionary of urls", p->guid);
543 p->urls = dictionary_create(DICTIONARY_FLAGS);
@@ -544,10 +545,10 @@ static inline ND_PERSON *registry_person_allocate(const char *person_guid, time_
545 p->first_t = p->last_t = when;
546 p->usages = 0;
547
547 - registry.persons_memory += sizeof(ND_PERSON);
548 + registry.persons_memory += sizeof(REGISTRY_PERSON);
549
550 registry.persons_count++;
550 - dictionary_set(registry.persons, p->guid, p, sizeof(ND_PERSON));
551 + dictionary_set(registry.persons, p->guid, p, sizeof(REGISTRY_PERSON));
552
553 return p;
554 }
@@ -557,13 +558,13 @@ static inline ND_PERSON *registry_person_allocate(const char *person_guid, time_
558 // 2. if it is valid, find it
559 // 3. if it is not valid, create a new one
560 // 4. return it
560 -static inline ND_PERSON *registry_person_get(const char *person_guid, time_t when) {
561 - ND_PERSON *p = NULL;
561 +static inline REGISTRY_PERSON *registry_person_get(const char *person_guid, time_t when) {
562 + REGISTRY_PERSON *p = NULL;
563
564 registry_persons_lock();
565
566 if(person_guid && *person_guid) {
566 - char buf[36 + 1];
567 + char buf[GUID_LEN + 1];
568 // validate it is a GUID
569 if(unlikely(registry_regenerate_guid(person_guid, buf) == -1))
570 info("Registry: person guid '%s' is not a valid guid. Ignoring it.", person_guid);
@@ -583,12 +584,12 @@ static inline ND_PERSON *registry_person_get(const char *person_guid, time_t whe
584 // ----------------------------------------------------------------------------
585 // LINKING OF OBJECTS
586
586 -static inline ND_PERSON_URL *registry_person_link_to_url(ND_PERSON *p, ND_MACHINE *m, ND_URL *u, char *name, size_t namelen, time_t when) {
587 +static inline REGISTRY_PERSON_URL *registry_person_link_to_url(REGISTRY_PERSON *p, REGISTRY_MACHINE *m, REGISTRY_URL *u, char *name, size_t namelen, time_t when) {
588 debug(D_REGISTRY, "registry_person_link_to_url('%s', '%s', '%s'): searching for URL in person", p->guid, m->guid, u->url);
589
590 registry_person_urls_lock(p);
591
591 - ND_PERSON_URL *pu = dictionary_get(p->urls, u->url);
592 + REGISTRY_PERSON_URL *pu = dictionary_get(p->urls, u->url);
593 if(!pu) {
594 debug(D_REGISTRY, "registry_person_link_to_url('%s', '%s', '%s'): not found", p->guid, m->guid, u->url);
595 pu = registry_person_url_allocate(p, m, u, name, namelen, when);
@@ -600,7 +601,7 @@ static inline ND_PERSON_URL *registry_person_link_to_url(ND_PERSON *p, ND_MACHIN
601 if(likely(pu->last_t < (uint32_t)when)) pu->last_t = when;
602
603 if(pu->machine != m) {
603 - ND_MACHINE_URL *mu = dictionary_get(pu->machine->urls, u->url);
604 + REGISTRY_MACHINE_URL *mu = dictionary_get(pu->machine->urls, u->url);
605 if(mu) {
606 info("registry_person_link_to_url('%s', '%s', '%s'): URL switched machines (old was '%s') - expiring it from previous machine.",
607 p->guid, m->guid, u->url, pu->machine->guid);
@@ -634,12 +635,12 @@ static inline ND_PERSON_URL *registry_person_link_to_url(ND_PERSON *p, ND_MACHIN
635 return pu;
636 }
637
637 -static inline ND_MACHINE_URL *registry_machine_link_to_url(ND_PERSON *p, ND_MACHINE *m, ND_URL *u, time_t when) {
638 +static inline REGISTRY_MACHINE_URL *registry_machine_link_to_url(REGISTRY_PERSON *p, REGISTRY_MACHINE *m, REGISTRY_URL *u, time_t when) {
639 debug(D_REGISTRY, "registry_machine_link_to_url('%s', '%s', '%s'): searching for URL in machine", p->guid, m->guid, u->url);
640
641 registry_machine_urls_lock(m);
642
642 - ND_MACHINE_URL *mu = dictionary_get(m->urls, u->url);
643 + REGISTRY_MACHINE_URL *mu = dictionary_get(m->urls, u->url);
644 if(!mu) {
645 debug(D_REGISTRY, "registry_machine_link_to_url('%s', '%s', '%s'): not found", p->guid, m->guid, u->url);
646 mu = registry_machine_url_allocate(m, u, when);
@@ -675,7 +676,7 @@ static inline int registry_should_save_db(void) {
676 return registry.log_count > registry.save_registry_every_entries;
677 }
678
678 -static inline void registry_log(const char action, ND_PERSON *p, ND_MACHINE *m, ND_URL *u, char *name) {
679 +static inline void registry_log(const char action, REGISTRY_PERSON *p, REGISTRY_MACHINE *m, REGISTRY_URL *u, char *name) {
680 if(likely(registry.log_fp)) {
681 // we lock only if the file is open
682 // to allow replaying the log at registry_log_load()
@@ -789,7 +790,7 @@ int registry_log_load(void) {
790
791 // make sure the person exists
792 // without this, a new person guid will be created
792 - ND_PERSON *p = registry_person_find(person_guid);
793 + REGISTRY_PERSON *p = registry_person_find(person_guid);
794 if(!p) p = registry_person_allocate(person_guid, when);
795
796 if(s[0] == 'A')
@@ -819,10 +820,10 @@ int registry_log_load(void) {
820 // ----------------------------------------------------------------------------
821 // REGISTRY REQUESTS
822
822 -ND_PERSON *registry_request_access(char *person_guid, char *machine_guid, char *url, char *name, time_t when) {
823 +REGISTRY_PERSON *registry_request_access(char *person_guid, char *machine_guid, char *url, char *name, time_t when) {
824 debug(D_REGISTRY, "registry_request_access('%s', '%s', '%s'): NEW REQUEST", (person_guid)?person_guid:"", machine_guid, url);
825
825 - ND_MACHINE *m = registry_machine_get(machine_guid, when);
826 + REGISTRY_MACHINE *m = registry_machine_get(machine_guid, when);
827 if(!m) return NULL;
828
829 // make sure the name is valid
@@ -832,8 +833,8 @@ ND_PERSON *registry_request_access(char *person_guid, char *machine_guid, char *
833 size_t urllen;
834 url = registry_fix_url(url, &urllen);
835
835 - ND_URL *u = registry_url_get(url, urllen);
836 - ND_PERSON *p = registry_person_get(person_guid, when);
836 + REGISTRY_URL *u = registry_url_get(url, urllen);
837 + REGISTRY_PERSON *p = registry_person_get(person_guid, when);
838
839 registry_person_link_to_url(p, m, u, name, namelen, when);
840 registry_machine_link_to_url(p, m, u, when);
@@ -845,8 +846,8 @@ ND_PERSON *registry_request_access(char *person_guid, char *machine_guid, char *
846 }
847
848 // verify the person, the machine and the URL exist in our DB
848 -ND_PERSON_URL *registry_verify_request(char *person_guid, char *machine_guid, char *url, ND_PERSON **pp, ND_MACHINE **mm) {
849 - char pbuf[36 + 1], mbuf[36 + 1];
849 +REGISTRY_PERSON_URL *registry_verify_request(char *person_guid, char *machine_guid, char *url, REGISTRY_PERSON **pp, REGISTRY_MACHINE **mm) {
850 + char pbuf[GUID_LEN + 1], mbuf[GUID_LEN + 1];
851
852 if(!person_guid || !*person_guid || !machine_guid || !*machine_guid || !url || !*url) {
853 info("Registry Request Verification: invalid request! person: '%s', machine '%s', url '%s'", person_guid?person_guid:"UNSET", machine_guid?machine_guid:"UNSET", url?url:"UNSET");
@@ -871,7 +872,7 @@ ND_PERSON_URL *registry_verify_request(char *person_guid, char *machine_guid, ch
872 machine_guid = mbuf;
873
874 // make sure the machine exists
874 - ND_MACHINE *m = registry_machine_find(machine_guid);
875 + REGISTRY_MACHINE *m = registry_machine_find(machine_guid);
876 if(!m) {
877 info("Registry Request Verification: machine not found, person: '%s', machine '%s', url '%s'", person_guid, machine_guid, url);
878 return NULL;
@@ -879,14 +880,14 @@ ND_PERSON_URL *registry_verify_request(char *person_guid, char *machine_guid, ch
880 if(mm) *mm = m;
881
882 // make sure the person exist
882 - ND_PERSON *p = registry_person_find(person_guid);
883 + REGISTRY_PERSON *p = registry_person_find(person_guid);
884 if(!p) {
885 info("Registry Request Verification: person not found, person: '%s', machine '%s', url '%s'", person_guid, machine_guid, url);
886 return NULL;
887 }
888 if(pp) *pp = p;
889
889 - ND_PERSON_URL *pu = dictionary_get(p->urls, url);
890 + REGISTRY_PERSON_URL *pu = dictionary_get(p->urls, url);
891 if(!pu) {
892 info("Registry Request Verification: URL not found for person, person: '%s', machine '%s', url '%s'", person_guid, machine_guid, url);
893 return NULL;
@@ -894,12 +895,12 @@ ND_PERSON_URL *registry_verify_request(char *person_guid, char *machine_guid, ch
895 return pu;
896 }
897
897 -ND_PERSON *registry_request_delete(char *person_guid, char *machine_guid, char *url, char *delete_url, time_t when) {
898 +REGISTRY_PERSON *registry_request_delete(char *person_guid, char *machine_guid, char *url, char *delete_url, time_t when) {
899 (void)when;
900
900 - ND_PERSON *p = NULL;
901 - ND_MACHINE *m = NULL;
902 - ND_PERSON_URL *pu = registry_verify_request(person_guid, machine_guid, url, &p, &m);
901 + REGISTRY_PERSON *p = NULL;
902 + REGISTRY_MACHINE *m = NULL;
903 + REGISTRY_PERSON_URL *pu = registry_verify_request(person_guid, machine_guid, url, &p, &m);
904 if(!pu || !p || !m) return NULL;
905
906 // normalize the url
@@ -913,7 +914,7 @@ ND_PERSON *registry_request_delete(char *person_guid, char *machine_guid, char *
914
915 registry_person_urls_lock(p);
916
916 - ND_PERSON_URL *dpu = dictionary_get(p->urls, delete_url);
917 + REGISTRY_PERSON_URL *dpu = dictionary_get(p->urls, delete_url);
918 if(!dpu) {
919 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);
920 registry_person_urls_unlock(p);
@@ -933,14 +934,14 @@ ND_PERSON *registry_request_delete(char *person_guid, char *machine_guid, char *
934
935 // a structure to pass to the dictionary_get_all() callback handler
936 struct machine_request_callback_data {
936 - ND_MACHINE *find_this_machine;
937 - ND_PERSON_URL *result;
937 + REGISTRY_MACHINE *find_this_machine;
938 + REGISTRY_PERSON_URL *result;
939 };
940
941 // the callback function
942 // this will be run for every PERSON_URL of this PERSON
943 int machine_request_callback(void *entry, void *data) {
943 - ND_PERSON_URL *mypu = (ND_PERSON_URL *)entry;
944 + REGISTRY_PERSON_URL *mypu = (REGISTRY_PERSON_URL *)entry;
945 struct machine_request_callback_data *myrdata = (struct machine_request_callback_data *)data;
946
947 if(mypu->machine == myrdata->find_this_machine) {
@@ -951,14 +952,14 @@ int machine_request_callback(void *entry, void *data) {
952 return 0; // continue
953 }
954
954 -ND_MACHINE *registry_request_machine(char *person_guid, char *machine_guid, char *url, char *request_machine, time_t when) {
955 +REGISTRY_MACHINE *registry_request_machine(char *person_guid, char *machine_guid, char *url, char *request_machine, time_t when) {
956 (void)when;
957
957 - char mbuf[36 + 1];
958 + char mbuf[GUID_LEN + 1];
959
959 - ND_PERSON *p = NULL;
960 - ND_MACHINE *m = NULL;
961 - ND_PERSON_URL *pu = registry_verify_request(person_guid, machine_guid, url, &p, &m);
960 + REGISTRY_PERSON *p = NULL;
961 + REGISTRY_MACHINE *m = NULL;
962 + REGISTRY_PERSON_URL *pu = registry_verify_request(person_guid, machine_guid, url, &p, &m);
963 if(!pu || !p || !m) return NULL;
964
965 // make sure the machine GUID is valid
@@ -1020,7 +1021,7 @@ void registry_set_cookie(struct web_client *w, const char *guid) {
1021 snprintfz(w->cookie2, COOKIE_MAX, NETDATA_REGISTRY_COOKIE_NAME "=%s; Domain=%s; Expires=%s", guid, registry.registry_domain, edate);
1022 }
1023
1023 -static inline void registry_set_person_cookie(struct web_client *w, ND_PERSON *p) {
1024 +static inline void registry_set_person_cookie(struct web_client *w, REGISTRY_PERSON *p) {
1025 registry_set_cookie(w, p->guid);
1026 }
1027
@@ -1057,15 +1058,15 @@ static inline int registry_json_disabled(struct web_client *w, const char *actio
1058
1059 // structure used be the callbacks below
1060 struct registry_json_walk_person_urls_callback {
1060 - ND_PERSON *p;
1061 - ND_MACHINE *m;
1061 + REGISTRY_PERSON *p;
1062 + REGISTRY_MACHINE *m;
1063 struct web_client *w;
1064 int count;
1065 };
1066
1067 // callback for rendering PERSON_URLs
1068 static inline int registry_json_person_url_callback(void *entry, void *data) {
1068 - ND_PERSON_URL *pu = (ND_PERSON_URL *)entry;
1069 + REGISTRY_PERSON_URL *pu = (REGISTRY_PERSON_URL *)entry;
1070 struct registry_json_walk_person_urls_callback *c = (struct registry_json_walk_person_urls_callback *)data;
1071 struct web_client *w = c->w;
1072
@@ -1080,10 +1081,10 @@ static inline int registry_json_person_url_callback(void *entry, void *data) {
1081
1082 // callback for rendering MACHINE_URLs
1083 static inline int registry_json_machine_url_callback(void *entry, void *data) {
1083 - ND_MACHINE_URL *mu = (ND_MACHINE_URL *)entry;
1084 + REGISTRY_MACHINE_URL *mu = (REGISTRY_MACHINE_URL *)entry;
1085 struct registry_json_walk_person_urls_callback *c = (struct registry_json_walk_person_urls_callback *)data;
1086 struct web_client *w = c->w;
1086 - ND_MACHINE *m = c->m;
1087 + REGISTRY_MACHINE *m = c->m;
1088
1089 if(unlikely(c->count++))
1090 buffer_strcat(w->response.data, ",");
@@ -1100,7 +1101,7 @@ int registry_request_access_json(struct web_client *w, char *person_guid, char *
1101 if(!registry.enabled)
1102 return registry_json_disabled(w, "access");
1103
1103 - ND_PERSON *p = registry_request_access(person_guid, machine_guid, url, name, when);
1104 + REGISTRY_PERSON *p = registry_request_access(person_guid, machine_guid, url, name, when);
1105 if(!p) {
1106 registry_json_header(w, "access", REGISTRY_STATUS_FAILED);
1107 registry_json_footer(w);
@@ -1127,7 +1128,7 @@ int registry_request_delete_json(struct web_client *w, char *person_guid, char *
1128 if(!registry.enabled)
1129 return registry_json_disabled(w, "delete");
1130
1130 - ND_PERSON *p = registry_request_delete(person_guid, machine_guid, url, delete_url, when);
1131 + REGISTRY_PERSON *p = registry_request_delete(person_guid, machine_guid, url, delete_url, when);
1132 if(!p) {
1133 registry_json_header(w, "delete", REGISTRY_STATUS_FAILED);
1134 registry_json_footer(w);
@@ -1145,7 +1146,7 @@ int registry_request_search_json(struct web_client *w, char *person_guid, char *
1146 if(!registry.enabled)
1147 return registry_json_disabled(w, "search");
1148
1148 - ND_MACHINE *m = registry_request_machine(person_guid, machine_guid, url, request_machine, when);
1149 + REGISTRY_MACHINE *m = registry_request_machine(person_guid, machine_guid, url, request_machine, when);
1150 if(!m) {
1151 registry_json_header(w, "search", REGISTRY_STATUS_FAILED);
1152 registry_json_footer(w);
@@ -1165,14 +1166,14 @@ int registry_request_search_json(struct web_client *w, char *person_guid, char *
1166
1167 // structure used be the callbacks below
1168 struct registry_person_url_callback_verify_machine_exists_data {
1168 - ND_MACHINE *m;
1169 + REGISTRY_MACHINE *m;
1170 int count;
1171 };
1172
1173 int registry_person_url_callback_verify_machine_exists(void *entry, void *data) {
1174 struct registry_person_url_callback_verify_machine_exists_data *d = (struct registry_person_url_callback_verify_machine_exists_data *)data;
1174 - ND_PERSON_URL *pu = (ND_PERSON_URL *)entry;
1175 - ND_MACHINE *m = d->m;
1175 + REGISTRY_PERSON_URL *pu = (REGISTRY_PERSON_URL *)entry;
1176 + REGISTRY_MACHINE *m = d->m;
1177
1178 if(pu->machine == m)
1179 d->count++;
@@ -1188,21 +1189,21 @@ int registry_request_switch_json(struct web_client *w, char *person_guid, char *
1189 if(!registry.enabled)
1190 return registry_json_disabled(w, "switch");
1191
1191 - ND_PERSON *op = registry_person_find(person_guid);
1192 + REGISTRY_PERSON *op = registry_person_find(person_guid);
1193 if(!op) {
1194 registry_json_header(w, "switch", REGISTRY_STATUS_FAILED);
1195 registry_json_footer(w);
1196 return 430;
1197 }
1198
1198 - ND_PERSON *np = registry_person_find(new_person_guid);
1199 + REGISTRY_PERSON *np = registry_person_find(new_person_guid);
1200 if(!np) {
1201 registry_json_header(w, "switch", REGISTRY_STATUS_FAILED);
1202 registry_json_footer(w);
1203 return 431;
1204 }
1205
1205 - ND_MACHINE *m = registry_machine_find(machine_guid);
1206 + REGISTRY_MACHINE *m = registry_machine_find(machine_guid);
1207 if(!m) {
1208 registry_json_header(w, "switch", REGISTRY_STATUS_FAILED);
1209 registry_json_footer(w);
@@ -1265,11 +1266,11 @@ char *registry_get_this_machine_guid(void) {
1266 // read it from disk
1267 int fd = open(registry.machine_guid_filename, O_RDONLY);
1268 if(fd != -1) {
1268 - char buf[36 + 1];
1269 - if(read(fd, buf, 36) != 36)
1269 + char buf[GUID_LEN + 1];
1270 + if(read(fd, buf, GUID_LEN) != GUID_LEN)
1271 error("Failed to read machine GUID from '%s'", registry.machine_guid_filename);
1272 else {
1272 - buf[36] = '\0';
1273 + buf[GUID_LEN] = '\0';
1274 if(registry_regenerate_guid(buf, registry.machine_guid) == -1) {
1275 error("Failed to validate machine GUID '%s' from '%s'. Ignoring it - this might mean this netdata will appear as duplicate in the registry.",
1276 buf, registry.machine_guid_filename);
@@ -1288,14 +1289,14 @@ char *registry_get_this_machine_guid(void) {
1289
1290 uuid_generate_time(uuid);
1291 uuid_unparse_lower(uuid, registry.machine_guid);
1291 - registry.machine_guid[36] = '\0';
1292 + registry.machine_guid[GUID_LEN] = '\0';
1293
1294 // save it
1295 fd = open(registry.machine_guid_filename, O_WRONLY|O_CREAT|O_TRUNC, 444);
1296 if(fd == -1)
1297 fatal("Cannot create unique machine id file '%s'. Please fix this.", registry.machine_guid_filename);
1298
1298 - if(write(fd, registry.machine_guid, 36) != 36)
1299 + if(write(fd, registry.machine_guid, GUID_LEN) != GUID_LEN)
1300 fatal("Cannot write the unique machine id file '%s'. Please fix this.", registry.machine_guid_filename);
1301
1302 close(fd);
@@ -1311,7 +1312,7 @@ char *registry_get_this_machine_guid(void) {
1312 // REGISTRY LOAD/SAVE
1313
1314 int registry_machine_save_url(void *entry, void *file) {
1314 - ND_MACHINE_URL *mu = entry;
1315 + REGISTRY_MACHINE_URL *mu = entry;
1316 FILE *fp = file;
1317
1318 debug(D_REGISTRY, "Registry: registry_machine_save_url('%s')", mu->url->url);
@@ -1330,7 +1331,7 @@ int registry_machine_save_url(void *entry, void *file) {
1331 }
1332
1333 int registry_machine_save(void *entry, void *file) {
1333 - ND_MACHINE *m = entry;
1334 + REGISTRY_MACHINE *m = entry;
1335 FILE *fp = file;
1336
1337 debug(D_REGISTRY, "Registry: registry_machine_save('%s')", m->guid);
@@ -1354,7 +1355,7 @@ int registry_machine_save(void *entry, void *file) {
1355 }
1356
1357 static inline int registry_person_save_url(void *entry, void *file) {
1357 - ND_PERSON_URL *pu = entry;
1358 + REGISTRY_PERSON_URL *pu = entry;
1359 FILE *fp = file;
1360
1361 debug(D_REGISTRY, "Registry: registry_person_save_url('%s')", pu->url->url);
@@ -1375,7 +1376,7 @@ static inline int registry_person_save_url(void *entry, void *file) {
1376 }
1377
1378 static inline int registry_person_save(void *entry, void *file) {
1378 - ND_PERSON *p = entry;
1379 + REGISTRY_PERSON *p = entry;
1380 FILE *fp = file;
1381
1382 debug(D_REGISTRY, "Registry: registry_person_save('%s')", p->guid);
@@ -1512,9 +1513,9 @@ int registry_save(void) {
1513
1514 static inline size_t registry_load(void) {
1515 char *s, buf[4096 + 1];
1515 - ND_PERSON *p = NULL;
1516 - ND_MACHINE *m = NULL;
1517 - ND_URL *u = NULL;
1516 + REGISTRY_PERSON *p = NULL;
1517 + REGISTRY_MACHINE *m = NULL;
1518 + REGISTRY_URL *u = NULL;
1519 size_t line = 0;
1520
1521 debug(D_REGISTRY, "Registry: loading active db from: '%s'", registry.db_filename);
@@ -1605,7 +1606,7 @@ static inline size_t registry_load(void) {
1606 m = registry_machine_find(&s[32]);
1607 if(!m) m = registry_machine_allocate(&s[32], first_t);
1608
1608 - ND_PERSON_URL *pu = registry_person_url_allocate(p, m, u, &s[69], strlen(&s[69]), first_t);
1609 + REGISTRY_PERSON_URL *pu = registry_person_url_allocate(p, m, u, &s[69], strlen(&s[69]), first_t);
1610 pu->last_t = strtoul(&s[11], NULL, 16);
1611 pu->usages = strtoul(&s[20], NULL, 16);
1612 pu->flags = strtoul(&s[29], NULL, 16);
@@ -1628,7 +1629,7 @@ static inline size_t registry_load(void) {
1629 // u = registry_url_allocate_nolock(&s[32], strlen(&s[32]));
1630 u = registry_url_get_nolock(&s[32], strlen(&s[32]));
1631
1631 - ND_MACHINE_URL *mu = registry_machine_url_allocate(m, u, strtoul(&s[2], NULL, 16));
1632 + REGISTRY_MACHINE_URL *mu = registry_machine_url_allocate(m, u, strtoul(&s[2], NULL, 16));
1633 mu->last_t = strtoul(&s[11], NULL, 16);
1634 mu->usages = strtoul(&s[20], NULL, 16);
1635 mu->flags = strtoul(&s[29], NULL, 16);
@@ -1740,12 +1741,12 @@ void registry_free(void) {
1741 // since the dictionaries use memory we allocated
1742
1743 while(registry.persons->values_index.root) {
1743 - ND_PERSON *p = ((NAME_VALUE *)registry.persons->values_index.root)->value;
1744 + REGISTRY_PERSON *p = ((NAME_VALUE *)registry.persons->values_index.root)->value;
1745
1746 // fprintf(stderr, "\nPERSON: '%s', first: %u, last: %u, usages: %u\n", p->guid, p->first_t, p->last_t, p->usages);
1747
1748 while(p->urls->values_index.root) {
1748 - ND_PERSON_URL *pu = ((NAME_VALUE *)p->urls->values_index.root)->value;
1749 + REGISTRY_PERSON_URL *pu = ((NAME_VALUE *)p->urls->values_index.root)->value;
1750
1751 // 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);
1752
@@ -1770,12 +1771,12 @@ void registry_free(void) {
1771 }
1772
1773 while(registry.machines->values_index.root) {
1773 - ND_MACHINE *m = ((NAME_VALUE *)registry.machines->values_index.root)->value;
1774 + REGISTRY_MACHINE *m = ((NAME_VALUE *)registry.machines->values_index.root)->value;
1775
1776 // fprintf(stderr, "\nMACHINE: '%s', first: %u, last: %u, usages: %u\n", m->guid, m->first_t, m->last_t, m->usages);
1777
1778 while(m->urls->values_index.root) {
1778 - ND_MACHINE_URL *mu = ((NAME_VALUE *)m->urls->values_index.root)->value;
1779 + REGISTRY_MACHINE_URL *mu = ((NAME_VALUE *)m->urls->values_index.root)->value;
1780
1781 // 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);
1782