SonarCloud: Fix some code smells (missing const qualifiers)

pull/886/head
Brad House 2 months ago
parent 79a4c63062
commit 3c544901b8
  1. 2
      src/lib/ares_process.c
  2. 17
      src/lib/ares_socket.c
  3. 2
      src/lib/ares_update_servers.c
  4. 4
      src/lib/dsa/ares_slist.c
  5. 4
      src/lib/dsa/ares_slist.h
  6. 2
      src/lib/str/ares_buf.c
  7. 39
      src/lib/util/ares_uri.c
  8. 22
      src/lib/util/ares_uri.h

@ -849,7 +849,7 @@ ares_status_t ares_requeue_query(ares_query_t *query, const ares_timeval_t *now,
* consecutive failures). Since they are sorted in priority order, we just
* stop when the consecutive failure count changes. Used for random selection
* of good servers. */
static size_t count_highest_prio_servers(ares_channel_t *channel)
static size_t count_highest_prio_servers(const ares_channel_t *channel)
{
ares_slist_node_t *node;
size_t cnt = 0;

@ -481,19 +481,22 @@ static void set_ipv6_v6only(ares_socket_t sockfd, int on)
ares_conn_err_t ares_socket_enable_tfo(const ares_channel_t *channel,
ares_socket_t fd)
{
#if defined(TFO_CLIENT_SOCKOPT)
int opt = 1;
if (!ares_socket_tfo_supported(channel)) {
return ARES_CONN_ERR_NOTIMP;
}
#if defined(TFO_CLIENT_SOCKOPT)
{
int opt = 1;
if (setsockopt(fd, IPPROTO_TCP, TFO_CLIENT_SOCKOPT, (void *)&opt,
sizeof(opt)) != 0) {
return ARES_CONN_ERR_NOTIMP;
}
if (setsockopt(fd, IPPROTO_TCP, TFO_CLIENT_SOCKOPT, (void *)&opt,
sizeof(opt)) != 0) {
return ARES_CONN_ERR_NOTIMP;
}
#else
if (!ares_socket_tfo_supported(channel)) {
return ARES_CONN_ERR_NOTIMP;
}
(void)fd;
#endif
return ARES_CONN_ERR_SUCCESS;

@ -573,7 +573,7 @@ static unsigned short ares_sconfig_get_port(const ares_channel_t *channel,
return port;
}
static ares_slist_node_t *ares_server_find(ares_channel_t *channel,
static ares_slist_node_t *ares_server_find(const ares_channel_t *channel,
const ares_sconfig_t *s)
{
ares_slist_node_t *node;

@ -435,12 +435,12 @@ ares_slist_t *ares_slist_node_parent(ares_slist_node_t *node)
return node->parent;
}
void *ares_slist_first_val(ares_slist_t *list)
void *ares_slist_first_val(const ares_slist_t *list)
{
return ares_slist_node_val(ares_slist_node_first(list));
}
void *ares_slist_last_val(ares_slist_t *list)
void *ares_slist_last_val(const ares_slist_t *list)
{
return ares_slist_node_val(ares_slist_node_last(list));
}

@ -165,14 +165,14 @@ ares_slist_t *ares_slist_node_parent(ares_slist_node_t *node);
* \param[in] list Initialized SkipList Object
* \return user defined node value or NULL if none
*/
void *ares_slist_first_val(ares_slist_t *list);
void *ares_slist_first_val(const ares_slist_t *list);
/*! Fetch last Node Value in SkipList
*
* \param[in] list Initialized SkipList Object
* \return user defined node value or NULL if none
*/
void *ares_slist_last_val(ares_slist_t *list);
void *ares_slist_last_val(const ares_slist_t *list);
/*! Take back ownership of Node Value in SkipList, remove from SkipList.
*

@ -849,7 +849,7 @@ static ares_bool_t ares_buf_split_isduplicate(ares_array_t *arr,
for (i = 0; i < num; i++) {
ares_buf_t **bufptr = ares_array_at(arr, i);
ares_buf_t *buf = *bufptr;
const ares_buf_t *buf = *bufptr;
size_t plen = 0;
const unsigned char *ptr = ares_buf_peek(buf, &plen);

@ -320,7 +320,7 @@ ares_status_t ares_uri_set_scheme(ares_uri_t *uri, const char *scheme)
return ARES_SUCCESS;
}
const char *ares_uri_get_scheme(ares_uri_t *uri)
const char *ares_uri_get_scheme(const ares_uri_t *uri)
{
if (uri == NULL) {
return NULL;
@ -370,7 +370,7 @@ ares_status_t ares_uri_set_username(ares_uri_t *uri, const char *username)
return status;
}
const char *ares_uri_get_username(ares_uri_t *uri)
const char *ares_uri_get_username(const ares_uri_t *uri)
{
if (uri == NULL) {
return NULL;
@ -418,7 +418,7 @@ ares_status_t ares_uri_set_password(ares_uri_t *uri, const char *password)
return status;
}
const char *ares_uri_get_password(ares_uri_t *uri)
const char *ares_uri_get_password(const ares_uri_t *uri)
{
if (uri == NULL) {
return NULL;
@ -480,7 +480,7 @@ ares_status_t ares_uri_set_host(ares_uri_t *uri, const char *host)
return ARES_SUCCESS;
}
const char *ares_uri_get_host(ares_uri_t *uri)
const char *ares_uri_get_host(const ares_uri_t *uri)
{
if (uri == NULL) {
return NULL;
@ -498,7 +498,7 @@ ares_status_t ares_uri_set_port(ares_uri_t *uri, unsigned short port)
return ARES_SUCCESS;
}
unsigned short ares_uri_get_port(ares_uri_t *uri)
unsigned short ares_uri_get_port(const ares_uri_t *uri)
{
if (uri == NULL) {
return 0;
@ -506,7 +506,6 @@ unsigned short ares_uri_get_port(ares_uri_t *uri)
return uri->port;
}
/* URI spec says path normalization is a requirement */
static char *ares_uri_path_normalize(const char *path)
{
@ -546,7 +545,7 @@ static char *ares_uri_path_normalize(const char *path)
i--;
} else if (ares_streq(str, "..")) {
if (i != 0) {
ares_array_remove_at(arr, (size_t)i-1);
ares_array_remove_at(arr, (size_t)i - 1);
i--;
}
ares_array_remove_at(arr, (size_t)i);
@ -614,7 +613,7 @@ ares_status_t ares_uri_set_path(ares_uri_t *uri, const char *path)
return ARES_SUCCESS;
}
const char *ares_uri_get_path(ares_uri_t *uri)
const char *ares_uri_get_path(const ares_uri_t *uri)
{
if (uri == NULL) {
return NULL;
@ -655,7 +654,7 @@ ares_status_t ares_uri_del_query_key(ares_uri_t *uri, const char *key)
return ARES_SUCCESS;
}
const char *ares_uri_get_query_key(ares_uri_t *uri, const char *key)
const char *ares_uri_get_query_key(const ares_uri_t *uri, const char *key)
{
if (uri == NULL || key == NULL || *key == 0 ||
!ares_str_isprint(key, ares_strlen(key))) {
@ -665,7 +664,7 @@ const char *ares_uri_get_query_key(ares_uri_t *uri, const char *key)
return ares_htable_dict_get_direct(uri->query, key);
}
char **ares_uri_get_query_keys(ares_uri_t *uri, size_t *num)
char **ares_uri_get_query_keys(const ares_uri_t *uri, size_t *num)
{
if (uri == NULL || num == NULL) {
return NULL;
@ -713,7 +712,7 @@ ares_status_t ares_uri_set_fragment(ares_uri_t *uri, const char *fragment)
return status;
}
const char *ares_uri_get_fragment(ares_uri_t *uri)
const char *ares_uri_get_fragment(const ares_uri_t *uri)
{
if (uri == NULL) {
return NULL;
@ -747,7 +746,8 @@ static ares_status_t ares_uri_encode_buf(ares_buf_t *buf, const char *str,
return ARES_SUCCESS;
}
static ares_status_t ares_uri_write_scheme(ares_uri_t *uri, ares_buf_t *buf)
static ares_status_t ares_uri_write_scheme(const ares_uri_t *uri,
ares_buf_t *buf)
{
ares_status_t status;
@ -764,7 +764,8 @@ static ares_status_t ares_uri_write_scheme(ares_uri_t *uri, ares_buf_t *buf)
return status;
}
static ares_status_t ares_uri_write_authority(ares_uri_t *uri, ares_buf_t *buf)
static ares_status_t ares_uri_write_authority(const ares_uri_t *uri,
ares_buf_t *buf)
{
ares_status_t status;
ares_bool_t is_ipv6 = ARES_FALSE;
@ -844,7 +845,7 @@ static ares_status_t ares_uri_write_authority(ares_uri_t *uri, ares_buf_t *buf)
return status;
}
static ares_status_t ares_uri_write_path(ares_uri_t *uri, ares_buf_t *buf)
static ares_status_t ares_uri_write_path(const ares_uri_t *uri, ares_buf_t *buf)
{
ares_status_t status;
@ -867,7 +868,8 @@ static ares_status_t ares_uri_write_path(ares_uri_t *uri, ares_buf_t *buf)
return ARES_SUCCESS;
}
static ares_status_t ares_uri_write_query(ares_uri_t *uri, ares_buf_t *buf)
static ares_status_t ares_uri_write_query(const ares_uri_t *uri,
ares_buf_t *buf)
{
ares_status_t status;
char **keys;
@ -922,7 +924,8 @@ done:
return status;
}
static ares_status_t ares_uri_write_fragment(ares_uri_t *uri, ares_buf_t *buf)
static ares_status_t ares_uri_write_fragment(const ares_uri_t *uri,
ares_buf_t *buf)
{
ares_status_t status;
@ -943,7 +946,7 @@ static ares_status_t ares_uri_write_fragment(ares_uri_t *uri, ares_buf_t *buf)
return ARES_SUCCESS;
}
ares_status_t ares_uri_write_buf(ares_uri_t *uri, ares_buf_t *buf)
ares_status_t ares_uri_write_buf(const ares_uri_t *uri, ares_buf_t *buf)
{
ares_status_t status;
size_t orig_len;
@ -990,7 +993,7 @@ done:
return status;
}
ares_status_t ares_uri_write(char **out, ares_uri_t *uri)
ares_status_t ares_uri_write(char **out, const ares_uri_t *uri)
{
ares_buf_t *buf;
ares_status_t status;

@ -72,7 +72,7 @@ ares_status_t ares_uri_set_scheme(ares_uri_t *uri, const char *scheme);
* \param[in] uri Initialized URI object
* \return string containing URI scheme
*/
const char *ares_uri_get_scheme(ares_uri_t *uri);
const char *ares_uri_get_scheme(const ares_uri_t *uri);
/*! Set the username in the URI object
*
@ -87,7 +87,7 @@ ares_status_t ares_uri_set_username(ares_uri_t *uri, const char *username);
* \param[in] uri Initialized URI object
* \return string containing username, maybe NULL if not set.
*/
const char *ares_uri_get_username(ares_uri_t *uri);
const char *ares_uri_get_username(const ares_uri_t *uri);
/*! Set the password in the URI object
*
@ -102,7 +102,7 @@ ares_status_t ares_uri_set_password(ares_uri_t *uri, const char *password);
* \param[in] uri Initialized URI object
* \return string containing password, maybe NULL if not set.
*/
const char *ares_uri_get_password(ares_uri_t *uri);
const char *ares_uri_get_password(const ares_uri_t *uri);
/*! Set the host or ip address in the URI object. This is required to be
* set to write a URI. The character set is strictly validated.
@ -119,7 +119,7 @@ ares_status_t ares_uri_set_host(ares_uri_t *uri, const char *host);
* \param[in] uri Initialized URI object
* \return string containing host, maybe NULL if not set.
*/
const char *ares_uri_get_host(ares_uri_t *uri);
const char *ares_uri_get_host(const ares_uri_t *uri);
/*! Set the port to use in the URI object. A port value of 0 will omit
* the port from the URI when written, thus using the scheme's default.
@ -135,7 +135,7 @@ ares_status_t ares_uri_set_port(ares_uri_t *uri, unsigned short port);
* \param[in] uri Initialized URI object
* \return port number, or 0 if not set.
*/
unsigned short ares_uri_get_port(ares_uri_t *uri);
unsigned short ares_uri_get_port(const ares_uri_t *uri);
/*! Set the path in the URI object. Unsupported characters will be URI-encoded
* when written.
@ -152,7 +152,7 @@ ares_status_t ares_uri_set_path(ares_uri_t *uri, const char *path);
* \param[in] uri Initialized URI object
* \return path string, or NULL if not set.
*/
const char *ares_uri_get_path(ares_uri_t *uri);
const char *ares_uri_get_path(const ares_uri_t *uri);
/*! Set a new query key/value pair. There is no set order for query keys
* when output in the URI, they will be emitted in a random order. Keys are
@ -183,7 +183,7 @@ ares_status_t ares_uri_del_query_key(ares_uri_t *uri, const char *key);
* NULL value set. There is currently no way to indicate the
* difference.
*/
const char *ares_uri_get_query_key(ares_uri_t *uri, const char *key);
const char *ares_uri_get_query_key(const ares_uri_t *uri, const char *key);
/*! Retrieve a complete list of query keys.
*
@ -192,7 +192,7 @@ const char *ares_uri_get_query_key(ares_uri_t *uri, const char *key);
* \return NULL on failure or no keys. Use
* ares_free_array(keys, num, ares_free) when done with array.
*/
char **ares_uri_get_query_keys(ares_uri_t *uri, size_t *num);
char **ares_uri_get_query_keys(const ares_uri_t *uri, size_t *num);
/*! Set the fragment in the URI object. Unsupported characters will be
* URI-encoded when written.
@ -209,7 +209,7 @@ ares_status_t ares_uri_set_fragment(ares_uri_t *uri, const char *fragment);
* \param[in] uri Initialized URI object
* \return fragment string, or NULL if not set.
*/
const char *ares_uri_get_fragment(ares_uri_t *uri);
const char *ares_uri_get_fragment(const ares_uri_t *uri);
/*! Parse the provided URI buffer into a new URI object.
*
@ -236,7 +236,7 @@ ares_status_t ares_uri_parse(ares_uri_t **out, const char *uri);
* \param[in] uri Initialized URI object.
* \return ARES_SUCCESS on successful write.
*/
ares_status_t ares_uri_write(char **out, ares_uri_t *uri);
ares_status_t ares_uri_write(char **out, const ares_uri_t *uri);
/*! Write URI object to an existing ares_buf_t object. Requires at least the
* scheme and host to be set for this to succeed.
@ -245,7 +245,7 @@ ares_status_t ares_uri_write(char **out, ares_uri_t *uri);
* \param[in,out] buf Destination buf object.
* \return ARES_SUCCESS on successful write.
*/
ares_status_t ares_uri_write_buf(ares_uri_t *uri, ares_buf_t *buf);
ares_status_t ares_uri_write_buf(const ares_uri_t *uri, ares_buf_t *buf);
/*! @} */

Loading…
Cancel
Save