OSSP CVS Repository

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

Check-in Number: 1260
Date: 2001-Nov-07 14:05:20 (local)
2001-Nov-07 13:05:20 (UTC)
User:rse
Branch:
Comment: Hell, I've seldom seen that it is needed to prepare and adjust such a lot of subtle details of existing code in order to make a new feature implementable in a straight-forward way. Anyway, here comes one more preparation change for the forthcoming channel tree specification parser:

- change l2_util_setparam() to take an l2_env_t parameter which allows the function to report better error messages.

- completely rewrite l2_util_setparam() to support calls l2_channel_configure(ch, "n1=v1,n2=v2,n3=v3") and/or l2_channel_configure(ch, "n1=%x,n2=%x,n3=%x", v1, v2, v3) instead of l2_channel_configure(ch, "n1,n2,n3", v1, v2, v3)

  This is both a step forward to make the interface of
  l2_channel_configure() more flexible (because one now can directly
  inline values instead of having them to be passed explicitly) and
  allows the spec parser not having to know the type (integer, floating
  point or string) of a parameter (which is important if one wants the
  parser to be independent of the implementing channel handlers).
Tickets:
Inspections:
Files:
ossp-pkg/l2/l2.h.in      1.19 -> 1.20     3 inserted, 9 deleted
ossp-pkg/l2/l2_ch_buffer.c      1.33 -> 1.34     3 inserted, 1 deleted
ossp-pkg/l2/l2_ch_fd.c      1.11 -> 1.12     3 inserted, 1 deleted
ossp-pkg/l2/l2_ch_file.c      1.18 -> 1.19     7 inserted, 5 deleted
ossp-pkg/l2/l2_ch_filter.c      1.13 -> 1.14     4 inserted, 5 deleted
ossp-pkg/l2/l2_ch_irc.c      1.3 -> 1.4     14 inserted, 12 deleted
ossp-pkg/l2/l2_ch_pipe.c      1.27 -> 1.28     8 inserted, 4 deleted
ossp-pkg/l2/l2_ch_prefix.c      1.17 -> 1.18     5 inserted, 3 deleted
ossp-pkg/l2/l2_ch_smtp.c      1.7 -> 1.8     12 inserted, 10 deleted
ossp-pkg/l2/l2_ch_socket.c      1.33 -> 1.34     7 inserted, 5 deleted
ossp-pkg/l2/l2_ch_syslog.c      1.26 -> 1.27     10 inserted, 8 deleted
ossp-pkg/l2/l2_test.c      1.42 -> 1.43     59 inserted, 58 deleted
ossp-pkg/l2/l2_ut_param.c      1.5 -> 1.6     126 inserted, 51 deleted

ossp-pkg/l2/l2.h.in 1.19 -> 1.20

--- l2.h.in      2001/11/07 11:37:18     1.19
+++ l2.h.in      2001/11/07 13:05:20     1.20
@@ -131,15 +131,9 @@
 
 /* list of types for storing data */
 typedef enum {
-    L2_TYPE_CHAR,
-    L2_TYPE_SHORT,
     L2_TYPE_INT,
-    L2_TYPE_LONG,
-    L2_TYPE_FLOAT,
-    L2_TYPE_DOUBLE,
-    L2_TYPE_STRING,
-    L2_TYPE_CHARPTR,
-    L2_TYPE_VOIDPTR
+    L2_TYPE_FLT,
+    L2_TYPE_STR
 } l2_type_t;
 
 /* parameter specification */
@@ -234,7 +228,7 @@
 l2_result_t   l2_channel_env        (l2_channel_t *ch, l2_env_t **env);
 
 /* utility operations */
-l2_result_t   l2_util_setparams     (l2_param_t p[], const char *fmt, va_list ap);
+l2_result_t   l2_util_setparams     (l2_env_t *env, l2_param_t p[], const char *fmt, va_list ap);
 l2_result_t   l2_util_l2s           (char *string,       size_t maxlen, int sep, unsigned int  levelmask);
 l2_result_t   l2_util_s2l           (const char *string, size_t maxlen, int sep, unsigned int *levelmask);
 l2_result_t   l2_util_fmt_string    (l2_context_t *, const char, const char *, char *, size_t, size_t *, va_list *);


ossp-pkg/l2/l2_ch_buffer.c 1.33 -> 1.34

--- l2_ch_buffer.c       2001/11/07 11:37:18     1.33
+++ l2_ch_buffer.c       2001/11/07 13:05:20     1.34
@@ -160,13 +160,15 @@
     l2_ch_buffer_t *cfg = (l2_ch_buffer_t *)ctx->vp;
     l2_param_t pa[4];
     l2_result_t rv;
+    l2_env_t *env;
 
     /* feed and call generic parameter parsing engine */
     L2_PARAM_SET(pa[0], size,       INT, &cfg->bufsize);
     L2_PARAM_SET(pa[1], interval,   INT, &cfg->bufinterval);
     L2_PARAM_SET(pa[2], levelflush, INT, &cfg->levelflush);
     L2_PARAM_END(pa[3]);
