Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnishevent
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
varnishevent
Commits
8034a796
Commit
8034a796
authored
Apr 01, 2015
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement and test the %{X}t formatter
parent
58acaecb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
7 deletions
+59
-7
format.c
src/format.c
+7
-7
format.h
src/format.h
+2
-0
test_format.c
src/test/test_format.c
+50
-0
No files found.
src/format.c
View file @
8034a796
...
...
@@ -425,15 +425,15 @@ format_##ltr(tx_t *tx, char *name, enum VSL_tag_e tag, \
{ \
double t; \
(void) tag; \
(extra);
\
extra;
\
\
t = get_tm(tx); \
AN(scratch); \
size_t n = strfTIMlocal(scratch, config.max_reclen, fmt, t); \
if (n
== 0)
\
*s
cratch = '\0';
\
*s = scratch;
\
*len = strlen(scratch);
\
if (n
!= 0) {
\
*s
= scratch;
\
*len = strlen(scratch);
\
}
\
}
FORMAT_tim
(
t
,
"[%d/%b/%Y:%T %z]"
,
(
void
)
name
)
...
...
@@ -523,10 +523,10 @@ FORMAT_Xio(backend, i, BereqHeader)
FORMAT_Xio
(
client
,
o
,
RespHeader
)
FORMAT_Xio
(
backend
,
o
,
BerespHeader
)
#if 0
FORMAT_tim
(
Xt
,
name
,
)
#if 0
static void
format_Xttfb_client(logline_t *ll, char *name, enum VSL_tag_e tag,
char **s, size_t *len)
...
...
src/format.h
View file @
8034a796
...
...
@@ -89,3 +89,5 @@ formatter_f format_Xi_client;
formatter_f
format_Xi_backend
;
formatter_f
format_Xo_client
;
formatter_f
format_Xo_backend
;
formatter_f
format_Xt
;
src/test/test_format.c
View file @
8034a796
...
...
@@ -31,6 +31,7 @@
#include <string.h>
#include <math.h>
#include <time.h>
#include "vre.h"
#include "minunit.h"
...
...
@@ -990,6 +991,54 @@ static const char
return
NULL
;
}
static
const
char
*
test_format_Xt
(
void
)
{
tx_t
tx
;
logline_t
rec
;
chunk_t
chunk
;
char
*
str
=
NULL
,
strftime_s
[
BUFSIZ
];
size_t
len
;
char
fmt
[]
=
"%a %A %b %B %c %C %d %D %e %F %g %G %h %H %I %j %m %M %n %p %r %R %S "
\
"%t %T %u %U %V %w %W %x %X %y %Y %z %Z %%"
;
char
afmt
[]
=
"%Ec %EC %Ex %EX %Ey %Ey %Od %Oe %OH %OI %Om %OM %OS %Ou %OU %OV %Ow "
\
"%OW %Oy"
;
char
subs
[]
=
"%N"
;
struct
tm
*
tm
;
time_t
t
=
1427743146
;
printf
(
"... testing format_Xt()
\n
"
);
init_tx_rec_chunk
(
&
tx
,
&
rec
,
&
chunk
);
MAN
(
chunk
.
data
);
set_record_data
(
&
rec
,
&
chunk
,
T1
,
SLT_Timestamp
);
tm
=
localtime
(
&
t
);
MAN
(
strftime
(
strftime_s
,
config
.
max_reclen
,
fmt
,
tm
));
format_Xt
(
&
tx
,
fmt
,
SLT__Bogus
,
&
str
,
&
len
);
MAN
(
str
);
VMASSERT
(
strcmp
(
str
,
strftime_s
)
==
0
,
"'%s' != '%s'"
,
str
,
strftime_s
);
MASSERT
(
len
==
strlen
(
strftime_s
));
/* Alternative strftime formatters */
MAN
(
strftime
(
strftime_s
,
config
.
max_reclen
,
afmt
,
tm
));
format_Xt
(
&
tx
,
afmt
,
SLT__Bogus
,
&
str
,
&
len
);
MAN
(
str
);
VMASSERT
(
strcmp
(
str
,
strftime_s
)
==
0
,
"'%s' != '%s'"
,
str
,
strftime_s
);
MASSERT
(
len
==
strlen
(
strftime_s
));
/* subsecond formatter */
format_Xt
(
&
tx
,
subs
,
SLT__Bogus
,
&
str
,
&
len
);
MAN
(
str
);
/* ms accuracy ... */
VMASSERT
(
strncmp
(
str
,
"529306000"
,
3
)
==
0
,
"'%s' != '529306000'"
,
str
);
MASSERT
(
len
==
9
);
return
NULL
;
}
static
const
char
*
all_tests
(
void
)
{
...
...
@@ -1016,6 +1065,7 @@ static const char
mu_run_test
(
test_format_u
);
mu_run_test
(
test_format_Xi
);
mu_run_test
(
test_format_Xo
);
mu_run_test
(
test_format_Xt
);
return
NULL
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment