* Use unix domain sockets because we're going to need to run this locally anyway...
[citadel.git] / ctdlsh / src / main.c
1 /*
2  * (c) 2009 by Art Cancro and citadel.org
3  * This program is released under the terms of the GNU General Public License v3.
4  */
5
6 #include <config.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <stdio.h>
10 #include <readline/readline.h>
11
12 int main(int argc, char **argv)
13 {
14         char *cmd = NULL;
15         char *prompt = "> ";
16         int server_socket = 0;
17         char buf[1024];
18
19         printf("\nCitadel administration shell v" PACKAGE_VERSION "\n");
20         printf("(c) 2009 citadel.org GPLv3\n");
21
22         printf("Attaching to server...\r");
23         fflush(stdout);
24         server_socket = uds_connectsock("/root/ctdl/trunk/citadel/citadel.socket");
25         if (server_socket < 0) {
26                 exit(1);
27         }
28         printf("                      \r");
29
30         sock_getln(server_socket, buf, sizeof buf);
31         printf("%s\n", buf);
32
33         while (cmd = readline(prompt)) {
34
35                 if ((cmd) && (*cmd)) {
36                         add_history(cmd);
37                 }
38
39                 printf("\nHaha, you said: '%s'\n\n", cmd);
40                 free(cmd);
41         }
42         printf("\r");
43
44         sock_puts(server_socket, "QUIT");
45         sock_getln(server_socket, buf, sizeof buf);
46         printf("%s\n", buf);
47         close(server_socket);
48         exit(0);
49 }