Some kind of shell is now there in act

shell
7u83 6 months ago
parent 2316a1125f
commit 50d11c0c62
  1. 4
      src/ac/Makefile
  2. 2
      src/ac/ac.h
  3. 6
      src/ac/ac_main.c
  4. 396
      src/ac/act.c
  5. 7
      src/ac/config.ckv
  6. 316
      src/ac/rpc.c
  7. 14
      src/cw/cfg.c
  8. 1
      src/cw/cfg.h

@ -29,7 +29,7 @@ LIBS+=-ledit
INCL_DIRS=-I../ -I/usr/local/include -I./ -I../../include
#FLAGS=-DWITH_IPV6 -DWITH_OPENSSL -DSYS_ARCH="$(ARCH)" -DSYS_ARCH="XXX"
FLAGS=-DWITH_IPV6 -DUSE_OPENSSL -DSYS_ARCH='"$(ARCH)"'
FLAGS=-DWITH_IPV6 -DUSE_OPENSSL -DSYS_ARCH='"$(KERNEL)/$(ARCH)"'
@ -44,7 +44,7 @@ $(PRG): $(OBJS)
$(CC) $(OBJS) -o $(PRG) $(LIBPATH) $(LDFLAGS) $(LIBS)
$(ACTPRG): $(ACTOBJS)
$(CC) $(ACTOBJS) -o $(ACTPRG) $(LIBPATH) $(LDFLAGS) -ledit $(LIBS)
$(CC) $(ACTOBJS) -o $(ACTPRG) $(LIBPATH) $(LDFLAGS) -ledit -lcw -lcrypto -lssl -lmavl -lnettle

@ -17,7 +17,7 @@ enum {
AC_PROTO_UNKNOWN
};
int start_shell(cw_Cfg_t *global_cfg);
int start_rpc(cw_Cfg_t *global_cfg);
int test_shell();

