3
* Copyright (c) 2010, Zed A. Shaw and Mongrel2 Project Contributors.
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions are
10
* * Redistributions of source code must retain the above copyright
11
* notice, this list of conditions and the following disclaimer.
13
* * Redistributions in binary form must reproduce the above copyright
14
* notice, this list of conditions and the following disclaimer in the
15
* documentation and/or other materials provided with the distribution.
17
* * Neither the name of the Mongrel2 Project, Zed A. Shaw, nor the names
18
* of its contributors may be used to endorse or promote products
19
* derived from this software without specific prior written
22
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
23
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
26
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
#include <tnetstrings.h>
39
#include "../commands.h"
40
#include "../query_print.h"
42
int Command_servers(Command *cmd)
44
bstring db_file = option(cmd, "db", "config.sqlite");
46
check_file(db_file, "config database", R_OK | W_OK);
48
printf("SERVERS:\n------\n");
49
return simple_query_print(db_file, "SELECT name, default_host, uuid from server");
55
int Command_hosts(Command *cmd)
57
bstring db_file = option(cmd, "db", "config.sqlite");
58
bstring server = option(cmd, "server", NULL);
62
check_file(db_file, "config database", R_OK | W_OK);
63
check(server, "You need to give a -server of the server to list hosts from.");
65
sql = sqlite3_mprintf("SELECT id, name from host where server_id = (select id from server where name = %Q)", bdata(server));
67
printf("HOSTS in %s:\n-----\n", bdata(server));
68
rc = simple_query_print(db_file, sql);
71
if(sql) sqlite3_free(sql);
76
int Command_routes(Command *cmd)
78
bstring db_file = option(cmd, "db", "config.sqlite");
79
bstring server = option(cmd, "server", NULL);
80
bstring host = option(cmd, "host", NULL);
81
bstring host_id = option(cmd, "id", NULL);
85
check_file(db_file, "config database", R_OK | W_OK);
88
printf("ROUTES in host id %s\n-----\n", bdata(host_id));
89
sql = sqlite3_mprintf("SELECT path from route where host_id=%q", bdata(host_id));
91
check(server, "Must set the -server name you want or use -id.");
92
check(host, "Must set the -host in that server you want or use -id.");
94
printf("ROUTES in host %s, server %s\n-----\n", bdata(host), bdata(server));
96
sql = sqlite3_mprintf("SELECT route.path from route, host, server where "
97
"host.name = %Q and route.host_id = host.id and server.name = %Q and "
98
"host.server_id = server.id", bdata(host), bdata(server));
101
rc = simple_query_print(db_file, sql);
104
if(sql) sqlite3_free(sql);