Exemplo n.º 1
0
void
html_embed(struct html_context *html_context, unsigned char *a,
           unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5)
{
	unsigned char *type, *extension;
	unsigned char *object_src;

	/* This is just some dirty wrapper. We emulate various things through
	 * this, which is anyway in the spirit of <object> element, unifying
	 * <img> and <iframe> etc. */

	object_src = get_url_val(a, (unsigned char *)"src", html_context->doc_cp);
	if (!object_src || !*object_src) {
		mem_free_set(&object_src, NULL);
		return;
	}

	/* If there is no extension we want to get the default mime/type
	 * anyway? */
	extension = (unsigned char *)strrchr((char *)object_src, '.');
	if (!extension) extension = object_src;

	type = get_extension_content_type(extension);
	if (type && !c_strncasecmp((const char *)type, "image/", 6)) {
		html_img_do(a, object_src, html_context);
	} else {
		/* We will just emulate <iframe>. */
		html_iframe_do(a, object_src, html_context);
	}

	mem_free_if(type);
	mem_free_set(&object_src, NULL);
}
Exemplo n.º 2
0
static inline void
do_script_hook_get_proxy(unsigned char **new_proxy_url, unsigned char *url)
{
	int count;
	dSP;	/* Keep in variables declaration block. */

	ENTER;
	SAVETMPS;

	PUSHMARK(SP);
	my_XPUSHs(url, strlen((const char *)url));
	PUTBACK;

	count = call_pv("proxy_for_hook", G_EVAL | G_SCALAR);
	if (SvTRUE(ERRSV)) count = 0;	/* FIXME: error message ? */
	SPAGAIN;
	if (count == 1) {
		if (TOPs == &PL_sv_undef) {
			(void) POPs;
			mem_free_set(new_proxy_url, NULL);
		} else {
#ifndef CONFIG_PERL_POPPX_WITHOUT_N_A
			STRLEN n_a; /* Used by POPpx macro. */
#endif
			unsigned char *new_url = POPpx;

			mem_free_set(new_proxy_url, stracpy(new_url));
		}
	}

	PUTBACK;
	FREETMPS;
	LEAVE;
}
Exemplo n.º 3
0
Arquivo: task.c Projeto: ezc/elinks
/** If @a loaded_in_frame is set, this was called just to indicate a move inside
 * a frameset, and we basically just reset the appropriate frame's view_state in
 * that case. When clicking on a link inside a frame, the frame URI is somehow
 * updated and added to the files-to-load queue, then ses_forward() is called
 * with @a loaded_in_frame unset, duplicating the whole frameset's location,
 * then later the file-to-load callback calls it for the particular frame with
 * @a loaded_in_frame set. */