-    rv = l2_util_setparams(pa, fmt, ap);
+    l2_channel_env(ch, &env);
+    rv = l2_util_setparams(env, pa, fmt, ap);
     if (cfg->bufinterval == -1L) /* -1 is reserved by L2 */
         return L2_ERR_ARG;       /* set_alarm() uses it  */
 


ossp-pkg/l2/l2_ch_fd.c 1.11 -> 1.12

--- l2_ch_fd.c   2001/11/07 11:37:18     1.11
+++ l2_ch_fd.c   2001/11/07 13:05:20     1.12
@@ -59,6 +59,7 @@
     l2_ch_fd_t *cfg;
     l2_param_t pa[1]; 
     l2_result_t rv;
+    l2_env_t *env;
 
     /* parameter checks */
     if ((cfg = (l2_ch_fd_t *)ctx->vp) == NULL)
@@ -67,7 +68,8 @@
     /* feed and call generic parameter parsing engine */
     L2_PARAM_SET(pa[0], filedescriptor, INT, &cfg->fd);
     L2_PARAM_END(pa[1]);
-    rv = l2_util_setparams(pa, fmt, ap);
+    l2_channel_env(ch, &env);
+    rv = l2_util_setparams(env, pa, fmt, ap);
 
     return rv;
 }


ossp-pkg/l2/l2_ch_file.c 1.18 -> 1.19

--- l2_ch_file.c 2001/11/07 11:37:18     1.18
+++ l2_ch_file.c 2001/11/07 13:05:20     1.19
@@ -38,7 +38,7 @@
     int   fd;
     char *path;
     int   append;
-    long  perm;
+    int   perm;
 } l2_ch_file_t;
 
 /* create channel */
@@ -68,13 +68,15 @@
     l2_ch_file_t *cfg = (l2_ch_file_t *)ctx->vp;
     l2_param_t pa[4]; 
     l2_result_t rv;
+    l2_env_t *env;
 
     /* feed and call generic parameter parsing engine */
-    L2_PARAM_SET(pa[0], path,   CHARPTR, &cfg->path);
-    L2_PARAM_SET(pa[1], append, INT,     &cfg->append);
-    L2_PARAM_SET(pa[2], perm,   LONG,    &cfg->perm);
+    L2_PARAM_SET(pa[0], path,   STR, &cfg->path);
+    L2_PARAM_SET(pa[1], append, INT, &cfg->append);
+    L2_PARAM_SET(pa[2], perm,   INT, &cfg->perm);
     L2_PARAM_END(pa[3]);
-    rv = l2_util_setparams(pa, fmt, ap);
+    l2_channel_env(ch, &env);
+    rv = l2_util_setparams(env, pa, fmt, ap);
 
     return rv;
 }


ossp-pkg/l2/l2_ch_filter.c 1.13 -> 1.14

--- l2_ch_filter.c       2001/11/07 11:37:18     1.13
+++ l2_ch_filter.c       2001/11/07 13:05:20     1.14
@@ -70,17 +70,17 @@
     int nErrorOffset;
 
     /* feed and call generic parameter parsing engine */
-    L2_PARAM_SET(pa[0], regex,  STRING, &cfg->szRegex);
-    L2_PARAM_SET(pa[1], negate, INT,    &cfg->bNegate);
+    L2_PARAM_SET(pa[0], regex,  STR, &cfg->szRegex);
+    L2_PARAM_SET(pa[1], negate, INT, &cfg->bNegate);
     L2_PARAM_END(pa[2]);
