コード例 #1
0
ファイル: mhshowsbr.c プロジェクト: dscho/nmh
static int
show_multi_aux (CT ct, int serial, int alternate, char *cp)
{
    int len, buflen, quoted;
    int xlist, xpause, xtty;
    char *bp, *pp, *file, buffer[BUFSIZ];
    struct multipart *m = (struct multipart *) ct->c_ctparams;
    struct part *part;
    CI ci = &ct->c_ctinfo;
    CT p;

    for (part = m->mp_parts; part; part = part->mp_next) {
	p = part->mp_part;

	if (!p->c_ceopenfnx) {
	    if (!alternate)
		content_error (NULL, p, "don't know how to decode content");
	    return NOTOK;
	}

	if (p->c_storage == NULL) {
	    file = NULL;
	    if ((*p->c_ceopenfnx) (p, &file) == NOTOK)
		return NOTOK;

	    /* I'm not sure if this is necessary? */
	    p->c_storage = add (file, NULL);

	    if (p->c_showproc && !strcmp (p->c_showproc, "true"))
		return (alternate ? DONE : OK);
	    (*p->c_ceclosefnx) (p);
	}
    }

    xlist     = 0;
    xpause    = 0;
    xtty      = 0;

    /* get buffer ready to go */
    bp = buffer;
    buflen = sizeof(buffer) - 1;
    bp[0] = bp[buflen] = '\0';
    quoted = 0;

    /* Now parse display string */
    for ( ; *cp && buflen > 0; cp++) {
	if (*cp == '%') {
	    pp = bp;
	    switch (*++cp) {
	    case 'a':
		/* insert parameters from Content-Type field */
	    {
		char **ap, **ep;
		char *s = "";

		for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
		    snprintf (bp, buflen, "%s%s=\"%s\"", s, *ap, *ep);
		    len = strlen (bp);
		    bp += len;
		    buflen -= len;
		    s = " ";
		}
	    }
	    break;

	    case 'd':
		/* insert content description */
		if (ct->c_descr) {
		    char *s;

		    s = trimcpy (ct->c_descr);
		    strncpy (bp, s, buflen);
		    free (s);
		}
		break;

	    case 'e':
		/* exclusive execution */
		xtty = 1;
		break;

	    case 'F':
		/* %e and %f */
		xtty = 1;
		/* and fall... */

	    case 'f':
		/* insert filename(s) containing content */
	    {
		char *s = "";
			
		for (part = m->mp_parts; part; part = part->mp_next) {
		    p = part->mp_part;

		    snprintf (bp, buflen, "%s'%s'", s, p->c_storage);
		    len = strlen (bp);
		    bp += len;
		    buflen -= len;
		    s = " ";
		}
		/* set our starting pointer back to bp, to avoid
		 * requoting the filenames we just added
		 */
		pp = bp;
	    }
	    break;

	    case 'p':
		/* %l, and pause prior to displaying content */
		xpause = pausesw;
		/* and fall... */

	    case 'l':
		/* display listing prior to displaying content */
		xlist = !nolist;
		break;

	    case 's':
		/* insert subtype of content */
		strncpy (bp, ci->ci_subtype, buflen);
		break;

	    case '%':
		/* insert character % */
		goto raw;

	    default:
		*bp++ = *--cp;
		*bp = '\0';
		buflen--;
		continue;
	    }
	    len = strlen (bp);
	    bp += len;
	    buflen -= len;

	    /* Did we actually insert something? */
	    if (bp != pp) {
		/* Insert single quote if not inside quotes already */
		if (!quoted && buflen) {
		    len = strlen (pp);
		    memmove (pp + 1, pp, len);
		    *pp++ = '\'';
		    buflen--;
		    bp++;
		}
		/* Escape existing quotes */
		while ((pp = strchr (pp, '\'')) && buflen > 3) {
		    len = strlen (pp++);
		    memmove (pp + 3, pp, len);
		    *pp++ = '\\';
		    *pp++ = '\'';
		    *pp++ = '\'';
		    buflen -= 3;
		    bp += 3;
		}
		/* If pp is still set, that means we ran out of space. */
		if (pp)
		    buflen = 0;
		if (!quoted && buflen) {
		    *bp++ = '\'';
		    *bp = '\0';
		    buflen--;
		}
	    }
	} else {
raw:
	    *bp++ = *cp;
	    *bp = '\0';
	    buflen--;

	    if (*cp == '\'')
		quoted = !quoted;
	}
    }

    if (buflen <= 0 ||
        (ct->c_termproc && buflen <= (ssize_t) strlen(ct->c_termproc))) {
	/* content_error would provide a more useful error message
	 * here, except that if we got overrun, it probably would
	 * too.
	 */
	fprintf(stderr, "Buffer overflow constructing show command!\n");
	return NOTOK;
    }

    /* use charset string to modify display method */
    if (ct->c_termproc) {
	char term[BUFSIZ];

	strncpy (term, buffer, sizeof(term));
	snprintf (buffer, sizeof(buffer), ct->c_termproc, term);
    }

    return show_content_aux2 (ct, serial, alternate, NULL, buffer,
			      NOTOK, xlist, xpause, 0, xtty);
}
コード例 #2
0
ファイル: seq_read.c プロジェクト: dscho/nmh
static void
seq_public (struct msgs *mp, int lockflag)
{
    int state;
    char *cp, seqfile[PATH_MAX];
    char name[NAMESZ], field[BUFSIZ];
    FILE *fp;
    m_getfld_state_t gstate = 0;

    /*
     * If mh_seq == NULL or if *mh_seq == '\0' (the user has defined
     * the "mh-sequences" profile entry, but left it empty),
     * then just return, and do not initialize any public sequences.
     */
    if (mh_seq == NULL || *mh_seq == '\0')
	return;

    /* get filename of sequence file */
    snprintf (seqfile, sizeof(seqfile), "%s/%s", mp->foldpath, mh_seq);

    if ((fp = lkfopendata (seqfile, lockflag ? "r+" : "r")) == NULL)
	return;

    /* Use m_getfld to scan sequence file */
    for (;;) {
	int fieldsz = sizeof field;
	switch (state = m_getfld (&gstate, name, field, &fieldsz, fp)) {
	    case FLD: 
	    case FLDPLUS:
		if (state == FLDPLUS) {
		    cp = getcpy (field);
		    while (state == FLDPLUS) {
			fieldsz = sizeof field;
			state = m_getfld (&gstate, name, field, &fieldsz, fp);
			cp = add (field, cp);
		    }
		    seq_init (mp, getcpy (name), trimcpy (cp));
		    free (cp);
		} else {
		    seq_init (mp, getcpy (name), trimcpy (field));
		}
		continue;

	    case BODY:
	    	lkfclosedata (fp, seqfile);
		adios (NULL, "no blank lines are permitted in %s", seqfile);
		/* fall */

	    case FILEEOF:
		break;

	    default: 
	    	lkfclosedata (fp, seqfile);
		adios (NULL, "%s is poorly formatted", seqfile);
	}
	break;	/* break from for loop */
    }
    m_getfld_state_destroy (&gstate);

    if (lockflag) {
	mp->seqhandle = fp;
	mp->seqname = getcpy(seqfile);
    } else {
	lkfclosedata (fp, seqfile);
    }
}
コード例 #3
0
ファイル: mhshowsbr.c プロジェクト: dscho/nmh
int
show_content_aux (CT ct, int serial, int alternate, char *cp, char *cracked)
{
    int fd, len, buflen, quoted;
    int	xstdin, xlist, xpause, xtty;
    char *bp, *pp, *file, buffer[BUFSIZ];
    CI ci = &ct->c_ctinfo;

    if (!ct->c_ceopenfnx) {
	if (!alternate)
	    content_error (NULL, ct, "don't know how to decode content");

	return NOTOK;
    }

    file = NULL;
    if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK)
	return NOTOK;
    if (ct->c_showproc && !strcmp (ct->c_showproc, "true"))
	return (alternate ? DONE : OK);
    
    xlist  = 0;
    xpause = 0;
    xstdin = 0;
    xtty   = 0;

    if (cracked) {
	strncpy (buffer, cp, sizeof(buffer));
	goto got_command;
    }

    /* get buffer ready to go */
    bp = buffer;
    buflen = sizeof(buffer) - 1;
    bp[0] = bp[buflen] = '\0';
    quoted = 0;

    /* Now parse display string */
    for ( ; *cp && buflen > 0; cp++) {
	if (*cp == '%') {
	    pp = bp;

	    switch (*++cp) {
	    case 'a':
		/* insert parameters from Content-Type field */
	    {
		char **ap, **ep;
		char *s = "";

		for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
		    snprintf (bp, buflen, "%s%s=\"%s\"", s, *ap, *ep);
		    len = strlen (bp);
		    bp += len;
		    buflen -= len;
		    s = " ";
		}
	    }
	    break;

	    case 'd':
		/* insert content description */
		if (ct->c_descr) {
		    char *s;

		    s = trimcpy (ct->c_descr);
		    strncpy (bp, s, buflen);
		    free (s);
		}
		break;

	    case 'e':
		/* exclusive execution */
		xtty = 1;
		break;

	    case 'F':
		/* %e, %f, and stdin is terminal not content */
		xstdin = 1;
		xtty = 1;
		/* and fall... */

	    case 'f':
		/* insert filename containing content */
		snprintf (bp, buflen, "'%s'", file);
		/* since we've quoted the file argument, set things up
		 * to look past it, to avoid problems with the quoting
		 * logic below.  (I know, I should figure out what's
		 * broken with the quoting logic, but..)
		 */
		len = strlen(bp);
		buflen -= len;
		bp += len;
		pp = bp;
		break;

	    case 'p':
		/* %l, and pause prior to displaying content */
		xpause = pausesw;
		/* and fall... */

	    case 'l':
		/* display listing prior to displaying content */
		xlist = !nolist;
		break;

	    case 's':
		/* insert subtype of content */
		strncpy (bp, ci->ci_subtype, buflen);
		break;

	    case '%':
		/* insert character % */
		goto raw;

	    default:
		*bp++ = *--cp;
		*bp = '\0';
		buflen--;
		continue;
	    }
	    len = strlen (bp);
	    bp += len;
	    buflen -= len;

	    /* Did we actually insert something? */
	    if (bp != pp) {
		/* Insert single quote if not inside quotes already */
		if (!quoted && buflen) {
		    len = strlen (pp);
		    memmove (pp + 1, pp, len);
		    *pp++ = '\'';
		    buflen--;
		    bp++;
		}
		/* Escape existing quotes */
		while ((pp = strchr (pp, '\'')) && buflen > 3) {
		    len = strlen (pp++);
		    memmove (pp + 3, pp, len);
		    *pp++ = '\\';
		    *pp++ = '\'';
		    *pp++ = '\'';
		    buflen -= 3;
		    bp += 3;
		}
		/* If pp is still set, that means we ran out of space. */
		if (pp)
		    buflen = 0;
		if (!quoted && buflen) {
		    *bp++ = '\'';
		    *bp = '\0';
		    buflen--;
		}
	    }
	} else {
raw:
	    *bp++ = *cp;
	    *bp = '\0';
	    buflen--;

	    if (*cp == '\'')
		quoted = !quoted;
	}
    }

    if (buflen <= 0 ||
        (ct->c_termproc && (size_t) buflen <= strlen(ct->c_termproc))) {
	/* content_error would provide a more useful error message
	 * here, except that if we got overrun, it probably would
	 * too.
	 */
	fprintf(stderr, "Buffer overflow constructing show command!\n");
	return NOTOK;
    }

    /* use charset string to modify display method */
    if (ct->c_termproc) {
	char term[BUFSIZ];

	strncpy (term, buffer, sizeof(term));
	snprintf (buffer, sizeof(buffer), ct->c_termproc, term);
    }

