Skip to content

Commit

Permalink
pre-commit: Include re-styled src/coap_[a-g]*.c files to checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdeep1 committed Jul 14, 2023
1 parent c46f9ca commit ba69c79
Show file tree
Hide file tree
Showing 9 changed files with 1,022 additions and 1,151 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ repos:
rev: v0.9.0
hooks:
- id: astyle_py
files: '^(coap_config|man|include|src/oscore|src/coap_oscore|examples|tests).*\.(c|cpp|cxx|h|h.in|h.riot|h.riot.in|h.windows|h.windows.in|h.contiki|hpp|inc)$'
files: '^(coap_config|man|include|src/oscore|src/coap_[a-g]|src/coap_oscore|examples|tests).*\.(c|cpp|cxx|h|h.in|h.riot|h.riot.in|h.windows|h.windows.in|h.contiki|hpp|inc)$'
exclude: '^.*/(coap_uthash_internal.h|coap_utlist_internal.h)$'
args: ['--style=google',
'--align-pointer=name',
Expand Down
87 changes: 51 additions & 36 deletions src/coap_address.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ coap_address_get_port(const coap_address_t *addr) {
assert(addr != NULL);
switch (addr->addr.sa.sa_family) {
#if COAP_IPV4_SUPPORT
case AF_INET: return ntohs(addr->addr.sin.sin_port);
case AF_INET:
return ntohs(addr->addr.sin.sin_port);
#endif /* COAP_IPV4_SUPPORT */
#if COAP_IPV6_SUPPORT
case AF_INET6: return ntohs(addr->addr.sin6.sin6_port);
case AF_INET6:
return ntohs(addr->addr.sin6.sin6_port);
#endif /* COAP_IPV6_SUPPORT */
default: /* undefined */
;
Expand Down Expand Up @@ -71,30 +73,30 @@ coap_address_set_port(coap_address_t *addr, uint16_t port) {

int
coap_address_equals(const coap_address_t *a, const coap_address_t *b) {
assert(a); assert(b);
assert(a);
assert(b);

if (a->size != b->size || a->addr.sa.sa_family != b->addr.sa.sa_family)
return 0;

/* need to compare only relevant parts of sockaddr_in6 */
switch (a->addr.sa.sa_family) {
switch (a->addr.sa.sa_family) {
#if COAP_IPV4_SUPPORT
case AF_INET:
return
a->addr.sin.sin_port == b->addr.sin.sin_port &&
memcmp(&a->addr.sin.sin_addr, &b->addr.sin.sin_addr,
sizeof(struct in_addr)) == 0;
case AF_INET:
return a->addr.sin.sin_port == b->addr.sin.sin_port &&
memcmp(&a->addr.sin.sin_addr, &b->addr.sin.sin_addr,
sizeof(struct in_addr)) == 0;
#endif /* COAP_IPV4_SUPPORT */
#if COAP_IPV6_SUPPORT
case AF_INET6:
return a->addr.sin6.sin6_port == b->addr.sin6.sin6_port &&
memcmp(&a->addr.sin6.sin6_addr, &b->addr.sin6.sin6_addr,
sizeof(struct in6_addr)) == 0;
case AF_INET6:
return a->addr.sin6.sin6_port == b->addr.sin6.sin6_port &&
memcmp(&a->addr.sin6.sin6_addr, &b->addr.sin6.sin6_addr,
sizeof(struct in6_addr)) == 0;
#endif /* COAP_IPV6_SUPPORT */
default: /* fall through and signal error */
;
}
return 0;
default: /* fall through and signal error */
;
}
return 0;
}

int
Expand All @@ -115,7 +117,7 @@ coap_is_mcast(const coap_address_t *a) {
case AF_INET6:
#if COAP_IPV4_SUPPORT
return IN6_IS_ADDR_MULTICAST(&a->addr.sin6.sin6_addr) ||
(IN6_IS_ADDR_V4MAPPED(&a->addr.sin6.sin6_addr) &&
(IN6_IS_ADDR_V4MAPPED(&a->addr.sin6.sin6_addr) &&
IN_MULTICAST(ntohl(a->addr.sin6.sin6_addr.s6_addr[12])));
#else /* ! COAP_IPV4_SUPPORT */
return a->addr.sin6.sin6_addr.s6_addr[0] == 0xff;
Expand Down Expand Up @@ -226,7 +228,8 @@ coap_is_bcast(const coap_address_t *a) {

#endif /* !defined(WITH_CONTIKI) && !defined(WITH_LWIP) */

void coap_address_init(coap_address_t *addr) {
void
coap_address_init(coap_address_t *addr) {
assert(addr);
memset(addr, 0, sizeof(coap_address_t));
#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI)
Expand All @@ -237,7 +240,7 @@ void coap_address_init(coap_address_t *addr) {

int
coap_address_set_unix_domain(coap_address_t *addr,
const uint8_t *host, size_t host_len) {
const uint8_t *host, size_t host_len) {
#if COAP_AF_UNIX_SUPPORT
size_t i;
size_t ofs = 0;
Expand Down Expand Up @@ -330,12 +333,24 @@ coap_get_available_scheme_hint_bits(int have_pki_psk, int ws_check,

switch (use_unix_proto) {
/* For AF_UNIX, can only listen on a single endpoint */
case COAP_PROTO_UDP: scheme_hint_bits = 1 << COAP_URI_SCHEME_COAP; break;
case COAP_PROTO_TCP: scheme_hint_bits = 1 << COAP_URI_SCHEME_COAP_TCP; break;
case COAP_PROTO_DTLS: scheme_hint_bits = 1 << COAP_URI_SCHEME_COAPS; break;
case COAP_PROTO_TLS: scheme_hint_bits = 1 << COAP_URI_SCHEME_COAPS_TCP; break;
case COAP_PROTO_WS: scheme_hint_bits = 1 << COAP_URI_SCHEME_COAP_WS; break;
case COAP_PROTO_WSS: scheme_hint_bits = 1 << COAP_URI_SCHEME_COAPS_WS; break;
case COAP_PROTO_UDP:
scheme_hint_bits = 1 << COAP_URI_SCHEME_COAP;
break;
case COAP_PROTO_TCP:
scheme_hint_bits = 1 << COAP_URI_SCHEME_COAP_TCP;
break;
case COAP_PROTO_DTLS:
scheme_hint_bits = 1 << COAP_URI_SCHEME_COAPS;
break;
case COAP_PROTO_TLS:
scheme_hint_bits = 1 << COAP_URI_SCHEME_COAPS_TCP;
break;
case COAP_PROTO_WS:
scheme_hint_bits = 1 << COAP_URI_SCHEME_COAP_WS;
break;
case COAP_PROTO_WSS:
scheme_hint_bits = 1 << COAP_URI_SCHEME_COAPS_WS;
break;
case COAP_PROTO_NONE: /* If use_unix_proto was not defined */
case COAP_PROTO_LAST:
default:
Expand Down Expand Up @@ -445,7 +460,7 @@ coap_resolve_address_info(const coap_str_const_t *address,
else
memcpy(addrstr, "localhost", 9);

memset ((char *)&hints, 0, sizeof(hints));
memset((char *)&hints, 0, sizeof(hints));
hints.ai_socktype = 0;
hints.ai_family = AF_UNSPEC;
hints.ai_flags = ai_hints_flags;
Expand Down Expand Up @@ -782,12 +797,12 @@ coap_free_address_info(coap_addr_info_t *info) {
void
coap_address_copy(coap_address_t *dst, const coap_address_t *src) {
#if defined(WITH_LWIP) || defined(WITH_CONTIKI)
memcpy( dst, src, sizeof( coap_address_t ) );
memcpy(dst, src, sizeof(coap_address_t));
#else
memset( dst, 0, sizeof( coap_address_t ) );
memset(dst, 0, sizeof(coap_address_t));
dst->size = src->size;
#if COAP_IPV6_SUPPORT
if ( src->addr.sa.sa_family == AF_INET6 ) {
if (src->addr.sa.sa_family == AF_INET6) {
dst->addr.sin6.sin6_family = src->addr.sin6.sin6_family;
dst->addr.sin6.sin6_addr = src->addr.sin6.sin6_addr;
dst->addr.sin6.sin6_port = src->addr.sin6.sin6_port;
Expand All @@ -798,13 +813,13 @@ coap_address_copy(coap_address_t *dst, const coap_address_t *src) {
else
#endif /* COAP_IPV4_SUPPORT && COAP_IPV6_SUPPORT */
#if COAP_IPV4_SUPPORT
if ( src->addr.sa.sa_family == AF_INET ) {
dst->addr.sin = src->addr.sin;
}
if (src->addr.sa.sa_family == AF_INET) {
dst->addr.sin = src->addr.sin;
}
#endif /* COAP_IPV4_SUPPORT */
else {
memcpy( &dst->addr, &src->addr, src->size );
}
else {
memcpy(&dst->addr, &src->addr, src->size);
}
#endif
}

Expand Down
12 changes: 4 additions & 8 deletions src/coap_asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
#include "coap3/coap_internal.h"

size_t
asn1_len(const uint8_t **ptr)
{
asn1_len(const uint8_t **ptr) {
size_t len = 0;

if ((**ptr) & 0x80) {
Expand All @@ -28,17 +27,15 @@ asn1_len(const uint8_t **ptr)
(*ptr)++;
octets--;
}
}
else {
} else {
len = (**ptr) & 0x7f;
(*ptr)++;
}
return len;
}

coap_asn1_tag_t
asn1_tag_c(const uint8_t **ptr, int *constructed, int *cls)
{
asn1_tag_c(const uint8_t **ptr, int *constructed, int *cls) {
coap_asn1_tag_t tag = 0;
uint8_t byte;

Expand Down Expand Up @@ -66,8 +63,7 @@ asn1_tag_c(const uint8_t **ptr, int *constructed, int *cls)
/* caller must free off returned coap_binary_t* */
coap_binary_t *
get_asn1_tag(coap_asn1_tag_t ltag, const uint8_t *ptr, size_t tlen,
asn1_validate validate)
{
asn1_validate validate) {
int constructed;
int class;
const uint8_t *acp = ptr;
Expand Down
24 changes: 11 additions & 13 deletions src/coap_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
if ((out)->field1 == (val1) && (out)->field2 == (val2) && \
((val2) == 0 || memcmp((out)->field3, (val3), (val2)) == 0)) break; \
} \
} while(0)
} while(0)

int
coap_async_is_supported(void) {
Expand Down Expand Up @@ -60,10 +60,9 @@ coap_register_async(coap_session_t *session,
/* Output maybe truncated */
outbuflen = strlen(outbuf);
snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,
"%02x", request->token[i]);
"%02x", request->token[i]);
}
coap_log_debug(
"asynchronous state for token '%s' already registered\n", outbuf);
coap_log_debug("asynchronous state for token '%s' already registered\n", outbuf);
return NULL;
}

Expand All @@ -90,7 +89,7 @@ coap_register_async(coap_session_t *session,
coap_add_data(s->pdu, len, data);
}

s->session = coap_session_reference( session );
s->session = coap_session_reference(session);

coap_async_set_delay(s, delay);

Expand All @@ -103,7 +102,7 @@ coap_async_trigger(coap_async_t *async) {
coap_ticks(&async->delay);

coap_log_debug(" %s: Async request triggered\n",
coap_session_str(async->session));
coap_session_str(async->session));
#ifdef COAP_EPOLL_SUPPORT
coap_update_epoll_timer(async->session->context, 0);
#endif /* COAP_EPOLL_SUPPORT */
Expand All @@ -123,15 +122,14 @@ coap_async_set_delay(coap_async_t *async, coap_tick_t delay) {
coap_update_epoll_timer(async->session->context, delay);
#endif /* COAP_EPOLL_SUPPORT */
coap_log_debug(" %s: Async request delayed for %u.%03u secs\n",
coap_session_str(async->session),
(unsigned int)(delay / COAP_TICKS_PER_SECOND),
(unsigned int)((delay % COAP_TICKS_PER_SECOND) *
1000 / COAP_TICKS_PER_SECOND));
}
else {
coap_session_str(async->session),
(unsigned int)(delay / COAP_TICKS_PER_SECOND),
(unsigned int)((delay % COAP_TICKS_PER_SECOND) *
1000 / COAP_TICKS_PER_SECOND));
} else {
async->delay = 0;
coap_log_debug(" %s: Async request indefinately delayed\n",
coap_session_str(async->session));
coap_session_str(async->session));
}
}

Expand Down
Loading

0 comments on commit ba69c79

Please sign in to comment.