REGISTRY_PERSON_URL *registry_person_url_allocate(REGISTRY_PERSON *p, REGISTRY_MACHINE *m, REGISTRY_URL *u, char *name, size_t namelen, time_t when) { debug(D_REGISTRY, "registry_person_url_allocate('%s', '%s', '%s'): allocating %zu bytes", p->guid, m->guid, u->url, sizeof(REGISTRY_PERSON_URL) + namelen); // protection from too big names if(namelen > registry.max_name_length) namelen = registry.max_name_length; REGISTRY_PERSON_URL *pu = mallocz(sizeof(REGISTRY_PERSON_URL) + namelen); // a simple strcpy() should do the job // but I prefer to be safe, since the caller specified urllen strncpyz(pu->machine_name, name, namelen); pu->machine = m; pu->first_t = pu->last_t = (uint32_t)when; pu->usages = 1; pu->url = u; pu->flags = REGISTRY_URL_FLAGS_DEFAULT; m->links++; registry.persons_urls_memory += sizeof(REGISTRY_PERSON_URL) + namelen; debug(D_REGISTRY, "registry_person_url_allocate('%s', '%s', '%s'): indexing URL in person", p->guid, m->guid, u->url); REGISTRY_PERSON_URL *tpu = registry_person_url_index_add(p, pu); if(tpu != pu) { error("Registry: Attempted to add duplicate person url '%s' with name '%s' to person '%s'", u->url, name, p->guid); free(pu); pu = tpu; } else registry_url_link(u); return pu; }
REGISTRY_MACHINE_URL *registry_machine_url_allocate(REGISTRY_MACHINE *m, REGISTRY_URL *u, time_t when) { debug(D_REGISTRY, "registry_machine_url_allocate('%s', '%s'): allocating %zu bytes", m->guid, u->url, sizeof(REGISTRY_MACHINE_URL)); REGISTRY_MACHINE_URL *mu = mallocz(sizeof(REGISTRY_MACHINE_URL)); mu->first_t = mu->last_t = (uint32_t)when; mu->usages = 1; mu->url = u; mu->flags = REGISTRY_URL_FLAGS_DEFAULT; registry.machines_urls_memory += sizeof(REGISTRY_MACHINE_URL); debug(D_REGISTRY, "registry_machine_url_allocate('%s', '%s'): indexing URL in machine", m->guid, u->url); dictionary_set(m->machine_urls, u->url, mu, sizeof(REGISTRY_MACHINE_URL)); registry_url_link(u); return mu; }