Exemplo n.º 1
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
  {
  }
}
Exemplo n.º 2
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;
}
Exemplo n.º 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);
}
Exemplo n.º 4
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');
}
Exemplo n.º 5
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);
}
Exemplo n.º 6
0
/* Returns a connection state. S_OK if all is well. */
static inline struct connection_state
list_directory(struct connection *conn, unsigned char *dirpath,
	       struct string *page)
{
	int show_hidden_files = get_opt_bool((const unsigned char *)"protocol.file.show_hidden_files",
	                                     NULL);
	struct directory_entry *entries;
	struct connection_state state;

	errno = 0;
	entries = get_directory_entries(dirpath, show_hidden_files);
	if (!entries) {
		if (errno) return connection_state_for_errno(errno);
		return connection_state(S_OUT_OF_MEM);
	}

	state = init_directory_listing(page, conn->uri);
	if (!is_in_state(state, S_OK))
		return connection_state(S_OUT_OF_MEM);

	add_dir_entries(entries, dirpath, page);

	if (!add_to_string(page, (const unsigned char *)"</pre>\n<hr/>\n</body>\n</html>\n")) {
		done_string(page);
		return connection_state(S_OUT_OF_MEM);
	}

	return connection_state(S_OK);
}
Exemplo n.º 7
0
void ReverseGeoLookupThread::run() {
	if (geo_lookup_data.isEmpty())
		return;

	QNetworkRequest request;
	QNetworkAccessManager *rgl = new QNetworkAccessManager();
	request.setRawHeader("Accept", "text/json");
	request.setRawHeader("User-Agent", getUserAgent().toUtf8());
	QEventLoop loop;
	QString apiCall("http://open.mapquestapi.com/nominatim/v1/reverse.php?format=json&accept-language=%1&lat=%2&lon=%3");
	Q_FOREACH (const GeoLookupInfo& info, geo_lookup_data ) {
		request.setUrl(apiCall.arg(uiLanguage(NULL)).arg(info.lat.udeg / 1000000.0).arg(info.lon.udeg / 1000000.0));
		QNetworkReply *reply = rgl->get(request);
		QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
		loop.exec();
		QJsonParseError errorObject;
		QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &errorObject);
		if (errorObject.error != QJsonParseError::NoError) {
			qDebug() << errorObject.errorString();
		} else {
			QJsonObject obj = jsonDoc.object();
			QJsonObject address = obj.value("address").toObject();
			qDebug() << "found country:" << address.value("country").toString();
			struct dive_site *ds = get_dive_site_by_uuid(info.uuid);
			ds->notes = add_to_string(ds->notes, "countrytag: %s", address.value("country").toString().toUtf8().data());
		}

		reply->deleteLater();
	}
