summaryrefslogtreecommitdiffstats
path: root/innbbsd/dbztool.c
blob: 5318721b19b64c2dd1ff9fde1a78ca49eeabf3e1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <sys/file.h>
#include "his.h"

#define DEBUG 1
#undef DEBUG

static datum content, inputkey, inputvalue;
static char dboutput[1025];
static char dbinput[1025];
static char valueinput[100];

enum {SUBJECT, FROM, NAME};
char *DBfetch(key)
char *key;
{
   int i;
   char *tail, *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;
}

DBstore(key,paths)
char *key;
char *paths;
{
   int i;
   char *tail;
   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 *key,*ptr;
   int rel;
   ptr = DBfetch(mid); 
   if (ptr != NULL) {
     return 0;
   } else {
     return DBstore(mid , paths);
   }
}

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;
}