/* * ApplySegment is responsible for copying in the xTEDS of the segment number of the passed * Message. If there is no xTEDSSegmentNode corresponding to the xTEDS provider, one is * created. In other words, there is no other function to add a xTEDSSegmentNode, this one * is to be used. * Params: * Message - The xTEDS to apply. * Returns: * bool - True if the xTEDS was applied successfully, false otherwise. */ bool xTEDSSegmentBuilder::ApplySegment(const SDMxTEDS &Message) { //Be sure this is a segment first if (!IsSegmentedxTEDS(Message)) { printf("xTEDSSegmentBuilder::ApplySegment - xTEDS not segmented.\n"); return false; } //Get the sequence number and the total segments from the xTEDS unsigned char SequenceNumber = Message.xTEDS[0]; //Zero-based sequence number unsigned char TotalSegments = Message.xTEDS[1]; //Total number of segments //If the sequence number is bigger than the advertised number of segments, or out of range if (SequenceNumber+1 > TotalSegments || SequenceNumber > MAX_XTEDS_SEQUENCE_VALUE || TotalSegments > MAX_XTEDS_SEQUENCE_VALUE) { printf("xTEDSSegmentBuilder::ApplySegment - Sequence number out of range.\n"); return false; } //Get a reference to the xTEDS node xTEDSSegmentNode *SegmentNode = FindNodeEntry(Message.source); //If the node doesn't exist, create it if (SegmentNode == NULL) { //This should be the first sequence number if (SequenceNumber != 0) { printf("xTEDSSegmentBuilder::ApplySegment - Sequence number not zero for new xTEDS.\n"); return false; } //Allocate the node SegmentNode = AddSegmentNode(); //If malloc error, return error if (SegmentNode == NULL) { printf("xTEDSSegmentBuilder::ApplySegment - Segment node could not be obtained.\n"); return false; } //Save the number of segments SegmentNode->NumSegments = static_cast<unsigned int>(TotalSegments); //Save the component ID of the xTEDS sender SegmentNode->xTEDSID = Message.source; //Allocate the buffer to use for the xTEDS, based on the number of segments //SegmentNode->xTEDSBuffer = new char[(TotalSegments * SEGMENT_MAX_XTEDS_SIZE)]; if (sizeof(SegmentNode->xTEDSBuffer) < static_cast<unsigned int>(TotalSegments*SEGMENT_MAX_XTEDS_SIZE)) { printf("xTEDSSegmentBuilder:: xTEDS buffer not large enough for incoming segmented xTEDS, not accepting.\n"); DeleteNode(Message.source); return false; } //Clear the buffer memset(SegmentNode->xTEDSBuffer, 0, sizeof(SegmentNode->xTEDSBuffer)); } //Node exists else { //If this is a timeout response, but the segment was received, no need to reapply, return true if(AlreadyReceived(SequenceNumber, SegmentNode)) return true; //Check that this segment number is sent in order if (!SentInOrder(SequenceNumber, SegmentNode)) { printf("xTEDSSegmentBuilder::ApplySegment - Segments out of order.\n"); return false; } } //At this point, apply the segment at the end of the current xTEDS document (this assumes in order message reception) strncpy((SegmentNode->xTEDSBuffer + strlen(SegmentNode->xTEDSBuffer)), Message.xTEDS+2, strlen(Message.xTEDS+2)); //Set this segment as having been received SegmentNode->SegmentsReceived[SequenceNumber] = XTEDS_RECEIVED; //Return success return true; }
/** Function to parse the command line options. Responsible to 1. Parse the input values. 2. Print the usage note. 3. Identify the valdations to be carried out. 4. Type of report needs to be generated. @internalComponent @released @param aArgc - argument count @param aArgv[] - argument values */ ReturnType CmdLineHandler::ProcessCommandLine(unsigned int aArgc, char* aArgv[]) { if(aArgc < 2) { std::cout << PrintVersion().c_str() << std::endl; std::cout << PrintUsage().c_str() << std::endl; return EQuit; } ArgumentList argumentList(&aArgv[0], aArgv + aArgc); int argCount = argumentList.size(); iInputCommand = KToolName; for( int i = 1; i < argCount; i++ ) //Skip tool name { String name = argumentList.at(i); iInputCommand += " "; iInputCommand += name; int longOptionFlag = 0; if(IsOption(name, longOptionFlag)) { String optionName; bool optionValue = false; StringList optionValueList; ParseOption(name, optionName, optionValueList, optionValue); char shortOption = KNull; if(Validate(ReaderUtil::ToLower(optionName), optionValue, optionValueList.size())) { if(longOptionFlag) { shortOption = optionName.at(2); } else { shortOption = optionName.at(1); } } switch(shortOption) { case 'q': iCommmandFlag |= QuietMode; break; case 'a': iCommmandFlag |= KAll; break; case 'x': iCommmandFlag |= KXmlReport; break; case 'o': iXmlFileName.assign(optionValueList.front()); NormaliseName(); break; case 's': if((optionName == KShortSuppressOption) || (optionName == KLongSuppressOption)) { String value; while(optionValueList.size() > 0) { value = optionValueList.front(); if(iSuppressVal[value]) { if(iValidations > 0) //Is any check enabled? { if(iValidations & iSuppressVal[value]) { iValidations ^= iSuppressVal[value]; //Consider only 3 LSB's } } else //Is this valid value? { iSuppressions |= iSuppressVal[value]; } } else { throw ExceptionReporter(UNKNOWNSUPPRESSVAL,(char*)(optionValueList.front().c_str())); } optionValueList.pop_front(); } } else if(optionName == KLongEnableSidCheck) { iValidations |= KMarkEnable; iValidations |= ESid; } else if(optionName == KLongSidAllOption) { iCommmandFlag |= KSidAll; } break; case 'd': if(optionName == KLongEnableDbgFlagCheck) { iValidations |= KMarkEnable; iValidations |= EDbg; if(optionValueList.size() > 0) { if(optionValueList.front() == String("true")) { iDebuggableFlagVal = true; } else if (optionValueList.front() == String("false")) { iDebuggableFlagVal = false; } else { throw ExceptionReporter(UNKNOWNDBGVALUE); } } } else if (optionName == KLongEnableDepCheck) { iValidations |= KMarkEnable; iValidations |= EDep; } break; case 'e': if (optionName == KLongE32InputOption) { iCommmandFlag |= KE32Input; } break; case 'v': if(optionName == KLongVidValOption) { StringListToUnIntList(optionValueList, iVidValList); } else if(optionName == KLongEnableVidCheck) { iValidations |= KMarkEnable; iValidations |= EVid; } else { iCommmandFlag |= KVerbose; /**Initialize ExceptionImplementation class with verbose mode flag to print all status information to standard output*/ ExceptionImplementation::Instance(iCommmandFlag); } break; case 'n': iCommmandFlag |= KNoCheck; break; case 'h': std::cout << PrintVersion().c_str() << std::endl; std::cout << PrintUsage().c_str() << std::endl; return EQuit; //Don't proceed further } } else { if(!AlreadyReceived(name)) { iImageNameList.push_back(name); } else { ExceptionReporter(IMAGENAMEALREADYRECEIVED, (char*)name.c_str()).Report(); } iNoImage = false; } } //While loop ends here if((iCommmandFlag || iValidations || iSuppressions) && iNoImage) { PrintVersion(); PrintUsage(); } //Always log the version information into log file ExceptionImplementation::Instance(iCommmandFlag)->Log(iVersion); ValidateArguments(); ValidateE32NoCheckArguments(); if(iCommmandFlag & KE32Input) { ValidateImageNameList(); } return ESuccess; }