diff options
author | Michael Larson <slioch@slioch.vyatta.com> | 2010-04-13 11:50:23 -0700 |
---|---|---|
committer | Michael Larson <slioch@slioch.vyatta.com> | 2010-04-13 11:50:23 -0700 |
commit | 7c03bbb617c8e8c5bc9a553f25b79d43a8e40623 (patch) | |
tree | 322afdeb7acdd3126011910bfa115cd7bc388b4e /src/set.c | |
parent | 3ea2bdb717ceb9ef1f2843e3416ccf6ad0a54583 (diff) | |
download | vyatta-cfg-7c03bbb617c8e8c5bc9a553f25b79d43a8e40623.tar.gz vyatta-cfg-7c03bbb617c8e8c5bc9a553f25b79d43a8e40623.zip |
fix for bug 2176.
Embedded leaf nodes can now be supported in the cli structure. In additional an arbritrary limit can be set on the number of multinode values allowed.
Format in the node.def is:
tag: [u32]
or
multi: [u32]
For the special case of a leaf node the value for u32 is 1. In this case the operation applied to the node is to replace the node with the set value. This generates a
delete of the old tree structure from the embedded leaf and a set of the new tree structure from the embedded leaf.
Diffstat (limited to 'src/set.c')
-rw-r--r-- | src/set.c | 57 |
1 files changed, 57 insertions, 0 deletions
@@ -91,6 +91,63 @@ boolean set_validate(vtw_def *defp, char *valp, boolean empty_val) } return TRUE; } + + //apply limit count here, needs to be defined as a tag,multi and have a value set + if ((defp->tag || defp->multi) && (defp->def_tag > 0 || defp->def_multi > 0)) { + //get count of siblings + + char path[2048]; + char val[2048]; + char last_val[2048]; + char *pos = rindex(m_path.path,'/'); + if (pos != NULL) { + int offset = pos - m_path.path; + + strncpy(path,m_path.path,offset); + path[offset] = '\0'; + + strncpy(val,m_path.path + offset + 1, strlen(m_path.path) - offset - 1); + val[strlen(m_path.path) - offset - 1] = '\0'; + + // fprintf(out_stream,"val: %s, offset: %d, path: %s\n",val,offset,m_path.path); + + int file_count = 0; + struct dirent* entry; + DIR* dirp = opendir(path); /* There should be error handling after this */ + if (dirp != NULL) { + while ((entry = readdir(dirp)) != NULL) { + if (strcmp(entry->d_name,".") != 0 && + strcmp(entry->d_name,"..") != 0) { + strcpy(last_val,entry->d_name); + file_count++; + } + } + closedir(dirp); + + if (defp->tag && file_count == 1 && defp->def_tag == 1) { + //this is the special case, where the previous value should be deleted here... + char command[8192]; + //let unionfs handle the diff + sprintf(command, "mv %s/%s %s/%s", path,last_val,path,val); + system(command); + } + + if (defp->tag) { + if (defp->def_tag > 1 && file_count >= defp->def_tag) { + fprintf(out_stream,"Number of values exceeded for %s, allowed: %d, actual: %d\n",val,defp->def_tag,file_count); + return FALSE; + } + } + else { + if (defp->def_multi > 1 && file_count >= defp->def_multi) { + fprintf(out_stream,"Number of values exceeded for %s, allowed: %d, actual: %d\n",val,defp->def_multi,file_count); + return FALSE; + } + } + } + } + } + res = validate_value(defp, valp); return res; } |