links

lynx-like text mode web browser
git clone anongit@rnpnr.xyz:links.git
Log | Files | Refs | Feed | README | LICENSE

Commit: 77a1c887e719ce131aef771aa9eb1a4501071f8b
Parent: 04769c72a60b43adb43943236396b705c57e6a05
Author: opask
Date:   Mon,  6 Aug 2018 18:40:45 -0600

remove unused code and style cleanup in sched.c

Diffstat:
Msched.c | 507+++++++++++++++++++++++++++++++++++++++----------------------------------------
1 file changed, 251 insertions(+), 256 deletions(-)

diff --git a/sched.c b/sched.c @@ -29,11 +29,6 @@ struct list_head keepalive_connections = {&keepalive_connections, &keepalive_con static void send_connection_info(struct connection *c); static void del_keepalive_socket(struct k_conn *kc); static void check_keepalive_connections(void); -#ifdef DEBUG -static void check_queue_bugs(void); -#else -#define check_queue_bugs() do { } while (0) -#endif unsigned long connect_info(int type) { @@ -41,19 +36,21 @@ unsigned long connect_info(int type) struct connection *ce; struct list_head *lce; switch (type) { - case CI_FILES: - return list_size(&queue); - case CI_CONNECTING: - foreach(struct connection, ce, lce, queue) i += ce->state > S_WAIT && ce->state < S_TRANS; - return i; - case CI_TRANSFER: - foreach(struct connection, ce, lce, queue) i += ce->state == S_TRANS; - return i; - case CI_KEEP: - check_keepalive_connections(); - return list_size(&keepalive_connections); - default: - internal("connect_info: bad request"); + case CI_FILES: + return list_size(&queue); + case CI_CONNECTING: + foreach(struct connection, ce, lce, queue) + i += ce->state > S_WAIT && ce->state < S_TRANS; + return i; + case CI_TRANSFER: + foreach(struct connection, ce, lce, queue) + i += ce->state == S_TRANS; + return i; + case CI_KEEP: + check_keepalive_connections(); + return list_size(&keepalive_connections); + default: + internal("connect_info: bad request"); } return 0; } @@ -61,7 +58,9 @@ unsigned long connect_info(int type) static int getpri(struct connection *c) { int i; - for (i = 0; i < N_PRI; i++) if (c->pri[i]) return i; + for (i = 0; i < N_PRI; i++) + if (c->pri[i]) + return i; internal("connection has no owner"); return N_PRI; } @@ -76,14 +75,16 @@ static int connection_disappeared(struct connection *c, tcount count) static struct h_conn *is_host_on_list(struct connection *c) { - unsigned char *ho; + char *ho = (char *)get_host_name(c->url); struct h_conn *h; struct list_head *lh; - if (!(ho = get_host_name(c->url))) return NULL; - foreach(struct h_conn, h, lh, h_conns) if (!strcmp(cast_const_char h->host, cast_const_char ho)) { - free(ho); - return h; - } + if (!ho) + return NULL; + foreach(struct h_conn, h, lh, h_conns) + if (!strcmp((const char *)h->host, ho)) { + free(ho); + return h; + } free(ho); return NULL; } @@ -98,7 +99,10 @@ static void stat_timer(void *c_) uttime a = now - r->last_time; if (a > SPD_DISP_TIME * 100) a = SPD_DISP_TIME * 100; - if (getpri(c) == PRI_CANCEL && (c->est_length > (longlong)memory_cache_size * MAX_CACHED_OBJECT || c->from > (longlong)memory_cache_size * MAX_CACHED_OBJECT)) register_bottom_half(check_queue, NULL); + if (getpri(c) == PRI_CANCEL + && (c->est_length > (long)memory_cache_size * MAX_CACHED_OBJECT + || c->from > (long)memory_cache_size * MAX_CACHED_OBJECT)) + register_bottom_half(check_queue, NULL); if (c->state > S_WAIT) { r->loaded = c->received; if ((r->size = c->est_length) < (r->pos = c->from) && r->size != -1) @@ -117,17 +121,19 @@ static void stat_timer(void *c_) } r->last_time = now; r->timer = install_timer(SPD_DISP_TIME, stat_timer, c); - if (!st_r) send_connection_info(c); + if (!st_r) + send_connection_info(c); } void setcstate(struct connection *c, int state) { struct status *stat; struct list_head *lstat; - if (c->state < 0 && state >= 0) c->prev_error = c->state; + if (c->state < 0 && state >= 0) + c->prev_error = c->state; if ((c->state = state) == S_TRANS) { struct remaining_info *r = &c->prg; - if (r->timer == NULL) { + if (!r->timer) { tcount count = c->count; if (!r->valid) { memset(r, 0, sizeof(struct remaining_info)); @@ -142,7 +148,7 @@ void setcstate(struct connection *c, int state) } } else { struct remaining_info *r = &c->prg; - if (r->timer != NULL) { + if (r->timer) { kill_timer(r->timer); r->timer = NULL; } @@ -151,21 +157,24 @@ void setcstate(struct connection *c, int state) stat->state = state; stat->prev_error = c->prev_error; } - if (state >= 0) send_connection_info(c); + if (state >= 0) + send_connection_info(c); } static struct k_conn *is_host_on_keepalive_list(struct connection *c) { - unsigned char *ho; - int po; + char *ho = (char *)get_keepalive_id(c->url); + const int po = get_port(c->url); void (*ph)(struct connection *); struct k_conn *h; struct list_head *lh; - if ((po = get_port(c->url)) == -1) return NULL; - if (!(ph = get_protocol_handle(c->url))) return NULL; - if (!(ho = get_keepalive_id(c->url))) return NULL; + if (!(ph = get_protocol_handle(c->url))) + return NULL; + if (!ho || po < 0) + return NULL; foreach(struct k_conn, h, lh, keepalive_connections) - if (h->protocol == ph && h->port == po && !strcmp(cast_const_char h->host, cast_const_char ho)) { + if (h->protocol == ph && h->port == po + && !strcmp((char *)h->host, ho)) { free(ho); return h; } @@ -177,10 +186,13 @@ int get_keepalive_socket(struct connection *c, int *protocol_data) { struct k_conn *k; int cc; - if (c->tries > 0 || c->unrestartable) return -1; - if (!(k = is_host_on_keepalive_list(c))) return -1; + if (c->tries > 0 || c->unrestartable) + return -1; + if (!(k = is_host_on_keepalive_list(c))) + return -1; cc = k->conn; - if (protocol_data) *protocol_data = k->protocol_data; + if (protocol_data) + *protocol_data = k->protocol_data; freeSSL(c->ssl); c->ssl = k->ssl; memcpy(&c->last_lookup_state, &k->last_lookup_state, sizeof(struct lookup_state)); @@ -188,14 +200,16 @@ int get_keepalive_socket(struct connection *c, int *protocol_data) free(k->host); free(k); c->sock1 = cc; - if (max_tries == 1) c->tries = -1; + if (max_tries == 1) + c->tries = -1; return 0; } void abort_all_keepalive_connections(void) { while (!list_empty(keepalive_connections)) - del_keepalive_socket(list_struct(keepalive_connections.next, struct k_conn)); + del_keepalive_socket(list_struct(keepalive_connections.next, + struct k_conn)); check_keepalive_connections(); } @@ -203,7 +217,8 @@ static void free_connection_data(struct connection *c) { struct h_conn *h; int rs; - if (c->sock1 != -1) set_handlers(c->sock1, NULL, NULL, NULL); + if (c->sock1 != -1) + set_handlers(c->sock1, NULL, NULL, NULL); close_socket(&c->sock2); if (c->pid) { EINTRLOOP(rs, kill(c->pid, SIGINT)); @@ -211,11 +226,11 @@ static void free_connection_data(struct connection *c) EINTRLOOP(rs, kill(c->pid, SIGKILL)); c->pid = 0; } - if (!c->running) { + if (!c->running) internal("connection already suspended"); - } c->running = 0; - if (c->dnsquery) kill_dns_request(&c->dnsquery); + if (c->dnsquery) + kill_dns_request(&c->dnsquery); free(c->buffer); free(c->newconn); free(c->info); @@ -234,32 +249,15 @@ static void free_connection_data(struct connection *c) free(h->host); free(h); } - } else internal("suspending connection that is not on the list (state %d)", c->state); + } else + internal("suspending connection that is not on the list (state %d)", c->state); } } static void send_connection_info(struct connection *c) { -#if 0 - int st = c->state; - tcount count = c->count; - struct status *stat; - struct list_head *lstat; - /*debug("reporting conn info %s", c->url);*/ - foreach(struct status, stat, lstat, c->statuss) { - /*debug("status list &%p %p %p, status %p %p %p", &c->statuss, c->statuss.next, c->statuss.prev, lstat, lstat->next, lstat->prev);*/ - stat->ce = c->cache; - verify_list_entry(lstat); - lstat = lstat->next; - if (stat->end) stat->end(stat, stat->data); - if (st >= 0 && connection_disappeared(c, count)) return; - verify_list_entry(lstat); - lstat = lstat->prev; - } - /*debug("end report %s", c->url);*/ -#else if (!list_empty(c->statuss)) { - int st = c->state; + const int st = c->state; tcount count = c->count; struct list_head *lstat = c->statuss.next; while (1) { @@ -268,27 +266,28 @@ static void send_connection_info(struct connection *c) xstat->ce = c->cache; lstat = lstat->next; e = lstat == &c->statuss; - if (xstat->end) xstat->end(xstat, xstat->data); - if (e) return; - if (st >= 0 && connection_disappeared(c, count)) return; + if (xstat->end) + xstat->end(xstat, xstat->data); + if (e || (st >= 0 && connection_disappeared(c, count))) + return; } } -#endif } static void del_connection(struct connection *c) { struct cache_entry *ce = c->cache; - if (ce) ce->refcount++; + if (ce) + ce->refcount++; del_from_list(c); send_connection_info(c); - if (ce) ce->refcount--; + if (ce) + ce->refcount--; if (c->detached) { if (ce && !ce->url[0] && !is_entry_used(ce) && !ce->refcount) delete_cache_entry(ce); - } else - if (ce) - trim_cache_entry(ce); + } else if (ce) + trim_cache_entry(ce); free(c->url); free(c->prev_url); free(c); @@ -304,11 +303,11 @@ void add_keepalive_socket(struct connection *c, uttime timeout, int protocol_dat goto del; } k = xmalloc(sizeof(struct k_conn)); - if (c->netcfg_stamp != netcfg_stamp || - ssl_not_reusable(c->ssl) || - (k->port = get_port(c->url)) == -1 || - !(k->protocol = get_protocol_handle(c->url)) || - !(k->host = get_keepalive_id(c->url))) { + if (c->netcfg_stamp != netcfg_stamp + || ssl_not_reusable(c->ssl) + || (k->port = get_port(c->url)) == -1 + || !(k->protocol = get_protocol_handle(c->url)) + || !(k->host = get_keepalive_id(c->url))) { free(k); del_connection(c); goto clos; @@ -320,14 +319,12 @@ void add_keepalive_socket(struct connection *c, uttime timeout, int protocol_dat k->ssl = c->ssl; memcpy(&k->last_lookup_state, &c->last_lookup_state, sizeof(struct lookup_state)); add_to_list(keepalive_connections, k); - del: +del: del_connection(c); - check_queue_bugs(); register_bottom_half(check_queue, NULL); return; - clos: +clos: EINTRLOOP(rs, close(c->sock1)); - check_queue_bugs(); register_bottom_half(check_queue, NULL); } @@ -355,7 +352,7 @@ static void check_keepalive_connections(void) struct list_head *lkc; uttime ct = get_absolute_time(); int p = 0; - if (keepalive_timeout != NULL) { + if (keepalive_timeout) { kill_timer(keepalive_timeout); keepalive_timeout = NULL; } @@ -391,14 +388,16 @@ static void sort_queue(void) int swp; do { swp = 0; - foreach(struct connection, c, lc, queue) if (c->list_entry.next != &queue) { - n = list_struct(c->list_entry.next, struct connection); - if (getpri(n) < getpri(c)) { - del_from_list(c); - add_after_pos(n, c); - swp = 1; + foreach(struct connection, c, lc, queue) + if (c->list_entry.next != &queue) { + n = list_struct(c->list_entry.next, + struct connection); + if (getpri(n) < getpri(c)) { + del_from_list(c); + add_after_pos(n, c); + swp = 1; + } } - } } while (swp); } @@ -422,13 +421,17 @@ static int try_to_suspend_connection(struct connection *c, unsigned char *ho) struct connection *d; struct list_head *ld; foreachback(struct connection, d, ld, queue) { - if (getpri(d) <= pri) return -1; - if (d->state == S_WAIT) continue; - if (d->unrestartable == 2 && getpri(d) < PRI_CANCEL) continue; + if (getpri(d) <= pri) + return -1; + if (d->state == S_WAIT) + continue; + if (d->unrestartable == 2 && getpri(d) < PRI_CANCEL) + continue; if (ho) { unsigned char *h; - if (!(h = get_host_name(d->url))) continue; - if (strcmp(cast_const_char h, cast_const_char ho)) { + if (!(h = get_host_name(d->url))) + continue; + if (strcmp((const char *)h, (const char *)ho)) { free(h); continue; } @@ -481,11 +484,15 @@ static void run_connection(struct connection *c) c->socks_proxy[0] = 0; c->dns_append[0] = 0; } else { - safe_strncpy(c->socks_proxy, proxies.socks_proxy, sizeof c->socks_proxy); - safe_strncpy(c->dns_append, proxies.dns_append, sizeof c->dns_append); + safe_strncpy(c->socks_proxy, proxies.socks_proxy, + sizeof(c->socks_proxy)); + safe_strncpy(c->dns_append, proxies.dns_append, + sizeof(c->dns_append)); } - if (proxies.only_proxies && !is_proxy_url(c->url) && casecmp(c->url, cast_uchar "data:", 5) && (!*c->socks_proxy || url_bypasses_socks(c->url))) { + if (proxies.only_proxies && !is_proxy_url(c->url) + && casecmp(c->url, cast_uchar "data:", 5) + && (!*c->socks_proxy || url_bypasses_socks(c->url))) { setcstate(c, S_NO_PROXY); del_connection(c); return; @@ -493,8 +500,10 @@ static void run_connection(struct connection *c) if (!(func = get_protocol_handle(c->url))) { s_bad_url: - if (is_proxy_url(c->url)) setcstate(c, S_BAD_PROXY); - else setcstate(c, S_BAD_URL); + if (is_proxy_url(c->url)) + setcstate(c, S_BAD_PROXY); + else + setcstate(c, S_BAD_URL); del_connection(c); return; } @@ -516,9 +525,9 @@ static void run_connection(struct connection *c) static int is_connection_seekable(struct connection *c) { unsigned char *protocol = get_protocol_name(c->url); - if (!casestrcmp(protocol, cast_uchar "http") || - !casestrcmp(protocol, cast_uchar "https") || - !casestrcmp(protocol, cast_uchar "proxy")) { + if (!casestrcmp(protocol, cast_uchar "http") + || !casestrcmp(protocol, cast_uchar "https") + || !casestrcmp(protocol, cast_uchar "proxy")) { unsigned char *d; free(protocol); if (!c->cache || !c->cache->head) @@ -557,7 +566,6 @@ void retry_connection(struct connection *c) interrupt_connection(c); if (!is_connection_restartable(c)) { del_connection(c); - check_queue_bugs(); register_bottom_half(check_queue, NULL); } else { c->tries++; @@ -568,9 +576,9 @@ void retry_connection(struct connection *c) void abort_connection(struct connection *c) { - if (c->running) interrupt_connection(c); + if (c->running) + interrupt_connection(c); del_connection(c); - check_queue_bugs(); register_bottom_half(check_queue, NULL); } @@ -579,65 +587,32 @@ static int try_connection(struct connection *c) struct h_conn *hc = NULL; if ((hc = is_host_on_list(c))) { if (hc->conn >= max_connections_to_host) { - if (try_to_suspend_connection(c, hc->host)) return 0; - else return -1; + if (try_to_suspend_connection(c, hc->host)) + return 0; + else + return -1; } } if (active_connections >= max_connections) { - if (try_to_suspend_connection(c, NULL)) return 0; - else return -1; + if (try_to_suspend_connection(c, NULL)) + return 0; + else + return -1; } run_connection(c); return 1; } -#ifdef DEBUG -static void check_queue_bugs(void) -{ - struct connection *d; - struct list_head *ld; - int p = 0, ps = 0; - int cc; - again: - cc = 0; - foreach(struct connection, d, ld, queue) { - int q = getpri(d); - cc += d->running; - if (q < p) { - if (!ps) { - internal("queue is not sorted"); - sort_queue(); - ps = 1; - goto again; - } else { - internal("queue is not sorted even after sort_queue!"); - break; - } - } else p = q; - if (d->state < 0) { - internal("interrupted connection on queue (conn %s, state %d)", d->url, d->state); - ld = ld->prev; - abort_connection(d); - } - } - if (cc != active_connections) { - internal("bad number of active connections (counted %d, stored %d)", cc, active_connections); - active_connections = cc; - } -} -#endif - void check_queue(void *dummy) { struct connection *c; struct list_head *lc; - again: - check_queue_bugs(); +again: check_keepalive_connections(); foreach(struct connection, c, lc, queue) { struct connection *d; struct list_head *ld; - int cp = getpri(c); + const int cp = getpri(c); foreachfrom(struct connection, d, ld, queue, &c->list_entry) { if (getpri(d) != cp) break; @@ -654,29 +629,33 @@ void check_queue(void *dummy) } lc = ld->prev; } - again2: +again2: foreachback(struct connection, c, lc, queue) { - if (getpri(c) < PRI_CANCEL) break; + if (getpri(c) < PRI_CANCEL) + break; if (c->state == S_WAIT) { setcstate(c, S_INTERRUPTED); del_connection(c); goto again2; - } else if (c->est_length > (longlong)memory_cache_size * MAX_CACHED_OBJECT || c->from > (longlong)memory_cache_size * MAX_CACHED_OBJECT) { + } else if (c->est_length > (long)memory_cache_size * MAX_CACHED_OBJECT + || c->from > (long)memory_cache_size * MAX_CACHED_OBJECT) { setcstate(c, S_INTERRUPTED); abort_connection(c); goto again2; } } - check_queue_bugs(); } unsigned char *get_proxy_string(unsigned char *url) { if (is_noproxy_url(url)) return NULL; - if (*proxies.http_proxy && !casecmp(url, cast_uchar "http://", 7)) return proxies.http_proxy; - if (*proxies.ftp_proxy && !casecmp(url, cast_uchar "ftp://", 6)) return proxies.ftp_proxy; - if (*proxies.https_proxy && !casecmp(url, cast_uchar "https://", 8)) return proxies.https_proxy; + if (*proxies.http_proxy && !casecmp(url, cast_uchar "http://", 7)) + return proxies.http_proxy; + if (*proxies.ftp_proxy && !casecmp(url, cast_uchar "ftp://", 6)) + return proxies.ftp_proxy; + if (*proxies.https_proxy && !casecmp(url, cast_uchar "https://", 8)) + return proxies.https_proxy; return NULL; } @@ -717,25 +696,26 @@ int get_allow_flags(unsigned char *url) int disallow_url(unsigned char *url, int allow_flags) { - if (!casecmp(url, cast_uchar "smb://", 6) && !(allow_flags & ALLOW_SMB) && !smb_options.allow_hyperlinks_to_smb) { + if (!casecmp(url, cast_uchar "smb://", 6) && !(allow_flags & ALLOW_SMB) + && !smb_options.allow_hyperlinks_to_smb) return S_SMB_NOT_ALLOWED; - } - if (!casecmp(url, cast_uchar "file://", 7) && !(allow_flags & ALLOW_FILE)) { + if (!casecmp(url, cast_uchar "file://", 7) + && !(allow_flags & ALLOW_FILE)) return S_FILE_NOT_ALLOWED; - } return 0; } /* prev_url is a pointer to previous url or NULL */ /* prev_url will NOT be deallocated */ -void load_url(unsigned char *url, unsigned char *prev_url, struct status *stat, int pri, int no_cache, int no_compress, int allow_flags, off_t position) +void load_url(unsigned char *url, unsigned char *prev_url, struct status *stat, + int pri, int no_cache, int no_compress, int allow_flags, off_t position) { struct cache_entry *e = NULL; struct connection *c; struct list_head *lc; unsigned char *u; int must_detach = 0; - int err; + const int err = disallow_url(url, allow_flags); if (stat) { stat->c = NULL; @@ -744,28 +724,14 @@ void load_url(unsigned char *url, unsigned char *prev_url, struct status *stat, stat->prev_error = 0; stat->pri = pri; } -#ifdef DEBUG - foreach(struct connection, c, lc, queue) { - struct status *st; - struct list_head *lst; - foreach(struct status, st, lst, c->statuss) { - if (st == stat) { - internal("status already assigned to '%s'", c->url); - stat->state = S_INTERNAL; - if (stat->end) stat->end(stat, stat->data); - goto ret; - } - } - } -#endif if (is_url_blocked(url)) { if (stat) { stat->state = S_BLOCKED_URL; - if (stat->end) stat->end(stat, stat->data); + if (stat->end) + stat->end(stat, stat->data); } goto ret; } - err = disallow_url(url, allow_flags); if (err) { if (stat) { stat->state = err; @@ -780,14 +746,16 @@ void load_url(unsigned char *url, unsigned char *prev_url, struct status *stat, } if (!aggressive_cache && no_cache > NC_ALWAYS_CACHE) { if (e->expire_time && e->expire_time < time(NULL)) { - if (no_cache < NC_IF_MOD) no_cache = NC_IF_MOD; + if (no_cache < NC_IF_MOD) + no_cache = NC_IF_MOD; e->refcount--; goto skip_cache; } } if (no_compress) { unsigned char *enc; - enc = parse_http_header(e->head, cast_uchar "Content-Encoding", NULL); + enc = parse_http_header(e->head, + cast_uchar "Content-Encoding", NULL); if (enc) { free(enc); e->refcount--; @@ -798,63 +766,70 @@ void load_url(unsigned char *url, unsigned char *prev_url, struct status *stat, if (stat) { stat->ce = e; stat->state = S__OK; - if (stat->end) stat->end(stat, stat->data); + if (stat->end) + stat->end(stat, stat->data); } e->refcount--; goto ret; } - skip_cache: +skip_cache: if (is_proxy_url(url)) { if (stat) { stat->state = S_BAD_URL; - if (stat->end) stat->end(stat, stat->data); + if (stat->end) + stat->end(stat, stat->data); } goto ret; } u = get_proxy(url); - foreach(struct connection, c, lc, queue) if (!c->detached && !strcmp(cast_const_char c->url, cast_const_char u)) { - if (c->from < position) continue; - if (no_compress && !c->no_compress) { - unsigned char *enc; - if ((c->state >= S_WAIT && c->state < S_TRANS) || !c->cache) { - must_detach = 1; - break; + foreach(struct connection, c, lc, queue) + if (!c->detached && !strcmp((const char *)c->url, (const char *)u)) { + if (c->from < position) + continue; + if (no_compress && !c->no_compress) { + unsigned char *enc; + if ((c->state >= S_WAIT && c->state < S_TRANS) + || !c->cache) { + must_detach = 1; + break; + } + enc = parse_http_header(c->cache->head, + cast_uchar "Content-Encoding", + NULL); + if (enc) { + free(enc); + must_detach = 1; + break; + } } - enc = parse_http_header(c->cache->head, cast_uchar "Content-Encoding", NULL); - if (enc) { - free(enc); - must_detach = 1; - break; + free(u); + if (getpri(c) > pri) { + del_from_list(c); + c->pri[pri]++; + add_to_queue(c); + register_bottom_half(check_queue, NULL); + } else + c->pri[pri]++; + if (stat) { + stat->prg = &c->prg; + stat->c = c; + stat->ce = c->cache; + add_to_list(c->statuss, stat); + setcstate(c, c->state); } + goto ret; } - free(u); - if (getpri(c) > pri) { - del_from_list(c); - c->pri[pri]++; - add_to_queue(c); - register_bottom_half(check_queue, NULL); - } else c->pri[pri]++; - if (stat) { - stat->prg = &c->prg; - stat->c = c; - stat->ce = c->cache; - add_to_list(c->statuss, stat); - setcstate(c, c->state); - } - check_queue_bugs(); - goto ret; - } c = mem_calloc(sizeof(struct connection)); c->count = connection_count++; c->url = u; c->prev_url = stracpy(prev_url); c->running = 0; c->prev_error = 0; - if (position || must_detach) { + if (position || must_detach) c->from = position; - } else if (no_cache >= NC_IF_MOD || !e) { + else if (no_cache >= NC_IF_MOD || !e) c->from = 0; - } else { + else { struct fragment *frag; struct list_head *lfrag; c->from = 0; @@ -888,7 +863,8 @@ void load_url(unsigned char *url, unsigned char *prev_url, struct status *stat, free(c); if (stat) { stat->state = S_OUT_OF_MEM; - if (stat->end) stat->end(stat, stat->data); + if (stat->end) + stat->end(stat, stat->data); } goto ret; } @@ -904,7 +880,6 @@ void load_url(unsigned char *url, unsigned char *prev_url, struct status *stat, } add_to_queue(c); setcstate(c, S_WAIT); - check_queue_bugs(); register_bottom_half(check_queue, NULL); ret: @@ -914,21 +889,22 @@ ret: void change_connection(struct status *oldstat, struct status *newstat, int newpri) { struct connection *c; - int oldpri; - oldpri = oldstat->pri; + const int oldpri = oldstat->pri; if (oldstat->state < 0) { if (newstat) { struct cache_entry *ce = oldstat->ce; - if (ce) ce->refcount++; + if (ce) + ce->refcount++; newstat->ce = oldstat->ce; newstat->state = oldstat->state; newstat->prev_error = oldstat->prev_error; - if (newstat->end) newstat->end(newstat, newstat->data); - if (ce) ce->refcount--; + if (newstat->end) + newstat->end(newstat, newstat->data); + if (ce) + ce->refcount--; } return; } - check_queue_bugs(); c = oldstat->c; if (--c->pri[oldpri] < 0) { internal("priority counter underflow"); @@ -951,7 +927,6 @@ void change_connection(struct status *oldstat, struct status *newstat, int newpr abort_connection(c); } sort_queue(); - check_queue_bugs(); register_bottom_half(check_queue, NULL); } @@ -960,31 +935,44 @@ void detach_connection(struct status *stat, off_t pos, int want_to_restart, int struct connection *c; int i, n_users; off_t l; - if (stat->state < 0) return; + if (stat->state < 0) + return; c = stat->c; - if (c->no_compress && want_to_restart) return; - if (!c->cache || (!dont_check_refcount && c->cache->refcount)) return; + if (c->no_compress && want_to_restart) + return; + if (!c->cache || (!dont_check_refcount && c->cache->refcount)) + return; want_to_restart |= pos > c->from && is_connection_seekable(c); - if (c->detached) goto detach_done; - if (c->est_length == -1) l = c->from; - else l = c->est_length; - if (!dont_check_refcount && l < (longlong)memory_cache_size * MAX_CACHED_OBJECT && !want_to_restart) return; + if (c->detached) + goto detach_done; + if (c->est_length == -1) + l = c->from; + else + l = c->est_length; + if (!dont_check_refcount + && l < (long)memory_cache_size * MAX_CACHED_OBJECT && !want_to_restart) + return; n_users = 0; - for (i = 0; i < PRI_CANCEL; i++) n_users += c->pri[i]; - if (!n_users) internal("detaching free connection"); - if (n_users != 1) return; + for (i = 0; i < PRI_CANCEL; i++) + n_users += c->pri[i]; + if (!n_users) + internal("detaching free connection"); + if (n_users != 1) + return; shrink_memory(SH_CHECK_QUOTA); detach_cache_entry(c->cache); c->detached = 1; - detach_done: +detach_done: free_entry_to(c->cache, pos); if (c->detached < 2 && want_to_restart) { int running = c->running; c->no_compress = 1; - if (running) interrupt_connection(c); + if (running) + interrupt_connection(c); c->from = pos; - if (running) run_connection(c); + if (running) + run_connection(c); c->detached = 2; } } @@ -1022,7 +1010,7 @@ static void connection_timeout_1(void *c_) void clear_connection_timeout(struct connection *c) { - if (c->timer != NULL) { + if (c->timer) { kill_timer(c->timer); c->timer = NULL; } @@ -1063,7 +1051,9 @@ int is_entry_used(struct cache_entry *e) { struct connection *c; struct list_head *lc; - foreach(struct connection, c, lc, queue) if (c->cache == e) return 1; + foreach(struct connection, c, lc, queue) + if (c->cache == e) + return 1; return 0; } @@ -1081,15 +1071,17 @@ void add_blacklist_entry(unsigned char *host, int flags) struct blacklist_entry *b; struct list_head *lb; size_t sl; - foreach(struct blacklist_entry, b, lb, blacklist) if (!casestrcmp(host, b->host)) { - b->flags |= flags; - return; - } - sl = strlen(cast_const_char host); - if (sl > MAXINT - sizeof(struct blacklist_entry)) overalloc(); + foreach(struct blacklist_entry, b, lb, blacklist) + if (!casestrcmp(host, b->host)) { + b->flags |= flags; + return; + } + sl = strlen((const char *)host); + if (sl > MAXINT - sizeof(struct blacklist_entry)) + overalloc(); b = xmalloc(sizeof(struct blacklist_entry) + sl); b->flags = flags; - strcpy(cast_char b->host, cast_const_char host); + strcpy((char *)b->host, (const char *)host); add_to_list(blacklist, b); } @@ -1097,21 +1089,24 @@ void del_blacklist_entry(unsigned char *host, int flags) { struct blacklist_entry *b; struct list_head *lb; - foreach(struct blacklist_entry, b, lb, blacklist) if (!casestrcmp(host, b->host)) { - b->flags &= ~flags; - if (!b->flags) { - del_from_list(b); - free(b); + foreach(struct blacklist_entry, b, lb, blacklist) + if (!casestrcmp(host, b->host)) { + b->flags &= ~flags; + if (!b->flags) { + del_from_list(b); + free(b); + } + return; } - return; - } } int get_blacklist_flags(unsigned char *host) { struct blacklist_entry *b; struct list_head *lb; - foreach(struct blacklist_entry, b, lb, blacklist) if (!casestrcmp(host, b->host)) return b->flags; + foreach(struct blacklist_entry, b, lb, blacklist) + if (!casestrcmp(host, b->host)) + return b->flags; return 0; }