OSSP CVS Repository

ossp - Difference in ossp-pkg/xds/register.c versions 1.1 and 1.2
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

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

--- register.c   2001/07/04 15:58:51     1.1
+++ register.c   2001/07/08 15:22:00     1.2
@@ -25,9 +25,61 @@
    SUCH DAMAGE.
 */
 
+#include <stdio.h>              /* delete me */
+
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
 #include "internal.h"
 
 int xds_register(xds_t* xds, const char* name, xds_engine_t engine, void* engine_context)
     {
-    return XDS_ERR_INVALID_ARG;
+    size_t pos;
+
+    printf("*** Inserting '%s' ...\n", name);
+    printf("Before the insertion:\n");
+    for (pos = 0; pos < xds->engines_len; ++pos)
+        printf("\tengines[%d] = '%s'\n", pos, xds->engines[pos].name);
+
+    /* Sanity checks. */
+
+    assert(xds != NULL);
+    assert(name != NULL);
+    assert(engine != NULL);
+    if (xds == NULL || name == NULL || engine == NULL)
+        return XDS_ERR_INVALID_ARG;
+
+    /* Copy the name argument into our own memory. */
+
+    name = strdup(name);
+    if (name == NULL)
+        return XDS_ERR_NO_MEM;
+
+    /* Search engines for the entry. */
+
+    if (xds_find_engine(xds->engines, xds->engines_len, name, &pos))
+        {                       /* overwrite existing entry */
+        free(xds->engines[pos].name);
+        }
+    else
+        {                       /* insert new entry */
+        xds_set_capacity((void**)&xds->engines, &xds->engines_capacity, xds->engines_len + 1, sizeof(engine_map_t), 1);
+        memmove(&xds->engines[pos+1], &xds->engines[pos], (xds->engines_len - pos) * sizeof(engine_map_t));
+        ++xds->engines_len;
+        }
+
+    /* Insert entry. */
+
+    xds->engines[pos].name    = (char*)name;
+    xds->engines[pos].engine  = engine;
+    xds->engines[pos].context = engine_context;
+
+    printf("After the insertion:\n");
+    for (pos = 0; pos < xds->engines_len; ++pos)
+        printf("\tengines[%d] = '%s'\n", pos, xds->engines[pos].name);
+    printf("\n");
+
+    /* Everything is fine. */
+
+    return XDS_OK;
     }

CVSTrac 2.0.1