#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#ifdef WIN32
#define strcasecmp _stricmp
#endif
#define PACKAGE "daliclient"
#define VERSION LIBDALI_VERSION
static short int verbose = 0;
static char *statefile = 0;
static char *matchpattern = 0;
static char *rejectpattern = 0;
static char *infotype = 0;
static int parameter_proc (int argcount, char **argvec);
static void usage (void);
int
main (int argc, char **argv)
{
char timestr[50];
char *infobuf = 0;
int infolen;
int endflag = 0;
if ( parameter_proc (argc, argv) < 0 )
{
fprintf (stderr, "Parameter processing failed\n\n");
fprintf (stderr, "Try '-h' for detailed help\n");
return -1;
}
{
fprintf (stderr, "Error connecting to server\n");
return -1;
}
{
return -1;
}
if ( matchpattern )
{
if (
dl_match (dlconn, matchpattern) < 0 )
return -1;
}
if ( rejectpattern )
{
return -1;
}
if ( infotype )
{
if ( (infolen =
dl_getinfo (dlconn, infotype, matchpattern, &infobuf, 0)) < 0 )
{
dl_log (2, 0,
"Problem requesting INFO from server\n");
return -1;
}
printf ("%.*s\n", infolen, infobuf);
if ( infobuf )
free (infobuf);
}
else
{
while (
dl_collect (dlconn, &dlpack, packetdata,
sizeof(packetdata), endflag) ==
DLPACKET )
{
dl_log (0, 0,
"Received %s (%" PRId64
"), %s, %d\n",
}
}
if ( dlconn->
link != -1 )
if ( statefile )
if ( dlconn )
return 0;
}
static int
parameter_proc (int argcount, char **argvec)
{
char *address = 0;
int keepalive = -1;
int optind;
for (optind = 1; optind < argcount; optind++)
{
if (strcmp (argvec[optind], "-V") == 0)
{
fprintf(stderr, "%s version: %s\n", PACKAGE, VERSION);
exit (0);
}
else if (strcmp (argvec[optind], "-h") == 0)
{
usage();
exit (0);
}
else if (strncmp (argvec[optind], "-v", 2) == 0)
{
verbose += strspn (&argvec[optind][1], "v");
}
else if (strcmp (argvec[optind], "-k") == 0)
{
keepalive = strtoul (argvec[++optind], NULL, 10);
}
else if (strcmp (argvec[optind], "-m") == 0)
{
matchpattern = argvec[++optind];
}
else if (strcmp (argvec[optind], "-r") == 0)
{
rejectpattern = argvec[++optind];
}
else if (strcmp (argvec[optind], "-i") == 0)
{
infotype = argvec[++optind];
}
else if (strcmp (argvec[optind], "-x") == 0)
{
statefile = argvec[++optind];
}
else if (strncmp (argvec[optind], "-", 1 ) == 0)
{
fprintf(stderr, "Unknown option: %s\n", argvec[optind]);
exit (1);
}
else if ( ! address )
{
address = argvec[optind];
}
else
{
fprintf(stderr, "Unknown option: %s\n", argvec[optind]);
exit (1);
}
}
if ( ! address )
{
fprintf(stderr, "No DataLink server specified\n\n");
fprintf(stderr, "%s version: %s\n\n", PACKAGE, VERSION);
fprintf(stderr, "Usage: %s [options] [host][:][port]\n", PACKAGE);
fprintf(stderr, "Try '-h' for detailed help\n");
exit (1);
}
if ( keepalive >= 0 )
dl_log (0, 1,
"%s version: %s\n", PACKAGE, VERSION);
if ( matchpattern && *matchpattern == '@' )
{
char *filename = matchpattern + 1;
{
dl_log (2, 0,
"Cannot read matching list file: %s\n", filename);
exit (1);
}
}
if ( rejectpattern && *rejectpattern == '@' )
{
char *filename = rejectpattern + 1;
{
dl_log (2, 0,
"Cannot read rejecting list file: %s\n", filename);
exit (1);
}
}
if ( statefile )
{
{
dl_log (2, 0,
"Error reading state file\n");
exit (1);
}
}
return 0;
}
static void
usage (void)
{
fprintf (stderr, "\nUsage: %s [options] [host][:][port]\n\n", PACKAGE);
fprintf (stderr,
" ## General program options ##\n"
" -V report program version\n"
" -h show this usage message\n"
" -v be more verbose, multiple flags can be used\n"
" -k secs specify keepalive interval in seconds\n"
" -m match specify stream ID matching pattern\n"
" -r reject specify stream ID rejecting pattern\n"
" -i type request INFO type, print XML and exit\n"
" -x statefile save/restore stream state information to this file\n"
"\n"
" [host][:][port] Address of the DataLink server in host:port format\n"
" if host is omitted (i.e. ':16000'), localhost is assumed\n"
" if :port is omitted (i.e. 'localhost'), 16000 is assumed\n\n");
}
dltime_t datastart
Definition libdali.h:263
int keepalive
Definition libdali.h:239
int32_t datasize
Definition libdali.h:265
SOCKET link
Definition libdali.h:243
int64_t pktid
Definition libdali.h:261
int64_t pktid
Definition libdali.h:247
char streamid[MAXSTREAMID]
Definition libdali.h:260
dltime_t pkttime
Definition libdali.h:248
char * dl_read_streamlist(DLCP *dlconn, const char *streamfile)
Create a compound regular expression from a list in a file.
Definition config.c:42
int64_t dl_match(DLCP *dlconn, char *matchpattern)
Set the packet match parameters for a connection.
Definition connection.c:391
int dl_recoverstate(DLCP *dlconn, const char *statefile)
Recover DataLink connection state from a file.
Definition statefile.c:95
void dl_freedlcp(DLCP *dlconn)
Free a DataLink Connection Parameter (DLCP) structure.
Definition connection.c:84
int dl_savestate(DLCP *dlconn, const char *statefile)
Save a DataLink connection state to a file.
Definition statefile.c:43
int dl_getinfo(DLCP *dlconn, const char *infotype, char *infomatch, char **infodata, size_t maxinfosize)
Request information from the DataLink server.
Definition connection.c:804
int64_t dl_position(DLCP *dlconn, int64_t pktid, dltime_t pkttime)
Position the client read position.
Definition connection.c:246
DLCP * dl_newdlcp(char *address, char *progname)
Create a new DataLink Connection Parameter (DLCP) structure.
Definition connection.c:42
int dl_collect(DLCP *dlconn, DLPacket *packet, void *packetdata, size_t maxdatasize, int8_t endflag)
Collect packets streaming from the DataLink server.
Definition connection.c:948
int64_t dl_reject(DLCP *dlconn, char *rejectpattern)
Set the packet reject parameters for a connection.
Definition connection.c:461
int dl_log(int level, int verb, const char *format,...)
Log a message using the global logging parameters.
Definition logging.c:215
void dl_loginit(int verbosity, void(*log_print)(char *), const char *logprefix, void(*diag_print)(char *), const char *errprefix)
Initialize global logging system parameters.
Definition logging.c:54
void dl_disconnect(DLCP *dlconn)
Disconnect a DataLink connection.
Definition network.c:219
SOCKET dl_connect(DLCP *dlconn)
Connect to a DataLink server.
Definition network.c:51
#define DLPACKET
Definition libdali.h:152
#define MAXPACKETSIZE
Definition libdali.h:139