static int checkOneField( CSSM_CL_HANDLE clHand, CSSM_HANDLE cacheHand1, CSSM_HANDLE cacheHand2, const CSSM_OID *fieldOid) { CSSM_DATA_PTR fieldData1 = NULL; CSSM_DATA_PTR fieldData2 = NULL; CSSM_RETURN crtn; CSSM_HANDLE resultHand1 = 0; CSSM_HANDLE resultHand2 = 0; uint32 numFields = 0; int rtn; crtn = CSSM_CL_CertGetFirstCachedFieldValue( clHand, cacheHand1, fieldOid, &resultHand1, &numFields, &fieldData1); if(crtn) { return crtn; } if(numFields != 1) { printf("Fiedl not present; try another cert\n"); return 1; } crtn = CSSM_CL_CertGetFirstCachedFieldValue( clHand, cacheHand2, fieldOid, &resultHand2, &numFields, &fieldData2); if(crtn) { return crtn; } rtn = compareFields(fieldOid, fieldData1, fieldData2); CSSM_CL_CertAbortQuery(clHand, resultHand1); CSSM_CL_CertAbortQuery(clHand, resultHand2); CSSM_CL_FreeFieldValue(clHand, fieldOid, fieldData1); CSSM_CL_FreeFieldValue(clHand, fieldOid, fieldData2); return rtn; }
void MHL7Compare::compareFieldValues(const MString& segment, int fldNum, int compNum, int subCompNum) { if (!segment.size()) return; if (subCompNum) { // get the sub component MString existValue; char* pExist = HL7GetSub(mMsgExist, fldNum, 1, compNum, subCompNum); if (pExist) existValue = pExist; else existValue = ""; MString newValue; char* pNew = HL7GetSub(mMsgNew, fldNum, 1, compNum, subCompNum); if (pNew) newValue = pNew; else newValue = ""; if (mLogLevel >= 3) { cout << segment << " " << setw(3) << fldNum << " " << setw(3) << compNum << " " << setw(3) << subCompNum << " " << "<" << existValue << "> " << "<" << newValue << "> " << endl; } if (existValue != newValue) { DIFF diff; diff.fldNum = fldNum; diff.existValue = existValue; diff.newValue = newValue; diff.comment = "Sub components do not match"; mDiff.insert (MDiff::value_type (segment, diff) ); mCount++; } } else if (compNum) { // get the component MString existValue; char* pExist = HL7GetComp(mMsgExist, fldNum, 1, compNum); if (pExist) { for (int i = strlen(pExist)-1; i >=0; i--) { if (pExist[i] == '\\') pExist[i] = 0; else break; } existValue = pExist; } else existValue = ""; MString newValue; char* pNew = HL7GetComp(mMsgNew, fldNum, 1, compNum); if (pNew) { for (int i = strlen(pNew)-1; i >=0; i--) { if (pNew[i] == '\\') pNew[i] = 0; else break; } newValue = pNew; } else { newValue = ""; } if (mLogLevel >= 3) { cout << segment << " " << setw(3) << fldNum << " " << setw(3) << compNum << " " << setw(3) << subCompNum << " " << "<" << existValue << "> " << "<" << newValue << "> " << endl; } if (existValue != newValue) { DIFF diff; diff.fldNum = fldNum; diff.existValue = existValue; diff.newValue = newValue; diff.comment = "Components do not match"; mDiff.insert (MDiff::value_type (segment, diff) ); mCount++; } } else if (fldNum) { // get the entire field MString existValue; char* pExist = HL7GetFld(mMsgExist, fldNum); if (pExist) { for (int i = strlen(pExist)-1; i >=0; i--) { if (pExist[i] == '^' || pExist[i] == '\\') pExist[i] = 0; else break; } existValue = pExist; } else existValue = ""; MString newValue; char* pNew = HL7GetFld(mMsgNew, fldNum); if (pNew) { for (int i = strlen(pNew)-1; i >=0; i--) { if (pNew[i] == '^' || pNew[i] == '\\') pNew[i] = 0; else break; } newValue = pNew; } else { newValue = ""; } if (mLogLevel >= 3) { cout << segment << " " << setw(3) << fldNum << " " << setw(3) << compNum << " " << setw(3) << subCompNum << " " << "<" << existValue << "> " << "<" << newValue << "> " << endl; } if (existValue != newValue) { DIFF diff; diff.fldNum = fldNum; diff.existValue = existValue; diff.newValue = newValue; diff.comment = "Fields do not match"; mDiff.insert (MDiff::value_type (segment, diff) ); mCount++; } } else { compareFields(segment); // compare all the fields } }
void MHL7Compare::compareHL7() { MString segExist, segNew; int rExist = getFirstSegment(mMsgExist, segExist); if (!rExist) { cout << "Cannot access the first segment of the existing message" << endl; return; } int rNew = getFirstSegment(mMsgNew, segNew); if (!rNew) { cout << "MHL7Compare: Cannot access the first segment of the new message" << endl; return; } if (mSegInfo.empty()) { // no initialize file was provided. // Compare all the fields of all the segments do { if (segExist != segNew) { cout << "MHL7Compare: segments not in proper order" << endl; DIFF diff; diff.fldNum = 0; diff.existValue = segExist; diff.newValue = segNew; diff.comment = "Segment order does not match"; mDiff.insert (MDiff::value_type (segExist, diff) ); mCount++; break; } // endif //cout << "Comparing segments: " << segExist << " " << segNew << endl; char *name = segNew.strData(); if (!strcmp(name, "MSH")) compareMesgHeaders(); else if (!strcmp(name, "EVN")) compareEVNs(); else compareFields(segExist); // applies to any segment rExist = getNextSegment(mMsgExist, segExist); rNew = getNextSegment(mMsgNew, segNew); if (rExist != rNew) { cout << "MHL7Compare: One message is shorter than the other" << endl; DIFF diff; diff.fldNum = 0; diff.existValue = segExist; diff.newValue = segNew; diff.comment = "One message is shorter than the other"; mDiff.insert (MDiff::value_type (segExist, diff) ); mCount++; } } while (rExist && rNew); } // endif mSegInfo.empty() else { for (MSegmentInfo::iterator i = mSegInfo.begin(); i != mSegInfo.end(); i++) { segExist = (*i).first; // Go to beginning of message, and restart search. rNew = getFirstSegment(mMsgNew, segNew); rExist = getFirstSegment(mMsgExist, segNew); if (segNew != segExist) { segNew = segExist; rExist = findSegment(mMsgExist, segExist); rNew = findSegment(mMsgNew, segNew); } // Check all instances of segExist in mMsgExist and mMsgNew // Note: if a segment mentioned in the .ini file does not // exist in the existing file, there is no error. while(rExist || rNew) { // If a segment is not found in the new message, that exists in the // existing file, generate a difference. if (rExist && !rNew) { DIFF diff; diff.fldNum = 0; diff.existValue = segExist; diff.newValue = segNew; diff.comment = "New message is missing this segment"; mDiff.insert (MDiff::value_type (segExist, diff) ); mCount++; rNew = rExist = false; continue; } // If a segment exists in the new message, but not in the existing, // then generate an appropriate difference. if (!rExist && rNew) { DIFF diff; diff.fldNum = 0; diff.existValue = segExist; diff.newValue = segNew; diff.comment = "New message has too many segments of this type"; mDiff.insert (MDiff::value_type (segExist, diff) ); mCount++; rNew = rExist = false; continue; } // Find the difference(s) within existing segments compareFieldValues(segExist, ((*i).second).fldNum, ((*i).second).compNum, ((*i).second).subCompNum ); rExist = findSegment(mMsgExist, segExist); rNew = findSegment(mMsgNew, segExist); } // endwhile } // endfor } // endelse mSegInfo.empty() }