mirror of https://framagit.org/bortzmeyer/echoping
First contrib plugins
parent
ccf3ab5b5c
commit
61fc1a3223
@ -0,0 +1,3 @@
|
|||||||
|
Various echoping goodies, plugins, etc. No warranty at all, no
|
||||||
|
support.
|
||||||
|
|
@ -0,0 +1,7 @@
|
|||||||
|
if ADAMSNAMESBUILD
|
||||||
|
pkglib_LTLIBRARIES = domquery.la
|
||||||
|
domquery_la_SOURCES = domquery.c util.c
|
||||||
|
domquery_la_LDFLAGS = -module
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
@ -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$ */
|
@ -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)
|
@ -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 <stdio.h>
|
||||||
|
|
||||||
|
/* http://xmlrpc-c.sourceforge.net/ */
|
||||||
|
#include <xmlrpc.h>
|
||||||
|
#include <xmlrpc_client.h>
|
||||||
|
|
||||||
|
#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 ();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
#include <xmlrpc.h>
|
||||||
|
#include <xmlrpc_client.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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}
|
@ -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 ()
|
||||||
|
{
|
||||||
|
}
|
Loading…
Reference in New Issue