]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: smtp-syntax - Add smtp_xtext_decode().
authorStephan Bosch <stephan.bosch@open-xchange.com>
Wed, 22 Apr 2020 19:52:14 +0000 (21:52 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Wed, 27 May 2020 05:32:15 +0000 (05:32 +0000)
src/lib-smtp/smtp-syntax.c
src/lib-smtp/smtp-syntax.h

index b542243fed50afe43353bb3fa142cc89a6ceb922..dc7b744be4029bc93961409ab714fa5d0d10d0a3 100644 (file)
@@ -81,24 +81,17 @@ void smtp_string_write(string_t *out, const char *value)
  * Xtext encoding
  */
 
-int smtp_xtext_parse(const char *xtext, const char **value_r,
-                    const char **error_r)
+int smtp_xtext_decode(string_t *out, const char *xtext, bool allow_nul,
+                     const char **error_r)
 {
        struct smtp_parser parser;
-       string_t *value = NULL;
-
-       *value_r = NULL;
-       *error_r = NULL;
 
-       if (xtext == NULL || *xtext == '\0') {
-               *value_r = "";
+       if (xtext == NULL || *xtext == '\0')
                return 1;
-       }
 
-       value = t_str_new(256);
        smtp_parser_init(&parser, pool_datastack_create(), xtext);
 
-       if (smtp_parser_parse_xtext(&parser, value) < 0) {
+       if (smtp_parser_parse_xtext(&parser, out) < 0) {
                *error_r = parser.error;
                return -1;
        }
@@ -106,15 +99,36 @@ int smtp_xtext_parse(const char *xtext, const char **value_r,
                *error_r = "Invalid character in xtext";
                return -1;
        }
-
-       *value_r = str_c(value);
-       if (strlen(*value_r) != str_len(value)) {
+       if (!allow_nul && strlen(str_c(out)) != str_len(out)) {
                *error_r = "Encountered NUL character in xtext";
                return -1;
        }
        return 1;
 }
 
+int smtp_xtext_parse(const char *xtext, const char **value_r,
+                    const char **error_r)
+{
+       string_t *value;
+       int ret;
+
+       *value_r = NULL;
+       *error_r = NULL;
+
+       if (xtext == NULL || *xtext == '\0') {
+               *value_r = "";
+               return 1;
+       }
+
+       value = t_str_new(256);
+       ret = smtp_xtext_decode(value, xtext, FALSE, error_r);
+       if (ret <= 0)
+               return ret;
+
+       *value_r = str_c(value);
+       return 1;
+}
+
 void smtp_xtext_encode(string_t *out, const unsigned char *data, size_t size)
 {
        const unsigned char *p, *pbegin, *pend;
index 31773c9991fe9901d93ef19b57da7c7fd8b24d77..f9f960c143d9267d297c9dc9cd5c4f0fc63a63b5 100644 (file)
@@ -15,7 +15,9 @@ void smtp_string_write(string_t *out, const char *value);
  * Xtext encoding
  */
 
-int smtp_xtext_parse(const char *xtext,        const char **value_r,
+int smtp_xtext_decode(string_t *out, const char *xtext, bool allow_nul,
+                     const char **error_r);
+int smtp_xtext_parse(const char *xtext, const char **value_r,
                     const char **error_r);
 
 void smtp_xtext_encode(string_t *out, const unsigned char *data, size_t size);