Index: ossp-pkg/xds/regression-tests/xds-register.c RCS File: /v/ossp/cvs/ossp-pkg/xds/regression-tests/Attic/xds-register.c,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/xds/regression-tests/Attic/xds-register.c,v' 2>/dev/null --- 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); Index: ossp-pkg/xds/unregister.c RCS File: /v/ossp/cvs/ossp-pkg/xds/Attic/unregister.c,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/xds/Attic/unregister.c,v' 2>/dev/null --- 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 +#include +#include #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; }