summaryrefslogtreecommitdiff
path: root/sqmail-4.3.07/src/control.c
diff options
context:
space:
mode:
authorJannis Hoffmann <jannis@fehcom.de>2024-07-09 11:44:11 +0200
committerJannis Hoffmann <jannis@fehcom.de>2024-07-09 11:44:11 +0200
commitf1b71c9fe7dbb4886588a036399cf5ebe16b7c47 (patch)
treee07786aa479c9fb6ee3e537078470aaab5454f80 /sqmail-4.3.07/src/control.c
parenta293489ee83c8b05d845a162dc2a4de026f3775d (diff)
removed top level directory
Diffstat (limited to 'sqmail-4.3.07/src/control.c')
-rw-r--r--sqmail-4.3.07/src/control.c122
1 files changed, 0 insertions, 122 deletions
diff --git a/sqmail-4.3.07/src/control.c b/sqmail-4.3.07/src/control.c
deleted file mode 100644
index 2558225..0000000
--- a/sqmail-4.3.07/src/control.c
+++ /dev/null
@@ -1,122 +0,0 @@
-#include <unistd.h>
-#include "open.h"
-#include "getln.h"
-#include "stralloc.h"
-#include "buffer.h"
-#include "logmsg.h"
-#include "control.h"
-#include "alloc.h"
-#include "scan.h"
-#include "error.h"
-
-static char inbuf[2048];
-static stralloc line = {0};
-static stralloc me = {0};
-static int meok = 0;
-
-/** @file control.c
-*/
-
-static void striptrailingwhitespace(stralloc *sa)
-{
- while (sa->len > 0)
- switch (sa->s[sa->len - 1]) {
- case '\n': case ' ': case '\t':
- --sa->len;
- break;
- default:
- return;
- }
-}
-
-int control_init(void)
-{
- int r;
-
- r = control_readline(&me,"control/me");
- if (r == 1) meok = 1;
- return r;
-}
-
-int control_rldef(stralloc *sa,char *fn,int flagme,char *def)
-{
- int r;
-
- r = control_readline(sa,fn);
- if (r) return r;
- if (flagme) if (meok) return stralloc_copy(sa,&me) ? 1 : -1;
- if (def) return stralloc_copys(sa,def) ? 1 : -1;
- return r;
-}
-
-int control_readline(stralloc *sa,char *fn)
-{
- buffer b;
- int fd;
- int match;
-
- fd = open_read(fn);
- if (fd == -1) { if (errno == ENOENT) return 0; return -1; }
-
- buffer_init(&b,read,fd,inbuf,sizeof(inbuf));
-
- if (getln(&b,sa,&match,'\n') == -1) { close(fd); return -1; }
-
- striptrailingwhitespace(sa);
-
- close(fd);
- return 1;
-}
-
-int control_readint(int *i,char *fn)
-{
- unsigned long u;
-
- switch (control_readline(&line,fn)) {
- case 0: return 0;
- case -1: return -1;
- }
- if (!stralloc_0(&line)) return -1;
- if (!scan_ulong(line.s,&u)) return 0;
- *i = u;
-
- return 1;
-}
-
-int control_readfile(stralloc *sa,char *fn,int flagme)
-{
- buffer b;
- int fd;
- int match;
-
- if (!stralloc_copys(sa,"")) return -1;
-
- fd = open_read(fn);
- if (fd == -1) {
- if (errno == ENOENT) {
- if (flagme && meok) {
- if (!stralloc_copy(sa,&me)) return -1;
- if (!stralloc_0(sa)) return -1;
- return 1;
- }
- return 0;
- }
- return -1;
- }
-
- buffer_init(&b,read,fd,inbuf,sizeof(inbuf));
-
- for (;;) {
- if (getln(&b,&line,&match,'\n') == -1) break;
- if (!match && !line.len) { close(fd); return 1; }
- striptrailingwhitespace(&line);
- if (!stralloc_0(&line)) break;
- if (line.s[0])
- if (line.s[0] != '#')
- if (!stralloc_cat(sa,&line)) break;
- if (!match) { close(fd); return 1; }
- }
-
- close(fd);
- return -1;
-}