예제 #1
0
static void DNSSD_API	RegisterRecordReply( DNSServiceRef sdRef _UNUSED, 
								DNSRecordRef recordRef _UNUSED, DNSServiceFlags flags, 
								DNSServiceErrorType errorCode, void *context)
{
	RecordRegistrationRef	*regEnvelope = (RecordRegistrationRef*) context;
	OpContext		*pContext = regEnvelope->Context;

	SetupCallbackState( &pContext->Env);

	if ( pContext->ClientObj != NULL && pContext->Callback != NULL)
	{	
		if ( errorCode == kDNSServiceErr_NoError)
		{	
			(*pContext->Env)->CallVoidMethod( pContext->Env, pContext->ClientObj, pContext->Callback, 
												regEnvelope->RecordObj, flags);
		}
		else
			ReportError( pContext->Env, pContext->ClientObj, pContext->JavaObj, errorCode);
	}

	(*pContext->Env)->DeleteWeakGlobalRef( pContext->Env, regEnvelope->RecordObj);
	free( regEnvelope);

	TeardownCallbackState();
}
예제 #2
0
static void DNSSD_API	ServiceQueryReply( DNSServiceRef sdRef _UNUSED, DNSServiceFlags flags, uint32_t interfaceIndex,
								DNSServiceErrorType errorCode, const char *serviceName,
								uint16_t rrtype, uint16_t rrclass, uint16_t rdlen,
								const void *rdata, uint32_t ttl, void *context)
{
	OpContext		*pContext = (OpContext*) context;
	jbyteArray		rDataObj;
	jbyte			*pBytes;

	SetupCallbackState( &pContext->Env);

	if ( pContext->ClientObj != NULL && pContext->Callback != NULL && 
		 NULL != ( rDataObj = (*pContext->Env)->NewByteArray( pContext->Env, rdlen)))
	{	
		if ( errorCode == kDNSServiceErr_NoError)
		{
			// Initialize rDataObj with contents of rdata
			pBytes = (*pContext->Env)->GetByteArrayElements( pContext->Env, rDataObj, NULL);
			memcpy( pBytes, rdata, rdlen);
			(*pContext->Env)->ReleaseByteArrayElements( pContext->Env, rDataObj, pBytes, JNI_COMMIT);

			jstring jServiceName = (*pContext->Env)->NewStringUTF( pContext->Env, serviceName);
			(*pContext->Env)->CallVoidMethod( pContext->Env, pContext->ClientObj, pContext->Callback,
								pContext->JavaObj, flags, interfaceIndex, jServiceName, rrtype, rrclass, rDataObj, ttl);
			(*pContext->Env)->DeleteLocalRef( pContext->Env, jServiceName);
		}
		else
			ReportError( pContext->Env, pContext->ClientObj, pContext->JavaObj, errorCode);
	}
	TeardownCallbackState();
}
예제 #3
0
static void DNSSD_API	ServiceRegisterReply( DNSServiceRef sdRef _UNUSED, DNSServiceFlags flags,
								DNSServiceErrorType errorCode, const char *serviceName,
								const char *regType, const char *domain, void *context)
{
	OpContext		*pContext = (OpContext*) context;

	SetupCallbackState( &pContext->Env);

	if ( pContext->ClientObj != NULL && pContext->Callback != NULL)
	{
		if ( errorCode == kDNSServiceErr_NoError)
		{
			jstring jServiceName = (*pContext->Env)->NewStringUTF( pContext->Env, serviceName);
			jstring jRegType = (*pContext->Env)->NewStringUTF( pContext->Env, regType);
			jstring jDomain = (*pContext->Env)->NewStringUTF( pContext->Env, domain);

			(*pContext->Env)->CallVoidMethod( pContext->Env, pContext->ClientObj, pContext->Callback,
								pContext->JavaObj, flags,jServiceName, jRegType, jDomain);
			(*pContext->Env)->DeleteLocalRef( pContext->Env, jServiceName);
			(*pContext->Env)->DeleteLocalRef( pContext->Env, jRegType);
			(*pContext->Env)->DeleteLocalRef( pContext->Env, jDomain);
		}
		else
			ReportError( pContext->Env, pContext->ClientObj, pContext->JavaObj, errorCode);
	}
	TeardownCallbackState();
}
예제 #4
0
static void DNSSD_API	ServiceRegisterReply( DNSServiceRef sdRef _UNUSED, DNSServiceFlags flags,
								DNSServiceErrorType errorCode, const char *serviceName,
								const char *regType, const char *domain, void *context)
{
	OpContext		*pContext = (OpContext*) context;

	SetupCallbackState( &pContext->Env);

	if ( pContext->ClientObj != NULL && pContext->Callback != NULL)
	{
		if ( errorCode == kDNSServiceErr_NoError)
		{
			jbyteArray jServiceName = (*pContext->Env)->NewByteArray(pContext->Env, (jsize)strlen(serviceName));
			(*pContext->Env)->SetByteArrayRegion (pContext->Env, jServiceName, 0, (jsize)strlen(serviceName), (const jbyte *) serviceName);
			jbyteArray jRegType = (*pContext->Env)->NewByteArray(pContext->Env, (jsize)strlen(regType));
			(*pContext->Env)->SetByteArrayRegion (pContext->Env, jRegType, 0, (jsize)strlen(regType), (const jbyte *) regType);
			jbyteArray jDomain = (*pContext->Env)->NewByteArray(pContext->Env, (jsize)strlen(domain));
			(*pContext->Env)->SetByteArrayRegion (pContext->Env, jDomain, 0, (jsize)strlen(domain), (const jbyte *) domain);

			(*pContext->Env)->CallVoidMethod( pContext->Env, pContext->ClientObj, pContext->Callback,
								pContext->JavaObj, flags,jServiceName, jRegType, jDomain);
			(*pContext->Env)->DeleteLocalRef( pContext->Env, jServiceName);
			(*pContext->Env)->DeleteLocalRef( pContext->Env, jRegType);
			(*pContext->Env)->DeleteLocalRef( pContext->Env, jDomain);
		}
		else
			ReportError( pContext->Env, pContext->ClientObj, pContext->JavaObj, errorCode);
	}
	TeardownCallbackState();
}
예제 #5
0
static void DNSSD_API	ServiceBrowseReply( DNSServiceRef sdRef _UNUSED, DNSServiceFlags flags, uint32_t interfaceIndex,
								DNSServiceErrorType errorCode, const char *serviceName, const char *regtype,
								const char *replyDomain, void *context)
{
	OpContext		*pContext = (OpContext*) context;

	SetupCallbackState( &pContext->Env);

	if ( pContext->ClientObj != NULL && pContext->Callback != NULL)
	{
		if ( errorCode == kDNSServiceErr_NoError)
		{
			(*pContext->Env)->CallVoidMethod( pContext->Env, pContext->ClientObj,
								( flags & kDNSServiceFlagsAdd) != 0 ? pContext->Callback : pContext->Callback2,
								pContext->JavaObj, flags, interfaceIndex,
								(*pContext->Env)->NewStringUTF( pContext->Env, serviceName),
								(*pContext->Env)->NewStringUTF( pContext->Env, regtype),
								(*pContext->Env)->NewStringUTF( pContext->Env, replyDomain));
		}
		else
			ReportError( pContext->Env, pContext->ClientObj, pContext->JavaObj, errorCode);
	}

	TeardownCallbackState();
}
예제 #6
0
static void DNSSD_API	ServiceResolveReply( DNSServiceRef sdRef _UNUSED, DNSServiceFlags flags, uint32_t interfaceIndex,
								DNSServiceErrorType errorCode, const char *fullname, const char *hosttarget,
								uint16_t port, uint16_t txtLen, const unsigned char *txtRecord, void *context)
{
	OpContext		*pContext = (OpContext*) context;
	jclass			txtCls;
	jmethodID		txtCtor;
	jbyteArray		txtBytes;
	jobject			txtObj;
	jbyte			*pBytes;

	SetupCallbackState( &pContext->Env);

	txtCls = (*pContext->Env)->FindClass( pContext->Env, "com/apple/dnssd/TXTRecord");
	txtCtor = (*pContext->Env)->GetMethodID( pContext->Env, txtCls, "<init>", "([B)V");

	if ( pContext->ClientObj != NULL && pContext->Callback != NULL && txtCtor != NULL &&
		 NULL != ( txtBytes = (*pContext->Env)->NewByteArray( pContext->Env, txtLen)))
	{
		if ( errorCode == kDNSServiceErr_NoError)
		{
			// Since Java ints are defined to be big-endian, we canonicalize 'port' from a 16-bit
			// pattern into a number here.
			port = ( ((unsigned char*) &port)[0] << 8) | ((unsigned char*) &port)[1];
	
			// Initialize txtBytes with contents of txtRecord
			pBytes = (*pContext->Env)->GetByteArrayElements( pContext->Env, txtBytes, NULL);
			memcpy( pBytes, txtRecord, txtLen);
			(*pContext->Env)->ReleaseByteArrayElements( pContext->Env, txtBytes, pBytes, JNI_COMMIT);
	
			// Construct txtObj with txtBytes
			txtObj = (*pContext->Env)->NewObject( pContext->Env, txtCls, txtCtor, txtBytes);
			(*pContext->Env)->DeleteLocalRef( pContext->Env, txtBytes);

			jbyteArray jFullName = (*pContext->Env)->NewByteArray(pContext->Env, (jsize)strlen(fullname));
			(*pContext->Env)->SetByteArrayRegion (pContext->Env, jFullName, 0, (jsize)strlen(fullname), (const jbyte *) fullname);
			jbyteArray jHostTarget = (*pContext->Env)->NewByteArray(pContext->Env, (jsize)strlen(hosttarget));
			(*pContext->Env)->SetByteArrayRegion (pContext->Env, jHostTarget, 0, (jsize)strlen(hosttarget), (const jbyte *) hosttarget);
			(*pContext->Env)->CallVoidMethod( pContext->Env, pContext->ClientObj, pContext->Callback,
								pContext->JavaObj, flags, interfaceIndex, jFullName, jHostTarget, port, txtObj);
			(*pContext->Env)->DeleteLocalRef( pContext->Env, jFullName);
			(*pContext->Env)->DeleteLocalRef( pContext->Env, jHostTarget);
			(*pContext->Env)->DeleteLocalRef( pContext->Env, txtObj);
		}
		else
			ReportError( pContext->Env, pContext->ClientObj, pContext->JavaObj, errorCode);
	}

	TeardownCallbackState();
}
예제 #7
0
static void DNSSD_API	DomainEnumReply( DNSServiceRef sdRef _UNUSED, DNSServiceFlags flags, uint32_t interfaceIndex,
								DNSServiceErrorType errorCode, const char *replyDomain, void *context)
{
	OpContext		*pContext = (OpContext*) context;

	SetupCallbackState( &pContext->Env);

	if ( pContext->ClientObj != NULL && pContext->Callback != NULL)
	{
		if ( errorCode == kDNSServiceErr_NoError)
		{
			jbyteArray jReplyDomain = (*pContext->Env)->NewByteArray(pContext->Env, (jsize)strlen(replyDomain));
			(*pContext->Env)->SetByteArrayRegion (pContext->Env, jReplyDomain, 0, (jsize)strlen(replyDomain), (const jbyte *) replyDomain);
			(*pContext->Env)->CallVoidMethod( pContext->Env, pContext->ClientObj,
								( flags & kDNSServiceFlagsAdd) != 0 ? pContext->Callback : pContext->Callback2,
								pContext->JavaObj, flags, interfaceIndex, jReplyDomain);
			(*pContext->Env)->DeleteLocalRef( pContext->Env, jReplyDomain);
		}
		else
			ReportError( pContext->Env, pContext->ClientObj, pContext->JavaObj, errorCode);
	}
	TeardownCallbackState();
}