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.
19 #include <sync_agent.h>
22 #include "common/dm_common.h"
23 #include "common/util/util.h"
24 #include "serviceadapter/networkbinder/na_binder.h"
26 #ifndef OMADM_AGENT_LOG
28 #define LOG_TAG "OMA_DM_NA"
31 int NA_http_header_binder(char *accType, char *loc_uri, char *sessionid, int isHMAC, char *username, char *mac, GList ** list)
35 retvm_if((accType) == NULL, COMMON_ERR_IS_NULL, "accType is NULL!!");
36 retvm_if((loc_uri) == NULL, COMMON_ERR_IS_NULL, "loc_uri is NULL!!");
38 if (strcmp(accType, "OMA_DM") == 0) {
39 _DEBUG_INFO(" header info start\n");
40 sync_agent_na_common_header_info_s *method = (sync_agent_na_common_header_info_s *) calloc(1, sizeof(sync_agent_na_common_header_info_s));
42 _DEBUG_INFO("alloc error");
46 method->key = "method";
47 method->value = "post";
48 *list = g_list_append(*list, method);
49 _DEBUG_INFO(" post method\n");
51 sync_agent_na_common_header_info_s *uri = (sync_agent_na_common_header_info_s *) calloc(1, sizeof(sync_agent_na_common_header_info_s));
53 _DEBUG_INFO("alloc error");
59 *list = g_list_append(*list, uri);
60 _DEBUG_INFO(" uri\n");
62 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));
63 memset(cache_control, 0x00, sizeof(sync_agent_na_common_header_info_s));
64 cache_control->key = "Cache-Control";
65 cache_control->value = "no-store, private";
66 *list = g_list_append(*list, cache_control);
69 sync_agent_na_common_header_info_s *connection = (sync_agent_na_common_header_info_s *) calloc(1, sizeof(sync_agent_na_common_header_info_s));
70 if (connection == NULL) {
71 _DEBUG_INFO("alloc error");
75 connection->key = "Connection";
76 connection->value = "Keep-Alive";
77 *list = g_list_append(*list, connection);
78 _DEBUG_INFO(" connection\n");
80 sync_agent_na_common_header_info_s *useragent = (sync_agent_na_common_header_info_s *) calloc(1, sizeof(sync_agent_na_common_header_info_s));
81 if (useragent == NULL) {
82 _DEBUG_INFO("alloc error");
86 useragent->key = "User-Agent";
87 useragent->value = "Samsung electronics Tizen SyncML_DM Client";
88 *list = g_list_append(*list, useragent);
89 _DEBUG_INFO(" user agent\n");
91 sync_agent_na_common_header_info_s *accept = (sync_agent_na_common_header_info_s *) calloc(1, sizeof(sync_agent_na_common_header_info_s));
93 _DEBUG_INFO("alloc error");
97 accept->key = "Accept";
98 accept->value = "application/vnd.syncml.dm+wbxml";
99 *list = g_list_append(*list, accept);
100 _DEBUG_INFO(" accept\n");
102 /* 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));
103 memset(accept_language, 0x00, sizeof(sync_agent_na_common_header_info_s));
104 accept_language->key = "Accept-Language";
105 accept_language->value = "en-US";
106 *list = g_list_append(*list, accept_language);
107 _DEBUG_INFO( " \n");*/
109 sync_agent_na_common_header_info_s *accept_charset = (sync_agent_na_common_header_info_s *) calloc(1, sizeof(sync_agent_na_common_header_info_s));
110 if (accept_charset == NULL) {
111 _DEBUG_INFO("alloc error");
115 accept_charset->key = "Accept-Charset";
116 accept_charset->value = "UTF-8";
117 *list = g_list_append(*list, accept_charset);
118 _DEBUG_INFO(" accept charset\n");
120 sync_agent_na_common_header_info_s *content_type = (sync_agent_na_common_header_info_s *) calloc(1, sizeof(sync_agent_na_common_header_info_s));
121 if (content_type == NULL) {
122 _DEBUG_INFO("alloc error");
126 content_type->key = "Content-Type";
127 content_type->value = "application/vnd.syncml.dm+wbxml";
128 *list = g_list_append(*list, content_type);
129 _DEBUG_INFO(" content type\n");
131 if (sessionid != NULL) {
132 _DEBUG_INFO(" jsessionid : %s\n", sessionid);
133 sync_agent_na_common_header_info_s *cookie = (sync_agent_na_common_header_info_s *) calloc(1, sizeof(sync_agent_na_common_header_info_s));
134 if (cookie == NULL) {
135 _DEBUG_INFO("alloc error");
139 cookie->key = HTTP_COOKIE;
140 cookie->value = sessionid;
141 *list = g_list_append(*list, cookie);
142 _DEBUG_INFO(" cookie : %s\n", cookie->value);
146 /* x-syncml-hmac: algorithm=MD5, username="156354238", mac=SF2dMGut4v2Mpmsrs1ydTw== */
147 _DEBUG_INFO(" x-syncml-hmac : %d\n", isHMAC);
148 sync_agent_na_common_header_info_s *hmac = (sync_agent_na_common_header_info_s *) calloc(1, sizeof(sync_agent_na_common_header_info_s));
150 _DEBUG_INFO("alloc error");
154 hmac->key = HTTP_X_SYNCML_HMAC;
155 if (username != NULL) {
156 hmac->value = g_strdup_printf("algorithm=MD5, username=\"%s\", mac=%s", username, mac);
157 _DEBUG_INFO(" hmac = %s : %s\n", hmac->key, hmac->value);
159 *list = g_list_append(*list, hmac);
164 for (iter = *list; iter != NULL; iter = g_list_next(iter)) {
165 fputs("[NA_Header_Binder] key : ", stdout);
166 if (fputs(((sync_agent_na_common_header_info_s *) (iter->data))->key, stdout) == EOF) {
167 _DEBUG_INFO("debuging test error");
170 fputs(", value : ", stdout);
171 if (fputs(((sync_agent_na_common_header_info_s *) (iter->data))->value, stdout) == EOF) {
172 _DEBUG_INFO("debuging test error");
182 int add_jsession_in_httpheader(GList * recv_header, char *temp_jsessionid, char **real_jsessionid, char **real_other_cookie)
185 DM_ERROR ret = DM_OK;
187 char *start_jessionid_msg = NULL;
188 _DEBUG_INFO(" set cookie is : %s \n", temp_jsessionid);
190 /*temp_jsessionid = "JSESSIONID=D15C621FD39535094F1B000307D5D520.sdm1; Path=/v1/sdm; Secure" */
191 if (temp_jsessionid != NULL) {
193 _DEBUG_INFO("-------------------------------------------------------------------------------------------------------------------------------------------------");
194 _DEBUG_INFO("cookie is = %s\n", temp_jsessionid);
195 _DEBUG_INFO("-------------------------------------------------------------------------------------------------------------------------------------------------");
197 start_jessionid_msg = strstr(temp_jsessionid, "JSESSIONID");
198 if (start_jessionid_msg != NULL) {
199 _DEBUG_INFO(" set cookie is : %s \n", start_jessionid_msg);
200 (*real_jsessionid) = strdup(start_jessionid_msg);
202 _DEBUG_INFO(" set cookie is : %s \n", (*real_jsessionid));
204 ret = COMMON_ERR_INTERNAL_NOT_DEFINED;
208 ret = COMMON_ERR_INTERNAL_NOT_DEFINED;