From: Jonathan McDowell Date: Sat, 16 Oct 2004 20:11:22 +0000 (+0000) Subject: Move mailsync functionality to the database backends. X-Git-Url: https://git.sommitrealweird.co.uk/onak.git/commitdiff_plain/fd58db2034c6781399583384055ce69fc300b26b Move mailsync functionality to the database backends. Move the sending of key sync mails to the DB backend. --- diff --git a/Makefile.in b/Makefile.in index cab1f82..d9459c8 100644 --- a/Makefile.in +++ b/Makefile.in @@ -18,7 +18,7 @@ exec_prefix ?= @exec_prefix@ PROGS = add lookup gpgwww onak splitkeys onak-mail.pl stripkey CORE_OBJS = armor.o charfuncs.o decodekey.o getcgi.o hash.o \ keyid.o keyindex.o ll.o mem.o onak-conf.o parsekey.o sha1.o md5.o \ - log.o photoid.o wordlist.o cleanup.o merge.o + log.o photoid.o wordlist.o cleanup.o merge.o sendsync.o SRCS = armor.c parsekey.c merge.c keyid.c md5.c sha1.c main.c getcgi.c mem.c \ keyindex.c stats.c lookup.c add.c keydb_$(DBTYPE).c ll.c hash.c \ gpgwww.c onak-conf.c charfuncs.c sendsync.c log.c photoid.c \ @@ -32,7 +32,7 @@ else KEYDB_OBJ = keydb_$(DBTYPE).o endif -OBJS = stats.o sendsync.o cleankey.o $(CORE_OBJS) $(KEYDB_OBJ) +OBJS = stats.o cleankey.o $(CORE_OBJS) $(KEYDB_OBJ) all: .depend $(PROGS) testparse maxpath sixdegrees splitkeys onak.conf @@ -62,8 +62,8 @@ lookup: lookup.o cleankey.o $(CORE_OBJS) $(KEYDB_OBJ) $(CC) $(LDFLAGS) -o lookup lookup.o cleankey.o $(CORE_OBJS) \ $(KEYDB_OBJ) $(LIBS) -add: add.o cleankey.o sendsync.o $(CORE_OBJS) $(KEYDB_OBJ) - $(CC) $(LDFLAGS) -o add add.o cleankey.o sendsync.o \ +add: add.o cleankey.o $(CORE_OBJS) $(KEYDB_OBJ) + $(CC) $(LDFLAGS) -o add add.o cleankey.o \ $(CORE_OBJS) $(KEYDB_OBJ) $(LIBS) onak: onak.o cleankey.o $(CORE_OBJS) $(KEYDB_OBJ) diff --git a/add.c b/add.c index 189444e..46f5ecf 100644 --- a/add.c +++ b/add.c @@ -78,14 +78,15 @@ int main(int argc, char *argv[]) logthing(LOGTHING_INFO, "%d keys cleaned.", count); - count = update_keys(&keys); + count = update_keys(&keys, true); logthing(LOGTHING_NOTICE, "Got %d new keys.", count); + if (keys != NULL) { - sendkeysync(keys); free_publickey(keys); keys = NULL; } + cleanupdb(); } else { puts("No OpenPGP packets found in input."); diff --git a/keydb.c b/keydb.c index 1621782..b8bd316 100644 --- a/keydb.c +++ b/keydb.c @@ -156,6 +156,7 @@ uint64_t getfullkeyid(uint64_t keyid) /** * update_keys - Takes a list of public keys and updates them in the DB. * @keys: The keys to update in the DB. + * @sendsync: Should we send a sync mail to our peers. * * Takes a list of keys and adds them to the database, merging them with * the key in the database if it's already present there. The key list is @@ -163,7 +164,7 @@ uint64_t getfullkeyid(uint64_t keyid) * we had before to what we have now (ie the set of data that was added to * the DB). Returns the number of entirely new keys added. */ -int update_keys(struct openpgp_publickey **keys) +int update_keys(struct openpgp_publickey **keys, bool sendsync) { struct openpgp_publickey *curkey = NULL; struct openpgp_publickey *oldkey = NULL; @@ -215,6 +216,10 @@ int update_keys(struct openpgp_publickey **keys) intrans = false; } + if (sendsync && keys != NULL) { + sendkeysync(keys); + } + return newkeys; } #endif /* NEED_UPDATEKEYS */ diff --git a/keydb.h b/keydb.h index ca2a823..98cf34d 100644 --- a/keydb.h +++ b/keydb.h @@ -100,14 +100,18 @@ int fetch_key_text(const char *search, struct openpgp_publickey **publickey); /** * update_keys - Takes a list of public keys and updates them in the DB. * @keys: The keys to update in the DB. + * @sendsync: If we should send a keysync mail. * * Takes a list of keys and adds them to the database, merging them with * the key in the database if it's already present there. The key list is * update to contain the minimum set of updates required to get from what * we had before to what we have now (ie the set of data that was added to * the DB). Returns the number of entirely new keys added. + * + * If sendsync is true then we send out a keysync mail to our sync peers + * with the update. */ -int update_keys(struct openpgp_publickey **keys); +int update_keys(struct openpgp_publickey **keys, bool sendsync); /** * keyid2uid - Takes a keyid and returns the primary UID for it. diff --git a/onak.c b/onak.c index 7bd8919..e79e565 100644 --- a/onak.c +++ b/onak.c @@ -145,7 +145,7 @@ int main(int argc, char *argv[]) initdb(false); logthing(LOGTHING_NOTICE, "Got %d new keys.", - update_keys(&keys)); + update_keys(&keys, false)); if (keys != NULL && update) { flatten_publickey(keys, &packets,