struct FirewallConfig *insertElem (struct ConfigEntry *entry, struct FirewallConfig *tree, int *errno) { if (tree != NULL) { int r = compareEntry(entry, tree->entry); if (r == 0) { *errno = ALREADY_IN_TREE; return (NULL); } if (r < 0) tree->left = insertElem (entry, tree->left, errno); else tree->right = insertElem (entry, tree->right, errno); } else { /* create a new leaf */ tree = malloc (sizeof (struct FirewallConfig)); if (!tree) { *errno = OUT_OF_MEMORY; return (NULL); } tree->entry = entry; tree->left = NULL; tree->right = NULL; } return tree; } struct FirewallConfig { struct ConfigEntry *entry; struct FirewallConfig *left; struct FirewallConfig *right; }; int compareEntry (struct ConfigEntry *entry1, struct ConfigEntry *entry2) { int result; result = strCompare (entry1->uid, entry2->uid); if (result != 0 ) { return result; } result = strCompare (entry1->program, entry2->program); if (result != 0 ) { return result; } result = strCompare (entry1->IPAddress, entry2->IPAddress); if (result != 0 ) { return result; } if (entry1->port < entry2->port) return -1; else if (entry1->port > entry2->port) return 1; else return 0; }