"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "session.c" between
links-1.03.tar.gz and links-1.04.tar.gz

About: Links is a Lynx-like text WWW browser (table support and pop-up dialog boxes).

session.c  (links-1.03):session.c  (links-1.04)
#include "links.h" #include "links.h"
void undisplay_download(struct download *down);
struct list_head downloads = {&downloads, &downloads}; struct list_head downloads = {&downloads, &downloads};
int are_there_downloads() int are_there_downloads()
{ {
int d = 0; int d = 0;
struct download *down; struct download *down;
foreach(down, downloads) if (!down->prog) d = 1; foreach(down, downloads) if (!down->prog) d = 1;
return d; return d;
} }
skipping to change at line 32 skipping to change at line 34
struct list_head strerror_buf = { &strerror_buf, &strerror_buf }; struct list_head strerror_buf = { &strerror_buf, &strerror_buf };
void free_strerror_buf() void free_strerror_buf()
{ {
free_list(strerror_buf); free_list(strerror_buf);
} }
int get_error_from_errno(int errn) int get_error_from_errno(int errn)
{ {
if (errn > 0 && (errn < -S_OK || errn > -S_MAX)) if (errn > 0 && (errn < -S__OK || errn > -S_MAX))
return -errn; return -errn;
#ifdef BEOS #ifdef BEOS
if (-errn > 0 && (-errn < -S_OK || -errn > -S_MAX)) if (-errn > 0 && (-errn < -S__OK || -errn > -S_MAX))
return errn; return errn;
#endif #endif
return S_UNKNOWN_ERROR; return S_UNKNOWN_ERROR;
} }
unsigned char *get_err_msg(int state) unsigned char *get_err_msg(int state)
{ {
unsigned char *e; unsigned char *e;
struct strerror_val *s; struct strerror_val *s;
if ((state >= S_MAX && state <= S_OK) || state >= S_WAIT) { if ((state >= S_MAX && state <= S__OK) || state >= S_WAIT) {
int i; int i;
for (i = 0; msg_dsc[i].msg; i++) for (i = 0; msg_dsc[i].msg; i++)
if (msg_dsc[i].n == state) return msg_dsc[i].msg; if (msg_dsc[i].n == state) return msg_dsc[i].msg;
unk: unk:
return TEXT_(T_UNKNOWN_ERROR); return TEXT_(T_UNKNOWN_ERROR);
} }
#ifdef BEOS #ifdef BEOS
if ((e = strerror(state)) && *e && !strstr(e, "No Error")) goto have_erro r; if ((e = strerror(state)) && *e && !strstr(e, "No Error")) goto have_erro r;
#endif #endif
if ((e = strerror(-state)) && *e) goto have_error; if ((e = strerror(-state)) && *e) goto have_error;
skipping to change at line 83 skipping to change at line 85
if (n < 10 && d != -1) add_chr_to_str(s, l, '.'), add_num_to_str(s, l, d) ; if (n < 10 && d != -1) add_chr_to_str(s, l, '.'), add_num_to_str(s, l, d) ;
add_chr_to_str(s, l, ' '); add_chr_to_str(s, l, ' ');
if (suff) add_chr_to_str(s, l, suff); if (suff) add_chr_to_str(s, l, suff);
add_chr_to_str(s, l, 'B'); add_chr_to_str(s, l, 'B');
} }
void add_time_to_str(unsigned char **s, int *l, ttime t) void add_time_to_str(unsigned char **s, int *l, ttime t)
{ {
unsigned char q[64]; unsigned char q[64];
if (t < 0) t = 0; if (t < 0) t = 0;
t &= 0xffffffff; if (t >= 86400) sprintf(q, "%ud ", (unsigned)(t / 86400)), add_to_str(s,
if (t >= 86400) sprintf(q, "%dd ", (int)(t / 86400)), add_to_str(s, l, q) l, q);
;
if (t >= 3600) t %= 86400, sprintf(q, "%d:%02d", (int)(t / 3600), (int)(t / 60 % 60)), add_to_str(s, l, q); if (t >= 3600) t %= 86400, sprintf(q, "%d:%02d", (int)(t / 3600), (int)(t / 60 % 60)), add_to_str(s, l, q);
else sprintf(q, "%d", (int)(t / 60)), add_to_str(s, l, q); else sprintf(q, "%d", (int)(t / 60)), add_to_str(s, l, q);
sprintf(q, ":%02d", (int)(t % 60)), add_to_str(s, l, q); sprintf(q, ":%02d", (int)(t % 60)), add_to_str(s, l, q);
} }
unsigned char *get_stat_msg(struct status *stat, struct terminal *term) unsigned char *get_stat_msg(struct status *stat, struct terminal *term)
{ {
if (stat->state == S_TRANS && stat->prg->elapsed / 100) { if (stat->state == S_TRANS && stat->prg->elapsed / 100) {
unsigned char *m = init_str(); unsigned char *m = init_str();
int l = 0; int l = 0;
skipping to change at line 119 skipping to change at line 120
return m; return m;
} }
return stracpy(_(get_err_msg(stat->state), term)); return stracpy(_(get_err_msg(stat->state), term));
} }
void print_screen_status(struct session *ses) void print_screen_status(struct session *ses)
{ {
struct terminal *term = ses->term; struct terminal *term = ses->term;
struct status *stat = NULL; struct status *stat = NULL;
unsigned char *m; unsigned char *m;
fill_area(term, 0, 0, term->x, 1, COLOR_TITLE_BG); fill_area(term, 0, 0, term->x, 1, COLOR_TITLE_BG | ' ');
fill_area(term, 0, term->y - 1, term->x, 1, COLOR_STATUS_BG); fill_area(term, 0, term->y - 1, term->x, 1, COLOR_STATUS_BG | ' ');
if (ses->wtd) stat = &ses->loading; if (ses->wtd) stat = &ses->loading;
else if (!list_empty(ses->history)) stat = &cur_loc(ses)->stat; else if (!list_empty(ses->history)) stat = &cur_loc(ses)->stat;
if (stat && stat->state == S_OK) { if (stat && stat->state == S__OK) {
struct file_to_load *ftl; struct file_to_load *ftl;
foreach(ftl, ses->more_files) { foreach(ftl, ses->more_files) {
if (ftl->req_sent && ftl->stat.state >= 0) { if (ftl->req_sent && ftl->stat.state >= 0) {
stat = &ftl->stat; stat = &ftl->stat;
break; break;
} }
} }
} }
if (stat) { if (stat) {
if (stat->state == S_OK) if ((m = print_current_link(ses))) goto p; if (stat->state == S__OK) if ((m = print_current_link(ses))) goto p;
if ((m = get_stat_msg(stat, term))) { if ((m = get_stat_msg(stat, term))) {
p: p:
print_text(term, 0, term->y - 1, strlen(m), m, COLOR_STAT US); print_text(term, 0, term->y - 1, strlen(m), m, COLOR_STAT US);
mem_free(m); mem_free(m);
} }
if ((m = print_current_title(ses))) { if ((m = print_current_title(ses))) {
int p = term->x - 1 - strlen(m); int p = term->x - 1 - strlen(m);
if (p < 0) p = 0; if (p < 0) p = 0;
print_text(term, p, 0, strlen(m), m, COLOR_TITLE); print_text(term, p, 0, strlen(m), m, COLOR_TITLE);
/*set_window_title(0,m);*/ /*set_window_title(0,m);*/
skipping to change at line 158 skipping to change at line 159
if (ses->screen && ses->screen->f_data && ses->screen->f_data->ti tle && ses->screen->f_data->title[0]) add_to_strn(&m, " - "), add_to_strn(&m, se s->screen->f_data->title); if (ses->screen && ses->screen->f_data && ses->screen->f_data->ti tle && ses->screen->f_data->title[0]) add_to_strn(&m, " - "), add_to_strn(&m, se s->screen->f_data->title);
set_terminal_title(term, m); set_terminal_title(term, m);
/* mem_free(m); -- set_terminal_title frees it */ /* mem_free(m); -- set_terminal_title frees it */
} }
redraw_from_window(ses->win); redraw_from_window(ses->win);
} }
void print_error_dialog(struct session *ses, struct status *stat, unsigned char *title) void print_error_dialog(struct session *ses, struct status *stat, unsigned char *title)
{ {
unsigned char *t = get_err_msg(stat->state); unsigned char *t = get_err_msg(stat->state);
if (!t) return;
msg_box(ses->term, NULL, title, AL_CENTER, t, ses, 1, TEXT_(T_CANCEL), NU LL, B_ENTER | B_ESC/*, _("Retry"), NULL, 0 !!! FIXME: retry */); msg_box(ses->term, NULL, title, AL_CENTER, t, ses, 1, TEXT_(T_CANCEL), NU LL, B_ENTER | B_ESC/*, _("Retry"), NULL, 0 !!! FIXME: retry */);
} }
void free_wtd(struct session *ses) void free_wtd(struct session *ses)
{ {
if (!ses->wtd) { if (!ses->wtd) {
internal("no WTD"); internal("no WTD");
return; return;
} }
if (ses->goto_position) mem_free(ses->goto_position), ses->goto_position = NULL; if (ses->goto_position) mem_free(ses->goto_position), ses->goto_position = NULL;
skipping to change at line 281 skipping to change at line 281
return; return;
} }
ce->refcount--; ce->refcount--;
defrag_entry(ce); defrag_entry(ce);
fr = ce->frag.next; fr = ce->frag.next;
if ((void *)fr == &ce->frag) return; if ((void *)fr == &ce->frag) return;
if (!(fd = current_frame(ses)) || !fd->f_data) return; if (!(fd = current_frame(ses)) || !fd->f_data) return;
d_opt = &fd->f_data->opt; d_opt = &fd->f_data->opt;
if (get_image_map(ce->head, fr->data, fr->data + fr->length, ses->goto_po sition, &menu, &ml, ses->imgmap_href_base, ses->imgmap_target_base, ses->term->s pec->charset, ses->ds.assume_cp, ses->ds.hard_assume)) if (get_image_map(ce->head, fr->data, fr->data + fr->length, ses->goto_po sition, &menu, &ml, ses->imgmap_href_base, ses->imgmap_target_base, ses->term->s pec->charset, ses->ds.assume_cp, ses->ds.hard_assume))
return; return;
add_empty_window(ses->term, (void (*)(void *))freeml, ml); /*add_empty_window(ses->term, (void (*)(void *))freeml, ml);*/
do_menu(ses->term, menu, ses); do_menu_selected(ses->term, menu, ses, 0, (void (*)(void *))freeml, ml);
} }
void map_selected(struct terminal *term, struct link_def *ld, struct session *se s) void map_selected(struct terminal *term, struct link_def *ld, struct session *se s)
{ {
goto_url_f(ses, ld->link, ld->target); goto_url_f(ses, ld->link, ld->target);
} }
void ses_back(struct session *ses) void ses_back(struct session *ses)
{ {
struct location *loc; struct location *loc;
skipping to change at line 321 skipping to change at line 321
struct session *get_download_ses(struct download *down) struct session *get_download_ses(struct download *down)
{ {
struct session *ses; struct session *ses;
foreach(ses, sessions) if (ses == down->ses) return ses; foreach(ses, sessions) if (ses == down->ses) return ses;
if (!list_empty(sessions)) return sessions.next; if (!list_empty(sessions)) return sessions.next;
return NULL; return NULL;
} }
void abort_download(struct download *down) void abort_download(struct download *down)
{ {
int rs;
unregister_bottom_half((void (*)(void *))abort_download, down);
unregister_bottom_half((void (*)(void *))undisplay_download, down);
if (down->win) delete_window(down->win); if (down->win) delete_window(down->win);
if (down->ask) delete_window(down->ask); if (down->ask) delete_window(down->ask);
if (down->stat.state >= 0) change_connection(&down->stat, NULL, PRI_CANCE L); if (down->stat.state >= 0) change_connection(&down->stat, NULL, PRI_CANCE L);
mem_free(down->url); mem_free(down->url);
if (down->handle != -1) prealloc_truncate(down->handle, down->last_pos), if (down->handle != -1) {
close(down->handle); prealloc_truncate(down->handle, down->last_pos);
EINTRLOOP(rs, close(down->handle));
}
if (down->prog) { if (down->prog) {
unlink(down->file); EINTRLOOP(rs, unlink(down->file));
mem_free(down->prog); mem_free(down->prog);
} }
mem_free(down->file); mem_free(down->file);
del_from_list(down); del_from_list(down);
mem_free(down); mem_free(down);
} }
void kill_downloads_to_file(unsigned char *file) void kill_downloads_to_file(unsigned char *file)
{ {
struct download *down; struct download *down;
skipping to change at line 364 skipping to change at line 370
register_bottom_half((void (*)(void *))undisplay_download, dlg->dlg->udat a); register_bottom_half((void (*)(void *))undisplay_download, dlg->dlg->udat a);
return 0; return 0;
} }
void download_abort_function(struct dialog_data *dlg) void download_abort_function(struct dialog_data *dlg)
{ {
struct download *down = dlg->dlg->udata; struct download *down = dlg->dlg->udata;
down->win = NULL; down->win = NULL;
} }
int test_percentage(struct status *stat)
{
return stat->prg->size > 0;
}
static int download_meter(int size, struct status *stat)
{
int m;
if (!stat->prg->size) return 0;
m = (int)((double)size * (double)stat->prg->pos / (double)stat->prg->size
);
if (m < 0) m = 0;
if (m > size) m = size;
return m;
}
unsigned char *download_percentage(struct download *down, int pad)
{
unsigned char *s;
int l;
int perc;
struct status *stat = &down->stat;
if (stat->state != S_TRANS || !test_percentage(stat)) return stracpy("");
s = init_str();
l = 0;
perc = download_meter(100, stat);
if (pad) {
if (perc < 10) add_chr_to_str(&s, &l, ' ');
if (perc < 100) add_chr_to_str(&s, &l, ' ');
}
add_num_to_str(&s, &l, perc);
add_chr_to_str(&s, &l, '%');
return s;
}
void download_window_function(struct dialog_data *dlg) void download_window_function(struct dialog_data *dlg)
{ {
struct download *down = dlg->dlg->udata; struct download *down = dlg->dlg->udata;
struct terminal *term = dlg->win->term; struct terminal *term = dlg->win->term;
int max = 0, min = 0; int max = 0, min = 0;
int w, x, y; int w, x, y;
int t = 0; int t = 0;
int show_percentage = 0;
unsigned char *m, *u; unsigned char *m, *u;
struct status *stat = &down->stat; struct status *stat = &down->stat;
redraw_below_window(dlg->win); redraw_below_window(dlg->win);
down->win = dlg->win; down->win = dlg->win;
if (stat->state == S_TRANS && stat->prg->elapsed / 100) { if (stat->state == S_TRANS && stat->prg->elapsed / 100) {
int l = 0; int l = 0;
m = init_str(); m = init_str();
t = 1; t = 1;
add_to_str(&m, &l, _(TEXT_(T_RECEIVED), term)); add_to_str(&m, &l, _(TEXT_(T_RECEIVED), term));
add_to_str(&m, &l, " "); add_to_str(&m, &l, " ");
skipping to change at line 398 skipping to change at line 439
add_to_str(&m, &l, " "); add_to_str(&m, &l, " ");
add_xnum_to_str(&m, &l, (longlong)stat->prg->loaded * 10 / (stat- >prg->elapsed / 100)); add_xnum_to_str(&m, &l, (longlong)stat->prg->loaded * 10 / (stat- >prg->elapsed / 100));
add_to_str(&m, &l, "/s"); add_to_str(&m, &l, "/s");
if (stat->prg->elapsed >= CURRENT_SPD_AFTER * SPD_DISP_TIME) if (stat->prg->elapsed >= CURRENT_SPD_AFTER * SPD_DISP_TIME)
add_to_str(&m, &l, ", "), add_to_str(&m, &l, _(TEXT_(T_CU RRENT_SPEED), term)), add_to_str(&m, &l, " "), add_to_str(&m, &l, ", "), add_to_str(&m, &l, _(TEXT_(T_CU RRENT_SPEED), term)), add_to_str(&m, &l, " "),
add_xnum_to_str(&m, &l, stat->prg->cur_loaded / (CURRENT_ SPD_SEC * SPD_DISP_TIME / 1000)), add_xnum_to_str(&m, &l, stat->prg->cur_loaded / (CURRENT_ SPD_SEC * SPD_DISP_TIME / 1000)),
add_to_str(&m, &l, "/s"); add_to_str(&m, &l, "/s");
add_to_str(&m, &l, "\n"); add_to_str(&m, &l, "\n");
add_to_str(&m, &l, _(TEXT_(T_ELAPSED_TIME), term)); add_to_str(&m, &l, _(TEXT_(T_ELAPSED_TIME), term));
add_to_str(&m, &l, " "); add_to_str(&m, &l, " ");
add_time_to_str(&m, &l, stat->prg->elapsed / 1000); add_time_to_str(&m, &l, (uttime)stat->prg->elapsed / 1000);
if (stat->prg->size >= 0 && stat->prg->loaded > 0) { if (stat->prg->size >= 0 && stat->prg->loaded > 0) {
add_to_str(&m, &l, ", "); add_to_str(&m, &l, ", ");
add_to_str(&m, &l, _(TEXT_(T_ESTIMATED_TIME), term)); add_to_str(&m, &l, _(TEXT_(T_ESTIMATED_TIME), term));
add_to_str(&m, &l, " "); add_to_str(&m, &l, " ");
/*add_time_to_str(&m, &l, stat->prg->elapsed / 1000 * sta t->prg->size / stat->prg->loaded * 1000 - stat->prg->elapsed);*/ /*add_time_to_str(&m, &l, stat->prg->elapsed / 1000 * sta t->prg->size / stat->prg->loaded * 1000 - stat->prg->elapsed);*/
add_time_to_str(&m, &l, (stat->prg->size - stat->prg->pos /*add_time_to_str(&m, &l, (stat->prg->size - stat->prg->p
) / ((longlong)stat->prg->loaded * 10 / (stat->prg->elapsed / 100))); os) / ((longlong)stat->prg->loaded * 10 / (stat->prg->elapsed / 100)));*/
add_time_to_str(&m, &l, (stat->prg->size - stat->prg->pos
) / ((double)stat->prg->loaded * 1000 / stat->prg->elapsed));
} }
} else m = stracpy(_(get_err_msg(stat->state), term)); } else m = stracpy(_(get_err_msg(stat->state), term));
show_percentage = t && test_percentage(stat);
u = stracpy(down->url); u = stracpy(down->url);
if (strchr(u, POST_CHAR)) *strchr(u, POST_CHAR) = 0; if (strchr(u, POST_CHAR)) *strchr(u, POST_CHAR) = 0;
max_text_width(term, u, &max); max_text_width(term, u, &max);
min_text_width(term, u, &min); min_text_width(term, u, &min);
max_text_width(term, m, &max); max_text_width(term, m, &max);
min_text_width(term, m, &min); min_text_width(term, m, &min);
max_buttons_width(term, dlg->items, dlg->n, &max); max_buttons_width(term, dlg->items, dlg->n, &max);
min_buttons_width(term, dlg->items, dlg->n, &min); min_buttons_width(term, dlg->items, dlg->n, &min);
w = dlg->win->term->x * 9 / 10 - 2 * DIALOG_LB; w = dlg->win->term->x * 9 / 10 - 2 * DIALOG_LB;
if (w < min) w = min; if (w < min) w = min;
if (w > dlg->win->term->x - 2 * DIALOG_LB) w = dlg->win->term->x - 2 * DI ALOG_LB; if (w > dlg->win->term->x - 2 * DIALOG_LB) w = dlg->win->term->x - 2 * DI ALOG_LB;
if (t && stat->prg->size >= 0) { if (show_percentage) {
if (w < DOWN_DLG_MIN) w = DOWN_DLG_MIN; if (w < DOWN_DLG_MIN) w = DOWN_DLG_MIN;
} else { } else {
if (w > max) w = max; if (w > max) w = max;
} }
if (w < 1) w = 1; if (w < 1) w = 1;
y = 0; y = 0;
dlg_format_text(NULL, term, u, 0, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT ); dlg_format_text(NULL, term, u, 0, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT );
y++; y++;
if (t && stat->prg->size >= 0) y += 2; if (show_percentage) y += 2;
dlg_format_text(NULL, term, m, 0, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT ); dlg_format_text(NULL, term, m, 0, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT );
y++; y++;
dlg_format_buttons(NULL, term, dlg->items, dlg->n, 0, &y, w, NULL, AL_CEN TER); dlg_format_buttons(NULL, term, dlg->items, dlg->n, 0, &y, w, NULL, AL_CEN TER);
dlg->xw = w + 2 * DIALOG_LB; dlg->xw = w + 2 * DIALOG_LB;
dlg->yw = y + 2 * DIALOG_TB; dlg->yw = y + 2 * DIALOG_TB;
center_dlg(dlg); center_dlg(dlg);
draw_dlg(dlg); draw_dlg(dlg);
y = dlg->y + DIALOG_TB + 1; y = dlg->y + DIALOG_TB + 1;
x = dlg->x + DIALOG_LB; x = dlg->x + DIALOG_LB;
dlg_format_text(term, term, u, x, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT ); dlg_format_text(term, term, u, x, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT );
if (t && stat->prg->size >= 0) { if (show_percentage) {
unsigned char q[64]; unsigned char *q;
int p = w - 6; int p = w - 6;
y++; y++;
set_only_char(term, x, y, '['); set_only_char(term, x, y, '[');
set_only_char(term, x + w - 5, y, ']'); set_only_char(term, x + w - 5, y, ']');
fill_area(term, x + 1, y, (int)((longlong)p * (longlong)stat->prg fill_area(term, x + 1, y, download_meter(p, stat), 1, COLOR_DIALO
->pos / (longlong)stat->prg->size), 1, COLOR_DIALOG_METER); G_METER | ' ');
sprintf(q, "%3d%%", (int)((longlong)100 * (longlong)stat->prg->po q = download_percentage(down, 1);
s / (longlong)stat->prg->size));
print_text(term, x + w - 4, y, strlen(q), q, COLOR_DIALOG_TEXT); print_text(term, x + w - 4, y, strlen(q), q, COLOR_DIALOG_TEXT);
mem_free(q);
y++; y++;
} }
y++; y++;
dlg_format_text(term, term, m, x, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT ); dlg_format_text(term, term, m, x, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT );
y++; y++;
dlg_format_buttons(term, term, dlg->items, dlg->n, x, &y, w, NULL, AL_CEN TER); dlg_format_buttons(term, term, dlg->items, dlg->n, x, &y, w, NULL, AL_CEN TER);
mem_free(u); mem_free(u);
mem_free(m); mem_free(m);
} }
skipping to change at line 487 skipping to change at line 531
dlg->items[1].type = D_BUTTON; dlg->items[1].type = D_BUTTON;
dlg->items[1].gid = 0; dlg->items[1].gid = 0;
dlg->items[1].fn = dlg_abort_download; dlg->items[1].fn = dlg_abort_download;
dlg->items[1].text = TEXT_(T_ABORT); dlg->items[1].text = TEXT_(T_ABORT);
dlg->items[2].type = D_END; dlg->items[2].type = D_END;
do_dialog(term, dlg, getml(dlg, NULL)); do_dialog(term, dlg, getml(dlg, NULL));
} }
time_t parse_http_date(const char *date) /* this functions is bad !!! */ time_t parse_http_date(const char *date) /* this functions is bad !!! */
{ {
#ifdef HAVE_MKTIME
const char *months[12] = const char *months[12] =
{"Jan", "Feb", "Mar", "Apr", "May", "Jun", {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
time_t t = 0; time_t t = 0;
/* Mon, 03 Jan 2000 21:29:33 GMT */ /* Mon, 03 Jan 2000 21:29:33 GMT */
struct tm tm; struct tm tm;
if (!date || strlen(date) < 28) return 0; if (!date || strlen(date) < 28) return 0;
date += 5; date += 5;
tm.tm_mday = (date[0] - '0') * 10 + date[1] - '0'; tm.tm_mday = (date[0] - '0') * 10 + date[1] - '0';
skipping to change at line 511 skipping to change at line 556
tm.tm_year = (date[0] - '0') * 1000 + (date[1] - '0') * 100 + (date[2] - '0') * 10 + date[3] - '0' - 1900; tm.tm_year = (date[0] - '0') * 1000 + (date[1] - '0') * 100 + (date[2] - '0') * 10 + date[3] - '0' - 1900;
date += 5; date += 5;
tm.tm_hour = (date[0] - '0') * 10 + date[1] - '0'; tm.tm_hour = (date[0] - '0') * 10 + date[1] - '0';
date += 3; date += 3;
tm.tm_min = (date[0] - '0') * 10 + date[1] - '0'; tm.tm_min = (date[0] - '0') * 10 + date[1] - '0';
date += 3; date += 3;
tm.tm_sec = (date[0] - '0') * 10 + date[1] - '0'; tm.tm_sec = (date[0] - '0') * 10 + date[1] - '0';
t = mktime(&tm); t = mktime(&tm);
if (t == (time_t) - 1) return 0; if (t == (time_t) - 1) return 0;
else return t; else return t;
#else
return 0;
#endif
} }
void download_data(struct status *stat, struct download *down) void download_data(struct status *stat, struct download *down)
{ {
struct cache_entry *ce; struct cache_entry *ce;
struct fragment *frag; struct fragment *frag;
int rs;
if (stat->state >= S_WAIT && stat->state < S_TRANS) goto end_store; if (stat->state >= S_WAIT && stat->state < S_TRANS) goto end_store;
if (!(ce = stat->ce)) goto end_store; if (!(ce = stat->ce)) goto end_store;
if (ce->last_modified) if (ce->last_modified)
down->remotetime = parse_http_date(ce->last_modified); down->remotetime = parse_http_date(ce->last_modified);
/* fprintf(stderr,"\nFEFE date %s\n",ce->last_modified); */ /* fprintf(stderr,"\nFEFE date %s\n",ce->last_modified); */
if (ce->redirect && down->redirect_cnt++ < MAX_REDIRECTS) { if (ce->redirect && down->redirect_cnt++ < MAX_REDIRECTS) {
unsigned char *u, *p, *pos; unsigned char *u, *p, *pos;
if (stat->state >= 0) change_connection(&down->stat, NULL, PRI_CA NCEL); if (stat->state >= 0) change_connection(&down->stat, NULL, PRI_CA NCEL);
u = join_urls(down->url, ce->redirect); u = join_urls(down->url, ce->redirect);
if (!u) goto x; if (!u) goto x;
skipping to change at line 549 skipping to change at line 598
load_url(down->url, &down->stat, PRI_DOWNLOAD, down->redi rect_cnt < MAX_CACHED_REDIRECTS ? NC_CACHE : NC_RELOAD); load_url(down->url, &down->stat, PRI_DOWNLOAD, down->redi rect_cnt < MAX_CACHED_REDIRECTS ? NC_CACHE : NC_RELOAD);
return; return;
/*} else { /*} else {
unsigned char *msg = init_str(); unsigned char *msg = init_str();
int l = 0; int l = 0;
add_bytes_to_str(&msg, &l, down->url, (unsigned char *)st rchr(down->url, POST_CHAR) - down->url); add_bytes_to_str(&msg, &l, down->url, (unsigned char *)st rchr(down->url, POST_CHAR) - down->url);
msg_box(get_download_ses(down)->term, getml(msg, NULL), T EXT_(T_WARNING), AL_CENTER | AL_EXTD_TEXT, TEXT_(T_DO_YOU_WANT_TO_FOLLOW_REDIREC T_AND_POST_FORM_DATA_TO_URL), "", msg, "?", NULL, down, 3, TEXT_(T_YES), down_po st_yes, B_ENTER, TEXT_(T_NO), down_post_no, 0, TEXT_(T_CANCEL), down_post_cancel , B_ESC); msg_box(get_download_ses(down)->term, getml(msg, NULL), T EXT_(T_WARNING), AL_CENTER | AL_EXTD_TEXT, TEXT_(T_DO_YOU_WANT_TO_FOLLOW_REDIREC T_AND_POST_FORM_DATA_TO_URL), "", msg, "?", NULL, down, 3, TEXT_(T_YES), down_po st_yes, B_ENTER, TEXT_(T_NO), down_post_no, 0, TEXT_(T_CANCEL), down_post_cancel , B_ESC);
}*/ }*/
} }
x: x:
foreach(frag, ce->frag) while (frag->offset <= down->last_pos && frag->of foreachback(frag, ce->frag) if (frag->offset <= down->last_pos) goto have
fset + frag->length > down->last_pos) { _frag;
foreach(frag, ce->frag) have_frag: while (frag->offset <= down->last_pos
&& frag->offset + frag->length > down->last_pos) {
int w; int w;
#ifdef HAVE_OPEN_PREALLOC #ifdef HAVE_OPEN_PREALLOC
if (!down->last_pos && (!down->stat.prg || down->stat.prg->size > 0) && can_prealloc(down->file)) { if (!down->last_pos && (!down->stat.prg || down->stat.prg->size > 0) && can_prealloc(down->file)) {
struct stat st; struct stat st;
if (fstat(down->handle, &st) || !S_ISREG(st.st_mode)) got EINTRLOOP(rs, fstat(down->handle, &st));
o skip_prealloc; if (rs || !S_ISREG(st.st_mode)) goto skip_prealloc;
close(down->handle); EINTRLOOP(rs, close(down->handle));
down->handle = open_prealloc(down->file, O_CREAT|O_WRONLY down->handle = open_prealloc(down->file, O_CREAT|O_NOCTTY
|O_TRUNC, 0666, down->stat.prg ? down->stat.prg->size : ce->length); |O_WRONLY|O_TRUNC, 0666, down->stat.prg ? down->stat.prg->size : ce->length);
if (down->handle == -1) goto error; if (down->handle == -1) goto download_error;
set_bin(down->handle); set_bin(down->handle);
skip_prealloc:; skip_prealloc:;
} }
#endif #endif
w = write(down->handle, frag->data + (down->last_pos - frag->offs et), frag->length - (down->last_pos - frag->offset)); w = hard_write(down->handle, frag->data + (down->last_pos - frag- >offset), frag->length - (down->last_pos - frag->offset));
if (w == -1) { if (w == -1) {
#ifdef HAVE_OPEN_PREALLOC download_error:
error:
#endif
if (!list_empty(sessions)) { if (!list_empty(sessions)) {
unsigned char *emsg = stracpy(strerror(errno)); unsigned char *emsg = stracpy(strerror(errno));
unsigned char *msg = stracpy(down->file); unsigned char *msg = stracpy(down->file);
msg_box(get_download_ses(down)->term, getml(msg, emsg, NULL), TEXT_(T_DOWNLOAD_ERROR), AL_CENTER | AL_EXTD_TEXT, TEXT_(T_COULD_NO T_WRITE_TO_FILE), " ", msg, ": ", emsg, NULL, NULL, 1, TEXT_(T_CANCEL), NULL, B_ ENTER | B_ESC); msg_box(get_download_ses(down)->term, getml(msg, emsg, NULL), TEXT_(T_DOWNLOAD_ERROR), AL_CENTER | AL_EXTD_TEXT, TEXT_(T_COULD_NO T_WRITE_TO_FILE), " ", msg, ": ", emsg, NULL, NULL, 1, TEXT_(T_CANCEL), NULL, B_ ENTER | B_ESC);
} }
detach_connection(stat, down->last_pos); detach_connection(stat, down->last_pos);
abort_download(down); abort_download(down);
return; return;
} }
down->last_pos += w; down->last_pos += w;
} }
detach_connection(stat, down->last_pos); detach_connection(stat, down->last_pos);
end_store:; end_store:;
if (stat->state < 0) { if (stat->state < 0) {
if (stat->state != S_OK) { if (stat->state != S__OK) {
unsigned char *t = get_err_msg(stat->state); unsigned char *t = get_err_msg(stat->state);
if (t) { unsigned char *tt = stracpy(down->url);
unsigned char *tt = stracpy(down->url); if (strchr(tt, POST_CHAR)) *strchr(tt, POST_CHAR) = 0;
if (strchr(tt, POST_CHAR)) *strchr(tt, POST_CHAR) msg_box(get_download_ses(down)->term, getml(tt, NULL), TE
= 0; XT_(T_DOWNLOAD_ERROR), AL_CENTER | AL_EXTD_TEXT, TEXT_(T_ERROR_DOWNLOADING), " "
msg_box(get_download_ses(down)->term, getml(tt, N , tt, ":\n\n", t, NULL, get_download_ses(down), 1, TEXT_(T_CANCEL), NULL, B_ENTE
ULL), TEXT_(T_DOWNLOAD_ERROR), AL_CENTER | AL_EXTD_TEXT, TEXT_(T_ERROR_DOWNLOADI R | B_ESC/*, TEXT_(T_RETRY), NULL, 0 !!! FIXME: retry */);
NG), " ", tt, ":\n\n", t, NULL, get_download_ses(down), 1, TEXT_(T_CANCEL), NULL
, B_ENTER | B_ESC/*, TEXT_(T_RETRY), NULL, 0 !!! FIXME: retry */);
}
} else { } else {
prealloc_truncate(down->handle, down->last_pos);
EINTRLOOP(rs, close(down->handle));
down->handle = -1;
if (rs) goto download_error;
if (down->prog) { if (down->prog) {
prealloc_truncate(down->handle, down->last_pos);
close(down->handle), down->handle = -1;
exec_on_terminal(get_download_ses(down)->term, do wn->prog, down->file, !!down->prog_flags); exec_on_terminal(get_download_ses(down)->term, do wn->prog, down->file, !!down->prog_flags);
mem_free(down->prog), down->prog = NULL; mem_free(down->prog), down->prog = NULL;
} else if (down->remotetime && download_utime) { } else if (down->remotetime && download_utime) {
#ifdef HAVE_UTIMES
struct timeval utv[2];
utv[0].tv_usec = utv[1].tv_usec = 0;
utv[0].tv_sec = utv[1].tv_sec = down->remotetime;
EINTRLOOP(rs, utimes(down->file, utv));
#elif defined(HAVE_UTIME)
struct utimbuf foo; struct utimbuf foo;
foo.actime = foo.modtime = down->remotetime; foo.actime = foo.modtime = down->remotetime;
utime(down->file, &foo); EINTRLOOP(rs, utime(down->file, &foo));
#endif
} }
} }
abort_download(down); abort_download(down);
return; return;
} }
if (down->win) { if (down->win) {
struct event ev = { EV_REDRAW, 0, 0, 0 }; struct event ev = { EV_REDRAW, 0, 0, 0 };
ev.x = down->win->term->x; ev.x = down->win->term->x;
ev.y = down->win->term->y; ev.y = down->win->term->y;
down->win->handler(down->win, &ev, 0); down->win->handler(down->win, &ev, 0);
skipping to change at line 635 skipping to change at line 691
if (file[0] == '~' && dir_sep(file[1])) { if (file[0] == '~' && dir_sep(file[1])) {
unsigned char *h = getenv("HOME"); unsigned char *h = getenv("HOME");
if (h) { if (h) {
int fl = 0; int fl = 0;
file = init_str(); file = init_str();
add_to_str(&file, &fl, h); add_to_str(&file, &fl, h);
add_to_str(&file, &fl, fi + 1); add_to_str(&file, &fl, fi + 1);
} }
} }
} }
h = open(file, O_CREAT|O_WRONLY|O_TRUNC|(safe?O_EXCL:0), sf ? 0600 : 0666 ); EINTRLOOP(h, open(file, O_CREAT|O_NOCTTY|O_WRONLY|O_TRUNC|(safe?O_EXCL:0) , sf ? 0600 : 0666));
if (h == -1) { if (h == -1) {
unsigned char *msg, *msge; unsigned char *msg, *msge;
int errn = errno; int errn = errno;
if (errn == EEXIST && safe) { if (errn == EEXIST && safe) {
h = -2; h = -2;
goto x; goto x;
} }
msg = stracpy(file); msg = stracpy(file);
msge = stracpy(strerror(errn)); msge = stracpy(strerror(errn));
msg_box(term, getml(msg, msge, NULL), TEXT_(T_DOWNLOAD_ERROR), AL _CENTER | AL_EXTD_TEXT, TEXT_(T_COULD_NOT_CREATE_FILE), " ", msg, ": ", msge, NU LL, NULL, 1, TEXT_(T_CANCEL), NULL, B_ENTER | B_ESC); msg_box(term, getml(msg, msge, NULL), TEXT_(T_DOWNLOAD_ERROR), AL _CENTER | AL_EXTD_TEXT, TEXT_(T_COULD_NOT_CREATE_FILE), " ", msg, ": ", msge, NU LL, NULL, 1, TEXT_(T_CANCEL), NULL, B_ENTER | B_ESC);
skipping to change at line 675 skipping to change at line 731
int l, nl; int l, nl;
unsigned char *name, *fn, *fnn, *fnnn, *s; unsigned char *name, *fn, *fnn, *fnnn, *s;
unsigned char *nm; unsigned char *nm;
unsigned char *directory = NULL; unsigned char *directory = NULL;
#ifdef WIN32 #ifdef WIN32
directory = getenv("TMP"); directory = getenv("TMP");
if (!directory) directory = getenv("TEMP"); if (!directory) directory = getenv("TEMP");
#endif #endif
nm = tempnam(directory, "links"); nm = tempnam(directory, "links");
if (!nm) return NULL; if (!nm) return NULL;
#ifdef OS2 #ifdef DOS_FS_8_3
if (strlen(nm) > 4 && !strcasecmp(nm + strlen(nm) - 4, ".tmp")) nm[strlen (nm) - 4] = 0; if (strlen(nm) > 4 && !strcasecmp(nm + strlen(nm) - 4, ".tmp")) nm[strlen (nm) - 4] = 0;
#endif #endif
name = init_str(); name = init_str();
nl = 0; nl = 0;
add_to_str(&name, &nl, nm); add_to_str(&name, &nl, nm);
free(nm); free(nm);
get_filename_from_url(url, &fn, &l); get_filename_from_url(url, &fn, &l);
fnnn = NULL; fnnn = NULL;
for (fnn = fn; fnn < fn + l; fnn++) if (*fnn == '.') fnnn = fnn; for (fnn = fn; fnn < fn + l; fnn++) if (*fnn == '.') fnnn = fnn;
if (fnnn) { if (fnnn) {
skipping to change at line 977 skipping to change at line 1033
msg_box(ses->term, getml(m2, w, w->url, w->pos, NULL), TEXT_(T_WARNING), AL_CENTER | AL_EXTD_TEXT, m1, " ", m2, "?", NULL, w, 3, TEXT_(T_YES), post_yes, B_ENTER, TEXT_(T_NO), post_no, 0, TEXT_(T_CANCEL), post_cancel, B_ESC); msg_box(ses->term, getml(m2, w, w->url, w->pos, NULL), TEXT_(T_WARNING), AL_CENTER | AL_EXTD_TEXT, m1, " ", m2, "?", NULL, w, 3, TEXT_(T_YES), post_yes, B_ENTER, TEXT_(T_NO), post_no, 0, TEXT_(T_CANCEL), post_cancel, B_ESC);
} }
int do_move(struct session *ses, struct status **stat) int do_move(struct session *ses, struct status **stat)
{ {
struct cache_entry *ce = NULL; struct cache_entry *ce = NULL;
if (!ses->loading_url) { if (!ses->loading_url) {
internal("no ses->loading_url"); internal("no ses->loading_url");
return 0; return 0;
} }
if (!(ce = (*stat)->ce) || (ses->wtd == WTD_IMGMAP && (*stat)->state >= 0 )) { if (!(ce = (*stat)->ce) || ((*stat)->state >= S_WAIT && (*stat)->state < S_TRANS) || (ses->wtd == WTD_IMGMAP && (*stat)->state >= 0)) {
return 0; return 0;
} }
if (ce->redirect && ses->redirect_cnt++ < MAX_REDIRECTS) { if (ce->redirect && ses->redirect_cnt++ < MAX_REDIRECTS) {
unsigned char *u, *p, *gp, *pos; unsigned char *u, *p, *gp, *pos;
int w = ses->wtd; int w = ses->wtd;
if (ses->wtd == WTD_BACK && (void *)cur_loc(ses)->next == &ses->h istory) if (ses->wtd == WTD_BACK && (void *)cur_loc(ses)->next == &ses->h istory)
goto b; goto b;
if (!(u = join_urls(ses->loading_url, ce->redirect))) goto b; if (!(u = join_urls(ses->loading_url, ce->redirect))) goto b;
if (!http_bugs.bug_302_redirect) if (!ce->redirect_get && (p = st rchr(ses->loading_url, POST_CHAR))) add_to_strn(&u, p); if (!http_bugs.bug_302_redirect) if (!ce->redirect_get && (p = st rchr(ses->loading_url, POST_CHAR))) add_to_strn(&u, p);
/* ^^^^ According to RFC2068 POST must not be redirected to GET, /* ^^^^ According to RFC2068 POST must not be redirected to GET,
skipping to change at line 1098 skipping to change at line 1154
struct f_data *ff = fd->f_data; struct f_data *ff = fd->f_data;
if (!ff || !ff->frame) return; if (!ff || !ff->frame) return;
request_frameset(ses, ff->frame_desc); request_frameset(ses, ff->frame_desc);
} }
void display_timer(struct session *ses) void display_timer(struct session *ses)
{ {
ttime t = get_time(); ttime t = get_time();
html_interpret(ses); html_interpret(ses);
draw_formatted(ses); draw_formatted(ses);
t = (get_time() - t) * DISPLAY_TIME; t = ((uttime)get_time() - (uttime)t) * DISPLAY_TIME;
if (t < DISPLAY_TIME_MIN) t = DISPLAY_TIME_MIN; if (t < DISPLAY_TIME_MIN) t = DISPLAY_TIME_MIN;
ses->display_timer = install_timer(t, (void (*)(void *))display_timer, se s); ses->display_timer = install_timer(t, (void (*)(void *))display_timer, se s);
load_frames(ses, ses->screen); load_frames(ses, ses->screen);
process_file_requests(ses); process_file_requests(ses);
} }
void end_load(struct status *stat, struct session *ses) void end_load(struct status *stat, struct session *ses)
{ {
int d; int d;
if (!ses->wtd) { if (!ses->wtd) {
skipping to change at line 1124 skipping to change at line 1180
if (d == 1) { if (d == 1) {
stat->end = (void (*)(struct status *, void *))doc_end_load; stat->end = (void (*)(struct status *, void *))doc_end_load;
display_timer(ses); display_timer(ses);
} }
if (stat->state < 0) { if (stat->state < 0) {
if (d != 2 && ses->wtd) { if (d != 2 && ses->wtd) {
free_wtd(ses); free_wtd(ses);
} }
if (d == 1) doc_end_load(stat, ses); if (d == 1) doc_end_load(stat, ses);
} }
if (stat->state < 0 && stat->state != S_OK && d != 2 && d != 1) { if (stat->state < 0 && stat->state != S__OK && d != 2 && d != 1) {
print_error_dialog(ses, stat, TEXT_(T_ERROR)); print_error_dialog(ses, stat, TEXT_(T_ERROR));
if (!d) reload(ses, NC_CACHE); if (!d) reload(ses, NC_CACHE);
} }
print_screen_status(ses); print_screen_status(ses);
} }
void doc_end_load(struct status *stat, struct session *ses) void doc_end_load(struct status *stat, struct session *ses)
{ {
if (stat->state < 0) { if (stat->state < 0) {
if (ses->display_timer != -1) kill_timer(ses->display_timer), ses ->display_timer = -1; if (ses->display_timer != -1) kill_timer(ses->display_timer), ses ->display_timer = -1;
html_interpret(ses); html_interpret(ses);
draw_formatted(ses); draw_formatted(ses);
load_frames(ses, ses->screen); load_frames(ses, ses->screen);
process_file_requests(ses); process_file_requests(ses);
if (stat->state != S_OK) print_error_dialog(ses, stat, TEXT_(T_ER if (stat->state != S__OK) print_error_dialog(ses, stat, TEXT_(T_E
ROR)); RROR));
#ifdef LINKS_TESTMODE_AUTO_EXIT
terminate_loop = 1;
#endif
} else if (ses->display_timer == -1) display_timer(ses); } else if (ses->display_timer == -1) display_timer(ses);
print_screen_status(ses); print_screen_status(ses);
} }
void file_end_load(struct status *stat, struct file_to_load *ftl) void file_end_load(struct status *stat, struct file_to_load *ftl)
{ {
if (ftl->stat.ce) { if (ftl->stat.ce) {
if (ftl->ce) ftl->ce->refcount--; if (ftl->ce) ftl->ce->refcount--;
(ftl->ce = ftl->stat.ce)->refcount++; (ftl->ce = ftl->stat.ce)->refcount++;
} }
skipping to change at line 1322 skipping to change at line 1381
struct session *s; struct session *s;
if (len < 2 * (int)sizeof(int)) return -1; if (len < 2 * (int)sizeof(int)) return -1;
cpfrom = *(int *)data; cpfrom = *(int *)data;
sz = *((int *)data + 1); sz = *((int *)data + 1);
foreach(s, sessions) if (s->id == cpfrom) { foreach(s, sessions) if (s->id == cpfrom) {
copy_session(s, ses); copy_session(s, ses);
break; break;
} }
if (sz) { if (sz) {
char *u, *uu; char *u, *uu;
if (len < 2 * (int)sizeof(int) + sz) return 0; if (len < 2 * (int)sizeof(int) + sz) return -1;
if ((unsigned)sz >= MAXINT) overalloc(); if ((unsigned)sz >= MAXINT) overalloc();
u = mem_alloc(sz + 1); u = mem_alloc(sz + 1);
memcpy(u, (int *)data + 2, sz); memcpy(u, (int *)data + 2, sz);
u[sz] = 0; u[sz] = 0;
uu = decode_url(u); uu = decode_url(u);
goto_url(ses, uu); goto_url(ses, uu);
mem_free(u); mem_free(u);
mem_free(uu); mem_free(uu);
} else if ((h = getenv("WWW_HOME")) && *h) goto_url(ses, h); } else if ((h = getenv("WWW_HOME")) && *h) goto_url(ses, h);
return 0; return 0;
skipping to change at line 1552 skipping to change at line 1611
switch ((int)ev->ev) { switch ((int)ev->ev) {
case EV_ABORT: case EV_ABORT:
if (ses) destroy_session(ses); if (ses) destroy_session(ses);
break; break;
case EV_INIT: case EV_INIT:
if (!(ses = win->data = create_session(win)) || if (!(ses = win->data = create_session(win)) ||
read_session_info(win->term->fdin, ses, (char *)ev->b + sizeof(int), *(int *)ev->b)) { read_session_info(win->term->fdin, ses, (char *)ev->b + sizeof(int), *(int *)ev->b)) {
register_bottom_half((void (*)(void *))destroy_te rminal, win->term); register_bottom_half((void (*)(void *))destroy_te rminal, win->term);
return; return;
} }
/*make_request(ses, 0);*/ /*-fallthrough*/
case EV_RESIZE: case EV_RESIZE:
html_interpret(ses); html_interpret(ses);
draw_formatted(ses); draw_formatted(ses);
load_frames(ses, ses->screen); load_frames(ses, ses->screen);
process_file_requests(ses); process_file_requests(ses);
print_screen_status(ses); print_screen_status(ses);
break; break;
case EV_REDRAW: case EV_REDRAW:
draw_formatted(ses); draw_formatted(ses);
print_screen_status(ses); print_screen_status(ses);
 End of changes. 44 change blocks. 
61 lines changed or deleted 119 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)