/* * Copyright (c) 2023 Valtteri Koskivuori * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* Prefs storage for MacNTP. The prefs are just two STR resources with the following IDs: 128 - NTP server URL as a Pascal string 129 - UTC offset as a Pascal String */ #include #include "prefs.h" // Yoink from dnr.c void GetSystemFolder(short *vRefNumP, long *dirIDP); short SearchForVKOS(short vRefNum, long dirID); short OpenMacNTP_RF(void); short SearchForVKOS(short vRefNum, long dirID) { HParamBlockRec fi; Str255 filename; short refnum; fi.fileParam.ioCompletion = nil; fi.fileParam.ioNamePtr = filename; fi.fileParam.ioVRefNum = vRefNum; fi.fileParam.ioDirID = dirID; fi.fileParam.ioFDirIndex = 1; while (PBHGetFInfo(&fi, false) == noErr) { /* scan system folder for driver resource files of specific type & creator */ //TODO: Maybe also check for xNIT? Is it a problem if this file is in use? if ((fi.fileParam.ioFlFndrInfo.fdType == 'INIT' || fi.fileParam.ioFlFndrInfo.fdType == 'xNIT') && fi.fileParam.ioFlFndrInfo.fdCreator == 'VKOS') { /* found the MacNTP file? */ refnum = HOpenResFile(vRefNum, dirID, filename, fsRdPerm); return refnum; } /* check next file in system folder */ fi.fileParam.ioFDirIndex++; fi.fileParam.ioDirID = dirID; /* PBHGetFInfo() clobbers ioDirID */ } return -1; } short OpenMacNTP_RF(void) { short refnum; short vRefNum; long dirID; vRefNum = 0; dirID = 0; GetSystemFolder(&vRefNum, &dirID); // VKOS is the creator ID for MacNTP. // It used to be that Apple wanted developers to officially register // these creator IDs before using them in production, but I doubt they // accept registrations these days! refnum = SearchForVKOS(vRefNum, dirID); if (refnum = -1) { return -1; } return refnum; } /* It might be that these will only be useful for the cdev, I'm having a hard time trying to get the INIT to look in the system folder. I think it makes sense that only the cdev cares about these to update the rsrc file on disk, and we just load it while we load everything else in the init, and keep those in the system heap. It will only ever query the time on boot anyway. */ // This should hopefully maybe maybe return a C string of the URL maybe // Written at 1AM on a wednesday though, so buyer beware. short get_url_param(Str255 url) { StringHandle url_handle; short refnum; refnum = OpenMacNTP_RF(); if (refnum == -1) { return -1; } url_handle = GetString(128); HLock(url_handle); if (url_handle == NULL) { return -1; } BlockMove(url_handle, &url, 1 + *(char *)(url_handle)); //sus HUnlock(url_handle); DisposHandle(url_handle); // Needed?? CloseResFile(refnum); PtoCstr(url); return 0; } short set_url_param(Str255 url) { //TODO return -1; } short get_utc_param(Str255 url) { //TODO return -1; } short set_utc_param(Str255 url) { //TODO return -1; }