names.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <string.h>
  10. #include <openssl/bio.h>
  11. #include <openssl/safestack.h>
  12. #include "names.h"
  13. #ifdef _WIN32
  14. # define strcasecmp _stricmp
  15. #endif
  16. int name_cmp(const char * const *a, const char * const *b)
  17. {
  18. return strcasecmp(*a, *b);
  19. }
  20. void collect_names(const char *name, void *vdata)
  21. {
  22. STACK_OF(OPENSSL_CSTRING) *names = vdata;
  23. sk_OPENSSL_CSTRING_push(names, name);
  24. }
  25. void print_names(BIO *out, STACK_OF(OPENSSL_CSTRING) *names)
  26. {
  27. int i = sk_OPENSSL_CSTRING_num(names);
  28. int j;
  29. sk_OPENSSL_CSTRING_sort(names);
  30. if (i > 1)
  31. BIO_printf(out, "{ ");
  32. for (j = 0; j < i; j++) {
  33. const char *name = sk_OPENSSL_CSTRING_value(names, j);
  34. if (j > 0)
  35. BIO_printf(out, ", ");
  36. BIO_printf(out, "%s", name);
  37. }
  38. if (i > 1)
  39. BIO_printf(out, " }");
  40. }