#include "config.h"
+#ifdef FEATURE_CLIENT_TAGS
+
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
#include "jcc.h"
#include "miscutil.h"
#include "errlog.h"
+#include "parsers.h"
struct client_specific_tag
{
clients_with_tags = clients_with_tags->next;
}
+ assert(clients_with_tags != NULL);
+ if (clients_with_tags == NULL)
+ {
+ log_error(LOG_LEVEL_ERROR,
+ "Tried to remove tag %s for tag-less client %s",
+ tag, client_address);
+ }
enabled_tags = clients_with_tags->tags;
while (enabled_tags != NULL)
{
return JB_ERR_PARSE;
}
- if (client_has_requested_tag(csp->ip_addr_str, tag_name))
+ if (client_has_requested_tag(csp->client_address, tag_name))
{
log_error(LOG_LEVEL_ERROR,
- "Tag '%s' already enabled for client '%s'", tag->name, csp->ip_addr_str);
+ "Tag '%s' already enabled for client '%s'", tag->name, csp->client_address);
}
else
{
- add_tag_for_client(csp->ip_addr_str, tag_name, time_to_live);
+ add_tag_for_client(csp->client_address, tag_name, time_to_live);
log_error(LOG_LEVEL_INFO,
"Tag '%s' enabled for client '%s'. TTL: %d.",
- tag->name, csp->ip_addr_str, time_to_live);
+ tag->name, csp->client_address, time_to_live);
}
privoxy_mutex_unlock(&client_tags_mutex);
return JB_ERR_PARSE;
}
- if (client_has_requested_tag(csp->ip_addr_str, tag_name))
+ if (client_has_requested_tag(csp->client_address, tag_name))
{
- remove_tag_for_client(csp->ip_addr_str, tag_name);
+ remove_tag_for_client(csp->client_address, tag_name);
log_error(LOG_LEVEL_INFO,
- "Tag '%s' disabled for client '%s'", tag->name, csp->ip_addr_str);
+ "Tag '%s' disabled for client '%s'", tag->name, csp->client_address);
}
else
{
log_error(LOG_LEVEL_ERROR,
"Tag '%s' currently not set for client '%s'",
- tag->name, csp->ip_addr_str);
+ tag->name, csp->client_address);
}
privoxy_mutex_unlock(&client_tags_mutex);
return 0;
}
+
+
+/*********************************************************************
+ *
+ * Function : set_client_address
+ *
+ * Description : Sets the client address that will be used to enable,
+ * disable, or apply client tags.
+ *
+ * Parameters :
+ * 1 : csp = Current client state (buffers, headers, etc...)
+ * 2 : headers = Client headers
+ *
+ * Returns : void.
+ *
+ *********************************************************************/
+void set_client_address(struct client_state *csp, const struct list *headers)
+{
+ if (csp->config->trust_x_forwarded_for)
+ {
+ const char *client_address;
+
+ client_address = get_header_value(headers, "X-Forwarded-For:");
+ if (client_address != NULL)
+ {
+ csp->client_address = strdup_or_die(client_address);
+ log_error(LOG_LEVEL_HEADER,
+ "Got client address %s from X-Forwarded-For header",
+ csp->client_address);
+ }
+ }
+
+ if (csp->client_address == NULL)
+ {
+ csp->client_address = strdup_or_die(csp->ip_addr_str);
+ }
+}
+
+#else
+#error Compiling client-tags.c without FEATURE_CLIENT_TAGS
+#endif /* def FEATURE_CLIENT_TAGS */