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

Commit 3640c56

Browse files
Wu Yu Weijkrvivian
authored andcommitted
feat(server): Implement microhttpd framework (#241)
* 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)
1 parent 38bbe7a commit 3640c56

File tree

5 files changed

+531
-0
lines changed

5 files changed

+531
-0
lines changed

accelerator/BUILD

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ cc_binary(
1313
],
1414
)
1515

16+
cc_binary(
17+
name = "accelerator_microhttpd",
18+
srcs = ["main.c"],
19+
copts = ["-DLOGGER_ENABLE"],
20+
deps = [
21+
":http",
22+
":ta_config",
23+
":ta_errors",
24+
"@entangled//utils/handles:signal",
25+
],
26+
)
27+
1628
cc_image(
1729
name = "ta_image",
1830
binary = ":accelerator",
@@ -34,6 +46,19 @@ cc_library(
3446
],
3547
)
3648

49+
cc_library(
50+
name = "http",
51+
srcs = ["http.c"],
52+
hdrs = ["http.h"],
53+
visibility = ["//visibility:public"],
54+
deps = [
55+
":apis",
56+
":ta_config",
57+
":ta_errors",
58+
"@libmicrohttpd",
59+
],
60+
)
61+
3762
cc_library(
3863
name = "common_core",
3964
srcs = ["common_core.c"],

accelerator/errors.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ extern "C" {
5151
#define SC_MODULE_RES (0x06 << SC_MODULE_SHIFT)
5252
#define SC_MODULE_CONF (0x07 << SC_MODULE_SHIFT)
5353
#define SC_MODULE_UTILS (0x08 << SC_MODULE_SHIFT)
54+
#define SC_MODULE_HTTP (0x09 << SC_MODULE_SHIFT)
5455
/** @} */
5556

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

151+
// UTILS module
150152
SC_UTILS_NULL = 0x01 | SC_MODULE_UTILS | SC_SEVERITY_FATAL,
151153
SC_UTILS_WRONG_REQUEST_OBJ = 0x02 | SC_MODULE_UTILS | SC_SEVERITY_FATAL,
152154
/**< wrong TA request object */
155+
156+
// HTTP module
157+
SC_HTTP_OOM = 0x01 | SC_MODULE_HTTP | SC_SEVERITY_FATAL,
158+
/**< Fail to create http object */
159+
SC_HTTP_NULL = 0x02 | SC_MODULE_HTTP | SC_SEVERITY_FATAL,
160+
/**< NULL object in http */
161+
SC_HTTP_INVALID_REGEX = 0x03 | SC_MODULE_HTTP | SC_SEVERITY_MAJOR,
162+
/**< Invalid URL regular expression rule in http */
163+
SC_HTTP_URL_NOT_MATCH = 0x04 | SC_MODULE_HTTP | SC_SEVERITY_MAJOR,
164+
/**< URL doesn't match regular expression rule */
165+
SC_HTTP_URL_PARSE_ERROR = 0x05 | SC_MODULE_HTTP | SC_SEVERITY_MAJOR,
166+
/**< URL parameter parsing error */
153167
} status_t;
154168

155169
typedef enum {

0 commit comments

Comments
 (0)