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.
22 #define MAX_TYPE_NAME_LEN 50
23 #define MAX_PARAM_NAME_LEN 50
27 #define VFREE(obj) if(obj != NULL) { /*VDATA_TRACE("%p",obj);*/ free(obj); \
31 #define TRIM(obj) if(obj != NULL) {\
36 #define UPPER(obj,start,end) if(obj != NULL) {\
37 for(start = 0; start < end; start++)\
38 obj[start] = toupper(obj[start]);\
41 #define GO_NEXT_CHAR(current, rowData, addedCnt) {\
47 #define SET_PARAM_VALUE(PARAM, SZVALUE, LIST, LISTCNT, PARAMOBJ, PTYPE, ENC) {\
49 PARAM |= __VMsgGetValue(SZVALUE, LIST, LISTCNT);\
50 if ( PARAM != UNKNOWN_NAME ) {\
51 PARAMOBJ->parameter = PTYPE;\
52 if(PTYPE == VMSG_PARAM_ENCODING)\
58 #define LENGTH_TYPE_LIST(obj, len) for(len =0; obj[len] != NULL; len++);
60 extern char* _VUnfoldingNoSpecNew( char *string );
62 /** GLOBAL VARIABLE DECLARATION AND INITIALIZATION */
64 char* pszMsgTypeList[] =
81 char* pszMsgParamList[] =
92 ValueObj pMsgEncList[] =
95 {"BASE64", 0x00000002},
96 {"QUOTED-PRINTABLE", 0x00000004},
101 /** Character set value */
102 ValueObj pMsgCharsetList[] =
104 {"UTF-8", 0x00000001},
105 {"UTF-16", 0x00000002},
106 {"ISO-8859-1", 0x00000004}
110 ValueObj pMsgValueList[] =
112 {"BINARY", 0x00000001},
113 {"BOOLEAN", 0x00000002},
114 {"DATE", 0x00000004},
115 {"DATE-TIME", 0x00000008},
116 {"FLOAT", 0x00000010},
117 {"INTEGER", 0x00000020},
118 {"PHONE-NUMBER", 0x00000040},
119 {"TEXT", 0x00000080},
120 {"TIME", 0x00000100},
123 {"UTC-OFFSET", 0x00000800},
128 ValueObj pMsgTypeList[] =
130 {"AIFF", 0x00000001},
133 {"CELL", 0x00000008},
135 {"WORK", 0x00000020},
138 {"HOME", 0x00000100},
139 {"INTL", 0x00000200},
140 {"INTERNET", 0x00000400},
141 {"ISDN", 0x00000800},
142 {"JPEG", 0x00001000},
143 {"MOBILE", 0x00002000},
144 {"MODEM", 0x00004000},
146 {"PAGER", 0x00010000},
147 {"PARCEL", 0x00020000},
151 {"POSTAL", 0x00200000},
152 {"PREF", 0x00400000},
153 {"VIDEO", 0x00800000},
154 {"VOICE", 0x01000000},
155 {"WAVE", 0x02000000},
156 {"WBMP", 0x04000000},
161 /** FUNCTION DECLARATION */
162 int __VMsgGetName(char*, char**, int);
163 int __VMsgGetValue(char*, const ValueObj*, int);
164 int __VMsgGetTypeName(char*, int*, int*);
165 int __VMsgGetParamName(char*, int*, int*);
166 int __VIsVmsgFile(char*, int);
167 char* __VMsgGetParamVal(char*,int*, int*);
168 char* __VMsgGetTypeVal(char*, int*, int*, int, VObject*);
169 char* __VMsgTypeEncode(VObject*, char*);
170 char* __VMsgParamEncode(VObject*, int*);
174 * __VMsgGetName() compares the string and vMsg type, parameter name.
176 * @param szString Name which will compare
177 * @param pszList[] Name list of vMsg type and param
178 * @param size Number of total element of list
180 * @return index The index in the list
183 __VMsgGetName(char* szString, char* pszList[], int size)
186 int high, low, i, diff = 0;
191 for(; high >= low; diff<0 ? (low = i+1):(high = i-1)) {
192 i = ( low + high ) / 2;
193 if((diff = strcmp( pszList[i], szString )) == 0) /* success: found it */
201 * __VMsgGetValue() compares the string and vMsg type, parameter value.
203 * @param szString Value which will compare
204 * @param list[] Value list of vMsg param
205 * @param size Number of total element of list
207 * @return flag The value's flag.
210 __VMsgGetValue( char* szString, const ValueObj list[], int size)
213 int i = 0, diff = -1;
214 char* szTemp = szString;
216 SysRequireEx(szString, UNKNOWN_NAME);
217 SysRequireEx(size > 0, UNKNOWN_NAME);
219 UPPER(szTemp,i,strlen(szTemp));
221 for(i = 0; i < size-1; i++)
223 VDATA_TRACE(" i : %d",i);
224 VDATA_TRACE(" for loop %d < %d, list[%d] : %p, list[%d].szName : %p",i,size,i,list[i],i,list[i].szName);
225 VDATA_TRACE(" i : %d",i);
226 if(list[i].szName != NULL)
228 VDATA_TRACE(" list[%d].szName != NULL",i);
229 VDATA_TRACE(" before strcmp %s %s",list[i].szName,szTemp);
230 VDATA_TRACE(" before strcmp %d",strcmp(list[i].szName, szTemp));
231 if((diff = strcmp(list[i].szName, szTemp)) == 0) /* success: found it */
233 VDATA_TRACE(" return %d",list[i].flag);
237 VDATA_TRACE(" after strcmp %s %s",list[i].szName,szTemp);
240 VDATA_TRACE(" return UNKNOWN_NAME");
246 * __VMsgGetTypeName() fine the type name and returns the index number
248 * @param pVMsgRaw The raw data
249 * @param pStatus Decoder status
250 * @param pDLen retrived length
252 * @return res The index in type list
255 __VMsgGetTypeName(char* pVMsgRaw, int* pStatus, int* pDLen)
260 char name[MAX_TYPE_NAME_LEN+1]={0,};
262 SysRequireEx(pVMsgRaw, UNKNOWN_NAME);
269 GO_NEXT_CHAR(c, pVMsgRaw, pDLen);
272 * TYPE NAME's length is must be less than MAX_TYPE_NAME_LEN.
273 * If TYPE NAME's value is over MAX_TYPE_NAME_LEN, return UNKNOWN_NAME.
274 * And then Decoding Step shoud not be changed.
276 if(index >= MAX_TYPE_NAME_LEN) {
277 *pStatus = VMSG_TYPE_NAME_STATUS;
283 * There is a delimeter between TYPE NAME and next element(=Param, or Type Value).
284 * If VTYPE_TOKEN_SEMICOLON or VTYPE_TOKEN_COLON is faced with,
285 * find TYPE NAME's value in pszMsgTypeList, and then return searched result.
287 if ((c == VTYPE_TOKEN_SEMICOLON ) || ( c == VTYPE_TOKEN_COLON)) {
291 res = __VMsgGetName( name, (char**)pszMsgTypeList, VMSG_TYPE_NUM );
295 * There is no new line in TYPE NAME.
296 * If new line character is faced with, return UNKNOWN_NAME;
298 else if ( ( c == '\r' ) || ( c == '\n' ) )
301 *pStatus = VMSG_TYPE_NAME_STATUS;
305 else if(_VIsSpace(c));
306 else name[index++] = c;
313 if ( c == VTYPE_TOKEN_SEMICOLON )
315 * This case next token is parameter. So set VMSG_PARAM_NAME_STATUS step.
317 *pStatus = VMSG_PARAM_NAME_STATUS;
320 if(res != UNKNOWN_NAME)
322 * This case next string is value. So set VMSG_TYPE_VALUE_STATUS step.
324 *pStatus = VMSG_TYPE_VALUE_STATUS;
327 * In current step, TYPE NAME is invalid. So Try to get TYPE NAME again from next position.
329 *pStatus = VMSG_TYPE_NAME_STATUS;
336 * __VMsgGetParamName() fine the param name and returns the index number
338 * @param pVMsgRaw The raw data
339 * @param pStatus Decoder status
340 * @param pDLen retrived length
342 * @return res The index in type list
345 __VMsgGetParamName( char* pVMsgRaw, int* pStatus, int* pDLen )
351 char name[MAX_PARAM_NAME_LEN+1]={0,};
352 char* pTemp = pVMsgRaw;
354 SysRequireEx( pVMsgRaw, UNKNOWN_NAME );
361 GO_NEXT_CHAR(c, pVMsgRaw, pDLen);
364 * PARAM NAME's length is must be less than MAX_PARAM_NAME_LEN.
365 * If PARAM NAME's value is over MAX_PARAM_NAME_LEN, return UNKNOWN_NAME.
366 * And then Decoding Step shoud not be changed.
368 if(index >= MAX_PARAM_NAME_LEN) {
369 *pStatus = VMSG_TYPE_NAME_STATUS;
375 * There is a delimeter between PARAM NAME and next element(=Param, or Param Value).
376 * If VTYPE_TOKEN_EQUAL is faced with,
377 * find PARAM NAME's value in pszMsgParamList, and then return searched result.
379 if(c == VTYPE_TOKEN_EQUAL) {
382 UPPER(name, i, index);
383 res = __VMsgGetName( name, ( char** )pszMsgParamList, VMSG_PARAM_NUM );
384 if(res==UNKNOWN_NAME){
387 *pStatus = VMSG_PARAM_VALUE_STATUS;
391 * This case, There is no parameter type. Only Parameter Value.
392 * In VMSG_PARAM_NAME_STATUS status, VTYPE_TOKEN_COLON means that anything parameter is no more.
393 * so set next step to VMSG_PARAM_VALUE_STATUS.
395 * Ex) TEL;WORK:+12341234
396 * ------ ":" next is TEL TYPE's value.
398 * VMSG_PARAM_NAME_STATUS(current) -> VMSG_PARAM_VALUE_STATUS
399 * -> VMSG_TYPE_VALUE_STATUS -> MOVE TO NEXT TYPE
401 else if(c == VTYPE_TOKEN_COLON) {
402 *pStatus = VMSG_PARAM_VALUE_STATUS;
409 * This case, There is no parameter type. Only Parameter Value.
410 * In VMSG_PARAM_NAME_STATUS status, VTYPE_TOKEN_SEMICOLON means that there is a next parameter.
411 * so set next step to VMSG_PARAM_NAME_STATUS.
413 * Ex) TEL;WORK;PREF:+12341234
414 * ------ ":" next is TEL TYPE's value.
416 * VMSG_PARAM_NAME_STATUS(current) -> VMSG_PARAM_NAME_STATUS
417 * -> VMSG_PARAM_VALUE_STATUS -> VMSG_TYPE_VALUE_STATUS -> MOVE TO NEXT TYPE
419 else if(c == VTYPE_TOKEN_SEMICOLON) {
420 *pStatus = VMSG_PARAM_NAME_STATUS;
426 else if((c == '\r') || (c == '\n') || (_VIsSpace(c)));
435 __VMsgFreeVTreeMemory(VTree * pTree)
438 VObject* pCurObj = NULL;
439 VObject* pNextObj = NULL;
441 VTree* pCurTree = NULL;
442 VTree* pNextTree = NULL;
444 VParam* pCurParam = NULL;
445 VParam* pNextParam = NULL;
450 SysRequireEx( pTree->treeType == VMESSAGE, false );
451 SysRequireEx( pTree != NULL, false );
452 VDATA_TRACE("vmsg_free_vtree_memory() entered.");
454 if (pTree->treeType != VMESSAGE)
464 pNextTree = pCurTree->pNext;
465 pCurObj = pCurTree->pTop;
470 pNextObj = pCurObj->pSibling;
471 count = pCurObj->valueCount;
473 for ( i = 0; i < count; i++ ) {
474 VFREE( pCurObj->pszValue[i]);
477 if ( pCurObj->pParam )
480 pCurParam = pCurObj->pParam;
482 while(pCurParam != NULL)
484 pNextParam = pCurParam->pNext;
485 VDATA_TRACE("pNEXT ==> %p", pCurParam->pNext);
486 VDATA_TRACE("pPARAM ==> %p", pCurParam->parameter);
487 VDATA_TRACE("pVALUE ==> %p", pCurParam->paramValue);
488 VDATA_TRACE("pCurParam : %p", pCurParam);
489 VDATA_TRACE("pCurParam->parameter : %d", pCurParam->parameter);
490 VDATA_TRACE("pCurParam->paramValue : %d", pCurParam->paramValue);
491 if(pNextParam != NULL) {
492 VDATA_TRACE("pNextParam : %p", pNextParam);
493 VDATA_TRACE("pNextParam->parameter : %d", pNextParam->parameter);
494 VDATA_TRACE("pNextParam->paramValue : %d", pNextParam->paramValue);
497 pCurParam = pNextParam;
506 pCurTree = pNextTree;
509 VDATA_TRACE("exit vmsg_free_vtree_memory");
515 * __VMsgGetParamVal() fine the param value and returns value.
517 * @param pVMsgRaw The raw data
518 * @param pStatus Decoder status
519 * @param pDLen retrived length
521 * @return buffer The result value
524 __VMsgGetParamVal( char* pVMsgRaw, int* pStatus, int* pDLen )
530 char* pTemp = pVMsgRaw;
532 SysRequireEx( pVMsgRaw, NULL );
535 GO_NEXT_CHAR(c, pVMsgRaw, pDLen);
538 case VTYPE_TOKEN_SEMICOLON :
539 *pStatus = VMSG_PARAM_NAME_STATUS;
541 case VTYPE_TOKEN_COLON :
542 *pStatus = VMSG_TYPE_VALUE_STATUS;
544 case VTYPE_TOKEN_COMMA :
545 *pStatus = VMSG_PARAM_VALUE_STATUS;
548 if( c == VTYPE_TOKEN_SEMICOLON
549 || c == VTYPE_TOKEN_COLON
550 || c == VTYPE_TOKEN_COMMA
555 if(len < 1 || (pBuf = (char *)calloc(1, len)) == NULL)
557 memset(pBuf, 0x00, len);
558 memcpy( pBuf, pTemp, len-1 );
566 * __VMsgGetTypeVal() fine the type value and returns value.
568 * @param pVMsgRaw The raw data
569 * @param status Decoder status
570 * @return buffer The result value
573 __VMsgGetTypeVal( char* pVMsgRaw, int* pStatus, int* pDLen, int enc, VObject* pType)
580 bool bEscape = false;
584 char* pTemp = pVMsgRaw;
585 char* pTmpBuf = NULL;
589 SysRequireEx( pVMsgRaw, NULL );
590 VDATA_TRACE("pVMsgRaw: %s", pVMsgRaw);
593 GO_NEXT_CHAR(c, pVMsgRaw, pDLen);
600 /** This case means that there are more type's value. */
601 if ( c == VTYPE_TOKEN_SEMICOLON && bEscape == false )
603 if((pBuf = (char *)calloc(1, len)) == NULL)
606 memset(pBuf, 0x00, len);
607 memcpy(pBuf,pTemp,len-1);
612 *pStatus = VMSG_TYPE_VALUE_STATUS;
614 /** Base 64 Decoding */
615 if((enc & pMsgEncList[1].flag) || (enc & pMsgEncList[0].flag))
618 bufferCount = (len * 6 / 8) + 2;
620 if((pTmpBuf = (char *)calloc(1, bufferCount)) == NULL)
626 memset(pTmpBuf, 0x00, bufferCount);
627 num = _VB64Decode(pTmpBuf, pBuf);
630 pType->numOfBiData = num;
638 /** Quoted Printable Decoding */
639 if(enc & pMsgEncList[2].flag)
646 if(pBuf[i] == '\n' || pBuf[i] == '\r')
649 if(pBuf[i] == '\n'|| pBuf[i] == '\r')
656 pBuf[j++] = pBuf[i++];
669 else if(bEscape == true && c != VTYPE_TOKEN_SEMICOLON )
671 else if((c == '\r') || (c == '\n'))
675 if(c2 == '=' && (enc & pMsgEncList[2].flag))
678 if((c1 == '\r') || (c1 == '\n'))
685 else if(__VMsgGetTypeName(pVMsgRaw, &Status, &Len) != UNKNOWN_NAME)
687 if((pBuf = (char *)calloc(1, len)) == NULL)
690 memset(pBuf, 0x00, len);
691 memcpy(pBuf, pTemp, len-1);
695 VDATA_TRACE("pVMsgRaw: %s", pVMsgRaw);
696 *pStatus = VMSG_TYPE_NAME_STATUS;
700 if((c1 == '\r') || (c1 == '\n'))
706 if((enc & pMsgEncList[1].flag) || (enc & pMsgEncList[0].flag))
709 bufferCount = (len * 6 / 8) + 5;
711 if((pTmpBuf = (char *)calloc(1, bufferCount)) == NULL)
717 memset(pTmpBuf, 0x00, bufferCount);
718 num = _VB64Decode(pTmpBuf, pBuf);
721 pType->numOfBiData = num;
729 if(enc & pMsgEncList[2].flag)
736 if(pBuf[i] == '\n' || pBuf[i] == '\r')
739 if(pBuf[i] == '\n' || pBuf[i] == '\r')
742 if(pBuf[j-1] == '=') j--;
745 pBuf[j++] = pBuf[i++];
764 VMsgGetTypeValue( int index )
767 VDATA_TRACE("VMsgGetTypeValue() enter..\n");
769 return pMsgTypeList[index].flag;
773 VMsgGetValValue( int index )
776 VDATA_TRACE("VMsgGetValValue() enter..\n");
778 return pMsgValueList[index].flag;
782 VMsgGetEncValue( int index )
785 VDATA_TRACE("VMsgGetEncValue() enter..\n");
787 return pMsgEncList[index].flag;
791 VMsgGetCharsetValue( int index )
794 VDATA_TRACE("VMsgGetCharsetValue() enter..\n");
796 return pMsgCharsetList[index].flag;
800 * vmsg_decode() decode the vMsg data and returns vObject struct
802 * @param pVMsgRaw The raw data
803 * @return vObject The result value
806 vmsg_decode( char *pMsgRaw )
810 char* szValue = NULL;
811 char* szMsgBegin = NULL;
812 char* pMsgRawTmp = NULL;
814 VTree* pVBody = NULL;
815 VTree* pCurrent = NULL;
816 VTree* pVCard = NULL;
817 VParam* pTmpParam = NULL;
818 VObject* pTemp = NULL;
823 int status = VMSG_TYPE_NAME_STATUS;
828 int param_status = false;
829 int numberedParam = 0;
831 int start_status = 0;
834 bool vmsg_ended = false;
836 SysRequireEx(pMsgRaw != NULL, NULL);
837 len = strlen(pMsgRaw);
838 VDATA_TRACE("length of pCardRaw = %d", len);
840 len = _VUnfoldingNoSpec(pMsgRaw, VMESSAGE);
841 pMsgRawTmp = pMsgRaw;
842 len = _VManySpace2Space( pMsgRaw );
844 VDATA_TRACE("ret value of _VManySpace2Space = %d", len);
846 if(!__VIsVmsgFile(pMsgRaw, CHECK_START)) {
856 if((c == '\0') || done)
860 case VMSG_TYPE_NAME_STATUS:
862 type = __VMsgGetTypeName(pMsgRaw, &status, &dLen);
864 if(type == VMSG_TYPE_BEGIN)
874 case VMSG_TYPE_BEGIN:
877 szMsgBegin = __VMsgGetTypeVal(pMsgRaw, &status, &dLen, enc, NULL);
880 if(szMsgBegin == NULL)
883 if(!strncmp(szMsgBegin, "VCARD", strlen("VCARD")))
885 VDATA_TRACE("pVTree: %s", pVTree);
886 pVCard = vcard_decode(pVTree);
887 pCurrent->pNext = pVCard;
890 dLen = ((strstr(pMsgRaw,"END:VCARD") + 9) - pMsgRaw);
897 if(start_status == 1)
903 if(!strncmp(szMsgBegin, "VMSG", strlen("VMSG")))
905 if ( ( pVMsg = ( VTree* )calloc( 1, sizeof( VTree ) ) ) == NULL )
910 memset(pVMsg,0x00, sizeof(VTree));
912 pVMsg->treeType = VMESSAGE;
919 else if(!strncmp(szMsgBegin, "VBODY", strlen("VBODY")))
921 if ( ( pVBody = ( VTree* )calloc( 1, sizeof( VTree ) ) ) == NULL )
927 memset(pVBody,0x00, sizeof(VTree));
928 pVBody->treeType = VBODY;
931 pVBody->pNext = NULL;
932 pCurrent->pNext = pVBody;
943 //szMsgBegin = __VMsgGetTypeVal(pMsgRaw, &status, &dLen, enc, NULL);
945 if(!strncmp(pMsgRaw,"VMSG", strlen("VMSG")))
952 status = VMSG_TYPE_NAME_STATUS;
955 VDATA_TRACE("pMsgRaw:%s", pMsgRaw);
963 if(UNKNOWN_NAME == type || type < 0) {
964 status = VMSG_TYPE_NAME_STATUS;
968 if ( ( pTemp = ( VObject* )calloc( 1, sizeof( VObject ) ) ) == NULL )
973 memset( pTemp, 0, sizeof( VObject ) );
974 pTemp->property = type;
976 if ( pCurrent->pTop == NULL ) {
977 pCurrent->pTop = pTemp;
978 pCurrent->pCur = pTemp;
981 pCurrent->pCur->pSibling = pTemp;
982 pCurrent->pCur = pTemp;
989 param_status = false;
993 case VMSG_PARAM_NAME_STATUS:
996 param = __VMsgGetParamName( pMsgRaw, &status, &dLen );
999 if ( param_status != true ) {
1001 if ( ( pTmpParam = ( VParam* )calloc( 1, sizeof( VParam ) ) ) == NULL )
1004 param_status = true;
1005 pCurrent->pCur->pParam = pTmpParam;
1006 memset( pTmpParam, 0x00, sizeof( VParam ) );
1007 VDATA_TRACE("pTmpParam : %p", pTmpParam);
1011 if ( ( pTmpParam->pNext = ( VParam* )calloc( 1, sizeof( VParam ) ) ) == NULL )
1014 pTmpParam = pTmpParam->pNext;
1015 memset( pTmpParam, 0x00, sizeof(VParam));
1016 VDATA_TRACE("pTmpParam : %p", pTmpParam);
1019 pTmpParam->parameter = param;
1022 case VMSG_PARAM_VALUE_STATUS:
1025 switch ( pTmpParam->parameter )
1027 case VMSG_PARAM_TYPE:
1028 szValue = __VMsgGetParamVal( pMsgRaw, &status, &dLen );
1029 numberedParam |= __VMsgGetValue( szValue, pMsgTypeList, VMSG_TYPE_PARAM_NUM );
1031 case VMSG_PARAM_VALUE:
1032 szValue = __VMsgGetParamVal( pMsgRaw, &status, &dLen );
1033 numberedParam |= __VMsgGetValue( szValue, pMsgValueList, VMSG_VALUE_PARAM_NUM );
1035 case VMSG_PARAM_ENCODING:
1036 szValue = __VMsgGetParamVal( pMsgRaw, &status, &dLen );
1037 numberedParam |= __VMsgGetValue( szValue, pMsgEncList, VMSG_ENCODE_PARAM_NUM );
1038 enc = numberedParam;
1040 case VMSG_PARAM_CHARSET:
1041 szValue = __VMsgGetParamVal( pMsgRaw, &status, &dLen );
1042 numberedParam |= __VMsgGetValue( szValue, pMsgCharsetList, VMSG_CHARSET_PARAM_NUM );
1044 case VMSG_PARAM_CONTEXT:
1045 case VMSG_PARAM_LANGUAGE:
1046 // prevent 7605 08.03.13
1047 szValue = __VMsgGetParamVal( pMsgRaw, &status, &dLen );
1051 szValue = __VMsgGetParamVal( pMsgRaw, &status, &dLen );
1053 SET_PARAM_VALUE(numberedParam, szValue, pMsgTypeList, VMSG_TYPE_PARAM_NUM, pTmpParam, VMSG_PARAM_TYPE, enc);
1054 SET_PARAM_VALUE(numberedParam, szValue, pMsgValueList, VMSG_VALUE_PARAM_NUM, pTmpParam, VMSG_PARAM_VALUE, enc);
1055 SET_PARAM_VALUE(numberedParam, szValue, pMsgEncList, VMSG_ENCODE_PARAM_NUM, pTmpParam, VMSG_PARAM_ENCODING, enc);
1056 SET_PARAM_VALUE(numberedParam, szValue, pMsgCharsetList, VMSG_CHARSET_PARAM_NUM, pTmpParam, VMSG_PARAM_CHARSET, enc);
1065 VDATA_TRACE("%d, %s, %p",numberedParam, szValue, pTmpParam);
1066 pTmpParam->paramValue = numberedParam;
1067 pTmpParam->pNext = NULL;
1071 case VMSG_TYPE_VALUE_STATUS:
1073 temp = __VMsgGetTypeVal( pMsgRaw, &status, &dLen, enc, pCurrent->pCur);
1075 if(valueCount <= VDATA_VALUE_COUNT_MAX) {
1076 pCurrent->pCur->pszValue[valueCount] = temp;
1078 pCurrent->pCur->valueCount = valueCount;
1079 VDATA_TRACE("object property: %d, value: %s", pCurrent->pCur->property, pCurrent->pCur->pszValue[valueCount - 1]);
1088 VDATA_TRACE("pMsgRawTmp: %s", pMsgRawTmp);
1089 //VFREE(pMsgRawTmp);
1091 if(pVMsg->pTop == NULL)
1093 VDATA_TRACE("pVMsg->Top: NULL");
1098 VDATA_TRACE("vmsg_ended: false");
1109 __VMsgFreeVTreeMemory(pVMsg);
1115 * vmsg_encode() compares the string and vMsg type, parameter value.
1117 * @param pVMsgRaw Data which will be encoded
1118 * @return char * Encoded result
1121 vmsg_encode( VTree *pVMsgRaw )
1124 char* pVMsgRes = NULL;
1125 char* pTmpVMsgRes = NULL;
1126 VTree* pTmpTree = NULL;
1127 VObject * pTmpObj = NULL;
1133 for(;cnt < pVMsgRaw->pTop->valueCount;cnt++) {
1135 if(pVMsgRaw->pTop->pszValue[cnt] == NULL) {
1136 VDATA_TRACE("pVMsgRaw->pTop->valueCount : %d",pVMsgRaw->pTop->valueCount);
1137 VDATA_TRACE("pVMsgRaw->pTop->pszValue[%d] : %s", cnt, pVMsgRaw->pTop->pszValue[cnt]);
1143 pTmpTree = pVMsgRaw;
1144 pTmpObj = pVMsgRaw->pTop;
1148 switch(pTmpTree->treeType)
1156 if ( ( pVMsgRes = ( char * )calloc( 1, sizeof( char ) * ( total += 13 ) ) ) == NULL )
1158 VDATA_TRACE( "vmsg_encode:calloc failed\n" );
1162 memcpy( pVMsgRes, "BEGIN:VMSG\r\n", 13 );
1166 if ( ( pTmpVMsgRes = ( char * )realloc( pVMsgRes, sizeof( char ) * ( total += 14 ) ) ) == NULL )
1168 VDATA_TRACE( "vmsg_encode:realloc failed\n" );
1174 pVMsgRes = pTmpVMsgRes;
1175 g_strlcat( pVMsgRes, "BEGIN:VBODY\r\n", 13);
1187 if ( ( pTemp = __VMsgTypeEncode( pTmpObj, pTmpObj->property == VCARD_TYPE_TEL ? "TEL" : pszMsgTypeList[pTmpObj->property] ) ) != NULL )
1189 if(pTmpTree->treeType == VCARD)
1191 char* encoded = NULL;
1193 encoded = vcard_encode(pTmpTree);
1194 if (encoded == NULL) {
1195 VDATA_TRACE( "vcard_encode() failed\n");
1202 len= strlen(encoded);
1204 if ( ( pTmpVMsgRes = ( char* )realloc( pVMsgRes, ( total += len+10 ) ) ) == NULL )
1206 VDATA_TRACE( "vmsg_encode():realloc failed\n");
1214 pVMsgRes = pTmpVMsgRes;
1215 g_strlcat(pVMsgRes, encoded, len+10);
1216 VDATA_TRACE("pTemp : %s", encoded);
1223 len = strlen( pTemp );
1225 if ( ( pTmpVMsgRes = ( char* )realloc( pVMsgRes, ( total += len+10 ) ) ) == NULL )
1227 VDATA_TRACE( "vmsg_encode():realloc failed\n");
1233 pVMsgRes = pTmpVMsgRes;
1234 g_strlcat(pVMsgRes, pTemp, len+10);
1235 VDATA_TRACE("pTemp : %s", pTemp);
1238 if ( pTmpObj->pSibling != NULL )
1239 pTmpObj = pTmpObj->pSibling;
1248 switch(pTmpTree->treeType)
1251 if ( ( pTmpVMsgRes = ( char * )realloc( pVMsgRes, ( total += 12 ) ) ) == NULL )
1254 VDATA_TRACE( "vcal_encode():realloc failed\n");
1258 pVMsgRes = pTmpVMsgRes;
1259 g_strlcat( pVMsgRes, "END:VBODY\r\n", 12);
1270 if ( pTmpTree->pNext != NULL )
1271 pTmpTree = pTmpTree->pNext;
1274 pTmpObj = pTmpTree->pTop;
1277 if ( ( pTmpVMsgRes = ( char * )realloc( pVMsgRes, ( total += 11 ) ) ) == NULL )
1279 VDATA_TRACE( "vmsg_encode:realloc failed\n");
1285 pVMsgRes = pTmpVMsgRes;
1286 g_strlcat( pVMsgRes, "END:VMSG\r\n", 11);
1293 * VIsVmsgFile() verify VMsg file.
1295 * @param pVMsgRaw Data which will be encoded
1296 * @return int result (true or false)
1299 __VIsVmsgFile(char *pMsgRaw, int mode)
1302 bool rtnValue = true;
1303 char *pszVmsgBegin = "BEGIN:VMSG";
1308 for(i=0; i < 10; i++)
1309 if(*pszVmsgBegin++ != *pMsgRaw++)
1322 * vMsgTypeEncoder() compares the string and vMsg type, parameter value.
1324 * @param typeObj Data which will be encoded
1325 * @param type Name of the type
1326 * @return char * Encoded result
1329 __VMsgTypeEncode( VObject *pTypeObj, char *pType )
1334 char* szTypeValue = NULL;
1337 char* pEncode = NULL;
1342 len = strlen( pType );
1343 biLen = pTypeObj->numOfBiData;
1345 if ( ( szTypeValue = ( char * )calloc( 1, total += ( len+1 ) ) ) == NULL )
1347 VDATA_TRACE( "__VMsgTypeEncode():calloc failed\n");
1351 memset( szTypeValue, '\0', ( len+1 ) );
1352 g_strlcat( szTypeValue, pType, len+1);
1354 pTemp = __VMsgParamEncode( pTypeObj, &enc );
1355 if ( pTemp != NULL )
1357 len = strlen( pTemp );
1358 if ( ( szTypeValue = ( char * )realloc( szTypeValue, ( total += len ) ) ) == NULL )
1360 VDATA_TRACE( "__VMsgTypeEncode():realloc failed\n");
1366 g_strlcat( szTypeValue, pTemp, len);
1371 if ( ( szTypeValue = ( char * )realloc( szTypeValue, ( total += 2 ) ) ) == NULL )
1377 g_strlcat( szTypeValue, ":", 2 );
1381 if(strcmp(pType, pszMsgTypeList[6]) != 0) {
1382 for ( i = 0; i < pTypeObj->valueCount; i++ ) {
1384 if(pTypeObj->pszValue[i] != NULL)
1385 len += strlen( pTypeObj->pszValue[i] );
1392 for ( i = 0; i < pTypeObj->valueCount; i++ ) {
1396 if ( ( pEncode = ( char * )calloc( 1, len+20 ) ) == NULL )
1403 memset( pEncode, '\0', len+20 );
1405 if(strcmp(pType, pszMsgTypeList[6]) != 0)
1407 g_strlcat( pEncode, pTypeObj->pszValue[i], 20 );
1411 memcpy(pEncode, pTypeObj->pszValue[i], biLen);
1416 strncpy( buf, pTypeObj->pszValue[i], 999 );
1418 g_strlcat( pEncode, ";" , len+20);
1419 g_strlcat( pEncode, buf , len+20);
1423 if(strcmp(pType, pszMsgTypeList[6]) != 0) {
1425 g_strlcat( pEncode, "\0\0", 2);
1426 len = strlen( pEncode );
1433 if ( enc & pMsgEncList[2].flag ) {
1434 if((pRes = (char *)calloc(1, len * 6 + 10)) == NULL) {
1441 _VQPEncode( pRes, pEncode );
1444 else if(enc & pMsgEncList[1].flag )
1446 if((pRes = (char *)calloc(1, (len * 8 / 6) + 48)) == NULL)
1454 memset( pRes, '\0', ( ( len * 8 / 6 ) + 48 ) );
1455 _VB64Encode( pRes, pEncode, biLen );
1456 VDATA_TRACE( "Origin Size: %d, Allocated Size %d, Coverted Size: %d\n", biLen, ( len * 8 / 6 ) + 48, strlen(pRes));
1461 if((pRes = (char *)calloc(1, len+30)) == NULL)
1468 memset( pRes, '\0', ( len + 30 ) );
1471 memcpy( pRes, pEncode, len );
1476 if((pRes = (char *)realloc(pRes, strlen(pRes) + 3)) == NULL)
1483 g_strlcat( pRes, "\r\n", strlen(pRes) + 2);
1485 len = strlen( pRes );
1487 if ((szTypeValue = (char *)realloc(szTypeValue, (total += (len+3)))) == NULL) {
1494 g_strlcat(szTypeValue, pRes, total - 1);
1496 if(strcmp(pType, pszMsgTypeList[6]) != 0) {
1497 _VRLSpace( szTypeValue );
1498 _VRTSpace( szTypeValue );
1508 * __VMsgParamEncode() Parameter Encoding.
1510 * @param pTypeObj Data which will be encoded
1511 * @param pEnc Name of the type
1514 __VMsgParamEncode(VObject* pTypeObj, int* pEnc)
1522 char* szParam = NULL;
1523 VParam* pTemp = NULL;
1524 ValueObj* pList = NULL;
1526 /** Paramter initialize. */
1527 pTemp = pTypeObj->pParam;
1529 /** Momory Allocation for parameter string. */
1531 if ((szParam = (char*)calloc(1, len+=2)) == NULL)
1536 memset(szParam, 0x00, 2);
1539 /** appending pamaters. */
1542 if(pTemp == NULL) break;
1546 /** Expand szParam string. For appending.*/
1547 if((szParam = (char *)realloc(szParam, len += 15)) == NULL)
1553 /** appending paramter name. */
1554 g_strlcat( szParam, ";" , len);
1555 if(pTemp->parameter != VMSG_PARAM_TYPE) {
1556 g_strlcat( szParam, pszMsgParamList[pTemp->parameter], len);
1557 g_strlcat( szParam, "=", len);
1560 /** Set Parameter Value name. */
1561 switch ( pTemp->parameter )
1563 case VMSG_PARAM_ENCODING:
1564 *pEnc = pMsgEncList[pTemp->paramValue].flag;
1565 shift = VMSG_ENCODE_PARAM_NUM;
1566 pList = pMsgEncList; bSupported = true;
1568 case VMSG_PARAM_TYPE:
1569 shift = VMSG_TYPE_PARAM_NUM;
1570 pList = pMsgTypeList; bSupported = true;
1572 case VMSG_PARAM_VALUE:
1573 shift = VMSG_VALUE_PARAM_NUM;
1574 pList = pMsgValueList; bSupported = true;
1576 case VMSG_PARAM_CHARSET:
1577 shift = VMSG_CHARSET_PARAM_NUM;
1578 pList = pMsgCharsetList; bSupported = true;
1581 if ( ( szParam = ( char* )realloc( szParam, 5 ) ) == NULL )
1586 g_strlcat( szParam, "NONE", strlen("NONE"));
1589 /** exchage parameter value's to string.*/
1590 if(bSupported == true) {
1592 for(i = 0, sNum = 0x00000001; i < shift; i++) {
1594 if(pList[pTemp->paramValue].flag & sNum) {
1595 if((szParam = (char *)realloc(szParam, ( len += (strlen(pList[i].szName) + 2)))) == NULL)
1601 g_strlcat( szParam, pList[i].szName, len);
1602 g_strlcat( szParam, "; ", len);
1609 /** remove semicolon from tail. */
1610 for(i = strlen( szParam ); i > 0 ; i--) {
1612 if ( szParam[i] == ' ' && szParam[i-1] == ';' ) {
1613 szParam[i-1] = '\0';
1618 if ( pTemp->pNext != NULL )
1619 pTemp = pTemp->pNext;
1628 vmsg_free_vtree_memory(VTree * pTree)
1637 return __VMsgFreeVTreeMemory(pTree);