Permalink
Browse files

Merge remote-tracking branch 'origin/jwip'

  • Loading branch information...
2 parents 80522c2 + 38b30d5 commit b0fd8f0a648334fdb9f07acbfeacd3819ec8aa53 @thejh committed May 31, 2012
Showing with 65 additions and 6 deletions.
  1. +17 −0 src/blacklist.c
  2. +1 −0 src/blacklist.h
  3. 0 src/list.c
  4. +9 −0 src/list.h
  5. +38 −6 src/main.c
View
@@ -31,6 +31,16 @@ static struct bl_entry *get_bl_entry(char *host) {
return NULL;
}
+static struct bl_entry *get_bl_entry_by_url(char *url, char *url_size) {
+ // WARNING: duplicate code! (see main.c)
+ char *hostname_end = memchr(url + 7, '/', url_size - 7);
+ assert(hostname_end != NULL);
+ char hostname[hostname_end - url - 7 + 1];
+ memcpy(hostname, url + 7, hostname_end - url - 7);
+ hostname[hostname_end - url - 7] = '\0';
+ return get_bl_entry(hostname);
+}
+
void reload_blacklist() {
FILE *f = fopen("../conf/domains.blacklist", "r");
char line[1024];
@@ -60,3 +70,10 @@ int bl_check(char *host) {
if (e == NULL) return 0;
return e->forbidden;
}
+
+data_filter *bl_get_data_filter(char *url, int url_size) {
+ struct bl_entry *e = get_bl_entry_by_url(url, url_size);
+ if (e == NULL) return NULL;
+
+
+}
View
@@ -1,2 +1,3 @@
void reload_blacklist();
int bl_check(char *host);
+data_filter *bl_get_data_filter(char *url, int url_size);
View
No changes.
View
@@ -0,0 +1,9 @@
+struct list_element {
+ struct list_element *prev;
+ struct list_element *next;
+}
+
+struct list {
+ struct list_element *first;
+ struct list_element *last;
+}
View
@@ -88,6 +88,8 @@ struct http_agent {
struct client_fd_watcher *client;
struct http_header *response_headers;
+ data_filter data_filter;
+ char ungzip_needed;
struct http_agent *prev, *next;
char is_free; // 0 or 1
@@ -288,6 +290,21 @@ int on_server_headers_complete(http_parser *p) {
char *status_str;
int status_len = asprintf(&status_str, "%i", p->status_code);
+ a->data_filter = bl_get_data_filter(a->client->url, a->client->url_size);
+ if (a->data_filter != NULL) {
+ struct http_header *h = a->response_headers;
+ while (h != NULL) {
+ if (strcasecmp(h->key, "Content-Type") == 0 && strncasecmp(h->value, "text/", 5) == 0) {
+ goto preserve_filter;
+ }
+ h = h->next;
+ }
+ a->data_filter = NULL;
+preserve_filter:
+ }
+
+
+ a->ungzip_needed = 0;
int len = 0;
len += 8 + 1 + status_len + 1 + 7/*PROXIED*/ + 2;
{
@@ -296,16 +313,24 @@ int on_server_headers_complete(http_parser *p) {
while (h != NULL) {
printd("SAVED RES HEADER: <<< %s: %s >>>\n", h->key, h->value);
if (strcasecmp(h->key, "Content-Length") == 0 || strcasecmp(h->key, "Transfer-Encoding") == 0) {
- free(h->key);
- free(h->value);
- *origin = h->next; // anchestry magic! my child shall be your child, my father,
- free(h); // so that I can go in peace.
- h = *origin;
- continue;
+ goto discard_header;
}
+ if (intercept_response == 1) {
+ if (strcasecmp(h->key, "Content-Encoding") == 0 && strcasecmp(h->value, "gzip") == 0) {
+ a->ungzip_needed = 1;
+ goto discard_header;
+ }
+ }
len += strlen(h->key) + 2 + strlen(h->value) + 2;
origin = &h->next;
h = h->next;
+ continue;
+discard_header: // mwahaha, unconditional-jump-protected goto target! :)
+ free(h->key);
+ free(h->value);
+ *origin = h->next; // anchestry magic! my child shall be your child, my father,
+ free(h); // so that I can go in peace.
+ h = *origin;
}
headers_append_key(&a->response_headers, "Transfer-Encoding", 17);
@@ -345,6 +370,13 @@ int on_server_body(http_parser *p, const char *data, size_t size) {
char *d = (char *) data; /* WARNING: Here, we promise not to touch *d before changing d! */
+ if (a->ungzip_needed) {
+ YADA
+ }
+ if (a->data_filter) {
+ YADA
+ }
+
assert(size != 0);
chunkify(&d, &size, 0);

0 comments on commit b0fd8f0

Please sign in to comment.