OSSP CVS Repository

ossp - Difference in ossp-pkg/lmtp2nntp/lmtp2nntp_config.c versions 1.58 and 1.59
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

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;

CVSTrac 2.0.1