Beispiel #1
0
/*
 * Read a single log item from a sync log file.  The item will be
 * returned as three constant strings.  The first string is the type of
 * the item (e.g. "MAILBOX") and is always capitalised.  The second and
 * third strings are arguments.
 *
 * Returns 0 on success, EOF when the end of the file is reached, or an
 * IMAP error code on failure.
 */
EXPORTED int sync_log_reader_getitem(sync_log_reader_t *slr,
				     const char *args[3])
{
    int c;
    const char *arg1s = NULL;
    const char *arg2s = NULL;

    if (!slr->input)
	return EOF;

    for (;;) {
	if ((c = getword(slr->input, &slr->type)) == EOF)
	    return EOF;

	/* Ignore blank lines */
	if (c == '\r') c = prot_getc(slr->input);
	if (c == '\n')
	    continue;

	if (c != ' ') {
	    syslog(LOG_ERR, "Invalid input");
	    eatline(slr->input, c);
	    continue;
	}

	if ((c = getastring(slr->input, 0, &slr->arg1)) == EOF) return EOF;
	arg1s = slr->arg1.s;

	arg2s = NULL;
	if (c == ' ') {
	    if ((c = getastring(slr->input, 0, &slr->arg2)) == EOF) return EOF;
	    arg2s = slr->arg2.s;
	}

	if (c == '\r') c = prot_getc(slr->input);
	if (c != '\n') {
	    syslog(LOG_ERR, "Garbage at end of input line");
	    eatline(slr->input, c);
	    continue;
	}

	break;
    }

    ucase(slr->type.s);
    args[0] = slr->type.s;
    args[1] = arg1s;
    args[2] = arg2s;
    return 0;
}
Beispiel #2
0
void getitemsql(ostringstream& itemsql, const uint16 itemid, const int generation)
{
    string identifier = "";
    ostringstream o;
    o << ""
      << "SELECT items.identifier "
      << "FROM   items "
      << "       INNER JOIN item_game_indices "
      << "               ON items.id = item_game_indices.item_id "
      << "WHERE  ( item_game_indices.game_index = " << itemid << " ) "
      << "       AND ( item_game_indices.generation_id = " << generation << ") ";
    identifier = getastring(o);
    itemsql << "select image from items where (identifier = \"" << identifier << "\")";
}
Beispiel #3
0
/* This handles piping of the LSUB command, because we have to figure out
 * what mailboxes actually exist before passing them to the end user.
 *
 * It is also needed if we are doing a FIND MAILBOXES, for that we do an
 * LSUB on the backend anyway, because the semantics of FIND do not allow
 * it to return nonexistant mailboxes (RFC1176), but we need to really dumb
 * down the response when this is the case.
 */
