mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-20 14:29:05 +03:00
observe: Make sure the correct token in used for cancellation
Use the Token used for the initial Observe response, not any interim stateful tokens used for Block handling.
This commit is contained in:
1 parent
c68d1e9fe7
commit
b4306bb791
2 files changed
+25
-7
No files matched your search
@@ -118,7 +118,8 @@ struct coap_lg_crcv_t {
|
||||
size_t total_len; /**< Length as indicated by SIZE2 option */
|
||||
coap_binary_t *body_data; /**< Used for re-assembling entire body */
|
||||
coap_binary_t *app_token; /**< app requesting PDU token */
|
||||
uint64_t state_token; /**< state token (and observe token) */
|
||||
coap_binary_t *obs_token; /**< Initial Observe response PDU token */
|
||||
uint64_t state_token; /**< state token */
|
||||
coap_pdu_t pdu; /**< skeletal PDU */
|
||||
coap_rblock_t rec_blocks; /** < list of received blocks */
|
||||
coap_tick_t last_used; /**< Last time all data sent or 0 */
|
||||
|
||||
+23
-6
@@ -396,13 +396,13 @@ coap_cancel_observe(coap_session_t *session, coap_binary_t *token,
|
||||
cq->app_token->length))) {
|
||||
uint8_t buf[8];
|
||||
coap_mid_t mid;
|
||||
size_t size = coap_encode_var_safe8(buf, sizeof(cq->state_token),
|
||||
cq->state_token);
|
||||
size_t size;
|
||||
const uint8_t *data;
|
||||
coap_binary_t *otoken = cq->obs_token ? cq->obs_token : cq->app_token;
|
||||
coap_pdu_t * pdu = coap_pdu_duplicate(&cq->pdu,
|
||||
session,
|
||||
size,
|
||||
buf,
|
||||
otoken->length,
|
||||
otoken->s,
|
||||
NULL);
|
||||
|
||||
cq->observe_set = 0;
|
||||
@@ -1030,6 +1030,7 @@ coap_block_delete_lg_crcv(coap_session_t *session,
|
||||
coap_log(LOG_DEBUG, "** %s: lg_crcv %p released\n",
|
||||
coap_session_str(session), (void*)lg_crcv);
|
||||
coap_delete_binary(lg_crcv->app_token);
|
||||
coap_delete_binary(lg_crcv->obs_token);
|
||||
coap_free_type(COAP_LG_CRCV, lg_crcv);
|
||||
}
|
||||
#endif /* COAP_CLIENT_SUPPORT */
|
||||
@@ -2112,6 +2113,13 @@ coap_handle_response_get_block(coap_context_t *context,
|
||||
p->observe_length = min(coap_opt_length(obs_opt), 3);
|
||||
memcpy(p->observe, coap_opt_value(obs_opt), p->observe_length);
|
||||
p->observe_set = 1;
|
||||
/* Need to keep observe response token for later cancellation */
|
||||
coap_delete_binary(p->obs_token);
|
||||
p->obs_token = coap_new_binary(rcvd->token_length);
|
||||
if (!p->obs_token) {
|
||||
goto fail_resp;
|
||||
}
|
||||
memcpy(p->obs_token->s, rcvd->token, rcvd->token_length);
|
||||
}
|
||||
else {
|
||||
p->observe_set = 0;
|
||||
@@ -2203,8 +2211,10 @@ coap_handle_response_get_block(coap_context_t *context,
|
||||
rcvd->body_total = size2;
|
||||
}
|
||||
if (context->response_handler) {
|
||||
coap_log(LOG_DEBUG, "Client app version of updated PDU\n");
|
||||
coap_show_pdu(LOG_DEBUG, rcvd);
|
||||
if (block.m != 0 || block.num != 0) {
|
||||
coap_log(LOG_DEBUG, "Client app version of updated PDU\n");
|
||||
coap_show_pdu(LOG_DEBUG, rcvd);
|
||||
}
|
||||
context->response_handler(session, sent, rcvd, rcvd->mid);
|
||||
}
|
||||
app_has_response = 1;
|
||||
@@ -2251,6 +2261,13 @@ block_mode:
|
||||
p->observe_length = min(coap_opt_length(obs_opt), 3);
|
||||
memcpy(p->observe, coap_opt_value(obs_opt), p->observe_length);
|
||||
p->observe_set = 1;
|
||||
/* Need to keep observe response token for later cancellation */
|
||||
coap_delete_binary(p->obs_token);
|
||||
p->obs_token = coap_new_binary(rcvd->token_length);
|
||||
if (!p->obs_token) {
|
||||
goto fail_resp;
|
||||
}
|
||||
memcpy(p->obs_token->s, rcvd->token, rcvd->token_length);
|
||||
}
|
||||
else {
|
||||
p->observe_set = 0;
|
||||
|
||||
Reference in new issue
Block a user