X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=daemon%2Fconf.c;h=07e408ea4189f836c1ced1b51ff94fd2862110b6;hb=302a260054ea38d3cb97be6d1a3010082c09265d;hp=ea3229e43056384dc2ce26e5e2d636615f1ef63d;hpb=d3372da97568d5e1f35fa19787c8ec8af93a0435;p=doldaconnect.git diff --git a/daemon/conf.c b/daemon/conf.c index ea3229e..07e408e 100644 --- a/daemon/conf.c +++ b/daemon/conf.c @@ -1,6 +1,6 @@ /* * Dolda Connect - Modular multiuser Direct Connect-style client - * Copyright (C) 2004 Fredrik Tolf (fredrik@dolda2000.com) + * Copyright (C) 2004 Fredrik Tolf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,10 +16,11 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#include #include #include #include -#include #include #include #include @@ -28,6 +29,7 @@ #include #include #include +#include #ifdef HAVE_CONFIG_H #include @@ -271,36 +273,6 @@ int runconfcmd(int argc, wchar_t **argv) return(ret); } -char *findconfigfile(void) -{ - static char pathbuf[128]; - char *p, *p2; - - if(getenv("HOME") != NULL) - { - snprintf(pathbuf, sizeof(pathbuf), "%s/.doldacond", getenv("HOME")); - if(!access(pathbuf, R_OK)) - return(pathbuf); - } - p = CONFIG_PATH; - do - { - p2 = strchr(p, ':'); - if(p2 != NULL) - { - memcpy(pathbuf, p, p2 - p); - pathbuf[p2 - p] = 0; - if(!access(pathbuf, R_OK)) - return(pathbuf); - } else { - if(!access(p, R_OK)) - return(p); - } - p = p2 + 1; - } while(p2 != NULL); - return(NULL); -} - void readconfig(FILE *stream) { int state; @@ -390,3 +362,48 @@ void readconfig(FILE *stream) if(state != 0) flog(LOG_WARNING, "unexpected end of file"); } + +/* {store,fetch}var re-opens the database every time, just in case two + * doldacond processes would be running simultaneously. */ +void storevar(char *key, void *val, size_t len) +{ + char *dbname; + GDBM_FILE db; + datum k, v; + + dbname = findfile("dc-vardb", NULL, 1); + if((db = gdbm_open(dbname, 0, GDBM_WRCREAT, 0666, NULL)) == NULL) + { + flog(LOG_CRIT, "could not open var database for writing, cannot continue: %s", gdbm_strerror(gdbm_errno)); + abort(); + } + free(dbname); + k.dptr = key; + k.dsize = strlen(key); + v.dptr = val; + v.dsize = len; + gdbm_store(db, k, v, GDBM_REPLACE); + gdbm_close(db); +} + +void *fetchvar(char *key, size_t *lenb) +{ + char *dbname; + GDBM_FILE db; + datum k, v; + + if((dbname = findfile("dc-vardb", NULL, 0)) == NULL) + return(NULL); + if((db = gdbm_open(dbname, 0, GDBM_READER, 0666, NULL)) == NULL) + return(NULL); + free(dbname); + k.dptr = key; + k.dsize = strlen(key); + v = gdbm_fetch(db, k); + gdbm_close(db); + if(v.dptr == NULL) + return(NULL); + if(lenb != NULL) + *lenb = v.dsize; + return(v.dptr); +}