httpserver: build with optimizations

I'm seeing a wierd miscompile without this, but it's a good idea anyway.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
build: clean httpserver build products

Otherwise wierd miscompilations pop up all over the place if there are
dependency issues (and there are).

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
httpserver: add build dependencies

Or chase mysterious bugs forever.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Http Server: Clean up in the lambda expression handlers

To simplify the use of lambda expression as handlers, the function type
was define, and additional function was added, a one that gets not only
the request but also the reply, this will allow using
lambda expression in more complicated scenarios then before.

The function handler was modified to use the more general function and a
temporary function is used to do the translation.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Http Server: handler to support mandatory parameters

Mandatory parameters are query parameters that the handler expect to
exists before starting the handler logic.

The handler now holds a list of mandatory parameter, that will be verify
before the handler is called.

The handler logic can safely assume all the mandatory parameters are
there and doesn't need to verify it.
If the parameters are missing a 400 will be return with the appropriate
error message.

The code generator will automatically adds any mandatory parameter from
the Swagger definition file. But it is also possible to add additional
parameters.

if h is the handler calling:
h.mandatory("op");

will add the query parameter "op" as a mandatory parameter

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Http Server: add mandatory parameters to the path

The path object that holds the information form the Swagger definition
file now holds a list of mandatory parameters.

Those parameters will be used to validate that mandatory parameters are
included before calling the handler logic.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Http server: Add a parameter not found exception

When a mandatory parameter is missing a missing mandatory exception will
be thrown.

The exception constructor gets the parameter name is a parameter.
It will return a 400 bad request.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Http Server: Add mandatory parameters support to the routes

The routes object now copy mandatory parameters from the path object to
the handler and uses the mandatory parameters in the handler to verify
that the mandatory parameters are in the request before calling the
handler logic.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Http server: Adding path holder

Path holder is an object that simplifies setting a handler to an api
define in the Swagger definition file.

The code generation will set a path holder object for each of the api
calls. For example to the api action "getFile" the following will be
define:

static const path_holder getFile("getFile");

getFile can now be used to set a handler to the operation. So if h is a
handler you can do:

getFile.set_handler(h);

It also support lamda expression, so if f is a request_function (as
define in the handlers.hh file) you can do:

getFile.set_handler(f,"json");

With the new API there is no need to access the routes object in most
cases.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Http server: code generation to support mandatory parameters

Mandatory query parameters are now set with the path description

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Http Server: Code generation declare path holder

Path holder replaces the constant name of the operation, the code
generation uses them instead of string.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Http Server: Initilialize the path_holder

The path_holder holds a pointer to the routes object. The main should
initialize it after creating the routes object.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Http Server: file.cc to use new API

The changed API, changed how a handler is set for an action, the file.cc
was modified to use the new API.

So setting a handler becomes:
getFile.set_handler(new get_file_handler());

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Http Server: running astyle on jvm.cc

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Http Server: jvm and os API implementation to use new API

With the introduce of the new API os and jvm implementation can now use
it in a cleaner and safer way.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Http Server: Modify the parameter order in path_holder

By modifying the parameter order in path holder, it is possible to add
the lambda expression directly as a parameter to the set_handler
function.

Now it is possible to write:
getOSversion.set_handler("json", [](const_req req)
    {
        return formatter::to_json(osv::version());
    });

the os.cc and jvm.cc where modified to use the shorten version

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Http Server: set a default type in path holder to be json

For most cases the return type of a handler is json, this adds a default
behavior so if the path holder is osVersion and the handler function is
f it will be possible to do:

osVersion.set_handler(f);
or
osVersion.set_handler("txt",f);

Keeping the simplified option when type is supplied but allows to ommit
it for the common case.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Http Server: Move the parameters object to the request

The parameter map, holds path parameters. For example the if a url
matching rule is defined as /file/{path} and a url is /file/etc/hosts
the param object will hold an entry for "path" => "/etc/hosts".

To simplify the API the parameters object was moved to the request
object. It can only be calculated by the routes, as it depends on
specific handler (ie. /file/etc/{path} and /file/{path} will have
different value in the path entry)

For that the routes will get the request as non const reference and
will use the parameters object that is now in the request.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Swagger API: Adding the env.json

This is the Swagger definition file for environment variable.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Swagger API: Adding the env.json to the api-docs

Adding the env.json to the api-docs so it will appear in the Swagger UI
GUI.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>