X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/a616a7953d87c3c51afcc8e693c48c37ec000edf..ed8d684230608a17524f91b7297e00a9d4faefd4:/uip/slocal.c?ds=sidebyside diff --git a/uip/slocal.c b/uip/slocal.c index a665d0ad..11a44cc9 100644 --- a/uip/slocal.c +++ b/uip/slocal.c @@ -31,7 +31,6 @@ #include #include -#include #include #include @@ -55,39 +54,30 @@ #include #endif /* HAVE_GETUTXENT */ -static struct swit switches[] = { -#define ADDRSW 0 - { "addr address", 0 }, -#define USERSW 1 - { "user name", 0 }, -#define FILESW 2 - { "file file", 0 }, -#define SENDERSW 3 - { "sender address", 0 }, -#define MAILBOXSW 4 - { "mailbox file", 0 }, -#define HOMESW 5 - { "home directory", -4 }, -#define INFOSW 6 - { "info data", 0 }, -#define MAILSW 7 - { "maildelivery file", 0 }, -#define VERBSW 8 - { "verbose", 0 }, -#define NVERBSW 9 - { "noverbose", 0 }, -#define SUPPRESSDUP 10 - { "suppressdup", 0 }, -#define NSUPPRESSDUP 11 - { "nosuppressdup", 0 }, -#define DEBUGSW 12 - { "debug", 0 }, -#define VERSIONSW 13 - { "version", 0 }, -#define HELPSW 14 - { "help", 0 }, - { NULL, 0 } -}; +#define SLOCAL_SWITCHES \ + X("addr address", 0, ADDRSW) \ + X("user name", 0, USERSW) \ + X("file file", 0, FILESW) \ + X("sender address", 0, SENDERSW) \ + X("mailbox file", 0, MAILBOXSW) \ + X("home directory", -4, HOMESW) \ + X("info data", 0, INFOSW) \ + X("maildelivery file", 0, MAILSW) \ + X("verbose", 0, VERBSW) \ + X("noverbose", 0, NVERBSW) \ + X("suppressdup", 0, SUPPRESSDUP) \ + X("nosuppressdup", 0, NSUPPRESSDUP) \ + X("debug", 0, DEBUGSW) \ + X("version", 0, VERSIONSW) \ + X("help", 0, HELPSW) \ + +#define X(sw, minchars, id) id, +DEFINE_SWITCH_ENUM(SLOCAL); +#undef X + +#define X(sw, minchars, id) { sw, minchars, id }, +DEFINE_SWITCH_ARRAY(SLOCAL, switches); +#undef X static int globbed = 0; /* have we built "vars" table yet? */ static int parsed = 0; /* have we built header field table yet */ @@ -525,7 +515,7 @@ usr_delivery (int fd, char *delivery, int su) } if (vecp > 5) { - if (!mh_strcasecmp (vec[5], "select")) { + if (!strcasecmp (vec[5], "select")) { if (logged_in () != -1) continue; if (vecp > 7 && timely (vec[6], vec[7]) == -1) @@ -544,7 +534,7 @@ usr_delivery (int fd, char *delivery, int su) * "default" matches only if the message hasn't * been delivered yet. */ - if (!mh_strcasecmp (field, "default")) { + if (!strcasecmp (field, "default")) { if (won) continue; break; @@ -574,7 +564,7 @@ usr_delivery (int fd, char *delivery, int su) switch (*action) { case 'q': /* deliver to quoted pipe */ - if (mh_strcasecmp (action, "qpipe")) + if (strcasecmp (action, "qpipe")) continue; /* else fall */ case '^': expand (tmpbuf, string, fd); @@ -585,7 +575,7 @@ usr_delivery (int fd, char *delivery, int su) case 'p': /* deliver to pipe */ - if (mh_strcasecmp (action, "pipe")) + if (strcasecmp (action, "pipe")) continue; /* else fall */ case '|': vec[2] = "sh"; @@ -598,12 +588,12 @@ usr_delivery (int fd, char *delivery, int su) case 'f': /* mbox format */ - if (!mh_strcasecmp (action, "file")) { + if (!strcasecmp (action, "file")) { status = usr_file (fd, string, MBOX_FORMAT); break; } /* deliver to nmh folder */ - else if (mh_strcasecmp (action, "folder")) + else if (strcasecmp (action, "folder")) continue; /* else fall */ case '+': status = usr_folder (fd, string); @@ -611,12 +601,12 @@ usr_delivery (int fd, char *delivery, int su) case 'm': /* mmdf format */ - if (!mh_strcasecmp (action, "mmdf")) { + if (!strcasecmp (action, "mmdf")) { status = usr_file (fd, string, MMDF_FORMAT); break; } /* mbox format */ - else if (mh_strcasecmp (action, "mbox")) + else if (strcasecmp (action, "mbox")) continue; /* else fall */ case '>': @@ -626,7 +616,7 @@ usr_delivery (int fd, char *delivery, int su) case 'd': /* ignore message */ - if (mh_strcasecmp (action, "destroy")) + if (strcasecmp (action, "destroy")) continue; status = 0; break; @@ -654,7 +644,7 @@ static int split (char *cp, char **vec) { int i; - unsigned char *s; + char *s; s = cp; @@ -663,7 +653,7 @@ split (char *cp, char **vec) vec[i] = NULL; /* zap any whitespace and comma's */ - while (isspace (*s) || *s == ',') + while (isspace ((unsigned char) *s) || *s == ',') *s++ = 0; /* end of buffer, time to leave */ @@ -693,7 +683,7 @@ split (char *cp, char **vec) vec[i++] = s++; /* move forward to next field delimiter */ - while (*s && !isspace (*s) && *s != ',') + while (*s && !isspace ((unsigned char) *s) && *s != ',') s++; } vec[i] = NULL; @@ -716,6 +706,7 @@ parse (int fd) char name[NAMESZ], field[BUFSIZ]; struct pair *p, *q; FILE *in; + m_getfld_state_t gstate = 0; if (parsed++) return 0; @@ -739,19 +730,19 @@ parse (int fd) * Scan the headers of the message and build * a lookup table. */ - for (i = 0, state = FLD;;) { + for (i = 0;;) { int fieldsz = sizeof field; - switch (state = m_getfld (state, name, field, &fieldsz, in)) { + switch (state = m_getfld (&gstate, name, field, &fieldsz, in)) { case FLD: case FLDPLUS: lp = add (field, NULL); while (state == FLDPLUS) { fieldsz = sizeof field; - state = m_getfld (state, name, field, &fieldsz, in); + state = m_getfld (&gstate, name, field, &fieldsz, in); lp = add (field, lp); } for (p = hdrs; p->p_name; p++) { - if (!mh_strcasecmp (p->p_name, name)) { + if (!strcasecmp (p->p_name, name)) { if (!(p->p_flags & P_HID)) { if ((cp = p->p_value)) { if (p->p_flags & P_ADR) { @@ -794,6 +785,7 @@ parse (int fd) } break; } + m_getfld_state_destroy (&gstate); fclose (in); if ((p = lookup (vars, "reply-to"))) { @@ -902,7 +894,7 @@ static struct pair * lookup (struct pair *pairs, char *key) { for (; pairs->p_name; pairs++) - if (!mh_strcasecmp (pairs->p_name, key)) + if (!strcasecmp (pairs->p_name, key)) return pairs; return NULL; @@ -1160,8 +1152,8 @@ static void get_sender (char *envelope, char **sender) { int i; - unsigned char *cp; - unsigned char buffer[BUFSIZ]; + char *cp; + char buffer[BUFSIZ]; if (envelope == NULL) { *sender = getcpy (""); @@ -1181,7 +1173,7 @@ get_sender (char *envelope, char **sender) *cp = 0; for (cp = buffer + strlen (buffer) - 1; cp >= buffer; cp--) - if (isspace (*cp)) + if (isspace ((unsigned char) *cp)) *cp = 0; else break; @@ -1303,7 +1295,7 @@ static char * trim (char *cp) { char buffer[BUFSIZ*4]; - unsigned char *bp, *sp; + char *bp, *sp; if (cp == NULL) return NULL; @@ -1313,12 +1305,12 @@ trim (char *cp) bp = buffer; /* skip over leading whitespace */ - while (isspace(*bp)) + while (isspace((unsigned char) *bp)) bp++; /* start at the end and zap trailing whitespace */ for (sp = bp + strlen(bp) - 1; sp >= bp; sp--) { - if (isspace(*sp)) + if (isspace((unsigned char) *sp)) *sp = 0; else break; @@ -1326,7 +1318,7 @@ trim (char *cp) /* replace remaining whitespace with spaces */ for (sp = bp; *sp; sp++) - if (isspace(*sp)) + if (isspace((unsigned char) *sp)) *sp = ' '; /* now return a copy */ @@ -1412,6 +1404,7 @@ suppress_duplicates (int fd, char *file) datum key, value; DBM *db; FILE *in; + m_getfld_state_t gstate = 0; if ((fd1 = dup (fd)) == -1) return -1; @@ -1421,17 +1414,17 @@ suppress_duplicates (int fd, char *file) } rewind (in); - for (state = FLD;;) { + for (;;) { int bufsz = sizeof buf; - state = m_getfld (state, name, buf, &bufsz, in); + state = m_getfld (&gstate, name, buf, &bufsz, in); switch (state) { case FLD: case FLDPLUS: /* Search for the message ID */ - if (mh_strcasecmp (name, "Message-ID")) { + if (strcasecmp (name, "Message-ID")) { while (state == FLDPLUS) { bufsz = sizeof buf; - state = m_getfld (state, name, buf, &bufsz, in); + state = m_getfld (&gstate, name, buf, &bufsz, in); } continue; } @@ -1439,7 +1432,7 @@ suppress_duplicates (int fd, char *file) cp = add (buf, NULL); while (state == FLDPLUS) { bufsz = sizeof buf; - state = m_getfld (state, name, buf, &bufsz, in); + state = m_getfld (&gstate, name, buf, &bufsz, in); cp = add (buf, cp); } key.dptr = trimcpy (cp); @@ -1459,7 +1452,7 @@ suppress_duplicates (int fd, char *file) * This will fail if your Maildelivery file doesn't * exist. */ - if ((lockfd = lkopen(file, O_RDWR, 0)) == -1) { + if ((lockfd = lkopendata(file, O_RDWR, 0)) == -1) { advise (file, "unable to perform file locking on"); free (cp); fclose (in); @@ -1480,7 +1473,7 @@ suppress_duplicates (int fd, char *file) } dbm_close (db); - lkclose(lockfd, file); + lkclosedata(lockfd, file); free (cp); fclose (in); return result; @@ -1498,6 +1491,7 @@ suppress_duplicates (int fd, char *file) break; } + m_getfld_state_destroy (&gstate); fclose (in); return 0;