merge with master
[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_storage_type(da_storage_type_t *type)
54 {
55   da_result_t ret = DA_RESULT_OK;
56 #ifdef _EFL_PLATFORM
57   int value = -1;
58 #endif
59
60   if (!type)  {
61     DA_LOG_ERR(Default,"DA_ERR_CONF_FAIL");
62         ret = DA_ERR_INVALID_ARGUMENT;
63         goto ERR;
64   }
65
66 #ifdef _EFL_PLATFORM
67         if (0 != vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_MEM_WAP_INT, &value)) {
68                 DA_LOG_ERR(Default,"DA_ERR_CONF_FAIL");
69                 ret = DA_ERR_FAIL_TO_GET_CONF_VALUE;
70                 goto ERR;
71         }
72
73         switch (value) {
74         case SETTING_DEF_MEMORY_PHONE:
75                 DA_LOG(Default,"Storage set - DA_STORAGE_PHONE");
76                 *type = DA_STORAGE_PHONE;
77                 break;
78         case SETTING_DEF_MEMORY_MMC:
79                 *type = DA_STORAGE_MMC;
80                 DA_LOG(Default,"Storage set - DA_STORAGE_MMC");
81                 break;
82         case SETTING_DEF_MEMORY_MAX:
83                 *type = DA_STORAGE_SYSTEM;
84                 DA_LOG(Default,"Storage set - DA_STORAGE_SYSTEM");
85                 break;
86         default:
87                 DA_LOG_ERR(Default,"DA_ERR_CONF_FAIL");
88                 ret = DA_ERR_FAIL_TO_GET_CONF_VALUE;
89                 break;
90         }
91 #endif
92
93 ERR:
94    return ret;
95
96 }
97
98 da_result_t get_user_agent_string(char **uagent_str)
99 {
100         da_result_t  ret = DA_RESULT_OK;
101 #ifdef _EFL_PLATFORM
102         char *key = DA_NULL;
103 #endif
104
105         DA_LOG_FUNC_START(Default);
106
107         if (!uagent_str) {
108                 DA_LOG_ERR(Default,"Invalid Argument");
109                 return DA_ERR_INVALID_ARGUMENT;
110         }
111
112 #ifdef _EFL_PLATFORM
113         key = VCONFKEY_BROWSER_USER_AGENT;
114         ret = __get_conf_string(key, uagent_str);
115         if(ret == DA_RESULT_OK) {
116                 if(*uagent_str) {
117                         DA_LOG(Default,"getting uagent_str = \n%s", *uagent_str);
118                         return ret;
119                 }
120         }
121         DA_LOG_ERR(Default,"No UA information from vconf !!");
122         *uagent_str = strdup(DEFAULT_UA_STR);
123         DA_LOG(Default,"Set default UA");
124 #else
125         *uagent_str = strdup(DEFAULT_UA_STR);
126 #endif
127         return ret;
128 }
129
130 char *get_proxy_address(void)
131 {
132 #ifdef _EFL_PLATFORM
133         char *proxy = NULL;
134         char *proxyRet = NULL;
135         connection_h handle = NULL;
136     connection_address_family_e family = CONNECTION_ADDRESS_FAMILY_IPV4;
137
138     DA_LOG_FUNC_START(Default);
139     if (connection_create(&handle) < 0) {
140                 DA_LOG_ERR(Default,"Fail to create connection handle");
141                 return NULL;
142         }
143
144         if (connection_get_proxy(handle, family, &proxyRet) < 0) {
145                 DA_LOG_ERR(Default,"Fail to get proxy address");
146                 connection_destroy(handle);
147                 return NULL;
148         }
149
150         if (proxyRet) {
151                 DA_LOG(Default,"===== Proxy address[%s] =====", proxyRet);
152                 proxy = strdup(proxyRet);
153                 free(proxyRet);
154                 proxyRet = NULL;
155                 connection_destroy(handle);
156                 return proxy;
157         }
158
159     if (connection_destroy(handle) < 0) {
160                 DA_LOG_ERR(Default,"Fail to desctory connection handle");
161                 return NULL;
162         }
163         return NULL;
164 #else
165         return NULL;
166 #endif
167 }