21 #include <rcutils/macros.h>
22 #include <rcutils/snprintf.h>
24 #include "rmw/validate_namespace.h"
26 #include "rcl/error_handling.h"
33 int * validation_result,
34 size_t * invalid_index)
38 enclave, strlen(enclave), validation_result, invalid_index);
44 size_t enclave_length,
45 int * validation_result,
46 size_t * invalid_index)
54 int tmp_validation_result;
55 size_t tmp_invalid_index;
56 rmw_ret_t ret = rmw_validate_namespace_with_size(
57 enclave, enclave_length, &tmp_validation_result, &tmp_invalid_index);
58 if (ret != RMW_RET_OK) {
59 return rcl_convert_rmw_ret_to_rcl_ret(ret);
62 if (tmp_validation_result != RMW_NAMESPACE_VALID &&
63 tmp_validation_result != RMW_NAMESPACE_INVALID_TOO_LONG)
65 switch (tmp_validation_result) {
66 case RMW_NAMESPACE_INVALID_IS_EMPTY_STRING:
69 case RMW_NAMESPACE_INVALID_NOT_ABSOLUTE:
72 case RMW_NAMESPACE_INVALID_ENDS_WITH_FORWARD_SLASH:
75 case RMW_NAMESPACE_INVALID_CONTAINS_UNALLOWED_CHARACTERS:
78 case RMW_NAMESPACE_INVALID_CONTAINS_REPEATED_FORWARD_SLASH:
81 case RMW_NAMESPACE_INVALID_NAME_TOKEN_STARTS_WITH_NUMBER:
86 char default_err_msg[256];
88 int ret = rcutils_snprintf(
89 default_err_msg,
sizeof(default_err_msg),
90 "rcl_validate_enclave_name_with_size(): "
91 "unknown rmw_validate_namespace_with_size() result '%d'",
92 tmp_validation_result);
95 "rcl_validate_enclave_name_with_size(): "
96 "rcutils_snprintf() failed while reporting an unknown validation result");
98 RCL_SET_ERROR_MSG(default_err_msg);
104 *invalid_index = tmp_invalid_index;
110 if (RMW_NAMESPACE_INVALID_TOO_LONG == tmp_validation_result) {
130 switch (validation_result) {
134 return "context name must not be empty";
136 return "context name must be absolute, it must lead with a '/'";
138 return "context name must not end with a '/', unless only a '/'";
140 return "context name must not contain characters other than alphanumerics, '_', or '/'";
142 return "context name must not contain repeated '/'";
144 return "context name must not have a token that starts with a number";
146 return "context name should not exceed '"
147 RCUTILS_STRINGIFY(RCL_ENCLAVE_NAME_MAX_NAME_LENGTH)
"'";
149 return "unknown result code for rcl context name validation";
#define RCL_RET_OK
Success return code.
#define RCL_RET_INVALID_ARGUMENT
Invalid argument return code.
#define RCL_RET_ERROR
Unspecified error return code.
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.
#define RCL_ENCLAVE_NAME_INVALID_NOT_ABSOLUTE
The enclave name is invalid because it is not absolute.
#define RCL_ENCLAVE_NAME_VALID
The enclave name is valid.
#define RCL_ENCLAVE_NAME_INVALID_NAME_TOKEN_STARTS_WITH_NUMBER
The enclave name is invalid because one of the tokens starts with a number.
#define RCL_ENCLAVE_NAME_INVALID_TOO_LONG
The enclave name is invalid because the name is too long.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_validate_enclave_name_with_size(const char *enclave, size_t enclave_length, int *validation_result, size_t *invalid_index)
Deterimine if a given enclave name is valid.
#define RCL_ENCLAVE_NAME_MAX_LENGTH
The maximum length of an enclave name.
#define RCL_ENCLAVE_NAME_INVALID_ENDS_WITH_FORWARD_SLASH
The enclave name is invalid because it ends with a forward slash.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_validate_enclave_name(const char *enclave, int *validation_result, size_t *invalid_index)
Determine if a given enclave name is valid.
#define RCL_ENCLAVE_NAME_INVALID_CONTAINS_UNALLOWED_CHARACTERS
The enclave name is invalid because it has characters that are not allowed.
#define RCL_ENCLAVE_NAME_INVALID_IS_EMPTY_STRING
The enclave name is invalid because it is an empty string.
#define RCL_ENCLAVE_NAME_INVALID_CONTAINS_REPEATED_FORWARD_SLASH
The enclave name is invalid because it contains repeated forward slashes.
RCL_PUBLIC RCL_WARN_UNUSED const char * rcl_enclave_name_validation_result_string(int validation_result)
Return a validation result description, or NULL if unknown or RCL_ENCLAVE_NAME_VALID.