Updated included headers to support compilation on Windows (using Visual C++)

- most of posix related functions and constants in unistd.h can be
  found in io.h in Visual C++
- introduced src/compat/msvc.h to adjust for compiler differences (and
  avoid updating code with #ifdef blocks for Windows support)
- removed some included headers that are not needed (both on Unix and
  Windows builds)
This commit is contained in:
Eduardo Arias 2024-04-23 11:46:29 -03:00
parent c8056483f7
commit a48856822c
33 changed files with 130 additions and 12 deletions

View File

@ -19,7 +19,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef WIN32
#include <unistd.h>
#else
#include <io.h>
#endif
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/time.h>

View File

@ -13,7 +13,11 @@
*
*/
#ifndef WIN32
#include <unistd.h>
#else
#include <io.h>
#endif
#include <stdio.h>
#include <string.h>

View File

@ -27,6 +27,10 @@
#include "modsecurity/transaction.h"
#include "src/actions/transformations/transformation.h"
#ifdef WIN32
#include "src/compat/msvc.h"
#endif
namespace modsecurity {
namespace actions {

View File

@ -17,6 +17,7 @@
#include <algorithm>
#include <string>
#include <locale>
#include "modsecurity/transaction.h"
#include "src/actions/transformations/transformation.h"

View File

@ -17,6 +17,7 @@
#include <algorithm>
#include <string>
#include <locale>
#include "modsecurity/transaction.h"
#include "src/actions/transformations/transformation.h"

View File

@ -21,7 +21,12 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifndef WIN32
#include <unistd.h>
#else
#include <io.h>
#include "src/compat/msvc.h"
#endif
#include <stdlib.h>
#include <fstream>

View File

@ -18,8 +18,10 @@
#include <stdio.h>
#ifndef WIN32
#include <sys/ipc.h>
#include <sys/shm.h>
#endif
#include <sys/types.h>
#include <iostream>

View File

@ -12,6 +12,7 @@
* directly using the email address security@modsecurity.org.
*
*/
#include <pthread.h>
#ifdef __cplusplus

View File

@ -18,7 +18,11 @@
#include "src/collection/backend/collection_data.h"
#include <sys/types.h>
#ifndef WIN32
#include <unistd.h>
#else
#include <io.h>
#endif
#include <string>
#include <memory>

22
src/compat/msvc.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef __COMPAT_MSVC
#define __COMPAT_MSVC
#include <time.h>
#if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#endif
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#define strtok_r strtok_s
#define popen _popen
#define pclose _pclose
inline tm* localtime_r(const time_t* tin, tm* tout) {
if (!localtime_s(tout, tin)) return tout;
return nullptr;
}
#endif

View File

@ -15,10 +15,6 @@
#include "modsecurity/debug_log.h"
#include <stddef.h>
#include <fstream>
#include "src/debug_log/debug_log_writer.h"
#include "src/debug_log_writer_agent.h"

View File

@ -23,6 +23,10 @@
#include "src/operators/operator.h"
#include "src/utils/system.h"
#ifdef WIN32
#include "src/compat/msvc.h"
#endif
namespace modsecurity {
namespace operators {

View File

@ -16,10 +16,15 @@
#include "src/operators/rbl.h"
#include <sys/types.h>
#ifndef WIN32
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#else
#include <winsock2.h>
#include <ws2tcpip.h>
#endif
#include <string>

View File

@ -17,10 +17,14 @@
#define SRC_OPERATORS_RBL_H_
#include <sys/types.h>
#ifndef WIN32
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#else
#include <winsock2.h>
#endif
#include <string>
#include <memory>

View File

@ -4952,7 +4952,11 @@ static std::stack<int> YY_PREVIOUS_STATE;
* The user has a chance to override it with an option.
*/
/* %if-c-only */
#ifndef WIN32
#include <unistd.h>
#else
#include <io.h>
#endif
/* %endif */
/* %if-c++-only */
/* %endif */

View File

@ -19,6 +19,10 @@
#include "src/utils/string.h"
#include "src/variables/variable.h"
#ifdef WIN32
#include "src/compat/msvc.h"
#endif
namespace modsecurity {

View File

@ -53,6 +53,9 @@
#include "src/actions/disruptive/allow.h"
#include "src/variables/remote_user.h"
#ifdef WIN32
#include "src/compat/msvc.h"
#endif
using modsecurity::actions::Action;

View File

@ -13,10 +13,13 @@
*
*/
#ifndef WIN32
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#else
#include <winsock2.h>
#endif
#include <string>
#include <fstream>

View File

@ -15,10 +15,14 @@
#include "src/utils/ip_tree.h"
#ifndef WIN32
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#else
#include <winsock2.h>
#endif
#include <string>
#include <fstream>

View File

@ -15,9 +15,15 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef WIN32
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#else
#include "src/compat/msvc.h"
#include <winsock2.h>
#include <ws2tcpip.h>
#endif
#include "src/utils/msc_tree.h"

View File

@ -17,11 +17,6 @@
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#ifdef __OpenBSD__
#include <glob.h>
#else
#include <wordexp.h>
#endif
#include <stdint.h>
#include <inttypes.h>

View File

@ -13,8 +13,6 @@
*
*/
#include <ctime>
#include <iostream>
#include <string>
#include <list>

View File

@ -30,6 +30,10 @@
#include "modsecurity/transaction.h"
#ifdef WIN32
#include "src/compat/msvc.h"
#endif
namespace modsecurity {
namespace variables {

View File

@ -30,6 +30,10 @@
#include "modsecurity/transaction.h"
#ifdef WIN32
#include "src/compat/msvc.h"
#endif
namespace modsecurity {
namespace variables {

View File

@ -30,6 +30,10 @@
#include "modsecurity/transaction.h"
#ifdef WIN32
#include "src/compat/msvc.h"
#endif
namespace modsecurity {
namespace variables {

View File

@ -30,6 +30,10 @@
#include "modsecurity/transaction.h"
#ifdef WIN32
#include "src/compat/msvc.h"
#endif
namespace modsecurity {
namespace variables {

View File

@ -30,6 +30,10 @@
#include "modsecurity/transaction.h"
#ifdef WIN32
#include "src/compat/msvc.h"
#endif
namespace modsecurity {
namespace variables {

View File

@ -30,6 +30,10 @@
#include "modsecurity/transaction.h"
#ifdef WIN32
#include "src/compat/msvc.h"
#endif
namespace modsecurity {
namespace variables {

View File

@ -30,6 +30,10 @@
#include "modsecurity/transaction.h"
#ifdef WIN32
#include "src/compat/msvc.h"
#endif
namespace modsecurity {
namespace variables {

View File

@ -30,6 +30,10 @@
#include "modsecurity/transaction.h"
#ifdef WIN32
#include "src/compat/msvc.h"
#endif
namespace modsecurity {
namespace variables {

View File

@ -114,7 +114,11 @@ using namespace modsecurity;
#include <stdio.h>
#include <stdlib.h>
#ifndef WIN32
#include <unistd.h>
#else
#include <io.h>
#endif
#include <signal.h>
#include <string.h>

View File

@ -15,7 +15,11 @@
#include <string.h>
#ifndef WIN32
#include <unistd.h>
#else
#include <io.h>
#endif
#include <ctime>
#include <iostream>

View File

@ -15,7 +15,11 @@
#include <string.h>
#include <sys/stat.h>
#ifndef WIN32
#include <unistd.h>
#else
#include <io.h>
#endif
#include <ctime>
#include <iostream>