Browse Source

merged from taskrambler

release0.1.5
Georg Hopp 13 years ago
parent
commit
fd111159de
  1. 277
      .doxygen
  2. 43
      .gitignore
  3. 1
      AUTHORS
  4. 674
      COPYING
  5. 424
      ChangeLog
  6. 12
      Makefile.am
  7. 34
      Makefile.am.coverage
  8. 0
      NEWS
  9. 29
      README
  10. 8
      TODO
  11. 50
      assets/html/main.html
  12. BIN
      assets/image/waldschrat.jpg
  13. 37
      assets/js/init.js
  14. 9266
      assets/js/jquery-1.7.1.js
  15. 4
      assets/js/jquery-1.7.1.min.js
  16. 78
      assets/js/serverval.js
  17. 78
      assets/js/session.js
  18. 58
      assets/style/common.css
  19. 7
      bootstrap
  20. 17
      certs/server.crt
  21. 15
      certs/server.key
  22. 63
      configure.ac
  23. 11
      include/auth.h
  24. 45
      include/auth/auth.h
  25. 54
      include/auth/credential.h
  26. 49
      include/auth/interface/auth.h
  27. 41
      include/auth/ldap.h
  28. 81
      include/cbuf.h
  29. 10
      include/class.h
  30. 128
      include/class/class.h
  31. 59
      include/class/interface.h
  32. 57
      include/class/interface/class.h
  33. 48
      include/commons.h
  34. 10
      include/hash.h
  35. 42
      include/hash/hash.h
  36. 45
      include/hash/interface/hashable.h
  37. 42
      include/hash/value.h
  38. 17
      include/http.h
  39. 51
      include/http/cookie.h
  40. 48
      include/http/header.h
  41. 47
      include/http/interface/http_intro.h
  42. 58
      include/http/message.h
  43. 70
      include/http/parser.h
  44. 51
      include/http/request.h
  45. 59
      include/http/response.h
  46. 61
      include/http/worker.h
  47. 65
      include/http/writer.h
  48. 40
      include/interface/observer.h
  49. 46
      include/interface/subject.h
  50. 9
      include/logger.h
  51. 45
      include/logger/interface/logger.h
  52. 57
      include/logger/logger.h
  53. 56
      include/queue.h
  54. 63
      include/server.h
  55. 47
      include/session.h
  56. 47
      include/socket.h
  57. 10
      include/stream.h
  58. 45
      include/stream/interface/reader.h
  59. 45
      include/stream/interface/writer.h
  60. 49
      include/stream/stream.h
  61. 33
      include/utils/hash.h
  62. 38
      include/utils/http.h
  63. 34
      include/utils/memory.h
  64. 33
      include/utils/signalHandling.h
  65. 77
      m4/gcov.m4
  66. 32
      src/Makefile.am
  67. 6
      src/auth/Makefile.am
  68. 85
      src/auth/credential.c
  69. 42
      src/auth/interface/auth.c
  70. 109
      src/auth/ldap.c
  71. 13
      src/cbuf/Makefile.am
  72. 33
      src/cbuf/addr_index.c
  73. 125
      src/cbuf/cbuf.c
  74. 32
      src/cbuf/empty.c
  75. 41
      src/cbuf/get_data.c
  76. 33
      src/cbuf/get_free.c
  77. 49
      src/cbuf/get_line.c
  78. 31
      src/cbuf/get_read.c
  79. 31
      src/cbuf/get_write.c
  80. 36
      src/cbuf/inc_read.c
  81. 36
      src/cbuf/inc_write.c
  82. 31
      src/cbuf/is_empty.c
  83. 33
      src/cbuf/is_locked.c
  84. 31
      src/cbuf/lock.c
  85. 33
      src/cbuf/memchr.c
  86. 60
      src/cbuf/read.c
  87. 31
      src/cbuf/release.c
  88. 45
      src/cbuf/set_data.c
  89. 34
      src/cbuf/skip_non_alpha.c
  90. 52
      src/cbuf/write.c
  91. 6
      src/class/Makefile.am
  92. 64
      src/class/interface.c
  93. 83
      src/class/interface/i_class.c
  94. 9
      src/hash/Makefile.am
  95. 53
      src/hash/add.c
  96. 46
      src/hash/delete.c
  97. 47
      src/hash/each.c
  98. 46
      src/hash/get.c
  99. 63
      src/hash/hash.c
  100. 51
      src/hash/interface/hashable.c

277
.doxygen

