/*++ /* NAME /* db_common 3 /* SUMMARY /* utilities common to network based dictionaries /* SYNOPSIS /* #include "db_common.h" /* /* int db_common_parse(dict, ctx, format, query) /* DICT *dict; /* void **ctx; /* const char *format; /* int query; /* /* void db_common_free_context(ctx) /* void *ctx; /* /* int db_common_expand(ctx, format, value, key, buf, quote_func); /* void *ctx; /* const char *format; /* const char *value; /* const char *key; /* VSTRING *buf; /* void (*quote_func)(DICT *, const char *, VSTRING *); /* /* int db_common_check_domain(domain_list, addr); /* STRING_LIST *domain_list; /* const char *addr; /* /* void db_common_sql_build_query(query,parser); /* VSTRING *query; /* CFG_PARSER *parser; /* /* DESCRIPTION /* This module implements utilities common to network based dictionaries. /* /* \fIdb_common_parse\fR parses query and result substitution templates. /* It must be called for each template before any calls to /* \fIdb_common_expand\fR. The \fIctx\fR argument must be initialized to /* a reference to a (void *)0 before the first template is parsed, this /* causes memory for the context to be allocated and the new pointer is /* stored in *ctx. When the dictionary is closed, this memory must be /* freed with a final call to \fBdb_common_free_context\fR. /* /* Calls for additional templates associated with the same map must use the /* same ctx argument. The context accumulates run-time lookup key and result /* validation information (inapplicable keys or results are skipped) and is /* needed later in each call of \fIdb_common_expand\fR. A non-zero return /* value indicates that data-dependent '%' expansions were found in the input /* template. /* /* db_common_alloc() provides a way to use db_common_parse_domain() /* etc. without prior db_common_parse() call. /* /* \fIdb_common_expand\fR expands the specifiers in \fIformat\fR. /* When the input data lacks all fields needed for the expansion, zero /* is returned and the query or result should be skipped. Otherwise /* the expansion is appended to the result buffer (after a comma if the /* result buffer is not empty). /* /* If not NULL, the \fBquote_func\fR callback performs database-specific /* quoting of each variable before expansion. /* \fBvalue\fR is the lookup key for query expansion and result for result /* expansion. \fBkey\fR is NULL for query expansion and the lookup key for /* result expansion. /* .PP /* The following '%' expansions are performed on \fBvalue\fR: /* .IP %% /* A literal percent character. /* .IP %s /* The entire lookup key \fIaddr\fR. /* .IP %u /* If \fBaddr\fR is a fully qualified address, the local part of the /* address. Otherwise \fIaddr\fR. /* .IP %d /* If \fIaddr\fR is a fully qualified address, the domain part of the /* address. Otherwise the query against the database is suppressed and /* the lookup returns no results. /* /* The following '%' expansions are performed on the lookup \fBkey\fR: /* .IP %S /* The entire lookup key \fIkey\fR. /* .IP %U /* If \fBkey\fR is a fully qualified address, the local part of the /* address. Otherwise \fIkey\fR. /* .IP %D /* If \fIkey\fR is a fully qualified address, the domain part of the /* address. Otherwise the query against the database is suppressed and /* the lookup returns no results. /* .PP /* \fIdb_common_check_domain\fR() checks the domain list so /* that query optimization can be performed. The result is >0 /* (match found), 0 (no match), or <0 (dictionary error code). /* /* .PP /* \fIdb_common_sql_build_query\fR builds the "default"(backwards compatible) /* query from the 'table', 'select_field', 'where_field' and /* 'additional_conditions' parameters, checking for errors. /* /* DIAGNOSTICS /* Fatal errors: invalid substitution format, invalid string_list pattern, /* insufficient parameters. /* SEE ALSO /* dict(3) dictionary manager /* string_list(3) string list pattern matching /* match_ops(3) simple string or host pattern matching /* LICENSE /* .ad /* .fi /* The Secure Mailer license must be distributed with this software. /* AUTHOR(S) /* Wietse Venema /* IBM T.J. Watson Research /* P.O. Box 704 /* Yorktown Heights, NY 10598, USA /* /* Wietse Venema /* Google, Inc. /* 111 8th Avenue /* New York, NY 10011, USA /* /* Liviu Daia /* Institute of Mathematics of the Romanian Academy /* P.O. BOX 1-764 /* RO-014700 Bucharest, ROMANIA /* /* Jose Luis Tallon /* G4 J.E. - F.I. - U.P.M. /* Campus de Montegancedo, S/N /* E-28660 Madrid, SPAIN /* /* Victor Duchovni /* Morgan Stanley
/*--*/
/* Don't silenty skip empty query string or empty lookup results. */ if (*value == 0) { if (key)
msg_warn("table \"%s:%s\": empty lookup result for: \"%s\"" " -- ignored", ctx->dict->type, ctx->dict->name, key); else
msg_warn("table \"%s:%s\": empty query string" " -- ignored", ctx->dict->type, ctx->dict->name); return (0);
} if (key) { /* This is a result template and the input value is the result */ if (ctx->flags & (DB_COMMON_VALUE_DOMAIN | DB_COMMON_VALUE_USER)) if ((vdomain = strrchr(value, '@')) != 0)
++vdomain;
/* The result format may use the local or domain part of the key */ if (ctx->flags & (DB_COMMON_KEY_DOMAIN | DB_COMMON_KEY_USER)) if ((kdomain = strrchr(key, '@')) != 0)
++kdomain;
/* *Thekeyshouldalreadybecheckedbeforethequery.Noharmifthe *querydidnotgetoptimizedout,sowejustissueawarning.
*/ if (((!kdomain || !*kdomain) && (ctx->flags & DB_COMMON_KEY_DOMAIN) != 0)
|| (kdomain == key + 1 && (ctx->flags & DB_COMMON_KEY_USER) != 0)) {
msg_warn("%s: %s: lookup key '%s' skipped after query", myname,
ctx->dict->name, value); return (0);
}
} else { /* This is a query template and the input value is the lookup key */ if (ctx->flags & (DB_COMMON_KEY_DOMAIN | DB_COMMON_KEY_USER)) if ((vdomain = strrchr(value, '@')) != 0)
++vdomain;
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.30Bemerkung:
(vorverarbeitet am 2026-08-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.