Beispiel #1
0
void
report_scripting_error(struct module *module, struct session *ses,
		       unsigned char *msg)
{
	struct terminal *term;
	struct string string;

	if (!ses) {
		if (list_empty(terminals)) {
			usrerror("[%s error] %s", module->name, msg);
			return;
		}

		term = terminals.next;

	} else {
		term = ses->tab->term;
	}

	if (!init_string(&string))
		return;

	add_format_to_string(&string,
		_("An error occurred while running a %s script", term),
		module->name);

	add_format_to_string(&string, ":\n\n%s", msg);

	info_box(term, MSGBOX_NO_TEXT_INTL | MSGBOX_FREE_TEXT,
		 N_("Browser scripting error"), ALIGN_LEFT, string.source);
}
Beispiel #2
0
Datei: ssl.c Projekt: ezc/elinks
unsigned char *
get_ssl_connection_cipher(struct socket *socket)
{
	ssl_t *ssl = socket->ssl;
	struct string str;

	if (!init_string(&str)) return NULL;

#ifdef USE_OPENSSL
	add_format_to_string(&str, "%ld-bit %s %s",
		SSL_get_cipher_bits(ssl, NULL),
		SSL_get_cipher_version(ssl),
		SSL_get_cipher_name(ssl));
#elif defined(CONFIG_GNUTLS)
	/* XXX: How to get other relevant parameters? */
	add_format_to_string(&str, "%s - %s - %s - %s - %s (compr: %s)",
		gnutls_protocol_get_name(gnutls_protocol_get_version(*ssl)),
		gnutls_kx_get_name(gnutls_kx_get(*ssl)),
		gnutls_cipher_get_name(gnutls_cipher_get(*ssl)),
		gnutls_mac_get_name(gnutls_mac_get(*ssl)),
		gnutls_certificate_type_get_name(gnutls_certificate_type_get(*ssl)),
		gnutls_compression_get_name(gnutls_compression_get(*ssl)));
#endif

	return str.source;
}
Beispiel #3
0
static void
error_reporter(JSContext *ctx, const char *message, JSErrorReport *report)
{
	unsigned char *strict, *exception, *warning, *error;
	struct string msg;

	if (!init_string(&msg)) goto reported;

	strict	  = JSREPORT_IS_STRICT(report->flags) ? " strict" : "";
	exception = JSREPORT_IS_EXCEPTION(report->flags) ? " exception" : "";
	warning   = JSREPORT_IS_WARNING(report->flags) ? " warning" : "";
	error	  = !report->flags ? " error" : "";

	add_format_to_string(&msg, "A client script raised the following%s%s%s%s",
			strict, exception, warning, error);

	add_to_string(&msg, ":\n\n");
	add_to_string(&msg, message);

	if (report->linebuf && report->tokenptr) {
		int pos = report->tokenptr - report->linebuf;

		add_format_to_string(&msg, "\n\n%s\n.%*s^%*s.",
			       report->linebuf,
			       pos - 2, " ",
			       strlen(report->linebuf) - pos - 1, " ");
	}

	alert_smjs_error(msg.source);
	done_string(&msg);

reported:
	JS_ClearPendingException(ctx);
}
Beispiel #4
0
unsigned char *get_auth_entry_info( struct listbox_item *item, struct terminal *term )
{
  int eax;
  int ecx;
  int edx;
  struct string info;
  if ( item->type != BI_FOLDER && init_string( &info ) )
  {
    add_format_to_string( &info, "%s: " );
    add_uri_to_string( &info, &item->udata[3], URI_HTTP_AUTH );
    add_format_to_string( &info, "\n%s: " );
    if ( item->udata[4] )
    {
      if ( strlen( &item->udata[4] ) <= 511 )
        add_bytes_to_string__( &info, &item->udata[4], strlen( &item->udata[4] ) );
      else
      {
        add_bytes_to_string__( &info, &item->udata[4], 512 );
        add_to_string( &info, "..." );
      }
    }
    else
    {
      add_to_string( &info, _( "none", term ) );
    }
    add_format_to_string( &info, "\n%s: %s\n" );
    return info.source;
  }
  else
  {
  }
}
Beispiel #5
0
static unsigned char *
get_auth_entry_info(struct listbox_item *item, struct terminal *term)
{
	struct auth_entry *auth_entry = (struct auth_entry *)item->udata;
	struct string info;

	if (item->type == BI_FOLDER) return NULL;
	if (!init_string(&info)) return NULL;

	add_format_to_string(&info, "%s: ", _("URL", term));
	add_uri_to_string(&info, auth_entry->uri, URI_HTTP_AUTH);

	add_format_to_string(&info, "\n%s: ", _("Realm", term));
	if (auth_entry->realm) {
		int len = strlen((const char *)auth_entry->realm);
		int maxlen = 512; /* Max. number of chars displayed for realm. */

		if (len < maxlen)
			add_bytes_to_string(&info, auth_entry->realm, len);
		else {
			add_bytes_to_string(&info, auth_entry->realm, maxlen);
			add_to_string(&info, (const unsigned char *)"...");
		}
	} else {
		add_to_string(&info, _("none", term));
	}

	add_format_to_string(&info, "\n%s: %s\n", _("State", term),
		auth_entry->valid ? _("valid", term) : _("invalid", term));

	return info.source;
}
Beispiel #6
0
Datei: core.c Projekt: ezc/elinks
static int
set_python_search_path(void)
{
	struct string new_python_path;
	unsigned char *old_python_path;
	int result = -1;

	if (!init_string(&new_python_path)) return result;

	if (elinks_home && !add_format_to_string(&new_python_path, "%s%c",
						 elinks_home, DELIM))
		goto end;

	if (!add_to_string(&new_python_path, CONFDIR))
		goto end;

	old_python_path = (unsigned char *) getenv("PYTHONPATH");
	if (old_python_path && !add_format_to_string(&new_python_path, "%c%s",
						     DELIM, old_python_path))
		goto end;

	result = env_set("PYTHONPATH", new_python_path.source, -1);

end:
	done_string(&new_python_path);
	return result;
}
Beispiel #7
0
static unsigned char *
get_nntp_title(struct connection *conn)
{
	struct nntp_connection_info *nntp = conn->info;
	struct string title;

	if (!init_string(&title))
		return NULL;

	switch (nntp->target) {
	case NNTP_TARGET_ARTICLE_RANGE:
		add_format_to_string(&title, "Articles in the range %ld to %ld",
				     nntp->current_article, nntp->end_article);
		break;

	case NNTP_TARGET_ARTICLE_NUMBER:
	case NNTP_TARGET_MESSAGE_ID:
	case NNTP_TARGET_GROUP_MESSAGE_ID:
	{
		unsigned char *subject;

		subject = parse_header(conn->cached->head, "Subject", NULL);
		if (subject) {
			add_to_string(&title, subject);
			mem_free(subject);
			break;
		}

		add_format_to_string(&title, "Article "),
		add_string_to_string(&title, &nntp->message);

		if (nntp->target == NNTP_TARGET_MESSAGE_ID)
			break;

		add_format_to_string(&title, " in ");
		add_string_to_string(&title, &nntp->group);
		break;
	}
	case NNTP_TARGET_GROUP:
		add_format_to_string(&title, "Articles in "),
		add_string_to_string(&title, &nntp->group);
		break;

	case NNTP_TARGET_GROUPS:
		add_format_to_string(&title, "Newsgroups on "),
		add_uri_to_string(&title, conn->uri, URI_PUBLIC);
		break;

	case NNTP_TARGET_QUIT:
		break;
	}

	return title.source;
}
Beispiel #8
0
static void
error_reporter(JSContext *ctx, const char *message, JSErrorReport *report)
{
	struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
	struct session *ses = interpreter->vs->doc_view->session;
	struct terminal *term;
	unsigned char *strict, *exception, *warning, *error;
	struct string msg;

	assert(interpreter && interpreter->vs && interpreter->vs->doc_view
	       && ses && ses->tab);
	if_assert_failed goto reported;

	term = ses->tab->term;

#ifdef CONFIG_LEDS
	set_led_value(ses->status.ecmascript_led, 'J');
#endif

	if (!get_opt_bool("ecmascript.error_reporting", ses)
	    || !init_string(&msg))
		goto reported;

	strict	  = JSREPORT_IS_STRICT(report->flags) ? " strict" : "";
	exception = JSREPORT_IS_EXCEPTION(report->flags) ? " exception" : "";
	warning   = JSREPORT_IS_WARNING(report->flags) ? " warning" : "";
	error	  = !report->flags ? " error" : "";

	add_format_to_string(&msg, _("A script embedded in the current "
			"document raised the following%s%s%s%s", term),
			strict, exception, warning, error);

	add_to_string(&msg, ":\n\n");
	add_to_string(&msg, message);

	if (report->linebuf && report->tokenptr) {
		int pos = report->tokenptr - report->linebuf;

		add_format_to_string(&msg, "\n\n%s\n.%*s^%*s.",
			       report->linebuf,
			       pos - 2, " ",
			       strlen(report->linebuf) - pos - 1, " ");
	}

	info_box(term, MSGBOX_FREE_TEXT, N_("JavaScript Error"), ALIGN_CENTER,
		 msg.source);

reported:
	/* Im clu'les. --pasky */
	JS_ClearPendingException(ctx);
}
Beispiel #9
0
unsigned char *get_formhist_data_info( struct listbox_item *item, struct terminal *term )
{
  int eax;
  int edx;
  struct string info;
  struct submitted_value *sv;
  if ( item->type != BI_FOLDER && init_string( &info ) )
  {
    add_format_to_string( &info, "%s: %s" );
    add_char_to_string( &info, 10 );
    if ( ( *(char*)(item->udata + 20) & 1 ) & 255 )
    {
      add_to_string( &info, _( "Forms are never saved for this URL.", &term[0] ) );
    }
    else
    {
      add_to_string( &info, _( "Forms are saved for this URL.", &term[0] ) );
    }
    add_char_to_string( &info, 10 );
    sv = &item->udata[3];
    if ( item->udata[3] != item->udata[3] )
    {
      do
      {
        add_format_to_string( &info, "\n[%8s] " );
        add_to_string( &info, sv->name );
        add_to_string( &info, " = " );
        if ( sv->value && sv->value[0] )
        {
          if ( sv->type != FC_PASSWORD )
            add_to_string( &info, sv->value );
          else
            add_to_string( &info, "********" );
        }
        sv = &sv;
      }
      while ( sv->next == item->udata[3] );
      return info.source;
    }
    else
    {
      return info.source;
    }
  }
  else
  {
  }
}
Beispiel #10
0
/* TODO: Store cookie in data arg. --jonas*/
void
accept_cookie_dialog(struct session *ses, void *data)
{
    /* [gettext_accelerator_context(accept_cookie_dialog)] */
    struct cookie *cookie = (struct cookie *)cookie_queries.next;
    struct string string;

    assert(ses);

    if (list_empty(cookie_queries)
            || !init_string(&string))
        return;

    del_from_list(cookie);

    add_format_to_string(&string,
                         (const char *)_("Do you want to accept a cookie from %s?", ses->tab->term),
                         cookie->server->host);

    add_to_string(&string, (const unsigned char *)"\n\n");

    add_cookie_info_to_string(&string, cookie, ses->tab->term);

    msg_box(ses->tab->term, NULL, MSGBOX_FREE_TEXT,
            N_("Accept cookie?"), ALIGN_LEFT,
            string.source,
            cookie, 2,
            MSG_BOX_BUTTON(N_("~Accept"), accept_cookie_in_msg_box, B_ENTER),
            MSG_BOX_BUTTON(N_("~Reject"), reject_cookie_in_msg_box, B_ESC));
}
Beispiel #11
0
static void
add_nntp_html_line(struct string *html, struct connection *conn,
		   unsigned char *line)
{
	struct nntp_connection_info *nntp = conn->info;

	switch (nntp->target) {
	case NNTP_TARGET_ARTICLE_NUMBER:
	case NNTP_TARGET_MESSAGE_ID:
	case NNTP_TARGET_GROUP_MESSAGE_ID:
		add_html_to_string(html, line, strlen(line));
		break;

	case NNTP_TARGET_ARTICLE_RANGE:
	case NNTP_TARGET_GROUP:
	case NNTP_TARGET_GROUPS:
	{
		unsigned char *field = line;

		line = strchr((const char *)line, '\t');
		if (!line)
			field = "";
		else
			*line++ = 0;
		add_format_to_string(html, "<li value=\"%s\"><a href=\"%s/%s\">",
				     field, struri(conn->uri), field);

		field = line;
		line = strchr((const char *)line, '\t');
		if (line)
			*line++ = 0;

		add_header_to_string(html, field);
		add_to_string(html, "</a> ");

		if (line) {
			field = line;
			line = strchr((const char *)line, '\t');
			if (line)
				*line++ = 0;

			add_header_to_string(html, field);
		}
		add_to_string(html, "</li>");
		break;
	}
	case NNTP_TARGET_QUIT:
		break;
	}

	add_char_to_string(html, '\n');
}
Beispiel #12
0
/* 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;
}
Beispiel #13
0
static void
decode_b_segment(struct string *str, unsigned char *in, unsigned char *end)
{
	/* Decode in..ep, possibly in-place to ot */
	int c, pos = 0, acc = 0;

	while ((c = *in++) != 0 && (in <= end)) {
		if (c == '+')
			c = 62;
		else if (c == '/')
			c = 63;
		else if ('A' <= c && c <= 'Z')
			c -= 'A';
		else if ('a' <= c && c <= 'z')
			c -= 'a' - 26;
		else if ('0' <= c && c <= '9')
			c -= '0' - 52;
		else if (c == '=') {
			/* padding is almost like (c == 0), except we do
			 * not output NUL resulting only from it;
			 * for now we just trust the data.
			 */
			c = 0;
		}
		else
			continue; /* garbage */

		switch (pos++) {
		case 0:
			acc = (c << 2);
			break;
		case 1:
			add_format_to_string(str, "&#%d;", (acc | (c >> 4)));
			acc = (c & 15) << 4;
			break;
		case 2:
			add_format_to_string(str, "&#%d;", (acc | (c >> 2)));
			acc = (c & 3) << 6;
			break;
		case 3:
			add_format_to_string(str, "&#%d;", (acc | c));
			acc = pos = 0;
			break;
		}
	}
}
Beispiel #14
0
static unsigned char *
get_cookie_info(struct listbox_item *item, struct terminal *term)
{
    struct cookie *cookie = (struct cookie *)item->udata;
    struct cookie_server *server;
    struct string string;

    if (item->type == BI_FOLDER) return NULL;

    if (!init_string(&string)) return NULL;

    server = cookie->server;

    add_format_to_string(&string, "%s: %s", _("Server", term), server->host);

    add_cookie_info_to_string(&string, cookie, term);

    return string.source;
}
Beispiel #15
0
static void
decode_q_segment(struct string *str, unsigned char *in, unsigned char *end)
{
	int c;

	while ((c = *in++) != 0 && (in <= end)) {
		if (c == '=') {
			int d = *in++;

			if (d == '\n' || !d)
				break; /* drop trailing newline */
			d = (unhx(d) << 4) | unhx(*in++);
			add_format_to_string(str, "&#%d;", d);
			continue;
		}

		if (c == '_') /* rfc2047 4.2 (2) */
			c = 0x20;
		add_char_to_string(str, c);
	}
}
Beispiel #16
0
static void
display_entry(const FSP_RDENTRY *fentry, const unsigned char dircolor[])
{
	struct string string;

	/* fentry->name is a fixed-size array and is followed by other
	 * members; thus, if the name reported by the server does not
	 * fit in the array, fsplib must either truncate or reject it.
	 * If fsplib truncates the name, it does not document whether
	 * fentry->namlen is the original length or the truncated
	 * length.  ELinks therefore ignores fentry->namlen and
	 * instead measures the length on its own.  */
	const size_t namelen = strlen(fentry->name);

	if (!init_string(&string)) return;
	add_format_to_string(&string, "%10d", fentry->size);
	add_to_string(&string, "\t<a href=\"");
	/* The result of encode_uri_string does not include '&' or '<'
	 * which could mess up the HTML.  */
	encode_uri_string(&string, fentry->name, namelen, 0);
	if (fentry->type == FSP_RDTYPE_DIR) {
		add_to_string(&string, "/\">");
		if (*dircolor) {
			add_to_string(&string, "<font color=\"");
			add_to_string(&string, dircolor);
			add_to_string(&string, "\"><b>");
		}
		add_html_to_string(&string, fentry->name, namelen);
		if (*dircolor) {
			add_to_string(&string, "</b></font>");
		}
	} else {
		add_to_string(&string, "\">");
		add_html_to_string(&string, fentry->name, namelen);
	}
	add_to_string(&string, "</a>");
	puts(string.source);
	done_string(&string);
}
Beispiel #17
0
static void
add_cookie_info_to_string(struct string *string, struct cookie *cookie,
                          struct terminal *term)
{
    add_format_to_string(string, "\n%s: %s", _("Name", term), cookie->name);
    add_format_to_string(string, "\n%s: %s", _("Value", term), cookie->value);
    add_format_to_string(string, "\n%s: %s", _("Domain", term), cookie->domain);
    add_format_to_string(string, "\n%s: %s", _("Path", term), cookie->path);

