Commit 7ae106db 7ae106db9767abe3f7716a50bb8b189e47083efe by Sergey Poznyakoff

Provide backward compatibility layer for deprecated functions.

* include/mailutils/sieve.h (mu_sieve_compile_text): New proto.
(mu_sieve_compile_buffer): Backward-compatible proto.
* include/mailutils/stream.h ((MU_IOCTL_LOGSTREAM_GET_LOCUS_DEPRECATED)
(MU_IOCTL_LOGSTREAM_SET_LOCUS_DEPRECATED): New defines.
(MU_IOCTL_LOGSTREAM_GET_LOCUS)
(MU_IOCTL_LOGSTREAM_SET_LOCUS): Use external functions to make
sure any references to these are marked as deprecated.
* include/mailutils/types.hin (mu_locus_DEPRECATED): New struct.
(mu_locus): Define to mu_locus_DEPRECATED
* libmailutils/stream/logstream.c (_log_ctl): Handle the deprecated
ctls.
* libmu_sieve/extensions/moderator.c (moderator_filter_message): Use
mu_sieve_compile_text.
* libmu_sieve/sieve-gram.y (mu_sieve_compile_buffer): Rename to
mu_sieve_compile_text.  Re-introduce it as a backward-compatibility
API.
* sieve/sieve.c: Call mu_sieve_compile_text instead of
mu_sieve_compile_buffer.
1 parent 1dbebc4d
......@@ -326,9 +326,13 @@ const char *mu_sieve_type_str (mu_sieve_data_type type);
/* Principal entry points */
int mu_sieve_compile (mu_sieve_machine_t mach, const char *name);
int mu_sieve_compile_text (mu_sieve_machine_t mach,
const char *buf, size_t bufsize,
struct mu_locus_point const *pt);
int mu_sieve_compile_buffer (mu_sieve_machine_t mach,
const char *buf, int bufsize,
struct mu_locus_point const *pt);
const char *fname, int line)
MU_DEPRECATED;
int mu_sieve_mailbox (mu_sieve_machine_t mach, mu_mailbox_t mbox);
int mu_sieve_message (mu_sieve_machine_t mach, mu_message_t message);
int mu_sieve_disass (mu_sieve_machine_t mach);
......
......@@ -106,8 +106,20 @@ enum mu_buffer_type
*/
#define MU_IOCTL_LOGSTREAM_GET_SEVERITY 0
#define MU_IOCTL_LOGSTREAM_SET_SEVERITY 1
/* Codes 2 and 3 are reserved */
/* The following two subcommands are deprecated and provided for
backward compatibility. Please use the MU_IOCTL_LOGSTREAM_GET_LOCUS_RANGE
and MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE instead. */
/* Get or set locus.
Arg: struct mu_locus_DEPRECATED *
*/
#define MU_IOCTL_LOGSTREAM_GET_LOCUS_DEPRECATED 2
#define MU_IOCTL_LOGSTREAM_SET_LOCUS_DEPRECATED 3
int mu_ioctl_logstream_get_locus_deprecated (void) MU_DEPRECATED;
#define MU_IOCTL_LOGSTREAM_GET_LOCUS mu_ioctl_logstream_get_locus_deprecated ()
int mu_ioctl_logstream_set_locus_deprecated (void) MU_DEPRECATED;
#define MU_IOCTL_LOGSTREAM_SET_LOCUS mu_ioctl_logstream_set_locus_deprecated ()
/* Get or set log mode.
Arg: int *
......
......@@ -149,6 +149,16 @@ typedef unsigned int mu_debug_level_t;
#define MU_DEFAULT_RECORD _MU_DEFAULT_RECORD_
/* The use of this structure and associated ioctl is deprecated. This
definition is provided for transition period */
struct mu_locus_DEPRECATED
{
char *mu_file;
unsigned mu_line;
unsigned mu_col;
};
#define mu_locus mu_locus_DEPRECATED
#ifdef __cplusplus
}
#endif
......
......@@ -480,6 +480,48 @@ _log_ctl (struct _mu_stream *str, int code, int opcode, void *arg)
}
break;
case MU_IOCTL_LOGSTREAM_GET_LOCUS_DEPRECATED:
if (!arg)
return EINVAL;
else
{
struct mu_locus_DEPRECATED *ploc = arg;
if (sp->locrange.beg.mu_file)
{
ploc->mu_file = strdup (sp->locrange.beg.mu_file);
if (!ploc->mu_file)
return ENOMEM;
}
else
ploc->mu_file = NULL;
ploc->mu_line = sp->locrange.beg.mu_line;
ploc->mu_col = sp->locrange.beg.mu_col;
}
break;
case MU_IOCTL_LOGSTREAM_SET_LOCUS_DEPRECATED:
{
struct mu_locus_DEPRECATED *ploc = arg;
mu_ident_deref (sp->locrange.end.mu_file);
sp->locrange.end.mu_file = NULL;
if (arg)
{
status = lr_set_file (&sp->locrange, ploc->mu_file, 0, 0);
if (status)
return status;
lr_set_line (&sp->locrange, ploc->mu_line, 0);
lr_set_col (&sp->locrange, ploc->mu_col, 0);
}
else
{
mu_ident_deref (sp->locrange.beg.mu_file);
sp->locrange.beg.mu_file = NULL;
}
break;
}
case MU_IOCTL_LOGSTREAM_SET_LOCUS_LINE:
if (!arg)
return EINVAL;
......@@ -606,5 +648,29 @@ mu_log_stream_create (mu_stream_t *pstr, mu_stream_t transport)
return 0;
}
int
mu_ioctl_logstream_get_locus_deprecated (void)
{
static int warned;
if (!warned)
{
mu_error (_("the program uses MU_IOCTL_LOGSTREAM_GET_LOCUS, which is deprecated"));
warned = 1;
}
return MU_IOCTL_LOGSTREAM_GET_LOCUS_DEPRECATED;
}
int
mu_ioctl_logstream_set_locus_deprecated (void)
{
static int warned;
if (!warned)
{
mu_error (_("program uses MU_IOCTL_LOGSTREAM_SET_LOCUS, which is deprecated"));
warned = 1;
}
return MU_IOCTL_LOGSTREAM_SET_LOCUS_DEPRECATED;
}
......
......@@ -113,9 +113,9 @@ moderator_filter_message (mu_sieve_machine_t mach,
return 1;
}
mu_sieve_get_locus (mach, &locrange);
rc = mu_sieve_compile_buffer (newmach,
arg, strlen (arg),
&locrange.beg);
rc = mu_sieve_compile_text (newmach,
arg, strlen (arg),
&locrange.beg);
if (rc)
mu_sieve_error (mach, _("cannot compile subprogram"));
}
......
......@@ -1568,9 +1568,9 @@ sieve_compile_strbuf (void *name)
}
int
mu_sieve_compile_buffer (mu_sieve_machine_t mach,
const char *str, int strsize,
struct mu_locus_point const *loc)
mu_sieve_compile_text (mu_sieve_machine_t mach,
const char *str, size_t strsize,
struct mu_locus_point const *loc)
{
struct strbuf buf;
buf.ptr = str;
......@@ -1579,6 +1579,19 @@ mu_sieve_compile_buffer (mu_sieve_machine_t mach,
return with_machine (mach, sieve_compile_strbuf, &buf);
}
int
mu_sieve_compile_buffer (mu_sieve_machine_t mach,
const char *buf, int bufsize,
const char *fname, int line)
{
int rc;
struct mu_locus_point loc;
mu_locus_point_init (&loc, fname);
loc.mu_line = line;
rc = mu_sieve_compile_text (mach, buf, bufsize, &loc);
mu_locus_point_deinit (&loc);
return rc;
}
......
......@@ -500,7 +500,7 @@ main (int argc, char *argv[])
pt.mu_file = "stdin";
pt.mu_line = 1;
pt.mu_col = 0;
rc = mu_sieve_compile_buffer (mach, script, strlen (script), &pt);
rc = mu_sieve_compile_text (mach, script, strlen (script), &pt);
}
else
rc = mu_sieve_compile (mach, script);
......