示例#1
0
文件: istream.c 项目: macks/w3m
static int
ens_read(struct ens_handle *handle, char *buf, int len)
{
    if (handle->s == NULL || handle->pos == handle->s->length) {
	char *p;
	handle->s = StrmyISgets(handle->is);
	if (handle->s->length == 0)
	    return 0;
	cleanup_line(handle->s, PAGER_MODE);
	if (handle->encoding == ENC_BASE64)
	    Strchop(handle->s);
	else if (handle->encoding == ENC_UUENCODE) {
	    if (!strncmp(handle->s->ptr, "begin", 5))
		handle->s = StrmyISgets(handle->is);
	    Strchop(handle->s);
	}
	p = handle->s->ptr;
	if (handle->encoding == ENC_QUOTE)
	    handle->s = decodeQP(&p);
	else if (handle->encoding == ENC_BASE64)
	    handle->s = decodeB(&p);
	else if (handle->encoding == ENC_UUENCODE)
	    handle->s = decodeU(&p);
	handle->pos = 0;
    }

    if (len > handle->s->length - handle->pos)
	len = handle->s->length - handle->pos;

    bcopy(&handle->s->ptr[handle->pos], buf, len);
    handle->pos += len;
    return len;
}
示例#2
0
文件: rc.c 项目: galexcode/w3m
static void
interpret_rc(FILE * f)
{
    Str line;
    Str tmp;
    char *p;

    for (;;) {
	line = Strfgets(f);
	Strchop(line);
	if (line->length == 0)
	    break;
	Strremovefirstspaces(line);
	if (line->ptr[0] == '#')	/* comment */
	    continue;
	tmp = Strnew();
	p = line->ptr;
	while (*p && !IS_SPACE(*p))
	    Strcat_char(tmp, *p++);
	while (*p && IS_SPACE(*p))
	    p++;
	Strlower(tmp);
	set_param(tmp->ptr, p);
    }
}
示例#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
void
printMailcapPanel(char *mailcap)
{
    FILE *f;
    Str tmp;
    char *type, *viewer;

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

	if (!(f = fopen(mailcap, "a+")))	/* if $HOME/.mailcap is not found, make it now! */
	    bye("Can't open", mailcap);

	{
	    char *SysMailcap = getenv("SYS_MAILCAP");
	    FILE *s = fopen(SysMailcap ? SysMailcap : "/etc/mailcap", "r");
	    if (s) {
		char buffer[256];
		while (fgets(buffer, sizeof buffer, s))	/* Copy system mailcap to */
		    fputs(buffer, f);	/* users' new one         */
		fclose(s);
		rewind(f);
	    }
	}
    }
#if LANG == JA
    /* FIXME: gettextize here */
    printf("Content-Type: text/html; charset=EUC-JP\n\n");
#else
    printf("Content-Type: text/html\n\n");
