31#include "cmdhandler.h"
35#include "clientpipe.h"
36#include "longgetopt.h"
41static const char *module_str =
"policy_export_cmd";
50 " --policy <policy> | --all aka -p | -a \n"
58 "Export a specified policy or all of them from the database.\n"
60 "policy|all limit the operation to a specified policy or all of them\n\n"
65run(cmdhandler_ctx_type* context,
int argc,
char* argv[])
67 int sockfd = context->sockfd;
68 struct longgetopt optctx;
69 int long_index = 0, opt = 0;
75 static struct option long_options[] = {
76 {
"policy", required_argument, 0,
'p'},
77 {
"all", no_argument, 0,
'a'},
81 for(opt = longgetopt(argc, argv,
"p:a", long_options, &long_index, &optctx); opt != -1;
82 opt = longgetopt(argc, argv, NULL, long_options, &long_index, &optctx)) {
91 client_printf_err(sockfd,
"unknown arguments\n");
92 ods_log_error(
"[%s] unknown arguments for policy export command", module_str);
108 client_printf_err(sockfd,
"Unable to find policy %s!\n",
policy_name);
118 client_printf_err(sockfd,
"Either --all or --policy needs to be given!\n");
126 "policy export", &usage, &help, NULL, NULL, &run, NULL
db_connection_t * getconnectioncontext(cmdhandler_ctx_type *context)
policy_t * policy_new_get_by_name(const db_connection_t *connection, const char *name)
const char * policy_name(const policy_t *policy)
void policy_free(policy_t *policy)
int policy_export(int sockfd, const policy_t *policy, const char *filename)
int policy_export_all(int sockfd, const db_connection_t *connection, const char *filename)
struct cmd_func_block policy_export_funcblock