certtool is able to set certificate policies via a template
[gnutls.git] / lib / gnutls_str_array.h
blobfdf3a1d98719deb27408f7f3ecfd44c03fd8dd74
1 /*
2 * Copyright (C) 2011-2012 Free Software Foundation, Inc.
4 * Author: Nikos Mavrogiannopoulos
6 * This file is part of GnuTLS.
8 * The GnuTLS is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 3 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
23 #ifndef GNUTLS_STR_ARRAY_H
24 #define GNUTLS_STR_ARRAY_H
26 #include <gnutls_int.h>
27 #include <gnutls_errors.h>
29 /* Functionality to allow an array of strings. Strings
30 * are allowed to be added to the list and matched against it.
33 typedef struct gnutls_str_array_st
35 char* str;
36 unsigned int len;
37 struct gnutls_str_array_st* next;
38 } *gnutls_str_array_t;
40 inline static void _gnutls_str_array_init(gnutls_str_array_t* head)
42 *head = NULL;
45 inline static void _gnutls_str_array_clear (gnutls_str_array_t *head)
47 gnutls_str_array_t prev, array = *head;
49 while(array != NULL)
51 prev = array;
52 array = prev->next;
53 gnutls_free(prev);
55 *head = NULL;
58 inline static int _gnutls_str_array_match (gnutls_str_array_t head, const char* str)
60 gnutls_str_array_t array = head;
62 while(array != NULL)
64 if (strcmp(array->str, str) == 0) return 1;
65 array = array->next;
68 return 0;
71 inline static void append(gnutls_str_array_t array, const char* str, int len)
73 array->str = ((char*)array) + sizeof(struct gnutls_str_array_st);
74 memcpy(array->str, str, len);
75 array->str[len] = 0;
76 array->len = len;
77 array->next = NULL;
80 inline static int _gnutls_str_array_append (gnutls_str_array_t* head, const char* str, int len)
82 gnutls_str_array_t prev, array;
83 if (*head == NULL)
85 *head = gnutls_malloc(len + 1 + sizeof(struct gnutls_str_array_st));
86 if (*head == NULL)
87 return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
89 array = *head;
90 append(array, str, len);
92 else
94 array = *head;
95 prev = array;
96 while(array != NULL)
98 prev = array;
99 array = prev->next;
101 prev->next = gnutls_malloc(len + 1 + sizeof(struct gnutls_str_array_st));
103 array = prev->next;
105 if (array == NULL)
106 return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
108 append(array, str, len);
111 return 0;
114 #endif