@ -92,7 +92,7 @@ static int parse_args (int argc, char *argv[], struct bootcfg * bootcfg)
bootcfg->cfgfilename = "config.ckv";
while ( (c = getopt (argc, argv, "vc:d:p:")) != -1) {
while ( (c = getopt (argc, argv, "hvc:d:p:")) != -1) {
switch (c) {
case 'c':
@ -225,8 +225,6 @@ int main (int argc, char *argv[])
goto errX;
};
test_shell();
cw_log_name = "AC-Tube";
/*
@ -279,7 +277,7 @@ test_shell();
ac_conf_init(global_cfg);
if (!start_shell(global_cfg))
if (!start_rpc(global_cfg))
goto errX;

@ -0,0 +1,396 @@
/* $NetBSD: tc1.c,v 1.7 2016/02/17 19:47:49 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Christos Zoulas of Cornell University.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* test.c: A little test program
*/
#include <sys/wait.h>
#include <ctype.h>
#include <dirent.h>
#include <locale.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>
#include "histedit.h"
#include "cw/cfg.h"
#include "cw/sock.h"
static int continuation = 0;
volatile sig_atomic_t gotsig = 0;
static unsigned char complete(EditLine *, int);
static char *prompt(EditLine *);
static void sig(int);
FILE * act_f;
static int
get_result(FILE *f, char *str,int len)
{
int n = len;
char *rc;
rc = fgets (str, len, f);
if (rc==NULL)
return 0;
n = strlen(str);
if (n==1 && str[0]=='\n')
return 0;
return 1;
}
static char *
prompt(EditLine *el )
{
static char str[64];
char str2[64];
int rc;
fprintf(act_f,"@prompt\n");
rc = get_result(act_f,str,64);
while(rc){
rc=get_result(act_f,str2,64);
}
static char a[] = "\1\033[7m\1Edit$\1\033[0m\1 ";
static char b[] = "> ";
return (continuation ? b : str);
}
static void
sig(int i)
{
gotsig = i;
}
static unsigned char
complete(EditLine *el, int ch __attribute__((__unused__)))
{
DIR *dd = opendir(".");
struct dirent *dp;
const char* ptr;
const LineInfo *lf = el_line(el);
size_t len;
int res = CC_ERROR;
/*
* Find the last word
*/
for (ptr = lf->cursor - 1;
!isspace((unsigned char)*ptr) && ptr > lf->buffer; ptr--)
continue;
len = lf->cursor - ++ptr;
for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) {
if (len > strlen(dp->d_name))
continue;
if (strncmp(dp->d_name, ptr, len) == 0) {
if (el_insertstr(el, &dp->d_name[len]) == -1)
res = CC_ERROR;
else
res = CC_REFRESH;
break;
}
}
closedir(dd);
return res;
}
const char *cfgfilename = "config.ckv";
const char *srvaddr;
const char *prgname;
static int
parse_args (int argc, char *argv[])
{
int c;
opterr = 1;
while ( (c = getopt (argc, argv, "hvc:s:")) != -1) {
switch (c) {
case 'c':
cfgfilename = optarg;
break;
case 'v':
printf("ACT shell for ACTube version 0.0.1, %s\n", SYS_ARCH);
exit(EXIT_SUCCESS);
break;
case 's':
srvaddr = optarg;
break;
/* case 'd':{
if (!cw_dbg_set_level_from_str(optarg)){
fprintf(stderr,"Invalid debug option: %s\n",optarg);
exit(EXIT_FAILURE);
}
break;
} */
case '?':
exit(EXIT_FAILURE);
default:
case 'h':
printf("Usage:\n");
printf("%s [-v | -h | -s <dst> | -c <cfg> ]\n",argv[0]);
printf(" -c: specify config file\n");
printf(" -s: specify adress to connect to \n");
printf(" -v: print version info\n");
exit(EXIT_SUCCESS);
break;
}
}
return 0;
}
int create_tcp_fd(const char *addr)
{
struct sockaddr server;
int rc;
int sockfd;
memset(&server,0,sizeof(server));
rc = sock_strtoaddr (addr, (struct sockaddr*) &server);
if (! rc) {
fprintf(stderr, "Can't parse address '%s', %s\n", addr, strerror (errno));
return -1;
}
sockfd = socket ( ( (struct sockaddr*) &server)->sa_family, SOCK_STREAM, 0);
rc = connect(sockfd, (struct sockaddr*)&server, sizeof(server));
if (rc ) {
fprintf(stderr,"%s: Error, can't connt to %s %s\n",prgname,addr,strerror(errno));
return -1;
}
return sockfd;
}
static FILE *act_connect(const char *srvaddr)
{
int fd;
if (srvaddr==NULL){
fprintf(stderr,"%s: Error, no address given.\n",prgname);
return NULL;
}
fd=create_tcp_fd(srvaddr);
if (fd==-1)
return NULL;
return fdopen(fd,"a+");
// return NULL;
}
int
main(int argc , char *argv[])
{
prgname = argv[0];
parse_args(argc,argv);
act_f = act_connect(srvaddr);
if (act_f==NULL){
return (EXIT_FAILURE);
}
EditLine *el = NULL;
int num;
const char *buf;
Tokenizer *tok;
#if 0
int lastevent = 0;
#endif
int ncontinuation;
History *hist;
HistEvent ev;
(void) setlocale(LC_CTYPE, "");
(void) signal(SIGINT, sig);
(void) signal(SIGQUIT, sig);
(void) signal(SIGHUP, sig);
(void) signal(SIGTERM, sig);
hist = history_init(); /* Init the builtin history */
/* Remember 100 events */
history(hist, &ev, H_SETSIZE, 100);
tok = tok_init(NULL); /* Initialize the tokenizer */
/* Initialize editline */
el = el_init(*argv, stdin, stdout, stderr);
el_set(el, EL_EDITOR, "emacs"); /* Default editor is vi */
el_set(el, EL_SIGNAL, 0); /* Handle signals gracefully */
el_set(el, EL_PROMPT_ESC, prompt, '\1');/* Set the prompt function */
/* Tell editline to use this history interface */
el_set(el, EL_HIST, history, hist);
/* Add a user-defined function */
el_set(el, EL_ADDFN, "ed-complete", "Complete argument", complete);
/* Bind tab to it */
el_set(el, EL_BIND, "^I", "ed-complete", NULL);
/*
* Bind j, k in vi command mode to previous and next line, instead
* of previous and next history.
*/
el_set(el, EL_BIND, "-a", "k", "ed-prev-line", NULL);
el_set(el, EL_BIND, "-a", "j", "ed-next-line", NULL);
/*
* Source the user's defaults file.
*/
el_source(el, NULL);
while ((buf = el_gets(el, &num)) != NULL && num != 0) {
int ac, cc, co;
const char **av;
const LineInfo *li;
li = el_line(el);
if (gotsig) {
(void) fprintf(stderr, "Got signal %d.\n", (int)gotsig);
gotsig = 0;
el_reset(el);
}
if (!continuation && num == 1)
continue;
ac = cc = co = 0;
ncontinuation = tok_line(tok, li, &ac, &av, &cc, &co);
if (ncontinuation < 0) {
(void) fprintf(stderr, "Internal error\n");
continuation = 0;
continue;
}
/* Simpler */
history(hist, &ev, continuation ? H_APPEND : H_ENTER, buf);
continuation = ncontinuation;
ncontinuation = 0;
if (continuation)
continue;
if (strcmp(av[0], "history") == 0) {
int rv;
switch (ac) {
case 1:
for (rv = history(hist, &ev, H_LAST); rv != -1;
rv = history(hist, &ev, H_PREV))
(void) fprintf(stdout, "%4d %s",
ev.num, ev.str);
break;
case 2:
if (strcmp(av[1], "clear") == 0)
history(hist, &ev, H_CLEAR);
else
goto badhist;
break;
case 3:
if (strcmp(av[1], "load") == 0)
history(hist, &ev, H_LOAD, av[2]);
else if (strcmp(av[1], "save") == 0)
history(hist, &ev, H_SAVE, av[2]);
break;
badhist:
default:
(void) fprintf(stderr,
"Bad history arguments\n");
break;
}
} else if (el_parse(el, ac, av) == -1) {
char str[2000];
str[0]=0;
fprintf(act_f,"%s\n",av[0]);
fflush(act_f);
do {
int n;
fgets (str, 2000, act_f);
n = strlen(str);
// printf("LEN: %d\n",n);
if (n==1 && str[0]=='\n')
break;
fprintf(stdout,"%s",str);
}while(!feof(act_f));
fflush(stdout);
}
tok_reset(tok);
}
el_end(el);
tok_end(tok);
history_end(hist);
return (0);
}

@ -40,10 +40,9 @@ actube/ipv6: false
actube/mod.1: capwap
actube/mod.2: capwap80211
actube/shell/listen: unix:/tmp/actube
#actube/shell/listen: tcp:127.0.0.1:5000
actube/shell/enable: true
actube/shell/term: ansi
#actube/rpc/listen: unix:/tmp/actube
actube/rpc/listen: tcp:127.0.0.1:5000
actube/rpc/enable: true
ac-descriptor/dtls-policy: 1

@ -25,14 +25,14 @@
#include "ac.h"
struct shelldata{
struct rpcdata{
FILE *in;
FILE *out;
FILE *eout;
char prompt[1024];
cw_Cfg_t * update_cfg;
cw_Cfg_t * global_cfg;
char *history[2000];
char line[4096];
int pos;
@ -45,7 +45,6 @@ struct shelldata{
Tokenizer *tok;
EditLine *el;
FILE * file;
};
struct sockdata{
@ -54,27 +53,32 @@ struct sockdata{
cw_Cfg_t * global_cfg;
};
void select_cmd(struct shelldata *sd, const char *cmd);
void list_cmd(struct shelldata *sd, const char * cmd);
void cfg_cmd(struct shelldata *sd, const char * cmd);
void ucfg_cmd(struct shelldata *sd, const char * cmd);
void set_cmd(struct shelldata *sd, const char * cmd);
void del_cmd(struct shelldata *sd, const char * cmd);
void send_cmd(struct shelldata *sd, const char * cmd);
void wlan0_cmd(struct shelldata *sd, const char * cmd);
void exit_cmd(struct shelldata *sd, const char * cmd);
int select_cmd(struct rpcdata *sd, const char *cmd);
int list_cmd(struct rpcdata *sd, const char * cmd);
int cfg_cmd(struct rpcdata *sd, const char * cmd);
int ucfg_cmd(struct rpcdata *sd, const char * cmd);
int set_cmd(struct rpcdata *sd, const char * cmd);
int del_cmd(struct rpcdata *sd, const char * cmd);
int send_cmd(struct rpcdata *sd, const char * cmd);
int wlan0_cmd(struct rpcdata *sd, const char * cmd);
int exit_cmd(struct rpcdata *sd, const char * cmd);
int prompt_cmd(struct rpcdata *sd, const char * cmd);
int global_cfg_cmd(struct rpcdata *sd, const char * cmd);
//void show_cfg (FILE *out, mavl_t ktv);
void show_aps (FILE *out);
int show_aps (FILE *out);
struct cw_Conn * find_ap(const char *name);
struct command{
char * cmd;
void (*fun)();
int (*fun)(struct rpcdata *sd, const char *cmd);
};
static struct command cmdlist[]={
{"exit",exit_cmd},
{"bumm",exit_cmd},
{"cfg", cfg_cmd },
{"del", del_cmd },
{"ucfg", ucfg_cmd},
@ -83,32 +87,63 @@ static struct command cmdlist[]={
{"send", send_cmd},
{"set", set_cmd },
{"wlan0",wlan0_cmd},
{"global_cfg", global_cfg_cmd},
{"@prompt",prompt_cmd},
{NULL,NULL}
};
void select_cmd(struct shelldata *sd, const char *cmd)
static void finish_cmd(FILE *f)
{
fprintf(f,"\n");
fflush(f);
}
int prompt_cmd(struct rpcdata *sd, const char *cmd)
{
fprintf(sd->out,"actube[%s]:>\n","*");
finish_cmd(sd->out);
return 0;
}
int global_cfg_cmd(struct rpcdata *sd, const char *cmd)
{
cw_cfg_fdump(sd->out,sd->global_cfg);
finish_cmd(sd->out);
return 0;
}
int select_cmd(struct rpcdata *sd, const char *cmd)
{
char ap [CAPWAP_MAX_WTP_NAME_LEN];
sscanf(cmd,"%s",ap);
strcpy(sd->prompt,ap);
}
void list_cmd(struct shelldata *sd, const char *cmd)
int list_cmd(struct rpcdata *sd, const char *cmd)
{
show_aps(sd->out);
return 0;
}
void exit_cmd(struct shelldata *sd, const char *cmd)
int exit_cmd(struct rpcdata *sd, const char *cmd)
{
sd->quit=1;
//fprintf(sd->out,"Unknown command: '%s'\n\r\n\r",cmd);
printf("Exitcmd %s\n",cmd);
fprintf(sd->out,"END: %s\n\r",cmd);
fflush(sd->out);
return 1;
}
void cfg_cmd(struct shelldata *sd, const char *cmd)
int cfg_cmd(struct rpcdata *sd, const char *cmd)
{
struct cw_Conn * conn;
wtplist_lock();
@ -121,21 +156,23 @@ void cfg_cmd(struct shelldata *sd, const char *cmd)
// show_cfg(sd->out,conn->remote_cfg);
}
wtplist_unlock();
return 0;
}
void ucfg_cmd(struct shelldata *sd, const char *cmd)
int ucfg_cmd(struct rpcdata *sd, const char *cmd)
{
// struct cw_Conn * conn;
stop();
// show_cfg(sd->out,sd->update_cfg);
return 0;
}
#include "wtpman.h"
void
send_cmd(struct shelldata * sd, const char *cmd)
int
send_cmd(struct rpcdata * sd, const char *cmd)
{
struct cw_Conn * conn;
wtplist_lock();
conn = find_ap(sd->prompt);
@ -146,10 +183,11 @@ send_cmd(struct shelldata * sd, const char *cmd)
conn->update_cfg=sd->update_cfg;
}
wtplist_unlock();
return 0;
}
void
wlan0_cmd(struct shelldata * sd, const char *cmd)
int
wlan0_cmd(struct rpcdata * sd, const char *cmd)
{
stop();
@ -166,10 +204,10 @@ wlan0_cmd(struct shelldata * sd, const char *cmd)
fclose(f);
}
wtplist_unlock();
return 0;
}
void set_cmd(struct shelldata *sd, const char *str)
int set_cmd(struct rpcdata *sd, const char *str)
{
/* struct cw_Conn * conn;
struct cw_Val_Reader r;
@ -186,14 +224,17 @@ void set_cmd(struct shelldata *sd, const char *str)
// fprintf(sd->out,"%s :%s: %s\n",key,type,val);
// cw_ktv_add(sd->update_cfg,key,CW_TYPE_STR,NULL,val,strlen(val));
return 0;
}
void del_cmd(struct shelldata *sd, const char *str)
int del_cmd(struct rpcdata *sd, const char *str)
{
char key[CW_CFG_MAX_KEY_LEN];
sscanf(str,"%s",key);
stop();
// cw_ktv_del_sub(sd->update_cfg,key);
//
return 0;
}
@ -221,7 +262,7 @@ void show_cfg (FILE *out, mavl_t ktv)
}
*/
void show_aps (FILE *out)
int show_aps (FILE *out)
{
stop();
/* struct connlist * cl;
@ -257,6 +298,7 @@ void show_aps (FILE *out)
}
wtplist_unlock();
*/
return 0;
}
@ -371,7 +413,7 @@ struct command * find_cmd(const char *cmd)
}
void execute_cmd (struct shelldata * sd, const char *str)
int execute_cmd (struct rpcdata * sd, const char *str)
{
char cmd[1024];
char args[1024];
@ -383,21 +425,21 @@ void execute_cmd (struct shelldata * sd, const char *str)
n = sscanf (str, "%s", cmd);
if (n<=0)
return;
return 0;
searchcmd = find_cmd(cmd);
if (searchcmd!=NULL){
if (searchcmd->fun != NULL){
fprintf(sd->out,"%s %s\n", searchcmd->cmd,str+strlen(cmd));
searchcmd->fun(sd, str+strlen(cmd));
return searchcmd->fun(sd, str+strlen(cmd));
}
}
else{
fprintf(sd->out,"Unknown command: '%s'\n\r",cmd);
printf("unknow command\n");
fprintf(sd->out,"Unknown command: '%s'\n",cmd);
finish_cmd(sd->out);
}
return;
return 0;
char key[CW_CFG_MAX_KEY_LEN];
@ -425,25 +467,26 @@ void execute_cmd (struct shelldata * sd, const char *str)
else{
fprintf(sd->out,"%s :%s: %s\n", key,type,val);
}
return;
return 0;
n = sscanf (str, "%s%s", cmd, args);
if (n<=0)
return;
return 0;
/*printf("CMD: %s, ARGS:\n",cmd);*/
if (strcmp (cmd, "s") == 0) {
show_aps (sd->out);
return;
return 0;
}
if (strcmp (cmd, "con")==0){
con(sd->out);
return;
return 0;
}
return 0;
}
struct esc_strings {
@ -486,20 +529,9 @@ static int cmpansi(char * str,char * ansistr)
static char *
prompt(EditLine *el )
{
static char a[] = "\1\033[7m\1Edit$\1\033[0m\1 ";
static char b[] = "Edit> ";
return b;
// return (continuation ? b : a);
}
static void get_line_char_mode(FILE * file, struct shelldata *sd)
static void get_line_char_mode(FILE * file, struct rpcdata *sd)
{
int c;
struct esc_strings * es;
@ -617,170 +649,40 @@ static void get_line_char_mode(FILE * file, struct shelldata *sd)
}
void init_edline(struct shelldata *sd)
void rpc_loop (FILE *file, cw_Cfg_t *global_cfg)
{
sd->hist = history_init(); /* Init the builtin history */
history(sd->hist, &sd->ev, H_SETSIZE, 100); /* Remember 100 events */
sd->tok = tok_init(NULL); /* Initialize the tokenizer */
sd->el = el_init("actube", sd->in, sd->out, sd->eout);
el_set(sd->el, EL_EDITOR, "emacs"); /* Default editor is vi */
el_set(sd->el, EL_HIST, history, sd->hist);
// el_set(sd->el, EL_UNBUFFERED, 1);
}
void get_edline(struct shelldata * sd)
{
int num;
int ncontinuation;
int continuation=0;
const char *buf;
while ((buf = el_gets(sd->el, &num)) != NULL && num != 0) {
int ac, cc, co;
const char **av;
const LineInfo *li;
li = el_line(sd->el);
/* if (gotsig) {
(void) fprintf(stderr, "Got signal %d.\n", (int)gotsig);
gotsig = 0;
el_reset(el);
}
*/
if (!continuation && num == 1)
continue;
ac = cc = co = 0;
ncontinuation = tok_line(sd->tok, li, &ac, &av, &cc, &co);
if (ncontinuation < 0) {
(void) fprintf(stderr, "Internal error\n");
continuation = 0;
continue;
}
/* Simpler */
history(sd->hist, &sd->ev, continuation ? H_APPEND : H_ENTER, buf);
continuation = ncontinuation;
ncontinuation = 0;
if (continuation)
continue;
/* if (strcmp(av[0], "history") == 0) {
int rv;
switch (ac) {
case 1:
for (rv = history(hist, &ev, H_LAST); rv != -1;
rv = history(hist, &ev, H_PREV))
(void) fprintf(stdout, "%4d %s",
ev.num, ev.str);
break;
case 2:
if (strcmp(av[1], "clear") == 0)
history(hist, &ev, H_CLEAR);
else
goto badhist;
break;
case 3:
if (strcmp(av[1], "load") == 0)
history(hist, &ev, H_LOAD, av[2]);
else if (strcmp(av[1], "save") == 0)
history(hist, &ev, H_SAVE, av[2]);
break;
badhist:
default:
(void) fprintf(stderr,
"Bad history arguments\n");
break;
}
} else */
if (el_parse(sd->el, ac, av) == -1) {
switch (fork()) {
case 0:
// printf("AV: %s\n",av[0]);
// execvp(av[0], (char *const *)__UNCONST(av));
// perror(av[0]);
// stop();
// _exit(1);
/*NOTREACHED*/
break;
case -1:
perror("fork");
break;
default:
if (wait(&num) == -1)
perror("wait");
(void) fprintf(stderr, "Exit %x\n", num);
break;
}
}
tok_reset(sd->tok);
}
}
void shell_loop (FILE *file)
{
struct shelldata sd;
struct rpcdata sd;
int c;
c=0;
/* setvbuf(file,NULL,_IONBF,0);
fflush(file);
*/
char str[2048];
sd.file = file;
sd.out = stdout;
sd.eout = stderr;
sd.in=stdin;
sd.in = file;
sd.out = file;
sd.global_cfg=global_cfg;
sprintf(sd.prompt,"%s","*");
sd.quit=0;
/* fprintf (file,"%c%c%c",IAC,WILL,TELOPT_ECHO );
fprintf (file,"%c%c%c",IAC,WILL,TELOPT_SGA );
fprintf (file,"%c%c%c",IAC,DONT,TELOPT_LINEMODE );
fflush(file);
*/
init_edline(&sd);
do {
int c;
get_edline(&sd);
// get_line_char_mode(file,&sd);
printf("THE CMD FROM LINE '%s'\n",sd.line);
str[0]=0;
// c=fgetc(file);
//printf("%c\n",c);
// fgets (str, sizeof (str), file);
// printf("My String: %s\n",str);
fgets (str, sizeof (str), file);
// execute_cmd (&sd, sd.line);
// if (sd.quit)
// break;
if (execute_cmd (&sd, str)) {
break;
}
} while (c != EOF);
}
void * run_shell (void * arg)
void * run_rpc_server (void * arg)
{
char sockstr[SOCK_ADDR_BUFSIZE];
struct sockdata * sockdata;
@ -793,7 +695,7 @@ void * run_shell (void * arg)
memset(&client,0,sizeof(client));
client_size=sizeof(client);
cw_dbg(DBG_INFO,"Starting shell, listening on: %s (sock fd: %d)",sockdata->name, sockdata->fd);
cw_dbg(DBG_INFO,"Starting RPC Service, listening on: %s (sock fd: %d)",sockdata->name, sockdata->fd);
while(1){
clientsock = accept (sockdata->fd, (struct sockaddr*) &client, &client_size);
@ -805,10 +707,8 @@ void * run_shell (void * arg)
if (clientsock > 0) {
sock_addr2str_p (&client, sockstr);
cw_dbg (DBG_INFO, "Acceptiong session from %s", sockstr);
cw_dbg (DBG_INFO, "Start shell");
shell_loop (fdopen (clientsock, "a+"));
cw_dbg (DBG_INFO, "Stop shell");
cw_dbg (DBG_INFO, "Accepting RPC session from %s", sockstr);
rpc_loop (fdopen (clientsock, "a+"),sockdata->global_cfg);
close (clientsock);
}
@ -876,20 +776,14 @@ static int create_unix_fd(const char *name)
return fd;
}
test_shell()
{
shell_loop(NULL);
return 0;
}
int start_shell(cw_Cfg_t *global_cfg)
int start_rpc(cw_Cfg_t *global_cfg)
{
struct sockdata * sockdata;
const char *sockname;
int rc, type;
int fd;
rc = cw_cfg_get_bool(global_cfg,"actube/shell/enable",1);
rc = cw_cfg_get_bool(global_cfg,"actube/rpc/enable",1);
if (!rc)
return 1;
@ -902,10 +796,10 @@ int start_shell(cw_Cfg_t *global_cfg)
sockdata->global_cfg = global_cfg;
sockdata->fd=-1;
sockname = cw_cfg_get(global_cfg,"actube/shell/listen",NULL);
sockname = cw_cfg_get(global_cfg,"actube/rpc/listen",NULL);
if (sockname==NULL) {
cw_log (LOG_ERR, "Can't get shell listen address from global_cfg 'actube/shell/listen");
cw_log (LOG_ERR, "Can't get RPC listen address from global_cfg 'actube/rpc/listen");
goto errX;
}
@ -937,7 +831,7 @@ int start_shell(cw_Cfg_t *global_cfg)
}
pthread_t thread;
pthread_create (&thread, NULL, run_shell,
pthread_create (&thread, NULL, run_rpc_server,
sockdata);
return 1;
errX:

@ -186,6 +186,20 @@ void cw_cfg_dump(cw_Cfg_t * cfg)
}
}
void cw_cfg_fdump(FILE *f, cw_Cfg_t * cfg)
{
mavliter_t it;
struct cw_Cfg_entry *e;
mavliter_init(&it, cfg->cfg);
mavliter_foreach(&it) {
e = mavliter_get(&it);
fprintf(f,"%s: '%s'\n", e->key, e->val);
}
}
struct parser {
int line;

@ -56,6 +56,7 @@ int cw_cfg_base_exists_l(cw_Cfg_t ** cfgs, const char *key);
int cw_cfg_save(const char *filename, cw_Cfg_t *cfg, const char *format, ...);
uint16_t cw_cfg_get_word_l(cw_Cfg_t ** cfg, char *key, uint16_t def);
void cw_cfg_fdump(FILE *f, cw_Cfg_t * cfg);

Loading…
Cancel
Save