/* * Add a node to the Trie * Define whether it's an exception (!<domain.tld>) or a regular TLD (including wildcards ones) * Exception go under the Tree root's kid part, regular under the root's sibling. */ static int faup_tld_tree_add_node(TLDNode **Tree, char *TLD, int tLen) { TLDNode *pNode; // regular tld if( *TLD != '!' ) { // First node if( (*Tree)->kid == NULL ) { (*Tree)->kid = calloc(1, sizeof(TLDNode)); if( (*Tree)->kid == NULL ) return -1; (*Tree)->kid->c = '\0'; } pNode = (*Tree)->kid; } // exception else { if( (*Tree)->sibling == NULL ) { (*Tree)->sibling = calloc(1, sizeof(TLDNode)); if( (*Tree)->sibling == NULL ) return -1; (*Tree)->sibling->c = '\0'; } pNode = (*Tree)->sibling; } return _faup_tld_tree_add_node(&pNode, TLD, tLen); }
/* * Add a node to the Trie * Define whether it's an exception (!<domain.tld>) or a regular TLD (including wildcards ones) * Exception go under the Tree root's kid part, regular under the root's sibling. */ static int faup_tld_tree_add_node(TLDNode **Tree, char *TLD, int tld_len) { TLDNode *pNode; if (!Tree) { fprintf(stderr, "%s Tree does not exists!\n", __FUNCTION__); return -1; } // regular tld if( *TLD != '!' ) { // First node if( (*Tree)->kid == NULL ) { (*Tree)->kid = calloc(1, sizeof(TLDNode)); if( (*Tree)->kid == NULL ) { return -1; } (*Tree)->kid->c = '\0'; } pNode = (*Tree)->kid; } // exception else { if( (*Tree)->sibling == NULL ) { (*Tree)->sibling = calloc(1, sizeof(TLDNode)); if( (*Tree)->sibling == NULL ) { return -1; } (*Tree)->sibling->c = '\0'; } pNode = (*Tree)->sibling; } return _faup_tld_tree_add_node(&pNode, TLD, tld_len); }