コード例 #1
0
ファイル: vparse.c プロジェクト: JensErat/cyrus-imapd
static int _parse_entry_multivalue(struct vparse_state *state)
{
    state->entry->multivalue = 1;
    state->entry->v.values = strarray_new();

    NOTESTART();

    while (*state->p) {
        switch (*state->p) {
        /* only one type of quoting */
        case '\\':
            /* seen in the wild - \n split by line wrapping */
            if (state->p[1] == '\r') INC(1);
            if (state->p[1] == '\n') {
                if (state->p[2] != ' ' && state->p[2] != '\t')
                    return PE_BACKQUOTE_EOF;
                INC(2);
            }
            if (!state->p[1])
                return PE_BACKQUOTE_EOF;
            if (state->p[1] == 'n' || state->p[1] == 'N')
                PUTC('\n');
            else
                PUTC(state->p[1]);
            INC(2);
            break;

        case ';':
            strarray_appendm(state->entry->v.values, buf_dup_cstring(&state->buf));
            INC(1);
            break;

        case '\r':
            INC(1);
            break; /* just skip */
        case '\n':
            if (state->p[1] == ' ' || state->p[1] == '\t') {/* wrapped line */
                INC(2);
                break;
            }
            /* otherwise it's the end of the value */
            INC(1);
            goto out;

        default:
            PUTC(*state->p);
            INC(1);
            break;
        }
    }

out:
    /* reaching the end of the file isn't a failure here,
     * it's just another type of end-of-value */
    strarray_appendm(state->entry->v.values, buf_dup_cstring(&state->buf));
    return 0;
}
コード例 #2
0
ファイル: test.c プロジェクト: pmhahn/cyrus-imapd
static void fill_cache(message_data_t *m)
{
    rewind(m->data);

    /* let's fill that header cache */
    for (;;) {
	char *name, *body;
	strarray_t *contents;

	if (parseheader(m->data, &name, &body) < 0) {
	    break;
	}
	/* put it in the hash table */
	contents = (strarray_t *)hash_lookup(name, &m->cache);
	if (!contents)
	    contents = hash_insert(name, strarray_new(), &m->cache);
	strarray_appendm(contents, body);
	free(name);
    }

    m->cache_full = 1;
}
コード例 #3
0
ファイル: notifyd.c プロジェクト: JensErat/cyrus-imapd
static int do_notify(void)
{
    struct sockaddr_un sun_data;
    socklen_t sunlen = sizeof(sun_data);
    char buf[NOTIFY_MAXSIZE+1], *cp, *tail;
    int r, i;
    char *method, *class, *priority, *user, *mailbox, *message;
    strarray_t options = STRARRAY_INITIALIZER;
    long nopt;
    char *reply;
    char *fname;
    notifymethod_t *nmethod;

    while (1) {
        method = class = priority = user = mailbox = message = reply = NULL;
        nopt = 0;

        if (signals_poll() == SIGHUP) {
            /* caught a SIGHUP, return */
            return 0;
        }
        r = recvfrom(soc, buf, NOTIFY_MAXSIZE, 0,
                     (struct sockaddr *) &sun_data, &sunlen);
        if (r == -1) {
            return (errno);
        }
        buf[r] = '\0';

        tail = buf + r - 1;

        /*
         * parse request of the form:
         *
         * method NUL class NUL priority NUL user NUL mailbox NUL
         *   nopt NUL N(option NUL) message NUL
         */
        method = (cp = buf);

        if (cp) class = (cp = fetch_arg(cp, tail));
        if (cp) priority = (cp = fetch_arg(cp, tail));
        if (cp) user = (cp = fetch_arg(cp, tail));
        if (cp) mailbox = (cp = fetch_arg(cp, tail));

        if (cp) cp = fetch_arg(cp, tail); /* skip to nopt */
        if (cp) nopt = strtol(cp, NULL, 10);
        if (nopt < 0 || errno == ERANGE) cp = NULL;

        for (i = 0; cp && i < nopt; i++)
            strarray_appendm(&options, cp = fetch_arg(cp, tail));

        if (cp) message = (cp = fetch_arg(cp, tail));
        if (cp) fname = (cp = fetch_arg(cp, tail));

        if (!message) {
            syslog(LOG_ERR, "malformed notify request");
            strarray_fini(&options);
            return 0;
        }

        if (!*method)
            nmethod = default_method;
        else {
            nmethod = methods;
            while (nmethod->name) {
                if (!strcasecmp(nmethod->name, method)) break;
                nmethod++;
            }
        }

        syslog(LOG_DEBUG, "do_notify using method '%s'",
               nmethod->name ? nmethod->name: "unknown");

        if (nmethod->name) {
            reply = nmethod->notify(class, priority, user, mailbox,
                                    nopt, options.data, message, fname);
        }
#if 0  /* we don't care about responses right now */
        else {