Permalink
Browse files

dlist_parse: add optional alt_reserve_base argument

Allows caller to specify their own base directory to spool message files to,
rather than using one derived from the received message's partition.
  • Loading branch information...
elliefm committed Jan 26, 2016
1 parent cd0a09c commit 152f59c608232711f9c58821ac245617544c1b91
Showing with 32 additions and 17 deletions.
  1. +2 −2 backup/backupd.c
  2. +1 −1 backup/lcb_internal.c
  3. +1 −1 imap/append.c
  4. +25 −10 imap/dlist.c
  5. +1 −1 imap/dlist.h
  6. +1 −1 imap/notify.c
  7. +1 −1 imap/sync_support.c
View
@@ -639,7 +639,7 @@ static void cmdloop(void)
if (!backupd_userid) goto nologin;
if (!strcmp(cmd.s, "Apply")) {
struct dlist *dl = NULL;
c = dlist_parse(&dl, DLIST_SFILE | DLIST_PARSEKEY, backupd_in);
c = dlist_parse(&dl, DLIST_SFILE | DLIST_PARSEKEY, backupd_in, NULL); // FIXME
if (c == EOF) goto missingargs;
if (c == '\r') c = prot_getc(backupd_in);
if (c != '\n') goto extraargs;
@@ -674,7 +674,7 @@ static void cmdloop(void)
if (!backupd_userid) goto nologin;
if (!strcmp(cmd.s, "Get")) {
struct dlist *dl = NULL;
c = dlist_parse(&dl, DLIST_SFILE | DLIST_PARSEKEY, backupd_in);
c = dlist_parse(&dl, DLIST_SFILE | DLIST_PARSEKEY, backupd_in, NULL); // FIXME
if (c == EOF) goto missingargs;
if (c == '\r') c = prot_getc(backupd_in);
if (c != '\n') goto extraargs;
View
@@ -77,7 +77,7 @@ HIDDEN int parse_backup_line(struct protstream *in, time_t *ts,
if (c == EOF)
goto fail;
c = dlist_parse(&dl, DLIST_SFILE | DLIST_PARSEKEY, in);
c = dlist_parse(&dl, DLIST_SFILE | DLIST_PARSEKEY, in, NULL); // FIXME
if (!dl) {
fprintf(stderr, "\ndidn't parse dlist, error %i\n", c);
View
@@ -421,7 +421,7 @@ static int callout_receive_reply(const char *callout,
prot_setisclient(p, 1);
/* read and parse the reply as a dlist */
c = dlist_parse(results, /*flags*/0, p);
c = dlist_parse(results, /*flags*/0, p, NULL);
r = (c == EOF ? IMAP_SYS_ERROR : 0);
out:
View
@@ -174,16 +174,29 @@ EXPORTED const char *dlist_reserve_path(const char *part, int isarchive,
const struct message_guid *guid)
{
static char buf[MAX_MAILBOX_PATH];
const char *base = isarchive ? config_archivepartitiondir(part)
: config_partitiondir(part);
const char *base;
/* part can be either a configured partition name, or a path */
if (strchr(part, '/')) {
base = part;
}
else {
base = isarchive ? config_archivepartitiondir(part)
: config_partitiondir(part);
}
/* we expect to have a base at this point, so let's assert that */
assert(base != NULL);
snprintf(buf, MAX_MAILBOX_PATH, "%s/sync./%lu/%s",
base, (unsigned long)getpid(),
message_guid_encode(guid));
/* gotta make sure we can create files */
if (cyrus_mkdir(buf, 0755)) {
/* it's going to fail later, but at least this will help */
syslog(LOG_ERR, "IOERROR: failed to create %s/%lu/ for reserve: %m",
config_partitiondir(part), (unsigned long)getpid());
syslog(LOG_ERR, "IOERROR: failed to create %s/sync./%lu/ for reserve: %m",
base, (unsigned long)getpid());
}
return buf;
}
@@ -1040,7 +1053,8 @@ static char next_nonspace(struct protstream *in, char c)
return c;
}
EXPORTED char dlist_parse(struct dlist **dlp, unsigned int flags, struct protstream *in)
EXPORTED char dlist_parse(struct dlist **dlp, unsigned int flags,
struct protstream *in, const char *alt_reserve_base)
{
struct dlist *dl = NULL;
static struct buf kbuf;
@@ -1067,7 +1081,7 @@ EXPORTED char dlist_parse(struct dlist **dlp, unsigned int flags, struct protstr
while (c != ')') {
struct dlist *di = NULL;
prot_ungetc(c, in);
c = dlist_parse(&di, (flags & ~DLIST_PARSEKEY), in);
c = dlist_parse(&di, (flags & ~DLIST_PARSEKEY), in, alt_reserve_base);
if (di) dlist_stitch(dl, di);
c = next_nonspace(in, c);
if (c == EOF) goto fail;
@@ -1083,7 +1097,7 @@ EXPORTED char dlist_parse(struct dlist **dlp, unsigned int flags, struct protstr
while (c != ')') {
struct dlist *di = NULL;
prot_ungetc(c, in);
c = dlist_parse(&di, (flags | DLIST_PARSEKEY), in);
c = dlist_parse(&di, (flags | DLIST_PARSEKEY), in, alt_reserve_base);
if (di) dlist_stitch(dl, di);
c = next_nonspace(in, c);
if (c == EOF) goto fail;
@@ -1114,7 +1128,8 @@ EXPORTED char dlist_parse(struct dlist **dlp, unsigned int flags, struct protstr
dl = dlist_setsfile(NULL, kbuf.s, pbuf.s, &tmp_guid, sbuf.s, sbuf.len);
}
else {
if (reservefile(in, pbuf.s, &tmp_guid, size, &fname)) goto fail;
const char *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 */
@@ -1154,7 +1169,7 @@ EXPORTED char dlist_parse(struct dlist **dlp, unsigned int flags, struct protstr
EXPORTED char dlist_parse_asatomlist(struct dlist **dlp, unsigned int flags,
struct protstream *in)
{
char c = dlist_parse(dlp, flags, in);
char c = dlist_parse(dlp, flags, in, NULL);
/* make a list with one item */
if (*dlp && !dlist_isatomlist(*dlp)) {
@@ -1175,7 +1190,7 @@ EXPORTED int dlist_parsemap(struct dlist **dlp, unsigned int flags,
stream = prot_readmap(base, len);
prot_setisclient(stream, 1); /* don't sync literals */
c = dlist_parse(&dl, flags, stream);
c = dlist_parse(&dl, flags, stream, NULL);
prot_free(stream);
if (c != EOF) {
View
@@ -232,7 +232,7 @@ void dlist_print(const struct dlist *dl, int printkeys,
void dlist_printbuf(const struct dlist *dl, int printkeys,
struct buf *outbuf);
char dlist_parse(struct dlist **dlp, unsigned int flags,
struct protstream *in);
struct protstream *in, const char *alt_reserve_base);
char dlist_parse_asatomlist(struct dlist **dlp, unsigned int flags,
struct protstream *in);
int dlist_parsemap(struct dlist **dlp, unsigned int flags,
View
@@ -133,7 +133,7 @@ static void notify_dlist(const char *sockpath, const char *method,
prot_printf(out, "\r\n");
prot_flush(out);
c = dlist_parse(&res, DLIST_PARSEKEY, in);
c = dlist_parse(&res, DLIST_PARSEKEY, in, NULL);
if (c == '\r') c = prot_getc(in);
/* XXX - do something with the response? Like have NOTIFY answer */
if (c == '\n' && res && res->name) {
View
@@ -1311,7 +1311,7 @@ struct dlist *sync_parseline(struct protstream *in)
struct dlist *dl = NULL;
char c;
c = dlist_parse(&dl, DLIST_PARSEKEY, in);
c = dlist_parse(&dl, DLIST_PARSEKEY, in, NULL);
/* end line - or fail */
if (c == '\r') c = prot_getc(in);

0 comments on commit 152f59c

Please sign in to comment.