summaryrefslogtreecommitdiff
path: root/src/agent/service-adapter/network-binder/na_binder.c
blob: 4c9ff49c2a6c66b2ae397461ab101465aab87aa0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
 * oma-ds-agent
 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 *   @NA_Binder.c
 *   @version									0.1
 *   @brief										This file is the source file of implementation of header binder function for Network Adapter
 */

#include <sync_agent.h>

#include "service-adapter/network-binder/na_binder.h"

#ifndef OMADS_AGENT_LOG
#undef LOG_TAG
#define LOG_TAG "OMA_DS_SA"
#endif

int na_http_header_binder(char *acc_type, char *loc_uri, bool is_xml, char *jsession_id, GList ** list)
{
	_EXTERN_FUNC_ENTER;

	retvm_if(acc_type == NULL, 0, "[NA Header Binder] accType is NULL");
	retvm_if(loc_uri == NULL, 0, "[NA Header Binder] loc_uri is NULL");

	if (!strcmp(acc_type, "OMA_DS")) {
		sync_agent_na_common_header_info_s *method = (sync_agent_na_common_header_info_s *) malloc(sizeof(sync_agent_na_common_header_info_s));
		retvm_if(method == NULL, 0, "[NA Header Binder] 'method' malloc fail !!");

		memset(method, 0x00, sizeof(sync_agent_na_common_header_info_s));
		method->key = "method";
		method->value = "post";
		*list = g_list_append(*list, method);

		sync_agent_na_common_header_info_s *uri = (sync_agent_na_common_header_info_s *) malloc(sizeof(sync_agent_na_common_header_info_s));
		retvm_if(uri == NULL, 0, "[NA Header Binder] 'uri' malloc fail !!");

		memset(uri, 0x00, sizeof(sync_agent_na_common_header_info_s));
		uri->key = "uri";
		uri->value = loc_uri;
		*list = g_list_append(*list, uri);

		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));
		retvm_if(cache_control == NULL, 0, "[NA Header Binder] 'cache_control' malloc fail !!");

		memset(cache_control, 0x00, sizeof(sync_agent_na_common_header_info_s));
		cache_control->key = "Cache-Control";
		cache_control->value = "no-store, private";
		*list = g_list_append(*list, cache_control);

		sync_agent_na_common_header_info_s *connection = (sync_agent_na_common_header_info_s *) malloc(sizeof(sync_agent_na_common_header_info_s));
		retvm_if(connection == NULL, 0, "[NA Header Binder] 'connection' malloc fail !!");

		memset(connection, 0x00, sizeof(sync_agent_na_common_header_info_s));
		connection->key = "Connection";
		connection->value = "Keep-Alive";
		*list = g_list_append(*list, connection);

		sync_agent_na_common_header_info_s *accept = (sync_agent_na_common_header_info_s *) malloc(sizeof(sync_agent_na_common_header_info_s));
		retvm_if(accept == NULL, 0, "[NA Header Binder] 'accept' malloc fail !!");

		memset(accept, 0x00, sizeof(sync_agent_na_common_header_info_s));
		accept->key = "Accept";
		if (is_xml == true)
			accept->value = "application/vnd.syncml+xml";
		else
			accept->value = "application/vnd.syncml+wbxml";
		*list = g_list_append(*list, accept);

		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));
		retvm_if(accept_language == NULL, 0, "[NA Header Binder] 'accept_language' malloc fail !!");

		memset(accept_language, 0x00, sizeof(sync_agent_na_common_header_info_s));
		accept_language->key = "Accept-Language";
		accept_language->value = "en-US";
		*list = g_list_append(*list, accept_language);

		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));
		retvm_if(accept_charset == NULL, 0, "[NA Header Binder] 'accept_charset' malloc fail !!");

		memset(accept_charset, 0x00, sizeof(sync_agent_na_common_header_info_s));
		accept_charset->key = "Accept-Charset";
		accept_charset->value = "UTF-8";
		*list = g_list_append(*list, accept_charset);

		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));
		retvm_if(content_type == NULL, 0, "[NA Header Binder] 'content_type' malloc fail !!");

		memset(content_type, 0x00, sizeof(sync_agent_na_common_header_info_s));
		content_type->key = "Content-Type";
		if (is_xml == true)
			content_type->value = "application/vnd.syncml+xml";
		else
			content_type->value = "application/vnd.syncml+wbxml";
		*list = g_list_append(*list, content_type);

		if (jsession_id != NULL) {
			_DEBUG_INFO(" jsessionid : %s\n", jsession_id);
			sync_agent_na_common_header_info_s *cookie = (sync_agent_na_common_header_info_s *) malloc(sizeof(sync_agent_na_common_header_info_s));
			retvm_if(cookie == NULL, 0, "[NA Header Binder] 'cookie' malloc fail !!");

			memset(cookie, 0x00, sizeof(sync_agent_na_common_header_info_s));
			cookie->key = "cookie";
			cookie->value = jsession_id;
			*list = g_list_append(*list, cookie);
			_DEBUG_INFO(" cookie :  %s\n", cookie->value);
		}
	}

	GList *iter = NULL;
	for (iter = *list; iter != NULL; iter = g_list_next(iter)) {
		_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);
	}

	_EXTERN_FUNC_EXIT;
	return 1;
}

void free_header_info(sync_agent_na_common_header_info_s * common_header_info)
{
	_EXTERN_FUNC_ENTER;

	retm_if(common_header_info == NULL, "pCommon_header_info is NULL");

	free(common_header_info);

	_EXTERN_FUNC_EXIT;
}