-    if ((rv = l2_util_setparams(pa, fmt, ap)) != L2_OK)
+    l2_channel_env(ch, &env);
+    if ((rv = l2_util_setparams(env, pa, fmt, ap)) != L2_OK)
         return rv;
 
     /* translate regular expression into finite state machine */ 
     if (cfg->szRegex != NULL) {
         /* compile regular expression into FSM */
         if ((cfg->pcreRegex = pcre_compile(cfg->szRegex, 0, &szError, &nErrorOffset, NULL)) == NULL) {
-            l2_channel_env(ch, &env);
             l2_env_errorinfo(env, L2_ERR_ARG, "%s ('%c')", szError, cfg->szRegex[nErrorOffset]);
             return L2_ERR_ARG;
         }
@@ -89,7 +89,6 @@
         if (szError != NULL) {
             free(cfg->pcreRegex);
             cfg->pcreRegex = NULL;
-            l2_channel_env(ch, &env);
             l2_env_errorinfo(env, L2_ERR_ARG, "%s", szError);
             return L2_ERR_ARG;
         }


ossp-pkg/l2/l2_ch_irc.c 1.3 -> 1.4

--- l2_ch_irc.c  2001/11/07 11:37:18     1.3
+++ l2_ch_irc.c  2001/11/07 13:05:20     1.4
@@ -99,21 +99,23 @@
     l2_ch_irc_t *cfg = (l2_ch_irc_t *)ctx->vp;
     l2_param_t pa[12]; 
     l2_result_t rv;
+    l2_env_t *env;
 
     /* feed and call generic parameter parsing engine */
-    L2_PARAM_SET(pa[0],  progname,  STRING, &cfg->cpLocalProg);
-    L2_PARAM_SET(pa[1],  localhost, STRING, &cfg->cpLocalHost);
-    L2_PARAM_SET(pa[2],  localuser, STRING, &cfg->cpLocalUser);
-    L2_PARAM_SET(pa[3],  nickname,  STRING, &cfg->cpNickname);
-    L2_PARAM_SET(pa[4],  username,  STRING, &cfg->cpUsername);
-    L2_PARAM_SET(pa[5],  realname,  STRING, &cfg->cpRealname);
-    L2_PARAM_SET(pa[6],  channel,   STRING, &cfg->cpChannel);
-    L2_PARAM_SET(pa[7],  join,      INT,    &cfg->bJoin);
-    L2_PARAM_SET(pa[8],  host,      STRING, &cfg->cpHost);
-    L2_PARAM_SET(pa[9],  port,      STRING, &cfg->cpPort);
-    L2_PARAM_SET(pa[10], timeout,   INT,    &cfg->nTimeout);
+    L2_PARAM_SET(pa[0],  progname,  STR, &cfg->cpLocalProg);
+    L2_PARAM_SET(pa[1],  localhost, STR, &cfg->cpLocalHost);
+    L2_PARAM_SET(pa[2],  localuser, STR, &cfg->cpLocalUser);
+    L2_PARAM_SET(pa[3],  nickname,  STR, &cfg->cpNickname);
+    L2_PARAM_SET(pa[4],  username,  STR, &cfg->cpUsername);
+    L2_PARAM_SET(pa[5],  realname,  STR, &cfg->cpRealname);
+    L2_PARAM_SET(pa[6],  channel,   STR, &cfg->cpChannel);
+    L2_PARAM_SET(pa[7],  join,      INT, &cfg->bJoin);
+    L2_PARAM_SET(pa[8],  host,      STR, &cfg->cpHost);
+    L2_PARAM_SET(pa[9],  port,      STR, &cfg->cpPort);
+    L2_PARAM_SET(pa[10], timeout,   INT, &cfg->nTimeout);
     L2_PARAM_END(pa[11]);
-    rv = l2_util_setparams(pa, fmt, ap);
+    l2_channel_env(ch, &env);
+    rv = l2_util_setparams(env, pa, fmt, ap);
 
     return rv;
 }


ossp-pkg/l2/l2_ch_pipe.c 1.27 -> 1.28

--- l2_ch_pipe.c 2001/11/07 11:37:18     1.27
+++ l2_ch_pipe.c 2001/11/07 13:05:20     1.28
@@ -176,13 +176,15 @@
     l2_result_t rv;
     char *szMode = NULL;
     char *szRel  = NULL;
+    l2_env_t *env;
 
     /* feed and call generic parameter parsing engine */
-    L2_PARAM_SET(pa[0], execmode, CHARPTR, &szMode); /* mode direct or shell  */
-    L2_PARAM_SET(pa[1], runtime,  CHARPTR, &szRel);  /* continuous or oneshot */
-    L2_PARAM_SET(pa[2], path,     STRING,  &cfg->szCmdpath); /* path of cmd   */
+    L2_PARAM_SET(pa[0], execmode, STR, &szMode); /* mode direct or shell  */
+    L2_PARAM_SET(pa[1], runtime,  STR, &szRel);  /* continuous or oneshot */
+    L2_PARAM_SET(pa[2], path,     STR, &cfg->szCmdpath); /* path of cmd   */
     L2_PARAM_END(pa[3]);
-    if ((rv = l2_util_setparams(pa, fmt, ap)) != L2_OK)
+    l2_channel_env(ch, &env);
+    if ((rv = l2_util_setparams(env, pa, fmt, ap)) != L2_OK)
         return rv;
 
     if (szMode != NULL) {
@@ -192,6 +194,7 @@
             cfg->iMode = L2_PIPE_EXECMODE_SHELL;
         else
             return L2_ERR_ARG;
+        free(szMode);
     }
 
     if (szRel != NULL) {
@@ -201,6 +204,7 @@
             cfg->iRtme = L2_PIPE_RUNTIME_ONESHOT;
         else
             return L2_ERR_ARG;
+        free(szRel);
     }
 
     return L2_OK;


ossp-pkg/l2/l2_ch_prefix.c 1.17 -> 1.18

--- l2_ch_prefix.c       2001/11/07 11:37:18     1.17
+++ l2_ch_prefix.c       2001/11/07 13:05:20     1.18
@@ -64,12 +64,14 @@
     l2_ch_prefix_t *cfg = (l2_ch_prefix_t *)ctx->vp;
     l2_param_t pa[3]; 
     l2_result_t rv;
+    l2_env_t *env;
 
     /* feed and call generic parameter parsing engine */
-    L2_PARAM_SET(pa[0], prefix,  STRING, &cfg->prefix);
-    L2_PARAM_SET(pa[1], timezone, STRING, &cfg->timezone);
+    L2_PARAM_SET(pa[0], prefix,   STR, &cfg->prefix);
+    L2_PARAM_SET(pa[1], timezone, STR, &cfg->timezone);
     L2_PARAM_END(pa[2]);
