Rename miniweb to httpserver

The name 'miniweb' does not really mean anything.  Rename the project to
'httpserver'.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: remove unused config object

The config object was passed to object that didn't used it.
This causes a warning during compilation.

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

Fix a formatting glitch introduced in commit 01158e4 ("Http Server:
remove unused config object").

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Serve: Clean up the matcher class

Tidying the matcher class, moved the parameters to private
and set a helper function in the cc class to static

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: Add mime types for ico and txt

In the review process of the http server, it was noted that other Mime
Types might be used.

Specifically ico and txt are poular and will be used when the server
will return pages as a web server.

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

Return the OS Version using the version method when part of the OSv Image.
Use a stub function when run locally.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: Change the OS version stub to use uname

When run locally the OS version will use the linux uname method
to return the OS version.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: Move handlers in the api directory

The os version handler moved from main to the api directory.

The idea is that each api swagger definition file under mgmt/api/listings/
will have a file with its handlers

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: Clean up <api/os.hh>

Fix include guards and odd include path.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: Fix include path in Makefile

Fixes build breakage caused by commit c69fad2 ("Http Server: Clean up
<api/os.hh>"):

  CXX obj/api/os.o
In file included from api/os.cc:9:0:
api/os.hh:14:21: fatal error: routes.hh: No such file or directory
 #include "routes.hh"
                     ^

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: Json formatter

The json formatter, format primitives to a json format.
It overload to_json method with the different types.

It can be used directly, to format return value as a json primitive.
it is also used by json objects to help them format themselfs

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: Change the OS version to work with the json formatter

The Os version handler use the json formatter to return
json formatted result

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

Change the HTTP server to use boost_program_options-mt instead of
boost_program_options to be compatible with the OSv boost libraries.

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

Path information is defined in the Swagger API definition file.  This include
the url path (e.g. /os/version) the method (GET/POST) and a nickname.

A patch in the API is mapped to a path_description object and is stored in a
hash so it can be located by its nickname.

The actuall mapping of the json to c++ code is done by an extenrnal json script
during the compilation

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

Json objects are struct that inherit from json_base and that all their
members are json_element.

To be able to format a json object, each of its member has a name and a
flag that mark if it is set or not.

All json element inherit from json_base_element that holds the set bit a
name and a flag that specify if it is mandatory or optional.

Most json element will instantiate the json_element template with a
type.

A specific json_element implementation handles list.  A json list is set
(and will be part of the result) if a value was pushed to it.

The json_base, a base class to all json objects, holds a vector of
elements, an inherit class will set its member in the base class vector.
This mimic reflection functionality, allowing to iterate over the class
members.

The ability to iterate over the class member is used by the format
method and the verify method

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

The formatter, format various data types to json.

This patch adds support for two additional types: unsigned long used in
the os.json swagger file and json objects.

If obj is a json object, to get a string representation of it, it should
be possible to call:

formatter::to_json(obj);

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: Routes can be configure with a json path

The json_path object are initilized with information taken from the
swagger definition file.

Route defintion can use a json_path object to set a route to a handler.
If os_version is a pointer to a handler and "getOSversion" is a nickname
of the operation, it should be possible to call:

routes.add_path("getOSversion", os_version);

to set the path

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

The python script creates json objects and json path from the json
swagger definitions.  For each json file there a header file which
contain any object definition, and a source file which contain the path
initilization, that can later be used to declare a path in the route
object

The script is run from the makefile during the compilation

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

The Makefile uses dependcy rules to create cc/hh files from json files.
Temporary source files are kept to allow code brawsing.

make clean will delete the autogen code as well

This patch also contains the removal of libraries dependencies from the
linkage of the so file object

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: Initilize the route from the json path definition

The json_path is initilized based on the Swagger json API definition
setting the route to match the os version operation is done by the
operation nickname.

In this situation, if the API will be modified the path will be changed
accordingly without any changes to the code.

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