OSSP CVS Repository

ossp - Check-in [4171]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 4171
Date: 2001-Jul-08 17:58:13 (local)
2001-Jul-08 15:58:13 (UTC)
User:simons
Branch:
Comment: Implemented xds_unregister() function and added apropriate test cases.
Tickets:
Inspections:
Files:
ossp-pkg/xds/regression-tests/xds-register.c      1.2 -> 1.3     32 inserted, 0 deleted
ossp-pkg/xds/unregister.c      1.1 -> 1.2     37 inserted, 1 deleted

ossp-pkg/xds/regression-tests/xds-register.c 1.2 -> 1.3

--- xds-register.c       2001/07/08 15:18:50     1.2
+++ xds-register.c       2001/07/08 15:58:14     1.3
@@ -104,6 +104,38 @@
             }
         }
 
+    /* Try to remove an unknown entry. */
+
+    if (xds_unregister(xds, "abacadabra") != XDS_ERR_UNKNOWN_ENGINE)
+        {
+        printf("xds_unregister() succeeded at removing 'abacadabra' even though it is not there.\n");
+        exit(1);
+        }
+
+    /* Remove an entry from the middle. */
+
+    if (xds_unregister(xds, "heinz") != XDS_OK)
+        {
+        printf("xds_unregister() failed to remove 'heinz'.\n");
+        exit(1);
+        }
+
+    /* Remove the last entry. */
+
+    if (xds_unregister(xds, "zarah") != XDS_OK)
+        {
+        printf("xds_unregister() failed to remove 'bar'.\n");
+        exit(1);
+        }
+
+    /* Remove the first entry. */
+
+    if (xds_unregister(xds, "bar") != XDS_OK)
+        {
+        printf("xds_unregister() failed to remove 'bar'.\n");
+        exit(1);
+        }
+
     /* Clean up. */
 
     xds_destroy(xds);


ossp-pkg/xds/unregister.c 1.1 -> 1.2

--- unregister.c 2001/07/04 15:58:51     1.1
+++ unregister.c 2001/07/08 15:58:13     1.2
@@ -25,9 +25,45 @@
    SUCH DAMAGE.
 */
 
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
 #include "internal.h"
 
 int xds_unregister(xds_t* xds, const char* name)
     {
-    return XDS_ERR_UNKNOWN_ENGINE;
+    size_t pos;
+
+    /* Sanity checks. */
+
+    assert(xds != NULL);
+    assert(name != NULL);
+    if (xds == NULL || name == NULL)
+        return XDS_ERR_INVALID_ARG;
+
+    /* Find the entry we're supposed to delete. */
+
+    if (!xds_find_engine(xds->engines, xds->engines_len, name, &pos))
+        return XDS_ERR_UNKNOWN_ENGINE;
+
+    /* Free the memory allocated for this entry and move the entries
+       behind it back if necessary. */
+
+    assert(xds->engines[pos].name != NULL);
+    free(xds->engines[pos].name);
+    memmove(&xds->engines[pos], &xds->engines[pos+1], (xds->engines_len - (pos + 1)) * sizeof(engine_map_t));
+    --xds->engines_len;
+
+    /* Lower capacity if necessary. */
+
+    int rc = xds_set_capacity((void**)&xds->engines,
+                              &xds->engines_capacity,
+                              xds->engines_len,
+                              sizeof(engine_map_t),
+                              XDS_INITIAL_ENGINES_CAPACITY);
+    assert(rc == XDS_OK || rc == XDS_ERR_NO_MEM);
+    if (rc != XDS_OK)
+        return rc;
+
+    return XDS_OK;
     }

CVSTrac 2.0.1