Revert manifest to default one
[profile/ivi/download-provider.git] / src / agent / download-agent-plugin-conf.c
1 /*
2  * Download Agent
3  *
4  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jungki Kwak <jungki.kwak@samsung.com>, Keunsoon Lee <keunsoon.lee@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  * @file                download-agent-plugin-conf.c
21  * @brief               Platform dependent functions for get configuration data from target
22  * @author              Keunsoon Lee(keunsoon.lee@samsung.com)
23  * @author              Jungki Kwak(jungki.kwak@samsung.com)
24  ***/
25
26 #include <string.h>
27 #include <stdlib.h>
28 #include <glib-object.h>
29
30 #ifdef _EFL_PLATFORM
31 #include <vconf.h>
32 #include <vconf-keys.h>
33 #include <net_connection.h>
34 #endif /* _EFL_PLATFORM */
35
36 #include "download-agent-plugin-conf.h"
37 #include "download-agent-debug.h"
38 #include "download-agent-file.h"
39
40 #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"
41
42 da_result_t __get_conf_string(const char *key, char **out_string);
43
44 da_result_t __get_conf_string(const char *key, char **out_string)
45 {
46 #ifdef _EFL_PLATFORM
47         if (!key || !out_string) {
48                 DA_LOG_ERR(Default,"Invalid Argument");
49                 return DA_ERR_INVALID_ARGUMENT;
50         }
51
52         *out_string = vconf_get_str(key);
53         return DA_RESULT_OK;
54 #else
55         if (out_string)
56                 *out_string = NULL;
57
58         return DA_RESULT_OK;
59 #endif
60 }
61
62 da_result_t get_storage_type(da_storage_type_t *type)
63 {
64   da_result_t ret = DA_RESULT_OK;
65 #ifdef _EFL_PLATFORM
66   int value = -1;
67 #endif
68
69   if (!type)  {
70     DA_LOG_ERR(Default,"DA_ERR_CONF_FAIL");
71         ret = DA_ERR_INVALID_ARGUMENT;
72         goto ERR;
73   }
74
75 #ifdef _EFL_PLATFORM
76         if (0 != vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_MEM_WAP_INT, &value)) {
77                 DA_LOG_ERR(Default,"DA_ERR_CONF_FAIL");
78                 ret = DA_ERR_FAIL_TO_GET_CONF_VALUE;
79                 goto ERR;
80         }
81
82         switch (value) {
83         case SETTING_DEF_MEMORY_PHONE:
84                 DA_LOG(Default,"Storage set - DA_STORAGE_PHONE");
85                 *type = DA_STORAGE_PHONE;
86                 break;
87         case SETTING_DEF_MEMORY_MMC:
88                 *type = DA_STORAGE_MMC;
89                 DA_LOG(Default,"Storage set - DA_STORAGE_MMC");
90                 break;
91         case SETTING_DEF_MEMORY_MAX:
92                 *type = DA_STORAGE_SYSTEM;
93                 DA_LOG(Default,"Storage set - DA_STORAGE_SYSTEM");
94                 break;
95         default:
96                 DA_LOG_ERR(Default,"DA_ERR_CONF_FAIL");
97                 ret = DA_ERR_FAIL_TO_GET_CONF_VALUE;
98                 break;
99         }
100 #endif
101
102 ERR:
103    return ret;
104
105 }
106
107 da_result_t get_user_agent_string(char **uagent_str)
108 {
109         da_result_t  ret = DA_RESULT_OK;
110 #ifdef _EFL_PLATFORM
111         char *key = DA_NULL;
112 #endif
113
114         DA_LOG_FUNC_START(Default);
115
116         if (!uagent_str) {
117                 DA_LOG_ERR(Default,"Invalid Argument");
118                 return DA_ERR_INVALID_ARGUMENT;
119         }
120
121 #ifdef _EFL_PLATFORM
122         key = VCONFKEY_ADMIN_UAGENT;
123         ret = __get_conf_string(key, uagent_str);
124         if(ret == DA_RESULT_OK) {
125                 if(*uagent_str) {
126                         DA_LOG(Default,"getting uagent_str = \n%s", *uagent_str);
127                         return ret;
128                 }
129         }
130         DA_LOG_ERR(Default,"No UA information from vconf !!");
131         *uagent_str = strdup(DEFAULT_UA_STR);
132         DA_LOG(Default,"Set default UA");
133 #else
134         *uagent_str = strdup(DEFAULT_UA_STR);
135 #endif
136         return ret;
137 }
138
139 char *get_proxy_address(void)
140 {
141 #ifdef _EFL_PLATFORM
142         char *proxy = NULL;
143         char *proxyRet = NULL;
144         connection_h handle = NULL;
145     connection_address_family_e family = CONNECTION_ADDRESS_FAMILY_IPV4;
146
147     DA_LOG_FUNC_START(Default);
148     if (connection_create(&handle) < 0) {
149                 DA_LOG_ERR(Default,"Fail to create connection handle");
150                 return NULL;
151         }
152
153         if (connection_get_proxy(handle, family, &proxyRet) < 0) {
154                 DA_LOG_ERR(Default,"Fail to get proxy address");
155                 connection_destroy(handle);
156                 return NULL;
157         }
158
159         if (proxyRet) {
160                 DA_LOG(Default,"===== Proxy address[%s] =====", proxyRet);
161                 proxy = strdup(proxyRet);
162                 free(proxyRet);
163                 proxyRet = NULL;
164                 connection_destroy(handle);
165                 return proxy;
166         }
167
168     if (connection_destroy(handle) < 0) {
169                 DA_LOG_ERR(Default,"Fail to desctory connection handle");
170                 return NULL;
171         }
172         return NULL;
173 #else
174         return NULL;
175 #endif
176 }