#include "SCPatchContext.h" /* -------------------------------------------------------------------------------- */ bool operator< (const MacPSN& x, const MacPSN& y) { if(x.psn.highLongOfPSN < y.psn.highLongOfPSN) return true; else if(x.psn.highLongOfPSN == y.psn.highLongOfPSN) return (x.psn.lowLongOfPSN < y.psn.lowLongOfPSN); else return false; } /* -------------------------------------------------------------------------------- */ bool operator==(const MacPSN& x, const MacPSN& y) { return (x.psn.highLongOfPSN == y.psn.highLongOfPSN && x.psn.lowLongOfPSN == y.psn.lowLongOfPSN); } /* -------------------------------------------------------------------------------- */ SCPatchContext::SCPatchContext(ProcessSerialNumber *inPSN, SInt32 inPID, OSType inCreator) { psn = *inPSN; pid = inPID; path = NULL; name = NULL; creator = inCreator; flags = 0; } /* -------------------------------------------------------------------------------- */ SCPatchContext::SCPatchContext(const SCPatchContext &toCopy) { psn = toCopy.psn; pid = toCopy.pid; flags = toCopy.flags; creator = toCopy.creator; if((path = toCopy.path) != NULL) CFRetain(path); if((name = toCopy.name) != NULL) CFRetain(name); } /* -------------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------------- */ SCPatchContextList::SCPatchContextList(void) : contexts() { } /* -------------------------------------------------------------------------------- */ SCPatchContextList::~SCPatchContextList(void) { } /* -------------------------------------------------------------------------------- */ SCPatchContextRef SCPatchContextList::NewContext(ProcessSerialNumber *inPSN, SInt32 inPID, OSType inCreator) { SCPatchContextRef zeroResult = { 0 }; SCPatchContextRef result; try { MacPSN macPSN(inPSN); SCPatchContext patchContext(inPSN, inPID, inCreator); SCPatchContextPair newContext(macPSN, patchContext); contexts.insert(newContext); result = *inPSN; } catch(...) { result = zeroResult; } return result; } /* -------------------------------------------------------------------------------- */ SCPatchContext *SCPatchContextList::GetContext(ProcessSerialNumber *inPSN) { SCPatchContextIterator iter; iter = contexts.find(MacPSN(inPSN)); if(iter != contexts.end()) return &(*iter).second; else return NULL; } /* -------------------------------------------------------------------------------- */ SCPatchContext *SCPatchContextList::GetContext(OSType inCreator) { SCPatchContextIterator iter; for(iter = contexts.begin(); iter != contexts.end(); iter++) if(iter->second.creator == inCreator) return &(*iter).second; return NULL; } /* -------------------------------------------------------------------------------- */ void SCPatchContextList::DeleteContext(ProcessSerialNumber *inPSN) { contexts.erase(MacPSN(inPSN)); }