File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / mpd / src / console.h
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Nov 1 09:56:12 2016 UTC (7 years, 8 months ago) by misho
Branches: mpd, MAIN
CVS tags: v5_8p1_cross, v5_8p1, v5_8, HEAD
mpd 5.8

    1: 
    2: /*
    3:  * console.h
    4:  *
    5:  * Written by Archie Cobbs <archie@freebsd.org>
    6:  * Copyright (c) 1998-1999 Whistle Communications, Inc. All rights reserved.
    7:  * See ``COPYRIGHT.whistle''
    8:  */
    9: 
   10: #ifndef _CONSOLE_H_
   11: #define	_CONSOLE_H_
   12: 
   13: #include "ppp.h"
   14: 
   15: /*
   16:  * DEFINITIONS
   17:  */
   18: 
   19:   #define MAX_CONSOLE_ARGS	50
   20:   #define MAX_CONSOLE_LINE	400
   21:   #define MAX_CONSOLE_HIST	10
   22: 
   23:   #define Printf(fmt, args...)	do { 						\
   24: 	  			  if (ctx->cs)	 				\
   25: 	  			    ctx->cs->write(ctx->cs, fmt, ## args);	\
   26:   				} while (0)
   27: 
   28:   #define Error(fmt, args...)	do { 						\
   29: 				  snprintf(ctx->errmsg, sizeof(ctx->errmsg),	\
   30: 				    fmt, ## args);				\
   31: 				  return(CMD_ERR_OTHER);			\
   32:   				} while (0)
   33: 
   34:   /* Global configuration options */
   35:   enum {
   36:     CONSOLE_AUTH	/* enable authentication */
   37:   };
   38: 
   39:   /* Configuration options */
   40:   enum {
   41:     CONSOLE_LOGGING	/* enable logging */
   42:   };
   43: 
   44:   struct console {
   45:     int			fd;		/* listener */
   46:     struct u_addr 	addr;
   47:     in_port_t		port;
   48:     SLIST_HEAD(, console_session) sessions;	/* active sessions */
   49:     EventRef		event;		/* connect-event */
   50:     pthread_rwlock_t	lock;
   51:     struct optinfo	options;	/* Configured options */
   52:   };
   53: 
   54:   typedef struct console *Console;
   55: 
   56:   struct console_session;
   57: 
   58:   typedef struct console_session *ConsoleSession;
   59: 
   60:   struct context {
   61: 	Bund		bund;
   62: 	Link		lnk;
   63: 	Rep		rep;
   64: 	ConsoleSession	cs;
   65: 	int		depth;		/* Number recursive 'load' calls */
   66: 	char		errmsg[256];	/* Error message of the last command */
   67: 	int		priv;
   68:   };
   69: 
   70:   struct console_user {
   71: 	char		username[32];
   72: 	char		password[32];
   73: 	int		priv;
   74:   };
   75: 
   76:   typedef struct console_user *ConsoleUser;
   77: 
   78:   struct console_session {
   79:     Console		console;
   80:     struct optinfo	options;	/* Configured options */
   81:     int			fd;		/* connection fd */
   82:     void		*cookie;	/* device dependent cookie */
   83:     EventRef		readEvent;
   84:     struct context	context;
   85:     struct console_user user;
   86:     struct u_addr	peer_addr;
   87:     in_port_t           peer_port;
   88:     void		(*prompt)(struct console_session *);
   89:     void		(*write)(struct console_session *, const char *fmt, ...);
   90:     void		(*writev)(struct console_session *, const char *fmt, va_list vl);
   91:     void		(*close)(struct console_session *);
   92:     u_char		state;
   93:     u_char		telnet;
   94:     u_char		escaped;
   95:     u_char		exit;
   96:     int			cmd_len;
   97:     char		cmd[MAX_CONSOLE_LINE];
   98:     int			currhist;
   99:     char		history[MAX_CONSOLE_HIST][MAX_CONSOLE_LINE];	/* last command */
  100:     SLIST_ENTRY(console_session)	next;
  101:   };
  102: 
  103: /*
  104:  * VARIABLES
  105:  */
  106: 
  107:   extern const struct cmdtab ConsoleSetCmds[];
  108:   extern struct ghash		*gUsers;		/* allowed users */
  109:   extern pthread_rwlock_t	gUsersLock;
  110: 
  111: 
  112: /*
  113:  * FUNCTIONS
  114:  */
  115: 
  116:   extern int	ConsoleInit(Console c);
  117:   extern int	ConsoleOpen(Console c);
  118:   extern int	ConsoleClose(Console c);
  119:   extern int	ConsoleStat(Context ctx, int ac, char *av[], void *arg);
  120:   extern Context	StdConsoleConnect(Console c);
  121:   extern void	ConsoleShutdown(Console c);
  122: 
  123:   extern int	UserCommand(Context ctx, int ac, char *av[], void *arg);
  124:   extern int	UserStat(Context ctx, int ac, char *av[], void *arg);
  125: 
  126: #endif
  127: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>