コード例 #1
0
ファイル: load_uri.c プロジェクト: ezc/elinks
static JSBool
smjs_load_uri(JSContext *ctx, uintN argc, jsval *rval)
{
	jsval *argv = JS_ARGV(ctx, rval);
	struct smjs_load_uri_hop *hop;
	struct download *download;
	JSString *jsstr;
	unsigned char *uri_string;
	struct uri *uri;

	if (argc < 2) return JS_FALSE;

	jsstr = JS_ValueToString(smjs_ctx, argv[0]);
	uri_string = JS_EncodeString(smjs_ctx, jsstr);

	uri = get_uri(uri_string, 0);
	if (!uri) return JS_FALSE;

	download = mem_alloc(sizeof(*download));
	if (!download) {
		done_uri(uri);
		return JS_FALSE;
	}

	hop = mem_alloc(sizeof(*hop));
	if (!hop) {
		mem_free(download);
		done_uri(uri);
		return JS_FALSE;
	}

	hop->callback = argv[1];
	hop->ses = smjs_ses;
	if (!JS_AddNamedValueRoot(smjs_ctx, &hop->callback,
			     "smjs_load_uri_hop.callback")) {
		mem_free(hop);
		mem_free(download);
		done_uri(uri);
		return JS_FALSE;
	}

	download->data = hop;
	download->callback = (download_callback_T *) smjs_loading_callback;

	load_uri(uri, NULL, download, PRI_MAIN, CACHE_MODE_NORMAL, -1);

	done_uri(uri);

	return JS_TRUE;
}
コード例 #2
0
ファイル: location.c プロジェクト: rkd77/felinks
void
location_goto(struct document_view *doc_view, unsigned char *url)
{
	unsigned char *new_abs_url;
	struct uri *new_uri;
	struct delayed_goto *deg;

	/* Workaround for bug 611. Does not crash, but may lead to infinite loop.*/
	if (!doc_view) return;
	new_abs_url = join_urls(doc_view->document->uri,
	                        trim_chars(url, ' ', 0));
	if (!new_abs_url)
		return;
	new_uri = get_uri(new_abs_url, 0);
	mem_free(new_abs_url);
	if (!new_uri)
		return;
	deg = mem_calloc(1, sizeof(*deg));
	if (!deg) {
		done_uri(new_uri);
		return;
	}
	assert(doc_view->vs);
	deg->vs = doc_view->vs;
	deg->uri = new_uri;
	/* It does not seem to be very safe inside of frames to
	 * call goto_uri() right away. */
	register_bottom_half(delayed_goto, deg);
}
コード例 #3
0
void done_connection_info( struct socket *socket )
{
  struct connect_info *connect_info = socket->connect_info;
  if ( assert_failed == 0 )
  {
    assert_failed = connect_info[0].addr == 0;
    if ( !(_Bool)( connect_info[0].addr != 0 ) )
    {
      errfile = "/home/naftali/source/elinks-0.12~pre5/src/network/socket.c";
      errline = 129;
      elinks_internal( "assertion socket-&gt;connect_info failed!" );
    }
  }
  if ( connect_info->dnsquery )
    kill_dns_request( &connect_info->dnsquery );
{
  void *p = (void*)connect_info->addr;
  if ( connect_info->addr )
    mem_free( &((int*)p)[0] );
  done_uri( connect_info->uri );
  if ( socket->connect_info )
  {
    mem_free( (void*)socket->connect_info );
  }
  socket->connect_info = 0;
  return;
}
}
コード例 #4
0
ファイル: task.c プロジェクト: 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 {
コード例 #5
0
ファイル: task.c プロジェクト: ezc/elinks
static void
post_no(void *task_)
{
	struct task *task = task_;

	reload(task->ses, CACHE_MODE_NORMAL);
	done_uri(task->uri);
}
コード例 #6
0
ファイル: dialogs.c プロジェクト: rkd77/elinks-tv
static void
auth_ok(void *data)
{
	struct dialog *dlg = (struct dialog *)data;
	struct auth_entry *entry = (struct auth_entry *)dlg->udata2;
	struct session *ses = (struct session *)dlg->udata;

	entry->blocked = 0;
	entry->valid = auth_entry_has_userinfo(entry);

#ifdef CONFIG_FORMHIST
	if (get_opt_bool((const unsigned char *)"document.browse.forms.show_formhist", ses)) {
		unsigned char *url = get_uri_string(entry->uri, URI_HTTP_AUTH);

		if (url) {
			struct form form = {};

			form.action = url;
			INIT_LIST_OF(struct submitted_value, submit);
			struct submitted_value *user, *password;

			user = init_submitted_value((unsigned char *)"user", entry->user, FC_TEXT, NULL, 0);
			if (user) {
				add_to_list(submit, user);
			}
			password = init_submitted_value((unsigned char *)"password", entry->password, FC_PASSWORD, NULL, 0);
			if (password) {
				add_to_list(submit, password);
			}

			memorize_form(ses, &submit, &form);
			done_submitted_value_list(&submit);
			mem_free(url);
		}
	}
#endif

	if (entry->valid && have_location(ses)) {
		struct location *loc = cur_loc(ses);
		struct uri *uri = loc->vs.uri;

		/* Make a 'fake' redirect to a URI without user/password so that
		 * the user/password from the URI will not override what the
		 * user just entered in the dialog. */
		if ((uri->userlen && strlcmp(entry->user, -1, uri->user, uri->userlen))
		    || (uri->password && strlcmp(entry->password, -1, uri->password, uri->passwordlen))) {

			uri = get_composed_uri(uri, URI_HTTP_AUTH | URI_DATA | URI_POST);
			if (uri) {
				goto_uri_frame(ses, uri, NULL, CACHE_MODE_INCREMENT);
				done_uri(uri);
				return;
			}
		}
	}

	reload(ses, CACHE_MODE_INCREMENT);
}
コード例 #7
0
ファイル: auth.c プロジェクト: Efreak/elinks
static void
done_auth_entry(struct auth_entry *entry)
{
	if (entry->box_item)
		done_listbox_item(&auth_browser, entry->box_item);
	done_uri(entry->uri);
	mem_free_if(entry->realm);
	mem_free_if(entry->nonce);
	mem_free_if(entry->opaque);
	mem_free(entry);
}
コード例 #8
0
ファイル: task.c プロジェクト: 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);
}
コード例 #9
0
ファイル: socket.c プロジェクト: nabetaro/elinks
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);
}
コード例 #10
0
ファイル: peerconnect.c プロジェクト: Efreak/elinks
/* Establish connection to a peer. As a backend, it uses the internal and more
 * generic connection creater which takes care of DNS querying etc. */
