Revert "[P151125-03506] NAVER server's server search is not operated"
[platform/core/messaging/email-service.git] / email-common-use / include / email-debug-log.h
1 /*
2 *  email-service
3 *
4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5 *
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
7 *
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
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
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.
19 *
20 */
21
22
23
24 /******************************************************************************
25  * File: email-debug-log.h
26  * Desc: email-common-use debug header
27  *
28  * Auth:
29  *
30  * History:
31  *    2006.08.01 : created
32  *****************************************************************************/
33 #ifndef __EMAIL_DEBUG_LOG_H__
34 #define __EMAIL_DEBUG_LOG_H__
35
36 #ifdef  __cplusplus
37 extern "C"
38 {
39 #endif
40 #include <tzplatform_config.h>
41 #include <stdio.h>
42 #include <string.h>
43 #include <stdlib.h>
44 #include <dlog.h>
45 #include <errno.h>
46
47 #define __FEATURE_DEBUG_LOG__
48 /* #define __FEATURE_LOG_FOR_LIFE_CYCLE_OF_FUNCTION__ */
49 /* #define __FEATURE_LOG_FOR_DEBUG_LOG_DEV__ */
50 /* #define FEATURE_CORE_DEBUG */
51
52 #ifdef  __FEATURE_DEBUG_LOG__
53
54 /* definition of LOG_TAG */
55 #ifdef LOG_TAG
56 #undef LOG_TAG
57 #endif
58
59 #define LOG_TAG "EMAIL_SERVICE"
60
61 #define EM_DEBUG_LOG(format, arg...)        SLOGD(format, ##arg)
62 #define EM_DEBUG_EXCEPTION(format, arg...)  SLOGE("[EXCEPTION!] " format "\n", ##arg)
63
64 #define EM_DEBUG_LOG_SEC(format, arg...)        SECURE_SLOGD(format, ##arg)
65 #define EM_DEBUG_EXCEPTION_SEC(format, arg...)  SECURE_SLOGE("[EXCEPTION!] " format "\n", ##arg)
66 #define EM_DEBUG_FUNC_BEGIN_SEC(format, arg...) EM_DEBUG_LOG_SEC("BEGIN - "format, ##arg)
67
68 #ifdef  _DEBUG_MIME_PARSE_
69 #define EM_DEBUG_LOG_MIME(format, arg...)   EM_DEBUG_LOG_SEC(format, ##arg)
70 #else   /*  _DEBUG_MIME_PARSE */
71 #define EM_DEBUG_LOG_MIME(format, arg...)
72 #endif /*  _DEBUG_MIME_PARSE */
73
74 #ifdef __FEATURE_LOG_FOR_LIFE_CYCLE_OF_FUNCTION__
75 #define EM_DEBUG_FUNC_BEGIN(format, arg...) EM_DEBUG_LOG("BEGIN - "format, ##arg)
76 #define EM_DEBUG_FUNC_END(format, arg...)   EM_DEBUG_LOG("END - "format, ##arg)
77 #else /* __FEATURE_LOG_FOR_LIFE_CYCLE_OF_FUNCTION__ */
78 #define EM_DEBUG_FUNC_BEGIN(format, arg...)
79 #define EM_DEBUG_FUNC_END(format, arg...)
80 #undef  EM_DEBUG_FUNC_BEGIN_SEC
81 #define EM_DEBUG_FUNC_BEGIN_SEC(format, arg...)
82 #endif
83
84 #ifdef __FEATURE_LOG_FOR_DEBUG_LOG_DEV__
85 #define EM_DEBUG_LOG_DEV(format, arg...) EM_DEBUG_LOG("[DEV] " format, ##arg)
86 #else /* __FEATURE_LOG_FOR_DEBUG_LOG_DEV__ */
87 #define EM_DEBUG_LOG_DEV(format, arg...)
88 #endif
89
90 #define EM_DEBUG_LINE                       EM_DEBUG_LOG("FUNC[%s : %d]", __FUNCTION__, __LINE__)
91 #define EM_DEBUG_DB_EXEC(eval, expr, X)     if (eval) { EM_DEBUG_EXCEPTION X; expr;} else {;}
92
93 #define EM_DEBUG_ERROR_FILE_PATH            tzplatform_mkpath(TZ_USER_DATA, "email/.email_data/.critical_error.log")
94 #define EM_DEBUG_CRITICAL_EXCEPTION(format, arg...)   \
95                         {\
96                                 FILE *fp_error = NULL;\
97                                 fp_error = fopen(EM_DEBUG_ERROR_FILE_PATH, "a");\
98                                 if(fp_error) {\
99                                         char now_time_string[30] = {0,}; \
100                                         time_t now = time(NULL); \
101                                         strftime(now_time_string, 20, "%Y.%m.%d %H:%M:%S", localtime(&now)); \
102                                         fprintf(fp_error, "[%s][%s() :%s:%d] " format "\n",\
103                                                 now_time_string, \
104                                                 __FUNCTION__, (rindex(__FILE__, '/')? rindex(__FILE__,'/')+1 : __FILE__ ),\
105                                                 __LINE__, ##arg); \
106                                         fclose(fp_error);\
107                                 }\
108                         }
109 #define EM_DEBUG_ALARM_LOG_FILE_PATH         tzplatform_mkpath(TZ_USER_DATA, "email/.email_data/.alarm.log")
110 #define EM_DEBUG_ALARM_LOG(format, arg...)   \
111                         {\
112                                 FILE *fp_error = NULL;\
113                                 fp_error = fopen(EM_DEBUG_ALARM_LOG_FILE_PATH, "a");\
114                                 if(fp_error) {\
115                                         char now_time_string[30] = {0,}; \
116                                         time_t now = time(NULL); \
117                                         strftime(now_time_string, 20, "%Y.%m.%d %H:%M:%S", localtime(&now)); \
118                                         fprintf(fp_error, "[%s][%s() :%s:%d] " format "\n",\
119                                                 now_time_string, \
120                                                 __FUNCTION__, (rindex(__FILE__, '/')? rindex(__FILE__,'/')+1 : __FILE__ ),\
121                                                 __LINE__, ##arg); \
122                                         fclose(fp_error);\
123                                 }\
124                         }
125 #define EM_DEBUG_PERROR(str)    ({\
126                 char buf[128] = {0};\
127                 strerror_r(errno, buf, sizeof(buf));\
128                 EM_DEBUG_EXCEPTION("%s: %s(%d)", str, buf, errno);\
129         })
130
131 #define EM_VALIDATION_SYSTEM_LOG(CLASSIFICATION, MAIL_ID, FORMAT, ARG...) {char now_time_string[30] = {0,}; \
132                 time_t now = time(NULL); \
133                 strftime(now_time_string, 20, "%Y.%m.%d %H:%M:%S", localtime(&now)); \
134                 LOG(LOG_VERBOSE, "VLD_EMAIL", "[Email " CLASSIFICATION "]%s, %d," FORMAT "\n", now_time_string, MAIL_ID, ##ARG);}
135
136 #ifdef _USE_PROFILE_DEBUG_
137 #define EM_PROFILE_BEGIN(pfid) \
138         unsigned int __prf_l1_##pfid = __LINE__;\
139         struct timeval __prf_1_##pfid;\
140         struct timeval __prf_2_##pfid;\
141         do {\
142                 gettimeofday(&__prf_1_##pfid, 0);\
143                 EM_DEBUG_LOG("**PROFILE BEGIN** [EMAILFW: %s() :%s %u ~ ] " #pfid \
144                 " ->  Start Time: %u.%06u seconds\n",\
145                         __FUNCTION__,\
146                 rindex(__FILE__,'/')+1, \
147                 __prf_l1_##pfid,\
148                 (unsigned int)__prf_1_##pfid.tv_sec,\
149                 (unsigned int)__prf_1_##pfid.tv_usec );\
150         } while (0)
151
152 #define EM_PROFILE_END(pfid) \
153         unsigned int __prf_l2_##pfid = __LINE__;\
154         do { \
155                 gettimeofday(&__prf_2_##pfid, 0);\
156                 long __ds = __prf_2_##pfid.tv_sec - __prf_1_##pfid.tv_sec;\
157                 long __dm = __prf_2_##pfid.tv_usec - __prf_1_##pfid.tv_usec;\
158                 if ( __dm < 0 ) { __ds--; __dm = 1000000 + __dm; } \
159                 EM_DEBUG_LOG("**PROFILE END** [EMAILFW: %s() :%s %u ~ %u] " #pfid                            \
160                 " -> Elapsed Time: %u.%06u seconds\n",\
161                         __FUNCTION__,\
162                 rindex(__FILE__, '/')+1,\
163                 __prf_l1_##pfid,\
164                 __prf_l2_##pfid,\
165                 (unsigned int)(__ds),\
166                 (unsigned int)(__dm));\
167         } while (0)
168 #else
169
170 #define EM_PROFILE_BEGIN(pfid)
171 #define EM_PROFILE_END(pfid)
172
173 #endif
174
175
176 #else /* __FEATURE_DEBUG_LOG__ */
177
178         #define EM_DEBUG_LINE
179         #define EM_DEBUG_LOG(format, arg...)
180         #define EM_DEBUG_ASSERT(format, arg...)
181         #define EM_DEBUG_EXCEPTION(format, arg...)
182
183
184         #define EM_DEBUG_DB_EXEC(eval, expr, X)  if (eval) { EM_DEBUG_DB X; expr;} else {;}
185         #define EM_PROFILE_BEGIN(pfid)
186         #define EM_PROFILE_END(pfid)
187
188 #endif /* __FEATURE_DEBUG_LOG__ */
189
190 /* Use it in api function */
191 #define EM_DEBUG_API_BEGIN(format, arg...) EM_DEBUG_LOG("BEGIN - "format, ##arg)
192 #define EM_DEBUG_API_END(format, arg...)   EM_DEBUG_LOG("END - "format, ##arg)
193
194 #define EM_NULL_CHECK_FOR_VOID(expr)    \
195         {\
196                 if (!expr) {\
197                         EM_DEBUG_LOG ("NULL_PARAM: ["#expr"]");\
198                         return;\
199                 }\
200         }
201
202 #define EM_IF_NULL_RETURN_VALUE(expr, ret) \
203         {\
204                 if (!expr ) {\
205                         EM_DEBUG_LOG("NULL_PARAM: ["#expr"]");\
206                         return ret;     \
207                 }\
208         }
209
210 #define EM_RETURN_ERR_CODE(err_ptr, err_code, ret) \
211         {\
212                 if(err_ptr) *err_ptr = err_code;\
213                 return ret;\
214         }
215
216 #define EM_EXIT_ERR_CODE(err_ptr, err_code) \
217         {\
218                 if(err_ptr) *err_ptr = err_code;\
219                 return;\
220         }
221
222
223 #define EM_SAFE_FREE(expr)       \
224         ({\
225                 if (expr) {\
226                         free (expr);\
227                         expr = NULL;\
228                 }\
229         })
230
231 #define EM_SAFE_CLOSE(fd)        \
232         ({\
233                 int err = 0;\
234                 if (fd >=0) {\
235                         err = close (fd);\
236                         if (err < 0)\
237                                 EM_DEBUG_EXCEPTION ("close errno [%d]", errno);\
238                         fd = 0;\
239                 }\
240         })
241
242 #define EM_SAFE_STRDUP(s) \
243         ({\
244                 char* _s = (char*)s;\
245                 (_s)? strdup(_s) : NULL;\
246         })
247
248 #define EM_SAFE_STRCMP(dest, src) \
249         ({\
250                 char* _dest = dest;\
251                 char* _src = src;\
252                 ((_src) && (_dest))? strcmp(_dest, _src) : -1;\
253         })
254
255 #define EM_SAFE_STRCASECMP(dest, src) \
256         ({\
257                 char* _dest = dest;\
258                 char* _src = src;\
259                 ((_src) && (_dest))? strcasecmp(_dest, _src) : -1;\
260         })
261
262 #define EM_SAFE_STRCPY(dest, src) \
263         ({\
264                 char* _dest = dest;\
265                 char* _src = src;\
266                 ((_src) && (_dest))? strcpy(_dest, _src) : NULL;\
267         })
268
269 #define EM_SAFE_STRNCPY(dest, src, size) \
270         ({\
271                 char* _dest = dest;\
272                 char* _src = src;\
273                 int _size = size;\
274                 ((_src) && (_dest))? strncpy(_dest, _src, _size) : NULL;\
275         })
276
277 #define EM_SAFE_STRCAT(dest, src) \
278         ({\
279                 char* _dest = dest;\
280                 char* _src = src;\
281                 ((_src) && (_dest))? strcat(_dest, _src) : NULL;\
282         })
283
284
285 #define EM_SAFE_STRNCAT(dest, src, size) \
286         ({\
287                 char* _dest = dest;\
288                 char* _src = src;\
289                 int _size = size;\
290                 ((_src) && (_dest))? strncat(_dest, _src, _size) : NULL;\
291         })
292
293
294 #define EM_SAFE_STRLEN(s) \
295         ({\
296                 char* _s = (char*)s;\
297                 (_s)? strlen(_s) : 0;\
298         })
299
300
301 #define EM_IF_ACCOUNT_ID_NULL(expr, ret) {\
302                 if (expr <= 0) {\
303                         EM_DEBUG_EXCEPTION_SEC ("EM_IF_ACCOUNT_ID_NULL: Account ID [ %d ]  ", expr);\
304                         return ret;\
305                 }\
306         }
307
308
309 #define ERRNO_BUF_SIZE          64
310
311 #define EM_STRERROR(errno_buf) ({\
312                         strerror_r(errno, errno_buf, sizeof(errno_buf));\
313                         errno_buf;\
314                 })
315
316 #ifdef  __cplusplus
317 }
318 #endif  /* __cplusplu */
319
320 #endif  /* __EMAIL_DEBUG_LOG_H__ */