sync-agent: Change the system-info api to 2.3 public api
[platform/core/system/sync-agent.git] / src / fw-plugins / common-public / http / src / plugin_interface.c
1 /*
2  * sync-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 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <glib.h>
22 #include <glib/gprintf.h>
23
24 //#define USING_LIBSOUP
25 /* #define time_check */
26 //#define CBA /* for using HTTP certification of FOTA production */
27
28 #ifdef USING_LIBSOUP
29 #include <libsoup/soup-uri.h>
30 #include <libsoup/soup.h>
31 #else
32 #include <curl/curl.h>
33 #include <ctype.h>
34 #endif
35
36 #include <time.h>
37
38 //#include <dlog.h>
39
40 #include "na_external.h"
41 #include "http_status.h"
42
43 /* for log */
44 #include "utility/sync_util.h"
45
46 #include "plugin/network_access_interface.h"
47
48 #ifdef CBA
49 #include <openssl/ssl.h>
50 #include <errno.h>
51 #endif
52
53 #define SEMI_COLON_LEN                  1
54 #define NULL_LEN                                                1
55
56 #ifndef EXPORT_API
57 #define EXPORT_API __attribute__ ((visibility("default")))
58 #endif
59
60 #ifndef SYNC_AGENT_LOG
61 #undef LOG_TAG
62 #define LOG_TAG "PLUGIN_NA_HTTP"
63 #endif
64
65 #ifdef USING_LIBSOUP
66 typedef struct {
67         SoupSession *session;
68         CURL *session;
69         char *id;
70         char *password;
71 } auth_info_s;
72
73 static int _add_auth_info(SoupSession * session, char *user_id, char *user_pw);
74                                                                                                                                                                      /*static int remove_auth_info(SoupSession *session); *//*      not used        */
75 static int _find_auth_info(SoupSession * session, auth_info_s ** auth_info);
76 static void authenticate_cb(SoupSession * session, SoupMessage * msg, SoupAuth * auth, gboolean retrying, gpointer user_data);
77
78 static GList *auth_info_list = NULL;
79 #else
80 typedef enum {
81         LIBCURL_HTTP_GET = 0,
82         LIBCURL_HTTP_PUT,
83         LIBCURL_HTTP_POST,
84         LIBCURL_HTTP_TRACE,
85         LIBCURL_HTTP_CONNECT,
86         LIBCURL_HTTP_HEAD,
87         LIBCURL_HTTP_DELETE,
88         LIBCURL_HTTP_OPTIONS
89 } libcurl_http_method_e;
90
91 typedef struct {
92         char *buff;
93         int length;
94         int block_size;
95 } http_buffer_s;
96
97 #ifdef CBA
98 typedef struct {
99         int accept_all_certs;
100         char *privatekey_password;
101         char *certificate_path;
102         unsigned char *privatekey;
103 } certificate_info_s;
104 #endif
105
106 typedef struct {
107         libcurl_http_method_e method;
108         char *uri;
109         char *accept_encoding;
110         struct curl_slist *send_header;
111         http_buffer_s *response_header;
112         http_buffer_s *response_body;
113         int http_status;
114         int abort;
115         void *session;
116 #ifdef CBA
117         certificate_info_s *cert_info;
118 #endif
119 } http_message_s;
120
121 typedef struct {
122         CURL *session;
123         http_message_s *msg;
124 } curl_session_s;
125
126 #define HEADER_BLOCK_SIZE               (1024)
127 #define CONTENT_BLOCK_SIZE              (16*1024)
128
129 static int curl_progress_cb(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
130
131 static int _curl_session_abort(curl_session_s * session);
132
133 static http_buffer_s *__create_http_buffer(int block_size);
134 static int __delete_http_buffer(http_buffer_s * buff);
135 static size_t write_http_buffer_cb(void *ptr, size_t size, size_t nmemb, void *userdata);
136
137 #ifdef CBA
138 static http_message_s *_create_http_message(libcurl_http_method_e method, char *uri, char *accept_encoding, int is_cert);
139 #else
140 static http_message_s *_create_http_message(libcurl_http_method_e method, char *uri, char *accept_encoding);
141 #endif
142
143 static int _add_http_header(http_message_s * msg, char *key, char *value);
144 static int _delete_http_message(http_message_s * msg);
145
146 static int _parse_http_header(http_buffer_s * header, GList ** header_list);
147
148 static common_header_info_s *__create_header_info(char *key, char *value);
149
150 #ifdef CBA
151 static void _add_certificate_option(CURL * curl, http_message_s * msg);
152 //static CURLcode ssl_context_cb(CURL * curl, SSL_CTX * sslctx, void *param);
153 static CURLcode ssl_context_cb(CURL * curl, void * sslctx, void *param);
154 static int verify_peer_cb(int preverify_ok, X509_STORE_CTX * x509_ctx);
155 #endif
156
157 #endif
158
159 #ifdef USING_LIBSOUP
160 EXPORT_API int sync_agent_plugin_open_connection(void **session, char *proxy, int timeout)
161 {
162 #ifdef time_check
163         /* function Start Time */
164         clock_t start_t, end_t;
165         double proc_t = 0.0;
166         start_t = clock();
167 #endif
168
169         int res = 1;
170
171         /*
172          *      create session
173          */
174         SoupSession *ss = (SoupSession *) (*session);
175         SoupURI *proxy_uri = NULL;
176
177         _DEBUG_INFO("proxy : %s", proxy);
178
179         /*
180          *      proxy setting
181          */
182         if (proxy != NULL) {
183                 proxy_uri = soup_uri_new(proxy);
184                 ss = soup_session_sync_new_with_options(SOUP_SESSION_PROXY_URI, proxy_uri, NULL);
185         } else {
186                 ss = soup_session_sync_new();
187         }
188
189         g_object_set(ss, SOUP_SESSION_TIMEOUT, timeout, NULL);
190         _DEBUG_INFO("[na_http_plugIn] set timeout : %d", timeout);
191
192         _DEBUG_INFO("[na_http_plugIn] session : %d\n", ss);
193
194         if (ss != NULL) {
195                 _DEBUG_INFO("[na_http_plugIn] success !! \n");
196         } else {
197                 _DEBUG_ERROR("[na_http_plugIn] fail !! \n");
198                 res = 0;
199         }
200
201         *session = ss;
202
203 #ifdef time_check
204         /* function End Time */
205         end_t = clock();
206         proc_t = ((double)(end_t - start_t)) / CLOCKS_PER_SEC;
207         _DEBUG_INFO("[na_http_plugIn] execute time : %0.2f\n", proc_t);
208 #endif
209
210         return res;
211 }
212 #else
213 EXPORT_API int sync_agent_plugin_open_connection(void **session, char *proxy, int timeout)
214 {
215         _EXTERN_FUNC_ENTER;
216
217 #ifdef time_check
218         /* function Start Time */
219         clock_t start_t, end_t;
220         double proc_t = 0.0;
221         start_t = clock();
222 #endif
223
224         int res = 1;
225
226         /*
227          *      create session
228          */
229
230         curl_session_s *curl_session = (curl_session_s *) calloc(1, sizeof(curl_session_s));
231         if (curl_session == NULL) {
232                 _DEBUG_ERROR("CALLOC failed !!!");
233                 return 0;
234         }
235         CURL *curl;
236         CURLcode ret;
237
238         _DEBUG_INFO("proxy : %s", proxy);
239
240         /*
241          *      proxy setting
242          */
243         curl = curl_easy_init();
244         if (proxy != NULL) {
245                 if(strncmp(proxy,"http://0.0.0.0", strlen("http://0.0.0.0")) == 0) {
246                 } else {
247                         ret = curl_easy_setopt(curl, CURLOPT_PROXY, proxy);
248                 }
249         }
250
251         ret = curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, timeout);
252         _DEBUG_INFO("[na_http_plugIn] set timeout : %d", timeout);
253
254         _DEBUG_INFO("[na_http_plugIn] session : %d\n", curl);
255
256         if (curl != NULL) {
257                 _DEBUG_INFO("[na_http_plugIn] success !! \n");
258         } else {
259                 _DEBUG_ERROR("[na_http_plugIn] fail !! \n");
260                 res = 0;
261         }
262
263         curl_session->session = curl;
264
265         *session = curl_session;
266
267 #ifdef time_check
268         /* function End Time */
269         end_t = clock();
270         proc_t = ((double)(end_t - start_t)) / CLOCKS_PER_SEC;
271         _DEBUG_INFO("[na_http_plugIn] execute time : %0.2f\n", proc_t);
272 #endif
273
274         _EXTERN_FUNC_EXIT;
275
276         return res;
277 }
278 #endif
279
280 EXPORT_API int sync_agent_plugin_header_binding(GList * header_info, void **header_binding)
281 {
282         _EXTERN_FUNC_ENTER;
283
284         retvm_if(header_info == NULL, 0, "header_info is NULL. FAIL !!!");
285
286 #ifdef time_check
287         /* function Start Time */
288         clock_t start_t, end_t;
289         double proc_t = 0.0;
290         start_t = clock();
291 #endif
292
293 #ifdef USING_LIBSOUP
294         int res = 1;
295         GList *iter = NULL;
296         char *method = NULL;
297         char *uri = NULL;
298         common_header_info_s *iter_data = NULL;
299
300         if (header_info == NULL) {
301                 _DEBUG_ERROR("[na_http_plugIn] Error !! ( not exist header information )\n");
302                 res = 0;
303                 return res;
304         }
305
306         SoupMessage *msg = (SoupMessage *) (*header_binding);
307         _DEBUG_INFO("[na_http_plugIn] msg : %d\n", msg);
308
309 #else
310         char *method = NULL;
311         char *uri = NULL;
312 #ifdef CBA
313         char *is_certificate = NULL;
314 #endif
315         char *accept_encoding = "gzip,deflate";
316
317         int res = 1;
318         GList *iter = NULL;
319         http_message_s *msg = NULL;
320         libcurl_http_method_e libcurl_method = LIBCURL_HTTP_GET;
321
322         /*
323          *      add message body to message header
324          */
325         _DEBUG_INFO("[na_http_plugIn] create whole msg (header + body)\n");
326
327         common_header_info_s *iter_data = NULL;
328
329         if (header_info == NULL) {
330                 _DEBUG_ERROR("[na_http_plugIn] Error !! ( not exist header information )\n");
331                 res = 0;
332                 return res;
333         }
334 #endif
335
336         for (iter = header_info; iter != NULL; iter = g_list_next(iter)) {
337                 if (((common_header_info_s *) (iter->data))->key != NULL) {
338                         if (!strcmp(((common_header_info_s *) (iter->data))->key, "method")) {
339                                 method = ((common_header_info_s *) (iter->data))->value;
340                                 break;
341                         }
342                 }
343         }
344
345         if (iter == NULL) {
346                 _DEBUG_ERROR("[na_http_plugIn] Iteration is NULL\n");
347                 res = 0;
348                 return res;
349         }
350
351         iter_data = (common_header_info_s *) iter->data;
352         header_info = g_list_remove(header_info, iter_data);
353         free((common_header_info_s *) iter_data);
354         _DEBUG_INFO("[na_http_plugIn] method : %s\n", method);
355
356         iter = NULL;
357         iter_data = NULL;
358         for (iter = header_info; iter != NULL; iter = g_list_next(iter)) {
359                 if (((common_header_info_s *) (iter->data))->key != NULL) {
360                         if (!strcmp(((common_header_info_s *) (iter->data))->key, "uri")) {
361                                 uri = ((common_header_info_s *) (iter->data))->value;
362                                 break;
363                         }
364                 }
365         }
366
367         if (iter == NULL) {
368                 _DEBUG_ERROR("[na_http_plugIn] Iteration is NULL\n");
369                 res = 0;
370                 return res;
371         }
372
373         iter_data = (common_header_info_s *) iter->data;
374         header_info = g_list_remove(header_info, iter_data);
375         free((common_header_info_s *) iter_data);
376         _DEBUG_INFO("[na_http_plugIn] uri : %s\n", uri);
377
378 #ifdef CBA
379         iter = NULL;
380         iter_data = NULL;
381         for (iter = header_info; iter != NULL; iter = g_list_next(iter)) {
382                 if (((common_header_info_s *) (iter->data))->key != NULL) {
383                         if (!strcmp(((common_header_info_s *) (iter->data))->key, "certificate")) {
384                                 is_certificate = ((common_header_info_s *) (iter->data))->value;
385                                 break;
386                         }
387                 }
388         }
389
390         if (iter == NULL) {
391                 _DEBUG_ERROR("[na_http_plugIn] 'Certificate' is not existed !!");
392         } else {
393                 iter_data = (common_header_info_s *) iter->data;
394                 header_info = g_list_remove(header_info, iter_data);
395                 free((common_header_info_s *) iter_data);
396                 _DEBUG_INFO("[na_http_plugIn] certificate : %s\n", is_certificate);
397         }
398 #endif
399
400 #ifdef USING_LIBSOUP
401         if (!strcmp(method, "options")) {
402                 msg = soup_message_new(SOUP_METHOD_OPTIONS, uri);
403         } else if (!strcmp(method, "get")) {
404                 msg = soup_message_new(SOUP_METHOD_GET, uri);
405         } else if (!strcmp(method, "head")) {
406                 msg = soup_message_new(SOUP_METHOD_HEAD, uri);
407         } else if (!strcmp(method, "post")) {
408                 msg = soup_message_new(SOUP_METHOD_POST, uri);
409         } else if (!strcmp(method, "put")) {
410                 msg = soup_message_new(SOUP_METHOD_PUT, uri);
411         } else if (!strcmp(method, "delete")) {
412                 msg = soup_message_new(SOUP_METHOD_DELETE, uri);
413         } else if (!strcmp(method, "trace")) {
414                 msg = soup_message_new(SOUP_METHOD_TRACE, uri);
415         } else if (!strcmp(method, "connect")) {
416                 msg = soup_message_new(SOUP_METHOD_CONNECT, uri);
417         }
418
419         if (msg == NULL) {
420                 _DEBUG_ERROR("[na_http_plugIn] Error !! ( wrong uri : %s )\n", uri);
421                 res = 0;
422                 return res;
423         }
424 #else
425         iter = NULL;
426         iter_data = NULL;
427         for (iter = header_info; iter != NULL; iter = g_list_next(iter)) {
428                 if (((common_header_info_s *) (iter->data))->key != NULL) {
429                         if (!strcmp(((common_header_info_s *) (iter->data))->key, "Accept-Encoding")) {
430                                 accept_encoding = ((common_header_info_s *) (iter->data))->value;
431                                 break;
432                         }
433                 }
434         }
435
436         if (iter != NULL) {
437                 iter_data = (common_header_info_s *) iter->data;
438                 header_info = g_list_remove(header_info, iter_data);
439                 free((common_header_info_s *) iter_data);
440                 _DEBUG_INFO("[na_http_plugIn] accept_encoding : %s\n", accept_encoding);
441         }
442
443         if (method != NULL) {
444                 if (!strcmp(method, "options")) {
445                         libcurl_method = LIBCURL_HTTP_OPTIONS;
446                 } else if (!strcmp(method, "get")) {
447                         libcurl_method = LIBCURL_HTTP_GET;
448                 } else if (!strcmp(method, "head")) {
449                         libcurl_method = LIBCURL_HTTP_HEAD;
450                 } else if (!strcmp(method, "post")) {
451                         libcurl_method = LIBCURL_HTTP_POST;
452                 } else if (!strcmp(method, "put")) {
453                         libcurl_method = LIBCURL_HTTP_PUT;
454                 } else if (!strcmp(method, "delete")) {
455                         libcurl_method = LIBCURL_HTTP_DELETE;
456                 } else if (!strcmp(method, "trace")) {
457                         libcurl_method = LIBCURL_HTTP_TRACE;
458                 } else if (!strcmp(method, "connect")) {
459                         libcurl_method = LIBCURL_HTTP_CONNECT;
460                 }
461                 //free(method);
462         }
463         if (uri != NULL) {
464 #ifdef CBA
465                 if (is_certificate != NULL) {
466                         msg = _create_http_message(libcurl_method, uri, accept_encoding, atoi(is_certificate));
467                 } else {
468                         msg = _create_http_message(libcurl_method, uri, accept_encoding, 0);
469                 }
470 #else
471                 msg = _create_http_message(libcurl_method, uri, accept_encoding);
472 #endif
473                 _DEBUG_INFO("[na_http_plugIn] create_http_message(%s)\n", uri);
474
475 #ifdef CBA
476                 if (msg == NULL) {
477                         _DEBUG_INFO("[na_http_plugIn] create_http_message(%s) Failed\n", uri);
478                         res = 0;
479                         return res;
480                 }
481
482                 if (msg->cert_info != NULL) {
483                         _DEBUG_INFO("[na_http_plugIn] certificate info is existed !!");
484
485                         iter = NULL;
486                         iter_data = NULL;
487                         for (iter = header_info; iter != NULL; iter = g_list_next(iter)) {
488                                 if (((common_header_info_s *) (iter->data))->key != NULL) {
489                                         if (!strcmp(((common_header_info_s *) (iter->data))->key, "accept_all_certs")) {
490                                                 //msg->cert_info->accept_all_certs = strdup(((common_header_info_s *) (iter->data))->value);
491                                                 msg->cert_info->accept_all_certs = atoi(strdup(((common_header_info_s *) (iter->data))->value));
492                                                 break;
493                                         }
494                                 }
495                         }
496
497                         if (iter != NULL) {
498                                 iter_data = (common_header_info_s *) iter->data;
499                                 header_info = g_list_remove(header_info, iter_data);
500                                 free((common_header_info_s *) iter_data);
501                                 //_DEBUG_INFO("[na_http_plugIn] privatekey password : %s", msg->cert_info->accept_all_certs);
502                                 _DEBUG_INFO("[na_http_plugIn] accept_all_certs : %d", msg->cert_info->accept_all_certs);
503                         }
504
505                         iter = NULL;
506                         iter_data = NULL;
507                         for (iter = header_info; iter != NULL; iter = g_list_next(iter)) {
508                                 if (((common_header_info_s *) (iter->data))->key != NULL) {
509                                         if (!strcmp(((common_header_info_s *) (iter->data))->key, "privatekey_password")) {
510                                                 msg->cert_info->privatekey_password = strdup(((common_header_info_s *) (iter->data))->value);
511                                                 break;
512                                         }
513                                 }
514                         }
515
516                         if (iter != NULL) {
517                                 iter_data = (common_header_info_s *) iter->data;
518                                 header_info = g_list_remove(header_info, iter_data);
519                                 free((common_header_info_s *) iter_data);
520                                 _DEBUG_INFO("[na_http_plugIn] privatekey password : %s", msg->cert_info->privatekey_password);
521                         }
522
523                         iter = NULL;
524                         iter_data = NULL;
525                         for (iter = header_info; iter != NULL; iter = g_list_next(iter)) {
526                                 if (((common_header_info_s *) (iter->data))->key != NULL) {
527                                         if (!strcmp(((common_header_info_s *) (iter->data))->key, "certificate_path")) {
528                                                 msg->cert_info->certificate_path = strdup(((common_header_info_s *) (iter->data))->value);
529                                                 break;
530                                         }
531                                 }
532                         }
533
534                         if (iter != NULL) {
535                                 iter_data = (common_header_info_s *) iter->data;
536                                 header_info = g_list_remove(header_info, iter_data);
537                                 free((common_header_info_s *) iter_data);
538                                 _DEBUG_INFO("[na_http_plugIn] certificate path : %s", msg->cert_info->certificate_path);
539                         }
540
541                         iter = NULL;
542                         iter_data = NULL;
543                         for (iter = header_info; iter != NULL; iter = g_list_next(iter)) {
544                                 if (((common_header_info_s *) (iter->data))->key != NULL) {
545                                         if (!strcmp(((common_header_info_s *) (iter->data))->key, "privatekey")) {
546                                                 //msg->cert_info->privatekey = strdup(((common_header_info_s *) (iter->data))->value);
547                                                 msg->cert_info->privatekey = (unsigned char *)strdup(((common_header_info_s *) (iter->data))->value);
548                                                 break;
549                                         }
550                                 }
551                         }
552
553                         if (iter != NULL) {
554                                 iter_data = (common_header_info_s *) iter->data;
555                                 header_info = g_list_remove(header_info, iter_data);
556                                 free((common_header_info_s *) iter_data);
557                                 _DEBUG_INFO("[na_http_plugIn] privatekey : %s", msg->cert_info->privatekey);
558                         }
559                 }
560 #endif
561                 //free(uri);
562         }
563
564         if (msg == NULL) {
565                 _DEBUG_INFO("[na_http_plugIn] create_http_message(%s) Failed\n", uri);
566                 res = 0;
567                 return res;
568         }
569 #endif
570         /*
571          *      perform soup_message_headers_append() using key-value in header_info
572          */
573         iter = NULL;
574         iter_data = NULL;
575         for (iter = header_info; iter != NULL;) {
576                 iter_data = ((common_header_info_s *) (iter->data));
577                 if (iter_data->key != NULL) {
578 #ifdef USING_LIBSOUP
579                         soup_message_headers_append(msg->request_headers, iter_data->key, iter_data->value);
580 #else
581                         _add_http_header(msg, iter_data->key, iter_data->value);
582 #endif
583                         _DEBUG_INFO("[na_http_plugIn] header append\n\t key : %s, value : %s\n", iter_data->key, iter_data->value);
584                         iter = g_list_next(iter);
585                         header_info = g_list_remove(header_info, iter_data);
586                         free((common_header_info_s *) (iter_data));
587                 }
588         }
589
590         *header_binding = msg;
591         _DEBUG_INFO("[na_http_plugIn] msg : %d\n", msg);
592
593         if (header_info != NULL)
594                 g_list_free(header_info);
595
596 #ifdef time_check
597         /* function End Time */
598         end_t = clock();
599         proc_t = ((double)(end_t - start_t)) / CLOCKS_PER_SEC;
600         _DEBUG_INFO("[na_http_plugIn] execute time : %0.2f\n", proc_t);
601 #endif
602
603         _EXTERN_FUNC_EXIT;
604
605         return res;
606 }
607
608 EXPORT_API int sync_agent_plugin_send_message(void *session, void **header_binding, char *send_msg, unsigned int send_msg_length, unsigned int *recv_msg_size)
609 {
610         _EXTERN_FUNC_ENTER;
611
612         retvm_if(*header_binding == NULL, 0, "*header_binding is NULL. FAIL !!!");
613
614 #ifdef time_check
615         /* function Start Time */
616         clock_t start_t, end_t;
617         double proc_t = 0.0;
618         start_t = clock();
619 #endif
620
621         int res = 1;
622
623 #ifdef USING_LIBSOUP
624         SoupSession *ss = (SoupSession *) session;
625         _DEBUG_INFO("[na_http_plugIn] session : %d\n", ss);
626         SoupMessage *msg = (SoupMessage *) (*header_binding);
627         _DEBUG_INFO("[na_http_plugIn] msg : %d\n", msg);
628
629 /*      for test
630         SoupMessageHeadersIter iter;
631         const char *name, *value;
632
633         soup_message_headers_iter_init (&iter, msg->request_headers);
634         _DEBUG_INFO(stdout, "1\n");
635         while (soup_message_headers_iter_next (&iter, &name, &value)) {
636                 _DEBUG_INFO(stdout, "header - name : %s   value : %s", name, value);
637                 _DEBUG_INFO(stdout, "2\n");
638         }
639         */
640
641         /*
642          *      add message body to message header
643          */
644         _DEBUG_INFO("[na_http_plugIn] create whole msg (header + body)\n");
645         soup_message_body_append(msg->request_body, SOUP_MEMORY_TEMPORARY, send_msg, send_msg_length);
646
647         /*
648          *      send & receive message
649          */
650         _DEBUG_INFO("[na_http_plugIn] send message & receive message to server \n");
651         int http_status = soup_session_send_message(ss, msg);
652
653         switch (http_status) {  /* todo : Send Message return type must be defined */
654         case REQUEST_TIMEOUT:
655                 res = -408;
656                 break;
657         case OK:
658                 res = 1;
659                 break;
660         case SOUP_CANCELED:
661                 res = -1;
662                 break;
663         case SOUP_TRY_AGAIN:
664                 res = -8;
665                 break;
666         default:
667                 res = 0;
668                 break;
669         }
670
671         _DEBUG_INFO("[na_http_plugIn] http status : %d\n", http_status);
672 #else
673         curl_session_s *curl_session = (curl_session_s *) session;
674         if (curl_session == NULL) {
675                 _DEBUG_ERROR("curl_session is NULL");
676                 res = 0;
677                 return res;
678         }
679
680         CURL *curl = curl_session->session;
681         http_message_s *msg = (http_message_s *) * header_binding;
682
683         _DEBUG_INFO("[na_http_plugIn] session : %d\n", session);
684
685         if (curl_session->msg != NULL) {
686                 _delete_http_message(curl_session->msg);
687                 curl_session->msg = NULL;
688         }
689         msg->session = curl_session;
690         curl_session->msg = msg;
691
692         /*
693          *      add message body to message header
694          */
695         _DEBUG_INFO("[na_http_plugIn] create whole msg (header + body)\n");
696
697         curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, NULL);
698         curl_easy_setopt(curl, CURLOPT_POST, 0L);
699         curl_easy_setopt(curl, CURLOPT_PUT, 0L);
700         curl_easy_setopt(curl, CURLOPT_HTTPGET, 0L);
701
702         curl_easy_setopt(curl, CURLOPT_ENCODING, msg->accept_encoding);
703
704         curl_easy_setopt(curl, CURLOPT_HTTPHEADER, msg->send_header);
705         switch (msg->method) {
706         case LIBCURL_HTTP_GET:
707                 curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
708                 break;
709         case LIBCURL_HTTP_HEAD:
710                 curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "HEAD");
711                 break;
712         case LIBCURL_HTTP_POST:
713                 curl_easy_setopt(curl, CURLOPT_POST, 1L);
714                 curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, send_msg_length);
715                 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (void*)send_msg);
716                 break;
717         case LIBCURL_HTTP_PUT:
718                 curl_easy_setopt(curl, CURLOPT_PUT, 1L);
719                 break;
720         case LIBCURL_HTTP_DELETE:
721                 curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
722                 break;
723         case LIBCURL_HTTP_TRACE:
724                 curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "TRACE");
725                 break;
726         case LIBCURL_HTTP_OPTIONS:
727                 curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "OPTIONS");
728                 break;
729         case LIBCURL_HTTP_CONNECT:
730                 break;
731         }
732         curl_easy_setopt(curl, CURLOPT_URL, msg->uri);
733
734         curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
735         curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, curl_progress_cb);
736         curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, session);
737         curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_http_buffer_cb);
738         curl_easy_setopt(curl, CURLOPT_WRITEDATA, msg->response_body);
739         curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_http_buffer_cb);
740         curl_easy_setopt(curl, CURLOPT_WRITEHEADER, msg->response_header);
741
742 #ifdef CBA
743         if (msg->cert_info == NULL) {
744                 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
745                 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
746         } else {
747                 _add_certificate_option(curl, msg);
748         }
749 #else
750         curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
751         curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
752 #endif
753
754         /*
755          *      send & receive message
756          */
757         _DEBUG_INFO("[na_http_plugIn] send message & receive message to server \n");
758         int http_status = 0;
759         long response_code;
760         http_status = curl_easy_perform(curl);
761
762         switch (http_status) {  /* todo : Send Message return type must be defined */
763         case CURLE_OPERATION_TIMEDOUT:
764                 res = -408;
765                 break;
766         case CURLE_OK:
767                 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
768                 http_status = response_code;
769                 _DEBUG_INFO("[na_http_plugIn] response_code : %d\n", response_code);
770                 if (response_code >= 200 && response_code <= 299) {
771                         res = 1;
772                 } else {
773                         res = 0;
774                 }
775                 break;
776         case CURLE_ABORTED_BY_CALLBACK:
777                 res = -1;
778                 break;
779         case CURLE_AGAIN:
780         case CURLE_GOT_NOTHING:
781                 res = -8;
782                 break;
783 #ifdef CBA
784         case CURLE_SSL_CACERT:
785         case CURLE_PEER_FAILED_VERIFICATION:
786                 if (msg->cert_info->accept_all_certs != 1) {
787                         res = -10;
788                 } else {
789                         res = 1;
790                 }
791                 break;
792 #endif
793         default:
794                 res = 0;
795                 break;
796         }
797         msg->http_status = http_status;
798         _DEBUG_INFO("[na_http_plugIn] http status : %d\n", http_status);
799 #endif
800
801 #ifdef time_check
802         /* function End Time */
803         end_t = clock();
804         proc_t = ((double)(end_t - start_t)) / CLOCKS_PER_SEC;
805         _DEBUG_INFO("[na_http_plugIn] execute time : %0.2f\n", proc_t);
806 #endif
807
808         _EXTERN_FUNC_EXIT;
809
810         return res;
811 }
812
813 EXPORT_API int sync_agent_plugin_header_unbinding(void *msg, unsigned int msg_size, GList ** recv_header, unsigned char **recv_msg, unsigned int *recv_msg_length)
814 {
815         _EXTERN_FUNC_ENTER;
816
817 #ifdef time_check
818         /* function Start Time */
819         clock_t start_t, end_t;
820         double proc_t = 0.0;
821         start_t = clock();
822 #endif
823
824         int res = 1;
825 #ifdef USING_LIBSOUP
826         SoupMessage *whole_msg = (SoupMessage *) msg;
827         _DEBUG_INFO("[na_http_plugIn] msg : %d\n", whole_msg);
828
829         SoupMessageHeadersIter iter;
830         const char *name, *value;
831
832         *recv_header = NULL;
833
834         /*
835          *      separate header
836          */
837         soup_message_headers_iter_init(&iter, whole_msg->response_headers);
838         common_header_info_s *header_info = NULL;
839         while (soup_message_headers_iter_next(&iter, &name, &value)) {
840                 header_info = (common_header_info_s *) malloc(sizeof(common_header_info_s));
841                 if (header_info == NULL) {
842                         _DEBUG_ERROR("[na_http_plugIn] header_info malloc fail !!");
843
844                         if (*recv_header != NULL)
845                                 g_list_free(*recv_header);
846
847                         res = 0;
848                         return res;
849                 }
850                 memset(header_info, 0x00, sizeof(common_header_info_s));
851
852                 header_info->key = strdup(name);
853                 header_info->value = strdup(value);
854
855                 *recv_header = g_list_append(*recv_header, header_info);
856         }
857 #else
858         http_message_s *http_message = (http_message_s *) msg;
859         //char *http_status = g_strdup_printf("%d", http_message->http_status);
860         _DEBUG_INFO("[na_http_plugIn] msg : %d\n", msg);
861         *recv_header = NULL;
862         if (_parse_http_header(http_message->response_header, recv_header) == 0) {
863                 res = 0;
864                 return res;
865         }
866
867         /*
868            if (http_status) {
869            *recv_header = g_list_append(*recv_header, create_header_info("Http-Status", http_status));
870            free(http_status);
871            } */
872 #endif
873         /* for test */
874         GList *g_iter = NULL;
875         for (g_iter = *recv_header; g_iter != NULL; g_iter = g_list_next(g_iter)) {
876                 _DEBUG_INFO("[na_http_plugIn] key : %s, value : %s", ((common_header_info_s *) (g_iter->data))->key, ((common_header_info_s *) (g_iter->data))->value);
877         }
878
879         /*
880          *      separate body
881          */
882 #ifdef USING_LIBSOUP
883         if (whole_msg->response_body != NULL) {
884                 if ((whole_msg->response_body->length > 0) && (whole_msg->response_body->data != NULL)) {
885                         _DEBUG_INFO("[na_http_plugIn] recv body length : %d\n", whole_msg->response_body->length);
886                         *recv_msg = (unsigned char *)malloc(whole_msg->response_body->length + 1);
887                         if (*recv_msg == NULL) {
888                                 res = 0;
889                                 return res;
890                         }
891                         memset(*recv_msg, 0x00, whole_msg->response_body->length + 1);
892                         memcpy(*recv_msg, whole_msg->response_body->data, whole_msg->response_body->length);
893
894                         *recv_msg_length = whole_msg->response_body->length;
895                         _DEBUG_INFO("[na_http_plugIn] recv_body : %s\n", *recv_msg);
896                 }
897                 /* else {
898                    _DEBUG_INFO("[na_http_plugIn] recv msg is not exist !!\n");
899
900                    if (*recv_header != NULL)
901                    g_list_free(recv_header);
902
903                    res = 0;
904                    return res;
905                    } */
906         }
907 #else
908         if ((recv_msg_length != NULL) && (recv_msg != NULL)) {
909                 if ((http_message->response_body->length > 0)) {
910                         if (http_message->response_body->buff != NULL) {
911                                 *recv_msg = malloc(http_message->response_body->length + 1);
912                                 if (*recv_msg == NULL) {
913                                         _DEBUG_ERROR("MALLOC failed !!!");
914                                         res = 0;
915                                         return res;
916                                 }
917                                 memcpy(*recv_msg, http_message->response_body->buff, http_message->response_body->length);
918                                 (*recv_msg)[http_message->response_body->length] = 0;
919                                 *recv_msg_length = http_message->response_body->length;
920                         }
921                 } else {
922                         *recv_msg_length = 0;
923                         *recv_msg = NULL;
924                 }
925         }
926 #endif
927
928         _DEBUG_INFO("[na_http_plugIn] msg : %d\n", msg);
929
930 #ifdef time_check
931         /* function End Time */
932         end_t = clock();
933         proc_t = ((double)(end_t - start_t)) / CLOCKS_PER_SEC;
934         _DEBUG_INFO("[na_http_plugIn] execute time : %0.2f\n", proc_t);
935 #endif
936
937 #ifdef USING_LIBSOUP
938         g_object_unref(G_OBJECT(msg));
939 #else
940         curl_session_s *session;
941         session = (curl_session_s *) http_message->session;
942         _delete_http_message(http_message);
943         if (session->msg != NULL)
944                 session->msg = NULL;
945 #endif
946
947         _EXTERN_FUNC_EXIT;
948
949         return res;
950 }
951
952 EXPORT_API int sync_agent_plugin_close_connection(void *session)
953 {
954         _EXTERN_FUNC_ENTER;
955
956 #ifdef time_check
957         /* function Start Time */
958         clock_t start_t, end_t;
959         double proc_t = 0.0;
960         start_t = clock();
961 #endif
962
963         int res = 1;
964
965 #ifdef USING_LIBSOUP
966         SoupSession *ss = (SoupSession *) session;
967
968         _DEBUG_INFO("[na_http_plugIn] session : %d", session);
969
970         auth_info_s *auth_info = NULL;
971         res = _find_auth_info(ss, &auth_info);
972         if (res == 0) {
973                 _DEBUG_INFO("[na_http_plugIn] auth_info is NULL !!");
974
975                 /* soup_session_cleanup_connections(ss, TRUE); */
976                 soup_session_abort(ss);
977                 _DEBUG_INFO("[na_http_plugIn] session cleanup connections !!");
978
979                 res = 1;
980         } else if (res == 1) {
981                 _DEBUG_INFO("[na_http_plugIn] fine_auth_info() is success !!");
982
983                 /* soup_session_cleanup_connections(ss, TRUE); */
984                 soup_session_abort(ss);
985                 _DEBUG_INFO("[na_http_plugIn] session cleanup connections !!");
986
987                 if (auth_info != NULL) {
988                         auth_info_list = g_list_remove(auth_info_list, auth_info);
989
990                         if (auth_info->id != NULL)
991                                 free(auth_info->id);
992                         if (auth_info->password != NULL)
993                                 free(auth_info->password);
994                         free(auth_info);
995
996                         _DEBUG_INFO("[na_http_plugIn] remove auth_info success !!");
997                 }
998         } else {                /* res  == -1 */
999                 _DEBUG_INFO("[na_http_plugIn] auth_info_list is NULL !!");
1000
1001                 /* soup_session_cleanup_connections(ss, TRUE); */
1002                 soup_session_abort(ss);
1003                 _DEBUG_INFO("[na_http_plugIn] session cleanup connections !!");
1004
1005                 res = 1;
1006         }
1007 #else
1008         curl_session_s *curl_session = (curl_session_s *) session;
1009         CURL *curl = curl_session->session;
1010         curl_easy_cleanup(curl);
1011
1012         if (curl_session->msg != NULL) {
1013                 _delete_http_message(curl_session->msg);
1014                 curl_session->msg = NULL;
1015         }
1016         free(curl_session);
1017
1018 #endif
1019
1020 #ifdef time_check
1021         /* function End Time */
1022         end_t = clock();
1023         proc_t = ((double)(end_t - start_t)) / CLOCKS_PER_SEC;
1024         _DEBUG_INFO("[na_http_plugIn] execute time : %0.2f\n", proc_t);
1025 #endif
1026
1027         _EXTERN_FUNC_EXIT;
1028
1029         return res;
1030 }
1031
1032 EXPORT_API int sync_agent_plugin_cancel_message(void *session)
1033 {
1034         _EXTERN_FUNC_ENTER;
1035
1036 #ifdef time_check
1037         /* function Start Time */
1038         clock_t start_t, end_t;
1039         double proc_t = 0.0;
1040         start_t = clock();
1041 #endif
1042
1043         int res = 1;
1044
1045 #ifdef USING_LIBSOUP
1046         SoupSession *ss = (SoupSession *) session;
1047         _DEBUG_INFO("[na_http_plugIn] session : %d", session);
1048
1049         auth_info_s *auth_info = NULL;
1050         /* SoupMessage *cancel_msg = (SoupMessage*)msg; */
1051
1052         /* if ((ss != NULL) && (cancel_msg != NULL) && (cancel_msg->status_code != SOUP_STATUS_OK && cancel_msg->status_code != SOUP_STATUS_CANCELLED)) {
1053            soup_session_cancel_message(ss, cancel_msg, SOUP_STATUS_CANCELLED);
1054            _DEBUG_INFO("[na_http_plugIn] cancel message !!\n");
1055            } */
1056
1057         res = _find_auth_info(ss, &auth_info);
1058         if (res == 0) {
1059                 _DEBUG_INFO("[na_http_plugIn] auth_info is NULL !!");
1060                 soup_session_abort(ss);
1061                 _DEBUG_INFO("[na_http_plugIn] session abort !! \n");
1062
1063                 res = 1;
1064         } else if (res == 1) {
1065                 _DEBUG_INFO("[na_http_plugIn] fine_auth_info() is success !!");
1066
1067                 /* cancel all pending requests & disconnect connection */
1068                 soup_session_abort(ss);
1069                 _DEBUG_INFO("[na_http_plugIn] session abort !! \n");
1070
1071                 if (auth_info != NULL) {
1072                         auth_info_list = g_list_remove(auth_info_list, auth_info);
1073
1074                         if (auth_info->id != NULL)
1075                                 free(auth_info->id);
1076                         if (auth_info->password != NULL)
1077                                 free(auth_info->password);
1078                         free(auth_info);
1079
1080                         _DEBUG_INFO("[na_http_plugIn] remove auth_info success !!");
1081                 }
1082         } else {                /* res  == -1 */
1083                 _DEBUG_INFO("[na_http_plugIn] auth_info_list is NULL !!");
1084
1085                 /* cancel all pending requests & disconnect connection */
1086                 soup_session_abort(ss);
1087                 _DEBUG_INFO("[na_http_plugIn] session abort !! \n");
1088
1089                 res = 1;
1090         }
1091 #else
1092         curl_session_s *curl_session = (curl_session_s *) session;
1093         _curl_session_abort(curl_session);
1094 #endif
1095
1096 #ifdef time_check
1097         /* function End Time */
1098         end_t = clock();
1099         proc_t = ((double)(end_t - start_t)) / CLOCKS_PER_SEC;
1100         _DEBUG_INFO("[na_http_plugIn] execute time : %0.2f\n", proc_t);
1101 #endif
1102
1103         _EXTERN_FUNC_EXIT;
1104
1105         return res;
1106 }
1107
1108 EXPORT_API int sync_agent_plugin_get_header_info(GList * header_info, char *key, char **value)
1109 {
1110         _EXTERN_FUNC_ENTER;
1111
1112         retvm_if(header_info == NULL, 0, "header_info is NULL. FAIL !!!");
1113         retvm_if(key == NULL, 0, "key is NULL. FAIL !!!");
1114
1115         int res = 1;
1116
1117         GList *iter = NULL;
1118         common_header_info_s *iter_data;
1119         *value = NULL;
1120         int value_len = 0;
1121
1122         if (header_info == NULL) {
1123                 _DEBUG_ERROR("[na_http_plugIn] Error !! ( not exist header information )\n");
1124                 res = 0;
1125                 return res;
1126         }
1127
1128         for (iter = header_info; iter != NULL; iter = g_list_next(iter)) {
1129                 iter_data = NULL;
1130                 iter_data = (common_header_info_s *) (iter->data);
1131                 if (iter_data->key != NULL) {
1132                         if (!strcmp(iter_data->key, key)) {
1133                                 if (iter_data->value != NULL) {
1134                                         /* if (*value == NULL) { *//* first 'key - value' pair */
1135                                         if (value_len == 0) {   /* first 'key - value' pair */
1136                                                 *value = (char *)malloc(strlen(iter_data->value) + NULL_LEN + SEMI_COLON_LEN);
1137                                                 if (*value == NULL) {
1138                                                         _DEBUG_ERROR("[na_http_plugIn] malloc error !!");
1139                                                         res = 0;
1140                                                         return res;
1141                                                 }
1142
1143                                                 memset(*value, 0x00, strlen(iter_data->value) + NULL_LEN + SEMI_COLON_LEN);
1144                                                 memcpy(*value, iter_data->value, strlen(iter_data->value));
1145                                                 _DEBUG_INFO("[na_http_plugIn] key : %s, value : %s ( %d )", iter_data->key, *value, strlen(*value));
1146
1147                                                 value_len += strlen(*value);
1148                                         } else {        /* after first 'key - value' pair */
1149                                                 int len = strlen(iter_data->value);
1150                                                 _DEBUG_INFO("value = %s, len = %d", iter_data->value, len);
1151                                                 if (len != 0) {
1152                                                         value_len += (len + NULL_LEN + SEMI_COLON_LEN);
1153                                                         *value = (char *)realloc(*value, value_len);
1154                                                         if (*value == NULL) {
1155                                                                 _DEBUG_ERROR("[na_http_plugIn] realloc error !!");
1156                                                                 res = 0;
1157                                                                 return res;
1158                                                         }
1159                                                         int strcat_check_len = 0;
1160
1161                                                         strcat_check_len = g_strlcat(*value, ";", value_len);
1162                                                         strcat_check_len = g_strlcat(*value, iter_data->value, value_len);
1163
1164                                                         if (strcat_check_len >= value_len) {
1165                                                                 _DEBUG_ERROR("[na_http_plugIn] *value buffer overflow !!");
1166                                                                 res = 0;
1167                                                                 return res;
1168                                                         }
1169                                                         _DEBUG_INFO("[na_http_plugIn] key : %s, value : %s ( %d )", iter_data->key, *value, strlen(*value));
1170                                                 } else {
1171                                                         /*do nothing */
1172                                                 }
1173                                         }
1174                                 } else {
1175                                         _DEBUG_ERROR("[na_http_plugIn] value is NULL !! \n");
1176                                         res = 0;
1177                                         return res;
1178                                 }
1179                         }
1180                 } else {
1181                         _DEBUG_ERROR("[na_http_plugIn] key is NULL !! \n");
1182                         res = 0;
1183                         return res;
1184                 }
1185         }
1186
1187         _EXTERN_FUNC_EXIT;
1188
1189         return res;
1190 }
1191
1192 EXPORT_API int sync_agent_plugin_set_data_download_info(void *http_info, char *current_download_range)
1193 {
1194         _EXTERN_FUNC_ENTER;
1195
1196         retvm_if(http_info == NULL, 0, "http_info is NULL. FAIL !!!");
1197         retvm_if(current_download_range == NULL, 0, "current_download_range is NULL. FAIL !!!");
1198
1199         int ret = 1;
1200
1201         GList *iter = 0;
1202         for (iter = (GList *) http_info; iter != NULL; iter = g_list_next(iter)) {
1203
1204                 if (((common_header_info_s *) (iter->data))->key != NULL && !strcmp(((common_header_info_s *) (iter->data))->key, "Range")) {
1205
1206                         char *value = ((common_header_info_s *) (iter->data))->value;
1207                         if (value != NULL) {
1208                                 free(value);
1209
1210                                 ((common_header_info_s *) (iter->data))->value = g_strdup_printf("bytes=%s", current_download_range);
1211                                 _DEBUG_INFO("[After] key : %s, value : %s\n", ((common_header_info_s *) (iter->data))->key, ((common_header_info_s *) (iter->data))->value);
1212                                 break;
1213                         } else {
1214                                 _DEBUG_ERROR("[na_http_plugIn] value is NULL !! \n");
1215                                 ret = 0;
1216                                 return ret;
1217                         }
1218                 }
1219         }
1220
1221         _DEBUG_INFO("[na_http_plugIn] end");
1222
1223         _EXTERN_FUNC_EXIT;
1224
1225         return ret;
1226 }
1227
1228 EXPORT_API int sync_agent_plugin_get_data_download_info(void *http_req_info, void *http_info, int *total_doanload_size, char **current_download_range, char **download_file_name)
1229 {
1230         _EXTERN_FUNC_ENTER;
1231
1232         retvm_if(http_req_info == NULL, 0, "http_req_info is NULL. FAIL !!!");
1233         retvm_if(http_info == NULL, 0, "http_info is NULL. FAIL !!!");
1234
1235         int ret = 1;
1236
1237         /* Get_Header_Info(http_info, "Content-Disposition", download_file_name);
1238            if (*download_file_name == NULL) {
1239            _DEBUG_INFO("[na_http_plugIn] download_file_name == 0");
1240            return 0;
1241            } else {
1242            _DEBUG_INFO("[na_http_plugIn]  download_file_name = %s\n", *download_file_name);
1243            }
1244
1245            char *content_range_value = 0;
1246            Get_Header_Info(http_info, "Content-Range", &content_range_value);
1247            if (content_range_value == NULL) {
1248            _DEBUG_INFO("[na_http_plugIn] content_range_value == 0");
1249            return 0;
1250            } else {
1251            _DEBUG_INFO("[na_http_plugIn] content range value = %s\n", content_range_value);
1252            } */
1253
1254         /* pasing file name */
1255         char *temp_file_name = 0;       /* strdup("attachment; fileName=\"FW-20110901-13121.bin\""); */
1256         sync_agent_plugin_get_header_info((GList *) http_info, "Content-Disposition", &temp_file_name);
1257         _DEBUG_INFO("temp_file_name = %s\n", temp_file_name);
1258         if (temp_file_name != NULL) {
1259                 char *ptr1 = strstr(temp_file_name, "attachment;");
1260                 if (ptr1 != NULL) {
1261                         ptr1 = strstr(ptr1, "fileName=");
1262                         if (ptr1 != NULL) {
1263
1264                                 char *temp = strdup(ptr1);
1265
1266                                 char *del = "\"";
1267                                 char *temp_ptr = strtok(temp, del);
1268                                 _DEBUG_INFO("1st token = %s\n", temp_ptr);
1269
1270                                 temp_ptr = strtok(NULL, del);
1271                                 _DEBUG_INFO("2nd token = %s\n", temp_ptr);
1272
1273                                 *download_file_name = strdup(temp_ptr);
1274                                 _DEBUG_INFO("*download_file_name = %s\n", *download_file_name);
1275
1276                                 if (temp != NULL)
1277                                         free(temp);
1278                         }
1279                 }
1280         } else {
1281                 char *result_name = NULL;
1282
1283                 sync_agent_plugin_get_header_info((GList *) http_req_info, "uri", &temp_file_name);
1284                 _DEBUG_INFO("temp_file_name = %s\n", temp_file_name);
1285
1286                 result_name = strrchr(temp_file_name, '/');
1287                 _DEBUG_INFO("result_file name : %s", result_name);
1288
1289                 if (result_name != NULL) {
1290                         ++result_name;
1291                         _DEBUG_INFO("remove '/' result_file name : %s", result_name);
1292                 }
1293
1294                 *download_file_name = strdup(result_name);
1295                 _DEBUG_INFO("*download_file_name = %s\n", *download_file_name);
1296
1297         }
1298         /* parsing data range info */
1299         char *temp_range_value = 0;     /* strdup("bytes 0-66303/3192624"); */
1300         sync_agent_plugin_get_header_info((GList *) http_info, "Content-Range", &temp_range_value);
1301         char *temp = strdup(temp_range_value + strlen("bytes "));
1302         _DEBUG_INFO("temp_range = %s\n", temp);
1303
1304         char *del2 = "/";
1305         char *ptr2 = strtok(temp, del2);
1306         if (ptr2 != NULL) {
1307                 _DEBUG_INFO("[na_http_plugIn] range = %s\n", ptr2);
1308                 *current_download_range = strdup(ptr2);
1309
1310                 ptr2 = strtok(NULL, del2);
1311                 _DEBUG_INFO("[na_http_plugIn] total = %s\n", ptr2);
1312                 *total_doanload_size = atoi(ptr2);
1313         }
1314 //      if (temp_file_name != NULL)
1315         free(temp_file_name);
1316         if (temp_range_value != NULL)
1317                 free(temp_range_value);
1318         if (temp != NULL)
1319                 free(temp);
1320
1321         _DEBUG_INFO("[na_http_plugIn] end");
1322
1323         _EXTERN_FUNC_EXIT;
1324
1325         return ret;
1326 }
1327
1328 EXPORT_API int sync_agent_plugin_add_authentication_info(void *session, char *id, char *password)
1329 {
1330         _EXTERN_FUNC_ENTER;
1331
1332         retvm_if(id == NULL, 0, "id is NULL. FAIL !!!");
1333         retvm_if(password == NULL, 0, "password is NULL. FAIL !!!");
1334
1335         int res = 1;
1336
1337 #ifdef USING_LIBSOUP
1338         SoupSession *ss = (SoupSession *) session;
1339
1340         res = _add_auth_info(ss, id, password);
1341 #else
1342         CURL *curl = ((curl_session_s *) session)->session;
1343
1344         char *userpwd;
1345         int id_len, pw_len, userpwd_len;
1346
1347         id_len = strlen(id);
1348         pw_len = strlen(password);
1349
1350         userpwd_len = id_len + pw_len + 2;
1351         userpwd = (char *)malloc(userpwd_len);
1352         if (userpwd != NULL) {
1353                 snprintf(userpwd, userpwd_len, "%s:%s", id, password);
1354         } else {
1355                 _DEBUG_ERROR("[na_http_plugIn] userpwd malloc failed !!");
1356                 res = 0;
1357                 return res;
1358         }
1359
1360         curl_easy_setopt(curl, CURLOPT_USERPWD, userpwd);
1361
1362         if (userpwd != NULL)
1363                 free(userpwd);
1364 #endif
1365         if (res != 1) {
1366                 _DEBUG_ERROR("[na_http_plugIn] _add_auth_info() is fail !!");
1367                 return res;
1368         } else {
1369                 _DEBUG_INFO("[na_http_plugIn] _add_auth_info() is success !!");
1370                 /* register user authentication callback (for EAS) */
1371 #ifdef USING_LIBSOUP
1372                 g_signal_connect(ss, "authenticate", G_CALLBACK(authenticate_cb), NULL);
1373 #endif
1374         }
1375
1376         _EXTERN_FUNC_EXIT;
1377
1378         return res;
1379 }
1380
1381 EXPORT_API int sync_agent_plugin_set_property(void *session, sync_agent_na_property_e property, va_list va)
1382 {
1383         _EXTERN_FUNC_ENTER;
1384
1385         int ret = 1;
1386         CURL *curl = ((curl_session_s *) session)->session;
1387         if (curl == NULL)
1388                 return 0;
1389
1390         switch (property) {
1391         case SYNC_AGENT_NA_PROP_TIMEOUT:{
1392                         int timeout = va_arg(va, long);
1393                         curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, timeout);
1394                 }
1395                 break;
1396         default:
1397                 ret = 0;
1398                 break;
1399         }
1400
1401         _EXTERN_FUNC_EXIT;
1402
1403         return ret;
1404 }
1405
1406 EXPORT_API int sync_agent_plugin_get_status(void *session, sync_agent_na_status_e status, va_list va)
1407 {
1408         _EXTERN_FUNC_ENTER;
1409
1410         int ret = 1;
1411         CURL *curl = ((curl_session_s *) session)->session;
1412         if (curl == NULL)
1413                 return 0;
1414
1415         switch (status) {
1416         case SYNC_AGENT_NA_STATUS_ELAPSED_TIME:{
1417                         double *arg = va_arg(va, double *);
1418                         curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, arg);
1419                 }
1420                 break;
1421         case SYNC_AGENT_NA_STATUS_RESPONSE_CODE:{
1422                         long *arg = va_arg(va, long *);
1423                         curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, arg);
1424                 }
1425                 break;
1426         default:
1427                 ret = 0;
1428                 break;
1429         }
1430
1431         _EXTERN_FUNC_EXIT;
1432
1433         return ret;
1434 }
1435
1436 #ifdef USING_LIBSOUP
1437 static int _add_auth_info(SoupSession * session, char *user_id, char *user_pw)
1438 {
1439         int res = 1;
1440
1441         auth_info_s *auth_info;
1442
1443         /* memory alloc - auth_info  */
1444         auth_info = (auth_info_s *) calloc(1, sizeof(auth_info_s));
1445         if (auth_info == NULL) {
1446                 _DEBUG_ERROR("[na_http_plugIn] auth_info calloc fail !!");
1447                 return 0;
1448         }
1449         _DEBUG_TRACE("[na_http_plugIn] auth_info calloc success !!");
1450
1451         auth_info->session = (void *)calloc(1, sizeof(auth_info->session));
1452         if (auth_info->session == NULL) {
1453                 _DEBUG_ERROR("CALLOC failed !!!");
1454                 return 0;
1455         }
1456         auth_info->session = session;
1457         _DEBUG_TRACE("[na_http_plugIn] auth_info : sessoin ( %d )", auth_info->session);
1458         auth_info->id = strdup(user_id);
1459         _DEBUG_TRACE("[na_http_plugIn] auth_info : id ( %s )", auth_info->id);
1460         auth_info->password = strdup(user_pw);
1461         _DEBUG_TRACE("[na_http_plugIn] auth_info : password ( %s )", auth_info->password);
1462
1463         /* append auth_info to auth_info_list */
1464         auth_info_list = g_list_append(auth_info_list, auth_info);
1465         _DEBUG_TRACE("[na_http_plugIn] append auth_info");
1466
1467         return res;
1468 }
1469
1470 /*static int remove_auth_info(SoupSession *session)
1471 {
1472         int res = 1;
1473         auth_info_s *auth_info = NULL;
1474
1475         res = _find_auth_info(session, &auth_info);
1476         if (res == 0) {
1477                 _DEBUG_ERROR("[na_http_plugIn] _find_auth_info() is fail !!");
1478                 res = 0;
1479                 return res;
1480         } else if (res == 1) {
1481                 _DEBUG_INFO("[na_http_plugIn] fine_auth_info() is success !!");
1482
1483                 if (auth_info->id != NULL)
1484                         free(auth_info->id);
1485
1486                 if (auth_info->password != NULL)
1487                         free(auth_info->password);
1488
1489                 if (auth_info != NULL)
1490                         free(auth_info);
1491         }
1492
1493         return res;
1494 }*/
1495
1496 static int _find_auth_info(SoupSession * session, auth_info_s ** auth_info)
1497 {
1498         GList *iter = NULL;
1499         auth_info_s *iter_data;
1500
1501         int res = 1;
1502
1503         if (auth_info_list != NULL) {
1504                 /* find auth_info for session */
1505                 for (iter = auth_info_list; iter != NULL; iter = g_list_next(iter)) {
1506                         iter_data = NULL;
1507                         if (((auth_info_s *) (iter->data))->session != NULL) {
1508                                 if (((auth_info_s *) (iter->data))->session == session) {
1509                                         iter_data = (auth_info_s *) (iter->data);
1510                                         _DEBUG_TRACE("[na_http_plugIn] find session : %d", session);
1511                                         break;
1512                                 }
1513                         }
1514                 }
1515         } else {
1516                 _DEBUG_ERROR("[na_http_plugIn] auth_info_list is NULL !!");
1517                 res = -1;
1518                 return res;
1519         }
1520
1521         if (iter_data != NULL) {
1522                 *auth_info = (auth_info_s *) iter_data;
1523         } else {
1524                 _DEBUG_ERROR("[na_http_plugIn] iter_data is NULL !!");
1525                 res = 0;
1526                 return res;
1527         }
1528
1529         return res;
1530 }
1531
1532 static void authenticate_cb(SoupSession * session, SoupMessage * msg, SoupAuth * auth, gboolean retrying, gpointer user_data)
1533 {
1534         int err = 1;
1535         auth_info_s *auth_info = NULL;
1536
1537         if (!retrying) {
1538                 err = _find_auth_info(session, &auth_info);
1539                 if (err == 0) {
1540                         _DEBUG_ERROR("[na_http_plugIn] _find_auth_info() is fail !!");
1541                         /* todo : error handling */
1542                 } else if (err == 1) {
1543                         _DEBUG_INFO("[na_http_plugIn] _find_auth_info() is success !!");
1544                         /* first authentication */
1545                         if (msg->status_code == SOUP_STATUS_UNAUTHORIZED) {
1546                                 if ((auth_info->id != NULL) && (auth_info->password != NULL))
1547                                         soup_auth_authenticate(auth, auth_info->id, auth_info->password);
1548                         }
1549                         /* not implement - proxy authentication */
1550                         /* else if (msg->status_code == SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED) {
1551                            if (((auth_info_s*)(iter->data))->proxy_id && ((auth_info_s*)(iter->data))->proxy_password)
1552                            soup_auth_authenticate(auth, ((auth_info_s*)(iter->data))->proxy_id, ((auth_info_s*)(iter->data))->proxy_password);
1553                            } */
1554                 } else {        /* err == -1 */
1555                         _DEBUG_INFO("[na_http_plugIn] auth_info_list is NULL !!");
1556                 }
1557         } else {
1558                 /* retry */
1559                 _DEBUG_INFO("[na_http_plugIn] authentication Retry !!");
1560         }
1561
1562 }
1563 #else
1564
1565 static http_buffer_s *__create_http_buffer(int block_size)
1566 {
1567         _INNER_FUNC_ENTER;
1568
1569         http_buffer_s *buff = (http_buffer_s *) calloc(1, sizeof(http_buffer_s));
1570         if (buff == NULL) {
1571                 _DEBUG_ERROR("CALLOC failed !!!");
1572                 return NULL;
1573         }
1574         buff->block_size = block_size;
1575
1576         _INNER_FUNC_EXIT;
1577
1578         return buff;
1579 }
1580
1581 static int __delete_http_buffer(http_buffer_s * buff)
1582 {
1583         _INNER_FUNC_ENTER;
1584
1585         if (buff->buff != NULL) {
1586                 free(buff->buff);
1587         }
1588         free(buff);
1589
1590         _INNER_FUNC_EXIT;
1591
1592         return 0;
1593 }
1594
1595 static size_t write_http_buffer_cb(void *ptr, size_t size, size_t nmemb, void *userdata)
1596 {
1597         _EXTERN_FUNC_ENTER;
1598
1599         http_buffer_s *buff = (http_buffer_s *) userdata;
1600         int len = size * nmemb;
1601         int written_len = buff->length;
1602         int block_size = buff->block_size;
1603         int allocated_block = (written_len + (block_size - 1)) / block_size;
1604
1605         if (written_len + len > allocated_block * block_size) {
1606                 allocated_block = (written_len + len + (block_size - 1)) / block_size;
1607                 buff->buff = realloc(buff->buff, allocated_block * block_size);
1608                 if (buff->buff == NULL) {
1609                         return 0;
1610                 }
1611         }
1612         memcpy(&buff->buff[written_len], ptr, len);
1613         buff->length += len;
1614
1615         _EXTERN_FUNC_EXIT;
1616
1617         return len;
1618 }
1619
1620 #ifdef CBA
1621 static http_message_s *_create_http_message(libcurl_http_method_e method, char *uri, char *accept_encoding, int is_cert)
1622 #else
1623 static http_message_s *_create_http_message(libcurl_http_method_e method, char *uri, char *accept_encoding)
1624 #endif
1625 {
1626         _INNER_FUNC_ENTER;
1627
1628         http_message_s *msg = (http_message_s *) calloc(1, sizeof(http_message_s));
1629         if (msg == NULL) {
1630                 return NULL;
1631         } else {
1632                 memset(msg, 0, sizeof(http_message_s));
1633         }
1634
1635         msg->method = method;
1636         msg->uri = uri ? strdup(uri) : NULL;
1637         msg->accept_encoding = accept_encoding ? strdup(accept_encoding) : NULL;
1638         msg->response_header = __create_http_buffer(HEADER_BLOCK_SIZE);
1639         msg->response_body = __create_http_buffer(CONTENT_BLOCK_SIZE);
1640 #ifdef CBA
1641         if (is_cert != 0){
1642                 msg->cert_info = (certificate_info_s *) calloc(1, sizeof(certificate_info_s));
1643                 if (msg->cert_info == NULL) {
1644                         _DEBUG_ERROR("CALLOC failed !!!");
1645                         return NULL;
1646                 } else {
1647                         memset(msg->cert_info, 0, sizeof(certificate_info_s));
1648                 }
1649         } else {
1650                 msg->cert_info = NULL;
1651         }
1652 #endif
1653
1654         _INNER_FUNC_EXIT;
1655
1656         return msg;
1657 }
1658
1659 static int _add_http_header(http_message_s * msg, char *key, char *value)
1660 {
1661         _INNER_FUNC_ENTER;
1662
1663         retvm_if(key == NULL, 0, "key is NULL. FAIL !!!");
1664         retvm_if(value == NULL, 0, "value is NULL. FAIL !!!");
1665
1666         char *key_pair;
1667         int key_len, val_len, key_pair_len;
1668
1669         key_len = strlen(key);
1670         val_len = strlen(value);
1671
1672         key_pair_len = key_len + val_len + 2;
1673         key_pair = (char *)malloc(key_pair_len);
1674         if (key_pair == NULL) {
1675                 _DEBUG_ERROR("[na_http_plugIn] authentication Retry !!");
1676                 return 0;
1677         }
1678
1679         snprintf(key_pair, key_pair_len, "%s:%s", key, value);
1680
1681         msg->send_header = curl_slist_append(msg->send_header, key_pair);
1682         free(key_pair);
1683
1684         _INNER_FUNC_EXIT;
1685
1686         return 1;
1687 }
1688
1689 static int _delete_http_message(http_message_s * msg)
1690 {
1691         _INNER_FUNC_ENTER;
1692
1693         retvm_if(msg == NULL, 0, "msg is NULL. FAIL !!!");
1694
1695         if (msg->uri != NULL) {
1696                 free(msg->uri);
1697         }
1698         if (msg->accept_encoding != NULL) {
1699                 free(msg->accept_encoding);
1700         }
1701         if (msg->send_header != NULL) {
1702                 curl_slist_free_all(msg->send_header);
1703         }
1704         if (msg->response_header != NULL) {
1705                 __delete_http_buffer(msg->response_header);
1706                 msg->response_header = 0;
1707         }
1708         if (msg->response_body != NULL) {
1709                 __delete_http_buffer(msg->response_body);
1710                 msg->response_body = 0;
1711         }
1712         free(msg);
1713
1714         _INNER_FUNC_EXIT;
1715
1716         return 1;
1717 }
1718
1719 static int curl_progress_cb(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
1720 {
1721         _EXTERN_FUNC_ENTER;
1722
1723         retvm_if(clientp == NULL, 0, "clientp is NULL. FAIL !!!");
1724
1725         curl_session_s *session = (curl_session_s *) clientp;
1726         if (session->msg != NULL) {
1727                 if (session->msg->abort != 0) {
1728                         _EXTERN_FUNC_EXIT;
1729                         return 1;
1730                 }
1731         }
1732
1733         _EXTERN_FUNC_EXIT;
1734         return 0;
1735 }
1736
1737 static int _curl_session_abort(curl_session_s * session)
1738 {
1739         _INNER_FUNC_ENTER;
1740
1741         retvm_if(session == NULL, 0, "session is NULL. FAIL !!!");
1742
1743         if (session->msg != NULL) {
1744                 session->msg->abort = 1;
1745         }
1746
1747         _INNER_FUNC_EXIT;
1748
1749         return 1;
1750 }
1751
1752 static common_header_info_s *__create_header_info(char *key, char *value)
1753 {
1754         _INNER_FUNC_ENTER;
1755
1756         retvm_if(key == NULL, NULL, "key is NULL. FAIL !!!");
1757         retvm_if(value == NULL, NULL, "value is NULL. FAIL !!!");
1758
1759         common_header_info_s *header_info = NULL;
1760         header_info = (common_header_info_s *) calloc(1, sizeof(common_header_info_s));
1761         if (header_info == NULL) {
1762                 return NULL;
1763         }
1764         header_info->key = strdup(key);
1765         header_info->value = strdup(value);
1766
1767         _INNER_FUNC_EXIT;
1768
1769         return header_info;
1770 }
1771
1772 static int _parse_http_header(http_buffer_s * header, GList ** header_list)
1773 {
1774         _INNER_FUNC_ENTER;
1775
1776         retvm_if(header == NULL, 0, "header is NULL. FAIL !!!");
1777
1778         common_header_info_s *header_info = NULL;
1779
1780         int state = 0;
1781         int ret = 1;
1782         char *value = NULL;
1783         char *buff = malloc(header->length + 1);
1784         if (buff == NULL) {
1785                 _DEBUG_ERROR("MALLOC failed !!!");
1786                 return 0;
1787         }
1788         char *tmp = buff;
1789         char ch;
1790
1791         char *key = NULL;
1792         *header_list = NULL;
1793
1794         memcpy(buff, header->buff, header->length);
1795         buff[header->length] = 0;
1796
1797         while (*tmp) {
1798                 ch = *tmp;
1799                 if (ch == '\r' || ch == '\n') {
1800                         *tmp = 0;
1801                         if ((key != NULL) && (state == 100)) {
1802                                 header_info = __create_header_info(key, value ? value : "");
1803                                 *header_list = g_list_append(*header_list, header_info);
1804                         }
1805                         state = 0;
1806                         key = NULL;
1807                         value = NULL;
1808                         tmp++;
1809                         continue;
1810                 }
1811                 switch (state) {
1812                 case 0:
1813                         if (isspace(ch) && (key == NULL)) {
1814                                 *tmp = 0;
1815                         } else {
1816                                 if (key == NULL) {
1817                                         key = tmp;
1818                                 }
1819                                 if (ch == ':') {
1820                                         *tmp = 0;
1821                                         state = 100;
1822                                 }
1823                         }
1824
1825                         break;
1826                 case 100:
1827                         if (isspace(ch) && (value == NULL)) {
1828                                 *tmp = 0;
1829                         } else {
1830                                 if (value == NULL) {
1831                                         value = tmp;
1832                                 }
1833                                 if (ch == ';') {
1834                                         *tmp = 0;
1835                                         if (key != NULL) {
1836                                                 header_info = __create_header_info(key, value);
1837                                                 *header_list = g_list_append(*header_list, header_info);
1838                                                 value = NULL;
1839                                         }
1840                                 }
1841                         }
1842                         break;
1843                 }
1844                 tmp++;
1845         }
1846
1847         free(buff);
1848
1849         _INNER_FUNC_EXIT;
1850
1851         return ret;
1852 }
1853
1854 #ifdef CBA
1855 static void _add_certificate_option(CURL * curl, http_message_s * msg)
1856 {
1857         _INNER_FUNC_ENTER;
1858
1859         retm_if(msg == NULL, "msg is NULL. FAIL !!!");
1860
1861         if (msg->cert_info->accept_all_certs != 1)
1862                 curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, ssl_context_cb);
1863
1864         curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
1865         curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2);
1866
1867         curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, "PEM");
1868         curl_easy_setopt(curl, CURLOPT_SSLCERT, msg->cert_info->certificate_path);
1869         curl_easy_setopt(curl, CURLOPT_KEYPASSWD, msg->cert_info->privatekey_password);
1870
1871         curl_easy_setopt(curl, CURLOPT_SSLKEYTYPE, "PEM");
1872         curl_easy_setopt(curl, CURLOPT_SSLKEY, msg->cert_info->privatekey);
1873
1874         /* set the file with the certs vaildating the server */
1875         //curl_easy_setopt(session->curl,CURLOPT_CAINFO,pServerCert);
1876         curl_easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, TRUE);
1877
1878         _INNER_FUNC_EXIT;
1879 }
1880
1881 //static CURLcode ssl_context_cb(CURL * curl, SSL_CTX * sslctx, void *param)
1882 static CURLcode ssl_context_cb(CURL * curl, void * sslctx, void *param)
1883 {
1884         _EXTERN_FUNC_ENTER;
1885
1886         SSL_CTX_set_verify((SSL_CTX *)sslctx, SSL_VERIFY_PEER, verify_peer_cb);
1887
1888         _EXTERN_FUNC_EXIT;
1889         return CURLE_OK;
1890 }
1891
1892 static int verify_peer_cb(int preverify_ok, X509_STORE_CTX * x509_ctx)
1893 {
1894         _EXTERN_FUNC_ENTER;
1895
1896         int retVal = 1;
1897
1898         _DEBUG_INFO("[na_http_plugIn] Read Peer certificates from SSL context !!");
1899         X509 *cert = X509_STORE_CTX_get_current_cert(x509_ctx);
1900         if (cert == NULL) {
1901                 _DEBUG_ERROR("[na_http_plugIn] No cert info available in the Context !!");
1902                 retVal = 0;
1903                 goto return_part;
1904         }
1905
1906         int err = X509_STORE_CTX_get_error(x509_ctx);
1907 //    char cert_file_path[1024] = {0, };
1908 //    snprintf(cert_file_path, sizeof(cert_file_path), "%s/PeerCertificate_%u", "aaa",(int)g_thread_self());
1909 //    _DEBUG_INFO("[na_http_plugIn] Certificate Path : %s",cert_file_path);
1910 //
1911 //    FILE *fp = fopen(cert_file_path, "a");
1912 //    errno = 0;
1913 //    if (!fp) {
1914 //        _DEBUG_ERROR("[na_http_plugIn] Failed to open file : %s", strerror(errno));
1915 //        retVal = 0;
1916 //        goto return_part;
1917 //    }
1918
1919         if (preverify_ok) {
1920 //        fprintf(fp,"Certificate is OK\n");
1921                 _DEBUG_INFO("[na_http_plugIn] Certificate is OK !!");
1922         } else {
1923 //        fprintf(fp,"Certificate verification failed.Reason::%d\n",err);
1924                 _DEBUG_ERROR("[na_http_plugIn] Certificate verification failed ( err : %d ) !!", err);
1925                 retVal = 0;
1926         }
1927 //    X509_print_fp(fp,cert);
1928 //    fprintf(fp,"===========================================\n");
1929 //    if (fp != NULL) {
1930 //        fclose(fp);
1931 //        fp = NULL;
1932 //    }
1933
1934  return_part:
1935
1936         _EXTERN_FUNC_EXIT;
1937
1938         return retVal;
1939 }
1940 #endif
1941
1942 #endif
1943
1944 EXPORT_API void sync_agent_plugin_register_fw_main_loop_network_access(void *data)
1945 {
1946         _EXTERN_FUNC_ENTER;
1947
1948         _EXTERN_FUNC_EXIT;
1949
1950         return;
1951 }