3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * @brief This file is the source file of implementation of header binder function for Network Adapter
24 #include <sync_agent.h>
26 #include "service-adapter/network-binder/na_binder.h"
28 #ifndef OMADS_AGENT_LOG
30 #define LOG_TAG "OMA_DS_SA"
33 int na_http_header_binder(char *acc_type, char *loc_uri, bool is_xml, char *jsession_id, GList ** list)
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");
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 !!");
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);
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 !!");
52 memset(uri, 0x00, sizeof(sync_agent_na_common_header_info_s));
55 *list = g_list_append(*list, uri);
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 !!");
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);
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 !!");
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);
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 !!");
76 memset(accept, 0x00, sizeof(sync_agent_na_common_header_info_s));
77 accept->key = "Accept";
79 accept->value = "application/vnd.syncml+xml";
81 accept->value = "application/vnd.syncml+wbxml";
82 *list = g_list_append(*list, accept);
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 !!");
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);
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 !!");
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);
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 !!");
103 memset(content_type, 0x00, sizeof(sync_agent_na_common_header_info_s));
104 content_type->key = "Content-Type";
106 content_type->value = "application/vnd.syncml+xml";
108 content_type->value = "application/vnd.syncml+wbxml";
109 *list = g_list_append(*list, content_type);
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 !!");
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);
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);
133 void free_header_info(sync_agent_na_common_header_info_s * common_header_info)
137 retm_if(common_header_info == NULL, "pCommon_header_info is NULL");
139 free(common_header_info);