1 /*
2  * ModSecurity, http://www.modsecurity.org/
3  * Copyright (c) 2015 - 2021 Trustwave Holdings, Inc. (http://www.trustwave.com/)
4  *
5  * You may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * If any of the files related to licensing are missing or if you have any
11  * other questions related to licensing please contact Trustwave Holdings, Inc.
12  * directly using the email address security@modsecurity.org.
13  *
14  */
15 
16 #include "src/variables/time_day.h"
17 
18 #include <time.h>
19 #include <stdio.h>
20 #include <string.h>
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <fcntl.h>
24 
25 #include <iostream>
26 #include <string>
27 #include <vector>
28 #include <list>
29 #include <utility>
30 
31 #include "modsecurity/transaction.h"
32 
33 namespace modsecurity {
34 namespace variables {
35 
evaluate(Transaction * transaction,RuleWithActions * rule,std::vector<const VariableValue * > * l)36 void TimeDay::evaluate(Transaction *transaction,
37     RuleWithActions *rule,
38     std::vector<const VariableValue *> *l) {
39     char tstr[200];
40     struct tm timeinfo;
41     time_t timer;
42 
43     time(&timer);
44     memset(tstr, '\0', 200);
45 
46     localtime_r(&timer, &timeinfo);
47     strftime(tstr, 200, "%d", &timeinfo);
48 
49     transaction->m_variableTimeDay.assign(tstr);
50 
51     l->push_back(new VariableValue(&m_retName,
52         &transaction->m_variableTimeDay));
53 }
54 
55 
56 }  // namespace variables
57 }  // namespace modsecurity
58