From 298c42d3b49822f97634982af4026e51a94c4e7e Mon Sep 17 00:00:00 2001 From: dmiller Date: Mon, 10 Feb 2014 19:39:09 +0000 Subject: [PATCH] Update the usage examples in match.lua The example uses of nmap.receive_buf() were missing the second parameter, keeppattern. Also referenced the match library from nmap.receive_buf's NSEdoc to avoid reimplementations of buffered sockets. --- nselib/match.lua | 18 +++++++++++------- nselib/nmap.luadoc | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/nselib/match.lua b/nselib/match.lua index fc0103296..ab1a70d13 100644 --- a/nselib/match.lua +++ b/nselib/match.lua @@ -12,11 +12,11 @@ _ENV = stdnse.module("match", stdnse.seeall) --various functions for use with nse's nsock:receive_buf - function -- e.g. --- sock:receive_buf(regex("myregexpattern")) - does a match using pcre- regular- --- - expressions --- sock:receive_buf(numbytes(80)) - is the buffered version of --- sock:receive_bytes(80) - i.e. it returns --- exactly 80 bytes and no more +-- sock:receive_buf(regex("myregexpattern"), true) - does a match using pcre +-- regular expressions +-- sock:receive_buf(numbytes(80), true) - is the buffered version of +-- sock:receive_bytes(80) - i.e. it +-- returns exactly 80 bytes and no more --- Return a function that allows delimiting with a regular expression. -- @@ -24,7 +24,7 @@ _ENV = stdnse.module("match", stdnse.seeall) -- give script developers the ability to use regular expressions for delimiting -- instead of Lua's string patterns. -- @param pattern The regex. --- @usage sock:receive_buf(match.regex("myregexpattern")) +-- @usage sock:receive_buf(match.regex("myregexpattern"), true) -- @see nmap.receive_buf -- @see pcre.exec regex = function(pattern) @@ -42,8 +42,12 @@ end -- sock:receive_bytes(n) in case a script requires more than one -- fixed-size chunk, as the unbuffered version may return more bytes than -- requested and thus would require you to do the parsing on your own. +-- +-- The keeppattern parameter to receive_buf should be set to +-- true, otherwise the string returned will be 1 less than +-- num -- @param num Number of bytes. --- @usage sock:receive_buf(match.numbytes(80)) +-- @usage sock:receive_buf(match.numbytes(80), true) -- @see nmap.receive_buf numbytes = function(num) local n = num diff --git a/nselib/nmap.luadoc b/nselib/nmap.luadoc index 0488c8e2c..509fe7149 100644 --- a/nselib/nmap.luadoc +++ b/nselib/nmap.luadoc @@ -608,6 +608,7 @@ function receive_bytes(n) -- @return Status (true or false). -- @return Data (if status is true) or error string (if status is false). -- @see new_socket +-- @see match -- @usage local status, line = socket:receive_buf("\r?\n", false) function receive_buf(delimiter, keeppattern)