#endif
    printf("<html>\n<head>\n<title>%s</title>\n</head>\n<body>\n<h1>%s</h1>\n",
	   MSG_TITLE, MSG_TITLE);
    printf("<form method=post action=\"file:///$LIB/" W3MHELPERPANEL_CMDNAME
	   "\">\n");
    printf("<input type=hidden name=mode value=edit>\n");
    printf("<input type=hidden name=cookie value=\"%s\">\n",
	   html_quote(local_cookie));
    printf("<table>\n<tr><td>%s:<td>%s=<input type=text name=newtype size=40>\n\
<tr><td><td>%s=<input type=text name=newcmd size=40>\n\
<tr><td><input type=submit name=submit value=\"%s\">\n</table>\n",
	   MSG_NEW_ENTRY, MSG_TYPE, MSG_COMMAND, MSG_REGISTER);
    printf("<p><hr width=50%%><p>\n<table border='0' cellpadding='0'>\n\
<tr><th align=left><b>%s</b><th><b>%s</b>\n",
	   MSG_TYPE, MSG_COMMAND);
    while (tmp = Strfgets(f), tmp->length > 0) {
	if (tmp->ptr[0] == '#')
	    continue;
	Strchop(tmp);
	extractMailcapEntry(tmp->ptr, &type, &viewer);
	printf("<tr valign=top><td>%s<td>%s<td nowrap>", html_quote(type),
	       html_quote(viewer));
	printf("<input type=checkbox name=delete value=\"%s\">%s\n",
	       html_quote(type), MSG_DELETE);
    }
    printf("</table>\n<input type=submit name=submit value=\"%s\">\n</form>\n\
</body>\n</html>\n",
	   MSG_DOIT);
    fclose(f);
}
示例#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
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);
}
示例#7
0
文件: ftp.c 项目: kumakichi/w3m
Str
loadFTPDir0(ParsedURL *pu)
#endif
{
    Str FTPDIRtmp;
    Str tmp;
    int status;
    volatile int sv_type;
    char *realpathname, *fn, *q;
    char **flist;
    int i, nfile, nfile_max;
    MySignalHandler(*volatile prevtrap) (SIGNAL_ARG) = NULL;
#ifdef USE_M17N
    wc_ces doc_charset = DocumentCharset;

    *charset = WC_CES_US_ASCII;
#endif
    if (current_ftp.data == NULL)
        return NULL;
    tmp = ftp_command(&current_ftp, "SYST", NULL, &status);
    if (strstr(tmp->ptr, "UNIX") != NULL || !strncmp(tmp->ptr + 4, "Windows_NT", 10))	/* :-) */
        sv_type = UNIXLIKE_SERVER;
    else
        sv_type = SERVER_NONE;
    if (pu->file == NULL || *pu->file == '\0') {
        if (sv_type == UNIXLIKE_SERVER)
            ftp_command(&current_ftp, "LIST", NULL, &status);
        else
            ftp_command(&current_ftp, "NLST", NULL, &status);
        pu->file = "/";
    }
    else {
        realpathname = file_unquote(pu->file);
        if (*realpathname == '/' && *(realpathname + 1) == '~')
            realpathname++;
        if (sv_type == UNIXLIKE_SERVER) {
            ftp_command(&current_ftp, "CWD", realpathname, &status);
            if (status == 250)
                ftp_command(&current_ftp, "LIST", NULL, &status);
        }
        else
            ftp_command(&current_ftp, "NLST", realpathname, &status);
    }
    if (status != 125 && status != 150) {
        fclose(current_ftp.data);
        current_ftp.data = NULL;
        return NULL;
    }
    tmp = parsedURL2Str(pu);
    if (Strlastchar(tmp) != '/')
        Strcat_char(tmp, '/');
    fn = html_quote(tmp->ptr);
    tmp =
        convertLine(NULL, Strnew_charp(file_unquote(tmp->ptr)), RAW_MODE,
                    charset, doc_charset);
    q = html_quote(tmp->ptr);
    FTPDIRtmp = Strnew_m_charp("<html>\n<head>\n<base href=\"", fn,
                               "\">\n<title>", q,
                               "</title>\n</head>\n<body>\n<h1>Index of ", q,
                               "</h1>\n", NULL);

    if (SETJMP(AbortLoading) != 0) {
        if (sv_type == UNIXLIKE_SERVER)
            Strcat_charp(FTPDIRtmp, "</a></pre>\n");
        else
            Strcat_charp(FTPDIRtmp, "</a></ul>\n");
        Strcat_charp(FTPDIRtmp, "<p>Transfer Interrupted!\n");
        goto ftp_end;
    }
    TRAP_ON;

    if (sv_type == UNIXLIKE_SERVER)
        Strcat_charp(FTPDIRtmp, "<pre>\n");
    else
        Strcat_charp(FTPDIRtmp, "<ul>\n<li>");
    Strcat_charp(FTPDIRtmp, "<a href=\"..\">[Upper Directory]</a>\n");

    nfile_max = 100;
    flist = New_N(char *, nfile_max);
    nfile = 0;
    if (sv_type == UNIXLIKE_SERVER) {
        char *name, *link, *date, *size, *type_str;
        int ftype, max_len, len, j;

        max_len = 20;
        while (tmp = Strfgets(current_ftp.data), tmp->length > 0) {
            Strchop(tmp);
            if ((ftype =
                        ex_ftpdir_name_size_date(tmp->ptr, &name, &link, &date,
                                                 &size)) == FTPDIR_NONE)
                continue;
            if (!strcmp(".", name) || !strcmp("..", name))
                continue;
            len = strlen(name);
            if (!len)
                continue;
            if (ftype == FTPDIR_DIR) {
                len++;
                type_str = "/";
            }
            else if (ftype == FTPDIR_LINK) {
                len++;
                type_str = "@";
            }
            else {
                type_str = " ";
            }
            if (max_len < len)
                max_len = len;
            flist[nfile++] = Sprintf("%s%s\n%s  %5s%s", name, type_str, date,
                                     size, link)->ptr;
            if (nfile == nfile_max) {
                nfile_max *= 2;
                flist = New_Reuse(char *, flist, nfile_max);
            }
        }