int pipe_lsub(struct backend *s, const char *userid, const char *tag,
              int force_notfatal, const char *resp)
{
    int taglen = strlen(tag);
    int c;
    int r = PROXY_OK;
    int exist_r;
    static struct buf tagb, cmd, sep, name;
    struct buf flags = BUF_INITIALIZER;

    const char *end_strip_flags[] = { " \\NonExistent)", "\\NonExistent)",
                                      " \\Noselect)", "\\Noselect)",
                                      NULL };
    const char *mid_strip_flags[] = { "\\NonExistent ",
                                      "\\Noselect ",
                                      NULL
                                    };

    assert(s);
    assert(s->timeout);

    s->timeout->mark = time(NULL) + IDLE_TIMEOUT;

    while(1) {
        c = getword(s->in, &tagb);

        if(c == EOF) {
            if(s == backend_current && !force_notfatal)
                fatal("Lost connection to selected backend", EC_UNAVAILABLE);
            proxy_downserver(s);
            r = PROXY_NOCONNECTION;
            goto out;
        }

        if(!strncmp(tag, tagb.s, taglen)) {
            char buf[2048];
            if(!prot_fgets(buf, sizeof(buf), s->in)) {
                if(s == backend_current && !force_notfatal)
                    fatal("Lost connection to selected backend",
                          EC_UNAVAILABLE);
                proxy_downserver(s);
                r = PROXY_NOCONNECTION;
                goto out;
            }
            /* Got the end of the response */
            buf_appendcstr(&s->last_result, buf);
            buf_cstring(&s->last_result);

            switch (buf[0]) {
            case 'O': case 'o':
                r = PROXY_OK;
                break;
            case 'N': case 'n':
                r = PROXY_NO;
                break;
            case 'B': case 'b':
                r = PROXY_BAD;
                break;
            default: /* huh? no result? */
                if(s == backend_current && !force_notfatal)
                    fatal("Lost connection to selected backend",
                          EC_UNAVAILABLE);
                proxy_downserver(s);
                r = PROXY_NOCONNECTION;
                break;
            }
            break; /* we're done */
        }

        c = getword(s->in, &cmd);

        if(c == EOF) {
            if(s == backend_current && !force_notfatal)
                fatal("Lost connection to selected backend", EC_UNAVAILABLE);
            proxy_downserver(s);
            r = PROXY_NOCONNECTION;
            goto out;
        }

        if(strncasecmp("LSUB", cmd.s, 4) && strncasecmp("LIST", cmd.s, 4)) {
            prot_printf(imapd_out, "%s %s ", tagb.s, cmd.s);
            r = pipe_to_end_of_response(s, force_notfatal);
            if (r != PROXY_OK)
                goto out;
        } else {
            /* build up the response bit by bit */
            int i;

            buf_reset(&flags);
            c = prot_getc(s->in);
            while(c != ')' && c != EOF) {
                buf_putc(&flags, c);
                c = prot_getc(s->in);
            }

            if(c != EOF) {
                /* terminate string */
                buf_putc(&flags, ')');
                buf_cstring(&flags);

                /* get the next character */
                c = prot_getc(s->in);
            }

            if(c != ' ') {
                if(s == backend_current && !force_notfatal)
                    fatal("Bad LSUB response from selected backend",
                          EC_UNAVAILABLE);
                proxy_downserver(s);
                r = PROXY_NOCONNECTION;
                goto out;
            }

            /* Check for flags that we should remove
             * (e.g. Noselect, NonExistent) */
            for(i=0; end_strip_flags[i]; i++)
                buf_replace_all(&flags, end_strip_flags[i], ")");

            for (i=0; mid_strip_flags[i]; i++)
                buf_replace_all(&flags, mid_strip_flags[i], NULL);

            /* Get separator */
            c = getastring(s->in, s->out, &sep);

            if(c != ' ') {
                if(s == backend_current && !force_notfatal)
                    fatal("Bad LSUB response from selected backend",
                          EC_UNAVAILABLE);
                proxy_downserver(s);
                r = PROXY_NOCONNECTION;
                goto out;
            }

            /* Get name */
            c = getastring(s->in, s->out, &name);

            if(c == '\r') c = prot_getc(s->in);
            if(c != '\n') {
                if(s == backend_current && !force_notfatal)
                    fatal("Bad LSUB response from selected backend",
                          EC_UNAVAILABLE);
                proxy_downserver(s);
                r = PROXY_NOCONNECTION;
                goto out;
            }

            /* lookup name */
            exist_r = 1;
            char *intname = mboxname_from_external(name.s, &imapd_namespace, userid);
            mbentry_t *mbentry = NULL;
            exist_r = mboxlist_lookup(intname, &mbentry, NULL);
            free(intname);
            if(!exist_r && (mbentry->mbtype & MBTYPE_RESERVE))
                exist_r = IMAP_MAILBOX_RESERVED;
            mboxlist_entry_free(&mbentry);

            /* send our response */
            /* we need to set \Noselect if it's not in our mailboxes.db */
            if (resp[0] == 'L') {
                if(!exist_r) {
                    prot_printf(imapd_out, "* %s %s \"%s\" ",
                                resp, flags.s, sep.s);
                } else {
                    prot_printf(imapd_out, "* %s (\\Noselect) \"%s\" ",
                                resp, sep.s);
                }

                prot_printstring(imapd_out, name.s);
                prot_printf(imapd_out, "\r\n");

            } else if(resp[0] == 'M' && !exist_r) {
                /* Note that it has to exist for a find response */
                prot_printf(imapd_out, "* %s ", resp);
                prot_printastring(imapd_out, name.s);
                prot_printf(imapd_out, "\r\n");
            }
        }
    } /* while(1) */

out:
    buf_free(&flags);
    return r;
}
Beispiel #4
0
void geticonsql(ostringstream& o, const pokemon_obj * pkm, int generation)
{
    string formid;
    if(pkm->ivs.isegg)
    {
        if(int(pkm->species) == int(Species::manaphy))
        {
            o << "SELECT image FROM icons_male WHERE (identifier = \"egg-manaphy\")"; // It's a Manaphy egg.
        }
        else
        {
            o << "SELECT image FROM icons_male WHERE (identifier = \"egg\")"; // It's as regular egg.
        }
    }
    else
    {
        //        int formint = pkm->forms.form;
        if(int(pkm->species) == int(Species::arceus))
        {
            //            formint = 0;
            formid = "";
        }
        else
        {
            o
                    << "SELECT pokemon_forms.form_identifier "
                    << "FROM   pokemon_forms "
                    << "       INNER JOIN pokemon_form_generations "
                    << "               ON pokemon_forms.id = pokemon_form_generations.pokemon_form_id "
                    << "       INNER JOIN pokemon "
                    << "               ON pokemon_forms.pokemon_id = pokemon.id "
                    << "WHERE  ( pokemon_form_generations.generation_id = " << generation << " ) "
                    << "       AND ( pokemon.species_id = " << (int)(pkm->species) << " ) "
                    << "       AND ( pokemon_form_generations.game_index = " << (int)(pkm->forms.form) << " ) ";
            //            << "SELECT pokemon_forms.form_identifier "
            //            << "FROM   pokemon_form_names "
            //            << "       INNER JOIN pokemon_forms "
            //            << "               ON pokemon_form_names.pokemon_form_id = pokemon_forms.id "
            //            << "       INNER JOIN pokemon "
            //            << "               ON pokemon_forms.pokemon_id = pokemon.id "
            //            << "WHERE  ( pokemon.species_id = " << (int)(pkm.species) << " ) "
            //            << "       AND ( pokemon_form_names.local_language_id = " << langid << " ) "
            //            << "       AND ( pokemon_forms.form_order = " << (int)(pkm.forms.form) << " + 1 ) ";
            formid = getastring(o);
            o.str("");
            o.clear();
        }
        o << (int)(int(pkm->species));
        if(formid != "")
        {
            o << "-" << formid;
        }
        formid = o.str().c_str();
        o.str("");
        o.clear();
        string tgender = "";
        if(((int(pkm->species) == 521) | (int(pkm->species) == 592) | (int(pkm->species) == 593)) && (calcpkmgender(pkm) == Genders::female))
        {
            tgender = "fe";
        }
        tgender += "male";
        if(int(pkm->species) == int(Species::keldeo))
        {
            switch(pkm->forms.form)
            {
            case 0:
                formid = "647-regular";
                break;
            case 1:
                formid = "647-resolution";
                break;
            }
        }
        if(int(pkm->species) == int(Species::kyurem) && pkm->forms.form != 0)
        {
            if(pkm->forms.form == 1)
            {
                formid = "646-white";
            }
            else
            {
                formid = "646-black";
            }
        }
        o << "SELECT image FROM icons_" << tgender << " WHERE (identifier = \"" << formid << "\")";
    }
}
Beispiel #5
0
void getspritesql(ostringstream& o, const pokemon_obj * pkm, int generation)
{
    o
            << "SELECT pokemon_forms.form_identifier "
            << "FROM   pokemon_forms "
            << "       INNER JOIN pokemon_form_generations "
            << "               ON pokemon_forms.id = pokemon_form_generations.pokemon_form_id "
            << "       INNER JOIN pokemon "
            << "               ON pokemon_forms.pokemon_id = pokemon.id "
            << "WHERE  ( pokemon_form_generations.generation_id = " << generation << " ) "
            << "       AND ( pokemon.species_id = " << (int)(pkm->species) << " ) "
            << "       AND ( pokemon_form_generations.game_index = " << (int)(pkm->forms.form) << " ) ";
    //            << "SELECT pokemon_forms.form_identifier "
    //            << "FROM   pokemon_form_names "
    //            << "       INNER JOIN pokemon_forms "
    //            << "               ON pokemon_form_names.pokemon_form_id = pokemon_forms.id "
    //            << "       INNER JOIN pokemon "
    //            << "               ON pokemon_forms.pokemon_id = pokemon.id "
    //            << "WHERE  ( pokemon.species_id = " << (int)(pkm.species) << " ) "
    //            << "       AND ( pokemon_form_names.local_language_id = " << langid << " ) "
    //            << "       AND ( pokemon_forms.form_order = " << (int)(pkm.forms.form) << " + 1 ) ";
    string formid = getastring(o);
    o.str("");
    o.clear();
    o << (int)(pkm->species);
    if(formid != "")
    {
        o << "-" << formid;
    }
    formid = o.str().c_str();
    string tshiny = "";
    if(getpkmshiny(pkm))
    {
        tshiny = "shiny";
    }
    else
    {
        tshiny = "normal";
    }
    if(int(pkm->species) == int(Species::keldeo))
    {
        switch(pkm->forms.form)
        {
        case 0:
            if(tshiny == "shiny")
            {
                formid = "647-regular";
            }
            else
            {
                formid = "647-ordinary";
            }
            break;
        case 1:
            formid = "647-resolution";
            break;
        }
    }
    o.str("");
    o.clear();
    string tgender = "";
    if((pkmhasgenddiff(pkm) && (calcpkmgender(pkm) == Genders::female)) & (int(pkm->species) != int(Species::torchic)) & (int(pkm->species) != int(Species::buizel)) & (int(pkm->species) != int(Species::floatzel)))
    {
        tgender = "female";
    }
    else
    {
        tgender = "male";
    }
    o << "SELECT image FROM front_" << tgender << "_" << tshiny << "_sprites WHERE (identifier = '" << formid << "')";
}
Beispiel #6
0
EXPORTED int dlist_parse(struct dlist **dlp, int parsekey,
                          struct protstream *in, const char *alt_reserve_base)
{
    struct dlist *dl = NULL;
    static struct buf kbuf;
    static struct buf vbuf;
    int c;

