Add function load_csr(file,format,desc) to apps/lib/apps.c
[openssl.git] / apps / lib / names.c
1 /*
2  * Copyright 2019 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
10 #include <string.h>
11 #include <openssl/bio.h>
12 #include <openssl/safestack.h>
13 #include "names.h"
14
15 DEFINE_STACK_OF_CSTRING()
16
17 #ifdef _WIN32
18 # define strcasecmp _stricmp
19 #endif
20
21 int name_cmp(const char * const *a, const char * const *b)
22 {
23     return strcasecmp(*a, *b);
24 }
25
26 void collect_names(const char *name, void *vdata)
27 {
28     STACK_OF(OPENSSL_CSTRING) *names = vdata;
29
30     sk_OPENSSL_CSTRING_push(names, name);
31 }
32
33 void print_names(BIO *out, STACK_OF(OPENSSL_CSTRING) *names)
34 {
35     int i = sk_OPENSSL_CSTRING_num(names);
36     int j;
37
38     sk_OPENSSL_CSTRING_sort(names);
39     if (i > 1)
40         BIO_printf(out, "{ ");
41     for (j = 0; j < i; j++) {
42         const char *name = sk_OPENSSL_CSTRING_value(names, j);
43
44         if (j > 0)
45             BIO_printf(out, ", ");
46         BIO_printf(out, "%s", name);
47     }
48     if (i > 1)
49         BIO_printf(out, " }");
50 }