From 5de94df423989ba2ffb6924f88fe2910379ca1c0 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 28 Apr 2005 20:39:39 +0000 Subject: cleanup --- Makefile | 2 +- connect.c | 1 + dddup.c | 4 +++- dddup.conf | 11 ++++++----- parse.c | 30 ++++++++++++++++-------------- parse.h | 2 +- request.c | 7 ++++--- request.h | 2 +- 8 files changed, 33 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index dfc0a54..3729174 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,6 @@ PROG= dddup SRCS= dddup.c parse.c ifaddr.c base64.c request.c connect.c NOMAN= -#CFLAGS+= -Wall -ggdb -pedantic +CFLAGS+= -W -Wall -pedantic # -ggdb .include diff --git a/connect.c b/connect.c index 0566742..f56a8a5 100644 --- a/connect.c +++ b/connect.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "connect.h" int diff --git a/dddup.c b/dddup.c index 612b9c7..5fb370d 100644 --- a/dddup.c +++ b/dddup.c @@ -41,6 +41,7 @@ main(int argc, char **argv) char ch; char *conffile = NULL; int reqc; + int errs; while ((ch = getopt(argc, argv, "f:dvh")) != -1) switch (ch) { @@ -63,7 +64,8 @@ main(int argc, char **argv) reqv = malloc(sizeof(struct dd_request)); if ((reqc = parse_config(conffile, reqv)) == 0) errx(1, "Nothing to do"); - do_request(reqc, reqv); + if ((errs = do_request(reqc, reqv)) != 0) + warnx("%i error(s) occurred", errs); free_config(reqc, reqv); free(reqv); exit(0); diff --git a/dddup.conf b/dddup.conf index 91b72e4..01f6dc9 100644 --- a/dddup.conf +++ b/dddup.conf @@ -1,6 +1,6 @@ # $Id$ # -# dyndns|statdns|custdns +# dynamic|static|custom # username=username (required) # password=password (required) # hostname=host1.dyndns.org (required) @@ -13,19 +13,20 @@ all:\ :dynamic:static:custom: dynamic:\ - :dyndns:\ + :dynamic:\ :interface=lo0:\ :username=test:password=test:\ - :hostname=test.dyndns.org: + :hostname=test.dyndns.org:\ + :wildcard: static:\ - :statdns:\ + :static:\ :interface=lo0:\ :username=test:password=test:\ :hostname=test-static.dyndns.org: custom:\ - :custdns:\ + :custom:\ :interface=lo0:\ :username=test:password=test:\ :hostname=test1.customtest.dyndns.org: diff --git a/parse.c b/parse.c index 8f6e687..d0ed95f 100644 --- a/parse.c +++ b/parse.c @@ -61,26 +61,28 @@ getconf(char **db_array, char *name, struct dd_request *req) if (cgetent(&buf, db_array, name) != 0) errx(1, "Can't find \"%s\" in dddup config", name); - /* get type of service -- optional */ - if (cgetcap(buf, "dyndns", ':') != NULL) { + /* get type of service -- optional + * if no one is specified dyndns.org assumes `dynamic' + */ + if (cgetcap(buf, "dynamic", ':') != NULL) { req->system = "dyndns"; f_sys = SYS_DYN; } -#define DSCERR "either \"dyndns\" or \"statdns\" or \"custdns\" " \ - "should be specifed" +#define DSCERR "either \"dynamic\" or \"static\" or \"custom\" " \ + "should be specified" - if (cgetcap(buf, "statdns", ':') != NULL) { + if (cgetcap(buf, "static", ':') != NULL) { if (req->system != NULL) errx(1, DSCERR); req->system = "statdns"; f_sys = SYS_STAT; } - if (cgetcap(buf, "custdns", ':') != NULL) { + if (cgetcap(buf, "custom", ':') != NULL) { if (req->system != NULL) errx(1, DSCERR); - req->system = "custdns"; + req->system = "custom"; f_sys = SYS_CUST; } @@ -106,7 +108,7 @@ getconf(char **db_array, char *name, struct dd_request *req) base64_encode(auth, strlen(auth), &req->auth); memset(&auth, '\0', sizeof(auth)); - /* interface -> set "req->myip" */ + /* interface -- determine IP and set "req->myip" */ switch (cgetstr(buf, "interface", &if_name)) { case -1: if_name = NULL; @@ -123,7 +125,7 @@ getconf(char **db_array, char *name, struct dd_request *req) } if (if_name != NULL && req->myip != NULL) - errx(1, "either \"interface\" or \"myip\" should be specifed"); + errx(1, "either \"interface\" or \"myip\" should be specified"); if (if_name != NULL) if_ntoa(if_name, &req->myip); @@ -135,6 +137,7 @@ getconf(char **db_array, char *name, struct dd_request *req) errx(1, "malloc"); } + /* following options are all optional */ if (f_sys & (SYS_DYN|SYS_STAT)) { if (cgetcap(buf, "wildcard", ':') != NULL) req->wildcard = "ON"; @@ -189,8 +192,7 @@ parse_config(char *file, struct dd_request **req) while ((name = strsep(&buf, ": \t")) != NULL) { if (*name) { req[count] = malloc(sizeof(struct dd_request)); - getconf(db_array, name, req[count]); - count++; + getconf(db_array, name, req[count++]); } } @@ -198,6 +200,7 @@ parse_config(char *file, struct dd_request **req) #if DEBUG if (debug) { + int i; for (i = 0; i < count; i++) { printf("===> No. %d\n", i); print_config(req[i]); @@ -211,9 +214,8 @@ parse_config(char *file, struct dd_request **req) int free_config(int reqc, struct dd_request **reqv) { - int i; + while (reqc > 0) + free(reqv[--reqc]); - for (i = 0; i < reqc; i++) - free(reqv[i]); return 0; } diff --git a/parse.h b/parse.h index bb86334..ac620f4 100644 --- a/parse.h +++ b/parse.h @@ -35,7 +35,7 @@ static struct dd_conf { } conf[] = { { "username", NULL, SYS_ALL, VAL_STR, OPT_NO }, { "password", NULL, SYS_ALL, VAL_STR, OPT_NO }, -// { "system", NULL, SYS_ALL, VAL_STR, OPT_YES }, +/* { "system", NULL, SYS_ALL, VAL_STR, OPT_YES }, */ { "dyndns", NULL, SYS_DYN, VAL_NONE, OPT_YES }, { "statdns", NULL, SYS_STAT, VAL_NONE, OPT_YES }, { "custdns", NULL, SYS_CUST, VAL_NONE, OPT_YES }, diff --git a/request.c b/request.c index f5d5f77..2a01792 100644 --- a/request.c +++ b/request.c @@ -111,6 +111,7 @@ int do_request(int reqc, struct dd_request **reqv) { int i; + int ret = reqc; int sockfd; char buf[BUFLEN]; @@ -125,9 +126,9 @@ do_request(int reqc, struct dd_request **reqv) if (debug) printf("response:\n%s\n", buf); - if (parse_answer(buf) == RET_ERR) - return -1; + if (parse_answer(buf) == RET_OK) + ret--; } - return 0; + return ret; } diff --git a/request.h b/request.h index a32d3f4..d28f3fc 100644 --- a/request.h +++ b/request.h @@ -23,7 +23,7 @@ #define DYNDNSPORT2 8245 struct dd_request { -// char *name; +/* char *name; */ char *auth; char *system; char *hostname; -- cgit v1.2.3