@ -0,0 +1,277 @@
# Doxyfile 1.7.3
#---------------------------------------------------------------------------
# Project related configuration options
#---------------------------------------------------------------------------
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = Server
PROJECT_NUMBER = 0.0.1
PROJECT_BRIEF = "HTTP/REST server implementation"
PROJECT_LOGO =
OUTPUT_DIRECTORY = docs
CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English
BRIEF_MEMBER_DESC = YES
REPEAT_BRIEF = YES
ABBREVIATE_BRIEF =
ALWAYS_DETAILED_SEC = NO
INLINE_INHERITED_MEMB = NO
FULL_PATH_NAMES = YES
STRIP_FROM_PATH =
STRIP_FROM_INC_PATH =
SHORT_NAMES = NO
JAVADOC_AUTOBRIEF = NO
QT_AUTOBRIEF = NO
MULTILINE_CPP_IS_BRIEF = NO
INHERIT_DOCS = YES
SEPARATE_MEMBER_PAGES = NO
TAB_SIZE = 8
ALIASES =
OPTIMIZE_OUTPUT_FOR_C = YES
OPTIMIZE_OUTPUT_JAVA = NO
OPTIMIZE_FOR_FORTRAN = NO
OPTIMIZE_OUTPUT_VHDL = NO
EXTENSION_MAPPING =
BUILTIN_STL_SUPPORT = NO
CPP_CLI_SUPPORT = YES
SIP_SUPPORT = NO
IDL_PROPERTY_SUPPORT = YES
DISTRIBUTE_GROUP_DOC = NO
SUBGROUPING = YES
TYPEDEF_HIDES_STRUCT = NO
SYMBOL_CACHE_SIZE = 0
#---------------------------------------------------------------------------
# Build related configuration options
#---------------------------------------------------------------------------
EXTRACT_ALL = YES
EXTRACT_PRIVATE = NO
EXTRACT_STATIC = NO
EXTRACT_LOCAL_CLASSES = YES
EXTRACT_LOCAL_METHODS = YES
EXTRACT_ANON_NSPACES = YES
HIDE_UNDOC_MEMBERS = NO
HIDE_UNDOC_CLASSES = NO
HIDE_FRIEND_COMPOUNDS = NO
HIDE_IN_BODY_DOCS = NO
INTERNAL_DOCS = YES
CASE_SENSE_NAMES = YES
HIDE_SCOPE_NAMES = NO
SHOW_INCLUDE_FILES = YES
FORCE_LOCAL_INCLUDES = NO
INLINE_INFO = YES
SORT_MEMBER_DOCS = YES
SORT_BRIEF_DOCS = NO
SORT_MEMBERS_CTORS_1ST = NO
SORT_GROUP_NAMES = NO
SORT_BY_SCOPE_NAME = NO
STRICT_PROTO_MATCHING = NO
GENERATE_TODOLIST = YES
GENERATE_TESTLIST = YES
GENERATE_BUGLIST = YES
GENERATE_DEPRECATEDLIST= YES
ENABLED_SECTIONS =
MAX_INITIALIZER_LINES = 30
SHOW_USED_FILES = YES
SHOW_DIRECTORIES = NO
SHOW_FILES = YES
SHOW_NAMESPACES = YES
FILE_VERSION_FILTER =
LAYOUT_FILE =
#---------------------------------------------------------------------------
# configuration options related to warning and progress messages
#---------------------------------------------------------------------------
QUIET = NO
WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = NO
WARN_FORMAT = "$file:$line: $text"
WARN_LOGFILE =
#---------------------------------------------------------------------------
# configuration options related to the input files
#---------------------------------------------------------------------------
INPUT =
INPUT_ENCODING = UTF-8
FILE_PATTERNS =
RECURSIVE = YES
EXCLUDE =
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS = */tests/* */doc/* */docs/* */.git/*
EXCLUDE_SYMBOLS =
EXAMPLE_PATH =
EXAMPLE_PATTERNS =
EXAMPLE_RECURSIVE = NO
IMAGE_PATH =
INPUT_FILTER =
FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO
FILTER_SOURCE_PATTERNS =
#---------------------------------------------------------------------------
# configuration options related to source browsing
#---------------------------------------------------------------------------
SOURCE_BROWSER = YES
INLINE_SOURCES = YES
STRIP_CODE_COMMENTS = YES
REFERENCED_BY_RELATION = NO
REFERENCES_RELATION = NO
REFERENCES_LINK_SOURCE = YES
USE_HTAGS = NO
VERBATIM_HEADERS = YES
#---------------------------------------------------------------------------
# configuration options related to the alphabetical class index
#---------------------------------------------------------------------------
ALPHABETICAL_INDEX = YES
COLS_IN_ALPHA_INDEX = 5
IGNORE_PREFIX =
#---------------------------------------------------------------------------
# configuration options related to the HTML output
#---------------------------------------------------------------------------
GENERATE_HTML = YES
HTML_OUTPUT = html
HTML_FILE_EXTENSION = .html
HTML_HEADER =
HTML_FOOTER =
HTML_STYLESHEET =
HTML_COLORSTYLE_HUE = 220
HTML_COLORSTYLE_SAT = 100
HTML_COLORSTYLE_GAMMA = 80
HTML_TIMESTAMP = YES
HTML_ALIGN_MEMBERS = YES
HTML_DYNAMIC_SECTIONS = NO
GENERATE_DOCSET = NO
DOCSET_FEEDNAME = "Doxygen generated docs"
DOCSET_BUNDLE_ID = org.doxygen.Project
DOCSET_PUBLISHER_ID = org.doxygen.Publisher
DOCSET_PUBLISHER_NAME = Publisher
GENERATE_HTMLHELP = NO
CHM_FILE =
HHC_LOCATION =
GENERATE_CHI = NO
CHM_INDEX_ENCODING =
BINARY_TOC = NO
TOC_EXPAND = NO
GENERATE_QHP = NO
QCH_FILE =
QHP_NAMESPACE = org.doxygen.Project
QHP_VIRTUAL_FOLDER = doc
QHP_CUST_FILTER_NAME =
QHP_CUST_FILTER_ATTRS =
QHP_SECT_FILTER_ATTRS =
QHG_LOCATION =
GENERATE_ECLIPSEHELP = NO
ECLIPSE_DOC_ID = org.doxygen.Project
DISABLE_INDEX = NO
ENUM_VALUES_PER_LINE = 4
GENERATE_TREEVIEW = YES
USE_INLINE_TREES = YES
TREEVIEW_WIDTH = 250
EXT_LINKS_IN_WINDOW = NO
FORMULA_FONTSIZE = 10
FORMULA_TRANSPARENT = YES
USE_MATHJAX = NO
MATHJAX_RELPATH = http://www.mathjax.org/mathjax
SEARCHENGINE = YES
SERVER_BASED_SEARCH = NO
#---------------------------------------------------------------------------
# configuration options related to the LaTeX output
#---------------------------------------------------------------------------
GENERATE_LATEX = YES
LATEX_OUTPUT = latex
LATEX_CMD_NAME = latex
MAKEINDEX_CMD_NAME = makeindex
COMPACT_LATEX = NO
PAPER_TYPE = a4
EXTRA_PACKAGES =
LATEX_HEADER =
PDF_HYPERLINKS = YES
USE_PDFLATEX = YES
LATEX_BATCHMODE = NO
LATEX_HIDE_INDICES = NO
LATEX_SOURCE_CODE = NO
#---------------------------------------------------------------------------
# configuration options related to the RTF output
#---------------------------------------------------------------------------
GENERATE_RTF = NO
RTF_OUTPUT = rtf
COMPACT_RTF = NO
RTF_HYPERLINKS = NO
RTF_STYLESHEET_FILE =
RTF_EXTENSIONS_FILE =
#---------------------------------------------------------------------------
# configuration options related to the man page output
#---------------------------------------------------------------------------
GENERATE_MAN = NO
MAN_OUTPUT = man
MAN_EXTENSION = .3
MAN_LINKS = NO
#---------------------------------------------------------------------------
# configuration options related to the XML output
#---------------------------------------------------------------------------
GENERATE_XML = NO
XML_OUTPUT = xml
XML_SCHEMA =
XML_DTD =
XML_PROGRAMLISTING = YES
#---------------------------------------------------------------------------
# configuration options for the AutoGen Definitions output
#---------------------------------------------------------------------------
GENERATE_AUTOGEN_DEF = NO
#---------------------------------------------------------------------------
# configuration options related to the Perl module output
#---------------------------------------------------------------------------
GENERATE_PERLMOD = NO
PERLMOD_LATEX = NO
PERLMOD_PRETTY = YES
PERLMOD_MAKEVAR_PREFIX =
#---------------------------------------------------------------------------
# Configuration options related to the preprocessor
#---------------------------------------------------------------------------
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = NO
EXPAND_ONLY_PREDEF = NO
SEARCH_INCLUDES = YES
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED =
EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = NO
#---------------------------------------------------------------------------
# Configuration::additions related to external references
#---------------------------------------------------------------------------
TAGFILES =
GENERATE_TAGFILE =
ALLEXTERNALS = NO
EXTERNAL_GROUPS = YES
PERL_PATH = /usr/bin/perl
#---------------------------------------------------------------------------
# Configuration options related to the dot tool
#---------------------------------------------------------------------------
CLASS_DIAGRAMS = YES
MSCGEN_PATH =
HIDE_UNDOC_RELATIONS = YES
HAVE_DOT = YES
DOT_NUM_THREADS = 0
DOT_FONTNAME = Helvetica
DOT_FONTSIZE = 10
DOT_FONTPATH =
CLASS_GRAPH = YES
COLLABORATION_GRAPH = YES
GROUP_GRAPHS = YES
UML_LOOK = YES
TEMPLATE_RELATIONS = NO
INCLUDE_GRAPH = YES
INCLUDED_BY_GRAPH = YES
CALL_GRAPH = YES
CALLER_GRAPH = YES
GRAPHICAL_HIERARCHY = YES
DIRECTORY_GRAPH = YES
DOT_IMAGE_FORMAT = png
DOT_PATH =
DOTFILE_DIRS =
MSCFILE_DIRS =
DOT_GRAPH_MAX_NODES = 50
MAX_DOT_GRAPH_DEPTH = 0
DOT_TRANSPARENT = YES
DOT_MULTI_TARGETS = NO
GENERATE_LEGEND = YES
DOT_CLEANUP = YES

43
.gitignore

@ -1,17 +1,30 @@
# Object files
.*.swp
*.o
# Libraries
*.lib
*.a
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.gcda
*.gcno
.dirstamp
.deps/
Makefile
Makefile.in
/config*
m4/
/docs/
/INSTALL
coverage.base
coverage.run
coverage.info
coveragereport/
*.m4
/autom4te.cache/
/compile
/depcomp
/docs/
/install-sh
/libtool
/ltmain.sh
/missing
stamp-h1
src/taskrambler
/tests/*Test
gmon.out

1
AUTHORS

@ -0,0 +1 @@
Georg Hopp <georg@steffers.org>

674
COPYING

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

424
ChangeLog

@ -0,0 +1,424 @@
2012-02-23 17:40:00 +0100 Georg Hopp
* add cookie header again (HEAD, origin/master, origin/HEAD, master)
2012-02-23 16:41:36 +0100 Georg Hopp
* optmize header search
2012-02-23 13:02:23 +0100 Georg Hopp
* changed all string operation within header handling with fixed length mem operations, preventing multiple iterations over these strings. In theory this should improve performance in reality it seems that it is worse...CHECK WHY
2012-02-23 00:05:25 +0100 Georg Hopp
* fix initialization of search value
2012-02-22 21:50:21 +0100 Georg Hopp
* ed
2012-02-22 21:49:52 +0100 Georg Hopp
* structural changes for worker/process. @TODO actually i have no idea why this happens.
2012-02-22 12:19:40 +0100 Georg Hopp
* fix memory problems occured with latest changes
2012-02-22 09:03:40 +0100 Georg Hopp
* fixed bug in keep-alive check arised by implementation if #10
2012-02-22 08:51:05 +0100 Georg Hopp
* add forgotten jquery assets
2012-02-22 08:48:43 +0100 Georg Hopp
* closes #10: values for header ids are now stored in a char ** making multiple values for one id possible. Additionally added a jquery action that delivers the jquery java script and use it on the me action
2012-02-21 13:01:38 +0100 Georg Hopp
* now when a constructor returns -1 the new call will in turn call the destructor effectively freeing all resources. ATTENTION: now the destructor has to be aware that it might be called with a not completely initialized object. To make this more ease there is the FREE makro with the corresponding ffree that does NULL pointer checking and the destructor checks for NULL pointer too. Additionally the handle_accept now handles _SC_OPEN_MAX - 10 connections. The 10 are reserved for internal usage.
2012-02-21 09:45:01 +0100 Georg Hopp
* now a child is spawned and writes random values in a shared memory segment. These values will be shown in the me action
2012-02-20 21:36:55 +0100 Georg Hopp
* some code cleanups...no changes in the logic
2012-02-20 18:08:23 +0100 Georg Hopp
* move sdbm implementation in one file.
2012-02-20 17:16:44 +0100 Georg Hopp
* changed /**/ single line comments to //
2012-02-20 14:55:46 +0100 Georg Hopp
* start documenting this whole stuff...well at least add a copyright information in each file
2012-02-20 10:10:29 +0100 Georg Hopp
* first very crude, not complete, experimental 304 test implementation
2012-02-20 07:55:06 +0100 Georg Hopp
* disconnect on invalid request line
2012-02-19 20:12:40 +0100 Georg Hopp
* now incomplete requests should no longer block the complete server. Tested with \'echo -en "GET / HTTP\r\nConn" | nc -w 600 localhost 11212\' and then doing requests from my browser. @TODO: cleanup those stuff, check if a not correctly response reading would block the server.
2012-02-19 18:28:30 +0100 Georg Hopp
* increase writebuffer size a lot.
2012-02-19 18:15:55 +0100 Georg Hopp
* fixed the non keep-alive performance issue as well as i lower memory usage by using a single read and write circular buffer for every connection. @TODO: i noticed a server hang while getting large data (my image) with non keep-alive connections. Additionally an incomplete keep-alive request might stop the server now as the lock on the read buffer will not be released.
2012-02-19 15:41:48 +0100 Georg Hopp
* another try with the shmen trick...this time use MAP_ANONYMOUS ... as GNU extension.
2012-02-19 14:33:42 +0100 Georg Hopp
* Merge remote branch 'origin/master'
2012-02-19 12:13:52 +0100 Georg Hopp
* added missing header file to repo
2012-02-19 11:35:15 +0100 Georg Hopp
* another try with a shared memory based ringbuffer...this performs well for keep-alive sessions but is much slower without. actually i am not sure why but most likely the shared memory setup is quite expensive. @TODO: make a profiling.
2012-02-18 21:08:32 +0100 Georg Hopp
* fix inf loop. @TODO: This whole handling has to be cleaned.
2012-02-18 20:50:01 +0100 Georg Hopp
* this change hopefully makes the shm trick work on amd64
2012-02-18 20:12:27 +0100 Georg Hopp
* lots of changes but primarily change the request parser to use a ringbuffer. The ringbuffer is implemented using the shared memory trick.
2012-02-15 12:30:33 +0100 Georg Hopp
* some more cleanups in the server code. Removing not needed header includes
2012-02-15 12:17:39 +0100 Georg Hopp
* Merge branch 'master' of 192.168.100.2:/var/lib/git/server
2012-02-15 12:17:00 +0100 Georg Hopp
* now the separated http worker works. Changed some size_t to ssize_t as i use -1 and -2 es error indicator in my server and fixed caculation of remainig buffer size in reader
2012-02-15 09:38:32 +0100 Georg Hopp
* separated the server completely from the http processing
2012-02-15 06:19:52 +0100 Georg Hopp
* add subject/observer interface
2012-02-15 06:19:52 +0100 Georg Hopp
* add subject/observer interface
2012-02-15 04:55:46 +0100 Georg Hopp
* fix infinite busy loop in run
2012-02-15 04:44:38 +0100 Georg Hopp
* dynamically get and free buffer for response write pipe now
2012-02-14 21:32:38 +0100 Georg Hopp
* increase write buffer
2012-02-13 21:27:47 +0100 Georg Hopp
* use one dynamic buffer less and save at least one write on small responses
2012-02-13 18:25:36 +0100 Georg Hopp
* removed generated docs
2012-02-13 17:55:52 +0100 Georg Hopp
* fixed bug in new response handling
2012-02-13 17:29:35 +0100 Georg Hopp
* better response handling but still buggy with stream piping
2012-02-13 09:46:39 +0100 Georg Hopp
* now load image from actual server
2012-02-13 09:39:21 +0100 Georg Hopp
* first working version of content delivery from file....very crude... @TODO: rewrite complete response handline.
2012-02-12 20:39:12 +0100 Georg Hopp
* more generalizing of response writing (implemented a response writer...now it should be possible to implement a stream writer for images
2012-02-12 12:43:56 +0100 Georg Hopp
* make http request and response childs of a common parent http message
2012-02-12 04:13:54 +0100 Georg Hopp
* remove now obsoleted header_sort
2012-02-12 04:05:38 +0100 Georg Hopp
* change response to tree based header storage and make everything work.
2012-02-12 00:05:13 +0100 Georg Hopp
* changed header hashing to use btree (GNU only). @TODO: make this conditional for other systems. Removed the qsort calls on server->fds making O(2nlogn) to O(n)
2012-02-11 13:52:32 +0100 Georg Hopp
* daemonize testserver now
2012-02-11 12:47:01 +0100 Georg Hopp
* fix seaks and hangs after adding response object (mostly not related with the response object but how i integated it into serverRun
2012-02-10 19:57:57 +0100 Georg Hopp
* started a response handler and changed serverRun to use it for its response
2012-02-10 12:42:04 +0100 Georg Hopp
* fixed bug at server destructor
2012-02-10 09:59:41 +0100 Georg Hopp
* reset keep_live flag on connection close
2012-02-10 09:52:27 +0100 Georg Hopp
* made a first cruel handling for keep-alive and non keep-alive requests. @TODO: this MUST BE cleaned
2012-02-10 08:14:31 +0100 Georg Hopp
* now only use keep-alive....
2012-02-10 06:36:43 +0100 Georg Hopp
* moved request_parser.h and request_queue.h in separeate request subfolder
2012-02-10 06:22:39 +0100 Georg Hopp
* fix rather nasty reentrance bug
2012-02-10 05:52:50 +0100 Georg Hopp
* fix bug that arose in rewrite of header get and results in an ugly memory leak, as well as no headers would be found any more
2012-02-10 00:27:51 +0100 Georg Hopp
* fix memory leak created while changing things
2012-02-09 22:39:08 +0100 Georg Hopp
* updated docs
2012-02-09 22:34:32 +0100 Georg Hopp
* start split of request parser
2012-02-09 11:44:17 +0100 Georg Hopp
* no more request body debig output
2012-02-09 11:32:28 +0100 Georg Hopp
* add missing header_get to repo and build header hash only from lowercase letters now as it seems header identifier should be case insensitive
2012-02-09 09:34:21 +0100 Georg Hopp
* access to headers via hash, read body (actually only with content-length header should also look for content-encoding)
2012-02-08 16:51:49 +0100 Georg Hopp
* fix handling of remote close - i should have another eye on this...there still seems to be something wrong.
2012-02-08 15:04:52 +0100 Georg Hopp
* fixed some warnings
2012-02-08 13:12:59 +0100 Georg Hopp
* changed documentation
2012-02-08 13:05:23 +0100 Georg Hopp
* added first generated documentation
2012-02-08 12:14:44 +0100 Georg Hopp
* oops commit...forgot to add request_queue.c
2012-02-08 11:52:30 +0100 Georg Hopp
* found the file handle lost...made a first workaround and added an todo.
2012-02-08 10:21:04 +0100 Georg Hopp
* changed request handling. @TODO: I still seem to have the problem that the file handles are not closed and freed correctly as the service refuses connections after about a 1000.
2012-02-07 14:20:00 +0100 Georg Hopp
* now stuff seems to work correct even if read does not provide a complete request (tested with telnet)
2012-02-07 13:41:49 +0100 Georg Hopp
* now each HttpRequestParser initializes its own request queue and enqueus completed requests there. The server now gets the queue and prints completed requests.
2012-02-07 11:12:30 +0100 Georg Hopp
* started filling out a request object with the parser
2012-02-07 09:29:59 +0100 Georg Hopp
* porformance improvement in parsing process (no longer do alloc and free on each line)
2012-02-07 08:52:18 +0100 Georg Hopp
* basic request parsing (line by line) implemented
2012-02-06 16:08:13 +0100 Georg Hopp
* split server implementation for readability
2012-02-06 11:35:40 +0100 Georg Hopp
* free reader (HttpRequestParser) when connection is closed
2012-02-06 11:20:00 +0100 Georg Hopp
* add StreamReader interface, modify HttpRequestParser and Server to use it
2012-02-06 11:15:00 +0100 Georg Hopp
* add missing include to stdarg.h
2012-02-06 10:45:33 +0100 Georg Hopp
* implement clone selector
2012-02-06 10:43:59 +0100 Georg Hopp
* add ability to call interface methods with return value
2012-02-06 02:37:55 +0100 Georg Hopp
* make build system work again
2012-02-06 02:37:24 +0100 Georg Hopp
* remove inline stuff for now ... add carefully again later perhaps
2012-02-06 00:57:26 +0100 Georg Hopp
* and also mod conigure.ac
2012-02-06 00:55:44 +0100 Georg Hopp
* makefile modification for new class stuff
2012-02-05 22:55:16 +0100 Georg Hopp
* changed class tool. Now multiple interface per class are supported as well as simple inheritence.
2012-02-05 22:47:10 +0100 Georg Hopp
* some latest work
2012-02-05 22:44:59 +0100 Georg Hopp
* added some documentation
2012-02-05 22:42:37 +0100 Georg Hopp
* changes related to server code
2012-01-19 16:41:41 +0100 Georg Hopp
* added some valueable thought about cclass and how this structure might evolve to a real class
2012-01-18 07:52:07 +0100 Georg Hopp
* add testserver and did some fixes not shown by my incomplete tests
2012-01-17 15:40:07 +0100 Georg Hopp
* more notes
2012-01-17 15:04:33 +0100 Georg Hopp
* add some thought
2012-01-17 14:49:49 +0100 Georg Hopp
* changed from select(UNIX) to poll(POSIX)
2012-01-16 18:39:01 +0100 Georg Hopp
* work on server_run
2012-01-16 17:05:57 +0100 Georg Hopp
* move test under docs dir
2012-01-16 17:05:08 +0100 Georg Hopp
* simply copy signal handling code from gameserver project
2012-01-16 16:04:11 +0100 Georg Hopp
* more work on socket handling stuff... @TODO think about renaming it to connection as it only handles TCP sockets
2012-01-16 13:48:05 +0100 Georg Hopp
* add info text about file handle passing and ported more stuff from my old server structure
2012-01-16 08:05:15 +0100 Georg Hopp
* reflect changes in configure.ac
2012-01-13 22:46:45 +0100 Georg Hopp
* add daemonize code from other project. (Might be integrated in a future class but i am not sure right now
2012-01-13 22:16:17 +0100 Georg Hopp
* logger now works and has some basic testing
2012-01-13 22:15:03 +0100 Georg Hopp
* change cclass so that the internal structure is no longer visible by the rest of the code
2012-01-13 16:06:02 +0100 Georg Hopp
* some fixes on first logger tests
2012-01-13 15:54:22 +0100 Georg Hopp
* initial checkin

12
Makefile.am

@ -0,0 +1,12 @@
ACLOCAL_AMFLAGS = -I m4
#bin_PROGRAMS = create_token
#create_token_SOURCES = base64.c createToken.c
#create_token_LDADD = src/libtoken.la $(LIBOBJS)
#create_token_CFLAGS = -Wall -I include
EXTRA_DIST = include assets certs
SUBDIRS = src tests
include $(top_srcdir)/Makefile.am.coverage

34
Makefile.am.coverage

@ -0,0 +1,34 @@
# Coverage targets
#if HAVE_GCOV
.PHONY: clean-gcda
clean-gcda:
@echo Removing old coverage results
-find -name '*.gcda' -print | xargs -r rm
.PHONY: coverage-html generate-coverage-html clean-coverage-html
coverage-html: clean-gcda
-$(MAKE) -C tests $(AM_MAKEFLAGS) -k check-build
$(MAKE) $(AM_MAKEFLAGS) init-coverage-html
-$(MAKE) $(AM_MAKEFLAGS) -k check
$(MAKE) $(AM_MAKEFLAGS) generate-coverage-html
init-coverage-html:
$(LCOV) -d $(top_builddir) -z
$(LCOV) -d $(top_builddir) -c -i -o coverage.base
generate-coverage-html:
@echo Collecting coverage data
$(LCOV) -d $(top_builddir) -c -o coverage.run --gcov-tool /usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3/gcov
$(LCOV) -d $(top_builddir) -a ./coverage.base -a ./coverage.run -o coverage.info
LANG=C $(GENHTML) --prefix $(top_builddir) --output-directory coveragereport --title "Code Coverage" --legend --branch-coverage --show-details coverage.run
clean-coverage-html: clean-gcda
-$(LCOV) --directory $(top_builddir) -z
-rm -rf coverage.info coveragereport
clean-local: clean-coverage-html
#endif # HAVE_GCOV

0
NEWS

29
README

@ -0,0 +1,29 @@
Actually this is some kind of server toolkit, also containing
a class and interface toolkit for C.
I use a gcc preprocessor extension to use empty variadoc
argument lists so actually this is gcc only code.
This should become a server that has a dynamic time-sliced part
that updates an internal state all the time.
Clients might connect as they want and get some information
from the server.
The server should scale in two manners.
New instances should be able to handle connection and get
updates about the computed state.
Additionally new instances might hold their own state which
all other instances might update.
In a first run the state might be something simple as a
matrix where every field hold a unique value. e.g.
-------------
|1|4|a|j|k|9|
-------------
|1|4|a|j|k|9|
-------------
|1|4|a|j|k|9|
-------------
|1|4|a|j|k|9|
-------------
suggestion for timing: sigsuspend

8
TODO

@ -0,0 +1,8 @@
VERY BIG TODO:
- right now i will use long polling ajax calls when feedback from to the client
is needed. In the long term this should be changed to websockets (ws). But
right now ws specification is not final anyway. :)
- handle errors after all system call...especially open, close, etc.
- IPV6 support

50
assets/html/main.html

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>My own little Web-App</title>
<link rel="stylesheet" type="text/css" href="/assets/style/common">
<script type="text/javascript" src="/assets/js/jquery"></script>
<script type="text/javascript" src="/assets/js/serverval"></script>
<script type="text/javascript" src="/assets/js/session"></script>
<script type="text/javascript" src="/assets/js/init"></script>
</head>
<body>
<ul id="menu">
<li>random Value</li>
<li>start session</li>
<li>login</li>
</ul>
<div id="sessinfo" class="x-small">
Session: <span></span><br />
<canvas width="100px" height="3px"></canvas>
</div>
<div id="login" class="hide">
<form>
<label for="username">username</label>
<input type="text" name="username" /><br />
<label for="password">password</label>
<input type="password" name="password" /><br />
<input type="submit" />
</form>
</div>
<div id="randval" class="hide">
<span class=\"small">
Value created at: <br />
<span></span><br>
Next value in: <span></span><br />
</span>
Value: <span></span>
</div>
<div id="main">
<h1>Testpage</h1>
Welcome<span></span>!!!<br />
<img src="/image/me" />
</div>
<hr />
<div id="msg"></div>
</body>
</html>
<!-- vim: set ts=4 sw=4: -->

BIN
assets/image/waldschrat.jpg

After

Width: 250  |  Height: 250  |  Size: 78 KiB

37
assets/js/init.js

@ -0,0 +1,37 @@
var sess = null;
$(document).ready(function() {
var sval = new ServerVal("#randval");
sess = new Session("#sessinfo");
$(window).focus(function() {
$.getJSON("/sessinfo/", $.proxy(sess.loadJSON, sess));
});
$("ul#menu li:eq(0)").click(function() {
sval.start();
});
$("ul#menu li:eq(1)").click(function() {
$.getJSON("/sess/", $.proxy(sess.loadJSON, sess));
});
$("ul#menu li:eq(2)").click(function() {
$("#login").removeClass("hide");
});
$("#randval").click(function() {
sval.stop();
});
$("#login form").submit(function(event) {
event.preventDefault();
$.post("/login/",
$("#login form").serialize(),
$.proxy(sess.loadJSON, sess));
$("#login").addClass("hide");
});
});
// vim: set ts=4 sw=4:

9266
assets/js/jquery-1.7.1.js
File diff suppressed because it is too large
View File

4
assets/js/jquery-1.7.1.min.js
File diff suppressed because it is too large
View File

78
assets/js/serverval.js

@ -0,0 +1,78 @@
function ServerVal(eId)
{
this.eId = eId;
this.eCtime = eId + " span:eq(1)";
this.eVnext = eId + " span:eq(2)";
this.eValue = eId + " span:eq(3)";
this.interval = null;
this.ctime = null;
this.vnext = 0;
this.value = null;
}
ServerVal.prototype.loadJSON = function(data)
{
this.ctime = new Date(data.ctime * 1000);
this.vnext = data.vnext;
this.value = data.value;
$.getJSON("/sessinfo/", $.proxy(sess.loadJSON, sess));
this.show();
}
ServerVal.prototype.show = function()
{
$(this.eCtime).empty().append(this.ctime.toString());
$(this.eVnext).empty().append(this.vnext);
$(this.eValue).empty().append(this.value);
if ($(this.eId).hasClass("hide")) {
$(this.eId).removeClass("hide");
}
}
ServerVal.prototype.start = function()
{
if (null === this.interval) {
this.interval = setInterval($.proxy(this.process, this), 1000);
}
}
ServerVal.prototype.process = function()
{
if (0 >= this.vnext) {
$.getJSON("/randval/", $.proxy(this.loadJSON, this))
.error($.proxy(function(xhr) {
this.stop();
$("#msg").append("AJAX error (" + xhr.status + "): ");
switch(xhr.status) {
case 403:
$("#msg").append(
"Please log in to access this function.<br />");
break;
default:
$("#msg").append(
"Unhandled - " + xhr.responseText + "<br />");
break;
}
}, this));
}
else {
this.vnext--;
$(this.eVnext).empty().append(this.vnext);
}
}
ServerVal.prototype.stop = function()
{
$(this.eId).addClass("hide");
clearInterval(this.interval);
this.interval = null;
this.vnext = 0;
}
// vim: set ts=4 sw=4:

78
assets/js/session.js

@ -0,0 +1,78 @@
function Session(sId)
{
this.eSid = $(sId + " span");
this.canvas = $(sId + " canvas").get(0);
this.context = this.canvas.getContext("2d");
this.id = "none"
this.timeout = 0;
this.timeleft = 0;
this.username = "";
this.interval = null;
this.draw();
}
Session.prototype.loadJSON = function(data)
{
this.stop();
this.id = ("0" == data.id)? "none" : data.id;
this.timeout = data.timeout * 10;
this.timeleft = data.timeleft * 10;
this.username = data.username;
this.eSid.empty().append(this.id);
$("#main span:eq(0)").empty().append(" " + this.username);
this.draw();
if (0 < this.timeleft)
this.start();
}
Session.prototype.draw = function()
{
this.context.fillStyle = "rgb(255, 0, 0)";
this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
this.context.fillStyle = "rgb(0, 255, 0)";
this.context.fillRect(0, 0,
this.canvas.width / this.timeout * this.timeleft,
this.canvas.height);
}
Session.prototype.start = function()
{
if (null === this.interval) {
this.interval = setInterval($.proxy(this.process, this), 100);
}
}
Session.prototype.process = function()
{
if (0 >= this.timeleft) {
this.stop();
}
else {
this.timeleft--;
this.draw();
}
}
Session.prototype.stop = function()
{
clearInterval(this.interval);
this.interval = null;
this.id = "none";
this.timeout = 0;
this.timeleft = 0;
this.username = "";
this.eSid.empty().append(this.id);
$("#main span:eq(0)").empty().append(" " + this.username);
this.draw();
}
// vim: set ts=4 sw=4:

58
assets/style/common.css

@ -0,0 +1,58 @@
div#randval {
left: 200px;
top: 100px;
padding: 10px;
position: fixed;
background-color: white;
border: 1px solid black;
border-radius: 10px;
}
div#login {
padding: 5px;
position: fixed;
background-color: white;
border: 1px solid black;
border-radius: 10px;
}
div.hide {
top: -500px !important;
}
.small {
font-size: small;
}
.x-small {
font-size: x-small;
}
ul#menu {
list-style: none inside;
margin: 0px;
padding: 1px 0px 0px;
border-bottom: 1px solid #7b0b2b;
display: inline-block;
width: 100%;
}
ul#menu li {
padding: 2px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
border-top: 1px solid #7b0b2b;
border-left: 1px solid #7b0b2b;
border-right: 1px solid #7b0b2b;
text-align: center;
cursor: pointer;
float: left;
margin-right: 1px;
}
div#sessinfo canvas {
border: 1px solid black;
}
/* vim: set st=4 sw=4: */

