Exemplo n.º 1
0
NMBoolean
EndpointHander::ScheduleDelete()
{
	// add endpoint to cleanup list
	OTLIFOEnqueue(gDeadEndpoints, &mLink);
	return true;
}
Exemplo n.º 2
0
// When a new named instance of a service is found, FoundInstance() is called.
// In this sample code we turn around and immediately to a DNSServiceResolve() to resolve that service name
// to find its target host, port, and txtinfo, but a normal browing application would just display the name.
// Resolving every single thing you find can be quite hard on the network, so you shouldn't do this
// in a real application. Defer resolving until the client has picked which instance from the
// long list of services is the one they want to use, and then resolve only that one.
static void FoundInstance(DNSServiceRef client, DNSServiceFlags flags, uint32_t interface, DNSServiceErrorType errorCode,
    const char *replyName, const char *replyType, const char *replyDomain, void *context)
	{
#pragma unused(client, interface, errorCode)
	SearcherServices *services = (SearcherServices *)context;
	linkedServiceInfo *info;

	if (!services) { DebugStr("\pFoundInstance: services is NULL"); return; }
	
	info = (linkedServiceInfo *)OTAllocMem(sizeof(linkedServiceInfo));
	if (!info) { services->lostRecords = true; return; }
	
	info->services = services;
	strcpy(info->name, replyName);
	strcpy(info->type, replyType);
	strcpy(info->domn, replyDomain);
	info->text[0] = 0;
	info->add = (flags & kDNSServiceFlagsAdd) ? true : false;
	info->dom = false;
	
	if (!info->add)	// If TTL == 0 we're deleting a service,
		OTLIFOEnqueue(&services->serviceinfolist, &info->link);
	else								// else we're adding a new service
		DNSServiceResolve(&info->sdRef, 0, 0, info->name, info->type, info->domn, FoundInstanceInfo, info);
	}
static void FoundDomain(mDNS *const m, DNSQuestion *question, const ResourceRecord *const answer, QC_result AddRecord)
	{
	#pragma unused (m)
	#pragma unused (question)
	SearcherServices *services = (SearcherServices *)question->QuestionContext;
	linkedServiceInfo *info;

	debugf("FoundDomain %##s PTR %##s", answer->name->c, answer->rdata->u.name.c);

	if (answer->rrtype != kDNSType_PTR) return;
	if (!services) { debugf("FoundDomain: services is NULL"); return; }
	
	info = (linkedServiceInfo *)OTAllocMem(sizeof(linkedServiceInfo));
	if (!info) { services->lostRecords = true; return; }
	
	info->i.name          = answer->rdata->u.name;
	info->i.InterfaceID   = answer->InterfaceID;
	info->i.ip.type		  = mDNSAddrType_IPv4;
	info->i.ip.ip.v4      = zerov4Addr;
	info->i.port          = zeroIPPort;
	info->add             = AddRecord;
	info->dom             = mDNStrue;
		
	OTLIFOEnqueue(&services->serviceinfolist, &info->link);
	}
// When a new named instance of a service is found, FoundInstance() is called.
// In this sample code we turn around and immediately issue a query to resolve that service name to
// find its address, port, and txtinfo, but a normal browing application would just display the name.
static void FoundInstance(mDNS *const m, DNSQuestion *question, const ResourceRecord *const answer, QC_result AddRecord)
	{
	#pragma unused (question)
	SearcherServices *services = (SearcherServices *)question->QuestionContext;
	linkedServiceInfo *info;

	debugf("FoundInstance %##s PTR %##s", answer->name->c, answer->rdata->u.name.c);

	if (answer->rrtype != kDNSType_PTR) return;
	if (!services) { debugf("FoundInstance: services is NULL"); return; }
	
	info = (linkedServiceInfo *)OTAllocMem(sizeof(linkedServiceInfo));
	if (!info) { services->lostRecords = true; return; }
	
	info->i.name          = answer->rdata->u.name;
	info->i.InterfaceID   = answer->InterfaceID;
	info->i.ip.type		  = mDNSAddrType_IPv4;
	info->i.ip.ip.v4      = zerov4Addr;
	info->i.port          = zeroIPPort;
	info->add             = AddRecord;
	info->dom             = mDNSfalse;
	
	if (!AddRecord)	// If TTL == 0 we're deleting a service,
		OTLIFOEnqueue(&services->serviceinfolist, &info->link);
	else								// else we're adding a new service
		{
		ServiceInfoQuery *q = (ServiceInfoQuery *)OTAllocMem(sizeof(ServiceInfoQuery));
		if (!q) { OTFreeMem(info); services->lostRecords = true; return; }
		mDNS_StartResolveService(m, q, &info->i, FoundInstanceInfo, services);
		}
	}
