Function rmw_validate_namespace

Function Documentation

rmw_ret_t rmw_validate_namespace(const char *namespace_, int *validation_result, size_t *invalid_index)

Determine if a given namespace is valid.

Validity of a namespace is based on rules for a topic defined here:

http://design.ros2.org/articles/topic_and_service_names.html

Note that this function expects that there are no URL suffixes as described in the above document which can be used for topics and services.

If either the C string or validation_result pointer are null, then RMW_RET_INVALID_ARGUMENT will be returned. The namespace_ should be a valid, null-terminated C string. The validation_result int pointer should point to valid memory so a result can be stored in it as an output variable. The invalid_index size_t pointer should either point NULL or to valid memory so in the event of a validation error, the location in the input string can be stored therein. If NULL is passed in for invalid_index, it will be not be set.

The invalid_index will not be assigned a value if the namespace is valid.

The int which validation_result points to will have a one of a few possible results values (defined with macros) stored into it:

  • RMW_NAMESPACE_VALID

  • RMW_NAMESPACE_INVALID_IS_EMPTY_STRING

  • RMW_NAMESPACE_INVALID_NOT_ABSOLUTE

  • RMW_NAMESPACE_INVALID_ENDS_WITH_FORWARD_SLASH

  • RMW_NAMESPACE_INVALID_CONTAINS_UNALLOWED_CHARACTERS

  • RMW_NAMESPACE_INVALID_CONTAINS_REPEATED_FORWARD_SLASH

  • RMW_NAMESPACE_INVALID_NAME_TOKEN_STARTS_WITH_NUMBER

  • RMW_NAMESPACE_INVALID_TOO_LONG

The result value can be converted to a description with the rmw_namespace_validation_result_string() function.

The RMW_NAMESPACE_INVALID_ENDS_WITH_FORWARD_SLASH validation result does not apply to "/", which is a valid namespace.

The RMW_NAMESPACE_INVALID_TOO_LONG is guaranteed to be checked last, such that if you get that result, then you can assume all other checks succeeded. This is done so that the length limit can be treated as a warning rather than an error if desired.

If a non RMW_RET_OK return value is returned, the RMW error message will be set

Parameters:
  • namespace_[in] namespace to be validated

  • validation_result[out] int in which the result of the check is stored

  • invalid_index[out] index of the input string where an error occurred

Returns:

RMW_RET_OK on successfully running the check, or

Returns:

RMW_RET_INVALID_ARGUMENT on invalid parameters, or

Returns:

RMW_RET_ERROR when an unspecified error occurs.