Tizen 2.0 Release
[pkgs/o/oma-ds-service.git] / src / agent / service-adapter / network-binder / na_binder.c
1 /*
2  * oma-ds-agent
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 /**
19  *   @NA_Binder.c
20  *   @version                                                                   0.1
21  *   @brief                                                                             This file is the source file of implementation of header binder function for Network Adapter
22  */
23
24 #include <sync_agent.h>
25
26 #include "service-adapter/network-binder/na_binder.h"
27
28 #ifndef OMADS_AGENT_LOG
29 #undef LOG_TAG
30 #define LOG_TAG "OMA_DS_SA"
31 #endif
32
33 int na_http_header_binder(char *acc_type, char *loc_uri, bool is_xml, char *jsession_id, GList ** list)
34 {
35         _EXTERN_FUNC_ENTER;
36
37         retvm_if(acc_type == NULL, 0, "[NA Header Binder] accType is NULL");
38         retvm_if(loc_uri == NULL, 0, "[NA Header Binder] loc_uri is NULL");
39
40         if (!strcmp(acc_type, "OMA_DS")) {
41                 sync_agent_na_common_header_info_s *method = (sync_agent_na_common_header_info_s *) malloc(sizeof(sync_agent_na_common_header_info_s));
42                 retvm_if(method == NULL, 0, "[NA Header Binder] 'method' malloc fail !!");
43
44                 memset(method, 0x00, sizeof(sync_agent_na_common_header_info_s));
45                 method->key = "method";
46                 method->value = "post";
47                 *list = g_list_append(*list, method);
48
49                 sync_agent_na_common_header_info_s *uri = (sync_agent_na_common_header_info_s *) malloc(sizeof(sync_agent_na_common_header_info_s));
50                 retvm_if(uri == NULL, 0, "[NA Header Binder] 'uri' malloc fail !!");
51
52                 memset(uri, 0x00, sizeof(sync_agent_na_common_header_info_s));
53                 uri->key = "uri";
54                 uri->value = loc_uri;
55                 *list = g_list_append(*list, uri);
56
57                 sync_agent_na_common_header_info_s *cache_control = (sync_agent_na_common_header_info_s *) malloc(sizeof(sync_agent_na_common_header_info_s));
58                 retvm_if(cache_control == NULL, 0, "[NA Header Binder] 'cache_control' malloc fail !!");
59
60                 memset(cache_control, 0x00, sizeof(sync_agent_na_common_header_info_s));
61                 cache_control->key = "Cache-Control";
62                 cache_control->value = "no-store, private";
63                 *list = g_list_append(*list, cache_control);
64
65                 sync_agent_na_common_header_info_s *connection = (sync_agent_na_common_header_info_s *) malloc(sizeof(sync_agent_na_common_header_info_s));
66                 retvm_if(connection == NULL, 0, "[NA Header Binder] 'connection' malloc fail !!");
67
68                 memset(connection, 0x00, sizeof(sync_agent_na_common_header_info_s));
69                 connection->key = "Connection";
70                 connection->value = "Keep-Alive";
71                 *list = g_list_append(*list, connection);
72
73                 sync_agent_na_common_header_info_s *accept = (sync_agent_na_common_header_info_s *) malloc(sizeof(sync_agent_na_common_header_info_s));
74                 retvm_if(accept == NULL, 0, "[NA Header Binder] 'accept' malloc fail !!");
75
76                 memset(accept, 0x00, sizeof(sync_agent_na_common_header_info_s));
77                 accept->key = "Accept";
78                 if (is_xml == true)
79                         accept->value = "application/vnd.syncml+xml";
80                 else
81                         accept->value = "application/vnd.syncml+wbxml";
82                 *list = g_list_append(*list, accept);
83
84                 sync_agent_na_common_header_info_s *accept_language = (sync_agent_na_common_header_info_s *) malloc(sizeof(sync_agent_na_common_header_info_s));
85                 retvm_if(accept_language == NULL, 0, "[NA Header Binder] 'accept_language' malloc fail !!");
86
87                 memset(accept_language, 0x00, sizeof(sync_agent_na_common_header_info_s));
88                 accept_language->key = "Accept-Language";
89                 accept_language->value = "en-US";
90                 *list = g_list_append(*list, accept_language);
91
92                 sync_agent_na_common_header_info_s *accept_charset = (sync_agent_na_common_header_info_s *) malloc(sizeof(sync_agent_na_common_header_info_s));
93                 retvm_if(accept_charset == NULL, 0, "[NA Header Binder] 'accept_charset' malloc fail !!");
94
95                 memset(accept_charset, 0x00, sizeof(sync_agent_na_common_header_info_s));
96                 accept_charset->key = "Accept-Charset";
97                 accept_charset->value = "UTF-8";
98                 *list = g_list_append(*list, accept_charset);
99
100                 sync_agent_na_common_header_info_s *content_type = (sync_agent_na_common_header_info_s *) malloc(sizeof(sync_agent_na_common_header_info_s));
101                 retvm_if(content_type == NULL, 0, "[NA Header Binder] 'content_type' malloc fail !!");
102
103                 memset(content_type, 0x00, sizeof(sync_agent_na_common_header_info_s));
104                 content_type->key = "Content-Type";
105                 if (is_xml == true)
106                         content_type->value = "application/vnd.syncml+xml";
107                 else
108                         content_type->value = "application/vnd.syncml+wbxml";
109                 *list = g_list_append(*list, content_type);
110
111                 if (jsession_id != NULL) {
112                         _DEBUG_INFO(" jsessionid : %s\n", jsession_id);
113                         sync_agent_na_common_header_info_s *cookie = (sync_agent_na_common_header_info_s *) malloc(sizeof(sync_agent_na_common_header_info_s));
114                         retvm_if(cookie == NULL, 0, "[NA Header Binder] 'cookie' malloc fail !!");
115
116                         memset(cookie, 0x00, sizeof(sync_agent_na_common_header_info_s));
117                         cookie->key = "cookie";
118                         cookie->value = jsession_id;
119                         *list = g_list_append(*list, cookie);
120                         _DEBUG_INFO(" cookie :  %s\n", cookie->value);
121                 }
122         }
123
124         GList *iter = NULL;
125         for (iter = *list; iter != NULL; iter = g_list_next(iter)) {
126                 _DEBUG_INFO("[NA_Header_Binder] key : %s, value : %s", ((sync_agent_na_common_header_info_s *) (iter->data))->key, ((sync_agent_na_common_header_info_s *) (iter->data))->value);
127         }
128
129         _EXTERN_FUNC_EXIT;
130         return 1;
131 }
132
133 void free_header_info(sync_agent_na_common_header_info_s * common_header_info)
134 {
135         _EXTERN_FUNC_ENTER;
136
137         retm_if(common_header_info == NULL, "pCommon_header_info is NULL");
138
139         free(common_header_info);
140
141         _EXTERN_FUNC_EXIT;
142 }