]>
jfr.im git - irc/quakenet/newserv.git/blob - glines/glines_store.c
4 static int glstore_savefile(const char *file
) {
16 for (gl
= glinelist
; gl
; gl
= gl
->next
) {
17 fprintf(fp
, "%s %jd,%jd,%jd,%d,%s,%s\n",
18 glinetostring(gl
), (intmax_t)gl
->expire
, (intmax_t)gl
->lastmod
, (intmax_t)gl
->lifetime
,
19 (gl
->flags
& GLINE_ACTIVE
) ? 1 : 0,
20 gl
->creator
->content
, gl
->reason
->content
);
29 static int glstore_loadfile(const char *file
) {
31 char mask
[512], creator
[512], reason
[512];
32 intmax_t expire
, lastmod
, lifetime
;
36 fp
= fopen(file
, "r");
44 if (fscanf(fp
, "%[^ ]%jd,%jd,%jd,%d,%[^,],%[^\n]\n", mask
, &expire
, &lastmod
, &lifetime
, &active
, creator
, reason
) != 7)
52 continue; /* Don't update existing glines. */
59 gl
->creator
= getsstring(creator
, 512);
61 gl
->flags
= active
? GLINE_ACTIVE
: 0;
63 gl
->reason
= getsstring(reason
, 512);
65 gl
->lastmod
= lastmod
;
66 gl
->lifetime
= lifetime
;
75 int glstore_save(void) {
76 char path
[512], srcfile
[512], dstfile
[512];
79 snprintf(path
, sizeof(path
), "%s.temp", GLSTORE_PATH_PREFIX
);
81 count
= glstore_savefile(path
);
84 Error("glines", ERR_ERROR
, "Could not save glines to %s", path
);
88 for (i
= GLSTORE_SAVE_FILES
; i
> 0; i
--) {
89 snprintf(srcfile
, sizeof(srcfile
), "%s.%d", GLSTORE_PATH_PREFIX
, i
- 1);
90 snprintf(dstfile
, sizeof(dstfile
), "%s.%d", GLSTORE_PATH_PREFIX
, i
);
91 (void) rename(srcfile
, dstfile
);
94 (void) rename(path
, srcfile
);
99 int glstore_load(void) {
101 snprintf(path
, sizeof(path
), "%s.0", GLSTORE_PATH_PREFIX
);
103 return glstore_loadfile(path
);