void transaction_handle_response(lwm2m_context_t * contextP, void * fromSessionH, coap_packet_t * message) { lwm2m_transaction_t * transacP; transacP = contextP->transactionList; while (transacP != NULL) { void * targetSessionH; targetSessionH = NULL; switch (transacP->peerType) { #ifdef LWM2M_SERVER_MODE case ENDPOINT_CLIENT: targetSessionH = ((lwm2m_client_t *)transacP->peerP)->sessionH; break; #endif #ifdef LWM2M_CLIENT_MODE case ENDPOINT_SERVER: targetSessionH = ((lwm2m_server_t *)transacP->peerP)->sessionH; break; #endif default: break; } if (prv_check_addr(fromSessionH, targetSessionH)) { if (transacP->mID == message->mid) { // HACK: If a message is sent from the monitor callback, // it will arrive before the registration ACK. // So we resend transaction that were denied for authentication reason. if (message->code != COAP_401_UNAUTHORIZED || transacP->retrans_counter >= COAP_MAX_RETRANSMIT) { if (transacP->callback != NULL) { transacP->callback(transacP, message); } transaction_remove(contextP, transacP); } // we found our guy, exit return; } } transacP = transacP->next; } }
static void sms_timeout_cb(fetion_transaction *trans) { fetion_account *account; account = trans->data; /* TODO add error message to textview */ printf("send message time out\n"); g_source_remove(trans->timer); transaction_remove(account, trans); }
static void process_sipc_cb(fetion_account *ses, const gchar *sipmsg) { gchar callid[16]; gint callid0; struct transaction *trans; GSList *trans_cur; fetion_sip_get_attr(sipmsg, "I", callid); callid0 = atoi(callid); trans_cur = ses->trans; while(trans_cur) { trans = (struct transaction*)(trans_cur->data); if(trans->callid == callid0) { if(trans->callback) (trans->callback)(ses, sipmsg, trans); transaction_remove(ses, trans); break; } trans_cur = g_slist_next(trans_cur); } }
/** * Process the sip response message. */ static void process_sipc_cb(fetion_account *ac, const gchar *sipmsg) { gchar *callid; gint callid0; fetion_transaction *trans; GSList *trans_cur; if (!(callid = sip_header_get_attr(sipmsg, "I"))) { hybrid_debug_error("fetion", "invalid sipc message received\n%s", sipmsg); g_free(callid); return; } callid0 = atoi(callid); trans_cur = ac->trans_list; while(trans_cur) { trans = (fetion_transaction*)(trans_cur->data); if (trans->callid == callid0) { if (trans->callback) { (trans->callback)(ac, sipmsg, trans); } transaction_remove(ac, trans); break; } trans_cur = g_slist_next(trans_cur); } }
int transaction_send(lwm2m_context_t * contextP, lwm2m_transaction_t * transacP) { bool maxRetriesReached = false; LOG("Entering"); if (transacP->buffer == NULL) { transacP->buffer_len = coap_serialize_get_size(transacP->message); if (transacP->buffer_len == 0) { transaction_remove(contextP, transacP); return COAP_500_INTERNAL_SERVER_ERROR; } transacP->buffer = (uint8_t*)lwm2m_malloc(transacP->buffer_len); if (transacP->buffer == NULL) { transaction_remove(contextP, transacP); return COAP_500_INTERNAL_SERVER_ERROR; } transacP->buffer_len = coap_serialize_message(transacP->message, transacP->buffer); if (transacP->buffer_len == 0) { lwm2m_free(transacP->buffer); transacP->buffer = NULL; transaction_remove(contextP, transacP); return COAP_500_INTERNAL_SERVER_ERROR; } } if (!transacP->ack_received) { long unsigned timeout; if (0 == transacP->retrans_counter) { time_t tv_sec = lwm2m_gettime(); if (0 <= tv_sec) { transacP->retrans_time = tv_sec + COAP_RESPONSE_TIMEOUT; transacP->retrans_counter = 1; timeout = 0; } else { maxRetriesReached = true; } } else { timeout = COAP_RESPONSE_TIMEOUT << (transacP->retrans_counter - 1); } if (COAP_MAX_RETRANSMIT + 1 >= transacP->retrans_counter) { (void)lwm2m_buffer_send(transacP->peerH, transacP->buffer, transacP->buffer_len, contextP->userData); transacP->retrans_time += timeout; transacP->retrans_counter += 1; } else { maxRetriesReached = true; } } if (transacP->ack_received || maxRetriesReached) { if (transacP->callback) { transacP->callback(transacP, NULL); } transaction_remove(contextP, transacP); return -1; } return 0; }
bool transaction_handleResponse(lwm2m_context_t * contextP, void * fromSessionH, coap_packet_t * message, coap_packet_t * response) { bool found = false; bool reset = false; lwm2m_transaction_t * transacP; LOG("Entering"); transacP = contextP->transactionList; while (NULL != transacP) { if (lwm2m_session_is_equal(fromSessionH, transacP->peerH, contextP->userData) == true) { if (!transacP->ack_received) { if ((COAP_TYPE_ACK == message->type) || (COAP_TYPE_RST == message->type)) { if (transacP->mID == message->mid) { found = true; transacP->ack_received = true; reset = COAP_TYPE_RST == message->type; } } } if (reset || prv_checkFinished(transacP, message)) { // HACK: If a message is sent from the monitor callback, // it will arrive before the registration ACK. // So we resend transaction that were denied for authentication reason. if (!reset) { if (COAP_TYPE_CON == message->type && NULL != response) { coap_init_message(response, COAP_TYPE_ACK, 0, message->mid); message_send(contextP, response, fromSessionH); } if ((COAP_401_UNAUTHORIZED == message->code) && (COAP_MAX_RETRANSMIT > transacP->retrans_counter)) { transacP->ack_received = false; transacP->retrans_time += COAP_RESPONSE_TIMEOUT; return true; } } if (transacP->callback != NULL) { transacP->callback(transacP, message); } transaction_remove(contextP, transacP); return true; } // if we found our guy, exit if (found) { time_t tv_sec = lwm2m_gettime(); if (0 <= tv_sec) { transacP->retrans_time = tv_sec; } if (transacP->response_timeout) { transacP->retrans_time += transacP->response_timeout; } else { transacP->retrans_time += COAP_RESPONSE_TIMEOUT * transacP->retrans_counter; } return true; } } transacP = transacP->next; } return false; }
int transaction_send(lwm2m_context_t * contextP, lwm2m_transaction_t * transacP) { if (transacP->buffer == NULL) { uint8_t tempBuffer[LWM2M_MAX_PACKET_SIZE]; int length; length = coap_serialize_message(transacP->message, tempBuffer); if (length <= 0) return COAP_500_INTERNAL_SERVER_ERROR; transacP->buffer = (uint8_t*)lwm2m_malloc(length); if (transacP->buffer == NULL) return COAP_500_INTERNAL_SERVER_ERROR; memcpy(transacP->buffer, tempBuffer, length); transacP->buffer_len = length; } switch(transacP->peerType) { case ENDPOINT_CLIENT: LOG("Sending %d bytes\r\n", transacP->buffer_len); contextP->bufferSendCallback(((lwm2m_client_t*)transacP->peerP)->sessionH, transacP->buffer, transacP->buffer_len, contextP->bufferSendUserData); break; case ENDPOINT_SERVER: LOG("Sending %d bytes\r\n", transacP->buffer_len); contextP->bufferSendCallback(((lwm2m_server_t*)transacP->peerP)->sessionH, transacP->buffer, transacP->buffer_len, contextP->bufferSendUserData); break; case ENDPOINT_BOOTSTRAP: // not implemented yet break; default: return 0; } if (transacP->retrans_counter == 0) { struct timeval tv; if (0 == lwm2m_gettimeofday(&tv, NULL)) { transacP->retrans_time = tv.tv_sec; transacP->retrans_counter = 1; } else { // crude error handling transacP->retrans_counter = COAP_MAX_RETRANSMIT; } } if (transacP->retrans_counter < COAP_MAX_RETRANSMIT) { transacP->retrans_time += COAP_RESPONSE_TIMEOUT * transacP->retrans_counter; transacP->retrans_counter++; } else { if (transacP->callback) { transacP->callback(transacP, NULL); } transaction_remove(contextP, transacP); return -1; } return 0; }