Skip to content

Commit

Permalink
man: Format examples as per CONTRIBUTION guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdeep1 committed Apr 25, 2024
1 parent 749e16f commit ae438cb
Show file tree
Hide file tree
Showing 16 changed files with 235 additions and 262 deletions.
16 changes: 8 additions & 8 deletions man/coap_address.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,14 @@ static int
get_address(coap_uri_t *uri, coap_address_t *dst) {
coap_addr_info_t *info_list;

info_list = coap_resolve_address_info(&uri->host, uri->port, uri->port,
uri->port, uri->port,0,
1 << uri->scheme, COAP_RESOLVE_TYPE_LOCAL);
if (info_list == NULL)
return 0;
memcpy(dst, &info_list->addr, sizeof(*dst));
coap_free_address_info(info_list);
return 1;
info_list = coap_resolve_address_info(&uri->host, uri->port, uri->port,
uri->port, uri->port,0,
1 << uri->scheme, COAP_RESOLVE_TYPE_LOCAL);
if (info_list == NULL)
return 0;
memcpy(dst, &info_list->addr, sizeof(*dst));
coap_free_address_info(info_list);
return 1;
}
----

Expand Down
9 changes: 4 additions & 5 deletions man/coap_async.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ EXAMPLES
*/
static void
hnd_get_with_delay(coap_session_t *session,
coap_resource_t *resource,
coap_pdu_t *request,
coap_string_t *query,
coap_pdu_t *response) {
coap_resource_t *resource,
coap_pdu_t *request,
coap_string_t *query,
coap_pdu_t *response) {
unsigned long delay = 5;
size_t size;
coap_async_t *async;
Expand Down Expand Up @@ -204,7 +204,6 @@ hnd_get_with_delay(coap_session_t *session,

/* async is automatically removed by libcoap on return from this handler */
}

----

SEE ALSO
Expand Down
27 changes: 13 additions & 14 deletions man/coap_block.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,9 @@ EXAMPLES

static int
build_send_pdu(coap_context_t *context, coap_session_t *session,
uint8_t msgtype, uint8_t request_code, const char *uri, const char *query,
unsigned char *data, size_t length, int observe) {

uint8_t msgtype, uint8_t request_code, const char *uri,
const char *query, unsigned char *data, size_t length,
int observe) {
coap_pdu_t *pdu;
uint8_t buf[1024];
size_t buflen;
Expand Down Expand Up @@ -372,11 +372,11 @@ unsigned char *data, size_t length, int observe) {
if (uri) {
/* Add in the URI options */
buflen = sizeof(buf);
res = coap_split_path((const uint8_t*)uri, strlen(uri), sbuf, &buflen);
res = coap_split_path((const uint8_t *)uri, strlen(uri), sbuf, &buflen);
while (res--) {
if (!coap_insert_optlist(&optlist_chain,
coap_new_optlist(COAP_OPTION_URI_PATH,
coap_opt_length(sbuf), coap_opt_value(sbuf))))
coap_opt_length(sbuf), coap_opt_value(sbuf))))
goto error;
sbuf += coap_opt_size(sbuf);
}
Expand All @@ -385,11 +385,11 @@ unsigned char *data, size_t length, int observe) {
if (query) {
/* Add in the QUERY options */
buflen = sizeof(buf);
res = coap_split_query((const uint8_t*)query, strlen(query), sbuf, &buflen);
res = coap_split_query((const uint8_t *)query, strlen(query), sbuf, &buflen);
while (res--) {
if (!coap_insert_optlist(&optlist_chain,
coap_new_optlist(COAP_OPTION_URI_QUERY,
coap_opt_length(sbuf), coap_opt_value(sbuf))))
coap_opt_length(sbuf), coap_opt_value(sbuf))))
goto error;
sbuf += coap_opt_size(sbuf);
}
Expand All @@ -399,9 +399,9 @@ unsigned char *data, size_t length, int observe) {
/* Indicate that we want to observe this resource */
if (!coap_insert_optlist(&optlist_chain,
coap_new_optlist(COAP_OPTION_OBSERVE,
coap_encode_var_safe(buf, sizeof(buf),
COAP_OBSERVE_ESTABLISH), buf)
))
coap_encode_var_safe(buf, sizeof(buf),
COAP_OBSERVE_ESTABLISH), buf)
))
goto error;
}

