/* * Validates encoded message ID byte order and put/get URI option. */ static void test_nanocoap__hdr(void) { uint8_t buf[_BUF_SIZE]; uint16_t msgid = 0xABCD; char path[] = "/test/abcd/efgh"; char loc_path[] = "/foo/bar"; unsigned char path_tmp[64] = {0}; uint8_t *pktpos = &buf[0]; pktpos += coap_build_hdr((coap_hdr_t *)pktpos, COAP_TYPE_CON, NULL, 0, COAP_METHOD_GET, msgid); pktpos += coap_opt_put_location_path(pktpos, 0, loc_path); pktpos += coap_opt_put_uri_path(pktpos, COAP_OPT_LOCATION_PATH, path); coap_pkt_t pkt; coap_parse(&pkt, &buf[0], pktpos - &buf[0]); TEST_ASSERT_EQUAL_INT(msgid, coap_get_id(&pkt)); int res = coap_get_uri_path(&pkt, path_tmp); TEST_ASSERT_EQUAL_INT(sizeof(path), res); TEST_ASSERT_EQUAL_STRING((char *)path, (char *)path_tmp); res = coap_get_location_path(&pkt, path_tmp, 64); TEST_ASSERT_EQUAL_INT(sizeof(loc_path), res); TEST_ASSERT_EQUAL_STRING((char *)loc_path, (char *)path_tmp); }
static void _on_register(unsigned req_state, coap_pkt_t* pdu, sock_udp_ep_t *remote) { thread_flags_t flag = FLAG_ERR; if ((req_state == GCOAP_MEMO_RESP) && (pdu->hdr->code == COAP_CODE_CREATED)) { /* read the location header and save the RD details on success */ if (coap_get_location_path(pdu, (uint8_t *)_rd_loc, sizeof(_rd_loc)) > 0) { memcpy(&_rd_remote, remote, sizeof(_rd_remote)); flag = FLAG_SUCCESS; } else { /* reset RD entry */ flag = FLAG_OVERFLOW; } } else if (req_state == GCOAP_MEMO_TIMEOUT) { flag = FLAG_TIMEOUT; } thread_flags_set((thread_t *)_waiter, flag); }