Пример #1
0
wi_boolean_t wi_p7_message_set_number_for_name(wi_p7_message_t *p7_message, wi_number_t *number, wi_string_t *field_name) {
	if(!number)
		number = wi_number_with_int32(0);
	
	if(wi_number_type(number) == WI_NUMBER_BOOL) {
		return wi_p7_message_set_bool_for_name(p7_message, wi_number_bool(number), field_name);
	} else {
		switch(wi_number_storage_type(number)) {
			case WI_NUMBER_STORAGE_INT32:
				return wi_p7_message_set_int32_for_name(p7_message, wi_number_int32(number), field_name);
				break;

			case WI_NUMBER_STORAGE_INT64:
				return wi_p7_message_set_int64_for_name(p7_message, wi_number_int64(number), field_name);
				break;

			case WI_NUMBER_STORAGE_FLOAT:
				return wi_p7_message_set_double_for_name(p7_message, wi_number_float(number), field_name);
				break;

			case WI_NUMBER_STORAGE_DOUBLE:
				return wi_p7_message_set_double_for_name(p7_message, wi_number_double(number), field_name);
				break;
		}
	}
	
	return false;
}
Пример #2
0
void wd_users_remove_user(wd_user_t *user) {
	wd_chats_remove_user(user);
	wd_transfers_remove_user(user);
	
	wi_dictionary_wrlock(wd_users);
	wi_dictionary_remove_data_for_key(wd_users, wi_number_with_int32(wd_user_uid(user)));
	wi_dictionary_unlock(wd_users);
}
Пример #3
0
wd_user_t * wd_users_user_with_uid(wd_uid_t uid) {
	wd_user_t     *user;

	wi_dictionary_rdlock(wd_users);
	user = wi_autorelease(wi_retain(wi_dictionary_data_for_key(wd_users, wi_number_with_int32(uid))));
	wi_dictionary_unlock(wd_users);
	
	return user;
}
Пример #4
0
wd_chat_t * wd_chats_chat_with_cid(wd_cid_t cid) {
	wd_chat_t		*chat;
	
	wi_dictionary_rdlock(wd_chats);
	chat = wi_autorelease(wi_retain(wi_dictionary_data_for_key(wd_chats, wi_number_with_int32(cid))));
	wi_dictionary_unlock(wd_chats);
	
	return chat;
}
Пример #5
0
void wi_test_number(void) {
	WI_TEST_ASSERT_TRUE(wi_number_bool(wi_number_with_bool(true)), "");
	WI_TEST_ASSERT_FALSE(wi_number_bool(wi_number_with_bool(false)), "");
	WI_TEST_ASSERT_EQUALS(wi_number_int32(wi_number_with_int32(2147483647)), 2147483647, "");
	WI_TEST_ASSERT_EQUALS((uint32_t) wi_number_int32(wi_number_with_int32(4294967295U)), 4294967295U, "");
	WI_TEST_ASSERT_EQUALS(wi_number_int64(wi_number_with_int64(9223372036854775807LL)), 9223372036854775807LL, "");
	WI_TEST_ASSERT_EQUALS((uint64_t) wi_number_int64(wi_number_with_int64(18446744073709551615ULL)), 18446744073709551615ULL, "");

#ifdef WI_32
	WI_TEST_ASSERT_EQUALS(wi_number_integer(wi_number_with_integer(2147483647)), 2147483647, "");
	WI_TEST_ASSERT_EQUALS((wi_uinteger_t) wi_number_integer(wi_number_with_integer(4294967295U)), 4294967295U, "");
#else
	WI_TEST_ASSERT_EQUALS(wi_number_integer(wi_number_with_integer(9223372036854775807LL)), 9223372036854775807LL, "");
	WI_TEST_ASSERT_EQUALS((wi_uinteger_t) wi_number_integer(wi_number_with_integer(18446744073709551615ULL)), 18446744073709551615ULL, "");
#endif
	
	WI_TEST_ASSERT_EQUALS_WITH_ACCURACY(wi_number_float(wi_number_with_float(3.40282346e38)), 3.40282346e38F, 0.0001, "");
	WI_TEST_ASSERT_EQUALS_WITH_ACCURACY(wi_number_double(wi_number_with_double(1.7976931348623155e308)), 1.7976931348623155e308, 0.0001, "");
}
Пример #6
0
void wd_users_remove_user(wd_user_t *user) {
	wd_chats_remove_user(user);
	wd_transfers_remove_user(user, false);
	
	wd_user_unsubscribe_paths(user);
	
	wi_dictionary_wrlock(wd_users);
	wi_mutable_dictionary_remove_data_for_key(wd_users, wi_number_with_int32(wd_user_id(user)));
	wi_dictionary_unlock(wd_users);
}
Пример #7
0
void wd_chat_remove_user(wd_chat_t *chat, wd_user_t *user) {
	wi_array_wrlock(chat->users);
	wi_mutable_array_remove_data(chat->users, user);
	wi_array_unlock(chat->users);

	if(chat != wd_public_chat && wi_array_count(chat->users) == 0) {
		wi_dictionary_wrlock(wd_chats);
		wi_mutable_dictionary_remove_data_for_key(wd_chats, wi_number_with_int32(chat->cid));
		wi_dictionary_unlock(wd_chats);
	}
}
Пример #8
0
wi_number_t * wi_p7_message_number_for_name(wi_p7_message_t *p7_message, wi_string_t *field_name) {
	wi_p7_int32_t			p7_int32;
	wi_p7_int64_t			p7_int64;
	wi_p7_double_t			p7_double;
	wi_p7_type_t			type_id;
	uint32_t				field_id;
	
	if(p7_message->serialization == WI_P7_BINARY) {
		field_id = wi_p7_spec_field_id(p7_message->spec, field_name);
		
		if(field_id == WI_P7_SPEC_FIELD_ID_NULL)
			return NULL;
		
		type_id = wi_p7_spec_field_type(p7_message->spec, field_id);
	} else {
		type_id = _wi_p7_message_xml_type_for_name(p7_message, field_name);
	}
	
	switch(type_id) {
		case WI_P7_INT32:
			if(wi_p7_message_get_int32_for_name(p7_message, &p7_int32, field_name))
				return wi_number_with_int32(p7_int32);
			break;
		
		case WI_P7_INT64:
			if(wi_p7_message_get_int64_for_name(p7_message, &p7_int64, field_name))
				return wi_number_with_int64(p7_int64);
			break;
		
		case WI_P7_DOUBLE:
			if(wi_p7_message_get_double_for_name(p7_message, &p7_double, field_name))
				return wi_number_with_double(p7_double);
			break;
		
		default:
			break;
	}
	
	return NULL;
}
Пример #9
0
void wd_users_add_user(wd_user_t *user) {
	wi_dictionary_wrlock(wd_users);
	wi_dictionary_set_data_for_key(wd_users, user, wi_number_with_int32(wd_user_uid(user)));
	wi_dictionary_unlock(wd_users);
}
Пример #10
0
wi_number_t * wi_p7_message_number_for_name(wi_p7_message_t *p7_message, wi_string_t *field_name) {
	wi_p7_spec_field_t		*field;
	wi_p7_spec_type_t		*type;
	wi_p7_boolean_t			p7_bool;
	wi_p7_enum_t			p7_enum;
	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;
	
	field = wi_p7_spec_field_with_name(p7_message->spec, field_name);
	
	if(!field) {
		wi_error_set_libwired_error_with_format(WI_ERROR_P7_UNKNOWNFIELD,
			WI_STR("No id found for field \"%@\""), field_name);
		
		return NULL;
	}
	
	type = wi_p7_spec_field_type(field);
	
	if(!type) {
		wi_error_set_libwired_error_with_format(WI_ERROR_P7_UNKNOWNFIELD,
			WI_STR("No type found for field \"%@\""), field_name);
		
		return NULL;
	}
	
	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))
				return wi_number_with_bool(p7_bool);
			break;
		
		case WI_P7_ENUM:
			if(wi_p7_message_get_enum_for_name(p7_message, &p7_enum, field_name))
				return wi_number_with_int32(p7_enum);
			break;
			
		case WI_P7_INT32:
			if(wi_p7_message_get_int32_for_name(p7_message, &p7_int32, field_name))
				return wi_number_with_int32(p7_int32);
			break;
		
		case WI_P7_UINT32:
			if(wi_p7_message_get_uint32_for_name(p7_message, &p7_uint32, field_name))
				return wi_number_with_int32(p7_uint32);
			break;
		
		case WI_P7_INT64:
			if(wi_p7_message_get_int64_for_name(p7_message, &p7_int64, field_name))
				return wi_number_with_int64(p7_int64);
			break;
		
		case WI_P7_UINT64:
			if(wi_p7_message_get_uint64_for_name(p7_message, &p7_uint64, field_name))
				return wi_number_with_int64(p7_uint64);
			break;
		
		case WI_P7_DOUBLE:
			if(wi_p7_message_get_double_for_name(p7_message, &p7_double, field_name))
				return wi_number_with_double(p7_double);
			break;
		
		default:
			wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDARGUMENT,
				WI_STR("Field \"%@\" is not a number"), field_name);
			break;
	}
	
	return NULL;
}
Пример #11
0
wi_boolean_t wi_p7_message_set_number_for_name(wi_p7_message_t *p7_message, wi_number_t *number, wi_string_t *field_name) {
	wi_p7_spec_field_t		*field;
	wi_p7_spec_type_t		*type;
	
	if(!number)
		number = wi_number_with_int32(0);
	
	field = wi_p7_spec_field_with_name(p7_message->spec, field_name);
	
	if(!field) {
		wi_error_set_libwired_error_with_format(WI_ERROR_P7_UNKNOWNFIELD,
			WI_STR("No id found for field \"%@\""), field_name);
		
		return false;
	}
	
	type = wi_p7_spec_field_type(field);
	
	if(!type) {
		wi_error_set_libwired_error_with_format(WI_ERROR_P7_UNKNOWNFIELD,
			WI_STR("No type found for field \"%@\""), field_name);
		
		return false;
	}
	
	switch(wi_p7_spec_type_id(type)) {
		case WI_P7_BOOL:
			return wi_p7_message_set_bool_for_name(p7_message, wi_number_bool(number), field_name);
			break;
			
		case WI_P7_ENUM:
			return wi_p7_message_set_enum_for_name(p7_message, wi_number_int32(number), field_name);
			break;
			
		case WI_P7_INT32:
			return wi_p7_message_set_int32_for_name(p7_message, wi_number_int32(number), field_name);
			break;
			
		case WI_P7_UINT32:
			return wi_p7_message_set_uint32_for_name(p7_message, wi_number_int32(number), field_name);
			break;
			
		case WI_P7_INT64:
			return wi_p7_message_set_int64_for_name(p7_message, wi_number_int64(number), field_name);
			break;
			
		case WI_P7_UINT64:
			return wi_p7_message_set_uint64_for_name(p7_message, wi_number_int64(number), field_name);
			break;
			
		case WI_P7_DOUBLE:
			return wi_p7_message_set_double_for_name(p7_message, wi_number_double(number), field_name);
			break;
			
		default:
			wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDARGUMENT,
				WI_STR("Field \"%@\" is not a number"), field_name);
			break;
	}

	return false;
}
Пример #12
0
static wi_runtime_instance_t * _wi_config_instance_for_setting(wi_config_t *config, wi_string_t *name, wi_string_t *value, wi_config_type_t *type) {
	struct passwd		*user;
	struct group		*group;
	struct servent		*servent;
	wi_uinteger_t		port;
	uint32_t			uid, gid;
	
	if(!wi_dictionary_contains_key(config->types, name)) {
		wi_error_set_libwired_error(WI_ERROR_SETTINGS_UNKNOWNSETTING);
		
		return NULL;
	}
	
	*type = wi_number_int32(wi_dictionary_data_for_key(config->types, name));
	
	switch(*type) {
		case WI_CONFIG_INTEGER:
			return wi_number_with_integer(wi_string_integer(value));
			break;
			
		case WI_CONFIG_BOOL:
			return wi_number_with_bool(wi_string_bool(value));
			break;
			
		case WI_CONFIG_STRING:
		case WI_CONFIG_STRINGLIST:
		case WI_CONFIG_PATH:
			return value;
			break;
			
		case WI_CONFIG_USER:
			user = getpwnam(wi_string_cstring(value));
			
			if(!user) {
				uid = wi_string_uint32(value);
				
				if(uid != 0 || wi_is_equal(value, WI_STR("0")))
					user = getpwuid(uid);
			}
			
			if(!user) {
				wi_error_set_libwired_error(WI_ERROR_SETTINGS_NOSUCHUSER);
				
				return NULL;
			}
			
			return wi_number_with_int32(user->pw_uid);
			break;
			
		case WI_CONFIG_GROUP:
			group = getgrnam(wi_string_cstring(value));
			
			if(!group) {
				gid = wi_string_uint32(value);
				
				if(gid != 0 || wi_is_equal(value, WI_STR("0")))
					group = getgrgid(gid);
			}
			
			if(!group) {
				wi_error_set_libwired_error(WI_ERROR_SETTINGS_NOSUCHGROUP);
				
				return NULL;
			}
			
			return wi_number_with_int32(group->gr_gid);
			break;
			
		case WI_CONFIG_PORT:
			port = wi_string_uinteger(value);
			
			if(port > 65535) {
				wi_error_set_libwired_error(WI_ERROR_SETTINGS_INVALIDPORT);
				
				return NULL;
			}
			
			if(port == 0) {
				servent = getservbyname(wi_string_cstring(value), "tcp");
				
				if(!servent) {
					wi_error_set_libwired_error(WI_ERROR_SETTINGS_NOSUCHSERVICE);
					
					return NULL;
				}
				
				port = servent->s_port;
			}
			
			return wi_number_with_int32(port);
			break;
			
		case WI_CONFIG_REGEXP:
			return wi_autorelease(wi_regexp_init_with_string(wi_regexp_alloc(), value));
			break;
			
		case WI_CONFIG_TIME_INTERVAL:
			return wi_number_with_double(wi_string_double(value));
			break;
	}
	
	return NULL;
}
Пример #13
0
void wd_chats_add_chat(wd_chat_t *chat) {
	wi_dictionary_wrlock(wd_chats);
	wi_mutable_dictionary_set_data_for_key(wd_chats, chat, wi_number_with_int32(chat->cid));
	wi_dictionary_unlock(wd_chats);
}
Пример #14
0
void wd_chats_add_chat(wd_chat_t *chat) {
	wi_hash_wrlock(wd_chats);
	wi_hash_set_data_for_key(wd_chats, chat, wi_number_with_int32(chat->cid));
	wi_hash_unlock(wd_chats);
}