[OT] InternetConfig mappings changes won't stick
[OT] InternetConfig mappings changes won't stick
- Subject: [OT] InternetConfig mappings changes won't stick
- From: Diggory Laycock <email@hidden>
- Date: Fri, 9 Aug 2002 16:37:20 +0100
[OT] InternetConfig mappings changes won't stick
It's off-topic as it's not cocoa, but the IC list seems to be almost
dead (and couldn't help me).
I was hoping someone with experience in IC could help me.
I am trying to alter the mappings preference in Internet Config. I have
Read the Docs many times and think I understand the system.
I have tried to write some sample code that just makes a simple change
to one of the mappings preferences.
The API reports the changes as sucessful (all the calls return noErr)
but the change never makes it into the actual Internet Config settings.
I must be going about it the wrong way, or be making a blindingly
obvious mistake.
This is my basic model for working with the mapping prefs:
>
startIC
>
make a handle
>
set the handle to point to the IC mappings preference (mappings
>
database)
>
>
ICCountMapEntries (Count the number of mappings entries)
>
>
ICGetIndMapEntry (get the mapping entry at index: n from the mappings
>
database)
>
>
display info for that mapping entry
>
alter the entry (specifically the Flags bits)
>
>
set the (now altered) entry back into the mappings database at its
>
original position.
>
>
ICSetPrefHandle (set the handle to the mappings database back into the
>
IC preferences)
>
>
stopIC
>
dispose of the handle
and this is my actual code:
Any Clues?
Diggory Laycock.
...............................
#import "Controller.h"
@implementation Controller
// IB Actions
- (IBAction)go:(id)sender
{
NSLog(@"Go:");
goCount=[mappingNumberTF floatValue];
[self getInfoForEntryAtIndex:goCount andAlter:[alterSwitch state]];
}
- (IBAction)resetIC:(id)sender
{
[self stopIC];
[self startIC];
}
-(void)awakeFromNib
{
NSLog(@"awakeFromNib");
[self startIC];
}
// NSApplication Delegate Method
- (void)applicationWillTerminate:(NSNotification *)aNotification
{
NSLog(@"applicationWillTerminate");
[self stopIC];
}
// IC Methods
-(void)startIC
{
int startErr=ICStart(&theICInstance, 0);
if (startErr==noErr) {
// Get a handle to the mappings DB
mappingsHandle=NewHandle(kICMapFixedLength);
NSLog(@"IC Started");
} else {
NSLog (@"Could not start InternetConfig. (%d)", startErr);
}
}
-(void)stopIC
{
int stopErr=ICStop(theICInstance);
if (stopErr!=noErr) {
NSLog(@"Error calling ICStop: %d", stopErr);
} else {
DisposeHandle(mappingsHandle);
NSLog(@"IC Stopped");
}
}
-(void)getMappingHandle
{
int findPrefErr=ICFindPrefHandle(theICInstance, kICMapping,
&mappingsICAttr ,mappingsHandle);
if (findPrefErr!=noErr) {
NSLog(@"Error: (%d) getting pref handle for Mappings preference:
%d", findPrefErr);
} else {
NSLog(@"got mappingsHandle");
[self countEntries];
}
}
-(void)countEntries
{
int countErr;
long entriesCount;
// Count the number of entries in the mappings DB
countErr=ICCountMapEntries(theICInstance, mappingsHandle,
&entriesCount);
if (countErr!=noErr) {
NSLog (@"Error: (%d) counting map entries: %d", countErr);
} else {
NSLog (@"There are : %d entries in the mappings database.",
entriesCount);
}
}
-(void)getInfoForEntryAtIndex: (int)i andAlter: (BOOL)alter
{
ICMapEntry theMapEntry;
int icErr, icErr3;
long pos=0;
NSLog(@"getInfoForEntryAtIndex: %d", i);
[self getMappingHandle];
icErr3=ICGetIndMapEntry( theICInstance, mappingsHandle, i , &pos ,
&theMapEntry);
if (icErr3!=noErr) {
NSLog(@"ICGetIndMapEntry error: %d", icErr3);
} else {
NSLog(@"entryName: %@",
((NSString*)CFStringCreateWithPascalString(NULL,(ConstStr255Param)&theMapEntry.
entryName, kCFStringEncodingMacRoman)));
NSLog(@"extension: %@",
((NSString*)CFStringCreateWithPascalString(NULL,(ConstStr255Param)&theMapEntry.
extension, kCFStringEncodingMacRoman)));
[self logFlags: theMapEntry.flags];
if (alter) {
// Alter the entry
NSLog(@"altering the entry flags:");
theMapEntry.flags=(theMapEntry.flags |
kICMapNotIncomingMask);
theMapEntry.flags=(theMapEntry.flags |
kICMapNotOutgoingMask);
[self logFlags: theMapEntry.flags];
// Put entry back into the Mappings 'database'
icErr=ICSetMapEntry(theICInstance, mappingsHandle, pos ,
&theMapEntry);
if (noErr==icErr) {
int setErr;
NSLog(@"altered entry replaced into mappings DB. at pos:
%d", pos);
// Then put the DB back into the IC Mapping preference.
setErr=ICSetPrefHandle(theICInstance, kICMapping,
mappingsICAttr, mappingsHandle);
if (noErr==setErr) {
NSLog(@"mappings DB was written back into the IC
preferences.");
}
}
} // if (alter)
}
}
-(void)logFlags:(long)flags
{
NSLog(@"mapping Entry Flags::");
NSLog(@"-------------------");
if ((flags & kICMapBinaryMask))
NSLog(@"BinaryTransfer");
if ((flags & kICMapPostMask))
NSLog(@"PostProcesses");
if ((flags & kICMapResourceForkMask))
NSLog(@"Resource Fork is Significant");
if ((flags & kICMapDataForkMask))
NSLog(@"Data Fork is Significant");
if ((flags & kICMapNotIncomingMask))
NSLog(@"Not Incoming");
if ((flags & kICMapNotOutgoingMask))
NSLog(@"Not Outgoing");
NSLog(@"\n");
}
@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.