Skip to content

Commit 96c7e7f

Browse files
committed
Add documentation from the old sites page
1 parent 6954851 commit 96c7e7f

5 files changed

Lines changed: 315 additions & 80 deletions

File tree

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,111 @@
1-
libcli
1+
Libcli provides a shared C library for including a Cisco-like command-line
2+
interface into other software.
23

3-
libcli emulates a cisco style telnet command-line interface.
4+
It’s a telnet interface which supports command-line editing, history,
5+
authentication and callbacks for a user-definable function tree.
46

57
To compile:
68

7-
make
8-
make install
9+
```sh
10+
$ make
11+
$ make install
12+
```
913

10-
This will install libcli.so into /usr/local/lib. If you want to change
11-
the location, edit Makefile.
14+
This will install `libcli.so` into `/usr/local/lib`. If you want to change the
15+
location, edit Makefile.
1216

13-
There is a test application built called clitest. Run this and telnet
14-
to port 8000.
17+
There is a test application built called clitest. Run this and telnet to port
18+
8000.
1519

1620
By default, a single username and password combination is enabled.
1721

22+
```
1823
Username: fred
1924
Password: nerk
25+
```
2026

21-
Get help by entering "help" or hitting ?.
27+
Get help by entering `help` or hitting `?`.
2228

2329
libcli provides support for using the arrow keys for command-line editing. Up
2430
and Down arrows will cycle through the command history, and Left & Right can be
2531
used for editing the current command line.
32+
2633
libcli also works out the shortest way of entering a command, so if you have a
27-
command "show users grep foobar" defined, you can enter "sh us g foobar" if that
34+
command `show users | grep foobar` defined, you can enter `sh us | g foobar` if that
2835
is the shortest possible way of doing it.
2936

30-
Enter "sh?" at the command line to get a list of commands starting with "sh"
37+
Enter `sh?` at the command line to get a list of commands starting with `sh`
3138

3239
A few commands are defined in every libcli program:
33-
help
34-
quit
35-
exit
36-
logout
37-
history
38-
39-
4040

41+
* `help`
42+
* `quit`
43+
* `exit`
44+
* `logout`
45+
* `history`
4146

4247
Use in your own code:
4348

44-
First of all, make sure you #include <libcli.h> in your C code, and link
45-
with -lcli.
49+
First of all, make sure you `#include <libcli.h>` in your C code, and link with
50+
`-lcli`.
4651

4752
If you have any trouble with this, have a look at clitest.c for a
4853
demonstration.
4954

50-
Start your program off with a cli_init().
55+
Start your program off with a `cli_init()`.
5156
This sets up the internal data structures required.
5257

5358
When a user connects, they are presented with a greeting if one is set using the
54-
cli_set_banner(banner) function.
55-
59+
`cli_set_banner(banner)` function.
5660

5761
By default, the command-line session is not authenticated, which means users
5862
will get full access as soon as they connect. As this may not be always the best
5963
thing, 2 methods of authentication are available.
6064

6165
First, you can add username / password combinations with the
62-
cli_allow_user(username, password) function. When a user connects, they can
66+
`cli_allow_user(username, password)` function. When a user connects, they can
6367
connect with any of these username / password combinations.
6468

65-
Secondly, you can add a callback using the cli_set_auth_callback(callback)
66-
function. This function is passed the username and password as char *, and must
67-
return CLI_OK if the user is to have access and CLI_ERROR if they are not.
69+
Secondly, you can add a callback using the `cli_set_auth_callback(callback)`
70+
function. This function is passed the username and password as `char *`, and must
71+
return `CLI_OK` if the user is to have access and `CLI_ERROR` if they are not.
6872

6973
The library itself will take care of prompting the user for credentials.
7074

71-
72-
73-
7475
Commands are built using a tree-like structure. You define commands with the
75-
cli_register_command(parent, command, callback, privilege, mode, help) function.
76+
`cli_register_command(parent, command, callback, privilege, mode, help)` function.
7677

77-
parent is a cli_command * reference to a previously added command. Using a
78+
`parent` is a `cli_command *` reference to a previously added command. Using a
7879
parent you can build up complex commands.
79-
e.g. to provide commands "show users", "show sessions" and "show people", use
80+
81+
e.g. to provide commands `show users`, `show sessions` and `show people`, use
8082
the following sequence:
8183

84+
```c
8285
cli_command *c = cli_register_command(NULL, "show", NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL);
8386
cli_register_command(c, "sessions", fn_sessions, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show the sessions connected");
8487
cli_register_command(c, "users", fn_users, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show the users connected");
8588
cli_register_command(c, "people", fn_people, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show a list of the people I like");
89+
```
8690
87-
88-
If callback is NULL, the command can be used as part of a tree, but cannot be
91+
If callback is `NULL`, the command can be used as part of a tree, but cannot be
8992
individually run.
9093
91-
9294
If you decide later that you don't want a command to be run, you can call
93-
cli_unregister_command(command).
95+
`cli_unregister_command(command)`.
9496
You can use this to build dynamic command trees.
9597
96-
9798
It is possible to carry along a user-defined context to all command callbacks
98-
using cli_set_context(cli, context) and cli_get_context(cli) functions.
99+
using `cli_set_context(cli, context)` and `cli_get_context(cli)` functions.
99100
100101
101102
You are responsible for accepting a TCP connection, and for creating a
102103
process or thread to run the cli. Once you are ready to process the
103-
connection, call cli_loop(cli, sock) to interact with the user on the
104+
connection, call `cli_loop(cli, sock)` to interact with the user on the
104105
given socket.
105106
106107
This function will return when the user exits the cli, either by breaking the
107-
connection or entering "quit".
108-
109-
Call cli_done() to free the data structures.
108+
connection or entering `quit`.
110109
110+
Call `cli_done()` to free the data structures.
111111
112-
- David Parrish (david@dparrish.com)

clitest.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ int shape_transient_eval(struct cli_def *cli, const char *name, const char *valu
260260
return CLI_OK;
261261
}
262262
cli_error(cli, "unrecognized value for setting %s -> %s", name, value);
263-
return CLI_ERROR;
263+
return CLI_ERROR;
264264
}
265265

266266
const char *KnownColors[] = {"black", "white", "gray", "red", "blue",
@@ -319,12 +319,12 @@ void run_child(int x) {
319319
cli_set_hostname(cli, "router");
320320
cli_telnet_protocol(cli, 1);
321321
cli_regular(cli, regular_callback);
322-
322+
323323
// change regular update to 5 seconds rather than default of 1 second
324324
cli_regular_interval(cli, 5);
325-
325+
326326
// set 60 second idle timeout
327-
cli_set_idle_timeout_callback(cli, 60, idle_timeout);
327+
cli_set_idle_timeout_callback(cli, 60, idle_timeout);
328328
cli_register_command(cli, NULL, "test", cmd_test, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL);
329329
cli_register_command(cli, NULL, "simple", NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL);
330330
cli_register_command(cli, NULL, "simon", NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL);

0 commit comments

Comments
 (0)