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

📄 osptnep.c

📁 mgcp协议源代码。支持多种编码:g711
💻 C
📖 第 1 页 / 共 3 页
字号:
                OSPPEnrollUsage( ospvArgv[0], OSPC_ENROLL_HELP_MSG );            }            else            {                OSPPEnrollUsage( OSPC_ENROLL_DEFAULT_CMD, OSPC_ENROLL_HELP_MSG );            }        }    }    OSPM_DBGEXIT(( "EXIT: OSPPEnrollParseParameters\n" ));    return retVal;}/* Given the binary of a BER-encoded certificate, print out its base64 * encoding to STDOUT. We'll need the length of the certificate just as * a convenience for knowing where to stop printing. * * Input: the certificate and its length ( minus the terminating null. )  */int OSPPPrintCert(    unsigned char* ospvCert,    unsigned       ospvCertLen ){    int retVal = OSPC_ERR_NO_ERROR;    /* This is initially the length allocated for encoding the certificate     * to a base64-encoded string, and after that it will be the actual     * length of the base64 encoding of the same string.     */    unsigned certB64Len = 0;    /* The base64-encoded certificate: */    unsigned char* certB64 = OSPC_OSNULL;    OSPM_DBGENTER(( "ENTER: OSPPPrintCert\n" ));    /* If ( the certificate is null or it's empty ) then     *  o warn the user.     */    if ( ( ospvCert == OSPC_OSNULL ) ||          ( ospvCertLen <= 0 ) )    {        retVal = OSPC_ERR_ENROLL_INVALID_ARG;        OSPM_DBGMISC(( "Warning; trying to print a null or empty cert.\n" ));    }    /* wbr: store the binary certificate in localcert_00001.dat */    OSPPSave( "localcert_00001.dat", ospvCert, ospvCertLen );    /* Set the amount of memory for the base64-encoded cert and then      * allocate it. If we have a null pointer, then set an error code     * and print a warning.     */    if ( retVal == OSPC_ERR_NO_ERROR )    {        certB64Len = 2 * ospvCertLen;        OSPM_MALLOC( certB64, unsigned char, certB64Len + 1 );            if ( certB64 == OSPC_OSNULL )         {               retVal = OSPC_ERR_ENROLL_INVALID_ARG;            OSPM_DBGMISC(( "Warning; unable to allocate memory.\n" ));         }    }    /* Now initialize the memory we just allocated and base64-encode the      * certificate. If we have any problems encoding it, then print a      * warning.     */    if ( retVal == OSPC_ERR_NO_ERROR )    {        OSPM_MEMSET( certB64, 0, certB64Len + 1 );            retVal =            OSPPBase64Encode( ospvCert, ospvCertLen, certB64, &certB64Len );        if ( retVal != OSPC_ERR_NO_ERROR )        {            OSPM_DBGMISC(( "Warning: unable to base64 encode cert.\n" ));        }    }        /* Now print out the base64-encoded text, but only if we didn't have     * any problems. Complain if we have problems printing it.     */    if ( retVal == OSPC_ERR_NO_ERROR )    {        retVal = OSPPPrintB64Text( certB64, certB64Len );        if ( retVal != OSPC_ERR_NO_ERROR )        {            OSPM_DBGMISC(( "Warning: unable to print base64 encoded cert.\n" ));        }    }    /* Free up the base64-encoded certificate we created if necessary: */    if ( certB64 != OSPC_OSNULL )    {        OSPM_FREE( certB64 );    }    OSPM_DBGEXIT(( "EXIT: OSPPPrintCert\n" ));    return retVal;}/* Print a block of base64-encoded text, given the text and the length  * to print. We'll separate each line with a newline and a carriage return * so that this function will write truly base64-encoded text. * * Input: the base64-encoded block to be printed and the length of the block. */int OSPPPrintB64Text(    unsigned char* ospvTextBlock,    unsigned       ospvTextBlockLen){    int      retVal             = OSPC_ERR_NO_ERROR;	/* The number of columns to be used per line. This may be something	 * other than a constant ( or we may use termcap or some other 	 * information ), so let's use an lvalue instead of a constant.	 */    unsigned columnsPerLine     = OSPC_ENROLL_B64_COLUMNS_PER_LINE;	/* an offset into the baes64-encoded string that's being printed: */	unsigned printIndex         = 0;	/* This is the temporary variable used for printing out the	 * characters, 64 ( or OSPC_ENROLL_B64_COLUMNS_PER_LINE ) at a time.	 */	unsigned outputText[ OSPC_ENROLL_B64_COLUMNS_PER_LINE + 1 ];    OSPM_DBGENTER(( "ENTER: OSPPPrintB64Text\n" ));	/* Report an error if the input parameters can't be used: */    if ( ( ospvTextBlock == OSPC_OSNULL ) ||         ( ospvTextBlockLen <= 0 ) )    {        retVal = OSPC_ERR_ENROLL_INVALID_ARG;        OSPM_DBGMISC(( "Warning: Bad parameters for printing base64 text\n" ));    }    if ( retVal == OSPC_ERR_NO_ERROR )    {		OSPM_MEMSET( outputText, 0, OSPC_ENROLL_B64_COLUMNS_PER_LINE + 1 );		/* For ( each possible line in the text ) do		 *  o copy the next line into another buffer		 *  o print that buffer in a format that is truly base64-formatted.		 *    That is, print 64 characters per line and print a CRLF at the 		 *    end:		 */        for ( printIndex = 0;               printIndex < ospvTextBlockLen;               printIndex += columnsPerLine )        {            OSPM_STRNCPY( 				outputText, 				ospvTextBlock + printIndex, 				columnsPerLine );            OSPM_PRINTF( "%s\r\n", outputText );        }    }    OSPM_DBGEXIT(( "EXIT: OSPPPrintB64Text\n" ));    return retVal;}/* Given a certificate ( which may be null ), its length ( which may be * less than or equal to zero ), and the status of an enrollment request, * report the enrollment request's status and certificate ( if available ) * to the user. * * Input: the certificate ( in binary ), the cert's length, and the *        status of the request ( as returned from the enrollment server. ) */void OSPPPrintCertAndStatus(    unsigned char* ospvCert,    unsigned       ospvCertLen,    unsigned       ospvEnrollStatus ){    OSPM_DBGENTER(( "ENTER: OSPPPrintCertAndStatus\n" ));    /* Now print out the status of the certificate.     *  o if ( the certificate isn't null and it isn't empty ) then     *      - print the cert.     *  o else     *      - print out an error depending on whether the certificate     *        was null or empty.     */    if ( ospvEnrollStatus == OSPC_ENROLL_STATUS_OK )     {        OSPM_PRINTF( "The certificate request was successful.\n" );        if ( ( ospvCert != OSPC_OSNULL ) &&             ( ospvCertLen > 0 ) )        {            OSPPPrintCert( ospvCert, ospvCertLen );        }        else        {            if ( ospvCert == OSPC_OSNULL )            {                OSPM_PRINTF( "Error: The certificate returned was null.\n" );            }            else if ( ospvCertLen == 0 )            {                OSPM_PRINTF( "Error: An empty certificate was retrieved.\n" );            }            }    }    /* Else     *  o Report that the certificate request is still pending approval:      */    else if ( ospvEnrollStatus == OSPC_ENROLL_STATUS_PENDING )    {        OSPM_PRINTF( "The certificate request is pending approval.\n" );    }    /* Else     *  o report that the certificate request failed and give the reason     *    ( returned from the enrollment server ) why.     */    else    {        OSPM_PRINTF(             "The certificate request failed with the following code: %d\n",             ospvEnrollStatus );    }    OSPM_DBGEXIT(( "EXIT: OSPPPrintCertAndStatus\n" ));    return;}/* Print the usage for the enrollment command. The first string in * is what the user typed in for the command; it may not necessarily * be "enroll". The second string is the help message that the user * receives. The message should explain what the user should enter * in order for the enrollment process to be successful. * * Input: string entered for executing this program. */void OSPPEnrollUsage(     char* ospvCmd,     char* ospvHelpMsg ){    /* Print both of these strings out, but only if they're valid.     * Other logic can be used for how to handle these cases,     * if necessary.     */    if ( ( ospvCmd != OSPC_OSNULL ) &&         ( ospvHelpMsg != OSPC_OSNULL ) )    {        OSPM_PRINTF( "Usage: %s%s", ospvCmd, ospvHelpMsg );    }}/*  wbr: Save the content in the specified file name *  Input: filename  *         content to be saved */void OSPPSave( char* file, char* content, int len){    int count = 0;    FILE *out_file;    OSPM_DBGENTER(( "ENTER: OSPPSave\n" ));    if ( (file == NULL) || (content == NULL) || (len <= 0) )    {        OSPM_PRINTF( "Bad parameter(s) in OSPPSave()\n");        return ;    }    out_file = fopen( file, "w");    if (out_file == NULL)    {        OSPM_PRINTF( "OSPPSave: Failure to open file, %s\n", file );        return ;    }    count = fwrite( content, 1, len, out_file );    OSPM_PRINTF( "OSPPSave: count = %d, len = %d\n", count, len);    fclose( out_file );    OSPM_DBGEXIT(( "EXIT: OSPPSave\n"));}

⌨️ 快捷键说明

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