⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmpdup.c

📁 彩信MMS的全部代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * Copyright (C) Obigo AB, 2002-2005.
 * All rights reserved.
 *
 * This software is covered by the license agreement between
 * the end user and Obigo AB, and may be 
 * used and copied only in accordance with the terms of the 
 * said agreement.
 *
 * Obigo AB assumes no responsibility or 
 * liability for any errors or inaccuracies in this software, 
 * or any consequential, incidental or indirect damage arising
 * out of the use of the software.
 *
 */

















#include "cansilib.h"   
#include "cmnconf.h"    
#include "cmntypes.h"   
#include "aapicmn.h"    
#include "gmem.h"       
#include "cutils.h"     

#include "mmsconf.h"    
#include "mmstypes.h"   
#include "aapimms.h"    
#include "mmem.h"       
#include "mcpdu.h"      
#include "mmpdup.h"     
#include "mfieldp.h"    
#include "msig.h"       
#include "mconfig.h"    


















static unsigned char *getPrevSentBy(char *buf, MmsPrevSentBy *prevSentBy, UINT32 bufLen);
static unsigned char *getPrevSentDate(char *buf, MmsPrevSentDate *prevSentDate, UINT32 bufLen);










MmsResult parseContentLocation(unsigned char *pdu, UINT32 len, char **uri)
{
    MmsHeaderValue  cont;
    MmsHeaderValue  trId;
    MmsHeaderValue  msgType;
    UINT32 tempLen = 0;
    char *str;
    char *contentLocation;

    *uri = NULL;

    
    if (!mmsPduGet( pdu, len, X_MMS_MESSAGE_TYPE, &msgType))
    {
        MMS_LOG_I(("%s(%d): Mandatory field X-Mms-Message-Type is missing.",
            __FILE__, __LINE__));   
        return MMS_RESULT_COMM_HEADER_TAG;
    }
    else if (msgType.messageType == MMS_M_MBOX_DELETE_CONF)
    {
        MMS_LOG_I(("%s(%d): The MMS 1.2 PDU M-Mbox-Delete.conf is not handled yet.",
            __FILE__, __LINE__));   
        return MMS_RESULT_ERROR;
    } 

    
    if (!mmsPduGet( pdu, len, X_MMS_TRANSACTION_ID, &trId))
    {
        MMS_LOG_I(("%s(%d): Mandatory field Transaction ID is missing.",
            __FILE__, __LINE__));   
        return MMS_RESULT_COMM_HEADER_TAG;
    } 

    
    if ( !mmsPduGet( pdu, len, X_MMS_CONTENT_LOCATION, &cont))
    {
        MMS_LOG_I(("parseMmsNotification: Invalid Content-location.\n"));
        return MMS_RESULT_INVALID_CONTENT_LOCATION;
    } 

    contentLocation = (char *)cont.contentLocation;

    
    if (cfgGetInt(MMS_CFG_STANDARD_NOTIFICATION_URI) || 
        contentLocation[0] != EOS)          
    {
        tempLen = strlen((const char *)contentLocation) + 1;
        *uri = M_ALLOC(tempLen);
        strcpy( *uri, contentLocation); 
    }
    else 
    {    
        str = cfgGetStr(MMS_CFG_GET_URI);
        if (str == NULL)
        {
            MMS_LOG_I(("%s(%d): Illegal combination of config variables "
                "MMS_CFG_GET_URI and MMS_CFG_STANDARD_NOTIFICATION_URI.\n", 
                __FILE__, __LINE__));
            return MMS_RESULT_CONFIG_ERROR;
        } 

        tempLen = strlen(str) + strlen(trId.transactionId) + 1;
        *uri = M_ALLOC(tempLen);
        if (sprintf( *uri, "%s%s", str, trId.transactionId) > (int)tempLen)
        {
            MMS_LOG_I(("%s(%d): Wrote outside allocated memory!\n",
                __FILE__, __LINE__));
            MMSa_error(MMS_RESULT_RESTART_NEEDED);

            return MMS_RESULT_RESTART_NEEDED;
        } 
    } 
    
    return MMS_RESULT_OK;
} 









MmsReadOrigInd *parseReadReport(unsigned char *pdu, UINT32 len)
{
    MmsReadOrigInd *mmsReadReport = NULL;
    MmsHeaderValue  headerValue;
    UINT32  tempLen = 0;

    if (pdu == NULL)
    {
        return NULL;
    } 

    mmsReadReport = (MmsReadOrigInd *)M_CALLOC(sizeof(MmsReadOrigInd));

    
    parseFromAddress( pdu, len, &mmsReadReport->from); 

    
    if (mmsPduGet( pdu, len, MMS_DATE, &headerValue))
    {
        mmsReadReport->date = headerValue.date;
    } 

     
    if (mmsPduGet( pdu, len, MMS_MESSAGE_ID, &headerValue))
    {
        tempLen = strlen((const char *)headerValue.messageId) + 1;
        mmsReadReport->serverMessageId = M_ALLOC(tempLen);
        strcpy(mmsReadReport->serverMessageId, headerValue.messageId); 
    } 

    
    if (mmsPduGet( pdu, len, X_MMS_READ_STATUS, &headerValue))
    {
        mmsReadReport->readStatus = (MmsReadStatus)headerValue.readStatus;
    } 

    return mmsReadReport;
} 











MmsResult parseMmsNotification(unsigned char *headerData, UINT32 headerDataSize, 
    MmsNotification *mmsNotification, MmsVersion *version)
{
    MmsHeaderValue  headerValue;
    INT32 size;
    UINT32 tempLen = 0;
    MmsResult result = MMS_RESULT_OK;

    if (mmsNotification == NULL)
    {
        MMS_LOG_I(("%s(%d): Memory not allocated for mmsNotification.",
            __FILE__, __LINE__));   
        return MMS_RESULT_INSUFFICIENT_MEMORY;
    } 
    
    
    memset( mmsNotification, 0, sizeof(MmsNotification));
    
    
 
    mmsNotification->msgClass.classIdentifier = MMS_MESSAGE_CLASS_NOT_SET;
    mmsNotification->msgClass.textString = NULL;
    mmsNotification->replyChargingId = NULL;

    
    parseFromAddress( headerData, headerDataSize, &mmsNotification->from); 

    
    if ( mmsPduGet( headerData, headerDataSize, MMS_SUBJECT, &headerValue))
    {
        UINT32 notUsed = 0; 
        
        size = (INT32)(headerData - (unsigned char *)headerValue.subject) + 
            (INT32)headerDataSize;

        if (size < 0)
        {
            MMS_LOG_I(("%s(%d): Pointer error %ld.", __FILE__, __LINE__, size));   
        }
        else
        {
            parseEncodedStringValue( headerValue.subject, (UINT32)size, &notUsed, 
                &mmsNotification->subject);
        } 
    }   

    
    if (mmsPduGet(headerData, headerDataSize, X_MMS_DELIVERY_REPORT, &headerValue))
    {    
        mmsNotification->deliveryReport= 
            (MmsDeliveryReport)headerValue.deliveryReport;
    } 

    
    if (mmsPduGet(headerData, headerDataSize, X_MMS_MESSAGE_CLASS, &headerValue))
    {    
        MmsMessageClass mc;

        mmsPduGetMessageClass( headerData, headerDataSize, &mc);
        switch (mc.classIdentifier)
        {
        case MMS_MESSAGE_CLASS_PERSONAL :
        case MMS_MESSAGE_CLASS_ADVERTISEMENT :
        case MMS_MESSAGE_CLASS_INFORMATIONAL :
        case MMS_MESSAGE_CLASS_AUTO :
            mmsNotification->msgClass.classIdentifier = mc.classIdentifier;
            break;
        case MMS_MESSAGE_CLASS_IS_TEXT :
            mmsNotification->msgClass.classIdentifier = MMS_MESSAGE_CLASS_NOT_SET;

            if (mc.textString != NULL)
            {
                tempLen = strlen(mc.textString) + 1;
                mmsNotification->msgClass.textString = M_ALLOC(tempLen);
                mmsNotification->msgClass.classIdentifier = 
                    MMS_MESSAGE_CLASS_IS_TEXT;
                strcpy( mmsNotification->msgClass.textString, mc.textString);
            } 
            break;
        case MMS_MESSAGE_CLASS_NOT_SET :
        default :
            mmsNotification->msgClass.classIdentifier = MMS_MESSAGE_CLASS_NOT_SET;
            mmsNotification->msgClass.textString      = NULL;
            break;
        } 
    } 
    else
    {
        MMS_LOG_I(("parseMmsNotification: Invalid message class.\n"));
        return MMS_RESULT_INVALID_MSG_CLASS;
    } 

    
    if (mmsPduGet( headerData, headerDataSize, X_MMS_MESSAGE_SIZE, &headerValue))
    {
        mmsNotification->length = headerValue.messageSize;
    } 

    
    if ( !parseHeaderTime( headerData, headerDataSize, 
        &mmsNotification->expiryTime, X_MMS_EXPIRY))
    {
        
        MMS_LOG_I(("%s(%d): Expiry time (mandatory) is missing.\n",
            __FILE__, __LINE__));
    } 

    
    if (mmsPduGet(headerData, headerDataSize, X_MMS_VERSION, &headerValue))
    {
        *version = (MmsVersion)headerValue.version;
    } 

    
    if (mmsPduGet( headerData, headerDataSize, X_MMS_PRIORITY, &headerValue))
    {
        mmsNotification->priority = (MmsPriority)headerValue.priority;
    } 

    
    if (mmsPduGet( headerData, headerDataSize, X_MMS_DISTRIBUTION_INDICATOR, 
        &headerValue))
    {
        mmsNotification->distributionIndicator = 
            (MmsDistributionIndicator)headerValue.distributionIndicator;
    } 

    
    if (mmsPduGet( headerData, headerDataSize, X_MMS_ELEMENT_DESCRIPTOR, 
        &headerValue))
    {
        size = (INT32)(headerData - (unsigned char *)headerValue.elementDescriptor) + 
            (INT32)headerDataSize;

        if (size < 0)
        {
            MMS_LOG_I(("%s(%d): Pointer error %ld.", __FILE__, __LINE__, size));   
        }
        else
        {
            mmsNotification->elementDescriptor = 
                parseElementDescriptor( headerValue.elementDescriptor, size);
        } 
    } 

    
    if (mmsPduGet(headerData, headerDataSize, X_MMS_REPLY_CHARGING, &headerValue))
    {
        mmsNotification->replyCharging = (MmsReplyCharging)headerValue.replyCharging;
    } 

    
    if ( !parseHeaderTime( headerData, headerDataSize, 
        &mmsNotification->replyChargingDeadline, X_MMS_REPLY_CHARGING_DEADLINE))
    {
        
    } 

    
    if (mmsPduGet(headerData, headerDataSize, X_MMS_REPLY_CHARGING_ID, 
        &headerValue))
    {
        tempLen = strlen((const char *)headerValue.replyChargingId) + 1;
        mmsNotification->replyChargingId = M_ALLOC( tempLen);
        strcpy(mmsNotification->replyChargingId, headerValue.replyChargingId);
    } 

    
    if (mmsPduGet(headerData, headerDataSize, X_MMS_REPLY_CHARGING_SIZE, 
        &headerValue))
    {
        mmsNotification->replyChargingSize = headerValue.replyChargingSize;
    } 

    
    result = parseContentLocation( headerData, headerDataSize, 
        &mmsNotification->contentLocation);

    return result;
} 










