Remove mempool code, we use the stuff in e-util. (PRESERVE_HEADERS): new

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.

svn path=/trunk/; revision=23343
This commit is contained in:
Not Zed
2003-11-13 23:17:31 +00:00
committed by Michael Zucci
parent cac6efa61f
commit 2699c4c41f
7 changed files with 87 additions and 154 deletions

View File

@ -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.

View File

@ -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);

View File

@ -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;

View File

@ -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();

View File

@ -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

View File

@ -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;

View File

@ -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));