7
bootstrap

@ -0,0 +1,7 @@
#!/bin/sh
aclocal
libtoolize --copy
autoheader
automake --gnu --add-missing --copy
autoconf

17
certs/server.crt

@ -0,0 +1,17 @@
-----BEGIN CERTIFICATE-----
MIICrzCCAhgCCQDgHe3rh23alDANBgkqhkiG9w0BAQUFADCBmzELMAkGA1UEBhMC
REUxEDAOBgNVBAgMB0hhbWJ1cmcxEDAOBgNVBAcMB0hhbWJ1cmcxGjAYBgNVBAoM
EVdlaXJkIFdlYiBXb3JrZXJzMRQwEgYDVQQLDAtkZXZlbG9wbWVudDETMBEGA1UE
AwwKR2VvcmcgSG9wcDEhMB8GCSqGSIb3DQEJARYSZ2VvcmdAc3RlZmZlcnMub3Jn
MB4XDTEyMDMwOTExMjUxOVoXDTEzMDMwOTExMjUxOVowgZsxCzAJBgNVBAYTAkRF
MRAwDgYDVQQIDAdIYW1idXJnMRAwDgYDVQQHDAdIYW1idXJnMRowGAYDVQQKDBFX
ZWlyZCBXZWIgV29ya2VyczEUMBIGA1UECwwLZGV2ZWxvcG1lbnQxEzARBgNVBAMM
Ckdlb3JnIEhvcHAxITAfBgkqhkiG9w0BCQEWEmdlb3JnQHN0ZWZmZXJzLm9yZzCB
nzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAt5ntW8UUwImTL0s3l7Jm2AkMqBvk
+XCDjkO3g89dxfYyRaYjluANnUqeg/ilF2ZcxI/8GVlCBTDbsJeQXFtlRFr94S2d
i1358dZkjGIQAutmtwf8L1nbYi6mtvS6wBWJhtE9baPfj6HDRePnAC/YtKunKfz9
5TbOj+/2vjj//I8CAwEAATANBgkqhkiG9w0BAQUFAAOBgQCWVZuqshFdOC3Vmf/7
CKrtA8/da2tgOIFB60LwGwcWicM3m/VIS6RPf3Ui/sUDFMempkmtkUYflr58T901
SAV5YubjNV3oaOySqDozsvfLsAxb7EUXk4VqY/g5VkK+pUxVAfE1biqf6LhPHzRd
KJrq5muIGeVx3YX1G9A1gdI0YQ==
-----END CERTIFICATE-----

