int GTPublicationsFile_DERDecode(const void *data, size_t data_length,
		GTPublicationsFile **publications_file)
{
	int retval = GT_UNKNOWN_ERROR;
	GTPublicationsFile *tmp_publications_file = NULL;

	if ((data == NULL && data_length != 0) || publications_file == NULL) {
		retval = GT_INVALID_ARGUMENT;
		goto cleanup;
	}

	tmp_publications_file = GT_malloc(sizeof(GTPublicationsFile));
	if (tmp_publications_file == NULL) {
		retval = GT_OUT_OF_MEMORY;
		goto cleanup;
	}

	/* Do not waste time with copying of data until we are sure that input data
	 * is correct. */
	tmp_publications_file->data = data;
	tmp_publications_file->data_length = data_length;
	tmp_publications_file->data_owner = 0;
	tmp_publications_file->publication_cells = NULL;
	tmp_publications_file->key_hash_cells = NULL;
	tmp_publications_file->pub_reference = NULL;
	tmp_publications_file->signature = NULL;

	retval = decodeHeader(tmp_publications_file);
	if (retval != GT_OK) {
		goto cleanup;
	}

	retval = decodePublicationCells(tmp_publications_file);
	if (retval != GT_OK) {
		goto cleanup;
	}

	retval = decodeKeyHashCells(tmp_publications_file);
	if (retval != GT_OK) {
		goto cleanup;
	}

	retval = decodePubReference(tmp_publications_file);
	if (retval != GT_OK) {
		goto cleanup;
	}

	retval = decodeSignature(tmp_publications_file);
	if (retval != GT_OK) {
		goto cleanup;
	}

	retval = GT_UNKNOWN_ERROR;

	tmp_publications_file->data = GT_malloc(data_length);
	if (tmp_publications_file->data == NULL) {
		retval = GT_OUT_OF_MEMORY;
		goto cleanup;
	}

	memcpy((void*) tmp_publications_file->data, data, data_length);
	tmp_publications_file->data_owner = 1;

	*publications_file = tmp_publications_file;
	tmp_publications_file = NULL;

	retval = GT_OK;

cleanup:

	GTPublicationsFile_free(tmp_publications_file);

	return retval;
}
Beispiel #2
0
yuv_buffer* TheoraDecoder::decodeTheora(StampedOggPacket* inPacket) 
{		
    //Accepts packet and deletes it.
    LOG(logDEBUG3) << __FUNCTIONW__;

	if (mPacketCount < 3) 
    {
		decodeHeader(inPacket);		//Accepts header and deletes it.

		if (mPacketCount == 3) 
        {
			mTheoraState = th_decode_alloc(&mTheoraInfo, mTheoraSetup);
			//TODO::: Post processing http://people.xiph.org/~tterribe/doc/libtheora-exp/theoradec_8h.html#a1
		}
		
        LOG(logDEBUG3) << __FUNCTIONW__ << " PacketCount under 3: " << mPacketCount;
		return NULL;
	} 
    else 
    {
		//if (mFirstPacket) 
        //{
		//	theora_decode_init(&mTheoraState, &mTheoraInfo);
		//	mFirstPacket = false;
		//}
		if (inPacket->packetSize() > 0 && (inPacket->packetData()[0] & 128) != 0) 
        {
			//Ignore header packets
			delete inPacket;

            LOG(logDEBUG3) << __FUNCTIONW__ << " Ignoring header packets";
			return NULL;
		}

		ogg_packet* locOldPack = simulateOldOggPacket(inPacket);		//Accepts the packet and deletes it.

		th_decode_packetin(mTheoraState, locOldPack, NULL);

        delete locOldPack->packet;
		delete locOldPack;
		
		th_decode_ycbcr_out(mTheoraState, mYCbCrBuffer);

		//TODO:::
		//This is slightly nasty for now... since changing the return type
		// will screw with other stuff
		//
		//Need to probably use the theora-exp buffer type and change all the
		// uses of yuv_buffer to handle this, and avoid assumptions about
		// the relative size of the Y and U and V buffer

		mYUVBuffer.y_width = mYCbCrBuffer[0].width;
		mYUVBuffer.y_height = mYCbCrBuffer[0].height;
		mYUVBuffer.y_stride = mYCbCrBuffer[0].stride;
		mYUVBuffer.y = mYCbCrBuffer[0].data;
		mYUVBuffer.uv_width = mYCbCrBuffer[1].width;
		mYUVBuffer.uv_height = mYCbCrBuffer[1].height;
		mYUVBuffer.uv_stride = mYCbCrBuffer[1].stride;
		mYUVBuffer.u = mYCbCrBuffer[1].data;
		mYUVBuffer.v = mYCbCrBuffer[2].data;
		
		return &mYUVBuffer;
	}
}
Beispiel #3
0
/*
* carsonl, jan 8,98 
* Decodes a string encoded in RFC2047 format. If the string is not encoded
* returns the original string. Can be used on the header value returned by
* getHeader() and getAllHeaders() methods in MIMEMessage class.
*
* parameter :
*
*	szInputString : string to be trimmed
*
* return : The decoded header string.
*/
char *decodeHeader( char *szInputString )
{
	int len, retLen = 0;
	int i, j, outBytes, outBits;
	int nStart = 0;
	int nEnd = 0;
	char *szEncodedText = NULL;
	char *szDecodedText = NULL;
	char *plainPart = NULL, *retBuf=NULL;
	char *leftOverBuf=NULL, *leftOverDecodedBuf=NULL;
	int  plainTextLen = 0, leftOverLen=0;
	char achCharset[16];
	BOOLEAN bEncodeBase64 = FALSE;
	BOOLEAN bEncodeQP = FALSE;
	BOOLEAN bEncodeString = FALSE;

	if ( szInputString == NULL )
		return NULL;

    len = strlen( szInputString );
    
    /* find start of encoding text */
    for ( i = 0; i < len && szInputString[i] != 0 ; i++ )
    {
    	if ( szInputString[i] == '=' && szInputString[i+1] == '?' )
	{
		bEncodeString = TRUE;
    		break;
	}
    }

    if (bEncodeString == FALSE)
	return (strdup (szInputString));

    if (i > 0)
    {
	plainTextLen = (i);
	plainPart = malloc (i+1);
	strncpy (plainPart, szInputString, plainTextLen);
	plainPart [i] = 0;
    }

    /* get charset */
    for ( i += 2, j = 0; i < len && szInputString[i] != '?' && j < 15; i++, j++ )
    {
    	achCharset[j] = szInputString[i];
    }

    achCharset[j] = 0;
    i++;	/* skip ? */

    /* get encoding type */
    if ( szInputString[i] == 'Q' || szInputString[i] == 'q' )
    	bEncodeQP = TRUE;

    else if ( szInputString[i] == 'B' || szInputString[i] == 'b' )
    	bEncodeBase64 = TRUE;

    if (szInputString[i] == '?' )
    	i++;	/* skip ? */
    nStart = ++i;

    /* look for end of encoded text */
    for ( j = 0; i < len && szInputString[i] != 0; i++, j++ )
    {
    	if ( szInputString[i] == '?' && (i+1) < len && szInputString[i+1] == '=' )
    	{
    		nEnd = i;
    		break;
    	}
    }

    if ( nEnd > 0 )
    {
    	/* extract encoded text */
		szEncodedText = (char *) malloc( j + 1 );
		szDecodedText = (char *) malloc( j + 1 );

		if ( szEncodedText != NULL && szDecodedText != NULL )
		{
    		strncpy( szEncodedText, &szInputString[nStart], j );

			if ( bEncodeQP )
				decodeQP( szEncodedText, szDecodedText, j );

			else if ( bEncodeBase64 )
				decodeBase64( szEncodedText, szDecodedText, j, j, &outBytes, &outBits );

			free( szEncodedText );
		}
    }

    if (nEnd+2 < len-1)
    {
	leftOverLen = len - (nEnd+2);
	leftOverBuf = malloc (leftOverLen + 1);	
    	strncpy (leftOverBuf, &szInputString[nEnd+2], leftOverLen);
	leftOverBuf [leftOverLen] = 0;
	leftOverDecodedBuf = decodeHeader (leftOverBuf);
    }

    retLen = plainTextLen + strlen (szDecodedText) + strlen (leftOverDecodedBuf);
    retBuf = malloc (retLen +1);

    if (plainPart != NULL && szDecodedText != NULL && leftOverDecodedBuf != NULL)
    {
	sprintf (retBuf, "%s%s%s", plainPart, szDecodedText, leftOverDecodedBuf);
	free (plainPart);
	free (szDecodedText);
	free (leftOverBuf);
	free (leftOverDecodedBuf);
    }
    else if (plainPart != NULL && szDecodedText != NULL)
    {
	sprintf (retBuf, "%s%s", plainPart, szDecodedText);
	free (plainPart);
	free (szDecodedText);
    }
    else if (szDecodedText != NULL && leftOverDecodedBuf != NULL)
    {
	sprintf (retBuf, "%s%s", szDecodedText, leftOverDecodedBuf);
	free (szDecodedText);
	free (leftOverBuf);
	free (leftOverDecodedBuf);
    }
    else if (szDecodedText != NULL)
    {
	free (retBuf);
	return szDecodedText;
    }
    else
    {
	free (retBuf);
	return null;
    }

    return retBuf;
    
}