35#include "src/include/jazz_elements.h"
38#ifndef INCLUDED_JAZZ_CATCH2
39#define INCLUDED_JAZZ_CATCH2
41#include "src/catch2/catch.hpp"
47#ifndef INCLUDED_JAZZ_BEBOP_BASE_API
48#define INCLUDED_JAZZ_BEBOP_BASE_API
62#define SIZE_OF_BASE_ENT_KEY (sizeof(Locator) - sizeof(pExtraLocator))
64#define RESULT_BUFFER_SIZE 4096
65#define SIZE_BUFFER_REMOTE_CALL 2048
69#define BASE_API_DELETE 5
73#define PSTATE_INITIAL 0
74#define PSTATE_DONE_NODE 1
76#define PSTATE_IN_NODE 3
78#define PSTATE_IN_BASE 5
79#define PSTATE_ENTITY0 6
80#define PSTATE_IN_ENTITY 7
82#define PSTATE_IN_KEY 9
83#define PSTATE_INFO_SWITCH 10
84#define PSTATE_BASE_SWITCH 11
85#define PSTATE_ENT_SWITCH 12
86#define PSTATE_KEY_SWITCH 13
87#define PSTATE_FAILED 98
88#define PSTATE_COMPLETE_OK 99
92#define RET_MV_CONST_FAILED -1
93#define RET_MV_CONST_NOTHING 0
94#define RET_MV_CONST_NEW_ENTITY 1
109 char url [MAX_FILE_OR_URL_SIZE];
138 bool recurse =
false);
142 bool make_tuple =
false);
152 int mode = WRITE_AS_BASE_DEFAULT);
208 if (*(p_url++) !=
'&')
209 return RET_MV_CONST_FAILED;
211 int url_len = strlen(p_url) - 1;
213 pChar p_end = p_url + url_len;
215 int ret = RET_MV_CONST_NOTHING;
218 if ((*(--p_end) !=
'e') || (*(--p_end) !=
'n') || (*(--p_end) !=
'.') || (*(--p_end) !=
';'))
219 return RET_MV_CONST_FAILED;
221 ret = RET_MV_CONST_NEW_ENTITY;
225 if (*p_end !=
';' && *p_end !=
']' && *p_end !=
')')
226 return RET_MV_CONST_FAILED;
231 if (p_base !=
nullptr) {
232 if (buff_size < 4 + SHORT_NAME_SIZE)
233 return RET_MV_CONST_FAILED;
240 for (
int i = 0; i < SHORT_NAME_SIZE; i++) {
241 char c = *(p_base++);
253 if (url_len >= buff_size)
254 return RET_MV_CONST_FAILED;
256 memcpy(p_buff, p_url, url_len);
282 if (q_state.
apply == APPLY_ASSIGN_CONST)
283 return block_from_const(p_txn, q_state.
url) ? SERVICE_NO_ERROR : SERVICE_ERROR_WRONG_ARGUMENTS;
287 if (p_container ==
nullptr)
288 return SERVICE_ERROR_WRONG_BASE;
290 switch (q_state.
apply) {
291 case APPLY_ASSIGN_NOTHING:
292 return p_container->get(p_txn, q_state.
r_value);
294 case APPLY_ASSIGN_NAME:
295 return p_container->get(p_txn, q_state.
r_value, q_state.
name);
297 case APPLY_ASSIGN_URL:
298 return p_container->get(p_txn, (
pChar) q_state.
url);
300 case APPLY_ASSIGN_FUNCTION:
303 if (p_aux_cont ==
nullptr)
304 return SERVICE_ERROR_WRONG_BASE;
306 if (p_aux_cont->get(p_aux, q_state.
rr_value) != SERVICE_NO_ERROR)
307 return SERVICE_ERROR_BLOCK_NOT_FOUND;
311 p_aux_cont->destroy_transaction(p_aux);
313 return SERVICE_ERROR_IO_ERROR;
315 Name ent = {
"result"};
317 p_aux_cont->destroy_transaction(p_aux);
319 return SERVICE_ERROR_IO_ERROR;
323 p_aux_cont->destroy_transaction(p_aux);
325 return SERVICE_ERROR_IO_ERROR;
328 p_aux_cont->destroy_transaction(p_aux);
330 return SERVICE_NO_ERROR;
332 case APPLY_ASSIGN_FUNCT_CONST:
334 return SERVICE_ERROR_WRONG_ARGUMENTS;
340 return SERVICE_ERROR_IO_ERROR;
342 Name ent = {
"result"};
346 return SERVICE_ERROR_IO_ERROR;
352 return SERVICE_ERROR_IO_ERROR;
357 return SERVICE_NO_ERROR;
359 case APPLY_ASSIGN_FILTER:
362 if (p_aux_cont ==
nullptr)
363 return SERVICE_ERROR_WRONG_BASE;
365 if (p_aux_cont->get(p_aux, q_state.
rr_value) != SERVICE_NO_ERROR)
366 return SERVICE_ERROR_BLOCK_NOT_FOUND;
368 if (p_container->get(p_txn, q_state.
r_value, p_aux->
p_block) != SERVICE_NO_ERROR) {
369 p_aux_cont->destroy_transaction(p_aux);
371 return SERVICE_ERROR_IO_ERROR;
373 p_aux_cont->destroy_transaction(p_aux);
375 return SERVICE_NO_ERROR;
377 case APPLY_ASSIGN_FILT_CONST:
379 return SERVICE_ERROR_WRONG_ARGUMENTS;
381 if (p_container->get(p_txn, q_state.
r_value, p_aux->
p_block) != SERVICE_NO_ERROR) {
384 return SERVICE_ERROR_IO_ERROR;
388 return SERVICE_NO_ERROR;
390 case APPLY_ASSIGN_RAW:
391 if (p_container->get(p_aux, q_state.
r_value) != SERVICE_NO_ERROR)
392 return SERVICE_ERROR_BLOCK_NOT_FOUND;
394 if (
new_block(p_txn, p_aux->
p_block, CELL_TYPE_UNDEFINED) != SERVICE_NO_ERROR) {
395 p_container->destroy_transaction(p_aux);
397 return SERVICE_ERROR_IO_ERROR;
399 p_container->destroy_transaction(p_aux);
401 return SERVICE_NO_ERROR;
403 case APPLY_ASSIGN_TEXT:
404 if (p_container->get(p_aux, q_state.
r_value) != SERVICE_NO_ERROR)
405 return SERVICE_ERROR_BLOCK_NOT_FOUND;
408 p_container->destroy_transaction(p_aux);
410 return SERVICE_ERROR_IO_ERROR;
412 p_container->destroy_transaction(p_aux);
414 return SERVICE_NO_ERROR;
416 return SERVICE_ERROR_MISC_SERVER;
432 char buffer_2k[SIZE_BUFFER_REMOTE_CALL];
434 switch (q_state.
apply) {
435 case APPLY_ASSIGN_NOTHING:
438 case APPLY_ASSIGN_NAME:
441 case APPLY_ASSIGN_URL:
442 sprintf(buffer_2k,
"//%s&%s;", q_state.
r_value.
base, q_state.
url);
444 case APPLY_ASSIGN_FUNCTION:
448 case APPLY_ASSIGN_FUNCT_CONST:
451 case APPLY_ASSIGN_FILTER:
455 case APPLY_ASSIGN_FILT_CONST:
458 case APPLY_ASSIGN_RAW:
461 case APPLY_ASSIGN_TEXT:
465 return SERVICE_ERROR_WRONG_ARGUMENTS;
488 if (p_container ==
nullptr)
489 return SERVICE_ERROR_WRONG_BASE;
491 switch (q_state.
apply) {
493 memcpy(&loc, &q_state.
base, SIZE_OF_BASE_ENT_KEY);
494 return p_container->get(p_txn, loc);
497 memcpy(&loc, &q_state.
base, SIZE_OF_BASE_ENT_KEY);
498 return p_container->get(p_txn, loc, q_state.
name);
501 return p_container->get(p_txn, (
pChar) q_state.
url);
506 if (p_aux_cont ==
nullptr)
507 return SERVICE_ERROR_WRONG_BASE;
509 if (p_aux_cont->get(p_aux, q_state.
r_value) != SERVICE_NO_ERROR)
510 return SERVICE_ERROR_BLOCK_NOT_FOUND;
512 memcpy(&loc, &q_state.
base, SIZE_OF_BASE_ENT_KEY);
513 if (q_state.
key[0] == 0) {
514 if (p_container->modify(loc, (
pTuple) p_aux->
p_block) != SERVICE_NO_ERROR) {
515 p_aux_cont->destroy_transaction(p_aux);
517 return SERVICE_ERROR_IO_ERROR;
519 Name ent = {
"result"};
521 p_aux_cont->destroy_transaction(p_aux);
523 return SERVICE_ERROR_IO_ERROR;
526 if (p_container->exec(p_txn, loc, (
pTuple) p_aux->
p_block) != SERVICE_NO_ERROR) {
527 p_aux_cont->destroy_transaction(p_aux);
529 return SERVICE_ERROR_IO_ERROR;
532 p_aux_cont->destroy_transaction(p_aux);
534 return SERVICE_NO_ERROR;
536 case APPLY_FUNCT_CONST:
538 return SERVICE_ERROR_WRONG_ARGUMENTS;
540 memcpy(&loc, &q_state.
base, SIZE_OF_BASE_ENT_KEY);
541 if (q_state.
key[0] == 0) {
542 if (p_container->modify(loc, (
pTuple) p_aux->
p_block) != SERVICE_NO_ERROR) {
545 return SERVICE_ERROR_IO_ERROR;
547 Name ent = {
"result"};
551 return SERVICE_ERROR_IO_ERROR;
554 if (p_container->exec(p_txn, loc, (
pTuple) p_aux->
p_block) != SERVICE_NO_ERROR) {
557 return SERVICE_ERROR_IO_ERROR;
562 return SERVICE_NO_ERROR;
567 if (p_aux_cont ==
nullptr)
568 return SERVICE_ERROR_WRONG_BASE;
570 if (p_aux_cont->get(p_aux, q_state.
r_value) != SERVICE_NO_ERROR)
571 return SERVICE_ERROR_BLOCK_NOT_FOUND;
573 memcpy(&loc, &q_state.
base, SIZE_OF_BASE_ENT_KEY);
574 if (p_container->get(p_txn, loc, p_aux->
p_block) != SERVICE_NO_ERROR) {
575 p_aux_cont->destroy_transaction(p_aux);
577 return SERVICE_ERROR_IO_ERROR;
579 p_aux_cont->destroy_transaction(p_aux);
581 return SERVICE_NO_ERROR;
583 case APPLY_FILT_CONST:
585 return SERVICE_ERROR_WRONG_ARGUMENTS;
587 memcpy(&loc, &q_state.
base, SIZE_OF_BASE_ENT_KEY);
588 if (p_container->get(p_txn, loc, p_aux->
p_block) != SERVICE_NO_ERROR) {
591 return SERVICE_ERROR_IO_ERROR;
595 return SERVICE_NO_ERROR;
598 memcpy(&loc, &q_state.
base, SIZE_OF_BASE_ENT_KEY);
599 if (p_container->get(p_aux, loc) != SERVICE_NO_ERROR)
600 return SERVICE_ERROR_BLOCK_NOT_FOUND;
602 if (
new_block(p_txn, p_aux->
p_block, CELL_TYPE_UNDEFINED) != SERVICE_NO_ERROR) {
603 p_container->destroy_transaction(p_aux);
605 return SERVICE_ERROR_IO_ERROR;
607 p_container->destroy_transaction(p_aux);
609 return SERVICE_NO_ERROR;
612 memcpy(&loc, &q_state.
base, SIZE_OF_BASE_ENT_KEY);
613 if (p_container->get(p_aux, loc) != SERVICE_NO_ERROR)
614 return SERVICE_ERROR_BLOCK_NOT_FOUND;
617 p_container->destroy_transaction(p_aux);
619 return SERVICE_ERROR_IO_ERROR;
621 p_container->destroy_transaction(p_aux);
623 return SERVICE_NO_ERROR;
625 return SERVICE_ERROR_MISC_SERVER;
642 if (p_container ==
nullptr)
643 return SERVICE_ERROR_WRONG_BASE;
647 memcpy(&where, &q_state.
base, SIZE_OF_BASE_ENT_KEY);
649 return p_container->put(where, p_block);
BaseAPI: The parent of API and Core.
Definition base_api.h:121
pPersisted get_persisted()
Definition base_api.h:177
StatusCode start()
Definition base_api.cpp:143
pChannels get_channels()
Definition base_api.h:161
StatusCode get_left_local(pTransaction &p_txn, ApiQueryState &q_state)
Definition base_api.h:480
StatusCode get_right_remote(pTransaction &p_txn, ApiQueryState &q_state)
Definition base_api.h:430
virtual pChar const id()
Definition base_api.cpp:133
pVolatile get_volatile()
Definition base_api.h:169
pPersisted p_persisted
The Persisted container.
Definition base_api.h:654
TenBitPtrLUT base_server
A LUT to convert TenBitsAtAddress(base) into a pContainer.
Definition base_api.h:183
virtual StatusCode get(pTransaction &p_txn, ApiQueryState &what)
Definition base_api.cpp:697
bool block_from_const(pTransaction &p_txn, pChar p_const, bool make_tuple=false)
Definition base_api.cpp:950
StatusCode put_left_local(ApiQueryState &q_state, pBlock p_block)
Definition base_api.h:638
pChannels p_channels
The Channels container.
Definition base_api.h:652
pVolatile p_volatile
The Volatile container.
Definition base_api.h:653
virtual StatusCode header(StaticBlockHeader &hea, ApiQueryState &what)
Definition base_api.cpp:637
virtual StatusCode put(ApiQueryState &where, pBlock p_block, int mode=WRITE_AS_BASE_DEFAULT)
Definition base_api.cpp:840
int move_const(pChar p_buff, int buff_size, pChar p_url, pChar p_base=nullptr)
Definition base_api.h:206
bool parse(ApiQueryState &q_state, pChar p_url, int method, bool recurse=false)
Definition base_api.cpp:202
bool parse_locator(Locator &loc, pChar p_url)
Definition base_api.cpp:553
virtual StatusCode remove(ApiQueryState &what)
Definition base_api.cpp:913
StatusCode get_right_local(pTransaction &p_txn, ApiQueryState &q_state)
Definition base_api.h:277
StatusCode shut_down()
Definition base_api.cpp:177
Channels: A Container doing block transactions across media (files, folders, shell,...
Definition channel.h:227
MHD_StatusCode forward_get(pTransaction &p_txn, Name node, pChar p_url)
Definition channel.cpp:1063
A configuration file as a key/value store.
Definition utils.h:217
Container: A Service to manage Jazz blocks. All Jazz blocks are managed by this or a descendant of th...
Definition container.h:282
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)
Definition container.cpp:573
virtual void destroy_transaction(pTransaction &p_txn)
Definition container.cpp:493
A simple logger.
Definition utils.h:245
Persisted: A Service to manage data objects in LMDB.
Definition persisted.h:93
Tuple: A Jazz Block with multiple Tensors.
Definition tuple.h:94
Volatile: A Service to manage data objects in RAM.
Definition volatile.h:244
A language to access any container by base using locators.
Definition base_api.cpp:39
BaseAPI * pBaseAPI
A pointer to a BaseAPI.
Definition base_api.h:656
The namespace for Jazz Utils, Blocks, Kinds, Tuples, Containers, etc.
Definition block.cpp:39
int TenBitsAtAddress(const char *str)
Get ten bits taking the least significant 5 of the first two characters of a string.
Definition utils.h:166
char * pChar
A pointer to a char buffer.
Definition types.h:185
class Block * pBlock
A (forward defined) pointer to a Block.
Definition block.h:66
char Name[NAME_SIZE]
A short identifier used in Blocks, Containers and API.
Definition types.h:183
void * TenBitPtrLUT[TENBITS_LUT_SIZE]
A lookup table for all the possible results of a TenBitsAtAddress() call -> pointer.
Definition utils.h:156
class Container * pContainer
A (forward defined) pointer to a Container.
Definition container.h:148
int StatusCode
Type returned by the Service API.
Definition utils.h:141
A buffer to keep the state while parsing/executing a query.
Definition base_api.h:99
Locator rr_value
Parsed //r_base/r_entity/r_key(//rr_base/rr_entity/rr_key)
Definition base_api.h:112
char l_node[NAME_SIZE]
An optional name of a Jazz node that is either the only one or the left of assignment.
Definition base_api.h:103
char key[NAME_SIZE]
A Locator compatible key for the l_value.
Definition base_api.h:107
char url[MAX_FILE_OR_URL_SIZE]
The endpoint (an URL, file name, folder name, bash script)
Definition base_api.h:109
char name[NAME_SIZE]
A possible item name.
Definition base_api.h:108
char entity[NAME_SIZE]
A Locator compatible entity for the l_value.
Definition base_api.h:106
char r_node[NAME_SIZE]
An additional optional name of a Jazz node for the right part in an assignment.
Definition base_api.h:104
int apply
APPLY_NOTHING, APPLY_NAME, APPLY_URL, APPLY_FUNCTION, .. APPLY_ASSIGN_CONST.
Definition base_api.h:101
int state
The parser state from PSTATE_INITIAL to PSTATE_COMPLETE_OK.
Definition base_api.h:100
Locator r_value
Parsed //r_base/r_entity/r_key.
Definition base_api.h:111
char base[SHORT_NAME_SIZE]
A Locator compatible base for the l_value.
Definition base_api.h:105
Locator: A minimal structure to define the location of resources inside a Container.
Definition container.h:184
char base[SHORT_NAME_SIZE]
A Jazz node level unique name to locate a Container and possibly a type of service inside it.
Definition container.h:185
Name entity
Another abstraction inside node.container.base, like the name of a table in a database.
Definition container.h:186
Name key
A key identifying a block inside the entity.
Definition container.h:187
Transaction: A wrapper over a Block that defines the communication of a block with a Container.
Definition container.h:162
pBlock p_block
A pointer to the Block (if status == BLOCK_STATUS_READY) for Tensor, Kind and Tuple.
Definition container.h:164