/* not reached */
}
-static void add_to_list (string_list_t ** list, const char *str)
+static void add_to_list(string_list_t **list, const char *str)
{
- string_list_t *t, *last = NULL;
-
- /* don't add a NULL or empty string to the list */
- if (!str || *str == '\0')
- return;
+ /* don't add a NULL or empty string to the list */
+ if (m_strisempty(str))
+ return;
- /* check to make sure the item is not already on this list */
- for (last = *list; last; last = last->next) {
- if (ascii_strcasecmp (str, last->data) == 0) {
- /* already on the list, so just ignore it */
- last = NULL;
- break;
+ /* check to make sure the item is not already on this list */
+ while (*list) {
+ if (!ascii_strcasecmp(str, (*list)->data))
+ return;
+ list = &(*list)->next;
}
- if (!last->next)
- break;
- }
- if (!*list || last) {
- t = p_new(string_list_t, 1);
- t->data = m_strdup(str);
- if (last) {
- last->next = t;
- last = last->next;
- }
- else
- *list = last = t;
- }
+ *list = p_new(string_list_t, 1);
+ (*list)->data = m_strdup(str);
}
static int
add_to_rx_list(rx_t **list, const char *s, int flags, BUFFER *err)
{
- rx_t* rx;
+ rx_t *rx;
if (m_strisempty(s))
return 0;
static int add_to_spam_list(rx_t **list, const char *pat,
const char *templ, BUFFER * err)
{
- rx_t **last, *rx;
+ rx_t *rx;
if (m_strisempty(pat) || !templ)
return 0;
}
/* check to make sure the item is not already on this list */
- for (last = list; *last; last = &(*last)->next) {
- if (!ascii_strcasecmp(rx->pattern, (*last)->pattern) == 0) {
- rx_t *tmp = rx_list_pop(last);
+ while (*list) {
+ if (!ascii_strcasecmp(rx->pattern, (*list)->pattern)) {
+ rx_t *tmp = rx_list_pop(list);
rx_delete(&tmp);
- last = rx_list_last(last);
- break;
+ } else {
+ list = &(*list)->next;
}
}
- *last = rx;
+ *list = rx;
rx_set_template(rx, templ);
return 0;
}
static int remove_from_spam_list (rx_t ** list, const char *pat)
{
- int nremoved = 0;
-
- while (*list) {
- if (!m_strcmp((*list)->pattern, pat)) {
- rx_t *spam = rx_list_pop(list);
- rx_delete(&spam);
- nremoved++;
- } else {
- list = &(*list)->next;
- }
- }
+ int nremoved = 0;
+
+ while (*list) {
+ if (!m_strcmp((*list)->pattern, pat)) {
+ rx_t *spam = rx_list_pop(list);
+ rx_delete(&spam);
+ nremoved++;
+ } else {
+ list = &(*list)->next;
+ }
+ }
- return nremoved;
+ return nremoved;
}
-static void remove_from_list (string_list_t ** l, const char *str)
+static void remove_from_list(string_list_t **l, const char *str)
{
- string_list_t *p, *last = NULL;
+ if (!m_strcmp("*", str)) {
+ string_list_wipe(l); /* ``unCMD *'' means delete all current entries */
+ return;
+ }
- if (m_strcmp("*", str) == 0)
- string_list_wipe(l); /* ``unCMD *'' means delete all current entries */
- else {
- p = *l;
- last = NULL;
- while (p) {
- if (ascii_strcasecmp (str, p->data) == 0) {
- p_delete(&p->data);
- if (last)
- last->next = p->next;
- else
- (*l) = p->next;
- p_delete(&p);
- }
- else {
- last = p;
- p = p->next;
- }
+ while (*l) {
+ if (!ascii_strcasecmp(str, (*l)->data)) {
+ string_list_t *it = string_list_pop(l);
+ string_item_delete(&it);
+ } else {
+ l = &(*l)->next;
+ }
}
- }
}
static int remove_from_rx_list(rx_t **l, const char *str)