Webserv
Loading...
Searching...
No Matches
utils Namespace Reference

Classes

struct  FileEntry
struct  IpInfo
class  Logger
class  TempFile

Enumerations

enum  LogLevel {
  TRACE , DEBUG , INFO , WARNING ,
  ERROR , FATAL
}
 Defines the severity levels for log messages. More...

Functions

bool writeFile (const std::string &content, const char *path)
bool isDir (const std::string &p)
const char * validateDirectoryPath (const char *path)
std::string getFileExtension (const std::string &fpath)
http::HttpStatus checkFileAccess (const std::string &path, int modeMask, bool allowDirectory=false)
std::string joinPaths (const std::string &p1, const std::string &p2)
bool getDirectoryEntries (std::string const &path, std::vector< FileEntry > &entries)
 Reads a directory, stats all files, and returns them sorted by name. Uses only opendir/readdir/closedir/stat.
bool getFileStatus (std::string const &path, struct stat &buf)
 Simple wrapper for stat to check existence and get details.
template<typename T>
std::string toString (T const &v)
template<typename T>
fromString (std::string const &str)
std::string trim (const std::string &s)
bool isAllDigit (std::string const &s)
void toLower (std::string &s)
bool isValidPort (int port)
bool isValidPort (std::string const &)
bool isValidIPv4 (char const *)
bool isValidIPv4 (std::string const &)
bool extractIpInfo (std::string const &, IpInfo &)
bool writeFile (const std::string &content, const char *path, size_t start, size_t end)

Enumeration Type Documentation

◆ LogLevel

Defines the severity levels for log messages.

Enumerator
TRACE 

Fine-grained messages, typically for detailed debugging.

DEBUG 

Information useful for developers during debugging.

INFO 

Informational messages about application progress.

WARNING 

Indicates a potential issue that is not a critical error.

ERROR 

An error that occurred but the application can recover from.

FATAL 

A critical error that will likely lead to termination.

Function Documentation

◆ checkFileAccess()

http::HttpStatus utils::checkFileAccess ( const std::string & path,
int modeMask,
bool allowDirectory = false )

◆ extractIpInfo()

bool utils::extractIpInfo ( std::string const & s,
IpInfo & info )

◆ fromString()

template<typename T>
T utils::fromString ( std::string const & str)

◆ getDirectoryEntries()

bool utils::getDirectoryEntries ( std::string const & path,
std::vector< FileEntry > & entries )

Reads a directory, stats all files, and returns them sorted by name. Uses only opendir/readdir/closedir/stat.

◆ getFileExtension()

std::string utils::getFileExtension ( const std::string & fpath)

◆ getFileStatus()

bool utils::getFileStatus ( std::string const & path,
struct stat & buf )

Simple wrapper for stat to check existence and get details.

◆ isAllDigit()

bool utils::isAllDigit ( std::string const & s)

◆ isDir()

bool utils::isDir ( const std::string & p)

◆ isValidIPv4() [1/2]

bool utils::isValidIPv4 ( char const * )

◆ isValidIPv4() [2/2]

bool utils::isValidIPv4 ( std::string const & s)

◆ isValidPort() [1/2]

bool utils::isValidPort ( int port)

◆ isValidPort() [2/2]

bool utils::isValidPort ( std::string const & v)

◆ joinPaths()

std::string utils::joinPaths ( const std::string & p1,
const std::string & p2 )

◆ toLower()

void utils::toLower ( std::string & s)

◆ toString()

template<typename T>
std::string utils::toString ( T const & v)

◆ trim()

std::string utils::trim ( const std::string & s)

◆ validateDirectoryPath()

const char * utils::validateDirectoryPath ( const char * path)

◆ writeFile() [1/2]

bool utils::writeFile ( const std::string & content,
const char * path )

◆ writeFile() [2/2]

bool utils::writeFile ( const std::string & content,
const char * path,
size_t start,
size_t end )