OSSP CVS Repository

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

Check-in Number: 1558
Date: 2002-Jan-16 15:19:07 (local)
2002-Jan-16 14:19:07 (UTC)
User:thl
Branch:
Comment: commit for protocol reasons
Tickets:
Inspections:
Files:
ossp-pkg/lmtp2nntp/lmtp2nntp_config.c      1.6 -> 1.7     27 inserted, 20 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp_val.c      1.2 -> 1.3     74 inserted, 23 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp_val.h      1.2 -> 1.3     1 inserted, 1 deleted

ossp-pkg/lmtp2nntp/lmtp2nntp_config.c 1.6 -> 1.7

--- lmtp2nntp_config.c   2002/01/16 09:46:52     1.6
+++ lmtp2nntp_config.c   2002/01/16 14:19:07     1.7
@@ -106,40 +106,40 @@
 {
     switch (type) {
         case VAL_TYPE_VAL:
-            fprintf(stderr, "DEBUG: <%10s> VAL_TYPE_VAL,    desc=<%20s>, data@%.8lx INTERNAL\n",
-                    (char *)ctx,       desc, (long)data);
+            fprintf(stderr, "DEBUG: <%10s>, name=<%10s>, VAL_TYPE_VAL,    desc=<%20s>, data@%.8lx INTERNAL\n",
+                    (char *)ctx, name,      desc, (long)data);
             break;
         case VAL_TYPE_PTR:
-            fprintf(stderr, "DEBUG: <%10s> VAL_TYPE_PTR,    desc=<%20s>, data@%.8lx=%.8lx\n",
-                    (char *)ctx,       desc, (long)data, *(long *)data);
+            fprintf(stderr, "DEBUG: <%10s>, name=<%10s>, VAL_TYPE_PTR,    desc=<%20s>, data@%.8lx=%.8lx\n",
+                    (char *)ctx, name,      desc, (long)data, *(long *)data);
             break;
         case VAL_TYPE_CHAR:                                                                              
-            fprintf(stderr, "DEBUG: <%10s> VAL_TYPE_CHAR,   desc=<%20s>, data@%.8lx='%c'\n",
-                    (char *)ctx,       desc, (long)data, *(char *)data);
+            fprintf(stderr, "DEBUG: <%10s>, name=<%10s>, VAL_TYPE_CHAR,   desc=<%20s>, data@%.8lx='%c'\n",
+                    (char *)ctx, name,      desc, (long)data, *(char *)data);
             break;
         case VAL_TYPE_SHORT:                                                                             
-            fprintf(stderr, "DEBUG: <%10s> VAL_TYPE_SHORT,  desc=<%20s>, data@%.8lx=%8d\n",
-                    (char *)ctx,       desc, (long)data, *(short *)data);
+            fprintf(stderr, "DEBUG: <%10s>, name=<%10s>, VAL_TYPE_SHORT,  desc=<%20s>, data@%.8lx=%8d\n",
+                    (char *)ctx, name,      desc, (long)data, *(short *)data);
             break;
         case VAL_TYPE_INT:                                                                               
-            fprintf(stderr, "DEBUG: <%10s> VAL_TYPE_INT,    desc=<%20s>, data@%.8lx=%8d\n",
-                    (char *)ctx,       desc, (long)data, *(int *)data);
+            fprintf(stderr, "DEBUG: <%10s>, name=<%10s>, VAL_TYPE_INT,    desc=<%20s>, data@%.8lx=%8d\n",
+                    (char *)ctx, name,      desc, (long)data, *(int *)data);
             break;
         case VAL_TYPE_LONG:                                                                              
-            fprintf(stderr, "DEBUG: <%10s> VAL_TYPE_LONG,   desc=<%20s>, data@%.8lx=%8d\n",
-                    (char *)ctx,       desc, (long)data, *(long *)data);
+            fprintf(stderr, "DEBUG: <%10s>, name=<%10s>, VAL_TYPE_LONG,   desc=<%20s>, data@%.8lx=%8ld\n",
+                    (char *)ctx, name,      desc, (long)data, *(long *)data);
             break;
         case VAL_TYPE_FLOAT:                                                                             
-            fprintf(stderr, "DEBUG: <%10s> VAL_TYPE_FLOAT,  desc=<%20s>, data@%.8lx=%8f\n",
-                    (char *)ctx,       desc, (long)data, *(float *)data);
+            fprintf(stderr, "DEBUG: <%10s>, name=<%10s>, VAL_TYPE_FLOAT,  desc=<%20s>, data@%.8lx=%8f\n",
+                    (char *)ctx, name,      desc, (long)data, *(float *)data);
             break;
         case VAL_TYPE_DOUBLE:                                                                            
-            fprintf(stderr, "DEBUG: <%10s> VAL_TYPE_DOUBLE, desc=<%20s>, data@%.8lx=%8f\n",
-                    (char *)ctx,       desc, (long)data, *(double *)data);
+            fprintf(stderr, "DEBUG: <%10s>, name=<%10s>, VAL_TYPE_DOUBLE, desc=<%20s>, data@%.8lx=%8f\n",
+                    (char *)ctx, name,      desc, (long)data, *(double *)data);
             break;
         default: 
-            fprintf(stderr, "DEBUG: <%10s> type = %.8lx,    desc=<%20s>, data@%.8lx\n",
-                    (char *)ctx, type, desc, (long)data);
+            fprintf(stderr, "DEBUG: <%10s>, name=<%10s>, type = %.8lx,    desc=<%20s>, data@%.8lx\n",
+                    (char *)ctx, name, (long)type, desc, (long)data);
     }
 
     return VAL_OK;
@@ -266,8 +266,15 @@
         if ((rc = val_set(v, "bar.double", 3.14159265358979)) != VAL_OK)
             die("val_set  for bar.double using inline data");
 
-        val_apply(v,  dumper, "v" );
-        val_apply(v2, dumper, "v2");
+        // OK val_apply(v,  "", 9, dumper, "v" );
+        // OK val_apply(v2, "", 9, dumper, "v2");
+        // OK val_apply(v,  "", 0, dumper, "v" );
+        // OK val_apply(v,  "bar", 1, dumper, "v" );
+        // OK val_apply(v2,  "", 0, dumper, "v" );
+        // OK val_apply(v,  "", 1, dumper, "v" );
+        // OK val_apply(v,  "foo", 0, dumper, "v" );
+        // OK val_apply(v2,  "char", 2, dumper, "v" );
+        // OK val_apply(v,  "bar.char", 2, dumper, "v" );
 
         if ((rc = val_destroy(v2)) != VAL_OK)
             die("val_destroy 2");


ossp-pkg/lmtp2nntp/lmtp2nntp_val.c 1.2 -> 1.3

--- lmtp2nntp_val.c      2002/01/16 09:46:52     1.2
+++ lmtp2nntp_val.c      2002/01/16 14:19:07     1.3
@@ -276,50 +276,101 @@
 #define VAL_MAXNAME 1024
 
 typedef struct {
+    val_t *val;
+    char *name;
+    int prefixlen;
+    int depth;
     val_cb_t cb;
     void *ctx;
     val_rc_t rc;
 } val_apply_ctx_t;
 
+static val_rc_t val_apply_internal(val_t *, const char *, int, int, val_cb_t, void *);
+
 static int (val_apply_cb)(void *_ctx, const void *keyptr, int keylen, const void *datptr, int datlen)
 {
     val_apply_ctx_t *ctx = (val_apply_ctx_t *)_ctx;
-    val_object_t *obj;
     char name[VAL_MAXNAME+1];
+    int prefixlen;
 
     /* on-the-fly create NUL-terminated name string */
-    if (keylen > VAL_MAXNAME) {
+    if ((strlen(ctx->name) + 1 + keylen) > VAL_MAXNAME) {
         ctx->rc = VAL_ERR_MEM;
         return FALSE;
     }
-    strncpy(name, (char *)keyptr, keylen);
-    *((char *)name+keylen) = '\0';
-
-    /* take object */
-    if (datlen != sizeof(val_object_t)) {
-        ctx->rc = VAL_ERR_ARG;
-        return FALSE;
+    if (strlen(ctx->name) > 0) {
+        strcpy(name, ctx->name);
+        strcat(name, ".");
+        prefixlen = ctx->prefixlen + 1;
     }
-    obj = (val_object_t *)datptr;
-
-    /* execute VAL callback */
-    if ((ctx->rc = ctx->cb(ctx->ctx, name, (obj->type & ~VAL_INLINE), obj->desc, val_storage(obj))) != VAL_OK)
+    else {
+        *name = '\0';
+        prefixlen = ctx->prefixlen;
+    }
+    strncat(name, (char *)keyptr, keylen);
+    if ((ctx->rc = val_apply_internal(ctx->val, name, prefixlen, ctx->depth, ctx->cb, ctx->ctx)) != VAL_OK)
         return FALSE;
-
     return TRUE;
 }
 
-val_rc_t val_apply(val_t *val, val_cb_t cb, void *ctx)
+static val_rc_t val_apply_internal(val_t *val, const char *name, int prefixlen, int depth, val_cb_t cb, void *ctx)
 {
+    val_object_t *obj;
+    val_t *child;
+    char *cp;
+    val_rc_t rc;
     val_apply_ctx_t val_ctx;
 
-    if (val == NULL || cb == NULL)
-        return VAL_ERR_ARG;
-    val_ctx.cb  = cb;
-    val_ctx.ctx = ctx;
-    val_ctx.rc  = VAL_OK;
-    if (!lh_apply(val->lh, val_apply_cb, &val_ctx))
-        return VAL_ERR_SYS;
-    return val_ctx.rc;
+fprintf(stderr, "DEBUG: val_apply_internal name=<%s>, prefixlen=%d, depth=%d\n", name, prefixlen, depth);
+    if (name[prefixlen] == '\0') {
+        /* prefix="foo.bar.", remainder="" */
+        //if (--depth > 0) {
+            val_ctx.val       = val;
+            val_ctx.name      = (char *)name;
+            val_ctx.prefixlen = prefixlen;
+            val_ctx.depth     = depth;
+            val_ctx.cb        = cb;
+            val_ctx.ctx       = ctx;
+            val_ctx.rc        = VAL_OK;
+            if (!lh_apply(val->lh, val_apply_cb, &val_ctx))
+                return VAL_ERR_SYS;
+        //}
+    }
+    else {
+        if ((cp = strchr(name+prefixlen, '.')) != NULL) {
+            /* prefix="foo.bar.", remainder="quux.baz" */
+            if (!lh_lookup(val->lh, name+prefixlen, cp-(name+prefixlen), (void **)&obj, NULL))
+                return VAL_ERR_ARG;
+            if (!(obj->type & VAL_TYPE_VAL))
+                return VAL_ERR_USE;
+            child = *(val_t **)(val_storage(obj));
+            if (depth == 0)
+                return VAL_OK;
+            return val_apply_internal(child, name, cp-name+1, --depth, cb, ctx);
+        }
+        else {
+            /* prefix="foo.bar.quux.", remainder="baz" */
+            if (!lh_lookup(val->lh, name+prefixlen, strlen(name+prefixlen), (void **)&obj, NULL))
+                return VAL_ERR_ARG;
+            /* execute VAL callback */
+            if ((rc = cb(ctx, name, (obj->type & ~VAL_INLINE), obj->desc, val_storage(obj))) != VAL_OK)
+                return rc;
+//fprintf(stderr, "DEBUG: depth=%d obj->type=%.8lx\n", depth, obj->type);
+            if (obj->type & VAL_TYPE_VAL) {
+                if (depth == 0)
+                    return VAL_OK;
+                child = *(val_t **)(val_storage(obj));
+                return val_apply_internal(child, name, strlen(name), --depth, cb, ctx);
+            }
+        }
+    }
+    return VAL_OK;
 }
 
+val_rc_t val_apply(val_t *val, const char *name, int depth, val_cb_t cb, void *ctx)
+{
+    if (val == NULL || name == NULL || depth < 0 || cb == NULL)
+        return VAL_ERR_ARG;
+
+    return val_apply_internal(val, name, 0, depth, cb, ctx);
+}


ossp-pkg/lmtp2nntp/lmtp2nntp_val.h 1.2 -> 1.3

--- lmtp2nntp_val.h      2002/01/16 09:46:52     1.2
+++ lmtp2nntp_val.h      2002/01/16 14:19:07     1.3
@@ -35,7 +35,7 @@
 val_rc_t val_get     (val_t *, const char *, ...);
 val_rc_t val_vset    (val_t *, const char *, va_list);
 val_rc_t val_vget    (val_t *, const char *, va_list);
-val_rc_t val_apply   (val_t *, val_cb_t cb, void *ctx);
+val_rc_t val_apply   (val_t *, const char *, int, val_cb_t, void *);
 
 #endif /* __LMTP2NNTP_VAL_H__ */
 

CVSTrac 2.0.1