media: fix relay-info with Farstream 0.2
[siplcs.git] / src / miranda / miranda-dnsquery.c
bloba29a8a3a6c21c5af0fdfc82b1f35dca6f94de5e1
1 /**
2 * @file miranda-dnsquery.c
4 * pidgin-sipe
6 * Copyright (C) 2010-12 SIPE Project <http://sipe.sourceforge.net/>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <windows.h>
24 #include <win2k.h>
25 #include <stdio.h>
26 #include <windns.h>
28 #include <glib.h>
30 #include "newpluginapi.h"
31 #include "m_protosvc.h"
32 #include "m_protoint.h"
33 #include "m_utils.h"
35 #include "sipe-backend.h"
36 #include "miranda-private.h"
38 typedef DNS_STATUS (WINAPI *DNSQUERYA)(IN PCSTR pszName, IN WORD wType, IN DWORD Options, IN PIP4_ARRAY aipServers OPTIONAL, IN OUT PDNS_RECORD *ppQueryResults OPTIONAL, IN OUT PVOID *pReserved OPTIONAL);
39 typedef void (WINAPI *DNSFREELIST)(IN OUT PDNS_RECORD pRecordList, IN DNS_FREE_TYPE FreeType);
41 typedef struct srv_reply_t {
42 char *host;
43 int port;
44 } srv_reply;
46 static srv_reply* srv_lookup(WORD wType,
47 const gchar* service,
48 const gchar* protocol,
49 const gchar* domain )
51 srv_reply *res = NULL;
52 HINSTANCE hDnsapi = LoadLibraryA( "dnsapi.dll" );
53 DNSQUERYA pDnsQuery;
54 DNSFREELIST pDnsRecordListFree;
55 gchar temp[256];
56 DNS_RECORD *results = NULL;
57 DNS_STATUS status;
59 if ( hDnsapi == NULL )
60 return res;
62 pDnsQuery = (DNSQUERYA)GetProcAddress(hDnsapi, "DnsQuery_A");
63 pDnsRecordListFree = (DNSFREELIST)GetProcAddress(hDnsapi, "DnsRecordListFree");
64 if ( pDnsQuery == NULL ) {
65 //dnsapi.dll is not the needed dnsapi ;)
66 FreeLibrary( hDnsapi );
67 return res;
70 mir_snprintf( temp, SIZEOF(temp), "_%s._%s.%s", service, protocol, domain );
72 status = pDnsQuery(temp, DNS_TYPE_SRV, DNS_QUERY_STANDARD, NULL, &results, NULL);
73 if (FAILED(status)||!results || results[0].Data.Srv.pNameTarget == 0||results[0].wType != DNS_TYPE_SRV) {
74 FreeLibrary(hDnsapi);
75 return res;
78 res = g_new0(srv_reply,1);
79 res->host = g_strdup((const gchar*)results[0].Data.Srv.pNameTarget);
80 res->port = (int)results[0].Data.Srv.wPort;
82 pDnsRecordListFree(results, DnsFreeRecordList);
83 FreeLibrary(hDnsapi);
84 return res;
88 struct sipe_dns_query *sipe_backend_dns_query_a(struct sipe_core_public *sipe_public,
89 const gchar *hostname,
90 guint port,
91 sipe_dns_resolved_cb callback,
92 gpointer data)
94 srv_reply* sr = srv_lookup( DNS_TYPE_A, "protocol", "transport", "domain" );
95 SIPE_DEBUG_INFO("Type A lookup for host <%s> port <%d>", hostname, port);
97 if (sr) {
98 callback( data, sr->host, sr->port);
100 g_free(sr->host);
101 g_free(sr);
102 } else {
103 callback( data, NULL, 0);
106 return NULL;
109 struct sipe_dns_query *sipe_backend_dns_query_srv(struct sipe_core_public *sipe_public,
110 const gchar *protocol,
111 const gchar *transport,
112 const gchar *domain,
113 sipe_dns_resolved_cb callback,
114 gpointer data)
116 srv_reply* sr = srv_lookup( DNS_TYPE_SRV, protocol, transport, domain );
118 SIPE_DEBUG_INFO("Type SRV lookup for proto <%s> transport <%s> domain <%s>",
119 protocol, transport, domain);
121 if (sr) {
122 callback( data, sr->host, sr->port);
124 g_free(sr->host);
125 g_free(sr);
126 } else {
127 callback( data, NULL, 0);
130 return NULL;
133 void sipe_backend_dns_query_cancel(struct sipe_dns_query *query)
135 _NIF();
139 Local Variables:
140 mode: c
141 c-file-style: "bsd"
142 indent-tabs-mode: t
143 tab-width: 8
144 End: