protocol_console.c File Reference
#include "magma.h"Defines | |
| #define | INCLUDE_FLARE_INTERNALS |
| #define | PROMPT "\nMAGMA:%s> " |
| #define | sendline(buffer) send(peer_socket, buffer, strlen(buffer), 0) |
| #define | xsendline(pattern,...) |
| #define | TRANSFORM_PATH |
Functions | |
| ccmd_t * | add_hook (char *pattern, void(*hook)(int, session_environment_t *, char *, regmatch_t *), char *help) |
| char * | strcast (magma_flare_t *flare) |
| void | traverse_cache (int peer_socket, magma_flare_t *flare, unsigned int indent) |
| void | dump_cache (int peer_socket, session_environment_t *env, char *buffer, regmatch_t *matchptr) |
| void | send_cache_node (int peer_socket, session_environment_t *env, magma_flare_t *node, char *prefix) |
| void | print_cache (int peer_socket, session_environment_t *env, char *buffer, regmatch_t *matchptr) |
| void | print_help (int peer_socket, session_environment_t *env, char *buffer, regmatch_t *matchptr) |
| void | send_ls_entry (int peer_socket, char *realpath, char *de) |
| void | console_ls (int peer_socket, session_environment_t *env, char *buffer, regmatch_t *matchptr) |
| void | console_pwd (int peer_socket, session_environment_t *env, char *buffer, regmatch_t *matchptr) |
| void | console_cd (int peer_socket, session_environment_t *env, char *buffer, regmatch_t *matchptr) |
| void | console_cat (int peer_socket, session_environment_t *env, char *buffer, regmatch_t *matchptr) |
| void | print_lava (int peer_socket, session_environment_t *env, char *buffer, regmatch_t *matchptr) |
| void | inspect (int peer_socket, session_environment_t *env, char *buffer, regmatch_t *matchptr) |
| void | erase_flare (int peer_socket, session_environment_t *env, char *buffer, regmatch_t *matchptr) |
| void | server_shutdown (int peer_socket, session_environment_t *env, char *buffer, regmatch_t *matchptr) |
| void | cache_load (int peer_socket, session_environment_t *env, char *buffer, regmatch_t *matchptr) |
| void | init_console () |
| void | match_query (char *buffer, int peer_socket, session_environment_t *env) |
| void | manage_console (int peer_socket, struct sockaddr_in *peer, socklen_t *peer_len) |
Variables | |
| pthread_mutex_t | passwd_mutex = PTHREAD_MUTEX_INITIALIZER |
| pthread_mutex_t | group_mutex = PTHREAD_MUTEX_INITIALIZER |
| ccmd_t * | command_list |
Define Documentation
| #define INCLUDE_FLARE_INTERNALS |
| #define PROMPT "\nMAGMA:%s> " |
| #define sendline | ( | buffer | ) | send(peer_socket, buffer, strlen(buffer), 0) |
| #define TRANSFORM_PATH |
Value:
char *realpath;\ if (path == NULL || strlen(path) == 0 || strcmp(path, ".") == 0) {\ realpath = strdup(env->working_path);\ } else if (strcmp(path, "..") == 0) {\ realpath = strdup(env->working_path);\ char *slash = NULL;\ if ((slash = rindex(realpath, '/')) != NULL) *slash = '\0';\ if ((slash = rindex(realpath, '/')) != NULL) *slash = '\0';\ if (*realpath == '\0') *realpath = '/', *(realpath+1) = '\0';\ } else if (path[0] == '/') {\ realpath = strdup(path);\ } else {\ catpath(&realpath, env->working_path, path, NULL);\ }\ realpath = magma_simplify_path(realpath);
| #define xsendline | ( | pattern, | |||
| ... | ) |
Value:
{\
char *stbuf = malloc(512);\
if (stbuf != NULL) {\
snprintf(stbuf,512,pattern,## __VA_ARGS__);\
send(peer_socket, stbuf, strlen(stbuf), 0);\
free(stbuf);\
}\
}
Function Documentation
| ccmd_t* add_hook | ( | char * | pattern, | |
| void(*)(int, session_environment_t *, char *, regmatch_t *) | hook, | |||
| char * | help | |||
| ) |
add new command to available console commands. pattern is compiled and saved with funtion pointer and function help message in the linked list.
- Parameters:
-
pattern regular expression pattern of the command hook pointer to function code help explaining message of this command
- Returns:
- a pointer to added command, NULL if something failed
| void cache_load | ( | int | peer_socket, | |
| session_environment_t * | env, | |||
| char * | buffer, | |||
| regmatch_t * | matchptr | |||
| ) |
console command that prints actual cache load
| void console_cat | ( | int | peer_socket, | |
| session_environment_t * | env, | |||
| char * | buffer, | |||
| regmatch_t * | matchptr | |||
| ) |
console command that prints given flare contents
| void console_cd | ( | int | peer_socket, | |
| session_environment_t * | env, | |||
| char * | buffer, | |||
| regmatch_t * | matchptr | |||
| ) |
console command that changes current working path
| void console_ls | ( | int | peer_socket, | |
| session_environment_t * | env, | |||
| char * | buffer, | |||
| regmatch_t * | matchptr | |||
| ) |
console command that lists given directory flare contents
| void console_pwd | ( | int | peer_socket, | |
| session_environment_t * | env, | |||
| char * | buffer, | |||
| regmatch_t * | matchptr | |||
| ) |
console command that prints current working path
| void dump_cache | ( | int | peer_socket, | |
| session_environment_t * | env, | |||
| char * | buffer, | |||
| regmatch_t * | matchptr | |||
| ) |
console command that print flare system cache contents as an XML document
| void erase_flare | ( | int | peer_socket, | |
| session_environment_t * | env, | |||
| char * | buffer, | |||
| regmatch_t * | matchptr | |||
| ) |
console command that erases a flare
| void init_console | ( | ) |
register console commands. called by flare_system_init().
| void inspect | ( | int | peer_socket, | |
| session_environment_t * | env, | |||
| char * | buffer, | |||
| regmatch_t * | matchptr | |||
| ) |
console command that shows information about given flare
| void manage_console | ( | int | peer_socket, | |
| struct sockaddr_in * | peer, | |||
| socklen_t * | peer_len | |||
| ) |
manage an incoming console connection.
- Parameters:
-
peer_socket network socket peer remote peer IP address peer_len size of *peer structure
| void match_query | ( | char * | buffer, | |
| int | peer_socket, | |||
| session_environment_t * | env | |||
| ) |
check a console command line on command list using regular expressions. if a match is found, related function is executed.
- Parameters:
-
buffer pointer to command line string peer_socket remote network socket to send data to env pointer to current session
| void print_cache | ( | int | peer_socket, | |
| session_environment_t * | env, | |||
| char * | buffer, | |||
| regmatch_t * | matchptr | |||
| ) |
console command that prints flare system cache contents ad a formatted tree
| void print_help | ( | int | peer_socket, | |
| session_environment_t * | env, | |||
| char * | buffer, | |||
| regmatch_t * | matchptr | |||
| ) |
console command that shows all available commands
| void print_lava | ( | int | peer_socket, | |
| session_environment_t * | env, | |||
| char * | buffer, | |||
| regmatch_t * | matchptr | |||
| ) |
console command that print lava topology
| void send_cache_node | ( | int | peer_socket, | |
| session_environment_t * | env, | |||
| magma_flare_t * | node, | |||
| char * | prefix | |||
| ) |
internally used by print_cache()
| void send_ls_entry | ( | int | peer_socket, | |
| char * | realpath, | |||
| char * | de | |||
| ) |
internally used by console_ls()
| void server_shutdown | ( | int | peer_socket, | |
| session_environment_t * | env, | |||
| char * | buffer, | |||
| regmatch_t * | matchptr | |||
| ) |
console command that issues node shutdown
| char* strcast | ( | magma_flare_t * | flare | ) |
fill a text buffer with the cast kind of given flare
- Parameters:
-
flare given flare
- Returns:
- pointer to cast string. result is dynamically allocated and should be freed by outside code.
| void traverse_cache | ( | int | peer_socket, | |
| magma_flare_t * | flare, | |||
| unsigned int | indent | |||
| ) |
internally used by print_cache()
Variable Documentation
| ccmd_t* command_list |
linked list of all registered commands
| pthread_mutex_t group_mutex = PTHREAD_MUTEX_INITIALIZER |
mutex protecting usage of getgrent()
| pthread_mutex_t passwd_mutex = PTHREAD_MUTEX_INITIALIZER |
mutex protecting usage of getpwent()