4d3c5c501c864f1d3dd0b4507b25020f0df770b2
[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 #include "vconf.h"
21 #include "vconf-keys.h"
22 #include "net_connection.h"
23
24 #include "download-agent-plugin-conf.h"
25 #include "download-agent-debug.h"
26 #include "download-agent-file.h"
27
28 #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"
29
30 da_ret_t __get_conf_string(const char *key, char **out_string)
31 {
32         if (!key || !out_string) {
33                 DA_LOGE("Invalid Argument");
34                 return DA_ERR_INVALID_ARGUMENT;
35         }
36
37         *out_string = vconf_get_str(key);
38         return DA_RESULT_OK;
39 }
40
41 da_ret_t get_user_agent_string(char **uagent_str)
42 {
43         da_ret_t  ret = DA_RESULT_OK;
44
45         DA_LOGV("");
46
47         if (!uagent_str) {
48                 DA_LOGE("Invalid Argument");
49                 return DA_ERR_INVALID_ARGUMENT;
50         }
51
52         DA_LOGI("No UA information from vconf !!");
53         *uagent_str = strdup(DEFAULT_UA_STR);
54         DA_LOGV("Set default UA");
55         return ret;
56 }
57
58 char *get_proxy_address(void)
59 {
60         char *proxy = NULL;
61         char *proxyRet = NULL;
62         connection_h handle = NULL;
63         connection_address_family_e family = CONNECTION_ADDRESS_FAMILY_IPV4;
64
65         DA_LOGV("");
66         if (connection_create(&handle) < 0) {
67                 DA_LOGE("Fail to create connection handle");
68                 return NULL;
69         }
70
71         if (connection_get_proxy(handle, family, &proxyRet) < 0) {
72                 DA_LOGE("Fail to get proxy address");
73                 connection_destroy(handle);
74                 return NULL;
75         }
76
77         if (proxyRet) {
78                 DA_SECURE_LOGD("===== Proxy address[%s] =====", proxyRet);
79                 proxy = strdup(proxyRet);
80                 free(proxyRet);
81                 proxyRet = NULL;
82                 connection_destroy(handle);
83                 return proxy;
84         }
85
86         if (connection_destroy(handle) < 0) {
87                 DA_LOGE("Fail to desctory connection handle");
88                 return NULL;
89         }
90         return NULL;
91 }
92 #ifdef _RAF_SUPPORT
93 // test code
94 void get_smart_bonding_vconf()
95 {
96         int ret = 0;
97         vconf_get_int("file/private/wifi/network_bonding", &ret);
98         DA_LOGI("Smart Bonding Vconf:%d", ret);
99 }
100 #endif