    /* handle the key if wanted */
    if (parsekey) {
        c = getastring(in, NULL, &kbuf);
        c = next_nonspace(in, c);
    }
    else {
        buf_setcstr(&kbuf, "");
        c = prot_getc(in);
    }

    /* connection dropped? */
    if (c == EOF) goto fail;

    /* check what sort of value we have */
    if (c == '(') {
        dl = dlist_newlist(NULL, kbuf.s);
        c = next_nonspace(in, ' ');
        while (c != ')') {
            struct dlist *di = NULL;
            prot_ungetc(c, in);
            c = dlist_parse(&di, 0, in, alt_reserve_base);
            if (di) dlist_stitch(dl, di);
            c = next_nonspace(in, c);
            if (c == EOF) goto fail;
        }
        c = prot_getc(in);
    }
    else if (c == '%') {
        /* no whitespace allowed here */
        c = prot_getc(in);
        if (c == '(') {
            dl = dlist_newkvlist(NULL, kbuf.s);
            c = next_nonspace(in, ' ');
            while (c != ')') {
                struct dlist *di = NULL;
                prot_ungetc(c, in);
                c = dlist_parse(&di, 1, in, alt_reserve_base);
                if (di) dlist_stitch(dl, di);
                c = next_nonspace(in, c);
                if (c == EOF) goto fail;
            }
        }
        else if (c == '{') {
            struct message_guid tmp_guid;
            static struct buf pbuf, gbuf;
            unsigned size = 0;
            const char *fname;
            const char *part;
            c = getastring(in, NULL, &pbuf);
            if (c != ' ') goto fail;
            c = getastring(in, NULL, &gbuf);
            if (c != ' ') goto fail;
            c = getuint32(in, &size);
            if (c != '}') goto fail;
            c = prot_getc(in);
            if (c == '\r') c = prot_getc(in);
            if (c != '\n') goto fail;
            if (!message_guid_decode(&tmp_guid, gbuf.s)) goto fail;
            part = alt_reserve_base ? alt_reserve_base : pbuf.s;
            if (reservefile(in, part, &tmp_guid, size, &fname)) goto fail;
            dl = dlist_setfile(NULL, kbuf.s, pbuf.s, &tmp_guid, size, fname);
            /* file literal */
        }
        else {
            /* unknown percent type */
            goto fail;
        }
        c = prot_getc(in);
    }
    else if (c == '{') {
        prot_ungetc(c, in);
        /* could be binary in a literal */
        c = getbastring(in, NULL, &vbuf);
        dl = dlist_setmap(NULL, kbuf.s, vbuf.s, vbuf.len);
    }
    else if (c == '\\') { /* special case for flags */
        prot_ungetc(c, in);
        c = getastring(in, NULL, &vbuf);
        dl = dlist_setflag(NULL, kbuf.s, vbuf.s);
    }
    else {
        prot_ungetc(c, in);
        c = getnastring(in, NULL, &vbuf);
        dl = dlist_setatom(NULL, kbuf.s, vbuf.s);
    }

    /* success */
    *dlp = dl;
    return c;

fail:
    dlist_free(&dl);
    return EOF;
}