--- lmtp2nntp_config.c 2002/01/21 16:21:16 1.10
+++ lmtp2nntp_config.c 2002/01/22 16:09:47 1.11
@@ -104,53 +104,11 @@
void die(char *); /* FIXME */
void die(char *msg)
{
- printf("ERROR: %s\n", msg);
+ //printf("ERROR: %s\n", msg);
exit(-1);
}
#if 0
-static val_rc_t dumper(void *ctx, const char *name, int type, const char *desc, void *data)
-{
- switch (type) {
- case VAL_TYPE_VAL:
- printf("DEBUG: <%10s>, name=<%10s>, VAL_TYPE_VAL, desc=<%20s>, data@%.8lx INTERNAL\n",
- (char *)ctx, name, desc, (long)data);
- break;
- case VAL_TYPE_PTR:
- printf("DEBUG: <%10s>, name=<%10s>, VAL_TYPE_PTR, desc=<%20s>, data@%.8lx=%.8lx\n",
- (char *)ctx, name, desc, (long)data, *(long *)data);
- break;
- case VAL_TYPE_CHAR:
- printf("DEBUG: <%10s>, name=<%10s>, VAL_TYPE_CHAR, desc=<%20s>, data@%.8lx='%c'\n",
- (char *)ctx, name, desc, (long)data, *(char *)data);
- break;
- case VAL_TYPE_SHORT:
- printf("DEBUG: <%10s>, name=<%10s>, VAL_TYPE_SHORT, desc=<%20s>, data@%.8lx=%8d\n",
- (char *)ctx, name, desc, (long)data, *(short *)data);
- break;
- case VAL_TYPE_INT:
- printf("DEBUG: <%10s>, name=<%10s>, VAL_TYPE_INT, desc=<%20s>, data@%.8lx=%8d\n",
- (char *)ctx, name, desc, (long)data, *(int *)data);
- break;
- case VAL_TYPE_LONG:
- printf("DEBUG: <%10s>, name=<%10s>, VAL_TYPE_LONG, desc=<%20s>, data@%.8lx=%8ld\n",
- (char *)ctx, name, desc, (long)data, *(long *)data);
- break;
- case VAL_TYPE_FLOAT:
- printf("DEBUG: <%10s>, name=<%10s>, VAL_TYPE_FLOAT, desc=<%20s>, data@%.8lx=%8f\n",
- (char *)ctx, name, desc, (long)data, *(float *)data);
- break;
- case VAL_TYPE_DOUBLE:
- printf("DEBUG: <%10s>, name=<%10s>, VAL_TYPE_DOUBLE, desc=<%20s>, data@%.8lx=%8f\n",
- (char *)ctx, name, desc, (long)data, *(double *)data);
- break;
- default:
- printf("DEBUG: <%10s>, name=<%10s>, type = %.8lx, desc=<%20s>, data@%.8lx\n",
- (char *)ctx, name, (long)type, desc, (long)data);
- }
-
- return VAL_OK;
-}
@@ -192,7 +150,7 @@
if (close(fd) == -1)
die("close");
}
- printf("DEBUG: *** 1 *** file as it was just read in ***\n%s***\n", cpBuf);
+ //printf("DEBUG: *** 1 *** file as it was just read in ***\n%s***\n", cpBuf);
{
char *cpI; /* pointer to next character to be read */
@@ -232,23 +190,23 @@
if (!eline) { /* process logical line unless it's empty */
*(cpO-1) = NUL;
if (lline == (pline-1))
- printf("DEBUG: line[%3d] = ***%s***\n", lline, cpL);
+ //printf("DEBUG: line[%3d] = ***%s***\n", lline, cpL);
else
- printf("DEBUG: [%3d-%3d] = ***%s***\n", lline, pline-1, cpL);
+ //printf("DEBUG: [%3d-%3d] = ***%s***\n", lline, pline-1, cpL);
{
char *cp = cpL;
char *command;
char *value;
if ((command = str_token(&cp, " \t", "\"'", "#", STR_STRIPQUOTES|STR_BACKSLASHESC)) == NULL)
- printf("DEBUG: no command - comment only\n");
+ //printf("DEBUG: no command - comment only\n");
else {
- printf("DEBUG: command = ***%s***\n", command);
+ //printf("DEBUG: command = ***%s***\n", command);
if ((value = str_token(&cp, " \t", "\"'", "#", STR_STRIPQUOTES|STR_BACKSLASHESC)) == NULL)
- printf("DEBUG: no value - section\n");
+ //printf("DEBUG: no value - section\n");
else {
while(isspace((int)*value)) value++;
- printf("DEBUG: value = ***%s***\n", value);
+ //printf("DEBUG: value = ***%s***\n", value);
}
}
}
@@ -265,7 +223,7 @@
#endif
struct optionconfig_s {
- optionconfig_t *next; /* cleanup chain for destroy */
+ optionconfig_t *next; /* cleanup chain for destroy */
/**/
char *longname; /* the long name (optional if shortname given) */
char shortname; /* the short name (optional if longname given) */
@@ -274,17 +232,45 @@
optiontype_t type; /* OPT_FLAG, OPT_SINGLE, OPT_MULTI */
optionloop_cb_t *cb; /* callback for first iteration - syntax check and include */
void *cbctx; /* context for pass1 */
- void *pass1default; /* default for pass1 */
val_t *val; /* val we are registered under */
/**/
- int number; /* number of this option for popt */
- union { /* option data as read from configuration */
- int f; /* OPT_FLAG */
- char *s; /* OPT_SINGLE */
- char **m; /* OPT_MULTI */
+ int number; /* number of this option for popt */
+ union { /* option data as read from configuration */
+ int f; /* OPT_FLAG */
+ char *s; /* OPT_SINGLE */
+ char **m; /* OPT_MULTI */
} data;
+ int ndata;
};
+static val_rc_t dumper(void *ctx, const char *name, int type, const char *desc, void *data)
+{
+ optionconfig_t *oc;
+ int i;
+
+ if (type != VAL_TYPE_PTR)
+ return VAL_OK;
+
+ oc = (optionconfig_t *)data;
+
+ switch (oc->type) {
+ case OPT_FLAG:
+ printf("DEBUG: <%5s>, name=<%20s>, OPT_FLAG, desc=<%20s>, data@%.8lx->[%d]%d\n", (char *)ctx, name, desc, (long)oc, oc->ndata, oc->data.f);
+ break;
+ case OPT_SINGLE:
+ printf("DEBUG: <%5s>, name=<%20s>, OPT_SINGLE, desc=<%20s>, data@%.8lx->[%d]\"%s\"\n", (char *)ctx, name, desc, (long)oc, oc->ndata, oc->data.s == NULL ? "NULL" : oc->data.s);
+ break;
+ case OPT_MULTI:
+ printf("DEBUG: <%5s>, name=<%20s>, OPT_MULTI, desc=<%20s>, data@%.8lx->[%d]%.8lx\n", (char *)ctx, name, desc, (long)oc, oc->ndata, (long)oc->data.m);
+ for (i = 0; i < oc->ndata; i++) {
+ printf("DEBUG: [%3d] =<%20s>\n", i, oc->data.m[i]);
+ }
+ break;
+ default:
+ break;
+ }
+ return VAL_OK;
+}
lmtp2nntp_option_rc_t option_find(lmtp2nntp_option_t *o, int number, optionconfig_t **ocp);
lmtp2nntp_option_rc_t option_find(lmtp2nntp_option_t *o, int number, optionconfig_t **ocp)
{
@@ -306,7 +292,7 @@
lmtp2nntp_option_rc_t rc = VAL_OK;
optionconfig_t *oc;
- printf("DEBUG: enter option_register(%.8lx, \"%s\", '%c', %d, %.8lx, %.8lx, \"%s\", \"%s\")\n", (long)o, longname, shortname, type, (long)cb, (long)cbctx, descrip, argdescrip);
+ //printf("DEBUG: enter option_register(%.8lx, \"%s\", '%c', %d, %.8lx, %.8lx, \"%s\", \"%s\")\n", (long)o, longname, shortname, type, (long)cb, (long)cbctx, descrip, argdescrip);
if (o == NULL || longname == NULL)
return OPTION_ERR_ARG;
@@ -314,7 +300,7 @@
/* create a optionconfig_t structure */
if ((oc = (optionconfig_t *)malloc(sizeof(optionconfig_t))) == NULL)
return OPTION_ERR_MEM;
- printf("DEBUG: optionconfig_t structure malloc'ed\n");
+ //printf("DEBUG: optionconfig_t structure malloc'ed\n");
oc->next = NULL;
oc->longname = strdup(longname);
oc->shortname = shortname;
@@ -323,34 +309,35 @@
oc->type = type;
oc->cb = cb;
oc->cbctx = cbctx;
- oc->pass1default = NULL; /*FIXME*/
oc->val = o->vo;
oc->number = o->pi; /*FIXME + 1; 0 is a reserved val in popt, so offset 1 */
+ oc->data.f = 0;
+ oc->data.s = NULL; /* just in case a pointer is larger than int */
+ oc->data.m = NULL;
+ oc->ndata = 0;
if ( ( oc->longname == NULL)
|| (descrip != NULL && oc->descrip == NULL)
|| (argdescrip != NULL && oc->argdescrip == NULL)
)
CU(OPTION_ERR_MEM);
- printf("DEBUG: optionconfig_t structure created\n");
+ //printf("DEBUG: optionconfig_t structure created\n");
/* feed lib_val */
- (void)/*FIXME rc*/val_reg(oc->val, oc->longname,
- type == OPT_FLAG ? VAL_TYPE_INT : VAL_TYPE_PTR,
- oc->descrip, NULL);
+ (void)/*FIXME rc*/val_reg(oc->val, oc->longname, VAL_TYPE_PTR, oc->descrip, oc);
- printf("DEBUG: val_reg'ed\n");
+ //printf("DEBUG: val_reg'ed\n");
/* feed lib_popt */
- printf("DEBUG: o->pi=%d, o->pn=%d\n", o->pi, o->pn);
+ //printf("DEBUG: o->pi=%d, o->pn=%d\n", o->pi, o->pn);
if (o->pi >= (o->pn-2)) { /* correction by two here, in malloc and realloc is for AUTOHELP and TABLEEND */
if (o->pt == NULL) {
- printf("DEBUG: malloc\n");
+ //printf("DEBUG: malloc\n");
o->pt = (struct popt_option *)malloc( (1 + 2) * sizeof(struct popt_option)); /*FIXME out of mem*/
o->pn = 1;
}
else {
- printf("DEBUG: realloc\n");
+ //printf("DEBUG: realloc\n");
o->pt = (struct popt_option *)realloc(o->pt, (o->pn * 2 + 2) * sizeof(struct popt_option)); /*FIXME out of mem*/
o->pn = o->pn * 2;
}
@@ -381,7 +368,7 @@
o->pt[o->pi+2].descrip = NULL;
o->pt[o->pi+2].argDescrip = NULL;
o->pi++;
- printf("DEBUG: popt'ed\n");
+ //printf("DEBUG: popt'ed\n");
/* link in this new optionconfig_t structure */
if (o->first == NULL) {
@@ -392,7 +379,7 @@
o->last->next = oc;
o->last = oc;
}
- printf("DEBUG: linked\n");
+ //printf("DEBUG: linked\n");
return rc;
@@ -406,20 +393,77 @@
return rc;
}
-static void stdsyntax(optionconfig_t *oc, char *arg, char *cbctx)
+static lmtp2nntp_option_rc_t stdsyntax(optionconfig_t *oc, char *arg, char *cbctx)
{
printf("DEBUG: enter stdsyntax %.8lx, \"%s\", \"%s\"\n", (long)oc, arg, cbctx);
- return;
+
+ //printf("DEBUG: oc->type=%d\n", oc->type);
+ switch (oc->type) {
+ case OPT_FLAG:
+ printf("DEBUG: flag\n");
+ if (arg != NULL || cbctx != NULL)
+ return OPTION_ERR_ARG;
+ if (oc->ndata >= 1)
+ return OPTION_ERR_USE;
+ oc->data.f = 1;
+ oc->ndata = 1;
+ break;
+ case OPT_SINGLE:
+ printf("DEBUG: single\n");
+ if (arg == NULL)
+ return OPTION_ERR_ARG;
+ if (oc->ndata >= 1 || oc->data.s != NULL)
+ return OPTION_ERR_USE;
+ if (cbctx != NULL)
+ if (str_parse(arg, cbctx) <= 0) {
+ //printf("DEBUG: \"%s\" does NOT match \"%s\"\n", arg, cbctx);
+ return OPTION_ERR_USE;
+ }
+ printf("DEBUG: \"%s\" does match \"%s\"\n", arg, cbctx);
+ if ((oc->data.s = strdup(arg)) == NULL)
+ return OPTION_ERR_MEM;
+ oc->ndata = 1;
+ break;
+ case OPT_MULTI:
+ //printf("DEBUG: multi\n");
+ if (arg == NULL)
+ return OPTION_ERR_ARG;
+ if (oc->ndata >= 1 && oc->data.m == NULL)
+ return OPTION_ERR_USE;
+ if (cbctx != NULL)
+ if (str_parse(arg, cbctx) <= 0) {
+ //printf("DEBUG: \"%s\" does NOT match \"%s\"\n", arg, cbctx);
+ return OPTION_ERR_USE;
+ }
+ //printf("DEBUG: \"%s\" does match \"%s\"\n", arg, cbctx);
+ if (oc->data.m == NULL) {
+ if ((oc->data.m = (char **)malloc( ( 1 + 1) * sizeof(char **))) == NULL)
+ return OPTION_ERR_MEM;
+ }
+ else {
+ if ((oc->data.m = (char **)realloc(oc->data.m, (oc->ndata + 1) * sizeof(char **))) == NULL)
+ return OPTION_ERR_MEM;
+ }
+ if ((oc->data.m[oc->ndata] = strdup(arg)) == NULL)
+ return OPTION_ERR_MEM;
+ oc->ndata++;
+ oc->data.m[oc->ndata] = NULL;
+ break;
+ default:
+ return OPTION_ERR_ARG;
+ break;
+ }
+ return OPTION_OK;
}
-static void includeit(optionconfig_t *oc, char *arg, char *cbctx)
+static lmtp2nntp_option_rc_t includeit(optionconfig_t *oc, char *arg, char *cbctx)
{
- return;
+ return OPTION_OK;
}
lmtp2nntp_option_rc_t option_create(lmtp2nntp_option_t **op)
{
- printf("DEBUG: enter option_create(%.8lx)\n", (long)op);
+ //printf("DEBUG: enter option_create(%.8lx)\n", (long)op);
if (op == NULL)
return OPTION_ERR_ARG;
@@ -474,38 +518,38 @@
lmtp2nntp_option_rc_t option_parse(lmtp2nntp_option_t *o, int argc, char **argv)
{
- printf("DEBUG: enter option_parse(%.8lx, %d, %.8lx)\n", (long)o, argc, (long)argv);
+ //printf("DEBUG: enter option_parse(%.8lx, %d, %.8lx)\n", (long)o, argc, (long)argv);
if (o == NULL)
return OPTION_ERR_ARG;
- (void)option_register(o, "childsmax", 'C', OPT_SINGLE, &stdsyntax, "[0-9]{,5}", "foo", "childsmax" );
+ (void)option_register(o, "childsmax", 'C', OPT_SINGLE, &stdsyntax, "m/.*/", "foo", "childsmax" );
(void)option_register(o, "daemonize", 'D', OPT_FLAG, NULL, NULL, "foo", NULL );
(void)option_register(o, "kill", 'K', OPT_FLAG, NULL, NULL, "foo", NULL );
- (void)option_register(o, "pidfile", 'P', OPT_SINGLE, &stdsyntax, ".{,255}", "foo", "pidfile" );
+ (void)option_register(o, "pidfile", 'P', OPT_SINGLE, &stdsyntax, "m/.{,255}/", "foo", "pidfile" );
(void)option_register(o, "veryverbose", 'V', OPT_FLAG, NULL, NULL, "foo", NULL );
- (void)option_register(o, "acl", 'a', OPT_MULTI, &stdsyntax, "[0-9.](/[0-9]2)?", "foo", "addr[/mask]" );
- (void)option_register(o, "bind", 'b', OPT_SINGLE, &stdsyntax, ".*", "foo", "addr[:port]|-|path[:perms]" );
- (void)option_register(o, "client", 'c', OPT_SINGLE, &stdsyntax, ".*", "foo", "addr[:port]" );
- (void)option_register(o, "destination", 'd', OPT_MULTI, &stdsyntax, ".*", "foo", "addr[:port]" );
- (void)option_register(o, "groupmode", 'g', OPT_SINGLE, &stdsyntax, ".*", "foo", "groupmode" );
- (void)option_register(o, "headervalue", 'h', OPT_MULTI, &stdsyntax, ".*", "foo", "header: value" );
- (void)option_register(o, "include", 'i', OPT_MULTI, &includeit, ".*", "foo", "configfile" );
- (void)option_register(o, "size", 's', OPT_SINGLE, &stdsyntax, ".*", "foo", "bytes" );
- (void)option_register(o, "timeoutlmtpaccept", NUL, OPT_MULTI, &stdsyntax, ".*", "foo", "sec" );
- (void)option_register(o, "timeoutlmtpread", NUL, OPT_MULTI, &stdsyntax, ".*", "foo", "sec" );
- (void)option_register(o, "timeoutlmtpwrite", NUL, OPT_MULTI, &stdsyntax, ".*", "foo", "sec" );
- (void)option_register(o, "timeoutnntpconnect", NUL, OPT_MULTI, &stdsyntax, ".*", "foo", "sec" );
- (void)option_register(o, "timeoutnntpread", NUL, OPT_MULTI, &stdsyntax, ".*", "foo", "sec" );
- (void)option_register(o, "timeoutnntpwrite", NUL, OPT_MULTI, &stdsyntax, ".*", "foo", "sec" );
- (void)option_register(o, "mailfrom", 'm', OPT_SINGLE, &stdsyntax, ".*", "foo", "regex" );
- (void)option_register(o, "nodename", 'n', OPT_SINGLE, &stdsyntax, ".*", "foo", "nodename" );
- (void)option_register(o, "operationmode", 'o', OPT_SINGLE, &stdsyntax, ".*", "foo", "post|feed" );
- (void)option_register(o, "l2spec", 'l', OPT_SINGLE, &stdsyntax, ".*", "foo", "spec" );
- (void)option_register(o, "uid", 'u', OPT_SINGLE, &stdsyntax, ".*", "foo", "number|name" );
- (void)option_register(o, "restrictheader", 'r', OPT_MULTI, &stdsyntax, ".*", "foo", "regex" );
- (void)option_register(o, "newsgroup", NUL, OPT_MULTI, &stdsyntax, ".*", "foo", "newsgroup");
-
+ (void)option_register(o, "acl", 'a', OPT_MULTI, &stdsyntax, "m/[0-9.](/[0-9]2)?/", "foo", "addr[/mask]" );
+ (void)option_register(o, "bind", 'b', OPT_SINGLE, &stdsyntax, "m/.*/", "foo", "addr[:port]|-|path[:perms]" );
+ (void)option_register(o, "client", 'c', OPT_SINGLE, &stdsyntax, "m/.*/", "foo", "addr[:port]" );
+ (void)option_register(o, "destination", 'd', OPT_MULTI, &stdsyntax, "m/.*/", "foo", "addr[:port]" );
+ (void)option_register(o, "groupmode", 'g', OPT_SINGLE, &stdsyntax, "m/.*/", "foo", "groupmode" );
+ (void)option_register(o, "headervalue", 'h', OPT_MULTI, &stdsyntax, "m/.*/", "foo", "header: value" );
+ (void)option_register(o, "include", 'i', OPT_MULTI, &includeit, "m/.*/", "foo", "configfile" );
+ (void)option_register(o, "size", 's', OPT_SINGLE, &stdsyntax, "m/[0-9]+/", "foo", "bytes" );
+ (void)option_register(o, "timeoutlmtpaccept", NUL, OPT_MULTI, &stdsyntax, "m/.*/", "foo", "sec" );
+ (void)option_register(o, "timeoutlmtpread", NUL, OPT_MULTI, &stdsyntax, "m/.*/", "foo", "sec" );
+ (void)option_register(o, "timeoutlmtpwrite", NUL, OPT_MULTI, &stdsyntax, "m/.*/", "foo", "sec" );
+ (void)option_register(o, "timeoutnntpconnect", NUL, OPT_MULTI, &stdsyntax, "m/.*/", "foo", "sec" );
+ (void)option_register(o, "timeoutnntpread", NUL, OPT_MULTI, &stdsyntax, "m/.*/", "foo", "sec" );
+ (void)option_register(o, "timeoutnntpwrite", NUL, OPT_MULTI, &stdsyntax, "m/.*/", "foo", "sec" );
+ (void)option_register(o, "mailfrom", 'm', OPT_SINGLE, &stdsyntax, "m/.*/", "foo", "regex" );
+ (void)option_register(o, "nodename", 'n', OPT_SINGLE, &stdsyntax, "m/.*/", "foo", "nodename" );
+ (void)option_register(o, "operationmode", 'o', OPT_SINGLE, &stdsyntax, "m/.*/", "foo", "post|feed" );
+ (void)option_register(o, "l2spec", 'l', OPT_SINGLE, &stdsyntax, "m/.*/", "foo", "spec" );
+ (void)option_register(o, "uid", 'u', OPT_SINGLE, &stdsyntax, "m/.*/", "foo", "number|name" );
+ (void)option_register(o, "restrictheader", 'r', OPT_MULTI, &stdsyntax, "m/.*/", "foo", "regex" );
+ (void)option_register(o, "newsgroup", NUL, OPT_MULTI, &stdsyntax, "m/.*/", "foo", "newsgroup");
+ //val_apply(o->vo, "", 9, dumper, "all" );
{
int i;
@@ -515,39 +559,55 @@
poptCon = popt_getcontext(NULL, argc, (const char **)argv, o->pt, 0);
popt_setotheroptionhelp(poptCon, "[OPTIONS]* [newsgroup ...]");
- printf("DEBUG: argc=%d\n", argc);
+ //printf("DEBUG: argc=%d\n", argc);
if (argc < 2) {
popt_printusage(poptCon, stderr, 0);
exit(1);
}
while ((i = popt_getnextopt(poptCon)) >= 0) {
(void)option_find(o, i, &ocp);
- if (ocp->type == OPT_FLAG)
- ocp->cb(ocp, "ohne", ocp->cbctx);
- else
- ocp->cb(ocp, cp = popt_getoptarg(poptCon), ocp->cbctx);
- printf("DEBUG: popt_getnextopt returned %d \"%s\", \"%s\"\n", i, o->pt[i].longName, ocp->longname);
- printf("DEBUG: popt_getoptarg returned \"%s\"\n", cp);
+ printf("DEBUG: ocp->type=%d\n", ocp->type);
+ if (ocp->cb != NULL)
+ ocp->cb(ocp, cp = (ocp->type == OPT_FLAG ? NULL : (char *)popt_getoptarg(poptCon)), ocp->cbctx);
+ //printf("DEBUG: popt_getnextopt returned %d \"%s\", \"%s\"\n", i, o->pt[i].longName, ocp->longname);
+ //printf("DEBUG: popt_getoptarg returned \"%s\"\n", cp);
}
- printf("DEBUG: current popt error is \"%s\"(%d)\n", popt_strerror(i), i);
- printf("DEBUG: ----\n");
+ //printf("DEBUG: current popt error is \"%s\"(%d)\n", popt_strerror(i), i);
+ //printf("DEBUG: ----\n");
while ((cp = (char *)popt_getarg(poptCon)) != NULL) {
- printf("DEBUG: popt_getarg returned \"%s\"\n", cp);
+ //printf("DEBUG: popt_getarg returned \"%s\"\n", cp);
}
- printf("DEBUG: current popt error is \"%s\"(%d)\n", popt_strerror(i), i);
+ //printf("DEBUG: current popt error is \"%s\"(%d)\n", popt_strerror(i), i);
popt_freecontext(poptCon);
}
+ val_apply(o->vo, "", 9, dumper, "all" );
return OPTION_OK;
}
lmtp2nntp_option_rc_t option_destroy(lmtp2nntp_option_t *o)
{
+ optionconfig_t *oc;
+ int i;
+
if (o == NULL)
return OPTION_ERR_ARG;
+ oc = o->first;
+ while (oc != NULL) {
+ if (oc->type == OPT_SINGLE && oc->data.s != NULL)
+ free(oc->data.s);
+ if (oc->type == OPT_MULTI && oc->data.m != NULL) {
+ for (i = 0; i < oc->ndata; i++)
+ if (oc->data.m[i] == NULL)
+ break;
+ else
+ free(oc->data.m[i]);
+ free(oc->data.m);
+ }
+ oc = oc->next;
+ }
if (o->vo != NULL)
val_destroy(o->vo);
-
free(o);
return OPTION_OK;
|