-    rv = l2_util_setparams(pa, fmt, ap);
+    l2_channel_env(ch, &env);
+    rv = l2_util_setparams(env, pa, fmt, ap);
 
     /* argument consistency check */
     if (rv == L2_OK) {


ossp-pkg/l2/l2_ch_smtp.c 1.7 -> 1.8

--- l2_ch_smtp.c 2001/11/07 11:37:18     1.7
+++ l2_ch_smtp.c 2001/11/07 13:05:20     1.8
@@ -93,19 +93,21 @@
     l2_ch_smtp_t *cfg = (l2_ch_smtp_t *)ctx->vp;
     l2_param_t pa[10]; 
     l2_result_t rv;
+    l2_env_t *env;
 
     /* feed and call generic parameter parsing engine */
-    L2_PARAM_SET(pa[0], progname,  STRING, &cfg->cpLocalProg);
-    L2_PARAM_SET(pa[1], localhost, STRING, &cfg->cpLocalHost);
-    L2_PARAM_SET(pa[2], localuser, STRING, &cfg->cpLocalUser);
-    L2_PARAM_SET(pa[3], from,      STRING, &cfg->cpFrom);
-    L2_PARAM_SET(pa[4], rcpt,      STRING, &cfg->cpRcpt);
-    L2_PARAM_SET(pa[5], subject,   STRING, &cfg->cpSubject);
-    L2_PARAM_SET(pa[6], host,      STRING, &cfg->cpHost);
-    L2_PARAM_SET(pa[7], port,      STRING, &cfg->cpPort);
-    L2_PARAM_SET(pa[8], timeout,   INT,    &cfg->nTimeout);
+    L2_PARAM_SET(pa[0], progname,  STR, &cfg->cpLocalProg);
+    L2_PARAM_SET(pa[1], localhost, STR, &cfg->cpLocalHost);
+    L2_PARAM_SET(pa[2], localuser, STR, &cfg->cpLocalUser);
+    L2_PARAM_SET(pa[3], from,      STR, &cfg->cpFrom);
+    L2_PARAM_SET(pa[4], rcpt,      STR, &cfg->cpRcpt);
+    L2_PARAM_SET(pa[5], subject,   STR, &cfg->cpSubject);
+    L2_PARAM_SET(pa[6], host,      STR, &cfg->cpHost);
+    L2_PARAM_SET(pa[7], port,      STR, &cfg->cpPort);
+    L2_PARAM_SET(pa[8], timeout,   INT, &cfg->nTimeout);
     L2_PARAM_END(pa[9]);
-    rv = l2_util_setparams(pa, fmt, ap);
+    l2_channel_env(ch, &env);
+    rv = l2_util_setparams(env, pa, fmt, ap);
 
     return rv;
 }


ossp-pkg/l2/l2_ch_socket.c 1.33 -> 1.34

--- l2_ch_socket.c       2001/11/07 11:37:18     1.33
+++ l2_ch_socket.c       2001/11/07 13:05:20     1.34
@@ -77,14 +77,16 @@
     l2_ch_socket_t *cfg = (l2_ch_socket_t *)ctx->vp;
     l2_param_t pa[5];
     l2_result_t rv;
+    l2_env_t *env;
 
     /* feed and call generic parameter parsing engine */
-    L2_PARAM_SET(pa[0], proto,     STRING,  &cfg->szProto);
-    L2_PARAM_SET(pa[1], host,      STRING,  &cfg->szHost);
-    L2_PARAM_SET(pa[2], port,      STRING,  &cfg->szPort);
-    L2_PARAM_SET(pa[3], timeout,   INT,     &cfg->nTimeout);
+    L2_PARAM_SET(pa[0], proto,   STR, &cfg->szProto);
+    L2_PARAM_SET(pa[1], host,    STR, &cfg->szHost);
+    L2_PARAM_SET(pa[2], port,    STR, &cfg->szPort);
+    L2_PARAM_SET(pa[3], timeout, INT, &cfg->nTimeout);
     L2_PARAM_END(pa[4]);
