From 43ba0c3da9ff8913f0286a01a82875fa59601dc0 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Mon, 21 Dec 2009 15:57:21 +0200 Subject: Namespace cleanup. Rename "access method" to "dictionary". All sources affected. * src/method.c: renamed to... * src/dictionary.c: ... this. --- doc/wydawca.texi | 177 ++++++++++++++++++++------------------ src/Makefile.am | 2 +- src/builtin.c | 46 +++++----- src/builtin.h | 12 +-- src/config.c | 104 +++++++++++----------- src/dictionary.c | 228 +++++++++++++++++++++++++++++++++++++++++++++++++ src/mail.c | 28 +++--- src/meta.c | 10 +-- src/method.c | 226 ------------------------------------------------ src/process.c | 14 +-- src/sql.c | 44 +++++----- src/sql.h | 20 ++--- src/triplet.c | 8 +- src/verify.c | 32 +++---- src/wydawca.h | 60 ++++++------- tests/etc/wydawca.rcin | 4 +- 16 files changed, 514 insertions(+), 501 deletions(-) create mode 100644 src/dictionary.c delete mode 100644 src/method.c diff --git a/doc/wydawca.texi b/doc/wydawca.texi index a136fd6..04b599f 100644 --- a/doc/wydawca.texi +++ b/doc/wydawca.texi @@ -92,7 +92,7 @@ How to Configure @command{wydawca}. * Syntax:: Configuration file syntax. * syslog:: * sql:: -* access methods:: +* dictionaries:: * archivation:: * spool:: * statistics:: @@ -105,13 +105,13 @@ Configuration file syntax * Statements:: * Preprocessor:: -Access Methods +Dictionaries * sql type:: * builtin type:: * external type:: -SQL Access Methods +SQL Dictionary * project-owner-sql:: * project-uploader-sql:: @@ -130,13 +130,13 @@ Mail Notification @chapter Introduction to Wydawca @cindex introduction Let's begin with a short synopsis. Suppose you run a developer's -site, like, e.g. @indicateurl{gnu.org}. You have at least two +site, like, e.g. @indicateurl{gnu.org}. You have two @dfn{distribution @acronym{URL}s}: @indicateurl{ftp.gnu.org}, which distributes stable versions of the software, and @indicateurl{alpha.gnu.org}, which distributes alpha and pre-test -versions. Now, package maintainers should have a way of uploading -their packages to one of these sites. The currently accepted scheme -is described in +versions. Now, package maintainers need to have a way of uploading +their packages to one of these sites. This is done using the +@dfn{Automated FTP Upload} method, as described in @ifnothtml @ref{Automated FTP Uploads, Automated FTP Uploads, Automated FTP Uploads, maintain, Information for maintainers of GNU software}. @@ -157,16 +157,17 @@ corresponding to a certain distribution @acronym{URL}. For example, @item @file{/incoming/ftp} @tab @indicateurl{ftp.gnu.org} @item @file{/incoming/alpha} @tab @indicateurl{alpha.gnu.org} @end multitable +@* @cindex @acronym{PGP} @cindex detached signature @cindex signature, detached - Now, if the maintainer of the project @samp{foo} wishes to make a release + Now, if maintainer of the project @samp{foo} wishes to make a release of the stable version @file{foo-1.0.tar.gz}, he first creates a detached signature @file{foo-1.0.tar.gz.sig}. Then he creates a special -@dfn{directive} file, that contains information about where the +@dfn{directive} file, which contains information about where the distributed tarball must be placed, and clear-signs it using his -@acronym{PGP} key, thus obtaining file +@acronym{PGP} key, thus obtaining the file @file{foo-1.0.tar.gz.directive.asc}. Finally, he uploads these three files (a @dfn{triplet}) to the upload site, storing them into the directory @file{/incoming/ftp}. @@ -179,9 +180,9 @@ their distribution sites. @command{Wydawca} is such a release submission daemon. It is able to handle any number of @samp{source/destination} pairs (called -@dfn{spools}, offers an extensible logging and mail notification -mechanism, allowing both package maintainers and site administrators -to be immediately notified about any occurring problems. +@dfn{spools}) in real time, and offers an extensible logging and mail +notification mechanism, allowing both package maintainers and site +administrators to be immediately notified about any occurring problems. @command{Wydawca} supports version 1.1 of directory file, as described in @@ -224,7 +225,7 @@ that case. upload and corresponding distribution directories. In @command{wydawca} terminology, upload directories are also called @dfn{source}, and distribution directories -- @dfn{destination} -directories. The file also supplies all the information +directories. The configuration file also supplies all the information necessary to access user and project databases. When started, @command{wydawca} scans each source directory and @@ -235,9 +236,9 @@ supplied with each upload and that contains directive regarding the placement of the uploaded files. A @dfn{triplet} is a standard entity, consisting of three files: a clear-signed directive file, a file to be distributed, and a detached signature of the latter. -In some special cases, a clear-signed directive file alone is valid, -namely when it contains only @dfn{standalone directives}, as described -in +In some special cases, a clear-signed directive file alone is valid. +This happens when it contains only @dfn{standalone directives}, as +described in @ifnothtml @ref{FTP Upload Directive File - v1.1, Standalone directives, Standalone directives, @@ -248,26 +249,38 @@ maintain, Information for maintainers of GNU software}. Standalone directives}. @end ifhtml - Each @dfn{incomplete} triplet, i.e. such that misses one or more +@cindex triplet, incomplete +@cindex incomplete triplet +@cindex triplet, expired +@cindex expired triplet + Each @dfn{incomplete} triplet, i.e. a triplet missing one or more necessary files, is then verified by checking if the modification date of its oldest file is older than a predefined amount of time -(@FIXME-pxref{file-sweep-time}), and if so, all files from this triplet are -removed (an @dfn{expired triplet}). This gives users the possibility -to restart interrupted or otherwise broken uploads later. - - Then, the utility ensures that each of the remaining triplets is -created by a single person. Any triplets that do not are immediately -removed. +(@FIXME-pxref{file-sweep-time}). If so, the triplet is considered +@dfn{expired}, and all its files are removed. This gives users the +possibility to restart interrupted or otherwise broken uploads later. +@cindex dictionary @cindex @acronym{PGP} + After completing these preliminary stages, @command{wydawca} +analyzes the directive file and extracts the project name +from it. Using this name as a key, it looks up in the @dfn{project +dictionary} a list of users authorized to make uploads for this +project. This list contains user names and their corresponding public +@acronym{PGP} keys. @command{Wydawca} tries to verify the directive +file using each @acronym{PGP} key from this list, until a matching +key is found, or the list in exhausted. In the latter case, the +triplet is rejected. Otherwise, the key and its owner are remembered +for the next step. + +@cindex detached signature @cindex detached signature @cindex signature, detached - Then, @acronym{PGP} signatures of directive files and any detached -signatures (if available) are verified. If they do not match public -keys of the user who uploaded the triplet, such a triplet is -discarded. + In this step, the uploaded file and its detached signature +are verified. If they do not match the public key obtained in the +previous step, the triplet is rejected. - Finally, the directives from each directive file are executed. On + Finally, directives from the directive file are executed. On this stage of the processing, the uploaded files are actually moved to their destination directories, requested symbolic links are created, etc. @@ -387,7 +400,7 @@ directives any time by running @command{wydawca --config-help}. * Syntax:: Configuration file syntax. * syslog:: * sql:: -* access methods:: +* dictionaries:: * archivation:: * spool:: * statistics:: @@ -860,7 +873,7 @@ sql @var{id} @{ Here, @var{id} is a string uniquely identifying this database. It is used by another configuration statements (e.g. by -access methods, see the next section) to refer to this +dictionaries, see the next section) to refer to this database. @end deffn @@ -904,21 +917,21 @@ sql default @{ @end group @end smallexample -@node access methods -@section Access Methods -@cindex Access method +@node dictionaries +@section Dictionaries +@cindex dictionaries @cindex @acronym{PGP} key - -An @dfn{access method} defines the ways to retrieve user information +@UNREVISED +A @dfn{dictionary} defines the ways to retrieve user information necessary to verify the submission. This information can be, for example, the user's @acronym{PGP} key or his permissions on a project. - Access methods are defined in configuration file using the + Dictionary is defined in configuration file using the following syntax: -@deffn {Config} access-method +@deffn {Config} dictionary @smallexample -access-method @var{method-name} @{ +dictionary @var{dict-id} @{ type @var{type}; query @var{string}; params (@var{param1},@var{param2},...); @@ -926,14 +939,14 @@ access-method @var{method-name} @{ @end smallexample @end deffn - Access method statements can appear either in the global scope of + A @code{dictionary} statement can appear either in the global scope of the configuration file, or inside a @code{spool} statement (@pxref{spool}). Global definitions affect all directory pairs in the configuration file, and ones inside a @code{directory} statement override them for that particular directory pair. -There are two access methods, identified by the value of -@var{method-name} tag: +There are two dictionaries, identified by the value of +@var{dict-id} tag: @table @asis @kwindex project-owner @@ -949,10 +962,10 @@ order. the users that are allowed to make uploads for the project. @end table -The sub-statements of @code{access-method} are: +The sub-statements of @code{dictionary} are: -@deffn {Config: access-method} type @var{name} -Defines the type of this method. @var{Name} is one of the following: +@deffn {Config: dictionary} type @var{name} +Defines the type of this dictionary. @var{Name} is one of the following: @table @asis @kwindex builtin @@ -966,14 +979,14 @@ Defines the type of this method. @var{Name} is one of the following: @kwindex external @item external - Retrieve data using an external program. This method is reserved for -future use. + Retrieve data using an external program. This dictionary type is +reserved for future use. @end table -See below for a detailed description of these access methods. +See below for a detailed description of these dictionary types. @end deffn -@deffn {Config: access-method} query @var{string} +@deffn {Config: dictionary} query @var{string} Sets the query used for retrieving the data. The @var{string} is subject to meta-variable interpretation (@pxref{meta-interpretation}). The following meta-variables are defined: @@ -1012,12 +1025,12 @@ Spool source directory (@pxref{spool, source}). @itemx user @itemx user:name The system name of the user that submitted the triplet. This is -defined only in @samp{project-owner} access method. +defined only for @samp{project-owner} dictionaries. @end table @end deffn -@deffn {Config: access-method} params (@var{param1}, @var{param2}, ...) -Supplies additional parameters for the method. +@deffn {Config: dictionary} params (@var{param1}, @var{param2}, ...) +Supplies additional parameters. @end deffn @menu @@ -1027,9 +1040,9 @@ Supplies additional parameters for the method. @end menu @node sql type -@subsection SQL Access Methods -@cindex sql access type -Access methods of @samp{sql} type retrieve information from an +@subsection SQL Dictionary +@cindex sql dictionary +Dictionaries of @samp{sql} type retrieve information from an @acronym{SQL} database (as of version @value{VERSION}, only @samp{MySQL} databases are supported). @@ -1042,8 +1055,7 @@ which determines database name and user credentials needed to access it. @cindex Savane The following sub-nodes contain sample definitions for the -access methods using the @code{sql} type. They are based -on the database structure used in +@code{sql} dictionaries. They are based on the database structure used in @uref{http://gna.org/projects/savane, @command{Savane} system}. @menu @@ -1059,7 +1071,7 @@ on the database structure used in consisting of two columns: an email address and a user name, in this order. @smallexample -access-method project-owner @{ +dictionary project-owner @{ type sql; params (default); query "SELECT user.email, user.realname " @@ -1077,7 +1089,7 @@ access-method project-owner @{ @UNREVISED @smallexample -access-method project-owner @{ +dictionary project-owner @{ type sql; params (default); query "SELECT user.email, user.realname " @@ -1090,15 +1102,15 @@ access-method project-owner @{ @end smallexample @node builtin type -@subsection Built-in access methods -@cindex builtin access type +@subsection Built-in Dictionary +@cindex builtin dictionary @WRITEME @node external type -@subsection External access methods -@cindex external access type +@subsection External Dictionary +@cindex external dictionary -As of version @value{VERSION} this access type is not yet +As of version @value{VERSION} this dictionary is not yet implemented. @node archivation @@ -1275,7 +1287,7 @@ archive-signatures no; A @dfn{distribution spool} defines the location of the source directory and the corresponding distribution (or @dfn{destination}) directory. It may also set archivation type, -various access methods and notifications for that directory, thus overriding +various dictionaries and notifications for that directory, thus overriding global settings. Distribution spool is defined in the configuration file by the @@ -1289,7 +1301,7 @@ spool @var{tag} @{ source @var{dir}; destination @var{dir}; file-sweep-time @var{interval}; - access-method @{ @dots{} @} + dictionary @{ @dots{} @} archive @{ @dots{} @} notify-event @{ @dots{} @} @} @@ -1338,9 +1350,9 @@ Configure spool-specific archivation. @xref{archivation}, for its description. @end deffn -@deffn {Config: spool} access-method @var{tag} @{ @dots{} @} -Configure spool-specific access-method. @xref{access -methods}, for a detailed discussion of this statement. +@deffn {Config: spool} dictionary @var{tag} @{ @dots{} @} +Configure spool-specific dictionary. @xref{dictionaries}, for a +detailed discussion of this statement. @end deffn @deffn {Config: spool} notify-event @{ @dots{} @} @@ -1364,7 +1376,7 @@ spool ftp @{ @end smallexample @noindent -This spool defines no particular archivation type, access method or +This spool defines no particular archivation type, dictionary or notifications, so it will inherit these settings from the global configuration. @@ -1885,13 +1897,12 @@ The system administrator, as defined in @code{admin-address} statement @kwindex owner @item owner Administrators of the project for which the files where -uploaded. Their addresses are retrieved using the @samp{project-owner} -access method (@pxref{access methods}). +uploaded. Their addresses are retrieved from the @samp{project-owner} +dictionary (@pxref{dictionaries}). @kwindex user @item user -The user who uploaded files. The user address is returned by -@samp{user-data} access method (@pxref{access methods}). +The user who uploaded files. @end table @end deffn @@ -2202,15 +2213,15 @@ notify-event @{ message @var{text-or-id:@i{}}; @} -# Define access method -access-method @var{ident} @{ - # Method type +# Define a dictionary +dictionary @var{ident} @{ + # Dictionary type type @var{type:@i{}}; # Query template query @var{string:@i{}}; - # Set method parameters + # Set dictionary parameters params @var{arg:@i{}}; @} @@ -2231,15 +2242,15 @@ spool @var{tag:@i{}} @{ # Define file sweep time file-sweep-time @var{interval:@i{}}; - # Define access method - access-method @var{ident} @{ - # Method type + # Define a dictionary + dictionary @var{ident} @{ + # Dictionary type type @var{type:@i{}}; # Query template query @var{string:@i{}}; - # Set method parameters + # Set dictionary parameters params @var{arg:@i{}}; @} diff --git a/src/Makefile.am b/src/Makefile.am index c96fbcb..a599118 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -20,6 +20,7 @@ wydawca_SOURCES=\ builtin.h\ cmdline.h\ config.c\ + dictionary.c\ directive.c\ diskio.c\ exec.c\ @@ -28,7 +29,6 @@ wydawca_SOURCES=\ job.c\ lock.c\ meta.c\ - method.c\ net.c\ pidfile.c\ process.c\ diff --git a/src/builtin.c b/src/builtin.c index 73b1d23..5588fd6 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -20,21 +20,21 @@ #include "regex.h" int -builtin_init (struct access_method *meth) +builtin_init (struct dictionary *dict) { return 0; } int -builtin_done (struct access_method *meth) +builtin_done (struct dictionary *dict) { return 0; } void * -builtin_open (struct access_method *meth) +builtin_open (struct dictionary *dict) { - return meth; + return dict; } #define CMP_EXACT 0 @@ -159,7 +159,7 @@ static int default_ncol[] = { }; int -builtin_run (struct access_method *meth, void *handle, const char *req) +builtin_lookup (struct dictionary *dict, void *handle, const char *req) { int i; int rc; @@ -168,19 +168,19 @@ builtin_run (struct access_method *meth, void *handle, const char *req) int flags = 0; strcmp_fn cmpfn = cmp_exact; struct builtin_data_storage *bds; - int ncol = default_ncol[meth->id]; + int ncol = default_ncol[dict->id]; - if (meth->parmc == 0) + if (dict->parmc == 0) { - meth->nrow = meth->ncol = 0; + dict->nrow = dict->ncol = 0; return 0; } obstack_init (&stk); - for (i = 0; i < meth->parmc; i++) + for (i = 0; i < dict->parmc; i++) { - char *pat = meth->parmv[i]; + char *pat = dict->parmv[i]; if (pat[0] == '/') { @@ -189,7 +189,7 @@ builtin_run (struct access_method *meth, void *handle, const char *req) continue; } - if (i + ncol >= meth->parmc) + if (i + ncol >= dict->parmc) break; if (cmpfn (pat, req, flags)) @@ -197,7 +197,7 @@ builtin_run (struct access_method *meth, void *handle, const char *req) size_t j; for (j = 1; j <= ncol; j++) { - char *val = meth->parmv[i + j]; + char *val = dict->parmv[i + j]; obstack_grow (&stk, val, strlen (val) + 1); } count++; @@ -206,8 +206,8 @@ builtin_run (struct access_method *meth, void *handle, const char *req) i += ncol; } - meth->nrow = count; - meth->ncol = ncol; + dict->nrow = count; + dict->ncol = ncol; if (count == 0) { @@ -234,32 +234,32 @@ builtin_run (struct access_method *meth, void *handle, const char *req) rc = 0; } - meth->storage = bds; + dict->storage = bds; return rc; } int -builtin_free_result (struct access_method *method, void *handle) +builtin_free_result (struct dictionary *dict, void *handle) { - if (method->storage) + if (dict->storage) { - struct builtin_data_storage *bds = method->storage; + struct builtin_data_storage *bds = dict->storage; obstack_free (&bds->stk, NULL); free (bds->wp); free (bds); - method->storage = NULL; + dict->storage = NULL; } return 0; } int -builtin_get (struct access_method *method, void *handle, +builtin_get (struct dictionary *dict, void *handle, unsigned nrow, unsigned ncol) { - struct builtin_data_storage *bds = method->storage; - char *str = bds->wp[nrow * method->ncol + ncol]; - method_copy_result (method, str, strlen (str)); + struct builtin_data_storage *bds = dict->storage; + char *str = bds->wp[nrow * dict->ncol + ncol]; + dictionary_copy_result (dict, str, strlen (str)); return 0; } diff --git a/src/builtin.h b/src/builtin.h index 500a6cb..dd52bce 100644 --- a/src/builtin.h +++ b/src/builtin.h @@ -14,9 +14,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -int builtin_init (struct access_method *); -int builtin_done (struct access_method *); -void *builtin_open (struct access_method *); -int builtin_get (struct access_method *, void *, unsigned, unsigned); -int builtin_run (struct access_method *, void *, const char *); -int builtin_free_result (struct access_method *, void *); +int builtin_init (struct dictionary *); +int builtin_done (struct dictionary *); +void *builtin_open (struct dictionary *); +int builtin_get (struct dictionary *, void *, unsigned, unsigned); +int builtin_lookup (struct dictionary *, void *, const char *); +int builtin_free_result (struct dictionary *, void *); diff --git a/src/config.c b/src/config.c index f0a7042..15c191c 100644 --- a/src/config.c +++ b/src/config.c @@ -26,7 +26,7 @@ static struct archive_descr default_archive_descr = { no_backups }; -static struct access_method *default_access_method[access_method_count]; +static struct dictionary *default_dictionary[dictionary_count]; static struct notification *default_notification = NULL; @@ -953,44 +953,44 @@ cb_notify_event (enum grecs_callback_command cmd, -static enum access_method_type -string_to_access_method_type (const char *str) +static enum dictionary_type +string_to_dictionary_type (const char *str) { if (strcmp (str, "sql") == 0) - return method_sql; + return dictionary_sql; else if (strcmp (str, "builtin") == 0) - return method_builtin; + return dictionary_builtin; else if (strcmp (str, "external") == 0) - return method_external; + return dictionary_external; else - return method_none; + return dictionary_none; } static int -cb_access_method_type (enum grecs_callback_command cmd, +cb_dictionary_type (enum grecs_callback_command cmd, grecs_locus_t *locus, void *varptr, grecs_value_t *value, void *cb_data) { - enum access_method_type *ptype = varptr; + enum dictionary_type *ptype = varptr; if (assert_string_arg (locus, cmd, value)) return 1; - *ptype = string_to_access_method_type (value->v.string); - if (*ptype == method_none) - grecs_error (locus, 0, _("unknown access method: %s"), value->v.string); + *ptype = string_to_dictionary_type (value->v.string); + if (*ptype == dictionary_none) + grecs_error (locus, 0, _("unknown dictionary type: %s"), value->v.string); return 0; } static int -cb_access_method_params (enum grecs_callback_command cmd, +cb_dictionary_params (enum grecs_callback_command cmd, grecs_locus_t *locus, void *varptr, grecs_value_t *value, void *cb_data) { - struct access_method *meth = varptr; + struct dictionary *meth = varptr; size_t size; if (cmd != grecs_callback_set_value) @@ -1034,21 +1034,21 @@ cb_access_method_params (enum grecs_callback_command cmd, return 0; } -static struct grecs_keyword access_method_kw[] = { - { "type", N_("type"), N_("Method type"), - grecs_type_string, NULL, offsetof(struct access_method, type), - cb_access_method_type }, +static struct grecs_keyword dictionary_kw[] = { + { "type", N_("type"), N_("Dictionary type"), + grecs_type_string, NULL, offsetof(struct dictionary, type), + cb_dictionary_type }, { "query", N_("string"), N_("Query template"), - grecs_type_string, NULL, offsetof(struct access_method, query) }, - { "params", N_("arg"), N_("Set method parameters"), + grecs_type_string, NULL, offsetof(struct dictionary, query) }, + { "params", N_("arg"), N_("Set dictionary parameters"), grecs_type_string|GRECS_LIST, NULL, 0, - cb_access_method_params }, + cb_dictionary_params }, { NULL } }; int -string_to_access_method_id (grecs_locus_t *locus, - const char *str, enum access_method_id *idp) +string_to_dictionary_id (grecs_locus_t *locus, + const char *str, enum dictionary_id *idp) { static const char *id_str[] = { "project-uploader", @@ -1056,13 +1056,13 @@ string_to_access_method_id (grecs_locus_t *locus, NULL }; static int id_num[] = { - project_uploader_method, - project_owner_method + project_uploader_dict, + project_owner_dict }; ARGMATCH_VERIFY (id_str, id_num); int rc, res; - rc = string_to ("access method", str, + rc = string_to ("dictionary", str, id_str, id_num, &res, locus); @@ -1071,15 +1071,15 @@ string_to_access_method_id (grecs_locus_t *locus, } static int -cb_access_method (enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, - grecs_value_t *value, - void *cb_data) +cb_dictionary (enum grecs_callback_command cmd, + grecs_locus_t *locus, + void *varptr, + grecs_value_t *value, + void *cb_data) { - struct access_method **pmeth, *meth; + struct dictionary **pmeth, *meth; void **pdata = cb_data; - enum access_method_id id; + enum dictionary_id id; switch (cmd) { case grecs_callback_section_begin: @@ -1088,10 +1088,10 @@ cb_access_method (enum grecs_callback_command cmd, grecs_error(locus, 0, _("tag must be a string")); return 0; } - if (string_to_access_method_id (locus, value->v.string, &id)) + if (string_to_dictionary_id (locus, value->v.string, &id)) return 1; - pmeth = (struct access_method **) varptr + id; - *pmeth = method_new (id, method_builtin); + pmeth = (struct dictionary **) varptr + id; + *pmeth = dictionary_new (id, dictionary_builtin); *pdata = *pmeth; break; @@ -1099,17 +1099,17 @@ cb_access_method (enum grecs_callback_command cmd, meth = *pdata; switch (meth->type) { - case method_sql: + case dictionary_sql: if (meth->parmc == 0 || !meth->parmv[0]) { grecs_error (locus, 0, _("SQL connection is not declared")); - meth->type = method_none; + meth->type = dictionary_none; } else if (!sql_connection_exists_p (meth->parmv[0])) { grecs_error (locus, 0, _("SQL connection `%s' not declared"), meth->parmv[0]); - meth->type = method_none; + meth->type = dictionary_none; } break; @@ -1171,9 +1171,9 @@ static struct grecs_keyword spool_kw[] = { { "file-sweep-time", N_("interval"), N_("Define file sweep time"), grecs_type_string, NULL, offsetof(struct spool, file_sweep_time), cb_interval }, - { "access-method", N_("ident"), N_("Define access method"), - grecs_type_section, NULL, offsetof(struct spool, access_method), - cb_access_method, NULL, access_method_kw }, + { "dictionary", N_("ident"), N_("Define data dictionary"), + grecs_type_section, NULL, offsetof(struct spool, dictionary), + cb_dictionary, NULL, dictionary_kw }, { "archive", N_("type: string"), N_("Set up archivation"), grecs_type_section, NULL, offsetof(struct spool, archive), cb_archive, NULL, archive_kw }, @@ -1208,8 +1208,8 @@ cb_spool (enum grecs_callback_command cmd, spool = xzalloc (sizeof (*spool)); spool->tag = xstrdup (value->v.string); spool->file_sweep_time = file_sweep_time; - for (i = 0; i < NITEMS (spool->access_method); i++) - spool->access_method[i] = default_access_method[i]; + for (i = 0; i < NITEMS (spool->dictionary); i++) + spool->dictionary[i] = default_dictionary[i]; spool->archive = default_archive_descr; *pdata = spool; break; @@ -1247,11 +1247,11 @@ cb_spool (enum grecs_callback_command cmd, && spool->vtab.test_url (spool->dest_url, locus)) rc = 1; - for (i = 0; i < access_method_count; i++) - if (spool->access_method[i]->type == method_external) + for (i = 0; i < dictionary_count; i++) + if (spool->dictionary[i]->type == dictionary_external) { grecs_error (locus, 0, - _("Sorry, method type `external' is not yet supported")); + _("Sorry, the dictionary type `external' is not yet supported")); rc = 1; } @@ -1452,9 +1452,9 @@ static struct grecs_keyword wydawca_kw[] = { grecs_type_section, &default_notification, 0, cb_notify_event, NULL, notify_event_kw }, - { "access-method", N_("ident"), N_("Define access method"), - grecs_type_section, default_access_method, 0, - cb_access_method, NULL, access_method_kw }, + { "dictionary", N_("ident"), N_("Define data dictionary"), + grecs_type_section, default_dictionary, 0, + cb_dictionary, NULL, dictionary_kw }, { "spool", N_("tag: string"), N_("Define distribution spool"), grecs_type_section, NULL, 0, @@ -1495,6 +1495,6 @@ config_init() if (serv != NULL) grecs_default_port = serv->s_port; - for (i = 0; i < access_method_count; i++) - default_access_method[i] = method_new (i, method_builtin); + for (i = 0; i < dictionary_count; i++) + default_dictionary[i] = dictionary_new (i, dictionary_builtin); } diff --git a/src/dictionary.c b/src/dictionary.c new file mode 100644 index 0000000..c31baf8 --- /dev/null +++ b/src/dictionary.c @@ -0,0 +1,228 @@ +/* wydawca - automatic release submission daemon + Copyright (C) 2007 Sergey Poznyakoff + + Wydawca is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3 of the License, or (at your + option) any later version. + + Wydawca is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with wydawca. If not, see . */ + +#include "wydawca.h" +#include "sql.h" +#include "builtin.h" + +struct dictionary_descr +{ + const char *name; + + int (*init) (struct dictionary *); + int (*done) (struct dictionary *); + int (*free) (struct dictionary *, void *); + + void *(*open) (struct dictionary *); + int (*close) (struct dictionary *, void *); + + int (*get) (struct dictionary *, void *, unsigned, unsigned); + int (*lookup) (struct dictionary *, void *, const char *); + int (*quote) (struct dictionary *, void *, const char *, char **, size_t *); +}; + +static struct dictionary_descr dictionary_tab[] = { + { "none", NULL, NULL, NULL, NULL, NULL, NULL, NULL }, + { "sql", sql_init_dictionary, sql_done_dictionary, sql_free_result, + sql_open, NULL, sql_get_dictionary, sql_lookup_dictionary, sql_quote }, + { "builtin", builtin_init, builtin_done, builtin_free_result, + builtin_open, NULL, + builtin_get, + builtin_lookup }, + { "external", NULL, NULL, NULL, NULL, NULL, NULL, NULL } +}; + +struct dictionary * +dictionary_new (enum dictionary_id id, enum dictionary_type type) +{ + struct dictionary *mp = xmalloc (sizeof mp[0]); + memset (mp, 0, sizeof mp[0]); + mp->id = id; + mp->type = type; + return mp; +} + +int +dictionary_init (struct dictionary *dict) +{ + struct dictionary_descr *mp = dictionary_tab + dict->type; + int rc = 0; + + if (dict->init_passed++) + return 0; + if (debug_level > 1) + { + int i; + logmsg (LOG_DEBUG, _("initializing dictionary: %s \"%s\""), + mp->name, SP (dict->query)); + for (i = 0; i < dict->parmc; i++) + logmsg (LOG_DEBUG, " parmv[%d]=%s", i, dict->parmv[i]); + } + if (mp->init) + rc = mp->init (dict); + if (rc == 0) + dict->init_passed = 1; + return rc; +} + +void * +dictionary_open (struct dictionary *dict) +{ + struct dictionary_descr *mp = dictionary_tab + dict->type; + + if (!mp->open) + return NULL; + return mp->open (dict); +} + +int +dictionary_close (struct dictionary *dict, void *handle) +{ + struct dictionary_descr *mp = dictionary_tab + dict->type; + if (!mp->close) + return 0; + return mp->close (dict, handle); +} + +int +dictionary_done (struct dictionary *dict) +{ + struct dictionary_descr *mp = dictionary_tab + dict->type; + int rc = 0; + + if (dict->init_passed == 0) + return 0; + if (--dict->init_passed) + return 0; + if (debug_level > 1) + { + int i; + logmsg (LOG_DEBUG, _("closing dictionary: %s \"%s\""), + mp->name, SP (dict->query)); + for (i = 0; i < dict->parmc; i++) + logmsg (LOG_DEBUG, " parmv[%d]=%s", i, dict->parmv[i]); + } + if (mp->done) + rc = mp->done (dict); + free (dict->result); + dict->result = NULL; + dict->result_size = 0; + return rc; +} + +int +dictionary_lookup (struct dictionary *dict, void *handle, const char *cmd) +{ + struct dictionary_descr *mp = dictionary_tab + dict->type; + + if (debug_level > 1) + { + if (cmd) + logmsg (LOG_DEBUG, _("dictionary lookup: %s \"%s\""), + mp->name, cmd); + else + logmsg (LOG_DEBUG, _("dictionary lookup: %s"), mp->name); + } + + if (!dict->init_passed) + { + logmsg (LOG_CRIT, + _("INTERNAL ERROR: dictionary %s \"%s\" not initialized"), + mp->name, SP (dict->query)); + return 1; + } + if (!mp->lookup) + { + logmsg (LOG_CRIT, + _("INTERNAL ERROR: no lookup function for dictionary %s \"%s\""), + mp->name, SP (dict->query)); + return 1; + } + if (mp->free) + mp->free (dict, handle); + return mp->lookup (dict, handle, cmd); +} + +unsigned +dictionary_num_rows (struct dictionary *dict) +{ + return dict->nrow; +} + +unsigned +dictionary_num_cols (struct dictionary *dict) +{ + return dict->ncol; +} + +const char * +dictionary_result (struct dictionary *dict, void *handle, + unsigned nrow, unsigned ncol) +{ + struct dictionary_descr *mp = dictionary_tab + dict->type; + + if (nrow >= dict->nrow || ncol >= dict->ncol + || mp->get (dict, handle, nrow, ncol)) + return NULL; + return dict->result; +} + +void +dictionary_copy_result (struct dictionary *dict, const char *res, size_t size) +{ + if (dict->result_size < size + 1) + { + dict->result_size = size + 1; + dict->result = x2realloc (dict->result, &dict->result_size); + } + memcpy (dict->result, res, size); + dict->result[size] = 0; +} + +/* Quote non-printable characters in INPUT. Point *OUTPUT to the malloc'ed + quoted string. Return its length. */ +int +dictionary_quote_string (struct dictionary *dict, void *handle, + const char *input, + char **poutput, size_t *psize) +{ + struct dictionary_descr *mp = dictionary_tab + dict->type; + size_t size; + int quote; + char *output; + + if (!input) + { + *poutput = xmalloc (1); + (*poutput)[0] = 0; + *psize = 1; + return 0; + } + + if (mp->quote) + return mp->quote (dict, handle, input, poutput, psize); + + size = wordsplit_quoted_length (input, 0, "e); + output = xmalloc (size + 1); + wordsplit_quote_copy (output, input, 0); + output[size] = 0; + + *poutput = output; + if (psize) + *psize = size; + return 0; +} + diff --git a/src/mail.c b/src/mail.c index 15c2937..98f6c4a 100644 --- a/src/mail.c +++ b/src/mail.c @@ -498,7 +498,7 @@ get_uploader_email (struct uploader_info *info, struct file_triplet *trp, } mu_address_t -get_recipient (struct access_method *method, struct file_triplet *trp, +get_recipient (struct dictionary *dict, struct file_triplet *trp, const char **errp) { unsigned nrows, ncols, i; @@ -507,32 +507,32 @@ get_recipient (struct access_method *method, struct file_triplet *trp, int rc; void *md; - if (method->type == method_none) + if (dict->type == dictionary_none) { - *errp = N_("access method is not configured"); + *errp = N_("dictionary is not configured"); return NULL; } - md = method_open (method); + md = dictionary_open (dict); if (!md) { - *errp = N_("failed to open access method"); + *errp = N_("failed to open dictionary"); return NULL; } - text = triplet_expand_method_query (method, md, trp); + text = triplet_expand_dictionary_query (dict, md, trp); - rc = method_run (method, md, text); + rc = dictionary_lookup (dict, md, text); free (text); if (rc) { *errp = N_("cannot obtain recipient emails"); - method_close (method, md); + dictionary_close (dict, md); return NULL; } - nrows = method_num_rows (method); - ncols = method_num_cols (method); + nrows = dictionary_num_rows (dict); + ncols = dictionary_num_cols (dict); if (nrows == 0) { @@ -543,19 +543,19 @@ get_recipient (struct access_method *method, struct file_triplet *trp, for (i = 0; i < nrows; i++) { mu_address_t addr; - const char *str = method_result (method, md, i, 0); + const char *str = dictionary_result (dict, md, i, 0); if (mu_address_create (&addr, str)) continue; if (ncols > 0) { - str = method_result (method, md, i, 1); + str = dictionary_result (dict, md, i, 1); if (str) mu_address_set_personal (addr, 1, str); } mu_address_union (&rcpt, addr); mu_address_destroy (&addr); } - method_close (method, md); + dictionary_close (dict, md); return rcpt; } @@ -583,7 +583,7 @@ do_notify (struct file_triplet *trp, enum notification_event ev, break; case notify_owner: - rcpt = get_recipient (trp->spool->access_method[project_owner_method], + rcpt = get_recipient (trp->spool->dictionary[project_owner_dict], trp, &errp); } diff --git a/src/meta.c b/src/meta.c index eb332f5..c415cd0 100644 --- a/src/meta.c +++ b/src/meta.c @@ -51,7 +51,7 @@ find_expansion_word (const char *kw, size_t len, char * meta_expand_string (const char *string, struct metadef *def, void *data, - struct access_method *method, void *handle) + struct dictionary *dict, void *handle) { const char *p, *s; char *res; @@ -82,12 +82,12 @@ meta_expand_string (const char *string, struct metadef *def, void *data, e = strchr (p + 1, '}'); if (e && (s = find_expansion_word (p + 1, e - p - 1, def, data))) { - if (method) + if (dict) { char *newval; size_t len; /* FIXME: Return value? */ - method_quote_string (method, handle, s, &newval, &len); + dictionary_quote_string (dict, handle, s, &newval, &len); obstack_grow (&stk, newval, len); free (newval); } @@ -111,12 +111,12 @@ meta_expand_string (const char *string, struct metadef *def, void *data, len = 1; } - if (method) + if (dict) { char *newval; size_t len; /* FIXME: Return value? */ - method_quote_string (method, handle, s, &newval, &len); + dictionary_quote_string (dict, handle, s, &newval, &len); obstack_grow (&stk, newval, len); free (newval); } diff --git a/src/method.c b/src/method.c deleted file mode 100644 index d5ad0b4..0000000 --- a/src/method.c +++ /dev/null @@ -1,226 +0,0 @@ -/* wydawca - automatic release submission daemon - Copyright (C) 2007 Sergey Poznyakoff - - Wydawca is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 3 of the License, or (at your - option) any later version. - - Wydawca is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with wydawca. If not, see . */ - -#include "wydawca.h" -#include "sql.h" -#include "builtin.h" - -struct method_descr -{ - const char *name; - - int (*init) (struct access_method *); - int (*done) (struct access_method *); - int (*free) (struct access_method *, void *); - - void *(*open) (struct access_method *); - int (*close) (struct access_method *, void *); - - int (*get) (struct access_method *, void *, unsigned, unsigned); - int (*run) (struct access_method *, void *, const char *); - int (*quote) (struct access_method *, void *, const char *, char **, size_t *); -}; - -static struct method_descr method_tab[] = { - { "none", NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - { "sql", sql_init_method, sql_done_method, sql_free_result, - sql_open, NULL, sql_get_method, sql_run_method, sql_quote }, - { "builtin", builtin_init, builtin_done, builtin_free_result, - builtin_open, NULL, - builtin_get, - builtin_run }, - { "external", NULL, NULL, NULL, NULL, NULL, NULL, NULL } -}; - -struct access_method * -method_new (enum access_method_id id, enum access_method_type type) -{ - struct access_method *mp = xmalloc (sizeof mp[0]); - memset (mp, 0, sizeof mp[0]); - mp->id = id; - mp->type = type; - return mp; -} - -int -method_init (struct access_method *method) -{ - struct method_descr *mp = method_tab + method->type; - int rc = 0; - - if (method->init_passed++) - return 0; - if (debug_level > 1) - { - int i; - logmsg (LOG_DEBUG, _("initializing method: %s \"%s\""), - mp->name, SP (method->query)); - for (i = 0; i < method->parmc; i++) - logmsg (LOG_DEBUG, " parmv[%d]=%s", i, method->parmv[i]); - } - if (mp->init) - rc = mp->init (method); - if (rc == 0) - method->init_passed = 1; - return rc; -} - -void * -method_open (struct access_method *method) -{ - struct method_descr *mp = method_tab + method->type; - - if (!mp->open) - return NULL; - return mp->open (method); -} - -int -method_close (struct access_method *method, void *handle) -{ - struct method_descr *mp = method_tab + method->type; - if (!mp->close) - return 0; - return mp->close (method, handle); -} - -int -method_done (struct access_method *method) -{ - struct method_descr *mp = method_tab + method->type; - int rc = 0; - - if (method->init_passed == 0) - return 0; - if (--method->init_passed) - return 0; - if (debug_level > 1) - { - int i; - logmsg (LOG_DEBUG, _("closing method: %s \"%s\""), - mp->name, SP (method->query)); - for (i = 0; i < method->parmc; i++) - logmsg (LOG_DEBUG, " parmv[%d]=%s", i, method->parmv[i]); - } - if (mp->done) - rc = mp->done (method); - free (method->result); - method->result = NULL; - method->result_size = 0; - return rc; -} - -int -method_run (struct access_method *method, void *handle, const char *cmd) -{ - struct method_descr *mp = method_tab + method->type; - - if (debug_level > 1) - { - if (cmd) - logmsg (LOG_DEBUG, _("running method: %s \"%s\""), mp->name, cmd); - else - logmsg (LOG_DEBUG, _("running method: %s"), mp->name); - } - - if (!method->init_passed) - { - logmsg (LOG_CRIT, _("INTERNAL ERROR: method %s \"%s\" not initialized"), - mp->name, SP (method->query)); - return 1; - } - if (!mp->run) - { - logmsg (LOG_CRIT, - _("INTERNAL ERROR: no run function for method %s \"%s\""), - mp->name, SP (method->query)); - return 1; - } - if (mp->free) - mp->free (method, handle); - return mp->run (method, handle, cmd); -} - -unsigned -method_num_rows (struct access_method *method) -{ - return method->nrow; -} - -unsigned -method_num_cols (struct access_method *method) -{ - return method->ncol; -} - -const char * -method_result (struct access_method *method, void *handle, - unsigned nrow, unsigned ncol) -{ - struct method_descr *mp = method_tab + method->type; - - if (nrow >= method->nrow || ncol >= method->ncol - || mp->get (method, handle, nrow, ncol)) - return NULL; - return method->result; -} - -void -method_copy_result (struct access_method *method, const char *res, size_t size) -{ - if (method->result_size < size + 1) - { - method->result_size = size + 1; - method->result = x2realloc (method->result, &method->result_size); - } - memcpy (method->result, res, size); - method->result[size] = 0; -} - -/* Quote non-printable characters in INPUT. Point *OUTPUT to the malloc'ed - quoted string. Return its length. */ -int -method_quote_string (struct access_method *method, void *handle, - const char *input, - char **poutput, size_t *psize) -{ - struct method_descr *mp = method_tab + method->type; - size_t size; - int quote; - char *output; - - if (!input) - { - *poutput = xmalloc (1); - (*poutput)[0] = 0; - *psize = 1; - return 0; - } - - if (mp->quote) - return mp->quote (method, handle, input, poutput, psize); - - size = wordsplit_quoted_length (input, 0, "e); - output = xmalloc (size + 1); - wordsplit_quote_copy (output, input, 0); - output[size] = 0; - - *poutput = output; - if (psize) - *psize = size; - return 0; -} - diff --git a/src/process.c b/src/process.c index a998edb..58df169 100644 --- a/src/process.c +++ b/src/process.c @@ -211,11 +211,11 @@ scan_spool_unlocked (const struct spool *spool, int uc, uid_t *uv) { int i; - for (i = 0; i < access_method_count; i++) + for (i = 0; i < dictionary_count; i++) { - if (method_init (spool->access_method[i])) + if (dictionary_init (spool->dictionary[i])) { - logmsg (LOG_ERR, _("failed to initialize access method %d"), i); + logmsg (LOG_ERR, _("failed to initialize dictionary %d"), i); return; } } @@ -250,11 +250,11 @@ scan_spool (const struct spool *spool, int uc, uid_t *uv) } static void -close_methods (struct spool *spool) +close_dictionaries (struct spool *spool) { int i; - for (i = 0; i < NITEMS (spool->access_method); i++) - method_done (spool->access_method[i]); + for (i = 0; i < NITEMS (spool->dictionary); i++) + dictionary_done (spool->dictionary[i]); } /* Scan all configured update directories */ @@ -271,7 +271,7 @@ scan_all_spools (int uidc, uid_t *uidv) rc++; for (sp = spool_list; sp; sp = sp->next) - close_methods (&sp->spool); + close_dictionaries (&sp->spool); timer_stop ("wydawca"); return rc; } diff --git a/src/sql.c b/src/sql.c index b8c1d42..c81d4fb 100644 --- a/src/sql.c +++ b/src/sql.c @@ -54,16 +54,16 @@ sql_connection_exists_p (const char *ident) return sql_find_connection (ident) != NULL; } -/* Initialize MySQL access method */ +/* Initialize MySQL dictionary */ int -sql_init_method (struct access_method *method) +sql_init_dictionary (struct dictionary *dict) { - struct sqlconn *conn = sql_find_connection (method->parmv[0]); + struct sqlconn *conn = sql_find_connection (dict->parmv[0]); if (!conn) { logmsg (LOG_EMERG, _("INTERNAL ERROR: cannot find SQL connection %s"), - method->parmv[0]); + dict->parmv[0]); abort (); } @@ -78,22 +78,22 @@ sql_init_method (struct access_method *method) conn->socket, 0)) { logmsg (LOG_ERR, _("failed to connect to database %s: error: %s\n"), - method->parmv[0], mysql_error (&conn->mysql)); + dict->parmv[0], mysql_error (&conn->mysql)); return 1; } } - method->storage = conn; + dict->storage = conn; return 0; } void * -sql_open (struct access_method *method) +sql_open (struct dictionary *dict) { - return method->storage; + return dict->storage; } int -sql_free_result (struct access_method *method, void *handle) +sql_free_result (struct dictionary *dict, void *handle) { struct sqlconn *conn = handle; if (conn->result) @@ -104,31 +104,31 @@ sql_free_result (struct access_method *method, void *handle) return 0; } -/* Finish the initialized MySQL access method */ +/* Finish the initialized MySQL dictionary */ int -sql_done_method (struct access_method *method) +sql_done_dictionary (struct dictionary *dict) { - struct sqlconn *conn = method->storage; + struct sqlconn *conn = dict->storage; if (!conn || conn->initcount == 0) return 0; if (--conn->initcount) return 0; - sql_free_result (method, conn); /* FIXME: Not needed */ + sql_free_result (dict, conn); /* FIXME: Not needed */ mysql_close (&conn->mysql); - method->storage = NULL; + dict->storage = NULL; return 0; } /* Execute QUERY using the given access METHOD. Return 0 on success. */ int -sql_run_method (struct access_method *method, void *handle, const char *query) +sql_lookup_dictionary (struct dictionary *dict, void *handle, const char *query) { struct sqlconn *conn = handle; MYSQL *mysql = &conn->mysql; if (!query) { - logmsg (LOG_ERR, _("no query supplied for method %s"), "sql"); + logmsg (LOG_ERR, _("no query supplied for dictionary %s"), "sql"); return 1; } @@ -147,12 +147,12 @@ sql_run_method (struct access_method *method, void *handle, const char *query) return 1; } - method->nrow = mysql_num_rows (conn->result); - method->ncol = mysql_num_fields (conn->result); + dict->nrow = mysql_num_rows (conn->result); + dict->ncol = mysql_num_fields (conn->result); if (debug_level > 1) { logmsg (LOG_DEBUG, _("query returned %u columns in %u rows"), - method->ncol, method->nrow); + dict->ncol, dict->nrow); logmsg (LOG_DEBUG, _("the query was: %s"), query); } @@ -160,7 +160,7 @@ sql_run_method (struct access_method *method, void *handle, const char *query) } int -sql_get_method (struct access_method *method, void *handle, +sql_get_dictionary (struct dictionary *dict, void *handle, unsigned nrow, unsigned ncol) { struct sqlconn *conn = handle; @@ -176,12 +176,12 @@ sql_get_method (struct access_method *method, void *handle, else len = trim_length (row[ncol]); - method_copy_result (method, row[ncol], len); + dictionary_copy_result (dict, row[ncol], len); return 0; } int -sql_quote (struct access_method *method, void *handle, const char *input, +sql_quote (struct dictionary *dict, void *handle, const char *input, char **poutput, size_t *psize) { struct sqlconn *conn = handle; diff --git a/src/sql.h b/src/sql.h index 1780052..cb257de 100644 --- a/src/sql.h +++ b/src/sql.h @@ -35,13 +35,13 @@ void sql_register_conn (struct sqlconn *); int sql_connection_exists_p (const char *); struct sqlconn *sql_find_connection (const char *ident); -int sql_init_method (struct access_method *method); -int sql_done_method (struct access_method *method); -void *sql_open (struct access_method *method); - -int sql_run_method (struct access_method *method, void *handle, - const char *cmd); -int sql_get_method (struct access_method *method, void *handle, - unsigned nrow, unsigned ncol); -int sql_free_result (struct access_method *method, void *handle); -int sql_quote (struct access_method *, void *, const char *, char **, size_t *); +int sql_init_dictionary (struct dictionary *dict); +int sql_done_dictionary (struct dictionary *dict); +void *sql_open (struct dictionary *dict); + +int sql_lookup_dictionary (struct dictionary *dict, void *handle, + const char *cmd); +int sql_get_dictionary (struct dictionary *dict, void *handle, + unsigned nrow, unsigned ncol); +int sql_free_result (struct dictionary *dict, void *handle); +int sql_quote (struct dictionary *, void *, const char *, char **, size_t *); diff --git a/src/triplet.c b/src/triplet.c index 1b0fb18..c4ac957 100644 --- a/src/triplet.c +++ b/src/triplet.c @@ -545,11 +545,11 @@ struct metadef triplet_default_meta[] = { }; char * -triplet_expand_method_query (struct access_method *method, void *handle, - struct file_triplet *trp) +triplet_expand_dictionary_query (struct dictionary *dict, void *handle, + struct file_triplet *trp) { - char *p = meta_expand_string (method->query, triplet_default_meta, trp, - method, handle); + char *p = meta_expand_string (dict->query, triplet_default_meta, trp, + dict, handle); meta_free (triplet_default_meta); return p; } diff --git a/src/verify.c b/src/verify.c index ed5f0cf..1b528aa 100644 --- a/src/verify.c +++ b/src/verify.c @@ -196,7 +196,7 @@ int verify_directive_file (struct file_triplet *trp, const struct spool *spool) { char *command; - struct access_method *method = spool->access_method[project_uploader_method]; + struct dictionary *dict = spool->dictionary[project_uploader_dict]; int rc; void *md; @@ -209,36 +209,36 @@ verify_directive_file (struct file_triplet *trp, const struct spool *spool) if (fill_project_name (trp)) return 1; - md = method_open (method); + md = dictionary_open (dict); if (!md) return 1; - command = triplet_expand_method_query (method, md, trp); + command = triplet_expand_dictionary_query (dict, md, trp); - rc = method_run (method, md, command); + rc = dictionary_lookup (dict, md, command); free (command); if (rc) { logmsg (LOG_ERR, _("cannot get uploaders for %s"), trp->name); - method_close (method, md); + dictionary_close (dict, md); return 1; } - nrows = method_num_rows (method); + nrows = dictionary_num_rows (dict); if (nrows == 0) { logmsg (LOG_ERR, _("found no uploaders for %s"), trp->name); - method_close (method, md); + dictionary_close (dict, md); return 1; } - ncols = method_num_cols (method); + ncols = dictionary_num_cols (dict); if (ncols < 4) { logmsg (LOG_ERR, - _("project-uploader method error: too few columns (%lu)"), + _("project-uploader dictionary error: too few columns (%lu)"), (unsigned long) ncols); - method_close (method, md); + dictionary_close (dict, md); return 1; } @@ -249,16 +249,16 @@ verify_directive_file (struct file_triplet *trp, const struct spool *spool) struct uploader_info info, *ptr; memset (&info, 0, sizeof (info)); - p = method_result (method, md, i, 0); + p = dictionary_result (dict, md, i, 0); if (p) info.name = xstrdup (p); - p = method_result (method, md, i, 1); + p = dictionary_result (dict, md, i, 1); if (p) info.realname = xstrdup (p); - p = method_result (method, md, i, 2); + p = dictionary_result (dict, md, i, 2); if (p) info.email = xstrdup (p); - p = method_result (method, md, i, 3); + p = dictionary_result (dict, md, i, 3); if (p) info.gpg_key = xstrdup (p); @@ -273,7 +273,7 @@ verify_directive_file (struct file_triplet *trp, const struct spool *spool) if (!info.name || !info.realname || !info.gpg_key || !info.email) { logmsg (LOG_ERR, - _("project-uploader method error: malformed row %lu"), + _("project-uploader dictionary error: malformed row %lu"), (unsigned long) i); free (info.name); free (info.realname); @@ -290,7 +290,7 @@ verify_directive_file (struct file_triplet *trp, const struct spool *spool) tail = ptr; } - method_close (method, md); + dictionary_close (dict, md); if (!head) { diff --git a/src/wydawca.h b/src/wydawca.h index 96fd336..d9933d6 100644 --- a/src/wydawca.h +++ b/src/wydawca.h @@ -83,26 +83,26 @@ #define __cat3__(a,b,c) a ## b ## c #define NITEMS(a) (sizeof(a)/sizeof((a)[0])) -enum access_method_id { - project_uploader_method, /* Retrieves names, gpg-keys, emails and - real names of the project uploaders */ - project_owner_method, /* Retrieves names and emails of the project - owners */ - access_method_count +enum dictionary_id { + project_uploader_dict, /* Contains names, gpg-keys, emails and + real names of the project uploaders */ + project_owner_dict, /* Contains names and emails of the project + owners */ + dictionary_count }; -enum access_method_type +enum dictionary_type { - method_none, /* Undefined or no method */ - method_sql, /* Use SQL database */ - method_builtin, /* Use built-in facilities */ - method_external /* Invoke an external program */ + dictionary_none, /* Undefined or no dictionary */ + dictionary_sql, /* Use SQL database */ + dictionary_builtin, /* Use built-in facilities */ + dictionary_external /* Invoke an external program */ }; -struct access_method +struct dictionary { - enum access_method_id id; - enum access_method_type type; /* Access method type */ + enum dictionary_id id; + enum dictionary_type type; /* Dictionary type */ char *query; /* Query template */ int parmc; /* Number of entries in paramv */ char **parmv; /* Parameters. The semantics differs @@ -230,7 +230,7 @@ struct spool time_t file_sweep_time; /* Remove invalid/unprocessed files after this amount of time */ - struct access_method *access_method[access_method_count]; + struct dictionary *dictionary[dictionary_count]; struct archive_descr archive; /* Archivation data */ struct notification *notification; }; @@ -304,7 +304,7 @@ struct metadef }; char *meta_expand_string (const char *string, struct metadef *def, void *data, - struct access_method *method, void *handle); + struct dictionary *dict, void *handle); void meta_free (struct metadef *def); @@ -395,27 +395,27 @@ void register_file (struct file_info *finfo); void enumerate_triplets (const struct spool *); size_t count_collected_triplets (void); char *triplet_expand_param (const char *tmpl, struct file_triplet *trp); -char *triplet_expand_method_query (struct access_method *method, void *handle, +char *triplet_expand_dictionary_query (struct dictionary *dict, void *handle, struct file_triplet *trp); -/* General-purpose method support */ -struct access_method *method_new (enum access_method_id id, - enum access_method_type type); -int method_init (struct access_method *method); -int method_done (struct access_method *method); -void *method_open (struct access_method *method); -int method_close (struct access_method *method, void *handle); -int method_run (struct access_method *method, void *handle, const char *cmd); -void method_copy_result (struct access_method *method, const char *res, +/* General-purpose dictionary support */ +struct dictionary *dictionary_new (enum dictionary_id id, + enum dictionary_type type); +int dictionary_init (struct dictionary *dict); +int dictionary_done (struct dictionary *dict); +void *dictionary_open (struct dictionary *dict); +int dictionary_close (struct dictionary *dict, void *handle); +int dictionary_lookup (struct dictionary *dict, void *handle, const char *cmd); +void dictionary_copy_result (struct dictionary *dict, const char *res, size_t size); -const char *method_result (struct access_method *method, void *handle, +const char *dictionary_result (struct dictionary *dict, void *handle, unsigned nrow, unsigned ncol); -int method_quote_string (struct access_method *method, void *handle, +int dictionary_quote_string (struct dictionary *dict, void *handle, const char *input, char **poutput, size_t *psize); -unsigned method_num_rows (struct access_method *method); -unsigned method_num_cols (struct access_method *method); +unsigned dictionary_num_rows (struct dictionary *dict); +unsigned dictionary_num_cols (struct dictionary *dict); /* Verification functions */ int verify_directive_file (struct file_triplet *trp, diff --git a/tests/etc/wydawca.rcin b/tests/etc/wydawca.rcin index 2ac40e9..54c1dc7 100644 --- a/tests/etc/wydawca.rcin +++ b/tests/etc/wydawca.rcin @@ -20,14 +20,14 @@ umask 022; locking no; -access-method project-owner { +dictionary project-owner { type builtin; query "${project}"; params ("/exact", "proj", "proj-owner@localhost", "Project Admin"); } -access-method project-uploader { +dictionary project-uploader { type builtin; query "${project}"; params ("/exact", -- cgit v1.2.1