OSSP CVS Repository

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

Check-in Number: 1919
Date: 2002-Feb-28 13:57:55 (local)
2002-Feb-28 12:57:55 (UTC)
User:thl
Branch:
Comment: integrated new lib_var API; lib_var patch fixed expansion problem
Tickets:
Inspections:
Files:
ossp-pkg/lmtp2nntp/fixme.h      1.18 -> 1.19     3 inserted, 0 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp_config.c      1.58 -> 1.59     46 inserted, 94 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp_main.c      1.41 -> 1.42     83 inserted, 6 deleted

ossp-pkg/lmtp2nntp/fixme.h 1.18 -> 1.19

--- fixme.h      2002/02/27 09:34:41     1.18
+++ fixme.h      2002/02/28 12:57:55     1.19
@@ -6,6 +6,7 @@
 #define __FIXME_H__
 
 #include <val.h>
+#include <var.h>
 #include <sa.h>
 struct acl {
     char      *acl;
@@ -106,6 +107,8 @@
     struct          session session;
     msg_t          *msg;
     struct utsname  uname;
+    var_t          *config_varregex;
+    var_t          *config_varctx;
 } lmtp2nntp_t;
 
 #define ERR_EXECUTION 1


ossp-pkg/lmtp2nntp/lmtp2nntp_config.c 1.58 -> 1.59

--- lmtp2nntp_config.c   2002/02/27 12:17:34     1.58
+++ lmtp2nntp_config.c   2002/02/28 12:57:55     1.59
@@ -127,6 +127,18 @@
     exit(0);
 
 }
+
+static var_syntax_t syntax_regex = {
+    '\\',         /* escape        */ 
+    '$',          /* varinit       */ 
+    '{',          /* startdelim    */ 
+    '}',          /* enddelim      */ 
+    NUL,          /* startindex    */
+    NUL,          /* endindex      */
+    NUL,          /* current_index */
+    "0-9"         /* namechars     */
+};
+
 void config_context(lmtp2nntp_t *ctx)
 {
     ex_t ex;
@@ -655,6 +667,19 @@
                     }
                     hrNew = NULL; /* release cleanup responsibility */
                 }
+                /* establish variable expansion context */
+                {
+                    var_rc_t rc;
+
+                    if ((rc = var_create(&ctx->config_varregex)) != VAR_OK) {
+                        log2(ctx, ERROR, "option --headerrule, create regex context failed with %s (%d)", var_strerror(ctx->config_varctx, rc, &cp) == VAR_OK ? cp : "Unknown Error", rc);
+                        throw(0,0,0);
+                    }
+                    if ((rc = var_config(ctx->config_varregex, VAR_CONFIG_SYNTAX, &syntax_regex)) != VAR_OK) {
+                        log2(ctx, ERROR, "option --headerrule, config regex context failed with %s (%d)", var_strerror(ctx->config_varctx, rc, &cp) == VAR_OK ? cp : "Unknown Error", rc);
+                        throw(0,0,0);
+                    }
+                }
             }
         }
         cleanup {
@@ -1288,73 +1313,6 @@
     }
     return (headerdata_t *)hdNew;
 }
