Allow passing of service and protocol for DNS SRV requests

This commit is contained in:
Torsten Dreyer
2016-11-09 13:30:58 +01:00
parent 27fff3b72a
commit e1fb13bed8
2 changed files with 15 additions and 2 deletions

View File

@@ -75,6 +75,14 @@ SRVRequest::SRVRequest( const std::string & dn ) :
_type = DNS_T_SRV;
}
SRVRequest::SRVRequest( const std::string & dn, const string & service, const string & protocol ) :
Request(dn),
_service(service),
_protocol(protocol)
{
_type = DNS_T_SRV;
}
static bool sortSRV( const SRVRequest::SRV_ptr a, const SRVRequest::SRV_ptr b )
{
if( a->priority > b->priority ) return false;
@@ -102,10 +110,11 @@ static void dnscbSRV(struct dns_ctx *ctx, struct dns_rr_srv *result, void *data)
}
r->setComplete();
}
void SRVRequest::submit()
{
// protocol and service an already encoded in DN so pass in NULL for both
if (!dns_submit_srv(NULL, getDn().c_str(), NULL, NULL, 0, dnscbSRV, this )) {
// if service is defined, pass service and protocol
if (!dns_submit_srv(NULL, getDn().c_str(), _service.empty() ? NULL : _service.c_str(), _service.empty() ? NULL : _protocol.c_str(), 0, dnscbSRV, this )) {
SG_LOG(SG_IO, SG_ALERT, "Can't submit dns request for " << getDn());
return;
}

View File

@@ -90,6 +90,7 @@ class SRVRequest : public Request
{
public:
SRVRequest( const std::string & dn );
SRVRequest( const std::string & dn, const string & service, const string & protocol );
virtual void submit();
struct SRV : SGReferenced {
@@ -101,6 +102,9 @@ public:
typedef SGSharedPtr<SRV> SRV_ptr;
typedef std::vector<SRV_ptr> SRV_list;
SRV_list entries;
private:
std::string _service;
std::string _protocol;
};
class TXTRequest : public Request