OpenDNSSEC-enforcer  2.1.3
help_cmd.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 NLNet Labs
3  * Copyright (c) 2014 OpenDNSSEC AB (svb)
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
29 #include "config.h"
30 
31 #include "file.h"
32 #include "log.h"
33 #include "str.h"
34 #include "cmdhandler.h"
35 #include "daemon/engine.h"
36 #include "clientpipe.h"
37 
38 #include "daemon/help_cmd.h"
39 
40 static const char *module_str = "help_cmd";
41 
42 static void
43 usage(int sockfd)
44 {
45  client_printf(sockfd,
46  "help\n"
47  " [command]\n"
48  );
49 }
50 
51 static void
52 help(int sockfd)
53 {
54  client_printf(sockfd,
55  "Without arguments print an overview of available commands for the daemon\n"
56  "and a short description of usage. With [command] set, print usage information\n"
57  "of command and extended help if available.\n\n"
58  );
59 }
60 
61 static int
62 handles(const char *cmd)
63 {
64  return ods_check_command(cmd, help_funcblock.cmdname)? 1 : 0;
65 }
66 
67 static int
68 run(int sockfd, cmdhandler_ctx_type* context, const char *cmd)
69 {
70  struct cmd_func_block* fb;
71 
72  ods_log_debug("[%s] help command", module_str);
73 
74  if (strlen(cmd) < 6) {
75  /* Anouncement */
76  client_printf(sockfd, "\nCommands:\n");
77  cmdhandler_get_usage(sockfd, context->cmdhandler);
78  } else {
79  if ((fb = get_funcblock(&cmd[5], context->cmdhandler))) {
80  client_printf(sockfd, "Usage:\n");
81  fb->usage(sockfd);
82  client_printf(sockfd, "\nHelp:\n");
83  if (fb->help) {
84  fb->help(sockfd);
85  } else {
86  client_printf(sockfd, "No help available for '%s'\n",
87  cmd+5);
88  return 1;
89  }
90  } else {
91  client_printf(sockfd, "Help: command '%s' unknown. Type "
92  "'help' without arguments to get a list of supported "
93  "commands.\n", cmd+5);
94  return 2;
95  }
96  }
97  return 0;
98 }
99 
100 struct cmd_func_block help_funcblock = {
101  "help", &usage, &help, &handles, &run
102 };
struct cmd_func_block help_funcblock
Definition: help_cmd.c:100