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

📄 ospmime.c

📁 radius协议源码÷The Radius Stack will connect to a Radius Server. This stack implementation is built upo
💻 C
📖 第 1 页 / 共 3 页
字号:
        OSPM_MEMCPY(next,            ospvMessage->MsgPart->Content,            ospvMessage->MsgPart->Length);        next+=ospvMessage->MsgPart->Length;        if(ospvMessage->SigPart->Length > 0)        {            /* CRLF for end of message body */            OSPM_MEMCPY(next,                OSPC_MIME_CRLF,                2);            next += 2;            /* CRLF for beginning of boundary */            OSPM_MEMCPY(next,                OSPC_MIME_CRLF,                2);            next += 2;            /* -- for start of boundary */            OSPM_MEMCPY(next,                OSPC_MIME_BOUNDARY_DELIM,                2);            next += 2;            /* boundary */            OSPM_MEMCPY(next,                OSPC_MIME_BOUNDARY,                boundln);            next += boundln;            /* CRLF for end of boundary */            OSPM_MEMCPY(next,                OSPC_MIME_CRLF,                2);            next += 2;            /* Signature Header */            OSPM_MEMCPY(next,                OSPC_MIME_SIG_HEADER,                sighdrln);            next += sighdrln;            /* Signature length */            OSPM_MEMCPY(next,                sigtmp,                sigszln);            next+=sigszln;            /* CRLF for end of signature header */            OSPM_MEMCPY(next,                OSPC_MIME_CRLF,                2);            next += 2;            /* CRLF for beginning of content */            OSPM_MEMCPY(next,                OSPC_MIME_CRLF,                2);            next += 2;            /* Signature content */            OSPM_MEMCPY(next,                ospvMessage->SigPart->Content,                ospvMessage->SigPart->Length);            next+=ospvMessage->SigPart->Length;            /* CRLF for end of signature body */            OSPM_MEMCPY(next,                OSPC_MIME_CRLF,                2);            next += 2;            /* CRLF for start of boundary */            OSPM_MEMCPY(next,                OSPC_MIME_CRLF,                2);            next += 2;            /* -- for start of boundary */            OSPM_MEMCPY(next,                OSPC_MIME_BOUNDARY_DELIM,                2);            next += 2;            /* boundary */            OSPM_MEMCPY(next,                OSPC_MIME_BOUNDARY,                boundln);            next += boundln;            /* -- for end of final boundary */            OSPM_MEMCPY(next,                OSPC_MIME_BOUNDARY_DELIM,                2);            next += 2;            /* CRLF for end of boundary */            OSPM_MEMCPY(next,                OSPC_MIME_CRLF,                2);            next += 2;        }    }    OSPM_DBGEXIT(("EXIT : OSPPMimeMessageBuild()\n"));    return errorcode;}intOSPPMimeMessageCreate(    unsigned char   *ospvMessage,    unsigned        ospvSizeOfMessage,    unsigned char   *ospvSignature,    unsigned        ospvSizeOfSignature,    unsigned char   **ospvMimeMessage,    unsigned        *ospvSizeOfMimeMessage){    int errorcode = OSPC_ERR_NO_ERROR;    OSPTMIMEMSG msg;    OSPM_DBGENTER(("ENTER: OSPPMimeMessageCreate()\n"));    /* Initialize the structure to hold the Mime message data */    errorcode = OSPPMimeMessageInit(&msg);    /* Set up the message and signature parts. We will use this function for the      * signature part as well when we get a real signature in */    if(errorcode == OSPC_ERR_NO_ERROR)    {        errorcode = OSPPMimeMessageSetContentAndLength(msg.MsgPart, ospvMessage, ospvSizeOfMessage);    }    if((errorcode == OSPC_ERR_NO_ERROR) && (ospvSignature != OSPC_OSNULL))    {        errorcode = OSPPMimeMessageSetContentAndLength(msg.SigPart, ospvSignature, ospvSizeOfSignature);    }    /* Build the MIME message */    if(errorcode == OSPC_ERR_NO_ERROR)    {        errorcode = OSPPMimeMessageBuild(&msg, ospvMimeMessage, ospvSizeOfMimeMessage);    }    /* Free the structure holding the message data */    OSPPMimeDataFree(&msg);    OSPM_DBGEXIT(("EXIT : OSPPMimeMessageCreate()\n"));    return errorcode;}intOSPPMimeMessageInit(    OSPTMIMEMSG *ospvMessage){    int     errorcode = OSPC_ERR_NO_ERROR;    OSPM_DBGENTER(("ENTER: OSPPMimeMessageInit()\n"));    if(ospvMessage != (OSPTMIMEMSG *)NULL)    {        OSPM_MEMSET(ospvMessage,            0,            sizeof(OSPTMIMEMSG));    }    else    {        errorcode = OSPC_ERR_MIME_VAR_NOT_FOUND;        OSPM_DBGERRORLOG(errorcode, "no pointer found for mime message");    }    if(errorcode == OSPC_ERR_NO_ERROR)    {        OSPM_MALLOC(ospvMessage->MsgPart,            OSPTMIMEPART,            sizeof(OSPTMIMEPART));        if(ospvMessage->MsgPart == (OSPTMIMEPART *)NULL)        {            errorcode = OSPC_ERR_MIME_MALLOC_FAILED;            OSPM_DBGERRORLOG(errorcode, "can't malloc message part");        }        else        {            OSPM_MEMSET(ospvMessage->MsgPart,                0,                sizeof(OSPTMIMEPART));        }        if(errorcode == OSPC_ERR_NO_ERROR)        {            OSPM_MALLOC(ospvMessage->SigPart,                OSPTMIMEPART,                sizeof(OSPTMIMEPART));            if(ospvMessage->SigPart == (OSPTMIMEPART *)NULL)            {                errorcode = OSPC_ERR_MIME_MALLOC_FAILED;                OSPM_DBGERRORLOG(errorcode, "can't malloc signature part");            }            else            {                OSPM_MEMSET(ospvMessage->SigPart,                    0,                    sizeof(OSPTMIMEPART));            }        }        if(errorcode == OSPC_ERR_NO_ERROR)        {            ospvMessage->Length = strlen(OSPC_MIME_MSG_HEADER) + strlen(OSPC_MIME_SIG_HEADER);            ospvMessage->NumParts = 2;        }    }    OSPM_DBGEXIT(("EXIT : OSPPMimeMessageInit()\n"));    return errorcode;}intOSPPMimeMessageParse(    unsigned char   *ospvMessageBuffer,    unsigned        ospvSizeOfMessageBuffer,    unsigned char   *ospvContent,    unsigned        ospvSizeOfContent,    unsigned char   **ospvMessageData,    unsigned        *ospvSizeOfMessageData,    unsigned char   **ospvSignatureData,    unsigned        *ospvSizeOfSignatureData){    int             errorcode   = OSPC_ERR_NO_ERROR,                    result      = -1;    OSPTMIMEFIELD   content;    OSPTMIMEBODY    mimebody;    OSPTMIMEPART    boundary, body;    unsigned        currpos     = 0;    OSPM_DBGENTER(("ENTER: OSPPMimeMessageParse()\n"));    OSPM_MEMSET(&mimebody, 0, sizeof(OSPTMIMEBODY));    OSPM_MEMSET(&body, 0, sizeof(OSPTMIMEPART));    OSPM_MEMSET(&boundary, 0, sizeof(OSPTMIMEPART));    OSPM_MEMSET(&content, 0, sizeof(OSPTMIMEFIELD));    /* Make sure we have only the field body without the field name.*/    while((isspace(ospvContent[currpos])) &&         (currpos < ospvSizeOfContent))    {        currpos++;    }    /* if we find a 'c' we have the field name. Get past it */    if(tolower(ospvContent[currpos]) == 'c')    {        while(currpos < ospvSizeOfContent)        {            if(ospvContent[currpos] == ':')            {                break;            }            currpos++;        }        /* get past the ':' */        currpos++;    }    /* Is there anything left? If so, get to the chars */    if(currpos < ospvSizeOfContent)    {        while((isspace(ospvContent[currpos])) &&             (currpos < ospvSizeOfContent))        {            currpos++;        }    }    content.FieldBody.Content = &ospvContent[currpos];    content.FieldBody.Length = ospvSizeOfContent - currpos;    body.Content = ospvMessageBuffer;    body.Length = ospvSizeOfMessageBuffer;    /* Make sure all the parameters meet our criteria, and copy      * the ones we intend to keep into their places      */    if(errorcode == OSPC_ERR_NO_ERROR)    {        errorcode = OSPPMimeVerifyParameters(&content, &boundary, OSPC_MAIN);    }    /* Pull out the body parts, i.e. the message and the signature */    if(errorcode == OSPC_ERR_NO_ERROR)    {        errorcode = OSPPUtilMemCaseCmp(content.FieldBody.Content,            content.FieldBody.Length,            "text/plain",            strlen("text/plain"),            &result);        if((errorcode == OSPC_ERR_NO_ERROR) &&            (result == 0))        {            OSPM_MALLOC(mimebody.BodyParts[0],                OSPTMIMEPART,                sizeof(OSPTMIMEPART));            if(mimebody.BodyParts[0] != (OSPTMIMEPART *)NULL)            {                OSPM_MEMSET(mimebody.BodyParts[0],                    0,                    sizeof(mimebody.BodyParts[0]));                mimebody.BodyParts[0]->Content = ospvMessageBuffer;                mimebody.BodyParts[0]->Length = ospvSizeOfMessageBuffer;                mimebody.NumBodyParts = 1;            }        }        else        {            errorcode = OSPPMimeBodyPartsParse(&body, &mimebody, &boundary);        }    }    /* Copy the body parts into the buffers to be sent back. Set the length of each */    if(errorcode == OSPC_ERR_NO_ERROR)    {        if(mimebody.NumBodyParts > 0)        {            errorcode = OSPPUtilMallocAndCopySubString(mimebody.BodyParts[0]->Content,                ospvMessageData,                0,                mimebody.BodyParts[0]->Length);            if(errorcode == OSPC_ERR_NO_ERROR)            {                *ospvSizeOfMessageData = mimebody.BodyParts[0]->Length;                if(mimebody.NumBodyParts > 1 )                {                    errorcode = OSPPUtilMallocAndCopySubString(mimebody.BodyParts[1]->Content,                        ospvSignatureData,                        0,                        mimebody.BodyParts[1]->Length);                    if(errorcode == OSPC_ERR_NO_ERROR)                    {                        *ospvSizeOfSignatureData = mimebody.BodyParts[1]->Length;                    }                }            }            }        else        {            errorcode = OSPC_ERR_MIME_MSG_PARTS_NOT_FOUND;            OSPM_DBGERRORLOG(errorcode, "not enough message parts for full message");        }    }    OSPPMimeFieldFree(&content);    if(strstr((const char *)content.FieldBody.Content, "multipart"))    {        OSPPMimeBodyFree(&mimebody);    }    else    {        OSPM_FREE(mimebody.BodyParts[0]);    }    if (boundary.Content)    {        OSPM_FREE(boundary.Content);        boundary.Content = OSPC_OSNULL;    }    OSPM_DBGEXIT(("EXIT : OSPPMimeMessageParse()\n"));    return errorcode;}long __mptr=0;intOSPPMimeMessageSetContentAndLength(    OSPTMIMEPART    *ospvMimePart,    unsigned char   *ospvMsgBuffer,    unsigned        ospvSizeOfMsgBuffer){    int errorcode = OSPC_ERR_NO_ERROR;    OSPM_DBGENTER(("ENTER: OSPPMimeMessageSetContentAndLength()\n"));    if(ospvSizeOfMsgBuffer > 0)    {        OSPM_MALLOC(ospvMimePart->Content,             unsigned char,             ospvSizeOfMsgBuffer + 1);        if(ospvMimePart->Content != (unsigned char *)NULL)        {            OSPM_MEMCPY(ospvMimePart->Content,                ospvMsgBuffer,                ospvSizeOfMsgBuffer);            ospvMimePart->Length = ospvSizeOfMsgBuffer;        }        else        {            errorcode = OSPC_ERR_MIME_MALLOC_FAILED;            OSPM_DBGERRORLOG(errorcode, "can't malloc msg content part");        }    }    else    {        errorcode = OSPC_ERR_MIME_NO_INPUT;        OSPM_DBGERRORLOG(errorcode, "no data input for msg part");    }    OSPM_DBGEXIT(("EXIT : OSPPMimeMessageSetContentAndLength()\n"));    return errorcode;}voidOSPPMimeParamFree(    OSPTMIMEPARAM   *ospvParam){    OSPM_DBGENTER(("ENTER: OSPPMimeParamFree()\n"));    if(ospvParam != (OSPTMIMEPARAM  *)NULL)    {        OSPPMimePartFree(ospvParam->ParamName);        OSPPMimePartFree(ospvParam->ParamValue);    }    OSPM_DBGEXIT(("EXIT : OSPPMimeParamFree()\n"));    return;}intOSPPMimeParamsParse(    OSPTMIMEFIELD   *ospvField){    int             errorcode = OSPC_ERR_NO_ERROR;    unsigned        start = 0;    unsigned        currpos = 0;    unsigned        bufend = ospvField->FieldBody.Length;    unsigned char   *bufptr = ospvField->FieldBody.Content;    unsigned        count = 0;    unsigned        len = 0;    OSPM_DBGENTER(("ENTER: OSPPMimeParamsParse()\n"));    if(bufptr != (unsigned char *)NULL)    {        /* Get past the type/subtype string */        while((bufptr[currpos] != ';') &&              (bufptr[currpos] != '\n') &&              (currpos < bufend))        {            currpos++;        }        /* pass the ; */        if(bufptr[currpos] == ';')        {            currpos++;            /* Now get the name = value pairs and store them */            while((ospvField->NumParams < OSPC_MAX_PARAMS) &&                (currpos < bufend))            {                /* Skip spaces, tabs, newlines, and stray ';' */                while (currpos < bufend)                 {                    if ((bufptr[currpos] != ' ') &&                         (bufptr[currpos] != '\t') &&                        (bufptr[currpos] != '\n') &&                        (bufptr[currpos] != ';'))                    {                        break;

⌨️ 快捷键说明

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