bugfix + change to the nextCertificate() function prototype
This commit is contained in:
parent
61c97e9fa9
commit
1bd00d0a18
@ -1764,7 +1764,7 @@ struct CertificateInfo {
|
|||||||
\verbatim
|
\verbatim
|
||||||
struct CertificateInfo* info;
|
struct CertificateInfo* info;
|
||||||
struct CertIterator* it = startListCertificates("Steffen");
|
struct CertIterator* it = startListCertificates("Steffen");
|
||||||
while( info = nextCertificate( it ) ) {
|
while( nextCertificate( it, &info ) == GPGME_No_Error && info ) {
|
||||||
do something with info.
|
do something with info.
|
||||||
dont free() it, the struct will be reused
|
dont free() it, the struct will be reused
|
||||||
by the next call to nextCertificate()
|
by the next call to nextCertificate()
|
||||||
@ -1773,7 +1773,7 @@ struct CertificateInfo {
|
|||||||
\endverbatim
|
\endverbatim
|
||||||
*/
|
*/
|
||||||
struct CertIterator* startListCertificates( const char* pattern, int remote );
|
struct CertIterator* startListCertificates( const char* pattern, int remote );
|
||||||
struct CertificateInfo* nextCertificate( struct CertIterator* );
|
int nextCertificate( struct CertIterator*, struct CertificateInfo** result );
|
||||||
void endListCertificates( struct CertIterator* );
|
void endListCertificates( struct CertIterator* );
|
||||||
|
|
||||||
|
|
||||||
|
@ -2115,6 +2115,7 @@ struct CertIterator* startListCertificates( const char* pattern, int remote )
|
|||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* free() each string in a char*[] and the array itself */
|
||||||
static void freeStringArray( char** c )
|
static void freeStringArray( char** c )
|
||||||
{
|
{
|
||||||
char** _c = c;
|
char** _c = c;
|
||||||
@ -2126,6 +2127,7 @@ static void freeStringArray( char** c )
|
|||||||
safe_free( (void**)&_c );
|
safe_free( (void**)&_c );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* free all malloc'ed data in a struct CertificateInfo */
|
||||||
static void freeInfo( struct CertificateInfo* info )
|
static void freeInfo( struct CertificateInfo* info )
|
||||||
{
|
{
|
||||||
struct DnPair* a = info->dnarray;
|
struct DnPair* a = info->dnarray;
|
||||||
@ -2145,6 +2147,8 @@ static void freeInfo( struct CertificateInfo* info )
|
|||||||
memset( info, 0, sizeof( *info ) );
|
memset( info, 0, sizeof( *info ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Format the fingerprint nicely. The caller should
|
||||||
|
free the returned value with safe_free() */
|
||||||
static char* make_fingerprint( const char* fpr )
|
static char* make_fingerprint( const char* fpr )
|
||||||
{
|
{
|
||||||
int len = strlen(fpr);
|
int len = strlen(fpr);
|
||||||
@ -2161,10 +2165,11 @@ static char* make_fingerprint( const char* fpr )
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CertificateInfo* nextCertificate( struct CertIterator* it )
|
int nextCertificate( struct CertIterator* it, struct CertificateInfo** result )
|
||||||
{
|
{
|
||||||
GpgmeError err;
|
GpgmeError err;
|
||||||
GpgmeKey key;
|
GpgmeKey key;
|
||||||
|
int retval = GPGME_No_Error;
|
||||||
assert( it );
|
assert( it );
|
||||||
err = gpgme_op_keylist_next ( it->ctx, &key);
|
err = gpgme_op_keylist_next ( it->ctx, &key);
|
||||||
if( err != GPGME_EOF ) {
|
if( err != GPGME_EOF ) {
|
||||||
@ -2173,6 +2178,7 @@ struct CertificateInfo* nextCertificate( struct CertIterator* it )
|
|||||||
unsigned long u;
|
unsigned long u;
|
||||||
char* names[MAX_GPGME_IDX+1];
|
char* names[MAX_GPGME_IDX+1];
|
||||||
struct DnPair *issuer_dn, *tmp_dn;
|
struct DnPair *issuer_dn, *tmp_dn;
|
||||||
|
retval = err;
|
||||||
memset( names, 0, sizeof( names ) );
|
memset( names, 0, sizeof( names ) );
|
||||||
freeInfo( &(it->info) );
|
freeInfo( &(it->info) );
|
||||||
|
|
||||||
@ -2188,10 +2194,10 @@ struct CertificateInfo* nextCertificate( struct CertIterator* it )
|
|||||||
struct DnPair* a = parse_dn( names[idx] );
|
struct DnPair* a = parse_dn( names[idx] );
|
||||||
if( idx == 0 ) {
|
if( idx == 0 ) {
|
||||||
it->info.userid[idx] = reorder_dn( a );
|
it->info.userid[idx] = reorder_dn( a );
|
||||||
|
it->info.dnarray = a;
|
||||||
safe_free( (void **)&(names[idx]) );
|
safe_free( (void **)&(names[idx]) );
|
||||||
} else {
|
} else {
|
||||||
it->info.userid[idx] = names[idx];
|
it->info.userid[idx] = names[idx];
|
||||||
it->info.dnarray = a;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
it->info.userid[idx] = 0;
|
it->info.userid[idx] = 0;
|
||||||
@ -2241,8 +2247,10 @@ struct CertificateInfo* nextCertificate( struct CertIterator* it )
|
|||||||
it->info.disabled = u;
|
it->info.disabled = u;
|
||||||
|
|
||||||
gpgme_key_release (key);
|
gpgme_key_release (key);
|
||||||
return &(it->info);
|
/*return &(it->info);*/
|
||||||
} else return NULL;
|
*result = &(it->info);
|
||||||
|
} else *result = NULL;
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
void endListCertificates( struct CertIterator* it )
|
void endListCertificates( struct CertIterator* it )
|
||||||
|
Loading…
Reference in New Issue
Block a user