2 * Copyright (c) 2007 - 2008 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * @page page_env Hx509 environment functions
39 * See the library functions here: @ref hx509_env
43 * Add a new key/value pair to the hx509_env.
45 * @param context A hx509 context.
46 * @param env environment to add the environment variable too.
47 * @param key key to add
48 * @param value value to add
50 * @return An hx509 error code, see hx509_get_error_string().
55 HX509_LIB_FUNCTION
int HX509_LIB_CALL
56 hx509_env_add(hx509_context context
, hx509_env
*env
,
57 const char *key
, const char *value
)
61 n
= malloc(sizeof(*n
));
63 hx509_set_error_string(context
, 0, ENOMEM
, "out of memory");
69 n
->name
= strdup(key
);
70 if (n
->name
== NULL
) {
74 n
->u
.string
= strdup(value
);
75 if (n
->u
.string
== NULL
) {
94 * Add a new key/binding pair to the hx509_env.
96 * @param context A hx509 context.
97 * @param env environment to add the environment variable too.
98 * @param key key to add
99 * @param list binding list to add
101 * @return An hx509 error code, see hx509_get_error_string().
106 HX509_LIB_FUNCTION
int HX509_LIB_CALL
107 hx509_env_add_binding(hx509_context context
, hx509_env
*env
,
108 const char *key
, hx509_env list
)
112 n
= malloc(sizeof(*n
));
114 hx509_set_error_string(context
, 0, ENOMEM
, "out of memory");
120 n
->name
= strdup(key
);
121 if (n
->name
== NULL
) {
141 * Search the hx509_env for a length based key.
143 * @param context A hx509 context.
144 * @param env environment to add the environment variable too.
145 * @param key key to search for.
146 * @param len length of key.
148 * @return the value if the key is found, NULL otherwise.
153 HX509_LIB_FUNCTION
const char * HX509_LIB_CALL
154 hx509_env_lfind(hx509_context context
, hx509_env env
,
155 const char *key
, size_t len
)
158 if (strncmp(key
, env
->name
,len
) == 0
159 && env
->name
[len
] == '\0' && env
->type
== env_string
)
160 return env
->u
.string
;
167 * Search the hx509_env for a key.
169 * @param context A hx509 context.
170 * @param env environment to add the environment variable too.
171 * @param key key to search for.
173 * @return the value if the key is found, NULL otherwise.
178 HX509_LIB_FUNCTION
const char * HX509_LIB_CALL
179 hx509_env_find(hx509_context context
, hx509_env env
, const char *key
)
182 if (strcmp(key
, env
->name
) == 0 && env
->type
== env_string
)
183 return env
->u
.string
;
190 * Search the hx509_env for a binding.
192 * @param context A hx509 context.
193 * @param env environment to add the environment variable too.
194 * @param key key to search for.
196 * @return the binding if the key is found, NULL if not found.
202 hx509_env_find_binding(hx509_context context
,
207 if (strcmp(key
, env
->name
) == 0 && env
->type
== env_list
)
215 env_free(hx509_env b
)
218 hx509_env next
= b
->next
;
220 if (b
->type
== env_string
)
222 else if (b
->type
== env_list
)
232 * Free an hx509_env environment context.
234 * @param env the environment to free.
239 HX509_LIB_FUNCTION
void HX509_LIB_CALL
240 hx509_env_free(hx509_env
*env
)