15
certs/server.key

@ -0,0 +1,15 @@
-----BEGIN RSA PRIVATE KEY-----
MIICXgIBAAKBgQC3me1bxRTAiZMvSzeXsmbYCQyoG+T5cIOOQ7eDz13F9jJFpiOW
4A2dSp6D+KUXZlzEj/wZWUIFMNuwl5BcW2VEWv3hLZ2LXfnx1mSMYhAC62a3B/wv
WdtiLqa29LrAFYmG0T1to9+PocNF4+cAL9i0q6cp/P3lNs6P7/a+OP/8jwIDAQAB
AoGAMbOEkpwmQvy7EElvUixkNMU2XOe4M2Im6sMgEZl4DBfaggo4hiY+6T6C7LzJ
jC0Unc1QdFg6TAdu4T4WQToojkODjEXWd/QRltxJjkCz2vrDp68JldzfTovE2HDn
k5MQvUZCrH1jFnvzwC1Ak+X4ON5hlsu67u2EYNTfdEeTI6ECQQDwm6DNNjsGynGy
W+zCCGTPjuwYHG7zjaGQw9Ng7g+SyYHkg0zSsxcVpwKwI3m3Iuju1O85pgcl/Bj9
UDuPdtLxAkEAw1i3ZyGxW/CHmk8mG4w31eC7loyjFgN51lSJE7DrZ3VtKnzRwUrk
EEUgQMh1RxWKTc5F8QvmMpkWJha2+FTHfwJBALDtwBEnD8CunWzKrA8CnR8DuhkA
z5XJUEVjusxMQqduBlZDNvq5NwB1D0T20UoaIa9+ZWu+6wLDnpynoySb/AECQQDB
EDY63EbQqfkrHdx4z20DmZdsZFRuVkMc+/F6H5mYZ6rbmf8ofR7HoboNrNCTz4sf
+KSRZgQ9r6T/QeXVqtx7AkEApiC8VAYhH0Dz+Y6QSRqwjOww0kDBCnFlrdn+oyG4
kAC34PCOFHzvSsJ3tjcAwNJgcaN/qw49DRnHBlwti6gyBg==
-----END RSA PRIVATE KEY-----

63
configure.ac