got_command:
    return show_content_aux2 (ct, serial, alternate, cracked, buffer,
			      fd, xlist, xpause, xstdin, xtty);
}
コード例 #4
0
ファイル: readconfig.c プロジェクト: ella13/nmh
void
readconfig (struct node **npp, FILE *ib, char *file, int ctx)
{
    register int state;
    register char *cp;
    char name[NAMESZ], field[BUFSIZ];
    register struct node *np;
    register struct procstr *ps;

    if (npp == NULL && (npp = opp) == NULL) {
	admonish (NULL, "bug: readconfig called but pump not primed");
	return;
    }

    for (state = FLD;;) {
	switch (state = m_getfld (state, name, field, sizeof(field), ib)) {
	    case FLD:
	    case FLDPLUS:
	    case FLDEOF:
		np = (struct node *) mh_xmalloc (sizeof(*np));
		*npp = np;
		*(npp = &np->n_next) = NULL;
		np->n_name = getcpy (name);
		if (state == FLDPLUS) {
		    cp = getcpy (field);
		    while (state == FLDPLUS) {
			state = m_getfld (state, name, field, sizeof(field), ib);
			cp = add (field, cp);
		    }
		    np->n_field = trimcpy (cp);
		    free (cp);
		} else {
		    np->n_field = trimcpy (field);
		}
		np->n_context = ctx;

		/*
		 * Now scan the list of `procs' and link in the
		 * field value to the global variable.
		 */
		for (ps = procs; ps->procname; ps++)
		    if (strcmp (np->n_name, ps->procname) == 0) {
			*ps->procnaddr = np->n_field;
			break;
		    }
		if (state == FLDEOF)
		    break;
		continue;

	    case BODY:
	    case BODYEOF:
		adios (NULL, "no blank lines are permitted in %s", file);

	    case FILEEOF:
		break;

	    default:
		adios (NULL, "%s is poorly formatted", file);
	}
	break;
    }

    opp = npp;
}