Index: ossp-pkg/l2/l2.h.in RCS File: /v/ossp/cvs/ossp-pkg/l2/l2.h.in,v rcsdiff -q -kk '-r1.19' '-r1.20' -u '/v/ossp/cvs/ossp-pkg/l2/l2.h.in,v' 2>/dev/null --- 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 *); Index: ossp-pkg/l2/l2_ch_buffer.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_buffer.c,v rcsdiff -q -kk '-r1.33' '-r1.34' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_buffer.c,v' 2>/dev/null --- 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 */ Index: ossp-pkg/l2/l2_ch_fd.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_fd.c,v rcsdiff -q -kk '-r1.11' '-r1.12' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_fd.c,v' 2>/dev/null --- 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; } Index: ossp-pkg/l2/l2_ch_file.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_file.c,v rcsdiff -q -kk '-r1.18' '-r1.19' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_file.c,v' 2>/dev/null --- 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; } Index: ossp-pkg/l2/l2_ch_filter.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_filter.c,v rcsdiff -q -kk '-r1.13' '-r1.14' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_filter.c,v' 2>/dev/null --- 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; } Index: ossp-pkg/l2/l2_ch_irc.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_irc.c,v rcsdiff -q -kk '-r1.3' '-r1.4' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_irc.c,v' 2>/dev/null --- 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; } Index: ossp-pkg/l2/l2_ch_pipe.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_pipe.c,v rcsdiff -q -kk '-r1.27' '-r1.28' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_pipe.c,v' 2>/dev/null --- 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; Index: ossp-pkg/l2/l2_ch_prefix.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_prefix.c,v rcsdiff -q -kk '-r1.17' '-r1.18' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_prefix.c,v' 2>/dev/null --- 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) { Index: ossp-pkg/l2/l2_ch_smtp.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_smtp.c,v rcsdiff -q -kk '-r1.7' '-r1.8' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_smtp.c,v' 2>/dev/null --- 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; } Index: ossp-pkg/l2/l2_ch_socket.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_socket.c,v rcsdiff -q -kk '-r1.33' '-r1.34' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_socket.c,v' 2>/dev/null --- 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 Index: ossp-pkg/l2/l2_ch_syslog.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_syslog.c,v rcsdiff -q -kk '-r1.26' '-r1.27' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_syslog.c,v' 2>/dev/null --- 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 Index: ossp-pkg/l2/l2_test.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_test.c,v rcsdiff -q -kk '-r1.42' '-r1.43' -u '/v/ossp/cvs/ossp-pkg/l2/l2_test.c,v' 2>/dev/null --- 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; } Index: ossp-pkg/l2/l2_ut_param.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ut_param.c,v rcsdiff -q -kk '-r1.5' '-r1.6' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ut_param.c,v' 2>/dev/null --- 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 #include +#include +#include +#include -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; }