summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/bbs/Makefile2
-rw-r--r--common/bbs/fhdr_stamp.c97
-rw-r--r--include/cmbbs.h7
-rw-r--r--include/cmsys.h4
-rw-r--r--include/proto.h3
-rw-r--r--include/pttstruct.h1
-rw-r--r--innbbsd/Makefile2
-rw-r--r--mbbsd/record.c24
-rw-r--r--trans/Makefile2
-rw-r--r--util/Makefile2
10 files changed, 112 insertions, 32 deletions
diff --git a/common/bbs/Makefile b/common/bbs/Makefile
index 4b992b6a..458a01e6 100644
--- a/common/bbs/Makefile
+++ b/common/bbs/Makefile
@@ -5,7 +5,7 @@ MKPIC:=no
SRCROOT:= ../..
.include "$(SRCROOT)/pttbbs.mk"
-SRCS:= log.c file.c money.c names.c path.c time.c string.c # record.c
+SRCS:= log.c file.c money.c names.c path.c time.c string.c fhdr_stamp.c
LIB:= cmbbs
install:
diff --git a/common/bbs/fhdr_stamp.c b/common/bbs/fhdr_stamp.c
new file mode 100644
index 00000000..97833316
--- /dev/null
+++ b/common/bbs/fhdr_stamp.c
@@ -0,0 +1,97 @@
+/* $Id$ */
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include "cmsys.h" // for time4_t
+#include "cmbbs.h"
+
+#if __GNUC__
+#define GCC_WEAK __attribute__ ((weak))
+#define GCC_INLINE __attribute__ ((always_inline))
+#else
+#define GCC_WEAK
+#define GCC_INLINE
+#endif
+
+static inline int fhdr_stamp(char *fpath, fileheader_t *fh, int type) GCC_INLINE;
+int stampfile(char *fpath, fileheader_t *fh) GCC_WEAK;
+int stampdir(char *fpath, fileheader_t *fh) GCC_WEAK;
+//int stamplink(char *fpath, fileheader_t * fh) GCC_WEAK;
+
+#define STAMP_FILE 0
+#define STAMP_DIR 1
+//#define STAMP_LINK 2
+
+static inline int
+fhdr_stamp(char *fpath, fileheader_t *fh, int type)
+{
+ char *ip = fpath;
+ time4_t dtime = time4(0);
+ struct tm ptime;
+ int res = 0;
+
+ if (access(fpath, X_OK | R_OK | W_OK))
+ mkdir(fpath, 0755);
+
+ while (*(++ip));
+ *ip++ = '/';
+
+ switch (type) {
+ case STAMP_FILE:
+ do {
+ sprintf(ip, "M.%d.A.%3.3X", (int)(++dtime), (unsigned int)(random() & 0xFFF));
+ } while ((res = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644)) == -1 && errno == EEXIST);
+ break;
+ case STAMP_DIR:
+ do {
+ sprintf(ip, "D%X", (int)++dtime & 07777);
+ } while ((res = mkdir(fpath, 0755)) == -1 && errno == EEXIST);
+ break;
+#if 0
+ case STAMP_LINK:
+ do {
+ sprintf(ip, "S%X", (int)++dtime);
+ } while ((res = symlink("temp", fpath)) == -1 && errno == EEXIST);
+ break;
+#endif
+ default:
+ // unknown
+ return -1;
+ break;
+ }
+
+ if (res == -1)
+ return -1;
+ close(res);
+
+ memset(fh, 0, sizeof(fileheader_t));
+ strlcpy(fh->filename, ip, sizeof(fh->filename));
+ localtime4_r(&dtime, &ptime);
+ snprintf(fh->date, sizeof(fh->date), "%2d/%02d", ptime.tm_mon + 1, ptime.tm_mday);
+
+ return 0;
+}
+
+int
+stampfile(char *fpath, fileheader_t *fh)
+{
+ return fhdr_stamp(fpath, fh, STAMP_FILE);
+}
+
+int
+stampdir(char *fpath, fileheader_t *fh)
+{
+ return fhdr_stamp(fpath, fh, STAMP_DIR);
+}
+
+#if 0
+int
+stamplink(char *fpath, fileheader_t * fh)
+{
+ return fhdr_stamp(fpath, fh, STAMP_LINK);
+}
+#endif
+
diff --git a/include/cmbbs.h b/include/cmbbs.h
index 52a5709e..149a6ae9 100644
--- a/include/cmbbs.h
+++ b/include/cmbbs.h
@@ -1,6 +1,8 @@
#ifndef _LIBBBS_H_
#define _LIBBBS_H_
+#include "pttstruct.h" /* for fileheader_t */
+
/* name.c */
extern int is_validuserid(const char *id);
@@ -32,4 +34,9 @@ extern void obfuscate_ipstr(char *s);
/* time.c */
extern const char *Now(); // m3 flavor time string
+/* fhdr_stamp.c */
+extern int stampfile(char *fpath, fileheader_t * fh);
+extern int stampdir(char *fpath, fileheader_t * fh);
+//extern int stamplink(char *fpath, fileheader_t * fh);
+
#endif
diff --git a/include/cmsys.h b/include/cmsys.h
index d1014291..572ce2a8 100644
--- a/include/cmsys.h
+++ b/include/cmsys.h
@@ -3,10 +3,8 @@
#include <stdint.h>
#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
#include <stdbool.h>
+#include <time.h>
#include "osdep.h"
#include "config.h" // XXX for TIMET64, but config.h has too much thing I don't want ...
diff --git a/include/proto.h b/include/proto.h
index bda24a0d..ff7d4bcb 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -472,9 +472,6 @@ void EnumTagFhdr(fileheader_t *fhdr, char *direct, int locus);
void UnTagger (int locus);
/* record */
int stampfile_u(char *fpath, fileheader_t *fh);
-inline int stampfile(char *fpath, fileheader_t *fh);
-void stampdir(char *fpath, fileheader_t *fh);
-void stamplink(char *fpath, fileheader_t *fh);
int delete_files(const char* dirname, int (*filecheck)(), int record);
void set_safedel_fhdr(fileheader_t *fhdr);
#ifdef SAFE_ARTICLE_DELETE
diff --git a/include/pttstruct.h b/include/pttstruct.h
index 1743f5bd..1c7df5d8 100644
--- a/include/pttstruct.h
+++ b/include/pttstruct.h
@@ -2,6 +2,7 @@
#ifndef INCLUDE_STRUCT_H
#define INCLUDE_STRUCT_H
+#include <netinet/in.h>
#include "cmsys.h" // for time4_t
#include "config.h" // various sizes in SHM
#include "statistic.h" // for MAX_STATS
diff --git a/innbbsd/Makefile b/innbbsd/Makefile
index 7d07107d..2f61729d 100644
--- a/innbbsd/Makefile
+++ b/innbbsd/Makefile
@@ -30,7 +30,7 @@ all: ${PROGS}
# bbs util
UTIL_DIR= $(SRCROOT)/util
UTIL_OBJS= \
- util_cache.o util_record.o util_passwd.o util_var.o
+ util_cache.o util_passwd.o util_var.o
.for fn in ${UTIL_OBJS}
LINK_UTIL_OBJS+= ${UTIL_DIR}/${fn}
diff --git a/mbbsd/record.c b/mbbsd/record.c
index 89304604..ec992b0b 100644
--- a/mbbsd/record.c
+++ b/mbbsd/record.c
@@ -364,7 +364,7 @@ stampfile(char *fpath, fileheader_t * fh)
return stampfile_u(fpath, fh);
}
-void
+int
stampdir(char *fpath, fileheader_t * fh)
{
register char *ip = fpath;
@@ -384,28 +384,8 @@ stampdir(char *fpath, fileheader_t * fh)
localtime4_r(&dtime, &ptime);
snprintf(fh->date, sizeof(fh->date),
"%2d/%02d", ptime.tm_mon + 1, ptime.tm_mday);
-}
-
-void
-stamplink(char *fpath, fileheader_t * fh)
-{
- register char *ip = fpath;
- time4_t dtime = COMMON_TIME;
- struct tm ptime;
-
- if (access(fpath, X_OK | R_OK | W_OK))
- mkdir(fpath, 0755);
- while (*(++ip));
- *ip++ = '/';
- do {
- sprintf(ip, "S%X", (int)++dtime);
- } while (symlink("temp", fpath) == -1);
- memset(fh, 0, sizeof(fileheader_t));
- strlcpy(fh->filename, ip, sizeof(fh->filename));
- localtime4_r(&dtime, &ptime);
- snprintf(fh->date, sizeof(fh->date),
- "%2d/%02d", ptime.tm_mon + 1, ptime.tm_mday);
+ return 0;
}
int
diff --git a/trans/Makefile b/trans/Makefile
index 1b960ec7..830c8bc2 100644
--- a/trans/Makefile
+++ b/trans/Makefile
@@ -8,7 +8,7 @@ CFLAGS+= -DPTTBBS_UTIL
BBSBASE= $(SRCROOT)/include/var.h
UTIL_OBJS= \
- util_cache.o util_record.o util_passwd.o util_var.o
+ util_cache.o util_passwd.o util_var.o
MBBSD_OBJS= \
cache record passwd var
diff --git a/util/Makefile b/util/Makefile
index 6a96d38a..3e9a45c5 100644
--- a/util/Makefile
+++ b/util/Makefile
@@ -8,7 +8,7 @@ CFLAGS+= -DPTTBBS_UTIL
BBSBASE= $(SRCROOT)/include/var.h
UTIL_OBJS= \
- util_cache.o util_record.o util_passwd.o util_var.o
+ util_cache.o util_passwd.o util_var.o
MBBSD_OBJS= \
cache record passwd var