[dovecot-cvs] dovecot/src/lib-imap imap-bodystructure.c,1.24,1.25 imap-parser.c,1.28,1.29 imap-util.c,1.6,1.7 imap-util.h,1.2,1.3
cras at procontrol.fi
cras at procontrol.fi
Fri Jan 3 17:57:14 EET 2003
Update of /home/cvs/dovecot/src/lib-imap
In directory danu:/tmp/cvs-serv6416/lib-imap
Modified Files:
imap-bodystructure.c imap-parser.c imap-util.c imap-util.h
Log Message:
Rewrote rfc822-tokenize.c to work one token at a time so it won't uselessly
take memory, maybe also a bit faster. This caused pretty large changes all
around.
Also moved all string (un)escaping code to lib/strescape.c.
Index: imap-bodystructure.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-imap/imap-bodystructure.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- imap-bodystructure.c 2 Jan 2003 08:09:27 -0000 1.24
+++ imap-bodystructure.c 3 Jan 2003 15:57:12 -0000 1.25
@@ -33,92 +33,95 @@
static void part_write_bodystructure(MessagePart *part, String *str,
int extended);
-static void parse_content_type(const Rfc822Token *tokens,
- int count, void *context)
+static void parse_content_type(const char *value, size_t value_len,
+ void *context)
{
MessagePartBodyData *data = context;
- const char *value;
- int i;
+ size_t i;
- /* find the content type separator */
- for (i = 0; i < count; i++) {
- if (tokens[i].token == '/')
+ for (i = 0; i < value_len; i++) {
+ if (value[i] == '/')
break;
}
- value = rfc822_tokens_get_value_quoted(tokens, i);
- data->content_type = p_strdup(data->pool, value);
+ if (i == value_len) {
+ data->content_type =
+ imap_quote_value(data->pool, value, value_len);
+ } else {
+ data->content_type =
+ imap_quote_value(data->pool, value, i);
- value = rfc822_tokens_get_value_quoted(tokens+i+1, count-i-1);
- data->content_subtype = p_strdup(data->pool, value);
+ i++;
+ data->content_subtype =
+ imap_quote_value(data->pool, value+i, value_len-i);
+ }
}
-static void parse_save_params_list(const Rfc822Token *name,
- const Rfc822Token *value, int value_count,
+static void parse_save_params_list(const char *name, size_t name_len,
+ const char *value, size_t value_len,
+ int value_quoted __attr_unused__,
void *context)
{
MessagePartBodyData *data = context;
- const char *str;
if (str_len(data->str) != 0)
str_append_c(data->str, ' ');
str_append_c(data->str, '"');
- str_append_n(data->str, name->ptr, name->len);
+ str_append_n(data->str, name, name_len);
str_append(data->str, "\" ");
- str = rfc822_tokens_get_value_quoted(value, value_count);
- str_append(data->str, str);
+ str_append_c(data->str, '"');
+ str_append_n(data->str, value, value_len);
+ str_append_c(data->str, '"');
}
-static void parse_content_transfer_encoding(const Rfc822Token *tokens,
- int count, void *context)
+static void parse_content_transfer_encoding(const char *value, size_t value_len,
+ void *context)
{
MessagePartBodyData *data = context;
- const char *value;
- value = rfc822_tokens_get_value_quoted(tokens, count);
- data->content_transfer_encoding = p_strdup(data->pool, value);
+ data->content_transfer_encoding =
+ imap_quote_value(data->pool, value, value_len);
}
-static void parse_content_disposition(const Rfc822Token *tokens,
- int count, void *context)
+static void parse_content_disposition(const char *value, size_t value_len,
+ void *context)
{
MessagePartBodyData *data = context;
- const char *value;
- value = rfc822_tokens_get_value_quoted(tokens, count);
- data->content_disposition = p_strdup(data->pool, value);
+ data->content_disposition =
+ imap_quote_value(data->pool, value, value_len);
}
-static void parse_content_language(const Rfc822Token *tokens,
- int count, void *context)
+static void parse_content_language(const char *value, size_t value_len,
+ MessagePartBodyData *data)
{
- MessagePartBodyData *data = context;
+ Rfc822TokenizeContext *ctx;
+ Rfc822Token token;
String *str;
int quoted;
/* Content-Language: en-US, az-arabic (comments allowed) */
- if (count <= 0)
- return;
+ ctx = rfc822_tokenize_init(value, value_len, NULL, NULL);
+ t_push();
str = t_str_new(256);
quoted = FALSE;
- for (; count > 0; count--, tokens++) {
- switch (tokens->token) {
- case '(':
- /* ignore comment */
+ while (rfc822_tokenize_next(ctx)) {
+ token = rfc822_tokenize_get(ctx);
+ if (token == TOKEN_LAST)
break;
- case ',':
+
+ if (token == ',') {
/* list separator */
if (quoted) {
str_append_c(str, '"');
quoted = FALSE;
}
- break;
- default:
+ } else {
/* anything else goes as-is. only alphabetic characters
and '-' is allowed, so anything else is error
which we can deal with however we want. */
@@ -129,11 +132,13 @@
quoted = TRUE;
}
- if (IS_TOKEN_STRING(tokens->token))
- str_append_n(str, tokens->ptr, tokens->len);
- else
- str_append_c(str, tokens->token);
- break;
+ if (!IS_TOKEN_STRING(token))
+ str_append_c(str, token);
+ else {
+ value = rfc822_tokenize_get_value(ctx,
+ &value_len);
+ str_append_n(str, value, value_len);
+ }
}
}
@@ -141,6 +146,10 @@
str_append_c(str, '"');
data->content_language = p_strdup(data->pool, str_c(str));
+
+ t_pop();
+
+ rfc822_tokenize_deinit(ctx);
}
static void parse_header(MessagePart *part,
@@ -174,17 +183,16 @@
if (strcasecmp(name, "Content-Type") == 0 &&
part_data->content_type == NULL) {
part_data->str = t_str_new(256);
- (void)message_content_parse_header(t_strndup(value, value_len),
- parse_content_type,
- parse_save_params_list,
- part_data);
+ message_content_parse_header(value, value_len,
+ parse_content_type,
+ parse_save_params_list, part_data);
part_data->content_type_params =
p_strdup_empty(pool, str_c(part_data->str));
} else if (strcasecmp(name, "Content-Transfer-Encoding") == 0 &&
part_data->content_transfer_encoding == NULL) {
- (void)message_content_parse_header(t_strndup(value, value_len),
- parse_content_transfer_encoding,
- NULL, part_data);
+ message_content_parse_header(value, value_len,
+ parse_content_transfer_encoding,
+ NULL, part_data);
} else if (strcasecmp(name, "Content-ID") == 0 &&
part_data->content_id == NULL) {
part_data->content_id =
@@ -196,16 +204,13 @@
} else if (strcasecmp(name, "Content-Disposition") == 0 &&
part_data->content_disposition_params == NULL) {
part_data->str = t_str_new(256);
- (void)message_content_parse_header(t_strndup(value, value_len),
- parse_content_disposition,
- parse_save_params_list,
- part_data);
+ message_content_parse_header(value, value_len,
+ parse_content_disposition,
+ parse_save_params_list, part_data);
part_data->content_disposition_params =
p_strdup_empty(pool, str_c(part_data->str));
} else if (strcasecmp(name, "Content-Language") == 0) {
- (void)message_content_parse_header(t_strndup(value, value_len),
- parse_content_language, NULL,
- part_data);
+ parse_content_language(value, value_len, part_data);
} else if (strcasecmp(name, "Content-MD5") == 0 &&
part_data->content_md5 == NULL) {
part_data->content_md5 =
@@ -262,7 +267,7 @@
if (data->content_subtype != NULL)
str_append(str, data->content_subtype);
else
- str_append(str, "x-unknown");
+ str_append(str, "\"x-unknown\"");
if (!extended)
return;
Index: imap-parser.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-imap/imap-parser.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- imap-parser.c 2 Jan 2003 08:09:27 -0000 1.28
+++ imap-parser.c 3 Jan 2003 15:57:12 -0000 1.29
@@ -3,6 +3,7 @@
#include "lib.h"
#include "istream.h"
#include "ostream.h"
+#include "strescape.h"
#include "imap-parser.h"
#define is_linebreak(c) \
@@ -215,8 +216,8 @@
if (parser->str_first_escape >= 0 &&
(parser->flags & IMAP_PARSE_FLAG_NO_UNESCAPE) == 0) {
/* -1 because we skipped the '"' prefix */
- str_remove_escapes(arg->_data.str +
- parser->str_first_escape-1);
+ str_unescape(arg->_data.str +
+ parser->str_first_escape-1);
}
break;
case ARG_PARSE_LITERAL_DATA:
Index: imap-util.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-imap/imap-util.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- imap-util.c 2 Jan 2003 11:06:36 -0000 1.6
+++ imap-util.c 3 Jan 2003 15:57:12 -0000 1.7
@@ -47,29 +47,3 @@
return str_c(str);
}
-
-const char *imap_escape(const char *str)
-{
- char *ret, *p;
- size_t i, esc;
-
- /* get length of string and number of chars to escape */
- esc = 0;
- for (i = 0; str[i] != '\0'; i++) {
- if (IS_ESCAPED_CHAR(str[i]))
- esc++;
- }
-
- if (esc == 0)
- return str;
-
- /* @UNSAFE: escape them */
- p = ret = t_malloc(i + esc + 1);
- for (; *str != '\0'; str++) {
- if (IS_ESCAPED_CHAR(*str))
- *p++ = '\\';
- *p++ = *str;
- }
- *p = '\0';
- return ret;
-}
Index: imap-util.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-imap/imap-util.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- imap-util.h 19 Oct 2002 14:51:59 -0000 1.2
+++ imap-util.h 3 Jan 2003 15:57:12 -0000 1.3
@@ -28,14 +28,9 @@
MAIL_FLAGS_COUNT = 32
};
-#define IS_ESCAPED_CHAR(c) ((c) == '"' || (c) == '\\')
-
/* Return flags as a space separated string. custom_flags[] is a list of
names for custom flags, flags having NULL or "" entry are ignored. */
const char *imap_write_flags(MailFlags flags, const char *custom_flags[],
unsigned int custom_flags_count);
-
-/* Escape the string */
-const char *imap_escape(const char *str);
#endif
More information about the dovecot-cvs
mailing list