source code open
[framework/security/cert-svc.git] / vcore / src / cert-svc / cstring.h
1 /**
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *    http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /*
17  * @file        cstring.h
18  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
19  * @version     1.0
20  * @brief       This is part of C api for ValidationCore.
21  */
22 #ifndef _CERTSVC_CSTRING_H_
23 #define _CERTSVC_CSTRING_H_
24
25 #include <cert-svc/cinstance.h>
26 #include <cert-svc/cstring.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32
33 typedef struct CertSvcStringList_t {
34     int privateHandler;
35     CertSvcInstance privateInstance;
36 } CertSvcStringList;
37
38 typedef struct CertSvcString_t {
39     char* privateHandler;
40     int privateLength;
41     CertSvcInstance privateInstance;
42 } CertSvcString;
43
44 /**
45  * This function will duplicate input data. Data in ouput string will be managed by certsvc.
46  *
47  * @param[in] instance CertSvcString will be conected with this instance.
48  * @param[in] input Input data.
49  * @param[in] size Input buffer size.
50  * @param[out] output Buffer with output data.
51  * @return CERTSVC_SUCCESS, CERTSVC_FAIL, CERTSVC_WRONG_ARGUMENT
52  */
53 int certsvc_string_new(
54     CertSvcInstance instance,
55     const char *input,
56     int size,
57     CertSvcString *output);
58
59 /**
60  * This function wont duplicate input data. Output param will contain pointer to input
61  * so input could not be free as long as ouput param is used.
62  *
63  * @param[in] instance CertSvcString will be conected with this instance.
64  * @param[in] input Input data.
65  * @param[in] size Input buffer size.
66  * @param[out] output Buffer with output data.
67  * @return CERTSVC_SUCCESS, CERTSVC_WRONG_ARGUMENT
68  */
69 int certsvc_string_not_managed(
70     CertSvcInstance instance,
71     const char *input,
72     int size,
73     CertSvcString *output);
74
75 /**
76  * Extract next result from result set. Function certsvc_string_list_free
77  * does not free results returned by this function. CertSvcString is valid
78  * until certsvc_string_free or vcore_instance_reset or vcore_instance_free
79  * is called.
80  *
81  * @param[in] handler Handler to set of strings.
82  * @param[out] buffer The buffer will be pointing to string with distrubution point url or will be set to NULL if error occures.
83  * @param[out] size Size of data pointed by buffer or 0 if error occures.
84  * @return CERTSVC_SUCCESS, CERTSVC_FAIL, CERTSVC_WRONG_ARGUMENT, CERTSVC_BAD_ALLOC
85  */
86 int certsvc_string_list_get_one(CertSvcStringList hander,
87                                 int position,
88                                 CertSvcString *buffer);
89
90 /**
91  * Extract CertSvcStringList size.
92  *
93  * @param[in] handler Handler to string list.
94  * @param[out] size Number of elements on the list.
95  * @return CERTSVC_SUCCESS, CERTSVC_WRONG_ARGUMENT
96  */
97 int certsvc_string_list_get_length(CertSvcStringList hander,int *size);
98
99 /**
100  * Free data.
101  *
102  * @param[in] string Data allocated by certsvc_certificate_get_string_field
103  */
104 void certsvc_string_free(CertSvcString string);
105
106 /**
107  * Free string list.
108  *
109  * Note: This function does not free strings returned by certsvc_string_list_get_one_result.
110  *
111  * @param[in] handler String set handler.
112  */
113 void certsvc_string_list_free(CertSvcStringList handler);
114
115 /**
116  * Convert CertSvcStringPtr into pure c pointer. Please note that this pointer is valid as long as CertSvcString is valid.
117  *
118  * @param[in] string CertSvcStringPtr.
119  * @param[out] buffer cstring
120  * @param[out] len Length of cstring
121  */
122 void certsvc_string_to_cstring(CertSvcString string, const char **buffer, int *len);
123
124 #ifdef __cplusplus
125 }
126 #endif
127
128 #endif
129