/* Parse a DN and return an array-ized one. This is not a validating parser and it does not support any old-stylish syntax; gpgme is expected to return only rfc2253 compatible strings. */ static Kleo::DN::Attribute::List parse_dn( const unsigned char * string ) { if ( !string ) return QValueVector<Kleo::DN::Attribute>(); QValueVector<Kleo::DN::Attribute> result; while (*string) { while (*string == ' ') string++; if (!*string) break; /* ready */ DnPair pair = { 0, 0 }; string = parse_dn_part (&pair, string); if (!string) goto failure; if ( pair.key && pair.value ) result.push_back( Kleo::DN::Attribute( QString::fromUtf8( pair.key ), QString::fromUtf8( pair.value ) ) ); free( pair.key ); free( pair.value ); while (*string == ' ') string++; if (*string && *string != ',' && *string != ';' && *string != '+') goto failure; /* invalid delimiter */ if (*string) string++; } return result; failure: return QValueVector<Kleo::DN::Attribute>(); }
/* Parse a DN and return an array-ized one. This is not a validating parser and it does not support any old-stylish syntax; KSBA is expected to return only rfc2253 compatible strings. */ static struct dn_array_s * parse_dn (const char *string) { struct dn_array_s *array; size_t arrayidx, arraysize; int i; arraysize = 7; /* C,ST,L,O,OU,CN,email */ arrayidx = 0; array = g_try_malloc ((arraysize+1) * sizeof *array); if (!array) return NULL; while (*string) { while (*string == ' ') string++; if (!*string) break; /* Ready. */ if (arrayidx >= arraysize) { struct dn_array_s *a2; arraysize += 5; a2 = g_try_realloc (array, (arraysize+1) * sizeof *array); if (!a2) goto failure; array = a2; } array[arrayidx].key = NULL; array[arrayidx].value = NULL; string = parse_dn_part (array+arrayidx, string); if (!string) goto failure; while (*string == ' ') string++; array[arrayidx].multivalued = (*string == '+'); array[arrayidx].done = 0; arrayidx++; if (*string && *string != ',' && *string != ';' && *string != '+') goto failure; /* Invalid delimiter. */ if (*string) string++; } array[arrayidx].key = NULL; array[arrayidx].value = NULL; return array; failure: for (i=0; i < arrayidx; i++) { g_free (array[i].key); g_free (array[i].value); } g_free (array); return NULL; }