@ -0,0 +1,63 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.68])
AC_INIT([taskrambler], [0.0.1], [Georg Hopp <georg@steffers.org>])
LT_INIT
AM_INIT_AUTOMAKE
#AM_INIT_AUTOMAKE([subdir-objects])
AM_SILENT_RULES([yes])
AC_COPYRIGHT([Copyright © 2012 Georg Hopp])
AC_REVISION([$Revision: 0.02 $])
AC_CONFIG_SRCDIR([src/taskrambler.c])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
m4_include([m4/gcov.m4])
AC_TDD_GCOV
AC_SUBST(COVERAGE_CFLAGS)
AC_SUBST(COVERAGE_CXXFLAGS)
AC_SUBST(COVERAGE_LDFLAGS)
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_CC_C99
AC_PROG_LIBTOOL
AM_PROG_CC_C_O
# # Checks for libraries.
# AC_CHECK_LIB([json], [json_object_new_object], [],
# [AC_MSG_ERROR([json-c library not found], [1])])
AC_CHECK_LIB([ssl], [SSL_library_init], [],
[AC_MSG_ERROR([openssl not found], [1])])
# Checks for header files.
AC_CHECK_HEADERS([stdarg.h string.h stdlib.h stdio.h unistd.h syslog.h sys/types.h json/json.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_PID_T
AC_TYPE_SIZE_T
# Checks for library functions.
#AC_FUNC_FORK
#AC_FUNC_MALLOC
AC_CHECK_FUNCS([memset])
AC_CONFIG_FILES([Makefile
src/Makefile
src/auth/Makefile
src/cbuf/Makefile
src/class/Makefile
src/hash/Makefile
src/queue/Makefile
src/http/Makefile
src/logger/Makefile
src/server/Makefile
src/session/Makefile
src/socket/Makefile
src/stream/Makefile
tests/Makefile])
AC_OUTPUT

11
include/auth.h

@ -0,0 +1,11 @@
#ifndef __AUTH_H__
#define __AUTH_H__
#include "auth/auth.h"
#include "auth/ldap.h"
#include "auth/credential.h"
#include "auth/interface/auth.h"
#endif // __AUTH_H__
// vim: set ts=4 sw=4:

45
include/auth/auth.h

@ -0,0 +1,45 @@
/**
* \file
* Authenticatio module factory
*
* A factory to get a specific authentication module.
* An authentication module is a class that implement the Auth interface.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __AUTH_AUTH_H__
#define __AUTH_AUTH_H__
#include "class.h"
#include "auth/ldap.h"
typedef enum e_AuthModule {
AUTH_LDAP = 0
} AuthModule;
CLASS(Auth) {
};
void * authCreateById(Auth, int);
AuthLdap authCreateLdap(Auth);
#endif // __AUTH_AUTH_H__
// vim: set ts=4 sw=4:

54
include/auth/credential.h

@ -0,0 +1,54 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __AUTH_CREDENTIAL_H__
#define __AUTH_CREDENTIAL_H__
#include <sys/types.h>
#include "class.h"
#define CRED_PWD(c) (((c)->cred).pwd)
typedef enum e_CredentialType {
CRED_PASSWORD = 0
} CredentialType;
CLASS(Credential) {
CredentialType type;
union {
struct {
char * user;
size_t nuser;
char * pass;
size_t npass;
} pwd;
} cred;
};
#endif // __AUTH_CREDENTIAL_H__
// vim: set ts=4 sw=4:

49
include/auth/interface/auth.h

@ -0,0 +1,49 @@
/**
* \file
* The authentication interface.
*
* This is the authentication interface. It's only pupose is to
* authenticate someone or somewhat. It is called AUTH.
* The concrete access rights are managed within a class called ACL.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __AUTH_INTERFACE_AUTH_H__
#define __AUTH_INTERFACE_AUTH_H__
#include <stdarg.h>
#include "class.h"
#include "auth/credential.h"
typedef int (* fptr_authenticate)(void *, Credential);
extern const struct interface i_Auth;
struct i_Auth {
const struct interface * const _;
fptr_authenticate authenticate;
};
extern int authenticate(void *, Credential);
#endif // __AUTH_INTERFACE_AUTH_H__
// vim: set ts=4 sw=4:

41
include/auth/ldap.h

@ -0,0 +1,41 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __AUTH_LDAP_H__
#define __AUTH_LDAP_H__
#include <ldap.h>
#include <sys/types.h>
#include "class.h"
CLASS(AuthLdap) {
LDAP * ldap;
char * url;
char * base_dn;
int version;
size_t nbase_dn;
};
#endif // __AUTH_LDAP_H__
// vim: set ts=4 sw=4:

81
include/cbuf.h

@ -0,0 +1,81 @@
/**
* \file
* My implementation of a ringbuffer.
* It maps a shared memory object twice directly following
* thus make it possible to read and write from any
* position within the buffer without the nasty wrap
* calculations.
* This is achived because the same memory region is mapped
* at the two addresses.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __CBUF_H__
#define __CBUF_H__
#include <ctype.h>
#include <string.h>
#include <sys/types.h>
#include "class.h"
#include "stream.h"
#include "commons.h"
#define ECBUFOVFL 100
CLASS(Cbuf) {
char * shm_name; // shared memory identifier
char * data;
Bool lock;
size_t bsize;
size_t bused;
size_t write;
size_t read;
};
ssize_t cbufRead(Cbuf, Stream);
ssize_t cbufWrite(Cbuf, Stream);
char * cbufGetLine(Cbuf, char **);
char * cbufGetData(Cbuf, size_t);
char * cbufSetData(Cbuf, const void *, size_t);
void cbufEmpty(Cbuf);
char * cbufGetRead(Cbuf this);
char * cbufGetWrite(Cbuf this);
char * cbufMemchr(Cbuf this, int c);
size_t cbufAddrIndex(Cbuf this, const void * c);
void cbufIncRead(Cbuf this, size_t n);
void cbufIncWrite(Cbuf this, size_t n);
size_t cbufGetFree(Cbuf this);
char cbufIsEmpty(Cbuf this);
void cbufSkipNonAlpha(Cbuf this);
Bool cbufIsLocked(Cbuf this);
void cbufLock(Cbuf this);
void cbufRelease(Cbuf this);
#endif // __CBUF_H__
// vim: set ts=4 sw=4:

10
include/class.h

@ -0,0 +1,10 @@
#ifndef __CLASS_H__
#define __CLASS_H__
#include "class/class.h"
#include "class/interface.h"
#include "class/interface/class.h"
#endif // __CLASS_H__
// vim: set ts=4 sw=4:

128
include/class/class.h

@ -0,0 +1,128 @@
/**
* \file
* My own class implementation for C. It combines a data structure
* with a set of dynamically linked methods defined by an interface. A
* dynamically linked method will be called via a selector method which in
* turn gets the implementation stored in the class.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __CLASS_CLASS_H__
#define __CLASS_CLASS_H__
#include <stdarg.h>
#include <sys/types.h>
#include <string.h>
#include <assert.h>
#include "class/interface.h"
#ifndef _ISOC99_SOURCE
#define _ISOC99_SOURCE
#endif
#define CLASS_MAGIC 0xFEFE
#define CLASS(name) \
struct c_##name; \
typedef struct c_##name * name; \
extern struct class * const _##name; \
struct c_##name
#define EXTENDS(parent) \
const char _[sizeof(struct c_##parent)]
#define _NULL NULL
#define CREATE_CLASS(name,_parent,...) \
static struct class c_##name; \
static class_ptr _classInit##name##_(void) { \
c_##name.parent = _##_parent; \
c_##name.init = NULL; \
return &c_##name; \
} \
static struct class c_##name = { \
CLASS_MAGIC, \
NULL, \
sizeof(struct c_##name), \
_classInit##name##_, \
INIT_IFACE_IMPL(__VA_ARGS__) \
}; struct class * const _##name = &c_##name
#define INIT_CLASS(class) ((class)->init? (class)->init() : (class))
#define GET_CLASS(object) (INIT_CLASS(*(class_ptr *)((void*)(object) - sizeof(void*))))
#define IFACE_GET(class,iface) (interfaceGet(&((class)->impl),(iface)))
#define HAS_PARENT(class) (NULL != ((class)->parent) && INIT_CLASS((class)->parent))
#define IS_OBJECT(obj) ((GET_CLASS((obj)))->magic == CLASS_MAGIC)
#define INSTANCE_OF(class,obj) ((GET_CLASS((obj))) == _##class)
/**
* \todo actually i use gcc feature ## for variadoc... think about
* a way to make this standard.
*/
#define _CALL(_class,_iface,method,...) \
do { \
class_ptr class = _class; \
iface = (struct i_##_iface *)IFACE_GET(class, &i_##_iface); \
while ((NULL == iface || NULL == iface->method) && HAS_PARENT(class)) { \
class = class->parent; \
iface = (struct i_##_iface *)IFACE_GET(class, &i_##_iface); \
} \
assert(NULL != iface->method); \
} while(0)
#define CALL(object,_iface,method,...) \
do { \
struct i_##_iface * iface; \
_CALL(GET_CLASS(object), _iface, method, ##__VA_ARGS__); \
iface->method(object, ##__VA_ARGS__); \
} while(0)
#define RETCALL(object,_iface,method,ret,...) \
do { \
struct i_##_iface * iface; \
_CALL(GET_CLASS(object), _iface, method, ##__VA_ARGS__); \
ret = iface->method(object, ##__VA_ARGS__); \
} while(0)
#define PARENTCALL(object,_iface,method,...) \
do { \
struct i_##_iface * iface; \
class_ptr pc_class = GET_CLASS((object)); \
assert(HAS_PARENT(pc_class)); \
_CALL(pc_class->parent, _iface, method, ##__VA_ARGS__); \
iface->method(object, ##__VA_ARGS__); \
} while(0)
struct class;
typedef struct class * class_ptr;
typedef class_ptr (* fptr_classInit)(void);
struct class {
const int magic;
class_ptr parent;
size_t object_size;
fptr_classInit init;
struct iface_impl impl;
};
#endif // __CLASS_CLASS_H__
// vim: set ts=4 sw=4:

59
include/class/interface.h

@ -0,0 +1,59 @@
/**
* \file
* Interface definition code. Each interface is a set of selector functions
* as well as a data structure where the concrete implementation will be stored.
* This structure is the intergrated in the class that implements the
* interface.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __CLASS_INTERFACE_H__
#define __CLASS_INTERFACE_H__
#include <sys/types.h>
#define MAX_IFACE 32 // ATTENTION: every iface_impl will use MAX_IFACE * sizeof(void*)
#define IFACE(name) ((const struct i_##name const*)&i_##name##_impl)
#define INIT_IFACE(name,...) \
static const struct i_##name i_##name##_impl = {&i_##name,__VA_ARGS__}
#define NUMARGS(...) (sizeof((const void*[]){__VA_ARGS__})/sizeof(void*))
#define INIT_IFACE_IMPL(...) {NUMARGS(__VA_ARGS__), 0, {__VA_ARGS__}}
struct interface {
const char * name;
const size_t nmethods;
};
typedef const struct interface * iface_ptr;
struct iface_impl {
const size_t nimpl; // number of interface implementations
char simpl; // implementations sorted??
const void * impl[MAX_IFACE]; // implementations
};
typedef struct iface_impl * iface_impl_ptr;
extern iface_ptr interfaceGet(iface_impl_ptr, const iface_ptr);
#endif // __CLASS_INTERFACE_H__
// vim: set ts=4 sw=4:

57
include/class/interface/class.h

@ -0,0 +1,57 @@
/**
* \file
* Interface for class handling. Defines new, delete and clone selectors
* which in turn use the ctor, dtor and clone implementation from the
* class implementation.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __CLASS_INTERFACE_CLASS_H__
#define __CLASS_INTERFACE_CLASS_H__
#include <stdarg.h>
#include "class/class.h"
#include "class/interface.h"
typedef int (* fptr_ctor)(void *, va_list *);
typedef void (* fptr_dtor)(void *);
typedef void (* fptr_clone)(void *, void * const);
extern const struct interface i_Class;
struct i_Class {
const struct interface * const _;
fptr_ctor ctor;
fptr_dtor dtor;
fptr_clone clone;
};
extern void * classNew(class_ptr, ...);
extern void classDelete(void **);
extern void * classClone(void *);
#define new(class,...) classNew(_##class, ##__VA_ARGS__)
#define delete(object) classDelete((void **)&(object))
#define clone(object) classClone((void *)(object))
#endif // __CLASS_INTERFACE_CLASS_H__
// vim: set ts=4 sw=4:

48
include/commons.h

@ -0,0 +1,48 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __COMMONS_H__
#define __COMMONS_H__
#define Bool char
#define TRUE 1
#define FALSE 0
#ifndef MAX
# define MAX(a,b) ((a)>(b)? (a) : (b))
#endif
#ifndef MIN
# define MIN(a,b) ((a)<(b)? (a) : (b))
#endif
#define SWAP_FUN(a, b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define SWAP(type, a, b) do { \
type tmp = (a); \
(a) = (b); \
(b) = tmp; \
} while(0);
#endif // __COMMONS_H__
// vim: set ts=4 sw=4:

10
include/hash.h

@ -0,0 +1,10 @@
#ifndef __HASH_H__
#define __HASH_H__
#include "hash/hash.h"
#include "hash/value.h"
#include "hash/interface/hashable.h"
#endif // __HASH_H__
// vim: set ts=4 sw=4:

42
include/hash/hash.h

@ -0,0 +1,42 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __HASH_HASH_H__
#define __HASH_HASH_H__
#include <sys/types.h>
#include "class.h"
CLASS(Hash) {
void * root;
};
void * hashAdd(Hash, void *);
void * hashDelete(Hash, const char *, size_t);
void * hashGet(Hash, const char *, size_t);
void hashEach(Hash, void (*)(const void*));
#endif // __HASH_HASH_H__
// vim: set ts=4 sw=4:

45
include/hash/interface/hashable.h

@ -0,0 +1,45 @@
/**
* \file
* The logger interface.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __HASH_INTERFACE_HASHABLE_H__
#define __HASH_INTERFACE_HASHABLE_H__
#include "class.h"
typedef unsigned long (* fptr_hashableGetHash)(void *);
typedef void (* fptr_hashableHandleDouble)(void *, void *);
extern const struct interface i_Hashable;
struct i_Hashable {
const struct interface * const _;
fptr_hashableGetHash getHash;
fptr_hashableHandleDouble handleDouble;
};
extern unsigned long hashableGetHash(void *);
extern void hashableHandleDouble(void *, void *);
#endif // __HASH_INTERFACE_HASHABLE_H__
// vim: set ts=4 sw=4:

42
include/hash/value.h

@ -0,0 +1,42 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __HASH_VALUE_H__
#define __HASH_VALUE_H__
#include <sys/types.h>
#include "class.h"
CLASS(HashValue) {
unsigned long hash;
char * key;
void * value;
size_t nkey;
size_t nvalue;
};
#endif // __HASH_VALUE_H__
// vim: set ts=4 sw=4:

17
include/http.h

@ -0,0 +1,17 @@
#ifndef __HTTP_H__
#define __HTTP_H__
#include "http/cookie.h"
#include "http/header.h"
#include "http/message.h"
#include "http/message/queue.h"
#include "http/request.h"
#include "http/response.h"
#include "http/parser.h"
#include "http/writer.h"
#include "http/worker.h"
#include "http/interface/http_intro.h"
#endif // __HTTP_H__
// vim: set ts=4 sw=4:

51
include/http/cookie.h

@ -0,0 +1,51 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __HTTP_COOKIE_H__
#define __HTTP_COOKIE_H__
#include <time.h>
#include <sys/types.h>
#include "class.h"
CLASS(HttpCookie) {
unsigned long hash;
char * key;
char * value;
char * domain;
char * path;
time_t expires;
time_t max_age;
size_t nkey;
size_t nvalue;
};
char * httpCookieToString(HttpCookie);
HttpCookie httpStringToCookie(const char *);
#endif // __HTTP_COOKIE_H__
// vim: set ts=4 sw=4:

48
include/http/header.h

@ -0,0 +1,48 @@
/**
* \file
* HTTP header class. One Instance represents one header line of
* an HTTP message.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __HTTP_HEADER_H__
#define __HTTP_HEADER_H__
#include <sys/types.h>
#include "class.h"
#define N_VALUES 128
CLASS(HttpHeader) {
unsigned long hash;
char * name;
char * value[N_VALUES];
size_t nname; //!< len of name without \0
size_t nvalue[N_VALUES]; //!< len of value without \0
size_t cvalue; //!< count of values up to N_VALUE
size_t size; //!< full size of this header
};
size_t httpHeaderToString(HttpHeader, char *);
#endif // __HTTP_HEADER_H__
// vim: set ts=4 sw=4:

47
include/http/interface/http_intro.h

@ -0,0 +1,47 @@
/**
* \file
* Virtual (dynamically bound) methods to get the size of the http intro
* line. As i have two kinds of http messages (response, request) which
* need a slitly different handling when turning the data into a string.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __HTTP_INTRO_H__
#define __HTTP_INTRO_H__
#include <sys/types.h>
typedef size_t (* fptr_httpIntroSizeGet)(void *);
typedef char * (* fptr_httpIntroToString)(void *, char *);
extern const struct interface i_HttpIntro;
struct i_HttpIntro {
const struct interface * const _;
fptr_httpIntroSizeGet sizeGet;
fptr_httpIntroToString toString;
};
extern size_t httpIntroSizeGet(void *);
extern char * httpIntroToString(void *, char *);
#endif // __HTTP_INTRO_H__
// vim: set ts=4 sw=4:

58
include/http/message.h

@ -0,0 +1,58 @@
/**
* \file
* Generic HTTP message. Parent for request and response.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __HTTP_MESSAGE__
#define __HTTP_MESSAGE__
#include "class.h"
#include "hash.h"
#include "stream.h"
typedef enum e_HttpMessageType {
HTTP_MESSAGE_BUFFERED=0,
HTTP_MESSAGE_PIPED
} HttpMessageType;
CLASS(HttpMessage) {
char * version;
Hash header;
HttpMessageType type;
Stream handle;
char * body;
int nbody;
int dbody;
};
char httpMessageHasKeepAlive(HttpMessage);
size_t httpMessageHeaderSizeGet(HttpMessage);
char * httpMessageHeaderToString(HttpMessage, char *);
int httpMessageGetVersion(HttpMessage, int *, int *);
int httpMessageHasValidVersion(HttpMessage);
#endif // __HTTP_MESSAGE__
// vim: set ts=4 sw=4:

70
include/http/parser.h

@ -0,0 +1,70 @@
/**
* \file
* Parse requests from an input stream.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __HTTP_PARSER_H__
#define __HTTP_PARSER_H__
#include "class.h"
#include "http/message.h"
#include "queue.h"
#include "cbuf.h"
#include "stream.h"
#include "commons.h"
#define PARSER_MAX_BUF 131072
typedef enum e_HttpMessageState {
HTTP_MESSAGE_GARBAGE=0,
HTTP_MESSAGE_START,
HTTP_MESSAGE_INTRO_DONE,
HTTP_MESSAGE_HEADERS_DONE,
HTTP_MESSAGE_DONE
} HttpMessageState;
CLASS(HttpParser) {
Cbuf buffer;
Bool ourLock;
char * incomplete;
size_t isize;
Queue queue;
HttpMessage current;
HttpMessageState state;
};
ssize_t httpParserParse(void *, Stream);
void httpParserRequestVars(HttpParser);
void httpParserHeader(HttpParser, const char *, const char *);
void httpParserNewMessage(HttpParser, const char *, const char * lend);
size_t httpParserBody(HttpParser, const char *, size_t);
void httpParserRequestVars(HttpParser);
void httpParserPostVars(HttpParser);
#endif // __HTTP_PARSER_H__
// vim: set ts=4 sw=4:

51
include/http/request.h

@ -0,0 +1,51 @@
/**
* \file
* Represents one HTTP request.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __HTTP_REQUEST_H__
#define __HTTP_REQUEST_H__
#include "class.h"
#include "http/message.h"
#include "hash.h"
#define N_HTTP_METHOD 8
char * http_method[N_HTTP_METHOD];
CLASS(HttpRequest) {
EXTENDS(HttpMessage);
char * method;
char * uri;
char * path;
Hash get;
Hash post;
Hash cookies;
};
int httpRequestHasValidMethod(HttpRequest);
#endif // __HTTP_REQUEST_H__
// vim: set ts=4 sw=4:

59
include/http/response.h

@ -0,0 +1,59 @@
/**
* \file
* Represents one HTTP response.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __HTTP_RESPONSE_H__
#define __HTTP_RESPONSE_H__
#include <time.h>
#include <sys/types.h>
#include "class.h"
#include "http/message.h"
#include "session.h"
CLASS(HttpResponse) {
EXTENDS(HttpMessage);
unsigned int status;
char * reason;
};
HttpResponse httpResponse304(
const char *, size_t,
const char *, size_t,
const char *, size_t);
HttpResponse httpResponse404();
HttpResponse httpResponse403();
HttpResponse httpResponseMe();
HttpResponse httpResponseLoginForm();
HttpResponse httpResponseRandval(time_t, int);
HttpResponse httpResponseSession(Session);
HttpResponse httpResponseAsset(
const char *,
const char *, size_t,
const char *, size_t);
#endif // __HTTP_RESPONSE_H__
// vim: set ts=4 sw=4:

61
include/http/worker.h

@ -0,0 +1,61 @@
/**
* \file
* Worker for processing HTTP request, response cycles.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __HTTP_WORKER_H__
#define __HTTP_WORKER_H__
#include <sys/types.h>
#include <time.h>
#include "class.h"
#include "http/parser.h"
#include "http/writer.h"
#include "cbuf.h"
#include "session.h"
#include "commons.h"
struct randval {
time_t timestamp;
int value;
};
CLASS(HttpWorker) {
char * id;
struct randval * val;
Cbuf pbuf;
Cbuf wbuf;
HttpParser parser;
HttpWriter writer;
Session session;
Session * sroot;
void * auth;
};
#endif // __HTTP_WORKER_H__
// vim: set ts=4 sw=4:

65
include/http/writer.h

@ -0,0 +1,65 @@
/**
* \file
* Write ready responses to an output stream.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __HTTP_WRITER_H__
#define __HTTP_WRITER_H__
#include <sys/types.h>
#include "class.h"
#include "http/message.h"
#include "queue.h"
#include "cbuf.h"
#include "stream.h"
#include "commons.h"
#define WRITER_MAX_BUF 131072
typedef enum e_HttpWriterState {
HTTP_WRITER_GET=0,
HTTP_WRITER_WRITE,
HTTP_WRITER_DONE
} HttpWriterState;
CLASS(HttpWriter) {
Cbuf buffer;
Bool ourLock;
Queue queue;
HttpMessage current;
size_t nheader;
size_t nbody;
size_t written;
HttpWriterState state;
};
ssize_t httpWriterWrite(void *, Stream);
#endif // __HTTP_WRITER_H__
// vim: set ts=4 sw=4:

40
include/interface/observer.h

@ -0,0 +1,40 @@
/**
* \file
* Definition of the observer pattern implementation.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __OBSERVER_H__
#define __OBSERVER_H__
typedef void (* fptr_observerNotify)(void *, void*);
extern const struct interface i_Observer;
struct i_Observer {
const struct interface * const _;
fptr_observerNotify notify;
};
extern void observerNotify(void *, void *);
#endif // __OBSERVER_H__
// vim: set ts=4 sw=4:

46
include/interface/subject.h

@ -0,0 +1,46 @@
/**
* \file
* Definition of the subject pattern implementation.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SUBJECT_H__
#define __SUBJECT_H__
typedef void (* fptr_subjectAttach)(void *, void *);
typedef void (* fptr_subjectDetach)(void *, void *);
typedef void (* fptr_subjectNotify)(void *);
extern const struct interface i_Subject;
struct i_Subject {
const struct interface * const _;
fptr_subjectAttach attach;
fptr_subjectDetach detach;
fptr_subjectNotify notify;
};
extern void subjectAttach(void *, void *);
extern void subjectDetach(void *, void *);
extern void subjectNotify(void *);
#endif // __SUBJECT_H__
// vim: set ts=4 sw=4:

9
include/logger.h

@ -0,0 +1,9 @@
#ifndef __LOGGER_H__
#define __LOGGER_H__
#include "logger/logger.h"
#include "logger/interface/logger.h"
#endif // __LOGGER_H__
// vim: set ts=4 sw=4:

45
include/logger/interface/logger.h

@ -0,0 +1,45 @@
/**
* \file
* The logger interface.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __LOGGER_INTERFACE_LOGGER_H__
#define __LOGGER_INTERFACE_LOGGER_H__
#include <stdarg.h>
#include "class.h"
#include "logger.h"
typedef void (* fptr_log)(void *, logger_level, const char * const);
extern const struct interface i_Logger;
struct i_Logger {
const struct interface * const _;
fptr_log log;
};
extern void loggerLog(void *, logger_level, const char * const, ...);
#endif // __LOGGER_INTERFACE_LOGGER_H__
// vim: set ts=4 sw=4:

57
include/logger/logger.h

@ -0,0 +1,57 @@
/**
* \file
* A generic logger class and two extended classes, One that logs to
* stderr and one that logs to the system syslog.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __LOGGER_LOGGER_H__
#define __LOGGER_LOGGER_H__
#include "class.h"
typedef enum logger_level {
LOGGER_DEBUG=0,
LOGGER_INFO,
LOGGER_NOTICE,
LOGGER_WARNING,
LOGGER_ERR,
LOGGER_CRIT,
LOGGER_ALERT,
LOGGER_EMERG
} logger_level;
extern const char * const logger_level_str[];
CLASS(Logger) {
logger_level min_level;
};
CLASS(LoggerStderr) {
EXTENDS(Logger);
};
CLASS(LoggerSyslog) {
EXTENDS(Logger);
};
#endif // __LOGGER_LOGGER_H__
// vim: set ts=4 sw=4:

56
include/queue.h

@ -0,0 +1,56 @@
/**
* \file
* Holds requests ready for processing.
*
* \todo change this to a real queue.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __QUEUE_H__
#define __QUEUE_H__
#include <sys/types.h>
#include "class.h"
#include "commons.h"
CLASS(Queue) {
void * msg;
Queue next;
/**
* first and last are only available in the initial queue
* element (the root). This elelment does not contain any message
* and exists only for organizational purpose.
*/
Queue first;
Queue last;
size_t nmsg;
};
void queuePut(Queue, void *);
void * queueGet(Queue);
#define queueEmpty(this) (0 >= (this)->nmsg)
#endif // __QUEUE_H__
// vim: set ts=4 sw=4:

63
include/server.h

@ -0,0 +1,63 @@
/**
* \file
* Server class. Handles acceptance and closing of connection and uses
* a class that has to implement the stream reader and writer interface
* to handle incoming reads and outgoing writes.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SERVER_H__
#define __SERVER_H__
#include <stdio.h> // for printf() and fprintf()
#include <poll.h> // for poll system call and related
#include <openssl/ssl.h>
#include "class.h"
#include "socket.h"
#include "logger.h"
#include "stream.h"
struct conns {
Sock sock;
Stream stream;
void * worker;
};
CLASS(Server) {
Logger logger;
Sock sock;
Sock sockSSL;
SSL_CTX * ctx;
void * worker;
nfds_t nfds;
struct pollfd * fds;
long max_fds;
struct conns * conns;
};
void serverRun(Server this);
#endif // __SERVER_H__
// vim: set ts=4 sw=4:

47
include/session.h

@ -0,0 +1,47 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SESSION_H__
#define __SESSION_H__
#include <time.h>
#include <sys/types.h>
#include "class.h"
#define SESSION_LIVETIME 30
CLASS(Session) {
unsigned long id;
time_t livetime;
char * username;
};
Session sessionAdd(const Session *, Session);
Session sessionGet(const Session *, const unsigned long id);
void sessionDelete(const Session *, const unsigned long id);
#endif // __SESSION_H__
// vim: set ts=4 sw=4:

47
include/socket.h

@ -0,0 +1,47 @@
/**
* \file
* Abstraction layer above BSD sockets. Capsules and simplifies connect
* accept and listen.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SOCKET_H__
#define __SOCKET_H__
#include <arpa/inet.h> // for in_port_t
#include "class.h"
#include "logger.h"
CLASS(Sock) {
Logger log;
in_port_t port;
struct sockaddr_in addr;
int handle;
};
void socketConnect(Sock this, const char * addr, char (*)[16]);
void socketListen(Sock this, int backlog);
Sock socketAccept(Sock this, char (*remoteAddr)[16]);
#endif // __SOCKET_H__
// vim: set ts=4 sw=4:

10
include/stream.h

@ -0,0 +1,10 @@
#ifndef __STREAM_H__
#define __STREAM_H__
#include "stream/stream.h"
#include "stream/interface/reader.h"
#include "stream/interface/writer.h"
#endif // __STREAM_H__
// vim: set ts=4 sw=4:

45
include/stream/interface/reader.h

@ -0,0 +1,45 @@
/**
* \file
* Interface whose implementations can read from a stream given as
* a handle.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __STREAM_INTERFACE_READER_H__
#define __STREAM_INTERFACE_READER_H__
#include <sys/types.h>
#include "stream/stream.h"
typedef ssize_t (* fptr_streamReaderRead)(void *, Stream);
extern const struct interface i_StreamReader;
struct i_StreamReader {
const struct interface * const _;
fptr_streamReaderRead read;
};
extern ssize_t streamReaderRead(void *, Stream);
#endif // __STREAM_INTERFACE_READER_H__
// vim: set ts=4 sw=4:

45
include/stream/interface/writer.h

@ -0,0 +1,45 @@
/**
* \file
* Interface whose implementations can write from a stream given as
* a handle.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __STREAM_INTERFACE_WRITER_H__
#define __STREAM_INTERFACE_WRITER_H__
#include <sys/types.h>
#include "stream/stream.h"
typedef ssize_t (* fptr_streamWriterWrite)(void *, Stream);
extern const struct interface i_StreamWriter;
struct i_StreamWriter {
const struct interface * const _;
fptr_streamWriterWrite write;
};
extern ssize_t streamWriterWrite(void *, Stream);
#endif // __STREAM_INTERFACE_WRITER_H__
// vim: set ts=4 sw=4:

49
include/stream/stream.h

@ -0,0 +1,49 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __STREAM_STREAM_H__
#define __STREAM_STREAM_H__
#include <sys/types.h>
#include <openssl/ssl.h>
#include "class.h"
typedef enum e_StreamHandleType {
STREAM_FD = 0,
STREAM_SSL
} StreamHandleType;
CLASS(Stream) {
StreamHandleType type;
union {
int fd;
SSL * ssl;
} handle;
};
ssize_t streamRead(Stream, void *, size_t);
ssize_t streamWrite(Stream, void *, size_t);
#endif // __STREAM_STREAM_H__
// vim: set ts=4 sw=4:

33
include/utils/hash.h

@ -0,0 +1,33 @@
/**
* \file
* Functions to handle varios signals send to the application.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __UTILS_HASH_H__
#define __UTILS_HASH_H__
#include <sys/types.h>
unsigned long sdbm(const unsigned char *, size_t);
#endif // __UTILS_HASH_H__
// vim: set ts=4 sw=4:

38
include/utils/http.h

@ -0,0 +1,38 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __UTILS_HTTP_H__
#define __UTILS_HTTP_H__
#include <sys/types.h>
#include "http/message.h"
char isHttpVersion(const char *, size_t);
HttpMessage httpGetMessage(
const char *, size_t,
const char *, size_t,
const char *, size_t);
#endif // __UTILS_HTTP_H__
// vim: set ts=4 sw=4:

34
include/utils/memory.h

@ -0,0 +1,34 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __UTILS_MEMORY_H__
#define __UTILS_MEMORY_H__
#define CSTRA(val) val, sizeof(val)-1 //!< Const STRing Argument
#define FREE(val) (ffree((void**)&(val)))
void ffree(void **);
#endif // __UTILS_MEMORY_H__
// vim: set ts=4 sw=4:

33
include/utils/signalHandling.h

@ -0,0 +1,33 @@
/**
* \file
* Functions to handle varios signals send to the application.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __UTILS_SIGNAL_HANDLING_H__
#define __UTILS_SIGNAL_HANDLING_H__
extern volatile int doShutdown;
void terminate(int signum);
void init_signals(void);
#endif // __UTILS_SIGNAL_HANDLING_H__

77
m4/gcov.m4

@ -0,0 +1,77 @@
# Checks for existence of coverage tools:
# * gcov
# * lcov
# * genhtml
# * gcovr
#
# Sets ac_cv_check_gcov to yes if tooling is present
# and reports the executables to the variables LCOV, GCOVR and GENHTML.
AC_DEFUN([AC_TDD_GCOV],
[
AC_ARG_ENABLE(gcov,
AS_HELP_STRING([--enable-gcov],
[enable coverage testing with gcov]),
[use_gcov=$enableval], [use_gcov=no])
AM_CONDITIONAL(HAVE_GCOV, test "x$use_gcov" = "xyes")
# if test "x$use_gcov" = "xyes"; then
# we need gcc:
if test "$GCC" != "yes"; then
AC_MSG_ERROR([GCC is required for --enable-gcov])
fi
# Check if ccache is being used
AC_CHECK_PROG(SHTOOL, shtool, shtool)
case `$SHTOOL path $CC` in
*ccache*[)] gcc_ccache=yes;;
*[)] gcc_ccache=no;;
esac
if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then
AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.])
fi
lcov_version_list="1.6 1.7 1.8 1.9"
AC_CHECK_PROG(LCOV, lcov, lcov)
AC_CHECK_PROG(GENHTML, genhtml, genhtml)
if test "$LCOV"; then
AC_CACHE_CHECK([for lcov version], glib_cv_lcov_version, [
glib_cv_lcov_version=invalid
lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'`
for lcov_check_version in $lcov_version_list; do
if test "$lcov_version" = "$lcov_check_version"; then
glib_cv_lcov_version="$lcov_check_version (ok)"
fi
done
])
else
lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list"
AC_MSG_ERROR([$lcov_msg])
fi
case $glib_cv_lcov_version in
""|invalid[)]
lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)."
AC_MSG_ERROR([$lcov_msg])
LCOV="exit 0;"
;;
esac
if test -z "$GENHTML"; then
AC_MSG_ERROR([Could not find genhtml from the lcov package])
fi
# Remove all optimization flags from CFLAGS
changequote({,})
CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'`
changequote([,])
# Add the special gcc flags
COVERAGE_CFLAGS="-O0 -fprofile-arcs -ftest-coverage"
COVERAGE_CXXFLAGS="-O0 -fprofile-arcs -ftest-coverage"
COVERAGE_LDFLAGS="-lgcov"
#fi
]) # AC_TDD_GCOV

32
src/Makefile.am

@ -0,0 +1,32 @@
ACLOCAL_AMFLAGS = -I m4
IFACE = interface/subject.c \
interface/observer.c
UTILS = utils/hash.c \
utils/memory.c \
utils/http.c \
utils/daemonize.c \
utils/signalHandling.c
LIBS = ./http/libhttp.a \
./auth/libauth.a \
./cbuf/libcbuf.a \
./class/libclass.a \
./hash/libhash.a \
./queue/libqueue.a \
./logger/liblogger.a \
./server/libserver.a \
./session/libsession.a \
./socket/libsocket.a \
./stream/libstream.a
AM_CFLAGS = -Wall -I ../include/
bin_PROGRAMS = taskrambler
taskrambler_SOURCES = taskrambler.c $(IFACE) $(UTILS)
taskrambler_CFLAGS = -Wall -I ../include/# $(COVERAGE_CFLAGS)
taskrambler_LDADD = $(LIBS) -lrt -lssl -lldap
#taskrambler_LDFLAGS = $(COVERAGE_LDFLAGS)
SUBDIRS = auth cbuf class hash queue http logger server session socket stream

6
src/auth/Makefile.am

@ -0,0 +1,6 @@
ACLOCAL_AMFLAGS = -I m4
noinst_LIBRARIES = libauth.a
libauth_a_SOURCES = interface/auth.c credential.c ldap.c
libauth_a_CFLAGS = -Wall -I ../../include/

85
src/auth/credential.c

@ -0,0 +1,85 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdarg.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include "class.h"
#include "utils/memory.h"
#include "auth/credential.h"
static
int
credentialCtor(void * _this, va_list * params)
{
Credential this = _this;
this->type = va_arg(* params, CredentialType);
switch(this->type) {
case CRED_PASSWORD:
{
char * user, *pass;
user = va_arg(* params, char*);
CRED_PWD(this).nuser = va_arg(* params, size_t);
pass = va_arg(* params, char*);
CRED_PWD(this).npass = va_arg(* params, size_t);
CRED_PWD(this).user = malloc(CRED_PWD(this).nuser + 1);
CRED_PWD(this).user[CRED_PWD(this).nuser] = 0;
memcpy(CRED_PWD(this).user, user, CRED_PWD(this).nuser);
CRED_PWD(this).pass = malloc(CRED_PWD(this).npass + 1);
CRED_PWD(this).pass[CRED_PWD(this).npass] = 0;
memcpy(CRED_PWD(this).pass, pass, CRED_PWD(this).npass);
}
break;
default:
return -1;
}
return 0;
}
static
void
credentialDtor(void * _this)
{
Credential this = _this;
switch(this->type) {
case CRED_PASSWORD:
FREE(CRED_PWD(this).user);
FREE(CRED_PWD(this).pass);
break;
}
}
INIT_IFACE(Class, credentialCtor, credentialDtor, NULL);
CREATE_CLASS(Credential, NULL, IFACE(Class));
// vim: set ts=4 sw=4:

42
src/auth/interface/auth.c

@ -0,0 +1,42 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "auth/auth.h"
#include "auth/credential.h"
#include "auth/interface/auth.h"
const struct interface i_Auth = {
"auth",
1
};
int
authenticate(void * auth, Credential cred)
{
int ret;
RETCALL(auth, Auth, authenticate, ret, cred);
return ret;
}
// vim: set ts=4 sw=4:

109
src/auth/ldap.c

@ -0,0 +1,109 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ldap.h>
#include "class.h"
#include "utils/memory.h"
#include "commons.h"
#include "auth/ldap.h"
#include "auth/credential.h"
#include "auth/interface/auth.h"
static
int
authLdapCtor(void * _this, va_list * params)
{
AuthLdap this = _this;
char * url = va_arg(*params, char*);
char * base_dn;
this->url = malloc(strlen(url) + 1);
strcpy(this->url, url);
this->version = 3;
base_dn = va_arg(* params, char *);
this->nbase_dn = va_arg(* params, size_t);
this->base_dn = malloc(this->nbase_dn + 1);
this->base_dn[this->nbase_dn] = 0;
memcpy(this->base_dn, base_dn, this->nbase_dn);
return 0;
}
static
void
authLdapDtor(void * _this)
{
AuthLdap this = _this;
FREE(this->base_dn);
FREE(this->url);
}
static
int
authLdapAuthenticate(void * _this, Credential cred)
{
AuthLdap this = _this;
char who[256];
char * who_ptr = who;
int ldap_err;
if (CRED_PASSWORD != cred->type) {
return FALSE;
}
ldap_initialize(&(this->ldap), this->url);
ldap_set_option(this->ldap, LDAP_OPT_PROTOCOL_VERSION, &(this->version));
memcpy(who_ptr, "cn=", sizeof("cn=") - 1);
who_ptr += sizeof("cn=") - 1;
memcpy(who_ptr, CRED_PWD(cred).user, CRED_PWD(cred).nuser);
who_ptr += CRED_PWD(cred).nuser;
*who_ptr++ = ',';
memcpy(who_ptr, this->base_dn, this->nbase_dn);
who_ptr[this->nbase_dn] = 0;
ldap_err = ldap_simple_bind_s(this->ldap, who, CRED_PWD(cred).pass);
if (0 == ldap_err) {
ldap_unbind_s(this->ldap);
//! \todo here we need to get and return the user id
return TRUE;
}
fprintf(stderr, "%s\n", ldap_err2string(ldap_err));
return FALSE;
}
INIT_IFACE(Class, authLdapCtor, authLdapDtor, NULL);
INIT_IFACE(Auth, authLdapAuthenticate);
CREATE_CLASS(AuthLdap, NULL, IFACE(Class), IFACE(Auth));
// vim: set ts=4 sw=4:

13
src/cbuf/Makefile.am

@ -0,0 +1,13 @@
ACLOCAL_AMFLAGS = -I m4
CB = cbuf.c read.c write.c \
get_line.c set_data.c get_data.c \
addr_index.c get_free.c get_read.c get_write.c \
inc_read.c inc_write.c is_empty.c memchr.c \
skip_non_alpha.c is_locked.c lock.c release.c \
empty.c
noinst_LIBRARIES = libcbuf.a
libcbuf_a_SOURCES = $(CB)
libcbuf_a_CFLAGS = -Wall -I ../../include/

33
src/cbuf/addr_index.c

@ -0,0 +1,33 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/types.h>
#include "cbuf.h"
size_t
cbufAddrIndex(Cbuf this, const void * c)
{
return c - (const void *)cbufGetRead(this);
}
// vim: set ts=4 sw=4:

125
src/cbuf/cbuf.c

@ -0,0 +1,125 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _POSIX_SOURCE
#define _POSIX_C_SOURCE 200112L
#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include "class.h"
#include "utils/memory.h"
#include "cbuf.h"
static void cbufDtor(void*);
static
int
cbufCtor(void * _this, va_list * params)
{
Cbuf this = _this;
char state = -1;
char * shm_name = va_arg(*params, char*);
long psize = sysconf(_SC_PAGESIZE);
size_t size;
int shm;
char * data;
this->shm_name = malloc(strlen(shm_name) + 7 + 2);
sprintf(this->shm_name, "/%06d_%s", getpid(), shm_name);
/**
* align size at page boundary.
* increase as neccessary
*/
size = va_arg(*params, size_t);
size = (0 >= size)? 1 : (0 != size%psize)? (size/psize)+1 : size/psize;
this->bsize = psize * size;
while (-1 == state) {
shm = shm_open(this->shm_name, O_RDWR|O_CREAT|O_EXCL, S_IRWXU);
if (-1 == shm) {
break;
}
if (-1 == ftruncate(shm, this->bsize)) {
break;
}
this->data = mmap (0, this->bsize << 1,
PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
if (this->data == MAP_FAILED) {
this->data = NULL;
break;
}
data = mmap (this->data, this->bsize,
PROT_READ|PROT_WRITE, MAP_FIXED|MAP_SHARED, shm, 0);
if (data != this->data) {
break;
}
data = mmap (this->data + this->bsize, this->bsize,
PROT_READ|PROT_WRITE, MAP_FIXED|MAP_SHARED, shm, 0);
if (data != this->data + this->bsize) {
break;
}
state = 0;
}
if (-1 != shm) {
shm_unlink(this->shm_name);
close(shm);
}
return state;
}
static
void
cbufDtor(void * _this)
{
Cbuf this = _this;
FREE(this->shm_name);
if (NULL != this->data && MAP_FAILED != this->data) {
munmap(this->data, this->bsize << 1);
}
this->data = NULL;
}
INIT_IFACE(Class, cbufCtor, cbufDtor, NULL);
CREATE_CLASS(Cbuf, NULL, IFACE(Class));
// vim: set ts=4 sw=4:

32
src/cbuf/empty.c

@ -0,0 +1,32 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "cbuf.h"
void
cbufEmpty(Cbuf this)
{
this->bused = 0;
this->read = this->write;
}
// vim: set ts=4 sw=4:

41
src/cbuf/get_data.c

@ -0,0 +1,41 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/types.h>
#include <string.h>
#include "cbuf.h"
char *
cbufGetData(Cbuf this, size_t n)
{
char * ret = cbufGetRead(this);
if (n > this->bused) {
return (char *)-1;
}
cbufIncRead(this, n);
return ret;
}
// vim: set ts=4 sw=4:

33
src/cbuf/get_free.c

@ -0,0 +1,33 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/types.h>
#include "cbuf.h"
size_t
cbufGetFree(Cbuf this)
{
return this->bsize - this->bused;
}
// vim: set ts=4 sw=4:

49
src/cbuf/get_line.c

@ -0,0 +1,49 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/types.h>
#include <string.h>
#include "cbuf.h"
char *
cbufGetLine(Cbuf this, char ** line_end)
{
char * nl = cbufMemchr(this, '\n');
char * ret = NULL;
if (NULL != nl) {
size_t len = cbufAddrIndex(this, nl) + 1;
*line_end = nl - 1;
*nl = 0;
*(nl-1) = ('\r' == *(nl-1))? 0 : *(nl-1);
ret = cbufGetRead(this);
cbufIncRead(this, len);
}
return ret;
}
// vim: set ts=4 sw=4:

31
src/cbuf/get_read.c

@ -0,0 +1,31 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "cbuf.h"
char *
cbufGetRead(Cbuf this)
{
return this->data + this->read;
}
// vim: set ts=4 sw=4:

31
src/cbuf/get_write.c

@ -0,0 +1,31 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "cbuf.h"
char *
cbufGetWrite(Cbuf this)
{
return this->data + this->write;
}
// vim: set ts=4 sw=4:

36
src/cbuf/inc_read.c

@ -0,0 +1,36 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/types.h>
#include "cbuf.h"
void
cbufIncRead(Cbuf this, size_t n)
{
this->read += n;
this->read = (this->read >= this->bsize)?
this->read - this->bsize : this->read;
this->bused -= n;
}
// vim: set ts=4 sw=4:

36
src/cbuf/inc_write.c

@ -0,0 +1,36 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/types.h>
#include "cbuf.h"
void
cbufIncWrite(Cbuf this, size_t n)
{
this->write += n;
this->write = (this->write >= this->bsize)?
this->write - this->bsize : this->write;
this->bused += n;
}
// vim: set ts=4 sw=4:

31
src/cbuf/is_empty.c

@ -0,0 +1,31 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "cbuf.h"
char
cbufIsEmpty(Cbuf this)
{
return (0 == this->bused);
}
// vim: set ts=4 sw=4:

33
src/cbuf/is_locked.c

@ -0,0 +1,33 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "cbuf.h"
#include "commons.h"
Bool
cbufIsLocked(Cbuf this)
{
return this->lock;
}
// vim: set ts=4 sw=4:

31
src/cbuf/lock.c

@ -0,0 +1,31 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "cbuf.h"
void
cbufLock(Cbuf this)
{
this->lock = TRUE;
}
// vim: set ts=4 sw=4:

33
src/cbuf/memchr.c

@ -0,0 +1,33 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include "cbuf.h"
char *
cbufMemchr(Cbuf this, int c)
{
return memchr(cbufGetRead(this), c, this->bused);
}
// vim: set ts=4 sw=4:

60
src/cbuf/read.c

@ -0,0 +1,60 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include "cbuf.h"
#include "stream.h"
ssize_t
cbufRead(Cbuf this, Stream st)
{
ssize_t rrsize = 0;
size_t rsize = cbufGetFree(this);
if (0 == rsize) {
errno = ECBUFOVFL;
return -1;
}
rrsize = streamRead(st, cbufGetWrite(this), rsize);
switch (rrsize) {
case 0:
rrsize = -2;
// DROP THROUGH
case -1:
break;
default:
cbufIncWrite(this, rrsize);
break;
}
return rrsize;
}
// vim: set ts=4 sw=4:

31
src/cbuf/release.c

@ -0,0 +1,31 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "cbuf.h"
void
cbufRelease(Cbuf this)
{
this->lock = FALSE;
}
// vim: set ts=4 sw=4:

45
src/cbuf/set_data.c

@ -0,0 +1,45 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/types.h>
#include <string.h>
#include <errno.h>
#include "cbuf.h"
char *
cbufSetData(Cbuf this, const void * src, size_t n)
{
char * addr;
if (n > cbufGetFree(this)) {
errno = ECBUFOVFL;
return (char *)-1;
}
addr = memcpy(cbufGetWrite(this), src, n);
cbufIncWrite(this, n);
return addr;
}
// vim: set ts=4 sw=4:

34
src/cbuf/skip_non_alpha.c

@ -0,0 +1,34 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ctype.h>
#include "cbuf.h"
void
cbufSkipNonAlpha(Cbuf this)
{
while(0 < this->bused && !isalpha(*cbufGetRead(this)))
cbufIncRead(this, 1);
}
// vim: set ts=4 sw=4:

52
src/cbuf/write.c

@ -0,0 +1,52 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/types.h>
#include <unistd.h>
#include "cbuf.h"
#include "stream.h"
ssize_t
cbufWrite(Cbuf this, Stream st)
{
ssize_t wwsize = 0;
size_t wsize = this->bused;
if (0 == wsize) return 0;
wwsize = streamWrite(st, cbufGetRead(this), wsize);
switch (wwsize) {
case -1:
break;
default:
cbufIncRead(this, wwsize);
break;
}
return wwsize;
}
// vim: set ts=4 sw=4:

6
src/class/Makefile.am

@ -0,0 +1,6 @@
ACLOCAL_AMFLAGS = -I m4
noinst_LIBRARIES = libclass.a
libclass_a_SOURCES = interface.c interface/i_class.c
libclass_a_CFLAGS = -Wall -I ../../include/

64
src/class/interface.c

@ -0,0 +1,64 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/types.h>
#include <stdlib.h>
#include "class/interface.h"
#include "commons.h"
static
inline
int
comp(const void * _a, const void * _b)
{
const struct interface * a = **(const struct interface ***)_a;
const struct interface * b = **(const struct interface ***)_b;
return ((a)<(b))? -1 : ((a)>(b))? 1 : 0;
}
/**
* this one is important in selector functions to get the correct interface
* implementation of a class.
*/
iface_ptr
interfaceGet(iface_impl_ptr iface_impl, const iface_ptr _iface)
{
const iface_ptr * iface = &_iface;
iface_ptr * found;
if (! iface_impl->simpl) {
qsort((void**)(iface_impl->impl), iface_impl->nimpl, sizeof(iface_ptr), comp);
iface_impl->simpl=TRUE;
}
found = bsearch(
&iface,
iface_impl->impl,
iface_impl->nimpl,
sizeof(iface_ptr),
comp);
return found? *found : (iface_ptr)NULL;
}
// vim: set ts=4 sw=4:

83
src/class/interface/i_class.c

@ -0,0 +1,83 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdarg.h>
#include <stdlib.h>
#include <assert.h>
#include "class/class.h"
#include "class/interface/class.h"
const
struct interface i_Class = {
"class",
3
};
void *
classNew(class_ptr class, ...)
{
void * object = calloc(1, class->object_size + sizeof(void*));
va_list params;
int ret;
* (class_ptr *)object = class;
object += sizeof(void*);
va_start(params, class);
RETCALL(object, Class, ctor, ret, &params);
va_end(params);
if (-1 == ret) {
classDelete(&object);
}
return object;
}
void
classDelete(void ** object)
{
if (NULL != *object) {
CALL(*object, Class, dtor);
free(*object - sizeof(void*));
*object = NULL;
}
}
void *
classClone(void * _object)
{
class_ptr class = GET_CLASS(_object);
void * object = calloc(1, class->object_size + sizeof(void*));
* (class_ptr *)object = class;
object += sizeof(void*);
#undef clone
CALL(object, Class, clone, _object);
return object;
}
// vim: set ts=4 sw=4:

9
src/hash/Makefile.am

@ -0,0 +1,9 @@
ACLOCAL_AMFLAGS = -I m4
HASH = hash.c add.c get.c delete.c each.c value.c \
interface/hashable.c
noinst_LIBRARIES = libhash.a
libhash_a_SOURCES = $(HASH)
libhash_a_CFLAGS = -Wall -I ../../include/

53
src/hash/add.c

@ -0,0 +1,53 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <search.h>
#include "hash.h"
#include "class.h"
static
inline
int
hashAddComp(const void * a, const void * b)
{
return hashableGetHash((void*)b) - hashableGetHash((void*)a);
}
void *
hashAdd(Hash this, void * operand)
{
void * found = tsearch(operand, &(this->root), hashAddComp);
if (NULL == found) {
return NULL;
}
if (operand != *(void**)found) {
hashableHandleDouble(*(void**)found, operand);
delete(operand);
}
return *(void**)found;
}
// vim: set ts=4 sw=4:

46
src/hash/delete.c

@ -0,0 +1,46 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <search.h>
#include <sys/types.h>
#include "hash.h"
#include "utils/hash.h"
static
inline
int
hashDeleteComp(const void * a, const void * b)
{
return hashableGetHash((void*)b) - *(const unsigned long*)a;
}
void *
hashDelete(Hash this, const char * search, size_t nsearch)
{
unsigned long hash = sdbm((const unsigned char *)search, nsearch);
void * found = tfind(&hash, &(this->root), hashDeleteComp);
return (NULL != found)? *(void**)found : NULL;
}
// vim: set ts=4 sw=4:

47
src/hash/each.c

@ -0,0 +1,47 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <search.h>
#include "hash.h"
static void (*cb)(void*);
static
inline
void
walk(const void * node, const VISIT which, const int depth)
{
if (endorder == which || leaf == which) {
cb(*(void**)node);
}
}
void
hashEach(Hash this, void (*callback)(const void*))
{
cb = callback;
twalk(this->root, walk);
}
// vim: set ts=4 sw=4:

46
src/hash/get.c

@ -0,0 +1,46 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <search.h>
#include <sys/types.h>
#include "hash.h"
#include "utils/hash.h"
static
inline
int
hashGetComp(const void * a, const void * b)
{
return hashableGetHash((void*)b) - *(const unsigned long*)a;
}
void *
hashGet(Hash this, const char * search, size_t nsearch)
{
unsigned long hash = sdbm((const unsigned char *)search, nsearch);
void * found = tfind(&hash, &(this->root), hashGetComp);
return (NULL != found)? *(void**)found : NULL;
}
// vim: set ts=4 sw=4:

63
src/hash/hash.c

@ -0,0 +1,63 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE
#include <search.h>
#include <stdarg.h>
#include "hash/hash.h"
#include "class.h"
static
int
hashCtor(void * _this, va_list * params)
{
return 0;
}
static
inline
void
tDelete(void * node)
{
delete(node);
}
static
void
hashDtor(void * _this)
{
Hash this = _this;
/**
* this is a GNU extension...anyway on most non
* GNUish systems i would not use tsearch anyway
* as the trees will be unbalanced.
*/
tdestroy(this->root, tDelete);
}
INIT_IFACE(Class, hashCtor, hashDtor, NULL);
CREATE_CLASS(Hash, NULL, IFACE(Class));
// vim: set ts=4 sw=4:

51
src/hash/interface/hashable.c

@ -0,0 +1,51 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include "class.h"
#include "hash/interface/hashable.h"
const struct interface i_Hashable = {
"hashable",
2
};
unsigned long
hashableGetHash(void * hashable)
{
unsigned long ret;
RETCALL(hashable, Hashable, getHash, ret);
return ret;
}
void
hashableHandleDouble(void * hashable, void * new_hashable)
{
CALL(hashable, Hashable, handleDouble, new_hashable);
}
// vim: set ts=4 sw=4:

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save