upload tizen1.0 source
[pkgs/o/oma-ds-service.git] / ServiceAdapter / NetworkBinder / NA_Binder.c
1 /*
2  * oma-ds-service
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: JuHak Park <juhaki.park@samsung.com>,
7  *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
8  *          SunBong Ha <sunbong.ha@samsung.com>
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */
23
24
25
26
27 /*
28  * For any sort of issue you concern as to this software,
29  * you may use following point of contact.
30  * All resources contributed on this software
31  * are orinigally written by S-Core Inc., a member of Samsung Group.
32  *
33  * SeongWon Shim <seongwon.shim@samsung.com>
34  */
35
36 /**
37  *   @NA_Binder.c
38  *   @version                                                                   0.1
39  *   @brief                                                                             This file is the source file of implementation of header binder function for Network Adapter
40  */
41
42 #include "agent-framework/Utility/fw_log.h"
43 #include "ServiceAdapter/NetworkBinder/NA_Binder.h"
44
45 #define LOG_TAG "OMA_DS_SA"
46
47 int NA_http_header_binder(char *accType, char *loc_uri, bool isXML, GList **list)
48 {
49         FW_LOGV("[NA Header Binder] start!!");
50
51         if (!strcmp(accType, "OMA_DS")) {
52                 common_header_info *method = (common_header_info *)malloc(sizeof(common_header_info));
53                 if (method == 0x00) {
54                         FW_LOGE("[NA Header Binder] 'method' malloc fail !!");
55                         return 0;
56                 }
57                 memset(method, 0x00, sizeof(common_header_info));
58                 method->key = "method";
59                 method->value = "post";
60                 *list = g_list_append(*list, method);
61
62                 common_header_info *uri = (common_header_info *)malloc(sizeof(common_header_info));
63                 if (uri == 0x00) {
64                         FW_LOGE("[NA Header Binder] 'uri' malloc fail !!");
65                         return 0;
66                 }
67                 memset(uri, 0x00, sizeof(common_header_info));
68                 uri->key = "uri";
69                 uri->value = loc_uri;
70                 *list = g_list_append(*list, uri);
71
72                 common_header_info *cache_control = (common_header_info *)malloc(sizeof(common_header_info));
73                 if (cache_control == 0x00) {
74                         FW_LOGE("[NA Header Binder] 'cache_control' malloc fail !!");
75                         return 0;
76                 }
77                 memset(cache_control, 0x00, sizeof(common_header_info));
78                 cache_control->key = "Cache-Control";
79                 cache_control->value = "no-store, private";
80                 *list = g_list_append(*list, cache_control);
81
82                 common_header_info *connection = (common_header_info *)malloc(sizeof(common_header_info));
83                 if (connection == 0x00) {
84                         FW_LOGE("[NA Header Binder] 'connection' malloc fail !!");
85                         return 0;
86                 }
87                 memset(connection, 0x00, sizeof(common_header_info));
88                 connection->key = "Connection";
89                 connection->value = "Keep-Alive";
90                 *list = g_list_append(*list, connection);
91
92                 common_header_info *accept = (common_header_info *)malloc(sizeof(common_header_info));
93                 if (accept == 0x00) {
94                         FW_LOGE("[NA Header Binder] 'accept' malloc fail !!");
95                         return 0;
96                 }
97                 memset(accept, 0x00, sizeof(common_header_info));
98                 accept->key = "Accept";
99                 if (isXML == true)
100                         accept->value = "application/vnd.syncml+xml";
101                 else
102                         accept->value = "application/vnd.syncml+wbxml";
103                 *list = g_list_append(*list, accept);
104
105                 common_header_info *accept_language = (common_header_info *)malloc(sizeof(common_header_info));
106                 if (accept_language == 0x00) {
107                         FW_LOGE("[NA Header Binder] 'accept_language' malloc fail !!");
108                         return 0;
109                 }
110                 memset(accept_language, 0x00, sizeof(common_header_info));
111                 accept_language->key = "Accept-Language";
112                 accept_language->value = "en-US";
113                 *list = g_list_append(*list, accept_language);
114
115                 common_header_info *accept_charset = (common_header_info *)malloc(sizeof(common_header_info));
116                 if (accept_charset == 0x00) {
117                         FW_LOGE("[NA Header Binder] 'accept_charset' malloc fail !!");
118                         return 0;
119                 }
120                 memset(accept_charset, 0x00, sizeof(common_header_info));
121                 accept_charset->key = "Accept-Charset";
122                 accept_charset->value = "UTF-8";
123                 *list = g_list_append(*list, accept_charset);
124
125                 common_header_info *content_type = (common_header_info *)malloc(sizeof(common_header_info));
126                 if (content_type == 0x00) {
127                         FW_LOGE("[NA Header Binder] 'content_type' malloc fail !!");
128                         return 0;
129                 }
130                 memset(content_type, 0x00, sizeof(common_header_info));
131                 content_type->key = "Content-Type";
132                 if (isXML == true)
133                         content_type->value = "application/vnd.syncml+xml";
134                 else
135                         content_type->value = "application/vnd.syncml+wbxml";
136                 *list = g_list_append(*list, content_type);
137
138         }
139
140         GList *iter = NULL;
141         for (iter = *list; iter != NULL; iter = g_list_next(iter)) {
142                 FW_LOGV("[NA_Header_Binder] key : %s, value : %s", ((common_header_info *)(iter->data))->key, ((common_header_info *)(iter->data))->value);
143         }
144
145         FW_LOGV("end");
146
147         return 1;
148 }
149
150 void free_header_info(common_header_info *pCommon_header_info)
151 {
152         if (pCommon_header_info == NULL)
153                 return;
154
155         free(pCommon_header_info);
156 }