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
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
)
45 inline static void _gnutls_str_array_clear (gnutls_str_array_t
*head
)
47 gnutls_str_array_t prev
, array
= *head
;
58 inline static int _gnutls_str_array_match (gnutls_str_array_t head
, const char* str
)
60 gnutls_str_array_t array
= head
;
64 if (strcmp(array
->str
, str
) == 0) return 1;
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
);
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
;
85 *head
= gnutls_malloc(len
+ 1 + sizeof(struct gnutls_str_array_st
));
87 return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR
);
90 append(array
, str
, len
);
101 prev
->next
= gnutls_malloc(len
+ 1 + sizeof(struct gnutls_str_array_st
));
106 return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR
);
108 append(array
, str
, len
);