summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-18 09:37:57 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2011-05-18 09:37:57 (GMT)
commitf46531f8627326bb31f75250096986d162ce5fdb (patch) (side-by-side diff)
tree46711a8fbfec60f0a99748cbe376b8240a70e25b
parent768689775c020ae36a0de7b3fdc166777685bd6e (diff)
downloadnssync-f46531f8627326bb31f75250096986d162ce5fdb.tar.gz
nssync-f46531f8627326bb31f75250096986d162ce5fdb.tar.bz2
Print to a specified output file.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/nssync.c2
-rw-r--r--src/nssync.h1
-rw-r--r--src/output.c70
3 files changed, 39 insertions, 34 deletions
diff --git a/src/nssync.c b/src/nssync.c
index ce55bc4..6360fc2 100644
--- a/src/nssync.c
+++ b/src/nssync.c
@@ -51,7 +51,7 @@ main(int argc, char **argv)
EX_CONFIG : 0);
config_parse();
sql_connect();
- format_soa();
+ format_soa(stdout);
//FIXME
exit(0);
diff --git a/src/nssync.h b/src/nssync.h
index aef5fa4..028d6a0 100644
--- a/src/nssync.h
+++ b/src/nssync.h
@@ -63,5 +63,6 @@ void sql_disconnect(void);
int sql_do_query(const char *query,
int (*fun)(MYSQL_ROW, unsigned, void*), void *data);
+void format_soa(FILE *fp);
diff --git a/src/output.c b/src/output.c
index 3a6ba35..72a09c1 100644
--- a/src/output.c
+++ b/src/output.c
@@ -28,13 +28,14 @@ enum {
int
format_ns_record(MYSQL_ROW row, unsigned nf, void *data)
{
+ FILE *fp = data;
if (nf != _ns_nfields) {
error("NS query returned wrong number of fields");
return 1;
}
/* FIXME: TTL */
- printf("\t%s\t%s\n",
- row[f_ns_type], row[f_ns_data]);
+ fprintf(fp, "\t%s\t%s\n",
+ row[f_ns_type], row[f_ns_data]);
return 0;
}
@@ -51,6 +52,7 @@ enum {
int
format_rr_record(MYSQL_ROW row, unsigned nf, void *data)
{
+ FILE *fp = data;
if (nf != _rr_nfields) {
error("RR query returned wrong number of fields");
return 1;
@@ -58,13 +60,13 @@ format_rr_record(MYSQL_ROW row, unsigned nf, void *data)
if (!row[f_rr_type])
return 0;
if (strcasecmp(row[f_rr_type], "MX") == 0)
- printf("%s\t%s\tMX\t%s\t%s\n",
- row[f_rr_host], S(row[f_rr_ttl]),
- row[f_rr_priority], row[f_rr_data]);
+ fprintf(fp, "%s\t%s\tMX\t%s\t%s\n",
+ row[f_rr_host], S(row[f_rr_ttl]),
+ row[f_rr_priority], row[f_rr_data]);
else
- printf("%s\t%s\t%s\t%s\n",
- row[f_rr_host], S(row[f_rr_ttl]),
- row[f_rr_type], row[f_rr_data]);
+ fprintf(fp, "%s\t%s\t%s\t%s\n",
+ row[f_rr_host], S(row[f_rr_ttl]),
+ row[f_rr_type], row[f_rr_data]);
return 0;
}
@@ -96,6 +98,7 @@ is_reverse_zone(const char *str)
int
format_soa_record(MYSQL_ROW row, unsigned nf, void *data)
{
+ FILE *fp = data;
struct wordsplit ws;
const char *env[3];
@@ -105,29 +108,30 @@ format_soa_record(MYSQL_ROW row, unsigned nf, void *data)
}
if (!row[f_soa_type])
return 0;
- printf("$ORIGIN .\n");
+ fprintf(fp, "$ORIGIN .\n");
if (row[f_soa_ttl])
- printf("$TTL %s\n", row[f_soa_ttl]);
- printf("%s %s IN SOA %s %s (\n"
- "\t%s ; Serial\n"
- "\t%s ; Refresh\n"
- "\t%s ; Retry\n"
- "\t%s ; Expire\n"
- "\t%s) ; Minimum\n",
- row[f_soa_zone],
- S(row[f_soa_ttl]),
- row[f_soa_data],
- row[f_soa_person],
- row[f_soa_serial],
- row[f_soa_refresh],
- row[f_soa_retry],
- row[f_soa_expire],
- row[f_soa_minimum]);
-
+ fprintf(fp, "$TTL %s\n", row[f_soa_ttl]);
+ fprintf(fp,
+ "%s %s IN SOA %s %s (\n"
+ "\t%s ; Serial\n"
+ "\t%s ; Refresh\n"
+ "\t%s ; Retry\n"
+ "\t%s ; Expire\n"
+ "\t%s) ; Minimum\n",
+ row[f_soa_zone],
+ S(row[f_soa_ttl]),
+ row[f_soa_data],
+ row[f_soa_person],
+ row[f_soa_serial],
+ row[f_soa_refresh],
+ row[f_soa_retry],
+ row[f_soa_expire],
+ row[f_soa_minimum]);
+
env[0] = "zone";
env[1] = row[f_soa_zone];
env[2] = 0;
-
+
ws.ws_env = env;
if (wordsplit(ns_query, &ws,
WRDSF_NOCMD | WRDSF_ENV | WRDSF_ENV_KV | WRDSF_NOSPLIT |
@@ -136,7 +140,7 @@ format_soa_record(MYSQL_ROW row, unsigned nf, void *data)
exit(EX_SOFTWARE);
}
- if (sql_do_query(ws.ws_wordv[0], format_ns_record, NULL))
+ if (sql_do_query(ws.ws_wordv[0], format_ns_record, fp))
exit(EX_UNAVAILABLE);
if (wordsplit((rev_rr_query && is_reverse_zone(row[f_soa_zone])) ?
@@ -146,18 +150,18 @@ format_soa_record(MYSQL_ROW row, unsigned nf, void *data)
error("cannot split rr_query: %s", wordsplit_strerror(&ws));
exit(EX_SOFTWARE);
}
-
- if (sql_do_query(ws.ws_wordv[0], format_rr_record, NULL))
+
+ if (sql_do_query(ws.ws_wordv[0], format_rr_record, fp))
exit(EX_UNAVAILABLE);
-
+
wordsplit_free(&ws);
return 0;
}
void
-format_soa()
+format_soa(FILE *fp)
{
- if (sql_do_query(soa_query, format_soa_record, NULL))
+ if (sql_do_query(soa_query, format_soa_record, fp))
exit(EX_UNAVAILABLE);
}

Return to:

Send suggestions and report system problems to the System administrator.