void ServiceBrowserCallback (DNSServiceRef sdRef,
                             DNSServiceFlags flags,
                             uint32_t interfaceIndex,
                             DNSServiceErrorType errorCode,
                             const char*                serviceName,
                             const char*                regtype,
                             const char*                replyDomain,
                             void*                      context )
{
    (void)interfaceIndex;
    (void)regtype;
    (void)replyDomain;
    BonjourUserEventsPlugin* plugin = (BonjourUserEventsPlugin*)context;
    NetBrowserInfo* browser = BrowserForSDRef(plugin, sdRef);

    if (!browser) // Missing browser?
    {
        fprintf(stderr, "%s:%s ServiceBrowserCallback: missing browser\n", sPluginIdentifier, __FUNCTION__);
        return;
    }

    if (errorCode != kDNSServiceErr_NoError)
    {
        fprintf(stderr, "%s:%s ServiceBrowserCallback: errcode set %d\n", sPluginIdentifier, __FUNCTION__, errorCode);
        return;
    }

    CFStringRef cfServiceName = CFStringCreateWithCString(NULL, serviceName, kCFStringEncodingUTF8);
    if (cfServiceName == NULL)
    {
        static int msg_count = 0;
        if (msg_count < 1000)
        {
            asl_log(NULL, NULL, ASL_LEVEL_INFO, "%s:%s Can not create CFString for serviceName %s", sPluginIdentifier, __FUNCTION__, serviceName);
            msg_count++;
        }
        return;
    }

    if (flags & kDNSServiceFlagsAdd)
    {
        asl_log(NULL, NULL, ASL_LEVEL_INFO, "%s:%s calling HandleTemporaryEventsForService Add\n", sPluginIdentifier, __FUNCTION__);
        HandleTemporaryEventsForService(plugin, browser, cfServiceName, plugin->_onAddEvents);
    }
    else
    {
        asl_log(NULL, NULL, ASL_LEVEL_INFO, "%s:%s calling HandleTemporaryEventsForService Remove\n", sPluginIdentifier, __FUNCTION__);
        HandleTemporaryEventsForService(plugin, browser, cfServiceName, plugin->_onRemoveEvents);
    }

    CFRelease(cfServiceName);
}
Ejemplo n.º 2
0
void ServiceBrowserCallback (DNSServiceRef				sdRef,
							 DNSServiceFlags            flags,
							 uint32_t                   interfaceIndex,
							 DNSServiceErrorType        errorCode,
							 const char*                serviceName,
							 const char*                regtype,
							 const char*                replyDomain,
							 void*                      context )
{
	(void)interfaceIndex;
	(void)regtype;
	(void)replyDomain;
	BonjourUserEventsPlugin* plugin = (BonjourUserEventsPlugin*)context;
	NetBrowserInfo* browser = BrowserForSDRef(plugin, sdRef);
	
	if (!browser) // Missing browser?
		return;
	
	if (errorCode != kDNSServiceErr_NoError)
		return;
	
	CFStringRef cfServiceName = CFStringCreateWithCString(NULL, serviceName, kCFStringEncodingUTF8);
	
	if (flags & kDNSServiceFlagsAdd)
	{
		HandleTemporaryEventsForService(plugin, browser, cfServiceName, plugin->_onAddEvents);
		HandleStateEventsForService(plugin, browser, cfServiceName, true);
	}
	else 
	{
		HandleTemporaryEventsForService(plugin, browser, cfServiceName, plugin->_onRemoveEvents);
		HandleStateEventsForService(plugin, browser, cfServiceName, false);
	}

	CFRelease(cfServiceName);
}