From 9b28bc8ed509c5707f48dd3429a28808ff77b329 Mon Sep 17 00:00:00 2001 From: david Date: Sat, 15 Sep 2012 17:56:17 +0000 Subject: [PATCH] Add an nseU_opttarget function. --- nse_utility.cc | 11 +++++++++++ nse_utility.h | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/nse_utility.cc b/nse_utility.cc index 50e1c92ea..9ce7c574f 100644 --- a/nse_utility.cc +++ b/nse_utility.cc @@ -121,6 +121,17 @@ void nseU_checktarget (lua_State *L, int idx, const char **address, const char * } } +void nseU_opttarget (lua_State *L, int idx, const char **address, const char **targetname) +{ + if (lua_isnoneornil(L, idx)) { + *address = NULL; + *targetname = NULL; + return; + } else { + return nseU_checktarget(L, idx, address, targetname); + } +} + uint16_t nseU_checkport (lua_State *L, int idx, const char **protocol) { uint16_t port; diff --git a/nse_utility.h b/nse_utility.h index 9ff2d039d..66567a02b 100644 --- a/nse_utility.h +++ b/nse_utility.h @@ -108,6 +108,15 @@ void *nseU_checkudata (lua_State *L, int idx, int upvalue, const char *name); */ void nseU_checktarget (lua_State *L, int idx, const char **address, const char **targetname); +/* void nseU_opttarget (lua_State *L, int idx, [-0, +0, v] + * const char **address, + * const char **targetname) + * + * Like nseU_checktarget, but sets *address and *targetname to NULL and returns + * success if the argument at idx is none or nil. + */ +void nseU_opttarget (lua_State *L, int idx, const char **address, const char **targetname); + /* uint16_t nseU_checkport (lua_State *L, int idx, [-0, +0, v] * const char **protocol) *