    if (!cookie->expires) {
        add_format_to_string(string, "\n%s: ", _("Expires", term));
        add_to_string(string, _("at quit time", term));
#ifdef HAVE_STRFTIME
    } else {
        add_format_to_string(string, "\n%s: ", _("Expires", term));
        add_date_to_string(string, get_opt_str((const unsigned char *)"ui.date_format", NULL), &cookie->expires);
#endif
    }

    add_format_to_string(string, "\n%s: %s", _("Secure", term),
                         _(cookie->secure ? N_("yes") : N_("no"), term));
}
Beispiel #18
0
static unsigned char *
get_cache_entry_info(struct listbox_item *item, struct terminal *term)
{
	struct cache_entry *cached = item->udata;
	struct string msg;

	if (item->type == BI_FOLDER) return NULL;
	if (!init_string(&msg)) return NULL;

	add_to_string(&msg, _("URL", term));
	add_to_string(&msg, ": ");
	add_uri_to_string(&msg, cached->uri, URI_PUBLIC);

	/* No need to use compare_uri() here we only want to check whether they
	 * point to the same URI. */
	if (cached->proxy_uri != cached->uri) {
		add_format_to_string(&msg, "\n%s: ", _("Proxy URL", term));
		add_uri_to_string(&msg, cached->proxy_uri, URI_PUBLIC);
	}

	if (cached->redirect) {
		add_format_to_string(&msg, "\n%s: ", _("Redirect", term));
		add_uri_to_string(&msg, cached->redirect, URI_PUBLIC);

		if (cached->redirect_get) {
			add_to_string(&msg, " (GET)");
		}
	}

	add_format_to_string(&msg, "\n%s: %" OFF_T_FORMAT, _("Size", term),
	                     cached->length);
	add_format_to_string(&msg, "\n%s: %" OFF_T_FORMAT, _("Loaded size", term),
						cached->data_size);
	if (cached->content_type) {
		add_format_to_string(&msg, "\n%s: %s", _("Content type", term),
				     cached->content_type);
	}
	if (cached->last_modified) {
		add_format_to_string(&msg, "\n%s: %s", _("Last modified", term),
				     cached->last_modified);
	}
	if (cached->etag) {
		add_format_to_string(&msg, "\n%s: %s", "ETag",
						cached->etag);
	}
	if (cached->ssl_info) {
		add_format_to_string(&msg, "\n%s: %s", _("SSL Cipher", term),
						cached->ssl_info);
	}
	if (cached->encoding_info) {
		add_format_to_string(&msg, "\n%s: %s", _("Encoding", term),
						cached->encoding_info);
	}

	if (cached->incomplete || !cached->valid) {
		add_char_to_string(&msg, '\n');
		add_to_string(&msg, _("Flags", term));
		add_to_string(&msg, ": ");
		if (cached->incomplete) {
			add_to_string(&msg, _("incomplete", term));
			add_char_to_string(&msg, ' ');
		}
		if (!cached->valid) add_to_string(&msg, _("invalid", term));
	}

#ifdef HAVE_STRFTIME
	if (cached->expire) {
		time_t expires = timeval_to_seconds(&cached->max_age);

		add_format_to_string(&msg, "\n%s: ", _("Expires", term));
		add_date_to_string(&msg, get_opt_str("ui.date_format"), &expires);
	}
#endif
#ifdef CONFIG_DEBUG
	add_format_to_string(&msg, "\n%s: %d", "Refcount", get_object_refcount(cached));
	add_format_to_string(&msg, "\n%s: %u", _("ID", term), cached->id);

	if (cached->head && *cached->head) {
		add_format_to_string(&msg, "\n%s:\n\n%s", _("Header", term),
				     cached->head);
	}
#endif

	return msg.source;
}
Beispiel #19
0
static void
add_nntp_html_start(struct string *html, struct connection *conn)
{
	struct nntp_connection_info *nntp = conn->info;
	unsigned char *title = get_nntp_title(conn);

	add_format_to_string(html,
		"<html>\n"
		"<head><title>%s</title></head>\n"
		"<body>\n",
		empty_string_or_(title));

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

		header_entries = get_nntp_header_entries();
		if (!*header_entries) break;

		add_to_string(html, "<pre>");

		while (*header_entries) {
			unsigned char *entry, *value;

			entry = get_next_path_filename(&header_entries, ',');
			if (!entry) continue;

			value = parse_header(conn->cached->head, entry, NULL);
			if (!value) {
				mem_free(entry);
				continue;
			}

			add_format_to_string(html, "<b>%s</b>: ", entry);
			add_header_to_string(html, value);
			add_char_to_string(html, '\n');
			mem_free(value);
			mem_free(entry);
		}

		add_to_string(html, "<hr />");
		break;
	}
	case NNTP_TARGET_ARTICLE_RANGE:
	case NNTP_TARGET_GROUP:
	case NNTP_TARGET_GROUPS:
		add_format_to_string(html,
			"<h2>%s</h2>\n"
			"<hr />\n"
			"<ol>",
			empty_string_or_(title));
		break;

	case NNTP_TARGET_QUIT:
		break;
	}

	mem_free_if(title);
}
Beispiel #20
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;
}
Beispiel #21
0
static unsigned char *
get_resource_info(struct terminal *term, void *data)
{
	struct string info;
	long val;
	unsigned longlong bigval;

	if (!init_string(&info))
		return NULL;

#define val_add(text) \
	add_format_to_string(&info, (const char *)text, val);

	add_to_string(&info, _("Resources", term));
	add_to_string(&info, (const unsigned char *)": ");

	val = get_file_handles_count();
	val_add(n_((unsigned char *)"%ld handle", (unsigned char *)"%ld handles", val, term));
	add_to_string(&info, (const unsigned char *)", ");

	val = get_timers_count();
	val_add(n_((unsigned char *)"%ld timer", (unsigned char *)"%ld timers", val, term));
	add_to_string(&info, (const unsigned char *)".\n");

	add_to_string(&info, _("Connections", term));
	add_to_string(&info, (const unsigned char *)": ");

	val = get_connections_count();
	val_add(n_((unsigned char *)"%ld connection", (unsigned char *)"%ld connections", val, term));
	add_to_string(&info, (const unsigned char *)", ");

	val = get_connections_connecting_count();
	val_add(n_((unsigned char *)"%ld connecting", (unsigned char *)"%ld connecting", val, term));
	add_to_string(&info, (const unsigned char *)", ");

	val = get_connections_transfering_count();
	val_add(n_((unsigned char *)"%ld transferring", (unsigned char *)"%ld transferring", val, term));
	add_to_string(&info, (const unsigned char *)", ");

	val = get_keepalive_connections_count();
	val_add(n_((unsigned char *)"%ld keepalive", (unsigned char *)"%ld keepalive", val, term));
	add_to_string(&info, (const unsigned char *)".\n");

	add_to_string(&info, _("Memory cache", term));
	add_to_string(&info, (const unsigned char *)": ");

	/* What about just using Kibi/Mebi representation here? --jonas */
	bigval = get_cache_size();
	add_format_to_string(&info, (const char *)n_((unsigned char *)"%ld byte", (unsigned char *)"%ld bytes", bigval, term), bigval);
	add_to_string(&info, (const unsigned char *)", ");

	val = get_cache_entry_count();
	val_add(n_((unsigned char *)"%ld file", (unsigned char *)"%ld files", val, term));
	add_to_string(&info, (const unsigned char *)", ");

	val = get_cache_entry_used_count();
	val_add(n_((unsigned char *)"%ld in use", (unsigned char *)"%ld in use", val, term));
	add_to_string(&info, (const unsigned char *)", ");

	val = get_cache_entry_loading_count();
	val_add(n_((unsigned char *)"%ld loading", (unsigned char *)"%ld loading", val, term));
	add_to_string(&info, (const unsigned char *)".\n");

	add_to_string(&info, _("Document cache", term));
	add_to_string(&info, (const unsigned char *)": ");

	val = get_format_cache_size();
	val_add(n_((unsigned char *)"%ld formatted", (unsigned char *)"%ld formatted", val, term));
	add_to_string(&info, (const unsigned char *)", ");

	val = get_format_cache_used_count();
	val_add(n_((unsigned char *)"%ld in use", (unsigned char *)"%ld in use", val, term));
	add_to_string(&info, (const unsigned char *)", ");

	val = get_format_cache_refresh_count();
	val_add(n_((unsigned char *)"%ld refreshing", (unsigned char *)"%ld refreshing", val, term));
	add_to_string(&info, (const unsigned char *)".\n");

#ifdef CONFIG_ECMASCRIPT
	add_to_string(&info, _("ECMAScript", term));
	add_to_string(&info, (const unsigned char *)": ");

	val = ecmascript_get_interpreter_count();
	val_add(n_((unsigned char *)"%ld interpreter", (unsigned char *)"%ld interpreters", val, term));
	add_to_string(&info, (const unsigned char *)".\n");
#endif

	add_to_string(&info, _("Interlinking", term));
	add_to_string(&info, (const unsigned char *)": ");
	if (term->master)
		add_to_string(&info, _("master terminal", term));
	else
		add_to_string(&info, _("slave terminal", term));
	add_to_string(&info, (const unsigned char *)", ");

	val = list_size(&terminals);
	val_add(n_((unsigned char *)"%ld terminal", (unsigned char *)"%ld terminals", val, term));
	add_to_string(&info, (const unsigned char *)", ");

	val = list_size(&sessions);
	val_add(n_((unsigned char *)"%ld session", (unsigned char *)"%ld sessions", val, term));
	add_char_to_string(&info, '.');

#ifdef DEBUG_MEMLEAK
	add_char_to_string(&info, '\n');
	add_to_string(&info, _("Memory allocated", term));
	add_to_string(&info, (const unsigned char *)": ");

	val = mem_stats.amount;
	val_add(n_((unsigned char *)"%ld byte", (unsigned char *)"%ld bytes", val, term));
	add_to_string(&info, ", ");

	val = mem_stats.true_amount - mem_stats.amount;
	val_add(n_((unsigned char *)"%ld byte overhead", (unsigned char *)"%ld bytes overhead", val, term));

	add_format_to_string(&info, " (%0.2f%%).",
		(double) (mem_stats.true_amount - mem_stats.amount) / (double) mem_stats.amount * 100);
#endif /* DEBUG_MEMLEAK */

#undef val_add

	return info.source;
}
Beispiel #22
0
static unsigned char *
get_cache_entry_info(struct listbox_item *item, struct terminal *term)
{
	struct cache_entry *cached = item->udata;
	struct string msg;

	if (item->type == BI_FOLDER) return NULL;
	if (!init_string(&msg)) return NULL;

	add_to_string(&msg, _("URL", term));
	add_to_string(&msg, ": ");
	add_uri_to_string(&msg, cached->uri, URI_PUBLIC);

	/* No need to use compare_uri() here we only want to check whether they
	 * point to the same URI. */
	if (cached->proxy_uri != cached->uri) {
		add_format_to_string(&msg, "\n%s: ", _("Proxy URL", term));
		add_uri_to_string(&msg, cached->proxy_uri, URI_PUBLIC);
	}

	if (cached->redirect) {
		add_format_to_string(&msg, "\n%s: ", _("Redirect", term));
		add_uri_to_string(&msg, cached->redirect, URI_PUBLIC);

		if (cached->redirect_get) {
			add_to_string(&msg, " (GET)");
		}
	}

	add_format_to_string(&msg, "\n%s: %" OFF_PRINT_FORMAT, _("Size", term),
			     (off_print_T) cached->length);
	add_format_to_string(&msg, "\n%s: %" OFF_PRINT_FORMAT, _("Loaded size", term),
			     (off_print_T) cached->data_size);
	if (cached->content_type) {
		add_format_to_string(&msg, "\n%s: %s", _("Content type", term),
				     cached->content_type);
	}
	if (cached->last_modified) {
		add_format_to_string(&msg, "\n%s: %s", _("Last modified", term),
				     cached->last_modified);
	}
	if (cached->etag) {
		add_format_to_string(&msg, "\n%s: %s", "ETag",
						cached->etag);
	}
	if (cached->ssl_info) {
		add_format_to_string(&msg, "\n%s: %s", _("SSL Cipher", term),
						cached->ssl_info);
	}
	if (cached->encoding_info) {
		add_format_to_string(&msg, "\n%s: %s", _("Encoding", term),
						cached->encoding_info);
	}

	if (cached->incomplete || !cached->valid) {
		add_char_to_string(&msg, '\n');
		add_to_string(&msg, _("Flags", term));
		add_to_string(&msg, ": ");
		if (cached->incomplete) {
			add_to_string(&msg, _("incomplete", term));
			add_char_to_string(&msg, ' ');
		}
		if (!cached->valid) add_to_string(&msg, _("invalid", term));
	}

#ifdef HAVE_STRFTIME
	if (cached->expire) {
		time_t expires = timeval_to_seconds(&cached->max_age);

		add_format_to_string(&msg, "\n%s: ", _("Expires", term));
		add_date_to_string(&msg, get_opt_str("ui.date_format", NULL), &expires);
	}
#endif

	add_format_to_string(&msg, "\n%s: ", _("Cache mode", term));
	switch (cached->cache_mode) {
	case CACHE_MODE_NEVER:
		add_to_string(&msg, _("never use cache entry", term));
		break;
	case CACHE_MODE_ALWAYS:
		add_to_string(&msg, _("always use cache entry", term));
		break;
	case CACHE_MODE_INCREMENT:
	case CACHE_MODE_NORMAL:
	case CACHE_MODE_CHECK_IF_MODIFIED:
	case CACHE_MODE_FORCE_RELOAD:
		/* Cache entries only use two values of enum cache_mode. */
		INTERNAL("cached->cache_mode = %d", cached->cache_mode);
		break;
	}

#ifdef CONFIG_DEBUG
	add_format_to_string(&msg, "\n%s: %d", "Refcount", get_object_refcount(cached));
	add_format_to_string(&msg, "\n%s: %u", _("ID", term), cached->cache_id);

	if (cached->head && *cached->head) {
		add_format_to_string(&msg, "\n%s:\n\n%s", _("Header", term),
				     cached->head);
	}
#endif

	return msg.source;
}