diff --git a/AUTHORS b/AUTHORS index 84aff36d0cf9da309ab58f5c7cbb98fc5a5d1105..88a2e4b75af93feedcf9fc8f2974e90558771956 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,8 +1,8 @@ Stephan Bosch <stephan@rename-it.nl> -This package is built for and partly based on the Dovecot Secure IMAP server +This package is built for and partly based on the Dovecot Secure IMAP server written by: -Timo Sirainen <tss@iki.fi>. +Timo Sirainen <tss@iki.fi>. Grepping 'patch by' from ChangeLog shows up more people. diff --git a/COPYING b/COPYING index 1f784d1978f948417e8b3cbc881a229157cfb13a..98aa091e6f64e7d8db21d431007af082f384de41 100644 --- a/COPYING +++ b/COPYING @@ -1,4 +1,4 @@ See AUTHORS file for list of copyright holders. -Everything is licenced under LGPLv2.1 (see COPYING.LGPL) unless otherwise +Everything is licenced under LGPLv2.1 (see COPYING.LGPL) unless otherwise mentioned at the beginning of the file. diff --git a/INSTALL b/INSTALL index 052ada22722c64e85855dd09d1b628638217ddf8..edfed5e36ada1186c59dfffdeb23a143c61ef99e 100644 --- a/INSTALL +++ b/INSTALL @@ -1,7 +1,7 @@ Compiling ========= -If you downloaded the sources using Mercurial, you will need to execute +If you downloaded the sources using Mercurial, you will need to execute ./autogen.sh first to build the automake structure in your source tree. This process requires autotools and libtool to be installed. @@ -12,7 +12,7 @@ able to find the installed dovecot-config automatically: make sudo make install -If your system uses a $prefix different than the default /usr/local, the +If your system uses a $prefix different than the default /usr/local, the configure script can still find the installed dovecot-config automatically when supplied with the proper --prefix argument: @@ -44,7 +44,7 @@ the Pigeonhole build: --with-unfinished-features=no Controls whether unfinished features and extensions are built. Enabling this will enable the compilation of code that is considered unfinished and highly - experimental and may therefore introduce bugs and unexpected behavior. + experimental and may therefore introduce bugs and unexpected behavior. In fact, it may not compile at all. Enable this only when you are eager to test some of the new development functionality. @@ -57,12 +57,12 @@ The Pigeonhole package provides the following items: facilitates the actual Sieve filtering upon delivery. - The ManageSieve Service: This implements the ManageSieve protocol through - which users can remotely manage Sieve scripts on the server. + which users can remotely manage Sieve scripts on the server. -The functionality of these items is described in more detail in the README file. +The functionality of these items is described in more detail in the README file. In this file and in this section their configuration is described. Example configuration files are provided in the doc/example-config directory of this -package. +package. Sieve Interpreter - Basic Configuration --------------------------------------- @@ -85,9 +85,9 @@ The Sieve interpreter recognizes the following configuration options in the plugin section of the config file (default values are shown if applicable): sieve = ~/.dovecot.sieve - The location of the user's main active script. - - sieve_default = + The location of the user's main active script. + + sieve_default = The location of the default personal sieve script file, which gets executed ONLY if user's private Sieve script does no exist, e.g. /var/lib/dovecot/default.sieve. This is usually a global script, so be sure @@ -96,20 +96,20 @@ plugin section of the config file (default values are shown if applicable): `sieve_global_path', but that name is now deprecated. sieve_global_dir = - Location for :global include scripts for the Sieve include extension. + Location for :global include scripts for the Sieve include extension. sieve_dir = ~/sieve - Location for :personal include scripts for the Sieve include extension. + Location for :personal include scripts for the Sieve include extension. sieve_extensions = - Which Sieve language extensions are available to users. By default, all - supported extensions are available, except for deprecated extensions or those - that are still under development. Some system administrators may want to - disable certain Sieve extensions or enable those that are not available by + Which Sieve language extensions are available to users. By default, all + supported extensions are available, except for deprecated extensions or those + that are still under development. Some system administrators may want to + disable certain Sieve extensions or enable those that are not available by default. This setting can use '+' and '-' to specify differences relative to the default. For example `sieve_extensions = +imapflags' will enable the deprecated imapflags extension in addition to all extensions were already - enabled by default. + enabled by default. sieve_global_extensions = Which Sieve language extensions are ONLY avalable in global scripts. This can @@ -117,7 +117,7 @@ plugin section of the config file (default values are shown if applicable): control, for instance when these extensions can cause security concerns. This setting has higher precedence than the `sieve_extensions' setting (above), meaning that the extensions enabled with this setting are never available to - the user's personal script no matter what is specified for the + the user's personal script no matter what is specified for the `sieve_extensions' setting. The syntax of this setting is similar to the `sieve_extensions' setting, with the difference that extensions are enabled or disabled for exclusive use in global scripts. Currently, no @@ -127,16 +127,16 @@ plugin section of the config file (default values are shown if applicable): The Pigeonhole Sieve interpreter can have plugins of its own. Using this setting, the used plugins can be specified. Check the Dovecot wiki (wiki2.dovecot.org) or the pigeonhole website (http://pigeonhole.dovecot.org) - for available plugins. + for available plugins. sieve_user_log = The path to the file where the user log file is written. If not configured, a default location is used. If the main user's personal Sieve (as configured with sieve=) is a file, the logfile is set to <filename>.log by default. If - it is not a file, the default user log file is ~/.dovecot.sieve.log. + it is not a file, the default user log file is ~/.dovecot.sieve.log. recipient_delimiter = + - The separator that is expected between the :user and :detail address parts + The separator that is expected between the :user and :detail address parts introduced by the subaddress extension. This may also be a sequence of characters (e.g. '--'). The current implementation looks for the separator from the left of the localpart and uses the first one encountered. The :user @@ -150,16 +150,16 @@ plugin { # The location of the user's active script: sieve = ~/.dovecot.sieve - # If the user has no personal active script (i.e. if the file + # If the user has no personal active script (i.e. if the file # indicated in sieve= does not exist), use this one: sieve_default = /var/lib/dovecot/sieve/default.sieve - # The include extension fetches the :personal scripts from this - # directory. When ManageSieve is used, this is also where scripts + # The include extension fetches the :personal scripts from this + # directory. When ManageSieve is used, this is also where scripts # are uploaded. sieve_dir = ~/sieve - # The include extension fetches the :global scripts from this + # The include extension fetches the :global scripts from this # directory. sieve_global_dir = /var/lib/dovecot/sieve/global/ } @@ -197,7 +197,7 @@ The following script location types are implemented by default: or a directory containing script files with names structured as `<script-name>.sieve'. dict - Dovecot dict lookup. The location path is a dict uri. Read - doc/scipt-location-dict.txt for more information and examples. + doc/scipt-location-dict.txt for more information and examples. If the type prefix is omitted, the script location type is 'file'. @@ -219,8 +219,8 @@ The following options are defined for all location types: directory as where the script file was found if possible. For `dict' type locations, the binary is not stored at all in that case. Don't specify the same directory for different script locations, as this will result in - undefined behavior. - + undefined behavior. + Sieve Interpreter - Per-user Sieve Script Location -------------------------------------------------- @@ -228,14 +228,14 @@ By default, the Pigeonhole LDA Sieve plugin looks for the user's Sieve script file in the user's home directory (~/.dovecot.sieve). This requires that the home directory is set for the user. -If you want to store the script elsewhere, you can override the default using +If you want to store the script elsewhere, you can override the default using the sieve= setting, which specifies the location of the user's script file. This can be done in two ways: 1. Define the sieve setting in the plugin section of dovecot.conf. - 2. Return sieve extra field from userdb extra fields. + 2. Return sieve extra field from userdb extra fields. -For example, to use a Sieve script file named <username>.sieve in +For example, to use a Sieve script file named <username>.sieve in /var/sieve-scripts, use: plugin { @@ -244,16 +244,16 @@ plugin { sieve = /var/sieve-scripts/%u.sieve } -You may use templates like %u, as shown in the example. Refer to +You may use templates like %u, as shown in the example. Refer to http://wiki.dovecot.org/Variables for more information. -A relative path (or just a filename) will be interpreted to point under the +A relative path (or just a filename) will be interpreted to point under the user's home directory. Sieve Interpreter - Executing Multiple Scripts Sequentially ----------------------------------------------------------- -Pigeonhole's Sieve interpreter allows executing multiple Sieve scripts +Pigeonhole's Sieve interpreter allows executing multiple Sieve scripts sequentially. The extra scripts can be executed before and after the user's private script. For example, this allows executing global Sieve policies before the user's script. The following settings in the plugin section of the Dovecot @@ -267,7 +267,7 @@ config file control the execution sequence: directory, all the Sieve scripts contained therein (with the proper .sieve extension) are executed. The order of execution within that directory is determined by the file names, using a normal 8bit per-character comparison. - + Multiple script file or directory paths can be specified by appending an increasing number. The Sieve scripts found from these paths are added to the script execution sequence in the specified order. Reading the numbered @@ -278,14 +278,14 @@ config file control the execution sequence: sieve_after2 = sieve_after3 = (etc..) Identical to sieve_before, but the specified scripts are executed after the - user's script (only when keep is still in effect, as explained below). + user's script (only when keep is still in effect, as explained below). The script execution ends when the currently executing script in the sequence -does not yield a "keep" result: when the script terminates, the next script is +does not yield a "keep" result: when the script terminates, the next script is only executed if an implicit or explicit "keep" is in effect. Thus, to end all script execution, a script must not execute keep and it must cancel the implicit -keep, e.g. by executing "discard; stop;". This means that the command "keep;" -has different semantics when used in a sequence of scripts. For normal Sieve +keep, e.g. by executing "discard; stop;". This means that the command "keep;" +has different semantics when used in a sequence of scripts. For normal Sieve execution, "keep;" is equivalent to "fileinto "INBOX";", because both cause the message to be stored in INBOX. However, in sequential script execution, it only controls whether the next script is executed. Storing the message into INBOX @@ -304,7 +304,7 @@ makes sure that the message is at least stored in the default folder (INBOX). Just as for executing a single script the normal way, the Pigeonhole LDA Sieve plugin takes care never to duplicate deliveries, forwards or responses. When -vacation actions are executed multiple times in different scripts, the usual +vacation actions are executed multiple times in different scripts, the usual error is not triggered: the subsequent duplicate vacation actions are simply discarded. @@ -325,7 +325,7 @@ plugin { # E.g. user-specific default mail filing rules sieve_after = /var/vmail/%d/%n/sieve-after - # Global scripts executed after the user's personal script + # Global scripts executed after the user's personal script # (if keep is still in effect) # E.g. default mail filing rules. sieve_after2 = /var/lib/dovecot/sieve/after.d/ @@ -385,7 +385,7 @@ Sieve Interpreter - Extension Configuration Sieve Interpreter - Migration from CMUSieve (Dovecot v1.0/v1.1) --------------------------------------------------------------- -For the most part, migration from CMUSieve to the Pigeonhole LDA Sieve plugin is +For the most part, migration from CMUSieve to the Pigeonhole LDA Sieve plugin is just a matter of changing the used plugin name from 'cmusieve' to 'sieve' in the mail_plugins option in the protocol lda section of the config file (as explained above). However, there are a few important differences: @@ -406,46 +406,46 @@ above). However, there are a few important differences: * The include extension now requires your script file names to end with ".sieve". This means that ` include :personal "myscript"; ' won't work unless - you rename "myscript" to "myscript.sieve" + you rename "myscript" to "myscript.sieve" Sieve Interpreter - Migration from Dovecot Sieve v0.1.x (Dovecot v1.2) ---------------------------------------------------------------------- - * Dovecot v2.0 adds support for LMTP. Much like the Dovecot LDA, it can make - use of the Pigeonhole Sieve plugin. Since the LMTP service has its own - prototocol lmtp section in the config file, you need to add the Sieve plugin + * Dovecot v2.0 adds support for LMTP. Much like the Dovecot LDA, it can make + use of the Pigeonhole Sieve plugin. Since the LMTP service has its own + prototocol lmtp section in the config file, you need to add the Sieve plugin to the mail_plugins setting there too when you decide to use LMTP. - * The 'sieve_subaddress_sep' setting for the Sieve subaddress extension is now + * The 'sieve_subaddress_sep' setting for the Sieve subaddress extension is now known as 'recipient_delimiter'. Although sieve_subaddress_sep is still recognized for backwards compatibility, it is recommended to update the setting to the new name, since the LMTP service also uses the - recipient_delimiter setting. + recipient_delimiter setting. ManageSieve Service - Basic Configuration ----------------------------------------- IMPORTANT: - If you have used the LDA Sieve plugin without ManageSieve before and you have + If you have used the LDA Sieve plugin without ManageSieve before and you have .dovecot.sieve files in user directories, you are advised to make a backup before installing ManageSieve. Although the ManageSieve service takes care to - move these files to the Sieve directory before it is substituted with a + move these files to the Sieve directory before it is substituted with a symbolic link, this is not a very well tested operation, meaning that there is a slim possibility that existing Sieve scripts get lost. -Just like all other binaries that Dovecot uses, the managesieve and +Just like all other binaries that Dovecot uses, the managesieve and managesieve-login binaries are installed during make install. There are two things that have be done to activate the ManageSieve support in Dovecot: - * The first step is to add `sieve' to the protocols= configuration line in + * The first step is to add `sieve' to the protocols= configuration line in your dovecot.conf. * The next step is specifying an additional service type for the ManageSieve - service. This could be done in Dovecot's conf.d/master.conf or you can use + service. This could be done in Dovecot's conf.d/master.conf or you can use the 20-managesieve.conf file from the doc/example-config/conf.d directory of - this package. + this package. For example: @@ -456,7 +456,7 @@ Dovecot: } Because the implementation of the ManageSieve daemon is largely based on the -original IMAP implementation, it is very similar in terms of configuration. The +original IMAP implementation, it is very similar in terms of configuration. The following settings can be configured in the 'protocol sieve' section: managesieve_max_line_length = 65536 @@ -466,18 +466,18 @@ following settings can be configured in the 'protocol sieve' section: managesieve_logout_format = bytes=%i/%o Specifies the string pattern used to compose the logout message of an - authenticated session. The following substitutions are available: + authenticated session. The following substitutions are available: %i - total number of bytes read from client %o - total number of bytes sent to client managesieve_implementation_string = Dovecot Pigeonhole - To fool ManageSieve clients that are focused on CMU's timesieved you can - specify the IMPLEMENTATION capability that the Dovecot reports to clients + To fool ManageSieve clients that are focused on CMU's timesieved you can + specify the IMPLEMENTATION capability that the Dovecot reports to clients (e.g. 'Cyrus timsieved v2.2.13'). managesieve_max_compile_errors = 5 - The maximum number of compile errors that are returned to the client upon + The maximum number of compile errors that are returned to the client upon script upload or script verification. managesieve_sieve_capability = @@ -512,12 +512,12 @@ the LDA Sieve plugin. already exists at the location specified by the sieve setting, it is moved to the sieve_dir location before the symbolic link is installed. It is renamed to dovecot.orig.sieve and therefore listed as `dovecot.orig' by a ManageSieve - client. + client. The following provides an example configuration for Sieve and ManageSieve. Only -sections and settings relevant to ManageSieve are shown. Refer to -20-managesieve.conf in the doc/example-config/conf.d directory for a full -example with comments, but don't forget to configure Sieve and add sieve to the +sections and settings relevant to ManageSieve are shown. Refer to +20-managesieve.conf in the doc/example-config/conf.d directory for a full +example with comments, but don't forget to configure Sieve and add sieve to the 'protocols = ...' setting if you use it. # *** conf.d/20-managesieve.conf *** @@ -594,7 +594,7 @@ ManageSieve Service - Migration The following has changed since the ManageSieve releases for Dovecot v1.x: * For Dovecot v1.0 and v1.1, the sieve_dir setting used by ManageSieve was - called sieve_storage. Also, the sieve and sieve_storage settings were located + called sieve_storage. Also, the sieve and sieve_storage settings were located inside the 'protocol managesieve' section of the configuration. As per Dovecot v1.2, these settings are shared with the Sieve plugin and located in the 'plugin' section of the configuration. Make sure you have updated the @@ -611,17 +611,17 @@ The following has changed since the ManageSieve releases for Dovecot v1.x: * The Dovecot configuration now calls the ManageSieve protocol 'sieve' instead of 'managesieve' because it is registered as such with IANA. The binaries and the services are still called 'managesieve' and 'managesieve-login'. The - example above demonstrates how this affects the configuration. + example above demonstrates how this affects the configuration. Test Suite ========== This package includes a test suite to verify the basic processing of the Sieve -interpreter on your particular platform. Note that the test suite is not -available when this package is compiled against the Dovecot headers only. The -test suite executes a list of test cases and halts when one of them fails. If it -executes all test cases successfully, the test suite finishes. You can execute -the test suite using `make test`. +interpreter on your particular platform. Note that the test suite is not +available when this package is compiled against the Dovecot headers only. The +test suite executes a list of test cases and halts when one of them fails. If it +executes all test cases successfully, the test suite finishes. You can execute +the test suite using `make test`. A failing test case is always a bug and a report is greatly appreciated. diff --git a/Makefile.am b/Makefile.am index e8cdca0acecbd7bb40067dcb346ac7fe9277b524..6e91416918e6a8ffd0a8b3f45522fc8a01748b8c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -25,7 +25,7 @@ endif TESTSUITE_BIN = $(top_builddir)/src/testsuite/testsuite $(TESTSUITE_OPTIONS) if TESTSUITE_VALGRIND -TEST_BIN = valgrind -q --error-exitcode=1 --show-reachable=yes --leak-check=full $(TESTSUITE_BIN) +TEST_BIN = valgrind -q --error-exitcode=1 --show-reachable=yes --leak-check=full $(TESTSUITE_BIN) else TEST_BIN = $(TESTSUITE_BIN) endif @@ -33,7 +33,7 @@ endif if BUILD_UNFINISHED test_unfinished = else -test_unfinished = +test_unfinished = endif test_cases = \ diff --git a/NEWS b/NEWS index 7414ce322bd059817237d19149efe5ffa1ece0a3..257014818abe0aa0e9f40e68ffda7ca2f1b8faef 100644 --- a/NEWS +++ b/NEWS @@ -6,7 +6,7 @@ v0.3.1 25-05-2012 Stephan Bosch <stephan@rename-it.nl> is updated with information on this new feature and the (backwards-compatible) changes to the configuration. Note that his feature is currently not supported for sieve_before/sieve_after or script management - through ManageSieve. + through ManageSieve. + Incorporated the sieve_duplicate plugin into main Pigeonhole tree as a normal extension (vnd.dovecot.duplicate). This Dovecot-specific extension adds the ability to check for duplicate deliveries based on message ID. @@ -30,7 +30,7 @@ v0.3.0 16-02-2012 Stephan Bosch <stephan@rename-it.nl> * Renamed sieve_global_path setting to sieve_default for clarity. Old name is still recognized for backwards compatibility. Support for the ancient (pre - v1.1) name for this setting "global_script_path" is now dropped. + v1.1) name for this setting "global_script_path" is now dropped. * Added means to prohibit use of redirect action. Setting sieve_max_redirects to 0 now means that redirect is disallowed in stead of unlimited. Default value remains four. @@ -54,7 +54,7 @@ v0.3.0 16-02-2012 Stephan Bosch <stephan@rename-it.nl> + Added support for substituting the entire message during Sieve processing. This is used for the filter action provided by the new sieve_extprograms plugin (provided separately for now). The filter action allows passing the - message through an external program. + message through an external program. + Added support for restricting certain Sieve language extensions to (admin-controled) global scripts. Restricted extensions can be configured using the new sieve_global_extensions setting. This is particularly useful @@ -71,13 +71,13 @@ v0.2.6 13-02-2012 Stephan Bosch <stephan@rename-it.nl> script is always stored with an appended .sieve file extension, also when the name already ends with a .sieve suffix. IMPORTANT: Some installations have relied on this unintentional feature, so - check your script includes for issues before upgrading. + check your script includes for issues before upgrading. * Matched changes regarding auth_verbose setting in Dovecot. This means that - this release will only compile against Dovecot v2.0.18. + this release will only compile against Dovecot v2.0.18. - Fixed problem in ManageSieve that caused it to omit a WARNINGS response code when the uploaded script compiled with warnings. - Made sure that locations of Sieve error never report `line 0'. - - Fixed potential segfault occurring when interpreter initialization fails. + - Fixed potential segfault occurring when interpreter initialization fails. v0.2.5 19-11-2011 Stephan Bosch <stephan@rename-it.nl> @@ -107,7 +107,7 @@ v0.2.4 13-09-2011 Stephan Bosch <stephan@rename-it.nl> of Sieve language extensions at 'runtime'. Actually, this is checked at compile time. At runtime the interpreter checks whether extensions that were not previously available are still unavailable. If the situation - changed, the script is re-compiled and the ihave tests are evaluated again. + changed, the script is re-compiled and the ihave tests are evaluated again. + Sieve: optimized compilation of tests that yield constant results (i.e. known at compile tme), such as 'true' and 'false'. No code is produced anymore for script sections that are never executed. Also, semantics @@ -133,23 +133,23 @@ v0.2.3 14-04-2011 Stephan Bosch <stephan@rename-it.nl> * Sieve filter tool: finished implementing basic functionality. It is not quite ready yet, but it is available for those willing to experiment with it (needs --with-unfinished-features config to compile). Also - includes man page. + includes man page. + Vacation extension now inhibits replies to messages from sender listed in :addresses, thus preventing replies to one of the user's other known addresses. + Vacation extension: implemented the (draft) vacation-seconds extension. - This also adds min/max period configuration settings. Refer to - doc/vacation.txt for configuration information. + This also adds min/max period configuration settings. Refer to + doc/vacation.txt for configuration information. - ManageSieve: fixed bug in UTF-8 checking of string values. This is done by discarding the original implementation and migrating to the Dovecot - API's UTF-8 functionality. + API's UTF-8 functionality. - Sieve command line tools now avoid initializing the mail store unless necessary. This prevents sievec and sieve-dump from failing when - executed by root for example. + executed by root for example. - Enotify extension: fixed inappropriate return type in mailto URI parse function, also fixing ARM compiler warning. - - Vacation extension: fixed handling of sendmail errors. It produced an - additional confusing success message in case of error. + - Vacation extension: fixed handling of sendmail errors. It produced an + additional confusing success message in case of error. - Removed header MIME-decoding to fix erroneous address parsing. Applies to address test and vacation command. - Fixed segfault bug in extension configuration, triggered when unknown @@ -170,7 +170,7 @@ v0.2.2 06-12-2010 Stephan Bosch <stephan@rename-it.nl> - Imap4flags: fixed segfault bug occuring in multiscript context. - Added version checking to the ManageSieve settings plugin. This plugin was forgotten when the LDA plugin was updated with this change in the previous - release. + release. - LDA Sieve plugin: fixed memory leak at deinitialization. v0.2.1 27-09-2010 Stephan Bosch <stephan@rename-it.nl> @@ -180,7 +180,7 @@ v0.2.1 27-09-2010 Stephan Bosch <stephan@rename-it.nl> + Regex extension: added support for regex keys composed from variables. - LDA Sieve plugin: added _version symbol to enable Dovecot's plugin version check. Without this check, people can forget to recompile the plugin, which - can lead to unexpected effects. + can lead to unexpected effects. - LDA Sieve plugin: turned debug message about an unconfigured home directory into a proper error and added script path information. - Fixed unnecessary reporting of dummy extensions in ManageSieve SIEVE @@ -189,32 +189,32 @@ v0.2.1 27-09-2010 Stephan Bosch <stephan@rename-it.nl> v0.2.0 10-09-2010 Stephan Bosch <stephan@rename-it.nl> - * Merged Sieve and ManageSieve packages into a single Pigeonhole package. + * Merged Sieve and ManageSieve packages into a single Pigeonhole package. There is also no need to patch Dovecot anymore to gain ManageSieve support. Version numbering of previous Sieve releases is continued as v0.2.0. The sources originally branched off from Sieve v0.1.5 and ManageSieve v0.11.4, but the NEWS history of much more recent releases for Dovecot v1.2 is included since these changes are all included in this release as well. - * The ManageSieve service now binds to TCP port 4190 by default due to the + * The ManageSieve service now binds to TCP port 4190 by default due to the IANA port assignment for the ManageSieve service. When upgrading from v1.2, this should be taken into account. The service can be configured manually to listen on both 2000 and 4190. * The Dovecot configuration now calls the ManageSieve protocol 'sieve' in - stead of 'managesieve' because it is registered as such with IANA. The + stead of 'managesieve' because it is registered as such with IANA. The binaries and the services are still called managesieve and managesieve-login. * The binary representation of a compiled Sieve script is updated to include source code locations of all commands and arguments. This is implemented in a similar manner as such debug information is included in some system - executables and libraries (DWARF-like). Run-time errors can now always refer + executables and libraries (DWARF-like). Run-time errors can now always refer to the proper line number in the Sieve source script. - * The Sieve plugin is adapted to work properly with the new LMTP service + * The Sieve plugin is adapted to work properly with the new LMTP service introduced with Dovecot v2.0. The same plugin is used for both LDA and LMTP. * The 'sieve_subaddress_sep' setting for the Sieve subaddress extension is now - known as 'recipient_delimiter'. Although the deprecated sieve_subaddress_sep + known as 'recipient_delimiter'. Although the deprecated sieve_subaddress_sep setting is still recognized for backwards compatibility, it is recommended to update the setting to the new name, since the new LMTP service also uses - the recipient_delimiter setting. + the recipient_delimiter setting. * ManageSieve: changed default IMPLEMENTATION capability to from 'Dovecot' to 'Dovecot Pigeonhole'. * Renamed the sieved tool to sieve-dump. The original name was somewhat @@ -223,14 +223,14 @@ v0.2.0 10-09-2010 Stephan Bosch <stephan@rename-it.nl> * Made testsuite commands more uniform and cleaned up many of the testsuite scripts. Some minor new tests were added in the process. + Simplified string matching API to use abstract string lists as data sources. - This will also make implementing the index extension easier in the future. + This will also make implementing the index extension easier in the future. + Significantly improved trace debugging with the sieve-test tool. The full - execution of the script can be examined, including the matched values and + execution of the script can be examined, including the matched values and keys of the respective Sieve test commands. The executed statements are listed with their line number (and code address when requested). The level - of detail is configurable from the command line. + of detail is configurable from the command line. + The SIEVE and NOTIFY capabilities reported by the ManageSieve protocol can - now be configured manually. If left unconfigured, the capabilities are + now be configured manually. If left unconfigured, the capabilities are determined from the default Sieve and ManageSieve configuration. User-specific capabilities aren't reported until after authentication. + Significantly improved file error handling. This means that administrators @@ -238,7 +238,7 @@ v0.2.0 10-09-2010 Stephan Bosch <stephan@rename-it.nl> most notable example is that when the LDA Sieve plugin is trying to store a binary for a global script, the resulting failure message also points the administrator towards pre-compiling the script with sievec. - + Added runtime argument value checking for several commands (redirect, date + + Added runtime argument value checking for several commands (redirect, date vacation). When variables are used, these checks cannot be performed at compiletime. A proper runtime error now is produced when invalid data is encountered. @@ -249,10 +249,10 @@ v0.2.0 10-09-2010 Stephan Bosch <stephan@rename-it.nl> at runtime. Previously, it was not checked until the store action was executed. + Simplified and restructured error handling. Also made sure that user-caused - errors are no longer written to the Dovecot master/LDA log. + errors are no longer written to the Dovecot master/LDA log. - Multiscript: fixed duplicate implicit keep caused by erroneous execution state update. - - Prevented assertion failure due to currupt binary string representation. + - Prevented assertion failure due to currupt binary string representation. If the string was missing a final \0 character an assertion was produced in stead of a binary corruption error. - Imap4flags: fixed bug in setflag command; when parameter was a stringlist, @@ -293,26 +293,26 @@ v0.1.16 30-04-2010 Stephan Bosch <stephan@rename-it.nl> * Finished implementation of spamtest, spamtestplus and virustest extensions. These are not enabled by default and need to be activated with the - sieve_extensions setting. Documentation available in + sieve_extensions setting. Documentation available in doc/spamtest-virustest.txt - + Vacation extension: the from address of the generated reply is now by + + Vacation extension: the from address of the generated reply is now by default equal to whatever known recipient alias matched the headers of the message. If it is one of the aliases specified with :addresses, it is used - in stead of the envelope recipient address that was used before. - + Restructured and optimized the lexical scanner. - + Added --with-docs configure option to allow disabling installation of - documentation. + in stead of the envelope recipient address that was used before. + + Restructured and optimized the lexical scanner. + + Added --with-docs configure option to allow disabling installation of + documentation. - Accidentally omitted 'extern' in two declarations of global variables in header files, causing compile failures on certain systems. - Deprecated imapflags extension: fixed implicit assignment of flags. Turns out this never really worked, but the effect of this bug was obscured by the removeflag bug fixed in the previous release. - - Fixed various memset argument mixups in enotify extension. This caused + - Fixed various memset argument mixups in enotify extension. This caused warnings on certain systems, but luckily no adverse effects at runtime. v0.1.15 25-01-2010 Stephan Bosch <stephan@rename-it.nl> - * Enotify extension: + * Enotify extension: - Adjusted notify method API for addition of new notification methods. - Set default importance level to 'normal' (was 'high'). * Include extension: updated implementation towards most recent specification @@ -324,7 +324,7 @@ v0.1.15 25-01-2010 Stephan Bosch <stephan@rename-it.nl> - One issue remains: ManageSieve currently requires included scripts to be uploaded first, which is not according to specification. * Changed envelope path parser to allow to and from envelope addresses that - have no domain part. + have no domain part. + Added preliminary support for Sieve plugins and added support for installing Sieve development headers. + Started work on the implementation of the spamtest, spamtestplus and @@ -333,16 +333,16 @@ v0.1.15 25-01-2010 Stephan Bosch <stephan@rename-it.nl> + Variables extension: added support for variable namespaces. + Added configurable script size limit. Compiler will refuse to compile files larger than sieve_max_script_size. - + Testsuite changes: + + Testsuite changes: - Added support for changing and testing an extension's configuration. - Added a command line parameter for copying errors to stderr. - Fixed a bug in the i;ascii-numeric comparator. If one of the strings started with a non-digit character, the comparator would always yield less-than. - - Imap4flags extension: fixed bug in removeflag: removing a single flag failed + - Imap4flags extension: fixed bug in removeflag: removing a single flag failed due to off-by-one error (bug report by Julian Cowley). - Improved EACCES error messages for stat() and lstat() syscalls and slightly improved error messages that may uccur when saving a binary. - - Vacation extension: fixed typo in runtime log message (patch by Julian + - Vacation extension: fixed typo in runtime log message (patch by Julian Cowley). - Fixed use of minus '-' in man pages; it is now properly escaped. - Fixed parser recovery. In particular cases it would trigger spurious errors @@ -351,104 +351,104 @@ v0.1.15 25-01-2010 Stephan Bosch <stephan@rename-it.nl> v0.1.14 19-12-2009 Stephan Bosch <stephan@rename-it.nl> - * Made the imposed limits on the number of redirects and the number of - actions configurable. The settings are called sieve_max_actions and + * Made the imposed limits on the number of redirects and the number of + actions configurable. The settings are called sieve_max_actions and sieve_max_redirects. * Did a major rework of extension handling, making sure that no global state is maintained. This change was triggered by problems that global state info would cause for Dovecot v2.0, but it is also important for v1.2 as it - significantly cleans up the library implementation. + significantly cleans up the library implementation. + Made LDA Sieve plugin recognize the deliver_log_format setting. + Message headers produced from user-supplied data are now RFC2047-encoded if necessary for outgoing messages. This is for example important for the - :subject argument of the vacation action. - + Added support for the $text$ substitution in the deprecated notify + :subject argument of the vacation action. + + Added support for the $text$ substitution in the deprecated notify extension. - + The subaddress extension now also accepts recipient_delimiter setting as an - alias for sieve_subaddress_sep setting. This anticipates the - recipient_delimiter setting in v2.0. - - Fixed logging of mailbox names. It logged the converted mUTF7 version in + + The subaddress extension now also accepts recipient_delimiter setting as an + alias for sieve_subaddress_sep setting. This anticipates the + recipient_delimiter setting in v2.0. + - Fixed logging of mailbox names. It logged the converted mUTF7 version in stead of the original UTF8 version supplied by the user. - Fixed a minor memory leak in the multiscript support. - - Fixed a bug in the recompilation of Sieve scripts. Made sure that scripts - are only recompiled when the script file - or the symlink pointing to it - + - Fixed a bug in the recompilation of Sieve scripts. Made sure that scripts + are only recompiled when the script file - or the symlink pointing to it - is strictly newer. v0.1.13 18-10-2009 Stephan Bosch <stephan@rename-it.nl> - + Body extension: implemented proper handling of the :raw transform and added + + Body extension: implemented proper handling of the :raw transform and added various new tests to the test suite. However, :content "multipart" and - :content "message/rfc822" are still not working. - + Fixed race condition occuring when multiple instances are saving the same + :content "message/rfc822" are still not working. + + Fixed race condition occuring when multiple instances are saving the same binary (patch by Timo Sirainen). + Test suite: added support for testing multiscript execution. - - Made compiler more lenient towars missing CRLF at the end of the script in a + - Made compiler more lenient towars missing CRLF at the end of the script in a hash comment. - - Body extension: don't give SKIP_BODY_BLOCK flag to message parser, we want + - Body extension: don't give SKIP_BODY_BLOCK flag to message parser, we want the body! (patch by Timo Sirainen). - Fixed handling of implicit side effects for multiscript execution. - - Fixed bugs in multiscript support; subsequent keep actions were not always + - Fixed bugs in multiscript support; subsequent keep actions were not always merged correctly and implicit side effects were not always handled correctly. - Fixed a segfault bug in the sieve-test tool occuring when compile fails. - - Fixed segfault bug in action procesing. It was triggered while merging side + - Fixed segfault bug in action procesing. It was triggered while merging side effects in duplicate actions. - - Fixed bug in the Sieve plugin that caused it to try to stat() a NULL path, - yielding a 'Bad address' error. + - Fixed bug in the Sieve plugin that caused it to try to stat() a NULL path, + yielding a 'Bad address' error. v0.1.12 21-08-2009 Stephan Bosch <stephan@rename-it.nl> + Testsuite: added support for testing binaries stored on disk. - + Implemented the new date extension. This allows matching against date values + + Implemented the new date extension. This allows matching against date values in header fields and the current date at the time of script evaluation. v0.1.11 08-08-2009 Stephan Bosch <stephan@rename-it.nl> + Built skeleton implementation for the date extension (RFC 5260). It - compiles, but it does not do anything useful yet. Therefore, it is not part - of the default compilation. + compiles, but it does not do anything useful yet. Therefore, it is not part + of the default compilation. - Fixed ARM portability issues caused by char type not being signed on that - platform. Reading optional operands from a binary would fail for action side - effects. Also, an accidental mixup of an int return type with bool caused - the interpreter to continue on ARM even though an error occured. + platform. Reading optional operands from a binary would fail for action side + effects. Also, an accidental mixup of an int return type with bool caused + the interpreter to continue on ARM even though an error occured. - Removed direct stdint.h includes to prevent portability issues. - Fixed segfault bug in the handling of script open failures. - Include: improved user error messages and system log messages. - Fixed copy-paste mixup between sieve_after and sieve_before settings in the - LDA Sieve plugin. If only a sieve_after script was active, nothing would + LDA Sieve plugin. If only a sieve_after script was active, nothing would have been executed. Patch by Mike Abbott. - - Include: fixed a bug in HOME substitution in the sieve_dir path. Surfaced in + - Include: fixed a bug in HOME substitution in the sieve_dir path. Surfaced in ManageSieve. v0.1.10 03-08-2009 Stephan Bosch <stephan@rename-it.nl> - * Changed action execution of fileinto and keep. These changes depend on API + * Changed action execution of fileinto and keep. These changes depend on API additions in Dovecot, making this release depend on Dovecot v1.2.2 or newer. * Further developed the sieve-filter command line tool. This required a few - changes to the action execution of the Sieve engine. The tool was - successfully tested on folders with a few 100k spam messages. However, the - commandline options are still incomplete, a man page is missing and it needs - much more testing before I can recommend anyone to use this tool. - + Added support for the mailbox extension. This allows checking whether a - mailbox exists using the mailboxexists command and it adds the :create - argument to the fileinto command to create the mailbox when it is missing. - The :create feature is useless unless the Deliver LDA is run with the -n + changes to the action execution of the Sieve engine. The tool was + successfully tested on folders with a few 100k spam messages. However, the + commandline options are still incomplete, a man page is missing and it needs + much more testing before I can recommend anyone to use this tool. + + Added support for the mailbox extension. This allows checking whether a + mailbox exists using the mailboxexists command and it adds the :create + argument to the fileinto command to create the mailbox when it is missing. + The :create feature is useless unless the Deliver LDA is run with the -n option. + Improved the testsuite with tests for message delivery. Messages stored - using keep and fileinto can be fed back into the Sieve engine for + using keep and fileinto can be fed back into the Sieve engine for verification. This includes testing of applied IMAP flags. - + Updated the man pages with the new method of specifying the supported + + Updated the man pages with the new method of specifying the supported extensions using + and - (for the -x parameter of the sieve tools) + Further developed the deprecated notify extension. A dummy for the denotify - command exists, meaning that its use does not cause an error anymore. - - Fixed a bug in the derivation of the binary path from the script path. A + command exists, meaning that its use does not cause an error anymore. + - Fixed a bug in the derivation of the binary path from the script path. A bare filename would yield a path relative to root. - Fixed a bug in the value matching code. The context data now uses a proper pool in stead of the data stack. Bug reported by Jan Sechser. - - Fixed assertion fail in the include extension caused by missing + - Fixed assertion fail in the include extension caused by missing initialization upon binary load. This bug surfaces only for stored binaries. Bug reported by Tom Hendrikx. - - Fixed include error message for failed :global include. It mentioned the + - Fixed include error message for failed :global include. It mentioned the wrong config parameter. - Fixed broken wiki reference in an error message of the plugin about the 'sieve' setting. @@ -457,48 +457,48 @@ v0.1.10 03-08-2009 Stephan Bosch <stephan@rename-it.nl> v0.1.9 22-07-2009 Stephan Bosch <stephan@rename-it.nl> - * Removed the unfinished sieve-filter tool from the default build. It is now - only built when the --with-unfinished-features switch is supplied during + * Removed the unfinished sieve-filter tool from the default build. It is now + only built when the --with-unfinished-features switch is supplied during configure. - + Started building support for the ereject version of the reject action, - which has a preference to use an SMTP/LMTP protocol error in stead of a + + Started building support for the ereject version of the reject action, + which has a preference to use an SMTP/LMTP protocol error in stead of a bounce message. This is to be used to make the Sieve plugin honour Deliver's - -e parameter. This is not yet finished and not built by default. + -e parameter. This is not yet finished and not built by default. + Improved 'Permission denied' error messages just like Dovecot does, precisely specifying what permission is missing to access or create a file. - + Added additional headers to the list of allowed headers for the address - test. The restrictive nature of the address test is not always appropriate. + + Added additional headers to the list of allowed headers for the address + test. The restrictive nature of the address test is not always appropriate. Still thinking of a better, less restrictive implementation. + Made the deprecated notify extension compatible with the old CMUSieve plugin. However, the denotify command and the $text$ substitution are not - yet supported. - + Made the discard action log a message to avoid confusion about disappearing + yet supported. + + Made the discard action log a message to avoid confusion about disappearing messages. - Fixed behavior of fileinto when delivering into a namespace prefix. It now uses silent delivery into INBOX as fallback. - - Fixed logging of folder namespace prefix upon delivery into a prefixed + - Fixed logging of folder namespace prefix upon delivery into a prefixed namespace. Formerly it only logged the bare folder name. - Fixed a potential segfault in the argument validation. It didn't surface because no command could have a :tag followed by an associated parameter as last argument. - - Fixed segfault bug occuring in envelope test when performed on null (<>) - envelope path. The fix involves a rather large restructuring of the code to + - Fixed segfault bug occuring in envelope test when performed on null (<>) + envelope path. The fix involves a rather large restructuring of the code to make sure envelope addresses are properly handled everywhere (bug reported by Nikita Koshikov) - - Envelope: fixed bug in application of address parts; failure to obtain + - Envelope: fixed bug in application of address parts; failure to obtain the part would cause inappropriate match success (bug reported by Ron Lee) - Fixed extension conflict checks during validation. It could sometimes - produce useless errormessages. This is currently only used by the + produce useless errormessages. This is currently only used by the deprecated extensions. - - Forgot to remove old explicit storage library dependency (patch by + - Forgot to remove old explicit storage library dependency (patch by Arkadiusz Miskiewicz). - - Fixed compiler warnings on certain platforms regarding the use fwrite for + - Fixed compiler warnings on certain platforms regarding the use fwrite for outgoing message construction v0.1.8 12-07-2009 Stephan Bosch <stephan@rename-it.nl> - Fixed AIX compile problem. For portability, the typeof operator is - not used anymore. + not used anymore. + Added partial support for the deprecated notify extension. However, it turns out that the implementation provided by cmusieve is even older (2001), meaning that this is currently not backwards compatible with cmusieve. @@ -511,49 +511,49 @@ v0.1.7 05-07-2009 Stephan Bosch <stephan@rename-it.nl> parameters in internal tool help output. + Enhanced extensions configuration, allowing to specify the enabled extensions relatively to the default (patch by Steffen Kaiser). - - Forgot to initialize script execution status in Sieve plugin, causing + - Forgot to initialize script execution status in Sieve plugin, causing segfaults on compile errors in specific conditions. - - Fixed logging in Sieve plugin for execution of default main script (went + - Fixed logging in Sieve plugin for execution of default main script (went to STDERR). - + v0.1.6 18-06-2009 Stephan Bosch <stephan@rename-it.nl> * Adjusted to changes in Dovecot to make it compile against v1.2.rc5 * Made default of sieve_dir setting match the ManageSieve implementation. - Fixed a few problems in de body extension that caused assert failures in - specific situations. + specific situations. v0.1.5 18-04-2009 Stephan Bosch <stephan@rename-it.nl> - * Ported the implementation of the Sieve include extension to the latest - draft. This means that the import and export commands are replaced by a new + * Ported the implementation of the Sieve include extension to the latest + draft. This means that the import and export commands are replaced by a new command called global. The import and export commands are now DEPRICATED and are mere aliases for the global command. The new specification also adds the - :once modifier to the include command. The also newly specified global.* + :once modifier to the include command. The also newly specified global.* variable namespace is not implemented yet as support for variable namespaces is currently missing. * Did a major rework of the multiscript support for better error handling and made sure that persistent global scripts (sieve_before/sieve_after) are - always executed, even when the user does not have a script of his own and - a global default is missing. + always executed, even when the user does not have a script of his own and + a global default is missing. + Provided basic support for the environment extension. Currenly, the name, version and host items are useful. Others are pending. + Improved error message that is presented when an unknown Sieve extension is provided as argument to the require command. It now notifies the user that Sieve core commands do not need to be specified in require. - Fixed bug in includes at levels deeper than one. - - Fixed bug in address matching that was caused by the failure to handle group - specifications. In dovecot, these are marked by address items with NULL + - Fixed bug in address matching that was caused by the failure to handle group + specifications. In dovecot, these are marked by address items with NULL elements, which causes a segfault if not considered. The group 'undisclosed- recipients:;' in particular triggered this bug. Bug reported by Bernhard - Schmidt. + Schmidt. v0.1.4 21-03-2009 Stephan Bosch <stephan@rename-it.nl> - * Started work on the sieve-filter tool. With this command line tool it will + * Started work on the sieve-filter tool. With this command line tool it will be possible to (re-)apply Sieve filters on a mail folder. It is currently undocumented and far from functional. - + Added a custom debug extension that provides the possibility to print debug + + Added a custom debug extension that provides the possibility to print debug messages from scripts executed by the Sieve tools. - Fixed issue with opening relative paths as a mail file. Bug reported by Ian P. Christian. @@ -567,7 +567,7 @@ v0.1.3 12-02-2009 Stephan Bosch <stephan@rename-it.nl> * Adapted to changes in Dovecot, making this release dependent on Dovecot >= 1.2.beta1 * Made mail address comparison fully case-insensitive. This is particularly - noticeable for the :addresses argument of the vacation command. + noticeable for the :addresses argument of the vacation command. + Finished enotify extension. Currently, only the mailto notification method is implemented. All still needs to be tested thoroughly. + Implemented multiscript support. It is now possible to execute multiple @@ -580,68 +580,68 @@ v0.1.3 12-02-2009 Stephan Bosch <stephan@rename-it.nl> separator other than '+'. + Compiler now warns about invalid header field names used for the header and address tests. - + Vacation extension now properly generates a References header for the + + Vacation extension now properly generates a References header for the response message. - + Added testing of basic result execution to the test suite. Also added - supportfor testing the outgoing messages produced by the Sieve interpreter. + + Added testing of basic result execution to the test suite. Also added + supportfor testing the outgoing messages produced by the Sieve interpreter. + Included execution of the actual result in the sieve-test command line tool. - The undocumented sieve-exec tool that existed for this is now removed as + The undocumented sieve-exec tool that existed for this is now removed as planned. + Added support for the now obsolete 'imapflags' extension for backwards compatibility with CMUSieve. This also implements the mark/unmark commands. - - Fixed bugs in the regex extension: 1) if an optional match value did not in + - Fixed bugs in the regex extension: 1) if an optional match value did not in fact match, subsequent match values would get unexpected indexes. 2) fixed segfault bug occuring when regex is freed. - Fixed bug in the use of the :from agrument for the vacation command. If this address included a phrase part, the response would not be a valid RFC822 message. - - Plugged a theoretical security hole occuring when a directory is opened as a + - Plugged a theoretical security hole occuring when a directory is opened as a Sieve binary. - Cleaned up and fixed various log messages. - - Fixed bug in the outgoing address verification. Addresses ending in ',' were + - Fixed bug in the outgoing address verification. Addresses ending in ',' were erroneously accepted. v0.1.2 26-11-2008 Stephan Bosch <stephan@rename-it.nl> - Fixed important bug in the redirect action (and probably other actions like reject and vacation that only send messages). This was a bug in the handling - of context information during the execution of actions. It caused the sieve - interpreter to crash with a segfault when redirect was executed. + of context information during the execution of actions. It caused the sieve + interpreter to crash with a segfault when redirect was executed. v0.1.1 24-11-2008 Stephan Bosch <stephan@rename-it.nl> - * Re-enabled support for compiling against dovecot headers. Much like - cmusieve, command line tools like sievec and sieved are not compiled in this + * Re-enabled support for compiling against dovecot headers. Much like + cmusieve, command line tools like sievec and sieved are not compiled in this case. * Started implementation of enotify extension. Not anywhere near finished - though. + though. * Adapted to changes in Dovecot on various occasions, making this release dependent on Dovecot >= v1.2.alpa4. + Improved logging of errors at specific occasions and added debug messages to - find script execution problems quicker. - + Removed code duplication between command line tools and the test suite. + find script execution problems quicker. + + Removed code duplication between command line tools and the test suite. Also restructured the sources of the tools. + Added UTF-8 to UTF-7 folder name conversion for compatibility with IMAP. - + Created man pages for the command line tools. These are automatically + + Created man pages for the command line tools. These are automatically installed upon 'make install' + Incorporated Valgrind support into the testsuite and fixed a few memory leaks in the process. - - Fixed compile error surfacing for gcc3.4. Forgot mask argument for the - open() system call when the O_CREAT flag is specified. Bug found by + - Fixed compile error surfacing for gcc3.4. Forgot mask argument for the + open() system call when the O_CREAT flag is specified. Bug found by Sergey Ivanov. - Fixed bug in the sievec tool. -d output was always written to stdout. - - Fixed important bug in the imap4flags extension. When no :flags argument is + - Fixed important bug in the imap4flags extension. When no :flags argument is specified, the previous version would always use the final value of the - internal variable to set the flags. This means that modifications to the - internal variable also affected the bare fileinto/keep actions executed - earlier. This does not comply to the RFC. + internal variable to set the flags. This means that modifications to the + internal variable also affected the bare fileinto/keep actions executed + earlier. This does not comply to the RFC. - Fixed bug in the include extension's import/export commands. Duplicate import/exports caused problems. - - Fixed bug in the handling of non-existent scripts. Errors were sometimes - ignored. + - Fixed bug in the handling of non-existent scripts. Errors were sometimes + ignored. - Dovecot omitted unfolding multi-line headers. This was added to the cmusieve plugin after the code was incorporated into the new implementation. This is - now mplicitly fixed by concurrent change in Dovecot. + now mplicitly fixed by concurrent change in Dovecot. v0.1.0 23-10-2008 Stephan Bosch <stephan@rename-it.nl> @@ -651,12 +651,12 @@ Dovecot ManageSieve NEWS history: --------------------------------- Dovecot 1.2: - + v0.11.11: * This release contains adjustments to match changes in the Sieve API. This means that this release will only compile against Pigeonhole Sieve v0.1.15. - + Implemented ManageSieve QUOTA enforcement. + + Implemented ManageSieve QUOTA enforcement. + Added MAXREDIRECTS capability after login. + Implemented new script name rules specified in most recent ManageSieve draft. @@ -667,21 +667,21 @@ v0.11.11: v0.11.10: * This release contains adjustments to match changes in the Sieve API. This - means that this release will only compile against Pigeonhole Sieve + means that this release will only compile against Pigeonhole Sieve v0.1.14. - Fixed compilation of ManageSieve against CMUSieve. v0.11.9: - * Adjusted to changes in the Dovecot login proxy API. This release + * Adjusted to changes in the Dovecot login proxy API. This release therefore depends on Dovecot v1.2.4. + Reintroduced ability to abort SASL with "*" response. Latest ManageSieve specification includes it. v0.11.8: - Fixed TLS support for proxying ManageSieve. The protocol state machine - was incorrect. Also added a check that disables ssl when 'starttls' is - not enabled for the user. This produces a proper warning in the log file. - There is no such thing as a managesieveS protocol which has SSL from the + was incorrect. Also added a check that disables ssl when 'starttls' is + not enabled for the user. This produces a proper warning in the log file. + There is no such thing as a managesieveS protocol which has SSL from the start. v0.11.7: @@ -697,56 +697,56 @@ v0.11.7: - Fixed memory leak in the PUTSCRIPT command. v0.11.6: - * Adjusted to changes in Dovecot regarding client idle timeout vs + * Adjusted to changes in Dovecot regarding client idle timeout vs authentication timeout. This release now depends on Dovecot v1.2.rc6 or newer. - Fixed CRLF line breaks in compile errors (bug reported by Pascal Volk). - Corrected directory/file creation behavior with respect to mode bits and gid (bug reported by Pascal Volk). - Improved handling of script truncation bugs: connection is now closed and - an error is logged. bug itself not fixed yet). + an error is logged. bug itself not fixed yet). - Prevented temp script name from showing up in error output. v0.11.5: * Incorporated various changes from imap-login into managesieve-login. This includes changes in the proxy support. - + v0.11.4: * Adjusted to changes in the Dovecot signal handler API. v0.11.3: * Changed the SASL service name from "managesieve" into "sieve" as required - in the protocol specification. Don't forget to adjust your configuration - if your authentication mechanism depends on this service name. + in the protocol specification. Don't forget to adjust your configuration + if your authentication mechanism depends on this service name. * Adapted to changes in Dovecot, making this release dependent on Dovecot >= v1.2.beta1. * Adapted to changes in the new Sieve implementation, making this release - dependent on Dovecot Sieve >= v0.1.3 if used. The old cmusieve plugin is - still supported. - + Implemented making the SIEVE and NOTIFY capability fully dynamic, meaning - that the sieve_extensions setting that was introduced for the new Sieve + dependent on Dovecot Sieve >= v0.1.3 if used. The old cmusieve plugin is + still supported. + + Implemented making the SIEVE and NOTIFY capability fully dynamic, meaning + that the sieve_extensions setting that was introduced for the new Sieve plugin properly affects the ManageSieve daemon as well. - + Added support for the CHECKSCRIPT command. In terms of the supported + + Added support for the CHECKSCRIPT command. In terms of the supported commands, the ManageSieve daemon now complies with protocol VERSION 1.0 as - listed in the CAPABILITY response. + listed in the CAPABILITY response. - Fixed maximum permissions for uploaded scripts; was 0777. This - was shielded however by the default umask (not documented to be + was shielded however by the default umask (not documented to be configurable), so the actual permissions would never have been 0777. - Fixed a segfault bug in the authentication time-out. Bug report and trace provided by Wolfgang Friebel. - Fixed handling of ~/ in use of mail-data for script location. - Fixed small problems in the login proxy support. - + v0.11.2: - * Adapted to changes in Dovecot, making this release dependent on Dovecot - >= v1.2.alpa4. + * Adapted to changes in Dovecot, making this release dependent on Dovecot + >= v1.2.alpa4. v0.11.1: - Fixed security issue that gives virtual users the ability to read and modify each other's scripts if the directory structure of the sieve storage is known. * Updated NOOP command to match new protocol specification - + Improved error handling and implemented the new response codes: + + Improved error handling and implemented the new response codes: ACTIVE, NONEXISTENT, ALREADYEXISTS and WARNINGS v0.11.0: @@ -754,127 +754,127 @@ v0.11.0: * Added support for new ManageSieve extensions RENAME and NOOP * Moved sieve settings to plugin {} section of config file. Now the settings `sieve` and `sieve_dir` in the plugin section are used for the Sieve plugin - and the ManageSieve service, avoiding the posibility of accidental + and the ManageSieve service, avoiding the posibility of accidental differences in configuration. Dovecot 1.1: v0.10.3 * Removed erroneous inline declarations that caused compiler warnings. GCC 4.3 - turns out to fail entirely as reported by Joel Johnson. - * Fixed auto-dectection of Sieve implementation during ./configure. It now + turns out to fail entirely as reported by Joel Johnson. + * Fixed auto-dectection of Sieve implementation during ./configure. It now produces a proper error when the directory is invalid. v0.10.2 * Fixed bug that caused SASL mechanisms that require more than a single client - response to fail. Reported by Steffen Kaiser and occured when he tried using + response to fail. Reported by Steffen Kaiser and occured when he tried using the (obsolete) LOGIN mechanism. - * Updated installation and configuration documentation to match the + * Updated installation and configuration documentation to match the information provided in the wiki v0.10.1 * Fixed bug introduced in v0.10.0: compiled scripts were also written to disk - in the sieve/tmp directory and left there. This accumulates much .sievec - junk in that directory over time. + in the sieve/tmp directory and left there. This accumulates much .sievec + junk in that directory over time. * Fixed bug in tmp file generation for sieve-storage: errors other than EEXIST - would cause the daemon to sleep() loop indefinitely. - - + Improved log lines to be more recognizable as being generated from + would cause the daemon to sleep() loop indefinitely. + + + Improved log lines to be more recognizable as being generated from managesieve. + Added short proxy configuration explanation to the README file + Added 'Known Issues' section to the README file - Fixed assert bug in sieve-storage occuring when save is canceled. - + v0.10.0 * Upgraded to Dovecot 1.1: - - The actual managesieve implementation is now a separate package. - The dovecot tree still needs to be patched though to make dovecot + - The actual managesieve implementation is now a separate package. + The dovecot tree still needs to be patched though to make dovecot recognize the new managesieve service. - - Incorporated changes to imap/imap-login into the equivalent + - Incorporated changes to imap/imap-login into the equivalent managesieve processes. - - Removed cmusieve implementation from managesieve sources. It is - now linked externally from the dovecot-sieve-1.1 package. - - Restructured README.managesieve file into separate README, NEWS, - TODO, DESIGN and INSTALL files. - * Added support for new libsieve implementation (to be released). This + - Removed cmusieve implementation from managesieve sources. It is + now linked externally from the dovecot-sieve-1.1 package. + - Restructured README.managesieve file into separate README, NEWS, + TODO, DESIGN and INSTALL files. + * Added support for new libsieve implementation (to be released). This package can be compiled with either the new or the old Sieve - implementation (autodetected). If the new Sieve becomes stable, this - package will be merged with it to make a single package for Dovecot + implementation (autodetected). If the new Sieve becomes stable, this + package will be merged with it to make a single package for Dovecot Sieve support. - + Dovecot 1.0: v9 -+ Definitively fixed the segfault mentioned in V8. It proved to be ++ Definitively fixed the segfault mentioned in V8. It proved to be very time-constrained and thus hard to reproduce. The error turned out - to be related to the input handling of the login daemon during - authentication. -+ Checked for changes in the imap daemon that weren't propagated to the + to be related to the input handling of the login daemon during + authentication. ++ Checked for changes in the imap daemon that weren't propagated to the managesieve implementation due to code duplication. + Fixed a bug in the autodetection of the sieve storage location. + Fixed bug in the sieve storage that failed to refresh the symlink if - the storage was moved. -+ Improved error handing in the sieve-storage implementation in various - places. -+ Fixed the situation in which the active script link is located in the - sieve storage. + the storage was moved. ++ Improved error handing in the sieve-storage implementation in various + places. ++ Fixed the situation in which the active script link is located in the + sieve storage. + Added managesieve configuration to dovecot-example.conf and made the example - in this file more concise. + in this file more concise. v8 + Fixed a few incompatibilities with 1.0.7 version. For instance, the "Logged - in" message is now sent by the -login process and not by the managesieve - daemon anymore. This caused a segfault every once in a while. -+ Probably fixed the settings problem reported by Steffen Kaiser regarding + in" message is now sent by the -login process and not by the managesieve + daemon anymore. This caused a segfault every once in a while. ++ Probably fixed the settings problem reported by Steffen Kaiser regarding login_dir. 'dovecot -n' now reports correct results, but testing will show whether the whole problem is solved. + The managesieve daemon now accepts the sieve_storage and sieve configuration settings, so it is now possible to explicitly configure the location of the sieve storage and the active script respectively. The daemon still falls back - to using the mail_location (MAIL) settings if nothing else is specified. + to using the mail_location (MAIL) settings if nothing else is specified. + The cyrus timsieved does not use the + character in string literals and many clients have adopted to this behaviour. The latest managesieve (08) advises to - accept a missing + from clients. The server should not send any + characters - as well. This behavior is now implemented on the server. -+ Cleaned up sieve-storage.c: split up the sieve_storage_create function in + accept a missing + from clients. The server should not send any + characters + as well. This behavior is now implemented on the server. ++ Cleaned up sieve-storage.c: split up the sieve_storage_create function in various sub-functions for obtaining the various paths and directories. + Forced manual intervention if rescueing a non-symlink file at the active script - path fails somehow. Previously, this presented the admin with a log message - that it had just eaten the script, which is not very nice. + path fails somehow. Previously, this presented the admin with a log message + that it had just eaten the script, which is not very nice. + Restructured the README.managesieve file and added some more explanation with regard to the configuration of the daemon. -v7 +v7 - Robin Breathe indicated that the regex capability was missing in the server's - SIEVE listing. It turns out I forgot to make arrangements for setting + SIEVE listing. It turns out I forgot to make arrangements for setting ENABLE_REGEX in the cmu libsieve sources, so the regex extension was not - compiled in. I copied the configure.in section regarding ENABLE_REGEX from + compiled in. I copied the configure.in section regarding ENABLE_REGEX from dovecot-sieve-1.0.2 and that fixed the problem. v6 -- Corked the client output stream while producing the capability greeting and on - other some other occasions as well. Some naive client implementations expect to +- Corked the client output stream while producing the capability greeting and on + other some other occasions as well. Some naive client implementations expect to receive this as a single tcp frame and it is a good practice to do so anyway. Using this change the Thunderbird sieve extension (v0.1.1) seemed to work. However, scripts larger than a tcp frame still caused failures. All these issues are fixed - in the latest version of the sieve add-on (currently v0.1.4). + in the latest version of the sieve add-on (currently v0.1.4). - Cleaned up the new proxy source. My editor made the indentation a complete mess - in terms of TABs vs spaces. -- Added TRYLATER response codes to BYE and NO messages where appropriate. + in terms of TABs vs spaces. +- Added TRYLATER response codes to BYE and NO messages where appropriate. - Recopied the libsieve library into this patch to incorporate any changes that were - made (only sieve-cmu.c still needs to be compared to the old cmu-sieve.c). This + made (only sieve-cmu.c still needs to be compared to the old cmu-sieve.c). This also solves the __attribute__((unused)) GCC dependencies. These were fixed long - ago by Timo.... the code duplication beast strikes again. -- Removed spurious return value from void function in + ago by Timo.... the code duplication beast strikes again. +- Removed spurious return value from void function in src/lib-sieve/sieve-implementation.c as reported by Robin Breathe. GCC fails to report these issues. The function involved is currently not used and serves only - as an example on how dovecot could support multiple sieve backends... + as an example on how dovecot could support multiple sieve backends... -v5 +v5 - Applied patch by Uldis Pakuls to fix master_dump_settings bug - Added some compilation/installation info to this README @@ -884,51 +884,51 @@ v5 - Now sieve capabilities are reported as they are specified by the implementing library and not in forced upper case. The sieve RFC now explicitly states that sieve capability identifiers are case-sensitive. This broke compatibility - with SquirrelMail/Avelsieve. + with SquirrelMail/Avelsieve. - Disabled ANONYMOUS login entirely until proper support is implemented. V4 claimed to do so as well, but in fact it only stopped announcing it. - Implemented managesieve-proxy. It is not so much a clean copy of imap-proxy, - since the managesieve greeting is much more complex and requires parsing. + since the managesieve greeting is much more complex and requires parsing. Configuration is identical to imap-proxy. This seems to be a little under- - documented however (http://wiki.dovecot.org/PasswordDatabase/ExtraFields). + documented however (http://wiki.dovecot.org/PasswordDatabase/ExtraFields). v4 -- Added managesieve_implementation_string setting to the managesieve - configuration. This can be used to customize the default "IMPLEMENTATION" +- Added managesieve_implementation_string setting to the managesieve + configuration. This can be used to customize the default "IMPLEMENTATION" capability response. - Denied ANONYMOUS login until proper support is implemented - Fixed problem with authenticate command regarding continued responses. In - V3 only initial response would work. Problem was caused by rc2 -> rc28 + V3 only initial response would work. Problem was caused by rc2 -> rc28 upgrade. One of the clear reasons why code duplication is a very bad idea. - Fixed readlink bug as indicated by Timo: return value of readlink can also be -1. -- Fixed bug in the regular file rescue code, as introduced in the previous - version. Used stat instead of lstat. This caused the symlink to be rescued - subsequently in the next activation, thus still overwriting the initially +- Fixed bug in the regular file rescue code, as introduced in the previous + version. Used stat instead of lstat. This caused the symlink to be rescued + subsequently in the next activation, thus still overwriting the initially rescued script. v3 -- Updated source to compile with dovecot 1.0.rc27 +- Updated source to compile with dovecot 1.0.rc27 - Daemon now uses the same location for .dovecot.sieve as dovecot-lda This is typically ~/.dovecot.sieve - If .dovecot.sieve is a regular file, it is now moved into the script storage as - dovecot.orig.sieve, preventing deletion of (important) active scripts + dovecot.orig.sieve, preventing deletion of (important) active scripts upon upgrade. -- Changed error handling to yield a BYE message when the managesieve - daemon exits unexpectedly (upon login) before any commands are entered. - Horde-ingo would wait indefinitely for a response. +- Changed error handling to yield a BYE message when the managesieve + daemon exits unexpectedly (upon login) before any commands are entered. + Horde-ingo would wait indefinitely for a response. v2 - Fixed the bug (missing CRLF) in the authenticate command - Modified the sieve storage library making the interface much less crude. -- The scripts put on the server using the putscript command are now +- The scripts put on the server using the putscript command are now checked before they are accepted. -- The reported SIEVE capability is now directly read from the sieve - implementation (in this case cmu), listing much more than "FILEINTO +- The reported SIEVE capability is now directly read from the sieve + implementation (in this case cmu), listing much more than "FILEINTO VACATION". - Imported instance of libsieve source into this patch for implementation - of script checking and capability listing. THIS NEEDS TO BE CHANGED! + of script checking and capability listing. THIS NEEDS TO BE CHANGED! - Fixed some minor bugs in the putscript command diff --git a/README b/README index 6e2ed9e456eaa9fb85df82511ccfe83872b4f665..4e3c00ab01e256e4b16b79c8b7c8aac36c5bccc6 100644 --- a/README +++ b/README @@ -3,49 +3,49 @@ Pigeonhole for Dovecot v2.1 Introduction ============ -This package is part of the Pigeonhole project (http://pigeonhole.dovecot.org). +This package is part of the Pigeonhole project (http://pigeonhole.dovecot.org). It adds support for the Sieve language (RFC 5228) and the ManageSieve protocol -(RFC 5804) to the Dovecot Secure IMAP Server. In the literal sense, a pigeonhole -is a a hole or recess inside a dovecot for pigeons to nest in. It is, however, -also the name for one of a series of small, open compartments in a cabinet used -for filing or sorting mail. As a verb, it describes the act of putting an item +(RFC 5804) to the Dovecot Secure IMAP Server. In the literal sense, a pigeonhole +is a a hole or recess inside a dovecot for pigeons to nest in. It is, however, +also the name for one of a series of small, open compartments in a cabinet used +for filing or sorting mail. As a verb, it describes the act of putting an item into one of those pigeonholes. The name `Pigeonhole' therefore well describes an -important part of the functionality that this project adds to Dovecot: sorting +important part of the functionality that this project adds to Dovecot: sorting and filing e-mail messages. -The Sieve language is used to specify how e-mail needs to be processed. By +The Sieve language is used to specify how e-mail needs to be processed. By writing Sieve scripts, users can customize how messages are delivered, e.g. -whether they are forwarded or stored in special folders. Unwanted messages can +whether they are forwarded or stored in special folders. Unwanted messages can be discarded or rejected, and, when the user is not available, the Sieve interpreter can send an automated reply. Above all, the Sieve language is meant to be simple, extensible and system independent. And, unlike most other mail filtering script languages, it does not allow users to execute arbitrary programs. This is particularly useful to prevent virtual users from having full access to the mail store. The intention of the language is to make it impossible -for users to do anything more complex (and dangerous) than write simple mail +for users to do anything more complex (and dangerous) than write simple mail filters. -Using the ManageSieve protocol, users can upload their Sieve scripts remotely, +Using the ManageSieve protocol, users can upload their Sieve scripts remotely, without needing direct filesystem access through FTP or SCP. Additionally, a -ManageSieve server always makes sure that uploaded scripts are valid, preventing +ManageSieve server always makes sure that uploaded scripts are valid, preventing compile failures at mail delivery. -This package provides Sieve support as a plugin to Dovecot's Local Delivery +This package provides Sieve support as a plugin to Dovecot's Local Delivery Agent (LDA) and Dovecot's LMTP service. The ManageSieve protocol is provided is -an additional service, next to Dovecot's own POP3 and IMAP services. +an additional service, next to Dovecot's own POP3 and IMAP services. Features ======== - * The Pigeonhole Sieve implementation aims to be admin- and user-friendly. - Much like Dovecot itself, common error messages are made as easily - understandable as possible. Any crash, no matter how it happened, is + * The Pigeonhole Sieve implementation aims to be admin- and user-friendly. + Much like Dovecot itself, common error messages are made as easily + understandable as possible. Any crash, no matter how it happened, is considered a bug that will be fixed. The compiler does not bail on the first error, but it looks for more script errors to make debugging more efficient. * The Pigeonhole Sieve implementation is, much like the Sieve language itself, highly extensible with new Sieve capabilities. This includes support for - third-party plugins. It should eventually provide the necessary + third-party plugins. It should eventually provide the necessary infrastructure for at least all currently known relevant (proposed) Sieve extensions. The goal is to keep the extension interface provided by the Sieve implementation as generic as possible, i.e. without explicit support @@ -56,16 +56,16 @@ Features * The Pigeonhole Sieve plugin is backwards compatible with the old CMUSieve plugin, which provided Sieve support for older versions of Dovecot. All - Sieve extensions supported by the old plugin are also supported by the - Pigeonhole Sieve plugin, including those that are now considered to be + Sieve extensions supported by the old plugin are also supported by the + Pigeonhole Sieve plugin, including those that are now considered to be deprecated. * The Pigeonhole Sieve implementation supports executing multiple Sieve scripts sequentially. Using this feature it is possible to execute administrator-controlled Sieve scripts before and after the user's personal Sieve script, guaranteeing that responses and message deliveries are never - duplicated. This implementation is based on a draft specification - (http://tools.ietf.org/html/draft-degener-sieve-multiscript-00), which + duplicated. This implementation is based on a draft specification + (http://tools.ietf.org/html/draft-degener-sieve-multiscript-00), which defines the Sieve behavior when multiple scripts are executed sequentially on the same message. @@ -79,9 +79,9 @@ Features variables extension, which allows maintaining state information throughout a Sieve script across subsequent rules. - * The Pigeonhole Sieve plugin is distributed with a sieve-test tool that - simplifies testing Sieve scripts and provides additional debugging - facilities. + * The Pigeonhole Sieve plugin is distributed with a sieve-test tool that + simplifies testing Sieve scripts and provides additional debugging + facilities. Sieve Implementation Status =========================== @@ -118,7 +118,7 @@ following list outlines the implementation status of each supported extension: mailto method (RFC 5436): fully supported (v0.1.3+). xmpp method (RFC 5437): is under development and will become available as a plugin. - ihave (RFC 5463): fully supported (v0.2.4+). + ihave (RFC 5463): fully supported (v0.2.4+). mailbox (RFC 5490; Section 3): fully supported (v0.1.10+), but ACL permissions are not verified for mailboxexists. include (draft v05; not latest version): almost fully supported, but @@ -156,42 +156,42 @@ Refer to INSTALL file. Sieve Tools =========== -To test the sieve engine outside deliver, it is useful to try the commands that -exist in the src/sieve-tools/ directory of this package. After installation, -these are available at your $prefix/bin directory. The following commands are +To test the sieve engine outside deliver, it is useful to try the commands that +exist in the src/sieve-tools/ directory of this package. After installation, +these are available at your $prefix/bin directory. The following commands are installed: -sievec - Compiles sieve scripts into a binary representation for later - execution. Refer to the next section on manually compiling Sieve +sievec - Compiles sieve scripts into a binary representation for later + execution. Refer to the next section on manually compiling Sieve scripts. sieve-test - This is a universal Sieve test tool for testing the effect of a - Sieve script on a particular message. It allows compiling, running + Sieve script on a particular message. It allows compiling, running and testing Sieve scripts. It can either be used to display the actions that would be performed on the provided test message or it can be used to test the actual delivery of the message and show the messages that would normally be sent through SMTP. -sieve-dump - Dumps the content of a Sieve binary file for (development) +sieve-dump - Dumps the content of a Sieve binary file for (development) debugging purposes. When installed, man pages are also available for these commands. In this package -the man pages are present in doc/man and can be viewed before install using -e.g.: +the man pages are present in doc/man and can be viewed before install using +e.g.: man -l doc/man/sieve-test.1 Various example scripts are bundled in the directory 'examples'. These scripts -were downloaded from various locations. View the top comment in the scripts for +were downloaded from various locations. View the top comment in the scripts for url and author information. Compiling Sieve Scripts ======================= -When the LDA Sieve plugin executes a script for the first time (or after it has -been changed), it is compiled into into a binary form. The Pigeonhole Sieve -implementation uses the .svbin extension to store compiled Sieve scripts (e.g. -.dovecot.svbin). To store the binary, the plugin needs write access in the +When the LDA Sieve plugin executes a script for the first time (or after it has +been changed), it is compiled into into a binary form. The Pigeonhole Sieve +implementation uses the .svbin extension to store compiled Sieve scripts (e.g. +.dovecot.svbin). To store the binary, the plugin needs write access in the directory in which the script is located. A problem occurs when a global script is encountered by the plugin. For security @@ -221,7 +221,7 @@ Compile and Runtime Logging Log messages produced at runtime by the Sieve plugin are written to two locations: - * A log file is written in the same directory as the user's main private + * A log file is written in the same directory as the user's main private script (as specified by the sieve setting). This log file bears the name of that script file appended with ".log", e.g. .dovecot.sieve.log. If there are errors or warnings in the script, the messages are appended to that log file @@ -237,9 +237,9 @@ locations: messages. Compile errors encountered in the user's private script are not logged here. -The ManageSieve service reports compile errors and warnings only back to the -user. System and configuration-related messages are written to the Dovecot -logging facility. +The ManageSieve service reports compile errors and warnings only back to the +user. System and configuration-related messages are written to the Dovecot +logging facility. Known issues ============ @@ -250,8 +250,8 @@ Sieve Most open issues are outlined in the TODO file. The more generic ones are (re-) listed here: -* Compile errors are sometimes a bit obscure and long. This needs work. - Suggestions for improvement are welcome. +* Compile errors are sometimes a bit obscure and long. This needs work. + Suggestions for improvement are welcome. * The documentation needs work. @@ -292,6 +292,6 @@ Stephan Bosch <stephan at rename-it dot nl> IRC: Freenode, #dovecot, S[r]us Web: http://pigeonhole.dovecot.org -Please use the Dovecot mailing list <dovecot at dovecot.org> for questions about -this package. You can post to the list without subscribing, the mail then waits +Please use the Dovecot mailing list <dovecot at dovecot.org> for questions about +this package. You can post to the list without subscribing, the mail then waits in a moderator queue for a while. See http://dovecot.org/mailinglists.html diff --git a/TODO b/TODO index 6c6363816fc31c762f6581864698225c30579189..e1211b868e0ba18bd7e20576ad578f1c386fccf7 100644 --- a/TODO +++ b/TODO @@ -12,11 +12,11 @@ Parallel plugin-based efforts: * Implement enotify xmpp method as a plugin. * Implement metadata and servermetadata extensions as a plugin. - Compiles against dovecot metadata plugin, as currently developed by - Dennis Schridde. + Dennis Schridde. Next (mostly in order of descending priority/precedence): -* Make the sieve storage a base class with (possibly) various implementations, +* Make the sieve storage a base class with (possibly) various implementations, just like mail-storage. This aims to provide support for alternate types of script storage like LDAP or SQL database. - Implement read/write script storages for using ManageSieve with dict @@ -26,7 +26,7 @@ Next (mostly in order of descending priority/precedence): * Implement index extension * Add normalize() method to comparators to normalize the string before matching (for efficiency). -* Improve error handling. +* Improve error handling. - Implement dropping errors in the user's mailbox as a mail message. * Further develop regex extension and update it to the latest draft: - Implement the :quoteregex set modifier @@ -46,20 +46,20 @@ Next (mostly in order of descending priority/precedence): vacation command's :addresses list. * Fix remaining RFC deviations: - Fix issues listed in doc/rfc/RFC-questions.txt based on answers - - Allow for the existence of dynamic comparators (i.e. specified by - variables). + - Allow for the existence of dynamic comparators (i.e. specified by + variables). - Verify outgoing mail addresses at runtime when necessary (e.g. after variables substitution) - Improve handling of invalid addresses in headers (requires Dovecot changes) -* Properly implement Sieve internationalization support (utf-8 handling), +* Properly implement Sieve internationalization support (utf-8 handling), currently it is not complete: - - Make this implementation fully conform section 2.7.2 of RFC5228 (Comparisons - Across Character Sets). + - Make this implementation fully conform section 2.7.2 of RFC5228 (Comparisons + Across Character Sets). - Verify validity of utf8 where necessary. - Implement comparator-i;unicode-casemap. * Make testsuite much more exhaustive: - Add support for testing the content of result actions - - Test as many error/warning/info conditions as possible. + - Test as many error/warning/info conditions as possible. - Review the specification documents and check whether the given requirements are tested at least once. * Fix ManageSieve proxy to recognize response codes from the backend and forward @@ -68,37 +68,37 @@ Next (mostly in order of descending priority/precedence): - Test pipelined behavior - Test proxy authentication * Code cleanup: - - Make address handling more uniform. - - Review all FIXMEs + - Make address handling more uniform. + - Review all FIXMEs -* Build a server with test mail accounts that processes lots and lots of mail +* Build a server with test mail accounts that processes lots and lots of mail (e.g. spam, mailing lists etc.) * ## MAKE A FOURTH MAIN RELEASE (0.4.x) ## * Implement extlists extension as a plugin -* Enotify extension: detect use of variable values extracted from the message +* Enotify extension: detect use of variable values extracted from the message that are used in the method argument. RFC reports this as a security issue. * Add support for stream matching for handling large values, e.g. from the body extension. * Implement message modification and extraction API in order to: - - Implement replace, enclose, foreverypart, mime and extracttext extensions + - Implement replace, enclose, foreverypart, mime and extracttext extensions * Provide a solution for mail_get_headers_utf8 reparsing the whole message each time it is called (header and address test; Timo might provide solution from within Dovecot) -* Use lib/str-find.h for :contains and :matches match types +* Use lib/str-find.h for :contains and :matches match types * Warn during compile if using non-existent folders. * Implement IMAP plugin for IMAPSieve support: - Requires the same Sieve transaction support as the sieve-filter tool needs. - Requires (IMAP) metadata support in Dovecot. - This may include support for manually running a script on a set of messages - through IMAP (no specification for something like this is available; we will + through IMAP (no specification for something like this is available; we will have to provide our own) * Variables extension: implement compile time evaluation of constant values - Detect assignment of too large constant values to variables at compile time. * Add development documentation, i.e. comment on library functions and document - the binary and byte-code format. + the binary and byte-code format. * Implement sip-message notify mechanism. diff --git a/configure.in b/configure.in index b91675f9eccca70a76bf8492011d551f709269a1..987ac68297cf7321d8e3464b3810f5d154c80467 100644 --- a/configure.in +++ b/configure.in @@ -3,15 +3,15 @@ AC_CONFIG_AUX_DIR([.]) AC_CONFIG_SRCDIR([src]) AC_CONFIG_MACRO_DIR([m4]) -# Autoheader is not needed and does more harm than good for this package. However, it is -# tightly integrated in autoconf/automake and therefore it is difficult not to use it. As -# a workaround we give autoheader a dummy config header to chew on and we handle the +# Autoheader is not needed and does more harm than good for this package. However, it is +# tightly integrated in autoconf/automake and therefore it is difficult not to use it. As +# a workaround we give autoheader a dummy config header to chew on and we handle the # real config header ourselves. AC_CONFIG_HEADERS([dummy-config.h pigeonhole-config.h]) -AC_DEFINE_UNQUOTED(PIGEONHOLE_NAME, "$PACKAGE_NAME", +AC_DEFINE_UNQUOTED(PIGEONHOLE_NAME, "$PACKAGE_NAME", [Define to the full name of Pigeonhole for Dovecot.]) -AC_DEFINE_UNQUOTED(PIGEONHOLE_VERSION, "$PACKAGE_VERSION", +AC_DEFINE_UNQUOTED(PIGEONHOLE_VERSION, "$PACKAGE_VERSION", [Define to the version of Pigeonhole for Dovecot.]) AM_INIT_AUTOMAKE([no-define foreign tar-ustar]) @@ -27,7 +27,7 @@ AC_PROG_LIBTOOL DC_DOVECOT DC_DOVECOT_MODULEDIR -LIBDOVECOT_INCLUDE="$LIBDOVECOT_INCLUDE $LIBDOVECOT_STORAGE_INCLUDE" +LIBDOVECOT_INCLUDE="$LIBDOVECOT_INCLUDE $LIBDOVECOT_STORAGE_INCLUDE" CFLAGS="$DOVECOT_CFLAGS" LIBS="$DOVECOT_LIBS" AC_SUBST(LIBDOVECOT_INCLUDE) @@ -42,7 +42,7 @@ AC_SUBST(sieve_docdir) # AC_ARG_WITH(unfinished-features, -[AC_HELP_STRING([--with-unfinished-features], +[AC_HELP_STRING([--with-unfinished-features], [Build unfinished new features/extensions [default=no]])], if test x$withval = xno || test x$withval = xauto; then want_unfinished_features=$withval @@ -81,7 +81,7 @@ AC_ARG_ENABLE(valgrind, AM_CONDITIONAL(TESTSUITE_VALGRIND, test "$want_valgrind" = "yes") AC_ARG_WITH(managesieve, -[AC_HELP_STRING([--with-managesieve], +[AC_HELP_STRING([--with-managesieve], [Build ManageSieve service [default=yes]])], if test x$withval = xno || test x$withval = xauto; then want_managesieve=$withval diff --git a/doc/devel/DESIGN b/doc/devel/DESIGN index 09120aff172126aeaa7ceab8f2f45a21cc0b94c3..8e78112fa0872e2839aa6c85072afc7907723ed0 100644 --- a/doc/devel/DESIGN +++ b/doc/devel/DESIGN @@ -1,45 +1,45 @@ The compiler consists of the following stages: PARSER: sieve-parser.c, sieve-lexer.c - Parses the scriptfile and produces an abstract syntax tree for it - (sieve-ast.c). + Parses the scriptfile and produces an abstract syntax tree for it + (sieve-ast.c). VALIDATOR: sieve-validator.c - Performs contextual analysis on the ast produced by the parser. This checks - for the validity of commands, tests and arguments. Also, the ast is decorated - with any context data acquired during the process. This context is used by the - last compiler stage. + Performs contextual analysis on the ast produced by the parser. This checks + for the validity of commands, tests and arguments. Also, the ast is decorated + with any context data acquired during the process. This context is used by the + last compiler stage. GENERATOR: sieve-generator.c - This last compiler stage uses a visitor pattern to wander through the ast and + This last compiler stage uses a visitor pattern to wander through the ast and produces sieve byte code (sieve-binary.c). The resulting (in-memory) binary can be fed to the interpreter for execution: -INTERPRETER: sieve-interpreter.c - The interpreter executes the byte code and produces a sieve_result object. - This result is no more than just a collection of actions to be performed. - During execution, action commands add actions to the result. Duplates and +INTERPRETER: sieve-interpreter.c + The interpreter executes the byte code and produces a sieve_result object. + This result is no more than just a collection of actions to be performed. + During execution, action commands add actions to the result. Duplates and conflicts between actions are handled in this execution phase. RESULT: sieve-result.c sieve-actions.c - When the result is to be executed, it needs no further checking, as the - validity of the result was verified during interpretation already. The - result's actions are executed in a transaction-like atomic manner. If one of - the actions fails, the whole transaction is rolled back meaning that either + When the result is to be executed, it needs no further checking, as the + validity of the result was verified during interpretation already. The + result's actions are executed in a transaction-like atomic manner. If one of + the actions fails, the whole transaction is rolled back meaning that either everything succeeds or everything fails. This is only possible to some extent: - transmitted responses can of course not be rolled back. However, these are + transmitted responses can of course not be rolled back. However, these are executed in the commit phase, meaning that they will only be performed if all other actions were successful. - + Debugging: BINARY-DUMPER: sieve-code-dumper.c sieve-binary-dumper.c - A loaded binary can be dumped to a stream in human-readable form using the + A loaded binary can be dumped to a stream in human-readable form using the binary-dumper. The binary-dumper displays information on all the blocks that the binary consists off. Program code blocks are dumped using the code-dumper. - It's implementation is similar to the interpreter, with the exception that it - performs no actions and just sequentially wanders through the byte code - printing instructions along the way. The term human-readable is a bit optimistic - though; currently, the presented data looks like an assembly language. + It's implementation is similar to the interpreter, with the exception that it + performs no actions and just sequentially wanders through the byte code + printing instructions along the way. The term human-readable is a bit optimistic + though; currently, the presented data looks like an assembly language. diff --git a/doc/example-config/conf.d/20-managesieve.conf b/doc/example-config/conf.d/20-managesieve.conf index f115c12411cb99c982e66d9636dc319127ca436c..4d5155520c3340770464d27d697bde4fc8e28bf4 100644 --- a/doc/example-config/conf.d/20-managesieve.conf +++ b/doc/example-config/conf.d/20-managesieve.conf @@ -38,7 +38,7 @@ protocol sieve { # Maximum ManageSieve command line length in bytes. ManageSieve usually does # not involve overly long command lines, so this setting will not normally - # need adjustment + # need adjustment #managesieve_max_line_length = 65536 # Maximum number of ManageSieve connections allowed for a user from each IP @@ -57,20 +57,20 @@ protocol sieve { # To fool ManageSieve clients that are focused on CMU's timesieved you can # specify the IMPLEMENTATION capability that Dovecot reports to clients. - # For example: 'Cyrus timsieved v2.2.13' + # For example: 'Cyrus timsieved v2.2.13' #managesieve_implementation_string = Dovecot Pigeonhole # Explicitly specify the SIEVE and NOTIFY capability reported by the server # before login. If left unassigned these will be reported dynamically # according to what the Sieve interpreter supports by default (after login # this may differ depending on the user). - #managesieve_sieve_capability = - #managesieve_notify_capability = + #managesieve_sieve_capability = + #managesieve_notify_capability = # The maximum number of compile errors that are returned to the client upon - # script upload or script verification. + # script upload or script verification. #managesieve_max_compile_errors = 5 - # Refer to 90-sieve.conf for script quota configuration and configuration of - # Sieve execution limits. + # Refer to 90-sieve.conf for script quota configuration and configuration of + # Sieve execution limits. } diff --git a/doc/example-config/conf.d/90-sieve.conf b/doc/example-config/conf.d/90-sieve.conf index 35a9f5d36352643f22a4a762d834353efdb0acad..128d9c3667ff9d007c622c6ac66178233501e0fa 100644 --- a/doc/example-config/conf.d/90-sieve.conf +++ b/doc/example-config/conf.d/90-sieve.conf @@ -1,6 +1,6 @@ ## ## Settings for the Sieve interpreter -## +## # Do not forget to enable the Sieve plugin in 15-lda.conf and 20-lmtp.conf # by adding it to the respective mail_plugins= settings. @@ -22,7 +22,7 @@ plugin { # is also where the ManageSieve service stores the user's scripts. sieve_dir = ~/sieve - # Directory for :global include scripts for the include extension. + # Directory for :global include scripts for the include extension. #sieve_global_dir = # Path to a script file or a directory containing script files that need to be @@ -39,17 +39,17 @@ plugin { # user's script (only when keep is still in effect!). Multiple script file or # directory paths can be specified by appending an increasing number. #sieve_after = - #sieve_after2 = + #sieve_after2 = #sieve_after2 = (etc...) - # Which Sieve language extensions are available to users. By default, all + # Which Sieve language extensions are available to users. By default, all # supported extensions are available, except for deprecated extensions or # those that are still under development. Some system administrators may want # to disable certain Sieve extensions or enable those that are not available # by default. This setting can use '+' and '-' to specify differences relative # to the default. For example `sieve_extensions = +imapflags' will enable the # deprecated imapflags extension in addition to all extensions were already - # enabled by default. + # enabled by default. #sieve_extensions = +notify +imapflags # Which Sieve language extensions are ONLY available in global scripts. This @@ -57,7 +57,7 @@ plugin { # control, for instance when these extensions can cause security concerns. # This setting has higher precedence than the `sieve_extensions' setting # (above), meaning that the extensions enabled with this setting are never - # available to the user's personal script no matter what is specified for the + # available to the user's personal script no matter what is specified for the # `sieve_extensions' setting. The syntax of this setting is similar to the # `sieve_extensions' setting, with the difference that extensions are # enabled or disabled for exclusive use in global scripts. Currently, no @@ -70,11 +70,11 @@ plugin { # (http://pigeonhole.dovecot.org) for available plugins. #sieve_plugins = - # The separator that is expected between the :user and :detail - # address parts introduced by the subaddress extension. This may - # also be a sequence of characters (e.g. '--'). The current - # implementation looks for the separator from the left of the - # localpart and uses the first one encountered. The :user part is + # The separator that is expected between the :user and :detail + # address parts introduced by the subaddress extension. This may + # also be a sequence of characters (e.g. '--'). The current + # implementation looks for the separator from the left of the + # localpart and uses the first one encountered. The :user part is # left of the separator and the :detail part is right. This setting # is also used by Dovecot's LMTP service. #recipient_delimiter = + @@ -99,6 +99,6 @@ plugin { # The maximum amount of disk storage a single user's scripts may occupy. If # set to 0, no limit on the used amount of disk storage is enforced. - # (Currently only relevant for ManageSieve) + # (Currently only relevant for ManageSieve) #sieve_quota_max_storage = 0 } diff --git a/doc/extensions/editheader.txt b/doc/extensions/editheader.txt index 0fd674ca65a707e1e9ce88243101e07b419e24ce..172ce9c52e6b85b5501a4240ae95128bf33e5e40 100644 --- a/doc/extensions/editheader.txt +++ b/doc/extensions/editheader.txt @@ -16,7 +16,7 @@ Configuration ============= The editheader is not available by default and needs to be enabled explicitly by -adding it to the sieve_extensions setting. +adding it to the sieve_extensions setting. The following settings can be configured for the editheader extension (default values are indicated): @@ -33,7 +33,7 @@ sieve_editheader_protected = RFC specification; adding one of these headers to this setting has no effect. Invalid values for the settings above will make the Sieve interpreter log -a warning and revert to the default values. +a warning and revert to the default values. Example ======= diff --git a/doc/extensions/include.txt b/doc/extensions/include.txt index 6f69a364551abab299b06ea0bb96e113e5b6b1b9..44cfacce6038f90922159a8faffa71d085cdad69 100644 --- a/doc/extensions/include.txt +++ b/doc/extensions/include.txt @@ -15,7 +15,7 @@ are able to include their own personal scripts or site-wide scripts. Included scripts can include more scripts of their own, yielding a tree of included scripts with the main script (typically the user's personal script) at -its root. +its root. Configuration ============= @@ -29,4 +29,4 @@ sieve_include_max_includes = 255 of scripts involved in the include tree. sieve_include_max_nesting_depth = 10 - The maximum nesting depth for the include tree. + The maximum nesting depth for the include tree. diff --git a/doc/extensions/spamtest-virustest.txt b/doc/extensions/spamtest-virustest.txt index 34036c68ecc4c6f10b72e9fbe884553416f699e2..892874748222b7709e5b54655b9e1230a3cdd65a 100644 --- a/doc/extensions/spamtest-virustest.txt +++ b/doc/extensions/spamtest-virustest.txt @@ -8,13 +8,13 @@ Relevant Specifications Description =========== -Using the spamtest and virustest extensions (RFC 5235), the Sieve language +Using the spamtest and virustest extensions (RFC 5235), the Sieve language provides a uniform and standardized command interface for evaluating spam and -virus tests performed on the message. Users no longer need to know what headers -need to be checked and how the scanner's verdict is represented in the header -field value. They only need to know how to use the spamtest (spamtestplus) and -virustest extensions. This also gives GUI-based Sieve editors the means to -provide a portable and easy to install interface for spam and virus filter +virus tests performed on the message. Users no longer need to know what headers +need to be checked and how the scanner's verdict is represented in the header +field value. They only need to know how to use the spamtest (spamtestplus) and +virustest extensions. This also gives GUI-based Sieve editors the means to +provide a portable and easy to install interface for spam and virus filter configuration. The burden of specifying which headers need to be checked and how the scanner output is represented falls onto the Sieve administrator. @@ -22,7 +22,7 @@ Configuration ============= The spamtest, spamtestplus and virustest extensions are not enabled by default -and thus need to be enabled explicitly using the sieve_extensions setting. +and thus need to be enabled explicitly using the sieve_extensions setting. The following settings need to be configured for using the spamtest and spamtestplus extensions. The virustest extension has identical configuration @@ -30,29 +30,29 @@ settings, but with a `sieve_virustest_' prefix instead of a `sieve_spamtest_' prefix: sieve_spamtest_status_type = "score" / "strlen" / "text" - This specifies the type of status result that the spam/virus scanner produces. - This can either be a numeric score ("score"), a string of identical characters + This specifies the type of status result that the spam/virus scanner produces. + This can either be a numeric score ("score"), a string of identical characters ("strlen"), e.g. '*******', or a textual description, e.g. `Spam' - or `Not Spam'. + or `Not Spam'. sieve_spamtest_status_header = <header-field> [ ":" <regexp> ] This specifies the header field that contains the result information of the spam scanner and it may express the syntax of the content of the header. If no matching header is found in the message, the spamtest command will match - against "0". + against "0". - This is a structured setting. The first part specifies the header field name. + This is a structured setting. The first part specifies the header field name. Optionally, a POSIX regular expression follows the header field name, separated by a colon. Any whitespace directly following the colon is not part of the regular expression. If the regular expression is omitted, any header content is accepted and the full header value is used. When a regular - expression is used, it must specify one match value (inside brackets) that + expression is used, it must specify one match value (inside brackets) that yields the desired spam scanner result. If the header does not match the - regular expression or if no value match is found, the spamtest will match - against "0". + regular expression or if no value match is found, the spamtest will match + against "0". -sieve_spamtest_max_value = - This statically specifies the maximum value a numeric spam score can have. +sieve_spamtest_max_value = + This statically specifies the maximum value a numeric spam score can have. sieve_spamtest_max_header = <header-field> [ ":" <regexp> ] Some spam scanners include the maximum score value in one of their status @@ -72,7 +72,7 @@ Examples ======== This section shows several configuration examples. Each example shows a specimen -of valid virus/spam test headers that the given configuration will work on. +of valid virus/spam test headers that the given configuration will work on. Example 1 --------- @@ -135,6 +135,6 @@ plugin { sieve_virustest_text_value1 = clean sieve_virustest_text_value5 = infected } - - + + diff --git a/doc/extensions/vacation.txt b/doc/extensions/vacation.txt index df8ec5563db1210d8d65a18181b682440ac524d8..8c9f8e9344a99f3fdc46675a123279292137f7df 100644 --- a/doc/extensions/vacation.txt +++ b/doc/extensions/vacation.txt @@ -23,14 +23,14 @@ Configuration ============= The vacation extension is available by default. In contrast, the -vacation-seconds extension - which implies the vacation extension when used - is +vacation-seconds extension - which implies the vacation extension when used - is not available by default and needs to be enabled explicitly by adding it to the sieve_extensions setting. The configuration also needs to be adjusted -accordingly to allow a non-reply period of less than a day. +accordingly to allow a non-reply period of less than a day. The vacation and vacation-seconds extensions have their own specific settings. The settings that specify a period are specified in s(econds), unless followed -by a d(ay), h(our) or m(inute) specifier character. +by a d(ay), h(our) or m(inute) specifier character. The following settings can be configured for the vacation extension (default values are indicated): @@ -40,13 +40,13 @@ sieve_vacation_min_period = 1d :seconds tags of the vacation command. A minimum of 0 indicates that users are allowed to make the Sieve interpreter send a vacation response message for every incoming message that meets the other reply criteria (refer to RFC5230). - A value of zero is however not recommended. + A value of zero is however not recommended. sieve_vacation_max_period = 0 This specifies the maximum period that can be specified for the :days tag of the vacation command. The configured value must be larger than the sieve_vacation_min_period setting. A value of 0 has a special meaning: it - indicates that there is no upper limit. + indicates that there is no upper limit. sieve_vacation_default_period = 7d This specifies the default period that is used when no :days or :seconds tag @@ -64,17 +64,17 @@ sieve_vacation_use_original_recipient = no including the original recipient specified in the SMTP session if available. This is useful to handle mail accounts with aliases. Use this option with caution: if you are using aliases that point to more than a single account, - senders can get multiple vacation responses for a single message. - + senders can get multiple vacation responses for a single message. + sieve_vacation_dont_check_recipient = no This disables the checks for implicit delivery entirely. This means that the vacation command does not verify that the message is explicitly addressed at the recipient. Use this option with caution. Specifying 'yes' will violate the Sieve standards and can cause vacation replies to be sent for messages not - directly addressed at the recipient. + directly addressed at the recipient. Invalid values for the settings above will make the Sieve interpreter log a -warning and revert to the default values. +warning and revert to the default values. Example ======= diff --git a/doc/man/pigeonhole.7.in b/doc/man/pigeonhole.7.in index 6625e0df3e81aa32c513e5e603c143f5d52d75b7..f86d5e6887448b68b3dc6df86f3bfb73a18a27fc 100644 --- a/doc/man/pigeonhole.7.in +++ b/doc/man/pigeonhole.7.in @@ -61,7 +61,7 @@ The universal Sieve test tool for testing the effect of a Sieve script on a particular message. .TP .BR sieve\-filter (1) -Filters all messages in a particular source mailbox through a Sieve script. +Filters all messages in a particular source mailbox through a Sieve script. .TP .BR sieve\-dump (1) Dumps the content of a Sieve binary file for (development) debugging purposes. diff --git a/doc/man/sieve-dump.1.in b/doc/man/sieve-dump.1.in index 3f8a887c9419c30ba32af744a4403fc4475a2225..2509ae06d8eba560b4c399487687767a34098333 100644 --- a/doc/man/sieve-dump.1.in +++ b/doc/man/sieve-dump.1.in @@ -54,7 +54,7 @@ are ignored and a warning is produced. For example \fB\-x\fP \(dq+imapflags \-enotify\(dq will enable the deprecated imapflags extension and disable the enotify extension. The rest of the active -extensions depends on the \fIsieve_extensions\fP and +extensions depends on the \fIsieve_extensions\fP and \fIsieve_global_extensions\fP settings. By default, i.e. when \fIsieve_extensions\fP and \fIsieve_global_extensions\fP remain unconfigured, all supported extensions are available, except for deprecated diff --git a/doc/man/sieve-filter.1.in b/doc/man/sieve-filter.1.in index 429bc64f504886201234da9faaad902a740e36ef..9f74e3854eeaab859d4492f01a36c28b62707746 100644 --- a/doc/man/sieve-filter.1.in +++ b/doc/man/sieve-filter.1.in @@ -7,7 +7,7 @@ sieve\-filter \- Pigeonhole\(aqs Sieve mailbox filter tool \fBWARNING: \fRThis tool is still experimental. Read this manual carefully, and backup any important mail before using this tool. Also note that some of the features documented here are not actually implemented yet; this is clearly -indicated where applicable. +indicated where applicable. .\"------------------------------------------------------------------------ .SH SYNOPSIS .B sieve\-filter @@ -21,7 +21,7 @@ The \fBsieve\-filter\fP command is part of the Pigeonhole Project (\fBpigeonhole\fR(7)), which adds Sieve (RFC 5228) support to the Dovecot secure IMAP and POP3 server (\fBdovecot\fR(1)). .PP -The Sieve language was originally meant for filtering messages upon delivery. +The Sieve language was originally meant for filtering messages upon delivery. However, there are occasions when it is desirable to filter messages that are already stored in a mailbox, for instance when a bug in a Sieve script caused many messages to be delivered incorrectly. Using the sieve\-filter tool it is @@ -30,14 +30,14 @@ possible to apply a Sieve script on all messages in a particular different mailbox, to change their content, and to change the assigned IMAP flags and keywords. Attempts to send messages to the outside world are ignored by default for obvious reasons, but, using the proper command line options, it -is possible to capture and handle outgoing mail as well. +is possible to capture and handle outgoing mail as well. .PP If no options are specified, the sieve\-filter command runs in a simulation mode in which it only prints what would be performed, without actually doing anything. Use the \fB\-e\fP option to activate true script execution. Also, the \fIsource\-mailbox\fP is opened read\-only by default, meaning that it normally always remains unchanged. Use the \fB\-W\fP option to allow changes in the -\fIsource\-mailbox\fP. +\fIsource\-mailbox\fP. .PP Even with the \fB\-W\fP option enabled, messages in the \fIsource\-mailbox\fP are only potentially modified or moved to a different folder. Messages are never @@ -49,7 +49,7 @@ the Sieve interpreter using the \fIimap4flags\fP extension, provided that \fB\-W\fP is specified. If the message itself is modified by the Sieve interpreter (e.g. using the \fIeditheader\fP extension), a new message is stored and the old one is expunged. However, if \fB-W\fP is omitted, the original -message is left untouched and the modifications are discarded. +message is left untouched and the modifications are discarded. .SS CAUTION Although this is a very useful tool, it can also be very destructive when used @@ -84,7 +84,7 @@ Enable Sieve debugging. Turns on execution mode. By default, the sieve\-filter command runs in simulation mode in which it changes nothing, meaning that no mailbox is altered in any way and no actions are performed. It only prints what would be done. -Using this option, the sieve\-filter command becomes active and performs the +Using this option, the sieve\-filter command becomes active and performs the requested actions. .TP .BI \-m\ default\-mailbox @@ -99,7 +99,7 @@ Store outgoing e\-mail into the indicated \fIoutput\-mailbox\fP. By default, the sieve\-filter command ignores Sieve actions such as redirect, reject, vacation and notify, but using this option outgoing messages can be appended to the indicated mailbox. This option has no effect in simulation mode. Flags of -redirected messages are not preserved. +redirected messages are not preserved. .TP .BI \-Q\ mail\-command\ \fB[not\ implemented\ yet]\fP Send outgoing e\-mail (e.g. as produced by redirect, reject and vacation) @@ -123,7 +123,7 @@ Produce verbose output during filtering. .B \-W Enables write access to the \fIsource\-mailbox\fP. This allows (re)moving the messages from the \fIsource\-mailbox\fP, changing their contents, and changing -the assigned IMAP flags and keywords. +the assigned IMAP flags and keywords. .TP .BI \-x\ extensions Set the available extensions. The parameter is a space\-separated list of the @@ -135,7 +135,7 @@ are ignored and a warning is produced. For example \fB\-x\fP \(dq+imapflags \-enotify\(dq will enable the deprecated imapflags extension and disable the enotify extension. The rest of the active -extensions depends on the \fIsieve_extensions\fP and +extensions depends on the \fIsieve_extensions\fP and \fIsieve_global_extensions\fP settings. By default, i.e. when \fIsieve_extensions\fP and \fIsieve_global_extensions\fP remain unconfigured, all supported extensions are available, except for deprecated @@ -154,26 +154,26 @@ into a new binary. .TP .I source\-mailbox The name of the source mailbox containing the messages that the Sieve filter -will act upon. This mailbox is not modified unless the \fB\-W\fP option is +will act upon. This mailbox is not modified unless the \fB\-W\fP option is specified. -.TP +.TP .I discard\-action Specifies what is done with messages in the \fIsource\-mailbox\fP that where not kept or otherwise stored by the Sieve script; i.e. those messages that would normally be discarded if the Sieve script were executed at delivery. The \fIdiscard\-action\fP parameter accepts one of the following values: .RS 7 -.TP +.TP .BR keep\ (default) -Keep discarded messages in source mailbox. -.TP +Keep discarded messages in source mailbox. +.TP .BI move\ mailbox Move discarded messages to the indicated \fImailbox\fP. This is for instance -useful to move messages to a Trash mailbox. -.TP +useful to move messages to a Trash mailbox. +.TP .B delete Flag discarded messages as \\DELETED. -.TP +.TP .B expunge Expunge discarded messages, meaning that these are removed irreversibly when the tool finishes filtering. @@ -184,7 +184,7 @@ immutable and the specified \fIdiscard\-action\fP has no effect. This means that messages are at most \fIcopied\fP to a new location. In contrast, when the \fB\-W\fP is specified, messages that are successfully stored somewhere else by the Sieve script are \fBalways\fP expunged from the \fIsource\-mailbox\fP, with -the effect that these are thus \fImoved\fP to the new location. This happens +the effect that these are thus \fImoved\fP to the new location. This happens irrespective of the specified \fIdiscard\-action\fP. Remember: only discarded messages are affected by the specified \fIdiscard\-action\fP. diff --git a/doc/man/sieve-test.1.in b/doc/man/sieve-test.1.in index 53c4fd6be6161e0601b707b8be5f969f406d9534..946c5b7cc744148212794f1e6010870556f45f0a 100644 --- a/doc/man/sieve-test.1.in +++ b/doc/man/sieve-test.1.in @@ -91,7 +91,7 @@ The final envelope recipient address. Some tests and actions will use this as the script owner\(aqs e\-mail address. For example, this is what is used by the vacation action to check whether a reply is appropriate. If the \fB\-r\fP option is omitted, the orignal envelope recipient address will be used -in stead (see \fB\-a\fP option for more info). +in stead (see \fB\-a\fP option for more info). .TP .BI \-s\ script\-file Specify additional scripts to be executed before the main script. Multiple @@ -119,7 +119,7 @@ are ignored and a warning is produced. For example \fB\-x\fP \(dq+imapflags \-enotify\(dq will enable the deprecated imapflags extension and disable the enotify extension. The rest of the active -extensions depends on the \fIsieve_extensions\fP and +extensions depends on the \fIsieve_extensions\fP and \fIsieve_global_extensions\fP settings. By default, i.e. when \fIsieve_extensions\fP and \fIsieve_global_extensions\fP remain unconfigured, all supported extensions are available, except for deprecated @@ -182,7 +182,7 @@ addresses are equal to those listed in a binary dump produced using the .\"------------------------------------------------------------------------ .SS DEBUG SIEVE EXTENSION .PP -To improve script debugging, this Sieve implementation supports a custom Sieve +To improve script debugging, this Sieve implementation supports a custom Sieve language extension called \(aqvnd.dovecot.debug\(aq. It adds the \fBdebug_log\fP command that allows logging debug messages. .PP @@ -203,7 +203,7 @@ the \fB\-x\fP option. The logged messages are written to \fBstdout\fP in this case. In contrast, for the actual Sieve plugin for the Dovecot LDA -(\fBdovecot\-lda\fR(1)) the vnd.dovecot.debug extension needs to be enabled +(\fBdovecot\-lda\fR(1)) the vnd.dovecot.debug extension needs to be enabled explicitly using the \fIsieve_extensions\fP setting. The messages are then logged to the user's private script log file. If used in a global script, the messages are logged through the default Dovecot logging facility. diff --git a/doc/man/sievec.1.in b/doc/man/sievec.1.in index 0df56bc3049b810407a00b02239ff18e7039c85b..8aca136abb5e7f8743507d5a615814a164a6ad6b 100644 --- a/doc/man/sievec.1.in +++ b/doc/man/sievec.1.in @@ -67,7 +67,7 @@ are ignored and a warning is produced. For example \fB\-x\fP \(dq+imapflags \-enotify\(dq will enable the deprecated imapflags extension and disable the enotify extension. The rest of the active -extensions depends on the \fIsieve_extensions\fP and +extensions depends on the \fIsieve_extensions\fP and \fIsieve_global_extensions\fP settings. By default, i.e. when \fIsieve_extensions\fP and \fIsieve_global_extensions\fP remain unconfigured, all supported extensions are available, except for deprecated diff --git a/doc/script-location-dict.txt b/doc/script-location-dict.txt index 3ee5a894d7f867e241874c7c70b3ef399451604a..9312ba34fa2628ca9edc305c61eb117faccc2489 100644 --- a/doc/script-location-dict.txt +++ b/doc/script-location-dict.txt @@ -45,7 +45,7 @@ The following additional options are recognized: user running the Sieve interpreter is used. If the name of the Script is left unspecified and not otherwise provided by the -Sieve interpreter, the name defaults to `default'. +Sieve interpreter, the name defaults to `default'. Examples ======== @@ -79,7 +79,7 @@ plugin { } The Sieve script named "keep" is retrieved from the file dict as the main -script. Binaries are stored in the ~/.sieve-bin directory. +script. Binaries are stored in the ~/.sieve-bin directory. Example 2 --------- diff --git a/src/lib-managesieve/Makefile.am b/src/lib-managesieve/Makefile.am index b24113477d7e7b9dc69fc0471b3043651b7dda5b..65fda67669a90d55641f06dd80abdb554dfe1a1b 100644 --- a/src/lib-managesieve/Makefile.am +++ b/src/lib-managesieve/Makefile.am @@ -7,9 +7,9 @@ AM_CPPFLAGS = \ libmanagesieve_a_SOURCES = \ managesieve-arg.c \ managesieve-quote.c \ - managesieve-parser.c + managesieve-parser.c noinst_HEADERS = \ managesieve-arg.h \ managesieve-quote.h \ - managesieve-parser.h + managesieve-parser.h diff --git a/src/lib-managesieve/managesieve-arg.c b/src/lib-managesieve/managesieve-arg.c index f1f409320b1eb216edbf9cfbe1a4d2240ad4d4df..403124a84d92a568527de8214b76492ddfcea2c6 100644 --- a/src/lib-managesieve/managesieve-arg.c +++ b/src/lib-managesieve/managesieve-arg.c @@ -37,9 +37,9 @@ bool managesieve_arg_get_number num = newnum; } - + *number_r = num; - return TRUE; + return TRUE; } bool managesieve_arg_get_quoted diff --git a/src/lib-managesieve/managesieve-arg.h b/src/lib-managesieve/managesieve-arg.h index caff69b5e0a87cf6a0ec4e08e7f3238acca5fc23..0b938baba1ad69654bfe972f9c58559fba3fa683 100644 --- a/src/lib-managesieve/managesieve-arg.h +++ b/src/lib-managesieve/managesieve-arg.h @@ -12,21 +12,21 @@ #define IS_QUOTED_SPECIAL(c) \ ((c) == '"' || (c) == '\\') -/* +/* * ATOM-SPECIALS = "(" / ")" / "{" / SP / CTL / QUOTED-SPECIALS */ #define IS_ATOM_SPECIAL(c) \ ((c) == '(' || (c) == ')' || (c) == '{' || \ (c) <= 32 || (c) == 0x7f || \ - IS_QUOTED_SPECIAL(c)) + IS_QUOTED_SPECIAL(c)) -/* +/* * CHAR = %x01-7F */ #define IS_CHAR(c) \ (((c) & 0x80) == 0) -/* +/* * TEXT-CHAR = %x01-09 / %x0B-0C / %x0E-7F * ;; any CHAR except CR and LF */ diff --git a/src/lib-managesieve/managesieve-parser.c b/src/lib-managesieve/managesieve-parser.c index d05888a5f9aef6b301d345f697fdddc85ab5e639..8c970098761f7c4a868f947605154d6378cdde00 100644 --- a/src/lib-managesieve/managesieve-parser.c +++ b/src/lib-managesieve/managesieve-parser.c @@ -174,7 +174,7 @@ static void managesieve_parser_save_arg(struct managesieve_parser *parser, /* -1 because we skipped the '"' prefix */ str_unescape(str + parser->str_first_escape-1); } - + arg->_data.str = str; arg->str_len = strlen(str); } @@ -396,7 +396,7 @@ static int managesieve_parser_read_literal_data(struct managesieve_parser *parse parser->error = "Invalid UTF-8 character in literal string."; return FALSE; } - + managesieve_parser_save_arg(parser, data, (size_t)parser->literal_size); parser->cur_pos = (size_t)parser->literal_size; diff --git a/src/lib-managesieve/managesieve-parser.h b/src/lib-managesieve/managesieve-parser.h index 5312a6fb7c3dbfe85dc8c35aec8e0273f0e15ba0..641b974946ee13fd0ab86d5830dd63baeab3e635 100644 --- a/src/lib-managesieve/managesieve-parser.h +++ b/src/lib-managesieve/managesieve-parser.h @@ -20,7 +20,7 @@ enum managesieve_parser_flags { struct managesieve_parser; -/* Create new MANAGESIEVE argument parser. +/* Create new MANAGESIEVE argument parser. max_line_size can be used to approximately limit the maximum amount of memory that gets allocated when parsing a line. Input buffer size limits diff --git a/src/lib-managesieve/managesieve-quote.c b/src/lib-managesieve/managesieve-quote.c index 72c7a3f75f850a37dbd3177176fab14131527fd8..6bcb0ca57f9b0deea2e9fdff196ef7b2d0908125 100644 --- a/src/lib-managesieve/managesieve-quote.c +++ b/src/lib-managesieve/managesieve-quote.c @@ -7,7 +7,7 @@ #include "managesieve-parser.h" #include "managesieve-quote.h" -/* Turn the value string into a valid MANAGESIEVE string or literal, no matter +/* Turn the value string into a valid MANAGESIEVE string or literal, no matter * what. QUOTED-SPECIALS are escaped, but any invalid (UTF-8) character * is simply removed. Linebreak characters are not considered invalid, but * they do force the generation of a string literal. @@ -17,9 +17,9 @@ void managesieve_quote_append(string_t *str, const unsigned char *value, { size_t i, extra = 0, escape = 0; string_t *tmp; - bool - last_lwsp = TRUE, - literal = FALSE, + bool + last_lwsp = TRUE, + literal = FALSE, modify = FALSE; if (value == NULL) { @@ -73,7 +73,7 @@ void managesieve_quote_append(string_t *str, const unsigned char *value, case '"': case '\\': last_lwsp = FALSE; - if (!literal) + if (!literal) str_append_c(tmp, '\\'); str_append_c(tmp, value[i]); break; diff --git a/src/lib-sieve-tool/mail-raw.c b/src/lib-sieve-tool/mail-raw.c index b7cb504d6fff0cbe7bca42515d23bf37c11b2c8f..497c05bf96da7c2e1fe5c5c7fa5ba1f6c0d20d90 100644 --- a/src/lib-sieve-tool/mail-raw.c +++ b/src/lib-sieve-tool/mail-raw.c @@ -154,7 +154,7 @@ static struct istream *mail_raw_create_stream */ struct mail_user *mail_raw_user_create -(struct master_service *service, struct mail_user *mail_user) +(struct master_service *service, struct mail_user *mail_user) { void **sets = master_service_settings_get_others(service); @@ -166,7 +166,7 @@ struct mail_user *mail_raw_user_create */ static struct mail_raw *mail_raw_create -(struct mail_user *ruser, struct istream *input, +(struct mail_user *ruser, struct istream *input, const char *mailfile, const char *sender, time_t mtime) { struct mail_raw *mailr; @@ -175,11 +175,11 @@ static struct mail_raw *mail_raw_create int ret; if ( mailfile != NULL && *mailfile != '/' ) - mailfile = t_abspath(mailfile); + mailfile = t_abspath(mailfile); mailr = i_new(struct mail_raw, 1); - envelope_sender = sender != NULL ? sender : DEFAULT_ENVELOPE_SENDER; + envelope_sender = sender != NULL ? sender : DEFAULT_ENVELOPE_SENDER; if ( mailfile == NULL ) { ret = raw_mailbox_alloc_stream(ruser, input, mtime, envelope_sender, &mailr->box); @@ -210,14 +210,14 @@ struct mail_raw *mail_raw_open_data input = i_stream_create_from_data(str_data(mail_data), str_len(mail_data)); i_stream_set_name(input, "data"); - + mailr = mail_raw_create(ruser, input, NULL, NULL, (time_t)-1); i_stream_unref(&input); return mailr; } - + struct mail_raw *mail_raw_open_file (struct mail_user *ruser, const char *path) { @@ -225,7 +225,7 @@ struct mail_raw *mail_raw_open_file struct istream *input = NULL; time_t mtime = (time_t)-1; const char *sender = NULL; - + if ( path == NULL || strcmp(path, "-") == 0 ) { path = NULL; input = mail_raw_create_stream(ruser, 0, &mtime, &sender); @@ -239,7 +239,7 @@ struct mail_raw *mail_raw_open_file return mailr; } -void mail_raw_close(struct mail_raw **mailr) +void mail_raw_close(struct mail_raw **mailr) { mail_free(&(*mailr)->mail); mailbox_transaction_rollback(&(*mailr)->trans); diff --git a/src/lib-sieve-tool/sieve-tool.c b/src/lib-sieve-tool/sieve-tool.c index d242cb89c4f23e21ee5b646e8afed9f4333816f5..d3a055878a7a8519f0c42d6f34efca31ed71a0e9 100644 --- a/src/lib-sieve-tool/sieve-tool.c +++ b/src/lib-sieve-tool/sieve-tool.c @@ -114,12 +114,12 @@ static void sieve_tool_get_user_data if ((pw = getpwuid(process_euid)) != NULL) { user = pw->pw_name; home = pw->pw_dir; - } + } } if ( username_r != NULL ) { if ( user == NULL || *user == '\0' ) { - i_fatal("couldn't lookup our username (uid=%s)", + i_fatal("couldn't lookup our username (uid=%s)", dec2str(process_euid)); } @@ -148,7 +148,7 @@ struct sieve_tool *sieve_tool_init tool = i_new(struct sieve_tool, 1); tool->name = i_strdup(name); tool->no_config = no_config; - + i_array_init(&tool->sieve_plugins, 16); return tool; @@ -159,11 +159,11 @@ int sieve_tool_getopt(struct sieve_tool *tool) int c; while ( (c = master_getopt(master_service)) > 0 ) { - switch ( c ) { + switch ( c ) { case 'x': /* extensions */ if ( tool->sieve_extensions != NULL ) { - i_fatal_status(EX_USAGE, + i_fatal_status(EX_USAGE, "duplicate -x option specified, but only one allowed."); } @@ -173,10 +173,10 @@ int sieve_tool_getopt(struct sieve_tool *tool) if ( tool->username == NULL ) tool->username = i_strdup(optarg); break; - case 'P': + case 'P': /* Plugin */ { - const char *plugin; + const char *plugin; plugin = t_strdup(optarg); array_append(&tool->sieve_plugins, &plugin, 1); @@ -211,7 +211,7 @@ static void sieve_tool_load_plugins file = plugins[i]; } - sieve_plugins_load(tool->svinst, path, file); + sieve_plugins_load(tool->svinst, path, file); } } @@ -232,7 +232,7 @@ struct sieve_instance *sieve_tool_init_finish if ( username == NULL ) { sieve_tool_get_user_data(&username, &homedir); - + username = tool->username = i_strdup(username); if ( tool->homedir != NULL ) @@ -242,7 +242,7 @@ struct sieve_instance *sieve_tool_init_finish storage_service_flags |= MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP; - if ( !init_mailstore ) + if ( !init_mailstore ) storage_service_flags |= MAIL_STORAGE_SERVICE_FLAG_NO_NAMESPACES; @@ -254,7 +254,7 @@ struct sieve_instance *sieve_tool_init_finish tool->storage_service = mail_storage_service_init (master_service, NULL, storage_service_flags); if (mail_storage_service_lookup_next - (tool->storage_service, &service_input, &tool->service_user, + (tool->storage_service, &service_input, &tool->service_user, &tool->mail_user_dovecot, &errstr) <= 0) i_fatal("%s", errstr); @@ -304,7 +304,7 @@ void sieve_tool_deinit(struct sieve_tool **_tool) if ( tool->homedir != NULL ) i_free(tool->homedir); - if ( tool->sieve_extensions != NULL ) + if ( tool->sieve_extensions != NULL ) i_free(tool->sieve_extensions); array_free(&tool->sieve_plugins); @@ -315,7 +315,7 @@ void sieve_tool_deinit(struct sieve_tool **_tool) if ( tool->mail_raw_user != NULL ) mail_user_unref(&tool->mail_raw_user); - + /* Free mail service */ if ( tool->mail_user != NULL ) @@ -377,7 +377,7 @@ struct mail *sieve_tool_open_file_as_mail tool->mail_raw = mail_raw_open_file(tool->mail_raw_user, path); - return tool->mail_raw->mail; + return tool->mail_raw->mail; } struct mail *sieve_tool_open_data_as_mail @@ -392,7 +392,7 @@ struct mail *sieve_tool_open_data_as_mail tool->mail_raw = mail_raw_open_data(tool->mail_raw_user, mail_data); - return tool->mail_raw->mail; + return tool->mail_raw->mail; } /* @@ -407,7 +407,7 @@ void sieve_tool_set_homedir(struct sieve_tool *tool, const char *homedir) i_free(tool->homedir); } - + tool->homedir = i_strdup(homedir); if ( tool->mail_user_dovecot != NULL ) @@ -419,7 +419,7 @@ void sieve_tool_set_homedir(struct sieve_tool *tool, const char *homedir) void sieve_tool_set_setting_callback (struct sieve_tool *tool, sieve_tool_setting_callback_t callback, void *context) { - tool->setting_callback = callback; + tool->setting_callback = callback; tool->setting_callback_context = context; } @@ -435,7 +435,7 @@ const char *sieve_tool_get_username if ( tool->username == NULL ) { sieve_tool_get_user_data(&username, NULL); return username; - } + } return tool->username; } @@ -472,21 +472,21 @@ void sieve_tool_get_envelope_data (struct mail *mail, const char **recipient, const char **sender) { /* Get recipient address */ - if ( *recipient == NULL ) + if ( *recipient == NULL ) (void)mail_get_first_header(mail, "Envelope-To", recipient); - if ( *recipient == NULL ) + if ( *recipient == NULL ) (void)mail_get_first_header(mail, "To", recipient); - if ( *recipient == NULL ) + if ( *recipient == NULL ) *recipient = "recipient@example.com"; - + /* Get sender address */ - if ( *sender == NULL ) + if ( *sender == NULL ) (void)mail_get_first_header(mail, "Return-path", sender); - if ( *sender == NULL ) + if ( *sender == NULL ) (void)mail_get_first_header(mail, "Sender", sender); - if ( *sender == NULL ) + if ( *sender == NULL ) (void)mail_get_first_header(mail, "From", sender); - if ( *sender == NULL ) + if ( *sender == NULL ) *sender = "sender@example.com"; } @@ -499,7 +499,7 @@ struct ostream *sieve_tool_open_output_stream(const char *filename) struct ostream *outstream; int fd; - if ( strcmp(filename, "-") == 0 ) + if ( strcmp(filename, "-") == 0 ) outstream = o_stream_create_fd(1, 0, FALSE); else { if ( (fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, 0600)) < 0 ) { @@ -557,7 +557,7 @@ struct sieve_binary *sieve_tool_script_open } void sieve_tool_dump_binary_to -(struct sieve_binary *sbin, const char *filename, bool hexdump) +(struct sieve_binary *sbin, const char *filename, bool hexdump) { struct ostream *dumpstream; @@ -565,7 +565,7 @@ void sieve_tool_dump_binary_to dumpstream = sieve_tool_open_output_stream(filename); if ( dumpstream != NULL ) { - if ( hexdump ) + if ( hexdump ) (void) sieve_hexdump(sbin, dumpstream); else (void) sieve_dump(sbin, dumpstream, FALSE); diff --git a/src/lib-sieve-tool/sieve-tool.h b/src/lib-sieve-tool/sieve-tool.h index 4e31f11cfa85a98037df17ead2b72ef5536bbfcf..254d14ff1f77fbfbf69f55797385b7b12bedd2d9 100644 --- a/src/lib-sieve-tool/sieve-tool.h +++ b/src/lib-sieve-tool/sieve-tool.h @@ -6,7 +6,7 @@ #include "sieve-common.h" -/* +/* * Types */ diff --git a/src/lib-sieve/Makefile.am b/src/lib-sieve/Makefile.am index a7b987da3262cddadd907f3efec2d2ba6c3b7286..e3dc25d28e2f20fe6af395e507ec429d7ca1f969 100644 --- a/src/lib-sieve/Makefile.am +++ b/src/lib-sieve/Makefile.am @@ -114,7 +114,7 @@ libdovecot_sieve_la_SOURCES = \ $(tests) \ $(commands) \ $(extensions) \ - sieve.c + sieve.c headers = \ rfc2822.h \ diff --git a/src/lib-sieve/cmd-discard.c b/src/lib-sieve/cmd-discard.c index b9550da568ade91a1757b4ccdfa0ce889c2f54a3..385bcc8e0e205941a401f43241e8b7f01821c408 100644 --- a/src/lib-sieve/cmd-discard.c +++ b/src/lib-sieve/cmd-discard.c @@ -9,29 +9,29 @@ #include "sieve-code.h" #include "sieve-dump.h" #include "sieve-actions.h" -#include "sieve-validator.h" +#include "sieve-validator.h" #include "sieve-generator.h" #include "sieve-interpreter.h" #include "sieve-result.h" -/* - * Discard command - * +/* + * Discard command + * * Syntax * discard - */ + */ static bool cmd_discard_generate - (const struct sieve_codegen_env *cgenv, - struct sieve_command *ctx ATTR_UNUSED); + (const struct sieve_codegen_env *cgenv, + struct sieve_command *ctx ATTR_UNUSED); -const struct sieve_command_def cmd_discard = { - "discard", - SCT_COMMAND, +const struct sieve_command_def cmd_discard = { + "discard", + SCT_COMMAND, 0, 0, FALSE, FALSE, NULL, NULL, NULL, NULL, - cmd_discard_generate, - NULL + cmd_discard_generate, + NULL }; /* @@ -43,25 +43,25 @@ static bool cmd_discard_operation_dump static int cmd_discard_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def cmd_discard_operation = { +const struct sieve_operation_def cmd_discard_operation = { "DISCARD", NULL, SIEVE_OPERATION_DISCARD, - cmd_discard_operation_dump, - cmd_discard_operation_execute + cmd_discard_operation_dump, + cmd_discard_operation_execute }; -/* +/* * Discard actions */ static void act_discard_print - (const struct sieve_action *action, - const struct sieve_result_print_env *rpenv, bool *keep); + (const struct sieve_action *action, + const struct sieve_result_print_env *rpenv, bool *keep); static bool act_discard_commit - (const struct sieve_action *action, + (const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void *tr_context, bool *keep); - + const struct sieve_action_def act_discard = { "discard", 0, @@ -75,16 +75,16 @@ const struct sieve_action_def act_discard = { /* * Code generation */ - + static bool cmd_discard_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd ATTR_UNUSED) +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd ATTR_UNUSED) { sieve_operation_emit(cgenv->sblock, NULL, &cmd_discard_operation); return TRUE; } -/* +/* * Code dump */ @@ -118,22 +118,22 @@ static int cmd_discard_operation_execute /* * Action implementation */ - + static void act_discard_print -(const struct sieve_action *action ATTR_UNUSED, - const struct sieve_result_print_env *rpenv, bool *keep) +(const struct sieve_action *action ATTR_UNUSED, + const struct sieve_result_print_env *rpenv, bool *keep) { sieve_result_action_printf(rpenv, "discard"); - + *keep = FALSE; } static bool act_discard_commit -(const struct sieve_action *action ATTR_UNUSED, - const struct sieve_action_exec_env *aenv, +(const struct sieve_action *action ATTR_UNUSED, + const struct sieve_action_exec_env *aenv, void *tr_context ATTR_UNUSED, bool *keep) { - sieve_result_global_log(aenv, + sieve_result_global_log(aenv, "marked message to be discarded if not explicitly delivered " "(discard action)"); *keep = FALSE; diff --git a/src/lib-sieve/cmd-if.c b/src/lib-sieve/cmd-if.c index b44439c0e7ce59de425a2a6e388ff3349463e1e3..0a34f9f375b3ebc7e13c52f67316d7b7ead634cb 100644 --- a/src/lib-sieve/cmd-if.c +++ b/src/lib-sieve/cmd-if.c @@ -26,19 +26,19 @@ static bool cmd_else_generate /* If command * - * Syntax: + * Syntax: * if <test1: test> <block1: block> */ -const struct sieve_command_def cmd_if = { - "if", - SCT_COMMAND, +const struct sieve_command_def cmd_if = { + "if", + SCT_COMMAND, 0, 1, TRUE, TRUE, NULL, NULL, cmd_if_validate, cmd_if_validate_const, - cmd_if_generate, - NULL + cmd_if_generate, + NULL }; /* ElsIf command @@ -48,42 +48,42 @@ const struct sieve_command_def cmd_if = { */ const struct sieve_command_def cmd_elsif = { - "elsif", + "elsif", SCT_COMMAND, - 0, 1, TRUE, TRUE, - NULL, NULL, + 0, 1, TRUE, TRUE, + NULL, NULL, cmd_elsif_validate, cmd_if_validate_const, - cmd_if_generate, - NULL + cmd_if_generate, + NULL }; -/* Else command +/* Else command * - * Syntax: + * Syntax: * else <block> */ const struct sieve_command_def cmd_else = { - "else", - SCT_COMMAND, + "else", + SCT_COMMAND, 0, 0, TRUE, TRUE, NULL, NULL, cmd_elsif_validate, cmd_if_validate_const, - cmd_else_generate, - NULL + cmd_else_generate, + NULL }; -/* +/* * Context management */ struct cmd_if_context_data { struct cmd_if_context_data *previous; struct cmd_if_context_data *next; - + int const_condition; bool jump_generated; @@ -91,18 +91,18 @@ struct cmd_if_context_data { }; static void cmd_if_initialize_context_data -(struct sieve_command *cmd, struct cmd_if_context_data *previous) -{ +(struct sieve_command *cmd, struct cmd_if_context_data *previous) +{ struct cmd_if_context_data *cmd_data; /* Assign context */ cmd_data = p_new(sieve_command_pool(cmd), struct cmd_if_context_data, 1); cmd_data->exit_jump = 0; - cmd_data->jump_generated = FALSE; + cmd_data->jump_generated = FALSE; /* Update linked list of contexts */ cmd_data->previous = previous; - cmd_data->next = NULL; + cmd_data->next = NULL; if ( previous != NULL ) previous->next = cmd_data; @@ -115,21 +115,21 @@ static void cmd_if_initialize_context_data } previous = previous->previous; } - + /* Assign to command context */ cmd->data = cmd_data; } -/* - * Validation +/* + * Validation */ static bool cmd_if_validate -(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *cmd) -{ +(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *cmd) +{ /* Start if-command structure */ cmd_if_initialize_context_data(cmd, NULL); - + return TRUE; } @@ -140,16 +140,16 @@ static bool cmd_elsif_validate /* Check valid command placement */ if ( prev == NULL || - ( !sieve_command_is(prev, cmd_if) && !sieve_command_is(prev, cmd_elsif) ) ) - { - sieve_command_validate_error(valdtr, cmd, - "the %s command must follow an if or elseif command", + ( !sieve_command_is(prev, cmd_if) && !sieve_command_is(prev, cmd_elsif) ) ) + { + sieve_command_validate_error(valdtr, cmd, + "the %s command must follow an if or elseif command", sieve_command_identifier(cmd)); return FALSE; } - - /* Previous command in this block is 'if' or 'elsif', so we can safely refer - * to its context data + + /* Previous command in this block is 'if' or 'elsif', so we can safely refer + * to its context data */ cmd_if_initialize_context_data(cmd, prev->data); @@ -160,14 +160,14 @@ static bool cmd_if_validate_const (struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *cmd, int *const_current, int const_next) { - struct cmd_if_context_data *cmd_data = + struct cmd_if_context_data *cmd_data = (struct cmd_if_context_data *) cmd->data; if ( cmd_data != NULL ) { if ( cmd_data->const_condition == 0 ) { *const_current = cmd_data->const_condition; return FALSE; - } + } cmd_data->const_condition = const_next; } @@ -177,27 +177,27 @@ static bool cmd_if_validate_const return ( const_next < 0 ); } -/* - * Code generation +/* + * Code generation */ /* The if command does not generate specific IF-ELSIF-ELSE opcodes, but only uses - * JMP instructions. This is why the implementation of the if command does not + * JMP instructions. This is why the implementation of the if command does not * include an opcode implementation. */ static void cmd_if_resolve_exit_jumps -(struct sieve_binary_block *sblock, struct cmd_if_context_data *cmd_data) +(struct sieve_binary_block *sblock, struct cmd_if_context_data *cmd_data) { struct cmd_if_context_data *if_ctx = cmd_data->previous; - - /* Iterate backwards through all if-command contexts and resolve the + + /* Iterate backwards through all if-command contexts and resolve the * exit jumps to the current code position. */ while ( if_ctx != NULL ) { - if ( if_ctx->jump_generated ) + if ( if_ctx->jump_generated ) sieve_binary_resolve_offset(sblock, if_ctx->exit_jump); - if_ctx = if_ctx->previous; + if_ctx = if_ctx->previous; } } @@ -205,11 +205,11 @@ static bool cmd_if_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) { struct sieve_binary_block *sblock = cgenv->sblock; - struct cmd_if_context_data *cmd_data = + struct cmd_if_context_data *cmd_data = (struct cmd_if_context_data *) cmd->data; struct sieve_ast_node *test; struct sieve_jumplist jmplist; - + /* Generate test condition */ if ( cmd_data->const_condition < 0 ) { /* Prepare jumplist */ @@ -219,10 +219,10 @@ static bool cmd_if_generate if ( !sieve_generate_test(cgenv, test, &jmplist, FALSE) ) return FALSE; } - + /* Case true { */ if ( cmd_data->const_condition != 0 ) { - if ( !sieve_generate_block(cgenv, cmd->ast_node) ) + if ( !sieve_generate_block(cgenv, cmd->ast_node) ) return FALSE; } @@ -232,10 +232,10 @@ static bool cmd_if_generate cmd_if_resolve_exit_jumps(sblock, cmd_data); } else if ( cmd_data->const_condition < 0 ) { - /* No, generate jump to end of if-elsif-else structure (resolved later) - * This of course is not necessary if the {} block contains a command + /* No, generate jump to end of if-elsif-else structure (resolved later) + * This of course is not necessary if the {} block contains a command * like stop at top level that unconditionally exits the block already - * anyway. + * anyway. */ if ( !sieve_command_block_exits_unconditionally(cmd) ) { sieve_operation_emit(sblock, NULL, &sieve_jmp_operation); @@ -244,11 +244,11 @@ static bool cmd_if_generate } } - if ( cmd_data->const_condition < 0 ) { + if ( cmd_data->const_condition < 0 ) { /* Case false ... (subsequent elsif/else commands might generate more) */ - sieve_jumplist_resolve(&jmplist); + sieve_jumplist_resolve(&jmplist); } - + return TRUE; } @@ -257,16 +257,16 @@ static bool cmd_else_generate { struct cmd_if_context_data *cmd_data = (struct cmd_if_context_data *) cmd->data; - + /* Else { */ if ( cmd_data->const_condition != 0 ) { - if ( !sieve_generate_block(cgenv, cmd->ast_node) ) + if ( !sieve_generate_block(cgenv, cmd->ast_node) ) return FALSE; - - /* } End: resolve all exit blocks */ + + /* } End: resolve all exit blocks */ cmd_if_resolve_exit_jumps(cgenv->sblock, cmd_data); } - + return TRUE; } diff --git a/src/lib-sieve/cmd-keep.c b/src/lib-sieve/cmd-keep.c index ee4cff978795111d3e70edf271e53cbbb659e823..61fb240c9aae068a9b45ab98d14b06ef1508205c 100644 --- a/src/lib-sieve/cmd-keep.c +++ b/src/lib-sieve/cmd-keep.c @@ -9,32 +9,32 @@ #include "sieve-dump.h" #include "sieve-message.h" #include "sieve-actions.h" -#include "sieve-validator.h" +#include "sieve-validator.h" #include "sieve-generator.h" #include "sieve-interpreter.h" #include "sieve-result.h" -/* - * Keep command +/* + * Keep command * * Syntax: * keep - */ + */ static bool cmd_keep_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd); -const struct sieve_command_def cmd_keep = { - "keep", - SCT_COMMAND, +const struct sieve_command_def cmd_keep = { + "keep", + SCT_COMMAND, 0, 0, FALSE, FALSE, NULL, NULL, NULL, NULL, - cmd_keep_generate, + cmd_keep_generate, NULL }; -/* - * Keep operation +/* + * Keep operation */ static bool cmd_keep_operation_dump @@ -42,12 +42,12 @@ static bool cmd_keep_operation_dump static int cmd_keep_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def cmd_keep_operation = { +const struct sieve_operation_def cmd_keep_operation = { "KEEP", NULL, SIEVE_OPERATION_KEEP, - cmd_keep_operation_dump, - cmd_keep_operation_execute + cmd_keep_operation_dump, + cmd_keep_operation_execute }; /* @@ -55,7 +55,7 @@ const struct sieve_operation_def cmd_keep_operation = { */ static bool cmd_keep_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) { /* Emit opcode */ sieve_operation_emit(cgenv->sblock, NULL, &cmd_keep_operation); @@ -64,7 +64,7 @@ static bool cmd_keep_generate return sieve_generate_arguments(cgenv, cmd, NULL); } -/* +/* * Code dump */ @@ -92,17 +92,17 @@ static int cmd_keep_operation_execute */ /* Optional operands (side effects only) */ - if ( sieve_action_opr_optional_read(renv, address, NULL, &ret, &slist) != 0 ) + if ( sieve_action_opr_optional_read(renv, address, NULL, &ret, &slist) != 0 ) return ret; /* * Perform operation */ - sieve_runtime_trace(renv, SIEVE_TRLVL_ACTIONS, + sieve_runtime_trace(renv, SIEVE_TRLVL_ACTIONS, "keep action; store message in default mailbox"); - /* Add keep action to result. + /* Add keep action to result. */ if ( sieve_result_add_keep(renv, slist) < 0 ) return SIEVE_EXEC_FAILURE; diff --git a/src/lib-sieve/cmd-redirect.c b/src/lib-sieve/cmd-redirect.c index 0c33f6ddcd97a6ed1d987e7fe5073ad4b51c9cb1..b65fef2956c3f57d984ccac4b2aac2bd4e68896f 100644 --- a/src/lib-sieve/cmd-redirect.c +++ b/src/lib-sieve/cmd-redirect.c @@ -17,7 +17,7 @@ #include "sieve-code.h" #include "sieve-message.h" #include "sieve-actions.h" -#include "sieve-validator.h" +#include "sieve-validator.h" #include "sieve-generator.h" #include "sieve-interpreter.h" #include "sieve-code-dumper.h" @@ -27,15 +27,15 @@ #include <stdio.h> -/* - * Configuration +/* + * Configuration */ #define CMD_REDIRECT_DUPLICATE_KEEP (3600 * 24) -/* - * Redirect command - * +/* + * Redirect command + * * Syntax * redirect <address: string> */ @@ -45,19 +45,19 @@ static bool cmd_redirect_validate static bool cmd_redirect_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd); -const struct sieve_command_def cmd_redirect = { - "redirect", +const struct sieve_command_def cmd_redirect = { + "redirect", SCT_COMMAND, - 1, 0, FALSE, FALSE, + 1, 0, FALSE, FALSE, NULL, NULL, cmd_redirect_validate, NULL, - cmd_redirect_generate, - NULL + cmd_redirect_generate, + NULL }; -/* - * Redirect operation +/* + * Redirect operation */ static bool cmd_redirect_operation_dump @@ -65,37 +65,37 @@ static bool cmd_redirect_operation_dump static int cmd_redirect_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def cmd_redirect_operation = { +const struct sieve_operation_def cmd_redirect_operation = { "REDIRECT", - NULL, + NULL, SIEVE_OPERATION_REDIRECT, - cmd_redirect_operation_dump, - cmd_redirect_operation_execute + cmd_redirect_operation_dump, + cmd_redirect_operation_execute }; -/* - * Redirect action +/* + * Redirect action */ static bool act_redirect_equals - (const struct sieve_script_env *senv, const struct sieve_action *act1, + (const struct sieve_script_env *senv, const struct sieve_action *act1, const struct sieve_action *act2); static int act_redirect_check_duplicate (const struct sieve_runtime_env *renv, - const struct sieve_action *act, + const struct sieve_action *act, const struct sieve_action *act_other); static void act_redirect_print (const struct sieve_action *action, const struct sieve_result_print_env *rpenv, - bool *keep); + bool *keep); static bool act_redirect_commit (const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void *tr_context, bool *keep); - + const struct sieve_action_def act_redirect = { "redirect", SIEVE_ACTFLAG_TRIES_DELIVER, act_redirect_equals, - act_redirect_check_duplicate, + act_redirect_check_duplicate, NULL, act_redirect_print, NULL, NULL, @@ -107,12 +107,12 @@ struct act_redirect_context { const char *to_address; }; -/* - * Validation +/* + * Validation */ static bool cmd_redirect_validate -(struct sieve_validator *validator, struct sieve_command *cmd) +(struct sieve_validator *validator, struct sieve_command *cmd) { struct sieve_instance *svinst = sieve_validator_svinst(validator); struct sieve_ast_argument *arg = cmd->first_positional; @@ -166,9 +166,9 @@ static bool cmd_redirect_validate /* * Code generation */ - + static bool cmd_redirect_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) { sieve_operation_emit(cgenv->sblock, NULL, &cmd_redirect_operation); @@ -176,10 +176,10 @@ static bool cmd_redirect_generate return sieve_generate_arguments(cgenv, cmd, NULL); } -/* +/* * Code dump */ - + static bool cmd_redirect_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) { @@ -213,7 +213,7 @@ static int cmd_redirect_operation_execute */ /* Optional operands (side effects only) */ - if ( sieve_action_opr_optional_read(renv, address, NULL, &ret, &slist) != 0 ) + if ( sieve_action_opr_optional_read(renv, address, NULL, &ret, &slist) != 0 ) return ret; /* Read the address */ @@ -273,45 +273,45 @@ static int cmd_redirect_operation_execute */ static bool act_redirect_equals -(const struct sieve_script_env *senv ATTR_UNUSED, +(const struct sieve_script_env *senv ATTR_UNUSED, const struct sieve_action *act1, const struct sieve_action *act2) { struct act_redirect_context *rd_ctx1 = (struct act_redirect_context *) act1->context; - struct act_redirect_context *rd_ctx2 = + struct act_redirect_context *rd_ctx2 = (struct act_redirect_context *) act2->context; /* Address is already normalized */ return ( sieve_address_compare (rd_ctx1->to_address, rd_ctx2->to_address, TRUE) == 0 ); } - + static int act_redirect_check_duplicate (const struct sieve_runtime_env *renv ATTR_UNUSED, - const struct sieve_action *act, + const struct sieve_action *act, const struct sieve_action *act_other) { return ( act_redirect_equals(renv->scriptenv, act, act_other) ? 1 : 0 ); } static void act_redirect_print -(const struct sieve_action *action, - const struct sieve_result_print_env *rpenv, bool *keep) +(const struct sieve_action *action, + const struct sieve_result_print_env *rpenv, bool *keep) { - struct act_redirect_context *ctx = + struct act_redirect_context *ctx = (struct act_redirect_context *) action->context; - - sieve_result_action_printf(rpenv, "redirect message to: %s", + + sieve_result_action_printf(rpenv, "redirect message to: %s", str_sanitize(ctx->to_address, 128)); - + *keep = FALSE; } -static bool act_redirect_send +static bool act_redirect_send (const struct sieve_action_exec_env *aenv, struct mail *mail, struct act_redirect_context *ctx) { - static const char *hide_headers[] = + static const char *hide_headers[] = { "Return-Path", "X-Sieve", "X-Sieve-Redirected-From" }; struct sieve_message_context *msgctx = aenv->msgctx; @@ -323,17 +323,17 @@ static bool act_redirect_send FILE *f; const unsigned char *data; size_t size; - + /* Just to be sure */ if ( !sieve_smtp_available(senv) ) { sieve_result_global_warning (aenv, "redirect action has no means to send mail."); return TRUE; } - + if (mail_get_stream(mail, NULL, NULL, &input) < 0) return FALSE; - + /* Open SMTP transport */ smtp_handle = sieve_smtp_open(senv, ctx->to_address, sender, &f); @@ -341,7 +341,7 @@ static bool act_redirect_send input = i_stream_create_header_filter (input, HEADER_FILTER_EXCLUDE, hide_headers, N_ELEMENTS(hide_headers), null_header_filter_callback, NULL); - + /* Make sure the message contains CRLF consistently */ crlf_input = i_stream_create_crlf(input); @@ -351,7 +351,7 @@ static bool act_redirect_send rfc2822_header_field_write(f, "X-Sieve-Redirected-From", recipient); /* Pipe the message to the outgoing SMTP transport */ - while (i_stream_read_data(crlf_input, &data, &size, 0) > 0) { + while (i_stream_read_data(crlf_input, &data, &size, 0) > 0) { if (fwrite(data, size, 1, f) == 0) break; i_stream_skip(crlf_input, size); @@ -364,18 +364,18 @@ static bool act_redirect_send /* Close SMTP transport */ if ( !sieve_smtp_close(senv, smtp_handle) ) { - sieve_result_global_error(aenv, + sieve_result_global_error(aenv, "failed to redirect message to <%s> " "(refer to server log for more information)", str_sanitize(ctx->to_address, 80)); return FALSE; } - + return TRUE; } static bool act_redirect_commit -(const struct sieve_action *action, +(const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void *tr_context ATTR_UNUSED, bool *keep) { @@ -388,7 +388,7 @@ static bool act_redirect_commit const char *dupeid; /* Prevent mail loops if possible */ - dupeid = msgdata->id == NULL ? + dupeid = msgdata->id == NULL ? NULL : t_strdup_printf("%s-%s", msgdata->id, ctx->to_address); if (dupeid != NULL) { /* Check whether we've seen this message before */ @@ -408,8 +408,8 @@ static bool act_redirect_commit ioloop_time + CMD_REDIRECT_DUPLICATE_KEEP); } - sieve_result_global_log(aenv, "forwarded to <%s>", - str_sanitize(ctx->to_address, 128)); + sieve_result_global_log(aenv, "forwarded to <%s>", + str_sanitize(ctx->to_address, 128)); /* Indicate that message was successfully forwarded */ aenv->exec_status->message_forwarded = TRUE; @@ -419,7 +419,7 @@ static bool act_redirect_commit return TRUE; } - + return FALSE; } diff --git a/src/lib-sieve/cmd-require.c b/src/lib-sieve/cmd-require.c index 50365a12a277cfcbae8405ba94d230f105cd0daf..5d45f4d8329445f83cb432baf65e5d1671e8f4a5 100644 --- a/src/lib-sieve/cmd-require.c +++ b/src/lib-sieve/cmd-require.c @@ -6,80 +6,80 @@ #include "sieve-common.h" #include "sieve-commands.h" #include "sieve-extensions.h" -#include "sieve-validator.h" +#include "sieve-validator.h" #include "sieve-generator.h" -/* +/* * Require command * - * Syntax + * Syntax * Syntax: require <capabilities: string-list> */ static bool cmd_require_validate (struct sieve_validator *valdtr, struct sieve_command *cmd); -const struct sieve_command_def cmd_require = { - "require", - SCT_COMMAND, +const struct sieve_command_def cmd_require = { + "require", + SCT_COMMAND, 1, 0, FALSE, FALSE, - NULL, NULL, - cmd_require_validate, + NULL, NULL, + cmd_require_validate, NULL, NULL, NULL }; - -/* - * Validation + +/* + * Validation */ static bool cmd_require_validate -(struct sieve_validator *valdtr, struct sieve_command *cmd) +(struct sieve_validator *valdtr, struct sieve_command *cmd) { bool result = TRUE; struct sieve_ast_argument *arg; struct sieve_command *prev = sieve_command_prev(cmd); - + /* Check valid command placement */ if ( !sieve_command_is_toplevel(cmd) || ( !sieve_command_is_first(cmd) && prev != NULL && - !sieve_command_is(prev, cmd_require) ) ) - { - sieve_command_validate_error(valdtr, cmd, + !sieve_command_is(prev, cmd_require) ) ) + { + sieve_command_validate_error(valdtr, cmd, "require commands can only be placed at top level " "at the beginning of the file"); return FALSE; } - + /* Check argument and load specified extension(s) */ arg = cmd->first_positional; if ( sieve_ast_argument_type(arg) == SAAT_STRING ) { /* Single string */ const struct sieve_extension *ext = sieve_validator_extension_load_by_name - (valdtr, cmd, arg, sieve_ast_argument_strc(arg)); + (valdtr, cmd, arg, sieve_ast_argument_strc(arg)); if ( ext == NULL ) result = FALSE; - + } else if ( sieve_ast_argument_type(arg) == SAAT_STRING_LIST ) { /* String list */ struct sieve_ast_argument *stritem = sieve_ast_strlist_first(arg); - + while ( stritem != NULL ) { const struct sieve_extension *ext = sieve_validator_extension_load_by_name (valdtr, cmd, stritem, sieve_ast_strlist_strc(stritem)); if ( ext == NULL ) result = FALSE; - + stritem = sieve_ast_strlist_next(stritem); } } else { /* Something else */ - sieve_argument_validate_error(valdtr, arg, + sieve_argument_validate_error(valdtr, arg, "the require command accepts a single string or string list argument, " - "but %s was found", + "but %s was found", sieve_ast_argument_name(arg)); return FALSE; } - + return result; } diff --git a/src/lib-sieve/cmd-stop.c b/src/lib-sieve/cmd-stop.c index e1d86af5592504d4aec549e08b8e7824662d6396..27866df0a4aa002f7dcbfc7ec428d07bf6621bd0 100644 --- a/src/lib-sieve/cmd-stop.c +++ b/src/lib-sieve/cmd-stop.c @@ -7,54 +7,54 @@ #include "sieve-generator.h" #include "sieve-interpreter.h" -/* - * Stop command - * +/* + * Stop command + * * Syntax * stop - */ + */ static bool cmd_stop_generate - (const struct sieve_codegen_env *cgenv, + (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx ATTR_UNUSED); static bool cmd_stop_validate (struct sieve_validator *valdtr, struct sieve_command *cmd); - -const struct sieve_command_def cmd_stop = { - "stop", - SCT_COMMAND, + +const struct sieve_command_def cmd_stop = { + "stop", + SCT_COMMAND, 0, 0, FALSE, FALSE, - NULL, NULL, + NULL, NULL, cmd_stop_validate, - NULL, - cmd_stop_generate, - NULL + NULL, + cmd_stop_generate, + NULL }; -/* +/* * Stop operation */ static int opc_stop_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def cmd_stop_operation = { +const struct sieve_operation_def cmd_stop_operation = { "STOP", NULL, SIEVE_OPERATION_STOP, - NULL, - opc_stop_execute + NULL, + opc_stop_execute }; /* * Command validation */ - + static bool cmd_stop_validate (struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *cmd) { sieve_command_exit_block_unconditionally(cmd); - + return TRUE; } @@ -63,8 +63,8 @@ static bool cmd_stop_validate */ static bool cmd_stop_generate -(const struct sieve_codegen_env *cgenv, - struct sieve_command *cmd ATTR_UNUSED) +(const struct sieve_codegen_env *cgenv, + struct sieve_command *cmd ATTR_UNUSED) { sieve_operation_emit(cgenv->sblock, NULL, &cmd_stop_operation); @@ -77,10 +77,10 @@ static bool cmd_stop_generate static int opc_stop_execute (const struct sieve_runtime_env *renv, sieve_size_t *address ATTR_UNUSED) -{ - sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, +{ + sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, "stop command; end all script execution"); - + sieve_interpreter_interrupt(renv->interp); return SIEVE_EXEC_OK; diff --git a/src/lib-sieve/cmp-i-ascii-casemap.c b/src/lib-sieve/cmp-i-ascii-casemap.c index ca16ea6462f9f42df6ac408c546a2971b7ffd2fa..effdda884350a014fce08607b38e0858bb1fd9dd 100644 --- a/src/lib-sieve/cmp-i-ascii-casemap.c +++ b/src/lib-sieve/cmp-i-ascii-casemap.c @@ -1,7 +1,7 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ -/* Comparator 'i;ascii-casemap': +/* Comparator 'i;ascii-casemap': * */ @@ -17,18 +17,18 @@ /* * Forward declarations */ - + static int cmp_i_ascii_casemap_compare (const struct sieve_comparator *cmp, const char *val1, size_t val1_size, const char *val2, size_t val2_size); static bool cmp_i_ascii_casemap_char_match - (const struct sieve_comparator *cmp, const char **val1, const char *val1_end, + (const struct sieve_comparator *cmp, const char **val1, const char *val1_end, const char **val2, const char *val2_end); /* * Comparator object */ - + const struct sieve_comparator_def i_ascii_casemap_comparator = { SIEVE_OBJECT ("i;ascii-casemap", &comparator_operand, SIEVE_COMPARATOR_I_ASCII_CASEMAP), @@ -51,45 +51,45 @@ static int cmp_i_ascii_casemap_compare( if ( val1_size == val2_size ) { return strncasecmp(val1, val2, val1_size); - } - + } + if ( val1_size > val2_size ) { result = strncasecmp(val1, val2, val2_size); - + if ( result == 0 ) return 1; - + return result; - } + } result = strncasecmp(val1, val2, val1_size); - + if ( result == 0 ) return -1; - + return result; } static bool cmp_i_ascii_casemap_char_match - (const struct sieve_comparator *cmp ATTR_UNUSED, - const char **val, const char *val_end, + (const struct sieve_comparator *cmp ATTR_UNUSED, + const char **val, const char *val_end, const char **key, const char *key_end) { const char *val_begin = *val; const char *key_begin = *key; - + while ( i_tolower(**val) == i_tolower(**key) && *val < val_end && *key < key_end ) { (*val)++; (*key)++; } - + if ( *key < key_end ) { /* Reset */ *val = val_begin; - *key = key_begin; - + *key = key_begin; + return FALSE; } - + return TRUE; } diff --git a/src/lib-sieve/cmp-i-octet.c b/src/lib-sieve/cmp-i-octet.c index 53099efe564bf54aa5c4ed2c929ae66f7e2d7066..70586221208486b9d67ac00be81d15408dee1346 100644 --- a/src/lib-sieve/cmp-i-octet.c +++ b/src/lib-sieve/cmp-i-octet.c @@ -1,7 +1,7 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ -/* Comparator 'i;octet': +/* Comparator 'i;octet': * */ @@ -21,7 +21,7 @@ static int cmp_i_octet_compare (const struct sieve_comparator *cmp, const char *val1, size_t val1_size, const char *val2, size_t val2_size); static bool cmp_i_octet_char_match - (const struct sieve_comparator *cmp, const char **val1, const char *val1_end, + (const struct sieve_comparator *cmp, const char **val1, const char *val1_end, const char **val2, const char *val2_end); /* @@ -34,13 +34,13 @@ const struct sieve_comparator_def i_octet_comparator = { SIEVE_COMPARATOR_FLAG_SUBSTRING_MATCH | SIEVE_COMPARATOR_FLAG_PREFIX_MATCH, cmp_i_octet_compare, cmp_i_octet_char_match, - sieve_comparator_octet_skip + sieve_comparator_octet_skip }; /* * Comparator implementation */ - + static int cmp_i_octet_compare( const struct sieve_comparator *cmp ATTR_UNUSED, const char *val1, size_t val1_size, const char *val2, size_t val2_size) @@ -49,45 +49,45 @@ static int cmp_i_octet_compare( if ( val1_size == val2_size ) { return memcmp((void *) val1, (void *) val2, val1_size); - } - + } + if ( val1_size > val2_size ) { result = memcmp((void *) val1, (void *) val2, val2_size); - + if ( result == 0 ) return 1; - + return result; - } + } result = memcmp((void *) val1, (void *) val2, val1_size); - + if ( result == 0 ) return -1; - + return result; } static bool cmp_i_octet_char_match - (const struct sieve_comparator *cmp ATTR_UNUSED, - const char **val, const char *val_end, + (const struct sieve_comparator *cmp ATTR_UNUSED, + const char **val, const char *val_end, const char **key, const char *key_end) { const char *val_begin = *val; const char *key_begin = *key; - + while ( **val == **key && *val < val_end && *key < key_end ) { (*val)++; (*key)++; } - + if ( *key < key_end ) { /* Reset */ *val = val_begin; - *key = key_begin; - + *key = key_begin; + return FALSE; } - + return TRUE; } - - + + diff --git a/src/lib-sieve/edit-mail.c b/src/lib-sieve/edit-mail.c index 8f6adf5b4da1270883154dbfda80f69537a832cc..e14583a7eb724482ddafff63e6debb3c87359009 100644 --- a/src/lib-sieve/edit-mail.c +++ b/src/lib-sieve/edit-mail.c @@ -142,7 +142,7 @@ static inline struct _header_field *_header_field_create(struct _header *header) struct _header_field *hfield; hfield = i_new(struct _header_field, 1); - hfield->refcount = 1; + hfield->refcount = 1; hfield->header = header; if ( header != NULL ) _header_ref(header); @@ -221,7 +221,7 @@ struct edit_mail *edit_mail_wrap(struct mail *mail) /* Create dummy raw mailbox for our wrapper */ raw_mail_user = edit_mail_raw_storage_get(mail->box->storage->user); - + if ( raw_mailbox_alloc_stream(raw_mail_user, wrapped_stream, (time_t)-1, "editor@example.com", &raw_box) < 0 ) { i_error("edit-mail: failed to open raw box: %s", @@ -285,7 +285,7 @@ struct edit_mail *edit_mail_snapshot(struct edit_mail *edmail) edmail_new->wrapped_body_size = edmail->wrapped_body_size; edmail_new->hdr_size = edmail->hdr_size; edmail_new->body_size = edmail->body_size; - edmail_new->appended_hdr_size = edmail->appended_hdr_size; + edmail_new->appended_hdr_size = edmail->appended_hdr_size; edmail_new->wrapped_stream = edmail->wrapped_stream; i_stream_ref(edmail_new->wrapped_stream); @@ -328,12 +328,12 @@ struct edit_mail *edit_mail_snapshot(struct edit_mail *edmail) if ( field_idx == edmail->header_fields_appended ) edmail_new->header_fields_appended = field_idx_new; - + field_idx = next; } edmail_new->modified = TRUE; - } + } edmail_new->headers_parsed = edmail->headers_parsed; @@ -359,7 +359,7 @@ void edit_mail_reset(struct edit_mail *edmail) _header_field_unref(field_idx->field); i_free(field_idx); - + field_idx = next; } @@ -501,7 +501,7 @@ static void edit_mail_header_field_delete i_free(header_idx); } else if ( header_idx->first == field_idx ) { struct _header_field_index *hfield = header_idx->first->next; - + while ( hfield != NULL && hfield->header != header_idx ) { hfield = hfield->next; } @@ -510,7 +510,7 @@ static void edit_mail_header_field_delete header_idx->first = hfield; } else if ( header_idx->last == field_idx ) { struct _header_field_index *hfield = header_idx->last->prev; - + while ( hfield != NULL && hfield->header != header_idx ) { hfield = hfield->prev; } @@ -563,7 +563,7 @@ static int edit_mail_headers_parse T_BEGIN { hdr_data = t_str_new(1024); - while ( (ret=message_parse_header_next(hparser, &hdr)) > 0 ) { + while ( (ret=message_parse_header_next(hparser, &hdr)) > 0 ) { struct _header_field_index *field_idx_new; struct _header_field *field; @@ -573,7 +573,7 @@ static int edit_mail_headers_parse } if ( hdr == NULL || hdr->eoh ) break; - + /* We deny the existence of any `Content-Length:' header. This header is * non-standard and it can wreak havok when the message is modified. */ @@ -649,7 +649,7 @@ static int edit_mail_headers_parse _header_field_unref(current->field); i_free(current); - + current = next; } @@ -758,7 +758,7 @@ void edit_mail_header_add /* Create header field data (folded if necessary) */ T_BEGIN { string_t *enc_value, *data; - + enc_value = t_str_new(strlen(field_name) + strlen(value) + 64); data = t_str_new(strlen(field_name) + strlen(value) + 128); @@ -772,7 +772,7 @@ void edit_mail_header_add field->size = str_len(data); field->virtual_size = ( edmail->crlf ? field->size : field->size + lines ); field->lines = lines; - } T_END; + } T_END; /* Record original (utf8) value */ field->utf8_value = _header_value_unfold(value); @@ -838,7 +838,7 @@ int edit_mail_header_delete while ( field_idx != NULL ) { struct _header_field_index *next = ( index >= 0 ? field_idx->next : field_idx->prev ); - + if ( field_idx->field->header == header_idx->header ) { bool final; @@ -876,10 +876,10 @@ int edit_mail_header_delete if ( header_idx->first == NULL ) header_idx->first = current; header_idx->last = current; - } + } current = current->next; } - } + } return ret; } @@ -939,15 +939,15 @@ void edit_mail_headers_iterate_deinit *edhiter = NULL; } -static inline string_t *_header_right_trim(const char *raw) +static inline string_t *_header_right_trim(const char *raw) { string_t *result; int i; - + for ( i = strlen(raw)-1; i >= 0; i-- ) { if ( raw[i] != ' ' && raw[i] != '\t' ) break; } - + result = t_str_new(i+1); str_append_n(result, raw, i + 1); return result; @@ -973,7 +973,7 @@ bool edit_mail_headers_iterate_next (struct edit_mail_header_iter *edhiter) { do { - edhiter->current = + edhiter->current = ( !edhiter->reverse ? edhiter->current->next : edhiter->current->next ); } while ( edhiter->current != NULL && edhiter->current->header != NULL && edhiter->header != NULL && edhiter->current->header != edhiter->header ); @@ -1024,7 +1024,7 @@ static void edit_mail_free(struct mail *mail) } static void edit_mail_set_seq -(struct mail *mail ATTR_UNUSED, uint32_t seq ATTR_UNUSED, +(struct mail *mail ATTR_UNUSED, uint32_t seq ATTR_UNUSED, bool saving ATTR_UNUSED) { i_panic("edit_mail_set_seq() not implemented"); @@ -1122,7 +1122,7 @@ static int edit_mail_get_virtual_size(struct mail *mail, uoff_t *size_r) } else { *size_r = edmail->wrapped_body_size.virtual_size + 2; } - + *size_r += edmail->hdr_size.virtual_size + edmail->body_size.virtual_size; return 0; } @@ -1142,7 +1142,7 @@ static int edit_mail_get_physical_size(struct mail *mail, uoff_t *size_r) *size_r = edmail->wrapped_body_size.physical_size + ( edmail->eoh_crlf ? 2 : 1 ); } - + *size_r += edmail->hdr_size.physical_size + edmail->body_size.physical_size; return 0; } @@ -1168,7 +1168,7 @@ static int edit_mail_get_first_header header_idx->count == 0 ) { if ( !edmail->headers_parsed ) { - /* No new header */ + /* No new header */ return edmail->wrapped->v.get_first_header (&edmail->wrapped->mail, field_name, decode_to_utf8, value_r); } @@ -1202,7 +1202,7 @@ static int edit_mail_get_first_header if ( (ret=edmail->wrapped->v.get_first_header (&edmail->wrapped->mail, field_name, decode_to_utf8, value_r)) != 0 ) return ret; - + /* Use first (apparently appended) header */ field = header_idx->first->field; } else { @@ -1267,7 +1267,7 @@ static int edit_mail_get_headers if ( field_idx == edmail->header_fields_appended && headers != NULL ) { while ( *headers != NULL ) { array_append(&header_values, headers, 1); - + headers++; } } @@ -1295,7 +1295,7 @@ static int edit_mail_get_headers if ( headers != NULL ) { while ( *headers != NULL ) { array_append(&header_values, headers, 1); - + headers++; } } @@ -1323,14 +1323,14 @@ static int edit_mail_get_stream if ( edmail->stream == NULL ) { edmail->stream = edit_mail_istream_create(edmail); } - + if ( hdr_size != NULL ) { *hdr_size = edmail->wrapped_hdr_size; hdr_size->physical_size += edmail->hdr_size.physical_size; hdr_size->virtual_size += edmail->hdr_size.virtual_size; hdr_size->lines += edmail->hdr_size.lines; } - + if ( body_size != NULL ) { *body_size = edmail->wrapped_body_size; } @@ -1528,20 +1528,20 @@ static ssize_t edit_mail_istream_read(struct istream_private *stream) if ( !edmail->headers_parsed && edmail->header_fields_appended != NULL ) { /* Output headers from original stream */ - /* At what offset does the header end (not including LF of final empty line) + /* At what offset does the header end (not including LF of final empty line) * Any final CR is dealt with later */ hdr_size = edmail->wrapped_hdr_size.physical_size + edmail->hdr_size.physical_size - - edmail->appended_hdr_size.physical_size - 1; + edmail->appended_hdr_size.physical_size - 1; if ( v_offset < hdr_size ) { - parent_v_offset = stream->parent_start_offset + + parent_v_offset = stream->parent_start_offset + (v_offset + edmail->appended_hdr_size.physical_size - edmail->hdr_size.physical_size); i_stream_seek(stream->parent, parent_v_offset); - + if ( (ret=i_stream_read_copy_from_parent(&stream->istream)) < 0 ) return ret; @@ -1648,7 +1648,7 @@ static void edit_mail_istream_seek if ( v_offset < offset ) { stream_reset_to(edstream, v_offset); - /* Find the header */ + /* Find the header */ cur_header = edmail->header_fields_head; i_assert( cur_header != NULL && cur_header != edmail->header_fields_appended ); @@ -1683,7 +1683,7 @@ static void edit_mail_istream_seek stream_reset_to(edstream, v_offset); offset -= edmail->appended_hdr_size.physical_size; - + cur_header = edmail->header_fields_appended; i_assert( cur_header != NULL ); offset += cur_header->field->size; diff --git a/src/lib-sieve/ext-encoded-character.c b/src/lib-sieve/ext-encoded-character.c index 5f412c353536f92bb0e14c1bad77fde0150e0c7e..8d51e121f16114d726fc9c68f277623c9a0a0930 100644 --- a/src/lib-sieve/ext-encoded-character.c +++ b/src/lib-sieve/ext-encoded-character.c @@ -20,19 +20,19 @@ #include <ctype.h> -/* +/* * Extension */ static bool ext_encoded_character_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr); - -struct sieve_extension_def encoded_character_extension = { - "encoded-character", + +struct sieve_extension_def encoded_character_extension = { + "encoded-character", NULL, NULL, - ext_encoded_character_validator_load, + ext_encoded_character_validator_load, NULL, NULL, NULL, NULL, NULL, - SIEVE_EXT_DEFINE_NO_OPERATIONS, + SIEVE_EXT_DEFINE_NO_OPERATIONS, SIEVE_EXT_DEFINE_NO_OPERANDS }; @@ -41,13 +41,13 @@ struct sieve_extension_def encoded_character_extension = { */ bool arg_encoded_string_validate - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *context); -const struct sieve_argument_def encoded_string_argument = { - "@encoded-string", - NULL, - arg_encoded_string_validate, +const struct sieve_argument_def encoded_string_argument = { + "@encoded-string", + NULL, + arg_encoded_string_validate, NULL, NULL, NULL }; @@ -63,14 +63,14 @@ static bool _skip_whitespace return FALSE; continue; } - + /* (Loose LF is non-standard) */ - if ( **in != ' ' && **in != '\n' && **in != '\t' ) + if ( **in != ' ' && **in != '\n' && **in != '\t' ) break; - + (*in)++; } - + return TRUE; } @@ -79,10 +79,10 @@ static bool _parse_hexint { int digit = 0; *result = 0; - + while ( *in < inend && (max_digits == 0 || digit < max_digits) ) { - - if ( (**in) >= '0' && (**in) <= '9' ) + + if ( (**in) >= '0' && (**in) <= '9' ) *result = ((*result) << 4) + (**in) - ((unsigned int) '0'); else if ( (**in) >= 'a' && (**in) <= 'f' ) *result = ((*result) << 4) + (**in) - ((unsigned int) 'a') + 0x0a; @@ -90,74 +90,74 @@ static bool _parse_hexint *result = ((*result) << 4) + (**in) - ((unsigned int) 'A') + 0x0a; else return ( digit > 0 ); - + (*in)++; digit++; } - + if ( digit == max_digits ) { /* Hex digit _MUST_ end here */ if ( (**in >= '0' && **in <= '9') || (**in >= 'a' && **in <= 'f') || (**in >= 'A' && **in <= 'F') ) return FALSE; - + return TRUE; } - + return ( digit > 0 ); } static bool _decode_hex -(const char **in, const char *inend, string_t *result) +(const char **in, const char *inend, string_t *result) { int values = 0; - + while ( *in < inend ) { unsigned int hexpair; - + if ( !_skip_whitespace(in, inend) ) return FALSE; - + if ( !_parse_hexint(in, inend, 2, &hexpair) ) break; - + str_append_c(result, (unsigned char) hexpair); values++; } - + return ( values > 0 ); } static int _decode_unicode -(const char **in, const char *inend, string_t *result, unsigned int *error_hex) +(const char **in, const char *inend, string_t *result, unsigned int *error_hex) { int values = 0; bool valid = TRUE; - + while ( *in < inend ) { unsigned int unicode_hex; - + if ( !_skip_whitespace(in, inend) ) return FALSE; - + if ( !_parse_hexint(in, inend, 0, &unicode_hex) ) break; - if ( (unicode_hex <= 0xD7FF) || - (unicode_hex >= 0xE000 && unicode_hex <= 0x10FFFF) ) + if ( (unicode_hex <= 0xD7FF) || + (unicode_hex >= 0xE000 && unicode_hex <= 0x10FFFF) ) uni_ucs4_to_utf8_c((unichar_t) unicode_hex, result); else { if ( valid ) *error_hex = unicode_hex; valid = FALSE; - } + } values++; } - + return ( values > 0 ); } bool arg_encoded_string_validate -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd) { bool result = TRUE; - enum { ST_NONE, ST_OPEN, ST_TYPE, ST_CLOSE } + enum { ST_NONE, ST_OPEN, ST_TYPE, ST_CLOSE } state = ST_NONE; string_t *str = sieve_ast_argument_str(*arg); string_t *tmpstr, *newstr = NULL; @@ -166,9 +166,9 @@ bool arg_encoded_string_validate const char *strend = strval + str_len(str); unsigned int error_hex = 0; - T_BEGIN { - tmpstr = t_str_new(32); - + T_BEGIN { + tmpstr = t_str_new(32); + p = strval; strstart = p; while ( result && p < strend ) { @@ -186,7 +186,7 @@ bool arg_encoded_string_validate if ( *p == '{' ) { state = ST_TYPE; p++; - } else + } else state = ST_NONE; break; /* Parsed '${' */ @@ -194,14 +194,14 @@ bool arg_encoded_string_validate mark = p; /* Scan for 'hex' or 'unicode' */ while ( p < strend && i_isalpha(*p) ) p++; - + if ( *p != ':' ) { state = ST_NONE; break; } - + state = ST_CLOSE; - + str_truncate(tmpstr, 0); if ( strncasecmp(mark, "hex", p - mark) == 0 ) { /* Hexadecimal */ @@ -213,56 +213,56 @@ bool arg_encoded_string_validate p++; if ( !_decode_unicode(&p, strend, tmpstr, &error_hex) ) state = ST_NONE; - } else { + } else { /* Invalid encoding */ p++; state = ST_NONE; } break; case ST_CLOSE: - if ( *p == '}' ) { - /* We now know that the substitution is valid */ + if ( *p == '}' ) { + /* We now know that the substitution is valid */ if ( error_hex != 0 ) { - sieve_argument_validate_error(valdtr, *arg, + sieve_argument_validate_error(valdtr, *arg, "invalid unicode character 0x%08x in encoded character substitution", error_hex); result = FALSE; break; } - + if ( newstr == NULL ) { newstr = str_new(sieve_ast_pool((*arg)->ast), str_len(str)*2); } - + str_append_n(newstr, strstart, substart-strstart); str_append_str(newstr, tmpstr); - + strstart = p + 1; substart = strstart; - - p++; - } + + p++; + } state = ST_NONE; } } } T_END; if ( !result ) return FALSE; - + if ( newstr != NULL ) { if ( strstart != strend ) - str_append_n(newstr, strstart, strend-strstart); - + str_append_n(newstr, strstart, strend-strstart); + sieve_ast_argument_string_set(*arg, newstr); } - + /* Pass the processed string to a (possible) next layer of processing */ return sieve_validator_argument_activate_super (valdtr, cmd, *arg, TRUE); } -/* +/* * Extension implementation */ @@ -271,7 +271,7 @@ static bool ext_encoded_character_validator_load { /* Override the constant string argument with our own */ sieve_validator_argument_override - (valdtr, SAT_CONST_STRING, ext, &encoded_string_argument); - + (valdtr, SAT_CONST_STRING, ext, &encoded_string_argument); + return TRUE; } diff --git a/src/lib-sieve/ext-envelope.c b/src/lib-sieve/ext-envelope.c index 0ae0ea2536a1d2189746df16ba4a810e9cde58c3..51cf04e3c6a25e47270fdb796f8f921fdc7c0d7b 100644 --- a/src/lib-sieve/ext-envelope.c +++ b/src/lib-sieve/ext-envelope.c @@ -40,20 +40,20 @@ static const struct sieve_command_def envelope_test; const struct sieve_operation_def envelope_operation; const struct sieve_extension_def envelope_extension; -/* - * Extension +/* + * Extension */ static bool ext_envelope_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr); -const struct sieve_extension_def envelope_extension = { - "envelope", +const struct sieve_extension_def envelope_extension = { + "envelope", NULL, NULL, - ext_envelope_validator_load, + ext_envelope_validator_load, NULL, NULL, NULL, NULL, NULL, - SIEVE_EXT_DEFINE_OPERATION(envelope_operation), - SIEVE_EXT_DEFINE_NO_OPERANDS + SIEVE_EXT_DEFINE_OPERATION(envelope_operation), + SIEVE_EXT_DEFINE_NO_OPERANDS }; static bool ext_envelope_validator_load @@ -65,12 +65,12 @@ static bool ext_envelope_validator_load return TRUE; } -/* - * Envelope test +/* + * Envelope test * * Syntax * envelope [COMPARATOR] [ADDRESS-PART] [MATCH-TYPE] - * <envelope-part: string-list> <key-list: string-list> + * <envelope-part: string-list> <key-list: string-list> */ static bool tst_envelope_registered @@ -81,20 +81,20 @@ static bool tst_envelope_validate static bool tst_envelope_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx); -static const struct sieve_command_def envelope_test = { - "envelope", - SCT_TEST, +static const struct sieve_command_def envelope_test = { + "envelope", + SCT_TEST, 2, 0, FALSE, FALSE, - tst_envelope_registered, + tst_envelope_registered, NULL, tst_envelope_validate, - NULL, - tst_envelope_generate, - NULL + NULL, + tst_envelope_generate, + NULL }; -/* - * Envelope operation +/* + * Envelope operation */ static bool ext_envelope_operation_dump @@ -102,12 +102,12 @@ static bool ext_envelope_operation_dump static int ext_envelope_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def envelope_operation = { +const struct sieve_operation_def envelope_operation = { "ENVELOPE", &envelope_extension, 0, - ext_envelope_operation_dump, - ext_envelope_operation_execute + ext_envelope_operation_dump, + ext_envelope_operation_execute }; /* @@ -146,17 +146,17 @@ static const struct sieve_envelope_part _to_part = { "to", _to_part_get_addresses, _to_part_get_values, -}; +}; static const struct sieve_envelope_part _auth_part = { "auth", NULL, _auth_part_get_values, -}; +}; static const struct sieve_envelope_part *_envelope_parts[] = { /* Required */ - &_from_part, &_to_part, + &_from_part, &_to_part, /* Non-standard */ &_auth_part @@ -174,7 +174,7 @@ static const struct sieve_envelope_part *_envelope_part_find return _envelope_parts[i]; } } - + return NULL; } @@ -186,7 +186,7 @@ static const struct sieve_address *const *_from_part_get_addresses ARRAY_DEFINE(envelope_values, const struct sieve_address *); const struct sieve_address *address = sieve_message_get_sender_address(renv->msgctx); - + if ( address != NULL ) { t_array_init(&envelope_values, 2); @@ -194,7 +194,7 @@ static const struct sieve_address *const *_from_part_get_addresses (void)array_append_space(&envelope_values); return array_idx(&envelope_values, 0); - } + } return NULL; } @@ -219,8 +219,8 @@ static const struct sieve_address *const *_to_part_get_addresses (const struct sieve_runtime_env *renv) { ARRAY_DEFINE(envelope_values, const struct sieve_address *); - const struct sieve_address *address = - sieve_message_get_orig_recipient_address(renv->msgctx); + const struct sieve_address *address = + sieve_message_get_orig_recipient_address(renv->msgctx); if ( address != NULL && address->local_part != NULL ) { t_array_init(&envelope_values, 2); @@ -274,7 +274,7 @@ static const char *const *_auth_part_get_values static int sieve_envelope_address_list_next_string_item (struct sieve_stringlist *_strlist, string_t **str_r); static int sieve_envelope_address_list_next_item - (struct sieve_address_list *_addrlist, struct sieve_address *addr_r, + (struct sieve_address_list *_addrlist, struct sieve_address *addr_r, string_t **unparsed_r); static void sieve_envelope_address_list_reset (struct sieve_stringlist *_strlist); @@ -289,32 +289,32 @@ struct sieve_envelope_address_list { const struct sieve_address *const *cur_addresses; const char * const *cur_values; - int value_index; + int value_index; }; static struct sieve_address_list *sieve_envelope_address_list_create (const struct sieve_runtime_env *renv, struct sieve_stringlist *env_parts) { struct sieve_envelope_address_list *addrlist; - + addrlist = t_new(struct sieve_envelope_address_list, 1); addrlist->addrlist.strlist.runenv = renv; addrlist->addrlist.strlist.exec_status = SIEVE_EXEC_OK; - addrlist->addrlist.strlist.next_item = + addrlist->addrlist.strlist.next_item = sieve_envelope_address_list_next_string_item; addrlist->addrlist.strlist.reset = sieve_envelope_address_list_reset; addrlist->addrlist.next_item = sieve_envelope_address_list_next_item; addrlist->env_parts = env_parts; - + return &addrlist->addrlist; } static int sieve_envelope_address_list_next_item -(struct sieve_address_list *_addrlist, struct sieve_address *addr_r, +(struct sieve_address_list *_addrlist, struct sieve_address *addr_r, string_t **unparsed_r) { - struct sieve_envelope_address_list *addrlist = - (struct sieve_envelope_address_list *) _addrlist; + struct sieve_envelope_address_list *addrlist = + (struct sieve_envelope_address_list *) _addrlist; const struct sieve_runtime_env *renv = _addrlist->strlist.runenv; if ( addr_r != NULL ) addr_r->local_part = NULL; @@ -326,7 +326,7 @@ static int sieve_envelope_address_list_next_item int ret; /* Read next header value from source list */ - if ( (ret=sieve_stringlist_next_item(addrlist->env_parts, &envp_item)) + if ( (ret=sieve_stringlist_next_item(addrlist->env_parts, &envp_item)) <= 0 ) return ret; @@ -335,7 +335,7 @@ static int sieve_envelope_address_list_next_item "getting `%s' part from message envelope", str_sanitize(str_c(envp_item), 80)); } - + if ( (epart=_envelope_part_find(str_c(envp_item))) != NULL ) { addrlist->value_index = 0; @@ -347,7 +347,7 @@ static int sieve_envelope_address_list_next_item if ( addrlist->cur_addresses != NULL && addrlist->cur_addresses[0] == NULL ) addrlist->cur_addresses = NULL; - } + } if ( addrlist->cur_addresses == NULL && epart->get_values != NULL ) { /* Field contains something else */ @@ -359,15 +359,15 @@ static int sieve_envelope_address_list_next_item } } } - + /* Return next item */ if ( addrlist->cur_addresses != NULL ) { - const struct sieve_address *addr = + const struct sieve_address *addr = addrlist->cur_addresses[addrlist->value_index]; if ( addr->local_part == NULL ) { /* Null path <> */ - if ( unparsed_r != NULL ) + if ( unparsed_r != NULL ) *unparsed_r = t_str_new_const("", 0); } else { if ( addr_r != NULL ) @@ -420,7 +420,7 @@ static int sieve_envelope_address_list_next_string_item static void sieve_envelope_address_list_reset (struct sieve_stringlist *_strlist) { - struct sieve_envelope_address_list *addrlist = + struct sieve_envelope_address_list *addrlist = (struct sieve_envelope_address_list *)_strlist; sieve_stringlist_reset(addrlist->env_parts); @@ -429,26 +429,26 @@ static void sieve_envelope_address_list_reset addrlist->value_index = 0; } -/* - * Command Registration +/* + * Command Registration */ static bool tst_envelope_registered (struct sieve_validator *valdtr, const struct sieve_extension *ext ATTR_UNUSED, - struct sieve_command_registration *cmd_reg) + struct sieve_command_registration *cmd_reg) { /* The order of these is not significant */ sieve_comparators_link_tag(valdtr, cmd_reg, SIEVE_AM_OPT_COMPARATOR); sieve_address_parts_link_tags(valdtr, cmd_reg, SIEVE_AM_OPT_ADDRESS_PART); sieve_match_types_link_tags(valdtr, cmd_reg, SIEVE_AM_OPT_MATCH_TYPE); - + return TRUE; } -/* - * Validation +/* + * Validation */ - + static int _envelope_part_is_supported (void *context, struct sieve_ast_argument *arg) { @@ -463,50 +463,50 @@ static int _envelope_part_is_supported if ( *not_address == NULL ) *not_address = epart; } - + return TRUE; } - + return FALSE; - } - + } + return TRUE; /* Can't check at compile time */ } static bool tst_envelope_validate -(struct sieve_validator *valdtr, struct sieve_command *tst) -{ +(struct sieve_validator *valdtr, struct sieve_command *tst) +{ struct sieve_ast_argument *arg = tst->first_positional; struct sieve_ast_argument *epart; - struct sieve_comparator cmp_default = + struct sieve_comparator cmp_default = SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator); - struct sieve_match_type mcht_default = + struct sieve_match_type mcht_default = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); const struct sieve_envelope_part *not_address = NULL; - + if ( !sieve_validate_positional_argument (valdtr, tst, arg, "envelope part", 1, SAAT_STRING_LIST) ) { return FALSE; } - + if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) ) return FALSE; - + /* Check whether supplied envelope parts are supported - * FIXME: verify dynamic envelope parts at runtime + * FIXME: verify dynamic envelope parts at runtime */ epart = arg; - if ( !sieve_ast_stringlist_map(&epart, (void *) ¬_address, - _envelope_part_is_supported) ) { - - sieve_argument_validate_error(valdtr, epart, - "specified envelope part '%s' is not supported by the envelope test", + if ( !sieve_ast_stringlist_map(&epart, (void *) ¬_address, + _envelope_part_is_supported) ) { + + sieve_argument_validate_error(valdtr, epart, + "specified envelope part '%s' is not supported by the envelope test", str_sanitize(sieve_ast_strlist_strc(epart), 64)); return FALSE; } if ( not_address != NULL ) { - struct sieve_ast_argument *addrp_arg = + struct sieve_ast_argument *addrp_arg = sieve_command_find_argument(tst, &address_part_tag); if ( addrp_arg != NULL ) { @@ -517,14 +517,14 @@ static bool tst_envelope_validate return FALSE; } } - + arg = sieve_ast_argument_next(arg); - + if ( !sieve_validate_positional_argument (valdtr, tst, arg, "key list", 2, SAAT_STRING_LIST) ) { return FALSE; } - + if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) ) return FALSE; @@ -536,9 +536,9 @@ static bool tst_envelope_validate /* * Code generation */ - + static bool tst_envelope_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) { (void)sieve_operation_emit(cgenv->sblock, cmd->ext, &envelope_operation); @@ -549,10 +549,10 @@ static bool tst_envelope_generate return TRUE; } -/* - * Code dump +/* + * Code dump */ - + static bool ext_envelope_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) { @@ -575,11 +575,11 @@ static bool ext_envelope_operation_dump static int ext_envelope_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) { - struct sieve_comparator cmp = + struct sieve_comparator cmp = SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator); - struct sieve_match_type mcht = + struct sieve_match_type mcht = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); - struct sieve_address_part addrp = + struct sieve_address_part addrp = SIEVE_ADDRESS_PART_DEFAULT(all_address_part); struct sieve_stringlist *env_part_list, *value_list, *key_list; struct sieve_address_list *addr_list; @@ -604,7 +604,7 @@ static int ext_envelope_operation_execute <= 0 ) return ret; - /* + /* * Perform test */ diff --git a/src/lib-sieve/ext-fileinto.c b/src/lib-sieve/ext-fileinto.c index fea8afdda888fb85b0d952754b59a79aeb09b645..98e2a5684095a0d5d1df19f4026bd2f7fd77c95b 100644 --- a/src/lib-sieve/ext-fileinto.c +++ b/src/lib-sieve/ext-fileinto.c @@ -4,7 +4,7 @@ /* Extension fileinto * ------------------ * - * Authors: Stephan Bosch + * Authors: Stephan Bosch * Specification: RFC 5228 * Implementation: full * Status: testing @@ -28,28 +28,28 @@ #include "sieve-dump.h" #include "sieve-result.h" -/* - * Forward declarations +/* + * Forward declarations */ static const struct sieve_command_def fileinto_command; const struct sieve_operation_def fileinto_operation; -const struct sieve_extension_def fileinto_extension; +const struct sieve_extension_def fileinto_extension; -/* +/* * Extension */ static bool ext_fileinto_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr); -const struct sieve_extension_def fileinto_extension = { - "fileinto", +const struct sieve_extension_def fileinto_extension = { + "fileinto", NULL, NULL, - ext_fileinto_validator_load, + ext_fileinto_validator_load, NULL, NULL, NULL, NULL, NULL, - SIEVE_EXT_DEFINE_OPERATION(fileinto_operation), - SIEVE_EXT_DEFINE_NO_OPERANDS + SIEVE_EXT_DEFINE_OPERATION(fileinto_operation), + SIEVE_EXT_DEFINE_NO_OPERANDS }; static bool ext_fileinto_validator_load @@ -61,10 +61,10 @@ static bool ext_fileinto_validator_load return TRUE; } -/* +/* * Fileinto command * - * Syntax: + * Syntax: * fileinto <folder: string> */ @@ -73,48 +73,48 @@ static bool cmd_fileinto_validate static bool cmd_fileinto_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx); -static const struct sieve_command_def fileinto_command = { - "fileinto", +static const struct sieve_command_def fileinto_command = { + "fileinto", SCT_COMMAND, - 1, 0, FALSE, FALSE, + 1, 0, FALSE, FALSE, NULL, NULL, cmd_fileinto_validate, NULL, - cmd_fileinto_generate, - NULL + cmd_fileinto_generate, + NULL }; -/* - * Fileinto operation +/* + * Fileinto operation */ static bool ext_fileinto_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address); static int ext_fileinto_operation_execute - (const struct sieve_runtime_env *renv, sieve_size_t *address); + (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def fileinto_operation = { +const struct sieve_operation_def fileinto_operation = { "FILEINTO", &fileinto_extension, 0, - ext_fileinto_operation_dump, - ext_fileinto_operation_execute + ext_fileinto_operation_dump, + ext_fileinto_operation_execute }; -/* - * Validation +/* + * Validation */ static bool cmd_fileinto_validate -(struct sieve_validator *valdtr, struct sieve_command *cmd) -{ +(struct sieve_validator *valdtr, struct sieve_command *cmd) +{ struct sieve_ast_argument *arg = cmd->first_positional; - + if ( !sieve_validate_positional_argument (valdtr, cmd, arg, "folder", 1, SAAT_STRING) ) { return FALSE; } - + if ( !sieve_validator_argument_activate(valdtr, cmd, arg, FALSE) ) return FALSE; @@ -123,10 +123,10 @@ static bool cmd_fileinto_validate const char *folder = sieve_ast_argument_strc(arg); if ( !uni_utf8_str_is_valid(folder) ) { - sieve_command_validate_error(valdtr, cmd, + sieve_command_validate_error(valdtr, cmd, "folder name specified for fileinto command is not utf-8: %s", folder); return FALSE; - } + } } return TRUE; @@ -135,9 +135,9 @@ static bool cmd_fileinto_validate /* * Code generation */ - + static bool cmd_fileinto_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) { sieve_operation_emit(cgenv->sblock, cmd->ext, &fileinto_operation); @@ -145,10 +145,10 @@ static bool cmd_fileinto_generate return sieve_generate_arguments(cgenv, cmd, NULL); } -/* +/* * Code dump */ - + static bool ext_fileinto_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) { @@ -168,7 +168,7 @@ static bool ext_fileinto_operation_dump static int ext_fileinto_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) { - struct sieve_side_effects_list *slist = NULL; + struct sieve_side_effects_list *slist = NULL; string_t *folder; bool folder_literal; bool trace = sieve_runtime_trace_active(renv, SIEVE_TRLVL_ACTIONS); @@ -179,7 +179,7 @@ static int ext_fileinto_operation_execute */ /* Optional operands (side effects only) */ - if ( sieve_action_opr_optional_read(renv, address, NULL, &ret, &slist) != 0 ) + if ( sieve_action_opr_optional_read(renv, address, NULL, &ret, &slist) != 0 ) return ret; /* Folder operand */ @@ -197,15 +197,15 @@ static int ext_fileinto_operation_execute } if ( !folder_literal && !uni_utf8_str_is_valid(str_c(folder)) ) { - sieve_runtime_error(renv, NULL, - "folder name specified for fileinto command is not utf-8: %s", + sieve_runtime_error(renv, NULL, + "folder name specified for fileinto command is not utf-8: %s", str_c(folder)); - return SIEVE_EXEC_FAILURE; + return SIEVE_EXEC_FAILURE; } - + if ( trace ) { - sieve_runtime_trace(renv, 0, "store message in mailbox `%s'", + sieve_runtime_trace(renv, 0, "store message in mailbox `%s'", str_sanitize(str_c(folder), 80)); } diff --git a/src/lib-sieve/ext-reject.c b/src/lib-sieve/ext-reject.c index 247a67a9ec4669954c8c289957d5645385a7028f..c6332f2b73a0fdcd4b5544ca63347133fbce4837 100644 --- a/src/lib-sieve/ext-reject.c +++ b/src/lib-sieve/ext-reject.c @@ -36,8 +36,8 @@ #include "sieve-message.h" #include "sieve-smtp.h" -/* - * Forward declarations +/* + * Forward declarations */ static const struct sieve_command_def reject_command; @@ -46,7 +46,7 @@ static const struct sieve_operation_def reject_operation; static const struct sieve_command_def ereject_command; static const struct sieve_operation_def ereject_operation; -/* +/* * Extensions */ @@ -54,13 +54,13 @@ static const struct sieve_operation_def ereject_operation; static bool ext_reject_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr); - -const struct sieve_extension_def reject_extension = { - "reject", + +const struct sieve_extension_def reject_extension = { + "reject", NULL, NULL, - ext_reject_validator_load, + ext_reject_validator_load, NULL, NULL, NULL, NULL, NULL, - SIEVE_EXT_DEFINE_OPERATION(reject_operation), + SIEVE_EXT_DEFINE_OPERATION(reject_operation), SIEVE_EXT_DEFINE_NO_OPERANDS }; @@ -77,13 +77,13 @@ static bool ext_reject_validator_load static bool ext_ereject_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr); - -const struct sieve_extension_def ereject_extension = { - "ereject", + +const struct sieve_extension_def ereject_extension = { + "ereject", NULL, NULL, - ext_ereject_validator_load, + ext_ereject_validator_load, NULL, NULL, NULL, NULL, NULL, - SIEVE_EXT_DEFINE_OPERATION(ereject_operation), + SIEVE_EXT_DEFINE_OPERATION(ereject_operation), SIEVE_EXT_DEFINE_NO_OPERANDS }; @@ -96,7 +96,7 @@ static bool ext_ereject_validator_load return TRUE; } -/* +/* * Commands */ @@ -105,40 +105,40 @@ static bool ext_ereject_validator_load static bool cmd_reject_validate (struct sieve_validator *valdtr, struct sieve_command *cmd); static bool cmd_reject_generate - (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd); + (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd); /* Reject command - * - * Syntax: + * + * Syntax: * reject <reason: string> */ -static const struct sieve_command_def reject_command = { - "reject", - SCT_COMMAND, +static const struct sieve_command_def reject_command = { + "reject", + SCT_COMMAND, 1, 0, FALSE, FALSE, NULL, NULL, cmd_reject_validate, NULL, - cmd_reject_generate, - NULL + cmd_reject_generate, + NULL }; /* EReject command - * - * Syntax: + * + * Syntax: * ereject <reason: string> */ -static const struct sieve_command_def ereject_command = { - "ereject", - SCT_COMMAND, +static const struct sieve_command_def ereject_command = { + "ereject", + SCT_COMMAND, 1, 0, FALSE, FALSE, NULL, NULL, cmd_reject_validate, NULL, - cmd_reject_generate, - NULL + cmd_reject_generate, + NULL }; /* @@ -154,48 +154,48 @@ static int ext_reject_operation_execute /* Reject operation */ -static const struct sieve_operation_def reject_operation = { +static const struct sieve_operation_def reject_operation = { "REJECT", - &reject_extension, + &reject_extension, 0, - ext_reject_operation_dump, - ext_reject_operation_execute + ext_reject_operation_dump, + ext_reject_operation_execute }; /* EReject operation */ -static const struct sieve_operation_def ereject_operation = { +static const struct sieve_operation_def ereject_operation = { "EREJECT", - &ereject_extension, + &ereject_extension, 0, - ext_reject_operation_dump, - ext_reject_operation_execute + ext_reject_operation_dump, + ext_reject_operation_execute }; -/* - * Reject action +/* + * Reject action */ static int act_reject_check_duplicate - (const struct sieve_runtime_env *renv, - const struct sieve_action *act, + (const struct sieve_runtime_env *renv, + const struct sieve_action *act, const struct sieve_action *act_other); int act_reject_check_conflict - (const struct sieve_runtime_env *renv, - const struct sieve_action *act, + (const struct sieve_runtime_env *renv, + const struct sieve_action *act, const struct sieve_action *act_other); static void act_reject_print - (const struct sieve_action *action, - const struct sieve_result_print_env *rpenv, bool *keep); + (const struct sieve_action *action, + const struct sieve_result_print_env *rpenv, bool *keep); static bool act_reject_commit - (const struct sieve_action *action ATTR_UNUSED, + (const struct sieve_action *action ATTR_UNUSED, const struct sieve_action_exec_env *aenv, void *tr_context, bool *keep); - + const struct sieve_action_def act_reject = { "reject", SIEVE_ACTFLAG_SENDS_RESPONSE, NULL, - act_reject_check_duplicate, + act_reject_check_duplicate, act_reject_check_conflict, act_reject_print, NULL, NULL, @@ -208,29 +208,29 @@ struct act_reject_context { bool ereject; }; -/* - * Validation +/* + * Validation */ static bool cmd_reject_validate -(struct sieve_validator *valdtr, struct sieve_command *cmd) -{ +(struct sieve_validator *valdtr, struct sieve_command *cmd) +{ struct sieve_ast_argument *arg = cmd->first_positional; - + if ( !sieve_validate_positional_argument (valdtr, cmd, arg, "reason", 1, SAAT_STRING) ) { return FALSE; } - + return sieve_validator_argument_activate(valdtr, cmd, arg, FALSE); } /* * Code generation */ - + static bool cmd_reject_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) { if ( sieve_command_is(cmd, reject_command) ) sieve_operation_emit(cgenv->sblock, cmd->ext, &reject_operation); @@ -241,10 +241,10 @@ static bool cmd_reject_generate return sieve_generate_arguments(cgenv, cmd, NULL); } -/* +/* * Code dump */ - + static bool ext_reject_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) { @@ -253,7 +253,7 @@ static bool ext_reject_operation_dump if ( sieve_action_opr_optional_dump(denv, address, NULL) != 0 ) return FALSE; - + return sieve_opr_string_dump(denv, address, "reason"); } @@ -277,7 +277,7 @@ static int ext_reject_operation_execute */ /* Optional operands (side effects only) */ - if ( sieve_action_opr_optional_read(renv, address, NULL, &ret, &slist) != 0 ) + if ( sieve_action_opr_optional_read(renv, address, NULL, &ret, &slist) != 0 ) return ret; /* Read rejection reason */ @@ -295,7 +295,7 @@ static int ext_reject_operation_execute sieve_runtime_trace(renv, 0, "reject action"); sieve_runtime_trace_descend(renv); - sieve_runtime_trace(renv, 0, "reject message with reason `%s'", + sieve_runtime_trace(renv, 0, "reject message with reason `%s'", str_sanitize(str_c(reason), 64)); } @@ -318,30 +318,30 @@ static int ext_reject_operation_execute static int act_reject_check_duplicate (const struct sieve_runtime_env *renv ATTR_UNUSED, - const struct sieve_action *act, + const struct sieve_action *act, const struct sieve_action *act_other) { if ( !act_other->executed ) { - sieve_runtime_error(renv, act->location, + sieve_runtime_error(renv, act->location, "duplicate reject/ereject action not allowed " - "(previously triggered one was here: %s)", act_other->location); + "(previously triggered one was here: %s)", act_other->location); return -1; } - + return 1; } - + int act_reject_check_conflict (const struct sieve_runtime_env *renv, - const struct sieve_action *act, + const struct sieve_action *act, const struct sieve_action *act_other) { if ( (act_other->def->flags & SIEVE_ACTFLAG_TRIES_DELIVER) > 0 ) { if ( !act_other->executed ) { - sieve_runtime_error(renv, act->location, + sieve_runtime_error(renv, act->location, "reject/ereject action conflicts with other action: " "the %s action (%s) tries to deliver the message", - act_other->def->name, act_other->location); + act_other->def->name, act_other->location); return -1; } } @@ -350,10 +350,10 @@ int act_reject_check_conflict struct act_reject_context *rj_ctx; if ( !act_other->executed ) { - sieve_runtime_error(renv, act->location, + sieve_runtime_error(renv, act->location, "reject/ereject action conflicts with other action: " "the %s action (%s) also sends a response to the sender", - act_other->def->name, act_other->location); + act_other->def->name, act_other->location); return -1; } @@ -366,27 +366,27 @@ int act_reject_check_conflict return 0; } - + static void act_reject_print -(const struct sieve_action *action, const struct sieve_result_print_env *rpenv, - bool *keep) +(const struct sieve_action *action, const struct sieve_result_print_env *rpenv, + bool *keep) { - struct act_reject_context *rj_ctx = + struct act_reject_context *rj_ctx = (struct act_reject_context *) action->context; - + if ( rj_ctx->reason != NULL ) { - sieve_result_action_printf(rpenv, "reject message with reason: %s", + sieve_result_action_printf(rpenv, "reject message with reason: %s", str_sanitize(rj_ctx->reason, 128)); } else { - sieve_result_action_printf(rpenv, - "reject message without sending a response (discard)"); + sieve_result_action_printf(rpenv, + "reject message without sending a response (discard)"); } - + *keep = FALSE; } static bool act_reject_commit -(const struct sieve_action *action, const struct sieve_action_exec_env *aenv, +(const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void *tr_context ATTR_UNUSED, bool *keep) { struct act_reject_context *rj_ctx = @@ -395,35 +395,35 @@ static bool act_reject_commit const char *recipient = sieve_message_get_final_recipient(aenv->msgctx); if ( recipient == NULL ) { - sieve_result_global_warning(aenv, + sieve_result_global_warning(aenv, "reject action aborted: envelope recipient is <>"); return TRUE; } - + if ( rj_ctx->reason == NULL ) { - sieve_result_global_log(aenv, + sieve_result_global_log(aenv, "not sending reject message (would cause second response to sender)"); - + *keep = FALSE; return TRUE; } if ( sender == NULL ) { sieve_result_global_log(aenv, "not sending reject message to <>"); - + *keep = FALSE; return TRUE; } - + if ( sieve_action_reject_mail(aenv, sender, recipient, rj_ctx->reason) ) { - sieve_result_global_log(aenv, + sieve_result_global_log(aenv, "rejected message from <%s> (%s)", str_sanitize(sender, 80), ( rj_ctx->ereject ? "ereject" : "reject" )); *keep = FALSE; return TRUE; } - + return FALSE; } diff --git a/src/lib-sieve/mcht-contains.c b/src/lib-sieve/mcht-contains.c index c84a8a8e8450932d777216a6241280bf401b9ac7..e5a5b905261ac85ce11e94c368abd388d2f98b80 100644 --- a/src/lib-sieve/mcht-contains.c +++ b/src/lib-sieve/mcht-contains.c @@ -1,7 +1,7 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ -/* Match-type ':contains' +/* Match-type ':contains' */ #include "lib.h" @@ -15,10 +15,10 @@ /* * Forward declarations - */ + */ static int mcht_contains_match_key - (struct sieve_match_context *mctx, const char *val, size_t val_size, + (struct sieve_match_context *mctx, const char *val, size_t val_size, const char *key, size_t key_size); /* @@ -38,11 +38,11 @@ const struct sieve_match_type_def contains_match_type = { * Match-type implementation */ -/* FIXME: Naive substring match implementation. Should switch to more +/* FIXME: Naive substring match implementation. Should switch to more * efficient algorithm if large values need to be searched (e.g. message body). */ static int mcht_contains_match_key -(struct sieve_match_context *mctx, const char *val, size_t val_size, +(struct sieve_match_context *mctx, const char *val, size_t val_size, const char *key, size_t key_size) { const struct sieve_comparator *cmp = mctx->comparator; @@ -51,17 +51,17 @@ static int mcht_contains_match_key const char *vp = val; const char *kp = key; - if ( val_size == 0 ) + if ( val_size == 0 ) return ( key_size == 0 ); - if ( cmp->def == NULL || cmp->def->char_match == NULL ) + if ( cmp->def == NULL || cmp->def->char_match == NULL ) return FALSE; while ( (vp < vend) && (kp < kend) ) { if ( !cmp->def->char_match(cmp, &vp, vend, &kp, kend) ) vp++; } - + return (kp == kend); } diff --git a/src/lib-sieve/mcht-is.c b/src/lib-sieve/mcht-is.c index 0dbd73ecb8e77cbc98e6319ea04343f4c408ae7e..5d05a5b8256b37feffcb1e49f0e062a6be95fc59 100644 --- a/src/lib-sieve/mcht-is.c +++ b/src/lib-sieve/mcht-is.c @@ -1,7 +1,7 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - -/* Match-type ':is': + +/* Match-type ':is': */ #include "lib.h" @@ -13,16 +13,16 @@ #include <string.h> #include <stdio.h> -/* - * Forward declarations +/* + * Forward declarations */ static int mcht_is_match_key - (struct sieve_match_context *mctx, const char *val, size_t val_size, + (struct sieve_match_context *mctx, const char *val, size_t val_size, const char *key, size_t key_size); -/* - * Match-type object +/* + * Match-type object */ const struct sieve_match_type_def is_match_type = { @@ -37,15 +37,15 @@ const struct sieve_match_type_def is_match_type = { */ static int mcht_is_match_key -(struct sieve_match_context *mctx ATTR_UNUSED, - const char *val, size_t val_size, +(struct sieve_match_context *mctx ATTR_UNUSED, + const char *val, size_t val_size, const char *key, size_t key_size) { - if ( val_size == 0 ) + if ( val_size == 0 ) return ( key_size == 0 ); if ( mctx->comparator->def != NULL && mctx->comparator->def->compare != NULL ) - return (mctx->comparator->def->compare(mctx->comparator, + return (mctx->comparator->def->compare(mctx->comparator, val, val_size, key, key_size) == 0); return FALSE; diff --git a/src/lib-sieve/mcht-matches.c b/src/lib-sieve/mcht-matches.c index 1cee70a57b0f8a2b772d2f094cfff824921de130..ccdbb0750737cf0bc310d9704513d9238f902799 100644 --- a/src/lib-sieve/mcht-matches.c +++ b/src/lib-sieve/mcht-matches.c @@ -1,7 +1,7 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - -/* Match-type ':matches' + +/* Match-type ':matches' */ #include "lib.h" @@ -19,7 +19,7 @@ */ static int mcht_matches_match_key - (struct sieve_match_context *mctx, const char *val, size_t val_size, + (struct sieve_match_context *mctx, const char *val, size_t val_size, const char *key, size_t key_size); /* @@ -29,7 +29,7 @@ static int mcht_matches_match_key const struct sieve_match_type_def matches_match_type = { SIEVE_OBJECT("matches", &match_type_operand, SIEVE_MATCH_TYPE_MATCHES), NULL, - sieve_match_substring_validate_context, + sieve_match_substring_validate_context, NULL, NULL, NULL, mcht_matches_match_key, NULL @@ -44,26 +44,26 @@ const struct sieve_match_type_def matches_match_type = { #ifdef MATCH_DEBUG #define debug_printf(...) printf ("match debug: " __VA_ARGS__) #else -#define debug_printf(...) +#define debug_printf(...) #endif /* FIXME: Naive implementation, substitute this with dovecot src/lib/str-find.c */ -static inline bool _string_find(const struct sieve_comparator *cmp, +static inline bool _string_find(const struct sieve_comparator *cmp, const char **valp, const char *vend, const char **keyp, const char *kend) { while ( (*valp < vend) && (*keyp < kend) ) { if ( !cmp->def->char_match(cmp, valp, vend, keyp, kend) ) (*valp)++; } - + return (*keyp == kend); } static char _scan_key_section (string_t *section, const char **wcardp, const char *key_end) { - /* Find next wildcard and resolve escape sequences */ + /* Find next wildcard and resolve escape sequences */ str_truncate(section, 0); while ( *wcardp < key_end && **wcardp != '*' && **wcardp != '?') { if ( **wcardp == '\\' ) { @@ -72,18 +72,18 @@ static char _scan_key_section str_append_c(section, **wcardp); (*wcardp)++; } - + /* Record wildcard character or \0 */ - if ( *wcardp < key_end ) { + if ( *wcardp < key_end ) { return **wcardp; - } - + } + i_assert( *wcardp == key_end ); return '\0'; } static int mcht_matches_match_key -(struct sieve_match_context *mctx, const char *val, size_t val_size, +(struct sieve_match_context *mctx, const char *val, size_t val_size, const char *key, size_t key_size) { const struct sieve_comparator *cmp = mctx->comparator; @@ -102,7 +102,7 @@ static int mcht_matches_match_key /* Key sections */ section = t_str_new(32); /* Section (after beginning or *) */ subsection = t_str_new(32); /* Sub-section (after ?) */ - + /* Mark end of value and key */ vend = (const char *) val + val_size; kend = (const char *) key + key_size; @@ -120,14 +120,14 @@ static int mcht_matches_match_key mvalue = t_str_new(32); /* Match value (*) */ mchars = t_str_new(32); /* Match characters (.?..?.??) */ } - - /* Match the pattern: + + /* Match the pattern: * <pattern> = <section>*<section>*<section>... * <section> = <sub-section>?<sub-section>?<sub-section>... * - * Escape sequences \? and \* need special attention. + * Escape sequences \? and \* need special attention. */ - + debug_printf("=== Start ===\n"); debug_printf(" key: %s\n", t_strdup_until(key, kend)); debug_printf(" value: %s\n", t_strdup_until(val, vend)); @@ -135,61 +135,61 @@ static int mcht_matches_match_key /* Loop until either key or value ends */ while (kp < kend && vp < vend ) { const char *needle, *nend; - + if ( !backtrack ) { /* Search the next '*' wildcard in the key string */ wcard = next_wcard; - - /* Find the needle to look for in the string */ - key_offset = 0; + + /* Find the needle to look for in the string */ + key_offset = 0; for (;;) { next_wcard = _scan_key_section(section, &wp, kend); - - if ( wcard == '\0' || str_len(section) > 0 ) + + if ( wcard == '\0' || str_len(section) > 0 ) break; - - if ( next_wcard == '*' ) { + + if ( next_wcard == '*' ) { break; } - - if ( wp < kend ) + + if ( wp < kend ) wp++; - else + else break; key_offset++; } - - debug_printf("found wildcard '%c' at pos [%d]\n", + + debug_printf("found wildcard '%c' at pos [%d]\n", next_wcard, (int) (wp-key)); - - if ( mvalues != NULL ) + + if ( mvalues != NULL ) str_truncate(mvalue, 0); } else { /* Backtracked; '*' wildcard is retained */ debug_printf("backtracked"); backtrack = FALSE; } - + /* Determine what we are looking for */ needle = str_c(section); - nend = PTR_OFFSET(needle, str_len(section)); - + nend = PTR_OFFSET(needle, str_len(section)); + debug_printf(" section needle: '%s'\n", t_strdup_until(needle, nend)); debug_printf(" section key: '%s'\n", t_strdup_until(kp, kend)); debug_printf(" section remnant: '%s'\n", t_strdup_until(wp, kend)); debug_printf(" value remnant: '%s'\n", t_strdup_until(vp, vend)); debug_printf(" key offset: %d\n", key_offset); - + pvp = vp; if ( next_wcard == '\0' ) { /* No more wildcards; find the needle substring at the end of string */ - + const char *qp, *qend; - - debug_printf("next_wcard = NUL; must find needle at end\n"); - /* Check if the value is still large enough */ + debug_printf("next_wcard = NUL; must find needle at end\n"); + + /* Check if the value is still large enough */ if ( vend - str_len(section) < vp ) { debug_printf(" wont match: value is too short\n"); break; @@ -201,16 +201,16 @@ static int mcht_matches_match_key /* Record match values */ qend = vp; qp = vp - key_offset; - + if ( mvalues != NULL ) str_append_n(mvalue, pvp, qp-pvp); - + /* Compare needle to end of value string */ - if ( !cmp->def->char_match(cmp, &vp, vend, &needle, nend) ) { - debug_printf(" match at end failed\n"); + if ( !cmp->def->char_match(cmp, &vp, vend, &needle, nend) ) { + debug_printf(" match at end failed\n"); break; } - + /* Add match values */ if ( mvalues != NULL ) { /* Append '*' match value */ @@ -218,7 +218,7 @@ static int mcht_matches_match_key /* Append any initial '?' match values */ for ( ; qp < qend; qp++ ) - sieve_match_values_add_char(mvalues, *qp); + sieve_match_values_add_char(mvalues, *qp); } /* Finish match */ @@ -236,17 +236,17 @@ static int mcht_matches_match_key const char *chars; /* Reset '?' match values */ - if ( mvalues != NULL ) + if ( mvalues != NULL ) str_truncate(mchars, 0); - + if ( wcard == '\0' ) { /* No current wildcard; match needs to happen right at the beginning */ debug_printf("wcard = NUL; needle should be found at the beginning.\n"); debug_printf(" begin needle: '%s'\n", t_strdup_until(needle, nend)); debug_printf(" begin value: '%s'\n", t_strdup_until(vp, vend)); - if ( !cmp->def->char_match(cmp, &vp, vend, &needle, nend) ) { - debug_printf(" failed to find needle at beginning\n"); + if ( !cmp->def->char_match(cmp, &vp, vend, &needle, nend) ) { + debug_printf(" failed to find needle at beginning\n"); break; } @@ -255,17 +255,17 @@ static int mcht_matches_match_key debug_printf("wcard != NUL; must find needle at an offset (>= %d).\n", key_offset); - /* Match may happen at any offset (>= key offset): find substring */ + /* Match may happen at any offset (>= key offset): find substring */ vp += key_offset; if ( (vp >= vend) || !_string_find(cmp, &vp, vend, &needle, nend) ) { - debug_printf(" failed to find needle at an offset\n"); + debug_printf(" failed to find needle at an offset\n"); break; } prv = vp - str_len(section); prk = kp; - prw = wp; - + prw = wp; + /* Append match values */ if ( mvalues != NULL ) { const char *qend = vp - str_len(section); @@ -281,26 +281,26 @@ static int mcht_matches_match_key str_append_c(mchars, *qp); } } - + /* Update wildcard and key pointers for next wildcard scan */ if ( wp < kend ) wp++; kp = wp; - + /* Scan successive '?' wildcards */ while ( next_wcard == '?' ) { debug_printf("next_wcard = '?'; need to match arbitrary character\n"); - - /* Add match value */ + + /* Add match value */ if ( mvalues != NULL ) str_append_c(mchars, *vp); vp++; - /* Scan for next '?' wildcard */ + /* Scan for next '?' wildcard */ next_wcard = _scan_key_section(subsection, &wp, kend); - debug_printf("found next wildcard '%c' at pos [%d] (fixed match)\n", + debug_printf("found next wildcard '%c' at pos [%d] (fixed match)\n", next_wcard, (int) (wp-key)); - + /* Determine what we are looking for */ needle = str_c(subsection); nend = PTR_OFFSET(needle, str_len(subsection)); @@ -309,33 +309,33 @@ static int mcht_matches_match_key debug_printf(" value remnant: '%s'\n", vp <= vend ? t_strdup_until(vp, vend) : ""); /* Try matching the needle at fixed position */ - if ( (needle == nend && next_wcard == '\0' && vp < vend ) || - !cmp->def->char_match(cmp, &vp, vend, &needle, nend) ) { - + if ( (needle == nend && next_wcard == '\0' && vp < vend ) || + !cmp->def->char_match(cmp, &vp, vend, &needle, nend) ) { + /* Match failed: now we have a problem. We need to backtrack to the previous * '*' wildcard occurence and start scanning for the next possible match. */ debug_printf(" failed fixed match\n"); - + /* Start backtrack */ if ( prv != NULL && prv + 1 < vend ) { /* Restore pointers */ vp = prv; kp = prk; wp = prw; - + /* Skip forward one value character to scan the next possible match */ if ( mvalues != NULL ) str_append_c(mvalue, *vp); vp++; - + /* Set wildcard state appropriately */ wcard = '*'; next_wcard = '?'; - + /* Backtrack */ - backtrack = TRUE; + backtrack = TRUE; debug_printf(" BACKTRACK\n"); } @@ -343,20 +343,20 @@ static int mcht_matches_match_key /* Break '?' wildcard scanning loop */ break; } - + /* Update wildcard and key pointers for next wildcard scan */ if ( wp < kend ) wp++; kp = wp; } - + if ( !backtrack ) { unsigned int i; - + if ( next_wcard == '?' ) { - debug_printf("failed to match '?'\n"); + debug_printf("failed to match '?'\n"); break; } - + if ( mvalues != NULL ) { if ( prv != NULL ) sieve_match_values_add(mvalues, mvalue); @@ -374,8 +374,8 @@ static int mcht_matches_match_key } } } - - /* Check whether string ends in a wildcard + + /* Check whether string ends in a wildcard * (avoid scanning the rest of the string) */ if ( kp == kend && next_wcard == '*' ) { @@ -385,15 +385,15 @@ static int mcht_matches_match_key str_append_n(mvalue, vp, vend-vp); sieve_match_values_add(mvalues, mvalue); } - + /* Finish match */ kp = kend; vp = vend; - + debug_printf("key ends with '*'\n"); break; - } - + } + debug_printf("== Loop ==\n"); } @@ -405,10 +405,10 @@ static int mcht_matches_match_key /* By definition, the match is only successful if both value and key pattern * are exhausted. */ - + debug_printf("=== Finish ===\n"); debug_printf(" result: %s\n", (kp == kend && vp == vend) ? "true" : "false"); - + if (kp == kend && vp == vend) { /* Activate new match values after successful match */ if ( mvalues != NULL ) { @@ -426,4 +426,4 @@ static int mcht_matches_match_key sieve_match_values_abort(&mvalues); return FALSE; } - + diff --git a/src/lib-sieve/plugins/Makefile.am b/src/lib-sieve/plugins/Makefile.am index 8f34320e843d7ecba19c48ae777e80ecd1736cdf..21fedfcee80a44d5cb27e2a28924d2f1702491ac 100644 --- a/src/lib-sieve/plugins/Makefile.am +++ b/src/lib-sieve/plugins/Makefile.am @@ -1,5 +1,5 @@ if BUILD_UNFINISHED -UNFINISHED = +UNFINISHED = endif SUBDIRS = \ diff --git a/src/lib-sieve/plugins/body/ext-body-common.c b/src/lib-sieve/plugins/body/ext-body-common.c index 6f2588d7220bd67c4c722d6b48822afd3620f139..e313d6aec4efe69c24171ecefdd3c917ff47d4f0 100644 --- a/src/lib-sieve/plugins/body/ext-body-common.c +++ b/src/lib-sieve/plugins/body/ext-body-common.c @@ -29,7 +29,7 @@ struct ext_body_part { const char *content; unsigned long size; }; - + struct ext_body_part_cached { const char *content_type; @@ -37,7 +37,7 @@ struct ext_body_part_cached { const char *decoded_body; size_t raw_body_size; size_t decoded_body_size; - + bool have_body; /* there's the empty end-of-headers line */ }; @@ -98,11 +98,11 @@ static bool ext_body_get_return_parts /* Clear result array */ array_clear(&ctx->return_body_parts); - + /* Fill result array with requested content_types */ for (i = 0; i < count; i++) { if (!body_parts[i].have_body) { - /* Part has no body; according to RFC this MUST not match to anything and + /* Part has no body; according to RFC this MUST not match to anything and * therefore it is not included in the result. */ continue; @@ -116,7 +116,7 @@ static bool ext_body_get_return_parts return_part = array_append_space(&ctx->return_body_parts); /* Depending on whether a decoded body part is requested, the appropriate - * cache item is read. If it is missing, this function fails and the cache + * cache item is read. If it is missing, this function fails and the cache * needs to be completed by ext_body_parts_add_missing(). */ if (decode_to_plain) { @@ -160,7 +160,7 @@ static void ext_body_part_save body_part->decoded_body = part_data; body_part->decoded_body_size = part_size; } - + /* Clear buffer */ buffer_set_used_size(buf, 0); } @@ -189,10 +189,10 @@ static const char *_parse_content_type(const struct message_header_line *hdr) } /* ext_body_parts_add_missing(): - * Add requested message body parts to the cache that are missing. + * Add requested message body parts to the cache that are missing. */ static bool ext_body_parts_add_missing -(struct sieve_message_context *msgctx, struct ext_body_message_context *ctx, +(struct sieve_message_context *msgctx, struct ext_body_message_context *ctx, const char * const *content_types, bool decode_to_plain) { struct mail *mail = sieve_message_get_mail(msgctx); @@ -218,9 +218,9 @@ static bool ext_body_parts_add_missing // return FALSE; buffer_set_used_size(ctx->tmp_buffer, 0); - + /* Initialize body decoder */ - decoder = decode_to_plain ? message_decoder_init(FALSE) : NULL; + decoder = decode_to_plain ? message_decoder_init(FALSE) : NULL; //parser = message_parser_init_from_parts(parts, input, 0, 0); parser = message_parser_init(ctx->pool, input, 0, 0); @@ -237,7 +237,7 @@ static bool ext_body_parts_add_missing strcmp(body_part->content_type, "message/rfc822") == 0 ) { message_rfc822 = TRUE; } else { - if ( save_body ) + if ( save_body ) ext_body_part_save(ctx, body_part, decoder != NULL); } } @@ -257,9 +257,9 @@ static bool ext_body_parts_add_missing } prev_part = block.part; - idx++; + idx++; } - + if ( block.hdr != NULL || block.size == 0 ) { /* Reading headers */ @@ -274,15 +274,15 @@ static bool ext_body_parts_add_missing ext_body_part_save(ctx, header_part, decoder != NULL); header_part = NULL; } - + /* Save bodies only if we have a wanted content-type */ i_assert( body_part != NULL ); save_body = _is_wanted_content_type (content_types, body_part->content_type); continue; } - - /* Encountered the empty line that indicates the end of the headers and + + /* Encountered the empty line that indicates the end of the headers and * the start of the body */ if ( block.hdr->eoh ) { @@ -301,12 +301,12 @@ static bool ext_body_parts_add_missing buffer_append(ctx->tmp_buffer, "\r\n", 2); } } - + /* We're interested of only Content-Type: header */ if ( strcasecmp(block.hdr->name, "Content-Type" ) != 0 ) continue; - /* Header can have folding whitespace. Acquire the full value before + /* Header can have folding whitespace. Acquire the full value before * continuing */ if ( block.hdr->continues ) { @@ -315,13 +315,13 @@ static bool ext_body_parts_add_missing } i_assert( body_part != NULL ); - + /* Parse the content type from the Content-type header */ T_BEGIN { body_part->content_type = p_strdup(ctx->pool, _parse_content_type(block.hdr)); } T_END; - + continue; } @@ -345,7 +345,7 @@ static bool ext_body_parts_add_missing /* Try to fill the return_body_parts array once more */ have_all = ext_body_get_return_parts(ctx, content_types, decode_to_plain); - + /* This time, failure is a bug */ i_assert(have_all); @@ -353,7 +353,7 @@ static bool ext_body_parts_add_missing (void)message_parser_deinit(&parser, &parts); if (decoder != NULL) message_decoder_deinit(&decoder); - + /* Return status */ return ( input->stream_errno == 0 ); } @@ -362,28 +362,28 @@ static struct ext_body_message_context *ext_body_get_context (const struct sieve_extension *this_ext, struct sieve_message_context *msgctx) { struct ext_body_message_context *ctx; - + /* Get message context (contains cached message body information) */ ctx = (struct ext_body_message_context *) sieve_message_context_extension_get(msgctx, this_ext); - + /* Create it if it does not exist already */ if ( ctx == NULL ) { pool_t pool; pool = sieve_message_context_pool(msgctx); - ctx = p_new(pool, struct ext_body_message_context, 1); + ctx = p_new(pool, struct ext_body_message_context, 1); ctx->pool = pool; p_array_init(&ctx->cached_body_parts, pool, 8); p_array_init(&ctx->return_body_parts, pool, 8); ctx->tmp_buffer = buffer_create_dynamic(pool, 1024*64); - ctx->raw_body = NULL; + ctx->raw_body = NULL; /* Register context */ sieve_message_context_extension_set(msgctx, this_ext, (void *) ctx); } - + return ctx; } @@ -392,7 +392,7 @@ static bool ext_body_get_content int decode_to_plain, struct ext_body_part **parts_r) { const struct sieve_extension *this_ext = renv->oprtn->ext; - struct ext_body_message_context *ctx = + struct ext_body_message_context *ctx = ext_body_get_context(this_ext, renv->msgctx); bool result = TRUE; @@ -402,7 +402,7 @@ static bool ext_body_get_content (renv->msgctx, ctx, content_types, decode_to_plain != 0) ) result = FALSE; } T_END; - + /* Check status */ if ( !result ) return FALSE; @@ -417,7 +417,7 @@ static bool ext_body_get_raw (const struct sieve_runtime_env *renv, struct ext_body_part **parts_r) { const struct sieve_extension *this_ext = renv->oprtn->ext; - struct ext_body_message_context *ctx = + struct ext_body_message_context *ctx = ext_body_get_context(this_ext, renv->msgctx); struct ext_body_part *return_part; buffer_t *buf; @@ -440,7 +440,7 @@ static bool ext_body_get_raw i_stream_skip(input, hdr_size.physical_size); /* Read raw message body */ - while ( (ret=i_stream_read_data(input, &data, &size, 0)) > 0 ) { + while ( (ret=i_stream_read_data(input, &data, &size, 0)) > 0 ) { buffer_append(buf, data, size); i_stream_skip(input, size); @@ -449,7 +449,7 @@ static bool ext_body_get_raw if ( ret == -1 && input->stream_errno != 0 ) return FALSE; } else { - buf = ctx->raw_body; + buf = ctx->raw_body; } /* Clear result array */ @@ -458,7 +458,7 @@ static bool ext_body_get_raw if ( buf->used > 0 ) { /* Add terminating NUL to the body part buffer */ buffer_append_c(buf, '\0'); - + /* Add single item to the result */ return_part = array_append_space(&ctx->return_body_parts); return_part->content = buf->data; @@ -530,7 +530,7 @@ struct sieve_stringlist *ext_body_get_part_list static int ext_body_stringlist_next_item (struct sieve_stringlist *_strlist, string_t **str_r) { - struct ext_body_stringlist *strlist = + struct ext_body_stringlist *strlist = (struct ext_body_stringlist *)_strlist; *str_r = NULL; @@ -539,14 +539,14 @@ static int ext_body_stringlist_next_item *str_r = t_str_new_const (strlist->body_parts_iter->content, strlist->body_parts_iter->size); - strlist->body_parts_iter++; + strlist->body_parts_iter++; return 1; } static void ext_body_stringlist_reset (struct sieve_stringlist *_strlist) { - struct ext_body_stringlist *strlist = + struct ext_body_stringlist *strlist = (struct ext_body_stringlist *)_strlist; strlist->body_parts_iter = strlist->body_parts; diff --git a/src/lib-sieve/plugins/body/ext-body-common.h b/src/lib-sieve/plugins/body/ext-body-common.h index 4fdc0202bbef9a5661ffa0e113014af22cbd3b6a..80e5043ccc71fea3a0689487aba18d057ad27808 100644 --- a/src/lib-sieve/plugins/body/ext-body-common.h +++ b/src/lib-sieve/plugins/body/ext-body-common.h @@ -1,6 +1,6 @@ /* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #ifndef __EXT_BODY_COMMON_H #define __EXT_BODY_COMMON_H @@ -17,15 +17,15 @@ enum tst_body_transform { /* * Extension */ - + extern const struct sieve_extension_def body_extension; -/* +/* * Commands */ extern const struct sieve_command_def body_test; - + /* * Operations */ diff --git a/src/lib-sieve/plugins/body/ext-body.c b/src/lib-sieve/plugins/body/ext-body.c index dc28667f2ddf6778e15bbe96ecbc8ea5b0855613..61946c1b22103a601ebee6a7d259565cd125ac65 100644 --- a/src/lib-sieve/plugins/body/ext-body.c +++ b/src/lib-sieve/plugins/body/ext-body.c @@ -11,8 +11,8 @@ * Status: testing * */ - -/* FIXME: + +/* FIXME: * * From RFC with respect to :text body transform: * @@ -24,10 +24,10 @@ * formats to text or apply optical character recognition algorithms to * image data.)" * - * We might want to do this in the future, i.e. we must evaluate whether this is + * We might want to do this in the future, i.e. we must evaluate whether this is * feasible. */ - + #include "lib.h" #include "array.h" @@ -45,19 +45,19 @@ #include "ext-body-common.h" -/* - * Extension +/* + * Extension */ static bool ext_body_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr); -const struct sieve_extension_def body_extension = { - "body", +const struct sieve_extension_def body_extension = { + "body", NULL, NULL, - ext_body_validator_load, + ext_body_validator_load, NULL, NULL, NULL, NULL, NULL, - SIEVE_EXT_DEFINE_OPERATION(body_operation), + SIEVE_EXT_DEFINE_OPERATION(body_operation), SIEVE_EXT_DEFINE_NO_OPERANDS }; diff --git a/src/lib-sieve/plugins/body/tst-body.c b/src/lib-sieve/plugins/body/tst-body.c index c6acc548ae6d0d1aa34159697e8e0ad9ad90f571..07b67a238a678ea8255869309a0570e87a0378da 100644 --- a/src/lib-sieve/plugins/body/tst-body.c +++ b/src/lib-sieve/plugins/body/tst-body.c @@ -1,6 +1,6 @@ /* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #include "sieve-extensions.h" #include "sieve-commands.h" #include "sieve-stringlist.h" @@ -18,8 +18,8 @@ #include "ext-body-common.h" -/* - * Body test +/* + * Body test * * Syntax * body [COMPARATOR] [MATCH-TYPE] [BODY-TRANSFORM] @@ -34,20 +34,20 @@ static bool tst_body_validate static bool tst_body_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx); -const struct sieve_command_def body_test = { - "body", - SCT_TEST, +const struct sieve_command_def body_test = { + "body", + SCT_TEST, 1, 0, FALSE, FALSE, - tst_body_registered, + tst_body_registered, NULL, tst_body_validate, - NULL, - tst_body_generate, - NULL + NULL, + tst_body_generate, + NULL }; -/* - * Body operation +/* + * Body operation */ static bool ext_body_operation_dump @@ -55,65 +55,65 @@ static bool ext_body_operation_dump static int ext_body_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def body_operation = { +const struct sieve_operation_def body_operation = { "body", &body_extension, 0, - ext_body_operation_dump, - ext_body_operation_execute + ext_body_operation_dump, + ext_body_operation_execute }; /* * Optional operands */ -enum tst_body_optional { +enum tst_body_optional { OPT_BODY_TRANSFORM = SIEVE_MATCH_OPT_LAST }; -/* - * Tagged arguments +/* + * Tagged arguments */ /* Forward declarations */ static bool tag_body_transform_validate - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); -static bool tag_body_transform_generate - (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, +static bool tag_body_transform_generate + (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *cmd); /* Argument objects */ - -static const struct sieve_argument_def body_raw_tag = { - "raw", + +static const struct sieve_argument_def body_raw_tag = { + "raw", NULL, - tag_body_transform_validate, - NULL, NULL, - tag_body_transform_generate + tag_body_transform_validate, + NULL, NULL, + tag_body_transform_generate }; -static const struct sieve_argument_def body_content_tag = { - "content", +static const struct sieve_argument_def body_content_tag = { + "content", NULL, - tag_body_transform_validate, - NULL, NULL, - tag_body_transform_generate + tag_body_transform_validate, + NULL, NULL, + tag_body_transform_generate }; -static const struct sieve_argument_def body_text_tag = { - "text", +static const struct sieve_argument_def body_text_tag = { + "text", NULL, - tag_body_transform_validate, - NULL, NULL, + tag_body_transform_validate, + NULL, NULL, tag_body_transform_generate }; /* Argument implementation */ - + static bool tag_body_transform_validate -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd) { enum tst_body_transform transform; @@ -125,7 +125,7 @@ static bool tag_body_transform_validate * / :text */ if ( (bool) cmd->data ) { - sieve_argument_validate_error(valdtr, *arg, + sieve_argument_validate_error(valdtr, *arg, "the :raw, :content and :text arguments for the body test are mutually " "exclusive, but more than one was specified"); return FALSE; @@ -135,12 +135,12 @@ static bool tag_body_transform_validate *arg = sieve_ast_argument_next(*arg); /* :content tag has a string-list argument */ - if ( sieve_argument_is(tag, body_raw_tag) ) + if ( sieve_argument_is(tag, body_raw_tag) ) transform = TST_BODY_TRANSFORM_RAW; - + else if ( sieve_argument_is(tag, body_text_tag) ) transform = TST_BODY_TRANSFORM_TEXT; - + else if ( sieve_argument_is(tag, body_content_tag) ) { /* Check syntax: * :content <content-types: string-list> @@ -149,59 +149,59 @@ static bool tag_body_transform_validate (valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING_LIST, FALSE) ) { return FALSE; } - + /* Assign tag parameters */ tag->parameters = *arg; *arg = sieve_ast_arguments_detach(*arg,1); - + transform = TST_BODY_TRANSFORM_CONTENT; - } else + } else return FALSE; - + /* Signal the presence of this tag */ cmd->data = (void *) TRUE; - + /* Assign context data */ - tag->argument->data = (void *) transform; - + tag->argument->data = (void *) transform; + return TRUE; } -/* - * Command Registration +/* + * Command Registration */ static bool tst_body_registered (struct sieve_validator *valdtr, const struct sieve_extension *ext, - struct sieve_command_registration *cmd_reg) + struct sieve_command_registration *cmd_reg) { /* The order of these is not significant */ sieve_comparators_link_tag(valdtr, cmd_reg, SIEVE_MATCH_OPT_COMPARATOR); sieve_match_types_link_tags(valdtr, cmd_reg, SIEVE_MATCH_OPT_MATCH_TYPE); - + sieve_validator_register_tag - (valdtr, cmd_reg, ext, &body_raw_tag, OPT_BODY_TRANSFORM); + (valdtr, cmd_reg, ext, &body_raw_tag, OPT_BODY_TRANSFORM); sieve_validator_register_tag - (valdtr, cmd_reg, ext, &body_content_tag, OPT_BODY_TRANSFORM); + (valdtr, cmd_reg, ext, &body_content_tag, OPT_BODY_TRANSFORM); sieve_validator_register_tag - (valdtr, cmd_reg, ext, &body_text_tag, OPT_BODY_TRANSFORM); - + (valdtr, cmd_reg, ext, &body_text_tag, OPT_BODY_TRANSFORM); + return TRUE; } -/* - * Validation +/* + * Validation */ - + static bool tst_body_validate -(struct sieve_validator *valdtr, struct sieve_command *tst) -{ +(struct sieve_validator *valdtr, struct sieve_command *tst) +{ struct sieve_ast_argument *arg = tst->first_positional; - const struct sieve_match_type mcht_default = + const struct sieve_match_type mcht_default = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); - const struct sieve_comparator cmp_default = + const struct sieve_comparator cmp_default = SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator); - + if ( !sieve_validate_positional_argument (valdtr, tst, arg, "key list", 1, SAAT_STRING_LIST) ) { return FALSE; @@ -218,9 +218,9 @@ static bool tst_body_validate /* * Code generation */ - + static bool tst_body_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) { (void)sieve_operation_emit(cgenv->sblock, cmd->ext, &body_operation); @@ -229,22 +229,22 @@ static bool tst_body_generate } static bool tag_body_transform_generate -(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, +(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *cmd ATTR_UNUSED) { - enum tst_body_transform transform = + enum tst_body_transform transform = (enum tst_body_transform) arg->argument->data; - + sieve_binary_emit_byte(cgenv->sblock, transform); - sieve_generate_argument_parameters(cgenv, cmd, arg); - + sieve_generate_argument_parameters(cgenv, cmd, arg); + return TRUE; } -/* - * Code dump +/* + * Code dump */ - + static bool ext_body_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) { @@ -258,7 +258,7 @@ static bool ext_body_operation_dump for (;;) { int opt; - if ( (opt=sieve_match_opr_optional_dump(denv, address, &opt_code)) + if ( (opt=sieve_match_opr_optional_dump(denv, address, &opt_code)) < 0 ) return FALSE; @@ -268,7 +268,7 @@ static bool ext_body_operation_dump case OPT_BODY_TRANSFORM: if ( !sieve_binary_read_byte(denv->sblock, address, &transform) ) return FALSE; - + switch ( transform ) { case TST_BODY_TRANSFORM_RAW: sieve_code_dumpf(denv, "BODY-TRANSFORM: RAW"); @@ -278,7 +278,7 @@ static bool ext_body_operation_dump break; case TST_BODY_TRANSFORM_CONTENT: sieve_code_dumpf(denv, "BODY-TRANSFORM: CONTENT"); - + sieve_code_descend(denv); if ( !sieve_opr_stringlist_dump(denv, address, "content types") ) return FALSE; @@ -288,7 +288,7 @@ static bool ext_body_operation_dump return FALSE; } break; - default: + default: return FALSE; } }; @@ -304,9 +304,9 @@ static int ext_body_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) { int opt_code = 0; - struct sieve_comparator cmp = + struct sieve_comparator cmp = SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator); - struct sieve_match_type mcht = + struct sieve_match_type mcht = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); unsigned int transform = TST_BODY_TRANSFORM_TEXT; struct sieve_stringlist *ctype_list, *value_list, *key_list; @@ -317,7 +317,7 @@ static int ext_body_operation_execute /* * Read operands */ - + /* Optional operands */ ctype_list = NULL; @@ -329,7 +329,7 @@ static int ext_body_operation_execute return ret; if ( opt == 0 ) break; - + switch ( opt_code ) { case OPT_BODY_TRANSFORM: if ( !sieve_binary_read_byte(renv->sblock, address, &transform) || @@ -337,8 +337,8 @@ static int ext_body_operation_execute sieve_runtime_trace_error(renv, "invalid body transform type"); return SIEVE_EXEC_BIN_CORRUPT; } - - if ( transform == TST_BODY_TRANSFORM_CONTENT && + + if ( transform == TST_BODY_TRANSFORM_CONTENT && (ret=sieve_opr_stringlist_read (renv, address, "content-type-list", &ctype_list)) <= 0 ) return ret; @@ -349,26 +349,26 @@ static int ext_body_operation_execute sieve_runtime_trace_error(renv, "unknown optional operand"); return SIEVE_EXEC_BIN_CORRUPT; } - } - + } + /* Read key-list */ - if ( (ret=sieve_opr_stringlist_read(renv, address, "key-list", &key_list)) - <= 0 ) + if ( (ret=sieve_opr_stringlist_read(renv, address, "key-list", &key_list)) + <= 0 ) return ret; - + if ( ctype_list != NULL && sieve_stringlist_read_all (ctype_list, pool_datastack_create(), &content_types) < 0 ) { sieve_runtime_trace_error(renv, "failed to read content-type-list operand"); return ctype_list->exec_status; } - + /* * Perform operation */ sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, "body test"); - + /* Extract requested parts */ value_list = ext_body_get_part_list (renv, (enum tst_body_transform) transform, content_types); @@ -379,11 +379,11 @@ static int ext_body_operation_execute mvalues_active = sieve_match_values_set_enabled(renv, FALSE); /* Perform match */ - match = sieve_match(renv, &mcht, &cmp, value_list, key_list, &ret); + match = sieve_match(renv, &mcht, &cmp, value_list, key_list, &ret); - /* Restore match values processing */ + /* Restore match values processing */ (void)sieve_match_values_set_enabled(renv, mvalues_active); - + if ( match < 0 ) return ret; diff --git a/src/lib-sieve/plugins/comparator-i-ascii-numeric/ext-cmp-i-ascii-numeric.c b/src/lib-sieve/plugins/comparator-i-ascii-numeric/ext-cmp-i-ascii-numeric.c index dc1fa746e3b03ed89175b0cb67e01128ba086f09..d51170705f24ceb6f6337245a3df5a1701cfb1f8 100644 --- a/src/lib-sieve/plugins/comparator-i-ascii-numeric/ext-cmp-i-ascii-numeric.c +++ b/src/lib-sieve/plugins/comparator-i-ascii-numeric/ext-cmp-i-ascii-numeric.c @@ -22,27 +22,27 @@ #include <ctype.h> -/* - * Forward declarations +/* + * Forward declarations */ static const struct sieve_operand_def my_comparator_operand; const struct sieve_comparator_def i_ascii_numeric_comparator; -/* +/* * Extension */ static bool ext_cmp_i_ascii_numeric_validator_load (const struct sieve_extension *ext, struct sieve_validator *validator); -const struct sieve_extension_def comparator_i_ascii_numeric_extension = { - "comparator-i;ascii-numeric", +const struct sieve_extension_def comparator_i_ascii_numeric_extension = { + "comparator-i;ascii-numeric", NULL, NULL, ext_cmp_i_ascii_numeric_validator_load, NULL, NULL, NULL, NULL, NULL, - SIEVE_EXT_DEFINE_NO_OPERATIONS, + SIEVE_EXT_DEFINE_NO_OPERATIONS, SIEVE_EXT_DEFINE_OPERAND(my_comparator_operand) }; @@ -59,11 +59,11 @@ static bool ext_cmp_i_ascii_numeric_validator_load static const struct sieve_extension_objects ext_comparators = SIEVE_EXT_DEFINE_COMPARATOR(i_ascii_numeric_comparator); - -static const struct sieve_operand_def my_comparator_operand = { - "comparator-i;ascii-numeric", + +static const struct sieve_operand_def my_comparator_operand = { + "comparator-i;ascii-numeric", &comparator_i_ascii_numeric_extension, - 0, + 0, &sieve_comparator_operand_class, &ext_comparators }; @@ -73,14 +73,14 @@ static const struct sieve_operand_def my_comparator_operand = { */ /* Forward declarations */ - + static int cmp_i_ascii_numeric_compare - (const struct sieve_comparator *cmp, + (const struct sieve_comparator *cmp, const char *val1, size_t val1_size, const char *val2, size_t val2_size); /* Comparator object */ -const struct sieve_comparator_def i_ascii_numeric_comparator = { +const struct sieve_comparator_def i_ascii_numeric_comparator = { SIEVE_OBJECT("i;ascii-numeric", &my_comparator_operand, 0), SIEVE_COMPARATOR_FLAG_ORDERING | SIEVE_COMPARATOR_FLAG_EQUALITY, cmp_i_ascii_numeric_compare, @@ -91,16 +91,16 @@ const struct sieve_comparator_def i_ascii_numeric_comparator = { /* Comparator implementation */ static int cmp_i_ascii_numeric_compare - (const struct sieve_comparator *cmp ATTR_UNUSED, + (const struct sieve_comparator *cmp ATTR_UNUSED, const char *val, size_t val_size, const char *key, size_t key_size) -{ +{ const char *vend = val + val_size; const char *kend = key + key_size; const char *vp = val; const char *kp = key; int digits, i; - /* RFC 4790: All input is valid; strings that do not start with a digit + /* RFC 4790: All input is valid; strings that do not start with a digit * represent positive infinity. */ if ( !i_isdigit(*vp) ) { @@ -114,13 +114,13 @@ static int cmp_i_ascii_numeric_compare return -1; } } - + /* Ignore leading zeros */ - while ( *vp == '0' && vp < vend ) + while ( *vp == '0' && vp < vend ) vp++; - while ( *kp == '0' && kp < kend ) + while ( *kp == '0' && kp < kend ) kp++; /* Check whether both numbers are equally long in terms of digits */ @@ -129,7 +129,7 @@ static int cmp_i_ascii_numeric_compare while ( vp < vend && kp < kend && i_isdigit(*vp) && i_isdigit(*kp) ) { vp++; kp++; - digits++; + digits++; } if ( vp == vend || !i_isdigit(*vp) ) { @@ -138,7 +138,7 @@ static int cmp_i_ascii_numeric_compare return -1; } } else { - /* Value is greater */ + /* Value is greater */ return 1; } @@ -157,7 +157,7 @@ static int cmp_i_ascii_numeric_compare vp++; i++; } - + return 0; } diff --git a/src/lib-sieve/plugins/copy/Makefile.am b/src/lib-sieve/plugins/copy/Makefile.am index 5e64796400d66741545622d6b4e130ee3c815966..483032a4272c85633ec91f6454b5ca47f0a86a3c 100644 --- a/src/lib-sieve/plugins/copy/Makefile.am +++ b/src/lib-sieve/plugins/copy/Makefile.am @@ -8,7 +8,7 @@ libsieve_ext_copy_la_SOURCES = \ ext-copy.c public_headers = \ - sieve-ext-copy.h + sieve-ext-copy.h headers = diff --git a/src/lib-sieve/plugins/copy/ext-copy.c b/src/lib-sieve/plugins/copy/ext-copy.c index f1d73eac2349470e510ec710e3825b796b418de7..dc057238d14d33b4ee89c3883e130b2d4aa9572e 100644 --- a/src/lib-sieve/plugins/copy/ext-copy.c +++ b/src/lib-sieve/plugins/copy/ext-copy.c @@ -31,17 +31,17 @@ static const struct sieve_argument_def copy_tag; static const struct sieve_operand_def copy_side_effect_operand; -/* +/* * Extension */ static bool ext_copy_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr); -const struct sieve_extension_def copy_extension = { - "copy", +const struct sieve_extension_def copy_extension = { + "copy", NULL, NULL, - ext_copy_validator_load, + ext_copy_validator_load, NULL, NULL, NULL, NULL, NULL, SIEVE_EXT_DEFINE_NO_OPERATIONS, SIEVE_EXT_DEFINE_OPERAND(copy_side_effect_operand) @@ -52,7 +52,7 @@ static bool ext_copy_validator_load { /* Register copy tag with redirect and fileinto commands and we don't care * whether these commands are registered or even whether they will be - * registered at all. The validator handles either situation gracefully + * registered at all. The validator handles either situation gracefully */ sieve_validator_register_external_tag (valdtr, "redirect", ext, ©_tag, SIEVE_OPT_SIDE_EFFECT); @@ -63,14 +63,14 @@ static bool ext_copy_validator_load } /* - * Side effect + * Side effect */ static void seff_copy_print - (const struct sieve_side_effect *seffect, const struct sieve_action *action, + (const struct sieve_side_effect *seffect, const struct sieve_action *action, const struct sieve_result_print_env *rpenv, bool *keep); static void seff_copy_post_commit - (const struct sieve_side_effect *seffect, const struct sieve_action *action, + (const struct sieve_side_effect *seffect, const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void *tr_context, bool *keep); const struct sieve_side_effect_def copy_side_effect = { @@ -79,25 +79,25 @@ const struct sieve_side_effect_def copy_side_effect = { NULL, NULL, NULL, seff_copy_print, NULL, NULL, - seff_copy_post_commit, + seff_copy_post_commit, NULL }; -/* - * Tagged argument +/* + * Tagged argument */ static bool tag_copy_validate - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); static bool tag_copy_generate (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *cmd); -static const struct sieve_argument_def copy_tag = { - "copy", +static const struct sieve_argument_def copy_tag = { + "copy", NULL, - tag_copy_validate, + tag_copy_validate, NULL, NULL, tag_copy_generate }; @@ -131,13 +131,13 @@ void sieve_ext_copy_register_tag } } -/* - * Tag validation +/* + * Tag validation */ static bool tag_copy_validate - (struct sieve_validator *valdtr ATTR_UNUSED, - struct sieve_ast_argument **arg ATTR_UNUSED, + (struct sieve_validator *valdtr ATTR_UNUSED, + struct sieve_ast_argument **arg ATTR_UNUSED, struct sieve_command *cmd ATTR_UNUSED) { *arg = sieve_ast_argument_next(*arg); @@ -146,7 +146,7 @@ static bool tag_copy_validate } /* - * Code generation + * Code generation */ static bool tag_copy_generate @@ -163,13 +163,13 @@ static bool tag_copy_generate return TRUE; } -/* +/* * Side effect implementation */ static void seff_copy_print -(const struct sieve_side_effect *seffect ATTR_UNUSED, - const struct sieve_action *action ATTR_UNUSED, +(const struct sieve_side_effect *seffect ATTR_UNUSED, + const struct sieve_action *action ATTR_UNUSED, const struct sieve_result_print_env *rpenv, bool *keep) { sieve_result_seffect_printf(rpenv, "preserve implicit keep"); @@ -178,11 +178,11 @@ static void seff_copy_print } static void seff_copy_post_commit -(const struct sieve_side_effect *seffect ATTR_UNUSED, - const struct sieve_action *action ATTR_UNUSED, - const struct sieve_action_exec_env *aenv ATTR_UNUSED, +(const struct sieve_side_effect *seffect ATTR_UNUSED, + const struct sieve_action *action ATTR_UNUSED, + const struct sieve_action_exec_env *aenv ATTR_UNUSED, void *tr_context ATTR_UNUSED, bool *keep) -{ +{ *keep = TRUE; } diff --git a/src/lib-sieve/plugins/date/ext-date-common.c b/src/lib-sieve/plugins/date/ext-date-common.c index b2e236311c65ba3b7800feda825a4d5be6e1959c..936b24c53f2d2f1359170b233e76775b0cc9c435 100644 --- a/src/lib-sieve/plugins/date/ext-date-common.c +++ b/src/lib-sieve/plugins/date/ext-date-common.c @@ -27,7 +27,7 @@ struct ext_date_context { */ static void ext_date_runtime_init -(const struct sieve_extension *ext, const struct sieve_runtime_env *renv, +(const struct sieve_extension *ext, const struct sieve_runtime_env *renv, void *context ATTR_UNUSED) { struct ext_date_context *dctx; @@ -37,7 +37,7 @@ static void ext_date_runtime_init int zone_offset; /* Get current time at instance main script is started */ - time(¤t_date); + time(¤t_date); tm = localtime(¤t_date); zone_offset = utc_offset(tm, current_date); @@ -61,7 +61,7 @@ static struct sieve_interpreter_extension date_interpreter_extension = { bool ext_date_interpreter_load (const struct sieve_extension *ext, const struct sieve_runtime_env *renv, sieve_size_t *address ATTR_UNUSED) -{ +{ /* Register runtime hook to obtain stript start timestamp */ if ( renv->msgctx == NULL || sieve_message_context_extension_get(renv->msgctx, ext) == NULL ) { @@ -92,7 +92,7 @@ bool ext_date_parse_timezone offset = ((str[1]-'0') * 10 + (str[2]-'0')) * 60 + (str[3]-'0') * 10 + (str[4]-'0'); - if ( zone_offset_r != NULL ) + if ( zone_offset_r != NULL ) *zone_offset_r = *str == '+' ? offset : -offset; return TRUE; @@ -107,14 +107,14 @@ bool ext_date_parse_timezone time_t ext_date_get_current_date (const struct sieve_runtime_env *renv, int *zone_offset_r) -{ +{ const struct sieve_extension *this_ext = renv->oprtn->ext; - struct ext_date_context *dctx = (struct ext_date_context *) + struct ext_date_context *dctx = (struct ext_date_context *) sieve_message_context_extension_get(renv->msgctx, this_ext); if ( dctx == NULL ) { ext_date_runtime_init(this_ext, renv, NULL); - dctx = (struct ext_date_context *) + dctx = (struct ext_date_context *) sieve_message_context_extension_get(renv->msgctx, this_ext); i_assert(dctx != NULL); @@ -128,11 +128,11 @@ time_t ext_date_get_current_date return dctx->current_date; } -/* - * Date parts +/* + * Date parts */ -/* "year" => the year, "0000" .. "9999". +/* "year" => the year, "0000" .. "9999". */ static const char *ext_date_year_part_get(struct tm *tm, int zone_offset); @@ -179,7 +179,7 @@ static const struct ext_date_part date_date_part = { * Julian Day minus 2400000.5. Sample routines to * convert to and from modified Julian dates are * given in Appendix A. - */ + */ static const char *ext_date_julian_part_get(struct tm *tm, int zone_offset); @@ -188,7 +188,7 @@ static const struct ext_date_part julian_date_part = { ext_date_julian_part_get }; -/* "hour" => the hour, "00" .. "23". +/* "hour" => the hour, "00" .. "23". */ static const char *ext_date_hour_part_get(struct tm *tm, int zone_offset); @@ -258,7 +258,7 @@ static const struct ext_date_part zone_date_part = { "zone", ext_date_zone_part_get }; - + /* "weekday" => the day of the week expressed as an integer between * "0" and "6". "0" is Sunday, "1" is Monday, etc. */ @@ -276,8 +276,8 @@ static const struct ext_date_part weekday_date_part = { static const struct ext_date_part *date_parts[] = { &year_date_part, &month_date_part, &day_date_part, &date_date_part, &julian_date_part, &hour_date_part, &minute_date_part, &second_date_part, - &time_date_part, &iso8601_date_part, &std11_date_part, &zone_date_part, - &weekday_date_part + &time_date_part, &iso8601_date_part, &std11_date_part, &zone_date_part, + &weekday_date_part }; unsigned int date_parts_count = N_ELEMENTS(date_parts); @@ -295,7 +295,7 @@ const char *ext_date_part_extract return NULL; } } - + return NULL; } @@ -333,7 +333,7 @@ static const char *ext_date_day_part_get static const char *ext_date_date_part_get (struct tm *tm, int zone_offset ATTR_UNUSED) { - return t_strdup_printf("%04d-%02d-%02d", + return t_strdup_printf("%04d-%02d-%02d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday); } @@ -344,8 +344,8 @@ static const char *ext_date_julian_part_get int month = tm->tm_mon+1; int day = tm->tm_mday; int c, ya, jd; - - /* Modified from RFC 5260 Appendix A */ + + /* Modified from RFC 5260 Appendix A */ if ( month > 2 ) month -= 3; @@ -358,7 +358,7 @@ static const char *ext_date_julian_part_get ya = year - c * 100; jd = c * 146097 / 4 + ya * 1461 / 4 + (month * 153 + 2) / 5 + day + 1721119; - + return t_strdup_printf("%d", jd - 2400001); } @@ -391,13 +391,13 @@ static const char *ext_date_iso8601_part_get { const char *time_offset; - /* + /* * RFC 3339: 5.6. Internet Date/Time Format - * + * * The following profile of ISO 8601 [ISO8601] dates SHOULD be used in * new protocols on the Internet. This is specified using the syntax * description notation defined in [ABNF]. - * + * * date-fullyear = 4DIGIT * date-month = 2DIGIT ; 01-12 * date-mday = 2DIGIT ; 01-28, 01-29, 01-30, 01-31 based on @@ -409,14 +409,14 @@ static const char *ext_date_iso8601_part_get * time-secfrac = "." 1*DIGIT * time-numoffset = ("+" / "-") time-hour ":" time-minute * time-offset = "Z" / time-numoffset - * + * * partial-time = time-hour ":" time-minute ":" time-second * [time-secfrac] * full-date = date-fullyear "-" date-month "-" date-mday * full-time = partial-time time-offset - * + * * date-time = full-date "T" full-time - * + * */ if ( zone_offset == 0 ) @@ -429,8 +429,8 @@ static const char *ext_date_iso8601_part_get } return t_strdup_printf("%04d-%02d-%02dT%02d:%02d:%02d%s", - tm->tm_year + 1900, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, - tm->tm_sec, time_offset); + tm->tm_year + 1900, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, + tm->tm_sec, time_offset); } static const char *ext_date_std11_part_get @@ -441,7 +441,7 @@ static const char *ext_date_std11_part_get tm->tm_mday, month_names[tm->tm_mon], tm->tm_year+1900, - tm->tm_hour, tm->tm_min, tm->tm_sec, + tm->tm_hour, tm->tm_min, tm->tm_sec, ext_date_zone_part_get(tm, zone_offset)); } @@ -484,7 +484,7 @@ static void ext_date_stringlist_reset struct ext_date_stringlist { struct sieve_stringlist strlist; - struct sieve_stringlist *field_values; + struct sieve_stringlist *field_values; int time_zone; const char *date_part; @@ -499,7 +499,7 @@ struct sieve_stringlist *ext_date_stringlist_create int time_zone, const char *date_part) { struct ext_date_stringlist *strlist; - + strlist = t_new(struct ext_date_stringlist, 1); strlist->strlist.runenv = renv; strlist->strlist.exec_status = SIEVE_EXEC_OK; @@ -508,7 +508,7 @@ struct sieve_stringlist *ext_date_stringlist_create strlist->field_values = field_values; strlist->time_zone = time_zone; strlist->date_part = date_part; - + strlist->local_time = ext_date_get_current_date(renv, &strlist->local_zone); return &strlist->strlist; @@ -519,7 +519,7 @@ struct sieve_stringlist *ext_date_stringlist_create static int ext_date_stringlist_next_item (struct sieve_stringlist *_strlist, string_t **str_r) { - struct ext_date_stringlist *strlist = + struct ext_date_stringlist *strlist = (struct ext_date_stringlist *) _strlist; bool got_date = FALSE; time_t date_value; @@ -551,7 +551,7 @@ static int ext_date_stringlist_next_item date_string = header_value; } else { /* Delimited by ';', e.g. a Received: header */ - date_string++; + date_string++; } /* Parse the date value */ @@ -596,7 +596,7 @@ static int ext_date_stringlist_next_item strlist->read = TRUE; - if ( part_value == NULL ) + if ( part_value == NULL ) return 0; *str_r = t_str_new_const(part_value, strlen(part_value)); @@ -606,7 +606,7 @@ static int ext_date_stringlist_next_item static void ext_date_stringlist_reset (struct sieve_stringlist *_strlist) { - struct ext_date_stringlist *strlist = + struct ext_date_stringlist *strlist = (struct ext_date_stringlist *) _strlist; if ( strlist->field_values != NULL ) diff --git a/src/lib-sieve/plugins/date/ext-date-common.h b/src/lib-sieve/plugins/date/ext-date-common.h index b0592e3da9c046be6ff4a1d3883c8b7ba376dd45..918d9f57cd5a25c35cab0f536505f455ed2f7f15 100644 --- a/src/lib-sieve/plugins/date/ext-date-common.h +++ b/src/lib-sieve/plugins/date/ext-date-common.h @@ -1,6 +1,6 @@ /* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #ifndef __EXT_DATE_COMMON_H #define __EXT_DATE_COMMON_H @@ -11,20 +11,20 @@ /* * Extension */ - + extern const struct sieve_extension_def date_extension; bool ext_date_interpreter_load (const struct sieve_extension *ext, const struct sieve_runtime_env *renv, sieve_size_t *address ATTR_UNUSED); -/* +/* * Tests */ extern const struct sieve_command_def date_test; extern const struct sieve_command_def currentdate_test; - + /* * Operations */ diff --git a/src/lib-sieve/plugins/date/ext-date.c b/src/lib-sieve/plugins/date/ext-date.c index f4b4af04f2c91019a373d372581337c3b642a40c..f69ca4e649b5bf0f079777f494be72d04788d3b4 100644 --- a/src/lib-sieve/plugins/date/ext-date.c +++ b/src/lib-sieve/plugins/date/ext-date.c @@ -30,8 +30,8 @@ #include "ext-date-common.h" -/* - * Extension +/* + * Extension */ static bool ext_date_validator_load @@ -42,14 +42,14 @@ const struct sieve_operation_def *ext_date_operations[] = { ¤tdate_operation }; -const struct sieve_extension_def date_extension = { - "date", +const struct sieve_extension_def date_extension = { + "date", NULL, NULL, - ext_date_validator_load, - NULL, - ext_date_interpreter_load, + ext_date_validator_load, + NULL, + ext_date_interpreter_load, NULL, NULL, NULL, - SIEVE_EXT_DEFINE_OPERATIONS(ext_date_operations), + SIEVE_EXT_DEFINE_OPERATIONS(ext_date_operations), SIEVE_EXT_DEFINE_NO_OPERANDS }; diff --git a/src/lib-sieve/plugins/date/tst-date.c b/src/lib-sieve/plugins/date/tst-date.c index 9d8816798ef2d2171880c391a84a1dd9c2d50c3b..d84581276991902a2be11dede2928563380dfa94 100644 --- a/src/lib-sieve/plugins/date/tst-date.c +++ b/src/lib-sieve/plugins/date/tst-date.c @@ -29,7 +29,7 @@ static bool tst_date_validate (struct sieve_validator *valdtr, struct sieve_command *tst); static bool tst_date_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx); - + /* Date test * * Syntax: @@ -42,20 +42,20 @@ static bool tst_date_registered (struct sieve_validator *valdtr, const struct sieve_extension *ext, struct sieve_command_registration *cmd_reg); -const struct sieve_command_def date_test = { - "date", - SCT_TEST, +const struct sieve_command_def date_test = { + "date", + SCT_TEST, 3, 0, FALSE, FALSE, tst_date_registered, - NULL, + NULL, tst_date_validate, - NULL, - tst_date_generate, - NULL + NULL, + tst_date_generate, + NULL }; /* Currentdate test - * + * * Syntax: * currentdate [":zone" <time-zone: string>] * [COMPARATOR] [MATCH-TYPE] @@ -66,20 +66,20 @@ static bool tst_currentdate_registered (struct sieve_validator *valdtr, const struct sieve_extension *ext, struct sieve_command_registration *cmd_reg); -const struct sieve_command_def currentdate_test = { - "currentdate", - SCT_TEST, +const struct sieve_command_def currentdate_test = { + "currentdate", + SCT_TEST, 2, 0, FALSE, FALSE, tst_currentdate_registered, - NULL, + NULL, tst_date_validate, NULL, - tst_date_generate, - NULL + tst_date_generate, + NULL }; -/* - * Tagged arguments +/* + * Tagged arguments */ /* Forward declarations */ @@ -109,8 +109,8 @@ static const struct sieve_argument_def date_originalzone_tag = { tag_zone_generate }; -/* - * Date operation +/* + * Date operation */ static bool tst_date_operation_dump @@ -118,20 +118,20 @@ static bool tst_date_operation_dump static int tst_date_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def date_operation = { +const struct sieve_operation_def date_operation = { "DATE", &date_extension, EXT_DATE_OPERATION_DATE, - tst_date_operation_dump, - tst_date_operation_execute + tst_date_operation_dump, + tst_date_operation_execute }; -const struct sieve_operation_def currentdate_operation = { +const struct sieve_operation_def currentdate_operation = { "CURRENTDATE", &date_extension, EXT_DATE_OPERATION_CURRENTDATE, - tst_date_operation_dump, - tst_date_operation_execute + tst_date_operation_dump, + tst_date_operation_execute }; /* @@ -182,31 +182,31 @@ static bool tag_zone_validate /* Check it */ if ( sieve_argument_is_string_literal(*arg) ) { const char *zone = sieve_ast_argument_strc(*arg); - + if ( !ext_date_parse_timezone(zone, NULL) ) { sieve_argument_validate_warning(valdtr, *arg, "specified :zone argument '%s' is not a valid timezone", str_sanitize(zone, 40)); - } + } } - + /* Assign tag parameters */ tag->parameters = *arg; *arg = sieve_ast_arguments_detach(*arg,1); - } + } cmd->data = (void *) TRUE; return TRUE; } -/* - * Test registration +/* + * Test registration */ static bool tst_date_registered (struct sieve_validator *valdtr, const struct sieve_extension *ext, - struct sieve_command_registration *cmd_reg) + struct sieve_command_registration *cmd_reg) { sieve_comparators_link_tag(valdtr, cmd_reg, SIEVE_MATCH_OPT_COMPARATOR); sieve_match_types_link_tags(valdtr, cmd_reg, SIEVE_MATCH_OPT_MATCH_TYPE); @@ -221,7 +221,7 @@ static bool tst_date_registered static bool tst_currentdate_registered (struct sieve_validator *valdtr, const struct sieve_extension *ext, - struct sieve_command_registration *cmd_reg) + struct sieve_command_registration *cmd_reg) { sieve_comparators_link_tag(valdtr, cmd_reg, SIEVE_MATCH_OPT_COMPARATOR); sieve_match_types_link_tags(valdtr, cmd_reg, SIEVE_MATCH_OPT_MATCH_TYPE); @@ -232,20 +232,20 @@ static bool tst_currentdate_registered return TRUE; } -/* - * Validation +/* + * Validation */ - + static bool tst_date_validate -(struct sieve_validator *valdtr, struct sieve_command *tst) +(struct sieve_validator *valdtr, struct sieve_command *tst) { struct sieve_ast_argument *arg = tst->first_positional; unsigned int arg_offset = 0 ; - const struct sieve_match_type mcht_default = + const struct sieve_match_type mcht_default = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); - const struct sieve_comparator cmp_default = + const struct sieve_comparator cmp_default = SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator); - + /* Check header name */ if ( sieve_command_is(tst, date_test) ) { @@ -255,7 +255,7 @@ static bool tst_date_validate (valdtr, tst, arg, "header name", 1, SAAT_STRING) ) { return FALSE; } - + if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) ) return FALSE; @@ -271,14 +271,14 @@ static bool tst_date_validate (valdtr, tst, arg, "date part", arg_offset + 1, SAAT_STRING) ) { return FALSE; } - + if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) ) return FALSE; arg = sieve_ast_argument_next(arg); /* Check key list */ - + if ( !sieve_validate_positional_argument (valdtr, tst, arg, "key list", arg_offset + 2, SAAT_STRING_LIST) ) { return FALSE; @@ -286,18 +286,18 @@ static bool tst_date_validate if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) ) return FALSE; - + /* Validate the key argument to a specified match type */ return sieve_match_type_validate - (valdtr, tst, arg, &mcht_default, &cmp_default); + (valdtr, tst, arg, &mcht_default, &cmp_default); } -/* - * Code generation +/* + * Code generation */ static bool tst_date_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *tst) +(const struct sieve_codegen_env *cgenv, struct sieve_command *tst) { if ( sieve_command_is(tst, date_test) ) sieve_operation_emit(cgenv->sblock, tst->ext, &date_operation); @@ -306,7 +306,7 @@ static bool tst_date_generate else i_unreached(); - /* Generate arguments */ + /* Generate arguments */ return sieve_generate_arguments(cgenv, tst, NULL); } @@ -322,8 +322,8 @@ static bool tag_zone_generate return sieve_generate_argument_parameters(cgenv, cmd, arg); } -/* - * Code dump +/* + * Code dump */ static bool tst_date_operation_dump @@ -334,7 +334,7 @@ static bool tst_date_operation_dump sieve_code_dumpf(denv, "%s", sieve_operation_mnemonic(op)); sieve_code_descend(denv); - + /* Handle any optional arguments */ for (;;) { int opt; @@ -352,30 +352,30 @@ static bool tst_date_operation_dump default: return FALSE; } - } + } if ( sieve_operation_is(op, date_operation) && !sieve_opr_string_dump(denv, address, "header name") ) return FALSE; return - sieve_opr_string_dump(denv, address, "date part") && + sieve_opr_string_dump(denv, address, "date part") && sieve_opr_stringlist_dump(denv, address, "key list"); } -/* - * Code execution +/* + * Code execution */ static int tst_date_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) -{ +{ const struct sieve_operation *op = renv->oprtn; int opt_code = 0; - struct sieve_match_type mcht = + struct sieve_match_type mcht = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); - struct sieve_comparator cmp = + struct sieve_comparator cmp = SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator); string_t *date_part = NULL, *zone = NULL; struct sieve_stringlist *hdr_list = NULL, *hdr_value_list; @@ -383,7 +383,7 @@ static int tst_date_operation_execute bool zone_specified = FALSE, zone_literal = TRUE; int time_zone; int match, ret; - + /* Read optional operands */ for (;;) { int opt; @@ -393,7 +393,7 @@ static int tst_date_operation_execute return ret; if ( opt == 0 ) break; - + switch ( opt_code ) { case OPT_DATE_ZONE: if ( (ret=sieve_opr_string_read_ex @@ -406,7 +406,7 @@ static int tst_date_operation_execute sieve_runtime_trace_error(renv, "unknown optional operand"); return SIEVE_EXEC_BIN_CORRUPT; } - } + } if ( sieve_operation_is(op, date_operation) ) { /* Read header name as stringlist */ @@ -416,7 +416,7 @@ static int tst_date_operation_execute } /* Read date part */ - if ( (ret=sieve_opr_string_read(renv, address, "date-part", &date_part)) + if ( (ret=sieve_opr_string_read(renv, address, "date-part", &date_part)) <= 0 ) return ret; @@ -432,14 +432,14 @@ static int tst_date_operation_execute time_zone = EXT_DATE_TIMEZONE_ORIGINAL; } else if ( !ext_date_parse_timezone(str_c(zone), &time_zone) ) { if ( !zone_literal ) - sieve_runtime_warning(renv, NULL, + sieve_runtime_warning(renv, NULL, "specified :zone argument '%s' is not a valid timezone " "(using local zone)", str_sanitize(str_c(zone), 40)); time_zone = EXT_DATE_TIMEZONE_LOCAL; } /* - * Perform test + * Perform test */ if ( sieve_operation_is(op, date_operation) ) { @@ -465,7 +465,7 @@ static int tst_date_operation_execute /* Perform match */ if ( (match=sieve_match(renv, &mcht, &cmp, value_list, key_list, &ret)) < 0 ) - return ret; + return ret; /* Set test result for subsequent conditional jump */ sieve_interpreter_set_test_result(renv->interp, match > 0); diff --git a/src/lib-sieve/plugins/editheader/cmd-addheader.c b/src/lib-sieve/plugins/editheader/cmd-addheader.c index e17780f9bdc691ffce74aad36e28653b3694ffa5..ccda1fccb256b33600d4cdecdc98aca66a44f2a5 100644 --- a/src/lib-sieve/plugins/editheader/cmd-addheader.c +++ b/src/lib-sieve/plugins/editheader/cmd-addheader.c @@ -54,8 +54,8 @@ const struct sieve_command_def addheader_command = { /* Argument objects */ -static const struct sieve_argument_def addheader_last_tag = { - "last", +static const struct sieve_argument_def addheader_last_tag = { + "last", NULL, NULL, NULL, NULL, NULL }; @@ -101,7 +101,7 @@ static bool cmd_addheader_validate if ( !sieve_validator_argument_activate(valdtr, cmd, arg, FALSE) ) return FALSE; - + if ( sieve_argument_is_string_literal(arg) ) { string_t *fname = sieve_ast_argument_str(arg); @@ -153,8 +153,8 @@ static bool cmd_addheader_validate return TRUE; } -/* - * Command registration +/* + * Command registration */ static bool cmd_addheader_registered @@ -202,14 +202,14 @@ static bool cmd_addheader_operation_dump if ( opt == 0 ) break; if ( opt_code == OPT_LAST ) { - sieve_code_dumpf(denv, "last"); + sieve_code_dumpf(denv, "last"); } else { return FALSE; } } return - sieve_opr_string_dump(denv, address, "field-name") && + sieve_opr_string_dump(denv, address, "field-name") && sieve_opr_string_dump(denv, address, "value"); } @@ -273,14 +273,14 @@ static int cmd_addheader_operation_execute str_sanitize(str_c(field_name), 80)); return SIEVE_EXEC_FAILURE; } - + if ( ext_editheader_header_is_protected(this_ext, str_c(field_name)) ) { sieve_runtime_warning(renv, NULL, "addheader action: " "specified header field `%s' is protected; modification denied", str_sanitize(str_c(field_name), 80)); return SIEVE_EXEC_OK; } - + if ( !rfc2822_header_field_body_verify (str_c(value), str_len(value), TRUE, TRUE) ) { sieve_runtime_error(renv, NULL, "addheader action: " diff --git a/src/lib-sieve/plugins/editheader/cmd-deleteheader.c b/src/lib-sieve/plugins/editheader/cmd-deleteheader.c index 7ddfbfc02e29dd7d5c3e36bf70dca0c2871f23c9..90066776dcbd8b2b78900f56a137d3a91aeeea03 100644 --- a/src/lib-sieve/plugins/editheader/cmd-deleteheader.c +++ b/src/lib-sieve/plugins/editheader/cmd-deleteheader.c @@ -23,7 +23,7 @@ #include "ext-editheader-common.h" -/* +/* * Deleteheader command * * Syntax: @@ -40,17 +40,17 @@ static bool cmd_deleteheader_validate static bool cmd_deleteheader_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd); -const struct sieve_command_def deleteheader_command = { - "deleteheader", +const struct sieve_command_def deleteheader_command = { + "deleteheader", SCT_COMMAND, - -1, /* We check positional arguments ourselves */ + -1, /* We check positional arguments ourselves */ 0, FALSE, FALSE, - cmd_deleteheader_registered, + cmd_deleteheader_registered, NULL, cmd_deleteheader_validate, NULL, - cmd_deleteheader_generate, - NULL + cmd_deleteheader_generate, + NULL }; /* @@ -60,23 +60,23 @@ const struct sieve_command_def deleteheader_command = { /* Forward declarations */ static bool cmd_deleteheader_validate_index_tag - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); static bool cmd_deleteheader_validate_last_tag - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); /* Argument objects */ -static const struct sieve_argument_def deleteheader_index_tag = { - "index", +static const struct sieve_argument_def deleteheader_index_tag = { + "index", NULL, cmd_deleteheader_validate_index_tag, NULL, NULL, NULL }; -static const struct sieve_argument_def deleteheader_last_tag = { - "last", +static const struct sieve_argument_def deleteheader_last_tag = { + "last", NULL, cmd_deleteheader_validate_last_tag, NULL, NULL, NULL @@ -89,8 +89,8 @@ enum cmd_deleteheader_optional { OPT_LAST }; -/* - * Deleteheader operation +/* + * Deleteheader operation */ static bool cmd_deleteheader_operation_dump @@ -98,21 +98,21 @@ static bool cmd_deleteheader_operation_dump static int cmd_deleteheader_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def deleteheader_operation = { +const struct sieve_operation_def deleteheader_operation = { "DELETEHEADER", &editheader_extension, EXT_EDITHEADER_OPERATION_DELETEHEADER, - cmd_deleteheader_operation_dump, - cmd_deleteheader_operation_execute + cmd_deleteheader_operation_dump, + cmd_deleteheader_operation_execute }; -/* - * Command registration +/* + * Command registration */ static bool cmd_deleteheader_registered -(struct sieve_validator *valdtr, const struct sieve_extension *ext ATTR_UNUSED, - struct sieve_command_registration *cmd_reg) +(struct sieve_validator *valdtr, const struct sieve_extension *ext ATTR_UNUSED, + struct sieve_command_registration *cmd_reg) { /* The order of these is not significant */ sieve_comparators_link_tag(valdtr, cmd_reg, SIEVE_MATCH_OPT_COMPARATOR); @@ -129,14 +129,14 @@ static bool cmd_deleteheader_registered /* * Command validation context */ - + struct cmd_deleteheader_context_data { struct sieve_ast_argument *arg_index; struct sieve_ast_argument *arg_last; }; -/* - * Tag validation +/* + * Tag validation */ static struct cmd_deleteheader_context_data * @@ -156,16 +156,16 @@ cmd_deleteheader_get_context } static bool cmd_deleteheader_validate_index_tag -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd) { struct sieve_ast_argument *tag = *arg; struct cmd_deleteheader_context_data *ctx_data; sieve_number_t index; - + /* Detach the tag itself */ *arg = sieve_ast_arguments_detach(*arg,1); - + /* Check syntax: * :index number */ @@ -189,45 +189,45 @@ static bool cmd_deleteheader_validate_index_tag /* Skip parameter */ *arg = sieve_ast_argument_next(*arg); - + return TRUE; } static bool cmd_deleteheader_validate_last_tag -(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_ast_argument **arg, struct sieve_command *cmd) { struct cmd_deleteheader_context_data *ctx_data; - + ctx_data = cmd_deleteheader_get_context(cmd); ctx_data->arg_last = *arg; /* Skip parameter */ *arg = sieve_ast_argument_next(*arg); - + return TRUE; } -/* - * Validation +/* + * Validation */ - + static bool cmd_deleteheader_validate -(struct sieve_validator *valdtr, struct sieve_command *cmd) -{ +(struct sieve_validator *valdtr, struct sieve_command *cmd) +{ struct sieve_ast_argument *arg = cmd->first_positional; struct cmd_deleteheader_context_data *ctx_data = (struct cmd_deleteheader_context_data *)cmd->data; - struct sieve_comparator cmp_default = + struct sieve_comparator cmp_default = SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator); - struct sieve_match_type mcht_default = + struct sieve_match_type mcht_default = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); if ( ctx_data != NULL ) { if ( ctx_data->arg_last != NULL && ctx_data->arg_index == NULL ) { - sieve_argument_validate_error(valdtr, ctx_data->arg_last, + sieve_argument_validate_error(valdtr, ctx_data->arg_last, "the :last tag for the %s %s cannot be specified " - "without the :index tag", + "without the :index tag", sieve_command_identifier(cmd), sieve_command_type_name(cmd)); } } @@ -235,17 +235,17 @@ static bool cmd_deleteheader_validate /* Field name argument */ if ( arg == NULL ) { - sieve_command_validate_error(valdtr, cmd, - "the %s %s expects at least one positional argument, but none was found", + sieve_command_validate_error(valdtr, cmd, + "the %s %s expects at least one positional argument, but none was found", sieve_command_identifier(cmd), sieve_command_type_name(cmd)); return FALSE; } - + if ( !sieve_validate_positional_argument (valdtr, cmd, arg, "field name", 1, SAAT_STRING_LIST) ) { return FALSE; } - + if ( !sieve_validator_argument_activate(valdtr, cmd, arg, FALSE) ) return FALSE; @@ -265,7 +265,7 @@ static bool cmd_deleteheader_validate "modification will be denied", str_sanitize(str_c(fname), 80)); } } - + /* Value patterns argument */ arg = sieve_ast_argument_next(arg); @@ -280,7 +280,7 @@ static bool cmd_deleteheader_validate (valdtr, cmd, arg, "value patterns", 2, SAAT_STRING_LIST) ) { return FALSE; } - + if ( !sieve_validator_argument_activate(valdtr, cmd, arg, FALSE) ) return FALSE; @@ -290,11 +290,11 @@ static bool cmd_deleteheader_validate } /* - * Code generation + * Code generation */ static bool cmd_deleteheader_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) { sieve_operation_emit(cgenv->sblock, cmd->ext, &deleteheader_operation); @@ -309,8 +309,8 @@ static bool cmd_deleteheader_generate return TRUE; } -/* - * Code dump +/* + * Code dump */ static bool cmd_deleteheader_operation_dump @@ -337,20 +337,20 @@ static bool cmd_deleteheader_operation_dump break; case OPT_LAST: sieve_code_dumpf(denv, "last"); - break; - default: + break; + default: return FALSE; } }; - + if ( !sieve_opr_string_dump(denv, address, "field name") ) return FALSE; return sieve_opr_stringlist_dump_ex(denv, address, "value patterns", ""); } -/* - * Code execution +/* + * Code execution */ static int cmd_deleteheader_operation_execute @@ -358,9 +358,9 @@ static int cmd_deleteheader_operation_execute { const struct sieve_extension *this_ext = renv->oprtn->ext; int opt_code = 0; - struct sieve_comparator cmp = + struct sieve_comparator cmp = SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator); - struct sieve_match_type mcht = + struct sieve_match_type mcht = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); string_t *field_name; struct sieve_stringlist *vpattern_list = NULL; @@ -369,8 +369,8 @@ static int cmd_deleteheader_operation_execute bool index_last = FALSE; bool trace = FALSE; int ret; - - /* + + /* * Read operands */ @@ -382,13 +382,13 @@ static int cmd_deleteheader_operation_execute return ret; if ( opt == 0 ) break; - + switch ( opt_code ) { case OPT_INDEX: if ( (ret=sieve_opr_number_read(renv, address, "index", &index_offset)) <= 0 ) return ret; - + if ( index_offset > INT_MAX ) { sieve_runtime_trace_error(renv, "index is > %d", INT_MAX); return SIEVE_EXEC_BIN_CORRUPT; @@ -402,10 +402,10 @@ static int cmd_deleteheader_operation_execute sieve_runtime_trace_error(renv, "unknown optional operand"); return SIEVE_EXEC_BIN_CORRUPT; } - } - + } + /* Read field-name */ - if ( (ret=sieve_opr_string_read(renv, address, "field-name", &field_name)) + if ( (ret=sieve_opr_string_read(renv, address, "field-name", &field_name)) <= 0 ) return ret; @@ -413,7 +413,7 @@ static int cmd_deleteheader_operation_execute if ( (ret=sieve_opr_stringlist_read_ex (renv, address, "value-patterns", TRUE, &vpattern_list)) <= 0 ) return ret; - + /* * Verify arguments */ @@ -452,16 +452,16 @@ static int cmd_deleteheader_operation_execute if ( trace ) { sieve_runtime_trace_descend(renv); if ( index_offset != 0 ) { - sieve_runtime_trace(renv, 0, + sieve_runtime_trace(renv, 0, "deleting matching occurences of header `%s' at index %u%s", str_c(field_name), index_offset, ( index_last ? " from last": "")); } else { - sieve_runtime_trace(renv, 0, + sieve_runtime_trace(renv, 0, "deleting matching occurences of header `%s'", str_c(field_name)); } } - /* Iterate through all headers and delete those that match */ + /* Iterate through all headers and delete those that match */ if ( (ret=edit_mail_headers_iterate_init (edmail, str_c(field_name), index_last, &edhiter)) > 0 ) { @@ -485,7 +485,7 @@ static int cmd_deleteheader_operation_execute if ( (match=sieve_match_value (mctx, value, strlen(value), vpattern_list)) < 0 ) break; - + if ( match > 0 ) { /* Remove it and iterate to next */ sieve_runtime_trace(renv, 0, "deleting header with value `%s'", @@ -506,7 +506,7 @@ static int cmd_deleteheader_operation_execute if ( mret < 0 ) return ret; } - + if ( ret == 0 ) { sieve_runtime_trace(renv, 0, "header `%s' not found", str_c(field_name)); } else if ( ret < 0 ) { @@ -514,7 +514,7 @@ static int cmd_deleteheader_operation_execute "failed to delete occurences of header `%s' (this should not happen!)", str_c(field_name)); } - + } else { int index = ( index_last ? -((int)index_offset) : ((int)index_offset) ); @@ -527,7 +527,7 @@ static int cmd_deleteheader_operation_execute sieve_runtime_trace(renv, 0, "deleting header `%s'", str_c(field_name)); } } - + /* Delete all occurences of header */ ret = edit_mail_header_delete(edmail, str_c(field_name), index); diff --git a/src/lib-sieve/plugins/editheader/ext-editheader-common.c b/src/lib-sieve/plugins/editheader/ext-editheader-common.c index a49edffca1fef274c86386614df511120a02d952..25a600e21b7816d34f78ec1b2763726ebf9e47c0 100644 --- a/src/lib-sieve/plugins/editheader/ext-editheader-common.c +++ b/src/lib-sieve/plugins/editheader/ext-editheader-common.c @@ -21,7 +21,7 @@ struct ext_editheader_header { const char *name; - + /* may extend this later */ unsigned int protected:1; }; @@ -39,14 +39,14 @@ static struct ext_editheader_header *ext_editheader_config_header_find { struct ext_editheader_header *headers; unsigned int count, i; - + headers = array_get_modifiable(&ext_config->headers, &count); for ( i = 0; i < count; i++ ) { if ( strcasecmp(hname, headers[i].name) == 0 ) return &headers[i]; } - return NULL; + return NULL; } bool ext_editheader_load @@ -79,7 +79,7 @@ bool ext_editheader_load struct ext_editheader_header *header; if ( !rfc2822_header_field_name_verify(*headers, strlen(*headers)) ) { - sieve_sys_warning(svinst, + sieve_sys_warning(svinst, "editheader: setting sieve_editheader_protected contains " "invalid header field name `%s' (ignored)", *headers); continue; @@ -100,10 +100,10 @@ bool ext_editheader_load if ( sieve_setting_get_size_value (svinst, "sieve_editheader_max_header_size", &max_header_size) ) { if ( max_header_size < EXT_EDITHEADER_MINIMUM_MAX_HEADER_SIZE ) { - sieve_sys_warning(svinst, + sieve_sys_warning(svinst, "editheader: value of sieve_editheader_max_header_size setting " "(=%"PRIuSIZE_T") is less than the minimum (=%"PRIuSIZE_T") " - "(ignored)", max_header_size, + "(ignored)", max_header_size, (size_t) EXT_EDITHEADER_MINIMUM_MAX_HEADER_SIZE); } else { ext_config->max_header_size = max_header_size; @@ -112,14 +112,14 @@ bool ext_editheader_load } T_END; *context = (void *) ext_config; - return TRUE; + return TRUE; } void ext_editheader_unload(const struct sieve_extension *ext) { - struct ext_editheader_config *ext_config = + struct ext_editheader_config *ext_config = (struct ext_editheader_config *) ext->context; - + if ( ext_config != NULL ) { pool_unref(&ext_config->pool); } @@ -132,11 +132,11 @@ void ext_editheader_unload(const struct sieve_extension *ext) bool ext_editheader_header_is_protected (const struct sieve_extension *ext, const char *hname) { - struct ext_editheader_config *ext_config = + struct ext_editheader_config *ext_config = (struct ext_editheader_config *) ext->context; const struct ext_editheader_header *header; - - if ( strcasecmp(hname, "received") == 0 + + if ( strcasecmp(hname, "received") == 0 || strcasecmp(hname, "auto-submitted") == 0 ) { return TRUE; } @@ -158,7 +158,7 @@ bool ext_editheader_header_is_protected bool ext_editheader_header_too_large (const struct sieve_extension *ext, size_t size) { - struct ext_editheader_config *ext_config = + struct ext_editheader_config *ext_config = (struct ext_editheader_config *) ext->context; return size > ext_config->max_header_size; diff --git a/src/lib-sieve/plugins/editheader/ext-editheader-limits.h b/src/lib-sieve/plugins/editheader/ext-editheader-limits.h index 3f1a05ede5527d192ba8d3d27e5071db59fb2198..61a75db36d20613febe1167a5ab1d1345e7504b4 100644 --- a/src/lib-sieve/plugins/editheader/ext-editheader-limits.h +++ b/src/lib-sieve/plugins/editheader/ext-editheader-limits.h @@ -1,6 +1,6 @@ /* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #ifndef __EXT_EDITHEADER_LIMITS_H #define __EXT_EDITHEADER_LIMITS_H diff --git a/src/lib-sieve/plugins/editheader/ext-editheader.c b/src/lib-sieve/plugins/editheader/ext-editheader.c index c36355cfa722560a79673ed8521f2d6f9d29e556..cb19d368bd74d447a53022d02c1006d2cd4528d9 100644 --- a/src/lib-sieve/plugins/editheader/ext-editheader.c +++ b/src/lib-sieve/plugins/editheader/ext-editheader.c @@ -28,12 +28,12 @@ #include "ext-editheader-common.h" -/* - * Operations +/* + * Operations */ -const struct sieve_operation_def *editheader_operations[] = { - &addheader_operation, +const struct sieve_operation_def *editheader_operations[] = { + &addheader_operation, &deleteheader_operation }; diff --git a/src/lib-sieve/plugins/enotify/Makefile.am b/src/lib-sieve/plugins/enotify/Makefile.am index 22a0cd5bf8ecaeea3d3f855a66adc09725d467a5..4b6563032eb0e53efaf28317a39a32ef2d99e5a2 100644 --- a/src/lib-sieve/plugins/enotify/Makefile.am +++ b/src/lib-sieve/plugins/enotify/Makefile.am @@ -24,7 +24,7 @@ libsieve_ext_enotify_la_DEPENDENCIES = \ $(notify_methods) libsieve_ext_enotify_la_LIBADD = \ $(notify_methods) - + libsieve_ext_enotify_la_SOURCES = \ ext-enotify.c \ ext-enotify-common.c \ diff --git a/src/lib-sieve/plugins/enotify/cmd-notify.c b/src/lib-sieve/plugins/enotify/cmd-notify.c index 09107e7daee0b220aad77ac73581c8bebf8246d9..cbb54b9e854d42c0dac0360343185c8bcb7521c1 100644 --- a/src/lib-sieve/plugins/enotify/cmd-notify.c +++ b/src/lib-sieve/plugins/enotify/cmd-notify.c @@ -18,19 +18,19 @@ #include "ext-enotify-common.h" -/* - * Forward declarations +/* + * Forward declarations */ - + static const struct sieve_argument_def notify_importance_tag; static const struct sieve_argument_def notify_from_tag; static const struct sieve_argument_def notify_options_tag; static const struct sieve_argument_def notify_message_tag; -/* - * Notify command - * - * Syntax: +/* + * Notify command + * + * Syntax: * notify [":from" string] * [":importance" <"1" / "2" / "3">] * [":options" string-list] @@ -48,16 +48,16 @@ static bool cmd_notify_validate static bool cmd_notify_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx); -const struct sieve_command_def notify_command = { +const struct sieve_command_def notify_command = { "notify", - SCT_COMMAND, - 1, 0, FALSE, FALSE, + SCT_COMMAND, + 1, 0, FALSE, FALSE, cmd_notify_registered, cmd_notify_pre_validate, cmd_notify_validate, - NULL, - cmd_notify_generate, - NULL + NULL, + cmd_notify_generate, + NULL }; /* @@ -67,47 +67,47 @@ const struct sieve_command_def notify_command = { /* Forward declarations */ static bool cmd_notify_validate_string_tag - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); static bool cmd_notify_validate_stringlist_tag - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); static bool cmd_notify_validate_importance_tag - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); /* Argument objects */ -static const struct sieve_argument_def notify_from_tag = { - "from", +static const struct sieve_argument_def notify_from_tag = { + "from", NULL, - cmd_notify_validate_string_tag, - NULL, NULL, NULL + cmd_notify_validate_string_tag, + NULL, NULL, NULL }; -static const struct sieve_argument_def notify_options_tag = { - "options", +static const struct sieve_argument_def notify_options_tag = { + "options", NULL, - cmd_notify_validate_stringlist_tag, - NULL, NULL, NULL + cmd_notify_validate_stringlist_tag, + NULL, NULL, NULL }; -static const struct sieve_argument_def notify_message_tag = { - "message", - NULL, - cmd_notify_validate_string_tag, - NULL, NULL, NULL +static const struct sieve_argument_def notify_message_tag = { + "message", + NULL, + cmd_notify_validate_string_tag, + NULL, NULL, NULL }; -static const struct sieve_argument_def notify_importance_tag = { - "importance", +static const struct sieve_argument_def notify_importance_tag = { + "importance", NULL, - cmd_notify_validate_importance_tag, - NULL, NULL, NULL + cmd_notify_validate_importance_tag, + NULL, NULL, NULL }; -/* - * Notify operation +/* + * Notify operation */ static bool cmd_notify_operation_dump @@ -115,29 +115,29 @@ static bool cmd_notify_operation_dump static int cmd_notify_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def notify_operation = { +const struct sieve_operation_def notify_operation = { "NOTIFY", &enotify_extension, EXT_ENOTIFY_OPERATION_NOTIFY, - cmd_notify_operation_dump, + cmd_notify_operation_dump, cmd_notify_operation_execute }; -/* - * Notify action +/* + * Notify action */ /* Forward declarations */ static int act_notify_check_duplicate - (const struct sieve_runtime_env *renv, + (const struct sieve_runtime_env *renv, const struct sieve_action *act, const struct sieve_action *act_other); static void act_notify_print (const struct sieve_action *action, const struct sieve_result_print_env *rpenv, - bool *keep); + bool *keep); static bool act_notify_commit - (const struct sieve_action *action, const struct sieve_action_exec_env *aenv, + (const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void *tr_context, bool *keep); /* Action object */ @@ -146,7 +146,7 @@ const struct sieve_action_def act_notify = { "notify", 0, NULL, - act_notify_check_duplicate, + act_notify_check_duplicate, NULL, act_notify_print, NULL, NULL, @@ -157,28 +157,28 @@ const struct sieve_action_def act_notify = { /* * Command validation context */ - + struct cmd_notify_context_data { struct sieve_ast_argument *from; struct sieve_ast_argument *message; struct sieve_ast_argument *options; }; -/* - * Tag validation +/* + * Tag validation */ static bool cmd_notify_validate_string_tag -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd) { struct sieve_ast_argument *tag = *arg; - struct cmd_notify_context_data *ctx_data = - (struct cmd_notify_context_data *) cmd->data; + struct cmd_notify_context_data *ctx_data = + (struct cmd_notify_context_data *) cmd->data; /* Detach the tag itself */ *arg = sieve_ast_arguments_detach(*arg,1); - + /* Check syntax: * :from <string> * :message <string> @@ -189,41 +189,41 @@ static bool cmd_notify_validate_string_tag if ( sieve_argument_is(tag, notify_from_tag) ) { ctx_data->from = *arg; - + /* Skip parameter */ *arg = sieve_ast_argument_next(*arg); - + } else if ( sieve_argument_is(tag, notify_message_tag) ) { ctx_data->message = *arg; /* Skip parameter */ - *arg = sieve_ast_argument_next(*arg); + *arg = sieve_ast_argument_next(*arg); } - + return TRUE; } static bool cmd_notify_validate_stringlist_tag -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd) { struct sieve_ast_argument *tag = *arg; - struct cmd_notify_context_data *ctx_data = - (struct cmd_notify_context_data *) cmd->data; + struct cmd_notify_context_data *ctx_data = + (struct cmd_notify_context_data *) cmd->data; /* Detach the tag itself */ *arg = sieve_ast_arguments_detach(*arg,1); - + /* Check syntax: * :options string-list */ if ( !sieve_validate_tag_parameter - (valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING_LIST, FALSE) ) + (valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING_LIST, FALSE) ) return FALSE; - + /* Assign context */ - ctx_data->options = *arg; - + ctx_data->options = *arg; + /* Skip parameter */ *arg = sieve_ast_argument_next(*arg); @@ -231,7 +231,7 @@ static bool cmd_notify_validate_stringlist_tag } static bool cmd_notify_validate_importance_tag -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd ATTR_UNUSED) { const struct sieve_ast_argument *tag = *arg; @@ -240,13 +240,13 @@ static bool cmd_notify_validate_importance_tag /* Detach the tag itself */ *arg = sieve_ast_arguments_detach(*arg,1); - /* Check syntax: + /* Check syntax: * :importance <"1" / "2" / "3"> */ if ( sieve_ast_argument_type(*arg) != SAAT_STRING ) { /* Not a string */ - sieve_argument_validate_error(valdtr, *arg, + sieve_argument_validate_error(valdtr, *arg, "the :importance tag for the notify command requires a string parameter, " "but %s was found", sieve_ast_argument_name(*arg)); return FALSE; @@ -256,10 +256,10 @@ static bool cmd_notify_validate_importance_tag if ( impstr[0] < '1' || impstr[0] > '3' || impstr[1] != '\0' ) { /* Invalid importance */ - sieve_argument_validate_error(valdtr, *arg, + sieve_argument_validate_error(valdtr, *arg, "invalid :importance value for notify command: %s", impstr); return FALSE; - } + } sieve_ast_argument_number_substitute(*arg, impstr[0] - '0'); (*arg)->argument = sieve_argument_create @@ -267,64 +267,64 @@ static bool cmd_notify_validate_importance_tag /* Skip parameter */ *arg = sieve_ast_argument_next(*arg); - + return TRUE; } -/* - * Command registration +/* + * Command registration */ static bool cmd_notify_registered (struct sieve_validator *valdtr, const struct sieve_extension *ext, - struct sieve_command_registration *cmd_reg) + struct sieve_command_registration *cmd_reg) { sieve_validator_register_tag - (valdtr, cmd_reg, ext, ¬ify_importance_tag, CMD_NOTIFY_OPT_IMPORTANCE); + (valdtr, cmd_reg, ext, ¬ify_importance_tag, CMD_NOTIFY_OPT_IMPORTANCE); sieve_validator_register_tag - (valdtr, cmd_reg, ext, ¬ify_from_tag, CMD_NOTIFY_OPT_FROM); + (valdtr, cmd_reg, ext, ¬ify_from_tag, CMD_NOTIFY_OPT_FROM); sieve_validator_register_tag - (valdtr, cmd_reg, ext, ¬ify_options_tag, CMD_NOTIFY_OPT_OPTIONS); + (valdtr, cmd_reg, ext, ¬ify_options_tag, CMD_NOTIFY_OPT_OPTIONS); sieve_validator_register_tag - (valdtr, cmd_reg, ext, ¬ify_message_tag, CMD_NOTIFY_OPT_MESSAGE); + (valdtr, cmd_reg, ext, ¬ify_message_tag, CMD_NOTIFY_OPT_MESSAGE); return TRUE; } -/* - * Command validation +/* + * Command validation */ static bool cmd_notify_pre_validate -(struct sieve_validator *validator ATTR_UNUSED, - struct sieve_command *cmd) +(struct sieve_validator *validator ATTR_UNUSED, + struct sieve_command *cmd) { struct cmd_notify_context_data *ctx_data; - + /* Assign context */ - ctx_data = p_new(sieve_command_pool(cmd), + ctx_data = p_new(sieve_command_pool(cmd), struct cmd_notify_context_data, 1); cmd->data = ctx_data; return TRUE; } - + static bool cmd_notify_validate -(struct sieve_validator *valdtr, struct sieve_command *cmd) -{ +(struct sieve_validator *valdtr, struct sieve_command *cmd) +{ struct sieve_ast_argument *arg = cmd->first_positional; - struct cmd_notify_context_data *ctx_data = - (struct cmd_notify_context_data *) cmd->data; + struct cmd_notify_context_data *ctx_data = + (struct cmd_notify_context_data *) cmd->data; if ( !sieve_validate_positional_argument (valdtr, cmd, arg, "method", 1, SAAT_STRING) ) { return FALSE; } - + if ( !sieve_validator_argument_activate(valdtr, cmd, arg, FALSE) ) return FALSE; - + return ext_enotify_compile_check_arguments (valdtr, cmd, arg, ctx_data->message, ctx_data->from, ctx_data->options); } @@ -332,27 +332,27 @@ static bool cmd_notify_validate /* * Code generation */ - + static bool cmd_notify_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) -{ +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) +{ sieve_operation_emit(cgenv->sblock, cmd->ext, ¬ify_operation); /* Generate arguments */ return sieve_generate_arguments(cgenv, cmd, NULL); } -/* +/* * Code dump */ - + static bool cmd_notify_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) -{ +{ int opt_code = 0; - + sieve_code_dumpf(denv, "NOTIFY"); - sieve_code_descend(denv); + sieve_code_descend(denv); /* Dump optional operands */ @@ -384,18 +384,18 @@ static bool cmd_notify_operation_dump if ( !opok ) return FALSE; } - + /* Dump method operand */ return sieve_opr_string_dump(denv, address, "method"); } -/* +/* * Code execution */ - + static int cmd_notify_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) -{ +{ const struct sieve_extension *this_ext = renv->oprtn->ext; struct sieve_side_effects_list *slist = NULL; struct sieve_enotify_action *act; @@ -405,7 +405,7 @@ static int cmd_notify_operation_execute sieve_number_t importance = 2; struct sieve_stringlist *options = NULL; const struct sieve_enotify_method *method; - string_t *method_uri, *message = NULL, *from = NULL; + string_t *method_uri, *message = NULL, *from = NULL; int ret; /* @@ -424,7 +424,7 @@ static int cmd_notify_operation_execute switch ( opt_code ) { case CMD_NOTIFY_OPT_IMPORTANCE: - ret = sieve_opr_number_read(renv, address, "importance", &importance); + ret = sieve_opr_number_read(renv, address, "importance", &importance); break; case CMD_NOTIFY_OPT_FROM: ret = sieve_opr_string_read(renv, address, "from", &from); @@ -442,19 +442,19 @@ static int cmd_notify_operation_execute if ( ret <= 0 ) return ret; } - + /* Method operand */ if ( (ret=sieve_opr_string_read(renv, address, "method", &method_uri)) <= 0 ) return ret; - + /* * Perform operation */ /* Enforce 0 < importance < 4 (just to be sure) */ - if ( importance < 1 ) + if ( importance < 1 ) importance = 1; else if ( importance > 3 ) importance = 3; @@ -462,17 +462,17 @@ static int cmd_notify_operation_execute /* Trace */ if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_ACTIONS) ) { - sieve_runtime_trace(renv, 0, "notify action"); + sieve_runtime_trace(renv, 0, "notify action"); sieve_runtime_trace_descend(renv); sieve_runtime_trace(renv, 0, "notify with uri `%s'", - str_sanitize(str_c(method_uri), 80)); + str_sanitize(str_c(method_uri), 80)); } /* Check operands */ if ( (ret=ext_enotify_runtime_check_operands - (renv, method_uri, message, from, options, &method, - &method_context)) > 0 ) + (renv, method_uri, message, from, options, &method, + &method_context)) > 0 ) { /* Add notify action to the result */ @@ -510,14 +510,14 @@ static int act_notify_check_duplicate const struct sieve_enotify_method_def *nmth_def; struct sieve_enotify_env nenv; bool result = TRUE; - + if ( act->context == NULL || act_other->context == NULL ) return 0; nact = (const struct sieve_enotify_action *) act->context; nact_other = (const struct sieve_enotify_action *) act_other->context; - if ( nact->method == NULL || nact->method->def == NULL ) + if ( nact->method == NULL || nact->method->def == NULL ) return 0; nmth_def = nact->method->def; @@ -526,24 +526,24 @@ static int act_notify_check_duplicate memset(&nenv, 0, sizeof(nenv)); nenv.svinst = renv->svinst; - nenv.method = nact->method; + nenv.method = nact->method; nenv.ehandler = sieve_prefix_ehandler_create (sieve_result_get_error_handler(renv->result), act->location, "notify"); result = nmth_def->action_check_duplicates(&nenv, nact, nact_other); sieve_error_handler_unref(&nenv.ehandler); - + return result; } /* Result printing */ - + static void act_notify_print -(const struct sieve_action *action, const struct sieve_result_print_env *rpenv, - bool *keep ATTR_UNUSED) +(const struct sieve_action *action, const struct sieve_result_print_env *rpenv, + bool *keep ATTR_UNUSED) { - const struct sieve_enotify_action *act = + const struct sieve_enotify_action *act = (const struct sieve_enotify_action *) action->context; const struct sieve_enotify_method *method; @@ -570,17 +570,17 @@ static bool act_notify_commit (const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void *tr_context ATTR_UNUSED, bool *keep ATTR_UNUSED) { - const struct sieve_enotify_action *act = + const struct sieve_enotify_action *act = (const struct sieve_enotify_action *) action->context; const struct sieve_enotify_method *method = act->method; struct sieve_enotify_exec_env nenv; bool result = TRUE; - if ( method->def != NULL && method->def->action_execute != NULL ) { + if ( method->def != NULL && method->def->action_execute != NULL ) { /* Compose log structure */ memset(&nenv, 0, sizeof(nenv)); nenv.svinst = aenv->svinst; - nenv.method = method; + nenv.method = method; nenv.scriptenv = aenv->scriptenv; nenv.msgdata = aenv->msgdata; nenv.msgctx = aenv->msgctx; @@ -592,7 +592,7 @@ static bool act_notify_commit sieve_error_handler_unref(&nenv.ehandler); } - + return result; } diff --git a/src/lib-sieve/plugins/enotify/ext-enotify-common.c b/src/lib-sieve/plugins/enotify/ext-enotify-common.c index e1a9efd64e842505e407c4854ec51df0bae26e1d..3b34b15cebfb9760f4ff083d5d2d2c9796d54377 100644 --- a/src/lib-sieve/plugins/enotify/ext-enotify-common.c +++ b/src/lib-sieve/plugins/enotify/ext-enotify-common.c @@ -1,6 +1,6 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #include "lib.h" #include "str.h" #include "str-sanitize.h" @@ -61,10 +61,10 @@ extern const struct sieve_enotify_method_def mailto_notify; /* * Notify method registry */ - + static const struct sieve_enotify_method *ext_enotify_method_register -(struct sieve_instance *svinst, struct ext_enotify_context *ectx, - const struct sieve_enotify_method_def *nmth_def) +(struct sieve_instance *svinst, struct ext_enotify_context *ectx, + const struct sieve_enotify_method_def *nmth_def) { struct sieve_enotify_method *nmth; int nmth_id = (int) array_count(&ectx->notify_methods); @@ -78,7 +78,7 @@ static const struct sieve_enotify_method *ext_enotify_method_register nmth_def->load(nmth, &nmth->context); return nmth; -} +} void ext_enotify_methods_init (struct sieve_instance *svinst, struct ext_enotify_context *ectx) @@ -92,7 +92,7 @@ void ext_enotify_methods_deinit(struct ext_enotify_context *ectx) { const struct sieve_enotify_method *methods; unsigned int meth_count, i; - + methods = array_get(&ectx->notify_methods, &meth_count); for ( i = 0; i < meth_count; i++ ) { if ( methods[i].def != NULL && methods[i].def->unload != NULL ) @@ -103,14 +103,14 @@ void ext_enotify_methods_deinit(struct ext_enotify_context *ectx) } const struct sieve_enotify_method *sieve_enotify_method_register -(struct sieve_instance *svinst, +(struct sieve_instance *svinst, const struct sieve_enotify_method_def *nmth_def) { const struct sieve_extension *ntfy_ext = sieve_extension_get_by_name(svinst, "enotify"); if ( ntfy_ext != NULL ) { - struct ext_enotify_context *ectx = + struct ext_enotify_context *ectx = (struct ext_enotify_context *) ntfy_ext->context; return ext_enotify_method_register(svinst, ectx, nmth_def); @@ -127,29 +127,29 @@ void sieve_enotify_method_unregister sieve_extension_get_by_name(svinst, "enotify"); if ( ntfy_ext != NULL ) { - struct ext_enotify_context *ectx = + struct ext_enotify_context *ectx = (struct ext_enotify_context *) ntfy_ext->context; int nmth_id = nmth->id; if ( nmth_id >= 0 && nmth_id < (int)array_count(&ectx->notify_methods) ) { struct sieve_enotify_method *nmth_mod = array_idx_modifiable(&ectx->notify_methods, nmth_id); - + nmth_mod->def = NULL; } } } const struct sieve_enotify_method *ext_enotify_method_find -(const struct sieve_extension *ntfy_ext, const char *identifier) +(const struct sieve_extension *ntfy_ext, const char *identifier) { - struct ext_enotify_context *ectx = + struct ext_enotify_context *ectx = (struct ext_enotify_context *) ntfy_ext->context; unsigned int meth_count, i; const struct sieve_enotify_method *methods; - + methods = array_get(&ectx->notify_methods, &meth_count); - + for ( i = 0; i < meth_count; i++ ) { if ( methods[i].def == NULL ) continue; @@ -157,21 +157,21 @@ const struct sieve_enotify_method *ext_enotify_method_find return &methods[i]; } } - + return NULL; } static const char *ext_notify_get_methods_string (const struct sieve_extension *ntfy_ext) { - struct ext_enotify_context *ectx = + struct ext_enotify_context *ectx = (struct ext_enotify_context *) ntfy_ext->context; unsigned int meth_count, i; const struct sieve_enotify_method *methods; string_t *result = t_str_new(128); - + methods = array_get(&ectx->notify_methods, &meth_count); - + if ( meth_count > 0 ) { for ( i = 0; i < meth_count; i++ ) { if ( str_len(result) > 0 ) @@ -180,50 +180,50 @@ static const char *ext_notify_get_methods_string if ( methods[i].def != NULL ) str_append(result, methods[i].def->identifier); } - + return str_c(result); } - + return NULL; } /* * Compile-time argument validation */ - + static const char *ext_enotify_uri_scheme_parse(const char **uri_p) { string_t *scheme = t_str_new(EXT_ENOTIFY_MAX_SCHEME_LEN); const char *p = *uri_p; unsigned int len = 0; - + /* RFC 3968: * * scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) * * FIXME: we do not allow '%' in schemes. Is this correct? */ - + if ( !i_isalpha(*p) ) return NULL; - + str_append_c(scheme, *p); p++; - + while ( *p != '\0' && len < EXT_ENOTIFY_MAX_SCHEME_LEN ) { - + if ( !i_isalnum(*p) && *p != '+' && *p != '-' && *p != '.' ) break; - + str_append_c(scheme, *p); p++; len++; } - + if ( *p != ':' ) return NULL; p++; - + *uri_p = p; return str_c(scheme); } @@ -233,21 +233,21 @@ static bool ext_enotify_option_parse const char **opt_name_r, const char **opt_value_r) { const char *p = option; - + /* "<optionname>=<value>". - * + * * l-d = ALPHA / DIGIT * l-d-p = l-d / "." / "-" / "_" * optionname = l-d *l-d-p * value = *(%x01-09 / %x0B-0C / %x0E-FF) */ - - /* - * Parse option name + + /* + * Parse option name * * optionname = l-d *l-d-p */ - + /* Explicitly report empty option as such */ if ( *p == '\0' ) { sieve_enotify_error(nenv, "empty option specified"); @@ -257,52 +257,52 @@ static bool ext_enotify_option_parse /* l-d = ALPHA / DIGIT */ if ( i_isalnum(*p) ) { p++; - + /* l-d-p = l-d / "." / "-" / "_" */ while ( i_isalnum(*p) || *p == '.' || *p == '-' || *p == '_' ) p++; } - + /* Parsing must end at '=' and we must parse at least one character */ if ( *p != '=' || p == option ) { sieve_enotify_error(nenv, "invalid option name specified in option '%s'", str_sanitize(option, 80)); return FALSE; } - + /* Assign option name */ - if ( opt_name_r != NULL ) + if ( opt_name_r != NULL ) *opt_name_r = t_strdup_until(option, p); - + /* Skip '=' */ p++; - + /* Exit now if only the option name is of interest */ if ( name_only ) return TRUE; - - /* + + /* * Parse option value */ - + /* value = *(%x01-09 / %x0B-0C / %x0E-FF) */ while ( *p != '\0' && *p != 0x0A && *p != 0x0D ) p++; - + /* Parse must end at end of string */ if ( *p != '\0' ) { - sieve_enotify_error(nenv, + sieve_enotify_error(nenv, "notify command: invalid option value specified in option '%s'", str_sanitize(option, 80)); return FALSE; } - + /* Assign option value */ if ( opt_value_r != NULL ) *opt_value_r = p; - + return TRUE; -} +} struct _ext_enotify_option_check_context { struct sieve_instance *svinst; @@ -313,7 +313,7 @@ struct _ext_enotify_option_check_context { static int _ext_enotify_option_check (void *context, struct sieve_ast_argument *arg) { - struct _ext_enotify_option_check_context *optn_context = + struct _ext_enotify_option_check_context *optn_context = (struct _ext_enotify_option_check_context *) context; struct sieve_validator *valdtr = optn_context->valdtr; const struct sieve_enotify_method *method = optn_context->method; @@ -321,28 +321,28 @@ static int _ext_enotify_option_check const char *option = sieve_ast_argument_strc(arg); const char *opt_name = NULL, *opt_value = NULL; bool result = TRUE, check = TRUE; - + /* Compose log structure */ memset(&nenv, 0, sizeof(nenv)); nenv.svinst = optn_context->svinst; - nenv.method = method; + nenv.method = method; nenv.ehandler = sieve_prefix_ehandler_create - (sieve_validator_error_handler(valdtr), + (sieve_validator_error_handler(valdtr), sieve_error_script_location - (sieve_validator_script(valdtr), arg->source_line), + (sieve_validator_script(valdtr), arg->source_line), "notify command"); - + /* Parse option */ if ( !sieve_argument_is_string_literal(arg) ) { /* Variable string: partial option parse - * + * * If the string item is not a string literal, it cannot be validated fully * at compile time. We can however check whether the '=' is in the string * specification and whether the part before the '=' is a valid option name. * In that case, the method option check function is called with the value * parameter equal to NULL, meaning that it should only check the validity * of the option itself and not the assigned value. - */ + */ if ( !ext_enotify_option_parse(NULL, option, TRUE, &opt_name, &opt_value) ) check = FALSE; } else { @@ -351,12 +351,12 @@ static int _ext_enotify_option_check (&nenv, option, FALSE, &opt_name, &opt_value) ) result = FALSE; } - + /* Call method's option check function */ - if ( result && check && method->def != NULL && - method->def->compile_check_option != NULL ) - result = method->def->compile_check_option(&nenv, opt_name, opt_value); - + if ( result && check && method->def != NULL && + method->def->compile_check_option != NULL ) + result = method->def->compile_check_option(&nenv, opt_name, opt_value); + sieve_error_handler_unref(&nenv.ehandler); return result; @@ -364,7 +364,7 @@ static int _ext_enotify_option_check bool ext_enotify_compile_check_arguments (struct sieve_validator *valdtr, struct sieve_command *cmd, - struct sieve_ast_argument *uri_arg, struct sieve_ast_argument *msg_arg, + struct sieve_ast_argument *uri_arg, struct sieve_ast_argument *msg_arg, struct sieve_ast_argument *from_arg, struct sieve_ast_argument *options_arg) { const struct sieve_extension *this_ext = cmd->ext; @@ -380,18 +380,18 @@ bool ext_enotify_compile_check_arguments */ if ( !sieve_argument_is_string_literal(uri_arg) ) return TRUE; - + /* Parse scheme part of URI */ if ( (scheme=ext_enotify_uri_scheme_parse(&uri)) == NULL ) { - sieve_argument_validate_error(valdtr, uri_arg, - "notify command: invalid scheme part for method URI '%s'", + sieve_argument_validate_error(valdtr, uri_arg, + "notify command: invalid scheme part for method URI '%s'", str_sanitize(sieve_ast_argument_strc(uri_arg), 80)); return FALSE; } - + /* Find used method with the parsed scheme identifier */ if ( (method=ext_enotify_method_find(this_ext, scheme)) == NULL ) { - sieve_argument_validate_error(valdtr, uri_arg, + sieve_argument_validate_error(valdtr, uri_arg, "notify command: invalid method '%s'", scheme); return FALSE; } @@ -401,15 +401,15 @@ bool ext_enotify_compile_check_arguments /* Compose log structure */ memset(&nenv, 0, sizeof(nenv)); nenv.svinst = svinst; - nenv.method = method; - + nenv.method = method; + /* Check URI itself */ if ( result && method->def->compile_check_uri != NULL ) { /* Set log location to location of URI argument */ nenv.ehandler = sieve_prefix_ehandler_create - (sieve_validator_error_handler(valdtr), + (sieve_validator_error_handler(valdtr), sieve_error_script_location - (sieve_validator_script(valdtr), uri_arg->source_line), + (sieve_validator_script(valdtr), uri_arg->source_line), "notify command"); /* Execute method check function */ @@ -423,9 +423,9 @@ bool ext_enotify_compile_check_arguments /* Set log location to location of :message argument */ sieve_error_handler_unref(&nenv.ehandler); nenv.ehandler = sieve_prefix_ehandler_create - (sieve_validator_error_handler(valdtr), + (sieve_validator_error_handler(valdtr), sieve_error_script_location - (sieve_validator_script(valdtr), msg_arg->source_line), + (sieve_validator_script(valdtr), msg_arg->source_line), "notify command"); /* Execute method check function */ @@ -439,9 +439,9 @@ bool ext_enotify_compile_check_arguments /* Set log location to location of :from argument */ sieve_error_handler_unref(&nenv.ehandler); nenv.ehandler = sieve_prefix_ehandler_create - (sieve_validator_error_handler(valdtr), + (sieve_validator_error_handler(valdtr), sieve_error_script_location - (sieve_validator_script(valdtr), from_arg->source_line), + (sieve_validator_script(valdtr), from_arg->source_line), "notify command"); /* Execute method check function */ @@ -450,32 +450,32 @@ bool ext_enotify_compile_check_arguments } sieve_error_handler_unref(&nenv.ehandler); - + /* Check :options argument */ if ( result && options_arg != NULL ) { struct sieve_ast_argument *option = options_arg; - struct _ext_enotify_option_check_context optn_context = + struct _ext_enotify_option_check_context optn_context = { svinst, valdtr, method }; - + /* Parse and check options */ result = ( sieve_ast_stringlist_map (&option, (void *) &optn_context, _ext_enotify_option_check) > 0 ); - + /* Discard argument if options are not accepted by method */ if ( result && method->def->compile_check_option == NULL ) { - sieve_argument_validate_warning(valdtr, options_arg, + sieve_argument_validate_warning(valdtr, options_arg, "notify command: method '%s' accepts no options", scheme); (void)sieve_ast_arguments_detach(options_arg,1); } } - + return result; } /* * Runtime operand checking */ - + bool ext_enotify_runtime_method_validate (const struct sieve_runtime_env *renv, string_t *method_uri) { @@ -528,7 +528,7 @@ static const struct sieve_enotify_method *ext_enotify_get_method */ if ( (scheme=ext_enotify_uri_scheme_parse(&uri)) == NULL ) { sieve_runtime_error(renv, NULL, - "invalid scheme part for method URI '%s'", + "invalid scheme part for method URI '%s'", str_sanitize(str_c(method_uri), 80)); return NULL; } @@ -558,9 +558,9 @@ const char *ext_enotify_runtime_get_method_capability if ( method == NULL ) return NULL; /* Get requested capability */ - if ( method->def != NULL && + if ( method->def != NULL && method->def->runtime_get_method_capability != NULL ) { - struct sieve_enotify_env nenv; + struct sieve_enotify_env nenv; memset(&nenv, 0, sizeof(nenv)); nenv.svinst = renv->svinst; @@ -580,8 +580,8 @@ const char *ext_enotify_runtime_get_method_capability int ext_enotify_runtime_check_operands (const struct sieve_runtime_env *renv, - string_t *method_uri, string_t *message, string_t *from, - struct sieve_stringlist *options, + string_t *method_uri, string_t *message, string_t *from, + struct sieve_stringlist *options, const struct sieve_enotify_method **method_r, void **method_context) { const struct sieve_enotify_method *method; @@ -593,7 +593,7 @@ int ext_enotify_runtime_check_operands /* Check provided operands */ if ( method->def != NULL && method->def->runtime_check_operands != NULL ) { - struct sieve_enotify_env nenv; + struct sieve_enotify_env nenv; int result = SIEVE_EXEC_OK; memset(&nenv, 0, sizeof(nenv)); @@ -605,22 +605,22 @@ int ext_enotify_runtime_check_operands /* Execute check function */ if ( method->def->runtime_check_operands - (&nenv, str_c(method_uri), uri_body, message, from, + (&nenv, str_c(method_uri), uri_body, message, from, sieve_result_pool(renv->result), method_context) ) { /* Check any provided options */ - if ( options != NULL ) { + if ( options != NULL ) { string_t *option = NULL; int ret; - + /* Iterate through all provided options */ while ( (ret=sieve_stringlist_next_item(options, &option)) > 0 ) { const char *opt_name = NULL, *opt_value = NULL; - + /* Parse option into <optionname> and <value> */ if ( ext_enotify_option_parse (&nenv, str_c(option), FALSE, &opt_name, &opt_value) ) { - + /* Set option */ if ( method->def->runtime_set_option != NULL ) { (void) method->def->runtime_set_option @@ -628,7 +628,7 @@ int ext_enotify_runtime_check_operands } } } - + /* Check for binary corruptions encountered during string list iteration */ if ( ret >= 0 ) { @@ -641,11 +641,11 @@ int ext_enotify_runtime_check_operands } } else { - /* No options */ + /* No options */ *method_r = method; } - } else { + } else { /* Operand check failed */ result = SIEVE_EXEC_FAILURE; } @@ -655,7 +655,7 @@ int ext_enotify_runtime_check_operands } /* No check function defined: a most unlikely situation */ - *method_context = NULL; + *method_context = NULL; *method_r = method; return SIEVE_EXEC_OK; } @@ -668,9 +668,9 @@ void sieve_enotify_method_printf (const struct sieve_enotify_print_env *penv, const char *fmt, ...) { va_list args; - - va_start(args, fmt); + + va_start(args, fmt); sieve_result_vprintf(penv->result_penv, fmt, args); - va_end(args); + va_end(args); } diff --git a/src/lib-sieve/plugins/enotify/ext-enotify-common.h b/src/lib-sieve/plugins/enotify/ext-enotify-common.h index 40637226b6b9eb7c7814f2da9d55297de642ebdf..5d3291e5a25abc92dfd9adb7a2ef02b1cb78a3f1 100644 --- a/src/lib-sieve/plugins/enotify/ext-enotify-common.h +++ b/src/lib-sieve/plugins/enotify/ext-enotify-common.h @@ -66,7 +66,7 @@ enum ext_variables_opcode { /* * Operands */ - + extern const struct sieve_operand_def encodeurl_operand; /* @@ -78,7 +78,7 @@ extern const struct sieve_variables_modifier_def encodeurl_modifier; /* * Notify methods */ - + void ext_enotify_methods_init (struct sieve_instance *svinst, struct ext_enotify_context *ectx); void ext_enotify_methods_deinit @@ -86,35 +86,35 @@ void ext_enotify_methods_deinit const struct sieve_enotify_method *ext_enotify_method_find (const struct sieve_extension *ntfy_ext, const char *identifier); - + /* * Validation */ - + bool ext_enotify_compile_check_arguments (struct sieve_validator *valdtr, struct sieve_command *cmd, struct sieve_ast_argument *uri_arg, struct sieve_ast_argument *msg_arg, - struct sieve_ast_argument *from_arg, + struct sieve_ast_argument *from_arg, struct sieve_ast_argument *options_arg); /* * Runtime */ - + bool ext_enotify_runtime_method_validate (const struct sieve_runtime_env *renv, string_t *method_uri); - + const char *ext_enotify_runtime_get_method_capability (const struct sieve_runtime_env *renv, string_t *method_uri, const char *capability); int ext_enotify_runtime_check_operands (const struct sieve_runtime_env *renv, - string_t *method_uri, string_t *message, string_t *from, - struct sieve_stringlist *options, + string_t *method_uri, string_t *message, string_t *from, + struct sieve_stringlist *options, const struct sieve_enotify_method **method_r, void **method_context); - + /* * Method printing */ diff --git a/src/lib-sieve/plugins/enotify/ext-enotify-limits.h b/src/lib-sieve/plugins/enotify/ext-enotify-limits.h index 5eb5336e134cdf78e10997331610bc1d73c9db93..6dbc1f2a72fa41bf81367f26e10e53b3094ee9f8 100644 --- a/src/lib-sieve/plugins/enotify/ext-enotify-limits.h +++ b/src/lib-sieve/plugins/enotify/ext-enotify-limits.h @@ -1,6 +1,6 @@ /* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #ifndef __EXT_ENOTIFY_LIMITS_H #define __EXT_ENOTIFY_LIMITS_H diff --git a/src/lib-sieve/plugins/enotify/ext-enotify.c b/src/lib-sieve/plugins/enotify/ext-enotify.c index 7be2b9fa141aeddfa6875f3e5dd8a52f2df9fb71..7d131dc141042f2198339339105628c89c5c7eab 100644 --- a/src/lib-sieve/plugins/enotify/ext-enotify.c +++ b/src/lib-sieve/plugins/enotify/ext-enotify.c @@ -36,7 +36,7 @@ const struct sieve_operation_def *ext_enotify_operations[] = { ¬ify_method_capability_operation }; -/* +/* * Extension */ @@ -45,11 +45,11 @@ static void ext_enotify_unload(const struct sieve_extension *ext); static bool ext_enotify_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr); -const struct sieve_extension_def enotify_extension = { - "enotify", +const struct sieve_extension_def enotify_extension = { + "enotify", ext_enotify_load, ext_enotify_unload, - ext_enotify_validator_load, + ext_enotify_validator_load, NULL, NULL, NULL, NULL, NULL, SIEVE_EXT_DEFINE_OPERATIONS(ext_enotify_operations), SIEVE_EXT_DEFINE_OPERAND(encodeurl_operand) @@ -61,7 +61,7 @@ static bool ext_enotify_load(const struct sieve_extension *ext, void **context) if ( *context != NULL ) { ext_enotify_unload(ext); - } + } ectx = i_new(struct ext_enotify_context, 1); ectx->var_ext = sieve_ext_variables_get_extension(ext->svinst); @@ -76,7 +76,7 @@ static bool ext_enotify_load(const struct sieve_extension *ext, void **context) static void ext_enotify_unload(const struct sieve_extension *ext) { - struct ext_enotify_context *ectx = + struct ext_enotify_context *ectx = (struct ext_enotify_context *) ext->context; ext_enotify_methods_deinit(ectx); @@ -87,18 +87,18 @@ static void ext_enotify_unload(const struct sieve_extension *ext) static bool ext_enotify_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr) { - struct ext_enotify_context *ectx = + struct ext_enotify_context *ectx = (struct ext_enotify_context *) ext->context; /* Register new commands */ sieve_validator_register_command(valdtr, ext, ¬ify_command); sieve_validator_register_command(valdtr, ext, &valid_notify_method_test); sieve_validator_register_command(valdtr, ext, ¬ify_method_capability_test); - + /* Register new set modifier for variables extension */ sieve_variables_modifier_register (ectx->var_ext, valdtr, ext, &encodeurl_modifier); - + return TRUE; } diff --git a/src/lib-sieve/plugins/enotify/mailto/ntfy-mailto.c b/src/lib-sieve/plugins/enotify/mailto/ntfy-mailto.c index 7e41ce9286f5012c3b2a9225a9007e863dea31db..c3054aff2a1ae4bee218b7bd9508d9e41b36c8e6 100644 --- a/src/lib-sieve/plugins/enotify/mailto/ntfy-mailto.c +++ b/src/lib-sieve/plugins/enotify/mailto/ntfy-mailto.c @@ -1,6 +1,6 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + /* Notify method mailto * -------------------- * @@ -8,16 +8,16 @@ * Specification: RFC 5436 * Implementation: full * Status: testing - * + * */ - + /* FIXME: URI syntax conforms to something somewhere in between RFC 2368 and * draft-duerst-mailto-bis-05.txt. Should fully migrate to new specification * when it matures. This requires modifications to the address parser (no * whitespace allowed within the address itself) and UTF-8 support will be * required in the URL. */ - + #include "lib.h" #include "array.h" #include "str.h" @@ -40,46 +40,46 @@ /* * Configuration */ - + #define NTFY_MAILTO_MAX_RECIPIENTS 8 #define NTFY_MAILTO_MAX_HEADERS 16 #define NTFY_MAILTO_MAX_SUBJECT 256 -/* +/* * Mailto notification method */ - + static bool ntfy_mailto_compile_check_uri (const struct sieve_enotify_env *nenv, const char *uri, const char *uri_body); static bool ntfy_mailto_compile_check_from (const struct sieve_enotify_env *nenv, string_t *from); static const char *ntfy_mailto_runtime_get_notify_capability - (const struct sieve_enotify_env *nenv, const char *uri, const char *uri_body, + (const struct sieve_enotify_env *nenv, const char *uri, const char *uri_body, const char *capability); static bool ntfy_mailto_runtime_check_uri (const struct sieve_enotify_env *nenv, const char *uri, const char *uri_body); static bool ntfy_mailto_runtime_check_operands - (const struct sieve_enotify_env *nenv, const char *uri,const char *uri_body, - string_t *message, string_t *from, pool_t context_pool, + (const struct sieve_enotify_env *nenv, const char *uri,const char *uri_body, + string_t *message, string_t *from, pool_t context_pool, void **method_context); static int ntfy_mailto_action_check_duplicates - (const struct sieve_enotify_env *nenv, + (const struct sieve_enotify_env *nenv, const struct sieve_enotify_action *nact, const struct sieve_enotify_action *nact_other); static void ntfy_mailto_action_print - (const struct sieve_enotify_print_env *penv, - const struct sieve_enotify_action *nact); + (const struct sieve_enotify_print_env *penv, + const struct sieve_enotify_action *nact); static bool ntfy_mailto_action_execute - (const struct sieve_enotify_exec_env *nenv, + (const struct sieve_enotify_exec_env *nenv, const struct sieve_enotify_action *nact); const struct sieve_enotify_method_def mailto_notify = { "mailto", - NULL, NULL, + NULL, NULL, ntfy_mailto_compile_check_uri, NULL, ntfy_mailto_compile_check_from, @@ -94,9 +94,9 @@ const struct sieve_enotify_method_def mailto_notify = { }; /* - * Reserved and unique headers + * Reserved and unique headers */ - + static const char *_reserved_headers[] = { "auto-submitted", "received", @@ -138,7 +138,7 @@ struct ntfy_mailto_context { static bool ntfy_mailto_compile_check_uri (const struct sieve_enotify_env *nenv, const char *uri ATTR_UNUSED, const char *uri_body) -{ +{ return uri_mailto_validate (uri_body, _reserved_headers, _unique_headers, NTFY_MAILTO_MAX_RECIPIENTS, NTFY_MAILTO_MAX_HEADERS, nenv->ehandler); @@ -167,19 +167,19 @@ static bool ntfy_mailto_compile_check_from /* * Runtime */ - + static const char *ntfy_mailto_runtime_get_notify_capability -(const struct sieve_enotify_env *nenv ATTR_UNUSED, const char *uri ATTR_UNUSED, +(const struct sieve_enotify_env *nenv ATTR_UNUSED, const char *uri ATTR_UNUSED, const char *uri_body, const char *capability) { if ( !uri_mailto_validate(uri_body, _reserved_headers, _unique_headers, NTFY_MAILTO_MAX_RECIPIENTS, NTFY_MAILTO_MAX_HEADERS, NULL) ) { return NULL; } - - if ( strcasecmp(capability, "online") == 0 ) + + if ( strcasecmp(capability, "online") == 0 ) return "maybe"; - + return NULL; } @@ -191,10 +191,10 @@ static bool ntfy_mailto_runtime_check_uri (uri_body, _reserved_headers, _unique_headers, NTFY_MAILTO_MAX_RECIPIENTS, NTFY_MAILTO_MAX_HEADERS, NULL); } - + static bool ntfy_mailto_runtime_check_operands (const struct sieve_enotify_env *nenv, const char *uri ATTR_UNUSED, - const char *uri_body, string_t *message ATTR_UNUSED, string_t *from, + const char *uri_body, string_t *message ATTR_UNUSED, string_t *from, pool_t context_pool, void **method_context) { struct ntfy_mailto_context *mtctx; @@ -214,7 +214,7 @@ static bool ntfy_mailto_runtime_check_operands "specified :from address '%s' is invalid for " "the mailto method: %s", str_sanitize(str_c(from), 128), error); - } else + } else mtctx->from_normalized = p_strdup(context_pool, normalized); } T_END; @@ -222,7 +222,7 @@ static bool ntfy_mailto_runtime_check_operands } if ( (parsed_uri=uri_mailto_parse - (uri_body, context_pool, _reserved_headers, + (uri_body, context_pool, _reserved_headers, _unique_headers, NTFY_MAILTO_MAX_RECIPIENTS, NTFY_MAILTO_MAX_HEADERS, nenv->ehandler)) == NULL ) { return FALSE; @@ -230,7 +230,7 @@ static bool ntfy_mailto_runtime_check_operands mtctx->uri = parsed_uri; *method_context = (void *) mtctx; - return TRUE; + return TRUE; } /* @@ -238,13 +238,13 @@ static bool ntfy_mailto_runtime_check_operands */ static int ntfy_mailto_action_check_duplicates -(const struct sieve_enotify_env *nenv ATTR_UNUSED, - const struct sieve_enotify_action *nact, +(const struct sieve_enotify_env *nenv ATTR_UNUSED, + const struct sieve_enotify_action *nact, const struct sieve_enotify_action *nact_other) { - struct ntfy_mailto_context *mtctx = + struct ntfy_mailto_context *mtctx = (struct ntfy_mailto_context *) nact->method_context; - struct ntfy_mailto_context *mtctx_other = + struct ntfy_mailto_context *mtctx_other = (struct ntfy_mailto_context *) nact_other->method_context; const struct uri_mailto_recipient *new_rcpts, *old_rcpts; unsigned int new_count, old_count, i, j; @@ -257,7 +257,7 @@ static int ntfy_mailto_action_check_duplicates for ( j = 0; j < old_count; j++ ) { if ( sieve_address_compare (new_rcpts[i].normalized, old_rcpts[j].normalized, TRUE) == 0 ) - break; + break; } if ( j == old_count ) { @@ -270,7 +270,7 @@ static int ntfy_mailto_action_check_duplicates i -= del_len; new_rcpts = array_get(&mtctx->uri->recipients, &new_count); } - del_len = 0; + del_len = 0; } else { /* Mark deletion */ if ( del_len == 0 ) @@ -281,7 +281,7 @@ static int ntfy_mailto_action_check_duplicates /* Perform pending deletion */ if ( del_len > 0 ) { - array_delete(&mtctx->uri->recipients, del_start, del_len); + array_delete(&mtctx->uri->recipients, del_start, del_len); } return ( array_count(&mtctx->uri->recipients) > 0 ? 0 : 1 ); @@ -290,17 +290,17 @@ static int ntfy_mailto_action_check_duplicates /* * Action printing */ - + static void ntfy_mailto_action_print -(const struct sieve_enotify_print_env *penv, +(const struct sieve_enotify_print_env *penv, const struct sieve_enotify_action *nact) { unsigned int count, i; const struct uri_mailto_recipient *recipients; const struct uri_mailto_header_field *headers; - struct ntfy_mailto_context *mtctx = + struct ntfy_mailto_context *mtctx = (struct ntfy_mailto_context *) nact->method_context; - + /* Print main method parameters */ sieve_enotify_method_printf @@ -336,18 +336,18 @@ static void ntfy_mailto_action_print } /* Print accepted headers for notification message */ - + headers = array_get(&mtctx->uri->headers, &count); if ( count > 0 ) { - sieve_enotify_method_printf(penv, " => headers :\n" ); + sieve_enotify_method_printf(penv, " => headers :\n" ); for ( i = 0; i < count; i++ ) { - sieve_enotify_method_printf(penv, " + %s: %s\n", + sieve_enotify_method_printf(penv, " + %s: %s\n", headers[i].name, headers[i].body); } } /* Print body for notification message */ - + if ( mtctx->uri->body != NULL ) sieve_enotify_method_printf (penv, " => body : \n--\n%s\n--\n", mtctx->uri->body); @@ -369,19 +369,19 @@ static bool _contains_8bit(const char *msg) if ((*s & 0x80) != 0) return TRUE; } - + return FALSE; } static bool ntfy_mailto_send -(const struct sieve_enotify_exec_env *nenv, +(const struct sieve_enotify_exec_env *nenv, const struct sieve_enotify_action *nact, const char *recipient) -{ +{ const struct sieve_message_data *msgdata = nenv->msgdata; const struct sieve_script_env *senv = nenv->scriptenv; - struct ntfy_mailto_context *mtctx = - (struct ntfy_mailto_context *) nact->method_context; - const char *from = NULL, *from_smtp = NULL; + struct ntfy_mailto_context *mtctx = + (struct ntfy_mailto_context *) nact->method_context; + const char *from = NULL, *from_smtp = NULL; const char *subject = mtctx->uri->subject; const char *body = mtctx->uri->body; string_t *to, *cc; @@ -394,18 +394,18 @@ static bool ntfy_mailto_send /* Get recipients */ recipients = array_get(&mtctx->uri->recipients, &count); if ( count == 0 ) { - sieve_enotify_warning(nenv, + sieve_enotify_warning(nenv, "notify mailto uri specifies no recipients; action has no effect"); return TRUE; } /* Just to be sure */ if ( !sieve_smtp_available(senv) ) { - sieve_enotify_global_warning(nenv, + sieve_enotify_global_warning(nenv, "notify mailto method has no means to send mail"); return TRUE; } - + /* Determine message from address */ if ( nact->from == NULL ) { from = t_strdup_printf("Postmaster <%s>", senv->postmaster_address); @@ -421,18 +421,18 @@ static bool ntfy_mailto_send from_smtp = mtctx->from_normalized; } } - + /* Determine subject */ if ( nact->message != NULL ) { /* FIXME: handle UTF-8 */ subject = str_sanitize(nact->message, NTFY_MAILTO_MAX_SUBJECT); } else if ( subject == NULL ) { const char *const *hsubject; - + /* Fetch subject from original message */ if ( mail_get_headers_utf8 (msgdata->mail, "subject", &hsubject) >= 0 ) - subject = str_sanitize(t_strdup_printf("Notification: %s", hsubject[0]), + subject = str_sanitize(t_strdup_printf("Notification: %s", hsubject[0]), NTFY_MAILTO_MAX_SUBJECT); else subject = "Notification: (no subject)"; @@ -469,7 +469,7 @@ static bool ntfy_mailto_send smtp_handle = sieve_smtp_open (senv, recipients[i].normalized, from_smtp, &f); outmsgid = sieve_message_get_new_id(nenv->svinst); - + rfc2822_header_field_write(f, "X-Sieve", SIEVE_IMPLEMENTATION); rfc2822_header_field_write(f, "Message-ID", outmsgid); rfc2822_header_field_write(f, "Date", message_date_create(ioloop_time)); @@ -479,11 +479,11 @@ static bool ntfy_mailto_send if ( to != NULL ) rfc2822_header_field_utf8_printf(f, "To", "%s", str_c(to)); - + if ( cc != NULL ) rfc2822_header_field_utf8_printf(f, "Cc", "%s", str_c(cc)); - - rfc2822_header_field_printf(f, "Auto-Submitted", + + rfc2822_header_field_printf(f, "Auto-Submitted", "auto-notified; owner-email=\"%s\"", recipient); rfc2822_header_field_write(f, "Precedence", "bulk"); @@ -503,16 +503,16 @@ static bool ntfy_mailto_send rfc2822_header_field_write(f, "Importance", "Normal"); break; } - + /* Add custom headers */ - + headers = array_get(&mtctx->uri->headers, &hcount); for ( h = 0; h < hcount; h++ ) { const char *name = rfc2822_header_field_name_sanitize(headers[h].name); - + rfc2822_header_field_write(f, name, headers[h].body); } - + /* Generate message body */ if ( body != NULL ) { if (_contains_8bit(body)) { @@ -521,23 +521,23 @@ static bool ntfy_mailto_send (f, "Content-Type", "text/plain; charset=UTF-8"); rfc2822_header_field_write(f, "Content-Transfer-Encoding", "8bit"); } - + fprintf(f, "\r\n"); fprintf(f, "%s\r\n", body); - + } else { fprintf(f, "\r\n"); fprintf(f, "Notification of new message.\r\n"); } - + if ( sieve_smtp_close(senv, smtp_handle) ) { - sieve_enotify_global_info(nenv, - "sent mail notification to <%s>", + sieve_enotify_global_info(nenv, + "sent mail notification to <%s>", str_sanitize(recipients[i].normalized, 80)); } else { sieve_enotify_global_error(nenv, "failed to send mail notification to <%s> " - "(refer to system log for more information)", + "(refer to system log for more information)", str_sanitize(recipients[i].normalized, 80)); } } @@ -546,21 +546,21 @@ static bool ntfy_mailto_send } static bool ntfy_mailto_action_execute -(const struct sieve_enotify_exec_env *nenv, +(const struct sieve_enotify_exec_env *nenv, const struct sieve_enotify_action *nact) { const char *const *headers; const char *sender = sieve_message_get_sender(nenv->msgctx); const char *recipient = sieve_message_get_final_recipient(nenv->msgctx); - /* Is the recipient unset? + /* Is the recipient unset? */ if ( recipient == NULL ) { - sieve_enotify_global_warning(nenv, + sieve_enotify_global_warning(nenv, "notify mailto action aborted: envelope recipient is <>"); return TRUE; } - + /* Is the message an automatic reply ? */ if ( mail_get_headers (nenv->msgdata->mail, "auto-submitted", &headers) >= 0 ) { @@ -569,8 +569,8 @@ static bool ntfy_mailto_action_execute /* Theoretically multiple headers could exist, so lets make sure */ while ( *hdsp != NULL ) { if ( strcasecmp(*hdsp, "no") != 0 ) { - sieve_enotify_global_info(nenv, - "not sending notification for auto-submitted message from <%s>", + sieve_enotify_global_info(nenv, + "not sending notification for auto-submitted message from <%s>", str_sanitize(sender, 128)); return TRUE; } diff --git a/src/lib-sieve/plugins/enotify/mailto/uri-mailto.c b/src/lib-sieve/plugins/enotify/mailto/uri-mailto.c index cc9ead12a4abf4fd90bda7259fb2525801028ea9..5a49833afc91240b100921f4629462c7f2533bd3 100644 --- a/src/lib-sieve/plugins/enotify/mailto/uri-mailto.c +++ b/src/lib-sieve/plugins/enotify/mailto/uri-mailto.c @@ -1,13 +1,13 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + /* FIXME: URI syntax conforms to something somewhere in between RFC 2368 and * draft-duerst-mailto-bis-05.txt. Should fully migrate to new specification * when it matures. This requires modifications to the address parser (no * whitespace allowed within the address itself) and UTF-8 support will be * required in the URL. */ - + #include "lib.h" #include "array.h" #include "str.h" @@ -26,7 +26,7 @@ #define uri_mailto_error(PARSER, ...) \ sieve_error((PARSER)->ehandler, NULL, "invalid mailto URI: " __VA_ARGS__ ) - + #define uri_mailto_warning(PARSER, ...) \ sieve_warning((PARSER)->ehandler, NULL, "mailto URI: " __VA_ARGS__ ) @@ -45,10 +45,10 @@ struct uri_mailto_parser { int max_headers; }; -/* - * Reserved and unique headers +/* + * Reserved and unique headers */ - + static inline bool uri_mailto_header_is_reserved (struct uri_mailto_parser *parser, const char *field_name) { @@ -81,9 +81,9 @@ static inline bool uri_mailto_header_is_unique } return FALSE; -} +} -/* +/* * Low-level URI parsing. * * FIXME: much of this implementation will be common to other URI schemes. This @@ -114,36 +114,36 @@ static inline bool _is_qchar(unsigned char c) { return _qchar_lookup[c]; } - + static inline int _decode_hex_digit(unsigned char digit) { switch ( digit ) { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': return (int) digit - '0'; case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': return (int) digit - 'a' + 0x0a; - + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': return (int) digit - 'A' + 0x0A; } - + return -1; } static bool _parse_hex_value(const char **in, char *out) { int value, digit; - + if ( (digit=_decode_hex_digit((unsigned char) **in)) < 0 ) return FALSE; - + value = digit << 4; (*in)++; - + if ( (digit=_decode_hex_digit((unsigned char) **in)) < 0 ) - return FALSE; + return FALSE; value |= digit; (*in)++; @@ -152,12 +152,12 @@ static bool _parse_hex_value(const char **in, char *out) return FALSE; *out = (char) value; - return TRUE; + return TRUE; } -/* - * URI recipient parsing - */ +/* + * URI recipient parsing + */ static bool uri_mailto_add_valid_recipient (struct uri_mailto_parser *parser, string_t *recipient, bool cc) @@ -168,41 +168,41 @@ static bool uri_mailto_add_valid_recipient unsigned int count, i; const char *error; const char *normalized; - + /* Verify recipient */ if ( (normalized=sieve_address_normalize(recipient, &error)) == NULL ) { uri_mailto_error(parser, "invalid recipient '%s': %s", str_sanitize(str_c(recipient), 80), error); return FALSE; } - + /* Add recipient to the uri */ - if ( uri != NULL ) { + if ( uri != NULL ) { /* Get current recipients */ rcpts = array_get_modifiable(&uri->recipients, &count); - + /* Enforce limits */ if ( parser->max_recipients > 0 && (int)count >= parser->max_recipients ) { if ( (int)count == parser->max_recipients) { - uri_mailto_warning(parser, + uri_mailto_warning(parser, "more than the maximum %u recipients specified; " "rest is discarded", parser->max_recipients); } - return TRUE; + return TRUE; } - + /* Check for duplicate first */ for ( i = 0; i < count; i++ ) { - if ( sieve_address_compare(rcpts[i].normalized, normalized, TRUE) == 0 ) + if ( sieve_address_compare(rcpts[i].normalized, normalized, TRUE) == 0 ) { /* Upgrade existing Cc: recipient to a To: recipient if possible */ rcpts[i].carbon_copy = ( rcpts[i].carbon_copy && cc ); - + uri_mailto_warning(parser, "ignored duplicate recipient '%s'", str_sanitize(str_c(recipient), 80)); return TRUE; - } - } + } + } /* Add */ new_recipient = array_append_space(&uri->recipients); @@ -219,17 +219,17 @@ static bool uri_mailto_parse_recipients { string_t *to = t_str_new(128); const char *p = *uri_p; - + if ( *p == '\0' || *p == '?' ) return TRUE; - + while ( *p != '\0' && *p != '?' ) { if ( *p == '%' ) { /* % encoded character */ char ch; - + p++; - + /* Parse 2-digit hex value */ if ( !_parse_hex_value(&p, &ch) ) { uri_mailto_error(parser, "invalid %% encoding"); @@ -241,7 +241,7 @@ static bool uri_mailto_parse_recipients /* Verify and add recipient */ if ( !uri_mailto_add_valid_recipient(parser, to, FALSE) ) return FALSE; - + /* Reset for next recipient */ str_truncate(to, 0); } else { @@ -259,11 +259,11 @@ static bool uri_mailto_parse_recipients str_append_c(to, *p); p++; } - } - + } + /* Skip '?' */ if ( *p != '\0' ) p++; - + /* Verify and add recipient */ if ( !uri_mailto_add_valid_recipient(parser, to, FALSE) ) return FALSE; @@ -278,13 +278,13 @@ static bool uri_mailto_parse_header_recipients string_t *to = t_str_new(128); const char *p = (const char *) str_data(rcpt_header); const char *pend = p + str_len(rcpt_header); - + while ( p < pend ) { if ( *p == ',' ) { /* Verify and add recipient */ if ( !uri_mailto_add_valid_recipient(parser, to, cc) ) return FALSE; - + /* Reset for next recipient */ str_truncate(to, 0); } else { @@ -292,20 +292,20 @@ static bool uri_mailto_parse_header_recipients str_append_c(to, *p); } p++; - } - + } + /* Verify and add recipient */ if ( !uri_mailto_add_valid_recipient(parser, to, cc) ) return FALSE; - return TRUE; + return TRUE; } /* URI header parsing */ static bool uri_mailto_header_is_duplicate (struct uri_mailto_parser *parser, const char *field_name) -{ +{ struct uri_mailto *uri = parser->uri; if ( uri == NULL ) return FALSE; @@ -314,13 +314,13 @@ static bool uri_mailto_header_is_duplicate const struct uri_mailto_header_field *hdrs; unsigned int count, i; - hdrs = array_get(&uri->headers, &count); + hdrs = array_get(&uri->headers, &count); for ( i = 0; i < count; i++ ) { - if ( strcasecmp(hdrs[i].name, field_name) == 0 ) + if ( strcasecmp(hdrs[i].name, field_name) == 0 ) return TRUE; } } - + return FALSE; } @@ -331,24 +331,24 @@ static bool uri_mailto_parse_headers unsigned int header_count = 0; string_t *field = t_str_new(128); const char *p = *uri_p; - + while ( *p != '\0' ) { enum { - _HNAME_IGNORED, + _HNAME_IGNORED, _HNAME_GENERIC, _HNAME_TO, _HNAME_CC, - _HNAME_SUBJECT, - _HNAME_BODY + _HNAME_SUBJECT, + _HNAME_BODY } hname_type = _HNAME_GENERIC; struct uri_mailto_header_field *hdrf = NULL; const char *field_name; - + /* Parse field name */ while ( *p != '\0' && *p != '=' ) { char ch = *p; p++; - + if ( ch == '%' ) { /* Encoded, parse 2-digit hex value */ if ( !_parse_hex_value(&p, &ch) ) { @@ -371,18 +371,18 @@ static bool uri_mailto_parse_headers return FALSE; } - if ( parser->max_headers > -1 && + if ( parser->max_headers > -1 && (int)header_count >= parser->max_headers ) { /* Refuse to accept more headers than allowed by policy */ if ( (int)header_count == parser->max_headers ) { uri_mailto_warning(parser, "more than the maximum %u headers specified; " "rest is discarded", parser->max_headers); } - + hname_type = _HNAME_IGNORED; } else { /* Add new header field to array and assign its name */ - + field_name = str_c(field); if ( strcasecmp(field_name, "to") == 0 ) hname_type = _HNAME_TO; @@ -398,7 +398,7 @@ static bool uri_mailto_parse_headers hdrf = array_append_space(&uri->headers); hdrf->name = p_strdup(parser->pool, field_name); } else { - uri_mailto_warning(parser, + uri_mailto_warning(parser, "ignored duplicate for unique header field '%s'", str_sanitize(field_name, 32)); hname_type = _HNAME_IGNORED; @@ -412,17 +412,17 @@ static bool uri_mailto_parse_headers hname_type = _HNAME_IGNORED; } } - + header_count++; - + /* Reset for field body */ str_truncate(field, 0); - - /* Parse field body */ + + /* Parse field body */ while ( *p != '\0' && *p != '&' ) { char ch = *p; p++; - + if ( ch == '%' ) { /* Encoded, parse 2-digit hex value */ if ( !_parse_hex_value(&p, &ch) ) { @@ -437,10 +437,10 @@ static bool uri_mailto_parse_headers str_append_c(field, ch); } if ( *p != '\0' ) p++; - + /* Verify field body */ if ( hname_type == _HNAME_BODY ) { - // FIXME: verify body ... + // FIXME: verify body ... } else { if ( !rfc2822_header_field_body_verify (str_c(field), str_len(field), FALSE, FALSE) ) { @@ -448,7 +448,7 @@ static bool uri_mailto_parse_headers return FALSE; } } - + /* Assign field body */ switch ( hname_type ) { @@ -478,20 +478,20 @@ static bool uri_mailto_parse_headers if ( uri != NULL ) { if ( uri->body == NULL ) uri->body = p_strdup(parser->pool, str_c(field)); - else + else uri_mailto_warning(parser, "ignored duplicate body field"); } break; case _HNAME_GENERIC: - if ( uri != NULL && hdrf != NULL ) + if ( uri != NULL && hdrf != NULL ) hdrf->body = p_strdup(parser->pool, str_c(field)); break; } - + /* Reset for next name */ str_truncate(field, 0); - } - + } + /* Skip '&' */ if ( *p != '\0' ) p++; @@ -503,8 +503,8 @@ static bool uri_mailto_parse_uri (struct uri_mailto_parser *parser, const char *uri_body) { const char *p = uri_body; - - /* + + /* * mailtoURI = "mailto:" [ to ] [ hfields ] * to = [ addr-spec *("%2C" addr-spec ) ] * hfields = "?" hfield *( "&" hfield ) @@ -518,8 +518,8 @@ static bool uri_mailto_parse_uri * / "+" / "," / ";" / ":" / "@" * * to ~= *tqchar - * tqchar ~= <qchar> without ";" and ":" - * + * tqchar ~= <qchar> without ";" and ":" + * * Scheme 'mailto:' already parsed, starting parse after colon */ @@ -527,16 +527,16 @@ static bool uri_mailto_parse_uri */ if ( !uri_mailto_parse_recipients(parser, &p) ) - return FALSE; + return FALSE; - /* Extract hfield items */ - - while ( *p != '\0' ) { + /* Extract hfield items */ + + while ( *p != '\0' ) { /* Extract hfield item by searching for '&' and decoding '%' items */ if ( !uri_mailto_parse_headers(parser, &p) ) - return FALSE; + return FALSE; } - + return TRUE; } @@ -545,8 +545,8 @@ static bool uri_mailto_parse_uri */ bool uri_mailto_validate -(const char *uri_body, const char **reserved_headers, - const char **unique_headers, int max_recipients, int max_headers, +(const char *uri_body, const char **reserved_headers, + const char **unique_headers, int max_recipients, int max_headers, struct sieve_error_handler *ehandler) { struct uri_mailto_parser parser; @@ -557,24 +557,24 @@ bool uri_mailto_validate parser.max_headers = max_headers; parser.reserved_headers = reserved_headers; parser.unique_headers = unique_headers; - + /* If no errors are reported, we don't need to record any data */ - if ( ehandler != NULL ) { + if ( ehandler != NULL ) { parser.pool = pool_datastack_create(); parser.uri = p_new(parser.pool, struct uri_mailto, 1); p_array_init(&parser.uri->recipients, parser.pool, max_recipients); p_array_init(&parser.uri->headers, parser.pool, max_headers); } - + if ( !uri_mailto_parse_uri(&parser, uri_body) ) return FALSE; - + if ( ehandler != NULL ) { if ( array_count(&parser.uri->recipients) == 0 ) uri_mailto_warning(&parser, "notification URI specifies no recipients"); } - + return TRUE; } @@ -583,12 +583,12 @@ bool uri_mailto_validate */ struct uri_mailto *uri_mailto_parse -(const char *uri_body, pool_t pool, const char **reserved_headers, - const char **unique_headers, int max_recipients, int max_headers, +(const char *uri_body, pool_t pool, const char **reserved_headers, + const char **unique_headers, int max_recipients, int max_headers, struct sieve_error_handler *ehandler) { struct uri_mailto_parser parser; - + parser.pool = pool; parser.ehandler = ehandler; parser.max_recipients = max_recipients; @@ -599,10 +599,10 @@ struct uri_mailto *uri_mailto_parse parser.uri = p_new(pool, struct uri_mailto, 1); p_array_init(&parser.uri->recipients, pool, max_recipients); p_array_init(&parser.uri->headers, pool, max_headers); - + if ( !uri_mailto_parse_uri(&parser, uri_body) ) return FALSE; - + if ( ehandler != NULL ) { if ( array_count(&parser.uri->recipients) == 0 ) uri_mailto_warning(&parser, "notification URI specifies no recipients"); diff --git a/src/lib-sieve/plugins/enotify/mailto/uri-mailto.h b/src/lib-sieve/plugins/enotify/mailto/uri-mailto.h index 7e30d5443b97c749f5160275567d0de59705a8c4..9b9936747f5a745e5da9053e847ca7d07c2fa392 100644 --- a/src/lib-sieve/plugins/enotify/mailto/uri-mailto.h +++ b/src/lib-sieve/plugins/enotify/mailto/uri-mailto.h @@ -1,11 +1,11 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ #ifndef __URI_MAILTO_H #define __URI_MAILTO_H -/* - * Types +/* + * Types */ struct uri_mailto_header_field { @@ -31,13 +31,13 @@ struct uri_mailto { }; bool uri_mailto_validate - (const char *uri_body, const char **reserved_headers, - const char **unique_headers, int max_recipients, int max_headers, + (const char *uri_body, const char **reserved_headers, + const char **unique_headers, int max_recipients, int max_headers, struct sieve_error_handler *ehandler); struct uri_mailto *uri_mailto_parse -(const char *uri_body, pool_t pool, const char **reserved_headers, - const char **unique_headers, int max_recipients, int max_headers, +(const char *uri_body, pool_t pool, const char **reserved_headers, + const char **unique_headers, int max_recipients, int max_headers, struct sieve_error_handler *ehandler); #endif /* __URI_MAILTO_H */ diff --git a/src/lib-sieve/plugins/enotify/sieve-ext-enotify.h b/src/lib-sieve/plugins/enotify/sieve-ext-enotify.h index 816bb1acbaae0cb408d43f9d730f467d5973fa2d..28b38080a28df2f94572891322eff10eae767c44 100644 --- a/src/lib-sieve/plugins/enotify/sieve-ext-enotify.h +++ b/src/lib-sieve/plugins/enotify/sieve-ext-enotify.h @@ -23,7 +23,7 @@ struct sieve_enotify_exec_env; /* * Notify method definition - */ + */ struct sieve_enotify_method_def { const char *identifier; @@ -33,7 +33,7 @@ struct sieve_enotify_method_def { (const struct sieve_enotify_method *nmth, void **context); void (*unload) (const struct sieve_enotify_method *nmth); - + /* Validation */ bool (*compile_check_uri) (const struct sieve_enotify_env *nenv, const char *uri, @@ -43,7 +43,7 @@ struct sieve_enotify_method_def { bool (*compile_check_from) (const struct sieve_enotify_env *nenv, string_t *from); bool (*compile_check_option) - (const struct sieve_enotify_env *nenv, const char *option, + (const struct sieve_enotify_env *nenv, const char *option, const char *value); /* Runtime */ @@ -51,11 +51,11 @@ struct sieve_enotify_method_def { (const struct sieve_enotify_env *nenv, const char *uri, const char *uri_body); const char *(*runtime_get_method_capability) - (const struct sieve_enotify_env *nenv, const char *uri, + (const struct sieve_enotify_env *nenv, const char *uri, const char *uri_body, const char *capability); bool (*runtime_check_operands) - (const struct sieve_enotify_env *nenv, const char *uri, - const char *uri_body, string_t *message, string_t *from, + (const struct sieve_enotify_env *nenv, const char *uri, + const char *uri_body, string_t *message, string_t *from, pool_t context_pool, void **method_context); bool (*runtime_set_option) (const struct sieve_enotify_env *nenv, void *method_context, @@ -63,18 +63,18 @@ struct sieve_enotify_method_def { /* Action duplicates */ int (*action_check_duplicates) - (const struct sieve_enotify_env *nenv, - const struct sieve_enotify_action *nact, + (const struct sieve_enotify_env *nenv, + const struct sieve_enotify_action *nact, const struct sieve_enotify_action *nact_other); - + /* Action print */ void (*action_print) - (const struct sieve_enotify_print_env *penv, - const struct sieve_enotify_action *nact); - + (const struct sieve_enotify_print_env *penv, + const struct sieve_enotify_action *nact); + /* Action execution */ bool (*action_execute) - (const struct sieve_enotify_exec_env *nenv, + (const struct sieve_enotify_exec_env *nenv, const struct sieve_enotify_action *nact); }; @@ -91,7 +91,7 @@ struct sieve_enotify_method { }; const struct sieve_enotify_method *sieve_enotify_method_register - (struct sieve_instance *svinst, + (struct sieve_instance *svinst, const struct sieve_enotify_method_def *nmth_def); void sieve_enotify_method_unregister (const struct sieve_enotify_method *nmth); @@ -122,7 +122,7 @@ void sieve_enotify_method_printf struct sieve_enotify_exec_env { struct sieve_instance *svinst; - + const struct sieve_enotify_method *method; const struct sieve_script_env *scriptenv; @@ -135,11 +135,11 @@ struct sieve_enotify_exec_env { /* * Notify action */ - + struct sieve_enotify_action { const struct sieve_enotify_method *method; void *method_context; - + sieve_number_t importance; const char *message; const char *from; @@ -151,7 +151,7 @@ struct sieve_enotify_action { #define sieve_enotify_error(ENV, ...) \ sieve_error((ENV)->ehandler, NULL, __VA_ARGS__ ) - + #define sieve_enotify_warning(ENV, ...) \ sieve_warning((ENV)->ehandler, NULL, __VA_ARGS__ ) @@ -160,7 +160,7 @@ struct sieve_enotify_action { #define sieve_enotify_global_error(ENV, ...) \ sieve_global_error((ENV)->svinst, (ENV)->ehandler, NULL, __VA_ARGS__ ) - + #define sieve_enotify_global_warning(ENV, ...) \ sieve_global_warning((ENV)->svinst, (ENV)->ehandler, NULL, __VA_ARGS__ ) diff --git a/src/lib-sieve/plugins/enotify/tst-notify-method-capability.c b/src/lib-sieve/plugins/enotify/tst-notify-method-capability.c index be0b76c9bc9e2127cf6300254f5c27668ac937af..15e71b04f41759c1e4a59b3135cececa60e456f6 100644 --- a/src/lib-sieve/plugins/enotify/tst-notify-method-capability.c +++ b/src/lib-sieve/plugins/enotify/tst-notify-method-capability.c @@ -15,8 +15,8 @@ #include "ext-enotify-common.h" -/* - * String test +/* + * String test * * Syntax: * notify_method_capability [COMPARATOR] [MATCH-TYPE] @@ -33,19 +33,19 @@ static bool tst_notifymc_validate static bool tst_notifymc_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx); -const struct sieve_command_def notify_method_capability_test = { - "notify_method_capability", - SCT_TEST, +const struct sieve_command_def notify_method_capability_test = { + "notify_method_capability", + SCT_TEST, 3, 0, FALSE, FALSE, - tst_notifymc_registered, + tst_notifymc_registered, NULL, tst_notifymc_validate, - NULL, - tst_notifymc_generate, - NULL + NULL, + tst_notifymc_generate, + NULL }; -/* +/* * String operation */ @@ -54,31 +54,31 @@ static bool tst_notifymc_operation_dump static int tst_notifymc_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def notify_method_capability_operation = { +const struct sieve_operation_def notify_method_capability_operation = { "NOTIFY_METHOD_CAPABILITY", - &enotify_extension, - EXT_ENOTIFY_OPERATION_NOTIFY_METHOD_CAPABILITY, - tst_notifymc_operation_dump, - tst_notifymc_operation_execute + &enotify_extension, + EXT_ENOTIFY_OPERATION_NOTIFY_METHOD_CAPABILITY, + tst_notifymc_operation_dump, + tst_notifymc_operation_execute }; -/* - * Optional arguments +/* + * Optional arguments */ -enum tst_notifymc_optional { +enum tst_notifymc_optional { OPT_END, OPT_COMPARATOR, OPT_MATCH_TYPE }; -/* - * Test registration +/* + * Test registration */ static bool tst_notifymc_registered (struct sieve_validator *valdtr, const struct sieve_extension *ext ATTR_UNUSED, - struct sieve_command_registration *cmd_reg) + struct sieve_command_registration *cmd_reg) { /* The order of these is not significant */ sieve_comparators_link_tag(valdtr, cmd_reg, OPT_COMPARATOR); @@ -87,44 +87,44 @@ static bool tst_notifymc_registered return TRUE; } -/* - * Test validation +/* + * Test validation */ static bool tst_notifymc_validate -(struct sieve_validator *valdtr, struct sieve_command *tst) -{ +(struct sieve_validator *valdtr, struct sieve_command *tst) +{ struct sieve_ast_argument *arg = tst->first_positional; - const struct sieve_match_type mcht_default = + const struct sieve_match_type mcht_default = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); - const struct sieve_comparator cmp_default = + const struct sieve_comparator cmp_default = SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator); - + if ( !sieve_validate_positional_argument (valdtr, tst, arg, "notification-uri", 1, SAAT_STRING) ) { return FALSE; } - + if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) ) return FALSE; - + arg = sieve_ast_argument_next(arg); if ( !sieve_validate_positional_argument (valdtr, tst, arg, "notification-capability", 2, SAAT_STRING) ) { return FALSE; } - + if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) ) return FALSE; - + arg = sieve_ast_argument_next(arg); if ( !sieve_validate_positional_argument (valdtr, tst, arg, "key-list", 3, SAAT_STRING_LIST) ) { return FALSE; } - + if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) ) return FALSE; @@ -133,12 +133,12 @@ static bool tst_notifymc_validate (valdtr, tst, arg, &mcht_default, &cmp_default); } -/* - * Test generation +/* + * Test generation */ static bool tst_notifymc_generate - (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) + (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) { sieve_operation_emit (cgenv->sblock, cmd->ext, ¬ify_method_capability_operation); @@ -147,8 +147,8 @@ static bool tst_notifymc_generate return sieve_generate_arguments(cgenv, cmd, NULL); } -/* - * Code dump +/* + * Code dump */ static bool tst_notifymc_operation_dump @@ -160,23 +160,23 @@ static bool tst_notifymc_operation_dump /* Handle any optional arguments */ if ( sieve_match_opr_optional_dump(denv, address, NULL) != 0 ) return FALSE; - + return sieve_opr_string_dump(denv, address, "notify uri") && sieve_opr_string_dump(denv, address, "notify capability") && sieve_opr_stringlist_dump(denv, address, "key list"); } -/* - * Code execution +/* + * Code execution */ static int tst_notifymc_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) { - struct sieve_match_type mcht = + struct sieve_match_type mcht = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); - struct sieve_comparator cmp = + struct sieve_comparator cmp = SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator); string_t *notify_uri, *notify_capability; struct sieve_stringlist *value_list, *key_list; @@ -184,9 +184,9 @@ static int tst_notifymc_operation_execute int match, ret; /* - * Read operands + * Read operands */ - + /* Handle match-type and comparator operands */ if ( sieve_match_opr_optional_read (renv, address, NULL, &ret, &cmp, &mcht) < 0 ) @@ -196,14 +196,14 @@ static int tst_notifymc_operation_execute if ( (ret=sieve_opr_string_read(renv, address, "notify-uri", ¬ify_uri)) <= 0 ) return ret; - + /* Read notify capability */ if ( (ret=sieve_opr_string_read (renv, address, "notify-capability", ¬ify_capability)) <= 0 ) return ret; - + /* Read key-list */ - if ( (ret=sieve_opr_stringlist_read(renv, address, "key-list", &key_list)) + if ( (ret=sieve_opr_stringlist_read(renv, address, "key-list", &key_list)) <= 0) return ret; @@ -220,7 +220,7 @@ static int tst_notifymc_operation_execute value_list = sieve_single_stringlist_create_cstr(renv, cap_value, TRUE); /* Perform match */ - if ( (match=sieve_match(renv, &mcht, &cmp, value_list, key_list, &ret)) + if ( (match=sieve_match(renv, &mcht, &cmp, value_list, key_list, &ret)) < 0 ) return ret; } else { diff --git a/src/lib-sieve/plugins/enotify/tst-valid-notify-method.c b/src/lib-sieve/plugins/enotify/tst-valid-notify-method.c index 5717e9f6e343d53492e021fcfee6d3f9e3e46957..0af8a7bd75f40c2ee173552610dcec135b155722 100644 --- a/src/lib-sieve/plugins/enotify/tst-valid-notify-method.c +++ b/src/lib-sieve/plugins/enotify/tst-valid-notify-method.c @@ -15,8 +15,8 @@ #include "ext-enotify-common.h" -/* - * Valid_notify_method test +/* + * Valid_notify_method test * * Syntax: * valid_notify_method <notification-uris: string-list> @@ -27,18 +27,18 @@ static bool tst_vnotifym_validate static bool tst_vnotifym_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx); -const struct sieve_command_def valid_notify_method_test = { - "valid_notify_method", - SCT_TEST, +const struct sieve_command_def valid_notify_method_test = { + "valid_notify_method", + SCT_TEST, 1, 0, FALSE, FALSE, NULL, NULL, tst_vnotifym_validate, - NULL, - tst_vnotifym_generate, - NULL + NULL, + tst_vnotifym_generate, + NULL }; -/* +/* * Valid_notify_method operation */ @@ -47,37 +47,37 @@ static bool tst_vnotifym_operation_dump static int tst_vnotifym_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def valid_notify_method_operation = { +const struct sieve_operation_def valid_notify_method_operation = { "VALID_NOTIFY_METHOD", - &enotify_extension, - EXT_ENOTIFY_OPERATION_VALID_NOTIFY_METHOD, - tst_vnotifym_operation_dump, - tst_vnotifym_operation_execute + &enotify_extension, + EXT_ENOTIFY_OPERATION_VALID_NOTIFY_METHOD, + tst_vnotifym_operation_dump, + tst_vnotifym_operation_execute }; -/* - * Test validation +/* + * Test validation */ static bool tst_vnotifym_validate - (struct sieve_validator *valdtr, struct sieve_command *tst) -{ + (struct sieve_validator *valdtr, struct sieve_command *tst) +{ struct sieve_ast_argument *arg = tst->first_positional; - + if ( !sieve_validate_positional_argument (valdtr, tst, arg, "notification-uris", 1, SAAT_STRING_LIST) ) { return FALSE; } - + return sieve_validator_argument_activate(valdtr, tst, arg, FALSE); } -/* - * Test generation +/* + * Test generation */ static bool tst_vnotifym_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) { sieve_operation_emit(cgenv->sblock, cmd->ext, &valid_notify_method_operation); @@ -85,8 +85,8 @@ static bool tst_vnotifym_generate return sieve_generate_arguments(cgenv, cmd, NULL); } -/* - * Code dump +/* + * Code dump */ static bool tst_vnotifym_operation_dump @@ -94,13 +94,13 @@ static bool tst_vnotifym_operation_dump { sieve_code_dumpf(denv, "VALID_NOTIFY_METHOD"); sieve_code_descend(denv); - + return sieve_opr_stringlist_dump(denv, address, "notify-uris"); } -/* - * Code execution +/* + * Code execution */ static int tst_vnotifym_operation_execute @@ -112,14 +112,14 @@ static int tst_vnotifym_operation_execute int ret; /* - * Read operands + * Read operands */ - + /* Read notify uris */ if ( (ret=sieve_opr_stringlist_read - (renv, address, "notify-uris", ¬ify_uris)) <= 0 ) + (renv, address, "notify-uris", ¬ify_uris)) <= 0 ) return ret; - + /* * Perform operation */ @@ -127,18 +127,18 @@ static int tst_vnotifym_operation_execute sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, "valid_notify_method test"); uri_item = NULL; - while ( (ret=sieve_stringlist_next_item(notify_uris, &uri_item)) > 0 ) { + while ( (ret=sieve_stringlist_next_item(notify_uris, &uri_item)) > 0 ) { if ( !ext_enotify_runtime_method_validate(renv, uri_item) ) { all_valid = FALSE; break; } } - + if ( ret < 0 ) { sieve_runtime_trace_error(renv, "invalid method uri item"); return SIEVE_EXEC_BIN_CORRUPT; } - + sieve_interpreter_set_test_result(renv->interp, all_valid); return SIEVE_EXEC_OK; } diff --git a/src/lib-sieve/plugins/enotify/vmodf-encodeurl.c b/src/lib-sieve/plugins/enotify/vmodf-encodeurl.c index 43b937162b38adb1af02250165f23df98c07cde9..3b0e03521d37230a72dd9647a36e0c3db230b771 100644 --- a/src/lib-sieve/plugins/enotify/vmodf-encodeurl.c +++ b/src/lib-sieve/plugins/enotify/vmodf-encodeurl.c @@ -14,15 +14,15 @@ /* * Encodeurl modifier */ - + bool mod_encodeurl_modify(string_t *in, string_t **result); - + const struct sieve_variables_modifier_def encodeurl_modifier = { SIEVE_OBJECT("encodeurl", &encodeurl_operand, 0), 15, mod_encodeurl_modify }; - + /* * Modifier operand */ @@ -30,10 +30,10 @@ const struct sieve_variables_modifier_def encodeurl_modifier = { static const struct sieve_extension_objects ext_enotify_modifiers = SIEVE_VARIABLES_DEFINE_MODIFIER(encodeurl_modifier); -const struct sieve_operand_def encodeurl_operand = { - "modifier", +const struct sieve_operand_def encodeurl_operand = { + "modifier", &enotify_extension, - 0, + 0, &sieve_variables_modifier_operand_class, &ext_enotify_modifiers }; @@ -63,22 +63,22 @@ static const char _uri_reserved_lookup[256] = { }; bool mod_encodeurl_modify(string_t *in, string_t **result) -{ +{ unsigned int i; const unsigned char *c; *result = t_str_new(2*str_len(in)); c = str_data(in); - + for ( i = 0; i < str_len(in); i++, c++ ) { if ( _uri_reserved_lookup[*c] ) { str_printfa(*result, "%%%02X", *c); } else { - str_append_c(*result, *c); - } + str_append_c(*result, *c); + } } return TRUE; } - + diff --git a/src/lib-sieve/plugins/environment/ext-environment-common.c b/src/lib-sieve/plugins/environment/ext-environment-common.c index 7657dc24c94ee2270d7e8030e45eda9f4e7f781d..8f4000a932bf09ec07d9cc3db4b664329b47c84a 100644 --- a/src/lib-sieve/plugins/environment/ext-environment-common.c +++ b/src/lib-sieve/plugins/environment/ext-environment-common.c @@ -18,11 +18,11 @@ struct ext_environment_context { */ static const struct sieve_environment_item *core_env_items[] = { - &domain_env_item, - &host_env_item, - &location_env_item, - &phase_env_item, - &name_env_item, + &domain_env_item, + &host_env_item, + &location_env_item, + &phase_env_item, + &name_env_item, &version_env_item }; @@ -33,7 +33,7 @@ static unsigned int core_env_items_count = N_ELEMENTS(core_env_items); */ static void ext_environment_item_register -(struct ext_environment_context *ectx, +(struct ext_environment_context *ectx, const struct sieve_environment_item *item) { hash_table_insert @@ -43,9 +43,9 @@ static void ext_environment_item_register void sieve_ext_environment_item_register (const struct sieve_extension *ext, const struct sieve_environment_item *item) { - struct ext_environment_context *ectx = + struct ext_environment_context *ectx = (struct ext_environment_context *) ext->context; - + ext_environment_item_register(ectx, item); } @@ -54,9 +54,9 @@ void sieve_ext_environment_item_register */ bool ext_environment_init -(const struct sieve_extension *ext ATTR_UNUSED, void **context) +(const struct sieve_extension *ext ATTR_UNUSED, void **context) { - struct ext_environment_context *ectx = + struct ext_environment_context *ectx = i_new(struct ext_environment_context, 1); unsigned int i; @@ -75,7 +75,7 @@ bool ext_environment_init void ext_environment_deinit(const struct sieve_extension *ext) { - struct ext_environment_context *ectx = + struct ext_environment_context *ectx = (struct ext_environment_context *) ext->context; hash_table_destroy(&ectx->environment_items); @@ -88,13 +88,13 @@ void ext_environment_deinit(const struct sieve_extension *ext) */ const char *ext_environment_item_get_value -(const struct sieve_extension *ext, const char *name, +(const struct sieve_extension *ext, const char *name, const struct sieve_script_env *senv) { - struct ext_environment_context *ectx = + struct ext_environment_context *ectx = (struct ext_environment_context *) ext->context; - const struct sieve_environment_item *item = - (const struct sieve_environment_item *) + const struct sieve_environment_item *item = + (const struct sieve_environment_item *) hash_table_lookup(ectx->environment_items, name); if ( item == NULL ) @@ -109,7 +109,7 @@ const char *ext_environment_item_get_value return ( value == NULL ? "" : value ); } - return NULL; + return NULL; } /* @@ -118,7 +118,7 @@ const char *ext_environment_item_get_value /* "domain": * - * The primary DNS domain associated with the Sieve execution context, usually + * The primary DNS domain associated with the Sieve execution context, usually * but not always a proper suffix of the host name. */ const struct sieve_environment_item domain_env_item = { @@ -129,7 +129,7 @@ const struct sieve_environment_item domain_env_item = { /* "host": * - * The fully-qualified domain name of the host where the Sieve script is + * The fully-qualified domain name of the host where the Sieve script is * executing. */ @@ -147,11 +147,11 @@ const struct sieve_environment_item host_env_item = { /* "location": * - * Sieve evaluation can be performed at various different points as messages + * Sieve evaluation can be performed at various different points as messages * are processed. This item provides additional information about the type of * service that is evaluating the script. Possible values are: - * "MTA" - the Sieve script is being evaluated by a Message Transfer Agent - * "MDA" - evaluation is being performed by a Mail Delivery Agent + * "MTA" - the Sieve script is being evaluated by a Message Transfer Agent + * "MDA" - evaluation is being performed by a Mail Delivery Agent * "MUA" - evaluation is being performed by a Mail User Agent * "MS" - evaluation is being performed by a Message Store */ @@ -164,8 +164,8 @@ const struct sieve_environment_item location_env_item = { /* "phase": * * The point relative to final delivery where the Sieve script is being - * evaluated. Possible values are "pre", "during", and "post", referring - * respectively to processing before, during, and after final delivery has + * evaluated. Possible values are "pre", "during", and "post", referring + * respectively to processing before, during, and after final delivery has * taken place. */ @@ -187,7 +187,7 @@ const struct sieve_environment_item name_env_item = { /* "version": * - * The product version associated with the Sieve interpreter. The meaning of the + * The product version associated with the Sieve interpreter. The meaning of the * product version string is product-specific and should always be considered * in the context of the product name given by the "name" item. */ diff --git a/src/lib-sieve/plugins/environment/ext-environment-common.h b/src/lib-sieve/plugins/environment/ext-environment-common.h index e579f52acaa500c33f5b5f3186b91308f8fba952..b1fcc00535f9f48d5a89d72c89892f3255645112 100644 --- a/src/lib-sieve/plugins/environment/ext-environment-common.h +++ b/src/lib-sieve/plugins/environment/ext-environment-common.h @@ -16,8 +16,8 @@ extern const struct sieve_extension_def environment_extension; -/* - * Commands +/* + * Commands */ extern const struct sieve_command_def tst_environment; @@ -51,7 +51,7 @@ void ext_environment_deinit(const struct sieve_extension *ext); */ const char *ext_environment_item_get_value - (const struct sieve_extension *ext, const char *name, + (const struct sieve_extension *ext, const char *name, const struct sieve_script_env *senv); #endif /* __EXT_VARIABLES_COMMON_H */ diff --git a/src/lib-sieve/plugins/environment/ext-environment.c b/src/lib-sieve/plugins/environment/ext-environment.c index c288321859e0d19ef837d96a7c0e75d5e9fc1a87..46f4b59c12ce4a2886ea3e2569104af8b847a52a 100644 --- a/src/lib-sieve/plugins/environment/ext-environment.c +++ b/src/lib-sieve/plugins/environment/ext-environment.c @@ -30,14 +30,14 @@ static bool ext_environment_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr); - -const struct sieve_extension_def environment_extension = { - "environment", - ext_environment_init, + +const struct sieve_extension_def environment_extension = { + "environment", + ext_environment_init, ext_environment_deinit, ext_environment_validator_load, NULL, NULL, NULL, NULL, NULL, - SIEVE_EXT_DEFINE_OPERATION(tst_environment_operation), + SIEVE_EXT_DEFINE_OPERATION(tst_environment_operation), SIEVE_EXT_DEFINE_NO_OPERANDS }; @@ -45,7 +45,7 @@ static bool ext_environment_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr) { sieve_validator_register_command(valdtr, ext, &tst_environment); - + return TRUE; } diff --git a/src/lib-sieve/plugins/environment/sieve-ext-environment.h b/src/lib-sieve/plugins/environment/sieve-ext-environment.h index cede06d3f6e96f0d04365191ceb03d3b42412825..a1f9399263282c51698d2e65922139d37d586060 100644 --- a/src/lib-sieve/plugins/environment/sieve-ext-environment.h +++ b/src/lib-sieve/plugins/environment/sieve-ext-environment.h @@ -8,14 +8,14 @@ struct sieve_environment_item { const char *name; - + const char *value; const char *(*get_value) (struct sieve_instance *svinst, const struct sieve_script_env *senv); }; void sieve_ext_environment_item_register - (const struct sieve_extension *ext, + (const struct sieve_extension *ext, const struct sieve_environment_item *item); #endif diff --git a/src/lib-sieve/plugins/environment/tst-environment.c b/src/lib-sieve/plugins/environment/tst-environment.c index d08a8b721217eac0a5988ef60adcddedca180279..10b7353875fd77e67491eb37d0631366f85c41aa 100644 --- a/src/lib-sieve/plugins/environment/tst-environment.c +++ b/src/lib-sieve/plugins/environment/tst-environment.c @@ -15,8 +15,8 @@ #include "ext-environment-common.h" -/* - * Environment test +/* + * Environment test * * Syntax: * environment [COMPARATOR] [MATCH-TYPE] @@ -31,19 +31,19 @@ static bool tst_environment_validate static bool tst_environment_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd); -const struct sieve_command_def tst_environment = { - "environment", - SCT_TEST, +const struct sieve_command_def tst_environment = { + "environment", + SCT_TEST, 2, 0, FALSE, FALSE, - tst_environment_registered, + tst_environment_registered, NULL, tst_environment_validate, - NULL, - tst_environment_generate, - NULL + NULL, + tst_environment_generate, + NULL }; -/* +/* * Environment operation */ @@ -52,21 +52,21 @@ static bool tst_environment_operation_dump static int tst_environment_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def tst_environment_operation = { +const struct sieve_operation_def tst_environment_operation = { "ENVIRONMENT", - &environment_extension, - 0, - tst_environment_operation_dump, - tst_environment_operation_execute + &environment_extension, + 0, + tst_environment_operation_dump, + tst_environment_operation_execute }; -/* - * Test registration +/* + * Test registration */ static bool tst_environment_registered (struct sieve_validator *valdtr, const struct sieve_extension *ext ATTR_UNUSED, - struct sieve_command_registration *cmd_reg) + struct sieve_command_registration *cmd_reg) { /* The order of these is not significant */ sieve_comparators_link_tag(valdtr, cmd_reg, SIEVE_MATCH_OPT_COMPARATOR); @@ -75,34 +75,34 @@ static bool tst_environment_registered return TRUE; } -/* - * Test validation +/* + * Test validation */ static bool tst_environment_validate -(struct sieve_validator *valdtr, struct sieve_command *tst) -{ +(struct sieve_validator *valdtr, struct sieve_command *tst) +{ struct sieve_ast_argument *arg = tst->first_positional; - const struct sieve_match_type mcht_default = + const struct sieve_match_type mcht_default = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); - const struct sieve_comparator cmp_default = + const struct sieve_comparator cmp_default = SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator); - + if ( !sieve_validate_positional_argument (valdtr, tst, arg, "name", 1, SAAT_STRING) ) { return FALSE; } - + if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) ) return FALSE; - + arg = sieve_ast_argument_next(arg); if ( !sieve_validate_positional_argument (valdtr, tst, arg, "key list", 2, SAAT_STRING_LIST) ) { return FALSE; } - + if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) ) return FALSE; @@ -111,24 +111,24 @@ static bool tst_environment_validate (valdtr, tst, arg, &mcht_default, &cmp_default); } -/* - * Test generation +/* + * Test generation */ static bool tst_environment_generate - (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) + (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) { sieve_operation_emit(cgenv->sblock, cmd->ext, &tst_environment_operation); /* Generate arguments */ if ( !sieve_generate_arguments(cgenv, cmd, NULL) ) return FALSE; - + return TRUE; } -/* - * Code dump +/* + * Code dump */ static bool tst_environment_operation_dump @@ -140,23 +140,23 @@ static bool tst_environment_operation_dump /* Optional operands */ if ( sieve_match_opr_optional_dump(denv, address, NULL) != 0 ) return FALSE; - + return sieve_opr_string_dump(denv, address, "name") && sieve_opr_stringlist_dump(denv, address, "key list"); } -/* - * Code execution +/* + * Code execution */ static int tst_environment_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) { const struct sieve_extension *this_ext = renv->oprtn->ext; - struct sieve_match_type mcht = + struct sieve_match_type mcht = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); - struct sieve_comparator cmp = + struct sieve_comparator cmp = SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator); string_t *name; struct sieve_stringlist *value_list, *key_list; @@ -164,9 +164,9 @@ static int tst_environment_operation_execute int match, ret; /* - * Read operands + * Read operands */ - + /* Handle match-type and comparator operands */ if ( sieve_match_opr_optional_read (renv, address, NULL, &ret, &cmp, &mcht) < 0 ) @@ -175,9 +175,9 @@ static int tst_environment_operation_execute /* Read source */ if ( (ret=sieve_opr_string_read(renv, address, "name", &name)) <= 0 ) return ret; - + /* Read key-list */ - if ( (ret=sieve_opr_stringlist_read(renv, address, "key-list", &key_list)) + if ( (ret=sieve_opr_stringlist_read(renv, address, "key-list", &key_list)) <= 0 ) return ret; @@ -195,8 +195,8 @@ static int tst_environment_operation_execute value_list = sieve_single_stringlist_create_cstr(renv, env_item, FALSE); /* Perform match */ - if ( (match=sieve_match(renv, &mcht, &cmp, value_list, key_list, &ret)) - < 0 ) + if ( (match=sieve_match(renv, &mcht, &cmp, value_list, key_list, &ret)) + < 0 ) return ret; } else { match = 0; diff --git a/src/lib-sieve/plugins/ihave/ext-ihave-binary.c b/src/lib-sieve/plugins/ihave/ext-ihave-binary.c index 2c5eb3e5dab16d52a113bdfac96f807e4be743ed..49b8b9e4f554808ad0f281d0c039bf979a8afb61 100644 --- a/src/lib-sieve/plugins/ihave/ext-ihave-binary.c +++ b/src/lib-sieve/plugins/ihave/ext-ihave-binary.c @@ -19,7 +19,7 @@ /* * Forward declarations */ - + static bool ext_ihave_binary_save (const struct sieve_extension *ext, struct sieve_binary *sbin, void *context); static bool ext_ihave_binary_open @@ -28,10 +28,10 @@ static bool ext_ihave_binary_up_to_date (const struct sieve_extension *ext, struct sieve_binary *sbin, void *context, enum sieve_compile_flags cpflags); -/* +/* * Binary include extension */ - + const struct sieve_binary_extension ihave_binary_ext = { &ihave_extension, ext_ihave_binary_save, @@ -43,11 +43,11 @@ const struct sieve_binary_extension ihave_binary_ext = { /* * Binary context management */ - + struct ext_ihave_binary_context { struct sieve_binary *binary; struct sieve_binary_block *block; - + ARRAY_DEFINE(missing_extensions, const char *); }; @@ -55,11 +55,11 @@ static struct ext_ihave_binary_context *ext_ihave_binary_create_context (const struct sieve_extension *this_ext, struct sieve_binary *sbin) { pool_t pool = sieve_binary_pool(sbin); - - struct ext_ihave_binary_context *ctx = + + struct ext_ihave_binary_context *ctx = p_new(pool, struct ext_ihave_binary_context, 1); - - ctx->binary = sbin; + + ctx->binary = sbin; p_array_init(&ctx->missing_extensions, pool, 64); sieve_binary_extension_set(sbin, this_ext, &ihave_binary_ext, ctx); @@ -68,18 +68,18 @@ static struct ext_ihave_binary_context *ext_ihave_binary_create_context struct ext_ihave_binary_context *ext_ihave_binary_get_context (const struct sieve_extension *this_ext, struct sieve_binary *sbin) -{ +{ struct ext_ihave_binary_context *ctx = (struct ext_ihave_binary_context *) sieve_binary_extension_get_context(sbin, this_ext); - + if ( ctx == NULL ) ctx = ext_ihave_binary_create_context(this_ext, sbin); - + return ctx; } - + struct ext_ihave_binary_context *ext_ihave_binary_init -(const struct sieve_extension *this_ext, struct sieve_binary *sbin, +(const struct sieve_extension *this_ext, struct sieve_binary *sbin, struct sieve_ast *ast) { struct ext_ihave_ast_context *ast_ctx = @@ -87,7 +87,7 @@ struct ext_ihave_binary_context *ext_ihave_binary_init struct ext_ihave_binary_context *binctx; const char *const *exts; unsigned int i, count; - + binctx = ext_ihave_binary_get_context(this_ext, sbin); exts = array_get(&ast_ctx->missing_extensions, &count); @@ -97,14 +97,14 @@ struct ext_ihave_binary_context *ext_ihave_binary_init if ( binctx->block == NULL ) binctx->block = sieve_binary_extension_create_block(sbin, this_ext); - + for ( i = 0; i < count; i++ ) { const char *ext_name = p_strdup(pool, exts[i]); array_append(&binctx->missing_extensions, &ext_name, 1); } - } - + } + return binctx; } @@ -115,7 +115,7 @@ struct ext_ihave_binary_context *ext_ihave_binary_init static bool ext_ihave_binary_save (const struct sieve_extension *ext, struct sieve_binary *sbin, void *context) { - struct ext_ihave_binary_context *binctx = + struct ext_ihave_binary_context *binctx = (struct ext_ihave_binary_context *) context; const char *const *exts; unsigned int count, i; @@ -124,7 +124,7 @@ static bool ext_ihave_binary_save if ( binctx->block != NULL ) sieve_binary_block_clear(binctx->block); - + if ( count > 0 ) { if ( binctx->block == NULL ) binctx->block = sieve_binary_extension_create_block(sbin, ext); @@ -135,7 +135,7 @@ static bool ext_ihave_binary_save sieve_binary_emit_cstring(binctx->block, exts[i]); } } - + return TRUE; } @@ -143,38 +143,38 @@ static bool ext_ihave_binary_open (const struct sieve_extension *ext, struct sieve_binary *sbin, void *context) { struct sieve_instance *svinst = ext->svinst; - struct ext_ihave_binary_context *binctx = + struct ext_ihave_binary_context *binctx = (struct ext_ihave_binary_context *) context; struct sieve_binary_block *sblock; unsigned int i, count, block_id; sieve_size_t offset; - + sblock = sieve_binary_extension_get_block(sbin, ext); if ( sblock != NULL ) { binctx->block = sblock; block_id = sieve_binary_block_get_id(sblock); - - offset = 0; - + + offset = 0; + /* Read number of missing extensions to read subsequently */ if ( !sieve_binary_read_unsigned(sblock, &offset, &count) ) { - sieve_sys_error(svinst, + sieve_sys_error(svinst, "ihave: failed to read missing extension count " "from block %d of binary %s", block_id, sieve_binary_path(sbin)); return FALSE; } - + /* Read dependencies */ for ( i = 0; i < count; i++ ) { string_t *ext_name; const char *name; - + if ( !sieve_binary_read_string(sblock, &offset, &ext_name) ) { /* Binary is corrupt, recompile */ sieve_sys_error(svinst, "ihave: failed to read missing extension name " - "from block %d of binary %s", block_id, sieve_binary_path(sbin)); + "from block %d of binary %s", block_id, sieve_binary_path(sbin)); return FALSE; } @@ -182,27 +182,27 @@ static bool ext_ihave_binary_open array_append(&binctx->missing_extensions, &name, 1); } } - - return TRUE; + + return TRUE; } static bool ext_ihave_binary_up_to_date -(const struct sieve_extension *ext, struct sieve_binary *sbin ATTR_UNUSED, +(const struct sieve_extension *ext, struct sieve_binary *sbin ATTR_UNUSED, void *context, enum sieve_compile_flags cpflags) { - struct ext_ihave_binary_context *binctx = + struct ext_ihave_binary_context *binctx = (struct ext_ihave_binary_context *) context; const struct sieve_extension *mext; const char *const *mexts; unsigned int count, i; - + mexts = array_get(&binctx->missing_extensions, &count); for ( i = 0; i < count; i++ ) { if ( (mext=sieve_extension_get_by_name(ext->svinst, mexts[i])) != NULL && ((cpflags & SIEVE_COMPILE_FLAG_NOGLOBAL) == 0 || !mext->global) ) return FALSE; } - + return TRUE; } @@ -222,23 +222,23 @@ bool ext_ihave_binary_dump (const struct sieve_extension *ext, struct sieve_dumptime_env *denv) { struct sieve_binary *sbin = denv->sbin; - struct ext_ihave_binary_context *binctx = + struct ext_ihave_binary_context *binctx = ext_ihave_binary_get_context(ext, sbin); const char *const *exts; unsigned int count, i; - + exts = array_get(&binctx->missing_extensions, &count); if ( count > 0 ) { sieve_binary_dump_sectionf(denv, - "Extensions missing at compile (block: %d)", + "Extensions missing at compile (block: %d)", sieve_binary_block_get_id(binctx->block)); - for ( i = 0; i < count; i++ ) { + for ( i = 0; i < count; i++ ) { sieve_binary_dumpf(denv, " - %s\n", exts[i]); } - } - + } + return TRUE; } diff --git a/src/lib-sieve/plugins/ihave/ext-ihave-binary.h b/src/lib-sieve/plugins/ihave/ext-ihave-binary.h index 123d98cd2bdf8b70def3872fd22c203e23614b80..dc22672697b552cc19b893647b5cc6ffdd9e4222 100644 --- a/src/lib-sieve/plugins/ihave/ext-ihave-binary.h +++ b/src/lib-sieve/plugins/ihave/ext-ihave-binary.h @@ -7,13 +7,13 @@ /* * Binary context management */ - + struct ext_ihave_binary_context; struct ext_ihave_binary_context *ext_ihave_binary_get_context (const struct sieve_extension *this_ext, struct sieve_binary *sbin); struct ext_ihave_binary_context *ext_ihave_binary_init - (const struct sieve_extension *this_ext, struct sieve_binary *sbin, + (const struct sieve_extension *this_ext, struct sieve_binary *sbin, struct sieve_ast *ast); /* diff --git a/src/lib-sieve/plugins/ihave/ext-ihave-common.c b/src/lib-sieve/plugins/ihave/ext-ihave-common.c index 6989bad5b1c17f98c088fa4f17042ddc810934cc..185e87aab218328443b2ae6ce660e202824c62c8 100644 --- a/src/lib-sieve/plugins/ihave/ext-ihave-common.c +++ b/src/lib-sieve/plugins/ihave/ext-ihave-common.c @@ -34,9 +34,9 @@ struct ext_ihave_ast_context *ext_ihave_get_ast_context void ext_ihave_ast_add_missing_extension (const struct sieve_extension *this_ext, struct sieve_ast *ast, - const char *ext_name) + const char *ext_name) { - struct ext_ihave_ast_context *actx = + struct ext_ihave_ast_context *actx = ext_ihave_get_ast_context(this_ext, ast); const char *const *exts; unsigned int i, count; diff --git a/src/lib-sieve/plugins/ihave/ext-ihave.c b/src/lib-sieve/plugins/ihave/ext-ihave.c index 9fc0c7f1995353585706d753e00452c16fa384a8..1d908a13719bfede5875bfca3de586eb046a7179 100644 --- a/src/lib-sieve/plugins/ihave/ext-ihave.c +++ b/src/lib-sieve/plugins/ihave/ext-ihave.c @@ -37,7 +37,7 @@ const struct sieve_extension_def ihave_extension = { NULL, NULL, ext_ihave_validator_load, ext_ihave_generator_load, - NULL, + NULL, ext_ihave_binary_load, ext_ihave_binary_dump, NULL, diff --git a/src/lib-sieve/plugins/ihave/tst-ihave.c b/src/lib-sieve/plugins/ihave/tst-ihave.c index 8c54d54b8143744222aef9c505ab6671e8cacfd0..c47f0e4e5a26b8b5425fd05205f2e749dcc301d8 100644 --- a/src/lib-sieve/plugins/ihave/tst-ihave.c +++ b/src/lib-sieve/plugins/ihave/tst-ihave.c @@ -12,8 +12,8 @@ #include "ext-ihave-common.h" -/* - * Ihave test +/* + * Ihave test * * Syntax: * ihave <capabilities: string-list> @@ -25,9 +25,9 @@ static bool tst_ihave_validate_const (struct sieve_validator *valdtr, struct sieve_command *tst, int *const_current, int const_next); -const struct sieve_command_def ihave_test = { - "ihave", - SCT_TEST, +const struct sieve_command_def ihave_test = { + "ihave", + SCT_TEST, 1, 0, FALSE, FALSE, NULL, NULL, tst_ihave_validate, @@ -41,16 +41,16 @@ const struct sieve_command_def ihave_test = { static bool tst_ihave_validate (struct sieve_validator *valdtr, struct sieve_command *tst) -{ - struct _capability { - const struct sieve_extension *ext; +{ + struct _capability { + const struct sieve_extension *ext; struct sieve_ast_argument *arg; }; struct sieve_ast_argument *arg = tst->first_positional; struct sieve_ast_argument *stritem; enum sieve_compile_flags cpflags = sieve_validator_compile_flags(valdtr); - bool no_global = ( (cpflags & SIEVE_COMPILE_FLAG_NOGLOBAL) != 0 ); + bool no_global = ( (cpflags & SIEVE_COMPILE_FLAG_NOGLOBAL) != 0 ); ARRAY_DEFINE(capabilities, struct _capability); struct _capability capability; const struct _capability *caps; @@ -88,7 +88,7 @@ static bool tst_ihave_validate case SAAT_STRING_LIST: /* String list */ stritem = sieve_ast_strlist_first(arg); - + while ( stritem != NULL ) { capability.arg = stritem; capability.ext = sieve_extension_get_by_name @@ -102,7 +102,7 @@ static bool tst_ihave_validate } else { array_append(&capabilities, &capability, 1); } - + stritem = sieve_ast_strlist_next(stritem); } @@ -143,7 +143,7 @@ static bool tst_ihave_validate } tst->data = (void *) TRUE; - return TRUE; + return TRUE; } static bool tst_ihave_validate_const diff --git a/src/lib-sieve/plugins/imap4flags/Makefile.am b/src/lib-sieve/plugins/imap4flags/Makefile.am index c9c099811ff9f1d73f8dff2d9c7afe50d290a06d..a511bacdcf6cad84b722ce380daca13739d0e3ca 100644 --- a/src/lib-sieve/plugins/imap4flags/Makefile.am +++ b/src/lib-sieve/plugins/imap4flags/Makefile.am @@ -21,7 +21,7 @@ libsieve_ext_imap4flags_la_SOURCES = \ $(tags) \ ext-imap4flags.c \ ext-imapflags.c - + noinst_HEADERS = \ ext-imap4flags-common.h diff --git a/src/lib-sieve/plugins/imap4flags/cmd-flag.c b/src/lib-sieve/plugins/imap4flags/cmd-flag.c index 0c86df1606e86ee6a85b4d70f4664fe99ea3164b..74e3e56a9330dae549cf21b6317ec04ed0eb4923 100644 --- a/src/lib-sieve/plugins/imap4flags/cmd-flag.c +++ b/src/lib-sieve/plugins/imap4flags/cmd-flag.c @@ -6,7 +6,7 @@ #include "sieve-code.h" #include "sieve-stringlist.h" #include "sieve-commands.h" -#include "sieve-validator.h" +#include "sieve-validator.h" #include "sieve-generator.h" #include "sieve-interpreter.h" #include "sieve-dump.h" @@ -22,59 +22,59 @@ static bool cmd_flag_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx); -/* Setflag command +/* Setflag command * - * Syntax: + * Syntax: * setflag [<variablename: string>] <list-of-flags: string-list> */ - -const struct sieve_command_def cmd_setflag = { - "setflag", + +const struct sieve_command_def cmd_setflag = { + "setflag", SCT_COMMAND, -1, /* We check positional arguments ourselves */ - 0, FALSE, FALSE, + 0, FALSE, FALSE, NULL, NULL, ext_imap4flags_command_validate, - NULL, - cmd_flag_generate, - NULL + NULL, + cmd_flag_generate, + NULL }; -/* Addflag command +/* Addflag command * * Syntax: * addflag [<variablename: string>] <list-of-flags: string-list> */ -const struct sieve_command_def cmd_addflag = { - "addflag", +const struct sieve_command_def cmd_addflag = { + "addflag", SCT_COMMAND, -1, /* We check positional arguments ourselves */ - 0, FALSE, FALSE, + 0, FALSE, FALSE, NULL, NULL, ext_imap4flags_command_validate, NULL, - cmd_flag_generate, - NULL + cmd_flag_generate, + NULL }; -/* Removeflag command +/* Removeflag command * * Syntax: * removeflag [<variablename: string>] <list-of-flags: string-list> */ -const struct sieve_command_def cmd_removeflag = { - "removeflag", +const struct sieve_command_def cmd_removeflag = { + "removeflag", SCT_COMMAND, -1, /* We check positional arguments ourselves */ - 0, FALSE, FALSE, + 0, FALSE, FALSE, NULL, NULL, ext_imap4flags_command_validate, NULL, - cmd_flag_generate, - NULL + cmd_flag_generate, + NULL }; /* @@ -90,7 +90,7 @@ static int cmd_flag_operation_execute /* Setflag operation */ -const struct sieve_operation_def setflag_operation = { +const struct sieve_operation_def setflag_operation = { "SETFLAG", &imap4flags_extension, ext_imap4flags_OPERATION_SETFLAG, @@ -100,42 +100,42 @@ const struct sieve_operation_def setflag_operation = { /* Addflag operation */ -const struct sieve_operation_def addflag_operation = { +const struct sieve_operation_def addflag_operation = { "ADDFLAG", &imap4flags_extension, ext_imap4flags_OPERATION_ADDFLAG, - cmd_flag_operation_dump, + cmd_flag_operation_dump, cmd_flag_operation_execute }; /* Removeflag operation */ -const struct sieve_operation_def removeflag_operation = { +const struct sieve_operation_def removeflag_operation = { "REMOVEFLAG", &imap4flags_extension, ext_imap4flags_OPERATION_REMOVEFLAG, - cmd_flag_operation_dump, - cmd_flag_operation_execute + cmd_flag_operation_dump, + cmd_flag_operation_execute }; -/* - * Code generation +/* + * Code generation */ static bool cmd_flag_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) { /* Emit operation */ - if ( sieve_command_is(cmd, cmd_setflag) ) + if ( sieve_command_is(cmd, cmd_setflag) ) sieve_operation_emit(cgenv->sblock, cmd->ext, &setflag_operation); - else if ( sieve_command_is(cmd, cmd_addflag) ) + else if ( sieve_command_is(cmd, cmd_addflag) ) sieve_operation_emit(cgenv->sblock, cmd->ext, &addflag_operation); - else if ( sieve_command_is(cmd, cmd_removeflag) ) + else if ( sieve_command_is(cmd, cmd_removeflag) ) sieve_operation_emit(cgenv->sblock, cmd->ext, &removeflag_operation); /* Generate arguments */ if ( !sieve_generate_arguments(cgenv, cmd, NULL) ) - return FALSE; + return FALSE; return TRUE; } @@ -151,23 +151,23 @@ bool cmd_flag_operation_dump sieve_code_dumpf(denv, "%s", sieve_operation_mnemonic(denv->oprtn)); sieve_code_descend(denv); - + sieve_code_mark(denv); if ( !sieve_operand_read(denv->sblock, address, NULL, &oprnd) ) { sieve_code_dumpf(denv, "ERROR: INVALID OPERAND"); return FALSE; } - if ( sieve_operand_is_variable(&oprnd) ) { - return + if ( sieve_operand_is_variable(&oprnd) ) { + return sieve_opr_string_dump_data(denv, &oprnd, address, "variable name") && sieve_opr_stringlist_dump(denv, address, "list of flags"); } - - return + + return sieve_opr_stringlist_dump_data(denv, &oprnd, address, "list of flags"); } - + /* * Code execution */ @@ -182,33 +182,33 @@ static int cmd_flag_operation_execute unsigned int var_index; ext_imapflag_flag_operation_t flag_op; int ret; - - /* - * Read operands + + /* + * Read operands */ /* Read bare operand (two types possible) */ if ( (ret=sieve_operand_runtime_read (renv, address, NULL, &oprnd)) <= 0 ) return ret; - + /* Variable operand (optional) */ - if ( sieve_operand_is_variable(&oprnd) ) { + if ( sieve_operand_is_variable(&oprnd) ) { /* Read the variable operand */ if ( (ret=sieve_variable_operand_read_data (renv, &oprnd, address, "variable", &storage, &var_index)) <= 0 ) return ret; /* Read flag list */ - if ( (ret=sieve_opr_stringlist_read(renv, address, "flag-list", &flag_list)) + if ( (ret=sieve_opr_stringlist_read(renv, address, "flag-list", &flag_list)) <= 0 ) return ret; - + /* Flag-list operand */ - } else if ( sieve_operand_is_stringlist(&oprnd) ) { + } else if ( sieve_operand_is_stringlist(&oprnd) ) { storage = NULL; var_index = 0; - + /* Read flag list */ if ( (ret=sieve_opr_stringlist_read_data (renv, &oprnd, address, "flag-list", &flag_list)) <= 0 ) @@ -221,11 +221,11 @@ static int cmd_flag_operation_execute "but found %s", sieve_operand_name(&oprnd)); return SIEVE_EXEC_BIN_CORRUPT; } - + /* * Perform operation - */ - + */ + /* Determine what to do */ if ( sieve_operation_is(op, setflag_operation) ) { diff --git a/src/lib-sieve/plugins/imap4flags/ext-imap4flags-common.c b/src/lib-sieve/plugins/imap4flags/ext-imap4flags-common.c index f9a6bebb1ebdfd89ff37c471568c3dc4414350c0..b0b262334cf210823f70159b3762ce3987131738 100644 --- a/src/lib-sieve/plugins/imap4flags/ext-imap4flags-common.c +++ b/src/lib-sieve/plugins/imap4flags/ext-imap4flags-common.c @@ -10,7 +10,7 @@ #include "sieve-code.h" #include "sieve-stringlist.h" #include "sieve-actions.h" -#include "sieve-validator.h" +#include "sieve-validator.h" #include "sieve-generator.h" #include "sieve-interpreter.h" #include "sieve-result.h" @@ -26,15 +26,15 @@ static bool flag_is_valid(const char *flag); -/* - * Tagged arguments +/* + * Tagged arguments */ extern const struct sieve_argument_def tag_flags; extern const struct sieve_argument_def tag_flags_implicit; -/* - * Common command functions +/* + * Common command functions */ bool ext_imap4flags_command_validate @@ -43,78 +43,78 @@ bool ext_imap4flags_command_validate struct sieve_ast_argument *arg = cmd->first_positional; struct sieve_ast_argument *arg2; const struct sieve_extension *var_ext; - + /* Check arguments */ - + if ( arg == NULL ) { - sieve_command_validate_error(valdtr, cmd, - "the %s %s expects at least one argument, but none was found", + sieve_command_validate_error(valdtr, cmd, + "the %s %s expects at least one argument, but none was found", sieve_command_identifier(cmd), sieve_command_type_name(cmd)); return FALSE; } - - if ( sieve_ast_argument_type(arg) != SAAT_STRING && - sieve_ast_argument_type(arg) != SAAT_STRING_LIST ) + + if ( sieve_ast_argument_type(arg) != SAAT_STRING && + sieve_ast_argument_type(arg) != SAAT_STRING_LIST ) { - sieve_argument_validate_error(valdtr, arg, + sieve_argument_validate_error(valdtr, arg, "the %s %s expects either a string (variable name) or " - "a string-list (list of flags) as first argument, but %s was found", + "a string-list (list of flags) as first argument, but %s was found", sieve_command_identifier(cmd), sieve_command_type_name(cmd), sieve_ast_argument_name(arg)); - return FALSE; + return FALSE; } arg2 = sieve_ast_argument_next(arg); - if ( arg2 != NULL ) { + if ( arg2 != NULL ) { /* First, check syntax sanity */ - - if ( sieve_ast_argument_type(arg) != SAAT_STRING ) + + if ( sieve_ast_argument_type(arg) != SAAT_STRING ) { if ( sieve_command_is(cmd, tst_hasflag) ) { if ( sieve_ast_argument_type(arg) != SAAT_STRING_LIST ) { - sieve_argument_validate_error(valdtr, arg, + sieve_argument_validate_error(valdtr, arg, "if a second argument is specified for the hasflag, the first " "must be a string-list (variable-list), but %s was found", sieve_ast_argument_name(arg)); return FALSE; } } else { - sieve_argument_validate_error(valdtr, arg, + sieve_argument_validate_error(valdtr, arg, "if a second argument is specified for the %s %s, the first " "must be a string (variable name), but %s was found", - sieve_command_identifier(cmd), sieve_command_type_name(cmd), + sieve_command_identifier(cmd), sieve_command_type_name(cmd), sieve_ast_argument_name(arg)); - return FALSE; + return FALSE; } } - + /* Then, check whether the second argument is permitted */ - + var_ext = sieve_ext_variables_get_extension(cmd->ext->svinst); - if ( var_ext == NULL || !sieve_ext_variables_is_active(var_ext, valdtr) ) + if ( var_ext == NULL || !sieve_ext_variables_is_active(var_ext, valdtr) ) { - sieve_argument_validate_error(valdtr,arg, + sieve_argument_validate_error(valdtr,arg, "the %s %s only allows for the specification of a " "variable name when the variables extension is active", sieve_command_identifier(cmd), sieve_command_type_name(cmd)); return FALSE; - } - + } + if ( !sieve_variable_argument_activate (var_ext, valdtr, cmd, arg, !sieve_command_is(cmd, tst_hasflag) ) ) return FALSE; - - if ( sieve_ast_argument_type(arg2) != SAAT_STRING && - sieve_ast_argument_type(arg2) != SAAT_STRING_LIST ) + + if ( sieve_ast_argument_type(arg2) != SAAT_STRING && + sieve_ast_argument_type(arg2) != SAAT_STRING_LIST ) { - sieve_argument_validate_error(valdtr, arg2, + sieve_argument_validate_error(valdtr, arg2, "the %s %s expects a string list (list of flags) as " "second argument when two arguments are specified, " "but %s was found", sieve_command_identifier(cmd), sieve_command_type_name(cmd), sieve_ast_argument_name(arg2)); - return FALSE; + return FALSE; } } else arg2 = arg; @@ -122,11 +122,11 @@ bool ext_imap4flags_command_validate if ( !sieve_validator_argument_activate(valdtr, cmd, arg2, FALSE) ) return FALSE; - if ( !sieve_command_is(cmd, tst_hasflag) && + if ( !sieve_command_is(cmd, tst_hasflag) && sieve_argument_is_string_literal(arg2) ) { struct ext_imap4flags_iter fiter; const char *flag; - + /* Warn the user about validity of verifiable flags */ ext_imap4flags_iter_init(&fiter, sieve_ast_argument_str(arg)); @@ -134,7 +134,7 @@ bool ext_imap4flags_command_validate if ( !flag_is_valid(flag) ) { sieve_argument_validate_warning(valdtr, arg, "IMAP flag '%s' specified for the %s command is invalid " - "and will be ignored (only first invalid is reported)", + "and will be ignored (only first invalid is reported)", str_sanitize(flag, 64), sieve_command_identifier(cmd)); break; } @@ -144,19 +144,19 @@ bool ext_imap4flags_command_validate return TRUE; } -/* - * Flags tag registration +/* + * Flags tag registration */ void ext_imap4flags_attach_flags_tag (struct sieve_validator *valdtr, const struct sieve_extension *ext, const char *command, bool implicit) { - /* Register :flags tag with the command and we don't care whether it is - * registered or even whether it will be registered at all. The validator - * handles either situation gracefully + /* Register :flags tag with the command and we don't care whether it is + * registered or even whether it will be registered at all. The validator + * handles either situation gracefully */ - + if ( !implicit ) { /* Tag specified by user */ sieve_validator_register_external_tag @@ -168,8 +168,8 @@ void ext_imap4flags_attach_flags_tag (valdtr, command, ext, &tag_flags_implicit); } -/* - * Result context +/* + * Result context */ struct ext_imap4flags_result_context { @@ -179,13 +179,13 @@ struct ext_imap4flags_result_context { static void _get_initial_flags (struct sieve_result *result, string_t *flags) { - const struct sieve_message_data *msgdata = + const struct sieve_message_data *msgdata = sieve_result_get_message_data(result); enum mail_flags mail_flags; const char *const *mail_keywords; mail_flags = mail_get_flags(msgdata->mail); - mail_keywords = mail_get_keywords(msgdata->mail); + mail_keywords = mail_get_keywords(msgdata->mail); if ( (mail_flags & MAIL_FLAGGED) > 0 ) str_printfa(flags, " \\flagged"); @@ -205,14 +205,14 @@ static void _get_initial_flags while ( *mail_keywords != NULL ) { str_printfa(flags, " %s", *mail_keywords); mail_keywords++; - } + } } static inline struct ext_imap4flags_result_context *_get_result_context (const struct sieve_extension *this_ext, struct sieve_result *result) { struct ext_imap4flags_result_context *rctx = - (struct ext_imap4flags_result_context *) + (struct ext_imap4flags_result_context *) sieve_result_extension_get_context(result, this_ext); if ( rctx == NULL ) { @@ -232,20 +232,20 @@ static inline struct ext_imap4flags_result_context *_get_result_context static string_t *_get_flags_string (const struct sieve_extension *this_ext, struct sieve_result *result) { - struct ext_imap4flags_result_context *ctx = + struct ext_imap4flags_result_context *ctx = _get_result_context(this_ext, result); - + return ctx->internal_flags; } -/* - * Runtime initialization +/* + * Runtime initialization */ static void ext_imap4flags_runtime_init -(const struct sieve_extension *ext, const struct sieve_runtime_env *renv, +(const struct sieve_extension *ext, const struct sieve_runtime_env *renv, void *context ATTR_UNUSED) -{ +{ sieve_result_add_implicit_side_effect (renv->result, NULL, TRUE, ext, &flags_side_effect, NULL); } @@ -256,11 +256,11 @@ const struct sieve_interpreter_extension imap4flags_interpreter_extension = { NULL, }; -/* +/* * Flag handling */ -/* FIXME: This currently accepts a potentially unlimited number of +/* FIXME: This currently accepts a potentially unlimited number of * flags, making the internal or variable flag list indefinitely long */ @@ -315,17 +315,17 @@ static void ext_imap4flags_iter_clear (struct ext_imap4flags_iter *iter) { memset(iter, 0, sizeof(*iter)); -} +} void ext_imap4flags_iter_init -(struct ext_imap4flags_iter *iter, string_t *flags_list) +(struct ext_imap4flags_iter *iter, string_t *flags_list) { ext_imap4flags_iter_clear(iter); iter->flags_list = flags_list; } static string_t *ext_imap4flags_iter_get_flag_str -(struct ext_imap4flags_iter *iter) +(struct ext_imap4flags_iter *iter) { unsigned int len; const unsigned char *fp; @@ -336,10 +336,10 @@ static string_t *ext_imap4flags_iter_get_flag_str /* Return if not initialized */ if ( iter->flags_list == NULL ) return NULL; - /* Return if no more flags are available */ + /* Return if no more flags are available */ len = str_len(iter->flags_list); if ( iter->offset >= len ) return NULL; - + /* Mark string boundries */ fbegin = str_data(iter->flags_list); fend = fbegin + len; @@ -357,21 +357,21 @@ static string_t *ext_imap4flags_iter_get_flag_str /* Return flag */ string_t *flag = t_str_new(fp-fstart+1); str_append_n(flag, fstart, fp-fstart); - + iter->last = fstart - fbegin; iter->offset = fp - fbegin; return flag; - } - + } + fstart = fp + 1; } - + if ( fp >= fend ) break; - + fp++; } - + iter->last = fstart - fbegin; iter->offset = fp - fbegin; return NULL; @@ -388,7 +388,7 @@ const char *ext_imap4flags_iter_get_flag } static void ext_imap4flags_iter_delete_last -(struct ext_imap4flags_iter *iter) +(struct ext_imap4flags_iter *iter) { iter->offset++; if ( iter->offset > str_len(iter->flags_list) ) @@ -396,8 +396,8 @@ static void ext_imap4flags_iter_delete_last if ( iter->offset == str_len(iter->flags_list) && iter->last > 0 ) iter->last--; - str_delete(iter->flags_list, iter->last, iter->offset - iter->last); - + str_delete(iter->flags_list, iter->last, iter->offset - iter->last); + iter->offset = iter->last; } @@ -408,14 +408,14 @@ static bool flags_list_flag_exists { const char *flg; struct ext_imap4flags_iter flit; - + ext_imap4flags_iter_init(&flit, flags_list); - + while ( (flg=ext_imap4flags_iter_get_flag(&flit)) != NULL ) { - if ( strcasecmp(flg, flag) == 0 ) - return TRUE; + if ( strcasecmp(flg, flag) == 0 ) + return TRUE; } - + return FALSE; } @@ -424,43 +424,43 @@ static void flags_list_flag_delete { const char *flg; struct ext_imap4flags_iter flit; - + ext_imap4flags_iter_init(&flit, flags_list); - + while ( (flg=ext_imap4flags_iter_get_flag(&flit)) != NULL ) { if ( strcasecmp(flg, flag) == 0 ) { ext_imap4flags_iter_delete_last(&flit); - } + } } } - + static void flags_list_add_flags (string_t *flags_list, string_t *flags) -{ +{ const char *flg; struct ext_imap4flags_iter flit; - + ext_imap4flags_iter_init(&flit, flags); - + while ( (flg=ext_imap4flags_iter_get_flag(&flit)) != NULL ) { if ( flag_is_valid(flg) && !flags_list_flag_exists(flags_list, flg) ) { - if ( str_len(flags_list) != 0 ) - str_append_c(flags_list, ' '); + if ( str_len(flags_list) != 0 ) + str_append_c(flags_list, ' '); str_append(flags_list, flg); - } + } } } static void flags_list_remove_flags (string_t *flags_list, string_t *flags) -{ +{ const char *flg; struct ext_imap4flags_iter flit; - + ext_imap4flags_iter_init(&flit, flags); - + while ( (flg=ext_imap4flags_iter_get_flag(&flit)) != NULL ) { - flags_list_flag_delete(flags_list, flg); + flags_list_flag_delete(flags_list, flg); } } @@ -482,15 +482,15 @@ static string_t *ext_imap4flags_get_flag_variable unsigned int var_index) { string_t *flags; - + if ( storage != NULL ) { if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) { const char *var_name, *var_id; - + (void)sieve_variable_get_identifier(storage, var_index, &var_name); var_id = sieve_variable_get_varid(storage, var_index); - sieve_runtime_trace(renv, 0, "update variable `%s' [%s]", + sieve_runtime_trace(renv, 0, "update variable `%s' [%s]", var_name, var_id); } @@ -509,21 +509,21 @@ int ext_imap4flags_set_flags { string_t *cur_flags = ext_imap4flags_get_flag_variable (renv, storage, var_index); - + if ( cur_flags != NULL ) { string_t *flags_item; int ret; flags_list_clear_flags(cur_flags); while ( (ret=sieve_stringlist_next_item(flags, &flags_item)) > 0 ) { - sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, - "set flags `%s'", str_c(flags_item)); + sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, + "set flags `%s'", str_c(flags_item)); flags_list_add_flags(cur_flags, flags_item); } if ( ret < 0 ) return SIEVE_EXEC_BIN_CORRUPT; - + return SIEVE_EXEC_OK; } @@ -531,25 +531,25 @@ int ext_imap4flags_set_flags } int ext_imap4flags_add_flags -(const struct sieve_runtime_env *renv, struct sieve_variable_storage *storage, +(const struct sieve_runtime_env *renv, struct sieve_variable_storage *storage, unsigned int var_index, struct sieve_stringlist *flags) { string_t *cur_flags = ext_imap4flags_get_flag_variable (renv, storage, var_index); - + if ( cur_flags != NULL ) { string_t *flags_item; int ret; while ( (ret=sieve_stringlist_next_item(flags, &flags_item)) > 0 ) { - sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, - "add flags `%s'", str_c(flags_item)); + sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, + "add flags `%s'", str_c(flags_item)); flags_list_add_flags(cur_flags, flags_item); } if ( ret < 0 ) return SIEVE_EXEC_BIN_CORRUPT; - + return SIEVE_EXEC_OK; } @@ -557,25 +557,25 @@ int ext_imap4flags_add_flags } int ext_imap4flags_remove_flags -(const struct sieve_runtime_env *renv, struct sieve_variable_storage *storage, +(const struct sieve_runtime_env *renv, struct sieve_variable_storage *storage, unsigned int var_index, struct sieve_stringlist *flags) { string_t *cur_flags = ext_imap4flags_get_flag_variable (renv, storage, var_index); - + if ( cur_flags != NULL ) { string_t *flags_item; int ret; while ( (ret=sieve_stringlist_next_item(flags, &flags_item)) > 0 ) { - sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, - "remove flags `%s'", str_c(flags_item)); + sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, + "remove flags `%s'", str_c(flags_item)); flags_list_remove_flags(cur_flags, flags_item); } if ( ret < 0 ) return SIEVE_EXEC_BIN_CORRUPT; - + return SIEVE_EXEC_OK; } @@ -644,9 +644,9 @@ static struct sieve_stringlist *ext_imap4flags_stringlist_create_single static int ext_imap4flags_stringlist_next_item (struct sieve_stringlist *_strlist, string_t **str_r) { - struct ext_imap4flags_stringlist *strlist = + struct ext_imap4flags_stringlist *strlist = (struct ext_imap4flags_stringlist *)_strlist; - + while ( (*str_r=ext_imap4flags_iter_get_flag_str(&strlist->flit)) == NULL ) { int ret; @@ -658,7 +658,7 @@ static int ext_imap4flags_stringlist_next_item return ret; if ( strlist->flags_string == NULL ) - return -1; + return -1; if ( strlist->normalize ) { string_t *flags_string = t_str_new(256); @@ -676,7 +676,7 @@ static int ext_imap4flags_stringlist_next_item static void ext_imap4flags_stringlist_reset (struct sieve_stringlist *_strlist) { - struct ext_imap4flags_stringlist *strlist = + struct ext_imap4flags_stringlist *strlist = (struct ext_imap4flags_stringlist *)_strlist; if ( strlist->flags_list != NULL ) { @@ -704,11 +704,11 @@ void ext_imap4flags_get_implicit_flags_init struct sieve_result *result) { string_t *cur_flags = _get_flags_string(this_ext, result); - - ext_imap4flags_iter_init(iter, cur_flags); + + ext_imap4flags_iter_init(iter, cur_flags); } - - + + diff --git a/src/lib-sieve/plugins/imap4flags/ext-imap4flags-common.h b/src/lib-sieve/plugins/imap4flags/ext-imap4flags-common.h index e6db69aabeef53f612e9dccd9432f9cd960905a3..a5f19ab2761c840681818b342776b34a5d54bfa3 100644 --- a/src/lib-sieve/plugins/imap4flags/ext-imap4flags-common.h +++ b/src/lib-sieve/plugins/imap4flags/ext-imap4flags-common.h @@ -12,9 +12,9 @@ /* * Extension */ - + extern const struct sieve_extension_def imap4flags_extension; -extern const struct sieve_interpreter_extension +extern const struct sieve_interpreter_extension imap4flags_interpreter_extension; /* @@ -32,7 +32,7 @@ extern const struct sieve_operand_def flags_side_effect_operand; /* * Operations */ - + enum ext_imap4flags_opcode { ext_imap4flags_OPERATION_SETFLAG, ext_imap4flags_OPERATION_ADDFLAG, @@ -45,8 +45,8 @@ extern const struct sieve_operation_def addflag_operation; extern const struct sieve_operation_def removeflag_operation; extern const struct sieve_operation_def hasflag_operation; -/* - * Commands +/* + * Commands */ extern const struct sieve_command_def cmd_setflag; @@ -64,14 +64,14 @@ bool ext_imap4flags_command_validate /* * Flags tagged argument - */ - + */ + void ext_imap4flags_attach_flags_tag (struct sieve_validator *valdtr, const struct sieve_extension *ext, const char *command, bool implicit); -/* - * Flag management +/* + * Flag management */ struct ext_imap4flags_iter { @@ -82,7 +82,7 @@ struct ext_imap4flags_iter { void ext_imap4flags_iter_init (struct ext_imap4flags_iter *iter, string_t *flags_list); - + const char *ext_imap4flags_iter_get_flag (struct ext_imap4flags_iter *iter); diff --git a/src/lib-sieve/plugins/imap4flags/ext-imap4flags.c b/src/lib-sieve/plugins/imap4flags/ext-imap4flags.c index b614af889201dbb76a7a9f15331b919b24d99776..0f88ea1bec1f6f6320bb82d433b33e3a03597d8f 100644 --- a/src/lib-sieve/plugins/imap4flags/ext-imap4flags.c +++ b/src/lib-sieve/plugins/imap4flags/ext-imap4flags.c @@ -27,35 +27,35 @@ #include "ext-imap4flags-common.h" -/* - * Operations +/* + * Operations */ -const struct sieve_operation_def *imap4flags_operations[] = { - &setflag_operation, - &addflag_operation, +const struct sieve_operation_def *imap4flags_operations[] = { + &setflag_operation, + &addflag_operation, &removeflag_operation, - &hasflag_operation + &hasflag_operation }; -/* +/* * Extension */ static bool ext_imap4flags_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr); static bool ext_imap4flags_interpreter_load - (const struct sieve_extension *ext, const struct sieve_runtime_env *renv, + (const struct sieve_extension *ext, const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_extension_def imap4flags_extension = { - "imap4flags", +const struct sieve_extension_def imap4flags_extension = { + "imap4flags", NULL, NULL, - ext_imap4flags_validator_load, - NULL, - ext_imap4flags_interpreter_load, + ext_imap4flags_validator_load, + NULL, + ext_imap4flags_interpreter_load, NULL, NULL, NULL, - SIEVE_EXT_DEFINE_OPERATIONS(imap4flags_operations), + SIEVE_EXT_DEFINE_OPERATIONS(imap4flags_operations), SIEVE_EXT_DEFINE_OPERAND(flags_side_effect_operand) }; @@ -68,7 +68,7 @@ static bool ext_imap4flags_validator_load sieve_validator_register_command(valdtr, ext, &cmd_removeflag); sieve_validator_register_command(valdtr, ext, &tst_hasflag); - /* Attach :flags tag to keep and fileinto commands */ + /* Attach :flags tag to keep and fileinto commands */ ext_imap4flags_attach_flags_tag(valdtr, ext, "keep", FALSE); ext_imap4flags_attach_flags_tag(valdtr, ext, "fileinto", FALSE); @@ -76,7 +76,7 @@ static bool ext_imap4flags_validator_load } static bool ext_imap4flags_interpreter_load -(const struct sieve_extension *ext, const struct sieve_runtime_env *renv, +(const struct sieve_extension *ext, const struct sieve_runtime_env *renv, sieve_size_t *address ATTR_UNUSED) { sieve_interpreter_extension_register diff --git a/src/lib-sieve/plugins/imap4flags/ext-imapflags.c b/src/lib-sieve/plugins/imap4flags/ext-imapflags.c index f98f13f4862dea584188fb93bd452b03f8c9b830..7e0a1db5d2fc4afc49ba1069e899b07d4a86e686 100644 --- a/src/lib-sieve/plugins/imap4flags/ext-imapflags.c +++ b/src/lib-sieve/plugins/imap4flags/ext-imapflags.c @@ -64,7 +64,7 @@ static const struct sieve_command_def cmd_unmark = { NULL, NULL, NULL }; -/* +/* * Extension */ @@ -76,24 +76,24 @@ static bool ext_imapflags_interpreter_load (const struct sieve_extension *ext, const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_extension_def imapflags_extension = { - "imapflags", - ext_imapflags_load, +const struct sieve_extension_def imapflags_extension = { + "imapflags", + ext_imapflags_load, NULL, - ext_imapflags_validator_load, + ext_imapflags_validator_load, NULL, - ext_imapflags_interpreter_load, + ext_imapflags_interpreter_load, NULL, NULL, NULL, - SIEVE_EXT_DEFINE_NO_OPERATIONS, + SIEVE_EXT_DEFINE_NO_OPERATIONS, SIEVE_EXT_DEFINE_NO_OPERANDS }; static bool ext_imapflags_load (const struct sieve_extension *ext, void **context) { - if ( *context == NULL ) { + if ( *context == NULL ) { /* Make sure real extension is registered, it is needed by the binary */ - *context = (void *) + *context = (void *) sieve_extension_require(ext->svinst, &imap4flags_extension, FALSE); } @@ -105,7 +105,7 @@ static bool ext_imapflags_load */ static bool ext_imapflags_validator_extension_validate - (const struct sieve_extension *ext, struct sieve_validator *valdtr, + (const struct sieve_extension *ext, struct sieve_validator *valdtr, void *context, struct sieve_ast_argument *require_arg); const struct sieve_validator_extension imapflags_validator_extension = { @@ -117,7 +117,7 @@ const struct sieve_validator_extension imapflags_validator_extension = { static bool ext_imapflags_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr) { - const struct sieve_extension *master_ext = + const struct sieve_extension *master_ext = (const struct sieve_extension *) ext->context; sieve_validator_extension_register @@ -129,12 +129,12 @@ static bool ext_imapflags_validator_load sieve_validator_register_command(valdtr, master_ext, &cmd_removeflag); sieve_validator_register_command(valdtr, master_ext, &cmd_mark); - sieve_validator_register_command(valdtr, master_ext, &cmd_unmark); + sieve_validator_register_command(valdtr, master_ext, &cmd_unmark); /* Attach implicit flags tag to keep and fileinto commands */ ext_imap4flags_attach_flags_tag(valdtr, master_ext, "keep", TRUE); ext_imap4flags_attach_flags_tag(valdtr, master_ext, "fileinto", TRUE); - + return TRUE; } @@ -142,7 +142,7 @@ static bool ext_imapflags_validator_extension_validate (const struct sieve_extension *ext, struct sieve_validator *valdtr, void *context ATTR_UNUSED, struct sieve_ast_argument *require_arg) { - const struct sieve_extension *master_ext = + const struct sieve_extension *master_ext = (const struct sieve_extension *) ext->context; if ( sieve_validator_extension_loaded(valdtr, master_ext) ) { @@ -163,7 +163,7 @@ static bool ext_imapflags_interpreter_load (const struct sieve_extension *ext, const struct sieve_runtime_env *renv, sieve_size_t *address ATTR_UNUSED) { - const struct sieve_extension *master_ext = + const struct sieve_extension *master_ext = (const struct sieve_extension *) ext->context; sieve_interpreter_extension_register @@ -174,7 +174,7 @@ static bool ext_imapflags_interpreter_load /* * Command validation - */ + */ static bool cmd_mark_validate (struct sieve_validator *valdtr, struct sieve_command *cmd) @@ -189,7 +189,7 @@ static bool cmd_mark_validate if ( !sieve_validator_argument_activate (valdtr, cmd, cmd->first_positional, FALSE) ) - return FALSE; - + return FALSE; + return TRUE; } diff --git a/src/lib-sieve/plugins/imap4flags/tag-flags.c b/src/lib-sieve/plugins/imap4flags/tag-flags.c index 06b73e0e3ee753fdc4e85a56632c996f78e6dfec..112aec463d956e735517df2c681b13d9d895f06f 100644 --- a/src/lib-sieve/plugins/imap4flags/tag-flags.c +++ b/src/lib-sieve/plugins/imap4flags/tag-flags.c @@ -11,7 +11,7 @@ #include "sieve-extensions.h" #include "sieve-commands.h" #include "sieve-result.h" -#include "sieve-validator.h" +#include "sieve-validator.h" #include "sieve-generator.h" #include "sieve-interpreter.h" #include "sieve-actions.h" @@ -21,12 +21,12 @@ #include <ctype.h> -/* +/* * Flags tagged argument */ static bool tag_flags_validate - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); static bool tag_flags_validate_persistent (struct sieve_validator *valdtr, struct sieve_command *cmd, @@ -35,43 +35,43 @@ static bool tag_flags_generate (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *cmd); -const struct sieve_argument_def tag_flags = { - "flags", - NULL, - tag_flags_validate, +const struct sieve_argument_def tag_flags = { + "flags", + NULL, + tag_flags_validate, NULL, NULL, - tag_flags_generate + tag_flags_generate }; -const struct sieve_argument_def tag_flags_implicit = { - "flags-implicit", - NULL, NULL, NULL, - tag_flags_validate_persistent, +const struct sieve_argument_def tag_flags_implicit = { + "flags-implicit", + NULL, NULL, NULL, + tag_flags_validate_persistent, tag_flags_generate }; -/* - * Side effect +/* + * Side effect */ static bool seff_flags_dump_context (const struct sieve_side_effect *seffect, const struct sieve_dumptime_env *denv, sieve_size_t *address); static int seff_flags_read_context - (const struct sieve_side_effect *seffect, + (const struct sieve_side_effect *seffect, const struct sieve_runtime_env *renv, sieve_size_t *address, void **context); static int seff_flags_merge - (const struct sieve_runtime_env *renv, const struct sieve_action *action, - const struct sieve_side_effect *old_seffect, + (const struct sieve_runtime_env *renv, const struct sieve_action *action, + const struct sieve_side_effect *old_seffect, const struct sieve_side_effect *new_seffect, void **old_context); static void seff_flags_print (const struct sieve_side_effect *seffect, const struct sieve_action *action, const struct sieve_result_print_env *rpenv, bool *keep); static bool seff_flags_pre_execute - (const struct sieve_side_effect *seffect, const struct sieve_action *action, + (const struct sieve_side_effect *seffect, const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void **context, void *tr_context); const struct sieve_side_effect_def flags_side_effect = { @@ -82,7 +82,7 @@ const struct sieve_side_effect_def flags_side_effect = { seff_flags_read_context, seff_flags_merge, seff_flags_print, - seff_flags_pre_execute, + seff_flags_pre_execute, NULL, NULL, NULL }; @@ -93,16 +93,16 @@ const struct sieve_side_effect_def flags_side_effect = { static const struct sieve_extension_objects ext_side_effects = SIEVE_EXT_DEFINE_SIDE_EFFECT(flags_side_effect); -const struct sieve_operand_def flags_side_effect_operand = { - "flags operand", +const struct sieve_operand_def flags_side_effect_operand = { + "flags operand", &imap4flags_extension, - 0, + 0, &sieve_side_effect_operand_class, &ext_side_effects }; -/* - * Tag validation +/* + * Tag validation */ static bool tag_flags_validate_persistent @@ -112,19 +112,19 @@ static bool tag_flags_validate_persistent if ( sieve_command_find_argument(cmd, &tag_flags) == NULL ) { sieve_command_add_dynamic_tag(cmd, ext, &tag_flags_implicit, -1); } - + return TRUE; } static bool tag_flags_validate -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd) { struct sieve_ast_argument *tag = *arg; /* Detach the tag itself */ *arg = sieve_ast_argument_next(*arg); - + /* Check syntax: * :flags <list-of-flags: string-list> */ @@ -132,17 +132,17 @@ static bool tag_flags_validate (valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING_LIST, FALSE) ) { return FALSE; } - + tag->parameters = *arg; - + /* Detach parameter */ *arg = sieve_ast_arguments_detach(*arg,1); return TRUE; } -/* - * Code generation +/* + * Code generation */ static bool tag_flags_generate @@ -162,28 +162,28 @@ static bool tag_flags_generate /* Explicit :flags tag */ param = arg->parameters; - /* Call the generation function for the argument */ - if ( param->argument != NULL && param->argument->def != NULL && - param->argument->def->generate != NULL && - !param->argument->def->generate(cgenv, param, cmd) ) + /* Call the generation function for the argument */ + if ( param->argument != NULL && param->argument->def != NULL && + param->argument->def->generate != NULL && + !param->argument->def->generate(cgenv, param, cmd) ) return FALSE; } else if ( sieve_argument_is(arg, tag_flags_implicit) ) { /* Implicit flags */ sieve_opr_omitted_emit(cgenv->sblock); - + } else { /* Something else?! */ i_unreached(); } - + return TRUE; } -/* +/* * Side effect implementation */ - + /* Context data */ struct seff_flags_context { @@ -194,7 +194,7 @@ struct seff_flags_context { /* Context coding */ static bool seff_flags_dump_context -(const struct sieve_side_effect *seffect ATTR_UNUSED, +(const struct sieve_side_effect *seffect ATTR_UNUSED, const struct sieve_dumptime_env *denv, sieve_size_t *address) { return sieve_opr_stringlist_dump_ex(denv, address, "flags", "INTERNAL"); @@ -207,15 +207,15 @@ static struct seff_flags_context *seff_flags_get_implicit_context struct seff_flags_context *ctx; const char *flag; struct ext_imap4flags_iter flit; - + ctx = p_new(pool, struct seff_flags_context, 1); p_array_init(&ctx->keywords, pool, 2); - + T_BEGIN { - + /* Unpack */ ext_imap4flags_get_implicit_flags_init(&flit, this_ext, result); - while ( (flag=ext_imap4flags_iter_get_flag(&flit)) != NULL ) { + while ( (flag=ext_imap4flags_iter_get_flag(&flit)) != NULL ) { if (flag != NULL && *flag != '\\') { /* keyword */ const char *keyword = p_strdup(pool, flag); @@ -236,12 +236,12 @@ static struct seff_flags_context *seff_flags_get_implicit_context } } T_END; - + return ctx; } static int seff_flags_do_read_context -(const struct sieve_side_effect *seffect, +(const struct sieve_side_effect *seffect, const struct sieve_runtime_env *renv, sieve_size_t *address, void **se_context) { @@ -249,21 +249,21 @@ static int seff_flags_do_read_context struct seff_flags_context *ctx; string_t *flags_item; struct sieve_stringlist *flag_list = NULL; - int ret; + int ret; if ( (ret=sieve_opr_stringlist_read_ex (renv, address, "flags", TRUE, &flag_list)) <= 0 ) return ret; - + if ( flag_list == NULL ) { - /* Flag list is omitted, use current value of internal + /* Flag list is omitted, use current value of internal * variable to construct side effect context. */ *se_context = seff_flags_get_implicit_context (SIEVE_OBJECT_EXTENSION(seffect), renv->result); return SIEVE_EXEC_OK; } - + ctx = p_new(pool, struct seff_flags_context, 1); p_array_init(&ctx->keywords, pool, 2); @@ -274,8 +274,8 @@ static int seff_flags_do_read_context struct ext_imap4flags_iter flit; ext_imap4flags_iter_init(&flit, flags_item); - - while ( (flag=ext_imap4flags_iter_get_flag(&flit)) != NULL ) { + + while ( (flag=ext_imap4flags_iter_get_flag(&flit)) != NULL ) { if (flag != NULL && *flag != '\\') { /* keyword */ const char *keyword = p_strdup(pool, flag); @@ -298,17 +298,17 @@ static int seff_flags_do_read_context } } } - + if ( ret < 0 ) return flag_list->exec_status; *se_context = (void *) ctx; - + return SIEVE_EXEC_OK; } static int seff_flags_read_context -(const struct sieve_side_effect *seffect, +(const struct sieve_side_effect *seffect, const struct sieve_runtime_env *renv, sieve_size_t *address, void **se_context) { @@ -324,50 +324,50 @@ static int seff_flags_read_context /* Result verification */ static int seff_flags_merge -(const struct sieve_runtime_env *renv ATTR_UNUSED, - const struct sieve_action *action ATTR_UNUSED, - const struct sieve_side_effect *old_seffect ATTR_UNUSED, - const struct sieve_side_effect *new_seffect, +(const struct sieve_runtime_env *renv ATTR_UNUSED, + const struct sieve_action *action ATTR_UNUSED, + const struct sieve_side_effect *old_seffect ATTR_UNUSED, + const struct sieve_side_effect *new_seffect, void **old_context) { if ( new_seffect != NULL ) *old_context = new_seffect->context; - + return 1; } /* Result printing */ static void seff_flags_print -(const struct sieve_side_effect *seffect, - const struct sieve_action *action ATTR_UNUSED, +(const struct sieve_side_effect *seffect, + const struct sieve_action *action ATTR_UNUSED, const struct sieve_result_print_env *rpenv,bool *keep ATTR_UNUSED) { struct sieve_result *result = rpenv->result; - struct seff_flags_context *ctx = + struct seff_flags_context *ctx = (struct seff_flags_context *) seffect->context; unsigned int i; - + if ( ctx == NULL ) ctx = seff_flags_get_implicit_context (SIEVE_OBJECT_EXTENSION(seffect), result); - + if ( ctx->flags != 0 || array_count(&ctx->keywords) > 0 ) { T_BEGIN { string_t *flags = t_str_new(128); - + if ( (ctx->flags & MAIL_FLAGGED) > 0 ) str_printfa(flags, " \\flagged"); if ( (ctx->flags & MAIL_ANSWERED) > 0 ) str_printfa(flags, " \\answered"); - + if ( (ctx->flags & MAIL_DELETED) > 0 ) str_printfa(flags, " \\deleted"); - + if ( (ctx->flags & MAIL_SEEN) > 0 ) str_printfa(flags, " \\seen"); - + if ( (ctx->flags & MAIL_DRAFT) > 0 ) str_printfa(flags, " \\draft"); @@ -384,24 +384,24 @@ static void seff_flags_print /* Result execution */ static bool seff_flags_pre_execute -(const struct sieve_side_effect *seffect, +(const struct sieve_side_effect *seffect, const struct sieve_action *action ATTR_UNUSED, const struct sieve_action_exec_env *aenv, void **context, void *tr_context) -{ +{ struct seff_flags_context *ctx = (struct seff_flags_context *) *context; const char *const *keywords; - + if ( ctx == NULL ) { ctx = seff_flags_get_implicit_context (SIEVE_OBJECT_EXTENSION(seffect), aenv->result); *context = (void *) ctx; } - + (void)array_append_space(&ctx->keywords); keywords = array_idx(&ctx->keywords, 0); sieve_act_store_add_flags(aenv, tr_context, keywords, ctx->flags); - + return TRUE; } diff --git a/src/lib-sieve/plugins/imap4flags/tst-hasflag.c b/src/lib-sieve/plugins/imap4flags/tst-hasflag.c index 8496da15e2d928eaa4df59811fc4fec16bcced62..36c9cd07ee68d25a321e3e748c9afa7d604defa1 100644 --- a/src/lib-sieve/plugins/imap4flags/tst-hasflag.c +++ b/src/lib-sieve/plugins/imap4flags/tst-hasflag.c @@ -1,6 +1,6 @@ /* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #include "lib.h" #include "sieve-commands.h" @@ -8,7 +8,7 @@ #include "sieve-code.h" #include "sieve-comparators.h" #include "sieve-match-types.h" -#include "sieve-validator.h" +#include "sieve-validator.h" #include "sieve-generator.h" #include "sieve-interpreter.h" #include "sieve-dump.h" @@ -19,7 +19,7 @@ /* * Hasflag test * - * Syntax: + * Syntax: * hasflag [MATCH-TYPE] [COMPARATOR] [<variable-list: string-list>] * <list-of-flags: string-list> */ @@ -31,22 +31,22 @@ static bool tst_hasflag_validate (struct sieve_validator *valdtr, struct sieve_command *tst); static bool tst_hasflag_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd); - -const struct sieve_command_def tst_hasflag = { - "hasflag", + +const struct sieve_command_def tst_hasflag = { + "hasflag", SCT_TEST, -1, /* We check positional arguments ourselves */ - 0, FALSE, FALSE, - tst_hasflag_registered, + 0, FALSE, FALSE, + tst_hasflag_registered, NULL, tst_hasflag_validate, - NULL, - tst_hasflag_generate, - NULL + NULL, + tst_hasflag_generate, + NULL }; -/* - * Hasflag operation +/* + * Hasflag operation */ static bool tst_hasflag_operation_dump @@ -54,7 +54,7 @@ static bool tst_hasflag_operation_dump static int tst_hasflag_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def hasflag_operation = { +const struct sieve_operation_def hasflag_operation = { "HASFLAG", &imap4flags_extension, ext_imap4flags_OPERATION_HASFLAG, @@ -62,21 +62,21 @@ const struct sieve_operation_def hasflag_operation = { tst_hasflag_operation_execute }; -/* - * Optional arguments +/* + * Optional arguments */ -enum tst_hasflag_optional { +enum tst_hasflag_optional { OPT_VARIABLES = SIEVE_MATCH_OPT_LAST, }; -/* - * Tag registration +/* + * Tag registration */ static bool tst_hasflag_registered (struct sieve_validator *valdtr, const struct sieve_extension *ext ATTR_UNUSED, - struct sieve_command_registration *cmd_reg) + struct sieve_command_registration *cmd_reg) { /* The order of these is not significant */ sieve_comparators_link_tag(valdtr, cmd_reg, SIEVE_MATCH_OPT_COMPARATOR); @@ -85,8 +85,8 @@ static bool tst_hasflag_registered return TRUE; } -/* - * Validation +/* + * Validation */ static bool tst_hasflag_validate @@ -94,28 +94,28 @@ static bool tst_hasflag_validate { struct sieve_ast_argument *vars = tst->first_positional; struct sieve_ast_argument *keys = sieve_ast_argument_next(vars); - const struct sieve_match_type mcht_default = + const struct sieve_match_type mcht_default = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); - const struct sieve_comparator cmp_default = + const struct sieve_comparator cmp_default = SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator); - + if ( !ext_imap4flags_command_validate(valdtr, tst) ) return FALSE; - + if ( keys == NULL ) { keys = vars; vars = NULL; } else { vars->argument->id_code = OPT_VARIABLES; } - + /* Validate the key argument to a specified match type */ return sieve_match_type_validate (valdtr, tst, keys, &mcht_default, &cmp_default); } /* - * Code generation + * Code generation */ static bool tst_hasflag_generate @@ -125,15 +125,15 @@ static bool tst_hasflag_generate /* Generate arguments */ if ( !sieve_generate_arguments(cgenv, cmd, NULL) ) - return FALSE; + return FALSE; return TRUE; } -/* - * Code dump +/* + * Code dump */ - + static bool tst_hasflag_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) { @@ -148,7 +148,7 @@ static bool tst_hasflag_operation_dump bool opok = TRUE; int opt; - if ( (opt=sieve_match_opr_optional_dump(denv, address, &opt_code)) + if ( (opt=sieve_match_opr_optional_dump(denv, address, &opt_code)) < 0 ) return FALSE; @@ -164,8 +164,8 @@ static bool tst_hasflag_operation_dump if ( !opok ) return FALSE; } - - return + + return sieve_opr_stringlist_dump(denv, address, "list of flags"); } @@ -177,13 +177,13 @@ static int tst_hasflag_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) { int opt_code = 0; - struct sieve_comparator cmp = + struct sieve_comparator cmp = SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator); - struct sieve_match_type mcht = + struct sieve_match_type mcht = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); struct sieve_stringlist *flag_list, *variables_list, *value_list, *key_list; int match, ret; - + /* * Read operands */ @@ -199,8 +199,8 @@ static int tst_hasflag_operation_execute return ret; if ( opt == 0 ) break; - - switch ( opt_code ) { + + switch ( opt_code ) { case OPT_VARIABLES: ret = sieve_opr_stringlist_read (renv, address, "variables-list", &variables_list); @@ -211,7 +211,7 @@ static int tst_hasflag_operation_execute } if ( ret <= 0 ) return ret; - } + } /* Fixed operands */ @@ -235,7 +235,7 @@ static int tst_hasflag_operation_execute /* Perform match */ if ( (match=sieve_match(renv, &mcht, &cmp, value_list, key_list, &ret)) < 0 ) - return ret; + return ret; /* Set test result for subsequent conditional jump */ sieve_interpreter_set_test_result(renv->interp, match > 0); diff --git a/src/lib-sieve/plugins/include/cmd-global.c b/src/lib-sieve/plugins/include/cmd-global.c index 4719732e845a0cd5f39659153b2d9e90b18de0ef..903a1aa067836fc68cd8ac904eb794ff3a495678 100644 --- a/src/lib-sieve/plugins/include/cmd-global.c +++ b/src/lib-sieve/plugins/include/cmd-global.c @@ -6,7 +6,7 @@ #include "sieve-common.h" #include "sieve-code.h" #include "sieve-commands.h" -#include "sieve-validator.h" +#include "sieve-validator.h" #include "sieve-generator.h" #include "sieve-binary.h" #include "sieve-interpreter.h" @@ -18,8 +18,8 @@ #include "ext-include-binary.h" #include "ext-include-variables.h" -/* - * Commands +/* + * Commands */ static bool cmd_global_validate @@ -40,36 +40,36 @@ const struct sieve_command_def cmd_global = { /* DEPRICATED: */ - -/* Import command - * + +/* Import command + * * Syntax * import - */ -const struct sieve_command_def cmd_import = { - "import", - SCT_COMMAND, + */ +const struct sieve_command_def cmd_import = { + "import", + SCT_COMMAND, 1, 0, FALSE, FALSE, NULL, NULL, cmd_global_validate, NULL, - cmd_global_generate, + cmd_global_generate, NULL }; -/* Export command - * +/* Export command + * * Syntax * export - */ -const struct sieve_command_def cmd_export = { - "export", - SCT_COMMAND, + */ +const struct sieve_command_def cmd_export = { + "export", + SCT_COMMAND, 1, 0, FALSE, FALSE, - NULL, NULL, + NULL, NULL, cmd_global_validate, NULL, - cmd_global_generate, + cmd_global_generate, NULL }; @@ -84,11 +84,11 @@ static int opc_global_execute /* Global operation */ -const struct sieve_operation_def global_operation = { +const struct sieve_operation_def global_operation = { "global", &include_extension, EXT_INCLUDE_OPERATION_GLOBAL, - opc_global_dump, + opc_global_dump, opc_global_execute }; @@ -108,7 +108,7 @@ static inline struct sieve_argument *_create_variable_argument } static bool cmd_global_validate -(struct sieve_validator *valdtr, struct sieve_command *cmd) +(struct sieve_validator *valdtr, struct sieve_command *cmd) { const struct sieve_extension *this_ext = cmd->ext; struct sieve_ast_argument *arg = cmd->first_positional; @@ -118,8 +118,8 @@ static bool cmd_global_validate if ( !sieve_command_is(cmd, cmd_global) ) { if ( !sieve_command_is_toplevel(cmd) || ( !sieve_command_is_first(cmd) && prev != NULL && - !sieve_command_is(prev, cmd_require) && - !sieve_command_is(prev, cmd_import) && + !sieve_command_is(prev, cmd_require) && + !sieve_command_is(prev, cmd_import) && !sieve_command_is(prev, cmd_export) ) ) { sieve_command_validate_error(valdtr, cmd, "the DEPRECATED %s command can only be placed at top level " @@ -130,45 +130,45 @@ static bool cmd_global_validate } } - /* Check for use of variables extension */ + /* Check for use of variables extension */ if ( !ext_include_validator_have_variables(this_ext, valdtr) ) { - sieve_command_validate_error(valdtr, cmd, + sieve_command_validate_error(valdtr, cmd, "%s command requires that variables extension is active", sieve_command_identifier(cmd)); return FALSE; } - + /* Register global variable */ if ( sieve_ast_argument_type(arg) == SAAT_STRING ) { /* Single string */ const char *identifier = sieve_ast_argument_strc(arg); struct sieve_variable *var; - + if ( (var=ext_include_variable_import_global (valdtr, cmd, identifier)) == NULL ) return FALSE; - + arg->argument = _create_variable_argument(cmd, var); } else if ( sieve_ast_argument_type(arg) == SAAT_STRING_LIST ) { /* String list */ struct sieve_ast_argument *stritem = sieve_ast_strlist_first(arg); - + while ( stritem != NULL ) { const char *identifier = sieve_ast_argument_strc(stritem); struct sieve_variable *var; - + if ( (var=ext_include_variable_import_global (valdtr, cmd, identifier)) == NULL ) return FALSE; stritem->argument = _create_variable_argument(cmd, var); - + stritem = sieve_ast_strlist_next(stritem); } } else { /* Something else */ - sieve_argument_validate_error(valdtr, arg, + sieve_argument_validate_error(valdtr, arg, "the %s command accepts a single string or string list argument, " "but %s was found", sieve_command_identifier(cmd), sieve_ast_argument_name(arg)); @@ -183,7 +183,7 @@ static bool cmd_global_validate if ( prev->first_positional == NULL ) { /* Not going to happen unless MAXINT stringlist items are specified */ - sieve_command_validate_error(valdtr, cmd, + sieve_command_validate_error(valdtr, cmd, "compiler reached AST limit (script too complex)"); return FALSE; } @@ -191,54 +191,54 @@ static bool cmd_global_validate /* Detach this command node */ sieve_ast_node_detach(cmd->ast_node); } - + return TRUE; } /* * Code generation */ - + static bool cmd_global_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) { struct sieve_ast_argument *arg = cmd->first_positional; sieve_operation_emit(cgenv->sblock, cmd->ext, &global_operation); - + if ( sieve_ast_argument_type(arg) == SAAT_STRING ) { /* Single string */ struct sieve_variable *var = (struct sieve_variable *) arg->argument->data; - + (void)sieve_binary_emit_unsigned(cgenv->sblock, 1); (void)sieve_binary_emit_unsigned(cgenv->sblock, var->index); - + } else if ( sieve_ast_argument_type(arg) == SAAT_STRING_LIST ) { /* String list */ struct sieve_ast_argument *stritem = sieve_ast_strlist_first(arg); - + (void)sieve_binary_emit_unsigned (cgenv->sblock, sieve_ast_strlist_count(arg)); - + while ( stritem != NULL ) { - struct sieve_variable *var = + struct sieve_variable *var = (struct sieve_variable *) stritem->argument->data; - + (void)sieve_binary_emit_unsigned(cgenv->sblock, var->index); - + stritem = sieve_ast_strlist_next(stritem); } } else { i_unreached(); } - + return TRUE; } -/* +/* * Code dump */ - + static bool opc_global_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) { @@ -247,7 +247,7 @@ static bool opc_global_dump struct sieve_variable_scope_binary *global_vars; struct sieve_variable_scope *global_scope; struct sieve_variable * const *vars; - + if ( !sieve_binary_read_unsigned(denv->sblock, address, &count) ) return FALSE; @@ -261,38 +261,38 @@ static bool opc_global_dump for ( i = 0; i < count; i++ ) { unsigned int index; - + sieve_code_mark(denv); if ( !sieve_binary_read_unsigned(denv->sblock, address, &index) || index >= var_count ) return FALSE; - - sieve_code_dumpf(denv, "%d: VAR[%d]: '%s'", i, index, vars[index]->identifier); + + sieve_code_dumpf(denv, "%d: VAR[%d]: '%s'", i, index, vars[index]->identifier); } - + return TRUE; } -/* +/* * Execution */ - + static int opc_global_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) { const struct sieve_extension *this_ext = renv->oprtn->ext; - struct sieve_variable_scope_binary *global_vars; - struct sieve_variable_scope *global_scope; + struct sieve_variable_scope_binary *global_vars; + struct sieve_variable_scope *global_scope; struct sieve_variable_storage *storage; struct sieve_variable * const *vars; unsigned int var_count, count, i; - + if ( !sieve_binary_read_unsigned(renv->sblock, address, &count) ) { - sieve_runtime_trace_error(renv, + sieve_runtime_trace_error(renv, "global: count operand invalid"); return SIEVE_EXEC_BIN_CORRUPT; } - + global_vars = ext_include_binary_get_global_scope(this_ext, renv->sbin); global_scope = sieve_variable_scope_binary_get(global_vars); vars = sieve_variable_scope_get_variables(global_scope, &var_count); @@ -301,16 +301,16 @@ static int opc_global_execute for ( i = 0; i < count; i++ ) { unsigned int index; - + if ( !sieve_binary_read_unsigned(renv->sblock, address, &index) ) { - sieve_runtime_trace_error(renv, + sieve_runtime_trace_error(renv, "global: variable index operand invalid"); return SIEVE_EXEC_BIN_CORRUPT; } - + if ( index >= var_count ) { - sieve_runtime_trace_error(renv, - "global: variable index %u is invalid in global storage (> %u)", + sieve_runtime_trace_error(renv, + "global: variable index %u is invalid in global storage (> %u)", index, var_count); return SIEVE_EXEC_BIN_CORRUPT; } @@ -318,9 +318,9 @@ static int opc_global_execute sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, "global: exporting variable '%s' [gvid: %u, vid: %u]", vars[index]->identifier, i, index); - + /* Make sure variable is initialized (export) */ - (void)sieve_variable_get_modifiable(storage, index, NULL); + (void)sieve_variable_get_modifiable(storage, index, NULL); } return SIEVE_EXEC_OK; diff --git a/src/lib-sieve/plugins/include/cmd-include.c b/src/lib-sieve/plugins/include/cmd-include.c index d2741605973f85b795e39ec071be37bad6580b3a..516cb6844a91dd003ce32faa60db25b2ec1c56fd 100644 --- a/src/lib-sieve/plugins/include/cmd-include.c +++ b/src/lib-sieve/plugins/include/cmd-include.c @@ -19,13 +19,13 @@ #include "ext-include-common.h" #include "ext-include-binary.h" -/* - * Include command - * - * Syntax: +/* + * Include command + * + * Syntax: * include [LOCATION] <value: string> * - * [LOCATION]: + * [LOCATION]: * ":personal" / ":global" */ @@ -39,20 +39,20 @@ static bool cmd_include_validate static bool cmd_include_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx); -const struct sieve_command_def cmd_include = { +const struct sieve_command_def cmd_include = { "include", - SCT_COMMAND, - 1, 0, FALSE, FALSE, + SCT_COMMAND, + 1, 0, FALSE, FALSE, cmd_include_registered, - cmd_include_pre_validate, + cmd_include_pre_validate, cmd_include_validate, NULL, - cmd_include_generate, - NULL + cmd_include_generate, + NULL }; -/* - * Include operation +/* + * Include operation */ static bool opc_include_dump @@ -60,85 +60,85 @@ static bool opc_include_dump static int opc_include_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def include_operation = { +const struct sieve_operation_def include_operation = { "include", &include_extension, EXT_INCLUDE_OPERATION_INCLUDE, - opc_include_dump, + opc_include_dump, opc_include_execute }; -/* - * Context structures +/* + * Context structures */ struct cmd_include_context_data { enum ext_include_script_location location; bool location_assigned; - + bool include_once; - + struct sieve_script *script; -}; +}; -/* +/* * Tagged arguments */ static bool cmd_include_validate_location_tag - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); -static const struct sieve_argument_def include_personal_tag = { - "personal", - NULL, - cmd_include_validate_location_tag, +static const struct sieve_argument_def include_personal_tag = { + "personal", + NULL, + cmd_include_validate_location_tag, NULL, NULL, NULL }; -static const struct sieve_argument_def include_global_tag = { - "global", +static const struct sieve_argument_def include_global_tag = { + "global", NULL, - cmd_include_validate_location_tag, + cmd_include_validate_location_tag, NULL, NULL, NULL }; static bool cmd_include_validate_once_tag - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); -static const struct sieve_argument_def include_once_tag = { - "once", +static const struct sieve_argument_def include_once_tag = { + "once", NULL, - cmd_include_validate_once_tag, - NULL, NULL, NULL + cmd_include_validate_once_tag, + NULL, NULL, NULL }; -/* - * Tag validation +/* + * Tag validation */ static bool cmd_include_validate_location_tag -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd) -{ - struct cmd_include_context_data *ctx_data = +{ + struct cmd_include_context_data *ctx_data = (struct cmd_include_context_data *) cmd->data; - + if ( ctx_data->location_assigned) { - sieve_argument_validate_error(valdtr, *arg, + sieve_argument_validate_error(valdtr, *arg, "include: cannot use location tags ':personal' and ':global' " "multiple times"); return FALSE; } - + if ( sieve_argument_is(*arg, include_personal_tag) ) ctx_data->location = EXT_INCLUDE_LOCATION_PERSONAL; else if ( sieve_argument_is(*arg, include_global_tag) ) ctx_data->location = EXT_INCLUDE_LOCATION_GLOBAL; else return FALSE; - + ctx_data->location_assigned = TRUE; /* Delete this tag (for now) */ @@ -148,37 +148,37 @@ static bool cmd_include_validate_location_tag } static bool cmd_include_validate_once_tag -(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_ast_argument **arg, struct sieve_command *cmd) -{ - struct cmd_include_context_data *ctx_data = +{ + struct cmd_include_context_data *ctx_data = (struct cmd_include_context_data *) cmd->data; ctx_data->include_once = TRUE; - + /* Delete this tag (for now) */ *arg = sieve_ast_arguments_detach(*arg, 1); return TRUE; } -/* - * Command registration +/* + * Command registration */ static bool cmd_include_registered -(struct sieve_validator *valdtr, const struct sieve_extension *ext, - struct sieve_command_registration *cmd_reg) +(struct sieve_validator *valdtr, const struct sieve_extension *ext, + struct sieve_command_registration *cmd_reg) { - sieve_validator_register_tag(valdtr, cmd_reg, ext, &include_personal_tag, 0); - sieve_validator_register_tag(valdtr, cmd_reg, ext, &include_global_tag, 0); - sieve_validator_register_tag(valdtr, cmd_reg, ext, &include_once_tag, 0); + sieve_validator_register_tag(valdtr, cmd_reg, ext, &include_personal_tag, 0); + sieve_validator_register_tag(valdtr, cmd_reg, ext, &include_global_tag, 0); + sieve_validator_register_tag(valdtr, cmd_reg, ext, &include_once_tag, 0); return TRUE; } -/* - * Command validation +/* + * Command validation */ static bool cmd_include_pre_validate @@ -190,22 +190,22 @@ static bool cmd_include_pre_validate ctx_data = p_new(sieve_command_pool(cmd), struct cmd_include_context_data, 1); ctx_data->location = EXT_INCLUDE_LOCATION_PERSONAL; cmd->data = ctx_data; - + return TRUE; } static bool cmd_include_validate -(struct sieve_validator *valdtr, struct sieve_command *cmd) -{ +(struct sieve_validator *valdtr, struct sieve_command *cmd) +{ const struct sieve_extension *this_ext = cmd->ext; struct sieve_ast_argument *arg = cmd->first_positional; - struct cmd_include_context_data *ctx_data = + struct cmd_include_context_data *ctx_data = (struct cmd_include_context_data *) cmd->data; struct sieve_script *script; const char *script_location, *script_name; enum sieve_error error = SIEVE_ERROR_NONE; bool include = TRUE; - + /* Check argument */ if ( !sieve_validate_positional_argument (valdtr, cmd, arg, "value", 1, SAAT_STRING) ) { @@ -215,11 +215,11 @@ static bool cmd_include_validate if ( !sieve_validator_argument_activate(valdtr, cmd, arg, FALSE) ) return FALSE; - /* + /* * Variables are not allowed. */ if ( !sieve_argument_is_string_literal(arg) ) { - sieve_argument_validate_error(valdtr, arg, + sieve_argument_validate_error(valdtr, arg, "the include command requires a constant string for its value argument"); return FALSE; } @@ -234,7 +234,7 @@ static bool cmd_include_validate str_sanitize(script_name, 80)); return FALSE; } - + script_location = ext_include_get_script_location (this_ext, ctx_data->location, script_name); if ( script_location == NULL ) { @@ -245,10 +245,10 @@ static bool cmd_include_validate str_sanitize(script_name, 80)); return FALSE; } - + /* Create script object */ script = sieve_script_create - (this_ext->svinst, script_location, script_name, + (this_ext->svinst, script_location, script_name, sieve_validator_error_handler(valdtr), &error); if ( script == NULL ) { @@ -259,14 +259,14 @@ static bool cmd_include_validate sieve_validator_compile_flags(valdtr); if ( (cpflags & SIEVE_COMPILE_FLAG_UPLOADED) != 0 ) { - sieve_argument_validate_warning(valdtr, arg, - "included %s script '%s' does not exist (ignored during upload)", + sieve_argument_validate_warning(valdtr, arg, + "included %s script '%s' does not exist (ignored during upload)", ext_include_script_location_name(ctx_data->location), str_sanitize(script_name, 80)); include = FALSE; } else { - sieve_argument_validate_error(valdtr, arg, - "included %s script '%s' does not exist", + sieve_argument_validate_error(valdtr, arg, + "included %s script '%s' does not exist", ext_include_script_location_name(ctx_data->location), str_sanitize(script_name, 80)); return FALSE; @@ -275,10 +275,10 @@ static bool cmd_include_validate } if ( include ) { - ext_include_ast_link_included_script(cmd->ext, cmd->ast_node->ast, script); + ext_include_ast_link_included_script(cmd->ext, cmd->ast_node->ast, script); ctx_data->script = script; } - + (void)sieve_ast_arguments_detach(arg, 1); return TRUE; } @@ -286,11 +286,11 @@ static bool cmd_include_validate /* * Code Generation */ - + static bool cmd_include_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) { - struct cmd_include_context_data *ctx_data = + struct cmd_include_context_data *ctx_data = (struct cmd_include_context_data *) cmd->data; const struct ext_include_script_info *included; unsigned int flags = ctx_data->include_once; @@ -301,27 +301,27 @@ static bool cmd_include_generate */ if ( ctx_data->script != NULL ) { /* Compile (if necessary) and include the script into the binary. - * This yields the id of the binary block containing the compiled byte code. + * This yields the id of the binary block containing the compiled byte code. */ if ( (ret=ext_include_generate_include (cgenv, cmd, ctx_data->location, ctx_data->script, &included, ctx_data->include_once)) < 0 ) return FALSE; - + if ( ret > 0 ) { (void)sieve_operation_emit(cgenv->sblock, cmd->ext, &include_operation); - (void)sieve_binary_emit_unsigned(cgenv->sblock, included->id); + (void)sieve_binary_emit_unsigned(cgenv->sblock, included->id); (void)sieve_binary_emit_byte(cgenv->sblock, flags); } } - + return TRUE; } -/* +/* * Code dump */ - + static bool opc_include_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) { @@ -330,7 +330,7 @@ static bool opc_include_dump unsigned int include_id, flags; sieve_code_dumpf(denv, "INCLUDE:"); - + sieve_code_mark(denv); if ( !sieve_binary_read_unsigned(denv->sblock, address, &include_id) ) return FALSE; @@ -344,7 +344,7 @@ static bool opc_include_dump return FALSE; sieve_code_descend(denv); - sieve_code_dumpf(denv, "script: `%s' from %s %s[ID: %d, BLOCK: %d]", + sieve_code_dumpf(denv, "script: `%s' from %s %s[ID: %d, BLOCK: %d]", sieve_script_name(included->script), sieve_script_location(included->script), (flags & 0x01 ? "(once) " : ""), include_id, sieve_binary_block_get_id(included->block)); @@ -352,15 +352,15 @@ static bool opc_include_dump return TRUE; } -/* +/* * Execution */ - + static int opc_include_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) { unsigned int include_id, flags; - + if ( !sieve_binary_read_unsigned(renv->sblock, address, &include_id) ) { sieve_runtime_trace_error(renv, "invalid include-id operand"); return SIEVE_EXEC_BIN_CORRUPT; @@ -370,7 +370,7 @@ static int opc_include_execute sieve_runtime_trace_error(renv, "invalid flags operand"); return SIEVE_EXEC_BIN_CORRUPT; } - + return ext_include_execute_include(renv, include_id, flags & 0x01); } diff --git a/src/lib-sieve/plugins/include/cmd-return.c b/src/lib-sieve/plugins/include/cmd-return.c index 479f4cba87bcf77b2d041e998ae549fd1f12ac3a..8c85977647fe95eff0e5be0fd6e75388b77a16b0 100644 --- a/src/lib-sieve/plugins/include/cmd-return.c +++ b/src/lib-sieve/plugins/include/cmd-return.c @@ -5,44 +5,44 @@ #include "sieve-code.h" #include "sieve-commands.h" -#include "sieve-validator.h" +#include "sieve-validator.h" #include "sieve-generator.h" #include "sieve-interpreter.h" #include "ext-include-common.h" -/* - * Return command - * +/* + * Return command + * * Syntax * return */ static bool cmd_return_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd); - -const struct sieve_command_def cmd_return = { - "return", - SCT_COMMAND, + +const struct sieve_command_def cmd_return = { + "return", + SCT_COMMAND, 0, 0, FALSE, FALSE, NULL, NULL, NULL, NULL, - cmd_return_generate, + cmd_return_generate, NULL }; -/* - * Return operation +/* + * Return operation */ static int opc_return_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def return_operation = { +const struct sieve_operation_def return_operation = { "return", &include_extension, EXT_INCLUDE_OPERATION_RETURN, - NULL, - opc_return_execute + NULL, + opc_return_execute }; /* @@ -50,7 +50,7 @@ const struct sieve_operation_def return_operation = { */ static bool cmd_return_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) { sieve_operation_emit(cgenv->sblock, cmd->ext, &return_operation); @@ -63,7 +63,7 @@ static bool cmd_return_generate static int opc_return_execute (const struct sieve_runtime_env *renv, sieve_size_t *address ATTR_UNUSED) -{ +{ ext_include_execute_return(renv); return SIEVE_EXEC_OK; } diff --git a/src/lib-sieve/plugins/include/ext-include-binary.c b/src/lib-sieve/plugins/include/ext-include-binary.c index da520c84b36d2707c9a446f17fb5eb007bd7962a..e40d2b5564af32e9aaf2abadf5e53ed967ba24f0 100644 --- a/src/lib-sieve/plugins/include/ext-include-binary.c +++ b/src/lib-sieve/plugins/include/ext-include-binary.c @@ -22,7 +22,7 @@ /* * Forward declarations */ - + static bool ext_include_binary_save (const struct sieve_extension *ext, struct sieve_binary *sbin, void *context); static bool ext_include_binary_open @@ -33,10 +33,10 @@ static bool ext_include_binary_up_to_date static void ext_include_binary_free (const struct sieve_extension *ext, struct sieve_binary *sbin, void *context); -/* +/* * Binary include extension */ - + const struct sieve_binary_extension include_binary_ext = { &include_extension, ext_include_binary_save, @@ -48,11 +48,11 @@ const struct sieve_binary_extension include_binary_ext = { /* * Binary context management */ - + struct ext_include_binary_context { struct sieve_binary *binary; struct sieve_binary_block *dependency_block; - + struct hash_table *included_scripts; ARRAY_DEFINE(include_index, struct ext_include_script_info *); @@ -65,13 +65,13 @@ static struct ext_include_binary_context *ext_include_binary_create_context (const struct sieve_extension *this_ext, struct sieve_binary *sbin) { pool_t pool = sieve_binary_pool(sbin); - - struct ext_include_binary_context *ctx = + + struct ext_include_binary_context *ctx = p_new(pool, struct ext_include_binary_context, 1); - - ctx->binary = sbin; - ctx->included_scripts = hash_table_create(default_pool, pool, 0, - (hash_callback_t *) sieve_script_hash, + + ctx->binary = sbin; + ctx->included_scripts = hash_table_create(default_pool, pool, 0, + (hash_callback_t *) sieve_script_hash, (hash_cmp_callback_t *) sieve_script_cmp); p_array_init(&ctx->include_index, pool, 128); @@ -82,38 +82,38 @@ static struct ext_include_binary_context *ext_include_binary_create_context struct ext_include_binary_context *ext_include_binary_get_context (const struct sieve_extension *this_ext, struct sieve_binary *sbin) -{ +{ struct ext_include_binary_context *ctx = (struct ext_include_binary_context *) sieve_binary_extension_get_context(sbin, this_ext); - + if ( ctx == NULL ) ctx = ext_include_binary_create_context(this_ext, sbin); - + return ctx; } - + struct ext_include_binary_context *ext_include_binary_init -(const struct sieve_extension *this_ext, struct sieve_binary *sbin, +(const struct sieve_extension *this_ext, struct sieve_binary *sbin, struct sieve_ast *ast) { struct ext_include_ast_context *ast_ctx = ext_include_get_ast_context(this_ext, ast); struct ext_include_binary_context *ctx; - + /* Get/create our context from the binary we are working on */ ctx = ext_include_binary_get_context(this_ext, sbin); - + /* Create dependency block */ if ( ctx->dependency_block == 0 ) - ctx->dependency_block = + ctx->dependency_block = sieve_binary_extension_create_block(sbin, this_ext); if ( ctx->global_vars == NULL ) { - ctx->global_vars = + ctx->global_vars = sieve_variable_scope_binary_create(ast_ctx->global_vars); sieve_variable_scope_binary_ref(ctx->global_vars); } - + return ctx; } @@ -133,10 +133,10 @@ const struct ext_include_script_info *ext_include_binary_script_include incscript->script = script; incscript->location = location; incscript->block = inc_block; - + /* Unreferenced on binary_free */ sieve_script_ref(script); - + hash_table_insert (binctx->included_scripts, (void *) script, (void *) incscript); array_append(&binctx->include_index, &incscript, 1); @@ -150,18 +150,18 @@ bool ext_include_binary_script_is_included { struct ext_include_script_info *incscript = (struct ext_include_script_info *) hash_table_lookup(binctx->included_scripts, script); - + if ( incscript == NULL ) return FALSE; - + *script_info_r = incscript; return TRUE; } const struct ext_include_script_info *ext_include_binary_script_get_included (struct ext_include_binary_context *binctx, unsigned int include_id) -{ - if ( include_id > 0 && +{ + if ( include_id > 0 && (include_id - 1) < array_count(&binctx->include_index) ) { struct ext_include_script_info *const *sinfo = array_idx(&binctx->include_index, include_id - 1); @@ -186,13 +186,13 @@ unsigned int ext_include_binary_script_get_count } /* - * Variables + * Variables */ struct sieve_variable_scope_binary *ext_include_binary_get_global_scope (const struct sieve_extension *this_ext, struct sieve_binary *sbin) { - struct ext_include_binary_context *binctx = + struct ext_include_binary_context *binctx = ext_include_binary_get_context(this_ext, sbin); return binctx->global_vars; @@ -203,16 +203,16 @@ struct sieve_variable_scope_binary *ext_include_binary_get_global_scope */ static bool ext_include_binary_save -(const struct sieve_extension *ext ATTR_UNUSED, +(const struct sieve_extension *ext ATTR_UNUSED, struct sieve_binary *sbin ATTR_UNUSED, void *context) { - struct ext_include_binary_context *binctx = + struct ext_include_binary_context *binctx = (struct ext_include_binary_context *) context; struct ext_include_script_info *const *scripts; struct sieve_binary_block *sblock = binctx->dependency_block; unsigned int script_count, i; bool result = TRUE; - + sieve_binary_block_clear(sblock); scripts = array_get(&binctx->include_index, &script_count); @@ -229,7 +229,7 @@ static bool ext_include_binary_save } result = ext_include_variables_save(sblock, binctx->global_vars); - + return result; } @@ -239,33 +239,33 @@ static bool ext_include_binary_open struct sieve_instance *svinst = ext->svinst; struct ext_include_context *ext_ctx = (struct ext_include_context *)ext->context; - struct ext_include_binary_context *binctx = + struct ext_include_binary_context *binctx = (struct ext_include_binary_context *) context; struct sieve_binary_block *sblock; unsigned int depcount, i, block_id; sieve_size_t offset; - + sblock = sieve_binary_extension_get_block(sbin, ext); block_id = sieve_binary_block_get_id(sblock); - - offset = 0; - + + offset = 0; + if ( !sieve_binary_read_unsigned(sblock, &offset, &depcount) ) { - sieve_sys_error(svinst, + sieve_sys_error(svinst, "include: failed to read include count " - "for dependency block %d of binary %s", block_id, + "for dependency block %d of binary %s", block_id, sieve_binary_path(sbin)); return FALSE; } - - /* Check include limit */ + + /* Check include limit */ if ( depcount > ext_ctx->max_includes ) { sieve_sys_error(svinst, "include: binary %s includes too many scripts (%u > %u)", - sieve_binary_path(sbin), depcount, ext_ctx->max_includes); + sieve_binary_path(sbin), depcount, ext_ctx->max_includes); return FALSE; } - + /* Read dependencies */ for ( i = 0; i < depcount; i++ ) { unsigned int inc_block_id; @@ -275,40 +275,40 @@ static bool ext_include_binary_open const char *script_location; struct sieve_script *script; int ret; - - if ( + + if ( !sieve_binary_read_unsigned(sblock, &offset, &inc_block_id) || !sieve_binary_read_byte(sblock, &offset, &location) || !sieve_binary_read_string(sblock, &offset, &script_name) ) { /* Binary is corrupt, recompile */ sieve_sys_error(svinst, "include: failed to read included script " - "from dependency block %d of binary %s", block_id, - sieve_binary_path(sbin)); + "from dependency block %d of binary %s", block_id, + sieve_binary_path(sbin)); return FALSE; } if ( (inc_block=sieve_binary_block_get(sbin, inc_block_id)) == NULL ) { sieve_sys_error(svinst, "include: failed to find block %d for included script " - "from dependency block %d of binary %s", inc_block_id, block_id, - sieve_binary_path(sbin)); + "from dependency block %d of binary %s", inc_block_id, block_id, + sieve_binary_path(sbin)); return FALSE; } - + if ( location >= EXT_INCLUDE_LOCATION_INVALID ) { /* Binary is corrupt, recompile */ sieve_sys_error(svinst, "include: dependency block %d of binary %s " - "uses invalid script location (id %d)", - block_id, sieve_binary_path(sbin), location); + "uses invalid script location (id %d)", + block_id, sieve_binary_path(sbin), location); return FALSE; - } - + } + /* Can we find/open the script dependency ? */ script_location = ext_include_get_script_location - (ext, location, str_c(script_name)); + (ext, location, str_c(script_name)); if ( script_location == NULL || (script=sieve_script_create (ext->svinst, script_location, str_c(script_name), NULL, NULL)) == NULL ) { @@ -321,25 +321,25 @@ static bool ext_include_binary_open /* Binary is corrupt, recompile */ sieve_sys_error(svinst, "include: dependency block %d of binary %s " - "contains invalid script metadata for script %s", - block_id, sieve_binary_path(sbin), sieve_script_location(script)); + "contains invalid script metadata for script %s", + block_id, sieve_binary_path(sbin), sieve_script_location(script)); return FALSE; } if ( ret == 0 ) binctx->outdated = TRUE; - + (void)ext_include_binary_script_include (binctx, script, location, inc_block); - + sieve_script_unref(&script); } if ( !ext_include_variables_load (ext, sblock, &offset, &binctx->global_vars) ) return FALSE; - - return TRUE; + + return TRUE; } static bool ext_include_binary_up_to_date @@ -347,46 +347,46 @@ static bool ext_include_binary_up_to_date struct sieve_binary *sbin ATTR_UNUSED, void *context, enum sieve_compile_flags cpflags ATTR_UNUSED) { - struct ext_include_binary_context *binctx = + struct ext_include_binary_context *binctx = (struct ext_include_binary_context *) context; return !binctx->outdated; } static void ext_include_binary_free -(const struct sieve_extension *ext ATTR_UNUSED, +(const struct sieve_extension *ext ATTR_UNUSED, struct sieve_binary *sbin ATTR_UNUSED, void *context) { - struct ext_include_binary_context *binctx = + struct ext_include_binary_context *binctx = (struct ext_include_binary_context *) context; struct hash_iterate_context *hctx; void *key, *value; - + /* Release references to all included script objects */ hctx = hash_table_iterate_init(binctx->included_scripts); while ( hash_table_iterate(hctx, &key, &value) ) { - struct ext_include_script_info *incscript = + struct ext_include_script_info *incscript = (struct ext_include_script_info *) value; - + sieve_script_unref(&incscript->script); } hash_table_iterate_deinit(&hctx); hash_table_destroy(&binctx->included_scripts); - if ( binctx->global_vars != NULL ) + if ( binctx->global_vars != NULL ) sieve_variable_scope_binary_unref(&binctx->global_vars); } /* - * Dumping the binary + * Dumping the binary */ bool ext_include_binary_dump (const struct sieve_extension *ext, struct sieve_dumptime_env *denv) { struct sieve_binary *sbin = denv->sbin; - struct ext_include_binary_context *binctx = + struct ext_include_binary_context *binctx = ext_include_binary_get_context(ext, sbin); struct hash_iterate_context *hctx; void *key, *value; @@ -394,16 +394,16 @@ bool ext_include_binary_dump if ( !ext_include_variables_dump(denv, binctx->global_vars) ) return FALSE; - hctx = hash_table_iterate_init(binctx->included_scripts); + hctx = hash_table_iterate_init(binctx->included_scripts); while ( hash_table_iterate(hctx, &key, &value) ) { - struct ext_include_script_info *incscript = + struct ext_include_script_info *incscript = (struct ext_include_script_info *) value; unsigned int block_id = sieve_binary_block_get_id(incscript->block); - - sieve_binary_dump_sectionf(denv, "Included %s script '%s' (block: %d)", - ext_include_script_location_name(incscript->location), + + sieve_binary_dump_sectionf(denv, "Included %s script '%s' (block: %d)", + ext_include_script_location_name(incscript->location), sieve_script_name(incscript->script), block_id); - + denv->sblock = incscript->block; denv->cdumper = sieve_code_dumper_create(denv); @@ -413,23 +413,23 @@ bool ext_include_binary_dump sieve_code_dumper_run(denv->cdumper); sieve_code_dumper_free(&(denv->cdumper)); } - + hash_table_iterate_deinit(&hctx); - + return TRUE; } bool ext_include_code_dump -(const struct sieve_extension *ext, const struct sieve_dumptime_env *denv, +(const struct sieve_extension *ext, const struct sieve_dumptime_env *denv, sieve_size_t *address ATTR_UNUSED) { struct sieve_binary *sbin = denv->sbin; - struct ext_include_binary_context *binctx = + struct ext_include_binary_context *binctx = ext_include_binary_get_context(ext, sbin); struct ext_include_context *ectx = ext_include_get_context(ext); - + sieve_ext_variables_dump_set_scope - (ectx->var_ext, denv, ext, + (ectx->var_ext, denv, ext, sieve_variable_scope_binary_get(binctx->global_vars)); return TRUE; diff --git a/src/lib-sieve/plugins/include/ext-include-binary.h b/src/lib-sieve/plugins/include/ext-include-binary.h index 0fffd70156ad8163c767b76f2976b5bd9b608da2..448ae9673b68a8940bbde77a0b990cc9c96fa412 100644 --- a/src/lib-sieve/plugins/include/ext-include-binary.h +++ b/src/lib-sieve/plugins/include/ext-include-binary.h @@ -13,7 +13,7 @@ struct ext_include_binary_context; struct ext_include_binary_context *ext_include_binary_init - (const struct sieve_extension *this_ext, struct sieve_binary *sbin, + (const struct sieve_extension *this_ext, struct sieve_binary *sbin, struct sieve_ast *ast); struct ext_include_binary_context *ext_include_binary_get_context (const struct sieve_extension *this_ext, struct sieve_binary *sbin); @@ -40,7 +40,7 @@ struct ext_include_script_info { const struct ext_include_script_info *ext_include_binary_script_include (struct ext_include_binary_context *binctx, struct sieve_script *script, - enum ext_include_script_location location, + enum ext_include_script_location location, struct sieve_binary_block *block); bool ext_include_binary_script_is_included (struct ext_include_binary_context *binctx, struct sieve_script *script, @@ -60,8 +60,8 @@ unsigned int ext_include_binary_script_get_count bool ext_include_binary_dump (const struct sieve_extension *ext, struct sieve_dumptime_env *denv); bool ext_include_code_dump - (const struct sieve_extension *ext, const struct sieve_dumptime_env *denv, + (const struct sieve_extension *ext, const struct sieve_dumptime_env *denv, sieve_size_t *address ATTR_UNUSED); - + #endif /* __EXT_INCLUDE_BINARY_H */ diff --git a/src/lib-sieve/plugins/include/ext-include-common.c b/src/lib-sieve/plugins/include/ext-include-common.c index 1c2e68a27e7f752f2eab2f6ff66d8e92b28d2cbe..795001fffe62e3c75f6e8c8666b11744672ea659 100644 --- a/src/lib-sieve/plugins/include/ext-include-common.c +++ b/src/lib-sieve/plugins/include/ext-include-common.c @@ -60,7 +60,7 @@ struct ext_include_interpreter_context { struct sieve_script *script; const struct ext_include_script_info *script_info; - + const struct ext_include_script_info *include; bool returned; }; @@ -84,7 +84,7 @@ bool ext_include_load } // FIXME: sieve_dir and sieve_global_dir settings have somewhat become - // misnomers; these are not necessary filesystem directories anymore. + // misnomers; these are not necessary filesystem directories anymore. ctx = i_new(struct ext_include_context, 1); @@ -102,7 +102,7 @@ bool ext_include_load sieve_dir = sieve_setting_get(svinst, "sieve_dir"); if ( sieve_dir == NULL ) { - sieve_dir = "~/sieve"; + sieve_dir = "~/sieve"; } ctx->personal_dir = i_strdup(sieve_dir); @@ -121,7 +121,7 @@ bool ext_include_load ctx->max_includes = (unsigned int) uint_setting; } - /* Extension dependencies */ + /* Extension dependencies */ ctx->var_ext = sieve_ext_variables_get_extension(ext->svinst); *context = (void *)ctx; @@ -140,8 +140,8 @@ void ext_include_unload i_free(ctx); } -/* - * Script access +/* + * Script access */ const char *ext_include_get_script_location @@ -189,10 +189,10 @@ const char *ext_include_get_script_location */ static void ext_include_ast_free -(const struct sieve_extension *ext ATTR_UNUSED, +(const struct sieve_extension *ext ATTR_UNUSED, struct sieve_ast *ast ATTR_UNUSED, void *context) { - struct ext_include_ast_context *actx = + struct ext_include_ast_context *actx = (struct ext_include_ast_context *) context; struct sieve_script **scripts; unsigned int count, i; @@ -201,7 +201,7 @@ static void ext_include_ast_free scripts = array_get_modifiable(&actx->included_scripts, &count); for ( i = 0; i < count; i++ ) { sieve_script_unref(&scripts[i]); - } + } /* Unreference variable scopes */ if ( actx->global_vars != NULL ) @@ -214,7 +214,7 @@ static const struct sieve_ast_extension include_ast_extension = { }; struct ext_include_ast_context *ext_include_create_ast_context -(const struct sieve_extension *this_ext, struct sieve_ast *ast, +(const struct sieve_extension *this_ext, struct sieve_ast *ast, struct sieve_ast *parent) { struct ext_include_ast_context *actx; @@ -233,7 +233,7 @@ struct ext_include_ast_context *ext_include_create_ast_context sieve_variable_scope_ref(actx->global_vars); } else { - actx->global_vars = sieve_variable_scope_create(this_ext->svinst, this_ext); + actx->global_vars = sieve_variable_scope_create(this_ext->svinst, this_ext); } sieve_ast_extension_register @@ -255,9 +255,9 @@ struct ext_include_ast_context *ext_include_get_ast_context void ext_include_ast_link_included_script (const struct sieve_extension *this_ext, struct sieve_ast *ast, - struct sieve_script *script) + struct sieve_script *script) { - struct ext_include_ast_context *actx = + struct ext_include_ast_context *actx = ext_include_get_ast_context(this_ext, ast); array_append(&actx->included_scripts, &script, 1); @@ -271,15 +271,15 @@ bool ext_include_validator_have_variables return sieve_ext_variables_is_active(ectx->var_ext, valdtr); } -/* - * Generator context management +/* + * Generator context management */ - + static struct ext_include_generator_context * ext_include_create_generator_context -(struct sieve_generator *gentr, struct ext_include_generator_context *parent, +(struct sieve_generator *gentr, struct ext_include_generator_context *parent, struct sieve_script *script) -{ +{ struct ext_include_generator_context *ctx; pool_t pool = sieve_generator_pool(gentr); @@ -291,7 +291,7 @@ ext_include_create_generator_context } else { ctx->nesting_depth = parent->nesting_depth + 1; } - + return ctx; } @@ -314,16 +314,16 @@ static inline void ext_include_initialize_generator_context void ext_include_register_generator_context (const struct sieve_extension *this_ext, const struct sieve_codegen_env *cgenv) { - struct ext_include_generator_context *ctx = + struct ext_include_generator_context *ctx = ext_include_get_generator_context(this_ext, cgenv->gentr); - + /* Initialize generator context if necessary */ if ( ctx == NULL ) { ctx = ext_include_create_generator_context( cgenv->gentr, NULL, cgenv->script); - + sieve_generator_extension_set_context - (cgenv->gentr, this_ext, (void *) ctx); + (cgenv->gentr, this_ext, (void *) ctx); } /* Initialize ast context if necessary */ @@ -339,26 +339,26 @@ static void ext_include_runtime_init (const struct sieve_extension *this_ext, const struct sieve_runtime_env *renv, void *context) { - struct ext_include_interpreter_context *ctx = + struct ext_include_interpreter_context *ctx = (struct ext_include_interpreter_context *) context; struct ext_include_context *ectx = ext_include_get_context(this_ext); - + if ( ctx->parent == NULL ) { ctx->global = p_new(ctx->pool, struct ext_include_interpreter_global, 1); p_array_init(&ctx->global->included_scripts, ctx->pool, 10); - ctx->global->var_scope = + ctx->global->var_scope = ext_include_binary_get_global_scope(this_ext, renv->sbin); - ctx->global->var_storage = + ctx->global->var_storage = sieve_variable_storage_create(ctx->pool, ctx->global->var_scope); } else { ctx->global = ctx->parent->global; } sieve_ext_variables_runtime_set_storage - (ectx->var_ext, renv, this_ext, ctx->global->var_storage); + (ectx->var_ext, renv, this_ext, ctx->global->var_storage); } static struct sieve_interpreter_extension include_interpreter_extension = { @@ -367,16 +367,16 @@ static struct sieve_interpreter_extension include_interpreter_extension = { NULL, }; -/* - * Interpreter context management +/* + * Interpreter context management */ static struct ext_include_interpreter_context * ext_include_interpreter_context_create -(struct sieve_interpreter *interp, - struct ext_include_interpreter_context *parent, +(struct sieve_interpreter *interp, + struct ext_include_interpreter_context *parent, struct sieve_script *script, const struct ext_include_script_info *sinfo) -{ +{ struct ext_include_interpreter_context *ctx; pool_t pool = sieve_interpreter_pool(interp); @@ -406,26 +406,26 @@ static inline struct ext_include_interpreter_context * static inline struct ext_include_interpreter_context * ext_include_interpreter_context_init_child -(const struct sieve_extension *this_ext, struct sieve_interpreter *interp, - struct ext_include_interpreter_context *parent, +(const struct sieve_extension *this_ext, struct sieve_interpreter *interp, + struct ext_include_interpreter_context *parent, struct sieve_script *script, const struct ext_include_script_info *sinfo) { - struct ext_include_interpreter_context *ctx = + struct ext_include_interpreter_context *ctx = ext_include_interpreter_context_create(interp, parent, script, sinfo); - + sieve_interpreter_extension_register (interp, this_ext, &include_interpreter_extension, ctx); - + return ctx; } void ext_include_interpreter_context_init (const struct sieve_extension *this_ext, struct sieve_interpreter *interp) { - struct ext_include_interpreter_context *ctx = + struct ext_include_interpreter_context *ctx = ext_include_get_interpreter_context(this_ext, interp); - /* Is this is the top-level interpreter ? */ + /* Is this is the top-level interpreter ? */ if ( ctx == NULL ) { struct sieve_script *script; @@ -433,9 +433,9 @@ void ext_include_interpreter_context_init script = sieve_interpreter_script(interp); ctx = ext_include_interpreter_context_create (interp, NULL, script, NULL); - + sieve_interpreter_extension_register - (interp, this_ext, &include_interpreter_extension, (void *) ctx); + (interp, this_ext, &include_interpreter_extension, (void *) ctx); } } @@ -444,17 +444,17 @@ struct sieve_variable_storage *ext_include_interpreter_get_global_variables { struct ext_include_interpreter_context *ctx = ext_include_get_interpreter_context(this_ext, interp); - + return ctx->global->var_storage; } -/* - * Including a script during code generation +/* + * Including a script during code generation */ int ext_include_generate_include (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd, - enum ext_include_script_location location, struct sieve_script *script, + enum ext_include_script_location location, struct sieve_script *script, const struct ext_include_script_info **included_r, bool once) { const struct sieve_extension *this_ext = cmd->ext; @@ -471,15 +471,15 @@ int ext_include_generate_include struct ext_include_generator_context *pctx; struct sieve_error_handler *ehandler = sieve_generator_error_handler(gentr); const struct ext_include_script_info *included; - + *included_r = NULL; - /* Just to be sure: do not include more scripts when errors have occured - * already. + /* Just to be sure: do not include more scripts when errors have occured + * already. */ if ( sieve_get_errors(ehandler) > 0 ) return -1; - + /* Limit nesting level */ if ( ctx->nesting_depth >= ext_ctx->max_nesting_depth ) { sieve_command_generate_error @@ -487,7 +487,7 @@ int ext_include_generate_include ext_ctx->max_nesting_depth); return -1; } - + /* Check for circular include */ if ( !once ) { pctx = ctx; @@ -496,7 +496,7 @@ int ext_include_generate_include /* Just drop circular include when uploading inactive script; * not an error */ - if ( (cgenv->flags & SIEVE_COMPILE_FLAG_UPLOADED) != 0 && + if ( (cgenv->flags & SIEVE_COMPILE_FLAG_UPLOADED) != 0 && (cgenv->flags & SIEVE_COMPILE_FLAG_ACTIVATED) == 0 ) { sieve_command_generate_warning (gentr, cmd, "circular include (ignored during upload)"); @@ -506,7 +506,7 @@ int ext_include_generate_include sieve_command_generate_error(gentr, cmd, "circular include"); return -1; } - + pctx = pctx->parent; } } @@ -515,21 +515,21 @@ int ext_include_generate_include binctx = ext_include_binary_init(this_ext, sbin, cgenv->ast); /* Is the script already compiled into the current binary? */ - if ( !ext_include_binary_script_is_included(binctx, script, &included) ) - { + if ( !ext_include_binary_script_is_included(binctx, script, &included) ) + { struct sieve_binary_block *inc_block; const char *script_name = sieve_script_name(script); enum sieve_compile_flags cpflags = cgenv->flags; /* Check whether include limit is exceeded */ - if ( ext_include_binary_script_get_count(binctx) >= + if ( ext_include_binary_script_get_count(binctx) >= ext_ctx->max_includes ) { - sieve_command_generate_error(gentr, cmd, - "failed to include script '%s': no more than %u includes allowed", + sieve_command_generate_error(gentr, cmd, + "failed to include script '%s': no more than %u includes allowed", str_sanitize(script_name, 80), ext_ctx->max_includes); return -1; } - + /* No, allocate a new block in the binary and mark the script as included. */ inc_block = sieve_binary_block_create(sbin); @@ -538,11 +538,11 @@ int ext_include_generate_include /* Parse */ if ( (ast = sieve_parse(script, ehandler, NULL)) == NULL ) { - sieve_command_generate_error(gentr, cmd, + sieve_command_generate_error(gentr, cmd, "failed to parse included script '%s'", str_sanitize(script_name, 80)); return -1; } - + /* Included scripts inherit global variable scope */ (void)ext_include_create_ast_context(this_ext, ast, cmd->ast_node->ast); @@ -553,41 +553,41 @@ int ext_include_generate_include /* Validate */ if ( !sieve_validate(ast, ehandler, cpflags, NULL) ) { - sieve_command_generate_error(gentr, cmd, - "failed to validate included script '%s'", + sieve_command_generate_error(gentr, cmd, + "failed to validate included script '%s'", str_sanitize(script_name, 80)); sieve_ast_unref(&ast); return -1; } - /* Generate + /* Generate * - * FIXME: It might not be a good idea to recurse code generation for + * FIXME: It might not be a good idea to recurse code generation for * included scripts. */ - subgentr = sieve_generator_create(ast, ehandler, cpflags); + subgentr = sieve_generator_create(ast, ehandler, cpflags); ext_include_initialize_generator_context(cmd->ext, subgentr, ctx, script); - + if ( sieve_generator_run(subgentr, &inc_block) == NULL ) { - sieve_command_generate_error(gentr, cmd, - "failed to generate code for included script '%s'", + sieve_command_generate_error(gentr, cmd, + "failed to generate code for included script '%s'", str_sanitize(script_name, 80)); result = -1; } - + sieve_generator_free(&subgentr); - + /* Cleanup */ - sieve_ast_unref(&ast); - } + sieve_ast_unref(&ast); + } if ( result > 0 ) *included_r = included; - + return result; } -/* - * Executing an included script during interpretation +/* + * Executing an included script during interpretation */ static int ext_include_runtime_check_circular @@ -614,14 +614,14 @@ static bool ext_include_runtime_include_mark { struct sieve_script *const *includes; unsigned int count, i; - + includes = array_get(&ctx->global->included_scripts, &count); for ( i = 0; i < count; i++ ) { if ( sieve_script_equals(include->script, includes[i]) ) return ( !once ); } - + array_append(&ctx->global->included_scripts, &include->script, 1); return TRUE; @@ -634,46 +634,46 @@ int ext_include_execute_include int result = SIEVE_EXEC_OK; struct ext_include_interpreter_context *ctx; const struct ext_include_script_info *included; - struct ext_include_binary_context *binctx = + struct ext_include_binary_context *binctx = ext_include_binary_get_context(this_ext, renv->sbin); unsigned int block_id; /* Check for invalid include id (== corrupt binary) */ included = ext_include_binary_script_get_included(binctx, include_id); if ( included == NULL ) { - sieve_runtime_trace_error(renv, "include: include id %d is invalid", + sieve_runtime_trace_error(renv, "include: include id %d is invalid", include_id); return SIEVE_EXEC_BIN_CORRUPT; } ctx = ext_include_get_interpreter_context(this_ext, renv->interp); - + block_id = sieve_binary_block_get_id(included->block); /* If :once modifier is specified, check for duplicate include */ if ( ext_include_runtime_include_mark(ctx, included, once) ) { sieve_runtime_trace(renv, SIEVE_TRLVL_NONE, - "include: start script '%s' [inc id: %d, block: %d]", + "include: start script '%s' [inc id: %d, block: %d]", sieve_script_name(included->script), include_id, block_id); } else { /* skip */ - sieve_runtime_trace(renv, SIEVE_TRLVL_NONE, + sieve_runtime_trace(renv, SIEVE_TRLVL_NONE, "include: skipped include for script '%s' [inc id: %d, block: %d]; " - "already run once", + "already run once", sieve_script_name(included->script), include_id, block_id); return result; } - /* Check circular include during interpretation as well. + /* Check circular include during interpretation as well. * Let's not trust binaries. */ if ( ext_include_runtime_check_circular(ctx, included) ) { - sieve_runtime_trace_error(renv, - "include: circular include of script '%s' [inc id: %d, block: %d]", + sieve_runtime_trace_error(renv, + "include: circular include of script '%s' [inc id: %d, block: %d]", sieve_script_name(included->script), include_id, block_id); /* Situation has no valid way to emerge at runtime */ - return SIEVE_EXEC_BIN_CORRUPT; + return SIEVE_EXEC_BIN_CORRUPT; } if ( ctx->parent == NULL ) { @@ -682,22 +682,22 @@ int ext_include_execute_include struct sieve_interpreter *subinterp; bool interrupted = FALSE; - /* We are the top-level interpreter instance */ - + /* We are the top-level interpreter instance */ + if ( result == SIEVE_EXEC_OK ) { enum sieve_runtime_flags rtflags = 0; - + if ( included->location != EXT_INCLUDE_LOCATION_GLOBAL ) rtflags |= SIEVE_RUNTIME_FLAG_NOGLOBAL; /* Create interpreter for top-level included script - * (first sub-interpreter) + * (first sub-interpreter) */ subinterp = sieve_interpreter_create_for_block - (included->block, included->script, renv->msgdata, renv->scriptenv, + (included->block, included->script, renv->msgdata, renv->scriptenv, ehandler, rtflags); - if ( subinterp != NULL ) { + if ( subinterp != NULL ) { curctx = ext_include_interpreter_context_init_child (this_ext, subinterp, ctx, included->script, included); @@ -707,19 +707,19 @@ int ext_include_execute_include } else result = SIEVE_EXEC_BIN_CORRUPT; } - + /* Included scripts can have includes of their own. This is not implemented - * recursively. Rather, the sub-interpreter interrupts and defers the + * recursively. Rather, the sub-interpreter interrupts and defers the * include to the top-level interpreter, which is here. */ if ( result == SIEVE_EXEC_OK && interrupted && !curctx->returned ) { while ( result == SIEVE_EXEC_OK ) { - if ( ( (interrupted && curctx->returned) || (!interrupted) ) && + if ( ( (interrupted && curctx->returned) || (!interrupted) ) && curctx->parent != NULL ) { const struct ext_include_script_info *ended_script = - curctx->script_info; - + curctx->script_info; + /* Sub-interpreter ended or executed return */ /* Ascend interpreter stack */ @@ -727,15 +727,15 @@ int ext_include_execute_include sieve_interpreter_free(&subinterp); sieve_runtime_trace(renv, SIEVE_TRLVL_NONE, - "include: script '%s' ended [inc id: %d, block: %d]", + "include: script '%s' ended [inc id: %d, block: %d]", sieve_script_name(ended_script->script), ended_script->id, sieve_binary_block_get_id(ended_script->block)); - + /* This is the top-most sub-interpreter, bail out */ if ( curctx->parent == NULL ) break; - - subinterp = curctx->interp; - + + subinterp = curctx->interp; + /* Continue parent */ curctx->include = NULL; curctx->returned = FALSE; @@ -744,34 +744,34 @@ int ext_include_execute_include } else { if ( curctx->include != NULL ) { /* Sub-include requested */ - + if ( result == SIEVE_EXEC_OK ) { enum sieve_runtime_flags rtflags = 0; - + if ( curctx->include->location != EXT_INCLUDE_LOCATION_GLOBAL ) rtflags |= SIEVE_RUNTIME_FLAG_NOGLOBAL; /* Create sub-interpreter */ subinterp = sieve_interpreter_create_for_block (curctx->include->block, curctx->include->script, renv->msgdata, - renv->scriptenv, ehandler, rtflags); + renv->scriptenv, ehandler, rtflags); if ( subinterp != NULL ) { curctx = ext_include_interpreter_context_init_child - (this_ext, subinterp, curctx, curctx->include->script, + (this_ext, subinterp, curctx, curctx->include->script, curctx->include); /* Start the sub-include's interpreter */ curctx->include = NULL; curctx->returned = FALSE; - result = ( sieve_interpreter_start(subinterp, renv->result, - &interrupted) == 1 ); + result = ( sieve_interpreter_start(subinterp, renv->result, + &interrupted) == 1 ); } else result = SIEVE_EXEC_BIN_CORRUPT; } } else { /* Sub-interpreter was interrupted outside this extension, probably - * stop command was executed. Generate an interrupt ourselves, + * stop command was executed. Generate an interrupt ourselves, * ending all script execution. */ sieve_interpreter_interrupt(renv->interp); @@ -786,13 +786,13 @@ int ext_include_execute_include struct ext_include_interpreter_context *nextctx = curctx->parent; struct sieve_interpreter *killed_interp = curctx->interp; const struct ext_include_script_info *ended_script = - curctx->script_info; + curctx->script_info; /* This kills curctx too */ sieve_interpreter_free(&killed_interp); sieve_runtime_trace(renv, SIEVE_TRLVL_NONE, - "include: script '%s' ended [id: %d, block: %d]", + "include: script '%s' ended [id: %d, block: %d]", sieve_script_name(ended_script->script), ended_script->id, sieve_binary_block_get_id(ended_script->block)); @@ -806,7 +806,7 @@ int ext_include_execute_include ctx->include = included; sieve_interpreter_interrupt(renv->interp); } - + return result; } @@ -816,11 +816,11 @@ void ext_include_execute_return const struct sieve_extension *this_ext = renv->oprtn->ext; struct ext_include_interpreter_context *ctx = ext_include_get_interpreter_context(this_ext, renv->interp); - - sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, + + sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, "return: exiting included script"); ctx->returned = TRUE; - sieve_interpreter_interrupt(renv->interp); + sieve_interpreter_interrupt(renv->interp); } - + diff --git a/src/lib-sieve/plugins/include/ext-include-common.h b/src/lib-sieve/plugins/include/ext-include-common.h index d62503743f79c79bda4095a49202cb6eeb72db3f..ac26c9a7f155a68676362a3bcf7d85af4b5ef454 100644 --- a/src/lib-sieve/plugins/include/ext-include-common.h +++ b/src/lib-sieve/plugins/include/ext-include-common.h @@ -10,21 +10,21 @@ #include "sieve-common.h" #include "sieve-extensions.h" -/* +/* * Forward declarations */ struct ext_include_script_info; struct ext_include_binary_context; -/* - * Types +/* + * Types */ -enum ext_include_script_location { - EXT_INCLUDE_LOCATION_PERSONAL, +enum ext_include_script_location { + EXT_INCLUDE_LOCATION_PERSONAL, EXT_INCLUDE_LOCATION_GLOBAL, - EXT_INCLUDE_LOCATION_INVALID + EXT_INCLUDE_LOCATION_INVALID }; static inline const char *ext_include_script_location_name @@ -45,8 +45,8 @@ static inline const char *ext_include_script_location_name } -/* - * Extension +/* + * Extension */ extern const struct sieve_extension_def include_extension; @@ -57,44 +57,44 @@ bool ext_include_load void ext_include_unload (const struct sieve_extension *ext); -/* - * Commands +/* + * Commands */ extern const struct sieve_command_def cmd_include; extern const struct sieve_command_def cmd_return; extern const struct sieve_command_def cmd_global; -/* DEPRICATED */ +/* DEPRICATED */ extern const struct sieve_command_def cmd_import; extern const struct sieve_command_def cmd_export; /* * Operations */ - + enum ext_include_opcode { EXT_INCLUDE_OPERATION_INCLUDE, EXT_INCLUDE_OPERATION_RETURN, EXT_INCLUDE_OPERATION_GLOBAL }; - + extern const struct sieve_operation_def include_operation; extern const struct sieve_operation_def return_operation; extern const struct sieve_operation_def global_operation; -/* - * Script access +/* + * Script access */ const char *ext_include_get_script_location (const struct sieve_extension *ext, enum ext_include_script_location location, const char *script_name); -/* - * Context +/* + * Context */ - + /* Extension context */ struct ext_include_context { @@ -124,13 +124,13 @@ struct ext_include_ast_context { }; struct ext_include_ast_context *ext_include_create_ast_context - (const struct sieve_extension *this_ext, struct sieve_ast *ast, + (const struct sieve_extension *this_ext, struct sieve_ast *ast, struct sieve_ast *parent); struct ext_include_ast_context *ext_include_get_ast_context (const struct sieve_extension *this_ext, struct sieve_ast *ast); void ext_include_ast_link_included_script - (const struct sieve_extension *this_ext, struct sieve_ast *ast, + (const struct sieve_extension *this_ext, struct sieve_ast *ast, struct sieve_script *script); bool ext_include_validator_have_variables @@ -139,12 +139,12 @@ bool ext_include_validator_have_variables /* Generator context */ void ext_include_register_generator_context - (const struct sieve_extension *this_ext, + (const struct sieve_extension *this_ext, const struct sieve_codegen_env *cgenv); int ext_include_generate_include (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd, - enum ext_include_script_location location, struct sieve_script *script, + enum ext_include_script_location location, struct sieve_script *script, const struct ext_include_script_info **included_r, bool once); /* Interpreter context */ diff --git a/src/lib-sieve/plugins/include/ext-include-variables.c b/src/lib-sieve/plugins/include/ext-include-variables.c index 5a5d9c18d7a5427a873b50512d485122e3dfba51..a8fc61205a29d6a2fa13120837405655fa0fc107 100644 --- a/src/lib-sieve/plugins/include/ext-include-variables.c +++ b/src/lib-sieve/plugins/include/ext-include-variables.c @@ -21,24 +21,24 @@ #include "ext-include-binary.h" #include "ext-include-variables.h" -/* +/* * Variable import-export */ - + struct sieve_variable *ext_include_variable_import_global -(struct sieve_validator *valdtr, struct sieve_command *cmd, +(struct sieve_validator *valdtr, struct sieve_command *cmd, const char *variable) { const struct sieve_extension *this_ext = cmd->ext; struct sieve_ast *ast = cmd->ast_node->ast; - struct ext_include_ast_context *ctx = + struct ext_include_ast_context *ctx = ext_include_get_ast_context(this_ext, ast); struct ext_include_context *ectx = ext_include_get_context(this_ext); struct sieve_variable_scope *local_scope; struct sieve_variable_scope *global_scope = ctx->global_vars; struct sieve_variable *global_var = NULL, *local_var; - /* Sanity safeguard */ + /* Sanity safeguard */ i_assert ( ctx->global_vars != NULL ); if ( !sieve_variable_identifier_is_valid(variable) ) { @@ -54,11 +54,11 @@ struct sieve_variable *ext_include_variable_import_global if ( global_var == NULL ) { sieve_command_validate_error(valdtr, cmd, "declaration of new global variable '%s' exceeds the limit " - "(max variables: %u)", + "(max variables: %u)", variable, sieve_variables_get_max_scope_size()); return NULL; } - + /* Import the global variable into the local script scope */ local_scope = sieve_ext_variables_get_local_scope(ectx->var_ext, valdtr); @@ -77,9 +77,9 @@ struct sieve_variable *ext_include_variable_import_global /* * Binary symbol table */ - + bool ext_include_variables_save -(struct sieve_binary_block *sblock, +(struct sieve_binary_block *sblock, struct sieve_variable_scope_binary *global_vars) { struct sieve_variable_scope *global_scope = @@ -93,7 +93,7 @@ bool ext_include_variables_save if ( count > 0 ) { unsigned int size, i; - struct sieve_variable *const *vars = + struct sieve_variable *const *vars = sieve_variable_scope_get_variables(global_scope, &size); for ( i = 0; i < size; i++ ) { @@ -107,7 +107,7 @@ bool ext_include_variables_save } bool ext_include_variables_load -(const struct sieve_extension *this_ext, struct sieve_binary_block *sblock, +(const struct sieve_extension *this_ext, struct sieve_binary_block *sblock, sieve_size_t *offset, struct sieve_variable_scope_binary **global_vars_r) { /* Sanity assert */ @@ -136,10 +136,10 @@ bool ext_include_variables_dump unsigned int i; sieve_binary_dump_sectionf(denv, "Global variables"); - + for ( i = 0; i < size; i++ ) { sieve_binary_dumpf(denv, "%3d: '%s' \n", i, vars[i]->identifier); - } + } } return TRUE; @@ -151,44 +151,44 @@ bool ext_include_variables_dump bool vnspc_global_variables_validate (struct sieve_validator *valdtr, const struct sieve_variables_namespace *nspc, - struct sieve_ast_argument *arg, struct sieve_command *cmd, - ARRAY_TYPE(sieve_variable_name) *var_name, void **var_data, + struct sieve_ast_argument *arg, struct sieve_command *cmd, + ARRAY_TYPE(sieve_variable_name) *var_name, void **var_data, bool assignment); bool vnspc_global_variables_generate - (const struct sieve_codegen_env *cgenv, + (const struct sieve_codegen_env *cgenv, const struct sieve_variables_namespace *nspc, struct sieve_ast_argument *arg, struct sieve_command *cmd, void *var_data); static const struct sieve_variables_namespace_def global_variables_namespace = { SIEVE_OBJECT("global", NULL, 0), - vnspc_global_variables_validate, + vnspc_global_variables_validate, vnspc_global_variables_generate, NULL, NULL }; bool vnspc_global_variables_validate -(struct sieve_validator *valdtr, +(struct sieve_validator *valdtr, const struct sieve_variables_namespace *nspc, struct sieve_ast_argument *arg, - struct sieve_command *cmd ATTR_UNUSED, - ARRAY_TYPE(sieve_variable_name) *var_name, void **var_data, + struct sieve_command *cmd ATTR_UNUSED, + ARRAY_TYPE(sieve_variable_name) *var_name, void **var_data, bool assignment ATTR_UNUSED) { const struct sieve_extension *this_ext = SIEVE_OBJECT_EXTENSION(nspc); struct sieve_ast *ast = arg->ast; - struct ext_include_ast_context *ctx = + struct ext_include_ast_context *ctx = ext_include_get_ast_context(this_ext, ast); struct sieve_variable *var = NULL; const struct sieve_variable_name *name_element; const char *variable; - /* Sanity safeguard */ + /* Sanity safeguard */ i_assert ( ctx->global_vars != NULL ); /* Check variable name */ if ( array_count(var_name) != 2 ) { - sieve_argument_validate_error(valdtr, arg, + sieve_argument_validate_error(valdtr, arg, "invalid variable name within global namespace: " "encountered sub-namespace"); return FALSE; @@ -196,12 +196,12 @@ bool vnspc_global_variables_validate name_element = array_idx(var_name, 1); if ( name_element->num_variable >= 0 ) { - sieve_argument_validate_error(valdtr, arg, + sieve_argument_validate_error(valdtr, arg, "invalid variable name within global namespace: " "encountered numeric variable name"); return FALSE; } - + variable = str_c(name_element->identifier); /* Get/Declare the variable in the global scope */ @@ -209,28 +209,28 @@ bool vnspc_global_variables_validate var = sieve_variable_scope_get_variable(ctx->global_vars, variable, TRUE); if ( var == NULL ) { - sieve_argument_validate_error(valdtr, arg, + sieve_argument_validate_error(valdtr, arg, "(implicit) declaration of new global variable '%s' exceeds the limit " - "(max variables: %u)", variable, + "(max variables: %u)", variable, sieve_variables_get_max_scope_size()); return FALSE; } - + *var_data = (void *) var; return TRUE; } bool vnspc_global_variables_generate -(const struct sieve_codegen_env *cgenv, - const struct sieve_variables_namespace *nspc, - struct sieve_ast_argument *arg ATTR_UNUSED, +(const struct sieve_codegen_env *cgenv, + const struct sieve_variables_namespace *nspc, + struct sieve_ast_argument *arg ATTR_UNUSED, struct sieve_command *cmd ATTR_UNUSED, void *var_data) { const struct sieve_extension *this_ext = SIEVE_OBJECT_EXTENSION(nspc); struct ext_include_context *ectx = ext_include_get_context(this_ext); struct sieve_variable *var = (struct sieve_variable *) var_data; - + sieve_variables_opr_variable_emit(cgenv->sblock, ectx->var_ext, var); return TRUE; diff --git a/src/lib-sieve/plugins/include/ext-include-variables.h b/src/lib-sieve/plugins/include/ext-include-variables.h index 190a61363b283c0c0b89b876422945167e7d0691..fabe29e982d82c014bf50b87b05e8b5b0e6cb1f1 100644 --- a/src/lib-sieve/plugins/include/ext-include-variables.h +++ b/src/lib-sieve/plugins/include/ext-include-variables.h @@ -10,12 +10,12 @@ #include "ext-include-common.h" -/* +/* * Variable import-export */ - + struct sieve_variable *ext_include_variable_import_global - (struct sieve_validator *valdtr, struct sieve_command *cmd, + (struct sieve_validator *valdtr, struct sieve_command *cmd, const char *variable); /* @@ -26,7 +26,7 @@ bool ext_include_variables_save (struct sieve_binary_block *sblock, struct sieve_variable_scope_binary *global_vars); bool ext_include_variables_load - (const struct sieve_extension *this_ext, struct sieve_binary_block *sblock, + (const struct sieve_extension *this_ext, struct sieve_binary_block *sblock, sieve_size_t *offset, struct sieve_variable_scope_binary **global_vars_r); bool ext_include_variables_dump (struct sieve_dumptime_env *denv, @@ -38,6 +38,6 @@ bool ext_include_variables_dump void ext_include_variables_global_namespace_init (const struct sieve_extension *this_ext, struct sieve_validator *valdtr); - + #endif /* __EXT_INCLUDE_VARIABLES_H */ diff --git a/src/lib-sieve/plugins/include/ext-include.c b/src/lib-sieve/plugins/include/ext-include.c index 865f20523e073e793e7d7c513a00154688ecc0a7..11f24b99b8e2dd44a60f537fdeaf3ef8c99e04c2 100644 --- a/src/lib-sieve/plugins/include/ext-include.c +++ b/src/lib-sieve/plugins/include/ext-include.c @@ -34,20 +34,20 @@ #include "ext-include-binary.h" #include "ext-include-variables.h" -/* - * Operations +/* + * Operations */ -static const struct sieve_operation_def *ext_include_operations[] = { - &include_operation, +static const struct sieve_operation_def *ext_include_operations[] = { + &include_operation, &return_operation, &global_operation }; -/* +/* * Extension */ - + /* Forward declaration */ static bool ext_include_validator_load @@ -55,18 +55,18 @@ static bool ext_include_validator_load static bool ext_include_generator_load (const struct sieve_extension *ext, const struct sieve_codegen_env *cgenv); static bool ext_include_interpreter_load - (const struct sieve_extension *ext, const struct sieve_runtime_env *renv, + (const struct sieve_extension *ext, const struct sieve_runtime_env *renv, sieve_size_t *address); static bool ext_include_binary_load (const struct sieve_extension *ext, struct sieve_binary *binary); /* Extension objects */ -const struct sieve_extension_def include_extension = { - "include", +const struct sieve_extension_def include_extension = { + "include", ext_include_load, ext_include_unload, - ext_include_validator_load, + ext_include_validator_load, ext_include_generator_load, ext_include_interpreter_load, ext_include_binary_load, @@ -92,7 +92,7 @@ static bool ext_include_validator_load ext_include_variables_global_namespace_init(ext, valdtr); return TRUE; -} +} static bool ext_include_generator_load (const struct sieve_extension *ext, const struct sieve_codegen_env *cgenv) @@ -103,11 +103,11 @@ static bool ext_include_generator_load } static bool ext_include_interpreter_load -(const struct sieve_extension *ext, const struct sieve_runtime_env *renv, +(const struct sieve_extension *ext, const struct sieve_runtime_env *renv, sieve_size_t *address ATTR_UNUSED) { ext_include_interpreter_context_init(ext, renv->interp); - + return TRUE; } diff --git a/src/lib-sieve/plugins/mailbox/ext-mailbox.c b/src/lib-sieve/plugins/mailbox/ext-mailbox.c index 7fca6d501fd5459af9e60123ae11feac0a59fa65..e94c93b9e3f9ac4615f9c9f5d1d3ef47256ae642 100644 --- a/src/lib-sieve/plugins/mailbox/ext-mailbox.c +++ b/src/lib-sieve/plugins/mailbox/ext-mailbox.c @@ -31,10 +31,10 @@ static bool ext_mailbox_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr); -const struct sieve_extension_def mailbox_extension = { - "mailbox", +const struct sieve_extension_def mailbox_extension = { + "mailbox", NULL, NULL, - ext_mailbox_validator_load, + ext_mailbox_validator_load, NULL, NULL, NULL, NULL, NULL, SIEVE_EXT_DEFINE_OPERATION(mailboxexists_operation), SIEVE_EXT_DEFINE_OPERAND(mailbox_create_operand) @@ -43,9 +43,9 @@ const struct sieve_extension_def mailbox_extension = { static bool ext_mailbox_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr) { - /* Register :create tag with fileinto command and we don't care whether this - * command is registered or even whether it will be registered at all. The - * validator handles either situation gracefully + /* Register :create tag with fileinto command and we don't care whether this + * command is registered or even whether it will be registered at all. The + * validator handles either situation gracefully */ sieve_validator_register_external_tag (valdtr, "fileinto", ext, &mailbox_create_tag, SIEVE_OPT_SIDE_EFFECT); diff --git a/src/lib-sieve/plugins/mailbox/tag-mailbox-create.c b/src/lib-sieve/plugins/mailbox/tag-mailbox-create.c index 583bbe2217a6f5549aa5dad3f86ffb1ce4b48ed1..bc440c1d7462c2637c632b9318cc475d8dccf481 100644 --- a/src/lib-sieve/plugins/mailbox/tag-mailbox-create.c +++ b/src/lib-sieve/plugins/mailbox/tag-mailbox-create.c @@ -15,35 +15,35 @@ #include "ext-mailbox-common.h" -/* - * Tagged argument +/* + * Tagged argument */ static bool tag_mailbox_create_validate - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); static bool tag_mailbox_create_generate (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *context); -const struct sieve_argument_def mailbox_create_tag = { - "create", +const struct sieve_argument_def mailbox_create_tag = { + "create", NULL, - tag_mailbox_create_validate, + tag_mailbox_create_validate, NULL, NULL, tag_mailbox_create_generate }; /* - * Side effect + * Side effect */ static void seff_mailbox_create_print - (const struct sieve_side_effect *seffect, const struct sieve_action *action, + (const struct sieve_side_effect *seffect, const struct sieve_action *action, const struct sieve_result_print_env *rpenv, bool *keep); static bool seff_mailbox_create_pre_execute - (const struct sieve_side_effect *seffect, const struct sieve_action *action, - const struct sieve_action_exec_env *aenv, void **se_context, + (const struct sieve_side_effect *seffect, const struct sieve_action *action, + const struct sieve_action_exec_env *aenv, void **se_context, void *tr_context); const struct sieve_side_effect_def mailbox_create_side_effect = { @@ -51,7 +51,7 @@ const struct sieve_side_effect_def mailbox_create_side_effect = { &act_store, NULL, NULL, NULL, seff_mailbox_create_print, - seff_mailbox_create_pre_execute, + seff_mailbox_create_pre_execute, NULL, NULL, NULL }; @@ -70,12 +70,12 @@ const struct sieve_operand_def mailbox_create_operand = { &ext_side_effects }; -/* - * Tag validation +/* + * Tag validation */ static bool tag_mailbox_create_validate -(struct sieve_validator *valdtr ATTR_UNUSED, +(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_ast_argument **arg, struct sieve_command *cmd ATTR_UNUSED) { *arg = sieve_ast_argument_next(*arg); @@ -84,7 +84,7 @@ static bool tag_mailbox_create_validate } /* - * Code generation + * Code generation */ static bool tag_mailbox_create_generate @@ -101,41 +101,41 @@ static bool tag_mailbox_create_generate return TRUE; } -/* +/* * Side effect implementation */ static void seff_mailbox_create_print -(const struct sieve_side_effect *seffect ATTR_UNUSED, - const struct sieve_action *action ATTR_UNUSED, +(const struct sieve_side_effect *seffect ATTR_UNUSED, + const struct sieve_action *action ATTR_UNUSED, const struct sieve_result_print_env *rpenv, bool *keep ATTR_UNUSED) { sieve_result_seffect_printf(rpenv, "create mailbox if it does not exist"); } static bool seff_mailbox_create_pre_execute -(const struct sieve_side_effect *seffect ATTR_UNUSED, - const struct sieve_action *action ATTR_UNUSED, +(const struct sieve_side_effect *seffect ATTR_UNUSED, + const struct sieve_action *action ATTR_UNUSED, const struct sieve_action_exec_env *aenv ATTR_UNUSED, void **se_context ATTR_UNUSED, void *tr_context ATTR_UNUSED) -{ - struct act_store_transaction *trans = +{ + struct act_store_transaction *trans = (struct act_store_transaction *) tr_context; struct mail_storage **storage = &(aenv->exec_status->last_storage); enum mail_error error; - + /* Check whether creation is necessary */ if ( trans->box == NULL || trans->disabled ) return TRUE; /* Check whether creation has a chance of working */ - if ( trans->error_code != MAIL_ERROR_NONE && + if ( trans->error_code != MAIL_ERROR_NONE && trans->error_code != MAIL_ERROR_NOTFOUND ) return FALSE; trans->error = NULL; trans->error_code = MAIL_ERROR_NONE; - + *storage = mailbox_get_storage(trans->box); diff --git a/src/lib-sieve/plugins/mailbox/tst-mailboxexists.c b/src/lib-sieve/plugins/mailbox/tst-mailboxexists.c index 33ad0005c03919233a22f83bf70e5dac29c67504..852024b94fce23e18321f11ad9c2389b172578a1 100644 --- a/src/lib-sieve/plugins/mailbox/tst-mailboxexists.c +++ b/src/lib-sieve/plugins/mailbox/tst-mailboxexists.c @@ -17,8 +17,8 @@ #include "ext-mailbox-common.h" -/* - * Mailboxexists command +/* + * Mailboxexists command * * Syntax: * mailboxexists <mailbox-names: string-list> @@ -29,18 +29,18 @@ static bool tst_mailboxexists_validate static bool tst_mailboxexists_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx); -const struct sieve_command_def mailboxexists_test = { - "mailboxexists", - SCT_TEST, +const struct sieve_command_def mailboxexists_test = { + "mailboxexists", + SCT_TEST, 1, 0, FALSE, FALSE, NULL, NULL, tst_mailboxexists_validate, - NULL, - tst_mailboxexists_generate, - NULL + NULL, + tst_mailboxexists_generate, + NULL }; -/* +/* * Mailboxexists operation */ @@ -49,37 +49,37 @@ static bool tst_mailboxexists_operation_dump static int tst_mailboxexists_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def mailboxexists_operation = { +const struct sieve_operation_def mailboxexists_operation = { "MAILBOXEXISTS", - &mailbox_extension, - 0, - tst_mailboxexists_operation_dump, - tst_mailboxexists_operation_execute + &mailbox_extension, + 0, + tst_mailboxexists_operation_dump, + tst_mailboxexists_operation_execute }; -/* - * Test validation +/* + * Test validation */ static bool tst_mailboxexists_validate -(struct sieve_validator *valdtr, struct sieve_command *tst) -{ +(struct sieve_validator *valdtr, struct sieve_command *tst) +{ struct sieve_ast_argument *arg = tst->first_positional; - + if ( !sieve_validate_positional_argument (valdtr, tst, arg, "mailbox-names", 1, SAAT_STRING_LIST) ) { return FALSE; } - + return sieve_validator_argument_activate(valdtr, tst, arg, FALSE); } -/* - * Test generation +/* + * Test generation */ static bool tst_mailboxexists_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *tst) +(const struct sieve_codegen_env *cgenv, struct sieve_command *tst) { sieve_operation_emit(cgenv->sblock, tst->ext, &mailboxexists_operation); @@ -87,8 +87,8 @@ static bool tst_mailboxexists_generate return sieve_generate_arguments(cgenv, tst, NULL); } -/* - * Code dump +/* + * Code dump */ static bool tst_mailboxexists_operation_dump @@ -96,13 +96,13 @@ static bool tst_mailboxexists_operation_dump { sieve_code_dumpf(denv, "MAILBOXEXISTS"); sieve_code_descend(denv); - + return sieve_opr_stringlist_dump(denv, address, "mailbox-names"); } -/* - * Code execution +/* + * Code execution */ static int tst_mailboxexists_operation_execute @@ -110,19 +110,19 @@ static int tst_mailboxexists_operation_execute { struct sieve_stringlist *mailbox_names; string_t *mailbox_item; - bool trace = FALSE; + bool trace = FALSE; bool all_exist = TRUE; int ret; /* - * Read operands + * Read operands */ - + /* Read notify uris */ if ( (ret=sieve_opr_stringlist_read (renv, address, "mailbox-names", &mailbox_names)) <= 0 ) return ret; - + /* * Perform operation */ @@ -138,7 +138,7 @@ static int tst_mailboxexists_operation_execute int ret; mailbox_item = NULL; - while ( (ret=sieve_stringlist_next_item(mailbox_names, &mailbox_item)) > 0 ) + while ( (ret=sieve_stringlist_next_item(mailbox_names, &mailbox_item)) > 0 ) { struct mail_namespace *ns; const char *mailbox = str_c(mailbox_item); @@ -148,7 +148,7 @@ static int tst_mailboxexists_operation_execute ns = mail_namespace_find(renv->scriptenv->user->namespaces, mailbox); if ( ns == NULL) { if ( trace ) { - sieve_runtime_trace(renv, 0, "mailbox `%s' not found", + sieve_runtime_trace(renv, 0, "mailbox `%s' not found", str_sanitize(mailbox, 80)); } @@ -160,7 +160,7 @@ static int tst_mailboxexists_operation_execute box = mailbox_alloc(ns->list, mailbox, 0); if ( mailbox_open(box) < 0 ) { if ( trace ) { - sieve_runtime_trace(renv, 0, "mailbox `%s' cannot be opened", + sieve_runtime_trace(renv, 0, "mailbox `%s' cannot be opened", str_sanitize(mailbox, 80)); } @@ -172,7 +172,7 @@ static int tst_mailboxexists_operation_execute /* Also fail when it is readonly */ if ( mailbox_is_readonly(box) ) { if ( trace ) { - sieve_runtime_trace(renv, 0, "mailbox `%s' is read-only", + sieve_runtime_trace(renv, 0, "mailbox `%s' is read-only", str_sanitize(mailbox, 80)); } @@ -184,14 +184,14 @@ static int tst_mailboxexists_operation_execute /* FIXME: check acl for 'p' or 'i' ACL permissions as required by RFC */ if ( trace ) { - sieve_runtime_trace(renv, 0, "mailbox `%s' exists", + sieve_runtime_trace(renv, 0, "mailbox `%s' exists", str_sanitize(mailbox, 80)); } /* Close mailbox */ mailbox_free(&box); } - + if ( ret < 0 ) { sieve_runtime_trace_error(renv, "invalid mailbox name item"); return SIEVE_EXEC_BIN_CORRUPT; @@ -204,7 +204,7 @@ static int tst_mailboxexists_operation_execute else sieve_runtime_trace(renv, 0, "some mailboxes are unavailable"); } - + sieve_interpreter_set_test_result(renv->interp, all_exist); return SIEVE_EXEC_OK; } diff --git a/src/lib-sieve/plugins/notify/cmd-denotify.c b/src/lib-sieve/plugins/notify/cmd-denotify.c index 2f23ab98954c838debfe0e98a425d88d4ad16203..8a70b729649da70a07a7569d7cc66d6bc2ec59b5 100644 --- a/src/lib-sieve/plugins/notify/cmd-denotify.c +++ b/src/lib-sieve/plugins/notify/cmd-denotify.c @@ -20,8 +20,8 @@ #include "sieve-result.h" #include "ext-notify-common.h" - -/* + +/* * Denotify command * * Syntax: @@ -46,7 +46,7 @@ const struct sieve_command_def cmd_denotify = { cmd_denotify_pre_validate, cmd_denotify_validate, NULL, - cmd_denotify_generate, + cmd_denotify_generate, NULL }; @@ -81,8 +81,8 @@ enum cmd_denotify_optional { OPT_MATCH_KEY }; -/* - * Denotify operation +/* + * Denotify operation */ static bool cmd_denotify_operation_dump @@ -90,7 +90,7 @@ static bool cmd_denotify_operation_dump static int cmd_denotify_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def denotify_operation = { +const struct sieve_operation_def denotify_operation = { "DENOTIFY", ¬ify_extension, EXT_NOTIFY_OPERATION_DENOTIFY, @@ -129,23 +129,23 @@ static bool tag_match_type_validate return FALSE; if ( *arg == NULL ) { - sieve_argument_validate_error(valdtr, tag, + sieve_argument_validate_error(valdtr, tag, "the MATCH-TYPE argument (:%s) for the denotify command requires " - "an additional key-string parameter, but no more arguments were found", + "an additional key-string parameter, but no more arguments were found", sieve_ast_argument_tag(tag)); - return FALSE; + return FALSE; } - - if ( sieve_ast_argument_type(*arg) != SAAT_STRING ) + + if ( sieve_ast_argument_type(*arg) != SAAT_STRING ) { - sieve_argument_validate_error(valdtr, *arg, + sieve_argument_validate_error(valdtr, *arg, "the MATCH-TYPE argument (:%s) for the denotify command requires " - "an additional key-string parameter, but %s was found", + "an additional key-string parameter, but %s was found", sieve_ast_argument_tag(tag), sieve_ast_argument_name(*arg)); return FALSE; } - if ( !sieve_validator_argument_activate(valdtr, cmd, *arg, FALSE) ) + if ( !sieve_validator_argument_activate(valdtr, cmd, *arg, FALSE) ) return FALSE; tag->argument->def = &match_type_tag; @@ -199,9 +199,9 @@ static bool cmd_denotify_validate struct cmd_denotify_context_data *ctx_data = (struct cmd_denotify_context_data *) cmd->data; struct sieve_ast_argument *key_arg = ctx_data->match_key_arg; - const struct sieve_match_type mcht_default = + const struct sieve_match_type mcht_default = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); - const struct sieve_comparator cmp_default = + const struct sieve_comparator cmp_default = SIEVE_COMPARATOR_DEFAULT(i_octet_comparator); if ( key_arg != NULL ) { @@ -226,18 +226,18 @@ static bool cmd_denotify_generate return sieve_generate_arguments(cgenv, cmd, NULL); } -/* +/* * Code dump */ - + static bool cmd_denotify_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) -{ +{ const struct sieve_operation *op = denv->oprtn; int opt_code = 0; - + sieve_code_dumpf(denv, "%s", sieve_operation_mnemonic(op)); - sieve_code_descend(denv); + sieve_code_descend(denv); for (;;) { int opt; @@ -264,21 +264,21 @@ static bool cmd_denotify_operation_dump if ( !opok ) return FALSE; } - + return TRUE; } -/* +/* * Code execution */ static int cmd_denotify_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) -{ +{ int opt_code = 0; - struct sieve_match_type mcht = + struct sieve_match_type mcht = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); - const struct sieve_comparator cmp = + const struct sieve_comparator cmp = SIEVE_COMPARATOR_DEFAULT(i_octet_comparator); struct sieve_stringlist *match_key = NULL; sieve_number_t importance = 0; @@ -290,8 +290,8 @@ static int cmd_denotify_operation_execute /* * Read operands */ - - /* Optional operands */ + + /* Optional operands */ for (;;) { int opt; @@ -318,14 +318,14 @@ static int cmd_denotify_operation_execute if ( ret <= 0 ) return ret; } - + /* * Perform operation */ /* Enforce 0 < importance < 4 (just to be sure) */ - if ( importance < 1 ) + if ( importance < 1 ) importance = 1; else if ( importance > 3 ) importance = 3; @@ -335,35 +335,35 @@ static int cmd_denotify_operation_execute sieve_runtime_trace(renv, SIEVE_TRLVL_ACTIONS, "denotify action"); /* Either do string matching or just kill all notify actions */ - if ( match_key != NULL ) { + if ( match_key != NULL ) { /* Initialize match */ mctx = sieve_match_begin(renv, &mcht, &cmp); /* Iterate through all notify actions and delete those that match */ rictx = sieve_result_iterate_init(renv->result); - + while ( (action=sieve_result_iterate_next(rictx, NULL)) != NULL ) { - if ( sieve_action_is(action, act_notify_old) ) { + if ( sieve_action_is(action, act_notify_old) ) { struct ext_notify_action *nact = (struct ext_notify_action *) action->context; - + if ( importance == 0 || nact->importance == importance ) { - int match; + int match; if ( (match=sieve_match_value (mctx, nact->id, strlen(nact->id), match_key)) < 0 ) break; - + if ( match > 0 ) sieve_result_iterate_delete(rictx); } } } - + /* Finish match */ if ( sieve_match_end(&mctx, &ret) < 0 ) return ret; - + } else { /* Delete all notify actions */ rictx = sieve_result_iterate_init(renv->result); @@ -377,7 +377,7 @@ static int cmd_denotify_operation_execute if ( importance == 0 || nact->importance == importance ) sieve_result_iterate_delete(rictx); } - } + } } return SIEVE_EXEC_OK; diff --git a/src/lib-sieve/plugins/notify/cmd-notify.c b/src/lib-sieve/plugins/notify/cmd-notify.c index e546f7d28653fe749cbdc760fe13b1d389d073fb..ea4ef9b2ba922f5175f66c99054214cf5e8ff162 100644 --- a/src/lib-sieve/plugins/notify/cmd-notify.c +++ b/src/lib-sieve/plugins/notify/cmd-notify.c @@ -47,7 +47,7 @@ static bool cmd_notify_pre_validate static bool cmd_notify_validate (struct sieve_validator *valdtr, struct sieve_command *cmd); static bool cmd_notify_generate - (const struct sieve_codegen_env *cgenv, + (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx); const struct sieve_command_def cmd_notify_old = { @@ -58,7 +58,7 @@ const struct sieve_command_def cmd_notify_old = { cmd_notify_pre_validate, cmd_notify_validate, NULL, - cmd_notify_generate, + cmd_notify_generate, NULL, }; @@ -72,7 +72,7 @@ static bool cmd_notify_validate_string_tag (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); static bool cmd_notify_validate_stringlist_tag - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); /* Argument objects */ @@ -84,11 +84,11 @@ static const struct sieve_argument_def notify_method_tag = { NULL, NULL, NULL }; -static const struct sieve_argument_def notify_options_tag = { - "options", - NULL, - cmd_notify_validate_stringlist_tag, - NULL, NULL, NULL +static const struct sieve_argument_def notify_options_tag = { + "options", + NULL, + cmd_notify_validate_stringlist_tag, + NULL, NULL, NULL }; static const struct sieve_argument_def notify_id_tag = { @@ -105,8 +105,8 @@ static const struct sieve_argument_def notify_message_tag = { NULL, NULL, NULL }; -/* - * Notify operation +/* + * Notify operation */ static bool cmd_notify_operation_dump @@ -114,11 +114,11 @@ static bool cmd_notify_operation_dump static int cmd_notify_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def notify_old_operation = { +const struct sieve_operation_def notify_old_operation = { "NOTIFY", ¬ify_extension, EXT_NOTIFY_OPERATION_NOTIFY, - cmd_notify_operation_dump, + cmd_notify_operation_dump, cmd_notify_operation_execute }; @@ -132,21 +132,21 @@ enum cmd_notify_optional { OPT_ID }; -/* - * Notify action +/* + * Notify action */ /* Forward declarations */ static int act_notify_check_duplicate - (const struct sieve_runtime_env *renv, + (const struct sieve_runtime_env *renv, const struct sieve_action *act, const struct sieve_action *act_other); static void act_notify_print (const struct sieve_action *action, const struct sieve_result_print_env *rpenv, - bool *keep); + bool *keep); static bool act_notify_commit - (const struct sieve_action *action, const struct sieve_action_exec_env *aenv, + (const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void *tr_context, bool *keep); /* Action object */ @@ -155,7 +155,7 @@ const struct sieve_action_def act_notify_old = { "notify", 0, NULL, - act_notify_check_duplicate, + act_notify_check_duplicate, NULL, act_notify_print, NULL, NULL, @@ -200,7 +200,7 @@ static bool cmd_notify_validate_string_tag if ( sieve_argument_is(tag, notify_method_tag) ) { ctx_data->method = *arg; - + /* Removed */ *arg = sieve_ast_arguments_detach(*arg, 1); @@ -221,26 +221,26 @@ static bool cmd_notify_validate_string_tag } static bool cmd_notify_validate_stringlist_tag -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd) { struct sieve_ast_argument *tag = *arg; - struct cmd_notify_context_data *ctx_data = - (struct cmd_notify_context_data *) cmd->data; + struct cmd_notify_context_data *ctx_data = + (struct cmd_notify_context_data *) cmd->data; /* Detach the tag itself */ *arg = sieve_ast_arguments_detach(*arg,1); - + /* Check syntax: * :options string-list */ if ( !sieve_validate_tag_parameter - (valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING_LIST, FALSE) ) + (valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING_LIST, FALSE) ) return FALSE; - + /* Assign context */ - ctx_data->options = *arg; - + ctx_data->options = *arg; + /* Skip parameter */ *arg = sieve_ast_argument_next(*arg); @@ -278,7 +278,7 @@ static bool cmd_notify_pre_validate struct sieve_command *cmd) { struct cmd_notify_context_data *ctx_data; - + /* Create context */ ctx_data = p_new(sieve_command_pool(cmd), struct cmd_notify_context_data, 1); cmd->data = ctx_data; @@ -322,7 +322,7 @@ static bool cmd_notify_validate /* Check :method argument */ if ( ctx_data->method != NULL ) { const char *method = sieve_ast_argument_strc(ctx_data->method); - + if ( strcasecmp(method, "mailto") != 0 ) { sieve_command_validate_error(valdtr, cmd, "the notify command of the deprecated notify extension " @@ -334,7 +334,7 @@ static bool cmd_notify_validate /* Check :options argument */ if ( ctx_data->options != NULL ) { struct sieve_ast_argument *option = ctx_data->options; - + /* Parse and check options */ if ( sieve_ast_stringlist_map (&option, (void *) valdtr, cmd_notify_address_validate) <= 0 ) { @@ -361,17 +361,17 @@ static bool cmd_notify_generate return sieve_generate_arguments(cgenv, cmd, NULL); } -/* +/* * Code dump */ - + static bool cmd_notify_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) -{ +{ int opt_code = 0; - + sieve_code_dumpf(denv, "NOTIFY"); - sieve_code_descend(denv); + sieve_code_descend(denv); /* Dump optional operands */ for (;;) { @@ -402,32 +402,32 @@ static bool cmd_notify_operation_dump if ( !opok ) return FALSE; } - + return TRUE; } -/* +/* * Code execution */ - + static int cmd_notify_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) -{ +{ const struct sieve_extension *this_ext = renv->oprtn->ext; struct ext_notify_action *act; pool_t pool; int opt_code = 0; sieve_number_t importance = 1; struct sieve_stringlist *options = NULL; - string_t *message = NULL, *id = NULL; + string_t *message = NULL, *id = NULL; int ret = 0; /* * Read operands */ - /* Optional operands */ + /* Optional operands */ for (;;) { int opt; @@ -457,21 +457,21 @@ static int cmd_notify_operation_execute if ( ret <= 0 ) return ret; } - + /* * Perform operation */ /* Enforce 0 < importance < 4 (just to be sure) */ - if ( importance < 1 ) + if ( importance < 1 ) importance = 1; else if ( importance > 3 ) importance = 3; /* Trace */ - sieve_runtime_trace(renv, SIEVE_TRLVL_ACTIONS, "notify action"); + sieve_runtime_trace(renv, SIEVE_TRLVL_ACTIONS, "notify action"); /* Compose action */ if ( options != NULL ) { @@ -482,26 +482,26 @@ static int cmd_notify_operation_execute act = p_new(pool, struct ext_notify_action, 1); if ( id != NULL ) act->id = p_strdup(pool, str_c(id)); - act->importance = importance; - + act->importance = importance; + /* Process message */ out_message = t_str_new(1024); ext_notify_construct_message (renv, (message == NULL ? NULL : str_c(message)), out_message); act->message = p_strdup(pool, str_c(out_message)); - - /* Normalize and verify all :options addresses */ + + /* Normalize and verify all :options addresses */ sieve_stringlist_reset(options); - + p_array_init(&act->recipients, pool, 4); - + raw_address = NULL; while ( (ret=sieve_stringlist_next_item(options, &raw_address)) > 0 ) { const char *error = NULL; const char *addr_norm = sieve_address_normalize(raw_address, &error); - + /* Add if valid address */ if ( addr_norm != NULL ) { const struct ext_notify_recipient *rcpts; @@ -509,21 +509,21 @@ static int cmd_notify_operation_execute /* Prevent duplicates */ rcpts = array_get(&act->recipients, &rcpt_count); - + for ( i = 0; i < rcpt_count; i++ ) { if ( sieve_address_compare (rcpts[i].normalized, addr_norm, TRUE) == 0 ) break; } - + /* Add only if unique */ if ( i != rcpt_count ) { sieve_runtime_warning(renv, NULL, "duplicate recipient '%s' specified in the :options argument of " - "the deprecated notify command", + "the deprecated notify command", str_sanitize(str_c(raw_address), 128)); - } else if + } else if ( array_count(&act->recipients) >= EXT_NOTIFY_MAX_RECIPIENTS ) { sieve_runtime_warning(renv, NULL, "more than the maximum %u recipients are specified " @@ -531,18 +531,18 @@ static int cmd_notify_operation_execute "the rest is discarded", EXT_NOTIFY_MAX_RECIPIENTS); break; - } else { - struct ext_notify_recipient recipient; + } else { + struct ext_notify_recipient recipient; recipient.full = p_strdup(pool, str_c(raw_address)); recipient.normalized = p_strdup(pool, addr_norm); - + array_append(&act->recipients, &recipient, 1); } } else { sieve_runtime_error(renv, NULL, "specified :options address '%s' is invalid for " - "the deprecated notify command: %s", + "the deprecated notify command: %s", str_sanitize(str_c(raw_address), 128), error); return SIEVE_EXEC_FAILURE; } @@ -568,7 +568,7 @@ static int cmd_notify_operation_execute /* Runtime verification */ static int act_notify_check_duplicate -(const struct sieve_runtime_env *renv ATTR_UNUSED, +(const struct sieve_runtime_env *renv ATTR_UNUSED, const struct sieve_action *act ATTR_UNUSED, const struct sieve_action *act_other ATTR_UNUSED) { @@ -577,7 +577,7 @@ static int act_notify_check_duplicate const struct ext_notify_recipient *old_rcpts; unsigned int new_count, old_count, i, j; unsigned int del_start = 0, del_len = 0; - + if ( act->context == NULL || act_other->context == NULL ) return 0; @@ -591,7 +591,7 @@ static int act_notify_check_duplicate for ( j = 0; j < old_count; j++ ) { if ( sieve_address_compare (new_rcpts[i].normalized, old_rcpts[j].normalized, TRUE) == 0 ) - break; + break; } if ( j == old_count ) { @@ -605,7 +605,7 @@ static int act_notify_check_duplicate new_rcpts = array_get(&new_nact->recipients, &new_count); } - del_len = 0; + del_len = 0; } else { /* Mark deletion */ if ( del_len == 0 ) @@ -616,26 +616,26 @@ static int act_notify_check_duplicate /* Perform pending deletion */ if ( del_len > 0 ) { - array_delete(&new_nact->recipients, del_start, del_len); + array_delete(&new_nact->recipients, del_start, del_len); } return ( array_count(&new_nact->recipients) > 0 ? 0 : 1 ); } /* Result printing */ - + static void act_notify_print -(const struct sieve_action *action, const struct sieve_result_print_env *rpenv, - bool *keep ATTR_UNUSED) +(const struct sieve_action *action, const struct sieve_result_print_env *rpenv, + bool *keep ATTR_UNUSED) { - const struct ext_notify_action *act = + const struct ext_notify_action *act = (const struct ext_notify_action *) action->context; const struct ext_notify_recipient *recipients; unsigned int count, i; sieve_result_action_printf ( rpenv, "send (depricated) notification with method 'mailto':"); - + /* Print main method parameters */ sieve_result_printf @@ -683,9 +683,9 @@ static bool contains_8bit(const char *msg) } static bool act_notify_send -(const struct sieve_action_exec_env *aenv, +(const struct sieve_action_exec_env *aenv, const struct ext_notify_action *act) -{ +{ const struct sieve_script_env *senv = aenv->scriptenv; const struct ext_notify_recipient *recipients; void *smtp_handle; @@ -696,30 +696,30 @@ static bool act_notify_send /* Get recipients */ recipients = array_get(&act->recipients, &count); if ( count == 0 ) { - sieve_result_warning(aenv, + sieve_result_warning(aenv, "notify action specifies no recipients; action has no effect"); return TRUE; } /* Just to be sure */ if ( senv->smtp_open == NULL || senv->smtp_close == NULL ) { - sieve_result_global_warning(aenv, + sieve_result_global_warning(aenv, "notify action has no means to send mail"); return TRUE; } - + /* Send message to all recipients */ for ( i = 0; i < count; i++ ) { if ( sieve_message_get_sender(aenv->msgctx) != NULL ) smtp_handle = sieve_smtp_open (senv, recipients[i].normalized, senv->postmaster_address, &f); - else + else smtp_handle = sieve_smtp_open (senv, recipients[i].normalized, NULL, &f); outmsgid = sieve_message_get_new_id(aenv->svinst); - + rfc2822_header_field_write(f, "X-Sieve", SIEVE_IMPLEMENTATION); rfc2822_header_field_write(f, "Message-ID", outmsgid); rfc2822_header_field_write(f, "Date", message_date_create(ioloop_time)); @@ -741,7 +741,7 @@ static bool act_notify_send break; } - rfc2822_header_field_printf(f, "From", "%s", + rfc2822_header_field_printf(f, "From", "%s", t_strdup_printf("Postmaster <%s>", senv->postmaster_address)); rfc2822_header_field_printf(f, "To", "%s", recipients[i].full); @@ -753,7 +753,7 @@ static bool act_notify_send if (contains_8bit(act->message)) { rfc2822_header_field_write(f, "MIME-Version", "1.0"); - rfc2822_header_field_write(f, + rfc2822_header_field_write(f, "Content-Type", "text/plain; charset=UTF-8"); rfc2822_header_field_write(f, "Content-Transfer-Encoding", "8bit"); } @@ -761,15 +761,15 @@ static bool act_notify_send /* Generate message body */ fprintf(f, "\r\n"); fprintf(f, "%s\r\n", act->message); - + if ( sieve_smtp_close(senv, smtp_handle) ) { - sieve_result_global_log(aenv, - "sent mail notification to <%s>", + sieve_result_global_log(aenv, + "sent mail notification to <%s>", str_sanitize(recipients[i].normalized, 80)); } else { sieve_result_global_error(aenv, "failed to send mail notification to <%s> " - "(refer to system log for more information)", + "(refer to system log for more information)", str_sanitize(recipients[i].normalized, 80)); } } @@ -778,10 +778,10 @@ static bool act_notify_send } static bool act_notify_commit -(const struct sieve_action *action, const struct sieve_action_exec_env *aenv, +(const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void *tr_context ATTR_UNUSED, bool *keep ATTR_UNUSED) { - const struct ext_notify_action *act = + const struct ext_notify_action *act = (const struct ext_notify_action *) action->context; const struct sieve_message_data *msgdata = aenv->msgdata; const char *const *headers; @@ -794,10 +794,10 @@ static bool act_notify_commit /* Theoretically multiple headers could exist, so lets make sure */ while ( *hdsp != NULL ) { if ( strcasecmp(*hdsp, "no") != 0 ) { - sieve_result_global_log(aenv, - "not sending notification for auto-submitted message from <%s>", - str_sanitize(msgdata->return_path, 128)); - return TRUE; + sieve_result_global_log(aenv, + "not sending notification for auto-submitted message from <%s>", + str_sanitize(msgdata->return_path, 128)); + return TRUE; } hdsp++; } diff --git a/src/lib-sieve/plugins/notify/ext-notify-common.c b/src/lib-sieve/plugins/notify/ext-notify-common.c index e7b6f9265761bb916c5d5a9f98f985673300919c..f2b6783ec909af1f328128d7c3c7a5691da24ea1 100644 --- a/src/lib-sieve/plugins/notify/ext-notify-common.c +++ b/src/lib-sieve/plugins/notify/ext-notify-common.c @@ -41,7 +41,7 @@ static const struct sieve_argument_def importance_low_tag = { static const struct sieve_argument_def importance_normal_tag = { "normal", - NULL, + NULL, tag_importance_validate, NULL, NULL, NULL }; @@ -76,7 +76,7 @@ static bool tag_importance_validate } void ext_notify_register_importance_tags -(struct sieve_validator *valdtr, struct sieve_command_registration *cmd_reg, +(struct sieve_validator *valdtr, struct sieve_command_registration *cmd_reg, const struct sieve_extension *ext, unsigned int id_code) { sieve_validator_register_tag(valdtr, cmd_reg, ext, &importance_low_tag, id_code); @@ -99,15 +99,15 @@ static struct ext_notify_message_context *ext_notify_get_message_context (const struct sieve_extension *this_ext, struct sieve_message_context *msgctx) { struct ext_notify_message_context *ctx; - + /* Get message context (contains cached message body information) */ ctx = (struct ext_notify_message_context *) sieve_message_context_extension_get(msgctx, this_ext); - + /* Create it if it does not exist already */ if ( ctx == NULL ) { pool_t pool = sieve_message_context_pool(msgctx); - ctx = p_new(pool, struct ext_notify_message_context, 1); + ctx = p_new(pool, struct ext_notify_message_context, 1); ctx->pool = pool; ctx->body_text = NULL; @@ -115,7 +115,7 @@ static struct ext_notify_message_context *ext_notify_get_message_context sieve_message_context_extension_set (msgctx, this_ext, (void *) ctx); } - + return ctx; } @@ -150,7 +150,7 @@ static bool _is_text_content(const struct message_header_line *hdr) static buffer_t *cmd_notify_extract_body_text (const struct sieve_runtime_env *renv) -{ +{ const struct sieve_extension *this_ext = renv->oprtn->ext; struct ext_notify_message_context *mctx; struct message_parser_ctx *parser; @@ -160,11 +160,11 @@ static buffer_t *cmd_notify_extract_body_text struct istream *input; bool is_text, save_body; int ret = 1; - + /* Return cached result if available */ mctx = ext_notify_get_message_context(this_ext, renv->msgctx); if ( mctx->body_text != NULL ) { - return mctx->body_text; + return mctx->body_text; } /* Create buffer */ @@ -173,10 +173,10 @@ static buffer_t *cmd_notify_extract_body_text /* Get the message stream */ if ( mail_get_stream(renv->msgdata->mail, NULL, NULL, &input) < 0 ) return NULL; - + /* Initialize body decoder */ decoder = message_decoder_init(FALSE); - + parser = message_parser_init(mctx->pool, input, 0, 0); is_text = TRUE; save_body = FALSE; @@ -190,19 +190,19 @@ static buffer_t *cmd_notify_extract_body_text save_body = is_text; continue; } - + /* We're interested of only Content-Type: header */ if ( strcasecmp(block.hdr->name, "Content-Type" ) != 0) continue; - /* Header can have folding whitespace. Acquire the full value before + /* Header can have folding whitespace. Acquire the full value before * continuing */ if ( block.hdr->continues ) { block.hdr->use_full_value = TRUE; continue; } - + /* Is it a text part? */ T_BEGIN { is_text = _is_text_content(block.hdr); @@ -215,14 +215,14 @@ static buffer_t *cmd_notify_extract_body_text if ( save_body ) { (void)message_decoder_decode_next_block(decoder, &block, &decoded); buffer_append(mctx->body_text, decoded.data, decoded.size); - is_text = TRUE; + is_text = TRUE; } } /* Cleanup */ (void)message_parser_deinit(&parser, &parts); message_decoder_deinit(&decoder); - + if ( ret < 0 && input->stream_errno != 0 ) return NULL; @@ -231,7 +231,7 @@ static buffer_t *cmd_notify_extract_body_text } void ext_notify_construct_message -(const struct sieve_runtime_env *renv, const char *msg_format, +(const struct sieve_runtime_env *renv, const char *msg_format, string_t *out_msg) { const struct sieve_message_data *msgdata = renv->msgdata; @@ -239,7 +239,7 @@ void ext_notify_construct_message if ( msg_format == NULL ) msg_format = "$from$: $subject$"; - + /* Scan message for substitutions */ p = msg_format; while ( *p != '\0' ) { @@ -247,25 +247,25 @@ void ext_notify_construct_message if ( strncasecmp(p, "$from$", 6) == 0 ) { p += 6; - + /* Fetch sender from oriinal message */ if ( mail_get_headers_utf8(msgdata->mail, "from", &header) >= 0 ) - str_append(out_msg, header[0]); + str_append(out_msg, header[0]); } else if ( strncasecmp(p, "$env-from$", 10) == 0 ) { p += 10; - if ( msgdata->return_path != NULL ) + if ( msgdata->return_path != NULL ) str_append(out_msg, msgdata->return_path); - } else if ( strncasecmp(p, "$subject$", 9) == 0 ) { + } else if ( strncasecmp(p, "$subject$", 9) == 0 ) { p += 9; /* Fetch sender from oriinal message */ if ( mail_get_headers_utf8(msgdata->mail, "subject", &header) >= 0 ) - str_append(out_msg, header[0]); - - } else if ( strncasecmp(p, "$text", 5) == 0 + str_append(out_msg, header[0]); + + } else if ( strncasecmp(p, "$text", 5) == 0 && (p[5] == '[' || p[5] == '$') ) { size_t num = 0; const char *begin = p; @@ -282,10 +282,10 @@ void ext_notify_construct_message if ( *p++ != ']' || *p++ != '$' ) { str_append_n(out_msg, begin, p-begin); - valid = FALSE; - } + valid = FALSE; + } } else { - p += 1; + p += 1; } if ( valid ) { @@ -293,16 +293,16 @@ void ext_notify_construct_message const char *body_text = (const char *) buffer_get_data(cmd_notify_extract_body_text(renv), &body_size); - if ( num > 0 && num < body_size) + if ( num > 0 && num < body_size) str_append_n(out_msg, body_text, num); - else + else str_append_n(out_msg, body_text, body_size); } } else { size_t len; /* Find next substitution */ - len = strcspn(p + 1, "$") + 1; + len = strcspn(p + 1, "$") + 1; /* Copy normal text */ str_append_n(out_msg, p, len); diff --git a/src/lib-sieve/plugins/notify/ext-notify-common.h b/src/lib-sieve/plugins/notify/ext-notify-common.h index c7e1560c4f0dad61c8fdb53b95ab3476cef4b739..027f39e963eb366ced43c76baeec4441874d9a71 100644 --- a/src/lib-sieve/plugins/notify/ext-notify-common.h +++ b/src/lib-sieve/plugins/notify/ext-notify-common.h @@ -37,8 +37,8 @@ enum ext_notify_opcode { EXT_NOTIFY_OPERATION_DENOTIFY, }; -/* - * Actions +/* + * Actions */ extern const struct sieve_action_def act_notify_old; @@ -49,7 +49,7 @@ struct ext_notify_recipient { }; ARRAY_DEFINE_TYPE(recipients, struct ext_notify_recipient); - + struct ext_notify_action { const char *id; const char *message; @@ -63,7 +63,7 @@ struct ext_notify_action { */ void ext_notify_construct_message - (const struct sieve_runtime_env *renv, const char *msg_format, + (const struct sieve_runtime_env *renv, const char *msg_format, string_t *out_msg); #endif /* __EXT_NOTIFY_COMMON_H */ diff --git a/src/lib-sieve/plugins/notify/ext-notify-limits.h b/src/lib-sieve/plugins/notify/ext-notify-limits.h index 1923546ee0f64cbb8afffdc83672e391de696d67..ef92ba72ad27d6987c16d47c3def6ef320442d02 100644 --- a/src/lib-sieve/plugins/notify/ext-notify-limits.h +++ b/src/lib-sieve/plugins/notify/ext-notify-limits.h @@ -1,6 +1,6 @@ /* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #ifndef __EXT_NOTIFY_LIMITS_H #define __EXT_NOTIFY_LIMITS_H diff --git a/src/lib-sieve/plugins/notify/ext-notify.c b/src/lib-sieve/plugins/notify/ext-notify.c index 836c615ae8435b281726b7a0c877fdce20ceabf7..787252bdbd76afba99b27b82e2d0bdd218651142 100644 --- a/src/lib-sieve/plugins/notify/ext-notify.c +++ b/src/lib-sieve/plugins/notify/ext-notify.c @@ -33,18 +33,18 @@ const struct sieve_operation_def *ext_notify_operations[] = { &denotify_operation }; -/* +/* * Extension */ static bool ext_notify_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr); -const struct sieve_extension_def notify_extension = { - "notify", +const struct sieve_extension_def notify_extension = { + "notify", NULL, NULL, - ext_notify_validator_load, + ext_notify_validator_load, NULL, NULL, NULL, NULL, NULL, SIEVE_EXT_DEFINE_OPERATIONS(ext_notify_operations), SIEVE_EXT_DEFINE_NO_OPERANDS, @@ -55,7 +55,7 @@ const struct sieve_extension_def notify_extension = { */ static bool ext_notify_validator_extension_validate - (const struct sieve_extension *ext, struct sieve_validator *valdtr, + (const struct sieve_extension *ext, struct sieve_validator *valdtr, void *context, struct sieve_ast_argument *require_arg); const struct sieve_validator_extension notify_validator_extension = { @@ -74,12 +74,12 @@ static bool ext_notify_validator_load /* Register new commands */ sieve_validator_register_command(valdtr, ext, &cmd_notify_old); sieve_validator_register_command(valdtr, ext, &cmd_denotify); - + return TRUE; } static bool ext_notify_validator_extension_validate -(const struct sieve_extension *ext, struct sieve_validator *valdtr, +(const struct sieve_extension *ext, struct sieve_validator *valdtr, void *context ATTR_UNUSED, struct sieve_ast_argument *require_arg) { const struct sieve_extension *ext_entfy; diff --git a/src/lib-sieve/plugins/regex/ext-regex-common.c b/src/lib-sieve/plugins/regex/ext-regex-common.c index c3eb8fb2c295cbece3a813221295b227ccd9d2a3..4525b1212e2eed0af592c343c2e93bbf52898b7c 100644 --- a/src/lib-sieve/plugins/regex/ext-regex-common.c +++ b/src/lib-sieve/plugins/regex/ext-regex-common.c @@ -6,7 +6,7 @@ #include "ext-regex-common.h" -/* +/* * Regex match type operand */ diff --git a/src/lib-sieve/plugins/regex/ext-regex.c b/src/lib-sieve/plugins/regex/ext-regex.c index a60d2ed731c6be85c5a7edc08e006adeb193d146..d6c1777678b9609c19fa6ead2a77822f437d15d9 100644 --- a/src/lib-sieve/plugins/regex/ext-regex.c +++ b/src/lib-sieve/plugins/regex/ext-regex.c @@ -41,26 +41,26 @@ #include <sys/types.h> #include <regex.h> -/* +/* * Extension */ static bool ext_regex_validator_load (const struct sieve_extension *ext, struct sieve_validator *validator); -const struct sieve_extension_def regex_extension = { - "regex", +const struct sieve_extension_def regex_extension = { + "regex", NULL, NULL, ext_regex_validator_load, NULL, NULL, NULL, NULL, NULL, - SIEVE_EXT_DEFINE_NO_OPERATIONS, + SIEVE_EXT_DEFINE_NO_OPERATIONS, SIEVE_EXT_DEFINE_OPERAND(regex_match_type_operand) }; static bool ext_regex_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr) { - sieve_match_type_register(valdtr, ext, ®ex_match_type); + sieve_match_type_register(valdtr, ext, ®ex_match_type); return TRUE; } diff --git a/src/lib-sieve/plugins/regex/mcht-regex.c b/src/lib-sieve/plugins/regex/mcht-regex.c index 29a40725d9416fe7a2ffaa4d5ce838f9804fc97e..3220608125e67e6378d34ae736b2c9fecae79caa 100644 --- a/src/lib-sieve/plugins/regex/mcht-regex.c +++ b/src/lib-sieve/plugins/regex/mcht-regex.c @@ -34,10 +34,10 @@ #define MCHT_REGEX_MAX_SUBSTITUTIONS SIEVE_MAX_MATCH_VALUES -/* +/* * Match type */ - + static bool mcht_regex_validate_context (struct sieve_validator *valdtr, struct sieve_ast_argument *arg, struct sieve_match_type_context *ctx, struct sieve_ast_argument *key_arg); @@ -55,28 +55,28 @@ const struct sieve_match_type_def regex_match_type = { NULL, mcht_regex_match_init, mcht_regex_match_keys, - NULL, + NULL, mcht_regex_match_deinit }; -/* - * Match type validation +/* + * Match type validation */ /* Wrapper around the regerror function for easy access */ static const char *_regexp_error(regex_t *regexp, int errorcode) { - size_t errsize = regerror(errorcode, regexp, NULL, 0); + size_t errsize = regerror(errorcode, regexp, NULL, 0); if ( errsize > 0 ) { char *errbuf; - buffer_t *error_buf = + buffer_t *error_buf = buffer_create_dynamic(pool_datastack_create(), errsize); errbuf = buffer_get_space_unsafe(error_buf, 0, errsize); errsize = regerror(errorcode, regexp, errbuf, errsize); - + /* We don't want the error to start with a capital letter */ errbuf[0] = i_tolower(errbuf[0]); @@ -89,9 +89,9 @@ static const char *_regexp_error(regex_t *regexp, int errorcode) } static int mcht_regex_validate_regexp -(struct sieve_validator *valdtr, +(struct sieve_validator *valdtr, struct sieve_match_type_context *mtctx ATTR_UNUSED, - struct sieve_ast_argument *key, int cflags) + struct sieve_ast_argument *key, int cflags) { int ret; regex_t regexp; @@ -99,10 +99,10 @@ static int mcht_regex_validate_regexp if ( (ret=regcomp(®exp, regex_str, cflags)) != 0 ) { sieve_argument_validate_error(valdtr, key, - "invalid regular expression '%s' for regex match: %s", + "invalid regular expression '%s' for regex match: %s", str_sanitize(regex_str, 128), _regexp_error(®exp, ret)); - regfree(®exp); + regfree(®exp); return FALSE; } @@ -131,7 +131,7 @@ static int mcht_regex_validate_key_argument return TRUE; } - + static bool mcht_regex_validate_context (struct sieve_validator *valdtr, struct sieve_ast_argument *arg ATTR_UNUSED, struct sieve_match_type_context *mtctx, struct sieve_ast_argument *key_arg) @@ -141,16 +141,16 @@ static bool mcht_regex_validate_context struct _regex_key_context keyctx; struct sieve_ast_argument *kitem; - if ( cmp != NULL ) { + if ( cmp != NULL ) { if ( sieve_comparator_is(cmp, i_ascii_casemap_comparator) ) cflags = REG_EXTENDED | REG_NOSUB | REG_ICASE; else if ( sieve_comparator_is(cmp, i_octet_comparator) ) cflags = REG_EXTENDED | REG_NOSUB; else { - sieve_argument_validate_error(valdtr, mtctx->argument, + sieve_argument_validate_error(valdtr, mtctx->argument, "regex match type only supports " "i;octet and i;ascii-casemap comparators" ); - return FALSE; + return FALSE; } } @@ -168,8 +168,8 @@ static bool mcht_regex_validate_context return TRUE; } -/* - * Match type implementation +/* + * Match type implementation */ struct mcht_regex_key { @@ -190,7 +190,7 @@ static void mcht_regex_match_init pool_t pool = mctx->pool; struct mcht_regex_context *ctx; - /* Create context */ + /* Create context */ ctx = p_new(pool, struct mcht_regex_context, 1); /* Create storage for match values if match values are requested */ @@ -201,7 +201,7 @@ static void mcht_regex_match_init ctx->pmatch = NULL; ctx->nmatch = 0; } - + /* Assign context */ mctx->data = (void *) ctx; } @@ -234,17 +234,17 @@ static int mcht_regex_match_key /* Add match values from regular expression */ for ( i = 0; i < ctx->nmatch; i++ ) { str_truncate(subst, 0); - + if ( ctx->pmatch[i].rm_so != -1 ) { if ( skipped > 0 ) { sieve_match_values_skip(mvalues, skipped); skipped = 0; } - - str_append_n(subst, val + ctx->pmatch[i].rm_so, + + str_append_n(subst, val + ctx->pmatch[i].rm_so, ctx->pmatch[i].rm_eo - ctx->pmatch[i].rm_so); sieve_match_values_add(mvalues, subst); - } else + } else skipped++; } @@ -259,7 +259,7 @@ static int mcht_regex_match_key } static int mcht_regex_match_keys -(struct sieve_match_context *mctx, const char *val, size_t val_size ATTR_UNUSED, +(struct sieve_match_context *mctx, const char *val, size_t val_size ATTR_UNUSED, struct sieve_stringlist *key_list) { const struct sieve_runtime_env *renv = mctx->runenv; @@ -281,7 +281,7 @@ static int mcht_regex_match_keys i = 0; match = 0; while ( match == 0 && - (ret=sieve_stringlist_next_item(key_list, &key_item)) > 0 ) { + (ret=sieve_stringlist_next_item(key_list, &key_item)) > 0 ) { T_BEGIN { struct mcht_regex_key *rkey; @@ -292,13 +292,13 @@ static int mcht_regex_match_keys rkey = array_append_space(&ctx->reg_expressions); /* Configure case-sensitivity according to comparator */ - if ( sieve_comparator_is(cmp, i_octet_comparator) ) + if ( sieve_comparator_is(cmp, i_octet_comparator) ) cflags = REG_EXTENDED; else if ( sieve_comparator_is(cmp, i_ascii_casemap_comparator) ) cflags = REG_EXTENDED | REG_ICASE; else rkey->status = -1; /* Not supported */ - + if ( rkey->status >= 0 ) { const char *regex_str = str_c(key_item); int rxret; @@ -309,7 +309,7 @@ static int mcht_regex_match_keys /* Compile regular expression */ if ( (rxret=regcomp(&rkey->regexp, regex_str, cflags)) != 0 ) { sieve_runtime_error(renv, NULL, - "invalid regular expression '%s' for regex match: %s", + "invalid regular expression '%s' for regex match: %s", str_sanitize(regex_str, 128), _regexp_error(&rkey->regexp, rxret)); rkey->status = -1; @@ -319,14 +319,14 @@ static int mcht_regex_match_keys } } else { rkey = array_idx_modifiable(&ctx->reg_expressions, 1); - } + } if ( rkey->status > 0 ) { match = mcht_regex_match_key(mctx, val, &rkey->regexp); if ( trace ) { sieve_runtime_trace(renv, 0, - "with regex `%s' [id=%d] => %d", + "with regex `%s' [id=%d] => %d", str_sanitize(str_c(key_item), 80), array_count(&ctx->reg_expressions)-1, match); } diff --git a/src/lib-sieve/plugins/relational/Makefile.am b/src/lib-sieve/plugins/relational/Makefile.am index 69f8d5a94d850efe61ac268de09b9f4d8047e6f2..dd28cc537c5623b6abfe9a1a452533b0483188a2 100644 --- a/src/lib-sieve/plugins/relational/Makefile.am +++ b/src/lib-sieve/plugins/relational/Makefile.am @@ -8,7 +8,7 @@ libsieve_ext_relational_la_SOURCES = \ ext-relational-common.c \ mcht-value.c \ mcht-count.c \ - ext-relational.c + ext-relational.c noinst_HEADERS = \ ext-relational-common.h diff --git a/src/lib-sieve/plugins/relational/ext-relational-common.c b/src/lib-sieve/plugins/relational/ext-relational-common.c index be4bca7243db91a61e0e55f7e895995e113e3394..50fb9b7daa2b93bd07fc850cd22af028ce26701c 100644 --- a/src/lib-sieve/plugins/relational/ext-relational-common.c +++ b/src/lib-sieve/plugins/relational/ext-relational-common.c @@ -7,7 +7,7 @@ * VALUE = ":value" relational-match * relational-match = DQUOTE ( "gt" / "ge" / "lt" * / "le" / "eq" / "ne" ) DQUOTE - */ + */ #include "lib.h" #include "str.h" @@ -32,37 +32,37 @@ const struct sieve_match_type_def *rel_match_types[]; -/* - * Validation +/* + * Validation */ bool mcht_relational_validate -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_match_type_context *ctx) -{ +{ struct sieve_match_type *mcht; enum relational_match rel_match = REL_MATCH_INVALID; string_t *rel_match_ident; /* Check syntax: - * relational-match = DQUOTE ( "gt" / "ge" / "lt" + * relational-match = DQUOTE ( "gt" / "ge" / "lt" * / "le" / "eq" / "ne" ) DQUOTE * - * So, actually this must be a constant string and it is implemented as such + * So, actually this must be a constant string and it is implemented as such */ - - /* Did we get a string in the first place ? */ + + /* Did we get a string in the first place ? */ if ( (*arg)->type != SAAT_STRING ) { - sieve_argument_validate_error(valdtr, *arg, + sieve_argument_validate_error(valdtr, *arg, "the :%s match-type requires a constant string argument being " "one of \"gt\", \"ge\", \"lt\", \"le\", \"eq\" or \"ne\", " - "but %s was found", + "but %s was found", sieve_match_type_name(ctx->match_type), sieve_ast_argument_name(*arg)); return FALSE; } - + /* Check the relational match id */ - + rel_match_ident = sieve_ast_argument_str(*arg); if ( str_len(rel_match_ident) == 2 ) { const char *rel_match_id = str_c(rel_match_ident); @@ -71,26 +71,26 @@ bool mcht_relational_validate /* "gt" or "ge" */ case 'g': switch ( rel_match_id[1] ) { - case 't': - rel_match = REL_MATCH_GREATER; + case 't': + rel_match = REL_MATCH_GREATER; break; - case 'e': - rel_match = REL_MATCH_GREATER_EQUAL; + case 'e': + rel_match = REL_MATCH_GREATER_EQUAL; break; - default: + default: rel_match = REL_MATCH_INVALID; } break; /* "lt" or "le" */ case 'l': switch ( rel_match_id[1] ) { - case 't': - rel_match = REL_MATCH_LESS; + case 't': + rel_match = REL_MATCH_LESS; break; - case 'e': - rel_match = REL_MATCH_LESS_EQUAL; + case 'e': + rel_match = REL_MATCH_LESS_EQUAL; break; - default: + default: rel_match = REL_MATCH_INVALID; } break; @@ -98,14 +98,14 @@ bool mcht_relational_validate case 'e': if ( rel_match_id[1] == 'q' ) rel_match = REL_MATCH_EQUAL; - else - rel_match = REL_MATCH_INVALID; + else + rel_match = REL_MATCH_INVALID; break; /* "ne" */ case 'n': if ( rel_match_id[1] == 'e' ) rel_match = REL_MATCH_NOT_EQUAL; - else + else rel_match = REL_MATCH_INVALID; break; /* invalid */ @@ -113,24 +113,24 @@ bool mcht_relational_validate rel_match = REL_MATCH_INVALID; } } - + if ( rel_match >= REL_MATCH_INVALID ) { - sieve_argument_validate_error(valdtr, *arg, + sieve_argument_validate_error(valdtr, *arg, "the :%s match-type requires a constant string argument being " "one of \"gt\", \"ge\", \"lt\", \"le\", \"eq\" or \"ne\", " - "but \"%s\" was found", - sieve_match_type_name(ctx->match_type), + "but \"%s\" was found", + sieve_match_type_name(ctx->match_type), str_sanitize(str_c(rel_match_ident), 32)); return FALSE; } - + /* Delete argument */ *arg = sieve_ast_arguments_detach(*arg, 1); /* Not used just yet */ ctx->ctx_data = (void *) rel_match; - /* Override the actual match type with a parameter-specific one + /* Override the actual match type with a parameter-specific one * FIXME: ugly! */ mcht = p_new(sieve_ast_argument_pool(*arg), struct sieve_match_type, 1); diff --git a/src/lib-sieve/plugins/relational/ext-relational-common.h b/src/lib-sieve/plugins/relational/ext-relational-common.h index fe989beee19b921deacff55f724a09c80298f5bc..7335daf29a93a7e5ecb5d3174c5d15e2f43d3380 100644 --- a/src/lib-sieve/plugins/relational/ext-relational-common.h +++ b/src/lib-sieve/plugins/relational/ext-relational-common.h @@ -1,6 +1,6 @@ /* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #ifndef __EXT_RELATIONAL_COMMON_H #define __EXT_RELATIONAL_COMMON_H @@ -9,8 +9,8 @@ #include "sieve-common.h" -/* - * Types +/* + * Types */ enum ext_relational_match_type { @@ -35,8 +35,8 @@ enum relational_match { #define REL_MATCH(index) \ (index % REL_MATCH_INVALID) -/* - * Extension definitions +/* + * Extension definitions */ extern const struct sieve_extension_def relational_extension; @@ -44,8 +44,8 @@ extern const struct sieve_extension_def relational_extension; /* * Match types */ - -/* Registered for validation */ + +/* Registered for validation */ extern const struct sieve_match_type_def value_match_type; extern const struct sieve_match_type_def count_match_type; @@ -69,7 +69,7 @@ extern const struct sieve_match_type_def rel_match_value_ne; /* * Operand */ - + extern const struct sieve_operand_def rel_match_type_operand; @@ -78,13 +78,13 @@ extern const struct sieve_operand_def rel_match_type_operand; */ bool mcht_relational_validate - (struct sieve_validator *validator, struct sieve_ast_argument **arg, + (struct sieve_validator *validator, struct sieve_ast_argument **arg, struct sieve_match_type_context *ctx); - + /* * Value match function (also used by :count) */ - + int mcht_value_match_key (struct sieve_match_context *mctx, const char *val, size_t val_size, const char *key, size_t key_size); diff --git a/src/lib-sieve/plugins/relational/ext-relational.c b/src/lib-sieve/plugins/relational/ext-relational.c index acf3dd2b401a9302849136eeb722892f043758c2..c9115f1d9bcff119ffb0267c675d9bfc5490d471 100644 --- a/src/lib-sieve/plugins/relational/ext-relational.c +++ b/src/lib-sieve/plugins/relational/ext-relational.c @@ -35,20 +35,20 @@ static bool ext_relational_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr); -const struct sieve_extension_def relational_extension = { - "relational", +const struct sieve_extension_def relational_extension = { + "relational", NULL, NULL, ext_relational_validator_load, NULL, NULL, NULL, NULL, NULL, - SIEVE_EXT_DEFINE_NO_OPERATIONS, + SIEVE_EXT_DEFINE_NO_OPERATIONS, SIEVE_EXT_DEFINE_OPERAND(rel_match_type_operand) }; static bool ext_relational_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr) { - sieve_match_type_register(valdtr, ext, &value_match_type); - sieve_match_type_register(valdtr, ext, &count_match_type); + sieve_match_type_register(valdtr, ext, &value_match_type); + sieve_match_type_register(valdtr, ext, &count_match_type); return TRUE; } diff --git a/src/lib-sieve/plugins/relational/mcht-count.c b/src/lib-sieve/plugins/relational/mcht-count.c index 13120abf9f40fca1ea0fb2fa4f2b083b9ea2c4b3..114f7f6567df1b899bad95282bc5bc63510d8f45 100644 --- a/src/lib-sieve/plugins/relational/mcht-count.c +++ b/src/lib-sieve/plugins/relational/mcht-count.c @@ -1,7 +1,7 @@ /* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - -/* Match-type ':count' + +/* Match-type ':count' */ #include "lib.h" @@ -24,7 +24,7 @@ #include "ext-relational-common.h" -/* +/* * Forward declarations */ @@ -32,10 +32,10 @@ static int mcht_count_match (struct sieve_match_context *mctx, struct sieve_stringlist *value_list, struct sieve_stringlist *key_list); -/* +/* * Match-type objects */ - + const struct sieve_match_type_def count_match_type = { SIEVE_OBJECT("count", &rel_match_type_operand, RELATIONAL_COUNT), mcht_relational_validate, @@ -51,7 +51,7 @@ const struct sieve_match_type_def rel_match_count_ ## name = { \ mcht_count_match, \ NULL, NULL, NULL, NULL \ } - + COUNT_MATCH_TYPE(gt, REL_MATCH_GREATER); COUNT_MATCH_TYPE(ge, REL_MATCH_GREATER_EQUAL); COUNT_MATCH_TYPE(lt, REL_MATCH_LESS); @@ -59,8 +59,8 @@ COUNT_MATCH_TYPE(le, REL_MATCH_LESS_EQUAL); COUNT_MATCH_TYPE(eq, REL_MATCH_EQUAL); COUNT_MATCH_TYPE(ne, REL_MATCH_NOT_EQUAL); -/* - * Match-type implementation +/* + * Match-type implementation */ static int mcht_count_match @@ -93,7 +93,7 @@ static int mcht_count_match /* Match to all key values */ key_item = NULL; match = 0; - while ( match == 0 && + while ( match == 0 && (ret=sieve_stringlist_next_item(key_list, &key_item)) > 0 ) { match = mcht_value_match_key diff --git a/src/lib-sieve/plugins/relational/mcht-value.c b/src/lib-sieve/plugins/relational/mcht-value.c index d3c7f308b22612455983f52761cae6a445a1023d..54097d67e39153406c1d3e0c181526eb597cc7a2 100644 --- a/src/lib-sieve/plugins/relational/mcht-value.c +++ b/src/lib-sieve/plugins/relational/mcht-value.c @@ -24,7 +24,7 @@ */ const struct sieve_match_type_def value_match_type = { - SIEVE_OBJECT("value", &rel_match_type_operand, RELATIONAL_VALUE), + SIEVE_OBJECT("value", &rel_match_type_operand, RELATIONAL_VALUE), mcht_relational_validate, NULL, NULL, NULL, NULL, NULL, NULL }; @@ -40,22 +40,22 @@ const struct sieve_match_type_def rel_match_value_ ## name = { \ } VALUE_MATCH_TYPE(gt, REL_MATCH_GREATER); -VALUE_MATCH_TYPE(ge, REL_MATCH_GREATER_EQUAL); +VALUE_MATCH_TYPE(ge, REL_MATCH_GREATER_EQUAL); VALUE_MATCH_TYPE(lt, REL_MATCH_LESS); -VALUE_MATCH_TYPE(le, REL_MATCH_LESS_EQUAL); +VALUE_MATCH_TYPE(le, REL_MATCH_LESS_EQUAL); VALUE_MATCH_TYPE(eq, REL_MATCH_EQUAL); VALUE_MATCH_TYPE(ne, REL_MATCH_NOT_EQUAL); -/* - * Match-type implementation +/* + * Match-type implementation */ int mcht_value_match_key -(struct sieve_match_context *mctx, const char *val, size_t val_size, +(struct sieve_match_context *mctx, const char *val, size_t val_size, const char *key, size_t key_size) { const struct sieve_match_type *mtch = mctx->match_type; - unsigned int rel_match = REL_MATCH(mtch->object.def->code); + unsigned int rel_match = REL_MATCH(mtch->object.def->code); int cmp_result; cmp_result = mctx->comparator->def-> @@ -77,8 +77,8 @@ int mcht_value_match_key case REL_MATCH_INVALID: default: break; - } - + } + return FALSE; } diff --git a/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest-common.c b/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest-common.c index feda6a443935ed086d353cf528f5e9e8912a6a7e..628941658de0bd9fe68380e96a2bd4dcf59bc767 100644 --- a/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest-common.c +++ b/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest-common.c @@ -65,13 +65,13 @@ static bool _regexp_compile return TRUE; } - errsize = regerror(ret, regexp, NULL, 0); + errsize = regerror(ret, regexp, NULL, 0); if ( errsize > 0 ) { char *errbuf = t_malloc(errsize); (void)regerror(ret, regexp, errbuf, errsize); - + /* We don't want the error to start with a capital letter */ errbuf[0] = i_tolower(errbuf[0]); @@ -85,7 +85,7 @@ static const char *_regexp_match_get_value (const char *string, int index, regmatch_t pmatch[], int nmatch) { if ( index > -1 && index < nmatch && pmatch[index].rm_so != -1 ) { - return t_strndup(string + pmatch[index].rm_so, + return t_strndup(string + pmatch[index].rm_so, pmatch[index].rm_eo - pmatch[index].rm_so); } return NULL; @@ -96,7 +96,7 @@ static const char *_regexp_match_get_value */ static bool ext_spamvirustest_header_spec_parse -(struct ext_spamvirustest_header_spec *spec, pool_t pool, const char *data, +(struct ext_spamvirustest_header_spec *spec, pool_t pool, const char *data, const char **error_r) { const char *p; @@ -138,7 +138,7 @@ static bool ext_spamvirustest_header_spec_parse spec->regexp_match = TRUE; if ( !_regexp_compile(&spec->regexp, p, ®exp_error) ) { - *error_r = t_strdup_printf("failed to compile regular expression '%s': " + *error_r = t_strdup_printf("failed to compile regular expression '%s': " "%s", p, regexp_error); return FALSE; } @@ -162,7 +162,7 @@ static bool ext_spamvirustest_parse_strlen_value *value_r = 0; return TRUE; } - + while ( *p == ch ) p++; if ( *p != '\0' ) { @@ -186,14 +186,14 @@ static bool ext_spamvirustest_parse_decimal_value int digits; if ( *p == '\0' ) { - *error_r = "empty value"; + *error_r = "empty value"; return FALSE; } if ( *p == '+' || *p == '-' ) { if ( *p == '-' ) sign = -1; - + p++; } @@ -203,9 +203,9 @@ static bool ext_spamvirustest_parse_decimal_value value = value*10 + (*p-'0'); if ( digits++ > 4 ) { *error_r = t_strdup_printf - ("decimal value has too many digits before radix point: %s", + ("decimal value has too many digits before radix point: %s", str_value); - return FALSE; + return FALSE; } p++; } @@ -220,7 +220,7 @@ static bool ext_spamvirustest_parse_decimal_value if ( digits++ > 4 ) { *error_r = t_strdup_printf - ("decimal value has too many digits after radix point: %s", + ("decimal value has too many digits after radix point: %s", str_value); return FALSE; } @@ -250,7 +250,7 @@ bool ext_spamvirustest_load struct ext_spamvirustest_data *ext_data = (struct ext_spamvirustest_data *) *context; struct sieve_instance *svinst = ext->svinst; - const char *ext_name, *status_header, *max_header, *status_type, + const char *ext_name, *status_header, *max_header, *status_type, *max_value; enum ext_spamvirustest_status_type type; const char *error; @@ -264,12 +264,12 @@ bool ext_spamvirustest_load *context = NULL; } - /* FIXME: - * Prevent loading of both spamtest and spamtestplus: let these share + /* FIXME: + * Prevent loading of both spamtest and spamtestplus: let these share * contexts. */ - if ( sieve_extension_is(ext, spamtest_extension) || + if ( sieve_extension_is(ext, spamtest_extension) || sieve_extension_is(ext, spamtestplus_extension) ) { ext_name = spamtest_extension.name; } else { @@ -300,7 +300,7 @@ bool ext_spamvirustest_load } else if ( strcmp(status_type, "text") == 0 ) { type = EXT_SPAMVIRUSTEST_STATUS_TYPE_TEXT; } else { - sieve_sys_error(svinst, + sieve_sys_error(svinst, "%s: invalid status type '%s'", ext_name, status_type); return FALSE; } @@ -333,7 +333,7 @@ bool ext_spamvirustest_load sieve_sys_warning(svinst, "%s: setting sieve_%s_max_value has no meaning " "for sieve_%s_status_type=text", ext_name, ext_name, ext_name); - } + } } pool = pool_alloconly_create("spamvirustest_data", 512); @@ -361,7 +361,7 @@ bool ext_spamvirustest_load "'%s': %s", ext_name, max_header, error); result = FALSE; } - + /* Parse max value */ if ( result && max_value != NULL ) { @@ -376,13 +376,13 @@ bool ext_spamvirustest_load } else { unsigned int i, max_text; - + max_text = ( sieve_extension_is(ext, virustest_extension) ? 5 : 10 ); /* Get text values */ for ( i = 0; i <= max_text; i++ ) { const char *value = sieve_setting_get - (svinst, t_strdup_printf("sieve_%s_text_value%d", ext_name, i)); + (svinst, t_strdup_printf("sieve_%s_text_value%d", ext_name, i)); if ( value != NULL && *value != '\0' ) ext_data->text_values[i] = p_strdup(ext_data->pool, value); @@ -395,7 +395,7 @@ bool ext_spamvirustest_load if ( result ) { *context = (void *) ext_data; } else { - sieve_sys_warning(svinst, + sieve_sys_warning(svinst, "%s: extension not configured, tests will always match against \"0\"", ext_name); ext_spamvirustest_unload(ext); @@ -407,9 +407,9 @@ bool ext_spamvirustest_load void ext_spamvirustest_unload(const struct sieve_extension *ext) { - struct ext_spamvirustest_data *ext_data = + struct ext_spamvirustest_data *ext_data = (struct ext_spamvirustest_data *) ext->context; - + if ( ext_data != NULL ) { ext_spamvirustest_header_spec_free(&ext_data->status_header); ext_spamvirustest_header_spec_free(&ext_data->max_header); @@ -444,15 +444,15 @@ static const char *ext_spamvirustest_get_score else score = score_ratio * 9 + 1.001; - return t_strdup_printf("%d", score); + return t_strdup_printf("%d", score); } const char *ext_spamvirustest_get_value (const struct sieve_runtime_env *renv, const struct sieve_extension *ext, bool percent) { - struct ext_spamvirustest_data *ext_data = - (struct ext_spamvirustest_data *) ext->context; + struct ext_spamvirustest_data *ext_data = + (struct ext_spamvirustest_data *) ext->context; struct ext_spamvirustest_header_spec *status_header, *max_header; const struct sieve_message_data *msgdata = renv->msgdata; struct sieve_message_context *msgctx = renv->msgctx; @@ -465,11 +465,11 @@ const char *ext_spamvirustest_get_value unsigned int i, max_text; pool_t pool = sieve_interpreter_pool(renv->interp); - /* - * Check whether extension is properly configured + /* + * Check whether extension is properly configured */ if ( ext_data == NULL ) { - sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, + sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, "%s: extension not configured", ext_name); return "0"; } @@ -477,7 +477,7 @@ const char *ext_spamvirustest_get_value /* * Check wether a cached result is available */ - + mctx = (struct ext_spamvirustest_message_context *) sieve_message_context_extension_get(msgctx, ext); @@ -485,14 +485,14 @@ const char *ext_spamvirustest_get_value mctx = p_new(pool, struct ext_spamvirustest_message_context, 1); sieve_message_context_extension_set(msgctx, ext, (void *)mctx); } else if ( mctx->reload == ext_data->reload ) { - return ext_spamvirustest_get_score(ext, mctx->score_ratio, percent); + return ext_spamvirustest_get_score(ext, mctx->score_ratio, percent); } mctx->reload = ext_data->reload; /* * Get max status value - */ + */ status_header = &ext_data->status_header; max_header = &ext_data->max_header; @@ -503,15 +503,15 @@ const char *ext_spamvirustest_get_value if ( mail_get_first_header_utf8 (msgdata->mail, max_header->header_name, &header_value) < 0 || header_value == NULL ) { - sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, - "%s: header '%s' not found in message", + sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, + "%s: header '%s' not found in message", ext_name, max_header->header_name); goto failed; - } + } if ( max_header->regexp_match ) { /* Execute regex */ - if ( regexec(&max_header->regexp, header_value, 2, match_values, 0) + if ( regexec(&max_header->regexp, header_value, 2, match_values, 0) != 0 ) { sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, "%s: regexp for header '%s' did not match " @@ -540,7 +540,7 @@ const char *ext_spamvirustest_get_value } if ( max_value == 0 ) { - sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, + sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, "%s: max value is 0", ext_name); goto failed; } @@ -557,25 +557,25 @@ const char *ext_spamvirustest_get_value (msgdata->mail, status_header->header_name, &header_value) < 0 || header_value == NULL ) { sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, - "%s: header '%s' not found in message", + "%s: header '%s' not found in message", ext_name, status_header->header_name); goto failed; } /* Execute regex */ if ( status_header->regexp_match ) { - if ( regexec(&status_header->regexp, header_value, 2, match_values, 0) + if ( regexec(&status_header->regexp, header_value, 2, match_values, 0) != 0 ) { sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, "%s: regexp for header '%s' did not match on value '%s'", ext_name, status_header->header_name, header_value); goto failed; - } - + } + status = _regexp_match_get_value(header_value, 1, match_values, 2); if ( status == NULL ) { - sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, - "%s: regexp did not return match value for string '%s'", + sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, + "%s: regexp did not return match value for string '%s'", ext_name, header_value); goto failed; } @@ -588,7 +588,7 @@ const char *ext_spamvirustest_get_value if ( !ext_spamvirustest_parse_decimal_value (status, &status_value, &error) ) { sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, - "%s: failed to parse status value '%s': %s", + "%s: failed to parse status value '%s': %s", ext_name, status, error); goto failed; } @@ -596,8 +596,8 @@ const char *ext_spamvirustest_get_value case EXT_SPAMVIRUSTEST_STATUS_TYPE_STRLEN: if ( !ext_spamvirustest_parse_strlen_value (status, &status_value, &error) ) { - sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, - "%s: failed to parse status value '%s': %s", + sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, + "%s: failed to parse status value '%s': %s", ext_name, status, error); goto failed; } @@ -606,7 +606,7 @@ const char *ext_spamvirustest_get_value max_text = ( sieve_extension_is(ext, virustest_extension) ? 5 : 10 ); status_value = 0; - i = 0; + i = 0; while ( i <= max_text ) { if ( ext_data->text_values[i] != NULL && strcmp(status, ext_data->text_values[i]) == 0 ) { @@ -617,17 +617,17 @@ const char *ext_spamvirustest_get_value } if ( i > max_text ) { - sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, - "%s: failed to match textstatus value '%s'", + sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, + "%s: failed to match textstatus value '%s'", ext_name, status); - goto failed; - } + goto failed; + } break; default: i_unreached(); break; } - + /* Calculate value */ if ( status_value < 0 ) mctx->score_ratio = 0; diff --git a/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest-common.h b/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest-common.h index 11f3c6821089164d107629b9587ed30bb949cc85..d567a65dc68290f45356a8038766caf06670a55f 100644 --- a/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest-common.h +++ b/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest-common.h @@ -1,6 +1,6 @@ /* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #ifndef __EXT_SPAMVIRUSTEST_COMMON_H #define __EXT_SPAMVIRUSTEST_COMMON_H @@ -9,7 +9,7 @@ /* * Extensions */ - + extern const struct sieve_extension_def spamtest_extension; extern const struct sieve_extension_def spamtestplus_extension; extern const struct sieve_extension_def virustest_extension; @@ -17,13 +17,13 @@ extern const struct sieve_extension_def virustest_extension; bool ext_spamvirustest_load(const struct sieve_extension *ext, void **context); void ext_spamvirustest_unload(const struct sieve_extension *ext); -/* +/* * Tests */ extern const struct sieve_command_def spamtest_test; extern const struct sieve_command_def virustest_test; - + const char *ext_spamvirustest_get_value (const struct sieve_runtime_env *renv, const struct sieve_extension *ext, bool percent); diff --git a/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest.c b/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest.c index eb165c14a9aba459a86b69d47dd25371722703e7..a433def11ce33eb4bd3f9dea78f1411f7cbd69a3 100644 --- a/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest.c +++ b/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest.c @@ -18,7 +18,7 @@ * sieve_spamtest_status_header = \ * X-Spam-Score: [[:alnum:]]+, score=(-?[[:digit:]]+\.[[:digit:]]) * sieve_spamtest_max_value = 5.0 - * + * * # 2: X-Spam-Status: Yes * * sieve_spamtest_status_header = X-Spam-Status @@ -33,9 +33,9 @@ * # 4: X-Spam-Score: status=3.2 required=5.0 * * sieve_spamtest_status_header = \ - * X-Spam-Score: score=(-?[[:digit:]]+\.[[:digit:]]).* + * X-Spam-Score: score=(-?[[:digit:]]+\.[[:digit:]]).* * sieve_spamtest_max_header = \ - * X-Spam-Score: score=-?[[:digit:]]+\.[[:digit:]] required=([[:digit:]]+\.[[:digit:]]) + * X-Spam-Score: score=-?[[:digit:]]+\.[[:digit:]] required=([[:digit:]]+\.[[:digit:]]) * * # 5: X-Virus-Scan: Found to be clean. * @@ -45,7 +45,7 @@ * sieve_virustest_text_value1 = clean * sieve_virustest_text_value5 = infected */ - + #include "lib.h" #include "array.h" @@ -58,8 +58,8 @@ #include "ext-spamvirustest-common.h" -/* - * Extensions +/* + * Extensions */ /* Spamtest */ @@ -67,33 +67,33 @@ static bool ext_spamvirustest_validator_load (const struct sieve_extension *ext, struct sieve_validator *validator); -const struct sieve_extension_def spamtest_extension = { - "spamtest", - ext_spamvirustest_load, +const struct sieve_extension_def spamtest_extension = { + "spamtest", + ext_spamvirustest_load, ext_spamvirustest_unload, - ext_spamvirustest_validator_load, + ext_spamvirustest_validator_load, NULL, NULL, NULL, NULL, NULL, - SIEVE_EXT_DEFINE_OPERATION(spamtest_operation), + SIEVE_EXT_DEFINE_OPERATION(spamtest_operation), SIEVE_EXT_DEFINE_NO_OPERANDS }; -const struct sieve_extension_def spamtestplus_extension = { - "spamtestplus", - ext_spamvirustest_load, +const struct sieve_extension_def spamtestplus_extension = { + "spamtestplus", + ext_spamvirustest_load, ext_spamvirustest_unload, - ext_spamvirustest_validator_load, + ext_spamvirustest_validator_load, NULL, NULL, NULL, NULL, NULL, - SIEVE_EXT_DEFINE_OPERATION(spamtest_operation), + SIEVE_EXT_DEFINE_OPERATION(spamtest_operation), SIEVE_EXT_DEFINE_NO_OPERANDS }; -const struct sieve_extension_def virustest_extension = { - "virustest", - ext_spamvirustest_load, +const struct sieve_extension_def virustest_extension = { + "virustest", + ext_spamvirustest_load, ext_spamvirustest_unload, - ext_spamvirustest_validator_load, + ext_spamvirustest_validator_load, NULL, NULL, NULL, NULL, NULL, - SIEVE_EXT_DEFINE_OPERATION(virustest_operation), + SIEVE_EXT_DEFINE_OPERATION(virustest_operation), SIEVE_EXT_DEFINE_NO_OPERANDS }; @@ -102,7 +102,7 @@ const struct sieve_extension_def virustest_extension = { */ static bool ext_spamtest_validator_extension_validate - (const struct sieve_extension *ext, struct sieve_validator *valdtr, + (const struct sieve_extension *ext, struct sieve_validator *valdtr, void *context, struct sieve_ast_argument *require_arg); const struct sieve_validator_extension spamtest_validator_extension = { @@ -132,7 +132,7 @@ static bool ext_spamvirustest_validator_load } static bool ext_spamtest_validator_extension_validate -(const struct sieve_extension *ext, struct sieve_validator *valdtr, +(const struct sieve_extension *ext, struct sieve_validator *valdtr, void *context ATTR_UNUSED, struct sieve_ast_argument *require_arg) { const struct sieve_extension *ext_spamtestplus = diff --git a/src/lib-sieve/plugins/spamvirustest/tst-spamvirustest.c b/src/lib-sieve/plugins/spamvirustest/tst-spamvirustest.c index 6ea114ff87dfbb8fd9cc5e21465f6bddaba9d9bc..0a2a0f383ee246055d3f5009be8484770f265d97 100644 --- a/src/lib-sieve/plugins/spamvirustest/tst-spamvirustest.c +++ b/src/lib-sieve/plugins/spamvirustest/tst-spamvirustest.c @@ -30,60 +30,60 @@ static bool tst_spamvirustest_generate static bool tst_spamvirustest_registered (struct sieve_validator *valdtr, const struct sieve_extension *ext, struct sieve_command_registration *cmd_reg); - + /* Spamtest test * * Syntax: - * spamtest [":percent"] [COMPARATOR] [MATCH-TYPE] <value: string> + * spamtest [":percent"] [COMPARATOR] [MATCH-TYPE] <value: string> */ -const struct sieve_command_def spamtest_test = { - "spamtest", - SCT_TEST, +const struct sieve_command_def spamtest_test = { + "spamtest", + SCT_TEST, 1, 0, FALSE, FALSE, tst_spamvirustest_registered, - NULL, + NULL, tst_spamvirustest_validate, NULL, - tst_spamvirustest_generate, - NULL + tst_spamvirustest_generate, + NULL }; /* Virustest test * * Syntax: - * virustest [COMPARATOR] [MATCH-TYPE] <value: string> + * virustest [COMPARATOR] [MATCH-TYPE] <value: string> */ -const struct sieve_command_def virustest_test = { - "virustest", - SCT_TEST, +const struct sieve_command_def virustest_test = { + "virustest", + SCT_TEST, 1, 0, FALSE, FALSE, tst_spamvirustest_registered, - NULL, + NULL, tst_spamvirustest_validate, - NULL, - tst_spamvirustest_generate, - NULL + NULL, + tst_spamvirustest_generate, + NULL }; -/* - * Tagged arguments +/* + * Tagged arguments */ static bool tst_spamtest_validate_percent_tag - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *tst); static const struct sieve_argument_def spamtest_percent_tag = { "percent", - NULL, + NULL, tst_spamtest_validate_percent_tag, NULL, NULL, NULL }; -/* - * Spamtest and virustest operations +/* + * Spamtest and virustest operations */ static bool tst_spamvirustest_operation_dump @@ -91,20 +91,20 @@ static bool tst_spamvirustest_operation_dump static int tst_spamvirustest_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def spamtest_operation = { +const struct sieve_operation_def spamtest_operation = { "SPAMTEST", &spamtest_extension, 0, - tst_spamvirustest_operation_dump, - tst_spamvirustest_operation_execute + tst_spamvirustest_operation_dump, + tst_spamvirustest_operation_execute }; -const struct sieve_operation_def virustest_operation = { +const struct sieve_operation_def virustest_operation = { "VIRUSTEST", &virustest_extension, 0, - tst_spamvirustest_operation_dump, - tst_spamvirustest_operation_execute + tst_spamvirustest_operation_dump, + tst_spamvirustest_operation_execute }; @@ -117,18 +117,18 @@ enum tst_spamvirustest_optional { OPT_SPAMTEST_LAST }; -/* - * Test registration +/* + * Test registration */ static bool tst_spamvirustest_registered (struct sieve_validator *valdtr, const struct sieve_extension *ext, - struct sieve_command_registration *cmd_reg) + struct sieve_command_registration *cmd_reg) { sieve_comparators_link_tag(valdtr, cmd_reg, SIEVE_MATCH_OPT_COMPARATOR); sieve_match_types_link_tags(valdtr, cmd_reg, SIEVE_MATCH_OPT_MATCH_TYPE); - if ( sieve_extension_is(ext, spamtestplus_extension) || + if ( sieve_extension_is(ext, spamtestplus_extension) || sieve_extension_is(ext, spamtest_extension) ) { sieve_validator_register_tag (valdtr, cmd_reg, ext, &spamtest_percent_tag, OPT_SPAMTEST_PERCENT); @@ -137,19 +137,19 @@ static bool tst_spamvirustest_registered return TRUE; } -/* - * Validation +/* + * Validation */ static bool tst_spamtest_validate_percent_tag -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *tst) { - if ( !sieve_extension_is(tst->ext, spamtestplus_extension) ) { + if ( !sieve_extension_is(tst->ext, spamtestplus_extension) ) { sieve_argument_validate_error(valdtr, *arg, "the spamtest test only accepts the :percent argument when " - "the spamtestplus extension is active"); - return FALSE; + "the spamtestplus extension is active"); + return FALSE; } /* Skip tag */ @@ -159,16 +159,16 @@ static bool tst_spamtest_validate_percent_tag } static bool tst_spamvirustest_validate -(struct sieve_validator *valdtr, struct sieve_command *tst) +(struct sieve_validator *valdtr, struct sieve_command *tst) { struct sieve_ast_argument *arg = tst->first_positional; - const struct sieve_match_type mcht_default = + const struct sieve_match_type mcht_default = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); - const struct sieve_comparator cmp_default = + const struct sieve_comparator cmp_default = SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator); - + /* Check value */ - + if ( !sieve_validate_positional_argument (valdtr, tst, arg, "value", 1, SAAT_STRING) ) { return FALSE; @@ -176,19 +176,19 @@ static bool tst_spamvirustest_validate if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) ) return FALSE; - + /* Validate the key argument to a specified match type */ return sieve_match_type_validate - (valdtr, tst, arg, &mcht_default, &cmp_default); + (valdtr, tst, arg, &mcht_default, &cmp_default); } -/* - * Code generation +/* + * Code generation */ static bool tst_spamvirustest_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *tst) -{ +(const struct sieve_codegen_env *cgenv, struct sieve_command *tst) +{ if ( sieve_command_is(tst, spamtest_test) ) sieve_operation_emit(cgenv->sblock, tst->ext, &spamtest_operation); else if ( sieve_command_is(tst, virustest_test) ) @@ -196,12 +196,12 @@ static bool tst_spamvirustest_generate else i_unreached(); - /* Generate arguments */ + /* Generate arguments */ return sieve_generate_arguments(cgenv, tst, NULL); } -/* - * Code dump +/* + * Code dump */ static bool tst_spamvirustest_operation_dump @@ -212,7 +212,7 @@ static bool tst_spamvirustest_operation_dump sieve_code_dumpf(denv, "%s", sieve_operation_mnemonic(op)); sieve_code_descend(denv); - + /* Optional operands */ for (;;) { int opt; @@ -235,25 +235,25 @@ static bool tst_spamvirustest_operation_dump sieve_opr_string_dump(denv, address, "value"); } -/* - * Code execution +/* + * Code execution */ static int tst_spamvirustest_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) -{ +{ const struct sieve_operation *op = renv->oprtn; const struct sieve_extension *this_ext = op->ext; int opt_code = 0; - struct sieve_match_type mcht = + struct sieve_match_type mcht = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); - struct sieve_comparator cmp = + struct sieve_comparator cmp = SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator); bool percent = FALSE; struct sieve_stringlist *value_list, *key_list; const char *score_value; int match, ret; - + /* Read optional operands */ for (;;) { int opt; @@ -263,7 +263,7 @@ static int tst_spamvirustest_operation_execute return ret; if ( opt == 0 ) break; - + switch ( opt_code ) { case OPT_SPAMTEST_PERCENT: percent = TRUE; @@ -277,7 +277,7 @@ static int tst_spamvirustest_operation_execute /* Read value part */ if ( (ret=sieve_opr_stringlist_read(renv, address, "value", &key_list)) <= 0 ) return ret; - + /* Perform test */ if ( sieve_operation_is(op, spamtest_operation) ) { @@ -297,7 +297,7 @@ static int tst_spamvirustest_operation_execute /* Perform match */ if ( (match=sieve_match(renv, &mcht, &cmp, value_list, key_list, &ret)) < 0 ) - return ret; + return ret; /* Set test result for subsequent conditional jump */ sieve_interpreter_set_test_result(renv->interp, match > 0); diff --git a/src/lib-sieve/plugins/subaddress/ext-subaddress.c b/src/lib-sieve/plugins/subaddress/ext-subaddress.c index 56a0e2c19a1ba23dad1bfc485e47fcf7b5c24e3d..061ec9a55b9052e1dc0a3cd24112f51068712f4e 100644 --- a/src/lib-sieve/plugins/subaddress/ext-subaddress.c +++ b/src/lib-sieve/plugins/subaddress/ext-subaddress.c @@ -37,7 +37,7 @@ struct ext_subaddress_config { }; /* - * Forward declarations + * Forward declarations */ const struct sieve_address_part_def user_address_part; @@ -56,13 +56,13 @@ static void ext_subaddress_unload static bool ext_subaddress_validator_load (const struct sieve_extension *ext, struct sieve_validator *validator); -const struct sieve_extension_def subaddress_extension = { - "subaddress", - ext_subaddress_load, +const struct sieve_extension_def subaddress_extension = { + "subaddress", + ext_subaddress_load, ext_subaddress_unload, ext_subaddress_validator_load, NULL, NULL, NULL, NULL, NULL, - SIEVE_EXT_DEFINE_NO_OPERATIONS, + SIEVE_EXT_DEFINE_NO_OPERATIONS, SIEVE_EXT_DEFINE_OPERAND(subaddress_operand) }; @@ -102,8 +102,8 @@ static void ext_subaddress_unload static bool ext_subaddress_validator_load (const struct sieve_extension *ext, struct sieve_validator *validator) { - sieve_address_part_register(validator, ext, &user_address_part); - sieve_address_part_register(validator, ext, &detail_address_part); + sieve_address_part_register(validator, ext, &user_address_part); + sieve_address_part_register(validator, ext, &detail_address_part); return TRUE; } @@ -111,7 +111,7 @@ static bool ext_subaddress_validator_load /* * Address parts */ - + enum ext_subaddress_address_part { SUBADDRESS_USER, SUBADDRESS_DETAIL @@ -124,7 +124,7 @@ static const char *subaddress_user_extract_from static const char *subaddress_detail_extract_from (const struct sieve_address_part *addrp, const struct sieve_address *address); -/* Address part objects */ +/* Address part objects */ const struct sieve_address_part_def user_address_part = { SIEVE_OBJECT("user", &subaddress_operand, SUBADDRESS_USER), @@ -141,38 +141,38 @@ const struct sieve_address_part_def detail_address_part = { static const char *subaddress_user_extract_from (const struct sieve_address_part *addrp, const struct sieve_address *address) { - struct ext_subaddress_config *config = + struct ext_subaddress_config *config = (struct ext_subaddress_config *) addrp->object.ext->context; const char *delim; delim = strstr(address->local_part, config->delimiter); - + if ( delim == NULL ) return address->local_part; - + return t_strdup_until(address->local_part, delim); } static const char *subaddress_detail_extract_from (const struct sieve_address_part *addrp, const struct sieve_address *address) { - struct ext_subaddress_config *config = + struct ext_subaddress_config *config = (struct ext_subaddress_config *) addrp->object.ext->context; const char *delim; if ( (delim=strstr(address->local_part, config->delimiter)) == NULL ) - return NULL; + return NULL; delim += strlen(config->delimiter); /* Just to be sure */ - if ( delim > (address->local_part + strlen(address->local_part)) ) + if ( delim > (address->local_part + strlen(address->local_part)) ) return NULL; return delim; } /* - * Operand + * Operand */ const struct sieve_address_part_def *ext_subaddress_parts[] = { @@ -182,8 +182,8 @@ const struct sieve_address_part_def *ext_subaddress_parts[] = { static const struct sieve_extension_objects ext_address_parts = SIEVE_EXT_DEFINE_ADDRESS_PARTS(ext_subaddress_parts); -static struct sieve_operand_def subaddress_operand = { - "address-part", +static struct sieve_operand_def subaddress_operand = { + "address-part", &subaddress_extension, 0, &sieve_address_part_operand_class, &ext_address_parts diff --git a/src/lib-sieve/plugins/vacation/cmd-vacation.c b/src/lib-sieve/plugins/vacation/cmd-vacation.c index d3c83e96a2fe4a95b4c4f15ebd5ebd65bbf3238f..fdab09856ca6cb94b2cb38bcb7b26523423df52f 100644 --- a/src/lib-sieve/plugins/vacation/cmd-vacation.c +++ b/src/lib-sieve/plugins/vacation/cmd-vacation.c @@ -32,10 +32,10 @@ #include <stdio.h> -/* - * Forward declarations +/* + * Forward declarations */ - + static const struct sieve_argument_def vacation_days_tag; static const struct sieve_argument_def vacation_subject_tag; static const struct sieve_argument_def vacation_from_tag; @@ -43,10 +43,10 @@ static const struct sieve_argument_def vacation_addresses_tag; static const struct sieve_argument_def vacation_mime_tag; static const struct sieve_argument_def vacation_handle_tag; -/* - * Vacation command - * - * Syntax: +/* + * Vacation command + * + * Syntax: * vacation [":days" number] [":subject" string] * [":from" string] [":addresses" string-list] * [":mime"] [":handle" string] <reason: string> @@ -56,22 +56,22 @@ static bool cmd_vacation_registered (struct sieve_validator *valdtr, const struct sieve_extension *ext, struct sieve_command_registration *cmd_reg); static bool cmd_vacation_pre_validate - (struct sieve_validator *valdtr, struct sieve_command *cmd); + (struct sieve_validator *valdtr, struct sieve_command *cmd); static bool cmd_vacation_validate (struct sieve_validator *valdtr, struct sieve_command *cmd); static bool cmd_vacation_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd); -const struct sieve_command_def vacation_command = { +const struct sieve_command_def vacation_command = { "vacation", - SCT_COMMAND, - 1, 0, FALSE, FALSE, + SCT_COMMAND, + 1, 0, FALSE, FALSE, cmd_vacation_registered, - cmd_vacation_pre_validate, + cmd_vacation_pre_validate, cmd_vacation_validate, NULL, - cmd_vacation_generate, - NULL + cmd_vacation_generate, + NULL }; /* @@ -81,67 +81,67 @@ const struct sieve_command_def vacation_command = { /* Forward declarations */ static bool cmd_vacation_validate_number_tag - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); static bool cmd_vacation_validate_string_tag - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); static bool cmd_vacation_validate_stringlist_tag - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); static bool cmd_vacation_validate_mime_tag - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); /* Argument objects */ -static const struct sieve_argument_def vacation_days_tag = { - "days", - NULL, - cmd_vacation_validate_number_tag, - NULL, NULL, NULL, +static const struct sieve_argument_def vacation_days_tag = { + "days", + NULL, + cmd_vacation_validate_number_tag, + NULL, NULL, NULL, }; -static const struct sieve_argument_def vacation_seconds_tag = { - "seconds", - NULL, - cmd_vacation_validate_number_tag, - NULL, NULL, NULL, +static const struct sieve_argument_def vacation_seconds_tag = { + "seconds", + NULL, + cmd_vacation_validate_number_tag, + NULL, NULL, NULL, }; -static const struct sieve_argument_def vacation_subject_tag = { - "subject", +static const struct sieve_argument_def vacation_subject_tag = { + "subject", NULL, - cmd_vacation_validate_string_tag, - NULL, NULL, NULL + cmd_vacation_validate_string_tag, + NULL, NULL, NULL }; -static const struct sieve_argument_def vacation_from_tag = { - "from", +static const struct sieve_argument_def vacation_from_tag = { + "from", NULL, - cmd_vacation_validate_string_tag, - NULL, NULL, NULL + cmd_vacation_validate_string_tag, + NULL, NULL, NULL }; -static const struct sieve_argument_def vacation_addresses_tag = { - "addresses", +static const struct sieve_argument_def vacation_addresses_tag = { + "addresses", NULL, - cmd_vacation_validate_stringlist_tag, - NULL, NULL, NULL + cmd_vacation_validate_stringlist_tag, + NULL, NULL, NULL }; -static const struct sieve_argument_def vacation_mime_tag = { - "mime", - NULL, +static const struct sieve_argument_def vacation_mime_tag = { + "mime", + NULL, cmd_vacation_validate_mime_tag, NULL, NULL, NULL }; -static const struct sieve_argument_def vacation_handle_tag = { - "handle", - NULL, - cmd_vacation_validate_string_tag, - NULL, NULL, NULL +static const struct sieve_argument_def vacation_handle_tag = { + "handle", + NULL, + cmd_vacation_validate_string_tag, + NULL, NULL, NULL }; /* Codes for optional arguments */ @@ -155,8 +155,8 @@ enum cmd_vacation_optional { OPT_MIME }; -/* - * Vacation operation +/* + * Vacation operation */ static bool ext_vacation_operation_dump @@ -164,33 +164,33 @@ static bool ext_vacation_operation_dump static int ext_vacation_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def vacation_operation = { +const struct sieve_operation_def vacation_operation = { "VACATION", &vacation_extension, 0, - ext_vacation_operation_dump, + ext_vacation_operation_dump, ext_vacation_operation_execute }; -/* - * Vacation action +/* + * Vacation action */ /* Forward declarations */ static int act_vacation_check_duplicate - (const struct sieve_runtime_env *renv, - const struct sieve_action *act, + (const struct sieve_runtime_env *renv, + const struct sieve_action *act, const struct sieve_action *act_other); int act_vacation_check_conflict - (const struct sieve_runtime_env *renv, - const struct sieve_action *act, + (const struct sieve_runtime_env *renv, + const struct sieve_action *act, const struct sieve_action *act_other); static void act_vacation_print - (const struct sieve_action *action, - const struct sieve_result_print_env *rpenv, bool *keep); + (const struct sieve_action *action, + const struct sieve_result_print_env *rpenv, bool *keep); static bool act_vacation_commit - (const struct sieve_action *action, const struct sieve_action_exec_env *aenv, + (const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void *tr_context, bool *keep); /* Action object */ @@ -199,7 +199,7 @@ const struct sieve_action_def act_vacation = { "vacation", SIEVE_ACTFLAG_SENDS_RESPONSE, NULL, - act_vacation_check_duplicate, + act_vacation_check_duplicate, act_vacation_check_conflict, act_vacation_print, NULL, NULL, @@ -208,7 +208,7 @@ const struct sieve_action_def act_vacation = { }; /* Action context information */ - + struct act_vacation_context { const char *reason; @@ -217,29 +217,29 @@ struct act_vacation_context { const char *handle; bool mime; const char *from; - const char *from_normalized; + const char *from_normalized; const char *const *addresses; }; /* * Command validation context */ - + struct cmd_vacation_context_data { string_t *from; string_t *subject; - + bool mime; - + struct sieve_ast_argument *handle_arg; }; -/* - * Tag validation +/* + * Tag validation */ static bool cmd_vacation_validate_number_tag -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd) { const struct sieve_extension *ext = sieve_argument_ext(*arg); @@ -247,10 +247,10 @@ static bool cmd_vacation_validate_number_tag (const struct ext_vacation_config *) ext->context; struct sieve_ast_argument *tag = *arg; sieve_number_t period, seconds; - + /* Detach the tag itself */ *arg = sieve_ast_arguments_detach(*arg,1); - + /* Check syntax: * :days number */ @@ -261,7 +261,7 @@ static bool cmd_vacation_validate_number_tag period = sieve_ast_argument_number(*arg); if ( sieve_argument_is(tag, vacation_days_tag) ) { - seconds = period * (24*60*60); + seconds = period * (24*60*60); } else if ( sieve_argument_is(tag, vacation_seconds_tag) ) { seconds = period; @@ -291,21 +291,21 @@ static bool cmd_vacation_validate_number_tag /* Skip parameter */ *arg = sieve_ast_argument_next(*arg); - + return TRUE; } static bool cmd_vacation_validate_string_tag -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd) { struct sieve_ast_argument *tag = *arg; - struct cmd_vacation_context_data *ctx_data = - (struct cmd_vacation_context_data *) cmd->data; + struct cmd_vacation_context_data *ctx_data = + (struct cmd_vacation_context_data *) cmd->data; /* Detach the tag itself */ *arg = sieve_ast_arguments_detach(*arg,1); - + /* Check syntax: * :subject string * :from string @@ -321,51 +321,51 @@ static bool cmd_vacation_validate_string_tag string_t *address = sieve_ast_argument_str(*arg); const char *error; bool result; - + T_BEGIN { result = sieve_address_validate(address, &error); - + if ( !result ) { - sieve_argument_validate_error(valdtr, *arg, - "specified :from address '%s' is invalid for vacation action: %s", + sieve_argument_validate_error(valdtr, *arg, + "specified :from address '%s' is invalid for vacation action: %s", str_sanitize(str_c(address), 128), error); } } T_END; - + if ( !result ) return FALSE; } - + ctx_data->from = sieve_ast_argument_str(*arg); - + /* Skip parameter */ *arg = sieve_ast_argument_next(*arg); - + } else if ( sieve_argument_is(tag, vacation_subject_tag) ) { ctx_data->subject = sieve_ast_argument_str(*arg); - + /* Skip parameter */ *arg = sieve_ast_argument_next(*arg); - + } else if ( sieve_argument_is(tag, vacation_handle_tag) ) { - ctx_data->handle_arg = *arg; + ctx_data->handle_arg = *arg; /* Detach optional argument (emitted as mandatory) */ *arg = sieve_ast_arguments_detach(*arg, 1); } - + return TRUE; } static bool cmd_vacation_validate_stringlist_tag -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd) { struct sieve_ast_argument *tag = *arg; /* Detach the tag itself */ *arg = sieve_ast_arguments_detach(*arg,1); - + /* Check syntax: * :addresses string-list */ @@ -373,7 +373,7 @@ static bool cmd_vacation_validate_stringlist_tag (valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING_LIST, FALSE) ) { return FALSE; } - + /* Skip parameter */ *arg = sieve_ast_argument_next(*arg); @@ -381,40 +381,40 @@ static bool cmd_vacation_validate_stringlist_tag } static bool cmd_vacation_validate_mime_tag -(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_ast_argument **arg, struct sieve_command *cmd) { - struct cmd_vacation_context_data *ctx_data = - (struct cmd_vacation_context_data *) cmd->data; + struct cmd_vacation_context_data *ctx_data = + (struct cmd_vacation_context_data *) cmd->data; ctx_data->mime = TRUE; /* Skip tag */ *arg = sieve_ast_argument_next(*arg); - + return TRUE; } -/* - * Command registration +/* + * Command registration */ static bool cmd_vacation_registered (struct sieve_validator *valdtr, const struct sieve_extension *ext, - struct sieve_command_registration *cmd_reg) + struct sieve_command_registration *cmd_reg) { sieve_validator_register_tag - (valdtr, cmd_reg, ext, &vacation_days_tag, OPT_SECONDS); + (valdtr, cmd_reg, ext, &vacation_days_tag, OPT_SECONDS); sieve_validator_register_tag - (valdtr, cmd_reg, ext, &vacation_subject_tag, OPT_SUBJECT); + (valdtr, cmd_reg, ext, &vacation_subject_tag, OPT_SUBJECT); sieve_validator_register_tag - (valdtr, cmd_reg, ext, &vacation_from_tag, OPT_FROM); + (valdtr, cmd_reg, ext, &vacation_from_tag, OPT_FROM); sieve_validator_register_tag - (valdtr, cmd_reg, ext, &vacation_addresses_tag, OPT_ADDRESSES); + (valdtr, cmd_reg, ext, &vacation_addresses_tag, OPT_ADDRESSES); sieve_validator_register_tag - (valdtr, cmd_reg, ext, &vacation_mime_tag, OPT_MIME); + (valdtr, cmd_reg, ext, &vacation_mime_tag, OPT_MIME); sieve_validator_register_tag - (valdtr, cmd_reg, ext, &vacation_handle_tag, 0); + (valdtr, cmd_reg, ext, &vacation_handle_tag, 0); return TRUE; } @@ -427,20 +427,20 @@ bool ext_vacation_register_seconds_tag OPT_SECONDS); return TRUE; -} +} -/* - * Command validation +/* + * Command validation */ - + static bool cmd_vacation_pre_validate -(struct sieve_validator *valdtr ATTR_UNUSED, - struct sieve_command *cmd) +(struct sieve_validator *valdtr ATTR_UNUSED, + struct sieve_command *cmd) { struct cmd_vacation_context_data *ctx_data; - + /* Assign context */ - ctx_data = p_new(sieve_command_pool(cmd), + ctx_data = p_new(sieve_command_pool(cmd), struct cmd_vacation_context_data, 1); cmd->data = ctx_data; @@ -453,52 +453,52 @@ static const char _handle_mime_enabled[] = "<MIME>"; static const char _handle_mime_disabled[] = "<NO-MIME>"; static bool cmd_vacation_validate -(struct sieve_validator *valdtr, struct sieve_command *cmd) -{ +(struct sieve_validator *valdtr, struct sieve_command *cmd) +{ struct sieve_ast_argument *arg = cmd->first_positional; - struct cmd_vacation_context_data *ctx_data = - (struct cmd_vacation_context_data *) cmd->data; + struct cmd_vacation_context_data *ctx_data = + (struct cmd_vacation_context_data *) cmd->data; if ( !sieve_validate_positional_argument (valdtr, cmd, arg, "reason", 1, SAAT_STRING) ) { return FALSE; } - + if ( !sieve_validator_argument_activate(valdtr, cmd, arg, FALSE) ) return FALSE; - + /* Construct handle if not set explicitly */ if ( ctx_data->handle_arg == NULL ) { T_BEGIN { string_t *handle; string_t *reason = sieve_ast_argument_str(arg); unsigned int size = str_len(reason); - + /* Precalculate the size of it all */ - size += ctx_data->subject == NULL ? + size += ctx_data->subject == NULL ? sizeof(_handle_empty_subject) - 1 : str_len(ctx_data->subject); - size += ctx_data->from == NULL ? - sizeof(_handle_empty_from) - 1 : str_len(ctx_data->from); - size += ctx_data->mime ? - sizeof(_handle_mime_enabled) - 1 : sizeof(_handle_mime_disabled) - 1; - + size += ctx_data->from == NULL ? + sizeof(_handle_empty_from) - 1 : str_len(ctx_data->from); + size += ctx_data->mime ? + sizeof(_handle_mime_enabled) - 1 : sizeof(_handle_mime_disabled) - 1; + /* Construct the string */ handle = t_str_new(size); str_append_str(handle, reason); - + if ( ctx_data->subject != NULL ) str_append_str(handle, ctx_data->subject); else str_append(handle, _handle_empty_subject); - + if ( ctx_data->from != NULL ) str_append_str(handle, ctx_data->from); else str_append(handle, _handle_empty_from); - - str_append(handle, + + str_append(handle, ctx_data->mime ? _handle_mime_enabled : _handle_mime_disabled ); - + /* Create positional handle argument */ ctx_data->handle_arg = sieve_ast_argument_string_create (cmd->ast_node, handle, sieve_ast_node_line(cmd->ast_node)); @@ -511,37 +511,37 @@ static bool cmd_vacation_validate /* Attach explicit handle argument as positional */ (void)sieve_ast_argument_attach(cmd->ast_node, ctx_data->handle_arg); } - + return TRUE; } /* * Code generation */ - + static bool cmd_vacation_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) -{ +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) +{ sieve_operation_emit(cgenv->sblock, cmd->ext, &vacation_operation); /* Generate arguments */ if ( !sieve_generate_arguments(cgenv, cmd, NULL) ) - return FALSE; - + return FALSE; + return TRUE; } -/* +/* * Code dump */ - + static bool ext_vacation_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) -{ +{ int opt_code = 0; - + sieve_code_dumpf(denv, "VACATION"); - sieve_code_descend(denv); + sieve_code_descend(denv); /* Dump optional operands */ @@ -568,28 +568,28 @@ static bool ext_vacation_operation_dump opok = sieve_opr_stringlist_dump(denv, address, "addresses"); break; case OPT_MIME: - sieve_code_dumpf(denv, "mime"); - break; + sieve_code_dumpf(denv, "mime"); + break; default: return FALSE; } if ( !opok ) return FALSE; } - + /* Dump reason and handle operands */ - return + return sieve_opr_string_dump(denv, address, "reason") && sieve_opr_string_dump(denv, address, "handle"); } -/* +/* * Code execution */ - + static int ext_vacation_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) -{ +{ const struct sieve_extension *this_ext = renv->oprtn->ext; const struct ext_vacation_config *config = (const struct ext_vacation_config *) this_ext->context; @@ -600,7 +600,7 @@ static int ext_vacation_operation_execute sieve_number_t seconds = config->default_period; bool mime = FALSE; struct sieve_stringlist *addresses = NULL; - string_t *reason, *subject = NULL, *from = NULL, *handle = NULL; + string_t *reason, *subject = NULL, *from = NULL, *handle = NULL; const char *from_normalized = NULL; int ret; @@ -642,14 +642,14 @@ static int ext_vacation_operation_execute if ( ret <= 0 ) return ret; } - + /* Fixed operands */ if ( (ret=sieve_opr_string_read(renv, address, "reason", &reason)) <= 0 || (ret=sieve_opr_string_read(renv, address, "handle", &handle)) <= 0 ) { return ret; } - + /* * Perform operation */ @@ -661,14 +661,14 @@ static int ext_vacation_operation_execute sieve_runtime_trace_descend(renv); sieve_runtime_trace(renv, 0, "auto-reply with message `%s'", str_sanitize(str_c(reason), 80)); - } + } /* Check and normalize :from address */ if ( from != NULL ) { const char *error; from_normalized = sieve_address_normalize(from, &error); - + if ( from_normalized == NULL) { sieve_runtime_error(renv, NULL, "specified :from address '%s' is invalid for vacation action: %s", @@ -698,18 +698,18 @@ static int ext_vacation_operation_execute int ret; sieve_stringlist_reset(addresses); - + p_array_init(&norm_addresses, pool, 4); - + raw_address = NULL; while ( (ret=sieve_stringlist_next_item(addresses, &raw_address)) > 0 ) { const char *error; const char *addr_norm = sieve_address_normalize(raw_address, &error); - + if ( addr_norm != NULL ) { addr_norm = p_strdup(pool, addr_norm); - - array_append(&norm_addresses, &addr_norm, 1); + + array_append(&norm_addresses, &addr_norm, 1); } else { sieve_runtime_error(renv, NULL, "specified :addresses item '%s' is invalid: %s for vacation action " @@ -717,21 +717,21 @@ static int ext_vacation_operation_execute str_sanitize(str_c(raw_address),128), error); } } - + if ( ret < 0 ) { sieve_runtime_trace_error(renv, "invalid addresses stringlist"); return SIEVE_EXEC_BIN_CORRUPT; } - + (void)array_append_space(&norm_addresses); act->addresses = array_idx(&norm_addresses, 0); - } - + } + if ( sieve_result_add_action (renv, this_ext, &act_vacation, slist, (void *) act, 0, FALSE) < 0 ) return SIEVE_EXEC_FAILURE; - return SIEVE_EXEC_OK; + return SIEVE_EXEC_OK; } /* @@ -758,14 +758,14 @@ static int act_vacation_check_duplicate int act_vacation_check_conflict (const struct sieve_runtime_env *renv, - const struct sieve_action *act, + const struct sieve_action *act, const struct sieve_action *act_other) { if ( (act_other->def->flags & SIEVE_ACTFLAG_SENDS_RESPONSE) > 0 ) { if ( !act_other->executed && !act->executed) { - sieve_runtime_error(renv, act->location, + sieve_runtime_error(renv, act->location, "vacation action conflicts with other action: " - "the %s action (%s) also sends a response back to the sender", + "the %s action (%s) also sends a response back to the sender", act_other->def->name, act_other->location); return -1; } else { @@ -778,14 +778,14 @@ int act_vacation_check_conflict } /* Result printing */ - + static void act_vacation_print -(const struct sieve_action *action ATTR_UNUSED, - const struct sieve_result_print_env *rpenv, bool *keep ATTR_UNUSED) +(const struct sieve_action *action ATTR_UNUSED, + const struct sieve_result_print_env *rpenv, bool *keep ATTR_UNUSED) { - struct act_vacation_context *ctx = + struct act_vacation_context *ctx = (struct act_vacation_context *) action->context; - + sieve_result_action_printf( rpenv, "send vacation message:"); sieve_result_printf(rpenv, " => seconds : %d\n", ctx->seconds); if ( ctx->subject != NULL ) @@ -799,27 +799,27 @@ static void act_vacation_print /* Result execution */ -/* Headers known to be associated with mailing lists +/* Headers known to be associated with mailing lists */ static const char * const _list_headers[] = { "list-id", "list-owner", "list-subscribe", - "list-post", + "list-post", "list-unsubscribe", "list-help", "list-archive", NULL }; -/* Headers that should be searched for the user's own mail address(es) +/* Headers that should be searched for the user's own mail address(es) */ static const char * const _my_address_headers[] = { "to", "cc", "bcc", - "resent-to", + "resent-to", "resent-cc", "resent-bcc", NULL @@ -850,20 +850,20 @@ static inline bool _contains_my_address { const char *const *hdsp = headers; bool result = FALSE; - + while ( *hdsp != NULL && !result ) { const struct message_address *addr; T_BEGIN { - + addr = message_address_parse - (pool_datastack_create(), (const unsigned char *) *hdsp, + (pool_datastack_create(), (const unsigned char *) *hdsp, strlen(*hdsp), 256, FALSE); while ( addr != NULL && !result ) { if (addr->domain != NULL) { - const char *hdr_address; - + const char *hdr_address; + i_assert(addr->mailbox != NULL); hdr_address = t_strconcat(addr->mailbox, "@", addr->domain, NULL); @@ -876,10 +876,10 @@ static inline bool _contains_my_address addr = addr->next; } } T_END; - + hdsp++; } - + return result; } @@ -894,7 +894,7 @@ static bool _contains_8bit(const char *text) return FALSE; } -static bool act_vacation_send +static bool act_vacation_send (const struct sieve_action_exec_env *aenv, struct act_vacation_context *ctx, const char *reply_to, const char *reply_from) { @@ -917,7 +917,7 @@ static bool act_vacation_send /* Make sure we have a subject for our reply */ - if ( ctx->subject == NULL || *(ctx->subject) == '\0' ) { + if ( ctx->subject == NULL || *(ctx->subject) == '\0' ) { if ( mail_get_headers_utf8 (msgdata->mail, "subject", &headers) >= 0 && headers[0] != NULL ) { subject = t_strconcat("Auto: ", headers[0], NULL); @@ -937,35 +937,35 @@ static bool act_vacation_send /* Produce a proper reply */ - rfc2822_header_field_write(f, "X-Sieve", SIEVE_IMPLEMENTATION); + rfc2822_header_field_write(f, "X-Sieve", SIEVE_IMPLEMENTATION); rfc2822_header_field_write(f, "Message-ID", outmsgid); rfc2822_header_field_write(f, "Date", message_date_create(ioloop_time)); if ( ctx->from != NULL && *(ctx->from) != '\0' ) rfc2822_header_field_utf8_printf(f, "From", "%s", ctx->from); - else if ( reply_from != NULL ) + else if ( reply_from != NULL ) rfc2822_header_field_printf(f, "From", "<%s>", reply_from); else rfc2822_header_field_printf(f, "From", "Postmaster <%s>", senv->postmaster_address); - - /* FIXME: If From header of message has same address, we should use that in + + /* FIXME: If From header of message has same address, we should use that in * stead properly include the phrase part. */ rfc2822_header_field_printf(f, "To", "<%s>", reply_to); if ( _contains_8bit(subject) ) rfc2822_header_field_utf8_printf(f, "Subject", "%s", subject); - else + else rfc2822_header_field_printf(f, "Subject", "%s", subject); /* Compose proper in-reply-to and references headers */ - + ret = mail_get_headers (aenv->msgdata->mail, "references", &headers); - + if ( msgdata->id != NULL ) { rfc2822_header_field_write(f, "In-Reply-To", msgdata->id); - + if ( ret >= 0 && headers[0] != NULL ) rfc2822_header_field_write (f, "References", t_strconcat(headers[0], " ", msgdata->id, NULL)); @@ -974,12 +974,12 @@ static bool act_vacation_send } else if ( ret >= 0 && headers[0] != NULL ) { rfc2822_header_field_write(f, "References", headers[0]); } - + rfc2822_header_field_write(f, "Auto-Submitted", "auto-replied (vacation)"); rfc2822_header_field_write(f, "Precedence", "bulk"); - + rfc2822_header_field_write(f, "MIME-Version", "1.0"); - + if ( !ctx->mime ) { rfc2822_header_field_write(f, "Content-Type", "text/plain; charset=utf-8"); rfc2822_header_field_write(f, "Content-Transfer-Encoding", "8bit"); @@ -988,15 +988,15 @@ static bool act_vacation_send fprintf(f, "%s\r\n", ctx->reason); - /* Close smtp session */ + /* Close smtp session */ if ( !sieve_smtp_close(senv, smtp_handle) ) { - sieve_result_global_error(aenv, + sieve_result_global_error(aenv, "failed to send vacation response to <%s> " - "(refer to server log for more information)", - str_sanitize(reply_to, 128)); + "(refer to server log for more information)", + str_sanitize(reply_to, 128)); return FALSE; } - + return TRUE; } @@ -1010,12 +1010,12 @@ static void act_vacation_hash md5_update(&ctx, rpath, strlen(rpath)); md5_update(&ctx, vctx->handle, strlen(vctx->handle)); - + md5_final(&ctx, hash_r); } static bool act_vacation_commit -(const struct sieve_action *action, const struct sieve_action_exec_env *aenv, +(const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void *tr_context ATTR_UNUSED, bool *keep ATTR_UNUSED) { const struct sieve_extension *ext = action->ext; @@ -1023,7 +1023,7 @@ static bool act_vacation_commit (const struct ext_vacation_config *) ext->context; const struct sieve_message_data *msgdata = aenv->msgdata; const struct sieve_script_env *senv = aenv->scriptenv; - struct act_vacation_context *ctx = + struct act_vacation_context *ctx = (struct act_vacation_context *) action->context; unsigned char dupl_hash[MD5_RESULTLEN]; struct mail *mail = sieve_message_get_mail(aenv->msgctx); @@ -1033,7 +1033,7 @@ static bool act_vacation_commit const char *const *headers; const char *reply_from = NULL; - /* Is the recipient unset? + /* Is the recipient unset? */ if ( recipient == NULL ) { sieve_result_global_warning @@ -1091,16 +1091,16 @@ static bool act_vacation_commit hdsp = _list_headers; while ( *hdsp != NULL ) { if ( mail_get_headers - (mail, *hdsp, &headers) >= 0 && headers[0] != NULL ) { + (mail, *hdsp, &headers) >= 0 && headers[0] != NULL ) { /* Yes, bail out */ - sieve_result_global_log(aenv, - "discarding vacation response to mailinglist recipient <%s>", - str_sanitize(sender, 128)); - return TRUE; + sieve_result_global_log(aenv, + "discarding vacation response to mailinglist recipient <%s>", + str_sanitize(sender, 128)); + return TRUE; } hdsp++; } - + /* Is the message that we are replying to an automatic reply ? */ if ( mail_get_headers (msgdata->mail, "auto-submitted", &headers) >= 0 ) { @@ -1108,15 +1108,15 @@ static bool act_vacation_commit hdsp = headers; while ( *hdsp != NULL ) { if ( strcasecmp(*hdsp, "no") != 0 ) { - sieve_result_global_log(aenv, - "discarding vacation response to auto-submitted message from <%s>", - str_sanitize(sender, 128)); - return TRUE; + sieve_result_global_log(aenv, + "discarding vacation response to auto-submitted message from <%s>", + str_sanitize(sender, 128)); + return TRUE; } hdsp++; } } - + /* Check for the (non-standard) precedence header */ if ( mail_get_headers (mail, "precedence", &headers) >= 0 ) { @@ -1125,10 +1125,10 @@ static bool act_vacation_commit while ( *hdsp != NULL ) { if ( strcasecmp(*hdsp, "junk") == 0 || strcasecmp(*hdsp, "bulk") == 0 || strcasecmp(*hdsp, "list") == 0 ) { - sieve_result_global_log(aenv, - "discarding vacation response to precedence=%s message from <%s>", - *hdsp, str_sanitize(sender, 128)); - return TRUE; + sieve_result_global_log(aenv, + "discarding vacation response to precedence=%s message from <%s>", + *hdsp, str_sanitize(sender, 128)); + return TRUE; } hdsp++; } @@ -1154,7 +1154,7 @@ static bool act_vacation_commit hdsp = _my_address_headers; while ( *hdsp != NULL ) { if ( mail_get_headers - (mail, *hdsp, &headers) >= 0 && headers[0] != NULL ) { + (mail, *hdsp, &headers) >= 0 && headers[0] != NULL ) { if ( _contains_my_address(headers, recipient) ) { reply_from = recipient; @@ -1209,14 +1209,14 @@ static bool act_vacation_commit /* Send the message */ if ( act_vacation_send(aenv, ctx, sender, reply_from) ) { - sieve_number_t seconds; + sieve_number_t seconds; - sieve_result_global_log(aenv, "sent vacation response to <%s>", + sieve_result_global_log(aenv, "sent vacation response to <%s>", str_sanitize(sender, 128)); /* Check period limits once more */ seconds = ctx->seconds; - if ( seconds < config->min_period ) + if ( seconds < config->min_period ) seconds = config->min_period; else if ( config->max_period > 0 && seconds > config->max_period ) seconds = config->max_period; diff --git a/src/lib-sieve/plugins/vacation/ext-vacation-common.c b/src/lib-sieve/plugins/vacation/ext-vacation-common.c index da3eaef0a3daa0f2cd02afea8d28178c1bb86fee..3100f98e4db3511f4c58af7e2ef967ef501aa84f 100644 --- a/src/lib-sieve/plugins/vacation/ext-vacation-common.c +++ b/src/lib-sieve/plugins/vacation/ext-vacation-common.c @@ -37,7 +37,7 @@ bool ext_vacation_load default_period = EXT_VACATION_DEFAULT_PERIOD; } - if ( max_period > 0 + if ( max_period > 0 && (min_period > max_period || default_period < min_period || default_period > max_period) ) { min_period = EXT_VACATION_DEFAULT_MIN_PERIOD; diff --git a/src/lib-sieve/plugins/vacation/ext-vacation-common.h b/src/lib-sieve/plugins/vacation/ext-vacation-common.h index 42c04f1314910eb99dd023a56e04bba9691e0439..6ebdc6b37c88b49c51162f039393162403bed7b0 100644 --- a/src/lib-sieve/plugins/vacation/ext-vacation-common.h +++ b/src/lib-sieve/plugins/vacation/ext-vacation-common.h @@ -13,7 +13,7 @@ #define EXT_VACATION_DEFAULT_PERIOD (7*24*60*60) #define EXT_VACATION_DEFAULT_MIN_PERIOD (24*60*60) #define EXT_VACATION_DEFAULT_MAX_PERIOD 0 - + struct ext_vacation_config { unsigned int min_period; unsigned int max_period; @@ -22,19 +22,19 @@ struct ext_vacation_config { bool dont_check_recipient; }; -/* - * Commands +/* + * Commands */ extern const struct sieve_command_def vacation_command; -/* - * Operations +/* + * Operations */ extern const struct sieve_operation_def vacation_operation; -/* +/* * Extensions */ diff --git a/src/lib-sieve/plugins/vacation/ext-vacation-seconds.c b/src/lib-sieve/plugins/vacation/ext-vacation-seconds.c index 3f1796061e04771bf56b532896d30fcb33e37c67..f21736f632f7bf6f3a1dbfa3775c407982fc03f1 100644 --- a/src/lib-sieve/plugins/vacation/ext-vacation-seconds.c +++ b/src/lib-sieve/plugins/vacation/ext-vacation-seconds.c @@ -29,11 +29,11 @@ bool ext_vacation_seconds_load static bool ext_vacation_seconds_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr); -const struct sieve_extension_def vacation_seconds_extension = { +const struct sieve_extension_def vacation_seconds_extension = { "vacation-seconds", ext_vacation_seconds_load, NULL, - ext_vacation_seconds_validator_load, + ext_vacation_seconds_validator_load, NULL, NULL, NULL, NULL, NULL, SIEVE_EXT_DEFINE_NO_OPERATIONS, SIEVE_EXT_DEFINE_NO_OPERANDS @@ -42,9 +42,9 @@ const struct sieve_extension_def vacation_seconds_extension = { bool ext_vacation_seconds_load (const struct sieve_extension *ext, void **context) { - if ( *context == NULL ) { + if ( *context == NULL ) { /* Make sure vacation extension is registered */ - *context = (void *) + *context = (void *) sieve_extension_require(ext->svinst, &vacation_extension, TRUE); } diff --git a/src/lib-sieve/plugins/vacation/ext-vacation.c b/src/lib-sieve/plugins/vacation/ext-vacation.c index acc156007b2411a2dbf8404b070fadd810a83b05..07f2676bacd30ed947dfc376da2aead5b76e6e0d 100644 --- a/src/lib-sieve/plugins/vacation/ext-vacation.c +++ b/src/lib-sieve/plugins/vacation/ext-vacation.c @@ -31,11 +31,11 @@ static bool ext_vacation_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr); -const struct sieve_extension_def vacation_extension = { +const struct sieve_extension_def vacation_extension = { "vacation", ext_vacation_load, ext_vacation_unload, - ext_vacation_validator_load, + ext_vacation_validator_load, NULL, NULL, NULL, NULL, NULL, SIEVE_EXT_DEFINE_OPERATION(vacation_operation), SIEVE_EXT_DEFINE_NO_OPERANDS diff --git a/src/lib-sieve/plugins/variables/Makefile.am b/src/lib-sieve/plugins/variables/Makefile.am index 59fb0142ba0b81917cc39a1c233eb08ecc5cd7d5..354bad2a6f61404ad58292d235d0a455aae147ad 100644 --- a/src/lib-sieve/plugins/variables/Makefile.am +++ b/src/lib-sieve/plugins/variables/Makefile.am @@ -23,7 +23,7 @@ libsieve_ext_variables_la_SOURCES = \ ext-variables.c public_headers = \ - sieve-ext-variables.h + sieve-ext-variables.h headers = \ ext-variables-common.h \ diff --git a/src/lib-sieve/plugins/variables/cmd-set.c b/src/lib-sieve/plugins/variables/cmd-set.c index 748a43ebeadee17cf122980bb243364eed5d0c03..8654391b50ed8f7bb1aa663b860ebcf502fd88b1 100644 --- a/src/lib-sieve/plugins/variables/cmd-set.c +++ b/src/lib-sieve/plugins/variables/cmd-set.c @@ -22,10 +22,10 @@ #include "ext-variables-limits.h" #include "ext-variables-modifiers.h" -/* - * Set command - * - * Syntax: +/* + * Set command + * + * Syntax: * set [MODIFIER] <name: string> <value: string> */ @@ -39,20 +39,20 @@ static bool cmd_set_validate static bool cmd_set_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx); -const struct sieve_command_def cmd_set = { +const struct sieve_command_def cmd_set = { "set", - SCT_COMMAND, - 2, 0, FALSE, FALSE, + SCT_COMMAND, + 2, 0, FALSE, FALSE, cmd_set_registered, - cmd_set_pre_validate, + cmd_set_pre_validate, cmd_set_validate, - NULL, - cmd_set_generate, - NULL + NULL, + cmd_set_generate, + NULL }; -/* - * Set operation +/* + * Set operation */ static bool cmd_set_operation_dump @@ -60,23 +60,23 @@ static bool cmd_set_operation_dump static int cmd_set_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def cmd_set_operation = { +const struct sieve_operation_def cmd_set_operation = { "SET", &variables_extension, EXT_VARIABLES_OPERATION_SET, - cmd_set_operation_dump, + cmd_set_operation_dump, cmd_set_operation_execute }; -/* - * Compiler context +/* + * Compiler context */ struct cmd_set_context { ARRAY_DEFINE(modifiers, const struct sieve_variables_modifier *); }; -/* +/* * Set modifier tag * * [MODIFIER]: @@ -85,33 +85,33 @@ struct cmd_set_context { */ /* Forward declarations */ - + static bool tag_modifier_is_instance_of (struct sieve_validator *valdtr, struct sieve_command *cmd, const struct sieve_extension *ext, const char *identifier, void **context); static bool tag_modifier_validate - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); /* Modifier tag object */ -const struct sieve_argument_def modifier_tag = { +const struct sieve_argument_def modifier_tag = { "MODIFIER", - tag_modifier_is_instance_of, - tag_modifier_validate, + tag_modifier_is_instance_of, + tag_modifier_validate, NULL, NULL, NULL }; - -/* Modifier tag implementation */ - + +/* Modifier tag implementation */ + static bool tag_modifier_is_instance_of (struct sieve_validator *valdtr, struct sieve_command *cmd, const struct sieve_extension *ext, const char *identifier, void **data) -{ +{ const struct sieve_variables_modifier *modf; if ( data == NULL ) { - return ext_variables_modifier_exists(ext, valdtr, identifier); + return ext_variables_modifier_exists(ext, valdtr, identifier); } if ( (modf=ext_variables_modifier_create_instance @@ -119,45 +119,45 @@ static bool tag_modifier_is_instance_of return FALSE; *data = (void *) modf; - + return TRUE; } static bool tag_modifier_validate -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd) { unsigned int i, modf_count; bool inserted; - const struct sieve_variables_modifier *modf = + const struct sieve_variables_modifier *modf = (const struct sieve_variables_modifier *) (*arg)->argument->data; - const struct sieve_variables_modifier *const *modfs; + const struct sieve_variables_modifier *const *modfs; struct cmd_set_context *sctx = (struct cmd_set_context *) cmd->data; - + inserted = FALSE; modfs = array_get(&sctx->modifiers, &modf_count); for ( i = 0; i < modf_count && !inserted; i++ ) { - + if ( modfs[i]->def->precedence == modf->def->precedence ) { - sieve_argument_validate_error(valdtr, *arg, + sieve_argument_validate_error(valdtr, *arg, "modifiers :%s and :%s specified for the set command conflict " - "having equal precedence", + "having equal precedence", modfs[i]->def->obj_def.identifier, modf->def->obj_def.identifier); return FALSE; } - + if ( modfs[i]->def->precedence < modf->def->precedence ) { array_insert(&sctx->modifiers, i, &modf, 1); inserted = TRUE; } } - + if ( !inserted ) array_append(&sctx->modifiers, &modf, 1); - + /* Added to modifier list; self-destruct to prevent duplicate generation */ *arg = sieve_ast_arguments_detach(*arg, 1); - + return TRUE; } @@ -165,80 +165,80 @@ static bool tag_modifier_validate static bool cmd_set_registered (struct sieve_validator *valdtr, const struct sieve_extension *ext, - struct sieve_command_registration *cmd_reg) + struct sieve_command_registration *cmd_reg) { - sieve_validator_register_tag(valdtr, cmd_reg, ext, &modifier_tag, 0); + sieve_validator_register_tag(valdtr, cmd_reg, ext, &modifier_tag, 0); return TRUE; } -/* - * Command validation +/* + * Command validation */ static bool cmd_set_pre_validate -(struct sieve_validator *valdtr ATTR_UNUSED, +(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *cmd) { pool_t pool = sieve_command_pool(cmd); struct cmd_set_context *sctx = p_new(pool, struct cmd_set_context, 1); - + /* Create an array for the sorted list of modifiers */ p_array_init(&sctx->modifiers, pool, 2); cmd->data = (void *) sctx; - + return TRUE; -} +} -static bool cmd_set_validate(struct sieve_validator *valdtr, - struct sieve_command *cmd) -{ +static bool cmd_set_validate(struct sieve_validator *valdtr, + struct sieve_command *cmd) +{ const struct sieve_extension *this_ext = cmd->ext; struct sieve_ast_argument *arg = cmd->first_positional; - + if ( !sieve_validate_positional_argument (valdtr, cmd, arg, "name", 1, SAAT_STRING) ) { return FALSE; } - + if ( !sieve_variable_argument_activate(this_ext, valdtr, cmd, arg, TRUE) ) { return FALSE; } arg = sieve_ast_argument_next(arg); - + if ( !sieve_validate_positional_argument (valdtr, cmd, arg, "value", 2, SAAT_STRING) ) { return FALSE; } - - return sieve_validator_argument_activate(valdtr, cmd, arg, FALSE); + + return sieve_validator_argument_activate(valdtr, cmd, arg, FALSE); } /* * Code generation */ - + static bool cmd_set_generate - (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) + (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) { const struct sieve_extension *this_ext = cmd->ext; struct sieve_binary_block *sblock = cgenv->sblock; struct cmd_set_context *sctx = (struct cmd_set_context *) cmd->data; const struct sieve_variables_modifier *const *modfs; - unsigned int i, modf_count; + unsigned int i, modf_count; - sieve_operation_emit(sblock, this_ext, &cmd_set_operation); + sieve_operation_emit(sblock, this_ext, &cmd_set_operation); /* Generate arguments */ if ( !sieve_generate_arguments(cgenv, cmd, NULL) ) - return FALSE; - + return FALSE; + /* Generate modifiers (already sorted during validation) */ sieve_binary_emit_byte(sblock, array_count(&sctx->modifiers)); - modfs = array_get(&sctx->modifiers, &modf_count); + modfs = array_get(&sctx->modifiers, &modf_count); for ( i = 0; i < modf_count; i++ ) { ext_variables_opr_modifier_emit(sblock, modfs[i]->object.ext, modfs[i]->def); } @@ -246,43 +246,43 @@ static bool cmd_set_generate return TRUE; } -/* +/* * Code dump */ - + static bool cmd_set_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) -{ +{ unsigned int mdfs, i; - + sieve_code_dumpf(denv, "SET"); sieve_code_descend(denv); - + /* Print both variable name and string value */ if ( !sieve_opr_string_dump(denv, address, "variable") || !sieve_opr_string_dump(denv, address, "value") ) return FALSE; - + /* Read the number of applied modifiers we need to read */ - if ( !sieve_binary_read_byte(denv->sblock, address, &mdfs) ) + if ( !sieve_binary_read_byte(denv->sblock, address, &mdfs) ) return FALSE; - + /* Print all modifiers (sorted during code generation already) */ for ( i = 0; i < mdfs; i++ ) { if ( !ext_variables_opr_modifier_dump(denv, address) ) return FALSE; } - + return TRUE; } -/* +/* * Code execution */ - + static int cmd_set_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) -{ +{ struct sieve_variable_storage *storage; unsigned int var_index, mdfs, i; string_t *value; @@ -291,11 +291,11 @@ static int cmd_set_operation_execute /* * Read the normal operands */ - + if ( (ret=sieve_variable_operand_read (renv, address, "variable", &storage, &var_index)) <= 0 ) return ret; - + if ( (ret=sieve_opr_string_read(renv, address, "string", &value)) <= 0 ) return ret; @@ -303,9 +303,9 @@ static int cmd_set_operation_execute sieve_runtime_trace_error(renv, "invalid modifier count"); return SIEVE_EXEC_BIN_CORRUPT; } - - /* - * Determine and assign the value + + /* + * Determine and assign the value */ sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, "set command"); @@ -321,13 +321,13 @@ static int cmd_set_operation_execute for ( i = 0; i < mdfs; i++ ) { string_t *new_value; struct sieve_variables_modifier modf; - + if ( !ext_variables_opr_modifier_read(renv, address, &modf) ) { value = NULL; ret = SIEVE_EXEC_BIN_CORRUPT; break; } - + if ( modf.def != NULL && modf.def->modify != NULL ) { if ( !modf.def->modify(value, &new_value) ) { value = NULL; @@ -348,8 +348,8 @@ static int cmd_set_operation_execute str_truncate(value, EXT_VARIABLES_MAX_VARIABLE_SIZE); } } - } - + } + /* Actually assign the value if all is well */ if ( value != NULL ) { if ( !sieve_variable_assign(storage, var_index, value) ) @@ -367,8 +367,8 @@ static int cmd_set_operation_execute } } } T_END; - - if ( ret <= 0 ) return ret; + + if ( ret <= 0 ) return ret; if ( value == NULL ) return SIEVE_EXEC_FAILURE; return SIEVE_EXEC_OK; diff --git a/src/lib-sieve/plugins/variables/ext-variables-arguments.c b/src/lib-sieve/plugins/variables/ext-variables-arguments.c index 312df7f7c326ca467b50e745dd8ffcd953d03045..768aa26798dfbd84d1efa36e894e987ebddda8a6 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-arguments.c +++ b/src/lib-sieve/plugins/variables/ext-variables-arguments.c @@ -21,104 +21,104 @@ #include "ext-variables-namespaces.h" #include "ext-variables-arguments.h" -/* +/* * Variable argument implementation */ static bool arg_variable_generate - (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, + (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *context); -const struct sieve_argument_def variable_argument = { - "@variable", +const struct sieve_argument_def variable_argument = { + "@variable", NULL, NULL, NULL, NULL, - arg_variable_generate + arg_variable_generate }; static bool ext_variables_variable_argument_activate -(const struct sieve_extension *this_ext, struct sieve_validator *valdtr, +(const struct sieve_extension *this_ext, struct sieve_validator *valdtr, struct sieve_ast_argument *arg, const char *variable) { struct sieve_ast *ast = arg->ast; struct sieve_variable *var; - + var = ext_variables_validator_get_variable(this_ext, valdtr, variable, TRUE); if ( var == NULL ) { - sieve_argument_validate_error(valdtr, arg, + sieve_argument_validate_error(valdtr, arg, "(implicit) declaration of new variable '%s' exceeds the limit " - "(max variables: %u)", variable, + "(max variables: %u)", variable, EXT_VARIABLES_MAX_SCOPE_SIZE); return FALSE; } - + arg->argument = sieve_argument_create(ast, &variable_argument, this_ext, 0); arg->argument->data = (void *) var; return TRUE; } static struct sieve_ast_argument *ext_variables_variable_argument_create -(const struct sieve_extension *this_ext, struct sieve_validator *valdtr, +(const struct sieve_extension *this_ext, struct sieve_validator *valdtr, struct sieve_ast_argument *parent_arg, const char *variable) { struct sieve_ast *ast = parent_arg->ast; struct sieve_ast_argument *new_arg; - + new_arg = sieve_ast_argument_create(ast, sieve_ast_argument_line(parent_arg)); new_arg->type = SAAT_STRING; if ( !ext_variables_variable_argument_activate (this_ext, valdtr, new_arg, variable) ) return NULL; - + return new_arg; } static bool arg_variable_generate -(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, +(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *context ATTR_UNUSED) { struct sieve_argument *argument = arg->argument; struct sieve_variable *var = (struct sieve_variable *) argument->data; - + sieve_variables_opr_variable_emit(cgenv->sblock, argument->ext, var); return TRUE; } -/* +/* * Match value argument implementation */ static bool arg_match_value_generate -(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, +(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *context ATTR_UNUSED); -const struct sieve_argument_def match_value_argument = { - "@match_value", +const struct sieve_argument_def match_value_argument = { + "@match_value", NULL, NULL, NULL, NULL, - arg_match_value_generate + arg_match_value_generate }; static bool ext_variables_match_value_argument_activate -(const struct sieve_extension *this_ext, - struct sieve_validator *valdtr, struct sieve_ast_argument *arg, +(const struct sieve_extension *this_ext, + struct sieve_validator *valdtr, struct sieve_ast_argument *arg, unsigned int index, bool assignment) { struct sieve_ast *ast = arg->ast; if ( assignment ) { - sieve_argument_validate_error(valdtr, arg, + sieve_argument_validate_error(valdtr, arg, "cannot assign to match variable"); return FALSE; } if ( index > EXT_VARIABLES_MAX_MATCH_INDEX ) { - sieve_argument_validate_error(valdtr, arg, - "match value index %u out of range (max: %u)", index, + sieve_argument_validate_error(valdtr, arg, + "match value index %u out of range (max: %u)", index, EXT_VARIABLES_MAX_MATCH_INDEX); return FALSE; - } + } arg->argument = sieve_argument_create (ast, &match_value_argument, this_ext, 0); @@ -127,12 +127,12 @@ static bool ext_variables_match_value_argument_activate } static struct sieve_ast_argument *ext_variables_match_value_argument_create -(const struct sieve_extension *this_ext, struct sieve_validator *valdtr, +(const struct sieve_extension *this_ext, struct sieve_validator *valdtr, struct sieve_ast_argument *parent_arg, unsigned int index) { struct sieve_ast *ast = parent_arg->ast; struct sieve_ast_argument *new_arg; - + new_arg = sieve_ast_argument_create(ast, sieve_ast_argument_line(parent_arg)); new_arg->type = SAAT_STRING; @@ -140,40 +140,40 @@ static struct sieve_ast_argument *ext_variables_match_value_argument_create (this_ext, valdtr, new_arg, index, FALSE) ) { return NULL; } - + return new_arg; } static bool arg_match_value_generate -(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, +(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *context ATTR_UNUSED) { struct sieve_argument *argument = arg->argument; unsigned int index = POINTER_CAST_TO(argument->data, unsigned int); - + sieve_variables_opr_match_value_emit(cgenv->sblock, argument->ext, index); return TRUE; } -/* +/* * Variable string argument implementation */ static bool arg_variable_string_validate - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); -const struct sieve_argument_def variable_string_argument = { - "@variable-string", +const struct sieve_argument_def variable_string_argument = { + "@variable-string", NULL, - arg_variable_string_validate, - NULL, NULL, + arg_variable_string_validate, + NULL, NULL, sieve_arg_catenated_string_generate, }; static bool arg_variable_string_validate -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd) { const struct sieve_extension *this_ext = (*arg)->argument->ext; @@ -185,13 +185,13 @@ static bool arg_variable_string_validate const char *strval = (const char *) str_data(str); const char *strend = strval + str_len(str); bool result = TRUE; - ARRAY_TYPE(sieve_variable_name) substitution; + ARRAY_TYPE(sieve_variable_name) substitution; int nelements = 0; - + T_BEGIN { /* Initialize substitution structure */ - t_array_init(&substitution, 2); - + t_array_init(&substitution, 2); + p = strval; strstart = p; while ( result && p < strend ) { @@ -211,46 +211,46 @@ static bool arg_variable_string_validate if ( *p == '{' ) { state = ST_VARIABLE; p++; - } else + } else state = ST_NONE; break; - /* Got '${' */ + /* Got '${' */ case ST_VARIABLE: nelements = ext_variable_name_parse(&substitution, &p, strend); - + if ( nelements < 0 ) state = ST_NONE; - else + else state = ST_CLOSE; - + break; /* Finished parsing name, expecting '}' */ case ST_CLOSE: - if ( *p == '}' ) { + if ( *p == '}' ) { struct sieve_ast_argument *strarg; - - /* We now know that the substitution is valid */ - + + /* We now know that the substitution is valid */ + if ( catstr == NULL ) { catstr = sieve_arg_catenated_string_create(*arg); } - - /* Add the substring that is before the substitution to the + + /* Add the substring that is before the substitution to the * variable-string AST. * - * FIXME: For efficiency, if the variable is not found we should + * FIXME: For efficiency, if the variable is not found we should * coalesce this substring with the one after the substitution. */ if ( substart > strstart ) { string_t *newstr = str_new(pool, substart - strstart); - str_append_n(newstr, strstart, substart - strstart); - + str_append_n(newstr, strstart, substart - strstart); + strarg = sieve_ast_argument_string_create_raw ((*arg)->ast, newstr, (*arg)->source_line); sieve_arg_catenated_string_add_element(catstr, strarg); - + /* Give other substitution extensions a chance to do their work */ if ( !sieve_validator_argument_activate_super (valdtr, cmd, strarg, FALSE) ) { @@ -258,12 +258,12 @@ static bool arg_variable_string_validate break; } } - + /* Find the variable */ if ( nelements == 1 ) { - const struct sieve_variable_name *cur_element = + const struct sieve_variable_name *cur_element = array_idx(&substitution, 0); - + if ( cur_element->num_variable == -1 ) { /* Add variable argument '${identifier}' */ @@ -272,13 +272,13 @@ static bool arg_variable_string_validate } else { /* Add match value argument '${000}' */ - + strarg = ext_variables_match_value_argument_create (this_ext, valdtr, *arg, cur_element->num_variable); } } else { strarg = ext_variables_namespace_argument_create - (this_ext, valdtr, *arg, cmd, &substitution); + (this_ext, valdtr, *arg, cmd, &substitution); } if ( strarg != NULL ) { @@ -287,14 +287,14 @@ static bool arg_variable_string_validate result = FALSE; break; } - + strstart = p + 1; substart = strstart; - p++; + p++; } - - /* Finished, reset for the next substitution */ + + /* Finished, reset for the next substitution */ state = ST_NONE; } } @@ -302,7 +302,7 @@ static bool arg_variable_string_validate /* Bail out early if substitution is invalid */ if ( !result ) return FALSE; - + /* Check whether any substitutions were found */ if ( catstr == NULL ) { /* No substitutions in this string, pass it on to any other substution @@ -310,25 +310,25 @@ static bool arg_variable_string_validate */ return sieve_validator_argument_activate_super(valdtr, cmd, *arg, TRUE); } - - /* Add the final substring that comes after the last substitution to the + + /* Add the final substring that comes after the last substitution to the * variable-string AST. */ if ( strend > strstart ) { struct sieve_ast_argument *strarg; string_t *newstr = str_new(pool, strend - strstart); - str_append_n(newstr, strstart, strend - strstart); + str_append_n(newstr, strstart, strend - strstart); strarg = sieve_ast_argument_string_create_raw ((*arg)->ast, newstr, (*arg)->source_line); sieve_arg_catenated_string_add_element(catstr, strarg); - - /* Give other substitution extensions a chance to do their work */ + + /* Give other substitution extensions a chance to do their work */ if ( !sieve_validator_argument_activate_super (valdtr, cmd, strarg, FALSE) ) return FALSE; - } - + } + return TRUE; } @@ -337,7 +337,7 @@ static bool arg_variable_string_validate */ static bool _sieve_variable_argument_activate -(const struct sieve_extension *this_ext, struct sieve_validator *valdtr, +(const struct sieve_extension *this_ext, struct sieve_validator *valdtr, struct sieve_command *cmd, struct sieve_ast_argument *arg, bool assignment) { bool result = FALSE; @@ -357,12 +357,12 @@ static bool _sieve_variable_argument_activate /* Check whether name parsing succeeded */ if ( nelements <= 0 || varstr != varend ) { /* Parse failed */ - sieve_argument_validate_error(valdtr, arg, + sieve_argument_validate_error(valdtr, arg, "invalid variable name '%s'", str_sanitize(str_c(variable),80)); } else if ( nelements == 1 ) { /* Normal (match) variable */ - const struct sieve_variable_name *cur_element = + const struct sieve_variable_name *cur_element = array_idx(&vname, 0); if ( cur_element->num_variable < 0 ) { @@ -371,7 +371,7 @@ static bool _sieve_variable_argument_activate (this_ext, valdtr, arg, str_c(cur_element->identifier)); } else { - /* Match value */ + /* Match value */ result = ext_variables_match_value_argument_activate (this_ext, valdtr, arg, cur_element->num_variable, assignment); } @@ -387,36 +387,36 @@ static bool _sieve_variable_argument_activate } bool sieve_variable_argument_activate -(const struct sieve_extension *this_ext, struct sieve_validator *valdtr, - struct sieve_command *cmd, struct sieve_ast_argument *arg, +(const struct sieve_extension *this_ext, struct sieve_validator *valdtr, + struct sieve_command *cmd, struct sieve_ast_argument *arg, bool assignment) { if ( sieve_ast_argument_type(arg) == SAAT_STRING ) { /* Single string */ return _sieve_variable_argument_activate (this_ext, valdtr, cmd, arg, assignment); - + } else if ( sieve_ast_argument_type(arg) == SAAT_STRING_LIST ) { /* String list */ struct sieve_ast_argument *stritem; - + i_assert ( !assignment ); - + stritem = sieve_ast_strlist_first(arg); while ( stritem != NULL ) { if ( !_sieve_variable_argument_activate (this_ext, valdtr, cmd, stritem, assignment) ) return FALSE; - + stritem = sieve_ast_strlist_next(stritem); } - + arg->argument = sieve_argument_create (arg->ast, &string_list_argument, NULL, 0); - + return TRUE; - } - + } + return FALSE; } diff --git a/src/lib-sieve/plugins/variables/ext-variables-arguments.h b/src/lib-sieve/plugins/variables/ext-variables-arguments.h index de9850e4fc84aa25b126089d8c30757c05839f01..0e90596435ddd3cc420e507496057e25c242130c 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-arguments.h +++ b/src/lib-sieve/plugins/variables/ext-variables-arguments.h @@ -6,20 +6,20 @@ #include "sieve-common.h" -/* - * Variable argument +/* + * Variable argument */ extern const struct sieve_argument_def variable_argument; -/* - * Match value argument +/* + * Match value argument */ extern const struct sieve_argument_def match_value_argument; -/* - * Variable string argument +/* + * Variable string argument */ extern const struct sieve_argument_def variable_string_argument; diff --git a/src/lib-sieve/plugins/variables/ext-variables-common.c b/src/lib-sieve/plugins/variables/ext-variables-common.c index f15910841cf628bad523e95c8d5429300d6cb357..cedcd2eac3d9edfc878271795d5d25706b770a95 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-common.c +++ b/src/lib-sieve/plugins/variables/ext-variables-common.c @@ -30,12 +30,12 @@ */ unsigned int sieve_variables_get_max_scope_size(void) -{ +{ return EXT_VARIABLES_MAX_SCOPE_SIZE; } /* - * Variable scope + * Variable scope */ struct sieve_variable_scope { @@ -56,7 +56,7 @@ struct sieve_variable_scope_binary { unsigned int size; struct sieve_binary_block *sblock; - sieve_size_t address; + sieve_size_t address; }; struct sieve_variable_scope_iter { @@ -65,7 +65,7 @@ struct sieve_variable_scope_iter { }; struct sieve_variable_scope *sieve_variable_scope_create -(struct sieve_instance *svinst, const struct sieve_extension *ext) +(struct sieve_instance *svinst, const struct sieve_extension *ext) { struct sieve_variable_scope *scope; pool_t pool; @@ -81,7 +81,7 @@ struct sieve_variable_scope *sieve_variable_scope_create scope->variables = hash_table_create (default_pool, pool, 0, strcase_hash, (hash_cmp_callback_t *)strcasecmp); p_array_init(&scope->variable_index, pool, 128); - + return scope; } @@ -122,21 +122,21 @@ struct sieve_variable *sieve_variable_scope_declare if ( scope->error_var == NULL ) { new_var->identifier = "@ERROR@"; new_var->index = 0; - + scope->error_var = new_var; return NULL; } return scope->error_var; } - + new_var->identifier = p_strdup(scope->pool, identifier); new_var->index = array_count(&scope->variable_index); hash_table_insert (scope->variables, (void *) new_var->identifier, (void *) new_var); array_append(&scope->variable_index, &new_var, 1); - + return new_var; } @@ -158,15 +158,15 @@ struct sieve_variable *sieve_variable_scope_get_variable struct sieve_variable *sieve_variable_scope_import (struct sieve_variable_scope *scope, struct sieve_variable *var) { - struct sieve_variable *new_var; + struct sieve_variable *new_var; new_var = p_new(scope->pool, struct sieve_variable, 1); memcpy(new_var, var, sizeof(struct sieve_variable)); - + hash_table_insert (scope->variables, (void *) new_var->identifier, (void *) new_var); - - /* Not entered into the index because it is an external variable + + /* Not entered into the index because it is an external variable * (This can be done unlimited; only limited by the size of the external scope) */ @@ -191,8 +191,8 @@ bool sieve_variable_scope_iterate void *key, *value; if ( !hash_table_iterate(iter->hctx, &key, &value) ) - return FALSE; - + return FALSE; + *var_r = (struct sieve_variable *) value; return TRUE; } @@ -226,19 +226,19 @@ struct sieve_variable *sieve_variable_scope_get_indexed (struct sieve_variable_scope *scope, unsigned int index) { struct sieve_variable * const *var; - - if ( index >= array_count(&scope->variable_index) ) + + if ( index >= array_count(&scope->variable_index) ) return NULL; - - var = array_idx(&scope->variable_index, index); - + + var = array_idx(&scope->variable_index, index); + return *var; } /* Scope binary */ struct sieve_variable_scope *sieve_variable_scope_binary_dump -(struct sieve_instance *svinst, const struct sieve_extension *ext, +(struct sieve_instance *svinst, const struct sieve_extension *ext, const struct sieve_dumptime_env *denv, sieve_size_t *address) { struct sieve_variable_scope *local_scope; @@ -246,24 +246,24 @@ struct sieve_variable_scope *sieve_variable_scope_binary_dump sieve_size_t pc; sieve_offset_t end_offset; - /* Read scope size */ + /* Read scope size */ sieve_code_mark(denv); if ( !sieve_binary_read_unsigned(denv->sblock, address, &scope_size) ) return FALSE; - + /* Read offset */ - pc = *address; + pc = *address; if ( !sieve_binary_read_offset(denv->sblock, address, &end_offset) ) return FALSE; - + /* Create scope */ local_scope = sieve_variable_scope_create(svinst, ext); - + /* Read and dump scope itself */ - sieve_code_dumpf(denv, "VARIABLES SCOPE [%u] (end: %08x)", + sieve_code_dumpf(denv, "VARIABLES SCOPE [%u] (end: %08x)", scope_size, (unsigned int) (pc + end_offset)); - + for ( i = 0; i < scope_size; i++ ) { string_t *identifier; @@ -271,12 +271,12 @@ struct sieve_variable_scope *sieve_variable_scope_binary_dump if (!sieve_binary_read_string(denv->sblock, address, &identifier) ) { return FALSE; } - + sieve_code_dumpf(denv, "%3d: '%s'", i, str_c(identifier)); - + (void) sieve_variable_scope_declare(local_scope, str_c(identifier)); } - + return local_scope; } @@ -288,7 +288,7 @@ struct sieve_variable_scope_binary *sieve_variable_scope_binary_create scpbin = p_new(scope->pool, struct sieve_variable_scope_binary, 1); scpbin->scope = scope; - return scpbin; + return scpbin; } void sieve_variable_scope_binary_ref @@ -311,12 +311,12 @@ struct sieve_variable_scope_binary *sieve_variable_scope_binary_read struct sieve_variable_scope *scope; struct sieve_variable_scope_binary *scpbin; unsigned int scope_size; - const char *ext_name = + const char *ext_name = ( ext == NULL ? "variables" : sieve_extension_name(ext) ); sieve_size_t pc; sieve_offset_t end_offset; - /* Read scope size */ + /* Read scope size */ if ( !sieve_binary_read_unsigned(sblock, address, &scope_size) ) { sieve_sys_error (svinst, "%s: variable scope: failed to read size", ext_name); @@ -326,19 +326,19 @@ struct sieve_variable_scope_binary *sieve_variable_scope_binary_read /* Check size limit */ if ( scope_size > EXT_VARIABLES_MAX_SCOPE_SIZE ) { sieve_sys_error(svinst, - "%s: variable scope: size exceeds the limit (%u > %u)", + "%s: variable scope: size exceeds the limit (%u > %u)", ext_name, scope_size, EXT_VARIABLES_MAX_SCOPE_SIZE ); return NULL; } - + /* Read offset */ - pc = *address; + pc = *address; if ( !sieve_binary_read_offset(sblock, address, &end_offset) ) { sieve_sys_error(svinst, "%s: variable scope: failed to read end offset", ext_name); return NULL; } - + /* Create scope */ scope = sieve_variable_scope_create(svinst, ext); @@ -347,8 +347,8 @@ struct sieve_variable_scope_binary *sieve_variable_scope_binary_read scpbin->sblock = sblock; scpbin->address = *address; - *address = pc + end_offset; - + *address = pc + end_offset; + return scpbin; } @@ -357,14 +357,14 @@ struct sieve_variable_scope *sieve_variable_scope_binary_get { const struct sieve_extension *ext = scpbin->scope->ext; struct sieve_instance *svinst = scpbin->scope->svinst; - const char *ext_name = + const char *ext_name = ( ext == NULL ? "variables" : sieve_extension_name(ext) ); unsigned int i; - + if ( scpbin->sblock != NULL ) { sieve_size_t *address = &scpbin->address; - /* Read scope itself */ + /* Read scope itself */ for ( i = 0; i < scpbin->size; i++ ) { struct sieve_variable *var; string_t *identifier; @@ -374,7 +374,7 @@ struct sieve_variable_scope *sieve_variable_scope_binary_get "%s: variable scope: failed to read variable name", ext_name); return NULL; } - + var = sieve_variable_scope_declare(scpbin->scope, str_c(identifier)); i_assert( var != NULL ); @@ -383,21 +383,21 @@ struct sieve_variable_scope *sieve_variable_scope_binary_get scpbin->sblock = NULL; } - + return scpbin->scope; } unsigned int sieve_variable_scope_binary_get_size (struct sieve_variable_scope_binary *scpbin) { - if ( scpbin->sblock != NULL ) + if ( scpbin->sblock != NULL ) return scpbin->size; return array_count(&scpbin->scope->variable_index); } -/* - * Variable storage +/* + * Variable storage */ struct sieve_variable_storage { @@ -405,21 +405,21 @@ struct sieve_variable_storage { struct sieve_variable_scope *scope; struct sieve_variable_scope_binary *scope_bin; unsigned int max_size; - ARRAY_DEFINE(var_values, string_t *); + ARRAY_DEFINE(var_values, string_t *); }; struct sieve_variable_storage *sieve_variable_storage_create (pool_t pool, struct sieve_variable_scope_binary *scpbin) { struct sieve_variable_storage *storage; - + storage = p_new(pool, struct sieve_variable_storage, 1); storage->pool = pool; storage->scope_bin = scpbin; storage->scope = NULL; - + storage->max_size = sieve_variable_scope_binary_get_size(scpbin); - + p_array_init(&storage->var_values, pool, 4); return storage; @@ -435,7 +435,7 @@ static inline bool sieve_variable_valid } bool sieve_variable_get_identifier -(struct sieve_variable_storage *storage, unsigned int index, +(struct sieve_variable_storage *storage, unsigned int index, const char **identifier) { struct sieve_variable * const *var; @@ -480,44 +480,44 @@ bool sieve_variable_get (struct sieve_variable_storage *storage, unsigned int index, string_t **value) { *value = NULL; - + if ( index < array_count(&storage->var_values) ) { string_t * const *varent; - + varent = array_idx(&storage->var_values, index); - + *value = *varent; } else if ( !sieve_variable_valid(storage, index) ) return FALSE; return TRUE; -} +} bool sieve_variable_get_modifiable (struct sieve_variable_storage *storage, unsigned int index, string_t **value) { string_t *dummy; - + if ( value == NULL ) value = &dummy; - + if ( !sieve_variable_get(storage, index, value) ) return FALSE; - + if ( *value == NULL ) { *value = str_new(storage->pool, 256); - array_idx_set(&storage->var_values, index, value); + array_idx_set(&storage->var_values, index, value); } - return TRUE; + return TRUE; } bool sieve_variable_assign -(struct sieve_variable_storage *storage, unsigned int index, +(struct sieve_variable_storage *storage, unsigned int index, const string_t *value) { string_t *varval; - - if ( !sieve_variable_get_modifiable(storage, index, &varval) ) + + if ( !sieve_variable_get_modifiable(storage, index, &varval) ) return FALSE; str_truncate(varval, 0); @@ -535,7 +535,7 @@ bool sieve_variable_assign */ static void ext_variables_ast_free -(const struct sieve_extension *ext ATTR_UNUSED, +(const struct sieve_extension *ext ATTR_UNUSED, struct sieve_ast *ast ATTR_UNUSED, void *context) { struct sieve_variable_scope *local_scope = @@ -568,22 +568,22 @@ static struct sieve_variable_scope *ext_variables_ast_get_local_scope { struct sieve_variable_scope *local_scope = (struct sieve_variable_scope *) sieve_ast_extension_get_context(ast, this_ext); - + return local_scope; } /* - * Validator context + * Validator context */ static struct ext_variables_validator_context * ext_variables_validator_context_create (const struct sieve_extension *this_ext, struct sieve_validator *valdtr) -{ +{ pool_t pool = sieve_validator_pool(valdtr); struct ext_variables_validator_context *ctx; struct sieve_ast *ast = sieve_validator_ast(valdtr); - + ctx = p_new(pool, struct ext_variables_validator_context, 1); ctx->modifiers = sieve_validator_object_registry_create(valdtr); ctx->namespaces = sieve_validator_object_registry_create(valdtr); @@ -596,14 +596,14 @@ ext_variables_validator_context_create struct ext_variables_validator_context *ext_variables_validator_context_get (const struct sieve_extension *this_ext, struct sieve_validator *valdtr) { - struct ext_variables_validator_context *ctx = + struct ext_variables_validator_context *ctx = (struct ext_variables_validator_context *) sieve_validator_extension_get_context(valdtr, this_ext); - + if ( ctx == NULL ) { ctx = ext_variables_validator_context_create(this_ext, valdtr); } - + return ctx; } @@ -611,51 +611,51 @@ void ext_variables_validator_initialize (const struct sieve_extension *this_ext, struct sieve_validator *valdtr) { struct ext_variables_validator_context *ctx; - + /* Create our context */ ctx = ext_variables_validator_context_get(this_ext, valdtr); - + ext_variables_register_core_modifiers(this_ext, ctx); - + ctx->active = TRUE; } struct sieve_variable *ext_variables_validator_get_variable -(const struct sieve_extension *this_ext, struct sieve_validator *validator, +(const struct sieve_extension *this_ext, struct sieve_validator *validator, const char *variable, bool declare) { - struct ext_variables_validator_context *ctx = + struct ext_variables_validator_context *ctx = ext_variables_validator_context_get(this_ext, validator); - + return sieve_variable_scope_get_variable(ctx->local_scope, variable, declare); } struct sieve_variable_scope *sieve_ext_variables_get_local_scope (const struct sieve_extension *var_ext, struct sieve_validator *validator) { - struct ext_variables_validator_context *ctx = + struct ext_variables_validator_context *ctx = ext_variables_validator_context_get(var_ext, validator); - + return ctx->local_scope; } bool sieve_ext_variables_is_active (const struct sieve_extension *var_ext, struct sieve_validator *valdtr) { - struct ext_variables_validator_context *ctx = + struct ext_variables_validator_context *ctx = ext_variables_validator_context_get(var_ext, valdtr); - + return ( ctx != NULL && ctx->active ); } /* * Code generation */ - + bool ext_variables_generator_load (const struct sieve_extension *ext, const struct sieve_codegen_env *cgenv) { - struct sieve_variable_scope *local_scope = + struct sieve_variable_scope *local_scope = ext_variables_ast_get_local_scope(ext, cgenv->ast); unsigned int count = sieve_variable_scope_size(local_scope); sieve_size_t jump; @@ -666,21 +666,21 @@ bool ext_variables_generator_load if ( count > 0 ) { unsigned int size, i; - struct sieve_variable *const *vars = + struct sieve_variable *const *vars = sieve_variable_scope_get_variables(local_scope, &size); - for ( i = 0; i < size; i++ ) { + for ( i = 0; i < size; i++ ) { sieve_binary_emit_cstring(cgenv->sblock, vars[i]->identifier); } } - + sieve_binary_resolve_offset(cgenv->sblock, jump); - + return TRUE; } -/* - * Interpreter context +/* + * Interpreter context */ struct ext_variables_interpreter_context { @@ -697,7 +697,7 @@ static void ext_variables_interpreter_free (const struct sieve_extension *ext ATTR_UNUSED, struct sieve_interpreter *interp ATTR_UNUSED, void *context) { - struct ext_variables_interpreter_context *ctx = + struct ext_variables_interpreter_context *ctx = (struct ext_variables_interpreter_context *)context; sieve_variable_scope_binary_unref(&ctx->local_scope_bin); @@ -711,18 +711,18 @@ static struct sieve_interpreter_extension variables_interpreter_extension = { static struct ext_variables_interpreter_context * ext_variables_interpreter_context_create -(const struct sieve_extension *this_ext, struct sieve_interpreter *interp, +(const struct sieve_extension *this_ext, struct sieve_interpreter *interp, struct sieve_variable_scope_binary *scpbin) -{ +{ pool_t pool = sieve_interpreter_pool(interp); struct ext_variables_interpreter_context *ctx; - + ctx = p_new(pool, struct ext_variables_interpreter_context, 1); ctx->pool = pool; ctx->local_scope = NULL; ctx->local_scope_bin = scpbin; ctx->local_storage = sieve_variable_storage_create(pool, scpbin); - p_array_init(&ctx->ext_storages, pool, + p_array_init(&ctx->ext_storages, pool, sieve_extensions_get_count(this_ext->svinst)); sieve_interpreter_extension_register @@ -732,7 +732,7 @@ ext_variables_interpreter_context_create } bool ext_variables_interpreter_load -(const struct sieve_extension *ext, const struct sieve_runtime_env *renv, +(const struct sieve_extension *ext, const struct sieve_runtime_env *renv, sieve_size_t *address) { struct sieve_variable_scope_binary *scpbin; @@ -761,13 +761,13 @@ ext_variables_interpreter_context_get } struct sieve_variable_storage *sieve_ext_variables_runtime_get_storage -(const struct sieve_extension *var_ext, const struct sieve_runtime_env *renv, +(const struct sieve_extension *var_ext, const struct sieve_runtime_env *renv, const struct sieve_extension *ext) { - struct ext_variables_interpreter_context *ctx = + struct ext_variables_interpreter_context *ctx = ext_variables_interpreter_context_get(var_ext, renv->interp); struct sieve_variable_storage * const *storage; - + if ( ext == NULL ) return ctx->local_storage; @@ -776,9 +776,9 @@ struct sieve_variable_storage *sieve_ext_variables_runtime_get_storage } else { storage = array_idx(&ctx->ext_storages, ext->id); } - + if ( storage == NULL ) return NULL; - + return *storage; } @@ -786,14 +786,14 @@ void sieve_ext_variables_runtime_set_storage (const struct sieve_extension *var_ext, const struct sieve_runtime_env *renv, const struct sieve_extension *ext, struct sieve_variable_storage *storage) { - struct ext_variables_interpreter_context *ctx = + struct ext_variables_interpreter_context *ctx = ext_variables_interpreter_context_get(var_ext, renv->interp); - + if ( ctx == NULL || ext == NULL || storage == NULL ) return; if ( ext->id < 0 ) return; - + array_idx_set(&ctx->ext_storages, (unsigned int) ext->id, &storage); } diff --git a/src/lib-sieve/plugins/variables/ext-variables-common.h b/src/lib-sieve/plugins/variables/ext-variables-common.h index c3a16e7c570870c230aee16d0b6d1ff504c08e75..e55adcc09c5f1f2ec458f0fdd8028e7c898472ef 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-common.h +++ b/src/lib-sieve/plugins/variables/ext-variables-common.h @@ -15,14 +15,14 @@ extern const struct sieve_extension_def variables_extension; -/* - * Commands +/* + * Commands */ extern const struct sieve_command_def cmd_set; extern const struct sieve_command_def tst_string; -/* +/* * Operands */ @@ -45,42 +45,42 @@ enum ext_variables_opcode { EXT_VARIABLES_OPERATION_STRING }; -/* - * Validator context +/* + * Validator context */ struct ext_variables_validator_context { bool active; - + struct sieve_validator_object_registry *modifiers; struct sieve_validator_object_registry *namespaces; - + struct sieve_variable_scope *local_scope; }; void ext_variables_validator_initialize (const struct sieve_extension *this_ext, struct sieve_validator *validator); - + struct ext_variables_validator_context *ext_variables_validator_context_get (const struct sieve_extension *this_ext, struct sieve_validator *valdtr); struct sieve_variable *ext_variables_validator_get_variable - (const struct sieve_extension *this_ext, struct sieve_validator *validator, + (const struct sieve_extension *this_ext, struct sieve_validator *validator, const char *variable, bool declare); /* * Code generation */ - + bool ext_variables_generator_load (const struct sieve_extension *ext, const struct sieve_codegen_env *cgenv); /* * Interpreter context - */ + */ bool ext_variables_interpreter_load - (const struct sieve_extension *ext, const struct sieve_runtime_env *renv, + (const struct sieve_extension *ext, const struct sieve_runtime_env *renv, sieve_size_t *address); - + #endif /* __EXT_VARIABLES_COMMON_H */ diff --git a/src/lib-sieve/plugins/variables/ext-variables-dump.c b/src/lib-sieve/plugins/variables/ext-variables-dump.c index c15db9fb027cc366e60482c41c6c8d206ad8fd21..2b624fb731c79d3aeb9313369f35feb2bb5a697d 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-dump.c +++ b/src/lib-sieve/plugins/variables/ext-variables-dump.c @@ -1,9 +1,9 @@ /* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #include "lib.h" #include "str.h" - + #include "sieve-common.h" #include "sieve-dump.h" #include "sieve-binary.h" @@ -27,7 +27,7 @@ const struct sieve_code_dumper_extension variables_dump_extension = { /* * Code dump context */ - + struct ext_variables_dump_context { struct sieve_variable_scope *local_scope; ARRAY_DEFINE(ext_scopes, struct sieve_variable_scope *); @@ -36,7 +36,7 @@ struct ext_variables_dump_context { static void ext_variables_code_dumper_free (struct sieve_code_dumper *dumper ATTR_UNUSED, void *context) { - struct ext_variables_dump_context *dctx = + struct ext_variables_dump_context *dctx = (struct ext_variables_dump_context *) context; if ( dctx == NULL || dctx->local_scope == NULL ) @@ -57,17 +57,17 @@ static struct ext_variables_dump_context *ext_variables_dump_get_context /* Create dumper context */ pool = sieve_code_dumper_pool(dumper); dctx = p_new(pool, struct ext_variables_dump_context, 1); - p_array_init(&dctx->ext_scopes, pool, + p_array_init(&dctx->ext_scopes, pool, sieve_extensions_get_count(this_ext->svinst)); - + sieve_dump_extension_set_context(dumper, this_ext, dctx); } return dctx; -} - +} + bool ext_variables_code_dump -(const struct sieve_extension *ext, +(const struct sieve_extension *ext, const struct sieve_dumptime_env *denv, sieve_size_t *address) { struct ext_variables_dump_context *dctx; @@ -75,10 +75,10 @@ bool ext_variables_code_dump local_scope = sieve_variable_scope_binary_dump (ext->svinst, NULL, denv, address); - + dctx = ext_variables_dump_get_context(ext, denv); dctx->local_scope = local_scope; - + return TRUE; } @@ -90,12 +90,12 @@ void sieve_ext_variables_dump_set_scope (const struct sieve_extension *var_ext, const struct sieve_dumptime_env *denv, const struct sieve_extension *ext, struct sieve_variable_scope *scope) { - struct ext_variables_dump_context *dctx = + struct ext_variables_dump_context *dctx = ext_variables_dump_get_context(var_ext, denv); if ( ext->id < 0 ) return; - array_idx_set(&dctx->ext_scopes, (unsigned int) ext->id, &scope); + array_idx_set(&dctx->ext_scopes, (unsigned int) ext->id, &scope); } /* @@ -107,7 +107,7 @@ const char *ext_variables_dump_get_identifier const struct sieve_extension *ext, unsigned int index) { struct ext_variables_dump_context *dctx = - ext_variables_dump_get_context(var_ext, denv); + ext_variables_dump_get_context(var_ext, denv); struct sieve_variable_scope *scope; struct sieve_variable *var; @@ -118,16 +118,16 @@ const char *ext_variables_dump_get_identifier if ( ext->id < 0 || ext->id >= (int) array_count(&dctx->ext_scopes) ) return NULL; - + ext_scope = array_idx(&dctx->ext_scopes, (unsigned int) ext->id); - scope = *ext_scope; + scope = *ext_scope; } if ( scope == NULL ) return NULL; - + var = sieve_variable_scope_get_indexed(scope, index); - + return var->identifier; } diff --git a/src/lib-sieve/plugins/variables/ext-variables-dump.h b/src/lib-sieve/plugins/variables/ext-variables-dump.h index d7f3b1f7d5b364d33352ddeceb7a92f6c88b8f36..37a0d36906768f45c0070e0f7f271b415bdd356f 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-dump.h +++ b/src/lib-sieve/plugins/variables/ext-variables-dump.h @@ -9,7 +9,7 @@ /* * Code dump context */ - + bool ext_variables_code_dump (const struct sieve_extension *ext, const struct sieve_dumptime_env *denv, sieve_size_t *address); @@ -17,7 +17,7 @@ bool ext_variables_code_dump /* * Variable identifier dump */ - + const char *ext_variables_dump_get_identifier (const struct sieve_extension *var_ext, const struct sieve_dumptime_env *denv, const struct sieve_extension *ext, unsigned int index); diff --git a/src/lib-sieve/plugins/variables/ext-variables-limits.h b/src/lib-sieve/plugins/variables/ext-variables-limits.h index e286e79b27c2864480daf91319b4d379d3531002..05bf3f0a689d41116cafde9570f9e23f1c5b853e 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-limits.h +++ b/src/lib-sieve/plugins/variables/ext-variables-limits.h @@ -7,7 +7,7 @@ #include "sieve-limits.h" /* From RFC 5229: - * + * * 6. Implementation Limits * * An implementation of this document MUST support at least 128 distinct diff --git a/src/lib-sieve/plugins/variables/ext-variables-modifiers.c b/src/lib-sieve/plugins/variables/ext-variables-modifiers.c index 12270429bd05002a98d8c096773b1de788c02d14..27ef2f51495126a0e8390ad335bd26d1b67a9322 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-modifiers.c +++ b/src/lib-sieve/plugins/variables/ext-variables-modifiers.c @@ -17,7 +17,7 @@ /* * Core modifiers */ - + extern const struct sieve_variables_modifier_def lower_modifier; extern const struct sieve_variables_modifier_def upper_modifier; extern const struct sieve_variables_modifier_def lowerfirst_modifier; @@ -60,19 +60,19 @@ const unsigned int ext_variables_core_modifiers_count = void sieve_variables_modifier_register (const struct sieve_extension *var_ext, struct sieve_validator *valdtr, const struct sieve_extension *ext, - const struct sieve_variables_modifier_def *smodf_def) + const struct sieve_variables_modifier_def *smodf_def) { - struct ext_variables_validator_context *ctx = + struct ext_variables_validator_context *ctx = ext_variables_validator_context_get(var_ext, valdtr); - + sieve_validator_object_registry_add(ctx->modifiers, ext, &smodf_def->obj_def); } bool ext_variables_modifier_exists (const struct sieve_extension *var_ext, struct sieve_validator *valdtr, - const char *identifier) + const char *identifier) { - struct ext_variables_validator_context *ctx = + struct ext_variables_validator_context *ctx = ext_variables_validator_context_get(var_ext, valdtr); return sieve_validator_object_registry_find(ctx->modifiers, identifier, NULL); @@ -80,9 +80,9 @@ bool ext_variables_modifier_exists const struct sieve_variables_modifier *ext_variables_modifier_create_instance (const struct sieve_extension *var_ext, struct sieve_validator *valdtr, - struct sieve_command *cmd, const char *identifier) + struct sieve_command *cmd, const char *identifier) { - struct ext_variables_validator_context *ctx = + struct ext_variables_validator_context *ctx = ext_variables_validator_context_get(var_ext, valdtr); struct sieve_object object; struct sieve_variables_modifier *modf; @@ -104,7 +104,7 @@ void ext_variables_register_core_modifiers (const struct sieve_extension *ext, struct ext_variables_validator_context *ctx) { unsigned int i; - + /* Register core modifiers*/ for ( i = 0; i < ext_variables_core_modifiers_count; i++ ) { sieve_validator_object_registry_add @@ -115,25 +115,25 @@ void ext_variables_register_core_modifiers /* * Modifier coding */ - -const struct sieve_operand_class sieve_variables_modifier_operand_class = + +const struct sieve_operand_class sieve_variables_modifier_operand_class = { "modifier" }; - + static const struct sieve_extension_objects core_modifiers = SIEVE_VARIABLES_DEFINE_MODIFIERS(ext_variables_core_modifiers); -const struct sieve_operand_def modifier_operand = { - "modifier", +const struct sieve_operand_def modifier_operand = { + "modifier", &variables_extension, - EXT_VARIABLES_OPERAND_MODIFIER, + EXT_VARIABLES_OPERAND_MODIFIER, &sieve_variables_modifier_operand_class, &core_modifiers }; -/* - * Core modifiers +/* + * Core modifiers */ - + /* Forward declarations */ bool mod_lower_modify(string_t *in, string_t **result); @@ -189,10 +189,10 @@ const struct sieve_variables_modifier_def length_modifier = { bool mod_upperfirst_modify(string_t *in, string_t **result) { char *content; - + *result = t_str_new(str_len(in)); str_append_str(*result, in); - + content = str_c_modifiable(*result); content[0] = i_toupper(content[0]); @@ -202,10 +202,10 @@ bool mod_upperfirst_modify(string_t *in, string_t **result) bool mod_lowerfirst_modify(string_t *in, string_t **result) { char *content; - + *result = t_str_new(str_len(in)); str_append_str(*result, in); - + content = str_c_modifiable(*result); content[0] = i_tolower(content[0]); @@ -215,20 +215,20 @@ bool mod_lowerfirst_modify(string_t *in, string_t **result) bool mod_upper_modify(string_t *in, string_t **result) { char *content; - + *result = t_str_new(str_len(in)); str_append_str(*result, in); content = str_c_modifiable(*result); (void)str_ucase(content); - + return TRUE; } bool mod_lower_modify(string_t *in, string_t **result) { char *content; - + *result = t_str_new(str_len(in)); str_append_str(*result, in); @@ -241,7 +241,7 @@ bool mod_lower_modify(string_t *in, string_t **result) bool mod_length_modify(string_t *in, string_t **result) { *result = t_str_new(64); - str_printfa(*result, "%llu", (unsigned long long) + str_printfa(*result, "%llu", (unsigned long long) uni_utf8_strlen_n(str_data(in), str_len(in))); return TRUE; } @@ -250,17 +250,17 @@ bool mod_quotewildcard_modify(string_t *in, string_t **result) { unsigned int i; const char *content; - + *result = t_str_new(str_len(in) * 2); content = (const char *) str_data(in); - + for ( i = 0; i < str_len(in); i++ ) { if ( content[i] == '*' || content[i] == '?' || content[i] == '\\' ) { str_append_c(*result, '\\'); } str_append_c(*result, content[i]); } - + return TRUE; } diff --git a/src/lib-sieve/plugins/variables/ext-variables-modifiers.h b/src/lib-sieve/plugins/variables/ext-variables-modifiers.h index 41650222882fb645103956e67fb0a5d06217c95c..f4a52b3b9f4e7502138a6c1ae6e4a40114585506 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-modifiers.h +++ b/src/lib-sieve/plugins/variables/ext-variables-modifiers.h @@ -24,11 +24,11 @@ bool ext_variables_modifier_exists const struct sieve_variables_modifier *ext_variables_modifier_create_instance (const struct sieve_extension *var_ext, struct sieve_validator *valdtr, struct sieve_command *cmd, const char *identifier); - + void ext_variables_register_core_modifiers (const struct sieve_extension *var_ext, struct ext_variables_validator_context *ctx); - + /* * Modifier operand */ @@ -38,7 +38,7 @@ extern const struct sieve_operand_def modifier_operand; static inline void ext_variables_opr_modifier_emit (struct sieve_binary_block *sblock, const struct sieve_extension *ext, const struct sieve_variables_modifier_def *modf_def) -{ +{ sieve_opr_object_emit(sblock, ext, &modf_def->obj_def); } @@ -62,5 +62,5 @@ static inline bool ext_variables_opr_modifier_dump return sieve_opr_object_dump (denv, &sieve_variables_modifier_operand_class, address, NULL); } - + #endif /* __EXT_VARIABLES_MODIFIERS_H */ diff --git a/src/lib-sieve/plugins/variables/ext-variables-name.h b/src/lib-sieve/plugins/variables/ext-variables-name.h index e72eacf8698d571d9278a1b315d6c68f46c7ce1d..0d9ea30c69a2adfe92d7b9e6e912ebaaced6f80b 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-name.h +++ b/src/lib-sieve/plugins/variables/ext-variables-name.h @@ -6,17 +6,17 @@ /* Variable Substitution * --------------------- - * - * The variable strings are preprocessed into an AST list consisting of variable + * + * The variable strings are preprocessed into an AST list consisting of variable * substitutions and constant parts of the string. The variables to which * the substitutions link are looked up and their index in their scope storage - * is what is added to the list and eventually emitted as byte code. So, in + * is what is added to the list and eventually emitted as byte code. So, in * bytecode a variable string will look as a series of substrings interrupted by - * integer operands that refer to variables. During execution, the strings and - * the looked-up variables are concatenated to obtain the desired result. The + * integer operands that refer to variables. During execution, the strings and + * the looked-up variables are concatenated to obtain the desired result. The * the variable references are simple indexes into an array of variables, so * looking these up during execution is a trivial process. - * + * * However (RFC 5229): * Tests or actions in future extensions may need to access the * unexpanded version of the string argument and, e.g., do the expansion @@ -26,7 +26,7 @@ * Various options exist to provide this feature. If the extension is entirely * namespace-based there is actually not very much of a problem. The variable * list can easily be extended with new argument-types that refer to a variable - * identifier in stead of an index in the variable's storage. + * identifier in stead of an index in the variable's storage. */ #include "lib.h" @@ -39,7 +39,7 @@ /* * Variable name parsing */ - + int ext_variable_name_parse (ARRAY_TYPE(sieve_variable_name) *vname, const char **str, const char *strend); diff --git a/src/lib-sieve/plugins/variables/ext-variables-namespaces.c b/src/lib-sieve/plugins/variables/ext-variables-namespaces.c index 03684179da4626de1bdd6cc907c46a33fabb5360..ebf42794684efdbc25d981d6a1f612ba578084e7 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-namespaces.c +++ b/src/lib-sieve/plugins/variables/ext-variables-namespaces.c @@ -19,19 +19,19 @@ void sieve_variables_namespace_register (const struct sieve_extension *var_ext, struct sieve_validator *valdtr, const struct sieve_extension *ext, - const struct sieve_variables_namespace_def *nspc_def) + const struct sieve_variables_namespace_def *nspc_def) { - struct ext_variables_validator_context *ctx = + struct ext_variables_validator_context *ctx = ext_variables_validator_context_get(var_ext, valdtr); - + sieve_validator_object_registry_add(ctx->namespaces, ext, &nspc_def->obj_def); } bool ext_variables_namespace_exists (const struct sieve_extension *var_ext, struct sieve_validator *valdtr, - const char *identifier) + const char *identifier) { - struct ext_variables_validator_context *ctx = + struct ext_variables_validator_context *ctx = ext_variables_validator_context_get(var_ext, valdtr); return sieve_validator_object_registry_find @@ -40,9 +40,9 @@ bool ext_variables_namespace_exists const struct sieve_variables_namespace *ext_variables_namespace_create_instance (const struct sieve_extension *var_ext, struct sieve_validator *valdtr, - struct sieve_command *cmd, const char *identifier) + struct sieve_command *cmd, const char *identifier) { - struct ext_variables_validator_context *ctx = + struct ext_variables_validator_context *ctx = ext_variables_validator_context_get(var_ext, valdtr); struct sieve_object object; struct sieve_variables_namespace *nspc; @@ -71,18 +71,18 @@ struct arg_namespace_variable { }; static bool arg_namespace_generate -(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, +(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *context ATTR_UNUSED); -const struct sieve_argument_def namespace_argument = { - "@namespace", +const struct sieve_argument_def namespace_argument = { + "@namespace", NULL, NULL, NULL, NULL, - arg_namespace_generate + arg_namespace_generate }; bool ext_variables_namespace_argument_activate (const struct sieve_extension *this_ext, struct sieve_validator *valdtr, - struct sieve_ast_argument *arg, struct sieve_command *cmd, + struct sieve_ast_argument *arg, struct sieve_command *cmd, ARRAY_TYPE(sieve_variable_name) *var_name, bool assignment) { pool_t pool = sieve_command_pool(cmd); @@ -95,8 +95,8 @@ bool ext_variables_namespace_argument_activate nspc = ext_variables_namespace_create_instance (this_ext, valdtr, cmd, str_c(name_element->identifier)); if ( nspc == NULL ) { - sieve_argument_validate_error(valdtr, arg, - "referring to variable in unknown namespace '%s'", + sieve_argument_validate_error(valdtr, arg, + "referring to variable in unknown namespace '%s'", str_c(name_element->identifier)); return FALSE; } @@ -110,16 +110,16 @@ bool ext_variables_namespace_argument_activate var = p_new(pool, struct arg_namespace_variable, 1); var->namespace = nspc; var->data = var_data; - + arg->argument = sieve_argument_create(ast, &namespace_argument, this_ext, 0); arg->argument->data = (void *) var; - + return TRUE; } struct sieve_ast_argument *ext_variables_namespace_argument_create -(const struct sieve_extension *this_ext, - struct sieve_validator *valdtr, struct sieve_ast_argument *parent_arg, +(const struct sieve_extension *this_ext, + struct sieve_validator *valdtr, struct sieve_ast_argument *parent_arg, struct sieve_command *cmd, ARRAY_TYPE(sieve_variable_name) *var_name) { struct sieve_ast *ast = parent_arg->ast; @@ -127,20 +127,20 @@ struct sieve_ast_argument *ext_variables_namespace_argument_create new_arg = sieve_ast_argument_create(ast, sieve_ast_argument_line(parent_arg)); new_arg->type = SAAT_STRING; - + if ( !ext_variables_namespace_argument_activate (this_ext, valdtr, new_arg, cmd, var_name, FALSE) ) return NULL; - + return new_arg; } static bool arg_namespace_generate -(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, +(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *cmd) { struct sieve_argument *argument = arg->argument; - struct arg_namespace_variable *var = + struct arg_namespace_variable *var = (struct arg_namespace_variable *) argument->data; const struct sieve_variables_namespace *nspc = var->namespace; @@ -154,7 +154,7 @@ static bool arg_namespace_generate * Namespace variable operands */ -const struct sieve_operand_class sieve_variables_namespace_operand_class = +const struct sieve_operand_class sieve_variables_namespace_operand_class = { "variable-namespace" }; static bool opr_namespace_variable_dump @@ -164,14 +164,14 @@ static int opr_namespace_variable_read (const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd, sieve_size_t *address, string_t **str_r); -static const struct sieve_opr_string_interface namespace_variable_interface = { +static const struct sieve_opr_string_interface namespace_variable_interface = { opr_namespace_variable_dump, opr_namespace_variable_read }; - -const struct sieve_operand_def namespace_variable_operand = { - "namespace", - &variables_extension, + +const struct sieve_operand_def namespace_variable_operand = { + "namespace", + &variables_extension, EXT_VARIABLES_OPERAND_NAMESPACE_VARIABLE, &string_class, &namespace_variable_interface @@ -181,7 +181,7 @@ void sieve_variables_opr_namespace_variable_emit (struct sieve_binary_block *sblock, const struct sieve_extension *var_ext, const struct sieve_extension *ext, const struct sieve_variables_namespace_def *nspc_def) -{ +{ sieve_operand_emit(sblock, var_ext, &namespace_variable_operand); sieve_opr_object_emit(sblock, ext, &nspc_def->obj_def); } @@ -191,14 +191,14 @@ static bool opr_namespace_variable_dump sieve_size_t *address) { struct sieve_variables_namespace nspc; - struct sieve_operand nsoprnd; + struct sieve_operand nsoprnd; if ( !sieve_operand_read(denv->sblock, address, NULL, &nsoprnd) ) { return FALSE; } if ( !sieve_opr_object_read_data - (denv->sblock, &nsoprnd, &sieve_variables_namespace_operand_class, address, + (denv->sblock, &nsoprnd, &sieve_variables_namespace_operand_class, address, &nspc.object) ) { return FALSE; } @@ -228,7 +228,7 @@ static int opr_namespace_variable_read if ( nspc.def == NULL || nspc.def->read_variable == NULL ) return SIEVE_EXEC_FAILURE; - + return nspc.def->read_variable(renv, &nspc, oprnd, address, str_r); } diff --git a/src/lib-sieve/plugins/variables/ext-variables-namespaces.h b/src/lib-sieve/plugins/variables/ext-variables-namespaces.h index 4bffb399526d9514e7ac2690d2e2970453f72941..f3d1325786ed7737bde6078d436a564ccd7eac48 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-namespaces.h +++ b/src/lib-sieve/plugins/variables/ext-variables-namespaces.h @@ -19,7 +19,7 @@ bool ext_variables_namespace_exists const struct sieve_variables_namespace *ext_variables_namespace_create_instance (const struct sieve_extension *var_ext, struct sieve_validator *valdtr, struct sieve_command *cmd, const char *identifier); - + void ext_variables_register_core_namespaces (const struct sieve_extension *var_ext, struct ext_variables_validator_context *ctx); @@ -29,14 +29,14 @@ void ext_variables_register_core_namespaces */ struct sieve_ast_argument *ext_variables_namespace_argument_create - (const struct sieve_extension *this_ext, - struct sieve_validator *valdtr, struct sieve_ast_argument *parent_arg, + (const struct sieve_extension *this_ext, + struct sieve_validator *valdtr, struct sieve_ast_argument *parent_arg, struct sieve_command *cmd, ARRAY_TYPE(sieve_variable_name) *var_name); bool ext_variables_namespace_argument_activate (const struct sieve_extension *this_ext, struct sieve_validator *valdtr, - struct sieve_ast_argument *arg, struct sieve_command *cmd, + struct sieve_ast_argument *arg, struct sieve_command *cmd, ARRAY_TYPE(sieve_variable_name) *var_name, bool assignment); - + /* * Namespace operand */ diff --git a/src/lib-sieve/plugins/variables/ext-variables-operands.c b/src/lib-sieve/plugins/variables/ext-variables-operands.c index 1296a4d07ca515e1511022d0a9a93ff754d30801..9c64976f2c048e2db4a663350ffdca215aae51eb 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-operands.c +++ b/src/lib-sieve/plugins/variables/ext-variables-operands.c @@ -24,8 +24,8 @@ #include "ext-variables-dump.h" #include "ext-variables-operands.h" -/* - * Variable operand +/* + * Variable operand */ static bool opr_variable_dump @@ -35,22 +35,22 @@ static int opr_variable_read_value (const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd, sieve_size_t *address, string_t **str_r); -const struct sieve_opr_string_interface variable_interface = { +const struct sieve_opr_string_interface variable_interface = { opr_variable_dump, opr_variable_read_value }; - -const struct sieve_operand_def variable_operand = { - "variable", - &variables_extension, + +const struct sieve_operand_def variable_operand = { + "variable", + &variables_extension, EXT_VARIABLES_OPERAND_VARIABLE, &string_class, &variable_interface }; void sieve_variables_opr_variable_emit -(struct sieve_binary_block *sblock, const struct sieve_extension *var_ext, - struct sieve_variable *var) +(struct sieve_binary_block *sblock, const struct sieve_extension *var_ext, + struct sieve_variable *var) { if ( var->ext == NULL ) { /* Default variable storage */ @@ -58,7 +58,7 @@ void sieve_variables_opr_variable_emit (void) sieve_binary_emit_byte(sblock, 0); /* Default */ (void) sieve_binary_emit_unsigned(sblock, var->index); return; - } + } (void) sieve_operand_emit(sblock, var_ext, &variable_operand); (void) sieve_binary_emit_extension(sblock, var->ext, 1); /* Extension */ @@ -67,7 +67,7 @@ void sieve_variables_opr_variable_emit static bool opr_variable_dump (const struct sieve_dumptime_env *denv, const struct sieve_operand *oprnd, - sieve_size_t *address) + sieve_size_t *address) { const struct sieve_extension *this_ext = oprnd->ext; unsigned int index = 0; @@ -77,18 +77,18 @@ static bool opr_variable_dump if ( !sieve_binary_read_extension(denv->sblock, address, &code, &ext) ) return FALSE; - + if ( !sieve_binary_read_unsigned(denv->sblock, address, &index) ) return FALSE; - + identifier = ext_variables_dump_get_identifier(this_ext, denv, ext, index); identifier = identifier == NULL ? "??" : identifier; - if ( oprnd->field_name != NULL ) - sieve_code_dumpf(denv, "%s: VAR[%s] ${%s}", + if ( oprnd->field_name != NULL ) + sieve_code_dumpf(denv, "%s: VAR[%s] ${%s}", oprnd->field_name, sieve_ext_variables_get_varid(ext, index), identifier); else - sieve_code_dumpf(denv, "VAR[%s] ${%s}", + sieve_code_dumpf(denv, "VAR[%s] ${%s}", sieve_ext_variables_get_varid(ext, index), identifier); return TRUE; @@ -97,13 +97,13 @@ static bool opr_variable_dump static int opr_variable_read_value (const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd, sieve_size_t *address, string_t **str_r) -{ +{ const struct sieve_extension *this_ext = oprnd->ext; const struct sieve_extension *ext; unsigned int code = 1; /* Initially set to offset value */ struct sieve_variable_storage *storage; unsigned int index = 0; - + if ( !sieve_binary_read_extension(renv->sblock, address, &code, &ext) ) { sieve_runtime_trace_operand_error(renv, oprnd, "variable operand corrupt: invalid extension byte"); @@ -117,39 +117,39 @@ static int opr_variable_read_value "variable operand corrupt: extension has no storage"); return SIEVE_EXEC_BIN_CORRUPT; } - + if ( sieve_binary_read_unsigned(renv->sblock, address, &index) ) { - /* Parameter str can be NULL if we are requested to only skip and not + /* Parameter str can be NULL if we are requested to only skip and not * actually read the argument. */ if ( str_r != NULL ) { if ( !sieve_variable_get(storage, index, str_r) ) return SIEVE_EXEC_FAILURE; - + if ( *str_r == NULL ) *str_r = t_str_new(0); } return SIEVE_EXEC_OK; } - + sieve_runtime_trace_operand_error(renv, oprnd, "variable operand corrupt: invalid variable index"); return SIEVE_EXEC_BIN_CORRUPT; } - + int sieve_variable_operand_read_data -(const struct sieve_runtime_env *renv, struct sieve_operand *oprnd, +(const struct sieve_runtime_env *renv, struct sieve_operand *oprnd, sieve_size_t *address, const char *field_name, struct sieve_variable_storage **storage_r, unsigned int *var_index_r) { const struct sieve_extension *ext; unsigned int code = 1; /* Initially set to offset value */ unsigned int idx = 0; - + oprnd->field_name = field_name; if ( !sieve_operand_is_variable(oprnd) ) { - sieve_runtime_trace_operand_error(renv, oprnd, + sieve_runtime_trace_operand_error(renv, oprnd, "expected variable operand but found %s", sieve_operand_name(oprnd)); return SIEVE_EXEC_BIN_CORRUPT; } @@ -159,7 +159,7 @@ int sieve_variable_operand_read_data "variable operand corrupt: invalid extension byte"); return SIEVE_EXEC_BIN_CORRUPT; } - + *storage_r = sieve_ext_variables_runtime_get_storage (oprnd->ext, renv, ext); if ( *storage_r == NULL ) { @@ -167,9 +167,9 @@ int sieve_variable_operand_read_data "variable operand corrupt: extension has no storage"); return SIEVE_EXEC_BIN_CORRUPT; } - + if ( !sieve_binary_read_unsigned(renv->sblock, address, &idx) ) { - sieve_runtime_trace_operand_error(renv, oprnd, + sieve_runtime_trace_operand_error(renv, oprnd, "variable operand corrupt: invalid variable index"); return SIEVE_EXEC_BIN_CORRUPT; } @@ -180,7 +180,7 @@ int sieve_variable_operand_read_data int sieve_variable_operand_read (const struct sieve_runtime_env *renv, sieve_size_t *address, - const char *field_name, struct sieve_variable_storage **storage_r, + const char *field_name, struct sieve_variable_storage **storage_r, unsigned int *var_index_r) { struct sieve_operand operand; @@ -193,9 +193,9 @@ int sieve_variable_operand_read return sieve_variable_operand_read_data (renv, &operand, address, field_name, storage_r, var_index_r); } - -/* - * Match value operand + +/* + * Match value operand */ static bool opr_match_value_dump @@ -205,22 +205,22 @@ static int opr_match_value_read (const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd, sieve_size_t *address, string_t **str_r); -const struct sieve_opr_string_interface match_value_interface = { +const struct sieve_opr_string_interface match_value_interface = { opr_match_value_dump, opr_match_value_read }; - -const struct sieve_operand_def match_value_operand = { - "match-value", - &variables_extension, + +const struct sieve_operand_def match_value_operand = { + "match-value", + &variables_extension, EXT_VARIABLES_OPERAND_MATCH_VALUE, &string_class, &match_value_interface -}; +}; void sieve_variables_opr_match_value_emit -(struct sieve_binary_block *sblock, const struct sieve_extension *var_ext, - unsigned int index) +(struct sieve_binary_block *sblock, const struct sieve_extension *var_ext, + unsigned int index) { (void) sieve_operand_emit(sblock, var_ext, &match_value_operand); (void) sieve_binary_emit_unsigned(sblock, index); @@ -228,10 +228,10 @@ void sieve_variables_opr_match_value_emit static bool opr_match_value_dump (const struct sieve_dumptime_env *denv, const struct sieve_operand *oprnd, - sieve_size_t *address) + sieve_size_t *address) { unsigned int index = 0; - + if (sieve_binary_read_unsigned(denv->sblock, address, &index) ) { if ( oprnd->field_name != NULL ) sieve_code_dumpf @@ -241,32 +241,32 @@ static bool opr_match_value_dump return TRUE; } - + return FALSE; } static int opr_match_value_read (const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd, sieve_size_t *address, string_t **str_r) -{ +{ unsigned int index = 0; - + if ( sieve_binary_read_unsigned(renv->sblock, address, &index) ) { - /* Parameter str can be NULL if we are requested to only skip and not + /* Parameter str can be NULL if we are requested to only skip and not * actually read the argument. */ if ( str_r != NULL ) { sieve_match_values_get(renv, index, str_r); - - if ( *str_r == NULL ) + + if ( *str_r == NULL ) *str_r = t_str_new(0); - else if ( str_len(*str_r) > EXT_VARIABLES_MAX_VARIABLE_SIZE ) + else if ( str_len(*str_r) > EXT_VARIABLES_MAX_VARIABLE_SIZE ) str_truncate(*str_r, EXT_VARIABLES_MAX_VARIABLE_SIZE); } return SIEVE_EXEC_OK; } - + sieve_runtime_trace_operand_error(renv, oprnd, "match value operand corrupt: invalid index data"); return SIEVE_EXEC_BIN_CORRUPT; diff --git a/src/lib-sieve/plugins/variables/ext-variables-operands.h b/src/lib-sieve/plugins/variables/ext-variables-operands.h index 9c0bf54658235e6daa8cacce1f00e634320e07b1..dd7fe2aa64b8a35fa9d49547d5257acd1d363b06 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-operands.h +++ b/src/lib-sieve/plugins/variables/ext-variables-operands.h @@ -12,21 +12,21 @@ #include "sieve-common.h" #include "ext-variables-common.h" -/* - * Variable operand +/* + * Variable operand */ - -extern const struct sieve_operand_def variable_operand; + +extern const struct sieve_operand_def variable_operand; bool ext_variables_opr_variable_read - (const struct sieve_runtime_env *renv, sieve_size_t *address, + (const struct sieve_runtime_env *renv, sieve_size_t *address, struct sieve_variable_storage **storage, unsigned int *var_index); -/* - * Match value operand +/* + * Match value operand */ - -extern const struct sieve_operand_def match_value_operand; + +extern const struct sieve_operand_def match_value_operand; /* * Variable string operand @@ -35,6 +35,6 @@ extern const struct sieve_operand_def match_value_operand; void ext_variables_opr_variable_string_emit (struct sieve_binary *sbin, unsigned int elements); - + #endif /* __EXT_VARIABLES_OPERANDS_H */ diff --git a/src/lib-sieve/plugins/variables/ext-variables.c b/src/lib-sieve/plugins/variables/ext-variables.c index 33c737cbcb2fc7887a65a87cbefe42fc0043bc12..1766f14f2320e7761ca4d709e2a88729824a3a68 100644 --- a/src/lib-sieve/plugins/variables/ext-variables.c +++ b/src/lib-sieve/plugins/variables/ext-variables.c @@ -29,42 +29,42 @@ #include "ext-variables-modifiers.h" #include "ext-variables-dump.h" -/* - * Operations +/* + * Operations */ const struct sieve_operation_def *ext_variables_operations[] = { - &cmd_set_operation, + &cmd_set_operation, &tst_string_operation }; -/* - * Operands +/* + * Operands */ const struct sieve_operand_def *ext_variables_operands[] = { - &variable_operand, + &variable_operand, &match_value_operand, &namespace_variable_operand, &modifier_operand }; -/* - * Extension +/* + * Extension */ static bool ext_variables_validator_load (const struct sieve_extension *ext, struct sieve_validator *validator); - -const struct sieve_extension_def variables_extension = { - "variables", + +const struct sieve_extension_def variables_extension = { + "variables", NULL, NULL, - ext_variables_validator_load, + ext_variables_validator_load, ext_variables_generator_load, ext_variables_interpreter_load, - NULL, NULL, + NULL, NULL, ext_variables_code_dump, - SIEVE_EXT_DEFINE_OPERATIONS(ext_variables_operations), + SIEVE_EXT_DEFINE_OPERATIONS(ext_variables_operations), SIEVE_EXT_DEFINE_OPERANDS(ext_variables_operands) }; @@ -72,11 +72,11 @@ static bool ext_variables_validator_load (const struct sieve_extension *ext, struct sieve_validator *validator) { sieve_validator_argument_override - (validator, SAT_VAR_STRING, ext, &variable_string_argument); - + (validator, SAT_VAR_STRING, ext, &variable_string_argument); + sieve_validator_register_command(validator, ext, &cmd_set); sieve_validator_register_command(validator, ext, &tst_string); - + ext_variables_validator_initialize(ext, validator); return TRUE; diff --git a/src/lib-sieve/plugins/variables/sieve-ext-variables.h b/src/lib-sieve/plugins/variables/sieve-ext-variables.h index 17a8219356d2c828b94e18191ae97787b15c5ed9..bcf91c7dad7e4c02ac8718a892a595cae236317b 100644 --- a/src/lib-sieve/plugins/variables/sieve-ext-variables.h +++ b/src/lib-sieve/plugins/variables/sieve-ext-variables.h @@ -1,10 +1,10 @@ /* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ -/* - * Public interface for other extensions to use +/* + * Public interface for other extensions to use */ - + #ifndef __SIEVE_EXT_VARIABLES_H #define __SIEVE_EXT_VARIABLES_H @@ -91,7 +91,7 @@ void sieve_variable_scope_binary_unref (struct sieve_variable_scope_binary **scpbin); struct sieve_variable_scope *sieve_variable_scope_binary_dump - (struct sieve_instance *svinst, const struct sieve_extension *ext, + (struct sieve_instance *svinst, const struct sieve_extension *ext, const struct sieve_dumptime_env *denv, sieve_size_t *address); struct sieve_variable_scope_binary *sieve_variable_scope_binary_read (struct sieve_instance *svinst, const struct sieve_extension *ext, @@ -110,26 +110,26 @@ struct sieve_variables_namespace; struct sieve_variables_namespace_def { struct sieve_object_def obj_def; - + bool (*validate) - (struct sieve_validator *valdtr, + (struct sieve_validator *valdtr, const struct sieve_variables_namespace *nspc, - struct sieve_ast_argument *arg, struct sieve_command *cmd, - ARRAY_TYPE(sieve_variable_name) *var_name, void **var_data, + struct sieve_ast_argument *arg, struct sieve_command *cmd, + ARRAY_TYPE(sieve_variable_name) *var_name, void **var_data, bool assignment); bool (*generate) - (const struct sieve_codegen_env *cgenv, + (const struct sieve_codegen_env *cgenv, const struct sieve_variables_namespace *nspc, - struct sieve_ast_argument *arg, struct sieve_command *cmd, + struct sieve_ast_argument *arg, struct sieve_command *cmd, void *var_data); bool (*dump_variable) - (const struct sieve_dumptime_env *denv, + (const struct sieve_dumptime_env *denv, const struct sieve_variables_namespace *nspc, const struct sieve_operand *oprnd, sieve_size_t *address); int (*read_variable) - (const struct sieve_runtime_env *renv, - const struct sieve_variables_namespace *nspc, + (const struct sieve_runtime_env *renv, + const struct sieve_variables_namespace *nspc, const struct sieve_operand *oprnd, sieve_size_t *address, string_t **str); }; @@ -138,7 +138,7 @@ struct sieve_variables_namespace_def { struct sieve_variables_namespace { struct sieve_object object; - + const struct sieve_variables_namespace_def *def; }; @@ -177,25 +177,25 @@ unsigned int sieve_variable_scope_size struct sieve_variable * const *sieve_variable_scope_get_variables (struct sieve_variable_scope *scope, unsigned int *size_r); -/* +/* * Variable storage - */ - + */ + struct sieve_variable_storage; struct sieve_variable_storage *sieve_variable_storage_create (pool_t pool, struct sieve_variable_scope_binary *scpbin); bool sieve_variable_get - (struct sieve_variable_storage *storage, unsigned int index, + (struct sieve_variable_storage *storage, unsigned int index, string_t **value); bool sieve_variable_get_modifiable - (struct sieve_variable_storage *storage, unsigned int index, + (struct sieve_variable_storage *storage, unsigned int index, string_t **value); bool sieve_variable_assign - (struct sieve_variable_storage *storage, unsigned int index, + (struct sieve_variable_storage *storage, unsigned int index, const string_t *value); bool sieve_variable_get_identifier - (struct sieve_variable_storage *storage, unsigned int index, + (struct sieve_variable_storage *storage, unsigned int index, const char **identifier); const char *sieve_variable_get_varid (struct sieve_variable_storage *storage, unsigned int index); @@ -220,7 +220,7 @@ static inline const char *sieve_ext_variables_get_varid return t_strdup_printf("%s:%ld", sieve_extension_name(ext), (long) index); } - + struct sieve_variable_storage *sieve_ext_variables_runtime_get_storage (const struct sieve_extension *var_ext, const struct sieve_runtime_env *renv, const struct sieve_extension *ext); @@ -231,59 +231,59 @@ void sieve_ext_variables_runtime_set_storage const char *sieve_ext_variables_runtime_get_identifier (const struct sieve_extension *var_ext, const struct sieve_runtime_env *renv, const struct sieve_extension *ext, unsigned int index); - -/* - * Variable arguments + +/* + * Variable arguments */ bool sieve_variable_argument_activate (const struct sieve_extension *this_ext, struct sieve_validator *valdtr, struct sieve_command *cmd, struct sieve_ast_argument *arg, bool assignment); - -/* - * Variable operands + +/* + * Variable operands */ extern const struct sieve_operand_def variable_operand; void sieve_variables_opr_variable_emit - (struct sieve_binary_block *sblock, const struct sieve_extension *var_ext, + (struct sieve_binary_block *sblock, const struct sieve_extension *var_ext, struct sieve_variable *var); void sieve_variables_opr_match_value_emit - (struct sieve_binary_block *sblock, const struct sieve_extension *var_ext, + (struct sieve_binary_block *sblock, const struct sieve_extension *var_ext, unsigned int index); int sieve_variable_operand_read_data - (const struct sieve_runtime_env *renv, struct sieve_operand *operand, + (const struct sieve_runtime_env *renv, struct sieve_operand *operand, sieve_size_t *address, const char *field_name, struct sieve_variable_storage **storage_r, unsigned int *var_index_r); int sieve_variable_operand_read (const struct sieve_runtime_env *renv, sieve_size_t *address, const char *field_name, struct sieve_variable_storage **storage_r, unsigned int *var_index_r); - + static inline bool sieve_operand_is_variable (const struct sieve_operand *operand) { - return ( operand != NULL && operand->def != NULL && + return ( operand != NULL && operand->def != NULL && operand->def == &variable_operand ); -} +} -/* - * Modifiers +/* + * Modifiers */ struct sieve_variables_modifier_def { struct sieve_object_def obj_def; - + unsigned int precedence; - + bool (*modify)(string_t *in, string_t **result); }; struct sieve_variables_modifier { struct sieve_object object; - + const struct sieve_variables_modifier_def *def; }; @@ -296,8 +296,8 @@ extern const struct sieve_operand_class sieve_variables_modifier_operand_class; ( (smodf)->object.def->identifier ) void sieve_variables_modifier_register - (const struct sieve_extension *var_ext, struct sieve_validator *valdtr, - const struct sieve_extension *ext, + (const struct sieve_extension *var_ext, struct sieve_validator *valdtr, + const struct sieve_extension *ext, const struct sieve_variables_modifier_def *smodf); /* @@ -305,7 +305,7 @@ void sieve_variables_modifier_register */ void sieve_ext_variables_dump_set_scope -(const struct sieve_extension *var_ext, const struct sieve_dumptime_env *denv, +(const struct sieve_extension *var_ext, const struct sieve_dumptime_env *denv, const struct sieve_extension *ext, struct sieve_variable_scope *scope); #endif /* __SIEVE_EXT_VARIABLES_H */ diff --git a/src/lib-sieve/plugins/variables/tst-string.c b/src/lib-sieve/plugins/variables/tst-string.c index 43f0ae01004293e745c1db89ad51ea1cff80f803..26eff0d19ec8d4997b51c422f61ce4db1062b7f1 100644 --- a/src/lib-sieve/plugins/variables/tst-string.c +++ b/src/lib-sieve/plugins/variables/tst-string.c @@ -15,8 +15,8 @@ #include "ext-variables-common.h" -/* - * String test +/* + * String test * * Syntax: * string [COMPARATOR] [MATCH-TYPE] @@ -24,26 +24,26 @@ */ static bool tst_string_registered - (struct sieve_validator *valdtr, const struct sieve_extension *ext, + (struct sieve_validator *valdtr, const struct sieve_extension *ext, struct sieve_command_registration *cmd_reg); static bool tst_string_validate (struct sieve_validator *valdtr, struct sieve_command *tst); static bool tst_string_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx); -const struct sieve_command_def tst_string = { - "string", - SCT_TEST, +const struct sieve_command_def tst_string = { + "string", + SCT_TEST, 2, 0, FALSE, FALSE, - tst_string_registered, + tst_string_registered, NULL, tst_string_validate, - NULL, - tst_string_generate, - NULL + NULL, + tst_string_generate, + NULL }; -/* +/* * String operation */ @@ -52,31 +52,31 @@ static bool tst_string_operation_dump static int tst_string_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def tst_string_operation = { +const struct sieve_operation_def tst_string_operation = { "STRING", - &variables_extension, - EXT_VARIABLES_OPERATION_STRING, - tst_string_operation_dump, - tst_string_operation_execute + &variables_extension, + EXT_VARIABLES_OPERATION_STRING, + tst_string_operation_dump, + tst_string_operation_execute }; -/* - * Optional arguments +/* + * Optional arguments */ -enum tst_string_optional { +enum tst_string_optional { OPT_END, OPT_COMPARATOR, OPT_MATCH_TYPE }; -/* - * Test registration +/* + * Test registration */ static bool tst_string_registered (struct sieve_validator *valdtr, const struct sieve_extension *ext ATTR_UNUSED, - struct sieve_command_registration *cmd_reg) + struct sieve_command_registration *cmd_reg) { /* The order of these is not significant */ sieve_comparators_link_tag(valdtr, cmd_reg, OPT_COMPARATOR); @@ -85,34 +85,34 @@ static bool tst_string_registered return TRUE; } -/* - * Test validation +/* + * Test validation */ static bool tst_string_validate -(struct sieve_validator *valdtr, struct sieve_command *tst) -{ +(struct sieve_validator *valdtr, struct sieve_command *tst) +{ struct sieve_ast_argument *arg = tst->first_positional; - const struct sieve_match_type mcht_default = + const struct sieve_match_type mcht_default = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); - const struct sieve_comparator cmp_default = + const struct sieve_comparator cmp_default = SIEVE_COMPARATOR_DEFAULT(i_octet_comparator); - + if ( !sieve_validate_positional_argument (valdtr, tst, arg, "source", 1, SAAT_STRING_LIST) ) { return FALSE; } - + if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) ) return FALSE; - + arg = sieve_ast_argument_next(arg); if ( !sieve_validate_positional_argument (valdtr, tst, arg, "key list", 2, SAAT_STRING_LIST) ) { return FALSE; } - + if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) ) return FALSE; @@ -121,24 +121,24 @@ static bool tst_string_validate (valdtr, tst, arg, &mcht_default, &cmp_default); } -/* - * Test generation +/* + * Test generation */ static bool tst_string_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) { sieve_operation_emit(cgenv->sblock, cmd->ext, &tst_string_operation); /* Generate arguments */ if ( !sieve_generate_arguments(cgenv, cmd, NULL) ) return FALSE; - + return TRUE; } -/* - * Code dump +/* + * Code dump */ static bool tst_string_operation_dump @@ -156,8 +156,8 @@ static bool tst_string_operation_dump sieve_opr_stringlist_dump(denv, address, "key list"); } -/* - * Code execution +/* + * Code execution */ static int tst_string_stringlist_next_item @@ -192,7 +192,7 @@ static struct sieve_stringlist *tst_string_stringlist_create static int tst_string_stringlist_next_item (struct sieve_stringlist *_strlist, string_t **str_r) { - struct tst_string_stringlist *strlist = + struct tst_string_stringlist *strlist = (struct tst_string_stringlist *)_strlist; return sieve_stringlist_next_item(strlist->value_list, str_r); @@ -201,7 +201,7 @@ static int tst_string_stringlist_next_item static void tst_string_stringlist_reset (struct sieve_stringlist *_strlist) { - struct tst_string_stringlist *strlist = + struct tst_string_stringlist *strlist = (struct tst_string_stringlist *)_strlist; sieve_stringlist_reset(strlist->value_list); @@ -210,7 +210,7 @@ static void tst_string_stringlist_reset static int tst_string_stringlist_get_length (struct sieve_stringlist *_strlist) { - struct tst_string_stringlist *strlist = + struct tst_string_stringlist *strlist = (struct tst_string_stringlist *)_strlist; string_t *item; int length = 0; @@ -227,28 +227,28 @@ static int tst_string_stringlist_get_length static int tst_string_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) { - struct sieve_match_type mcht = + struct sieve_match_type mcht = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); - struct sieve_comparator cmp = + struct sieve_comparator cmp = SIEVE_COMPARATOR_DEFAULT(i_octet_comparator); struct sieve_stringlist *source, *value_list, *key_list; int match, ret; /* - * Read operands + * Read operands */ - + /* Handle match-type and comparator operands */ if ( sieve_match_opr_optional_read (renv, address, NULL, &ret, &cmp, &mcht) < 0 ) return ret; - + /* Read source */ if ( (ret=sieve_opr_stringlist_read(renv, address, "source", &source)) <= 0 ) return ret; - + /* Read key-list */ - if ( (ret=sieve_opr_stringlist_read(renv, address, "key-list", &key_list)) + if ( (ret=sieve_opr_stringlist_read(renv, address, "key-list", &key_list)) <= 0 ) return ret; @@ -263,7 +263,7 @@ static int tst_string_operation_execute /* Perform match */ if ( (match=sieve_match(renv, &mcht, &cmp, value_list, key_list, &ret)) < 0 ) - return ret; + return ret; /* Set test result for subsequent conditional jump */ sieve_interpreter_set_test_result(renv->interp, match > 0); diff --git a/src/lib-sieve/plugins/vnd.dovecot/duplicate/ext-duplicate-common.c b/src/lib-sieve/plugins/vnd.dovecot/duplicate/ext-duplicate-common.c index d538ccd26d9c3a59f2cf0a8bbb84e6b141e3c6fa..b24806906a33e9cc2a044eb34061d651f0cdc6a0 100644 --- a/src/lib-sieve/plugins/vnd.dovecot/duplicate/ext-duplicate-common.c +++ b/src/lib-sieve/plugins/vnd.dovecot/duplicate/ext-duplicate-common.c @@ -23,7 +23,7 @@ */ #define EXT_DUPLICATE_DEFAULT_PERIOD (1*24*60*60) - + struct ext_duplicate_config { unsigned int period; }; @@ -73,11 +73,11 @@ bool ext_duplicate_check const struct sieve_extension *this_ext = renv->oprtn->ext; const struct sieve_script_env *senv = renv->scriptenv; struct ext_duplicate_context *rctx; - pool_t pool; + pool_t pool; /* Get context; find out whether duplicate was checked earlier */ - rctx = (struct ext_duplicate_context *) - sieve_result_extension_get_context(renv->result, this_ext); + rctx = (struct ext_duplicate_context *) + sieve_result_extension_get_context(renv->result, this_ext); if ( rctx != NULL ) { /* Already checked for duplicate */ @@ -115,6 +115,6 @@ bool ext_duplicate_check (senv, dupl_hash, sizeof(dupl_hash), ioloop_time + ext_config->period); } - return rctx->duplicate; + return rctx->duplicate; } - + diff --git a/src/lib-sieve/plugins/vnd.dovecot/duplicate/ext-duplicate-common.h b/src/lib-sieve/plugins/vnd.dovecot/duplicate/ext-duplicate-common.h index fc44bfab326a1a20989b1380a0a3a37b3271b2bd..5fc6f743391eddd13442e5bf37ddb20a60626b0f 100644 --- a/src/lib-sieve/plugins/vnd.dovecot/duplicate/ext-duplicate-common.h +++ b/src/lib-sieve/plugins/vnd.dovecot/duplicate/ext-duplicate-common.h @@ -18,7 +18,7 @@ void ext_duplicate_unload extern const struct sieve_extension_def duplicate_extension; -/* +/* * Tests */ diff --git a/src/lib-sieve/plugins/vnd.dovecot/duplicate/ext-duplicate.c b/src/lib-sieve/plugins/vnd.dovecot/duplicate/ext-duplicate.c index 4b134c15962d08ff87192c3882a65a0daf5c244b..a9b2c2320ae82d2745941652fe031bd656880429 100644 --- a/src/lib-sieve/plugins/vnd.dovecot/duplicate/ext-duplicate.c +++ b/src/lib-sieve/plugins/vnd.dovecot/duplicate/ext-duplicate.c @@ -11,25 +11,25 @@ * Status: experimental * */ - + #include "lib.h" #include "sieve-extensions.h" #include "sieve-commands.h" -#include "sieve-binary.h" +#include "sieve-binary.h" #include "sieve-validator.h" #include "ext-duplicate-common.h" -/* - * Extension +/* + * Extension */ static bool ext_duplicate_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr); - -const struct sieve_extension_def duplicate_extension = { + +const struct sieve_extension_def duplicate_extension = { "vnd.dovecot.duplicate", ext_duplicate_load, ext_duplicate_unload, diff --git a/src/lib-sieve/plugins/vnd.dovecot/duplicate/tst-duplicate.c b/src/lib-sieve/plugins/vnd.dovecot/duplicate/tst-duplicate.c index c65688f74e3c0d0a3e039f4c9cf86a35039aa1f9..8c5b67290c1a6d22b17832a4f2700d4aeea44a5b 100644 --- a/src/lib-sieve/plugins/vnd.dovecot/duplicate/tst-duplicate.c +++ b/src/lib-sieve/plugins/vnd.dovecot/duplicate/tst-duplicate.c @@ -39,8 +39,8 @@ const struct sieve_command_def tst_duplicate = { NULL, }; -/* - * Duplicate operation +/* + * Duplicate operation */ static bool tst_duplicate_operation_dump @@ -48,22 +48,22 @@ static bool tst_duplicate_operation_dump static int tst_duplicate_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def tst_duplicate_operation = { - "DUPLICATE", &duplicate_extension, +const struct sieve_operation_def tst_duplicate_operation = { + "DUPLICATE", &duplicate_extension, 0, tst_duplicate_operation_dump, tst_duplicate_operation_execute }; -/* - * Validation +/* + * Validation */ static bool tst_duplicate_validate -(struct sieve_validator *valdtr, struct sieve_command *cmd) -{ +(struct sieve_validator *valdtr, struct sieve_command *cmd) +{ struct sieve_ast_argument *arg = cmd->first_positional; - + if ( arg == NULL ) return TRUE; @@ -71,7 +71,7 @@ static bool tst_duplicate_validate (valdtr, cmd, arg, "name", 1, SAAT_STRING) ) { return FALSE; } - + return sieve_validator_argument_activate(valdtr, cmd, arg, FALSE); } @@ -94,26 +94,26 @@ static bool tst_duplicate_generate return TRUE; } -/* +/* * Code dump */ - + static bool tst_duplicate_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) { sieve_code_dumpf(denv, "DUPLICATE"); sieve_code_descend(denv); - + return sieve_opr_string_dump_ex(denv, address, "name", ""); } -/* +/* * Code execution */ static int tst_duplicate_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address ATTR_UNUSED) -{ +{ string_t *name = NULL; bool duplicate = FALSE; int ret; @@ -139,11 +139,11 @@ static int tst_duplicate_operation_execute if ( (duplicate=ext_duplicate_check(renv, name)) ) { sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, "message is a duplicate"); - } else { + } else { sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, "message is not a duplicate"); } - + /* Set test result for subsequent conditional jump */ sieve_interpreter_set_test_result(renv->interp, duplicate); return SIEVE_EXEC_OK; diff --git a/src/lib-sieve/rfc2822.c b/src/lib-sieve/rfc2822.c index 43f730e478c61bc88537edd24461def49c8e9c63..8fbb103bdaa2065a527e50a0011186e071d74752 100644 --- a/src/lib-sieve/rfc2822.c +++ b/src/lib-sieve/rfc2822.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ /* NOTE: much of the functionality implemented here should eventually appear @@ -15,9 +15,9 @@ #include <stdio.h> #include <ctype.h> - + bool rfc2822_header_field_name_verify -(const char *field_name, unsigned int len) +(const char *field_name, unsigned int len) { const char *p = field_name; const char *pend = p + len; @@ -27,14 +27,14 @@ bool rfc2822_header_field_name_verify * %d59-126 ; controls, SP, and * ; ":". */ - + while ( p < pend ) { if ( *p < 33 || *p == ':' ) return FALSE; p++; - } - + } + return TRUE; } @@ -75,8 +75,8 @@ bool rfc2822_header_field_body_verify if ( is8bit && !uni_utf8_str_is_valid(field_body) ) { return FALSE; - } - + } + return TRUE; } @@ -88,7 +88,7 @@ const char *rfc2822_header_field_name_sanitize(const char *name) { char *result = t_strdup_noconst(name); char *p; - + /* Make the whole name lower case ... */ result = str_lcase(result); @@ -98,23 +98,23 @@ const char *rfc2822_header_field_name_sanitize(const char *name) while ( *p != '\0' ) { if ( *p == '-' ) { p++; - + if ( *p != '\0' ) *p = i_toupper(*p); - + continue; } - + p++; } - + return result; } /* * Message construction */ - + /* FIXME: This should be collected into a Dovecot API for composing internet * mail messages. These functions now use FILE * output streams, but this should * be changed to proper dovecot streams. @@ -125,14 +125,14 @@ unsigned int rfc2822_header_field_append uoff_t *body_offset_r) { static const unsigned int max_line = 80; - - const char *bp = body; /* Pointer */ + + const char *bp = body; /* Pointer */ const char *sp = body; /* Start pointer */ - const char *wp = NULL; /* Whitespace pointer */ + const char *wp = NULL; /* Whitespace pointer */ const char *nlp = NULL; /* New-line pointer */ unsigned int line_len = strlen(name); unsigned int lines = 0; - + /* Write header field name first */ str_append_n(header, name, line_len); str_append_n(header, ": ", 2); @@ -141,30 +141,30 @@ unsigned int rfc2822_header_field_append *body_offset_r = str_len(header); line_len += 2; - + /* Add field body; fold it if necessary and account for existing folding */ while ( *bp != '\0' ) { while ( *bp != '\0' && nlp == NULL && (wp == NULL || line_len < max_line) ) { if ( *bp == ' ' || *bp == '\t' ) { wp = bp; } else if ( *bp == '\r' || *bp == '\n' ) { - nlp = bp; + nlp = bp; break; } bp++; line_len++; } - + if ( *bp == '\0' ) break; - + /* Existing newline ? */ if ( nlp != NULL ) { /* Replace any sort of newline for consistency */ while ( *bp == '\r' || *bp == '\n' ) bp++; - + str_append_n(header, sp, nlp-sp); - + if ( *bp != '\0' && *bp != ' ' && *bp != '\t' ) { if ( crlf ) str_append_n(header, "\r\n\t", 3); @@ -185,17 +185,17 @@ unsigned int rfc2822_header_field_append str_append_n(header, "\r\n", 2); else str_append_n(header, "\n", 1); - + sp = wp; } lines++; - - line_len = bp - sp; + + line_len = bp - sp; wp = NULL; nlp = NULL; } - + if ( bp != sp || lines == 0 ) { str_append_n(header, sp, bp-sp); if ( crlf ) @@ -210,7 +210,7 @@ unsigned int rfc2822_header_field_append static int rfc2822_header_field_write_real (FILE *f, const char *name, const char *body, size_t size) -{ +{ string_t *header = t_str_new(strlen(name) + size + 256); (void)rfc2822_header_field_append(header, name, body, TRUE, NULL); @@ -229,14 +229,14 @@ int rfc2822_header_field_write T_BEGIN { ret = rfc2822_header_field_write_real(f, name, body, strlen(body)); } T_END; - + return ret; } int rfc2822_header_field_printf (FILE *f, const char *name, const char *body_fmt, ...) { - string_t *body; + string_t *body; va_list args; int ret; @@ -246,7 +246,7 @@ int rfc2822_header_field_printf va_start(args, body_fmt); str_vprintfa(body, body_fmt, args); va_end(args); - + ret = rfc2822_header_field_write_real (f, name, (const char *) str_data(body), str_len(body)); } T_END; @@ -267,7 +267,7 @@ int rfc2822_header_field_utf8_printf va_start(args, body_fmt); message_header_encode(t_strdup_vprintf(body_fmt, args), body); va_end(args); - + ret = rfc2822_header_field_write_real (f, name, (const char *) str_data(body), str_len(body)); } T_END; diff --git a/src/lib-sieve/rfc2822.h b/src/lib-sieve/rfc2822.h index eea35f762fd889fc743adfff6a4ac66f36251a59..4960c4a1a3f936deae77f37736e96cf0cc9cb2d4 100644 --- a/src/lib-sieve/rfc2822.h +++ b/src/lib-sieve/rfc2822.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ #ifndef __RFC2822_H @@ -10,8 +10,8 @@ /* * Verification - */ - + */ + bool rfc2822_header_field_name_verify (const char *field_name, unsigned int len); bool rfc2822_header_field_body_verify diff --git a/src/lib-sieve/sieve-actions.c b/src/lib-sieve/sieve-actions.c index adb003b287579bc01bcdf81e067cda1483f6fe93..ce4b3f9739c60e0c4aadb12b4acafc99ddc2fb67 100644 --- a/src/lib-sieve/sieve-actions.c +++ b/src/lib-sieve/sieve-actions.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ #include "lib.h" @@ -32,8 +32,8 @@ /* * Side-effect operand */ - -const struct sieve_operand_class sieve_side_effect_operand_class = + +const struct sieve_operand_class sieve_side_effect_operand_class = { "SIDE-EFFECT" }; bool sieve_opr_side_effect_read @@ -48,10 +48,10 @@ bool sieve_opr_side_effect_read (renv, &sieve_side_effect_operand_class, address, &seffect->object) ) return FALSE; - sdef = seffect->def = + sdef = seffect->def = (const struct sieve_side_effect_def *) seffect->object.def; - if ( sdef->read_context != NULL && + if ( sdef->read_context != NULL && !sdef->read_context(seffect, renv, address, &seffect->context) ) { return FALSE; } @@ -64,18 +64,18 @@ bool sieve_opr_side_effect_dump { struct sieve_side_effect seffect; const struct sieve_side_effect_def *sdef; - + if ( !sieve_opr_object_dump (denv, &sieve_side_effect_operand_class, address, &seffect.object) ) return FALSE; - - sdef = seffect.def = + + sdef = seffect.def = (const struct sieve_side_effect_def *) seffect.object.def; if ( sdef->dump_context != NULL ) { sieve_code_descend(denv); if ( !sdef->dump_context(&seffect, denv, address) ) { - return FALSE; + return FALSE; } sieve_code_ascend(denv); } @@ -90,7 +90,7 @@ bool sieve_opr_side_effect_dump int sieve_action_opr_optional_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address, signed int *opt_code) -{ +{ signed int _opt_code = 0; bool final = FALSE, opok = TRUE; @@ -98,7 +98,7 @@ int sieve_action_opr_optional_dump opt_code = &_opt_code; final = TRUE; } - + while ( opok ) { int opt; @@ -130,29 +130,29 @@ int sieve_action_opr_optional_read } if ( exec_status != NULL ) - *exec_status = SIEVE_EXEC_OK; + *exec_status = SIEVE_EXEC_OK; for ( ;; ) { int opt; if ( (opt=sieve_opr_optional_read(renv, address, opt_code)) <= 0 ) { if ( opt < 0 && exec_status != NULL ) - *exec_status = SIEVE_EXEC_BIN_CORRUPT; + *exec_status = SIEVE_EXEC_BIN_CORRUPT; return opt; } if ( *opt_code == SIEVE_OPT_SIDE_EFFECT ) { struct sieve_side_effect seffect; - + i_assert( list != NULL ); - + if ( (ret=sieve_opr_side_effect_read(renv, address, &seffect)) <= 0 ) { if ( exec_status != NULL ) - *exec_status = ret; + *exec_status = ret; return -1; } - - if ( *list == NULL ) + + if ( *list == NULL ) *list = sieve_side_effects_list_create(renv->result); sieve_side_effects_list_add(*list, &seffect); @@ -160,8 +160,8 @@ int sieve_action_opr_optional_read if ( final ) { sieve_runtime_trace_error(renv, "invalid optional operand"); if ( exec_status != NULL ) - *exec_status = SIEVE_EXEC_BIN_CORRUPT; - return -1; + *exec_status = SIEVE_EXEC_BIN_CORRUPT; + return -1; } return 1; } @@ -174,42 +174,42 @@ int sieve_action_opr_optional_read /* * Store action */ - + /* Forward declarations */ static bool act_store_equals (const struct sieve_script_env *senv, const struct sieve_action *act1, const struct sieve_action *act2); - + static int act_store_check_duplicate - (const struct sieve_runtime_env *renv, - const struct sieve_action *act, + (const struct sieve_runtime_env *renv, + const struct sieve_action *act, const struct sieve_action *act_other); static void act_store_print - (const struct sieve_action *action, + (const struct sieve_action *action, const struct sieve_result_print_env *rpenv, bool *keep); static bool act_store_start (const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void **tr_context); static bool act_store_execute - (const struct sieve_action *action, + (const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void *tr_context); static bool act_store_commit - (const struct sieve_action *action, + (const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void *tr_context, bool *keep); static void act_store_rollback - (const struct sieve_action *action, + (const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void *tr_context, bool success); - + /* Action object */ const struct sieve_action_def act_store = { "store", SIEVE_ACTFLAG_TRIES_DELIVER, act_store_equals, - act_store_check_duplicate, - NULL, + act_store_check_duplicate, + NULL, act_store_print, act_store_start, act_store_execute, @@ -239,7 +239,7 @@ void sieve_act_store_add_flags (const struct sieve_action_exec_env *aenv, void *tr_context, const char *const *keywords, enum mail_flags flags) { - struct act_store_transaction *trans = + struct act_store_transaction *trans = (struct act_store_transaction *) tr_context; /* Assign mail keywords for subsequent mailbox_copy() */ @@ -247,10 +247,10 @@ void sieve_act_store_add_flags const char *const *kw; if ( !array_is_created(&trans->keywords) ) { - pool_t pool = sieve_result_pool(aenv->result); + pool_t pool = sieve_result_pool(aenv->result); p_array_init(&trans->keywords, pool, 2); } - + kw = keywords; while ( *kw != NULL ) { @@ -265,9 +265,9 @@ void sieve_act_store_add_flags error = t_strdup_noconst(kw_error); error[0] = i_tolower(error[0]); } - - sieve_result_warning(aenv, - "specified IMAP keyword '%s' is invalid (ignored): %s", + + sieve_result_warning(aenv, + "specified IMAP keyword '%s' is invalid (ignored): %s", str_sanitize(*kw, 64), error); } } @@ -286,9 +286,9 @@ void sieve_act_store_get_storage_error (const struct sieve_action_exec_env *aenv, struct act_store_transaction *trans) { pool_t pool = sieve_result_pool(aenv->result); - + trans->error = p_strdup(pool, - mail_storage_get_last_error(mailbox_get_storage(trans->box), + mail_storage_get_last_error(mailbox_get_storage(trans->box), &trans->error_code)); } @@ -298,27 +298,27 @@ static bool act_store_equals (const struct sieve_script_env *senv, const struct sieve_action *act1, const struct sieve_action *act2) { - struct act_store_context *st_ctx1 = + struct act_store_context *st_ctx1 = ( act1 == NULL ? NULL : (struct act_store_context *) act1->context ); - struct act_store_context *st_ctx2 = + struct act_store_context *st_ctx2 = ( act2 == NULL ? NULL : (struct act_store_context *) act2->context ); const char *mailbox1, *mailbox2; - + /* FIXME: consider namespace aliases */ if ( st_ctx1 == NULL && st_ctx2 == NULL ) return TRUE; - - mailbox1 = ( st_ctx1 == NULL ? + + mailbox1 = ( st_ctx1 == NULL ? SIEVE_SCRIPT_DEFAULT_MAILBOX(senv) : st_ctx1->mailbox ); - mailbox2 = ( st_ctx2 == NULL ? + mailbox2 = ( st_ctx2 == NULL ? SIEVE_SCRIPT_DEFAULT_MAILBOX(senv) : st_ctx2->mailbox ); - - if ( strcmp(mailbox1, mailbox2) == 0 ) + + if ( strcmp(mailbox1, mailbox2) == 0 ) return TRUE; - - return - ( strcasecmp(mailbox1, "INBOX") == 0 && strcasecmp(mailbox2, "INBOX") == 0 ); + + return + ( strcasecmp(mailbox1, "INBOX") == 0 && strcasecmp(mailbox2, "INBOX") == 0 ); } @@ -326,7 +326,7 @@ static bool act_store_equals static int act_store_check_duplicate (const struct sieve_runtime_env *renv, - const struct sieve_action *act, + const struct sieve_action *act, const struct sieve_action *act_other) { return ( act_store_equals(renv->scriptenv, act, act_other) ? 1 : 0 ); @@ -335,18 +335,18 @@ static int act_store_check_duplicate /* Result printing */ static void act_store_print -(const struct sieve_action *action, - const struct sieve_result_print_env *rpenv, bool *keep) +(const struct sieve_action *action, + const struct sieve_result_print_env *rpenv, bool *keep) { struct act_store_context *ctx = (struct act_store_context *) action->context; const char *mailbox; - mailbox = ( ctx == NULL ? - SIEVE_SCRIPT_DEFAULT_MAILBOX(rpenv->scriptenv) : ctx->mailbox ); + mailbox = ( ctx == NULL ? + SIEVE_SCRIPT_DEFAULT_MAILBOX(rpenv->scriptenv) : ctx->mailbox ); - sieve_result_action_printf(rpenv, "store message in folder: %s", + sieve_result_action_printf(rpenv, "store message in folder: %s", str_sanitize(mailbox, 128)); - + *keep = FALSE; } @@ -384,9 +384,9 @@ static bool act_store_mailbox_open } static bool act_store_start -(const struct sieve_action *action, +(const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void **tr_context) -{ +{ struct act_store_context *ctx = (struct act_store_context *) action->context; const struct sieve_script_env *senv = aenv->scriptenv; struct act_store_transaction *trans; @@ -396,7 +396,7 @@ static bool act_store_start enum mail_error error_code = MAIL_ERROR_NONE; bool disabled = FALSE, open_failed = FALSE; - /* If context is NULL, the store action is the result of (implicit) keep */ + /* If context is NULL, the store action is the result of (implicit) keep */ if ( ctx == NULL ) { ctx = p_new(pool, struct act_store_context, 1); ctx->mailbox = p_strdup(pool, SIEVE_SCRIPT_DEFAULT_MAILBOX(senv)); @@ -404,7 +404,7 @@ static bool act_store_start /* Open the requested mailbox */ - /* NOTE: The caller of the sieve library is allowed to leave user set + /* NOTE: The caller of the sieve library is allowed to leave user set * to NULL. This implementation will then skip actually storing the message. */ if ( senv->user != NULL ) { @@ -414,7 +414,7 @@ static bool act_store_start } else { disabled = TRUE; } - + /* Create transaction context */ trans = p_new(pool, struct act_store_transaction, 1); @@ -433,23 +433,23 @@ static bool act_store_start *tr_context = (void *)trans; - return ( trans->error_code == MAIL_ERROR_NONE || + return ( trans->error_code == MAIL_ERROR_NONE || trans->error_code == MAIL_ERROR_NOTFOUND ); } static struct mail_keywords *act_store_keywords_create -(const struct sieve_action_exec_env *aenv, ARRAY_TYPE(const_string) *keywords, +(const struct sieve_action_exec_env *aenv, ARRAY_TYPE(const_string) *keywords, struct mailbox *box) { struct mail_keywords *box_keywords = NULL; - - if ( array_is_created(keywords) && array_count(keywords) > 0 ) + + if ( array_is_created(keywords) && array_count(keywords) > 0 ) { const char *const *kwds; - + (void)array_append_space(keywords); kwds = array_idx(keywords, 0); - + /* FIXME: Do we need to clear duplicates? */ if ( mailbox_keywords_create(box, kwds, &box_keywords) < 0) { sieve_result_error(aenv, "invalid keywords set for stored message"); @@ -457,14 +457,14 @@ static struct mail_keywords *act_store_keywords_create } } - return box_keywords; + return box_keywords; } static bool act_store_execute -(const struct sieve_action *action, +(const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void *tr_context) -{ - struct act_store_transaction *trans = +{ + struct act_store_transaction *trans = (struct act_store_transaction *) tr_context; struct mail *mail = ( action->mail != NULL ? action->mail : aenv->msgdata->mail ); @@ -472,7 +472,7 @@ static bool act_store_execute struct mail_save_context *save_ctx; struct mail_keywords *keywords = NULL; bool result = TRUE; - + /* Verify transaction */ if ( trans == NULL ) return FALSE; @@ -480,10 +480,10 @@ static bool act_store_execute if ( trans->disabled ) return TRUE; /* Exit early if mailbox is not available */ - if ( trans->box == NULL || trans->error_code != MAIL_ERROR_NONE ) + if ( trans->box == NULL || trans->error_code != MAIL_ERROR_NONE ) return FALSE; - /* If the message originates from the target mailbox, only update the flags + /* If the message originates from the target mailbox, only update the flags * and keywords (if not read-only) */ if ( mailbox_backends_equal(trans->box, mail->box) || @@ -511,7 +511,7 @@ static bool act_store_execute * separately. */ } else if ( mail != aenv->msgdata->mail - && mailbox_is_readonly(aenv->msgdata->mail->box) + && mailbox_is_readonly(aenv->msgdata->mail->box) && ( mailbox_backends_equal(trans->box, aenv->msgdata->mail->box) ) ) { trans->redundant = TRUE; @@ -519,12 +519,12 @@ static bool act_store_execute } /* Mark attempt to store in default mailbox */ - if ( strcmp(trans->context->mailbox, - SIEVE_SCRIPT_DEFAULT_MAILBOX(aenv->scriptenv)) == 0 ) + if ( strcmp(trans->context->mailbox, + SIEVE_SCRIPT_DEFAULT_MAILBOX(aenv->scriptenv)) == 0 ) aenv->exec_status->tried_default_save = TRUE; /* Mark attempt to use storage. Can only get here when all previous actions - * succeeded. + * succeeded. */ aenv->exec_status->last_storage = mailbox_get_storage(trans->box); @@ -557,7 +557,7 @@ static bool act_store_execute if ( keywords != NULL ) { mailbox_keywords_unref(&keywords); } - + return result; } @@ -573,9 +573,9 @@ static void act_store_log_status const char *mailbox_vname = mailbox_get_vname(trans->box); if ( strcmp(mailbox_name, mailbox_vname) != 0 ) - mailbox_name = + mailbox_name = t_strdup_printf("'%s' (%s)", mailbox_name, mailbox_vname); - else + else mailbox_name = t_strdup_printf("'%s'", mailbox_name); } else { mailbox_name = t_strdup_printf("'%s'", mailbox_name); @@ -604,7 +604,7 @@ static void act_store_log_status (mailbox_get_storage(trans->box), &error_code); } - if ( error_code != MAIL_ERROR_NOTFOUND && error_code != MAIL_ERROR_PARAMS ) + if ( error_code != MAIL_ERROR_NOTFOUND && error_code != MAIL_ERROR_PARAMS ) { sieve_result_global_error(aenv, "failed to store into mailbox %s: %s", mailbox_name, errstr); @@ -626,10 +626,10 @@ static void act_store_log_status } static bool act_store_commit -(const struct sieve_action *action ATTR_UNUSED, +(const struct sieve_action *action ATTR_UNUSED, const struct sieve_action_exec_env *aenv, void *tr_context, bool *keep) -{ - struct act_store_transaction *trans = +{ + struct act_store_transaction *trans = (struct act_store_transaction *) tr_context; bool status = TRUE; @@ -649,32 +649,32 @@ static bool act_store_commit aenv->exec_status->message_saved = TRUE; if ( trans->box != NULL ) mailbox_free(&trans->box); - return TRUE; + return TRUE; } /* Mark attempt to use storage. Can only get here when all previous actions - * succeeded. + * succeeded. */ aenv->exec_status->last_storage = mailbox_get_storage(trans->box); /* Free mail object for stored message */ - if ( trans->dest_mail != NULL ) - mail_free(&trans->dest_mail); + if ( trans->dest_mail != NULL ) + mail_free(&trans->dest_mail); - /* Commit mailbox transaction */ + /* Commit mailbox transaction */ status = ( mailbox_transaction_commit(&trans->mail_trans) == 0 ); /* Note the fact that the message was stored at least once */ if ( status ) aenv->exec_status->message_saved = TRUE; - + /* Log our status */ act_store_log_status(trans, aenv, FALSE, status); - + /* Cancel implicit keep if all went well */ *keep = !status; - - /* Close mailbox */ + + /* Close mailbox */ if ( trans->box != NULL ) mailbox_free(&trans->box); @@ -682,25 +682,25 @@ static bool act_store_commit } static void act_store_rollback -(const struct sieve_action *action ATTR_UNUSED, +(const struct sieve_action *action ATTR_UNUSED, const struct sieve_action_exec_env *aenv, void *tr_context, bool success) { - struct act_store_transaction *trans = + struct act_store_transaction *trans = (struct act_store_transaction *) tr_context; /* Log status */ act_store_log_status(trans, aenv, TRUE, success); /* Free mailobject for stored message */ - if ( trans->dest_mail != NULL ) - mail_free(&trans->dest_mail); + if ( trans->dest_mail != NULL ) + mail_free(&trans->dest_mail); /* Rollback mailbox transaction */ if ( trans->mail_trans != NULL ) mailbox_transaction_rollback(&trans->mail_trans); - + /* Close the mailbox */ - if ( trans->box != NULL ) + if ( trans->box != NULL ) mailbox_free(&trans->box); } @@ -722,7 +722,7 @@ int sieve_action_duplicate_check if ( senv->duplicate_check == NULL || senv->duplicate_mark == NULL) return 0; - return senv->duplicate_check(senv, id, id_size); + return senv->duplicate_check(senv, id, id_size); } void sieve_action_duplicate_mark @@ -738,7 +738,7 @@ void sieve_action_duplicate_mark /* Rejecting the mail */ static bool sieve_action_do_reject_mail -(const struct sieve_action_exec_env *aenv, const char *sender, +(const struct sieve_action_exec_env *aenv, const char *sender, const char *recipient, const char *reason) { struct sieve_instance *svinst = aenv->svinst; @@ -775,12 +775,12 @@ static bool sieve_action_do_reject_mail rfc2822_header_field_write(f, "Subject", "Automatically rejected mail"); rfc2822_header_field_write(f, "Auto-Submitted", "auto-replied (rejected)"); rfc2822_header_field_write(f, "Precedence", "bulk"); - + rfc2822_header_field_write(f, "MIME-Version", "1.0"); - rfc2822_header_field_printf(f, "Content-Type", + rfc2822_header_field_printf(f, "Content-Type", "multipart/report; report-type=disposition-notification;\n" "boundary=\"%s\"", boundary); - + fprintf(f, "\r\nThis is a MIME-encapsulated message\r\n\r\n"); /* Human readable status report */ @@ -789,7 +789,7 @@ static bool sieve_action_do_reject_mail fprintf(f, "Content-Disposition: inline\r\n"); fprintf(f, "Content-Transfer-Encoding: 8bit\r\n\r\n"); - fprintf(f, "Your message to <%s> was automatically rejected:\r\n" + fprintf(f, "Your message to <%s> was automatically rejected:\r\n" "%s\r\n", recipient, reason); /* MDN status report */ @@ -814,15 +814,15 @@ static bool sieve_action_do_reject_mail /* Note: If you add more headers, they need to be sorted. * We'll drop Content-Type because we're not including the message * body, and having a multipart Content-Type may confuse some - * MIME parsers when they don't see the message boundaries. + * MIME parsers when they don't see the message boundaries. */ static const char *const exclude_headers[] = { "Content-Type" }; input = i_stream_create_header_filter(input, - HEADER_FILTER_EXCLUDE | HEADER_FILTER_NO_CR | HEADER_FILTER_HIDE_BODY, - exclude_headers, N_ELEMENTS(exclude_headers), + HEADER_FILTER_EXCLUDE | HEADER_FILTER_NO_CR | HEADER_FILTER_HIDE_BODY, + exclude_headers, N_ELEMENTS(exclude_headers), null_header_filter_callback, NULL); while ((ret = i_stream_read_data(input, &data, &size, 0)) > 0) { @@ -831,7 +831,7 @@ static bool sieve_action_do_reject_mail i_stream_skip(input, size); } i_stream_unref(&input); - + i_assert(ret != 0); } @@ -844,7 +844,7 @@ static bool sieve_action_do_reject_mail str_sanitize(sender, 80)); return FALSE; } - + return TRUE; } @@ -857,10 +857,10 @@ bool sieve_action_reject_mail if ( senv->reject_mail != NULL ) { return ( senv->reject_mail(senv, recipient, reason) >= 0 ); } - + return sieve_action_do_reject_mail(aenv, sender, recipient, reason); } - + diff --git a/src/lib-sieve/sieve-actions.h b/src/lib-sieve/sieve-actions.h index eb0a4ebe4297846271ed100dd70d603303636bb5..d90b6e0d8bfb4ce8817f015df513fcc4b90dab75 100644 --- a/src/lib-sieve/sieve-actions.h +++ b/src/lib-sieve/sieve-actions.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ #ifndef __SIEVE_ACTIONS_H @@ -15,7 +15,7 @@ * Action execution environment */ -struct sieve_action_exec_env { +struct sieve_action_exec_env { struct sieve_instance *svinst; struct sieve_result *result; @@ -37,49 +37,49 @@ enum sieve_action_flags { SIEVE_ACTFLAG_TRIES_DELIVER = (1 << 0), SIEVE_ACTFLAG_SENDS_RESPONSE = (1 << 1) }; - -/* + +/* * Action definition */ struct sieve_action_def { const char *name; unsigned int flags; - + bool (*equals) - (const struct sieve_script_env *senv, const struct sieve_action *act1, + (const struct sieve_script_env *senv, const struct sieve_action *act1, const struct sieve_action *act2); /* Result verification */ - - int (*check_duplicate) + + int (*check_duplicate) (const struct sieve_runtime_env *renv, - const struct sieve_action *act, - const struct sieve_action *act_other); + const struct sieve_action *act, + const struct sieve_action *act_other); int (*check_conflict) - (const struct sieve_runtime_env *renv, - const struct sieve_action *act, - const struct sieve_action *act_other); + (const struct sieve_runtime_env *renv, + const struct sieve_action *act, + const struct sieve_action *act_other); /* Result printing */ - + void (*print) - (const struct sieve_action *action, - const struct sieve_result_print_env *penv, bool *keep); - - /* Result execution */ - + (const struct sieve_action *action, + const struct sieve_result_print_env *penv, bool *keep); + + /* Result execution */ + bool (*start) - (const struct sieve_action *action, - const struct sieve_action_exec_env *aenv, void **tr_context); + (const struct sieve_action *action, + const struct sieve_action_exec_env *aenv, void **tr_context); bool (*execute) - (const struct sieve_action *action, + (const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void *tr_context); bool (*commit) - (const struct sieve_action *action, + (const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void *tr_context, bool *keep); void (*rollback) - (const struct sieve_action *action, + (const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void *tr_context, bool success); }; @@ -100,56 +100,56 @@ struct sieve_action { #define sieve_action_is(act, definition) \ ( (act)->def == &(definition) ) -/* - * Action side effects +/* + * Action side effects */ /* Side effect object */ struct sieve_side_effect_def { struct sieve_object_def obj_def; - + /* The action it is supposed to link to */ - + const struct sieve_action_def *to_action; - + /* Context coding */ - + bool (*dump_context) - (const struct sieve_side_effect *seffect, + (const struct sieve_side_effect *seffect, const struct sieve_dumptime_env *renv, sieve_size_t *address); int (*read_context) - (const struct sieve_side_effect *seffect, + (const struct sieve_side_effect *seffect, const struct sieve_runtime_env *renv, sieve_size_t *address, void **se_context); - + /* Result verification */ - + int (*merge) - (const struct sieve_runtime_env *renv, const struct sieve_action *action, + (const struct sieve_runtime_env *renv, const struct sieve_action *action, const struct sieve_side_effect *old_seffect, const struct sieve_side_effect *new_seffect, void **old_context); - /* Result printing */ - + /* Result printing */ + void (*print) - (const struct sieve_side_effect *seffect, const struct sieve_action *action, + (const struct sieve_side_effect *seffect, const struct sieve_action *action, const struct sieve_result_print_env *penv, bool *keep); /* Result execution */ bool (*pre_execute) - (const struct sieve_side_effect *seffect, const struct sieve_action *action, - const struct sieve_action_exec_env *aenv, void **context, + (const struct sieve_side_effect *seffect, const struct sieve_action *action, + const struct sieve_action_exec_env *aenv, void **context, void *tr_context); bool (*post_execute) - (const struct sieve_side_effect *seffect, const struct sieve_action *action, + (const struct sieve_side_effect *seffect, const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void *tr_context); void (*post_commit) - (const struct sieve_side_effect *seffect, const struct sieve_action *action, + (const struct sieve_side_effect *seffect, const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void *tr_context, bool *keep); void (*rollback) - (const struct sieve_side_effect *seffect, const struct sieve_action *action, + (const struct sieve_side_effect *seffect, const struct sieve_action *action, const struct sieve_action_exec_env *aenv, void *tr_context, bool success); }; @@ -164,7 +164,7 @@ struct sieve_side_effect { /* * Side effect operand */ - + #define SIEVE_EXT_DEFINE_SIDE_EFFECT(SEF) SIEVE_EXT_DEFINE_OBJECT(SEF) #define SIEVE_EXT_DEFINE_SIDE_EFFECTS(SEFS) SIEVE_EXT_DEFINE_OBJECTS(SEFS) @@ -175,7 +175,7 @@ extern const struct sieve_operand_class sieve_side_effect_operand_class; static inline void sieve_opr_side_effect_emit (struct sieve_binary_block *sblock, const struct sieve_extension *ext, const struct sieve_side_effect_def *seff) -{ +{ sieve_opr_object_emit(sblock, ext, &seff->obj_def); } @@ -199,21 +199,21 @@ int sieve_action_opr_optional_read signed int *opt_code, int *exec_status, struct sieve_side_effects_list **list); -/* - * Core actions +/* + * Core actions */ extern const struct sieve_action_def act_redirect; extern const struct sieve_action_def act_store; extern const struct sieve_action_def act_discard; -/* +/* * Store action */ struct act_store_context { /* Folder name represented in utf-8 */ - const char *mailbox; + const char *mailbox; }; struct act_store_transaction { @@ -221,7 +221,7 @@ struct act_store_transaction { struct mailbox *box; struct mailbox_transaction_context *mail_trans; struct mail *dest_mail; - + const char *error; enum mail_error error_code; @@ -234,7 +234,7 @@ struct act_store_transaction { }; int sieve_act_store_add_to_result - (const struct sieve_runtime_env *renv, + (const struct sieve_runtime_env *renv, struct sieve_side_effects_list *seffects, const char *folder); void sieve_act_store_add_flags @@ -244,7 +244,7 @@ void sieve_act_store_add_flags void sieve_act_store_get_storage_error (const struct sieve_action_exec_env *aenv, struct act_store_transaction *trans); -/* +/* * Action utility functions */ diff --git a/src/lib-sieve/sieve-address-parts.c b/src/lib-sieve/sieve-address-parts.c index ad88726fce1da6fa48e76f13134f9e7b124c430b..0661681284e9b2c3ac840094b38e8ed67a34e8f6 100644 --- a/src/lib-sieve/sieve-address-parts.c +++ b/src/lib-sieve/sieve-address-parts.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ #include "lib.h" @@ -25,7 +25,7 @@ #include <string.h> -/* +/* * Default address parts */ @@ -33,11 +33,11 @@ const struct sieve_address_part_def *sieve_core_address_parts[] = { &all_address_part, &local_address_part, &domain_address_part }; -const unsigned int sieve_core_address_parts_count = +const unsigned int sieve_core_address_parts_count = N_ELEMENTS(sieve_core_address_parts); -/* - * Address-part 'extension' +/* + * Address-part 'extension' */ static bool addrp_validator_load @@ -51,10 +51,10 @@ const struct sieve_extension_def address_part_extension = { SIEVE_EXT_DEFINE_NO_OPERATIONS, SIEVE_EXT_DEFINE_NO_OPERANDS /* Defined as core operand */ }; - -/* + +/* * Validator context: - * name-based address-part registry. + * name-based address-part registry. */ static struct sieve_validator_object_registry *_get_object_registry @@ -67,18 +67,18 @@ static struct sieve_validator_object_registry *_get_object_registry adrp_ext = sieve_get_address_part_extension(svinst); return sieve_validator_object_registry_get(valdtr, adrp_ext); } - + void sieve_address_part_register (struct sieve_validator *valdtr, const struct sieve_extension *ext, - const struct sieve_address_part_def *addrp_def) + const struct sieve_address_part_def *addrp_def) { struct sieve_validator_object_registry *regs = _get_object_registry(valdtr); - + sieve_validator_object_registry_add(regs, ext, &addrp_def->obj_def); } static bool sieve_address_part_exists -(struct sieve_validator *valdtr, const char *identifier) +(struct sieve_validator *valdtr, const char *identifier) { struct sieve_validator_object_registry *regs = _get_object_registry(valdtr); @@ -86,8 +86,8 @@ static bool sieve_address_part_exists } static const struct sieve_address_part *sieve_address_part_create_instance -(struct sieve_validator *valdtr, struct sieve_command *cmd, - const char *identifier) +(struct sieve_validator *valdtr, struct sieve_command *cmd, + const char *identifier) { struct sieve_validator_object_registry *regs = _get_object_registry(valdtr); struct sieve_object object; @@ -106,7 +106,7 @@ static const struct sieve_address_part *sieve_address_part_create_instance static bool addrp_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr) { - struct sieve_validator_object_registry *regs = + struct sieve_validator_object_registry *regs = sieve_validator_object_registry_init(valdtr, ext); unsigned int i; @@ -121,8 +121,8 @@ static bool addrp_validator_load void sieve_address_parts_link_tags (struct sieve_validator *valdtr, struct sieve_command_registration *cmd_reg, - int id_code) -{ + int id_code) +{ struct sieve_instance *svinst; const struct sieve_extension *adrp_ext; @@ -130,40 +130,40 @@ void sieve_address_parts_link_tags adrp_ext = sieve_get_address_part_extension(svinst); sieve_validator_register_tag - (valdtr, cmd_reg, adrp_ext, &address_part_tag, id_code); + (valdtr, cmd_reg, adrp_ext, &address_part_tag, id_code); } -/* - * Address-part tagged argument +/* + * Address-part tagged argument */ - + /* Forward declarations */ static bool tag_address_part_is_instance_of (struct sieve_validator *valdtr, struct sieve_command *cmd, const struct sieve_extension *ext, const char *identifier, void **data); static bool tag_address_part_validate - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); static bool tag_address_part_generate - (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, + (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *cmd); /* Argument object */ -const struct sieve_argument_def address_part_tag = { +const struct sieve_argument_def address_part_tag = { "ADDRESS-PART", - tag_address_part_is_instance_of, + tag_address_part_is_instance_of, tag_address_part_validate, NULL, NULL, - tag_address_part_generate + tag_address_part_generate }; /* Argument implementation */ - + static bool tag_address_part_is_instance_of (struct sieve_validator *valdtr, struct sieve_command *cmd, - const struct sieve_extension *ext ATTR_UNUSED, const char *identifier, + const struct sieve_extension *ext ATTR_UNUSED, const char *identifier, void **data) { const struct sieve_address_part *addrp; @@ -174,13 +174,13 @@ static bool tag_address_part_is_instance_of if ( (addrp=sieve_address_part_create_instance (valdtr, cmd, identifier)) == NULL ) return FALSE; - + *data = (void *) addrp; return TRUE; } - + static bool tag_address_part_validate -(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_ast_argument **arg, struct sieve_command *cmd ATTR_UNUSED) { /* NOTE: Currenly trivial, but might need to allow for further validation for @@ -198,29 +198,29 @@ static bool tag_address_part_validate } static bool tag_address_part_generate -(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, +(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *cmd ATTR_UNUSED) { struct sieve_address_part *addrp = (struct sieve_address_part *) arg->argument->data; - - sieve_opr_address_part_emit(cgenv->sblock, addrp); - + + sieve_opr_address_part_emit(cgenv->sblock, addrp); + return TRUE; } /* * Address-part operand */ - -const struct sieve_operand_class sieve_address_part_operand_class = + +const struct sieve_operand_class sieve_address_part_operand_class = { "address part" }; static const struct sieve_extension_objects core_address_parts = SIEVE_EXT_DEFINE_MATCH_TYPES(sieve_core_address_parts); -const struct sieve_operand_def address_part_operand = { - "address-part", +const struct sieve_operand_def address_part_operand = { + "address-part", NULL, SIEVE_OPERAND_ADDRESS_PART, &sieve_address_part_operand_class, &core_address_parts @@ -268,7 +268,7 @@ struct sieve_stringlist *sieve_address_part_stringlist_create static int sieve_address_part_stringlist_next_item (struct sieve_stringlist *_strlist, string_t **str_r) { - struct sieve_address_part_stringlist *strlist = + struct sieve_address_part_stringlist *strlist = (struct sieve_address_part_stringlist *)_strlist; struct sieve_address item; string_t *item_unparsed; @@ -280,7 +280,7 @@ static int sieve_address_part_stringlist_next_item if ( (ret=sieve_address_list_next_item (strlist->addresses, &item, &item_unparsed)) <= 0 ) return ret; - + if ( item.local_part == NULL ) { if ( item_unparsed != NULL ) { if ( _strlist->trace ) { @@ -305,21 +305,21 @@ static int sieve_address_part_stringlist_next_item str_sanitize(sieve_address_to_string(&item), 80)); } - if ( addrp->def != NULL && addrp->def->extract_from ) + if ( addrp->def != NULL && addrp->def->extract_from ) part = addrp->def->extract_from(addrp, &item); if ( part != NULL ) *str_r = t_str_new_const(part, strlen(part)); } } - + return 1; } static void sieve_address_part_stringlist_reset (struct sieve_stringlist *_strlist) { - struct sieve_address_part_stringlist *strlist = + struct sieve_address_part_stringlist *strlist = (struct sieve_address_part_stringlist *)_strlist; sieve_address_list_reset(strlist->addresses); @@ -328,7 +328,7 @@ static void sieve_address_part_stringlist_reset static int sieve_address_part_stringlist_get_length (struct sieve_stringlist *_strlist) { - struct sieve_address_part_stringlist *strlist = + struct sieve_address_part_stringlist *strlist = (struct sieve_address_part_stringlist *)_strlist; return sieve_address_list_get_length(strlist->addresses); @@ -337,19 +337,19 @@ static int sieve_address_part_stringlist_get_length static void sieve_address_part_stringlist_set_trace (struct sieve_stringlist *_strlist, bool trace) { - struct sieve_address_part_stringlist *strlist = + struct sieve_address_part_stringlist *strlist = (struct sieve_address_part_stringlist *)_strlist; sieve_address_list_set_trace(strlist->addresses, trace); } -/* +/* * Default ADDRESS-PART, MATCH-TYPE, COMPARATOR access */ - + int sieve_addrmatch_opr_optional_dump -(const struct sieve_dumptime_env *denv, sieve_size_t *address, - signed int *opt_code) +(const struct sieve_dumptime_env *denv, sieve_size_t *address, + signed int *opt_code) { signed int _opt_code = 0; bool final = FALSE, opok = TRUE; @@ -386,7 +386,7 @@ int sieve_addrmatch_opr_optional_dump int sieve_addrmatch_opr_optional_read (const struct sieve_runtime_env *renv, sieve_size_t *address, signed int *opt_code, int *exec_status, struct sieve_address_part *addrp, - struct sieve_match_type *mtch, struct sieve_comparator *cmp) + struct sieve_match_type *mtch, struct sieve_comparator *cmp) { signed int _opt_code = 0; bool final = FALSE; @@ -398,14 +398,14 @@ int sieve_addrmatch_opr_optional_read } if ( exec_status != NULL ) - *exec_status = SIEVE_EXEC_OK; + *exec_status = SIEVE_EXEC_OK; while ( status == SIEVE_EXEC_OK ) { int opt; if ( (opt=sieve_opr_optional_read(renv, address, opt_code)) <= 0 ){ if ( opt < 0 && exec_status != NULL ) - *exec_status = SIEVE_EXEC_BIN_CORRUPT; + *exec_status = SIEVE_EXEC_BIN_CORRUPT; return opt; } @@ -435,12 +435,12 @@ int sieve_addrmatch_opr_optional_read return -1; } -/* +/* * Core address-part modifiers */ - + static const char *addrp_all_extract_from -(const struct sieve_address_part *addrp ATTR_UNUSED, +(const struct sieve_address_part *addrp ATTR_UNUSED, const struct sieve_address *address) { const char *local_part = address->local_part; diff --git a/src/lib-sieve/sieve-address-parts.h b/src/lib-sieve/sieve-address-parts.h index 4f6d049d9e9a53e5d7142a1b1f503d4860a2276d..c2ce04bec48dfa868d4c0d2f4156479bf4c06db7 100644 --- a/src/lib-sieve/sieve-address-parts.h +++ b/src/lib-sieve/sieve-address-parts.h @@ -1,6 +1,6 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #ifndef __SIEVE_ADDRESS_PARTS_H #define __SIEVE_ADDRESS_PARTS_H @@ -15,10 +15,10 @@ */ struct sieve_address_part_def { - struct sieve_object_def obj_def; + struct sieve_object_def obj_def; const char *(*extract_from) - (const struct sieve_address_part *addrp, + (const struct sieve_address_part *addrp, const struct sieve_address *address); }; @@ -43,7 +43,7 @@ struct sieve_address_part { /* * Core address parts */ - + enum sieve_address_part_code { SIEVE_ADDRESS_PART_ALL, SIEVE_ADDRESS_PART_LOCAL, @@ -58,7 +58,7 @@ extern const struct sieve_address_part_def domain_address_part; /* * Address part tagged argument */ - + extern const struct sieve_argument_def address_part_tag; void sieve_address_parts_link_tags @@ -68,11 +68,11 @@ void sieve_address_parts_link_tags /* * Address part registry */ - + void sieve_address_part_register (struct sieve_validator *valdtr, const struct sieve_extension *ext, const struct sieve_address_part_def *addrp); - + /* * Address part operand */ @@ -85,7 +85,7 @@ extern const struct sieve_operand_class sieve_address_part_operand_class; static inline void sieve_opr_address_part_emit (struct sieve_binary_block *sblock, const struct sieve_address_part *addrp) -{ +{ sieve_opr_object_emit(sblock, addrp->object.ext, addrp->object.def); } @@ -97,7 +97,7 @@ static inline bool sieve_opr_address_part_dump } static inline int sieve_opr_address_part_read -(const struct sieve_runtime_env *renv, sieve_size_t *address, +(const struct sieve_runtime_env *renv, sieve_size_t *address, struct sieve_address_part *addrp) { if ( !sieve_opr_object_read @@ -116,8 +116,8 @@ struct sieve_stringlist *sieve_address_part_stringlist_create (const struct sieve_runtime_env *renv, const struct sieve_address_part *addrp, struct sieve_address_list *addresses); -/* - * Match utility +/* + * Match utility */ enum sieve_addrmatch_opt_operand { @@ -132,7 +132,7 @@ int sieve_addrmatch_opr_optional_dump signed int *opt_code); int sieve_addrmatch_opr_optional_read - (const struct sieve_runtime_env *renv, sieve_size_t *address, + (const struct sieve_runtime_env *renv, sieve_size_t *address, signed int *opt_code, int *exec_status, struct sieve_address_part *addrp, struct sieve_match_type *mtch, struct sieve_comparator *cmp); diff --git a/src/lib-sieve/sieve-address.c b/src/lib-sieve/sieve-address.c index d88b9cf6363228152eb0daab421cde39210fda4a..08cf540a60a9890ac59403ff9d6e689f5f7396e0 100644 --- a/src/lib-sieve/sieve-address.c +++ b/src/lib-sieve/sieve-address.c @@ -1,6 +1,6 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #include "lib.h" #include "str.h" #include "str-sanitize.h" @@ -23,7 +23,7 @@ static int sieve_header_address_list_next_string_item (struct sieve_stringlist *_strlist, string_t **str_r); static int sieve_header_address_list_next_item - (struct sieve_address_list *_addrlist, struct sieve_address *addr_r, + (struct sieve_address_list *_addrlist, struct sieve_address *addr_r, string_t **unparsed_r); static void sieve_header_address_list_reset (struct sieve_stringlist *_strlist); @@ -43,26 +43,26 @@ struct sieve_address_list *sieve_header_address_list_create (const struct sieve_runtime_env *renv, struct sieve_stringlist *field_values) { struct sieve_header_address_list *addrlist; - + addrlist = t_new(struct sieve_header_address_list, 1); addrlist->addrlist.strlist.runenv = renv; addrlist->addrlist.strlist.exec_status = SIEVE_EXEC_OK; - addrlist->addrlist.strlist.next_item = + addrlist->addrlist.strlist.next_item = sieve_header_address_list_next_string_item; addrlist->addrlist.strlist.reset = sieve_header_address_list_reset; addrlist->addrlist.strlist.set_trace = sieve_header_address_list_set_trace; addrlist->addrlist.next_item = sieve_header_address_list_next_item; addrlist->field_values = field_values; - + return &addrlist->addrlist; } static int sieve_header_address_list_next_item -(struct sieve_address_list *_addrlist, struct sieve_address *addr_r, +(struct sieve_address_list *_addrlist, struct sieve_address *addr_r, string_t **unparsed_r) { - struct sieve_header_address_list *addrlist = - (struct sieve_header_address_list *) _addrlist; + struct sieve_header_address_list *addrlist = + (struct sieve_header_address_list *) _addrlist; const struct message_address *aitem; bool valid = TRUE; @@ -75,7 +75,7 @@ static int sieve_header_address_list_next_item int ret; /* Read next header value from source list */ - if ( (ret=sieve_stringlist_next_item(addrlist->field_values, &value_item)) + if ( (ret=sieve_stringlist_next_item(addrlist->field_values, &value_item)) <= 0 ) return ret; @@ -86,7 +86,7 @@ static int sieve_header_address_list_next_item } addrlist->cur_address = message_address_parse - (pool_datastack_create(), (const unsigned char *) str_data(value_item), + (pool_datastack_create(), (const unsigned char *) str_data(value_item), str_len(value_item), 256, FALSE); /* Check validity of all addresses simultaneously. Unfortunately, @@ -153,7 +153,7 @@ static int sieve_header_address_list_next_string_item static void sieve_header_address_list_reset (struct sieve_stringlist *_strlist) { - struct sieve_header_address_list *addrlist = + struct sieve_header_address_list *addrlist = (struct sieve_header_address_list *)_strlist; sieve_stringlist_reset(addrlist->field_values); @@ -163,7 +163,7 @@ static void sieve_header_address_list_reset static void sieve_header_address_list_set_trace (struct sieve_stringlist *_strlist, bool trace) { - struct sieve_header_address_list *addrlist = + struct sieve_header_address_list *addrlist = (struct sieve_header_address_list *)_strlist; sieve_stringlist_set_trace(addrlist->field_values, trace); @@ -173,7 +173,7 @@ static void sieve_header_address_list_set_trace * RFC 2822 addresses */ -/* Mail message address according to RFC 2822 and implemented in the Dovecot +/* Mail message address according to RFC 2822 and implemented in the Dovecot * message address parser: * * address = mailbox / group @@ -210,26 +210,26 @@ static void sieve_header_address_list_set_trace * word = atom / quoted-string * phrase = 1*word / obs-phrase * - * Message address specification as allowed bij the RFC 5228 SIEVE + * Message address specification as allowed bij the RFC 5228 SIEVE * specification: * sieve-address = addr-spec ; simple address * / phrase "<" addr-spec ">" ; name & addr-spec\ * * Which concisely is about equal to: * sieve-address = mailbox - */ + */ /* * Address parse context */ - + struct sieve_message_address_parser { struct rfc822_parser_context parser; string_t *str; string_t *local_part; string_t *domain; - + string_t *error; }; @@ -238,14 +238,14 @@ struct sieve_message_address_parser { */ static inline void sieve_address_error - (struct sieve_message_address_parser *ctx, const char *fmt, ...) + (struct sieve_message_address_parser *ctx, const char *fmt, ...) ATTR_FORMAT(2, 3); static inline void sieve_address_error (struct sieve_message_address_parser *ctx, const char *fmt, ...) { va_list args; - + if ( str_len(ctx->error) == 0 ) { va_start(args, fmt); str_vprintfa(ctx->error, fmt, args); @@ -260,7 +260,7 @@ static inline void sieve_address_error * --> this implementation adds textual error reporting * MERGE! */ - + static int parse_local_part(struct sieve_message_address_parser *ctx) { int ret; @@ -279,7 +279,7 @@ static int parse_local_part(struct sieve_message_address_parser *ctx) ret = rfc822_parse_quoted_string(&ctx->parser, ctx->local_part); else ret = rfc822_parse_dot_atom(&ctx->parser, ctx->local_part); - + if (ret < 0) { sieve_address_error(ctx, "invalid local part"); return -1; @@ -308,12 +308,12 @@ static int parse_addr_spec(struct sieve_message_address_parser *ctx) if ((ret = parse_local_part(ctx)) < 0) return ret; - + if ( ret > 0 && *ctx->parser.data == '@') { return parse_domain(ctx); - } + } - sieve_address_error(ctx, "invalid or lonely local part '%s' (expecting '@')", + sieve_address_error(ctx, "invalid or lonely local part '%s' (expecting '@')", str_sanitize(str_c(ctx->local_part), 80)); return -1; } @@ -322,31 +322,31 @@ static int parse_mailbox(struct sieve_message_address_parser *ctx) { int ret; const unsigned char *start; - + /* sieve-address = addr-spec ; simple address * / phrase "<" addr-spec ">" ; name & addr-spec */ - + /* Record parser state in case we fail at our first attempt */ - start = ctx->parser.data; - - /* First try: phrase "<" addr-spec ">" ; name & addr-spec */ + start = ctx->parser.data; + + /* First try: phrase "<" addr-spec ">" ; name & addr-spec */ str_truncate(ctx->str, 0); if (rfc822_parse_phrase(&ctx->parser, ctx->str) <= 0 || *ctx->parser.data != '<') { /* Failed; try just bare addr-spec */ ctx->parser.data = start; return parse_addr_spec(ctx); - } + } /* "<" addr-spec ">" */ ctx->parser.data++; if ((ret = rfc822_skip_lwsp(&ctx->parser)) <= 0 ) { - if ( ret < 0 ) - sieve_address_error(ctx, "invalid characters after <"); + if ( ret < 0 ) + sieve_address_error(ctx, "invalid characters after <"); return ret; - } + } if (parse_addr_spec(ctx) < 0) return -1; @@ -359,38 +359,38 @@ static int parse_mailbox(struct sieve_message_address_parser *ctx) if ( (ret=rfc822_skip_lwsp(&ctx->parser)) < 0 ) sieve_address_error(ctx, "address ends with invalid characters"); - + return ret; } static bool parse_mailbox_address -(struct sieve_message_address_parser *ctx, const unsigned char *address, +(struct sieve_message_address_parser *ctx, const unsigned char *address, unsigned int addr_size) { /* Initialize parser */ - + rfc822_parser_init(&ctx->parser, address, addr_size, NULL); /* Parse */ - + rfc822_skip_lwsp(&ctx->parser); if (ctx->parser.data == ctx->parser.end) { sieve_address_error(ctx, "empty address"); return FALSE; } - + if (parse_mailbox(ctx) < 0) return FALSE; if (ctx->parser.data != ctx->parser.end) { - if ( *ctx->parser.data == ',' ) + if ( *ctx->parser.data == ',' ) sieve_address_error(ctx, "not a single addres (found ',')"); else sieve_address_error(ctx, "address ends in invalid characters"); return FALSE; } - + if ( str_len(ctx->domain) == 0 ) { /* Not gonna happen */ sieve_address_error(ctx, "missing domain"); @@ -416,15 +416,15 @@ bool sieve_rfc2822_mailbox_validate(const char *address, const char **error_r) } memset(&ctx, 0, sizeof(ctx)); - + ctx.local_part = t_str_new(128); ctx.domain = t_str_new(128); ctx.str = t_str_new(128); ctx.error = t_str_new(128); - if ( !parse_mailbox_address(&ctx, (const unsigned char *) address, + if ( !parse_mailbox_address(&ctx, (const unsigned char *) address, strlen(address)) ) { - if ( error_r != NULL ) + if ( error_r != NULL ) *error_r = str_c(ctx.error); return FALSE; } @@ -446,19 +446,19 @@ const char *sieve_rfc2822_mailbox_normalize if ( address == NULL ) return NULL; memset(&ctx, 0, sizeof(ctx)); - + ctx.local_part = t_str_new(128); ctx.domain = t_str_new(128); ctx.str = t_str_new(128); ctx.error = t_str_new(128); - if ( !parse_mailbox_address(&ctx, (const unsigned char *) address, + if ( !parse_mailbox_address(&ctx, (const unsigned char *) address, strlen(address)) ) { - if ( error_r != NULL ) + if ( error_r != NULL ) *error_r = str_c(ctx.error); return NULL; } - + (void)str_lcase(str_c_modifiable(ctx.domain)); return t_strconcat(str_c(ctx.local_part), "@", str_c(ctx.domain), NULL); @@ -474,7 +474,7 @@ const char *sieve_address_normalize struct sieve_message_address_parser ctx; memset(&ctx, 0, sizeof(ctx)); - + ctx.local_part = t_str_new(128); ctx.domain = t_str_new(128); ctx.str = t_str_new(128); @@ -485,7 +485,7 @@ const char *sieve_address_normalize *error_r = str_c(ctx.error); return NULL; } - + *error_r = NULL; (void)str_lcase(str_c_modifiable(ctx.domain)); @@ -507,7 +507,7 @@ bool sieve_address_validate *error_r = str_c(ctx.error); return FALSE; } - + *error_r = NULL; return TRUE; } @@ -515,28 +515,28 @@ bool sieve_address_validate int sieve_address_compare (const char *address1, const char *address2, bool normalized ATTR_UNUSED) { - /* NOTE: this deviates from RFC specification in that it compares the local - * part of the address case-insensitively. This however conforms to the + /* NOTE: this deviates from RFC specification in that it compares the local + * part of the address case-insensitively. This however conforms to the * consensus in mail software. */ - - /* FIXME: provided addresses are currently assumed to be normalized to + + /* FIXME: provided addresses are currently assumed to be normalized to * local_part@domain */ i_assert(address1 != NULL); i_assert(address2 != NULL); - + return strcasecmp(address1, address2); } /* * RFC 2821 addresses (envelope paths) */ - + /* FIXME: Quite a bit of this will overlap with the rfc822 parser * dovecot already has and the rfc2821 parser that it probably will - * have once it implements LMTP. For now we implement things separately. + * have once it implements LMTP. For now we implement things separately. */ #define AB (1<<0) @@ -545,17 +545,17 @@ int sieve_address_compare /* atext = ALPHA / DIGIT / "!" / "#" / "$" / "%" * / "&" / "'" / "*" / "+" / "-" / "/" / "=" - * / "?" / "^" / "_" / "`" / "{" / "|" / "}" / "~" + * / "?" / "^" / "_" / "`" / "{" / "|" / "}" / "~" */ -//#define IS_ATEXT(C) ((rfc2821_chars[C] & AB) != 0) +//#define IS_ATEXT(C) ((rfc2821_chars[C] & AB) != 0) -/* dtext = NO-WS-CTL / %d33-90 / %d94-126 - * NO-WS-CTL = %d1-8 / %d11 / %d12 / %d14-31 / %d127 +/* dtext = NO-WS-CTL / %d33-90 / %d94-126 + * NO-WS-CTL = %d1-8 / %d11 / %d12 / %d14-31 / %d127 */ -#define IS_DTEXT(C) ((rfc2821_chars[C] & DB) != 0) +#define IS_DTEXT(C) ((rfc2821_chars[C] & DB) != 0) /* qtext= NO-WS-CTL / %d33 / %d35-91 / %d93-126 */ -#define IS_QTEXT(C) ((rfc2821_chars[C] & QB) == 0) +#define IS_QTEXT(C) ((rfc2821_chars[C] & QB) == 0) /* text = %d1-9 / %d11 / %d12 / %d14-127 / obs-text*/ #define IS_TEXT(C) ((C) != '\r' && (C) != '\n' && (C) < 128) @@ -613,7 +613,7 @@ static int path_skip_white_space(struct sieve_envelope_address_parser *parser) /* Not mentioned anywhere in the specification, but we do it any way * (e.g. Exim does so too) */ - while ( parser->data < parser->end && + while ( parser->data < parser->end && (*parser->data == ' ' || *parser->data == '\t') ) parser->data++; @@ -639,9 +639,9 @@ static int path_skip_address_literal if ( *parser->data == '\\' ) { str_append_c(parser->str, *parser->data); parser->data++; - + if ( parser->data < parser->end ) { - if ( !IS_TEXT(*parser->data) ) + if ( !IS_TEXT(*parser->data) ) return -1; str_append_c(parser->str, *parser->data); @@ -658,7 +658,7 @@ static int path_skip_address_literal count++; } - + if ( count == 0 || parser->data >= parser->end || *parser->data != ']' ) return -1; @@ -678,7 +678,7 @@ static int path_parse_domain * Let-dig = ALPHA / DIGIT * Ldh-str = *( ALPHA / DIGIT / "-" ) Let-dig */ - + str_truncate(parser->str, 0); if ( *parser->data == '[' ) { ret = path_skip_address_literal(parser); @@ -702,7 +702,7 @@ static int path_parse_domain if ( !i_isalnum(*(parser->data-1)) ) return -1; - + if ( (ret=path_skip_white_space(parser)) < 0 ) return ret; @@ -727,20 +727,20 @@ static int path_skip_source_route(struct sieve_envelope_address_parser *parser) { int ret; - /* Source-route = [ A-d-l ":" ] + /* Source-route = [ A-d-l ":" ] * A-d-l = At-domain *( "," A-d-l ) * At-domain = "@" domain */ if ( *parser->data == '@' ) { parser->data++; - + for (;;) { if ( path_skip_white_space(parser) <= 0 ) - return -1; + return -1; if ( path_parse_domain(parser, TRUE) <= 0 ) - return -1; + return -1; if ( (ret=path_skip_white_space(parser)) <= 0 ) return ret; @@ -802,18 +802,18 @@ static int path_parse_local_part(struct sieve_envelope_address_parser *parser) parser->data++; } } - + if ( *parser->data != '"' ) return -1; str_append_c(parser->str, *parser->data); parser->data++; - + if ( (ret=path_skip_white_space(parser)) < 0 ) return ret; } else { for (;;) { - if ( !IS_ATEXT(*parser->data) ) + if ( !IS_ATEXT(*parser->data) ) return -1; str_append_c(parser->str, *parser->data); parser->data++; @@ -822,7 +822,7 @@ static int path_parse_local_part(struct sieve_envelope_address_parser *parser) str_append_c(parser->str, *parser->data); parser->data++; } - + if ( (ret=path_skip_white_space(parser)) < 0 ) return ret; @@ -831,7 +831,7 @@ static int path_parse_local_part(struct sieve_envelope_address_parser *parser) str_append_c(parser->str, *parser->data); parser->data++; - + if ( path_skip_white_space(parser) <= 0 ) return -1; } @@ -846,7 +846,7 @@ static int path_parse_mailbox(struct sieve_envelope_address_parser *parser) int ret; /* Mailbox = Local-part "@" Domain */ - + if ( (ret=path_parse_local_part(parser)) < 0 || (ret=path_skip_white_space(parser)) < 0 ) return -1; @@ -870,15 +870,15 @@ static int path_parse(struct sieve_envelope_address_parser *parser) /* Path = "<" [ A-d-l ":" ] Mailbox ">" */ - if ( (ret=path_skip_white_space(parser)) <= 0 ) + if ( (ret=path_skip_white_space(parser)) <= 0 ) return ret; - + /* We allow angle brackets to be missing */ if ( *parser->data == '<' ) { parser->data++; brackets = TRUE; - if ( path_skip_white_space(parser) <= 0 ) + if ( path_skip_white_space(parser) <= 0 ) return -1; /* Null path? */ @@ -895,7 +895,7 @@ static int path_parse(struct sieve_envelope_address_parser *parser) if ( (ret=path_parse_mailbox(parser)) < 0 ) return -1; - if ( ret > 0 && (ret=path_skip_white_space(parser)) < 0 ) + if ( ret > 0 && (ret=path_skip_white_space(parser)) < 0 ) return -1; if ( brackets ) { @@ -927,7 +927,7 @@ const struct sieve_address *sieve_address_parse_envelope_path if ( (ret=path_parse(&parser)) < 0 ) return NULL; - + if ( ret > 0 && path_skip_white_space(&parser) < 0 ) return NULL; diff --git a/src/lib-sieve/sieve-address.h b/src/lib-sieve/sieve-address.h index bca341c11aedf9622fa548c3be49bf731dc11e7b..042424a00e04a3fc5527982f780124eaff8f89ac 100644 --- a/src/lib-sieve/sieve-address.h +++ b/src/lib-sieve/sieve-address.h @@ -1,9 +1,9 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #ifndef __SIEVE_ADDRESS_H #define __SIEVE_ADDRESS_H - + #include "lib.h" #include "strfuncs.h" @@ -12,15 +12,15 @@ /* * Generic address representation - */ - + */ + struct sieve_address { const char *local_part; const char *domain; }; static inline const char *sieve_address_to_string -(const struct sieve_address *address) +(const struct sieve_address *address) { if ( address == NULL || address->local_part == NULL ) return NULL; @@ -39,19 +39,19 @@ struct sieve_address_list { struct sieve_stringlist strlist; int (*next_item) - (struct sieve_address_list *_addrlist, struct sieve_address *addr_r, + (struct sieve_address_list *_addrlist, struct sieve_address *addr_r, string_t **unparsed_r); }; static inline int sieve_address_list_next_item -(struct sieve_address_list *addrlist, struct sieve_address *addr_r, +(struct sieve_address_list *addrlist, struct sieve_address *addr_r, string_t **unparsed_r) { return addrlist->next_item(addrlist, addr_r, unparsed_r); } static inline void sieve_address_list_reset -(struct sieve_address_list *addrlist) +(struct sieve_address_list *addrlist) { sieve_stringlist_reset(&addrlist->strlist); } @@ -75,9 +75,9 @@ static inline void sieve_address_list_set_trace struct sieve_address_list *sieve_header_address_list_create (const struct sieve_runtime_env *renv, struct sieve_stringlist *field_values); -/* +/* * RFC 2822 addresses - */ + */ bool sieve_rfc2822_mailbox_validate (const char *address, const char **error_r); @@ -89,7 +89,7 @@ const char *sieve_address_normalize (string_t *address, const char **error_r); bool sieve_address_validate (string_t *address, const char **error_r); - + int sieve_address_compare (const char *address1, const char *address2, bool normalized); diff --git a/src/lib-sieve/sieve-ast.c b/src/lib-sieve/sieve-ast.c index bcacde530f4525184e0f84bc94a2f6a3f270032c..923b0d2e28f68a5ff045ade047e0387783d65df1 100644 --- a/src/lib-sieve/sieve-ast.c +++ b/src/lib-sieve/sieve-ast.c @@ -1,6 +1,6 @@ /* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #include "lib.h" #include "str.h" #include "mempool.h" @@ -14,12 +14,12 @@ #include <stdio.h> -/* - * Forward declarations +/* + * Forward declarations */ static struct sieve_ast_node *sieve_ast_node_create - (struct sieve_ast *ast, struct sieve_ast_node *parent, + (struct sieve_ast *ast, struct sieve_ast_node *parent, enum sieve_ast_type type, unsigned int source_line); /* @@ -34,8 +34,8 @@ struct sieve_ast_extension_reg { void *context; }; -/* - * AST object +/* + * AST object */ struct sieve_ast { @@ -43,70 +43,70 @@ struct sieve_ast { int refcount; struct sieve_instance *svinst; - + struct sieve_script *script; - + struct sieve_ast_node *root; - + ARRAY_DEFINE(linked_extensions, const struct sieve_extension *); ARRAY_DEFINE(extensions, struct sieve_ast_extension_reg); }; struct sieve_ast *sieve_ast_create -(struct sieve_script *script) +(struct sieve_script *script) { pool_t pool; struct sieve_ast *ast; unsigned int ext_count; - - pool = pool_alloconly_create("sieve_ast", 16384); + + pool = pool_alloconly_create("sieve_ast", 16384); ast = p_new(pool, struct sieve_ast, 1); ast->pool = pool; ast->refcount = 1; - + ast->script = script; sieve_script_ref(script); ast->svinst = sieve_script_svinst(script); - + ast->root = sieve_ast_node_create(ast, NULL, SAT_ROOT, 0); ast->root->identifier = "ROOT"; - + ext_count = sieve_extensions_get_count(ast->svinst); p_array_init(&ast->linked_extensions, pool, ext_count); p_array_init(&ast->extensions, pool, ext_count); - + return ast; } -void sieve_ast_ref(struct sieve_ast *ast) +void sieve_ast_ref(struct sieve_ast *ast) { ast->refcount++; } -void sieve_ast_unref(struct sieve_ast **ast) +void sieve_ast_unref(struct sieve_ast **ast) { unsigned int i, ext_count; const struct sieve_ast_extension_reg *extrs; - + i_assert((*ast)->refcount > 0); if (--(*ast)->refcount != 0) return; - + /* Release script reference */ sieve_script_unref(&(*ast)->script); - + /* Signal registered extensions that the AST is being destroyed */ extrs = array_get(&(*ast)->extensions, &ext_count); for ( i = 0; i < ext_count; i++ ) { - if ( extrs[i].ast_ext != NULL && + if ( extrs[i].ast_ext != NULL && extrs[i].ast_ext->free != NULL ) extrs[i].ast_ext->free(extrs[i].ext, *ast, extrs[i].context); } /* Destroy AST */ pool_unref(&(*ast)->pool); - + *ast = NULL; } @@ -125,8 +125,8 @@ struct sieve_script *sieve_ast_script(struct sieve_ast *ast) return ast->script; } -/* - * Extension support +/* + * Extension support */ bool sieve_ast_extension_link @@ -134,9 +134,9 @@ bool sieve_ast_extension_link { unsigned int i, ext_count; const struct sieve_extension *const *extensions; - + if ( ext->id < 0 ) return TRUE; - + /* Prevent duplicates */ extensions = array_get(&ast->linked_extensions, &ext_count); for ( i = 0; i < ext_count; i++ ) { @@ -145,7 +145,7 @@ bool sieve_ast_extension_link } /* Add extension */ - array_append(&ast->linked_extensions, &ext, 1); + array_append(&ast->linked_extensions, &ext, 1); return TRUE; } @@ -167,7 +167,7 @@ void sieve_ast_extension_register reg = array_idx_modifiable(&ast->extensions, (unsigned int) ext->id); reg->ast_ext = ast_ext; reg->ext = ext; - reg->context = context; + reg->context = context; } void sieve_ast_extension_set_context @@ -176,20 +176,20 @@ void sieve_ast_extension_set_context struct sieve_ast_extension_reg *reg; if ( ext->id < 0 ) return; - + reg = array_idx_modifiable(&ast->extensions, (unsigned int) ext->id); reg->context = context; } void *sieve_ast_extension_get_context -(struct sieve_ast *ast, const struct sieve_extension *ext) +(struct sieve_ast *ast, const struct sieve_extension *ext) { const struct sieve_ast_extension_reg *reg; if ( ext->id < 0 || ext->id >= (int) array_count(&ast->extensions) ) return NULL; - - reg = array_idx(&ast->extensions, (unsigned int) ext->id); + + reg = array_idx(&ast->extensions, (unsigned int) ext->id); return reg->context; } @@ -197,7 +197,7 @@ void *sieve_ast_extension_get_context /* * AST list implementations */ - + /* Very simplistic linked list implementation * FIXME: Move to separate file */ @@ -226,8 +226,8 @@ void *sieve_ast_extension_get_context list->len++; \ node->list = list; \ return TRUE; \ - } - + } + #define __LIST_INSERT(list, before, node) { \ if ( list->len + 1 < list->len ) \ return FALSE; \ @@ -271,7 +271,7 @@ void *sieve_ast_extension_get_context node = node->next; \ } \ return TRUE; \ - } + } #define __LIST_DETACH(first, node_type, count) { \ node_type *last, *result; \ @@ -307,22 +307,22 @@ void *sieve_ast_extension_get_context /* List of AST nodes */ -static struct sieve_ast_list *sieve_ast_list_create(pool_t pool) +static struct sieve_ast_list *sieve_ast_list_create(pool_t pool) __LIST_CREATE(pool, struct sieve_ast_list) static bool sieve_ast_list_add -(struct sieve_ast_list *list, struct sieve_ast_node *node) +(struct sieve_ast_list *list, struct sieve_ast_node *node) __LIST_ADD(list, node) static struct sieve_ast_node *sieve_ast_list_detach -(struct sieve_ast_node *first, unsigned int count) +(struct sieve_ast_node *first, unsigned int count) __LIST_DETACH(first, struct sieve_ast_node, count) /* List of argument AST nodes */ -struct sieve_ast_arg_list *sieve_ast_arg_list_create(pool_t pool) +struct sieve_ast_arg_list *sieve_ast_arg_list_create(pool_t pool) __LIST_CREATE(pool, struct sieve_ast_arg_list) - + bool sieve_ast_arg_list_add (struct sieve_ast_arg_list *list, struct sieve_ast_argument *argument) __LIST_ADD(list, argument) @@ -341,145 +341,145 @@ static struct sieve_ast_argument *sieve_ast_arg_list_detach __LIST_DETACH(first, struct sieve_ast_argument, count) void sieve_ast_arg_list_substitute -(struct sieve_ast_arg_list *list, struct sieve_ast_argument *argument, +(struct sieve_ast_arg_list *list, struct sieve_ast_argument *argument, struct sieve_ast_argument *replacement) { if ( list->head == argument ) list->head = replacement; if ( list->tail == argument ) list->tail = replacement; - + if ( argument->prev != NULL ) argument->prev->next = replacement; if ( argument->next != NULL ) argument->next->prev = replacement; - + replacement->prev = argument->prev; replacement->next = argument->next; replacement->list = argument->list; - + argument->next = NULL; argument->prev = NULL; } - -/* - * AST node + +/* + * AST node */ static struct sieve_ast_node *sieve_ast_node_create -(struct sieve_ast *ast, struct sieve_ast_node *parent, enum sieve_ast_type type, - unsigned int source_line) +(struct sieve_ast *ast, struct sieve_ast_node *parent, enum sieve_ast_type type, + unsigned int source_line) { struct sieve_ast_node *node = p_new(ast->pool, struct sieve_ast_node, 1); - + node->ast = ast; node->parent = parent; node->type = type; - + node->prev = NULL; node->next = NULL; - + node->arguments = NULL; node->tests = NULL; - node->commands = NULL; - + node->commands = NULL; + node->test_list = FALSE; node->block = FALSE; - + node->source_line = source_line; - + return node; } static bool sieve_ast_node_add_command -(struct sieve_ast_node *node, struct sieve_ast_node *command) +(struct sieve_ast_node *node, struct sieve_ast_node *command) { - i_assert( command->type == SAT_COMMAND && + i_assert( command->type == SAT_COMMAND && (node->type == SAT_ROOT || node->type == SAT_COMMAND) ); - - if (node->commands == NULL) + + if (node->commands == NULL) node->commands = sieve_ast_list_create(node->ast->pool); - + return sieve_ast_list_add(node->commands, command); } static bool sieve_ast_node_add_test -(struct sieve_ast_node *node, struct sieve_ast_node *test) +(struct sieve_ast_node *node, struct sieve_ast_node *test) { - i_assert( test->type == SAT_TEST && + i_assert( test->type == SAT_TEST && (node->type == SAT_TEST || node->type == SAT_COMMAND) ); - - if (node->tests == NULL) + + if (node->tests == NULL) node->tests = sieve_ast_list_create(node->ast->pool); - + return sieve_ast_list_add(node->tests, test); } static bool sieve_ast_node_add_argument -(struct sieve_ast_node *node, struct sieve_ast_argument *argument) +(struct sieve_ast_node *node, struct sieve_ast_argument *argument) { i_assert( node->type == SAT_TEST || node->type == SAT_COMMAND ); - - if (node->arguments == NULL) + + if (node->arguments == NULL) node->arguments = sieve_ast_arg_list_create(node->ast->pool); - + return sieve_ast_arg_list_add(node->arguments, argument); } struct sieve_ast_node *sieve_ast_node_detach -(struct sieve_ast_node *first) -{ +(struct sieve_ast_node *first) +{ return sieve_ast_list_detach(first, 1); } const char *sieve_ast_type_name -(enum sieve_ast_type ast_type) +(enum sieve_ast_type ast_type) { switch ( ast_type ) { - + case SAT_NONE: return "none"; case SAT_ROOT: return "ast root node"; case SAT_COMMAND: return "command"; case SAT_TEST: return "test"; - + default: return "??AST NODE??"; } } -/* - * Argument AST node +/* + * Argument AST node */ struct sieve_ast_argument *sieve_ast_argument_create -(struct sieve_ast *ast, unsigned int source_line) -{ - struct sieve_ast_argument *arg = +(struct sieve_ast *ast, unsigned int source_line) +{ + struct sieve_ast_argument *arg = p_new(ast->pool, struct sieve_ast_argument, 1); - + arg->ast = ast; - + arg->prev = NULL; arg->next = NULL; - + arg->source_line = source_line; - + arg->argument = NULL; - + return arg; } static void sieve_ast_argument_substitute -(struct sieve_ast_argument *argument, struct sieve_ast_argument *replacement) +(struct sieve_ast_argument *argument, struct sieve_ast_argument *replacement) { sieve_ast_arg_list_substitute(argument->list, argument, replacement); } struct sieve_ast_argument *sieve_ast_argument_string_create_raw -(struct sieve_ast *ast, string_t *str, unsigned int source_line) +(struct sieve_ast *ast, string_t *str, unsigned int source_line) { struct sieve_ast_argument *argument = sieve_ast_argument_create (ast, source_line); - + argument->type = SAAT_STRING; argument->_value.str = str; @@ -487,17 +487,17 @@ struct sieve_ast_argument *sieve_ast_argument_string_create_raw } struct sieve_ast_argument *sieve_ast_argument_string_create -(struct sieve_ast_node *node, const string_t *str, unsigned int source_line) -{ +(struct sieve_ast_node *node, const string_t *str, unsigned int source_line) +{ struct sieve_ast_argument *argument; string_t *newstr; - + /* Allocate new internal string buffer */ newstr = str_new(node->ast->pool, str_len(str)); - + /* Clone string */ str_append_str(newstr, str); - + /* Create string argument */ argument = sieve_ast_argument_string_create_raw (node->ast, newstr, source_line); @@ -509,17 +509,17 @@ struct sieve_ast_argument *sieve_ast_argument_string_create } struct sieve_ast_argument *sieve_ast_argument_cstring_create -(struct sieve_ast_node *node, const char *str, unsigned int source_line) -{ +(struct sieve_ast_node *node, const char *str, unsigned int source_line) +{ struct sieve_ast_argument *argument; string_t *newstr; - + /* Allocate new internal string buffer */ newstr = str_new(node->ast->pool, strlen(str)); - + /* Clone string */ str_append(newstr, str); - + /* Create string argument */ argument = sieve_ast_argument_string_create_raw (node->ast, newstr, source_line); @@ -541,7 +541,7 @@ void sieve_ast_argument_string_setc (struct sieve_ast_argument *argument, const char *newstr) { i_assert( argument->type == SAAT_STRING); - + str_truncate(argument->_value.str, 0); str_append(argument->_value.str, newstr); } @@ -554,62 +554,62 @@ void sieve_ast_argument_number_substitute } struct sieve_ast_argument *sieve_ast_argument_stringlist_create -(struct sieve_ast_node *node, unsigned int source_line) +(struct sieve_ast_node *node, unsigned int source_line) { - struct sieve_ast_argument *argument = + struct sieve_ast_argument *argument = sieve_ast_argument_create(node->ast, source_line); - + argument->type = SAAT_STRING_LIST; argument->_value.strlist = NULL; - + sieve_ast_node_add_argument(node, argument); return argument; } struct sieve_ast_argument *sieve_ast_argument_stringlist_substitute -(struct sieve_ast_node *node, struct sieve_ast_argument *arg) +(struct sieve_ast_node *node, struct sieve_ast_argument *arg) { - struct sieve_ast_argument *argument = + struct sieve_ast_argument *argument = sieve_ast_argument_create(node->ast, arg->source_line); - + argument->type = SAAT_STRING_LIST; argument->_value.strlist = NULL; - + sieve_ast_argument_substitute(arg, argument); return argument; } static inline bool _sieve_ast_stringlist_add_item -(struct sieve_ast_argument *list, struct sieve_ast_argument *item) +(struct sieve_ast_argument *list, struct sieve_ast_argument *item) { i_assert( list->type == SAAT_STRING_LIST ); - - if ( list->_value.strlist == NULL ) + + if ( list->_value.strlist == NULL ) list->_value.strlist = sieve_ast_arg_list_create(list->ast->pool); - + return sieve_ast_arg_list_add(list->_value.strlist, item); } static bool sieve_ast_stringlist_add_stringlist -(struct sieve_ast_argument *list, struct sieve_ast_argument *items) +(struct sieve_ast_argument *list, struct sieve_ast_argument *items) { i_assert( list->type == SAAT_STRING_LIST ); i_assert( items->type == SAAT_STRING_LIST ); - if ( list->_value.strlist == NULL ) + if ( list->_value.strlist == NULL ) list->_value.strlist = sieve_ast_arg_list_create(list->ast->pool); - + return sieve_ast_arg_list_join(list->_value.strlist, items->_value.strlist); } static bool _sieve_ast_stringlist_add_str -(struct sieve_ast_argument *list, string_t *str, unsigned int source_line) +(struct sieve_ast_argument *list, string_t *str, unsigned int source_line) { struct sieve_ast_argument *stritem; - - stritem = sieve_ast_argument_create(list->ast, source_line); + + stritem = sieve_ast_argument_create(list->ast, source_line); stritem->type = SAAT_STRING; stritem->_value.str = str; @@ -617,7 +617,7 @@ static bool _sieve_ast_stringlist_add_str } bool sieve_ast_stringlist_add -(struct sieve_ast_argument *list, const string_t *str, unsigned int source_line) +(struct sieve_ast_argument *list, const string_t *str, unsigned int source_line) { string_t *copied_str = str_new(list->ast->pool, str_len(str)); str_append_str(copied_str, str); @@ -626,20 +626,20 @@ bool sieve_ast_stringlist_add } bool sieve_ast_stringlist_add_strc -(struct sieve_ast_argument *list, const char *str, unsigned int source_line) +(struct sieve_ast_argument *list, const char *str, unsigned int source_line) { string_t *copied_str = str_new(list->ast->pool, strlen(str)); str_append(copied_str, str); - + return _sieve_ast_stringlist_add_str(list, copied_str, source_line); } struct sieve_ast_argument *sieve_ast_argument_tag_create -(struct sieve_ast_node *node, const char *tag, unsigned int source_line) -{ - struct sieve_ast_argument *argument = +(struct sieve_ast_node *node, const char *tag, unsigned int source_line) +{ + struct sieve_ast_argument *argument = sieve_ast_argument_create(node->ast, source_line); - + argument->type = SAAT_TAG; argument->_value.tag = p_strdup(node->ast->pool, tag); @@ -650,33 +650,33 @@ struct sieve_ast_argument *sieve_ast_argument_tag_create } struct sieve_ast_argument *sieve_ast_argument_tag_insert -(struct sieve_ast_argument *before, const char *tag, unsigned int source_line) -{ - struct sieve_ast_argument *argument = +(struct sieve_ast_argument *before, const char *tag, unsigned int source_line) +{ + struct sieve_ast_argument *argument = sieve_ast_argument_create(before->ast, source_line); - + argument->type = SAAT_TAG; argument->_value.tag = p_strdup(before->ast->pool, tag); if ( !sieve_ast_arg_list_insert(before->list, before, argument) ) return NULL; - + return argument; } struct sieve_ast_argument *sieve_ast_argument_number_create -(struct sieve_ast_node *node, unsigned int number, unsigned int source_line) +(struct sieve_ast_node *node, unsigned int number, unsigned int source_line) { - - struct sieve_ast_argument *argument = + + struct sieve_ast_argument *argument = sieve_ast_argument_create(node->ast, source_line); - + argument->type = SAAT_NUMBER; argument->_value.number = number; - + if ( !sieve_ast_node_add_argument(node, argument) ) return NULL; - + return argument; } @@ -689,8 +689,8 @@ void sieve_ast_argument_number_set struct sieve_ast_argument *sieve_ast_arguments_detach -(struct sieve_ast_argument *first, unsigned int count) -{ +(struct sieve_ast_argument *first, unsigned int count) +{ return sieve_ast_arg_list_detach(first, count); } @@ -701,16 +701,16 @@ bool sieve_ast_argument_attach } const char *sieve_ast_argument_type_name -(enum sieve_ast_argument_type arg_type) +(enum sieve_ast_argument_type arg_type) { switch ( arg_type ) { - + case SAAT_NONE: return "none"; case SAAT_STRING_LIST: return "a string list"; case SAAT_STRING: return "a string"; case SAAT_NUMBER: return "a number"; case SAAT_TAG: return "a tag"; - + default: return "??ARGUMENT??"; } } @@ -718,35 +718,35 @@ const char *sieve_ast_argument_type_name /* Test AST node */ struct sieve_ast_node *sieve_ast_test_create -(struct sieve_ast_node *parent, const char *identifier, - unsigned int source_line) -{ +(struct sieve_ast_node *parent, const char *identifier, + unsigned int source_line) +{ struct sieve_ast_node *test = sieve_ast_node_create (parent->ast, parent, SAT_TEST, source_line); - + test->identifier = p_strdup(parent->ast->pool, identifier); - + if ( !sieve_ast_node_add_test(parent, test) ) return NULL; - + return test; } /* Command AST node */ struct sieve_ast_node *sieve_ast_command_create -(struct sieve_ast_node *parent, const char *identifier, - unsigned int source_line) +(struct sieve_ast_node *parent, const char *identifier, + unsigned int source_line) { struct sieve_ast_node *command = sieve_ast_node_create (parent->ast, parent, SAT_COMMAND, source_line); - + command->identifier = p_strdup(parent->ast->pool, identifier); - + if ( !sieve_ast_node_add_command(parent, command) ) return NULL; - + return command; } @@ -762,22 +762,22 @@ int sieve_ast_stringlist_map /* Single string */ return map_function(context, *listitem); } else if ( sieve_ast_argument_type(*listitem) == SAAT_STRING_LIST ) { - int ret = 0; - + int ret = 0; + /* String list */ *listitem = sieve_ast_strlist_first(*listitem); - + while ( *listitem != NULL ) { - + if ( (ret=map_function(context, *listitem)) <= 0 ) return ret; - + *listitem = sieve_ast_strlist_next(*listitem); } - + return ret; - } - + } + i_unreached(); return -1; } @@ -787,75 +787,75 @@ struct sieve_ast_argument *sieve_ast_stringlist_join { enum sieve_ast_argument_type list_type, items_type; struct sieve_ast_argument *newlist; - + list_type = sieve_ast_argument_type(list); items_type = sieve_ast_argument_type(items); - + switch ( list_type ) { - + case SAAT_STRING: switch ( items_type ) { - + case SAAT_STRING: - newlist = + newlist = sieve_ast_argument_create(list->ast, list->source_line); newlist->type = SAAT_STRING_LIST; newlist->_value.strlist = NULL; - + sieve_ast_argument_substitute(list, newlist); sieve_ast_arguments_detach(items, 1); - + if ( !_sieve_ast_stringlist_add_item(newlist, list) || !_sieve_ast_stringlist_add_item(newlist, items) ) { return NULL; } - + return newlist; - + case SAAT_STRING_LIST: /* Adding stringlist to string; make them swith places and add one to the * other. */ sieve_ast_arguments_detach(items, 1); sieve_ast_argument_substitute(list, items); - if ( !_sieve_ast_stringlist_add_item(items, list) ) + if ( !_sieve_ast_stringlist_add_item(items, list) ) return NULL; - + return list; - + default: i_unreached(); } break; - + case SAAT_STRING_LIST: switch ( items_type ) { - + case SAAT_STRING: /* Adding string to stringlist; straightforward add */ sieve_ast_arguments_detach(items, 1); if ( !_sieve_ast_stringlist_add_item(list, items) ) return NULL; - + return list; - + case SAAT_STRING_LIST: /* Adding stringlist to stringlist; perform actual join */ sieve_ast_arguments_detach(items, 1); if ( !sieve_ast_stringlist_add_stringlist(list, items) ) return NULL; - + return list; - + default: i_unreached(); } - + break; default: i_unreached(); } - + return NULL; } @@ -864,7 +864,7 @@ struct sieve_ast_argument *sieve_ast_stringlist_join /* Unparsing, currently implemented using plain printf()s */ -static void sieve_ast_unparse_string(const string_t *strval) +static void sieve_ast_unparse_string(const string_t *strval) { char *str = t_strdup_noconst(str_c((string_t *) strval)); @@ -873,35 +873,35 @@ static void sieve_ast_unparse_string(const string_t *strval) char *spos = str; char *epos = strchr(str, '\n'); printf("text:\n"); - + while ( epos != NULL ) { *epos = '\0'; - if ( *spos == '.' ) + if ( *spos == '.' ) printf("."); - + printf("%s\n", spos); - + spos = epos+1; epos = strchr(spos, '\n'); } - if ( *spos == '.' ) + if ( *spos == '.' ) printf("."); - - printf("%s\n.\n", spos); + + printf("%s\n.\n", spos); } else { /* Print it as a quoted string and escape " */ char *spos = str; char *epos = strchr(str, '"'); printf("\""); - + while ( epos != NULL ) { *epos = '\0'; printf("%s\\\"", spos); - + spos = epos+1; epos = strchr(spos, '"'); } - + printf("%s\"", spos); } } @@ -910,43 +910,43 @@ static void sieve_ast_unparse_argument (struct sieve_ast_argument *argument, int level); static void sieve_ast_unparse_stringlist -(struct sieve_ast_argument *strlist, int level) +(struct sieve_ast_argument *strlist, int level) { struct sieve_ast_argument *stritem; - - if ( sieve_ast_strlist_count(strlist) > 1 ) { + + if ( sieve_ast_strlist_count(strlist) > 1 ) { int i; - + printf("[\n"); - + /* Create indent */ - for ( i = 0; i < level+2; i++ ) - printf(" "); + for ( i = 0; i < level+2; i++ ) + printf(" "); stritem = sieve_ast_strlist_first(strlist); if ( stritem != NULL ) { sieve_ast_unparse_string(sieve_ast_strlist_str(stritem)); - + stritem = sieve_ast_strlist_next(stritem); while ( stritem != NULL ) { printf(",\n"); - for ( i = 0; i < level+2; i++ ) + for ( i = 0; i < level+2; i++ ) printf(" "); sieve_ast_unparse_string(sieve_ast_strlist_str(stritem)); stritem = sieve_ast_strlist_next(stritem); } } - + printf(" ]"); } else { stritem = sieve_ast_strlist_first(strlist); - if ( stritem != NULL ) + if ( stritem != NULL ) sieve_ast_unparse_string(sieve_ast_strlist_str(stritem)); } } static void sieve_ast_unparse_argument -(struct sieve_ast_argument *argument, int level) +(struct sieve_ast_argument *argument, int level) { switch ( argument->type ) { case SAAT_STRING: @@ -971,107 +971,107 @@ static void sieve_ast_unparse_test (struct sieve_ast_node *node, int level); static void sieve_ast_unparse_tests -(struct sieve_ast_node *node, int level) +(struct sieve_ast_node *node, int level) { struct sieve_ast_node *test; - - if ( sieve_ast_test_count(node) > 1 ) { + + if ( sieve_ast_test_count(node) > 1 ) { int i; - + printf(" (\n"); - + /* Create indent */ - for ( i = 0; i < level+2; i++ ) - printf(" "); + for ( i = 0; i < level+2; i++ ) + printf(" "); test = sieve_ast_test_first(node); sieve_ast_unparse_test(test, level+1); - + test = sieve_ast_test_next(test); while ( test != NULL ) { printf(", \n"); - for ( i = 0; i < level+2; i++ ) + for ( i = 0; i < level+2; i++ ) printf(" "); sieve_ast_unparse_test(test, level+1); test = sieve_ast_test_next(test); } - + printf(" )"); } else { test = sieve_ast_test_first(node); - if ( test != NULL ) + if ( test != NULL ) sieve_ast_unparse_test(test, level); } } static void sieve_ast_unparse_test -(struct sieve_ast_node *node, int level) +(struct sieve_ast_node *node, int level) { struct sieve_ast_argument *argument; - + printf(" %s", node->identifier); - + argument = sieve_ast_argument_first(node); while ( argument != NULL ) { printf(" "); sieve_ast_unparse_argument(argument, level); argument = sieve_ast_argument_next(argument); } - + sieve_ast_unparse_tests(node, level); } static void sieve_ast_unparse_command -(struct sieve_ast_node *node, int level) +(struct sieve_ast_node *node, int level) { struct sieve_ast_node *command; struct sieve_ast_argument *argument; - + int i; - + /* Create indent */ - for ( i = 0; i < level; i++ ) + for ( i = 0; i < level; i++ ) printf(" "); - + printf("%s", node->identifier); - + argument = sieve_ast_argument_first(node); while ( argument != NULL ) { printf(" "); sieve_ast_unparse_argument(argument, level); argument = sieve_ast_argument_next(argument); } - + sieve_ast_unparse_tests(node, level); - + command = sieve_ast_command_first(node); if ( command != NULL ) { printf(" {\n"); - - while ( command != NULL) { + + while ( command != NULL) { sieve_ast_unparse_command(command, level+1); command = sieve_ast_command_next(command); } - - for ( i = 0; i < level; i++ ) + + for ( i = 0; i < level; i++ ) printf(" "); printf("}\n"); - } else + } else printf(";\n"); } -void sieve_ast_unparse(struct sieve_ast *ast) +void sieve_ast_unparse(struct sieve_ast *ast) { struct sieve_ast_node *command; printf("Unparsing Abstract Syntax Tree:\n"); - T_BEGIN { + T_BEGIN { command = sieve_ast_command_first(sieve_ast_root(ast)); - while ( command != NULL ) { + while ( command != NULL ) { sieve_ast_unparse_command(command, 0); command = sieve_ast_command_next(command); - } + } } T_END; } diff --git a/src/lib-sieve/sieve-ast.h b/src/lib-sieve/sieve-ast.h index 0da2b984a67b4fd4127271360272c530e64518b2..16cb2215ddd2c347d0288cd9cff9fe3147c7b675 100644 --- a/src/lib-sieve/sieve-ast.h +++ b/src/lib-sieve/sieve-ast.h @@ -12,7 +12,7 @@ /* Abstract Syntax Tree (AST) structure: - + sieve_ast (root) [*command] | @@ -26,30 +26,30 @@ | | [number | tag | *string] | . . - + *test +-- test: | .... +-- test: | [identifier *argument *test] - | +-- argument: \--> as from the top + | +-- argument: \--> as from the top . | .... of this tree +-- argument: | [number | tag | *string] . - - Tests and commands are defined using the same structure: sieve_ast_node. - However, arguments and string-lists are described using sieve_ast_argument. + + Tests and commands are defined using the same structure: sieve_ast_node. + However, arguments and string-lists are described using sieve_ast_argument. */ -/* IMPORTANT NOTICE: Do not decorate the AST with objects other than those - * allocated on the ast's pool or static const objects. Otherwise it is possible +/* IMPORTANT NOTICE: Do not decorate the AST with objects other than those + * allocated on the ast's pool or static const objects. Otherwise it is possible * that pointers in the tree become dangling which is highly undesirable. */ /* * Forward declarations - */ + */ struct sieve_ast_list; struct sieve_ast_arg_list; @@ -57,7 +57,7 @@ struct sieve_ast_arg_list; /* * Types */ - + enum sieve_ast_argument_type { SAAT_NONE, SAAT_NUMBER, @@ -76,7 +76,7 @@ enum sieve_ast_type { /* * AST Nodes */ - + /* Argument node */ struct sieve_ast_argument { @@ -89,18 +89,18 @@ struct sieve_ast_argument { struct sieve_ast_arg_list *list; struct sieve_ast_argument *next; struct sieve_ast_argument *prev; - + /* Parser-assigned data */ - - union { + + union { string_t *str; struct sieve_ast_arg_list *strlist; const char *tag; unsigned int number; } _value; - + unsigned int source_line; - + /* Assigned during validation */ /* Argument associated with this ast element */ @@ -115,60 +115,60 @@ struct sieve_ast_node { /* Back reference to the AST object */ struct sieve_ast *ast; - + /* Back reference to this node's parent */ struct sieve_ast_node *parent; - + /* Linked list references */ struct sieve_ast_list *list; struct sieve_ast_node *next; struct sieve_ast_node *prev; - + /* Commands (NULL if not allocated) */ bool block; struct sieve_ast_list *commands; - + /* Tests (NULL if not allocated)*/ bool test_list; struct sieve_ast_list *tests; /* Arguments (NULL if not allocated) */ - struct sieve_ast_arg_list *arguments; + struct sieve_ast_arg_list *arguments; /* Identifier of command or test */ - const char *identifier; + const char *identifier; /* The location in the file where this command was started */ unsigned int source_line; - + /* Assigned during validation */ - + /* Context */ - struct sieve_command *command; + struct sieve_command *command; }; /* * AST node lists */ - + struct sieve_ast_list { - struct sieve_ast_node *head; + struct sieve_ast_node *head; struct sieve_ast_node *tail; - unsigned int len; + unsigned int len; }; struct sieve_ast_arg_list { - struct sieve_ast_argument *head; + struct sieve_ast_argument *head; struct sieve_ast_argument *tail; - unsigned int len; + unsigned int len; }; /* - * AST object + * AST object */ - -struct sieve_ast; - + +struct sieve_ast; + struct sieve_ast *sieve_ast_create(struct sieve_script *script); void sieve_ast_ref(struct sieve_ast *ast); void sieve_ast_unref(struct sieve_ast **ast); @@ -180,9 +180,9 @@ struct sieve_script *sieve_ast_script(struct sieve_ast *ast); /* Extension support */ struct sieve_ast_extension { - const struct sieve_extension_def *ext; + const struct sieve_extension_def *ext; - void (*free)(const struct sieve_extension *ext, struct sieve_ast *ast, + void (*free)(const struct sieve_extension *ext, struct sieve_ast *ast, void *context); }; @@ -199,37 +199,37 @@ void sieve_ast_extension_set_context void *sieve_ast_extension_get_context (struct sieve_ast *ast, const struct sieve_extension *ext); -/* +/* * AST node manipulation */ - + /* Command nodes */ struct sieve_ast_node *sieve_ast_test_create - (struct sieve_ast_node *parent, const char *identifier, + (struct sieve_ast_node *parent, const char *identifier, unsigned int source_line); struct sieve_ast_node *sieve_ast_command_create - (struct sieve_ast_node *parent, const char *identifier, + (struct sieve_ast_node *parent, const char *identifier, unsigned int source_line); struct sieve_ast_node *sieve_ast_node_detach (struct sieve_ast_node *first); const char *sieve_ast_type_name(enum sieve_ast_type ast_type); - + /* Argument nodes */ struct sieve_ast_argument *sieve_ast_argument_create (struct sieve_ast *ast, unsigned int source_line); -struct sieve_ast_arg_list *sieve_ast_arg_list_create(pool_t pool); +struct sieve_ast_arg_list *sieve_ast_arg_list_create(pool_t pool); bool sieve_ast_arg_list_add (struct sieve_ast_arg_list *list, struct sieve_ast_argument *argument); bool sieve_ast_arg_list_insert (struct sieve_ast_arg_list *list, struct sieve_ast_argument *before, struct sieve_ast_argument *argument); void sieve_ast_arg_list_substitute - (struct sieve_ast_arg_list *list, struct sieve_ast_argument *argument, + (struct sieve_ast_arg_list *list, struct sieve_ast_argument *argument, struct sieve_ast_argument *replacement); struct sieve_ast_argument *sieve_ast_argument_string_create_raw @@ -238,7 +238,7 @@ struct sieve_ast_argument *sieve_ast_argument_string_create (struct sieve_ast_node *node, const string_t *str, unsigned int source_line); struct sieve_ast_argument *sieve_ast_argument_cstring_create (struct sieve_ast_node *node, const char *str, unsigned int source_line); - + struct sieve_ast_argument *sieve_ast_argument_tag_create (struct sieve_ast_node *node, const char *tag, unsigned int source_line); @@ -256,7 +256,7 @@ void sieve_ast_argument_number_substitute (struct sieve_ast_argument *argument, unsigned int number); struct sieve_ast_argument *sieve_ast_argument_tag_insert -(struct sieve_ast_argument *before, const char *tag, unsigned int source_line); +(struct sieve_ast_argument *before, const char *tag, unsigned int source_line); struct sieve_ast_argument *sieve_ast_argument_stringlist_create (struct sieve_ast_node *node, unsigned int source_line); @@ -267,19 +267,19 @@ struct sieve_ast_argument *sieve_ast_arguments_detach (struct sieve_ast_argument *first, unsigned int count); bool sieve_ast_argument_attach (struct sieve_ast_node *node, struct sieve_ast_argument *argument); - + const char *sieve_ast_argument_type_name(enum sieve_ast_argument_type arg_type); #define sieve_ast_argument_name(argument) \ sieve_ast_argument_type_name((argument)->type) bool sieve_ast_stringlist_add - (struct sieve_ast_argument *list, const string_t *str, + (struct sieve_ast_argument *list, const string_t *str, unsigned int source_line); bool sieve_ast_stringlist_add_strc - (struct sieve_ast_argument *list, const char *str, + (struct sieve_ast_argument *list, const char *str, unsigned int source_line); - -/* + +/* * Utility */ @@ -288,9 +288,9 @@ int sieve_ast_stringlist_map int (*map_function)(void *context, struct sieve_ast_argument *arg)); struct sieve_ast_argument *sieve_ast_stringlist_join (struct sieve_ast_argument *list, struct sieve_ast_argument *items); - -/* - * AST access macros + +/* + * AST access macros */ /* Generic list access macros */ @@ -327,7 +327,7 @@ struct sieve_ast_argument *sieve_ast_stringlist_join #define sieve_ast_prev_cmd_is(cmd, id) \ ( (cmd)->prev == NULL ? FALSE : \ strncasecmp((cmd)->prev->identifier, id, sizeof(id)-1) == 0 ) - + /* AST test macros */ #define sieve_ast_test_count(node) __AST_NODE_LIST_COUNT(node, tests) #define sieve_ast_test_first(node) __AST_NODE_LIST_FIRST(node, tests) @@ -361,8 +361,8 @@ struct sieve_ast_argument *sieve_ast_stringlist_join #define sieve_ast_strlist_str(str) sieve_ast_argument_str(str) #define sieve_ast_strlist_strc(str) sieve_ast_argument_strc(str) -/* - * Debug +/* + * Debug */ void sieve_ast_unparse(struct sieve_ast *ast); diff --git a/src/lib-sieve/sieve-binary-code.c b/src/lib-sieve/sieve-binary-code.c index 055b0f5e83df43417aafd34a5b8d2166507b28d8..92202beb1a3240b0f02d50f098fec9a3f237c27a 100644 --- a/src/lib-sieve/sieve-binary-code.c +++ b/src/lib-sieve/sieve-binary-code.c @@ -32,8 +32,8 @@ static inline sieve_size_t sieve_binary_emit_dynamic_data /* Low-level emission functions */ static inline void _sieve_binary_emit_data -(struct sieve_binary_block *sblock, const void *data, sieve_size_t size) -{ +(struct sieve_binary_block *sblock, const void *data, sieve_size_t size) +{ buffer_append(sblock->data, data, size); } @@ -44,8 +44,8 @@ static inline void _sieve_binary_emit_byte } static inline void _sieve_binary_update_data -(struct sieve_binary_block *sblock, sieve_size_t address, const void *data, - sieve_size_t size) +(struct sieve_binary_block *sblock, sieve_size_t address, const void *data, + sieve_size_t size) { buffer_write(sblock->data, address, data, size); } @@ -61,18 +61,18 @@ sieve_size_t sieve_binary_emit_data } sieve_size_t sieve_binary_emit_byte -(struct sieve_binary_block *sblock, uint8_t byte) +(struct sieve_binary_block *sblock, uint8_t byte) { sieve_size_t address = _sieve_binary_block_get_size(sblock); _sieve_binary_emit_data(sblock, &byte, 1); - + return address; } void sieve_binary_update_data -(struct sieve_binary_block *sblock, sieve_size_t address, const void *data, - sieve_size_t size) +(struct sieve_binary_block *sblock, sieve_size_t address, const void *data, + sieve_size_t size) { _sieve_binary_update_data(sblock, address, data, size); } @@ -80,7 +80,7 @@ void sieve_binary_update_data /* Offset emission functions */ sieve_size_t sieve_binary_emit_offset -(struct sieve_binary_block *sblock, sieve_offset_t offset) +(struct sieve_binary_block *sblock, sieve_offset_t offset) { int i; sieve_size_t address = _sieve_binary_block_get_size(sblock); @@ -93,15 +93,15 @@ sieve_size_t sieve_binary_emit_offset } _sieve_binary_emit_data(sblock, encoded, 4); - + return address; } void sieve_binary_resolve_offset -(struct sieve_binary_block *sblock, sieve_size_t address) +(struct sieve_binary_block *sblock, sieve_size_t address) { int i; - sieve_offset_t offset = _sieve_binary_block_get_size(sblock) - address; + sieve_offset_t offset = _sieve_binary_block_get_size(sblock) - address; uint8_t encoded[4]; for ( i = 3; i >= 0; i-- ) { @@ -119,7 +119,7 @@ sieve_size_t sieve_binary_emit_integer { sieve_size_t address = _sieve_binary_block_get_size(sblock); uint8_t buffer[sizeof(sieve_number_t) + 1]; - int bufpos = sizeof(buffer) - 1; + int bufpos = sizeof(buffer) - 1; /* Encode last byte [0xxxxxxx]; msb == 0 marks the last byte */ buffer[bufpos] = integer & 0x7F; @@ -130,11 +130,11 @@ sieve_size_t sieve_binary_emit_integer while ( integer > 0 ) { buffer[bufpos] = (integer & 0x7F) | 0x80; bufpos--; - integer >>= 7; + integer >>= 7; } - + /* Emit encoded integer */ - bufpos++; + bufpos++; _sieve_binary_emit_data(sblock, buffer + bufpos, sizeof(buffer) - bufpos); return address; @@ -147,7 +147,7 @@ static inline sieve_size_t sieve_binary_emit_dynamic_data (sblock, (sieve_number_t) size); _sieve_binary_emit_data(sblock, data, size); - + return address; } @@ -157,7 +157,7 @@ sieve_size_t sieve_binary_emit_cstring sieve_size_t address = sieve_binary_emit_dynamic_data (sblock, (void *) str, (sieve_size_t) strlen(str)); _sieve_binary_emit_byte(sblock, 0); - + return address; } @@ -167,7 +167,7 @@ sieve_size_t sieve_binary_emit_string sieve_size_t address = sieve_binary_emit_dynamic_data (sblock, (void *) str_data(str), (sieve_size_t) str_len(str)); _sieve_binary_emit_byte(sblock, 0); - + return address; } @@ -205,7 +205,7 @@ void sieve_binary_emit_extension_object #define ADDR_CODE_READ(block) \ size_t _code_size; \ const int8_t *_code = buffer_get_data((block)->data, &_code_size) - + #define ADDR_CODE_AT(address) \ ((int8_t) (_code[*address])) #define ADDR_DATA_AT(address) \ @@ -221,81 +221,81 @@ void sieve_binary_emit_extension_object /* Literals */ bool sieve_binary_read_byte -(struct sieve_binary_block *sblock, sieve_size_t *address, unsigned int *byte_r) +(struct sieve_binary_block *sblock, sieve_size_t *address, unsigned int *byte_r) { ADDR_CODE_READ(sblock); - + if ( ADDR_BYTES_LEFT(address) >= 1 ) { if ( byte_r != NULL ) *byte_r = ADDR_DATA_AT(address); ADDR_JUMP(address, 1); - + return TRUE; } - + *byte_r = 0; return FALSE; } bool sieve_binary_read_code -(struct sieve_binary_block *sblock, sieve_size_t *address, signed int *code_r) -{ +(struct sieve_binary_block *sblock, sieve_size_t *address, signed int *code_r) +{ ADDR_CODE_READ(sblock); if ( ADDR_BYTES_LEFT(address) >= 1 ) { if ( code_r != NULL ) *code_r = ADDR_CODE_AT(address); ADDR_JUMP(address, 1); - + return TRUE; } - + *code_r = 0; return FALSE; } bool sieve_binary_read_offset -(struct sieve_binary_block *sblock, sieve_size_t *address, sieve_offset_t *offset_r) +(struct sieve_binary_block *sblock, sieve_size_t *address, sieve_offset_t *offset_r) { sieve_offset_t offs = 0; ADDR_CODE_READ(sblock); - + if ( ADDR_BYTES_LEFT(address) >= 4 ) { - int i; - + int i; + for ( i = 0; i < 4; i++ ) { offs = (offs << 8) + ADDR_DATA_AT(address); ADDR_JUMP(address, 1); } - + if ( offset_r != NULL ) *offset_r = offs; - + return TRUE; } - + return FALSE; } /* FIXME: might need negative numbers in the future */ bool sieve_binary_read_integer -(struct sieve_binary_block *sblock, sieve_size_t *address, sieve_number_t *int_r) +(struct sieve_binary_block *sblock, sieve_size_t *address, sieve_number_t *int_r) { int bits = sizeof(sieve_number_t) * 8; *int_r = 0; ADDR_CODE_READ(sblock); - + if ( ADDR_BYTES_LEFT(address) == 0 ) return FALSE; - /* Read first integer bytes [1xxxxxxx] */ + /* Read first integer bytes [1xxxxxxx] */ while ( (ADDR_DATA_AT(address) & 0x80) > 0 ) { if ( ADDR_BYTES_LEFT(address) > 0 && bits > 0) { *int_r |= ADDR_DATA_AT(address) & 0x7F; ADDR_JUMP(address, 1); - + /* Each byte encodes 7 bits of the integer */ *int_r <<= 7; bits -= 7; @@ -304,44 +304,44 @@ bool sieve_binary_read_integer return FALSE; } } - + /* Read last byte [0xxxxxxx] */ *int_r |= ADDR_DATA_AT(address) & 0x7F; ADDR_JUMP(address, 1); - + return TRUE; } bool sieve_binary_read_string -(struct sieve_binary_block *sblock, sieve_size_t *address, string_t **str_r) +(struct sieve_binary_block *sblock, sieve_size_t *address, string_t **str_r) { unsigned int strlen = 0; const char *strdata; ADDR_CODE_READ(sblock); - - if ( !sieve_binary_read_unsigned(sblock, address, &strlen) ) + + if ( !sieve_binary_read_unsigned(sblock, address, &strlen) ) return FALSE; - - if ( strlen > ADDR_BYTES_LEFT(address) ) + + if ( strlen > ADDR_BYTES_LEFT(address) ) return FALSE; - + strdata = (const char *) ADDR_POINTER(address); ADDR_JUMP(address, strlen); - + if ( ADDR_CODE_AT(address) != 0 ) return FALSE; - if ( str_r != NULL ) + if ( str_r != NULL ) *str_r = t_str_new_const(strdata, strlen); - + ADDR_JUMP(address, 1); - + return TRUE; } bool sieve_binary_read_extension -(struct sieve_binary_block *sblock, sieve_size_t *address, +(struct sieve_binary_block *sblock, sieve_size_t *address, unsigned int *offset_r, const struct sieve_extension **ext_r) { unsigned int code; @@ -358,8 +358,8 @@ bool sieve_binary_read_extension if ( code >= offset ) { ext = sieve_binary_extension_get_by_index(sblock->sbin, code - offset); - - if ( ext == NULL ) + + if ( ext == NULL ) return FALSE; } @@ -369,14 +369,14 @@ bool sieve_binary_read_extension } const void *sieve_binary_read_extension_object -(struct sieve_binary_block *sblock, sieve_size_t *address, +(struct sieve_binary_block *sblock, sieve_size_t *address, const struct sieve_extension_objects *objs) { unsigned int code; ADDR_CODE_READ(sblock); - if ( objs->count == 0 ) + if ( objs->count == 0 ) return NULL; if ( objs->count == 1 ) @@ -386,7 +386,7 @@ const void *sieve_binary_read_extension_object return NULL; code = ADDR_DATA_AT(address); - ADDR_JUMP(address, 1); + ADDR_JUMP(address, 1); if ( code >= objs->count ) return NULL; diff --git a/src/lib-sieve/sieve-binary-debug.c b/src/lib-sieve/sieve-binary-debug.c index ff8b7a6aa20da17a0cba6ba7dcf20f02ce96ba9a..09e07ff9ab72e78454c8669c7e3a8f200167296c 100644 --- a/src/lib-sieve/sieve-binary-debug.c +++ b/src/lib-sieve/sieve-binary-debug.c @@ -14,7 +14,7 @@ #if 0 #define debug_printf(...) printf ("lineinfo: " __VA_ARGS__) #else -#define debug_printf(...) +#define debug_printf(...) #endif /* @@ -63,19 +63,19 @@ void sieve_binary_debug_writer_deinit } void sieve_binary_debug_emit -(struct sieve_binary_debug_writer *dwriter, sieve_size_t code_address, +(struct sieve_binary_debug_writer *dwriter, sieve_size_t code_address, unsigned int code_line, unsigned int code_column) { struct sieve_binary_block *sblock = dwriter->sblock; sieve_size_t address_inc = code_address - dwriter->address; unsigned int line_inc = code_line - dwriter->line; unsigned int sp_opcode = 0; - + /* Check for applicability of special opcode */ if ( (LINPROG_LINE_BASE + LINPROG_LINE_RANGE - 1) >= line_inc ) { - sp_opcode = LINPROG_OP_SPECIAL_BASE + (line_inc - LINPROG_LINE_BASE) + + sp_opcode = LINPROG_OP_SPECIAL_BASE + (line_inc - LINPROG_LINE_BASE) + (LINPROG_LINE_RANGE * address_inc); - + if ( sp_opcode > 255 ) sp_opcode = 0; } @@ -92,7 +92,7 @@ void sieve_binary_debug_emit (void)sieve_binary_emit_unsigned(sblock, address_inc); } } else { - (void)sieve_binary_emit_byte(sblock, sp_opcode); + (void)sieve_binary_emit_byte(sblock, sp_opcode); } /* Set column */ @@ -154,16 +154,16 @@ void sieve_binary_debug_reader_reset unsigned int sieve_binary_debug_read_line (struct sieve_binary_debug_reader *dreader, sieve_size_t code_address) { - size_t linprog_size; + size_t linprog_size; sieve_size_t address; unsigned long int line; if ( code_address < dreader->last_address ) sieve_binary_debug_reader_reset(dreader); - if ( code_address >= dreader->last_address && + if ( code_address >= dreader->last_address && code_address < dreader->address ) { - debug_printf("%08llx: NOOP [%08llx]\n", + debug_printf("%08llx: NOOP [%08llx]\n", (unsigned long long) dreader->state, (unsigned long long) code_address); return dreader->last_line; } @@ -171,7 +171,7 @@ unsigned int sieve_binary_debug_read_line address = dreader->address; line = dreader->line; - debug_printf("%08llx: READ [%08llx]\n", + debug_printf("%08llx: READ [%08llx]\n", (unsigned long long) dreader->state, (unsigned long long) code_address); linprog_size = sieve_binary_block_get_size(dreader->sblock); @@ -183,12 +183,12 @@ unsigned int sieve_binary_debug_read_line switch ( opcode ) { case LINPROG_OP_COPY: - debug_printf("%08llx: COPY ==> %08llx: %ld\n", - (unsigned long long) dreader->state, (unsigned long long) address, + debug_printf("%08llx: COPY ==> %08llx: %ld\n", + (unsigned long long) dreader->state, (unsigned long long) address, line); - - dreader->last_address = dreader->address; - dreader->last_line = dreader->line; + + dreader->last_address = dreader->address; + dreader->last_line = dreader->line; dreader->address = address; dreader->line = line; @@ -231,7 +231,7 @@ unsigned int sieve_binary_debug_read_line } debug_printf(" : = %d\n", value); dreader->column = value; - break; + break; default: opcode -= LINPROG_OP_SPECIAL_BASE; @@ -241,7 +241,7 @@ unsigned int sieve_binary_debug_read_line debug_printf("%08llx: SPECIAL\n", (unsigned long long) dreader->state); debug_printf(" : +A %d +L %d\n", (opcode / LINPROG_LINE_RANGE), - LINPROG_LINE_BASE + (opcode % LINPROG_LINE_RANGE)); + LINPROG_LINE_BASE + (opcode % LINPROG_LINE_RANGE)); break; } } else { diff --git a/src/lib-sieve/sieve-binary-dumper.c b/src/lib-sieve/sieve-binary-dumper.c index baf8efed16cc377e5db4e65a28f2483c3679916b..a8ec957e58fe8ebd24e8c165a6d095e2fe8aa421 100644 --- a/src/lib-sieve/sieve-binary-dumper.c +++ b/src/lib-sieve/sieve-binary-dumper.c @@ -15,39 +15,39 @@ /* * Binary dumper object - */ - + */ + struct sieve_binary_dumper { pool_t pool; - + /* Dumptime environment */ - struct sieve_dumptime_env dumpenv; + struct sieve_dumptime_env dumpenv; }; struct sieve_binary_dumper *sieve_binary_dumper_create -(struct sieve_binary *sbin) +(struct sieve_binary *sbin) { pool_t pool; struct sieve_binary_dumper *dumper; - - pool = pool_alloconly_create("sieve_binary_dumper", 4096); + + pool = pool_alloconly_create("sieve_binary_dumper", 4096); dumper = p_new(pool, struct sieve_binary_dumper, 1); dumper->pool = pool; dumper->dumpenv.dumper = dumper; - + dumper->dumpenv.sbin = sbin; sieve_binary_ref(sbin); - + dumper->dumpenv.svinst = sieve_binary_svinst(sbin); return dumper; } -void sieve_binary_dumper_free(struct sieve_binary_dumper **dumper) +void sieve_binary_dumper_free(struct sieve_binary_dumper **dumper) { sieve_binary_unref(&(*dumper)->dumpenv.sbin); pool_unref(&((*dumper)->pool)); - + *dumper = NULL; } @@ -56,20 +56,20 @@ pool_t sieve_binary_dumper_pool(struct sieve_binary_dumper *dumper) return dumper->pool; } -/* - * Formatted output +/* + * Formatted output */ void sieve_binary_dumpf (const struct sieve_dumptime_env *denv, const char *fmt, ...) -{ +{ string_t *outbuf = t_str_new(128); va_list args; - - va_start(args, fmt); + + va_start(args, fmt); str_vprintfa(outbuf, fmt, args); va_end(args); - + o_stream_send(denv->stream, str_data(outbuf), str_len(outbuf)); } @@ -78,27 +78,27 @@ void sieve_binary_dump_sectionf { string_t *outbuf = t_str_new(128); va_list args; - - va_start(args, fmt); + + va_start(args, fmt); str_printfa(outbuf, "\n* "); str_vprintfa(outbuf, fmt, args); str_printfa(outbuf, ":\n\n"); va_end(args); - + o_stream_send(denv->stream, str_data(outbuf), str_len(outbuf)); } -/* +/* * Dumping the binary */ bool sieve_binary_dumper_run -(struct sieve_binary_dumper *dumper, struct ostream *stream, bool verbose) -{ +(struct sieve_binary_dumper *dumper, struct ostream *stream, bool verbose) +{ struct sieve_binary *sbin = dumper->dumpenv.sbin; struct sieve_dumptime_env *denv = &(dumper->dumpenv); int count, i; - + dumper->dumpenv.stream = stream; /* Dump list of binary blocks */ @@ -111,49 +111,49 @@ bool sieve_binary_dumper_run for ( i = 0; i < count; i++ ) { struct sieve_binary_block *sblock = sieve_binary_block_get(sbin, i); - sieve_binary_dumpf(denv, - "%3d: size: %"PRIuSIZE_T" bytes\n", i, + sieve_binary_dumpf(denv, + "%3d: size: %"PRIuSIZE_T" bytes\n", i, sieve_binary_block_get_size(sblock)); } } - + /* Dump list of used extensions */ - + count = sieve_binary_extensions_count(sbin); if ( count > 0 ) { sieve_binary_dump_sectionf (denv, "Required extensions (block: %d)", SBIN_SYSBLOCK_EXTENSIONS); - + for ( i = 0; i < count; i++ ) { const struct sieve_extension *ext = sieve_binary_extension_get_by_index (sbin, i); struct sieve_binary_block *sblock = sieve_binary_extension_get_block (sbin, ext); - + if ( sblock == NULL ) { - sieve_binary_dumpf(denv, "%3d: %s (id: %d)\n", + sieve_binary_dumpf(denv, "%3d: %s (id: %d)\n", i, sieve_extension_name(ext), ext->id); } else { - sieve_binary_dumpf(denv, "%3d: %s (id: %d; block: %d)\n", - i, sieve_extension_name(ext), ext->id, + sieve_binary_dumpf(denv, "%3d: %s (id: %d; block: %d)\n", + i, sieve_extension_name(ext), ext->id, sieve_binary_block_get_id(sblock)); } } } /* Dump extension-specific elements of the binary */ - + count = sieve_binary_extensions_count(sbin); - if ( count > 0 ) { + if ( count > 0 ) { for ( i = 0; i < count; i++ ) { bool success = TRUE; - T_BEGIN { + T_BEGIN { const struct sieve_extension *ext = sieve_binary_extension_get_by_index (sbin, i); - - if ( ext->def != NULL && ext->def->binary_dump != NULL ) { + + if ( ext->def != NULL && ext->def->binary_dump != NULL ) { success = ext->def->binary_dump(ext, denv); } } T_END; @@ -161,22 +161,22 @@ bool sieve_binary_dumper_run if ( !success ) return FALSE; } } - + /* Dump main program */ - + sieve_binary_dump_sectionf (denv, "Main program (block: %d)", SBIN_SYSBLOCK_MAIN_PROGRAM); - dumper->dumpenv.sblock = + dumper->dumpenv.sblock = sieve_binary_block_get(sbin, SBIN_SYSBLOCK_MAIN_PROGRAM); dumper->dumpenv.cdumper = sieve_code_dumper_create(&(dumper->dumpenv)); if ( dumper->dumpenv.cdumper != NULL ) { sieve_code_dumper_run(dumper->dumpenv.cdumper); - + sieve_code_dumper_free(&dumper->dumpenv.cdumper); } - + /* Finish with empty line */ sieve_binary_dumpf(denv, "\n"); @@ -193,7 +193,7 @@ void sieve_binary_dumper_hexdump struct sieve_binary *sbin = dumper->dumpenv.sbin; struct sieve_dumptime_env *denv = &(dumper->dumpenv); int count, i; - + dumper->dumpenv.stream = stream; count = sieve_binary_block_count(sbin); @@ -206,8 +206,8 @@ void sieve_binary_dumper_hexdump for ( i = 0; i < count; i++ ) { struct sieve_binary_block *sblock = sieve_binary_block_get(sbin, i); - sieve_binary_dumpf(denv, - "%3d: size: %"PRIuSIZE_T" bytes\n", i, + sieve_binary_dumpf(denv, + "%3d: size: %"PRIuSIZE_T" bytes\n", i, sieve_binary_block_get_size(sblock)); } @@ -237,7 +237,7 @@ void sieve_binary_dumper_hexdump str_printfa(line, "%08llx ", (unsigned long long) offset); for ( b = 0; b < len; b++ ) { - str_printfa(line, "%02x ", (unsigned int) data[offset+b]); + str_printfa(line, "%02x ", (unsigned int) data[offset+b]); if ( b == 7 ) str_append_c(line, ' '); } @@ -265,9 +265,9 @@ void sieve_binary_dumper_hexdump str_truncate(line, 0); offset += len; } - + str_printfa(line, "%08llx\n", (unsigned long long) offset); o_stream_send(stream, str_data(line), str_len(line)); } -} +} diff --git a/src/lib-sieve/sieve-binary-dumper.h b/src/lib-sieve/sieve-binary-dumper.h index 031295c768c3f433abbfdd8cae7f7c613f3d69e1..8408fcc3e279c848418b3146b7d7f9413c509212 100644 --- a/src/lib-sieve/sieve-binary-dumper.h +++ b/src/lib-sieve/sieve-binary-dumper.h @@ -20,8 +20,8 @@ void sieve_binary_dumper_free pool_t sieve_binary_dumper_pool (struct sieve_binary_dumper *dumper); -/* - * Formatted output +/* + * Formatted output */ void sieve_binary_dumpf diff --git a/src/lib-sieve/sieve-binary-file.c b/src/lib-sieve/sieve-binary-file.c index 98624ec037c4348c727e26c400a9a8f3e5bf8718..9d1ad5bd8c422f24ff23635364ac24aff8baba76 100644 --- a/src/lib-sieve/sieve-binary-file.c +++ b/src/lib-sieve/sieve-binary-file.c @@ -9,7 +9,7 @@ #include "hash.h" #include "array.h" #include "ostream.h" -#include "eacces-error.h" +#include "eacces-error.h" #include "safe-mkstemp.h" #include "sieve-common.h" @@ -30,7 +30,7 @@ */ #define SIEVE_BINARY_MAGIC 0xcafebabe -#define SIEVE_BINARY_MAGIC_OTHER_ENDIAN 0xbebafeca +#define SIEVE_BINARY_MAGIC_OTHER_ENDIAN 0xbebafeca #define SIEVE_BINARY_ALIGN(offset) \ (((offset) + 3) & ~3) @@ -38,9 +38,9 @@ ((void *) SIEVE_BINARY_ALIGN(((size_t) ptr))) /* - * Header and record structures of the binary on disk + * Header and record structures of the binary on disk */ - + struct sieve_binary_header { uint32_t magic; uint16_t version_major; @@ -56,17 +56,17 @@ struct sieve_binary_block_index { }; struct sieve_binary_block_header { - uint32_t id; + uint32_t id; uint32_t size; }; -/* - * Saving the binary to a file. +/* + * Saving the binary to a file. */ static inline bool _save_skip (struct sieve_binary *sbin, struct ostream *stream, size_t size) -{ +{ if ( (o_stream_seek(stream, stream->offset + size)) <= 0 ) { sieve_sys_error(sbin->svinst, "binary save: failed to skip output stream " @@ -79,21 +79,21 @@ static inline bool _save_skip } static inline bool _save_skip_aligned -(struct sieve_binary *sbin, struct ostream *stream, size_t size, +(struct sieve_binary *sbin, struct ostream *stream, size_t size, uoff_t *offset) { uoff_t aligned_offset = SIEVE_BINARY_ALIGN(stream->offset); - + if ( (o_stream_seek(stream, aligned_offset + size)) <= 0 ) { sieve_sys_error(sbin->svinst, "binary save: failed to skip output stream " "to position %"PRIuUOFF_T": %s", aligned_offset + size, strerror(stream->stream_errno)); return FALSE; } - + if ( offset != NULL ) *offset = aligned_offset; - + return TRUE; } @@ -103,48 +103,48 @@ static bool _save_full { size_t bytes_left = size; const void *pdata = data; - + while ( bytes_left > 0 ) { ssize_t ret; - + if ( (ret=o_stream_send(stream, pdata, bytes_left)) <= 0 ) { sieve_sys_error(sbin->svinst, "binary save: failed to write %"PRIuSIZE_T" bytes " "to output stream: %s", bytes_left, strerror(stream->stream_errno)); return FALSE; } - + pdata = PTR_OFFSET(pdata, ret); bytes_left -= ret; - } - + } + return TRUE; } static bool _save_aligned (struct sieve_binary *sbin, struct ostream *stream, const void *data, size_t size, uoff_t *offset) -{ +{ uoff_t aligned_offset = SIEVE_BINARY_ALIGN(stream->offset); o_stream_cork(stream); - + /* Align the data by adding zeroes to the output stream */ if ( stream->offset < aligned_offset ) { - if ( !_save_skip(sbin, stream, aligned_offset - stream->offset) ) + if ( !_save_skip(sbin, stream, aligned_offset - stream->offset) ) return FALSE; } - + if ( !_save_full(sbin, stream, data, size) ) return FALSE; - - o_stream_uncork(stream); + + o_stream_uncork(stream); if ( offset != NULL ) *offset = aligned_offset; return TRUE; -} +} static bool _save_block (struct sieve_binary *sbin, struct ostream *stream, unsigned int id) @@ -153,20 +153,20 @@ static bool _save_block struct sieve_binary_block *block; const void *data; size_t size; - + block = sieve_binary_block_get(sbin, id); if ( block == NULL ) return FALSE; - + data = buffer_get_data(block->data, &size); - + block_header.id = id; block_header.size = size; - + if ( !_save_aligned(sbin, stream, &block_header, sizeof(block_header), &block->offset) ) return FALSE; - + return _save_aligned(sbin, stream, data, size, NULL); } @@ -175,22 +175,22 @@ static bool _save_block_index_record { struct sieve_binary_block *block; struct sieve_binary_block_index header; - + block = sieve_binary_block_get(sbin, id); if ( block == NULL ) return FALSE; - + header.id = id; header.size = buffer_get_used_size(block->data); header.ext_id = block->ext_index; header.offset = block->offset; - + if ( !_save_full(sbin, stream, &header, sizeof(header)) ) { sieve_sys_error(sbin->svinst, "binary save: failed to save block index header %d", id); return FALSE; } - + return TRUE; } @@ -202,21 +202,21 @@ static bool _sieve_binary_save struct sieve_binary_block *ext_block; unsigned int ext_count, blk_count, i; uoff_t block_index; - + blk_count = sieve_binary_block_count(sbin); - + /* Signal all extensions to finish generating their blocks */ - - regs = array_get(&sbin->extensions, &ext_count); + + regs = array_get(&sbin->extensions, &ext_count); for ( i = 0; i < ext_count; i++ ) { const struct sieve_binary_extension *binext = regs[i]->binext; - + if ( binext != NULL && binext->binary_save != NULL ) binext->binary_save(regs[i]->extension, sbin, regs[i]->context); } - + /* Create header */ - + header.magic = SIEVE_BINARY_MAGIC; header.version_major = SIEVE_BINARY_VERSION_MAJOR; header.version_minor = SIEVE_BINARY_VERSION_MINOR; @@ -225,48 +225,48 @@ static bool _sieve_binary_save if ( !_save_aligned(sbin, stream, &header, sizeof(header), NULL) ) { sieve_sys_error(sbin->svinst, "binary save: failed to save header"); return FALSE; - } - + } + /* Skip block index for now */ - - if ( !_save_skip_aligned(sbin, stream, + + if ( !_save_skip_aligned(sbin, stream, sizeof(struct sieve_binary_block_index) * blk_count, &block_index) ) return FALSE; - - /* Create block containing all used extensions + + /* Create block containing all used extensions * FIXME: Per-extension this should also store binary version numbers. */ ext_block = sieve_binary_block_get(sbin, SBIN_SYSBLOCK_EXTENSIONS); i_assert( ext_block != NULL ); - + ext_count = array_count(&sbin->linked_extensions); sieve_binary_emit_unsigned(ext_block, ext_count); - + for ( i = 0; i < ext_count; i++ ) { struct sieve_binary_extension_reg * const *ext = array_idx(&sbin->linked_extensions, i); - + sieve_binary_emit_cstring (ext_block, sieve_extension_name((*ext)->extension)); sieve_binary_emit_unsigned(ext_block, (*ext)->block_id); } - + /* Save all blocks into the binary */ - + for ( i = 0; i < blk_count; i++ ) { - if ( !_save_block(sbin, stream, i) ) + if ( !_save_block(sbin, stream, i) ) return FALSE; } - + /* Create the block index */ o_stream_seek(stream, block_index); for ( i = 0; i < blk_count; i++ ) { - if ( !_save_block_index_record(sbin, stream, i) ) + if ( !_save_block_index_record(sbin, stream, i) ) return FALSE; } return TRUE; -} +} int sieve_binary_save (struct sieve_binary *sbin, const char *path, bool update, mode_t save_mode, @@ -320,7 +320,7 @@ int sieve_binary_save } o_stream_destroy(&stream); - /* Close saved binary */ + /* Close saved binary */ if ( close(fd) < 0 ) { sieve_sys_error(sbin->svinst, "binary save: failed to close temporary file: " @@ -330,11 +330,11 @@ int sieve_binary_save /* Replace any original binary atomically */ if ( result && (rename(str_c(temp_path), path) < 0) ) { if ( errno == EACCES ) { - sieve_sys_error(sbin->svinst, "binary save: failed to save binary: %s", + sieve_sys_error(sbin->svinst, "binary save: failed to save binary: %s", eacces_error_get_creating("rename", path)); if ( error_r != NULL ) *error_r = SIEVE_ERROR_NO_PERM; - } else { + } else { sieve_sys_error(sbin->svinst, "binary save: failed to save binary: " "rename(%s, %s) failed: %m", str_c(temp_path), path); if ( error_r != NULL ) @@ -346,7 +346,7 @@ int sieve_binary_save if ( result < 0 ) { /* Get rid of temp output (if any) */ if ( unlink(str_c(temp_path)) < 0 && errno != ENOENT ) { - sieve_sys_error(sbin->svinst, + sieve_sys_error(sbin->svinst, "binary save: failed to clean up after error: unlink(%s) failed: %m", str_c(temp_path)); } @@ -355,16 +355,16 @@ int sieve_binary_save sbin->path = p_strdup(sbin->pool, path); } } - + return result; } -/* - * Binary file management +/* + * Binary file management */ bool sieve_binary_file_open -(struct sieve_binary_file *file, +(struct sieve_binary_file *file, struct sieve_instance *svinst, const char *path, enum sieve_error *error_r) { int fd; @@ -373,7 +373,7 @@ bool sieve_binary_file_open if ( error_r != NULL ) *error_r = SIEVE_ERROR_NONE; - + if ( (fd=open(path, O_RDONLY)) < 0 ) { switch ( errno ) { case ENOENT: @@ -381,7 +381,7 @@ bool sieve_binary_file_open *error_r = SIEVE_ERROR_NOT_FOUND; break; case EACCES: - sieve_sys_error(svinst, "binary open: failed to open: %s", + sieve_sys_error(svinst, "binary open: failed to open: %s", eacces_error_get("open", path)); if ( error_r != NULL ) *error_r = SIEVE_ERROR_NO_PERM; @@ -405,11 +405,11 @@ bool sieve_binary_file_open } if ( result && !S_ISREG(st.st_mode) ) { - sieve_sys_error(svinst, + sieve_sys_error(svinst, "binary open: %s is not a regular file", path); - result = FALSE; + result = FALSE; } - + if ( !result ) { if ( close(fd) < 0 ) { sieve_sys_error(svinst, @@ -424,19 +424,19 @@ bool sieve_binary_file_open return TRUE; } - + void sieve_binary_file_close(struct sieve_binary_file **file) { if ( (*file)->fd != -1 ) { if ( close((*file)->fd) < 0 ) { - sieve_sys_error((*file)->svinst, + sieve_sys_error((*file)->svinst, "binary close: failed to close: close(fd=%s) failed: %m", (*file)->path); } } pool_unref(&(*file)->pool); - + *file = NULL; } @@ -454,7 +454,7 @@ struct _file_memory { static const void *_file_memory_load_data (struct sieve_binary_file *file, off_t *offset, size_t size) -{ +{ struct _file_memory *fmem = (struct _file_memory *) file; *offset = SIEVE_BINARY_ALIGN(*offset); @@ -463,16 +463,16 @@ static const void *_file_memory_load_data const void *data = PTR_OFFSET(fmem->memory, *offset); *offset += size; file->offset = *offset; - + return data; } - + return NULL; } static buffer_t *_file_memory_load_buffer (struct sieve_binary_file *file, off_t *offset, size_t size) -{ +{ struct _file_memory *fmem = (struct _file_memory *) file; *offset = SIEVE_BINARY_ALIGN(*offset); @@ -481,10 +481,10 @@ static buffer_t *_file_memory_load_buffer const void *data = PTR_OFFSET(fmem->memory, *offset); *offset += size; file->offset = *offset; - + return buffer_create_const_data(file->pool, data, size); } - + return NULL; } @@ -494,15 +494,15 @@ static bool _file_memory_load(struct sieve_binary_file *file) int ret; size_t size; void *indata; - + i_assert(file->fd > 0); - + /* Allocate memory buffer */ indata = p_malloc(file->pool, file->st.st_size); - size = file->st.st_size; - - file->offset = 0; + size = file->st.st_size; + + file->offset = 0; fmem->memory = indata; fmem->memory_size = file->st.st_size; @@ -510,7 +510,7 @@ static bool _file_memory_load(struct sieve_binary_file *file) if ( lseek(file->fd, 0, SEEK_SET) == (off_t) -1 ) { sieve_sys_error("failed to seek() in binary %s: %m", file->path); return FALSE; - } + } /* Read the whole file into memory */ while (size > 0) { @@ -518,16 +518,16 @@ static bool _file_memory_load(struct sieve_binary_file *file) sieve_sys_error("failed to read from binary %s: %m", file->path); break; } - + indata = PTR_OFFSET(indata, ret); size -= ret; - } + } if ( size != 0 ) { /* Failed to read the whole file */ return FALSE; } - + return TRUE; } @@ -535,7 +535,7 @@ static struct sieve_binary_file *_file_memory_open(const char *path) { pool_t pool; struct _file_memory *file; - + pool = pool_alloconly_create("sieve_binary_file_memory", 1024); file = p_new(pool, struct _file_memory, 1); file->binfile.pool = pool; @@ -543,7 +543,7 @@ static struct sieve_binary_file *_file_memory_open(const char *path) file->binfile.load = _file_memory_load; file->binfile.load_data = _file_memory_load_data; file->binfile.load_buffer = _file_memory_load_buffer; - + if ( !sieve_binary_file_open(&file->binfile, path) ) { pool_unref(&pool); return NULL; @@ -563,40 +563,40 @@ static bool _file_lazy_read int ret; void *indata = buffer; size_t insize = size; - + *offset = SIEVE_BINARY_ALIGN(*offset); - - /* Seek to the correct position */ - if ( *offset != file->offset && + + /* Seek to the correct position */ + if ( *offset != file->offset && lseek(file->fd, *offset, SEEK_SET) == (off_t) -1 ) { sieve_sys_error(svinst, "binary read:" - "failed to seek(fd, %lld, SEEK_SET) in binary %s: %m", + "failed to seek(fd, %lld, SEEK_SET) in binary %s: %m", (long long) *offset, file->path); return FALSE; - } + } /* Read record into memory */ while (insize > 0) { if ( (ret=read(file->fd, indata, insize)) <= 0 ) { - if ( ret == 0 ) - sieve_sys_error(svinst, - "binary read: binary %s is truncated (more data expected)", + if ( ret == 0 ) + sieve_sys_error(svinst, + "binary read: binary %s is truncated (more data expected)", file->path); else sieve_sys_error(svinst, "binary read: failed to read from binary %s: %m", file->path); break; } - + indata = PTR_OFFSET(indata, ret); insize -= ret; - } + } if ( insize != 0 ) { /* Failed to read the whole requested record */ return FALSE; } - + *offset += size; file->offset = *offset; @@ -605,26 +605,26 @@ static bool _file_lazy_read static const void *_file_lazy_load_data (struct sieve_binary_file *file, off_t *offset, size_t size) -{ +{ void *data = t_malloc(size); if ( _file_lazy_read(file, offset, data, size) ) { return data; } - + return NULL; } static buffer_t *_file_lazy_load_buffer (struct sieve_binary_file *file, off_t *offset, size_t size) -{ +{ buffer_t *buffer = buffer_create_dynamic(file->pool, size); - + if ( _file_lazy_read (file, offset, buffer_get_space_unsafe(buffer, 0, size), size) ) { return buffer; } - + return NULL; } @@ -633,14 +633,14 @@ static struct sieve_binary_file *_file_lazy_open { pool_t pool; struct sieve_binary_file *file; - + pool = pool_alloconly_create("sieve_binary_file_lazy", 4096); file = p_new(pool, struct sieve_binary_file, 1); file->pool = pool; file->path = p_strdup(pool, path); file->load_data = _file_lazy_load_data; file->load_buffer = _file_lazy_load_buffer; - + if ( !sieve_binary_file_open(file, svinst, path, error_r) ) { pool_unref(&pool); return NULL; @@ -649,7 +649,7 @@ static struct sieve_binary_file *_file_lazy_open return file; } -/* +/* * Load binary from a file */ @@ -662,16 +662,16 @@ bool sieve_binary_load_block struct sieve_binary *sbin = sblock->sbin; unsigned int id = sblock->id; off_t offset = sblock->offset; - const struct sieve_binary_block_header *header = + const struct sieve_binary_block_header *header = LOAD_HEADER(sbin, &offset, const struct sieve_binary_block_header); - + if ( header == NULL ) { sieve_sys_error(sbin->svinst, "binary load: binary %s is corrupt: " "failed to read header of block %d", sbin->path, id); return FALSE; } - + if ( header->id != id ) { sieve_sys_error(sbin->svinst, "binary load: binary %s is corrupt: " @@ -679,7 +679,7 @@ bool sieve_binary_load_block sbin->path, id, header->id); return FALSE; } - + sblock->data = sbin->file->load_buffer(sbin->file, &offset, header->size); if ( sblock->data == NULL ) { sieve_sys_error(sbin->svinst, @@ -687,35 +687,35 @@ bool sieve_binary_load_block id, sbin->path, header->size); return FALSE; } - + return TRUE; } static bool _read_block_index_record (struct sieve_binary *sbin, off_t *offset, unsigned int id) { - const struct sieve_binary_block_index *record = + const struct sieve_binary_block_index *record = LOAD_HEADER(sbin, offset, const struct sieve_binary_block_index); struct sieve_binary_block *block; - + if ( record == NULL ) { sieve_sys_error(sbin->svinst, "binary open: binary %s is corrupt: " "failed to load block index record %d", sbin->path, id); return FALSE; } - + if ( record->id != id ) { sieve_sys_error(sbin->svinst, "binary open: binary %s is corrupt: " "block index record %d has unexpected id %d", sbin->path, id, record->id); return FALSE; } - + block = sieve_binary_block_create_id(sbin, id); block->ext_index = record->ext_id; block->offset = record->offset; - + return TRUE; } @@ -725,26 +725,26 @@ static bool _read_extensions(struct sieve_binary_block *sblock) sieve_size_t offset = 0; unsigned int i, count; bool result = TRUE; - + if ( !sieve_binary_read_unsigned(sblock, &offset, &count) ) return FALSE; - + for ( i = 0; result && i < count; i++ ) { T_BEGIN { string_t *extension; const struct sieve_extension *ext; - - if ( sieve_binary_read_string(sblock, &offset, &extension) ) { - ext = sieve_extension_get_by_name(sbin->svinst, str_c(extension)); - - if ( ext == NULL ) { + + if ( sieve_binary_read_string(sblock, &offset, &extension) ) { + ext = sieve_extension_get_by_name(sbin->svinst, str_c(extension)); + + if ( ext == NULL ) { sieve_sys_error(sbin->svinst, - "binary open: binary %s requires unknown extension '%s'", + "binary open: binary %s requires unknown extension '%s'", sbin->path, str_sanitize(str_c(extension), 128)); - result = FALSE; + result = FALSE; } else { struct sieve_binary_extension_reg *ereg = NULL; - + (void) sieve_binary_extension_register(sbin, ext, &ereg); if ( !sieve_binary_read_unsigned(sblock, &offset, &ereg->block_id) ) result = FALSE; @@ -752,8 +752,8 @@ static bool _read_extensions(struct sieve_binary_block *sblock) } else result = FALSE; } T_END; - } - + } + return result; } @@ -764,9 +764,9 @@ static bool _sieve_binary_open(struct sieve_binary *sbin) const struct sieve_binary_header *header; struct sieve_binary_block *ext_block; unsigned int i, blk_count; - + /* Verify header */ - + T_BEGIN { header = LOAD_HEADER(sbin, &offset, const struct sieve_binary_header); /* Check header presence */ @@ -778,8 +778,8 @@ static bool _sieve_binary_open(struct sieve_binary *sbin) /* Check header validity */ } else if ( header->magic != SIEVE_BINARY_MAGIC ) { - if ( header->magic != SIEVE_BINARY_MAGIC_OTHER_ENDIAN ) - sieve_sys_error(sbin->svinst, + if ( header->magic != SIEVE_BINARY_MAGIC_OTHER_ENDIAN ) + sieve_sys_error(sbin->svinst, "binary_open: binary %s has corrupted header " "(0x%08x) or it is not a Sieve binary", sbin->path, header->magic); else if ( sbin->svinst->debug ) @@ -791,11 +791,11 @@ static bool _sieve_binary_open(struct sieve_binary *sbin) /* Check binary version */ } else if ( result && ( - header->version_major != SIEVE_BINARY_VERSION_MAJOR || + header->version_major != SIEVE_BINARY_VERSION_MAJOR || header->version_minor != SIEVE_BINARY_VERSION_MINOR ) ) { /* Binary is of different version. Caller will have to recompile */ - + if ( sbin->svinst->debug ) { sieve_sys_debug(sbin->svinst, "binary open: binary %s stored with different binary version %d.%d " @@ -810,42 +810,42 @@ static bool _sieve_binary_open(struct sieve_binary *sbin) sieve_sys_error(sbin->svinst, "binary open: binary %s is corrupt: it contains no blocks", sbin->path); - result = FALSE; + result = FALSE; /* Valid */ } else { blk_count = header->blocks; } } T_END; - + if ( !result ) return FALSE; - + /* Load block index */ - - for ( i = 0; i < blk_count && result; i++ ) { + + for ( i = 0; i < blk_count && result; i++ ) { T_BEGIN { if ( !_read_block_index_record(sbin, &offset, i) ) { result = FALSE; } } T_END; } - + if ( !result ) return FALSE; - + /* Load extensions used by this binary */ - + T_BEGIN { ext_block = sieve_binary_block_get(sbin, SBIN_SYSBLOCK_EXTENSIONS); if ( ext_block == NULL ) { result = FALSE; } else if ( !_read_extensions(ext_block) ) { sieve_sys_error(sbin->svinst, - "binary open: binary %s is corrupt: failed to load extension block", + "binary open: binary %s is corrupt: failed to load extension block", sbin->path); result = FALSE; } } T_END; - + return result; } @@ -857,33 +857,33 @@ struct sieve_binary *sieve_binary_open unsigned int ext_count, i; struct sieve_binary *sbin; struct sieve_binary_file *file; - + i_assert( script == NULL || sieve_script_svinst(script) == svinst ); - - //file = _file_memory_open(path); - if ( (file=_file_lazy_open(svinst, path, error_r)) == NULL ) + + //file = _file_memory_open(path); + if ( (file=_file_lazy_open(svinst, path, error_r)) == NULL ) return NULL; - + /* Create binary object */ sbin = sieve_binary_create(svinst, script); sbin->path = p_strdup(sbin->pool, path); sbin->file = file; - + if ( !_sieve_binary_open(sbin) ) { sieve_binary_unref(&sbin); if ( error_r != NULL ) *error_r = SIEVE_ERROR_NOT_VALID; return NULL; } - + sieve_binary_activate(sbin); - + /* Signal open event to extensions */ - regs = array_get(&sbin->extensions, &ext_count); + regs = array_get(&sbin->extensions, &ext_count); for ( i = 0; i < ext_count; i++ ) { const struct sieve_binary_extension *binext = regs[i]->binext; - - if ( binext != NULL && binext->binary_open != NULL && + + if ( binext != NULL && binext->binary_open != NULL && !binext->binary_open(regs[i]->extension, sbin, regs[i]->context) ) { /* Extension thinks its corrupt */ @@ -893,7 +893,7 @@ struct sieve_binary *sieve_binary_open sieve_binary_unref(&sbin); return NULL; } - } + } return sbin; } diff --git a/src/lib-sieve/sieve-binary-private.h b/src/lib-sieve/sieve-binary-private.h index 40fb4979432ff035ec3b9079cfd9485918644b82..a7387874f4850a87663c119ce4ca98bbb8fdb3f6 100644 --- a/src/lib-sieve/sieve-binary-private.h +++ b/src/lib-sieve/sieve-binary-private.h @@ -18,7 +18,7 @@ struct sieve_binary_file { pool_t pool; const char *path; struct sieve_instance *svinst; - + struct stat st; int fd; off_t offset; @@ -34,7 +34,7 @@ bool sieve_binary_file_open const char *path, enum sieve_error *error_r); void sieve_binary_file_close(struct sieve_binary_file **file); -/* +/* * Internal structures */ @@ -43,19 +43,19 @@ void sieve_binary_file_close(struct sieve_binary_file **file); struct sieve_binary_extension_reg { /* The identifier of the extension within this binary */ int index; - + /* Global extension object */ - const struct sieve_extension *extension; - - /* Extension to the binary; typically used to manage extension-specific blocks + const struct sieve_extension *extension; + + /* Extension to the binary; typically used to manage extension-specific blocks * in the binary and as a means to get a binary_free notification to release - * references held by extensions. + * references held by extensions. */ - const struct sieve_binary_extension *binext; - + const struct sieve_binary_extension *binext; + /* Context data associated to the binary by this extension */ void *context; - + /* Main block for this extension */ unsigned int block_id; }; @@ -68,7 +68,7 @@ struct sieve_binary_block { int ext_index; buffer_t *data; - + uoff_t offset; }; @@ -81,33 +81,33 @@ struct sieve_binary { int refcount; struct sieve_instance *svinst; - + struct sieve_script *script; - + struct sieve_binary_file *file; - + /* When the binary is loaded into memory or when it is being constructed by * the generator, extensions can be associated to the binary. The extensions - * array is a sequential list of all linked extensions. The extension_index - * array is a mapping ext_id -> binary_extension. This is used to obtain the - * index code associated with an extension for this particular binary. The + * array is a sequential list of all linked extensions. The extension_index + * array is a mapping ext_id -> binary_extension. This is used to obtain the + * index code associated with an extension for this particular binary. The * linked_extensions list all extensions linked to this binary object other - * than the preloaded language features implemented as 'extensions'. - * - * All arrays refer to the same extension registration objects. Upon loading - * a binary, the 'require'd extensions will sometimes need to associate - * context data to the binary object in memory. This is stored in these + * than the preloaded language features implemented as 'extensions'. + * + * All arrays refer to the same extension registration objects. Upon loading + * a binary, the 'require'd extensions will sometimes need to associate + * context data to the binary object in memory. This is stored in these * registration objects as well. */ - ARRAY_DEFINE(extensions, struct sieve_binary_extension_reg *); - ARRAY_DEFINE(extension_index, struct sieve_binary_extension_reg *); - ARRAY_DEFINE(linked_extensions, struct sieve_binary_extension_reg *); - + ARRAY_DEFINE(extensions, struct sieve_binary_extension_reg *); + ARRAY_DEFINE(extension_index, struct sieve_binary_extension_reg *); + ARRAY_DEFINE(linked_extensions, struct sieve_binary_extension_reg *); + /* Attributes of a loaded binary */ const char *path; - + /* Blocks */ - ARRAY_DEFINE(blocks, struct sieve_binary_block *); + ARRAY_DEFINE(blocks, struct sieve_binary_block *); }; struct sieve_binary *sieve_binary_create @@ -116,13 +116,13 @@ struct sieve_binary *sieve_binary_create /* Blocks management */ static inline struct sieve_binary_block *sieve_binary_block_index -(struct sieve_binary *sbin, unsigned int id) +(struct sieve_binary *sbin, unsigned int id) { struct sieve_binary_block * const *sblock; if ( id >= array_count(&sbin->blocks) ) return NULL; - + sblock = array_idx(&sbin->blocks, id); if ( *sblock == NULL ) { @@ -158,22 +158,22 @@ static inline struct sieve_binary_extension_reg * ereg = p_new(sbin->pool, struct sieve_binary_extension_reg, 1); ereg->index = index; ereg->extension = ext; - + array_idx_set(&sbin->extensions, (unsigned int) index, &ereg); array_idx_set(&sbin->extension_index, (unsigned int) ext->id, &ereg); - + return ereg; } -static inline struct sieve_binary_extension_reg *sieve_binary_extension_get_reg -(struct sieve_binary *sbin, const struct sieve_extension *ext, bool create) +static inline struct sieve_binary_extension_reg *sieve_binary_extension_get_reg +(struct sieve_binary *sbin, const struct sieve_extension *ext, bool create) { struct sieve_binary_extension_reg *reg = NULL; if ( ext->id >= 0 && ext->id < (int) array_count(&sbin->extension_index) ) { - struct sieve_binary_extension_reg * const *ereg = + struct sieve_binary_extension_reg * const *ereg = array_idx(&sbin->extension_index, (unsigned int) ext->id); - + reg = *ereg; } @@ -185,14 +185,14 @@ static inline struct sieve_binary_extension_reg *sieve_binary_extension_get_reg } static inline int sieve_binary_extension_register -(struct sieve_binary *sbin, const struct sieve_extension *ext, - struct sieve_binary_extension_reg **reg_r) +(struct sieve_binary *sbin, const struct sieve_extension *ext, + struct sieve_binary_extension_reg **reg_r) { struct sieve_binary_extension_reg *ereg; if ( (ereg=sieve_binary_extension_get_reg(sbin, ext, FALSE)) == NULL ) { ereg = sieve_binary_extension_create_reg(sbin, ext); - + if ( ereg == NULL ) return -1; array_append(&sbin->linked_extensions, &ereg, 1); diff --git a/src/lib-sieve/sieve-binary.c b/src/lib-sieve/sieve-binary.c index d6c730a1d55d3ea8184a9f1e8fecabb426ad101d..07d1079c1fa2147db143e3acd3b643407bfec17b 100644 --- a/src/lib-sieve/sieve-binary.c +++ b/src/lib-sieve/sieve-binary.c @@ -9,7 +9,7 @@ #include "hash.h" #include "array.h" #include "ostream.h" -#include "eacces-error.h" +#include "eacces-error.h" #include "safe-mkstemp.h" #include "sieve-error.h" @@ -24,11 +24,11 @@ */ static inline struct sieve_binary_extension_reg *sieve_binary_extension_get_reg - (struct sieve_binary *sbin, const struct sieve_extension *ext, + (struct sieve_binary *sbin, const struct sieve_extension *ext, bool create); static inline int sieve_binary_extension_register - (struct sieve_binary *sbin, const struct sieve_extension *ext, + (struct sieve_binary *sbin, const struct sieve_extension *ext, struct sieve_binary_extension_reg **reg); /* @@ -36,50 +36,50 @@ static inline int sieve_binary_extension_register */ struct sieve_binary *sieve_binary_create -(struct sieve_instance *svinst, struct sieve_script *script) +(struct sieve_instance *svinst, struct sieve_script *script) { pool_t pool; struct sieve_binary *sbin; const struct sieve_extension *const *ext_preloaded; unsigned int i, ext_count; - - pool = pool_alloconly_create("sieve_binary", 8192); + + pool = pool_alloconly_create("sieve_binary", 8192); sbin = p_new(pool, struct sieve_binary, 1); sbin->pool = pool; sbin->refcount = 1; sbin->svinst = svinst; sbin->script = script; - if ( script != NULL ) + if ( script != NULL ) sieve_script_ref(script); - + ext_count = sieve_extensions_get_count(svinst); p_array_init(&sbin->linked_extensions, pool, ext_count); p_array_init(&sbin->extensions, pool, ext_count); p_array_init(&sbin->extension_index, pool, ext_count); - + p_array_init(&sbin->blocks, pool, 16); /* Pre-load core language features implemented as 'extensions' */ - ext_preloaded = sieve_extensions_get_preloaded(svinst, &ext_count); + ext_preloaded = sieve_extensions_get_preloaded(svinst, &ext_count); for ( i = 0; i < ext_count; i++ ) { const struct sieve_extension_def *ext_def = ext_preloaded[i]->def; if ( ext_def != NULL && ext_def->binary_load != NULL ) - (void)ext_def->binary_load(ext_preloaded[i], sbin); + (void)ext_def->binary_load(ext_preloaded[i], sbin); } - + return sbin; } -struct sieve_binary *sieve_binary_create_new(struct sieve_script *script) +struct sieve_binary *sieve_binary_create_new(struct sieve_script *script) { struct sieve_binary *sbin = sieve_binary_create (sieve_script_svinst(script), script); struct sieve_binary_block *sblock; unsigned int i; - + /* Create script metadata block */ sblock = sieve_binary_block_create(sbin); sieve_script_binary_write_metadata(script, sblock); @@ -88,31 +88,31 @@ struct sieve_binary *sieve_binary_create_new(struct sieve_script *script) for ( i = 1; i < SBIN_SYSBLOCK_LAST; i++ ) { (void) sieve_binary_block_create(sbin); } - + return sbin; } -void sieve_binary_ref(struct sieve_binary *sbin) +void sieve_binary_ref(struct sieve_binary *sbin) { sbin->refcount++; } -static inline void sieve_binary_extensions_free(struct sieve_binary *sbin) +static inline void sieve_binary_extensions_free(struct sieve_binary *sbin) { struct sieve_binary_extension_reg *const *regs; unsigned int ext_count, i; - + /* Cleanup binary extensions */ regs = array_get(&sbin->extensions, &ext_count); for ( i = 0; i < ext_count; i++ ) { const struct sieve_binary_extension *binext = regs[i]->binext; - + if ( binext != NULL && binext->binary_free != NULL ) binext->binary_free(regs[i]->extension, sbin, regs[i]->context); } } -void sieve_binary_unref(struct sieve_binary **sbin) +void sieve_binary_unref(struct sieve_binary **sbin) { i_assert((*sbin)->refcount > 0); @@ -120,15 +120,15 @@ void sieve_binary_unref(struct sieve_binary **sbin) return; sieve_binary_extensions_free(*sbin); - + if ( (*sbin)->file != NULL ) sieve_binary_file_close(&(*sbin)->file); if ( (*sbin)->script != NULL ) sieve_script_unref(&(*sbin)->script); - + pool_unref(&((*sbin)->pool)); - + *sbin = NULL; } @@ -200,8 +200,8 @@ const char *sieve_binfile_from_name(const char *name) return t_strconcat(name, "."SIEVE_BINARY_FILEEXT, NULL); } -/* - * Block management +/* + * Block management */ unsigned int sieve_binary_block_count @@ -214,7 +214,7 @@ struct sieve_binary_block *sieve_binary_block_create(struct sieve_binary *sbin) { unsigned int id = sieve_binary_block_count(sbin); struct sieve_binary_block *sblock; - + sblock = p_new(sbin->pool, struct sieve_binary_block, 1); sblock->data = buffer_create_dynamic(sbin->pool, 64); sblock->sbin = sbin; @@ -229,14 +229,14 @@ struct sieve_binary_block *sieve_binary_block_create_id (struct sieve_binary *sbin, unsigned int id) { struct sieve_binary_block *sblock; - + sblock = p_new(sbin->pool, struct sieve_binary_block, 1); - array_idx_set(&sbin->blocks, id, &sblock); + array_idx_set(&sbin->blocks, id, &sblock); sblock->data = NULL; sblock->sbin = sbin; sblock->id = id; - + return sblock; } @@ -247,7 +247,7 @@ static bool sieve_binary_block_fetch(struct sieve_binary_block *sblock) if ( sbin->file ) { /* Try to acces the block in the binary on disk (apperently we were lazy) */ - if ( !sieve_binary_load_block(sblock) || sblock->data == NULL ) + if ( !sieve_binary_load_block(sblock) || sblock->data == NULL ) return FALSE; } else { sblock->data = buffer_create_dynamic(sbin->pool, 64); @@ -258,7 +258,7 @@ static bool sieve_binary_block_fetch(struct sieve_binary_block *sblock) } struct sieve_binary_block *sieve_binary_block_get -(struct sieve_binary *sbin, unsigned int id) +(struct sieve_binary *sbin, unsigned int id) { struct sieve_binary_block *sblock = sieve_binary_block_index(sbin, id); @@ -273,16 +273,16 @@ struct sieve_binary_block *sieve_binary_block_get void sieve_binary_block_clear (struct sieve_binary_block *sblock) -{ +{ buffer_reset(sblock->data); } buffer_t *sieve_binary_block_get_buffer (struct sieve_binary_block *sblock) -{ +{ if ( sblock->data == NULL && !sieve_binary_block_fetch(sblock) ) - return NULL; - + return NULL; + return sblock->data; } @@ -315,70 +315,70 @@ bool sieve_binary_up_to_date struct sieve_binary_block *sblock; sieve_size_t offset = 0; unsigned int ext_count, i; - + i_assert(sbin->file != NULL); sblock = sieve_binary_block_get(sbin, SBIN_SYSBLOCK_SCRIPT_DATA); if ( sblock == NULL || sbin->script == NULL || sieve_script_binary_read_metadata(sbin->script, sblock, &offset) <= 0 ) return FALSE; - - regs = array_get(&sbin->extensions, &ext_count); + + regs = array_get(&sbin->extensions, &ext_count); for ( i = 0; i < ext_count; i++ ) { const struct sieve_binary_extension *binext = regs[i]->binext; - - if ( binext != NULL && binext->binary_up_to_date != NULL && + + if ( binext != NULL && binext->binary_up_to_date != NULL && !binext->binary_up_to_date (regs[i]->extension, sbin, regs[i]->context, cpflags) ) return FALSE; } - + return TRUE; } /* * Activate the binary (after code generation) */ - + void sieve_binary_activate(struct sieve_binary *sbin) { struct sieve_binary_extension_reg *const *regs; unsigned int i, ext_count; - + /* Load other extensions into binary */ regs = array_get(&sbin->linked_extensions, &ext_count); for ( i = 0; i < ext_count; i++ ) { const struct sieve_extension *ext = regs[i]->extension; - + if ( ext != NULL && ext->def != NULL && ext->def->binary_load != NULL ) ext->def->binary_load(ext, sbin); } } -/* - * Extension handling +/* + * Extension handling */ void sieve_binary_extension_set_context (struct sieve_binary *sbin, const struct sieve_extension *ext, void *context) { - struct sieve_binary_extension_reg *ereg = + struct sieve_binary_extension_reg *ereg = sieve_binary_extension_get_reg(sbin, ext, TRUE); - + if ( ereg != NULL ) ereg->context = context; } const void *sieve_binary_extension_get_context - (struct sieve_binary *sbin, const struct sieve_extension *ext) + (struct sieve_binary *sbin, const struct sieve_extension *ext) { - struct sieve_binary_extension_reg *ereg = + struct sieve_binary_extension_reg *ereg = sieve_binary_extension_get_reg(sbin, ext, TRUE); if ( ereg != NULL ) { return ereg->context; } - + return NULL; } @@ -386,9 +386,9 @@ void sieve_binary_extension_set (struct sieve_binary *sbin, const struct sieve_extension *ext, const struct sieve_binary_extension *bext, void *context) { - struct sieve_binary_extension_reg *ereg = + struct sieve_binary_extension_reg *ereg = sieve_binary_extension_get_reg(sbin, ext, TRUE); - + if ( ereg != NULL ) { ereg->binext = bext; @@ -400,27 +400,27 @@ void sieve_binary_extension_set struct sieve_binary_block *sieve_binary_extension_create_block (struct sieve_binary *sbin, const struct sieve_extension *ext) { - struct sieve_binary_block *sblock; - struct sieve_binary_extension_reg *ereg = + struct sieve_binary_block *sblock; + struct sieve_binary_extension_reg *ereg = sieve_binary_extension_get_reg(sbin, ext, TRUE); - + i_assert(ereg != NULL); sblock = sieve_binary_block_create(sbin); - + if ( ereg->block_id < SBIN_SYSBLOCK_LAST ) ereg->block_id = sblock->id; sblock->ext_index = ereg->index; - + return sblock; } struct sieve_binary_block *sieve_binary_extension_get_block (struct sieve_binary *sbin, const struct sieve_extension *ext) { - struct sieve_binary_extension_reg *ereg = + struct sieve_binary_extension_reg *ereg = sieve_binary_extension_get_reg(sbin, ext, TRUE); - + i_assert(ereg != NULL); if ( ereg->block_id < SBIN_SYSBLOCK_LAST ) @@ -430,35 +430,35 @@ struct sieve_binary_block *sieve_binary_extension_get_block } int sieve_binary_extension_link -(struct sieve_binary *sbin, const struct sieve_extension *ext) -{ +(struct sieve_binary *sbin, const struct sieve_extension *ext) +{ return sieve_binary_extension_register(sbin, ext, NULL); } const struct sieve_extension *sieve_binary_extension_get_by_index -(struct sieve_binary *sbin, int index) +(struct sieve_binary *sbin, int index) { struct sieve_binary_extension_reg * const *ereg; - + if ( index < (int) array_count(&sbin->extensions) ) { ereg = array_idx(&sbin->extensions, (unsigned int) index); - + return (*ereg)->extension; } - + return NULL; } int sieve_binary_extension_get_index - (struct sieve_binary *sbin, const struct sieve_extension *ext) + (struct sieve_binary *sbin, const struct sieve_extension *ext) { struct sieve_binary_extension_reg *ereg = sieve_binary_extension_get_reg(sbin, ext, FALSE); - + return ( ereg == NULL ? -1 : ereg->index ); } -int sieve_binary_extensions_count(struct sieve_binary *sbin) +int sieve_binary_extensions_count(struct sieve_binary *sbin) { return (int) array_count(&sbin->extensions); } diff --git a/src/lib-sieve/sieve-binary.h b/src/lib-sieve/sieve-binary.h index 20d12cf894270b3a7ed13e5cfeb399a622965167..cabefcd82927203f32bbdb7733fa6801eb3b51dc 100644 --- a/src/lib-sieve/sieve-binary.h +++ b/src/lib-sieve/sieve-binary.h @@ -11,14 +11,14 @@ /* * Config */ - + #define SIEVE_BINARY_VERSION_MAJOR 0 #define SIEVE_BINARY_VERSION_MINOR 4 /* * Binary object */ - + struct sieve_binary; struct sieve_binary *sieve_binary_create_new(struct sieve_script *script); @@ -50,32 +50,32 @@ const char *sieve_binfile_from_name(const char *name); /* * Activation after code generation - */ - + */ + void sieve_binary_activate(struct sieve_binary *sbin); -/* +/* * Saving the binary */ - + int sieve_binary_save (struct sieve_binary *sbin, const char *path, bool update, mode_t save_mode, enum sieve_error *error_r); - -/* + +/* * Loading the binary - */ - + */ + struct sieve_binary *sieve_binary_open - (struct sieve_instance *svinst, const char *path, + (struct sieve_instance *svinst, const char *path, struct sieve_script *script, enum sieve_error *error_r); bool sieve_binary_up_to_date (struct sieve_binary *sbin, enum sieve_compile_flags cpflags); - -/* - * Block management + +/* + * Block management */ - + enum sieve_binary_system_block { SBIN_SYSBLOCK_SCRIPT_DATA, SBIN_SYSBLOCK_EXTENSIONS, @@ -104,10 +104,10 @@ struct sieve_binary *sieve_binary_block_get_binary unsigned int sieve_binary_block_get_id (const struct sieve_binary_block *sblock); -/* - * Extension support +/* + * Extension support */ - + struct sieve_binary_extension { const struct sieve_extension_def *extension; @@ -116,22 +116,22 @@ struct sieve_binary_extension { void *context); bool (*binary_open) (const struct sieve_extension *ext, struct sieve_binary *sbin, - void *context); + void *context); void (*binary_free) (const struct sieve_extension *ext, struct sieve_binary *sbin, - void *context); - + void *context); + bool (*binary_up_to_date) (const struct sieve_extension *ext, struct sieve_binary *sbin, - void *context, enum sieve_compile_flags cpflags); + void *context, enum sieve_compile_flags cpflags); }; - + void sieve_binary_extension_set_context (struct sieve_binary *sbin, const struct sieve_extension *ext, void *context); const void *sieve_binary_extension_get_context (struct sieve_binary *sbin, const struct sieve_extension *ext); - + void sieve_binary_extension_set (struct sieve_binary *sbin, const struct sieve_extension *ext, const struct sieve_binary_extension *bext, void *context); @@ -149,11 +149,11 @@ int sieve_binary_extension_get_index (struct sieve_binary *sbin, const struct sieve_extension *ext); int sieve_binary_extensions_count(struct sieve_binary *sbin); - -/* - * Code emission + +/* + * Code emission */ - + /* Low-level emission functions */ sieve_size_t sieve_binary_emit_data @@ -161,7 +161,7 @@ sieve_size_t sieve_binary_emit_data sieve_size_t sieve_binary_emit_byte (struct sieve_binary_block *sblock, uint8_t byte); void sieve_binary_update_data - (struct sieve_binary_block *sblock, sieve_size_t address, const void *data, + (struct sieve_binary_block *sblock, sieve_size_t address, const void *data, sieve_size_t size); /* Offset emission functions */ @@ -192,33 +192,33 @@ sieve_size_t sieve_binary_emit_extension (struct sieve_binary_block *sblock, const struct sieve_extension *ext, unsigned int offset); void sieve_binary_emit_extension_object - (struct sieve_binary_block *sblock, + (struct sieve_binary_block *sblock, const struct sieve_extension_objects *objs, unsigned int code); -/* - * Code retrieval +/* + * Code retrieval */ /* Literals */ bool sieve_binary_read_byte - (struct sieve_binary_block *sblock, sieve_size_t *address, + (struct sieve_binary_block *sblock, sieve_size_t *address, unsigned int *byte_r); bool sieve_binary_read_code - (struct sieve_binary_block *sblock, sieve_size_t *address, + (struct sieve_binary_block *sblock, sieve_size_t *address, signed int *code_r); bool sieve_binary_read_offset (struct sieve_binary_block *sblock, sieve_size_t *address, sieve_offset_t *offset_r); bool sieve_binary_read_integer - (struct sieve_binary_block *sblock, sieve_size_t *address, - sieve_number_t *int_r); + (struct sieve_binary_block *sblock, sieve_size_t *address, + sieve_number_t *int_r); bool sieve_binary_read_string - (struct sieve_binary_block *sblock, sieve_size_t *address, + (struct sieve_binary_block *sblock, sieve_size_t *address, string_t **str_r); static inline bool sieve_binary_read_unsigned -(struct sieve_binary_block *sblock, sieve_size_t *address, +(struct sieve_binary_block *sblock, sieve_size_t *address, unsigned int *count_r) { sieve_number_t integer; @@ -254,7 +254,7 @@ void sieve_binary_debug_writer_deinit (struct sieve_binary_debug_writer **dwriter); void sieve_binary_debug_emit - (struct sieve_binary_debug_writer *dwriter, sieve_size_t code_address, + (struct sieve_binary_debug_writer *dwriter, sieve_size_t code_address, unsigned int code_line, unsigned int code_column); /* Reader */ diff --git a/src/lib-sieve/sieve-code-dumper.c b/src/lib-sieve/sieve-code-dumper.c index 18e1e1e793f2c964b7feea72c7c0edf00d929a98..096d9a2beb56073a20848530ee338925de6ae9e6 100644 --- a/src/lib-sieve/sieve-code-dumper.c +++ b/src/lib-sieve/sieve-code-dumper.c @@ -21,7 +21,7 @@ #include "sieve-dump.h" -/* +/* * Code dumper extension */ @@ -33,42 +33,42 @@ struct sieve_code_dumper_extension_reg { struct sieve_code_dumper { pool_t pool; - - /* Dump status */ + + /* Dump status */ struct sieve_operation oprtn; sieve_size_t mark_address; unsigned int mark_line; unsigned int mark_last_line; unsigned int indent; - + /* Dump environment */ - struct sieve_dumptime_env *dumpenv; + struct sieve_dumptime_env *dumpenv; struct sieve_binary_debug_reader *dreader; - + ARRAY_DEFINE(extensions, struct sieve_code_dumper_extension_reg); }; struct sieve_code_dumper *sieve_code_dumper_create -(struct sieve_dumptime_env *denv) +(struct sieve_dumptime_env *denv) { pool_t pool; struct sieve_code_dumper *cdumper; - - pool = pool_alloconly_create("sieve_code_dumper", 4096); + + pool = pool_alloconly_create("sieve_code_dumper", 4096); cdumper = p_new(pool, struct sieve_code_dumper, 1); cdumper->pool = pool; cdumper->dumpenv = denv; - - /* Setup storage for extension contexts */ - p_array_init(&cdumper->extensions, pool, + + /* Setup storage for extension contexts */ + p_array_init(&cdumper->extensions, pool, sieve_extensions_get_count(denv->svinst)); return cdumper; } -void sieve_code_dumper_free(struct sieve_code_dumper **cdumper) -{ +void sieve_code_dumper_free(struct sieve_code_dumper **cdumper) +{ sieve_binary_debug_reader_deinit(&(*cdumper)->dreader); pool_unref(&((*cdumper)->pool)); @@ -97,7 +97,7 @@ void sieve_dump_extension_register } void sieve_dump_extension_set_context -(struct sieve_code_dumper *cdumper, const struct sieve_extension *ext, +(struct sieve_code_dumper *cdumper, const struct sieve_extension *ext, void *context) { struct sieve_code_dumper_extension_reg *reg; @@ -109,14 +109,14 @@ void sieve_dump_extension_set_context } void *sieve_dump_extension_get_context -(struct sieve_code_dumper *cdumper, const struct sieve_extension *ext) +(struct sieve_code_dumper *cdumper, const struct sieve_extension *ext) { const struct sieve_code_dumper_extension_reg *reg; if ( ext->id < 0 || ext->id >= (int) array_count(&cdumper->extensions) ) return NULL; - - reg = array_idx(&cdumper->extensions, (unsigned int) ext->id); + + reg = array_idx(&cdumper->extensions, (unsigned int) ext->id); return reg->context; } @@ -126,15 +126,15 @@ void *sieve_dump_extension_get_context void sieve_code_dumpf (const struct sieve_dumptime_env *denv, const char *fmt, ...) { - struct sieve_code_dumper *cdumper = denv->cdumper; + struct sieve_code_dumper *cdumper = denv->cdumper; unsigned tab = cdumper->indent; - + string_t *outbuf = t_str_new(128); va_list args; - - va_start(args, fmt); + + va_start(args, fmt); str_printfa(outbuf, "%08llx: ", (unsigned long long) cdumper->mark_address); - + if ( cdumper->mark_line > 0 && (cdumper->indent == 0 || cdumper->mark_line != cdumper->mark_last_line) ) { str_printfa(outbuf, "%4u: ", cdumper->mark_line); @@ -147,11 +147,11 @@ void sieve_code_dumpf str_append(outbuf, " "); tab--; } - + str_vprintfa(outbuf, fmt, args); str_append_c(outbuf, '\n'); va_end(args); - + o_stream_send(denv->stream, str_data(outbuf), str_len(outbuf)); } @@ -160,7 +160,7 @@ static inline void sieve_code_line_mark { if ( denv->cdumper->dreader != NULL ) { denv->cdumper->mark_line = sieve_binary_debug_read_line - (denv->cdumper->dreader, location); + (denv->cdumper->dreader, location); } } @@ -187,12 +187,12 @@ void sieve_code_ascend(const struct sieve_dumptime_env *denv) if ( denv->cdumper->indent > 0 ) denv->cdumper->indent--; } - + /* Code Dump */ static bool sieve_code_dumper_print_operation -(struct sieve_code_dumper *cdumper) -{ +(struct sieve_code_dumper *cdumper) +{ struct sieve_dumptime_env *denv = cdumper->dumpenv; struct sieve_operation *oprtn = &(cdumper->oprtn); sieve_size_t *address = &(denv->offset); @@ -213,15 +213,15 @@ static bool sieve_code_dumper_print_operation sieve_code_dumpf(denv, "%s", opdef->mnemonic); else return FALSE; - + return TRUE; - } - + } + sieve_code_dumpf(denv, "Failed to read opcode."); return FALSE; } -void sieve_code_dumper_run(struct sieve_code_dumper *cdumper) +void sieve_code_dumper_run(struct sieve_code_dumper *cdumper) { struct sieve_dumptime_env *denv = cdumper->dumpenv; struct sieve_binary *sbin = denv->sbin; @@ -239,7 +239,7 @@ void sieve_code_dumper_run(struct sieve_code_dumper *cdumper) /* Load debug block */ sieve_code_mark(denv); - + if ( sieve_binary_read_unsigned(sblock, address, &debug_block_id) ) { struct sieve_binary_block *debug_block = sieve_binary_block_get(sbin, debug_block_id); @@ -261,27 +261,27 @@ void sieve_code_dumper_run(struct sieve_code_dumper *cdumper) /* Load and dump extensions listed in code */ sieve_code_mark(denv); - + if ( sieve_binary_read_unsigned(sblock, address, &ext_count) ) { unsigned int i; - + sieve_code_dumpf(denv, "EXTENSIONS [%d]:", ext_count); sieve_code_descend(denv); - + for ( i = 0; i < ext_count; i++ ) { unsigned int code = 0; const struct sieve_extension *ext; - + T_BEGIN { sieve_code_mark(denv); - + if ( !sieve_binary_read_extension(sblock, address, &code, &ext) ) { success = FALSE; break; } - + sieve_code_dumpf(denv, "%s", sieve_extension_name(ext)); - + if ( ext->def != NULL && ext->def->code_dump != NULL ) { sieve_code_descend(denv); if ( !ext->def->code_dump(ext, denv, address) ) { @@ -292,16 +292,16 @@ void sieve_code_dumper_run(struct sieve_code_dumper *cdumper) } } T_END; } - + sieve_code_ascend(denv); } else success = FALSE; - + if ( !success ) { sieve_code_dumpf(denv, "Binary code header is corrupt."); return; } - + while ( *address < sieve_binary_block_get_size(sblock) ) { T_BEGIN { @@ -313,9 +313,9 @@ void sieve_code_dumper_run(struct sieve_code_dumper *cdumper) return; } } - + /* Mark end of the binary */ cdumper->indent = 0; cdumper->mark_address = sieve_binary_block_get_size(sblock); - sieve_code_dumpf(denv, "[End of code]"); + sieve_code_dumpf(denv, "[End of code]"); } diff --git a/src/lib-sieve/sieve-code-dumper.h b/src/lib-sieve/sieve-code-dumper.h index 1b623aaa66dc8bc96c604fba1400ae1db1d0e36d..8df89fcb473921be806ed6501ccc4fb5f2b9017f 100644 --- a/src/lib-sieve/sieve-code-dumper.h +++ b/src/lib-sieve/sieve-code-dumper.h @@ -14,13 +14,13 @@ void sieve_code_dumper_free (struct sieve_code_dumper **dumper); pool_t sieve_code_dumper_pool (struct sieve_code_dumper *dumper); - -/* + +/* * Extension support */ struct sieve_code_dumper_extension { - const struct sieve_extension_def *ext; + const struct sieve_extension_def *ext; void (*free)(struct sieve_code_dumper *dumper, void *context); }; @@ -29,13 +29,13 @@ void sieve_dump_extension_register (struct sieve_code_dumper *dumper, const struct sieve_extension *ext, const struct sieve_code_dumper_extension *dump_ext, void *context); void sieve_dump_extension_set_context - (struct sieve_code_dumper *dumper, const struct sieve_extension *ext, + (struct sieve_code_dumper *dumper, const struct sieve_extension *ext, void *context); void *sieve_dump_extension_get_context - (struct sieve_code_dumper *dumper, const struct sieve_extension *ext); - -/* Dump functions */ - + (struct sieve_code_dumper *dumper, const struct sieve_extension *ext); + +/* Dump functions */ + void sieve_code_dumpf (const struct sieve_dumptime_env *denv, const char *fmt, ...) ATTR_FORMAT(2, 3); @@ -47,7 +47,7 @@ void sieve_code_descend(const struct sieve_dumptime_env *denv); void sieve_code_ascend(const struct sieve_dumptime_env *denv); /* Operations and operands */ - + bool sieve_code_dumper_print_optional_operands (const struct sieve_dumptime_env *denv, sieve_size_t *address); diff --git a/src/lib-sieve/sieve-code.c b/src/lib-sieve/sieve-code.c index 2b15592ecece21accd5f1caa1a54670ff3d3ad08..7cfd9842f008e881c798a10fa5ee47e89ca984e3 100644 --- a/src/lib-sieve/sieve-code.c +++ b/src/lib-sieve/sieve-code.c @@ -1,6 +1,6 @@ /* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #include "lib.h" #include "str.h" #include "str-sanitize.h" @@ -19,7 +19,7 @@ #include <stdio.h> -/* +/* * Code stringlist */ @@ -45,14 +45,14 @@ struct sieve_code_stringlist { }; static struct sieve_stringlist *sieve_code_stringlist_create -(const struct sieve_runtime_env *renv, +(const struct sieve_runtime_env *renv, sieve_size_t start_address, unsigned int length, sieve_size_t end) { struct sieve_code_stringlist *strlist; - - if ( end > sieve_binary_block_get_size(renv->sblock) ) + + if ( end > sieve_binary_block_get_size(renv->sblock) ) return NULL; - + strlist = t_new(struct sieve_code_stringlist, 1); strlist->strlist.runenv = renv; strlist->strlist.exec_status = SIEVE_EXEC_OK; @@ -64,40 +64,40 @@ static struct sieve_stringlist *sieve_code_stringlist_create strlist->end_address = end; strlist->length = length; strlist->index = 0; - + return &strlist->strlist; } /* Stringlist implementation */ static int sieve_code_stringlist_next_item -(struct sieve_stringlist *_strlist, string_t **str_r) +(struct sieve_stringlist *_strlist, string_t **str_r) { struct sieve_code_stringlist *strlist = (struct sieve_code_stringlist *) _strlist; sieve_size_t address; *str_r = NULL; int ret; - + /* Check for end of list */ - if ( strlist->index >= strlist->length ) + if ( strlist->index >= strlist->length ) return 0; /* Read next item */ - address = strlist->current_offset; + address = strlist->current_offset; if ( (ret=sieve_opr_string_read(_strlist->runenv, &address, NULL, str_r)) == SIEVE_EXEC_OK ) { strlist->index++; strlist->current_offset = address; return 1; } - + _strlist->exec_status = ret; return -1; } static void sieve_code_stringlist_reset -(struct sieve_stringlist *_strlist) +(struct sieve_stringlist *_strlist) { struct sieve_code_stringlist *strlist = (struct sieve_code_stringlist *) _strlist; @@ -116,45 +116,45 @@ static int sieve_code_stringlist_get_length } static bool sieve_code_stringlist_dump -(const struct sieve_dumptime_env *denv, sieve_size_t *address, +(const struct sieve_dumptime_env *denv, sieve_size_t *address, unsigned int length, sieve_size_t end, const char *field_name) { unsigned int i; - - if ( end > sieve_binary_block_get_size(denv->sblock) ) + + if ( end > sieve_binary_block_get_size(denv->sblock) ) return FALSE; - + if ( field_name != NULL ) - sieve_code_dumpf(denv, "%s: STRLIST [%u] (end: %08llx)", + sieve_code_dumpf(denv, "%s: STRLIST [%u] (end: %08llx)", field_name, length, (unsigned long long) end); else - sieve_code_dumpf(denv, "STRLIST [%u] (end: %08llx)", + sieve_code_dumpf(denv, "STRLIST [%u] (end: %08llx)", length, (unsigned long long) end); - + sieve_code_descend(denv); - + for ( i = 0; i < length; i++ ) { bool success = TRUE; - T_BEGIN { + T_BEGIN { success = sieve_opr_string_dump(denv, address, NULL); } T_END; - if ( !success || *address > end ) + if ( !success || *address > end ) return FALSE; } if ( *address != end ) return FALSE; - + sieve_code_ascend(denv); - + return TRUE; } /* * Core operands */ - + extern const struct sieve_operand_def comparator_operand; extern const struct sieve_operand_def match_type_operand; extern const struct sieve_operand_def address_part_operand; @@ -168,17 +168,17 @@ const struct sieve_operand_def *sieve_operands[] = { &match_type_operand, &address_part_operand, &catenated_string_operand -}; +}; const unsigned int sieve_operand_count = N_ELEMENTS(sieve_operands); -/* - * Operand functions +/* + * Operand functions */ sieve_size_t sieve_operand_emit -(struct sieve_binary_block *sblock, const struct sieve_extension *ext, +(struct sieve_binary_block *sblock, const struct sieve_extension *ext, const struct sieve_operand_def *opr_def) { sieve_size_t address; @@ -186,7 +186,7 @@ sieve_size_t sieve_operand_emit if ( ext != NULL ) { address = sieve_binary_emit_extension (sblock, ext, sieve_operand_count); - + sieve_binary_emit_extension_object (sblock, &opr_def->ext_def->operands, opr_def->code); @@ -198,7 +198,7 @@ sieve_size_t sieve_operand_emit bool sieve_operand_read (struct sieve_binary_block *sblock, sieve_size_t *address, - const char *field_name, struct sieve_operand *operand) + const char *field_name, struct sieve_operand *operand) { unsigned int code = sieve_operand_count; @@ -220,8 +220,8 @@ bool sieve_operand_read if ( operand->ext->def == NULL ) return FALSE; - operand->def = (const struct sieve_operand_def *) - sieve_binary_read_extension_object(sblock, address, + operand->def = (const struct sieve_operand_def *) + sieve_binary_read_extension_object(sblock, address, &operand->ext->def->operands); return ( operand->def != NULL ); @@ -233,28 +233,28 @@ bool sieve_operand_read int sieve_opr_optional_next (struct sieve_binary_block *sblock, sieve_size_t *address, signed int *opt_code) -{ +{ /* Start of optional operand block */ if ( *opt_code == 0 ) { sieve_size_t tmp_addr = *address; unsigned int op; - + if ( !sieve_binary_read_byte(sblock, &tmp_addr, &op) || op != SIEVE_OPERAND_OPTIONAL ) return 0; - + *address = tmp_addr; } /* Read optional operand code */ - if ( !sieve_binary_read_code(sblock, address, opt_code) ) + if ( !sieve_binary_read_code(sblock, address, opt_code) ) return -1; - + /* Return 0 at end of list */ return ( *opt_code != 0 ? 1 : 0 ); } -/* +/* * Operand definitions */ @@ -265,10 +265,10 @@ const struct sieve_operand_class omitted_class = const struct sieve_operand_def omitted_operand = { "@OMITTED", - NULL, SIEVE_OPERAND_OPTIONAL, + NULL, SIEVE_OPERAND_OPTIONAL, &omitted_class, NULL }; - + /* Number */ static bool opr_number_dump @@ -278,19 +278,19 @@ static int opr_number_read (const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd, sieve_size_t *address, sieve_number_t *number_r); -const struct sieve_opr_number_interface number_interface = { - opr_number_dump, +const struct sieve_opr_number_interface number_interface = { + opr_number_dump, opr_number_read }; -const struct sieve_operand_class number_class = +const struct sieve_operand_class number_class = { "number" }; - -const struct sieve_operand_def number_operand = { - "@number", + +const struct sieve_operand_def number_operand = { + "@number", NULL, SIEVE_OPERAND_NUMBER, &number_class, - &number_interface + &number_interface }; /* String */ @@ -302,20 +302,20 @@ static int opr_string_read (const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd, sieve_size_t *address, string_t **str_r); -const struct sieve_opr_string_interface string_interface ={ +const struct sieve_opr_string_interface string_interface ={ opr_string_dump, opr_string_read }; - -const struct sieve_operand_class string_class = + +const struct sieve_operand_class string_class = { "string" }; - -const struct sieve_operand_def string_operand = { - "@string", + +const struct sieve_operand_def string_operand = { + "@string", NULL, SIEVE_OPERAND_STRING, &string_class, &string_interface -}; +}; /* String List */ @@ -326,18 +326,18 @@ static int opr_stringlist_read (const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd, sieve_size_t *address, struct sieve_stringlist **strlist_r); -const struct sieve_opr_stringlist_interface stringlist_interface = { - opr_stringlist_dump, +const struct sieve_opr_stringlist_interface stringlist_interface = { + opr_stringlist_dump, opr_stringlist_read }; -const struct sieve_operand_class stringlist_class = +const struct sieve_operand_class stringlist_class = { "string-list" }; -const struct sieve_operand_def stringlist_operand = { - "@string-list", +const struct sieve_operand_def stringlist_operand = { + "@string-list", NULL, SIEVE_OPERAND_STRING_LIST, - &stringlist_class, + &stringlist_class, &stringlist_interface }; @@ -350,20 +350,20 @@ static int opr_catenated_string_read (const struct sieve_runtime_env *renv, const struct sieve_operand *operand, sieve_size_t *address, string_t **str); -const struct sieve_opr_string_interface catenated_string_interface = { +const struct sieve_opr_string_interface catenated_string_interface = { opr_catenated_string_dump, opr_catenated_string_read }; - -const struct sieve_operand_def catenated_string_operand = { - "@catenated-string", + +const struct sieve_operand_def catenated_string_operand = { + "@catenated-string", NULL, SIEVE_OPERAND_CATENATED_STRING, &string_class, &catenated_string_interface -}; - -/* - * Operand implementations +}; + +/* + * Operand implementations */ /* Omitted */ @@ -372,11 +372,11 @@ void sieve_opr_omitted_emit(struct sieve_binary_block *sblock) { (void) sieve_operand_emit(sblock, NULL, &omitted_operand); } - + /* Number */ void sieve_opr_number_emit -(struct sieve_binary_block *sblock, sieve_number_t number) +(struct sieve_binary_block *sblock, sieve_number_t number) { (void) sieve_operand_emit(sblock, NULL, &number_operand); (void) sieve_binary_emit_integer(sblock, number); @@ -384,31 +384,31 @@ void sieve_opr_number_emit bool sieve_opr_number_dump_data (const struct sieve_dumptime_env *denv, struct sieve_operand *oprnd, - sieve_size_t *address, const char *field_name) + sieve_size_t *address, const char *field_name) { const struct sieve_opr_number_interface *intf; oprnd->field_name = field_name; - if ( !sieve_operand_is_number(oprnd) ) + if ( !sieve_operand_is_number(oprnd) ) return FALSE; - - intf = (const struct sieve_opr_number_interface *) oprnd->def->interface; - + + intf = (const struct sieve_opr_number_interface *) oprnd->def->interface; + if ( intf->dump == NULL ) return FALSE; - return intf->dump(denv, oprnd, address); + return intf->dump(denv, oprnd, address); } bool sieve_opr_number_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address, - const char *field_name) + const char *field_name) { struct sieve_operand operand; - + sieve_code_mark(denv); - + if ( !sieve_operand_read(denv->sblock, address, field_name, &operand) ) return FALSE; @@ -420,7 +420,7 @@ int sieve_opr_number_read_data sieve_size_t *address, const char *field_name, sieve_number_t *number_r) { const struct sieve_opr_number_interface *intf; - + oprnd->field_name = field_name; if ( !sieve_operand_is_number(oprnd) ) { @@ -428,9 +428,9 @@ int sieve_opr_number_read_data "expected number operand but found %s", sieve_operand_name(oprnd)); return SIEVE_EXEC_BIN_CORRUPT; } - - intf = (const struct sieve_opr_number_interface *) oprnd->def->interface; - + + intf = (const struct sieve_opr_number_interface *) oprnd->def->interface; + if ( intf->read == NULL ) { sieve_runtime_trace_operand_error(renv, oprnd, "number operand not implemented"); @@ -441,43 +441,43 @@ int sieve_opr_number_read_data } int sieve_opr_number_read -(const struct sieve_runtime_env *renv, sieve_size_t *address, +(const struct sieve_runtime_env *renv, sieve_size_t *address, const char *field_name, sieve_number_t *number_r) { struct sieve_operand operand; int ret; - if ( (ret=sieve_operand_runtime_read(renv, address, field_name, &operand)) + if ( (ret=sieve_operand_runtime_read(renv, address, field_name, &operand)) <= 0) return ret; - + return sieve_opr_number_read_data (renv, &operand, address, field_name, number_r); } static bool opr_number_dump -(const struct sieve_dumptime_env *denv, const struct sieve_operand *oprnd, - sieve_size_t *address) +(const struct sieve_dumptime_env *denv, const struct sieve_operand *oprnd, + sieve_size_t *address) { sieve_number_t number = 0; - + if (sieve_binary_read_integer(denv->sblock, address, &number) ) { - if ( oprnd->field_name != NULL ) - sieve_code_dumpf(denv, "%s: NUM %llu", oprnd->field_name, + if ( oprnd->field_name != NULL ) + sieve_code_dumpf(denv, "%s: NUM %llu", oprnd->field_name, (unsigned long long) number); else sieve_code_dumpf(denv, "NUM %llu", (unsigned long long) number); return TRUE; } - + return FALSE; } static int opr_number_read -(const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd, +(const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd, sieve_size_t *address, sieve_number_t *number_r) -{ +{ if ( !sieve_binary_read_integer(renv->sblock, address, number_r) ) { sieve_runtime_trace_operand_error(renv, oprnd, "invalid number operand"); return SIEVE_EXEC_BIN_CORRUPT; @@ -496,34 +496,34 @@ void sieve_opr_string_emit(struct sieve_binary_block *sblock, string_t *str) bool sieve_opr_string_dump_data (const struct sieve_dumptime_env *denv, struct sieve_operand *oprnd, - sieve_size_t *address, const char *field_name) + sieve_size_t *address, const char *field_name) { const struct sieve_opr_string_interface *intf; - + oprnd->field_name = field_name; if ( !sieve_operand_is_string(oprnd) ) { - sieve_code_dumpf(denv, "ERROR: INVALID STRING OPERAND %s", + sieve_code_dumpf(denv, "ERROR: INVALID STRING OPERAND %s", sieve_operand_name(oprnd)); return FALSE; } - - intf = (const struct sieve_opr_string_interface *) oprnd->def->interface; - + + intf = (const struct sieve_opr_string_interface *) oprnd->def->interface; + if ( intf->dump == NULL ) { sieve_code_dumpf(denv, "ERROR: DUMP STRING OPERAND"); return FALSE; } - return intf->dump(denv, oprnd, address); + return intf->dump(denv, oprnd, address); } bool sieve_opr_string_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address, - const char *field_name) + const char *field_name) { struct sieve_operand operand; - + sieve_code_mark(denv); if ( !sieve_operand_read(denv->sblock, address, field_name, &operand) ) { @@ -535,11 +535,11 @@ bool sieve_opr_string_dump } bool sieve_opr_string_dump_ex -(const struct sieve_dumptime_env *denv, sieve_size_t *address, +(const struct sieve_dumptime_env *denv, sieve_size_t *address, const char *field_name, const char *omitted_value) { struct sieve_operand operand; - + sieve_code_mark(denv); if ( !sieve_operand_read(denv->sblock, address, field_name, &operand) ) { sieve_code_dumpf(denv, "ERROR: INVALID OPERAND"); @@ -553,7 +553,7 @@ bool sieve_opr_string_dump_ex } return sieve_opr_string_dump_data(denv, &operand, address, field_name); -} +} int sieve_opr_string_read_data (const struct sieve_runtime_env *renv, struct sieve_operand *oprnd, @@ -562,26 +562,26 @@ int sieve_opr_string_read_data const struct sieve_opr_string_interface *intf; oprnd->field_name = field_name; - + if ( !sieve_operand_is_string(oprnd) ) { sieve_runtime_trace_operand_error(renv, oprnd, "expected string operand but found %s", sieve_operand_name(oprnd)); return SIEVE_EXEC_BIN_CORRUPT; } - - intf = (const struct sieve_opr_string_interface *) oprnd->def->interface; - + + intf = (const struct sieve_opr_string_interface *) oprnd->def->interface; + if ( intf->read == NULL ) { sieve_runtime_trace_operand_error(renv, oprnd, "string operand not implemented"); return SIEVE_EXEC_FAILURE; } - return intf->read(renv, oprnd, address, str_r); + return intf->read(renv, oprnd, address, str_r); } int sieve_opr_string_read -(const struct sieve_runtime_env *renv, sieve_size_t *address, +(const struct sieve_runtime_env *renv, sieve_size_t *address, const char *field_name, string_t **str_r) { struct sieve_operand operand; @@ -617,47 +617,47 @@ int sieve_opr_string_read_ex } static void _dump_string -(const struct sieve_dumptime_env *denv, string_t *str, - const char *field_name) +(const struct sieve_dumptime_env *denv, string_t *str, + const char *field_name) { if ( str_len(str) > 80 ) { - if ( field_name != NULL ) - sieve_code_dumpf(denv, "%s: STR[%ld] \"%s", + if ( field_name != NULL ) + sieve_code_dumpf(denv, "%s: STR[%ld] \"%s", field_name, (long) str_len(str), str_sanitize(str_c(str), 80)); else - sieve_code_dumpf(denv, "STR[%ld] \"%s", + sieve_code_dumpf(denv, "STR[%ld] \"%s", (long) str_len(str), str_sanitize(str_c(str), 80)); } else { if ( field_name != NULL ) - sieve_code_dumpf(denv, "%s: STR[%ld] \"%s\"", - field_name, (long) str_len(str), str_sanitize(str_c(str), 80)); + sieve_code_dumpf(denv, "%s: STR[%ld] \"%s\"", + field_name, (long) str_len(str), str_sanitize(str_c(str), 80)); else - sieve_code_dumpf(denv, "STR[%ld] \"%s\"", - (long) str_len(str), str_sanitize(str_c(str), 80)); + sieve_code_dumpf(denv, "STR[%ld] \"%s\"", + (long) str_len(str), str_sanitize(str_c(str), 80)); } } bool opr_string_dump (const struct sieve_dumptime_env *denv, const struct sieve_operand *oprnd, - sieve_size_t *address) + sieve_size_t *address) { - string_t *str; - + string_t *str; + if ( sieve_binary_read_string(denv->sblock, address, &str) ) { - _dump_string(denv, str, oprnd->field_name); - + _dump_string(denv, str, oprnd->field_name); + return TRUE; } - + return FALSE; } static int opr_string_read -(const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd, +(const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd, sieve_size_t *address, string_t **str_r) -{ +{ if ( !sieve_binary_read_string(renv->sblock, address, str_r) ) { - sieve_runtime_trace_operand_error(renv, oprnd, + sieve_runtime_trace_operand_error(renv, oprnd, "invalid string operand"); return SIEVE_EXEC_BIN_CORRUPT; } @@ -672,9 +672,9 @@ void sieve_opr_stringlist_emit_start { sieve_size_t *end_offset = t_new(sieve_size_t, 1); - /* Emit byte identifying the type of operand */ + /* Emit byte identifying the type of operand */ (void) sieve_operand_emit(sblock, NULL, &stringlist_operand); - + /* Give the interpreter an easy way to skip over this string list */ *end_offset = sieve_binary_emit_offset(sblock, 0); *context = (void *) end_offset; @@ -699,37 +699,37 @@ void sieve_opr_stringlist_emit_end bool sieve_opr_stringlist_dump_data (const struct sieve_dumptime_env *denv, struct sieve_operand *oprnd, - sieve_size_t *address, const char *field_name) + sieve_size_t *address, const char *field_name) { if ( oprnd == NULL || oprnd->def == NULL ) return FALSE; - + oprnd->field_name = field_name; if ( oprnd->def->class == &stringlist_class ) { const struct sieve_opr_stringlist_interface *intf = - (const struct sieve_opr_stringlist_interface *) oprnd->def->interface; - + (const struct sieve_opr_stringlist_interface *) oprnd->def->interface; + if ( intf->dump == NULL ) return FALSE; - return intf->dump(denv, oprnd, address); + return intf->dump(denv, oprnd, address); } else if ( oprnd->def->class == &string_class ) { const struct sieve_opr_string_interface *intf = - (const struct sieve_opr_string_interface *) oprnd->def->interface; - - if ( intf->dump == NULL ) + (const struct sieve_opr_string_interface *) oprnd->def->interface; + + if ( intf->dump == NULL ) return FALSE; - return intf->dump(denv, oprnd, address); + return intf->dump(denv, oprnd, address); } - + return FALSE; } bool sieve_opr_stringlist_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address, - const char *field_name) + const char *field_name) { struct sieve_operand operand; @@ -744,7 +744,7 @@ bool sieve_opr_stringlist_dump bool sieve_opr_stringlist_dump_ex (const struct sieve_dumptime_env *denv, sieve_size_t *address, - const char *field_name, const char *omitted_value) + const char *field_name, const char *omitted_value) { struct sieve_operand operand; @@ -765,19 +765,19 @@ bool sieve_opr_stringlist_dump_ex int sieve_opr_stringlist_read_data (const struct sieve_runtime_env *renv, struct sieve_operand *oprnd, - sieve_size_t *address, const char *field_name, + sieve_size_t *address, const char *field_name, struct sieve_stringlist **strlist_r) { if ( oprnd == NULL || oprnd->def == NULL ) return SIEVE_EXEC_FAILURE; oprnd->field_name = field_name; - + if ( oprnd->def->class == &stringlist_class ) { - const struct sieve_opr_stringlist_interface *intf = + const struct sieve_opr_stringlist_interface *intf = (const struct sieve_opr_stringlist_interface *) oprnd->def->interface; int ret; - + if ( intf->read == NULL ) { sieve_runtime_trace_operand_error(renv, oprnd, "stringlist operand not implemented"); @@ -790,10 +790,10 @@ int sieve_opr_stringlist_read_data return SIEVE_EXEC_OK; } else if ( oprnd->def->class == &string_class ) { /* Special case, accept single string as string list as well. */ - const struct sieve_opr_string_interface *intf = + const struct sieve_opr_string_interface *intf = (const struct sieve_opr_string_interface *) oprnd->def->interface; int ret; - + if ( intf->read == NULL ) { sieve_runtime_trace_operand_error(renv, oprnd, "stringlist string operand not implemented"); @@ -803,20 +803,20 @@ int sieve_opr_stringlist_read_data if ( (ret=intf->read(renv, oprnd, address, NULL)) <= 0 ) return ret; - if ( strlist_r != NULL ) + if ( strlist_r != NULL ) *strlist_r = sieve_code_stringlist_create - (renv, oprnd->address, 1, *address); + (renv, oprnd->address, 1, *address); return SIEVE_EXEC_OK; - } + } sieve_runtime_trace_operand_error(renv, oprnd, - "expected stringlist or string operand but found %s", + "expected stringlist or string operand but found %s", sieve_operand_name(oprnd)); return SIEVE_EXEC_BIN_CORRUPT; } int sieve_opr_stringlist_read -(const struct sieve_runtime_env *renv, sieve_size_t *address, +(const struct sieve_runtime_env *renv, sieve_size_t *address, const char *field_name, struct sieve_stringlist **strlist_r) { struct sieve_operand operand; @@ -825,13 +825,13 @@ int sieve_opr_stringlist_read if ( (ret=sieve_operand_runtime_read(renv, address, field_name, &operand)) <= 0 ) return ret; - + return sieve_opr_stringlist_read_data (renv, &operand, address, field_name, strlist_r); } int sieve_opr_stringlist_read_ex -(const struct sieve_runtime_env *renv, sieve_size_t *address, +(const struct sieve_runtime_env *renv, sieve_size_t *address, const char *field_name, bool optional, struct sieve_stringlist **strlist_r) { struct sieve_operand operand; @@ -845,18 +845,18 @@ int sieve_opr_stringlist_read_ex *strlist_r = NULL; return TRUE; } - + return sieve_opr_stringlist_read_data (renv, &operand, address, field_name, strlist_r); } static bool opr_stringlist_dump (const struct sieve_dumptime_env *denv, const struct sieve_operand *oprnd, - sieve_size_t *address) + sieve_size_t *address) { sieve_size_t pc = *address; - sieve_size_t end; - unsigned int length = 0; + sieve_size_t end; + unsigned int length = 0; sieve_offset_t end_offset; if ( !sieve_binary_read_offset(denv->sblock, address, &end_offset) ) @@ -864,11 +864,11 @@ static bool opr_stringlist_dump end = pc + end_offset; - if ( !sieve_binary_read_unsigned(denv->sblock, address, &length) ) - return FALSE; - + if ( !sieve_binary_read_unsigned(denv->sblock, address, &length) ) + return FALSE; + return sieve_code_stringlist_dump - (denv, address, length, end, oprnd->field_name); + (denv, address, length, end, oprnd->field_name); } static int opr_stringlist_read @@ -876,10 +876,10 @@ static int opr_stringlist_read sieve_size_t *address, struct sieve_stringlist **strlist_r) { sieve_size_t pc = *address; - sieve_size_t end; - unsigned int length = 0; + sieve_size_t end; + unsigned int length = 0; sieve_offset_t end_offset; - + if ( !sieve_binary_read_offset(renv->sblock, address, &end_offset) ) { sieve_runtime_trace_operand_error(renv, oprnd, "stringlist corrupt: invalid end offset"); @@ -893,21 +893,21 @@ static int opr_stringlist_read "stringlist corrupt: invalid length data"); return SIEVE_EXEC_BIN_CORRUPT; } - - if ( strlist_r != NULL ) + + if ( strlist_r != NULL ) *strlist_r = sieve_code_stringlist_create - (renv, *address, (unsigned int) length, end); + (renv, *address, (unsigned int) length, end); /* Skip over the string list for now */ *address = end; - + return SIEVE_EXEC_OK; -} +} /* Catenated String */ void sieve_opr_catenated_string_emit -(struct sieve_binary_block *sblock, unsigned int elements) +(struct sieve_binary_block *sblock, unsigned int elements) { (void) sieve_operand_emit(sblock, NULL, &catenated_string_operand); (void) sieve_binary_emit_unsigned(sblock, elements); @@ -915,16 +915,16 @@ void sieve_opr_catenated_string_emit static bool opr_catenated_string_dump (const struct sieve_dumptime_env *denv, const struct sieve_operand *oprnd, - sieve_size_t *address) + sieve_size_t *address) { unsigned int elements = 0; unsigned int i; - + if ( !sieve_binary_read_unsigned(denv->sblock, address, &elements) ) return FALSE; - - if ( oprnd->field_name != NULL ) - sieve_code_dumpf(denv, "%s: CAT-STR [%ld]:", + + if ( oprnd->field_name != NULL ) + sieve_code_dumpf(denv, "%s: CAT-STR [%ld]:", oprnd->field_name, (long) elements); else sieve_code_dumpf(denv, "CAT-STR [%ld]:", (long) elements); @@ -935,30 +935,30 @@ static bool opr_catenated_string_dump return FALSE; } sieve_code_ascend(denv); - + return TRUE; } static int opr_catenated_string_read (const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd, sieve_size_t *address, string_t **str) -{ +{ unsigned int elements = 0; unsigned int i; int ret; - + if ( !sieve_binary_read_unsigned(renv->sblock, address, &elements) ) { sieve_runtime_trace_operand_error(renv, oprnd, "catenated string corrupt: invalid element count data"); return SIEVE_EXEC_BIN_CORRUPT; } - /* Parameter str can be NULL if we are requested to only skip and not + /* Parameter str can be NULL if we are requested to only skip and not * actually read the argument. */ if ( str == NULL ) { - for ( i = 0; i < (unsigned int) elements; i++ ) { - if ( (ret=sieve_opr_string_read(renv, address, NULL, NULL)) <= 0 ) + for ( i = 0; i < (unsigned int) elements; i++ ) { + if ( (ret=sieve_opr_string_read(renv, address, NULL, NULL)) <= 0 ) return ret; } } else { @@ -967,10 +967,10 @@ static int opr_catenated_string_read *str = t_str_new(128); for ( i = 0; i < (unsigned int) elements; i++ ) { - - if ( (ret=sieve_opr_string_read(renv, address, NULL, elm)) <= 0 ) + + if ( (ret=sieve_opr_string_read(renv, address, NULL, elm)) <= 0 ) return ret; - + if ( elm != NULL ) { str_append_str(*str, strelm); @@ -985,10 +985,10 @@ static int opr_catenated_string_read return SIEVE_EXEC_OK; } -/* +/* * Core operations */ - + /* Forward declarations */ static bool opc_jmp_dump @@ -1003,32 +1003,32 @@ static int opc_jmpfalse_execute /* Operation objects defined in this file */ -const struct sieve_operation_def sieve_jmp_operation = { +const struct sieve_operation_def sieve_jmp_operation = { "JMP", NULL, SIEVE_OPERATION_JMP, - opc_jmp_dump, - opc_jmp_execute + opc_jmp_dump, + opc_jmp_execute }; -const struct sieve_operation_def sieve_jmptrue_operation = { +const struct sieve_operation_def sieve_jmptrue_operation = { "JMPTRUE", NULL, SIEVE_OPERATION_JMPTRUE, - opc_jmp_dump, - opc_jmptrue_execute + opc_jmp_dump, + opc_jmptrue_execute }; -const struct sieve_operation_def sieve_jmpfalse_operation = { +const struct sieve_operation_def sieve_jmpfalse_operation = { "JMPFALSE", NULL, SIEVE_OPERATION_JMPFALSE, - opc_jmp_dump, - opc_jmpfalse_execute + opc_jmp_dump, + opc_jmpfalse_execute }; /* Operation objects defined in other files */ - + extern const struct sieve_operation_def cmd_stop_operation; extern const struct sieve_operation_def cmd_keep_operation; extern const struct sieve_operation_def cmd_discard_operation; @@ -1041,12 +1041,12 @@ extern const struct sieve_operation_def tst_size_over_operation; extern const struct sieve_operation_def tst_size_under_operation; const struct sieve_operation_def *sieve_operations[] = { - NULL, - + NULL, + &sieve_jmp_operation, - &sieve_jmptrue_operation, + &sieve_jmptrue_operation, &sieve_jmpfalse_operation, - + &cmd_stop_operation, &cmd_keep_operation, &cmd_discard_operation, @@ -1057,13 +1057,13 @@ const struct sieve_operation_def *sieve_operations[] = { &tst_exists_operation, &tst_size_over_operation, &tst_size_under_operation -}; +}; const unsigned int sieve_operation_count = N_ELEMENTS(sieve_operations); -/* - * Operation functions +/* + * Operation functions */ sieve_size_t sieve_operation_emit @@ -1087,7 +1087,7 @@ sieve_size_t sieve_operation_emit bool sieve_operation_read (struct sieve_binary_block *sblock, sieve_size_t *address, - struct sieve_operation *oprtn) + struct sieve_operation *oprtn) { unsigned int code = sieve_operation_count; @@ -1106,8 +1106,8 @@ bool sieve_operation_read return ( oprtn->def != NULL ); } - oprtn->def = (const struct sieve_operation_def *) - sieve_binary_read_extension_object(sblock, address, + oprtn->def = (const struct sieve_operation_def *) + sieve_binary_read_extension_object(sblock, address, &oprtn->ext->def->operations); return ( oprtn->def != NULL ); @@ -1116,7 +1116,7 @@ bool sieve_operation_read /* * Jump operations */ - + /* Code dump */ static bool opc_jmp_dump @@ -1125,42 +1125,42 @@ static bool opc_jmp_dump const struct sieve_operation *oprtn = denv->oprtn; unsigned int pc = *address; sieve_offset_t offset; - - if ( sieve_binary_read_offset(denv->sblock, address, &offset) ) - sieve_code_dumpf(denv, "%s %d [%08x]", + + if ( sieve_binary_read_offset(denv->sblock, address, &offset) ) + sieve_code_dumpf(denv, "%s %d [%08x]", sieve_operation_mnemonic(oprtn), offset, pc + offset); else return FALSE; - + return TRUE; -} - +} + /* Code execution */ static int opc_jmp_execute -(const struct sieve_runtime_env *renv, sieve_size_t *address ATTR_UNUSED) +(const struct sieve_runtime_env *renv, sieve_size_t *address ATTR_UNUSED) { return sieve_interpreter_program_jump(renv->interp, TRUE); -} - +} + static int opc_jmptrue_execute (const struct sieve_runtime_env *renv, sieve_size_t *address ATTR_UNUSED) -{ +{ bool result = sieve_interpreter_get_test_result(renv->interp); - + sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, "jump if result is true"); sieve_runtime_trace_descend(renv); - + return sieve_interpreter_program_jump(renv->interp, result); } static int opc_jmpfalse_execute (const struct sieve_runtime_env *renv, sieve_size_t *address ATTR_UNUSED) -{ +{ bool result = sieve_interpreter_get_test_result(renv->interp); - + sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, "jump if result is false"); sieve_runtime_trace_descend(renv); return sieve_interpreter_program_jump(renv->interp, !result); -} +} diff --git a/src/lib-sieve/sieve-code.h b/src/lib-sieve/sieve-code.h index e70fb16a10db1827d48da4f20edca57f5846d72b..6a67b873a192aa5c1d02c3278ca0b181cda043b8 100644 --- a/src/lib-sieve/sieve-code.h +++ b/src/lib-sieve/sieve-code.h @@ -1,6 +1,6 @@ /* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #ifndef __SIEVE_CODE_H #define __SIEVE_CODE_H @@ -14,7 +14,7 @@ #include "sieve-runtime-trace.h" #include "sieve-dump.h" -/* +/* * Operand object */ @@ -24,10 +24,10 @@ struct sieve_operand_class { struct sieve_operand_def { const char *name; - + const struct sieve_extension_def *ext_def; unsigned int code; - + const struct sieve_operand_class *class; const void *interface; }; @@ -48,7 +48,7 @@ sieve_size_t sieve_operand_emit (struct sieve_binary_block *sblock, const struct sieve_extension *ext, const struct sieve_operand_def *oprnd); bool sieve_operand_read - (struct sieve_binary_block *sblock, sieve_size_t *address, + (struct sieve_binary_block *sblock, sieve_size_t *address, const char *field_name, struct sieve_operand *oprnd); static inline int sieve_operand_runtime_read @@ -68,11 +68,11 @@ static inline int sieve_operand_runtime_read */ int sieve_opr_optional_next -(struct sieve_binary_block *sblock, sieve_size_t *address, +(struct sieve_binary_block *sblock, sieve_size_t *address, signed int *opt_code); static inline int sieve_opr_optional_dump -(const struct sieve_dumptime_env *denv, sieve_size_t *address, +(const struct sieve_dumptime_env *denv, sieve_size_t *address, signed int *opt_code) { sieve_size_t pc = *address; @@ -82,11 +82,11 @@ static inline int sieve_opr_optional_dump return ret; sieve_code_mark_specific(denv, pc); - return ret; + return ret; } static inline int sieve_opr_optional_read -(const struct sieve_runtime_env *renv, sieve_size_t *address, +(const struct sieve_runtime_env *renv, sieve_size_t *address, signed int *opt_code) { int ret; @@ -100,7 +100,7 @@ static inline int sieve_opr_optional_read /* * Core operands */ - + /* Operand codes */ enum sieve_core_operand { @@ -136,7 +136,7 @@ extern const unsigned int sieve_operand_count; /* Operand object interfaces */ struct sieve_opr_number_interface { - bool (*dump) + bool (*dump) (const struct sieve_dumptime_env *denv, const struct sieve_operand *oprnd, sieve_size_t *address); int (*read) @@ -146,10 +146,10 @@ struct sieve_opr_number_interface { struct sieve_opr_string_interface { bool (*dump) - (const struct sieve_dumptime_env *denv, const struct sieve_operand *oprnd, + (const struct sieve_dumptime_env *denv, const struct sieve_operand *oprnd, sieve_size_t *address); int (*read) - (const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd, + (const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd, sieve_size_t *address, string_t **str_r); }; @@ -162,8 +162,8 @@ struct sieve_opr_stringlist_interface { sieve_size_t *address, struct sieve_stringlist **strlist_r); }; -/* - * Core operand functions +/* + * Core operand functions */ /* Omitted */ @@ -181,23 +181,23 @@ static inline bool sieve_operand_is_omitted void sieve_opr_number_emit (struct sieve_binary_block *sblock, sieve_number_t number); -bool sieve_opr_number_dump_data +bool sieve_opr_number_dump_data (const struct sieve_dumptime_env *denv, struct sieve_operand *operand, - sieve_size_t *address, const char *field_name); -bool sieve_opr_number_dump + sieve_size_t *address, const char *field_name); +bool sieve_opr_number_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address, - const char *field_name); + const char *field_name); int sieve_opr_number_read_data (const struct sieve_runtime_env *renv, struct sieve_operand *operand, sieve_size_t *address, const char *field_name, sieve_number_t *number_r); int sieve_opr_number_read - (const struct sieve_runtime_env *renv, sieve_size_t *address, + (const struct sieve_runtime_env *renv, sieve_size_t *address, const char *field_name, sieve_number_t *number_r); static inline bool sieve_operand_is_number (const struct sieve_operand *operand) { - return ( operand != NULL && operand->def != NULL && + return ( operand != NULL && operand->def != NULL && operand->def->class == &number_class ); } @@ -207,21 +207,21 @@ void sieve_opr_string_emit (struct sieve_binary_block *sblock, string_t *str); bool sieve_opr_string_dump_data (const struct sieve_dumptime_env *denv, struct sieve_operand *operand, - sieve_size_t *address, const char *field_name); + sieve_size_t *address, const char *field_name); bool sieve_opr_string_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address, - const char *field_name); + const char *field_name); bool sieve_opr_string_dump_ex - (const struct sieve_dumptime_env *denv, sieve_size_t *address, - const char *field_name, const char *omitted_value); + (const struct sieve_dumptime_env *denv, sieve_size_t *address, + const char *field_name, const char *omitted_value); int sieve_opr_string_read_data (const struct sieve_runtime_env *renv, struct sieve_operand *operand, sieve_size_t *address, const char *field_name, string_t **str_r); int sieve_opr_string_read - (const struct sieve_runtime_env *renv, sieve_size_t *address, + (const struct sieve_runtime_env *renv, sieve_size_t *address, const char *field_name, string_t **str_r); int sieve_opr_string_read_ex - (const struct sieve_runtime_env *renv, sieve_size_t *address, + (const struct sieve_runtime_env *renv, sieve_size_t *address, const char *field_name, bool optional, string_t **str_r, bool *literal_r); static inline bool sieve_operand_is_string @@ -247,7 +247,7 @@ void sieve_opr_stringlist_emit_item void sieve_opr_stringlist_emit_end (struct sieve_binary_block *sblock, void *context); bool sieve_opr_stringlist_dump_data - (const struct sieve_dumptime_env *denv, struct sieve_operand *operand, + (const struct sieve_dumptime_env *denv, struct sieve_operand *operand, sieve_size_t *address, const char *field_name); bool sieve_opr_stringlist_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address, @@ -256,8 +256,8 @@ bool sieve_opr_stringlist_dump_ex (const struct sieve_dumptime_env *denv, sieve_size_t *address, const char *field_name, const char *omitted_value); int sieve_opr_stringlist_read_data - (const struct sieve_runtime_env *renv, struct sieve_operand *operand, - sieve_size_t *address, const char *field_name, + (const struct sieve_runtime_env *renv, struct sieve_operand *operand, + sieve_size_t *address, const char *field_name, struct sieve_stringlist **strlist_r); int sieve_opr_stringlist_read (const struct sieve_runtime_env *renv, sieve_size_t *address, @@ -270,7 +270,7 @@ static inline bool sieve_operand_is_stringlist (const struct sieve_operand *operand) { return ( operand != NULL && operand->def != NULL && - (operand->def->class == &stringlist_class || + (operand->def->class == &stringlist_class || operand->def->class == &string_class) ); } @@ -278,17 +278,17 @@ static inline bool sieve_operand_is_stringlist void sieve_opr_catenated_string_emit (struct sieve_binary_block *sblock, unsigned int elements); - + /* * Operation object */ - + struct sieve_operation_def { const char *mnemonic; - + const struct sieve_extension_def *ext_def; unsigned int code; - + bool (*dump) (const struct sieve_dumptime_env *denv, sieve_size_t *address); int (*execute) @@ -309,15 +309,15 @@ struct sieve_operation { sieve_size_t sieve_operation_emit (struct sieve_binary_block *sblock, const struct sieve_extension *ext, - const struct sieve_operation_def *op_def); + const struct sieve_operation_def *op_def); bool sieve_operation_read (struct sieve_binary_block *sblock, sieve_size_t *address, struct sieve_operation *oprtn); const char *sieve_operation_read_string (struct sieve_binary_block *sblock, sieve_size_t *address); -/* - * Core operations +/* + * Core operations */ /* Opcodes */ @@ -327,18 +327,18 @@ enum sieve_operation_code { SIEVE_OPERATION_JMP, SIEVE_OPERATION_JMPTRUE, SIEVE_OPERATION_JMPFALSE, - + SIEVE_OPERATION_STOP, SIEVE_OPERATION_KEEP, SIEVE_OPERATION_DISCARD, SIEVE_OPERATION_REDIRECT, - + SIEVE_OPERATION_ADDRESS, - SIEVE_OPERATION_HEADER, - SIEVE_OPERATION_EXISTS, + SIEVE_OPERATION_HEADER, + SIEVE_OPERATION_EXISTS, SIEVE_OPERATION_SIZE_OVER, SIEVE_OPERATION_SIZE_UNDER, - + SIEVE_OPERATION_CUSTOM }; @@ -346,7 +346,7 @@ enum sieve_operation_code { extern const struct sieve_operation_def sieve_jmp_operation; extern const struct sieve_operation_def sieve_jmptrue_operation; -extern const struct sieve_operation_def sieve_jmpfalse_operation; +extern const struct sieve_operation_def sieve_jmpfalse_operation; extern const struct sieve_operation_def *sieve_operations[]; extern const unsigned int sieve_operations_count; diff --git a/src/lib-sieve/sieve-commands.c b/src/lib-sieve/sieve-commands.c index 243e5bfde94f408e2e7ad028237b15ddf60ab104..4330834dae3ed66308d823c6930df84d12b4b2a2 100644 --- a/src/lib-sieve/sieve-commands.c +++ b/src/lib-sieve/sieve-commands.c @@ -16,51 +16,51 @@ #include "sieve-code.h" #include "sieve-interpreter.h" -/* +/* * Literal arguments */ /* Forward declarations */ static bool arg_number_generate - (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, + (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *context); static bool arg_string_generate - (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, + (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *context); static bool arg_string_list_validate - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *context); static bool arg_string_list_generate - (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, + (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *context); /* Argument objects */ -const struct sieve_argument_def number_argument = { - "@number", +const struct sieve_argument_def number_argument = { + "@number", NULL, NULL, NULL, NULL, - arg_number_generate + arg_number_generate }; -const struct sieve_argument_def string_argument = { - "@string", +const struct sieve_argument_def string_argument = { + "@string", NULL, NULL, NULL, NULL, - arg_string_generate + arg_string_generate }; -const struct sieve_argument_def string_list_argument = { - "@string-list", +const struct sieve_argument_def string_list_argument = { + "@string-list", NULL, - arg_string_list_validate, - NULL, NULL, - arg_string_list_generate -}; + arg_string_list_validate, + NULL, NULL, + arg_string_list_generate +}; /* Argument implementations */ static bool arg_number_generate -(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, +(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *cmd ATTR_UNUSED) { sieve_opr_number_emit(cgenv->sblock, sieve_ast_argument_number(arg)); @@ -69,38 +69,38 @@ static bool arg_number_generate } static bool arg_string_generate -(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, +(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *cmd ATTR_UNUSED) { sieve_opr_string_emit(cgenv->sblock, sieve_ast_argument_str(arg)); - + return TRUE; } static bool arg_string_list_validate -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd) { struct sieve_ast_argument *stritem; - stritem = sieve_ast_strlist_first(*arg); + stritem = sieve_ast_strlist_first(*arg); while ( stritem != NULL ) { if ( !sieve_validator_argument_activate(valdtr, cmd, stritem, FALSE) ) return FALSE; - + stritem = sieve_ast_strlist_next(stritem); } - return TRUE; + return TRUE; } static bool emit_string_list_operand (const struct sieve_codegen_env *cgenv, const struct sieve_ast_argument *strlist, struct sieve_command *cmd) -{ +{ void *list_context; struct sieve_ast_argument *stritem; - + sieve_opr_stringlist_emit_start (cgenv->sblock, sieve_ast_strlist_count(strlist), &list_context); @@ -108,17 +108,17 @@ static bool emit_string_list_operand while ( stritem != NULL ) { if ( !sieve_generate_argument(cgenv, stritem, cmd) ) return FALSE; - + stritem = sieve_ast_strlist_next(stritem); } sieve_opr_stringlist_emit_end(cgenv->sblock, list_context); - + return TRUE; } static bool arg_string_list_generate -(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, +(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *cmd) { if ( sieve_ast_argument_type(arg) == SAAT_STRING ) { @@ -126,34 +126,34 @@ static bool arg_string_list_generate } else if ( sieve_ast_argument_type(arg) == SAAT_STRING_LIST ) { bool result = TRUE; - - if ( sieve_ast_strlist_count(arg) == 1 ) + + if ( sieve_ast_strlist_count(arg) == 1 ) return ( sieve_generate_argument (cgenv, sieve_ast_strlist_first(arg), cmd) ); else { - T_BEGIN { + T_BEGIN { result=emit_string_list_operand(cgenv, arg, cmd); } T_END; } return result; } - + return FALSE; } /* - * Abstract arguments + * Abstract arguments * * (Generated by processing and not by parsing the grammar) */ - + /* Catenated string */ struct sieve_arg_catenated_string { struct sieve_ast_arg_list *str_parts; }; - + struct sieve_arg_catenated_string *sieve_arg_catenated_string_create (struct sieve_ast_argument *orig_arg) { @@ -162,16 +162,16 @@ struct sieve_arg_catenated_string *sieve_arg_catenated_string_create struct sieve_arg_catenated_string *catstr; arglist = sieve_ast_arg_list_create(pool); - + catstr = p_new(pool, struct sieve_arg_catenated_string, 1); catstr->str_parts = arglist; (orig_arg)->argument->data = (void *) catstr; - + return catstr; } void sieve_arg_catenated_string_add_element -(struct sieve_arg_catenated_string *catstr, +(struct sieve_arg_catenated_string *catstr, struct sieve_ast_argument *element) { sieve_ast_arg_list_add(catstr->str_parts, element); @@ -182,13 +182,13 @@ void sieve_arg_catenated_string_add_element #define _cat_string_next(item) __AST_LIST_NEXT(item) bool sieve_arg_catenated_string_generate -(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, - struct sieve_command *cmd) +(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, + struct sieve_command *cmd) { - struct sieve_arg_catenated_string *catstr = + struct sieve_arg_catenated_string *catstr = (struct sieve_arg_catenated_string *) arg->argument->data; struct sieve_ast_argument *strpart; - + if ( _cat_string_count(catstr) == 1 ) sieve_generate_argument(cgenv, _cat_string_first(catstr), cmd); else { @@ -198,11 +198,11 @@ bool sieve_arg_catenated_string_generate while ( strpart != NULL ) { if ( !sieve_generate_argument(cgenv, strpart, cmd) ) return FALSE; - + strpart = _cat_string_next(strpart); } } - + return TRUE; } @@ -226,8 +226,8 @@ struct sieve_argument *sieve_argument_create return arg; } -/* - * Core tests and commands +/* + * Core tests and commands */ const struct sieve_command_def *sieve_core_tests[] = { @@ -239,58 +239,58 @@ const struct sieve_command_def *sieve_core_tests[] = { const unsigned int sieve_core_tests_count = N_ELEMENTS(sieve_core_tests); const struct sieve_command_def *sieve_core_commands[] = { - &cmd_require, - &cmd_stop, &cmd_if, &cmd_elsif, &cmd_else, + &cmd_require, + &cmd_stop, &cmd_if, &cmd_elsif, &cmd_else, &cmd_keep, &cmd_discard, &cmd_redirect }; const unsigned int sieve_core_commands_count = N_ELEMENTS(sieve_core_commands); - -/* - * Command context + +/* + * Command context */ -struct sieve_command *sieve_command_prev -(struct sieve_command *cmd) +struct sieve_command *sieve_command_prev +(struct sieve_command *cmd) { struct sieve_ast_node *node = sieve_ast_node_prev(cmd->ast_node); - + if ( node != NULL ) { return node->command; } - + return NULL; } struct sieve_command *sieve_command_parent -(struct sieve_command *cmd) +(struct sieve_command *cmd) { struct sieve_ast_node *node = sieve_ast_node_parent(cmd->ast_node); - - return ( node != NULL ? node->command : NULL ); + + return ( node != NULL ? node->command : NULL ); } struct sieve_command *sieve_command_create (struct sieve_ast_node *cmd_node, const struct sieve_extension *ext, - const struct sieve_command_def *cmd_def, + const struct sieve_command_def *cmd_def, struct sieve_command_registration *cmd_reg) { struct sieve_command *cmd; - + cmd = p_new(sieve_ast_node_pool(cmd_node), struct sieve_command, 1); cmd->ast_node = cmd_node; cmd->def = cmd_def; cmd->ext = ext; cmd->reg = cmd_reg; - + cmd->block_exit_command = NULL; - + return cmd; } const char *sieve_command_def_type_name -(const struct sieve_command_def *cmd_def) +(const struct sieve_command_def *cmd_def) { switch ( cmd_def->type ) { case SCT_NONE: return "command of unspecified type (bug)"; @@ -307,16 +307,16 @@ struct sieve_ast_argument *sieve_command_add_dynamic_tag const struct sieve_argument_def *tag, int id_code) { struct sieve_ast_argument *arg; - + if ( cmd->first_positional != NULL ) arg = sieve_ast_argument_tag_insert (cmd->first_positional, tag->identifier, cmd->ast_node->source_line); else arg = sieve_ast_argument_tag_create (cmd->ast_node, tag->identifier, cmd->ast_node->source_line); - + arg->argument = sieve_argument_create(cmd->ast_node->ast, tag, ext, id_code); - + return arg; } @@ -324,21 +324,21 @@ struct sieve_ast_argument *sieve_command_find_argument (struct sieve_command *cmd, const struct sieve_argument_def *arg_def) { struct sieve_ast_argument *arg = sieve_ast_argument_first(cmd->ast_node); - + /* Visit tagged and optional arguments */ while ( arg != NULL ) { - if ( arg->argument != NULL && arg->argument->def == arg_def ) + if ( arg->argument != NULL && arg->argument->def == arg_def ) return arg; - + arg = sieve_ast_argument_next(arg); } - + return arg; } /* Use this function with caution. The command commits to exiting the block. - * When it for some reason does not, the interpretation will break later on, - * because exiting jumps are not generated when they would otherwise be + * When it for some reason does not, the interpretation will break later on, + * because exiting jumps are not generated when they would otherwise be * necessary. */ void sieve_command_exit_block_unconditionally @@ -347,7 +347,7 @@ void sieve_command_exit_block_unconditionally struct sieve_command *parent = sieve_command_parent(cmd); /* Only the first unconditional exit is of importance */ - if ( parent != NULL && parent->block_exit_command == NULL ) + if ( parent != NULL && parent->block_exit_command == NULL ) parent->block_exit_command = cmd; } @@ -383,7 +383,7 @@ static int _verify_header_name_item bool sieve_command_verify_headers_argument (struct sieve_validator *valdtr, struct sieve_ast_argument *headers) -{ +{ return ( sieve_ast_stringlist_map (&headers, (void *) valdtr, _verify_header_name_item) >= 0 ); } diff --git a/src/lib-sieve/sieve-commands.h b/src/lib-sieve/sieve-commands.h index 6d73c1dff5dc483b20dbb656bf1684105a007c48..b5bf262b88e3e786555c34219b4035230acab3ef 100644 --- a/src/lib-sieve/sieve-commands.h +++ b/src/lib-sieve/sieve-commands.h @@ -9,29 +9,29 @@ #include "sieve-common.h" #include "sieve-ast.h" -/* +/* * Argument definition */ struct sieve_argument_def { const char *identifier; - + bool (*is_instance_of) (struct sieve_validator *valdtr, struct sieve_command *cmd, const struct sieve_extension *ext, const char *identifier, void **data); - + bool (*validate) - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); bool (*validate_context) - (struct sieve_validator *valdtr, struct sieve_ast_argument *arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument *arg, struct sieve_command *cmd); - bool (*validate_persistent) + bool (*validate_persistent) (struct sieve_validator *valdtr, struct sieve_command *cmd, const struct sieve_extension *ext); bool (*generate) - (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, + (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *cmd); }; @@ -82,18 +82,18 @@ extern const struct sieve_argument_def string_list_argument; /* Catenated string argument */ bool sieve_arg_catenated_string_generate - (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, + (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *context); -struct sieve_arg_catenated_string; +struct sieve_arg_catenated_string; struct sieve_arg_catenated_string *sieve_arg_catenated_string_create (struct sieve_ast_argument *orig_arg); void sieve_arg_catenated_string_add_element - (struct sieve_arg_catenated_string *strdata, + (struct sieve_arg_catenated_string *strdata, struct sieve_ast_argument *element); -/* +/* * Command definition */ @@ -107,26 +107,26 @@ enum sieve_command_type { struct sieve_command_def { const char *identifier; enum sieve_command_type type; - + /* High-level command syntax */ int positional_arguments; int subtests; bool block_allowed; bool block_required; - + bool (*registered) (struct sieve_validator *valdtr, const struct sieve_extension *ext, - struct sieve_command_registration *cmd_reg); + struct sieve_command_registration *cmd_reg); bool (*pre_validate) - (struct sieve_validator *valdtr, struct sieve_command *cmd); + (struct sieve_validator *valdtr, struct sieve_command *cmd); bool (*validate) (struct sieve_validator *valdtr, struct sieve_command *cmd); bool (*validate_const) (struct sieve_validator *valdtr, struct sieve_command *cmd, - int *const_current, int const_next); - bool (*generate) + int *const_current, int const_next); + bool (*generate) (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd); - bool (*control_generate) + bool (*control_generate) (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd, struct sieve_jumplist *jumps, bool jump_true); }; @@ -138,13 +138,13 @@ struct sieve_command_def { struct sieve_command { const struct sieve_command_def *def; const struct sieve_extension *ext; - + /* The registration of this command in the validator (sieve-validator.h) */ struct sieve_command_registration *reg; /* The ast node of this command */ struct sieve_ast_node *ast_node; - + /* First positional argument, found during argument validation */ struct sieve_ast_argument *first_positional; @@ -160,7 +160,7 @@ struct sieve_command { #define sieve_command_identifier(cmd) \ ( (cmd)->def->identifier ) #define sieve_command_type_name(cmd) \ - ( sieve_command_def_type_name((cmd)->def) ) + ( sieve_command_def_type_name((cmd)->def) ) #define sieve_commands_equal(cmd1, cmd2) \ ( (cmd1) != NULL && (cmd2) != NULL && (cmd1)->def == (cmd2)->def ) @@ -171,28 +171,28 @@ struct sieve_command *sieve_command_create (struct sieve_ast_node *cmd_node, const struct sieve_extension *ext, const struct sieve_command_def *cmd_def, struct sieve_command_registration *cmd_reg); - + const char *sieve_command_def_type_name - (const struct sieve_command_def *cmd_def); + (const struct sieve_command_def *cmd_def); struct sieve_command *sieve_command_prev - (struct sieve_command *cmd); -struct sieve_command *sieve_command_parent (struct sieve_command *cmd); - +struct sieve_command *sieve_command_parent + (struct sieve_command *cmd); + struct sieve_ast_argument *sieve_command_add_dynamic_tag (struct sieve_command *cmd, const struct sieve_extension *ext, const struct sieve_argument_def *tag, int id_code); struct sieve_ast_argument *sieve_command_find_argument - (struct sieve_command *cmd, const struct sieve_argument_def *argument); - + (struct sieve_command *cmd, const struct sieve_argument_def *argument); + void sieve_command_exit_block_unconditionally (struct sieve_command *cmd); bool sieve_command_block_exits_unconditionally (struct sieve_command *cmd); - + /* Error handling */ - + #define sieve_command_validate_error(validator, context, ...) \ sieve_validator_error(validator, (context)->ast_node->source_line, __VA_ARGS__) #define sieve_command_validate_warning(validator, context, ...) \ @@ -213,16 +213,16 @@ bool sieve_command_block_exits_unconditionally #define sieve_command_first_argument(context) \ sieve_ast_argument_first((context)->ast_node) - + #define sieve_command_is_toplevel(context) \ ( sieve_ast_node_type(sieve_ast_node_parent((context)->ast_node)) == SAT_ROOT ) #define sieve_command_is_first(context) \ - ( sieve_ast_node_prev((context)->ast_node) == NULL ) + ( sieve_ast_node_prev((context)->ast_node) == NULL ) /* * Core commands */ - + extern const struct sieve_command_def cmd_require; extern const struct sieve_command_def cmd_stop; extern const struct sieve_command_def cmd_if; @@ -235,8 +235,8 @@ extern const struct sieve_command_def cmd_discard; extern const struct sieve_command_def *sieve_core_commands[]; extern const unsigned int sieve_core_commands_count; -/* - * Core tests +/* + * Core tests */ extern const struct sieve_command_def tst_true; diff --git a/src/lib-sieve/sieve-common.h b/src/lib-sieve/sieve-common.h index 92ad7b9069cbc2ab5537bf3cc94e37fe615b4a51..912560bdc7ce572fc33d505cb081db03013dd3bc 100644 --- a/src/lib-sieve/sieve-common.h +++ b/src/lib-sieve/sieve-common.h @@ -12,11 +12,11 @@ #include <sys/types.h> #include <stdlib.h> -/* +/* * Types */ -typedef size_t sieve_size_t; +typedef size_t sieve_size_t; typedef uint32_t sieve_offset_t; typedef uint32_t sieve_number_t; @@ -141,11 +141,11 @@ struct sieve_plugin; /* sieve.c */ struct sieve_ast *sieve_parse - (struct sieve_script *script, struct sieve_error_handler *ehandler, + (struct sieve_script *script, struct sieve_error_handler *ehandler, enum sieve_error *error_r); bool sieve_validate (struct sieve_ast *ast, struct sieve_error_handler *ehandler, - enum sieve_compile_flags flags, enum sieve_error *error_r); + enum sieve_compile_flags flags, enum sieve_error *error_r); /* * Sieve engine instance diff --git a/src/lib-sieve/sieve-comparators.c b/src/lib-sieve/sieve-comparators.c index dbcde005f8978fbe109abb4989e72ac5a1804b8f..dce73d834a3e08fda9fafe37f12e5ce44027dbad 100644 --- a/src/lib-sieve/sieve-comparators.c +++ b/src/lib-sieve/sieve-comparators.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ #include "lib.h" @@ -20,10 +20,10 @@ #include <string.h> #include <stdio.h> -/* +/* * Core comparators */ - + const struct sieve_comparator_def *sieve_core_comparators[] = { &i_octet_comparator, &i_ascii_casemap_comparator }; @@ -31,8 +31,8 @@ const struct sieve_comparator_def *sieve_core_comparators[] = { const unsigned int sieve_core_comparators_count = N_ELEMENTS(sieve_core_comparators); -/* - * Comparator 'extension' +/* + * Comparator 'extension' */ static bool cmp_validator_load @@ -47,11 +47,11 @@ const struct sieve_extension_def comparator_extension = { SIEVE_EXT_DEFINE_NO_OPERANDS /* Defined as core operand */ }; -/* +/* * Validator context: - * name-based comparator registry. + * name-based comparator registry. */ - + static struct sieve_validator_object_registry *_get_object_registry (struct sieve_validator *valdtr) { @@ -65,16 +65,16 @@ static struct sieve_validator_object_registry *_get_object_registry void sieve_comparator_register (struct sieve_validator *valdtr, const struct sieve_extension *ext, - const struct sieve_comparator_def *cmp) + const struct sieve_comparator_def *cmp) { struct sieve_validator_object_registry *regs = _get_object_registry(valdtr); - + sieve_validator_object_registry_add(regs, ext, &cmp->obj_def); } static struct sieve_comparator *sieve_comparator_create -(struct sieve_validator *valdtr, struct sieve_command *cmd, - const char *identifier) +(struct sieve_validator *valdtr, struct sieve_command *cmd, + const char *identifier) { struct sieve_validator_object_registry *regs = _get_object_registry(valdtr); struct sieve_object object; @@ -93,10 +93,10 @@ static struct sieve_comparator *sieve_comparator_create bool cmp_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr) { - struct sieve_validator_object_registry *regs = + struct sieve_validator_object_registry *regs = sieve_validator_object_registry_init(valdtr, ext); unsigned int i; - + /* Register core comparators */ for ( i = 0; i < sieve_core_comparators_count; i++ ) { sieve_validator_object_registry_add @@ -106,47 +106,47 @@ bool cmp_validator_load return TRUE; } -/* - * Comparator tagged argument +/* + * Comparator tagged argument */ - + /* Forward declarations */ static bool tag_comparator_validate - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); static bool tag_comparator_generate - (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, + (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *cmd); /* Argument object */ -const struct sieve_argument_def comparator_tag = { - "comparator", - NULL, - tag_comparator_validate, +const struct sieve_argument_def comparator_tag = { + "comparator", + NULL, + tag_comparator_validate, NULL, NULL, - tag_comparator_generate + tag_comparator_generate }; /* Argument implementation */ static bool tag_comparator_validate -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd) { struct sieve_ast_argument *tag = *arg; const struct sieve_comparator *cmp; - + /* Skip tag */ *arg = sieve_ast_argument_next(*arg); - + /* Check syntax: * ":comparator" <comparator-name: string> */ if ( (*arg)->type != SAAT_STRING ) { - sieve_argument_validate_error(valdtr, *arg, - ":comparator tag requires one string argument, but %s was found", + sieve_argument_validate_error(valdtr, *arg, + ":comparator tag requires one string argument, but %s was found", sieve_ast_argument_name(*arg) ); return FALSE; } @@ -158,51 +158,51 @@ static bool tag_comparator_validate * variables are not allowed. */ if ( !sieve_argument_is_string_literal(*arg) ) { - sieve_argument_validate_error(valdtr, *arg, + sieve_argument_validate_error(valdtr, *arg, "this Sieve implementation currently only supports " "a literal string argument for the :comparator tag"); return FALSE; } - + /* Get comparator from registry */ cmp = sieve_comparator_create(valdtr, cmd, sieve_ast_argument_strc(*arg)); - + if ( cmp == NULL ) { - sieve_argument_validate_error(valdtr, *arg, - "unknown comparator '%s'", + sieve_argument_validate_error(valdtr, *arg, + "unknown comparator '%s'", str_sanitize(sieve_ast_argument_strc(*arg),80)); return FALSE; } - - /* String argument not needed during code generation, so detach it from - * argument list + + /* String argument not needed during code generation, so detach it from + * argument list */ *arg = sieve_ast_arguments_detach(*arg, 1); /* Store comparator in context */ tag->argument->data = (void *) cmp; - + return TRUE; } static bool tag_comparator_generate -(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, +(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *cmd ATTR_UNUSED) { - const struct sieve_comparator *cmp = + const struct sieve_comparator *cmp = (const struct sieve_comparator *) arg->argument->data; - + sieve_opr_comparator_emit(cgenv->sblock, cmp); - + return TRUE; } /* Functions to enable and evaluate comparator tag for commands */ void sieve_comparators_link_tag -(struct sieve_validator *valdtr, struct sieve_command_registration *cmd_reg, - int id_code) +(struct sieve_validator *valdtr, struct sieve_command_registration *cmd_reg, + int id_code) { struct sieve_instance *svinst; const struct sieve_extension *mcht_ext; @@ -211,7 +211,7 @@ void sieve_comparators_link_tag mcht_ext = sieve_get_comparator_extension(svinst); sieve_validator_register_tag - (valdtr, cmd_reg, mcht_ext, &comparator_tag, id_code); + (valdtr, cmd_reg, mcht_ext, &comparator_tag, id_code); } bool sieve_comparator_tag_is @@ -223,7 +223,7 @@ bool sieve_comparator_tag_is return FALSE; cmp = (const struct sieve_comparator *) tag->argument->data; - + return ( cmp->def == cmp_def ); } @@ -233,24 +233,24 @@ const struct sieve_comparator *sieve_comparator_tag_get if ( !sieve_argument_is(tag, comparator_tag) ) return NULL; - + return (const struct sieve_comparator *) tag->argument->data; } /* * Comparator coding */ - -const struct sieve_operand_class sieve_comparator_operand_class = + +const struct sieve_operand_class sieve_comparator_operand_class = { "comparator" }; - + static const struct sieve_extension_objects core_comparators = SIEVE_EXT_DEFINE_COMPARATORS(sieve_core_comparators); -const struct sieve_operand_def comparator_operand = { - "comparator", +const struct sieve_operand_def comparator_operand = { + "comparator", NULL, - SIEVE_OPERAND_COMPARATOR, + SIEVE_OPERAND_COMPARATOR, &sieve_comparator_operand_class, &core_comparators }; @@ -260,13 +260,13 @@ const struct sieve_operand_def comparator_operand = { */ bool sieve_comparator_octet_skip - (const struct sieve_comparator *cmp ATTR_UNUSED, + (const struct sieve_comparator *cmp ATTR_UNUSED, const char **val, const char *val_end) { if ( *val < val_end ) { (*val)++; return TRUE; } - + return FALSE; } diff --git a/src/lib-sieve/sieve-comparators.h b/src/lib-sieve/sieve-comparators.h index 9442c76694ade56c33192338f57f005877b00f98..b249610aab7f9167e00ee8e295dde1d3558aee1c 100644 --- a/src/lib-sieve/sieve-comparators.h +++ b/src/lib-sieve/sieve-comparators.h @@ -1,6 +1,6 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #ifndef __SIEVE_COMPARATORS_H #define __SIEVE_COMPARATORS_H @@ -10,10 +10,10 @@ #include "sieve-objects.h" #include "sieve-code.h" -/* - * Core comparators +/* + * Core comparators */ - + enum sieve_comparator_code { SIEVE_COMPARATOR_I_OCTET, SIEVE_COMPARATOR_I_ASCII_CASEMAP, @@ -31,7 +31,7 @@ enum sieve_comparator_flags { SIEVE_COMPARATOR_FLAG_ORDERING = (1 << 0), SIEVE_COMPARATOR_FLAG_EQUALITY = (1 << 1), SIEVE_COMPARATOR_FLAG_PREFIX_MATCH = (1 << 2), - SIEVE_COMPARATOR_FLAG_SUBSTRING_MATCH = (1 << 3), + SIEVE_COMPARATOR_FLAG_SUBSTRING_MATCH = (1 << 3), }; /* @@ -39,22 +39,22 @@ enum sieve_comparator_flags { */ struct sieve_comparator_def { - struct sieve_object_def obj_def; - + struct sieve_object_def obj_def; + unsigned int flags; - + /* Equality and ordering */ - int (*compare)(const struct sieve_comparator *cmp, - const char *val1, size_t val1_size, + int (*compare)(const struct sieve_comparator *cmp, + const char *val1, size_t val1_size, const char *val2, size_t val2_size); - + /* Prefix and substring match */ - - bool (*char_match)(const struct sieve_comparator *cmp, + + bool (*char_match)(const struct sieve_comparator *cmp, const char **val, const char *val_end, const char **key, const char *key_end); - bool (*char_skip)(const struct sieve_comparator *cmp, + bool (*char_skip)(const struct sieve_comparator *cmp, const char **val, const char *val_end); }; @@ -64,9 +64,9 @@ struct sieve_comparator_def { struct sieve_comparator { struct sieve_object object; - + const struct sieve_comparator_def *def; -}; +}; #define SIEVE_COMPARATOR_DEFAULT(definition) \ { SIEVE_OBJECT_DEFAULT(definition), &(definition) } @@ -74,7 +74,7 @@ struct sieve_comparator { #define sieve_comparator_name(cmp) \ ( (cmp)->object.def->identifier ) #define sieve_comparator_is(cmp, definition) \ - ( (cmp)->def == &(definition) ) + ( (cmp)->def == &(definition) ) static inline const struct sieve_comparator *sieve_comparator_copy (pool_t pool, const struct sieve_comparator *cmp_orig) @@ -89,18 +89,18 @@ static inline const struct sieve_comparator *sieve_comparator_copy /* * Comparator tagged argument */ - + extern const struct sieve_argument_def comparator_tag; static inline bool sieve_argument_is_comparator -(struct sieve_ast_argument *arg) +(struct sieve_ast_argument *arg) { - return ( arg->argument != NULL && + return ( arg->argument != NULL && (arg->argument->def == &comparator_tag) ); } void sieve_comparators_link_tag - (struct sieve_validator *validator, + (struct sieve_validator *validator, struct sieve_command_registration *cmd_reg, int id_code); bool sieve_comparator_tag_is (struct sieve_ast_argument *tag, const struct sieve_comparator_def *cmp); @@ -109,8 +109,8 @@ const struct sieve_comparator *sieve_comparator_tag_get void sieve_comparator_register (struct sieve_validator *validator, const struct sieve_extension *ext, - const struct sieve_comparator_def *cmp); - + const struct sieve_comparator_def *cmp); + /* * Comparator operand */ @@ -123,7 +123,7 @@ extern const struct sieve_operand_def comparator_operand; static inline void sieve_opr_comparator_emit (struct sieve_binary_block *sblock, const struct sieve_comparator *cmp) -{ +{ sieve_opr_object_emit(sblock, cmp->object.ext, cmp->object.def); } static inline bool sieve_opr_comparator_dump @@ -144,13 +144,13 @@ static inline int sieve_opr_comparator_read cmp->def = (const struct sieve_comparator_def *) cmp->object.def; return SIEVE_EXEC_OK; } - + /* * Trivial/Common comparator method implementations */ bool sieve_comparator_octet_skip - (const struct sieve_comparator *cmp ATTR_UNUSED, + (const struct sieve_comparator *cmp ATTR_UNUSED, const char **val, const char *val_end); #endif /* __SIEVE_COMPARATORS_H */ diff --git a/src/lib-sieve/sieve-config.h b/src/lib-sieve/sieve-config.h index fc1ae966872adb4fa410c2a23e684c3aa0de2d34..e7158ad4ab1aaea7a40d9a2442e7495879655068 100644 --- a/src/lib-sieve/sieve-config.h +++ b/src/lib-sieve/sieve-config.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ #ifndef __SIEVE_CONFIG_H diff --git a/src/lib-sieve/sieve-dump.h b/src/lib-sieve/sieve-dump.h index b1254bbd9eede2d64de1b59e9081d6811767ae5c..1c487e32c5c14feb073fead2f0020d00708ad62d 100644 --- a/src/lib-sieve/sieve-dump.h +++ b/src/lib-sieve/sieve-dump.h @@ -25,7 +25,7 @@ struct sieve_dumptime_env { /* Code position */ const struct sieve_operation *oprtn; sieve_size_t offset; - + /* Output stream */ struct ostream *stream; }; diff --git a/src/lib-sieve/sieve-error-private.h b/src/lib-sieve/sieve-error-private.h index eb95c06dfe5011d9f3e465ba2450b6dfe9cb13ae..7a30cbcae5c2b33d733284213671ccf27c80df09 100644 --- a/src/lib-sieve/sieve-error-private.h +++ b/src/lib-sieve/sieve-error-private.h @@ -10,7 +10,7 @@ * Types */ -enum sieve_error_flags { +enum sieve_error_flags { SIEVE_ERROR_FLAG_GLOBAL = (1 << 0) }; @@ -62,11 +62,11 @@ struct sieve_error_handler { }; void sieve_error_handler_init - (struct sieve_error_handler *ehandler, struct sieve_instance *svinst, + (struct sieve_error_handler *ehandler, struct sieve_instance *svinst, pool_t pool, unsigned int max_errors); void sieve_error_handler_init_from_parent - (struct sieve_error_handler *ehandler, pool_t pool, + (struct sieve_error_handler *ehandler, pool_t pool, struct sieve_error_handler *parent); /* @@ -92,9 +92,9 @@ static inline void sieve_direct_error { va_list args; va_start(args, fmt); - + sieve_direct_verror(svinst, ehandler, flags, location, fmt, args); - + va_end(args); } @@ -104,9 +104,9 @@ static inline void sieve_direct_warning { va_list args; va_start(args, fmt); - + sieve_direct_vwarning(svinst, ehandler, flags, location, fmt, args); - + va_end(args); } @@ -116,9 +116,9 @@ static inline void sieve_direct_info { va_list args; va_start(args, fmt); - + sieve_direct_vinfo(svinst, ehandler, flags, location, fmt, args); - + va_end(args); } diff --git a/src/lib-sieve/sieve-error.c b/src/lib-sieve/sieve-error.c index 6c1bfd2b8677b6fe2a45d5fa1fa468c98546d953..b14bef8d71036605e9f9b0ff20cfc678975bed73 100644 --- a/src/lib-sieve/sieve-error.c +++ b/src/lib-sieve/sieve-error.c @@ -1,6 +1,6 @@ /* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #include "lib.h" #include "str.h" #include "array.h" @@ -62,7 +62,7 @@ void sieve_errors_init(struct sieve_instance *svinst) { svinst->system_ehandler = sieve_master_ehandler_create(svinst, NULL, 0); } - + void sieve_errors_deinit(struct sieve_instance *svinst) { sieve_error_handler_unref(&svinst->system_ehandler); @@ -73,7 +73,7 @@ void sieve_errors_deinit(struct sieve_instance *svinst) */ void sieve_direct_verror -(struct sieve_instance *svinst, struct sieve_error_handler *ehandler, +(struct sieve_instance *svinst, struct sieve_error_handler *ehandler, unsigned int flags, const char *location, const char *fmt, va_list args) { if ( (flags & SIEVE_ERROR_FLAG_GLOBAL) != 0 && @@ -81,7 +81,7 @@ void sieve_direct_verror svinst->system_ehandler != ehandler && svinst->system_ehandler->verror != NULL ) { va_list args_copy; - + VA_COPY(args_copy, args); svinst->system_ehandler->verror @@ -93,7 +93,7 @@ void sieve_direct_verror if ( ehandler->parent != NULL || sieve_errors_more_allowed(ehandler) ) { if ( ehandler->verror != NULL ) ehandler->verror(ehandler, flags, location, fmt, args); - + if ( ehandler->pool != NULL ) ehandler->errors++; } @@ -104,11 +104,11 @@ void sieve_direct_vwarning unsigned int flags, const char *location, const char *fmt, va_list args) { if ( (flags & SIEVE_ERROR_FLAG_GLOBAL) != 0 && - (ehandler == NULL || ehandler->parent == NULL) && + (ehandler == NULL || ehandler->parent == NULL) && svinst->system_ehandler != ehandler && svinst->system_ehandler->vwarning != NULL ) { va_list args_copy; - + VA_COPY(args_copy, args); svinst->system_ehandler->vwarning @@ -117,7 +117,7 @@ void sieve_direct_vwarning if ( ehandler == NULL ) return; - if ( ehandler->vwarning != NULL ) + if ( ehandler->vwarning != NULL ) ehandler->vwarning(ehandler, flags, location, fmt, args); if ( ehandler->pool != NULL ) @@ -133,7 +133,7 @@ void sieve_direct_vinfo svinst->system_ehandler != ehandler && svinst->system_ehandler->vinfo != NULL ) { va_list args_copy; - + VA_COPY(args_copy, args); svinst->system_ehandler->vinfo @@ -143,7 +143,7 @@ void sieve_direct_vinfo if ( ehandler == NULL ) return; if ( ehandler->parent != NULL || ehandler->log_info ) { - if ( ehandler->vinfo != NULL ) + if ( ehandler->vinfo != NULL ) ehandler->vinfo(ehandler, flags, location, fmt, args); } } @@ -178,7 +178,7 @@ void sieve_direct_vdebug void sieve_sys_verror (struct sieve_instance *svinst, const char *fmt, va_list args) -{ +{ T_BEGIN { sieve_direct_verror(svinst, svinst->system_ehandler, 0, NULL, fmt, args); } T_END; @@ -186,24 +186,24 @@ void sieve_sys_verror void sieve_sys_vwarning (struct sieve_instance *svinst, const char *fmt, va_list args) -{ - T_BEGIN { +{ + T_BEGIN { sieve_direct_vwarning(svinst, svinst->system_ehandler, 0, NULL, fmt, args); } T_END; } void sieve_sys_vinfo (struct sieve_instance *svinst, const char *fmt, va_list args) -{ - T_BEGIN { +{ + T_BEGIN { sieve_direct_vinfo(svinst, svinst->system_ehandler, 0, NULL, fmt, args); } T_END; } void sieve_sys_vdebug (struct sieve_instance *svinst, const char *fmt, va_list args) -{ - T_BEGIN { +{ + T_BEGIN { sieve_direct_vdebug(svinst, svinst->system_ehandler, 0, NULL, fmt, args); } T_END; } @@ -212,11 +212,11 @@ void sieve_sys_error(struct sieve_instance *svinst, const char *fmt, ...) { va_list args; va_start(args, fmt); - - T_BEGIN { + + T_BEGIN { sieve_direct_verror(svinst, svinst->system_ehandler, 0, NULL, fmt, args); } T_END; - + va_end(args); } @@ -224,11 +224,11 @@ void sieve_sys_warning(struct sieve_instance *svinst, const char *fmt, ...) { va_list args; va_start(args, fmt); - + T_BEGIN { sieve_direct_vwarning(svinst, svinst->system_ehandler, 0, NULL, fmt, args); } T_END; - + va_end(args); } @@ -236,11 +236,11 @@ void sieve_sys_info(struct sieve_instance *svinst, const char *fmt, ...) { va_list args; va_start(args, fmt); - + T_BEGIN { sieve_direct_vinfo(svinst, svinst->system_ehandler, 0, NULL, fmt, args); } T_END; - + va_end(args); } @@ -248,11 +248,11 @@ void sieve_sys_debug(struct sieve_instance *svinst, const char *fmt, ...) { va_list args; va_start(args, fmt); - + T_BEGIN { sieve_direct_vdebug(svinst, svinst->system_ehandler, 0, NULL, fmt, args); } T_END; - + va_end(args); } @@ -269,7 +269,7 @@ void sieve_system_ehandler_set struct sieve_error_handler *sieve_system_ehandler_get (struct sieve_instance *svinst) { - return svinst->system_ehandler; + return svinst->system_ehandler; } /* @@ -301,44 +301,44 @@ void sieve_global_vinfo } void sieve_global_error -(struct sieve_instance *svinst, struct sieve_error_handler *ehandler, +(struct sieve_instance *svinst, struct sieve_error_handler *ehandler, const char *location, const char *fmt, ...) { va_list args; va_start(args, fmt); - + T_BEGIN { - sieve_global_verror(svinst, ehandler, location, fmt, args); + sieve_global_verror(svinst, ehandler, location, fmt, args); } T_END; - + va_end(args); } void sieve_global_warning -(struct sieve_instance *svinst, struct sieve_error_handler *ehandler, +(struct sieve_instance *svinst, struct sieve_error_handler *ehandler, const char *location, const char *fmt, ...) { va_list args; va_start(args, fmt); - + T_BEGIN { - sieve_global_vwarning(svinst, ehandler, location, fmt, args); + sieve_global_vwarning(svinst, ehandler, location, fmt, args); } T_END; - + va_end(args); } void sieve_global_info -(struct sieve_instance *svinst, struct sieve_error_handler *ehandler, +(struct sieve_instance *svinst, struct sieve_error_handler *ehandler, const char *location, const char *fmt, ...) { va_list args; va_start(args, fmt); - + T_BEGIN { - sieve_global_vinfo(svinst, ehandler, location, fmt, args); + sieve_global_vinfo(svinst, ehandler, location, fmt, args); } T_END; - + va_end(args); } @@ -347,16 +347,16 @@ void sieve_global_info */ void sieve_verror -(struct sieve_error_handler *ehandler, const char *location, +(struct sieve_error_handler *ehandler, const char *location, const char *fmt, va_list args) -{ +{ if ( ehandler == NULL ) return; sieve_direct_verror(ehandler->svinst, ehandler, 0, location, fmt, args); } void sieve_vwarning -(struct sieve_error_handler *ehandler, const char *location, +(struct sieve_error_handler *ehandler, const char *location, const char *fmt, va_list args) { if ( ehandler == NULL ) return; @@ -365,7 +365,7 @@ void sieve_vwarning } void sieve_vinfo -(struct sieve_error_handler *ehandler, const char *location, +(struct sieve_error_handler *ehandler, const char *location, const char *fmt, va_list args) { if ( ehandler == NULL ) return; @@ -387,8 +387,8 @@ void sieve_vcritical const char *location, const char *user_prefix, const char *fmt, va_list args) { char str[256]; - struct tm *tm; - + struct tm *tm; + if ( location == NULL || *location == '\0' ) { sieve_direct_verror (svinst, svinst->system_ehandler, 0, NULL, fmt, args); @@ -400,63 +400,63 @@ void sieve_vcritical if ( ehandler == NULL || ehandler == svinst->system_ehandler ) return; tm = localtime(&ioloop_time); - + if ( user_prefix == NULL || *user_prefix == '\0' ) { - sieve_direct_error(svinst, ehandler, 0, location, "%s", - ( strftime(str, sizeof(str), CRITICAL_MSG_STAMP, tm) > 0 ? - str : CRITICAL_MSG )); - } else { - sieve_direct_error(svinst, ehandler, 0, location, "%s: %s", user_prefix, - ( strftime(str, sizeof(str), CRITICAL_MSG_STAMP, tm) > 0 ? + sieve_direct_error(svinst, ehandler, 0, location, "%s", + ( strftime(str, sizeof(str), CRITICAL_MSG_STAMP, tm) > 0 ? + str : CRITICAL_MSG )); + } else { + sieve_direct_error(svinst, ehandler, 0, location, "%s: %s", user_prefix, + ( strftime(str, sizeof(str), CRITICAL_MSG_STAMP, tm) > 0 ? str : CRITICAL_MSG )); - } + } } void sieve_error -(struct sieve_error_handler *ehandler, const char *location, +(struct sieve_error_handler *ehandler, const char *location, const char *fmt, ...) { va_list args; va_start(args, fmt); - + T_BEGIN { sieve_verror(ehandler, location, fmt, args); } T_END; - + va_end(args); } void sieve_warning -(struct sieve_error_handler *ehandler, const char *location, +(struct sieve_error_handler *ehandler, const char *location, const char *fmt, ...) { va_list args; va_start(args, fmt); - + T_BEGIN { sieve_vwarning(ehandler, location, fmt, args); } T_END; va_end(args); } void sieve_info -(struct sieve_error_handler *ehandler, const char *location, +(struct sieve_error_handler *ehandler, const char *location, const char *fmt, ...) { va_list args; va_start(args, fmt); - + T_BEGIN { sieve_vinfo(ehandler, location, fmt, args); } T_END; - + va_end(args); } void sieve_debug -(struct sieve_error_handler *ehandler, const char *location, +(struct sieve_error_handler *ehandler, const char *location, const char *fmt, ...) { va_list args; va_start(args, fmt); - + T_BEGIN { sieve_vdebug(ehandler, location, fmt, args); } T_END; - + va_end(args); } @@ -466,11 +466,11 @@ void sieve_critical { va_list args; va_start(args, fmt); - + T_BEGIN { sieve_vcritical(svinst, ehandler, location, user_prefix, fmt, args); } T_END; - + va_end(args); } @@ -478,23 +478,23 @@ void sieve_critical * Error statistics */ -unsigned int sieve_get_errors(struct sieve_error_handler *ehandler) +unsigned int sieve_get_errors(struct sieve_error_handler *ehandler) { if ( ehandler == NULL || ehandler->pool == NULL ) return 0; - + return ehandler->errors; } -unsigned int sieve_get_warnings(struct sieve_error_handler *ehandler) +unsigned int sieve_get_warnings(struct sieve_error_handler *ehandler) { if ( ehandler == NULL || ehandler->pool == NULL ) return 0; return ehandler->warnings; } -bool sieve_errors_more_allowed(struct sieve_error_handler *ehandler) +bool sieve_errors_more_allowed(struct sieve_error_handler *ehandler) { - if ( ehandler == NULL || ehandler->pool == NULL ) + if ( ehandler == NULL || ehandler->pool == NULL ) return TRUE; return ehandler->max_errors == 0 || ehandler->errors < ehandler->max_errors; @@ -569,7 +569,7 @@ void sieve_error_handler_unref(struct sieve_error_handler **ehandler) if (--(*ehandler)->refcount != 0) return; - if ( (*ehandler)->parent != NULL ) + if ( (*ehandler)->parent != NULL ) sieve_error_handler_unref(&(*ehandler)->parent); if ( (*ehandler)->free != NULL ) @@ -588,7 +588,7 @@ void sieve_error_handler_reset(struct sieve_error_handler *ehandler) ehandler->warnings = 0; } -/* +/* * Master/System error handler * * - Output errors directly to Dovecot master log @@ -604,7 +604,7 @@ typedef void (*master_log_func_t)(const char *fmt, ...) ATTR_FORMAT(1, 2); static void ATTR_FORMAT(4, 0) sieve_master_vlog (struct sieve_error_handler *_ehandler, master_log_func_t log_func, - const char *location, const char *fmt, va_list args) + const char *location, const char *fmt, va_list args) { struct sieve_master_ehandler *ehandler = (struct sieve_master_ehandler *) _ehandler; @@ -627,7 +627,7 @@ static void ATTR_FORMAT(4, 0) sieve_master_vlog static void ATTR_FORMAT(4, 0) sieve_master_verror (struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, const char *location, const char *fmt, - va_list args) + va_list args) { sieve_master_vlog(ehandler, i_error, location, fmt, args); } @@ -635,7 +635,7 @@ static void ATTR_FORMAT(4, 0) sieve_master_verror static void ATTR_FORMAT(4, 0) sieve_master_vwarning (struct sieve_error_handler *ehandler ATTR_UNUSED, unsigned int flags ATTR_UNUSED, const char *location, const char *fmt, - va_list args) + va_list args) { sieve_master_vlog(ehandler, i_warning, location, fmt, args); } @@ -643,7 +643,7 @@ static void ATTR_FORMAT(4, 0) sieve_master_vwarning static void ATTR_FORMAT(4, 0) sieve_master_vinfo (struct sieve_error_handler *ehandler ATTR_UNUSED, unsigned int flags ATTR_UNUSED, const char *location, const char *fmt, - va_list args) + va_list args) { sieve_master_vlog(ehandler, i_info, location, fmt, args); } @@ -651,13 +651,13 @@ static void ATTR_FORMAT(4, 0) sieve_master_vinfo static void ATTR_FORMAT(4, 0) sieve_master_vdebug (struct sieve_error_handler *ehandler ATTR_UNUSED, unsigned int flags ATTR_UNUSED, const char *location, const char *fmt, - va_list args) + va_list args) { sieve_master_vlog(ehandler, i_debug, location, fmt, args); } struct sieve_error_handler *sieve_master_ehandler_create -(struct sieve_instance *svinst, const char *prefix, unsigned int max_errors) +(struct sieve_instance *svinst, const char *prefix, unsigned int max_errors) { pool_t pool; struct sieve_master_ehandler *ehandler; @@ -679,15 +679,15 @@ struct sieve_error_handler *sieve_master_ehandler_create return &ehandler->handler; } -/* +/* * STDERR error handler * - * - Output errors directly to stderror + * - Output errors directly to stderror */ static void ATTR_FORMAT(4, 0) sieve_stderr_vmessage (struct sieve_error_handler *ehandler ATTR_UNUSED, const char *prefix, - const char *location, const char *fmt, va_list args) + const char *location, const char *fmt, va_list args) { if ( location == NULL || *location == '\0' ) fprintf(stderr, "%s: %s.\n", prefix, t_strdup_vprintf(fmt, args)); @@ -697,28 +697,28 @@ static void ATTR_FORMAT(4, 0) sieve_stderr_vmessage static void ATTR_FORMAT(4, 0) sieve_stderr_verror (struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, - const char *location, const char *fmt, va_list args) + const char *location, const char *fmt, va_list args) { sieve_stderr_vmessage(ehandler, "error", location, fmt, args); } static void ATTR_FORMAT(4, 0) sieve_stderr_vwarning -(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, - const char *location, const char *fmt, va_list args) +(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, + const char *location, const char *fmt, va_list args) { sieve_stderr_vmessage(ehandler, "warning", location, fmt, args); } static void ATTR_FORMAT(4, 0) sieve_stderr_vinfo -(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, - const char *location, const char *fmt, va_list args) +(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, + const char *location, const char *fmt, va_list args) { sieve_stderr_vmessage(ehandler, "info", location, fmt, args); } static void ATTR_FORMAT(4, 0) sieve_stderr_vdebug -(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, - const char *location, const char *fmt, va_list args) +(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, + const char *location, const char *fmt, va_list args) { sieve_stderr_vmessage(ehandler, "debug", location, fmt, args); } @@ -747,7 +747,7 @@ struct sieve_error_handler *sieve_stderr_ehandler_create /* String buffer error handler * - * - Output errors to a string buffer + * - Output errors to a string buffer */ struct sieve_strbuf_ehandler { @@ -758,7 +758,7 @@ struct sieve_strbuf_ehandler { }; static void ATTR_FORMAT(4, 0) sieve_strbuf_vmessage -(struct sieve_error_handler *ehandler, const char *prefix, +(struct sieve_error_handler *ehandler, const char *prefix, const char *location, const char *fmt, va_list args) { struct sieve_strbuf_ehandler *handler = @@ -776,28 +776,28 @@ static void ATTR_FORMAT(4, 0) sieve_strbuf_vmessage } static void ATTR_FORMAT(4, 0) sieve_strbuf_verror -(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, +(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, const char *location, const char *fmt, va_list args) { sieve_strbuf_vmessage(ehandler, "error", location, fmt, args); } static void ATTR_FORMAT(4, 0) sieve_strbuf_vwarning -(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, +(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, const char *location, const char *fmt, va_list args) { sieve_strbuf_vmessage(ehandler, "warning", location, fmt, args); } static void ATTR_FORMAT(4, 0) sieve_strbuf_vinfo -(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, +(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, const char *location, const char *fmt, va_list args) { sieve_strbuf_vmessage(ehandler, "info", location, fmt, args); } static void ATTR_FORMAT(4, 0) sieve_strbuf_vdebug -(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, +(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, const char *location, const char *fmt, va_list args) { sieve_strbuf_vmessage(ehandler, "debug", location, fmt, args); @@ -826,15 +826,15 @@ struct sieve_error_handler *sieve_strbuf_ehandler_create return &(ehandler->handler); } -/* +/* * Logfile error handler - * - * - Output errors to a log file + * + * - Output errors to a log file */ struct sieve_logfile_ehandler { struct sieve_error_handler handler; - + const char *logfile; bool started; int fd; @@ -842,27 +842,27 @@ struct sieve_logfile_ehandler { }; static void ATTR_FORMAT(4, 0) sieve_logfile_vprintf -(struct sieve_logfile_ehandler *ehandler, const char *location, - const char *prefix, const char *fmt, va_list args) +(struct sieve_logfile_ehandler *ehandler, const char *location, + const char *prefix, const char *fmt, va_list args) { string_t *outbuf; ssize_t ret = 0, remain; const char *data; - + if ( ehandler->stream == NULL ) return; - + T_BEGIN { outbuf = t_str_new(256); if ( location != NULL && *location != '\0' ) str_printfa(outbuf, "%s: ", location); - str_printfa(outbuf, "%s: ", prefix); + str_printfa(outbuf, "%s: ", prefix); str_vprintfa(outbuf, fmt, args); str_append(outbuf, ".\n"); - + remain = str_len(outbuf); data = (const char *) str_data(outbuf); - while ( remain > 0 ) { + while ( remain > 0 ) { if ( (ret=o_stream_send(ehandler->stream, data, remain)) < 0 ) break; @@ -873,19 +873,19 @@ static void ATTR_FORMAT(4, 0) sieve_logfile_vprintf if ( ret < 0 ) { sieve_sys_error(ehandler->handler.svinst, - "o_stream_send() failed on logfile %s: %m", ehandler->logfile); + "o_stream_send() failed on logfile %s: %m", ehandler->logfile); } } inline static void ATTR_FORMAT(4, 5) sieve_logfile_printf (struct sieve_logfile_ehandler *ehandler, const char *location, - const char *prefix, const char *fmt, ...) + const char *prefix, const char *fmt, ...) { va_list args; va_start(args, fmt); - + sieve_logfile_vprintf(ehandler, location, prefix, fmt, args); - + va_end(args); } @@ -918,7 +918,7 @@ static void sieve_logfile_start(struct sieve_logfile_ehandler *ehandler) if ( fstat(fd, &st) != 0 ) { sieve_sys_error(svinst, "failed to stat logfile (logging to STDERR): " "fstat(fd=%s) failed: %m", ehandler->logfile); - + if ( close(fd) < 0 ) { sieve_sys_error(svinst, "failed to close logfile after error: " "close(fd=%s) failed: %m", ehandler->logfile); @@ -926,25 +926,25 @@ static void sieve_logfile_start(struct sieve_logfile_ehandler *ehandler) fd = STDERR_FILENO; } - + /* Rotate log when it has grown too large */ if ( st.st_size >= LOGFILE_MAX_SIZE ) { const char *rotated; - + /* Close open file */ if ( close(fd) < 0 ) { - sieve_sys_error(svinst, + sieve_sys_error(svinst, "failed to close logfile: close(fd=%s) failed: %m", ehandler->logfile); } - + /* Rotate logfile */ rotated = t_strconcat(ehandler->logfile, ".0", NULL); if ( rename(ehandler->logfile, rotated) < 0 ) { sieve_sys_error(svinst, - "failed to rotate logfile: rename(%s, %s) failed: %m", + "failed to rotate logfile: rename(%s, %s) failed: %m", ehandler->logfile, rotated); } - + /* Open clean logfile (overwrites existing if rename() failed earlier) */ fd = open(ehandler->logfile, O_CREAT | O_WRONLY | O_TRUNC, 0600); if (fd == -1) { @@ -954,7 +954,7 @@ static void sieve_logfile_start(struct sieve_logfile_ehandler *ehandler) eacces_error_get_creating("open", ehandler->logfile)); } else { sieve_sys_error(svinst, - "failed to open logfile (LOGGING TO STDERR): open(%s) failed: %m", + "failed to open logfile (LOGGING TO STDERR): open(%s) failed: %m", ehandler->logfile); } fd = STDERR_FILENO; @@ -968,14 +968,14 @@ static void sieve_logfile_start(struct sieve_logfile_ehandler *ehandler) sieve_sys_error(svinst, "failed to open log stream on open file: " "o_stream_create_fd(fd=%s) failed " "(non-critical messages are not logged!)", ehandler->logfile); - } + } ehandler->fd = fd; ehandler->stream = ostream; ehandler->started = TRUE; - + if ( ostream != NULL ) { - now = time(NULL); + now = time(NULL); tm = localtime(&now); if (strftime(buf, sizeof(buf), "%b %d %H:%M:%S", tm) > 0) { @@ -986,43 +986,43 @@ static void sieve_logfile_start(struct sieve_logfile_ehandler *ehandler) } static void ATTR_FORMAT(4, 0) sieve_logfile_verror -(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, - const char *location, const char *fmt, va_list args) +(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, + const char *location, const char *fmt, va_list args) { - struct sieve_logfile_ehandler *handler = + struct sieve_logfile_ehandler *handler = (struct sieve_logfile_ehandler *) ehandler; - if ( !handler->started ) sieve_logfile_start(handler); + if ( !handler->started ) sieve_logfile_start(handler); sieve_logfile_vprintf(handler, location, "error", fmt, args); } static void ATTR_FORMAT(4, 0) sieve_logfile_vwarning -(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, - const char *location, const char *fmt, va_list args) +(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, + const char *location, const char *fmt, va_list args) { - struct sieve_logfile_ehandler *handler = + struct sieve_logfile_ehandler *handler = (struct sieve_logfile_ehandler *) ehandler; - if ( !handler->started ) sieve_logfile_start(handler); + if ( !handler->started ) sieve_logfile_start(handler); sieve_logfile_vprintf(handler, location, "warning", fmt, args); } static void ATTR_FORMAT(4, 0) sieve_logfile_vinfo -(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, - const char *location, const char *fmt, va_list args) +(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, + const char *location, const char *fmt, va_list args) { - struct sieve_logfile_ehandler *handler = + struct sieve_logfile_ehandler *handler = (struct sieve_logfile_ehandler *) ehandler; - if ( !handler->started ) sieve_logfile_start(handler); + if ( !handler->started ) sieve_logfile_start(handler); sieve_logfile_vprintf(handler, location, "info", fmt, args); } static void ATTR_FORMAT(4, 0) sieve_logfile_vdebug -(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, +(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, const char *location, const char *fmt, va_list args) { struct sieve_logfile_ehandler *handler = @@ -1036,9 +1036,9 @@ static void ATTR_FORMAT(4, 0) sieve_logfile_vdebug static void sieve_logfile_free (struct sieve_error_handler *ehandler) { - struct sieve_logfile_ehandler *handler = + struct sieve_logfile_ehandler *handler = (struct sieve_logfile_ehandler *) ehandler; - + if ( handler->stream != NULL ) { o_stream_destroy(&(handler->stream)); if ( handler->fd != STDERR_FILENO ){ @@ -1078,7 +1078,7 @@ struct sieve_error_handler *sieve_logfile_ehandler_create } /* - * Prefix error handler + * Prefix error handler * * Encapsulates an existing error handler and prefixes all messages with * the given prefix. @@ -1110,46 +1110,46 @@ static const char *ATTR_FORMAT(3, 0) _prefix_message static void ATTR_FORMAT(4, 0) sieve_prefix_verror (struct sieve_error_handler *_ehandler, unsigned int flags, - const char *location, const char *fmt, va_list args) -{ + const char *location, const char *fmt, va_list args) +{ struct sieve_prefix_ehandler *ehandler = (struct sieve_prefix_ehandler *) _ehandler; sieve_direct_error(_ehandler->svinst, _ehandler->parent, flags, - ehandler->location, "%s", _prefix_message(ehandler, location, fmt, args)); + ehandler->location, "%s", _prefix_message(ehandler, location, fmt, args)); } static void ATTR_FORMAT(4, 0) sieve_prefix_vwarning -(struct sieve_error_handler *_ehandler, unsigned int flags, - const char *location, const char *fmt, va_list args) +(struct sieve_error_handler *_ehandler, unsigned int flags, + const char *location, const char *fmt, va_list args) { struct sieve_prefix_ehandler *ehandler = (struct sieve_prefix_ehandler *) _ehandler; sieve_direct_warning(_ehandler->svinst, _ehandler->parent, flags, - ehandler->location, "%s", _prefix_message(ehandler, location, fmt, args)); + ehandler->location, "%s", _prefix_message(ehandler, location, fmt, args)); } static void ATTR_FORMAT(4, 0) sieve_prefix_vinfo (struct sieve_error_handler *_ehandler, unsigned int flags, - const char *location, const char *fmt, va_list args) + const char *location, const char *fmt, va_list args) { struct sieve_prefix_ehandler *ehandler = (struct sieve_prefix_ehandler *) _ehandler; sieve_direct_info(_ehandler->svinst, _ehandler->parent, flags, - ehandler->location, "%s", _prefix_message(ehandler, location, fmt, args)); + ehandler->location, "%s", _prefix_message(ehandler, location, fmt, args)); } static void ATTR_FORMAT(4, 0) sieve_prefix_vdebug -(struct sieve_error_handler *_ehandler, unsigned int flags, - const char *location, const char *fmt, va_list args) +(struct sieve_error_handler *_ehandler, unsigned int flags, + const char *location, const char *fmt, va_list args) { struct sieve_prefix_ehandler *ehandler = (struct sieve_prefix_ehandler *) _ehandler; - sieve_direct_debug(_ehandler->svinst, _ehandler->parent, flags, - ehandler->location, "%s", _prefix_message(ehandler, location, fmt, args)); + sieve_direct_debug(_ehandler->svinst, _ehandler->parent, flags, + ehandler->location, "%s", _prefix_message(ehandler, location, fmt, args)); } struct sieve_error_handler *sieve_prefix_ehandler_create @@ -1161,7 +1161,7 @@ struct sieve_error_handler *sieve_prefix_ehandler_create if ( parent == NULL ) return NULL; - pool = pool_alloconly_create("sieve_prefix_error_handler", 256); + pool = pool_alloconly_create("sieve_prefix_error_handler", 256); ehandler = p_new(pool, struct sieve_prefix_ehandler, 1); sieve_error_handler_init_from_parent(&ehandler->handler, pool, parent); @@ -1177,7 +1177,7 @@ struct sieve_error_handler *sieve_prefix_ehandler_create } /* - * Varexpand error handler + * Varexpand error handler * * Encapsulates an existing error handler and formats all messages using the * provided format string and variables; @@ -1192,7 +1192,7 @@ struct sieve_varexpand_ehandler { static const char *ATTR_FORMAT(3, 0) _expand_message (struct sieve_error_handler *_ehandler, - const char *location, const char *fmt, va_list args) + const char *location, const char *fmt, va_list args) { struct sieve_varexpand_ehandler *ehandler = (struct sieve_varexpand_ehandler *) _ehandler; @@ -1213,34 +1213,34 @@ static const char *ATTR_FORMAT(3, 0) _expand_message static void ATTR_FORMAT(4, 0) sieve_varexpand_verror (struct sieve_error_handler *ehandler, unsigned int flags, - const char *location, const char *fmt, va_list args) -{ + const char *location, const char *fmt, va_list args) +{ sieve_direct_error(ehandler->svinst, ehandler->parent, flags, location, - "%s", _expand_message(ehandler, location, fmt, args)); + "%s", _expand_message(ehandler, location, fmt, args)); } static void ATTR_FORMAT(4, 0) sieve_varexpand_vwarning (struct sieve_error_handler *ehandler, unsigned int flags, - const char *location, const char *fmt, va_list args) + const char *location, const char *fmt, va_list args) { - sieve_direct_warning(ehandler->svinst, ehandler->parent, flags, location, - "%s", _expand_message(ehandler, location, fmt, args)); + sieve_direct_warning(ehandler->svinst, ehandler->parent, flags, location, + "%s", _expand_message(ehandler, location, fmt, args)); } static void ATTR_FORMAT(4, 0) sieve_varexpand_vinfo (struct sieve_error_handler *ehandler, unsigned int flags, - const char *location, const char *fmt, va_list args) + const char *location, const char *fmt, va_list args) { sieve_direct_info(ehandler->svinst, ehandler->parent, flags, location, - "%s", _expand_message(ehandler, location, fmt, args)); + "%s", _expand_message(ehandler, location, fmt, args)); } static void ATTR_FORMAT(4, 0) sieve_varexpand_vdebug (struct sieve_error_handler *ehandler, unsigned int flags, - const char *location, const char *fmt, va_list args) + const char *location, const char *fmt, va_list args) { sieve_direct_debug(ehandler->svinst, ehandler->parent, flags, location, - "%s", _expand_message(ehandler, location, fmt, args)); + "%s", _expand_message(ehandler, location, fmt, args)); } struct sieve_error_handler *sieve_varexpand_ehandler_create diff --git a/src/lib-sieve/sieve-error.h b/src/lib-sieve/sieve-error.h index 22af608a207e1ccaf0aeab768ad43a3eac1e72a7..cafd9347ce6ec0d637039f132267a9baeab33bce 100644 --- a/src/lib-sieve/sieve-error.h +++ b/src/lib-sieve/sieve-error.h @@ -24,10 +24,10 @@ struct sieve_error_handler; */ typedef void (*sieve_error_vfunc_t) - (struct sieve_error_handler *ehandler, const char *location, + (struct sieve_error_handler *ehandler, const char *location, const char *fmt, va_list args); typedef void (*sieve_error_func_t) - (struct sieve_error_handler *ehandler, const char *location, + (struct sieve_error_handler *ehandler, const char *location, const char *fmt, ...) ATTR_FORMAT(3, 4); /* @@ -93,14 +93,14 @@ const char *sieve_error_script_location (const struct sieve_script *script, unsigned int source_line); void sieve_verror - (struct sieve_error_handler *ehandler, const char *location, + (struct sieve_error_handler *ehandler, const char *location, const char *fmt, va_list args); void sieve_vwarning - (struct sieve_error_handler *ehandler, const char *location, - const char *fmt, va_list args); + (struct sieve_error_handler *ehandler, const char *location, + const char *fmt, va_list args); void sieve_vinfo - (struct sieve_error_handler *ehandler, const char *location, - const char *fmt, va_list args); + (struct sieve_error_handler *ehandler, const char *location, + const char *fmt, va_list args); void sieve_vdebug (struct sieve_error_handler *ehandler, const char *location, const char *fmt, va_list args); @@ -110,13 +110,13 @@ void sieve_vcritical va_list args); void sieve_error - (struct sieve_error_handler *ehandler, const char *location, + (struct sieve_error_handler *ehandler, const char *location, const char *fmt, ...) ATTR_FORMAT(3, 4); void sieve_warning - (struct sieve_error_handler *ehandler, const char *location, + (struct sieve_error_handler *ehandler, const char *location, const char *fmt, ...) ATTR_FORMAT(3, 4); void sieve_info - (struct sieve_error_handler *ehandler, const char *location, + (struct sieve_error_handler *ehandler, const char *location, const char *fmt, ...) ATTR_FORMAT(3, 4); void sieve_debug (struct sieve_error_handler *ehandler, const char *location, @@ -153,8 +153,8 @@ void sieve_error_handler_unref(struct sieve_error_handler **ehandler); void sieve_error_handler_reset(struct sieve_error_handler *ehandler); -/* - * Error handlers +/* + * Error handlers */ /* Write errors to dovecot master log */ @@ -172,11 +172,11 @@ struct sieve_error_handler *sieve_strbuf_ehandler_create /* Write errors to a logfile */ struct sieve_error_handler *sieve_logfile_ehandler_create - (struct sieve_instance *svinst, const char *logfile, unsigned int max_errors); + (struct sieve_instance *svinst, const char *logfile, unsigned int max_errors); /* Wrapper: prefix all log messages */ struct sieve_error_handler *sieve_prefix_ehandler_create - (struct sieve_error_handler *parent, const char *location, + (struct sieve_error_handler *parent, const char *location, const char *prefix); /* Wrapper: make messages part of var expansion */ diff --git a/src/lib-sieve/sieve-extensions.c b/src/lib-sieve/sieve-extensions.c index fd5a24f1bf87445008e0e0b02b2f92458feb400c..e0e816f6eb2397a39409c29c79122743306a9482 100644 --- a/src/lib-sieve/sieve-extensions.c +++ b/src/lib-sieve/sieve-extensions.c @@ -13,7 +13,7 @@ #include "sieve-extensions.h" /* - * Forward declarations + * Forward declarations */ static void sieve_extension_registry_init(struct sieve_instance *svinst); @@ -23,7 +23,7 @@ static void sieve_capability_registry_init(struct sieve_instance *svinst); static void sieve_capability_registry_deinit(struct sieve_instance *svinst); static struct sieve_extension *_sieve_extension_register - (struct sieve_instance *svinst, const struct sieve_extension_def *extdef, + (struct sieve_instance *svinst, const struct sieve_extension_def *extdef, bool load, bool required); /* @@ -31,8 +31,8 @@ static struct sieve_extension *_sieve_extension_register */ struct sieve_extension_registry { - ARRAY_DEFINE(extensions, struct sieve_extension *); - struct hash_table *extension_index; + ARRAY_DEFINE(extensions, struct sieve_extension *); + struct hash_table *extension_index; struct hash_table *capabilities_index; /* Core language 'extensions' */ @@ -44,36 +44,36 @@ struct sieve_extension_registry { ARRAY_DEFINE(preloaded_extensions, const struct sieve_extension *); }; -/* - * Pre-loaded 'extensions' +/* + * Pre-loaded 'extensions' */ extern const struct sieve_extension_def comparator_extension; extern const struct sieve_extension_def match_type_extension; extern const struct sieve_extension_def address_part_extension; -/* - * Dummy extensions +/* + * Dummy extensions */ - + /* FIXME: This is stupid. Define a comparator-* extension and be done with it */ static const struct sieve_extension_def comparator_i_octet_extension = { - "comparator-i;octet", - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - SIEVE_EXT_DEFINE_NO_OPERATIONS, + "comparator-i;octet", + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + SIEVE_EXT_DEFINE_NO_OPERATIONS, SIEVE_EXT_DEFINE_NO_OPERANDS }; static const struct sieve_extension_def comparator_i_ascii_casemap_extension = { - "comparator-i;ascii-casemap", + "comparator-i;ascii-casemap", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - SIEVE_EXT_DEFINE_NO_OPERATIONS, + SIEVE_EXT_DEFINE_NO_OPERATIONS, SIEVE_EXT_DEFINE_NO_OPERANDS }; -/* - * Core extensions +/* + * Core extensions */ extern const struct sieve_extension_def fileinto_extension; @@ -81,8 +81,8 @@ extern const struct sieve_extension_def reject_extension; extern const struct sieve_extension_def envelope_extension; extern const struct sieve_extension_def encoded_character_extension; -/* - * Native 'plugin' extensions +/* + * Native 'plugin' extensions */ extern const struct sieve_extension_def vacation_extension; @@ -114,8 +114,8 @@ extern const struct sieve_extension_def duplicate_extension; * List of native extensions */ -const struct sieve_extension_def *sieve_dummy_extensions[] = { - /* Dummy extensions */ +const struct sieve_extension_def *sieve_dummy_extensions[] = { + /* Dummy extensions */ &comparator_i_octet_extension, &comparator_i_ascii_casemap_extension }; @@ -189,14 +189,14 @@ const unsigned int sieve_unfinished_extensions_count = #endif /* HAVE_SIEVE_UNFINISHED */ -/* +/* * Extensions init/deinit */ -bool sieve_extensions_init(struct sieve_instance *svinst) +bool sieve_extensions_init(struct sieve_instance *svinst) { - unsigned int i; - struct sieve_extension_registry *ext_reg = + unsigned int i; + struct sieve_extension_registry *ext_reg = p_new(svinst->pool, struct sieve_extension_registry, 1); struct sieve_extension *ext; @@ -206,19 +206,19 @@ bool sieve_extensions_init(struct sieve_instance *svinst) sieve_capability_registry_init(svinst); /* Preloaded 'extensions' */ - ext_reg->comparator_extension = + ext_reg->comparator_extension = sieve_extension_register(svinst, &comparator_extension, TRUE); - ext_reg->match_type_extension = + ext_reg->match_type_extension = sieve_extension_register(svinst, &match_type_extension, TRUE); - ext_reg->address_part_extension = + ext_reg->address_part_extension = sieve_extension_register(svinst, &address_part_extension, TRUE); - + p_array_init(&ext_reg->preloaded_extensions, svinst->pool, 5); - array_append(&ext_reg->preloaded_extensions, + array_append(&ext_reg->preloaded_extensions, &ext_reg->comparator_extension, 1); - array_append(&ext_reg->preloaded_extensions, + array_append(&ext_reg->preloaded_extensions, &ext_reg->match_type_extension, 1); - array_append(&ext_reg->preloaded_extensions, + array_append(&ext_reg->preloaded_extensions, &ext_reg->address_part_extension, 1); /* Pre-load dummy extensions */ @@ -226,7 +226,7 @@ bool sieve_extensions_init(struct sieve_instance *svinst) if ( (ext=_sieve_extension_register (svinst, sieve_dummy_extensions[i], TRUE, FALSE)) == NULL ) return FALSE; - + ext->dummy = TRUE; } @@ -281,7 +281,7 @@ void sieve_extensions_configure(struct sieve_instance *svinst) } void sieve_extensions_deinit(struct sieve_instance *svinst) -{ +{ sieve_extension_registry_deinit(svinst); sieve_capability_registry_deinit(svinst); } @@ -298,14 +298,14 @@ const struct sieve_extension *const *sieve_extensions_get_preloaded return array_get(&ext_reg->preloaded_extensions, count_r); } -/* +/* * Extension registry */ static bool _sieve_extension_load(struct sieve_extension *ext) { /* Call load handler */ - if ( ext->def != NULL && ext->def->load != NULL && + if ( ext->def != NULL && ext->def->load != NULL && !ext->def->load(ext, &ext->context) ) { sieve_sys_error(ext->svinst, "failed to load '%s' extension support.", ext->def->name); @@ -323,7 +323,7 @@ static void _sieve_extension_unload(struct sieve_extension *ext) } static void sieve_extension_registry_init(struct sieve_instance *svinst) -{ +{ struct sieve_extension_registry *ext_reg = svinst->ext_reg; p_array_init(&ext_reg->extensions, svinst->pool, 50); @@ -331,12 +331,12 @@ static void sieve_extension_registry_init(struct sieve_instance *svinst) (default_pool, default_pool, 0, str_hash, (hash_cmp_callback_t *)strcmp); } -static void sieve_extension_registry_deinit(struct sieve_instance *svinst) +static void sieve_extension_registry_deinit(struct sieve_instance *svinst) { struct sieve_extension_registry *ext_reg = svinst->ext_reg; struct sieve_extension * const *exts; unsigned int i, ext_count; - + if ( ext_reg->extension_index == NULL ) return; exts = array_get_modifiable(&ext_reg->extensions, &ext_count); @@ -352,7 +352,7 @@ bool sieve_extension_reload(const struct sieve_extension *ext) struct sieve_extension_registry *ext_reg = ext->svinst->ext_reg; struct sieve_extension * const *mod_ext; int ext_id = ext->id; - + /* Let's not just cast the 'const' away */ if ( ext_id >= 0 && ext_id < (int) array_count(&ext_reg->extensions) ) { mod_ext = array_idx(&ext_reg->extensions, ext_id); @@ -368,7 +368,7 @@ static struct sieve_extension *_sieve_extension_register bool load, bool required) { struct sieve_extension_registry *ext_reg = svinst->ext_reg; - struct sieve_extension *ext = (struct sieve_extension *) + struct sieve_extension *ext = (struct sieve_extension *) hash_table_lookup(ext_reg->extension_index, extdef->name); /* Register extension if it is not registered already */ @@ -452,7 +452,7 @@ int sieve_extensions_get_count(struct sieve_instance *svinst) } const struct sieve_extension *sieve_extension_get_by_id -(struct sieve_instance *svinst, unsigned int ext_id) +(struct sieve_instance *svinst, unsigned int ext_id) { struct sieve_extension_registry *ext_reg = svinst->ext_reg; struct sieve_extension * const *ext; @@ -468,7 +468,7 @@ const struct sieve_extension *sieve_extension_get_by_id } const struct sieve_extension *sieve_extension_get_by_name -(struct sieve_instance *svinst, const char *name) +(struct sieve_instance *svinst, const char *name) { struct sieve_extension_registry *ext_reg = svinst->ext_reg; const struct sieve_extension *ext; @@ -584,7 +584,7 @@ void sieve_extensions_set_string for ( i = 0; i < ext_count; i++ ) sieve_extension_set_enabled(exts[i], TRUE); - return; + return; } T_BEGIN { @@ -611,7 +611,7 @@ void sieve_extensions_set_string if ( *name == '@' ) ext = NULL; else - ext = (const struct sieve_extension *) + ext = (const struct sieve_extension *) hash_table_lookup(ext_reg->extension_index, name); if ( ext == NULL || ext->def == NULL ) { @@ -644,15 +644,15 @@ void sieve_extensions_set_string } /* If extensions are specified relative to the default set, - * we first need to check which ones are disabled + * we first need to check which ones are disabled */ if ( relative ) { if ( global ) enabled = exts[i]->global; else - enabled = exts[i]->enabled; - + enabled = exts[i]->enabled; + if ( enabled ) { /* Disable if explicitly disabled */ for ( j = 0; j < dis_count; j++ ) { @@ -662,7 +662,7 @@ void sieve_extensions_set_string } } } - } + } /* Enable if listed with '+' or no prefix */ @@ -711,19 +711,19 @@ void sieve_enable_debug_extension(struct sieve_instance *svinst) */ struct sieve_capability_registration { - const struct sieve_extension *ext; + const struct sieve_extension *ext; const struct sieve_extension_capabilities *capabilities; }; void sieve_capability_registry_init(struct sieve_instance *svinst) -{ +{ struct sieve_extension_registry *ext_reg = svinst->ext_reg; ext_reg->capabilities_index = hash_table_create (default_pool, default_pool, 0, str_hash, (hash_cmp_callback_t *)strcmp); } -void sieve_capability_registry_deinit(struct sieve_instance *svinst) +void sieve_capability_registry_deinit(struct sieve_instance *svinst) { struct sieve_extension_registry *ext_reg = svinst->ext_reg; @@ -733,12 +733,12 @@ void sieve_capability_registry_deinit(struct sieve_instance *svinst) } void sieve_extension_capabilities_register -(const struct sieve_extension *ext, - const struct sieve_extension_capabilities *cap) -{ +(const struct sieve_extension *ext, + const struct sieve_extension_capabilities *cap) +{ struct sieve_instance *svinst = ext->svinst; struct sieve_extension_registry *ext_reg = svinst->ext_reg; - struct sieve_capability_registration *reg = + struct sieve_capability_registration *reg = p_new(svinst->pool, struct sieve_capability_registration, 1); reg->ext = ext; @@ -749,7 +749,7 @@ void sieve_extension_capabilities_register } void sieve_extension_capabilities_unregister -(const struct sieve_extension *ext) +(const struct sieve_extension *ext) { struct sieve_extension_registry *ext_reg = ext->svinst->ext_reg; struct hash_iterate_context *hictx; @@ -757,21 +757,21 @@ void sieve_extension_capabilities_unregister hictx = hash_table_iterate_init(ext_reg->capabilities_index); while ( hash_table_iterate(hictx, &key, &value) ) { - struct sieve_capability_registration *reg = + struct sieve_capability_registration *reg = (struct sieve_capability_registration *) value; if ( reg->ext == ext ) - hash_table_remove(ext_reg->capabilities_index, key); + hash_table_remove(ext_reg->capabilities_index, key); } hash_table_iterate_deinit(&hictx); } const char *sieve_extension_capabilities_get_string -(struct sieve_instance *svinst, const char *cap_name) +(struct sieve_instance *svinst, const char *cap_name) { struct sieve_extension_registry *ext_reg = svinst->ext_reg; - const struct sieve_capability_registration *cap_reg = - (const struct sieve_capability_registration *) + const struct sieve_capability_registration *cap_reg = + (const struct sieve_capability_registration *) hash_table_lookup(ext_reg->capabilities_index, cap_name); const struct sieve_extension_capabilities *cap; @@ -782,7 +782,7 @@ const char *sieve_extension_capabilities_get_string if ( cap->get_string == NULL || !cap_reg->ext->enabled ) return NULL; - + return cap->get_string(cap_reg->ext); } diff --git a/src/lib-sieve/sieve-extensions.h b/src/lib-sieve/sieve-extensions.h index 479feea8f24add4b605c5d0f7a4b6b816f6c3add..6e976bebdf8f2aa316a029367da94bd571dc8daf 100644 --- a/src/lib-sieve/sieve-extensions.h +++ b/src/lib-sieve/sieve-extensions.h @@ -7,8 +7,8 @@ #include "lib.h" #include "sieve-common.h" -/* - * Per-extension object registry +/* + * Per-extension object registry */ struct sieve_extension_objects { @@ -16,33 +16,33 @@ struct sieve_extension_objects { unsigned int count; }; -/* +/* * Extension definition */ struct sieve_extension_def { const char *name; - /* Registration */ + /* Registration */ bool (*load)(const struct sieve_extension *ext, void **context); void (*unload)(const struct sieve_extension *ext); /* Compilation */ bool (*validator_load) - (const struct sieve_extension *ext, struct sieve_validator *validator); + (const struct sieve_extension *ext, struct sieve_validator *validator); bool (*generator_load) (const struct sieve_extension *ext, const struct sieve_codegen_env *cgenv); bool (*interpreter_load) - (const struct sieve_extension *ext, const struct sieve_runtime_env *renv, + (const struct sieve_extension *ext, const struct sieve_runtime_env *renv, sieve_size_t *address); bool (*binary_load) (const struct sieve_extension *ext, struct sieve_binary *binary); - + /* Code dump */ bool (*binary_dump) (const struct sieve_extension *ext, struct sieve_dumptime_env *denv); bool (*code_dump) - (const struct sieve_extension *ext, const struct sieve_dumptime_env *denv, + (const struct sieve_extension *ext, const struct sieve_dumptime_env *denv, sieve_size_t *address); /* Objects */ @@ -69,7 +69,7 @@ struct sieve_extension { int id; struct sieve_instance *svinst; - void *context; + void *context; unsigned int required:1; unsigned int loaded:1; @@ -85,8 +85,8 @@ struct sieve_extension { #define sieve_extension_name_is(ext, _name) \ ( strcmp((ext)->def->name, (_name)) == 0 ) -/* - * Defining opcodes and operands +/* + * Defining opcodes and operands */ #define SIEVE_EXT_DEFINE_NO_OPERATIONS SIEVE_EXT_DEFINE_NO_OBJECTS @@ -97,30 +97,30 @@ struct sieve_extension { #define SIEVE_EXT_DEFINE_OPERAND(OP) SIEVE_EXT_DEFINE_OBJECT(OP) #define SIEVE_EXT_DEFINE_OPERANDS(OPS) SIEVE_EXT_DEFINE_OBJECTS(OPS) -/* - * Extensions init/deinit +/* + * Extensions init/deinit */ bool sieve_extensions_init(struct sieve_instance *svinst); void sieve_extensions_configure(struct sieve_instance *svinst); void sieve_extensions_deinit(struct sieve_instance *svinst); -/* - * Pre-loaded extensions +/* + * Pre-loaded extensions */ const struct sieve_extension *const *sieve_extensions_get_preloaded (struct sieve_instance *svinst, unsigned int *count_r); -/* - * Extension registry +/* + * Extension registry */ const struct sieve_extension *sieve_extension_register - (struct sieve_instance *svinst, const struct sieve_extension_def *extension, + (struct sieve_instance *svinst, const struct sieve_extension_def *extension, bool load); const struct sieve_extension *sieve_extension_require - (struct sieve_instance *svinst, const struct sieve_extension_def *extension, + (struct sieve_instance *svinst, const struct sieve_extension_def *extension, bool load); bool sieve_extension_reload(const struct sieve_extension *ext); @@ -154,11 +154,11 @@ void sieve_enable_debug_extension(struct sieve_instance *svinst); struct sieve_extension_capabilities { const char *name; - const char *(*get_string)(const struct sieve_extension *ext); + const char *(*get_string)(const struct sieve_extension *ext); }; void sieve_extension_capabilities_register - (const struct sieve_extension *ext, + (const struct sieve_extension *ext, const struct sieve_extension_capabilities *cap); void sieve_extension_capabilities_unregister (const struct sieve_extension *ext); diff --git a/src/lib-sieve/sieve-generator.c b/src/lib-sieve/sieve-generator.c index ae51a8880164873437f6de606837fb70fafe429b..b1f68f2237ee739e3c259e878217842d85489471 100644 --- a/src/lib-sieve/sieve-generator.c +++ b/src/lib-sieve/sieve-generator.c @@ -13,19 +13,19 @@ #include "sieve-generator.h" -/* - * Jump list +/* + * Jump list */ struct sieve_jumplist *sieve_jumplist_create (pool_t pool, struct sieve_binary_block *sblock) { struct sieve_jumplist *jlist; - + jlist = p_new(pool, struct sieve_jumplist, 1); jlist->block = sblock; p_array_init(&jlist->jumps, pool, 4); - + return jlist; } @@ -42,58 +42,58 @@ void sieve_jumplist_reset array_clear(&jlist->jumps); } -void sieve_jumplist_add(struct sieve_jumplist *jlist, sieve_size_t jump) +void sieve_jumplist_add(struct sieve_jumplist *jlist, sieve_size_t jump) { array_append(&jlist->jumps, &jump, 1); } -void sieve_jumplist_resolve(struct sieve_jumplist *jlist) +void sieve_jumplist_resolve(struct sieve_jumplist *jlist) { unsigned int i; - + for ( i = 0; i < array_count(&jlist->jumps); i++ ) { const sieve_size_t *jump = array_idx(&jlist->jumps, i); - + sieve_binary_resolve_offset(jlist->block, *jump); } } -/* - * Code Generator +/* + * Code Generator */ struct sieve_generator { pool_t pool; struct sieve_instance *instance; - + struct sieve_error_handler *ehandler; struct sieve_codegen_env genenv; struct sieve_binary_debug_writer *dwriter; - + ARRAY_DEFINE(ext_contexts, void *); }; struct sieve_generator *sieve_generator_create (struct sieve_ast *ast, struct sieve_error_handler *ehandler, - enum sieve_compile_flags flags) + enum sieve_compile_flags flags) { pool_t pool; struct sieve_generator *gentr; struct sieve_script *script; struct sieve_instance *svinst; - - pool = pool_alloconly_create("sieve_generator", 4096); + + pool = pool_alloconly_create("sieve_generator", 4096); gentr = p_new(pool, struct sieve_generator, 1); gentr->pool = pool; gentr->ehandler = ehandler; sieve_error_handler_ref(ehandler); - + gentr->genenv.gentr = gentr; gentr->genenv.flags = flags; - gentr->genenv.ast = ast; + gentr->genenv.ast = ast; sieve_ast_ref(ast); script = sieve_ast_script(ast); @@ -102,16 +102,16 @@ struct sieve_generator *sieve_generator_create gentr->genenv.script = script; gentr->genenv.svinst = svinst; - /* Setup storage for extension contexts */ + /* Setup storage for extension contexts */ p_array_init(&gentr->ext_contexts, pool, sieve_extensions_get_count(svinst)); - + return gentr; } -void sieve_generator_free(struct sieve_generator **gentr) +void sieve_generator_free(struct sieve_generator **gentr) { sieve_ast_unref(&(*gentr)->genenv.ast); - + sieve_error_handler_unref(&(*gentr)->ehandler); sieve_binary_debug_writer_deinit(&(*gentr)->dwriter); @@ -119,12 +119,12 @@ void sieve_generator_free(struct sieve_generator **gentr) sieve_binary_unref(&(*gentr)->genenv.sbin); pool_unref(&((*gentr)->pool)); - + *gentr = NULL; } -/* - * Accessors +/* + * Accessors */ struct sieve_error_handler *sieve_generator_error_handler @@ -156,29 +156,29 @@ struct sieve_binary_block *sieve_generator_get_block return gentr->genenv.sblock; } -/* - * Error handling +/* + * Error handling */ void sieve_generator_warning -(struct sieve_generator *gentr, unsigned int source_line, - const char *fmt, ...) -{ +(struct sieve_generator *gentr, unsigned int source_line, + const char *fmt, ...) +{ va_list args; - + va_start(args, fmt); sieve_vwarning(gentr->ehandler, sieve_error_script_location(gentr->genenv.script, source_line), fmt, args); va_end(args); } - + void sieve_generator_error -(struct sieve_generator *gentr, unsigned int source_line, - const char *fmt, ...) +(struct sieve_generator *gentr, unsigned int source_line, + const char *fmt, ...) { va_list args; - + va_start(args, fmt); sieve_verror(gentr->ehandler, sieve_error_script_location(gentr->genenv.script, source_line), @@ -187,11 +187,11 @@ void sieve_generator_error } void sieve_generator_critical -(struct sieve_generator *gentr, unsigned int source_line, - const char *fmt, ...) +(struct sieve_generator *gentr, unsigned int source_line, + const char *fmt, ...) { va_list args; - + va_start(args, fmt); sieve_vwarning(gentr->ehandler, sieve_error_script_location(gentr->genenv.script, source_line), @@ -199,32 +199,32 @@ void sieve_generator_critical va_end(args); } -/* - * Extension support +/* + * Extension support */ void sieve_generator_extension_set_context (struct sieve_generator *gentr, const struct sieve_extension *ext, void *context) { if ( ext->id < 0 ) return; - - array_idx_set(&gentr->ext_contexts, (unsigned int) ext->id, &context); + + array_idx_set(&gentr->ext_contexts, (unsigned int) ext->id, &context); } const void *sieve_generator_extension_get_context -(struct sieve_generator *gentr, const struct sieve_extension *ext) +(struct sieve_generator *gentr, const struct sieve_extension *ext) { void * const *ctx; if ( ext->id < 0 || ext->id >= (int) array_count(&gentr->ext_contexts) ) return NULL; - - ctx = array_idx(&gentr->ext_contexts, (unsigned int) ext->id); + + ctx = array_idx(&gentr->ext_contexts, (unsigned int) ext->id); return *ctx; } -/* +/* * Code generation API */ @@ -247,15 +247,15 @@ static void sieve_generate_debug_from_ast_argument } bool sieve_generate_argument -(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, +(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *cmd) { const struct sieve_argument_def *arg_def; - + if ( arg->argument == NULL || arg->argument->def == NULL ) return FALSE; arg_def = arg->argument->def; - + if ( arg_def->generate == NULL ) return TRUE; @@ -265,18 +265,18 @@ bool sieve_generate_argument } bool sieve_generate_arguments -(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd, +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd, struct sieve_ast_argument **last_arg_r) { enum { ARG_START, ARG_OPTIONAL, ARG_POSITIONAL } state = ARG_START; struct sieve_ast_argument *arg = sieve_ast_argument_first(cmd->ast_node); - + /* Generate all arguments with assigned generator function */ - + while ( arg != NULL ) { const struct sieve_argument *argument; const struct sieve_argument_def *arg_def; - + if ( arg->argument == NULL || arg->argument->def == NULL ) return FALSE; @@ -284,13 +284,13 @@ bool sieve_generate_arguments arg_def = argument->def; switch ( state ) { - case ARG_START: + case ARG_START: if ( argument->id_code == 0 ) state = ARG_POSITIONAL; else { /* Mark start of optional operands with 0 operand identifier */ sieve_binary_emit_byte(cgenv->sblock, SIEVE_OPERAND_OPTIONAL); - + /* Emit argument id for optional operand */ sieve_binary_emit_byte (cgenv->sblock, (unsigned char) argument->id_code); @@ -298,10 +298,10 @@ bool sieve_generate_arguments state = ARG_OPTIONAL; } break; - case ARG_OPTIONAL: + case ARG_OPTIONAL: if ( argument->id_code == 0 ) state = ARG_POSITIONAL; - + /* Emit argument id for optional operand (0 marks the end of the optionals) */ sieve_binary_emit_byte (cgenv->sblock, (unsigned char) argument->id_code); @@ -312,12 +312,12 @@ bool sieve_generate_arguments return FALSE; break; } - - /* Call the generation function for the argument */ + + /* Call the generation function for the argument */ if ( arg_def->generate != NULL ) { sieve_generate_debug_from_ast_argument(cgenv, arg); - - if ( !arg_def->generate(cgenv, arg, cmd) ) + + if ( !arg_def->generate(cgenv, arg, cmd) ) return FALSE; } else if ( state == ARG_POSITIONAL ) break; @@ -327,43 +327,43 @@ bool sieve_generate_arguments /* Mark end of optional list if it is still open */ if ( state == ARG_OPTIONAL ) sieve_binary_emit_byte(cgenv->sblock, 0); - + if ( last_arg_r != NULL ) *last_arg_r = arg; - + return TRUE; } bool sieve_generate_argument_parameters -(const struct sieve_codegen_env *cgenv, +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd, struct sieve_ast_argument *arg) { struct sieve_ast_argument *param = arg->parameters; - + /* Generate all parameters with assigned generator function */ - + while ( param != NULL ) { if ( param->argument != NULL && param->argument->def != NULL ) { const struct sieve_argument_def *parameter = param->argument->def; - - /* Call the generation function for the parameter */ + + /* Call the generation function for the parameter */ if ( parameter->generate != NULL ) { sieve_generate_debug_from_ast_argument(cgenv, param); - - if ( !parameter->generate(cgenv, param, cmd) ) + + if ( !parameter->generate(cgenv, param, cmd) ) return FALSE; } } param = sieve_ast_argument_next(param); } - + return TRUE; } bool sieve_generate_test (const struct sieve_codegen_env *cgenv, struct sieve_ast_node *tst_node, - struct sieve_jumplist *jlist, bool jump_true) + struct sieve_jumplist *jlist, bool jump_true) { struct sieve_command *test; const struct sieve_command_def *tst_def; @@ -375,35 +375,35 @@ bool sieve_generate_test if ( tst_def->control_generate != NULL ) { sieve_generate_debug_from_ast_node(cgenv, tst_node); - - if ( tst_def->control_generate(cgenv, test, jlist, jump_true) ) + + if ( tst_def->control_generate(cgenv, test, jlist, jump_true) ) return TRUE; - + return FALSE; } - + if ( tst_def->generate != NULL ) { sieve_generate_debug_from_ast_node(cgenv, tst_node); if ( tst_def->generate(cgenv, test) ) { - - if ( jump_true ) + + if ( jump_true ) sieve_operation_emit(cgenv->sblock, NULL, &sieve_jmptrue_operation); else sieve_operation_emit(cgenv->sblock, NULL, &sieve_jmpfalse_operation); sieve_jumplist_add(jlist, sieve_binary_emit_offset(cgenv->sblock, 0)); - + return TRUE; - } - + } + return FALSE; } - + return TRUE; } static bool sieve_generate_command -(const struct sieve_codegen_env *cgenv, struct sieve_ast_node *cmd_node) +(const struct sieve_codegen_env *cgenv, struct sieve_ast_node *cmd_node) { struct sieve_command *command; const struct sieve_command_def *cmd_def; @@ -418,29 +418,29 @@ static bool sieve_generate_command return cmd_def->generate(cgenv, command); } - - return TRUE; + + return TRUE; } bool sieve_generate_block -(const struct sieve_codegen_env *cgenv, struct sieve_ast_node *block) +(const struct sieve_codegen_env *cgenv, struct sieve_ast_node *block) { bool result = TRUE; struct sieve_ast_node *cmd_node; - T_BEGIN { + T_BEGIN { cmd_node = sieve_ast_command_first(block); - while ( result && cmd_node != NULL ) { - result = sieve_generate_command(cgenv, cmd_node); + while ( result && cmd_node != NULL ) { + result = sieve_generate_command(cgenv, cmd_node); cmd_node = sieve_ast_command_next(cmd_node); - } + } } T_END; - + return result; } struct sieve_binary *sieve_generator_run -(struct sieve_generator *gentr, struct sieve_binary_block **sblock_r) +(struct sieve_generator *gentr, struct sieve_binary_block **sblock_r) { bool topmost = ( sblock_r == NULL || *sblock_r == NULL ); struct sieve_binary *sbin; @@ -448,9 +448,9 @@ struct sieve_binary *sieve_generator_run const struct sieve_extension *const *extensions; unsigned int i, ext_count; bool result = TRUE; - + /* Initialize */ - + if ( topmost ) { sbin = sieve_binary_create_new(sieve_ast_script(gentr->genenv.ast)); sblock = sieve_binary_block_get(sbin, SBIN_SYSBLOCK_MAIN_PROGRAM); @@ -458,7 +458,7 @@ struct sieve_binary *sieve_generator_run sblock = *sblock_r; sbin = sieve_binary_block_get_binary(sblock); } - + sieve_binary_ref(sbin); gentr->genenv.sbin = sbin; gentr->genenv.sblock = sblock; @@ -468,7 +468,7 @@ struct sieve_binary *sieve_generator_run gentr->dwriter = sieve_binary_debug_writer_init(debug_block); (void)sieve_binary_emit_unsigned (sblock, sieve_binary_block_get_id(debug_block)); - + /* Load extensions linked to the AST and emit a list in code */ extensions = sieve_ast_extensions_get(gentr->genenv.ast, &ext_count); (void) sieve_binary_emit_unsigned(sblock, ext_count); @@ -477,10 +477,10 @@ struct sieve_binary *sieve_generator_run /* Link to binary */ (void)sieve_binary_extension_link(sbin, ext); - + /* Emit */ sieve_binary_emit_extension(sblock, ext, 0); - + /* Load */ if ( ext->def != NULL && ext->def->generator_load != NULL && !ext->def->generator_load(ext, &gentr->genenv) ) @@ -488,17 +488,17 @@ struct sieve_binary *sieve_generator_run } /* Generate code */ - + if ( result ) { if ( !sieve_generate_block - (&gentr->genenv, sieve_ast_root(gentr->genenv.ast))) + (&gentr->genenv, sieve_ast_root(gentr->genenv.ast))) result = FALSE; - else if ( topmost ) + else if ( topmost ) sieve_binary_activate(sbin); } /* Cleanup */ - + gentr->genenv.sbin = NULL; gentr->genenv.sblock = NULL; sieve_binary_unref(&sbin); @@ -514,7 +514,7 @@ struct sieve_binary *sieve_generator_run if ( sblock_r != NULL ) *sblock_r = sblock; } - + return sbin; } diff --git a/src/lib-sieve/sieve-generator.h b/src/lib-sieve/sieve-generator.h index 941fb434f26f943f6fce1b7e08ce6d0f3df5469e..b9c52b0fb6bb3e7461629d0daaaecffd7e54ccea 100644 --- a/src/lib-sieve/sieve-generator.h +++ b/src/lib-sieve/sieve-generator.h @@ -30,8 +30,8 @@ struct sieve_generator *sieve_generator_create enum sieve_compile_flags flags); void sieve_generator_free(struct sieve_generator **generator); -/* - * Accessors +/* + * Accessors */ struct sieve_error_handler *sieve_generator_error_handler @@ -44,32 +44,32 @@ struct sieve_binary *sieve_generator_get_binary struct sieve_binary_block *sieve_generator_get_block (struct sieve_generator *gentr); -/* - * Error handling +/* + * Error handling */ void sieve_generator_warning -(struct sieve_generator *gentr, unsigned int source_line, +(struct sieve_generator *gentr, unsigned int source_line, const char *fmt, ...) ATTR_FORMAT(3, 4); void sieve_generator_error -(struct sieve_generator *gentr, unsigned int source_line, +(struct sieve_generator *gentr, unsigned int source_line, const char *fmt, ...) ATTR_FORMAT(3, 4); void sieve_generator_critical -(struct sieve_generator *gentr, unsigned int source_line, - const char *fmt, ...) ATTR_FORMAT(3, 4); +(struct sieve_generator *gentr, unsigned int source_line, + const char *fmt, ...) ATTR_FORMAT(3, 4); -/* - * Extension support +/* + * Extension support */ void sieve_generator_extension_set_context - (struct sieve_generator *gentr, const struct sieve_extension *ext, + (struct sieve_generator *gentr, const struct sieve_extension *ext, void *context); const void *sieve_generator_extension_get_context (struct sieve_generator *gentr, const struct sieve_extension *ext); - -/* - * Jump list + +/* + * Jump list */ struct sieve_jumplist { @@ -88,24 +88,24 @@ void sieve_jumplist_add (struct sieve_jumplist *jlist, sieve_size_t jump); void sieve_jumplist_resolve(struct sieve_jumplist *jlist); -/* - * Code generation API +/* + * Code generation API */ bool sieve_generate_argument - (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, + (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *cmd); bool sieve_generate_arguments - (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd, + (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd, struct sieve_ast_argument **last_arg_r); bool sieve_generate_argument_parameters - (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd, + (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd, struct sieve_ast_argument *arg); bool sieve_generate_block (const struct sieve_codegen_env *cgenv, struct sieve_ast_node *block); bool sieve_generate_test - (const struct sieve_codegen_env *cgenv, struct sieve_ast_node *tst_node, + (const struct sieve_codegen_env *cgenv, struct sieve_ast_node *tst_node, struct sieve_jumplist *jlist, bool jump_true); struct sieve_binary *sieve_generator_run (struct sieve_generator *gentr, struct sieve_binary_block **sblock_r); diff --git a/src/lib-sieve/sieve-interpreter.c b/src/lib-sieve/sieve-interpreter.c index 47dea9835906f6d09edeea761cb04a11f7fcf612..11e5e7c49b8a101fdb6287c2365d533ac8dda26e 100644 --- a/src/lib-sieve/sieve-interpreter.c +++ b/src/lib-sieve/sieve-interpreter.c @@ -26,8 +26,8 @@ #include <string.h> -/* - * Interpreter extension +/* + * Interpreter extension */ struct sieve_interpreter_extension_reg { @@ -37,30 +37,30 @@ struct sieve_interpreter_extension_reg { void *context; }; -/* - * Interpreter +/* + * Interpreter */ struct sieve_interpreter { pool_t pool; /* Runtime data for extensions */ - ARRAY_DEFINE(extensions, struct sieve_interpreter_extension_reg); - - sieve_size_t reset_vector; - + ARRAY_DEFINE(extensions, struct sieve_interpreter_extension_reg); + + sieve_size_t reset_vector; + /* Execution status */ - + sieve_size_t pc; /* Program counter */ bool interrupted; /* Interpreter interrupt requested */ bool test_result; /* Result of previous test command */ - + /* Runtime environment */ struct sieve_runtime_env runenv; struct sieve_runtime_trace trace; /* Current operation */ - struct sieve_operation oprtn; + struct sieve_operation oprtn; /* Location information */ struct sieve_binary_debug_reader *dreader; @@ -68,10 +68,10 @@ struct sieve_interpreter { }; static struct sieve_interpreter *_sieve_interpreter_create -(struct sieve_binary *sbin, struct sieve_binary_block *sblock, +(struct sieve_binary *sbin, struct sieve_binary_block *sblock, struct sieve_script *script, const struct sieve_message_data *msgdata, const struct sieve_script_env *senv, struct sieve_error_handler *ehandler, - enum sieve_runtime_flags flags) + enum sieve_runtime_flags flags) { unsigned int i, ext_count; struct sieve_interpreter *interp; @@ -81,8 +81,8 @@ static struct sieve_interpreter *_sieve_interpreter_create unsigned int debug_block_id; sieve_size_t *address; bool success = TRUE; - - pool = pool_alloconly_create("sieve_interpreter", 4096); + + pool = pool_alloconly_create("sieve_interpreter", 4096); interp = p_new(pool, struct sieve_interpreter, 1); interp->pool = pool; @@ -109,16 +109,16 @@ static struct sieve_interpreter *_sieve_interpreter_create interp->runenv.trace = &interp->trace; } - if ( senv->exec_status == NULL ) + if ( senv->exec_status == NULL ) interp->runenv.exec_status = p_new(interp->pool, struct sieve_exec_status, 1); else interp->runenv.exec_status = senv->exec_status; - if ( script == NULL ) + if ( script == NULL ) interp->runenv.script = sieve_binary_script(sbin); else interp->runenv.script = script; - + interp->runenv.pc = 0; address = &(interp->runenv.pc); @@ -127,13 +127,13 @@ static struct sieve_interpreter *_sieve_interpreter_create p_array_init(&interp->extensions, pool, sieve_extensions_get_count(svinst)); /* Pre-load core language features implemented as 'extensions' */ - ext_preloaded = sieve_extensions_get_preloaded(svinst, &ext_count); + ext_preloaded = sieve_extensions_get_preloaded(svinst, &ext_count); for ( i = 0; i < ext_count; i++ ) { const struct sieve_extension_def *ext_def = ext_preloaded[i]->def; if ( ext_def != NULL && ext_def->interpreter_load != NULL ) (void)ext_def->interpreter_load - (ext_preloaded[i], &interp->runenv, address); + (ext_preloaded[i], &interp->runenv, address); } /* Load debug block */ @@ -151,18 +151,18 @@ static struct sieve_interpreter *_sieve_interpreter_create } /* Load other extensions listed in code */ - if ( success && + if ( success && sieve_binary_read_unsigned(sblock, address, &ext_count) ) { for ( i = 0; i < ext_count; i++ ) { unsigned int code = 0; const struct sieve_extension *ext; - + if ( !sieve_binary_read_extension(sblock, address, &code, &ext) ) { success = FALSE; break; } - + if ( ext->def != NULL ) { if ( ext->global && (flags & SIEVE_RUNTIME_FLAG_NOGLOBAL) != 0 ) { sieve_runtime_error(&interp->runenv, NULL, @@ -173,7 +173,7 @@ static struct sieve_interpreter *_sieve_interpreter_create break; } - if ( ext->def->interpreter_load != NULL && + if ( ext->def->interpreter_load != NULL && !ext->def->interpreter_load(ext, &interp->runenv, address) ) { success = FALSE; break; @@ -182,25 +182,25 @@ static struct sieve_interpreter *_sieve_interpreter_create } } else success = FALSE; - + if ( !success ) { sieve_interpreter_free(&interp); interp = NULL; } else { interp->reset_vector = *address; } - + return interp; } struct sieve_interpreter *sieve_interpreter_create (struct sieve_binary *sbin, const struct sieve_message_data *msgdata, const struct sieve_script_env *senv, struct sieve_error_handler *ehandler, - enum sieve_runtime_flags flags) + enum sieve_runtime_flags flags) { struct sieve_binary_block *sblock; - if ( (sblock=sieve_binary_block_get(sbin, SBIN_SYSBLOCK_MAIN_PROGRAM)) + if ( (sblock=sieve_binary_block_get(sbin, SBIN_SYSBLOCK_MAIN_PROGRAM)) == NULL ) return NULL; @@ -210,8 +210,8 @@ struct sieve_interpreter *sieve_interpreter_create struct sieve_interpreter *sieve_interpreter_create_for_block (struct sieve_binary_block *sblock, struct sieve_script *script, - const struct sieve_message_data *msgdata, const struct sieve_script_env *senv, - struct sieve_error_handler *ehandler, enum sieve_runtime_flags flags) + const struct sieve_message_data *msgdata, const struct sieve_script_env *senv, + struct sieve_error_handler *ehandler, enum sieve_runtime_flags flags) { if ( sblock == NULL ) return NULL; @@ -220,7 +220,7 @@ struct sieve_interpreter *sieve_interpreter_create_for_block ehandler, flags); } -void sieve_interpreter_free(struct sieve_interpreter **interp) +void sieve_interpreter_free(struct sieve_interpreter **interp) { const struct sieve_interpreter_extension_reg *eregs; unsigned int ext_count, i; @@ -238,7 +238,7 @@ void sieve_interpreter_free(struct sieve_interpreter **interp) sieve_binary_unref(&(*interp)->runenv.sbin); sieve_error_handler_unref(&(*interp)->runenv.ehandler); - pool_unref(&((*interp)->pool)); + pool_unref(&((*interp)->pool)); *interp = NULL; } @@ -293,7 +293,7 @@ static inline void sieve_runtime_vmsg if ( location == NULL ) location = sieve_runtime_get_full_command_location(renv); - msg_func(renv->ehandler, location, fmt, args); + msg_func(renv->ehandler, location, fmt, args); } T_END; } @@ -343,7 +343,7 @@ void sieve_runtime_critical location = sieve_runtime_get_full_command_location(renv); sieve_vcritical - (renv->svinst, renv->ehandler, location, user_prefix, fmt, args); + (renv->svinst, renv->ehandler, location, user_prefix, fmt, args); } T_END; va_end(args); @@ -403,42 +403,42 @@ void sieve_interpreter_extension_register if ( ext->id < 0 ) return; - reg = array_idx_modifiable(&interp->extensions, (unsigned int) ext->id); + reg = array_idx_modifiable(&interp->extensions, (unsigned int) ext->id); reg->intext = intext; reg->ext = ext; reg->context = context; } void sieve_interpreter_extension_set_context -(struct sieve_interpreter *interp, const struct sieve_extension *ext, +(struct sieve_interpreter *interp, const struct sieve_extension *ext, void *context) { struct sieve_interpreter_extension_reg *reg; if ( ext->id < 0 ) return; - - reg = array_idx_modifiable(&interp->extensions, (unsigned int) ext->id); + + reg = array_idx_modifiable(&interp->extensions, (unsigned int) ext->id); reg->context = context; } void *sieve_interpreter_extension_get_context -(struct sieve_interpreter *interp, const struct sieve_extension *ext) +(struct sieve_interpreter *interp, const struct sieve_extension *ext) { const struct sieve_interpreter_extension_reg *reg; if ( ext->id < 0 || ext->id >= (int) array_count(&interp->extensions) ) return NULL; - - reg = array_idx(&interp->extensions, (unsigned int) ext->id); + + reg = array_idx(&interp->extensions, (unsigned int) ext->id); return reg->context; } -/* - * Program flow +/* + * Program flow */ -void sieve_interpreter_reset(struct sieve_interpreter *interp) +void sieve_interpreter_reset(struct sieve_interpreter *interp) { interp->runenv.pc = interp->reset_vector; interp->interrupted = FALSE; @@ -463,25 +463,25 @@ int sieve_interpreter_program_jump sieve_size_t *address = &(interp->runenv.pc); sieve_size_t jmp_start = *address; sieve_offset_t jmp_offset; - + if ( !sieve_binary_read_offset(renv->sblock, address, &jmp_offset) ) { - sieve_runtime_trace_error(renv, "invalid jump offset"); + sieve_runtime_trace_error(renv, "invalid jump offset"); return SIEVE_EXEC_BIN_CORRUPT; } - if ( jmp_start + jmp_offset <= sieve_binary_block_get_size(renv->sblock) && - jmp_start + jmp_offset > 0 ) - { + if ( jmp_start + jmp_offset <= sieve_binary_block_get_size(renv->sblock) && + jmp_start + jmp_offset > 0 ) + { if ( jump ) { sieve_size_t jmp_addr = jmp_start + jmp_offset; if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) { - unsigned int jmp_line = + unsigned int jmp_line = sieve_runtime_get_source_location(renv, jmp_addr); if ( sieve_runtime_trace_hasflag(renv, SIEVE_TRFLG_ADDRESSES) ) { - sieve_runtime_trace(renv, 0, "jumping to line %d [%08llx]", + sieve_runtime_trace(renv, 0, "jumping to line %d [%08llx]", jmp_line, (long long unsigned int) jmp_addr); } else { sieve_runtime_trace(renv, 0, "jumping to line %d", jmp_line); @@ -490,12 +490,12 @@ int sieve_interpreter_program_jump *address = jmp_addr; } else { - sieve_runtime_trace(renv, 0, "not jumping"); + sieve_runtime_trace(renv, 0, "not jumping"); } - + return SIEVE_EXEC_OK; } - + sieve_runtime_trace_error(renv, "jump offset out of range"); return SIEVE_EXEC_BIN_CORRUPT; } @@ -516,12 +516,12 @@ bool sieve_interpreter_get_test_result return interp->test_result; } -/* - * Code execute +/* + * Code execute */ static int sieve_interpreter_operation_execute -(struct sieve_interpreter *interp) +(struct sieve_interpreter *interp) { struct sieve_operation *oprtn = &(interp->oprtn); sieve_size_t *address = &(interp->runenv.pc); @@ -543,57 +543,57 @@ static int sieve_interpreter_operation_execute } T_END; } else { sieve_runtime_trace - (&interp->runenv, SIEVE_TRLVL_COMMANDS, "OP: %s (NOOP)", + (&interp->runenv, SIEVE_TRLVL_COMMANDS, "OP: %s (NOOP)", sieve_operation_mnemonic(oprtn)); } return result; } - + /* Binary corrupt */ - sieve_runtime_trace_error(&interp->runenv, "Encountered invalid operation"); + sieve_runtime_trace_error(&interp->runenv, "Encountered invalid operation"); return SIEVE_EXEC_BIN_CORRUPT; -} +} int sieve_interpreter_continue -(struct sieve_interpreter *interp, bool *interrupted) +(struct sieve_interpreter *interp, bool *interrupted) { sieve_size_t *address = &(interp->runenv.pc); int ret = SIEVE_EXEC_OK; - + sieve_result_ref(interp->runenv.result); interp->interrupted = FALSE; - + if ( interrupted != NULL ) *interrupted = FALSE; - - while ( ret == SIEVE_EXEC_OK && !interp->interrupted && + + while ( ret == SIEVE_EXEC_OK && !interp->interrupted && *address < sieve_binary_block_get_size(interp->runenv.sblock) ) { - + ret = sieve_interpreter_operation_execute(interp); if ( ret != SIEVE_EXEC_OK ) { - sieve_runtime_trace(&interp->runenv, SIEVE_TRLVL_NONE, + sieve_runtime_trace(&interp->runenv, SIEVE_TRLVL_NONE, "[[EXECUTION ABORTED]]"); } } - + if ( interrupted != NULL ) *interrupted = interp->interrupted; - + sieve_result_unref(&interp->runenv.result); return ret; } int sieve_interpreter_start -(struct sieve_interpreter *interp, struct sieve_result *result, bool *interrupted) +(struct sieve_interpreter *interp, struct sieve_result *result, bool *interrupted) { const struct sieve_interpreter_extension_reg *eregs; unsigned int ext_count, i; - + interp->runenv.result = result; - interp->runenv.msgctx = sieve_result_get_message_context(result); - + interp->runenv.msgctx = sieve_result_get_message_context(result); + /* Signal registered extensions that the interpreter is being run */ eregs = array_get(&interp->extensions, &ext_count); for ( i = 0; i < ext_count; i++ ) { @@ -601,21 +601,21 @@ int sieve_interpreter_start eregs[i].intext->run(eregs[i].ext, &interp->runenv, eregs[i].context); } - return sieve_interpreter_continue(interp, interrupted); + return sieve_interpreter_continue(interp, interrupted); } int sieve_interpreter_run (struct sieve_interpreter *interp, struct sieve_result *result) { int ret = 0; - + sieve_interpreter_reset(interp); sieve_result_ref(result); - + ret = sieve_interpreter_start(interp, result, NULL); - + sieve_result_unref(&result); - + return ret; } diff --git a/src/lib-sieve/sieve-interpreter.h b/src/lib-sieve/sieve-interpreter.h index d0117a7c3a024e8c26236163a3e47836b3f1750c..8c566358a6a8209fc8e27dc77255f9a30927c61f 100644 --- a/src/lib-sieve/sieve-interpreter.h +++ b/src/lib-sieve/sieve-interpreter.h @@ -12,8 +12,8 @@ #include "sieve-common.h" #include "sieve-runtime.h" -/* - * Interpreter +/* + * Interpreter */ struct sieve_interpreter *sieve_interpreter_create @@ -22,7 +22,7 @@ struct sieve_interpreter *sieve_interpreter_create enum sieve_runtime_flags flags); struct sieve_interpreter *sieve_interpreter_create_for_block (struct sieve_binary_block *sblock, struct sieve_script *script, - const struct sieve_message_data *msgdata, + const struct sieve_message_data *msgdata, const struct sieve_script_env *senv, struct sieve_error_handler *ehandler, enum sieve_runtime_flags flags); void sieve_interpreter_free(struct sieve_interpreter **interp); @@ -81,8 +81,8 @@ unsigned int sieve_runtime_get_command_location const char *sieve_runtime_get_full_command_location (const struct sieve_runtime_env *renv); -/* - * Error handling +/* + * Error handling */ void sieve_runtime_error @@ -92,24 +92,24 @@ void sieve_runtime_warning (const struct sieve_runtime_env *renv, const char *location, const char *fmt, ...) ATTR_FORMAT(3, 4); void sieve_runtime_log - (const struct sieve_runtime_env *renv, const char *location, + (const struct sieve_runtime_env *renv, const char *location, const char *fmt, ...) ATTR_FORMAT(3, 4); void sieve_runtime_critical (const struct sieve_runtime_env *renv, const char *location, const char *user_prefix, const char *fmt, ...) ATTR_FORMAT(4, 5); -/* - * Extension support +/* + * Extension support */ struct sieve_interpreter_extension { - const struct sieve_extension_def *ext_def; + const struct sieve_extension_def *ext_def; void (*run) - (const struct sieve_extension *ext, const struct sieve_runtime_env *renv, + (const struct sieve_extension *ext, const struct sieve_runtime_env *renv, void *context); void (*free) - (const struct sieve_extension *ext, struct sieve_interpreter *interp, + (const struct sieve_extension *ext, struct sieve_interpreter *interp, void *context); }; @@ -117,27 +117,27 @@ void sieve_interpreter_extension_register (struct sieve_interpreter *interp, const struct sieve_extension *ext, const struct sieve_interpreter_extension *intext, void *context); void sieve_interpreter_extension_set_context - (struct sieve_interpreter *interp, const struct sieve_extension *ext, + (struct sieve_interpreter *interp, const struct sieve_extension *ext, void *context); void *sieve_interpreter_extension_get_context - (struct sieve_interpreter *interp, const struct sieve_extension *ext); + (struct sieve_interpreter *interp, const struct sieve_extension *ext); -/* - * Opcodes and operands +/* + * Opcodes and operands */ - + int sieve_interpreter_handle_optional_operands (const struct sieve_runtime_env *renv, sieve_size_t *address, struct sieve_side_effects_list **list); -/* - * Code execute +/* + * Code execute */ int sieve_interpreter_continue (struct sieve_interpreter *interp, bool *interrupted); int sieve_interpreter_start - (struct sieve_interpreter *interp, struct sieve_result *result, + (struct sieve_interpreter *interp, struct sieve_result *result, bool *interrupted); int sieve_interpreter_run (struct sieve_interpreter *interp, struct sieve_result *result); diff --git a/src/lib-sieve/sieve-lexer.c b/src/lib-sieve/sieve-lexer.c index 039d7d29dca5f0753d5ff2b38b55547403cac7d2..16d82a64d875230124302eac2669af6aff9742f3 100644 --- a/src/lib-sieve/sieve-lexer.c +++ b/src/lib-sieve/sieve-lexer.c @@ -1,6 +1,6 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #include "lib.h" #include "compat.h" #include "str.h" @@ -22,7 +22,7 @@ #include <unistd.h> #include <ctype.h> -/* +/* * Useful macros */ @@ -31,7 +31,7 @@ /* * Forward declarations */ - + inline static void sieve_lexer_error (const struct sieve_lexer *lexer, const char *fmt, ...) ATTR_FORMAT(2, 3); inline static void sieve_lexer_warning @@ -46,23 +46,23 @@ struct sieve_lexical_scanner { struct sieve_instance *svinst; struct sieve_script *script; - struct istream *input; - + struct istream *input; + struct sieve_error_handler *ehandler; - + /* Currently scanned data */ const unsigned char *buffer; size_t buffer_size; size_t buffer_pos; struct sieve_lexer lexer; - + int current_line; }; const struct sieve_lexer *sieve_lexer_create (struct sieve_script *script, struct sieve_error_handler *ehandler, - enum sieve_error *error_r) + enum sieve_error *error_r) { pool_t pool; struct sieve_lexical_scanner *scanner; @@ -86,37 +86,37 @@ const struct sieve_lexer *sieve_lexer_create *error_r = SIEVE_ERROR_NOT_POSSIBLE; return NULL; } - - pool = pool_alloconly_create("sieve_lexer_scanner", 1024); + + pool = pool_alloconly_create("sieve_lexer_scanner", 1024); scanner = p_new(pool, struct sieve_lexical_scanner, 1); scanner->pool = pool; scanner->lexer.scanner = scanner; - + scanner->ehandler = ehandler; sieve_error_handler_ref(ehandler); scanner->input = stream; i_stream_ref(scanner->input); - + scanner->script = script; sieve_script_ref(script); - + scanner->buffer = NULL; scanner->buffer_size = 0; scanner->buffer_pos = 0; - + scanner->lexer.token_type = STT_NONE; scanner->lexer.token_str_value = str_new(pool, 256); scanner->lexer.token_int_value = 0; scanner->lexer.token_line = 1; - scanner->current_line = 1; - + scanner->current_line = 1; + return &scanner->lexer; } -void sieve_lexer_free(const struct sieve_lexer **lexer) -{ +void sieve_lexer_free(const struct sieve_lexer **lexer) +{ struct sieve_lexical_scanner *scanner = (*lexer)->scanner; i_stream_unref(&scanner->input); @@ -126,7 +126,7 @@ void sieve_lexer_free(const struct sieve_lexer **lexer) sieve_error_handler_unref(&scanner->ehandler); - pool_unref(&scanner->pool); + pool_unref(&scanner->pool); *lexer = NULL; } @@ -144,11 +144,11 @@ inline static void sieve_lexer_error va_start(args, fmt); T_BEGIN { - sieve_verror(scanner->ehandler, + sieve_verror(scanner->ehandler, sieve_error_script_location(scanner->script, scanner->current_line), fmt, args); } T_END; - + va_end(args); } @@ -160,63 +160,63 @@ inline static void sieve_lexer_warning va_list args; va_start(args, fmt); - T_BEGIN { - sieve_vwarning(scanner->ehandler, + T_BEGIN { + sieve_vwarning(scanner->ehandler, sieve_error_script_location(scanner->script, scanner->current_line), fmt, args); } T_END; - + va_end(args); } const char *sieve_lexer_token_description -(const struct sieve_lexer *lexer) +(const struct sieve_lexer *lexer) { switch ( lexer->token_type ) { - case STT_NONE: return "no token (bug)"; + case STT_NONE: return "no token (bug)"; case STT_WHITESPACE: return "whitespace (bug)"; case STT_EOF: return "end of file"; - - case STT_NUMBER: return "number"; - case STT_IDENTIFIER: return "identifier"; + + case STT_NUMBER: return "number"; + case STT_IDENTIFIER: return "identifier"; case STT_TAG: return "tag"; - case STT_STRING: return "string"; - - case STT_RBRACKET: return "')'"; + case STT_STRING: return "string"; + + case STT_RBRACKET: return "')'"; case STT_LBRACKET: return "'('"; - case STT_RCURLY: return "'}'"; - case STT_LCURLY: return "'{'"; - case STT_RSQUARE: return "']'"; - case STT_LSQUARE: return "'['"; - case STT_SEMICOLON: return "';'"; - case STT_COMMA: return "','"; - - case STT_SLASH: return "'/'"; - case STT_COLON: return "':'"; - - case STT_GARBAGE: return "unknown characters"; + case STT_RCURLY: return "'}'"; + case STT_LCURLY: return "'{'"; + case STT_RSQUARE: return "']'"; + case STT_LSQUARE: return "'['"; + case STT_SEMICOLON: return "';'"; + case STT_COMMA: return "','"; + + case STT_SLASH: return "'/'"; + case STT_COLON: return "':'"; + + case STT_GARBAGE: return "unknown characters"; case STT_ERROR: return "error token (bug)"; } - + return "unknown token (bug)"; } - -/* - * Debug + +/* + * Debug */ - -void sieve_lexer_token_print(const struct sieve_lexer *lexer) + +void sieve_lexer_token_print(const struct sieve_lexer *lexer) { switch ( lexer->token_type ) { - case STT_NONE: printf("??NONE?? "); break; + case STT_NONE: printf("??NONE?? "); break; case STT_WHITESPACE: printf("??WHITESPACE?? "); break; case STT_EOF: printf("EOF\n"); break; - + case STT_NUMBER: printf("NUMBER "); break; case STT_IDENTIFIER: printf("IDENTIFIER "); break; case STT_TAG: printf("TAG "); break; case STT_STRING: printf("STRING "); break; - + case STT_RBRACKET: printf(") "); break; case STT_LBRACKET: printf("( "); break; case STT_RCURLY: printf("}\n"); break; @@ -225,49 +225,49 @@ void sieve_lexer_token_print(const struct sieve_lexer *lexer) case STT_LSQUARE: printf("[ "); break; case STT_SEMICOLON: printf(";\n"); break; case STT_COMMA: printf(", "); break; - - case STT_SLASH: printf("/ "); break; - case STT_COLON: printf(": "); break; - + + case STT_SLASH: printf("/ "); break; + case STT_COLON: printf(": "); break; + case STT_GARBAGE: printf(">>GARBAGE<<"); break; case STT_ERROR: printf(">>ERROR<<"); break; - default: + default: printf("UNKNOWN "); break; } } /* - * Lexical scanning + * Lexical scanning */ -static void sieve_lexer_shift(struct sieve_lexical_scanner *scanner) +static void sieve_lexer_shift(struct sieve_lexical_scanner *scanner) { - if ( scanner->buffer != NULL && scanner->buffer[scanner->buffer_pos] == '\n' ) - scanner->current_line++; - - if ( scanner->buffer != NULL && + if ( scanner->buffer != NULL && scanner->buffer[scanner->buffer_pos] == '\n' ) + scanner->current_line++; + + if ( scanner->buffer != NULL && scanner->buffer_pos + 1 < scanner->buffer_size ) scanner->buffer_pos++; else { if ( scanner->buffer != NULL ) i_stream_skip(scanner->input, scanner->buffer_size); - + scanner->buffer = i_stream_get_data(scanner->input, &scanner->buffer_size); - + if ( scanner->buffer == NULL && i_stream_read(scanner->input) > 0 ) scanner->buffer = i_stream_get_data (scanner->input, &scanner->buffer_size); - + scanner->buffer_pos = 0; } } -static inline int sieve_lexer_curchar(struct sieve_lexical_scanner *scanner) -{ +static inline int sieve_lexer_curchar(struct sieve_lexical_scanner *scanner) +{ if ( scanner->buffer == NULL ) return -1; - + return scanner->buffer[scanner->buffer_pos]; } @@ -275,14 +275,14 @@ static inline const char *_char_sanitize(int ch) { if ( ch > 31 && ch < 127 ) return t_strdup_printf("'%c'", ch); - + return t_strdup_printf("0x%02x", ch); } /* sieve_lexer_scan_raw_token: - * Scans valid tokens and whitespace + * Scans valid tokens and whitespace */ -static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) +static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) { struct sieve_lexer *lexer = &scanner->lexer; string_t *str; @@ -294,11 +294,11 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) } lexer->token_line = scanner->current_line; - + switch ( sieve_lexer_curchar(scanner) ) { - + /* whitespace */ - + // hash-comment = ( "#" *CHAR-NOT-CRLF CRLF ) case '#': sieve_lexer_shift(scanner); @@ -314,21 +314,21 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) sieve_lexer_error (lexer, "encountered NUL character in hash comment"); lexer->token_type = STT_ERROR; - return FALSE; + return FALSE; default: break; } - + /* Stray CR is ignored */ - + sieve_lexer_shift(scanner); - } + } sieve_lexer_shift(scanner); - + lexer->token_type = STT_WHITESPACE; return TRUE; - + // bracket-comment = "/*" *(CHAR-NOT-STAR / ("*" CHAR-NOT-SLASH)) "*/" // ;; No */ allowed inside a comment. // ;; (No * is allowed unless it is the last character, @@ -336,29 +336,29 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) // ;; slash.) case '/': sieve_lexer_shift(scanner); - - if ( sieve_lexer_curchar(scanner) == '*' ) { + + if ( sieve_lexer_curchar(scanner) == '*' ) { sieve_lexer_shift(scanner); - + while ( TRUE ) { switch ( sieve_lexer_curchar(scanner) ) { case -1: - sieve_lexer_error(lexer, + sieve_lexer_error(lexer, "end of file before end of bracket comment ('/* ... */') " "started at line %d", lexer->token_line); lexer->token_type = STT_ERROR; return FALSE; case '*': sieve_lexer_shift(scanner); - + if ( sieve_lexer_curchar(scanner) == '/' ) { sieve_lexer_shift(scanner); - + lexer->token_type = STT_WHITESPACE; return TRUE; - + } else if ( sieve_lexer_curchar(scanner) == -1 ) { - sieve_lexer_error(lexer, + sieve_lexer_error(lexer, "end of file before end of bracket comment ('/* ... */') " "started at line %d", lexer->token_line); lexer->token_type = STT_ERROR; @@ -366,22 +366,22 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) } break; case '\0': - sieve_lexer_error(lexer, + sieve_lexer_error(lexer, "encountered NUL character in bracket comment"); lexer->token_type = STT_ERROR; - return FALSE; + return FALSE; default: sieve_lexer_shift(scanner); } } - + i_unreached(); return FALSE; } - + lexer->token_type = STT_SLASH; return TRUE; - + // comment = bracket-comment / hash-comment // white-space = 1*(SP / CRLF / HTAB) / comment case '\t': @@ -389,35 +389,35 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) case '\n': case ' ': sieve_lexer_shift(scanner); - + while ( sieve_lexer_curchar(scanner) == '\t' || sieve_lexer_curchar(scanner) == '\r' || sieve_lexer_curchar(scanner) == '\n' || sieve_lexer_curchar(scanner) == ' ' ) { - + sieve_lexer_shift(scanner); } - + lexer->token_type = STT_WHITESPACE; return TRUE; - + /* quoted-string */ case '"': sieve_lexer_shift(scanner); str_truncate(lexer->token_str_value, 0); str = lexer->token_str_value; - + while ( sieve_lexer_curchar(scanner) != '"' ) { if ( sieve_lexer_curchar(scanner) == '\\' ) { sieve_lexer_shift(scanner); } switch ( sieve_lexer_curchar(scanner) ) { - - /* End of file */ + + /* End of file */ case -1: - sieve_lexer_error(lexer, + sieve_lexer_error(lexer, "end of file before end of quoted string " "started at line %d", lexer->token_line); lexer->token_type = STT_ERROR; @@ -436,46 +436,46 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) sieve_lexer_shift(scanner); if ( sieve_lexer_curchar(scanner) != '\n' ) { - sieve_lexer_error(lexer, + sieve_lexer_error(lexer, "found stray carriage-return (CR) character " "in quoted string started at line %d", lexer->token_line); lexer->token_type = STT_ERROR; return FALSE; } - if ( str_len(str) <= SIEVE_MAX_STRING_LEN ) + if ( str_len(str) <= SIEVE_MAX_STRING_LEN ) str_append(str, "\r\n"); break; /* Loose LF is allowed (non-standard) and converted to CRLF */ case '\n': - if ( str_len(str) <= SIEVE_MAX_STRING_LEN ) + if ( str_len(str) <= SIEVE_MAX_STRING_LEN ) str_append(str, "\r\n"); break; /* Other characters */ default: - if ( str_len(str) <= SIEVE_MAX_STRING_LEN ) + if ( str_len(str) <= SIEVE_MAX_STRING_LEN ) str_append_c(str, sieve_lexer_curchar(scanner)); } - sieve_lexer_shift(scanner); + sieve_lexer_shift(scanner); } sieve_lexer_shift(scanner); if ( str_len(str) > SIEVE_MAX_STRING_LEN ) { - sieve_lexer_error(lexer, + sieve_lexer_error(lexer, "quoted string started at line %d is too long " "(longer than %llu bytes)", lexer->token_line, (long long) SIEVE_MAX_STRING_LEN); lexer->token_type = STT_ERROR; return FALSE; } - + lexer->token_type = STT_STRING; return TRUE; - + /* single character tokens */ case ']': sieve_lexer_shift(scanner); @@ -499,7 +499,7 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) return TRUE; case '(': sieve_lexer_shift(scanner); - lexer->token_type = STT_LBRACKET; + lexer->token_type = STT_LBRACKET; return TRUE; case ';': sieve_lexer_shift(scanner); @@ -509,24 +509,24 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) sieve_lexer_shift(scanner); lexer->token_type = STT_COMMA; return TRUE; - - /* EOF */ - case -1: + + /* EOF */ + case -1: lexer->token_type = STT_EOF; return TRUE; - - default: + + default: /* number */ if ( i_isdigit(sieve_lexer_curchar(scanner)) ) { sieve_number_t value = DIGIT_VAL(sieve_lexer_curchar(scanner)); bool overflow = FALSE; sieve_lexer_shift(scanner); - + while ( i_isdigit(sieve_lexer_curchar(scanner)) ) { - sieve_number_t valnew = + sieve_number_t valnew = value * 10 + DIGIT_VAL(sieve_lexer_curchar(scanner)); - + /* Check for integer wrap */ if ( valnew < value ) overflow = TRUE; @@ -534,8 +534,8 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) value = valnew; sieve_lexer_shift(scanner); } - - switch ( sieve_lexer_curchar(scanner) ) { + + switch ( sieve_lexer_curchar(scanner) ) { case 'k': case 'K': /* Kilo */ if ( value > (SIEVE_MAX_NUMBER >> 10) ) @@ -544,7 +544,7 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) value = value << 10; sieve_lexer_shift(scanner); break; - case 'm': + case 'm': case 'M': /* Mega */ if ( value > (SIEVE_MAX_NUMBER >> 20) ) overflow = TRUE; @@ -573,28 +573,28 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) lexer->token_type = STT_ERROR; return FALSE; } - + lexer->token_type = STT_NUMBER; lexer->token_int_value = value; - return TRUE; - - /* identifier / tag */ + return TRUE; + + /* identifier / tag */ } else if ( i_isalpha(sieve_lexer_curchar(scanner)) || - sieve_lexer_curchar(scanner) == '_' || + sieve_lexer_curchar(scanner) == '_' || sieve_lexer_curchar(scanner) == ':' ) { - + enum sieve_token_type type = STT_IDENTIFIER; str_truncate(lexer->token_str_value,0); str = lexer->token_str_value; - + /* If it starts with a ':' it is a tag and not an identifier */ if ( sieve_lexer_curchar(scanner) == ':' ) { sieve_lexer_shift(scanner); // discard colon type = STT_TAG; - + /* First character still can't be a DIGIT */ if ( i_isalpha(sieve_lexer_curchar(scanner)) || - sieve_lexer_curchar(scanner) == '_' ) { + sieve_lexer_curchar(scanner) == '_' ) { str_append_c(str, sieve_lexer_curchar(scanner)); sieve_lexer_shift(scanner); } else { @@ -606,7 +606,7 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) str_append_c(str, sieve_lexer_curchar(scanner)); sieve_lexer_shift(scanner); } - + /* Scan the rest of the identifier */ while ( i_isalnum(sieve_lexer_curchar(scanner)) || sieve_lexer_curchar(scanner) == '_' ) { @@ -622,12 +622,12 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) type == STT_IDENTIFIER && str_len(str) == 4 && strncasecmp(str_c(str), "text", 4) == 0 ) { sieve_lexer_shift(scanner); // discard colon - + /* Discard SP and HTAB whitespace */ - while ( sieve_lexer_curchar(scanner) == ' ' || + while ( sieve_lexer_curchar(scanner) == ' ' || sieve_lexer_curchar(scanner) == '\t' ) sieve_lexer_shift(scanner); - + /* Discard hash comment or handle single CRLF */ switch ( sieve_lexer_curchar(scanner) ) { case '#': @@ -638,28 +638,28 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) sieve_lexer_shift(scanner); break; } - + /* Terminating LF required */ switch ( sieve_lexer_curchar(scanner) ) { case '\n': sieve_lexer_shift(scanner); break; case -1: - sieve_lexer_error(lexer, + sieve_lexer_error(lexer, "end of file before end of multi-line string"); lexer->token_type = STT_ERROR; return FALSE; - default: - sieve_lexer_error(lexer, + default: + sieve_lexer_error(lexer, "invalid character %s after 'text:' in multiline string", _char_sanitize(sieve_lexer_curchar(scanner))); lexer->token_type = STT_ERROR; return FALSE; } - + /* Start over */ - str_truncate(str, 0); - + str_truncate(str, 0); + /* Parse literal lines */ while ( TRUE ) { bool cr_shifted = FALSE; @@ -667,13 +667,13 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) /* Remove dot-stuffing or detect end of text */ if ( sieve_lexer_curchar(scanner) == '.' ) { sieve_lexer_shift(scanner); - + /* Check for CR.. */ if ( sieve_lexer_curchar(scanner) == '\r' ) { sieve_lexer_shift(scanner); cr_shifted = TRUE; } - + /* ..LF */ if ( sieve_lexer_curchar(scanner) == '\n' ) { sieve_lexer_shift(scanner); @@ -682,7 +682,7 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) /* Check whether length limit was violated */ if ( str_len(str) > SIEVE_MAX_STRING_LEN ) { - sieve_lexer_error(lexer, + sieve_lexer_error(lexer, "multi-line string started at line %d is too long " "(longer than %llu bytes)", lexer->token_line, (long long) SIEVE_MAX_STRING_LEN); @@ -694,7 +694,7 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) return TRUE; } else if ( cr_shifted ) { /* Seen CR, but no LF */ - sieve_lexer_error(lexer, + sieve_lexer_error(lexer, "found stray carriage-return (CR) character " "in multi-line string started at line %d", lexer->token_line); lexer->token_type = STT_ERROR; @@ -702,19 +702,19 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) } /* Handle dot-stuffing */ - if ( str_len(str) <= SIEVE_MAX_STRING_LEN ) + if ( str_len(str) <= SIEVE_MAX_STRING_LEN ) str_append_c(str, '.'); if ( sieve_lexer_curchar(scanner) == '.' ) sieve_lexer_shift(scanner); } - + /* Scan the rest of the line */ while ( sieve_lexer_curchar(scanner) != '\n' && sieve_lexer_curchar(scanner) != '\r' ) { switch ( sieve_lexer_curchar(scanner) ) { case -1: - sieve_lexer_error(lexer, + sieve_lexer_error(lexer, "end of file before end of multi-line string"); lexer->token_type = STT_ERROR; return FALSE; @@ -725,7 +725,7 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) lexer->token_type = STT_ERROR; return FALSE; default: - if ( str_len(str) <= SIEVE_MAX_STRING_LEN ) + if ( str_len(str) <= SIEVE_MAX_STRING_LEN ) str_append_c(str, sieve_lexer_curchar(scanner)); } @@ -738,41 +738,41 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) } /* Now we must see an LF */ - if ( sieve_lexer_curchar(scanner) != '\n' ) { - sieve_lexer_error(lexer, + if ( sieve_lexer_curchar(scanner) != '\n' ) { + sieve_lexer_error(lexer, "found stray carriage-return (CR) character " "in multi-line string started at line %d", lexer->token_line); lexer->token_type = STT_ERROR; return FALSE; } - - if ( str_len(str) <= SIEVE_MAX_STRING_LEN ) + + if ( str_len(str) <= SIEVE_MAX_STRING_LEN ) str_append(str, "\r\n"); sieve_lexer_shift(scanner); } - + i_unreached(); lexer->token_type = STT_ERROR; return FALSE; } if ( str_len(str) > SIEVE_MAX_IDENTIFIER_LEN ) { - sieve_lexer_error(lexer, + sieve_lexer_error(lexer, "encountered impossibly long %s%s'", - (type == STT_TAG ? "tag identifier ':" : "identifier '"), + (type == STT_TAG ? "tag identifier ':" : "identifier '"), str_sanitize(str_c(str), SIEVE_MAX_IDENTIFIER_LEN)); lexer->token_type = STT_ERROR; return FALSE; } - + lexer->token_type = type; return TRUE; } - + /* Error (unknown character and EOF handled already) */ - if ( lexer->token_type != STT_GARBAGE ) - sieve_lexer_error(lexer, "unexpected character(s) starting with %s", + if ( lexer->token_type != STT_GARBAGE ) + sieve_lexer_error(lexer, "unexpected character(s) starting with %s", _char_sanitize(sieve_lexer_curchar(scanner))); sieve_lexer_shift(scanner); lexer->token_type = STT_GARBAGE; @@ -780,14 +780,14 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) } } -bool sieve_lexer_skip_token(const struct sieve_lexer *lexer) +bool sieve_lexer_skip_token(const struct sieve_lexer *lexer) { /* Scan token while skipping whitespace */ - do { + do { if ( !sieve_lexer_scan_raw_token(lexer->scanner) ) return FALSE; } while ( lexer->token_type == STT_WHITESPACE ); - + return TRUE; } diff --git a/src/lib-sieve/sieve-lexer.h b/src/lib-sieve/sieve-lexer.h index f62429473228dce99556a163d78e2997bc931941..96888efb9826126133e4f1f4a9bd28615796a3ab 100644 --- a/src/lib-sieve/sieve-lexer.h +++ b/src/lib-sieve/sieve-lexer.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ #ifndef __SIEVE_LEXER_H @@ -13,12 +13,12 @@ enum sieve_token_type { STT_NONE, STT_WHITESPACE, STT_EOF, - + STT_NUMBER, STT_IDENTIFIER, STT_TAG, STT_STRING, - + STT_RBRACKET, STT_LBRACKET, STT_RCURLY, @@ -27,18 +27,18 @@ enum sieve_token_type { STT_LSQUARE, STT_SEMICOLON, STT_COMMA, - + /* These are currently not used in the lexical specification, but a token * is assigned to these to generate proper error messages (these are * technically not garbage and possibly part of mistyped but otherwise * valid tokens). */ - STT_SLASH, - STT_COLON, - + STT_SLASH, + STT_COLON, + /* Error tokens */ - STT_GARBAGE, /* Error reporting deferred to parser */ - STT_ERROR /* Lexer is responsible for error, parser won't report additional + STT_GARBAGE, /* Error reporting deferred to parser */ + STT_ERROR /* Lexer is responsible for error, parser won't report additional errors */ }; @@ -50,7 +50,7 @@ struct sieve_lexical_scanner; struct sieve_lexer { struct sieve_lexical_scanner *scanner; - + enum sieve_token_type token_type; string_t *token_str_value; int token_int_value; @@ -59,60 +59,60 @@ struct sieve_lexer { }; const struct sieve_lexer *sieve_lexer_create - (struct sieve_script *script, struct sieve_error_handler *ehandler, + (struct sieve_script *script, struct sieve_error_handler *ehandler, enum sieve_error *error_r); void sieve_lexer_free(const struct sieve_lexer **lexer); -/* - * Scanning +/* + * Scanning */ bool sieve_lexer_skip_token(const struct sieve_lexer *lexer); /* * Token access - */ + */ static inline enum sieve_token_type sieve_lexer_token_type -(const struct sieve_lexer *lexer) +(const struct sieve_lexer *lexer) { return lexer->token_type; } static inline const string_t *sieve_lexer_token_str -(const struct sieve_lexer *lexer) +(const struct sieve_lexer *lexer) { i_assert( lexer->token_type == STT_STRING ); - + return lexer->token_str_value; } static inline const char *sieve_lexer_token_ident -(const struct sieve_lexer *lexer) +(const struct sieve_lexer *lexer) { i_assert( lexer->token_type == STT_TAG || lexer->token_type == STT_IDENTIFIER); - + return str_c(lexer->token_str_value); } static inline int sieve_lexer_token_int -(const struct sieve_lexer *lexer) +(const struct sieve_lexer *lexer) { i_assert(lexer->token_type == STT_NUMBER); - + return lexer->token_int_value; } static inline bool sieve_lexer_eof -(const struct sieve_lexer *lexer) +(const struct sieve_lexer *lexer) { return lexer->token_type == STT_EOF; } static inline int sieve_lexer_token_line -(const struct sieve_lexer *lexer) +(const struct sieve_lexer *lexer) { return lexer->token_line; } diff --git a/src/lib-sieve/sieve-match-types.c b/src/lib-sieve/sieve-match-types.c index 694e9194060370326c12ac50fdcbc2f2d1ba3cbb..e4e76e102c9605298f9a77ee246189dda1ec90c6 100644 --- a/src/lib-sieve/sieve-match-types.c +++ b/src/lib-sieve/sieve-match-types.c @@ -1,6 +1,6 @@ /* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #include "lib.h" #include "compat.h" #include "mempool.h" @@ -26,26 +26,26 @@ /* * Types */ - + struct sieve_match_values { pool_t pool; ARRAY_DEFINE(values, string_t *); unsigned count; }; -/* +/* * Default match types - */ + */ const struct sieve_match_type_def *sieve_core_match_types[] = { &is_match_type, &contains_match_type, &matches_match_type }; -const unsigned int sieve_core_match_types_count = +const unsigned int sieve_core_match_types_count = N_ELEMENTS(sieve_core_match_types); -/* - * Match-type 'extension' +/* + * Match-type 'extension' */ static bool mtch_validator_load @@ -59,10 +59,10 @@ const struct sieve_extension_def match_type_extension = { SIEVE_EXT_DEFINE_NO_OPERATIONS, SIEVE_EXT_DEFINE_NO_OPERANDS }; - -/* + +/* * Validator context: - * name-based match-type registry. + * name-based match-type registry. */ static struct sieve_validator_object_registry *_get_object_registry @@ -75,18 +75,18 @@ static struct sieve_validator_object_registry *_get_object_registry mcht_ext = sieve_get_match_type_extension(svinst); return sieve_validator_object_registry_get(valdtr, mcht_ext); } - + void sieve_match_type_register (struct sieve_validator *valdtr, const struct sieve_extension *ext, - const struct sieve_match_type_def *mcht_def) + const struct sieve_match_type_def *mcht_def) { struct sieve_validator_object_registry *regs = _get_object_registry(valdtr); - + sieve_validator_object_registry_add(regs, ext, &mcht_def->obj_def); } static bool sieve_match_type_exists -(struct sieve_validator *valdtr, const char *identifier) +(struct sieve_validator *valdtr, const char *identifier) { struct sieve_validator_object_registry *regs = _get_object_registry(valdtr); @@ -94,8 +94,8 @@ static bool sieve_match_type_exists } static const struct sieve_match_type *sieve_match_type_create_instance -(struct sieve_validator *valdtr, struct sieve_command *cmd, - const char *identifier) +(struct sieve_validator *valdtr, struct sieve_command *cmd, + const char *identifier) { struct sieve_validator_object_registry *regs = _get_object_registry(valdtr); struct sieve_object object; @@ -114,7 +114,7 @@ static const struct sieve_match_type *sieve_match_type_create_instance bool mtch_validator_load (const struct sieve_extension *ext, struct sieve_validator *valdtr) { - struct sieve_validator_object_registry *regs = + struct sieve_validator_object_registry *regs = sieve_validator_object_registry_init(valdtr, ext); unsigned int i; @@ -127,7 +127,7 @@ bool mtch_validator_load return TRUE; } -/* +/* * Interpreter context */ @@ -137,12 +137,12 @@ struct mtch_interpreter_context { }; static void mtch_interpreter_free -(const struct sieve_extension *ext ATTR_UNUSED, +(const struct sieve_extension *ext ATTR_UNUSED, struct sieve_interpreter *interp ATTR_UNUSED, void *context) { - struct mtch_interpreter_context *mctx = + struct mtch_interpreter_context *mctx = (struct mtch_interpreter_context *) context; - + if ( mctx->match_values != NULL ) { pool_unref(&mctx->match_values->pool); } @@ -168,7 +168,7 @@ static inline struct mtch_interpreter_context *get_interpreter_context sieve_interpreter_extension_get_context(interp, mcht_ext); if ( ctx == NULL && create ) { - pool_t pool = sieve_interpreter_pool(interp); + pool_t pool = sieve_interpreter_pool(interp); ctx = p_new(pool, struct mtch_interpreter_context, 1); sieve_interpreter_extension_register @@ -185,58 +185,58 @@ static inline struct mtch_interpreter_context *get_interpreter_context bool sieve_match_values_set_enabled (const struct sieve_runtime_env *renv, bool enable) { - struct mtch_interpreter_context *ctx = + struct mtch_interpreter_context *ctx = get_interpreter_context(renv->interp, enable); - + if ( ctx != NULL ) { bool previous = ctx->match_values_enabled; - + ctx->match_values_enabled = enable; return previous; } - + return FALSE; } bool sieve_match_values_are_enabled (const struct sieve_runtime_env *renv) { - struct mtch_interpreter_context *ctx = + struct mtch_interpreter_context *ctx = get_interpreter_context(renv->interp, FALSE); - + return ( ctx == NULL ? FALSE : ctx->match_values_enabled ); } struct sieve_match_values *sieve_match_values_start (const struct sieve_runtime_env *renv) { - struct mtch_interpreter_context *ctx = + struct mtch_interpreter_context *ctx = get_interpreter_context(renv->interp, FALSE); struct sieve_match_values *match_values; - + if ( ctx == NULL || !ctx->match_values_enabled ) return NULL; - + pool_t pool = pool_alloconly_create("sieve_match_values", 1024); - + match_values = p_new(pool, struct sieve_match_values, 1); match_values->pool = pool; match_values->count = 0; - + p_array_init(&match_values->values, pool, 4); return match_values; } static string_t *sieve_match_values_add_entry -(struct sieve_match_values *mvalues) +(struct sieve_match_values *mvalues) { string_t *entry; - - if ( mvalues == NULL ) return NULL; + + if ( mvalues == NULL ) return NULL; if ( mvalues->count >= SIEVE_MAX_MATCH_VALUES ) return NULL; - + if ( mvalues->count >= array_count(&mvalues->values) ) { entry = str_new(mvalues->pool, 64); array_append(&mvalues->values, &entry, 1); } else { @@ -244,7 +244,7 @@ static string_t *sieve_match_values_add_entry entry = *ep; str_truncate(entry, 0); } - + mvalues->count++; return entry; @@ -263,45 +263,45 @@ void sieve_match_values_set } } } - + void sieve_match_values_add -(struct sieve_match_values *mvalues, string_t *value) +(struct sieve_match_values *mvalues, string_t *value) { - string_t *entry = sieve_match_values_add_entry(mvalues); + string_t *entry = sieve_match_values_add_entry(mvalues); if ( entry != NULL && value != NULL ) str_append_str(entry, value); } void sieve_match_values_add_char -(struct sieve_match_values *mvalues, char c) +(struct sieve_match_values *mvalues, char c) { - string_t *entry = sieve_match_values_add_entry(mvalues); + string_t *entry = sieve_match_values_add_entry(mvalues); if ( entry != NULL ) str_append_c(entry, c); } void sieve_match_values_skip -(struct sieve_match_values *mvalues, int num) +(struct sieve_match_values *mvalues, int num) { int i; - + for ( i = 0; i < num; i++ ) - (void) sieve_match_values_add_entry(mvalues); + (void) sieve_match_values_add_entry(mvalues); } void sieve_match_values_commit (const struct sieve_runtime_env *renv, struct sieve_match_values **mvalues) { struct mtch_interpreter_context *ctx; - + if ( (*mvalues) == NULL ) return; - + ctx = get_interpreter_context(renv->interp, FALSE); if ( ctx == NULL || !ctx->match_values_enabled ) - return; - + return; + if ( ctx->match_values != NULL ) { pool_unref(&ctx->match_values->pool); ctx->match_values = NULL; @@ -313,17 +313,17 @@ void sieve_match_values_commit void sieve_match_values_abort (struct sieve_match_values **mvalues) -{ +{ if ( (*mvalues) == NULL ) return; - + pool_unref(&(*mvalues)->pool); *mvalues = NULL; } void sieve_match_values_get -(const struct sieve_runtime_env *renv, unsigned int index, string_t **value_r) +(const struct sieve_runtime_env *renv, unsigned int index, string_t **value_r) { - struct mtch_interpreter_context *ctx = + struct mtch_interpreter_context *ctx = get_interpreter_context(renv->interp, FALSE); struct sieve_match_values *mvalues; @@ -331,49 +331,49 @@ void sieve_match_values_get *value_r = NULL; return; } - + mvalues = ctx->match_values; if ( index < array_count(&mvalues->values) && index < mvalues->count ) { string_t * const *entry = array_idx(&mvalues->values, index); - + *value_r = *entry; return; } - *value_r = NULL; + *value_r = NULL; } -/* - * Match-type tagged argument +/* + * Match-type tagged argument */ - + /* Forward declarations */ static bool tag_match_type_is_instance_of - (struct sieve_validator *valdtr, struct sieve_command *cmd, + (struct sieve_validator *valdtr, struct sieve_command *cmd, const struct sieve_extension *ext, const char *identifier, void **data); static bool tag_match_type_validate - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); static bool tag_match_type_generate - (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, + (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *cmd); /* Argument object */ - -const struct sieve_argument_def match_type_tag = { + +const struct sieve_argument_def match_type_tag = { "MATCH-TYPE", tag_match_type_is_instance_of, - tag_match_type_validate, + tag_match_type_validate, NULL, NULL, - tag_match_type_generate + tag_match_type_generate }; /* Argument implementation */ static bool tag_match_type_is_instance_of -(struct sieve_validator *valdtr, struct sieve_command *cmd, - const struct sieve_extension *ext ATTR_UNUSED, const char *identifier, +(struct sieve_validator *valdtr, struct sieve_command *cmd, + const struct sieve_extension *ext ATTR_UNUSED, const char *identifier, void **data) { const struct sieve_match_type *mcht; @@ -384,16 +384,16 @@ static bool tag_match_type_is_instance_of if ( (mcht=sieve_match_type_create_instance (valdtr, cmd, identifier)) == NULL ) return FALSE; - + *data = (void *) mcht; return TRUE; } - + static bool tag_match_type_validate -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd ATTR_UNUSED) { - const struct sieve_match_type *mcht = + const struct sieve_match_type *mcht = (const struct sieve_match_type *) (*arg)->argument->data; struct sieve_match_type_context *mtctx; @@ -404,40 +404,40 @@ static bool tag_match_type_validate (*arg)->argument->data = mtctx; - /* Syntax: + /* Syntax: * ":is" / ":contains" / ":matches" (subject to extension) */ - + /* Skip tag */ *arg = sieve_ast_argument_next(*arg); - - /* Check whether this match type requires additional validation. - * Additional validation can override the match type recorded in the context - * for later code generation. + + /* Check whether this match type requires additional validation. + * Additional validation can override the match type recorded in the context + * for later code generation. */ if ( mcht->def != NULL && mcht->def->validate != NULL ) { return mcht->def->validate(valdtr, arg, mtctx); } - + return TRUE; } static bool tag_match_type_generate -(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, +(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *cmd ATTR_UNUSED) { struct sieve_match_type_context *mtctx = (struct sieve_match_type_context *) arg->argument->data; - + (void) sieve_opr_match_type_emit(cgenv->sblock, mtctx->match_type); - + return TRUE; } void sieve_match_types_link_tags -(struct sieve_validator *valdtr, - struct sieve_command_registration *cmd_reg, int id_code) -{ +(struct sieve_validator *valdtr, + struct sieve_command_registration *cmd_reg, int id_code) +{ struct sieve_instance *svinst; const struct sieve_extension *mcht_ext; @@ -445,7 +445,7 @@ void sieve_match_types_link_tags mcht_ext = sieve_get_comparator_extension(svinst); sieve_validator_register_tag - (valdtr, cmd_reg, mcht_ext, &match_type_tag, id_code); + (valdtr, cmd_reg, mcht_ext, &match_type_tag, id_code); } /* @@ -454,8 +454,8 @@ void sieve_match_types_link_tags bool sieve_match_type_validate (struct sieve_validator *valdtr, struct sieve_command *cmd, - struct sieve_ast_argument *key_arg, - const struct sieve_match_type *mcht_default, + struct sieve_ast_argument *key_arg, + const struct sieve_match_type *mcht_default, const struct sieve_comparator *cmp_default) { struct sieve_ast_argument *arg = sieve_command_first_argument(cmd); @@ -477,14 +477,14 @@ bool sieve_match_type_validate } arg = sieve_ast_argument_next(arg); } - + /* Verify using the default comparator if none is specified explicitly */ if ( cmp == NULL ) { cmp = sieve_comparator_copy(sieve_command_pool(cmd), cmp_default); } - + /* Verify the default match type if none is specified explicitly */ - if ( mt_arg == NULL || mt_arg->argument == NULL || + if ( mt_arg == NULL || mt_arg->argument == NULL || mt_arg->argument->data == NULL ) { mtctx = NULL; mcht = sieve_match_type_copy(sieve_command_pool(cmd), mcht_default); @@ -494,16 +494,16 @@ bool sieve_match_type_validate mtctx->comparator = cmp; } - /* Check whether this match type requires additional validation. - * Additional validation can override the match type recorded in the context - * for later code generation. + /* Check whether this match type requires additional validation. + * Additional validation can override the match type recorded in the context + * for later code generation. */ if ( mcht != NULL && mcht->def != NULL && mcht->def->validate_context != NULL ) { return mcht->def->validate_context(valdtr, mt_arg, mtctx, key_arg); } - - return TRUE; + + return TRUE; } void sieve_match_type_arguments_remove @@ -531,15 +531,15 @@ void sieve_match_type_arguments_remove /* * Match-type operand */ - -const struct sieve_operand_class sieve_match_type_operand_class = + +const struct sieve_operand_class sieve_match_type_operand_class = { "match type" }; - + static const struct sieve_extension_objects core_match_types = SIEVE_EXT_DEFINE_MATCH_TYPES(sieve_core_match_types); -const struct sieve_operand_def match_type_operand = { - "match-type", +const struct sieve_operand_def match_type_operand = { + "match-type", NULL, SIEVE_OPERAND_MATCH_TYPE, &sieve_match_type_operand_class, @@ -556,10 +556,10 @@ bool sieve_match_substring_validate_context struct sieve_ast_argument *key_arg ATTR_UNUSED) { const struct sieve_comparator *cmp = ctx->comparator; - + if ( cmp == NULL || cmp->def == NULL ) return TRUE; - + if ( (cmp->def->flags & SIEVE_COMPARATOR_FLAG_SUBSTRING_MATCH) == 0 ) { sieve_argument_validate_error(valdtr, arg, "the specified %s comparator does not support " @@ -568,6 +568,6 @@ bool sieve_match_substring_validate_context return FALSE; } - + return TRUE; -} +} diff --git a/src/lib-sieve/sieve-match-types.h b/src/lib-sieve/sieve-match-types.h index 0e0805159722a9a5956c52a7efb1bbdae1d63dd4..1da010e3e75b49beaea0545887a021769b2ac746 100644 --- a/src/lib-sieve/sieve-match-types.h +++ b/src/lib-sieve/sieve-match-types.h @@ -1,6 +1,6 @@ /* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #ifndef __SIEVE_MATCH_TYPES_H #define __SIEVE_MATCH_TYPES_H @@ -17,9 +17,9 @@ struct sieve_match_type_context; /* - * Core match types + * Core match types */ - + enum sieve_match_type_code { SIEVE_MATCH_TYPE_IS, SIEVE_MATCH_TYPE_CONTAINS, @@ -34,17 +34,17 @@ extern const struct sieve_match_type_def matches_match_type; /* * Match type definition */ - + struct sieve_match_type_def { struct sieve_object_def obj_def; - + bool (*validate) - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_match_type_context *ctx); bool (*validate_context) - (struct sieve_validator *valdtr, struct sieve_ast_argument *arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument *arg, struct sieve_match_type_context *ctx, struct sieve_ast_argument *key_arg); - + /* * Matching */ @@ -55,28 +55,28 @@ struct sieve_match_type_def { (struct sieve_match_context *mctx, struct sieve_stringlist *value_list, struct sieve_stringlist *key_list); - /* Default match loop */ + /* Default match loop */ void (*match_init)(struct sieve_match_context *mctx); int (*match_keys) - (struct sieve_match_context *mctx, const char *val, size_t val_size, + (struct sieve_match_context *mctx, const char *val, size_t val_size, struct sieve_stringlist *key_list); int (*match_key) - (struct sieve_match_context *mctx, const char *val, size_t val_size, + (struct sieve_match_context *mctx, const char *val, size_t val_size, const char *key, size_t key_size); void (*match_deinit)(struct sieve_match_context *mctx); }; -/* +/* * Match type instance */ struct sieve_match_type { struct sieve_object object; - const struct sieve_match_type_def *def; + const struct sieve_match_type_def *def; }; #define SIEVE_MATCH_TYPE_DEFAULT(definition) \ @@ -85,7 +85,7 @@ struct sieve_match_type { #define sieve_match_type_name(mcht) \ ( (mcht)->object.def->identifier ) #define sieve_match_type_is(mcht, definition) \ - ( (mcht)->def == &(definition) ) + ( (mcht)->def == &(definition) ) static inline const struct sieve_match_type *sieve_match_type_copy (pool_t pool, const struct sieve_match_type *cmp_orig) @@ -106,12 +106,12 @@ struct sieve_match_type_context { struct sieve_ast_argument *argument; const struct sieve_match_type *match_type; - + /* Only filled in when match_type->validate_context() is called */ const struct sieve_comparator *comparator; - + /* Context data could be used in the future to pass data between validator and - * generator in match types that use extra parameters. Currently not + * generator in match types that use extra parameters. Currently not * necessary, not even for the relational extension. */ void *ctx_data; @@ -125,8 +125,8 @@ void sieve_match_type_register (struct sieve_validator *valdtr, const struct sieve_extension *ext, const struct sieve_match_type_def *mcht); -/* - * Match values +/* + * Match values */ struct sieve_match_values; @@ -134,8 +134,8 @@ struct sieve_match_values; bool sieve_match_values_set_enabled (const struct sieve_runtime_env *renv, bool enable); bool sieve_match_values_are_enabled - (const struct sieve_runtime_env *renv); - + (const struct sieve_runtime_env *renv); + struct sieve_match_values *sieve_match_values_start (const struct sieve_runtime_env *renv); void sieve_match_values_set @@ -143,20 +143,20 @@ void sieve_match_values_set void sieve_match_values_add (struct sieve_match_values *mvalues, string_t *value); void sieve_match_values_add_char - (struct sieve_match_values *mvalues, char c); + (struct sieve_match_values *mvalues, char c); void sieve_match_values_skip (struct sieve_match_values *mvalues, int num); - + void sieve_match_values_commit (const struct sieve_runtime_env *renv, struct sieve_match_values **mvalues); void sieve_match_values_abort (struct sieve_match_values **mvalues); - + void sieve_match_values_get (const struct sieve_runtime_env *renv, unsigned int index, string_t **value_r); /* - * Match type tagged argument + * Match type tagged argument */ extern const struct sieve_argument_def match_type_tag; @@ -168,7 +168,7 @@ static inline bool sieve_argument_is_match_type } void sieve_match_types_link_tags - (struct sieve_validator *valdtr, + (struct sieve_validator *valdtr, struct sieve_command_registration *cmd_reg, int id_code); /* @@ -177,8 +177,8 @@ void sieve_match_types_link_tags bool sieve_match_type_validate (struct sieve_validator *valdtr, struct sieve_command *cmd, - struct sieve_ast_argument *key_arg, - const struct sieve_match_type *mcht_default, + struct sieve_ast_argument *key_arg, + const struct sieve_match_type *mcht_default, const struct sieve_comparator *cmp_default); void sieve_match_type_arguments_remove @@ -187,7 +187,7 @@ void sieve_match_type_arguments_remove /* * Match type operand */ - + extern const struct sieve_operand_def match_type_operand; extern const struct sieve_operand_class sieve_match_type_operand_class; @@ -203,7 +203,7 @@ static inline bool sieve_operand_is_match_type static inline void sieve_opr_match_type_emit (struct sieve_binary_block *sblock, const struct sieve_match_type *mcht) -{ +{ sieve_opr_object_emit(sblock, mcht->object.ext, mcht->object.def); } @@ -230,7 +230,7 @@ static inline int sieve_opr_match_type_read bool sieve_match_substring_validate_context (struct sieve_validator *valdtr, struct sieve_ast_argument *arg, - struct sieve_match_type_context *ctx, + struct sieve_match_type_context *ctx, struct sieve_ast_argument *key_arg); #endif /* __SIEVE_MATCH_TYPES_H */ diff --git a/src/lib-sieve/sieve-match.c b/src/lib-sieve/sieve-match.c index 2ae303b92687fc3ba8d6e2534b0b1c70c5fb2a1e..c014ed1e88a1f960c110a469fe58090239c191a1 100644 --- a/src/lib-sieve/sieve-match.c +++ b/src/lib-sieve/sieve-match.c @@ -28,20 +28,20 @@ struct sieve_match_context *sieve_match_begin (const struct sieve_runtime_env *renv, - const struct sieve_match_type *mcht, + const struct sieve_match_type *mcht, const struct sieve_comparator *cmp) { struct sieve_match_context *mctx; pool_t pool; /* Reject unimplemented match-type */ - if ( mcht->def == NULL || (mcht->def->match == NULL && + if ( mcht->def == NULL || (mcht->def->match == NULL && mcht->def->match_keys == NULL && mcht->def->match_key == NULL) ) return NULL; /* Create match context */ pool = pool_alloconly_create("sieve_match_context", 1024); - mctx = p_new(pool, struct sieve_match_context, 1); + mctx = p_new(pool, struct sieve_match_context, 1); mctx->pool = pool; mctx->runenv = renv; mctx->match_type = mcht; @@ -79,7 +79,7 @@ int sieve_match_value } /* Match to key values */ - + sieve_stringlist_reset(key_list); if ( mctx->trace ) @@ -95,8 +95,8 @@ int sieve_match_value /* Default key match loop */ match = 0; - while ( match == 0 && - (ret=sieve_stringlist_next_item(key_list, &key_item)) > 0 ) { + while ( match == 0 && + (ret=sieve_stringlist_next_item(key_list, &key_item)) > 0 ) { T_BEGIN { match = mcht->def->match_key (mctx, value, value_size, str_c(key_item), str_len(key_item)); @@ -119,8 +119,8 @@ int sieve_match_value if ( mctx->match_status < 0 || match < 0 ) mctx->match_status = -1; - else - mctx->match_status = + else + mctx->match_status = ( mctx->match_status > match ? mctx->match_status : match ); return match; } @@ -140,7 +140,7 @@ int sieve_match_end(struct sieve_match_context **mctx, int *exec_status) pool_unref(&(*mctx)->pool); sieve_runtime_trace(renv, SIEVE_TRLVL_MATCHING, - "finishing match with result: %s", + "finishing match with result: %s", ( match > 0 ? "matched" : ( match < 0 ? "error" : "not matched" ) )); sieve_runtime_trace_ascend(renv); @@ -149,10 +149,10 @@ int sieve_match_end(struct sieve_match_context **mctx, int *exec_status) int sieve_match (const struct sieve_runtime_env *renv, - const struct sieve_match_type *mcht, - const struct sieve_comparator *cmp, + const struct sieve_match_type *mcht, + const struct sieve_comparator *cmp, struct sieve_stringlist *value_list, - struct sieve_stringlist *key_list, + struct sieve_stringlist *key_list, int *exec_status) { struct sieve_match_context *mctx; @@ -171,14 +171,14 @@ int sieve_match if ( mcht->def->match != NULL ) { /* Call match-type's match handler */ - match = mctx->match_status = - mcht->def->match(mctx, value_list, key_list); + match = mctx->match_status = + mcht->def->match(mctx, value_list, key_list); } else { /* Default value match loop */ match = 0; - while ( match == 0 && + while ( match == 0 && (ret=sieve_stringlist_next_item(value_list, &value_item)) > 0 ) { match = sieve_match_value @@ -198,7 +198,7 @@ int sieve_match /* * Reading match operands */ - + int sieve_match_opr_optional_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address, int *opt_code) { @@ -245,14 +245,14 @@ int sieve_match_opr_optional_read } if ( exec_status != NULL ) - *exec_status = SIEVE_EXEC_OK; + *exec_status = SIEVE_EXEC_OK; while ( status == SIEVE_EXEC_OK ) { int opt; if ( (opt=sieve_opr_optional_read(renv, address, opt_code)) <= 0 ){ if ( opt < 0 && exec_status != NULL ) - *exec_status = SIEVE_EXEC_BIN_CORRUPT; + *exec_status = SIEVE_EXEC_BIN_CORRUPT; return opt; } @@ -275,7 +275,7 @@ int sieve_match_opr_optional_read } if ( exec_status != NULL ) - *exec_status = status; + *exec_status = status; return -1; } diff --git a/src/lib-sieve/sieve-match.h b/src/lib-sieve/sieve-match.h index 5b08fe853248b01995ff76043426bb4498a10148..f06f55086fc0a7d7cf4342860aee1ba72183753d 100644 --- a/src/lib-sieve/sieve-match.h +++ b/src/lib-sieve/sieve-match.h @@ -1,6 +1,6 @@ /* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #ifndef __SIEVE_MATCH_H #define __SIEVE_MATCH_H @@ -33,7 +33,7 @@ struct sieve_match_context { /* Manual value iteration (for when multiple matches are allowed) */ struct sieve_match_context *sieve_match_begin (const struct sieve_runtime_env *renv, - const struct sieve_match_type *mcht, + const struct sieve_match_type *mcht, const struct sieve_comparator *cmp); int sieve_match_value (struct sieve_match_context *mctx, const char *value, size_t value_size, @@ -43,8 +43,8 @@ int sieve_match_end(struct sieve_match_context **mctx, int *exec_status); /* Default matching operation */ int sieve_match (const struct sieve_runtime_env *renv, - const struct sieve_match_type *mcht, - const struct sieve_comparator *cmp, + const struct sieve_match_type *mcht, + const struct sieve_comparator *cmp, struct sieve_stringlist *value_list, struct sieve_stringlist *key_list, int *exec_status); @@ -52,7 +52,7 @@ int sieve_match /* * Read matching operands */ - + enum sieve_match_opt_operand { SIEVE_MATCH_OPT_END, SIEVE_MATCH_OPT_COMPARATOR, @@ -65,7 +65,7 @@ int sieve_match_opr_optional_dump int sieve_match_opr_optional_read (const struct sieve_runtime_env *renv, sieve_size_t *address, int *opt_code, - int *exec_status, struct sieve_comparator *cmp, + int *exec_status, struct sieve_comparator *cmp, struct sieve_match_type *mcht); #endif /* __SIEVE_MATCH_H */ diff --git a/src/lib-sieve/sieve-message.c b/src/lib-sieve/sieve-message.c index 242611dc775344c1ff7d2f8048bd432ad8e40ec2..fe9bf53e250b7f18837b18f3255c01388fc5b3e2 100644 --- a/src/lib-sieve/sieve-message.c +++ b/src/lib-sieve/sieve-message.c @@ -29,18 +29,18 @@ /* * Message transmission */ - + const char *sieve_message_get_new_id(const struct sieve_instance *svinst) { static int count = 0; - + return t_strdup_printf("<dovecot-sieve-%s-%s-%d@%s>", dec2str(ioloop_timeval.tv_sec), dec2str(ioloop_timeval.tv_usec), count++, svinst->hostname); } -/* - * Message context +/* + * Message context */ struct sieve_message_version { @@ -55,7 +55,7 @@ struct sieve_message_context { pool_t context_pool; int refcount; - struct sieve_instance *svinst; + struct sieve_instance *svinst; struct mail_user *mail_user; const struct sieve_message_data *msgdata; @@ -99,7 +99,7 @@ static inline struct sieve_message_version *sieve_message_version_get versions = array_get_modifiable(&msgctx->versions, &count); if ( count == 0 ) return array_append_space(&msgctx->versions); - + return &versions[count-1]; } @@ -168,12 +168,12 @@ static void sieve_message_context_clear(struct sieve_message_context *msgctx) } void sieve_message_context_unref(struct sieve_message_context **msgctx) -{ +{ i_assert((*msgctx)->refcount > 0); if (--(*msgctx)->refcount != 0) return; - + if ( (*msgctx)->raw_mail_user != NULL ) mail_user_unref(&(*msgctx)->raw_mail_user); @@ -190,11 +190,11 @@ static void sieve_message_context_flush(struct sieve_message_context *msgctx) { if ( msgctx->context_pool != NULL ) pool_unref(&(msgctx->context_pool)); - + msgctx->context_pool = pool_alloconly_create("sieve_message_context_data", 1024); - p_array_init(&msgctx->ext_contexts, msgctx->context_pool, + p_array_init(&msgctx->ext_contexts, msgctx->context_pool, sieve_extensions_get_count(msgctx->svinst)); } @@ -217,23 +217,23 @@ pool_t sieve_message_context_pool(struct sieve_message_context *msgctx) /* Extension support */ void sieve_message_context_extension_set -(struct sieve_message_context *msgctx, const struct sieve_extension *ext, +(struct sieve_message_context *msgctx, const struct sieve_extension *ext, void *context) { if ( ext->id < 0 ) return; - array_idx_set(&msgctx->ext_contexts, (unsigned int) ext->id, &context); + array_idx_set(&msgctx->ext_contexts, (unsigned int) ext->id, &context); } const void *sieve_message_context_extension_get -(struct sieve_message_context *msgctx, const struct sieve_extension *ext) +(struct sieve_message_context *msgctx, const struct sieve_extension *ext) { void * const *ctx; if ( ext->id < 0 || ext->id >= (int) array_count(&msgctx->ext_contexts) ) return NULL; - - ctx = array_idx(&msgctx->ext_contexts, (unsigned int) ext->id); + + ctx = array_idx(&msgctx->ext_contexts, (unsigned int) ext->id); return *ctx; } @@ -248,27 +248,27 @@ static void sieve_message_envelope_parse(struct sieve_message_context *msgctx) /* FIXME: log parse problems properly; logs only 'failure' now */ msgctx->envelope_orig_recipient = sieve_address_parse_envelope_path - (msgctx->pool, msgdata->orig_envelope_to); + (msgctx->pool, msgdata->orig_envelope_to); if ( msgctx->envelope_orig_recipient == NULL ) { sieve_sys_error(svinst, "original envelope recipient address '%s' is unparsable", - msgdata->orig_envelope_to); + msgdata->orig_envelope_to); } else if ( msgctx->envelope_orig_recipient->local_part == NULL ) { sieve_sys_error(svinst, "original envelope recipient address '%s' is a null path", msgdata->orig_envelope_to); - } + } msgctx->envelope_final_recipient = sieve_address_parse_envelope_path - (msgctx->pool, msgdata->final_envelope_to); - + (msgctx->pool, msgdata->final_envelope_to); + if ( msgctx->envelope_final_recipient == NULL ) { if ( msgctx->envelope_orig_recipient != NULL ) { sieve_sys_error(svinst, "final envelope recipient address '%s' is unparsable", msgdata->final_envelope_to); - } + } } else if ( msgctx->envelope_final_recipient->local_part == NULL ) { if ( strcmp(msgdata->orig_envelope_to, msgdata->final_envelope_to) != 0 ) { sieve_sys_error(svinst, @@ -278,11 +278,11 @@ static void sieve_message_envelope_parse(struct sieve_message_context *msgctx) } msgctx->envelope_sender = sieve_address_parse_envelope_path - (msgctx->pool, msgdata->return_path); + (msgctx->pool, msgdata->return_path); if ( msgctx->envelope_sender == NULL ) { - sieve_sys_error(svinst, - "envelope sender address '%s' is unparsable", + sieve_sys_error(svinst, + "envelope sender address '%s' is unparsable", msgdata->return_path); } @@ -292,7 +292,7 @@ static void sieve_message_envelope_parse(struct sieve_message_context *msgctx) const struct sieve_address *sieve_message_get_orig_recipient_address (struct sieve_message_context *msgctx) { - if ( !msgctx->envelope_parsed ) + if ( !msgctx->envelope_parsed ) sieve_message_envelope_parse(msgctx); return msgctx->envelope_orig_recipient; @@ -301,7 +301,7 @@ const struct sieve_address *sieve_message_get_orig_recipient_address const struct sieve_address *sieve_message_get_final_recipient_address (struct sieve_message_context *msgctx) { - if ( !msgctx->envelope_parsed ) + if ( !msgctx->envelope_parsed ) sieve_message_envelope_parse(msgctx); return msgctx->envelope_final_recipient; @@ -310,16 +310,16 @@ const struct sieve_address *sieve_message_get_final_recipient_address const struct sieve_address *sieve_message_get_sender_address (struct sieve_message_context *msgctx) { - if ( !msgctx->envelope_parsed ) + if ( !msgctx->envelope_parsed ) sieve_message_envelope_parse(msgctx); - return msgctx->envelope_sender; -} + return msgctx->envelope_sender; +} const char *sieve_message_get_orig_recipient (struct sieve_message_context *msgctx) { - if ( !msgctx->envelope_parsed ) + if ( !msgctx->envelope_parsed ) sieve_message_envelope_parse(msgctx); return sieve_address_to_string(msgctx->envelope_orig_recipient); @@ -328,7 +328,7 @@ const char *sieve_message_get_orig_recipient const char *sieve_message_get_final_recipient (struct sieve_message_context *msgctx) { - if ( !msgctx->envelope_parsed ) + if ( !msgctx->envelope_parsed ) sieve_message_envelope_parse(msgctx); return sieve_address_to_string(msgctx->envelope_final_recipient); @@ -337,7 +337,7 @@ const char *sieve_message_get_final_recipient const char *sieve_message_get_sender (struct sieve_message_context *msgctx) { - if ( !msgctx->envelope_parsed ) + if ( !msgctx->envelope_parsed ) sieve_message_envelope_parse(msgctx); return sieve_address_to_string(msgctx->envelope_sender); @@ -379,7 +379,7 @@ int sieve_message_substitute if ( msgctx->substitute_snapshot ) { version = sieve_message_version_new(msgctx); } else { - version = sieve_message_version_get(msgctx); + version = sieve_message_version_get(msgctx); sieve_message_version_free(version); } @@ -403,8 +403,8 @@ struct mail *sieve_message_get_mail { const struct sieve_message_version *versions; unsigned int count; - - versions = array_get(&msgctx->versions, &count); + + versions = array_get(&msgctx->versions, &count); if ( count == 0 ) return msgctx->msgdata->mail; @@ -424,13 +424,13 @@ struct edit_mail *sieve_message_edit if ( version->edit_mail == NULL ) { version->edit_mail = edit_mail_wrap (( version->mail == NULL ? msgctx->msgdata->mail : version->mail )); - } else if ( msgctx->edit_snapshot ) { - version->edit_mail = edit_mail_snapshot(version->edit_mail); + } else if ( msgctx->edit_snapshot ) { + version->edit_mail = edit_mail_snapshot(version->edit_mail); } msgctx->edit_snapshot = FALSE; - return version->edit_mail; + return version->edit_mail; } void sieve_message_snapshot @@ -481,15 +481,15 @@ struct sieve_stringlist *sieve_message_header_stringlist_create return &strlist->strlist; } -static inline string_t *_header_right_trim(const char *raw) +static inline string_t *_header_right_trim(const char *raw) { string_t *result; int i; - + for ( i = strlen(raw)-1; i >= 0; i-- ) { if ( raw[i] != ' ' && raw[i] != '\t' ) break; } - + result = t_str_new(i+1); str_append_n(result, raw, i + 1); return result; @@ -500,7 +500,7 @@ static inline string_t *_header_right_trim(const char *raw) static int sieve_message_header_stringlist_next_item (struct sieve_stringlist *_strlist, string_t **str_r) { - struct sieve_message_header_stringlist *strlist = + struct sieve_message_header_stringlist *strlist = (struct sieve_message_header_stringlist *) _strlist; const struct sieve_runtime_env *renv = _strlist->runenv; struct mail *mail = sieve_message_get_mail(renv->msgctx); @@ -521,7 +521,7 @@ static int sieve_message_header_stringlist_next_item int ret; /* Read next header name from source list */ - if ( (ret=sieve_stringlist_next_item(strlist->field_names, &hdr_item)) + if ( (ret=sieve_stringlist_next_item(strlist->field_names, &hdr_item)) <= 0 ) return ret; @@ -557,7 +557,7 @@ static int sieve_message_header_stringlist_next_item static void sieve_message_header_stringlist_reset (struct sieve_stringlist *_strlist) { - struct sieve_message_header_stringlist *strlist = + struct sieve_message_header_stringlist *strlist = (struct sieve_message_header_stringlist *) _strlist; strlist->headers = NULL; diff --git a/src/lib-sieve/sieve-message.h b/src/lib-sieve/sieve-message.h index 4fc1549b6bd424c0dd1e32dc2af73e7b19d71314..b0f62a55830fcc97b8476cbd42635aabd1e40264 100644 --- a/src/lib-sieve/sieve-message.h +++ b/src/lib-sieve/sieve-message.h @@ -4,14 +4,14 @@ #ifndef __SIEVE_MESSAGE_H #define __SIEVE_MESSAGE_H -/* +/* * Message transmission */ const char *sieve_message_get_new_id(const struct sieve_instance *svinst); -/* - * Message context +/* + * Message context */ struct sieve_message_context; @@ -30,7 +30,7 @@ pool_t sieve_message_context_pool /* Extension support */ void sieve_message_context_extension_set - (struct sieve_message_context *msgctx, const struct sieve_extension *ext, + (struct sieve_message_context *msgctx, const struct sieve_extension *ext, void *context); const void *sieve_message_context_extension_get (struct sieve_message_context *msgctx, const struct sieve_extension *ext); diff --git a/src/lib-sieve/sieve-objects.c b/src/lib-sieve/sieve-objects.c index f6ad1291762731b37422f6e411f09d5c1ba3e82d..69b6b854770ca6303b25ed2c95bee57172f13fca 100644 --- a/src/lib-sieve/sieve-objects.c +++ b/src/lib-sieve/sieve-objects.c @@ -18,14 +18,14 @@ void sieve_opr_object_emit (struct sieve_binary_block *sblock, const struct sieve_extension *ext, const struct sieve_object_def *obj_def) { - struct sieve_extension_objects *objs = + struct sieve_extension_objects *objs = (struct sieve_extension_objects *) obj_def->operand->interface; - + (void) sieve_operand_emit(sblock, ext, obj_def->operand); - - if ( objs->count > 1 ) { + + if ( objs->count > 1 ) { (void) sieve_binary_emit_byte(sblock, obj_def->code); - } + } } bool sieve_opr_object_read_data @@ -34,63 +34,63 @@ bool sieve_opr_object_read_data struct sieve_object *obj) { const struct sieve_extension_objects *objs; - unsigned int obj_code; + unsigned int obj_code; if ( operand == NULL || operand->def->class != opclass ) return FALSE; - + objs = (struct sieve_extension_objects *) operand->def->interface; - if ( objs == NULL ) + if ( objs == NULL ) return FALSE; - + if ( objs->count > 1 ) { - if ( !sieve_binary_read_byte(sblock, address, &obj_code) ) + if ( !sieve_binary_read_byte(sblock, address, &obj_code) ) return FALSE; if ( obj_code < objs->count ) { - const struct sieve_object_def *const *objects = + const struct sieve_object_def *const *objects = (const struct sieve_object_def *const *) objs->objects; obj->def = objects[obj_code]; obj->ext = operand->ext; - return TRUE; + return TRUE; } } - - obj->def = (const struct sieve_object_def *) objs->objects; + + obj->def = (const struct sieve_object_def *) objs->objects; obj->ext = operand->ext; return TRUE; } bool sieve_opr_object_read -(const struct sieve_runtime_env *renv, +(const struct sieve_runtime_env *renv, const struct sieve_operand_class *opclass, sieve_size_t *address, struct sieve_object *obj) { - struct sieve_operand operand; + struct sieve_operand operand; if ( !sieve_operand_read(renv->sblock, address, NULL, &operand) ) { return FALSE; } - + return sieve_opr_object_read_data (renv->sblock, &operand, opclass, address, obj); } bool sieve_opr_object_dump -(const struct sieve_dumptime_env *denv, +(const struct sieve_dumptime_env *denv, const struct sieve_operand_class *opclass, sieve_size_t *address, struct sieve_object *obj) { struct sieve_operand operand; struct sieve_object obj_i; const char *class; - + if ( obj == NULL ) obj = &obj_i; sieve_code_mark(denv); - + if ( !sieve_operand_read(denv->sblock, address, NULL, &operand) ) { return FALSE; } @@ -98,14 +98,14 @@ bool sieve_opr_object_dump if ( !sieve_opr_object_read_data (denv->sblock, &operand, opclass, address, obj) ) return FALSE; - + if ( operand.def->class == NULL ) class = "OBJECT"; else class = operand.def->class->name; - + sieve_code_dumpf(denv, "%s: %s", class, obj->def->identifier); - + return TRUE; } diff --git a/src/lib-sieve/sieve-objects.h b/src/lib-sieve/sieve-objects.h index a31ebc823c6e8042d452759d158d859b757d3ee1..b83d6777dfe3dc07328eb183ca7c40f412ebeb81 100644 --- a/src/lib-sieve/sieve-objects.h +++ b/src/lib-sieve/sieve-objects.h @@ -42,7 +42,7 @@ struct sieve_object { /* * Object coding */ - + void sieve_opr_object_emit (struct sieve_binary_block *sblock, const struct sieve_extension *ext, const struct sieve_object_def *obj_def); @@ -53,12 +53,12 @@ bool sieve_opr_object_read_data struct sieve_object *obj); bool sieve_opr_object_read - (const struct sieve_runtime_env *renv, + (const struct sieve_runtime_env *renv, const struct sieve_operand_class *opclass, sieve_size_t *address, struct sieve_object *obj); bool sieve_opr_object_dump - (const struct sieve_dumptime_env *denv, + (const struct sieve_dumptime_env *denv, const struct sieve_operand_class *opclass, sieve_size_t *address, struct sieve_object *obj); diff --git a/src/lib-sieve/sieve-parser.c b/src/lib-sieve/sieve-parser.c index 08816020eee27bf03516bf7eb5c1cf45b89c13d4..1811a07fac128e340f0c61b6dc43b62785d1cc35 100644 --- a/src/lib-sieve/sieve-parser.c +++ b/src/lib-sieve/sieve-parser.c @@ -1,6 +1,6 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #include "lib.h" #include "istream.h" #include "failures.h" @@ -16,12 +16,12 @@ /* * Forward declarations */ - + inline static void sieve_parser_error (struct sieve_parser *parser, const char *fmt, ...) ATTR_FORMAT(2, 3); inline static void sieve_parser_warning - (struct sieve_parser *parser, const char *fmt, ...) ATTR_FORMAT(2, 3); - + (struct sieve_parser *parser, const char *fmt, ...) ATTR_FORMAT(2, 3); + static int sieve_parser_recover (struct sieve_parser *parser, enum sieve_token_type end_token); @@ -31,13 +31,13 @@ static int sieve_parser_recover struct sieve_parser { pool_t pool; - + bool valid; - + struct sieve_script *script; - + struct sieve_error_handler *ehandler; - + const struct sieve_lexer *lexer; struct sieve_ast *ast; }; @@ -48,34 +48,34 @@ struct sieve_parser *sieve_parser_create { struct sieve_parser *parser; const struct sieve_lexer *lexer; - + lexer = sieve_lexer_create(script, ehandler, error_r); - + if ( lexer != NULL ) { - pool_t pool = pool_alloconly_create("sieve_parser", 4096); + pool_t pool = pool_alloconly_create("sieve_parser", 4096); parser = p_new(pool, struct sieve_parser, 1); parser->pool = pool; parser->valid = TRUE; - + parser->ehandler = ehandler; sieve_error_handler_ref(ehandler); parser->script = script; sieve_script_ref(script); - + parser->lexer = lexer; parser->ast = NULL; - + return parser; } - + return NULL; } void sieve_parser_free(struct sieve_parser **parser) { - if ((*parser)->ast != NULL) + if ((*parser)->ast != NULL) sieve_ast_unref(&(*parser)->ast); sieve_lexer_free(&(*parser)->lexer); @@ -84,7 +84,7 @@ void sieve_parser_free(struct sieve_parser **parser) sieve_error_handler_unref(&(*parser)->ehandler); pool_unref(&(*parser)->pool); - + *parser = NULL; } @@ -94,23 +94,23 @@ void sieve_parser_free(struct sieve_parser **parser) inline static void sieve_parser_error (struct sieve_parser *parser, const char *fmt, ...) -{ +{ va_list args; va_start(args, fmt); - /* Don't report a parse error if the lexer complained already */ - if ( sieve_lexer_token_type(parser->lexer) != STT_ERROR ) + /* Don't report a parse error if the lexer complained already */ + if ( sieve_lexer_token_type(parser->lexer) != STT_ERROR ) { T_BEGIN { sieve_verror(parser->ehandler, - sieve_error_script_location(parser->script, + sieve_error_script_location(parser->script, sieve_lexer_token_line(parser->lexer)), fmt, args); - } T_END; + } T_END; } - + parser->valid = FALSE; - + va_end(args); } @@ -121,14 +121,14 @@ inline static void sieve_parser_warning va_start(args, fmt); T_BEGIN { - sieve_vwarning(parser->ehandler, - sieve_error_script_location(parser->script, + sieve_vwarning(parser->ehandler, + sieve_error_script_location(parser->script, sieve_lexer_token_line(parser->lexer)), fmt, args); } T_END; - + va_end(args); -} +} /* * Sieve grammar parsing @@ -146,13 +146,13 @@ inline static void sieve_parser_warning * test = identifier arguments */ static int sieve_parse_arguments -(struct sieve_parser *parser, struct sieve_ast_node *node, unsigned int depth) -{ +(struct sieve_parser *parser, struct sieve_ast_node *node, unsigned int depth) +{ const struct sieve_lexer *lexer = parser->lexer; struct sieve_ast_node *test = NULL; bool test_present = TRUE; bool arg_present = TRUE; - int result = TRUE; /* Indicates whether the parser is in a defined, not + int result = TRUE; /* Indicates whether the parser is in a defined, not necessarily error-free state */ /* Parse arguments */ @@ -163,9 +163,9 @@ static int sieve_parse_arguments result = 0; break; } - + switch ( sieve_lexer_token_type(lexer) ) { - + /* String list */ case STT_LSQUARE: /* Create stinglist object */ @@ -173,99 +173,99 @@ static int sieve_parse_arguments (node, sieve_lexer_token_line(parser->lexer)); if ( arg == NULL ) break; - - sieve_lexer_skip_token(lexer); - + + sieve_lexer_skip_token(lexer); + if ( sieve_lexer_token_type(lexer) == STT_STRING ) { bool add_failed = FALSE; /* Add the string to the list */ if ( !sieve_ast_stringlist_add - (arg, sieve_lexer_token_str(lexer), + (arg, sieve_lexer_token_str(lexer), sieve_lexer_token_line(parser->lexer)) ) add_failed = TRUE; - + sieve_lexer_skip_token(lexer); - + while ( !add_failed && sieve_lexer_token_type(lexer) == STT_COMMA ) { sieve_lexer_skip_token(lexer); /* Check parser status */ if ( !parser->valid && !sieve_errors_more_allowed(parser->ehandler) ) { result = sieve_parser_recover(parser, STT_RSQUARE); - break; + break; } - + if ( sieve_lexer_token_type(lexer) == STT_STRING ) { /* Add the string to the list */ if ( !sieve_ast_stringlist_add - (arg, sieve_lexer_token_str(lexer), + (arg, sieve_lexer_token_str(lexer), sieve_lexer_token_line(parser->lexer)) ) add_failed = TRUE; - + sieve_lexer_skip_token(lexer); } else { - sieve_parser_error(parser, + sieve_parser_error(parser, "expecting string after ',' in string list, but found %s", sieve_lexer_token_description(lexer)); - + result = sieve_parser_recover(parser, STT_RSQUARE); break; } } - + if ( add_failed ) { - sieve_parser_error(parser, + sieve_parser_error(parser, "failed to accept more items in string list"); return -1; } } else { - sieve_parser_error(parser, + sieve_parser_error(parser, "expecting string after '[' in string list, but found %s", sieve_lexer_token_description(lexer)); - + result = sieve_parser_recover(parser, STT_RSQUARE); } - + /* Finish the string list */ if ( sieve_lexer_token_type(lexer) == STT_RSQUARE ) { sieve_lexer_skip_token(lexer); } else { - sieve_parser_error(parser, + sieve_parser_error(parser, "expecting ',' or end of string list ']', but found %s", sieve_lexer_token_description(lexer)); - - if ( (result=sieve_parser_recover(parser, STT_RSQUARE)) == TRUE ) + + if ( (result=sieve_parser_recover(parser, STT_RSQUARE)) == TRUE ) sieve_lexer_skip_token(lexer); } - + break; - + /* Single string */ - case STT_STRING: + case STT_STRING: arg = sieve_ast_argument_string_create - (node, sieve_lexer_token_str(lexer), + (node, sieve_lexer_token_str(lexer), sieve_lexer_token_line(parser->lexer)); sieve_lexer_skip_token(lexer); break; - + /* Number */ case STT_NUMBER: arg = sieve_ast_argument_number_create - (node, sieve_lexer_token_int(lexer), + (node, sieve_lexer_token_int(lexer), sieve_lexer_token_line(parser->lexer)); sieve_lexer_skip_token(lexer); break; - + /* Tag */ case STT_TAG: arg = sieve_ast_argument_tag_create - (node, sieve_lexer_token_ident(lexer), + (node, sieve_lexer_token_ident(lexer), sieve_lexer_token_line(parser->lexer)); sieve_lexer_skip_token(lexer); break; - + /* End of argument list, continue with tests */ default: arg_present = FALSE; @@ -273,21 +273,21 @@ static int sieve_parse_arguments } if ( arg_present && arg == NULL ) { - sieve_parser_error(parser, + sieve_parser_error(parser, "failed to accept more arguments for command '%s'", node->identifier); return -1; } if ( sieve_ast_argument_count(node) > SIEVE_MAX_COMMAND_ARGUMENTS ) { - sieve_parser_error(parser, + sieve_parser_error(parser, "too many arguments for command '%s'", node->identifier); return FALSE; } } - + if ( result <= 0 ) return result; /* Defer recovery to caller */ - - /* --> [ test / test-list ] + + /* --> [ test / test-list ] * test-list = "(" test *("," test) ")" * test = identifier arguments */ @@ -296,17 +296,17 @@ static int sieve_parse_arguments /* Single test */ case STT_IDENTIFIER: if ( depth+1 > SIEVE_MAX_TEST_NESTING ) { - sieve_parser_error(parser, + sieve_parser_error(parser, "cannot nest tests deeper than %u levels", SIEVE_MAX_TEST_NESTING); return FALSE; } test = sieve_ast_test_create - (node, sieve_lexer_token_ident(lexer), + (node, sieve_lexer_token_ident(lexer), sieve_lexer_token_line(parser->lexer)); sieve_lexer_skip_token(lexer); - + /* Theoretically, test can be NULL */ if ( test == NULL ) break; @@ -314,15 +314,15 @@ static int sieve_parse_arguments if ( !sieve_parse_arguments(parser, test, depth+1) ) { return FALSE; /* Defer recovery to caller */ } - + break; - + /* Test list */ - case STT_LBRACKET: + case STT_LBRACKET: sieve_lexer_skip_token(lexer); if ( depth+1 > SIEVE_MAX_TEST_NESTING ) { - sieve_parser_error(parser, + sieve_parser_error(parser, "cannot nest tests deeper than %u levels", SIEVE_MAX_TEST_NESTING); result = sieve_parser_recover(parser, STT_RBRACKET); @@ -332,21 +332,21 @@ static int sieve_parse_arguments } node->test_list = TRUE; - + /* Test starts with identifier */ if ( sieve_lexer_token_type(lexer) == STT_IDENTIFIER ) { test = sieve_ast_test_create - (node, sieve_lexer_token_ident(lexer), + (node, sieve_lexer_token_ident(lexer), sieve_lexer_token_line(parser->lexer)); sieve_lexer_skip_token(lexer); - + if ( test == NULL ) break; /* Parse test arguments, which may include more tests (recurse) */ if ( (result=sieve_parse_arguments(parser, test, depth+1)) > 0 ) { - + /* More tests ? */ - while ( sieve_lexer_token_type(lexer) == STT_COMMA ) { + while ( sieve_lexer_token_type(lexer) == STT_COMMA ) { sieve_lexer_skip_token(lexer); /* Check parser status */ @@ -358,12 +358,12 @@ static int sieve_parse_arguments /* Test starts with identifier */ if ( sieve_lexer_token_type(lexer) == STT_IDENTIFIER ) { test = sieve_ast_test_create - (node, sieve_lexer_token_ident(lexer), + (node, sieve_lexer_token_ident(lexer), sieve_lexer_token_line(parser->lexer)); sieve_lexer_skip_token(lexer); if ( test == NULL ) break; - + /* Parse test arguments, which may include more tests (recurse) */ if ( (result=sieve_parse_arguments(parser, test, depth+1)) <= 0 ) { if ( result < 0 ) return result; @@ -371,62 +371,62 @@ static int sieve_parse_arguments break; } } else { - sieve_parser_error(parser, + sieve_parser_error(parser, "expecting test identifier after ',' in test list, but found %s", sieve_lexer_token_description(lexer)); - + result = sieve_parser_recover(parser, STT_RBRACKET); break; } } if ( test == NULL ) break; - } else { + } else { if ( result < 0 ) return result; result = sieve_parser_recover(parser, STT_RBRACKET); } } else { - sieve_parser_error(parser, + sieve_parser_error(parser, "expecting test identifier after '(' in test list, but found %s", sieve_lexer_token_description(lexer)); - + result = sieve_parser_recover(parser, STT_RBRACKET); } - + /* The next token should be a ')', indicating the end of the test list - * --> previous sieve_parser_recover calls try to restore this situation - * after parse errors. + * --> previous sieve_parser_recover calls try to restore this situation + * after parse errors. */ if ( sieve_lexer_token_type(lexer) == STT_RBRACKET ) { sieve_lexer_skip_token(lexer); } else { - sieve_parser_error(parser, + sieve_parser_error(parser, "expecting ',' or end of test list ')', but found %s", sieve_lexer_token_description(lexer)); - - /* Recover function tries to make next token equal to ')'. If it succeeds + + /* Recover function tries to make next token equal to ')'. If it succeeds * we need to skip it. */ - if ( (result=sieve_parser_recover(parser, STT_RBRACKET)) == TRUE ) + if ( (result=sieve_parser_recover(parser, STT_RBRACKET)) == TRUE ) sieve_lexer_skip_token(lexer); } break; - + default: /* Not an error: test / test-list is optional - * --> any errors are detected by the caller + * --> any errors are detected by the caller */ test_present = FALSE; break; } if ( test_present && test == NULL ) { - sieve_parser_error(parser, + sieve_parser_error(parser, "failed to accept more tests for command '%s'", node->identifier); return -1; - } - + } + return result; } @@ -435,12 +435,12 @@ static int sieve_parse_arguments * block = "{" commands "}" */ static int sieve_parse_commands -(struct sieve_parser *parser, struct sieve_ast_node *block, unsigned int depth) -{ +(struct sieve_parser *parser, struct sieve_ast_node *block, unsigned int depth) +{ const struct sieve_lexer *lexer = parser->lexer; int result = TRUE; - while ( result > 0 && + while ( result > 0 && sieve_lexer_token_type(lexer) == STT_IDENTIFIER ) { struct sieve_ast_node *command; @@ -452,33 +452,33 @@ static int sieve_parse_commands /* Create command node */ command = sieve_ast_command_create - (block, sieve_lexer_token_ident(lexer), + (block, sieve_lexer_token_ident(lexer), sieve_lexer_token_line(parser->lexer)); sieve_lexer_skip_token(lexer); - + if ( command == NULL ) { - sieve_parser_error(parser, - "failed to accept more commands inside the block of command '%s'", + sieve_parser_error(parser, + "failed to accept more commands inside the block of command '%s'", block->identifier); return -1; } result = sieve_parse_arguments(parser, command, 1); - /* Check whether the command is properly terminated - * (i.e. with ; or a new block) + /* Check whether the command is properly terminated + * (i.e. with ; or a new block) */ if ( result > 0 && sieve_lexer_token_type(lexer) != STT_SEMICOLON && sieve_lexer_token_type(lexer) != STT_LCURLY ) { - - sieve_parser_error(parser, + + sieve_parser_error(parser, "expected end of command ';' or the beginning of a compound block '{', " "but found %s", - sieve_lexer_token_description(lexer)); + sieve_lexer_token_description(lexer)); result = FALSE; } - + /* Try to recover from parse errors to reacquire a defined state */ if ( result == 0 ) { result = sieve_parser_recover(parser, STT_SEMICOLON); @@ -488,21 +488,21 @@ static int sieve_parse_commands if ( result <= 0 ) { return result; } - + switch ( sieve_lexer_token_type(lexer) ) { - + /* End of the command */ case STT_SEMICOLON: sieve_lexer_skip_token(lexer); break; - /* Command has a block {...} */ + /* Command has a block {...} */ case STT_LCURLY: sieve_lexer_skip_token(lexer); - + /* Check current depth first */ if ( depth+1 > SIEVE_MAX_BLOCK_NESTING ) { - sieve_parser_error(parser, + sieve_parser_error(parser, "cannot nest command blocks deeper than %u levels", SIEVE_MAX_BLOCK_NESTING); result = sieve_parser_recover(parser, STT_RCURLY); @@ -513,25 +513,25 @@ static int sieve_parse_commands } command->block = TRUE; - + if ( (result=sieve_parse_commands(parser, command, depth+1)) > 0 ) { - + if ( sieve_lexer_token_type(lexer) != STT_RCURLY ) { - sieve_parser_error(parser, + sieve_parser_error(parser, "expected end of compound block '}', but found %s", sieve_lexer_token_description(lexer)); - result = sieve_parser_recover(parser, STT_RCURLY); - } else + result = sieve_parser_recover(parser, STT_RCURLY); + } else sieve_lexer_skip_token(lexer); } else { if ( result < 0 ) return result; - if ( (result=sieve_parser_recover(parser, STT_RCURLY)) > 0 ) + if ( (result=sieve_parser_recover(parser, STT_RCURLY)) > 0 ) sieve_lexer_skip_token(lexer); } break; - + default: /* Recovered previously, so this cannot happen */ i_unreached(); @@ -542,130 +542,130 @@ static int sieve_parse_commands } bool sieve_parser_run -(struct sieve_parser *parser, struct sieve_ast **ast) +(struct sieve_parser *parser, struct sieve_ast **ast) { if ( parser->ast != NULL ) sieve_ast_unref(&parser->ast); - + /* Create AST object if none is provided */ if ( *ast == NULL ) *ast = sieve_ast_create(parser->script); - else + else sieve_ast_ref(*ast); - + parser->ast = *ast; /* Scan first token */ sieve_lexer_skip_token(parser->lexer); /* Parse */ - if ( sieve_parse_commands(parser, sieve_ast_root(parser->ast), 1) > 0 && + if ( sieve_parse_commands(parser, sieve_ast_root(parser->ast), 1) > 0 && parser->valid ) { - + /* Parsed right to EOF ? */ - if ( sieve_lexer_token_type(parser->lexer) != STT_EOF ) { - sieve_parser_error(parser, + if ( sieve_lexer_token_type(parser->lexer) != STT_EOF ) { + sieve_parser_error(parser, "unexpected %s found at (the presumed) end of file", sieve_lexer_token_description(parser->lexer)); parser->valid = FALSE; } } else parser->valid = FALSE; - + /* Clean up AST if parse failed */ if ( !parser->valid ) { parser->ast = NULL; sieve_ast_unref(ast); } - + return parser->valid; -} +} /* Error recovery: - * To continue parsing after an error it is important to find the next - * parsible item in the stream. The recover function skips over the remaining - * garbage after an error. It tries to find the end of the failed syntax - * structure and takes nesting of structures into account. + * To continue parsing after an error it is important to find the next + * parsible item in the stream. The recover function skips over the remaining + * garbage after an error. It tries to find the end of the failed syntax + * structure and takes nesting of structures into account. */ -/* Assign useful names to priorities for readability */ +/* Assign useful names to priorities for readability */ enum sieve_grammatical_prio { SGP_BLOCK = 3, SGP_COMMAND = 2, SGP_TEST_LIST = 1, SGP_STRING_LIST = 0, - + SGP_OTHER = -1 }; static inline enum sieve_grammatical_prio __get_token_priority -(enum sieve_token_type token) +(enum sieve_token_type token) { switch ( token ) { case STT_LCURLY: - case STT_RCURLY: + case STT_RCURLY: return SGP_BLOCK; - case STT_SEMICOLON: + case STT_SEMICOLON: return SGP_COMMAND; case STT_LBRACKET: - case STT_RBRACKET: + case STT_RBRACKET: return SGP_TEST_LIST; case STT_LSQUARE: - case STT_RSQUARE: + case STT_RSQUARE: return SGP_STRING_LIST; default: break; } - + return SGP_OTHER; } static int sieve_parser_recover -(struct sieve_parser *parser, enum sieve_token_type end_token) +(struct sieve_parser *parser, enum sieve_token_type end_token) { - /* The tokens that begin/end a specific block/command/list in order + /* The tokens that begin/end a specific block/command/list in order * of ascending grammatical priority. - */ - static const enum sieve_token_type begin_tokens[4] = + */ + static const enum sieve_token_type begin_tokens[4] = { STT_LSQUARE, STT_LBRACKET, STT_NONE, STT_LCURLY }; - static const enum sieve_token_type end_tokens[4] = + static const enum sieve_token_type end_tokens[4] = { STT_RSQUARE, STT_RBRACKET, STT_SEMICOLON, STT_RCURLY}; const struct sieve_lexer *lexer = parser->lexer; int nesting = 1; enum sieve_grammatical_prio end_priority = __get_token_priority(end_token); - + i_assert( end_priority != SGP_OTHER ); - - while ( sieve_lexer_token_type(lexer) != STT_EOF && + + while ( sieve_lexer_token_type(lexer) != STT_EOF && __get_token_priority(sieve_lexer_token_type(lexer)) <= end_priority ) { - + if ( sieve_lexer_token_type(lexer) == begin_tokens[end_priority] ) { nesting++; sieve_lexer_skip_token(lexer); continue; } - + if ( sieve_lexer_token_type(lexer) == end_tokens[end_priority] ) { nesting--; if ( nesting == 0 ) { /* Next character is the end */ - return TRUE; + return TRUE; } } - + sieve_lexer_skip_token(lexer); } - + /* Special case: COMMAND */ - if (end_token == STT_SEMICOLON && + if (end_token == STT_SEMICOLON && sieve_lexer_token_type(lexer) == STT_LCURLY) { return TRUE; } - - /* End not found before eof or end of surrounding grammatical structure + + /* End not found before eof or end of surrounding grammatical structure */ - return FALSE; + return FALSE; } diff --git a/src/lib-sieve/sieve-parser.h b/src/lib-sieve/sieve-parser.h index 99c69900d3483476905fd715b52b97bd54510a0a..490ff7d01ecc247b719810b0dd2c2fb388b7069e 100644 --- a/src/lib-sieve/sieve-parser.h +++ b/src/lib-sieve/sieve-parser.h @@ -1,6 +1,6 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #ifndef __SIEVE_PARSER_H #define __SIEVE_PARSER_H diff --git a/src/lib-sieve/sieve-plugins.c b/src/lib-sieve/sieve-plugins.c index cefe4295c12bc332de804bea3c420f8c5a8b8e33..a994ca4523000f8099b68fcec518c5e28f2188b5 100644 --- a/src/lib-sieve/sieve-plugins.c +++ b/src/lib-sieve/sieve-plugins.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ #include "lib.h" @@ -22,7 +22,7 @@ typedef void (*sieve_plugin_unload_func_t) struct sieve_plugin { struct module *module; - + void *context; struct sieve_plugin *next; @@ -72,7 +72,7 @@ void sieve_plugins_load if ( plugins == NULL || *plugins == '\0' ) return; - + if ( path == NULL || *path == '\0' ) path = MODULEDIR"/sieve"; @@ -136,7 +136,7 @@ void sieve_plugins_load /* Create plugin list item */ plugin = p_new(svinst->pool, struct sieve_plugin, 1); plugin->module = module; - + /* Call load function */ load_func = (sieve_plugin_load_func_t) module_get_symbol (module, t_strdup_printf("%s_load", module->name)); @@ -165,7 +165,7 @@ void sieve_plugins_unload(struct sieve_instance *svinst) if ( svinst->plugins == NULL ) return; - + /* Call plugin unload functions for this instance */ plugin = svinst->plugins; diff --git a/src/lib-sieve/sieve-plugins.h b/src/lib-sieve/sieve-plugins.h index dad880bcbbf7dec527481b22e2722a9b0517db83..80e54c538ed62ba1e8be98e0b79082bcee968333 100644 --- a/src/lib-sieve/sieve-plugins.h +++ b/src/lib-sieve/sieve-plugins.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ #ifndef __SIEVE_PLUGINS_H diff --git a/src/lib-sieve/sieve-result.c b/src/lib-sieve/sieve-result.c index dcda00b85309e6512f04423d9b4702a8bdae5dc1..b3ca760fdafea9aae36efb32e4c4c0e4de3b7d76 100644 --- a/src/lib-sieve/sieve-result.c +++ b/src/lib-sieve/sieve-result.c @@ -1,6 +1,6 @@ /* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #include "lib.h" #include "mempool.h" #include "ostream.h" @@ -33,18 +33,18 @@ /* * Types */ - + struct sieve_result_action { struct sieve_action action; - + void *tr_context; bool success; - + bool keep; struct sieve_side_effects_list *seffects; - - struct sieve_result_action *prev, *next; + + struct sieve_result_action *prev, *next; }; struct sieve_side_effects_list { @@ -57,7 +57,7 @@ struct sieve_side_effects_list { struct sieve_result_side_effect { struct sieve_side_effect seffect; - struct sieve_result_side_effect *prev, *next; + struct sieve_result_side_effect *prev, *next; }; struct sieve_result_action_context { @@ -76,21 +76,21 @@ struct sieve_result { struct sieve_instance *svinst; /* Context data for extensions */ - ARRAY_DEFINE(ext_contexts, void *); + ARRAY_DEFINE(ext_contexts, void *); struct sieve_error_handler *ehandler; - + struct sieve_action_exec_env action_env; - + struct sieve_action keep_action; struct sieve_action failure_action; unsigned int action_count; struct sieve_result_action *first_action; struct sieve_result_action *last_action; - + struct sieve_result_action *last_attempted_action; - + struct hash_table *action_contexts; }; @@ -100,17 +100,17 @@ struct sieve_result *sieve_result_create { pool_t pool; struct sieve_result *result; - - pool = pool_alloconly_create("sieve_result", 4096); + + pool = pool_alloconly_create("sieve_result", 4096); result = p_new(pool, struct sieve_result, 1); result->refcount = 1; result->pool = pool; result->svinst = svinst; - + p_array_init(&result->ext_contexts, pool, 4); if ( ehandler != NULL ) - sieve_error_handler_ref(ehandler); + sieve_error_handler_ref(ehandler); result->ehandler = ehandler; result->action_env.svinst = svinst; @@ -118,13 +118,13 @@ struct sieve_result *sieve_result_create result->action_env.scriptenv = senv; result->action_env.msgdata = msgdata; result->action_env.msgctx = sieve_message_context_create - (svinst, senv->user, msgdata); - + (svinst, senv->user, msgdata); + result->keep_action.def = &act_store; result->keep_action.ext = NULL; result->failure_action.def = &act_store; result->failure_action.ext = NULL; - + result->action_count = 0; result->first_action = NULL; result->last_action = NULL; @@ -133,12 +133,12 @@ struct sieve_result *sieve_result_create return result; } -void sieve_result_ref(struct sieve_result *result) +void sieve_result_ref(struct sieve_result *result) { result->refcount++; } -void sieve_result_unref(struct sieve_result **result) +void sieve_result_unref(struct sieve_result **result) { i_assert((*result)->refcount > 0); @@ -153,7 +153,7 @@ void sieve_result_unref(struct sieve_result **result) if ( (*result)->ehandler != NULL ) sieve_error_handler_unref(&(*result)->ehandler); - if ( (*result)->action_env.ehandler != NULL ) + if ( (*result)->action_env.ehandler != NULL ) sieve_error_handler_unref(&(*result)->action_env.ehandler); pool_unref(&(*result)->pool); @@ -212,33 +212,33 @@ void sieve_result_extension_set_context { if ( ext->id < 0 ) return; - array_idx_set(&result->ext_contexts, (unsigned int) ext->id, &context); -} + array_idx_set(&result->ext_contexts, (unsigned int) ext->id, &context); +} const void *sieve_result_extension_get_context -(struct sieve_result *result, const struct sieve_extension *ext) +(struct sieve_result *result, const struct sieve_extension *ext) { void * const *ctx; if ( ext->id < 0 || ext->id >= (int) array_count(&result->ext_contexts) ) return NULL; - - ctx = array_idx(&result->ext_contexts, (unsigned int) ext->id); + + ctx = array_idx(&result->ext_contexts, (unsigned int) ext->id); return *ctx; } -/* - * Error handling +/* + * Error handling */ void sieve_result_error (const struct sieve_action_exec_env *aenv, const char *fmt, ...) { va_list args; - - va_start(args, fmt); - sieve_verror(aenv->ehandler, NULL, fmt, args); + + va_start(args, fmt); + sieve_verror(aenv->ehandler, NULL, fmt, args); va_end(args); } @@ -246,9 +246,9 @@ void sieve_result_global_error (const struct sieve_action_exec_env *aenv, const char *fmt, ...) { va_list args; - - va_start(args, fmt); - sieve_global_verror(aenv->svinst, aenv->ehandler, NULL, fmt, args); + + va_start(args, fmt); + sieve_global_verror(aenv->svinst, aenv->ehandler, NULL, fmt, args); va_end(args); } @@ -256,8 +256,8 @@ void sieve_result_warning (const struct sieve_action_exec_env *aenv, const char *fmt, ...) { va_list args; - - va_start(args, fmt); + + va_start(args, fmt); sieve_vwarning(aenv->ehandler, NULL, fmt, args); va_end(args); } @@ -266,8 +266,8 @@ void sieve_result_global_warning (const struct sieve_action_exec_env *aenv, const char *fmt, ...) { va_list args; - - va_start(args, fmt); + + va_start(args, fmt); sieve_global_vwarning(aenv->svinst, aenv->ehandler, NULL, fmt, args); va_end(args); } @@ -277,8 +277,8 @@ void sieve_result_log (const struct sieve_action_exec_env *aenv, const char *fmt, ...) { va_list args; - - va_start(args, fmt); + + va_start(args, fmt); sieve_vinfo(aenv->ehandler, NULL, fmt, args); va_end(args); } @@ -287,31 +287,31 @@ void sieve_result_global_log (const struct sieve_action_exec_env *aenv, const char *fmt, ...) { va_list args; - - va_start(args, fmt); + + va_start(args, fmt); sieve_global_vinfo(aenv->svinst, aenv->ehandler, NULL, fmt, args); va_end(args); } -/* - * Result composition +/* + * Result composition */ void sieve_result_add_implicit_side_effect -(struct sieve_result *result, const struct sieve_action_def *to_action, - bool to_keep, const struct sieve_extension *ext, +(struct sieve_result *result, const struct sieve_action_def *to_action, + bool to_keep, const struct sieve_extension *ext, const struct sieve_side_effect_def *seff_def, void *context) { struct sieve_result_action_context *actctx = NULL; struct sieve_side_effect seffect; - + to_action = to_keep ? &act_store : to_action; if ( result->action_contexts == NULL ) { result->action_contexts = hash_table_create (default_pool, result->pool, 0, NULL, NULL); } else { - actctx = (struct sieve_result_action_context *) + actctx = (struct sieve_result_action_context *) hash_table_lookup(result->action_contexts, to_action); } @@ -320,15 +320,15 @@ void sieve_result_add_implicit_side_effect (result->pool, struct sieve_result_action_context, 1); actctx->action = to_action; actctx->seffects = sieve_side_effects_list_create(result); - - hash_table_insert(result->action_contexts, (void *) to_action, + + hash_table_insert(result->action_contexts, (void *) to_action, (void *) actctx); - } + } seffect.object.def = &seff_def->obj_def; seffect.object.ext = ext; seffect.def = seff_def; - seffect.context = context; + seffect.context = context; sieve_side_effects_list_add(actctx->seffects, &seffect); } @@ -337,19 +337,19 @@ static int sieve_result_side_effects_merge (const struct sieve_runtime_env *renv, const struct sieve_action *action, struct sieve_result_action *old_action, struct sieve_side_effects_list *new_seffects) -{ +{ struct sieve_side_effects_list *old_seffects = old_action->seffects; int ret; struct sieve_result_side_effect *rsef, *nrsef; /* Allow side-effects to merge with existing copy */ - + /* Merge existing side effects */ rsef = old_seffects != NULL ? old_seffects->first_effect : NULL; while ( rsef != NULL ) { struct sieve_side_effect *seffect = &rsef->seffect; bool found = FALSE; - + if ( seffect->def != NULL && seffect->def->merge != NULL ) { /* Try to find it among the new */ @@ -361,20 +361,20 @@ static int sieve_result_side_effects_merge if ( seffect->def->merge (renv, action, seffect, nseffect, &seffect->context) < 0 ) return -1; - + found = TRUE; break; } - + nrsef = nrsef->next; } - + /* Not found? */ if ( !found && seffect->def->merge (renv, action, seffect, NULL, &rsef->seffect.context) < 0 ) return -1; } - + rsef = rsef->next; } @@ -383,9 +383,9 @@ static int sieve_result_side_effects_merge while ( nrsef != NULL ) { struct sieve_side_effect *nseffect = &nrsef->seffect; bool found = FALSE; - + if ( nseffect->def != NULL && nseffect->def->merge != NULL ) { - + /* Try to find it among the exising */ rsef = old_seffects != NULL ? old_seffects->first_effect : NULL; while ( rsef != NULL ) { @@ -395,19 +395,19 @@ static int sieve_result_side_effects_merge } rsef = rsef->next; } - + /* Not found? */ if ( !found ) { - void *new_context = NULL; - + void *new_context = NULL; + if ( (ret=nseffect->def->merge - (renv, action, nseffect, nseffect, &new_context)) < 0 ) + (renv, action, nseffect, nseffect, &new_context)) < 0 ) return -1; - + if ( ret != 0 ) { if ( old_action->seffects == NULL ) old_action->seffects = old_seffects = - sieve_side_effects_list_create(renv->result); + sieve_side_effects_list_create(renv->result); nseffect->context = new_context; @@ -416,31 +416,31 @@ static int sieve_result_side_effects_merge } } } - + nrsef = nrsef->next; } - + return 1; } static void sieve_result_action_detach (struct sieve_result *result, struct sieve_result_action *raction) -{ - if ( result->first_action == raction ) +{ + if ( result->first_action == raction ) result->first_action = raction->next; - - if ( result->last_action == raction ) + + if ( result->last_action == raction ) result->last_action = raction->prev; - if ( result->last_attempted_action == raction ) + if ( result->last_attempted_action == raction ) result->last_attempted_action = raction->prev; - + if ( raction->next != NULL ) raction->next->prev = raction->prev; if ( raction->prev != NULL ) raction->prev->next = raction->next; - + raction->next = NULL; raction->prev = NULL; - + if ( result->action_count > 0 ) result->action_count--; } @@ -468,66 +468,66 @@ static int _sieve_result_add_action raction = result->first_action; while ( raction != NULL ) { const struct sieve_action *oact = &raction->action; - + if ( keep && raction->keep ) { - + /* Duplicate keep */ if ( raction->action.def == NULL || raction->action.executed ) { /* Keep action from preceeding execution */ - + /* Detach existing keep action */ sieve_result_action_detach(result, raction); /* Merge existing side-effects with new keep action */ if ( kaction == NULL ) kaction = raction; - + if ( (ret=sieve_result_side_effects_merge - (renv, &action, kaction, seffects)) <= 0 ) - return ret; + (renv, &action, kaction, seffects)) <= 0 ) + return ret; } else { /* True duplicate */ return sieve_result_side_effects_merge (renv, &action, raction, seffects); } - + } if ( act_def != NULL && raction->action.def == act_def ) { instance_count++; /* Possible duplicate */ if ( act_def->check_duplicate != NULL ) { - if ( (ret=act_def->check_duplicate(renv, &action, &raction->action)) + if ( (ret=act_def->check_duplicate(renv, &action, &raction->action)) < 0 ) return ret; - - /* Duplicate */ + + /* Duplicate */ if ( ret == 1 ) { if ( keep && !raction->keep ) { - /* New keep has higher precedence than existing duplicate non-keep + /* New keep has higher precedence than existing duplicate non-keep * action. So, take over the result action object and transform it * into a keep. */ - + if ( (ret=sieve_result_side_effects_merge - (renv, &action, raction, seffects)) < 0 ) + (renv, &action, raction, seffects)) < 0 ) return ret; - - if ( kaction == NULL ) { + + if ( kaction == NULL ) { raction->action.context = NULL; raction->action.location = p_strdup(result->pool, action.location); - - /* Note that existing execution status is retained, making sure + + /* Note that existing execution status is retained, making sure * that keep is not executed multiple times. */ - + kaction = raction; - + } else { sieve_result_action_detach(result, raction); if ( (ret=sieve_result_side_effects_merge - (renv, &action, kaction, raction->seffects)) < 0 ) + (renv, &action, kaction, raction->seffects)) < 0 ) return ret; } } else { @@ -541,9 +541,9 @@ static int _sieve_result_add_action if ( act_def != NULL && oact->def != NULL ) { /* Check conflict */ if ( act_def->check_conflict != NULL && - (ret=act_def->check_conflict(renv, &action, &raction->action)) != 0 ) + (ret=act_def->check_conflict(renv, &action, &raction->action)) != 0 ) return ret; - + if ( !raction->action.executed && oact->def->check_conflict != NULL && (ret=oact->def->check_conflict (renv, &raction->action, &action)) != 0 ) @@ -602,27 +602,27 @@ static int _sieve_result_add_action raction->next = NULL; } result->action_count++; - + /* Apply any implicit side effects */ if ( result->action_contexts != NULL ) { struct sieve_result_action_context *actctx; - + /* Check for implicit side effects to this particular action */ - actctx = (struct sieve_result_action_context *) - hash_table_lookup(result->action_contexts, + actctx = (struct sieve_result_action_context *) + hash_table_lookup(result->action_contexts, ( keep ? &act_store : act_def )); - + if ( actctx != NULL ) { struct sieve_result_side_effect *iseff; - - /* Iterate through all implicit side effects and add those that are + + /* Iterate through all implicit side effects and add those that are * missing. */ iseff = actctx->seffects->first_effect; while ( iseff != NULL ) { struct sieve_result_side_effect *seff; bool exists = FALSE; - + /* Scan for presence */ if ( seffects != NULL ) { seff = seffects->first_effect; @@ -631,19 +631,19 @@ static int _sieve_result_add_action exists = TRUE; break; } - + seff = seff->next; } } else { - raction->seffects = seffects = + raction->seffects = seffects = sieve_side_effects_list_create(result); } - + /* If not present, add it */ if ( !exists ) { sieve_side_effects_list_add(seffects, &iseff->seffect); } - + iseff = iseff->next; } } @@ -651,12 +651,12 @@ static int _sieve_result_add_action } if ( preserve_mail ) { - raction->action.mail = sieve_message_get_mail(renv->msgctx); + raction->action.mail = sieve_message_get_mail(renv->msgctx); sieve_message_snapshot(renv->msgctx); } else { raction->action.mail = NULL; } - + return 0; } @@ -674,7 +674,7 @@ int sieve_result_add_keep (const struct sieve_runtime_env *renv, struct sieve_side_effects_list *seffects) { return _sieve_result_add_action - (renv, renv->result->keep_action.ext, renv->result->keep_action.def, + (renv, renv->result->keep_action.ext, renv->result->keep_action.def, seffects, NULL, 0, TRUE, TRUE); } @@ -700,51 +700,51 @@ void sieve_result_set_failure_action void sieve_result_vprintf (const struct sieve_result_print_env *penv, const char *fmt, va_list args) -{ +{ string_t *outbuf = t_str_new(128); str_vprintfa(outbuf, fmt, args); - + o_stream_send(penv->stream, str_data(outbuf), str_len(outbuf)); } void sieve_result_printf (const struct sieve_result_print_env *penv, const char *fmt, ...) -{ +{ va_list args; - - va_start(args, fmt); + + va_start(args, fmt); sieve_result_vprintf(penv, fmt, args); - va_end(args); + va_end(args); } void sieve_result_action_printf (const struct sieve_result_print_env *penv, const char *fmt, ...) -{ +{ string_t *outbuf = t_str_new(128); va_list args; - - va_start(args, fmt); + + va_start(args, fmt); str_append(outbuf, " * "); str_vprintfa(outbuf, fmt, args); str_append_c(outbuf, '\n'); va_end(args); - + o_stream_send(penv->stream, str_data(outbuf), str_len(outbuf)); } void sieve_result_seffect_printf (const struct sieve_result_print_env *penv, const char *fmt, ...) -{ +{ string_t *outbuf = t_str_new(128); va_list args; - - va_start(args, fmt); + + va_start(args, fmt); str_append(outbuf, " + "); str_vprintfa(outbuf, fmt, args); str_append_c(outbuf, '\n'); va_end(args); - + o_stream_send(penv->stream, str_data(outbuf), str_len(outbuf)); } @@ -759,8 +759,8 @@ static void sieve_result_print_side_effects while ( rsef != NULL ) { if ( rsef->seffect.def != NULL ) { const struct sieve_side_effect *sef = &rsef->seffect; - - if ( sef->def->print != NULL ) + + if ( sef->def->print != NULL ) sef->def->print(sef, action, rpenv, implicit_keep); } rsef = rsef->next; @@ -776,44 +776,44 @@ static void sieve_result_print_implicit_side_effects /* Print any implicit side effects if applicable */ if ( result->action_contexts != NULL ) { struct sieve_result_action_context *actctx; - + /* Check for implicit side effects to keep action */ - actctx = (struct sieve_result_action_context *) + actctx = (struct sieve_result_action_context *) hash_table_lookup(rpenv->result->action_contexts, &act_store); - - if ( actctx != NULL && actctx->seffects != NULL ) + + if ( actctx != NULL && actctx->seffects != NULL ) sieve_result_print_side_effects (rpenv, &result->keep_action, actctx->seffects, &dummy); } } bool sieve_result_print -(struct sieve_result *result, const struct sieve_script_env *senv, +(struct sieve_result *result, const struct sieve_script_env *senv, struct ostream *stream, bool *keep) { struct sieve_action act_keep = result->keep_action; struct sieve_result_print_env penv; bool implicit_keep = TRUE; struct sieve_result_action *rac, *first_action; - + first_action = ( result->last_attempted_action == NULL ? result->first_action : result->last_attempted_action->next ); - + if ( keep != NULL ) *keep = FALSE; - + /* Prepare environment */ - + penv.result = result; penv.stream = stream; penv.scriptenv = senv; - + sieve_result_printf(&penv, "\nPerformed actions:\n\n"); - + if ( first_action == NULL ) { sieve_result_printf(&penv, " (none)\n"); - } else { + } else { rac = first_action; - while ( rac != NULL ) { + while ( rac != NULL ) { bool impl_keep = TRUE; const struct sieve_action *act = &rac->action; @@ -823,7 +823,7 @@ bool sieve_result_print if ( act->def->print != NULL ) act->def->print(act, &penv, &impl_keep); else - sieve_result_action_printf(&penv, "%s", act->def->name); + sieve_result_action_printf(&penv, "%s", act->def->name); } else { if ( rac->keep ) { sieve_result_action_printf(&penv, "keep"); @@ -832,55 +832,55 @@ bool sieve_result_print sieve_result_action_printf(&penv, "[NULL]"); } } - + /* Print side effects */ sieve_result_print_side_effects (&penv, &rac->action, rac->seffects, &impl_keep); - - implicit_keep = implicit_keep && impl_keep; - - rac = rac->next; + + implicit_keep = implicit_keep && impl_keep; + + rac = rac->next; } } - + if ( implicit_keep && keep != NULL ) *keep = TRUE; - + sieve_result_printf(&penv, "\nImplicit keep:\n\n"); - + if ( implicit_keep ) { bool dummy = TRUE; - + if ( act_keep.def == NULL ) { sieve_result_action_printf(&penv, "keep"); sieve_result_print_implicit_side_effects(&penv); } else { - /* Scan for execution of keep-equal actions */ + /* Scan for execution of keep-equal actions */ rac = result->first_action; while ( act_keep.def != NULL && rac != NULL ) { - if ( rac->action.def == act_keep.def && act_keep.def->equals != NULL - && act_keep.def->equals(senv, NULL, &rac->action) + if ( rac->action.def == act_keep.def && act_keep.def->equals != NULL + && act_keep.def->equals(senv, NULL, &rac->action) && rac->action.executed ) { act_keep.def = NULL; } - - rac = rac->next; + + rac = rac->next; } - + if ( act_keep.def == NULL ) { - sieve_result_printf(&penv, + sieve_result_printf(&penv, " (none; keep or equivalent action executed earlier)\n"); } else { act_keep.def->print(&act_keep, &penv, &dummy); - + sieve_result_print_implicit_side_effects(&penv); } } - } else + } else sieve_result_printf(&penv, " (none)\n"); - + sieve_result_printf(&penv, "\n"); - + return TRUE; } @@ -896,10 +896,10 @@ static void _sieve_result_prepare_execution(struct sieve_result *result) tab = mail_deliver_get_log_var_expand_table(msgdata->mail, NULL); result->action_env.exec_status = - ( senv->exec_status == NULL ? + ( senv->exec_status == NULL ? t_new(struct sieve_exec_status, 1) : senv->exec_status ); - if ( result->action_env.ehandler != NULL ) + if ( result->action_env.ehandler != NULL ) sieve_error_handler_unref(&result->action_env.ehandler); if ( senv->action_log_format != NULL ) { @@ -913,13 +913,13 @@ static void _sieve_result_prepare_execution(struct sieve_result *result) static bool _sieve_result_implicit_keep (struct sieve_result *result, bool rollback) -{ +{ struct sieve_result_action *rac; bool success = TRUE; struct sieve_result_side_effect *rsef, *rsef_first = NULL; void *tr_context = NULL; struct sieve_action act_keep; - + if ( rollback ) { act_keep = result->failure_action; act_keep.mail = NULL; @@ -927,36 +927,36 @@ static bool _sieve_result_implicit_keep act_keep = result->keep_action; act_keep.mail = sieve_message_get_mail(result->action_env.msgctx); } - + /* If keep is a non-action, return right away */ - if ( act_keep.def == NULL ) return TRUE; + if ( act_keep.def == NULL ) return TRUE; - /* Scan for execution of keep-equal actions */ + /* Scan for execution of keep-equal actions */ rac = result->first_action; while ( rac != NULL ) { - if ( rac->action.def == act_keep.def && act_keep.def->equals != NULL && + if ( rac->action.def == act_keep.def && act_keep.def->equals != NULL && act_keep.def->equals (result->action_env.scriptenv, NULL, &rac->action) && rac->action.executed ) return TRUE; - - rac = rac->next; + + rac = rac->next; } - + /* Apply any implicit side effects if applicable */ if ( !rollback && result->action_contexts != NULL ) { struct sieve_result_action_context *actctx; - + /* Check for implicit side effects to keep action */ - actctx = (struct sieve_result_action_context *) + actctx = (struct sieve_result_action_context *) hash_table_lookup(result->action_contexts, act_keep.def); - - if ( actctx != NULL && actctx->seffects != NULL ) + + if ( actctx != NULL && actctx->seffects != NULL ) rsef_first = actctx->seffects->first_effect; } - + /* Start keep action */ - if ( act_keep.def->start != NULL ) + if ( act_keep.def->start != NULL ) success = act_keep.def->start (&act_keep, &result->action_env, &tr_context); @@ -966,7 +966,7 @@ static bool _sieve_result_implicit_keep while ( success && rsef != NULL ) { struct sieve_side_effect *sef = &rsef->seffect; - if ( sef->def->pre_execute != NULL ) + if ( sef->def->pre_execute != NULL ) success = success && sef->def->pre_execute (sef, &act_keep, &result->action_env, &sef->context, tr_context); rsef = rsef->next; @@ -980,18 +980,18 @@ static bool _sieve_result_implicit_keep while ( success && rsef != NULL ) { struct sieve_side_effect *sef = &rsef->seffect; - if ( sef->def->post_execute != NULL ) + if ( sef->def->post_execute != NULL ) success = success && sef->def->post_execute (sef, &act_keep, &result->action_env, tr_context); rsef = rsef->next; } } - + /* Finish keep action */ if ( success ) { bool dummy = TRUE; - if ( act_keep.def->commit != NULL ) + if ( act_keep.def->commit != NULL ) success = act_keep.def->commit (&act_keep, &result->action_env, tr_context, &dummy); @@ -999,16 +999,16 @@ static bool _sieve_result_implicit_keep while ( rsef != NULL ) { struct sieve_side_effect *sef = &rsef->seffect; bool keep = TRUE; - - if ( sef->def->post_commit != NULL ) + + if ( sef->def->post_commit != NULL ) sef->def->post_commit (sef, &act_keep, &result->action_env, tr_context, &keep); rsef = rsef->next; } - - return success; + + return success; } - + /* Failed, rollback */ if ( act_keep.def->rollback != NULL ) act_keep.def->rollback @@ -1022,13 +1022,13 @@ bool sieve_result_implicit_keep { _sieve_result_prepare_execution(result); - return _sieve_result_implicit_keep(result, TRUE); + return _sieve_result_implicit_keep(result, TRUE); } void sieve_result_mark_executed(struct sieve_result *result) { struct sieve_result_action *first_action, *rac; - + first_action = ( result->last_attempted_action == NULL ? result->first_action : result->last_attempted_action->next ); result->last_attempted_action = result->last_action; @@ -1037,8 +1037,8 @@ void sieve_result_mark_executed(struct sieve_result *result) while ( rac != NULL ) { if ( rac->action.def != NULL ) rac->action.executed = TRUE; - - rac = rac->next; + + rac = rac->next; } } @@ -1055,85 +1055,85 @@ int sieve_result_execute /* Prepare environment */ _sieve_result_prepare_execution(result); - + /* Make notice of this attempt */ - + first_action = ( result->last_attempted_action == NULL ? result->first_action : result->last_attempted_action->next ); result->last_attempted_action = result->last_action; - - /* - * Transaction start + + /* + * Transaction start */ - + rac = first_action; while ( success && rac != NULL ) { struct sieve_action *act = &rac->action; - + /* Skip non-actions (inactive keep) and executed ones */ if ( act->def == NULL || act->executed ) { - rac = rac->next; + rac = rac->next; continue; } - + if ( act->def->start != NULL ) { rac->success = act->def->start (act, &result->action_env, &rac->tr_context); success = success && rac->success; - } - - rac = rac->next; + } + + rac = rac->next; } - - /* - * Transaction execute + + /* + * Transaction execute */ - + last_attempted = rac; rac = first_action; while ( success && rac != NULL ) { struct sieve_action *act = &rac->action; struct sieve_result_side_effect *rsef; struct sieve_side_effect *sef; - + /* Skip non-actions (inactive keep) and executed ones */ if ( act->def == NULL || act->executed ) { - rac = rac->next; + rac = rac->next; continue; } - + /* Execute pre-execute event of side effects */ rsef = rac->seffects != NULL ? rac->seffects->first_effect : NULL; while ( success && rsef != NULL ) { sef = &rsef->seffect; - if ( sef->def != NULL && sef->def->pre_execute != NULL ) + if ( sef->def != NULL && sef->def->pre_execute != NULL ) success = success & sef->def->pre_execute (sef, act, &result->action_env, &sef->context, rac->tr_context); rsef = rsef->next; } - + /* Execute the action itself */ if ( success && act->def != NULL && act->def->execute != NULL ) { rac->success = act->def->execute (act, &result->action_env, rac->tr_context); success = success && rac->success; } - + /* Execute post-execute event of side effects */ rsef = rac->seffects != NULL ? rac->seffects->first_effect : NULL; while ( success && rsef != NULL ) { sef = &rsef->seffect; - if ( sef->def != NULL && sef->def->post_execute != NULL ) + if ( sef->def != NULL && sef->def->post_execute != NULL ) success = success && sef->def->post_execute (sef, act, &result->action_env, rac->tr_context); rsef = rsef->next; } - - rac = rac->next; + + rac = rac->next; } - - /* - * Transaction commit/rollback + + /* + * Transaction commit/rollback */ commit_ok = success; @@ -1142,80 +1142,80 @@ int sieve_result_execute struct sieve_action *act = &rac->action; struct sieve_result_side_effect *rsef; struct sieve_side_effect *sef; - + if ( success ) { bool impl_keep = TRUE; - + if ( rac->keep && keep != NULL ) *keep = TRUE; /* Skip non-actions (inactive keep) and executed ones */ if ( act->def == NULL || act->executed ) { - rac = rac->next; + rac = rac->next; continue; } - - if ( act->def->commit != NULL ) { + + if ( act->def->commit != NULL ) { act->executed = act->def->commit (act, &result->action_env, rac->tr_context, &impl_keep); commit_ok = act->executed && commit_ok; } - + /* Execute post_commit event of side effects */ rsef = rac->seffects != NULL ? rac->seffects->first_effect : NULL; while ( rsef != NULL ) { sef = &rsef->seffect; - if ( sef->def->post_commit != NULL ) + if ( sef->def->post_commit != NULL ) sef->def->post_commit (sef, act, &result->action_env, rac->tr_context, &impl_keep); rsef = rsef->next; } - + implicit_keep = implicit_keep && impl_keep; } else { /* Skip non-actions (inactive keep) and executed ones */ if ( act->def == NULL || act->executed ) { - rac = rac->next; + rac = rac->next; continue; } - - if ( act->def->rollback != NULL ) + + if ( act->def->rollback != NULL ) act->def->rollback (act, &result->action_env, rac->tr_context, rac->success); - + /* Rollback side effects */ rsef = rac->seffects != NULL ? rac->seffects->first_effect : NULL; while ( rsef != NULL ) { sef = &rsef->seffect; - if ( sef->def && sef->def->rollback != NULL ) + if ( sef->def && sef->def->rollback != NULL ) sef->def->rollback (sef, act, &result->action_env, rac->tr_context, rac->success); rsef = rsef->next; } } - - rac = rac->next; + + rac = rac->next; } - + if ( implicit_keep && keep != NULL ) *keep = TRUE; - - /* Return value indicates whether the caller should attempt an implicit keep + + /* Return value indicates whether the caller should attempt an implicit keep * of its own. So, if the above transaction fails, but the implicit keep below - * succeeds, the return value is still true. An error is/should be logged + * succeeds, the return value is still true. An error is/should be logged * though. */ - + /* Execute implicit keep if the transaction failed or when the implicit keep - * was not canceled during transaction. + * was not canceled during transaction. */ - if ( !commit_ok || implicit_keep ) { - if ( !_sieve_result_implicit_keep(result, !commit_ok) ) + if ( !commit_ok || implicit_keep ) { + if ( !_sieve_result_implicit_keep(result, !commit_ok) ) return SIEVE_EXEC_KEEP_FAILED; - - return ( commit_ok ? + + return ( commit_ok ? SIEVE_EXEC_OK /* Success */ : SIEVE_EXEC_FAILURE /* Implicit keep executed */ ); } - + /* Unconditional success */ return SIEVE_EXEC_OK; } @@ -1233,9 +1233,9 @@ struct sieve_result_iterate_context { struct sieve_result_iterate_context *sieve_result_iterate_init (struct sieve_result *result) { - struct sieve_result_iterate_context *rictx = + struct sieve_result_iterate_context *rictx = t_new(struct sieve_result_iterate_context, 1); - + rictx->result = result; rictx->current_action = NULL; rictx->next_action = result->first_action; @@ -1254,10 +1254,10 @@ const struct sieve_action *sieve_result_iterate_next rac = rictx->current_action = rictx->next_action; if ( rac != NULL ) { rictx->next_action = rac->next; - + if ( keep != NULL ) *keep = rac->keep; - + return &rac->action; } @@ -1296,22 +1296,22 @@ void sieve_result_iterate_delete /* * Side effects list */ - + struct sieve_side_effects_list *sieve_side_effects_list_create (struct sieve_result *result) { - struct sieve_side_effects_list *list = + struct sieve_side_effects_list *list = p_new(result->pool, struct sieve_side_effects_list, 1); - + list->result = result; list->first_effect = NULL; list->last_effect = NULL; - + return list; } void sieve_side_effects_list_add -(struct sieve_side_effects_list *list, const struct sieve_side_effect *seffect) +(struct sieve_side_effects_list *list, const struct sieve_side_effect *seffect) { struct sieve_result_side_effect *reffect; @@ -1322,11 +1322,11 @@ void sieve_side_effects_list_add reffect = reffect->next; } - + /* Create new side effect object */ reffect = p_new(list->result->pool, struct sieve_result_side_effect, 1); reffect->seffect = *seffect; - + /* Add */ if ( list->first_effect == NULL ) { list->first_effect = reffect; @@ -1338,8 +1338,8 @@ void sieve_side_effects_list_add reffect->prev = list->last_effect; list->last_effect = reffect; reffect->next = NULL; - } -} + } +} diff --git a/src/lib-sieve/sieve-result.h b/src/lib-sieve/sieve-result.h index b6dc9129c35cabe28b050282f9d6efd27e4c2abe..0533f5da3a0c698f3092260d707617fd19dd2964 100644 --- a/src/lib-sieve/sieve-result.h +++ b/src/lib-sieve/sieve-result.h @@ -10,7 +10,7 @@ /* * Types */ - + struct sieve_side_effects_list; /* @@ -20,13 +20,13 @@ struct sieve_side_effects_list; struct sieve_result; struct sieve_result *sieve_result_create - (struct sieve_instance *svinst, const struct sieve_message_data *msgdata, + (struct sieve_instance *svinst, const struct sieve_message_data *msgdata, const struct sieve_script_env *senv, struct sieve_error_handler *ehandler); -void sieve_result_ref(struct sieve_result *result); +void sieve_result_ref(struct sieve_result *result); -void sieve_result_unref(struct sieve_result **result); +void sieve_result_unref(struct sieve_result **result); pool_t sieve_result_pool(struct sieve_result *result); @@ -54,10 +54,10 @@ void sieve_result_extension_set_context (struct sieve_result *result, const struct sieve_extension *ext, void *context); const void *sieve_result_extension_get_context - (struct sieve_result *result, const struct sieve_extension *ext); + (struct sieve_result *result, const struct sieve_extension *ext); -/* - * Result printing +/* + * Result printing */ struct sieve_result_print_env { @@ -80,11 +80,11 @@ void sieve_result_seffect_printf ATTR_FORMAT(2, 3); bool sieve_result_print - (struct sieve_result *result, const struct sieve_script_env *senv, + (struct sieve_result *result, const struct sieve_script_env *senv, struct ostream *stream, bool *keep); -/* - * Error handling +/* + * Error handling */ void sieve_result_error @@ -134,7 +134,7 @@ void sieve_result_set_failure_action /* * Result execution */ - + bool sieve_result_implicit_keep(struct sieve_result *result); void sieve_result_mark_executed(struct sieve_result *result); @@ -153,15 +153,15 @@ const struct sieve_action *sieve_result_iterate_next (struct sieve_result_iterate_context *rictx, bool *keep); void sieve_result_iterate_delete (struct sieve_result_iterate_context *rictx); - + /* * Side effects list */ - + struct sieve_side_effects_list *sieve_side_effects_list_create (struct sieve_result *result); void sieve_side_effects_list_add - (struct sieve_side_effects_list *list, + (struct sieve_side_effects_list *list, const struct sieve_side_effect *seffect); #endif diff --git a/src/lib-sieve/sieve-runtime-trace.c b/src/lib-sieve/sieve-runtime-trace.c index 9907e9518a426b512f4060084d93a4a8a691e45b..122001482bfa310b8f04641ce2a9e9a557431559 100644 --- a/src/lib-sieve/sieve-runtime-trace.c +++ b/src/lib-sieve/sieve-runtime-trace.c @@ -18,17 +18,17 @@ static inline string_t *_trace_line_new { string_t *trline; unsigned int i; - + trline = t_str_new(128); if ( (renv->trace->config.flags & SIEVE_TRFLG_ADDRESSES) > 0 ) str_printfa(trline, "%08llx: ", (unsigned long long) address); - if ( cmd_line > 0 ) - str_printfa(trline, "%4d: ", cmd_line); + if ( cmd_line > 0 ) + str_printfa(trline, "%4d: ", cmd_line); else - str_append(trline, " "); + str_append(trline, " "); for ( i = 0; i < renv->trace->indent; i++ ) - str_append(trline, " "); + str_append(trline, " "); return trline; } @@ -86,11 +86,11 @@ void _sieve_runtime_trace_operand_error static inline void ATTR_FORMAT(4, 0) _sieve_runtime_trace_vprintf (const struct sieve_runtime_env *renv, sieve_size_t address, unsigned int cmd_line, const char *fmt, va_list args) -{ +{ string_t *trline = _trace_line_new(renv, address, cmd_line); - - str_vprintfa(trline, fmt, args); - + + str_vprintfa(trline, fmt, args); + _trace_line_print(trline, renv); } @@ -99,55 +99,55 @@ static inline void ATTR_FORMAT(4, 5) _sieve_runtime_trace_printf unsigned int cmd_line, const char *fmt, ...) { va_list args; - + va_start(args, fmt); - _sieve_runtime_trace_vprintf(renv, address, cmd_line, fmt, args); + _sieve_runtime_trace_vprintf(renv, address, cmd_line, fmt, args); va_end(args); } void ATTR_FORMAT(2, 0) _sieve_runtime_trace (const struct sieve_runtime_env *renv, const char *fmt, va_list args) -{ +{ _sieve_runtime_trace_vprintf (renv, renv->oprtn->address, sieve_runtime_get_command_location(renv), - fmt, args); + fmt, args); } void _sieve_runtime_trace_address -(const struct sieve_runtime_env *renv, sieve_size_t address, +(const struct sieve_runtime_env *renv, sieve_size_t address, const char *fmt, va_list args) -{ +{ _sieve_runtime_trace_vprintf (renv, address, sieve_runtime_get_source_location(renv, address), fmt, - args); + args); } -/* +/* * Trace boundaries */ void _sieve_runtime_trace_begin(const struct sieve_runtime_env *renv) { - const char *script_name = ( renv->script != NULL ? + const char *script_name = ( renv->script != NULL ? sieve_script_name(renv->script) : sieve_binary_path(renv->sbin) ); _trace_line_print_empty(renv); - _sieve_runtime_trace_printf(renv, renv->pc, 0, + _sieve_runtime_trace_printf(renv, renv->pc, 0, "## Started executing script '%s'", script_name); } void _sieve_runtime_trace_end(const struct sieve_runtime_env *renv) { - const char *script_name = ( renv->script != NULL ? + const char *script_name = ( renv->script != NULL ? sieve_script_name(renv->script) : sieve_binary_path(renv->sbin) ); - _sieve_runtime_trace_printf(renv, renv->pc, 0, + _sieve_runtime_trace_printf(renv, renv->pc, 0, "## Finished executing script '%s'", script_name); _trace_line_print_empty(renv); } void _sieve_runtime_trace_sep(const struct sieve_runtime_env *renv) { - _trace_line_print_empty(renv); + _trace_line_print_empty(renv); } diff --git a/src/lib-sieve/sieve-runtime-trace.h b/src/lib-sieve/sieve-runtime-trace.h index 7cd1830a3e5b89c0d2cbe9e631ba93b619782744..778f3fc212281007d9e4a1b86ddfdcfb03367a99 100644 --- a/src/lib-sieve/sieve-runtime-trace.h +++ b/src/lib-sieve/sieve-runtime-trace.h @@ -20,13 +20,13 @@ struct sieve_runtime_trace { /* Trace configuration */ static inline bool sieve_runtime_trace_active -(const struct sieve_runtime_env *renv, sieve_trace_level_t trace_level) +(const struct sieve_runtime_env *renv, sieve_trace_level_t trace_level) { return ( renv->trace != NULL && trace_level <= renv->trace->config.level ); } static inline bool sieve_runtime_trace_hasflag -(const struct sieve_runtime_env *renv, unsigned int flag) +(const struct sieve_runtime_env *renv, unsigned int flag) { return ( renv->trace != NULL && (renv->trace->config.flags & flag) != 0 ); } @@ -66,26 +66,26 @@ static inline void sieve_runtime_trace_error ATTR_FORMAT(2, 3); static inline void sieve_runtime_trace_operand_error - (const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd, + (const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd, const char *fmt, ...) ATTR_FORMAT(3, 4); static inline void ATTR_FORMAT(2, 3) sieve_runtime_trace_error (const struct sieve_runtime_env *renv, const char *fmt, ...) { va_list args; - + va_start(args, fmt); if ( renv->trace != NULL ) - _sieve_runtime_trace_error(renv, fmt, args); + _sieve_runtime_trace_error(renv, fmt, args); va_end(args); } static inline void ATTR_FORMAT(3, 4) sieve_runtime_trace_operand_error - (const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd, + (const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd, const char *fmt, ...) { va_list args; - + va_start(args, fmt); if ( renv->trace != NULL ) _sieve_runtime_trace_operand_error(renv, oprnd, fmt, args); @@ -118,7 +118,7 @@ static inline void ATTR_FORMAT(3, 4) sieve_runtime_trace } void _sieve_runtime_trace_address - (const struct sieve_runtime_env *renv, sieve_size_t address, + (const struct sieve_runtime_env *renv, sieve_size_t address, const char *fmt, va_list args) ATTR_FORMAT(3, 0); static inline void sieve_runtime_trace_address diff --git a/src/lib-sieve/sieve-runtime.h b/src/lib-sieve/sieve-runtime.h index 1c74c2b84ab93816207280fdf923317fa7a4a9a6..c37b9557325ad68b6e0678524670fcaf531494de 100644 --- a/src/lib-sieve/sieve-runtime.h +++ b/src/lib-sieve/sieve-runtime.h @@ -25,11 +25,11 @@ struct sieve_runtime_env { /* Executing binary */ struct sieve_binary *sbin; struct sieve_binary_block *sblock; - + /* Current code */ sieve_size_t pc; - const struct sieve_operation *oprtn; - + const struct sieve_operation *oprtn; + /* Tested message */ const struct sieve_message_data *msgdata; struct sieve_message_context *msgctx; diff --git a/src/lib-sieve/sieve-script-dict.c b/src/lib-sieve/sieve-script-dict.c index 4c94ff3c07f091a675cc8ab0edca1196620435eb..6586091af3297519c3b3b515ac6959015de4c2f3 100644 --- a/src/lib-sieve/sieve-script-dict.c +++ b/src/lib-sieve/sieve-script-dict.c @@ -43,9 +43,9 @@ static struct sieve_script *sieve_dict_script_alloc(void) pool = pool_alloconly_create("sieve_dict_script", 1024); script = p_new(pool, struct sieve_dict_script, 1); - script->script = sieve_dict_script; + script->script = sieve_dict_script; script->script.pool = pool; - + return &script->script; } @@ -118,12 +118,12 @@ static int sieve_dict_script_create path = t_strconcat (DICT_SIEVE_NAME_PATH, dict_escape_string(name), NULL); - + ret = dict_lookup (script->dict, script->script.pool, path, &script->data_id); if ( ret <= 0 ) { if ( ret < 0 ) { - sieve_critical(svinst, ehandler, name, "failed to open sieve script", + sieve_critical(svinst, ehandler, name, "failed to open sieve script", "sieve dict backend: failed to lookup script id from path %s", path); *error_r = SIEVE_ERROR_TEMP_FAIL; } else { @@ -176,7 +176,7 @@ static struct istream *sieve_dict_script_open script->data_pool = pool_alloconly_create("sieve_dict_script data pool", 1024); - + path = t_strconcat (DICT_SIEVE_DATA_PATH, dict_escape_string(script->data_id), NULL); @@ -184,12 +184,12 @@ static struct istream *sieve_dict_script_open (script->dict, script->data_pool, path, &script->data); if ( ret <= 0 ) { if ( ret < 0 ) { - sieve_critical(svinst, ehandler, name, "failed to open sieve script", + sieve_critical(svinst, ehandler, name, "failed to open sieve script", "sieve dict backend: failed to lookup data with id `%s' " "for script `%s' from path %s", script->data_id, name, path); } else { - sieve_critical(svinst, ehandler, name, "failed to open sieve script", + sieve_critical(svinst, ehandler, name, "failed to open sieve script", "sieve dict backend: data with id `%s' for script `%s' " "not found at path %s", script->data_id, name, path); } diff --git a/src/lib-sieve/sieve-script-file.c b/src/lib-sieve/sieve-script-file.c index f684f96342f859607da0f15c3cc891c8526e6af7..d7c184f81e81c496940086dab40591ea418af623 100644 --- a/src/lib-sieve/sieve-script-file.c +++ b/src/lib-sieve/sieve-script-file.c @@ -22,7 +22,7 @@ /* * Configuration */ - + #define SIEVE_FILE_READ_BLOCK_SIZE (1024*8) /* @@ -70,12 +70,12 @@ static void sieve_file_script_handle_error *error_r = SIEVE_ERROR_NOT_FOUND; break; case EACCES: - sieve_critical(svinst, ehandler, name, "failed to open sieve script", + sieve_critical(svinst, ehandler, name, "failed to open sieve script", "failed to stat sieve script: %s", eacces_error_get("stat", path)); *error_r = SIEVE_ERROR_NO_PERM; break; default: - sieve_critical(svinst, ehandler, name, "failed to open sieve script", + sieve_critical(svinst, ehandler, name, "failed to open sieve script", "failed to stat sieve script: stat(%s) failed: %m", path); *error_r = SIEVE_ERROR_TEMP_FAIL; break; @@ -88,7 +88,7 @@ static void sieve_file_script_handle_error static int sieve_file_script_stat (const char *path, struct stat *st, struct stat *lnk_st) -{ +{ if ( lstat(path, st) < 0 ) return -1; @@ -107,9 +107,9 @@ static struct sieve_script *sieve_file_script_alloc(void) pool = pool_alloconly_create("sieve_file_script", 1024); script = p_new(pool, struct sieve_file_script, 1); - script->script = sieve_file_script; + script->script = sieve_file_script; script->script.pool = pool; - + return &script->script; } @@ -138,7 +138,7 @@ static int sieve_file_script_create } T_BEGIN { - if ( (path[0] == '~' && (path[1] == '/' || path[1] == '\0')) || + if ( (path[0] == '~' && (path[1] == '/' || path[1] == '\0')) || (((svinst->flags & SIEVE_FLAG_HOME_RELATIVE) != 0 ) && path[0] != '/') ) { /* home-relative path. change to absolute. */ const char *home = sieve_environment_get_homedir(svinst); @@ -149,7 +149,7 @@ static int sieve_file_script_create else path = t_strconcat(home, "/", path, NULL); } else { - sieve_critical(svinst, ehandler, NULL, + sieve_critical(svinst, ehandler, NULL, "failed to open sieve script", "sieve script file path %s is relative to home directory, " "but home directory is not available.", path); @@ -162,13 +162,13 @@ static int sieve_file_script_create if ( S_ISDIR(st.st_mode) ) { /* Path is directory; name is used to find actual file */ if (name == 0 || *name == '\0') { - sieve_critical(svinst, ehandler, NULL, + sieve_critical(svinst, ehandler, NULL, "failed to open sieve script", "sieve script file path '%s' is a directory.", path); *error_r = SIEVE_ERROR_TEMP_FAIL; success = FALSE; } else { - /* Extend path with filename */ + /* Extend path with filename */ filename = sieve_scriptfile_from_name(name); basename = name; dirpath = path; @@ -177,7 +177,7 @@ static int sieve_file_script_create path = t_strconcat(dirpath, filename, NULL); else path = t_strconcat(dirpath, "/", filename , NULL); - + ret = sieve_file_script_stat(path, &st, &lnk_st); } @@ -202,18 +202,18 @@ static int sieve_file_script_create } else { basename = name; } - + if ( success ) { if ( ret <= 0 ) { sieve_file_script_handle_error(_script, path, name, error_r); success = FALSE; } else if (!S_ISREG(st.st_mode) ) { - sieve_critical(svinst, ehandler, name, + sieve_critical(svinst, ehandler, name, "failed to open sieve script", "sieve script file '%s' is not a regular file.", path); *error_r = SIEVE_ERROR_TEMP_FAIL; success = FALSE; - } + } } if ( success ) { @@ -243,7 +243,7 @@ static int sieve_file_script_create if ( script->script.name == NULL ) script->script.name = p_strdup(pool, basename); } - } T_END; + } T_END; return ( success ? 0 : -1 ); } @@ -262,8 +262,8 @@ static struct istream *sieve_file_script_open if ( (fd=open(script->path, O_RDONLY)) < 0 ) { sieve_file_script_handle_error(_script, script->path, name, error_r); return NULL; - } - + } + if ( fstat(fd, &st) != 0 ) { sieve_critical(svinst, ehandler, name, "failed to open sieve script", @@ -287,11 +287,11 @@ static struct istream *sieve_file_script_open if ( result == NULL ) { /* Something went wrong, close the fd */ if ( close(fd) != 0 ) { - sieve_sys_error(svinst, + sieve_sys_error(svinst, "failed to close sieve script: close(fd=%s) failed: %m", script->path); } } - + return result; } @@ -324,7 +324,7 @@ static int sieve_file_script_binary_read_metadata struct sieve_binary *sbin = sieve_binary_block_get_binary(sblock); time_t time = ( script->st.st_mtime > script->lnk_st.st_mtime ? script->st.st_mtime : script->lnk_st.st_mtime ); - + if ( sieve_binary_mtime(sbin) <= time ) return 0; @@ -360,7 +360,7 @@ const struct sieve_script sieve_file_script = { NULL, sieve_file_script_open, - NULL, + NULL, sieve_file_script_binary_read_metadata, NULL, diff --git a/src/lib-sieve/sieve-script-file.h b/src/lib-sieve/sieve-script-file.h index c71fa87eeffd66271397c4d69f8acd0e944cef42..a2ebcfe204c6980eee731ab6beaa503c2edc0d8f 100644 --- a/src/lib-sieve/sieve-script-file.h +++ b/src/lib-sieve/sieve-script-file.h @@ -7,7 +7,7 @@ /* * Sieve script filenames */ - + bool sieve_scriptfile_has_extension(const char *filename); const char *sieve_scriptfile_get_script_name(const char *filename); const char *sieve_scriptfile_from_name(const char *name); diff --git a/src/lib-sieve/sieve-script-private.h b/src/lib-sieve/sieve-script-private.h index 49e1ca3720839a002036d291e072f360fa995c07..e317ff0d76b48d5e518bd8e4a3c9e372bd527399 100644 --- a/src/lib-sieve/sieve-script-private.h +++ b/src/lib-sieve/sieve-script-private.h @@ -31,7 +31,7 @@ struct sieve_script_vfuncs { struct sieve_binary *(*binary_load) (struct sieve_script *script, enum sieve_error *error_r); int (*binary_save) - (struct sieve_script *script, struct sieve_binary *sbin, + (struct sieve_script *script, struct sieve_binary *sbin, bool update, enum sieve_error *error_r); int (*get_size) diff --git a/src/lib-sieve/sieve-script.c b/src/lib-sieve/sieve-script.c index 8a82b66698c95f875b73c7d3cfed413a553a7557..82558674f17cc1bf89d78029a2f31b95794dc301 100644 --- a/src/lib-sieve/sieve-script.c +++ b/src/lib-sieve/sieve-script.c @@ -88,8 +88,8 @@ bool sieve_script_name_is_valid(const char *scriptname) return TRUE; } -/* - * Script object +/* + * Script object */ static const char *split_next_arg(const char *const **_args) @@ -122,7 +122,7 @@ static bool sieve_script_location_parse if (*data == '\0') { *options_r = NULL; - *location_r = data; + *location_r = data; return TRUE; } @@ -132,7 +132,7 @@ static bool sieve_script_location_parse if ( options_r != NULL ) { t_array_init(&options, 8); - + /* [<option> *(';' <option>)] */ while (*tmp != NULL) { const char *option = split_next_arg(&tmp); @@ -197,9 +197,9 @@ struct sieve_script *sieve_script_init script->svinst = svinst; script->ehandler = ehandler; - + script->name = p_strdup_empty(script->pool, name); - + if ( !sieve_script_location_parse (script, data, &location, &options, &parse_error) ) { sieve_critical(svinst, ehandler, NULL, @@ -228,7 +228,7 @@ struct sieve_script *sieve_script_init } struct sieve_script *sieve_script_create -(struct sieve_instance *svinst, const char *location, const char *name, +(struct sieve_instance *svinst, const char *location, const char *name, struct sieve_error_handler *ehandler, enum sieve_error *error_r) { struct sieve_script *script; @@ -250,13 +250,13 @@ struct sieve_script *sieve_script_create /* FIXME script_class = sieve_script_class_lookup(driver);*/ - if ( strcasecmp(driver, SIEVE_FILE_SCRIPT_DRIVER_NAME) == 0 ) + if ( strcasecmp(driver, SIEVE_FILE_SCRIPT_DRIVER_NAME) == 0 ) script_class = &sieve_file_script; else if ( strcasecmp(driver, SIEVE_DICT_SCRIPT_DRIVER_NAME) == 0 ) script_class = &sieve_dict_script; else script_class = NULL; - + if ( script_class == NULL ) i_error("Unknown sieve script driver module: %s", driver); } T_END; @@ -276,7 +276,7 @@ struct sieve_script *sieve_script_create } struct sieve_script *sieve_script_create_as -(struct sieve_instance *svinst, const char *location, const char *name, +(struct sieve_instance *svinst, const char *location, const char *name, struct sieve_error_handler *ehandler, enum sieve_error *error_r) { struct sieve_script *script; @@ -287,7 +287,7 @@ struct sieve_script *sieve_script_create_as /* override name */ script->name = p_strdup(script->pool, name); - return script; + return script; } void sieve_script_ref(struct sieve_script *script) @@ -317,7 +317,7 @@ void sieve_script_unref(struct sieve_script **_script) *_script = NULL; } -/* +/* * Properties */ @@ -352,8 +352,8 @@ int sieve_script_get_size(struct sieve_script *script, uoff_t *size_r) return i_stream_get_size(script->stream, TRUE, size_r); } -/* - * Stream management +/* + * Stream management */ struct istream *sieve_script_open @@ -391,15 +391,15 @@ void sieve_script_close(struct sieve_script *script) i_stream_unref(&script->stream); - if ( script->v.close != NULL ) { + if ( script->v.close != NULL ) { T_BEGIN { script->v.close(script); } T_END; } } -/* - * Comparison +/* + * Comparison */ bool sieve_script_equals @@ -439,7 +439,7 @@ int sieve_script_binary_read_metadata struct sieve_instance *svinst = script->svinst; struct sieve_binary *sbin = sieve_binary_block_get_binary(sblock); string_t *script_class; - + if ( sieve_binary_block_get_size(sblock) - *offset == 0 ) return 0; diff --git a/src/lib-sieve/sieve-script.h b/src/lib-sieve/sieve-script.h index 896cfdfad182da3defbd981b6b09502d3d67b7c6..93a3d93d4369bba1c47041673b275db47992a728 100644 --- a/src/lib-sieve/sieve-script.h +++ b/src/lib-sieve/sieve-script.h @@ -24,10 +24,10 @@ struct sieve_script; ARRAY_DEFINE_TYPE(sieve_scripts, struct sieve_script *); struct sieve_script *sieve_script_create - (struct sieve_instance *svinst, const char *location, const char *name, + (struct sieve_instance *svinst, const char *location, const char *name, struct sieve_error_handler *ehandler, enum sieve_error *error_r); struct sieve_script *sieve_script_create_as - (struct sieve_instance *svinst, const char *location, const char *name, + (struct sieve_instance *svinst, const char *location, const char *name, struct sieve_error_handler *ehandler, enum sieve_error *error_r); void sieve_script_ref(struct sieve_script *script); @@ -36,7 +36,7 @@ void sieve_script_unref(struct sieve_script **script); /* * Accessors */ - + const char *sieve_script_name(const struct sieve_script *script); const char *sieve_script_location(const struct sieve_script *script); struct sieve_instance *sieve_script_svinst(const struct sieve_script *script); @@ -57,8 +57,8 @@ int sieve_script_binary_save (struct sieve_script *script, struct sieve_binary *sbin, bool update, enum sieve_error *error_r); -/* - * Stream management +/* + * Stream management */ struct istream *sieve_script_open @@ -70,7 +70,7 @@ int sieve_script_get_size(struct sieve_script *script, uoff_t *size_r); /* * Comparison */ - + bool sieve_script_equals (const struct sieve_script *script, const struct sieve_script *other); diff --git a/src/lib-sieve/sieve-settings.c b/src/lib-sieve/sieve-settings.c index 3a58d76f99b81545d9f4b62f418e9a1f35ea0981..0ab26b9329eea86a8f4464676a5af4ec6414848c 100644 --- a/src/lib-sieve/sieve-settings.c +++ b/src/lib-sieve/sieve-settings.c @@ -21,7 +21,7 @@ static bool sieve_setting_parse_uint setting, str_value); return FALSE; } - + return TRUE; } @@ -44,7 +44,7 @@ static bool sieve_setting_parse_int setting, str_value); return FALSE; } - + return TRUE; } @@ -69,8 +69,8 @@ bool sieve_setting_get_uint_value setting, str_value); return FALSE; } - - return TRUE; + + return TRUE; } bool sieve_setting_get_int_value @@ -94,8 +94,8 @@ bool sieve_setting_get_int_value return FALSE; } - - return TRUE; + + return TRUE; } bool sieve_setting_get_size_value @@ -146,7 +146,7 @@ bool sieve_setting_get_size_value } *value_r = (size_t) (value * multiply); - + return TRUE; } @@ -197,7 +197,7 @@ bool sieve_setting_get_duration_value case 's': /* seconds */ multiply = 1; break; - case 'm': /* minutes */ + case 'm': /* minutes */ multiply = 60; break; case 'h': /* hours */ @@ -221,7 +221,7 @@ bool sieve_setting_get_duration_value } *value_r = (unsigned int) (value * multiply); - + return TRUE; } diff --git a/src/lib-sieve/sieve-stringlist.c b/src/lib-sieve/sieve-stringlist.c index 5e3995f01fc672ba181cf7e53b30350613386f0e..a40124753779ae1f839807445903a5567841f32e 100644 --- a/src/lib-sieve/sieve-stringlist.c +++ b/src/lib-sieve/sieve-stringlist.c @@ -20,21 +20,21 @@ int sieve_stringlist_read_all ARRAY_DEFINE(items, const char *); string_t *item; int ret; - + sieve_stringlist_reset(strlist); - + p_array_init(&items, pool, 4); - + item = NULL; while ( (ret=sieve_stringlist_next_item(strlist, &item)) > 0 ) { const char *stritem = p_strdup(pool, str_c(item)); - + array_append(&items, &stritem, 1); } - + (void)array_append_space(&items); *list_r = array_idx(&items, 0); - + return ( ret < 0 ? -1 : 1 ); } @@ -57,7 +57,7 @@ int sieve_stringlist_get_length } return strlist->get_length(strlist); -} +} /* * Single Stringlist @@ -103,7 +103,7 @@ struct sieve_stringlist *sieve_single_stringlist_create_cstr { string_t *str = t_str_new_const(cstr, strlen(cstr)); - return sieve_single_stringlist_create(renv, str, count_empty); + return sieve_single_stringlist_create(renv, str, count_empty); } /* Implementation */ @@ -118,7 +118,7 @@ static int sieve_single_stringlist_next_item *str_r = NULL; return 0; } - + *str_r = strlist->value; strlist->end = TRUE; return 1; diff --git a/src/lib-sieve/sieve-stringlist.h b/src/lib-sieve/sieve-stringlist.h index 58104b1346e85e1df161697e2eb7e1e2e6eed4cd..fd64be115bf8a0c3b836fa9d4209c76f29d46c07 100644 --- a/src/lib-sieve/sieve-stringlist.h +++ b/src/lib-sieve/sieve-stringlist.h @@ -39,13 +39,13 @@ static inline void sieve_stringlist_set_trace } static inline int sieve_stringlist_next_item -(struct sieve_stringlist *strlist, string_t **str_r) +(struct sieve_stringlist *strlist, string_t **str_r) { return strlist->next_item(strlist, str_r); } static inline void sieve_stringlist_reset -(struct sieve_stringlist *strlist) +(struct sieve_stringlist *strlist) { strlist->reset(strlist); } diff --git a/src/lib-sieve/sieve-types.h b/src/lib-sieve/sieve-types.h index 3cd5ccddd4bb46eaf319d035c01428e03cbae49c..02a60217ba8c153037bab8c55dc877b761ecf79b 100644 --- a/src/lib-sieve/sieve-types.h +++ b/src/lib-sieve/sieve-types.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ #ifndef __SIEVE_TYPES_H @@ -91,13 +91,13 @@ enum sieve_compile_flags { /* Script is being uploaded (usually through ManageSieve) */ SIEVE_COMPILE_FLAG_UPLOADED = (1<<1), /* Script is being activated (usually through ManageSieve) */ - SIEVE_COMPILE_FLAG_ACTIVATED = (1<<2), + SIEVE_COMPILE_FLAG_ACTIVATED = (1<<2), }; -/* +/* * Message data * - * - The mail message + envelope data + * - The mail message + envelope data */ struct sieve_message_data { @@ -142,10 +142,10 @@ struct sieve_trace_config { unsigned int flags; }; -/* +/* * Script environment * - * - Environment for currently executing script + * - Environment for currently executing script */ struct sieve_script_env { @@ -158,19 +158,19 @@ struct sieve_script_env { const char *postmaster_address; bool mailbox_autocreate; bool mailbox_autosubscribe; - + /* External context data */ void *script_context; /* Callbacks */ - + /* Interface for sending mail */ void *(*smtp_open) - (const struct sieve_script_env *senv, const char *destination, + (const struct sieve_script_env *senv, const char *destination, const char *return_path, FILE **file_r); bool (*smtp_close)(const struct sieve_script_env *senv, void *handle); - + /* Interface for marking and checking duplicates */ int (*duplicate_check) (const struct sieve_script_env *senv, const void *id, size_t id_size); @@ -181,10 +181,10 @@ struct sieve_script_env { /* Interface for rejecting mail */ int (*reject_mail)(const struct sieve_script_env *senv, const char *recipient, const char *reason); - - /* Execution status record */ + + /* Execution status record */ struct sieve_exec_status *exec_status; - + /* Runtime trace*/ struct ostream *trace_stream; struct sieve_trace_config trace_config; @@ -195,7 +195,7 @@ struct sieve_script_env { /* * Script execution status - */ + */ struct sieve_exec_status { bool message_saved; diff --git a/src/lib-sieve/sieve-validator.c b/src/lib-sieve/sieve-validator.c index 9647751fd666f3ca5d503b54a0b3c5bea9cd2162..4e85b83e1305eae369a5eeac02acd2f8bb817b9d 100644 --- a/src/lib-sieve/sieve-validator.c +++ b/src/lib-sieve/sieve-validator.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ #include "lib.h" @@ -22,23 +22,23 @@ /* * Forward declarations */ - + static void sieve_validator_register_core_commands (struct sieve_validator *valdtr); static void sieve_validator_register_core_tests (struct sieve_validator *valdtr); - + /* * Types */ - + /* Tag registration */ struct sieve_tag_registration { const struct sieve_argument_def *tag_def; const struct sieve_extension *ext; - const char *identifier; + const char *identifier; int id_code; }; @@ -47,12 +47,12 @@ struct sieve_tag_registration { struct sieve_command_registration { const struct sieve_command_def *cmd_def; const struct sieve_extension *ext; - - ARRAY_DEFINE(normal_tags, struct sieve_tag_registration *); - ARRAY_DEFINE(instanced_tags, struct sieve_tag_registration *); - ARRAY_DEFINE(persistent_tags, struct sieve_tag_registration *); + + ARRAY_DEFINE(normal_tags, struct sieve_tag_registration *); + ARRAY_DEFINE(instanced_tags, struct sieve_tag_registration *); + ARRAY_DEFINE(persistent_tags, struct sieve_tag_registration *); }; - + /* Default (literal) arguments */ struct sieve_default_argument { @@ -62,7 +62,7 @@ struct sieve_default_argument { struct sieve_default_argument *overrides; }; -/* +/* * Validator extension */ @@ -75,7 +75,7 @@ struct sieve_validator_extension_reg { bool loaded; }; -/* +/* * Validator */ @@ -86,17 +86,17 @@ struct sieve_validator { struct sieve_ast *ast; struct sieve_script *script; enum sieve_compile_flags flags; - + struct sieve_error_handler *ehandler; bool finished_require; - + /* Registries */ - + struct hash_table *commands; - + ARRAY_DEFINE(extensions, struct sieve_validator_extension_reg); - + /* This is currently a wee bit ugly and needs more thought */ struct sieve_default_argument default_arguments[SAT_COUNT]; @@ -106,58 +106,58 @@ struct sieve_validator { bool current_defarg_constant; }; -/* - * Error handling +/* + * Error handling */ void sieve_validator_warning -(struct sieve_validator *valdtr, unsigned int source_line, - const char *fmt, ...) -{ +(struct sieve_validator *valdtr, unsigned int source_line, + const char *fmt, ...) +{ va_list args; - + va_start(args, fmt); - sieve_vwarning(valdtr->ehandler, + sieve_vwarning(valdtr->ehandler, sieve_error_script_location(valdtr->script, source_line), fmt, args); va_end(args); - + } - + void sieve_validator_error -(struct sieve_validator *valdtr, unsigned int source_line, - const char *fmt, ...) +(struct sieve_validator *valdtr, unsigned int source_line, + const char *fmt, ...) { va_list args; - + va_start(args, fmt); - sieve_verror(valdtr->ehandler, + sieve_verror(valdtr->ehandler, sieve_error_script_location(valdtr->script, source_line), fmt, args); va_end(args); } -/* - * Validator object +/* + * Validator object */ struct sieve_validator *sieve_validator_create (struct sieve_ast *ast, struct sieve_error_handler *ehandler, - enum sieve_compile_flags flags) + enum sieve_compile_flags flags) { pool_t pool; struct sieve_validator *valdtr; const struct sieve_extension *const *ext_preloaded; unsigned int i, ext_count; - - pool = pool_alloconly_create("sieve_validator", 8192); + + pool = pool_alloconly_create("sieve_validator", 8192); valdtr = p_new(pool, struct sieve_validator, 1); valdtr->pool = pool; - + valdtr->ehandler = ehandler; sieve_error_handler_ref(ehandler); - - valdtr->ast = ast; + + valdtr->ast = ast; sieve_ast_ref(ast); valdtr->script = sieve_ast_script(ast); @@ -174,29 +174,29 @@ struct sieve_validator *sieve_validator_create valdtr->default_arguments[SAT_STRING_LIST].arg_def = &string_list_argument; valdtr->default_arguments[SAT_STRING_LIST].ext = NULL; - /* Setup storage for extension contexts */ - p_array_init(&valdtr->extensions, pool, + /* Setup storage for extension contexts */ + p_array_init(&valdtr->extensions, pool, sieve_extensions_get_count(valdtr->svinst)); - + /* Setup command registry */ valdtr->commands = hash_table_create (default_pool, pool, 0, strcase_hash, (hash_cmp_callback_t *)strcasecmp); sieve_validator_register_core_commands(valdtr); sieve_validator_register_core_tests(valdtr); - + /* Pre-load core language features implemented as 'extensions' */ - ext_preloaded = sieve_extensions_get_preloaded(valdtr->svinst, &ext_count); + ext_preloaded = sieve_extensions_get_preloaded(valdtr->svinst, &ext_count); for ( i = 0; i < ext_count; i++ ) { const struct sieve_extension_def *ext_def = ext_preloaded[i]->def; if ( ext_def != NULL && ext_def->validator_load != NULL ) - (void)ext_def->validator_load(ext_preloaded[i], valdtr); + (void)ext_def->validator_load(ext_preloaded[i], valdtr); } return valdtr; } -void sieve_validator_free(struct sieve_validator **valdtr) +void sieve_validator_free(struct sieve_validator **valdtr) { const struct sieve_validator_extension_reg *extrs; unsigned int ext_count, i; @@ -259,44 +259,44 @@ enum sieve_compile_flags sieve_validator_compile_flags return valdtr->flags; } -/* - * Command registry +/* + * Command registry */ /* Dummy command object to mark unknown commands in the registry */ static bool _cmd_unknown_validate -(struct sieve_validator *valdtr ATTR_UNUSED, - struct sieve_command *cmd ATTR_UNUSED) +(struct sieve_validator *valdtr ATTR_UNUSED, + struct sieve_command *cmd ATTR_UNUSED) { i_unreached(); return FALSE; } -static const struct sieve_command_def unknown_command = { - "", SCT_NONE, 0, 0, FALSE, FALSE , - NULL, NULL, _cmd_unknown_validate, NULL, NULL, NULL +static const struct sieve_command_def unknown_command = { + "", SCT_NONE, 0, 0, FALSE, FALSE , + NULL, NULL, _cmd_unknown_validate, NULL, NULL, NULL }; /* Registration of the core commands of the language */ static void sieve_validator_register_core_tests -(struct sieve_validator *valdtr) +(struct sieve_validator *valdtr) { unsigned int i; - + for ( i = 0; i < sieve_core_tests_count; i++ ) { - sieve_validator_register_command(valdtr, NULL, sieve_core_tests[i]); + sieve_validator_register_command(valdtr, NULL, sieve_core_tests[i]); } } static void sieve_validator_register_core_commands -(struct sieve_validator *valdtr) +(struct sieve_validator *valdtr) { unsigned int i; - + for ( i = 0; i < sieve_core_commands_count; i++ ) { - sieve_validator_register_command(valdtr, NULL, sieve_core_commands[i]); + sieve_validator_register_command(valdtr, NULL, sieve_core_commands[i]); } } @@ -304,86 +304,86 @@ static void sieve_validator_register_core_commands static struct sieve_command_registration * sieve_validator_find_command_registration -(struct sieve_validator *valdtr, const char *command) +(struct sieve_validator *valdtr, const char *command) { - return (struct sieve_command_registration *) + return (struct sieve_command_registration *) hash_table_lookup(valdtr->commands, command); } static struct sieve_command_registration *_sieve_validator_register_command (struct sieve_validator *valdtr, const struct sieve_extension *ext, - const struct sieve_command_def *cmd_def, const char *identifier) + const struct sieve_command_def *cmd_def, const char *identifier) { - struct sieve_command_registration *cmd_reg = + struct sieve_command_registration *cmd_reg = p_new(valdtr->pool, struct sieve_command_registration, 1); cmd_reg->cmd_def = cmd_def; cmd_reg->ext = ext; - + hash_table_insert(valdtr->commands, (void *) identifier, (void *) cmd_reg); - + return cmd_reg; } void sieve_validator_register_command -(struct sieve_validator *valdtr, const struct sieve_extension *ext, - const struct sieve_command_def *cmd_def) +(struct sieve_validator *valdtr, const struct sieve_extension *ext, + const struct sieve_command_def *cmd_def) { struct sieve_command_registration *cmd_reg = sieve_validator_find_command_registration(valdtr, cmd_def->identifier); - - if ( cmd_reg == NULL ) + + if ( cmd_reg == NULL ) cmd_reg = _sieve_validator_register_command (valdtr, ext, cmd_def, cmd_def->identifier); else { cmd_reg->cmd_def = cmd_def; cmd_reg->ext = ext; } - - if ( cmd_def->registered != NULL ) + + if ( cmd_def->registered != NULL ) cmd_def->registered(valdtr, ext, cmd_reg); } static void sieve_validator_register_unknown_command -(struct sieve_validator *valdtr, const char *command) +(struct sieve_validator *valdtr, const char *command) { (void)_sieve_validator_register_command - (valdtr, NULL, &unknown_command, command); + (valdtr, NULL, &unknown_command, command); } /*const struct sieve_command *sieve_validator_find_command -(struct sieve_validator *valdtr, const char *command) +(struct sieve_validator *valdtr, const char *command) { - struct sieve_command_registration *cmd_reg = + struct sieve_command_registration *cmd_reg = sieve_validator_find_command_registration(valdtr, command); - + return ( record == NULL ? NULL : record->command ); }*/ -/* - * Per-command tagged argument registry +/* + * Per-command tagged argument registry */ /* Dummy argument object to mark unknown arguments in the registry */ static bool _unknown_tag_validate -(struct sieve_validator *valdtr ATTR_UNUSED, - struct sieve_ast_argument **arg ATTR_UNUSED, +(struct sieve_validator *valdtr ATTR_UNUSED, + struct sieve_ast_argument **arg ATTR_UNUSED, struct sieve_command *tst ATTR_UNUSED) { i_unreached(); return FALSE; } -static const struct sieve_argument_def _unknown_tag = { - "", - NULL, - _unknown_tag_validate, - NULL, NULL, NULL +static const struct sieve_argument_def _unknown_tag = { + "", + NULL, + _unknown_tag_validate, + NULL, NULL, NULL }; static inline bool _tag_registration_is_unknown -(struct sieve_tag_registration *tag_reg) +(struct sieve_tag_registration *tag_reg) { return ( tag_reg != NULL && tag_reg->tag_def == &_unknown_tag ); } @@ -391,9 +391,9 @@ static inline bool _tag_registration_is_unknown /* Registry functions */ static void _sieve_validator_register_tag -(struct sieve_validator *valdtr, struct sieve_command_registration *cmd_reg, - const struct sieve_extension *ext, const struct sieve_argument_def *tag_def, - const char *identifier, int id_code) +(struct sieve_validator *valdtr, struct sieve_command_registration *cmd_reg, + const struct sieve_extension *ext, const struct sieve_argument_def *tag_def, + const char *identifier, int id_code) { struct sieve_tag_registration *reg; @@ -405,7 +405,7 @@ static void _sieve_validator_register_tag reg->identifier = tag_def->identifier; else reg->identifier = p_strdup(valdtr->pool, identifier); - + if ( !array_is_created(&cmd_reg->normal_tags) ) p_array_init(&cmd_reg->normal_tags, valdtr->pool, 4); @@ -415,95 +415,95 @@ static void _sieve_validator_register_tag void sieve_validator_register_persistent_tag (struct sieve_validator *valdtr, const char *command, const struct sieve_extension *ext, const struct sieve_argument_def *tag_def) -{ +{ /* Add the tag to the persistent tags list if necessary */ if ( tag_def->validate_persistent != NULL ) { - struct sieve_command_registration *cmd_reg = + struct sieve_command_registration *cmd_reg = sieve_validator_find_command_registration(valdtr, command); - + if ( cmd_reg == NULL ) { cmd_reg = _sieve_validator_register_command(valdtr, NULL, NULL, command); - } + } struct sieve_tag_registration *reg; - + reg = p_new(valdtr->pool, struct sieve_tag_registration, 1); reg->ext = ext; reg->tag_def = tag_def; reg->id_code = -1; - if ( !array_is_created(&cmd_reg->persistent_tags) ) + if ( !array_is_created(&cmd_reg->persistent_tags) ) p_array_init(&cmd_reg->persistent_tags, valdtr->pool, 4); - + array_append(&cmd_reg->persistent_tags, ®, 1); } } void sieve_validator_register_external_tag -(struct sieve_validator *valdtr, const char *command, +(struct sieve_validator *valdtr, const char *command, const struct sieve_extension *ext, const struct sieve_argument_def *tag_def, - int id_code) + int id_code) { - struct sieve_command_registration *cmd_reg = + struct sieve_command_registration *cmd_reg = sieve_validator_find_command_registration(valdtr, command); - + if ( cmd_reg == NULL ) { cmd_reg = _sieve_validator_register_command(valdtr, NULL, NULL, command); } - + _sieve_validator_register_tag (valdtr, cmd_reg, ext, tag_def, NULL, id_code); } void sieve_validator_register_tag -(struct sieve_validator *valdtr, struct sieve_command_registration *cmd_reg, - const struct sieve_extension *ext, const struct sieve_argument_def *tag_def, - int id_code) +(struct sieve_validator *valdtr, struct sieve_command_registration *cmd_reg, + const struct sieve_extension *ext, const struct sieve_argument_def *tag_def, + int id_code) { if ( tag_def->is_instance_of == NULL ) _sieve_validator_register_tag(valdtr, cmd_reg, ext, tag_def, NULL, id_code); else { - struct sieve_tag_registration *reg = + struct sieve_tag_registration *reg = p_new(valdtr->pool, struct sieve_tag_registration, 1); - reg->ext = ext; + reg->ext = ext; reg->tag_def = tag_def; reg->id_code = id_code; - if ( !array_is_created(&cmd_reg->instanced_tags) ) + if ( !array_is_created(&cmd_reg->instanced_tags) ) p_array_init(&cmd_reg->instanced_tags, valdtr->pool, 4); - + array_append(&cmd_reg->instanced_tags, ®, 1); } } static void sieve_validator_register_unknown_tag -(struct sieve_validator *valdtr, struct sieve_command_registration *cmd_reg, - const char *tag) +(struct sieve_validator *valdtr, struct sieve_command_registration *cmd_reg, + const char *tag) { _sieve_validator_register_tag(valdtr, cmd_reg, NULL, &_unknown_tag, tag, 0); } static struct sieve_tag_registration *_sieve_validator_command_tag_get -(struct sieve_validator *valdtr, struct sieve_command *cmd, +(struct sieve_validator *valdtr, struct sieve_command *cmd, const char *tag, void **data) { struct sieve_command_registration *cmd_reg = cmd->reg; struct sieve_tag_registration * const *regs; unsigned int i, reg_count; - + /* First check normal tags */ if ( array_is_created(&cmd_reg->normal_tags) ) { regs = array_get(&cmd_reg->normal_tags, ®_count); for ( i = 0; i < reg_count; i++ ) { - if ( regs[i]->tag_def != NULL && + if ( regs[i]->tag_def != NULL && strcasecmp(regs[i]->identifier, tag) == 0) { return regs[i]; } } - } - + } + /* Not found so far, try the instanced tags */ if ( array_is_created(&cmd_reg->instanced_tags) ) { regs = array_get(&cmd_reg->instanced_tags, ®_count); @@ -516,18 +516,18 @@ static struct sieve_tag_registration *_sieve_validator_command_tag_get } } } - + return NULL; } static bool sieve_validator_command_tag_exists -(struct sieve_validator *valdtr, struct sieve_command *cmd, const char *tag) +(struct sieve_validator *valdtr, struct sieve_command *cmd, const char *tag) { - return ( _sieve_validator_command_tag_get(valdtr, cmd, tag, NULL) != NULL ); + return ( _sieve_validator_command_tag_get(valdtr, cmd, tag, NULL) != NULL ); } static struct sieve_tag_registration *sieve_validator_command_tag_get -(struct sieve_validator *valdtr, struct sieve_command *cmd, +(struct sieve_validator *valdtr, struct sieve_command *cmd, struct sieve_ast_argument *arg, void **data) { const char *tag = sieve_ast_argument_tag(arg); @@ -535,8 +535,8 @@ static struct sieve_tag_registration *sieve_validator_command_tag_get return _sieve_validator_command_tag_get(valdtr, cmd, tag, data); } -/* - * Extension support +/* + * Extension support */ bool sieve_validator_extension_load @@ -547,7 +547,7 @@ bool sieve_validator_extension_load struct sieve_validator_extension_reg *reg; if ( ext->global && (valdtr->flags & SIEVE_COMPILE_FLAG_NOGLOBAL) != 0 ) { - sieve_argument_validate_error(valdtr, ext_arg, + sieve_argument_validate_error(valdtr, ext_arg, "%s %s: failed to load Sieve capability `%s': " "its use is restricted to global scripts", sieve_command_identifier(cmd), sieve_command_type_name(cmd), @@ -557,16 +557,16 @@ bool sieve_validator_extension_load if ( !sieve_ast_extension_link(valdtr->ast, ext) ) { /*if ( cmd != NULL && ext_arg != NULL ) { - sieve_argument_validate_warning(valdtr, ext_arg, + sieve_argument_validate_warning(valdtr, ext_arg, "%s %s: sieve capability `%s' already loaded", sieve_command_identifier(cmd), sieve_command_type_name(cmd), sieve_extension_name(ext)); }*/ } else { - if ( extdef->validator_load != NULL && + if ( extdef->validator_load != NULL && !extdef->validator_load(ext, valdtr) ) { if ( cmd != NULL && ext_arg != NULL ) { - sieve_argument_validate_error(valdtr, ext_arg, + sieve_argument_validate_error(valdtr, ext_arg, "%s %s: failed to load Sieve capability `%s'", sieve_command_identifier(cmd), sieve_command_type_name(cmd), sieve_extension_name(ext)); @@ -575,7 +575,7 @@ bool sieve_validator_extension_load } } - /* Register extension no matter what and store the AST argument registering it + /* Register extension no matter what and store the AST argument registering it */ if ( ext->id >= 0 ) { reg = array_idx_modifiable(&valdtr->extensions, (unsigned int) ext->id); @@ -589,11 +589,11 @@ bool sieve_validator_extension_load const struct sieve_extension *sieve_validator_extension_load_by_name (struct sieve_validator *valdtr, struct sieve_command *cmd, - struct sieve_ast_argument *ext_arg, const char *ext_name) + struct sieve_ast_argument *ext_arg, const char *ext_name) { const struct sieve_extension *ext; - ext = sieve_extension_get_by_name(valdtr->svinst, ext_name); + ext = sieve_extension_get_by_name(valdtr->svinst, ext_name); if ( ext == NULL || ext->def == NULL || !ext->enabled ) { unsigned int i; @@ -618,7 +618,7 @@ const struct sieve_extension *sieve_validator_extension_load_by_name str_sanitize(ext_name, 128), ( core_test ? "test" : "command" )); } else { sieve_argument_validate_error(valdtr, ext_arg, - "%s %s: unknown Sieve capability `%s'", + "%s %s: unknown Sieve capability `%s'", sieve_command_identifier(cmd), sieve_command_type_name(cmd), str_sanitize(ext_name, 128)); } @@ -636,7 +636,7 @@ const struct sieve_extension *sieve_validator_extension_load_implicit { const struct sieve_extension *ext; - ext = sieve_extension_get_by_name(valdtr->svinst, ext_name); + ext = sieve_extension_get_by_name(valdtr->svinst, ext_name); if ( ext == NULL || ext->def == NULL ) return NULL; @@ -654,7 +654,7 @@ void sieve_validator_extension_register struct sieve_validator_extension_reg *reg; if ( ext->id < 0 ) return; - + reg = array_idx_modifiable(&valdtr->extensions, (unsigned int) ext->id); reg->valext = valext; reg->ext = ext; @@ -675,47 +675,47 @@ bool sieve_validator_extension_loaded } void sieve_validator_extension_set_context -(struct sieve_validator *valdtr, const struct sieve_extension *ext, +(struct sieve_validator *valdtr, const struct sieve_extension *ext, void *context) { struct sieve_validator_extension_reg *reg; if ( ext->id < 0 ) return; - + reg = array_idx_modifiable(&valdtr->extensions, (unsigned int) ext->id); reg->context = context; } void *sieve_validator_extension_get_context -(struct sieve_validator *valdtr, const struct sieve_extension *ext) +(struct sieve_validator *valdtr, const struct sieve_extension *ext) { const struct sieve_validator_extension_reg *reg; if ( ext->id < 0 || ext->id >= (int) array_count(&valdtr->extensions) ) return NULL; - - reg = array_idx(&valdtr->extensions, (unsigned int) ext->id); + + reg = array_idx(&valdtr->extensions, (unsigned int) ext->id); return reg->context; } -/* +/* * Overriding the default literal arguments */ void sieve_validator_argument_override -(struct sieve_validator *valdtr, enum sieve_argument_type type, +(struct sieve_validator *valdtr, enum sieve_argument_type type, const struct sieve_extension *ext, const struct sieve_argument_def *arg_def) { struct sieve_default_argument *arg; - + if ( valdtr->default_arguments[type].arg_def != NULL ) { arg = p_new(valdtr->pool, struct sieve_default_argument, 1); - *arg = valdtr->default_arguments[type]; - + *arg = valdtr->default_arguments[type]; + valdtr->default_arguments[type].overrides = arg; } - + valdtr->default_arguments[type].arg_def = arg_def; valdtr->default_arguments[type].ext = ext; } @@ -726,36 +726,36 @@ static bool sieve_validator_argument_default_activate { bool result = TRUE; struct sieve_default_argument *prev_defarg; - + prev_defarg = valdtr->current_defarg; valdtr->current_defarg = defarg; - + if ( arg->argument == NULL ) { arg->argument = sieve_argument_create (arg->ast, defarg->arg_def, defarg->ext, 0); - } else { + } else { arg->argument->def = defarg->arg_def; arg->argument->ext = defarg->ext; } if (defarg->arg_def != NULL && defarg->arg_def->validate != NULL ) - result = defarg->arg_def->validate(valdtr, &arg, cmd); - - valdtr->current_defarg = prev_defarg; - + result = defarg->arg_def->validate(valdtr, &arg, cmd); + + valdtr->current_defarg = prev_defarg; + return result; } bool sieve_validator_argument_activate_super -(struct sieve_validator *valdtr, struct sieve_command *cmd, +(struct sieve_validator *valdtr, struct sieve_command *cmd, struct sieve_ast_argument *arg, bool constant ATTR_UNUSED) { struct sieve_default_argument *defarg; - if ( valdtr->current_defarg == NULL || + if ( valdtr->current_defarg == NULL || valdtr->current_defarg->overrides == NULL ) return FALSE; - + if ( valdtr->current_defarg->overrides->arg_def == &string_argument ) { switch ( valdtr->current_defarg_type) { case SAT_CONST_STRING: @@ -773,23 +773,23 @@ bool sieve_validator_argument_activate_super } } else defarg = valdtr->current_defarg->overrides; - + return sieve_validator_argument_default_activate (valdtr, cmd, defarg, arg); } -/* - * Argument Validation API +/* + * Argument Validation API */ bool sieve_validator_argument_activate -(struct sieve_validator *valdtr, struct sieve_command *cmd, +(struct sieve_validator *valdtr, struct sieve_command *cmd, struct sieve_ast_argument *arg, bool constant) { struct sieve_default_argument *defarg; - + switch ( sieve_ast_argument_type(arg) ) { - case SAAT_NUMBER: + case SAAT_NUMBER: valdtr->current_defarg_type = SAT_NUMBER; break; case SAAT_STRING: @@ -809,7 +809,7 @@ bool sieve_validator_argument_activate valdtr->current_defarg_type = SAT_VAR_STRING; defarg = &valdtr->default_arguments[SAT_VAR_STRING]; } - + return sieve_validator_argument_default_activate(valdtr, cmd, defarg, arg); } @@ -820,18 +820,18 @@ bool sieve_validate_positional_argument { i_assert( arg != NULL ); - if ( sieve_ast_argument_type(arg) != req_type && - (sieve_ast_argument_type(arg) != SAAT_STRING || - req_type != SAAT_STRING_LIST) ) + if ( sieve_ast_argument_type(arg) != req_type && + (sieve_ast_argument_type(arg) != SAAT_STRING || + req_type != SAAT_STRING_LIST) ) { - sieve_argument_validate_error(valdtr, arg, - "the %s %s expects %s as argument %d (%s), but %s was found", - sieve_command_identifier(cmd), sieve_command_type_name(cmd), + sieve_argument_validate_error(valdtr, arg, + "the %s %s expects %s as argument %d (%s), but %s was found", + sieve_command_identifier(cmd), sieve_command_type_name(cmd), sieve_ast_argument_type_name(req_type), arg_pos, arg_name, sieve_ast_argument_name(arg)); - return FALSE; + return FALSE; } - + return TRUE; } @@ -844,25 +844,25 @@ bool sieve_validate_tag_parameter if ( param == NULL ) { const char *position = ( arg_pos == 0 ? "" : t_strdup_printf(" %d (%s)", arg_pos, arg_name) ); - - sieve_argument_validate_error(valdtr, tag, + + sieve_argument_validate_error(valdtr, tag, "the :%s tag for the %s %s requires %s as parameter %s, " - "but no parameters were found", sieve_ast_argument_tag(tag), + "but no parameters were found", sieve_ast_argument_tag(tag), sieve_command_identifier(cmd), sieve_command_type_name(cmd), sieve_ast_argument_type_name(req_type), position); - return FALSE; + return FALSE; } - if ( sieve_ast_argument_type(param) != req_type && - (sieve_ast_argument_type(param) != SAAT_STRING || - req_type != SAAT_STRING_LIST) ) + if ( sieve_ast_argument_type(param) != req_type && + (sieve_ast_argument_type(param) != SAAT_STRING || + req_type != SAAT_STRING_LIST) ) { const char *position = ( arg_pos == 0 ? "" : t_strdup_printf(" %d (%s)", arg_pos, arg_name) ); - sieve_argument_validate_error(valdtr, param, + sieve_argument_validate_error(valdtr, param, "the :%s tag for the %s %s requires %s as parameter%s, " - "but %s was found", sieve_ast_argument_tag(tag), + "but %s was found", sieve_ast_argument_tag(tag), sieve_command_identifier(cmd), sieve_command_type_name(cmd), sieve_ast_argument_type_name(req_type), position, sieve_ast_argument_name(param)); @@ -877,12 +877,12 @@ bool sieve_validate_tag_parameter return TRUE; } -/* - * Command argument validation +/* + * Command argument validation */ static bool sieve_validate_command_arguments -(struct sieve_validator *valdtr, struct sieve_command *cmd) +(struct sieve_validator *valdtr, struct sieve_command *cmd) { int arg_count = cmd->def->positional_arguments; int real_count = 0; @@ -891,30 +891,30 @@ static bool sieve_validate_command_arguments /* Validate any tags that might be present */ arg = sieve_ast_argument_first(cmd->ast_node); - + /* Visit tagged and optional arguments */ while ( arg != NULL && sieve_ast_argument_type(arg) == SAAT_TAG ) { struct sieve_ast_argument *parg; - void *arg_data = NULL; - struct sieve_tag_registration *tag_reg = + void *arg_data = NULL; + struct sieve_tag_registration *tag_reg = sieve_validator_command_tag_get(valdtr, cmd, arg, &arg_data); const struct sieve_argument_def *tag_def; - + if ( tag_reg == NULL ) { - sieve_argument_validate_error(valdtr, arg, + sieve_argument_validate_error(valdtr, arg, "unknown tagged argument ':%s' for the %s %s " "(reported only once at first occurence)", - sieve_ast_argument_tag(arg), sieve_command_identifier(cmd), + sieve_ast_argument_tag(arg), sieve_command_identifier(cmd), sieve_command_type_name(cmd)); sieve_validator_register_unknown_tag (valdtr, cmd_reg, sieve_ast_argument_tag(arg)); - return FALSE; + return FALSE; } - + /* Check whether previously tagged as unknown */ - if ( _tag_registration_is_unknown(tag_reg) ) + if ( _tag_registration_is_unknown(tag_reg) ) return FALSE; - + tag_def = tag_reg->tag_def; /* Assign the tagged argument type to the ast for later reference */ @@ -925,79 +925,79 @@ static bool sieve_validate_command_arguments /* Scan backwards for any duplicates */ parg = sieve_ast_argument_prev(arg); while ( parg != NULL ) { - if ( (sieve_ast_argument_type(parg) == SAAT_TAG && - parg->argument->def == tag_reg->tag_def) - || (tag_reg->id_code > 0 && parg->argument != NULL && - parg->argument->id_code == tag_reg->id_code) ) + if ( (sieve_ast_argument_type(parg) == SAAT_TAG && + parg->argument->def == tag_reg->tag_def) + || (tag_reg->id_code > 0 && parg->argument != NULL && + parg->argument->id_code == tag_reg->id_code) ) { const char *tag_id = sieve_ast_argument_tag(arg); const char *tag_desc = strcmp(tag_def->identifier, tag_id) != 0 ? - t_strdup_printf("%s argument (:%s)", tag_def->identifier, tag_id) : - t_strdup_printf(":%s argument", tag_def->identifier); - - sieve_argument_validate_error(valdtr, arg, + t_strdup_printf("%s argument (:%s)", tag_def->identifier, tag_id) : + t_strdup_printf(":%s argument", tag_def->identifier); + + sieve_argument_validate_error(valdtr, arg, "encountered duplicate %s for the %s %s", - tag_desc, sieve_command_identifier(cmd), + tag_desc, sieve_command_identifier(cmd), sieve_command_type_name(cmd)); - - return FALSE; + + return FALSE; } - + parg = sieve_ast_argument_prev(parg); } - + /* Call the validation function for the tag (if present) * Fail if the validation fails: - * Let's not whine multiple times about a single command having multiple + * Let's not whine multiple times about a single command having multiple * bad arguments... - */ + */ if ( tag_def->validate != NULL ) { - if ( !tag_def->validate(valdtr, &arg, cmd) ) + if ( !tag_def->validate(valdtr, &arg, cmd) ) return FALSE; } else { arg = sieve_ast_argument_next(arg); } - } - + } + /* Remaining arguments should be positional (tags are not allowed here) */ cmd->first_positional = arg; - + while ( arg != NULL ) { if ( sieve_ast_argument_type(arg) == SAAT_TAG ) { - sieve_argument_validate_error(valdtr, arg, + sieve_argument_validate_error(valdtr, arg, "encountered an unexpected tagged argument ':%s' " "while validating positional arguments for the %s %s", - sieve_ast_argument_tag(arg), sieve_command_identifier(cmd), + sieve_ast_argument_tag(arg), sieve_command_identifier(cmd), sieve_command_type_name(cmd)); return FALSE; } - + real_count++; - + arg = sieve_ast_argument_next(arg); } - + /* Check the required count versus the real number of arguments */ if ( arg_count >= 0 && real_count != arg_count ) { - sieve_command_validate_error(valdtr, cmd, + sieve_command_validate_error(valdtr, cmd, "the %s %s requires %d positional argument(s), but %d is/are specified", - sieve_command_identifier(cmd), sieve_command_type_name(cmd), + sieve_command_identifier(cmd), sieve_command_type_name(cmd), arg_count, real_count); return FALSE; } - + /* Call initial validation for persistent arguments */ if ( array_is_created(&cmd_reg->persistent_tags) ) { struct sieve_tag_registration * const *regs; unsigned int i, reg_count; - - regs = array_get(&cmd_reg->persistent_tags, ®_count); + + regs = array_get(&cmd_reg->persistent_tags, ®_count); for ( i = 0; i < reg_count; i++ ) { - + const struct sieve_argument_def *tag_def = regs[i]->tag_def; - - if ( tag_def != NULL && tag_def->validate_persistent != NULL ) { + + if ( tag_def != NULL && tag_def->validate_persistent != NULL ) { /* To be sure */ if ( !tag_def->validate_persistent(valdtr, cmd, regs[i]->ext) ) return FALSE; @@ -1010,36 +1010,36 @@ static bool sieve_validate_command_arguments static bool sieve_validate_arguments_context (struct sieve_validator *valdtr, struct sieve_command *cmd) -{ - struct sieve_ast_argument *arg = +{ + struct sieve_ast_argument *arg = sieve_command_first_argument(cmd); - + while ( arg != NULL ) { const struct sieve_argument *argument = arg->argument; - - if ( argument != NULL && argument->def != NULL && + + if ( argument != NULL && argument->def != NULL && argument->def->validate_context != NULL ) { - - if ( !argument->def->validate_context(valdtr, arg, cmd) ) + + if ( !argument->def->validate_context(valdtr, arg, cmd) ) return FALSE; } - + arg = sieve_ast_argument_next(arg); } return TRUE; } - -/* - * Command Validation API - */ - + +/* + * Command Validation API + */ + static bool sieve_validate_command_subtests -(struct sieve_validator *valdtr, struct sieve_command *cmd, - const unsigned int count) +(struct sieve_validator *valdtr, struct sieve_command *cmd, + const unsigned int count) { switch ( count ) { - + case 0: if ( sieve_ast_test_count(cmd->ast_node) > 0 ) { /* Unexpected command specified */ @@ -1049,7 +1049,7 @@ static bool sieve_validate_command_subtests cmd_reg = sieve_validator_find_command_registration (valdtr, test->identifier); - + /* First check what we are dealing with */ if ( cmd_reg != NULL && cmd_reg->cmd_def != NULL ) ctype = cmd_reg->cmd_def->type; @@ -1057,8 +1057,8 @@ static bool sieve_validate_command_subtests switch ( ctype ) { case SCT_TEST: /* Spurious test */ case SCT_HYBRID: - sieve_command_validate_error(valdtr, cmd, - "the %s %s accepts no sub-tests, but tests are specified", + sieve_command_validate_error(valdtr, cmd, + "the %s %s accepts no sub-tests, but tests are specified", sieve_command_identifier(cmd), sieve_command_type_name(cmd)); break; @@ -1067,16 +1067,16 @@ static bool sieve_validate_command_subtests /* Is it perhaps a tag for which the ':' was omitted ? */ if ( sieve_validator_command_tag_exists (valdtr, cmd, test->identifier) ) { - sieve_command_validate_error(valdtr, cmd, - "missing colon ':' before ':%s' tag in %s %s", test->identifier, + sieve_command_validate_error(valdtr, cmd, + "missing colon ':' before ':%s' tag in %s %s", test->identifier, sieve_command_identifier(cmd), sieve_command_type_name(cmd)); break; - } + } /* Fall through */ - + case SCT_COMMAND: - sieve_command_validate_error(valdtr, cmd, - "missing semicolon ';' after %s %s", + sieve_command_validate_error(valdtr, cmd, + "missing semicolon ';' after %s %s", sieve_command_identifier(cmd), sieve_command_type_name(cmd)); break; } @@ -1085,98 +1085,98 @@ static bool sieve_validate_command_subtests break; case 1: if ( sieve_ast_test_count(cmd->ast_node) == 0 ) { - sieve_command_validate_error(valdtr, cmd, - "the %s %s requires one sub-test, but none is specified", + sieve_command_validate_error(valdtr, cmd, + "the %s %s requires one sub-test, but none is specified", sieve_command_identifier(cmd), sieve_command_type_name(cmd)); - + return FALSE; - - } else if ( sieve_ast_test_count(cmd->ast_node) > 1 || + + } else if ( sieve_ast_test_count(cmd->ast_node) > 1 || cmd->ast_node->test_list ) { - - sieve_command_validate_error(valdtr, cmd, - "the %s %s requires one sub-test, but a list of tests is specified", + + sieve_command_validate_error(valdtr, cmd, + "the %s %s requires one sub-test, but a list of tests is specified", sieve_command_identifier(cmd), sieve_command_type_name(cmd)); - + return FALSE; } break; - + default: if ( sieve_ast_test_count(cmd->ast_node) == 0 ) { - sieve_command_validate_error(valdtr, cmd, - "the %s %s requires a list of sub-tests, but none is specified", + sieve_command_validate_error(valdtr, cmd, + "the %s %s requires a list of sub-tests, but none is specified", sieve_command_identifier(cmd), sieve_command_type_name(cmd)); - + return FALSE; - - } else if ( sieve_ast_test_count(cmd->ast_node) == 1 && + + } else if ( sieve_ast_test_count(cmd->ast_node) == 1 && !cmd->ast_node->test_list ) { - - sieve_command_validate_error(valdtr, cmd, + + sieve_command_validate_error(valdtr, cmd, "the %s %s requires a list of sub-tests, " - "but a single test is specified", + "but a single test is specified", sieve_command_identifier(cmd), sieve_command_type_name(cmd) ); - + return FALSE; } - break; + break; } return TRUE; } static bool sieve_validate_command_block -(struct sieve_validator *valdtr, struct sieve_command *cmd, - bool block_allowed, bool block_required) +(struct sieve_validator *valdtr, struct sieve_command *cmd, + bool block_allowed, bool block_required) { i_assert( cmd->ast_node->type == SAT_COMMAND ); - + if ( block_required ) { if ( !cmd->ast_node->block ) { - sieve_command_validate_error(valdtr, cmd, - "the %s command requires a command block, but it is missing", + sieve_command_validate_error(valdtr, cmd, + "the %s command requires a command block, but it is missing", sieve_command_identifier(cmd)); - + return FALSE; } } else if ( !block_allowed && cmd->ast_node->block ) { - sieve_command_validate_error(valdtr, cmd, + sieve_command_validate_error(valdtr, cmd, "the %s command does not accept a command block, " - "but one is specified anyway", + "but one is specified anyway", sieve_command_identifier(cmd) ); - + return FALSE; } - + return TRUE; -} +} -/* - * AST Validation +/* + * AST Validation */ static bool sieve_validate_test_list (struct sieve_validator *valdtr, struct sieve_ast_node *test_list, - int *const_r); + int *const_r); static bool sieve_validate_block (struct sieve_validator *valdtr, struct sieve_ast_node *block); static bool sieve_validate_command (struct sieve_validator *valdtr, struct sieve_ast_node *cmd_node, int *const_r); - + static bool sieve_validate_command_context -(struct sieve_validator *valdtr, struct sieve_ast_node *cmd_node) +(struct sieve_validator *valdtr, struct sieve_ast_node *cmd_node) { enum sieve_ast_type ast_type = sieve_ast_node_type(cmd_node); struct sieve_command_registration *cmd_reg; - + i_assert( ast_type == SAT_TEST || ast_type == SAT_COMMAND ); - + /* Verify the command specified by this node */ cmd_reg = sieve_validator_find_command_registration (valdtr, cmd_node->identifier); - + if ( cmd_reg != NULL && cmd_reg->cmd_def != NULL ) { const struct sieve_command_def *cmd_def = cmd_reg->cmd_def; @@ -1185,27 +1185,27 @@ static bool sieve_validate_command_context if ( (cmd_def->type == SCT_COMMAND && ast_type == SAT_TEST) || (cmd_def->type == SCT_TEST && ast_type == SAT_COMMAND) ) { sieve_validator_error( - valdtr, cmd_node->source_line, "attempted to use %s '%s' as %s", + valdtr, cmd_node->source_line, "attempted to use %s '%s' as %s", sieve_command_def_type_name(cmd_def), cmd_node->identifier, sieve_ast_type_name(ast_type)); - + return FALSE; - } - + } + cmd_node->command = - sieve_command_create(cmd_node, cmd_reg->ext, cmd_def, cmd_reg); + sieve_command_create(cmd_node, cmd_reg->ext, cmd_def, cmd_reg); } else { return FALSE; } } else { sieve_validator_error( - valdtr, cmd_node->source_line, - "unknown %s '%s' (only reported once at first occurence)", + valdtr, cmd_node->source_line, + "unknown %s '%s' (only reported once at first occurence)", sieve_ast_type_name(ast_type), cmd_node->identifier); - + sieve_validator_register_unknown_command(valdtr, cmd_node->identifier); - + return FALSE; } @@ -1213,23 +1213,23 @@ static bool sieve_validate_command_context } static bool sieve_validate_command -(struct sieve_validator *valdtr, struct sieve_ast_node *cmd_node, int *const_r) +(struct sieve_validator *valdtr, struct sieve_ast_node *cmd_node, int *const_r) { enum sieve_ast_type ast_type = sieve_ast_node_type(cmd_node); struct sieve_command *cmd = ( cmd_node == NULL ? NULL : cmd_node->command ); const struct sieve_command_def *cmd_def = ( cmd != NULL ? cmd->def : NULL ); bool result = TRUE; - + i_assert( ast_type == SAT_TEST || ast_type == SAT_COMMAND ); if ( cmd_def != NULL && *(cmd_def->identifier) != '\0' ) { - - if ( cmd_def->pre_validate == NULL + + if ( cmd_def->pre_validate == NULL || cmd_def->pre_validate(valdtr, cmd) ) { - + /* Check argument syntax */ if ( !sieve_validate_command_arguments(valdtr, cmd) ) { - result = FALSE; + result = FALSE; /* A missing ':' causes a tag to become a test. This can be the cause * of the arguments validation failing. Therefore we must produce an @@ -1238,7 +1238,7 @@ static bool sieve_validate_command (void)sieve_validate_command_subtests(valdtr, cmd, cmd_def->subtests); } else if ( - !sieve_validate_command_subtests(valdtr, cmd, cmd_def->subtests) || + !sieve_validate_command_subtests(valdtr, cmd, cmd_def->subtests) || (ast_type == SAT_COMMAND && !sieve_validate_command_block (valdtr, cmd, cmd_def->block_allowed, cmd_def->block_required)) ) { @@ -1250,26 +1250,26 @@ static bool sieve_validate_command result = cmd_def->validate(valdtr, cmd) && result; } } else { - /* If pre-validation fails, don't bother to validate further - * as context might be missing and doing so is not very useful for + /* If pre-validation fails, don't bother to validate further + * as context might be missing and doing so is not very useful for * further error reporting anyway */ return FALSE; } - - result = result && sieve_validate_arguments_context(valdtr, cmd); + + result = result && sieve_validate_arguments_context(valdtr, cmd); } - /* - * Descend further into the AST + /* + * Descend further into the AST */ - + if ( cmd_def != NULL ) { /* Tests */ - if ( cmd_def->subtests > 0 ) { + if ( cmd_def->subtests > 0 ) { if ( result || sieve_errors_more_allowed(valdtr->ehandler) ) { result = sieve_validate_test_list(valdtr, cmd_node, const_r) && result; - } + } } else if ( result ) { if ( cmd_def->validate_const != NULL ) { (void)cmd_def->validate_const(valdtr, cmd, const_r, -1); @@ -1285,18 +1285,18 @@ static bool sieve_validate_command return TRUE; /* Command block */ - if ( cmd_def->block_allowed && ast_type == SAT_COMMAND && + if ( cmd_def->block_allowed && ast_type == SAT_COMMAND && (result || sieve_errors_more_allowed(valdtr->ehandler)) ) { result = sieve_validate_block(valdtr, cmd_node) && result; } } - + return result; } static bool sieve_validate_test_list (struct sieve_validator *valdtr, struct sieve_ast_node *test_node, - int *const_r) + int *const_r) { struct sieve_command *tst = test_node->command; const struct sieve_command_def *tst_def = ( tst != NULL ? tst->def : NULL ); @@ -1304,54 +1304,54 @@ static bool sieve_validate_test_list bool result = TRUE; if ( tst_def != NULL && tst_def->validate_const != NULL ) { - if ( !tst_def->validate_const(valdtr, tst, const_r, -2) ) + if ( !tst_def->validate_const(valdtr, tst, const_r, -2) ) return TRUE; } test = sieve_ast_test_first(test_node); - while ( test != NULL + while ( test != NULL && (result || sieve_errors_more_allowed(valdtr->ehandler)) ) { int const_value = -2; - - result = - sieve_validate_command_context(valdtr, test) && + + result = + sieve_validate_command_context(valdtr, test) && sieve_validate_command(valdtr, test, &const_value) && result; if ( result ) { if ( tst_def != NULL && tst_def->validate_const != NULL ) { - if ( !tst_def->validate_const(valdtr, tst, const_r, const_value) ) + if ( !tst_def->validate_const(valdtr, tst, const_r, const_value) ) return TRUE; } else { *const_r = -1; } } - + if ( result && const_value >= 0 ) test = sieve_ast_node_detach(test); else test = sieve_ast_test_next(test); - } - + } + return result; } static bool sieve_validate_block -(struct sieve_validator *valdtr, struct sieve_ast_node *block) +(struct sieve_validator *valdtr, struct sieve_ast_node *block) { bool result = TRUE, fatal = FALSE; struct sieve_ast_node *cmd_node, *next; - T_BEGIN { + T_BEGIN { cmd_node = sieve_ast_command_first(block); while ( !fatal && cmd_node != NULL - && (result || sieve_errors_more_allowed(valdtr->ehandler)) ) { + && (result || sieve_errors_more_allowed(valdtr->ehandler)) ) { bool command_success; int const_value = -2; next = sieve_ast_command_next(cmd_node); command_success = sieve_validate_command_context(valdtr, cmd_node); - result = command_success && result; + result = command_success && result; /* Check if this is the first non-require command */ if ( command_success && sieve_ast_node_type(block) == SAT_ROOT @@ -1365,29 +1365,29 @@ static bool sieve_validate_block /* Validate all 'require'd extensions */ extrs = array_get(&valdtr->extensions, &ext_count); for ( i = 0; i < ext_count; i++ ) { - if ( extrs[i].valext != NULL + if ( extrs[i].valext != NULL && extrs[i].valext->validate != NULL ) { if ( !extrs[i].valext->validate (extrs[i].ext, valdtr, extrs[i].context, extrs[i].arg) ) fatal = TRUE; break; - } + } } } result = !fatal && sieve_validate_command(valdtr, cmd_node, &const_value) && result; - + cmd_node = next; - } + } } T_END; - + return result && !fatal; } -bool sieve_validator_run(struct sieve_validator *valdtr) -{ +bool sieve_validator_run(struct sieve_validator *valdtr) +{ return sieve_validate_block(valdtr, sieve_ast_root(valdtr->ast)); } @@ -1408,13 +1408,13 @@ struct sieve_validator_object_registry { struct sieve_validator_object_registry *sieve_validator_object_registry_get (struct sieve_validator *valdtr, const struct sieve_extension *ext) { - return (struct sieve_validator_object_registry *) + return (struct sieve_validator_object_registry *) sieve_validator_extension_get_context(valdtr, ext); } void sieve_validator_object_registry_add (struct sieve_validator_object_registry *regs, - const struct sieve_extension *ext, const struct sieve_object_def *obj_def) + const struct sieve_extension *ext, const struct sieve_object_def *obj_def) { struct sieve_validator_object_reg *reg; @@ -1425,12 +1425,12 @@ void sieve_validator_object_registry_add bool sieve_validator_object_registry_find (struct sieve_validator_object_registry *regs, const char *identifier, - struct sieve_object *obj) + struct sieve_object *obj) { unsigned int i; for ( i = 0; i < array_count(®s->registrations); i++ ) { - const struct sieve_validator_object_reg *reg = + const struct sieve_validator_object_reg *reg = array_idx(®s->registrations, i); if ( strcasecmp(reg->obj_def->identifier, identifier) == 0) { @@ -1449,10 +1449,10 @@ struct sieve_validator_object_registry *sieve_validator_object_registry_create (struct sieve_validator *valdtr) { pool_t pool = valdtr->pool; - struct sieve_validator_object_registry *regs = + struct sieve_validator_object_registry *regs = p_new(pool, struct sieve_validator_object_registry, 1); - - /* Setup registry */ + + /* Setup registry */ p_array_init(®s->registrations, valdtr->pool, 4); regs->valdtr = valdtr; @@ -1463,9 +1463,9 @@ struct sieve_validator_object_registry *sieve_validator_object_registry_create struct sieve_validator_object_registry *sieve_validator_object_registry_init (struct sieve_validator *valdtr, const struct sieve_extension *ext) { - struct sieve_validator_object_registry *regs = + struct sieve_validator_object_registry *regs = sieve_validator_object_registry_create(valdtr); - + sieve_validator_extension_set_context(valdtr, ext, regs); return regs; } diff --git a/src/lib-sieve/sieve-validator.h b/src/lib-sieve/sieve-validator.h index 86641d906479f453687c0a4a500232c2e0de7728..ce10d60244e51d4ff8468f9b2b98e76999d8c5ea 100644 --- a/src/lib-sieve/sieve-validator.h +++ b/src/lib-sieve/sieve-validator.h @@ -1,6 +1,6 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #ifndef __SIEVE_VALIDATOR_H #define __SIEVE_VALIDATOR_H @@ -17,7 +17,7 @@ enum sieve_argument_type { SAT_CONST_STRING, SAT_VAR_STRING, SAT_STRING_LIST, - + SAT_COUNT }; @@ -26,7 +26,7 @@ struct sieve_command_registration; /* * Validator */ - + struct sieve_validator; struct sieve_validator *sieve_validator_create @@ -40,7 +40,7 @@ bool sieve_validator_run(struct sieve_validator *valdtr); /* * Accessors */ - + struct sieve_error_handler *sieve_validator_error_handler (struct sieve_validator *valdtr); struct sieve_ast *sieve_validator_ast @@ -57,52 +57,52 @@ enum sieve_compile_flags sieve_validator_compile_flags */ void sieve_validator_warning - (struct sieve_validator *valdtr, unsigned int source_line, + (struct sieve_validator *valdtr, unsigned int source_line, const char *fmt, ...) ATTR_FORMAT(3, 4); void sieve_validator_error - (struct sieve_validator *valdtr, unsigned int source_line, + (struct sieve_validator *valdtr, unsigned int source_line, const char *fmt, ...) ATTR_FORMAT(3, 4); void sieve_validator_critical - (struct sieve_validator *valdtr, unsigned int source_line, + (struct sieve_validator *valdtr, unsigned int source_line, const char *fmt, ...) ATTR_FORMAT(3, 4); - -/* + +/* * Command/Test registry */ - + void sieve_validator_register_command (struct sieve_validator *valdtr, const struct sieve_extension *ext, const struct sieve_command_def *command); - -/* + +/* * Per-command tagged argument registry */ void sieve_validator_register_tag (struct sieve_validator *valdtr, struct sieve_command_registration *cmd_reg, - const struct sieve_extension *ext, const struct sieve_argument_def *tag_def, + const struct sieve_extension *ext, const struct sieve_argument_def *tag_def, int id_code); void sieve_validator_register_external_tag - (struct sieve_validator *valdtr, const char *command, + (struct sieve_validator *valdtr, const char *command, const struct sieve_extension *ext, const struct sieve_argument_def *tag_def, int id_code); void sieve_validator_register_persistent_tag (struct sieve_validator *valdtr, const char *command, - const struct sieve_extension *ext, + const struct sieve_extension *ext, const struct sieve_argument_def *tag_def); - + /* * Overriding the default literal arguments - */ - + */ + void sieve_validator_argument_override -(struct sieve_validator *valdtr, enum sieve_argument_type type, +(struct sieve_validator *valdtr, enum sieve_argument_type type, const struct sieve_extension *ext, const struct sieve_argument_def *arg_def); bool sieve_validator_argument_activate_super -(struct sieve_validator *valdtr, struct sieve_command *cmd, +(struct sieve_validator *valdtr, struct sieve_command *cmd, struct sieve_ast_argument *arg, bool constant); - -/* + +/* * Argument validation API */ @@ -113,26 +113,26 @@ bool sieve_validate_positional_argument bool sieve_validator_argument_activate (struct sieve_validator *valdtr, struct sieve_command *cmd, struct sieve_ast_argument *arg, bool constant); - + bool sieve_validate_tag_parameter (struct sieve_validator *valdtr, struct sieve_command *cmd, struct sieve_ast_argument *tag, struct sieve_ast_argument *param, const char *arg_name, unsigned int arg_pos, enum sieve_ast_argument_type req_type, bool constant); - -/* + +/* * Extension support */ struct sieve_validator_extension { - const struct sieve_extension_def *ext; + const struct sieve_extension_def *ext; bool (*validate) - (const struct sieve_extension *ext, struct sieve_validator *valdtr, + (const struct sieve_extension *ext, struct sieve_validator *valdtr, void *context, struct sieve_ast_argument *require_arg); void (*free) - (const struct sieve_extension *ext, struct sieve_validator *valdtr, + (const struct sieve_extension *ext, struct sieve_validator *valdtr, void *context); }; @@ -152,7 +152,7 @@ bool sieve_validator_extension_loaded (struct sieve_validator *valdtr, const struct sieve_extension *ext); void sieve_validator_extension_set_context -(struct sieve_validator *valdtr, const struct sieve_extension *ext, +(struct sieve_validator *valdtr, const struct sieve_extension *ext, void *context); void *sieve_validator_extension_get_context (struct sieve_validator *valdtr, const struct sieve_extension *ext); diff --git a/src/lib-sieve/sieve.c b/src/lib-sieve/sieve.c index cfb3e7d3ea12ed37a0d8102f875707bf1d706aef..3d60dc7aaca64abf2e7061bfee50b5a49fc16700 100644 --- a/src/lib-sieve/sieve.c +++ b/src/lib-sieve/sieve.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ #include "lib.h" @@ -38,7 +38,7 @@ #include <stdio.h> #include <dirent.h> -/* +/* * Main Sieve library interface */ @@ -76,7 +76,7 @@ struct sieve_instance *sieve_init (svinst, "sieve_max_script_size", &size_setting) ) { svinst->max_script_size = size_setting; } - + if ( sieve_setting_get_uint_value (svinst, "sieve_max_actions", &uint_setting) ) { svinst->max_actions = (unsigned int) uint_setting; @@ -86,7 +86,7 @@ struct sieve_instance *sieve_init (svinst, "sieve_max_redirects", &uint_setting) ) { svinst->max_redirects = (unsigned int) uint_setting; } - + /* Initialize extensions */ if ( !sieve_extensions_init(svinst) ) { sieve_deinit(&svinst); @@ -129,7 +129,7 @@ const char *sieve_get_capabilities } /* - * Low-level compiler functions + * Low-level compiler functions */ struct sieve_ast *sieve_parse @@ -138,17 +138,17 @@ struct sieve_ast *sieve_parse { struct sieve_parser *parser; struct sieve_ast *ast = NULL; - + /* Parse */ if ( (parser = sieve_parser_create(script, ehandler, error_r)) == NULL ) return NULL; if ( !sieve_parser_run(parser, &ast) ) { ast = NULL; - } else + } else sieve_ast_ref(ast); - - sieve_parser_free(&parser); + + sieve_parser_free(&parser); if ( error_r != NULL ) { if ( ast == NULL ) @@ -156,7 +156,7 @@ struct sieve_ast *sieve_parse else *error_r = SIEVE_ERROR_NONE; } - + return ast; } @@ -167,11 +167,11 @@ bool sieve_validate bool result = TRUE; struct sieve_validator *validator = sieve_validator_create(ast, ehandler, flags); - - if ( !sieve_validator_run(validator) ) + + if ( !sieve_validator_run(validator) ) result = FALSE; - - sieve_validator_free(&validator); + + sieve_validator_free(&validator); if ( error_r != NULL ) { if ( !result ) @@ -179,22 +179,22 @@ bool sieve_validate else *error_r = SIEVE_ERROR_NONE; } - + return result; } static struct sieve_binary *sieve_generate -(struct sieve_ast *ast, struct sieve_error_handler *ehandler, +(struct sieve_ast *ast, struct sieve_error_handler *ehandler, enum sieve_compile_flags flags, enum sieve_error *error_r) { struct sieve_generator *generator = sieve_generator_create(ast, ehandler, flags); struct sieve_binary *sbin = NULL; - + sbin = sieve_generator_run(generator, NULL); - + sieve_generator_free(&generator); - + if ( error_r != NULL ) { if ( sbin == NULL ) *error_r = SIEVE_ERROR_NOT_VALID; @@ -211,10 +211,10 @@ static struct sieve_binary *sieve_generate struct sieve_binary *sieve_compile_script (struct sieve_script *script, struct sieve_error_handler *ehandler, - enum sieve_compile_flags flags, enum sieve_error *error_r) + enum sieve_compile_flags flags, enum sieve_error *error_r) { struct sieve_ast *ast; - struct sieve_binary *sbin; + struct sieve_binary *sbin; /* Parse */ if ( (ast = sieve_parse(script, ehandler, error_r)) == NULL ) { @@ -225,15 +225,15 @@ struct sieve_binary *sieve_compile_script /* Validate */ if ( !sieve_validate(ast, ehandler, flags, error_r) ) { sieve_error(ehandler, sieve_script_name(script), "validation failed"); - + sieve_ast_unref(&ast); return NULL; } - + /* Generate */ if ( (sbin=sieve_generate(ast, ehandler, flags, error_r)) == NULL ) { sieve_error(ehandler, sieve_script_name(script), "code generation failed"); - + sieve_ast_unref(&ast); return NULL; } @@ -258,7 +258,7 @@ struct sieve_binary *sieve_compile if ( (script = sieve_script_create (svinst, script_location, script_name, ehandler, error_r)) == NULL ) return NULL; - + sbin = sieve_compile_script(script, ehandler, flags, error_r); if ( svinst->debug && sbin != NULL ) { @@ -267,7 +267,7 @@ struct sieve_binary *sieve_compile } sieve_script_unref(&script); - + return sbin; } @@ -276,22 +276,22 @@ struct sieve_binary *sieve_compile */ static int sieve_run -(struct sieve_binary *sbin, struct sieve_result **result, - const struct sieve_message_data *msgdata, const struct sieve_script_env *senv, +(struct sieve_binary *sbin, struct sieve_result **result, + const struct sieve_message_data *msgdata, const struct sieve_script_env *senv, struct sieve_error_handler *ehandler, enum sieve_runtime_flags flags) { struct sieve_interpreter *interp; int ret = 0; /* Create the interpreter */ - if ( (interp=sieve_interpreter_create(sbin, msgdata, senv, ehandler, flags)) + if ( (interp=sieve_interpreter_create(sbin, msgdata, senv, ehandler, flags)) == NULL ) return SIEVE_EXEC_BIN_CORRUPT; /* Reset execution status */ if ( senv->exec_status != NULL ) memset(senv->exec_status, 0, sizeof(*senv->exec_status)); - + /* Create result object */ if ( *result == NULL ) *result = sieve_result_create @@ -299,10 +299,10 @@ static int sieve_run else { sieve_result_set_error_handler(*result, ehandler); } - + /* Run the interpreter */ ret = sieve_interpreter_run(interp, *result); - + /* Free the interpreter */ sieve_interpreter_free(&interp); @@ -325,11 +325,11 @@ struct sieve_binary *sieve_open_script { struct sieve_instance *svinst = sieve_script_svinst(script); struct sieve_binary *sbin; - + T_BEGIN { /* Then try to open the matching binary */ sbin = sieve_script_binary_load(script, error_r); - + if (sbin != NULL) { /* Ok, it exists; now let's see if it is up to date */ if ( !sieve_binary_up_to_date(sbin, flags) ) { @@ -340,9 +340,9 @@ struct sieve_binary *sieve_open_script sieve_binary_unref(&sbin); sbin = NULL; - } + } } - + /* If the binary does not exist or is not up-to-date, we need * to (re-)compile. */ @@ -350,14 +350,14 @@ struct sieve_binary *sieve_open_script if ( svinst->debug ) sieve_sys_debug(svinst, "script binary %s successfully loaded", sieve_binary_path(sbin)); - - } else { + + } else { sbin = sieve_compile_script(script, ehandler, flags, error_r); /* Save the binary if compile was successful */ if ( sbin != NULL ) { if ( svinst->debug ) - sieve_sys_debug(svinst, "script `%s' from %s successfully compiled", + sieve_sys_debug(svinst, "script `%s' from %s successfully compiled", sieve_script_name(script), sieve_script_location(script)); } } @@ -367,13 +367,13 @@ struct sieve_binary *sieve_open_script } struct sieve_binary *sieve_open -(struct sieve_instance *svinst, const char *script_location, +(struct sieve_instance *svinst, const char *script_location, const char *script_name, struct sieve_error_handler *ehandler, enum sieve_compile_flags flags, enum sieve_error *error_r) { struct sieve_script *script; struct sieve_binary *sbin; - + /* First open the scriptfile itself */ script = sieve_script_create (svinst, script_location, script_name, ehandler, error_r); @@ -385,7 +385,7 @@ struct sieve_binary *sieve_open sbin = sieve_open_script(script, ehandler, flags, error_r); - /* Drop script reference, if sbin != NULL it holds a reference of its own. + /* Drop script reference, if sbin != NULL it holds a reference of its own. * Otherwise the script object is freed here. */ sieve_script_unref(&script); @@ -435,45 +435,45 @@ void sieve_close(struct sieve_binary **sbin) */ void sieve_dump -(struct sieve_binary *sbin, struct ostream *stream, bool verbose) +(struct sieve_binary *sbin, struct ostream *stream, bool verbose) { - struct sieve_binary_dumper *dumpr = sieve_binary_dumper_create(sbin); + struct sieve_binary_dumper *dumpr = sieve_binary_dumper_create(sbin); + + sieve_binary_dumper_run(dumpr, stream, verbose); - sieve_binary_dumper_run(dumpr, stream, verbose); - sieve_binary_dumper_free(&dumpr); } void sieve_hexdump -(struct sieve_binary *sbin, struct ostream *stream) -{ - struct sieve_binary_dumper *dumpr = sieve_binary_dumper_create(sbin); +(struct sieve_binary *sbin, struct ostream *stream) +{ + struct sieve_binary_dumper *dumpr = sieve_binary_dumper_create(sbin); + + sieve_binary_dumper_hexdump(dumpr, stream); - sieve_binary_dumper_hexdump(dumpr, stream); - sieve_binary_dumper_free(&dumpr); } int sieve_test (struct sieve_binary *sbin, const struct sieve_message_data *msgdata, const struct sieve_script_env *senv, struct sieve_error_handler *ehandler, - struct ostream *stream, enum sieve_runtime_flags flags, bool *keep) + struct ostream *stream, enum sieve_runtime_flags flags, bool *keep) { struct sieve_result *result = NULL; int ret; if ( keep != NULL ) *keep = FALSE; - + /* Run the script */ ret = sieve_run(sbin, &result, msgdata, senv, ehandler, flags); - + /* Print result if successful */ if ( ret > 0 ) { ret = sieve_result_print(result, senv, stream, keep); } else if ( ret == 0 ) { if ( keep != NULL ) *keep = TRUE; } - + /* Cleanup */ if ( result != NULL ) sieve_result_unref(&result); @@ -494,13 +494,13 @@ int sieve_execute int ret; if ( keep != NULL ) *keep = FALSE; - + /* Run the script */ ret = sieve_run(sbin, &result, msgdata, senv, ehandler, flags); - + /* Evaluate status and execute the result: - * Strange situations, e.g. currupt binaries, must be handled by the caller. - * In that case no implicit keep is attempted, because the situation may be + * Strange situations, e.g. currupt binaries, must be handled by the caller. + * In that case no implicit keep is attempted, because the situation may be * resolved. */ if ( ret > 0 ) { @@ -525,7 +525,7 @@ int sieve_execute /* * Multiscript support */ - + struct sieve_multiscript { struct sieve_instance *svinst; struct sieve_result *result; @@ -538,20 +538,20 @@ struct sieve_multiscript { struct ostream *teststream; }; - + struct sieve_multiscript *sieve_multiscript_start_execute -(struct sieve_instance *svinst, const struct sieve_message_data *msgdata, +(struct sieve_instance *svinst, const struct sieve_message_data *msgdata, const struct sieve_script_env *senv) { pool_t pool; struct sieve_result *result; struct sieve_multiscript *mscript; - + result = sieve_result_create(svinst, msgdata, senv, NULL); pool = sieve_result_pool(result); - + sieve_result_set_keep_action(result, NULL, NULL); - + mscript = p_new(pool, struct sieve_multiscript, 1); mscript->svinst = svinst; mscript->result = result; @@ -560,7 +560,7 @@ struct sieve_multiscript *sieve_multiscript_start_execute mscript->status = SIEVE_EXEC_OK; mscript->active = TRUE; mscript->keep = TRUE; - + return mscript; } @@ -568,9 +568,9 @@ struct sieve_multiscript *sieve_multiscript_start_test (struct sieve_instance *svinst, const struct sieve_message_data *msgdata, const struct sieve_script_env *senv, struct ostream *stream) { - struct sieve_multiscript *mscript = + struct sieve_multiscript *mscript = sieve_multiscript_start_execute(svinst, msgdata, senv); - + mscript->teststream = stream; return mscript; @@ -579,7 +579,7 @@ struct sieve_multiscript *sieve_multiscript_start_test static void sieve_multiscript_test (struct sieve_multiscript *mscript, struct sieve_error_handler *ehandler, bool *keep) -{ +{ sieve_result_set_error_handler(mscript->result, ehandler); if ( mscript->status > 0 ) { @@ -604,7 +604,7 @@ static void sieve_multiscript_execute if ( !sieve_result_implicit_keep(mscript->result) ) mscript->status = SIEVE_EXEC_KEEP_FAILED; else - if ( keep != NULL ) *keep = TRUE; + if ( keep != NULL ) *keep = TRUE; } } @@ -614,25 +614,25 @@ bool sieve_multiscript_run bool final) { if ( !mscript->active ) return FALSE; - + if ( final ) sieve_result_set_keep_action(mscript->result, NULL, &act_store); - + /* Run the script */ - mscript->status = sieve_run(sbin, &mscript->result, mscript->msgdata, + mscript->status = sieve_run(sbin, &mscript->result, mscript->msgdata, mscript->scriptenv, ehandler, flags); if ( mscript->status >= 0 ) { mscript->keep = FALSE; - if ( mscript->teststream != NULL ) + if ( mscript->teststream != NULL ) sieve_multiscript_test(mscript, ehandler, &mscript->keep); else sieve_multiscript_execute(mscript, ehandler, &mscript->keep); mscript->active = ( mscript->active && mscript->keep && !final && mscript->status > 0 ); - } + } if ( mscript->status <= 0 ) return FALSE; @@ -645,14 +645,14 @@ int sieve_multiscript_status(struct sieve_multiscript *mscript) return mscript->status; } -int sieve_multiscript_finish(struct sieve_multiscript **mscript, +int sieve_multiscript_finish(struct sieve_multiscript **mscript, struct sieve_error_handler *ehandler, bool *keep) { struct sieve_result *result = (*mscript)->result; int ret = (*mscript)->status; if ( ehandler != NULL ) - sieve_result_set_error_handler((*mscript)->result, ehandler); + sieve_result_set_error_handler((*mscript)->result, ehandler); if ( (*mscript)->active ) { ret = SIEVE_EXEC_FAILURE; @@ -668,11 +668,11 @@ int sieve_multiscript_finish(struct sieve_multiscript **mscript, } if ( keep != NULL ) *keep = (*mscript)->keep; - + /* Cleanup */ sieve_result_unref(&result); *mscript = NULL; - + return ret; } @@ -708,7 +708,7 @@ struct sieve_directory { struct sieve_directory *sieve_directory_open (struct sieve_instance *svinst, const char *path, enum sieve_error *error_r) -{ +{ struct sieve_directory *sdir = NULL; DIR *dirp; struct stat st; @@ -716,7 +716,7 @@ struct sieve_directory *sieve_directory_open if ( error_r != NULL ) *error_r = SIEVE_ERROR_NONE; - if ( (path[0] == '~' && (path[1] == '/' || path[1] == '\0')) || + if ( (path[0] == '~' && (path[1] == '/' || path[1] == '\0')) || (((svinst->flags & SIEVE_FLAG_HOME_RELATIVE) != 0 ) && path[0] != '/') ) { /* Home-relative path. change to absolute. */ const char *home = sieve_environment_get_homedir(svinst); @@ -760,7 +760,7 @@ struct sieve_directory *sieve_directory_open } if ( S_ISDIR(st.st_mode) ) { - + /* Open the directory */ if ( (dirp = opendir(path)) == NULL ) { switch ( errno ) { @@ -781,9 +781,9 @@ struct sieve_directory *sieve_directory_open *error_r = SIEVE_ERROR_TEMP_FAIL; break; } - return NULL; + return NULL; } - + /* Create object */ sdir = t_new(struct sieve_directory, 1); sdir->path = path; @@ -803,7 +803,7 @@ const char *sieve_directory_get_scriptfile(struct sieve_directory *sdir) { const char *script = NULL; struct dirent *dp; - + if ( sdir->dirp != NULL ) { while ( script == NULL ) { const char *file; @@ -834,19 +834,19 @@ const char *sieve_directory_get_scriptfile(struct sieve_directory *sdir) } } else { script = sdir->path; - sdir->path = NULL; + sdir->path = NULL; } - + return script; } void sieve_directory_close(struct sieve_directory **sdir) { /* Close the directory */ - if ( (*sdir)->dirp != NULL && closedir((*sdir)->dirp) < 0 ) + if ( (*sdir)->dirp != NULL && closedir((*sdir)->dirp) < 0 ) sieve_sys_error((*sdir)->svinst, "failed to close sieve dir: " "closedir(%s) failed: %m", (*sdir)->path); - + *sdir = NULL; } diff --git a/src/lib-sieve/sieve.h b/src/lib-sieve/sieve.h index 20e5d8299072a17b26081180c84acb2225871d35..e5a98338bf24125eefe1fc215978665470edea97 100644 --- a/src/lib-sieve/sieve.h +++ b/src/lib-sieve/sieve.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ #ifndef __SIEVE_H @@ -15,7 +15,7 @@ struct sieve_binary; * Main Sieve library interface */ -/* sieve_init(): +/* sieve_init(): * Initializes the sieve engine. Must be called before any sieve functionality * is used. */ @@ -24,7 +24,7 @@ struct sieve_instance *sieve_init void *context, bool debug); /* sieve_deinit(): - * Frees all memory allocated by the sieve engine. + * Frees all memory allocated by the sieve engine. */ void sieve_deinit(struct sieve_instance **svinst); @@ -55,11 +55,11 @@ struct sieve_binary *sieve_compile_script * Compiles the script into a binary. */ struct sieve_binary *sieve_compile - (struct sieve_instance *svinst, const char *script_location, + (struct sieve_instance *svinst, const char *script_location, const char *script_name, struct sieve_error_handler *ehandler, enum sieve_compile_flags flags, enum sieve_error *error_r); -/* +/* * Reading/writing Sieve binaries */ @@ -73,8 +73,8 @@ struct sieve_binary *sieve_load /* sieve_open_script: * - * First tries to open the binary version of the specified script and if it - * does not exist or if it contains errors, the script is (re-)compiled. Note + * First tries to open the binary version of the specified script and if it + * does not exist or if it contains errors, the script is (re-)compiled. Note * that errors in the bytecode are caught only at runtime. */ struct sieve_binary *sieve_open_script @@ -83,12 +83,12 @@ struct sieve_binary *sieve_open_script /* sieve_open: * - * First tries to open the binary version of the specified script and if it - * does not exist or if it contains errors, the script is (re-)compiled. Note + * First tries to open the binary version of the specified script and if it + * does not exist or if it contains errors, the script is (re-)compiled. Note * that errors in the bytecode are caught only at runtime. */ struct sieve_binary *sieve_open - (struct sieve_instance *svinst, const char *script_location, + (struct sieve_instance *svinst, const char *script_location, const char *script_name, struct sieve_error_handler *ehandler, enum sieve_compile_flags flags, enum sieve_error *error_r); @@ -96,7 +96,7 @@ struct sieve_binary *sieve_open * * Saves the binary as the file indicated by the path parameter. This function * will not write the binary to disk when it was loaded from the indicated - * bin_path, unless update is TRUE. + * bin_path, unless update is TRUE. */ int sieve_save_as (struct sieve_binary *sbin, const char *bin_path, bool update, @@ -106,7 +106,7 @@ int sieve_save_as * * Saves the binary to the default location. This function will not overwrite * the binary it was loaded earlier from the default location, unless update - * is TRUE. + * is TRUE. */ int sieve_save (struct sieve_binary *sbin, bool update, enum sieve_error *error_r); @@ -126,7 +126,7 @@ const char *sieve_get_source(struct sieve_binary *sbin); /* * sieve_is_loeded: * - * Indicates whether the binary was loaded from a pre-compiled file. + * Indicates whether the binary was loaded from a pre-compiled file. */ bool sieve_is_loaded(struct sieve_binary *sbin); @@ -152,10 +152,10 @@ void sieve_hexdump /* sieve_test: * * Executes the bytecode, but only prints the result to the given stream. - */ + */ int sieve_test - (struct sieve_binary *sbin, const struct sieve_message_data *msgdata, - const struct sieve_script_env *senv, struct sieve_error_handler *ehandler, + (struct sieve_binary *sbin, const struct sieve_message_data *msgdata, + const struct sieve_script_env *senv, struct sieve_error_handler *ehandler, struct ostream *stream, enum sieve_runtime_flags flags, bool *keep); /* @@ -164,19 +164,19 @@ int sieve_test /* sieve_execute: * - * Executes the binary, including the result. + * Executes the binary, including the result. */ int sieve_execute (struct sieve_binary *sbin, const struct sieve_message_data *msgdata, const struct sieve_script_env *senv, struct sieve_error_handler *ehandler, enum sieve_runtime_flags flags, bool *keep); - + /* * Multiscript support */ - + struct sieve_multiscript; - + struct sieve_multiscript *sieve_multiscript_start_execute (struct sieve_instance *svinst, const struct sieve_message_data *msgdata, const struct sieve_script_env *senv); @@ -185,7 +185,7 @@ struct sieve_multiscript *sieve_multiscript_start_test const struct sieve_script_env *senv, struct ostream *stream); bool sieve_multiscript_run - (struct sieve_multiscript *mscript, struct sieve_binary *sbin, + (struct sieve_multiscript *mscript, struct sieve_binary *sbin, struct sieve_error_handler *ehandler, enum sieve_runtime_flags flags, bool final); diff --git a/src/lib-sieve/tst-address.c b/src/lib-sieve/tst-address.c index 4e676f5e3a273c6019be2abcd985ba7c868ea265..f9cdd5bb781189306fa751f6c059ee354a6e718e 100644 --- a/src/lib-sieve/tst-address.c +++ b/src/lib-sieve/tst-address.c @@ -21,7 +21,7 @@ #include <stdio.h> -/* +/* * Address test * * Syntax: @@ -37,20 +37,20 @@ static bool tst_address_validate static bool tst_address_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx); -const struct sieve_command_def tst_address = { - "address", - SCT_TEST, +const struct sieve_command_def tst_address = { + "address", + SCT_TEST, 2, 0, FALSE, FALSE, tst_address_registered, - NULL, + NULL, tst_address_validate, - NULL, - tst_address_generate, - NULL + NULL, + tst_address_generate, + NULL }; -/* - * Address operation +/* + * Address operation */ static bool tst_address_operation_dump @@ -58,21 +58,21 @@ static bool tst_address_operation_dump static int tst_address_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def tst_address_operation = { +const struct sieve_operation_def tst_address_operation = { "ADDRESS", NULL, SIEVE_OPERATION_ADDRESS, - tst_address_operation_dump, - tst_address_operation_execute + tst_address_operation_dump, + tst_address_operation_execute }; -/* - * Test registration +/* + * Test registration */ static bool tst_address_registered (struct sieve_validator *valdtr, const struct sieve_extension *ext ATTR_UNUSED, - struct sieve_command_registration *cmd_reg) + struct sieve_command_registration *cmd_reg) { /* The order of these is not significant */ sieve_comparators_link_tag(valdtr, cmd_reg, SIEVE_AM_OPT_COMPARATOR ); @@ -82,20 +82,20 @@ static bool tst_address_registered return TRUE; } -/* - * Validation +/* + * Validation */ - + /* List of valid headers: * Implementations MUST restrict the address test to headers that * contain addresses, but MUST include at least From, To, Cc, Bcc, * Sender, Resent-From, and Resent-To, and it SHOULD include any other * header that utilizes an "address-list" structured header body. * - * This list explicitly does not contain the envelope-to and return-path + * This list explicitly does not contain the envelope-to and return-path * headers. The envelope test must be used to test against these addresses. * - * FIXME: this restriction is somewhat odd. Sieve list advises to allow + * FIXME: this restriction is somewhat odd. Sieve list advises to allow * any other header as long as its content matches the address-list * grammar. */ @@ -104,19 +104,19 @@ static const char * const _allowed_headers[] = { "from", "to", "cc", "bcc", "sender", "resent-from", "resent-to", /* Additional (RFC 822 / RFC 2822) */ - "reply-to", "resent-reply-to", "resent-sender", "resent-cc", "resent-bcc", + "reply-to", "resent-reply-to", "resent-sender", "resent-cc", "resent-bcc", /* Non-standard (RFC 2076, draft-palme-mailext-headers-08.txt) */ - "for-approval", "for-handling", "for-comment", "apparently-to", "errors-to", - "delivered-to", "return-receipt-to", "x-admin", "read-receipt-to", - "x-confirm-reading-to", "return-receipt-requested", + "for-approval", "for-handling", "for-comment", "apparently-to", "errors-to", + "delivered-to", "return-receipt-to", "x-admin", "read-receipt-to", + "x-confirm-reading-to", "return-receipt-requested", "registered-mail-reply-requested-by", "mail-followup-to", "mail-reply-to", "abuse-reports-to", "x-complaints-to", "x-report-abuse-to", - + /* Undocumented */ "x-beenthere", - - NULL + + NULL }; static int _header_is_allowed @@ -127,33 +127,33 @@ static int _header_is_allowed const char * const *hdsp = _allowed_headers; while ( *hdsp != NULL ) { - if ( strcasecmp( *hdsp, header ) == 0 ) + if ( strcasecmp( *hdsp, header ) == 0 ) return TRUE; hdsp++; } - + return FALSE; } - + return TRUE; } static bool tst_address_validate -(struct sieve_validator *valdtr, struct sieve_command *tst) +(struct sieve_validator *valdtr, struct sieve_command *tst) { struct sieve_ast_argument *arg = tst->first_positional; struct sieve_ast_argument *header; - struct sieve_comparator cmp_default = + struct sieve_comparator cmp_default = SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator); - struct sieve_match_type mcht_default = + struct sieve_match_type mcht_default = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); - + if ( !sieve_validate_positional_argument (valdtr, tst, arg, "header list", 1, SAAT_STRING_LIST) ) { return FALSE; } - + if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) ) return FALSE; @@ -161,20 +161,20 @@ static bool tst_address_validate return FALSE; /* Check if supplied header names are allowed - * FIXME: verify dynamic header names at runtime + * FIXME: verify dynamic header names at runtime */ header = arg; - if ( !sieve_ast_stringlist_map(&header, NULL, _header_is_allowed) ) { - sieve_argument_validate_error(valdtr, header, - "specified header '%s' is not allowed for the address test", + if ( !sieve_ast_stringlist_map(&header, NULL, _header_is_allowed) ) { + sieve_argument_validate_error(valdtr, header, + "specified header '%s' is not allowed for the address test", str_sanitize(sieve_ast_strlist_strc(header), 64)); return FALSE; } /* Check key list */ - + arg = sieve_ast_argument_next(arg); - + if ( !sieve_validate_positional_argument (valdtr, tst, arg, "key list", 2, SAAT_STRING_LIST) ) { return FALSE; @@ -182,27 +182,27 @@ static bool tst_address_validate if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) ) return FALSE; - + /* Validate the key argument to a specified match type */ return sieve_match_type_validate - (valdtr, tst, arg, &mcht_default, &cmp_default); + (valdtr, tst, arg, &mcht_default, &cmp_default); } -/* - * Code generation +/* + * Code generation */ static bool tst_address_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *tst) +(const struct sieve_codegen_env *cgenv, struct sieve_command *tst) { sieve_operation_emit(cgenv->sblock, NULL, &tst_address_operation); - - /* Generate arguments */ + + /* Generate arguments */ return sieve_generate_arguments(cgenv, tst, NULL); } -/* - * Code dump +/* + * Code dump */ static bool tst_address_operation_dump @@ -210,7 +210,7 @@ static bool tst_address_operation_dump { sieve_code_dumpf(denv, "ADDRESS"); sieve_code_descend(denv); - + /* Handle any optional arguments */ if ( sieve_addrmatch_opr_optional_dump(denv, address, NULL) != 0 ) return FALSE; @@ -220,28 +220,28 @@ static bool tst_address_operation_dump sieve_opr_stringlist_dump(denv, address, "key list"); } -/* - * Code execution +/* + * Code execution */ static int tst_address_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) -{ - struct sieve_comparator cmp = +{ + struct sieve_comparator cmp = SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator); - struct sieve_match_type mcht = + struct sieve_match_type mcht = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); - struct sieve_address_part addrp = + struct sieve_address_part addrp = SIEVE_ADDRESS_PART_DEFAULT(all_address_part); struct sieve_stringlist *hdr_list, *hdr_value_list, *value_list, *key_list; struct sieve_address_list *addr_list; int match, ret; - + /* Read optional operands */ if ( sieve_addrmatch_opr_optional_read - (renv, address, NULL, &ret, &addrp, &mcht, &cmp) < 0 ) + (renv, address, NULL, &ret, &addrp, &mcht, &cmp) < 0 ) return ret; - + /* Read header-list */ if ( (ret=sieve_opr_stringlist_read(renv, address, "header-list", &hdr_list)) <= 0 ) @@ -260,7 +260,7 @@ static int tst_address_operation_execute value_list = sieve_address_part_stringlist_create(renv, &addrp, addr_list); /* Perform match */ - if ( (match=sieve_match(renv, &mcht, &cmp, value_list, key_list, &ret)) < 0 ) + if ( (match=sieve_match(renv, &mcht, &cmp, value_list, key_list, &ret)) < 0 ) return ret; /* Set test result for subsequent conditional jump */ diff --git a/src/lib-sieve/tst-allof.c b/src/lib-sieve/tst-allof.c index 215679ad679788f726be803300120590b520a24e..bd3fcbd8309352afd06a0cab297e8b1144a6bcf6 100644 --- a/src/lib-sieve/tst-allof.c +++ b/src/lib-sieve/tst-allof.c @@ -9,11 +9,11 @@ #include "sieve-code.h" #include "sieve-binary.h" -/* - * Allof test - * - * Syntax - * allof <tests: test-list> +/* + * Allof test + * + * Syntax + * allof <tests: test-list> */ static bool tst_allof_generate @@ -23,14 +23,14 @@ static bool tst_allof_validate_const (struct sieve_validator *valdtr, struct sieve_command *tst, int *const_current, int const_new); -const struct sieve_command_def tst_allof = { - "allof", - SCT_TEST, +const struct sieve_command_def tst_allof = { + "allof", + SCT_TEST, 0, 2, FALSE, FALSE, NULL, NULL, NULL, tst_allof_validate_const, NULL, - tst_allof_generate + tst_allof_generate }; /* @@ -51,8 +51,8 @@ static bool tst_allof_validate_const return TRUE; } -/* - * Code generation +/* + * Code generation */ static bool tst_allof_generate @@ -63,36 +63,36 @@ static bool tst_allof_generate struct sieve_ast_node *test; struct sieve_jumplist false_jumps; - if ( sieve_ast_test_count(ctx->ast_node) > 1 ) { + if ( sieve_ast_test_count(ctx->ast_node) > 1 ) { if ( jump_true ) { /* Prepare jumplist */ sieve_jumplist_init_temp(&false_jumps, sblock); } - + test = sieve_ast_test_first(ctx->ast_node); - while ( test != NULL ) { - bool result; + while ( test != NULL ) { + bool result; /* If this test list must jump on false, all sub-tests can simply add their jumps - * to the caller's jump list, otherwise this test redirects all false jumps to the + * to the caller's jump list, otherwise this test redirects all false jumps to the * end of the currently generated code. This is just after a final jump to the true - * case + * case */ - if ( jump_true ) + if ( jump_true ) result = sieve_generate_test(cgenv, test, &false_jumps, FALSE); else result = sieve_generate_test(cgenv, test, jumps, FALSE); - + if ( !result ) return FALSE; test = sieve_ast_test_next(test); - } - + } + if ( jump_true ) { /* All tests succeeded, jump to case TRUE */ sieve_operation_emit(cgenv->sblock, NULL, &sieve_jmp_operation); sieve_jumplist_add(jumps, sieve_binary_emit_offset(sblock, 0)); - + /* All false exits jump here */ sieve_jumplist_resolve(&false_jumps); } @@ -101,7 +101,7 @@ static bool tst_allof_generate test = sieve_ast_test_first(ctx->ast_node); sieve_generate_test(cgenv, test, jumps, jump_true); } - + return TRUE; } diff --git a/src/lib-sieve/tst-anyof.c b/src/lib-sieve/tst-anyof.c index ad23af02ff9bfd6ccbdee8a2d961666cae6ac824..13221897af4da696741719a90061462e6e5025b7 100644 --- a/src/lib-sieve/tst-anyof.c +++ b/src/lib-sieve/tst-anyof.c @@ -9,28 +9,28 @@ #include "sieve-code.h" #include "sieve-binary.h" -/* - * Anyof test +/* + * Anyof test * - * Syntax - * anyof <tests: test-list> + * Syntax + * anyof <tests: test-list> */ -static bool tst_anyof_generate +static bool tst_anyof_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx, struct sieve_jumplist *jumps, bool jump_true); static bool tst_anyof_validate_const (struct sieve_validator *valdtr, struct sieve_command *tst, int *const_current, int const_next); -const struct sieve_command_def tst_anyof = { - "anyof", - SCT_TEST, +const struct sieve_command_def tst_anyof = { + "anyof", + SCT_TEST, 0, 2, FALSE, FALSE, NULL, NULL, NULL, tst_anyof_validate_const, NULL, - tst_anyof_generate + tst_anyof_generate }; /* @@ -51,11 +51,11 @@ static bool tst_anyof_validate_const return TRUE; } -/* - * Code generation +/* + * Code generation */ -static bool tst_anyof_generate +static bool tst_anyof_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx, struct sieve_jumplist *jumps, bool jump_true) { @@ -63,36 +63,36 @@ static bool tst_anyof_generate struct sieve_ast_node *test; struct sieve_jumplist true_jumps; - if ( sieve_ast_test_count(ctx->ast_node) > 1 ) { + if ( sieve_ast_test_count(ctx->ast_node) > 1 ) { if ( !jump_true ) { /* Prepare jumplist */ sieve_jumplist_init_temp(&true_jumps, sblock); } - + test = sieve_ast_test_first(ctx->ast_node); - while ( test != NULL ) { + while ( test != NULL ) { bool result; /* If this test list must jump on true, all sub-tests can simply add their jumps - * to the caller's jump list, otherwise this test redirects all true jumps to the + * to the caller's jump list, otherwise this test redirects all true jumps to the * end of the currently generated code. This is just after a final jump to the false - * case + * case */ - if ( !jump_true ) + if ( !jump_true ) result = sieve_generate_test(cgenv, test, &true_jumps, TRUE); else result = sieve_generate_test(cgenv, test, jumps, TRUE); if ( !result ) return FALSE; - + test = sieve_ast_test_next(test); - } - + } + if ( !jump_true ) { /* All tests failed, jump to case FALSE */ sieve_operation_emit(sblock, NULL, &sieve_jmp_operation); sieve_jumplist_add(jumps, sieve_binary_emit_offset(sblock, 0)); - + /* All true exits jump here */ sieve_jumplist_resolve(&true_jumps); } @@ -100,7 +100,7 @@ static bool tst_anyof_generate /* Script author is being inefficient; we can optimize the allof test away */ test = sieve_ast_test_first(ctx->ast_node); sieve_generate_test(cgenv, test, jumps, jump_true); - } - + } + return TRUE; } diff --git a/src/lib-sieve/tst-exists.c b/src/lib-sieve/tst-exists.c index 978ea141e303a8dde46c9c77e01ae3808c23f899..7b73021f1bfa72be503b7f07d9b80a9c559f582e 100644 --- a/src/lib-sieve/tst-exists.c +++ b/src/lib-sieve/tst-exists.c @@ -14,9 +14,9 @@ #include "sieve-interpreter.h" #include "sieve-code-dumper.h" -/* +/* * Exists test - * + * * Syntax: * exists <header-names: string-list> */ @@ -26,20 +26,20 @@ static bool tst_exists_validate static bool tst_exists_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *tst); -const struct sieve_command_def tst_exists = { - "exists", - SCT_TEST, +const struct sieve_command_def tst_exists = { + "exists", + SCT_TEST, 1, 0, FALSE, FALSE, - NULL, + NULL, NULL, tst_exists_validate, NULL, - tst_exists_generate, - NULL + tst_exists_generate, + NULL }; -/* - * Exists operation +/* + * Exists operation */ static bool tst_exists_operation_dump @@ -47,40 +47,40 @@ static bool tst_exists_operation_dump static int tst_exists_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def tst_exists_operation = { +const struct sieve_operation_def tst_exists_operation = { "EXISTS", NULL, SIEVE_OPERATION_EXISTS, - tst_exists_operation_dump, - tst_exists_operation_execute + tst_exists_operation_dump, + tst_exists_operation_execute }; -/* - * Validation +/* + * Validation */ static bool tst_exists_validate - (struct sieve_validator *valdtr, struct sieve_command *tst) + (struct sieve_validator *valdtr, struct sieve_command *tst) { struct sieve_ast_argument *arg = tst->first_positional; - + if ( !sieve_validate_positional_argument (valdtr, tst, arg, "header names", 1, SAAT_STRING_LIST) ) { return FALSE; } - + if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) ) return FALSE; return sieve_command_verify_headers_argument(valdtr, arg); } -/* - * Code generation +/* + * Code generation */ static bool tst_exists_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *tst) +(const struct sieve_codegen_env *cgenv, struct sieve_command *tst) { sieve_operation_emit(cgenv->sblock, NULL, &tst_exists_operation); @@ -88,8 +88,8 @@ static bool tst_exists_generate return sieve_generate_arguments(cgenv, tst, NULL); } -/* - * Code dump +/* + * Code dump */ static bool tst_exists_operation_dump @@ -101,8 +101,8 @@ static bool tst_exists_operation_dump return sieve_opr_stringlist_dump(denv, address, "header names"); } -/* - * Code execution +/* + * Code execution */ static int tst_exists_operation_execute @@ -113,7 +113,7 @@ static int tst_exists_operation_execute string_t *hdr_item; bool matched; int ret; - + /* * Read operands */ @@ -136,12 +136,12 @@ static int tst_exists_operation_execute while ( matched && (ret=sieve_stringlist_next_item(hdr_list, &hdr_item)) > 0 ) { const char *const *headers; - + if ( mail_get_headers(mail, str_c(hdr_item), &headers) < 0 || headers[0] == NULL ) { - matched = FALSE; - } - + matched = FALSE; + } + sieve_runtime_trace(renv, SIEVE_TRLVL_MATCHING, "header `%s' %s", str_sanitize(str_c(hdr_item), 80), ( matched ? "exists" : "is missing" )); @@ -151,13 +151,13 @@ static int tst_exists_operation_execute sieve_runtime_trace(renv, SIEVE_TRLVL_MATCHING, "all headers exist"); else sieve_runtime_trace(renv, SIEVE_TRLVL_MATCHING, "headers are missing"); - + /* Set test result for subsequent conditional jump */ if ( ret >= 0 ) { sieve_interpreter_set_test_result(renv->interp, matched); return SIEVE_EXEC_OK; } - + sieve_runtime_trace_error(renv, "invalid header-list item"); return SIEVE_EXEC_BIN_CORRUPT; } diff --git a/src/lib-sieve/tst-header.c b/src/lib-sieve/tst-header.c index 25d2f54aa8a5e29b68a26c0d64c364bb6f4be356..c830c05bed03611d4e1f66d42ba6820453f702b9 100644 --- a/src/lib-sieve/tst-header.c +++ b/src/lib-sieve/tst-header.c @@ -16,8 +16,8 @@ #include "sieve-dump.h" #include "sieve-match.h" -/* - * Header test +/* + * Header test * * Syntax: * header [COMPARATOR] [MATCH-TYPE] @@ -32,20 +32,20 @@ static bool tst_header_validate static bool tst_header_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *tst); -const struct sieve_command_def tst_header = { - "header", +const struct sieve_command_def tst_header = { + "header", SCT_TEST, 2, 0, FALSE, FALSE, - tst_header_registered, + tst_header_registered, NULL, tst_header_validate, NULL, - tst_header_generate, - NULL + tst_header_generate, + NULL }; -/* - * Header operation +/* + * Header operation */ static bool tst_header_operation_dump @@ -53,21 +53,21 @@ static bool tst_header_operation_dump static int tst_header_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def tst_header_operation = { +const struct sieve_operation_def tst_header_operation = { "HEADER", NULL, SIEVE_OPERATION_HEADER, - tst_header_operation_dump, - tst_header_operation_execute + tst_header_operation_dump, + tst_header_operation_execute }; -/* - * Test registration +/* + * Test registration */ static bool tst_header_registered -(struct sieve_validator *valdtr, const struct sieve_extension *ext ATTR_UNUSED, - struct sieve_command_registration *cmd_reg) +(struct sieve_validator *valdtr, const struct sieve_extension *ext ATTR_UNUSED, + struct sieve_command_registration *cmd_reg) { /* The order of these is not significant */ sieve_comparators_link_tag(valdtr, cmd_reg, SIEVE_MATCH_OPT_COMPARATOR); @@ -76,37 +76,37 @@ static bool tst_header_registered return TRUE; } -/* - * Validation +/* + * Validation */ - + static bool tst_header_validate -(struct sieve_validator *valdtr, struct sieve_command *tst) -{ +(struct sieve_validator *valdtr, struct sieve_command *tst) +{ struct sieve_ast_argument *arg = tst->first_positional; - struct sieve_comparator cmp_default = + struct sieve_comparator cmp_default = SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator); - struct sieve_match_type mcht_default = + struct sieve_match_type mcht_default = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); - + if ( !sieve_validate_positional_argument (valdtr, tst, arg, "header names", 1, SAAT_STRING_LIST) ) { return FALSE; } - + if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) ) return FALSE; if ( !sieve_command_verify_headers_argument(valdtr, arg) ) return FALSE; - + arg = sieve_ast_argument_next(arg); if ( !sieve_validate_positional_argument (valdtr, tst, arg, "key list", 2, SAAT_STRING_LIST) ) { return FALSE; } - + if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) ) return FALSE; @@ -116,11 +116,11 @@ static bool tst_header_validate } /* - * Code generation + * Code generation */ static bool tst_header_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *tst) +(const struct sieve_codegen_env *cgenv, struct sieve_command *tst) { sieve_operation_emit(cgenv->sblock, NULL, &tst_header_operation); @@ -128,8 +128,8 @@ static bool tst_header_generate return sieve_generate_arguments(cgenv, tst, NULL); } -/* - * Code dump +/* + * Code dump */ static bool tst_header_operation_dump @@ -141,40 +141,40 @@ static bool tst_header_operation_dump /* Optional operands */ if ( sieve_match_opr_optional_dump(denv, address, NULL) != 0 ) return FALSE; - + return sieve_opr_stringlist_dump(denv, address, "header names") && sieve_opr_stringlist_dump(denv, address, "key list"); } -/* - * Code execution +/* + * Code execution */ static int tst_header_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) { - struct sieve_comparator cmp = + struct sieve_comparator cmp = SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator); - struct sieve_match_type mcht = + struct sieve_match_type mcht = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); struct sieve_stringlist *hdr_list, *key_list, *value_list; int match, ret; - - /* + + /* * Read operands */ /* Handle match-type and comparator operands */ - if ( sieve_match_opr_optional_read(renv, address, NULL, &ret, &cmp, &mcht) + if ( sieve_match_opr_optional_read(renv, address, NULL, &ret, &cmp, &mcht) < 0 ) return ret; - + /* Read header-list */ - if ( (ret=sieve_opr_stringlist_read(renv, address, "header-list", &hdr_list)) + if ( (ret=sieve_opr_stringlist_read(renv, address, "header-list", &hdr_list)) <= 0 ) return ret; - + /* Read key-list */ if ( (ret=sieve_opr_stringlist_read(renv, address, "key-list", &key_list)) <= 0 ) @@ -191,7 +191,7 @@ static int tst_header_operation_execute /* Perform match */ if ( (match=sieve_match(renv, &mcht, &cmp, value_list, key_list, &ret)) < 0 ) - return ret; + return ret; /* Set test result for subsequent conditional jump */ sieve_interpreter_set_test_result(renv->interp, match > 0); diff --git a/src/lib-sieve/tst-not.c b/src/lib-sieve/tst-not.c index 5a62f024c071fbd900a9e065f4cb2e83baccad61..30a6d234a2adb346d22e7cf24589e186bbe79afb 100644 --- a/src/lib-sieve/tst-not.c +++ b/src/lib-sieve/tst-not.c @@ -6,11 +6,11 @@ #include "sieve-validator.h" #include "sieve-generator.h" -/* - * Not test +/* + * Not test * * Syntax: - * not <tests: test-list> + * not <tests: test-list> */ static bool tst_not_generate @@ -20,14 +20,14 @@ static bool tst_not_validate_const (struct sieve_validator *valdtr, struct sieve_command *tst, int *const_current, int const_next); -const struct sieve_command_def tst_not = { - "not", - SCT_TEST, +const struct sieve_command_def tst_not = { + "not", + SCT_TEST, 0, 1, FALSE, FALSE, NULL, NULL, NULL, tst_not_validate_const, - NULL, - tst_not_generate + NULL, + tst_not_generate }; /* @@ -48,8 +48,8 @@ static bool tst_not_validate_const return TRUE; } -/* - * Code generation +/* + * Code generation */ static bool tst_not_generate @@ -57,10 +57,10 @@ static bool tst_not_generate struct sieve_jumplist *jumps, bool jump_true) { struct sieve_ast_node *test; - + /* Validator verified the existance of the single test already */ - test = sieve_ast_test_first(ctx->ast_node); - + test = sieve_ast_test_first(ctx->ast_node); + return sieve_generate_test(cgenv, test, jumps, !jump_true); } diff --git a/src/lib-sieve/tst-size.c b/src/lib-sieve/tst-size.c index 5e9fb4ba7123a66856f238417206c82ba4f2d9d0..9f2b1ce3656fab9a7bc3920cd6934a7e013c2e84 100644 --- a/src/lib-sieve/tst-size.c +++ b/src/lib-sieve/tst-size.c @@ -12,37 +12,37 @@ #include "sieve-interpreter.h" #include "sieve-dump.h" -/* - * Size test +/* + * Size test * * Syntax: * size <":over" / ":under"> <limit: number> */ static bool tst_size_registered - (struct sieve_validator *valdtr, const struct sieve_extension *ext, + (struct sieve_validator *valdtr, const struct sieve_extension *ext, struct sieve_command_registration *cmd_reg); static bool tst_size_pre_validate (struct sieve_validator *valdtr, struct sieve_command *tst); static bool tst_size_validate (struct sieve_validator *valdtr, struct sieve_command *tst); static bool tst_size_generate - (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx); + (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx); -const struct sieve_command_def tst_size = { - "size", - SCT_TEST, +const struct sieve_command_def tst_size = { + "size", + SCT_TEST, 1, 0, FALSE, FALSE, - tst_size_registered, + tst_size_registered, tst_size_pre_validate, - tst_size_validate, + tst_size_validate, NULL, - tst_size_generate, - NULL + tst_size_generate, + NULL }; -/* - * Size operations +/* + * Size operations */ static bool tst_size_operation_dump @@ -50,23 +50,23 @@ static bool tst_size_operation_dump static int tst_size_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def tst_size_over_operation = { +const struct sieve_operation_def tst_size_over_operation = { "SIZE-OVER", - NULL, + NULL, SIEVE_OPERATION_SIZE_OVER, - tst_size_operation_dump, - tst_size_operation_execute + tst_size_operation_dump, + tst_size_operation_execute }; const struct sieve_operation_def tst_size_under_operation = { "SIZE-UNDER", - NULL, + NULL, SIEVE_OPERATION_SIZE_UNDER, - tst_size_operation_dump, - tst_size_operation_execute + tst_size_operation_dump, + tst_size_operation_execute }; -/* +/* * Context data */ @@ -78,89 +78,89 @@ struct tst_size_context_data { "exactly one of the ':under' or ':over' tags must be specified " \ "for the size test, but more were found" -/* - * Tag validation +/* + * Tag validation */ static bool tst_size_validate_over_tag -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *tst) { - struct tst_size_context_data *ctx_data = - (struct tst_size_context_data *) tst->data; - + struct tst_size_context_data *ctx_data = + (struct tst_size_context_data *) tst->data; + if ( ctx_data->type != SIZE_UNASSIGNED ) { sieve_argument_validate_error(valdtr, *arg, TST_SIZE_ERROR_DUP_TAG); - return FALSE; + return FALSE; } - + ctx_data->type = SIZE_OVER; - + /* Delete this tag */ *arg = sieve_ast_arguments_detach(*arg, 1); - + return TRUE; } static bool tst_size_validate_under_tag -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg ATTR_UNUSED, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg ATTR_UNUSED, struct sieve_command *tst) { - struct tst_size_context_data *ctx_data = - (struct tst_size_context_data *) tst->data; - + struct tst_size_context_data *ctx_data = + (struct tst_size_context_data *) tst->data; + if ( ctx_data->type != SIZE_UNASSIGNED ) { sieve_argument_validate_error(valdtr, *arg, TST_SIZE_ERROR_DUP_TAG); - return FALSE; + return FALSE; } - + ctx_data->type = SIZE_UNDER; - + /* Delete this tag */ *arg = sieve_ast_arguments_detach(*arg, 1); - + return TRUE; } -/* - * Test registration +/* + * Test registration */ -static const struct sieve_argument_def size_over_tag = { - "over", +static const struct sieve_argument_def size_over_tag = { + "over", NULL, - tst_size_validate_over_tag, + tst_size_validate_over_tag, NULL, NULL, NULL }; -static const struct sieve_argument_def size_under_tag = { - "under", +static const struct sieve_argument_def size_under_tag = { + "under", NULL, - tst_size_validate_under_tag, + tst_size_validate_under_tag, NULL, NULL, NULL }; static bool tst_size_registered -(struct sieve_validator *valdtr, const struct sieve_extension *ext ATTR_UNUSED, - struct sieve_command_registration *cmd_reg) +(struct sieve_validator *valdtr, const struct sieve_extension *ext ATTR_UNUSED, + struct sieve_command_registration *cmd_reg) { /* Register our tags */ - sieve_validator_register_tag(valdtr, cmd_reg, NULL, &size_over_tag, 0); - sieve_validator_register_tag(valdtr, cmd_reg, NULL, &size_under_tag, 0); + sieve_validator_register_tag(valdtr, cmd_reg, NULL, &size_over_tag, 0); + sieve_validator_register_tag(valdtr, cmd_reg, NULL, &size_under_tag, 0); return TRUE; } -/* - * Test validation +/* + * Test validation */ static bool tst_size_pre_validate -(struct sieve_validator *valdtr ATTR_UNUSED, - struct sieve_command *tst) +(struct sieve_validator *valdtr ATTR_UNUSED, + struct sieve_command *tst) { struct tst_size_context_data *ctx_data; - + /* Assign context */ ctx_data = p_new(sieve_command_pool(tst), struct tst_size_context_data, 1); ctx_data->type = SIZE_UNASSIGNED; @@ -170,38 +170,38 @@ static bool tst_size_pre_validate } static bool tst_size_validate - (struct sieve_validator *valdtr, struct sieve_command *tst) + (struct sieve_validator *valdtr, struct sieve_command *tst) { - struct tst_size_context_data *ctx_data = + struct tst_size_context_data *ctx_data = (struct tst_size_context_data *) tst->data; struct sieve_ast_argument *arg = tst->first_positional; - + if ( ctx_data->type == SIZE_UNASSIGNED ) { - sieve_command_validate_error(valdtr, tst, + sieve_command_validate_error(valdtr, tst, "the size test requires either the :under or the :over tag " "to be specified"); - return FALSE; + return FALSE; } - + if ( !sieve_validate_positional_argument (valdtr, tst, arg, "limit", 1, SAAT_NUMBER) ) { return FALSE; } - + return sieve_validator_argument_activate(valdtr, tst, arg, FALSE); } -/* - * Code generation +/* + * Code generation */ bool tst_size_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *tst) +(const struct sieve_codegen_env *cgenv, struct sieve_command *tst) { - struct tst_size_context_data *ctx_data = + struct tst_size_context_data *ctx_data = (struct tst_size_context_data *) tst->data; - if ( ctx_data->type == SIZE_OVER ) + if ( ctx_data->type == SIZE_OVER ) sieve_operation_emit(cgenv->sblock, NULL, &tst_size_over_operation); else sieve_operation_emit(cgenv->sblock, NULL, &tst_size_under_operation); @@ -209,12 +209,12 @@ bool tst_size_generate /* Generate arguments */ if ( !sieve_generate_arguments(cgenv, tst, NULL) ) return FALSE; - + return TRUE; } -/* - * Code dump +/* + * Code dump */ static bool tst_size_operation_dump @@ -222,17 +222,17 @@ static bool tst_size_operation_dump { sieve_code_dumpf(denv, "%s", sieve_operation_mnemonic(denv->oprtn)); sieve_code_descend(denv); - - return + + return sieve_opr_number_dump(denv, address, "limit"); } -/* - * Code execution +/* + * Code execution */ static inline bool tst_size_get -(const struct sieve_runtime_env *renv, sieve_number_t *size) +(const struct sieve_runtime_env *renv, sieve_number_t *size) { struct mail *mail = sieve_message_get_mail(renv->msgctx); uoff_t psize; @@ -241,7 +241,7 @@ static inline bool tst_size_get return FALSE; *size = psize; - + return TRUE; } @@ -250,19 +250,19 @@ static int tst_size_operation_execute { sieve_number_t mail_size, limit; int ret; - + /* * Read operands */ /* Read size limit */ if ( (ret=sieve_opr_number_read(renv, address, "limit", &limit)) <= 0 ) - return ret; + return ret; /* * Perform test */ - + /* Get the size of the message */ if ( !tst_size_get(renv, &mail_size) ) { /* FIXME: improve this error */ @@ -273,7 +273,7 @@ static int tst_size_operation_execute /* Perform the test */ if ( sieve_operation_is(renv->oprtn, tst_size_over_operation) ) { sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, "size :over test"); - + if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_MATCHING) ) { sieve_runtime_trace_descend(renv); diff --git a/src/lib-sieve/tst-truefalse.c b/src/lib-sieve/tst-truefalse.c index a7e5da14e6c696565f618f08a9ac8d08e584a819..93afc8406c23f5c858dd56a0508cab0e0616d7e8 100644 --- a/src/lib-sieve/tst-truefalse.c +++ b/src/lib-sieve/tst-truefalse.c @@ -21,14 +21,14 @@ static bool tst_false_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd, struct sieve_jumplist *jumps, bool jump_true); -const struct sieve_command_def tst_false = { - "false", - SCT_TEST, +const struct sieve_command_def tst_false = { + "false", + SCT_TEST, 0, 0, FALSE, FALSE, NULL, NULL, NULL, - tst_false_validate_const, + tst_false_validate_const, NULL, - tst_false_generate + tst_false_generate }; static bool tst_true_validate_const @@ -38,14 +38,14 @@ static bool tst_true_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd, struct sieve_jumplist *jumps, bool jump_true); -const struct sieve_command_def tst_true = { - "true", - SCT_TEST, +const struct sieve_command_def tst_true = { + "true", + SCT_TEST, 0, 0, FALSE, FALSE, NULL, NULL, NULL, tst_true_validate_const, - NULL, - tst_true_generate + NULL, + tst_true_generate }; /* @@ -75,7 +75,7 @@ static bool tst_true_validate_const */ static bool tst_false_generate -(const struct sieve_codegen_env *cgenv, +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd ATTR_UNUSED, struct sieve_jumplist *jumps, bool jump_true) { @@ -83,12 +83,12 @@ static bool tst_false_generate sieve_operation_emit(cgenv->sblock, NULL, &sieve_jmp_operation); sieve_jumplist_add(jumps, sieve_binary_emit_offset(cgenv->sblock, 0)); } - + return TRUE; } static bool tst_true_generate -(const struct sieve_codegen_env *cgenv, +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd ATTR_UNUSED, struct sieve_jumplist *jumps, bool jump_true) { @@ -96,7 +96,7 @@ static bool tst_true_generate sieve_operation_emit(cgenv->sblock, NULL, &sieve_jmp_operation); sieve_jumplist_add(jumps, sieve_binary_emit_offset(cgenv->sblock, 0)); } - + return TRUE; } diff --git a/src/lib-sievestorage/Makefile.am b/src/lib-sievestorage/Makefile.am index 98f40e556ed0c648763ad2926832c05d84573a42..181971db2ed8d1d03df1cd604073764da3580dae 100644 --- a/src/lib-sievestorage/Makefile.am +++ b/src/lib-sievestorage/Makefile.am @@ -10,7 +10,7 @@ libsievestorage_a_SOURCES = \ sieve-storage-script.c \ sieve-storage-list.c \ sieve-storage-quota.c \ - sieve-storage.c + sieve-storage.c noinst_HEADERS = \ sieve-storage-save.h \ diff --git a/src/lib-sievestorage/sieve-storage-list.c b/src/lib-sievestorage/sieve-storage-list.c index 3941f41b5a8ae1b862c0a141e1c8d4a7c21346cf..e840e9242b27b5d8526f75d7ffc2d17d044c5153 100644 --- a/src/lib-sievestorage/sieve-storage-list.c +++ b/src/lib-sievestorage/sieve-storage-list.c @@ -31,7 +31,7 @@ struct sieve_list_context { struct sieve_list_context *sieve_storage_list_init (struct sieve_storage *storage) -{ +{ struct sieve_list_context *ctx; const char *active = NULL; pool_t pool; @@ -57,7 +57,7 @@ struct sieve_list_context *sieve_storage_list_init ctx->seen_active = FALSE; } } T_END; - + return ctx; } @@ -74,15 +74,15 @@ const char *sieve_storage_list_next if ( (dp = readdir(ctx->dirp)) == NULL ) return NULL; - scriptname = sieve_scriptfile_get_script_name(dp->d_name); + scriptname = sieve_scriptfile_get_script_name(dp->d_name); if (scriptname != NULL ) { - /* Don't list our active sieve script link if the link + /* Don't list our active sieve script link if the link * resides in the script dir (generally a bad idea). */ - if ( *(storage->link_path) == '\0' && + if ( *(storage->link_path) == '\0' && strcmp(storage->active_fname, dp->d_name) == 0 ) continue; - + break; } } @@ -108,5 +108,5 @@ int sieve_storage_list_deinit(struct sieve_list_context **ctx) } - - + + diff --git a/src/lib-sievestorage/sieve-storage-list.h b/src/lib-sievestorage/sieve-storage-list.h index 76ac9d69f5f0a77873003da32724749671157ffc..35f89a27a552730f30070a7d1e1f1e4edcb82c07 100644 --- a/src/lib-sievestorage/sieve-storage-list.h +++ b/src/lib-sievestorage/sieve-storage-list.h @@ -25,5 +25,5 @@ int sieve_storage_list_deinit #endif - - + + diff --git a/src/lib-sievestorage/sieve-storage-private.h b/src/lib-sievestorage/sieve-storage-private.h index 658f5a1d2c3847c92e38e99efd4d845433880e12..bd2b6415847a1bc63d076aa4a9b310da75fa63fc 100644 --- a/src/lib-sievestorage/sieve-storage-private.h +++ b/src/lib-sievestorage/sieve-storage-private.h @@ -40,7 +40,7 @@ struct sieve_storage { char *dir; bool debug; - /* Private */ + /* Private */ char *active_path; char *active_fname; char *link_path; diff --git a/src/lib-sievestorage/sieve-storage-quota.c b/src/lib-sievestorage/sieve-storage-quota.c index 0989b504d474322cb7f3f4ba743321644981550a..b0c42316e5c63e06a37ff371b3c8a16d5084aa75 100644 --- a/src/lib-sievestorage/sieve-storage-quota.c +++ b/src/lib-sievestorage/sieve-storage-quota.c @@ -44,7 +44,7 @@ uint64_t sieve_storage_quota_max_script_size int sieve_storage_quota_havespace (struct sieve_storage *storage, const char *scriptname, size_t size, enum sieve_storage_quota *quota_r, uint64_t *limit_r) -{ +{ struct dirent *dp; DIR *dirp; uint64_t script_count = 1; @@ -89,16 +89,16 @@ int sieve_storage_quota_havespace } /* Parse filename */ - name = sieve_scriptfile_get_script_name(dp->d_name); + name = sieve_scriptfile_get_script_name(dp->d_name); /* Ignore non-script files */ if ( name == NULL ) continue; - - /* Don't list our active sieve script link if the link + + /* Don't list our active sieve script link if the link * resides in the script dir (generally a bad idea). */ - if ( *(storage->link_path) == '\0' && + if ( *(storage->link_path) == '\0' && strcmp(storage->active_fname, dp->d_name) == 0 ) continue; @@ -109,8 +109,8 @@ int sieve_storage_quota_havespace if ( storage->max_scripts > 0 ) { if ( !replaced ) { script_count++; - - if ( script_count > storage->max_scripts ) { + + if ( script_count > storage->max_scripts ) { *quota_r = SIEVE_STORAGE_QUOTA_MAXSCRIPTS; *limit_r = storage->max_scripts; result = 0; @@ -120,12 +120,12 @@ int sieve_storage_quota_havespace } /* Check storage quota if necessary */ - if ( storage->max_storage > 0 ) { + if ( storage->max_storage > 0 ) { const char *path; struct stat st; path = t_strconcat(storage->dir, "/", dp->d_name, NULL); - + if ( stat(path, &st) < 0 ) { i_warning ("sieve-storage: quota: stat(%s) failed: %m", path); @@ -139,7 +139,7 @@ int sieve_storage_quota_havespace *quota_r = SIEVE_STORAGE_QUOTA_MAXSTORAGE; *limit_r = storage->max_storage; result = 0; - break; + break; } } } @@ -155,5 +155,5 @@ int sieve_storage_quota_havespace } - - + + diff --git a/src/lib-sievestorage/sieve-storage-quota.h b/src/lib-sievestorage/sieve-storage-quota.h index 9b50f4baed7757f73ba7789234a4248439946db8..245e1d2e05e9a4661d50cc6adc332452049bfea3 100644 --- a/src/lib-sievestorage/sieve-storage-quota.h +++ b/src/lib-sievestorage/sieve-storage-quota.h @@ -24,5 +24,5 @@ uint64_t sieve_storage_quota_max_script_size int sieve_storage_quota_havespace (struct sieve_storage *storage, const char *scriptname, size_t size, enum sieve_storage_quota *quota_r, uint64_t *limit_r); - + #endif /* __SIEVE_STORAGE_QUOTA_H */ diff --git a/src/lib-sievestorage/sieve-storage-save.c b/src/lib-sievestorage/sieve-storage-save.c index c99b12d5ef23853aecac298c07161463a80a6335..9bc1f033ec4322c8d93048bbff086b49e8bf8e32 100644 --- a/src/lib-sievestorage/sieve-storage-save.c +++ b/src/lib-sievestorage/sieve-storage-save.c @@ -76,7 +76,7 @@ static int sieve_storage_create_tmp string_t *path; int fd; - path = t_str_new(256); + path = t_str_new(256); str_append(path, storage->dir); str_append(path, "/tmp/"); prefix_len = str_len(path); @@ -90,7 +90,7 @@ static int sieve_storage_create_tmp possibility of that happening is if time had moved backwards, but even then it's highly unlikely. */ if (stat(str_c(path), &st) == 0) { - /* try another file name */ + /* try another file name */ } else if (errno != ENOENT) { sieve_storage_set_critical(storage, "stat(%s) failed: %m", str_c(path)); @@ -118,7 +118,7 @@ static int sieve_storage_create_tmp sieve_storage_set_critical(storage, "open(%s) failed: %m", str_c(path)); } - } + } return fd; } @@ -171,13 +171,13 @@ sieve_storage_save_init(struct sieve_storage *storage, if ( scriptname != NULL ) { /* Validate script name */ if ( !sieve_script_name_is_valid(scriptname) ) { - sieve_storage_set_error(storage, + sieve_storage_set_error(storage, SIEVE_ERROR_BAD_PARAMS, "Invalid script name '%s'.", scriptname); return NULL; } - /* Prevent overwriting the active script link when it resides in the + /* Prevent overwriting the active script link when it resides in the * sieve storage directory. */ if ( *(storage->link_path) == '\0' ) { @@ -187,12 +187,12 @@ sieve_storage_save_init(struct sieve_storage *storage, svext = strrchr(storage->active_fname, '.'); namelen = svext - storage->active_fname; if ( svext != NULL && strncmp(svext+1, "sieve", 5) == 0 && - strlen(scriptname) == namelen && - strncmp(scriptname, storage->active_fname, namelen) == 0 ) + strlen(scriptname) == namelen && + strncmp(scriptname, storage->active_fname, namelen) == 0 ) { sieve_storage_set_error( - storage, SIEVE_ERROR_BAD_PARAMS, - "Script name '%s' is reserved for internal use.", scriptname); + storage, SIEVE_ERROR_BAD_PARAMS, + "Script name '%s' is reserved for internal use.", scriptname); return NULL; } } @@ -261,7 +261,7 @@ int sieve_storage_save_finish(struct sieve_save_context *ctx) if ( ctx->failed ) { /* delete the tmp file */ - if (unlink(ctx->tmp_path) < 0 && errno != ENOENT) + if (unlink(ctx->tmp_path) < 0 && errno != ENOENT) i_warning("sieve-storage: Unlink(%s) failed: %m", ctx->tmp_path); errno = output_errno; @@ -290,23 +290,23 @@ static void sieve_storage_save_destroy(struct sieve_save_context **ctx) struct sieve_script *sieve_storage_save_get_tempscript (struct sieve_save_context *ctx) { - const char *scriptname = - ( ctx->scriptname == NULL ? "" : ctx->scriptname ); + const char *scriptname = + ( ctx->scriptname == NULL ? "" : ctx->scriptname ); - if (ctx->failed) + if (ctx->failed) return NULL; if ( ctx->scriptobject != NULL ) return ctx->scriptobject; ctx->scriptobject = sieve_storage_script_init_from_path - (ctx->storage, ctx->tmp_path, scriptname); + (ctx->storage, ctx->tmp_path, scriptname); if ( ctx->scriptobject == NULL ) { if ( ctx->storage->error_code == SIEVE_ERROR_NOT_FOUND ) { - sieve_storage_set_critical(ctx->storage, + sieve_storage_set_critical(ctx->storage, "save: Temporary script file with name '%s' got lost, " - "which should not happen (possibly deleted externally).", + "which should not happen (possibly deleted externally).", ctx->tmp_path); } return NULL; @@ -344,7 +344,7 @@ int sieve_storage_save_commit(struct sieve_save_context **ctx) i_assert((*ctx)->scriptname != NULL); T_BEGIN { - dest_path = t_strconcat((*ctx)->storage->dir, "/", + dest_path = t_strconcat((*ctx)->storage->dir, "/", sieve_scriptfile_from_name((*ctx)->scriptname), NULL); failed = !sieve_storage_script_move((*ctx), dest_path); @@ -359,7 +359,7 @@ void sieve_storage_save_cancel(struct sieve_save_context **ctx) { (*ctx)->failed = TRUE; - if (!(*ctx)->finished) + if (!(*ctx)->finished) (void)sieve_storage_save_finish(*ctx); else (void)unlink((*ctx)->tmp_path); diff --git a/src/lib-sievestorage/sieve-storage-script.c b/src/lib-sievestorage/sieve-storage-script.c index d240697212f074115ca398a32e21db0812e2007c..7314addcb7d1f442fe1bc44c65807cac51f97759 100644 --- a/src/lib-sievestorage/sieve-storage-script.c +++ b/src/lib-sievestorage/sieve-storage-script.c @@ -25,17 +25,17 @@ #include <fcntl.h> struct sieve_storage_script { - struct sieve_file_script file; + struct sieve_file_script file; struct sieve_storage *storage; }; struct sieve_script *sieve_storage_script_init_from_path -(struct sieve_storage *storage, const char *path, +(struct sieve_storage *storage, const char *path, const char *scriptname) { pool_t pool; - struct sieve_storage_script *st_script = NULL; + struct sieve_storage_script *st_script = NULL; enum sieve_error error; /* Prevent initializing the active script link as a script when it @@ -57,7 +57,7 @@ struct sieve_script *sieve_storage_script_init_from_path } } - pool = pool_alloconly_create("sieve_storage_script", 4096); + pool = pool_alloconly_create("sieve_storage_script", 4096); st_script = p_new(pool, struct sieve_storage_script, 1); st_script->file.script = sieve_file_script; st_script->file.script.pool = pool; @@ -79,11 +79,11 @@ struct sieve_script *sieve_storage_script_init_from_path struct sieve_script *sieve_storage_script_init (struct sieve_storage *storage, const char *scriptname) -{ +{ struct sieve_script *script; const char *path; - /* Validate script name */ + /* Validate script name */ if ( !sieve_script_name_is_valid(scriptname) ) { sieve_storage_set_error(storage, SIEVE_ERROR_BAD_PARAMS, "Invalid script name '%s'.", scriptname); @@ -102,7 +102,7 @@ struct sieve_script *sieve_storage_script_init static struct sieve_script *sieve_storage_script_init_from_file (struct sieve_storage *storage, const char *scriptfile) -{ +{ struct sieve_script *script; const char *path; @@ -144,7 +144,7 @@ static int sieve_storage_read_active_link /* We do need to panic otherwise */ sieve_storage_set_critical(storage, - "Performing readlink() on active sieve symlink '%s' failed: %m", + "Performing readlink() on active sieve symlink '%s' failed: %m", storage->active_path); return -1; } @@ -188,7 +188,7 @@ static const char *sieve_storage_parse_link ("sieve-storage: Active sieve script symlink %s is broken: " "invalid/unknown path to storage (points to %s).", storage->active_path, link); - return NULL; + return NULL; } if ( scriptname_r != NULL ) @@ -276,8 +276,8 @@ struct sieve_script *sieve_storage_get_active_script */ return NULL; } - - script = sieve_storage_script_init_from_file(storage, scriptfile); + + script = sieve_storage_script_init_from_file(storage, scriptfile); if ( script == NULL && storage->error_code == SIEVE_ERROR_NOT_FOUND ) { i_warning @@ -298,7 +298,7 @@ int sieve_storage_script_is_active(struct sieve_script *script) T_BEGIN { ret = sieve_storage_get_active_scriptfile(st_script->storage, &afile); - + if ( ret > 0 ) { /* Is the requested script active? */ ret = ( strcmp(st_script->file.filename, afile) == 0 ? 1 : 0 ); @@ -308,9 +308,9 @@ int sieve_storage_script_is_active(struct sieve_script *script) return ret; } -int sieve_storage_script_delete(struct sieve_script **script) +int sieve_storage_script_delete(struct sieve_script **script) { - struct sieve_storage_script *st_script = + struct sieve_storage_script *st_script = (struct sieve_storage_script *) *script; struct sieve_storage *storage = st_script->storage; int ret = 0; @@ -324,33 +324,33 @@ int sieve_storage_script_delete(struct sieve_script **script) ret = unlink(st_script->file.path); if ( ret < 0 ) { - if ( errno == ENOENT ) + if ( errno == ENOENT ) sieve_storage_set_error(storage, SIEVE_ERROR_NOT_FOUND, "Sieve script does not exist."); else sieve_storage_set_critical( - storage, "Performing unlink() failed on sieve file '%s': %m", + storage, "Performing unlink() failed on sieve file '%s': %m", st_script->file.path); - } + } } /* Always deinitialize the script object */ sieve_script_unref(script); - return ret; + return ret; } static bool sieve_storage_rescue_regular_file(struct sieve_storage *storage) { struct stat st; - + /* Stat the file */ if ( lstat(storage->active_path, &st) != 0 ) { if ( errno != ENOENT ) { - sieve_storage_set_critical(storage, - "Failed to stat active sieve script symlink (%s): %m.", - storage->active_path); - return FALSE; - } + sieve_storage_set_critical(storage, + "Failed to stat active sieve script symlink (%s): %m.", + storage->active_path); + return FALSE; + } return TRUE; } @@ -370,15 +370,15 @@ static bool sieve_storage_rescue_regular_file(struct sieve_storage *storage) dstpath = t_strconcat ( storage->dir, "/", sieve_scriptfile_from_name("dovecot.orig"), NULL ); if ( file_copy(storage->active_path, dstpath, 1) < 1 ) { - sieve_storage_set_critical(storage, + sieve_storage_set_critical(storage, "Active sieve script file '%s' is a regular file and copying it to " "the script storage as '%s' failed. This needs to be fixed manually.", storage->active_path, dstpath); - result = FALSE; + result = FALSE; } else { i_info("sieve-storage: Moved active sieve script file '%s' " "to script storage as '%s'.", - storage->active_path, dstpath); + storage->active_path, dstpath); } } T_END; @@ -388,14 +388,14 @@ static bool sieve_storage_rescue_regular_file(struct sieve_storage *storage) sieve_storage_set_critical( storage, "Active sieve script file '%s' is no symlink nor a regular file. " "This needs to be fixed manually.", storage->active_path ); - return FALSE; + return FALSE; } int sieve_storage_deactivate(struct sieve_storage *storage) { int ret; - if ( !sieve_storage_rescue_regular_file(storage) ) + if ( !sieve_storage_rescue_regular_file(storage) ) return -1; /* Delete the symlink, so no script is active */ @@ -406,9 +406,9 @@ int sieve_storage_deactivate(struct sieve_storage *storage) sieve_storage_set_critical(storage, "sieve_storage_deactivate(): " "error on unlink(%s): %m", storage->active_path); return -1; - } else + } else return 0; - } + } return 1; } @@ -418,11 +418,11 @@ static int sieve_storage_replace_active_link { const char *active_path_new; struct timeval *tv, tv_now; - int ret = 0; + int ret = 0; tv = &ioloop_timeval; - for (;;) { + for (;;) { /* First the new symlink is created with a different filename */ active_path_new = t_strdup_printf ("%s-new.%s.P%sM%s.%s", @@ -431,7 +431,7 @@ static int sieve_storage_replace_active_link dec2str(tv->tv_usec), my_hostname); ret = symlink(link_path, active_path_new); - + if ( ret < 0 ) { /* If link exists we try again later */ if ( errno == EEXIST ) { @@ -445,11 +445,11 @@ static int sieve_storage_replace_active_link /* Other error, critical */ sieve_storage_set_critical - (storage, "Creating symlink() %s to %s failed: %m", + (storage, "Creating symlink() %s to %s failed: %m", active_path_new, link_path); return -1; } - + /* Link created */ break; } @@ -461,17 +461,17 @@ static int sieve_storage_replace_active_link /* Failed; created symlink must be deleted */ (void)unlink(active_path_new); sieve_storage_set_critical - (storage, "Performing rename() %s to %s failed: %m", + (storage, "Performing rename() %s to %s failed: %m", active_path_new, storage->active_path); return -1; - } + } return 1; } static int _sieve_storage_script_activate(struct sieve_script *script) { - struct sieve_storage_script *st_script = + struct sieve_storage_script *st_script = (struct sieve_storage_script *) script; struct sieve_storage *storage = st_script->storage; struct stat st; @@ -487,18 +487,18 @@ static int _sieve_storage_script_activate(struct sieve_script *script) ret = sieve_storage_get_active_scriptfile(storage, &afile); /* Is the requested script already active? */ - if ( ret <= 0 || strcmp(st_script->file.filename, afile) != 0 ) - activated = 1; + if ( ret <= 0 || strcmp(st_script->file.filename, afile) != 0 ) + activated = 1; /* Check the scriptfile we are trying to activate */ if ( lstat(st_script->file.path, &st) != 0 ) { - sieve_storage_set_critical(storage, - "Stat on sieve script %s failed, but it is to be activated: %m.", + sieve_storage_set_critical(storage, + "Stat on sieve script %s failed, but it is to be activated: %m.", st_script->file.path); return -1; } - /* Rescue a possible .dovecot.sieve regular file remaining from old + /* Rescue a possible .dovecot.sieve regular file remaining from old * installations. */ if ( !sieve_storage_rescue_regular_file(storage) ) { @@ -509,7 +509,7 @@ static int _sieve_storage_script_activate(struct sieve_script *script) /* Just try to create the symlink first */ link_path = t_strconcat ( storage->link_path, st_script->file.filename, NULL ); - + ret = symlink(link_path, storage->active_path); if ( ret < 0 ) { @@ -534,8 +534,8 @@ static int _sieve_storage_script_activate(struct sieve_script *script) int sieve_storage_script_activate(struct sieve_script *script) { int ret; - - T_BEGIN { + + T_BEGIN { ret = _sieve_storage_script_activate(script); } T_END; @@ -543,9 +543,9 @@ int sieve_storage_script_activate(struct sieve_script *script) } int sieve_storage_script_rename -(struct sieve_script *script, const char *newname) +(struct sieve_script *script, const char *newname) { - struct sieve_storage_script *st_script = + struct sieve_storage_script *st_script = (struct sieve_storage_script *) script; struct sieve_storage *storage = st_script->storage; const char *newpath, *newfile, *link_path; @@ -553,8 +553,8 @@ int sieve_storage_script_rename /* Check script name */ if ( !sieve_script_name_is_valid(newname) ) { - sieve_storage_set_error(storage, - SIEVE_ERROR_BAD_PARAMS, + sieve_storage_set_error(storage, + SIEVE_ERROR_BAD_PARAMS, "Invalid new script name '%s'.", newname); return -1; } @@ -564,7 +564,7 @@ int sieve_storage_script_rename newpath = t_strconcat( storage->dir, "/", newfile, NULL ); /* The normal rename() system call overwrites the existing file without - * notice. Also, active scripts must not be disrupted by renaming a script. + * notice. Also, active scripts must not be disrupted by renaming a script. * That is why we use a link(newpath) [activate newpath] unlink(oldpath) */ @@ -583,7 +583,7 @@ int sieve_storage_script_rename if ( ret >= 0 ) { /* If all is good, remove the old link */ if ( unlink(st_script->file.path) < 0 ) { - i_error("Failed to clean up old file link '%s' after rename: %m", + i_error("Failed to clean up old file link '%s' after rename: %m", st_script->file.path); } @@ -592,8 +592,8 @@ int sieve_storage_script_rename st_script->file.path = p_strdup(script->pool, newpath); st_script->file.filename = p_strdup(script->pool, newfile); } else { - /* If something went wrong, remove the new link to restore previous - * state + /* If something went wrong, remove the new link to restore previous + * state */ if ( unlink(newpath) < 0 ) { i_error("Failed to clean up new file link '%s'" @@ -603,8 +603,8 @@ int sieve_storage_script_rename } else { /* Our efforts failed right away */ switch ( errno ) { - case ENOENT: - sieve_storage_set_error(storage, SIEVE_ERROR_NOT_FOUND, + case ENOENT: + sieve_storage_set_error(storage, SIEVE_ERROR_NOT_FOUND, "Sieve script does not exist."); break; case EEXIST: @@ -613,13 +613,13 @@ int sieve_storage_script_rename break; default: sieve_storage_set_critical( - storage, "Performing link(%s, %s) failed: %m", + storage, "Performing link(%s, %s) failed: %m", st_script->file.path, newpath); - } + } } } T_END; - return ret; + return ret; } diff --git a/src/lib-sievestorage/sieve-storage.c b/src/lib-sievestorage/sieve-storage.c index ec2036db61f9a295a5eb401d84ec0b3fc48364fa..9c58cc690bb6b6b2fb37354eda7679442d4fe71c 100644 --- a/src/lib-sievestorage/sieve-storage.c +++ b/src/lib-sievestorage/sieve-storage.c @@ -37,34 +37,34 @@ static void sieve_storage_verror const char *fmt, va_list args); static const char *sieve_storage_get_relative_link_path - (const char *active_path, const char *storage_dir) + (const char *active_path, const char *storage_dir) { const char *link_path, *p; size_t pathlen; - - /* Determine to what extent the sieve storage and active script - * paths match up. This enables the managed symlink to be short and the - * sieve storages can be moved around without trouble (if the active + + /* Determine to what extent the sieve storage and active script + * paths match up. This enables the managed symlink to be short and the + * sieve storages can be moved around without trouble (if the active * script path is common to the script storage). - */ + */ p = strrchr(active_path, '/'); if ( p == NULL ) { link_path = storage_dir; - } else { + } else { pathlen = p - active_path; if ( strncmp( active_path, storage_dir, pathlen ) == 0 && - (storage_dir[pathlen] == '/' || storage_dir[pathlen] == '\0') ) + (storage_dir[pathlen] == '/' || storage_dir[pathlen] == '\0') ) { - if ( storage_dir[pathlen] == '\0' ) - link_path = ""; - else + if ( storage_dir[pathlen] == '\0' ) + link_path = ""; + else link_path = storage_dir + pathlen + 1; - } else + } else link_path = storage_dir; } - /* Add trailing '/' when link path is not empty + /* Add trailing '/' when link path is not empty */ pathlen = strlen(link_path); if ( pathlen != 0 && link_path[pathlen-1] != '/') @@ -85,7 +85,7 @@ static mode_t get_dir_mode(mode_t mode) } static void sieve_storage_get_permissions -(const char *path, mode_t *file_mode_r, mode_t *dir_mode_r, gid_t *gid_r, +(const char *path, mode_t *file_mode_r, mode_t *dir_mode_r, gid_t *gid_r, const char **gid_origin_r, bool debug) { struct stat st; @@ -129,7 +129,7 @@ static void sieve_storage_get_permissions } if ( debug ) { - i_debug("sieve-storage: using permissions from %s: mode=0%o gid=%ld", + i_debug("sieve-storage: using permissions from %s: mode=0%o gid=%ld", path, (int)*dir_mode_r, *gid_r == (gid_t)-1 ? -1L : (long)*gid_r); } } @@ -228,7 +228,7 @@ static struct sieve_storage *_sieve_storage_create if ( *active_path == '\0' ) { /* disabled */ - if ( debug ) + if ( debug ) i_debug("sieve-storage: sieve is disabled (sieve=\"\")"); return NULL; } @@ -271,15 +271,15 @@ static struct sieve_storage *_sieve_storage_create /* Get the filename for the active script link */ active_fname = strrchr(active_path, '/'); - if ( active_fname == NULL ) + if ( active_fname == NULL ) active_fname = active_path; else active_fname++; - if ( *active_fname == '\0' ) { + if ( *active_fname == '\0' ) { /* Link cannot be just a path */ i_error("sieve-storage: " - "path to active symlink must include the link's filename. Path is: %s", + "path to active symlink must include the link's filename. Path is: %s", active_path); return NULL; @@ -303,7 +303,7 @@ static struct sieve_storage *_sieve_storage_create if ( sieve_data == NULL || *sieve_data == '\0' ) { /* We'll need to figure out the storage location ourself. * - * It's $HOME/sieve or /sieve when (presumed to be) chrooted. + * It's $HOME/sieve or /sieve when (presumed to be) chrooted. */ if ( home != NULL && *home != '\0' ) { if (access(home, R_OK|W_OK|X_OK) == 0) { @@ -375,16 +375,16 @@ static struct sieve_storage *_sieve_storage_create i_debug("sieve-storage: " "using active sieve script path: %s", active_path); i_debug("sieve-storage: " - "using sieve script storage directory: %s", storage_dir); + "using sieve script storage directory: %s", storage_dir); } /* Get permissions */ sieve_storage_get_permissions - (storage_dir, &file_create_mode, &dir_create_mode, &file_create_gid, + (storage_dir, &file_create_mode, &dir_create_mode, &file_create_gid, &file_create_gid_origin, debug); - /* + /* * Ensure sieve local directory structure exists (full autocreate): * This currently only consists of a ./tmp direcory */ @@ -418,7 +418,7 @@ static struct sieve_storage *_sieve_storage_create storage->file_create_mode = file_create_mode; storage->file_create_gid = file_create_gid; - /* Get the path to be prefixed to the script name in the symlink pointing + /* Get the path to be prefixed to the script name in the symlink pointing * to the active script. */ link_path = sieve_storage_get_relative_link_path @@ -447,11 +447,11 @@ static struct sieve_storage *_sieve_storage_create if ( debug ) { if ( storage->max_storage > 0 ) { - i_info("sieve-storage: quota: storage limit: %llu bytes", + i_info("sieve-storage: quota: storage limit: %llu bytes", (unsigned long long int) storage->max_storage); } if ( storage->max_scripts > 0 ) { - i_info("sieve-storage: quota: script count limit: %llu scripts", + i_info("sieve-storage: quota: script count limit: %llu scripts", (unsigned long long int) storage->max_scripts); } } @@ -493,7 +493,7 @@ struct sieve_error_handler *sieve_storage_get_error_handler ehandler->handler.verror = sieve_storage_verror; ehandler->storage = storage; - + storage->ehandler = (struct sieve_error_handler *) ehandler; } @@ -504,12 +504,12 @@ static void ATTR_FORMAT(4, 0) sieve_storage_verror (struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED, const char *location ATTR_UNUSED, const char *fmt, va_list args) { - struct sieve_storage_ehandler *sehandler = - (struct sieve_storage_ehandler *) ehandler; + struct sieve_storage_ehandler *sehandler = + (struct sieve_storage_ehandler *) ehandler; struct sieve_storage *storage = sehandler->storage; sieve_storage_clear_error(storage); - + if (fmt != NULL) { storage->error = i_strdup_vprintf(fmt, args); } @@ -558,13 +558,13 @@ void sieve_storage_set_critical (struct sieve_storage *storage, const char *fmt, ...) { va_list va; - + sieve_storage_clear_error(storage); if (fmt != NULL) { va_start(va, fmt); i_error("sieve-storage: %s", t_strdup_vprintf(fmt, va)); va_end(va); - + /* critical errors may contain sensitive data, so let user see only "Internal error" with a timestamp to make it easier to look from log files the actual error message. */ @@ -577,10 +577,10 @@ const char *sieve_storage_get_last_error { /* We get here only in error situations, so we have to return some error. If storage->error is NULL, it means we forgot to set it at - some point.. + some point.. */ - - if ( error_r != NULL ) + + if ( error_r != NULL ) *error_r = storage->error_code; return storage->error != NULL ? storage->error : "Unknown error"; diff --git a/src/lib-sievestorage/sieve-storage.h b/src/lib-sievestorage/sieve-storage.h index 608e3f63857a7901900e306d58272d3f22f475eb..e49d37622eb4b012d8c83238ad31dd710c062e3b 100644 --- a/src/lib-sievestorage/sieve-storage.h +++ b/src/lib-sievestorage/sieve-storage.h @@ -21,7 +21,7 @@ struct sieve_error_handler *sieve_storage_get_error_handler void sieve_storage_clear_error(struct sieve_storage *storage); void sieve_storage_set_error - (struct sieve_storage *storage, enum sieve_error error, + (struct sieve_storage *storage, enum sieve_error error, const char *fmt, ...) ATTR_FORMAT(3, 4); void sieve_storage_set_critical(struct sieve_storage *storage, diff --git a/src/managesieve-login/client-authenticate.c b/src/managesieve-login/client-authenticate.c index 849dab3b41a3ee3ce01122b0ddee53d611e41d32..95053b14e96c13ee97125a755c62b5616c7883c6 100644 --- a/src/managesieve-login/client-authenticate.c +++ b/src/managesieve-login/client-authenticate.c @@ -78,7 +78,7 @@ bool managesieve_client_auth_handle_reply if ( reply->reason == NULL ) { if ( reply->nologin ) reason = "Try this server instead."; - else + else reason = "Logged in, but you should use " "this server instead."; } else { @@ -116,7 +116,7 @@ bool managesieve_client_auth_handle_reply msieve_client->auth_response_input = NULL; managesieve_parser_reset(msieve_client->parser); - if ( !client->destroyed ) + if ( !client->destroyed ) client_auth_failed(client); return TRUE; } @@ -152,7 +152,7 @@ static int managesieve_client_auth_read_response uoff_t resp_size; int ret; - if ( i_stream_read(client->input) == -1 ) { + if ( i_stream_read(client->input) == -1 ) { /* disconnected */ client_destroy(client, "Disconnected"); return -1; @@ -295,7 +295,7 @@ int cmd_authenticate const char *mech_name, *init_response; const char *error; int ret; - + if (!msieve_client->auth_mech_name_parsed) { i_assert(args != NULL); @@ -303,7 +303,7 @@ int cmd_authenticate if ( !managesieve_arg_get_string(&args[0], &mech_name) ) return -1; - if (*mech_name == '\0') + if (*mech_name == '\0') return -1; /* Refuse the ANONYMOUS mechanism. */ @@ -338,6 +338,6 @@ int cmd_authenticate return ret; msieve_client->cmd_finished = TRUE; - return 0; + return 0; } diff --git a/src/managesieve-login/client.c b/src/managesieve-login/client.c index 0bdeac48e5c040cc29391d3e723f60d7de8634ca..4bc48becae22cb84c8d620bc4316904ff50338c5 100644 --- a/src/managesieve-login/client.c +++ b/src/managesieve-login/client.c @@ -56,7 +56,7 @@ bool client_skip_line(struct managesieve_client *client) static void client_send_capabilities(struct client *client) { - struct managesieve_client *msieve_client = + struct managesieve_client *msieve_client = (struct managesieve_client *) client; const char *saslcap; @@ -64,12 +64,12 @@ static void client_send_capabilities(struct client *client) saslcap = client_authenticate_get_capabilities(client); /* Default capabilities */ - client_send_raw(client, t_strconcat("\"IMPLEMENTATION\" \"", + client_send_raw(client, t_strconcat("\"IMPLEMENTATION\" \"", msieve_client->set->managesieve_implementation_string, "\"\r\n", NULL)); - client_send_raw(client, t_strconcat("\"SIEVE\" \"", + client_send_raw(client, t_strconcat("\"SIEVE\" \"", msieve_client->set->managesieve_sieve_capability, "\"\r\n", NULL)); if ( msieve_client->set->managesieve_notify_capability != NULL ) - client_send_raw(client, t_strconcat("\"NOTIFY\" \"", + client_send_raw(client, t_strconcat("\"NOTIFY\" \"", msieve_client->set->managesieve_notify_capability, "\"\r\n", NULL)); client_send_raw (client, t_strconcat("\"SASL\" \"", saslcap, "\"\r\n", NULL)); @@ -180,7 +180,7 @@ static bool client_handle_input(struct managesieve_client *client) if (client->cmd == NULL) { struct managesieve_command *cmd; const char *cmd_name; - + client->cmd_name = managesieve_parser_read_word(client->parser); if (client->cmd_name == NULL) return FALSE; /* need more data */ @@ -192,13 +192,13 @@ static bool client_handle_input(struct managesieve_client *client) break; cmd++; } - + if ( cmd->name != NULL ) client->cmd = cmd; } if ( client->cmd != NULL && !client->cmd_parsed_args ) { - unsigned int arg_count = + unsigned int arg_count = ( client->cmd->preparsed_args > 0 ? client->cmd->preparsed_args : 0 ); switch (managesieve_parser_read_args(client->parser, arg_count, 0, &args)) { case -1: @@ -250,12 +250,12 @@ static bool client_handle_input(struct managesieve_client *client) if (ret < 0) { if (++client->common.bad_counter >= CLIENT_MAX_BAD_COMMANDS) { - client_send_bye(&client->common, + client_send_bye(&client->common, "Too many invalid MANAGESIEVE commands."); - client_destroy(&client->common, + client_destroy(&client->common, "Disconnected: Too many invalid commands."); return FALSE; - } + } client_send_no(&client->common, "Error in MANAGESIEVE command received by server."); } @@ -265,7 +265,7 @@ static bool client_handle_input(struct managesieve_client *client) static void managesieve_client_input(struct client *client) { - struct managesieve_client *managesieve_client = + struct managesieve_client *managesieve_client = (struct managesieve_client *) client; if (!client_read(client)) @@ -306,7 +306,7 @@ static struct client *managesieve_client_alloc(pool_t pool) static void managesieve_client_create (struct client *client, void **other_sets) { - struct managesieve_client *msieve_client = + struct managesieve_client *msieve_client = (struct managesieve_client *) client; msieve_client->set = other_sets[0]; @@ -317,7 +317,7 @@ static void managesieve_client_create static void managesieve_client_destroy(struct client *client) { - struct managesieve_client *managesieve_client = + struct managesieve_client *managesieve_client = (struct managesieve_client *) client; managesieve_parser_destroy(&managesieve_client->parser); @@ -330,7 +330,7 @@ static void managesieve_client_send_greeting(struct client *client) */ o_stream_cork(client->output); - /* Send initial capabilities */ + /* Send initial capabilities */ client_send_capabilities(client); client_send_ok(client, client->set->login_greeting); @@ -340,7 +340,7 @@ static void managesieve_client_send_greeting(struct client *client) static void managesieve_client_starttls(struct client *client) { - struct managesieve_client *msieve_client = + struct managesieve_client *msieve_client = (struct managesieve_client *) client; managesieve_parser_destroy(&msieve_client->parser); @@ -358,24 +358,24 @@ static void managesieve_client_starttls(struct client *client) client_send_capabilities(client); client_send_ok(client, "TLS negotiation successful."); - o_stream_uncork(client->output); + o_stream_uncork(client->output); } -void _client_send_response(struct client *client, +void _client_send_response(struct client *client, const char *oknobye, const char *resp_code, const char *msg) { T_BEGIN { string_t *line = t_str_new(256); str_append(line, oknobye); - + if (resp_code != NULL) { str_append(line, " ["); str_append(line, resp_code); str_append_c(line, ']'); } - - if ( msg != NULL ) + + if ( msg != NULL ) { str_append_c(line, ' '); managesieve_quote_append_string(line, msg, TRUE); diff --git a/src/managesieve-login/client.h b/src/managesieve-login/client.h index dd7242434b1e8142db66d75d2a9a0d9fcf9af649..68450d1f42413260ecadaf556cb8629846b1ae41 100644 --- a/src/managesieve-login/client.h +++ b/src/managesieve-login/client.h @@ -18,7 +18,7 @@ struct managesieve_client { const struct managesieve_login_settings *set; struct managesieve_parser *parser; - unsigned int proxy_state; + unsigned int proxy_state; const char *cmd_name; struct managesieve_command *cmd; diff --git a/src/managesieve-login/managesieve-login-settings-plugin.c b/src/managesieve-login/managesieve-login-settings-plugin.c index aab26820275863de80a695697a07afebbca567e5..3e4378fec6b9c3f48a14067009f9bfbab26a16fe 100644 --- a/src/managesieve-login/managesieve-login-settings-plugin.c +++ b/src/managesieve-login/managesieve-login-settings-plugin.c @@ -69,7 +69,7 @@ static void capability_parse(const char *cap_string) i_warning("managesieve-login: capability string is empty."); return; } - + while ( *p != '\0' ) { if ( *p == '\\' ) { p++; @@ -85,7 +85,7 @@ static void capability_parse(const char *cap_string) else i_warning("managesieve-login: unknown capability '%s' listed in " "capability string (ignored).", str_c(part)); - str_truncate(part, 0); + str_truncate(part, 0); } else if ( *p == ',' ) { capability_store(cap_type, str_c(part)); str_truncate(part, 0); @@ -96,7 +96,7 @@ static void capability_parse(const char *cap_string) } p++; } - + if ( str_len(part) > 0 ) { capability_store(cap_type, str_c(part)); } @@ -130,8 +130,8 @@ static bool capability_dump(void) const char *argv[5]; /* Child */ - (void)close(fd[0]); - + (void)close(fd[0]); + if (dup2(fd[1], STDOUT_FILENO) < 0) i_fatal("managesieve-login: dump-capability dup2() failed: %m"); @@ -151,7 +151,7 @@ static bool capability_dump(void) alarm(60); if (wait(&status) == -1) { - i_error("managesieve-login: dump-capability failed: process %d got stuck", + i_error("managesieve-login: dump-capability failed: process %d got stuck", (int)pid); return FALSE; } diff --git a/src/managesieve-login/managesieve-login-settings.c b/src/managesieve-login/managesieve-login-settings.c index c89c9492bb9d448a1a25b2653207b07d3134ff40..c4ca0c2a256edb0c33065d69e297176d0f1bf851 100644 --- a/src/managesieve-login/managesieve-login-settings.c +++ b/src/managesieve-login/managesieve-login-settings.c @@ -86,7 +86,7 @@ static const struct setting_parser_info managesieve_login_setting_parser_info = .module_name = "managesieve-login", .defines = managesieve_login_setting_defines, .defaults = &managesieve_login_default_settings, - + .type_offset = (size_t)-1, .struct_size = sizeof(struct managesieve_login_settings), diff --git a/src/managesieve-login/managesieve-proxy.c b/src/managesieve-login/managesieve-proxy.c index 276e1f1ce34d4c35d0ced019d90cf80b49054cd5..98537415d340197646e0b085941b428621eec7aa 100644 --- a/src/managesieve-login/managesieve-proxy.c +++ b/src/managesieve-login/managesieve-proxy.c @@ -34,7 +34,7 @@ typedef enum { } managesieve_response_t; static void proxy_free_password(struct client *client) -{ +{ if (client->proxy_password == NULL) return; @@ -43,7 +43,7 @@ static void proxy_free_password(struct client *client) } static void get_plain_auth(struct client *client, string_t *dest) -{ +{ string_t *str, *base64; str = t_str_new(128); @@ -65,7 +65,7 @@ static void get_plain_auth(struct client *client, string_t *dest) } static int proxy_write_login(struct managesieve_client *client, string_t *str) -{ +{ if ( !client->proxy_sasl_plain ) { client_log_err(&client->common, "proxy: " "Server does not support required PLAIN SASL mechanism"); @@ -90,16 +90,16 @@ static managesieve_response_t proxy_read_response if ( strcasecmp(response, "OK") == 0 ) { /* Received OK response; greeting is finished */ - return MANAGESIEVE_RESPONSE_OK; + return MANAGESIEVE_RESPONSE_OK; } else if ( strcasecmp(response, "NO") == 0 ) { /* Received OK response; greeting is finished */ - return MANAGESIEVE_RESPONSE_NO; + return MANAGESIEVE_RESPONSE_NO; } else if ( strcasecmp(response, "BYE") == 0 ) { /* Received OK response; greeting is finished */ return MANAGESIEVE_RESPONSE_BYE; - + } } @@ -107,9 +107,9 @@ static managesieve_response_t proxy_read_response } static int proxy_input_capability -(struct managesieve_client *client, const char *line, +(struct managesieve_client *client, const char *line, managesieve_response_t *resp_r) -{ +{ struct istream *input; struct managesieve_parser *parser; const struct managesieve_arg *args; @@ -119,7 +119,7 @@ static int proxy_input_capability *resp_r = MANAGESIEVE_RESPONSE_NONE; - /* Build an input stream for the managesieve parser + /* Build an input stream for the managesieve parser * FIXME: It would be nice if the line-wise parsing could be * substituded by something similar to the command line interpreter. * However, the current login_proxy structure does not make streams @@ -130,13 +130,13 @@ static int proxy_input_capability parser = managesieve_parser_create(input, MAX_MANAGESIEVE_LINE); managesieve_parser_reset(parser); - /* Parse input - * FIXME: Theoretically the OK response could include a - * response code which could be rejected by the parser. - */ + /* Parse input + * FIXME: Theoretically the OK response could include a + * response code which could be rejected by the parser. + */ (void)i_stream_read(input); ret = managesieve_parser_read_args(parser, 2, 0, &args); - + if ( ret >= 1 ) { if ( args[0].type == MANAGESIEVE_ARG_ATOM ) { *resp_r = proxy_read_response(args); @@ -145,18 +145,18 @@ static int proxy_input_capability client_log_err(&client->common, t_strdup_printf("proxy: " "Remote sent invalid response: %s", str_sanitize(line,160))); - + fatal = TRUE; } } else if ( managesieve_arg_get_string(&args[0], &capability) ) { if ( strcasecmp(capability, "SASL") == 0 ) { const char *sasl_mechs; - /* Check whether the server supports the SASL mechanism - * we are going to use (currently only PLAIN supported). + /* Check whether the server supports the SASL mechanism + * we are going to use (currently only PLAIN supported). */ if ( ret == 2 && managesieve_arg_get_string(&args[1], &sasl_mechs) ) { - const char *const *mechs = t_strsplit(sasl_mechs, " "); + const char *const *mechs = t_strsplit(sasl_mechs, " "); if ( str_array_icase_find(mechs, "PLAIN") ) client->proxy_sasl_plain = TRUE; @@ -188,7 +188,7 @@ static int proxy_input_capability } else if ( ret < 0 ) { const char *error_str = managesieve_parser_get_error(parser, &fatal); error_str = (error_str != NULL ? error_str : "unknown (bug)" ); - + /* Do not accept faulty server */ client_log_err(&client->common, t_strdup_printf("proxy: " "Protocol parse error(%d) in capability/greeting line: %s (line='%s')", @@ -211,9 +211,9 @@ static int proxy_input_capability int managesieve_proxy_parse_line(struct client *client, const char *line) { - struct managesieve_client *msieve_client = + struct managesieve_client *msieve_client = (struct managesieve_client *) client; - struct ostream *output; + struct ostream *output; enum login_proxy_ssl_flags ssl_flags; managesieve_response_t response = MANAGESIEVE_RESPONSE_NONE; string_t *command; @@ -234,7 +234,7 @@ int managesieve_proxy_parse_line(struct client *client, const char *line) client_log_err(client, "proxy: " "Remote sent unexpected NO/BYE in stead of capability response"); client_proxy_failed(client, TRUE); - return -1; + return -1; } command = t_str_new(128); @@ -246,7 +246,7 @@ int managesieve_proxy_parse_line(struct client *client, const char *line) client_proxy_failed(client, TRUE); return -1; } - + str_append(command, "STARTTLS\r\n"); msieve_client->proxy_state = PROXY_STATE_TLS_START; } else { @@ -270,14 +270,14 @@ int managesieve_proxy_parse_line(struct client *client, const char *line) client_proxy_failed(client, TRUE); return -1; } - + msieve_client->proxy_state = PROXY_STATE_TLS_READY; return 1; } client_log_err(client, "proxy: Remote refused STARTTLS command"); client_proxy_failed(client, TRUE); - return -1; + return -1; case PROXY_STATE_TLS_READY: if ( (ret=proxy_input_capability(msieve_client, line, &response)) < 0 ) { @@ -288,8 +288,8 @@ int managesieve_proxy_parse_line(struct client *client, const char *line) if ( ret == 0 ) { if ( response != MANAGESIEVE_RESPONSE_OK ) { /* STARTTLS failed */ - client_log_err(client, - t_strdup_printf("proxy: Remote STARTTLS failed: %s", + client_log_err(client, + t_strdup_printf("proxy: Remote STARTTLS failed: %s", str_sanitize(line, 160))); client_proxy_failed(client, TRUE); return -1; @@ -302,12 +302,12 @@ int managesieve_proxy_parse_line(struct client *client, const char *line) } (void)o_stream_send(output, str_data(command), str_len(command)); - + msieve_client->proxy_state = PROXY_STATE_AUTHENTICATE; } return 0; - + case PROXY_STATE_AUTHENTICATE: /* Check login status */ diff --git a/src/managesieve/Makefile.am b/src/managesieve/Makefile.am index 28b758ecfbbe7fa1bc28537fdd4e4c072943425e..43bab10d55fa1bacfb5dc1ccf48b403be145f88a 100644 --- a/src/managesieve/Makefile.am +++ b/src/managesieve/Makefile.am @@ -49,7 +49,7 @@ managesieve_SOURCES = \ managesieve-client.c \ managesieve-commands.c \ managesieve-capabilities.c \ - main.c + main.c noinst_HEADERS = \ managesieve-quota.h \ @@ -57,4 +57,4 @@ noinst_HEADERS = \ managesieve-commands.h \ managesieve-capabilities.h \ managesieve-settings.h \ - managesieve-common.h + managesieve-common.h diff --git a/src/managesieve/cmd-capability.c b/src/managesieve/cmd-capability.c index b4d94ca9fab83e33d12a97136e99c95255da9f65..98e3566039b3ff8ee80501ea78b5df9153956a7e 100644 --- a/src/managesieve/cmd-capability.c +++ b/src/managesieve/cmd-capability.c @@ -30,19 +30,19 @@ bool cmd_capability(struct client_command_context *cmd) max_redirects = sieve_max_redirects(client->svinst); /* Default capabilities */ - client_send_line(client, t_strconcat("\"IMPLEMENTATION\" \"", + client_send_line(client, t_strconcat("\"IMPLEMENTATION\" \"", client->set->managesieve_implementation_string, "\"", NULL)); - client_send_line(client, t_strconcat("\"SIEVE\" \"", + client_send_line(client, t_strconcat("\"SIEVE\" \"", ( sievecap == NULL ? "" : sievecap ), "\"", NULL)); /* Maximum number of redirects (if limited) */ if ( max_redirects > 0 ) - client_send_line(client, + client_send_line(client, t_strdup_printf("\"MAXREDIRECTS\" \"%u\"", max_redirects)); /* Notify methods */ if ( notifycap != NULL ) { - client_send_line(client, t_strconcat("\"NOTIFY\" \"", + client_send_line(client, t_strconcat("\"NOTIFY\" \"", notifycap, "\"", NULL)); } diff --git a/src/managesieve/cmd-deletescript.c b/src/managesieve/cmd-deletescript.c index 3a80e2f1f4937f1a7bf9046dd773e569e4b796e9..e5f30ac56576f3994ba84db2b59cc72224f59476 100644 --- a/src/managesieve/cmd-deletescript.c +++ b/src/managesieve/cmd-deletescript.c @@ -33,7 +33,7 @@ bool cmd_deletescript(struct client_command_context *cmd) client_send_ok(client, "Deletescript completed."); } - /* Script object is deleted no matter what in + /* Script object is deleted no matter what in * sieve_script_delete() */ diff --git a/src/managesieve/cmd-getscript.c b/src/managesieve/cmd-getscript.c index 59e24230a344347561910272856906919d4a2f6f..d5aae5c8e6e2551081fd944d749c4bbb6a06b9e2 100644 --- a/src/managesieve/cmd-getscript.c +++ b/src/managesieve/cmd-getscript.c @@ -13,7 +13,7 @@ struct cmd_getscript_context { struct client *client; struct client_command_context *cmd; - struct sieve_storage *storage; + struct sieve_storage *storage; uoff_t script_size, script_offset; struct sieve_script *script; @@ -54,7 +54,7 @@ static bool cmd_getscript_continue(struct client_command_context *cmd) if ( ret < 0 ) { sieve_storage_set_critical(ctx->storage, - "o_stream_send_istream() failed for script `%s' from %s: %m", + "o_stream_send_istream() failed for script `%s' from %s: %m", sieve_script_name(ctx->script), sieve_script_location(ctx->script)); ctx->failed = TRUE; return cmd_getscript_finish(ctx); @@ -104,7 +104,7 @@ bool cmd_getscript(struct client_command_context *cmd) ctx->failed = TRUE; return cmd_getscript_finish(ctx); } - + ctx->script_stream = sieve_script_open(ctx->script, &error); if ( ctx->script_stream == NULL ) { @@ -122,7 +122,7 @@ bool cmd_getscript(struct client_command_context *cmd) return cmd_getscript_finish(ctx); } - ctx->script_offset = 0; + ctx->script_offset = 0; client_send_line (client, t_strdup_printf("{%"PRIuUOFF_T"}", ctx->script_size)); diff --git a/src/managesieve/cmd-listscripts.c b/src/managesieve/cmd-listscripts.c index 5f87a97c9030aa8477f49adaf62bd03973e8ffea..4917c4251ccee61b12d151797b3bf8b20115db52 100644 --- a/src/managesieve/cmd-listscripts.c +++ b/src/managesieve/cmd-listscripts.c @@ -37,21 +37,21 @@ bool cmd_listscripts(struct client_command_context *cmd) while ((scriptname = sieve_storage_list_next(ctx, &active)) != NULL) { T_BEGIN { str = t_str_new(128); - + managesieve_quote_append_string(str, scriptname, FALSE); - - if ( active ) + + if ( active ) str_append(str, " ACTIVE"); - + client_send_line(client, str_c(str)); } T_END; } - + if ( sieve_storage_list_deinit(&ctx) < 0 ) { client_send_storage_error(client, client->storage); return TRUE; } - + client_send_ok(client, "Listscripts completed."); return TRUE; } diff --git a/src/managesieve/cmd-putscript.c b/src/managesieve/cmd-putscript.c index 4218eda322aea63dc1958f58f6b17f00e329200b..ef0b62b82418be25bb8ce66131e788ee96364b00 100644 --- a/src/managesieve/cmd-putscript.c +++ b/src/managesieve/cmd-putscript.c @@ -98,7 +98,7 @@ static void client_input_putscript(void *context) static void cmd_putscript_finish(struct cmd_putscript_context *ctx) { managesieve_parser_destroy(&ctx->save_parser); - + io_remove(&ctx->client->io); o_stream_set_flush_callback(ctx->client->output, client_output, ctx->client); @@ -150,10 +150,10 @@ static bool cmd_putscript_finish_parsing(struct client_command_context *cmd) struct cmd_putscript_context *ctx = cmd->context; const struct managesieve_arg *args; int ret; - + /* if error occurs, the CRLF is already read. */ client->input_skip_line = FALSE; - + /* <script literal> */ ret = managesieve_parser_read_args(ctx->save_parser, 0, 0, &args); if (ret == -1 || client->output->closed) { @@ -189,7 +189,7 @@ static bool cmd_putscript_finish_parsing(struct client_command_context *cmd) /* Check quota; max size is already checked */ if ( ctx->scriptname != NULL && !managesieve_quota_check_all (client, ctx->scriptname, ctx->script_size) ) { - cmd_putscript_finish(ctx); + cmd_putscript_finish(ctx); return TRUE; } } @@ -197,7 +197,7 @@ static bool cmd_putscript_finish_parsing(struct client_command_context *cmd) /* Try to compile script */ T_BEGIN { struct sieve_error_handler *ehandler; - enum sieve_compile_flags cpflags = + enum sieve_compile_flags cpflags = SIEVE_COMPILE_FLAG_NOGLOBAL | SIEVE_COMPILE_FLAG_UPLOADED; struct sieve_binary *sbin; string_t *errors; @@ -209,7 +209,7 @@ static bool cmd_putscript_finish_parsing(struct client_command_context *cmd) /* Prepare error handler */ errors = str_new(default_pool, 1024); - ehandler = sieve_strbuf_ehandler_create(client->svinst, errors, TRUE, + ehandler = sieve_strbuf_ehandler_create(client->svinst, errors, TRUE, client->set->managesieve_max_compile_errors); /* Compile */ @@ -221,15 +221,15 @@ static bool cmd_putscript_finish_parsing(struct client_command_context *cmd) sieve_close(&sbin); /* Commit to save only when this is a putscript command */ - if ( ctx->scriptname != NULL ) { + if ( ctx->scriptname != NULL ) { ret = sieve_storage_save_commit(&ctx->save_ctx); - /* Check commit */ + /* Check commit */ if (ret < 0) { client_send_storage_error(client, ctx->storage); success = FALSE; } - } + } } /* Finish up */ @@ -237,13 +237,13 @@ static bool cmd_putscript_finish_parsing(struct client_command_context *cmd) /* Report result to user */ if ( success ) { - if ( sieve_get_warnings(ehandler) > 0 ) + if ( sieve_get_warnings(ehandler) > 0 ) client_send_okresp(client, "WARNINGS", str_c(errors)); else { if ( ctx->scriptname != NULL ) client_send_ok(client, "PUTSCRIPT completed."); else - client_send_ok(client, "Script checked successfully."); + client_send_ok(client, "Script checked successfully."); } } @@ -292,12 +292,12 @@ static bool cmd_putscript_continue_parsing(struct client_command_context *cmd) if ( i_stream_get_size(ctx->input, FALSE, &ctx->script_size) > 0 ) { if ( ctx->script_size == 0 ) { /* no script content, abort */ - if ( ctx->scriptname != NULL ) + if ( ctx->scriptname != NULL ) client_send_no(client, "PUTSCRIPT aborted (empty script)."); else client_send_no(client, "CHECKSCRIPT aborted (empty script)."); - cmd_putscript_finish(ctx); + cmd_putscript_finish(ctx); return TRUE; /* Check quota */ @@ -309,9 +309,9 @@ static bool cmd_putscript_continue_parsing(struct client_command_context *cmd) (client, ctx->scriptname, ctx->script_size) ) return cmd_putscript_cancel(ctx, TRUE); } - + } else { - ctx->max_script_size = managesieve_quota_max_script_size(client); + ctx->max_script_size = managesieve_quota_max_script_size(client); } /* save the script */ @@ -348,7 +348,7 @@ static bool cmd_putscript_continue_script(struct client_command_context *cmd) return TRUE; } - ret = i_stream_read(ctx->input); + ret = i_stream_read(ctx->input); if (sieve_storage_save_continue(ctx->save_ctx) < 0) { /* we still have to finish reading the script from client */ @@ -381,7 +381,7 @@ static bool cmd_putscript_continue_script(struct client_command_context *cmd) client->input_skip_line = TRUE; failed = TRUE; } - } + } all_written = ( ctx->input->eof && ctx->input->stream_errno == 0 ); } else { diff --git a/src/managesieve/cmd-renamescript.c b/src/managesieve/cmd-renamescript.c index eeec61aa26a4cafc0b78a682602873d03940eb21..7292505e0d7f699b462797ff5aaef883ee57fe11 100644 --- a/src/managesieve/cmd-renamescript.c +++ b/src/managesieve/cmd-renamescript.c @@ -30,7 +30,7 @@ bool cmd_renamescript(struct client_command_context *cmd) if (sieve_storage_script_rename(script, newname) < 0) client_send_storage_error(client, storage); - else + else client_send_ok(client, "Renamescript completed."); return TRUE; diff --git a/src/managesieve/cmd-setactive.c b/src/managesieve/cmd-setactive.c index c46a0566c86071ab55e38fb4f91e30215fbe9d4a..1f24c1d6a4e6e0c70a3815ee4a8050cdcd2d897b 100644 --- a/src/managesieve/cmd-setactive.c +++ b/src/managesieve/cmd-setactive.c @@ -41,13 +41,13 @@ bool cmd_setactive(struct client_command_context *cmd) */ T_BEGIN { struct sieve_error_handler *ehandler; - enum sieve_compile_flags cpflags = + enum sieve_compile_flags cpflags = SIEVE_COMPILE_FLAG_NOGLOBAL | SIEVE_COMPILE_FLAG_ACTIVATED; struct sieve_binary *sbin; /* Prepare error handler */ errors = str_new(default_pool, 1024); - ehandler = sieve_strbuf_ehandler_create(client->svinst, errors, TRUE, + ehandler = sieve_strbuf_ehandler_create(client->svinst, errors, TRUE, client->set->managesieve_max_compile_errors); /* Compile */ @@ -62,7 +62,7 @@ bool cmd_setactive(struct client_command_context *cmd) sieve_error_handler_unref(&ehandler); } T_END; } - + /* Activate only when script is valid (or already active) */ if ( success ) { /* Refresh activation no matter what; this can also resolve some erroneous @@ -75,7 +75,7 @@ bool cmd_setactive(struct client_command_context *cmd) if ( warnings ) { client_send_okresp(client, "WARNINGS", str_c(errors)); } else { - client_send_ok(client, ( ret > 0 ? + client_send_ok(client, ( ret > 0 ? "Setactive completed." : "Script is already active." )); } @@ -91,13 +91,13 @@ bool cmd_setactive(struct client_command_context *cmd) /* ... deactivate */ } else { ret = sieve_storage_deactivate(storage); - + if ( ret < 0 ) client_send_storage_error(client, storage); else client_send_ok(client, ( ret > 0 ? "Active script is now deactivated." : - "No scripts currently active." )); + "No scripts currently active." )); } return TRUE; diff --git a/src/managesieve/managesieve-capabilities.c b/src/managesieve/managesieve-capabilities.c index e2f573da0e34939a2a19e34c2caa99aec596c2d3..fcc7ce016cb13aa0168c19fdfa15fea8a81ed7a5 100644 --- a/src/managesieve/managesieve-capabilities.c +++ b/src/managesieve/managesieve-capabilities.c @@ -52,7 +52,7 @@ static const struct setting_parser_info *default_plugin_set_roots[] = { NULL }; -static const struct setting_parser_info **plugin_set_roots = +static const struct setting_parser_info **plugin_set_roots = default_plugin_set_roots; static struct plugin_settings *plugin_settings_read(void) @@ -111,7 +111,7 @@ void managesieve_capabilities_dump(void) struct sieve_environment svenv; struct sieve_instance *svinst; const char *notify_cap; - + /* Read plugin settings */ global_plugin_settings = plugin_settings_read(); @@ -128,7 +128,7 @@ void managesieve_capabilities_dump(void) notify_cap = sieve_get_capabilities(svinst, "notify"); - if ( notify_cap == NULL ) + if ( notify_cap == NULL ) printf("SIEVE: %s\n", sieve_get_capabilities(svinst, NULL)); else printf("SIEVE: %s, NOTIFY: %s\n", sieve_get_capabilities(svinst, NULL), diff --git a/src/managesieve/managesieve-client.c b/src/managesieve/managesieve-client.c index a1a4342689759f819a374a4ebe79708cde3824e9..5c16b84bd60e053de4e869dd82e46cf2090c5ebf 100644 --- a/src/managesieve/managesieve-client.c +++ b/src/managesieve/managesieve-client.c @@ -58,7 +58,7 @@ static void client_idle_timeout(struct client *client) } static struct sieve_storage *client_get_storage -(struct sieve_instance *svinst, struct mail_user *user, +(struct sieve_instance *svinst, struct mail_user *user, const struct managesieve_settings *set) { struct sieve_storage *storage; @@ -116,7 +116,7 @@ struct client *client_create /* Get Sieve storage */ - storage = client_get_storage(svinst, user, set); + storage = client_get_storage(svinst, user, set); /* always use nonblocking I/O */ net_set_nonblock(fd_in, TRUE); @@ -149,7 +149,7 @@ struct client *client_create client->user = user; client->svinst = svinst; - client->storage = storage; + client->storage = storage; ident = mail_user_get_anvil_userip_ident(client->user); if (ident != NULL) { @@ -168,7 +168,7 @@ struct client *client_create } static const char *client_stats(struct client *client) -{ +{ static struct var_expand_table static_tab[] = { { 'i', NULL, "input" }, { 'o', NULL, "output" }, @@ -211,7 +211,7 @@ void client_destroy(struct client *client, const char *reason) client->disconnected = TRUE; if (reason == NULL) reason = client_get_disconnect_reason(client); - i_info("%s %s", reason, client_stats(client)); + i_info("%s %s", reason, client_stats(client)); } managesieve_client_count--; @@ -286,7 +286,7 @@ void client_disconnect_with_error(struct client *client, const char *msg) client_disconnect(client, msg); } -int client_send_line(struct client *client, const char *data) +int client_send_line(struct client *client, const char *data) { struct const_iovec iov[2]; @@ -314,7 +314,7 @@ void client_send_response (struct client *client, const char *oknobye, const char *resp_code, const char *msg) { string_t *str; - + str = t_str_new(128); str_append(str, oknobye); @@ -412,7 +412,7 @@ bool client_read_args(struct client_command_context *cmd, unsigned int count, const struct managesieve_arg *dummy_args_r = NULL; int ret; - if ( args_r == NULL ) args_r = &dummy_args_r; + if ( args_r == NULL ) args_r = &dummy_args_r; i_assert(count <= INT_MAX); @@ -428,7 +428,7 @@ bool client_read_args(struct client_command_context *cmd, unsigned int count, return FALSE; } } - + /* all parameters read successfully */ return TRUE; } else if (ret == -2) { diff --git a/src/managesieve/managesieve-client.h b/src/managesieve/managesieve-client.h index c5b24c0681f15175cc2aba8940c05cff4cb834a0..d569a028d97653e47a667a7cfbdf2d0aa3528413 100644 --- a/src/managesieve/managesieve-client.h +++ b/src/managesieve/managesieve-client.h @@ -74,7 +74,7 @@ extern unsigned int managesieve_client_count; /* Create new client with specified input/output handles. socket specifies if the handle is a socket. */ struct client *client_create - (int fd_in, int fd_out, const char *session_id, struct mail_user *user, + (int fd_in, int fd_out, const char *session_id, struct mail_user *user, struct mail_storage_service_user *service_user, const struct managesieve_settings *set); void client_destroy(struct client *client, const char *reason); diff --git a/src/managesieve/managesieve-commands.c b/src/managesieve/managesieve-commands.c index d836491b342ff40fc1498ac409e23eb105487568..04dd984e0b1cb5c5dd7387e9f1b18ced242d309e 100644 --- a/src/managesieve/managesieve-commands.c +++ b/src/managesieve/managesieve-commands.c @@ -9,8 +9,8 @@ #include <stdlib.h> -/* Might want to combine this somewhere in a commands-common.c - * to avoid duplicate code +/* Might want to combine this somewhere in a commands-common.c + * to avoid duplicate code */ static const struct command managesieve_base_commands[] = { @@ -27,7 +27,7 @@ static const struct command managesieve_base_commands[] = { { "NOOP", cmd_noop } }; -#define MANAGESIEVE_COMMANDS_COUNT N_ELEMENTS(managesieve_base_commands) +#define MANAGESIEVE_COMMANDS_COUNT N_ELEMENTS(managesieve_base_commands) static ARRAY_DEFINE(managesieve_commands, struct command); static bool commands_unsorted; @@ -98,7 +98,7 @@ void commands_init(void) { i_array_init(&managesieve_commands, 16); commands_unsorted = FALSE; - + command_register_array(managesieve_base_commands, MANAGESIEVE_COMMANDS_COUNT); } diff --git a/src/managesieve/managesieve-quota.c b/src/managesieve/managesieve-quota.c index 8301d63d88fd0f477f56977e9933156dd7e969ce..c36956ed31b63391f4d82d3af278fbe22a2991ea 100644 --- a/src/managesieve/managesieve-quota.c +++ b/src/managesieve/managesieve-quota.c @@ -16,21 +16,21 @@ uint64_t managesieve_quota_max_script_size(struct client *client) } bool managesieve_quota_check_validsize(struct client *client, size_t size) -{ +{ uint64_t limit; if ( !sieve_storage_quota_validsize (client->storage, size, &limit) ) { - client_send_noresp(client, "QUOTA/MAXSIZE", - t_strdup_printf("Script is too large (max %llu bytes).", + client_send_noresp(client, "QUOTA/MAXSIZE", + t_strdup_printf("Script is too large (max %llu bytes).", (unsigned long long int) limit)); - + return FALSE; } return TRUE; } - + bool managesieve_quota_check_all (struct client *client, const char *scriptname, size_t size) { @@ -44,19 +44,19 @@ bool managesieve_quota_check_all switch ( quota ) { case SIEVE_STORAGE_QUOTA_MAXSIZE: client_send_noresp(client, "QUOTA/MAXSIZE", t_strdup_printf( - "Script is too large (max %llu bytes).", + "Script is too large (max %llu bytes).", (unsigned long long int) limit)); break; case SIEVE_STORAGE_QUOTA_MAXSCRIPTS: client_send_noresp(client, "QUOTA/MAXSCRIPTS", t_strdup_printf( - "Script count quota exceeded (max %llu scripts).", + "Script count quota exceeded (max %llu scripts).", (unsigned long long int) limit)); break; case SIEVE_STORAGE_QUOTA_MAXSTORAGE: client_send_noresp(client, "QUOTA/MAXSTORAGE", t_strdup_printf( - "Script storage quota exceeded (max %llu bytes).", + "Script storage quota exceeded (max %llu bytes).", (unsigned long long int) limit)); break; diff --git a/src/managesieve/managesieve-settings.c b/src/managesieve/managesieve-settings.c index a706d8ce1cb246acf97901d85030d180a9728dc8..fae10e66f682759b105e5da775bf0ba17f6e86ba 100644 --- a/src/managesieve/managesieve-settings.c +++ b/src/managesieve/managesieve-settings.c @@ -122,7 +122,7 @@ struct managesieve_client_workaround_list { enum managesieve_client_workarounds num; }; -static const struct managesieve_client_workaround_list +static const struct managesieve_client_workaround_list managesieve_client_workaround_list[] = { { NULL, 0 } }; diff --git a/src/plugins/lda-sieve/Makefile.am b/src/plugins/lda-sieve/Makefile.am index b89ed4b437d150758f112f0a22e40d7429d53567..191141608445947daa2e896d527be5dde813179f 100644 --- a/src/plugins/lda-sieve/Makefile.am +++ b/src/plugins/lda-sieve/Makefile.am @@ -12,7 +12,7 @@ lib90_sieve_plugin_la_LIBADD = \ $(top_builddir)/src/lib-sieve/libdovecot-sieve.la lib90_sieve_plugin_la_SOURCES = \ - lda-sieve-plugin.c + lda-sieve-plugin.c noinst_HEADERS = \ lda-sieve-plugin.h diff --git a/src/plugins/lda-sieve/lda-sieve-plugin.c b/src/plugins/lda-sieve/lda-sieve-plugin.c index 6280938f34d994420eab2e76bc56c67a0af8bdfb..128e125d94fa591e8d9a71b07260fe0ad16f9441 100644 --- a/src/plugins/lda-sieve/lda-sieve-plugin.c +++ b/src/plugins/lda-sieve/lda-sieve-plugin.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file +/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ #include "lib.h" @@ -32,7 +32,7 @@ #define LDA_SIEVE_MAX_USER_ERRORS 30 /* - * Global variables + * Global variables */ static deliver_mail_func_t *next_deliver_mail; @@ -91,7 +91,7 @@ static int lda_sieve_reject_mail { struct mail_deliver_context *dctx = (struct mail_deliver_context *) senv->script_context; - + return mail_send_rejection(dctx, recipient, reason); } @@ -205,7 +205,7 @@ static int lda_sieve_multiscript_get_scripts break; } - if ( i == count ) + if ( i == count ) array_append(&script_files, &file, 1); else array_insert(&script_files, i, &file, 1); @@ -225,7 +225,7 @@ static int lda_sieve_multiscript_get_scripts sieve_sys_warning (svinst, "%s script %s doesn't exist", label, files[i]); break; - + default: sieve_sys_error (svinst, "failed to access %s script %s", label, files[i]); @@ -242,7 +242,7 @@ static int lda_sieve_multiscript_get_scripts } static void lda_sieve_binary_save -(struct lda_sieve_run_context *srctx, struct sieve_binary *sbin, +(struct lda_sieve_run_context *srctx, struct sieve_binary *sbin, struct sieve_script *script) { enum sieve_error error; @@ -286,7 +286,7 @@ static struct sieve_binary *lda_sieve_open sieve_sys_debug(svinst, "script file %s is missing", sieve_script_location(script)); } - } else if ( *error_r == SIEVE_ERROR_NOT_VALID && + } else if ( *error_r == SIEVE_ERROR_NOT_VALID && script == srctx->user_script && srctx->userlog != NULL ) { sieve_sys_error(svinst, "failed to open script %s " "(view user logfile %s for more information)", @@ -330,9 +330,9 @@ static struct sieve_binary *lda_sieve_recompile if ( *error_r == SIEVE_ERROR_NOT_FOUND ) { if ( debug ) - sieve_sys_debug(svinst, "script file %s is missing for re-compile", + sieve_sys_debug(svinst, "script file %s is missing for re-compile", sieve_script_location(script)); - } else if ( *error_r == SIEVE_ERROR_NOT_VALID && + } else if ( *error_r == SIEVE_ERROR_NOT_VALID && script == srctx->user_script && srctx->userlog != NULL ) { sieve_sys_error(svinst, "failed to re-compile script %s " @@ -364,20 +364,20 @@ static int lda_sieve_handle_exec_status switch ( status ) { case SIEVE_EXEC_FAILURE: sieve_sys_error(svinst, - "execution of script %s failed, but implicit keep was successful%s", + "execution of script %s failed, but implicit keep was successful%s", sieve_script_location(script), userlog_notice); ret = 1; break; case SIEVE_EXEC_BIN_CORRUPT: sieve_sys_error(svinst, "!!BUG!!: binary compiled from %s is still corrupt; " - "bailing out and reverting to default delivery", + "bailing out and reverting to default delivery", sieve_script_location(script)); ret = -1; break; case SIEVE_EXEC_KEEP_FAILED: sieve_sys_error(svinst, - "script %s failed with unsuccessful implicit keep%s", + "script %s failed with unsuccessful implicit keep%s", sieve_script_location(script), userlog_notice); ret = -1; break; @@ -469,7 +469,7 @@ static int lda_sieve_multiscript_execute struct sieve_script *last_script = NULL; bool user_script = FALSE; unsigned int i; - int ret = 1; + int ret = 1; bool more = TRUE; enum sieve_error error; @@ -530,7 +530,7 @@ static int lda_sieve_multiscript_execute /* Save new version */ - if ( more && + if ( more && sieve_multiscript_status(mscript) != SIEVE_EXEC_BIN_CORRUPT ) { lda_sieve_binary_save(srctx, sbin, script); } @@ -588,7 +588,7 @@ static int lda_sieve_deliver_mail /* Find scripts and run them */ - T_BEGIN { + T_BEGIN { struct sieve_script *const *scripts; unsigned int count, i; @@ -663,13 +663,13 @@ static int lda_sieve_deliver_mail sieve_before = mail_user_plugin_getenv(mdctx->dest_user, setting_name); } - if ( debug ) { + if ( debug ) { scripts = array_get(&script_sequence, &count); for ( i = 0; i < count; i ++ ) { sieve_sys_debug(svinst, "executed before user's personal Sieve script(%d): %s", i+1, sieve_script_location(scripts[i])); - } + } } if ( srctx.main_script != NULL ) { @@ -696,13 +696,13 @@ static int lda_sieve_deliver_mail setting_name = t_strdup_printf("sieve_after%u", i++); sieve_after = mail_user_plugin_getenv(mdctx->dest_user, setting_name); } - + if ( debug ) { scripts = array_get(&script_sequence, &count); for ( i = after_index; i < count; i ++ ) { sieve_sys_debug(svinst, "executed after user's Sieve script(%d): %s", i+1, sieve_script_location(scripts[i])); - } + } } srctx.scripts = @@ -720,9 +720,9 @@ static int lda_sieve_deliver_mail * for a deliver plugin is is considered a failure. In deliver itself, * saved_mail and tried_default_save remain unset, meaning that deliver * will then attempt the default delivery. We return 0 to signify the lack - * of a real error. + * of a real error. */ - ret = 0; + ret = 0; } else { /* Initialize user error handler */ @@ -742,8 +742,8 @@ static int lda_sieve_deliver_mail } } else { /* Use script file as a basic (legacy behavior) */ - log_path = t_strconcat(path, ".log", NULL); - } + log_path = t_strconcat(path, ".log", NULL); + } } else if ( svenv.home_dir != NULL ) { /* Expand home dir if necessary */ if ( log_path[0] == '~' ) { @@ -815,13 +815,13 @@ static int lda_sieve_deliver_mail /* Cleanup scripts */ for ( i = 0; i < srctx.script_count; i++ ) { sieve_script_unref(&srctx.scripts[i]); - } + } } T_END; sieve_deinit(&svinst); sieve_error_handler_unref(&master_ehandler); - return ret; + return ret; } /* diff --git a/src/sieve-tools/Makefile.am b/src/sieve-tools/Makefile.am index 33b1bad26a2790622c6f6442cad72144527cbc48..33bfbf57f924d4cdc932ad814f579e439dadaeca 100644 --- a/src/sieve-tools/Makefile.am +++ b/src/sieve-tools/Makefile.am @@ -9,7 +9,7 @@ AM_CPPFLAGS = \ libs = \ $(top_builddir)/src/lib-sieve/libdovecot-sieve.la \ - $(top_builddir)/src/lib-sieve-tool/libsieve-tool.la + $(top_builddir)/src/lib-sieve-tool/libsieve-tool.la libs_ldadd = $(libs) $(LIBDOVECOT_STORAGE) $(LIBDOVECOT_LDA) $(LIBDOVECOT) libs_deps = $(libs) $(LIBDOVECOT_STORAGE_DEPS) $(LIBDOVECOT_LDA_DEPS) $(LIBDOVECOT_DEPS) @@ -21,7 +21,7 @@ sievec_LDADD = $(libs_ldadd) sievec_DEPENDENCIES = $(libs_deps) sievec_SOURCES = \ - sievec.c + sievec.c # Sieve Dump Tool @@ -30,7 +30,7 @@ sieve_dump_LDADD = $(libs_ldadd) sieve_dump_DEPENDENCIES = $(libs_deps) sieve_dump_SOURCES = \ - sieve-dump.c + sieve-dump.c # Sieve Test Tool @@ -39,7 +39,7 @@ sieve_test_LDADD = $(libs_ldadd) sieve_test_DEPENDENCIES = $(libs_deps) sieve_test_SOURCES = \ - sieve-test.c + sieve-test.c ## Unfinished tools @@ -50,6 +50,6 @@ sieve_filter_LDADD = $(libs_ldadd) sieve_filter_DEPENDENCIES = $(libs_deps) sieve_filter_SOURCES = \ - sieve-filter.c + sieve-filter.c noinst_HEADERS = diff --git a/src/sieve-tools/sieve-dump.c b/src/sieve-tools/sieve-dump.c index 2d6e8c24224e57599328f5ef941670874ec17946..cb7d399713cbdb4c72a2a12d10aea1ddbd3fb92f 100644 --- a/src/sieve-tools/sieve-dump.c +++ b/src/sieve-tools/sieve-dump.c @@ -37,7 +37,7 @@ static void print_help(void) * Tool implementation */ -int main(int argc, char **argv) +int main(int argc, char **argv) { struct sieve_instance *svinst; struct sieve_binary *sbin; @@ -47,7 +47,7 @@ int main(int argc, char **argv) int c; sieve_tool = sieve_tool_init("sieve-dump", &argc, &argv, "hP:x:", FALSE); - + outfile = NULL; while ((c = sieve_tool_getopt(sieve_tool)) > 0) { @@ -65,15 +65,15 @@ int main(int argc, char **argv) if ( optind < argc ) { binfile = argv[optind++]; - } else { + } else { print_help(); i_fatal_status(EX_USAGE, "Missing <script-file> argument"); } if ( optind < argc ) { outfile = argv[optind++]; - } - + } + /* Finish tool initialization */ svinst = sieve_tool_init_finish(sieve_tool, FALSE); @@ -84,7 +84,7 @@ int main(int argc, char **argv) sbin = sieve_load(svinst, binfile, NULL); if ( sbin != NULL ) { sieve_tool_dump_binary_to(sbin, outfile == NULL ? "-" : outfile, hexdump); - + sieve_close(&sbin); } else { i_error("failed to load binary: %s", binfile); diff --git a/src/sieve-tools/sieve-filter.c b/src/sieve-tools/sieve-filter.c index 16a07334ad98fa01001e03d7c0d5e2b053614a18..1381266b263e1332c1d2d52264410975edf910ac 100644 --- a/src/sieve-tools/sieve-filter.c +++ b/src/sieve-tools/sieve-filter.c @@ -42,8 +42,8 @@ static void print_help(void) } enum sieve_filter_discard_action { - SIEVE_FILTER_DACT_KEEP, /* Keep discarded messages in source folder */ - SIEVE_FILTER_DACT_MOVE, /* Move discarded messages to Trash folder */ + SIEVE_FILTER_DACT_KEEP, /* Keep discarded messages in source folder */ + SIEVE_FILTER_DACT_MOVE, /* Move discarded messages to Trash folder */ SIEVE_FILTER_DACT_DELETE, /* Flag discarded messages as \DELETED */ SIEVE_FILTER_DACT_EXPUNGE /* Expunge discarded messages */ }; @@ -71,7 +71,7 @@ struct sieve_filter_context { static int filter_message (struct sieve_filter_context *sfctx, struct mail *mail) { - struct sieve_error_handler *ehandler = sfctx->data->ehandler; + struct sieve_error_handler *ehandler = sfctx->data->ehandler; struct sieve_script_env *senv = sfctx->data->senv; struct sieve_exec_status estatus; struct sieve_binary *sbin; @@ -97,20 +97,20 @@ static int filter_message msgdata.final_envelope_to = recipient; msgdata.auth_user = senv->user->username; (void)mail_get_first_header(mail, "Message-ID", &msgdata.id); - + if ( mail_get_virtual_size(mail, &size) < 0 ) { if ( mail->expunged ) return 1; - + sieve_error(ehandler, NULL, "failed to obtain message size; " - "skipping this message (id=%s)", + "skipping this message (id=%s)", ( msgdata.id == NULL ? "none" : msgdata.id )); return 0; } if ( mail_get_first_header(mail, "date", &date) <= 0 ) date = ""; - if ( mail_get_first_header(mail, "subject", &subject) <= 0 ) + if ( mail_get_first_header(mail, "subject", &subject) <= 0 ) subject = ""; /* Single script */ @@ -164,21 +164,21 @@ static int filter_message sieve_info(ehandler, NULL, "message left in source mailbox"); break; /* Move message to indicated folder */ - case SIEVE_FILTER_DACT_MOVE: - sieve_info(ehandler, NULL, + case SIEVE_FILTER_DACT_MOVE: + sieve_info(ehandler, NULL, "message in source mailbox moved to mailbox '%s'", mailbox_get_name(move_box)); if ( execute && move_box != NULL ) { struct mailbox_transaction_context *t = sfctx->move_trans; struct mail_save_context *save_ctx; - + save_ctx = mailbox_save_alloc(t); if ( mailbox_copy(&save_ctx, mail) < 0 ) { enum mail_error error; const char *errstr; - + errstr = mail_storage_get_last_error (mailbox_get_storage(move_box), &error); @@ -187,12 +187,12 @@ static int filter_message mailbox_get_name(move_box), errstr); return -1; } - + mail_expunge(mail); } break; /* Flag message as \DELETED */ - case SIEVE_FILTER_DACT_DELETE: + case SIEVE_FILTER_DACT_DELETE: sieve_info(ehandler, NULL, "message flagged as deleted in source mailbox"); if ( execute ) mail_update_flags(mail, MODIFY_ADD, MAIL_DELETED); @@ -216,7 +216,7 @@ static int filter_message break; case SIEVE_EXEC_BIN_CORRUPT: sieve_error(ehandler, NULL, "sieve script binary is corrupt"); - return -1; + return -1; case SIEVE_EXEC_FAILURE: case SIEVE_EXEC_KEEP_FAILED: sieve_error(ehandler, NULL, @@ -225,7 +225,7 @@ static int filter_message return 0; default: sieve_error(ehandler, NULL, - "sieve execution result: unrecognized return value?!"); + "sieve execution result: unrecognized return value?!"); return -1; } @@ -296,7 +296,7 @@ static int filter_mailbox while ( ret >= 0 && mailbox_search_next(search_ctx, &mail) > 0 ) { ret = filter_message(&sfctx, mail); } - + /* Cleanup */ if ( mailbox_search_deinit(&search_ctx) < 0 ) { @@ -326,7 +326,7 @@ static int filter_mailbox return -1; } } - + return ret; } @@ -344,7 +344,7 @@ static const char *mailbox_name_to_mutf7(const char *mailbox_utf8) * Tool implementation */ -int main(int argc, char **argv) +int main(int argc, char **argv) { struct sieve_instance *svinst; ARRAY_TYPE (const_string) scriptfiles; @@ -362,7 +362,7 @@ int main(int argc, char **argv) enum mail_error error; int c; - sieve_tool = sieve_tool_init("sieve-filter", &argc, &argv, + sieve_tool = sieve_tool_init("sieve-filter", &argc, &argv, "m:s:x:P:u:q:Q:DCevW", FALSE); t_array_init(&scriptfiles, 16); @@ -376,25 +376,25 @@ int main(int argc, char **argv) /* default mailbox (keep box) */ dst_mailbox = optarg; break; - case 's': + case 's': /* scriptfile executed before main script */ { - const char *file; + const char *file; file = t_strdup(optarg); array_append(&scriptfiles, &file, 1); /* FIXME: */ - i_fatal_status(EX_USAGE, + i_fatal_status(EX_USAGE, "The -s argument is currently NOT IMPLEMENTED"); } break; - case 'q': - i_fatal_status(EX_USAGE, + case 'q': + i_fatal_status(EX_USAGE, "The -q argument is currently NOT IMPLEMENTED"); break; - case 'Q': - i_fatal_status(EX_USAGE, + case 'Q': + i_fatal_status(EX_USAGE, "The -Q argument is currently NOT IMPLEMENTED"); break; case 'e': @@ -421,7 +421,7 @@ int main(int argc, char **argv) } } - /* Script file argument */ + /* Script file argument */ if ( optind < argc ) { scriptfile = t_strdup(argv[optind++]); } else { @@ -436,7 +436,7 @@ int main(int argc, char **argv) print_help(); i_fatal_status(EX_USAGE, "Missing <source-mailbox> argument"); } - + /* Source action argument */ if ( optind < argc ) { const char *srcact = argv[optind++]; @@ -461,7 +461,7 @@ int main(int argc, char **argv) print_help(); i_fatal_status(EX_USAGE, "Invalid <discard-action> argument"); } - } + } if ( optind != argc ) { print_help(); @@ -495,22 +495,22 @@ int main(int argc, char **argv) /* Initialize mail user */ mail_user = sieve_tool_get_mail_user(sieve_tool); - /* Open the source mailbox */ + /* Open the source mailbox */ src_mailbox = mailbox_name_to_mutf7(src_mailbox); ns = mail_namespace_find(mail_user->namespaces, src_mailbox); if ( ns == NULL ) i_fatal("Unknown namespace for source mailbox '%s'", src_mailbox); - if ( !source_write || !execute ) + if ( !source_write || !execute ) open_flags |= MAILBOX_FLAG_READONLY; - + src_box = mailbox_alloc(ns->list, src_mailbox, open_flags); if ( mailbox_open(src_box) < 0 ) { - i_fatal("Couldn't open source mailbox '%s': %s", + i_fatal("Couldn't open source mailbox '%s': %s", src_mailbox, mail_storage_get_last_error(ns->storage, &error)); } - + /* Open move box if necessary */ if ( execute && discard_action == SIEVE_FILTER_DACT_MOVE && @@ -522,7 +522,7 @@ int main(int argc, char **argv) move_box = mailbox_alloc(ns->list, move_mailbox, open_flags); if ( mailbox_open(move_box) < 0 ) { - i_fatal("Couldn't open mailbox '%s': %s", + i_fatal("Couldn't open mailbox '%s': %s", move_mailbox, mail_storage_get_last_error(ns->storage, &error)); } @@ -552,7 +552,7 @@ int main(int argc, char **argv) /* Apply Sieve filter to all messages found */ (void) filter_mailbox(&sfdata, src_box); - + /* Close the source mailbox */ if ( src_box != NULL ) mailbox_free(&src_box); diff --git a/src/sieve-tools/sieve-test.c b/src/sieve-tools/sieve-test.c index 3aa60721d26af51097a73e9b7b43603b7cb01b72..b32d1d80347675d4f445799ee9d0300680c7da81 100644 --- a/src/sieve-tools/sieve-test.c +++ b/src/sieve-tools/sieve-test.c @@ -28,7 +28,7 @@ #include <sysexits.h> -/* +/* * Configuration */ @@ -63,10 +63,10 @@ static void *sieve_smtp_open i_info("sending message from <%s> to <%s>:", ( return_path == NULL ? "" : return_path ), destination); printf("\nSTART MESSAGE:\n"); - + *file_r = stdout; - - return NULL; + + return NULL; } static bool sieve_smtp_close @@ -81,7 +81,7 @@ static bool sieve_smtp_close */ static int duplicate_check -(const struct sieve_script_env *senv, const void *id ATTR_UNUSED, +(const struct sieve_script_env *senv, const void *id ATTR_UNUSED, size_t id_size ATTR_UNUSED) { i_info("checked duplicate for user %s.\n", senv->user->username); @@ -89,7 +89,7 @@ static int duplicate_check } static void duplicate_mark -(const struct sieve_script_env *senv, const void *id ATTR_UNUSED, +(const struct sieve_script_env *senv, const void *id ATTR_UNUSED, size_t id_size ATTR_UNUSED, time_t time ATTR_UNUSED) { i_info("marked duplicate for user %s.\n", senv->user->username); @@ -99,7 +99,7 @@ static void duplicate_mark * Tool implementation */ -int main(int argc, char **argv) +int main(int argc, char **argv) { struct sieve_instance *svinst; ARRAY_TYPE (const_string) scriptfiles; @@ -162,10 +162,10 @@ int main(int argc, char **argv) /* dump file */ dumpfile = optarg; break; - case 's': + case 's': /* scriptfile executed before main script */ { - const char *file; + const char *file; file = t_strdup(optarg); array_append(&scriptfiles, &file, 1); @@ -189,18 +189,18 @@ int main(int argc, char **argv) if ( optind < argc ) { scriptfile = argv[optind++]; - } else { + } else { print_help(); i_fatal_status(EX_USAGE, "Missing <script-file> argument"); } - + if ( optind < argc ) { mailfile = argv[optind++]; - } else { + } else { print_help(); i_fatal_status(EX_USAGE, "Missing <mail-file> argument"); } - + if (optind != argc) { print_help(); i_fatal_status(EX_USAGE, "Unknown argument: %s", argv[optind]); @@ -263,7 +263,7 @@ int main(int argc, char **argv) if ( tracefile != NULL ) tracestream = sieve_tool_open_output_stream(tracefile); - + /* Compose script environment */ memset(&scriptenv, 0, sizeof(scriptenv)); scriptenv.default_mailbox = mailbox; @@ -276,21 +276,21 @@ int main(int argc, char **argv) scriptenv.trace_stream = tracestream; scriptenv.trace_config = tr_config; scriptenv.exec_status = &estatus; - + /* Run the test */ ret = 1; if ( array_count(&scriptfiles) == 0 ) { /* Single script */ sbin = main_sbin; main_sbin = NULL; - + /* Execute/Test script */ if ( execute ) ret = sieve_execute (sbin, &msgdata, &scriptenv, ehandler, 0, NULL); else ret = sieve_test - (sbin, &msgdata, &scriptenv, ehandler, teststream, 0, NULL); + (sbin, &msgdata, &scriptenv, ehandler, teststream, 0, NULL); } else { /* Multiple scripts */ const char *const *sfiles; @@ -305,18 +305,18 @@ int main(int argc, char **argv) else mscript = sieve_multiscript_start_test (svinst, &msgdata, &scriptenv, teststream); - + /* Execute scripts sequentially */ - sfiles = array_get(&scriptfiles, &count); + sfiles = array_get(&scriptfiles, &count); for ( i = 0; i < count && more; i++ ) { - if ( teststream != NULL ) - o_stream_send_str(teststream, + if ( teststream != NULL ) + o_stream_send_str(teststream, t_strdup_printf("\n## Executing script: %s\n", sfiles[i])); - + /* Close previous script */ - if ( sbin != NULL ) + if ( sbin != NULL ) sieve_close(&sbin); - + /* Compile sieve script */ if ( force_compile ) { sbin = sieve_tool_script_compile(svinst, sfiles[i], sfiles[i]); @@ -325,37 +325,37 @@ int main(int argc, char **argv) } else { sbin = sieve_tool_script_open(svinst, sfiles[i]); } - + if ( sbin == NULL ) { ret = SIEVE_EXEC_FAILURE; break; } - + /* Execute/Test script */ more = sieve_multiscript_run(mscript, sbin, ehandler, 0, FALSE); } - + /* Execute/Test main script */ if ( more && ret > 0 ) { - if ( teststream != NULL ) - o_stream_send_str(teststream, + if ( teststream != NULL ) + o_stream_send_str(teststream, t_strdup_printf("## Executing script: %s\n", scriptfile)); - + /* Close previous script */ - if ( sbin != NULL ) - sieve_close(&sbin); - + if ( sbin != NULL ) + sieve_close(&sbin); + sbin = main_sbin; main_sbin = NULL; - + sieve_multiscript_run(mscript, sbin, ehandler, 0, TRUE); } - + result = sieve_multiscript_finish(&mscript, ehandler, NULL); - + ret = ret > 0 ? result : ret; } - + /* Run */ switch ( ret ) { case SIEVE_EXEC_OK: @@ -373,7 +373,7 @@ int main(int argc, char **argv) exit_status = EXIT_FAILURE; break; default: - i_info("final result: unrecognized return value?!"); + i_info("final result: unrecognized return value?!"); exit_status = EXIT_FAILURE; break; } @@ -384,7 +384,7 @@ int main(int argc, char **argv) /* Cleanup remaining binaries */ if ( sbin != NULL ) sieve_close(&sbin); - if ( main_sbin != NULL ) + if ( main_sbin != NULL ) sieve_close(&main_sbin); } diff --git a/src/sieve-tools/sievec.c b/src/sieve-tools/sievec.c index 59bd756acbe848053fa6ad806cc1a8aaf86cef94..c9717525bf429684192006fa5e9842387803c7bc 100644 --- a/src/sieve-tools/sievec.c +++ b/src/sieve-tools/sievec.c @@ -36,11 +36,11 @@ static void print_help(void) ); } -/* +/* * Tool implementation */ -int main(int argc, char **argv) +int main(int argc, char **argv) { struct sieve_instance *svinst; struct stat st; @@ -68,7 +68,7 @@ int main(int argc, char **argv) if ( optind < argc ) { scriptfile = argv[optind++]; - } else { + } else { print_help(); i_fatal_status(EX_USAGE, "Missing <script-file> argument"); } @@ -88,34 +88,34 @@ int main(int argc, char **argv) /* Script directory */ DIR *dirp; struct dirent *dp; - + /* Sanity checks on some of the arguments */ - + if ( dump ) - i_fatal_status(EX_USAGE, - "the -d option is not allowed when scriptfile is a directory."); - + i_fatal_status(EX_USAGE, + "the -d option is not allowed when scriptfile is a directory."); + if ( outfile != NULL ) - i_fatal_status(EX_USAGE, - "the outfile argument is not allowed when scriptfile is a directory."); - + i_fatal_status(EX_USAGE, + "the outfile argument is not allowed when scriptfile is a directory."); + /* Open the directory */ if ( (dirp = opendir(scriptfile)) == NULL ) i_fatal("opendir(%s) failed: %m", scriptfile); - + /* Compile each sieve file */ for (;;) { - + errno = 0; if ( (dp = readdir(dirp)) == NULL ) { - if ( errno != 0 ) + if ( errno != 0 ) i_fatal("readdir(%s) failed: %m", scriptfile); break; } - + if ( sieve_scriptfile_has_extension(dp->d_name) ) { const char *file; - + if ( scriptfile[strlen(scriptfile)-1] == '/' ) file = t_strconcat(scriptfile, dp->d_name, NULL); else @@ -124,35 +124,35 @@ int main(int argc, char **argv) sbin = sieve_tool_script_compile(svinst, file, dp->d_name); if ( sbin != NULL ) { - sieve_save(sbin, TRUE, NULL); + sieve_save(sbin, TRUE, NULL); sieve_close(&sbin); } } } - + /* Close the directory */ - if ( closedir(dirp) < 0 ) - i_fatal("closedir(%s) failed: %m", scriptfile); + if ( closedir(dirp) < 0 ) + i_fatal("closedir(%s) failed: %m", scriptfile); } else { /* Script file (i.e. not a directory) - * - * NOTE: For consistency, stat errors are handled here as well - */ + * + * NOTE: For consistency, stat errors are handled here as well + */ sbin = sieve_tool_script_compile(svinst, scriptfile, NULL); if ( sbin != NULL ) { - if ( dump ) + if ( dump ) sieve_tool_dump_binary_to(sbin, outfile, FALSE); else { sieve_save_as(sbin, outfile, TRUE, 0600, NULL); } - + sieve_close(&sbin); } else { exit_status = EXIT_FAILURE; } } - + sieve_tool_deinit(&sieve_tool); return exit_status; diff --git a/src/testsuite/cmd-test-binary.c b/src/testsuite/cmd-test-binary.c index 2a7afdc6b98fd0d72578cdcd293245cdf5571f2a..ff12bc89aa4b1e95bb65995f19a02845e7ec6eb2 100644 --- a/src/testsuite/cmd-test-binary.c +++ b/src/testsuite/cmd-test-binary.c @@ -25,88 +25,88 @@ static bool cmd_test_binary_generate /* Test_binary_load command * - * Syntax: + * Syntax: * test_binary_load <binary-name: string> */ -const struct sieve_command_def cmd_test_binary_load = { - "test_binary_load", - SCT_COMMAND, +const struct sieve_command_def cmd_test_binary_load = { + "test_binary_load", + SCT_COMMAND, 1, 0, FALSE, FALSE, - NULL, + NULL, NULL, cmd_test_binary_validate, NULL, - cmd_test_binary_generate, - NULL + cmd_test_binary_generate, + NULL }; /* Test_binary_save command * - * Syntax: + * Syntax: * test_binary_save <binary-name: string> */ -const struct sieve_command_def cmd_test_binary_save = { - "test_binary_save", - SCT_COMMAND, +const struct sieve_command_def cmd_test_binary_save = { + "test_binary_save", + SCT_COMMAND, 1, 0, FALSE, FALSE, - NULL, + NULL, NULL, cmd_test_binary_validate, NULL, - cmd_test_binary_generate, - NULL + cmd_test_binary_generate, + NULL }; -/* +/* * Operations - */ + */ static bool cmd_test_binary_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address); static int cmd_test_binary_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); - + /* test_binary_create operation */ -const struct sieve_operation_def test_binary_load_operation = { +const struct sieve_operation_def test_binary_load_operation = { "TEST_BINARY_LOAD", - &testsuite_extension, + &testsuite_extension, TESTSUITE_OPERATION_TEST_BINARY_LOAD, - cmd_test_binary_operation_dump, - cmd_test_binary_operation_execute + cmd_test_binary_operation_dump, + cmd_test_binary_operation_execute }; /* test_binary_delete operation */ -const struct sieve_operation_def test_binary_save_operation = { +const struct sieve_operation_def test_binary_save_operation = { "TEST_BINARY_SAVE", - &testsuite_extension, + &testsuite_extension, TESTSUITE_OPERATION_TEST_BINARY_SAVE, - cmd_test_binary_operation_dump, - cmd_test_binary_operation_execute + cmd_test_binary_operation_dump, + cmd_test_binary_operation_execute }; -/* - * Validation +/* + * Validation */ static bool cmd_test_binary_validate -(struct sieve_validator *valdtr, struct sieve_command *cmd) -{ +(struct sieve_validator *valdtr, struct sieve_command *cmd) +{ struct sieve_ast_argument *arg = cmd->first_positional; - + if ( !sieve_validate_positional_argument (valdtr, cmd, arg, "binary-name", 1, SAAT_STRING) ) { return FALSE; } - + return sieve_validator_argument_activate(valdtr, cmd, arg, FALSE); } -/* - * Code generation +/* + * Code generation */ static bool cmd_test_binary_generate @@ -119,7 +119,7 @@ static bool cmd_test_binary_generate sieve_operation_emit(cgenv->sblock, cmd->ext, &test_binary_save_operation); else i_unreached(); - + /* Generate arguments */ if ( !sieve_generate_arguments(cgenv, cmd, NULL) ) return FALSE; @@ -127,24 +127,24 @@ static bool cmd_test_binary_generate return TRUE; } -/* +/* * Code dump */ - + static bool cmd_test_binary_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) { sieve_code_dumpf(denv, "%s:", sieve_operation_mnemonic(denv->oprtn)); - + sieve_code_descend(denv); - + return sieve_opr_string_dump(denv, address, "binary-name"); } /* * Intepretation */ - + static int cmd_test_binary_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) { @@ -152,8 +152,8 @@ static int cmd_test_binary_operation_execute string_t *binary_name = NULL; int ret; - /* - * Read operands + /* + * Read operands */ /* Binary Name */ @@ -194,7 +194,7 @@ static int cmd_test_binary_operation_execute sieve_runtime_trace(renv, 0, "save binary `%s'", str_c(binary_name)); } - if ( sbin != NULL ) + if ( sbin != NULL ) testsuite_binary_save(sbin, str_c(binary_name)); else { sieve_sys_error(testsuite_sieve_instance, diff --git a/src/testsuite/cmd-test-config.c b/src/testsuite/cmd-test-config.c index 61e6e4ec5fb5e4beeb1ed89a4d1008c98ec40704..adb3692a195144f2319e67bbfd873c9be76d9b1f 100644 --- a/src/testsuite/cmd-test-config.c +++ b/src/testsuite/cmd-test-config.c @@ -23,62 +23,62 @@ static bool cmd_test_config_generate /* Test_config_set command * - * Syntax: + * Syntax: * test_config_set <setting: string> <value: string> */ static bool cmd_test_config_set_validate (struct sieve_validator *valdtr, struct sieve_command *cmd); -const struct sieve_command_def cmd_test_config_set = { - "test_config_set", - SCT_COMMAND, +const struct sieve_command_def cmd_test_config_set = { + "test_config_set", + SCT_COMMAND, 2, 0, FALSE, FALSE, NULL, NULL, cmd_test_config_set_validate, NULL, - cmd_test_config_generate, - NULL + cmd_test_config_generate, + NULL }; /* Test_config_unset command * - * Syntax: - * test_config_unset <setting: string> + * Syntax: + * test_config_unset <setting: string> */ static bool cmd_test_config_unset_validate (struct sieve_validator *valdtr, struct sieve_command *cmd); -const struct sieve_command_def cmd_test_config_unset = { - "test_config_unset", - SCT_COMMAND, +const struct sieve_command_def cmd_test_config_unset = { + "test_config_unset", + SCT_COMMAND, 1, 0, FALSE, FALSE, NULL, NULL, cmd_test_config_unset_validate, NULL, - cmd_test_config_generate, - NULL + cmd_test_config_generate, + NULL }; /* Test_config_reload command * - * Syntax: + * Syntax: * test_config_reload [:extension <extension: string>] */ static bool cmd_test_config_reload_registered (struct sieve_validator *valdtr, const struct sieve_extension *ext, - struct sieve_command_registration *cmd_reg); + struct sieve_command_registration *cmd_reg); -const struct sieve_command_def cmd_test_config_reload = { - "test_config_reload", - SCT_COMMAND, +const struct sieve_command_def cmd_test_config_reload = { + "test_config_reload", + SCT_COMMAND, 0, 0, FALSE, FALSE, - cmd_test_config_reload_registered, + cmd_test_config_reload_registered, NULL, NULL, NULL, - cmd_test_config_generate, - NULL + cmd_test_config_generate, + NULL }; /* @@ -88,16 +88,16 @@ const struct sieve_command_def cmd_test_config_reload = { /* Forward declarations */ static bool cmd_test_config_reload_validate_tag - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); /* Argument objects */ -static const struct sieve_argument_def test_config_reload_extension_tag = { - "extension", - NULL, - cmd_test_config_reload_validate_tag, - NULL, NULL, NULL, +static const struct sieve_argument_def test_config_reload_extension_tag = { + "extension", + NULL, + cmd_test_config_reload_validate_tag, + NULL, NULL, NULL, }; /* Codes for optional arguments */ @@ -107,10 +107,10 @@ enum cmd_test_config_optional { OPT_EXTENSION }; -/* +/* * Operations - */ - + */ + /* Test_config_set operation */ static bool cmd_test_config_set_operation_dump @@ -118,12 +118,12 @@ static bool cmd_test_config_set_operation_dump static int cmd_test_config_set_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def test_config_set_operation = { +const struct sieve_operation_def test_config_set_operation = { "TEST_CONFIG_SET", - &testsuite_extension, + &testsuite_extension, TESTSUITE_OPERATION_TEST_CONFIG_SET, - cmd_test_config_set_operation_dump, - cmd_test_config_set_operation_execute + cmd_test_config_set_operation_dump, + cmd_test_config_set_operation_execute }; /* Test_config_unset operation */ @@ -133,12 +133,12 @@ static bool cmd_test_config_unset_operation_dump static int cmd_test_config_unset_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def test_config_unset_operation = { +const struct sieve_operation_def test_config_unset_operation = { "TEST_CONFIG_UNSET", - &testsuite_extension, + &testsuite_extension, TESTSUITE_OPERATION_TEST_CONFIG_UNSET, - cmd_test_config_unset_operation_dump, - cmd_test_config_unset_operation_execute + cmd_test_config_unset_operation_dump, + cmd_test_config_unset_operation_execute }; /* Test_config_read operation */ @@ -148,12 +148,12 @@ static bool cmd_test_config_reload_operation_dump static int cmd_test_config_reload_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def test_config_reload_operation = { +const struct sieve_operation_def test_config_reload_operation = { "TEST_CONFIG_RELOAD", - &testsuite_extension, + &testsuite_extension, TESTSUITE_OPERATION_TEST_CONFIG_RELOAD, - cmd_test_config_reload_operation_dump, - cmd_test_config_reload_operation_execute + cmd_test_config_reload_operation_dump, + cmd_test_config_reload_operation_execute }; /* @@ -161,7 +161,7 @@ const struct sieve_operation_def test_config_reload_operation = { */ static bool cmd_test_config_reload_validate_tag -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd) { struct sieve_ast_argument *tag = *arg; @@ -179,26 +179,26 @@ static bool cmd_test_config_reload_validate_tag /* Skip parameter */ *arg = sieve_ast_argument_next(*arg); - + return TRUE; } -/* - * Command registration +/* + * Command registration */ static bool cmd_test_config_reload_registered (struct sieve_validator *valdtr, const struct sieve_extension *ext, - struct sieve_command_registration *cmd_reg) + struct sieve_command_registration *cmd_reg) { sieve_validator_register_tag - (valdtr, cmd_reg, ext, &test_config_reload_extension_tag, OPT_EXTENSION); + (valdtr, cmd_reg, ext, &test_config_reload_extension_tag, OPT_EXTENSION); return TRUE; } -/* - * Command validation +/* + * Command validation */ static bool cmd_test_config_set_validate @@ -213,7 +213,7 @@ static bool cmd_test_config_set_validate if ( !sieve_validate_positional_argument (valdtr, cmd, arg, "setting", 1, SAAT_STRING) ) { return FALSE; - } + } if ( !sieve_validator_argument_activate(valdtr, cmd, arg, FALSE) ) return FALSE; @@ -223,7 +223,7 @@ static bool cmd_test_config_set_validate if ( !sieve_validate_positional_argument (valdtr, cmd, arg, "value", 2, SAAT_STRING) ) { return FALSE; - } + } return sieve_validator_argument_activate(valdtr, cmd, arg, FALSE); } @@ -245,20 +245,20 @@ static bool cmd_test_config_unset_validate return sieve_validator_argument_activate(valdtr, cmd, arg, FALSE); } -/* - * Code generation +/* + * Code generation */ static bool cmd_test_config_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) -{ - if ( sieve_command_is(cmd, cmd_test_config_set) ) +{ + if ( sieve_command_is(cmd, cmd_test_config_set) ) sieve_operation_emit (cgenv->sblock, cmd->ext, &test_config_set_operation); - else if ( sieve_command_is(cmd, cmd_test_config_unset) ) + else if ( sieve_command_is(cmd, cmd_test_config_unset) ) sieve_operation_emit (cgenv->sblock, cmd->ext, &test_config_unset_operation); - else if ( sieve_command_is(cmd, cmd_test_config_reload) ) + else if ( sieve_command_is(cmd, cmd_test_config_reload) ) sieve_operation_emit (cgenv->sblock, cmd->ext, &test_config_reload_operation); else @@ -271,17 +271,17 @@ static bool cmd_test_config_generate return TRUE; } -/* +/* * Code dump */ - + static bool cmd_test_config_set_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) { sieve_code_dumpf(denv, "TEST_CONFIG_SET:"); - + sieve_code_descend(denv); - + return sieve_opr_string_dump(denv, address, "setting") && sieve_opr_string_dump(denv, address, "value"); } @@ -290,10 +290,10 @@ static bool cmd_test_config_unset_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) { sieve_code_dumpf(denv, "TEST_CONFIG_UNSET:"); - + sieve_code_descend(denv); - return + return sieve_opr_string_dump(denv, address, "setting"); } @@ -301,8 +301,8 @@ static bool cmd_test_config_reload_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) { int opt_code = 0; - - sieve_code_dumpf(denv, "TEST_CONFIG_RELOAD:"); + + sieve_code_dumpf(denv, "TEST_CONFIG_RELOAD:"); sieve_code_descend(denv); /* Dump optional operands */ @@ -334,7 +334,7 @@ static bool cmd_test_config_reload_operation_dump /* * Intepretation */ - + static int cmd_test_config_set_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) { @@ -342,8 +342,8 @@ static int cmd_test_config_set_operation_execute string_t *value; int ret; - /* - * Read operands + /* + * Read operands */ /* Setting */ @@ -357,12 +357,12 @@ static int cmd_test_config_set_operation_execute /* * Perform operation */ - + if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) { sieve_runtime_trace(renv, 0, "testsuite: test_config_set command"); sieve_runtime_trace_descend(renv); - sieve_runtime_trace(renv, 0, "set config `%s' = `%s'", + sieve_runtime_trace(renv, 0, "set config `%s' = `%s'", str_c(setting), str_c(value)); } @@ -377,8 +377,8 @@ static int cmd_test_config_unset_operation_execute string_t *setting; int ret; - /* - * Read operands + /* + * Read operands */ /* Setting */ @@ -388,7 +388,7 @@ static int cmd_test_config_unset_operation_execute /* * Perform operation */ - + if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) { sieve_runtime_trace(renv, 0, "testsuite: test_config_unset command"); @@ -409,10 +409,10 @@ static int cmd_test_config_reload_operation_execute string_t *extension = NULL; int ret; - /* - * Read operands + /* + * Read operands */ - + /* Optional operands */ for (;;) { int opt; @@ -448,10 +448,10 @@ static int cmd_test_config_reload_operation_execute testsuite_test_failf("test_config_reload: " ":extension argument is currently mandatory"); return SIEVE_EXEC_OK; - } + } if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) { - sieve_runtime_trace(renv, 0, "reload configuration for extension `%s'", + sieve_runtime_trace(renv, 0, "reload configuration for extension `%s'", str_c(extension)); } @@ -460,7 +460,7 @@ static int cmd_test_config_reload_operation_execute testsuite_test_failf("test_config_reload: " "unknown extension '%s'", str_c(extension)); return SIEVE_EXEC_OK; - } + } sieve_extension_reload(ext); return SIEVE_EXEC_OK; diff --git a/src/testsuite/cmd-test-fail.c b/src/testsuite/cmd-test-fail.c index 034a3608194f5447b12c6189562776eddda9a6ac..96e98df23b226cc7595fea0e4a8e53c8ab9834db 100644 --- a/src/testsuite/cmd-test-fail.c +++ b/src/testsuite/cmd-test-fail.c @@ -12,10 +12,10 @@ #include "testsuite-common.h" -/* +/* * Test_fail command * - * Syntax: + * Syntax: * test_fail <reason: string> */ @@ -24,19 +24,19 @@ static bool cmd_test_fail_validate static bool cmd_test_fail_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx); -const struct sieve_command_def cmd_test_fail = { - "test_fail", - SCT_COMMAND, +const struct sieve_command_def cmd_test_fail = { + "test_fail", + SCT_COMMAND, 1, 0, FALSE, FALSE, NULL, NULL, cmd_test_fail_validate, - NULL, - cmd_test_fail_generate, - NULL + NULL, + cmd_test_fail_generate, + NULL }; -/* - * Test operation +/* + * Test operation */ static bool cmd_test_fail_operation_dump @@ -44,74 +44,74 @@ static bool cmd_test_fail_operation_dump static int cmd_test_fail_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def test_fail_operation = { +const struct sieve_operation_def test_fail_operation = { "TEST_FAIL", - &testsuite_extension, + &testsuite_extension, TESTSUITE_OPERATION_TEST_FAIL, - cmd_test_fail_operation_dump, - cmd_test_fail_operation_execute + cmd_test_fail_operation_dump, + cmd_test_fail_operation_execute }; -/* - * Validation +/* + * Validation */ static bool cmd_test_fail_validate -(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *cmd) +(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *cmd) { struct sieve_ast_argument *arg = cmd->first_positional; - + if ( !sieve_validate_positional_argument (valdtr, cmd, arg, "reason", 1, SAAT_STRING) ) { return FALSE; } - + return sieve_validator_argument_activate(valdtr, cmd, arg, FALSE); } -/* - * Code generation +/* + * Code generation */ static inline struct testsuite_generator_context * _get_generator_context(struct sieve_generator *gentr) { - return (struct testsuite_generator_context *) + return (struct testsuite_generator_context *) sieve_generator_extension_get_context(gentr, testsuite_ext); } static bool cmd_test_fail_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) { - struct testsuite_generator_context *genctx = + struct testsuite_generator_context *genctx = _get_generator_context(cgenv->gentr); - + sieve_operation_emit(cgenv->sblock, cmd->ext, &test_fail_operation); /* Generate arguments */ if ( !sieve_generate_arguments(cgenv, cmd, NULL) ) return FALSE; - - sieve_jumplist_add(genctx->exit_jumps, - sieve_binary_emit_offset(cgenv->sblock, 0)); - + + sieve_jumplist_add(genctx->exit_jumps, + sieve_binary_emit_offset(cgenv->sblock, 0)); + return TRUE; } -/* +/* * Code dump */ - + static bool cmd_test_fail_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) { unsigned int pc; sieve_offset_t offset; - + sieve_code_dumpf(denv, "TEST_FAIL:"); sieve_code_descend(denv); - if ( !sieve_opr_string_dump(denv, address, "reason") ) + if ( !sieve_opr_string_dump(denv, address, "reason") ) return FALSE; sieve_code_mark(denv); @@ -141,7 +141,7 @@ static int cmd_test_fail_operation_execute "testsuite: test_fail command; FAIL current test"); testsuite_test_fail(reason); - + return sieve_interpreter_program_jump(renv->interp, TRUE); } diff --git a/src/testsuite/cmd-test-mailbox.c b/src/testsuite/cmd-test-mailbox.c index 81504b24a63df710db840dd0876f4843a4b701da..0c72c0b586b627893761add74436f09f6c5c8cb3 100644 --- a/src/testsuite/cmd-test-mailbox.c +++ b/src/testsuite/cmd-test-mailbox.c @@ -24,101 +24,101 @@ static bool cmd_test_mailbox_generate /* Test_mailbox_create command * - * Syntax: + * Syntax: * test_mailbox_create <mailbox: string> */ -const struct sieve_command_def cmd_test_mailbox_create = { - "test_mailbox_create", - SCT_COMMAND, +const struct sieve_command_def cmd_test_mailbox_create = { + "test_mailbox_create", + SCT_COMMAND, 1, 0, FALSE, FALSE, NULL, NULL, cmd_test_mailbox_validate, NULL, - cmd_test_mailbox_generate, - NULL + cmd_test_mailbox_generate, + NULL }; /* Test_mailbox_delete command * - * Syntax: + * Syntax: * test_mailbox_create <mailbox: string> */ -const struct sieve_command_def cmd_test_mailbox_delete = { - "test_mailbox_delete", - SCT_COMMAND, +const struct sieve_command_def cmd_test_mailbox_delete = { + "test_mailbox_delete", + SCT_COMMAND, 1, 0, FALSE, FALSE, NULL, NULL, cmd_test_mailbox_validate, NULL, - cmd_test_mailbox_generate, - NULL + cmd_test_mailbox_generate, + NULL }; -/* +/* * Operations - */ + */ static bool cmd_test_mailbox_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address); static int cmd_test_mailbox_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); - + /* Test_mailbox_create operation */ -const struct sieve_operation_def test_mailbox_create_operation = { +const struct sieve_operation_def test_mailbox_create_operation = { "TEST_MAILBOX_CREATE", - &testsuite_extension, + &testsuite_extension, TESTSUITE_OPERATION_TEST_MAILBOX_CREATE, - cmd_test_mailbox_operation_dump, - cmd_test_mailbox_operation_execute + cmd_test_mailbox_operation_dump, + cmd_test_mailbox_operation_execute }; /* Test_mailbox_delete operation */ -const struct sieve_operation_def test_mailbox_delete_operation = { +const struct sieve_operation_def test_mailbox_delete_operation = { "TEST_MAILBOX_DELETE", - &testsuite_extension, + &testsuite_extension, TESTSUITE_OPERATION_TEST_MAILBOX_DELETE, - cmd_test_mailbox_operation_dump, - cmd_test_mailbox_operation_execute + cmd_test_mailbox_operation_dump, + cmd_test_mailbox_operation_execute }; -/* - * Validation +/* + * Validation */ static bool cmd_test_mailbox_validate -(struct sieve_validator *valdtr, struct sieve_command *cmd) +(struct sieve_validator *valdtr, struct sieve_command *cmd) { struct sieve_ast_argument *arg = cmd->first_positional; - + if ( !sieve_validate_positional_argument (valdtr, cmd, arg, "mailbox", 1, SAAT_STRING) ) { return FALSE; } - + return sieve_validator_argument_activate(valdtr, cmd, arg, FALSE); } -/* - * Code generation +/* + * Code generation */ static bool cmd_test_mailbox_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) { /* Emit operation */ - if ( sieve_command_is(cmd, cmd_test_mailbox_create) ) + if ( sieve_command_is(cmd, cmd_test_mailbox_create) ) sieve_operation_emit (cgenv->sblock, cmd->ext, &test_mailbox_create_operation); - else if ( sieve_command_is(cmd, cmd_test_mailbox_delete) ) + else if ( sieve_command_is(cmd, cmd_test_mailbox_delete) ) sieve_operation_emit (cgenv->sblock, cmd->ext, &test_mailbox_delete_operation); else i_unreached(); - + /* Generate arguments */ if ( !sieve_generate_arguments(cgenv, cmd, NULL) ) return FALSE; @@ -126,17 +126,17 @@ static bool cmd_test_mailbox_generate return TRUE; } -/* +/* * Code dump */ - + static bool cmd_test_mailbox_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) { sieve_code_dumpf(denv, "%s:", sieve_operation_mnemonic(denv->oprtn)); - + sieve_code_descend(denv); - + return sieve_opr_string_dump(denv, address, "mailbox"); } @@ -144,7 +144,7 @@ static bool cmd_test_mailbox_operation_dump /* * Intepretation */ - + static int cmd_test_mailbox_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) { @@ -152,8 +152,8 @@ static int cmd_test_mailbox_operation_execute string_t *mailbox = NULL; int ret; - /* - * Read operands + /* + * Read operands */ /* Index */ @@ -164,7 +164,7 @@ static int cmd_test_mailbox_operation_execute /* * Perform operation */ - + if ( sieve_operation_is(oprtn, test_mailbox_create_operation) ) { if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) { sieve_runtime_trace(renv, 0, "testsuite/test_mailbox_create command"); @@ -179,7 +179,7 @@ static int cmd_test_mailbox_operation_execute sieve_runtime_trace_descend(renv); sieve_runtime_trace(renv, 0, "delete mailbox `%s'", str_c(mailbox)); } - + /* FIXME: implement */ testsuite_test_failf("test_mailbox_delete: NOT IMPLEMENTED"); } diff --git a/src/testsuite/cmd-test-message.c b/src/testsuite/cmd-test-message.c index 59f7104239ff629cda2409b8001c168b6856783c..01eaff2cce74c25d9b9919de8cdf5c4cbbdc5588 100644 --- a/src/testsuite/cmd-test-message.c +++ b/src/testsuite/cmd-test-message.c @@ -20,11 +20,11 @@ /* * Commands - */ + */ /* Test_message command * - * Syntax: + * Syntax: * test_message ( :smtp / :mailbox <mailbox: string> ) <index: number> */ @@ -36,30 +36,30 @@ static bool cmd_test_message_validate static bool cmd_test_message_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx); -const struct sieve_command_def cmd_test_message = { - "test_message", - SCT_HYBRID, +const struct sieve_command_def cmd_test_message = { + "test_message", + SCT_HYBRID, 1, 0, FALSE, FALSE, - cmd_test_message_registered, + cmd_test_message_registered, NULL, cmd_test_message_validate, - NULL, - cmd_test_message_generate, - NULL + NULL, + cmd_test_message_generate, + NULL }; /* Test_message_print command * - * Syntax: + * Syntax: * test_message_print */ static bool cmd_test_message_print_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd); -const struct sieve_command_def cmd_test_message_print = { - "test_message_print", - SCT_COMMAND, +const struct sieve_command_def cmd_test_message_print = { + "test_message_print", + SCT_COMMAND, 0, 0, FALSE, FALSE, NULL, NULL, NULL, NULL, cmd_test_message_print_generate @@ -67,10 +67,10 @@ const struct sieve_command_def cmd_test_message_print = { }; -/* +/* * Operations - */ - + */ + /* Test_message_smtp operation */ static bool cmd_test_message_smtp_operation_dump @@ -78,12 +78,12 @@ static bool cmd_test_message_smtp_operation_dump static int cmd_test_message_smtp_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def test_message_smtp_operation = { +const struct sieve_operation_def test_message_smtp_operation = { "TEST_MESSAGE_SMTP", - &testsuite_extension, + &testsuite_extension, TESTSUITE_OPERATION_TEST_MESSAGE_SMTP, - cmd_test_message_smtp_operation_dump, - cmd_test_message_smtp_operation_execute + cmd_test_message_smtp_operation_dump, + cmd_test_message_smtp_operation_execute }; /* Test_message_mailbox operation */ @@ -93,12 +93,12 @@ static bool cmd_test_message_mailbox_operation_dump static int cmd_test_message_mailbox_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def test_message_mailbox_operation = { +const struct sieve_operation_def test_message_mailbox_operation = { "TEST_MESSAGE_MAILBOX", - &testsuite_extension, + &testsuite_extension, TESTSUITE_OPERATION_TEST_MESSAGE_MAILBOX, - cmd_test_message_mailbox_operation_dump, - cmd_test_message_mailbox_operation_execute + cmd_test_message_mailbox_operation_dump, + cmd_test_message_mailbox_operation_execute }; /* Test_message_print operation */ @@ -108,20 +108,20 @@ static bool cmd_test_message_print_operation_dump static int cmd_test_message_print_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def test_message_print_operation = { +const struct sieve_operation_def test_message_print_operation = { "TEST_MESSAGE_PRINT", - &testsuite_extension, + &testsuite_extension, TESTSUITE_OPERATION_TEST_MESSAGE_PRINT, - cmd_test_message_print_operation_dump, - cmd_test_message_print_operation_execute + cmd_test_message_print_operation_dump, + cmd_test_message_print_operation_execute }; /* * Compiler context data */ - + enum test_message_source { - MSG_SOURCE_SMTP, + MSG_SOURCE_SMTP, MSG_SOURCE_MAILBOX, MSG_SOURCE_LAST }; @@ -140,61 +140,61 @@ struct cmd_test_message_context_data { "exactly one of the ':smtp' or ':folder' tags must be specified " \ "for the test_message command, but more were found" -/* - * Command tags +/* + * Command tags */ - + static bool cmd_test_message_validate_smtp_tag - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); static bool cmd_test_message_validate_folder_tag - (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd); -static const struct sieve_argument_def test_message_smtp_tag = { - "smtp", +static const struct sieve_argument_def test_message_smtp_tag = { + "smtp", NULL, cmd_test_message_validate_smtp_tag, NULL, NULL, NULL }; -static const struct sieve_argument_def test_message_folder_tag = { - "folder", +static const struct sieve_argument_def test_message_folder_tag = { + "folder", NULL, cmd_test_message_validate_folder_tag, - NULL, NULL, NULL + NULL, NULL, NULL }; static bool cmd_test_message_registered (struct sieve_validator *valdtr, const struct sieve_extension *ext, - struct sieve_command_registration *cmd_reg) + struct sieve_command_registration *cmd_reg) { /* Register our tags */ sieve_validator_register_tag - (valdtr, cmd_reg, ext, &test_message_folder_tag, 0); + (valdtr, cmd_reg, ext, &test_message_folder_tag, 0); sieve_validator_register_tag - (valdtr, cmd_reg, ext, &test_message_smtp_tag, 0); + (valdtr, cmd_reg, ext, &test_message_smtp_tag, 0); return TRUE; } static struct cmd_test_message_context_data *cmd_test_message_validate_tag -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd) { - struct cmd_test_message_context_data *ctx_data = - (struct cmd_test_message_context_data *) cmd->data; - + struct cmd_test_message_context_data *ctx_data = + (struct cmd_test_message_context_data *) cmd->data; + if ( ctx_data != NULL ) { sieve_argument_validate_error (valdtr, *arg, CMD_TEST_MESSAGE_ERROR_DUP_TAG); - return NULL; + return NULL; } - + ctx_data = p_new (sieve_command_pool(cmd), struct cmd_test_message_context_data, 1); cmd->data = ctx_data; - + /* Delete this tag */ *arg = sieve_ast_arguments_detach(*arg, 1); @@ -202,35 +202,35 @@ static struct cmd_test_message_context_data *cmd_test_message_validate_tag } static bool cmd_test_message_validate_smtp_tag -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd) { - struct cmd_test_message_context_data *ctx_data = + struct cmd_test_message_context_data *ctx_data = cmd_test_message_validate_tag(valdtr, arg, cmd); /* Return value is NULL on error */ if ( ctx_data == NULL ) return FALSE; - + /* Assign chosen message source */ ctx_data->msg_source = MSG_SOURCE_SMTP; - + return TRUE; } static bool cmd_test_message_validate_folder_tag -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd) { struct sieve_ast_argument *tag = *arg; - struct cmd_test_message_context_data *ctx_data = + struct cmd_test_message_context_data *ctx_data = cmd_test_message_validate_tag(valdtr, arg, cmd); - + /* Return value is NULL on error */ if ( ctx_data == NULL ) return FALSE; /* Assign chose message source */ ctx_data->msg_source = MSG_SOURCE_MAILBOX; - + /* Check syntax: * :folder string */ @@ -241,53 +241,53 @@ static bool cmd_test_message_validate_folder_tag /* Skip parameter */ *arg = sieve_ast_argument_next(*arg); - + return TRUE; } -/* - * Validation +/* + * Validation */ static bool cmd_test_message_validate -(struct sieve_validator *valdtr, struct sieve_command *cmd) +(struct sieve_validator *valdtr, struct sieve_command *cmd) { struct sieve_ast_argument *arg = cmd->first_positional; - + if ( cmd->data == NULL ) { - sieve_command_validate_error(valdtr, cmd, + sieve_command_validate_error(valdtr, cmd, "the test_message command requires either the :smtp or the :mailbox tag " "to be specified"); - return FALSE; + return FALSE; } - + if ( !sieve_validate_positional_argument (valdtr, cmd, arg, "index", 1, SAAT_NUMBER) ) { return FALSE; } - + return sieve_validator_argument_activate(valdtr, cmd, arg, FALSE); } -/* - * Code generation +/* + * Code generation */ static bool cmd_test_message_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) { struct cmd_test_message_context_data *ctx_data = - (struct cmd_test_message_context_data *) cmd->data; + (struct cmd_test_message_context_data *) cmd->data; i_assert( ctx_data->msg_source < MSG_SOURCE_LAST ); - + /* Emit operation */ sieve_operation_emit(cgenv->sblock, cmd->ext, test_message_operations[ctx_data->msg_source]); /* Emit is_test flag */ sieve_binary_emit_byte(cgenv->sblock, ( cmd->ast_node->type == SAT_TEST )); - + /* Generate arguments */ if ( !sieve_generate_arguments(cgenv, cmd, NULL) ) return FALSE; @@ -297,17 +297,17 @@ static bool cmd_test_message_generate static bool cmd_test_message_print_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) -{ +{ /* Emit operation */ sieve_operation_emit (cgenv->sblock, cmd->ext, &test_message_print_operation); return TRUE; } -/* +/* * Code dump */ - + static bool cmd_test_message_smtp_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) { @@ -316,11 +316,11 @@ static bool cmd_test_message_smtp_operation_dump if ( !sieve_binary_read_byte(denv->sblock, address, &is_test) ) return FALSE; - sieve_code_dumpf(denv, "TEST_MESSAGE_SMTP (%s):", + sieve_code_dumpf(denv, "TEST_MESSAGE_SMTP (%s):", ( is_test ? "TEST" : "COMMAND" )); - + sieve_code_descend(denv); - + return sieve_opr_number_dump(denv, address, "index"); } @@ -334,10 +334,10 @@ static bool cmd_test_message_mailbox_operation_dump sieve_code_dumpf(denv, "TEST_MESSAGE_MAILBOX (%s):", ( is_test ? "TEST" : "COMMAND" )); - + sieve_code_descend(denv); - return + return sieve_opr_string_dump(denv, address, "folder") && sieve_opr_number_dump(denv, address, "index"); } @@ -354,7 +354,7 @@ static bool cmd_test_message_print_operation_dump /* * Intepretation */ - + static int cmd_test_message_smtp_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) { @@ -363,8 +363,8 @@ static int cmd_test_message_smtp_operation_execute bool result; int ret; - /* - * Read operands + /* + * Read operands */ /* Is test */ @@ -385,18 +385,18 @@ static int cmd_test_message_smtp_operation_execute if ( is_test ) { if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_TESTS) ) { - sieve_runtime_trace(renv, 0, + sieve_runtime_trace(renv, 0, "testsuite: test_message test"); sieve_runtime_trace_descend(renv); - sieve_runtime_trace(renv, 0, + sieve_runtime_trace(renv, 0, "check and retrieve smtp message [index=%d]", msg_index); } } else { if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) { - sieve_runtime_trace(renv, 0, + sieve_runtime_trace(renv, 0, "testsuite: test_message command"); sieve_runtime_trace_descend(renv); - sieve_runtime_trace(renv, 0, + sieve_runtime_trace(renv, 0, "retrieve smtp message [index=%d]", msg_index); } } @@ -436,7 +436,7 @@ static int cmd_test_message_mailbox_operation_execute /* Folder */ if ( (ret=sieve_opr_string_read(renv, address, "folder", &folder)) <= 0 ) return ret; - + /* Index */ if ( (ret=sieve_opr_number_read(renv, address, "index", &msg_index)) <= 0 ) return ret; @@ -444,23 +444,23 @@ static int cmd_test_message_mailbox_operation_execute /* * Perform operation */ - + if ( is_test ) { if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_TESTS) ) { - sieve_runtime_trace(renv, 0, + sieve_runtime_trace(renv, 0, "testsuite: test_message test"); sieve_runtime_trace_descend(renv); - sieve_runtime_trace(renv, 0, - "check and retrieve mailbox message [mailbox=`%s' index=%d]", + sieve_runtime_trace(renv, 0, + "check and retrieve mailbox message [mailbox=`%s' index=%d]", str_c(folder), msg_index); } } else { if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) { - sieve_runtime_trace(renv, 0, + sieve_runtime_trace(renv, 0, "testsuite: test_message command"); sieve_runtime_trace_descend(renv); - sieve_runtime_trace(renv, 0, - "retrieve mailbox message [mailbox=`%s' index=%d]", + sieve_runtime_trace(renv, 0, + "retrieve mailbox message [mailbox=`%s' index=%d]", str_c(folder), msg_index); } } @@ -473,7 +473,7 @@ static int cmd_test_message_mailbox_operation_execute } if ( !result ) - testsuite_test_failf("no message in folder '%s' with index %d", + testsuite_test_failf("no message in folder '%s' with index %d", str_c(folder), msg_index); return SIEVE_EXEC_OK; diff --git a/src/testsuite/cmd-test-result.c b/src/testsuite/cmd-test-result.c index 2c7e186d2e1c97d4146bacf141887cd188abc45d..9e42bcd7bad64b2607779db4ac87b045a0acb11c 100644 --- a/src/testsuite/cmd-test-result.c +++ b/src/testsuite/cmd-test-result.c @@ -25,36 +25,36 @@ static bool cmd_test_result_generate /* Test_result_reset command * - * Syntax: + * Syntax: * test_result_reset */ -const struct sieve_command_def cmd_test_result_reset = { - "test_result_reset", - SCT_COMMAND, +const struct sieve_command_def cmd_test_result_reset = { + "test_result_reset", + SCT_COMMAND, 0, 0, FALSE, FALSE, NULL, NULL, NULL, NULL, - cmd_test_result_generate, - NULL + cmd_test_result_generate, + NULL }; /* Test_result_print command * - * Syntax: + * Syntax: * test_result_print */ -const struct sieve_command_def cmd_test_result_print = { - "test_result_print", - SCT_COMMAND, +const struct sieve_command_def cmd_test_result_print = { + "test_result_print", + SCT_COMMAND, 0, 0, FALSE, FALSE, NULL, NULL, NULL, NULL, - cmd_test_result_generate, - NULL + cmd_test_result_generate, + NULL }; -/* - * Operations +/* + * Operations */ /* test_result_reset */ @@ -62,12 +62,12 @@ const struct sieve_command_def cmd_test_result_print = { static int cmd_test_result_reset_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def test_result_reset_operation = { +const struct sieve_operation_def test_result_reset_operation = { "TEST_RESULT_RESET", - &testsuite_extension, + &testsuite_extension, TESTSUITE_OPERATION_TEST_RESULT_RESET, - NULL, - cmd_test_result_reset_operation_execute + NULL, + cmd_test_result_reset_operation_execute }; /* test_result_print */ @@ -75,16 +75,16 @@ const struct sieve_operation_def test_result_reset_operation = { static int cmd_test_result_print_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def test_result_print_operation = { +const struct sieve_operation_def test_result_print_operation = { "TEST_RESULT_PRINT", - &testsuite_extension, + &testsuite_extension, TESTSUITE_OPERATION_TEST_RESULT_PRINT, - NULL, - cmd_test_result_print_operation_execute + NULL, + cmd_test_result_print_operation_execute }; -/* - * Code generation +/* + * Code generation */ static bool cmd_test_result_generate @@ -107,7 +107,7 @@ static bool cmd_test_result_generate static int cmd_test_result_reset_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address ATTR_UNUSED) { - sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, + sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, "testsuite: test_result_reset command; reset script result"); testsuite_result_reset(renv); @@ -119,7 +119,7 @@ static int cmd_test_result_reset_operation_execute static int cmd_test_result_print_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address ATTR_UNUSED) { - sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, + sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, "testsuite: test_result_print command; print script result "); testsuite_result_print(renv); diff --git a/src/testsuite/cmd-test-set.c b/src/testsuite/cmd-test-set.c index 7884d5f91b3b514586e6f1f9dd1dce231edd71d4..28a8af095c28a0d3582e52b33bc99bf8843d4abd 100644 --- a/src/testsuite/cmd-test-set.c +++ b/src/testsuite/cmd-test-set.c @@ -11,7 +11,7 @@ #include "sieve-commands.h" #include "sieve-code.h" #include "sieve-actions.h" -#include "sieve-validator.h" +#include "sieve-validator.h" #include "sieve-generator.h" #include "sieve-interpreter.h" #include "sieve-code-dumper.h" @@ -22,9 +22,9 @@ #include <stdio.h> -/* - * Test_set command - * +/* + * Test_set command + * * Syntax * test_set <testsuite object (member): string> <value: string> */ @@ -34,19 +34,19 @@ static bool cmd_test_set_validate static bool cmd_test_set_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd); -const struct sieve_command_def cmd_test_set = { - "test_set", +const struct sieve_command_def cmd_test_set = { + "test_set", SCT_COMMAND, - 2, 0, FALSE, FALSE, + 2, 0, FALSE, FALSE, NULL, NULL, cmd_test_set_validate, - NULL, - cmd_test_set_generate, - NULL + NULL, + cmd_test_set_generate, + NULL }; -/* - * Test_set operation +/* + * Test_set operation */ static bool cmd_test_set_operation_dump @@ -54,49 +54,49 @@ static bool cmd_test_set_operation_dump static int cmd_test_set_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def test_set_operation = { +const struct sieve_operation_def test_set_operation = { "TEST_SET", - &testsuite_extension, + &testsuite_extension, TESTSUITE_OPERATION_TEST_SET, - cmd_test_set_operation_dump, - cmd_test_set_operation_execute + cmd_test_set_operation_dump, + cmd_test_set_operation_execute }; -/* - * Validation +/* + * Validation */ - + static bool cmd_test_set_validate -(struct sieve_validator *valdtr, struct sieve_command *cmd) +(struct sieve_validator *valdtr, struct sieve_command *cmd) { struct sieve_ast_argument *arg = cmd->first_positional; /* Check arguments */ - + if ( !sieve_validate_positional_argument (valdtr, cmd, arg, "object", 1, SAAT_STRING) ) { return FALSE; } - + if ( !testsuite_object_argument_activate(valdtr, arg, cmd) ) return FALSE; - + arg = sieve_ast_argument_next(arg); - + if ( !sieve_validate_positional_argument (valdtr, cmd, arg, "value", 2, SAAT_STRING) ) { return FALSE; } - + return sieve_validator_argument_activate(valdtr, cmd, arg, FALSE); } /* * Code generation */ - + static bool cmd_test_set_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) { sieve_operation_emit(cgenv->sblock, cmd->ext, &test_set_operation); @@ -104,17 +104,17 @@ static bool cmd_test_set_generate return sieve_generate_arguments(cgenv, cmd, NULL); } -/* +/* * Code dump */ - + static bool cmd_test_set_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) { sieve_code_dumpf(denv, "TEST SET:"); sieve_code_descend(denv); - return + return testsuite_object_dump(denv, address) && sieve_opr_string_dump(denv, address, "value"); } @@ -143,17 +143,17 @@ static int cmd_test_set_operation_execute if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) { sieve_runtime_trace(renv, 0, "testsuite: test_set command"); sieve_runtime_trace_descend(renv); - sieve_runtime_trace(renv, 0, - "set test parameter '%s' = \"%s\"", + sieve_runtime_trace(renv, 0, + "set test parameter '%s' = \"%s\"", testsuite_object_member_name(&tobj, member_id), str_c(value)); } - + if ( tobj.def == NULL || tobj.def->set_member == NULL ) { sieve_runtime_trace_error(renv, "unimplemented testsuite object"); return SIEVE_EXEC_FAILURE; } - - tobj.def->set_member(renv, member_id, value); + + tobj.def->set_member(renv, member_id, value); return SIEVE_EXEC_OK; } diff --git a/src/testsuite/cmd-test.c b/src/testsuite/cmd-test.c index b8efc17037425d6e7570f237784cb589acfd5b03..1301e1fe5f437dd79e78c85768b0531589d9dd0c 100644 --- a/src/testsuite/cmd-test.c +++ b/src/testsuite/cmd-test.c @@ -15,7 +15,7 @@ /* * Test command * - * Syntax: + * Syntax: * test <test-name: string> <block> */ @@ -24,19 +24,19 @@ static bool cmd_test_validate static bool cmd_test_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *md); -const struct sieve_command_def cmd_test = { - "test", - SCT_COMMAND, +const struct sieve_command_def cmd_test = { + "test", + SCT_COMMAND, 1, 0, TRUE, TRUE, NULL, NULL, cmd_test_validate, NULL, - cmd_test_generate, - NULL + cmd_test_generate, + NULL }; -/* - * Test operations +/* + * Test operations */ /* Test operation */ @@ -46,12 +46,12 @@ static bool cmd_test_operation_dump static int cmd_test_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def test_operation = { +const struct sieve_operation_def test_operation = { "TEST", - &testsuite_extension, + &testsuite_extension, TESTSUITE_OPERATION_TEST, - cmd_test_operation_dump, - cmd_test_operation_execute + cmd_test_operation_dump, + cmd_test_operation_execute }; /* Test_finish operation */ @@ -59,23 +59,23 @@ const struct sieve_operation_def test_operation = { static int cmd_test_finish_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def test_finish_operation = { +const struct sieve_operation_def test_finish_operation = { "TEST-FINISH", - &testsuite_extension, + &testsuite_extension, TESTSUITE_OPERATION_TEST_FINISH, - NULL, - cmd_test_finish_operation_execute + NULL, + cmd_test_finish_operation_execute }; -/* - * Validation +/* + * Validation */ static bool cmd_test_validate -(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *cmd) +(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *cmd) { struct sieve_ast_argument *arg = cmd->first_positional; - + /* Check valid command placement */ if ( !sieve_command_is_toplevel(cmd) ) { @@ -83,64 +83,64 @@ static bool cmd_test_validate "tests cannot be nested: test command must be issued at top-level"); return FALSE; } - + if ( !sieve_validate_positional_argument (valdtr, cmd, arg, "test-name", 1, SAAT_STRING) ) { return FALSE; } - + return sieve_validator_argument_activate(valdtr, cmd, arg, FALSE); } -/* - * Code generation +/* + * Code generation */ static inline struct testsuite_generator_context * _get_generator_context(struct sieve_generator *gentr) { - return (struct testsuite_generator_context *) + return (struct testsuite_generator_context *) sieve_generator_extension_get_context(gentr, testsuite_ext); } static bool cmd_test_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) { - struct testsuite_generator_context *genctx = + struct testsuite_generator_context *genctx = _get_generator_context(cgenv->gentr); - + sieve_operation_emit(cgenv->sblock, cmd->ext, &test_operation); /* Generate arguments */ if ( !sieve_generate_arguments(cgenv, cmd, NULL) ) return FALSE; - + /* Prepare jumplist */ sieve_jumplist_reset(genctx->exit_jumps); - + /* Test body */ if ( !sieve_generate_block(cgenv, cmd->ast_node) ) return FALSE; - + sieve_operation_emit(cgenv->sblock, cmd->ext, &test_finish_operation); - + /* Resolve exit jumps to this point */ - sieve_jumplist_resolve(genctx->exit_jumps); - + sieve_jumplist_resolve(genctx->exit_jumps); + return TRUE; } -/* +/* * Code dump */ - + static bool cmd_test_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) { sieve_code_dumpf(denv, "TEST:"); sieve_code_descend(denv); - return + return sieve_opr_string_dump(denv, address, "test name"); } @@ -157,9 +157,9 @@ static int cmd_test_operation_execute if ( (ret=sieve_opr_string_read(renv, address, "test name", &test_name)) <= 0 ) return ret; - + sieve_runtime_trace_sep(renv); - sieve_runtime_trace(renv, SIEVE_TRLVL_NONE, + sieve_runtime_trace(renv, SIEVE_TRLVL_NONE, "** Testsuite test start: \"%s\"", str_c(test_name)); testsuite_test_start(test_name); @@ -167,13 +167,13 @@ static int cmd_test_operation_execute } static int cmd_test_finish_operation_execute -(const struct sieve_runtime_env *renv ATTR_UNUSED, +(const struct sieve_runtime_env *renv ATTR_UNUSED, sieve_size_t *address ATTR_UNUSED) { - sieve_runtime_trace(renv, SIEVE_TRLVL_NONE, + sieve_runtime_trace(renv, SIEVE_TRLVL_NONE, "** Testsuite test end"); sieve_runtime_trace_sep(renv); - + testsuite_test_succeed(NULL); return SIEVE_EXEC_OK; } diff --git a/src/testsuite/ext-testsuite.c b/src/testsuite/ext-testsuite.c index babf5558d98c94e2fa4e497b3a77f178b72446e0..bcf3250e08c5d1a56143e5e1638f3054155b183a 100644 --- a/src/testsuite/ext-testsuite.c +++ b/src/testsuite/ext-testsuite.c @@ -48,12 +48,12 @@ #include "testsuite-variables.h" #include "testsuite-arguments.h" -/* - * Operations +/* + * Operations */ -const struct sieve_operation_def *testsuite_operations[] = { - &test_operation, +const struct sieve_operation_def *testsuite_operations[] = { + &test_operation, &test_finish_operation, &test_fail_operation, &test_config_set_operation, @@ -105,13 +105,13 @@ static bool ext_testsuite_binary_load /* Extension object */ -const struct sieve_extension_def testsuite_extension = { - "vnd.dovecot.testsuite", +const struct sieve_extension_def testsuite_extension = { + "vnd.dovecot.testsuite", NULL, NULL, ext_testsuite_validator_load, ext_testsuite_generator_load, ext_testsuite_interpreter_load, - ext_testsuite_binary_load, + ext_testsuite_binary_load, NULL, NULL, SIEVE_EXT_DEFINE_OPERATIONS(testsuite_operations), SIEVE_EXT_DEFINE_OPERANDS(testsuite_operands) diff --git a/src/testsuite/testsuite-arguments.c b/src/testsuite/testsuite-arguments.c index faa73ce119a73ff74e3b9b3602ba22797724d74a..6071cade0c1736096b0bb8dec92a9a219c39495a 100644 --- a/src/testsuite/testsuite-arguments.c +++ b/src/testsuite/testsuite-arguments.c @@ -20,27 +20,27 @@ #include <ctype.h> -/* - * Testsuite string argument +/* + * Testsuite string argument */ static bool arg_testsuite_string_validate - (struct sieve_validator *validator, struct sieve_ast_argument **arg, + (struct sieve_validator *validator, struct sieve_ast_argument **arg, struct sieve_command *context); -const struct sieve_argument_def testsuite_string_argument = { - "@testsuite-string", - NULL, - arg_testsuite_string_validate, +const struct sieve_argument_def testsuite_string_argument = { + "@testsuite-string", + NULL, + arg_testsuite_string_validate, NULL, NULL, sieve_arg_catenated_string_generate, }; static bool arg_testsuite_string_validate -(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd) { - enum { ST_NONE, ST_OPEN, ST_SUBSTITUTION, ST_PARAM, ST_CLOSE } state = + enum { ST_NONE, ST_OPEN, ST_SUBSTITUTION, ST_PARAM, ST_CLOSE } state = ST_NONE; pool_t pool = sieve_ast_pool((*arg)->ast); struct sieve_arg_catenated_string *catstr = NULL; @@ -51,10 +51,10 @@ static bool arg_testsuite_string_validate bool result = TRUE; string_t *subs_name = t_str_new(256); string_t *subs_param = t_str_new(256); - + T_BEGIN { /* Initialize substitution structure */ - + p = strval; strstart = p; while ( result && p < strend ) { @@ -76,24 +76,24 @@ static bool arg_testsuite_string_validate if ( *p == '{' ) { state = ST_SUBSTITUTION; p++; - } else + } else state = ST_NONE; break; - /* Got '%{' */ + /* Got '%{' */ case ST_SUBSTITUTION: - state = ST_PARAM; + state = ST_PARAM; while ( *p != '}' && *p != ':' ) { if ( !i_isalnum(*p) ) { state = ST_NONE; break; - } + } str_append_c(subs_name, *p); p++; } break; - + /* Got '%{name' */ case ST_PARAM: if ( *p == ':' ) { @@ -108,26 +108,26 @@ static bool arg_testsuite_string_validate /* Finished parsing param, expecting '}' */ case ST_CLOSE: - if ( *p == '}' ) { + if ( *p == '}' ) { struct sieve_ast_argument *strarg; - - /* We now know that the substitution is valid */ - + + /* We now know that the substitution is valid */ + if ( catstr == NULL ) { catstr = sieve_arg_catenated_string_create(*arg); } - - /* Add the substring that is before the substitution to the + + /* Add the substring that is before the substitution to the * variable-string AST. */ if ( substart > strstart ) { string_t *newstr = str_new(pool, substart - strstart); - str_append_n(newstr, strstart, substart - strstart); - + str_append_n(newstr, strstart, substart - strstart); + strarg = sieve_ast_argument_string_create_raw ((*arg)->ast, newstr, (*arg)->source_line); sieve_arg_catenated_string_add_element(catstr, strarg); - + /* Give other substitution extensions a chance to do their work */ if ( !sieve_validator_argument_activate_super (valdtr, cmd, strarg, FALSE) ) { @@ -135,25 +135,25 @@ static bool arg_testsuite_string_validate break; } } - + strarg = testsuite_substitution_argument_create - (valdtr, (*arg)->ast, (*arg)->source_line, str_c(subs_name), + (valdtr, (*arg)->ast, (*arg)->source_line, str_c(subs_name), str_c(subs_param)); - + if ( strarg != NULL ) sieve_arg_catenated_string_add_element(catstr, strarg); else { - sieve_argument_validate_error(valdtr, *arg, + sieve_argument_validate_error(valdtr, *arg, "unknown testsuite substitution type '%s'", str_c(subs_name)); } strstart = p + 1; substart = strstart; - p++; + p++; } - - /* Finished, reset for the next substitution */ + + /* Finished, reset for the next substitution */ state = ST_NONE; } } @@ -161,7 +161,7 @@ static bool arg_testsuite_string_validate /* Bail out early if substitution is invalid */ if ( !result ) return FALSE; - + /* Check whether any substitutions were found */ if ( catstr == NULL ) { /* No substitutions in this string, pass it on to any other substution @@ -169,24 +169,24 @@ static bool arg_testsuite_string_validate */ return sieve_validator_argument_activate_super(valdtr, cmd, *arg, TRUE); } - - /* Add the final substring that comes after the last substitution to the + + /* Add the final substring that comes after the last substitution to the * variable-string AST. */ if ( strend > strstart ) { struct sieve_ast_argument *strarg; string_t *newstr = str_new(pool, strend - strstart); - str_append_n(newstr, strstart, strend - strstart); + str_append_n(newstr, strstart, strend - strstart); strarg = sieve_ast_argument_string_create_raw ((*arg)->ast, newstr, (*arg)->source_line); sieve_arg_catenated_string_add_element(catstr, strarg); - - /* Give other substitution extensions a chance to do their work */ + + /* Give other substitution extensions a chance to do their work */ if ( !sieve_validator_argument_activate_super (valdtr, cmd, strarg, FALSE) ) return FALSE; - } - + } + return TRUE; } diff --git a/src/testsuite/testsuite-binary.c b/src/testsuite/testsuite-binary.c index d8232ef97276285eaf6c421e6f802aa4c93c8065..210b2cb390f4ddbdf274556de9434ebb299408ec 100644 --- a/src/testsuite/testsuite-binary.c +++ b/src/testsuite/testsuite-binary.c @@ -32,13 +32,13 @@ static char *testsuite_binary_tmp = NULL; */ void testsuite_binary_init(void) -{ +{ testsuite_binary_tmp = i_strconcat (testsuite_tmp_dir_get(), "/binaries", NULL); if ( mkdir(testsuite_binary_tmp, 0700) < 0 ) { - i_fatal("failed to create temporary directory '%s': %m.", - testsuite_binary_tmp); + i_fatal("failed to create temporary directory '%s': %m.", + testsuite_binary_tmp); } } @@ -48,8 +48,8 @@ void testsuite_binary_deinit(void) i_warning("failed to remove temporary directory '%s': %m.", testsuite_binary_tmp); } - - i_free(testsuite_binary_tmp); + + i_free(testsuite_binary_tmp); } void testsuite_binary_reset(void) diff --git a/src/testsuite/testsuite-binary.h b/src/testsuite/testsuite-binary.h index 7495134f454b577672e7ef033b9239fb1ae86d4e..cc20492f9bdbc982baee4aee1dcdc011e8345126 100644 --- a/src/testsuite/testsuite-binary.h +++ b/src/testsuite/testsuite-binary.h @@ -4,7 +4,7 @@ #ifndef __TESTSUITE_BINARY_H #define __TESTSUITE_BINARY_H -#include "sieve-common.h" +#include "sieve-common.h" void testsuite_binary_init(void); void testsuite_binary_deinit(void); diff --git a/src/testsuite/testsuite-common.c b/src/testsuite/testsuite-common.c index 2fbddaeb75f9a86ae14013ad05fa0b3591881a91..02c23780846c5f86d83478b609bac75b2d5de5ab 100644 --- a/src/testsuite/testsuite-common.c +++ b/src/testsuite/testsuite-common.c @@ -58,20 +58,20 @@ static unsigned int test_failures; const struct sieve_extension *testsuite_ext; -/* - * Validator context +/* + * Validator context */ bool testsuite_validator_context_initialize(struct sieve_validator *valdtr) { pool_t pool = sieve_validator_pool(valdtr); - struct testsuite_validator_context *ctx = + struct testsuite_validator_context *ctx = p_new(pool, struct testsuite_validator_context, 1); - + /* Setup object registry */ ctx->object_registrations = sieve_validator_object_registry_create(valdtr); testsuite_register_core_objects(ctx); - + sieve_validator_extension_set_context(valdtr, testsuite_ext, ctx); return TRUE; @@ -84,8 +84,8 @@ struct testsuite_validator_context *testsuite_validator_context_get sieve_validator_extension_get_context(valdtr, testsuite_ext); } -/* - * Generator context +/* + * Generator context */ bool testsuite_generator_context_initialize @@ -93,12 +93,12 @@ bool testsuite_generator_context_initialize { pool_t pool = sieve_generator_pool(gentr); struct sieve_binary_block *sblock = sieve_generator_get_block(gentr); - struct testsuite_generator_context *ctx = + struct testsuite_generator_context *ctx = p_new(pool, struct testsuite_generator_context, 1); - + /* Setup exit jumplist */ ctx->exit_jumps = sieve_jumplist_create(pool, sblock); - + sieve_generator_extension_set_context(gentr, this_ext, ctx); return TRUE; @@ -149,11 +149,11 @@ struct testsuite_interpreter_context *testsuite_interpreter_context_get /* * Test context */ - + static void testsuite_test_context_init(void) { test_name = str_new(default_pool, 128); - test_index = 0; + test_index = 0; test_failures = 0; } @@ -181,7 +181,7 @@ void testsuite_test_failf(const char *fmt, ...) } void testsuite_test_fail_cstr(const char *reason) -{ +{ if ( str_len(test_name) == 0 ) { if ( reason == NULL || *reason == '\0' ) printf("%2d: Test FAILED\n", test_index); @@ -191,7 +191,7 @@ void testsuite_test_fail_cstr(const char *reason) if ( reason == NULL || *reason == '\0' ) printf("%2d: Test '%s' FAILED\n", test_index, str_c(test_name)); else - printf("%2d: Test '%s' FAILED: %s\n", test_index, + printf("%2d: Test '%s' FAILED: %s\n", test_index, str_c(test_name), reason); } @@ -201,7 +201,7 @@ void testsuite_test_fail_cstr(const char *reason) } void testsuite_testcase_fail(const char *reason) -{ +{ if ( reason == NULL || *reason == '\0' ) printf("XX: Test CASE FAILED\n"); else @@ -221,7 +221,7 @@ void testsuite_test_succeed(string_t *reason) if ( reason == NULL || str_len(reason) == 0 ) printf("%2d: Test '%s' SUCCEEDED\n", test_index, str_c(test_name)); else - printf("%2d: Test '%s' SUCCEEDED: %s\n", test_index, + printf("%2d: Test '%s' SUCCEEDED: %s\n", test_index, str_c(test_name), str_c(reason)); } str_truncate(test_name, 0); @@ -255,8 +255,8 @@ static void testsuite_tmp_dir_init(void) ("/tmp/dsieve-testsuite.%s.%s", dec2str(time(NULL)), dec2str(getpid())); if ( mkdir(testsuite_tmp_dir, 0700) < 0 ) { - i_fatal("failed to create temporary directory '%s': %m.", - testsuite_tmp_dir); + i_fatal("failed to create temporary directory '%s': %m.", + testsuite_tmp_dir); } } diff --git a/src/testsuite/testsuite-common.h b/src/testsuite/testsuite-common.h index 40c56817f3a3121dbaf9cec24fd5dcbac72c62db..36e9078e7196bf819853f83fd8e807400279a8a0 100644 --- a/src/testsuite/testsuite-common.h +++ b/src/testsuite/testsuite-common.h @@ -23,8 +23,8 @@ extern const struct sieve_script_env *testsuite_scriptenv; extern char *testsuite_test_path; -/* - * Validator context +/* + * Validator context */ struct testsuite_validator_context { @@ -35,8 +35,8 @@ bool testsuite_validator_context_initialize(struct sieve_validator *valdtr); struct testsuite_validator_context *testsuite_validator_context_get (struct sieve_validator *valdtr); -/* - * Generator context +/* + * Generator context */ struct testsuite_generator_context { @@ -90,8 +90,8 @@ extern const struct sieve_command_def tst_test_error; extern const struct sieve_command_def tst_test_result_action; extern const struct sieve_command_def tst_test_result_execute; -/* - * Operations +/* + * Operations */ enum testsuite_operation_code { @@ -142,8 +142,8 @@ extern const struct sieve_operation_def test_mailbox_delete_operation; extern const struct sieve_operation_def test_binary_load_operation; extern const struct sieve_operation_def test_binary_save_operation; -/* - * Operands +/* + * Operands */ extern const struct sieve_operand_def testsuite_object_operand; @@ -155,8 +155,8 @@ enum testsuite_operand_code { TESTSUITE_OPERAND_NAMESPACE }; -/* - * Test context +/* + * Test context */ void testsuite_test_start(string_t *name); @@ -172,11 +172,11 @@ bool testsuite_testcase_result(void); /* * Testsuite temporary directory */ - + const char *testsuite_tmp_dir_get(void); -/* - * Testsuite init/deinit +/* + * Testsuite init/deinit */ void testsuite_init diff --git a/src/testsuite/testsuite-log.c b/src/testsuite/testsuite-log.c index 58b861531566d7a6f6f6f929b91faeb9439159ad..a6da258cac059b4ec8ba3dc61d71e2278b62f1e3 100644 --- a/src/testsuite/testsuite-log.c +++ b/src/testsuite/testsuite-log.c @@ -18,7 +18,7 @@ bool _testsuite_log_stdout = FALSE; -/* +/* * Testsuite log error handlers */ @@ -65,7 +65,7 @@ static void ATTR_FORMAT(4, 0) _testsuite_log_verror msg.location = p_strdup(pool, location); msg.message = p_strdup_vprintf(pool, fmt, args); - array_append(&_testsuite_log_errors, &msg, 1); + array_append(&_testsuite_log_errors, &msg, 1); } static void ATTR_FORMAT(4, 0) _testsuite_log_main_verror @@ -74,10 +74,10 @@ static void ATTR_FORMAT(4, 0) _testsuite_log_main_verror va_list args) { if ( location == NULL || *location == '\0' ) - fprintf(stderr, + fprintf(stderr, "error: %s\n", t_strdup_vprintf(fmt, args)); else - fprintf(stderr, + fprintf(stderr, "%s: error: %s\n", location, t_strdup_vprintf(fmt, args)); } @@ -188,11 +188,11 @@ void testsuite_log_init(bool log_stdout) { _testsuite_log_stdout = log_stdout; - testsuite_log_ehandler = _testsuite_log_ehandler_create(); + testsuite_log_ehandler = _testsuite_log_ehandler_create(); sieve_error_handler_accept_infolog(testsuite_log_ehandler, TRUE); sieve_error_handler_accept_debuglog(testsuite_log_ehandler, TRUE); - testsuite_log_main_ehandler = _testsuite_log_main_ehandler_create(); + testsuite_log_main_ehandler = _testsuite_log_main_ehandler_create(); sieve_error_handler_accept_infolog(testsuite_log_main_ehandler, TRUE); sieve_error_handler_accept_debuglog(testsuite_log_main_ehandler, TRUE); @@ -232,7 +232,7 @@ struct sieve_stringlist *testsuite_log_stringlist_create (const struct sieve_runtime_env *renv, int index) { struct testsuite_log_stringlist *strlist; - + strlist = t_new(struct testsuite_log_stringlist, 1); strlist->strlist.runenv = renv; strlist->strlist.exec_status = SIEVE_EXEC_OK; @@ -241,14 +241,14 @@ struct sieve_stringlist *testsuite_log_stringlist_create strlist->index = index; strlist->pos = 0; - + return &strlist->strlist; } static int testsuite_log_stringlist_next_item (struct sieve_stringlist *_strlist, string_t **str_r) { - struct testsuite_log_stringlist *strlist = + struct testsuite_log_stringlist *strlist = (struct testsuite_log_stringlist *) _strlist; const struct _testsuite_log_message *msg; int pos; @@ -261,7 +261,7 @@ static int testsuite_log_stringlist_next_item if ( strlist->index > 0 ) { pos = strlist->index - 1; strlist->pos = -1; - } else { + } else { pos = strlist->pos++; } @@ -279,7 +279,7 @@ static int testsuite_log_stringlist_next_item static void testsuite_log_stringlist_reset (struct sieve_stringlist *_strlist) { - struct testsuite_log_stringlist *strlist = + struct testsuite_log_stringlist *strlist = (struct testsuite_log_stringlist *) _strlist; strlist->pos = 0; diff --git a/src/testsuite/testsuite-mailstore.c b/src/testsuite/testsuite-mailstore.c index 07557203cd5de402f9977ec7103ccbc69d63347a..d405b93c71ab8a37fc1c8cd6f6d74eef425c5dfd 100644 --- a/src/testsuite/testsuite-mailstore.c +++ b/src/testsuite/testsuite-mailstore.c @@ -11,10 +11,10 @@ #include "mail-namespace.h" #include "mail-storage.h" -#include "sieve-common.h" +#include "sieve-common.h" #include "sieve-error.h" #include "sieve-interpreter.h" - + #include "testsuite-message.h" #include "testsuite-common.h" #include "testsuite-smtp.h" @@ -46,13 +46,13 @@ static struct mail *testsuite_mailstore_mail = NULL; */ void testsuite_mailstore_init(void) -{ +{ testsuite_mailstore_tmp = i_strconcat (testsuite_tmp_dir_get(), "/mailstore", NULL); if ( mkdir(testsuite_mailstore_tmp, 0700) < 0 ) { - i_fatal("failed to create temporary directory '%s': %m.", - testsuite_mailstore_tmp); + i_fatal("failed to create temporary directory '%s': %m.", + testsuite_mailstore_tmp); } sieve_tool_init_mail_user @@ -67,8 +67,8 @@ void testsuite_mailstore_deinit(void) i_warning("failed to remove temporary directory '%s': %m.", testsuite_mailstore_tmp); } - - i_free(testsuite_mailstore_tmp); + + i_free(testsuite_mailstore_tmp); } void testsuite_mailstore_reset(void) @@ -105,7 +105,7 @@ static void testsuite_mailstore_close(void) if ( testsuite_mailstore_trans != NULL ) mailbox_transaction_rollback(&testsuite_mailstore_trans); - + if ( testsuite_mailstore_box != NULL ) mailbox_free(&testsuite_mailstore_box); @@ -124,9 +124,9 @@ static struct mail *testsuite_mailstore_open(const char *folder) if ( testsuite_mailstore_mail == NULL ) { testsuite_mailstore_close(); - } else if ( testsuite_mailstore_folder != NULL + } else if ( testsuite_mailstore_folder != NULL && strcmp(folder, testsuite_mailstore_folder) != 0 ) { - testsuite_mailstore_close(); + testsuite_mailstore_close(); } else { return testsuite_mailstore_mail; } @@ -136,9 +136,9 @@ static struct mail *testsuite_mailstore_open(const char *folder) sieve_sys_error(testsuite_sieve_instance, "testsuite: failed to open mailbox '%s'", folder); mailbox_free(&box); - return NULL; + return NULL; } - + /* Sync mailbox */ if ( mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0 ) { diff --git a/src/testsuite/testsuite-mailstore.h b/src/testsuite/testsuite-mailstore.h index 5d8a6b62cab901fc704b4bd3b404077bd17f49f1..fffe3219c54c00450e70e7ac54dd9ca407bdbe5c 100644 --- a/src/testsuite/testsuite-mailstore.h +++ b/src/testsuite/testsuite-mailstore.h @@ -7,7 +7,7 @@ #include "lib.h" #include "mail-storage.h" -#include "sieve-common.h" +#include "sieve-common.h" /* * Initialization @@ -26,7 +26,7 @@ bool testsuite_mailstore_mailbox_create (const struct sieve_runtime_env *renv ATTR_UNUSED, const char *folder); bool testsuite_mailstore_mail_index - (const struct sieve_runtime_env *renv, const char *folder, + (const struct sieve_runtime_env *renv, const char *folder, unsigned int index); #endif /* __TESTSUITE_MAILSTORE */ diff --git a/src/testsuite/testsuite-message.c b/src/testsuite/testsuite-message.c index c50b653bceaf9a21fe8c16a5762d4ad79374300d..e06bf7aa0f9660bd01c584942db4dc1275cd23e2 100644 --- a/src/testsuite/testsuite-message.c +++ b/src/testsuite/testsuite-message.c @@ -16,15 +16,15 @@ #include "testsuite-common.h" #include "testsuite-message.h" -/* - * Testsuite message environment +/* + * Testsuite message environment */ - + struct sieve_message_data testsuite_msgdata; static struct mail *testsuite_mail; -static const char *_default_message_data = +static const char *_default_message_data = "From: stephan@rename-it.nl\n" "To: sirius@drunksnipers.com\n" "Subject: Frop!\n" @@ -41,28 +41,28 @@ pool_t message_pool; static void testsuite_message_set_data(struct mail *mail) { const char *recipient = NULL, *sender = NULL; - - /* - * Collect necessary message data + + /* + * Collect necessary message data */ - - /* Get recipient address */ + + /* Get recipient address */ (void)mail_get_first_header(mail, "Envelope-To", &recipient); if ( recipient == NULL ) (void)mail_get_first_header(mail, "To", &recipient); - if ( recipient == NULL ) + if ( recipient == NULL ) recipient = "recipient@example.com"; - + /* Get sender address */ (void)mail_get_first_header(mail, "Return-path", &sender); - if ( sender == NULL ) + if ( sender == NULL ) (void)mail_get_first_header(mail, "Sender", &sender); - if ( sender == NULL ) + if ( sender == NULL ) (void)mail_get_first_header(mail, "From", &sender); - if ( sender == NULL ) + if ( sender == NULL ) sender = "sender@example.com"; - memset(&testsuite_msgdata, 0, sizeof(testsuite_msgdata)); + memset(&testsuite_msgdata, 0, sizeof(testsuite_msgdata)); testsuite_msgdata.mail = mail; testsuite_msgdata.auth_user = sieve_tool_get_username(sieve_tool); testsuite_msgdata.return_path = sender; @@ -73,7 +73,7 @@ static void testsuite_message_set_data(struct mail *mail) } void testsuite_message_init(void) -{ +{ message_pool = pool_alloconly_create("testsuite_message", 6096); string_t *default_message = str_new(message_pool, 1024); @@ -170,5 +170,5 @@ void testsuite_envelope_set_auth_user str_append(envelope_auth, value); testsuite_msgdata.auth_user = str_c(envelope_auth); -} - +} + diff --git a/src/testsuite/testsuite-objects.c b/src/testsuite/testsuite-objects.c index 797362fd046c4cc0fb3ebf6aa8e7be63b61beadc..589aa8713b1f4ac65e2b491aa9f08e46722e6c68 100644 --- a/src/testsuite/testsuite-objects.c +++ b/src/testsuite/testsuite-objects.c @@ -19,11 +19,11 @@ #include "testsuite-common.h" #include "testsuite-objects.h" #include "testsuite-message.h" - -/* + +/* * Testsuite core objects */ - + enum testsuite_object_code { TESTSUITE_OBJECT_MESSAGE, TESTSUITE_OBJECT_ENVELOPE @@ -36,31 +36,31 @@ const struct testsuite_object_def *testsuite_core_objects[] = { const unsigned int testsuite_core_objects_count = N_ELEMENTS(testsuite_core_objects); -/* +/* * Testsuite object registry */ static inline struct sieve_validator_object_registry *_get_object_registry (struct sieve_validator *valdtr) { - struct testsuite_validator_context *ctx = + struct testsuite_validator_context *ctx = testsuite_validator_context_get(valdtr); return ctx->object_registrations; } - + void testsuite_object_register (struct sieve_validator *valdtr, const struct sieve_extension *ext, - const struct testsuite_object_def *tobj_def) + const struct testsuite_object_def *tobj_def) { struct sieve_validator_object_registry *regs = _get_object_registry(valdtr); - + sieve_validator_object_registry_add(regs, ext, &tobj_def->obj_def); } static const struct testsuite_object *testsuite_object_create -(struct sieve_validator *valdtr, struct sieve_command *cmd, - const char *identifier) +(struct sieve_validator *valdtr, struct sieve_command *cmd, + const char *identifier) { struct sieve_validator_object_registry *regs = _get_object_registry(valdtr); struct sieve_object object; @@ -81,7 +81,7 @@ void testsuite_register_core_objects { struct sieve_validator_object_registry *regs = ctx->object_registrations; unsigned int i; - + /* Register core testsuite objects */ for ( i = 0; i < testsuite_core_objects_count; i++ ) { const struct testsuite_object_def *tobj_def = testsuite_core_objects[i]; @@ -90,21 +90,21 @@ void testsuite_register_core_objects (regs, testsuite_ext, &tobj_def->obj_def); } } - -/* + +/* * Testsuite object code - */ - -const struct sieve_operand_class sieve_testsuite_object_operand_class = + */ + +const struct sieve_operand_class sieve_testsuite_object_operand_class = { "testsuite object" }; static const struct sieve_extension_objects core_testsuite_objects = SIEVE_EXT_DEFINE_OBJECTS(testsuite_core_objects); -const struct sieve_operand_def testsuite_object_operand = { +const struct sieve_operand_def testsuite_object_operand = { "testsuite-object", - &testsuite_extension, - TESTSUITE_OPERAND_OBJECT, + &testsuite_extension, + TESTSUITE_OPERAND_OBJECT, &sieve_testsuite_object_operand_class, &core_testsuite_objects }; @@ -112,23 +112,23 @@ const struct sieve_operand_def testsuite_object_operand = { static void testsuite_object_emit (struct sieve_binary_block *sblock, const struct testsuite_object *tobj, int member_id) -{ +{ sieve_opr_object_emit(sblock, tobj->object.ext, tobj->object.def); - + if ( tobj->def != NULL && tobj->def->get_member_id != NULL ) { (void) sieve_binary_emit_byte(sblock, (unsigned char) member_id); } } bool testsuite_object_read -(struct sieve_binary_block *sblock, sieve_size_t *address, +(struct sieve_binary_block *sblock, sieve_size_t *address, struct testsuite_object *tobj) { struct sieve_operand oprnd; if ( !sieve_operand_read(sblock, address, NULL, &oprnd) ) return FALSE; - + if ( !sieve_opr_object_read_data (sblock, &oprnd, &sieve_testsuite_object_operand_class, address, &tobj->object) ) @@ -140,18 +140,18 @@ bool testsuite_object_read } bool testsuite_object_read_member -(struct sieve_binary_block *sblock, sieve_size_t *address, +(struct sieve_binary_block *sblock, sieve_size_t *address, struct testsuite_object *tobj, int *member_id_r) -{ +{ if ( !testsuite_object_read(sblock, address, tobj) ) return FALSE; - + *member_id_r = -1; if ( tobj->def != NULL && tobj->def->get_member_id != NULL ) { - if ( !sieve_binary_read_code(sblock, address, member_id_r) ) + if ( !sieve_binary_read_code(sblock, address, member_id_r) ) return FALSE; } - + return TRUE; } @@ -164,12 +164,12 @@ const char *testsuite_object_member_name if ( obj_def->get_member_id != NULL ) { if ( obj_def->get_member_name != NULL ) member = obj_def->get_member_name(member_id); - } else + } else return obj_def->obj_def.identifier; - - if ( member == NULL ) + + if ( member == NULL ) return t_strdup_printf("%s.%d", obj_def->obj_def.identifier, member_id); - + return t_strdup_printf("%s.%s", obj_def->obj_def.identifier, member); } @@ -180,32 +180,32 @@ bool testsuite_object_dump int member_id; sieve_code_mark(denv); - + if ( !testsuite_object_read_member (denv->sblock, address, &object, &member_id) ) return FALSE; - + sieve_code_dumpf(denv, "%s: %s", - sieve_testsuite_object_operand_class.name, + sieve_testsuite_object_operand_class.name, testsuite_object_member_name(&object, member_id)); - + return TRUE; } -/* +/* * Testsuite object argument */ - + static bool arg_testsuite_object_generate - (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, + (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *cmd); -const struct sieve_argument_def testsuite_object_argument = { - "testsuite-object", +const struct sieve_argument_def testsuite_object_argument = { + "testsuite-object", NULL, NULL, NULL, NULL, - arg_testsuite_object_generate + arg_testsuite_object_generate }; - + struct testsuite_object_argctx { const struct testsuite_object *object; int member; @@ -213,72 +213,72 @@ struct testsuite_object_argctx { bool testsuite_object_argument_activate (struct sieve_validator *valdtr, struct sieve_ast_argument *arg, - struct sieve_command *cmd) + struct sieve_command *cmd) { const char *objname = sieve_ast_argument_strc(arg); const struct testsuite_object *tobj; int member_id; const char *member; struct testsuite_object_argctx *ctx; - + /* Parse the object specifier */ - + member = strchr(objname, '.'); if ( member != NULL ) { objname = t_strdup_until(objname, member); member++; } - + /* Find the object */ - + tobj = testsuite_object_create(valdtr, cmd, objname); if ( tobj == NULL ) { - sieve_argument_validate_error(valdtr, arg, + sieve_argument_validate_error(valdtr, arg, "unknown testsuite object '%s'", objname); return FALSE; } - + /* Find the object member */ - + member_id = -1; if ( member != NULL ) { - if ( tobj->def == NULL || tobj->def->get_member_id == NULL || + if ( tobj->def == NULL || tobj->def->get_member_id == NULL || (member_id=tobj->def->get_member_id(member)) == -1 ) { - sieve_argument_validate_error(valdtr, arg, + sieve_argument_validate_error(valdtr, arg, "member '%s' does not exist for testsuite object '%s'", member, objname); return FALSE; } } - + /* Assign argument context */ - + ctx = p_new(sieve_command_pool(cmd), struct testsuite_object_argctx, 1); ctx->object = tobj; ctx->member = member_id; - + arg->argument = sieve_argument_create (arg->ast, &testsuite_object_argument, testsuite_ext, 0); arg->argument->data = (void *) ctx; - + return TRUE; } static bool arg_testsuite_object_generate - (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, + (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *cmd ATTR_UNUSED) { - struct testsuite_object_argctx *ctx = + struct testsuite_object_argctx *ctx = (struct testsuite_object_argctx *) arg->argument->data; - + testsuite_object_emit(cgenv->sblock, ctx->object, ctx->member); - + return TRUE; } -/* +/* * Testsuite core object implementation */ - + static bool tsto_message_set_member (const struct sieve_runtime_env *renv, int id, string_t *value); @@ -287,18 +287,18 @@ static const char *tsto_envelope_get_member_name(int id); static bool tsto_envelope_set_member (const struct sieve_runtime_env *renv, int id, string_t *value); -const struct testsuite_object_def message_testsuite_object = { +const struct testsuite_object_def message_testsuite_object = { SIEVE_OBJECT("message", &testsuite_object_operand, TESTSUITE_OBJECT_MESSAGE), - NULL, NULL, - tsto_message_set_member, + NULL, NULL, + tsto_message_set_member, NULL }; -const struct testsuite_object_def envelope_testsuite_object = { +const struct testsuite_object_def envelope_testsuite_object = { SIEVE_OBJECT("envelope", &testsuite_object_operand, TESTSUITE_OBJECT_ENVELOPE), - tsto_envelope_get_member_id, + tsto_envelope_get_member_id, tsto_envelope_get_member_name, - tsto_envelope_set_member, + tsto_envelope_set_member, NULL }; @@ -310,12 +310,12 @@ enum testsuite_object_envelope_field { }; static bool tsto_message_set_member -(const struct sieve_runtime_env *renv, int id, string_t *value) +(const struct sieve_runtime_env *renv, int id, string_t *value) { if ( id != -1 ) return FALSE; - + testsuite_message_set_string(renv, value); - + return TRUE; } @@ -328,24 +328,24 @@ static int tsto_envelope_get_member_id(const char *identifier) if ( strcasecmp(identifier, "orig_to") == 0 ) return TESTSUITE_OBJECT_ENVELOPE_ORIG_TO; if ( strcasecmp(identifier, "auth") == 0 ) - return TESTSUITE_OBJECT_ENVELOPE_AUTH_USER; - + return TESTSUITE_OBJECT_ENVELOPE_AUTH_USER; + return -1; } -static const char *tsto_envelope_get_member_name(int id) +static const char *tsto_envelope_get_member_name(int id) { switch ( id ) { - case TESTSUITE_OBJECT_ENVELOPE_FROM: + case TESTSUITE_OBJECT_ENVELOPE_FROM: return "from"; - case TESTSUITE_OBJECT_ENVELOPE_TO: + case TESTSUITE_OBJECT_ENVELOPE_TO: return "to"; - case TESTSUITE_OBJECT_ENVELOPE_ORIG_TO: + case TESTSUITE_OBJECT_ENVELOPE_ORIG_TO: return "orig_to"; - case TESTSUITE_OBJECT_ENVELOPE_AUTH_USER: + case TESTSUITE_OBJECT_ENVELOPE_AUTH_USER: return "auth"; } - + return NULL; } @@ -353,7 +353,7 @@ static bool tsto_envelope_set_member (const struct sieve_runtime_env *renv, int id, string_t *value) { switch ( id ) { - case TESTSUITE_OBJECT_ENVELOPE_FROM: + case TESTSUITE_OBJECT_ENVELOPE_FROM: testsuite_envelope_set_sender(renv, str_c(value)); return TRUE; case TESTSUITE_OBJECT_ENVELOPE_TO: @@ -362,10 +362,10 @@ static bool tsto_envelope_set_member case TESTSUITE_OBJECT_ENVELOPE_ORIG_TO: testsuite_envelope_set_orig_recipient(renv, str_c(value)); return TRUE; - case TESTSUITE_OBJECT_ENVELOPE_AUTH_USER: + case TESTSUITE_OBJECT_ENVELOPE_AUTH_USER: testsuite_envelope_set_auth_user(renv, str_c(value)); return TRUE; } - + return FALSE; } diff --git a/src/testsuite/testsuite-objects.h b/src/testsuite/testsuite-objects.h index 1c276d588631cda8027e7ed48b8a3315897320cc..ef521966bf258c315bbea3eca8baa75b9a2871d5 100644 --- a/src/testsuite/testsuite-objects.h +++ b/src/testsuite/testsuite-objects.h @@ -9,8 +9,8 @@ #include "testsuite-common.h" -/* - * Testsuite object operand +/* + * Testsuite object operand */ struct testsuite_object_operand_interface { @@ -19,13 +19,13 @@ struct testsuite_object_operand_interface { extern const struct sieve_operand_class testsuite_object_oprclass; -/* - * Testsuite object access +/* + * Testsuite object access */ struct testsuite_object_def { struct sieve_object_def obj_def; - + int (*get_member_id)(const char *identifier); const char *(*get_member_name)(int id); @@ -41,30 +41,30 @@ struct testsuite_object { const struct testsuite_object_def *def; }; -/* - * Testsuite object registration +/* + * Testsuite object registration */ void testsuite_register_core_objects (struct testsuite_validator_context *ctx); void testsuite_object_register (struct sieve_validator *valdtr, const struct sieve_extension *ext, - const struct testsuite_object_def *tobj_def); - -/* - * Testsuite object argument - */ - + const struct testsuite_object_def *tobj_def); + +/* + * Testsuite object argument + */ + bool testsuite_object_argument_activate (struct sieve_validator *valdtr, struct sieve_ast_argument *arg, - struct sieve_command *cmd); - -/* - * Testsuite object code + struct sieve_command *cmd); + +/* + * Testsuite object code */ bool testsuite_object_read - (struct sieve_binary_block *sblock, sieve_size_t *address, + (struct sieve_binary_block *sblock, sieve_size_t *address, struct testsuite_object *tobj); bool testsuite_object_read_member (struct sieve_binary_block *sblock, sieve_size_t *address, @@ -76,8 +76,8 @@ bool testsuite_object_dump const char *testsuite_object_member_name (const struct testsuite_object *object, int member_id); -/* - * Testsuite core objects +/* + * Testsuite core objects */ extern const struct testsuite_object_def message_testsuite_object; diff --git a/src/testsuite/testsuite-result.c b/src/testsuite/testsuite-result.c index 7156c7a6a238dc7a40a278e11377c2056fa349c5..4dfb84a2953322daa30ddb888490e3a25d1e45e9 100644 --- a/src/testsuite/testsuite-result.c +++ b/src/testsuite/testsuite-result.c @@ -74,9 +74,9 @@ bool testsuite_result_execute(const struct sieve_runtime_env *renv) testsuite_log_clear_messages(); - /* Execute the result */ + /* Execute the result */ ret=sieve_result_execute(_testsuite_result, NULL); - + return ( ret > 0 ); } @@ -84,14 +84,14 @@ void testsuite_result_print (const struct sieve_runtime_env *renv) { struct ostream *out; - - out = o_stream_create_fd(1, 0, FALSE); + + out = o_stream_create_fd(1, 0, FALSE); o_stream_send_str(out, "\n--"); sieve_result_print(_testsuite_result, renv->scriptenv, out, NULL); o_stream_send_str(out, "--\n\n"); - o_stream_destroy(&out); + o_stream_destroy(&out); } /* @@ -118,7 +118,7 @@ struct sieve_stringlist *testsuite_result_stringlist_create (const struct sieve_runtime_env *renv, int index) { struct testsuite_result_stringlist *strlist; - + strlist = t_new(struct testsuite_result_stringlist, 1); strlist->strlist.runenv = renv; strlist->strlist.exec_status = SIEVE_EXEC_OK; @@ -128,14 +128,14 @@ struct sieve_stringlist *testsuite_result_stringlist_create strlist->result_iter = testsuite_result_iterate_init(); strlist->index = index; strlist->pos = 0; - + return &strlist->strlist; } static int testsuite_result_stringlist_next_item (struct sieve_stringlist *_strlist, string_t **str_r) { - struct testsuite_result_stringlist *strlist = + struct testsuite_result_stringlist *strlist = (struct testsuite_result_stringlist *) _strlist; const struct sieve_action *action; const char *act_name; @@ -146,15 +146,15 @@ static int testsuite_result_stringlist_next_item if ( strlist->index > 0 && strlist->pos > 0 ) return 0; - do { + do { if ( (action=sieve_result_iterate_next(strlist->result_iter, &keep)) == NULL ) return 0; - + strlist->pos++; } while ( strlist->pos < strlist->index ); - - if ( keep ) + + if ( keep ) act_name = "keep"; else act_name = ( action == NULL || action->def == NULL || @@ -167,7 +167,7 @@ static int testsuite_result_stringlist_next_item static void testsuite_result_stringlist_reset (struct sieve_stringlist *_strlist) { - struct testsuite_result_stringlist *strlist = + struct testsuite_result_stringlist *strlist = (struct testsuite_result_stringlist *) _strlist; strlist->result_iter = testsuite_result_iterate_init(); diff --git a/src/testsuite/testsuite-result.h b/src/testsuite/testsuite-result.h index 9a54307c0c6284017147a28f0b24d10f60ab6a2d..655b733bad1bf774780120e9331c7effc4846729 100644 --- a/src/testsuite/testsuite-result.h +++ b/src/testsuite/testsuite-result.h @@ -7,7 +7,7 @@ void testsuite_result_init(void); void testsuite_result_deinit(void); -void testsuite_result_reset +void testsuite_result_reset (const struct sieve_runtime_env *renv); struct sieve_result *testsuite_result_get(void); diff --git a/src/testsuite/testsuite-script.c b/src/testsuite/testsuite-script.c index 589b02adb20a2aac80993af217feabfecae78a01..d76608a1d7bb185d00ceced4c2bab5675505a1ae 100644 --- a/src/testsuite/testsuite-script.c +++ b/src/testsuite/testsuite-script.c @@ -186,7 +186,7 @@ bool testsuite_script_multiscript scriptenv.duplicate_mark = NULL; scriptenv.duplicate_check = NULL; scriptenv.user = renv->scriptenv->user; - scriptenv.trace_stream = renv->scriptenv->trace_stream; + scriptenv.trace_stream = renv->scriptenv->trace_stream; scriptenv.trace_config = renv->scriptenv->trace_config; /* Start execution */ diff --git a/src/testsuite/testsuite-script.h b/src/testsuite/testsuite-script.h index 669c89335759cbf80fd5bf71bdfd7f11b3944ed2..a0b6757122ca977bdbd058630d55991ac16251fd 100644 --- a/src/testsuite/testsuite-script.h +++ b/src/testsuite/testsuite-script.h @@ -16,7 +16,7 @@ bool testsuite_script_compile bool testsuite_script_run (const struct sieve_runtime_env *renv); bool testsuite_script_multiscript - (const struct sieve_runtime_env *renv, + (const struct sieve_runtime_env *renv, ARRAY_TYPE (const_string) *scriptfiles); struct sieve_binary *testsuite_script_get_binary(const struct sieve_runtime_env *renv); diff --git a/src/testsuite/testsuite-settings.c b/src/testsuite/testsuite-settings.c index 7301583b9a18cf5b1cde9115748032fc2a054c30..0dae3e133ab52dbcb8b75dd0373230ff4ae6b2da 100644 --- a/src/testsuite/testsuite-settings.c +++ b/src/testsuite/testsuite-settings.c @@ -16,7 +16,7 @@ struct testsuite_setting { char *value; }; -static struct hash_table *settings; +static struct hash_table *settings; static const char *testsuite_setting_get (void *context, const char *identifier); @@ -31,11 +31,11 @@ void testsuite_settings_init(void) void testsuite_settings_deinit(void) { - struct hash_iterate_context *itx = + struct hash_iterate_context *itx = hash_table_iterate_init(settings); - void *key; + void *key; void *value; - + while ( hash_table_iterate(itx, &key, &value) ) { struct testsuite_setting *setting = (struct testsuite_setting *) value; @@ -44,7 +44,7 @@ void testsuite_settings_deinit(void) i_free(setting); } - hash_table_iterate_deinit(&itx); + hash_table_iterate_deinit(&itx); hash_table_destroy(&settings); } @@ -52,7 +52,7 @@ void testsuite_settings_deinit(void) static const char *testsuite_setting_get (void *context ATTR_UNUSED, const char *identifier) { - struct testsuite_setting *setting = (struct testsuite_setting *) + struct testsuite_setting *setting = (struct testsuite_setting *) hash_table_lookup(settings, identifier); if ( setting == NULL ) { @@ -64,7 +64,7 @@ static const char *testsuite_setting_get void testsuite_setting_set(const char *identifier, const char *value) { - struct testsuite_setting *setting = (struct testsuite_setting *) + struct testsuite_setting *setting = (struct testsuite_setting *) hash_table_lookup(settings, identifier); if ( setting != NULL ) { @@ -74,14 +74,14 @@ void testsuite_setting_set(const char *identifier, const char *value) setting = i_new(struct testsuite_setting, 1); setting->identifier = i_strdup(identifier); setting->value = i_strdup(value); - + hash_table_insert(settings, (void *) identifier, (void *) setting); } } void testsuite_setting_unset(const char *identifier) { - struct testsuite_setting *setting = (struct testsuite_setting *) + struct testsuite_setting *setting = (struct testsuite_setting *) hash_table_lookup(settings, identifier); if ( setting != NULL ) { diff --git a/src/testsuite/testsuite-smtp.c b/src/testsuite/testsuite-smtp.c index 4e4dd296f14cbaec5baa394a73b1a0810c81d1e4..3d96b178e7317fede0cc3f2399d4a86478fdda64 100644 --- a/src/testsuite/testsuite-smtp.c +++ b/src/testsuite/testsuite-smtp.c @@ -5,10 +5,10 @@ #include "array.h" #include "unlink-directory.h" -#include "sieve-common.h" +#include "sieve-common.h" #include "sieve-error.h" #include "sieve-interpreter.h" - + #include "testsuite-message.h" #include "testsuite-common.h" #include "testsuite-smtp.h" @@ -33,17 +33,17 @@ static ARRAY_DEFINE(testsuite_smtp_messages, struct testsuite_smtp_message); void testsuite_smtp_init(void) { pool_t pool; - - testsuite_smtp_pool = pool = pool_alloconly_create("testsuite_smtp", 8192); - + + testsuite_smtp_pool = pool = pool_alloconly_create("testsuite_smtp", 8192); + testsuite_smtp_tmp = p_strconcat (pool, testsuite_tmp_dir_get(), "/smtp", NULL); if ( mkdir(testsuite_smtp_tmp, 0700) < 0 ) { - i_fatal("failed to create temporary directory '%s': %m.", - testsuite_smtp_tmp); + i_fatal("failed to create temporary directory '%s': %m.", + testsuite_smtp_tmp); } - + p_array_init(&testsuite_smtp_messages, pool, 16); } @@ -52,8 +52,8 @@ void testsuite_smtp_deinit(void) if ( unlink_directory(testsuite_smtp_tmp, TRUE) < 0 ) i_warning("failed to remove temporary directory '%s': %m.", testsuite_smtp_tmp); - - pool_unref(&testsuite_smtp_pool); + + pool_unref(&testsuite_smtp_pool); } void testsuite_smtp_reset(void) @@ -65,28 +65,28 @@ void testsuite_smtp_reset(void) /* * Simulated SMTP out */ - + struct testsuite_smtp { const char *tmp_path; FILE *mfile; }; - + void *testsuite_smtp_open -(const struct sieve_script_env *senv ATTR_UNUSED, const char *destination, +(const struct sieve_script_env *senv ATTR_UNUSED, const char *destination, const char *return_path, FILE **file_r) -{ +{ struct testsuite_smtp_message smtp_msg; struct testsuite_smtp *smtp; unsigned int smtp_count = array_count(&testsuite_smtp_messages); - - smtp_msg.file = p_strdup_printf(testsuite_smtp_pool, + + smtp_msg.file = p_strdup_printf(testsuite_smtp_pool, "%s/%d.eml", testsuite_smtp_tmp, smtp_count); - smtp_msg.envelope_from = + smtp_msg.envelope_from = ( return_path != NULL ? p_strdup(testsuite_smtp_pool, return_path) : NULL ); smtp_msg.envelope_to = p_strdup(testsuite_smtp_pool, destination); - + array_append(&testsuite_smtp_messages, &smtp_msg, 1); - + smtp = t_new(struct testsuite_smtp, 1); smtp->tmp_path = smtp_msg.file; smtp->mfile = fopen(smtp->tmp_path, "w"); @@ -95,8 +95,8 @@ void *testsuite_smtp_open i_fatal("failed to open tmp file for SMTP simulation."); *file_r = smtp->mfile; - - return (void *) smtp; + + return (void *) smtp; } bool testsuite_smtp_close @@ -105,7 +105,7 @@ bool testsuite_smtp_close struct testsuite_smtp *smtp = (struct testsuite_smtp *) handle; fclose(smtp->mfile); - + return TRUE; } diff --git a/src/testsuite/testsuite-smtp.h b/src/testsuite/testsuite-smtp.h index 4d785d037da7b5698ddbf731a8c243bd1856702a..66e4e9bc72aae46cc2159adf9d7ede942c7e1e23 100644 --- a/src/testsuite/testsuite-smtp.h +++ b/src/testsuite/testsuite-smtp.h @@ -1,9 +1,9 @@ /* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file */ - + #ifndef __TESTSUITE_SMTP_H #define __TESTSUITE_SMTP_H - + void testsuite_smtp_init(void); void testsuite_smtp_deinit(void); void testsuite_smtp_reset(void); @@ -11,7 +11,7 @@ void testsuite_smtp_reset(void); /* * Simulated SMTP out */ - + void *testsuite_smtp_open (const struct sieve_script_env *senv, const char *destination, const char *return_path, FILE **file_r); diff --git a/src/testsuite/testsuite-substitutions.c b/src/testsuite/testsuite-substitutions.c index 47141cf359584e9606108eb15027a831637fec5a..a332bc443927d93dc55d7eaf6de49e15292322df 100644 --- a/src/testsuite/testsuite-substitutions.c +++ b/src/testsuite/testsuite-substitutions.c @@ -17,15 +17,15 @@ /* * Forward declarations */ - + void testsuite_opr_substitution_emit (struct sieve_binary_block *sblock, const struct testsuite_substitution *tsub, const char *param); - + /* * Testsuite substitutions */ - + /* FIXME: make this extendible */ enum { @@ -39,22 +39,22 @@ static const struct testsuite_substitution_def *substitutions[] = { }; static const unsigned int substitutions_count = N_ELEMENTS(substitutions); - + static inline const struct testsuite_substitution_def * testsuite_substitution_get (unsigned int code) { if ( code > substitutions_count ) return NULL; - + return substitutions[code]; } static const struct testsuite_substitution *testsuite_substitution_create (struct sieve_ast *ast, const char *identifier) { - unsigned int i; - + unsigned int i; + for ( i = 0; i < substitutions_count; i++ ) { if ( strcasecmp(substitutions[i]->obj_def.identifier, identifier) == 0 ) { const struct testsuite_substitution_def *tsub_def = substitutions[i]; @@ -63,21 +63,21 @@ static const struct testsuite_substitution *testsuite_substitution_create tsub = p_new(sieve_ast_pool(ast), struct testsuite_substitution, 1); tsub->object.def = &tsub_def->obj_def; tsub->object.ext = testsuite_ext; - tsub->def = tsub_def; - + tsub->def = tsub_def; + return tsub; } } - + return NULL; } /* * Substitution argument */ - + static bool arg_testsuite_substitution_generate - (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, + (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *context); struct _testsuite_substitution_context { @@ -85,25 +85,25 @@ struct _testsuite_substitution_context { const char *param; }; -const struct sieve_argument_def testsuite_substitution_argument = { - "@testsuite-substitution", +const struct sieve_argument_def testsuite_substitution_argument = { + "@testsuite-substitution", NULL, NULL, NULL, NULL, - arg_testsuite_substitution_generate + arg_testsuite_substitution_generate }; struct sieve_ast_argument *testsuite_substitution_argument_create -(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_ast *ast, +(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_ast *ast, unsigned int source_line, const char *substitution, const char *param) { const struct testsuite_substitution *tsub; struct _testsuite_substitution_context *tsctx; struct sieve_ast_argument *arg; pool_t pool; - + tsub = testsuite_substitution_create(ast, substitution); - if ( tsub == NULL ) + if ( tsub == NULL ) return NULL; - + arg = sieve_ast_argument_create(ast, source_line); arg->type = SAAT_STRING; @@ -120,12 +120,12 @@ struct sieve_ast_argument *testsuite_substitution_argument_create } static bool arg_testsuite_substitution_generate -(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, +(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, struct sieve_command *context ATTR_UNUSED) { - struct _testsuite_substitution_context *tsctx = + struct _testsuite_substitution_context *tsctx = (struct _testsuite_substitution_context *) arg->argument->data; - + testsuite_opr_substitution_emit(cgenv->sblock, tsctx->tsub, tsctx->param); return TRUE; @@ -139,17 +139,17 @@ static bool opr_substitution_dump (const struct sieve_dumptime_env *denv, const struct sieve_operand *oprnd, sieve_size_t *address); static int opr_substitution_read_value - (const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd, + (const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd, sieve_size_t *address, string_t **str); - -const struct sieve_opr_string_interface testsuite_substitution_interface = { + +const struct sieve_opr_string_interface testsuite_substitution_interface = { opr_substitution_dump, opr_substitution_read_value }; - -const struct sieve_operand_def testsuite_substitution_operand = { - "test-substitution", - &testsuite_extension, + +const struct sieve_operand_def testsuite_substitution_operand = { + "test-substitution", + &testsuite_extension, TESTSUITE_OPERAND_SUBSTITUTION, &string_class, &testsuite_substitution_interface @@ -157,7 +157,7 @@ const struct sieve_operand_def testsuite_substitution_operand = { void testsuite_opr_substitution_emit (struct sieve_binary_block *sblock, const struct testsuite_substitution *tsub, - const char *param) + const char *param) { /* Default variable storage */ (void) sieve_operand_emit @@ -167,78 +167,78 @@ void testsuite_opr_substitution_emit } static bool opr_substitution_dump -(const struct sieve_dumptime_env *denv, const struct sieve_operand *oprnd, - sieve_size_t *address) +(const struct sieve_dumptime_env *denv, const struct sieve_operand *oprnd, + sieve_size_t *address) { unsigned int code = 0; const struct testsuite_substitution_def *tsub; - string_t *param; + string_t *param; if ( !sieve_binary_read_unsigned(denv->sblock, address, &code) ) return FALSE; - + tsub = testsuite_substitution_get(code); if ( tsub == NULL ) - return FALSE; - + return FALSE; + if ( !sieve_binary_read_string(denv->sblock, address, ¶m) ) return FALSE; - - if ( oprnd->field_name != NULL ) - sieve_code_dumpf(denv, "%s: TEST_SUBS %%{%s:%s}", + + if ( oprnd->field_name != NULL ) + sieve_code_dumpf(denv, "%s: TEST_SUBS %%{%s:%s}", oprnd->field_name, tsub->obj_def.identifier, str_c(param)); else - sieve_code_dumpf(denv, "TEST_SUBS %%{%s:%s}", + sieve_code_dumpf(denv, "TEST_SUBS %%{%s:%s}", tsub->obj_def.identifier, str_c(param)); return TRUE; } static int opr_substitution_read_value -(const struct sieve_runtime_env *renv, - const struct sieve_operand *oprnd ATTR_UNUSED, sieve_size_t *address, +(const struct sieve_runtime_env *renv, + const struct sieve_operand *oprnd ATTR_UNUSED, sieve_size_t *address, string_t **str_r) -{ +{ const struct testsuite_substitution_def *tsub; unsigned int code = 0; string_t *param; - + if ( !sieve_binary_read_unsigned(renv->sblock, address, &code) ) return SIEVE_EXEC_BIN_CORRUPT; - + tsub = testsuite_substitution_get(code); if ( tsub == NULL ) - return SIEVE_EXEC_FAILURE; + return SIEVE_EXEC_FAILURE; - /* Parameter str can be NULL if we are requested to only skip and not + /* Parameter str can be NULL if we are requested to only skip and not * actually read the argument. - */ + */ if ( str_r == NULL ) { if ( !sieve_binary_read_string(renv->sblock, address, NULL) ) return SIEVE_EXEC_BIN_CORRUPT; - + return SIEVE_EXEC_OK; } - + if ( !sieve_binary_read_string(renv->sblock, address, ¶m) ) return SIEVE_EXEC_BIN_CORRUPT; - + if ( !tsub->get_value(str_c(param), str_r) ) return SIEVE_EXEC_FAILURE; - + return SIEVE_EXEC_OK; } /* * Testsuite substitution definitions */ - + static bool testsuite_file_substitution_get_value - (const char *param, string_t **result); - + (const char *param, string_t **result); + static const struct testsuite_substitution_def testsuite_file_substitution = { SIEVE_OBJECT( - "file", - &testsuite_substitution_operand, + "file", + &testsuite_substitution_operand, TESTSUITE_SUBSTITUTION_FILE ), testsuite_file_substitution_get_value diff --git a/src/testsuite/testsuite-substitutions.h b/src/testsuite/testsuite-substitutions.h index ce0f9c3d99a755f3db6dcba00dbb746671ecff2a..79d15ad05cf543ec59e8705c43906be695de1486 100644 --- a/src/testsuite/testsuite-substitutions.h +++ b/src/testsuite/testsuite-substitutions.h @@ -9,7 +9,7 @@ struct testsuite_substitution_def { struct sieve_object_def obj_def; - + bool (*get_value)(const char *param, string_t **result); }; @@ -20,7 +20,7 @@ struct testsuite_substitution { }; struct sieve_ast_argument *testsuite_substitution_argument_create - (struct sieve_validator *valdtr, struct sieve_ast *ast, + (struct sieve_validator *valdtr, struct sieve_ast *ast, unsigned int source_line, const char *substitution, const char *param); #endif /* __TESTSUITE_SUBSTITUTIONS_H */ diff --git a/src/testsuite/testsuite-variables.c b/src/testsuite/testsuite-variables.c index 6f74a05604b913f5370cab31f48d939e0569262e..3c2dcc49d6675a6cbca548632ffa587762a9d1d5 100644 --- a/src/testsuite/testsuite-variables.c +++ b/src/testsuite/testsuite-variables.c @@ -39,7 +39,7 @@ bool testsuite_varnamespace_generate struct sieve_ast_argument *arg, struct sieve_command *cmd, void *var_data); bool testsuite_varnamespace_dump_variable (const struct sieve_dumptime_env *denv, - const struct sieve_variables_namespace *nspc, + const struct sieve_variables_namespace *nspc, const struct sieve_operand *oprnd, sieve_size_t *address); int testsuite_varnamespace_read_variable (const struct sieve_runtime_env *renv, @@ -55,7 +55,7 @@ static const struct sieve_variables_namespace_def testsuite_namespace = { }; bool testsuite_varnamespace_validate -(struct sieve_validator *valdtr, +(struct sieve_validator *valdtr, const struct sieve_variables_namespace *nspc ATTR_UNUSED, struct sieve_ast_argument *arg, struct sieve_command *cmd ATTR_UNUSED, ARRAY_TYPE(sieve_variable_name) *var_name, void **var_data, diff --git a/src/testsuite/testsuite-variables.h b/src/testsuite/testsuite-variables.h index 7f299778758413aacf07e8833e2a1b3413ccba7a..429d3c6d8fac9659d2ce744ff8719d54bfe3b3cc 100644 --- a/src/testsuite/testsuite-variables.h +++ b/src/testsuite/testsuite-variables.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2002-2010 Sieve Extdata plugin authors, see the included COPYING file +/* Copyright (c) 2002-2010 Sieve Extdata plugin authors, see the included COPYING file */ #ifndef __TESTSUITE_VARIABLES_H diff --git a/src/testsuite/testsuite.c b/src/testsuite/testsuite.c index dfd5a1a65bbc37bbbb5fddd8bcdff55a56c59d92..dd9be67bf27caef0f3778718b569e1bc36e731af 100644 --- a/src/testsuite/testsuite.c +++ b/src/testsuite/testsuite.c @@ -57,7 +57,7 @@ static void print_help(void) } static int testsuite_run -(struct sieve_binary *sbin, const struct sieve_message_data *msgdata, +(struct sieve_binary *sbin, const struct sieve_message_data *msgdata, const struct sieve_script_env *senv, struct sieve_error_handler *ehandler) { struct sieve_interpreter *interp; @@ -81,7 +81,7 @@ static int testsuite_run return ret; } -int main(int argc, char **argv) +int main(int argc, char **argv) { struct sieve_instance *svinst; const char *scriptfile, *dumpfile, *tracefile; @@ -128,7 +128,7 @@ int main(int argc, char **argv) print_help(); i_fatal_status(EX_USAGE, "Missing <scriptfile> argument"); } - + if (optind != argc) { print_help(); i_fatal_status(EX_USAGE, "Unknown argument: %s", argv[optind]); @@ -136,7 +136,7 @@ int main(int argc, char **argv) /* Initialize mail user */ sieve_tool_set_homedir(sieve_tool, t_abspath("")); - + /* Initialize settings environment */ testsuite_settings_init(); @@ -154,7 +154,7 @@ int main(int argc, char **argv) ("sieve_global_dir", t_strconcat(sieve_dir, "included-global", NULL)); /* Finish testsuite initialization */ - svinst = sieve_tool_init_finish(sieve_tool, FALSE); + svinst = sieve_tool_init_finish(sieve_tool, FALSE); testsuite_init(svinst, sieve_dir, log_stdout); printf("Test case: %s:\n\n", scriptfile); diff --git a/src/testsuite/tst-test-error.c b/src/testsuite/tst-test-error.c index 1d4c577b8bbbb996c270eaa4e9e7c7bb8e5a309a..7c88b8fd5ce281a601332ddba55f110e6785e999 100644 --- a/src/testsuite/tst-test-error.c +++ b/src/testsuite/tst-test-error.c @@ -21,7 +21,7 @@ /* * Test_error command * - * Syntax: + * Syntax: * test [MATCH-TYPE] [COMPARATOR] [:index number] <key-list: string-list> */ @@ -33,20 +33,20 @@ static bool tst_test_error_validate static bool tst_test_error_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx); -const struct sieve_command_def tst_test_error = { - "test_error", - SCT_TEST, +const struct sieve_command_def tst_test_error = { + "test_error", + SCT_TEST, 1, 0, FALSE, FALSE, - tst_test_error_registered, + tst_test_error_registered, NULL, tst_test_error_validate, - NULL, - tst_test_error_generate, - NULL + NULL, + tst_test_error_generate, + NULL }; -/* - * Operation +/* + * Operation */ static bool tst_test_error_operation_dump @@ -54,19 +54,19 @@ static bool tst_test_error_operation_dump static int tst_test_error_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def test_error_operation = { +const struct sieve_operation_def test_error_operation = { "TEST_ERROR", - &testsuite_extension, + &testsuite_extension, TESTSUITE_OPERATION_TEST_ERROR, - tst_test_error_operation_dump, - tst_test_error_operation_execute + tst_test_error_operation_dump, + tst_test_error_operation_execute }; /* * Tagged arguments - */ + */ -/* NOTE: This will be merged with the date-index extension when it is +/* NOTE: This will be merged with the date-index extension when it is * implemented. */ @@ -76,7 +76,7 @@ static bool tst_test_error_validate_index_tag static const struct sieve_argument_def test_error_index_tag = { "index", - NULL, + NULL, tst_test_error_validate_index_tag, NULL, NULL, NULL }; @@ -131,17 +131,17 @@ static bool tst_test_error_registered return TRUE; } -/* - * Validation +/* + * Validation */ static bool tst_test_error_validate -(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *tst) +(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *tst) { struct sieve_ast_argument *arg = tst->first_positional; - struct sieve_comparator cmp_default = + struct sieve_comparator cmp_default = SIEVE_COMPARATOR_DEFAULT(i_octet_comparator); - struct sieve_match_type mcht_default = + struct sieve_match_type mcht_default = SIEVE_COMPARATOR_DEFAULT(is_match_type); if ( !sieve_validate_positional_argument @@ -157,8 +157,8 @@ static bool tst_test_error_validate (valdtr, tst, arg, &mcht_default, &cmp_default); } -/* - * Code generation +/* + * Code generation */ static bool tst_test_error_generate @@ -170,10 +170,10 @@ static bool tst_test_error_generate return sieve_generate_arguments(cgenv, tst, NULL); } -/* +/* * Code dump */ - + static bool tst_test_error_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) { @@ -186,7 +186,7 @@ static bool tst_test_error_operation_dump for (;;) { int opt; - if ( (opt=sieve_match_opr_optional_dump(denv, address, &opt_code)) + if ( (opt=sieve_match_opr_optional_dump(denv, address, &opt_code)) < 0 ) return FALSE; @@ -198,7 +198,7 @@ static bool tst_test_error_operation_dump } else { return FALSE; } - } + } return sieve_opr_stringlist_dump(denv, address, "key list"); } @@ -209,7 +209,7 @@ static bool tst_test_error_operation_dump static int tst_test_error_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) -{ +{ int opt_code = 0; struct sieve_comparator cmp = SIEVE_COMPARATOR_DEFAULT(i_octet_comparator); struct sieve_match_type mcht = SIEVE_COMPARATOR_DEFAULT(is_match_type); @@ -223,7 +223,7 @@ static int tst_test_error_operation_execute /* Read optional operands */ for (;;) { - sieve_number_t number; + sieve_number_t number; int opt; if ( (opt=sieve_match_opr_optional_read @@ -231,7 +231,7 @@ static int tst_test_error_operation_execute return ret; if ( opt == 0 ) break; - + if ( opt_code == OPT_INDEX ) { if ( (ret=sieve_opr_number_read(renv, address, "index", &number)) <= 0 ) return ret; @@ -239,7 +239,7 @@ static int tst_test_error_operation_execute } else { sieve_runtime_trace_error(renv, "invalid optional operand"); return SIEVE_EXEC_BIN_CORRUPT; - } + } } /* Read key-list */ @@ -250,7 +250,7 @@ static int tst_test_error_operation_execute /* * Perform operation */ - + if ( index > 0 ) sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, "testsuite: test_error test; match error message [index=%d]", index); @@ -263,8 +263,8 @@ static int tst_test_error_operation_execute /* Perform match */ if ( (match=sieve_match(renv, &mcht, &cmp, value_list, key_list, &ret)) < 0 ) - return ret; - + return ret; + /* Set test result for subsequent conditional jump */ sieve_interpreter_set_test_result(renv->interp, match > 0); return SIEVE_EXEC_OK; diff --git a/src/testsuite/tst-test-multiscript.c b/src/testsuite/tst-test-multiscript.c index 183bff23d92b0ffe0a25f07de37fe345f13ee561..505c05d88194c8c64062cada5aeba8aac0b1ac28 100644 --- a/src/testsuite/tst-test-multiscript.c +++ b/src/testsuite/tst-test-multiscript.c @@ -19,7 +19,7 @@ /* * Test_multiscript command * - * Syntax: + * Syntax: * test_multiscript <scripts: string-list> */ @@ -28,19 +28,19 @@ static bool tst_test_multiscript_validate static bool tst_test_multiscript_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *tst); -const struct sieve_command_def tst_test_multiscript = { - "test_multiscript", - SCT_TEST, +const struct sieve_command_def tst_test_multiscript = { + "test_multiscript", + SCT_TEST, 1, 0, FALSE, FALSE, NULL, NULL, tst_test_multiscript_validate, - NULL, - tst_test_multiscript_generate, - NULL + NULL, + tst_test_multiscript_generate, + NULL }; -/* - * Operation +/* + * Operation */ static bool tst_test_multiscript_operation_dump @@ -48,33 +48,33 @@ static bool tst_test_multiscript_operation_dump static int tst_test_multiscript_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def test_multiscript_operation = { +const struct sieve_operation_def test_multiscript_operation = { "TEST_MULTISCRIPT", - &testsuite_extension, + &testsuite_extension, TESTSUITE_OPERATION_TEST_MULTISCRIPT, - tst_test_multiscript_operation_dump, - tst_test_multiscript_operation_execute + tst_test_multiscript_operation_dump, + tst_test_multiscript_operation_execute }; -/* - * Validation +/* + * Validation */ static bool tst_test_multiscript_validate -(struct sieve_validator *valdtr, struct sieve_command *tst) +(struct sieve_validator *valdtr, struct sieve_command *tst) { struct sieve_ast_argument *arg = tst->first_positional; - + if ( !sieve_validate_positional_argument (valdtr, tst, arg, "scripts", 1, SAAT_STRING_LIST) ) { return FALSE; } - + return sieve_validator_argument_activate(valdtr, tst, arg, FALSE); } -/* - * Code generation +/* + * Code generation */ static bool tst_test_multiscript_generate @@ -86,17 +86,17 @@ static bool tst_test_multiscript_generate return sieve_generate_arguments(cgenv, tst, NULL); } -/* +/* * Code dump */ - + static bool tst_test_multiscript_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) { sieve_code_dumpf(denv, "TEST_MULTISCRIPT:"); sieve_code_descend(denv); - if ( !sieve_opr_stringlist_dump(denv, address, "scripts") ) + if ( !sieve_opr_stringlist_dump(denv, address, "scripts") ) return FALSE; return TRUE; @@ -127,7 +127,7 @@ static int tst_test_multiscript_operation_execute * Perform operation */ - sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, + sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, "testsuite: test_multiscript test"); sieve_runtime_trace_descend(renv); @@ -141,7 +141,7 @@ static int tst_test_multiscript_operation_execute array_append(&scriptfiles, &script, 1); } - result = result && (ret >= 0) && + result = result && (ret >= 0) && testsuite_script_multiscript(renv, &scriptfiles); /* Set result */ diff --git a/src/testsuite/tst-test-result-action.c b/src/testsuite/tst-test-result-action.c index 647e4a45a5a65c529c0d5bf6a39631058063a199..05239a629f0014259915d36a33269e5322fe0d9d 100644 --- a/src/testsuite/tst-test-result-action.c +++ b/src/testsuite/tst-test-result-action.c @@ -23,8 +23,8 @@ /* * test_result_action command * - * Syntax: - * test_result_action [MATCH-TYPE] [COMPARATOR] [:index number] + * Syntax: + * test_result_action [MATCH-TYPE] [COMPARATOR] [:index number] * <key-list: string-list> */ @@ -36,20 +36,20 @@ static bool tst_test_result_action_validate static bool tst_test_result_action_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx); -const struct sieve_command_def tst_test_result_action = { - "test_result_action", - SCT_TEST, +const struct sieve_command_def tst_test_result_action = { + "test_result_action", + SCT_TEST, 1, 0, FALSE, FALSE, - tst_test_result_action_registered, + tst_test_result_action_registered, NULL, tst_test_result_action_validate, NULL, - tst_test_result_action_generate, - NULL + tst_test_result_action_generate, + NULL }; -/* - * Operation +/* + * Operation */ static bool tst_test_result_action_operation_dump @@ -57,17 +57,17 @@ static bool tst_test_result_action_operation_dump static int tst_test_result_action_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def test_result_action_operation = { +const struct sieve_operation_def test_result_action_operation = { "TEST_RESULT_ACTION", - &testsuite_extension, + &testsuite_extension, TESTSUITE_OPERATION_TEST_RESULT_ACTION, - tst_test_result_action_operation_dump, - tst_test_result_action_operation_execute + tst_test_result_action_operation_dump, + tst_test_result_action_operation_execute }; /* * Tagged arguments - */ + */ /* FIXME: merge this with the test_error version of this tag */ @@ -131,19 +131,19 @@ static bool tst_test_result_action_registered return TRUE; } -/* - * Validation +/* + * Validation */ static bool tst_test_result_action_validate -(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *tst) +(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *tst) { struct sieve_ast_argument *arg = tst->first_positional; - struct sieve_comparator cmp_default = + struct sieve_comparator cmp_default = SIEVE_COMPARATOR_DEFAULT(i_octet_comparator); - struct sieve_match_type mcht_default = + struct sieve_match_type mcht_default = SIEVE_COMPARATOR_DEFAULT(is_match_type); - + if ( !sieve_validate_positional_argument (valdtr, tst, arg, "key list", 2, SAAT_STRING_LIST) ) { return FALSE; @@ -157,8 +157,8 @@ static bool tst_test_result_action_validate (valdtr, tst, arg, &mcht_default, &cmp_default); } -/* - * Code generation +/* + * Code generation */ static bool tst_test_result_action_generate @@ -170,10 +170,10 @@ static bool tst_test_result_action_generate return sieve_generate_arguments(cgenv, tst, NULL); } -/* +/* * Code dump */ - + static bool tst_test_result_action_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) { @@ -186,7 +186,7 @@ static bool tst_test_result_action_operation_dump for (;;) { int opt; - if ( (opt=sieve_match_opr_optional_dump(denv, address, &opt_code)) + if ( (opt=sieve_match_opr_optional_dump(denv, address, &opt_code)) < 0 ) return FALSE; @@ -198,7 +198,7 @@ static bool tst_test_result_action_operation_dump } else { return FALSE; } - } + } return sieve_opr_stringlist_dump(denv, address, "key list"); } @@ -209,7 +209,7 @@ static bool tst_test_result_action_operation_dump static int tst_test_result_action_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) -{ +{ int opt_code = 0; struct sieve_comparator cmp = SIEVE_COMPARATOR_DEFAULT(i_octet_comparator); struct sieve_match_type mcht = SIEVE_MATCH_TYPE_DEFAULT(is_match_type); @@ -223,7 +223,7 @@ static int tst_test_result_action_operation_execute /* Read optional operands */ for (;;) { - sieve_number_t number; + sieve_number_t number; int opt; if ( (opt=sieve_match_opr_optional_read @@ -231,7 +231,7 @@ static int tst_test_result_action_operation_execute return ret; if ( opt == 0 ) break; - + if ( opt_code == OPT_INDEX ) { if ( (ret=sieve_opr_number_read(renv, address, "index", &number)) <= 0 ) return ret; @@ -239,7 +239,7 @@ static int tst_test_result_action_operation_execute } else { sieve_runtime_trace_error(renv, "invalid optional operand"); return SIEVE_EXEC_BIN_CORRUPT; - } + } } /* Read key-list */ @@ -250,7 +250,7 @@ static int tst_test_result_action_operation_execute /* * Perform operation */ - + sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, "testsuite: test_result_action test; match result name (index: %d)", index); @@ -259,8 +259,8 @@ static int tst_test_result_action_operation_execute /* Perform match */ if ( (match=sieve_match(renv, &mcht, &cmp, value_list, key_list, &ret)) < 0 ) - return ret; - + return ret; + /* Set test result for subsequent conditional jump */ sieve_interpreter_set_test_result(renv->interp, match > 0); return SIEVE_EXEC_OK; diff --git a/src/testsuite/tst-test-result-execute.c b/src/testsuite/tst-test-result-execute.c index ae5507df41e3fc27777f7feb79aee927353eda02..5f12580ea6c02aec28f48a08f1405c7145c77cdb 100644 --- a/src/testsuite/tst-test-result-execute.c +++ b/src/testsuite/tst-test-result-execute.c @@ -18,39 +18,39 @@ /* * Test_result_execute command * - * Syntax: + * Syntax: * test_result_execute */ static bool tst_test_result_execute_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd); -const struct sieve_command_def tst_test_result_execute = { - "test_result_execute", - SCT_TEST, +const struct sieve_command_def tst_test_result_execute = { + "test_result_execute", + SCT_TEST, 0, 0, FALSE, FALSE, NULL, NULL, NULL, NULL, - tst_test_result_execute_generate, - NULL + tst_test_result_execute_generate, + NULL }; -/* - * Operation +/* + * Operation */ static int tst_test_result_execute_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def test_result_execute_operation = { +const struct sieve_operation_def test_result_execute_operation = { "TEST_RESULT_EXECUTE", - &testsuite_extension, + &testsuite_extension, TESTSUITE_OPERATION_TEST_RESULT_EXECUTE, - NULL, - tst_test_result_execute_operation_execute + NULL, + tst_test_result_execute_operation_execute }; -/* - * Code generation +/* + * Code generation */ static bool tst_test_result_execute_generate @@ -74,14 +74,14 @@ static int tst_test_result_execute_operation_execute * Perform operation */ - sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, + sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, "testsuite: test_result_execute test"); result = testsuite_result_execute(renv); if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_TESTS) ) { sieve_runtime_trace_descend(renv); - sieve_runtime_trace(renv, 0, "execution of result %s", + sieve_runtime_trace(renv, 0, "execution of result %s", ( result ? "succeeded" : "failed" )); } diff --git a/src/testsuite/tst-test-script-compile.c b/src/testsuite/tst-test-script-compile.c index 2d00d0a4eac6382a8420a19b2af08445ebc5c8c8..e37c6b341f7b787b85768013fbc53dad02f9f360 100644 --- a/src/testsuite/tst-test-script-compile.c +++ b/src/testsuite/tst-test-script-compile.c @@ -18,7 +18,7 @@ /* * Test_script_compile command * - * Syntax: + * Syntax: * test_script_compile <scriptpath: string> */ @@ -27,19 +27,19 @@ static bool tst_test_script_compile_validate static bool tst_test_script_compile_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd); -const struct sieve_command_def tst_test_script_compile = { - "test_script_compile", - SCT_TEST, +const struct sieve_command_def tst_test_script_compile = { + "test_script_compile", + SCT_TEST, 1, 0, FALSE, FALSE, NULL, NULL, tst_test_script_compile_validate, NULL, - tst_test_script_compile_generate, - NULL + tst_test_script_compile_generate, + NULL }; -/* - * Operation +/* + * Operation */ static bool tst_test_script_compile_operation_dump @@ -47,33 +47,33 @@ static bool tst_test_script_compile_operation_dump static int tst_test_script_compile_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def test_script_compile_operation = { +const struct sieve_operation_def test_script_compile_operation = { "TEST_SCRIPT_COMPILE", - &testsuite_extension, + &testsuite_extension, TESTSUITE_OPERATION_TEST_SCRIPT_COMPILE, - tst_test_script_compile_operation_dump, - tst_test_script_compile_operation_execute + tst_test_script_compile_operation_dump, + tst_test_script_compile_operation_execute }; -/* - * Validation +/* + * Validation */ static bool tst_test_script_compile_validate -(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *tst) +(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *tst) { struct sieve_ast_argument *arg = tst->first_positional; - + if ( !sieve_validate_positional_argument (valdtr, tst, arg, "script", 1, SAAT_STRING) ) { return FALSE; } - + return sieve_validator_argument_activate(valdtr, tst, arg, FALSE); } -/* - * Code generation +/* + * Code generation */ static bool tst_test_script_compile_generate @@ -85,17 +85,17 @@ static bool tst_test_script_compile_generate return sieve_generate_arguments(cgenv, tst, NULL); } -/* +/* * Code dump */ - + static bool tst_test_script_compile_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) { sieve_code_dumpf(denv, "TEST_SCRIPT_COMPILE:"); sieve_code_descend(denv); - if ( !sieve_opr_string_dump(denv, address, "script-name") ) + if ( !sieve_opr_string_dump(denv, address, "script-name") ) return FALSE; return TRUE; diff --git a/src/testsuite/tst-test-script-run.c b/src/testsuite/tst-test-script-run.c index e7cba352b019dc3b3470057b050b6fd252dc3186..e5d1656ea1b9b7b23605c8f1c958b6bbc144de88 100644 --- a/src/testsuite/tst-test-script-run.c +++ b/src/testsuite/tst-test-script-run.c @@ -19,7 +19,7 @@ /* * Test_script_run command * - * Syntax: + * Syntax: * test_script_run */ @@ -29,18 +29,18 @@ static bool tst_test_script_run_registered static bool tst_test_script_run_generate (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd); -const struct sieve_command_def tst_test_script_run = { - "test_script_run", - SCT_TEST, +const struct sieve_command_def tst_test_script_run = { + "test_script_run", + SCT_TEST, 0, 0, FALSE, FALSE, - tst_test_script_run_registered, + tst_test_script_run_registered, NULL, NULL, NULL, - tst_test_script_run_generate, - NULL + tst_test_script_run_generate, + NULL }; -/* - * Operation +/* + * Operation */ static bool tst_test_script_run_operation_dump @@ -48,12 +48,12 @@ static bool tst_test_script_run_operation_dump static int tst_test_script_run_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address); -const struct sieve_operation_def test_script_run_operation = { +const struct sieve_operation_def test_script_run_operation = { "test_script_run", - &testsuite_extension, + &testsuite_extension, TESTSUITE_OPERATION_TEST_SCRIPT_RUN, - tst_test_script_run_operation_dump, - tst_test_script_run_operation_execute + tst_test_script_run_operation_dump, + tst_test_script_run_operation_execute }; /* @@ -69,24 +69,24 @@ enum cmd_vacation_optional { /* Tags */ -static const struct sieve_argument_def append_result_tag = { - "append_result", +static const struct sieve_argument_def append_result_tag = { + "append_result", NULL, NULL, NULL, NULL, NULL }; static bool tst_test_script_run_registered (struct sieve_validator *validator, const struct sieve_extension *ext, - struct sieve_command_registration *cmd_reg) + struct sieve_command_registration *cmd_reg) { sieve_validator_register_tag - (validator, cmd_reg, ext, &append_result_tag, OPT_APPEND_RESULT); + (validator, cmd_reg, ext, &append_result_tag, OPT_APPEND_RESULT); return TRUE; } -/* - * Code generation +/* + * Code generation */ static bool tst_test_script_run_generate @@ -103,11 +103,11 @@ static bool tst_test_script_run_generate static bool tst_test_script_run_operation_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address) -{ +{ int opt_code = 0; - + sieve_code_dumpf(denv, "TEST_SCRIPT_RUN"); - sieve_code_descend(denv); + sieve_code_descend(denv); /* Dump optional operands */ for (;;) { @@ -120,13 +120,13 @@ static bool tst_test_script_run_operation_dump switch ( opt_code ) { case OPT_APPEND_RESULT: - sieve_code_dumpf(denv, "append_result"); + sieve_code_dumpf(denv, "append_result"); break; default: return FALSE; } } - + return TRUE; } @@ -146,7 +146,7 @@ static int tst_test_script_run_operation_execute * Read operands */ - /* Optional operands */ + /* Optional operands */ for (;;) { int opt; @@ -160,7 +160,7 @@ static int tst_test_script_run_operation_execute append_result = TRUE; break; default: - sieve_runtime_trace_error(renv, + sieve_runtime_trace_error(renv, "unknown optional operand"); return SIEVE_EXEC_BIN_CORRUPT; } @@ -170,12 +170,12 @@ static int tst_test_script_run_operation_execute * Perform operation */ - sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, + sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, "testsuite: run compiled script [append_result=%s]", ( append_result ? "yes" : "no" )); /* Reset result object */ - if ( !append_result ) + if ( !append_result ) testsuite_result_reset(renv); /* Run script */ @@ -183,7 +183,7 @@ static int tst_test_script_run_operation_execute if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_TESTS) ) { sieve_runtime_trace_descend(renv); - sieve_runtime_trace(renv, 0, "execution of script %s", + sieve_runtime_trace(renv, 0, "execution of script %s", ( result ? "succeeded" : "failed" )); } diff --git a/tests/compile/errors.svtest b/tests/compile/errors.svtest index a1d3673c5d19b28a568100a9462fd4d6223961ad..23e1e526f55fd4f5006cc076f52a9deee5e2e3fa 100644 --- a/tests/compile/errors.svtest +++ b/tests/compile/errors.svtest @@ -5,7 +5,7 @@ require "comparator-i;ascii-numeric"; /* * Errors triggered in the compiled scripts are pretty reduntant over the - * tested commands, but we want to be thorough. + * tested commands, but we want to be thorough. */ /* @@ -49,12 +49,12 @@ test "Header errors" { test_fail "wrong number of errors reported"; } - if not test_error :index 1 :matches + if not test_error :index 1 :matches "unknown * ':all' for * header test *" { test_fail "error 1 is invalid"; } - if not test_error :index 2 :matches + if not test_error :index 2 :matches "*header test * string list * 1 (header names), but * number *" { test_fail "error 2 is invalid"; } @@ -64,32 +64,32 @@ test "Header errors" { test_fail "error 3 is invalid"; } - if not test_error :index 4 :matches + if not test_error :index 4 :matches "* unexpected tagged argument ':tag' while *" { test_fail "error 4 is invalid"; } - if not test_error :index 5 :matches + if not test_error :index 5 :matches "* header test requires 2 *, but 1 *" { test_fail "error 5 is invalid"; } - if not test_error :index 6 :matches + if not test_error :index 6 :matches "* header test requires 2 *, but 0 *" { test_fail "error 6 is invalid"; } - if not test_error :index 7 :matches + if not test_error :index 7 :matches "*header test accepts no sub-tests* specified*" { test_fail "error 7 is invalid"; } - if not test_error :index 8 :matches + if not test_error :index 8 :matches "* use test 'header' * command*" { test_fail "error 8 is invalid"; } - if not test_error :index 9 :matches + if not test_error :index 9 :matches "* use test 'header' * command*" { test_fail "error 9 is invalid"; } @@ -97,7 +97,7 @@ test "Header errors" { if test_error :index 4 :contains "radish" { test_fail "error test matched nonsense"; } -} +} /* * Address test @@ -111,7 +111,7 @@ test "Address errors" { if not test_error :count "eq" :comparator "i;ascii-numeric" "9" { test_fail "wrong number of errors reported"; - } + } if not test_error :index 1 :matches "*unknown * ':nonsense' * address test*" { @@ -169,7 +169,7 @@ test "If errors (FIXME: count only)" { if not test_error :count "eq" :comparator "i;ascii-numeric" "12" { test_fail "wrong number of errors reported"; - } + } } /* @@ -183,7 +183,7 @@ test "Require errors (FIXME: count only)" { if not test_error :count "eq" :comparator "i;ascii-numeric" "15" { test_fail "wrong number of errors reported"; - } + } } /* diff --git a/tests/compile/errors/address.sieve b/tests/compile/errors/address.sieve index 917da1f8e6f94bf9c4c18554f0a45b900e536aa2..f7d3b260f8709ab9ecae16369984894248cf34c3 100644 --- a/tests/compile/errors/address.sieve +++ b/tests/compile/errors/address.sieve @@ -1,6 +1,6 @@ require "comparator-i;ascii-numeric"; -/* +/* * Address test errors * * Total count: 8 (+1 = 9) @@ -8,7 +8,7 @@ require "comparator-i;ascii-numeric"; /* * Command structure - */ + */ # Invalid tag if address :nonsense :comparator "i;ascii-casemap" :localpart "From" "nico" { @@ -49,7 +49,7 @@ if address :localpart :is :comparator "i;ascii-casemap" "from" ["frop", "frop"] * Specified headers must contain addresses */ -# Invalid header +# Invalid header if address :is "frop" "frml" { keep; } diff --git a/tests/compile/errors/envelope.sieve b/tests/compile/errors/envelope.sieve index a19f0af83cc45a626a357ebe8c77f0acdafc6d79..9639846be082601601ea5f062b288f28f369e66f 100644 --- a/tests/compile/errors/envelope.sieve +++ b/tests/compile/errors/envelope.sieve @@ -6,7 +6,7 @@ require "envelope"; -# Not an error +# Not an error if envelope :is "to" "frop@example.org" { } diff --git a/tests/compile/errors/if.sieve b/tests/compile/errors/if.sieve index fa741c9c6716d24984e05fe599edc58b676dfffa..ebb6d34fbe812abd4fa6397ee31573d008fd2aa4 100644 --- a/tests/compile/errors/if.sieve +++ b/tests/compile/errors/if.sieve @@ -1,5 +1,5 @@ /* - * If command errors + * If command errors * * Total errors: 11 (+1 = 12) */ @@ -63,7 +63,7 @@ if true { # If used as test if if true { -} +} # Else if in stead of elsif diff --git a/tests/compile/errors/keep.sieve b/tests/compile/errors/keep.sieve index bbce0d530335b9b68c7a6137e58eef0ec24f461b..7b3397cec5273eac13b15039d4bafb9d7e8bcfab 100644 --- a/tests/compile/errors/keep.sieve +++ b/tests/compile/errors/keep.sieve @@ -7,7 +7,7 @@ # Spurious string argument keep "frop"; -# Spurious test +# Spurious test keep true; # Not an error diff --git a/tests/compile/errors/lexer.sieve b/tests/compile/errors/lexer.sieve index eba66b28d5a9ddadc88446e0c95fe9503e47039d..4b16ea9444b282c2e694ecbf2f1cf3a048b4dc52 100644 --- a/tests/compile/errors/lexer.sieve +++ b/tests/compile/errors/lexer.sieve @@ -7,7 +7,7 @@ /* * Number limits */ - + # Number too large if size :under 4294967300 { stop; diff --git a/tests/compile/errors/out-address.sieve b/tests/compile/errors/out-address.sieve index ef96f400a2a8f09d980fb802021641b76110efe3..935a2aab206fca5cdf4b18d3b59c40678911c691 100644 --- a/tests/compile/errors/out-address.sieve +++ b/tests/compile/errors/out-address.sieve @@ -1,6 +1,6 @@ require "vacation"; -# Error +# Error redirect "@wrong.example.com"; redirect "error"; diff --git a/tests/compile/errors/parser.sieve b/tests/compile/errors/parser.sieve index b5300b12b3de140facd7371e600dcf12d59b4d3d..26a1e53bda6c008f0779054203d922590757468b 100644 --- a/tests/compile/errors/parser.sieve +++ b/tests/compile/errors/parser.sieve @@ -5,8 +5,8 @@ */ # Too many arguments (1) -frop :this "is" "a" 2 :long "argument" "list" :and :it :should "fail" :during "parsing" :but "it" "should" "be" - "recoverable" "." :this "is" "a" 2 :long "argument" "list" :and :it :should "fail" :during "parsing" :but +frop :this "is" "a" 2 :long "argument" "list" :and :it :should "fail" :during "parsing" :but "it" "should" "be" + "recoverable" "." :this "is" "a" 2 :long "argument" "list" :and :it :should "fail" :during "parsing" :but "it" "should" "be" "recoverable" { stop; } @@ -31,22 +31,22 @@ if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { - if true { if true { if true { if true { if true { if true { - if - anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( - anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( - anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( - anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( + if true { if true { if true { if true { if true { if true { + if anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( - true - )))))))) - )))))))) - )))))))) - )))))))) - )))))))) + anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( + anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( + anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( + anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( anyof ( + true + )))))))) + )))))))) + )))))))) + )))))))) + )))))))) { stop; - } + } } } } } } } } } } } } } } } } } } } } } } } @@ -56,8 +56,8 @@ if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { if true { - if true { if true { if true { if true { if true { if true { - if + if true { if true { if true { if true { if true { if true { + if not not not not not not not not not not not not not not not not not not not not not not not not @@ -65,7 +65,7 @@ if true { if true { if true { if true { if true { if true { if true { if true { not not not not not not not not false { stop; - } + } } } } } } } } } } } } } } } } } } } } } } } diff --git a/tests/compile/errors/require.sieve b/tests/compile/errors/require.sieve index 9670bf1b7e32dd66b0aa0d601e0c735aaca22876..ecbd7a2bd7fb87963b7925c0dc33783b6c143d25 100644 --- a/tests/compile/errors/require.sieve +++ b/tests/compile/errors/require.sieve @@ -29,7 +29,7 @@ require "dovecot.test" true; require "_frop"; # Spurious command block -require "fileinto" { +require "fileinto" { keep; } diff --git a/tests/compile/errors/size.sieve b/tests/compile/errors/size.sieve index 71281ae7f0f6c5221ea6cecc9467452477650783..14dbee5d1b497e981576be1b5aa24bab862177c2 100644 --- a/tests/compile/errors/size.sieve +++ b/tests/compile/errors/size.sieve @@ -1,6 +1,6 @@ /* * Size test errors - * + * * Total errors: 6 (+1 = 7) */ diff --git a/tests/compile/errors/tag.sieve b/tests/compile/errors/tag.sieve index d285cf9c7dbfd25b614867c50f8c4b94cf5e0c6f..7fa65e9f2e979819f68d0964ed10dc3a02fba9d3 100644 --- a/tests/compile/errors/tag.sieve +++ b/tests/compile/errors/tag.sieve @@ -1,6 +1,6 @@ /* * Tag errors - * + * * Total errors: 2 (+1 = 3) */ diff --git a/tests/compile/errors/typos.sieve b/tests/compile/errors/typos.sieve index cd678a2dd7a5d28e5e742addb67e218a80dd3e7c..3d65b2620ab98e8d22914969f02a2abb0e356be1 100644 --- a/tests/compile/errors/typos.sieve +++ b/tests/compile/errors/typos.sieve @@ -5,8 +5,8 @@ require "fileinto"; -/* - * Missing semicolon +/* + * Missing semicolon */ fileinto "frop" @@ -14,15 +14,15 @@ keep; /* Other situations */ -fileinto "frup" +fileinto "frup" true; -fileinto "friep" +fileinto "friep" snot; /* * Forgot tag colon - */ + */ if address matches "from" "*frop*" { stop; diff --git a/tests/compile/errors/unsupported.sieve b/tests/compile/errors/unsupported.sieve index e367ad193d47f4272532b02c94fb2cd448d5a101..9943f7b3db15e1b5dbab2b0b62df69173b46484d 100644 --- a/tests/compile/errors/unsupported.sieve +++ b/tests/compile/errors/unsupported.sieve @@ -1,4 +1,4 @@ -/* +/* * Handling of unsupported language features. * * Total errors: 3 (+1 = 4) @@ -8,11 +8,11 @@ require "variables"; require "include"; require "regex"; -/* +/* * Unsupported use of variables */ -/* Comparator argument */ +/* Comparator argument */ set "comp" "i;ascii-numeric"; diff --git a/tests/compile/recover.svtest b/tests/compile/recover.svtest index 959a602d018b02bae4f85c3c8ed0c5b3baa8d925..9c24c11369aadd81068311d531700bfe71b22450 100644 --- a/tests/compile/recover.svtest +++ b/tests/compile/recover.svtest @@ -8,7 +8,7 @@ require "comparator-i;ascii-numeric"; */ /* - * Commands + * Commands */ /* Missing semicolon */ diff --git a/tests/control-if.svtest b/tests/control-if.svtest index eb4f2e77236d649d00b499e3f6e820c925fb2b90..e11de64b5417d608857aaf68768047d88ddc7c20 100644 --- a/tests/control-if.svtest +++ b/tests/control-if.svtest @@ -1,7 +1,7 @@ require "vnd.dovecot.testsuite"; -/* - * ## RFC 5228, Section 3.1. Control if (page 21) ## +/* + * ## RFC 5228, Section 3.1. Control if (page 21) ## */ test_set "message" text: @@ -112,7 +112,7 @@ test "Basic functionality: elseif true/false" { } elsif true { test_fail "executed wrong alternative for static true-true (elsif)"; } else { - test_fail "executed wrong alternative for static true-true (else)"; + test_fail "executed wrong alternative for static true-true (else)"; } if true { @@ -120,7 +120,7 @@ test "Basic functionality: elseif true/false" { } elsif false { test_fail "executed wrong alternative for static true-false (elsif)"; } else { - test_fail "executed wrong alternative for static true-false (else)"; + test_fail "executed wrong alternative for static true-false (else)"; } if false { @@ -128,13 +128,13 @@ test "Basic functionality: elseif true/false" { } elsif true { /* Correct */ } else { - test_fail "executed wrong alternative for static false-false (else)"; + test_fail "executed wrong alternative for static false-false (else)"; } if false { test_fail "executed wrong alternative for static false-false (if)"; } elsif false { - test_fail "executed wrong alternative for static false-false (elsif)"; + test_fail "executed wrong alternative for static false-false (elsif)"; } else { /* Correct */ } @@ -145,7 +145,7 @@ test "Basic functionality: elseif true/false" { } elsif address :contains "from" "stephan" { test_fail "executed wrong alternative for dynamic true-true (elsif)"; } else { - test_fail "executed wrong alternative for dynamic true-true (else)"; + test_fail "executed wrong alternative for dynamic true-true (else)"; } if address :is "from" "stephan@example.org" { @@ -153,7 +153,7 @@ test "Basic functionality: elseif true/false" { } elsif address :is "from" "frop@example.com" { test_fail "executed wrong alternative for dynamic true-false (elsif)"; } else { - test_fail "executed wrong alternative for dynamic true-false (else)"; + test_fail "executed wrong alternative for dynamic true-false (else)"; } if address :is "from" "tss@example.net" { @@ -161,13 +161,13 @@ test "Basic functionality: elseif true/false" { } elsif address :is "from" "stephan@example.org" { /* Correct */ } else { - test_fail "executed wrong alternative for dynamic false-true(else)"; + test_fail "executed wrong alternative for dynamic false-true(else)"; } if address :is "from" "tss@example.net" { test_fail "executed wrong alternative for dynamic false-false (if)"; } elsif address :is "to" "stephan@example.org" { - test_fail "executed wrong alternative for dynamic false-false (elsif)"; + test_fail "executed wrong alternative for dynamic false-false (elsif)"; } else { /* Correct */ } @@ -179,7 +179,7 @@ test "Basic functionality: elseif true/false" { } elsif address :contains "from" "stephan" { test_fail "executed wrong alternative for first-static true-true (elsif)"; } else { - test_fail "executed wrong alternative for first-static true-true (else)"; + test_fail "executed wrong alternative for first-static true-true (else)"; } if address :is "from" "stephan@example.org" { @@ -187,7 +187,7 @@ test "Basic functionality: elseif true/false" { } elsif true { test_fail "executed wrong alternative for second-static true-true (elsif)"; } else { - test_fail "executed wrong alternative for second-static true-true (else)"; + test_fail "executed wrong alternative for second-static true-true (else)"; } if true { @@ -195,7 +195,7 @@ test "Basic functionality: elseif true/false" { } elsif address :is "from" "frop@example.com" { test_fail "executed wrong alternative for first-static true-false (elsif)"; } else { - test_fail "executed wrong alternative for first-static true-false (else)"; + test_fail "executed wrong alternative for first-static true-false (else)"; } if address :is "from" "stephan@example.org" { @@ -203,7 +203,7 @@ test "Basic functionality: elseif true/false" { } elsif false { test_fail "executed wrong alternative for second-static true-false (elsif)"; } else { - test_fail "executed wrong alternative for second-static true-false (else)"; + test_fail "executed wrong alternative for second-static true-false (else)"; } if false { @@ -211,7 +211,7 @@ test "Basic functionality: elseif true/false" { } elsif address :is "from" "stephan@example.org" { /* Correct */ } else { - test_fail "executed wrong alternative for first-static false-true(else)"; + test_fail "executed wrong alternative for first-static false-true(else)"; } if address :is "from" "tss@example.net" { @@ -219,13 +219,13 @@ test "Basic functionality: elseif true/false" { } elsif true { /* Correct */ } else { - test_fail "executed wrong alternative for second-static false-true(else)"; + test_fail "executed wrong alternative for second-static false-true(else)"; } if false { test_fail "executed wrong alternative for first-static false-false (if)"; } elsif address :is "to" "stephan@example.org" { - test_fail "executed wrong alternative for first-static false-false (elsif)"; + test_fail "executed wrong alternative for first-static false-false (elsif)"; } else { /* Correct */ } @@ -233,7 +233,7 @@ test "Basic functionality: elseif true/false" { if address :is "from" "tss@example.net" { test_fail "executed wrong alternative for second-static false-false (if)"; } elsif false { - test_fail "executed wrong alternative for second-static false-false (elsif)"; + test_fail "executed wrong alternative for second-static false-false (elsif)"; } else { /* Correct */ } @@ -257,7 +257,7 @@ test "Basic functionality: nesting" { } } elsif true { if false { - test_fail "chose wrong static outcome: false->true->false"; + test_fail "chose wrong static outcome: false->true->false"; } elsif true { test_fail "chose wrong static outcome: false->true->true"; } @@ -279,7 +279,7 @@ test "Basic functionality: nesting" { } } elsif exists "cc" { if exists "frop" { - test_fail "chose wrong dynamic outcome: false->true->false"; + test_fail "chose wrong dynamic outcome: false->true->false"; } elsif exists "from" { test_fail "chose wrong dynamic outcome: false->true->true"; } diff --git a/tests/deprecated/notify/basic.svtest b/tests/deprecated/notify/basic.svtest index 15886d658eb16b364789fdca069f665af2f1f313..cd6b31d04151cc53244c158fab4843aa18582ddc 100644 --- a/tests/deprecated/notify/basic.svtest +++ b/tests/deprecated/notify/basic.svtest @@ -3,9 +3,9 @@ require "notify"; test "Execute" { /* Test to catch runtime segfaults */ - notify + notify :message "This is probably very important" :low - :method "mailto" + :method "mailto" :options ["stephan@example.com", "stephan@example.org"]; } diff --git a/tests/deprecated/notify/mailto.svtest b/tests/deprecated/notify/mailto.svtest index e8da4277761b442c1b6bf7e303ef2d30664ddde1..cdbddf2dd4198dff7ef248450787c6a409db7c46 100644 --- a/tests/deprecated/notify/mailto.svtest +++ b/tests/deprecated/notify/mailto.svtest @@ -86,11 +86,11 @@ test "Multiple recipients" { if not address :count "eq" :comparator "i;ascii-numeric" "to" "1" { test_fail "too many recipients in To header"; - } + } if not address :count "eq" :comparator "i;ascii-numeric" "cc" "0" { test_fail "too many recipients in Cc header"; - } + } } /* @@ -176,8 +176,8 @@ $text$ You have been notified. . -; - +; + if not test_result_execute { test_fail "failed to execute notify"; } @@ -190,7 +190,7 @@ You have been notified. if not body :raw :contains "You have been notified" { test_fail "notification has no footer"; - } + } if not allof( body :raw :contains "Test. Test", @@ -220,8 +220,8 @@ $text[5]$ You have been notified. . -; - +; + if not test_result_execute { test_fail "failed to execute notify"; } @@ -234,7 +234,7 @@ You have been notified. if not body :raw :contains "You have been notified" { test_fail "notification has no footer"; - } + } if anyof( body :raw :contains "Test. Test", @@ -244,7 +244,7 @@ You have been notified. if not body :raw :contains "Test." { test_fail "notification does not contain the required message"; - } + } } test_result_reset; @@ -267,7 +267,7 @@ This is a nested multi-part message in MIME format. Content-Type: application/sieve; charset="us-ascii" keep; - + --inner Content-Type: text/plain; charset="us-ascii" @@ -300,8 +300,8 @@ $text$ You have been notified. . -; - +; + if not test_result_execute { test_fail "failed to execute notify"; } diff --git a/tests/execute/actions.svtest b/tests/execute/actions.svtest index 6225d39917fa6215b127b7afd4c242f01c9d40f5..3f517fa7d1adde65932464905c8d9804ff29bcc9 100644 --- a/tests/execute/actions.svtest +++ b/tests/execute/actions.svtest @@ -25,19 +25,19 @@ test "Fileinto" { if not test_result_action :count "eq" :comparator "i;ascii-numeric" "3" { test_fail "wrong number of actions in result"; - } + } if not test_result_action :index 1 "store" { test_fail "first action is not 'store'"; - } + } if not test_result_action :index 2 "store" { test_fail "second action is not 'store'"; - } + } if not test_result_action :index 3 "keep" { test_fail "third action is not 'keep'"; - } + } if not test_result_execute { test_fail "result execute failed"; @@ -55,23 +55,23 @@ test "Redirect" { if not test_result_action :count "eq" :comparator "i;ascii-numeric" "4" { test_fail "wrong number of actions in result"; - } + } if not test_result_action :index 1 "redirect" { test_fail "first action is not 'redirect'"; - } + } if not test_result_action :index 2 "keep" { test_fail "second action is not 'keep'"; - } + } if not test_result_action :index 3 "redirect" { test_fail "third action is not 'redirect'"; - } + } if not test_result_action :index 4 "redirect" { test_fail "fourth action is not 'redirect'"; - } + } if not test_result_execute { test_fail "result execute failed"; diff --git a/tests/execute/actions/redirect.sieve b/tests/execute/actions/redirect.sieve index a88a0a8c46be874f3279835684a966ec2aba7124..7adc23e158ef43c0adc640340748795b951b0762 100644 --- a/tests/execute/actions/redirect.sieve +++ b/tests/execute/actions/redirect.sieve @@ -1,7 +1,7 @@ if address :contains "to" "frop.example" { /* #1 */ redirect "stephan@example.com"; - + /* #2 */ keep; } diff --git a/tests/execute/errors.svtest b/tests/execute/errors.svtest index 7d4658a6f0a891818a3f1fb60d9fc3fa543b1467..713180535ccbcbee3f5521279cddb312ce121504 100644 --- a/tests/execute/errors.svtest +++ b/tests/execute/errors.svtest @@ -58,7 +58,7 @@ test "Action limit" { if test_error :count "gt" :comparator "i;ascii-numeric" "1" { test_fail "too many runtime errors reported"; } - + if not test_error :index 1 :contains "total number of actions exceeds policy limit"{ test_fail "unexpected error reported"; } @@ -76,7 +76,7 @@ test "Redirect limit" { if test_error :count "gt" :comparator "i;ascii-numeric" "1" { test_fail "too many runtime errors reported"; } - + if not test_error :index 1 :contains "number of redirect actions exceeds policy limit"{ test_fail "unexpected error reported"; } diff --git a/tests/execute/examples.svtest b/tests/execute/examples.svtest index 57053eecaed18ed3ff91d626dc22428abc7d7bce..6143018d0e878956677bb87830d74e047905f299 100644 --- a/tests/execute/examples.svtest +++ b/tests/execute/examples.svtest @@ -1,6 +1,6 @@ require "vnd.dovecot.testsuite"; -/* Compile and execute all example scripts to trigger +/* Compile and execute all example scripts to trigger * any Segfaults. No message is set and no results are checked. */ diff --git a/tests/execute/mailstore.svtest b/tests/execute/mailstore.svtest index 457bb93fd771bac79384ea5a2076f55e8e8adcdf..d6cc220b95bee31366aafb38469afb83d0aa8d15 100644 --- a/tests/execute/mailstore.svtest +++ b/tests/execute/mailstore.svtest @@ -63,7 +63,7 @@ test "Duplicates" { } test_message :folder "Folder" 0; - + if not header :is "subject" "First message" { test_fail "first message incorrect"; } diff --git a/tests/extensions/body/basic.svtest b/tests/extensions/body/basic.svtest index a70678ff351d7e887f8545027a4caa2ef69afb9c..0b2bffc2b0e9ada0d97e25ea00c6845b8ccf3f16 100644 --- a/tests/extensions/body/basic.svtest +++ b/tests/extensions/body/basic.svtest @@ -15,8 +15,8 @@ Test! ; /* Empty line - * - * RFC 5173: + * + * RFC 5173: * 'The body test matches content in the body of an email message, that * is, anything following the first empty line after the header. (The * empty line itself, if present, is not considered to be part of the @@ -69,9 +69,9 @@ test "Defaults" { /* No body * * RFC 5173: - * 'If a message consists of a header only, not followed by an empty line, - * then that set is empty and all "body" tests return false, including - * those that test for an empty string. (This is similar to how the + * 'If a message consists of a header only, not followed by an empty line, + * then that set is empty and all "body" tests return false, including + * those that test for an empty string. (This is similar to how the * "header" test always fails when the named header fields aren't present.)' */ diff --git a/tests/extensions/body/content.svtest b/tests/extensions/body/content.svtest index 4ff287fe9a434bcee0e1274abb65e0d4ebcc0184..b82da934170d3fdba15183dfd04dfa836f9b53da 100644 --- a/tests/extensions/body/content.svtest +++ b/tests/extensions/body/content.svtest @@ -139,7 +139,7 @@ test "Full Content Type" { test "Empty Content Type" { if not body :content "" :matches "This is a text message.*" { test_fail "failed to match text/plain content"; - } + } if not body :content "" :matches "<html><body>This is HTML</body></html>*" { test_fail "failed to match text/html content"; @@ -147,17 +147,17 @@ test "Empty Content Type" { if not body :content "" :matches "keep;*" { test_fail "failed to match application/sieve content"; - } + } if body :content "" :matches "*blurdybloop*" { test_fail "body :content \"\" test matches nonsense"; - } + } } test "Main Content Type" { if not body :content "text" :matches "This is a text message.*" { test_fail "failed to match text/plain content"; - } + } if not body :content "text" :matches "<html><body>This is HTML</body></html>*" { test_fail "failed to match text/html content"; @@ -165,7 +165,7 @@ test "Main Content Type" { if body :content "text" :matches "keep;*" { test_fail "erroneously matched application/sieve content"; - } + } } /* @@ -190,7 +190,7 @@ This is a nested multi-part message in MIME format. Content-Type: text/plain; charset="us-ascii" Hello - + --inner Content-Type: text/html; charset="us-ascii" @@ -242,7 +242,7 @@ test "Nested Search" { } if not body :content "text" :contains "html" { - test_fail "failed match text content (1)"; + test_fail "failed match text content (1)"; } if not body :content "text" :contains "hello" { @@ -256,7 +256,7 @@ test "Nested Search" { if not body :content "text" :contains "please say hello" { test_fail "failed match nested message content as text/*"; } - + if not body :content "text" :count "eq" :comparator "i;ascii-numeric" "3" { test_fail "matched wrong number of \"text/*\" body parts"; } @@ -282,7 +282,7 @@ test "Multipart Content" { "This is a nested multi-part message in MIME format" { test_fail "missed second multipart body part"; } - + /* FIXME: FAILS if not body :content "multipart" :contains @@ -293,7 +293,7 @@ test "Multipart Content" { if not body :content "multipart" :contains "This is the end of the outer MIME multipart." { test_fail "missed fourth multipart body part"; - } + } if body :content "multipart" :contains "--inner" { test_fail "inner boundary is part of match"; diff --git a/tests/extensions/body/raw.svtest b/tests/extensions/body/raw.svtest index ba6696eac67a1070ebb30a4776509865f82b34e3..d3404b91721e8cf84bc838b2fff571e0647dc3b8 100644 --- a/tests/extensions/body/raw.svtest +++ b/tests/extensions/body/raw.svtest @@ -19,7 +19,7 @@ This is a nested multi-part message in MIME format. Content-Type: text/plain; charset="us-ascii" Hello - + --inner Content-Type: text/html; charset="us-ascii" diff --git a/tests/extensions/date/basic.svtest b/tests/extensions/date/basic.svtest index 9ecfd45beb5ed4532354f65cbebd7572b6a2a433..b6f4a84de6271c236ad69fcea40d7b2094f6991f 100644 --- a/tests/extensions/date/basic.svtest +++ b/tests/extensions/date/basic.svtest @@ -16,7 +16,7 @@ Wanna date? test "Defaults" { if not date :originalzone "date" "std11" "mon, 20 jul 2009 21:44:43 +0300" { - test_fail "default comparator is not i;ascii-casemap"; + test_fail "default comparator is not i;ascii-casemap"; } if anyof ( date "date" "std11" "Mon", date "date" "std11" "*") { @@ -26,16 +26,16 @@ test "Defaults" { test "Count" { if not date :count "eq" "date" "date" "1" { - test_fail "count of existing date header field is not 1"; + test_fail "count of existing date header field is not 1"; } if not date :count "eq" "resent-date" "date" "0" { - test_fail "count of non-existent date header field is not 0"; + test_fail "count of non-existent date header field is not 0"; } } test "Invalid" { if date :matches "invalid-date" "std11" "*" { - test_fail "matched invalid date: ${0}"; + test_fail "matched invalid date: ${0}"; } } diff --git a/tests/extensions/date/zones.svtest b/tests/extensions/date/zones.svtest index 471011aaa5f0f612a16b78f0c82cbae994ce9320..77adb77103d5b04e1153a909e239e40c79f45b7d 100644 --- a/tests/extensions/date/zones.svtest +++ b/tests/extensions/date/zones.svtest @@ -7,7 +7,7 @@ test "Local-Zone" { if not currentdate :matches "zone" "*" { test_fail "matches '*' failed for zone part."; } - set "local_zone" "${0}"; + set "local_zone" "${0}"; } /* FIXME: using variables somehow fails here */ @@ -38,37 +38,37 @@ Wanna date? test "Specified Zone" { if not date :zone "+0200" "date" "zone" "+0200" { if date :matches :zone "+0200" "date" "zone" "*" {} - test_fail "zone is incorrect: ${0}"; + test_fail "zone is incorrect: ${0}"; } if not date :zone "+0200" "date" "time" "20:44:43" { - test_fail "zone is not applied"; + test_fail "zone is not applied"; } } test "Original Zone" { if not date :originalzone "date" "zone" "+0300" { if date :matches :originalzone "date" "zone" "*" {} - test_fail "zone is incorrect: ${0}"; + test_fail "zone is incorrect: ${0}"; } if not date :originalzone "date" "time" "21:44:43" { - test_fail "time should be left untouched"; + test_fail "time should be left untouched"; } } test "Local Zone Shift" { - if anyof ( - allof ( + if anyof ( + allof ( string "${local_zone}" "+0200", date "delivery-date" "iso8601" "2009-07-23T05:30:14+08:00"), - allof ( + allof ( not string "${local_zone}" "+0200", date "delivery-date" "iso8601" "2009-07-22T23:30:14+02:00")) { - - if date :matches "delivery-date" "iso8601" "*" + + if date :matches "delivery-date" "iso8601" "*" { set "a" "${0}"; } - if date :originalzone :matches "delivery-date" "iso8601" "*" + if date :originalzone :matches "delivery-date" "iso8601" "*" { set "b" "${0}"; } test_fail "time not shifted to local zone: ${b} => ${a}"; diff --git a/tests/extensions/editheader/addheader.svtest b/tests/extensions/editheader/addheader.svtest index c0da0ff552d920273e6a1fd25612d3251854bf6f..1ce7d44471ba784eb96ffc8900f740ece1929f53 100644 --- a/tests/extensions/editheader/addheader.svtest +++ b/tests/extensions/editheader/addheader.svtest @@ -28,7 +28,7 @@ test "Addheader - first" { if not size :over 76 { test_fail "mail is not larger"; } - + if size :over 107 { test_fail "mail is too large"; } @@ -63,7 +63,7 @@ test "Addheader - first" { if not size :over 76 { test_fail "stored mail is not larger"; } - + if size :over 107 { test_fail "stored mail is too large"; } @@ -74,7 +74,7 @@ test "Addheader - first" { if not header :is "subject" "Frop!" { test_fail "original subject header not retained in stored mail"; - } + } if not exists "x-some-header" { test_fail "header not in stored mail"; @@ -94,7 +94,7 @@ test "Addheader - first" { if not header :is "subject" "Frop!" { test_fail "original subject header not retained in redirected mail"; - } + } if not exists "x-some-header" { test_fail "header not in redirected mail"; @@ -121,7 +121,7 @@ test "Addheader - last" { if not size :over 76 { test_fail "mail is not larger"; } - + if size :over 107 { test_fail "mail is too large"; } @@ -156,7 +156,7 @@ test "Addheader - last" { if not size :over 76 { test_fail "stored mail is not larger"; } - + if size :over 107 { test_fail "stored mail is too large"; } @@ -167,7 +167,7 @@ test "Addheader - last" { if not header :is "subject" "Frop!" { test_fail "original subject header not retained in stored mail"; - } + } if not exists "x-some-header" { test_fail "header not in stored mail"; @@ -187,7 +187,7 @@ test "Addheader - last" { if not header :is "subject" "Frop!" { test_fail "original subject header not retained in redirected mail"; - } + } if not exists "x-some-header" { test_fail "header not in redirected mail"; @@ -215,7 +215,7 @@ test "Addheader - framed" { if not size :over 76 { test_fail "mail is not larger"; } - + if size :over 160 { test_fail "mail is too large"; } @@ -258,7 +258,7 @@ test "Addheader - framed" { if not size :over 76 { test_fail "stored mail is not larger"; } - + if size :over 160 { test_fail "stored mail is too large"; } @@ -269,7 +269,7 @@ test "Addheader - framed" { if not header :is "subject" "Frop!" { test_fail "original subject header not retained in stored mail"; - } + } if not exists "x-some-header-first" { test_fail "first header not in stored mail"; @@ -297,7 +297,7 @@ test "Addheader - framed" { if not header :is "subject" "Frop!" { test_fail "original subject header not retained in redirected mail"; - } + } if not exists "x-some-header-first" { test_fail "first header not in redirected mail"; @@ -332,7 +332,7 @@ test "Addheader - folded" { set "after" "This is somewhat longer header content, folded to fit inside multiple header lines. This may cause problems, so that is why it is tested here."; - addheader "X-Some-Header-first" "${before}"; + addheader "X-Some-Header-first" "${before}"; addheader :last "X-Some-Header-last" "${after}"; if not header :is "subject" "Frop!" { @@ -367,7 +367,7 @@ test "Addheader - folded" { if not header :is "subject" "Frop!" { test_fail "original subject header not retained in redirected mail"; - } + } if not exists "x-some-header-first" { test_fail "first header not in redirected mail"; @@ -419,7 +419,7 @@ This is somewhat longer header content set "after_out" "This is somewhat longer header content containing newlines. This may cause some problems, so that is why it is tested here."; - addheader "X-Some-Header-first" "${before}"; + addheader "X-Some-Header-first" "${before}"; addheader :last "X-Some-Header-last" "${after}"; if not header :is "subject" "Frop!" { @@ -454,7 +454,7 @@ This is somewhat longer header content if not header :is "subject" "Frop!" { test_fail "original subject header not retained in redirected mail"; - } + } if not exists "x-some-header-first" { test_fail "first header not in redirected mail"; @@ -498,7 +498,7 @@ test "Addheader - implicit keep" { if not size :over 76 { test_fail "stored mail is not larger"; } - + if size :over 107 { test_fail "stored mail is too large"; } diff --git a/tests/extensions/editheader/alternating.svtest b/tests/extensions/editheader/alternating.svtest index 339f9a09c59f7229547d4e1ee2247b67690b8292..cef84c4860d595b6d2e6b510dd6c5bad186c9239 100644 --- a/tests/extensions/editheader/alternating.svtest +++ b/tests/extensions/editheader/alternating.svtest @@ -56,7 +56,7 @@ test "Alternating - add; delete" { if not header :is "x-some-header" "Header content" { test_fail "wrong content in redirected mail "; } - + /* stored message message */ if not test_message :folder "folder1" 0 { @@ -105,7 +105,7 @@ test "Alternating - delete; add" { if exists "subject" { test_fail "deleted header still present redirected mail"; } - + /* stored message message */ if not test_message :folder "folder2" 0 { diff --git a/tests/extensions/editheader/deleteheader.svtest b/tests/extensions/editheader/deleteheader.svtest index f2f12dbdf1ab88a5e11ae57cb13c0431e9b033a9..7a0ec43f39963868de20fd2e1504aaff20a7e13d 100644 --- a/tests/extensions/editheader/deleteheader.svtest +++ b/tests/extensions/editheader/deleteheader.svtest @@ -84,7 +84,7 @@ test "Deleteheader - nonexistent" { if not header :is "subject" "Frop!" { test_fail "original subject header not retained in redirected mail"; - } + } if not header :is "X-B" "omdat dit anders" { test_fail "original X-B header not retained in redirected mail"; @@ -177,7 +177,7 @@ test "Deleteheader - one" { if not header :is "subject" "Frop!" { test_fail "original subject header not retained in redirected mail"; - } + } if not header :is "X-B" "omdat dit anders" { test_fail "original X-B header not retained in redirected mail"; @@ -274,7 +274,7 @@ test "Deleteheader - two (first)" { if not header :is "subject" "Frop!" { test_fail "original subject header not retained in redirected mail"; - } + } if not header :is "X-B" "omdat dit anders" { test_fail "original X-B header not retained in redirected mail"; @@ -937,9 +937,9 @@ test "Deleteheader - folded" { test_set "message" text: From: stephan@example.org To: nico@frop.example.com -Subject: Help +Subject: Help X-A: Text -X-B: Text +X-B: Text Text . diff --git a/tests/extensions/editheader/errors.svtest b/tests/extensions/editheader/errors.svtest index 3e2ff4dc9b749ead4f82837a66288c963760ee22..b7d4136c54a7dea00e05b9f4cf50f125694d300a 100644 --- a/tests/extensions/editheader/errors.svtest +++ b/tests/extensions/editheader/errors.svtest @@ -36,7 +36,7 @@ test "Invalid field-name at runtime " { } if test_script_run { - test_fail "run should have failed"; + test_fail "run should have failed"; } if not test_error :count "eq" :comparator "i;ascii-numeric" "1" { @@ -94,7 +94,7 @@ test "Size limit" { if not test_error :count "eq" :comparator "i;ascii-numeric" "2" { test_fail "wrong number of errors reported"; - } + } } @@ -127,7 +127,7 @@ test "Size limit at runtime" { if not test_error :count "eq" :comparator "i;ascii-numeric" "1" { test_fail "wrong number of errors reported"; - } + } } /* @@ -153,7 +153,7 @@ test "Implicit keep at runtime error" { } if test_result_execute { - test_fail "result execution should have failed"; + test_fail "result execution should have failed"; } if not test_message :folder "INBOX" 0 { diff --git a/tests/extensions/editheader/errors/command-syntax.sieve b/tests/extensions/editheader/errors/command-syntax.sieve index 34d7f1e591dc878955aafc9afa8a81940939fd33..8543e6d46599725d408c768d9c531dfc017088b5 100644 --- a/tests/extensions/editheader/errors/command-syntax.sieve +++ b/tests/extensions/editheader/errors/command-syntax.sieve @@ -39,4 +39,4 @@ deleteheader :matches "x-frop"; # 9: value patterns not a string(list) deleteheader "x-frop" 1; - + diff --git a/tests/extensions/editheader/protected.svtest b/tests/extensions/editheader/protected.svtest index 70a0a6fa8675e95a0088a25dd4367bec6affa5fb..e21415b02539c5da3c626975e643cab937f6363c 100644 --- a/tests/extensions/editheader/protected.svtest +++ b/tests/extensions/editheader/protected.svtest @@ -29,14 +29,14 @@ test "Default protected" { deleteheader "received"; deleteheader "auto-submitted"; - + if not exists "received" { test_fail "protected received header was deleted"; - } + } if not exists "auto-submitted" { test_fail "protected auto-submitted header was deleted"; - } + } } test_config_set "sieve_editheader_protected" "subject delivery-date x-frop"; @@ -59,14 +59,14 @@ test "Configured protected" { deleteheader "delivery-date"; deleteheader "subject"; addheader "x-frop" "Frop!"; - + if not exists "delivery-date" { test_fail "protected delivery-date header was deleted"; - } + } if exists "subject" { test_fail "subject header cannot be protected, but it was not deleted"; - } + } if exists "x-frop" { test_fail "protected x-frop header was added"; diff --git a/tests/extensions/encoded-character.svtest b/tests/extensions/encoded-character.svtest index 5d1e3368ae27a30e4d0e62859aeeab760144873d..150d812513386d1df7000f4cf5b72e0ca6fee3eb 100644 --- a/tests/extensions/encoded-character.svtest +++ b/tests/extensions/encoded-character.svtest @@ -141,7 +141,7 @@ test "RFC Examples" { if not string "${HEX: 40}" "@" { test_fail "failed RFC example 3"; } - + if not string "${hex:40" "${hex:40" { test_fail "failed RFC example 4"; } @@ -157,7 +157,7 @@ test "RFC Examples" { if not string "${unicode:40}" "@" { test_fail "failed RFC example 7"; } - + if not string "${ unicode:40}" "${ unicode:40}" { test_fail "failed RFC example 8"; } diff --git a/tests/extensions/enotify/basic.svtest b/tests/extensions/enotify/basic.svtest index 80bb93657e7ce27a3fb928160d3a243a5e80525b..2a03aeea2ea5afd2c92d6ad0146b1d69f6c86b62 100644 --- a/tests/extensions/enotify/basic.svtest +++ b/tests/extensions/enotify/basic.svtest @@ -3,13 +3,13 @@ require "enotify"; test "Execute" { /* Test to catch runtime segfaults */ - if valid_notify_method + if valid_notify_method "mailto:stephan@example.com" { /* Test to catch runtime segfaults */ - notify + notify :message "This is probably very important" - :importance "1" + :importance "1" "mailto:stephan@example.com%2cstephan@example.org?subject=Important%20message%20received"; } } diff --git a/tests/extensions/enotify/errors/uri-mailto.sieve b/tests/extensions/enotify/errors/uri-mailto.sieve index f29b472ee73871f846961605b838d7fd1aa85a2a..2aced861005238cd27d443611b7864fbe4756411 100644 --- a/tests/extensions/enotify/errors/uri-mailto.sieve +++ b/tests/extensions/enotify/errors/uri-mailto.sieve @@ -9,7 +9,7 @@ notify "mailto:stephan@example.org?header<=frop"; # 3: Invalid character in hvalue notify "mailto:stephan@example.org?header=fr>op"; -# 4: Invalid header name +# 4: Invalid header name notify "mailto:stephan@example.org?header:=frop"; # 5: Invalid recipient diff --git a/tests/extensions/enotify/mailto.svtest b/tests/extensions/enotify/mailto.svtest index 0535e95da52dff22962dd14ec970f1c118306cbc..e0388c0f2b50b1d955e1a6c9f41e0f5c295fa994 100644 --- a/tests/extensions/enotify/mailto.svtest +++ b/tests/extensions/enotify/mailto.svtest @@ -80,11 +80,11 @@ test "Multiple recipients" { if not address :count "eq" :comparator "i;ascii-numeric" "to" "2" { test_fail "too many recipients in To header"; - } + } if not address :count "eq" :comparator "i;ascii-numeric" "cc" "1" { test_fail "too many recipients in Cc header"; - } + } if not header "subject" "Frop received" { test_fail "subject header set incorrectly"; @@ -211,11 +211,11 @@ test "Envelope" { if not envelope :is "to" "timo@example.com" { test_fail "envelope sender set incorrectly"; - } + } } -/* - * Envelope :from +/* + * Envelope :from */ test_set "message" text: @@ -258,11 +258,11 @@ test "Envelope :from" { if not envelope :is "to" "timo@example.com" { test_fail "envelope sender set incorrectly"; - } + } } -/* - * Envelope <> +/* + * Envelope <> */ test_set "message" text: @@ -305,5 +305,5 @@ test "Envelope <>" { if not envelope :is "to" "timo@example.com" { test_fail "envelope sender set incorrectly"; - } + } } diff --git a/tests/extensions/enotify/valid_notify_method.svtest b/tests/extensions/enotify/valid_notify_method.svtest index 4d247705f84055f1b1bcdfd18d5249a7bcfc10f4..35255d6d2d9fc75aa1d29101091ec8ad45d73ed1 100644 --- a/tests/extensions/enotify/valid_notify_method.svtest +++ b/tests/extensions/enotify/valid_notify_method.svtest @@ -3,14 +3,14 @@ require "vnd.dovecot.testsuite"; require "enotify"; test "Mailto: invalid header name" { - if valid_notify_method + if valid_notify_method "mailto:stephan@example.org?header:=frop" { test_fail "invalid uri accepted"; } } test "Mailto: invalid recipient" { - if valid_notify_method + if valid_notify_method "mailto:stephan%23example.org" { test_fail "invalid uri accepted"; } diff --git a/tests/extensions/envelope.svtest b/tests/extensions/envelope.svtest index 8076070672666f2979fa32b46f644e356a3bf2d3..0a6ff4970815ee8be9453b86f6a69b3f8aa3bc71 100644 --- a/tests/extensions/envelope.svtest +++ b/tests/extensions/envelope.svtest @@ -100,7 +100,7 @@ test "Envelope - invalid paths" { } /* - * Syntax errors + * Syntax errors */ test "Envelope - syntax errors" { @@ -157,7 +157,7 @@ test "Envelope - source route" { if not envelope :localpart :is "from" "stephan" { test_fail "parsing path with source route (dual) failed"; } - + /* Multiple */ test_set "envelope.from" "<@cola.example.org,@mx.utwente.nl,@smtp.example.net:stephan@example.org>"; if not envelope :localpart :is "from" "stephan" { @@ -168,7 +168,7 @@ test "Envelope - source route" { test_set "envelope.from" "@cola.example.org,@mx.utwente.nl,@smtp.example.net:stephan@example.org"; if not envelope :domain :is "from" "example.org" { test_fail "parsing path with source route (bare) failed"; - } + } /* Whitespace */ test_set "envelope.from" " < @ cola . example . org , @ mx . utwente . nl , @ smtp . iki . fi : stephan @ example . org > "; diff --git a/tests/extensions/environment/rfc.svtest b/tests/extensions/environment/rfc.svtest index 598ca56aca3f99c5e76dfab6be11e37a2c566510..70e38a6b41f4eebf9624284062f1e09317b64054 100644 --- a/tests/extensions/environment/rfc.svtest +++ b/tests/extensions/environment/rfc.svtest @@ -4,7 +4,7 @@ require "relational"; test "Non-existent" { if environment :contains "nonsense" "" { - test_fail "matched unknown environment item"; + test_fail "matched unknown environment item"; } } @@ -21,7 +21,7 @@ test "Count" { ) { test_fail "count should not match unknown environment item"; } - + if not environment :count "eq" "host" "1" { test_fail "count of non-empty environment should be 1"; } diff --git a/tests/extensions/imap4flags/basic.svtest b/tests/extensions/imap4flags/basic.svtest index 07b1a3d2d01d5b33b6e8b547991bf717f7624ebf..bb0154bffd7cfe0f46e0ebb6c890561de65cdf28 100644 --- a/tests/extensions/imap4flags/basic.svtest +++ b/tests/extensions/imap4flags/basic.svtest @@ -78,7 +78,7 @@ test "Flag operations" { if not hasflag "B" { test_fail "flag \"B\" not added"; } - + if not hasflag "A" { test_fail "flag \"A\" not retained"; } @@ -87,7 +87,7 @@ test "Flag operations" { test_fail "hasflag sees more than two flags"; } - addflag ["C", "D", "E F"]; + addflag ["C", "D", "E F"]; if not hasflag :comparator "i;ascii-numeric" :count "eq" "6" { test_fail "hasflag sees more than two flags"; @@ -97,8 +97,8 @@ test "Flag operations" { if not hasflag :comparator "i;ascii-numeric" :count "eq" "5" { test_fail "hasflag sees more than two flags"; - } - + } + if hasflag "D" { test_fail "removed flag still present"; } @@ -137,7 +137,7 @@ test "Removal: one" { removeflag "\\seen"; - if hasflag "\\seen" { + if hasflag "\\seen" { test_fail "flag not removed"; } @@ -155,13 +155,13 @@ test "Removal: first" { removeflag "$frop"; - if not hasflag "\\seen" { + if not hasflag "\\seen" { test_fail "wrong flag removed"; } - if hasflag "$frop" { + if hasflag "$frop" { test_fail "flag not removed"; - } + } if not hasflag :comparator "i;ascii-numeric" :count "eq" "1" { test_fail "more than one flag remains set"; diff --git a/tests/extensions/imap4flags/execute.svtest b/tests/extensions/imap4flags/execute.svtest index 8383e31bb704ddbc1481d50bd90b580ab3fcd720..1ee1906bacd822779c27df43b3db04f1a7819894 100644 --- a/tests/extensions/imap4flags/execute.svtest +++ b/tests/extensions/imap4flags/execute.svtest @@ -20,49 +20,49 @@ test "Flags Side Effect" { } if not test_result_execute { - test_fail "result execute failed"; + test_fail "result execute failed"; } test_result_reset; if not test_message :folder "INBOX.Junk" 0 { - test_fail "message not stored in INBOX.Junk"; + test_fail "message not stored in INBOX.Junk"; } if not hasflag :count "eq" "1" { - test_fail "invalid number of flags for message in INBOX.Junk"; + test_fail "invalid number of flags for message in INBOX.Junk"; } if not hasflag :is "NONSENSE" { - test_fail "invalid flag set for message in INBOX.Junk"; + test_fail "invalid flag set for message in INBOX.Junk"; } test_result_reset; if not test_message :folder "INBOX" 0 { - test_fail "message not stored in INBOX"; + test_fail "message not stored in INBOX"; } if not hasflag :count "eq" "1" { - test_fail "invalid number of flags for message in INBOX"; + test_fail "invalid number of flags for message in INBOX"; } if not hasflag :is "\\seen" { - test_fail "invalid flag set for message in INBOX"; + test_fail "invalid flag set for message in INBOX"; } test_result_reset; if not test_message :folder "INBOX.Nonsense" 0 { - test_fail "message not stored in INBOX.Nonsense"; + test_fail "message not stored in INBOX.Nonsense"; } if not hasflag :count "eq" "1" { - test_fail "invalid number of flags for message in Inbox.Nonsense"; + test_fail "invalid number of flags for message in Inbox.Nonsense"; } if not hasflag :is "IMPLICIT" { - test_fail "invalid flag set for message in Inbox.Nonsene"; + test_fail "invalid flag set for message in Inbox.Nonsene"; } } diff --git a/tests/extensions/imap4flags/execute/flags-side-effect.sieve b/tests/extensions/imap4flags/execute/flags-side-effect.sieve index f7a91d44981ba79f490f0d33645054c4176ca534..17de0ad017926c599a81e60821d504f345e3cb08 100644 --- a/tests/extensions/imap4flags/execute/flags-side-effect.sieve +++ b/tests/extensions/imap4flags/execute/flags-side-effect.sieve @@ -1,8 +1,8 @@ -require "imap4flags"; +require "imap4flags"; require "fileinto"; /* - * When keep/fileinto is used multiple times in a script and duplicate + * When keep/fileinto is used multiple times in a script and duplicate * message elimination is performed, the last flag list value MUST win. */ diff --git a/tests/extensions/imap4flags/hasflag.svtest b/tests/extensions/imap4flags/hasflag.svtest index 4d07312a1b4c1877c5b3fc373960a792d4d16d0f..10881907ded807af65a46a569a708f9e775c6410 100644 --- a/tests/extensions/imap4flags/hasflag.svtest +++ b/tests/extensions/imap4flags/hasflag.svtest @@ -33,7 +33,7 @@ test "Multiple variables" { /* * RFC examples - */ + */ test "RFC hasflag example - :is" { setflag "A B"; @@ -41,7 +41,7 @@ test "RFC hasflag example - :is" { if not hasflag ["b","A"] { test_fail "list representation did not match"; } - + if not hasflag :is "b A" { test_fail "string representation did not match"; } @@ -57,11 +57,11 @@ test "RFC hasflag example - :contains variable" { if not hasflag :contains "MyVar" "forward" { test_fail "failed true example 2"; } - + if not hasflag :contains "MyVar" ["label", "forward"] { test_fail "failed true example 3"; } - + if not hasflag :contains "MyVar" ["junk", "forward"] { test_fail "failed true example 4"; } diff --git a/tests/extensions/imap4flags/multiscript.svtest b/tests/extensions/imap4flags/multiscript.svtest index cdadea62ee85570108a3e6bda0b20fe01cb662bd..5080eda77da336198059e434ce52bceeda8974e8 100644 --- a/tests/extensions/imap4flags/multiscript.svtest +++ b/tests/extensions/imap4flags/multiscript.svtest @@ -8,11 +8,11 @@ require "fileinto"; test "Segfault Trigger 1" { if not test_multiscript [ - "multiscript/group-spam.sieve", - "multiscript/spam.sieve", + "multiscript/group-spam.sieve", + "multiscript/spam.sieve", "multiscript/sent-store.sieve"] { - test_fail "failed multiscript execution"; + test_fail "failed multiscript execution"; } } @@ -31,15 +31,15 @@ test "Internal Flags" { } if not test_multiscript [ - "multiscript/setflag.sieve", + "multiscript/setflag.sieve", "multiscript/fileinto.sieve"] { - test_fail "failed multiscript execution"; + test_fail "failed multiscript execution"; } - - test_result_reset; + + test_result_reset; test_message :folder "folder" 0; - + if not hasflag "\\answered" { test_fail "\\answered flag not stored for message"; } diff --git a/tests/extensions/include/execute.svtest b/tests/extensions/include/execute.svtest index 7ee4b7b024e9161398b9863d4d39c5b3d13b5376..3d91423321258ccb4b52b485f31893fbc93fcb40 100644 --- a/tests/extensions/include/execute.svtest +++ b/tests/extensions/include/execute.svtest @@ -14,7 +14,7 @@ Frop. test "Actions Fileinto" { test_mailbox_create "aaaa"; test_mailbox_create "bbbb"; - + if not test_script_compile "execute/actions-fileinto.sieve" { test_fail "failed to compile sieve script"; } @@ -34,13 +34,13 @@ test "Actions Fileinto" { if not header "subject" "Frop!" { test_fail "fileinto \"aaaa\" not executed."; - } + } test_message :folder "bbbb" 0; if not header "subject" "Frop!" { test_fail "fileinto \"bbbb\" not executed."; - } + } } test "Namespace - file" { diff --git a/tests/extensions/regex/basic.svtest b/tests/extensions/regex/basic.svtest index a78abfac2cedb948d2f0a474c4a1bc5af96ab41a..941743478f87979c16e12f8eeffe2232deb2f587 100644 --- a/tests/extensions/regex/basic.svtest +++ b/tests/extensions/regex/basic.svtest @@ -14,8 +14,8 @@ Test message. test "Basic example" { if not address :regex :comparator "i;ascii-casemap" "from" [ - "stephan(\\+.*)?@it\\.example\\.com", - "stephan(\\+.*)?@friep\\.example\\.com" + "stephan(\\+.*)?@it\\.example\\.com", + "stephan(\\+.*)?@friep\\.example\\.com" ] { test_fail "failed to match"; } @@ -25,7 +25,7 @@ test "No values" { if header :regex "cc" [".*\\.com", ".*\\.nl"] { test_fail "matched inappropriately"; } -} +} test "More values" { @@ -48,4 +48,4 @@ test "Variable regex" { if not string "${1}" "sieve" { test_fail "failed to extract proper match value from variable regex"; } -} +} diff --git a/tests/extensions/regex/match-values.svtest b/tests/extensions/regex/match-values.svtest index 344c7c95a7393ca05e319e208fffda7b728b9375..18b7404cb371fffdbfae6cb39ad6a6c6072e7e3c 100644 --- a/tests/extensions/regex/match-values.svtest +++ b/tests/extensions/regex/match-values.svtest @@ -20,15 +20,15 @@ test "Basic match values 1" { if not string :is "${1}" "antlr" { test_fail "first match value is not correct"; - } + } if not string :is "${2}" "interest" { test_fail "second match value is not correct"; - } + } if not string :is "${3}" "-bounces" { test_fail "third match value is not correct"; - } + } if string :is "${4}" "-bounces" { test_fail "fourth match contains third value"; @@ -47,15 +47,15 @@ test "Basic match values 2" { if not string :is "${2}" "antlr" { test_fail "second match value is not correct: ${2}"; - } + } if not string :is "${3}" "interest" { test_fail "third match value is not correct: ${3}"; - } + } if not string :is "${4}" "-bounces" { test_fail "fourth match value is not correct: ${4}"; - } + } if string :is "${5}" "-bounces" { test_fail "fifth match contains fourth value: ${5}"; diff --git a/tests/extensions/relational/basic.svtest b/tests/extensions/relational/basic.svtest index c13681179f27d87c9a7aa976f72d9b5d71a37cf7..288661a77c60b64e627ab404a6ea36bde6dbc30f 100644 --- a/tests/extensions/relational/basic.svtest +++ b/tests/extensions/relational/basic.svtest @@ -3,7 +3,7 @@ require "vnd.dovecot.testsuite"; require "relational"; require "comparator-i;ascii-numeric"; -/* +/* * Test message */ @@ -43,7 +43,7 @@ X-Count: x X-Count: y X-Count: z Subject: Test -Comment: +Comment: Test! . @@ -67,14 +67,14 @@ test "Value \"\" eq 40 (vs)" { } } -/* +/* * Match type :value */ test "Value 300 eq 2" { if header :value "eq" :comparator "i;ascii-numeric" "x-spam-score" "2" { test_fail "should not have matched"; - } + } } test "Value 300 lt 2" { @@ -143,7 +143,7 @@ test "Value abcdzyz gt aaaaaaa" { } } -/* +/* * Match type :count */ diff --git a/tests/extensions/relational/comparators.svtest b/tests/extensions/relational/comparators.svtest index 96ab213471faac5282d9d64e788d29be8a39294b..60480448ead5e478eb50f60723c4a9cce3fbc11c 100644 --- a/tests/extensions/relational/comparators.svtest +++ b/tests/extensions/relational/comparators.svtest @@ -199,7 +199,7 @@ test "i;ascii-numeric" { if not string :comparator "i;ascii-numeric" :value "eq" "0" "0" { test_fail "not '0' eq '0'"; } - + /* Digit characters; basic comparison */ if not string :comparator "i;ascii-numeric" :value "eq" "2" "2" { @@ -208,7 +208,7 @@ test "i;ascii-numeric" { if not string :comparator "i;ascii-numeric" :value "gt" "2" "1" { test_fail "not '2' gt '1'"; - } + } if not string :comparator "i;ascii-numeric" :value "lt" "1" "2" { test_fail "not '1' lt '2'"; @@ -220,39 +220,39 @@ test "i;ascii-numeric" { if not string :comparator "i;ascii-numeric" :value "gt" "65635" "65535" { test_fail "not '65635' gt '65535'"; - } + } /* Digit characters; leading zeros */ if not string :comparator "i;ascii-numeric" :value "eq" "0" "000" { test_fail "not '0' eq '000'"; - } + } if not string :comparator "i;ascii-numeric" :value "eq" "000" "0" { test_fail "not '0' eq '000'"; - } + } if not string :comparator "i;ascii-numeric" :value "eq" "02" "0002" { test_fail "not '02' eq '0002'"; - } + } if not string :comparator "i;ascii-numeric" :value "eq" "0002" "02" { test_fail "not '0002' eq '02'"; - } + } if not string :comparator "i;ascii-numeric" :value "gt" "2" "001" { test_fail "not '2' gt '001'"; - } + } if not string :comparator "i;ascii-numeric" :value "lt" "001" "2" { test_fail "not '001' lt '2'"; - } + } if not string :comparator "i;ascii-numeric" :value "gt" "002" "1" { test_fail "not '002' gt '1'"; - } + } if not string :comparator "i;ascii-numeric" :value "lt" "1" "002" { test_fail "not '1' lt '002'"; - } + } } diff --git a/tests/extensions/relational/errors/validation.sieve b/tests/extensions/relational/errors/validation.sieve index e632a46f76447b9bfba860adb6652b05bb533b6f..f355097ac43cd86f496aadf3e96f656f67960d34 100644 --- a/tests/extensions/relational/errors/validation.sieve +++ b/tests/extensions/relational/errors/validation.sieve @@ -3,7 +3,7 @@ require "relational"; # Not a valid relation (1) if header :value "gr" "from" "ah" { keep; -} +} # Not a valid relation (1) if header :count "lf" "from" "eek" { diff --git a/tests/extensions/relational/rfc.svtest b/tests/extensions/relational/rfc.svtest index f092931931041b09f6f2a2a51bb92ad09e837421..bc055161d4ff3c4acdf956705042ea42ccde5e45 100644 --- a/tests/extensions/relational/rfc.svtest +++ b/tests/extensions/relational/rfc.svtest @@ -19,19 +19,19 @@ test "Example 1" { if not address :count "ge" :comparator "i;ascii-numeric" ["to", "cc"] ["3"] { - + test_fail "should have counted three addresses"; } # would evaluate to true, and the test - if anyof ( + if anyof ( address :count "ge" :comparator "i;ascii-numeric" ["to"] ["3"], address :count "ge" :comparator "i;ascii-numeric" - ["cc"] ["3"] + ["cc"] ["3"] ) { - + test_fail "should not have counted three addresses"; } @@ -42,7 +42,7 @@ test "Example 1" { if header :count "ge" :comparator "i;ascii-numeric" ["received"] ["3"] { - + test_fail "should not have counted three received headers"; } @@ -55,7 +55,7 @@ test "Example 1" { } # would evaluate to true. - + # The test: if header :count "ge" :comparator "i;ascii-numeric" diff --git a/tests/extensions/spamvirustest/spamtest.svtest b/tests/extensions/spamvirustest/spamtest.svtest index 458dc626592d22f9a326c0f2ca1acc024a65dd6b..11ffdeefd2cabee720b79d87dce215ae46daff2f 100644 --- a/tests/extensions/spamvirustest/spamtest.svtest +++ b/tests/extensions/spamvirustest/spamtest.svtest @@ -136,7 +136,7 @@ test_set "message" text: From: legitimate@example.com To: victim@dovecot.example.net Subject: Not spammish -X-Spam-Status: +X-Spam-Status: X-Spam-Status1: s X-Spam-Status2: sssssss X-Spam-Status3: ssssssss diff --git a/tests/extensions/subaddress/basic.svtest b/tests/extensions/subaddress/basic.svtest index b74992b98d82b1e5e39b356bc4282f32abc9bc01..e62d65d1aeadc88fc21e5a1d791653940c6ddc0e 100644 --- a/tests/extensions/subaddress/basic.svtest +++ b/tests/extensions/subaddress/basic.svtest @@ -106,6 +106,6 @@ test "No detail" { } if address :detail "from" "virus" { - test_fail ":detail matched non-existent detail element in from header (separator is missing)"; + test_fail ":detail matched non-existent detail element in from header (separator is missing)"; } } diff --git a/tests/extensions/subaddress/rfc.svtest b/tests/extensions/subaddress/rfc.svtest index 3651ffdf09d5538a5bc55a5163c4455e0aa91733..5615c534ae54c6753ce9b18607dd671d3b2a516c 100644 --- a/tests/extensions/subaddress/rfc.svtest +++ b/tests/extensions/subaddress/rfc.svtest @@ -44,7 +44,7 @@ test "User sub-part" { test "Detail sub-part" { if not address :detail "to" "spam" { test_fail "wrong :detail part extracted"; - } + } if anyof ( address :detail :matches "cc" ["*", "?"], @@ -55,5 +55,5 @@ test "Detail sub-part" { if not address :detail "from" "" { test_fail "wrong empty :detail part extracted"; - } + } } diff --git a/tests/extensions/vacation/execute.svtest b/tests/extensions/vacation/execute.svtest index b28aeb5ad0214d3bec440d8e66fb93ab6ee14b97..3d3f4a5196bdb5779697e5cd377412e32afb84bb 100644 --- a/tests/extensions/vacation/execute.svtest +++ b/tests/extensions/vacation/execute.svtest @@ -18,7 +18,7 @@ test "Action" { if not test_result_action :index 1 "vacation" { test_fail "vacation action is not present as first item in result"; } - + if not test_result_action :index 2 "keep" { test_fail "keep action is missing in result"; } @@ -61,7 +61,7 @@ test "Using :seconds tag" { if not test_result_action :index 1 "vacation" { test_fail "vacation action is not present as first item in result"; } - + if not test_result_action :index 2 "keep" { test_fail "keep action is missing in result"; } diff --git a/tests/extensions/vacation/execute/no-handle.sieve b/tests/extensions/vacation/execute/no-handle.sieve index 13cb16812baa6109bb78670c1da9d21186e6ba18..0d37c54bc3e68a5988f811da26196ea3ebfd04cd 100644 --- a/tests/extensions/vacation/execute/no-handle.sieve +++ b/tests/extensions/vacation/execute/no-handle.sieve @@ -3,8 +3,8 @@ require "variables"; set "reason" "I have a conference in Seattle"; -vacation - :subject "I am not in: ${reason}" - :from "stephan@example.org" +vacation + :subject "I am not in: ${reason}" + :from "stephan@example.org" "I am gone for today: ${reason}."; diff --git a/tests/extensions/vacation/message.svtest b/tests/extensions/vacation/message.svtest index 6cf7b7a4df84d3963a9859082132f8b60538e362..0f3668c451200b5d299e4e28caa90ec39b3db1df 100644 --- a/tests/extensions/vacation/message.svtest +++ b/tests/extensions/vacation/message.svtest @@ -28,12 +28,12 @@ test "References" { test_fail "references header does not contain new id"; } - if anyof ( - not header :contains "references" "1234@local.machine.example", + if anyof ( + not header :contains "references" "1234@local.machine.example", not header :contains "references" "3456@example.net", - not header :contains "references" "435444@ttms.example.org", - not header :contains "references" "4223@froop.example.net", - not header :contains "references" "m345444444@message-id.exp" + not header :contains "references" "435444@ttms.example.org", + not header :contains "references" "4223@froop.example.net", + not header :contains "references" "m345444444@message-id.exp" ) { test_fail "references header does not contain all existing ids"; } diff --git a/tests/extensions/vacation/reply.svtest b/tests/extensions/vacation/reply.svtest index c4d0aa593b24cfeb98ddb82ce3b995fbd8f738c0..58463d33a6d0a3aca3491f81473d768b023ec903 100644 --- a/tests/extensions/vacation/reply.svtest +++ b/tests/extensions/vacation/reply.svtest @@ -270,7 +270,7 @@ test "Reply for normal mail" { } /* - * Reply for :addresses + * Reply for :addresses */ test_result_reset; diff --git a/tests/extensions/vacation/utf-8.svtest b/tests/extensions/vacation/utf-8.svtest index 2417a67b3b1daa98e7ae5989facb95cb75e5a3f1..6697849f12d7ad3d98e89cb2e99e917cf16f0e00 100644 --- a/tests/extensions/vacation/utf-8.svtest +++ b/tests/extensions/vacation/utf-8.svtest @@ -17,7 +17,7 @@ Frop test "UTF-8 Subject" { /* Trigger vacation response with rediculous Russian subject */ vacation :subject "Auto: Я могу еÑÑ‚ÑŒ Ñтекло, оно мне не вредит." - "I am not in today"; + "I am not in today"; /* Execute Sieve result (sending message to dummy SMTP) */ if not test_result_execute { @@ -60,7 +60,7 @@ Frop test "MIME Encoded Subject" { /* Trigger vacation response with rediculous Russian subject */ vacation :subject "=?utf-8?b?w4TDlsOc?= sadasd" - "I am not in today"; + "I am not in today"; /* Execute Sieve result (sending message to dummy SMTP) */ if not test_result_execute { diff --git a/tests/extensions/variables/basic.svtest b/tests/extensions/variables/basic.svtest index 2817357d51d26979544d84510c9e68b0f83e4b9d..f01aeeb92d19405f4e46156132b04b20a617de49 100644 --- a/tests/extensions/variables/basic.svtest +++ b/tests/extensions/variables/basic.svtest @@ -32,7 +32,7 @@ test "Unknown variables" { test "One pass" { set "something" "value"; set "s" "$"; - + if string "${s}{something}" "value" { test_fail "somehow variable string is scanned multiple times"; } @@ -46,7 +46,7 @@ test "Syntax errors" { set "s" "$"; set "variable" "nonsense"; - if anyof ( + if anyof ( not string "$" "${s}", not string "${" "${s}{", not string "${a" "${s}{a", @@ -57,12 +57,12 @@ test "Syntax errors" { not string "${doh!}" "${s}{doh!}" ) { test_fail "variables substitution changed substring not matching variable-ref"; - } + } } test "RFC syntax examples" { # The variable "company" holds the value "ACME". No other variables - # are set. + # are set. set "company" "ACME"; # "${full}" => the empty string @@ -80,7 +80,7 @@ test "RFC syntax examples" { test_fail "'BADACME' test did not yield expected result"; } - #"${President, ${Company} Inc.}" + #"${President, ${Company} Inc.}" # => "${President, ACME Inc.}" if not string "${President, ${Company} Inc.}" "${President, ACME Inc.}" { @@ -176,7 +176,7 @@ test "Multi-line string substitution" { set "name" "Stephan Bosch"; set "address" "stephan@example.org"; set "subject" "Test message"; - + set "message" text: # Message with substitutions From: ${name} <${address}> To: Bertus van Asseldonk <b.vanasseldonk@nl.example.com> @@ -217,7 +217,7 @@ test "Multiple substitutions" { if not string :is "${sentence}" "The monkey eats a nut" { test_fail "modified variable substitution failed"; - } + } } diff --git a/tests/extensions/variables/errors/limits.sieve b/tests/extensions/variables/errors/limits.sieve index ada93c4bdb21ad8c7d5274c9c8a9f04ce40315e7..3c9dbbd1da07ba623eef84d35ec5db9062f15a42 100644 --- a/tests/extensions/variables/errors/limits.sieve +++ b/tests/extensions/variables/errors/limits.sieve @@ -7,7 +7,7 @@ set "var123456789012345678901234567890" "value"; set "var123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" "value"; # Must yield unknown namespace error (no limit exceeded) (1) -set "namespace.sub.sub.variable" "value"; +set "namespace.sub.sub.variable" "value"; # Must yield unknown namespace error (exceeds element limit) (1) set "namespace.sub.sub.sub.variable" "value"; diff --git a/tests/extensions/variables/match.svtest b/tests/extensions/variables/match.svtest index fcbb1e98229043df01e0142856fe92ced26c424d..11c07010ba5f6b3289064384cfd80aa686f35e69 100644 --- a/tests/extensions/variables/match.svtest +++ b/tests/extensions/variables/match.svtest @@ -69,15 +69,15 @@ test "RFC - test short-circuit" { } } -# Test overwriting only on match +# Test overwriting only on match test "RFC - values overwrite" { set "sentence1" "the cat jumps off the table"; set "sentence2" "the dog barks at the cat in the alley"; if not string :matches "${sentence1}" "the * jumps off the *" { test_fail "failed to match first sentence"; - } - + } + if not string :is "${1}:${2}" "cat:table" { test_fail "invalid match values"; } @@ -102,14 +102,14 @@ test "RFC - values overwrite" { test "RFC - example" { test_set "message" text: Subject: [acme-users] [fwd] version 1.0 is out -List-Id: Dovecot Mailing List <dovecot@dovecot.example.net> +List-Id: Dovecot Mailing List <dovecot@dovecot.example.net> To: coyote@ACME.Example.COM Fom: stephan@example.org Test message. . ; - if header :matches "List-ID" "*<*@*" { + if header :matches "List-ID" "*<*@*" { if not string "INBOX.lists.${2}" "INBOX.lists.dovecot" { test_fail "incorrect match value: INBOX.lists.${2}"; } @@ -135,7 +135,7 @@ Test message. # Imagine the header # To: coyote@ACME.Example.COM - if address :matches ["To", "Cc"] ["coyote@**.com", + if address :matches ["To", "Cc"] ["coyote@**.com", "wile@**.com"] { # ${0} is the matching address # ${1} is always the empty string @@ -147,7 +147,7 @@ Test message. not string "${2}" "ACME.Example" ) { test_fail "invalid match values: ${0}, ${1}, ${2}"; - } + } } else { # Control wouldn't reach this block if any match was # successful, so no match variables are set at this @@ -159,7 +159,7 @@ Test message. if anyof (true, address :domain :matches "To" "*.com") { # The second test is never evaluated, so there are # still no match variables set. - + /* FIXME: not compliant */ } } @@ -173,7 +173,7 @@ set "match1" "Test of general stupidity"; test "Begin" { if not string :matches "${match1}" "Test of *" { test_fail "should have matched"; - } + } if not string :is "${1}" "general stupidity" { test_fail "match value incorrect"; @@ -203,7 +203,7 @@ set "match3" "ik ben een tukker met grote oren en een lelijke broek."; test "Multiple" { if not string :matches "${match3}" "ik ben * met * en *." { test_fail "should have matched"; - } + } set "line" "Hij is ${1} met ${2} en ${3}!"; @@ -218,7 +218,7 @@ set "match4" "beter van niet?"; test "Escape" { if not string :matches "${match4}" "*\\?" { test_fail "should have matched"; - } + } if not string :is "${1}" "beter van niet" { test_fail "match value incorrect: ${1}"; @@ -230,7 +230,7 @@ set "match5" "The quick brown fox jumps over the lazy dog."; test "Alphabet ?" { if not string :matches "${match5}" "T?? ????? ????? ?o? ?u??? o?er ?he ???? ?o?." { test_fail "should have matched"; - } + } set "alphabet" "${22}${8}${6}${25}${2}${13}${26}${1}${5}${15}${7}${21}${16}${12}${10}${17}${3}${9}${18}${20}${4}${19}${11}${14}${24}${23}"; @@ -262,9 +262,9 @@ test "Letters begin ?" { if not string :matches "${match7}" "??op" { test_fail "should have matched"; } - + set "val" "${0}:${1}:${2}:${3}:"; - + if not string :is "${val}" "frop:f:r::" { test_fail "incorrect match values: ${val}"; } @@ -290,7 +290,7 @@ test "Letters words *? - 1" { } set "val" ":${0}:${1}:${2}:${3}:${4}:${5}:"; - + if not string :is "${val}" ":klopfropstroptop:klop:o:p:strop::" { test_fail "incorrect match values: ${val}"; } @@ -300,7 +300,7 @@ test "Letters words *? - 2" { if not string :matches "${match8}" "?*fr??*top" { test_fail "should have matched"; } - + set "val" ":${0}:${1}:${2}:${3}:${4}:${5}:${6}:"; if not string :is "${val}" ":klopfropstroptop:k:lop:o:p:strop::" { @@ -314,7 +314,7 @@ test "Letters words *? backtrack" { } set "val" ":${0}:${1}:${2}:${3}:${4}:"; - + if not string :is "${val}" ":klopfropstroptop:klopfropstrop:t:::" { test_fail "incorrect match values: ${val}"; } diff --git a/tests/extensions/variables/modifiers.svtest b/tests/extensions/variables/modifiers.svtest index 6948aecabb946ec85e2008ac140ae895f4480144..60b174fa5955f42f5b748ee0474f1b46f79233e0 100644 --- a/tests/extensions/variables/modifiers.svtest +++ b/tests/extensions/variables/modifiers.svtest @@ -113,31 +113,31 @@ test "RFC examples" { if not string "${a}" "juMBlEd lETteRS" { test_fail "modified assignment failed (1): ${a}"; } - + set :length "b" "${a}"; # => "15" if not string "${b}" "15" { test_fail "modified assignment failed (2): ${a}"; } - + set :lower "b" "${a}"; # => "jumbled letters" if not string "${b}" "jumbled letters" { test_fail "modified assignment failed (3): ${a}"; } - + set :upperfirst "b" "${a}"; # => "JuMBlEd lETteRS" if not string "${b}" "JuMBlEd lETteRS" { test_fail "modified assignment failed (4): ${a}"; } - + set :upperfirst :lower "b" "${a}"; # => "Jumbled letters" if not string "${b}" "Jumbled letters" { test_fail "modified assignment failed (5): ${a}"; } - + set :quotewildcard "b" "Rock*"; # => "Rock\*" if not string "${b}" "Rock\\*" { test_fail "modified assignment failed (6): ${a}"; - } + } } /* RFC mentions `characters' and not octets */ diff --git a/tests/extensions/variables/quoting.svtest b/tests/extensions/variables/quoting.svtest index e9a23b0a032818028479f4fb5abee431286654b6..f65e4e458f4c7cb0b1064e9838593b2e06d215ce 100644 --- a/tests/extensions/variables/quoting.svtest +++ b/tests/extensions/variables/quoting.svtest @@ -12,7 +12,7 @@ test "Encodings - RFC examples" { test_fail "failed 'the expansion of variable foo (${s}{fo\\o})'"; } - # "${fo\\o}" => ${fo\o} => illegal identifier => left verbatim. + # "${fo\\o}" => ${fo\o} => illegal identifier => left verbatim. if not string :is "${fo\\o}" "${s}{fo\\o}" { test_fail "failed 'illegal identifier => left verbatim'"; } diff --git a/tests/extensions/variables/regex.svtest b/tests/extensions/variables/regex.svtest index 8e814b51af5d61bfb20b96d12b629d64e7712c1d..04ca00da2a242ec06d0ce4ab448f488f40ba89fc 100644 --- a/tests/extensions/variables/regex.svtest +++ b/tests/extensions/variables/regex.svtest @@ -3,15 +3,15 @@ require "vnd.dovecot.testsuite"; require "regex"; require "variables"; -# Test overwriting only on match +# Test overwriting only on match test "RFC - values overwrite" { set "sentence1" "the cat jumps off the table"; set "sentence2" "the dog barks at the cat in the alley"; if not string :regex "${sentence1}" "the (.*) jumps off the (.*)" { test_fail "failed to match first sentence"; - } - + } + if not string :is "${1}:${2}" "cat:table" { test_fail "invalid match values"; } diff --git a/tests/extensions/variables/string.svtest b/tests/extensions/variables/string.svtest index 13a99812848739e46b2447e7d18ff7d770c6195f..d0244e60612fa7df4c07ae2f852e608c33b71e44 100644 --- a/tests/extensions/variables/string.svtest +++ b/tests/extensions/variables/string.svtest @@ -22,7 +22,7 @@ test "RFC example" { if not string :matches " ${state} " "* pending *" { # the above test always succeeds - + test_fail "test should have matched: \" ${state} \""; } } diff --git a/tests/match-types/contains.svtest b/tests/match-types/contains.svtest index 18bb2166db1068bf6a2983a4eb51f218af5d90b3..710afca8e8d8d0d16d2c430b1dcec0f640a21d61 100644 --- a/tests/match-types/contains.svtest +++ b/tests/match-types/contains.svtest @@ -6,7 +6,7 @@ Cc: frop@example.com To: test@dovecot.example.net X-Bullshit: f fr fro frop frob frobn frobnitzn Subject: Test Message -Comment: +Comment: Test! . @@ -56,7 +56,7 @@ test "Match similar beginnings" { test "Match case-insensitive" { if not address :contains :comparator "i;ascii-casemap" "from" "EXAMPLE" { - test_fail "match fails to apply correct comparator"; + test_fail "match fails to apply correct comparator"; } if not address :contains "from" "EXAMPLE" { diff --git a/tests/match-types/is.svtest b/tests/match-types/is.svtest index 2fa02a0921b325a803bfcf26e50cb6a27c75961c..c715db8139cbb0384f45d967403d4997288354e2 100644 --- a/tests/match-types/is.svtest +++ b/tests/match-types/is.svtest @@ -4,7 +4,7 @@ test_set "message" text: From: Stephan Bosch <stephan@example.org> To: nico@frop.example.org Subject: Test message -Comment: +Comment: Test! @@ -13,7 +13,7 @@ Test! test "Empty key" { if header :is "from" "" { - test_fail "erroneously matched empty key against non-empty string"; + test_fail "erroneously matched empty key against non-empty string"; } if not header :is "comment" "" { diff --git a/tests/match-types/matches.svtest b/tests/match-types/matches.svtest index f81a484aa475e63f172b3056955d6fa30f628216..35ead66ecbd9d92673d05d2a376438148f76087e 100644 --- a/tests/match-types/matches.svtest +++ b/tests/match-types/matches.svtest @@ -11,7 +11,7 @@ Subject: make your money very fast!!! X-Spam-Score: ********** X-Bullshit: 33333???a Message-ID: <90a02fe01fc25e131d0e9c4c45975894@example.com> -Comment: +Comment: X-Subject: Log for successful build of Dovecot. Het werkt! diff --git a/tests/multiscript/basic.svtest b/tests/multiscript/basic.svtest index 6e6e73ac70627dec6ec3a90275d42231f317e249..ce9bb6624c4d491bffb8dd901f096722f479cd38 100644 --- a/tests/multiscript/basic.svtest +++ b/tests/multiscript/basic.svtest @@ -17,13 +17,13 @@ test "Append" { test_fail "failed to compile and run first script"; } - if not allof ( + if not allof ( test_script_compile "vacation.sieve", test_script_run :append_result ) { test_fail "failed to compile and run second script"; } - if not allof ( + if not allof ( test_script_compile "notify.sieve", test_script_run :append_result ) { test_fail "failed to compile and run third script"; diff --git a/tests/multiscript/conflicts.svtest b/tests/multiscript/conflicts.svtest index 79b87adec14849848d965141e45677662b578c14..a2b8fab9fc25b545585b277a6ff94545d914b745 100644 --- a/tests/multiscript/conflicts.svtest +++ b/tests/multiscript/conflicts.svtest @@ -21,7 +21,7 @@ test "Graceful Conflicts" { test_fail "result execute failed after first script"; } - if not allof ( + if not allof ( test_script_compile "reject-1.sieve", test_script_run :append_result ) { test_fail "failed to compile and run second script"; @@ -31,7 +31,7 @@ test "Graceful Conflicts" { test_fail "result execute failed after second script"; } - if not allof ( + if not allof ( test_script_compile "reject-2.sieve", test_script_run :append_result ) { test_fail "failed to compile and run third script"; @@ -69,7 +69,7 @@ test "Duplicates" { test_fail "result execute failed after first script"; } - if not allof ( + if not allof ( test_script_compile "fileinto-inbox.sieve", test_script_run :append_result ) { test_fail "failed to compile and run second script"; @@ -79,7 +79,7 @@ test "Duplicates" { test_fail "result execute failed after second script"; } - if not allof ( + if not allof ( test_script_compile "keep.sieve", test_script_run :append_result ) { test_fail "failed to compile and run third script"; diff --git a/tests/test-address.svtest b/tests/test-address.svtest index f7dad1f6276d7e540a9fbbad1e600f8dea5307d0..1761c5e8c78db7551eef62c9fbae947b1d2078fd 100644 --- a/tests/test-address.svtest +++ b/tests/test-address.svtest @@ -1,6 +1,6 @@ require "vnd.dovecot.testsuite"; -/* +/* * ## RFC 5228, Section 5.1. Test address (page 26) ## */ @@ -73,12 +73,12 @@ test "Basic functionality" { /* First header */ if not address :contains ["to", "from"] ["fred", "nico", "henk"] { test_fail "failed to match first header"; - } + } /* Second header */ if not address :contains ["from", "to"] ["fred", "nico", "henk"] { test_fail "failed to match second header"; - } + } /* Comment */ if not address :is "cc" "tss@fi.iki" { @@ -92,7 +92,7 @@ test "Basic functionality" { /* "Internet email addresses [RFC 2822] have the somewhat awkward characteristic * that the local-part to the left of the at-sign is considered case sensitive, - * and the domain-part to the right of the at-sign is case insensitive. The + * and the domain-part to the right of the at-sign is case insensitive. The * "address" command does not deal with this itself, but provides the * ADDRESS-PART argument for allowing users to deal with it. * " @@ -285,20 +285,20 @@ test "Address headers" { if not address "resent-from" "ivo@boer.ex" { test_fail "resent-from header not recognized"; - } + } if not address "resent-to" "idioot@dombo.ex" { test_fail "resent-to header not recognized"; - } -} + } +} /* ## RFC 5228, Section 2.7.4. Comparisons against Addresses (page 16) ## */ /* * TEST: Invalid addresses - */ + */ -/* +/* * "If an address is not syntactically valid, then it will not be matched * by tests specifying ":localpart" or ":domain". * " @@ -319,15 +319,15 @@ Test. test "Invalid addresses" { if address :localpart "from" "stephan" { test_fail ":localpart matched invalid address"; - } + } if address :domain "to" "example.org" { test_fail ":domain matched invalid address"; - } + } if not address :is :all "resent-to" "" { test_fail ":all failed to match empty address"; - } + } if not address :is :all "cc" "nonsense" { test_fail ":all failed to match invalid address"; @@ -339,7 +339,7 @@ test "Invalid addresses" { if address :is :domain "cc" "example.org" { test_fail ":domain matched invalid address"; - } + } } /* @@ -364,7 +364,7 @@ test "Default address part" { { test_fail "invalid default address part (1)"; } - + if not address :is :comparator "i;ascii-casemap" "to" ["harry@de.example.com"] { test_fail "invalid default address part (2)"; diff --git a/tests/test-allof.svtest b/tests/test-allof.svtest index f0ace457ac9b5e0a80920b81c514aeb74127ba46..1ebef674707023b86d191f4b7dcd6e6139b8195a 100644 --- a/tests/test-allof.svtest +++ b/tests/test-allof.svtest @@ -1,7 +1,7 @@ require "vnd.dovecot.testsuite"; -/* - * ## RFC 5228, Section 5.2. Test allof (page 27) ## +/* + * ## RFC 5228, Section 5.2. Test allof (page 27) ## */ /* "The "allof" test performs a logical AND on the tests supplied to it. @@ -58,7 +58,7 @@ test "Basic functionality: static" { } else { /* Correct */ } - + if allof ( false, true, false ) { test_fail "chose wrong second-true outcome: true"; } else { @@ -76,7 +76,7 @@ test "Basic functionality: static" { } else { /* Correct */ } - + if allof ( true, false, true ) { test_fail "chose wrong second-false outcome: true"; } else { @@ -124,7 +124,7 @@ test "Basic functionality: dynamic" { } else { /* Correct */ } - + if allof ( exists "friep", exists "from", exists "frml" ) { test_fail "chose wrong second-true outcome: true"; } else { @@ -142,7 +142,7 @@ test "Basic functionality: dynamic" { } else { /* Correct */ } - + if allof ( exists "to", exists "frop", exists "cc" ) { test_fail "chose wrong second-false outcome: true"; } else { @@ -222,7 +222,7 @@ test "Basic functionality: static/dynamic" { } /* Second true */ - + if allof ( false, exists "from", exists "frml" ) { test_fail "chose wrong second-true first-static outcome: true"; } else { @@ -282,7 +282,7 @@ test "Basic functionality: static/dynamic" { } /* Second false */ - + if allof ( true, exists "frop", exists "cc" ) { test_fail "chose wrong second-false first-static outcome: true"; } else { diff --git a/tests/test-anyof.svtest b/tests/test-anyof.svtest index 4674fc8aa8e1042e0d8391020f72250f7058fab9..77a9c79da2b252599b5ee700fd393cc48fd60dca 100644 --- a/tests/test-anyof.svtest +++ b/tests/test-anyof.svtest @@ -1,11 +1,11 @@ require "vnd.dovecot.testsuite"; -/* - * ## RFC 5228, Section 5.3. Test anyof (page 27) ## +/* + * ## RFC 5228, Section 5.3. Test anyof (page 27) ## */ /* "The "anyof" test performs a logical OR on the tests supplied to it. - * + * * Example: anyof (false, false) => false * anyof (false, true) => true * anyof (true, true) => true @@ -56,14 +56,14 @@ test "Basic functionality: static" { } else { test_fail "chose wrong first-true outcome: false"; } - + if anyof ( false, true, false ) { /* Correct */ } else { test_fail "chose wrong second-true outcome: false"; } - if anyof ( false, false, true ) { + if anyof ( false, false, true ) { /* Correct */ } else { test_fail "chose wrong last-true outcome: false"; @@ -74,7 +74,7 @@ test "Basic functionality: static" { } else { test_fail "chose wrong first-false outcome: false"; } - + if anyof ( true, false, true ) { /* Correct */ } else { @@ -118,11 +118,11 @@ test "Basic functionality: dynamic" { } if anyof ( exists "to", exists "frop", exists "frml" ) { - /* Correct */ + /* Correct */ } else { test_fail "chose wrong first-true outcome: false"; } - + if anyof ( exists "friep", exists "from", exists "frml" ) { /* Correct */ } else { @@ -140,7 +140,7 @@ test "Basic functionality: dynamic" { } else { test_fail "chose wrong first-false outcome: false"; } - + if anyof ( exists "to", exists "frop", exists "cc" ) { /* Correct */ } else { @@ -202,25 +202,25 @@ test "Basic functionality: static/dynamic" { /* First true */ if anyof ( true, exists "frop", exists "frml" ) { - /* Correct */ + /* Correct */ } else { test_fail "chose wrong first-true first-static outcome: false"; } if anyof ( exists "to", false, exists "frml" ) { - /* Correct */ + /* Correct */ } else { test_fail "chose wrong first-true second-static outcome: false"; } if anyof ( exists "to", exists "frop", false ) { - /* Correct */ + /* Correct */ } else { test_fail "chose wrong first-true third-static outcome: false"; } /* Second true */ - + if anyof ( false, exists "from", exists "frml" ) { /* Correct */ } else { @@ -280,7 +280,7 @@ test "Basic functionality: static/dynamic" { } /* Second false */ - + if anyof ( true, exists "frop", exists "cc" ) { /* Correct */ } else { diff --git a/tests/test-exists.svtest b/tests/test-exists.svtest index 456fefb11630c9b9d251c376d29e5a88cd3c4496..8c4c2fcb7bede5575c5b732f2c659198927a04b3 100644 --- a/tests/test-exists.svtest +++ b/tests/test-exists.svtest @@ -5,7 +5,7 @@ require "vnd.dovecot.testsuite"; * the test is false. * " */ - + test_set "message" text: From: stephan@example.org To: nico@vestingbar.bl diff --git a/tests/test-header.svtest b/tests/test-header.svtest index 18c676d9d8e3d2ca84e4803034d462e1e0814b4e..cb201b0a9ded1561546213ca077f4e8b772b6311 100644 --- a/tests/test-header.svtest +++ b/tests/test-header.svtest @@ -73,13 +73,13 @@ test "Basic functionality" { if not header :contains ["keywords", "subject"] ["raar", "strange", "vreemd"] { test_fail "failed to match first header"; - } + } /* Second header */ if not header :contains ["subject", "keywords"] ["raar", "strange", "vreemd"] { test_fail "failed to match second header"; - } + } } /* @@ -106,7 +106,7 @@ From: stephan@example.org To: nico@frop.example.com X-Caffeine: C8H10N4O2 Subject: I need coffee! -Comments: +Comments: Text . @@ -143,9 +143,9 @@ test "Matching empty key" { test_set "message" text: From: stephan@example.org To: nico@frop.example.com -Subject: Help +Subject: Help X-A: Text -X-B: Text +X-B: Text Text . @@ -181,7 +181,7 @@ test_set "message" text: From: stephan@example.org To: nico@frop.example.com CC: harry@nonsense.ex -Subject: +Subject: Comments: Text @@ -200,7 +200,7 @@ test "Absent or empty header" { if header :matches "Comment" "?*" { test_fail "Comment header is empty, but matched otherwise"; } -} +} /* * ## RFC 5228, Section 2.4.2.2. Headers (page 9) @@ -253,7 +253,7 @@ test "Invalid header name" { test_set "message" text: From: stephan@example.org To: nico@frop.example.com -Subject: Not enough space on a line! +Subject: Not enough space on a line! X-Multiline: This is a multi-line header body, which should be unfolded correctly. @@ -263,7 +263,7 @@ Text ; test "Folded header" { - if not header :is "x-multiline" + if not header :is "x-multiline" "This is a multi-line header body, which should be unfolded correctly." { test_fail "failed to properly unfold folded header."; } diff --git a/tests/testsuite.svtest b/tests/testsuite.svtest index 3447fd0cbba67ffcfd9a7bdb48ff6e195e1441c5..349ba897d1925b95afa4dc3a8579d6f8d48fde11 100644 --- a/tests/testsuite.svtest +++ b/tests/testsuite.svtest @@ -28,7 +28,7 @@ Friep! if not header :is "from" "nico@frop.example.com" { test_fail "message data not set properly."; - } + } keep; }