enum bittorrent_state
make_bittorrent_peer_connection(struct bittorrent_connection *bittorrent,
				struct bittorrent_peer *peer_info)
{
	enum bittorrent_state result = BITTORRENT_STATE_OUT_OF_MEM;
	struct uri *uri = NULL;
	struct string uri_string = NULL_STRING;
	struct bittorrent_peer_connection *peer;

	peer = init_bittorrent_peer_connection(-1);
	if (!peer) goto out;

	peer->local.initiater = 1;

	add_to_list(bittorrent->peers, peer);
	peer->bittorrent = bittorrent;

	peer->bitfield = init_bitfield(bittorrent->meta.pieces);
	if (!peer->bitfield) goto out;

	memcpy(peer->id, peer_info->id, sizeof(peer->id));

	/* XXX: Very hacky; construct a fake URI from which make_connection()
	 * can extract the IP address and port number. */
	/* FIXME: Rather change the make_connection() interface. This is an ugly
	 * hack. */
	if (!init_string(&uri_string)) goto out;
	if (!add_format_to_string(&uri_string,
#ifdef CONFIG_IPV6
				  strchr((const char *)peer_info->ip, ':') ?
				  "bittorrent-peer://[%s]:%u/" :
#endif
				  "bittorrent-peer://%s:%u/",
				  peer_info->ip, (unsigned) peer_info->port))
		goto out;
	uri = get_uri(uri_string.source, 0);
	if (!uri) goto out;

