4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
23 /******************************************************************************
24 * File : em-core-types.h
25 * Desc : defines data structures and macros
30 * 2011.04.05 : created
31 *****************************************************************************/
32 #ifndef __EM_CORE_TYPES_H__
33 #define __EM_CORE_TYPES_H__
36 #include "emf-types.h"
41 #endif /* __cplusplu */
43 #if !defined(EXPORT_API)
44 #define EXPORT_API __attribute__((visibility("default")))
47 /* ----------------------------------------------------------------------------- */
48 /* Feature definitions */
49 #define __FEATURE_USING_MY_ACCOUNT__
50 #define __FEATURE_BACKUP_ACCOUNT__
51 #define __FEATURE_MOVE_TO_OUTBOX_FIRST__
52 /* #define __FEATURE_PARTIAL_BODY_FOR_POP3__ */
53 /* #define __FEATURE_KEEP_CONNECTION__ */
54 #define __FEATURE_DRM__
55 #define __FEATURE_PARTIAL_BODY_DOWNLOAD__
56 #define __FEATURE_HEADER_OPTIMIZATION__
57 #define __FEATURE_SEND_OPTMIZATION__
58 #define __FEATURE_DOWNLOAD_BODY_ATTACHMENT_OPTIMIZATION__
59 #define __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
60 #define __FEATURE_SYNC_CLIENT_TO_SERVER__
61 #define __FEATURE_PROGRESS_IN_OUTBOX__
62 #define __FEATURE_AUTO_POLLING__
63 #define __FEATURE_DEBUG_LOG__
64 #define __FEATURE_USE_PTHREAD__
65 #define __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__
66 /* #define __FEATURE_USE_SHARED_MUTEX_FOR_PROTECTED_FUNC_CALL__ */
67 #define __FEATURE_SUPPORT_ACTIVE_SYNC__
69 #define __HEADER_OPTIMIZATION__ /* Will be removed */
70 #define __DOWNLOAD_BODY_ATTACHMENT_OPTIMIZATION__ /* Will be removed */
72 /* ----------------------------------------------------------------------------- */
75 #define NULL (char *)0
79 #define IMAP_2004_LOG 1
81 #define MAILBOX_COUNT 6
82 #define PARTIAL_DOWNLOAD_SIZE 1024
83 #define PARTIAL_BODY_SIZE_IN_BYTES 15360 /* Partial Body download - 15K */
84 #define NO_LIMITATION 0
85 #define MAX_MAILBOX_TYPE 100
86 #define EMF_SYNC_ALL_MAILBOX 1
87 #define EMF_ATTACHMENT_MAX_COUNT 512
88 #define DOWNLOAD_MAX_BUFFER_SIZE 8000
89 #define LOCAL_MAX_BUFFER_SIZE 1000000
90 #define IMAP_MAX_COMMAND_LENGTH 1000
91 #define DOWNLOAD_NOTI_INTERVAL_PERCENT 5 /* notify every 5% */
92 #define DOWNLOAD_NOTI_INTERVAL_SIZE 51200 /* notify every 50k */
93 #define MAX_PATH 4096 /* /usr/src/linux-2.4.20-8/include/linux/limits.h */
94 #define DATETIME_LENGTH 16
95 #define MAIL_ID_STRING_LENGTH 10
97 #define DIR_SEPERATOR "/"
99 #define DATA_PATH "/opt/data"
100 #define DB_PATH "/opt/dbspace"
101 #define EMAIL_SERVICE_DB_FILE_PATH "/opt/dbspace/.email-service.db"
103 #define VCONF_KEY_LAST_SYNC_TIME "db/email/last_sync_time"
104 #define VCONF_KEY_DEFAULT_SLOT_SIZE "db/email/slot_size"
105 #define VCONF_KEY_LATEST_MAIL_ID "db/email/latest_mail_id"
106 #define VCONF_KEY_DEFAULT_ACCOUNT_ID "db/email/defaultaccount"
107 #define VCONF_KEY_UNREAD_MAIL_COUNT "db/badge/com.samsung.email"
109 #define MIME_SUBTYPE_DRM_OBJECT "vnd.oma.drm.message"
110 #define MIME_SUBTYPE_DRM_RIGHTS "vnd.oma.drm.rights+xml"
111 #define MIME_SUBTYPE_DRM_DCF "vnd.oma.drm.dcf"
113 #define SHM_FILE_FOR_DB_LOCK "/.email_shm_db_lock"
115 #ifdef __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__
116 #define SHM_FILE_FOR_MAIL_ID_LOCK "/.email_shm_mail_id_lock"
117 #endif /* __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__ */
123 #define NULL_CHAR '\0'
124 #define TAB_STRING "\t"
125 #define CR_STRING "\r"
126 #define LF_STRING "\n"
127 #define CRLF_STRING "\r\n"
129 #define SYNC_STATUS_FINISHED 0 /* BIN 00000000 */
130 #define SYNC_STATUS_SYNCING 1 /* BIN 00000001 */
131 #define SYNC_STATUS_HAVE_NEW_MAILS 2 /* BIN 00000010 */
133 #define GRAB_TYPE_TEXT 1 /* retrieve text and attachment list */
134 #define GRAB_TYPE_ATTACHMENT 2 /* retrieve attachment */
136 #define SAVE_TYPE_SIZE 1 /* only get content size */
137 #define SAVE_TYPE_BUFFER 2 /* save content to buffer */
138 #define SAVE_TYPE_FILE 3 /* save content to temporary file */
140 #define FINISH_OFF_IF_CANCELED if (!em_core_check_thread_status()) { err = EMF_ERROR_CANCELLED; goto FINISH_OFF; }
141 #define CHECK_JOB_CANCELED() {if (!em_core_check_thread_status()) goto JOB_CANCEL; }
143 #define SNPRINTF(buff, size, format, args...) snprintf(buff, size, format, ##args)
144 #define SNPRINTF_OFFSET(base_buf, offset, base_size, format, args...) \
146 int _offset = offset;\
147 snprintf(base_buf + _offset, base_size - _offset - 1, format, ##args);\
150 #ifdef __FEATURE_USE_PTHREAD__
151 #define THREAD_CREATE(tv, func, param, err) { EM_DEBUG_LOG("THREAD_CREATE "#tv); err = pthread_create(&tv, NULL, func, param); }
152 #define THREAD_CREATE_JOINABLE(tv, func, err) { pthread_attr_t attr; EM_DEBUG_LOG("THREAD_CREATE_JOINABLE "#tv); \
153 pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);\
154 err = pthread_create(&tv, &attr, func, NULL); pthread_attr_destroy(&attr); }
155 #define THREAD_JOIN(tv) {EM_DEBUG_LOG("THREAD_JOIN "#tv); pthread_join(tv, NULL); }
156 #define THREAD_SELF() pthread_self()
157 #define THREAD_DETACH(tv) pthread_detach(tv)
158 #define INITIALIZE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("INITIALIZE_CRITICAL_SECTION "#cs); pthread_mutex_init(&cs, NULL); }
159 #define ENTER_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("ENTER_CRITICAL_SECTION "#cs); pthread_mutex_lock(&cs); }
160 #define TRY_ENTER_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("TRY_ENTER_CRITICAL_SECTION "#cs); pthread_mutex_trylock(&cs); }
161 #define LEAVE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("LEAVE_CRITICAL_SECTION "#cs); pthread_mutex_unlock(&cs); }
162 #define DELETE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("DELETE_CRITICAL_SECTION "#cs); pthread_mutex_destroy(&cs); }
164 #define INITIALIZE_CONDITION_VARIABLE(cv) {EM_DEBUG_LOG("INITIALIZE_CONDITION_VARIABLE "#cv); pthread_cond_init(&cv, NULL); }
165 #define SLEEP_CONDITION_VARIABLE(cv, cs) {EM_DEBUG_LOG("SLEEP_CONDITION_VARIABLE "#cv); pthread_cond_wait(&cv, &cs); }
166 #define WAKE_CONDITION_VARIABLE(cv) {EM_DEBUG_LOG("WAKE_CONDITION_VARIABLE "#cv); pthread_cond_signal(&cv); }
167 #define DELETE_CONDITION_VARIABLE(cv) {EM_DEBUG_LOG("DELETE_CONDITION_VARIABLE "#cv); pthread_cond_destroy(&cv); }
169 #define INITIALIZE_RECURSIVE_CRITICAL_SECTION(cs) { EM_DEBUG_LOG("INITIALIZE_RECURSIVE_CRITICAL_SECTION "#cs); \
170 if (cs == NULL) {pthread_mutex_lock(&_send_event_available_lock); pthread_mutexattr_t attr; cs = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));\
171 pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);\
172 pthread_mutex_init(cs, &attr);pthread_mutexattr_destroy(&attr); pthread_mutex_unlock(&_send_event_available_lock);}}
173 #define ENTER_RECURSIVE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("ENTER_RECURSIVE_CRITICAL_SECTION "#cs); if(cs) pthread_mutex_lock(cs);}
174 #define TRY_ENTER_RECURSIVE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("TRY_ENTER_RECURSIVE_CRITICAL_SECTION "#cs); if(cs) pthread_mutex_trylock(cs);}
175 #define LEAVE_RECURSIVE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("LEAVE_RECURSIVE_CRITICAL_SECTION "#cs); if(cs) pthread_mutex_unlock(cs);}
176 #define DELETE_RECURSIVE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("DELETE_RECURSIVE_CRITICAL_SECTION "#cs); if(cs) pthread_mutex_destroy(cs);}
177 typedef pthread_t thread_t;
178 #else /* __FEATURE_USE_PTHREAD__ */
179 #define THREAD_CREATE(tv, func, param, err) {EM_DEBUG_LOG("THREAD_CREATE "#tv); tv = g_thread_create(func, param, FALSE, NULL); if (tv == NULL) err = -1; else err = 0; }
180 #define THREAD_CREATE_JOINABLE(tv, func, err) {EM_DEBUG_LOG("THREAD_CREATE_JOINABLE "#tv); tv = g_thread_create(func, NULL, TRUE, NULL); if (tv == NULL) err = -1; else err = 0; }
181 #define THREAD_JOIN(tv) {EM_DEBUG_LOG("THREAD_JOIN "#tv); g_thread_join(tv); }
182 #define THREAD_SELF() g_thread_self()
183 #define INITIALIZE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("INITIALIZE_CRITICAL_SECTION "#cs); if (cs == NULL) cs = g_mutex_new(); }
184 #define ENTER_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("ENTER_CRITICAL_SECTION "#cs); if (cs) g_mutex_lock(cs); }
185 #define TRY_ENTER_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("TRY_ENTER_CRITICAL_SECTION "#cs); if (cs) g_mutex_trylock(cs); }
186 #define LEAVE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("LEAVE_CRITICAL_SECTION "#cs); if (cs) g_mutex_unlock(cs); }
187 #define DELETE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("DELETE_CRITICAL_SECTION "#cs); if (cs) g_mutex_free(cs); cs = NULL; }
189 #define INITIALIZE_CONDITION_VARIABLE(cv) {EM_DEBUG_LOG("INITIALIZE_CONDITION_VARIABLE "#cv); if (cv == NULL) cv = g_cond_new(); }
190 #define SLEEP_CONDITION_VARIABLE(cv, cs) {EM_DEBUG_LOG("SLEEP_CONDITION_VARIABLE "#cv); if (cv) g_cond_wait(cv, cs); }
191 #define WAKE_CONDITION_VARIABLE(cv) {EM_DEBUG_LOG("WAKE_CONDITION_VARIABLE "#cv); if (cv) g_cond_signal(cv); }
192 #define DELETE_CONDITION_VARIABLE(cv) {EM_DEBUG_LOG("DELETE_CONDITION_VARIABLE "#cv); if (cv) g_cond_free(cv); cv = NULL; }
194 #define INITIALIZE_RECURSIVE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("INITIALIZE_RECURSIVE_CRITICAL_SECTION "#cs); g_static_rec_mutex_init(&cs); }
195 #define ENTER_RECURSIVE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("ENTER_RECURSIVE_CRITICAL_SECTION "#cs); g_static_rec_mutex_lock(&cs); }
196 #define TRY_ENTER_RECURSIVE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("TRY_ENTER_RECURSIVE_CRITICAL_SECTION "#cs); g_static_rec_mutex_trylock(&cs); }
197 #define LEAVE_RECURSIVE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("LEAVE_RECURSIVE_CRITICAL_SECTION "#cs); g_static_rec_mutex_unlock(&cs); }
198 #define DELETE_RECURSIVE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("DELETE_RECURSIVE_CRITICAL_SECTION "#cs); g_static_rec_mutex_free(&cs); }
199 typedef GThread* thread_t;
200 #endif /* __FEATURE_USE_PTHREAD__ */
202 #define SMTP_RESPONSE_OK 250
203 #define SMTP_RESPONSE_READY 354
204 #define SMTP_RESPONSE_WANT_AUTH 505
205 #define SMTP_RESPONSE_WANT_AUTH2 530
206 #define SMTP_RESPONSE_UNAVAIL 550
207 /* ----------------------------------------------------------------------------- */
211 _SERVICE_THREAD_TYPE_NONE = 0,
212 _SERVICE_THREAD_TYPE_RECEIVING = 1,
213 _SERVICE_THREAD_TYPE_SENDING = 2,
214 #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
215 _SERVICE_THREAD_TYPE_PBD = 3,
216 #endif /* __FEATURE_PARTIAL_BODY_DOWNLOAD__ */
217 } emf_service_thread_type;
222 EMF_PROTOCOL_POP3 = 1,
225 EMF_PROTOCOL_NONE = 0,
226 } emf_protocol_type_t;
228 #ifdef __FEATURE_KEEP_CONNECTION__
231 EMF_STREAM_STATUS_DISCONNECTED = 0,
232 EMF_STREAM_STATUS_CONNECTED = 1
234 #endif /* __FEATURE_KEEP_CONNECTION__ */
236 /* event information */
239 int account_id; /* in general, account id */
240 emf_event_type_t type;
241 emf_event_status_type_t status;
242 char *event_param_data_1; /* in general, mailbox name (exception in em_core_mail_send, em_core_mail_send_saved it is emf_option_t **/
243 char *event_param_data_2;
244 char *event_param_data_3;
245 int event_param_data_4;
246 int event_param_data_5;
247 int event_param_data_6; /* in general, notification parameter #1 */
248 int event_param_data_7; /* in general, notification parameter #2 */
256 } emf_callback_holder_t;
259 typedef struct emf_search_key_t emf_search_key_t;
260 struct emf_search_key_t
264 emf_search_key_t *next;
270 emf_protocol_type_t protocol;
278 #ifdef __FEATURE_KEEP_CONNECTION__
280 typedef struct emf_connection_info
283 int sending_server_stream_status;
284 void *sending_server_stream;
285 int receiving_server_stream_status;
286 void *receiving_server_stream;
287 struct emf_connection_info *next;
288 } emf_connection_info_t;
289 #endif /* __FEATURE_KEEP_CONNECTION__ */
291 typedef void (*emf_event_callback)(int total, int done, int status, int account_id, int mail_id, int handle, void *user_data, int error);
293 /* ----------------------------------------------------------------------------- */
294 /* Please contact Himanshu [h.gahlaut@samsung.com] for any explanation in code here under __FEATURE_PARTIAL_BODY_DOWNLOAD__ MACRO */
295 #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
298 ACTIVITY_PARTIAL_BODY_DOWNLOAD_IMAP4 = 1,
299 ACTIVITY_PARTIAL_BODY_DOWNLOAD_POP3_WAIT,
300 ACTIVITY_PARTIAL_BODY_DOWNLOAD_POP3_ACTIVE
301 } emf_pdb_activity_type_e;
307 unsigned long server_mail_id;
310 emf_event_type_t event_type; /* Event Type Null means event is created from local activitys */
311 int activity_type; /* Activity Type Null means event is created from event queue */
313 } emf_event_partial_body_thd;
314 #endif /* __FEATURE_PARTIAL_BODY_DOWNLOAD__ */
318 #endif /* __cplusplus */
320 #endif /* __EM_CORE_TYPES_H_ */