* 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;
}
*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;
* 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);