/* This file is part of GNU Pies.
Copyright (C) 2015, 2016 Sergey Poznyakoff
GNU Pies is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Pies is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Pies. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/un.h>
#include <sys/stat.h>
#include <netdb.h>
#include <locale.h>
#include <errno.h>
#include <fcntl.h>
#include <configmake.h>
#include <grecs.h>
#include <grecs-locus.h>
#include <json.h>
#include <wordsplit.h>
#include <sysexits.h>
#include <termios.h>
#include "base64.h"
#include "progname.h"
#include "libpies.h"
#include "grecsasrt.h"
#include "fprintftime.h"
struct pies_url *default_url; /* Control socket URL */
struct pies_url *url;
char const *instance = "pies";
char *config_file;
char default_config_file[] = SYSCONFDIR "/piesctl.conf";
int preprocess_only;
int verbose;
int dump;
static void config_help (void);
#include "piesctl-cl.h"
static struct grecs_keyword instance_keywords[] = {
{"socket",
N_("url: string"),
N_("Socket URL for that instance."),
grecs_type_string, GRECS_DFLT,
NULL, 0, conf_callback_url},
{ NULL }
};
static int
callback_instance (enum grecs_callback_command cmd,
grecs_locus_t *locus,
void *varptr,
grecs_value_t *value, void *cb_data)
{
switch (cmd)
{
case grecs_callback_section_begin:
if (GRECS_VALUE_EMPTY_P (value))
{
grecs_error (locus, 0, _("missing tag"));
return 1;
}
if (assert_grecs_value_type (&value->locus, value, GRECS_TYPE_STRING))
return 1;
if (!url && strcmp (value->v.string, instance) == 0)
*(struct pies_url ***) cb_data = &url;
else
*(struct pies_url ***) cb_data = NULL;
break;
case grecs_callback_section_end:
break;
case grecs_callback_set_value:
grecs_error (locus, 0, _("invalid use of block statement"));
}
return 0;
}
struct grecs_keyword piesctl_keywords[] = {
{"socket",
N_("url: string"),
N_("Default socket URL."),
grecs_type_string, GRECS_DFLT,
&default_url, 0, conf_callback_url},
{"instance",
N_("name"),
N_("Configure connection to a pies instance"),
grecs_type_section, GRECS_DFLT,
NULL, 0,
callback_instance, NULL, instance_keywords },
{ NULL }
};
static void
parse_config ()
{
char *file_name;
struct grecs_node *tree;
grecs_include_path_setup (DEFAULT_VERSION_INCLUDE_DIR,
DEFAULT_INCLUDE_DIR, NULL);
grecs_log_to_stderr = 1;
grecs_preprocessor = pp_command_line ();
if (config_file)
file_name = config_file;
else if (access (default_config_file, F_OK) == 0)
file_name = d
|