-    rv = l2_util_setparams(pa, fmt, ap);
+    l2_channel_env(ch, &env);
+    rv = l2_util_setparams(env, pa, fmt, ap);
 
     /* sanity check configuration parameters */
     if (   cfg->szProto != NULL


ossp-pkg/l2/l2_ch_syslog.c 1.26 -> 1.27

--- l2_ch_syslog.c       2001/11/07 11:37:18     1.26
+++ l2_ch_syslog.c       2001/11/07 13:05:20     1.27
@@ -161,20 +161,22 @@
     l2_ch_syslog_t *cfg = (l2_ch_syslog_t *)ctx->vp;
     l2_param_t pa[8];
     l2_result_t rv;
+    l2_env_t *env;
     int i;
 
     /* feed and call generic parameter parsing engine */
-    L2_PARAM_SET(pa[0], target,     STRING, &cfg->szTarget);
-    L2_PARAM_SET(pa[1], remotehost, STRING, &cfg->szRemoteHost);
-    L2_PARAM_SET(pa[2], remoteport, INT,    &cfg->nRemotePort);
-    L2_PARAM_SET(pa[3], localhost,  STRING, &cfg->szLocalHost);
-    L2_PARAM_SET(pa[4], facility,   STRING, &cfg->szFacility);
-    L2_PARAM_SET(pa[5], ident,      STRING, &cfg->szIdent);
-    L2_PARAM_SET(pa[6], logpid,     INT,    &cfg->bLogPid);
+    L2_PARAM_SET(pa[0], target,     STR, &cfg->szTarget);
+    L2_PARAM_SET(pa[1], remotehost, STR, &cfg->szRemoteHost);
+    L2_PARAM_SET(pa[2], remoteport, INT, &cfg->nRemotePort);
+    L2_PARAM_SET(pa[3], localhost,  STR, &cfg->szLocalHost);
+    L2_PARAM_SET(pa[4], facility,   STR, &cfg->szFacility);
+    L2_PARAM_SET(pa[5], ident,      STR, &cfg->szIdent);
+    L2_PARAM_SET(pa[6], logpid,     INT, &cfg->bLogPid);
     L2_PARAM_END(pa[7]);
 
     /* sanity checking & post-processing */
-    rv = l2_util_setparams(pa, fmt, ap);
+    l2_channel_env(ch, &env);
+    rv = l2_util_setparams(env, pa, fmt, ap);
     if (cfg->szTarget == NULL || cfg->szFacility == NULL)
         return L2_ERR_USE;
     if (!(   strcmp(cfg->szTarget, "local") == 0


ossp-pkg/l2/l2_test.c 1.42 -> 1.43

--- l2_test.c    2001/11/07 11:37:18     1.42
+++ l2_test.c    2001/11/07 13:05:20     1.43
@@ -31,14 +31,16 @@
 
 #include "l2.h"
 
-static void die(char *fmt, ...)
+static void die(l2_env_t *env, l2_result_t rv, char *fmt, ...)
 {
     va_list ap;
+    char *error;
 
     va_start(ap, fmt);
     fprintf(stderr, "l2_test:ERROR: ");
     vfprintf(stderr, fmt, ap);
-    fprintf(stderr, "\n");
+    error = l2_env_strerror(env, rv);
+    fprintf(stderr, " (%s)\n", error);
     va_end(ap);
     exit(1);
 }
@@ -64,87 +66,86 @@
     l2_channel_t *chFile;
     l2_channel_t *chSyslog;
     l2_channel_t *chSmtp;
+    l2_result_t rv;
     l2_env_t *env;
 
     /* create environment */
-    if ((l2_env_create(&env)) != L2_OK)
-        die("failed to create environment");
-    if (l2_env_formatter(env, 'k', formatter, NULL) != L2_OK)
-        die("failed to configure formatter for %%x");
-    if (l2_env_formatter(env, 'S', l2_util_fmt_dump, NULL) != L2_OK)
-        die("failed to configure formatter for %%S");
+    if ((rv = l2_env_create(&env)) != L2_OK)
+        die(env, rv, "failed to create environment");
+    if ((rv = l2_env_formatter(env, 'k', formatter, NULL)) != L2_OK)
+        die(env, rv, "failed to configure formatter for %%x");
+    if ((rv = l2_env_formatter(env, 'S', l2_util_fmt_dump, NULL)) != L2_OK)
+        die(env, rv, "failed to configure formatter for %%S");
 
     /* create noop channel */
-    if ((l2_channel_create(&ch, env, "noop")) != L2_OK)
-        die("failed to create noop channel");
+    if ((rv = l2_channel_create(&ch, env, "noop")) != L2_OK)
+        die(env, rv, "failed to create noop channel");
 
     /* create prefix channel */
-    if ((l2_channel_create(&chPrefix, env, "prefix")) != L2_OK)
-        die("failed to create prefix channel");
-    if (l2_channel_configure(chPrefix, "prefix,timezone", 
-                             "[%d-%m-%Y/%H:%M:%S] %L test[%P]: ", "local") != L2_OK)
-        die("failed to configure prefix channel");
+    if ((rv = l2_channel_create(&chPrefix, env, "prefix")) != L2_OK)
+        die(env, rv, "failed to create prefix channel");
+    if ((rv = l2_channel_configure(chPrefix, "prefix=\"%s\", timezone=local", "[%d-%m-%Y/%H:%M:%S] %L test[%P]: ")) != L2_OK)
+        die(env, rv, "failed to configure prefix channel");
 
     /* create prefix channel */
-    if ((l2_channel_create(&chFilter, env, "filter")) != L2_OK)
-        die("failed to create filter channel");
-    if (l2_channel_configure(chFilter, "regex,negate", "hecking", 0) != L2_OK)
-        die("failed to configure filter channel");
+    if ((rv = l2_channel_create(&chFilter, env, "filter")) != L2_OK)
+        die(env, rv, "failed to create filter channel");
+    if ((rv = l2_channel_configure(chFilter, "regex=hecking, negate=0")) != L2_OK)
+        die(env, rv, "failed to configure filter channel");
 
     /* create buffer channel */
-    if ((l2_channel_create(&chBuffer, env, "buffer")) != L2_OK)
-        die("failed to create buffer channel");
-    if (l2_channel_configure(chBuffer, "size", 800) != L2_OK)
-        die("failed to configure buffer channel");
+    if ((rv = l2_channel_create(&chBuffer, env, "buffer")) != L2_OK)
+        die(env, rv, "failed to create buffer channel");
+    if ((rv = l2_channel_configure(chBuffer, "size=800")) != L2_OK)
+        die(env, rv, "failed to configure buffer channel");
 
     /* create file channel */
-    if ((l2_channel_create(&chFile, env, "file")) != L2_OK)
-        die("failed to create file channel");
-    if (l2_channel_configure(chFile, "path,append,perm", "l2_test.log", TRUE, 0644) != L2_OK)
-        die("failed to configure file channel");
-    if (l2_channel_levels(chFile, L2_LEVEL_UPTO(L2_LEVEL_INFO), L2_LEVEL_NONE) != L2_OK)
-        die("failed to level of smtp channel");
+    if ((rv = l2_channel_create(&chFile, env, "file")) != L2_OK)
+        die(env, rv, "failed to create file channel");
+    if ((rv = l2_channel_configure(chFile, "path=l2_test.log, append=%d,perm=%d", TRUE, 0644)) != L2_OK)
+        die(env, rv, "failed to configure file channel");
+    if ((rv = l2_channel_levels(chFile, L2_LEVEL_UPTO(L2_LEVEL_INFO), L2_LEVEL_NONE)) != L2_OK)
+        die(env, rv, "failed to level of smtp channel");
 
     /* create syslog channel */
-    if ((l2_channel_create(&chSyslog, env, "syslog")) != L2_OK)
-        die("failed to create syslog channel");
-    if (l2_channel_configure(chSyslog, "ident,facility,target,remotehost,logpid",
-                             "L2-Test", "user", "remote", "en1", 1) != L2_OK)
-        die("failed to configure syslog channel");
-    if (l2_channel_levels(chSyslog, L2_LEVEL_UPTO(L2_LEVEL_ERROR), L2_LEVEL_ALL) != L2_OK)
-        die("failed to level of syslog channel");
+    if ((rv = l2_channel_create(&chSyslog, env, "syslog")) != L2_OK)
+        die(env, rv, "failed to create syslog channel");
+    if ((rv = l2_channel_configure(chSyslog, "ident=L2-Test, facility=user, target=remote, remotehost=en1, logpid=1")) != L2_OK)
+        die(env, rv, "failed to configure syslog channel");
+    if ((rv = l2_channel_levels(chSyslog, L2_LEVEL_UPTO(L2_LEVEL_ERROR), L2_LEVEL_ALL)) != L2_OK)
+        die(env, rv, "failed to level of syslog channel");
 
     /* create smtp channel */
-    if ((l2_channel_create(&chSmtp, env, "smtp")) != L2_OK)
-        die("failed to create smtp channel");
-    if (l2_channel_configure(chSmtp, "rcpt,host,port", "rse@engelschall.com", "en1", "25") != L2_OK)
-        die("failed to configure smtp channel");
-    if (l2_channel_levels(chSmtp, L2_LEVEL_UPTO(L2_LEVEL_PANIC), L2_LEVEL_ALL) != L2_OK)
-        die("failed to level of smtp channel");
+    if ((rv = l2_channel_create(&chSmtp, env, "smtp")) != L2_OK)
+        die(env, rv, "failed to create smtp channel");
+    if ((rv = l2_channel_configure(chSmtp, "rcpt=rse@engelschall.com, host=en1, port=25")) != L2_OK)
+        die(env, rv, "failed to configure smtp channel");
+    if ((rv = l2_channel_levels(chSmtp, L2_LEVEL_UPTO(L2_LEVEL_PANIC), L2_LEVEL_ALL)) != L2_OK)
+        die(env, rv, "failed to level of smtp channel");
 
     /* build channel tree */
-    if (l2_channel_link(ch, L2_LINK_CHILD, chFilter, chPrefix, chBuffer, chFile, NULL) != L2_OK)
-        die("failed to link file-related channels together as a child sequence");
-    if (l2_channel_link(ch, L2_LINK_CHILD, chSyslog, NULL) != L2_OK)
-        die("failed to link syslog-related channels together as a child sequence");
+    if ((rv = l2_channel_link(ch, L2_LINK_CHILD, chFilter, chPrefix, chBuffer, chFile, NULL)) != L2_OK)
+        die(env, rv, "failed to link file-related channels together as a child sequence");
+    if ((rv = l2_channel_link(ch, L2_LINK_CHILD, chSyslog, NULL)) != L2_OK)
+        die(env, rv, "failed to link syslog-related channels together as a child sequence");
 
     /* open channel tree */
-    if (l2_channel_open(ch) != L2_OK)
-        die("failed to open channel tree");
+    if ((rv = l2_channel_open(ch)) != L2_OK)
+        die(env, rv, "failed to open channel tree");
     
     /* perform a few log operations */
-    if (l2_channel_log(ch, L2_LEVEL_PANIC, "1: Checking localhost %s %{myparm}k <%{text}S><%{hex}S><%{base64}S>\n", "foo", 12345, "foo\1bar", 7, "foo\1bar", 7, "foo\1bar", 7) != L2_OK)
-        die("failed to log message #1 to channel");
-    if (l2_channel_log(ch, L2_LEVEL_PANIC, "2: Shecking\n") != L2_OK)
-        die("failed to log message #2 to channel");
-    if (l2_channel_log(ch, L2_LEVEL_PANIC, "3: Checking localhost %s %{myparm}k <%{text}S><%{hex}S><%{base64}S>\n", "foo", 12345, "foo\1bar", 7, "foo\1bar", 7, "foo\1bar", 7) != L2_OK)
-        die("failed to log message #3 to channel");
-    if (l2_channel_log(ch, L2_LEVEL_PANIC, "4: Shecking\n") != L2_OK)
-        die("failed to log message #4 to channel");
+    if ((rv = l2_channel_log(ch, L2_LEVEL_PANIC, "1: Checking localhost %s %{myparm}k <%{text}S><%{hex}S><%{base64}S>\n", "foo", 12345, "foo\1bar", 7, "foo\1bar", 7, "foo\1bar", 7)) != L2_OK)
+        die(env, rv, "failed to log message #1 to channel");
+    if ((rv = l2_channel_log(ch, L2_LEVEL_PANIC, "2: Shecking\n")) != L2_OK)
+        die(env, rv, "failed to log message #2 to channel");
+    if ((rv = l2_channel_log(ch, L2_LEVEL_PANIC, "3: Checking localhost %s %{myparm}k <%{text}S><%{hex}S><%{base64}S>\n", "foo", 12345, "foo\1bar", 7, "foo\1bar", 7, "foo\1bar", 7)) != L2_OK)
+        die(env, rv, "failed to log message #3 to channel");
+    if ((rv = l2_channel_log(ch, L2_LEVEL_PANIC, "4: Shecking\n")) != L2_OK)
+        die(env, rv, "failed to log message #4 to channel");
 
     /* destroy channel tree */
-    if (l2_channel_destroy(ch) != L2_OK)
-        die("failed to destroy channel tree");
+    if ((rv = l2_channel_destroy(ch)) != L2_OK)
+        die(env, rv, "failed to destroy channel tree");
 
     return 0;
 }


ossp-pkg/l2/l2_ut_param.c 1.5 -> 1.6

--- l2_ut_param.c        2001/09/08 22:06:09     1.5
+++ l2_ut_param.c        2001/11/07 13:05:20     1.6
@@ -30,82 +30,157 @@
 #include "l2.h"
 #include "l2_p.h"
 
+#include <stdlib.h>
 #include <string.h>
+#include <limits.h>
+#include <math.h>
+#include <ctype.h>
 
-l2_result_t l2_util_setparams(l2_param_t pa[], const char *fmt, va_list ap)
+l2_result_t l2_util_setparams(l2_env_t *env, l2_param_t pa[], const char *fmt, va_list ap)
 {
-    const char *cpB, *cpE;
-    const char *cpC, *cpG;
+    char *cpB, *cpE;
+    char *spec;
     int ok;
     int i; 
+    int n;
 
-    if (pa == NULL || fmt == NULL || ap == NULL)
+    /* argument sanity check */
+    if (env == NULL || pa == NULL || fmt == NULL || ap == NULL)
         return L2_ERR_ARG;
-    cpE = fmt;
+
+    /* on-the-fly create or just take over parameter specification string */
+    spec = l2_util_vasprintf(fmt, ap);
+
+    /* enter the parsing loop */
+    cpE = spec;
     while (*cpE != '\0') {
         /* determine begin of parameter name */
         cpB = cpE;
-        while (*cpB == ',')
-            cpB++;
+        if ((n = strspn(cpB, " \t\r\n")) > 0)
+            cpB += n;
 
         /* determine end of parameter name */
         cpE = cpB;
-        while (*cpE != ',' && *cpE != '\0')
+        if (!isalpha((int)*cpE)) {
+            l2_env_errorinfo(env, L2_ERR_ARG, 
+                             "expected alpha-numerical parameter "
+                             "start character, got '%c'", *cpE);
+            return L2_ERR_ARG;
+        }
+        cpE++;
+        while (isalnum((int)*cpE))
             cpE++;
+        if (*cpE != '=') {
+            l2_env_errorinfo(env, L2_ERR_ARG, 
+                             "expected assignment operator ('='), "
+                             "got '%c'", *cpE);
+            return L2_ERR_ARG;
+        }
+        *cpE++ = '\0';
 
         /* try to match with configured parameters */
         ok = FALSE;
         for (i = 0; pa[i].name != NULL; i++) {
-            cpC = pa[i].name;
-            cpG = cpB;
-            while (*cpC != '\0' && cpG < cpE) {
-                if (*cpC != *cpG)
+            if (strcmp(pa[i].name, cpB) == 0) {
+                ok = TRUE;
+                break;
+            }
+        }
+        if (!ok) {
+            l2_env_errorinfo(env, L2_ERR_ARG, "unknown parameter name '%s'", cpB);
+            return L2_ERR_ARG;
+        }
+
+        /* determine parameter value */
+        cpB = cpE;
+        if ((n = strspn(cpB, " \t\r\n")) > 0)
+            cpB += n;
+        if (*cpB == '"') {
+            cpB++;
+            while (1) {
+                cpE = cpB;
+                if ((cpE = strchr(cpE+1, '"')) == NULL) {
+                    l2_env_errorinfo(env, L2_ERR_ARG, "closing quote ('\"') not found");
+                    return L2_ERR_ARG;
+                }
+                if (*(cpE-1) != '\\')
                     break;
-                cpC++;
-                cpG++;
             }
-            if (*cpC == '\0' && cpG == cpE) {
-                /* parameter matched, so store value */
-                switch (pa[i].type) {
-                    case L2_TYPE_CHAR:
-                        *(char *)(pa[i].store) = va_get(ap, char); 
-                        break;
-                    case L2_TYPE_SHORT:
-                        *(short *)(pa[i].store) = va_get(ap, short); 
-                        break;
-                    case L2_TYPE_INT:
-                        *(int *)(pa[i].store) = va_get(ap, int); 
-                        break;
-                    case L2_TYPE_LONG:
-                        *(long *)(pa[i].store) = va_get(ap, long); 
-                        break;
-                    case L2_TYPE_FLOAT:
-                        *(float *)(pa[i].store) = va_get(ap, float); 
-                        break;
-                    case L2_TYPE_DOUBLE:
-                        *(double *)(pa[i].store) = va_get(ap, double); 
-                        break;
-                    case L2_TYPE_STRING:
-                        if (*(char **)(pa[i].store) != NULL) 
-                            free(*(char **)(pa[i].store));
-                        *(char **)(pa[i].store) = va_get(ap, charptr);
-                        if (*(char **)(pa[i].store) != NULL)
-                            *(char **)(pa[i].store) = strdup(*(char **)(pa[i].store));
-                        break;
-                    case L2_TYPE_CHARPTR:
-                        *(char **)(pa[i].store) = va_get(ap, charptr); 
-                        break;
-                    case L2_TYPE_VOIDPTR:
-                        *(void **)(pa[i].store) = va_get(ap, voidptr); 
-                        break;
+        }
+        else {
+            cpE = cpB;
+            while (1) {
+                if ((n = strcspn(cpE, " \t\r\n,")) > 0) {
+                    cpE += n;
+                    if (*(cpE-1) == '\\') {
+                        cpE++;
+                        continue;
+                    }
                 }
-                ok = TRUE;
                 break;
             }
         }
-        if (!ok)
-            return L2_ERR_USE;
+        *cpE++ = '\0';
+
+        /* store parameter value */
+        switch (pa[i].type) {
+            case L2_TYPE_INT: {
+                /* integer parameter */
+                long val = strtol(cpB, &cpE, 10);
+                if ((val == LONG_MIN || val == LONG_MAX) && errno == ERANGE) {
+                    l2_env_errorinfo(env, L2_ERR_ARG, 
+                                     "numerical parameter value out of range "
+                                     "('%s')", cpB);
+                    return L2_ERR_ARG;
+                }
+                if (*cpE != '\0') {
+                    l2_env_errorinfo(env, L2_ERR_ARG, 
+                                     "expected valid numerical parameter value, "
+                                     "got '%c' character", *cpE);
+                    return L2_ERR_ARG;
+                }
+                *(int *)(pa[i].store) = (int)val;
+                break;
+            }
+            case L2_TYPE_FLT: {
+                /* floating point parameter */
+                double val = strtod(cpB, &cpE);
+                if (val == HUGE_VAL && errno == ERANGE) {
+                    l2_env_errorinfo(env, L2_ERR_ARG, 
+                                     "floating point parameter value too huge "
+                                     "('%s')", cpB);
+                    return L2_ERR_ARG;
+                }
+                if (val == 0 && cpE == cpB) {
+                    l2_env_errorinfo(env, L2_ERR_ARG, 
+                                     "floating point parameter value conversion failed "
+                                     "('%s')", cpB);
+                }
+                if (*cpE != '\0') {
+                    l2_env_errorinfo(env, L2_ERR_ARG, 
+                                     "expected valid floating point parameter value, "
+                                     "got '%c' character", *cpE);
+                    return L2_ERR_ARG;
+                }
+                *(float *)(pa[i].store) = (float)val;
+                break;
+            }
+            case L2_TYPE_STR: {
+                /* string parameter */
+                if (*(char **)(pa[i].store) != NULL) 
+                    free(*(char **)(pa[i].store));
+                *(char **)(pa[i].store) = strdup(cpB);
+                break;
+            }
+        }
+
+        /* skip delimiter */
+        if ((n = strspn(cpE, " \t\r\n,")) > 0)
+            cpE += n;
     }
+
+    free(spec);
+
     return L2_OK;
 }
 

CVSTrac 2.0.1