2019-06-14 14:49:13 +02:00
|
|
|
#ifndef __COMMANDS_H__
|
|
|
|
# define __COMMANDS_H__
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
2019-06-14 19:24:48 +02:00
|
|
|
/* Define session_s */
|
2019-06-14 14:49:13 +02:00
|
|
|
#include <utils.h>
|
|
|
|
|
2019-06-14 19:24:48 +02:00
|
|
|
/* cmd_block - data part of command block */
|
|
|
|
struct cmd_block
|
2019-06-14 14:49:13 +02:00
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
void (*constructor)(int, char **, struct session_s *, char *);
|
|
|
|
const char *man;
|
|
|
|
};
|
|
|
|
|
2019-06-14 19:24:48 +02:00
|
|
|
// CMDBLOCK()
|
|
|
|
// Generate a "command block" stored in ".cmd.cahce" section.
|
|
|
|
// We need to "hide" the block, so we generate anonyme name using
|
|
|
|
// __COUNTER__ macros.
|
2019-06-14 14:49:13 +02:00
|
|
|
#define gen_name(n) _##n
|
|
|
|
#define anonym_name(n) gen_name(n)
|
|
|
|
#define CMDBLOCK(cmd,callback,string) \
|
|
|
|
__attribute__((section(".cmd.cache"))) \
|
2019-06-14 19:24:48 +02:00
|
|
|
static const struct cmd_block anonym_name(__COUNTER__) = { \
|
2019-06-14 14:49:13 +02:00
|
|
|
.name = cmd, \
|
|
|
|
.constructor = callback, \
|
|
|
|
.man = string \
|
|
|
|
}
|
|
|
|
|
2019-06-14 19:24:48 +02:00
|
|
|
/* command_entry() - parse and execute the user's command. */
|
2019-06-14 14:49:13 +02:00
|
|
|
void command_entry(struct session_s *session, struct vhex_s *vhex);
|
2019-06-14 19:24:48 +02:00
|
|
|
|
|
|
|
/* cmd_cache_find() - find command in the cache section. */
|
2019-06-14 22:58:45 +02:00
|
|
|
const struct cmd_block *cmd_cache_find(char const *name);
|
2019-06-14 19:24:48 +02:00
|
|
|
|
2019-06-14 14:49:13 +02:00
|
|
|
#endif /*__COMMANDS_H__*/
|