示例#1
0
wi_error_domain_t wi_error_domain(void) {
	wi_error_t		*error;

	error = _wi_error_get_error();

	return error->domain;
}
示例#2
0
wi_integer_t wi_error_code(void) {
	wi_error_t		*error;

	error = _wi_error_get_error();

	return error->code;
}
示例#3
0
文件: wi-error.c 项目: asvitkine/phxd
void wi_error_set_commoncrypto_error(int code) {
	wi_error_t		*error;
	
	error = _wi_error_get_error();
	error->domain = WI_ERROR_DOMAIN_COMMONCRYPTO;
	error->code = code;
	
	wi_release(error->string);

	switch(code) {
		case kCCParamError:
			error->string = wi_retain(WI_STR("Illegal parameter value"));
			break;

		case kCCBufferTooSmall:
			error->string = wi_retain(WI_STR("Insufficent buffer provided for specified operation"));
			break;

		case kCCMemoryFailure:
			error->string = wi_retain(WI_STR("Memory allocation failure"));
			break;

		case kCCAlignmentError:
			error->string = wi_retain(WI_STR("Input size was not aligned properly"));
			break;

		case kCCDecodeError:
			error->string = wi_retain(WI_STR("Input data did not decode or decrypt properly"));
			break;

		case kCCUnimplemented:
			error->string = wi_retain(WI_STR("Function not implemented for the current algorithm"));
			break;
	}
}
示例#4
0
文件: wi-error.c 项目: asvitkine/phxd
void wi_error_set_openssl_ssl_error_with_result(void *ssl, int result) {
	wi_error_t		*error;
	int				code;
	
	code = SSL_get_error(ssl, result);
	
	if(code == SSL_ERROR_SYSCALL) {
		if(ERR_peek_error() == 0) {
			if(result == 0)
				wi_error_set_libwired_error(WI_ERROR_SOCKET_EOF);
			else
				wi_error_set_errno(errno);
		} else {
			wi_error_set_openssl_error();
		}
	}
	else if(code == SSL_ERROR_SSL) {
		wi_error_set_openssl_error();
	} else {
		error = _wi_error_get_error();
		error->domain = WI_ERROR_DOMAIN_OPENSSL_SSL;
		error->code = code;

		wi_release(error->string);

		switch(error->code) {
			case SSL_ERROR_NONE:
				error->string = wi_retain(WI_STR("SSL: No error"));
				break;

			case SSL_ERROR_ZERO_RETURN:
				error->string = wi_retain(WI_STR("SSL: Zero return"));
				break;
				
			case SSL_ERROR_WANT_READ:
				error->string = wi_retain(WI_STR("SSL: Want read"));
				break;
				
			case SSL_ERROR_WANT_WRITE:
				error->string = wi_retain(WI_STR("SSL: Want write"));
				break;
				
			case SSL_ERROR_WANT_CONNECT:
				error->string = wi_retain(WI_STR("SSL: Want connect"));
				break;
				
			case SSL_ERROR_WANT_ACCEPT:
				error->string = wi_retain(WI_STR("SSL: Want accept"));
				break;
				
			case SSL_ERROR_WANT_X509_LOOKUP:
				error->string = wi_retain(WI_STR("SSL: Want X509 lookup"));
				break;
		}
	}
	
	ERR_clear_error();
}
示例#5
0
void wi_error_set_error_with_string(wi_error_domain_t domain, int code, wi_string_t *string) {
	wi_error_t		*error;

	error			= _wi_error_get_error();
	error->domain	= domain;
	error->code		= code;

	wi_release(error->string);
	error->string = wi_retain(string);
}
示例#6
0
void wi_error_set_error(wi_error_domain_t domain, int code) {
	wi_error_t		*error;

	error			= _wi_error_get_error();
	error->domain	= domain;
	error->code		= code;

	wi_release(error->string);
	error->string = NULL;
}
示例#7
0
文件: wi-error.c 项目: asvitkine/phxd
void wi_error_set_regex_error(regex_t *regex, int code) {
	wi_error_t		*error;
	char			string[256];

	error = _wi_error_get_error();
	error->domain = WI_ERROR_DOMAIN_REGEX;
	error->code = code;
	
	regerror(code, regex, string, sizeof(string));

	wi_release(error->string);
	error->string = wi_string_init_with_cstring(wi_string_alloc(), string);
}
示例#8
0
文件: wi-error.c 项目: asvitkine/phxd
void wi_error_set_libxml2_error(void) {
	wi_error_t		*error;
	wi_string_t		*string;
	xmlErrorPtr		xml_error;

	xml_error = xmlGetLastError();

	error = _wi_error_get_error();
	error->domain = WI_ERROR_DOMAIN_REGEX;
	error->code = xml_error->code;
	
	string = wi_string_by_deleting_surrounding_whitespace(wi_string_with_cstring(xml_error->message));
	
	wi_release(error->string);
	error->string = wi_retain(string);
}
示例#9
0
wi_string_t * wi_error_string(void) {
	wi_error_t		*error;

	error = _wi_error_get_error();

	if(!error->string) {
		switch(error->domain) {
			case WI_ERROR_DOMAIN_ERRNO:
				error->string = wi_string_init_with_cstring(wi_string_alloc(), strerror(error->code));
				break;

			case WI_ERROR_DOMAIN_GAI:
				error->string = wi_string_init_with_cstring(wi_string_alloc(), gai_strerror(error->code));
				break;

			case WI_ERROR_DOMAIN_REGEX:
			case WI_ERROR_DOMAIN_OPENSSL:
			case WI_ERROR_DOMAIN_OPENSSL_SSL:
			case WI_ERROR_DOMAIN_COMMONCRYPTO:
			case WI_ERROR_DOMAIN_LIBXML2:
			case WI_ERROR_DOMAIN_SQLITE3:
				break;
			
			case WI_ERROR_DOMAIN_ZLIB:
#ifdef WI_ZLIB
				error->string = wi_string_init_with_format(wi_string_alloc(), WI_STR("zlib: %s"), zError(error->code));
#endif
				break;
			
			case WI_ERROR_DOMAIN_CARBON:
				error->string = wi_string_init_with_format(wi_string_alloc(), WI_STR("Carbon: %d"), error->code);
				break;

			case WI_ERROR_DOMAIN_LIBWIRED:
				error->string = wi_string_init_with_cstring(wi_string_alloc(), _wi_error_strings[error->code]);
				break;

			case WI_ERROR_DOMAIN_NONE:
				error->string = wi_string_init_with_format(wi_string_alloc(), WI_STR("Unknown error domain: %d"), error->code);
				break;
		}
	}

	return error->string;
}
示例#10
0
文件: wi-error.c 项目: asvitkine/phxd
void wi_error_set_libwired_error_with_string(int code, wi_string_t *string) {
	wi_error_t		*error;

	error = _wi_error_get_error();
	error->domain = WI_ERROR_DOMAIN_LIBWIRED;
	error->code = code;
	
	wi_release(error->string);
	
	error->string = wi_string_init_with_cstring(wi_mutable_string_alloc(), _wi_error_strings[error->code]);

	if(wi_string_length(string) > 0) {
		if(wi_string_length(error->string) > 0)
			wi_mutable_string_append_string(error->string, WI_STR(": "));
		
		wi_mutable_string_append_string(error->string, string);
	}
}
示例#11
0
文件: wi-error.c 项目: asvitkine/phxd
void wi_error_set_openssl_error(void) {
	wi_error_t		*error;
	const char		*file;
	int				line;

	if(ERR_peek_error() == 0) {
		wi_error_set_errno(errno);
	} else {
		error = _wi_error_get_error();
		error->domain = WI_ERROR_DOMAIN_OPENSSL;
		error->code = ERR_get_error_line(&file, &line);
		
		wi_release(error->string);

		error->string = wi_string_init_with_format(wi_string_alloc(), WI_STR("%s:%d: %s: %s (%u)"),
			file,
			line,
			ERR_func_error_string(error->code),
			ERR_reason_error_string(error->code),
			ERR_GET_REASON(error->code));
	}
	
	ERR_clear_error();
}