Пример #1
0
static int
compare_tag_item(const struct tag *a, const struct tag *b, enum tag_type type)
{
	if (a == NULL)
		return b == NULL ? 0 : -1;

	if (b == NULL)
		return 1;

	return compare_number_string(tag_get_value(a, type),
				     tag_get_value(b, type));
}
Пример #2
0
static const char *
tag_get_value_checked(const struct tag *tag, enum tag_type type)
{
	return tag != NULL
		? tag_get_value(tag, type)
		: NULL;
}
Пример #3
0
void
editMailcap(char *mailcap, struct parsed_tagarg *args)
{
    TextList *t = newTextList();
    TextListItem *ti;
    FILE *f;
    Str tmp;
    char *type, *viewer;
    struct parsed_tagarg *a;
    bool delete_it;

    if ((f = fopen(mailcap, "rt")) == NULL)
	bye("Can't open", mailcap);

    while (tmp = Strfgets(f), tmp->length > 0) {
	if (tmp->ptr[0] == '#')
	    continue;
	Strchop(tmp);
	extractMailcapEntry(tmp->ptr, &type, &viewer);
	delete_it = false;
	for (a = args; a != NULL; a = a->next) {
	    if (!strcmp(a->arg, "delete") && !strcmp(a->value, type)) {
		delete_it = true;
		break;
	    }
	}
	if (!delete_it)
	    pushText(t, Sprintf("%s;\t%s\n", type, viewer)->ptr);
    }
    type = tag_get_value(args, "newtype");
    viewer = tag_get_value(args, "newcmd");
    if (type != NULL && *type != '\0' && viewer != NULL && *viewer != '\0')
	pushText(t, Sprintf("%s;\t%s\n", type, viewer)->ptr);
    fclose(f);
    if ((f = fopen(mailcap, "w")) == NULL)
	bye("Can't write to", mailcap);

    for (ti = t->first; ti != NULL; ti = ti->next)
	fputs(ti->ptr, f);
    fclose(f);
    printf("Content-Type: text/plain\n");
    printf("w3m-control: BACK\nw3m-control: BACK\n");
    printf("w3m-control: REINIT MAILCAP\n");
}
Пример #4
0
struct page*
icy_server_metadata_page(const struct tag *tag, ...)
{
	va_list args;
	const gchar *tag_items[TAG_NUM_OF_ITEM_TYPES];
	gint last_item, item;
	guint position;
	gchar *icy_string;
	struct page *icy_metadata;
	gchar stream_title[(1 + 255 - 28) * 16]; // Length + Metadata -
						 // "StreamTitle='';StreamUrl='';"
						 // = 4081 - 28

	last_item = -1;

	va_start(args, tag);
	while (1) {
		enum tag_type type;
		const gchar *tag_item;

		type = va_arg(args, enum tag_type);

		if (type == TAG_NUM_OF_ITEM_TYPES)
			break;

		tag_item = tag_get_value(tag, type);

		if (tag_item)
			tag_items[++last_item] = tag_item;
	}
	va_end(args);

	position = item = 0;
	while (position < sizeof(stream_title) && item <= last_item) {
		gint length = 0;

		length = g_strlcpy(stream_title + position,
				   tag_items[item++],
				   sizeof(stream_title) - position);

		position += length;

		if (item <= last_item) {
			length = g_strlcpy(stream_title + position,
					   " - ",
					   sizeof(stream_title) - position);

			position += length;
		}
	}

	icy_string = icy_server_metadata_string(stream_title, "");

	if (icy_string == NULL)
		return NULL;

	icy_metadata = page_new_copy(icy_string, (icy_string[0] * 16) + 1);

	g_free(icy_string);

	return icy_metadata;
}
Пример #5
0
int
main(int argc, char *argv[], char **envp)
{
    Str mailcapfile;
    extern char *getenv();
    char *p;
    int length;
    Str qs = NULL;
    struct parsed_tagarg *cgiarg;
    char *mode;
    char *sent_cookie;

    GC_INIT();
    p = getenv("REQUEST_METHOD");
    if (p == NULL || strcasecmp(p, "post"))
	goto request_err;
    p = getenv("CONTENT_LENGTH");
    if (p == NULL || (length = atoi(p)) <= 0)
	goto request_err;

    qs = Strfgets(stdin);
    Strchop(qs);
    if (qs->length != length)
	goto request_err;
    cgiarg = cgistr2tagarg(qs->ptr);

    p = getenv("LOCAL_COOKIE_FILE");
    if (p) {
	FILE *f = fopen(p, "r");
	if (f) {
	    local_cookie = Strfgets(f)->ptr;
	    fclose(f);
	}
    }
    sent_cookie = tag_get_value(cgiarg, "cookie");
    if (local_cookie == NULL || sent_cookie == NULL ||
	strcmp(local_cookie, sent_cookie) != 0) {
	/* Local cookie doesn't match */
	bye("Local cookie doesn't match: It may be an illegal execution", "");
    }

    mode = tag_get_value(cgiarg, "mode");
    mailcapfile = Strnew_charp(expandPath(USER_MAILCAP));
    if (mode && !strcmp(mode, "edit")) {
	char *referer;
	/* check if I can edit my mailcap */
	if ((referer = getenv("HTTP_REFERER")) != NULL) {
	    if (strncmp(referer, "file://", 7) != 0 &&
		strncmp(referer, "exec://", 7) != 0) {
		/* referer is not file: nor exec: */
		bye("It may be an illegal execution\n referer=", referer);
	    }
	}
	/* edit mailcap */
	editMailcap(mailcapfile->ptr, cgiarg);
    }
    else {
	/* initial panel */
	printMailcapPanel(mailcapfile->ptr);
    }
    return 0;

  request_err:
    bye("Incomplete Request:", qs ? qs->ptr : "(null)");
    exit(1);
}
Пример #6
0
bool tag_has_type(const struct tag *tag, enum tag_type type)
{
	return tag_get_value(tag, type) != NULL;
}
Пример #7
0
int
main(int argc, char *argv[], char **envp)
{
    extern char *getenv();
    char *p;
    int length;
    Str qs = NULL;
    struct parsed_tagarg *cgiarg;
    char *mode;
    char *bmark;
    char *url;
    char *title;
    char *sent_cookie;

    p = getenv("REQUEST_METHOD");
    if (p == NULL || strcasecmp(p, "post"))
	goto request_err;
    p = getenv("CONTENT_LENGTH");
    if (p == NULL || (length = atoi(p)) <= 0)
	goto request_err;

    qs = Strfgets(stdin);
    Strchop(qs);
    if (qs->length != length)
	goto request_err;
    cgiarg = cgistr2tagarg(qs->ptr);

    p = getenv("LOCAL_COOKIE_FILE");
    if (p) {
	FILE *f = fopen(p, "r");
	if (f) {
	    Local_cookie = Strfgets(f)->ptr;
	    fclose(f);
	}
    }
    sent_cookie = tag_get_value(cgiarg, "cookie");
    if (sent_cookie == NULL || Local_cookie == NULL ||
	strcmp(sent_cookie, Local_cookie) != 0) {
	/* local cookie doesn't match: It may be an illegal invocation */
	printf("Content-Type: text/plain\n\n");
	printf("Local cookie doesn't match: It may be an illegal invocation\n");
	exit(1);
    }

    mode = tag_get_value(cgiarg, "mode");
    bmark = expandPath(tag_get_value(cgiarg, "bmark"));
    url = tag_get_value(cgiarg, "url");
    title = tag_get_value(cgiarg, "title");
    if (bmark == NULL || url == NULL)
	goto request_err;
    if (mode && !strcmp(mode, "panel")) {
	if (title == NULL)
	    title = "";
	print_bookmark_panel(bmark, url, title);
    }
    else if (mode && !strcmp(mode, "register")) {
	printf("Content-Type: text/plain\n");
	if (insert_bookmark(bmark, cgiarg)) {
	    printf("w3m-control: BACK\n");
	    printf("w3m-control: BACK\n");
	}
	printf("\n");
    }
    return 0;

  request_err:
    printf("Content-Type: text/plain\n\n");
    printf("Incomplete Request: %s\n", qs ? qs->ptr : "(null)");
    exit(1);
}
Пример #8
0
int
insert_bookmark(char *bmark, struct parsed_tagarg *data)
{
    char *url, *title, *section;
    FILE *f;
    TextList *tl = newTextList();
    int section_found = 0;
    int bmark_added = 0;
    Str tmp, section_tmp;

    url = tag_get_value(data, "url");
    title = tag_get_value(data, "title");
    section = tag_get_value(data, "newsection");
    if (section == NULL || *section == '\0')
	section = tag_get_value(data, "section");
    if (section == NULL || *section == '\0')
	section = DEFAULT_SECTION;

    if (url == NULL || *url == '\0' || title == NULL || *title == '\0') {
	/* Bookmark not added */
	return FALSE;
    }
    url = html_quote(url);
    title = html_quote(title);
    section = html_quote(section);

    f = fopen(bmark, "r");
    if (f == NULL)
	return create_new_bookmark(bmark, section, title, url, "w");

    section_tmp = Sprintf("<h2>%s</h2>\n", section);
    for (;;) {
	tmp = Strfgets(f);
	if (tmp->length == 0)
	    break;
	if (Strcasecmp(tmp, section_tmp) == 0)
	    section_found = 1;
	if (section_found && !bmark_added) {
	    Strremovefirstspaces(tmp);
	    if (Strcmp_charp(tmp, end_section) == 0) {
		pushText(tl,
			 Sprintf("<li><a href=\"%s\">%s</a>\n", url,
				 title)->ptr);
		bmark_added = 1;
	    }
	}
	if (!bmark_added && Strcasecmp_charp(tmp, "</body>\n") == 0) {
	    pushText(tl, Sprintf("<h2>%s</h2>\n<ul>\n", section)->ptr);
	    pushText(tl,
		     Sprintf("<li><a href=\"%s\">%s</a>\n", url, title)->ptr);
	    pushText(tl, end_section);
	    pushText(tl, "</ul>\n");
	    bmark_added = 1;
	}
	pushText(tl, tmp->ptr);
    }
    fclose(f);
    if (!bmark_added) {
	/* Bookmark not added; perhaps the bookmark file is ill-formed */
	/* In this case, a new bookmark is appeneded after the bookmark file */
	return create_new_bookmark(bmark, section, title, url, "a");
    }
    f = fopen(bmark, "w");
    while (tl->nitem) {
	fputs(popText(tl), f);
    }
    fclose(f);
    return TRUE;
}