From 8ec8e8a051c57230443e97279b274fcb620e9540 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 29 Dec 2019 15:50:32 +0100 Subject: [WIP] prometheus module (with prometheus_vty) --- include/osmocom/vty/prometheus.h | 135 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 include/osmocom/vty/prometheus.h (limited to 'include/osmocom/vty/prometheus.h') diff --git a/include/osmocom/vty/prometheus.h b/include/osmocom/vty/prometheus.h new file mode 100644 index 00000000..2a09a127 --- /dev/null +++ b/include/osmocom/vty/prometheus.h @@ -0,0 +1,135 @@ +#include + + +/*! A telnet connection */ +struct prom_connection { + /*! linked list header for internal management */ + struct llist_head entry; + /*! private data pointer passed through */ + void *priv; + /*! filedsecriptor (socket ) */ + struct osmo_fd fd; + /*! VTY instance associated with telnet connection */ + struct prom_vty *vty; + /*! logging target associated with this telnet connection */ + struct log_target *dbg; +}; + + +int osmo_prom_init(void *ctx, int port); + +int osmo_prom_init_dynif(void *ctx, const char *host, int port); + +#define PROM_HTTP_BUFSIZ 512 + +//#define PROM_VTY_BUFSIZ 512 + +// TODO kill PROM_VTY_MAXHIST +#define PROM_VTY_MAXHIST 0 + +// +//enum event { +// PROM_VTY_SERV, +// PROM_VTY_READ, +// PROM_VTY_WRITE, +// PROM_VTY_CLOSED, +// PROM_VTY_TIMEOUT_RESET, +//}; + +/*! Internal representation of a single VTY */ +struct prom_vty { + /*! underlying file (if any) */ + FILE *file; + + /*! private data, specified by creator */ + void *priv; + + /*! File descripter of this vty. */ + int fd; + + /*! Is this vty connect to file or not */ + //enum prom_vty_type type; + + /*! Node status of this vty */ + int node; + + /*! Failure count */ + int fail; + + /*! Output buffer. */ + struct buffer *obuf; + + /*! Command input buffer */ + char *buf; + + /*! Command cursor point */ + int cp; + + /*! Command length */ + int length; + + /*! Command max length. */ + int max; + + /*! Histry of command */ + char *hist[PROM_VTY_MAXHIST]; + + /*! History lookup current point */ + int hp; + + /*! History insert end point */ + int hindex; + + /*! For current referencing point of interface, route-map, + access-list etc... */ + void *index; + + /*! For multiple level index treatment such as key chain and key. */ + void *index_sub; + + /*! For escape character. */ + unsigned char escape; + + /*! Current vty status. */ + enum { PROM_VTY_NORMAL, PROM_VTY_CLOSE, PROM_VTY_MORE, PROM_VTY_MORELINE } status; + + /*! IAC handling + * + * IAC handling: was the last character received the IAC + * (interpret-as-command) escape character (and therefore the next + * character will be the command code)? Refer to Telnet RFC 854. */ + unsigned char iac; + + /*! IAC SB (option subnegotiation) handling */ + unsigned char iac_sb_in_progress; + /* At the moment, we care only about the NAWS (window size) negotiation, + * and that requires just a 5-character buffer (RFC 1073): + * <16-bit width> <16-bit height> */ +#define TELNET_NAWS_SB_LEN 5 + /*! sub-negotiation buffer */ + unsigned char sb_buf[TELNET_NAWS_SB_LEN]; + /*! How many subnegotiation characters have we received? + * + * We just drop those that do not fit in the buffer. */ + size_t sb_len; + + /*! Window width */ + int width; + /*! Widnow height */ + int height; + + /*! Configure lines. */ + int lines; + + int monitor; + + /*! In configure mode. */ + int config; + + /*! List of parent nodes, last item is the outermost parent. */ + struct llist_head parent_nodes; + + /*! When reading from a config file, these are the indenting characters expected for children of + * the current VTY node. */ + char *indent; +}; -- cgit v1.2.3