Exemplo n.º 8
0
Arquivo: core.c Projeto: 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;
}
Exemplo n.º 9
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));
}
Exemplo n.º 10
0
/** @relates string */
struct string *
add_xnum_to_string(struct string *string, long long xnum)
{
	unsigned char suff[3] = "\0i";
	off_t d = -1;

	/* XXX: I don't completely like the computation of d here. --pasky */
	/* Mebi (Mi), 2^20 */
	if (xnum >= 1024 * 1024) {
		suff[0] = 'M';
		d = (xnum * (int) 10 / (int) ((int) (1024 * 1024))) % 10;
		xnum /= 1024*1024;
	/* Kibi (Ki), 2^10 */
	} else if (xnum >= 1024) {
		suff[0] = 'K';
		d = (xnum * (int) 10 / (int) 1024) % 10;
		xnum /= 1024;
	}

	add_long_to_string(string, xnum);

	if (d != -1) {
		add_char_to_string(string, '.');
		add_long_to_string(string, d);
	}
	add_char_to_string(string, ' ');

	if (suff[0]) add_to_string(string, suff);
	add_char_to_string(string, 'B');
	return string;
}
Exemplo n.º 11
0
static void parse_dive_gps(char *line, struct membuffer *str, void *_dive)
{
	uint32_t uuid;
	degrees_t latitude = parse_degrees(line, &line);
	degrees_t longitude = parse_degrees(line, &line);
	struct dive *dive = _dive;
	struct dive_site *ds = get_dive_site_for_dive(dive);
	if (!ds) {
		uuid = get_dive_site_uuid_by_gps(latitude, longitude, NULL);
		if (!uuid)
			uuid = create_dive_site_with_gps("", latitude, longitude, dive->when);
		dive->dive_site_uuid = uuid;
	} else {
		if (dive_site_has_gps_location(ds) &&
		    (ds->latitude.udeg != latitude.udeg || ds->longitude.udeg != longitude.udeg)) {
			const char *coords = printGPSCoords(latitude.udeg, longitude.udeg);
			// we have a dive site that already has GPS coordinates
			ds->notes = add_to_string(ds->notes, translate("gettextFromC", "multiple GPS locations for this dive site; also %s\n"), coords);
			free((void *)coords);
		}
		ds->latitude = latitude;
		ds->longitude = longitude;
	}

}
Exemplo n.º 12
0
/** @relates string */
struct string *
add_duration_to_string(struct string *string, long seconds)
{
	unsigned char q[64];
	int qlen = 0;

	if (seconds < 0) seconds = 0;

	/* Days */
	if (seconds >= (24 * 3600)) {
		ulongcat(q, &qlen, (seconds / (24 * 3600)), 5, 0);
		q[qlen++] = 'd';
		q[qlen++] = ' ';
	}

	/* Hours and minutes */
	if (seconds >= 3600) {
		seconds %= (24 * 3600);
		ulongcat(q, &qlen, (seconds / 3600), 4, 0);
		q[qlen++] = ':';
		ulongcat(q, &qlen, ((seconds / 60) % 60), 2, '0');
	} else {
		/* Only minutes */
		ulongcat(q, &qlen, (seconds / 60), 2, 0);
	}

	/* Seconds */
	q[qlen++] = ':';
	ulongcat(q, &qlen, (seconds % 60), 2, '0');

	add_to_string(string, q);
	return string;
}
Exemplo n.º 13
0
Arquivo: smb2.c Projeto: Efreak/elinks
/** First information such as permissions is gathered for each directory entry.
 * All entries are then sorted. */
