static void wtls_application(WAPEvent * event, WTLSMachine * wtls_machine) { int listLen, i = 0; WAPEvent *dgram; wtls_Payload *payLoad; /* Apply the negotiated decryption/decoding/MAC check to the received data */ /* Take the userdata and pass it on up to the WTP/WSP, depending on the destination port */ listLen = gwlist_len(event->u.T_Unitdata_Ind.pdu_list); for (; i < listLen; i++) { payLoad = gwlist_consume(event->u.T_Unitdata_Ind.pdu_list); dgram = wap_event_create(T_DUnitdata_Ind); dgram->u.T_DUnitdata_Ind.addr_tuple = wap_addr_tuple_create(event->u.T_Unitdata_Ind.addr_tuple-> remote->address, event->u.T_Unitdata_Ind.addr_tuple-> remote->port, event->u.T_Unitdata_Ind.addr_tuple-> local->address, event->u.T_Unitdata_Ind.addr_tuple-> local->port); dgram->u.T_DUnitdata_Ind.user_data = payLoad->data; wap_dispatch_datagram(dgram); payLoad->data = NULL; wtls_payload_destroy(payLoad); } }
void *wtls_payloadlist_destroy(List* payloadList) { wtls_Payload* currentPayload; int listLen, i; listLen = gwlist_len(payloadList); for( i=0; i<listLen; i++) { currentPayload = (wtls_Payload *)gwlist_get(payloadList, i); wtls_payload_destroy(currentPayload); } /* delete the list itself */ gw_free(payloadList); }
static void add_pdu(WTLSMachine * wtls_machine, wtls_PDU * pduToAdd) { int currentLength; wtls_Payload *payloadToAdd; Octstr *packedPDU; /* Update sequence number before encryption */ wtls_machine->server_seq_num++; /* Pack and encrypt the pdu */ if (!(payloadToAdd = wtls_pdu_pack(pduToAdd, wtls_machine))) { wtls_machine->server_seq_num--; return; } if (!payloadToAdd->data) { wtls_machine->server_seq_num--; wtls_payload_destroy(payloadToAdd); return; } /* Check to see if we've already allocated some memory for the list */ if (!wtls_machine->packet_to_send) wtls_machine->packet_to_send = octstr_create(""); /* If the pdu is a Handshake pdu, append the Octstr to our wtls_machine's exchanged_handshakes Octstr */ packedPDU = wtls_payload_pack(payloadToAdd, wtls_machine->server_seq_num); if (pduToAdd->type == ChangeCipher_PDU) wtls_machine->server_seq_num = -1; /* Add it to our list */ currentLength = octstr_len(wtls_machine->packet_to_send); octstr_insert(wtls_machine->packet_to_send, packedPDU, currentLength); wtls_payload_destroy(payloadToAdd); octstr_destroy(packedPDU); }