Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Commit

Permalink
feat(server): Implement microhttpd framework (#241)
Browse files Browse the repository at this point in the history
* feat(server): Implement server core functions with microhttpd

* feat(server): Implement signal handler to terminate TA

- Add signal handler for SIGINT and SIGTERM
- Add logger when error occurred, starting and destroying TA

* feat(server): Implement URL parser

* Match request URL with regular expression
* Parse parameter to use with strtok

* feat(server): Implement generate_address API callback function

* feat(server): Implement find_txn_by_tag API callback function

* feat(server): Implement find_txn_obj_by_tag API callback function

* feat(server): Implement get_txn_obj API callback function

* feat(server): Implement get_tips_pair API callback function

* feat(server): Implement get_tips API callback function

* feat(server): Implement send_transfer API callback function

* feat(server): Implement recv_mam_msg API callback function

* feat(server): Implement send_mam_msg API callback function

* feat(server): Implement invalid path handling callback function

* feat(server): Implement OPTIONS request handling callback function

* feat(server): Implement send_trytes API callback function

* fix(server): Rename POST and OPTIONS flag

* fix: Refactor codelines to meet coding style

* feat(server): Implement req / res log message

* fix(server): Fix wrong url length in ta_get_url_parameter

* fix(api): Update find txn related apis (#237)

* fix(server): Check request body in POST api callback functions (#239)

If the GET request has the same url with the POST apis, it should return
a method_not_allowed response. Thus we should check if body is empty or not
in the callback functions before execution.

* fix(server): Modify error code switch case in set_response_content (#240)
  • Loading branch information
Wu Yu Wei authored and jkrvivian committed Jul 5, 2019
1 parent 38bbe7a commit 3640c56
Show file tree
Hide file tree
Showing 5 changed files with 531 additions and 0 deletions.
25 changes: 25 additions & 0 deletions accelerator/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ cc_binary(
],
)

cc_binary(
name = "accelerator_microhttpd",
srcs = ["main.c"],
copts = ["-DLOGGER_ENABLE"],
deps = [
":http",
":ta_config",
":ta_errors",
"@entangled//utils/handles:signal",
],
)

cc_image(
name = "ta_image",
binary = ":accelerator",
Expand All @@ -34,6 +46,19 @@ cc_library(
],
)

cc_library(
name = "http",
srcs = ["http.c"],
hdrs = ["http.h"],
visibility = ["//visibility:public"],
deps = [
":apis",
":ta_config",
":ta_errors",
"@libmicrohttpd",
],
)

cc_library(
name = "common_core",
srcs = ["common_core.c"],
Expand Down
14 changes: 14 additions & 0 deletions accelerator/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ extern "C" {
#define SC_MODULE_RES (0x06 << SC_MODULE_SHIFT)
#define SC_MODULE_CONF (0x07 << SC_MODULE_SHIFT)
#define SC_MODULE_UTILS (0x08 << SC_MODULE_SHIFT)
#define SC_MODULE_HTTP (0x09 << SC_MODULE_SHIFT)
/** @} */

/** @name serverity code */
Expand Down Expand Up @@ -147,9 +148,22 @@ typedef enum {
SC_CONF_UNKNOWN_OPTION = 0x03 | SC_MODULE_CONF | SC_SEVERITY_FATAL,
/**< undefined option in CLI */

// UTILS module
SC_UTILS_NULL = 0x01 | SC_MODULE_UTILS | SC_SEVERITY_FATAL,
SC_UTILS_WRONG_REQUEST_OBJ = 0x02 | SC_MODULE_UTILS | SC_SEVERITY_FATAL,
/**< wrong TA request object */

// HTTP module
SC_HTTP_OOM = 0x01 | SC_MODULE_HTTP | SC_SEVERITY_FATAL,
/**< Fail to create http object */
SC_HTTP_NULL = 0x02 | SC_MODULE_HTTP | SC_SEVERITY_FATAL,
/**< NULL object in http */
SC_HTTP_INVALID_REGEX = 0x03 | SC_MODULE_HTTP | SC_SEVERITY_MAJOR,
/**< Invalid URL regular expression rule in http */
SC_HTTP_URL_NOT_MATCH = 0x04 | SC_MODULE_HTTP | SC_SEVERITY_MAJOR,
/**< URL doesn't match regular expression rule */
SC_HTTP_URL_PARSE_ERROR = 0x05 | SC_MODULE_HTTP | SC_SEVERITY_MAJOR,
/**< URL parameter parsing error */
} status_t;

typedef enum {
Expand Down
Loading

0 comments on commit 3640c56

Please sign in to comment.