//
// webserver.h
//
// Simple HTTP server sample for sanos
//

#ifndef __WEBSERVER_H_
#define __WEBSERVER_H_

#include <unistd.h>
#include <stdarg.h>
#include <time.h>
#include <sys/stat.h>
#include <dirent.h>

#include <string>
#include <vector>

#define SERVER "webserver/1.0"
#define PROTOCOL "HTTP/1.0"
#define PORT 80

class WebServer
{
public:
	void ReadyToRun();

private:
	const char *GetMimeType( const char *name );
	const char* RFC1123FMT( time_t t );
	const char* RF850FMT( time_t t );
	void SendHeaders( int fd, int status, const char *title, const char *extra, const char *mime, int length, time_t date );
	void SendError( int fd, int status, const char *title, const char *extra, const char *text );
	void SendFile( int fd, const char *path, struct stat *statbuf );
	int IsDir( int fd, std::string &path, struct stat statbuf );
	int Process( int fd );
};

#endif