📄 mfetch.c
字号:
part->data.buffer = NULL;
}
else
{
FILEa_delete(CMN_FILE_CATEGORY_TMP, part->data.file.id);
}
M_FREE(part);
part = NULL;
}
}
return newPart;
}
static CMN_BOOL getReqData(UINT32 msgId, UINT32 number)
{
MmsBodyPart *realBodyPart = M_CALLOC(sizeof(MmsBodyPart));
FmResult fmResult = FM_RESULT_OK;
MmsResult mmsResult = MMS_RESULT_OK;
UINT32 bytesRead = 0;
realBodyPart->dataSize = 0;
if (fsm.part.dataSize == 0)
{
MMS_LOG_I(("%s(%d): No body data was found!\n", __FILE__, __LINE__));
(void)fldrmgrCloseList(fsm.cache);
(void)fldrmgrCloseMessage( CMN_CLIENT_MMS, msgId);
}
else if (fsm.part.dataSize + sizeof(MmsBodyPart) <= MMS_MAX_CHUNK_SIZE)
{
realBodyPart->data.buffer = M_CALLOC((unsigned int)fsm.part.dataSize);
realBodyPart->storageType = MMS_BODY_PART_AS_BUFFER;
fmResult = fldrmgrGetMessage( CMN_CLIENT_MMS, msgId, fsm.part.dataStart,
fsm.part.dataSize, &bytesRead, realBodyPart->data.buffer);
if (fmResult != FM_RESULT_OK)
{
mmsResult = checkFolderError(fmResult);
}
else
{
realBodyPart->dataSize = bytesRead;
realBodyPart = charsetCvtData(realBodyPart, &fsm.part.charset,
fsm.part.mediaType);
}
(void)fldrmgrCloseList(fsm.cache);
(void)fldrmgrCloseMessage( CMN_CLIENT_MMS, msgId);
MMSa_getBodyPartResponse( mmsResult, realBodyPart, msgId, number);
#ifndef MMS_RETAIN_ADAPTER_PARAMETERS
if (realBodyPart->data.buffer != NULL)
{
M_FREE(realBodyPart->data.buffer);
realBodyPart->data.buffer = NULL;
}
if (realBodyPart != NULL)
{
M_FREE(realBodyPart);
realBodyPart = NULL;
}
#endif
}
else
{
MmsCopyFile *copy;
realBodyPart->storageType = MMS_BODY_PART_AS_FILE;
copy = M_CALLOC(sizeof(MmsCopyFile));
copy->sender = M_FSM_MMH_FETCH;
copy->callerData = realBodyPart;
copy->from.id = msgId;
copy->from.category = CMN_FILE_CATEGORY_MSG;
copy->from.pos = (INT32)fsm.part.dataStart;
copy->from.bytes = (INT32)fsm.part.dataSize;
copy->from.isOpen = TRUE;
copy->to.category = CMN_FILE_CATEGORY_TMP;
copy->to.shouldCreate = TRUE;
copy->to.id = 0;
copy->to.pos = MMH_COPY_APPEND;
copy->to.isOpen = FALSE;
fsm.srcFileId = msgId;
fsm.partNumber = number;
M_SIGNAL_SENDTO_P( M_FSM_MMH_COPY, MMS_SIG_MMH_COPY_START, copy);
return FALSE;
}
return TRUE;
}
static CMN_BOOL getBodyPart(const MmsSignal *sig)
{
UINT32 size = 0;
MmsResult mmsResult = MMS_RESULT_OK;
FmResult fmResult = FM_RESULT_OK;
UINT32 bytesRead = 0;
UINT32 *ourPartInfo = NULL;
UINT32 *partInfo = NULL;
MmsBodyPart *realBodyPart = NULL;
if (fldrmgrOpenList( CMN_CLIENT_MMS, sig->u_param1, &fsm.cache, FM_READ) != FM_RESULT_OK)
{
mmsResult = MMS_RESULT_FILE_READ_ERROR;
}
else if (fldrmgrOpenMessage( CMN_CLIENT_MMS, sig->u_param1, FM_READ) != FM_RESULT_OK)
{
mmsResult = MMS_RESULT_FILE_READ_ERROR;
}
else
{
fmResult = fldrmgrGetListSize( CMN_CLIENT_MMS, sig->u_param1, &size);
if (fmResult != FM_RESULT_OK)
{
mmsResult = checkFolderError(fmResult);
}
else if (size < MMS_MESSAGE_INFO_SIZE)
{
mmsResult = MMS_RESULT_MESSAGE_ID_NOT_FOUND;
}
else if (size < (MMS_MESSAGE_INFO_SIZE + MMS_PART_INFO_SIZE))
{
fsm.part.dataSize = 0;
fsm.part.dataStart = 0;
fsm.part.entrySize = 0;
fsm.part.entryStart = 0;
fsm.part.nEntries = 0;
fsm.part.mediaType = MMS_TYPE_ANY_ANY;
fsm.part.charset = CMN_CHARSET_UNKNOWN;
}
else
{
partInfo = M_CALLOC((unsigned int)size);
fmResult = fldrmgrGetList( fsm.cache, 0UL, size, &bytesRead,
(unsigned char *)partInfo);
if (fmResult != FM_RESULT_OK)
{
mmsResult = checkFolderError(fmResult);
}
else if ((MMS_MESSAGE_INFO_SIZE +
(MMS_PART_INFO_SIZE * (sig->u_param2 + 1))) > bytesRead)
{
mmsResult = MMS_RESULT_BODY_PART_NOT_FOUND;
}
else
{
ourPartInfo = partInfo + (POS_INT_MSG_NUMBER +
(POS_INT_PART_NUMBER * sig->u_param2));
fsm.part.dataSize = ourPartInfo[POS_DATA_SIZE];
fsm.part.dataStart = ourPartInfo[POS_DATA_START];
fsm.part.entrySize = ourPartInfo[POS_ENTRY_SIZE];
fsm.part.entryStart = ourPartInfo[POS_ENTRY_START];
fsm.part.nEntries = ourPartInfo[POS_NENTRIES];
fsm.part.mediaType = (MmsKnownMediaType)ourPartInfo[POS_PART_MEDIA_TYPE];
fsm.part.charset = ourPartInfo[POS_CHARSET];
}
M_FREE(partInfo);
}
}
if (mmsResult == MMS_RESULT_OK && fsm.part.dataSize > 0)
{
return getReqData(sig->u_param1, sig->u_param2);
}
else
{
realBodyPart = M_CALLOC(sizeof(MmsBodyPart));
realBodyPart->storageType = MMS_BODY_PART_AS_BUFFER;
realBodyPart->data.buffer = NULL;
realBodyPart->dataSize = 0;
(void)fldrmgrCloseList(fsm.cache);
(void)fldrmgrCloseMessage( CMN_CLIENT_MMS, sig->u_param1);
MMSa_getBodyPartResponse( mmsResult, realBodyPart, sig->u_param1,
sig->u_param2);
#ifndef MMS_RETAIN_ADAPTER_PARAMETERS
M_FREE(realBodyPart);
realBodyPart = NULL;
#endif
}
return TRUE;
}
static void getAllMsg(const MmsSignal *sig)
{
FmResult fmResult;
MmsResult mmsResult = MMS_RESULT_OK;
UINT32 numberOfMsg;
UINT32 *allIds = NULL;
UINT8 *metadata = NULL;
UINT8 *attributes = NULL;
MmsTimeSec *idTime = NULL;
fmResult = fldrmgrGetNumberOfMsg( CMN_CLIENT_MMS, (UINT16)sig->i_param,
FM_IS_ANY, &numberOfMsg);
if (fmResult != FM_RESULT_OK)
{
mmsResult = checkFolderError(fmResult);
}
else if (numberOfMsg > 0)
{
if (numberOfMsg > sig->u_param2)
{
allIds = M_CALLOC((unsigned int)sig->u_param2 * sizeof(UINT32));
idTime = M_CALLOC((unsigned int)sig->u_param2 * sizeof(UINT32));
metadata = M_CALLOC((unsigned int)sig->u_param2 * sizeof(UINT8));
attributes = M_CALLOC((unsigned int)sig->u_param2 * sizeof(UINT8));
}
else
{
allIds = M_CALLOC((unsigned int)numberOfMsg * sizeof(UINT32));
idTime = M_CALLOC((unsigned int)numberOfMsg * sizeof(UINT32));
metadata = M_CALLOC((unsigned int)numberOfMsg * sizeof(UINT8));
attributes = M_CALLOC((unsigned int)numberOfMsg * sizeof(UINT8));
}
fmResult = fldrmgrGetMsgDataList( CMN_CLIENT_MMS, 0, (UINT16)sig->i_param,
sig->u_param1, sig->u_param2, &numberOfMsg, allIds, idTime,
metadata, attributes);
if (fmResult != FM_RESULT_OK)
{
mmsResult = checkFolderError(fmResult);
}
}
MMSa_getMessageIdListResponse(mmsResult, numberOfMsg, allIds, idTime,
metadata, attributes, (MmsFolderType)sig->i_param);
#ifndef MMS_RETAIN_ADAPTER_PARAMETERS
M_FREE(allIds);
M_FREE(idTime);
M_FREE(metadata);
M_FREE(attributes);
#endif
}
static void getNumOfMsg(const MmsSignal *sig)
{
UINT32 numberOfMsg;
MmsResult mmsResult = MMS_RESULT_OK;
FmResult fmResult;
fmResult = fldrmgrGetNumberOfMsg( CMN_CLIENT_MMS, (UINT16)sig->i_param,
FM_IS_ANY, &numberOfMsg);
if (fmResult != FM_RESULT_OK)
{
mmsResult = checkFolderError(fmResult);
}
MMSa_getNumberOfMessagesResponse(mmsResult, numberOfMsg,
(MmsFolderType)sig->i_param);
}
static CMN_BOOL getContentTypeValues(UINT32 *partInfo,
const unsigned char *contentTypeStart, UINT32 size)
{
MmsContentType *contentType = NULL;
MmsAllParams *paramPtr = NULL;
CMN_BOOL ret = TRUE;
partInfo[POS_CHARSET] = CMN_CHARSET_UNKNOWN;
if (parseContentType( &contentType,
(const unsigned char *)contentTypeStart, size) == NULL)
{
ret = FALSE;
}
else if (contentType->strValue != NULL)
{
#ifdef MMS_EXTERNAL_DRM_ID_GENERATION
if (strncmp((const char *)contentType->strValue,
MMS_CONTENT_TYPE_DRM_MESSAGE,
sizeof(MMS_CONTENT_TYPE_DRM_MESSAGE)-1) == 0)
{
partInfo[POS_PART_MEDIA_TYPE] = MMS_TYPE_APP_VND_OMA_DRM_MESSAGE;
}
else if (strncmp((const char *)contentType->strValue,
MMS_CONTENT_TYPE_DRM_CONTENT,
sizeof(MMS_CONTENT_TYPE_DRM_CONTENT)-1) == 0)
{
partInfo[POS_PART_MEDIA_TYPE] = MMS_TYPE_APP_VND_OMA_DRM_CONTENT;
}
else if (strncmp((const char *)contentType->strValue,
MMS_CONTENT_TYPE_DRM_RIGHTS_XML,
sizeof(MMS_CONTENT_TYPE_DRM_RIGHTS_XML)-1) == 0)
{
partInfo[POS_PART_MEDIA_TYPE] = MMS_TYPE_APP_VND_OMA_DRM_R_XML;
}
else if (strncmp((const char *)contentType->strValue,
MMS_CONTENT_TYPE_DRM_RIGHTS_WBXML,
sizeof(MMS_CONTENT_TYPE_DRM_RIGHTS_WBXML)-1) == 0)
{
partInfo[POS_PART_MEDIA_TYPE] = MMS_TYPE_APP_VND_OMA_DRM_R_WBXML;
}
else
{
partInfo[POS_PART_MEDIA_TYPE] = MMS_VALUE_AS_STRING;
}
#else
partInfo[POS_PART_MEDIA_TYPE] = MMS_VALUE_AS_STRING;
#endif
}
else
{
partInfo[POS_PART_MEDIA_TYPE] = contentType->knownValue;
if (isText(contentType->knownValue))
{
paramPtr = contentType->params;
while (contentType->params != NULL)
{
if (contentType->params->param == MMS_CHARSET)
{
if (contentType->params->type == MMS_PARAM_INTEGER)
{
partInfo[POS_CHARSET] =
(UINT32)contentType->params->value.integer;
break;
}
}
contentType->params = contentType->params->next;
}
contentType->params = paramPtr;
}
}
if (ret != TRUE)
{
MMS_LOG_I(("%s(%d): parse of content type failed!\n", __FILE__, __LINE__));
}
else
{
freeMmsContentType(contentType);
M_FREE(contentType);
contentType = NULL;
}
return ret;
}
static CMN_BOOL getHeaderMediaType(UINT32 *partInfo, UINT32 *msgInfo,
unsigned char *header, UINT32 size)
{
MmsHeaderValue contentTypeStart;
CMN_BOOL ret = TRUE;
if (!mmsPduGet(header, size, MMS_CONTENT_TYPE, &contentTypeStart))
{
ret = FALSE;
}
else
{
partInfo[POS_PART_MEDIA_TYPE] = 0;
partInfo[POS_CHARSET] = 0;
msgInfo[POS_MEDIA_TYPE] = 0;
if (getContentTypeValues(partInfo,
(const unsigned char *) contentTypeStart.contentType,
size - (UINT32)((const unsigned char *)contentTypeStart.contentType -
header)) == FALSE)
{
ret = FALSE;
}
msgInfo[POS_MEDIA_TYPE] = partInfo[POS_PART_MEDIA_TYPE];
}
return ret;
}
static unsigned char *getPartInfo(unsigned char *bodyPointer, UINT32 *headerLen,
UINT32 *partInfo, UINT32 bufSize)
{
CMN_BOOL ret = TRUE;
unsigned long remainingSize;
unsigned char *secBodyPointer = bodyPointer;
if (bufSize == 0 || bodyPointer == NULL)
{
return NULL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -