summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cli_def.l7
-rw-r--r--src/cli_new.c2
-rw-r--r--src/cli_parse.y27
-rw-r--r--src/cli_val.h1
-rw-r--r--src/commit.c117
-rw-r--r--src/delete.c88
6 files changed, 229 insertions, 13 deletions
diff --git a/src/cli_def.l b/src/cli_def.l
index 07c9c68..d73f1c4 100644
--- a/src/cli_def.l
+++ b/src/cli_def.l
@@ -19,8 +19,9 @@ static char str_delim = 0;
static int eof_seen = 0;
static int pre_str_state = 0;
-static char *reg_fields[] = { "default", "tag", "type", "multi", NULL };
-static int reg_fields_t[] = { DEFAULT, TAG, TYPE, MULTI, 0 };
+static char *reg_fields[] = { "default", "tag", "type", "multi", "priority",
+ NULL };
+static int reg_fields_t[] = { DEFAULT, TAG, TYPE, MULTI, PRIORITY, 0 };
static char *act_fields[] = { "help", "syntax", "commit",
"delete", "update", "activate", "create",
"begin", "end",
@@ -262,7 +263,7 @@ RE_OP_COND (==|!=|<|>|<=|>=|in)
RE_OP_OTHER (pattern|exec|,|\|\||&&|=|!|\(|\)|;)
/* template fields */
-RE_REG_FIELD (default|tag|type|multi)
+RE_REG_FIELD (default|tag|type|multi|priority)
RE_ACT_FIELD (help|syntax|commit|delete|update|activate|create|begin|end|comp_help|allowed)
%%
diff --git a/src/cli_new.c b/src/cli_new.c
index 1ecbe83..26cc719 100644
--- a/src/cli_new.c
+++ b/src/cli_new.c
@@ -1435,7 +1435,7 @@ static int expand_string(char *stringp)
if(clind_config_engine_apply_command_path(n_cfg_path,
n_tmpl_path,
n_cmd_path,
- FALSE,
+ TRUE,
&cv,
get_cdirp(),
get_tdirp(),
diff --git a/src/cli_parse.y b/src/cli_parse.y
index 6378bc9..dd3d7d2 100644
--- a/src/cli_parse.y
+++ b/src/cli_parse.y
@@ -1,8 +1,12 @@
%{
-
#include <assert.h>
#include <stdio.h>
#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#define __USE_ISOC99
+#include <limits.h>
#include "cli_val.h"
@@ -30,6 +34,7 @@ static void cli_deferror(const char *);
%token TYPE
%token HELP
%token DEFAULT
+%token PRIORITY
%token PATTERN
%token EXEC
%token SYNTAX
@@ -101,6 +106,7 @@ type: TYPE TYPE_DEF
cause: help_cause
| default_cause
+ | priority_stmt
| syntax_cause
| ACTION action { append(parse_defp->actions + $1, $2, 0);}
| dummy_stmt
@@ -126,6 +132,25 @@ default_cause: DEFAULT STRING
parse_defp->def_default = $2;
}
+priority_stmt: PRIORITY VALUE
+ {
+ char *tmp = $2.val;
+ long long int cval = 0;
+ char *endp = NULL;
+ errno = 0;
+ cval = strtoll(tmp, &endp, 10);
+ if (($2.val_type != INT_TYPE)
+ || (errno == ERANGE
+ && (cval == LLONG_MAX || cval == LLONG_MIN))
+ || (errno != 0 && cval == 0)
+ || (*endp != '\0') || (cval < 0) || (cval > UINT_MAX)) {
+ yy_cli_parse_error((const char *)
+ "Priority must be <u32>\n");
+ } else {
+ parse_defp->def_priority = cval;
+ }
+ }
+
syntax_cause: SYNTAX exp {append(parse_defp->actions + syntax_act, $2, 0);}
;
diff --git a/src/cli_val.h b/src/cli_val.h
index edbda41..520fa8e 100644
--- a/src/cli_val.h
+++ b/src/cli_val.h
@@ -101,6 +101,7 @@ typedef struct {
char *def_type_help;
char *def_node_help;
char *def_default;
+ unsigned int def_priority;
boolean tag;
boolean multi;
vtw_list actions[top_act];
diff --git a/src/commit.c b/src/commit.c
index 534757c..84e088f 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -15,6 +15,23 @@
#include "cli_parse.h"
#include "cli_path_utils.h"
+struct DirIndex {
+ int dirname_index;
+ int dirname_ct;
+ struct DirSort** dirname;
+};
+
+struct DirSort {
+ char name[255];
+ unsigned long priority;
+};
+
+/*
+static int g_dirname_index = 0;
+static int g_dirname_ct = 0;
+static struct DirSort** g_dirname = NULL;
+*/
+
static char def_name[] = DEF_NAME;
static char tag_name[] = TAG_NAME;
static char opaque_name[] = OPQ_NAME;
@@ -52,17 +69,92 @@ static void make_dir()
return;
}
#endif
+/*
+static int
+compare_dirname(const void *p, const void *q)
+{
+ const struct DirSort *a = (const struct DirSort*)*(struct Dirsort **)p;
+ const struct DirSort *b = (const struct DirSort*)*(struct Dirsort **)q;
+ if (a->priority == b->priority) {
+ return strcmp(a->name,b->name);
+ }
+ return ((long)b->priority - (long)a->priority);
+}
-static struct dirent *
-get_next_filtered_dirent(DIR *dp, int exclude_wh)
+void
+init_next_filtered_dirname(DIR *dp, struct DirIndex *di, int exclude_wh)
{
- struct dirent *dirp = NULL;
+ // fprintf(out_stream,"\n");
+ di->dirname = malloc(1024 * sizeof(char*));
+ di->dirname_ct = 0;
+ di->dirname_index = 0;
+
+ int i;
+
+ //NOTE: need to free ct round up to next 1024 when shutting down commit
+
+ struct dirent *dirp;
while ((dirp = readdir(dp)) != NULL) {
if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0
|| strcmp(dirp->d_name, MOD_NAME) == 0
|| strcmp(dirp->d_name, opaque_name) == 0
|| (exclude_wh && strncmp(dirp->d_name, ".wh.", 4) == 0)) {
continue;
+ }
+ else {
+ struct DirSort *d = malloc(sizeof(struct DirSort));
+ if (strlen(dirp->d_name) >= 255) {
+ bye("configuration value exceeds 255 chars\n");
+ }
+ strcpy(d->name,dirp->d_name);
+ d->priority = (unsigned long)0;
+
+ //retreive priority now
+ vtw_def def;
+ char *path;
+ path = malloc(strlen(t_path.path)+strlen(dirp->d_name)+2+8);
+ sprintf(path,"%s/%s/node.def",t_path.path,dirp->d_name);
+ struct stat s;
+ if ((lstat(path,&s) >= 0) &&
+ ((s.st_mode & S_IFMT) == S_IFREG)) {
+ memset(&def, 0, sizeof(def));
+ if (parse_def(&def,path,FALSE) == 0) {
+ // fprintf(out_stream, "found(D): %s:%d\n",dirp->d_name, def.def_priority);
+ d->priority = def.def_priority;
+ }
+ }
+ free(path);
+
+ di->dirname[di->dirname_ct++] = d;
+ if (di->dirname_ct % 1024 == 0) {
+ di->dirname = realloc(di->dirname, (di->dirname_ct+1024)*sizeof(char*));
+ }
+ }
+ }
+ qsort(di->dirname, di->dirname_ct, sizeof(char*), compare_dirname);
+}
+
+static char*
+get_next_filtered_dirname(struct DirIndex *di)
+{
+ if (di->dirname_index == di->dirname_ct) {
+ return NULL;
+ }
+ //just return the collection ptr;
+ // fprintf(out_stream, "get_next: %s\n", di->dirname[di->dirname_index]->name);
+ return di->dirname[di->dirname_index++]->name;
+}
+*/
+static struct dirent *
+get_next_filtered_dirent(DIR *dp, int exclude_wh)
+{
+ struct dirent *dirp = NULL;
+ while ((dirp = readdir(dp)) != NULL) {
+ if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0
+ || strcmp(dirp->d_name, MOD_NAME) == 0
+ || strcmp(dirp->d_name, opaque_name) == 0
+ || (exclude_wh && strncmp(dirp->d_name, ".wh.", 4) == 0)) {
+ continue;
} else {
return dirp;
}
@@ -89,6 +181,7 @@ static boolean validate_dir_for_commit()
int subdirs_number=0;
DIR *dp=NULL;
struct dirent *dirp=NULL;
+ char *dirname = NULL;
char *cp=NULL;
boolean ret=TRUE;
char *uename = NULL;
@@ -130,8 +223,12 @@ static boolean validate_dir_for_commit()
if (def_present && def.tag) {
push_path(&t_path, tag_name); /* PUSH 2a */
}
-
- while ((dirp = get_next_filtered_dirent(dp, 1)) != NULL) {
+ /*
+ struct DirIndex *di = malloc(sizeof(struct DirIndex));
+ init_next_filtered_dirname(dp,di,1);
+ while ((dirname = get_next_filtered_dirname(di)) != NULL) {
+ */
+ while ((dirp = get_next_filtered_dirent(dp,1)) != NULL) {
subdirs_number++;
if(uename)
@@ -962,11 +1059,17 @@ static void
get_filtered_directory_listing(DIR *dp, valstruct *mvals, vtw_type_e type,
int exclude_wh)
{
- struct dirent *dirp = NULL;
+ char *dname = NULL;
char *cp = NULL;
+ struct dirent *dirp = NULL;
memset(mvals, 0, sizeof (valstruct));
- while ((dirp = get_next_filtered_dirent(dp, exclude_wh)) != NULL) {
+ /*
+ struct DirIndex *di = malloc(sizeof(struct DirIndex));
+ init_next_filtered_dirname(dp,di,exclude_wh);
+ while ((dname = get_next_filtered_dirname(di)) != NULL) {
+ */
+ while ((dirp = get_next_filtered_dirent(dp,exclude_wh)) != NULL) {
cp = clind_unescape(dirp->d_name);
valstruct_append(mvals, cp, type);
}
diff --git a/src/delete.c b/src/delete.c
index bb36fd1..aa83796 100644
--- a/src/delete.c
+++ b/src/delete.c
@@ -34,6 +34,49 @@ static void remove_rf(boolean do_umount)
free(command);
}
}
+static boolean has_default(char **def, int size)
+{
+ char *buf;
+ buf = malloc(1025);
+ char *buf_ptr;
+ FILE *fp = fopen(t_path.path, "r");
+ if (fp) {
+ while (fgets(buf, 1024, fp)) {
+ if (strncmp(buf, "default:", 8) == 0) {
+ buf_ptr = index(buf,':');
+ if (buf_ptr == NULL) {
+ break;
+ }
+ buf_ptr++;
+ if (size < strlen(buf_ptr)-1) {
+ bye("default buffer size is too small\n");
+ }
+ memcpy(*def, buf_ptr, strlen(buf_ptr)-1);
+ fclose(fp);
+ free(buf);
+ return 0;
+ }
+ }
+ fclose(fp);
+ }
+ free(buf);
+ return 1;
+}
+static void reset_default(char *def_val)
+{
+ char *command;
+ boolean has_default = 1;
+ if (def_val == NULL) {
+ return;
+ }
+ if (has_default) {
+ touch();
+ command = my_malloc(strlen(m_path.path) + 100, "set");
+ sprintf(command, "echo %s > %s/node.val", def_val, m_path.path);
+ system(command);
+ free(command);
+ }
+}
/***************************************************
set_validate:
validate value against definition
@@ -139,6 +182,7 @@ int main(int argc, char **argv)
fprintf(out_stream, "Nothing to delete\n");
bye("Nothing to delete at %s", m_path.path);
}
+
remove_rf(FALSE);
pop_path(&m_path);
if ((dp = opendir(m_path.path)) == NULL){
@@ -187,7 +231,17 @@ int main(int argc, char **argv)
}
}
/* else no defnition, remove it also */
- remove_rf(FALSE);
+ char *def_val;
+ def_val = malloc(1025);
+ if (has_default(&def_val,1024) == 0) {
+ reset_default(def_val);
+ free(def_val);
+ }
+ else {
+ remove_rf(FALSE);
+ }
+
+ // remove_rf(FALSE);
exit(0);
}
if(ai < argc -1 || last_tag) {
@@ -267,6 +321,38 @@ int main(int argc, char **argv)
remove_rf(FALSE);
return 0;
}
+
+ /*
+ let's do a new check here:
+ -> if this is a leaf and there is a value look for a match of the value
+ -> make sure to check existing configuration as well as uncommitted config
+ */
+ if (ai+1 == argc) {
+ //does this work up until the last value
+ pop_path(&m_path);
+ if(lstat(m_path.path, &statbuf) == 0) {
+ //now compare last value with that in the node.def file to determine whether to accept this delete
+ status = get_value(&cp, &m_path);
+ if (status != VTWERR_OK) {
+ bye("Cannot read old value %s\n", m_path.path);
+ }
+ if (!strcmp(cp,argv[argc - 1])) {
+ /* Also need to handle the case where the value is not specified. */
+ char *def_val;
+ def_val = malloc(1025);
+ if (has_default(&def_val,1024) == 0) {
+ reset_default(def_val);
+ free(def_val);
+ }
+ else {
+ remove_rf(FALSE);
+ }
+ return 0;
+ }
+ }
+ }
+
+
fprintf(out_stream, "The specified configuration node is not valid\n");
bye("There is no appropriate template for %s",
m_path.path + strlen(get_mdirp()));