OSSP CVS Repository

ossp - Difference in ossp-pkg/var/var.c versions 1.65 and 1.66
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/var/var.c 1.65 -> 1.66

--- var.c        2002/02/28 11:08:58     1.65
+++ var.c        2002/02/28 11:54:25     1.66
@@ -58,9 +58,12 @@
 #define VAR_RC(rv) (rv)
 #endif /* WITH_EX */
 
+typedef char char_class_t[256]; /* 256 == 2 ^ sizeof(unsigned char)*8 */
+
 /* the external context structure */
 struct var_st {
     var_syntax_t   syntax;
+    char_class_t   syntax_nameclass;
     var_cb_value_t cb_value_fct;
     void          *cb_value_ctx;
 };
@@ -201,8 +204,6 @@
 
 /* Routines for the expansion of quoted-pair expressions. */
 
-typedef char char_class_t[256]; /* 256 == 2 ^ sizeof(unsigned char)*8 */
-
 static void expand_range(char a, char b, char_class_t class)
 {
     do {
@@ -1955,38 +1956,15 @@
     const char *input_buf, size_t input_len,
     char **result, size_t *result_len,
     var_cb_value_t lookup, void *lookup_context,
-    const var_syntax_t *config, int force_expand)
+    const var_syntax_t *config, char_class_t nameclass, int force_expand)
 {
-    char_class_t nameclass;
     var_rc_t rc;
     tokenbuf_t output;
 
-    /* Argument sanity checks */
-    if (input_buf == NULL || input_len == 0 ||
-        result == NULL ||
-        lookup == NULL)
-        return VAR_RC(VAR_ERR_INVALID_ARGUMENT);
-
-    /* Optionally use default configuration */
-    if (config == NULL)
-        config = &var_syntax_default;
-
     /* Set the result pointer to the begining of the input buffer so
        that it is correctly initialized in case we fail with an error. */
     *result = (char *)input_buf;
 
-    /* Expand the class description for valid variable names. */
-    if ((rc = expand_character_class(config->name_chars, nameclass)) != VAR_OK)
-        return VAR_RC(rc);
-
-    /* Make sure that the specials defined in the configuration do not
-       appear in the character name class. */
-    if (nameclass[(int)config->delim_init] ||
-        nameclass[(int)config->delim_open] ||
-        nameclass[(int)config->delim_close] ||
-        nameclass[(int)config->escape])
-        return VAR_RC(VAR_ERR_INVALID_CONFIGURATION);
-
     /* Call the parser. */
     tokenbuf_init(&output);
     rc = input(input_buf, input_buf + input_len, config, nameclass,
@@ -2054,6 +2032,7 @@
     ...)
 {
     va_list ap;
+    var_rc_t rc;
 
     if (var == NULL)
         return VAR_RC(VAR_ERR_INVALID_ARGUMENT);
@@ -2071,9 +2050,14 @@
             var->syntax.index_open  = s->index_open;
             var->syntax.index_close = s->index_close;
             var->syntax.index_mark  = s->index_mark;
-            if (var->syntax.name_chars != NULL)
-                free(var->syntax.name_chars);
-            var->syntax.name_chars = strdup(s->name_chars);
+            var->syntax.name_chars  = NULL; /* unused internally */
+            if ((rc = expand_character_class(s->name_chars, var->syntax_nameclass)) != VAR_OK)
+                return VAR_RC(rc);
+            if (   var->syntax_nameclass[(int)var->syntax.delim_init] 
+                || var->syntax_nameclass[(int)var->syntax.delim_open]
+                || var->syntax_nameclass[(int)var->syntax.delim_close]
+                || var->syntax_nameclass[(int)var->syntax.escape])
+                return VAR_RC(VAR_ERR_INVALID_CONFIGURATION);
             break;
         }
         case VAR_CONFIG_CB_VALUE: {
@@ -2156,17 +2140,21 @@
 var_rc_t 
 var_expand(
     var_t *var, 
-    const char *src, size_t srclen, 
-    char **dst, size_t *dstlen, 
+    const char *src_ptr, size_t src_len, 
+    char **dst_ptr, size_t *dst_len, 
     int force_expand)
 {
     /* var_expand_t ctx; */
     var_rc_t rc;
 
+    /* argument sanity checks */
+    if (var == NULL || src_ptr == NULL || src_len == 0 || dst_ptr == NULL)
+        return VAR_RC(VAR_ERR_INVALID_ARGUMENT);
+
     /* ctx.force_expand = force_expand; */
-    rc = internal_expand(src, srclen, dst, dstlen, 
+    rc = internal_expand(src_ptr, src_len, dst_ptr, dst_len, 
                          var->cb_value_fct, var->cb_value_ctx,
-                         &var->syntax, force_expand);
+                         &var->syntax, var->syntax_nameclass, force_expand);
     return rc;
 }
 

CVSTrac 2.0.1