struct view_state *
ses_forward(struct session *ses, int loaded_in_frame)
{
	struct location *loc = NULL;
	struct view_state *vs;

	if (!loaded_in_frame) {
		free_files(ses);
		mem_free_set(&ses->search_word, NULL);
	}

x:
	if (!loaded_in_frame) {
		loc = mem_calloc(1, sizeof(*loc));
		if (!loc) return NULL;
		copy_struct(&loc->download, &ses->loading);
	}

	if (ses->task.target.frame && *ses->task.target.frame) {
		struct frame *frame;

		assertm(have_location(ses), "no location yet");
		if_assert_failed return NULL;

		if (!loaded_in_frame) {
			copy_location(loc, cur_loc(ses));
			add_to_history(&ses->history, loc);
		}

		frame = ses_find_frame(ses, ses->task.target.frame);
		if (!frame) {
			if (!loaded_in_frame) {
				del_from_history(&ses->history, loc);
				destroy_location(loc);
			}
			mem_free_set(&ses->task.target.frame, NULL);
			goto x;
		}

		vs = &frame->vs;
		if (!loaded_in_frame) {
			destroy_vs(vs, 1);
			init_vs(vs, ses->loading_uri, vs->plain);
		} else {
			done_uri(vs->uri);
			vs->uri = get_uri_reference(ses->loading_uri);
			if (vs->doc_view) {
				/* vs->doc_view itself will get detached in
				 * render_document_frames(), but that's too
				 * late for us. */
				vs->doc_view->vs = NULL;
				vs->doc_view = NULL;
			}
#ifdef CONFIG_ECMASCRIPT
			vs->ecmascript_fragile = 1;
#endif
		}

	} else {
Exemplo n.º 4
0
void
html_a(struct html_context *html_context, unsigned char *a,
       unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5)
{
	unsigned char *href;

	href = get_url_val(a, (unsigned char *)"href", html_context->doc_cp);
	if (href) {
		unsigned char *target;

		mem_free_set(&format.link,
			     join_urls(html_context->base_href,
				       trim_chars(href, ' ', 0)));

		mem_free(href);

		target = get_target(html_context->options, a);
		if (target) {
			mem_free_set(&format.target, target);
		} else {
			mem_free_set(&format.target, stracpy(html_context->base_target));
		}

		if (0) {
			; /* Shut up compiler */
#ifdef CONFIG_GLOBHIST
		} else if (get_global_history_item(format.link)) {
			format.style.color.foreground = format.color.vlink;
			html_top->pseudo_class &= ~ELEMENT_LINK;
			html_top->pseudo_class |= ELEMENT_VISITED;
#endif
#ifdef CONFIG_BOOKMARKS
		} else if (get_bookmark(format.link)) {
			format.style.color.foreground = format.color.bookmark_link;
			html_top->pseudo_class &= ~ELEMENT_VISITED;
			/* XXX: Really set ELEMENT_LINK? --pasky */
			html_top->pseudo_class |= ELEMENT_LINK;
#endif
		} else {
			format.style.color.foreground = format.color.clink;
			html_top->pseudo_class &= ~ELEMENT_VISITED;
			html_top->pseudo_class |= ELEMENT_LINK;
		}

		mem_free_set(&format.title,
		             get_attr_val(a, (unsigned char *)"title", html_context->doc_cp));

		html_focusable(html_context, a);

	} else {
		pop_html_element(html_context);
	}

	set_fragment_identifier(html_context, a, (unsigned char *)"name");
}
Exemplo n.º 5
0
/* @smjs_globhist_item_class.setProperty */
static JSBool
smjs_globhist_item_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
{
	struct global_history_item *history_item;

	/* This can be called if @obj if not itself an instance of the
	 * appropriate class but has one in its prototype chain.  Fail
	 * such calls.  */
	if (!JS_InstanceOf(ctx, obj, (JSClass *) &smjs_globhist_item_class, NULL))
		return JS_FALSE;

	history_item = JS_GetInstancePrivate(ctx, obj,
					     (JSClass *) &smjs_globhist_item_class,
					     NULL);

	if (!history_item) return JS_FALSE;

	if (!JSID_IS_INT(id))
		return JS_FALSE;

	switch (JSID_TO_INT(id)) {
	case GLOBHIST_TITLE: {
		JSString *jsstr = JS_ValueToString(smjs_ctx, *vp);
		unsigned char *str = JS_EncodeString(smjs_ctx, jsstr);

		mem_free_set(&history_item->title, stracpy(str));

		return JS_TRUE;
	}
	case GLOBHIST_URL: {
		JSString *jsstr = JS_ValueToString(smjs_ctx, *vp);
		unsigned char *str = JS_EncodeString(smjs_ctx, jsstr);

		mem_free_set(&history_item->url, stracpy(str));

		return JS_TRUE;
	}
	case GLOBHIST_LAST_VISIT: {
		uint32 seconds;

		/* Bug 923: Assumes time_t values fit in uint32.  */
		JS_ValueToECMAUint32(smjs_ctx, *vp, &seconds);
		history_item->last_visit = seconds;

		return JS_TRUE;
	}
	default:
		/* Unrecognized integer property ID; someone is using
		 * the object as an array.  SMJS builtin classes (e.g.
		 * js_RegExpClass) just return JS_TRUE in this case.
		 * Do the same here.  */
		return JS_TRUE;
	}
}
Exemplo n.º 6
0
static struct connection_state
init_nntp_header(struct connection *conn, struct read_buffer *rb)
{
	struct nntp_connection_info *nntp = conn->info;

	if (!conn->cached) {
		conn->cached = get_cache_entry(conn->uri);
		if (!conn->cached) return connection_state(S_OUT_OF_MEM);

	} else if (conn->cached->head || conn->cached->content_type) {
		/* If the head is set wipe out the content to be sure */
		delete_entry_content(conn->cached);
		mem_free_set(&conn->cached->head, NULL);
	}

	/* XXX: Override any Content-Type line in the header */
	mem_free_set(&conn->cached->content_type, stracpy("text/html"));
	if (!conn->cached->content_type)
		return connection_state(S_OUT_OF_MEM);

	switch (nntp->target) {
	case NNTP_TARGET_ARTICLE_NUMBER:
	case NNTP_TARGET_MESSAGE_ID:
	case NNTP_TARGET_GROUP_MESSAGE_ID:
	{
		unsigned char *end;

		end = get_nntp_message_header_end(rb->data, rb->length);
		if (!end) {
			/* Redo the whole cache entry thing next time */
			return connection_state(S_TRANS);
		}

		/* FIXME: Add the NNTP response code line */
		conn->cached->head = stracpy("FIXME NNTP response code\r\n");
		if (!conn->cached->head) return connection_state(S_OUT_OF_MEM);

		add_to_strn(&conn->cached->head, rb->data);

		/* ... and remove it */
		conn->received += end - rb->data;
		kill_buffer_data(rb, end - rb->data);
		break;
	}
	case NNTP_TARGET_ARTICLE_RANGE:
	case NNTP_TARGET_GROUP:
	case NNTP_TARGET_GROUPS:
	case NNTP_TARGET_QUIT:
		break;
	}

	return connection_state(S_OK);
}
Exemplo n.º 7
0
static inline void
do_script_hook_follow_url(unsigned char **url)
{
	int count;
	dSP;	/* Keep in variables declaration block. */

	ENTER;
	SAVETMPS;

	PUSHMARK(SP);
	my_XPUSHs(*url, strlen((const char *)*url));
	PUTBACK;

	count = call_pv("follow_url_hook", G_EVAL | G_SCALAR);
	if (SvTRUE(ERRSV)) count = 0;	/* FIXME: error message ? */
	SPAGAIN;
	if (count == 1) {
#ifndef CONFIG_PERL_POPPX_WITHOUT_N_A
		STRLEN n_a;	/* Used by POPpx macro. */
#endif
		unsigned char *new_url = POPpx;

		if (new_url) {
			unsigned char *n = stracpy(new_url);

			if (n) {
				mem_free_set(url, n);
			}
		}
	}

	PUTBACK;
	FREETMPS;
	LEAVE;
}
Exemplo n.º 8
0
void
about_protocol_handler(struct connection *conn)
{
	struct cache_entry *cached = get_cache_entry(conn->uri);

	/* Only do this the first time */
	if (cached && !cached->content_type) {
#ifndef CONFIG_SMALL
		{
			const struct about_page *page = about_pages;

			for (; page->name; page++) {
				int len;
				unsigned char *str;

				if (strcmp(conn->uri->data, page->name))
					continue;

				str = page->string;
				len = strlen(str);
				add_fragment(cached, 0, str, len);
				conn->from = len;
				break;
			}
		}
#endif

		/* Set content to known type */
		mem_free_set(&cached->content_type, stracpy("text/html"));
	}

	conn->cached = cached;
	abort_connection(conn, connection_state(S_OK));
}
Exemplo n.º 9
0
Arquivo: link.c Projeto: rkd77/felinks
void
html_source(struct html_context *html_context, unsigned char *a,
           unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5)
{
	unsigned char *src, *title;
	struct document_options *options = html_context->options;
	int display_style = options->image_link.display_style;

	src = get_url_val(a, "src", html_context->doc_cp);
	if (!src) return;

	title = get_attr_val(a, "title", html_context->doc_cp);
	if (!title || !*title) {
		if (display_style == 3) {
			mem_free_set(&title, get_image_filename_from_src(options->image_link.filename_maxlen, src));
		}
	}

	html_focusable(html_context, a);

	if (title && *title) {
		put_link_line("Source: ", title, src,
			      html_context->options->framename, html_context);
	} else {
		put_link_line("", "Source", src,
			      html_context->options->framename, html_context);
	}

	mem_free_if(title);
	mem_free(src);
}
Exemplo n.º 10
0
/** Convert a jsval to a string and store it in struct bookmark.
 *
 * @param ctx
 *   Context for memory allocations and error reports.
 * @param val
 *   The @c jsval that should be converted.
 * @param[in,out] result
 *   A string allocated with mem_alloc().
 *   On success, this function frees the original string, if any.
 *
 * @return JS_TRUE if successful.  On error, report the error to
 * SpiderMonkey and return JS_FALSE.  */
static JSBool
jsval_to_bookmark_string(JSContext *ctx, jsid id, unsigned char **result)
{
	JSString *jsstr = NULL;
	unsigned char *str;
	jsval val;

	/* jsstring_to_utf8() might GC; protect the string to come.  */
	if (!JS_AddNamedStringRoot(ctx, &jsstr, "jsval_to_bookmark_string"))
		return JS_FALSE;

	if (JS_TRUE != JS_IdToValue(ctx, id, &val)) {
		JS_RemoveStringRoot(ctx, &jsstr);
		return JS_FALSE;
	}

	jsstr = JS_ValueToString(ctx, val);
	if (jsstr == NULL) {
		JS_RemoveStringRoot(ctx, &jsstr);
		return JS_FALSE;
	}

	str = jsstring_to_utf8(ctx, jsstr, NULL);
	if (str == NULL) {
		JS_RemoveStringRoot(ctx, &jsstr);
		return JS_FALSE;
	}

	JS_RemoveStringRoot(ctx, &jsstr);
	mem_free_set(result, str);
	return JS_TRUE;
}
Exemplo n.º 11
0
void
html_hr(struct html_context *html_context, unsigned char *a,
        unsigned char *html, unsigned char *eof, unsigned char **end)
{
	int i/* = par_format.width - 10*/;
	unsigned char r = (unsigned char) BORDER_DHLINE;
	int q = get_num(a, (unsigned char *)"size", html_context->doc_cp);

	if (q >= 0 && q < 2) r = (unsigned char) BORDER_SHLINE;
	html_stack_dup(html_context, ELEMENT_KILLABLE);
	par_format.align = ALIGN_CENTER;
	mem_free_set(&format.link, NULL);
	format.form = NULL;
	html_linebrk(html_context, a, html, eof, end);
	if (par_format.align == ALIGN_JUSTIFY) par_format.align = ALIGN_CENTER;
	par_format.leftmargin = par_format.rightmargin = html_context->margin;

	i = get_width(a, (unsigned char *)"width", 1, html_context);
	if (i == -1) i = get_html_max_width();
	format.style.attr = AT_GRAPHICS;
	html_context->special_f(html_context, SP_NOWRAP, 1);
	while (i-- > 0) {
		put_chrs(html_context, &r, 1);
	}
	html_context->special_f(html_context, SP_NOWRAP, 0);
	ln_break(html_context, 2);
	pop_html_element(html_context);
}
Exemplo n.º 12
0
void
done_socket(struct socket *socket)
{
	struct socket_weak_ref *ref;

	close_socket(socket);

	if (socket->connect_info)
		done_connection_info(socket);

	mem_free_set(&socket->read_buffer, NULL);
	mem_free_set(&socket->write_buffer, NULL);

	foreach(ref, socket_weak_refs) {
		if (ref->socket == socket)
			ref->socket = NULL;
	}
}
Exemplo n.º 13
0
static void
free_mark_by_index(int i)
{
	assert(is_valid_mark_index(i));

	if (!marks[i]) return;

	destroy_vs(marks[i], 1);
	mem_free_set(&marks[i], NULL);
}
Exemplo n.º 14
0
static widget_handler_status_T
set_cookie_domain(struct dialog_data *dlg_data, struct widget_data *widget_data)
{
    struct cookie *cookie = (struct cookie *)dlg_data->dlg->udata;
    unsigned char *value = widget_data->cdata;

    if (!value || !cookie) return EVENT_NOT_PROCESSED;
    mem_free_set(&cookie->domain, stracpy(value));
    set_cookies_dirty();
    return EVENT_PROCESSED;
}
Exemplo n.º 15
0
void
data_protocol_handler(struct connection *conn)
{
	struct uri *uri = conn->uri;
	struct cache_entry *cached = get_cache_entry(uri);
	unsigned char *data_start, *data;
	int base64 = 0;

	if (!cached) {
		abort_connection(conn, connection_state(S_OUT_OF_MEM));
		return;
	}

	conn->cached = cached;

	data_start = parse_data_protocol_header(conn, &base64);
	if (!data_start) {
		abort_connection(conn, connection_state(S_OUT_OF_MEM));
		return;
	}

	/* Allocate the data string because URI decoding will possibly modify
	 * it. */
	data = memacpy(data_start, uri->datalen - (data_start - uri->data));
	if (!data) {
		abort_connection(conn, connection_state(S_OUT_OF_MEM));
		return;
	}

	if (base64) {
		unsigned char *decoded = base64_encode(data);

		if (!decoded) {
			abort_connection(conn, connection_state(S_OUT_OF_MEM));
			return;
		}

		mem_free_set(&data, decoded);
	} else {
		decode_uri(data);
	}

	{
		/* Use strlen() to get the correct decoded length */
		int datalen = strlen((const char *)data);

		add_fragment(cached, conn->from, data, datalen);
		conn->from += datalen;
	}

	mem_free(data);

	abort_connection(conn, connection_state(S_OK));
}
Exemplo n.º 16
0
static void
done_connection_info(struct socket *socket)
{
	struct connect_info *connect_info = socket->connect_info;

	assert(socket->connect_info);

	if (connect_info->dnsquery) kill_dns_request(&connect_info->dnsquery);

	mem_free_if(connect_info->addr);
	done_uri(connect_info->uri);
	mem_free_set(&socket->connect_info, NULL);
}
Exemplo n.º 17
0
Arquivo: task.c Projeto: ezc/elinks
static void
free_task(struct session *ses)
{
	assertm(ses->task.type, "Session has no task");
	if_assert_failed return;

	if (ses->loading_uri) {
		done_uri(ses->loading_uri);
		ses->loading_uri = NULL;
	}
	ses->task.type = TASK_NONE;
	mem_free_set(&ses->task.target.frame, NULL);
}
Exemplo n.º 18
0
/* prefix can have entities in it, but linkname cannot.  */
void
put_link_line(unsigned char *prefix, unsigned char *linkname,
	      unsigned char *link, unsigned char *target,
	      struct html_context *html_context)
{
	html_context->has_link_lines = 1;
	html_stack_dup(html_context, ELEMENT_KILLABLE);
	ln_break(html_context, 1);
	mem_free_set(&format.link, NULL);
	mem_free_set(&format.target, NULL);
	mem_free_set(&format.title, NULL);
	format.form = NULL;
	put_chrs(html_context, prefix, strlen((const char *)prefix));
	format.link = join_urls(html_context->base_href, link);
	format.target = stracpy(target);
	format.style.color.foreground = format.color.clink;
	/* linkname typically comes from get_attr_val, which
	 * has already expanded character entity references.
	 * Tell put_chrs not to expand them again.  */
	format.style.attr |= AT_NO_ENTITIES;
	put_chrs(html_context, linkname, strlen((const char *)linkname));
	ln_break(html_context, 1);
	pop_html_element(html_context);
}
Exemplo n.º 19
0
static void
do_html_select_multiple(struct html_context *html_context, unsigned char *a,
                        unsigned char *html, unsigned char *eof,
                        unsigned char **end)
{
	unsigned char *al = get_attr_val(a, (unsigned char *)"name", html_context->doc_cp);

	if (!al) return;
	html_focusable(html_context, a);
	html_top->type = ELEMENT_DONT_KILL;
	mem_free_set(&format.select, al);
	format.select_disabled = has_attr(a, (unsigned char *)"disabled", html_context->doc_cp)
	                         ? FORM_MODE_DISABLED
	                         : FORM_MODE_NORMAL;
}
Exemplo n.º 20
0
Arquivo: task.c Projeto: ezc/elinks
void
ses_load(struct session *ses, struct uri *uri, unsigned char *target_frame,
	 struct location *target_location, enum cache_mode cache_mode,
	 enum task_type task_type)
{
	ses->loading.callback = (download_callback_T *) loading_callback;
	ses->loading.data = ses;
	ses->loading_uri = uri;

	ses->task.type = task_type;
	mem_free_set(&ses->task.target.frame, null_or_stracpy(target_frame));
	ses->task.target.location = target_location;

	load_uri(ses->loading_uri, ses->referrer, &ses->loading,
		 PRI_MAIN, cache_mode, -1);
}
Exemplo n.º 21
0
static enum evhook_status
script_hook_goto_url(va_list ap, void *data)
{
	unsigned char **url = va_arg(ap, unsigned char **);
	struct session *ses = va_arg(ap, struct session *);
	int error;
	VALUE args[2];
	VALUE result;

	if (*url == NULL)
		return EVENT_HOOK_STATUS_NEXT;

	args[0] = rb_str_new(*url, strlen((const char *)*url));

	if (!ses || !have_location(ses)) {
		args[1] = Qnil;
	} else {
		args[1] = rb_str_new(struri(cur_loc(ses)->vs.uri), strlen((const char *)struri(cur_loc(ses)->vs.uri)));
	}

	result = erb_protected_method_call("goto_url_hook", 2, args, &error);
	if (error) {
		erb_report_error(ses, error);
		return EVENT_HOOK_STATUS_NEXT;
	}

	switch (rb_type(result)) {
	case T_STRING:
	{
		unsigned char *new_url;

		new_url = memacpy(RSTRING(result)->ptr, RSTRING(result)->len);
		if (new_url) {
			mem_free_set(url, new_url);
		}
		break;
	}
	case T_NIL:
		break;

	default:
		alert_ruby_error(ses, "goto_url_hook must return a string or nil");
	}

	return EVENT_HOOK_STATUS_NEXT;
}
Exemplo n.º 22
0
Arquivo: kbd.c Projeto: Efreak/elinks
static void
free_itrm(struct itrm *itrm)
{
	if (!itrm) return;

	if (!itrm->remote) {
		if (itrm->orig_title && *itrm->orig_title) {
			set_window_title(itrm->orig_title, itrm->title_codepage);

		} else if (itrm->touched_title) {
			/* Set the window title to the value of $TERM if X11
			 * wasn't compiled in. Should hopefully make at least
			 * half the users happy. (debian bug #312955) */
			unsigned char title[MAX_TERM_LEN];

			get_terminal_name(title);
			if (*title)
				set_window_title(title,
						 get_cp_index("US-ASCII"));
		}


		unhandle_terminal_resize(itrm->in.ctl);
#ifdef CONFIG_MOUSE
		disable_mouse();
#endif
		send_done_sequence(itrm->out.std, itrm->altscreen);
		tcsetattr(itrm->in.ctl, TCSANOW, &itrm->t);
	}

	mem_free_set(&itrm->orig_title, NULL);

	/* elinks -remote may not have a valid stdin if not run from a tty (bug 938) */
	if (!itrm->remote || itrm->in.std >= 0) clear_handlers(itrm->in.std);
	clear_handlers(itrm->in.sock);
	clear_handlers(itrm->out.std);
	clear_handlers(itrm->out.sock);

	kill_timer(&itrm->timer);

	if (itrm == ditrm) ditrm = NULL;
	mem_free_if(itrm->out.queue.data);
	mem_free_if(itrm->in.queue.data);
	mem_free(itrm);
}
Exemplo n.º 23
0
/** Free all resources owned by *@a http_post, but do not free the
 * structure itself.  It is safe to call this multiple times.
 *
 * @relates http_post */
void
done_http_post(struct http_post *http_post)
{
	size_t i;

	http_post->total_upload_length = 0;
	http_post->uploaded = 0;
	http_post->post_data = NULL;
	if (http_post->post_fd != -1) {
		close(http_post->post_fd);
		http_post->post_fd = -1;
	}
	for (i = 0; i < http_post->file_count; i++)
		mem_free(http_post->files[i].name);
	http_post->file_index = 0;
	http_post->file_count = 0;
	http_post->file_read = 0;
	mem_free_set(&http_post->files, NULL);
}
Exemplo n.º 24
0
static inline void
compress_node(struct ff_node *leafset, struct fastfind_info *info,
	      int i, int pos)
{
	struct ff_node_c *new_ = mem_alloc(sizeof(*new_));

	if (!new_) return;

	new_->c = 1;
	new_->e = leafset[pos].e;
	new_->p = leafset[pos].p;
	new_->l = leafset[pos].l;
	new_->ch = pos;

	mem_free_set(&info->leafsets[i], (struct ff_node *) new_);
	FF_DBG_cnode(info);
	FF_DBG_mem(info, sizeof(*new_));
	FF_DBG_mem(info, sizeof(*leafset) * -info->uniq_chars_count);
}
Exemplo n.º 25
0
static inline void
do_script_hook_goto_url(struct session *ses, unsigned char **url)
{
	int count;
	dSP;	/* Keep in variables declaration block. */

	ENTER;
	SAVETMPS;

	PUSHMARK(SP);
	my_XPUSHs(*url, strlen((const char *)*url));
	if (!ses || !have_location(ses)) {
		XPUSHs(sv_2mortal(newSV(0)));
	} else {
		unsigned char *uri = struri(cur_loc(ses)->vs.uri);

		my_XPUSHs(uri, strlen((const char *)uri));
	}
	PUTBACK;

	count = call_pv("goto_url_hook", G_EVAL | G_SCALAR);
	if (SvTRUE(ERRSV)) count = 0;	/* FIXME: error message ? */
	SPAGAIN;
	if (count == 1) {
#ifndef CONFIG_PERL_POPPX_WITHOUT_N_A
		STRLEN n_a;	/* Used by POPpx macro. */
#endif
		unsigned char *new_url = POPpx;

		if (new_url) {
			unsigned char *n = stracpy(new_url);

			if (n) {
				mem_free_set(url, n);
			}
		}
	}

	PUTBACK;
	FREETMPS;
	LEAVE;
}
Exemplo n.º 26
0
static enum evhook_status
script_hook_follow_url(va_list ap, void *data)
{
	unsigned char **url = va_arg(ap, unsigned char **);
	struct session *ses = va_arg(ap, struct session *);
	int error;
	VALUE args[1];
	VALUE result;

	evhook_use_params(url && ses);

	if (*url == NULL)
		return EVENT_HOOK_STATUS_NEXT;

	args[0] = rb_str_new(*url, strlen((const char *)*url));

	result = erb_protected_method_call("follow_url_hook", 1, args, &error);
	if (error) {
		erb_report_error(ses, error);
		return EVENT_HOOK_STATUS_NEXT;
	}

	switch (rb_type(result)) {
	case T_STRING:
	{
		unsigned char *new_url;

		new_url = memacpy(RSTRING(result)->ptr, RSTRING(result)->len);
		if (new_url) {
			mem_free_set(url, new_url);
		}
		break;
	}
	case T_NIL:
		break;

	default:
		alert_ruby_error(ses, "follow_url_hook must return a string or nil");
	}

	return EVENT_HOOK_STATUS_NEXT;
}
Exemplo n.º 27
0
static unsigned char *
init_data_protocol_header(struct cache_entry *cached,
			  unsigned char *type, int typelen)
{
	unsigned char *head;

	assert(typelen);

	type = memacpy(type, typelen);
	if (!type) return NULL;

	/* Set fake content type */
	head = straconcat((const unsigned char *)"\r\nContent-Type: ", type, "\r\n",
			  (unsigned char *) NULL);
	mem_free(type);
	if (!head) return NULL;

	mem_free_set(&cached->head, head);
	return head;
}
Exemplo n.º 28
0
Arquivo: task.c Projeto: ezc/elinks
void
abort_preloading(struct session *ses, int interrupt)
{
	if (!ses->task.type) {
		/* ses->task.target.frame must be freed in the
		 * destroy_session() => abort_loading() =>
		 * abort_preloading() call chain.  Normally,
		 * free_task() called from here would do that,
		 * but if the task has no type, free_task()
		 * cannot be called because an assertion would
		 * fail.  There are several functions that set
		 * ses->task.target.frame without ses->task.type,
		 * so apparently it is allowed.  */
		mem_free_set(&ses->task.target.frame, NULL);
		return;
	}

	cancel_download(&ses->loading, interrupt);
	free_task(ses);
}
Exemplo n.º 29
0
/* The Ruby function can return:
 *  - "PROXY:PORT" to use the specified proxy
 *  - ""           to not use any proxy
 *  - nil          to use the default proxies */
static enum evhook_status
script_hook_get_proxy(va_list ap, void *data)
{
	unsigned char **new_proxy_url = va_arg(ap, unsigned char **);
	unsigned char *url = va_arg(ap, unsigned char *);
	int error;
	VALUE args[1];
	VALUE result;

	if (!new_proxy_url || !url)
		return EVENT_HOOK_STATUS_NEXT;

	args[0] = rb_str_new(url, strlen((const char *)url));

	result = erb_protected_method_call("proxy_hook", 1, args, &error);
	if (error) {
		erb_report_error(NULL, error);
		return EVENT_HOOK_STATUS_NEXT;
	}

	switch (rb_type(result)) {
	case T_STRING:
	{
		unsigned char *proxy;

		proxy = memacpy(RSTRING(result)->ptr, RSTRING(result)->len);
		if (proxy) {
			mem_free_set(new_proxy_url, proxy);
		}
		break;
	}
	case T_NIL:
		break;

	default:
		alert_ruby_error(NULL, "proxy_hook must return a string or nil");
	}

	return EVENT_HOOK_STATUS_NEXT;
}
Exemplo n.º 30
0
void
html_base(struct html_context *html_context, unsigned char *a,
          unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5)
{
	unsigned char *al;

	al = get_url_val(a, (unsigned char *)"href", html_context->doc_cp);
	if (al) {
		unsigned char *base = join_urls(html_context->base_href, al);
		struct uri *uri = base ? get_uri(base, 0) : NULL;

		mem_free(al);
		mem_free_if(base);

		if (uri) {
			done_uri(html_context->base_href);
			html_context->base_href = uri;
		}
	}

	al = get_target(html_context->options, a);
	if (al) mem_free_set(&html_context->base_target, al);
}