2005-09-15 09:58:31 -04:00
|
|
|
/* Blacklist manager */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "elinks.h"
|
|
|
|
|
|
|
|
#include "protocol/http/blacklist.h"
|
2010-07-24 11:07:18 -04:00
|
|
|
#include "protocol/protocol.h"
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "protocol/uri.h"
|
|
|
|
#include "util/lists.h"
|
|
|
|
#include "util/memory.h"
|
|
|
|
#include "util/string.h"
|
|
|
|
|
|
|
|
|
|
|
|
struct blacklist_entry {
|
|
|
|
LIST_HEAD(struct blacklist_entry);
|
|
|
|
|
|
|
|
enum blacklist_flags flags;
|
2021-01-02 10:20:27 -05:00
|
|
|
char host[1]; /* Must be last. */
|
2005-09-15 09:58:31 -04:00
|
|
|
};
|
|
|
|
|
2007-07-26 15:39:08 -04:00
|
|
|
static INIT_LIST_OF(struct blacklist_entry, blacklist);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
|
|
|
|
static struct blacklist_entry *
|
|
|
|
get_blacklist_entry(struct uri *uri)
|
|
|
|
{
|
|
|
|
struct blacklist_entry *entry;
|
|
|
|
|
2010-07-24 11:07:18 -04:00
|
|
|
if (uri->protocol != PROTOCOL_MAILCAP) {
|
|
|
|
assert(uri && uri->hostlen > 0);
|
|
|
|
if_assert_failed return NULL;
|
|
|
|
}
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
foreach (entry, blacklist)
|
2008-10-18 21:25:00 -04:00
|
|
|
if (!c_strlcasecmp(entry->host, -1, uri->host, uri->hostlen))
|
2005-09-15 09:58:31 -04:00
|
|
|
return entry;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
add_blacklist_entry(struct uri *uri, enum blacklist_flags flags)
|
|
|
|
{
|
|
|
|
struct blacklist_entry *entry = get_blacklist_entry(uri);
|
|
|
|
|
|
|
|
if (entry) {
|
|
|
|
entry->flags |= flags;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry = mem_alloc(sizeof(*entry) + uri->hostlen);
|
|
|
|
if (!entry) return;
|
|
|
|
|
|
|
|
entry->flags = flags;
|
|
|
|
safe_strncpy(entry->host, uri->host, uri->hostlen + 1);
|
|
|
|
add_to_list(blacklist, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
del_blacklist_entry(struct uri *uri, enum blacklist_flags flags)
|
|
|
|
{
|
|
|
|
struct blacklist_entry *entry = get_blacklist_entry(uri);
|
|
|
|
|
|
|
|
if (!entry) return;
|
|
|
|
|
|
|
|
entry->flags &= ~flags;
|
|
|
|
if (entry->flags) return;
|
|
|
|
|
|
|
|
del_from_list(entry);
|
|
|
|
mem_free(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum blacklist_flags
|
|
|
|
get_blacklist_flags(struct uri *uri)
|
|
|
|
{
|
|
|
|
struct blacklist_entry *entry = get_blacklist_entry(uri);
|
|
|
|
|
|
|
|
return entry ? entry->flags : SERVER_BLACKLIST_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
free_blacklist(void)
|
|
|
|
{
|
|
|
|
free_list(blacklist);
|
|
|
|
}
|