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

📄 mcreate.c

📁 彩信MMS的全部代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/*
 * 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 "aapifile.h"   
#include "cmntypes.h"   
#include "aapicmn.h"    
#include "gmem.h"       
#include "fldrmgr.h"    
#include "mmstypes.h"   
#include "mmsconf.h"    
#include "aapimms.h"    
#include "msig.h"       
#include "mmem.h"       
#include "mcreate.h"    
#include "mfetch.h"     
#include "mcpdu.h"      
#include "mmpduc.h"     
#include "mutils.h"     
#include "mconfig.h"    
#include "mmpdup.h"     
#include "mcopy.h"      


#define FILE_APPEND                 -1L




typedef struct
{
    CMN_BOOL isBusy;        
    UINT32 callingFsm;
    UINT32 returnSignal;
    UINT32 altReturnSignal;
    MmsReadStatus readStatus;
    MmsMsgId readRepMsgId;
} MmhCreateInstanceData;


typedef struct
{
    MmsSetBodyParams *bodyParams;           
    MmsResult result;                       
    CMN_BOOL isMultipartEntryFileOpened;    
    CMN_BOOL isBodypartFileOpened;          
} MmsMmhCreateSetBodyParams;















static MmhCreateInstanceData fsm;


static MmsResult appendPartFromBuffer( unsigned char *buf, UINT32 size, 
    MmsBodyPartTarget targetType, UINT32 msgId);
static void closeFiles(MmsMmhCreateSetBodyParams *setParams);
static void convertFileFormat(void);
static void copyFile(MmsMmhCreateSetBodyParams *setParams);
static void createBodyPart(MmsSetBodyParams *bodyParams);
static MmsResult createMsgDone(UINT32 msgId, UINT32 *messageSize);
static MmsResult createRrMessage( const MmsHeader *header, UINT32 *newMsgId);
static MmsHeader *createRrHeader( const MmsHeader *header, const UINT32 date);
static unsigned char *createRrBody( const MmsHeader *header, UINT32 *length);
static unsigned char *createWspHeader(const MmsSetBodyParams *bodyParams,
    UINT32 *encHeaderLen);
static void fsmRelease(void);
static void freeMmsSetBodyParams( MmsSetBodyParams *bodyParams);
static CMN_BOOL mmhCreateIsBusy(MmsSignal *sig);
static void mmhCreateMain(MmsSignal *sig);
static MmsMessageType msgSetDate( MmsMsgId msgId);
static MmsResult storeToFm( unsigned char *data, UINT32 position, 
    UINT32 lenght, UINT32 msgId);
static MmsResult storeWspHeader(const UINT32 msgId, 
    const UINT32 numOfBodyParts, MmsHeader *header);
                











static MmsResult appendPartFromBuffer( unsigned char *buf, UINT32 size, 
    MmsBodyPartTarget targetType, UINT32 msgId)
{
    MmsResult result;

    if (targetType == MMS_MULTIPART_ENTRY)
    {
        result = storeToFile( buf, size, CMN_FILE_CATEGORY_TMP, msgId, FILE_APPEND);
    }
    else
    {   
        result = storeToFm( buf, FM_APPEND, size, msgId);
    } 
    
    return result;
} 






static void closeFiles(MmsMmhCreateSetBodyParams *setParams)
{
    MmsSetBodyParams *bodyParams = setParams->bodyParams;

    if (setParams->isBodypartFileOpened)
    {
        FILEa_close( bodyParams->bodyPart.data.file.category, 
            bodyParams->bodyPart.data.file.id);
        setParams->isBodypartFileOpened = TRUE;
    } 

    if (setParams->isMultipartEntryFileOpened)
    {
        FILEa_close( CMN_FILE_CATEGORY_TMP, bodyParams->msgId);
        setParams->isMultipartEntryFileOpened = TRUE;
    } 

    if (setParams->result != MMS_RESULT_OK && 
        setParams->result != MMS_RESULT_INSUFFICIENT_PERSISTENT_STORAGE)
    {   
        



        if (fldrmgrCloseMessage( CMN_CLIENT_MMS, bodyParams->msgId) != FM_RESULT_OK)
        {
            MMS_LOG_I(("%s(%d): Couldn't close file %lu.\n", 
                __FILE__, __LINE__, bodyParams->msgId));
        } 

        if (fldrmgrDeleteMsg( CMN_CLIENT_MMS, bodyParams->msgId, FALSE) != FM_RESULT_OK)
        {
            MMS_LOG_I(("%s(%d): Couldn't delete file %lu!\n",
                __FILE__, __LINE__, bodyParams->msgId));
        } 
    } 
} 





static void convertFileFormat(void)
{
    FmResult fmRes;
    MmsResult mmsRes;
    UINT32 count;
    UINT32 i;
    UINT32 found;
    UINT32 size;
    UINT32 *allIds = NULL;
    CMN_BOOL isConverted = FALSE;

    fmRes = fldrmgrGetNumberOfMsg( CMN_CLIENT_MMS, FM_ALL_FOLDERS, 
        FM_IS_ANY, &count);
    if (fmRes != FM_RESULT_OK)
    {
        MMS_LOG_I(("%s(%d): unable to convert files %d\n", 
            __FILE__, __LINE__, (int)fmRes));
    }
    else if (count > 0)
    {
        allIds = M_CALLOC((unsigned int)count * sizeof(UINT32));
        fmRes = fldrmgrGetMsgIdList( CMN_CLIENT_MMS, FM_ALL_FOLDERS, count, 
            &found, allIds);

        if (fmRes != FM_RESULT_OK)
        {
            MMS_LOG_I(("%s(%d): unable to convert files %d\n", 
                __FILE__, __LINE__, (int)fmRes));
            M_FREE(allIds);
            return;
        } 

        for ( i = 0; i < count; ++i)
        {
            isConverted = FALSE;
            fmRes = fldrmgrOpenMessage( CMN_CLIENT_MMS, allIds[i], FM_READ);
            if (fmRes != FM_RESULT_OK)
            {
                MMS_LOG_I(("%s(%d): unable to open file %lu to convert, Error %d\n", 
                    __FILE__, __LINE__,  allIds[i], (int)fmRes));
            }
            else if ((mmsRes = createMsgDone( allIds[i], &size)) != MMS_RESULT_OK)
            {
                MMS_LOG_I(("%s(%d): unable to create info file %lu, Error %d\n", 
                    __FILE__, __LINE__,  allIds[i], (int)mmsRes));
            }

            

            else if ( (fmRes = fldrmgrSetFlagValid( CMN_CLIENT_MMS, allIds[i], 
                TRUE)) != FM_RESULT_OK)
            {
                MMS_LOG_I(("%s(%d): Couldn't set the msg as valid, error=%d.\n", 
                    __FILE__, __LINE__, (int)fmRes));
            }
            else
            {
                MMS_LOG_I(("%s(%d): Successfully converted file %lu\n", 
                    __FILE__, __LINE__,  allIds[i]));
                isConverted = TRUE;
            } 
            (void)fldrmgrCloseMessage( CMN_CLIENT_MMS, allIds[i]);

            if ( !isConverted)
            {
                fmRes = fldrmgrDeleteMsg( CMN_CLIENT_MMS, allIds[i], TRUE);
                if (fmRes != FM_RESULT_OK)
                {
                    MMS_LOG_I(("%s(%d): Unable to delete file %d. Error %d.\n",
                        __FILE__, __LINE__, allIds[i], fmRes));
                } 
            } 
        } 

        M_FREE(allIds);
    } 
} 











static void copyFile( MmsMmhCreateSetBodyParams *setParams)
{   
    MmsSetBodyParams *bodyParams = setParams->bodyParams;
    MmsCopyFile *copy;

    copy = M_CALLOC(sizeof(MmsCopyFile));
    copy->sender = M_FSM_MMH_CREATE;
    copy->callerData = setParams;
    copy->from.id = bodyParams->bodyPart.data.file.id;
    copy->from.category = bodyParams->bodyPart.data.file.category;
    copy->from.pos = 0;
    copy->from.bytes = MMH_COPY_ENTIRE_FILE;
    copy->from.isOpen = TRUE;

    if (bodyParams->targetType == MMS_MULTIPART_ENTRY)
    {   
        copy->to.category = CMN_FILE_CATEGORY_TMP;
    }
    else
    {   
        copy->to.category = CMN_FILE_CATEGORY_MSG;
    } 

    copy->to.shouldCreate = FALSE;
    copy->to.id = bodyParams->msgId;
    copy->to.pos = MMH_COPY_APPEND;
    copy->to.isOpen = TRUE;

    if (isMultiPart( bodyParams->contentType.knownValue))
    {   
        copy->from.pos = sizeof(UINT32);
    } 
    
    M_SIGNAL_SENDTO_P( M_FSM_MMH_COPY, MMS_SIG_MMH_COPY_START, copy);
} 






static void createBodyPart(MmsSetBodyParams *bodyParams)
{
    CMN_BOOL isCopying = FALSE;
    UINT32 encHeaderLen = 0;    
    unsigned char *encHeader = NULL;    
    MmsMmhCreateSetBodyParams *setParams;

    setParams = M_CALLOC(sizeof(MmsMmhCreateSetBodyParams));
    setParams->result = MMS_RESULT_OK;
    setParams->bodyParams = bodyParams;

    


    if ( (bodyParams->targetType != MMS_PLAIN_MESSAGE &&
        isMultiPart(bodyParams->contentType.knownValue)) 
        || bodyParams->bodyPart.storageType == MMS_BODY_PART_AS_FILE)
    {
        if ( FILEa_open( bodyParams->bodyPart.data.file.category, 
            bodyParams->bodyPart.data.file.id, FILE_OPTION_READ) != -1)
        {
            setParams->isBodypartFileOpened = TRUE;
        }
        else
        {   
            MMS_LOG_I(("%s(%d): unable to open file %lu in category 0x%x\n",
                __FILE__, __LINE__, bodyParams->bodyPart.data.file.id,
                (int)bodyParams->bodyPart.data.file.category));
            setParams->result = MMS_RESULT_FILE_READ_ERROR;
        } 
    } 

    if (setParams->result != MMS_RESULT_OK)
    {
        
    }
    else if (bodyParams->targetType == MMS_MULTIPART_ENTRY)
    { 
        if ( FILEa_open( CMN_FILE_CATEGORY_TMP, bodyParams->msgId,
            FILE_OPTION_WRITE) != -1)
        {
            setParams->isMultipartEntryFileOpened = TRUE;
        }
        else
        {   
            MMS_LOG_I(("%s(%d): unable to open file %lu in category 0x%x\n",
                __FILE__, __LINE__, bodyParams->msgId, (int)CMN_FILE_CATEGORY_TMP));
            setParams->result = MMS_RESULT_FILE_READ_ERROR;
        } 
    } 

    

    if (setParams->result != MMS_RESULT_OK)
    {
        
    }
    else if (bodyParams->targetType != MMS_PLAIN_MESSAGE)
    {
        encHeader = createWspHeader( bodyParams, &encHeaderLen);
        if (encHeader == NULL)
        {
            setParams->result = MMS_RESULT_ERROR;
        }
        else
        {   
            setParams->result = appendPartFromBuffer( encHeader, encHeaderLen, 
                bodyParams->targetType, bodyParams->msgId);
            M_FREE( encHeader);
            encHeader = NULL;
        } 
    } 
        
    if (setParams->result != MMS_RESULT_OK)
    {
        
    }
    else if (bodyParams->bodyPart.storageType == MMS_BODY_PART_AS_BUFFER)
    {   
        setParams->result = appendPartFromBuffer( bodyParams->bodyPart.data.buffer,
            bodyParams->bodyPart.dataSize, bodyParams->targetType,
            bodyParams->msgId);
    }
    else if (bodyParams->bodyPart.storageType == MMS_BODY_PART_AS_FILE)
    {   
        isCopying = TRUE;
    }
    else
    {   
        MMS_LOG_I(("%s(%d): received unknown storageType\n",
            __FILE__, __LINE__));
        setParams->result = MMS_RESULT_INVALID_STORAGE_TYPE;
    } 
    
    if (isCopying)
    {   
        copyFile(setParams);

⌨️ 快捷键说明

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