home *** CD-ROM | disk | FTP | other *** search
- /*
- * AuthNotification.c
- * Copyright © 1992 Apple Computer Inc. All Rights Reserved.
- *
- * Manage the notification queue and update our local copy
- * of the current identity when the user locks and unlocks
- * the local identity. Note, it might be better to fetch
- * the local identity each time it is needed, rather than
- * to try to maintain a shadow copy. Perhaps a better example
- * would be to use the notification callback to enable or
- * disable AOCE-specific menu options.
- *
- * Usage:
- * status = InitNotificationQueue(
- * &userIdentity
- * );
- */
- #include <OCE.h>
- #include <OCEAuthDir.h>
- #include <OCEErrors.h>
- #define TRUE 1
- #define FALSE 0
-
- OSErr InitAuthNotificationQueue(
- LocalIdentity *localIdentityPtr
- );
- OSErr RemoveAuthNotificationQueue(void);
-
- static pascal Boolean MyAuthNotifyProc(
- long clientData,
- AuthLocalIdentityOp callValue,
- AuthLocalIdentityLockAction actionValue,
- LocalIdentity identity
- );
-
- /*
- * Initialize the local identity callback.
- */
- OSErr
- InitAuthNotificationQueue(
- LocalIdentity *userIdentity
- )
- {
- AuthAddToLocalIdentityQueuePB authParamBlock;
- OSErr status;
- #define PB (authParamBlock)
-
- PB.notifyProc = (NotificationProc) MyAuthNotifyProc;
- PB.notifyFlags = (
- kNotifyLockMask
- | kNotifyUnlockMask
- | kNotifyNameChangeMask
- );
- PB.appName = "\pInsert Your Application Name Here";
- PB.clientData = (long) userIdentity;
- status = AuthAddToLocalIdentityQueue(
- (AuthParamBlockPtr) &authParamBlock,
- FALSE
- );
- return (status);
- #undef PB
- }
-
- /*
- * Remove our callback from the local identity queue.
- * Be sure to do this before your application exits:
- * You should trap ExitToShell to make absolutely
- * certain that this function is called.
- */
- OSErr
- RemoveAuthNotificationQueue(void)
- {
- AuthRemoveFromLocalIdentityQueuePB authParamBlock;
- OSErr status;
- #define PB (authParamBlock)
-
- PB.notifyProc = (NotificationProc) MyAuthNotifyProc;
- status = AuthRemoveFromLocalIdentityQueue(
- (AuthParamBlockPtr) &authParamBlock,
- FALSE
- );
- return (status);
- #undef PB
- }
-
- /*
- * Refuse by returning TRUE
- */
- static pascal Boolean
- MyAuthNotifyProc(
- long clientData,
- AuthLocalIdentityOp callValue,
- AuthLocalIdentityLockAction actionValue,
- LocalIdentity identity
- )
- {
- switch (callValue) {
- case kAuthUnlockLocalIdentityOp:
- case kAuthLocalIdentityNameChangeOp:
- /*
- * Store our copy of the local identity.
- * You might, instead, set a flag that
- * causes the application event loop
- * to enable AOCE-specific menu items.
- */
- *((LocalIdentity *) clientData) = identity;
- break;
- default:
- case kAuthLockLocalIdentityOp:
- /*
- * Cancel our copy of the local identity.
- * Here, too, you might prefer setting
- * a flag that causes the application to
- * disable AOCE-specific menu items.
- */
- if (actionValue == kAuthLockWillBeDone)
- *((LocalIdentity *) clientData) = 0;
- break;
- }
- return (FALSE); /* We always accept */
- }
-