![]() |
Jazz 1.25.+
|
API: A Service to manage the REST API. More...
#include <api.h>
Public Member Functions | |
API (pLogger a_logger, pConfigFile a_config, pChannels a_channels, pVolatile a_volatile, pPersisted a_persisted, pCore a_core, pModelsAPI a_model) | |
virtual pChar const | id () |
StatusCode | start () |
StatusCode | shut_down () |
MHD_StatusCode | get_static (pMHD_Response &response, pChar p_url, bool get_it=true) |
MHD_Result | return_error_message (pMHD_Connection connection, pChar p_url, int http_status) |
MHD_StatusCode | http_put (pChar p_upload, size_t size, ApiQueryState &q_state, int sequence) |
MHD_StatusCode | http_delete (ApiQueryState &q_state) |
MHD_StatusCode | http_get (pMHD_Response &response, ApiQueryState &q_state) |
![]() | |
BaseAPI (pLogger a_logger, pConfigFile a_config, pChannels a_channels, pVolatile a_volatile, pPersisted a_persisted) | |
Creates a BaseAPI service without starting it. | |
StatusCode | start () |
StatusCode | shut_down () |
bool | parse (ApiQueryState &q_state, pChar p_url, int method, bool recurse=false) |
bool | block_from_const (pTransaction &p_txn, pChar p_const, bool make_tuple=false) |
virtual StatusCode | header (StaticBlockHeader &hea, ApiQueryState &what) |
virtual StatusCode | get (pTransaction &p_txn, ApiQueryState &what) |
virtual StatusCode | put (ApiQueryState &where, pBlock p_block, int mode=WRITE_AS_BASE_DEFAULT) |
virtual StatusCode | remove (ApiQueryState &what) |
pChannels | get_channels () |
pVolatile | get_volatile () |
pPersisted | get_persisted () |
![]() | |
Container (pLogger a_logger, pConfigFile a_config) | |
StatusCode | start () |
StatusCode | shut_down () |
void | enter_read (pTransaction p_txn) |
void | enter_write (pTransaction p_txn) |
void | leave_read (pTransaction p_txn) |
void | leave_write (pTransaction p_txn) |
StatusCode | new_block (pTransaction &p_txn, int cell_type, int *dim, int fill_tensor=FILL_NEW_DONT_FILL, int stringbuff_size=0, const char *p_text=nullptr, char eol='\n', AttributeMap *att=nullptr) |
StatusCode | new_block (pTransaction &p_txn, int num_items, StaticBlockHeader p_hea[], Name p_names[], pBlock p_block[], AttributeMap *dims=nullptr, AttributeMap *att=nullptr) |
StatusCode | new_block (pTransaction &p_txn, pBlock p_from, pBlock p_row_filter, AttributeMap *att=nullptr) |
StatusCode | new_block (pTransaction &p_txn, pTuple p_from, pChar name, AttributeMap *att=nullptr) |
StatusCode | new_block (pTransaction &p_txn, pBlock p_from_text, int cell_type, pKind p_as_kind=nullptr, AttributeMap *att=nullptr) |
StatusCode | new_block (pTransaction &p_txn, pBlock p_from_raw, pChar p_fmt=nullptr, bool ret_as_string=false, AttributeMap *att=nullptr) |
StatusCode | new_block (pTransaction &p_txn, int cell_type) |
StatusCode | new_block (pTransaction &p_txn, Index &index) |
virtual StatusCode | new_transaction (pTransaction &p_txn) |
virtual void | destroy_transaction (pTransaction &p_txn) |
virtual StatusCode | get (pTransaction &p_txn, pChar p_what) |
virtual StatusCode | get (pTransaction &p_txn, pChar p_what, pBlock p_row_filter) |
virtual StatusCode | get (pTransaction &p_txn, pChar p_what, pChar name) |
virtual StatusCode | locate (Locator &location, pChar p_what) |
virtual StatusCode | header (StaticBlockHeader &hea, pChar p_what) |
virtual StatusCode | header (pTransaction &p_txn, pChar p_what) |
virtual StatusCode | put (pChar p_where, pBlock p_block, int mode=WRITE_AS_BASE_DEFAULT) |
virtual StatusCode | new_entity (pChar p_where) |
virtual StatusCode | remove (pChar p_where) |
virtual StatusCode | copy (pChar p_where, pChar p_what) |
virtual StatusCode | exec (pTransaction &p_txn, Locator &function, pTuple p_args) |
virtual StatusCode | modify (Locator &function, pTuple p_args) |
virtual StatusCode | as_locator (Locator &result, pChar p_what) |
virtual StatusCode | get (pTransaction &p_txn, Locator &what) |
virtual StatusCode | get (pTransaction &p_txn, Locator &what, pBlock p_row_filter) |
virtual StatusCode | get (pTransaction &p_txn, Locator &what, pChar name) |
virtual StatusCode | locate (Locator &location, Locator &what) |
virtual StatusCode | header (StaticBlockHeader &hea, Locator &what) |
virtual StatusCode | header (pTransaction &p_txn, Locator &what) |
virtual StatusCode | put (Locator &where, pBlock p_block, int mode=WRITE_AS_BASE_DEFAULT) |
virtual StatusCode | new_entity (Locator &where) |
virtual StatusCode | remove (Locator &where) |
virtual StatusCode | copy (Locator &where, Locator &what) |
StatusCode | unwrap_received (pTransaction &p_txn) |
StatusCode | unwrap_received (pTransaction &p_txn, pBlock p_maybe_block, int rec_size) |
void | base_names (BaseNames &base_names) |
![]() | |
Service (pLogger a_logger, pConfigFile a_config) | |
void | log (int loglevel, const char *message) |
void | log_printf (int loglevel, const char *fmt,...) |
bool | get_conf_key (const char *key, int &value) |
bool | get_conf_key (const char *key, double &value) |
bool | get_conf_key (const char *key, std::string &value) |
Private Member Functions | |
bool | find_myself () |
StatusCode | load_statics (pChar p_base_path, pChar p_relative_path, int rec_level) |
bool | expand_url_encoded (pChar p_buff, int buff_size, pChar p_url) |
Private Attributes | |
pCore | p_core |
The Core. | |
pModelsAPI | p_model |
The ModelsAPI. | |
Index | www |
A map from url to locators to serve static files. | |
int | remove_statics |
A flag to remove the statics from persistence on shutdown configured by REMOVE_STATICS_ON_CLOSE. | |
Additional Inherited Members | |
![]() | |
TenBitPtrLUT | base_server |
A LUT to convert TenBitsAtAddress(base) into a pContainer. | |
![]() | |
pLogger | p_log |
The logger. | |
pConfigFile | p_conf |
The configuration file. | |
![]() | |
bool | parse_locator (Locator &loc, pChar p_url) |
int | move_const (pChar p_buff, int buff_size, pChar p_url, pChar p_base=nullptr) |
StatusCode | get_right_local (pTransaction &p_txn, ApiQueryState &q_state) |
StatusCode | get_right_remote (pTransaction &p_txn, ApiQueryState &q_state) |
StatusCode | get_left_local (pTransaction &p_txn, ApiQueryState &q_state) |
StatusCode | put_left_local (ApiQueryState &q_state, pBlock p_block) |
![]() | |
void * | malloc (size_t size) |
pBlock | block_malloc (size_t size) |
void | lock_container () |
void | unlock_container () |
StatusCode | destroy_container () |
int | from_hex (char c) |
![]() | |
pChannels | p_channels |
The Channels container. | |
pVolatile | p_volatile |
The Volatile container. | |
pPersisted | p_persisted |
The Persisted container. | |
![]() | |
int | max_transactions |
The configured ONE_SHOT_MAX_TRANSACTIONS. | |
uint64_t | warn_alloc_bytes |
Taken from ONE_SHOT_WARN_BLOCK_KBYTES. | |
uint64_t | fail_alloc_bytes |
Taken from ONE_SHOT_ERROR_BLOCK_KBYTES. | |
uint64_t | alloc_bytes |
The current allocation in bytes. | |
pTransaction | p_buffer |
The buffer for the transactions. | |
pTransaction | p_free |
The free list of transactions. | |
bool | alloc_warning_issued |
True if a warning was issued for over-allocation. | |
Lock32 | _lock_ |
A lock for the deque of transactions. | |
API: A Service to manage the REST API.
This service parses and executes http queries. It is aware and redistributes to all the appropriate services. It is called directly by the http callback http_request_callback().
jazz_main::API::API | ( | pLogger | a_logger, |
pConfigFile | a_config, | ||
pChannels | a_channels, | ||
pVolatile | a_volatile, | ||
pPersisted | a_persisted, | ||
pCore | a_core, | ||
pModelsAPI | a_model | ||
) |
Constructor for the API service.
a_logger | A pointer to the Logger object. |
a_config | A pointer to the ConfigFile object. |
a_channels | A pointer to the Channels object. |
a_volatile | A pointer to the Volatile object. |
a_persisted | A pointer to the Persisted object. |
a_core | A pointer to the Core object. |
a_model | A pointer to the ModelsAPI object. |
|
virtual |
Return object ID.
Reimplemented from jazz_bebop::BaseAPI.
|
virtual |
Starts the API service
Configuration-wise the API has just two keys:
Besides that, this function initializes global (and object) variables used by the parser (mostly CharLUT).
Reimplemented from jazz_elements::Service.
|
virtual |
Shuts down the Persisted Service
Configuration-wise the API has just one key:
Reimplemented from jazz_elements::Service.
MHD_StatusCode jazz_main::API::get_static | ( | pMHD_Response & | response, |
pChar | p_url, | ||
bool | get_it = true |
||
) |
Check a non-API url into and return the static object related with it.
response | A valid (or error) MHD_Response pointer with the resource, status, mime, etc. |
p_url | The http url (that has already been checked not to start with //) |
get_it | If true (default), it actually gets it as a response, otherwise it just check if it exists. |
MHD_Result jazz_main::API::return_error_message | ( | pMHD_Connection | connection, |
pChar | p_url, | ||
int | http_status | ||
) |
Finish a query by delivering the appropriate message page.
connection | The MHD connection passed to the callback function. (Needed for MHD_queue_response()ing the response.) |
p_url | The url that failed. |
http_status | The http status error (e.g., MHD_HTTP_NOT_FOUND) |
This function searches for a persistence block named ("www", "httpERR_%d") where d is the code in decimal and serves it as an answer.
MHD_StatusCode jazz_main::API::http_put | ( | pChar | p_upload, |
size_t | size, | ||
ApiQueryState & | q_state, | ||
int | sequence | ||
) |
Execute a put block using some one-shot block as an intermediate buffer.
p_upload | A pointer to the data uploaded with the http PUT call. |
size | The size of the data uploaded with the http PUT call. |
q_state | The structure containing the parts of the url successfully parsed. |
sequence | SEQUENCE_FIRST_CALL, SEQUENCE_INCREMENT_CALL or SEQUENCE_FINAL_CALL. (See below) |
This function is only called after a successful parse() of an HTTP_PUT query. It is not private because it is called for the callback, but it is not intended for any other context.
It supports any successful HTTP_PUT syntax, that is:
APPLY_NOTHING: With or without node, mandatory base, entity and key. APPLY_RAW & APPLY_TEXT: With or without node, mandatory base, entity and key. APPLY_URL: With or without node and just a base.
In all cases, calls with a node (it can only be l_node) q_state.url contains exactly what has to be forwarded.
SEQUENCE_FIRST_CALL comes first and is mandatory. On success, the functions keeps the data in a block stored in a pTransaction in q_state.rr_value.p_extra (that pointer will be returned in successive call of the same PUT query). SEQUENCE_INCREMENT_CALL may or may not come, if it does, it must allocate bigger blocks and store more data in the same pTransaction. SEQUENCE_FINAL_CALL is called just once, it must destroy the pTransaction when done
MHD_StatusCode jazz_main::API::http_delete | ( | ApiQueryState & | q_state | ) |
Execute an http DELETE of a block using the block API.
q_state | The structure containing the parts of the url successfully parsed. |
This function is only called after a successful parse() of an HTTP_DELETE query. It is not private because it is called for the callback, but it is not intended for any other context.
It supports any successful HTTP_PUT syntax, that is:
APPLY_NOTHING: With or without node, mandatory base and entity, with of without a key. APPLY_URL: With or without node and just a base.
In all cases, calls with a node (it can only be l_node) q_state.url contains exactly what has to be forwarded.
MHD_StatusCode jazz_main::API::http_get | ( | pMHD_Response & | response, |
ApiQueryState & | q_state | ||
) |
Execute a get block using the instrumental API.
response | A valid (or error) MHD_Response pointer with the resource. It will only be used on success. |
q_state | The structure containing the parts of the url successfully parsed. |
This function is only called after a successful parse() of HTTP_GET and HTTP_HEAD queries. It is not private because it is called for the callback, but it is not intended for any other context.
It supports, basically everything, which is, all apply in many versions:
APPLY_NOTHING, APPLY_NAME, APPLY_URL, APPLY_FUNCTION, APPLY_FUNCT_CONST, APPLY_FILTER, APPLY_FILT_CONST, APPLY_RAW, APPLY_TEXT, APPLY_ASSIGN_NOTHING, APPLY_ASSIGN_NAME, APPLY_ASSIGN_URL, APPLY_ASSIGN_FUNCTION, APPLY_ASSIGN_FUNCT_CONST, APPLY_ASSIGN_FILTER, APPLY_ASSIGN_FILT_CONST, APPLY_ASSIGN_RAW, APPLY_ASSIGN_TEXT, APPLY_ASSIGN_CONST, APPLY_NEW_ENTITY, APPLY_GET_ATTRIBUTE, APPLY_SET_ATTRIBUTE and APPLY_JAZZ_INFO
To simplify, this top level function decomposes the logic into smaller parts.
|
private |
Changes the current name until.
Try to find what is the IP, port of the current node in case no match by name with the configuration was found.
|
private |
Push a copy of all the files in the path (searched recursively) to the Persisted database "static" and index their names to be found by get_static().
It also assigns attributes:
p_base_path | The path to the tree of webpage statics. |
p_relative_path | The relative path that becomes the url with a file name added, starting with /. |
rec_level | The level of recursion (from 0 to MAX_RECURSE_LEVEL_ON_STATICS) |
Copy while percent-decoding a string into a buffer. Only RFC 3986 section 2.3 and RFC 3986 section 2.2 characters accepted.
p_buff | A buffer to store the result. |
buff_size | The size of the output buffer (ending zero included). |
p_url | The input string. |
See https://en.wikipedia.org/wiki/Percent-encoding This is utf-8 compatible, utf-8 chars are just percent encoded one byte at a time.