2 * Copyright 2012-2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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 *)malloc(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 *)malloc(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 *)malloc(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 *)malloc(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 *)malloc(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 len = _VUnfoldingNoSpec(pMsgRaw, VMESSAGE);
839 pMsgRawTmp = pMsgRaw;
840 len = _VManySpace2Space( pMsgRaw );
842 if(!__VIsVmsgFile(pMsgRaw, CHECK_START)) {
852 if((c == '\0') || done)
856 case VMSG_TYPE_NAME_STATUS:
858 type = __VMsgGetTypeName(pMsgRaw, &status, &dLen);
860 if(type == VMSG_TYPE_BEGIN)
870 case VMSG_TYPE_BEGIN:
873 szMsgBegin = __VMsgGetTypeVal(pMsgRaw, &status, &dLen, enc, NULL);
876 if(szMsgBegin == NULL)
879 if(!strncmp(szMsgBegin, "VCARD", strlen("VCARD")))
881 VDATA_TRACE("pVTree: %s", pVTree);
882 pVCard = vcard_decode(pVTree);
883 pCurrent->pNext = pVCard;
886 dLen = ((strstr(pMsgRaw,"END:VCARD") + 9) - pMsgRaw);
893 if(start_status == 1)
899 if(!strncmp(szMsgBegin, "VMSG", strlen("VMSG")))
901 if ( ( pVMsg = ( VTree* )malloc( sizeof( VTree ) ) ) == NULL )
906 memset(pVMsg,0x00, sizeof(VTree));
908 pVMsg->treeType = VMESSAGE;
915 else if(!strncmp(szMsgBegin, "VBODY", strlen("VBODY")))
917 if ( ( pVBody = ( VTree* )malloc( sizeof( VTree ) ) ) == NULL )
923 memset(pVBody,0x00, sizeof(VTree));
924 pVBody->treeType = VBODY;
927 pVBody->pNext = NULL;
928 pCurrent->pNext = pVBody;
939 //szMsgBegin = __VMsgGetTypeVal(pMsgRaw, &status, &dLen, enc, NULL);
941 if(!strncmp(pMsgRaw,"VMSG", strlen("VMSG")))
948 status = VMSG_TYPE_NAME_STATUS;
951 VDATA_TRACE("pMsgRaw:%s", pMsgRaw);
959 if(UNKNOWN_NAME == type || type < 0) {
960 status = VMSG_TYPE_NAME_STATUS;
964 if ( ( pTemp = ( VObject* )malloc( sizeof( VObject ) ) ) == NULL )
969 memset( pTemp, 0, sizeof( VObject ) );
970 pTemp->property = type;
972 if ( pCurrent->pTop == NULL ) {
973 pCurrent->pTop = pTemp;
974 pCurrent->pCur = pTemp;
977 pCurrent->pCur->pSibling = pTemp;
978 pCurrent->pCur = pTemp;
985 param_status = false;
989 case VMSG_PARAM_NAME_STATUS:
992 param = __VMsgGetParamName( pMsgRaw, &status, &dLen );
995 if ( param_status != true ) {
997 if ( ( pTmpParam = ( VParam* )malloc( sizeof( VParam ) ) ) == NULL )
1000 param_status = true;
1001 pCurrent->pCur->pParam = pTmpParam;
1002 memset( pTmpParam, 0x00, sizeof( VParam ) );
1003 VDATA_TRACE("pTmpParam : %p", pTmpParam);
1007 if ( ( pTmpParam->pNext = ( VParam* )malloc( sizeof( VParam ) ) ) == NULL )
1010 pTmpParam = pTmpParam->pNext;
1011 memset( pTmpParam, 0x00, sizeof(VParam));
1012 VDATA_TRACE("pTmpParam : %p", pTmpParam);
1015 pTmpParam->parameter = param;
1018 case VMSG_PARAM_VALUE_STATUS:
1021 switch ( pTmpParam->parameter )
1023 case VMSG_PARAM_TYPE:
1024 szValue = __VMsgGetParamVal( pMsgRaw, &status, &dLen );
1025 numberedParam |= __VMsgGetValue( szValue, pMsgTypeList, VMSG_TYPE_PARAM_NUM );
1027 case VMSG_PARAM_VALUE:
1028 szValue = __VMsgGetParamVal( pMsgRaw, &status, &dLen );
1029 numberedParam |= __VMsgGetValue( szValue, pMsgValueList, VMSG_VALUE_PARAM_NUM );
1031 case VMSG_PARAM_ENCODING:
1032 szValue = __VMsgGetParamVal( pMsgRaw, &status, &dLen );
1033 numberedParam |= __VMsgGetValue( szValue, pMsgEncList, VMSG_ENCODE_PARAM_NUM );
1034 enc = numberedParam;
1036 case VMSG_PARAM_CHARSET:
1037 szValue = __VMsgGetParamVal( pMsgRaw, &status, &dLen );
1038 numberedParam |= __VMsgGetValue( szValue, pMsgCharsetList, VMSG_CHARSET_PARAM_NUM );
1040 case VMSG_PARAM_CONTEXT:
1041 case VMSG_PARAM_LANGUAGE:
1042 // prevent 7605 08.03.13
1043 szValue = __VMsgGetParamVal( pMsgRaw, &status, &dLen );
1047 szValue = __VMsgGetParamVal( pMsgRaw, &status, &dLen );
1049 SET_PARAM_VALUE(numberedParam, szValue, pMsgTypeList, VMSG_TYPE_PARAM_NUM, pTmpParam, VMSG_PARAM_TYPE, enc);
1050 SET_PARAM_VALUE(numberedParam, szValue, pMsgValueList, VMSG_VALUE_PARAM_NUM, pTmpParam, VMSG_PARAM_VALUE, enc);
1051 SET_PARAM_VALUE(numberedParam, szValue, pMsgEncList, VMSG_ENCODE_PARAM_NUM, pTmpParam, VMSG_PARAM_ENCODING, enc);
1052 SET_PARAM_VALUE(numberedParam, szValue, pMsgCharsetList, VMSG_CHARSET_PARAM_NUM, pTmpParam, VMSG_PARAM_CHARSET, enc);
1061 VDATA_TRACE("%d, %s, %p",numberedParam, szValue, pTmpParam);
1062 pTmpParam->paramValue = numberedParam;
1063 pTmpParam->pNext = NULL;
1067 case VMSG_TYPE_VALUE_STATUS:
1069 temp = __VMsgGetTypeVal( pMsgRaw, &status, &dLen, enc, pCurrent->pCur);
1071 if(valueCount <= VDATA_VALUE_COUNT_MAX) {
1072 pCurrent->pCur->pszValue[valueCount] = temp;
1074 pCurrent->pCur->valueCount = valueCount;
1075 VDATA_TRACE("object property: %d, value: %s", pCurrent->pCur->property, pCurrent->pCur->pszValue[valueCount - 1]);
1084 VDATA_TRACE("pMsgRawTmp: %s", pMsgRawTmp);
1085 //VFREE(pMsgRawTmp);
1087 if(pVMsg->pTop == NULL)
1089 VDATA_TRACE("pVMsg->Top: NULL");
1094 VDATA_TRACE("vmsg_ended: false");
1104 __VMsgFreeVTreeMemory(pVMsg);
1110 * vmsg_encode() compares the string and vMsg type, parameter value.
1112 * @param pVMsgRaw Data which will be encoded
1113 * @return char * Encoded result
1116 vmsg_encode( VTree *pVMsgRaw )
1119 char* pVMsgRes = NULL;
1120 char* pTmpVMsgRes = NULL;
1121 VTree* pTmpTree = NULL;
1122 VObject * pTmpObj = NULL;
1128 for(;cnt < pVMsgRaw->pTop->valueCount;cnt++) {
1130 if(pVMsgRaw->pTop->pszValue[cnt] == NULL) {
1131 VDATA_TRACE("pVMsgRaw->pTop->valueCount : %d",pVMsgRaw->pTop->valueCount);
1132 VDATA_TRACE("pVMsgRaw->pTop->pszValue[%d] : %s", cnt, pVMsgRaw->pTop->pszValue[cnt]);
1138 pTmpTree = pVMsgRaw;
1139 pTmpObj = pVMsgRaw->pTop;
1143 switch(pTmpTree->treeType)
1151 if ( ( pVMsgRes = ( char * )malloc( sizeof( char ) * ( total += 13 ) ) ) == NULL )
1153 VDATA_TRACE( "vmsg_encode:malloc failed\n" );
1157 memcpy( pVMsgRes, "BEGIN:VMSG\r\n", 13 );
1161 if ( ( pTmpVMsgRes = ( char * )realloc( pVMsgRes, sizeof( char ) * ( total += 14 ) ) ) == NULL )
1163 VDATA_TRACE( "vmsg_encode:realloc failed\n" );
1169 pVMsgRes = pTmpVMsgRes;
1170 strncat( pVMsgRes, "BEGIN:VBODY\r\n", 13);
1182 if ( ( pTemp = __VMsgTypeEncode( pTmpObj, pTmpObj->property == VCARD_TYPE_TEL ? "TEL" : pszMsgTypeList[pTmpObj->property] ) ) != NULL )
1184 if(pTmpTree->treeType == VCARD)
1186 char* encoded = NULL;
1188 encoded = vcard_encode(pTmpTree);
1189 if (encoded == NULL) {
1190 VDATA_TRACE( "vcard_encode() failed\n");
1197 len= strlen(encoded);
1199 if ( ( pTmpVMsgRes = ( char* )realloc( pVMsgRes, ( total += len+10 ) ) ) == NULL )
1201 VDATA_TRACE( "vmsg_encode():realloc failed\n");
1209 pVMsgRes = pTmpVMsgRes;
1210 strncat(pVMsgRes, encoded, len+10);
1211 VDATA_TRACE("pTemp : %s", encoded);
1219 len = strlen( pTemp );
1221 if ( ( pTmpVMsgRes = ( char* )realloc( pVMsgRes, ( total += len+10 ) ) ) == NULL )
1223 VDATA_TRACE( "vmsg_encode():realloc failed\n");
1229 pVMsgRes = pTmpVMsgRes;
1230 strncat(pVMsgRes, pTemp, len+10);
1231 VDATA_TRACE("pTemp : %s", pTemp);
1234 if ( pTmpObj->pSibling != NULL )
1235 pTmpObj = pTmpObj->pSibling;
1244 switch(pTmpTree->treeType)
1247 if ( ( pTmpVMsgRes = ( char * )realloc( pVMsgRes, ( total += 12 ) ) ) == NULL )
1250 VDATA_TRACE( "vcal_encode():realloc failed\n");
1254 pVMsgRes = pTmpVMsgRes;
1255 strncat( pVMsgRes, "END:VBODY\r\n", 12);
1266 if ( pTmpTree->pNext != NULL )
1267 pTmpTree = pTmpTree->pNext;
1270 pTmpObj = pTmpTree->pTop;
1273 if ( ( pTmpVMsgRes = ( char * )realloc( pVMsgRes, ( total += 11 ) ) ) == NULL )
1275 VDATA_TRACE( "vmsg_encode:realloc failed\n");
1281 pVMsgRes = pTmpVMsgRes;
1282 strncat( pVMsgRes, "END:VMSG\r\n", 11);
1289 * VIsVmsgFile() verify VMsg file.
1291 * @param pVMsgRaw Data which will be encoded
1292 * @return int result (true or false)
1295 __VIsVmsgFile(char *pMsgRaw, int mode)
1298 bool rtnValue = true;
1299 char *pszVmsgBegin = "BEGIN:VMSG";
1304 for(i=0; i < 10; i++)
1305 if(*pszVmsgBegin++ != *pMsgRaw++)
1318 * vMsgTypeEncoder() compares the string and vMsg type, parameter value.
1320 * @param typeObj Data which will be encoded
1321 * @param type Name of the type
1322 * @return char * Encoded result
1325 __VMsgTypeEncode( VObject *pTypeObj, char *pType )
1330 char* szTypeValue = NULL;
1333 char* pEncode = NULL;
1338 len = strlen( pType );
1339 biLen = pTypeObj->numOfBiData;
1341 if ( ( szTypeValue = ( char * )malloc( total += ( len+1 ) ) ) == NULL )
1343 VDATA_TRACE( "__VMsgTypeEncode():malloc failed\n");
1347 memset( szTypeValue, '\0', ( len+1 ) );
1348 strncat( szTypeValue, pType, len+1);
1350 pTemp = __VMsgParamEncode( pTypeObj, &enc );
1351 if ( pTemp != NULL )
1353 len = strlen( pTemp );
1354 if ( ( szTypeValue = ( char * )realloc( szTypeValue, ( total += len ) ) ) == NULL )
1356 VDATA_TRACE( "__VMsgTypeEncode():realloc failed\n");
1362 strncat( szTypeValue, pTemp, len);
1367 if ( ( szTypeValue = ( char * )realloc( szTypeValue, ( total += 2 ) ) ) == NULL )
1373 strncat( szTypeValue, ":", 2 );
1377 if(strcmp(pType, pszMsgTypeList[6]) != 0) {
1378 for ( i = 0; i < pTypeObj->valueCount; i++ ) {
1380 if(pTypeObj->pszValue[i] != NULL)
1381 len += strlen( pTypeObj->pszValue[i] );
1388 for ( i = 0; i < pTypeObj->valueCount; i++ ) {
1392 if ( ( pEncode = ( char * )malloc( len+20 ) ) == NULL )
1399 memset( pEncode, '\0', len+20 );
1401 if(strcmp(pType, pszMsgTypeList[6]) != 0)
1403 strncat( pEncode, pTypeObj->pszValue[i], 20 );
1407 memcpy(pEncode, pTypeObj->pszValue[i], biLen);
1412 strncpy( buf, pTypeObj->pszValue[i], 999 );
1414 strcat( pEncode, ";" );
1415 strcat( pEncode, buf );
1419 if(strcmp(pType, pszMsgTypeList[6]) != 0) {
1421 strcat( pEncode, "\0\0" );
1422 len = strlen( pEncode );
1429 if ( enc & pMsgEncList[2].flag ) {
1430 if((pRes = (char *)malloc(len * 6 + 10)) == NULL) {
1437 _VQPEncode( pRes, pEncode );
1440 else if(enc & pMsgEncList[1].flag )
1442 if((pRes = (char *)malloc((len * 8 / 6) + 48)) == NULL)
1450 memset( pRes, '\0', ( ( len * 8 / 6 ) + 48 ) );
1451 _VB64Encode( pRes, pEncode, biLen );
1452 VDATA_TRACE( "Origin Size: %d, Allocated Size %d, Coverted Size: %d\n", biLen, ( len * 8 / 6 ) + 48, strlen(pRes));
1457 if((pRes = (char *)malloc(len+30)) == NULL)
1464 memset( pRes, '\0', ( len + 30 ) );
1467 memcpy( pRes, pEncode, len );
1472 if((pRes = (char *)realloc(pRes, strlen(pRes) + 3)) == NULL)
1479 strncat( pRes, "\r\n", strlen(pRes) + 2);
1481 len = strlen( pRes );
1483 if ((szTypeValue = (char *)realloc(szTypeValue, (total += (len+3)))) == NULL) {
1490 strncat(szTypeValue, pRes, total - 1);
1492 if(strcmp(pType, pszMsgTypeList[6]) != 0) {
1493 _VRLSpace( szTypeValue );
1494 _VRTSpace( szTypeValue );
1504 * __VMsgParamEncode() Parameter Encoding.
1506 * @param pTypeObj Data which will be encoded
1507 * @param pEnc Name of the type
1510 __VMsgParamEncode(VObject* pTypeObj, int* pEnc)
1518 char* szParam = NULL;
1519 VParam* pTemp = NULL;
1520 ValueObj* pList = NULL;
1522 /** Paramter initialize. */
1523 pTemp = pTypeObj->pParam;
1525 /** Momory Allocation for parameter string. */
1527 if ((szParam = (char*)malloc(len+=2)) == NULL)
1532 memset(szParam, 0x00, 2);
1535 /** appending pamaters. */
1538 if(pTemp == NULL) break;
1542 /** Expand szParam string. For appending.*/
1543 if((szParam = (char *)realloc(szParam, len += 15)) == NULL)
1549 /** appending paramter name. */
1550 strcat( szParam, ";" );
1551 if(pTemp->parameter != VMSG_PARAM_TYPE) {
1552 strcat( szParam, pszMsgParamList[pTemp->parameter] );
1553 strcat( szParam, "=" );
1556 /** Set Parameter Value name. */
1557 switch ( pTemp->parameter )
1559 case VMSG_PARAM_ENCODING:
1560 *pEnc = pMsgEncList[pTemp->paramValue].flag;
1561 shift = VMSG_ENCODE_PARAM_NUM;
1562 pList = pMsgEncList; bSupported = true;
1564 case VMSG_PARAM_TYPE:
1565 shift = VMSG_TYPE_PARAM_NUM;
1566 pList = pMsgTypeList; bSupported = true;
1568 case VMSG_PARAM_VALUE:
1569 shift = VMSG_VALUE_PARAM_NUM;
1570 pList = pMsgValueList; bSupported = true;
1572 case VMSG_PARAM_CHARSET:
1573 shift = VMSG_CHARSET_PARAM_NUM;
1574 pList = pMsgCharsetList; bSupported = true;
1577 if ( ( szParam = ( char* )realloc( szParam, 5 ) ) == NULL )
1582 strcat( szParam, "NONE" );
1585 /** exchage parameter value's to string.*/
1586 if(bSupported == true) {
1588 for(i = 0, sNum = 0x00000001; i < shift; i++) {
1590 if(pList[pTemp->paramValue].flag & sNum) {
1591 if((szParam = (char *)realloc(szParam, ( len += (strlen(pList[i].szName) + 2)))) == NULL)
1597 strcat( szParam, pList[i].szName );
1598 strcat( szParam, "; " );
1605 /** remove semicolon from tail. */
1606 for(i = strlen( szParam ); i > 0 ; i--) {
1608 if ( szParam[i] == ' ' && szParam[i-1] == ';' ) {
1609 szParam[i-1] = '\0';
1614 if ( pTemp->pNext != NULL )
1615 pTemp = pTemp->pNext;
1624 vmsg_free_vtree_memory(VTree * pTree)
1633 return __VMsgFreeVTreeMemory(pTree);