2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #define MAX_TYPE_NAME_LEN 50
22 #define MAX_PARAM_NAME_LEN 50
26 #define VFREE(obj) if(obj != NULL) { /*VDATA_TRACE("%p",obj);*/ free(obj); \
30 #define TRIM(obj) if(obj != NULL) {\
35 #define UPPER(obj,start,end) if(obj != NULL) {\
36 for(start = 0; start < end; start++)\
37 obj[start] = toupper(obj[start]);\
40 #define GO_NEXT_CHAR(current, rowData, addedCnt) {\
46 #define SET_PARAM_VALUE(PARAM, SZVALUE, LIST, LISTCNT, PARAMOBJ, PTYPE, ENC) {\
48 PARAM |= __VCardGetValue(SZVALUE, LIST, LISTCNT);\
49 if ( PARAM != UNKNOWN_NAME ) {\
50 PARAMOBJ->parameter = PTYPE;\
51 if(PTYPE == VCARD_PARAM_ENCODING)\
57 #define LENGTH_TYPE_LIST(obj, len) for(len =0; obj[len] != NULL; len++);
59 extern char* _VUnfoldingNoSpecNew( char *string );
61 /** GLOBAL VARIABLE DECLARATION AND INITIALIZATION */
63 char* pszCardTypeList[] =
65 "ADR", /* Delivery Address -> address*/
66 "AGENT", /* Agent -> assistant name, assistant number*/
67 "BDAY", /* Birthday -> birthday */
68 "BEGIN", /* BEGIN VCARD DELIMITER*/
69 "CATEGORIES", /* Categories is a multivalued attribute */
71 "EMAIL", /* Email -> email */
72 "END", /* END VCARD DELIMITER*/
73 "FN", /* Formatted Name -> display_name */
74 "GEO", /* Geographic Positioning*/
75 "KEY", /* Public Key*/
76 "LABEL", /* Label Address -> address*/
78 "MAILER", /* Email Program (Optional)*/
79 "N", /* Name -> name */
80 "NAME", /* Name -> name */
81 "NICKNAME", /* Nickname -> nickname */
82 "NOTE", /* Note -> note */
83 "ORG", /* Organization Name or Organizational unit -> department*/
84 "PHOTO", /* Photograph -> caller id*/
87 "REV", /* Last Revision(combination of calendar date & time)*/
88 "ROLE", /* Role or occupation */
92 "TEL", /* Telephone -> phone number */
93 "TITLE", /* Job Title -> job title */
95 "UID", /* Unique Identifier*/
96 "URL", /* URL -> web address */
97 "VERSION", /* Version*/
103 char* pszCardParamList[] =
113 /** Encoding value */
114 ValueObj pEncList[] =
117 {"BASE64", 0x00000002},
118 {"QUOTED-PRINTABLE", 0x00000004},
119 {"7BIT", 0x00000008},
123 /** Character set value */
124 ValueObj pCharsetList[] =
126 {"UTF-8", 0x00000001},
127 {"UTF-16", 0x00000002},
128 {"ISO-8859-1", 0x00000004}
132 ValueObj pValueList[] =
134 {"BINARY", 0x00000001},
135 {"BOOLEAN", 0x00000002},
136 {"DATE", 0x00000004},
137 {"DATE-TIME", 0x00000008},
138 {"FLOAT", 0x00000010},
139 {"INTEGER", 0x00000020},
140 {"PHONE-NUMBER", 0x00000040},
141 {"TEXT", 0x00000080},
142 {"TIME", 0x00000100},
145 {"UTC-OFFSET", 0x00000800},
146 {"VCARD", 0x00001000}
150 ValueObj pTypeList[] =
152 {"AIFF", 0x00000001},
155 {"CELL", 0x00000008},
157 {"WORK", 0x00000020},
160 {"HOME", 0x00000100},
161 {"INTL", 0x00000200},
162 {"INTERNET", 0x00000400},
163 {"ISDN", 0x00000800},
164 {"JPEG", 0x00001000},
165 {"MOBILE", 0x00002000},
166 {"MODEM", 0x00004000},
168 {"PAGER", 0x00010000},
169 {"PARCEL", 0x00020000},
173 {"POSTAL", 0x00200000},
174 {"PREF", 0x00400000},
175 {"VIDEO", 0x00800000},
176 {"VOICE", 0x01000000},
177 {"WAVE", 0x02000000},
178 {"WBMP", 0x04000000},
183 /** FUNCTION DECLARATION */
184 int __VCardGetName(char*, char**, int);
185 int __VCardGetValue(char*, const ValueObj*, int);
186 int __VCardGetTypeName(char*, int*, int*);
187 int __VCardGetParamName(char*, int*, int*);
188 int __VIsVcardFile(char*, int);
189 char* __VCardGetParamVal(char*,int*, int*);
190 char* __VCardGetTypeVal(char*, int*, int*, int, VObject*);
191 char* __VCardTypeEncode(VObject*, char*);
192 char* __VCardParamEncode(VObject*, int*);
194 #ifdef VDATA_GROUPNAME_SUPPORTED
196 #endif // VDATA_GROUPNAME_SUPPORTED
200 * __VCardGetName() compares the string and vCard type, parameter name.
202 * @param szString Name which will compare
203 * @param pszList[] Name list of vCard type and param
204 * @param size Number of total element of list
206 * @return index The index in the list
209 __VCardGetName(char* szString, char* pszList[], int size)
212 int high, low, i, diff;
217 for(; high >= low; diff<0 ? (low = i+1):(high = i-1)) {
218 i = ( low + high ) / 2;
219 if((diff = strcmp( pszList[i], szString )) == 0) /* success: found it */
227 * __VCardGetValue() compares the string and vCard type, parameter value.
229 * @param szString Value which will compare
230 * @param list[] Value list of vCard param
231 * @param size Number of total element of list
233 * @return flag The value's flag.
236 __VCardGetValue( char* szString, const ValueObj list[], int size)
239 int i = 0, diff = -1;
240 char* szTemp = szString;
242 SysRequireEx(szString, UNKNOWN_NAME);
243 SysRequireEx(size > 0, UNKNOWN_NAME);
245 UPPER(szTemp,i,strlen(szTemp));
247 for(i = 0; i < size-1; i++)
249 VDATA_TRACE(" i : %d",i);
250 VDATA_TRACE(" for loop %d < %d, list[%d] : %p, list[%d].szName : %p",i,size,i,list[i],i,list[i].szName);
251 VDATA_TRACE(" i : %d",i);
252 if(list[i].szName != NULL)
254 VDATA_TRACE(" list[%d].szName != NULL",i);
255 VDATA_TRACE(" before strcmp %s %s",list[i].szName,szTemp);
256 VDATA_TRACE(" before strcmp %d",strcmp(list[i].szName, szTemp));
257 if((diff = strcmp(list[i].szName, szTemp)) == 0) /* success: found it */
259 VDATA_TRACE(" return %d",list[i].flag);
263 VDATA_TRACE(" after strcmp %s %s",list[i].szName,szTemp);
266 VDATA_TRACE(" return UNKNOWN_NAME");
272 * __VCardGetTypeName() fine the type name and returns the index number
274 * @param pVCardRaw The raw data
275 * @param pStatus Decoder status
276 * @param pDLen retrived length
278 * @return res The index in type list
281 __VCardGetTypeName(char* pVCardRaw, int* pStatus, int* pDLen)
286 char name[MAX_TYPE_NAME_LEN+1]={0,};
288 #ifdef VDATA_GROUPNAME_SUPPORTED
289 char* szGroupName = NULL;
290 #endif // VDATA_GROUPNAME_SUPPORTED
292 SysRequireEx(pVCardRaw, UNKNOWN_NAME);
299 GO_NEXT_CHAR(c, pVCardRaw, pDLen);
302 * TYPE NAME's length is must be less than MAX_TYPE_NAME_LEN.
303 * If TYPE NAME's value is over MAX_TYPE_NAME_LEN, return UNKNOWN_NAME.
304 * And then Decoding Step shoud not be changed.
306 if(index >= MAX_TYPE_NAME_LEN) {
307 *pStatus = VCARD_TYPE_NAME_STATUS;
313 * There is a delimeter between TYPE NAME and next element(=Param, or Type Value).
314 * If VTYPE_TOKEN_SEMICOLON or VTYPE_TOKEN_COLON is faced with,
315 * find TYPE NAME's value in pszCardTypeList, and then return searched result.
317 if ((c == VTYPE_TOKEN_SEMICOLON ) || ( c == VTYPE_TOKEN_COLON)) {
321 res = __VCardGetName( name, (char**)pszCardTypeList, VCARD_TYPE_NUM );
324 /** current version not support grouping vcard type */
325 else if ( c == VTYPE_TOKEN_DOT ) {
326 #ifdef VDATA_GROUPNAME_SUPPORTED
328 szGroupName = ( char* ) calloc(1, index+1 );
329 if(szGroupName != NULL){
330 strncpy( szGroupName, name, index );
331 gszGroupName = szGroupName;
337 * There is no new line in TYPE NAME.
338 * If new line character is faced with, return UNKNOWN_NAME;
340 else if ( ( c == '\r' ) || ( c == '\n' ) )
343 *pStatus = VCARD_TYPE_NAME_STATUS;
347 else if(_VIsSpace(c));
348 else name[index++] = c;
355 if ( c == VTYPE_TOKEN_SEMICOLON )
357 * This case next token is parameter. So set VCARD_PARAM_NAME_STATUS step.
359 *pStatus = VCARD_PARAM_NAME_STATUS;
361 if(res != UNKNOWN_NAME)
363 * This case next string is value. So set VCARD_TYPE_VALUE_STATUS step.
365 *pStatus = VCARD_TYPE_VALUE_STATUS;
368 * In current step, TYPE NAME is invalid. So Try to get TYPE NAME again from next position.
370 *pStatus = VCARD_TYPE_NAME_STATUS;
377 * __VCardGetParamName() fine the param name and returns the index number
379 * @param pVCardRaw The raw data
380 * @param pStatus Decoder status
381 * @param pDLen retrived length
383 * @return res The index in type list
386 __VCardGetParamName( char* pVCardRaw, int* pStatus, int* pDLen )
392 char name[MAX_PARAM_NAME_LEN+1]={0,};
393 char* pTemp = pVCardRaw;
395 SysRequireEx( pVCardRaw, UNKNOWN_NAME );
402 GO_NEXT_CHAR(c, pVCardRaw, pDLen);
405 * PARAM NAME's length is must be less than MAX_PARAM_NAME_LEN.
406 * If PARAM NAME's value is over MAX_PARAM_NAME_LEN, return UNKNOWN_NAME.
407 * And then Decoding Step shoud not be changed.
409 if(index >= MAX_PARAM_NAME_LEN) {
410 *pStatus = VCARD_TYPE_NAME_STATUS;
416 * There is a delimeter between PARAM NAME and next element(=Param, or Param Value).
417 * If VTYPE_TOKEN_EQUAL is faced with,
418 * find PARAM NAME's value in pszCardParamList, and then return searched result.
420 if(c == VTYPE_TOKEN_EQUAL) {
423 UPPER(name, i, index);
424 res = __VCardGetName( name, ( char** )pszCardParamList, VCARD_PARAM_NUM );
425 if(res==UNKNOWN_NAME){
428 *pStatus = VCARD_PARAM_VALUE_STATUS;
432 * This case, There is no parameter type. Only Parameter Value.
433 * In VCARD_PARAM_NAME_STATUS status, VTYPE_TOKEN_COLON means that anything parameter is no more.
434 * so set next step to VCARD_PARAM_VALUE_STATUS.
436 * Ex) TEL;WORK:+12341234
437 * ------ ":" next is TEL TYPE's value.
439 * VCARD_PARAM_NAME_STATUS(current) -> VCARD_PARAM_VALUE_STATUS
440 * -> VCARD_TYPE_VALUE_STATUS -> MOVE TO NEXT TYPE
442 else if(c == VTYPE_TOKEN_COLON) {
443 *pStatus = VCARD_PARAM_VALUE_STATUS;
450 * This case, There is no parameter type. Only Parameter Value.
451 * In VCARD_PARAM_NAME_STATUS status, VTYPE_TOKEN_SEMICOLON means that there is a next parameter.
452 * so set next step to VCARD_PARAM_NAME_STATUS.
454 * Ex) TEL;WORK;PREF:+12341234
455 * ------ ":" next is TEL TYPE's value.
457 * VCARD_PARAM_NAME_STATUS(current) -> VCARD_PARAM_NAME_STATUS
458 * -> VCARD_PARAM_VALUE_STATUS -> VCARD_TYPE_VALUE_STATUS -> MOVE TO NEXT TYPE
460 else if(c == VTYPE_TOKEN_SEMICOLON) {
461 *pStatus = VCARD_PARAM_NAME_STATUS;
467 else if((c == '\r') || (c == '\n') || (_VIsSpace(c)));
476 __VCardFreeVTreeMemory(VTree * pTree)
479 VObject* pCurObj = NULL;
480 VObject* pNextObj = NULL;
482 VTree* pCurTree = NULL;
483 VTree* pNextTree = NULL;
485 VParam* pCurParam = NULL;
486 VParam* pNextParam = NULL;
491 SysRequireEx( pTree->treeType == VCARD, false );
492 SysRequireEx( pTree != NULL, false );
493 VDATA_TRACE("vcard_free_vtree_memory() entered.");
495 if (pTree->treeType != VCARD)
505 pNextTree = pCurTree->pNext;
506 pCurObj = pCurTree->pTop;
511 pNextObj = pCurObj->pSibling;
512 count = pCurObj->valueCount;
514 for ( i = 0; i < count; i++ ) {
515 VFREE( pCurObj->pszValue[i]);
518 #ifdef VDATA_GROUPNAME_SUPPORTED
519 if ( pCurObj->pszGroupName )
520 VFREE( pCurObj->pszGroupName );
523 if ( pCurObj->pParam )
526 pCurParam = pCurObj->pParam;
528 while(pCurParam != NULL)
530 pNextParam = pCurParam->pNext;
531 VDATA_TRACE("pNEXT ==> %p", pCurParam->pNext);
532 VDATA_TRACE("pPARAM ==> %p", pCurParam->parameter);
533 VDATA_TRACE("pVALUE ==> %p", pCurParam->paramValue);
534 VDATA_TRACE("pCurParam : %p", pCurParam);
535 VDATA_TRACE("pCurParam->parameter : %d", pCurParam->parameter);
536 VDATA_TRACE("pCurParam->paramValue : %d", pCurParam->paramValue);
537 if(pNextParam != NULL) {
538 VDATA_TRACE("pNextParam : %p", pNextParam);
539 VDATA_TRACE("pNextParam->parameter : %d", pNextParam->parameter);
540 VDATA_TRACE("pNextParam->paramValue : %d", pNextParam->paramValue);
543 pCurParam = pNextParam;
552 pCurTree = pNextTree;
555 VDATA_TRACE("exit vcard_free_vtree_memory");
561 * __VCardGetParamVal() fine the param value and returns value.
563 * @param pVCardRaw The raw data
564 * @param pStatus Decoder status
565 * @param pDLen retrived length
567 * @return buffer The result value
570 __VCardGetParamVal( char* pVCardRaw, int* pStatus, int* pDLen )
576 char* pTemp = pVCardRaw;
578 SysRequireEx( pVCardRaw, NULL );
581 GO_NEXT_CHAR(c, pVCardRaw, pDLen);
584 case VTYPE_TOKEN_SEMICOLON :
585 *pStatus = VCARD_PARAM_NAME_STATUS;
587 case VTYPE_TOKEN_COLON :
588 *pStatus = VCARD_TYPE_VALUE_STATUS;
590 case VTYPE_TOKEN_COMMA :
591 *pStatus = VCARD_PARAM_VALUE_STATUS;
594 if( c == VTYPE_TOKEN_SEMICOLON
595 || c == VTYPE_TOKEN_COLON
596 || c == VTYPE_TOKEN_COMMA
604 pBuf = (char *)calloc(1, len);
608 memset(pBuf, 0x00, len);
609 memcpy(pBuf, pTemp, len-1);
617 * __VCardGetTypeVal() fine the type value and returns value.
619 * @param pVCardRaw The raw data
620 * @param status Decoder status
621 * @return buffer The result value
624 __VCardGetTypeVal( char* pVCardRaw, int* pStatus, int* pDLen, int enc, VObject* pType)
631 bool bEscape = false;
635 char* pTemp = pVCardRaw;
636 char* pTmpBuf = NULL;
640 SysRequireEx( pVCardRaw, NULL );
644 GO_NEXT_CHAR(c, pVCardRaw, pDLen);
646 if( c == 0x00) break;
650 /** This case means that there are more type's value. */
651 if ( c == VTYPE_TOKEN_SEMICOLON && bEscape == false ) {
653 if((pBuf = (char *)calloc(1, len)) == NULL) return NULL;
655 memset(pBuf, 0x00, len);
656 memcpy(pBuf,pTemp,len-1);
661 *pStatus = VCARD_TYPE_VALUE_STATUS;
663 /** Base 64 Decoding */
664 if((enc & pEncList[1].flag) || (enc & pEncList[0].flag)) {
666 bufferCount = (len * 6 / 8) + 2;
668 if((pTmpBuf = (char *)calloc(1, bufferCount)) == NULL) {
673 memset(pTmpBuf, 0x00, bufferCount);
674 num = _VB64Decode(pTmpBuf, pBuf);
676 if(pType != NULL) pType->numOfBiData = num;
684 /** Quoted Printable Decoding */
685 if(enc & pEncList[2].flag) {
690 if(pBuf[i] == '\n' || pBuf[i] == '\r'){
692 if(pBuf[i] == '\n'|| pBuf[i] == '\r')
695 if(pBuf[j-1] == '=') j--;
698 pBuf[j++] = pBuf[i++];
711 else if(bEscape == true && c != VTYPE_TOKEN_SEMICOLON )
713 else if((c == '\r') || (c == '\n'))
717 if(c2 == '=' && (enc & pEncList[2].flag))
720 if((c1 == '\r') || (c1 == '\n'))
727 else if(__VCardGetTypeName(pVCardRaw, &Status, &Len) != UNKNOWN_NAME)
730 if((pBuf = (char *)calloc(1, len)) == NULL) return NULL;
732 memset(pBuf, 0x00, len);
733 memcpy(pBuf,pTemp,len-1);
738 *pStatus = VCARD_TYPE_NAME_STATUS;
742 if((c1 == '\r') || (c1 == '\n')) {
747 if((enc & pEncList[1].flag) || (enc & pEncList[0].flag)) {
749 bufferCount = (len * 6 / 8) + 5;
751 if((pTmpBuf = (char *)calloc(1, bufferCount)) == NULL) {
756 memset(pTmpBuf, 0x00, bufferCount);
757 num = _VB64Decode(pTmpBuf, pBuf);
760 pType->numOfBiData = num;
768 if(enc & pEncList[2].flag) {
774 if(pBuf[i] == '\n' || pBuf[i] == '\r')
777 if(pBuf[i] == '\n' || pBuf[i] == '\r')
780 if(pBuf[j-1] == '=') j--;
783 pBuf[j++] = pBuf[i++];
801 VCardGetTypeValue( int index )
804 VDATA_TRACE("VCardGetTypeValue() enter..\n");
806 return pTypeList[index].flag;
810 VCardGetValValue( int index )
813 VDATA_TRACE("VCardGetValValue() enter..\n");
815 return pValueList[index].flag;
819 VCardGetEncValue( int index )
822 VDATA_TRACE("VCardGetEncValue() enter..\n");
824 return pEncList[index].flag;
828 VCardGetCharsetValue( int index )
831 VDATA_TRACE("VCardGetCharsetValue() enter..\n");
833 return pCharsetList[index].flag;
837 * vcard_decode() decode the vCard data and returns vObject struct
839 * @param pVCardRaw The raw data
840 * @return vObject The result value
843 vcard_decode( char *pCardRaw )
846 char* szValue = NULL;
847 char* szCardBegin = NULL;
848 char* pCardRawTmp = NULL;
849 VTree* pVCard = NULL;
850 VParam* pTmpParam = NULL;
851 VObject* pTemp = NULL;
856 int status = VCARD_TYPE_NAME_STATUS;
861 int param_status = false;
862 int numberedParam = 0;
864 //int start_status = 0;
867 bool vcard_ended = false;
869 SysRequireEx(pCardRaw != NULL, NULL);
870 len = strlen(pCardRaw);
871 VDATA_TRACE("length of pCardRaw = %d", len);
873 pCardRaw = _VUnfoldingNoSpecNew(pCardRaw);
874 if (pCardRaw == NULL) {
877 pCardRawTmp = pCardRaw;
878 len = _VManySpace2Space( pCardRaw );
880 VDATA_TRACE("ret value of _VManySpace2Space = %d", len);
882 if(!__VIsVcardFile(pCardRaw, CHECK_START)) {
893 if((c == '\0') || done)
897 case VCARD_TYPE_NAME_STATUS:
899 type = __VCardGetTypeName(pCardRaw, &status, &dLen);
907 case VCARD_TYPE_BEGIN:
913 if ( ( pVCard = ( VTree* )calloc(1, sizeof( VTree ) ) ) == NULL ) {
918 memset(pVCard,0x00, sizeof(VTree));
921 szCardBegin = __VCardGetTypeVal(pCardRaw, &status, &dLen, enc, NULL);
925 pVCard->treeType = VCARD;
928 pVCard->pNext = NULL;
933 if(strstr(pCardRaw,"VCARD") != NULL) {
939 status = VCARD_TYPE_NAME_STATUS;
949 if(UNKNOWN_NAME == type || type < 0) {
950 status = VCARD_TYPE_NAME_STATUS;
954 if ( ( pTemp = ( VObject* )calloc(1, sizeof( VObject ) ) ) == NULL ) {
958 memset( pTemp, 0, sizeof( VObject ) );
959 pTemp->property = type;
961 if ( pVCard->pTop == NULL ) {
962 pVCard->pTop = pTemp;
963 pVCard->pCur = pTemp;
966 pVCard->pCur->pSibling = pTemp;
967 pVCard->pCur = pTemp;
974 param_status = false;
977 #ifdef VDATA_GROUPNAME_SUPPORTED
978 if ( gszGroupName != NULL )
979 pVCard->pCur->pszGroupName = gszGroupName;
983 case VCARD_PARAM_NAME_STATUS:
986 param = __VCardGetParamName( pCardRaw, &status, &dLen );
989 if ( param_status != true ) {
991 if ( ( pTmpParam = ( VParam* )calloc(1, sizeof( VParam ) ) ) == NULL )
995 pVCard->pCur->pParam = pTmpParam;
996 memset( pTmpParam, 0x00, sizeof( VParam ) );
997 VDATA_TRACE("pTmpParam : %p", pTmpParam);
1001 if ( ( pTmpParam->pNext = ( VParam* )calloc(1, sizeof( VParam ) ) ) == NULL )
1004 pTmpParam = pTmpParam->pNext;
1005 memset( pTmpParam, 0x00, sizeof(VParam));
1006 VDATA_TRACE("pTmpParam : %p", pTmpParam);
1009 pTmpParam->parameter = param;
1012 case VCARD_PARAM_VALUE_STATUS:
1015 switch ( pTmpParam->parameter )
1017 case VCARD_PARAM_TYPE:
1018 szValue = __VCardGetParamVal( pCardRaw, &status, &dLen );
1019 numberedParam |= __VCardGetValue( szValue, pTypeList, VCARD_TYPE_PARAM_NUM );
1021 case VCARD_PARAM_VALUE:
1022 szValue = __VCardGetParamVal( pCardRaw, &status, &dLen );
1023 numberedParam |= __VCardGetValue( szValue, pValueList, VCARD_VALUE_PARAM_NUM );
1025 case VCARD_PARAM_ENCODING:
1026 szValue = __VCardGetParamVal( pCardRaw, &status, &dLen );
1027 numberedParam |= __VCardGetValue( szValue, pEncList, VCARD_ENCODE_PARAM_NUM );
1028 enc = numberedParam;
1030 case VCARD_PARAM_CHARSET:
1031 szValue = __VCardGetParamVal( pCardRaw, &status, &dLen );
1032 numberedParam |= __VCardGetValue( szValue, pCharsetList, VCARD_CHARSET_PARAM_NUM );
1034 case VCARD_PARAM_CONTEXT:
1035 case VCARD_PARAM_LANGUAGE:
1036 // prevent 7605 08.03.13
1037 szValue = __VCardGetParamVal( pCardRaw, &status, &dLen );
1041 szValue = __VCardGetParamVal( pCardRaw, &status, &dLen );
1043 SET_PARAM_VALUE(numberedParam, szValue, pTypeList, VCARD_TYPE_PARAM_NUM, pTmpParam, VCARD_PARAM_TYPE, enc);
1044 SET_PARAM_VALUE(numberedParam, szValue, pValueList, VCARD_VALUE_PARAM_NUM, pTmpParam, VCARD_PARAM_VALUE, enc);
1045 SET_PARAM_VALUE(numberedParam, szValue, pEncList, VCARD_ENCODE_PARAM_NUM, pTmpParam, VCARD_PARAM_ENCODING, enc);
1046 SET_PARAM_VALUE(numberedParam, szValue, pCharsetList, VCARD_CHARSET_PARAM_NUM, pTmpParam, VCARD_PARAM_CHARSET, enc);
1055 VDATA_TRACE("%d, %s, %p",numberedParam, szValue, pTmpParam);
1056 pTmpParam->paramValue = numberedParam;
1057 pTmpParam->pNext = NULL;
1061 case VCARD_TYPE_VALUE_STATUS:
1063 temp = __VCardGetTypeVal( pCardRaw, &status, &dLen, enc, pVCard->pCur);
1065 if(valueCount <= VDATA_VALUE_COUNT_MAX) {
1066 pVCard->pCur->pszValue[valueCount] = temp;
1068 pVCard->pCur->valueCount = valueCount;
1080 if(pVCard->pTop == NULL)
1093 __VCardFreeVTreeMemory(pVCard);
1099 * vcard_encode() compares the string and vCard type, parameter value.
1101 * @param pVCardRaw Data which will be encoded
1102 * @return char * Encoded result
1105 vcard_encode( VTree *pVCardRaw )
1108 char* pVCardRes = NULL;
1109 VObject * pTmpObj = NULL;
1114 int lenTypeList = 0;
1116 LENGTH_TYPE_LIST(pszCardTypeList, lenTypeList);
1118 SysRequireEx(pVCardRaw != NULL, NULL);
1119 SysRequireEx(pVCardRaw->pTop != NULL, NULL);
1120 SysRequireEx(pVCardRaw->pTop->property >= 0, NULL);
1121 SysRequireEx(pVCardRaw->pTop->property < lenTypeList, NULL);
1122 SysRequireEx(pVCardRaw->treeType == VCARD, NULL);
1123 SysRequireEx(pVCardRaw->pTop->valueCount > 0, NULL);
1125 //VDATA_TRACE("START %d %d", pVCardRaw->pTop->property, lenTypeList);
1127 for(;cnt < pVCardRaw->pTop->valueCount;cnt++) {
1129 if(pVCardRaw->pTop->pszValue[cnt] == NULL) {
1130 VDATA_TRACE("pVCardRaw->pTop->valueCount : %d",pVCardRaw->pTop->valueCount);
1131 VDATA_TRACE("pVCardRaw->pTop->pszValue[%d] : %s", cnt, pVCardRaw->pTop->pszValue[cnt]);
1136 total += sizeof(char) * (14 + 14);
1137 if ( ( pVCardRes = ( char * )calloc(1, total ) ) == NULL )
1139 VDATA_TRACE( "vcard_encode:calloc failed\n" );
1144 memcpy( pVCardRes, "BEGIN:VCARD\r\n", 14 );
1145 g_strlcat( pVCardRes, "VERSION:2.1\r\n", total - strlen(pVCardRes));
1147 pTmpObj = pVCardRaw->pTop;
1154 if ( ( pTemp = __VCardTypeEncode( pTmpObj, pszCardTypeList[pTmpObj->property] ) ) != NULL )
1156 len = strlen( pTemp );
1157 total += len + sizeof(char) * 10;
1158 if ( ( pVCardRes = ( char* )realloc( pVCardRes, total ) ) == NULL )
1160 VDATA_TRACE( "vcard_encode():realloc failed\n");
1167 if( strncmp(pTemp,"VERSION", strlen("VERSION")) != 0)
1168 g_strlcat(pVCardRes, pTemp, total - strlen(pVCardRes));
1170 VDATA_TRACE("pTemp : %s", pTemp);
1176 if ( pTmpObj->pSibling != NULL )
1177 pTmpObj = pTmpObj->pSibling;
1182 total += sizeof(char) * 12;
1183 if ( ( pVCardRes = ( char * )realloc( pVCardRes, total ) ) == NULL )
1185 VDATA_TRACE( "vcard_encode:realloc failed\n");
1189 g_strlcat( pVCardRes, "END:VCARD\r\n", total - strlen(pVCardRes));
1196 * VIsVcardFile() verify VCard file.
1198 * @param pVCardRaw Data which will be encoded
1199 * @return int result (true or false)
1202 __VIsVcardFile(char *pCardRaw, int mode)
1205 bool rtnValue = true;
1206 char *pszVcardBegin = "BEGIN:VCARD";
1211 for(i=0; i < 11; i++)
1212 if(*pszVcardBegin++ != *pCardRaw++)
1225 * vCardTypeEncoder() compares the string and vCard type, parameter value.
1227 * @param typeObj Data which will be encoded
1228 * @param type Name of the type
1229 * @return char * Encoded result
1232 __VCardTypeEncode( VObject *pTypeObj, char *pType )
1237 char* szTypeValue = NULL;
1240 char* pEncode = NULL;
1245 len = strlen( pType );
1246 biLen = pTypeObj->numOfBiData;
1248 #ifdef VDATA_GROUPNAME_SUPPORTED
1249 if ( pTypeObj->pszGroupName != NULL )
1251 len += strlen( pTypeObj->pszGroupName ) + 1;
1253 #endif // VDATA_GROUPNAME_SUPPORTED
1254 if ( ( szTypeValue = ( char * )calloc(1, total += ( len+1 ) ) ) == NULL )
1256 VDATA_TRACE( "__VCardTypeEncode():calloc failed\n");
1260 memset( szTypeValue, '\0', ( len+1 ) );
1261 #ifdef VDATA_GROUPNAME_SUPPORTED
1262 if ( pTypeObj->pszGroupName != NULL )
1264 g_strlcat( szTypeValue, pTypeObj->pszGroupName, total - strlen(szTypeValue));
1265 g_strlcat( szTypeValue, ".", total - strlen(szTypeValue));
1267 #endif // VDATA_GROUPNAME_SUPPORTED
1268 g_strlcat( szTypeValue, pType, total - strlen(szTypeValue));
1270 pTemp = __VCardParamEncode( pTypeObj, &enc );
1271 if ( pTemp != NULL )
1273 len = strlen( pTemp );
1274 if ( ( szTypeValue = ( char * )realloc( szTypeValue, ( total += len ) ) ) == NULL )
1276 VDATA_TRACE( "__VCardTypeEncode():realloc failed\n");
1282 g_strlcat( szTypeValue, pTemp, total - strlen(szTypeValue));
1287 if ( ( szTypeValue = ( char * )realloc( szTypeValue, ( total += 2 ) ) ) == NULL )
1293 g_strlcat( szTypeValue, ":", total - strlen(szTypeValue));
1297 if(strcmp(pType, pszCardTypeList[19]) != 0) {
1298 for ( i = 0; i < pTypeObj->valueCount; i++ ) {
1300 if(pTypeObj->pszValue[i] != NULL)
1301 len += strlen( pTypeObj->pszValue[i] );
1308 for ( i = 0; i < pTypeObj->valueCount; i++ ) {
1311 if ( ( pEncode = ( char * )calloc(1, len+20 ) ) == NULL ) {
1317 memset( pEncode, '\0', len+20 );
1319 if(strcmp(pType, pszCardTypeList[19]) != 0) {
1320 g_strlcat( pEncode, pTypeObj->pszValue[i], len+20 - strlen(pEncode));
1324 memcpy(pEncode, pTypeObj->pszValue[i], biLen);
1328 strncpy( buf, pTypeObj->pszValue[i], 999 );
1330 g_strlcat( pEncode, ";", len+20 - strlen(pEncode));
1331 g_strlcat( pEncode, buf, len+20 - strlen(pEncode));
1335 if(strcmp(pType, pszCardTypeList[19]) != 0) {
1337 g_strlcat( pEncode, "\0\0", len+20 - strlen(pEncode) );
1338 len = strlen( pEncode );
1345 if ( enc & pEncList[2].flag ) {
1346 if((pRes = (char *)calloc(1, len * 6 + 10)) == NULL) {
1353 _VQPEncode( pRes, pEncode );
1356 else if(enc & pEncList[1].flag ) {
1357 if((pRes = (char *)calloc(1, (len * 8 / 6) + 4)) == NULL){
1364 memset( pRes, '\0', ( ( len * 8 / 6 ) + 4 ) );
1365 _VB64Encode( pRes, pEncode, biLen );
1369 if((pRes = (char *)calloc(1, len+30)) == NULL) {
1375 memset( pRes, '\0', ( len + 30 ) );
1378 memcpy( pRes, pEncode, len );
1383 if((pRes = (char *)realloc(pRes, strlen(pRes) + 3)) == NULL)
1390 g_strlcat( pRes, "\r\n", 2);
1392 len = strlen( pRes );
1394 if ((szTypeValue = (char *)realloc(szTypeValue, (total += (len+3)))) == NULL) {
1401 g_strlcat(szTypeValue, pRes, total - strlen(szTypeValue));
1403 if(strcmp(pType, pszCardTypeList[19]) != 0) {
1404 _VRLSpace( szTypeValue );
1405 _VRTSpace( szTypeValue );
1414 * __VCardParamEncode() Parameter Encoding.
1416 * @param pTypeObj Data which will be encoded
1417 * @param pEnc Name of the type
1420 __VCardParamEncode(VObject* pTypeObj, int* pEnc)
1428 char* szParam = NULL;
1429 VParam* pTemp = NULL;
1430 ValueObj* pList = NULL;
1432 /** Paramter initialize. */
1433 pTemp = pTypeObj->pParam;
1435 /** Momory Allocation for parameter string. */
1437 if ((szParam = (char*)calloc(1, len+=2)) == NULL)
1442 memset(szParam, 0x00, 2);
1445 /** appending pamaters. */
1448 if(pTemp == NULL) break;
1452 /** Expand szParam string. For appending.*/
1453 if((szParam = (char *)realloc(szParam, len += 15)) == NULL)
1459 /** appending paramter name. */
1460 g_strlcat( szParam, ";", len - strlen(szParam) );
1461 if(pTemp->parameter != VCARD_PARAM_TYPE) {
1462 g_strlcat( szParam, pszCardParamList[pTemp->parameter], len - strlen(szParam));
1463 g_strlcat( szParam, "=", len - strlen(szParam));
1466 /** Set Parameter Value name. */
1467 switch ( pTemp->parameter )
1469 case VCARD_PARAM_ENCODING:
1470 *pEnc = pTemp->paramValue;
1471 shift = VCARD_ENCODE_PARAM_NUM;
1472 pList = pEncList; bSupported = true;
1474 case VCARD_PARAM_TYPE:
1475 shift = VCARD_TYPE_PARAM_NUM;
1476 pList = pTypeList; bSupported = true;
1478 case VCARD_PARAM_VALUE:
1479 shift = VCARD_VALUE_PARAM_NUM;
1480 pList = pValueList; bSupported = true;
1482 case VCARD_PARAM_CHARSET:
1483 shift = VCARD_CHARSET_PARAM_NUM;
1484 pList = pCharsetList; bSupported = true;
1487 if ( ( szParam = ( char* )realloc( szParam, 5 ) ) == NULL )
1492 g_strlcat( szParam, "NONE", 5 - strlen(szParam) );
1495 /** exchage parameter value's to string.*/
1496 if(bSupported == true) {
1498 for(i = 0, sNum = 0x00000001; i < shift; i++) {
1500 if(pTemp->paramValue & sNum) {
1501 if((szParam = (char *)realloc(szParam, ( len += (strlen(pList[i].szName) + 2)))) == NULL)
1507 g_strlcat( szParam, pList[i].szName, len - strlen(szParam));
1508 g_strlcat( szParam, "; ", len - strlen(szParam));
1515 /** remove semicolon from tail. */
1516 for(i = strlen( szParam ); i > 0 ; i--) {
1518 if ( szParam[i] == ' ' && szParam[i-1] == ';' ) {
1519 szParam[i-1] = '\0';
1524 if ( pTemp->pNext != NULL )
1525 pTemp = pTemp->pNext;
1534 vcard_free_vtree_memory(VTree * pTree)
1543 return __VCardFreeVTreeMemory(pTree);