Updated source code for download-provider from tizen 2.2.1 git branch
[platform/framework/web/download-provider.git] / agent / download-agent-plugin-conf.c
1 /*
2  * Copyright (c) 2012 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 #include <string.h>
18 #include <stdlib.h>
19 #include <glib-object.h>
20
21 #ifdef _EFL_PLATFORM
22 #include <vconf.h>
23 #include <vconf-keys.h>
24 #include <net_connection.h>
25 #endif /* _EFL_PLATFORM */
26
27 #include "download-agent-plugin-conf.h"
28 #include "download-agent-debug.h"
29 #include "download-agent-file.h"
30
31 #define DEFAULT_UA_STR "Mozilla/5.0 (Linux; U; Tizen 1.0; en-us) AppleWebKit/534.46 (KHTML, like Gecko) Mobile Tizen Browser/1.0"
32
33 da_result_t __get_conf_string(const char *key, char **out_string);
34
35 da_result_t __get_conf_string(const char *key, char **out_string)
36 {
37 #ifdef _EFL_PLATFORM
38         if (!key || !out_string) {
39                 DA_LOG_ERR(Default,"Invalid Argument");
40                 return DA_ERR_INVALID_ARGUMENT;
41         }
42
43         *out_string = vconf_get_str(key);
44         return DA_RESULT_OK;
45 #else
46         if (out_string)
47                 *out_string = NULL;
48
49         return DA_RESULT_OK;
50 #endif
51 }
52
53 da_result_t get_user_agent_string(char **uagent_str)
54 {
55         da_result_t  ret = DA_RESULT_OK;
56 #ifdef _EFL_PLATFORM
57         char *key = DA_NULL;
58 #endif
59
60         DA_LOG_FUNC_LOGV(Default);
61
62         if (!uagent_str) {
63                 DA_LOG_ERR(Default,"Invalid Argument");
64                 return DA_ERR_INVALID_ARGUMENT;
65         }
66
67 #ifdef _EFL_PLATFORM
68         key = VCONFKEY_BROWSER_USER_AGENT;
69         ret = __get_conf_string(key, uagent_str);
70         if(ret == DA_RESULT_OK) {
71                 if(*uagent_str) {
72                         DA_SECURE_LOGD("getting uagent_str = \n%s", *uagent_str);
73                         return ret;
74                 }
75         }
76         DA_LOG_ERR(Default,"No UA information from vconf !!");
77         *uagent_str = strdup(DEFAULT_UA_STR);
78         DA_LOG(Default,"Set default UA");
79 #else
80         *uagent_str = strdup(DEFAULT_UA_STR);
81 #endif
82         return ret;
83 }
84
85 char *get_proxy_address(void)
86 {
87 #ifdef _EFL_PLATFORM
88         char *proxy = NULL;
89         char *proxyRet = NULL;
90         connection_h handle = NULL;
91     connection_address_family_e family = CONNECTION_ADDRESS_FAMILY_IPV4;
92
93     DA_LOG_FUNC_LOGV(Default);
94     if (connection_create(&handle) < 0) {
95                 DA_LOG_ERR(Default,"Fail to create connection handle");
96                 return NULL;
97         }
98
99         if (connection_get_proxy(handle, family, &proxyRet) < 0) {
100                 DA_LOG_ERR(Default,"Fail to get proxy address");
101                 connection_destroy(handle);
102                 return NULL;
103         }
104
105         if (proxyRet) {
106                 DA_SECURE_LOGD("===== Proxy address[%s] =====", proxyRet);
107                 proxy = strdup(proxyRet);
108                 free(proxyRet);
109                 proxyRet = NULL;
110                 connection_destroy(handle);
111                 return proxy;
112         }
113
114     if (connection_destroy(handle) < 0) {
115                 DA_LOG_ERR(Default,"Fail to desctory connection handle");
116                 return NULL;
117         }
118         return NULL;
119 #else
120         return NULL;
121 #endif
122 }