Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from objective-see:master #3

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions LuLu/App/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,22 @@ -(void)preferencesChanged:(NSDictionary*)preferences
return;
}

//menu handler for rules
-(IBAction)rulesMenuHandler:(id)sender {

switch(((NSMenuItem*)sender).tag)
{
case MENU_IMPORT_RULES:
case MENU_EXPORT_RULES:
case MENU_CLEANUP_RULES:

default:
return;
}

return;
}

//close window handler
// close rules || pref window
-(IBAction)closeWindow:(id)sender
Expand Down
26 changes: 26 additions & 0 deletions LuLu/App/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@
</items>
</menu>
</menuItem>
<menuItem title="Rules" id="rZ2-dU-Sks">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Rules" systemMenu="apple" id="F6a-9V-HHo">
<items>
<menuItem title="Import..." tag="1" id="KcY-Hb-SMi" userLabel="Import">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="rulesMenuHandler:" target="Voe-Tx-rLC" id="q3G-v0-dR7"/>
</connections>
</menuItem>
<menuItem title="Export..." tag="2" id="RRJ-ZN-K2Q" userLabel="Export">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="rulesMenuHandler:" target="Voe-Tx-rLC" id="9sL-Mh-74f"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="t8R-1v-1JD"/>
<menuItem title="Cleanup" tag="3" id="Txf-8U-czQ">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="rulesMenuHandler:" target="Voe-Tx-rLC" id="3uz-F1-eEm"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
</items>
<point key="canvasLocation" x="-59" y="-473"/>
</menu>
Expand Down
10 changes: 5 additions & 5 deletions LuLu/App/Rules.xib
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
<tableColumns>
<tableColumn width="804" minWidth="800" maxWidth="3.4028234663852886e+38" id="Iaf-If-UX3" userLabel="Main">
<tableColumn width="800" minWidth="800" maxWidth="3.4028234663852886e+38" id="Iaf-If-UX3" userLabel="Main">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left">
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
Expand All @@ -61,7 +61,7 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES"/>
<prototypeCellViews>
<tableCellView identifier="processCell" id="hYC-a4-Gp3" userLabel="Process">
<rect key="frame" x="1" y="1" width="809" height="50"/>
<rect key="frame" x="1" y="1" width="805" height="50"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" tag="100" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bkx-JF-q5i">
Expand Down Expand Up @@ -94,7 +94,7 @@
</connections>
</tableCellView>
<tableCellView identifier="simpleCell" id="Tec-Zl-6cm" userLabel="Connection">
<rect key="frame" x="1" y="53" width="809" height="50"/>
<rect key="frame" x="1" y="53" width="805" height="50"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="jpF-QT-jfh">
Expand Down Expand Up @@ -126,7 +126,7 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES"/>
<prototypeCellViews>
<tableCellView identifier="ruleCell" id="5sm-If-Eqg" customClass="RuleRowCell">
<rect key="frame" x="813" y="1" width="204" height="54"/>
<rect key="frame" x="809" y="1" width="204" height="54"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button verticalHuggingPriority="750" fixedFrame="YES" tag="110" translatesAutoresizingMaskIntoConstraints="NO" id="ZYK-WR-Jeh">
Expand Down Expand Up @@ -171,7 +171,7 @@
</subviews>
</clipView>
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="djS-lX-Nkf">
<rect key="frame" x="1" y="512" width="1014" height="16"/>
<rect key="frame" x="1" y="488" width="1019" height="16"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="Ud6-Ad-xqt">
Expand Down
2 changes: 1 addition & 1 deletion LuLu/App/Update.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ -(NSString*)getLatestVersion
@try
{
//convert
productsVersionDictionary = [NSJSONSerialization JSONObjectWithData:productsVersionData options:0 error:nil];
productsVersionDictionary = [NSJSONSerialization JSONObjectWithData:productsVersionData options:kNilOptions error:nil];
if(nil == productsVersionDictionary)
{
//bail
Expand Down
10 changes: 9 additions & 1 deletion LuLu/Extension/Rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,15 @@
//delete rule
-(BOOL)delete:(NSString*)key rule:(NSString*)uuid;

@end
//import rules
-(BOOL)import:(NSString*)path;

//export rules
-(BOOL)export:(NSString*)path;

//cleanup rules
-(void)cleanup;

@end

#endif /* Rules_h */
147 changes: 134 additions & 13 deletions LuLu/Extension/Rules.m
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ -(BOOL)upgrade:(NSDictionary*)rules_v1
}

//save
if(YES != [self save])
if(YES != [self save:nil format:RULES_FORMAT_SERIALIZED])
{
//err msg
os_log_error(logHandle, "ERROR: failed to save v1 -> v2 rules");
Expand Down Expand Up @@ -364,7 +364,7 @@ -(BOOL)generateDefaultRules
}

//save
if(YES != [self save])
if(YES != [self save:nil format:RULES_FORMAT_SERIALIZED])
{
//err msg
os_log_error(logHandle, "ERROR: failed to save (generated) rules");
Expand Down Expand Up @@ -421,7 +421,7 @@ -(BOOL)add:(Rule*)rule save:(BOOL)save
if(YES == save)
{
//save
if(YES != [self save])
if(YES != [self save:nil format:RULES_FORMAT_SERIALIZED])
{
//err msg
os_log_error(logHandle, "ERROR: failed to save rules");
Expand Down Expand Up @@ -921,7 +921,7 @@ -(BOOL)delete:(NSString*)key rule:(NSString*)uuid
bail:

//always save to disk
if(YES != [self save])
if(YES != [self save:nil format:RULES_FORMAT_SERIALIZED])
{
//err msg
os_log_error(logHandle, "ERROR: failed to save (updated) rules");
Expand All @@ -936,7 +936,7 @@ -(BOOL)delete:(NSString*)key rule:(NSString*)uuid
//save to disk
// note: temporary rules are ignored
// note: temporary rules for (now) dead processes are removed
-(BOOL)save
-(BOOL)save:path format:(NSUInteger)format
{
//result
BOOL result = NO;
Expand All @@ -950,11 +950,21 @@ -(BOOL)save
//(non-temp) rules
NSMutableDictionary* persistentRules = nil;

//archived rules
NSData* archivedRules = nil;
//formatted rules
NSData* formattedRules = nil;

//init path to rule's file
rulesFile = [INSTALL_DIRECTORY stringByAppendingPathComponent:RULES_FILE];
if(nil == path)
{
//init
rulesFile = [INSTALL_DIRECTORY stringByAppendingPathComponent:RULES_FILE];
}

//otherwise, used specified path (e.g. for an export)
else
{
rulesFile = path;
}

//init persistent rules
persistentRules = [NSMutableDictionary dictionary];
Expand Down Expand Up @@ -1032,19 +1042,62 @@ -(BOOL)save
}
}

//archive persistent rules
archivedRules = [NSKeyedArchiver archivedDataWithRootObject:persistentRules requiringSecureCoding:YES error:&error];
if(nil == archivedRules)
//serialize?
if(format == RULES_FORMAT_SERIALIZED)
{
//archive persistent rules
formattedRules = [NSKeyedArchiver archivedDataWithRootObject:persistentRules requiringSecureCoding:YES error:&error];
if(nil == formattedRules)
{
//err msg
os_log_error(logHandle, "ERROR: failed to serialize rules: %{public}@", error);

//bail
goto bail;
}
}
//otherwise
// ...to JSON
else if(format == RULES_FORMAT_JSON)
{
//convert JSON to dictionary
// wrap as may throw exception
@try
{
//convert
formattedRules = [NSJSONSerialization dataWithJSONObject:persistentRules options:kNilOptions error:&error];
if(nil == formattedRules)
{
//err msg
os_log_error(logHandle, "ERROR: failed to JSON'ify rules: %{public}@", error);

//bail
goto bail;
}
}
//catch
@catch(NSException* exception)
{
//err msg
os_log_error(logHandle, "ERROR: failed to JSON'ify rules: %{public}@", error);

//bail
goto bail;
}
}

//invalid format
else
{
//err msg
os_log_error(logHandle, "ERROR: failed to archive rules: %{public}@", error);
os_log_error(logHandle, "ERROR: %lu is an invalid rules format", (unsigned long)format);

//bail
goto bail;
}

//write out persistent rules
if(YES != [archivedRules writeToFile:rulesFile atomically:YES])
if(YES != [formattedRules writeToFile:rulesFile atomically:YES])
{
//err msg
os_log_error(logHandle, "ERROR: failed to save archived rules to: %{public}@", rulesFile);
Expand All @@ -1063,4 +1116,72 @@ -(BOOL)save
return result;
}

//import rules
//TODO: in client check permissions of file
-(BOOL)import:(NSString*)path
{
//flag
BOOL imported = NO;

//error
NSError* error = nil;

//rules data
NSData* data = nil;

//import rules
NSMutableDictionary* importedRules = nil;

//load from user-specified file
data = [NSData dataWithContentsOfFile:path options:NSDataReadingMappedIfSafe error:&error];
if(nil == data)
{
goto bail;
}

//deserialize
@try
{
//convert
importedRules = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
if(nil == importedRules)
{
//bail
goto bail;
}

//replace all existing rules
@synchronized (self) {

//replace
self.rules = importedRules;
}
}
@catch(NSException* exception)
{
//bail
goto bail;
}

bail:

return imported;
}

//export rules
//TODO: in client check permissions of file
-(BOOL)export:(NSString*)path
{
return [self save:path format:RULES_FORMAT_JSON];
}

//cleanup
// ...remove any rules that don't match a on-disk
-(void)cleanup
{
//TODO:

return;
}

@end
36 changes: 34 additions & 2 deletions LuLu/Extension/XPCDaemon.m
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,43 @@ -(void)deleteRule:(NSString*)key rule:(NSString*)uuid
return;
}

//import rules
-(void)importRules:(NSString*)path result:(void (^)(BOOL))reply
{
//dbg msg
os_log_debug(logHandle, "XPC request: '%s'", __PRETTY_FUNCTION__);

//import rules
reply([rules import:path]);

return;
}

//export rules
-(void)exportRules:(NSString*)path result:(void (^)(BOOL))reply
{
//dbg msg
os_log_debug(logHandle, "XPC request: '%s'", __PRETTY_FUNCTION__);

//import rules
reply([rules export:path]);

return;
}

//cleanup rules
-(void)cleanupRules
{
//dbg msg
os_log_debug(logHandle, "XPC request: '%s'", __PRETTY_FUNCTION__);

return;
}

//uninstall
-(void)uninstall:(void (^)(BOOL))reply
{
//flab
//flag
BOOL uninstalled = NO;

//directory
Expand Down Expand Up @@ -234,5 +267,4 @@ -(void)uninstall:(void (^)(BOOL))reply
return;
}


@end
Loading