From 61fc1a322327e75e600538be8509ea638aad4eb1 Mon Sep 17 00:00:00 2001 From: Stephane Bortzmeyer Date: Tue, 15 Jun 2004 21:30:24 +0000 Subject: [PATCH] First contrib plugins --- SRC/contrib/README | 3 + SRC/contrib/adamsnames/Makefile.am | 7 ++ SRC/contrib/adamsnames/common.h | 10 +++ SRC/contrib/adamsnames/configure.ac | 15 ++++ SRC/contrib/adamsnames/domquery.c | 108 ++++++++++++++++++++++++++++ SRC/contrib/adamsnames/util.c | 15 ++++ SRC/contrib/daytime/Makefile | 17 +++++ SRC/contrib/daytime/daytime.c | 54 ++++++++++++++ 8 files changed, 229 insertions(+) create mode 100644 SRC/contrib/README create mode 100644 SRC/contrib/adamsnames/Makefile.am create mode 100644 SRC/contrib/adamsnames/common.h create mode 100644 SRC/contrib/adamsnames/configure.ac create mode 100644 SRC/contrib/adamsnames/domquery.c create mode 100644 SRC/contrib/adamsnames/util.c create mode 100644 SRC/contrib/daytime/Makefile create mode 100644 SRC/contrib/daytime/daytime.c diff --git a/SRC/contrib/README b/SRC/contrib/README new file mode 100644 index 0000000..b480904 --- /dev/null +++ b/SRC/contrib/README @@ -0,0 +1,3 @@ +Various echoping goodies, plugins, etc. No warranty at all, no +support. + diff --git a/SRC/contrib/adamsnames/Makefile.am b/SRC/contrib/adamsnames/Makefile.am new file mode 100644 index 0000000..83439e5 --- /dev/null +++ b/SRC/contrib/adamsnames/Makefile.am @@ -0,0 +1,7 @@ +if ADAMSNAMESBUILD +pkglib_LTLIBRARIES = domquery.la +domquery_la_SOURCES = domquery.c util.c +domquery_la_LDFLAGS = -module +endif + + diff --git a/SRC/contrib/adamsnames/common.h b/SRC/contrib/adamsnames/common.h new file mode 100644 index 0000000..35aa632 --- /dev/null +++ b/SRC/contrib/adamsnames/common.h @@ -0,0 +1,10 @@ +#define CLIENT_NAME "XML-RPC Adams Names plugin for echoping" +#define CLIENT_VERSION "0.0" + +#define ENDPOINT "http://www.adamsnames.tc/api/xmlrpc" + +poptContext poptcon; +xmlrpc_env env; +char *domain; + +/* $Id$ */ diff --git a/SRC/contrib/adamsnames/configure.ac b/SRC/contrib/adamsnames/configure.ac new file mode 100644 index 0000000..3c7f7bf --- /dev/null +++ b/SRC/contrib/adamsnames/configure.ac @@ -0,0 +1,15 @@ +dnl $Id$ + +AC_INIT(adamsnames, 0.0-BETA) +AC_PROG_CC(cc gcc) +AC_PROG_LIBTOOL +AM_INIT_AUTOMAKE(foreign) +AC_CONFIG_HEADERS(config.h) + +AC_CHECK_PROG(ADAMSNAMES_BUILD, xmlrpc-c-config, 1, 0) +if test "$ADAMSNAMES_BUILD" = 1; then + LIBS="${LIBS} `xmlrpc-c-config libwww-client --libs`" + CCFLAGS="${CCFLAGS} `xmlrpc-c-config libwww-client --cflags`" +fi +AM_CONDITIONAL(ADAMSNAMESBUILD, test "$ADAMSNAMES_BUILD" = 1) +AC_OUTPUT(Makefile) diff --git a/SRC/contrib/adamsnames/domquery.c b/SRC/contrib/adamsnames/domquery.c new file mode 100644 index 0000000..150e06d --- /dev/null +++ b/SRC/contrib/adamsnames/domquery.c @@ -0,0 +1,108 @@ +/* echoping plugin to query (with XML-RPC) Adam's Names, the DNS registry. + See http://www.adamsnames.tc/api/xmlrpc.html. + $Id$ +*/ + +#define IN_PLUGIN +#include "../../echoping.h" + +#include + +/* http://xmlrpc-c.sourceforge.net/ */ +#include +#include + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "common.h" + +void +domquery_usage (char *msg) +{ + fprintf (stderr, "%s\n", msg); + poptPrintUsage (poptcon, stderr, 0); + err_quit(" domain"); +} + +char * +init (int argc, char **argv) +{ + int value; + xmlrpc_value *result; + xmlrpc_bool free, read_contacts; + xmlrpc_int32 reason; + char *msg, *hostname; + + struct poptOption options[] = { + {"read-contacts", 'c', POPT_ARG_NONE, &read_contacts, 0, + "Read also the contacts of the domain [NOT IMPLEMENTED]", + ""}, + POPT_AUTOHELP POPT_TABLEEND + }; + poptcon = poptGetContext (NULL, argc, + argv, options, POPT_CONTEXT_KEEP_FIRST); + while ((value = poptGetNextOpt (poptcon)) > 0) + { + if (value < -1) + { + sprintf (msg, "%s: %s", + poptBadOption (poptcon, POPT_BADOPTION_NOALIAS), + poptStrerror (value)); + domquery_usage (msg); + } + } + hostname = (char *) poptGetArg (poptcon); /* Not used */ + domain = (char *) poptGetArg (poptcon); + if (domain == NULL) + domquery_usage ("Mandatory request missing"); + + return NULL; +} + +void +start_raw() { + + /* Start up our XML-RPC client library. */ + xmlrpc_client_init (XMLRPC_CLIENT_NO_FLAGS, CLIENT_NAME, CLIENT_VERSION); + + /* Initialize our error-handling environment. */ + xmlrpc_env_init (&env); + +} + +int +execute () +{ + xmlrpc_value *result; + xmlrpc_value *domain_h; + xmlrpc_bool found; + xmlrpc_value *error; + char *dst; + dst = HTAnchor_findAddress(ENDPOINT); + /* Call the server */ + result = xmlrpc_client_call (&env, ENDPOINT, "domquery", "(s)", domain); + die_if_fault_occurred (&env); + + xmlrpc_parse_value (&env, result, "{{},b,[]*}", "domain", domain_h, "found", &found, "error", error); + die_if_fault_occurred (&env); + if (found) + { + printf ("%s is there\n", domain); + } + /* Dispose of our result value. */ + xmlrpc_DECREF (result); + return 0; +} + +void +terminate () +{ + /* Clean up our error-handling environment. */ + xmlrpc_env_clean (&env); + + /* Shutdown our XML-RPC client library. */ + xmlrpc_client_cleanup (); + + } diff --git a/SRC/contrib/adamsnames/util.c b/SRC/contrib/adamsnames/util.c new file mode 100644 index 0000000..0afccdf --- /dev/null +++ b/SRC/contrib/adamsnames/util.c @@ -0,0 +1,15 @@ +/* $Id$ */ + +#include +#include + +void +die_if_fault_occurred (xmlrpc_env * env) +{ + if (env->fault_occurred) + { + err_quit("XML-RPC Fault: %s (%d)\n", + env->fault_string, env->fault_code); + } +} + diff --git a/SRC/contrib/daytime/Makefile b/SRC/contrib/daytime/Makefile new file mode 100644 index 0000000..fb80fa5 --- /dev/null +++ b/SRC/contrib/daytime/Makefile @@ -0,0 +1,17 @@ +CCFLAGS=-Wall -O0 -g -fPIC +LDFLAGS=-shared + +OBJECTS=daytime.o + +all: daytime.so + +%.o: %.c + ${CC} ${CCFLAGS} -c -o $@ $< + +%.so: %.o + ${CC} ${LDFLAGS} -o $@ $< + +clean: + -rm -f *.o *.so + +.SECONDARY: ${OBJECTS} diff --git a/SRC/contrib/daytime/daytime.c b/SRC/contrib/daytime/daytime.c new file mode 100644 index 0000000..dbc1f6e --- /dev/null +++ b/SRC/contrib/daytime/daytime.c @@ -0,0 +1,54 @@ +/* + * Daytime (RFC 867) plugin. + * + * $Id$ + */ + +#define IN_PLUGIN +#include "../../echoping.h" + +struct addrinfo daytime_server; +int sockfd; +echoping_options options; + +char * +init (const int argc, const char **argv, echoping_options global_options) +{ + if (global_options.udp) + err_quit ("Sorry, UDP is not yet compatible with this daytime plugin"); + options = global_options; + return "daytime"; +} + +void +start (struct addrinfo *res) +{ + daytime_server = *res; +} + +int +execute () +{ + int nr; + FILE *file; +#define MAX 256 + char recvline[MAX]; + if ((sockfd = + socket (daytime_server.ai_family, daytime_server.ai_socktype, + daytime_server.ai_protocol)) < 0) + err_sys ("Can't open socket"); + if (connect (sockfd, daytime_server.ai_addr, daytime_server.ai_addrlen) < 0) + err_sys ("Can't connect to server"); + if ((file = fdopen (sockfd, "r")) == NULL) + err_sys ("Cannot fdopen"); + nr = readline (file, recvline, MAX, 1); + if (options.verbose) + printf ("%s", recvline); + close (sockfd); + return 1; +} + +void +terminate () +{ +}