cconf.c: use sha1_io.h
This commit is contained in:
parent
0b2b159b2d
commit
c1198121bb
2 changed files with 7 additions and 18 deletions
7
Makefile
7
Makefile
|
|
@ -11,9 +11,10 @@ install : $(PROGRAMS)
|
||||||
cp $^ $(HOME)/bin/
|
cp $^ $(HOME)/bin/
|
||||||
|
|
||||||
dlight : dlight.o buffer.o env.o http.o rss.o lockfile.o filter.o cconf.o \
|
dlight : dlight.o buffer.o env.o http.o rss.o lockfile.o filter.o cconf.o \
|
||||||
proc-cache.o dlhist.o error.o
|
sha1_io.o proc-cache.o dlhist.o error.o
|
||||||
dlight-compile : compile.o buffer.o env.o lockfile.o filter.o cconf.o error.o
|
dlight-compile : compile.o buffer.o env.o lockfile.o filter.o cconf.o \
|
||||||
dlight-read-config : read-config.o buffer.o env.o cconf.o error.o
|
sha1_io.o error.o
|
||||||
|
dlight-read-config : read-config.o buffer.o env.o cconf.o sha1_io.o error.o
|
||||||
dlight-filter-check: filter-check.o filter.o error.o
|
dlight-filter-check: filter-check.o filter.o error.o
|
||||||
|
|
||||||
dlight-% : %.o
|
dlight-% : %.o
|
||||||
|
|
|
||||||
18
cconf.c
18
cconf.c
|
|
@ -25,25 +25,13 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <openssl/sha.h>
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include "sha1_io.h"
|
||||||
#include "cconf.h"
|
#include "cconf.h"
|
||||||
|
|
||||||
/* we count NULL as part of the string ondisk */
|
/* we count NULL as part of the string ondisk */
|
||||||
#define strsize(str) (strlen(str) + 1)
|
#define strsize(str) (strlen(str) + 1)
|
||||||
|
|
||||||
static int sha1_write(SHA_CTX *ctx, int fd, void *buf, size_t size) {
|
|
||||||
|
|
||||||
SHA1_Update(ctx, buf, size);
|
|
||||||
return write(fd, buf, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void write_int(SHA_CTX *ctx, int fd, int val) {
|
|
||||||
|
|
||||||
val = htonl(val);
|
|
||||||
sha1_write(ctx, fd, &val, sizeof val);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void* read_entry_nr(void *buf, unsigned int *out) {
|
static void* read_entry_nr(void *buf, unsigned int *out) {
|
||||||
|
|
||||||
memcpy(out, buf, sizeof(*out));
|
memcpy(out, buf, sizeof(*out));
|
||||||
|
|
@ -217,7 +205,7 @@ int cconf_write(int fd, struct cconf *c) {
|
||||||
lseek(fd, sizeof(hdr), SEEK_SET);
|
lseek(fd, sizeof(hdr), SEEK_SET);
|
||||||
|
|
||||||
/* put number of targets */
|
/* put number of targets */
|
||||||
write_int(&ctx, fd, c->nr);
|
sha1_write_int(&ctx, fd, c->nr);
|
||||||
|
|
||||||
for(i = 0; i < c->nr; i++) {
|
for(i = 0; i < c->nr; i++) {
|
||||||
int j;
|
int j;
|
||||||
|
|
@ -229,7 +217,7 @@ int cconf_write(int fd, struct cconf *c) {
|
||||||
sha1_write(&ctx, fd, target->src, strsize(target->src));
|
sha1_write(&ctx, fd, target->src, strsize(target->src));
|
||||||
|
|
||||||
/* write number of filters */
|
/* write number of filters */
|
||||||
write_int(&ctx, fd, target->nr);
|
sha1_write_int(&ctx, fd, target->nr);
|
||||||
|
|
||||||
for(j=0; j < target->nr; j++) {
|
for(j=0; j < target->nr; j++) {
|
||||||
struct filter *f = &target->filter[j];
|
struct filter *f = &target->filter[j];
|
||||||
|
|
|
||||||
Reference in a new issue