]> diplodocus.org Git - nmh/blobdiff - uip/sendsbr.c
Add more NORETURN and CHECK_PRINTF function attributes.
[nmh] / uip / sendsbr.c
index 191f5628ecdcdeab5b74b65ef959ecf1d46afcf2..4106010078cca75bf449494ddeeb84d112b3c0df 100644 (file)
@@ -1,6 +1,4 @@
-
-/*
- * sendsbr.c -- routines to help WhatNow/Send along
+/* sendsbr.c -- routines to help WhatNow/Send along
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
 
 #ifdef OAUTH_SUPPORT
 #include <h/oauth.h>
+#endif
+#include "../sbr/m_maildir.h"
+#include "../sbr/m_mktemp.h"
+#include "../sbr/message_id.h"
 
+#ifdef OAUTH_SUPPORT
 static int setup_oauth_params(char *[], int *, const char *, const char **);
 #endif /* OAUTH_SUPPORT */
 
@@ -132,7 +135,7 @@ sendsbr (char **vec, int vecp, char *program, char *draft, struct stat *st,
 #ifdef OAUTH_SUPPORT
                const char *errmsg;
                if (setup_oauth_params(vec, nvecsp, auth_svc, &errmsg) != OK) {
-                       adios(NULL, errmsg);
+                        adios(NULL, "%s", errmsg);
                }
 #else
                 adios(NULL, "send built without OAUTH_SUPPORT, "
@@ -191,11 +194,11 @@ splitmsg (char **vec, int vecp, char *program, char *drft,
     int        compnum, nparts, partno, state, status;
     long pos, start;
     time_t clock;
-    char *cp, *dp, buffer[BUFSIZ], msgid[BUFSIZ];
+    char *cp, *dp, buffer[NMH_BUFSIZ], msgid[BUFSIZ];
     char subject[BUFSIZ];
     char name[NAMESZ], partnum[BUFSIZ];
     FILE *in;
-    m_getfld_state_t gstate = 0;
+    m_getfld_state_t gstate;
 
     if ((in = fopen (drft, "r")) == NULL)
        adios (drft, "unable to open for reading");
@@ -207,10 +210,11 @@ splitmsg (char **vec, int vecp, char *program, char *drft,
      * Scan through the message and examine the various header fields,
      * as well as locate the beginning of the message body.
      */
-    m_getfld_track_filepos (&gstate, in);
+    gstate = m_getfld_state_init(in);
+    m_getfld_track_filepos2(&gstate);
     for (compnum = 1;;) {
        int bufsz = sizeof buffer;
-       switch (state = m_getfld (&gstate, name, buffer, &bufsz, in)) {
+       switch (state = m_getfld2(&gstate, name, buffer, &bufsz)) {
            case FLD:
            case FLDPLUS:
                compnum++;
@@ -221,7 +225,7 @@ splitmsg (char **vec, int vecp, char *program, char *drft,
                if (!strcasecmp (name, "Message-ID")) {
                    while (state == FLDPLUS) {
                        bufsz = sizeof buffer;
-                       state = m_getfld (&gstate, name, buffer, &bufsz, in);
+                       state = m_getfld2(&gstate, name, buffer, &bufsz);
                    }
                } else if (uprf (name, XXX_FIELD_PRF)
                        || !strcasecmp (name, VRSN_FIELD)
@@ -247,7 +251,7 @@ splitmsg (char **vec, int vecp, char *program, char *drft,
                    dp = add (concat (name, ":", buffer, NULL), dp);
                    while (state == FLDPLUS) {
                        bufsz = sizeof buffer;
-                       state = m_getfld (&gstate, name, buffer, &bufsz, in);
+                       state = m_getfld2(&gstate, name, buffer, &bufsz);
                        dp = add (buffer, dp);
                    }
                } else {
@@ -258,7 +262,7 @@ splitmsg (char **vec, int vecp, char *program, char *drft,
                    cp = add (concat (name, ":", buffer, NULL), cp);
                    while (state == FLDPLUS) {
                        bufsz = sizeof buffer;
-                       state = m_getfld (&gstate, name, buffer, &bufsz, in);
+                       state = m_getfld2(&gstate, name, buffer, &bufsz);
                        cp = add (buffer, cp);
                    }
                }
@@ -454,7 +458,7 @@ sendaux (char **vec, int vecp, char *program, char *drft, struct stat *st)
        /*
         * child process -- send it
         *
-        * If fd is ok, then we are pushing and fd points to temp
+        * If fd is OK, then we are pushing and fd points to temp
         * file, so capture anything on stdout and stderr there.
         */
        if (fd != NOTOK) {
@@ -534,7 +538,7 @@ alert (char *file, int out)
                if ((in = open (file, O_RDONLY)) == NOTOK) {
                    admonish (file, "unable to re-open");
                } else {
-                   lseek (out, (off_t) 0, SEEK_END);
+                   lseek(out, 0, SEEK_END);
                    strncpy (buf, "\nMessage not delivered to anyone.\n", sizeof(buf));
                    if (write (out, buf, strlen (buf)) < 0) {
                        advise (file, "write");
@@ -553,7 +557,7 @@ alert (char *file, int out)
                        admonish (buf, "unable to rename %s to", file);
                }
            }
-           lseek (out, (off_t) 0, SEEK_SET);
+           lseek(out, 0, SEEK_SET);
            dup2 (out, fileno (stdin));
            close (out);
            /* create subject for error notification */
@@ -588,9 +592,8 @@ tmp_fd (void)
 
     if (debugsw)
        inform("temporary file %s selected", tfile);
-    else
-       if (m_unlink (tfile) == NOTOK)
-           advise (tfile, "unable to remove");
+    else if (m_unlink (tfile) == NOTOK)
+        advise (tfile, "unable to remove");
 
     return fd;
 }
@@ -711,7 +714,7 @@ annoaux (int fd)
        goto oops;
     }
 
-    lseek (fd, (off_t) 0, SEEK_SET);
+    lseek(fd, 0, SEEK_SET);
     if ((fp = fdopen (fd, "r")) == NULL) {
        if (debugsw)
            inform("unable to fdopen annotation list, continuing...");
@@ -748,7 +751,7 @@ handle_sendfrom(char **vec, int *vecp, char *draft, const char *auth_svc) {
 
     /* Extract address and host from From: header line in draft. */
     if (get_from_header_info(draft, &addr, &host, &message) != OK) {
-        adios(draft, message);
+        adios(draft, "%s", message);
     }
 
     /* Merge in any address or host specific switches to post(1) from profile. */
@@ -765,7 +768,7 @@ handle_sendfrom(char **vec, int *vecp, char *draft, const char *auth_svc) {
             if (strcmp(*vp, "xoauth2") == 0) {
 #ifdef OAUTH_SUPPORT
                 if (setup_oauth_params(vec, vecp, auth_svc, &message) != OK) {
-                    adios(NULL, message);
+                    adios(NULL, "%s", message);
                 }
                 break;
 #else
@@ -884,8 +887,7 @@ get_from_header_info(const char *filename, const char **addr, const char **host,
 
         /* Use the hostformat that corresponds to the successful addrformat. */
         if ((*host = get_message_header_info(in, hostformat)) == NULL) {
-            fclose(in);
-            *message = "unable to find sender host in";
+            *message = "unable to find sender host";
             fclose(in);
             return NOTOK;
         }
@@ -910,7 +912,7 @@ get_message_header_info(FILE *in, char *format) {
     struct format *fmt;
     struct stat st;
     int parsing_header;
-    m_getfld_state_t gstate = 0;
+    m_getfld_state_t gstate;
     charstring_t buffer = charstring_create(0);
     char *retval;
 
@@ -926,10 +928,11 @@ get_message_header_info(FILE *in, char *format) {
      */
     rewind (in);
     parsing_header = 1;
+    gstate = m_getfld_state_init(in);
     do {
         char name[NAMESZ], rbuf[NMH_BUFSIZ];
         int bufsz = sizeof rbuf;
-        int state = m_getfld(&gstate, name, rbuf, &bufsz, in);
+        int state = m_getfld2(&gstate, name, rbuf, &bufsz);
 
         switch (state) {
         case FLD:
@@ -939,14 +942,14 @@ get_message_header_info(FILE *in, char *format) {
             if (bucket != -1) {
                 while (state == FLDPLUS) {
                     bufsz = sizeof rbuf;
-                    state = m_getfld(&gstate, name, rbuf, &bufsz, in);
+                    state = m_getfld2(&gstate, name, rbuf, &bufsz);
                     fmt_appendcomp(bucket, name, rbuf);
                 }
             }
 
             while (state == FLDPLUS) {
                 bufsz = sizeof rbuf;
-                state = m_getfld(&gstate, name, rbuf, &bufsz, in);
+                state = m_getfld2(&gstate, name, rbuf, &bufsz);
             }
             break;
         }
@@ -1011,7 +1014,7 @@ merge_profile_entry(const char *addr, const char *host, char *vec[], int *vecp)
 }
 
 
-static void
+static void NORETURN
 armed_done (int status)
 {
     longjmp (env, status ? status : NOTOK);