|
DTNMA Reference Tools v2.1.0 - 13.gc5c0bac
Delay-Tolerant Networking Management Architecture (DTNMA) Tool Suite
|
#include "nm_rest.h"#include <cace/ari/text_util.h>#include <cace/ari/cbor.h>#include <cace/ari/text.h>#include <cace/util/logging.h>#include <cace/util/defs.h>#include <m-bstring.h>#include <cjson/cJSON.h>#include <civetweb.h>#include <stdlib.h>#include <string.h>#include <strings.h>
Include dependency graph for nm_rest.c:Macros | |
| #define | REQUEST_BODY_CHUNK 4096 |
| Chunking size for receiving request bodies. | |
| #define | BASE_API_URI "/nm/api" |
| #define | VERSION_URI BASE_API_URI "/version$" |
| #define | AGENTS_URI BASE_API_URI "/agents$" |
| #define | AGENTS_IDX_PREFIX BASE_API_URI "/agents/idx/" |
| #define | AGENTS_EID_PREFIX BASE_API_URI "/agents/eid/" |
Functions | |
| static int | requireContentType (struct mg_connection *conn, const char *match) |
| static int | readRequstBody (struct mg_connection *conn, m_bstring_t data) |
| static size_t | SendJSON (struct mg_connection *conn, const cJSON *json_obj) |
| static int | log_message (const struct mg_connection *conn, const char *message) |
| static int | versionHandler (struct mg_connection *conn, void *cbdata) |
| static int | agentsGetHandler (struct mg_connection *conn) |
| static int | agentsPostHandler (struct mg_connection *conn) |
| static int | agentsHandler (struct mg_connection *conn, void *cbdata) |
| static int | agentParseHex (struct mg_connection *conn, cace_ari_list_t tosend) |
| static int | agentParseText (struct mg_connection *conn, cace_ari_list_t tosend) |
| static int | agentSendItems (struct mg_connection *conn, refdm_agent_t *agent, cace_ari_list_t tosend) |
| static int | agentShowTextReports (struct mg_connection *conn, refdm_agent_t *agent) |
| static int | agentShowHexReports (struct mg_connection *conn, refdm_agent_t *agent) |
| static int | getSegmentDecoded (struct mg_connection *conn, const char *prefix, m_string_t seg) |
| static int | getAgentFromEid (struct mg_connection *conn, const char *prefix, refdm_agent_t **agent) |
| static int | getFormParam (struct mg_connection *conn, char *form, size_t form_len) |
| static int | agentAnySendHandler (struct mg_connection *conn, refdm_agent_t *agent) |
| The . | |
| static int | agentEidSendHandler (struct mg_connection *conn, void *cbdata) |
| Handler /agents/eid/$eid/send - Send EXECSET encoded according to query key "form". | |
| static int | agentEidClearReportsHandler (struct mg_connection *conn, void *cbdata) |
| Handler /agents/eid/$eid/clear_reports - Clear all received reports for this agent. | |
| static int | agentAnyReportsHandler (struct mg_connection *conn, refdm_agent_t *agent) |
| The . | |
| static int | agentEidReportsHandler (struct mg_connection *conn, void *cbdata) |
| Handler /agents/eid/$eid/reports/hex - Retrieve array of reports in CBOR-encoded HEX form. | |
| static int | getAgentFromIdx (struct mg_connection *conn, const char *prefix, refdm_agent_t **agent) |
| static int | agentIdxSendHandler (struct mg_connection *conn, void *cbdata) |
| Handler /agents/idx/$idx/hex - Send HEX-encoded CBOR Command (hex string as request body). | |
| static int | agentIdxClearReportsHandler (struct mg_connection *conn, void *cbdata) |
| Handler /agents/idx/$idx/clear_reports - Clear all received reports for this agent. | |
| static int | agentIdxReportsHandler (struct mg_connection *conn, void *cbdata) |
| Handler /agents/idx/$idx/reports/hex - Retrieve array of reports in CBOR-encoded HEX form. | |
| int | refdm_nm_rest_start (struct mg_context **ctx, refdm_mgr_t *mgr) |
| Begin operation of the REST service. | |
| void | refdm_nm_rest_stop (struct mg_context *ctx) |
| Stop operation of the REST service. | |
Variables | |
| static const char * | uri_seg_sep = "/?#" |
| Characters disallowed in URI segments (per RFC 3986) to know where they end. | |
| #define AGENTS_EID_PREFIX BASE_API_URI "/agents/eid/" |
| #define AGENTS_IDX_PREFIX BASE_API_URI "/agents/idx/" |
| #define AGENTS_URI BASE_API_URI "/agents$" |
| #define BASE_API_URI "/nm/api" |
| #define REQUEST_BODY_CHUNK 4096 |
Chunking size for receiving request bodies.
| #define VERSION_URI BASE_API_URI "/version$" |
|
static |
The .
/reports resource of either agent form.
References agent, agentShowHexReports(), agentShowTextReports(), getFormParam(), and HTTP_METHOD_NOT_ALLOWED.
Referenced by agentEidReportsHandler(), and agentIdxReportsHandler().
|
static |
The .
/send resource of either agent form.
References agent, agentParseHex(), agentParseText(), agentSendItems(), getFormParam(), HTTP_METHOD_NOT_ALLOWED, HTTP_UNSUP_MEDIA_TYPE, and requireContentType().
Referenced by agentEidSendHandler(), and agentIdxSendHandler().
|
static |
Handler /agents/eid/$eid/clear_reports - Clear all received reports for this agent.
References agent, AGENTS_EID_PREFIX, CACE_LOG_DEBUG, getAgentFromEid(), HTTP_METHOD_NOT_ALLOWED, HTTP_NO_CONTENT, mgr, and refdm_mgr_clear_reports().
Referenced by refdm_nm_rest_start().
|
static |
Handler /agents/eid/$eid/reports/hex - Retrieve array of reports in CBOR-encoded HEX form.
References agent, agentAnyReportsHandler(), AGENTS_EID_PREFIX, CACE_LOG_DEBUG, and getAgentFromEid().
Referenced by refdm_nm_rest_start().
|
static |
Handler /agents/eid/$eid/send - Send EXECSET encoded according to query key "form".
References agent, agentAnySendHandler(), AGENTS_EID_PREFIX, CACE_LOG_DEBUG, and getAgentFromEid().
Referenced by refdm_nm_rest_start().
|
static |
Handler /agents/idx/$idx/clear_reports - Clear all received reports for this agent.
References agent, AGENTS_IDX_PREFIX, CACE_LOG_DEBUG, getAgentFromIdx(), HTTP_METHOD_NOT_ALLOWED, HTTP_OK, mgr, and refdm_mgr_clear_reports().
Referenced by refdm_nm_rest_start().
|
static |
Handler /agents/idx/$idx/reports/hex - Retrieve array of reports in CBOR-encoded HEX form.
References agent, agentAnyReportsHandler(), AGENTS_IDX_PREFIX, CACE_LOG_DEBUG, and getAgentFromIdx().
Referenced by refdm_nm_rest_start().
|
static |
Handler /agents/idx/$idx/hex - Send HEX-encoded CBOR Command (hex string as request body).
References agent, agentAnySendHandler(), AGENTS_IDX_PREFIX, CACE_LOG_DEBUG, and getAgentFromIdx().
Referenced by refdm_nm_rest_start().
|
static |
References cace_ari_cbor_decode(), cace_ari_is_lit_typed(), CACE_ARI_TEXT_ENC_OPTS_DEFAULT, cace_ari_text_encode(), CACE_ARI_TYPE_EXECSET, cace_base16_decode(), cace_data_deinit(), cace_data_init(), CACE_FREE, CACE_LOG_DEBUG, cace_log_is_enabled_for(), errm, HTTP_BAD_REQUEST, and readRequstBody().
Referenced by agentAnySendHandler().
|
static |
References cace_ari_is_lit_typed(), cace_ari_text_decode(), CACE_ARI_TYPE_EXECSET, CACE_FREE, CACE_LOG_DEBUG, errm, HTTP_BAD_REQUEST, and readRequstBody().
Referenced by agentAnySendHandler().
|
static |
References agent, cace_amm_msg_if_metadata_deinit(), cace_amm_msg_if_metadata_init(), cace_ari_set_tstr(), CACE_LOG_ERR, CACE_LOG_INFO, cace_amm_msg_if_t::ctx, cace_amm_msg_if_metadata_t::dest, HTTP_INTERNAL_ERROR, HTTP_OK, mgr, refdm_mgr_t::mif, refdm_db_insert_execset(), and cace_amm_msg_if_t::send.
Referenced by agentAnySendHandler().
|
static |
References agent, refdm_mgr_t::agent_list, refdm_mgr_t::agent_mutex, CACE_LOG_CRIT, CACE_LOG_ERR, HTTP_INTERNAL_ERROR, HTTP_OK, mgr, refdm_db_fetch_agent_idx(), refdm_db_fetch_rptset_count(), RET_PASS, and SendJSON().
Referenced by agentsHandler().
|
static |
References agentsGetHandler(), agentsPostHandler(), and HTTP_METHOD_NOT_ALLOWED.
Referenced by refdm_nm_rest_start().
|
static |
References agent, cace_ari_cbor_encode(), cace_base16_encode(), cace_data_deinit(), cace_data_init(), CHKRET, HTTP_INTERNAL_ERROR, HTTP_NO_CONTENT, HTTP_OK, refdm_db_fetch_agent_idx(), and refdm_db_fetch_rptset_list().
Referenced by agentAnyReportsHandler().
|
static |
References agent, CACE_ARI_TEXT_ENC_OPTS_DEFAULT, cace_ari_text_encode(), CHKRET, HTTP_INTERNAL_ERROR, HTTP_NO_CONTENT, HTTP_OK, refdm_db_fetch_agent_idx(), and refdm_db_fetch_rptset_list().
Referenced by agentAnyReportsHandler().
|
static |
References agent, HTTP_BAD_REQUEST, HTTP_OK, HTTP_UNPROCESSABLE_CNT, HTTP_UNSUP_MEDIA_TYPE, mgr, readRequstBody(), refdm_mgr_agent_add(), and requireContentType().
Referenced by agentsHandler().
|
static |
References agent, getSegmentDecoded(), HTTP_NOT_FOUND, mgr, and refdm_mgr_agent_get_eid().
Referenced by agentEidClearReportsHandler(), agentEidReportsHandler(), and agentEidSendHandler().
|
static |
References agent, getSegmentDecoded(), HTTP_BAD_REQUEST, HTTP_NOT_FOUND, mgr, and refdm_mgr_agent_get_index().
Referenced by agentIdxClearReportsHandler(), agentIdxReportsHandler(), and agentIdxSendHandler().
|
static |
References CACE_LOG_DEBUG, and HTTP_BAD_REQUEST.
Referenced by agentAnyReportsHandler(), and agentAnySendHandler().
|
static |
References HTTP_BAD_REQUEST, HTTP_NOT_FOUND, and uri_seg_sep.
Referenced by getAgentFromEid(), and getAgentFromIdx().
|
static |
References CACE_LOG_INFO.
Referenced by refdm_nm_rest_start().
|
static |
References HTTP_BAD_REQUEST, and REQUEST_BODY_CHUNK.
Referenced by agentParseHex(), agentParseText(), and agentsPostHandler().
| int refdm_nm_rest_start | ( | struct mg_context ** | ctx, |
| refdm_mgr_t * | mgr | ||
| ) |
Begin operation of the REST service.
| [out] | ctx | The context to store into. |
References agentEidClearReportsHandler(), agentEidReportsHandler(), agentEidSendHandler(), agentIdxClearReportsHandler(), agentIdxReportsHandler(), agentIdxSendHandler(), AGENTS_EID_PREFIX, AGENTS_IDX_PREFIX, AGENTS_URI, agentsHandler(), CACE_LOG_ERR, CACE_LOG_INFO, CHKERR1, log_message(), mgr, VERSION_URI, and versionHandler().
Referenced by refdm_mgr_start().
| void refdm_nm_rest_stop | ( | struct mg_context * | ctx | ) |
Stop operation of the REST service.
| [in] | ctx | The context to stop for. |
References CHKVOID.
Referenced by refdm_mgr_stop().
|
static |
Referenced by agentAnySendHandler(), and agentsPostHandler().
|
static |
Referenced by agentsGetHandler(), and versionHandler().
|
static |
References HTTP_INTERNAL_ERROR, HTTP_METHOD_NOT_ALLOWED, HTTP_OK, and SendJSON().
Referenced by refdm_nm_rest_start().
|
static |
Characters disallowed in URI segments (per RFC 3986) to know where they end.
Referenced by getSegmentDecoded().