// When the name, address, port, and txtinfo for a service is found, FoundInstanceInfo()
// enqueues a record for PrintServiceInfo() to print.
// Note, a browsing application would *not* normally need to get all this information --
// all it needs is the name, to display to the user.
// Finding out the address, port, and txtinfo should be deferred to the time that the user
// actually needs to contact the service to use it.
static void FoundInstanceInfo(mDNS *const m, ServiceInfoQuery *query)
	{
	SearcherServices *services = (SearcherServices *)query->ServiceInfoQueryContext;
	linkedServiceInfo *info = (linkedServiceInfo *)(query->info);
	if (query->info->ip.type == mDNSAddrType_IPv4)
		{
		mDNS_StopResolveService(m, query);		// For this test code, one answer is sufficient
		OTLIFOEnqueue(&services->serviceinfolist, &info->link);
		OTFreeMem(query);
		}
	}
Exemplo n.º 6
0
//ECF - added this to be able to keep a nice, full reserve as time goes on. - just call periodically at system-time
NMErr UpkeepOTMemoryReserve(void)
{
	NMErr err = noErr;
	Boolean done = false;
	OTLink *	thisChunk;
	
	if (gReserveInited == false)
		return paramErr;
		
	//if its full, return happy
	if (gReserveChunksAllocated >= gMaxReserveChunks)
		return 0;
		
	do {
		// Only try allocating this chunk if doing so will not 
		// break the minimum free space requirement.

		thisChunk = nil;
		if ( FreeMem() >= (gFreeHeapSpaceRequired + gReserveChunkSize) ) {
			//thisChunk = OTAllocMemInContext(chunkSize, clientContext);
			#if (OP_PLATFORM_MAC_CARBON_FLAG)
				thisChunk = (OTLink*)OTAllocMemInContext(gReserveChunkSize,gOTClientContext);
			#else
				thisChunk = (OTLink*)OTAllocMem(gReserveChunkSize);
			#endif
		}

		if (thisChunk == nil) {
			// Either the next block is going to push us below the free 
			// space requirement, or we tried to get the block and failed.
			if (gReserveChunksAllocated < gMinReserveChunks) {
				// Because weÕre still trying to get our minimum chunks, 
				// this is a fatal error.
				err = memFullErr;
			} else {
				// The block was optional so we donÕt need to error. 
				// We set done and leave the loop.
				done = true;
			}
		} else {
			// We got the block.  Put it into the reserve.  If we have 
			// all of our chunks, set done so that we leave the loop.
			OTLIFOEnqueue(&gMemoryReserve, (OTLink *) thisChunk);
			gReserveChunksAllocated += 1;
			if (gReserveChunksAllocated == gMaxReserveChunks) {
				done = true;
			}
		}
	} while (err == noErr && !done);

	return err;
}
Exemplo n.º 7
0
static void FoundInstanceAddress(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode,
	const char *fullname, uint16_t rrtype, uint16_t rrclass, uint16_t rdlen, const void *rdata, uint32_t ttl, void *context)
	{
	linkedServiceInfo *info = (linkedServiceInfo *)context;
	SearcherServices *services = info->services;
	(void)sdRef;			// Unused
	(void)interfaceIndex;	// Unused
	(void)fullname;			// Unused
	(void)ttl;				// Unused
	if (errorCode == kDNSServiceErr_NoError)
		if (flags & kDNSServiceFlagsAdd)
			if (rrclass == ns_c_in && rrtype == ns_t_a && rdlen == sizeof(info->address))
				{
				memcpy(&info->address, rdata, sizeof(info->address));
				DNSServiceRefDeallocate(info->sdRef);
				OTLIFOEnqueue(&services->serviceinfolist, &info->link);
				}
	}