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

📄 ospmime.c

📁 mgcp协议源代码。支持多种编码:g711
💻 C
📖 第 1 页 / 共 3 页
字号:
                    }                    ++currpos;                }                start = currpos;                while(currpos < bufend)                {                    if(bufptr[currpos] == '=')                    {                        break;                    }                    currpos++;                }                len = currpos - start;                /* remove white space at end */                while(len > 0)                {                    if(!isspace(bufptr[currpos-1]))                    {                        break;                    }                    --len;                }                /* Create Param structure */                OSPM_MALLOC(ospvField->Params[count],                    OSPTMIMEPARAM,                    sizeof(OSPTMIMEPARAM));                if(ospvField->Params[count] != (OSPTMIMEPARAM *)NULL)                {                    OSPM_MEMSET(ospvField->Params[count],                        0,                        sizeof(OSPTMIMEPARAM));                    /* Create Param Name Structure */                    OSPM_MALLOC(ospvField->Params[count]->ParamName,                        OSPTMIMEPART,                        sizeof(OSPTMIMEPART));                    if(ospvField->Params[count]->ParamName != (OSPTMIMEPART *)NULL)                    {                        OSPM_MEMSET(ospvField->Params[count]->ParamName,                            0,                            sizeof(OSPTMIMEPART));                        errorcode = OSPPUtilMallocAndCopySubString(ospvField->FieldBody.Content,                            &(ospvField->Params[count])->ParamName->Content,                            start,                            len);                    }                    else                    {                        errorcode = OSPC_ERR_MIME_MALLOC_FAILED;                        OSPM_DBGERRORLOG(errorcode, "malloc failed for param name structure");                    }                }                else                {                    errorcode = OSPC_ERR_MIME_MALLOC_FAILED;                    OSPM_DBGERRORLOG(errorcode, "malloc failed for param structure");                }                /* Now get value */                if(errorcode == OSPC_ERR_NO_ERROR)                {                    ospvField->Params[count]->ParamName->Length = len;                    if((currpos < bufend) && (bufptr[currpos] == '='))                    {                        currpos++;                    }                    /* Skip spaces and tabs */                    while (currpos < bufend)                     {                        if ((bufptr[currpos] != ' ') &&                             (bufptr[currpos] != '\t'))                         {                            break;                        }                        ++currpos;                    }                    start = currpos;                    len = 0;                    /* Get value */                    while(currpos < bufend)                    {                        /* ; means we are at the end of the param value                         * get rid of it */                        if(bufptr[currpos] == ';')                        {                            break;                        }                        if(bufptr[currpos] == '\n')                        {                            /* Are we at the end of the data? */                            if(currpos == bufend -1)                            {                                currpos++;                                break;                            }                            /* Is this really the end of the param value, and not just the end                             * of a wrapped line? */                            else if ((bufptr[currpos+1] != ' ') &&                                 (bufptr[currpos+1] != '\t'))                             {                                currpos++;                                break;                            }                        }                        currpos++;                    }                    /* remove whitespace at end of value */                    while(currpos > start)                    {                        if(!isspace(bufptr[currpos-1]))                        {                            break;                        }                        --currpos;                    }                    len = currpos - start;                    /* Create Param Value Structure */                    OSPM_MALLOC(ospvField->Params[count]->ParamValue,                        OSPTMIMEPART,                        sizeof(OSPTMIMEPART));                    if(ospvField->Params[count]->ParamValue != (OSPTMIMEPART *)NULL)                    {                        OSPM_MEMSET(ospvField->Params[count]->ParamValue,                            0,                            sizeof(OSPTMIMEPART));                        errorcode = OSPPUtilMallocAndCopySubString(ospvField->FieldBody.Content,                             &(ospvField->Params[count])->ParamValue->Content,                             start,                             len);                    }                    else                    {                        errorcode = OSPC_ERR_MIME_MALLOC_FAILED;                        OSPM_DBGERRORLOG(errorcode, "malloc failed for param value structure");                    }                    if(errorcode == OSPC_ERR_NO_ERROR)                    {                        ospvField->Params[count]->ParamValue->Length = len;                        ospvField->NumParams++;                    }                }                count++;            }            if((count == OSPC_MAX_PARAMS) && (currpos != bufend))            {                errorcode = OSPC_ERR_MIME_NO_MORE_SPACE;                OSPM_DBGERRORLOG(errorcode, "no space for this parameter");            }        }    }    OSPM_DBGEXIT(("EXIT : OSPPMimeParamsParse()\n"));    return errorcode;}voidOSPPMimePartFree(    OSPTMIMEPART    *ospvPart){    OSPM_DBGENTER(("ENTER: OSPPMimePartFree()\n"));    if(ospvPart->Content != (unsigned char *)NULL)    {        OSPM_FREE(ospvPart->Content);        ospvPart->Content = OSPC_OSNULL;    }    if(ospvPart != (OSPTMIMEPART *)NULL)    {        OSPM_FREE(ospvPart);        ospvPart = OSPC_OSNULL;    }    OSPM_DBGEXIT(("EXIT : OSPPMimePartFree()\n"));    return;}intOSPPMimeVerifyParameters(    OSPTMIMEFIELD   *ospvContent,    OSPTMIMEPART    *ospvBoundary,    int             ospvHeaderType){    int errorcode = OSPC_ERR_NO_ERROR;    unsigned    pcount = 0;    int         result = 0;    int         pfound = 0;    OSPM_DBGENTER(("ENTER: OSPPMimeVerifyParameters()\n"));    switch(ospvHeaderType)    {        case OSPC_MAIN:        /* verify content-type, protocol, micalg, boundary, length */        /* found content-type, now check type and subtype */        errorcode = OSPPUtilMemCaseCmp(ospvContent->FieldBody.Content,            ospvContent->FieldBody.Length,            "multipart/signed",            strlen("multipart/signed"),            &result);        if((errorcode == OSPC_ERR_NO_ERROR) &&            (result == 0))        {            /* Parse parameters into structure for easier compares */            errorcode = OSPPMimeParamsParse(ospvContent);            if(errorcode == OSPC_ERR_NO_ERROR)            {                pcount = 0;                pfound = 0;                /* check protocol */                while((pcount < ospvContent->NumParams) &&                    (!pfound))                {                    errorcode = OSPPUtilMemCaseCmp( ospvContent->Params[pcount]->ParamName->Content,                        ospvContent->Params[pcount]->ParamName->Length,                        "protocol",                        strlen("protocol"),                        &result);                    if((errorcode == OSPC_ERR_NO_ERROR) &&                        (result == 0))                    {                        pfound = 1;                        break;                    }                    pcount++;                }                if(pfound)                {                    /* copy the protocol string somewhere to save it for SECURITY                       * remember to strip off double quotes                       */                }                else                {                    errorcode = OSPC_ERR_MIME_PROTOCOL_NOT_FOUND;                    OSPM_DBGERRORLOG(errorcode, "protocol parameter not found");                }            }            if(errorcode == OSPC_ERR_NO_ERROR)            {                pcount = 0;                pfound = 0;                /* check micalg */                while((pcount < ospvContent->NumParams) &&                    (!pfound))                {                    errorcode = OSPPUtilMemCaseCmp( ospvContent->Params[pcount]->ParamName->Content,                        ospvContent->Params[pcount]->ParamName->Length,                        "micalg",                        strlen("micalg"),                        &result);                    if((errorcode == OSPC_ERR_NO_ERROR) &&                        (result == 0))                    {                        pfound = 1;                        break;                    }                    pcount++;                }                if(pfound)                {                    /* copy this out to hand up to SECURITY */                }                else                {                    errorcode = OSPC_ERR_MIME_MICALG_NOT_FOUND;                    OSPM_DBGERRORLOG(errorcode, "micalg not found");                }            }            if(errorcode == OSPC_ERR_NO_ERROR)            {                pcount = 0;                pfound = 0;                /* get boundary */                while((pcount < ospvContent->NumParams) &&                    (!pfound))                {                    errorcode = OSPPUtilMemCaseCmp( ospvContent->Params[pcount]->ParamName->Content,                        ospvContent->Params[pcount]->ParamName->Length,                        "boundary",                        strlen("boundary"),                        &result);                    if((errorcode == OSPC_ERR_NO_ERROR) &&                        (result == 0))                    {                        pfound = 1;                        break;                    }                    pcount++;                }                if(pfound)                {                    OSPM_MALLOC(ospvBoundary->Content,                        unsigned char,                        ospvContent->Params[pcount]->ParamValue->Length);                    if(ospvBoundary->Content != (unsigned char *)NULL)                    {                        OSPM_MEMSET(ospvBoundary->Content,                            0,                            ospvContent->Params[pcount]->ParamValue->Length);                        OSPM_MEMCPY(ospvBoundary->Content,                            ospvContent->Params[pcount]->ParamValue->Content,                            ospvContent->Params[pcount]->ParamValue->Length);                        ospvBoundary->Length = ospvContent->Params[pcount]->ParamValue->Length;                    }                    else                    {                        errorcode = OSPC_ERR_MIME_MALLOC_FAILED;                        OSPM_DBGERRORLOG(errorcode, "malloc failed for boundary content");                    }                } /* end if (pfound) */                else                {                    errorcode = OSPC_ERR_MIME_BOUNDARY_NOT_FOUND;                    OSPM_DBGERRORLOG(errorcode, "boundary not found");                }            }            else if(result != 0)            {                errorcode = OSPC_ERR_MIME_INVALID_SUBTYPE;                OSPM_DBGERRORLOG(errorcode, "subtype does not match");            }        }        else        {            errorcode = OSPPUtilMemCaseCmp(ospvContent->FieldBody.Content,                ospvContent->FieldBody.Length,                "text/plain",                strlen("text/plain"),                &result);                        if(errorcode == OSPC_ERR_NO_ERROR)            {                /* Parse parameters into structure for easier compares */                errorcode = OSPPMimeParamsParse(ospvContent);            }        }        break;        case OSPC_BODY:        /* verify content-type, length */        break;        case OSPC_SIGNATURE:        /* verify content-type, length */        break;        default:        errorcode = OSPC_ERR_MIME_INVALID_TYPE;        OSPM_DBGERRORLOG(errorcode, "invalid header type");        break;    }    OSPM_DBGEXIT(("EXIT : OSPPMimeVerifyParameters()\n"));    return errorcode;}intOSPPUtilMallocAndCopySubString(    unsigned char   *ospvSrcString,    unsigned char   **ospvDestString,    unsigned        ospvStartOfSubString,    unsigned        ospvSizeOfSubString){    int errorcode = OSPC_ERR_NO_ERROR;    OSPM_DBGENTER(("ENTER: OSPPUtilMallocAndCopySubString()\n"));    if(&ospvSrcString[ospvStartOfSubString] != (unsigned char *)NULL)    {        OSPM_MALLOC(*ospvDestString,            unsigned char,            ospvSizeOfSubString+1);        if(*ospvDestString != (unsigned char *)NULL)        {            OSPM_MEMSET(*ospvDestString,                0,                ospvSizeOfSubString +1);            OSPM_MEMCPY(*ospvDestString,                &ospvSrcString[ospvStartOfSubString],                ospvSizeOfSubString);        }        else        {            errorcode = OSPC_ERR_UTIL_MALLOC_FAILED;            OSPM_DBGERRORLOG(errorcode, "malloc failed for mallocandcopystring");        }    }    else    {        errorcode = OSPC_ERR_UTIL_VALUE_NOT_FOUND;        OSPM_DBGERRORLOG(errorcode, "no string for mallocandcopystring");    }    OSPM_DBGEXIT(("EXIT : OSPPUtilMallocAndCopySubString()\n"));    return errorcode;}int OSPPUtilMemCaseCmp(    unsigned char   *ospvMem1,     unsigned        ospvLen1,     char            *ospvMem2,    unsigned        ospvLen2,    int             *ospvResult){    int errorcode = OSPC_ERR_NO_ERROR;    unsigned count=0;    unsigned len = OSPM_MIN(ospvLen1, ospvLen2);    int char1 = 0;    int char2 = 0;    OSPM_DBGENTER(("ENTER: OSPPUtilMemCaseCmp()\n"));    *ospvResult = 0;    if((ospvMem1 != (unsigned char *)NULL) &&        (ospvMem2 != (char *)NULL))     {        for (count=0; count < len; ++count)         {            char1 = tolower(ospvMem1[count]);            char2 = tolower(ospvMem2[count]);            if (char1 < char2)             {                *ospvResult = -1;                break;            }            else if (char1 > char2)             {                *ospvResult = 1;                break;            }        } /* end for */    }    else    {        errorcode = OSPC_ERR_MIME_INVALID_ARG;        OSPM_DBGERRORLOG(errorcode, "no data for compare");    }    OSPM_DBGEXIT(("EXIT : OSPPUtilMemCaseCmp()\n"));    return errorcode;}/* End of file */

⌨️ 快捷键说明

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