⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 session.c

📁 ELinks is an advanced and well-established feature-rich text mode web (HTTP/FTP/..) browser. ELinks
💻 C
📖 第 1 页 / 共 5 页
字号:
	if (wd) set_cwd(wd), mem_free(wd);	return h;}void increase_download_file(unsigned char **f){	unsigned char *p = NULL, *pp = *f;	unsigned char *q;	while ((pp = strstr(pp, ".part-"))) p = pp += 6;	if (!p || !*p) {		no_suffix:		add_to_strn(f, ".part-2");		return;	}	for (q = p; *q; q++) if (*q < '0' || *q > '9') goto no_suffix;	for (q--; q >= p; q--) {		if (*q < '9') {			(*q)++;			return;		}		*q = '0';	}	*p = '1';	add_to_strn(f, "0");}unsigned char *get_temp_name(unsigned char *url, unsigned char *head){	int nl;	unsigned char *name, *fn, *fnx;	unsigned char *nm;	unsigned char *directory = NULL;#ifdef WIN32	directory = getenv("TMP");	if (!directory) directory = getenv("TEMP");#endif	nm = tempnam(directory, "links");	if (!nm) return NULL;#ifdef OS2	if (strlen(nm) > 4 && !strcasecmp(nm + strlen(nm) - 4, ".tmp")) nm[strlen(nm) - 4] = 0;#endif	name = init_str();	nl = 0;	add_to_str(&name, &nl, nm);	free(nm);	fn = get_filename_from_url(url, head, 1);#ifndef OS2	fnx = strchr(fn, '.');#else	fnx = strrchr(fn, '.');#endif	if (fnx) {		unsigned char *s;#ifdef OS2		if (strlen(fnx) > 4) fnx[4] = 0;#endif		s = stracpy(fnx);		check_shell_security(&s);		add_to_str(&name, &nl, s);		mem_free(s);	}	mem_free(fn);	return name;}unsigned char *subst_file(unsigned char *prog, unsigned char *file, int cyg_subst){	unsigned char *n = init_str();	int l = 0;	while (*prog) {		int p;		for (p = 0; prog[p] && prog[p] != '%'; p++) ;		add_bytes_to_str(&n, &l, prog, p);		prog += p;		if (*prog == '%') {#if defined(HAVE_CYGWIN_CONV_TO_FULL_WIN32_PATH)			if (cyg_subst) {#ifdef MAX_PATH				unsigned char new_path[MAX_PATH];#else				unsigned char new_path[1024];#endif				cygwin_conv_to_full_win32_path(file, new_path);				add_to_str(&n, &l, new_path);			} else#endif			add_to_str(&n, &l, file);			prog++;		}	}	return n;}void start_download(struct session *ses, unsigned char *file){	struct download *down;	int h;	unsigned char *url = ses->dn_url;	if (!url) return;	kill_downloads_to_file(file, ses->term->cwd);	if ((h = create_download_file(ses, ses->term->cwd, file, 0, 0)) < 0) return;	down = mem_calloc(sizeof(struct download));	down->url = stracpy(url);	down->stat.end = (void (*)(struct status *, void *))download_data;	down->stat.data = down;	down->decompress = 0;	down->last_pos = 0;	down->file_shift = 0;	down->cwd = stracpy(ses->term->cwd);	down->orig_file = stracpy(file);	down->file = stracpy(file);	down->handle = h;	down->ses = ses;	down->remotetime = 0;	add_to_list(downloads, down);	load_url(url, NULL, &down->stat, PRI_DOWNLOAD, NC_CACHE);	display_download(ses->term, down, ses);}void abort_all_downloads(void){	while (!list_empty(downloads)) abort_download(downloads.next);}int f_is_finished(struct f_data *f){	struct additional_file *af;	if (!f || f->rq->state >= 0) return 0;	if (f->fd && f->fd->rq && f->fd->rq->state >= 0) return 0;	if (f->af) foreach(af, f->af->af) if (!af->rq || af->rq->state >= 0) return 0;	return 1;}int f_is_cacheable(struct f_data *f){	if (!f || f->rq->state >= 0) return 0;	if (f->fd && f->fd->rq && f->fd->rq->state >= 0) return 0;	return 1;}int f_need_reparse(struct f_data *f){	struct additional_file *af;	if (!f || f->rq->state >= 0) return 1;	if (f->af) foreach(af, f->af->af) if (af->need_reparse > 0) return 1;	return 0;}struct f_data *format_html(struct f_data_c *fd, struct object_request *rq, unsigned char *url, struct document_options *opt, int *cch){	struct f_data *f;	pr(	if (cch) *cch = 0;	if (!rq->ce || !(f = init_formatted(opt))) goto nul;	f->fd = fd;	f->ses = fd->ses;	f->time_to_get = -get_time();	clone_object(rq, &f->rq);	if (f->rq->ce) {		unsigned char *start; unsigned char *end;		int stl = -1;		struct additional_file *af;		if (fd->af) foreach(af, fd->af->af) if (af->need_reparse > 0) af->need_reparse = 0;		get_file(rq, &start, &end);		if (jsint_get_source(fd, &start, &end)) f->uncacheable = 1;		if (opt->plain == 2) {			start = init_str();			stl = 0;			add_to_str(&start, &stl, "<img src=\"");			add_to_str(&start, &stl, f->rq->ce->url);			add_to_str(&start, &stl, "\">");			end = start + stl;		}		really_format_html(f->rq->ce, start, end, f, fd->ses ? fd != fd->ses->screen : 0);		if (stl != -1) mem_free(start);		f->use_tag = f->rq->ce->count;		if (f->af) foreach(af, f->af->af) {			if (af->rq && af->rq->ce) {				af->use_tag = af->rq->ce->count;				af->use_tag2 = af->rq->ce->count2;			} else {				af->use_tag = 0;				af->use_tag2 = 0;			}		}	} else f->use_tag = 0;	f->time_to_get += get_time();	) nul:return NULL;	return f;}void count_frames(struct f_data_c *fd, int *i){	struct f_data_c *sub;	if (!fd) return;	if (fd->f_data) (*i)++;	foreach(sub, fd->subframes) count_frames(sub, i);}long formatted_info(int type){	int i = 0;	struct session *ses;	struct f_data *ce;	switch (type) {		case CI_FILES:			foreach(ses, sessions)				foreach(ce, ses->format_cache) i++;			/* fall through */		case CI_LOCKED:			foreach(ses, sessions)				count_frames(ses->screen, &i);			return i;		default:			internal("formatted_info: bad request");	}	return 0;}void f_data_attach(struct f_data_c *fd, struct f_data *f){	struct additional_file *af;	f->rq->upcall = (void (*)(struct object_request *, void *))fd_loaded;	f->rq->data = fd;	free_additional_files(&fd->af);	fd->af = f->af;	if (f->af) {		f->af->refcount++;		foreach(af, f->af->af) {			if (af->rq) {				af->rq->upcall = (void (*)(struct object_request *, void *))fd_loaded;				af->rq->data = fd;			} else {				request_object(fd->ses->term, af->url, f->rq->url, PRI_IMG, NC_CACHE, f->rq->upcall, f->rq->data, &af->rq);			}		}	}}void detach_f_data(struct f_data **ff){	struct f_data *f = *ff;	if (!f) return;#ifdef G	f->hlt_pos = -1;	f->hlt_len = 0;	f->start_highlight_x = -1;	f->start_highlight_y = -1;#endif	*ff = NULL;	if (f->frame_desc_link) {		destroy_formatted(f);		return;	}	f->fd = NULL;#ifdef G	f->locked_on = NULL;	free_list(f->image_refresh);#endif	if (f->uncacheable || !f_is_cacheable(f) || !f->ses) destroy_formatted(f);	else add_to_list(f->ses->format_cache, f);}static inline int is_format_cache_entry_uptodate(struct f_data *f){	struct cache_entry *ce = f->rq->ce;	struct additional_file *af;	if (!ce || ce->count != f->use_tag) return 0;	if (f->af) foreach(af, f->af->af) {		struct cache_entry *ce = af->rq ? af->rq->ce : NULL;		tcount tag = ce ? ce->count : 0;		tcount tag2 = ce ? ce->count2 : 0;		if (af->need_reparse > 0) if (tag != af->use_tag) return 0;		if (af->unknown_image_size) if (tag2 != af->use_tag2) return 0;	}	return 1;}int shrink_format_cache(int u){	static int sc = 0;	int scc;	int r = 0;	struct f_data *f;	int c = 0;	struct session *ses;	foreach(ses, sessions) foreach(f, ses->format_cache) {		if (u == SH_FREE_ALL || !is_format_cache_entry_uptodate(f)) {			struct f_data *ff = f;			f = f->prev;			del_from_list(ff);			destroy_formatted(ff);			r |= ST_SOMETHING_FREED;		} else c++;	}	if (u == SH_FREE_SOMETHING) c = max_format_cache_entries + 1;	if (c > max_format_cache_entries) {		a:		scc = sc++;		foreach (ses, sessions) if (!scc--) {			foreachback(f, ses->format_cache) {				struct f_data *ff = f;				f = f->next;				del_from_list(ff);				destroy_formatted(ff);				r |= ST_SOMETHING_FREED;				if (--c <= max_format_cache_entries) goto ret;			}			goto q;		}		sc = 0;		goto a;		q:;	}	ret:	return r | (!c) * ST_CACHE_EMPTY;}void init_fcache(void){	register_cache_upcall(shrink_format_cache, "format");}struct f_data *cached_format_html(struct f_data_c *fd, struct object_request *rq, unsigned char *url, struct document_options *opt, int *cch){	struct f_data *f;	/*if (F) opt->tables = 0;*/	if (fd->marginwidth != -1) {		int marg = (fd->marginwidth + G_HTML_MARGIN - 1) / G_HTML_MARGIN;		if (marg >= 0 && marg < 9) opt->margin = marg;	}	if (opt->plain == 2) opt->margin = 0, opt->display_images = 1;	pr(	if (!jsint_get_source(fd, NULL, NULL) && fd->ses) {		if (fd->f_data && !strcmp(fd->f_data->rq->url, url) && !compare_opt(&fd->f_data->opt, opt) && is_format_cache_entry_uptodate(fd->f_data)) {			xpr();			return fd->f_data;		}		foreach(f, fd->ses->format_cache) {			if (!strcmp(f->rq->url, url) && !compare_opt(&f->opt, opt)) {				if (!is_format_cache_entry_uptodate(f)) {					struct f_data *ff = f;					f = f->prev;					del_from_list(ff);					destroy_formatted(ff);					continue;				}				detach_f_data(&fd->f_data);				del_from_list(f);				f->fd = fd;				if (cch) *cch = 1;				f_data_attach(fd, f);				xpr();				return f;			}		}	}) {};	detach_f_data(&fd->f_data);	f = format_html(fd, rq, url, opt, cch);	if (f) f->fd = fd;	shrink_memory(SH_CHECK_QUOTA);	return f;}struct location *new_location(void);void create_new_frames(struct f_data_c *fd, struct frameset_desc *fs, struct document_options *o){	struct location *loc;	struct frame_desc *frm;	int c_loc;	int i;	int x, y;	int xp, yp;	i = 0;#ifdef JS	if (fd->onload_frameset_code)mem_free(fd->onload_frameset_code);	fd->onload_frameset_code=stracpy(fs->onload_code);#endif	foreach(loc, fd->loc->subframes) i++;	if (i != fs->n) {		while (!list_empty(fd->loc->subframes)) destroy_location(fd->loc->subframes.next);		c_loc = 1;	} else {		c_loc = 0;		loc = fd->loc->subframes.next;	}	yp = fd->yp;	frm = &fs->f[0];	for (y = 0; y < fs->y; y++) {		xp = fd->xp;		for (x = 0; x < fs->x; x++) {			struct f_data_c *nfdc;			if (!(nfdc = create_f_data_c(fd->ses, fd))) return;			if (c_loc) {				struct list_head *l = (struct list_head *)fd->loc->subframes.prev;				loc = new_location();				add_to_list(*l, loc);				loc->parent = fd->loc;				loc->name = stracpy(frm->name);				if ((loc->url = stracpy(frm->url)))					nfdc->goto_position = extract_position(loc->url);			}			nfdc->xp = xp; nfdc->yp = yp;			nfdc->xw = frm->xw;			nfdc->yw = frm->yw;			nfdc->scrolling = frm->scrolling;			nfdc->loc = loc;			nfdc->vs = loc->vs;			if (frm->marginwidth != -1) nfdc->marginwidth = frm->marginwidth;			else nfdc->marginwidth = fd->marginwidth;			if (frm->marginheight != -1) nfdc->marginheight = frm->marginheight;			else nfdc->marginheight = fd->marginheight;			/*debug("frame: %d %d, %d %d\n", nfdc->xp, nfdc->yp, nfdc->xw, nfdc->yw);*/			{				struct list_head *l = (struct list_head *)fd->subframes.prev;				add_to_list(*l, nfdc);			}			if (frm->subframe) {				create_new_frames(nfdc, frm->subframe, o);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -