Integration w/ DLP feature from privacy-guard
[platform/upstream/curl.git] / lib / extensions / curl_extensions.c
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 2014 - 2016, Steve Holme, <steve_holme@hotmail.com>.
9  *
10  * This software is licensed as described in the file COPYING, which
11  * you should have received as part of this distribution. The terms
12  * are also available at https://curl.haxx.se/docs/copyright.html.
13  *
14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15  * copies of the Software, and permit persons to whom the Software is
16  * furnished to do so, under the terms of the COPYING file.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  ***************************************************************************/
22
23 /**
24  * @file    curl_extensions.cpp
25  * @brief   external API functions for DLP
26  */
27
28 #ifdef USE_TIZEN_FEATURE_DLP
29 #include <dlfcn.h>
30 #include <extensions/curl_extensions.h>
31
32 #define LIBRARY_PATH "/usr/lib/libcurl_extension_dlp.so.0"
33
34 static int first_run = 1;
35 static void (*tizen_dlp_init)(void) = NULL;
36 static void (*tizen_dlp_check_leak)(const char *, char * const, size_t) = NULL;
37
38 /**
39  * @fn void curl_extensions_init(void)
40  * @brief Load the extension shared library looking for the function call
41  * symbols it going to use
42  * @callgraph
43  */
44 static void curl_extensions_init(void)
45 {
46     if (first_run) {
47         void *handle = dlopen(LIBRARY_PATH, RTLD_LAZY);
48         if (handle) {
49             tizen_dlp_init = dlsym(handle, "tizen_dlp_init");
50             tizen_dlp_check_leak = dlsym(handle, "tizen_dlp_check_leak");
51         }
52         first_run = 0;
53     }
54 }
55
56 /**
57  *   @callgraph
58  */
59 void curl_extensions_tizen_dlp_init(void)
60 {
61     curl_extensions_init();
62
63     if (tizen_dlp_init)
64         tizen_dlp_init();
65 }
66
67 /**
68  *   @callgraph
69  */
70 void curl_extensions_tizen_dlp_check_leak(const char *hostname, char * const mem, size_t len)
71 {
72     if(tizen_dlp_check_leak)
73         tizen_dlp_check_leak(hostname, mem, len);
74 }
75 #endif /* USE_TIZEN_FEATURE_DLP */