OSSP CVS Repository

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

Check-in Number: 1565
Date: 2002-Jan-16 21:32:23 (local)
2002-Jan-16 20:32:23 (UTC)
User:rse
Branch:
Comment: add general query function which can be used to get back all things which were stored on val_reg() and especially allows to query just the existance of the value.
Tickets:
Inspections:
Files:
ossp-pkg/val/val.c      1.4 -> 1.5     37 inserted, 0 deleted
ossp-pkg/val/val.h      1.3 -> 1.4     1 inserted, 0 deleted

ossp-pkg/val/val.c 1.4 -> 1.5

--- val.c        2002/01/16 20:24:09     1.4
+++ val.c        2002/01/16 20:32:23     1.5
@@ -722,6 +722,43 @@
     return VAL_OK;
 }
 
+/* query information about a value */
+val_rc_t val_query(val_t *val, const char *name, 
+                   int *ptype, char **pdesc, void **pstorage)
+{
+    char *cp;
+    val_object_t *obj;
+    val_t *child;
+
+    /* argument consistency check */
+    if (val == NULL || name == NULL)
+        return VAL_ERR_ARG;
+
+    /* recursive step-down on structured name */
+    if ((cp = strchr(name, '.')) != NULL) {
+        if (!lh_lookup(val->lh, name, cp-name, (void **)&obj, NULL))
+            return VAL_ERR_ARG;
+        if (!(obj->type & VAL_TYPE_VAL))
+            return VAL_ERR_USE;
+        child = *(val_t **)(val_storage(obj));
+        return val_query(child, cp+1, ptype, pdesc, pstorage);
+    }
+
+    /* try to lookup object in hash table */
+    if (!lh_lookup(val->lh, name, strlen(name), (void **)&obj, NULL))
+        return VAL_ERR_ARG;
+
+    /* pass queried information to caller */
+    if (ptype != NULL)
+        *ptype = (obj->type & ~VAL_INLINE);
+    if (pdesc != NULL)
+        *pdesc = obj->desc;
+    if (pstorage != NULL)
+        *pstorage = val_storage(obj);
+
+    return VAL_OK;
+}
+
 /* set a value (va_list variant) */
 val_rc_t val_vset(val_t *val, const char *name, va_list ap)
 {


ossp-pkg/val/val.h 1.3 -> 1.4

--- val.h        2002/01/16 20:24:10     1.3
+++ val.h        2002/01/16 20:32:23     1.4
@@ -70,6 +70,7 @@
 val_rc_t val_create  (val_t **);
 val_rc_t val_destroy (val_t *);
 val_rc_t val_reg     (val_t *, const char *, int, const char *, void *);
+val_rc_t val_query   (val_t *, const char *, int *, char **, void **);
 val_rc_t val_set     (val_t *, const char *, ...);
 val_rc_t val_get     (val_t *, const char *, ...);
 val_rc_t val_vset    (val_t *, const char *, va_list);

CVSTrac 2.0.1