Made DNS resolver work with libc versions that don't define __NAMESER.

Initialize the resolver in JS DNS and return null if initialization fails.


git-svn-id: http://yate.null.ro/svn/yate/trunk@6422 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2020-08-27 09:54:46 +00:00
parent 614ace3007
commit 2ca7a18ac8
2 changed files with 12 additions and 8 deletions

View File

@ -103,7 +103,7 @@ static int printResult(int type, int code, const char* dname, ObjList& result, S
error = &dummy;
#ifdef _WINDOWS
Thread::errorString(dummy,code);
#elif defined(__NAMESER)
#elif defined(__RES)
dummy = hstrerror(code);
#endif
}
@ -376,7 +376,7 @@ bool Resolver::available(Type t)
#endif
}
return true;
#elif defined(__NAMESER)
#elif defined(__RES)
return true;
#endif
return false;
@ -389,7 +389,7 @@ bool Resolver::init(int timeout, int retries)
return false;
#ifdef _WINDOWS
return true;
#elif defined(__NAMESER)
#elif defined(__RES)
if ((_res.options & RES_INIT) == 0) {
// need to initialize in current thread
if (res_init())
@ -446,7 +446,7 @@ int Resolver::srvQuery(const char* dname, ObjList& result, String* error)
Thread::errorString(*error,code);
if (srv)
::DnsRecordListFree(srv,DnsFreeRecordList);
#elif defined(__NAMESER)
#elif defined(__RES)
unsigned char buf[512];
int r = res_query(dname,ns_c_in,ns_t_srv,buf,sizeof(buf));
if (r <= 0 || r > (int)sizeof(buf)) {
@ -557,7 +557,7 @@ int Resolver::naptrQuery(const char* dname, ObjList& result, String* error)
Thread::errorString(*error,code);
if (naptr)
::DnsRecordListFree(naptr,DnsFreeRecordList);
#elif defined(__NAMESER)
#elif defined(__RES)
unsigned char buf[2048];
int r,q,a;
unsigned char *p, *e;
@ -642,7 +642,7 @@ int Resolver::a4Query(const char* dname, ObjList& result, String* error)
Thread::errorString(*error,code);
if (adr)
::DnsRecordListFree(adr,DnsFreeRecordList);
#elif defined(__NAMESER)
#elif defined(__RES)
unsigned char buf[512];
int r = res_query(dname,ns_c_in,ns_t_a,buf,sizeof(buf));
if (r <= 0 || r > (int)sizeof(buf)) {
@ -718,7 +718,7 @@ int Resolver::a6Query(const char* dname, ObjList& result, String* error)
Thread::errorString(*error,code);
if (adr)
::DnsRecordListFree(adr,DnsFreeRecordList);
#elif defined(__NAMESER)
#elif defined(__RES)
unsigned char buf[512];
int r = res_query(dname,ns_c_in,ns_t_aaaa,buf,sizeof(buf));
if (r <= 0 || r > (int)sizeof(buf)) {
@ -793,7 +793,7 @@ int Resolver::txtQuery(const char* dname, ObjList& result, String* error)
Thread::errorString(*error,code);
if (adr)
::DnsRecordListFree(adr,DnsFreeRecordList);
#elif defined(__NAMESER)
#elif defined(__RES)
unsigned char buf[512];
int r = res_query(dname,ns_c_in,ns_t_txt,buf,sizeof(buf));
if (r <= 0 || r > (int)sizeof(buf)) {

View File

@ -4636,6 +4636,10 @@ bool JsDNS::runNative(ObjList& stack, const ExpOperation& oper, GenObject* conte
void JsDNS::runQuery(ObjList& stack, const String& name, Resolver::Type type, GenObject* context)
{
if (!Resolver::init()) {
ExpEvaluator::pushOne(stack,JsParser::nullClone());
return;
}
JsArray* jsa = 0;
ObjList res;
if (Resolver::query(type,name,res) == 0) {