summaryrefslogtreecommitdiff
path: root/comsat
diff options
context:
space:
mode:
authorAlain Magloire <alainm@gnu.org>2001-11-13 14:08:35 +0000
committerAlain Magloire <alainm@gnu.org>2001-11-13 14:08:35 +0000
commit8ccd48fd24ee193c02dd13d65f4bd4981293ddb1 (patch)
tree990bf4e714b8840c9bc85b983f530222fd8fdb64 /comsat
parent9bcb4c72fbd5d9da96da87feaf705d4ed6f8f33f (diff)
downloadmailutils-8ccd48fd24ee193c02dd13d65f4bd4981293ddb1.tar.gz
mailutils-8ccd48fd24ee193c02dd13d65f4bd4981293ddb1.tar.bz2
Try to use const whenever appropriate to make it clear
that a string should not be modified. Nuke some trailing spaces, thanks to emacs. Reduce the scope of functions with static. GNU ident style for switch() promote a empty line after the break; * comsat/action.c (expand_escape): size and lncount could have been use uninitialized. (expand_escape): const char *cr. (expand_line): cr == "\n\r" make it const. variable i and size unneeded. variable c initialize to zero. (expand_line): obstack_1grow() pass *p instead of c. (defaul_action): const char*. (run_user_action): fprintf () missing argument. (open_rc): const char *filename. * comsat/comsat.c (username): const char *username. (mailbox_path): const prototype. (change_user): const prototype. (notify_user): const prototype. body and header unneeded variables. (find_user): const prototype. * comsat/comsat.h: Prototype updates.
Diffstat (limited to 'comsat')
-rw-r--r--comsat/action.c73
-rw-r--r--comsat/cfg.c8
-rw-r--r--comsat/comsat.c40
-rw-r--r--comsat/comsat.h6
4 files changed, 69 insertions, 58 deletions
diff --git a/comsat/action.c b/comsat/action.c
index bb5bcd34c..fa674d8cd 100644
--- a/comsat/action.c
+++ b/comsat/action.c
@@ -27,7 +27,7 @@
beep -- Produce audible signal
echo STRING -- Output STRING to the user's tty
exec PROG ARGS... -- Execute given program (absolute pathname
- required)
+ required)
Following metacharacters are accepted in strings:
@@ -38,13 +38,13 @@
number of characters and line in the expansion.
When omitted, they default to 400, 5. */
-int
+static int
act_getline (FILE *fp, char **sptr, size_t *size)
{
char buf[256];
int cont = 1;
size_t used = 0;
-
+
while (cont && fgets (buf, sizeof buf, fp))
{
int len = strlen (buf);
@@ -71,22 +71,22 @@ act_getline (FILE *fp, char **sptr, size_t *size)
}
memcpy (*sptr + used, buf, len);
used += len;
- }
+ }
if (*sptr)
(*sptr)[used] = 0;
-
+
return used;
}
/* Convert second character of a backslash sequence to its ASCII
value: */
-int
+static int
backslash(int c)
{
static char transtab[] = "a\ab\bf\fn\nr\rt\t";
char *p;
-
+
for (p = transtab; *p; p += 2)
{
if (*p == c)
@@ -95,8 +95,8 @@ backslash(int c)
return c;
}
-int
-expand_escape (char **pp, message_t msg, char *cr, struct obstack *stk)
+static int
+expand_escape (char **pp, message_t msg, const char *cr, struct obstack *stk)
{
char *p = *pp;
char *start, *sval, *namep;
@@ -105,8 +105,8 @@ expand_escape (char **pp, message_t msg, char *cr, struct obstack *stk)
body_t body;
stream_t stream;
int rc = 1;
- size_t size, lncount;
-
+ size_t size = 0, lncount = 0;
+
switch (*++p) /* skip past $ */
{
case 'u':
@@ -115,12 +115,14 @@ expand_escape (char **pp, message_t msg, char *cr, struct obstack *stk)
*pp = p;
rc = 0;
break;
+
case 'h':
len = strlen (hostname);
obstack_grow (stk, hostname, len);
*pp = p;
rc = 0;
break;
+
case 'H':
/* Header field */
if (*++p != '{')
@@ -145,6 +147,7 @@ expand_escape (char **pp, message_t msg, char *cr, struct obstack *stk)
*pp = p;
rc = 0;
break;
+
case 'B':
/* Message body */
if (*++p == '(')
@@ -164,7 +167,7 @@ expand_escape (char **pp, message_t msg, char *cr, struct obstack *stk)
{
size_t nread;
char *buf = malloc (size+1);
-
+
if (!buf)
break;
if (stream_read (stream, buf, size, 0, &nread) == 0)
@@ -193,14 +196,13 @@ expand_escape (char **pp, message_t msg, char *cr, struct obstack *stk)
return rc;
}
-char *
-expand_line (char *str, char *cr, message_t msg)
+static char *
+expand_line (const char *str, const char *cr, message_t msg)
{
- char *p;
- int i, c, len;
- size_t size;
+ const char *p;
+ int c = 0, len;
struct obstack stk;
-
+
if (!*str)
return NULL;
obstack_init (&stk);
@@ -212,25 +214,30 @@ expand_line (char *str, char *cr, message_t msg)
len = strlen (cr);
obstack_grow (&stk, cr, len);
break;
+
case '\\':
p++;
switch (*p)
{
case 0:
- obstack_1grow (&stk, c);
+ obstack_1grow (&stk, *p);
break;
+
case 'n':
len = strlen (cr);
obstack_grow (&stk, cr, len);
break;
+
default:
c = backslash (*p);
obstack_1grow (&stk, c);
}
break;
+
case '$':
if (expand_escape (&p, msg, cr, &stk) == 0)
break;
+
/*FALLTHRU*/
default:
obstack_1grow (&stk, *p);
@@ -239,10 +246,10 @@ expand_line (char *str, char *cr, message_t msg)
obstack_1grow (&stk, 0);
str = strdup (obstack_finish (&stk));
obstack_free (&stk, NULL);
- return str;
+ return (char *)str;
}
-char *default_action =
+const char *default_action =
"Mail to \a$u@$h\a\n"
"---\n"
"From: $H{from}\n"
@@ -253,18 +260,18 @@ char *default_action =
/* Take care to clear eighth bit, so we won't upset some stupid terminals */
#define LB(c) ((c)&0x7f)
-
-void
+
+static void
action_beep (FILE *tty)
{
fprintf (tty, "\a\a");
}
-void
+static void
action_echo (FILE *tty, char *str)
{
char *p;
-
+
if (!str)
return;
for (p = str; *p; p++)
@@ -272,7 +279,7 @@ action_echo (FILE *tty, char *str)
fprintf (tty, "%s", str);
}
-void
+static void
action_exec (FILE *tty, int line, int argc, char **argv)
{
pid_t pid;
@@ -319,8 +326,8 @@ action_exec (FILE *tty, int line, int argc, char **argv)
}
}
-FILE *
-open_rc (char *filename, FILE *tty)
+static FILE *
+open_rc (const char *filename, FILE *tty)
{
struct stat stb;
struct passwd *pw = getpwnam (username);
@@ -348,7 +355,7 @@ open_rc (char *filename, FILE *tty)
}
void
-run_user_action (FILE *tty, char *cr, message_t msg)
+run_user_action (FILE *tty, const char *cr, message_t msg)
{
FILE *fp;
int nact = 0;
@@ -359,7 +366,7 @@ run_user_action (FILE *tty, char *cr, message_t msg)
if (fp)
{
int line = 0;
-
+
while (act_getline (fp, &stmt, &size))
{
char *str;
@@ -396,7 +403,7 @@ run_user_action (FILE *tty, char *cr, message_t msg)
}
else
{
- fprintf (tty, ".biffrc:%d: unknown keyword\r\n");
+ fprintf (tty, ".biffrc:%d: unknown keyword\r\n", line);
syslog (LOG_ERR, "%s:.biffrc:%d: unknown keyword %s",
username, line, argv[0]);
break;
@@ -404,12 +411,10 @@ run_user_action (FILE *tty, char *cr, message_t msg)
}
fclose (fp);
}
-
+
if (nact == 0)
{
char *str = expand_line (default_action, cr, msg);
action_echo (tty, str);
}
}
-
-
diff --git a/comsat/cfg.c b/comsat/cfg.c
index a1fcdeeaa..a05535877 100644
--- a/comsat/cfg.c
+++ b/comsat/cfg.c
@@ -124,7 +124,7 @@ netdef_parse (char *str)
}
void
-read_config (char *config_file)
+read_config (const char *config_file)
{
FILE *fp;
int line;
@@ -217,9 +217,9 @@ read_config (char *config_file)
tail->next = cur;
tail = cur;
}
-
+
argcv_free (argc, argv);
-
+
acl = malloc (sizeof *acl);
if (!acl)
{
@@ -268,7 +268,7 @@ acl_free (acl_t *acl)
}
/*NOTE: currently unused. */
-void
+static void
discard_acl (acl_t *mark)
{
if (mark)
diff --git a/comsat/comsat.c b/comsat/comsat.c
index 1a57e27bc..8566ecd5d 100644
--- a/comsat/comsat.c
+++ b/comsat/comsat.c
@@ -76,17 +76,17 @@ int port = 512; /* Default biff port */
int timeout = 0;
int maxlines = 5;
char hostname[MAXHOSTNAMELEN];
-char *username;
+const char *username;
static void comsat_init (void);
static void comsat_daemon_init (void);
-static void comsat_daemon (int port);
+static void comsat_daemon (int _port);
static int comsat_main (int fd);
-static void notify_user (char *user, char *device, char *path, off_t offset);
-static int find_user (char *name, char *tty);
+static void notify_user (const char *user, const char *device, const char *path, off_t offset);
+static int find_user (const char *name, char *tty);
static void help (void);
-char *mailbox_path (const char *user);
-void change_user (char *user);
+static char *mailbox_path (const char *user);
+static void change_user (const char *user);
static int xargc;
static char **xargv;
@@ -105,25 +105,32 @@ main(int argc, char **argv)
case 'c':
config_file = optarg;
break;
+
case 'd':
mode = MODE_DAEMON;
break;
+
case 'h':
help ();
/*NOTREACHED*/
+
case 'i':
mode = MODE_INETD;
break;
+
case 'p':
port = strtoul (optarg, NULL, 10);
break;
+
case 't':
timeout = strtoul (optarg, NULL, 10);
break;
+
case 'v':
printf (IMPL " ("PACKAGE " " VERSION ")\n");
exit (EXIT_SUCCESS);
break;
+
default:
exit (EXIT_FAILURE);
}
@@ -162,7 +169,7 @@ main(int argc, char **argv)
return c != 0;
}
-RETSIGTYPE
+static RETSIGTYPE
sig_hup (int sig)
{
syslog (LOG_NOTICE, "restarting");
@@ -386,7 +393,7 @@ comsat_main (int fd)
exit (0);
}
-char *
+static const char *
get_newline_str (FILE *fp)
{
#if defined(OPOST) && defined(ONLCR)
@@ -404,15 +411,14 @@ get_newline_str (FILE *fp)
/* NOTE: Do not bother to free allocated memory, as the program exits
immediately after executing this */
-void
-notify_user (char *user, char *device, char *path, off_t offset)
+static void
+notify_user (const char *user, const char *device, const char *path, off_t offset)
{
FILE *fp;
- char *cr, *p, *blurb;
+ const char *cr;
+ char *blurb;
mailbox_t mbox = NULL, tmp = NULL;
message_t msg;
- body_t body = NULL;
- header_t header = NULL;
stream_t stream = NULL;
int status;
size_t size, count, n;
@@ -491,8 +497,8 @@ notify_user (char *user, char *device, char *path, off_t offset)
}
/* Search utmp for the local user */
-int
-find_user (char *name, char *tty)
+static int
+find_user (const char *name, char *tty)
{
UTMP *uptr;
int status;
@@ -520,7 +526,7 @@ find_user (char *name, char *tty)
ftty[sizeof (ftty) - 1] = 0;
mu_normalize_path (ftty, "/");
- if (strncmp (ftty, PATH_TTY_PFX, strlen(PATH_TTY_PFX)))
+ if (strncmp (ftty, PATH_TTY_PFX, strlen (PATH_TTY_PFX)))
{
/* An attempt to break security... */
syslog (LOG_ALERT, "bad line name in utmp record: %s", ftty);
@@ -557,7 +563,7 @@ find_user (char *name, char *tty)
}
void
-change_user (char *user)
+change_user (const char *user)
{
struct passwd *pw;
diff --git a/comsat/comsat.h b/comsat/comsat.h
index e74981bf1..1c1f8a3b7 100644
--- a/comsat/comsat.h
+++ b/comsat/comsat.h
@@ -59,9 +59,9 @@ extern time_t request_control_interval;
extern time_t overflow_control_interval;
extern time_t overflow_delay_time;
extern int maxlines;
-extern char *username;
+extern const char *username;
extern char hostname[];
-extern void read_config (char *config_file);
+extern void read_config (const char *config_file);
int acl_match (struct sockaddr_in *sa_in);
-void run_user_action (FILE *tty, char *cr, message_t msg);
+void run_user_action (FILE *tty, const char *cr, message_t msg);

Return to:

Send suggestions and report system problems to the System administrator.