PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/src/common/error/api.cpp

https://gitlab.com/admin-github-cloud/cynara
C++ | 102 lines | 72 code | 9 blank | 21 comment | 6 complexity | eb07664ac4e21ed445e83b159af9e810 MD5 | raw file
  1. /*
  2. * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * @file src/common/error/api.cpp
  18. * @author Aleksander Zdyb <a.zdyb@samsung.com>
  19. * @version 1.0
  20. * @brief Implementation of cynara_strerror
  21. */
  22. #include <cstring>
  23. #include <cynara-error.h>
  24. int cynara_strerror(int errnum, char *buf, size_t buflen) {
  25. if (buf == nullptr)
  26. return CYNARA_API_INVALID_PARAM;
  27. const char *message = nullptr;
  28. switch (errnum) {
  29. case CYNARA_API_ACCESS_NOT_RESOLVED:
  30. message = "Access not resolved";
  31. break;
  32. case CYNARA_API_ACCESS_ALLOWED:
  33. message = "Access granted";
  34. break;
  35. case CYNARA_API_ACCESS_DENIED:
  36. message = "Access denied";
  37. break;
  38. case CYNARA_API_SUCCESS:
  39. message = "Operation successful";
  40. break;
  41. case CYNARA_API_CACHE_MISS:
  42. message = "Value not in cache";
  43. break;
  44. case CYNARA_API_MAX_PENDING_REQUESTS:
  45. message = "Pending requests exceeded maximum";
  46. break;
  47. case CYNARA_API_OUT_OF_MEMORY:
  48. message = "Out of memory";
  49. break;
  50. case CYNARA_API_INVALID_PARAM:
  51. message = "Invalid param";
  52. break;
  53. case CYNARA_API_SERVICE_NOT_AVAILABLE:
  54. message = "Service not available";
  55. break;
  56. case CYNARA_API_METHOD_NOT_SUPPORTED:
  57. message = "Method not supported";
  58. break;
  59. case CYNARA_API_OPERATION_NOT_ALLOWED:
  60. message = "Operation not allowed";
  61. break;
  62. case CYNARA_API_OPERATION_FAILED:
  63. message = "Operation failed";
  64. break;
  65. case CYNARA_API_BUCKET_NOT_FOUND:
  66. message = "Bucket not found";
  67. break;
  68. case CYNARA_API_UNKNOWN_ERROR:
  69. message = "Unknown error";
  70. break;
  71. case CYNARA_API_CONFIGURATION_ERROR:
  72. message = "Configuration error";
  73. break;
  74. case CYNARA_API_INVALID_COMMANDLINE_PARAM:
  75. message = "Invalid parameter in command-line";
  76. break;
  77. case CYNARA_API_BUFFER_TOO_SHORT:
  78. message = "Buffer too short";
  79. break;
  80. case CYNARA_API_DATABASE_CORRUPTED:
  81. message = "Database corrupted";
  82. break;
  83. case CYNARA_API_PERMISSION_DENIED:
  84. message = "Not enough permission to perform action";
  85. break;
  86. }
  87. if (message == nullptr)
  88. return CYNARA_API_INVALID_PARAM;
  89. if (buflen < strlen(message) + 1)
  90. return CYNARA_API_BUFFER_TOO_SHORT;
  91. strcpy(buf, message);
  92. return CYNARA_API_SUCCESS;
  93. }