-#if 0
-#endif
-
-static var_config_t ctx_lookup_cfg = {
-    '$',          /* varinit       */ 
-    '{',          /* startdelim    */ 
-    '}',          /* enddelim      */ 
-    '[',          /* startindex    */ 
-    ']',          /* endindex      */ 
-    '#',          /* current_index */ 
-    '\\',         /* escape        */ 
-    "a-zA-Z0-9_.-" /* namechars     */ 
-};
-
-static var_rc_t ctx_lookup(
-    void *_ctx, 
-    const char *var_ptr, size_t var_len, int var_idx,
-    const char **val_ptr, size_t *val_len, size_t *val_size)
-{
-    lmtp2nntp_t *ctx = (lmtp2nntp_t *)_ctx;
-    /*FIXME
-    const char *name;
-    size_t len;
-    */
-    var_rc_t rc;
-    char *cp;
-    optionval_t *ov;
-
-    log2(ctx, DEBUG, "ctx_lookup variable \"%s\" (%d)", var_ptr, var_len);
-    rc = VAR_ERR_UNDEFINED_VARIABLE;
-    if (strncasecmp(var_ptr, "option.", strlen("option.")) == 0) {
-        cp = str_dupex(var_ptr, var_len);
-        if (val_get(ctx->val, cp, &ov) == VAL_OK) {
-            //log3(ctx, DEBUG, "FIXME var_idx=%d, ov->type=%d, ov->ndata=%d", var_idx, ov->type, ov->ndata);
-            if ((var_idx == 0) && (ov->ndata == 1) && (ov->type == OPT_SINGLE)) { /* request first/only single value */
-                *val_ptr = ov->data.s;
-                *val_len = strlen(ov->data.s);
-                *val_size = 0;
-                rc = VAR_OK;
-            }
-            else if ((var_idx == 0) && (ov->ndata == 1) && (ov->type == OPT_FLAG)) { /* request first/only single value */
-                *val_ptr = ov->data.f == TRUE ? "yes" : "no";
-                *val_len = strlen(ov->data.s);
-                *val_size = 0;
-                rc = VAR_OK;
-            }
-            else if ((var_idx < ov->ndata) && (ov->type == OPT_MULTI)) { /* request second+ from multi value */
-                *val_ptr = ov->data.m[var_idx];
-                *val_len = strlen(ov->data.m[var_idx]);
-                *val_size = 0;
-                rc = VAR_OK;
-            }
-        }
-        free(cp);
-    }
-    else if (strncasecmp(var_ptr, "xyz", var_len) == 0) {
-        *val_ptr = "Hello, World!";
-        *val_len = strlen("Hello, World!");
-        *val_size = 0;
-        rc = VAR_OK;
-    }
-    if (rc == VAR_OK)
-        log4(ctx, DEBUG, "ctx_lookup variable \"%s\" (%d) ok: result is \"%s\" (%d)", var_ptr, var_len, *val_ptr, *val_len);
-    else
-        log3(ctx, DEBUG, "ctx_lookup variable \"%s\" (%d) failed: %s", var_ptr, var_len, var_strerror(rc));
-    return rc;
-}
 
 struct regex_ctx_st; //FIXME go into a header!
 typedef struct regex_ctx_st regex_ctx_t;
@@ -1365,29 +1323,14 @@
     l2_channel_t  *l2;
 };
 
-static var_config_t regex_lookup_cfg = {
-    '$',          /* varinit       */ 
-    '{',          /* startdelim    */ 
-    '}',          /* enddelim      */ 
-    '[',          /* startindex    */ //FIXME
-    ']',          /* endindex      */ //FIXME
-    '#',          /* current_index */ //FIXME
-    '\\',         /* escape        */ 
-    "0-9"         /* namechars     */ //FIXME bug in lib_val
-};
-
 static var_rc_t regex_lookup(
-    void *_ctx, 
+    var_t *var, void *_ctx, 
     const char *var_ptr, size_t var_len, int var_idx,
     const char **val_ptr, size_t *val_len, size_t *val_size)
 {
     regex_ctx_t *ctx = (regex_ctx_t *)_ctx;
-    /*FIXME
-    const char *name;
-    size_t len;
-    char *cp;
-    */
     var_rc_t rc;
+    char *cp;
     int i;
 
     log2(ctx, DEBUG, "rgx_lookup variable \"%s\" (%d)", var_ptr, var_len);
@@ -1402,7 +1345,7 @@
     if (rc == VAR_OK)
         log4(ctx, DEBUG, "rgx_lookup variable \"%s\" (%d) ok: result is \"%s\" (%d)", var_ptr, var_len, *val_ptr, *val_len);
     else
-        log3(ctx, DEBUG, "rgx_lookup variable \"%s\" (%d) failed: %s", var_ptr, var_len, var_strerror(rc));
+        log4(ctx, DEBUG, "rgx_lookup variable \"%s\" (%d) failed: %s (%d)", var_ptr, var_len, var_strerror(var, rc, &cp) == VAR_OK ? cp : "Unknown Error", rc);
     return rc;
 }
 
@@ -1574,6 +1517,7 @@
     regex_ctx_t *regex_ctx;
 #define OVECSIZE 30
     int            ovec[OVECSIZE];
+    var_rc_t rc; char *cp; //FIXME what a bad name, it's not the returncode of this function
 
     { //FIXME debug code block
         int i;
@@ -1599,6 +1543,10 @@
     regex_ctx->acpMatch = NULL;
     regex_ctx->l2_env = ctx->l2_env;
     regex_ctx->l2 = ctx->l2;
+    if ((rc = var_config(ctx->config_varregex, VAR_CONFIG_CB_VALUE, regex_lookup, regex_ctx)) != VAR_OK) {
+        log2(ctx, ERROR, "configure regex callback failed with %s (%d)", var_strerror(ctx->config_varctx, rc, &cp) == VAR_OK ? cp : "Unknown Error", rc);
+        throw(0,0,0);
+    }
     for (hrI = ctx->option_firstheaderrule; hrI != NULL; hrI = hrI->next) { /* for each rule */
         //log1(ctx, DEBUG, "FIXME trace loop hrI=%.8lx", hrI);
         { //FIXME debug code block
@@ -1641,9 +1589,9 @@
                         var_rc_t var_rc;
                         char *res_ptr;
                         log1(ctx, DEBUG, "expanding regex references in headername '%s'", hrI->header);
-                        if ((var_rc = var_expand(hrI->header, strlen(hrI->header), &res_ptr, NULL,
-                                                 regex_lookup, regex_ctx, &regex_lookup_cfg, FALSE)) != VAR_OK) {
-                            log2(ctx, ERROR, "expansion of '%s' failed: %s", hrI->header, var_strerror(var_rc));
+                        //if ((var_rc = var_expand(hrI->header, strlen(hrI->header), &res_ptr, NULL, regex_lookup, regex_ctx, &regex_lookup_cfg, FALSE)) != VAR_OK) {
+                        if ((var_rc = var_expand(ctx->config_varregex, hrI->header, strlen(hrI->header), &res_ptr, NULL, FALSE)) != VAR_OK) {
+                            log3(ctx, ERROR, "expansion of '%s' failed: %s", hrI->header, var_strerror(ctx->config_varctx, rc, &cp) == VAR_OK ? cp : "Unknown Error", rc);
                         }
                         log1(ctx, DEBUG, "expansion result '%s'", res_ptr);
                         hdNew->name = res_ptr; //FIXME rename ->header to ->name
@@ -1659,9 +1607,9 @@
                             var_rc_t var_rc;
                             char *res_ptr;
                             log1(ctx, DEBUG, "expanding regex references in header value '%s'", hrI->val);
-                            if ((var_rc = var_expand(hrI->val, strlen(hrI->val), &res_ptr, NULL,
-                                                     regex_lookup, regex_ctx, &regex_lookup_cfg, FALSE)) != VAR_OK) {
-                                log2(ctx, ERROR, "expansion of '%s' failed: %s", hrI->val, var_strerror(var_rc));
+                            //if ((var_rc = var_expand(hrI->val, strlen(hrI->val), &res_ptr, NULL, regex_lookup, regex_ctx, &regex_lookup_cfg, FALSE)) != VAR_OK) {
+                            if ((var_rc = var_expand(ctx->config_varregex, hrI->val, strlen(hrI->val), &res_ptr, NULL, FALSE)) != VAR_OK) {
+                                log3(ctx, ERROR, "expansion of '%s' failed: %s", hrI->val, var_strerror(ctx->config_varctx, rc, &cp) == VAR_OK ? cp : "Unknown Error", rc);
                             }
                             log1(ctx, DEBUG, "expansion result '%s'", res_ptr);
                             cp = res_ptr;
@@ -1671,9 +1619,13 @@
                             var_rc_t var_rc;
                             char *res_ptr;
                             log1(ctx, DEBUG, "expanding variables in header value '%s'", hrI->val);
-                            if ((var_rc = var_expand(cp, strlen(cp), &res_ptr, NULL,
-                                                     ctx_lookup, ctx, &ctx_lookup_cfg, FALSE)) != VAR_OK) {
-                                log2(ctx, ERROR, "expansion of '%s' failed: %s", cp, var_strerror(var_rc));
+                            var_rc_t var_expand(var_t *var, const char *src_ptr,
+                                   size_t src_len, char **dst_ptr, size_t *dst_len, int
+                                          force_expand);
+                            
+                            //if ((var_rc = var_expand(cp, strlen(cp), &res_ptr, NULL, ctx_lookup, ctx, &ctx_lookup_cfg, FALSE)) != VAR_OK) {
+                            if ((var_rc = var_expand(ctx->config_varctx, cp, strlen(cp), &res_ptr, NULL, FALSE)) != VAR_OK) {
+                                log3(ctx, ERROR, "expansion of '%s' failed: %s", cp, var_strerror(ctx->config_varctx, rc, &cp) == VAR_OK ? cp : "Unknown Error", rc);
                             }
                             log1(ctx, DEBUG, "expansion result '%s'", res_ptr);
                             hdNew->data.s = res_ptr;


ossp-pkg/lmtp2nntp/lmtp2nntp_main.c 1.41 -> 1.42

--- lmtp2nntp_main.c     2002/02/14 11:03:52     1.41
+++ lmtp2nntp_main.c     2002/02/28 12:57:55     1.42
@@ -115,17 +115,18 @@
 static void resetsession(struct session *session);
 int groupmatch(char *, size_t, char *);
 
-static var_config_t ctx_lookup_cfg = {
+static var_syntax_t syntax_ctx = {
+    '\\',         /* escape        */ 
     '$',          /* varinit       */ 
     '{',          /* startdelim    */ 
     '}',          /* enddelim      */ 
     '[',          /* startindex    */ 
     ']',          /* endindex      */ 
     '#',          /* current_index */ 
-    '\\',         /* escape        */ 
-    "a-zA-Z0-9_.-" /* namechars     */ 
+    "a-zA-Z0-9.-" /* namechars     */ 
 };
 
+#if 0
 static var_rc_t ctx_lookup(
     void *_ctx, 
     const char *var_ptr, size_t var_len, int var_idx,
@@ -181,6 +182,59 @@
              var_ptr /* FIXME: NUL-termination? */, var_len, var_strerror(rc));
     return rc;
 }
+#endif
+
+static var_rc_t ctx_lookup(
+    var_t *var,
+    void *_ctx, 
+    const char *var_ptr, size_t var_len, int var_idx,
+    const char **val_ptr, size_t *val_len, size_t *val_size)
+{
+    lmtp2nntp_t *ctx = (lmtp2nntp_t *)_ctx;
+    var_rc_t rc;
+    char *cp;
+    optionval_t *ov;
+
+    log2(ctx, DEBUG, "ctx_lookup variable \"%s\" (%d)", var_ptr, var_len);
+    rc = VAR_ERR_UNDEFINED_VARIABLE;
+    if (strncasecmp(var_ptr, "option.", strlen("option.")) == 0) {
+        cp = str_dupex(var_ptr, var_len);
+        if (val_get(ctx->val, cp, &ov) == VAL_OK) {
+            //log3(ctx, DEBUG, "FIXME var_idx=%d, ov->type=%d, ov->ndata=%d", var_idx, ov->type, ov->ndata);
+            if ((var_idx == 0) && (ov->ndata == 1) && (ov->type == OPT_SINGLE)) { /* request first/only single value */
+                *val_ptr = ov->data.s;
+                *val_len = strlen(ov->data.s);
+                *val_size = 0;
+                rc = VAR_OK;
+            }
+            else if ((var_idx == 0) && (ov->ndata == 1) && (ov->type == OPT_FLAG)) { /* request first/only single value */
+                *val_ptr = ov->data.f == TRUE ? "yes" : "no";
+                *val_len = strlen(ov->data.s);
+                *val_size = 0;
+                rc = VAR_OK;
+            }
+            else if ((var_idx < ov->ndata) && (ov->type == OPT_MULTI)) { /* request second+ from multi value */
+                *val_ptr = ov->data.m[var_idx];
+                *val_len = strlen(ov->data.m[var_idx]);
+                *val_size = 0;
+                rc = VAR_OK;
+            }
+        }
+        free(cp);
+    }
+    else if (strncasecmp(var_ptr, "xyz", var_len) == 0) {
+        *val_ptr = "Hello, World!";
+        *val_len = strlen("Hello, World!");
+        *val_size = 0;
+        rc = VAR_OK;
+    }
+    if (rc == VAR_OK)
+        log4(ctx, DEBUG, "ctx_lookup variable \"%s\" (%d) ok: result is \"%s\" (%d)", var_ptr, var_len, *val_ptr, *val_len);
+    else
+        log4(ctx, DEBUG, "ctx_lookup variable \"%s\" (%d) failed: %s (%d)", var_ptr, var_len, var_strerror(var, rc, &cp) == VAR_OK ? cp : "Unknown Error", rc);
+    return rc;
+}
+
 
 
 static void lmtp_gfs_ns(struct ns *);
@@ -385,6 +439,8 @@
     initsession(&ctx->session);
     ctx->msg = NULL;
     memset(&ctx->uname, 0, sizeof(struct utsname));
+    ctx->config_varregex = NULL;
+    ctx->config_varctx = NULL;
     
     /* fill in application context */
     if (val_create(&ctx->val) != VAL_OK)
@@ -395,6 +451,24 @@
     }
     ctx->progname = strdup(argv[0]);
 
+    /* establish variable expansion context */
+    {
+        var_rc_t rc;
+        char *cp;
+
+        if ((rc = var_create(&ctx->config_varctx)) != VAR_OK) {
+            fprintf(stderr, "%s:Error: create varctx context failed with %s (%d)", ctx->progname, var_strerror(ctx->config_varctx, rc, &cp) == VAR_OK ? cp : "Unknown Error", rc);
+            CU(ERR_EXECUTION);
+        }
+        if ((rc = var_config(ctx->config_varctx, VAR_CONFIG_SYNTAX, &syntax_ctx)) != VAR_OK) {
+            fprintf(stderr, "%s:Error: config varctx context failed with %s (%d)", ctx->progname, var_strerror(ctx->config_varctx, rc, &cp) == VAR_OK ? cp : "Unknown Error", rc);
+            CU(ERR_EXECUTION);
+        }
+        if ((rc = var_config(ctx->config_varctx, VAR_CONFIG_CB_VALUE, ctx_lookup, ctx)) != VAR_OK) {
+            fprintf(stderr, "%s:Error: config varctx callback failed with %s (%d)", ctx->progname, var_strerror(ctx->config_varctx, rc, &cp) == VAR_OK ? cp : "Unknown Error", rc);
+            CU(ERR_EXECUTION);
+        }
+    }
     /* read in the arguments */
     (void)option_create(&o, ctx->val); /* FIXME */
     (void)option_parse(o, argc, argv);
@@ -658,6 +732,10 @@
         free(ctx->progname);
     if (ctx->azGroupargs != NULL)
         free(ctx->azGroupargs);
+    if (ctx->config_varregex != NULL)
+        var_destroy(ctx->config_varregex);
+    if (ctx->config_varctx != NULL)
+        var_destroy(ctx->config_varctx);
     if (ctx != NULL)
         free(ctx);
     str_parse(NULL, NULL);
@@ -1454,9 +1532,8 @@
     while ((cp = argz_next(ctx->azHeaderValuePairs, ctx->asHeaderValuePairs, cp)) != NULL) {
         var_rc_t var_rc;
         char *res_ptr;
-        if ((var_rc = var_expand(cp, strlen(cp), &res_ptr, NULL,
-                                 ctx_lookup, ctx, &ctx_lookup_cfg, TRUE)) != VAR_OK) {
-            log2(ctx, ERROR, "expansion of '%s' failed: %s", cp, var_strerror(var_rc));
+        if ((var_rc = var_expand(ctx->config_varctx, cp, strlen(cp), &res_ptr, NULL, TRUE)) != VAR_OK) {
+            log3(ctx, ERROR, "expansion of '%s' failed: %s (%d)", cp, var_strerror(ctx->config_varctx, rc, &cp) == VAR_OK ? cp : "Unknown Error", rc);
             continue;
         }
         log1(ctx, DEBUG, "adding expanded header: \"%s\"", res_ptr);

CVSTrac 2.0.1