home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************************\
- CInternetConfig.h
-
- A C++ class for using Internet Config
-
- by Dan Crevier
-
- version 1.0
-
- \***********************************************************************/
-
- #include "CInternetConfig.h"
-
- #ifndef __ICAPI__
- #include "ICAPI.h"
- #endif
-
- #ifndef __COMPONENTS__
- #include <Components.h>
- #endif
-
- /***********************************************************************\
- CInternetConfig - constructor
- If prefFile is NULL, the default preferences are used
- \***********************************************************************/
-
- CInternetConfig::CInternetConfig(OSType applicationSig, FSSpec *prefFile)
- : installed(false), mappings(0)
- {
- ComponentDescription ICDescription = {'PREF', 'ICAp', 0L, 0L, 0L};
- ICError err;
-
- // first, see if IC is installed
- if (CountComponents(&ICDescription))
- {
- if (ICStart(&inst, applicationSig) == noErr)
- {
- if (prefFile == NULL) // use default prefs
- {
- err = ICFindConfigFile(inst, 0, NULL);
- }
- else
- {
- ICDirSpec prefDir;
-
- prefDir.vRefNum = prefFile->vRefNum;
- prefDir.dirID = prefFile->parID;
- err = ICFindUserConfigFile(inst, &prefDir);
- }
- if (err == noErr) // startup was successful
- {
- installed = true;
- }
- else
- {
- // if ICStart was called, but pref couldn't be found, we
- // need to call ICStop
-
- ICStop(inst);
- }
- }
- }
- }
-
- /***********************************************************************\
- ~CInternetConfig - destructor
- \***********************************************************************/
-
- CInternetConfig::~CInternetConfig()
- {
- if (installed)
- {
- ICStop(inst);
- }
- }
-
- /***********************************************************************\
- GetEmailAddress - return the user's email address
- \***********************************************************************/
-
- ICError CInternetConfig::GetEmailAddress(Str255 emailAddress)
- {
- ICAttr junkAttr;
- long size = 256;
-
- if (installed)
- {
- return ICGetPref(inst, kICEmail, &junkAttr, (char *)emailAddress, &size);
- }
- else
- {
- return -1;
- }
- }
-
- /***********************************************************************\
- GetRealName - return the user's real name
- \***********************************************************************/
-
- ICError CInternetConfig::GetRealName(Str255 realName)
- {
- ICAttr junkAttr;
- long size = 256;
-
- if (installed)
- {
- return ICGetPref(inst, kICRealName, &junkAttr, (char *)realName, &size);
- }
- else
- {
- return -1;
- }
- }
-
- /***********************************************************************\
- GetMailHost - return the user's mail (SMTP) host
- \***********************************************************************/
-
- ICError CInternetConfig::GetMailHost(Str255 mailHost)
- {
- ICAttr junkAttr;
- long size = 256;
-
- if (installed)
- {
- return ICGetPref(inst, kICSMTPHost, &junkAttr, (char *)mailHost, &size);
- }
- else
- {
- return -1;
- }
- }
-
- /***********************************************************************\
- DoURL - launch the URL past in
- \***********************************************************************/
-
- ICError CInternetConfig::DoURL(StringPtr theURL)
- {
- long start = 0, end;
-
- if (installed)
- {
- end = theURL[0];
- return ICLaunchURL(inst, "\p", (char *)theURL+1, end, &start, &end);
- }
- else
- {
- return -1;
- }
- }
-
- /***********************************************************************\
- MapFilename - return the map entry for the given filename
- \***********************************************************************/
-
- ICError CInternetConfig::MapFilename(StringPtr name, ICMapEntry *entry)
- {
- if (installed)
- {
- return ICMapFilename(inst, name, entry);
- }
- else
- {
- return -1;
- }
- }
-
- /***********************************************************************\
- MapFilename - return the map entry for the given filename
- takes name as C string
- \***********************************************************************/
-
- ICError CInternetConfig::MapFilename(char *name, ICMapEntry *entry)
- {
- short i;
- Str255 newName;
-
- // convert name to P string
- for(i=0; name[i] && i<255; i++)
- {
- newName[i+1] = name[i];
- }
- newName[0] = i;
-
- return MapFilename(newName, entry);
- }
-
- /***********************************************************************\
- StartMapIteration -- starts iterating over the mappings
- Note: It calls ICBegin() and FinishMapIteration calls
- ICEnd(), so you have can't handle events in between
- \***********************************************************************/
-
- ICError CInternetConfig::StartMapIteration(void)
- {
- ICError err;
- ICAttr attr = 0;
-
- currentPos = 1;
-
- if (!installed) return -1;
-
- err = ICBegin(inst, icReadOnlyPerm);
- if (err != noErr) return err;
-
- err = ICGetPrefHandle(inst, kICMapping, &attr, &mappings);
-
- if (!err)
- {
- err = ICCountMapEntries(inst, mappings, &numMappings);
- }
-
- if (err)
- {
- ICEnd(inst);
- }
-
- return err;
- }
-
- /***********************************************************************\
- NextMapEntry - get the next map entry after calling
- StartMapIteration. Returns false if there are no more entries
- \***********************************************************************/
-
- Boolean CInternetConfig::NextMapEntry(ICMapEntry *entry)
- {
- long pos;
-
- if (!installed || mappings == NULL) return false;
-
- // are we done?
- if (currentPos > numMappings) return false;
-
- ICGetIndMapEntry(inst, mappings, currentPos, &pos, entry);
-
- currentPos++;
-
- return true;
- }
-
- /***********************************************************************\
- FinishMapIteration -- call after doing a map iteration
- \***********************************************************************/
-
- ICError CInternetConfig::FinishMapIteration(void)
- {
- if (!installed || mappings == NULL) return -1;
-
- DisposeHandle(mappings);
- mappings = NULL;
-
- return ICEnd(inst);
- }
-