Permalink
Browse files

Added source files, Makefile etc. from cvs tag rel-0-87.

  • Loading branch information...
stealth committed Nov 29, 2011
1 parent 6baa8ee commit 7fe1662ed36d4d700c44f23c294eec3bcfa5f0d6
Showing with 2,161 additions and 0 deletions.
  1. +45 −0 Changelog
  2. +32 −0 LICENSE
  3. +32 −0 Makefile
  4. +20 −0 config.h
  5. BIN icons/back.gif
  6. BIN icons/back.png
  7. BIN icons/file.gif
  8. BIN icons/folder.gif
  9. BIN icons/folder.png
  10. +191 −0 log.cc
  11. +39 −0 log.h
  12. +745 −0 lonely.cc
  13. +173 −0 lonely.h
  14. +241 −0 main.cc
  15. +182 −0 misc.cc
  16. +51 −0 misc.h
  17. +126 −0 multicore.cc
  18. +13 −0 multicore.h
  19. +209 −0 socket.cc
  20. +62 −0 socket.h
View
@@ -0,0 +1,45 @@
0.87
----
+ Thu Feb 17
+ Add Date: string to HTTP replies so httpdate works
properly
0.86
----
+ Sat Okt 30 2010
+ Adding multicore support for Linux
0.85
----
+ Sat Jun 26 2010
+ Fixed a bug that lead to truncation of large files.
Content-Length was using %d rather than %zu :(
0.83
----
+ Wed Jun 16 2010
+ made mmap provider portable
0.82
----
+ Mon Jun 7 2010
+ Added log providers. For heavy loaded machines one can try to
get some benefit by using mmap or aio log provider in order to
prevent millions of write()s to disk.
0.80
----
+ Sun May 30 2010
+ Security: Fixed access to unmapped memory if large directories
are autoindexed
Thanks to Alexander Hagenah for sending a bug report
+ Security: Fixed handling of large amounts of "wget -r" for many
files, including potential out of bounds write to the poll
array
+ Introducing a timeout in which valid headers must arrive
in order to handle slow links and clients which may send large
requests
View
32 LICENSE
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2008 Sebastian Krahmer.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Sebastian Krahmer.
* 4. The name Sebastian Krahmer may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
View
@@ -0,0 +1,32 @@
CXX=c++ -Wall -O2
LD=c++
all: lhttpd
clean:
rm -f *.o
distclean: clean
rm -f lhttpd
lhttpd: lonely.o socket.o main.o misc.o log.o multicore.o
$(LD) lonely.o socket.o main.o misc.o log.o multicore.o -o lhttpd -lrt
multicore.o: multicore.cc multicore.h
$(CXX) -c multicore.cc
log.o: log.cc log.h
$(CXX) -c log.cc
misc.o: misc.cc misc.h
$(CXX) -c misc.cc
main.o: main.cc
$(CXX) -c main.cc
socket.o: socket.cc socket.h
$(CXX) -c socket.cc
lonely.o: lonely.cc lonely.h
$(CXX) -c lonely.cc
View
@@ -0,0 +1,20 @@
#ifndef __config_h__
#define __config_h__
#include <string>
#include <sys/types.h>
#include <stdint.h>
namespace Config
{
extern std::string root;
extern bool gen_index, virtual_hosts, is_chrooted;
extern std::string user, logfile;
extern uid_t user_uid, user_gid;
extern uint16_t port;
extern uint16_t log_granularity;
extern int cores, master;
}
#endif
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
191 log.cc
@@ -0,0 +1,191 @@
/*
* Copyright (C) 2010 Sebastian Krahmer.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Sebastian Krahmer.
* 4. The name Sebastian Krahmer may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <string>
#include <fcntl.h>
#include <unistd.h>
#include <cstring>
#include <errno.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <stdlib.h>
#include "log.h"
using namespace std;
static inline off_t next_aligned_size(off_t size)
{
return (size + 1024*1024 + 0x1000)&~(0x1000-1);
}
int log_provider::open_log(const string &logfile, const string &method)
{
struct stat st;
int flags = O_RDWR|O_CREAT;
if (method != "mmap")
flags |= O_APPEND;
log_fd = open(logfile.c_str(), flags, 0600);
if (log_fd < 0) {
err = "log_provider::open_log::open:";
err += strerror(errno);
return -1;
}
// safe default
do_log = &log_provider::write_log;
memset(&log_aio, 0, sizeof(log_aio));
log_area = (void *)-1;
log_index = 0;
log_size = 1<<20;
if (method == "aio")
do_log = &log_provider::aio_log;
else if (method == "mmap") {
if (fstat(log_fd, &st) < 0) {
err = "log_provider::open_log::fstat:";
err += strerror(errno);
return -1;
}
if (ftruncate(log_fd, st.st_size + log_size) < 0) {
err = "log_provider::open_log::ftruncate:";
err += strerror(errno);
return -1;
}
if ((log_area = mmap(NULL, log_size, PROT_READ|PROT_WRITE, MAP_SHARED,
log_fd, st.st_size)) == (void *)-1) {
err = "log_provider::open_log::mmap:";
err += strerror(errno);
return -1;
}
do_log = &log_provider::mmap_log;
}
return 0;
}
int log_provider::log(const string &msg)
{
return (this->*do_log)(msg);
}
int log_provider::write_log(const string &msg)
{
flock(log_fd, LOCK_EX);
ssize_t r = write(log_fd, msg.c_str(), msg.size());
flock(log_fd, LOCK_UN);
return (int)r;
}
int log_provider::mmap_log(const string &msg)
{
if (log_area == (void *)-1)
return -1;
if (log_index + (off_t)msg.size() >= log_size) {
struct stat st;
if (munmap(log_area, log_size) < 0) {
err = "log_provider::mmap_log::munmap:";
err += strerror(errno);
return -1;
}
if (fstat(log_fd, &st) < 0) {
err = "log_provider::open_log::fstat:";
err += strerror(errno);
return -1;
}
if (ftruncate(log_fd, st.st_size + log_size) < 0) {
err = "log_provider::open_log::ftruncate:";
err += strerror(errno);
return -1;
}
if ((log_area = mmap(NULL, log_size, PROT_READ|PROT_WRITE, MAP_SHARED,
log_fd, st.st_size)) == (void *)-1) {
err = "log_provider::open_log::mmap:";
err += strerror(errno);
return -1;
}
log_index = 0;
}
memcpy((char *)log_area + log_index, msg.c_str(), msg.size());
log_index += msg.size();
return 0;
}
int log_provider::aio_log(const string &msg)
{
int count = 0;
bool error = 0;
// finish last requests
if (log_aio.aio_fildes == log_fd) {
do {
++count;
} while (aio_error(&log_aio) == EINPROGRESS && count < 12);
if (count == 12) {
if (aio_cancel(log_fd, &log_aio) != AIO_CANCELED)
error = 1;
} else {
if (aio_return(&log_aio) <= 0)
error = 1;
}
}
// free(NULL) is defined
free((void *)log_aio.aio_buf);
memset(&log_aio, 0, sizeof(log_aio));
if (error)
return -1;
log_aio.aio_fildes = log_fd;
log_aio.aio_buf = strdup(msg.c_str());
log_aio.aio_nbytes = msg.size();
aio_write(&log_aio);
return 0;
}
log_provider::~log_provider()
{
close(log_fd);
}
View
39 log.h
@@ -0,0 +1,39 @@
#ifndef __log_h__
#define __log_h__
#include <string>
#include <sys/types.h>
#include <aio.h>
class log_provider {
private:
int log_fd;
struct aiocb log_aio;
void *log_area;
off_t log_index, log_size;
int write_log(const std::string &);
int mmap_log(const std::string &);
int aio_log(const std::string &);
int (log_provider::*do_log)(const std::string &);
std::string err;
public:
const char *why() { return err.c_str(); };
int log(const std::string &);
int open_log(const std::string &, const std::string &);
log_provider() {};
~log_provider();
};
#endif
Oops, something went wrong.

0 comments on commit 7fe1662

Please sign in to comment.