From: Steffen Hansen Date: Thu, 7 Mar 2002 14:10:07 +0000 (+0000) Subject: encryptMessage() now accepts a comma separated list of addressees X-Git-Tag: gpgme-1.2.0@1385~1049 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=36bb3b61eea59f0a5e0ebe3f0e3f188a7986e87f;p=gpgme.git encryptMessage() now accepts a comma separated list of addressees --- diff --git a/trunk/gpgmeplug/ChangeLog b/trunk/gpgmeplug/ChangeLog index 8307049..d75eb97 100644 --- a/trunk/gpgmeplug/ChangeLog +++ b/trunk/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/trunk/gpgmeplug/gpgmeplug.c b/trunk/gpgmeplug/gpgmeplug.c index 403df1d..8fb11ae 100644 --- a/trunk/gpgmeplug/gpgmeplug.c +++ b/trunk/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); + } }