2e0be59928a6c55f8d9ae58f7147951ad94b6f89
[platform/core/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     size_t privateHandler;
35     CertSvcInstance privateInstance;
36 } CertSvcStringList;
37
38 typedef struct CertSvcString_t {
39     /*
40      * You are not allowed to use private fields of this structure. It is internal
41      * implementation of strings and it may change at any time without notice!
42      * To extract data use certsvc_string_to_cstring function!
43      */
44     char *privateHandler;
45     size_t privateLength;
46     CertSvcInstance privateInstance;
47 } CertSvcString;
48
49 /**
50  * This function will duplicate input data. Data in ouput string will be managed by certsvc.
51  *
52  * @param[in] instance CertSvcString will be conected with this instance.
53  * @param[in] input Input data.
54  * @param[in] size Input buffer size.
55  * @param[out] output Buffer with output data.
56  * @return CERTSVC_SUCCESS, CERTSVC_FAIL, CERTSVC_WRONG_ARGUMENT
57  */
58 int certsvc_string_new(
59     CertSvcInstance instance,
60     const char *input,
61     size_t size,
62     CertSvcString *output);
63
64 /**
65  * This function wont duplicate input data. Output param will contain pointer to input
66  * so input could not be free as long as ouput param is used.
67  *
68  * @param[in] instance CertSvcString will be conected with this instance.
69  * @param[in] input Input data.
70  * @param[in] size Input buffer size.
71  * @param[out] output Buffer with output data.
72  * @return CERTSVC_SUCCESS, CERTSVC_WRONG_ARGUMENT
73  */
74 int certsvc_string_not_managed(
75     CertSvcInstance instance,
76     const char *input,
77     size_t size,
78     CertSvcString *output);
79
80 /**
81  * Extract next result from result set. Function certsvc_string_list_free
82  * does not free results returned by this function. CertSvcString is valid
83  * until certsvc_string_free or vcore_instance_reset or vcore_instance_free
84  * is called.
85  *
86  * @param[in] handler Handler to set of strings.
87  * @param[out] buffer The buffer will be pointing to string with distrubution point url or will be set to NULL if error occures.
88  * @param[out] size Size of data pointed by buffer or 0 if error occures.
89  * @return CERTSVC_SUCCESS, CERTSVC_FAIL, CERTSVC_WRONG_ARGUMENT, CERTSVC_BAD_ALLOC
90  */
91 int certsvc_string_list_get_one(CertSvcStringList hander,
92                                 size_t position,
93                                 CertSvcString *buffer);
94
95 /**
96  * Extract CertSvcStringList size.
97  *
98  * @param[in] handler Handler to string list.
99  * @param[out] size Number of elements on the list.
100  * @return CERTSVC_SUCCESS, CERTSVC_WRONG_ARGUMENT
101  */
102 int certsvc_string_list_get_length(CertSvcStringList hander, size_t *size);
103
104 /**
105  * Free data.
106  *
107  * @param[in] string Data allocated by certsvc_certificate_get_string_field
108  */
109 void certsvc_string_free(CertSvcString string);
110
111 /**
112  * Free string list.
113  *
114  * Note: This function does not free strings returned by certsvc_string_list_get_one_result.
115  *
116  * @param[in] handler String set handler.
117  */
118 void certsvc_string_list_free(CertSvcStringList handler);
119
120 /**
121  * Convert CertSvcStringPtr into pure c pointer. Please note that this pointer is valid as long as CertSvcString is valid.
122  *
123  * @param[in] string CertSvcStringPtr.
124  * @param[out] buffer cstring
125  * @param[out] len Length of cstring
126  */
127 void certsvc_string_to_cstring(CertSvcString string, const char **buffer, size_t *len);
128
129 #ifdef __cplusplus
130 }
131 #endif
132
133 #endif
134