📄 mfetch.c
字号:
partInfo[POS_ENTRY_SIZE] = 0;
if (isMultiPart((MmsKnownMediaType)partInfo[POS_PART_MEDIA_TYPE]))
{
bodyPointer = (unsigned char *)cnvUintvarToUint32(
secBodyPointer, &partInfo[POS_NENTRIES], bufSize);
if (bodyPointer == NULL)
{
ret = FALSE;
}
}
else
{
partInfo[POS_NENTRIES] = 0;
}
remainingSize = bufSize - (UINT32)(bodyPointer - secBodyPointer);
if (ret == TRUE && bodyPointer != NULL && remainingSize > 0)
{
bodyPointer = (unsigned char *)cnvUintvarToUint32(
bodyPointer, headerLen, remainingSize);
if (bodyPointer == NULL)
{
ret = FALSE;
}
else
{
remainingSize = bufSize - (UINT32)(bodyPointer - secBodyPointer);
bodyPointer = (unsigned char *)cnvUintvarToUint32(
bodyPointer, &partInfo[POS_DATA_SIZE], remainingSize);
if (bodyPointer == NULL)
{
ret = FALSE;
}
else
{
partInfo[POS_ENTRY_SIZE] += (UINT32)(bodyPointer - secBodyPointer);
if (getContentTypeValues(partInfo, bodyPointer, *headerLen) == FALSE)
{
bodyPointer = NULL;
}
}
}
partInfo[POS_ENTRY_SIZE] += *headerLen;
partInfo[POS_DATA_START] = partInfo[POS_ENTRY_SIZE] + partInfo[POS_ENTRY_START];
}
if (ret == FALSE)
{
bodyPointer = NULL;
}
return bodyPointer;
}
static CMN_BOOL getAllEntries( UINT32 **dataToWrite,
unsigned char *secBodyPointer, UINT32 *partInfo, CMN_BOOL gotCompMsg,
UINT32 *msgInfo, unsigned char *header, UINT32 messageSize,
UINT32 clientMsgId, UINT32 **tempPointer)
{
unsigned char *bodyPointer = secBodyPointer;
UINT32 readFrom = msgInfo[POS_HEADER_SIZE];
CMN_BOOL ret = TRUE;
CMN_BOOL isFinished = FALSE;
UINT32 bytesRead = 0;
UINT32 headerLen = 0UL;
UINT32 size = 0;
UINT32 countNumOfEntry = 0;
*dataToWrite = NULL;
msgInfo[POS_NUM_OF_MSG_INFO] = 0;
while (readFrom < messageSize && ret != FALSE && !isFinished)
{
if (gotCompMsg == FALSE)
{
if (fldrmgrGetMessage( CMN_CLIENT_MMS, clientMsgId, readFrom,
MMS_MAX_CHUNK_SIZE, &bytesRead, header) != FM_RESULT_OK)
{
MMS_LOG_I(("%s(%d): Couldn't read!\n", __FILE__, __LINE__));
ret = FALSE;
}
bodyPointer = header;
}
secBodyPointer = bodyPointer;
partInfo[POS_ENTRY_START] = readFrom;
if (gotCompMsg == FALSE)
{
bodyPointer = getPartInfo( bodyPointer, &headerLen, partInfo,
bytesRead);
if ((bodyPointer == NULL) ||
(partInfo[POS_ENTRY_SIZE] > MMS_MAX_CHUNK_SIZE))
{
MMS_LOG_I(("%s(%d): getPartInfo failed %d, %ld!\n",
__FILE__, __LINE__, (int)bodyPointer,
partInfo[POS_ENTRY_SIZE]));
ret = FALSE;
}
else
{
++msgInfo[POS_NUM_OF_MSG_INFO];
}
}
else
{
bodyPointer = getPartInfo( bodyPointer, &headerLen, partInfo,
(messageSize - (UINT32)(secBodyPointer - header)));
if ((bodyPointer == NULL) ||
(partInfo[POS_ENTRY_SIZE] > MMS_MAX_CHUNK_SIZE))
{
MMS_LOG_I(("%s(%d): getPartInfo failed %d, %ld!\n",
__FILE__, __LINE__, (int)bodyPointer,
partInfo[POS_ENTRY_SIZE]));
ret = FALSE;
}
else if (messageSize == (UINT32)(bodyPointer - header))
{
isFinished = TRUE;
}
else
{
++msgInfo[POS_NUM_OF_MSG_INFO];
}
}
if (isMultiPart((MmsKnownMediaType)partInfo[POS_PART_MEDIA_TYPE]) &&
(readFrom >= msgInfo[POS_HEADER_SIZE]))
{
if (gotCompMsg == TRUE && ret == TRUE && bodyPointer != NULL)
{
bodyPointer += headerLen;
}
readFrom += partInfo[POS_ENTRY_SIZE];
}
else
{
if (gotCompMsg == TRUE && ret == TRUE && bodyPointer != NULL)
{
bodyPointer += headerLen + partInfo[POS_DATA_SIZE];
}
readFrom += (partInfo[POS_ENTRY_SIZE] + partInfo[POS_DATA_SIZE]);
if (partInfo[POS_ENTRY_SIZE] == 0 && partInfo[POS_DATA_SIZE] == 0)
{
MMS_LOG_I(("%s(%d): Msg corrupt!\n", __FILE__, __LINE__));
ret = FALSE;
}
}
#ifdef MMS_EXTERNAL_DRM_ID_GENERATION
partInfo[POS_LOCAL_DRM_ID] = 0;
#endif
if (partInfo[POS_NENTRIES] > 0 && ret == TRUE)
{
if (*dataToWrite != NULL)
{
if (fldrmgrSetList( fsm.cache, (unsigned char *)*dataToWrite,
(UINT32)((*tempPointer - *dataToWrite) * (int)(sizeof(UINT32))),
(UINT32)FM_APPEND) != FM_RESULT_OK)
{
MMS_LOG_I(("%s(%d): Couldn't write!\n", __FILE__, __LINE__));
ret = FALSE;
}
M_FREE(*dataToWrite);
*dataToWrite = NULL;
}
size = (MMS_PART_INFO_SIZE * (partInfo[POS_NENTRIES] + 1));
*dataToWrite = M_CALLOC(size);
*tempPointer = *dataToWrite;
countNumOfEntry += partInfo[POS_NENTRIES];
}
if ((*tempPointer != NULL) && (*dataToWrite != NULL) && ret == TRUE &&
(UINT32)(*tempPointer - *dataToWrite) * (UINT32)(sizeof(UINT32)) <=
(size - MMS_PART_INFO_SIZE))
{
memcpy(*tempPointer, partInfo, MMS_PART_INFO_SIZE);
*tempPointer += POS_INT_PART_NUMBER;
}
else if ( !isFinished )
{
MMS_LOG_I(("%s(%d): Message is corrupt!\n", __FILE__, __LINE__));
ret = FALSE;
}
}
if (msgInfo[POS_NUM_OF_MSG_INFO] != countNumOfEntry)
{
MMS_LOG_I(("%s(%d): num of entries is wrong!\n", __FILE__, __LINE__));
ret = FALSE;
}
if (ret == FALSE)
{
M_FREE(*dataToWrite);
*dataToWrite = NULL;
}
return ret;
}
static MmsResult getMessage( UINT32 clientMsgId, UINT32 *messageSize,
CMN_BOOL *gotCompMsg, unsigned char **header, UINT32 *bytesRead)
{
UINT32 allocSize = 0;
MmsResult ret = MMS_RESULT_OK;
FmResult res = FM_RESULT_OK;
res = fldrmgrGetMessageSize( CMN_CLIENT_MMS, clientMsgId, messageSize);
if (res != FM_RESULT_OK)
{
ret = checkFolderError(res);
}
else if (*messageSize == 0)
{
ret = MMS_RESULT_MESSAGE_EMPTY;
}
else if (messageSize != NULL)
{
if (MMS_MAX_CHUNK_SIZE < *messageSize)
{
allocSize = MMS_MAX_CHUNK_SIZE;
*gotCompMsg = FALSE;
}
else
{
*gotCompMsg = TRUE;
allocSize = *messageSize;
}
*header = M_CALLOC((unsigned int)allocSize);
if (fldrmgrGetMessage( CMN_CLIENT_MMS, clientMsgId, 0UL,
allocSize, bytesRead, *header) != FM_RESULT_OK || *bytesRead == 0)
{
ret = MMS_RESULT_FILE_READ_ERROR;
}
}
return ret;
}
MmsResult createMsgInfoList(UINT32 clientMsgId, MmsTimeSec time)
{
unsigned char *header = NULL;
unsigned char *body = NULL;
UINT32 *dataToWrite = NULL;
UINT32 *tempPointer = NULL;
UINT32 partInfo[POS_INT_PART_NUMBER];
UINT32 msgInfo[POS_INT_MSG_NUMBER];
UINT32 messageSize = 0UL;
MmsResult ret = MMS_RESULT_OK;
MmsResult tmpRet;
CMN_BOOL gotCompMsg = TRUE;
CMN_BOOL isEntriesOk = FALSE;
UINT32 bytesRead = 0;
MmsHeaderValue tag;
FmResult fmResult;
memset( partInfo, 0, sizeof(partInfo));
memset( msgInfo, 0, sizeof(msgInfo));
if (fldrmgrOpenList( CMN_CLIENT_MMS, clientMsgId, &fsm.cache, FM_READ_WRITE)
!= FM_RESULT_OK)
{
MMS_LOG_I(("%s(%d): Couldn't open list.\n", __FILE__, __LINE__));
return MMS_RESULT_FILE_READ_ERROR;
}
(void)fldrmgrSetListSize( CMN_CLIENT_MMS, clientMsgId, 0UL);
ret = getMessage( clientMsgId, &messageSize, &gotCompMsg, &header, &bytesRead);
if (ret != MMS_RESULT_OK)
{
MMS_LOG_I(("%s(%d): Couldn't get msg.\n", __FILE__, __LINE__));
(void)createMsgInfoListCleanup(header);
return ret;
}
else if ( mmsPduSanityCheck( header,
CMN_MIN( messageSize, MMS_MAX_CHUNK_SIZE)) == FALSE)
{
MMS_LOG_I(("%s(%d): Unrecognized PDU!\n", __FILE__, __LINE__));
(void)createMsgInfoListCleanup(header);
return MMS_RESULT_MESSAGE_CORRUPT;
}
if ( cfgGetInt(MMS_CFG_USE_RECEPTION_DATE) == FALSE &&
mmsPduGet( header, bytesRead, MMS_DATE, &tag))
{
(void)fldrmgrSetDate( CMN_CLIENT_MMS, clientMsgId, tag.date);
}
else if (time)
{
(void)fldrmgrSetDate( CMN_CLIENT_MMS, clientMsgId, time);
}
else
{
(void)fldrmgrSetDate( CMN_CLIENT_MMS, clientMsgId, CMNa_currentTime());
}
body = mmsGetBody( header, bytesRead);
if (body != NULL)
{
msgInfo[POS_HEADER_SIZE] = (UINT32)(body - header);
}
else if (bytesRead == messageSize)
{
msgInfo[POS_HEADER_SIZE] = messageSize;
}
else
{
MMS_LOG_I(("%s(%d): Illegal PDU.\n", __FILE__, __LINE__));
(void)createMsgInfoListCleanup(header);
return MMS_RESULT_MESSAGE_CORRUPT;
}
if (msgInfo[POS_HEADER_SIZE] > MMS_MAX_CHUNK_SIZE)
{
(void)createMsgInfoListCleanup(header);
return MMS_RESULT_INVALID_HEADER_SIZE;
}
if (fldrmgrSetList( fsm.cache, (unsigned char *)msgInfo,
(UINT32)MMS_MESSAGE_INFO_SIZE, 0UL) != FM_RESULT_OK)
{
MMS_LOG_I(("%s(%d): Couldn't store the infolist.\n",
__FILE__, __LINE__));
(void)createMsgInfoListCleanup(header);
return MMS_RESULT_INSUFFICIENT_PERSISTENT_STORAGE;
}
if (msgInfo[POS_HEADER_SIZE] == messageSize)
{
ret = createMsgInfoListCleanup(header);
if (ret != MMS_RESULT_OK)
{
MMS_LOG_I(("%s(%d): Couldn't save the infoList.\n",
__FILE__, __LINE__));
}
else
{
fmResult = fldrmgrSetFlagValid( CMN_CLIENT_MMS, clientMsgId, TRUE);
ret = checkFolderError( fmResult);
}
return ret;
}
if (!getHeaderMediaType(partInfo, msgInfo, header, bytesRead))
{
MMS_LOG_I(("%s(%d): Illegal PDU.\n", __FILE__, __LINE__));
ret = MMS_RESULT_MESSAGE_CORRUPT;
}
if (!isMultiPart((MmsKnownMediaType)partInfo[POS_PART_MEDIA_TYPE]))
{
#ifdef MMS_EXTERNAL_DRM_ID_GENERATION
partInfo[POS_LOCAL_DRM_ID] = 0;
#endif
partInfo[POS_ENTRY_START] = 0;
partInfo[POS_ENTRY_SIZE] = 0;
partInfo[POS_DATA_START] = msgInfo[POS_HEADER_SIZE];
partInfo[POS_DATA_SIZE] = messageSize - msgInfo[POS_HEADER_SIZE];
partInfo[POS_NENTRIES] = 0;
msgInfo[POS_NUM_OF_MSG_INFO] = 1;
if (fldrmgrSetList( fsm.cache, (unsigned char *)partInfo,
sizeof(partInfo), (UINT32)FM_APPEND) != FM_RESULT_OK)
{
ret = MMS_RESULT_INSUFFICIENT_PERSISTENT_STORAGE;
}
}
else
{
if (body != NULL)
{
isEntriesOk = getAllEntries( &dataToWrite, body, partInfo,
gotCompMsg, msgInfo, header, messageSize, clientMsgId,
&tempPointer);
}
if ( !isEntriesOk )
{
MMS_LOG_I(("%s(%d): Illegal PDU.\n", __FILE__, __LINE__));
ret = MMS_RESULT_MESSAGE_CORRUPT;
}
if (ret == MMS_RESULT_OK && dataToWrite != NULL &&
tempPointer != N
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -