Shell: Add `top` as an alias for `thread top`

Fixes #17.

Signed-off-by: Or Cohen <orc@fewbytes.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
httpserver: compile using boost headers matching libraries we link with

Spotted when analyzing GDB backtrace. We compiled the server using
headers installed on the host, which may come from different version
of boost than the one we put in the image.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Shell: Removed tests from shell package

These tests will be available in the cloudius.jar package.

Signed-off-by: Or Cohen <orc@fewbytes.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
shell: Dynamically load/call Stty

Stty currently compiles and loads from mgmt, but it originally belongs to the
OSv main build, coupled with the JNI. Removing Stty from this build and moving
it to cloudius.jar, creates a problem.

Because cloudius.jar might not be available at compile time, OSvTerminal was
changed to load and call Stty in a dynamic manner. If it fails, a warning will
be logged with the exception trace.

Signed-off-by: Or Cohen <orc@fewbytes.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
shell: Remove cli and cloudius gradle projects

These projects are coupled with JNI, which is built with the main OSv.

Signed-off-by: Or Cohen <orc@fewbytes.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
shell: Proper formatting

Signed-off-by: Or Cohen <orc@fewbytes.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: Code Cleanup in routes and matchrules

A clean up patch that modify the camel case to snake case and a bit
formatting

Reviewed-by: Tomasz Grabiec <tgrabiec@gmail.com>
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: Code clean up and astyle handlers

This patch is a result of running astyle on the file and remove some
redundant code.

Reviewed-by: Tomasz Grabiec <tgrabiec@gmail.com>
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: Rename parser to transformer

Transformer are used to modify content return from file, previous name
parser, could be confusing. The base class for file content
transformation is file_transformer and the method is transform

Reviewed-by: Tomasz Grabiec <tgrabiec@gmail.com>
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http server: file interaction handlers complete support for file_transformer

The file_transformer is an option to modify a file while reading it and
modify part of its content.

For example, the Swagger json api, needs to contain an abosolute valid
url path. To do that a variable is placed inside the json file
'{{Host}}' and when a file is read, a transformer would replace the
{{Host}} with the host identifier taken from the request (ie.
192.168.122.89:8000)

To simplify using the transformer, it was added as an optional parameter
to the file_interaction_handler constructor and a destructor was added
to remove it.

Reviewed-by: Tomasz Grabiec <tgrabiec@gmail.com>
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: Search a header in the request by its name

The request object holds the headers in a vector. This is because a
header can apear more than once. Sometimes it is nessary to find a
header, where only one header will be found.

The get_header method searches for the first header by its name

Reviewed-by: Tomasz Grabiec <tgrabiec@gmail.com>
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: add get_url to the request

It is sometimes required to have the full url of the request, this is a
combination of the protocl the host and the uri.

get_url return the url

Reviewed-by: Tomasz Grabiec <tgrabiec@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: fix a bug in the matcher

While testing the code a bug was found in the matcher. The matcher
should use find and not find_first

find_first return the first character from the given string and not the
location of the given string.

In practice in the code the url parameter that would be passed to its
search string will start with a slash, and becasue that so do the url,
this call will always return 0 and this part of the if, will succeed.
Consider this case: url = "/ui/os" param="/uiabc" those two are
different, and find will return npos, but find_first will return 0 and
the entire if will evaluate to true.

Reviewed-by: Tomasz Grabiec <tgrabiec@gmail.com>
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: allows empty paramter in a path parameter

Speficially for parameters that gets the entire url and used for file
path, an empty parameter is a valid value. This change allows it

so the rule that matches: /file/{path} will match the url /file/ with
path equals to the empty string

Reviewed-by: Tomasz Grabiec <tgrabiec@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: add redirect on missing slash

When returning a file from the server, if the path specify doesnot
include the file name it must end with a slash. If a slash is ommitted,
the request will be redirect to the same url with a slash at the end

redirect_if_needed check if the path is missing the slash at the end, if
so it would redirect the request

Reviewed-by: Tomasz Grabiec <tgrabiec@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: when requesting for a directory adds index.html to the path

When act as a web application and returning files according to a
relative path, if the path is a directory and index.html will be added
to the path.

If a slash is missing from the end of the path a redirect to the url
with a slash at the end will be returned

Reviewed-by: Tomasz Grabiec <tgrabiec@gmail.com>
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: Add a file transformer

When the http server reads a file from the disk, it is sometimes
required that the file content will be transform and string substitution
will be perform.

For example, when reading the json files, it is required to place the
real host name/ip so the Swagger-UI will be able to use those files. The
file transformer will look for a variable in the file (given that it has
the right extension) and will replace it.

Currently it only support {{Host}} variable, additional variable can be
added when needed

Reviewed-by: Tomasz Grabiec <tgrabiec@gmail.com>
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: Simplify the routes API with the url object

When adding a route with parameters, the syntex can be complicated. To
simplify the API a url class was introduce. it is now possible to add
the rule /api/{path}, where the 'path' parameter matches all url to its
end, like:

routes.add(GET, url("/api").remainder("path"), handler);

Reviewed-by: Tomasz Grabiec <tgrabiec@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: Add file mapping

There are few scenarios where the httpserver should return files from
the disk in reply to a request.

Currently: Swagger library, and the Json definition files

so a call to
http://192.168.122.89:8000/api/api-docs.json
should return the api doc

The Swagger libray, that is located under /usr/mgmt/swagger-ui is mapped
to /ui so a call to
http://192.168.122.89:8000/ui/index.html
should open the Swagger GUI

The swagger index.html is mapped to /ui so a call to
http://192.168.122.89:8000/ui would also open the Swagger gui

Reviewed-by: Tomasz Grabiec <tgrabiec@gmail.com>
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: Add file mapping to main

main should call the init method to initilize file mapping

Reviewed-by: Tomasz Grabiec <tgrabiec@gmail.com>
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>