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

📄 osputils.c

📁 mgcp协议源代码。支持多种编码:g711
💻 C
字号:
/**########################################################################*########################################################################*########################################################################*                                                               *   COPYRIGHT (c) 1998, 1999 by TransNexus, LLC                          *                                                                    *   This software contains proprietary and confidential information  *   of TransNexus, LLC. Except as may be set forth in the license    *   agreement under which this software is supplied, use, disclosure, *   or reproduction is prohibited without the prior, express, written*   consent of TransNexus, LLC.                                      *                                     *******#########################################################################*#########################################################################*#########################################################################*//* * osputils.h - Utility functions. */#include "osp.h"#include "osputils.h"#include "osplist.h"/* Build a string given a uint64 and an int. */intOSPPUtilBuildString(    OSPTUINT64  ospv64,     int         ospvInt,    char        **ospvNumberString    ){    char    returnstring[50];    char    *strptr         = OSPC_OSNULL;    int     errorcode       = OSPC_ERR_NO_ERROR;    OSPM_MEMSET(returnstring, 0, sizeof(returnstring));    /*     * So we don't have to worry about the size of unsigned longs on     * the system, we work backwards.     */        /* First the integer */    strptr = &returnstring[sizeof(returnstring)-2];    do    {        *strptr-- = (char)('0' + (ospvInt%10));        ospvInt = ospvInt/10;    }    while ((ospvInt != 0) && (strptr >= &returnstring[0]));    if (ospvInt != 0)    {        /* error - we ran out of space before completing the number */        errorcode = OSPC_ERR_DATA_BAD_NUMBER;    }    /* Now the uint64 */    do    {        *strptr-- = (char)('0' + (ospv64%10));        ospv64 = ospv64/10;    }    while ((ospv64 != 0) && (strptr >= &returnstring[0]));    if (ospv64 != 0)    {        /* error - we ran out of space before completing the number */        errorcode = OSPC_ERR_DATA_BAD_NUMBER;    }    if(errorcode == OSPC_ERR_NO_ERROR)    {        strptr++; /*get back to beginning of string*/        OSPM_MALLOC(*ospvNumberString, char, OSPM_STRLEN(strptr) + 1);        OSPM_MEMSET(*ospvNumberString, 0, OSPM_STRLEN(strptr) + 1);        OSPM_MEMCPY(*ospvNumberString, strptr, OSPM_STRLEN(strptr));    }    return errorcode;}/* Get the proper errorcode based on the status code returned from   the server.OSPC_ERR_TRAN_CLIENT_ERROR                  (11481)OSPC_ERR_TRAN_BAD_REQUEST                   (11482)OSPC_ERR_TRAN_UNAUTHORIZED                  (11483)OSPC_ERR_TRAN_CHAR_ENC_NOT_SUPD             (11484)OSPC_ERR_TRAN_PARS_UNSUCCESSFUL             (11485)OSPC_ERR_TRAN_UNSUPD_CRIT_ELEM              (11486)OSPC_ERR_TRAN_SECURITY_PROBLEM              (11487)OSPC_ERR_TRAN_SIG_INVALID                   (11488)OSPC_ERR_TRAN_CRYPTO_ALG_NOT_SUPD           (11489)OSPC_ERR_TRAN_CERT_INVALID                  (11490)OSPC_ERR_TRAN_CERT_REVOKED                  (11491)OSPC_ERR_TRAN_ENCRYPTION_REQD               (11492)OSPC_ERR_TRAN_SERVER_ERROR                  (11493)OSPC_ERR_TRAN_INTERNAL_SRVR_ERR             (11494)OSPC_ERR_TRAN_NOT_IMPLEMENTED               (11495)OSPC_ERR_TRAN_SERVICE_NOT_AVAIL             (11496)OSPC_ERR_TRAN_TRANSIENT_SRVR_PROB           (11497)OSPC_ERR_TRAN_LONG_TERM_SRVR_PROB           (11498)OSPC_ERR_TRAN_TIME_PROB                     (11499)OSPC_ERR_TRAN_VALID_TIME_TOO_SOON           (11500)OSPC_ERR_TRAN_TIME_INTERVAL_TOO_SMALL       (11501)OSPC_ERR_TRAN_GENERIC_FAILURE               (11502)*/intOSPPUtilGetErrorFromStatus(    unsigned ospvStatusCode){    int errorcode = OSPC_ERR_NO_ERROR;    if(ospvStatusCode != OSPC_ERR_NO_ERROR)    {        switch(ospvStatusCode)        {        case 400:            errorcode = OSPC_ERR_TRAN_BAD_REQUEST;            break;        case 401:            errorcode = OSPC_ERR_TRAN_UNAUTHORIZED;            break;        case 410:            errorcode = OSPC_ERR_TRAN_CHAR_ENC_NOT_SUPD;            break;        case 411:            errorcode = OSPC_ERR_TRAN_PARS_UNSUCCESSFUL;            break;        case 412:            errorcode = OSPC_ERR_TRAN_UNSUPD_CRIT_ELEM;            break;        case 420:            errorcode = OSPC_ERR_TRAN_SECURITY_PROBLEM;            break;        case 421:            errorcode = OSPC_ERR_TRAN_SIG_INVALID;            break;        case 422:            errorcode = OSPC_ERR_TRAN_CRYPTO_ALG_NOT_SUPD;            break;        case 423:            errorcode = OSPC_ERR_TRAN_CERT_INVALID;            break;        case 424:            errorcode = OSPC_ERR_TRAN_CERT_REVOKED;            break;        case 425:            errorcode = OSPC_ERR_TRAN_ENCRYPTION_REQD;            break;        case 500:            errorcode = OSPC_ERR_TRAN_INTERNAL_SRVR_ERR;            break;        case 501:            errorcode = OSPC_ERR_TRAN_UNIMPLEMENTED;            break;        case 503:            errorcode = OSPC_ERR_TRAN_SERVICE_NOT_AVAIL;            break;        case 510:            errorcode = OSPC_ERR_TRAN_TRANSIENT_SRVR_PROB;            break;        case 520:            errorcode = OSPC_ERR_TRAN_LONG_TERM_SRVR_PROB;            break;        case 530:            errorcode = OSPC_ERR_TRAN_TIME_PROB;            break;        case 531:            errorcode = OSPC_ERR_TRAN_VALID_TIME_TOO_SOON;            break;        case 532:            errorcode = OSPC_ERR_TRAN_TIME_INTERVAL_TOO_SMALL;            break;        case 999:            errorcode = OSPC_ERR_TRAN_GENERIC_FAILURE;            break;        default:            if((ospvStatusCode > 401) && (ospvStatusCode < 500))                errorcode = OSPC_ERR_TRAN_CLIENT_ERROR;            else if((ospvStatusCode > 501) && (ospvStatusCode < 600))                errorcode = OSPC_ERR_TRAN_SERVER_ERROR;            else                errorcode = OSPC_ERR_TRAN_GENERIC_FAILURE;        }    }    return errorcode;}OSPTBOOL    OSPPUtilIsDottedNumericIP(    const char *szStr){    const char *pTmp = szStr;    while (*pTmp)    {        if (*pTmp != '.' && (*pTmp < '0' || *pTmp > '9'))            return OSPC_FALSE;        pTmp++;    }    return OSPC_TRUE;}/* OSPPUtilGetRandom - gets a decimal number string for the random attribute. * ****NOTE**** * Need to get a better way of obtaining a cryptographically strong random number */intOSPPUtilGetRandom(    char *ospvRandom,    int   ospvAddValue){    int             randnum     = 0;    int             numchars    = 0;    unsigned int    seed        = time(NULL) + ospvAddValue;#ifdef _WIN32    srand(seed);    randnum = rand();#else    randnum = rand_r(&seed);#endif    if(randnum > 0)    {        numchars = sprintf(ospvRandom, "%u", (unsigned)randnum);    }    return numchars;}/*  * Converts a string to all lowercase characters */voidOSPPUtilStringToLowercase(    char** ospvString){    int ospvIndex = 0;    if(*ospvString != OSPC_OSNULL)    {        for(ospvIndex=0; ((unsigned int)ospvIndex) < OSPM_STRLEN((const char *)*ospvString); ospvIndex++)        {            *(*ospvString + ospvIndex) = (char)OSPM_TOLOWER((unsigned int)*(*ospvString + ospvIndex));        }    }}

⌨️ 快捷键说明

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