summaryrefslogtreecommitdiffstats
path: root/daemon/innbbsd/dbztool.c
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-03-20 19:33:49 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-03-20 19:33:49 +0800
commit6c7b18b32d87c2a835f7e5c48faac4a8ad44668b (patch)
treee88e1b2b1007f4ddcd348a4a1bf1d13c515c4564 /daemon/innbbsd/dbztool.c
parentf59699c22c130373cda3cc4cb6fab5bae510bd5a (diff)
downloadpttbbs-piaip.newlayout.tar
pttbbs-piaip.newlayout.tar.gz
pttbbs-piaip.newlayout.tar.bz2
pttbbs-piaip.newlayout.tar.lz
pttbbs-piaip.newlayout.tar.xz
pttbbs-piaip.newlayout.tar.zst
pttbbs-piaip.newlayout.zip
- (internal/exp) first draft of new layoutpiaip.newlayout
git-svn-id: http://opensvn.csie.org/pttbbs/branches/piaip.newlayout@4013 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'daemon/innbbsd/dbztool.c')
-rw-r--r--daemon/innbbsd/dbztool.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/daemon/innbbsd/dbztool.c b/daemon/innbbsd/dbztool.c
new file mode 100644
index 00000000..c2d77476
--- /dev/null
+++ b/daemon/innbbsd/dbztool.c
@@ -0,0 +1,97 @@
+#include <string.h>
+#include <unistd.h>
+#include <sys/file.h>
+#include "his.h"
+#include "externs.h"
+#include <time.h>
+
+#define DEBUG 1
+#undef DEBUG
+
+static datum content, inputkey;
+static char dboutput[1025];
+static char dbinput[1025];
+
+#if 0
+enum {
+ SUBJECT, FROM, NAME
+};
+#endif
+
+char *
+DBfetch(key)
+ char *key;
+{
+ char *ptr;
+ if (key == NULL)
+ return NULL;
+ sprintf(dbinput, "%.510s", key);
+ inputkey.dptr = dbinput;
+ inputkey.dsize = strlen(dbinput);
+ content.dptr = dboutput;
+ ptr = (char *)HISfilesfor(&inputkey, &content);
+ if (ptr == NULL) {
+ return NULL;
+ }
+ return ptr;
+}
+
+int
+DBstore(key, paths)
+ char *key;
+ char *paths;
+{
+ time_t now;
+ time(&now);
+ if (key == NULL)
+ return -1;
+ sprintf(dbinput, "%.510s", key);
+ inputkey.dptr = dbinput;
+ inputkey.dsize = strlen(dbinput);
+ if (HISwrite(&inputkey, now, paths) == FALSE) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+int
+storeDB(mid, paths)
+ char *mid;
+ char *paths;
+{
+ char *ptr;
+ ptr = DBfetch(mid);
+ if (ptr != NULL) {
+ return 0;
+ } else {
+ return DBstore(mid, paths);
+ }
+}
+
+int
+my_mkdir(idir, mode)
+ char *idir;
+ int mode;
+{
+ char buffer[LEN];
+ char *ptr, *dir = buffer;
+ struct stat st;
+ strncpy(dir, idir, LEN - 1);
+ for (; dir != NULL && *dir;) {
+ ptr = (char *)strchr(dir, '/');
+ if (ptr != NULL) {
+ *ptr = '\0';
+ }
+ if (stat(dir, &st) != 0) {
+ if (mkdir(dir, mode) != 0)
+ return -1;
+ }
+ chdir(dir);
+ if (ptr != NULL)
+ dir = ptr + 1;
+ else
+ dir = ptr;
+ }
+ return 0;
+}