]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSMacOS9/mDNSLibrary.c
mDNSResponder-212.1.tar.gz
[apple/mdnsresponder.git] / mDNSMacOS9 / mDNSLibrary.c
1 /* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16
17 Change History (most recent first):
18
19 $Log: mDNSLibrary.c,v $
20 Revision 1.4 2006/08/14 23:24:29 cheshire
21 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
22
23 Revision 1.3 2004/12/16 20:49:35 cheshire
24 <rdar://problem/3324626> Cache memory management improvements
25
26 Revision 1.2 2004/09/17 01:08:50 cheshire
27 Renamed mDNSClientAPI.h to mDNSEmbeddedAPI.h
28 The name "mDNSClientAPI.h" is misleading to new developers looking at this code. The interfaces
29 declared in that file are ONLY appropriate to single-address-space embedded applications.
30 For clients on general-purpose computers, the interfaces defined in dns_sd.h should be used.
31
32 Revision 1.1 2004/03/12 21:30:26 cheshire
33 Build a System-Context Shared Library from mDNSCore, for the benefit of developers
34 like Muse Research who want to be able to use mDNS/DNS-SD from GPL-licensed code.
35
36 */
37
38 // Define the required CFM Shared Library entry and exit points
39 #include <CodeFragments.h>
40 #include "mDNSEmbeddedAPI.h" // Defines the interface to the client layer above
41 #include "mDNSMacOS9.h" // Defines the specific types needed to run mDNS on this platform
42
43 mDNS mDNSStorage;
44 static mDNS_PlatformSupport PlatformSupportStorage;
45 // Start off with a default cache of 16K (about 100 records)
46 #define RR_CACHE_SIZE ((16*1024) / sizeof(CacheRecord))
47 static CacheEntity rrcachestorage[RR_CACHE_SIZE];
48
49 mDNSlocal void mDNS_StatusCallback(mDNS *const m, mStatus result)
50 {
51 if (result == mStatus_GrowCache)
52 {
53 // Allocate another chunk of cache storage
54 CacheEntity *storage = OTAllocMem(sizeof(CacheEntity) * RR_CACHE_SIZE);
55 if (storage) mDNS_GrowCache(m, storage, RR_CACHE_SIZE);
56 }
57 }
58
59 extern pascal OSErr mDNS_CFMInit(const CFragInitBlock *theInitBlock);
60 pascal OSErr mDNS_CFMInit(const CFragInitBlock *theInitBlock)
61 {
62 extern pascal OSErr __initialize(const CFragInitBlock *theInitBlock);
63 __initialize(theInitBlock); // MUST do this first!
64 {
65 mStatus err;
66 THz oldZone = GetZone();
67 SetZone(SystemZone());
68 LogMsg("mDNS/DNS-SD with Macsbug breaks -- do not ship this version to customers");
69 err = mDNS_Init(&mDNSStorage, &PlatformSupportStorage, rrcachestorage, RR_CACHE_SIZE,
70 mDNS_Init_AdvertiseLocalAddresses, mDNS_StatusCallback, mDNS_Init_NoInitCallbackContext);
71 SetZone(oldZone);
72 return((OSErr)err);
73 }
74 }
75
76 extern void mDNS_CFMTerm(void);
77 void mDNS_CFMTerm(void)
78 {
79 extern pascal void __terminate(void);
80 LogMsg("mDNS_CFMTerm");
81 mDNS_Close(&mDNSStorage);
82 __terminate();
83 }