Beispiel #1
0
void config_write( stream_t* stream, hash_t filter_section )
{
	config_section_t* csection;
	config_key_t* bucket;
	int key, ib, bsize;

	stream_set_binary( stream, false );

	//TODO: If random access stream, update section if available, else append at end of stream
	//if( stream_is_sequential( stream ) )
	{
		stream_write_format( stream, "[%s]", hash_to_string( filter_section ) );
		stream_write_endl( stream );

		csection = config_section( filter_section, false );
		if( csection ) for( key = 0; key < CONFIG_KEY_BUCKETS; ++key )
		{
			bucket = csection->key[ key ];
			if( bucket ) for( ib = 0, bsize = array_size( bucket ); ib < bsize; ++ib )
			{
				stream_write_format( stream, "\t%s\t\t\t\t= ", hash_to_string( bucket[ib].name ) );
				switch( bucket[ib].type )
				{
					case CONFIGVALUE_BOOL:
						stream_write_bool( stream, bucket[ib].bval );
						break;

					case CONFIGVALUE_INT:
						stream_write_int64( stream, bucket[ib].ival );
						break;

					case CONFIGVALUE_REAL:
#if FOUNDATION_PLATFORM_REALSIZE == 64
						stream_write_float64( stream, bucket[ib].rval );
#else
						stream_write_float32( stream, bucket[ib].rval );
#endif
						break;

					case CONFIGVALUE_STRING:
					case CONFIGVALUE_STRING_CONST:
					case CONFIGVALUE_STRING_VAR:
					case CONFIGVALUE_STRING_CONST_VAR:
						stream_write_string( stream, bucket[ib].sval );
						break;

					default:
						break;
				}
				stream_write_endl( stream );
			}
		}
	}
}
Beispiel #2
0
DECLARE_TEST(md5, streams) {
	stream_t* test_stream;
	stream_t* unix_stream;
	stream_t* windows_stream;
	uint128_t digest, unix_digest, windows_digest;
	size_t ichunks;

	char unix_buffer[] =
	  "tvqy0C9TO2MI7uyUqr\n\n"
	  "QVcrmjDKDEcB3e7dpM\n\n"
	  "bMpRv6uH0LWPjvNcNp\n"
	  "jpkje9KYXhJjSA2TBy\n"
	  "bTqnOPhOOZ5aWnUdgO\n"
	  "fLapbWSZInasn1SJlk\n"
	  "ytNFKkASDln05zw39X\n"
	  "L8McmojqPmn41Y6CRN\n\n"
	  "wZbKo0PZofDpbAMr1u\n"
	  "u8GJIocbEBFzsyKo62\n"
	  "FlQh1pjm9jBeoEJIHL\n"
	  "v4ixQn77l4M7zbRHgJ\n"
	  "DIVy0vvpNEzxFRyD3Z\n"
	  "5OrJvr\n";

	char windows_buffer[] =
	  "tvqy0C9TO2MI7uyUqr\r\n\r\n"
	  "QVcrmjDKDEcB3e7dpM\r\n\r\n"
	  "bMpRv6uH0LWPjvNcNp\r\n"
	  "jpkje9KYXhJjSA2TBy\r\n"
	  "bTqnOPhOOZ5aWnUdgO\r\n"
	  "fLapbWSZInasn1SJlk\r\n"
	  "ytNFKkASDln05zw39X\r\n"
	  "L8McmojqPmn41Y6CRN\r\n\r\n"
	  "wZbKo0PZofDpbAMr1u\r\n"
	  "u8GJIocbEBFzsyKo62\r\n"
	  "FlQh1pjm9jBeoEJIHL\r\n"
	  "v4ixQn77l4M7zbRHgJ\r\n"
	  "DIVy0vvpNEzxFRyD3Z\r\n"
	  "5OrJvr\r\n";

	test_stream = buffer_stream_allocate(0, STREAM_IN | STREAM_OUT | STREAM_BINARY, 0, 0, true, true);
	stream_write(test_stream, digest_test_string, 2000);

	stream_seek(test_stream, 0, STREAM_SEEK_BEGIN);
	digest = stream_md5(test_stream);
	stream_deallocate(test_stream);

	EXPECT_TRUE(uint128_equal(digest, uint128_make(0x230e0a23943c7d13ULL, 0xd2ccac7ec9df4d0cULL)));

	unix_stream = buffer_stream_allocate((void*)unix_buffer, STREAM_IN, string_length(unix_buffer),
	                                     string_length(unix_buffer), false, false);
	windows_stream = buffer_stream_allocate((void*)windows_buffer, STREAM_IN,
	                                        string_length(windows_buffer), string_length(windows_buffer), false, false);

	stream_set_binary(unix_stream, false);
	stream_set_binary(windows_stream, false);

	unix_digest = stream_md5(unix_stream);
	windows_digest = stream_md5(windows_stream);

	EXPECT_TRUE(uint128_equal(unix_digest, uint128_make(0xcf32b789c7e77197ULL, 0x2bff28c36c601093ULL)));
	EXPECT_TRUE(uint128_equal(unix_digest, windows_digest));

	stream_set_binary(unix_stream, true);
	stream_set_binary(windows_stream, true);

	stream_seek(unix_stream, 0, STREAM_SEEK_BEGIN);
	stream_seek(windows_stream, 0, STREAM_SEEK_BEGIN);

	unix_digest = stream_md5(unix_stream);
	windows_digest = stream_md5(windows_stream);

	stream_deallocate(unix_stream);
	stream_deallocate(windows_stream);

	EXPECT_TRUE(uint128_equal(unix_digest, uint128_make(0xcf32b789c7e77197ULL, 0x2bff28c36c601093ULL)));
	EXPECT_TRUE(uint128_equal(windows_digest, uint128_make(0xf77d63bbe1df9334ULL,
	                                                       0x24d5cb05cd503e44ULL)));
	EXPECT_TRUE(!uint128_equal(unix_digest, windows_digest));

	unix_stream = buffer_stream_allocate(nullptr, STREAM_IN | STREAM_OUT,
	                                     128 * 1024, 128 * 1024, true, true);
	windows_stream = buffer_stream_allocate(nullptr, STREAM_IN | STREAM_OUT,
	                                        128 * 1024, 128 * 1024, true, true);

	ichunks = 0;
	while ((ichunks+1) * 3 < 128 * 1024) {
		stream_write(unix_stream, STRING_CONST("a\n"));
		stream_write(windows_stream, STRING_CONST("a\r\n"));
		++ichunks;
	}

	stream_seek(unix_stream, 0, STREAM_SEEK_BEGIN);
	stream_seek(windows_stream, 0, STREAM_SEEK_BEGIN);

	unix_digest = stream_md5(unix_stream);
	windows_digest = stream_md5(windows_stream);

	stream_deallocate(unix_stream);
	stream_deallocate(windows_stream);

	EXPECT_TRUE(uint128_equal(unix_digest, windows_digest));

	return 0;
}