	make_connection(peer->socket, uri, send_bittorrent_peer_handshake, 1);
	result = BITTORRENT_STATE_OK;

out:
	if (uri)
		done_uri(uri);
	done_string(&uri_string);
	if (peer && result != BITTORRENT_STATE_OK)
		done_bittorrent_peer_connection(peer);
	return result;
}
コード例 #11
0
ファイル: location.c プロジェクト: rkd77/felinks
static void
delayed_goto(void *data)
{
	struct delayed_goto *deg = data;

	assert(deg);
	if (deg->vs->doc_view
	    && deg->vs->doc_view == deg->vs->doc_view->session->doc_view) {
		goto_uri_frame(deg->vs->doc_view->session, deg->uri,
		               deg->vs->doc_view->name,
			       CACHE_MODE_NORMAL);
	}
	done_uri(deg->uri);
	mem_free(deg);
}
コード例 #12
0
void done_auth_entry( struct auth_entry *entry )
{
  if ( entry->box_item )
    done_listbox_item( &auth_browser, entry->box_item );
  done_uri( entry->uri );
{
  void *p = (void*)entry->realm;
  if ( entry->realm )
    mem_free( &((int*)p)[0] );
{
  void *p = (void*)entry->nonce;
  if ( entry->nonce )
    mem_free( &((int*)p)[0] );
{
  void *p = (void*)entry->opaque;
  if ( entry->opaque )
    mem_free( &((int*)p)[0] );
  mem_free( (void*)entry[0].next );
  return;
}
}
}
}
コード例 #13
0
ファイル: general.c プロジェクト: rkd77/elinks-tv
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);
}
コード例 #14
0
void abort_download( struct file_download *file_download )
{
  int eax;
  done_download_display( file_download );
  if ( file_download->ses )
    check_questions_queue( file_download->ses );
  if ( file_download->dlg_data )
    cancel_dialog( file_download->dlg_data, 0 );
  cancel_download( &file_download->download, ( (int)file_download->bits_at_104/*.1_1of4*/ >> 1 ) & 1 );
  if ( file_download->uri )
    done_uri( file_download->uri );
  if ( file_download->handle != -1 )
    close( file_download->handle );
{
  void *p = (void*)file_download->external_handler;
  if ( file_download->external_handler )
    mem_free( &((int*)p)[0] );
  if ( file_download->file )
  {
    if ( ( file_download->bits_at_104/*.1_1of4*/ & 1 ) & 255 )
    {
      unlink( (char*)file_download->file );
      file_download->file[0] = file_download->file;
    }
    mem_free( (void*)file_download->file );
    file_download->prev = file_download->prev;
    &file_download->prev = &file_download;
    file_download = &file_download;
  }
  else
  {
    file_download->prev = file_download->prev;
    &file_download->prev = &file_download;
    file_download = &file_download;
  }
}
}
コード例 #15
0
void show_http_error_document( struct session *ses, void *data )
{
  struct terminal *term = ses->tab->term;
  struct cache_entry *cached;
  struct cache_entry *cache = find_in_cache( &((int*)data)[1] );
  unsigned char *str;
  cached = find_in_cache( &((int*)data)[1] );
  if ( cached || get_cache_entry( &((int*)data)[1] ) )
  {
    if ( 0 != 72 )
    {
      if ( term && current_charset != get_terminal_codepage( term ) )
      {
        bind_textdomain_codeset( "elinks", get_cp_mime_name( get_terminal_codepage( term ) ) );
        current_charset = get_terminal_codepage( term );
      }
      gettext( "HTTP error %03d" );
    }
    if ( init_string( ebp_32 ) == 0 )
    {
      if ( asprintfa( (char*)gettext( "HTTP error %03d" ) ) )
        mem_free( (void*)asprintfa( (char*)gettext( "HTTP error %03d" ) ) );
    }
    else
    {
      add_format_to_string( (struct string*)asprintfa( (char*)gettext( "HTTP error %03d" ) ), asprintfa( (char*)gettext( "HTTP error %03d" ) ) );
      if ( 0 != 32 )
      {
        if ( term && current_charset != get_terminal_codepage( term ) )
        {
          bind_textdomain_codeset( "elinks", get_cp_mime_name( get_terminal_codepage( term ) ) );
          current_charset = get_terminal_codepage( term );
        }
        gettext( "  An error occurred on the server while fetching the document you\n  requested. However, the server did not send back any explanation of what\n  happened, so it is unknown what went wrong. Please contact the web\n  server administrator about this, if you believe that this error should\n  not occur since it is not a nice behaviour from the web server at all\n  and indicates that there is some much deeper problem with the web server\n  software.\n" );
      }
      add_format_to_string( ebp_32, gettext( "  An error occurred on the server while fetching the document you\n  requested. However, the server did not send back any explanation of what\n  happened, so it is unknown what went wrong. Please contact the web\n  server administrator about this, if you believe that this error should\n  not occur since it is not a nice behaviour from the web server at all\n  and indicates that there is some much deeper problem with the web server\n  software.\n" ) );
      add_format_to_string( "  &lt;/p&gt;\n  &lt;p&gt;\n  URI: &lt;a href=\"%s\"&gt;%s&lt;/a&gt;\n", *(int*)(((int*)data)[1]) );
      add_format_to_string( ebp_32, " &lt;/p&gt;\n &lt;hr /&gt;\n &lt;/body&gt;\n&lt;/html&gt;\n" );
      if ( asprintfa( (char*)gettext( "HTTP error %03d" ) ) )
        mem_free( (void*)asprintfa( (char*)gettext( "HTTP error %03d" ) ) );
      str[0] = ebp_32;
      if ( ebp_32 )
      {
        int gettext_codepage = get_terminal_codepage( term );
        if ( cached )
          delete_entry_content( &cache[0] );
        if ( cache->content_type )
          mem_free( (void*)cache->content_type );
        cache->content_type = stracpy( "text/html" );
        if ( cache->head )
          mem_free( (void*)cache->head );
        cache->head = straconcat( "\r\nContent-Type: text/html; charset=" );
        add_fragment( &cache[0], (long long)0, &str[0] );
        mem_free( &str[0] );
        draw_formatted( ses, 1 );
      }
    }
  }
  done_uri( &((int*)data)[1] );
  mem_free( &((int*)data)[0] );
  return;
}
コード例 #16
0
ファイル: general.c プロジェクト: rkd77/elinks-tv
void
html_script(struct html_context *html_context, unsigned char *a,
            unsigned char *html, unsigned char *eof, unsigned char **end)
{
#ifdef CONFIG_ECMASCRIPT
	/* TODO: <noscript> processing. Well, same considerations apply as to
	 * CSS property display: none processing. */
	/* TODO: Charsets for external scripts. */
	unsigned char *type, *language, *src;
	int in_comment = 0;
#endif

	html_skip(html_context, a);

#ifdef CONFIG_ECMASCRIPT
	/* We try to process nested <script> if we didn't process the parent
	 * one. That's why's all the fuzz. */
	/* Ref:
	 * http://www.ietf.org/internet-drafts/draft-hoehrmann-script-types-03.txt
	 */
	type = get_attr_val(a, (unsigned char *)"type", html_context->doc_cp);
	if (type) {
		unsigned char *pos = type;

		if (!c_strncasecmp((const char *)type, "text/", 5)) {
			pos += 5;

		} else if (!c_strncasecmp((const char *)type, "application/", 12)) {
			pos += 12;

		} else {
			mem_free(type);
not_processed:
			/* Permit nested scripts and retreat. */
			html_top->invisible++;
			return;
		}

		if (!c_strncasecmp((const char *)pos, "javascript", 10)) {
			int len = strlen((const char *)pos);

			if (len > 10 && !isdigit(pos[10])) {
				mem_free(type);
				goto not_processed;
			}

		} else if (c_strcasecmp((const char *)pos, "ecmascript")
		    && c_strcasecmp((const char *)pos, "jscript")
		    && c_strcasecmp((const char *)pos, "livescript")
		    && c_strcasecmp((const char *)pos, "x-javascript")
		    && c_strcasecmp((const char *)pos, "x-ecmascript")) {
			mem_free(type);
			goto not_processed;
		}

		mem_free(type);
	}

	/* Check that the script content is ecmascript. The value of the
	 * language attribute can be JavaScript with optional version digits
	 * postfixed (like: ``JavaScript1.1'').
	 * That attribute is deprecated in favor of type by HTML 4.01 */
	language = get_attr_val(a, (unsigned char *)"language", html_context->doc_cp);
	if (language) {
		int languagelen = strlen((const char *)language);

		if (languagelen < 10
		    || (languagelen > 10 && !isdigit(language[10]))
		    || c_strncasecmp((const char *)language, "javascript", 10)) {
			mem_free(language);
			html_top->invisible++;
			return;
			//goto not_processed;
		}

		mem_free(language);
	}

	if (html_context->part->document
	    && (src = get_attr_val(a, (unsigned char *)"src", html_context->doc_cp))) {
		/* External reference. */

		unsigned char *import_url;
		struct uri *uri;

		if (!get_opt_bool((const unsigned char *)"ecmascript.enable", NULL)) {
			mem_free(src);
			html_top->invisible++;
			return;
			//goto not_processed;
		}

		/* HTML <head> urls should already be fine but we can.t detect them. */
		import_url = join_urls(html_context->base_href, src);
		mem_free(src);
		if (!import_url) goto imported;

		uri = get_uri(import_url, URI_BASE);
		if (!uri) goto imported;

		/* Request the imported script as part of the document ... */
		html_context->special_f(html_context, SP_SCRIPT, uri);
		done_uri(uri);

		/* Create URL reference onload snippet. */
		insert_in_string(&import_url, 0, (const unsigned char *)"^", 1);
		add_to_string_list(&html_context->part->document->onload_snippets,
		                   import_url, -1);

imported:
		/* Retreat. Do not permit nested scripts, tho'. */
		if (import_url) mem_free(import_url);
		return;
	}

	/* Positive, grab the rest and interpret it. */

	/* First position to the real script start. */
	while (html < eof && *html <= ' ') html++;
	if (eof - html > 4 && !strncmp((const char *)html, "<!--", 4)) {
		in_comment = 1;
		/* We either skip to the end of line or to -->. */
		for (; *html != '\n' && *html != '\r' && eof - html >= 3; html++) {
			if (!strncmp((const char *)html, "-->", 3)) {
				/* This means the document is probably broken.
				 * We will now try to process the rest of
				 * <script> contents, which is however likely
				 * to be empty. Should we try to process the
				 * comment too? Currently it seems safer but
				 * less tolerant to broken pages, if there are
				 * any like this. */
				html += 3;
				in_comment = 0;
				break;
			}
		}
	}

	*end = html;

	/* Now look ahead for the script end. The <script> contents is raw
	 * CDATA, so we just look for the ending tag and need not care for
	 * any quote marks counting etc - YET, we are more tolerant and permit
	 * </script> stuff inside of the script if the whole <script> element
	 * contents is wrapped in a comment. See i.e. Mozilla bug 26857 for fun
	 * reading regarding this. */
	for (; *end < eof; (*end)++) {
		unsigned char *name;
		int namelen;

		if (in_comment) {
			/* TODO: If we ever get some standards-quirk mode
			 * distinction, this should be disabled in the
			 * standards mode (and we should just look for CDATA
			 * end, which is "</"). --pasky */
			if (eof - *end >= 3 && !strncmp((const char *)*end, "-->", 3)) {
				/* Next iteration will jump passed the ending '>' */
				(*end) += 2;
				in_comment = 0;
			}
			continue;
			/* XXX: Scan for another comment? That's admittelly
			 * already stretching things a little bit to an
			 * extreme ;-). */
		}

		if (**end != '<')
			continue;
		/* We want to land before the closing element, that's why we
		 * don't pass @end also as the appropriate parse_element()
		 * argument. */
		if (parse_element(*end, eof, &name, &namelen, NULL, NULL))
			continue;
		if (c_strlcasecmp(name, namelen, (const unsigned char *)"/script", 7))
			continue;
		/* We have won! */
		break;
	}
	if (*end >= eof) {
		/* Either the document is not completely loaded yet or it's
		 * broken. At any rate, run away screaming. */
		*end = eof; /* Just for sanity. */
		return;
	}

	if (html_context->part->document && *html != '^') {
		add_to_string_list(&html_context->part->document->onload_snippets,
		                   html, *end - html);
	}
#endif
}