🔨」 fix: fixed merge conflict

This commit is contained in:
2025-04-22 12:34:42 +02:00
parent b9b299cd68
commit 7ee79b6fa4
4 changed files with 117 additions and 12 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/19 14:59:41 by adjoly #+# #+# */
/* Updated: 2025/04/22 11:49:19 by mmoussou ### ########.fr */
/* Updated: 2025/04/22 12:34:00 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -29,6 +29,19 @@ class Route {
Route(toml::ANode *);
~Route(void);
bool getDirList(void) { return _dirlist; }
bool getCookies(void) { return _cookies; }
bool getRedirect(void) { return _redirect; }
int32_t getMaxBody(void) { return _max_body; }
std::string getRootDir(void) { return _root; }
std::string getUpRoot(void) { return _up_root; }
std::string getIndex(void) { return _index; }
std::map<std::string, std::string> *getCgi(void) { return _cgi; }
bool *getMethods(void) { return _methods; }
protected:
private:
bool _dirlist;

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/19 14:11:28 by adjoly #+# #+# */
/* Updated: 2025/04/22 12:02:36 by mmoussou ### ########.fr */
/* Updated: 2025/04/22 12:34:14 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -66,6 +66,12 @@ class Server {
return false;
}
Route *whatRoute(const std::string &route_path) {
for (auto it = prange(_routes)) {
}
}
protected:
private:
std::map<std::string, Route *>
@ -84,6 +90,8 @@ class Server {
std::map<int, std::string> *
_parseErrPages(std::map<std::string, toml::ANode *> *table);
};
} // namespace config

73
includes/config/URL.hpp Normal file
View File

@ -0,0 +1,73 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* URL.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/22 12:17:48 by adjoly #+# #+# */
/* Updated: 2025/04/22 12:26:21 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#include <cstring>
#include <sstream>
#include <string>
#include <vector>
#include <webserv.hpp>
class URL {
public:
URL(const std::string &url) : _full_url(url) { parse(); }
bool operator==(const URL &other) const {
return comparePathSegments(other);
}
std::vector<std::string> getSegments(void) { return _path_segments; }
std::string getFullUrl(void) { return _full_url; }
private:
void parse() {
size_t scheme_pos = _full_url.find("://");
size_t path_start = 0;
if (scheme_pos != std::string::npos) {
path_start = _full_url.find('/', scheme_pos + 3);
} else {
path_start = 0;
}
if (path_start != std::string::npos) {
std::string path = _full_url.substr(path_start);
splitPath(path, _path_segments);
}
}
void splitPath(const std::string &path,
std::vector<std::string> &segments) const {
std::stringstream ss(path);
std::string segment;
while (std::getline(ss, segment, '/')) {
if (!segment.empty()) {
segments.push_back(segment);
}
}
}
bool comparePathSegments(const URL &other) const {
size_t min_size =
std::min(_path_segments.size(), other._path_segments.size());
for (size_t i = 0; i < min_size; ++i) {
if (_path_segments[i] != other._path_segments[i]) {
return false;
}
}
return true;
}
std::string _full_url;
std::vector<std::string> _path_segments;
};

View File

@ -6,7 +6,11 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/11 13:29:21 by mmoussou #+# #+# */
<<<<<<< HEAD
/* Updated: 2025/04/22 11:54:13 by mmoussou ### ########.fr */
=======
/* Updated: 2025/04/22 12:32:23 by adjoly ### ########.fr */
>>>>>>> 8129f45 (🏗 wip: added url class for easier manipulation)
/* */
/* ************************************************************************** */
@ -15,25 +19,32 @@
#ifndef __WEBSERV_WEBSERV_HPP__
#define __WEBSERV_WEBSERV_HPP__
#include <string>
#include <cstring>
#include <fstream>
#include <csignal>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string>
#include <sys/socket.h>
#include <unistd.h>
#include <vector>
#include <sstream>
#define auto __auto_type
#define range(x) x.begin(); it != x.end(); it++
#define prange(x) x->begin(); it != x->end(); it++
#define range(x) \
x.begin(); \
it != x.end(); \
it++
#define prange(x) \
x->begin(); \
it != x->end(); \
it++
#define BUFFER_SIZE 4096
namespace webserv {
} //-namespace webserv
} // namespace webserv
#endif // __WEBSERV_WEBSERV_HPP__