int _gnutls_parse_extensions(gnutls_session_t session, gnutls_ext_parse_type_t parse_type, const uint8_t * data, int data_size) { int next, ret; int pos = 0; uint16_t type; const uint8_t *sdata; gnutls_ext_recv_func ext_recv; uint16_t size; #ifdef DEBUG int i; if (session->security_parameters.entity == GNUTLS_CLIENT) for (i = 0; i < session->internals.extensions_sent_size; i++) { _gnutls_handshake_log ("EXT[%d]: expecting extension '%s'\n", session, _gnutls_extension_get_name(session->internals. extensions_sent [i])); } #endif DECR_LENGTH_RET(data_size, 2, 0); next = _gnutls_read_uint16(data); pos += 2; DECR_LENGTH_RET(data_size, next, 0); do { DECR_LENGTH_RET(next, 2, 0); type = _gnutls_read_uint16(&data[pos]); pos += 2; if ((ret = _gnutls_extension_list_check(session, type)) < 0) { gnutls_assert(); return ret; } DECR_LENGTH_RET(next, 2, 0); size = _gnutls_read_uint16(&data[pos]); pos += 2; DECR_LENGTH_RET(next, size, 0); sdata = &data[pos]; pos += size; ext_recv = _gnutls_ext_func_recv(type, parse_type); if (ext_recv == NULL) { _gnutls_handshake_log ("EXT[%p]: Found extension '%s/%d'\n", session, _gnutls_extension_get_name(type), type); continue; } _gnutls_handshake_log ("EXT[%p]: Parsing extension '%s/%d' (%d bytes)\n", session, _gnutls_extension_get_name(type), type, size); if ((ret = ext_recv(session, sdata, size)) < 0) { gnutls_assert(); return ret; } } while (next > 2); return 0; }
/* ###### Handle incoming CSP message #################################### */ static void handleMessage(int sd, struct SimpleRedBlackTree* objectStorage, struct SimpleRedBlackTree* objectDisplay) { struct ComponentStatusReport* cspReport; struct CSPObject* cspObject; char buffer[65536]; ssize_t received; size_t i; received = ext_recv(sd, (char*)&buffer, sizeof(buffer), 0); if(received) { cspReport = (struct ComponentStatusReport*)&buffer; if( (received >= (ssize_t)sizeof(struct ComponentStatusReport)) && (cspReport->Header.Type == CSPT_REPORT) && (ntohl(cspReport->Header.Version) == CSP_VERSION) ) { cspReport->Header.Version = ntohl(cspReport->Header.Version); cspReport->Header.Length = ntohs(cspReport->Header.Length); cspReport->Header.SenderID = ntoh64(cspReport->Header.SenderID); cspReport->Header.SenderTimeStamp = ntoh64(cspReport->Header.SenderTimeStamp); cspReport->ReportInterval = ntohl(cspReport->ReportInterval); cspReport->Workload = ntohs(cspReport->Workload); cspReport->Associations = ntohs(cspReport->Associations); if(sizeof(struct ComponentStatusReport) + (cspReport->Associations * sizeof(struct ComponentAssociation)) == (size_t)received) { for(i = 0;i < cspReport->Associations;i++) { cspReport->AssociationArray[i].ReceiverID = ntoh64(cspReport->AssociationArray[i].ReceiverID); cspReport->AssociationArray[i].Duration = ntoh64(cspReport->AssociationArray[i].Duration); cspReport->AssociationArray[i].Flags = ntohs(cspReport->AssociationArray[i].Flags); cspReport->AssociationArray[i].ProtocolID = ntohs(cspReport->AssociationArray[i].ProtocolID); cspReport->AssociationArray[i].PPID = ntohl(cspReport->AssociationArray[i].PPID); } cspObject = findCSPObject(objectStorage, cspReport->Header.SenderID); if(cspObject == NULL) { cspObject = (struct CSPObject*)malloc(sizeof(struct CSPObject)); if(cspObject) { simpleRedBlackTreeNodeNew(&cspObject->StorageNode); simpleRedBlackTreeNodeNew(&cspObject->DisplayNode); cspObject->Identifier = cspReport->Header.SenderID; cspObject->AssociationArray = NULL; switch(CID_GROUP(cspObject->Identifier)) { case CID_GROUP_REGISTRAR: totalPRs++; break; case CID_GROUP_POOLELEMENT: totalPEs++; break; case CID_GROUP_POOLUSER: totalPUs++; break; } } } if(cspObject) { if(simpleRedBlackTreeNodeIsLinked(&cspObject->DisplayNode)) { /* The position within the objectDisplay storage may change, due to updated locationArray! */ CHECK(simpleRedBlackTreeRemove(objectDisplay, &cspObject->DisplayNode) == &cspObject->DisplayNode); simpleRedBlackTreeVerify(objectDisplay); } if(cspReport->Header.Flags != 0x00) { cspObject->LastReportTimeStamp = 0; } else { cspObject->LastReportTimeStamp = getMicroTime(); cspObject->SenderTimeStamp = cspReport->Header.SenderTimeStamp; cspObject->ReportInterval = cspReport->ReportInterval; cspObject->Workload = CSR_GET_WORKLOAD(cspReport->Workload); getDescriptionForID(cspObject->Identifier, (char*)&cspObject->Description, sizeof(cspObject->Description)); memcpy(&cspObject->Status, &cspReport->Status, sizeof(cspObject->Status)); cspObject->Status[sizeof(cspObject->Status) - 1] = 0x00; memcpy(&cspObject->Location, &cspReport->Location, sizeof(cspObject->Location)); /* DisplayNode MUST be re-inserted, since the location may change and the location is part of the sorting key! */ /* for(int i=0;i < 6;i++) { cspObject->Location[i] = 'A' + (random() % 26); } */ cspObject->Location[sizeof(cspObject->Location) - 1] = 0x00; } if(cspObject->AssociationArray) { deleteComponentAssociationArray(cspObject->AssociationArray); } cspObject->AssociationArray = createComponentAssociationArray(cspReport->Associations); CHECK(cspObject->AssociationArray); memcpy(cspObject->AssociationArray, &cspReport->AssociationArray, cspReport->Associations * sizeof(struct ComponentAssociation)); cspObject->Associations = cspReport->Associations; CHECK(simpleRedBlackTreeInsert(objectStorage, &cspObject->StorageNode) == &cspObject->StorageNode); simpleRedBlackTreeVerify(objectStorage); CHECK(simpleRedBlackTreeInsert(objectDisplay, &cspObject->DisplayNode) == &cspObject->DisplayNode); simpleRedBlackTreeVerify(objectDisplay); } } } } }