diff --git a/kernel/include/net/http_layer.hpp b/kernel/include/net/http_layer.hpp new file mode 100644 index 00000000..7dd76fb6 --- /dev/null +++ b/kernel/include/net/http_layer.hpp @@ -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 + +#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 kernel_prepare_packet(network::interface_descriptor& interface, const packet_descriptor& descriptor); +std::expected user_prepare_packet(char* buffer, network::interface_descriptor& interface, const packet_descriptor* descriptor); + +std::expected finalize_packet(network::interface_descriptor& interface, network::ethernet::packet& p); + +} // end of http namespace + +} // end of network namespace + +#endif diff --git a/kernel/src/net/http_layer.cpp b/kernel/src/net/http_layer.cpp new file mode 100644 index 00000000..adb2e496 --- /dev/null +++ b/kernel/src/net/http_layer.cpp @@ -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::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::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 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); +} diff --git a/tlib/include/tlib/net_constants.hpp b/tlib/include/tlib/net_constants.hpp index de66f748..b127417a 100644 --- a/tlib/include/tlib/net_constants.hpp +++ b/tlib/include/tlib/net_constants.hpp @@ -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 {