Remove C++ template declarance from C linkage
[platform/core/security/drm-service-core-tizen.git] / tappsd / inc / drm_intf_tapps.h
1 /*
2  * Copyright (c) 2000-2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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 /**
18  * @file        drm_intf_tapps.h
19  * @brief       This file includes declarations of the drm TAPPS intf APIs.
20  */
21
22 #ifndef __DRM_INTF_TAPPS_H__
23 #define __DRM_INTF_TAPPS_H__
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 #include <sys/syscall.h>
32 #include <linux/unistd.h>
33 #include <unistd.h>
34 #include <time.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <memory.h>
38 #include <stdarg.h>
39 #include <assert.h>
40 #include <ctype.h>
41 #include <stdint.h>
42 #include <dirent.h>
43 #include <pthread.h>
44 #include <semaphore.h>
45 #include <glib.h>
46 #include <signal.h>
47 #include <string.h>
48 #include <errno.h>
49
50 #include "db-util.h"
51
52 #include "drm-tizen-mid.h"
53 #include <openssl/aes.h>
54
55 /* Enable this flag during development time */
56 #define _TAPPS_DEBUG_ENABLE_
57
58 /* IMEI and other VCONF Paths */
59
60 #define DTAPPS_DUID_SIZE 32
61
62 #if  0
63 #define DTAPPS_IMEI_PATH VCONFKEY_TELEPHONY_IMEI
64 #endif
65
66 /*************************************************************************************************************/
67 typedef bool BOOL;
68
69 /* Constants */
70 #ifndef TRUE
71 #define TRUE 1
72 #endif
73
74 #ifndef FALSE
75 #define FALSE 0
76 #endif
77
78 #ifndef NULL
79 #define NULL 0
80 #endif
81
82 /*************************************************************************************************************/
83 /* DB Details */
84
85 /* drm db schema name */
86 #define DTAPPS_DB_NAME DB_PATH
87
88 typedef enum {
89    TAPPSDB_TYPE_NONE,
90    TAPPSDB_TYPE_INT,
91    TAPPSDB_TYPE_DATETIME,
92    TAPPSDB_TYPE_CHAR,
93    TAPPSDB_TYPE_VARCHAR,
94    TAPPSDB_TYPE_BINARY,
95    TAPPSDB_TYPE_BLOB,
96    TAPPSDB_TYPE_UNKNOWN = 0xFFFFFFFF
97 } TAPPSDbType;
98
99 /* Enable this Flag if CEK is to be stored in DB */
100 #define DTAPPS_STORE_CEK_IN_DB
101
102 /*************************************************************************************************************/
103
104 /* Logs and Macros */
105
106 #define MID_DRM 200
107 #define MID_EXCEPTION 100
108
109 #define MCATCH_B _M_catch:
110
111 #define MTHROW_B   \
112 {                  \
113         goto _M_catch; \
114 }
115
116 #define MTHROW_BL            \
117 {                            \
118         M_LOGLINE("Throw error") \
119         goto _M_catch;           \
120 }
121
122
123 #define MCFG_DISPLAY_ERROR_LINE
124
125 #define DRM_LINUX_SYSDEBUG(dbg_lvl, FMT, ARG...) \
126 {                                                \
127         if ((dbg_lvl) == MID_EXCEPTION)              \
128                 DRM_TAPPS_EXCEPTION(FMT, ##ARG);         \
129         else if((dbg_lvl) == MID_DRM)                \
130                 DRM_TAPPS_LOG(FMT, ##ARG);               \
131         else                                         \
132                 DRM_TAPPS_FRQ_LOG(FMT, ##ARG);           \
133 }
134
135 #ifdef MCFG_DISPLAY_ERROR_LINE
136 #define M_LOGLINE(log_prefix) DRM_LINUX_SYSDEBUG(MID_EXCEPTION, "(%s)[Statement] "#log_prefix"", __func__)
137 #else
138 #define M_LOGLINE(log_prefix)
139 #endif // MCFG_DISPLAY_ERROR_LINE
140
141 #define MTRY_BL(f)                     \
142 {                                      \
143         if ((f) == 0) {                    \
144                 M_LOGLINE("Try catched("#f")") \
145                 goto _M_catch;                 \
146         }                                  \
147 }
148
149 /*************************************************************************************************************/
150 /* Mutex structure */
151 typedef pthread_mutex_t dtapps_mutex_t;
152
153 #define dtappslockarg  dtapps_mutex_t*
154
155 int dtapps_mutex_lock (dtappslockarg dtapps_mutex);
156 int dtapps_mutex_unlock (dtappslockarg dtapps_mutex);
157
158 /*************************************************************************************************************/
159 /* Memory Operations Wrapper APIs */
160
161 #define DTAPPS_MEMSET memset
162 #define DTAPPS_MEMCPY memcpy
163 #define DTAPPS_MALLOC malloc
164 #define DTAPPS_MEMCPY memcpy
165 #define DTAPPS_MEMCMP memcmp
166 #define DTAPPS_FREE free
167
168 /*************************************************************************************************************/
169
170 /* Time Wrapper APIs */
171
172 #define DTAPPS_TIME time
173 #define DTAPPS_MKTIME mktime
174 #define DTAPPS_GMTIME gmtime
175 #define DTAPPS_GMTIME_THREAD_SAFE gmtime_r
176 #define DTAPPS_ASCTIME asctime
177
178 /* String Operations Wrapper APIs */
179 #ifdef _TAPPS_DEBUG_ENABLE_
180 unsigned int TAPPS_gstrlcat(char* s1,const char* s2,unsigned int destsize,const char* funName, unsigned int lineno);
181 unsigned int TAPPS_gstrlcpy(char* s1,const char* s2,unsigned int destsize,const char* funName, unsigned int lineno);
182 unsigned int TAPPS_strlen(const char* s,const char* funName, unsigned int lineno);
183
184 #define TAPPS_GSTRLCPY(dest,src,LenDest) TAPPS_gstrlcpy(dest,src,LenDest,__func__,__LINE__)
185 #define TAPPS_GSTRLCAT(dest,src,LenDest) TAPPS_gstrlcat(dest,src,LenDest,__func__,__LINE__)
186 #define TAPPS_STRLEN(string) TAPPS_strlen(string,__func__,__LINE__)
187 #else
188 #define TAPPS_GSTRLCPY(dest,src,LenDest) g_strlcpy(dest, src, LenDest)
189 #define TAPPS_GSTRLCAT(dest,src,LenDest) g_strlcat(dest, src, LenDest)
190 #define TAPPS_STRLEN(string) strlen(string)
191 #endif
192
193 #define DTAPPS_SNPRINTF snprintf
194 #define DTAPPS_ATOI atoi
195 #define DTAPPS_STRNCMP strncmp
196
197 int TAPPS_strnicmp(const char * s1, const char * s2, unsigned int sz);
198 /*************************************************************************************************************/
199 /* SLEEP API */
200
201 void dtapps_sleep(unsigned int TimeInSec,unsigned int TimeInMicroSec);
202
203 /*************************************************************************************************************/
204
205 /*************************************************************************************************************/
206 /* OPENSSL APIs */
207 #define DTAPPS_AES_SET_ENCR_KEY AES_set_encrypt_key
208 #define DTAPPS_AES_SET_DECR_KEY AES_set_decrypt_key
209 #define DTAPPS_AES_WRAP_KEY AES_wrap_key
210 #define DTAPPS_AES_UNWRAP_KEY AES_unwrap_key
211
212 /*************************************************************************************************************/
213 #ifdef __cplusplus
214 }
215 #endif
216
217 #endif /* __DRM_INTF_TAPPS_H__ */