Http Server: matchers

matchers are used in match rules to decide if a url matches
some logic.

For example consider the rule: /file/{path} where path
is a parameter.
This rule would match /file/etc/hosts, but would not match /file1/etc/hosts

A rule that would match this url would be combined from two matchers.
An str_matcher that would match the static part '/file'
And a param_matcher that would match the remaining url ('/etc/hosts')

For param_matcher there are two options:
They can match either a part between slashes
(e.g. for cases /usr/{name}/get) or until the end of the
URL like the /file example above

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
[ penberg: cleanups ]
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: match rule

Match rule check if a given url match some logic, if it does,
it returns the handler assigned to it.

A match rule has a list of matchers, when searching
for a match, it iterate over them.
Each match returns the next position in the url,
a match would also fill the parameters object when needed.

Consider the rule /file/{path} and the url /file/etc/hosts

The match rule would hold a handler and two matcher, an
str_matcher
and a param_matcher.

It would call the first matcher with the url, it would get back
7 (the end position of the match), the parameters object is still
not changed at this point.
It would then call the second matcher that would return the
end of the string position and would fill in the parameter
object, parameters 'path' with value /etc/hosts

As this is the end of the string and there are no more matcher
the match rule would return the handler

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
[ penberg: cleanups ]
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: json_element

This patch adds the ability to handle json objects.

The basic building block of a json object is an element.

The base class for all json element is the json_base_element,
that has a name and two flags to state if this element is mandatory
and if this element was set.

From json_base_element, there are two inherited classes, the json_element
which is a template for types.

And the json_list which is a list of elements.
It is up to the inherit class to set the the flag when their value
is set.

The json element uses the json parser to format their value in a
json maner.

json objects are objects that all their members are json elements.
All json object inherit from json_base.

the json base holds a vector with pointers to all object memebers.

This way, an inherit class, add its field to the vector allowing
the json base to itertate over them. This is similiar to reflection
in other languages.

json classes are auto generated from the json swagger definition
file during compilation.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
[ penberg: cleanups ]
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: json_path

json path holds information about path definition.
path definition contained the information required
from an external client to reach some action.

Those action are identified by a nickname.
A path object holds the path (url) the http action (GET/PUT)
and path parameters.

The json path is updated when the json swagger files are parssed,
in the auto code generation that also creates the json files

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
[ penberg: cleanups ]
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: routes

The routes object holds the dispatching information for
the incoming http reqeust.

It uses either an exact match or a match rules to find a
handler to handle the request based on its URL request.

If no handler is found, a page not found is returned.
If an exception is thrown during the processing of the
handler an internal server error is returned.

The matching is done in two phases, first an exact match
is search for.
For that the routes holds a map of url, if an exact match
is found, its associated handler is returned.

If there is no exact match, a matching rule is searched.
Matching rules are choose by their insertion order.
where the first rules that inserted has the highest priority.

For that, routes holds a vector of matching rules that
is search for a match.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
[ penberg: cleanups ]
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: request_handler

The request handlers gets the request object, parse the url
And use the routes object to handle the request.

This file was taken from the boost example and was modified
to use the routes object

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
[ penberg: cleanups ]
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: handlers implementation

handlers implementation adds specific logic for specific cases.

Currently it contains the file information handler, that
get a path to a file or directory and returns information on it

handler implementation also contains the initilization part of the routes.
This is where handlers are subscribed to routes

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
[ penberg: cleanups ]
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: connection

connection holds the open socket for the request.
It uses the parser to parse the incoming message and
create a reqeust object from it.

It would use the reply to answer the request and would
close the connection.

This file was taken from the boost example

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
[ penberg: cleanups ]
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: connection_manager

The connection manager is a container for the connections.
It can be used by the server for force connection
termination on exit.

This file was taken from the boost example

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
[ penberg: cleanups ]
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: server

The sever listen to incoming request, when a new request is comming
it call accept and passes the new socket to the connection manager,
which would pass it to a new connection

This file was taken from the boost example

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
[ penberg: cleanups ]
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: main

The main class parse the command line, starts the server and prints
the help if needed

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
[ penberg: cleanups ]
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: json2code parser

The python script reads the swagger json definition
and creates the json objects and json path.
It creates a header and a path definition file for each swagger file

All of its configuration can be override from command line.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: makefile

This patch adds a make file to the http server.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>