From abd320021169986df50c8f6f21192c3bd665c058 Mon Sep 17 00:00:00 2001 From: Steffen Hansen Date: Thu, 7 Mar 2002 14:10:07 +0000 Subject: [PATCH] encryptMessage() now accepts a comma separated list of addressees --- gpgmeplug/ChangeLog | 6 ++++ gpgmeplug/gpgmeplug.c | 65 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/gpgmeplug/ChangeLog b/gpgmeplug/ChangeLog index 8307049..d75eb97 100644 --- a/gpgmeplug/ChangeLog +++ b/gpgmeplug/ChangeLog @@ -1,3 +1,9 @@ +2002-03-07 Steffen Hansen + + * gpgmeplug.c (encryptMessage): Made the function accept multiple + reciepients via addressee -- it is now parsed af a comma-separated + list. + 2002-03-06 Werner Koch * gpgmeplug.c (signMessage): Fixed offbyone. Don't include the diff --git a/gpgmeplug/gpgmeplug.c b/gpgmeplug/gpgmeplug.c index 403df1d..8fb11ae 100644 --- a/gpgmeplug/gpgmeplug.c +++ b/gpgmeplug/gpgmeplug.c @@ -50,6 +50,7 @@ #include #include #include +#include #ifndef BUG_URL #define BUG_URL "http:://www.gnupg.org/aegypten/" @@ -1067,6 +1068,61 @@ bool storeCertificatesFromMessage( const char* ciphertext ){ return true; } +/* returns the next address in a comma-separated list + or NULL if the list is empty. The function honors double quotes + and '(' ')' comments. + A non-NULL return value should be deleted with free(). +*/ +static char* nextAddress( const char** address ) +{ + const char *start = *address; + char* result = NULL; + int quote = 0; + int comment = 0; + int found = 0; + if( *address == NULL ) return NULL; + while( **address ) { + + switch( **address ) { + case '\\': /* escaped character */ + ++(*address); + break; + case '"': + if( comment == 0 ) { + if( quote > 0 ) --quote; + else ++quote; + } + break; + case '(': /* comment start */ + if( quote == 0 ) ++comment; + break; + case ')': /* comment end */ + if( quote == 0 ) --comment; + break; + case '\0': + case ',': /* delimiter */ + if( quote == 0 && comment == 0 ) { + found = 1; + } + break; + } + ++(*address); + if( found ) break; + } + if( found || **address == 0 ) { + size_t len; + while( isspace( *start ) ) ++start; + len = *address - start; + if( len > 0 ) { + if( **address != 0 ) --len; + result = malloc( len*sizeof(char)+1 ); + strncpy( result, start, len ); + result[len] = '\0'; + } + } + return result; +} + bool encryptMessage( const char* cleartext, const char** ciphertext, const char* addressee, @@ -1104,8 +1160,13 @@ bool encryptMessage( const char* cleartext, } else { - gpgme_recipients_add_name (rset, addressee); - fprintf( stderr, "\nGPGMEPLUG encryptMessage() using addressee %s\n", addressee ); + const char* p = addressee; + char* tok; + while( (tok = nextAddress( &p ) ) != 0 ) { + gpgme_recipients_add_name (rset, tok); + fprintf( stderr, "\nGPGMEPLUG encryptMessage() using addressee %s\n", tok ); + free(tok); + } } -- 2.26.2