diff --git a/lib/gibber/gibber-resolver.c b/lib/gibber/gibber-resolver.c index 973ef18..fadcc5a 100644 --- a/lib/gibber/gibber-resolver.c +++ b/lib/gibber/gibber-resolver.c @@ -655,6 +655,8 @@ gibber_resolver_nameinfo_result (GibberResolver *resolver, #define ANSWER_BUFSIZE 10240 + +#ifndef G_OS_WIN32 GList * gibber_resolver_res_query_to_list (guchar *answer, int length) { @@ -710,6 +712,39 @@ failed: gibber_resolver_srv_list_free (list); return NULL; } +#else +GList * +gibber_resolver_res_query_to_list (PDNS_RECORD answer) +{ + GList *list = NULL; + char name[256]; + guint16 port; + guint16 priority; + guint16 weight; + PDNS_RECORD tmp; + errno_t strcpy_error; + rsize_t name_buffer_size = 256; + + for (tmp = answer; tmp != NULL; tmp = tmp->pNext) + { + DNS_SRV_DATA * data; + if (tmp->wType != DNS_TYPE_SRV) + continue; + + strcpy_error = strcpy_s(name, name_buffer_size, tmp->pName); + + if(strcpy_error != 0) // ignore result in case of errors + continue; + + port = tmp->Data.SRV.wPort; + priority = tmp->Data.SRV.wPriority; + weight = tmp->Data.SRV.wWeight; + + list = g_list_prepend (list, gibber_resolver_srv_record_new (name, port, priority, weight)); + } + return list; +} +#endif GError * gibber_resolver_gai_error_to_g_error (int error) @@ -733,11 +768,14 @@ gibber_resolver_gai_error_to_g_error (int error) break; case EAI_MEMORY: +#ifndef G_OS_WIN32: case EAI_OVERFLOW: +#endif code = GIBBER_RESOLVER_ERROR_MEMORY; break; - +#ifndef G_OS_WIN32: case EAI_SYSTEM: +#endif default: code = GIBBER_RESOLVER_ERROR_UNKNOWN; } @@ -786,6 +824,11 @@ resolver_resolv_srv (GibberResolver *resolver, const char *service, GibberResolverServiceType type) { +#ifdef G_OS_WIN32 + DNS_STATUS dns_status; + PDNS_RECORD dns_record; +#endif + gchar *srv_str; int ret; GList *entries = NULL; @@ -795,6 +838,8 @@ resolver_resolv_srv (GibberResolver *resolver, srv_str = g_strdup_printf ("_%s._%s.%s", service, type == GIBBER_RESOLVER_SERVICE_TYPE_TCP ? "tcp" : "udp", service_name); +#ifndef G_OS_WIN32 + ret = res_query (srv_str, C_IN, T_SRV, answer, ANSWER_BUFSIZE); if (ret < 0) @@ -806,6 +851,22 @@ resolver_resolv_srv (GibberResolver *resolver, error = g_error_new (GIBBER_RESOLVER_ERROR, GIBBER_RESOLVER_ERROR_RESOLVE_FAILURE, "Invalid reply received"); } +#else + dns_status = DnsQuery_UTF8(srv_str, DNS_TYPE_SRV, DNS_QUERY_BYPASS_CACHE, NULL, &dns_record, NULL); + if (dns_status != NO_ERROR) + { + error = gibber_resolver_h_error_to_g_error (dns_status); + } + else + { + // convert dns_record list to GList entries + entries = gibber_resolver_res_query_to_list (dns_record); + if (entries == NULL) + error = g_error_new (GIBBER_RESOLVER_ERROR, + GIBBER_RESOLVER_ERROR_RESOLVE_FAILURE, + "Invalid reply received"); + } +#endif gibber_resolver_srv_result (resolver, id, entries, error); diff --git a/lib/gibber/gibber-sockets-win32.h b/lib/gibber/gibber-sockets-win32.h index d35e3cb..6dd1b82 100644 --- a/lib/gibber/gibber-sockets-win32.h +++ b/lib/gibber/gibber-sockets-win32.h @@ -24,6 +24,13 @@ #include #include #include +#include /* Winsock makes some inappropriately-namespaced definitions */ #undef ERROR #undef interface + +// Sticking these here untill someone invents better place or other fix for them +#ifdef G_OS_WIN32 +typedef unsigned short u_int16_t; +typedef unsigned int u_int32_t; +#endif