void parseDeliveryReport(unsigned char *headerData, UINT32 headerDataSize, 
    MmsDeliveryInd *mmsDelivery)    
{
    MmsHeaderValue  headerValue;
    MmsAddressList  *tmpTo;
    UINT32 tempLen = 0;
  
    if ( headerData == NULL || mmsDelivery == NULL)
    {
        
        MMS_LOG_I(("%s(%d): Memmory not allocated!\n", __FILE__, __LINE__));   
        return;
    } 
    memset( mmsDelivery, 0, sizeof(MmsDeliveryInd));
    
   
     
    if (mmsPduGet(headerData, headerDataSize, X_MMS_VERSION, &headerValue))
    {
        mmsDelivery->version = headerValue.version;
    } 

     
    if (mmsPduGet( headerData, headerDataSize, MMS_MESSAGE_ID, &headerValue))
    {
        tempLen = strlen((const char *)headerValue.messageId) + 1;
        mmsDelivery->messageId = M_ALLOC( tempLen);
        strcpy(mmsDelivery->messageId, headerValue.messageId); 
    } 

     
    mmsDelivery->to = M_CALLOC( sizeof(MmsAddress));
    tmpTo = parseAddress(MMS_TO, headerData, headerDataSize);
    if (tmpTo == NULL)
    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -