ext/dnssd/errors.c in dnssd-1.2 vs ext/dnssd/errors.c in dnssd-1.3
- old
+ new
@@ -1,7 +1,6 @@
#include "dnssd.h"
-#include <assert.h>
VALUE eDNSSDError;
static VALUE eDNSSDUnknownError;
#define DNSSD_ERROR_START (DNSServiceErrorType)(-65792) /* 0xFFFE FF00 */
@@ -9,12 +8,17 @@
static VALUE dnssd_errors[DNSSD_ERROR_END - DNSSD_ERROR_START];
static void
dnssd_errors_store(VALUE error, DNSServiceErrorType err) {
- assert(DNSSD_ERROR_START <= err && err <= DNSSD_ERROR_END);
- dnssd_errors[err - DNSSD_ERROR_START] = error;
+ if (DNSSD_ERROR_START <= err && err <= DNSSD_ERROR_END) {
+ dnssd_errors[err - DNSSD_ERROR_START] = error;
+ } else {
+ rb_raise(eDNSSDError,
+ "invalid error number %d (expected between %d and %d)",
+ err, DNSSD_ERROR_START, DNSSD_ERROR_END);
+ }
}
void
dnssd_check_error_code(DNSServiceErrorType err) {
if (err) {
@@ -105,10 +109,11 @@
dnssd_errors_store(error_class, kDNSServiceErr_DoubleNAT);
error_class = rb_define_class_under(mDNSSD, "BadTimeError", eDNSSDError);
dnssd_errors_store(error_class, kDNSServiceErr_BadTime);
+#ifdef HAVE_KDNSSERVICEERR_BADSIG
error_class = rb_define_class_under(mDNSSD, "BadSigError", eDNSSDError);
dnssd_errors_store(error_class, kDNSServiceErr_BadSig);
error_class = rb_define_class_under(mDNSSD, "BadKeyError", eDNSSDError);
dnssd_errors_store(error_class, kDNSServiceErr_BadKey);
@@ -122,6 +127,7 @@
error_class = rb_define_class_under(mDNSSD, "NATPortMappingUnsupported", eDNSSDError);
dnssd_errors_store(error_class, kDNSServiceErr_NATPortMappingUnsupported);
error_class = rb_define_class_under(mDNSSD, "NATPortMappingDisabled", eDNSSDError);
dnssd_errors_store(error_class, kDNSServiceErr_NATPortMappingDisabled);
+#endif
}