list_item_t* list_insert_sorted_new(list_t* list, void* data, int (*compare)(const void*, const void*)) { list_item_t* item = list_alloc_item(data); list_insert_sorted(list, data, compare); return item; }
list_item_t* list_prepend_new(list_t* list, void* data) { list_item_t* item = list_alloc_item(data); list_prepend(list, item); return item; }
list_item_t* list_insert_before_new(list_t* list, list_item_t* ref, void* data) { list_item_t* item = list_alloc_item(data); list_insert_before(list, ref, item); return item; }
struct list *list_prepend_data(struct list *list, void *data) { return list_prepend_item(list, list_alloc_item(data)); }
void init_blacklist (void) { struct blacklist_entry *entry; char *temp, *parsestr, *token, *subtoken, *subsubtoken; char *list, *item, *subitem; char *username = NULL; temp = getenv ("NFBLACKLIST"); if (temp != NULL) parsestr = newts_strdup (temp); else parsestr = NULL; list_init (&blacklist, (void * (*) (void)) alloc_blacklist_entry, (void (*) (void *)) free_blacklist_entry, NULL); if (parsestr != NULL) { token = strtok_r (parsestr, " ", &list); while (token != NULL) { if (*token == ':') { /* ":nf,nf, ..." format */ token++; subtoken = strtok_r (token, ",", &item); while (subtoken != NULL) { entry = list_alloc_item (&blacklist); entry->username = NULL; entry->nf = newts_strdup (subtoken); list_insert_next (&blacklist, list_tail (&blacklist), (void *) entry); subtoken = strtok_r (NULL, ",", &item); } } else { subtoken = strtok_r (token, ":", &item); username = newts_strdup (subtoken); subtoken = strtok_r (NULL, ":", &item); if (subtoken == NULL) { /* "user" format */ entry = list_alloc_item (&blacklist); entry->username = newts_strdup (username); entry->nf = NULL; list_insert_next (&blacklist, list_tail (&blacklist), (void *) entry); } else { /* "user:nf,nf, ..." format */ subsubtoken = strtok_r (subtoken, ",", &subitem); while (subsubtoken != NULL) { entry = list_alloc_item (&blacklist); entry->username = newts_strdup (username); entry->nf = newts_strdup (subsubtoken); list_insert_next (&blacklist, list_tail (&blacklist), (void *) entry); subsubtoken = strtok_r (NULL, ",", &subitem); } } newts_free (username); } token = strtok_r (NULL, " ", &list); } } newts_free (parsestr); temp = getenv ("NFWHITELIST"); if (temp != NULL) parsestr = newts_strdup (temp); else parsestr = NULL; list_init (&whitelist, (void * (*) (void)) alloc_blacklist_entry, (void (*) (void *)) free_blacklist_entry, NULL); if (parsestr != NULL) { token = strtok_r (parsestr, " ", &list); while (token != NULL) { if (*token == ':') { /* ":nf,nf, ..." format */ subtoken = strtok_r (token, ",", &item); while (subtoken != NULL) { entry = list_alloc_item (&whitelist); entry->username = NULL; entry->nf = newts_strdup (subtoken); list_insert_next (&whitelist, list_tail (&whitelist), (void *) entry); subtoken = strtok_r (NULL, ",", &item); } } else { subtoken = strtok_r (token, ":", &item); username = newts_strdup (subtoken); subtoken = strtok_r (NULL, ":", &item); if (subtoken == NULL) { /* "user" format */ entry = list_alloc_item (&whitelist); entry->username = newts_strdup (username); entry->nf = NULL; list_insert_next (&whitelist, list_tail (&whitelist), (void *) entry); } else { /* "user:nf,nf, ..." format */ subsubtoken = strtok_r (subtoken, ",", &subitem); while (subsubtoken != NULL) { entry = list_alloc_item (&whitelist); entry->username = newts_strdup (username); entry->nf = newts_strdup (subsubtoken); list_insert_next (&whitelist, list_tail (&whitelist), (void *) entry); subsubtoken = strtok_r (NULL, ",", &subitem); } } newts_free (username); } token = strtok_r (NULL, " ", &list); } } newts_free (parsestr); return; }