sdkutils.c 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. * SPDX-License-Identifier: Apache-2.0.
  4. */
  5. #include <aws/sdkutils/private/endpoints_types_impl.h>
  6. #include <aws/sdkutils/sdkutils.h>
  7. /* clang-format off */
  8. static struct aws_error_info s_errors[] = {
  9. AWS_DEFINE_ERROR_INFO(AWS_ERROR_SDKUTILS_GENERAL, "General error in SDK Utility library", "aws-c-sdkutils"),
  10. AWS_DEFINE_ERROR_INFO(AWS_ERROR_SDKUTILS_PARSE_FATAL, "Parser encountered a fatal error", "aws-c-sdkutils"),
  11. AWS_DEFINE_ERROR_INFO(AWS_ERROR_SDKUTILS_PARSE_RECOVERABLE, "Parser encountered an error, but recovered", "aws-c-sdkutils"),
  12. AWS_DEFINE_ERROR_INFO(AWS_ERROR_SDKUTILS_ENDPOINTS_UNSUPPORTED_RULESET, "Ruleset version not supported", "aws-c-sdkutils"),
  13. AWS_DEFINE_ERROR_INFO(AWS_ERROR_SDKUTILS_ENDPOINTS_PARSE_FAILED, "Ruleset parsing failed", "aws-c-sdkutils"),
  14. AWS_DEFINE_ERROR_INFO(AWS_ERROR_SDKUTILS_ENDPOINTS_RESOLVE_INIT_FAILED, "Endpoints eval failed to initialize", "aws-c-sdkutils"),
  15. AWS_DEFINE_ERROR_INFO(AWS_ERROR_SDKUTILS_ENDPOINTS_RESOLVE_FAILED, "Unexpected eval error", "aws-c-sdkutils"),
  16. AWS_DEFINE_ERROR_INFO(AWS_ERROR_SDKUTILS_ENDPOINTS_EMPTY_RULESET, "Ruleset has no rules", "aws-c-sdkutils"),
  17. AWS_DEFINE_ERROR_INFO(AWS_ERROR_SDKUTILS_ENDPOINTS_RULESET_EXHAUSTED, "Ruleset was exhausted before finding a matching rule", "aws-c-sdkutils"),
  18. AWS_DEFINE_ERROR_INFO(AWS_ERROR_SDKUTILS_PARTITIONS_UNSUPPORTED, "Partitions version not supported.", "aws-c-sdkutils"),
  19. AWS_DEFINE_ERROR_INFO(AWS_ERROR_SDKUTILS_PARTITIONS_PARSE_FAILED, "Partitions parsing failed.", "aws-c-sdkutils"),
  20. };
  21. /* clang-format on */
  22. static struct aws_error_info_list s_sdkutils_error_info = {
  23. .error_list = s_errors,
  24. .count = sizeof(s_errors) / sizeof(struct aws_error_info),
  25. };
  26. static struct aws_log_subject_info s_log_subject_infos[] = {
  27. DEFINE_LOG_SUBJECT_INFO(
  28. AWS_LS_SDKUTILS_GENERAL,
  29. "SDKUtils",
  30. "Subject for SDK utility logging that defies categorization."),
  31. DEFINE_LOG_SUBJECT_INFO(AWS_LS_SDKUTILS_PROFILE, "AWSProfile", "Subject for AWS Profile parser and utilities"),
  32. };
  33. static struct aws_log_subject_info_list s_sdkutils_log_subjects = {
  34. .subject_list = s_log_subject_infos,
  35. .count = AWS_ARRAY_SIZE(s_log_subject_infos),
  36. };
  37. static int s_library_init_count = 0;
  38. void aws_sdkutils_library_init(struct aws_allocator *allocator) {
  39. if (s_library_init_count++ != 0) {
  40. return;
  41. }
  42. aws_common_library_init(allocator);
  43. aws_register_error_info(&s_sdkutils_error_info);
  44. aws_register_log_subject_info_list(&s_sdkutils_log_subjects);
  45. aws_endpoints_rule_engine_init();
  46. }
  47. void aws_sdkutils_library_clean_up(void) {
  48. if (--s_library_init_count != 0) {
  49. return;
  50. }
  51. aws_unregister_log_subject_info_list(&s_sdkutils_log_subjects);
  52. aws_unregister_error_info(&s_sdkutils_error_info);
  53. aws_common_library_clean_up();
  54. }