summaryrefslogtreecommitdiffstats
path: root/include/osmocom/vty/prometheus.h
blob: 2a09a12732681a0d827b3e4e5c298a6e2e84b0e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <osmocom/core/select.h>


/*! 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):
	 * <NAWS char> <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;
};