mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-09 04:22:04 -04:00
Prepare HTTP support
This commit is contained in:
parent
7d57d2a019
commit
bf78df3dcf
32
kernel/include/net/http_layer.hpp
Normal file
32
kernel/include/net/http_layer.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
//=======================================================================
|
||||
// Copyright Baptiste Wicht 2013-2016.
|
||||
// Distributed under the terms of the MIT License.
|
||||
// (See accompanying file LICENSE or copy at
|
||||
// http://www.opensource.org/licenses/MIT)
|
||||
//=======================================================================
|
||||
|
||||
#ifndef NET_HTTP_LAYER_H
|
||||
#define NET_HTTP_LAYER_H
|
||||
|
||||
#include <types.hpp>
|
||||
|
||||
#include "net/ethernet_layer.hpp"
|
||||
#include "net/ip_layer.hpp"
|
||||
#include "net/network.hpp"
|
||||
|
||||
namespace network {
|
||||
|
||||
namespace http {
|
||||
|
||||
void decode(network::interface_descriptor& interface, network::ethernet::packet& packet);
|
||||
|
||||
std::expected<network::ethernet::packet> kernel_prepare_packet(network::interface_descriptor& interface, const packet_descriptor& descriptor);
|
||||
std::expected<network::ethernet::packet> user_prepare_packet(char* buffer, network::interface_descriptor& interface, const packet_descriptor* descriptor);
|
||||
|
||||
std::expected<void> finalize_packet(network::interface_descriptor& interface, network::ethernet::packet& p);
|
||||
|
||||
} // end of http namespace
|
||||
|
||||
} // end of network namespace
|
||||
|
||||
#endif
|
54
kernel/src/net/http_layer.cpp
Normal file
54
kernel/src/net/http_layer.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
//=======================================================================
|
||||
// Copyright Baptiste Wicht 2013-2016.
|
||||
// Distributed under the terms of the MIT License.
|
||||
// (See accompanying file LICENSE or copy at
|
||||
// http://www.opensource.org/licenses/MIT)
|
||||
//=======================================================================
|
||||
|
||||
#include "net/http_layer.hpp"
|
||||
#include "net/tcp_layer.hpp"
|
||||
|
||||
#include "kernel_utils.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
} //end of anonymous namespace
|
||||
|
||||
void network::http::decode(network::interface_descriptor& /*interface*/, network::ethernet::packet& packet) {
|
||||
packet.tag(3, packet.index);
|
||||
|
||||
logging::logf(logging::log_level::TRACE, "http: Start HTTP packet handling\n");
|
||||
|
||||
//TODO ?
|
||||
|
||||
//TODO network::propagate_packet(packet, network::socket_protocol::HTTP);
|
||||
}
|
||||
|
||||
std::expected<network::ethernet::packet> network::http::kernel_prepare_packet(network::interface_descriptor& interface, const packet_descriptor& descriptor) {
|
||||
// Ask the TCP layer to craft a packet
|
||||
//network::tcp::packet_descriptor desc{descriptor.target_ip, descriptor.source_port, 80, descriptor.payload_size};
|
||||
//auto packet = network::tcp::kernel_prepare_packet(interface, desc);
|
||||
|
||||
//if (packet) {
|
||||
//packet.tag(3, packet.index);
|
||||
//}
|
||||
|
||||
//return packet;
|
||||
}
|
||||
|
||||
std::expected<network::ethernet::packet> network::http::user_prepare_packet(char* buffer, network::interface_descriptor& interface, const packet_descriptor* descriptor) {
|
||||
// Ask the TCP layer to craft a packet
|
||||
//network::tcp::packet_descriptor desc{descriptor->target_ip, descriptor->source_port, 80, descriptor->payload_size};
|
||||
//auto packet = network::tcp::user_prepare_packet(buffer, interface, &desc);
|
||||
|
||||
//if (packet) {
|
||||
//packet.tag(3, packet.index);
|
||||
//}
|
||||
|
||||
//return packet;
|
||||
}
|
||||
|
||||
std::expected<void> network::http::finalize_packet(network::interface_descriptor& interface, network::ethernet::packet& p) {
|
||||
// Give the packet to the TCP layer for finalization
|
||||
return network::tcp::finalize_packet(interface, p);
|
||||
}
|
@ -133,6 +133,15 @@ struct packet_descriptor {
|
||||
|
||||
} // end of namespace icmp
|
||||
|
||||
namespace http {
|
||||
|
||||
struct packet_descriptor {
|
||||
size_t payload_size;
|
||||
ip::address target_ip;
|
||||
};
|
||||
|
||||
} // end of http namespace
|
||||
|
||||
namespace dns {
|
||||
|
||||
struct header {
|
||||
|
Loading…
x
Reference in New Issue
Block a user