3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <glib/gprintf.h>
26 #include "cals-typedef.h"
27 #include "cals-ical.h"
28 #include "cals-ical-codec.h"
29 #include "cals-internal.h"
30 #include "cals-utils.h"
32 #include "utility/sync_util.h"
34 #ifndef SYNC_AGENT_LOG
36 #define LOG_TAG "VOBJECT_TIZEN"
39 /****************************************************************************************************/
40 /* GLOBAL VARIABLE DECLARATION AND INITIALIZATION */
41 /****************************************************************************************************/
44 const char *pszCalTypeList[] = {
114 static const char *pszCalParamList[] = {
143 static const ValueObj pCalCutypeValList[] = {
144 {"GROUP", 0x00000001},
145 {"INDIVIDUAL", 0x00000002},
146 {"RESOURCE", 0x00000004},
147 {"ROOM", 0x00000008},
148 {"UNKNOWN", 0x00000010}
151 /* Character set value */
152 static const ValueObj pCalCharsetValList[] = {
153 {"UTF-8", 0x00000001},
154 {"UTF-16", 0x00000002}
158 static const ValueObj pCalEncValList[] = {
160 {"BASE64", 0x00000002},
161 {"QUOTED-PRINTABLE", 0x00000004},
162 {"7BIT", 0x00000008},
167 static const ValueObj pCalFbtypeValList[] = {
168 {"BUSY", 0x00000001},
169 {"BUSY_TENTATIVE", 0x00000002},
170 {"BUSY_UNAVAILABLE", 0x00000004},
175 static const ValueObj pCalPartstatValList[] = {
176 {"ACCEPTED", 0x00000001},
177 {"COMPLETED", 0x00000002},
178 {"DELEGATED", 0x00000004},
179 {"DECLINED", 0x00000008},
180 {"IN_PROCESS", 0x00000010},
181 {"NEED_ACTION", 0x00000020},
182 {"TENTATIVE", 0x00000040}
186 static const ValueObj pCalRangeValList[] = {
187 {"THISANDFUTURE", 0x00000001},
188 {"THISANDPRIOR", 0x00000002}
192 static const ValueObj pCalRelatedValList[] = {
194 {"START", 0x00000002}
198 static const ValueObj pCalReltypeValList[] = {
199 {"CHILD", 0x00000001},
200 {"PARENT", 0x00000002},
201 {"SIBLING", 0x00000004}
205 static const ValueObj pCalValValList[] = {
206 {"BINARY", 0x00000001},
207 {"BOOLEAN", 0x00000002},
208 {"CAL-ADDRESS", 0x00000004},
210 {"CONTENT-ID", 0x00000010},
211 {"DATE", 0x00000020},
212 {"DATE-TIME", 0x00000040},
213 {"DURATION", 0x00000080},
214 {"FLOAT", 0x00000100},
215 {"INTEGER", 0x00000200},
216 {"PERIOD", 0x00000400},
217 {"PHONE-NUMBER", 0x00000800},
218 {"RECUR", 0X00001000},
219 {"TEXT", 0x00002000},
220 {"TIME", 0x00004000},
223 {"UTC-OFFSET", 0x00020000},
224 {"VCALENDAR", 0x00040000},
225 {"VEVENT", 0x00080000},
226 {"VTODO", 0x00100000}
230 static const ValueObj pCalTypeValList[] = {
231 {"AIFF", 0x00000001},
234 {"CELL", 0x00000008},
238 {"HOME", 0x00000080},
239 {"INTL", 0x00000100},
240 {"INTERNET", 0x00000200},
241 {"ISDN", 0x00000400},
242 {"JPEG", 0x00000800},
243 {"MODEM", 0x00001000},
245 {"PAGER", 0x00004000},
246 {"PARCEL", 0x00008000},
250 {"POSTAL", 0x00080000},
251 {"PREF", 0x00100000},
252 {"VCARD", 0x00200000},
253 {"VIDEO", 0x00400000},
254 {"VOICE", 0x00800000},
255 {"WAVE", 0x01000000},
256 {"WBMP", 0x02000000},
257 {"WORK", 0x04000000},
262 static const ValueObj pCalExpectValList[] = {
264 {"IMMEDIATE", 0x00000002},
265 {"REQUEST", 0x00000004},
266 {"REQUIRE", 0x00000008}
270 static const ValueObj pCalRoleValList[] = {
271 {"ATTENDEE", 0x00000001},
272 {"CHAIR", 0x00000002},
273 {"DELEGATE", 0x00000004},
274 {"NON_PARTICIPANT", 0x00000008},
275 {"OPT_PARTICIPANT", 0x00000010},
276 {"ORGANIZER", 0x00000020},
277 {"OWNER", 0x00000040},
278 {"REQ_PARTICIPANT", 0x00000080}
282 static const ValueObj pCalRSVPValList[] = {
283 {"false", 0x00000001},
285 {"true", 0x00000004},
290 static const ValueObj pCalStatusValList[] = {
291 {"ACCEPTED", 0x00000001},
292 {"COMPLETED", 0x00000002},
293 {"CONFIRMED", 0x00000004},
294 {"DECLINED", 0x00000008},
295 {"DELEGATED", 0x00000010},
296 {"NEEDS ACTION", 0x00000020},
297 {"SENT", 0x00000040},
298 {"TENTATIVE", 0x00000080},
301 static char *__VCalParamEncode(VObject *, int *);
303 void _gbase64Encode(char *Dest, char *Src, int len)
307 gchar *buf = g_base64_encode((guchar *) Src, strlen(Src));
309 dest_len = g_strlcpy(Dest, buf, len);
310 if (dest_len >= len) {
311 _DEBUG_ERROR("Dest buffer overflow !!");
312 /* todo : exception handling */
314 _DEBUG_TRACE("_gbase64Decode before:\n%s \n", Src);
315 _DEBUG_TRACE("_gbase64Decode after:\n%s \n", Dest);
322 * vcal_free_vtree_memory() frees memory used for decoding.
324 * @param pTree VTree structure to be freed.
325 * @return If succeeds, return true, else false.
327 bool vcal_free_vtree_memory(VTree * pTree)
331 VObject *pCurObj = NULL;
332 VObject *pNextObj = NULL;
333 VTree *pCurTree = NULL;
334 VTree *pNextTree = NULL;
336 _DEBUG_INFO("vcal_free_vtree_memory() entered.\n");
337 //SysRequireEx( pTree != NULL, false );
338 retvm_if(NULL == pTree, NULL, "[ERROR]vcal_free_vtree_memory:Invalid parameter(pTree)!\n");
340 if ((pTree->treeType == VCALENDAR) || ((pTree->treeType >= VEVENT) && (pTree->treeType <= DAYLIGHT))) {
350 pNextTree = pCurTree->pNext;
351 pCurObj = pCurTree->pTop;
357 pNextObj = pCurObj->pSibling;
359 count = pCurObj->valueCount;
361 for (i = 0; i < count; i++) {
362 if (pCurObj->pszValue[i] != NULL) {
363 free(pCurObj->pszValue[i]);
364 pCurObj->pszValue[i] = NULL;
368 #ifdef VDATA_GROUPNAME_SUPPORTED
369 if (pCurObj->pszGroupName != NULL) {
370 free(pCurObj->pszGroupName);
371 pCurObj->pszGroupName = NULL;
373 #endif // VDATA_GROUPNAME_SUPPORTED
375 if (pCurObj->pParam != NULL) {
376 VParam *pCurParam = NULL;
377 VParam *pNextParam = NULL;
379 pCurParam = pCurObj->pParam;
382 pNextParam = pCurParam->pNext;
387 pCurParam = pNextParam;
400 pCurTree = pNextTree;
403 _DEBUG_INFO("\n---------------------------exit vcal_free_vtree_memory--------- -------------\n");
411 * vCaLTypeEncoder() compares the string and VCal type, parameter value.
413 * @param typeObj Data which will be encoded
414 * @param type Name of the type
415 * @return char * Encoded result
417 static char *__VCalTypeEncode(VObject * pTypeObj, const char *pType)
423 char *szTypeValue = NULL;
426 char *pEncode = NULL;
430 char *tempszTypeValue = NULL;
433 _DEBUG_VERBOSE("__VCalTypeEncode() enter..\n");
436 biLen = pTypeObj->numOfBiData;
438 if ((szTypeValue = (char *)malloc(total += (len + 1 + 10))) == NULL) {
439 _DEBUG_ERROR("VCalTypeEncode():malloc failed\n");
443 memset(szTypeValue, '\0', (len + 1 + 10));
444 memcpy(szTypeValue, pType, len);
446 pTemp = __VCalParamEncode(pTypeObj, &enc);
449 tempszTypeValue = szTypeValue;
450 if ((szTypeValue = (char *)realloc(szTypeValue, (total += len + 10))) == NULL) {
451 _DEBUG_ERROR("__VCalTypeEncode():realloc failed\n");
457 if (tempszTypeValue != NULL) {
458 free(tempszTypeValue);
459 tempszTypeValue = NULL;
463 temp_len = g_strlcat(szTypeValue, pTemp, total);
464 if (temp_len >= total) {
465 _DEBUG_ERROR("szTypeValue buffer overflow !!");
466 /* todo : exception handling */
471 tempszTypeValue = szTypeValue;
472 if ((szTypeValue = (char *)realloc(szTypeValue, (total += 2 + 10))) == NULL) {
474 _DEBUG_ERROR("__VCalTypeEncode():realloc failed\n");
475 if (tempszTypeValue != NULL) {
476 free(tempszTypeValue);
477 tempszTypeValue = NULL;
482 temp_len = g_strlcat(szTypeValue, ":\0", total);
483 if (temp_len >= total) {
484 _DEBUG_ERROR("szTypeValue buffer overflow !!");
485 /* todo : exception handling */
489 for (i = 0; i < pTypeObj->valueCount; i++) {
490 if ((pTypeObj->pszValue[i] == NULL)) {
495 len += strlen(pTypeObj->pszValue[i]);
500 if ((pEncode = (char *)calloc(1, (len + 30) * 2 + 31)) == NULL) {
502 _DEBUG_ERROR("__VCalTypeEncode():malloc failed\n");
505 for (i = 0; i < pTypeObj->valueCount; i++) {
506 int len_i = strlen(pTypeObj->pszValue[i]);
507 if (buf_len < len_i) {
510 if ((buf = (char *)calloc(1, buf_len * 2 + 1)) == NULL) {
512 _DEBUG_ERROR("__VCalTypeEncode():malloc failed\n");
522 strncpy(buf, pTypeObj->pszValue[i], len_i);
527 temp_len = g_strlcat(pEncode, ";", ((len + 30) * 2 + 31));
528 if (temp_len >= ((len + 30) * 2 + 31)) {
529 _DEBUG_ERROR("pEncode buffer overflow !!");
530 /* todo : exception handling */
534 temp_len = g_strlcat(pEncode, buf, ((len + 30) * 2 + 31));
535 if (temp_len >= ((len + 30) * 2 + 31)) {
536 _DEBUG_ERROR("pEncode buffer overflow !!");
537 /* todo : exception handling */
544 temp_len = g_strlcat(pEncode, "\0\0", ((len + 30) * 2 + 31));
545 if (temp_len >= ((len + 30) * 2 + 31)) {
546 _DEBUG_ERROR("pEncode buffer overflow !!");
547 /* todo : exception handling */
549 // _VEscape( pEncode );
550 len = strlen(pEncode);
552 if (enc & pCalEncValList[2].flag) {
554 //if ( ( pRes = ( char * )malloc( len+40 ) ) == NULL )
555 //if ( ( pRes = ( char * )malloc( len+40+10 ) ) == NULL )
556 // Task description?? enter?? ??? ??? memory ?????. len * 4 + 30 -> len * 6 + 30???? ???? 2004.3.12
557 if ((pRes = (char *)malloc(len * 6 + 30)) == NULL) {
558 _DEBUG_ERROR("__VCalTypeEncode():malloc failed\n");
565 _VQPEncode(pRes, pEncode);
568 } else if (enc & pCalEncValList[1].flag) {
570 //if ( ( pRes = ( char * )malloc( ( len * 8 / 6 ) + 4 ) ) == NULL )
571 if ((pRes = (char *)malloc((len * 8 / 6) + 4 + 10)) == NULL) {
572 _DEBUG_ERROR("__VCalTypeEncode():malloc failed\n");
578 //memset( pRes, '\0', ( ( len * 8 / 6 ) + 4 ) );
579 memset(pRes, '\0', ((len * 8 / 6) + 4 + 10));
580 // _gbase64Encode( pRes, pEncode, biLen );
581 _gbase64Encode(pRes, pEncode, ((len * 8 / 6) + 4 + 10));
587 //if ( ( pRes = ( char * )malloc( len+2 ) ) == NULL )
588 if ((pRes = (char *)malloc(len + 2 + 10)) == NULL) {
589 _DEBUG_ERROR("__VCalTypeEncode():malloc failed\n");
596 //memset( pRes, '\0', ( len + 2 ) );
597 memset(pRes, '\0', (len + 2 + 10));
598 memcpy(pRes, pEncode, len);
604 temp_len = g_strlcat(pRes, "\r\n", (len + 2 + 10));
605 if (temp_len >= (len + 2 + 10)) {
606 _DEBUG_ERROR("pRes buffer overflow !!");
607 /* todo : exception handling */
611 //if ( ( szTypeValue = ( char * )realloc( szTypeValue, ( total += ( len+3 ) ) ) ) == NULL )
612 tempszTypeValue = szTypeValue;
613 if ((szTypeValue = (char *)malloc((total += (len * 4 + 3 + 10)))) == NULL) {
614 _DEBUG_ERROR("__VCalTypeEncode():realloc failed\n");
619 if (tempszTypeValue != NULL) {
620 free(tempszTypeValue);
621 tempszTypeValue = NULL;
627 memset(szTypeValue, 0x00, total);
628 strncpy(szTypeValue, tempszTypeValue, total);
630 temp_len = g_strlcat(szTypeValue, pRes, total);
631 if (temp_len >= (total + 1)) {
632 _DEBUG_ERROR("szTypeValue buffer overflow !!");
633 /* todo : exception handling */
635 _VRLSpace(szTypeValue);
636 _VRTSpace(szTypeValue);
638 free(tempszTypeValue);
640 if (strlen(szTypeValue) >= 75) {
641 if ((pEncode = (char *)malloc(sizeof(char) * (strlen(szTypeValue) * 4 + (strlen(szTypeValue) / 75) * 2 + 10 + 10))) == NULL) {
642 _DEBUG_ERROR("__VCalTypeEncode():malloc failed\n");
647 _VFolding(pEncode, szTypeValue);
653 _DEBUG_VERBOSE("__VCalTypeEncode() end..\n");
661 * vcal_encode() compares the string and VCal type, parameter value.
663 * @param pVCalRaw Data which will be encoded
664 * @return char * Encoded result
666 char *vcal_encode(VTree * pVCalRaw)
670 char *pCalRes = NULL;
674 VTree *pTmpTree = NULL;
675 VObject *pTmpObj = NULL;
678 _DEBUG_INFO("vcal_encode() enter..\n");
679 //SysRequireEx( pVCalRaw != NULL, NULL );
680 if (pVCalRaw == NULL)
683 if ((pVCalRaw->treeType == VCALENDAR) || ((pVCalRaw->treeType >= VEVENT) && (pVCalRaw->treeType <= DAYLIGHT))) {
690 if ((pCalRes = (char *)malloc(total += 2)) == NULL) {
691 _DEBUG_INFO("vcal_encode():malloc failed\n");
694 memset(pCalRes, '\0', 1);
697 pTmpObj = pTmpTree->pTop;
700 if( (pTmpObj == NULL) || (pTmpObj->property < 0) || (pTmpObj->valueCount < 0) )
703 _DEBUG_INFO( "pTmpObj = %d, pTmpObj->property = %d,pTmpObj->valueCount=%d \n",pTmpObj,pTmpObj->property,pTmpObj->valueCount);
705 _DEBUG_INFO("pTmpObj is NULL");
710 switch (pTmpTree->treeType) {
713 // wyj add PRODID field,set PRODID length is 100
714 if ((pCalRes = (char *)realloc(pCalRes, (total += 18 + 100 + 15))) == NULL) {
716 _DEBUG_INFO("vcal_encode():realloc failed\n");
720 temp_len = g_strlcat(pCalRes, "BEGIN:VCALENDAR\r\n", total);
721 temp_len = g_strlcat(pCalRes, "PRODID:-//Samsung Electronics //Calendar //EN\r\n", total);
722 temp_len = g_strlcat(pCalRes, "VERSION:1.0\r\n", total);
723 if (temp_len >= (total + 1)) {
724 _DEBUG_ERROR("pCalRes buffer overflow !!");
725 /* todo : exception handling */
729 if ((pCalRes = (char *)realloc(pCalRes, (total += 15))) == NULL) {
731 _DEBUG_INFO("vcal_encode():realloc failed\n");
735 temp_len = g_strlcat(pCalRes, "BEGIN:VEVENT\r\n", total);
736 if (temp_len >= (total + 1)) {
737 _DEBUG_ERROR("pCalRes buffer overflow !!");
738 /* todo : exception handling */
742 if ((pCalRes = (char *)realloc(pCalRes, (total += 14))) == NULL) {
744 _DEBUG_INFO("vcal_encode():realloc failed\n");
748 temp_len = g_strlcat(pCalRes, "BEGIN:VTODO\r\n", total);
749 if (temp_len >= (total + 1)) {
750 _DEBUG_ERROR("pCalRes buffer overflow !!");
751 /* todo : exception handling */
755 if ((pCalRes = (char *)realloc(pCalRes, (total += 17))) == NULL) {
757 _DEBUG_INFO("vcal_encode():realloc failed\n");
761 temp_len = g_strlcat(pCalRes, "BEGIN:VJOURNAL\r\n", total);
762 if (temp_len >= (total + 1)) {
763 _DEBUG_ERROR("pCalRes buffer overflow !!");
764 /* todo : exception handling */
768 if ((pCalRes = (char *)realloc(pCalRes, (total += 18))) == NULL) {
770 _DEBUG_INFO("vcal_encode():realloc failed\n");
774 temp_len = g_strlcat(pCalRes, "BEGIN:VFREEBUSY\r\n", total);
775 if (temp_len >= (total + 1)) {
776 _DEBUG_ERROR("pCalRes buffer overflow !!");
777 /* todo : exception handling */
781 if ((pCalRes = (char *)realloc(pCalRes, (total += 19))) == NULL) {
783 _DEBUG_INFO("vcal_encode():realloc failed\n");
787 temp_len = g_strlcat(pCalRes, "BEGIN:VTIMEZONE\r\n", total);
788 if (temp_len >= (total + 1)) {
789 _DEBUG_ERROR("pCalRes buffer overflow !!");
790 /* todo : exception handling */
794 if ((pCalRes = (char *)realloc(pCalRes, (total += 15))) == NULL) {
796 _DEBUG_INFO("vcal_encode():realloc failed\n");
800 temp_len = g_strlcat(pCalRes, "BEGIN:VALARM\r\n", total);
801 if (temp_len >= (total + 1)) {
802 _DEBUG_ERROR("pCalRes buffer overflow !!");
803 /* todo : exception handling */
807 if ((pCalRes = (char *)realloc(pCalRes, (total += 17))) == NULL) {
809 _DEBUG_INFO("vcal_encode():realloc failed\n");
813 temp_len = g_strlcat(pCalRes, "BEGIN:STANDARD\r\n", total);
814 if (temp_len >= (total + 1)) {
815 _DEBUG_ERROR("pCalRes buffer overflow !!");
816 /* todo : exception handling */
820 if ((pCalRes = (char *)realloc(pCalRes, (total += 17))) == NULL) {
822 _DEBUG_INFO("vcal_encode():realloc failed\n");
826 temp_len = g_strlcat(pCalRes, "BEGIN:DAYLIGHT\r\n", total);
827 if (temp_len >= (total + 1)) {
828 _DEBUG_ERROR("pCalRes buffer overflow !!");
829 /* todo : exception handling */
835 if (pTmpObj != NULL) {
836 if (pTmpObj->property < 0 || pTmpObj->property >= VCAL_TYPE_NUM) {
841 if ((pTemp = __VCalTypeEncode(pTmpObj, pszCalTypeList[pTmpObj->property])) != NULL) {
843 if ((pCalRes = (char *)realloc(pCalRes, (total += (len + 10)))) == NULL) {
844 _DEBUG_INFO("vcal_encode():realloc failed\n");
850 temp_len = g_strlcat(pCalRes, pTemp, total);
851 if (temp_len >= (total + 1)) {
852 _DEBUG_ERROR("pCalRes buffer overflow !!");
853 /* todo : exception handling */
858 if (pTmpObj->pSibling != NULL)
859 pTmpObj = pTmpObj->pSibling;
866 switch (pTmpTree->treeType) {
868 if ( ( pCalRes = ( char * )realloc( pCalRes, ( total += 15 ) ) ) == NULL )
870 _DEBUG_INFO( "vcal_encode():realloc failed\n");
873 memcpy( pCalRes, "END:VCALENDAR\r\n", 17 );
876 if ((pCalRes = (char *)realloc(pCalRes, (total += 13))) == NULL) {
878 _DEBUG_INFO("vcal_encode():realloc failed\n");
882 temp_len = g_strlcat(pCalRes, "END:VEVENT\r\n", total);
883 if (temp_len >= (total + 1)) {
884 _DEBUG_ERROR("pCalRes buffer overflow !!");
885 /* todo : exception handling */
889 if ((pCalRes = (char *)realloc(pCalRes, (total += 12))) == NULL) {
891 _DEBUG_INFO("vcal_encode():realloc failed\n");
895 temp_len = g_strlcat(pCalRes, "END:VTODO\r\n", total);
896 if (temp_len >= (total + 1)) {
897 _DEBUG_ERROR("pCalRes buffer overflow !!");
898 /* todo : exception handling */
902 if ((pCalRes = (char *)realloc(pCalRes, (total += 15))) == NULL) {
904 _DEBUG_INFO("vcal_encode():realloc failed\n");
908 temp_len = g_strlcat(pCalRes, "END:VJOURNALO\r\n", total);
909 if (temp_len >= (total + 1)) {
910 _DEBUG_ERROR("pCalRes buffer overflow !!");
911 /* todo : exception handling */
915 if ((pCalRes = (char *)realloc(pCalRes, (total += 16))) == NULL) {
917 _DEBUG_INFO("vcal_encode():realloc failed\n");
921 temp_len = g_strlcat(pCalRes, "END:VFREEBUSY\r\n", total);
922 if (temp_len >= (total + 1)) {
923 _DEBUG_ERROR("pCalRes buffer overflow !!");
924 /* todo : exception handling */
928 if ((pCalRes = (char *)realloc(pCalRes, (total += 16))) == NULL) {
930 _DEBUG_INFO("vcal_encode():realloc failed\n");
934 temp_len = g_strlcat(pCalRes, "END:VTIMEZONE\r\n", total);
935 if (temp_len >= (total + 1)) {
936 _DEBUG_ERROR("pCalRes buffer overflow !!");
937 /* todo : exception handling */
941 if ((pCalRes = (char *)realloc(pCalRes, (total += 13))) == NULL) {
943 _DEBUG_INFO("vcal_encode():realloc failed\n");
947 temp_len = g_strlcat(pCalRes, "END:VALARM\r\n", total);
948 if (temp_len >= (total + 1)) {
949 _DEBUG_ERROR("pCalRes buffer overflow !!");
950 /* todo : exception handling */
954 if ((pCalRes = (char *)realloc(pCalRes, (total += 15))) == NULL) {
956 _DEBUG_INFO("vcal_encode():realloc failed\n");
960 temp_len = g_strlcat(pCalRes, "END:STANDARD\r\n", total);
961 if (temp_len >= (total + 1)) {
962 _DEBUG_ERROR("pCalRes buffer overflow !!");
963 /* todo : exception handling */
967 if ((pCalRes = (char *)realloc(pCalRes, (total += 15))) == NULL) {
968 _DEBUG_INFO("vcal_encode():realloc failed\n");
972 temp_len = g_strlcat(pCalRes, "END:DAYLIGHT\r\n", total);
973 if (temp_len >= (total + 1)) {
974 _DEBUG_ERROR("pCalRes buffer overflow !!");
975 /* todo : exception handling */
980 if (pTmpTree->pNext != NULL)
981 pTmpTree = pTmpTree->pNext;
984 pTmpObj = pTmpTree->pTop;
987 if ((pCalRes = (char *)realloc(pCalRes, (total += 16))) == NULL) {
989 _DEBUG_INFO("vcal_encode():realloc failed\n");
993 temp_len = g_strlcat(pCalRes, "END:VCALENDAR\r\n", total);
994 if (temp_len >= (total + 1)) {
995 _DEBUG_ERROR("pCalRes buffer overflow !!");
996 /* todo : exception handling */
999 _DEBUG_INFO("vcal_encode() end..\n");
1007 * vCalParamEncoder() compares the string and VCal type, parameter value.
1009 * @param typeObj Data which will be encoded
1010 * @param type Name of the type
1012 static char *__VCalParamEncode(VObject * pTypeObj, int *pEnc)
1016 char *szParam = NULL;
1017 VParam *pTemp = NULL;
1019 const ValueObj *pList;
1026 _DEBUG_VERBOSE("__VCalParamEncode() enter..\n");
1027 retvm_if(NULL == pTypeObj, NULL, "[ERROR]__VCalParamEncode:Invalid parameter(pTypeObj)!\n");
1029 pTemp = pTypeObj->pParam;
1030 if (pTemp != NULL) {
1031 if ((szParam = (char *)malloc(len += 2)) == NULL) {
1032 _DEBUG_ERROR("__VCalParamEncode():malloc failed\n");
1035 memcpy(szParam, "\0\0", 2);
1038 while (pTemp != NULL) {
1041 if ((szParam = (char *)realloc(szParam, (len += 15))) == NULL) {
1043 _DEBUG_ERROR("__VCalParamEncode():realloc failed\n");
1047 temp_len = g_strlcat(szParam, ";", len);
1048 temp_len = g_strlcat(szParam, pszCalParamList[pTemp->parameter], len);
1049 temp_len = g_strlcat(szParam, "=", len);
1050 if (temp_len >= (len + 1)) {
1051 _DEBUG_ERROR("szParam buffer overflow !!");
1052 /* todo : exception handling */
1055 switch (pTemp->parameter) {
1056 case VCAL_PARAM_ENCODING:
1057 *pEnc = pTemp->paramValue;
1058 shift = VCAL_ENCODE_PARAM_NUM;
1059 pList = pCalEncValList;
1062 case VCAL_PARAM_CHARSET:
1063 shift = VCAL_CHARSET_PARAM_NUM;
1064 pList = pCalCharsetValList;
1067 case VCAL_PARAM_TYPE:
1068 shift = VCAL_TYPE_PARAM_NUM;
1069 pList = pCalTypeValList;
1072 case VCAL_PARAM_VALUE:
1073 shift = VCAL_VALUE_PARAM_NUM;
1074 pList = pCalValValList;
1077 case VCAL_PARAM_EXPECT:
1078 shift = VCAL_EXPECT_PARAM_NUM;
1079 pList = pCalExpectValList;
1082 case VCAL_PARAM_ROLE:
1083 shift = VCAL_ROLE_PARAM_NUM;
1084 pList = pCalRoleValList;
1087 case VCAL_PARAM_RSVP:
1088 shift = VCAL_RSVP_PARAM_NUM;
1089 pList = pCalRSVPValList;
1092 case VCAL_PARAM_STATUS:
1093 shift = VCAL_STATUS_PARAM_NUM;
1094 pList = pCalStatusValList;
1097 case VCAL_PARAM_CUTYPE:
1098 shift = VCAL_CUTYPE_PARAM_NUM;
1099 pList = pCalCutypeValList;
1102 case VCAL_PARAM_FBTYPE:
1103 shift = VCAL_FBTYPE_PARAM_NUM;
1104 pList = pCalFbtypeValList;
1107 case VCAL_PARAM_PARTSTAT:
1108 shift = VCAL_PARTSTAT_PARAM_NUM;
1109 pList = pCalPartstatValList;
1112 case VCAL_PARAM_RANGE:
1113 shift = VCAL_RANGE_PARAM_NUM;
1114 pList = pCalRangeValList;
1117 case VCAL_PARAM_RELATED:
1118 shift = VCAL_RELATED_PARAM_NUM;
1119 pList = pCalRelatedValList;
1122 case VCAL_PARAM_RELTYPE:
1123 shift = VCAL_RELTYPE_PARAM_NUM;
1124 pList = pCalReltypeValList;
1129 if ((szParam = (char *)realloc(szParam, 5)) == NULL) {
1130 _DEBUG_ERROR("__VCalParamEncode():realloc failed\n");
1134 temp_len = g_strlcat(szParam, "NONE", 5);
1135 if (temp_len >= 5) {
1136 _DEBUG_ERROR("szParam buffer overflow !!");
1137 /* todo : exception handling */
1142 if (bSupported == true) {
1143 for (i = 0, sNum = 0x00000001; i < shift; i++) {
1144 if (pTemp->paramValue & sNum) {
1145 if ((szParam = (char *)realloc(szParam, (len += (strlen(pList[i].szName) + 2)))) == NULL) {
1147 _DEBUG_ERROR("__VCalParamEncode():realloc failed\n");
1152 temp_len = g_strlcat(szParam, pList[i].szName, len);
1153 temp_len = g_strlcat(szParam, ", \0", len);
1154 if (temp_len >= (len + 1)) {
1155 _DEBUG_ERROR("szParam buffer overflow !!");
1156 /* todo : exception handling */
1163 for (i = strlen(szParam); i > 0; i--) {
1164 if (szParam[i] == ' ' && szParam[i - 1] == ',') {
1165 szParam[i - 1] = '\0';
1170 if (pTemp->pNext != NULL)
1171 pTemp = pTemp->pNext;
1176 _DEBUG_VERBOSE("\n ------end __VCalParamEncode ---------..\n");
1183 bool __cal_vcalendar_get_week_day_string(struct tm * start_time, char *s2)
1187 char *date_string[7] = { "SU", "MO", "TU", "WE", "TH", "FR", "SA" };
1190 time_t t = timegm(start_time);
1191 gmtime_r(&t, &temp);
1193 if (temp.tm_wday < 0 || temp.tm_wday > 6) {
1196 snprintf(s2, 3, "%s", date_string[temp.tm_wday]);
1204 struct tm *__cal_vcalendar_compute_pre_time(struct tm *start_tm, struct tm *alarm_tm, const int remind_tick, const cal_sch_remind_tick_unit_t unit, struct tm *ret_tm)
1208 start_tm->tm_sec = 0;
1209 alarm_tm->tm_sec = 0;
1210 // time_t gap_time = cals_mktime(alarm_tm) - cals_mktime(start_tm);
1211 time_t timep = timegm(alarm_tm);
1214 // Fix for prevent - B.
1216 case CAL_SCH_TIME_UNIT_MIN:
1217 t = timep - 60 * remind_tick;
1220 case CAL_SCH_TIME_UNIT_HOUR:
1221 t = timep - 60 * 60 * remind_tick;
1224 case CAL_SCH_TIME_UNIT_DAY:
1225 t = timep - 24 * 60 * 60 * remind_tick;
1227 case CAL_SCH_TIME_UNIT_WEEK:
1228 t = timep - 7 * 24 * 60 * 60 * remind_tick;
1231 case CAL_SCH_TIME_UNIT_MONTH:
1232 t = timep - 30 * 24 * 60 * 60 * remind_tick;
1242 return gmtime_r(&t, ret_tm);
1245 bool __cal_vcalendar_sch_vtree_add_object(VTree * tree, const cal_sch_full_t * sch, vCalType obj_type)
1255 assert((tree != NULL) && (sch != NULL));
1257 object = (VObject *) malloc(sizeof(VObject));
1258 if (object == NULL) {
1259 vcal_free_vtree_memory(tree);
1263 memset(object, 0, sizeof(VObject));
1266 case VCAL_TYPE_CATEGORIES:
1268 if (sch->cal_type == CALS_SCH_TYPE_TODO) {
1272 object->property = VCAL_TYPE_CATEGORIES;
1274 object->pszValue[0] = (char *)malloc(20);
1275 if ((object->pszValue[0]) == NULL) {
1276 vcal_free_vtree_memory(tree);
1282 memset(object->pszValue[0], 0, 20);
1284 object->valueCount = 1;
1288 case VCAL_TYPE_SUMMARY:
1290 if (NULL != sch->summary && strlen(sch->summary) != 0) {
1291 object->property = VCAL_TYPE_SUMMARY;
1292 str_len = strlen(sch->summary);
1293 //str_len = (str_len>500)?500:str_len;
1294 _DEBUG_INFO("-------------------__cal_vcalendar_sch_vtree_add_object /VCAL_TYPE_SUMMARY(%d) -------------", str_len);
1295 object->pParam = (VParam *) malloc(sizeof(VParam));
1296 if (object->pParam == NULL) {
1297 vcal_free_vtree_memory(tree);
1302 memset(object->pParam, 0, sizeof(VParam));
1304 object->pParam->parameter = VCAL_PARAM_CHARSET;
1305 object->pParam->paramValue = 0x01 << VCAL_CHARSET_PARAM_UTF_8;
1306 object->pParam->pNext = NULL;
1308 object->pParam->pNext = (VParam *) malloc(sizeof(VParam));
1309 if (object->pParam->pNext == NULL) {
1310 vcal_free_vtree_memory(tree);
1315 memset(object->pParam->pNext, 0, sizeof(VParam));
1317 object->pParam->pNext->parameter = VCAL_PARAM_ENCODING;
1318 object->pParam->pNext->paramValue = 0x01 << VCAL_ENC_PARAM_BASE64;
1320 object->pszValue[0] = (char *)malloc(str_len * 2 + 1);
1321 if ((object->pszValue[0]) == NULL) {
1322 vcal_free_vtree_memory(tree);
1328 if (NULL != sch->summary) {
1329 memset(object->pszValue[0], 0, str_len + 1);
1330 memcpy(object->pszValue[0], sch->summary, str_len);
1332 _DEBUG_INFO("sch->summary = %s,%s\n", sch->summary, object->pszValue[0]);
1334 object->valueCount = 1;
1343 case VCAL_TYPE_DESCRIPTION:
1345 _DEBUG_INFO("---__cal_vcalendar_sch_vtree_add_object /VCAL_TYPE_DESCRIPTION/ -------------\n");
1347 if (NULL != sch->description && strlen(sch->description) != 0) {
1348 object->property = VCAL_TYPE_DESCRIPTION;
1349 str_len = strlen(sch->description);
1350 //str_len = (str_len>500)?500:str_len;
1352 object->pParam = (VParam *) malloc(sizeof(VParam));
1353 if (object->pParam == NULL) {
1354 vcal_free_vtree_memory(tree);
1359 memset(object->pParam, 0, sizeof(VParam));
1361 object->pParam->parameter = VCAL_PARAM_CHARSET;
1362 object->pParam->paramValue = 0x01 << VCAL_CHARSET_PARAM_UTF_8;
1363 object->pParam->pNext = NULL;
1365 object->pParam->pNext = (VParam *) malloc(sizeof(VParam));
1366 if (object->pParam->pNext == NULL) {
1367 vcal_free_vtree_memory(tree);
1372 memset(object->pParam->pNext, 0, sizeof(VParam));
1374 object->pParam->pNext->parameter = VCAL_PARAM_ENCODING;
1375 object->pParam->pNext->paramValue = 0x01 << VCAL_ENC_PARAM_BASE64;
1377 object->pszValue[0] = (char *)malloc(str_len + 1);
1378 if ((object->pszValue[0]) == NULL) {
1379 vcal_free_vtree_memory(tree);
1385 if (sch->description != NULL) {
1386 memset(object->pszValue[0], 0, str_len + 1);
1387 memcpy(object->pszValue[0], sch->description, str_len);
1389 object->valueCount = 1;
1391 _DEBUG_INFO("description = %s", object->pszValue[0]);
1401 case VCAL_TYPE_LOCATION:
1403 _DEBUG_INFO("-------------------__cal_vcalendar_sch_vtree_add_object /VCAL_TYPE_LOCATION -------------\n");
1405 if (NULL != sch->location && strlen(sch->location) != 0) {
1406 object->property = VCAL_TYPE_LOCATION;
1407 str_len = strlen(sch->location);
1408 object->pParam = (VParam *) malloc(sizeof(VParam));
1409 if (object->pParam == NULL) {
1410 vcal_free_vtree_memory(tree);
1415 memset(object->pParam, 0, sizeof(VParam));
1417 object->pParam->parameter = VCAL_PARAM_CHARSET;
1418 object->pParam->paramValue = 0x01 << VCAL_CHARSET_PARAM_UTF_8;
1419 object->pParam->pNext = NULL;
1421 object->pParam->pNext = (VParam *) malloc(sizeof(VParam));
1422 if (object->pParam->pNext == NULL) {
1423 vcal_free_vtree_memory(tree);
1428 memset(object->pParam->pNext, 0, sizeof(VParam));
1430 object->pParam->pNext->parameter = VCAL_PARAM_ENCODING;
1431 object->pParam->pNext->paramValue = 0x01;
1433 object->pszValue[0] = (char *)malloc(str_len + 1);
1434 if ((object->pszValue[0]) == NULL) {
1435 vcal_free_vtree_memory(tree);
1441 if (sch->location != NULL) {
1442 memset(object->pszValue[0], 0, str_len + 1);
1443 memcpy(object->pszValue[0], sch->location, str_len);
1445 object->valueCount = 1;
1454 case VCAL_TYPE_DTSTART:
1456 _DEBUG_INFO("-------------------__cal_vcalendar_sch_vtree_add_object /VCAL_TYPE_DTSTART -------------\n");
1458 object->property = VCAL_TYPE_DTSTART;
1460 object->pszValue[0] = (char *)malloc(VCALENDAR_TIME_STR_LEN + 1);
1461 if ((object->pszValue[0]) == NULL) {
1462 vcal_free_vtree_memory(tree);
1468 cal_vcalendar_convert_tm_to_vdata_str(&sch->start_date_time, object->pszValue[0]);
1470 object->valueCount = 1;
1474 case VCAL_TYPE_DTEND:
1476 _DEBUG_INFO("-------------------__cal_vcalendar_sch_vtree_add_object /VCAL_TYPE_DTEND -------------\n");
1478 if (sch->cal_type == CALS_SCH_TYPE_TODO) {
1482 object->property = VCAL_TYPE_DTEND;
1484 object->pszValue[0] = (char *)malloc(VCALENDAR_TIME_STR_LEN + 1);
1485 if ((object->pszValue[0]) == NULL) {
1486 vcal_free_vtree_memory(tree);
1492 cal_vcalendar_convert_tm_to_vdata_str(&sch->end_date_time, object->pszValue[0]);
1494 object->valueCount = 1;
1498 // in Calendar sch data structure, there is no due data field
1499 // end_date_time is assigned to due date
1502 _DEBUG_INFO("-------------------__cal_vcalendar_sch_vtree_add_object /VCAL_TYPE_DUE -------------\n");
1504 if (sch->cal_type != CALS_SCH_TYPE_TODO) {
1508 object->property = VCAL_TYPE_DUE;
1510 object->pszValue[0] = (char *)malloc(VCALENDAR_TIME_STR_LEN + 1);
1511 if ((object->pszValue[0]) == NULL) {
1512 vcal_free_vtree_memory(tree);
1517 cal_vcalendar_convert_tm_to_vdata_str(&sch->end_date_time, object->pszValue[0]);
1519 object->valueCount = 1;
1523 case VCAL_TYPE_LAST_MODIFIED:
1525 _DEBUG_INFO("-------------------__cal_vcalendar_sch_vtree_add_object /VCAL_TYPE_LAST_MODIFIED -------------\n");
1527 object->property = obj_type;
1528 object->pszValue[0] = (char *)malloc(VCALENDAR_TIME_STR_LEN + 1);
1529 if ((object->pszValue[0]) == NULL) {
1530 vcal_free_vtree_memory(tree);
1545 cal_vcalendar_convert_tm_to_vdata_str(&now, object->pszValue[0]);
1547 object->valueCount = 1;
1551 case VCAL_TYPE_AALARM:
1553 _DEBUG_INFO("\n-------------------__cal_vcalendar_sch_vtree_add_object /VCAL_TYPE_AALARM -------------\n");
1555 if (sch->alarm_list != NULL) {
1556 object->property = VCAL_TYPE_AALARM;
1557 cal_alarm_info_t *tmp_alarm = ((cal_value *) sch->alarm_list->data)->user_data;
1559 object->pszValue[0] = (char *)malloc(VCALENDAR_TIME_STR_LEN + 1);
1560 if ((object->pszValue[0]) == NULL) {
1561 vcal_free_vtree_memory(tree);
1562 if (object != NULL) {
1570 // TODO: handle alarms(this is one alarm)
1571 struct tm *tm = __cal_vcalendar_compute_pre_time((struct tm *)&sch->start_date_time,
1572 &tmp_alarm->alarm_time, tmp_alarm->remind_tick, tmp_alarm->remind_tick_unit, &ttm);
1573 cal_vcalendar_convert_tm_to_vdata_str(tm, object->pszValue[0]);
1575 object->valueCount = 1;
1584 case VCAL_TYPE_RRULE:
1586 _DEBUG_INFO("\n-------------------__cal_vcalendar_sch_vtree_add_object /VCAL_TYPE_RRULE -------------\n");
1588 if (sch->repeat_term != CAL_REPEAT_NONE) {
1589 _DEBUG_INFO(" ------------------------ begine to create RRULE-------------------------- ");
1591 object->property = VCAL_TYPE_RRULE;
1593 char repeat_end_date[VCALENDAR_TIME_STR_LEN + 1] = { 0 };
1594 char week_day_string[VCALENDAR_TIME_STR_LEN + 1] = { 0 };
1595 cal_vcalendar_convert_tm_to_vdata_str(&sch->repeat_end_date, repeat_end_date);
1597 _DEBUG_INFO(" repeat_end_date = %s ", repeat_end_date);
1600 memset(str, 0, 100);
1602 switch (sch->repeat_term) {
1603 case CAL_REPEAT_EVERY_DAY:
1604 snprintf(str, sizeof(str), "D%d %s", sch->repeat_interval, repeat_end_date);
1607 case CAL_REPEAT_EVERY_WEEK:
1608 case CAL_REPEAT_EVERY_WEEKDAYS:
1609 __cal_vcalendar_get_week_day_string((struct tm *)&(sch->start_date_time), week_day_string);
1610 snprintf(str, sizeof(str), "W%d %s %s", sch->repeat_interval, week_day_string, repeat_end_date);
1613 case CAL_REPEAT_EVERY_MONTH:
1614 case CAL_REPEAT_EVERY_MONTH_DAY:
1615 snprintf(str, sizeof(str), "MD%d %s", sch->repeat_interval, repeat_end_date);
1618 case CAL_REPEAT_EVERY_YEAR:
1619 case CAL_REPEAT_EVERY_YEAR_DAY:
1620 snprintf(str, sizeof(str), "YM%d %s", sch->repeat_interval, repeat_end_date);
1626 object->valueCount = 1;
1628 object->pszValue[0] = (char *)malloc(strlen(str) + 1);
1629 if ((object->pszValue[0]) == NULL) {
1630 vcal_free_vtree_memory(tree);
1635 memset(object->pszValue[0], 0, (strlen(str) + 1));
1637 buf_len = g_strlcpy(object->pszValue[0], str, (strlen(str) + 1));
1638 if (buf_len >= (strlen(str) + 1)) {
1639 _DEBUG_ERROR("object->pszValue[0] buffer overflow !!");
1640 vcal_free_vtree_memory(tree);
1646 _DEBUG_INFO("RRULE = %s", object->pszValue[0]);
1656 case VCAL_TYPE_PRIORITY:
1658 _DEBUG_INFO("\n-------------------__cal_vcalendar_todo_vtree_add_object /VCAL_TYPE_PRIORITY -------------\n");
1660 object->property = VCAL_TYPE_PRIORITY;
1665 snprintf(str, sizeof(str), "%d", sch->priority);
1667 object->pszValue[0] = (char *)malloc(3);
1668 if ((object->pszValue[0]) == NULL) {
1669 vcal_free_vtree_memory(tree);
1675 memset(object->pszValue[0], 0, 3);
1677 buf_len = g_strlcpy(object->pszValue[0], str, 3);
1679 _DEBUG_ERROR("object->pszValue[0] buffer overflow !!");
1680 vcal_free_vtree_memory(tree);
1686 object->valueCount = 1;
1690 case VCAL_TYPE_STATUS:
1692 _DEBUG_INFO("\n-------------------__cal_vcalendar_todo_vtree_add_object /VCAL_TYPE_STATUS -------------\n");
1694 if (sch->cal_type != CALS_SCH_TYPE_TODO) {
1698 object->property = VCAL_TYPE_STATUS;
1700 object->pszValue[0] = (char *)malloc(20);
1701 if ((object->pszValue[0]) == NULL) {
1702 vcal_free_vtree_memory(tree);
1708 memset(object->pszValue[0], 0, 20);
1710 switch (sch->task_status) {
1711 case CALS_EVENT_STATUS_TENTATIVE:
1713 buf_len = g_strlcpy(object->pszValue[0], "TENTATIVE", 20);
1714 if (buf_len >= 20) {
1715 _DEBUG_ERROR("object->pszValue[0] buffer overflow !!");
1716 vcal_free_vtree_memory(tree);
1722 case CALS_EVENT_STATUS_CONFIRMED:
1724 buf_len = g_strlcpy(object->pszValue[0], "CONFIRMED", 20);
1725 if (buf_len >= 20) {
1726 _DEBUG_ERROR("object->pszValue[0] buffer overflow !!");
1727 vcal_free_vtree_memory(tree);
1733 case CALS_EVENT_STATUS_CANCELLED:
1735 buf_len = g_strlcpy(object->pszValue[0], "CANCELLED", 20);
1736 if (buf_len >= 20) {
1737 _DEBUG_ERROR("object->pszValue[0] buffer overflow !!");
1738 vcal_free_vtree_memory(tree);
1744 case CALS_TODO_STATUS_NEEDS_ACTION:
1746 buf_len = g_strlcpy(object->pszValue[0], "NEEDS-ACTION", 20);
1747 if (buf_len >= 20) {
1748 _DEBUG_ERROR("object->pszValue[0] buffer overflow !!");
1749 vcal_free_vtree_memory(tree);
1755 case CALS_TODO_STATUS_COMPLETED:
1757 buf_len = g_strlcpy(object->pszValue[0], "COMPLETED", 20);
1758 if (buf_len >= 20) {
1759 _DEBUG_ERROR("object->pszValue[0] buffer overflow !!");
1760 vcal_free_vtree_memory(tree);
1766 case CALS_TODO_STATUS_IN_PROCESS:
1768 buf_len = g_strlcpy(object->pszValue[0], "IN-PROCESS", 20);
1769 if (buf_len >= 20) {
1770 _DEBUG_ERROR("object->pszValue[0] buffer overflow !!");
1771 vcal_free_vtree_memory(tree);
1777 case CALS_TODO_STATUS_CANCELLED:
1779 buf_len = g_strlcpy(object->pszValue[0], "CANCELLED", 20);
1780 if (buf_len >= 20) {
1781 _DEBUG_ERROR("object->pszValue[0] buffer overflow !!");
1782 vcal_free_vtree_memory(tree);
1790 buf_len = g_strlcpy(object->pszValue[0], "NEEDS-ACTION", 20);
1791 if (buf_len >= 20) {
1792 _DEBUG_ERROR("object->pszValue[0] buffer overflow !!");
1793 vcal_free_vtree_memory(tree);
1801 object->valueCount = 1;
1810 // if current is the header of the list
1811 if (tree->pTop == NULL) {
1812 _DEBUG_INFO("\n--------tree->pTop = object--------------\n");
1813 tree->pTop = object;
1815 tree->pCur->pSibling = object;
1818 // the object is the current object
1819 tree->pCur = object;
1826 bool _cal_convert_sch_to_vcalendar(const cal_sch_full_t * sch_array, const int sch_count, char **vcal, cal_vCal_ver_t version)
1834 VTree *cal_tree = NULL;
1835 VTree *tmp_tree = NULL;
1837 vCalType obj_type[] = {
1839 VCAL_TYPE_DESCRIPTION,
1843 VCAL_TYPE_LAST_MODIFIED,
1845 VCAL_TYPE_CATEGORIES,
1853 assert((sch_array != NULL) && (vcal != NULL));
1855 cal_tree = (VTree *) malloc(sizeof(VTree));
1856 if (cal_tree == NULL)
1859 memset(cal_tree, 0, sizeof(VTree));
1861 cal_tree->treeType = VCALENDAR;
1862 cal_tree->pTop = NULL;
1863 cal_tree->pCur = NULL;
1864 cal_tree->pNext = NULL;
1866 VTree *tree = cal_tree;
1868 for (i = 0; i < sch_count; i++) {
1869 tmp_tree = (VTree *) malloc(sizeof(VTree));
1870 if (tmp_tree == NULL) {
1871 vcal_free_vtree_memory(cal_tree);
1875 memset(tmp_tree, 0, sizeof(VTree));
1877 if ((sch_array + i)->cal_type == CALS_SCH_TYPE_TODO) {
1878 tmp_tree->treeType = VTODO;
1879 obj_type[4] = VCAL_TYPE_DUE;
1881 tmp_tree->treeType = VEVENT;
1884 tmp_tree->pTop = NULL;
1885 tmp_tree->pCur = NULL;
1886 tmp_tree->pNext = NULL;
1889 while (obj_type[j]) {
1890 if (!__cal_vcalendar_sch_vtree_add_object(tmp_tree, sch_array + i, obj_type[j])) {
1891 vcal_free_vtree_memory(cal_tree);
1897 tree->pNext = tmp_tree;
1904 *vcal = vcal_encode(cal_tree);
1905 if (*vcal == NULL) {
1906 _DEBUG_ERROR("vcal_encode Failed");
1907 vcal_free_vtree_memory(cal_tree);
1911 vcal_free_vtree_memory(cal_tree);
1912 _DEBUG_TRACE("\n---------------------------exit _cal_convert_sch_to_vcalendar--------- -------------\n");