/*
 * dispatch.c
 *
 *  Created on: Sep 6, 2018
 *      Author: root
 */

#include "commands.h"
#include "dispatch.h"

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


int DispatchCommand(char* recv_buffer, char** tokens, int nTokens, char* send_buffer)
{
	int i = 0, n = NUM_COMMANDS;

	for (i=0; i<n; i++)
	{
		if (0 == strcmp(tokens[0], commandHandlers[i].command))
		{
			return commandHandlers[i].handler(tokens, nTokens, send_buffer);
		}
	}

  //sprintf(send_buffer, "NAK Unknown command.\n");
	sprintf(send_buffer, "Unknown command.");
	return CMDFAILURE;
}
