Fix dlclose issue when calling DLP feature
[platform/upstream/curl.git] / extensions / tizen_dlp.c
1 /**
2  * @file        tizen_dlp.cpp
3  * @brief       external API functions for DLP
4  */
5
6 #include <dlfcn.h>
7
8 #define LIBRARY_PATH "/lib/libprivacy-guard-client.so"
9
10 static int first_run = 1;
11 static void (*privacy_guard_dlp_init)(void) = 0;
12 static void (*privacy_guard_dlp_check_leak)(const char *, char * const, size_t) = 0;
13
14 /**
15  * @fn void tizen_dlp_init(void)
16  * @brief Initialize the DLP creating the Load Rules and Logging threads
17  * @callgraph
18  */
19 void tizen_dlp_init(void)
20 {
21     if (first_run) {
22         void *handle = dlopen(LIBRARY_PATH, RTLD_LAZY|RTLD_NODELETE);
23         if (handle) {
24             privacy_guard_dlp_init = dlsym(handle, "privacy_guard_dlp_init");
25             privacy_guard_dlp_check_leak = dlsym(handle, "privacy_guard_dlp_check_leak");
26             dlclose(handle);
27             first_run = 0;
28         }
29     }
30
31     if (privacy_guard_dlp_init)
32         privacy_guard_dlp_init();
33 }
34
35 /**
36  * @fn void tizen_dlp_check_leak(const char *hostname, char * const mem, size_t len)
37  * @brief Checks for information leak on a given request string
38  *
39  * @param[in] hostname                                  The hostname of the server to which the request will be sent
40  * @param[in] mem                                               Text that we are going to validate for info leak
41  * @param[in] len                                               Size of len in bytes
42  *
43  * @return  either PRIV_GUARD_DLP_RESULT_ALLOW or PRIV_GUARD_DLP_RESULT_DENY
44  * @callgraph
45  */
46 void tizen_dlp_check_leak(const char *hostname, char * const mem, size_t len)
47 {
48     /**
49     * Send data to Tizen DLP verification
50     */
51     if(privacy_guard_dlp_check_leak)
52         privacy_guard_dlp_check_leak(hostname, mem, len);
53 }