]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
* prof_tree.c (struct profile_node): Add new bitfield DELETED.
authorKen Raeburn <raeburn@mit.edu>
Thu, 23 Sep 2004 23:26:25 +0000 (23:26 +0000)
committerKen Raeburn <raeburn@mit.edu>
Thu, 23 Sep 2004 23:26:25 +0000 (23:26 +0000)
(profile_add_node): Move variable CMP into inner block where it's used.  Clear
deleted flag.
(profile_find_node): Skip deleted nodes.
(profile_remove_node): Just set the deleted flag, don't modify the tree.
* Makefile.in (profile_tcl.c): Target should be in srcdir.
(profile_tcl.o): Depend on profile.h.
(DO_TCL): New variable.
(check-unix-tcl-, check-unix-tcl-ok): New targets.
(check-unix): Depend on one of them, based on DO_TCL.
* configure.in: Set and substitute DO_TCL.
* prof_test1: New file.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16784 dc483132-0cff-0310-8789-dd5450dbe970

src/util/profile/ChangeLog
src/util/profile/Makefile.in
src/util/profile/configure.in
src/util/profile/prof_set.c
src/util/profile/prof_test1 [new file with mode: 0644]
src/util/profile/prof_tree.c

index a08a6107d938d9a75d9e0c23c7003d4f3ed0c24e..a1cdc5b6fea98a498b58900ecd8e0719b293fa44 100644 (file)
@@ -1,5 +1,19 @@
 2004-09-23  Ken Raeburn  <raeburn@mit.edu>
 
+       * prof_tree.c (struct profile_node): Add new bitfield DELETED.
+       (profile_add_node): Move variable CMP into inner block where it's
+       used.  Clear deleted flag.
+       (profile_find_node): Skip deleted nodes.
+       (profile_remove_node): Just set the deleted flag, don't modify the
+       tree.
+       * Makefile.in (profile_tcl.c): Target should be in srcdir.
+       (profile_tcl.o): Depend on profile.h.
+       (DO_TCL): New variable.
+       (check-unix-tcl-, check-unix-tcl-ok): New targets.
+       (check-unix): Depend on one of them, based on DO_TCL.
+       * configure.in: Set and substitute DO_TCL.
+       * prof_test1: New file.
+
        * profile.swg: Only include tclsh.i if building for Tcl.
        (Tcl_SetResult, my_tcl_setresult): Compile hack only if building
        for Tcl.
@@ -7,6 +21,7 @@
        scripting language.  Add Python code.
        (%typemap errcode_t, errcode_t*): Add placeholders for Python
        support.
+       * profile_tcl.c: Regenerated.
 
 2004-08-28  Ken Raeburn  <raeburn@mit.edu>
 
index 6735909b719af2ed98d54cce0f669d529e188d09..76540a39e20d0d806f8f0fe1662baa9124561dce 100644 (file)
@@ -112,9 +112,9 @@ prof_err.c: $(srcdir)/prof_err.et
 prof_err.o: prof_err.c
 
 # not built by default, but may be useful for testing
-profile_tcl.c: profile.swg
+$(srcdir)/profile_tcl.c: profile.swg
        (cd $(srcdir) && swig -tcl8 -o profile_tcl.c profile.swg)
-profile_tcl.o: $(srcdir)/profile_tcl.c
+profile_tcl.o: $(srcdir)/profile_tcl.c profile.h
 profile_tcl: profile_tcl.o libprofile.a
        $(CC_LINK) -o profile_tcl profile_tcl.o \
                $(TCL_MAYBE_RPATH) \
@@ -129,6 +129,18 @@ clean-windows::
 
 check-unix:: test_parse test_profile
 
+DO_TCL=@DO_TCL@
+check-unix:: check-unix-tcl-$(DO_TCL)
+
+check-unix-tcl-:
+       @echo "+++"
+       @echo "+++ Tcl not available, some profile tests not run."
+       @echo "+++"
+
+check-unix-tcl-ok: profile_tcl
+       cp $(srcdir)/test.ini test2.ini
+       ./profile_tcl $(srcdir)/prof_test1
+
 check-windows:: $(OUTPRE)test_profile.exe $(OUTPRE)test_parse.exe
        $(RM) $(OUTPRE)*.obj
        $(OUTPRE)test_parse test.ini
index da9d921e867107d99ceba37034e1be72472561cc..17e8b58a2704ad14e82b6513fc4a24f6e621a872 100644 (file)
@@ -8,6 +8,9 @@ AC_CHECK_HEADERS(unistd.h stdlib.h pwd.h)
 AC_CHECK_FUNCS(stat access strdup getpwuid_r)
 AC_PROG_AWK
 AC_KRB5_TCL
