NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
commandProcessor.c
1#define _CRT_SECURE_NO_WARNINGS
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <Ws2tcpip.h>
6#include <windows.h>
7#include <stdbool.h>
8#include "CLI.h"
9
10void send_message(ptrCLIENTINFO info, char* msg, ...)
11{
12 char sendMSG[2 * BUFSIZ];
13 va_list l;
14 va_start(l, msg);
15 vsprintf(sendMSG, msg, l);
16 if (info->clientType == CLIENTTYPE_SOCKET)
17 send_to_socket(info, sendMSG, (int)strlen(sendMSG) + 1);
18 else if (info->clientType == CLIENTTYPE_FILE)
19 write_to_file(info, sendMSG, (int)strlen(sendMSG) + 1);
20 else if (info->clientType == CLIENTTYPE_STRING)
21 add_to_string(info, sendMSG, (int)strlen(sendMSG) + 1);
22}
23
24static void commandProcessor(ptrCLIENTINFO info, char* command)
25{
26 ptrCOMMANDARRAY ls = get_commandArray(command);
27 char* first = ls->commands[0];
28 if (!_stricmp(first, CMD_CONTINUE))
29 cli_continue_simulation(info);
30 else if (!_stricmp(first, CMD_PAUSE))
31 cli_pause_simulation(info);
32 else if (!_stricmp(first, CMD_PAUSEAT))
33 cli_pause_simulation_at(info, atof(ls->commands[1]));
34 else if (!_stricmp(first, CMD_STOP))
35 cli_stop_simulation(info);
36 else if (!_stricmp(first, CMD_EXIT))
37 cli_clear_prompt(info);
38 else
39 {
40 if (validate_command(info, ls))
41 {
42 if (isCommandAsDeviceName(ls->commands[0]))
43 {
44 pass_to_SDNModule(info, ls);
45 }
46 else
47 {
48 execute_command(info, ls, info->deviceId);
49 }
50 }
51 }
52
53 free_commandArray(ls);
54}
55
56void process_command(ptrCLIENTINFO clientInfo, char* command, int len)
57{
58 commandProcessor(clientInfo, command);
59}