rust/dns/lua - fix call convention to match C.

Also, when requesting the query, if the request doesn't exist,
return the query from the response. This makes it behave
more like C implementation.

Redmine issue:
https://redmine.openinfosecfoundation.org/issues/2730
pull/3577/head
Jason Ish 7 years ago committed by Victor Julien
parent 87250da0fc
commit 4163d5c360

@ -69,14 +69,13 @@ pub extern "C" fn rs_dns_lua_get_query_table(clua: &mut CLuaState,
let mut i: i64 = 0;
for request in &tx.request {
if request.queries.len() == 0 {
break;
}
lua.newtable();
// Create table now to be consistent with C that always returns
// table even in the absence of any authorities.
lua.newtable();
// We first look in the request for queries. However, if there is
// no request, check the response for queries.
if let &Some(ref request) = &tx.request {
for query in &request.queries {
lua.pushinteger(i);
i += 1;
@ -93,11 +92,28 @@ pub extern "C" fn rs_dns_lua_get_query_table(clua: &mut CLuaState,
lua.settable(-3);
}
} else if let &Some(ref response) = &tx.response {
for query in &response.queries {
lua.pushinteger(i);
i += 1;
lua.newtable();
lua.pushstring("type");
lua.pushstring(&dns_rrtype_string(query.rrtype));
lua.settable(-3);
lua.pushstring("rrname");
lua.pushstring(&String::from_utf8_lossy(&query.name));
lua.settable(-3);
return 1;
lua.settable(-3);
}
}
return 0;
// Again, always return 1 to be consistent with C, even if the
// table is empty.
return 1;
}
#[no_mangle]
@ -111,14 +127,11 @@ pub extern "C" fn rs_dns_lua_get_answer_table(clua: &mut CLuaState,
let mut i: i64 = 0;
for response in &tx.response {
if response.answers.len() == 0 {
break;
}
lua.newtable();
// Create table now to be consistent with C that always returns
// table even in the absence of any authorities.
lua.newtable();
if let &Some(ref response) = &tx.response {
for answer in &response.answers {
lua.pushinteger(i);
i += 1;
@ -150,11 +163,11 @@ pub extern "C" fn rs_dns_lua_get_answer_table(clua: &mut CLuaState,
}
lua.settable(-3);
}
return 1;
}
return 0;
// Again, always return 1 to be consistent with C, even if the
// table is empty.
return 1;
}
#[no_mangle]
@ -168,14 +181,11 @@ pub extern "C" fn rs_dns_lua_get_authority_table(clua: &mut CLuaState,
let mut i: i64 = 0;
for response in &tx.response {
if response.authorities.len() == 0 {
break;
}
lua.newtable();
// Create table now to be consistent with C that always returns
// table even in the absence of any authorities.
lua.newtable();
if let &Some(ref response) = &tx.response {
for answer in &response.authorities {
lua.pushinteger(i);
i += 1;
@ -195,9 +205,9 @@ pub extern "C" fn rs_dns_lua_get_authority_table(clua: &mut CLuaState,
lua.settable(-3);
}
return 1;
}
return 0;
// Again, always return 1 to be consistent with C, even if the
// table is empty.
return 1;
}

Loading…
Cancel
Save