Don't attempt to DNS resolve empty, null or undefined names.
Added helper functions to check if an operator is missing or empty. git-svn-id: http://voip.null.ro/svn/yate@6266 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
25ac4c9458
commit
018a1a65a5
|
@ -3689,4 +3689,11 @@ bool JsParser::isUndefined(const ExpOperation& oper)
|
|||
return w && !w->object();
|
||||
}
|
||||
|
||||
// Check if an operation is null or undefined
|
||||
bool JsParser::isMissing(const ExpOperation& oper)
|
||||
{
|
||||
ExpWrapper* w = YOBJECT(ExpWrapper,&oper);
|
||||
return w && (!w->object() || (w->object() == s_null.object()));
|
||||
}
|
||||
|
||||
/* vi: set ts=8 sw=4 sts=4 noet: */
|
||||
|
|
|
@ -2671,6 +2671,61 @@ public:
|
|||
*/
|
||||
static bool isUndefined(const ExpOperation& oper);
|
||||
|
||||
/**
|
||||
* Check if an operation is null or undefined
|
||||
* @return True if the operation holds an undefined value or a null object
|
||||
*/
|
||||
static bool isMissing(const ExpOperation& oper);
|
||||
|
||||
/**
|
||||
* Check if an operation is missing, holds a null or undefined
|
||||
* @return True if the operation is null or holds an undefined value or a null object
|
||||
*/
|
||||
inline static bool isMissing(const ExpOperation* oper)
|
||||
{ return !oper || isMissing(*oper); }
|
||||
|
||||
/**
|
||||
* Check if an operation is not null or undefined
|
||||
* @return True if the operation holds a value or non-null object
|
||||
*/
|
||||
inline static bool isPresent(const ExpOperation& oper)
|
||||
{ return !isMissing(oper); }
|
||||
|
||||
/**
|
||||
* Check if an operation is present and not null or undefined
|
||||
* @return True if the operation holds a value or non-null object
|
||||
*/
|
||||
inline static bool isPresent(const ExpOperation* oper)
|
||||
{ return oper && !isMissing(*oper); }
|
||||
|
||||
/**
|
||||
* Check if an operation holds a null or undefined value or empty string
|
||||
* @return True if the operation is an undefined value or a null object or empty string
|
||||
*/
|
||||
inline static bool isEmpty(const ExpOperation& oper)
|
||||
{ return oper.null() || isMissing(oper); }
|
||||
|
||||
/**
|
||||
* Check if an operation is missing, holds a null or undefined value or empty string
|
||||
* @return True if the operation is an undefined value or a null object or empty string
|
||||
*/
|
||||
inline static bool isEmpty(const ExpOperation* oper)
|
||||
{ return TelEngine::null(oper) || isMissing(*oper); }
|
||||
|
||||
/**
|
||||
* Check if an operation is not null or undefined or empty string
|
||||
* @return True if the operation holds a non-empty value or non-null object
|
||||
*/
|
||||
inline static bool isFilled(const ExpOperation& oper)
|
||||
{ return oper && !isMissing(oper); }
|
||||
|
||||
/**
|
||||
* Check if an operation is not null or undefined or empty string
|
||||
* @return True if the operation holds a non-empty value or non-null object
|
||||
*/
|
||||
inline static bool isFilled(const ExpOperation* oper)
|
||||
{ return !isEmpty(oper); }
|
||||
|
||||
private:
|
||||
String m_basePath;
|
||||
String m_includePath;
|
||||
|
|
|
@ -3815,7 +3815,7 @@ bool JsJSON::runNative(ObjList& stack, const ExpOperation& oper, GenObject* cont
|
|||
return false;
|
||||
ExpOperation* op = 0;
|
||||
ExpOperation* file = static_cast<ExpOperation*>(args[0]);
|
||||
if (!TelEngine::null(file)) {
|
||||
if (JsParser::isFilled(file)) {
|
||||
File f;
|
||||
if (f.openPath(*file)) {
|
||||
int64_t len = f.length();
|
||||
|
@ -3837,7 +3837,7 @@ bool JsJSON::runNative(ObjList& stack, const ExpOperation& oper, GenObject* cont
|
|||
if (extractArgs(stack,oper,context,args) < 2)
|
||||
return false;
|
||||
ExpOperation* file = static_cast<ExpOperation*>(args[0]);
|
||||
bool ok = !TelEngine::null(file);
|
||||
bool ok = JsParser::isFilled(file);
|
||||
if (ok) {
|
||||
ok = false;
|
||||
int spaces = args[2] ? static_cast<ExpOperation*>(args[2])->number() : 0;
|
||||
|
@ -4030,7 +4030,7 @@ bool JsDNS::runNative(ObjList& stack, const ExpOperation& oper, GenObject* conte
|
|||
return false;
|
||||
type.toUpper();
|
||||
int qType = lookup(type,Resolver::s_types,-1);
|
||||
if ((qType < 0) || TelEngine::null(arg))
|
||||
if ((qType < 0) || JsParser::isEmpty(arg))
|
||||
ExpEvaluator::pushOne(stack,new ExpWrapper(0,"DNS"));
|
||||
else {
|
||||
if (async && async->valBoolean()) {
|
||||
|
@ -4047,18 +4047,20 @@ bool JsDNS::runNative(ObjList& stack, const ExpOperation& oper, GenObject* conte
|
|||
else if ((oper.name() == YSTRING("resolve")) || (oper.name() == YSTRING("local"))) {
|
||||
if (extractArgs(stack,oper,context,args) != 1)
|
||||
return false;
|
||||
String tmp = static_cast<ExpOperation*>(args[0]);
|
||||
if ((tmp[0] == '[') && (tmp[tmp.length() - 1] == ']'))
|
||||
tmp = tmp.substr(1,tmp.length() - 2);
|
||||
SocketAddr rAddr;
|
||||
ExpOperation* op = 0;
|
||||
if (rAddr.host(tmp)) {
|
||||
if (oper.name() == YSTRING("resolve"))
|
||||
op = new ExpOperation(rAddr.host(),"IP");
|
||||
else {
|
||||
SocketAddr lAddr;
|
||||
if (lAddr.local(rAddr))
|
||||
op = new ExpOperation(lAddr.host(),"IP");
|
||||
if (JsParser::isFilled(static_cast<ExpOperation*>(args[0]))) {
|
||||
String tmp = static_cast<ExpOperation*>(args[0]);
|
||||
if ((tmp[0] == '[') && (tmp[tmp.length() - 1] == ']'))
|
||||
tmp = tmp.substr(1,tmp.length() - 2);
|
||||
SocketAddr rAddr;
|
||||
if (rAddr.host(tmp)) {
|
||||
if (oper.name() == YSTRING("resolve"))
|
||||
op = new ExpOperation(rAddr.host(),"IP");
|
||||
else {
|
||||
SocketAddr lAddr;
|
||||
if (lAddr.local(rAddr))
|
||||
op = new ExpOperation(lAddr.host(),"IP");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!op)
|
||||
|
@ -4078,7 +4080,7 @@ bool JsDNS::runNative(ObjList& stack, const ExpOperation& oper, GenObject* conte
|
|||
// fall through
|
||||
case 1:
|
||||
op = 0;
|
||||
{
|
||||
if (JsParser::isFilled(static_cast<ExpOperation*>(args[0]))) {
|
||||
String tmp = static_cast<ExpOperation*>(args[0]);
|
||||
if ((tmp[0] == '[') && (tmp[tmp.length() - 1] == ']'))
|
||||
tmp = tmp.substr(1,tmp.length() - 2);
|
||||
|
|
Loading…
Reference in New Issue