Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > editing Internet Config Mappings

editing Internet Config Mappings
Thread Tools
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Aug 12, 2002, 06:44 AM
 
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 where I am going wrong?

...............................

#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,(C onstStr255Param)&theMapEntry.
entryName, kCFStringEncodingMacRoman)));
NSLog(@"extension: %@",

((NSString*)CFStringCreateWithPascalString(NULL,(C onstStr255Param)&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");
}
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:09 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2