aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--camel/ChangeLog21
-rw-r--r--camel/camel-gpg-context.c2
-rw-r--r--camel/camel-mime-parser.c146
-rw-r--r--camel/tests/message/test1.c2
-rw-r--r--camel/tests/smime/Makefile.am6
-rw-r--r--camel/tests/smime/pgp-mime.c2
-rw-r--r--camel/tests/smime/pgp.c62
7 files changed, 87 insertions, 154 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index e9d9132bfe..9058fe0267 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,5 +1,26 @@
2003-11-13 Not Zed <NotZed@Ximian.com>
+ * camel-mime-parser.c: Remove mempool code, we use the stuff in
+ e-util.
+ (PRESERVE_HEADERS): new compile option, if on, we preserve headers
+ and folding exactly rather than unfolding all input. THIS BREAKS
+ EVERYTHING right now, so don't turn it on.
+
+ * camel-gpg-context.c (gpg_decrypt): reset the input memstream
+ before passing it to the gpg engine.
+
+ * tests/smime/pgp-mime.c (main): redirect /dev/null to stdin so it
+ doesn't hang waiting for input.
+ (main): removed from build - this tests multipart/signed
+ explictly, but now the details of this is handled directly by the
+ cipher context.
+
+ * tests/smime/pgp.c (main): fixes for api changes.
+ (main): redirect /dev/null to stdin so it doesn't hang waiting for
+ input.
+
+ * tests/message/test1.c (main): update for api changes.
+
* camel-smime-context.c (sm_verify): look at the content object's
mime type, not the container's type.
diff --git a/camel/camel-gpg-context.c b/camel/camel-gpg-context.c
index 71b9106e10..87cf1b8647 100644
--- a/camel/camel-gpg-context.c
+++ b/camel/camel-gpg-context.c
@@ -1569,6 +1569,8 @@ gpg_decrypt(CamelCipherContext *context, CamelMimePart *ipart, CamelMimePart *op
istream = camel_stream_mem_new();
camel_data_wrapper_write_to_stream(camel_medium_get_content_object((CamelMedium *)ipart), istream);
+ camel_stream_reset(istream);
+
/* TODO: de-canonicalise end of lines? */
/*stream = camel_stream_mem_new ();
filtered_stream = (CamelStream *) camel_stream_filter_new_with_stream (stream);
diff --git a/camel/camel-mime-parser.c b/camel/camel-mime-parser.c
index 7f2c515b3b..214b48bc33 100644
--- a/camel/camel-mime-parser.c
+++ b/camel/camel-mime-parser.c
@@ -51,6 +51,8 @@
#define c(x)
#define d(x)
+/*#define PRESERVE_HEADERS*/
+
/*#define PURIFY*/
#define MEMPOOL
@@ -62,136 +64,6 @@ int inend_id = -1,
inbuffer_id = -1;
#endif
-#if 0
-extern int strdup_count;
-extern int malloc_count;
-extern int free_count;
-
-#define g_strdup(x) (strdup_count++, g_strdup(x))
-#define g_malloc(x) (malloc_count++, g_malloc(x))
-#define g_free(x) (free_count++, g_free(x))
-#endif
-
-#ifdef MEMPOOL
-typedef struct _MemPoolNode {
- struct _MemPoolNode *next;
-
- int free;
- char data[1];
-} MemPoolNode;
-
-typedef struct _MemPoolThresholdNode {
- struct _MemPoolThresholdNode *next;
- char data[1];
-} MemPoolThresholdNode;
-
-typedef struct _MemPool {
- int blocksize;
- int threshold;
- struct _MemPoolNode *blocks;
- struct _MemPoolThresholdNode *threshold_blocks;
-} MemPool;
-
-MemPool *mempool_new(int blocksize, int threshold);
-void *mempool_alloc(MemPool *pool, int size);
-void mempool_flush(MemPool *pool, int freeall);
-void mempool_free(MemPool *pool);
-
-MemPool *mempool_new(int blocksize, int threshold)
-{
- MemPool *pool;
-
- pool = g_malloc(sizeof(*pool));
- if (threshold >= blocksize)
- threshold = blocksize * 2 / 3;
- pool->blocksize = blocksize;
- pool->threshold = threshold;
- pool->blocks = NULL;
- pool->threshold_blocks = NULL;
- return pool;
-}
-
-void *mempool_alloc(MemPool *pool, int size)
-{
- size = (size + STRUCT_ALIGN) & (~(STRUCT_ALIGN-1));
- if (size>=pool->threshold) {
- MemPoolThresholdNode *n;
-
- n = g_malloc(sizeof(*n) - sizeof(char) + size);
- n->next = pool->threshold_blocks;
- pool->threshold_blocks = n;
- return &n->data[0];
- } else {
- MemPoolNode *n;
-
- n = pool->blocks;
- while (n) {
- if (n->free >= size) {
- n->free -= size;
- return &n->data[n->free];
- }
- n = n->next;
- }
-
- n = g_malloc(sizeof(*n) - sizeof(char) + pool->blocksize);
- n->next = pool->blocks;
- pool->blocks = n;
- n->free = pool->blocksize - size;
- return &n->data[n->free];
- }
-}
-
-void mempool_flush(MemPool *pool, int freeall)
-{
- MemPoolThresholdNode *tn, *tw;
- MemPoolNode *pw, *pn;
-
- tw = pool->threshold_blocks;
- while (tw) {
- tn = tw->next;
- g_free(tw);
- tw = tn;
- }
- pool->threshold_blocks = NULL;
-
- if (freeall) {
- pw = pool->blocks;
- while (pw) {
- pn = pw->next;
- g_free(pw);
- pw = pn;
- }
- pool->blocks = NULL;
- } else {
- pw = pool->blocks;
- while (pw) {
- pw->free = pool->blocksize;
- pw = pw->next;
- }
- }
-}
-
-void mempool_free(MemPool *pool)
-{
- if (pool) {
- mempool_flush(pool, 1);
- g_free(pool);
- }
-}
-
-#endif
-
-
-
-
-
-
-
-
-
-
-
-
#define SCAN_BUF 4096 /* size of read buffer */
#define SCAN_HEAD 128 /* headroom guaranteed to be before each read buffer */
@@ -1310,8 +1182,11 @@ folder_scan_header(struct _header_scan_state *s, int *lastone)
h(printf("got line part: '%.*s'\n", inptr-1-start, start));
/* got a line, strip and add it, process it */
s->midline = FALSE;
+#ifdef PRESERVE_HEADERS
+ header_append(s, start, inptr);
+#else
header_append(s, start, inptr-1);
-
+#endif
/* check for end of headers */
if (s->outbuf == s->outptr)
goto header_done;
@@ -1319,6 +1194,7 @@ folder_scan_header(struct _header_scan_state *s, int *lastone)
/* check for continuation/compress headers, we have atleast 1 char here to work with */
if (inptr[0] == ' ' || inptr[0] == '\t') {
h(printf("continuation\n"));
+#ifndef PRESERVE_HEADERS
/* TODO: this wont catch multiple space continuation across a read boundary, but
that is assumed rare, and not fatal anyway */
do
@@ -1326,11 +1202,17 @@ folder_scan_header(struct _header_scan_state *s, int *lastone)
while (*inptr == ' ' || *inptr == '\t');
inptr--;
*inptr = ' ';
+#endif
} else {
/* otherwise, complete header, add it */
+#ifdef PRESERVE_HEADERS
+ s->outptr--;
+ if (s->outptr[-1] == '\r')
+ s->outptr--;
+#endif
s->outptr[0] = 0;
- h(printf("header '%.20s' at %d\n", s->outbuf, (int)s->header_start));
+ h(printf("header '%s' at %d\n", s->outbuf, (int)s->header_start));
header_raw_append_parse(&h->headers, s->outbuf, s->header_start);
s->outptr = s->outbuf;
diff --git a/camel/tests/message/test1.c b/camel/tests/message/test1.c
index 3c16dab963..8dcf84c92c 100644
--- a/camel/tests/message/test1.c
+++ b/camel/tests/message/test1.c
@@ -162,7 +162,7 @@ int main(int argc, char **argv)
push("testing text number %d", j);
text = texts[j].text;
len = texts[j].len;
- for (i=0;i<CAMEL_MIME_PART_NUM_ENCODINGS;i++) {
+ for (i=0;i<CAMEL_TRANSFER_NUM_ENCODINGS;i++) {
push("test simple message, encoding %s", camel_transfer_encoding_to_string(i));
msg = test_message_create_simple();
diff --git a/camel/tests/smime/Makefile.am b/camel/tests/smime/Makefile.am
index ea3cab9d52..b14d804dc3 100644
--- a/camel/tests/smime/Makefile.am
+++ b/camel/tests/smime/Makefile.am
@@ -17,8 +17,8 @@ LDADD = \
$(EVOLUTION_MAIL_LIBS)
check_PROGRAMS = \
- pgp \
- pgp-mime
+ pgp
+# pgp-mime
# pkcs7
-TESTS = pgp pgp-mime #pkcs7
+TESTS = pgp #pgp-mime pkcs7
diff --git a/camel/tests/smime/pgp-mime.c b/camel/tests/smime/pgp-mime.c
index 557b3353ab..102092679a 100644
--- a/camel/tests/smime/pgp-mime.c
+++ b/camel/tests/smime/pgp-mime.c
@@ -141,7 +141,7 @@ int main (int argc, char **argv)
setenv ("GNUPGHOME", "/tmp/camel-test/.gnupg", 1);
/* import the gpg keys */
- if ((ret = system ("gpg > /dev/null 2>&1")) == -1)
+ if ((ret = system ("gpg < /dev/null > /dev/null 2>&1")) == -1)
return 77;
else if (WEXITSTATUS (ret) == 127)
return 77;
diff --git a/camel/tests/smime/pgp.c b/camel/tests/smime/pgp.c
index 2c8de8ccd1..81ea6fabdf 100644
--- a/camel/tests/smime/pgp.c
+++ b/camel/tests/smime/pgp.c
@@ -120,8 +120,9 @@ int main (int argc, char **argv)
CamelCipherContext *ctx;
CamelException *ex;
CamelCipherValidity *valid;
- CamelStream *stream1, *stream2, *stream3;
- struct _CamelMimePart *sigpart;
+ CamelStream *stream1, *stream2;
+ struct _CamelMimePart *sigpart, *conpart, *encpart, *outpart;
+ CamelDataWrapper *dw;
GPtrArray *recipients;
GByteArray *buf;
char *before, *after;
@@ -135,7 +136,7 @@ int main (int argc, char **argv)
setenv ("GNUPGHOME", "/tmp/camel-test/.gnupg", 1);
/* import the gpg keys */
- if ((ret = system ("gpg > /dev/null 2>&1")) == -1)
+ if ((ret = system ("gpg < /dev/null > /dev/null 2>&1")) == -1)
return 77;
else if (WEXITSTATUS (ret) == 127)
return 77;
@@ -155,58 +156,85 @@ int main (int argc, char **argv)
stream1 = camel_stream_mem_new ();
camel_stream_write (stream1, "Hello, I am a test stream.\n", 27);
camel_stream_reset (stream1);
-
+
+ conpart = camel_mime_part_new();
+ dw = camel_data_wrapper_new();
+ camel_data_wrapper_construct_from_stream(dw, stream1);
+ camel_medium_set_content_object((CamelMedium *)conpart, dw);
+ camel_object_unref(stream1);
+ camel_object_unref(dw);
+
sigpart = camel_mime_part_new();
camel_test_push ("PGP signing");
- camel_cipher_sign (ctx, "no.user@no.domain", CAMEL_CIPHER_HASH_SHA1, stream1, sigpart, ex);
+ camel_cipher_sign (ctx, "no.user@no.domain", CAMEL_CIPHER_HASH_SHA1, conpart, sigpart, ex);
check_msg (!camel_exception_is_set (ex), "%s", camel_exception_get_description (ex));
camel_test_pull ();
camel_exception_clear (ex);
camel_test_push ("PGP verify");
- camel_stream_reset (stream1);
- valid = camel_cipher_verify (ctx, CAMEL_CIPHER_HASH_SHA1, stream1, sigpart, ex);
+ valid = camel_cipher_verify (ctx, sigpart, ex);
check_msg (!camel_exception_is_set (ex), "%s", camel_exception_get_description (ex));
check_msg (camel_cipher_validity_get_valid (valid), "%s", camel_cipher_validity_get_description (valid));
camel_cipher_validity_free (valid);
camel_test_pull ();
- camel_object_unref(stream1);
+ camel_object_unref(conpart);
camel_object_unref(sigpart);
stream1 = camel_stream_mem_new ();
- stream2 = camel_stream_mem_new ();
- stream3 = camel_stream_mem_new ();
-
camel_stream_write (stream1, "Hello, I am a test of encryption/decryption.", 44);
camel_stream_reset (stream1);
+
+ conpart = camel_mime_part_new();
+ dw = camel_data_wrapper_new();
+ camel_stream_reset(stream1);
+ camel_data_wrapper_construct_from_stream(dw, stream1);
+ camel_medium_set_content_object((CamelMedium *)conpart, dw);
+ camel_object_unref(stream1);
+ camel_object_unref(dw);
+
+ encpart = camel_mime_part_new();
camel_exception_clear (ex);
camel_test_push ("PGP encrypt");
recipients = g_ptr_array_new ();
g_ptr_array_add (recipients, "no.user@no.domain");
- camel_cipher_encrypt (ctx, FALSE, "no.user@no.domain", recipients,
- stream1, stream2, ex);
+ camel_cipher_encrypt (ctx, "no.user@no.domain", recipients, conpart, encpart, ex);
check_msg (!camel_exception_is_set (ex), "%s", camel_exception_get_description (ex));
g_ptr_array_free (recipients, TRUE);
camel_test_pull ();
-
- camel_stream_reset (stream2);
+
camel_exception_clear (ex);
camel_test_push ("PGP decrypt");
- camel_cipher_decrypt (ctx, stream2, stream3, ex);
+ outpart = camel_mime_part_new();
+ valid = camel_cipher_decrypt (ctx, encpart, outpart, ex);
check_msg (!camel_exception_is_set (ex), "%s", camel_exception_get_description (ex));
+ check_msg (valid->encrypt.status == CAMEL_CIPHER_VALIDITY_ENCRYPT_ENCRYPTED, "%s", valid->encrypt.description);
+
+ stream1 = camel_stream_mem_new();
+ stream2 = camel_stream_mem_new();
+
+ camel_data_wrapper_write_to_stream((CamelDataWrapper *)conpart, stream1);
+ camel_data_wrapper_write_to_stream((CamelDataWrapper *)outpart, stream2);
+
buf = CAMEL_STREAM_MEM (stream1)->buffer;
before = g_strndup (buf->data, buf->len);
- buf = CAMEL_STREAM_MEM (stream3)->buffer;
+ buf = CAMEL_STREAM_MEM (stream2)->buffer;
after = g_strndup (buf->data, buf->len);
check_msg (string_equal (before, after), "before = '%s', after = '%s'", before, after);
g_free (before);
g_free (after);
+
+ camel_object_unref(stream1);
+ camel_object_unref(stream2);
+ camel_object_unref(conpart);
+ camel_object_unref(encpart);
+ camel_object_unref(outpart);
+
camel_test_pull ();
camel_object_unref (CAMEL_OBJECT (ctx));