merge with master
[platform/framework/web/download-provider.git] / agent / include / download-agent-utils.h
1 /*
2  * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef _Download_Agent_Utils_H
18 #define _Download_Agent_Utils_H
19
20 #include <time.h>
21 #include "download-agent-defs.h"
22 #include "download-agent-interface.h"
23 #include "download-agent-dl-mgr.h"
24
25 /* Todo : move these to mime-util.c */
26 #define MIME_DRM_MESSAGE        "application/vnd.oma.drm.message"
27 #define MIME_ODF                                "application/vnd.oasis.opendocument.formula"
28 #define MIME_OMA_DD                     "application/vnd.oma.dd+xml"
29 #define MIME_MIDP_JAR           "application/vnd.sun.j2me.java-archive"
30 #define MIME_MULTIPART_MESSAGE  "multipart/related"
31 #define MIME_TEXT_PLAIN                 "text/plain"
32
33 #define SAVE_FILE_BUFFERING_SIZE_50KB (50*1024)
34 #define SAVE_FILE_BUFFERING_SIZE_5MB (5*1024*1024)
35
36 #define DA_SLEEP(x) \
37         do \
38         { \
39                 struct timespec interval,remainder; \
40                 interval.tv_sec = (unsigned int)((x)/1000); \
41                 interval.tv_nsec = (((x)-(interval.tv_sec*1000))*1000000); \
42                 nanosleep(&interval,&remainder); \
43         } while(0)
44
45 typedef enum {
46         DA_STORAGE_PHONE,                       /*To Store in Phone memory*/
47         DA_STORAGE_MMC,                     /*To Store in MMC */
48         DA_STORAGE_SYSTEM                       /*To Store in both Phone and MMC*/
49 } da_storage_type_t;
50
51 typedef struct _da_storage_size_t {
52         unsigned long b_available;
53         unsigned long b_size;
54 } da_storage_size_t;
55
56 typedef enum {
57         DA_MIME_TYPE_NONE,
58         DA_MIME_TYPE_DRM1_MESSATE,
59         DA_MIME_TYPE_END
60 } da_mime_type_id_t;
61
62 void get_random_number(int *out_num);
63 da_result_t  get_available_dd_id(int *available_id);
64 da_result_t  get_extension_from_mime_type(char *mime_type, char **extension);
65 da_mime_type_id_t get_mime_type_id(char *content_type);
66 da_result_t  get_available_memory(da_storage_type_t storage_type, da_storage_size_t *avail_memory);
67 da_bool_t is_valid_url(const char *url, da_result_t *err_code);
68
69 int read_data_from_file(char *file, char**out_buffer);
70 da_result_t move_file(const char *from_path, const char *to_path);
71 void remove_file(const char *file_path);
72 char *_stristr(const char *long_str, const char *find_str);
73
74 #endif