Commit: d2f52a49d8eaf3fb8ba0e8a642668185125b21ae
Parent: e816017ce2abd955b933a47a480ed5f09140eadc
Author: opask
Date: Fri, 27 Jul 2018 18:14:14 -0600
remove unused functions in error.c, style cleanup
Diffstat:
M | bfu.c | | | 60 | +++++++++++++++++++++++++++++++++++++++++------------------- |
M | charsets.c | | | 77 | ++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------- |
M | cookies.c | | | 161 | ++++++++++++++++++++++++++++++++++++++++++++++--------------------------------- |
M | dns.c | | | 159 | ++++++++++++++++++++++++++++++++++++++++++++----------------------------------- |
M | error.c | | | 31 | +++++-------------------------- |
M | links.h | | | 3 | --- |
M | objreq.c | | | 6 | ++++-- |
7 files changed, 284 insertions(+), 213 deletions(-)
diff --git a/bfu.c b/bfu.c
@@ -16,17 +16,23 @@ struct memory_list *getml(void *p, ...)
void *q = p;
va_start(ap, p);
while (q) {
- if (n == MAXINT) overalloc();
- n++, q = va_arg(ap, void *);
+ if (n == MAXINT)
+ overalloc();
+ n++;
+ q = va_arg(ap, void *);
}
- if ((unsigned)n > (MAXINT - sizeof(struct memory_list)) / sizeof(void *)) overalloc();
+ if ((unsigned)n > (MAXINT - sizeof(struct memory_list)) / sizeof(void *))
+ overalloc();
ml = xmalloc(sizeof(struct memory_list) + n * sizeof(void *));
ml->n = n;
n = 0;
q = p;
va_end(ap);
va_start(ap, p);
- while (q) ml->p[n++] = q, q = va_arg(ap, void *);
+ while (q) {
+ ml->p[n++] = q;
+ q = va_arg(ap, void *);
+ }
va_end(ap);
return ml;
}
@@ -43,7 +49,8 @@ void add_to_ml(struct memory_list **ml, ...)
}
va_start(ap, ml);
while ((q = va_arg(ap, void *))) {
- if (n == MAXINT) overalloc();
+ if (n == MAXINT)
+ overalloc();
n++;
}
if ((unsigned)n + (unsigned)((*ml)->n) > (MAXINT - sizeof(struct memory_list)) / sizeof(void *))
@@ -69,9 +76,11 @@ void freeml(struct memory_list *ml)
static inline int is_utf_8(struct terminal *term)
{
#ifdef G
- if (F) return 1;
+ if (F)
+ return 1;
#endif
- if (term_charset(term) == utf8_table) return 1;
+ if (term_charset(term) == utf8_table)
+ return 1;
return 0;
}
@@ -117,7 +126,8 @@ void init_bfu(void)
void shutdown_bfu(void)
{
- if (!F) return;
+ if (!F)
+ return;
g_free_style(bfu_style_wb);
g_free_style(bfu_style_wb_b);
g_free_style(bfu_style_bw);
@@ -139,7 +149,8 @@ unsigned char m_bar = 0;
static unsigned select_hotkey(struct terminal *term, unsigned char *text, unsigned char *hotkey, unsigned *hotkeys, int n)
{
unsigned c;
- if (hotkey == M_BAR) return 0;
+ if (hotkey == M_BAR)
+ return 0;
if (text) {
text = stracpy(get_text_translation(text, term));
charset_upcase_string(&text, term_charset(term));
@@ -148,11 +159,14 @@ static unsigned select_hotkey(struct terminal *term, unsigned char *text, unsign
while (1) {
int i;
c = GET_TERM_CHAR(term, &hotkey);
- if (!c) break;
+ if (!c)
+ break;
c = charset_upcase(c, term_charset(term));
- for (i = 0; i < n; i++) if (hotkeys[i] == c) goto cont;
- if (!text || cp_strchr(term_charset(term), text, c)) break;
- cont:;
+ for (i = 0; i < n; i++)
+ if (hotkeys[i] == c)
+ continue;
+ if (!text || cp_strchr(term_charset(term), text, c))
+ break;
}
free(text);
return c;
@@ -162,7 +176,9 @@ void do_menu_selected(struct terminal *term, struct menu_item *items, void *data
{
int i;
struct menu *menu;
- for (i = 0; items[i].text; i++) if (i == (MAXINT - sizeof(struct menu)) / sizeof(unsigned)) overalloc();
+ for (i = 0; items[i].text; i++)
+ if (i == (MAXINT - sizeof(struct menu)) / sizeof(unsigned))
+ overalloc();
menu = xmalloc(sizeof(struct menu) + (!i ? 0 : i - 1) * sizeof(unsigned));
menu->selected = selected;
menu->view = 0;
@@ -172,10 +188,13 @@ void do_menu_selected(struct terminal *term, struct menu_item *items, void *data
menu->free_function = free_function;
menu->free_data = free_data;
for (i = 0; i < menu->ni; i++)
- menu->hotkeys[i] = select_hotkey(term, !term->spec->braille ? items[i].text : NULL, items[i].hotkey, menu->hotkeys, i);
+ menu->hotkeys[i] = select_hotkey(term,
+ !term->spec->braille ? items[i].text : NULL,
+ items[i].hotkey, menu->hotkeys, i);
#ifdef G
if (F) {
- if ((unsigned)menu->ni > MAXINT / sizeof(unsigned char *)) overalloc();
+ if ((unsigned)menu->ni > MAXINT / sizeof(unsigned char *))
+ overalloc();
menu->hktxt1 = mem_calloc(menu->ni * sizeof(unsigned char *));
menu->hktxt2 = mem_calloc(menu->ni * sizeof(unsigned char *));
menu->hktxt3 = mem_calloc(menu->ni * sizeof(unsigned char *));
@@ -215,12 +234,14 @@ static void select_menu(struct terminal *term, struct menu *menu)
void (*func)(struct terminal *, void *, void *);
void *data1;
void *data2;
- if (menu->selected < 0 || menu->selected >= menu->ni) return;
+ if (menu->selected < 0 || menu->selected >= menu->ni)
+ return;
it = &menu->items[menu->selected];
func = it->func;
data1 = it->data;
data2 = menu->data;
- if (it->hotkey == M_BAR) return;
+ if (it->hotkey == M_BAR)
+ return;
flush_terminal(term);
if (!it->in_m) {
struct window *win;
@@ -237,7 +258,8 @@ static void select_menu(struct terminal *term, struct menu *menu)
static unsigned char *get_rtext(unsigned char *rtext)
{
- if (!strcmp(cast_const_char rtext, ">")) return MENU_SUBMENU;
+ if (!strcmp(cast_const_char rtext, ">"))
+ return MENU_SUBMENU;
return rtext;
}
diff --git a/charsets.c b/charsets.c
@@ -62,7 +62,9 @@ static_const unsigned char strings[256][2] = {
static void free_translation_table(struct conv_table *p)
{
int i;
- for (i = 0; i < 256; i++) if (p[i].t) free_translation_table(p[i].u.tbl);
+ for (i = 0; i < 256; i++)
+ if (p[i].t)
+ free_translation_table(p[i].u.tbl);
free(p);
}
@@ -71,9 +73,17 @@ static_const unsigned char no_str[] = "*";
static void new_translation_table(struct conv_table *p)
{
int i;
- for (i = 0; i < 256; i++) if (p[i].t) free_translation_table(p[i].u.tbl);
- for (i = 0; i < 128; i++) p[i].t = 0, p[i].u.str = cast_uchar strings[i];
- for (; i < 256; i++) p[i].t = 0, p[i].u.str = cast_uchar no_str;
+ for (i = 0; i < 256; i++)
+ if (p[i].t)
+ free_translation_table(p[i].u.tbl);
+ for (i = 0; i < 128; i++) {
+ p[i].t = 0;
+ p[i].u.str = cast_uchar strings[i];
+ }
+ for (; i < 256; i++) {
+ p[i].t = 0;
+ p[i].u.str = cast_uchar no_str;
+ }
}
static_const unsigned short strange_chars[32] = {
@@ -95,31 +105,43 @@ unsigned char *u2cp(int u, int to, int fallback)
{
int j, s;
again:
- if (u < 0) return cast_uchar "";
- if (u < 128) return cast_uchar strings[u];
- if (is_nbsp(u)) return cast_uchar strings[1];
- if (u == 0xad) return cast_uchar strings[0];
- if (to == utf8_table) return encode_utf_8(u);
+ if (u < 0)
+ return cast_uchar "";
+ if (u < 128)
+ return cast_uchar strings[u];
+ if (is_nbsp(u))
+ return cast_uchar strings[1];
+ if (u == 0xad)
+ return cast_uchar strings[0];
+ if (to == utf8_table)
+ return encode_utf_8(u);
if (u < 0xa0) {
u = strange_chars[u - 0x80];
- if (!u) return NULL;
+ if (!u)
+ return NULL;
goto again;
}
for (j = 0; codepages[to].table[j].c; j++)
if (codepages[to].table[j].u == u)
return cast_uchar strings[codepages[to].table[j].c];
- if (!fallback) return NULL;
+ if (!fallback)
+ return NULL;
BIN_SEARCH(N_UNICODE_7B, U_EQUAL, U_ABOVE, u, s);
- if (s != -1) return cast_uchar unicode_7b[s].s;
+ if (s != -1)
+ return cast_uchar unicode_7b[s].s;
return NULL;
}
int cp2u(unsigned ch, int from)
{
const struct table_entry *e;
- if (from == utf8_table) return ch;
- if (from < 0 || ch < 0x80) return ch;
- for (e = codepages[from].table; e->c; e++) if (e->c == ch) return e->u;
+ if (from == utf8_table)
+ return ch;
+ if (from < 0 || ch < 0x80)
+ return ch;
+ for (e = codepages[from].table; e->c; e++)
+ if (e->c == ch)
+ return e->u;
return -1;
}
@@ -128,8 +150,9 @@ static unsigned char utf_buffer[7];
unsigned char *encode_utf_8(int u)
{
memset(utf_buffer, 0, 7);
- if (u < 0) ;
- else if (u < 0x80) utf_buffer[0] = (unsigned char)u;
+ if (u < 0);
+ else if (u < 0x80)
+ utf_buffer[0] = (unsigned char)u;
else if (u < 0x800)
utf_buffer[0] = 0xc0 | ((u >> 6) & 0x1f),
utf_buffer[1] = 0x80 | (u & 0x3f);
@@ -161,7 +184,8 @@ static void add_utf_8(struct conv_table *ct, int u, unsigned char *str)
{
unsigned char *p = encode_utf_8(u);
while (p[1]) {
- if (ct[*p].t) ct = ct[*p].u.tbl;
+ if (ct[*p].t)
+ ct = ct[*p].u.tbl;
else {
struct conv_table *nct;
if (ct[*p].u.str != no_str) {
@@ -181,7 +205,8 @@ static void add_utf_8(struct conv_table *ct, int u, unsigned char *str)
internal("bad utf encoding #2");
return;
}
- if (ct[*p].u.str == no_str) ct[*p].u.str = str;
+ if (ct[*p].u.str == no_str)
+ ct[*p].u.str = str;
}
static struct conv_table utf_table[256];
@@ -198,23 +223,25 @@ static struct conv_table *get_translation_table_to_utf_8(int from)
{
int i;
static int lfr = -1;
- if (from == -1) return NULL;
- if (from == lfr) return utf_table;
+ if (from == -1)
+ return NULL;
+ if (from == lfr)
+ return utf_table;
lfr = from;
if (utf_table_init) {
memset(utf_table, 0, sizeof(struct conv_table) * 256);
for (i = 0; i < 128; i++) utf_table[i].u.str = cast_uchar strings[i];
utf_table_init = 0;
- } else {
+ } else
free_utf_table();
- }
if (from == utf8_table) {
for (i = 128; i < 256; i++) utf_table[i].u.str = stracpy(strings[i]);
return utf_table;
}
- for (i = 128; i < 256; i++) utf_table[i].u.str = NULL;
+ for (i = 128; i < 256; i++)
+ utf_table[i].u.str = NULL;
for (i = 0; codepages[from].table[i].c; i++) {
- int u = codepages[from].table[i].u;
+ const int u = codepages[from].table[i].u;
if (!utf_table[codepages[from].table[i].c].u.str)
utf_table[codepages[from].table[i].c].u.str = stracpy(encode_utf_8(u));
}
diff --git a/cookies.c b/cookies.c
@@ -43,18 +43,21 @@ static void accept_cookie(struct cookie *);
*/
int set_cookie(struct terminal *term, unsigned char *url, unsigned char *str)
{
+ if (!accept_cookies)
+ return 0;
int noval = 0;
struct cookie *cookie;
struct c_server *cs;
struct list_head *lcs;
unsigned char *p, *q, *s, *server, *date, *dom;
- if (accept_cookies == ACCEPT_NONE) return 0;
- for (p = str; *p != ';' && *p; p++) { /*if (WHITECHAR(*p)) return 0;*/ }
- for (q = str; *q != '='; q++) if (!*q || q >= p) {
- noval = 1;
- break;
- }
- if (str == q || q + 1 == p) return 0;
+ for (p = str; *p != ';' && *p; p++);
+ for (q = str; *q != '='; q++)
+ if (!*q || q >= p) {
+ noval = 1;
+ break;
+ }
+ if (str == q || q + 1 == p)
+ return 0;
cookie = xmalloc(sizeof(struct cookie));
server = get_host_name(url);
cookie->name = memacpy(str, q - str);
@@ -63,53 +66,53 @@ int set_cookie(struct terminal *term, unsigned char *url, unsigned char *str)
date = parse_header_param(str, cast_uchar "expires", 0);
if (date) {
cookie->expires = parse_http_date(date);
- /* kdo tohle napsal a proc ?? */
- /*if (! cookie->expires) cookie->expires++;*/ /* no harm and we can use zero then */
free(date);
- } else {
+ } else
cookie->expires = 0;
- }
- if (!(cookie->path = parse_header_param(str, cast_uchar "path", 0))) {
+ if (!(cookie->path = parse_header_param(str, cast_uchar "path", 0)))
cookie->path = stracpy(cast_uchar "/");
- } else {
- if (cookie->path[0] != '/') {
- add_to_strn(&cookie->path, cast_uchar "x");
- memmove(cookie->path + 1, cookie->path, strlen(cast_const_char cookie->path) - 1);
- cookie->path[0] = '/';
- }
+ else if (cookie->path[0] != '/') {
+ add_to_strn(&cookie->path, cast_uchar "x");
+ memmove(cookie->path + 1, cookie->path, strlen(cast_const_char cookie->path) - 1);
+ cookie->path[0] = '/';
}
dom = parse_header_param(str, cast_uchar "domain", 0);
- if (!dom) {
+ if (!dom)
cookie->domain = stracpy(server);
- } else {
+ else {
cookie->domain = idn_encode_host(dom, (int)strlen(cast_const_char dom), cast_uchar ".", 0);
if (!cookie->domain)
cookie->domain = stracpy(server);
free(dom);
}
- if (cookie->domain[0] == '.') memmove(cookie->domain, cookie->domain + 1, strlen(cast_const_char cookie->domain));
+ if (cookie->domain[0] == '.')
+ memmove(cookie->domain, cookie->domain + 1,
+ strlen(cast_const_char cookie->domain));
if ((s = parse_header_param(str, cast_uchar "secure", 0))) {
cookie->secure = 1;
free(s);
- } else cookie->secure = 0;
+ } else
+ cookie->secure = 0;
if (!allow_cookie_domain(server, cookie->domain)) {
free(cookie->domain);
cookie->domain = stracpy(server);
}
- foreach(struct c_server, cs, lcs, c_servers) if (!casestrcmp(cs->server, server)) {
- if (cs->accpt) goto ok;
- else {
- free_cookie(cookie);
- free(server);
- return 0;
+ foreach(struct c_server, cs, lcs, c_servers)
+ if (!casestrcmp(cs->server, server)) {
+ if (cs->accpt)
+ goto ok;
+ else {
+ free_cookie(cookie);
+ free(server);
+ return 0;
+ }
}
- }
- if (accept_cookies != ACCEPT_ALL) {
+ if (!accept_cookies) {
free_cookie(cookie);
free(server);
return 1;
}
- ok:
+ok:
accept_cookie(cookie);
free(server);
return 0;
@@ -122,19 +125,24 @@ static void accept_cookie(struct cookie *c)
struct cookie *d;
struct list_head *ld;
size_t sl;
- foreach(struct cookie, d, ld, all_cookies) if (!casestrcmp(d->name, c->name) && !casestrcmp(d->domain, c->domain)) {
- ld = ld->prev;
- del_from_list(d);
- free_cookie(d);
- }
+ foreach(struct cookie, d, ld, all_cookies)
+ if (!casestrcmp(d->name, c->name)
+ && !casestrcmp(d->domain, c->domain)) {
+ ld = ld->prev;
+ del_from_list(d);
+ free_cookie(d);
+ }
if (c->value && !casestrcmp(c->value, cast_uchar "deleted")) {
free_cookie(c);
return;
}
add_to_list(all_cookies, c);
- foreach(struct c_domain, cd, lcd, c_domains) if (!casestrcmp(cd->domain, c->domain)) return;
+ foreach(struct c_domain, cd, lcd, c_domains)
+ if (!casestrcmp(cd->domain, c->domain))
+ return;
sl = strlen(cast_const_char c->domain);
- if (sl > MAXINT - sizeof(struct c_domain)) overalloc();
+ if (sl > MAXINT - sizeof(struct c_domain))
+ overalloc();
cd = xmalloc(sizeof(struct c_domain) + sl);
strcpy(cast_char cd->domain, cast_const_char c->domain);
add_to_list(c_domains, cd);
@@ -142,21 +150,27 @@ static void accept_cookie(struct cookie *c)
int is_in_domain(unsigned char *d, unsigned char *s)
{
- int dl = (int)strlen(cast_const_char d);
- int sl = (int)strlen(cast_const_char s);
- if (dl > sl) return 0;
- if (dl == sl) return !casestrcmp(d, s);
- if (s[sl - dl - 1] != '.') return 0;
+ const int dl = strlen(cast_const_char d);
+ const int sl = strlen(cast_const_char s);
+ if (dl > sl)
+ return 0;
+ if (dl == sl)
+ return !casestrcmp(d, s);
+ if (s[sl - dl - 1] != '.')
+ return 0;
return !casecmp(d, s + sl - dl, dl);
}
int is_path_prefix(unsigned char *d, unsigned char *s)
{
- int dl = (int)strlen(cast_const_char d);
- int sl = (int)strlen(cast_const_char s);
- if (!dl) return 1;
- if (dl > sl) return 0;
- if (memcmp(d, s, dl)) return 0;
+ const int dl = strlen(cast_const_char d);
+ const int sl = strlen(cast_const_char s);
+ if (!dl)
+ return 1;
+ if (dl > sl)
+ return 0;
+ if (memcmp(d, s, dl))
+ return 0;
return d[dl - 1] == '/' || !s[dl] || s[dl] == '/' || s[dl] == POST_CHAR || s[dl] == '?' || s[dl] == '&';
}
@@ -177,28 +191,39 @@ void add_cookies(unsigned char **s, int *l, unsigned char *url)
struct list_head *lc;
unsigned char *server = get_host_name(url);
unsigned char *data = get_url_data(url);
- if (data > url) data--;
- foreach(struct c_domain, cd, lcd, c_domains) if (is_in_domain(cd->domain, server)) goto ok;
+ if (data > url)
+ data--;
+ foreach(struct c_domain, cd, lcd, c_domains)
+ if (is_in_domain(cd->domain, server))
+ goto ok;
free(server);
return;
- ok:
- foreachback(struct cookie, c, lc, all_cookies) if (is_in_domain(c->domain, server)) if (is_path_prefix(c->path, data)) {
- if (cookie_expired(c)) {
- lc = lc->prev;
- del_from_list(c);
- free_cookie(c);
- continue;
- }
- if (c->secure && casecmp(url, cast_uchar "https://", 8)) continue;
- if (!nc) add_to_str(s, l, cast_uchar "Cookie: "), nc = 1;
- else add_to_str(s, l, cast_uchar "; ");
- add_to_str(s, l, c->name);
- if (c->value) {
- add_to_str(s, l, cast_uchar "=");
- add_to_str(s, l, c->value);
- }
- }
- if (nc) add_to_str(s, l, cast_uchar "\r\n");
+ok:
+ foreachback(struct cookie, c, lc, all_cookies)
+ if (is_in_domain(c->domain, server))
+ if (is_path_prefix(c->path, data)) {
+ if (cookie_expired(c)) {
+ lc = lc->prev;
+ del_from_list(c);
+ free_cookie(c);
+ continue;
+ }
+ if (c->secure
+ && casecmp(url, cast_uchar "https://", 8))
+ continue;
+ if (!nc) {
+ add_to_str(s, l, cast_uchar "Cookie: ");
+ nc = 1;
+ } else
+ add_to_str(s, l, cast_uchar "; ");
+ add_to_str(s, l, c->name);
+ if (c->value) {
+ add_to_str(s, l, cast_uchar "=");
+ add_to_str(s, l, c->value);
+ }
+ }
+ if (nc)
+ add_to_str(s, l, cast_uchar "\r\n");
free(server);
}
diff --git a/dns.c b/dns.c
@@ -56,22 +56,24 @@ static int get_addr_byte(unsigned char **ptr, unsigned char *res, unsigned char
int numeric_ip_address(unsigned char *name, unsigned char address[4])
{
unsigned char dummy[4];
- if (!address) address = dummy;
- if (get_addr_byte(&name, address + 0, '.')) return -1;
- if (get_addr_byte(&name, address + 1, '.')) return -1;
- if (get_addr_byte(&name, address + 2, '.')) return -1;
- if (get_addr_byte(&name, address + 3, 0)) return -1;
+ if (!address)
+ address = dummy;
+ if (get_addr_byte(&name, address + 0, '.'))
+ return -1;
+ if (get_addr_byte(&name, address + 1, '.'))
+ return -1;
+ if (get_addr_byte(&name, address + 2, '.'))
+ return -1;
+ if (get_addr_byte(&name, address + 3, 0))
+ return -1;
return 0;
}
static int extract_ipv6_address(struct addrinfo *p, unsigned char address[16], unsigned *scope_id)
{
- /*{
- int i;
- for (i = 0; i < p->ai_addrlen; i++)
- fprintf(stderr, "%02x%c", ((unsigned char *)p->ai_addr)[i], i != p->ai_addrlen - 1 ? ':' : '\n');
- }*/
- if (p->ai_family == AF_INET6 && (socklen_t)p->ai_addrlen >= (socklen_t)sizeof(struct sockaddr_in6) && p->ai_addr->sa_family == AF_INET6) {
+ if (p->ai_family == AF_INET6
+ && (socklen_t)p->ai_addrlen >= (socklen_t)sizeof(struct sockaddr_in6)
+ && p->ai_addr->sa_family == AF_INET6) {
memcpy(address, &((struct sockaddr_in6 *)p->ai_addr)->sin6_addr, 16);
*scope_id = ((struct sockaddr_in6 *)p->ai_addr)->sin6_scope_id;
return 0;
@@ -86,8 +88,10 @@ int numeric_ipv6_address(unsigned char *name, unsigned char address[16], unsigne
int r;
struct in6_addr i6a;
struct addrinfo hints, *res;
- if (!address) address = dummy_a;
- if (!scope_id) scope_id = &dummy_s;
+ if (!address)
+ address = dummy_a;
+ if (!scope_id)
+ scope_id = &dummy_s;
if (inet_pton(AF_INET6, cast_const_char name, &i6a) == 1) {
memcpy(address, &i6a, 16);
@@ -116,18 +120,17 @@ static int memcmp_host_address(struct host_address *a, struct host_address *b)
}
#endif
-static void add_address(struct lookup_result *host, int af, unsigned char *address, unsigned scope_id, int preference)
+static void add_address(struct lookup_result *host, int af,
+ unsigned char *address, unsigned scope_id, int preference)
{
struct host_address neww;
struct host_address *e, *t;
#if MAX_ADDRESSES > 1
struct host_address *n;
#endif
- if (af != AF_INET && preference == ADDR_PREFERENCE_IPV4_ONLY)
- return;
- if (af != AF_INET6 && preference == ADDR_PREFERENCE_IPV6_ONLY)
- return;
- if (host->n >= MAX_ADDRESSES)
+ if ((af != AF_INET && preference == ADDR_PREFERENCE_IPV4_ONLY)
+ || (af != AF_INET6 && preference == ADDR_PREFERENCE_IPV6_ONLY)
+ || (host->n >= MAX_ADDRESSES))
return;
memset(&neww, 0, sizeof(struct host_address));
neww.af = af;
@@ -139,11 +142,10 @@ static void add_address(struct lookup_result *host, int af, unsigned char *addre
for (n = host->a; n != e; n++) {
if (!memcmp_host_address(n, &neww))
return;
- if (preference == ADDR_PREFERENCE_IPV4 && af == AF_INET && n->af != AF_INET) {
- t = n;
- break;
- }
- if (preference == ADDR_PREFERENCE_IPV6 && af == AF_INET6 && n->af != AF_INET6) {
+ if ((preference == ADDR_PREFERENCE_IPV4 && af == AF_INET
+ && n->af != AF_INET)
+ || (preference == ADDR_PREFERENCE_IPV6 && af == AF_INET6
+ && n->af != AF_INET6)) {
t = n;
break;
}
@@ -164,15 +166,20 @@ static int use_getaddrinfo(unsigned char *name, struct addrinfo *hints, int pref
if (gai_err)
return gai_err;
for (p = res; p; p = p->ai_next) {
- if (p->ai_family == AF_INET && (socklen_t)p->ai_addrlen >= (socklen_t)sizeof(struct sockaddr_in) && p->ai_addr->sa_family == AF_INET) {
- add_address(host, AF_INET, (unsigned char *)&((struct sockaddr_in *)p->ai_addr)->sin_addr.s_addr, 0, preference);
+ if (p->ai_family == AF_INET
+ && (socklen_t)p->ai_addrlen >= (socklen_t)sizeof(struct sockaddr_in)
+ && p->ai_addr->sa_family == AF_INET) {
+ add_address(host, AF_INET,
+ (unsigned char *)&((struct sockaddr_in *)p->ai_addr)->sin_addr.s_addr,
+ 0, preference);
continue;
}
{
unsigned char address[16];
unsigned scope_id;
if (!extract_ipv6_address(p, address, &scope_id)) {
- add_address(host, AF_INET6, address, scope_id, preference);
+ add_address(host, AF_INET6, address, scope_id,
+ preference);
continue;
}
}
@@ -218,10 +225,13 @@ void do_real_lookup(unsigned char *name, int preference, struct lookup_result *h
memset(host, 0, sizeof(struct lookup_result));
- if (strlen(cast_const_char name) >= 6 && !casestrcmp(name + strlen(cast_const_char name) - 6, cast_uchar ".onion"))
+ if (strlen(cast_const_char name) >= 6
+ && !casestrcmp(name + strlen(cast_const_char name) - 6,
+ cast_uchar ".onion"))
goto ret;
- if (!support_ipv6) preference = ADDR_PREFERENCE_IPV4_ONLY;
+ if (!support_ipv6)
+ preference = ADDR_PREFERENCE_IPV4_ONLY;
if (!numeric_ip_address(name, address)) {
add_address(host, AF_INET, address, 0, preference);
@@ -291,10 +301,9 @@ ret:
static int do_lookup(struct dnsquery *q, int force_async)
{
- /*debug("starting lookup for %s", q->name);*/
- do_real_lookup(q->name, q->addr_preference, q->addr);
- end_dns_lookup(q, !q->addr->n);
- return 0;
+ do_real_lookup(q->name, q->addr_preference, q->addr);
+ end_dns_lookup(q, !q->addr->n);
+ return 0;
}
static int do_queued_lookup(struct dnsquery *q)
@@ -303,13 +312,13 @@ static int do_queued_lookup(struct dnsquery *q)
q->next_in_queue = NULL;
if (!dns_queue) {
dns_queue = q;
- /*debug("direct lookup");*/
#endif
return do_lookup(q, 0);
#ifndef THREAD_SAFE_LOOKUP
} else {
/*debug("queuing lookup for %s", q->name);*/
- if (dns_queue->next_in_queue) internal("DNS queue corrupted");
+ if (dns_queue->next_in_queue)
+ internal("DNS queue corrupted");
dns_queue->next_in_queue = q;
dns_queue = q;
return 1;
@@ -352,12 +361,11 @@ static void end_dns_lookup(struct dnsquery *q, int a)
size_t sl;
void (*fn)(void *, int);
void *data;
- /*debug("end lookup %s", q->name);*/
#ifndef THREAD_SAFE_LOOKUP
if (q->next_in_queue) {
- /*debug("processing next in queue: %s", q->next_in_queue->name);*/
do_lookup(q->next_in_queue, 1);
- } else dns_queue = NULL;
+ } else
+ dns_queue = NULL;
#endif
if (!q->fn || !q->addr) {
free(q);
@@ -371,18 +379,22 @@ static void end_dns_lookup(struct dnsquery *q, int a)
}
free_dns_entry(dnsentry);
}
- if (a) goto e;
- if (q->addr_preference != ipv6_options.addr_preference) goto e;
+ if (a)
+ goto e;
+ if (q->addr_preference != ipv6_options.addr_preference)
+ goto e;
check_dns_cache_addr_preference();
sl = strlen(cast_const_char q->name);
- if (sl > MAXINT - sizeof(struct dnsentry)) overalloc();
+ if (sl > MAXINT - sizeof(struct dnsentry))
+ overalloc();
dnsentry = xmalloc(sizeof(struct dnsentry) + sl);
strcpy(cast_char dnsentry->name, cast_const_char q->name);
memcpy(&dnsentry->addr, q->addr, sizeof(struct lookup_result));
dnsentry->absolute_time = get_absolute_time();
add_to_list(dns_cache, dnsentry);
- e:
- if (q->s) *q->s = NULL;
+e:
+ if (q->s)
+ *q->s = NULL;
fn = q->fn;
data = q->data;
free(q);
@@ -406,14 +418,16 @@ int find_host_no_cache(unsigned char *name, struct lookup_result *addr, void **q
q->addr = addr;
q->addr_preference = ipv6_options.addr_preference;
strcpy(cast_char q->name, cast_const_char name);
- if (qp) *qp = q;
+ if (qp)
+ *qp = q;
return do_queued_lookup(q);
}
int find_host(unsigned char *name, struct lookup_result *addr, void **qp, void (*fn)(void *, int), void *data)
{
struct dnsentry *dnsentry;
- if (qp) *qp = NULL;
+ if (qp)
+ *qp = NULL;
if (!find_in_dns_cache(name, &dnsentry)) {
if (get_absolute_time() - dnsentry->absolute_time > DNS_TIMEOUT) goto timeout;
memcpy(addr, &dnsentry->addr, sizeof(struct lookup_result));
@@ -440,15 +454,18 @@ void dns_set_priority(unsigned char *name, struct host_address *address, int pre
if (find_in_dns_cache(name, &dnsentry))
return;
for (i = 0; i < dnsentry->addr.n; i++)
- if (!memcmp_host_address(&dnsentry->addr.a[i], address)) goto found_it;
+ if (!memcmp_host_address(&dnsentry->addr.a[i], address))
+ goto found_it;
return;
- found_it:
+found_it:
if (prefer) {
memmove(&dnsentry->addr.a[1], &dnsentry->addr.a[0], i * sizeof(struct host_address));
memcpy(&dnsentry->addr.a[0], address, sizeof(struct host_address));
} else {
- memmove(&dnsentry->addr.a[i], &dnsentry->addr.a[i + 1], (dnsentry->addr.n - i - 1) * sizeof(struct host_address));
- memcpy(&dnsentry->addr.a[dnsentry->addr.n - 1], address, sizeof(struct host_address));
+ memmove(&dnsentry->addr.a[i], &dnsentry->addr.a[i + 1],
+ (dnsentry->addr.n - i - 1) * sizeof(struct host_address));
+ memcpy(&dnsentry->addr.a[dnsentry->addr.n - 1], address,
+ sizeof(struct host_address));
}
}
#endif
@@ -464,10 +481,10 @@ void dns_clear_host(unsigned char *name)
unsigned long dns_info(int type)
{
switch (type) {
- case CI_FILES:
- return list_size(&dns_cache);
- default:
- internal("dns_info: bad request");
+ case CI_FILES:
+ return list_size(&dns_cache);
+ default:
+ internal("dns_info: bad request");
}
return 0;
}
@@ -482,12 +499,13 @@ static int shrink_dns_cache(int u)
d = list_struct(dns_cache.prev, struct dnsentry);
goto delete_last;
}
- foreach(struct dnsentry, d, ld, dns_cache) if (u == SH_FREE_ALL || now - d->absolute_time > DNS_TIMEOUT) {
+ foreach(struct dnsentry, d, ld, dns_cache)
+ if (u == SH_FREE_ALL || now - d->absolute_time > DNS_TIMEOUT) {
delete_last:
- ld = d->list_entry.prev;
- free_dns_entry(d);
- f = ST_SOMETHING_FREED;
- }
+ ld = d->list_entry.prev;
+ free_dns_entry(d);
+ f = ST_SOMETHING_FREED;
+ }
return f | (list_empty(dns_cache) ? ST_CACHE_EMPTY : 0);
}
@@ -519,30 +537,31 @@ int ipv6_full_access(void)
*/
struct sockaddr_in6 sin6;
int h, c, rs;
- if (!support_ipv6) return 0;
+ if (!support_ipv6)
+ return 0;
h = c_socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
- if (h == -1) return 0;
+ if (h == -1)
+ return 0;
memset(&sin6, 0, sizeof sin6);
sin6.sin6_family = AF_INET6;
sin6.sin6_port = htons(1024);
memcpy(&sin6.sin6_addr.s6_addr, "\052\001\004\060\000\015\000\000\002\314\236\377\376\044\176\032", 16);
EINTRLOOP(c, connect(h, (struct sockaddr *)(void *)&sin6, sizeof sin6));
EINTRLOOP(rs, close(h));
- if (!c) return 1;
+ if (!c)
+ return 1;
return 0;
}
void init_dns(void)
{
register_cache_upcall(shrink_dns_cache, 0, cast_uchar "dns");
- {
- int h, rs;
- h = c_socket(AF_INET6, SOCK_STREAM, 0);
- if (h == -1)
- support_ipv6 = 0;
- else {
- EINTRLOOP(rs, close(h));
- support_ipv6 = 1;
- }
+ int h, rs;
+ h = c_socket(AF_INET6, SOCK_STREAM, 0);
+ if (h == -1)
+ support_ipv6 = 0;
+ else {
+ EINTRLOOP(rs, close(h));
+ support_ipv6 = 1;
}
}
diff --git a/error.c b/error.c
@@ -17,19 +17,10 @@ void *do_not_optimize_here(void *p)
return p;
}
-static inline void force_dump(void)
-{
- int rs;
- fprintf(stderr, "\n"ANSI_SET_BOLD"Forcing core dump"ANSI_CLEAR_BOLD"\n");
- fflush(stdout);
- fflush(stderr);
- EINTRLOOP(rs, raise(SIGSEGV));
-}
-
-static void er(int b, char *m, va_list l)
+static void er(char *m, va_list l)
{
vfprintf(stderr, cast_const_char m, l);
- if (b) fprintf(stderr, ANSI_BELL);
+ fprintf(stderr, ANSI_BELL);
fprintf(stderr, "\n");
fflush(stderr);
portable_sleep(1000);
@@ -39,8 +30,7 @@ void error(char *m, ...)
{
va_list l;
va_start(l, m);
- fprintf(stderr, "\n");
- er(1, m, l);
+ er(m, l);
va_end(l);
}
@@ -49,8 +39,7 @@ void fatal_exit(char *m, ...)
va_list l;
fatal_tty_exit();
va_start(l, m);
- fprintf(stderr, "\n");
- er(1, m, l);
+ er(m, l);
va_end(l);
fflush(stdout);
fflush(stderr);
@@ -71,22 +60,12 @@ void int_error(char *m, ...)
fatal_tty_exit();
va_start(l, m);
sprintf(cast_char errbuf, "\n"ANSI_SET_BOLD"INTERNAL ERROR"ANSI_CLEAR_BOLD" at %s:%d: %s", errfile, errline, m);
- er(1, cast_char errbuf, l);
+ er(cast_char errbuf, l);
va_end(l);
- force_dump();
exit(RET_INTERNAL);
#endif
}
-void debug_msg(char *m, ...)
-{
- va_list l;
- va_start(l, m);
- sprintf(cast_char errbuf, "\nDEBUG MESSAGE at %s:%d: %s", errfile, errline, m);
- er(0, cast_char errbuf, l);
- va_end(l);
-}
-
void *mem_calloc_(size_t size, int mayfail)
{
void *p;
diff --git a/links.h b/links.h
@@ -219,7 +219,6 @@ void *xrealloc(void *, size_t);
void *do_not_optimize_here(void *p);
void error(char *, ...) PRINTF_FORMAT(1, 2);
void fatal_exit(char *, ...) PRINTF_FORMAT(1, 2) ATTR_NORETURN;
-void debug_msg(char *, ...) PRINTF_FORMAT(1, 2);
void int_error(char *, ...) PRINTF_FORMAT(1, 2)
#ifndef NO_IE
ATTR_NORETURN
@@ -230,8 +229,6 @@ extern unsigned char *errfile;
#define internal_ errfile = cast_uchar __FILE__, errline = __LINE__, int_error
#define internal internal_
-#define debug errfile = cast_uchar __FILE__, errline = __LINE__, debug_msg
-
void fatal_tty_exit(void);
diff --git a/objreq.c b/objreq.c
@@ -83,9 +83,11 @@ static int auth_cancel(struct dialog_data *dlg, struct dialog_item_data *item)
if (rq) {
rq->hold = 0;
rq->state = O_OK;
- if (rq->timer != NULL) kill_timer(rq->timer);
+ if (rq->timer != NULL)
+ kill_timer(rq->timer);
rq->timer = install_timer(0, object_timer, rq);
- if (!rq->ce) (rq->ce = rq->ce_internal)->refcount++;
+ if (!rq->ce)
+ (rq->ce = rq->ce_internal)->refcount++;
}
cancel_dialog(dlg, item);
return 0;