Replaced builder_t objects by simple builder_function_t functions
[strongswan.git] / src / libstrongswan / credentials / credential_factory.h
1 /*
2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup credential_factory credential_factory
18 * @{ @ingroup credentials
19 */
20
21 #ifndef CREDENTIAL_FACTORY_H_
22 #define CREDENTIAL_FACTORY_H_
23
24 typedef struct credential_factory_t credential_factory_t;
25 typedef enum credential_type_t credential_type_t;
26
27 #include <credentials/builder.h>
28
29 /**
30 * Kind of credential.
31 */
32 enum credential_type_t {
33 /** private key, implemented in private_key_t */
34 CRED_PRIVATE_KEY,
35 /** public key, implemented in public_key_t */
36 CRED_PUBLIC_KEY,
37 /** certificates, implemented in certificate_t */
38 CRED_CERTIFICATE,
39 };
40
41 /**
42 * enum names for credential_type_t
43 */
44 extern enum_name_t *credential_type_names;
45
46 /**
47 * Manages credential construction functions and creates instances.
48 */
49 struct credential_factory_t {
50
51 /**
52 * Create a credential using a list of builder_part_t's.
53 *
54 * The variable argument list takes builder_part_t types followed
55 * by the type specific value. The list must be terminated using BUILD_END.
56 * All passed parts get cloned/refcounted by the builder functions,
57 * so free up allocated ressources after successful and unsuccessful
58 * invocations.
59 *
60 * @param type credential type to build
61 * @param subtype subtype specific for type of the credential
62 * @param ... build_part_t arguments, BUILD_END terminated.
63 * @return type specific credential, NULL if failed
64 */
65 void* (*create)(credential_factory_t *this, credential_type_t type,
66 int subtype, ...);
67
68 /**
69 * Register a credential builder function.
70 *
71 * @param type type of credential the builder creates
72 * @param constructor builder constructor function to register
73 */
74 void (*add_builder)(credential_factory_t *this,
75 credential_type_t type, int subtype,
76 builder_function_t constructor);
77 /**
78 * Unregister a credential builder function.
79 *
80 * @param constructor constructor function to unregister.
81 */
82 void (*remove_builder)(credential_factory_t *this,
83 builder_function_t constructor);
84
85 /**
86 * Destroy a credential_factory instance.
87 */
88 void (*destroy)(credential_factory_t *this);
89 };
90
91 /**
92 * Create a credential_factory instance.
93 */
94 credential_factory_t *credential_factory_create();
95
96 #endif /** CREDENTIAL_FACTORY_H_ @}*/