コード例 #1
0
ファイル: wi-set-tests.c プロジェクト: axelandersson/libwired
void wi_test_set_runtime_functions(void) {
    wi_set_t            *set1;
    wi_mutable_set_t    *set2;
    
    set1 = wi_set_with_data(WI_STR("foo"), WI_STR("bar"), NULL);
    set2 = wi_autorelease(wi_mutable_copy(set1));
    
    WI_TEST_ASSERT_EQUAL_INSTANCES(set1, set2, "");
    WI_TEST_ASSERT_EQUALS(wi_hash(set1), wi_hash(set2), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(set1), wi_set_runtime_id(), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(set2), wi_set_runtime_id(), "");
    WI_TEST_ASSERT_TRUE(wi_runtime_options(set1) & WI_RUNTIME_OPTION_IMMUTABLE, "");
    WI_TEST_ASSERT_TRUE(wi_runtime_options(set2) & WI_RUNTIME_OPTION_MUTABLE, "");
    
    wi_mutable_set_remove_data(set2, WI_STR("bar"));
    wi_mutable_set_add_data(set2, WI_STR("baz"));
    
    WI_TEST_ASSERT_NOT_EQUAL_INSTANCES(set1, set2, "");
    
    wi_mutable_set_remove_data(set2, WI_STR("baz"));
    
    WI_TEST_ASSERT_NOT_EQUAL_INSTANCES(set1, set2, "");

    set2 = wi_autorelease(wi_set_init_with_capacity_and_callbacks(wi_mutable_set_alloc(), 0, false, wi_set_null_callbacks));
    
    wi_mutable_set_add_data(set2, (void *) 1);
    wi_mutable_set_add_data(set2, (void *) 2);
    
    WI_TEST_ASSERT_NOT_EQUALS(wi_string_index_of_string(wi_description(set1), WI_STR("foo"), 0), WI_NOT_FOUND, "");
    WI_TEST_ASSERT_NOT_EQUALS(wi_string_index_of_string(wi_description(set2), WI_STR("0x1"), 0), WI_NOT_FOUND, "");
}
コード例 #2
0
void wi_test_regexp_runtime_functions(void) {
    wi_regexp_t   *regexp1, *regexp2;
    
    regexp1 = wi_regexp_with_pattern(WI_STR("foobar"), 0);
    regexp2 = wi_autorelease(wi_copy(regexp1));
    
    WI_TEST_ASSERT_EQUAL_INSTANCES(regexp1, regexp2, "");
    WI_TEST_ASSERT_EQUALS(wi_hash(regexp1), wi_hash(regexp2), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(regexp1), wi_regexp_runtime_id(), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(regexp2), wi_regexp_runtime_id(), "");
    
    WI_TEST_ASSERT_NOT_EQUALS(wi_string_index_of_string(wi_description(regexp1), wi_regexp_pattern(regexp1), 0), WI_NOT_FOUND, "");
}
コード例 #3
0
ファイル: wi-dsa-tests.c プロジェクト: axelandersson/libwired
void wi_test_dsa_runtime_functions(void) {
#ifdef WI_DSA
    wi_dsa_t    *dsa1, *dsa2;
    
    dsa1 = wi_autorelease(wi_dsa_init_with_bits(wi_dsa_alloc(), 512));
    dsa2 = wi_autorelease(wi_copy(dsa1));
    
    WI_TEST_ASSERT_EQUAL_INSTANCES(wi_dsa_private_key(dsa1), wi_dsa_private_key(dsa2), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(dsa1), wi_dsa_runtime_id(), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(dsa2), wi_dsa_runtime_id(), "");
    WI_TEST_ASSERT_NOT_EQUALS(wi_string_index_of_string(wi_description(dsa1), WI_STR("384"), 0), WI_NOT_FOUND, "");
#endif
}
コード例 #4
0
ファイル: wi-plist.c プロジェクト: Patater/libwired
static wi_boolean_t _wi_plist_read_node_to_instance(xmlNodePtr content_node, wi_runtime_instance_t *collection) {
	xmlNodePtr				node;
	wi_string_t				*key = NULL;
	wi_runtime_instance_t	*instance = NULL;
	wi_boolean_t			dictionary;
	
	dictionary = (wi_runtime_id(collection) == wi_dictionary_runtime_id());
	
	for(node = content_node->children; node != NULL; node = node->next) {
		if(node->type == XML_ELEMENT_NODE) {
			if(strcmp((const char *) node->name, "key") == 0)
				key = wi_xml_node_content(node);
			else if(strcmp((const char *) node->name, "string") == 0)
				instance = wi_xml_node_content(node);
			else if(strcmp((const char *) node->name, "integer") == 0)
				instance = wi_number_with_integer(wi_string_integer(wi_xml_node_content(node)));
			else if(strcmp((const char *) node->name, "real") == 0)
				instance = wi_number_with_double(wi_string_double(wi_xml_node_content(node)));
			else if(strcmp((const char *) node->name, "true") == 0)
				instance = wi_number_with_bool(true);
			else if(strcmp((const char *) node->name, "false") == 0)
				instance = wi_number_with_bool(false);
			else if(strcmp((const char *) node->name, "date") == 0)
				instance = wi_date_with_rfc3339_string(wi_xml_node_content(node));
			else if(strcmp((const char *) node->name, "data") == 0)
				instance = wi_data_with_base64(wi_xml_node_content(node));
			else if(strcmp((const char *) node->name, "dict") == 0) {
				instance = wi_mutable_dictionary();
				
				if(!_wi_plist_read_node_to_instance(node, instance))
					return false;
			}
			else if(strcmp((const char *) node->name, "array") == 0) {
				instance = wi_mutable_array();
				
				if(!_wi_plist_read_node_to_instance(node, instance))
					return false;
			}
			else {
				wi_error_set_libwired_error_with_format(WI_ERROR_PLIST_READFAILED,
					WI_STR("Unhandled node \"%s\""), node->name);
				
				return false;
			}
		}
			
		if(instance) {
			if(dictionary)
				wi_mutable_dictionary_set_data_for_key(collection, instance, key);
			else
				wi_mutable_array_add_data(collection, instance);
			
			instance = NULL;
			key = NULL;
		}
	}
	
	return true;
}
コード例 #5
0
ファイル: wi-sqlite3.c プロジェクト: ProfDrLuigi/zanka
static void _wi_sqlite3_bind_statement(wi_sqlite3_statement_t *statement, va_list ap) {
	wi_string_t					*string;
	wi_runtime_instance_t		*instance;
	wi_runtime_id_t				id;
	wi_uinteger_t				index;
	int							result;
	
	index = 1;
	
	while((instance = va_arg(ap, wi_runtime_instance_t *))) {
		id			= wi_runtime_id(instance);
		result		= SQLITE_OK;
		
		if(id == wi_string_runtime_id()) {
			result = sqlite3_bind_text(statement->statement, index, wi_string_cstring(instance), wi_string_length(instance), SQLITE_STATIC);
		}
		else if(id == wi_number_runtime_id()) {
			switch(wi_number_storage_type(instance)) {
				case WI_NUMBER_STORAGE_INT8:
				case WI_NUMBER_STORAGE_INT16:
				case WI_NUMBER_STORAGE_INT32:
				case WI_NUMBER_STORAGE_INT64:
					result = sqlite3_bind_int64(statement->statement, index, wi_number_int64(instance));
					break;
					
				case WI_NUMBER_STORAGE_FLOAT:
				case WI_NUMBER_STORAGE_DOUBLE:
					result = sqlite3_bind_double(statement->statement, index, wi_number_double(instance));
					break;
			}
		}
		else if(id == wi_uuid_runtime_id()) {
			string = wi_uuid_string(instance);
			
			result = sqlite3_bind_text(statement->statement, index, wi_string_cstring(string), wi_string_length(string), SQLITE_STATIC);
		}
		else if(id == wi_date_runtime_id()) {
			string = wi_date_sqlite3_string(instance);
			
			result = sqlite3_bind_text(statement->statement, index, wi_string_cstring(string), wi_string_length(string), SQLITE_STATIC);
		}
		else if(id == wi_null_runtime_id()) {
			result = sqlite3_bind_null(statement->statement, index);
		}
		else if(id == wi_data_runtime_id()) {
			result = sqlite3_bind_blob(statement->statement, index, wi_data_bytes(instance), wi_data_length(instance), SQLITE_STATIC);
		}
		else {
			WI_ASSERT(0, "%@ is not a supported data type", instance);
		}
		
		WI_ASSERT(result == SQLITE_OK, "error %d while binding parameter %u", result, index);
		
		index++;
	}
}
コード例 #6
0
void wi_test_sha2_creation(void) {
#ifdef WI_SHA1
    wi_sha2_t   *sha2;
    
    sha2 = wi_sha2_with_bits(WI_SHA2_256);
    
    WI_TEST_ASSERT_NOT_NULL(sha2, "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(sha2), wi_sha2_runtime_id(), "");
#endif
}
コード例 #7
0
void wi_test_readwrite_lock_runtime_functions(void) {
#ifdef WI_PTHREADS
    wi_readwrite_lock_t     *lock;
    
    lock = wi_autorelease(wi_readwrite_lock_init(wi_readwrite_lock_alloc()));
    
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(lock), wi_readwrite_lock_runtime_id(), "");
    
    WI_TEST_ASSERT_NOT_EQUALS(wi_string_index_of_string(wi_description(lock), WI_STR("wi_readwrite_lock_t"), 0), WI_NOT_FOUND, "");
#endif
}
コード例 #8
0
void wi_test_string_encoding_runtime_functions(void) {
#ifdef WI_STRING_ENCODING
    wi_string_encoding_t    *encoding;

    encoding = wi_string_encoding_with_charset(WI_STR("ASCII"), 0);

    WI_TEST_ASSERT_EQUALS(wi_runtime_id(encoding), wi_string_encoding_runtime_id(), "");

    WI_TEST_ASSERT_NOT_EQUALS(wi_string_index_of_string(wi_description(encoding), WI_STR("ASCII"), 0), WI_NOT_FOUND, "");
#endif
}
コード例 #9
0
void wi_test_indexset_runtime_functions(void) {
    wi_indexset_t           *indexset1;
    wi_mutable_indexset_t   *indexset2;
    
    indexset1 = wi_indexset_with_indexes_in_range(wi_make_range(1, 3));
    indexset2 = wi_autorelease(wi_mutable_copy(indexset1));
    
    WI_TEST_ASSERT_EQUAL_INSTANCES(indexset1, indexset2, "");
    WI_TEST_ASSERT_EQUALS(wi_hash(indexset1), wi_hash(indexset2), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(indexset1), wi_indexset_runtime_id(), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(indexset2), wi_indexset_runtime_id(), "");
    WI_TEST_ASSERT_TRUE(wi_runtime_options(indexset1) & WI_RUNTIME_OPTION_IMMUTABLE, "");
    WI_TEST_ASSERT_TRUE(wi_runtime_options(indexset2) & WI_RUNTIME_OPTION_MUTABLE, "");
    
    wi_mutable_indexset_remove_index(indexset2, 1);
    wi_mutable_indexset_add_index(indexset2, 4);
    
    WI_TEST_ASSERT_NOT_EQUAL_INSTANCES(indexset1, indexset2, "");
    
    WI_TEST_ASSERT_NOT_EQUALS(wi_string_index_of_string(wi_description(indexset2), WI_STR("4"), 0), WI_NOT_FOUND, "");
}
コード例 #10
0
ファイル: wi-runtime-tests.c プロジェクト: Patater/libwired
void wi_test_runtime_info(void) {
	_wi_runtimetest_t		*runtimetest;
	
	WI_TEST_ASSERT_EQUALS(wi_runtime_class_with_name(WI_STR("_wi_runtimetest_t")), &_wi_runtimetest_runtime_class, "");
	WI_TEST_ASSERT_EQUALS(wi_runtime_class_with_id(_wi_runtimetest_runtime_id), &_wi_runtimetest_runtime_class, "");
	
	runtimetest = _wi_runtimetest_init_with_value(_wi_runtimetest_alloc(), 42);
	
	WI_TEST_ASSERT_EQUALS(wi_runtime_id(runtimetest), _wi_runtimetest_runtime_id, "");
	WI_TEST_ASSERT_EQUALS(wi_runtime_class(runtimetest), &_wi_runtimetest_runtime_class, "");
	WI_TEST_ASSERT_EQUAL_INSTANCES(wi_runtime_class_name(runtimetest), wi_string_with_cstring(_wi_runtimetest_runtime_class.name), "");
	
	wi_release(runtimetest);
}
コード例 #11
0
ファイル: wi-dictionary.c プロジェクト: haifenghuang/libwired
wi_dictionary_t * wi_dictionary_init_with_plist_file(wi_dictionary_t *dictionary, wi_string_t *path) {
    wi_runtime_instance_t   *instance;

    wi_release(dictionary);

    instance = wi_plist_read_instance_from_path(path);

    if(!instance)
        return NULL;

    if(wi_runtime_id(instance) != wi_dictionary_runtime_id())
        return NULL;

    return wi_retain(instance);
}
コード例 #12
0
ファイル: wi-array.c プロジェクト: ProfDrLuigi/zanka
wi_array_t * wi_array_init_with_plist_file(wi_array_t *array, wi_string_t *path) {
	wi_runtime_instance_t	*instance;
	
	wi_release(array);
	
	instance = wi_plist_read_instance_from_file(path);
	
	if(!instance)
		return NULL;
	
	if(wi_runtime_id(instance) != wi_array_runtime_id())
		return NULL;
	
	return wi_retain(instance);
}
コード例 #13
0
void wi_test_runtime_info(void) {
    _wi_runtimetest_t   *runtimetest;
    
    WI_TEST_ASSERT_EQUALS(wi_runtime_class_with_name(WI_STR("_wi_runtimetest_t")), &_wi_runtimetest_runtime_class, "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_class_with_id(_wi_runtimetest_runtime_id), &_wi_runtimetest_runtime_class, "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id_for_class(&_wi_runtimetest_runtime_class), _wi_runtimetest_runtime_id, "");
    
    runtimetest = _wi_runtimetest_init_with_value(_wi_runtimetest_alloc(), 42);
    
    WI_TEST_ASSERT_EQUALS(wi_runtime_class(runtimetest), &_wi_runtimetest_runtime_class, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(wi_runtime_class_name(runtimetest), wi_string_with_utf8_string(_wi_runtimetest_runtime_class.name), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(runtimetest), _wi_runtimetest_runtime_id, "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_options(runtimetest), WI_RUNTIME_OPTION_IMMUTABLE, "");
    
    wi_release(runtimetest);
}
コード例 #14
0
void wi_test_runtime_invalid(void) {
    WI_TEST_ASSERT_NULL(wi_runtime_class_with_name(WI_STR("foo")), "");
    WI_TEST_ASSERT_NULL(wi_runtime_class_with_id(1337), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id_for_class(NULL), WI_RUNTIME_ID_NULL, "");
    
    WI_TEST_ASSERT_NULL(wi_runtime_class("foo"), "");
    WI_TEST_ASSERT_NULL(wi_runtime_class_name("foo"), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id("foo"), WI_RUNTIME_ID_NULL, "");

    WI_TEST_ASSERT_NULL(wi_retain(NULL), "");
    WI_TEST_ASSERT_EQUALS(wi_retain_count(NULL), 0U, "");
    WI_TEST_ASSERT_NULL(wi_copy(NULL), "");
    WI_TEST_ASSERT_NULL(wi_mutable_copy(NULL), "");
    WI_TEST_ASSERT_TRUE(wi_is_equal(NULL, NULL), "");
    WI_TEST_ASSERT_FALSE(wi_is_equal(NULL, "foo"), "");
    WI_TEST_ASSERT_FALSE(wi_is_equal(wi_array(), wi_dictionary()), "");
    WI_TEST_ASSERT_NULL(wi_description(NULL), "");
    WI_TEST_ASSERT_EQUALS(wi_hash(NULL), 0U, "");
}
コード例 #15
0
void wi_test_host_runtime_functions(void) {
    wi_host_t   *host1, *host2, *host3, *host4, *host5, *host6;
    
    host1 = wi_host();
    host2 = wi_autorelease(wi_copy(host1));
    host3 = wi_host_with_string(WI_STR("localhost"));
    host4 = wi_autorelease(wi_copy(host3));
    host5 = wi_host_with_string(WI_STR("aab119a592b9e23779b66649677b436d24b35aaa5ad5beadf4c2a945b70577e5.com"));
    host6 = wi_autorelease(wi_copy(host5));
    
    WI_TEST_ASSERT_EQUAL_INSTANCES(host1, host2, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(host3, host4, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(host5, host6, "");
    WI_TEST_ASSERT_NOT_EQUAL_INSTANCES(host1, host3, "");
    WI_TEST_ASSERT_NOT_EQUAL_INSTANCES(host2, host3, "");
    WI_TEST_ASSERT_NOT_EQUAL_INSTANCES(host1, host4, "");
    WI_TEST_ASSERT_NOT_EQUAL_INSTANCES(host2, host4, "");
    WI_TEST_ASSERT_NOT_EQUAL_INSTANCES(host1, host5, "");
    WI_TEST_ASSERT_NOT_EQUAL_INSTANCES(host2, host5, "");
    WI_TEST_ASSERT_NOT_EQUAL_INSTANCES(host1, host6, "");
    WI_TEST_ASSERT_NOT_EQUAL_INSTANCES(host2, host6, "");
    WI_TEST_ASSERT_EQUALS(wi_hash(host1), wi_hash(host2), "");
    WI_TEST_ASSERT_EQUALS(wi_hash(host3), wi_hash(host4), "");
    WI_TEST_ASSERT_EQUALS(wi_hash(host5), wi_hash(host6), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(host1), wi_host_runtime_id(), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(host2), wi_host_runtime_id(), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(host3), wi_host_runtime_id(), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(host4), wi_host_runtime_id(), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(host5), wi_host_runtime_id(), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(host6), wi_host_runtime_id(), "");
    
#ifdef HAVE_GETIFADDRS
    WI_TEST_ASSERT_NOT_EQUALS(wi_string_index_of_string(wi_description(host1), WI_STR("127.0.0.1"), 0), WI_NOT_FOUND, "");
#else
    WI_TEST_ASSERT_NOT_EQUALS(wi_string_index_of_string(wi_description(host1), WI_STR("0.0.0.0"), 0), WI_NOT_FOUND, "");
#endif

    WI_TEST_ASSERT_NOT_EQUALS(wi_string_index_of_string(wi_description(host3), WI_STR("127.0.0.1"), 0), WI_NOT_FOUND, "");
}
コード例 #16
0
ファイル: wi-p7-message.c プロジェクト: ProfDrLuigi/zanka
void wi_p7_message_serialize(wi_p7_message_t *p7_message, wi_p7_serialization_t serialization) {
	xmlDocPtr				doc;
	xmlNsPtr				ns;
	xmlNodePtr				root_node, list_node, item_node;
	wi_p7_spec_field_t		*field;
	wi_p7_spec_type_t		*type;
	wi_runtime_instance_t	*instance;
	wi_string_t				*field_name, *field_value;
	unsigned char			*buffer, *start;
	wi_uuid_t				*uuid;
	wi_date_t				*date;
	wi_p7_boolean_t			p7_bool;
	wi_p7_int32_t			p7_int32;
	wi_p7_uint32_t			p7_uint32;
	wi_p7_int64_t			p7_int64;
	wi_p7_uint64_t			p7_uint64;
	wi_p7_double_t			p7_double;
	wi_p7_oobdata_t			p7_oobdata;
	wi_string_t				*string;
	wi_data_t				*data;
	wi_array_t				*list;
	wi_uinteger_t			i, count;
	uint32_t				message_size, field_id, field_size;
	
	if(serialization == WI_P7_XML && !p7_message->xml_buffer) {
		doc			= xmlNewDoc((xmlChar *) "1.0");
		root_node	= xmlNewNode(NULL, (xmlChar *) "message");
		
		xmlDocSetRootElement(doc, root_node);
		
		ns = xmlNewNs(root_node, (xmlChar *) "http://www.zankasoftware.com/P7/Message", (xmlChar *) "p7");
		xmlSetNs(root_node, ns);
		
		xmlSetProp(root_node, (xmlChar *) "name", (xmlChar *) wi_string_cstring(p7_message->name));
		
		message_size = p7_message->binary_size - WI_P7_MESSAGE_BINARY_HEADER_SIZE;
		buffer = start = p7_message->binary_buffer + WI_P7_MESSAGE_BINARY_HEADER_SIZE;
		
		while((uint32_t) (buffer - start) < message_size) {
			field_id		= wi_read_swap_big_to_host_int32(buffer, 0);
			buffer			+= sizeof(field_id);
			field			= wi_p7_spec_field_with_id(p7_message->spec, field_id);

			if(!field)
				continue;
			
			field_size		= wi_p7_spec_field_size(field);
			
			if(field_size == 0) {
				field_size = wi_read_swap_big_to_host_int32(buffer, 0);
				
				buffer += sizeof(field_size);
			}
			
			field_name		= wi_p7_spec_field_name(field);
			field_value		= NULL;
			type			= wi_p7_spec_field_type(field);

			switch(wi_p7_spec_type_id(type)) {
				case WI_P7_BOOL:
					if(wi_p7_message_get_bool_for_name(p7_message, &p7_bool, field_name))
						field_value = wi_string_with_format(WI_STR("%u"), p7_bool ? 1 : 0);
					break;
					
				case WI_P7_ENUM:
					string = wi_p7_message_enum_name_for_name(p7_message, field_name);
					
					if(string)
						field_value = string;
					break;
					
				case WI_P7_INT32:
					if(wi_p7_message_get_int32_for_name(p7_message, &p7_int32, field_name))
						field_value = wi_string_with_format(WI_STR("%u"), p7_int32);
					break;
					
				case WI_P7_UINT32:
					if(wi_p7_message_get_uint32_for_name(p7_message, &p7_uint32, field_name))
						field_value = wi_string_with_format(WI_STR("%u"), p7_uint32);
					break;
					
				case WI_P7_INT64:
					if(wi_p7_message_get_int64_for_name(p7_message, &p7_int64, field_name))
						field_value = wi_string_with_format(WI_STR("%lld"), p7_int64);
					break;
					
				case WI_P7_UINT64:
					if(wi_p7_message_get_uint64_for_name(p7_message, &p7_uint64, field_name))
						field_value = wi_string_with_format(WI_STR("%llu"), p7_uint64);
					break;
					
				case WI_P7_DOUBLE:
					if(wi_p7_message_get_double_for_name(p7_message, &p7_double, field_name))
						field_value = wi_string_with_format(WI_STR("%f"), p7_double);
					break;
					
				case WI_P7_STRING:
					string = wi_p7_message_string_for_name(p7_message, field_name);
					
					if(string)
						field_value = string;
					break;
					
				case WI_P7_UUID:
					uuid = wi_p7_message_uuid_for_name(p7_message, field_name);
					
					if(uuid)
						field_value = wi_uuid_string(uuid);
					break;
					
				case WI_P7_DATE:
					date = wi_p7_message_date_for_name(p7_message, field_name);
					
					if(date)
						field_value = wi_string_with_format(WI_STR("%f"), wi_date_time_interval(date));
					break;
					
				case WI_P7_DATA:
					data = wi_p7_message_data_for_name(p7_message, field_name);
					
					if(data)
						field_value = wi_data_base64(data);
					break;
					
				case WI_P7_OOBDATA:
					if(wi_p7_message_get_oobdata_for_name(p7_message, &p7_oobdata, field_name))
						field_value = wi_string_with_format(WI_STR("%llu"), p7_oobdata);
					break;
					
				case WI_P7_LIST:
					list = wi_p7_message_list_for_name(p7_message, field_name);
					
					if(list) {
						list_node = wi_xml_node_child_with_name(root_node, field_name);
						
						if(!list_node) {
							list_node = xmlNewNode(ns, (xmlChar *) "field");
							xmlSetProp(list_node, (xmlChar *) "name", (xmlChar *) wi_string_cstring(field_name));
							xmlAddChild(root_node, list_node);
						}
						
						count = wi_array_count(list);
						
						for(i = 0; i < count; i++) {
							item_node = xmlNewNode(ns, (xmlChar *) "item");
							instance = WI_ARRAY(list, i);

							if(wi_runtime_id(instance) == wi_string_runtime_id())
								xmlNodeSetContent(item_node, (xmlChar *) wi_string_cstring(instance));
							
							xmlAddChild(list_node, item_node);
						}
					}
					break;
			}
			
			if(field_value) {
				item_node = wi_xml_node_child_with_name(root_node, field_name);
				
				if(!item_node) {
					item_node = xmlNewNode(ns, (xmlChar *) "field");
					xmlSetProp(item_node, (xmlChar *) "name", (xmlChar *) wi_string_cstring(field_name));
					xmlAddChild(root_node, item_node);
				}
				
				xmlNodeSetContent(item_node, (xmlChar *) wi_string_cstring(field_value));

			}
			
			buffer += field_size;
		}
		
		xmlDocDumpMemoryEnc(doc, &p7_message->xml_buffer, &p7_message->xml_length, "UTF-8");
		xmlFreeDoc(doc);
	}
}
コード例 #17
0
ファイル: wi-p7-message.c プロジェクト: ProfDrLuigi/zanka
wi_boolean_t wi_p7_message_set_list_for_name(wi_p7_message_t *p7_message, wi_array_t *list, wi_string_t *field_name) {
	wi_runtime_instance_t	*instance;
	unsigned char			*binary;
	wi_runtime_id_t			first_id, id;
	wi_uinteger_t			i, count, offset;
	uint32_t				field_id, field_size, string_size;
	
	count = wi_array_count(list);
	field_size = 0;
	
	if(count > 0) {
		first_id = wi_runtime_id(wi_array_first_data(list));
	
		for(i = 0; i < count; i++) {
			instance = WI_ARRAY(list, i);
			id = wi_runtime_id(instance);
			
			if(id != first_id) {
				wi_error_set_libwired_error_with_format(WI_ERROR_P7_UNKNOWNFIELD,
					WI_STR("Mixed types in list"));
				
				return false;
			}
			
			if(id == wi_string_runtime_id()) {
				field_size += 4 + wi_string_length(instance) + 1;
			} else {
				wi_error_set_libwired_error_with_format(WI_ERROR_P7_UNKNOWNFIELD,
					WI_STR("Unhandled type %@ in list"), wi_runtime_class_name(instance));
				
				return false;
			}
		}
	}
	
	if(!_wi_p7_message_get_binary_buffer_for_writing_for_name(p7_message, field_name, field_size, &binary, &field_id))
		return false;
	
	wi_write_swap_host_to_big_int32(binary, 0, field_id);
	wi_write_swap_host_to_big_int32(binary, 4, field_size);
	
	offset = 8;
	
	for(i = 0; i < count; i++) {
		instance = WI_ARRAY(list, i);
		
		if(wi_runtime_id(instance) == wi_string_runtime_id()) {
			string_size = wi_string_length(instance) + 1;
			
			wi_write_swap_host_to_big_int32(binary, offset, string_size);
			
			offset += 4;
			
			memcpy(binary + offset, wi_string_cstring(instance), string_size);
			
			offset += string_size;
		}
	}

	return true;
}
コード例 #18
0
ファイル: wi-plist.c プロジェクト: ProfDrLuigi/zanka
static wi_boolean_t _wi_plist_write_instance_to_node(wi_runtime_instance_t *instance, xmlNodePtr node) {
	wi_enumerator_t			*enumerator;
	wi_array_t				*keys;
	wi_runtime_instance_t	*value;
	xmlNodePtr				child_node;
	void					*key;
	wi_runtime_id_t			id;
	wi_number_type_t		type;
	
	id = wi_runtime_id(instance);
	
	if(id == wi_string_runtime_id()) {
		wi_xml_node_new_child(node, WI_STR("string"), instance);
	}
	else if(id == wi_number_runtime_id()) {
		type = wi_number_type(instance);
		
		if(type == WI_NUMBER_BOOL) {
			if(wi_number_bool(instance))
				wi_xml_node_new_child(node, WI_STR("true"), NULL);
			else
				wi_xml_node_new_child(node, WI_STR("false"), NULL);
		} else {
			if(type == WI_NUMBER_FLOAT || type == WI_NUMBER_DOUBLE)
				wi_xml_node_new_child(node, WI_STR("real"), wi_number_string(instance));
			else
				wi_xml_node_new_child(node, WI_STR("integer"), wi_number_string(instance));
		}
	}
	else if(id == wi_data_runtime_id()) {
		wi_xml_node_new_child(node, WI_STR("data"), wi_data_base64(instance));
	}
	else if(id == wi_date_runtime_id()) {
		wi_xml_node_new_child(node, WI_STR("date"), wi_date_string_with_format(instance, WI_STR("%Y-%m-%dT%H:%M:%SZ")));
	}
	else if(id == wi_dictionary_runtime_id()) {
		child_node = wi_xml_node_new_child(node, WI_STR("dict"), NULL);
		
		keys = wi_dictionary_all_keys(instance);

		wi_array_sort(keys, wi_string_compare);
		
		enumerator = wi_array_data_enumerator(keys);
		
		while((key = wi_enumerator_next_data(enumerator))) {
			value = wi_dictionary_data_for_key(instance, key);
			
			wi_xml_node_new_child(child_node, WI_STR("key"), key);
			
			if(!_wi_plist_write_instance_to_node(value, child_node))
				return false;
		}
	}
	else if(id == wi_array_runtime_id()) {
		child_node = wi_xml_node_new_child(node, WI_STR("array"), NULL);
		
		xmlAddChild(node, child_node);
		
		enumerator = wi_array_data_enumerator(instance);
		
		while((value = wi_enumerator_next_data(enumerator))) {
			if(!_wi_plist_write_instance_to_node(value, child_node))
				return false;
		}
	}
	else {
		wi_error_set_libwired_error_with_format(WI_ERROR_PLIST_WRITEFAILED,
			WI_STR("Unhandled class %@"), wi_runtime_class_name(instance));
		
		return false;
	}
	
	return true;
}
コード例 #19
0
ファイル: wi-config.c プロジェクト: asvitkine/phxd
wi_boolean_t wi_config_read_file(wi_config_t *config) {
	wi_enumerator_t				*enumerator;
	wi_runtime_instance_t		*instance;
	wi_file_t					*file;
	wi_mutable_array_t			*array;
	wi_mutable_dictionary_t		*previous_values;
	wi_string_t					*string, *name, *value;
	wi_config_type_t			type;
	
	file = wi_file_for_reading(config->path);
	
	if(!file) {
		wi_log_err(WI_STR("Could not open %@: %m"),
			config->path);
		
		return false;
	}
	
	wi_log_info(WI_STR("Reading %@"), config->path);
	
	config->line = 0;
	
	wi_lock_lock(config->lock);
	
	previous_values = config->values;
	
	config->values = wi_dictionary_init(wi_mutable_dictionary_alloc());
	
	if(config->defaults) {
		enumerator = wi_dictionary_key_enumerator(config->defaults);
		
		while((name = wi_enumerator_next_data(enumerator))) {
//			instance = wi_mutable_copy(wi_dictionary_data_for_key(config->defaults, name));
			instance = wi_dictionary_data_for_key(config->defaults, name);
			if(wi_runtime_id(instance) == wi_array_runtime_id())
				instance = wi_autorelease(wi_mutable_copy(instance));
			wi_mutable_dictionary_set_data_for_key(config->values, instance, name);
//			wi_release(instance);
		}
	}
	
	while((string = wi_file_read_line(file))) {
		config->line++;

		if(wi_string_length(string) > 0 && !wi_string_has_prefix(string, WI_STR("#"))) {
			if(_wi_config_parse_string(config, string, &name, &value)) {
				instance = _wi_config_instance_for_setting(config, name, value, &type);
				
				if(instance) {
					wi_log_debug(WI_STR("  %@ = %@"), name, value);
					
					if(type == WI_CONFIG_STRINGLIST) {
						array = wi_dictionary_data_for_key(config->values, name);
						
						if(!array) {
							array = wi_mutable_array();
							
							wi_mutable_dictionary_set_data_for_key(config->values, array, name);
						}
						
						wi_mutable_array_add_data(array, instance);
					} else {
						wi_mutable_dictionary_set_data_for_key(config->values, instance, name);
					}
				} else {
					_wi_config_log_error(config, name);
				}
			} else {
				wi_error_set_libwired_error(WI_ERROR_SETTINGS_SYNTAXERROR);
				
				_wi_config_log_error(config, string);
			}
		}
	}
	
	enumerator = wi_dictionary_key_enumerator(config->values);
	
	while((name = wi_enumerator_next_data(enumerator))) {
		instance = wi_dictionary_data_for_key(config->values, name);
		
		if(!previous_values || !wi_is_equal(instance, wi_dictionary_data_for_key(previous_values, name)))
			wi_mutable_set_add_data(config->changes, name);
	}
	
	wi_release(previous_values);

	wi_lock_unlock(config->lock);

	return true;
}