view cmu200/dispatch.c @ 0:bd62be88259d

initial import of rfcal code and docs from freecalypso-tools repository
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 20 May 2017 18:49:35 +0000
parents
children 504d3cbb95b5
line wrap: on
line source

/*
 * This module contains the code that dispatches client commands.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

extern char *client_cmd_fields[];
extern int client_cmd_nfields;

cmd_ping()
{
	send_socket_response("+Pong\n");
	return(0);
}

static struct cmdtab {
	char	*cmd_kw;
	int	(*handler)();
} cmdtab[] = {
	{"ping", cmd_ping},
	{0, 0}
};

dispatch_client_command()
{
	struct cmdtab *tp;

	for (tp = cmdtab; tp->cmd_kw; tp++)
		if (!strcmp(client_cmd_fields[0], tp->cmd_kw))
			break;
	if (tp->handler)
		return tp->handler();
	send_socket_response("-Unknown or unimplemented command\n");
	return(0);
}