📄 mnotify.c
字号:
{
M_SIGNAL_SENDTO( M_FSM_MSR_NOTIFY, MMS_SIG_MSR_CHECK_IMMEDIATE_RETRIEVALS);
}
}
static void immediateRetrievalFinished(MmsSigMsrReceiveParam *p)
{
MmsHeaderValue trId;
MmsHeaderValue ver;
MmsMessageClass mc;
CMN_BOOL isRetrying = FALSE;
MmsResult mmsResult = MMS_RESULT_OK;
if (p == NULL || p->pdu == NULL)
{
MMS_LOG_I(("%s(%d): Parameter error.\n", __FILE__, __LINE__));
return;
}
else if (p->result == MMS_RESULT_BUSY)
{
M_TIMER_SET( M_FSM_MSR_NOTIFY, MMS_NOTIFY_TIMEOUT);
}
else if (!mmsPduGet( p->pdu, p->len, X_MMS_TRANSACTION_ID, &trId) ||
trId.transactionId == NULL)
{
MMS_LOG_I(("%s(%d): Missing transaction ID.\n", __FILE__, __LINE__));
msrNotifyRemoveId( NOTIF_IMMEDIATE, p->notifId);
}
else if (!mmsPduGet( p->pdu, p->len, X_MMS_VERSION, &ver))
{
MMS_LOG_I(("%s(%d): Missing version.\n", __FILE__, __LINE__));
msrNotifyRemoveId( NOTIF_IMMEDIATE, p->notifId);
}
else
{
switch (p->result)
{
case MMS_RESULT_OK :
mmsPduGetMessageClass( p->pdu, p->len, &mc);
sendNotifyRespInd( p->isSmsBearer, trId.transactionId,
MMS_STATUS_RETRIEVED, mc.classIdentifier,
(MmsVersion)ver.version);
msrNotifyRemoveId( NOTIF_IMMEDIATE, p->notifId);
MMSa_notificationReceived( MMS_NOTIFICATION_MESSAGE, p->msgId,
p->seqId, MMS_NOTIFICATION_REASON_NORMAL);
break;
case MMS_RESULT_MAX_DOWNLOAD_SIZE_EXCEEDED :
mmsResult = storeDelayedRetrieval( NOTIF_IMMEDIATE, p->notifId,
p->time, p->isSmsBearer, p->len, p->pdu, (MmsVersion)ver.version,
MMS_NOTIFICATION_REASON_MAX_DOWNLOAD_SIZE_EXCEEDED, p->seqId);
break;
case MMS_RESULT_INSUFFICIENT_PERSISTENT_STORAGE :
mmsResult = storeDelayedRetrieval( NOTIF_IMMEDIATE, p->notifId,
p->time, p->isSmsBearer, p->len, p->pdu, (MmsVersion)ver.version,
MMS_NOTIFICATION_REASON_FULL_PERSISTENT_STORAGE, p->seqId);
break;
case MMS_RESULT_CANCELLED_BY_USER :
mmsResult = storeDelayedRetrieval( NOTIF_IMMEDIATE, p->notifId,
p->time, p->isSmsBearer, p->len, p->pdu, (MmsVersion)ver.version,
MMS_NOTIFICATION_REASON_CANCELLED_BY_USER, p->seqId);
break;
default :
if ((p->result == MMS_RESULT_COMM_TIMEOUT ||
p->result == MMS_RESULT_COMM_NETWORK_UNAVAILABLE ||
transientError(p->retrieveStatus)) &&
moreAttempts(p->notifId))
{
MMS_LOG_I(("%s(%d): Transient error (%d)/timeout(%d). Retrying "
"immediate retrieval later.\n", __FILE__, __LINE__));
M_TIMER_SET( M_FSM_MSR_NOTIFY,
cfgGetInt(MMS_CFG_IMM_RET_RETRY_TIMEOUT));
isRetrying = TRUE;
}
else
{
MMS_LOG_I(("%s(%d): Download failed %d. Transfering notification to "
"deferred retrieval instead.\n", __FILE__, __LINE__, p->result));
mmsResult = storeDelayedRetrieval( NOTIF_IMMEDIATE, p->notifId,
p->time, p->isSmsBearer, p->len, p->pdu, (MmsVersion)ver.version,
MMS_NOTIFICATION_REASON_DOWNLOAD_FAILED, p->seqId);
}
break;
}
}
if (!isRetrying &&
p->result != MMS_RESULT_BUSY &&
mmsResult != MMS_RESULT_INSUFFICIENT_PERSISTENT_STORAGE)
{
M_SIGNAL_SENDTO( M_FSM_MSR_NOTIFY, MMS_SIG_MSR_CHECK_IMMEDIATE_RETRIEVALS);
}
msrReceiveFreeParam(p);
}
static CMN_BOOL isImmediateRetrieval(const MmsNotification *mmsNotification)
{
CMN_BOOL ret = FALSE;
char *serverList;
if (mmsNotification == NULL)
{
MMS_LOG_I(("%s(%d): Missing parameter.\n", __FILE__, __LINE__));
return FALSE;
}
if (mmsNotification->length > cfgGetInt(MMS_CFG_MAX_SIZE_OF_MSG))
{
MMS_LOG_I(("Not immediate retrieval: msg len %d > config size %d\n",
mmsNotification->length, cfgGetInt(MMS_CFG_MAX_SIZE_OF_MSG)));
return FALSE;
}
serverList = cfgGetStr(MMS_CFG_IMMEDIATE_RETRIEVAL_SERVER);
if (serverList != NULL && strlen(serverList) > 0)
{
if (isInServerList( serverList, mmsNotification->contentLocation) == FALSE)
{
MMS_LOG_I(("Not immediate retrieval: server %s not in list %s.\n",
serverList, mmsNotification->contentLocation));
return FALSE;
}
}
if (mmsNotification->from.address == NULL && !cfgGetInt(MMS_CFG_ANONYMOUS_SENDER))
{
MMS_LOG_I(("Not immediate retrieval: anonymous sender not accepted.\n"));
return FALSE;
}
switch (mmsNotification->msgClass.classIdentifier)
{
case MMS_MESSAGE_CLASS_PERSONAL:
if (cfgGetInt(MMS_CFG_CLASS_PERSONAL))
{
ret = TRUE;
}
break;
case MMS_MESSAGE_CLASS_ADVERTISEMENT:
if (cfgGetInt(MMS_CFG_CLASS_ADVERTISEMENT))
{
ret = TRUE;
}
break;
case MMS_MESSAGE_CLASS_INFORMATIONAL:
if (cfgGetInt(MMS_CFG_CLASS_INFORMATIONAL))
{
ret = TRUE;
}
break;
case MMS_MESSAGE_CLASS_AUTO:
if (cfgGetInt(MMS_CFG_CLASS_AUTO))
{
ret = TRUE;
}
break;
case MMS_MESSAGE_CLASS_IS_TEXT:
if (mmsNotification->msgClass.textString != NULL)
{
if (strcmp(mmsNotification->msgClass.textString,
cfgGetStr(MMS_CFG_CLASS_STRING)) == 0)
{
ret = TRUE;
}
}
break;
case MMS_MESSAGE_CLASS_NOT_SET:
default:
MMS_LOG_I(("%s(%d): Illegal msg class %d.\n", __FILE__, __LINE__,
(int)mmsNotification->msgClass.classIdentifier));
ret = FALSE;
break;
}
return ret;
}
static CMN_BOOL isInServerList( const char *serverList, const char *uri)
{
const char *authority;
const char *uriStart;
CMN_BOOL isFound = FALSE;
if (serverList == NULL || uri == NULL)
{
return FALSE;
}
while (*uri && *uri != ':')
{
++uri;
}
while (*uri && (*uri == ':' || *uri == '/'))
{
++uri;
}
authority = strchr( uri, '@');
if (authority != NULL)
{
uri = ++authority;
}
uriStart = uri;
while (*serverList && !isFound)
{
while (*serverList && *uri && CMN_TOLOWER(*serverList) == CMN_TOLOWER(*uri))
{
++serverList;
++uri;
}
if ((*serverList == EOS || IS_HOST_SEPARATOR(*serverList)) &&
!IS_HOST_LETTER(*uri))
{
isFound = TRUE;
}
else if (*serverList != EOS)
{
while (*serverList && !IS_HOST_SEPARATOR(*serverList))
{
++serverList;
}
if (IS_HOST_SEPARATOR(*serverList))
{
++serverList;
}
uri = uriStart;
}
}
return isFound;
}
static CMN_BOOL moreAttempts( UINT32 fileId)
{
int i;
for ( i = 0; i < fsm.notifTable.count; ++i)
{
if (fileId == fsm.notifTable.notif[i].fileId &&
fsm.notifTable.notif[i].type == NOTIF_IMMEDIATE)
{
if (++fsm.notifTable.notif[i].retries <
cfgGetInt(MMS_CFG_IMM_RET_RETRY_ATTEMPTS))
{
return TRUE;
}
else
{
return FALSE;
}
}
}
return FALSE;
}
void msrNotifyDeleteQueue(void)
{
int nrOfFiles = 0;
UINT32 *allFileIds = NULL;
nrOfFiles = FILEa_getFileIds( MMS_FILE_CATEGORY_IMMEDIATE, NULL, 0);
if (nrOfFiles <= 0)
{
return;
}
allFileIds = M_CALLOC((UINT32)nrOfFiles * sizeof(UINT32));
if (FILEa_getFileIds( MMS_FILE_CATEGORY_IMMEDIATE, allFileIds, nrOfFiles) <= 0)
{
MMS_LOG_I(("%s(%d): FILEa_getFileIds returned error\n",
__FILE__, __LINE__));
}
while ( --nrOfFiles >= 0)
{
if (allFileIds[nrOfFiles] != 0)
{
FILEa_delete( MMS_FILE_CATEGORY_IMMEDIATE, allFileIds[nrOfFiles]);
}
}
M_FREE( allFileIds);
}
void msrNotifyDeleteTable(void)
{
int ret;
notifTableFreeMemory();
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;
}
if (FILEa_setSize( MMS_FILE_CATEGORY_IMMEDIATE, NOTIF_TABLE_FILE_ID, 0) != 0)
{
CMN_LOG_I(("%s(%d): Couldn't clear notif table\n", __FILE__, __LINE__));
}
FILEa_close( MMS_FILE_CATEGORY_IMMEDIATE, NOTIF_TABLE_FILE_ID);
}
void msrNotifyImmediateCheck(void)
{
M_TIMER_RESET(M_FSM_MSR_NOTIFY);
if (cfgGetInt(MMS_CFG_IMMEDIATE_RETRIEVAL) != MMS_IMMEDIATE_RETRIEVAL_PAUSED)
{
M_SIGNAL_SENDTO( M_FSM_MSR_NOTIFY, MMS_SIG_MSR_CHECK_IMMEDIATE_RETRIEVALS);
}
}
void msrNotifyInit(void)
{
memset( &fsm, 0, sizeof(fsm));
fsm.notifTable.count = 0;
fsm.state = MSR_IDLE;
mSignalRegisterDst(M_FSM_MSR_NOTIFY, msrNotifyMain);
notifInit();
notifTableRead();
M_TIMER_SET( M_FSM_MSR_NOTIFY, MMS_NOTIFY_TIMEOUT_INIT);
MMS_LOG_I(("MMS FSM MSR NOTIFY: initialized\n"));
}
static void msrNotifyMain(MmsSignal *sig)
{
MmsMsrNotificationParam *param;
switch (sig->type)
{
case MMS_SIG_MSR_NOTIFICATION:
MMS_LOG_I(("MSR Notify FSM, Received MMS_SIG_MSR_NOTIFICATION\n"));
param = (MmsMsrNotificationParam *)sig->p_param;
if (param == NULL)
{
MMS_LOG_I(("%s(%d): Illegal signal %d\n",
__FILE__, __LINE__, param));
break;
}
if (param->type == MMS_M_DELIVERY_IND)
{
handleDeliveryReport( param->size, param->pdu);
M_FREE(param->pdu);
M_FREE(param);
}
else if (param->type == MMS_M_NOTIFICATION_IND)
{
(void)handleNotification( NOTIF_UNSTORED, 0, param->time,
param->isSmsBearer, param->size, param->pdu);
M_FREE(param);
}
else if (param->type == MMS_M_READ_ORIG_IND)
{
handleReadReport( param->size, param->pdu);
M_FREE(param->pdu);
M_FREE(param);
}
else
{
MMS_LOG_I(("%s(%d): Received unsupported notification %d\n",
__FILE__, __LINE__, param->type));
M_FREE(param->pdu);
M_FREE(param);
}
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -