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

📄 mcreate.c

📁 彩信MMS的全部代码
💻 C
📖 第 1 页 / 共 4 页
字号:
    }
    else
    {   
        M_SIGNAL_SENDTO_P( M_FSM_MMH_CREATE, MMS_SIG_MMH_SET_BODY_PART_FINISHED, 
            setParams);
    } 
} 









static MmsResult createMsgDone( UINT32 msgId, UINT32 *messageSize)
{
    FmResult result;
    MmsResult ret;

    result = fldrmgrGetMessageSize( CMN_CLIENT_MMS, msgId, messageSize);
    if ( (ret = checkFolderError(result)) != MMS_RESULT_OK)
    {
        MMS_LOG_I(("MMS FSM MMH CREATE: Unable to get message size"));
    }
    else
    {
        ret = createMsgInfoList( msgId, 0);
    } 
    
    return ret;
} 








static unsigned char *createRrBody( const MmsHeader *header, UINT32 *length)
{
    unsigned char *offset   = NULL; 
    unsigned char *body     = NULL;
    char *serverMsgId       = NULL;
    char *textYourMsg       = NULL;
    char *textFrom          = NULL;
    char *textTo            = NULL;
    char *textMsgId         = NULL;
    char *textSent          = NULL;
    char *textWasReadOn     = NULL;
    char *textSubject       = NULL;
    UINT32 size             = 0;
    UINT32 serverMsgIdSize  = 0;

    
    if ( (textYourMsg = cfgGetStr( MMS_CFG_TEXT_YOUR_MSG)) != NULL)
    {
        size += strlen( textYourMsg);
        size += strlen("\n"); 
    } 

    if ( (textFrom = cfgGetStr(MMS_CFG_TEXT_FROM)) != NULL)
    {
        size += strlen( textFrom);
        size += strlen("\n"); 
        if (header->from.address != NULL)
        {
            size += strlen( header->from.address);
        } 
    }  

    if ( (textTo = cfgGetStr( MMS_CFG_TEXT_TO)) != NULL)
    {
        size += strlen(textTo);
        size += strlen("\n"); 
        if (header->to != NULL && header->to->current.address != NULL)
        {
            size += strlen(header->to->current.address);
        } 
    } 

    



    if ( (textMsgId = cfgGetStr( MMS_CFG_TEXT_MSGID)) != NULL)
    {
        if ( header->serverMessageId == NULL)
        {
            serverMsgIdSize = 0;
            serverMsgId = NULL;
        }
        else 
        {   
            serverMsgId = header->serverMessageId;
            serverMsgIdSize = strlen(serverMsgId);
        } 
        
        size += strlen(textMsgId);
        size += serverMsgIdSize;
        size += strlen("\n"); 
    } 

    if ( (textSubject = cfgGetStr(MMS_CFG_TEXT_SUBJECT)) != NULL)
    {
        size += strlen( textSubject);
        size += strlen("\n"); 
        if (header->subject.text != NULL)
        {
            size += strlen(header->subject.text);
        } 
    } 

    if ( (textSent = cfgGetStr(MMS_CFG_TEXT_SENT)) != NULL)
    {
        size += strlen( textSent);
        size += SIZE_OF_DATE;
        size += strlen("\n"); 
    } 

    if ( (textWasReadOn = cfgGetStr(MMS_CFG_TEXT_WAS_READ)) != NULL)
    {
        size += strlen(textWasReadOn);
        size += SIZE_OF_DATE;
        size += strlen("\n"); 
    } 
    
    size += 1; 
    *length = size; 
    body = M_CALLOC(size);
    offset = body;

    
    if (textYourMsg != NULL)
    {
        strcpy( (char *)offset, textYourMsg);
        offset += strlen(textYourMsg);
        *offset = '\n';
        offset += strlen("\n");
    } 

    if (textFrom != NULL)
    {
        strcpy( (char *)offset, textFrom);
        offset += strlen(textFrom);
        if (header->from.address != NULL)
        {
            strcpy( (char *)offset, header->from.address);
            offset += strlen(header->from.address);
        } 

        *offset = '\n';
        offset += strlen("\n");
    } 

    if ( textTo != NULL)
    {
        strcpy( (char *)offset, textTo);
        offset += strlen(textTo);
        if (header->to != NULL && header->to->current.address != NULL)
        {
            strcpy( (char *)offset, header->to->current.address);
            offset += strlen(header->to->current.address);
        } 

        *offset = '\n';
        offset += strlen("\n");
    } 

    if ( textSubject != NULL)
    {
        strcpy( (char *)offset, textSubject);
        offset += strlen(textSubject);
        if ( header->subject.text != NULL)
        {
            
            strcpy( (char *)offset, header->subject.text);
            offset += strlen(header->subject.text);
        } 

        *offset = '\n';
        offset += strlen("\n");
    } 

    if ( textMsgId != NULL)
    {
        strcpy( (char *)offset, textMsgId);
        offset += strlen(textMsgId);

        if (serverMsgId != NULL)
        {
            memcpy( offset, serverMsgId, serverMsgIdSize);
            
            offset += serverMsgIdSize; 
            *offset = '\n';
            offset += strlen("\n");
        } 
    } 

    if ( textSent != NULL)
    {
        strcpy( (char *)offset, textSent);
        offset += strlen(textSent);
        convertDateToString( header->date, (char *)offset);
        offset += SIZE_OF_DATE;
        *offset = '\n';
        offset += strlen("\n");
    } 

    if ( textWasReadOn != NULL)
    {
        strcpy( (char *)offset, textWasReadOn);
        offset += strlen(textWasReadOn);
        convertDateToString( CMNa_currentTime(), (char *)offset);
        offset += SIZE_OF_DATE;
        *offset = '\n';
        offset += strlen("\n");
    } 

    *offset++ = EOS; 

    

    if (cfgGetInt(MMS_CFG_READ_REPORT_MULTIPART_MIXED))
    {
        UINT32 len;
        unsigned char *multipart;
        unsigned char *sum;
        MmsSetBodyParams params;
        MmsResult result;

        params.bodyPart.data.buffer = body;
        params.bodyPart.dataSize = size;
        params.bodyPart.storageType = MMS_BODY_PART_AS_BUFFER;
        params.contentType.knownValue = MMS_TYPE_TEXT_PLAIN;
        params.contentType.params = M_ALLOC(sizeof(MmsAllParams));
        params.contentType.params->param = MMS_CHARSET;
        params.contentType.params->type = MMS_PARAM_INTEGER;
        params.contentType.params->value.integer = CMN_CHARSET_UTF_8;
        params.contentType.params->next = NULL;
        params.contentType.strValue = NULL;
        params.entryHeader = NULL;
        params.msgId = 0; 
        params.targetType = MMS_MULTIPART_MESSAGE;

        
        if ((multipart = createWspBodyPartHead( &params, &len, 0, &result)) == NULL) 
        {
            
            MMS_LOG_I(("%s(%d): unable to createWspBodyPartHead\n",
                __FILE__, __LINE__));
            M_FREE(params.contentType.params);
            M_FREE(body);
            return NULL;
        } 

        
        sum = M_CALLOC(len + size);
        memcpy( sum, multipart, len);   
        memcpy( sum + len, body, size); 
        M_FREE(multipart);  
        M_FREE(body);       
        M_FREE(params.contentType.params);
    
        *length = len + size;
        body = sum;
    } 

    return body;    
} 








static MmsHeader *createRrHeader( const MmsHeader *header, const UINT32 date)
{
    unsigned char *tmpPtr   = NULL;
    MmsHeader *newHeader    = M_CALLOC( sizeof( MmsHeader));
    char *textRead          = NULL;
    UINT32 tmpVal           = 0;

    
    tmpVal = sizeof( MmsAddressList);
    newHeader->to = M_ALLOC( tmpVal);
    if (copyAddress( &newHeader->to->current, &header->from) == FALSE)
    {
        MMS_LOG_I(("createRrHeader: unable to copy To address"));
        freeMmsHeader(newHeader);
        M_FREE(newHeader);
        return NULL;
    } 
    newHeader->to->next = NULL;
    
    
    tmpVal = sizeof( MmsContentType);
    newHeader->contentType = M_CALLOC( tmpVal);

    if (cfgGetInt(MMS_CFG_READ_REPORT_MULTIPART_MIXED))
    {
        newHeader->contentType->knownValue = MMS_VND_WAP_MULTIPART_MIXED;
        newHeader->contentType->strValue = NULL;
        newHeader->contentType->params = NULL;
    }
    else 
    {
        newHeader->contentType->knownValue = MMS_TYPE_TEXT_PLAIN;
        newHeader->contentType->strValue = NULL;
        newHeader->contentType->params = NULL;
    } 
    
    
    newHeader->subject.charset = header->subject.charset;
    if (((textRead = cfgGetStr(MMS_CFG_TEXT_READ)) != NULL) &&
        header->subject.text != NULL)
    {
        
        tmpVal = strlen(textRead) + strlen(header->subject.text) + 1;
        newHeader->subject.text = M_ALLOC(tmpVal);
        strcpy( newHeader->subject.text, textRead);
        tmpPtr = (unsigned char *)newHeader->subject.text + strlen(textRead);
        strcpy( (char *)tmpPtr, header->subject.text);
    }
    else if ( header->subject.text != NULL)
    {
        
        tmpVal = strlen( header->subject.text) + 1;
        newHeader->subject.text = M_ALLOC( tmpVal);
        strcpy( newHeader->subject.text, header->subject.text);
    }
    else
    {
        
        if ( textRead != NULL)
        {
            tmpVal = strlen( textRead) + 1;
            newHeader->subject.text = M_ALLOC( tmpVal);
            strcpy( newHeader->subject.text, textRead);
        } 
    }  
    newHeader->subject.charset = CMN_CHARSET_UTF_8;

    

    


    newHeader->msgClass.classIdentifier = MMS_MESSAGE_CLASS_AUTO;
    newHeader->readReply = MMS_READ_REPLY_NO;
    newHeader->deliveryReport = MMS_DELIVERY_REPORT_NO; 
    newHeader->date = date; 
    newHeader->priority = MMS_PRIORITY_NOT_SET;
    newHeader->visibility = MMS_SENDER_VISIBILITY_NOT_SET;
    
    return newHeader;
}  








