void oc_send_response(oc_request_t *request, oc_status_t response_code) { // FIX:: set errno if CBOR encoding failed. request->response->response_buffer->response_length = response_length(); request->response->response_buffer->code = oc_status_code(response_code); }
void oc_send_separate_response(oc_separate_response_t *handle, oc_status_t response_code) { oc_response_buffer_t response_buffer; response_buffer.buffer = handle->buffer; response_buffer.response_length = response_length(); response_buffer.code = oc_status_code(response_code); coap_separate_t *cur = oc_list_head(handle->requests), *next = NULL; coap_packet_t response[1]; while (cur != NULL) { next = cur->next; if (cur->observe > 0) { coap_transaction_t *t = coap_new_transaction(coap_get_mid(), &cur->endpoint); if (t) { coap_separate_resume(response, cur, oc_status_code(response_code), t->mid); coap_set_header_content_format(response, APPLICATION_CBOR); if (cur->observe == 1) { coap_set_header_observe(response, 1); } if (response_buffer.response_length > 0) { coap_set_payload(response, handle->buffer, response_buffer.response_length); } t->message->length = coap_serialize_message(response, t->message->data); coap_send_transaction(t); } coap_separate_clear(handle, cur); } else { if (coap_notify_observers(NULL, &response_buffer, &cur->endpoint) == 0) { coap_separate_clear(handle, cur); } } cur = next; } if (oc_list_length(handle->requests) == 0) { handle->active = 0; } }
static void oc_core_discovery_handler(oc_request_t *req, oc_interface_mask_t interface) { char *rt = NULL; int rt_len = 0, matches = 0; char uuid[37]; rt_len = oc_ri_get_query_value(req->query, req->query_len, "rt", &rt); oc_uuid_to_str(oc_core_get_device_id(0), uuid, sizeof(uuid)); switch (interface) { case OC_IF_LL: { oc_rep_start_links_array(); matches = process_device_object(oc_rep_array(links), uuid, rt, rt_len); oc_rep_end_links_array(); } break; case OC_IF_BASELINE: { oc_rep_start_root_object(); oc_process_baseline_interface(req->resource); oc_rep_set_array(root, links); matches = process_device_object(oc_rep_array(links), uuid, rt, rt_len); oc_rep_close_array(root, links); oc_rep_end_root_object(); } break; default: break; } int response_length = oc_rep_finalize(); if (matches && response_length > 0) { req->response->response_buffer->response_length = response_length; req->response->response_buffer->code = oc_status_code(OC_STATUS_OK); } else { /* There were rt/if selections and there were no matches, so ignore */ req->response->response_buffer->code = OC_IGNORE; } }