diff --git a/SRC/PLUGINS b/SRC/PLUGINS index 6c443c7..3fef949 100644 --- a/SRC/PLUGINS +++ b/SRC/PLUGINS @@ -16,11 +16,12 @@ cooked one by returning a port name or NULL from the init() function. You will have to provide three functions: -char * init (const int argc, const char **argv) Accepts remaining - arguments (you have to use popt to parse them, or do it by hand, - getopt does not allow you to resume the parsing) and returns a - string identifying the port name (cooked interface) or NULL (raw - interface). +char * init (const int argc, const char **argv, const echoping_options options)) + Accepts remaining arguments (you have to use popt to parse them, or do + it by hand, getopt does not allow you to resume the parsing) and + returns a string identifying the port name (cooked interface) or NULL + (raw interface). The options struct will give you the global options + (see echoping.h). For the cooked interface: diff --git a/SRC/echoping.c b/SRC/echoping.c index de796cc..d6cac75 100644 --- a/SRC/echoping.c +++ b/SRC/echoping.c @@ -88,7 +88,6 @@ main (argc, argv) char *ext; void *plugin; int plugin_result; - char *dl_result; void to_alarm (); /* our alarm() signal handler */ void interrupted (); @@ -141,6 +140,7 @@ main (argc, argv) int tos; int tos_requested = 0; char *p; + echoping_options global_options; /* popt variables */ const struct poptOption options[] = { @@ -174,6 +174,9 @@ main (argc, argv) }; poptContext poptcon; + global_options.udp = 0; + global_options.verbose = 0; + null_timeval.tv_sec = 0; null_timeval.tv_usec = 0; max_timeval.tv_sec = 1000000000; @@ -457,7 +460,10 @@ main (argc, argv) { err_sys ("Cannot find init in %s: %s", plugin_name, dlerror ()); } - plugin_port_name = plugin_init (remaining, (const char **) leftover); + global_options.udp = udp; + global_options.verbose = verbose; + plugin_port_name = + plugin_init (remaining, (const char **) leftover, global_options); if (plugin_port_name != NULL) { strcpy (port_name, plugin_port_name); @@ -889,7 +895,7 @@ main (argc, argv) { plugin_result = plugin_execute (); if (plugin_result == -2) - err_quit(""); + err_quit (""); } else { diff --git a/SRC/echoping.h b/SRC/echoping.h index d634166..03176f0 100644 --- a/SRC/echoping.h +++ b/SRC/echoping.h @@ -35,7 +35,7 @@ #include #include -/* popt library TODO: what if missing? */ +/* popt library */ #include #ifdef OPENSSL @@ -119,11 +119,17 @@ struct result }; unsigned short timeout_flag; - +struct echoping_struct +{ + unsigned short udp; /* Use the UDP protocol (TCP is the default) */ + unsigned short verbose; +}; +typedef struct echoping_struct echoping_options; #ifndef IN_PLUGIN /* The functions we will find in the plugin */ -/* Initializes the plugin with its arguments. Returns the port name or number. */ -typedef char * (*init_f) (const int argc, const char **argv); +/* Initializes the plugin with its arguments. Returns the port name or number or NULL if the plugin wants to use the raw interface. */ +typedef char *(*init_f) (const int argc, const char **argv, + const echoping_options global_options); init_f plugin_init; typedef void (*start_f) (struct addrinfo *); start_f plugin_start; diff --git a/SRC/plugins/postgresql/Makefile.am b/SRC/plugins/postgresql/Makefile.am index e4ea81d..9552322 100644 --- a/SRC/plugins/postgresql/Makefile.am +++ b/SRC/plugins/postgresql/Makefile.am @@ -2,6 +2,7 @@ if PGSQLBUILD pkglib_LTLIBRARIES = postgresql.la postgresql_la_SOURCES = postgresql.c postgresql_la_LDFLAGS = -module +man_MANS = echoping_postgresql.1 endif # $Id$ diff --git a/SRC/plugins/postgresql/Makefile.in b/SRC/plugins/postgresql/Makefile.in index d778b31..176c2b4 100644 --- a/SRC/plugins/postgresql/Makefile.in +++ b/SRC/plugins/postgresql/Makefile.in @@ -55,7 +55,7 @@ am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs CONFIG_HEADER = config.h CONFIG_CLEAN_FILES = -am__installdirs = "$(DESTDIR)$(pkglibdir)" +am__installdirs = "$(DESTDIR)$(pkglibdir)" "$(DESTDIR)$(man1dir)" pkglibLTLIBRARIES_INSTALL = $(INSTALL) LTLIBRARIES = $(pkglib_LTLIBRARIES) postgresql_la_LIBADD = @@ -76,6 +76,9 @@ LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ SOURCES = $(postgresql_la_SOURCES) DIST_SOURCES = $(am__postgresql_la_SOURCES_DIST) +man1dir = $(mandir)/man1 +NROFF = nroff +MANS = $(man_MANS) ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -188,6 +191,7 @@ target_alias = @target_alias@ @PGSQLBUILD_TRUE@pkglib_LTLIBRARIES = postgresql.la @PGSQLBUILD_TRUE@postgresql_la_SOURCES = postgresql.c @PGSQLBUILD_TRUE@postgresql_la_LDFLAGS = -module +@PGSQLBUILD_TRUE@man_MANS = echoping_postgresql.1 all: config.h $(MAKE) $(AM_MAKEFLAGS) all-am @@ -314,6 +318,51 @@ clean-libtool: distclean-libtool: -rm -f libtool uninstall-info-am: +install-man1: $(man1_MANS) $(man_MANS) + @$(NORMAL_INSTALL) + test -z "$(man1dir)" || $(mkdir_p) "$(DESTDIR)$(man1dir)" + @list='$(man1_MANS) $(dist_man1_MANS) $(nodist_man1_MANS)'; \ + l2='$(man_MANS) $(dist_man_MANS) $(nodist_man_MANS)'; \ + for i in $$l2; do \ + case "$$i" in \ + *.1*) list="$$list $$i" ;; \ + esac; \ + done; \ + for i in $$list; do \ + if test -f $(srcdir)/$$i; then file=$(srcdir)/$$i; \ + else file=$$i; fi; \ + ext=`echo $$i | sed -e 's/^.*\\.//'`; \ + case "$$ext" in \ + 1*) ;; \ + *) ext='1' ;; \ + esac; \ + inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \ + inst=`echo $$inst | sed -e 's/^.*\///'`; \ + inst=`echo $$inst | sed '$(transform)'`.$$ext; \ + echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man1dir)/$$inst'"; \ + $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man1dir)/$$inst"; \ + done +uninstall-man1: + @$(NORMAL_UNINSTALL) + @list='$(man1_MANS) $(dist_man1_MANS) $(nodist_man1_MANS)'; \ + l2='$(man_MANS) $(dist_man_MANS) $(nodist_man_MANS)'; \ + for i in $$l2; do \ + case "$$i" in \ + *.1*) list="$$list $$i" ;; \ + esac; \ + done; \ + for i in $$list; do \ + ext=`echo $$i | sed -e 's/^.*\\.//'`; \ + case "$$ext" in \ + 1*) ;; \ + *) ext='1' ;; \ + esac; \ + inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \ + inst=`echo $$inst | sed -e 's/^.*\///'`; \ + inst=`echo $$inst | sed '$(transform)'`.$$ext; \ + echo " rm -f '$(DESTDIR)$(man1dir)/$$inst'"; \ + rm -f "$(DESTDIR)$(man1dir)/$$inst"; \ + done ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ @@ -492,9 +541,9 @@ distcleancheck: distclean exit 1; } >&2 check-am: all-am check: check-am -all-am: Makefile $(LTLIBRARIES) config.h +all-am: Makefile $(LTLIBRARIES) $(MANS) config.h installdirs: - for dir in "$(DESTDIR)$(pkglibdir)"; do \ + for dir in "$(DESTDIR)$(pkglibdir)" "$(DESTDIR)$(man1dir)"; do \ test -z "$$dir" || $(mkdir_p) "$$dir"; \ done install: install-am @@ -543,13 +592,13 @@ info: info-am info-am: -install-data-am: +install-data-am: install-man install-exec-am: install-pkglibLTLIBRARIES install-info: install-info-am -install-man: +install-man: install-man1 installcheck-am: @@ -573,7 +622,10 @@ ps: ps-am ps-am: -uninstall-am: uninstall-info-am uninstall-pkglibLTLIBRARIES +uninstall-am: uninstall-info-am uninstall-man \ + uninstall-pkglibLTLIBRARIES + +uninstall-man: uninstall-man1 .PHONY: CTAGS GTAGS all all-am am--refresh check check-am clean \ clean-generic clean-libtool clean-pkglibLTLIBRARIES ctags dist \ @@ -583,11 +635,12 @@ uninstall-am: uninstall-info-am uninstall-pkglibLTLIBRARIES distdir distuninstallcheck dvi dvi-am html html-am info \ info-am install install-am install-data install-data-am \ install-exec install-exec-am install-info install-info-am \ - install-man install-pkglibLTLIBRARIES install-strip \ - installcheck installcheck-am installdirs maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-compile \ - mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ - tags uninstall uninstall-am uninstall-info-am \ + install-man install-man1 install-pkglibLTLIBRARIES \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags uninstall uninstall-am \ + uninstall-info-am uninstall-man uninstall-man1 \ uninstall-pkglibLTLIBRARIES diff --git a/SRC/plugins/postgresql/echoping_postgresql.1 b/SRC/plugins/postgresql/echoping_postgresql.1 new file mode 100644 index 0000000..75b808a --- /dev/null +++ b/SRC/plugins/postgresql/echoping_postgresql.1 @@ -0,0 +1,48 @@ +.\" Hey, EMACS: -*- nroff -*- +.\" First parameter, NAME, should be all caps +.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection +.\" other parameters are allowed: see man(7), man(1) +.TH ECHOPING_POSTGRESQL 1 "May 26, 2004" +.\" Please adjust this date whenever revising the manpage. +.\" +.\" Some roff macros, for reference: +.\" .nh disable hyphenation +.\" .hy enable hyphenation +.\" .ad l left justify +.\" .ad b justify to both left and right margins +.\" .nf disable filling +.\" .fi enable filling +.\" .br insert line break +.\" .sp insert n+1 empty lines +.\" for manpage-specific macros, see man(7) +.SH NAME +echoping_postgresql \- echoping plugin which connects to a PostgreSQL RDBMS server +.SH SYNOPSIS +.B echoping +.RI [echoping\ options] +.RI -m\ postgresql +.B hostname +.RI [-c conninfo] +.RI [request] +.SH DESCRIPTION +.PP +.\" TeX users may be more comfortable with the \fB\fP and +.\" \fI\fP escape sequences to invode bold face and italics, +.\" respectively. +postgresql is an echoping plugin to connect to PostgreSQL RDBMS servers. +.SH ARGUMENTS +.B [request] +The request to the PostgreSQL server (in SQL). Only SELECT are +supported. The default is 'SELECT now()'. +.TP +.SH OPTIONS +.TP +.B \-c, \-\-conninfo +Connection information for the Postgresql server. Something like 'host=foo dbname=bar' +.TP +.B \-r, \-\-readall +Read all the data sent by the Postgresql server +.SH SEE ALSO +.BR echoping (1), +.SH AUTHOR +Stephane Bortzmeyer diff --git a/SRC/plugins/postgresql/postgresql.c b/SRC/plugins/postgresql/postgresql.c index 8575fe9..f2b520b 100644 --- a/SRC/plugins/postgresql/postgresql.c +++ b/SRC/plugins/postgresql/postgresql.c @@ -15,6 +15,7 @@ poptContext postgresql_poptcon; PGconn *conn; PGresult *res; char *conninfo; +echoping_options global_options; void postgresql_usage (const char *msg) @@ -28,23 +29,25 @@ postgresql_usage (const char *msg) } char * -init (const int argc, const char **argv) +init (const int argc, const char **argv, + const echoping_options global_external_options) { int value; char *msg = malloc (256); + char *hostname; /* popt variables */ struct poptOption options[] = { {"conninfo", 'c', POPT_ARG_STRING, &conninfo, 0, "Connection information for the Postgresql server. Something like 'host=foo dbname=bar''", - "request"}, - {"request", 'r', POPT_ARG_STRING, &request, 0, - "Request/query (in SQL) to send to the Postgresql server. Only SELECT are supported.", - "request"}, + ""}, {"readall", 'a', POPT_ARG_NONE, &readall, 0, "Read all the data sent by the Postgresql server", ""}, POPT_AUTOHELP POPT_TABLEEND }; + global_options = global_external_options; + if (global_options.udp) + err_quit ("UDP makes no sense for a PostgreSQL connection"); postgresql_poptcon = poptGetContext (NULL, argc, argv, options, POPT_CONTEXT_KEEP_FIRST); @@ -58,10 +61,12 @@ init (const int argc, const char **argv) postgresql_usage (msg); } } - if (request == NULL) /* TODO: a default like SELECT now()? */ - postgresql_usage ("Mandatory request missing"); + hostname = poptGetArg (postgresql_poptcon); /* Not used */ + request = poptGetArg (postgresql_poptcon); + if (request == NULL) + request = "SELECT now()"; if (conninfo == NULL) - postgresql_usage ("Mandatory connection information missing"); + conninfo = ""; return NULL; /* We only use the conninfo, echoping does not see our hostname or port */ } @@ -89,6 +94,8 @@ execute () printf ("Cannot run \"%s\": %s\n", request, PQresultErrorMessage (res)); return -1; } + if (global_options.verbose) + printf ("%d tuples returned\n", PQntuples (res)); if (readall) { for (row = 0; row++; row < PQntuples (res)) diff --git a/SRC/plugins/whois/whois.c b/SRC/plugins/whois/whois.c index 919ce0d..d635223 100644 --- a/SRC/plugins/whois/whois.c +++ b/SRC/plugins/whois/whois.c @@ -29,7 +29,7 @@ whois_usage (const char *msg) } char * -init (const int argc, const char **argv) +init (const int argc, const char **argv, echoping_options global_options) { int value; char *msg = malloc (256); @@ -43,6 +43,9 @@ init (const int argc, const char **argv) ""}, POPT_AUTOHELP POPT_TABLEEND }; + if (global_options.udp) + err_quit ("UDP is incompatible with this whois plugin"); + /* Will probably be cached before because /etc/services have no entry for UDP port 43 */ whois_poptcon = poptGetContext (NULL, argc, argv, options, POPT_CONTEXT_KEEP_FIRST); while ((value = poptGetNextOpt (whois_poptcon)) > 0) @@ -105,5 +108,7 @@ execute () return 1; } -void terminate() { +void +terminate () +{ }