Expand Down Expand Up @@ -472,8 +472,8 @@ main(int argc, char *argv[]) {

static void
hnd_get_time(coap_resource_t *resource, coap_session_t *session,
const coap_pdu_t *request, const coap_string_t *query, coap_pdu_t *response) {

const coap_pdu_t *request, const coap_string_t *query,
coap_pdu_t *response) {
unsigned char buf[40];
size_t len;
time_t now;
Expand All @@ -487,8 +487,7 @@ const coap_pdu_t *request, const coap_string_t *query, coap_pdu_t *response) {
if (query != NULL && coap_string_equal(query, coap_make_str_const("secs"))) {
/* Output secs since Jan 1 1970 */
len = snprintf((char *)buf, sizeof(buf), "%lu", now);
}
else {
} else {
/* Output human-readable time */
struct tm *tmp;
tmp = gmtime(&now);
Expand Down
57 changes: 26 additions & 31 deletions man/coap_cache.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ static int example_data_media_type = COAP_MEDIATYPE_TEXT_PLAIN;

static void
cache_free_app_data(void *data) {
coap_binary_t *bdata = (coap_binary_t*)data;
coap_binary_t *bdata = (coap_binary_t *)data;
coap_delete_binary(bdata);
}

Expand All @@ -255,13 +255,12 @@ cache_free_app_data(void *data) {

static void
hnd_put_example_data(coap_context_t *ctx,
coap_resource_t *resource,
coap_session_t *session,
coap_pdu_t *request,
coap_binary_t *token,
coap_string_t *query,
coap_pdu_t *response
) {
coap_resource_t *resource,
coap_session_t *session,
coap_pdu_t *request,
coap_binary_t *token,
coap_string_t *query,
coap_pdu_t *response) {
size_t size;
const uint8_t *data;
coap_opt_iterator_t opt_iter;
Expand All @@ -276,7 +275,7 @@ hnd_put_example_data(coap_context_t *ctx,
(void)query;

if (coap_get_data_large(request, &size, &data, &offset, &total) &&
size != total) {
size != total) {
/*
* A part of the data has been received (COAP_BLOCK_SINGLE_BODY not set).
* However, total unfortunately is only an indication, so it is not safe to
Expand All @@ -291,7 +290,7 @@ hnd_put_example_data(coap_context_t *ctx,
*/
coap_cache_entry_t *cache_entry = coap_cache_get_by_pdu(session,
request,
COAP_CACHE_IS_SESSION_BASED);
COAP_CACHE_IS_SESSION_BASED);

if (offset == 0) {
if (!cache_entry) {
Expand All @@ -301,10 +300,9 @@ hnd_put_example_data(coap_context_t *ctx,
* the session is deleted as session_based is set here.
*/
cache_entry = coap_new_cache_entry(session, request,
COAP_CACHE_NOT_RECORD_PDU,
COAP_CACHE_IS_SESSION_BASED, 0);
}
else {
COAP_CACHE_NOT_RECORD_PDU,
COAP_CACHE_IS_SESSION_BASED, 0);
} else {
data_so_far = coap_cache_get_app_data(cache_entry);
if (data_so_far) {
coap_delete_binary(data_so_far);
Expand All @@ -316,10 +314,9 @@ hnd_put_example_data(coap_context_t *ctx,
if (!cache_entry) {
if (offset == 0) {
coap_log_warn("Unable to create a new cache entry\n");
}
else {
} else {
coap_log_warn(
"No cache entry available for the non-first BLOCK\n");
"No cache entry available for the non-first BLOCK\n");
}
coap_pdu_set_code(response, COAP_RESPONSE_CODE_INTERNAL_ERROR);
return;
Expand All @@ -337,14 +334,12 @@ hnd_put_example_data(coap_context_t *ctx,
/* All the data is now in */
data_so_far = coap_cache_get_app_data(cache_entry);
coap_cache_set_app_data(cache_entry, NULL, NULL);
}
else {
} else {
/* Give us the next block response */
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CONTINUE);
return;
}
}
else {
} else {
/* single body of data received */
data_so_far = coap_new_binary(size);
if (data_so_far) {
Expand All @@ -356,19 +351,18 @@ hnd_put_example_data(coap_context_t *ctx,
/* pre-existed response */
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CHANGED);
coap_delete_binary(example_data_ptr);
}
else
} else {
/* just generated response */
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CREATED);
}

example_data_ptr = data_so_far;
if ((option = coap_check_option(request, COAP_OPTION_CONTENT_FORMAT,
&opt_iter)) != NULL) {
example_data_media_type =
coap_decode_var_bytes (coap_opt_value (option),
coap_opt_length (option));
}
else {
coap_decode_var_bytes(coap_opt_value(option),
coap_opt_length(option));
} else {
example_data_media_type = COAP_MEDIATYPE_TEXT_PLAIN;
}

Expand All @@ -377,11 +371,12 @@ hnd_put_example_data(coap_context_t *ctx,
}

int
main(int argc, char* argv[]) {
main(int argc, char *argv[]) {
coap_context_t *ctx = NULL; /* Set up as normal */
/* ... */
uint16_t cache_ignore_options[] = { COAP_OPTION_BLOCK1,
COAP_OPTION_BLOCK2 };
COAP_OPTION_BLOCK2
};

/* Initialize libcoap library */
coap_startup();
Expand All @@ -392,9 +387,9 @@ main(int argc, char* argv[]) {

/* ... */

/** Define the options to ignore when setting up cache-keys */
/* Define the options to ignore when setting up cache-keys */
coap_cache_ignore_options(ctx, cache_ignore_options,
sizeof(cache_ignore_options)/sizeof(cache_ignore_options[0]));
sizeof(cache_ignore_options)/sizeof(cache_ignore_options[0]));

/* ... */
coap_cleanup();
Expand Down
Loading

0 comments on commit ae438cb

Please sign in to comment.