📄 mnotify.c
字号:
FILEa_close( MMS_FILE_CATEGORY_IMMEDIATE, NOTIF_TABLE_FILE_ID);
MMSa_error(MMS_RESULT_RESTART_NEEDED);
return;
}
memset( buffer, 0, bufSize);
storePos = buffer;
bufFree = bufSize;
for (;;)
{
bytesRead = FILEa_read( MMS_FILE_CATEGORY_IMMEDIATE, NOTIF_TABLE_FILE_ID,
storePos, readPos, (INT32)bufFree);
readPos += bytesRead;
if (bytesRead < 0)
{
MMS_LOG_I(("%s(%d): FILEa_read returned %d\n",
__FILE__, __LINE__, bytesRead));
break;
}
decodedBytes = notifTableDecodeData( buffer,
(UINT32)(storePos - buffer + bytesRead));
if ((UINT32)bytesRead < bufSize ||
fsm.notifTable.count >= MMS_MAX_DUPLICATE_NOTIFICATION_CHECK)
{
break;
}
if (decodedBytes < bufSize)
{
memmove( buffer, &buffer[decodedBytes],
(UINT32)(bufSize - decodedBytes));
bufFree = decodedBytes;
storePos = buffer + bufSize - decodedBytes;
}
else
{
storePos = buffer;
bufFree = bufSize;
}
}
M_FREE(buffer);
FILEa_close( MMS_FILE_CATEGORY_IMMEDIATE, NOTIF_TABLE_FILE_ID);
}
static void notifTableRemove(int index)
{
if (index >= fsm.notifTable.count || fsm.notifTable.count <= 0)
{
MMS_LOG_I(("%s(%d): Trying to remove wrong index %d, count %d\n",
__FILE__, __LINE__, index, fsm.notifTable.count));
return;
}
M_FREE( fsm.notifTable.notif[index].uri);
memset( &fsm.notifTable.notif[index], 0, sizeof(MsrNotifTableData));
--fsm.notifTable.count;
if (fsm.notifTable.count > 0 && index < fsm.notifTable.count)
{
memmove( &fsm.notifTable.notif[index], &fsm.notifTable.notif[index + 1],
(UINT32)(fsm.notifTable.count - index) * sizeof(MsrNotifTableData));
}
#if MMS_NOTIF_TABLE_SAVE_DELETE
notifTableSaveAll();
#endif
}
static void notifTableSaveAll(void)
{
int i;
int iterations = 0;
INT32 actually = 0;
UINT32 pos = 0;
UINT32 len;
INT32 bytesWritten = 0;
INT32 bytesInCache = 0;
char *cache = NULL;
if (FILEa_open( MMS_FILE_CATEGORY_IMMEDIATE, NOTIF_TABLE_FILE_ID,
FILE_OPTION_WRITE) != 0)
{
MMS_LOG_I(("%s(%d): Couldn't open file %d\n", __FILE__, __LINE__,
NOTIF_TABLE_FILE_ID));
return;
}
cache = M_CALLOC(MMS_MAX_CHUNK_SIZE);
i = 0;
while (iterations < fsm.notifTable.count && i < fsm.notifTable.count)
{
pos = 0;
bytesInCache = 0;
while (i < fsm.notifTable.count)
{
len = sizeof(fsm.notifTable.notif[i].fileId);
if (pos + len >= MMS_MAX_CHUNK_SIZE)
{
break;
}
memcpy( &cache[pos], &fsm.notifTable.notif[i].fileId,
sizeof(fsm.notifTable.notif[i].fileId));
pos += len;
len = sizeof(fsm.notifTable.notif[0].type);
if (pos + len >= MMS_MAX_CHUNK_SIZE)
{
break;
}
memcpy( &cache[pos], &fsm.notifTable.notif[i].type,
sizeof(fsm.notifTable.notif[i].type));
pos += len;
len = strlen(fsm.notifTable.notif[i].uri) + 1;
if (pos + len >= MMS_MAX_CHUNK_SIZE)
{
break;
}
memcpy( &cache[pos], fsm.notifTable.notif[i].uri, len);
pos += len;
bytesInCache = (INT32)pos;
++i;
}
actually = FILEa_write( MMS_FILE_CATEGORY_IMMEDIATE, NOTIF_TABLE_FILE_ID,
cache, bytesWritten, bytesInCache);
if (actually == bytesInCache)
{
bytesWritten += bytesInCache;
}
else
{
CMN_LOG_I(("%s(%d): Only wrote %ld bytes out of %ld\n",
__FILE__, __LINE__, actually, bytesInCache));
MMSa_error( MMS_RESULT_INSUFFICIENT_PERSISTENT_STORAGE);
break;
}
++iterations;
}
if (iterations > 1 && iterations >= fsm.notifTable.count)
{
CMN_LOG_I(("%s(%d): Chunk size is chosen to small, %d iterations.\n",
__FILE__, __LINE__, iterations));
}
if (FILEa_setSize( MMS_FILE_CATEGORY_IMMEDIATE, NOTIF_TABLE_FILE_ID,
bytesWritten) != bytesWritten)
{
CMN_LOG_I(("%s(%d): Couldn't set size %ld bytes for notif table\n",
__FILE__, __LINE__, bytesWritten));
}
M_FREE(cache);
FILEa_close( MMS_FILE_CATEGORY_IMMEDIATE, NOTIF_TABLE_FILE_ID);
}
static void notifTableSaveAllNoCache(void)
{
int i;
int ret;
UINT32 expected = 0;
INT32 actually = 0;
INT32 pos = 0;
INT32 len;
INT32 bytesFullyWritten = 0;
ret = FILEa_open( MMS_FILE_CATEGORY_IMMEDIATE, NOTIF_TABLE_FILE_ID,
FILE_OPTION_WRITE);
if (ret != 0)
{
MMS_LOG_I(("%s(%d): Couldn't open file %d\n", __FILE__, __LINE__,
NOTIF_TABLE_FILE_ID));
return;
}
for ( i = 0; i < fsm.notifTable.count; ++i)
{
expected = sizeof(fsm.notifTable.notif[0].fileId);
actually = FILEa_write( MMS_FILE_CATEGORY_IMMEDIATE, NOTIF_TABLE_FILE_ID,
&fsm.notifTable.notif[i].fileId, pos, sizeof(fsm.notifTable.notif[0].fileId));
pos += (INT32)sizeof(fsm.notifTable.notif[0].fileId);
expected += sizeof(fsm.notifTable.notif[0].type);
actually += FILEa_write( MMS_FILE_CATEGORY_IMMEDIATE, NOTIF_TABLE_FILE_ID,
&fsm.notifTable.notif[i].type, pos, sizeof(fsm.notifTable.notif[0].type));
pos += (INT32)sizeof(fsm.notifTable.notif[0].type);
len = (INT32)strlen(fsm.notifTable.notif[i].uri) + 1;
expected += (UINT32)len;
actually += FILEa_write( MMS_FILE_CATEGORY_IMMEDIATE, NOTIF_TABLE_FILE_ID,
fsm.notifTable.notif[i].uri, pos, len);
pos += len;
if (actually == (INT32)expected)
{
bytesFullyWritten = pos;
}
else
{
CMN_LOG_I(("%s(%d): Only wrote %ld bytes out of %lu\n",
__FILE__, __LINE__, actually, expected));
MMSa_error( MMS_RESULT_INSUFFICIENT_PERSISTENT_STORAGE);
break;
}
}
if (FILEa_setSize( MMS_FILE_CATEGORY_IMMEDIATE, NOTIF_TABLE_FILE_ID,
bytesFullyWritten) != bytesFullyWritten)
{
CMN_LOG_I(("%s(%d): Couldn't set size %ld bytes for notif table\n",
__FILE__, __LINE__, bytesFullyWritten));
}
FILEa_close( MMS_FILE_CATEGORY_IMMEDIATE, NOTIF_TABLE_FILE_ID);
}
static void sendNotifyRespInd( CMN_BOOL isSmsBearer, const char *trId,
MmsStatus msgStatus, MmsClassIdentifier msgClass, MmsVersion version)
{
unsigned int len = 0;
MmsNotifIndInfo *notifIndInfo = NULL;
if (cfgGetInt(MMS_CFG_NO_SMS_NOTIFY_RESP) && isSmsBearer)
{
MMS_LOG_I(("sendNotifyRespInd: Configured not to "
"send NotifyResp.ind for notifications via SMS\n"));
return;
}
if (trId == NULL)
{
MMS_LOG_I(("%s(%d): No X_MMS_TRANSACTION_ID passed\n", __FILE__, __LINE__));
return;
}
notifIndInfo = M_CALLOC(sizeof(MmsNotifIndInfo));
len = strlen(trId) + 1;
notifIndInfo->transactionId = M_ALLOC(len);
strcpy( notifIndInfo->transactionId, trId);
if (msgClass == MMS_MESSAGE_CLASS_AUTO)
{
notifIndInfo->deliveryReportFlag = MMS_DELIVERY_REPORT_NO;
}
else
{
notifIndInfo->deliveryReportFlag =
(unsigned int)cfgGetInt(MMS_CFG_DELIVERY_REPORT);
}
notifIndInfo->isSmsBearer = isSmsBearer;
notifIndInfo->msgStatus = msgStatus;
notifIndInfo->version = version;
M_SIGNAL_SENDTO_P( M_FSM_COH_PUSH_RECEIVE, MMS_SIG_COH_NOTIFY_RESP,
notifIndInfo);
}
static MmsResult storeDelayedRetrieval( MmsMsrNotifStorageType storage,
UINT32 fileId, MmsTimeSec time, CMN_BOOL isSmsBearer, UINT32 len,
unsigned char *pdu, MmsVersion version, MmsNotificationReason reason,
UINT32 seqId)
{
char *trId;
char *uri = NULL;
UINT32 msgId;
FmResult fmResult;
MmsResult ret = MMS_RESULT_OK;
MmsMessageClass mc;
trId = getTransactionId( pdu, len);
ret = parseContentLocation( pdu, len, &uri);
if (ret != MMS_RESULT_OK)
{
MMS_LOG_I(("%s(%d): Missing content location.\n", __FILE__, __LINE__));
}
else if (trId == NULL)
{
MMS_LOG_I(("%s(%d): Missing transaction ID.\n", __FILE__, __LINE__));
M_FREE(uri);
ret = MMS_RESULT_COMM_HEADER_TAG;
}
if (storage == NOTIF_IMMEDIATE)
{
msrNotifyRemoveId( storage, fileId);
}
if (ret != MMS_RESULT_OK)
{
return ret;
}
if ((fmResult = fldrmgrCreateMsg( CMN_CLIENT_MMS, &msgId, MMS_NOTIFY, TRUE))
!= FM_RESULT_OK)
{
ret = checkFolderError(fmResult);
MMSa_error(ret);
MMS_LOG_I(("%s(%d): Failed to create notification file %d\n",
__FILE__, __LINE__, ret));
ret = MMS_RESULT_INSUFFICIENT_PERSISTENT_STORAGE;
}
else
{
if ((fmResult = fldrmgrSetMessage( CMN_CLIENT_MMS, msgId, pdu, len, 0))
!= FM_RESULT_OK)
{
ret = checkFolderError(fmResult);
MMSa_error(ret);
MMS_LOG_I(("%s(%d): Failed to store notification on file. Error %d\n",
__FILE__, __LINE__, ret));
ret = MMS_RESULT_INSUFFICIENT_PERSISTENT_STORAGE;
fmResult = fldrmgrDeleteMsg( CMN_CLIENT_MMS, msgId, TRUE);
if (checkFolderError(fmResult) != MMS_RESULT_OK)
{
MMS_LOG_I(("%s(%d): Failed to delete file. Error=%d\n",
__FILE__, __LINE__, fmResult));
}
}
else if (createMsgInfoList(msgId, time) != MMS_RESULT_OK)
{
ret = checkFolderError(fmResult);
MMSa_error(ret);
MMS_LOG_I(("%s(%d): Failed to create the info list %d\n",
__FILE__, __LINE__, ret));
ret = MMS_RESULT_INSUFFICIENT_PERSISTENT_STORAGE;
fmResult = fldrmgrDeleteMsg( CMN_CLIENT_MMS, msgId, TRUE);
if (checkFolderError(fmResult) != MMS_RESULT_OK)
{
MMS_LOG_I(("%s(%d): Couldn't remove corrupt notification\n",
__FILE__, __LINE__));
}
MMSa_error(MMS_RESULT_MESSAGE_CORRUPT);
}
else if (fldrmgrSetFlagValid( CMN_CLIENT_MMS, msgId, TRUE) != FM_RESULT_OK)
{
MMS_LOG_I(("%s(%d): Couldn't set the msg as valid and store "
"the index file.\n", __FILE__, __LINE__));
MMSa_error(MMS_RESULT_INDEX_FILE_ERROR);
}
else
{
mmsPduGetMessageClass( pdu, len, &mc);
sendNotifyRespInd( isSmsBearer, trId , MMS_STATUS_DEFERRED,
mc.classIdentifier, version);
notifTableInsert( NOTIF_DELAYED, msgId, uri);
MMSa_notificationReceived( MMS_NOTIFICATION_NORMAL, msgId,
seqId, reason);
}
(void)fldrmgrCloseMessage( CMN_CLIENT_MMS, msgId);
}
M_FREE(uri);
return ret;
}
static CMN_BOOL transientError( MmsRetrieveStatus retrieveStatus)
{
CMN_BOOL isTransient = FALSE;
if (retrieveStatus != MMS_RTRV_STATUS_OK)
{
MMS_LOG_I(("%s(%d): Wrong retrieve status (%d)\n",
__FILE__, __LINE__, retrieveStatus));
if (retrieveStatus != 0 && retrieveStatus < MMS_RTRV_STATUS_P_FAILURE)
{
isTransient = TRUE;
}
}
return isTransient;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -