Commit e51baf78 authored by Daniel Salzman's avatar Daniel Salzman

ctl: add command flags

parent b17e5e4d
......@@ -14,6 +14,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <urcu.h>
#include "knot/common/log.h"
......@@ -362,8 +363,8 @@ static int send_block(conf_io_t *io)
// Get the item prefix.
switch (io->type) {
case NEW: data[KNOT_CTL_IDX_TYPE] = "+"; break;
case OLD: data[KNOT_CTL_IDX_TYPE] = "-"; break;
case NEW: data[KNOT_CTL_IDX_FLAGS] = CTL_FLAG_ADD; break;
case OLD: data[KNOT_CTL_IDX_FLAGS] = CTL_FLAG_REM; break;
default: break;
}
......@@ -653,3 +654,12 @@ int ctl_exec(ctl_cmd_t cmd, ctl_args_t *args)
return cmd_table[cmd].fcn(args, cmd);
}
bool ctl_has_flag(const char *flags, const char *flag)
{
if (flags == NULL || flag == NULL) {
return false;
}
return strstr(flags, flag) != NULL;
}
......@@ -27,6 +27,10 @@
#include "libknot/libknot.h"
#include "knot/server/server.h"
#define CTL_FLAG_FORCE "F"
#define CTL_FLAG_ADD "+"
#define CTL_FLAG_REM "-"
/*! Control commands. */
typedef enum {
CTL_NONE,
......@@ -97,4 +101,14 @@ int ctl_exec(ctl_cmd_t cmd, ctl_args_t *args);
*/
void ctl_log_data(knot_ctl_data_t *data);
/*!
* Checks flag presence in flags.
*
* \param[in] flags Flags to check presence in.
* \param[in] flag Checked flag.
*
* \return True if presented.
*/
bool ctl_has_flag(const char *flags, const char *flag);
/*! @} */
......@@ -157,15 +157,16 @@ static int get_conf_key(const char *key, knot_ctl_data_t *data)
return KNOT_EOK;
}
static void format_data(ctl_cmd_t cmd, knot_ctl_type_t type, knot_ctl_data_t *data,
bool *empty)
static void format_data(ctl_cmd_t cmd, knot_ctl_type_t data_type,
knot_ctl_data_t *data, bool *empty)
{
const char *error = (*data)[KNOT_CTL_IDX_ERROR];
const char *flags = (*data)[KNOT_CTL_IDX_FLAGS];
const char *key0 = (*data)[KNOT_CTL_IDX_SECTION];
const char *key1 = (*data)[KNOT_CTL_IDX_ITEM];
const char *id = (*data)[KNOT_CTL_IDX_ID];
const char *zone = (*data)[KNOT_CTL_IDX_ZONE];
const char *param = (*data)[KNOT_CTL_IDX_TYPE];
const char *type = (*data)[KNOT_CTL_IDX_TYPE];
const char *value = (*data)[KNOT_CTL_IDX_DATA];
switch (cmd) {
......@@ -186,7 +187,7 @@ static void format_data(ctl_cmd_t cmd, knot_ctl_type_t type, knot_ctl_data_t *da
case CTL_ZONE_RETRANSFER:
case CTL_ZONE_FLUSH:
case CTL_ZONE_SIGN:
if (type == KNOT_CTL_TYPE_DATA) {
if (data_type == KNOT_CTL_TYPE_DATA) {
printf("%s%s%s%s%s%s%s%s",
(!(*empty) ? "\n" : ""),
(error != NULL ? "error: " : ""),
......@@ -198,10 +199,10 @@ static void format_data(ctl_cmd_t cmd, knot_ctl_type_t type, knot_ctl_data_t *da
(error != NULL ? ")" : ""));
*empty = false;
}
if (param != NULL) {
if (cmd == CTL_ZONE_STATUS && type != NULL) {
printf("%s %s: %s",
(type != KNOT_CTL_TYPE_DATA ? " |" : ""),
param, value);
(data_type != KNOT_CTL_TYPE_DATA ? " |" : ""),
type, value);
}
break;
case CTL_CONF_LIST:
......@@ -210,13 +211,20 @@ static void format_data(ctl_cmd_t cmd, knot_ctl_type_t type, knot_ctl_data_t *da
case CTL_CONF_GET:
case CTL_CONF_SET:
case CTL_CONF_UNSET:
if (type == KNOT_CTL_TYPE_DATA) {
if (data_type == KNOT_CTL_TYPE_DATA) {
const char *sign = NULL;
if (ctl_has_flag(flags, CTL_FLAG_ADD)) {
sign = CTL_FLAG_ADD;
} else if (ctl_has_flag(flags, CTL_FLAG_REM)) {
sign = CTL_FLAG_REM;
}
printf("%s%s%s%s%s%s%s%s%s%s%s%s",
(!(*empty) ? "\n" : ""),
(error != NULL ? "error: (" : ""),
(error != NULL ? error : ""),
(error != NULL ? ") " : ""),
(param != NULL ? param : ""),
(sign != NULL ? sign : ""),
(key0 != NULL ? key0 : ""),
(id != NULL ? "[" : ""),
(id != NULL ? id : ""),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment