mirror of
https://github.com/zeek/zeek.git
synced 2025-10-15 21:18:20 +00:00
Merge remote-tracking branch 'origin/topic/seth/strptime'
* origin/topic/seth/strptime: Added a BiF to wrap the strptime function. Closes #904.
This commit is contained in:
commit
5716545cfa
7 changed files with 60 additions and 7 deletions
5
CHANGES
5
CHANGES
|
@ -1,4 +1,9 @@
|
||||||
|
|
||||||
|
2.1-84 | 2012-10-19 15:12:56 -0700
|
||||||
|
|
||||||
|
* Added a BiF strptime() to wrap the corresponding C function. (Seth
|
||||||
|
Hall)
|
||||||
|
|
||||||
2.1-82 | 2012-10-19 15:05:40 -0700
|
2.1-82 | 2012-10-19 15:05:40 -0700
|
||||||
|
|
||||||
* Add IPv6 support to signature header conditions. (Jon Siwek)
|
* Add IPv6 support to signature header conditions. (Jon Siwek)
|
||||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
2.1-82
|
2.1-84
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 3d7c2d61e63d7d51c455363cdfe9373e4e680b89
|
Subproject commit fd0e7e0b0cf50131efaf536a5683266cfe169455
|
36
src/bro.bif
36
src/bro.bif
|
@ -11,6 +11,7 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "digest.h"
|
#include "digest.h"
|
||||||
#include "Reporter.h"
|
#include "Reporter.h"
|
||||||
|
@ -2615,15 +2616,15 @@ function to_double%(str: string%): double
|
||||||
%{
|
%{
|
||||||
const char* s = str->CheckString();
|
const char* s = str->CheckString();
|
||||||
char* end_s;
|
char* end_s;
|
||||||
|
|
||||||
double d = strtod(s, &end_s);
|
double d = strtod(s, &end_s);
|
||||||
|
|
||||||
if ( s[0] == '\0' || end_s[0] != '\0' )
|
if ( s[0] == '\0' || end_s[0] != '\0' )
|
||||||
{
|
{
|
||||||
builtin_error("bad conversion to double", @ARG@[0]);
|
builtin_error("bad conversion to double", @ARG@[0]);
|
||||||
d = 0;
|
d = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Val(d, TYPE_DOUBLE);
|
return new Val(d, TYPE_DOUBLE);
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
@ -3285,6 +3286,31 @@ function strftime%(fmt: string, d: time%) : string
|
||||||
return new StringVal(buffer);
|
return new StringVal(buffer);
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
## Parse a textual representation of a date/time value into a ``time`` type value.
|
||||||
|
##
|
||||||
|
## fmt: The format string used to parse the following *d* argument. See ``man strftime``
|
||||||
|
## for the syntax.
|
||||||
|
##
|
||||||
|
## d: The string representing the time.
|
||||||
|
##
|
||||||
|
## Returns: The time value calculated from parsing *d* with *fmt*.
|
||||||
|
function strptime%(fmt: string, d: string%) : time
|
||||||
|
%{
|
||||||
|
const time_t timeval = time_t(NULL);
|
||||||
|
struct tm t = *localtime(&timeval);
|
||||||
|
|
||||||
|
if ( strptime(d->CheckString(), fmt->CheckString(), &t) == NULL )
|
||||||
|
{
|
||||||
|
reporter->Warning("strptime conversion failed: fmt:%s d:%s", fmt->CheckString(), d->CheckString());
|
||||||
|
return new Val(0.0, TYPE_TIME);
|
||||||
|
}
|
||||||
|
|
||||||
|
double ret = mktime(&t);
|
||||||
|
return new Val(ret, TYPE_TIME);
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
||||||
# ===========================================================================
|
# ===========================================================================
|
||||||
#
|
#
|
||||||
# Network Type Processing
|
# Network Type Processing
|
||||||
|
|
2
testing/btest/Baseline/bifs.strptime/.stdout
Normal file
2
testing/btest/Baseline/bifs.strptime/.stdout
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
1350604800.0
|
||||||
|
0.0
|
10
testing/btest/Baseline/bifs.strptime/reporter.log
Normal file
10
testing/btest/Baseline/bifs.strptime/reporter.log
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#separator \x09
|
||||||
|
#set_separator ,
|
||||||
|
#empty_field (empty)
|
||||||
|
#unset_field -
|
||||||
|
#path reporter
|
||||||
|
#open 2012-10-19-06-06-36
|
||||||
|
#fields ts level message location
|
||||||
|
#types time enum string string
|
||||||
|
0.000000 Reporter::WARNING strptime conversion failed: fmt:%m d:1980-10-24 (empty)
|
||||||
|
#close 2012-10-19-06-06-36
|
10
testing/btest/bifs/strptime.bro
Normal file
10
testing/btest/bifs/strptime.bro
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#
|
||||||
|
# @TEST-EXEC: bro %INPUT
|
||||||
|
# @TEST-EXEC: btest-diff .stdout
|
||||||
|
# @TEST-EXEC: btest-diff reporter.log
|
||||||
|
|
||||||
|
event bro_init()
|
||||||
|
{
|
||||||
|
print strptime("%Y-%m-%d", "2012-10-19");
|
||||||
|
print strptime("%m", "1980-10-24");
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue