[gmime] Always use accessor functions for GMimeParserOptions
- From: Jeffrey Stedfast <fejj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gmime] Always use accessor functions for GMimeParserOptions
- Date: Sat, 18 Mar 2017 22:46:51 +0000 (UTC)
commit a912effce5a76b6bf062e436232de365370f6bff
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date: Sat Mar 18 17:31:54 2017 -0400
Always use accessor functions for GMimeParserOptions
This allows us to handle NULL w/o problems.
docs/reference/gmime-sections.txt | 4 ++--
gmime/gmime-format-options.c | 34 +++++++++++-----------------------
gmime/gmime-param.c | 15 ++++++++-------
gmime/gmime-parser-options.c | 35 +++++++++++++++--------------------
gmime/gmime-parser-options.h | 4 ++--
gmime/gmime-utils.c | 18 ++++++++++++------
gmime/internet-address.c | 17 +++++++++--------
7 files changed, 59 insertions(+), 68 deletions(-)
---
diff --git a/docs/reference/gmime-sections.txt b/docs/reference/gmime-sections.txt
index 72653a2..ba0c515 100644
--- a/docs/reference/gmime-sections.txt
+++ b/docs/reference/gmime-sections.txt
@@ -1215,8 +1215,8 @@ GMimeRfcComplianceMode
g_mime_parser_options_new
g_mime_parser_options_free
g_mime_parser_options_get_default
-g_mime_parser_options_get_address_parser_compliance_mode
-g_mime_parser_options_set_address_parser_compliance_mode
+g_mime_parser_options_get_address_compliance_mode
+g_mime_parser_options_set_address_compliance_mode
g_mime_parser_options_get_parameter_compliance_mode
g_mime_parser_options_set_parameter_compliance_mode
g_mime_parser_options_get_rfc2047_compliance_mode
diff --git a/gmime/gmime-format-options.c b/gmime/gmime-format-options.c
index 1ad58ea..a7e2e67 100644
--- a/gmime/gmime-format-options.c
+++ b/gmime/gmime-format-options.c
@@ -165,7 +165,7 @@ g_mime_format_options_free (GMimeFormatOptions *options)
/**
* g_mime_format_options_get_param_encoding_method:
- * @options: a #GMimeFormatOptions
+ * @options: a #GMimeFormatOptions or %NULL
*
* Gets the parameter encoding method to use for #GMimeParam parameters that do not
* already have an encoding method specified.
@@ -175,10 +175,7 @@ g_mime_format_options_free (GMimeFormatOptions *options)
GMimeParamEncodingMethod
g_mime_format_options_get_param_encoding_method (GMimeFormatOptions *options)
{
- if (options == NULL)
- options = default_options;
-
- return options->method;
+ return options ? options->method : default_options->method;
}
@@ -204,7 +201,7 @@ g_mime_format_options_set_param_encoding_method (GMimeFormatOptions *options, GM
/**
* g_mime_format_options_get_newline_format:
- * @options: a #GMimeFormatOptions
+ * @options: a #GMimeFormatOptions or %NULL
*
* Gets the new-line format to use when writing out messages and headers.
*
@@ -213,10 +210,7 @@ g_mime_format_options_set_param_encoding_method (GMimeFormatOptions *options, GM
GMimeNewLineFormat
g_mime_format_options_get_newline_format (GMimeFormatOptions *options)
{
- if (options == NULL)
- options = default_options;
-
- return options->newline;
+ return options ? options->newline : default_options->newline;
}
@@ -239,7 +233,7 @@ g_mime_format_options_set_newline_format (GMimeFormatOptions *options, GMimeNewL
/**
* g_mime_format_options_get_newline:
- * @options: a #GMimeFormatOptions
+ * @options: a #GMimeFormatOptions or %NULL
*
* Gets a string representing the currently set new-line format.
*
@@ -260,7 +254,7 @@ g_mime_format_options_get_newline (GMimeFormatOptions *options)
/**
* g_mime_format_options_create_newline_filter:
- * @options: a #GMimeFormatOptions
+ * @options: a #GMimeFormatOptions or %NULL
* @ensure_newline: %TRUE if the output must *always* end with a new line
*
* Creates a #GMimeFilter suitable for converting line-endings to the
@@ -284,7 +278,7 @@ g_mime_format_options_create_newline_filter (GMimeFormatOptions *options, gboole
#ifdef NOT_YET_IMPLEMENTED
/**
* g_mime_format_options_get_allow_mixed_charsets:
- * @options: a #GMimeFormatOptions
+ * @options: a #GMimeFormatOptions or %NULL
*
* Gets whether or not headers are allowed to be encoded using mixed charsets.
*
@@ -318,7 +312,7 @@ g_mime_format_options_set_allow_mixed_charsets (GMimeFormatOptions *options, gbo
/**
* g_mime_format_options_get_allow_international:
- * @options: a #GMimeFormatOptions
+ * @options: a #GMimeFormatOptions or %NULL
*
* Gets whether or not international encoding is allowed.
*
@@ -327,10 +321,7 @@ g_mime_format_options_set_allow_mixed_charsets (GMimeFormatOptions *options, gbo
gboolean
g_mime_format_options_get_allow_international (GMimeFormatOptions *options)
{
- if (options == NULL)
- options = default_options;
-
- return options->international;
+ return options ? options->international : default_options->international;
}
@@ -352,7 +343,7 @@ g_mime_format_options_set_allow_international (GMimeFormatOptions *options, gboo
/**
* g_mime_format_options_get_allow_international:
- * @options: a #GMimeFormatOptions
+ * @options: a #GMimeFormatOptions or %NULL
*
* Gets the max line length to use with encoders.
*
@@ -361,10 +352,7 @@ g_mime_format_options_set_allow_international (GMimeFormatOptions *options, gboo
guint
g_mime_format_options_get_max_line (GMimeFormatOptions *options)
{
- if (options == NULL)
- options = default_options;
-
- return options->maxline;
+ return options ? options->maxline : default_options->maxline;
}
diff --git a/gmime/gmime-param.c b/gmime/gmime-param.c
index c6e3e05..acf842a 100644
--- a/gmime/gmime-param.c
+++ b/gmime/gmime-param.c
@@ -940,7 +940,7 @@ decode_quoted_string (const char **in)
}
static char *
-decode_token (GMimeParserOptions *options, const char **in)
+decode_token (GMimeRfcComplianceMode mode, const char **in)
{
const char *inptr = *in;
const char *start;
@@ -948,7 +948,7 @@ decode_token (GMimeParserOptions *options, const char **in)
skip_cfws (&inptr);
start = inptr;
- if (options->parameters != GMIME_RFC_COMPLIANCE_LOOSE) {
+ if (mode != GMIME_RFC_COMPLIANCE_LOOSE) {
while (is_ttoken (*inptr))
inptr++;
} else {
@@ -972,7 +972,7 @@ decode_token (GMimeParserOptions *options, const char **in)
}
static char *
-decode_value (GMimeParserOptions *options, const char **in)
+decode_value (GMimeRfcComplianceMode mode, const char **in)
{
const char *inptr = *in;
@@ -982,11 +982,11 @@ decode_value (GMimeParserOptions *options, const char **in)
if (*inptr == '"') {
return decode_quoted_string (in);
} else if (is_ttoken (*inptr)) {
- return decode_token (options, in);
+ return decode_token (mode, in);
}
- if (options->parameters == GMIME_RFC_COMPLIANCE_LOOSE)
- return decode_token (options, in);
+ if (mode == GMIME_RFC_COMPLIANCE_LOOSE)
+ return decode_token (mode, in);
return NULL;
}
@@ -1061,6 +1061,7 @@ static gboolean
decode_param (GMimeParserOptions *options, const char **in, char **namep, char **valuep, int *id,
const char **rfc2047_charset, gboolean *encoded, GMimeParamEncodingMethod *method)
{
+ GMimeRfcComplianceMode mode = g_mime_parser_options_get_parameter_compliance_mode (options);
gboolean is_rfc2184 = FALSE;
const char *inptr = *in;
char *name, *value = NULL;
@@ -1074,7 +1075,7 @@ decode_param (GMimeParserOptions *options, const char **in, char **namep, char *
if (*inptr == '=') {
inptr++;
- value = decode_value (options, &inptr);
+ value = decode_value (mode, &inptr);
if (!is_rfc2184 && value) {
if (strstr (value, "=?") != NULL) {
diff --git a/gmime/gmime-parser-options.c b/gmime/gmime-parser-options.c
index 4222654..8057bbf 100644
--- a/gmime/gmime-parser-options.c
+++ b/gmime/gmime-parser-options.c
@@ -116,6 +116,9 @@ _g_mime_parser_options_clone (GMimeParserOptions *options)
GMimeParserOptions *clone;
guint i, n = 0;
+ if (options == NULL)
+ options = default_options;
+
clone = g_slice_new (GMimeParserOptions);
clone->addresses = options->addresses;
clone->parameters = options->parameters;
@@ -152,8 +155,8 @@ g_mime_parser_options_free (GMimeParserOptions *options)
/**
- * g_mime_parser_options_get_address_parser_compliance_mode:
- * @options: a #GMimeParserOptions
+ * g_mime_parser_options_get_address_compliance_mode:
+ * @options: a #GMimeParserOptions or %NULL
*
* Gets the compliance mode that should be used when parsing rfc822 addresses.
*
@@ -164,16 +167,14 @@ g_mime_parser_options_free (GMimeParserOptions *options)
* Returns: the compliance mode that is currently set.
**/
GMimeRfcComplianceMode
-g_mime_parser_options_get_address_parser_compliance_mode (GMimeParserOptions *options)
+g_mime_parser_options_get_address_compliance_mode (GMimeParserOptions *options)
{
- g_return_val_if_fail (options != NULL, GMIME_RFC_COMPLIANCE_LOOSE);
-
- return options->addresses;
+ return options ? options->addresses : default_options->addresses;
}
/**
- * g_mime_parser_options_set_address_parser_compliance_mode:
+ * g_mime_parser_options_set_address_compliance_mode:
* @options: a #GMimeParserOptions
* @mode: a #GMimeRfcComplianceMode
*
@@ -188,7 +189,7 @@ g_mime_parser_options_get_address_parser_compliance_mode (GMimeParserOptions *op
* deal with garbage input.
**/
void
-g_mime_parser_options_set_address_parser_compliance_mode (GMimeParserOptions *options,
GMimeRfcComplianceMode mode)
+g_mime_parser_options_set_address_compliance_mode (GMimeParserOptions *options, GMimeRfcComplianceMode mode)
{
g_return_if_fail (options != NULL);
@@ -198,7 +199,7 @@ g_mime_parser_options_set_address_parser_compliance_mode (GMimeParserOptions *op
/**
* g_mime_parser_options_get_parameter_compliance_mode:
- * @options: a #GMimeParserOptions
+ * @options: a #GMimeParserOptions or %NULL
*
* Gets the compliance mode that should be used when parsing Content-Type and
* Content-Disposition parameters.
@@ -212,9 +213,7 @@ g_mime_parser_options_set_address_parser_compliance_mode (GMimeParserOptions *op
GMimeRfcComplianceMode
g_mime_parser_options_get_parameter_compliance_mode (GMimeParserOptions *options)
{
- g_return_val_if_fail (options != NULL, GMIME_RFC_COMPLIANCE_LOOSE);
-
- return options->parameters;
+ return options ? options->parameters : default_options->parameters;
}
@@ -245,7 +244,7 @@ g_mime_parser_options_set_parameter_compliance_mode (GMimeParserOptions *options
/**
* g_mime_parser_options_get_rfc2047_compliance_mode:
- * @options: a #GMimeParserOptions
+ * @options: a #GMimeParserOptions or %NULL
*
* Gets the compliance mode that should be used when parsing rfc2047 encoded words.
*
@@ -258,9 +257,7 @@ g_mime_parser_options_set_parameter_compliance_mode (GMimeParserOptions *options
GMimeRfcComplianceMode
g_mime_parser_options_get_rfc2047_compliance_mode (GMimeParserOptions *options)
{
- g_return_val_if_fail (options != NULL, GMIME_RFC_COMPLIANCE_LOOSE);
-
- return options->rfc2047;
+ return options ? options->rfc2047 : default_options->rfc2047;
}
@@ -290,7 +287,7 @@ g_mime_parser_options_set_rfc2047_compliance_mode (GMimeParserOptions *options,
/**
* g_mime_parser_options_get_fallback_charsets:
- * @options: a #GMimeParserOptions
+ * @options: a #GMimeParserOptions or %NULL
*
* Gets the fallback charsets to try when decoding 8-bit headers.
*
@@ -300,9 +297,7 @@ g_mime_parser_options_set_rfc2047_compliance_mode (GMimeParserOptions *options,
const char **
g_mime_parser_options_get_fallback_charsets (GMimeParserOptions *options)
{
- g_return_val_if_fail (options != NULL, (const char **) default_charsets);
-
- return (const char **) options->charsets;
+ return (const char **) (options ? options->charsets : default_options->charsets);
}
diff --git a/gmime/gmime-parser-options.h b/gmime/gmime-parser-options.h
index 813c3d8..8633495 100644
--- a/gmime/gmime-parser-options.h
+++ b/gmime/gmime-parser-options.h
@@ -59,8 +59,8 @@ GMimeParserOptions *g_mime_parser_options_get_default (void);
GMimeParserOptions *g_mime_parser_options_new (void);
void g_mime_parser_options_free (GMimeParserOptions *options);
-GMimeRfcComplianceMode g_mime_parser_options_get_address_parser_compliance_mode (GMimeParserOptions
*options);
-void g_mime_parser_options_set_address_parser_compliance_mode (GMimeParserOptions *options,
GMimeRfcComplianceMode mode);
+GMimeRfcComplianceMode g_mime_parser_options_get_address_compliance_mode (GMimeParserOptions *options);
+void g_mime_parser_options_set_address_compliance_mode (GMimeParserOptions *options, GMimeRfcComplianceMode
mode);
GMimeRfcComplianceMode g_mime_parser_options_get_parameter_compliance_mode (GMimeParserOptions *options);
void g_mime_parser_options_set_parameter_compliance_mode (GMimeParserOptions *options,
GMimeRfcComplianceMode mode);
diff --git a/gmime/gmime-utils.c b/gmime/gmime-utils.c
index 9cb7b2e..ebe6747 100644
--- a/gmime/gmime-utils.c
+++ b/gmime/gmime-utils.c
@@ -1479,6 +1479,7 @@ char *
g_mime_utils_decode_8bit (GMimeParserOptions *options, const char *text, size_t len)
{
size_t outleft, outlen, min, ninval;
+ const char **charsets;
const char *best;
iconv_t cd;
char *out;
@@ -1486,14 +1487,15 @@ g_mime_utils_decode_8bit (GMimeParserOptions *options, const char *text, size_t
g_return_val_if_fail (text != NULL, NULL);
- best = options->charsets[0];
+ charsets = g_mime_parser_options_get_fallback_charsets (options);
+ best = charsets[0];
min = len;
outleft = (len * 2) + 16;
out = g_malloc (outleft + 1);
- for (i = 0; options->charsets[i]; i++) {
- if ((cd = g_mime_iconv_open ("UTF-8", options->charsets[i])) == (iconv_t) -1)
+ for (i = 0; charsets[i]; i++) {
+ if ((cd = g_mime_iconv_open ("UTF-8", charsets[i])) == (iconv_t) -1)
continue;
outlen = charset_convert (cd, text, len, &out, &outleft, &ninval);
@@ -1504,7 +1506,7 @@ g_mime_utils_decode_8bit (GMimeParserOptions *options, const char *text, size_t
return g_realloc (out, outlen + 1);
if (ninval < min) {
- best = options->charsets[i];
+ best = charsets[i];
min = ninval;
}
}
@@ -1781,11 +1783,13 @@ tokenize_rfc2047_phrase (GMimeParserOptions *options, const char *in, size_t *le
{
rfc2047_token list, *lwsp, *token, *tail;
register const char *inptr = in;
+ GMimeRfcComplianceMode mode;
gboolean encoded = FALSE;
const char *text, *word;
gboolean ascii;
size_t n;
+ mode = g_mime_parser_options_get_rfc2047_compliance_mode (options);
tail = (rfc2047_token *) &list;
list.next = NULL;
lwsp = NULL;
@@ -1803,7 +1807,7 @@ tokenize_rfc2047_phrase (GMimeParserOptions *options, const char *in, size_t *le
word = inptr;
ascii = TRUE;
if (is_atom (*inptr)) {
- if (G_LIKELY (options->rfc2047 == GMIME_RFC_COMPLIANCE_LOOSE)) {
+ if (G_LIKELY (mode == GMIME_RFC_COMPLIANCE_LOOSE)) {
/* Make an extra effort to detect and
* separate encoded-word tokens that
* have been merged with other
@@ -1914,11 +1918,13 @@ tokenize_rfc2047_text (GMimeParserOptions *options, const char *in, size_t *len)
{
rfc2047_token list, *lwsp, *token, *tail;
register const char *inptr = in;
+ GMimeRfcComplianceMode mode;
gboolean encoded = FALSE;
const char *text, *word;
gboolean ascii;
size_t n;
+ mode = g_mime_parser_options_get_rfc2047_compliance_mode (options);
tail = (rfc2047_token *) &list;
list.next = NULL;
lwsp = NULL;
@@ -1937,7 +1943,7 @@ tokenize_rfc2047_text (GMimeParserOptions *options, const char *in, size_t *len)
word = inptr;
ascii = TRUE;
- if (G_LIKELY (options->rfc2047 == GMIME_RFC_COMPLIANCE_LOOSE)) {
+ if (G_LIKELY (mode == GMIME_RFC_COMPLIANCE_LOOSE)) {
if (!strncmp (inptr, "=?", 2)) {
inptr += 2;
diff --git a/gmime/internet-address.c b/gmime/internet-address.c
index 0b47a24..b23971c 100644
--- a/gmime/internet-address.c
+++ b/gmime/internet-address.c
@@ -1559,6 +1559,7 @@ addrspec_parse (const char **in, const char *sentinels, char **addrspec)
static gboolean
mailbox_parse (GMimeParserOptions *options, const char **in, const char *name, InternetAddress **address)
{
+ GMimeRfcComplianceMode mode = g_mime_parser_options_get_address_compliance_mode (options);
const char *inptr = *in;
char *addrspec = NULL;
@@ -1567,7 +1568,7 @@ mailbox_parse (GMimeParserOptions *options, const char **in, const char *name, I
/* Note: check for excessive angle brackets like the example described in section 7.1.2 of rfc7103...
*/
if (*inptr == '<') {
- if (options->addresses != GMIME_RFC_COMPLIANCE_LOOSE)
+ if (mode != GMIME_RFC_COMPLIANCE_LOOSE)
goto error;
do {
@@ -1606,7 +1607,7 @@ mailbox_parse (GMimeParserOptions *options, const char **in, const char *name, I
goto error;
if (*inptr != '>') {
- if (options->addresses != GMIME_RFC_COMPLIANCE_LOOSE)
+ if (mode != GMIME_RFC_COMPLIANCE_LOOSE)
goto error;
} else {
/* skip over the '>' */
@@ -1614,7 +1615,7 @@ mailbox_parse (GMimeParserOptions *options, const char **in, const char *name, I
/* Note: check for excessive angle brackets like the example described in section 7.1.2 of
rfc7103... */
if (*inptr == '>') {
- if (options->addresses != GMIME_RFC_COMPLIANCE_LOOSE)
+ if (mode != GMIME_RFC_COMPLIANCE_LOOSE)
goto error;
do {
@@ -1666,7 +1667,7 @@ group_parse (InternetAddressGroup *group, GMimeParserOptions *options, const cha
static gboolean
address_parse (GMimeParserOptions *options, AddressParserFlags flags, const char **in, const char **charset,
InternetAddress **address)
{
- gboolean strict = options->addresses != GMIME_RFC_COMPLIANCE_LOOSE;
+ GMimeRfcComplianceMode mode = g_mime_parser_options_get_address_compliance_mode (options);
gboolean trim_leading_quote = FALSE;
const char *inptr = *in;
const char *start;
@@ -1681,7 +1682,7 @@ address_parse (GMimeParserOptions *options, AddressParserFlags flags, const char
length = 0;
while (*inptr) {
- if (strict) {
+ if (mode != GMIME_RFC_COMPLIANCE_LOOSE) {
if (!skip_word (&inptr))
break;
} else if (*inptr == '"') {
@@ -1770,7 +1771,7 @@ address_parse (GMimeParserOptions *options, AddressParserFlags flags, const char
}
if (*inptr == '>') {
- if (strict)
+ if (mode != GMIME_RFC_COMPLIANCE_LOOSE)
goto error;
inptr++;
@@ -1865,7 +1866,7 @@ address_parse (GMimeParserOptions *options, AddressParserFlags flags, const char
* is an unquoted string with an '@'. */
const char *end;
- if (strict)
+ if (mode != GMIME_RFC_COMPLIANCE_LOOSE)
goto error;
end = inptr;
@@ -1882,7 +1883,7 @@ address_parse (GMimeParserOptions *options, AddressParserFlags flags, const char
* anyway in order to deal with the second Unbalanced Angle Brackets example in
* section 7.1.3: second example org> */
if (*inptr == '>') {
- if (strict)
+ if (mode != GMIME_RFC_COMPLIANCE_LOOSE)
goto error;
inptr++;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]