shithub: ircd

ref: b579d46f62e61c4fbb97ed9edd024ddb26def34d
dir: /cmd.c/

View raw version
#include <u.h>
#include <libc.h>
#include "dat.h"
#include "fns.h"
#include "cmd.h"
#include "version.h"

static void
cversion(Request *r)
{
	if (r->args[0]) {
		fprint(2, "get version of '%s' (not implemented yet!)\n", r->args[0]);
		reply(Enosuchserver, r->args[0]);
		return;
	}
	reply(Rversion, getversion());
}

static Command commands[] = {
	{ "version", cversion },
};
int ncommands = sizeof(commands) / sizeof(Command);

Command*
findcommand(char *s)
{
	for (int i = 0; i < ncommands; i++) {
		if (cistrcmp(commands[i].name, s) == 0)
			return &commands[i];
	}
	return nil;
}

Command*
findcommandn(int n)
{
	return nil;
}

void
execrequest(Request r)
{
	if (!(r.cmd && r.cmd->func)) {
		fprint(2, "cannot execute request: no command\n");
		return;
	}
	if (debug)
		fprint(2, "run command '%s'\n", r.cmd->name);
	r.cmd->func(&r);
}