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

📄 session.c

📁 ELinks is an advanced and well-established feature-rich text mode web (HTTP/FTP/..) browser. ELinks
💻 C
📖 第 1 页 / 共 5 页
字号:
			z.next_in = (unsigned char *)z.next_in + headlen;			z.avail_in -= headlen;			skip_gzip_header = 0;		}		r = inflate(&z, (void *)f->next == (void *)&ce->frag ? Z_SYNC_FLUSH : Z_NO_FLUSH);		switch (r) {			case Z_OK:		break;			case Z_BUF_ERROR:	break;			case Z_STREAM_END:	r = inflateEnd(&z);						if (r != Z_OK) goto end_failed;						r = inflateInit2(&z, old_zlib ? -15 : defl ? 15 : 15 + 16);						if (r != Z_OK) {							old_zlib = 0;							goto init_failed;						}						if (old_zlib) {							skip_gzip_header = 2;						}						break;			case Z_NEED_DICT:			case Z_DATA_ERROR:	if (defl == 1) {							defl = 2;							r = inflateEnd(&z);							if (r != Z_OK) goto end_failed;							goto init_again;						}						decompress_error(term, ce, "zlib", z.msg ? (unsigned char *)z.msg : TEXT(T_COMPRESSED_ERROR), errp);						err = 1;						goto finish;			case Z_STREAM_ERROR:	decompress_error(term, ce, "zlib", z.msg ? (unsigned char *)z.msg : (unsigned char *)"Internal error on inflate", errp);						err = 1;						goto finish;			case Z_MEM_ERROR:	decompress_error(term, ce, "zlib", z.msg ? (unsigned char *)z.msg : TEXT(T_OUT_OF_MEMORY), errp);						err = 1;						goto finish;			default:		decompress_error(term, ce, "zlib", z.msg ? (unsigned char *)z.msg : (unsigned char *)"Unknown return value on inflate", errp);						err = 1;						break;		}		if (!z.avail_out) {			p = mem_realloc(p, size + DECODE_STEP);			z.next_out = p + size;			z.avail_out = DECODE_STEP;			size += DECODE_STEP;		}		if (z.avail_in) goto repeat_frag;		/* In zlib 1.1.3, inflate(Z_SYNC_FLUSH) doesn't work.		   The following line fixes it --- for last fragment, loop until		   we get an eof. */		if (r == Z_OK && (void *)f->next == (void *)&ce->frag) goto repeat_frag;		/*{			static int x = 0;			if (++x < 100) goto repeat_frag;			x = 0;		}*/		offset += f->length;	}	finish:	r = inflateEnd(&z);	end_failed:	switch (r) {		case Z_OK:		break;		case Z_STREAM_ERROR:	decompress_error(term, ce, "zlib", z.msg ? (unsigned char *)z.msg : (unsigned char *)"Internal error on inflateEnd", errp);					err = 1;					break;		default:		decompress_error(term, ce, "zlib", z.msg ? (unsigned char *)z.msg : (unsigned char *)"Unknown return value on inflateEnd", errp);					err = 1;					break;	}	after_inflateend:	if (err && (unsigned char *)z.next_out == p) {		mem_free(p);		return 1;	}	*p_start = p;	*p_len = (unsigned char *)z.next_out - (unsigned char *)p;	return 0;}#endif#ifdef HAVE_BZIP2#include <bzlib.h>static int decode_bzip2(struct terminal *term, struct cache_entry *ce, unsigned char **p_start, size_t *p_len, int *errp){	int err = 0;	bz_stream z;	off_t offset;	int r;	unsigned char *p;	struct fragment *f;	size_t size = ce->length > 0 ? (ce->length + DECODE_STEP - 1) & ~(size_t)(DECODE_STEP - 1) : DECODE_STEP;	p = mem_alloc(size);	memset(&z, 0, sizeof z);	z.next_in = NULL;	z.avail_in = 0;	z.next_out = p;	z.avail_out = size;	z.bzalloc = NULL;	z.bzfree = NULL;	z.opaque = NULL;	r = BZ2_bzDecompressInit(&z, 0, 0);	init_failed:	switch (r) {		case BZ_OK:		break;		case BZ_MEM_ERROR:	decompress_error(term, ce, "bzip2", TEXT(T_OUT_OF_MEMORY), errp);					err = 1;					goto after_inflateend;		case BZ_PARAM_ERROR:						decompress_error(term, ce, "bzip2", "Invalid parameter", errp);					err = 1;					goto after_inflateend;		case BZ_CONFIG_ERROR:	decompress_error(term, ce, "bzip2", "Bzlib is miscompiled", errp);					err = 1;					goto after_inflateend;		default:		decompress_error(term, ce, "bzip2", "Unknown return value on BZ2_bzDecompressInit", errp);					err = 1;					goto after_inflateend;	}	offset = 0;	foreach(f, ce->frag) {		if (f->offset != offset) break;		z.next_in = f->data;		z.avail_in = f->length;		repeat_frag:		r = BZ2_bzDecompress(&z);		switch (r) {			case BZ_OK:		break;			case BZ_STREAM_END:						r = BZ2_bzDecompressEnd(&z);						if (r != BZ_OK) goto end_failed;						r = BZ2_bzDecompressInit(&z, 0, 0);						if (r != BZ_OK) goto init_failed;						break;			case BZ_DATA_ERROR_MAGIC:			case BZ_DATA_ERROR:	decompress_error(term, ce, "bzip2", TEXT(T_COMPRESSED_ERROR), errp);						err = 1;						goto finish;			case BZ_PARAM_ERROR:	decompress_error(term, ce, "bzip2", "Internal error on BZ2_bzDecompress", errp);						err = 1;						goto finish;			case BZ_MEM_ERROR:	decompress_error(term, ce, "bzip2", TEXT(T_OUT_OF_MEMORY), errp);						err = 1;						goto finish;			default:		decompress_error(term, ce, "bzip2", "Unknown return value on BZ2_bzDecompress", errp);						err = 1;						break;		}		if (!z.avail_out) {			p = mem_realloc(p, size + DECODE_STEP);			z.next_out = p + size;			z.avail_out = DECODE_STEP;			size += DECODE_STEP;		}		if (z.avail_in) goto repeat_frag;		offset += f->length;	}	finish:	r = BZ2_bzDecompressEnd(&z);	end_failed:	switch (r) {		case BZ_OK:		break;		case BZ_PARAM_ERROR:	decompress_error(term, ce, "bzip2", "Internal error on BZ2_bzDecompressEnd", errp);					err = 1;					break;		default:		decompress_error(term, ce, "bzip2", "Unknown return value on BZ2_bzDecompressEnd", errp);					err = 1;					break;	}	after_inflateend:	if (err && (unsigned char *)z.next_out == p) {		mem_free(p);		return 1;	}	*p_start = p;	*p_len = (unsigned char *)z.next_out - (unsigned char *)p;	return 0;}#endifint get_file_by_term(struct terminal *term, struct cache_entry *ce, unsigned char **start, unsigned char **end, int *errp){	unsigned char *enc;	struct fragment *fr;	if (errp) *errp = 0;	*start = *end = NULL;	if (!ce) return 1;	if (ce->decompressed) {		return_decompressed:		*start = ce->decompressed;		*end = ce->decompressed + ce->decompressed_len;		return 0;	}	enc = get_content_encoding(ce->head, ce->url);	if (enc) {#ifdef HAVE_ZLIB		if (!strcasecmp(enc, "gzip") || !strcasecmp(enc, "x-gzip") || !strcasecmp(enc, "deflate")) {			int defl = !strcasecmp(enc, "deflate");			mem_free(enc);			if (decode_gzip(term, ce, &ce->decompressed, &ce->decompressed_len, defl, errp)) goto uncompressed;			goto return_decompressed;		}#endif#ifdef HAVE_BZIP2		if (!strcasecmp(enc, "bzip2")) {			mem_free(enc);			if (decode_bzip2(term, ce, &ce->decompressed, &ce->decompressed_len, errp)) goto uncompressed;			goto return_decompressed;		}#endif		mem_free(enc);		goto uncompressed;	}	uncompressed:	defrag_entry(ce);	fr = ce->frag.next;	if ((void *)fr == &ce->frag || fr->offset || !fr->length) return 1;	*start = fr->data, *end = fr->data + fr->length;	return 0;}int get_file(struct object_request *o, unsigned char **start, unsigned char **end){	struct terminal *term;	*start = *end = NULL;	if (!o) return 1;	foreach(term, terminals) if (o->term == term->count) goto ok;	term = NULL;	ok:	return get_file_by_term(term, o->ce, start, end, NULL);}void refresh_timer(struct f_data_c *fd){	if (fd->ses->rq) {		fd->refresh_timer = install_timer(500, (void (*)(void *))refresh_timer, fd);		return;	}	fd->refresh_timer = -1;	if (fd->f_data && fd->f_data->refresh) {		fd->refresh_timer = install_timer(fd->f_data->refresh_seconds * 1000, (void (*)(void *))refresh_timer, fd);		goto_url_f(fd->ses, NULL, fd->f_data->refresh, "_self", fd, -1, 0, 0, 1);	}}#ifdef JSstatic int frame_and_all_subframes_loaded(struct f_data_c *fd){	struct f_data_c *f;	int loaded=fd->done||fd->rq==NULL;	if (loaded)		/* this frame is loaded */		foreach(f,fd->subframes)		{			loaded=frame_and_all_subframes_loaded(f);			if (!loaded)break;		}	return loaded;}#endifvoid fd_loaded(struct object_request *rq, struct f_data_c *fd){	if (fd->done) {		if (f_is_finished(fd->f_data)) goto priint;		else fd->done = 0, fd->parsed_done = 1;	}	if (fd->parsed_done && f_need_reparse(fd->f_data)) fd->parsed_done = 0;	if (fd->vs->plain == -1 && rq->state != O_WAITING) {		fd->vs->plain = plain_type(fd->ses, fd->rq, NULL);	}	if (fd->rq->state < 0 && (f_is_finished(fd->f_data) || !fd->f_data)) {		if (!fd->parsed_done) {			html_interpret(fd);			if (fd->went_to_position) {				if (!fd->goto_position) fd->goto_position = fd->went_to_position, fd->went_to_position = NULL;				else mem_free(fd->went_to_position), fd->went_to_position = NULL;			}		}		draw_fd(fd);		/* it may happen that html_interpret requests load of additional file */		if (!f_is_finished(fd->f_data)) goto more_data;		fn:		if (fd->f_data->are_there_scripts) {			jsint_scan_script_tags(fd);			if (!f_is_finished(fd->f_data)) goto more_data;		}		fd->done = 1;		fd->parsed_done = 0;		if (fd->f_data->refresh) {			if (fd->refresh_timer != -1) kill_timer(fd->refresh_timer);			fd->refresh_timer = install_timer(fd->f_data->refresh_seconds * 1000, (void (*)(void *))refresh_timer, fd);		}#ifdef JS		jsint_run_queue(fd);#endif	} else more_data: if (get_time() >= fd->next_update) {		ttime t;		int first = !fd->f_data;		if (!fd->parsed_done) {			html_interpret(fd);			if (fd->rq->state < 0 && !f_need_reparse(fd->f_data)) {				if (fd->went_to_position) {					if (!fd->goto_position) fd->goto_position = fd->went_to_position, fd->went_to_position = NULL;					else mem_free(fd->went_to_position), fd->went_to_position = NULL;				}				fd->parsed_done = 1;			}		}		draw_fd(fd);		if (fd->rq->state < 0 && f_is_finished(fd->f_data)) goto fn;		t = fd->f_data ? ((fd->parsed_done ? 0 : fd->f_data->time_to_get * DISPLAY_TIME) + fd->f_data->time_to_draw * IMG_DISPLAY_TIME) : 0;		if (t < DISPLAY_TIME_MIN) t = DISPLAY_TIME_MIN;		if (first && t > DISPLAY_TIME_MAX_FIRST) t = DISPLAY_TIME_MAX_FIRST;		fd->next_update = get_time() + t;	} else {		change_screen_status(fd->ses);		print_screen_status(fd->ses);	}	priint:	/* process onload handler of a frameset */#ifdef JS	{		int all_loaded;		/* go to parent and test if all subframes are loaded, if yes, call onload handler */		if (!fd->parent) goto hell;	/* this frame has no parent, skip */		if (!fd->parent->onload_frameset_code)goto hell;	/* no onload handler, skip all this */		all_loaded=frame_and_all_subframes_loaded(fd->parent);		if (!all_loaded) goto hell;		/* parent has all subframes loaded */		jsint_execute_code(fd->parent,fd->parent->onload_frameset_code,strlen(fd->parent->onload_frameset_code),-1,-1,-1, NULL);		mem_free(fd->parent->onload_frameset_code), fd->parent->onload_frameset_code=NULL;	hell:;	}#endif	if (rq && (rq->state == O_FAILED || rq->state == O_INCOMPLETE) && (fd->rq == rq || fd->ses->rq == rq)) print_error_dialog(fd->ses, &rq->stat, rq->url);}struct location *new_location(void){	struct location *loc;	loc = mem_calloc(sizeof(struct location));	init_list(loc->subframes);	loc->vs = create_vs();	return loc;}static inline struct location *alloc_ses_location(struct session *ses){	struct location *loc;	if (!(loc = new_location())) return NULL;	add_to_list(ses->history, loc);	return loc;}void subst_location(struct f_data_c *fd, struct location *old, struct location *new){	struct f_data_c *f;	foreach(f, fd->subframes) subst_location(f, old, new);	if (fd->loc == old) fd->loc = new;}struct location *copy_sublocations(struct session *ses, struct location *d, struct location *s, struct location *x){	struct location *dl, *sl, *y, *z;	d->name = stracpy(s->name);	if (s == x) return d;	d->url = stracpy(s->url);	d->prev_url = stracpy(s->prev_url);	destroy_vs(d->vs);	d->vs = s->vs; s->vs->refcount++;	subst_location(ses->screen, s, d);	y = NULL;	foreach(sl, s->subframes) {		if ((dl = new_location())) {			struct list_head *l = (struct list_head *)d->subframes.prev;			add_to_list(*l, dl);			dl->parent = d;			z = copy_sublocations(ses, dl, sl, x);			if (z && y) internal("copy_sublocations: crossed references");			if (z) y = z;		}	}	return y;}struct location *copy_location(struct session *ses, struct location *loc){	struct location *l2, *l1, *nl;	l1 = cur_loc(ses);	if (!(l2 = alloc_ses_location(ses))) return NULL;	if (!(nl = copy_sublocations(ses, l2, l1, loc))) internal("copy_location: sublocation not found");	return nl;}struct f_data_c *new_main_location(struct session *ses){	struct location *loc;	if (!(loc = alloc_ses_location(ses))) return NULL;	reinit_f_data_c(ses->screen);	ses->screen->loc = loc;	ses->screen->vs = loc->vs;	if (ses->wanted_framename) loc->name=ses->wanted_framename, ses->wanted_framename=NULL;	return ses->screen;}struct f_data_c *copy_location_and_replace_frame(struct session *ses, struct f_data_c *fd){	struct location *loc;	if (!(loc = copy_location(ses, fd->loc))) return NULL;	reinit_f_data_c(fd);	fd->loc = loc;	fd->vs = loc->vs;	return fd;}/* vrati frame prislusici danemu targetu   pokud takovy frame nenajde, vraci NULL */struct f_data_c *find_frame(struct session *ses, unsigned char *target, s

⌨️ 快捷键说明

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