static CamConfigSection *camconfig_add_section( CamConfig *ccfg, char *newsec ) { CamConfigSection *res; char *keyval; hnode_t *node; if( hash_lookup( ccfg->mainhash, newsec ) != NULL ){ camserv_log( "camconfig", "Section \"%s\" multi-defined in cfg", newsec ); return NULL; } if( (res = section_new( newsec )) == NULL ) return NULL; if( (keyval = strdup( newsec )) == NULL ){ section_dest( res ); return NULL; } if( (node = hnode_create( res )) == NULL ){ section_dest( res ); free( keyval ); return NULL; } hash_insert( ccfg->mainhash, node, keyval ); return res; }
int main(int argc, char *argv[]) { hash_t *htab; hnode_t *hnp, *hnp1; char *line; ca_o ca, pca; int i; unsigned long phash = 0; htab = hash_create(argc, (hash_comp_t) hash_comp_test, hash_fun_test); //printf("key width = %lu\n", HASH_VAL_T_MAX); for (i = 1; i < argc; i++) { line = argv[i]; ca = ca_new(line); ca->ca_phash = phash; phash = ca->ca_hash; if (! hash_lookup(htab, (void *)ca->ca_hash)) { hnp = hnode_create(ca); hash_insert(htab, hnp, (void *)ca->ca_hash); printf("%s [%lu.%lu]\n", ca->ca_line, ca->ca_phash, ca->ca_hash); } else { printf("%s present\n", line); } } hscan_t hscan; hash_scan_begin(&hscan, htab); for (hnp = hash_scan_next(&hscan); hnp; hnp = hash_scan_next(&hscan)) { ca = (ca_o)hnode_get(hnp); printf("%s [%lu.%lu]\n", ca->ca_line, ca->ca_phash, ca->ca_hash); if ((hnp1 = hash_lookup(htab, (void *)ca->ca_phash))) { pca = (ca_o)hnode_get(hnp1); printf("parent of %s is %s\n", ca->ca_line, pca->ca_line); } else { printf("%s [%lu.%lu] has no parent\n", ca->ca_line, ca->ca_phash, ca->ca_hash); } //hash_scan_delete(htab, hnp); //hnode_destroy(hnp); } return 0; }
/// Adds a new CA to the audit group. /// @param[in] ldr the leader object reference /// @param[in] sub the new member CA void ca_aggregate(ca_o ldr, ca_o sub) { ck_o ck; hnode_t *hnp; assert(ldr->ca_group_hash); ck = ck_new_from_ca(sub); if (hash_lookup(ldr->ca_group_hash, ck)) { ck_destroy(ck); } else { if (!(hnp = hnode_create(sub))) { putil_int("hnode_create()"); } hash_insert(ldr->ca_group_hash, hnp, ck); } // Each member of the audit group gets a pointer back to the group leader. ca_set_leader(sub, ldr); }