static MmsResult createRrMessage( const MmsHeader *header, UINT32 *newMsgId)
{
    MmsResult ret;
    FmResult fmResult;
    MmsHeader *newHeader = NULL;
    UINT32 length = 0;
    unsigned char *pduData = NULL;
    unsigned char *pduBody = NULL;
    MmsVersion version;

    version = (MmsVersion)cfgGetInt(MMS_CFG_PROXY_RELAY_VERSION);
#if MMS_CREATE_1_0_READ_REPORT_IN_OUTBOX
    ret = checkFolderError( fldrmgrCreateMsg( CMN_CLIENT_MMS, newMsgId, 
        MMS_OUTBOX, FALSE));
#else
    ret = checkFolderError( fldrmgrCreateMsg( CMN_CLIENT_MMS, newMsgId, 
        MMS_DRAFTS, FALSE));
#endif
    
    if ( ret != MMS_RESULT_OK)
    {
        *newMsgId = 0;
        return ret;
    } 

    if (header != NULL)
    {
        
        if ((newHeader = createRrHeader( header, 0)) == NULL)
        {
            MMS_LOG_I(("MMS FSM MMH CREATE: Unable to create Read report header"));
            ret = MMS_RESULT_ERROR;
        }
        
        else if (( pduData = createWspSendHeader( newHeader, 1, &length, 
            &ret, version)) == NULL)
        {
            MMS_LOG_I(("MMS FSM MMH CREATE: Unable to encode Read report header"));
        }
        
        else if (( ret = storeToFm( pduData, FM_APPEND, length, *newMsgId))
           != MMS_RESULT_OK)
        {
            MMS_LOG_I(("MMS FSM MMH CREATE: Unable to store Read report header"));
        } 
        
        else if ((pduBody = createRrBody( header, &length)) == NULL)
        {
            MMS_LOG_I(("MMS FSM MMH CREATE: Unable to create Read report body"));

⌨️ 快捷键说明

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