static struct directory_entry *
get_smb_directory_entries(int dir, struct string *prefix)
{
	struct directory_entry *entries = NULL;
	
	int size = 0;
	struct smbc_dirent *entry;

	while ((entry = smbc_readdir(dir))) {
		struct stat st, *stp;
		struct directory_entry *new_entries;
		struct string attrib;
		struct string name;

		if (!strcmp(entry->name, "."))
			continue;

		new_entries = mem_realloc(entries, (size + 2) * sizeof(*new_entries));
		if (!new_entries) continue;
		entries = new_entries;

		if (!init_string(&attrib)) {
			continue;
		}

		if (!init_string(&name)) {
			done_string(&attrib);
			continue;
		}

		add_string_to_string(&name, prefix);
		add_to_string(&name, entry->name);

		stp = (smbc_stat(name.source, &st)) ? NULL : &st;

		stat_type(&attrib, stp);
		stat_mode(&attrib, stp);
		stat_links(&attrib, stp);
		stat_user(&attrib, stp);
		stat_group(&attrib, stp);
		stat_size(&attrib, stp);
		stat_date(&attrib, stp);

		entries[size].name = stracpy(entry->name);
		entries[size].attrib = attrib.source;
		done_string(&name);
		size++;
	}
	smbc_closedir(dir);

	if (!size) {
		/* We may have allocated space for entries but added none. */
		mem_free_if(entries);
		return NULL;
	}
	qsort(entries, size, sizeof(*entries), compare_dir_entries);
	memset(&entries[size], 0, sizeof(*entries));
	return entries;
}
Exemplo n.º 14
0
Arquivo: uri.c Projeto: Efreak/elinks
/* Encodes URIs without encoding stuff like fragments and query separators. */
static void
encode_file_uri_string(struct string *string, unsigned char *uristring)
{
	int filenamelen = check_whether_file_exists(uristring);

	encode_uri_string(string, uristring, filenamelen, 0);
	if (filenamelen > 0) add_to_string(string, uristring + filenamelen);
}
Exemplo n.º 15
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;
}
Exemplo n.º 16
0
struct string *
add_shell_quoted_to_string(struct string *string, unsigned char *src, int len)
{
	add_char_to_string(string, '\'');
	for (; len; len--, ++src)
		if (*src == '\'')
			add_to_string(string, (const unsigned char *)"'\\''");
		else
			add_char_to_string(string, *src);
	add_char_to_string(string, '\'');

	return string;
}
Exemplo n.º 17
0
struct string *
add_date_to_string(struct string *string, const unsigned char *fmt,
		   const time_t *date)
{
	unsigned char buffer[MAX_STR_LEN];
	time_t when_time = date ? *date : time(NULL);
	struct tm *when_local = localtime(&when_time);

	if (strftime((char *)buffer, sizeof(buffer), (const char *)fmt, when_local) <= 0)
		return NULL;

	return add_to_string(string, buffer);
}
Exemplo n.º 18
0
void delete_configuration(struct node **head, struct boot_option *to_delete,
		char *boot_dir)
{
	/* Handle to_delete is the head node */
	if (to_delete == (struct boot_option *)(*head)->data)
		*head = (*head)->next;

	struct node *current = (*head)->next;
	struct node *previous = *head;

	while (current->data) {
		if ((struct boot_option *)current->data == to_delete) {
			remove_node(previous);
			break;
		}
		current = current->next;
		previous = previous->next;
	}

	char *image;

	if (to_delete->image != NULL) {
		image = NULL;
		image = add_to_string(image, 3, boot_dir, "/", basename(to_delete->image));
		remove(image);
		free(image);
	}
	char *initrd;

	if (to_delete->initrd != NULL) {
		initrd = NULL;
		initrd = add_to_string(initrd, 3, boot_dir, "/", basename(to_delete->initrd));
		remove(initrd);
		free(initrd);
	}
	free_boot_option(to_delete);
}
Exemplo n.º 19
0
static void
add_nntp_html_end(struct string *html, struct connection *conn)
{
	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_to_string(html, "</pre>");
		break;

	case NNTP_TARGET_ARTICLE_RANGE:
	case NNTP_TARGET_GROUP:
	case NNTP_TARGET_GROUPS:
		add_to_string(html, "</ol>");
		break;

	case NNTP_TARGET_QUIT:
		break;
	}

	add_to_string(html, "\n<hr />\n</body>\n</html>");
}
Exemplo n.º 20
0
static void
roman(struct string  *p, unsigned n)
{
	int i = 0;

	if (n >= 4000) {
		add_to_string(p, (const unsigned char *)"---");
		return;
	}
	if (!n) {
		add_to_string(p, (const unsigned char *)"o");
		return;
	}
	while (n) {
		while (roman_tbl[i].n <= n) {
			n -= roman_tbl[i].n;
			add_to_string(p, roman_tbl[i].s);
		}
		i++;
		assertm(!(n && !roman_tbl[i].n),
			"BUG in roman number convertor");
		if_assert_failed break;
	}
}
Exemplo n.º 21
0
/* The global Kernel::p method will for each object, directly write
 * object.inspect() followed by the current output record separator to the
 * program's standard output and will bypass the Ruby I/O libraries.
 *
 * Inspired by Vim we hook into the method and pop up a nice message box so it
 * can be used to easily debug scripts without dirtying the screen. */
static VALUE
erb_stdout_p(int argc, VALUE *argv, VALUE self)
{
	int i;
	struct string string;
	struct terminal *term;

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

	for (i = 0; i < argc; i++) {
		VALUE substr;
		unsigned char *ptr;
		int len;

		if (i > 0)
			add_to_string(&string, ", ");

		substr = rb_inspect(argv[i]);

		/* The Ruby p() function writes variable number of objects using
		 * the inspect() method, which adds quotes to the strings, so
		 * gently ignore them. */

		ptr = RSTRING(substr)->ptr;
		len = RSTRING(substr)->len;

		if (*ptr == '"')
			ptr++, len--;

		if (ptr[len - 1] == '"')
			len--;

		add_bytes_to_string(&string, ptr, len);
	}

	term = get_default_terminal();
	if (!term) {
		usrerror("[Ruby] %s", string.source);
		done_string(&string);
		return Qnil;
	}

	info_box(term, MSGBOX_NO_TEXT_INTL | MSGBOX_FREE_TEXT,
		N_("Ruby Message"), ALIGN_LEFT, string.source);

	return Qnil;
}
Exemplo n.º 22
0
void
set_clipboard_text(unsigned char *data)
{
	/* GNU Screen's clipboard */
	if (is_gnuscreen()) {
		struct string str;

		if (!init_string(&str)) return;

		add_to_string(&str, "screen -X register . ");
		add_shell_quoted_to_string(&str, data, strlen(data));

		if (str.length) exe(str.source);
		if (str.source) done_string(&str);
	}

	/* TODO: internal clipboard */
}
Exemplo n.º 23
0
void
set_clipboard_text(unsigned char *data)
{
	/* GNU Screen's clipboard */
	if (is_gnuscreen()) {
		struct string str;

		if (!init_string(&str)) return;

		add_to_string(&str, (const unsigned char *)"screen -X register . ");
		add_shell_quoted_to_string(&str, data, strlen((const char *)data));

		if (str.length) exe(str.source);
		if (str.source) done_string(&str);
	}

	/* Shouldn't complain about leaks. */
	if (clipboard) free(clipboard);
	clipboard = (unsigned char *)strdup((const char *)data);
}
Exemplo n.º 24
0
Arquivo: fsp.c Projeto: Efreak/elinks
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);
}
void add_quoted_str_to_string(const char* str,
				     a_boolean add_quotes,
				     string_buffer_ptr bp) {
    const char* p = str;
    const char* escapee;
    if (add_quotes) {
	add_1_char_to_string('\"', bp);
    }
    for (escapee = p + strcspn(p, "\"\\"); *escapee;
         escapee = p + strcspn(p, "\"\\")) {
	const char* q = escapee - 1;
	add_to_string_with_len(p, escapee - p, bp);
	add_1_char_to_string('\\', bp);
	add_1_char_to_string(*escapee, bp);
	p = escapee + 1;
    }
    add_to_string(p, bp);
    if (add_quotes) {
	add_1_char_to_string('\"', bp);
    }
}
Exemplo n.º 26
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
  {
  }
}
Exemplo n.º 27
0
Arquivo: smb2.c Projeto: Efreak/elinks
static void
smb_directory(int dir, struct string *prefix, struct uri *uri)
{
	struct string buf;
	struct directory_entry *entries;

	if (!is_in_state(init_directory_listing(&buf, uri), S_OK)) {
		smb_error(connection_state(S_OUT_OF_MEM));
	}

	fputs("text/html", header_out);
	fclose(header_out);

	entries = get_smb_directory_entries(dir, prefix);
	add_smb_dir_entries(entries, NULL, &buf);
	add_to_string(&buf, "</pre><hr/></body></html>\n");

	fputs(buf.source, data_out);
	done_string(&buf);
	exit(0);
}
Exemplo n.º 28
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));
}
Exemplo n.º 29
0
static void parse_dive_location(char *line, struct membuffer *str, void *_dive)
{
	uint32_t uuid;
	char *name = get_utf8(str);
	struct dive *dive = _dive;
	struct dive_site *ds = get_dive_site_for_dive(dive);
	if (!ds) {
		uuid = get_dive_site_uuid_by_name(name, NULL);
		if (!uuid)
			uuid = create_dive_site(name, dive->when);
		dive->dive_site_uuid = uuid;
	} else {
		// we already had a dive site linked to the dive
		if (same_string(ds->name, "")) {
			ds->name = strdup(name);
		} else {
			// and that dive site had a name. that's weird - if our name is different, add it to the notes
			if (!same_string(ds->name, name))
				ds->notes = add_to_string(ds->notes, translate("gettextFromC", "additional name for site: %s\n"), name);
		}
	}
	free(name);
}
Exemplo n.º 30
0
unsigned char *
get_clipboard_text(void)
{
	/* The following support for GNU Screen's clipboard is
	 * disabled for two reasons:
	 *
	 * 1. It does not actually return the string from that
	 *    clipboard, but rather causes the clipboard contents to
	 *    appear in stdin.	get_clipboard_text is normally called
	 *    because the user pressed a Paste key in an input field,
	 *    so the characters end up being inserted in that field;
	 *    but if there are newlines in the clipboard, then the
	 *    field may lose focus, in which case the remaining
	 *    characters may trigger arbitrary actions in ELinks.
	 *
	 * 2. It pastes from both GNU Screen's clipboard and the ELinks
	 *    internal clipboard.  Because set_clipboard_text also sets
	 *    them both, the same text would typically get pasted twice.
	 *
	 * Users can instead use the GNU Screen key bindings to run the
	 * paste command.  This method still suffers from problem 1 but
	 * any user of GNU Screen should know that already.  */
#if 0
	/* GNU Screen's clipboard */
	if (is_gnuscreen()) {
		struct string str;

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

		add_to_string(&str, (const unsigned char *)"screen -X paste .");
		if (str.length) exe(str.source);
		if (str.source) done_string(&str);
	}
#endif

	return stracpy(empty_string_or_(clipboard));
}