+DO_TCL=
+test "$TCL_LIBS" != "" && DO_TCL=ok
+AC_SUBST(DO_TCL)
 KRB5_BUILD_LIBOBJS
 KRB5_BUILD_PROGRAM
 KRB5_BUILD_LIBRARY_WITH_DEPS
index f1e3daf63931c4128a9edf4d707421695f133124..310949b0ec7f327483820ff568ea46808eb7cf47 100644 (file)
@@ -81,7 +81,7 @@ static errcode_t rw_setup(profile_t profile)
 
        profile_unlock_global();
        retval = profile_update_file(file);
-       
+
        return retval;
 }
 
diff --git a/src/util/profile/prof_test1 b/src/util/profile/prof_test1
new file mode 100644 (file)
index 0000000..42a6021
--- /dev/null
@@ -0,0 +1,70 @@
+set wd [pwd]
+set p [profile_init_path $wd/test2.ini]
+set verbose 0
+
+proc test1 {} {
+    global wd p verbose
+    set sect {{test section 1} child_section child}
+    set iter [profile_iterator_create $p $sect 0]
+    set done 0
+    if $verbose { puts "Iterating over {$sect} entries:" }
+    while {!$done} {
+       set pair [profile_iterator $iter]
+       if [string match $pair {{} {}}] {
+           set done 1
+       } else {
+           set val [lindex $pair 1]
+           if $verbose { puts -nonewline "\t$val" }
+       }
+    }
+    if $verbose { puts "" }
+    #profile_iterator_free $iter
+
+    set iter [profile_iterator_create $p $sect 0]
+    set done 0
+    if $verbose { puts "Iterating again, deleting:" }
+    while {!$done} {
+       set pair [profile_iterator $iter]
+       if [string match $pair {{} {}}] {
+           set done 1
+       } else {
+           set val [lindex $pair 1]
+           if $verbose { puts -nonewline "\t$val" }
+           profile_update_relation $p $sect $val
+       }
+    }
+    if $verbose { puts "" }
+    #profile_iterator_free $iter
+    profile_flush $p
+
+    if $verbose { puts "Reloading profile" }
+    set p [profile_init_path $wd/test2.ini]
+    set iter [profile_iterator_create $p $sect 0]
+    set done 0
+    if $verbose { puts "Iterating again:" }
+    set found_some 0
+    while {!$done} {
+       set pair [profile_iterator $iter]
+       if [string match $pair {{} {}}] {
+           set done 1
+       } else {
+           set found_some 1
+           set val [lindex $pair 1]
+           if $verbose { puts -nonewline "\t$val" }
+       }
+    }
+    #profile_iterator_free $iter
+    profile_abandon $p
+
+    if {$found_some} {
+       if $verbose { puts "" }
+       puts stderr "Error: Deleting in iterator didn't get them all."
+       exit 1
+    } else {
+       puts "OK: Deleting in iteration got rid of all entries."
+    }
+}
+
+test1
+
+exit 0
index cf7f33f9cf4bbf476b68bb8e479d872b1d24e098..1d96ffbb82b2c57aa2c776869c7dca334014323a 100644 (file)
@@ -33,6 +33,7 @@ struct profile_node {
        char *value;
        int group_level;
        int final:1;            /* Indicate don't search next file */
+       int deleted:1;
        struct profile_node *first_child;
        struct profile_node *parent;
        struct profile_node *next, *prev;
@@ -149,7 +150,6 @@ errcode_t profile_add_node(struct profile_node *section, const char *name,
 {
        errcode_t retval;
        struct profile_node *p, *last, *new;
-       int     cmp = -1;
 
        CHECK_MAGIC(section);
 
@@ -162,6 +162,7 @@ errcode_t profile_add_node(struct profile_node *section, const char *name,
         * order matters.
         */
        for (p=section->first_child, last = 0; p; last = p, p = p->next) {
+               int cmp;
                cmp = strcmp(p->name, name);
                if (cmp > 0)
                        break;
@@ -170,6 +171,7 @@ errcode_t profile_add_node(struct profile_node *section, const char *name,
        if (retval)
                return retval;
        new->group_level = section->group_level+1;
+       new->deleted = 0;
        new->parent = section;
        new->prev = last;
        new->next = p;
@@ -262,6 +264,8 @@ errcode_t profile_find_node(struct profile_node *section, const char *name,
                        if (value && (strcmp(p->value, value)))
                                continue;
                }
+               if (p->deleted)
+                   continue;
                /* A match! */
                if (node)
                        *node = p;
@@ -570,15 +574,7 @@ errcode_t profile_remove_node(struct profile_node *node)
        if (node->parent == 0)
                return PROF_EINVAL; /* Can't remove the root! */
        
-       if (node->prev)
-               node->prev->next = node->next;
-       else
-               node->parent->first_child = node->next;
-
-       if (node->next)
-               node->next->prev = node->prev;
-
-       profile_free_node(node);
+       node->deleted = 1;
 
        return 0;
 }