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];
139 bool recurse =
false);
143 bool make_tuple =
false);
153 int mode = WRITE_AS_BASE_DEFAULT);
209 if (*(p_url++) !=
'&')
210 return RET_MV_CONST_FAILED;
212 int url_len = strlen(p_url) - 1;
214 pChar p_end = p_url + url_len;
216 int ret = RET_MV_CONST_NOTHING;
219 if ((*(--p_end) !=
'e') || (*(--p_end) !=
'n') || (*(--p_end) !=
'.') || (*(--p_end) !=
';'))
220 return RET_MV_CONST_FAILED;
222 ret = RET_MV_CONST_NEW_ENTITY;
226 if (*p_end !=
';' && *p_end !=
']' && *p_end !=
')')
227 return RET_MV_CONST_FAILED;
232 if (p_base !=
nullptr) {
233 if (buff_size < 4 + SHORT_NAME_SIZE)
234 return RET_MV_CONST_FAILED;
241 for (
int i = 0; i < SHORT_NAME_SIZE; i++) {
242 char c = *(p_base++);
254 if (url_len >= buff_size)
255 return RET_MV_CONST_FAILED;
257 memcpy(p_buff, p_url, url_len);
283 if (q_state.
apply == APPLY_ASSIGN_CONST)
284 return block_from_const(p_txn, q_state.
url) ? SERVICE_NO_ERROR : SERVICE_ERROR_WRONG_ARGUMENTS;
288 if (p_container ==
nullptr)
289 return SERVICE_ERROR_WRONG_BASE;
291 switch (q_state.
apply) {
292 case APPLY_ASSIGN_NOTHING:
293 return p_container->get(p_txn, q_state.
r_value);
295 case APPLY_ASSIGN_NAME:
296 return p_container->get(p_txn, q_state.
r_value, q_state.
name);
298 case APPLY_ASSIGN_URL:
299 return p_container->get(p_txn, (
pChar) q_state.
url);
301 case APPLY_ASSIGN_FUNCTION:
304 if (p_aux_cont ==
nullptr)
305 return SERVICE_ERROR_WRONG_BASE;
307 if (p_aux_cont->get(p_aux, q_state.
rr_value) != SERVICE_NO_ERROR)
308 return SERVICE_ERROR_BLOCK_NOT_FOUND;
312 p_aux_cont->destroy_transaction(p_aux);
314 return SERVICE_ERROR_IO_ERROR;
316 Name ent = {
"result"};
318 p_aux_cont->destroy_transaction(p_aux);
320 return SERVICE_ERROR_IO_ERROR;
324 p_aux_cont->destroy_transaction(p_aux);
326 return SERVICE_ERROR_IO_ERROR;
329 p_aux_cont->destroy_transaction(p_aux);
331 return SERVICE_NO_ERROR;
333 case APPLY_ASSIGN_FUNCT_CONST:
335 return SERVICE_ERROR_WRONG_ARGUMENTS;
341 return SERVICE_ERROR_IO_ERROR;
343 Name ent = {
"result"};
347 return SERVICE_ERROR_IO_ERROR;
353 return SERVICE_ERROR_IO_ERROR;
358 return SERVICE_NO_ERROR;
360 case APPLY_ASSIGN_FILTER:
363 if (p_aux_cont ==
nullptr)
364 return SERVICE_ERROR_WRONG_BASE;
366 if (p_aux_cont->get(p_aux, q_state.
rr_value) != SERVICE_NO_ERROR)
367 return SERVICE_ERROR_BLOCK_NOT_FOUND;
369 if (p_container->get(p_txn, q_state.
r_value, p_aux->
p_block) != SERVICE_NO_ERROR) {
370 p_aux_cont->destroy_transaction(p_aux);
372 return SERVICE_ERROR_IO_ERROR;
374 p_aux_cont->destroy_transaction(p_aux);
376 return SERVICE_NO_ERROR;
378 case APPLY_ASSIGN_FILT_CONST:
380 return SERVICE_ERROR_WRONG_ARGUMENTS;
382 if (p_container->get(p_txn, q_state.
r_value, p_aux->
p_block) != SERVICE_NO_ERROR) {
385 return SERVICE_ERROR_IO_ERROR;
389 return SERVICE_NO_ERROR;
391 case APPLY_ASSIGN_RAW:
392 if (p_container->get(p_aux, q_state.
r_value) != SERVICE_NO_ERROR)
393 return SERVICE_ERROR_BLOCK_NOT_FOUND;
395 if (
new_block(p_txn, p_aux->
p_block, CELL_TYPE_UNDEFINED) != SERVICE_NO_ERROR) {
396 p_container->destroy_transaction(p_aux);
398 return SERVICE_ERROR_IO_ERROR;
400 p_container->destroy_transaction(p_aux);
402 return SERVICE_NO_ERROR;
404 case APPLY_ASSIGN_TEXT:
405 if (p_container->get(p_aux, q_state.
r_value) != SERVICE_NO_ERROR)
406 return SERVICE_ERROR_BLOCK_NOT_FOUND;
409 p_container->destroy_transaction(p_aux);
411 return SERVICE_ERROR_IO_ERROR;
413 p_container->destroy_transaction(p_aux);
415 return SERVICE_NO_ERROR;
417 return SERVICE_ERROR_MISC_SERVER;
433 char buffer_2k[SIZE_BUFFER_REMOTE_CALL];
435 switch (q_state.
apply) {
436 case APPLY_ASSIGN_NOTHING:
439 case APPLY_ASSIGN_NAME:
442 case APPLY_ASSIGN_URL:
443 sprintf(buffer_2k,
"//%s&%s;", q_state.
r_value.
base, q_state.
url);
445 case APPLY_ASSIGN_FUNCTION:
449 case APPLY_ASSIGN_FUNCT_CONST:
452 case APPLY_ASSIGN_FILTER:
456 case APPLY_ASSIGN_FILT_CONST:
459 case APPLY_ASSIGN_RAW:
462 case APPLY_ASSIGN_TEXT:
466 return SERVICE_ERROR_WRONG_ARGUMENTS;
489 if (p_container ==
nullptr)
490 return SERVICE_ERROR_WRONG_BASE;
492 switch (q_state.
apply) {
494 memcpy(&loc, &q_state.
base, SIZE_OF_BASE_ENT_KEY);
495 return p_container->get(p_txn, loc);
498 memcpy(&loc, &q_state.
base, SIZE_OF_BASE_ENT_KEY);
499 return p_container->get(p_txn, loc, q_state.
name);
502 return p_container->get(p_txn, (
pChar) q_state.
url);
507 if (p_aux_cont ==
nullptr)
508 return SERVICE_ERROR_WRONG_BASE;
510 if (p_aux_cont->get(p_aux, q_state.
r_value) != SERVICE_NO_ERROR)
511 return SERVICE_ERROR_BLOCK_NOT_FOUND;
513 memcpy(&loc, &q_state.
base, SIZE_OF_BASE_ENT_KEY);
514 if (q_state.
key[0] == 0) {
515 if (p_container->modify(loc, (
pTuple) p_aux->
p_block) != SERVICE_NO_ERROR) {
516 p_aux_cont->destroy_transaction(p_aux);
518 return SERVICE_ERROR_IO_ERROR;
520 Name ent = {
"result"};
522 p_aux_cont->destroy_transaction(p_aux);
524 return SERVICE_ERROR_IO_ERROR;
527 if (p_container->exec(p_txn, loc, (
pTuple) p_aux->
p_block) != SERVICE_NO_ERROR) {
528 p_aux_cont->destroy_transaction(p_aux);
530 return SERVICE_ERROR_IO_ERROR;
533 p_aux_cont->destroy_transaction(p_aux);
535 return SERVICE_NO_ERROR;
537 case APPLY_FUNCT_CONST:
539 return SERVICE_ERROR_WRONG_ARGUMENTS;
541 memcpy(&loc, &q_state.
base, SIZE_OF_BASE_ENT_KEY);
542 if (q_state.
key[0] == 0) {
543 if (p_container->modify(loc, (
pTuple) p_aux->
p_block) != SERVICE_NO_ERROR) {
546 return SERVICE_ERROR_IO_ERROR;
548 Name ent = {
"result"};
552 return SERVICE_ERROR_IO_ERROR;
555 if (p_container->exec(p_txn, loc, (
pTuple) p_aux->
p_block) != SERVICE_NO_ERROR) {
558 return SERVICE_ERROR_IO_ERROR;
563 return SERVICE_NO_ERROR;
568 if (p_aux_cont ==
nullptr)
569 return SERVICE_ERROR_WRONG_BASE;
571 if (p_aux_cont->get(p_aux, q_state.
r_value) != SERVICE_NO_ERROR)
572 return SERVICE_ERROR_BLOCK_NOT_FOUND;
574 memcpy(&loc, &q_state.
base, SIZE_OF_BASE_ENT_KEY);
575 if (p_container->get(p_txn, loc, p_aux->
p_block) != SERVICE_NO_ERROR) {
576 p_aux_cont->destroy_transaction(p_aux);
578 return SERVICE_ERROR_IO_ERROR;
580 p_aux_cont->destroy_transaction(p_aux);
582 return SERVICE_NO_ERROR;
584 case APPLY_FILT_CONST:
586 return SERVICE_ERROR_WRONG_ARGUMENTS;
588 memcpy(&loc, &q_state.
base, SIZE_OF_BASE_ENT_KEY);
589 if (p_container->get(p_txn, loc, p_aux->
p_block) != SERVICE_NO_ERROR) {
592 return SERVICE_ERROR_IO_ERROR;
596 return SERVICE_NO_ERROR;
599 memcpy(&loc, &q_state.
base, SIZE_OF_BASE_ENT_KEY);
600 if (p_container->get(p_aux, loc) != SERVICE_NO_ERROR)
601 return SERVICE_ERROR_BLOCK_NOT_FOUND;
603 if (
new_block(p_txn, p_aux->
p_block, CELL_TYPE_UNDEFINED) != SERVICE_NO_ERROR) {
604 p_container->destroy_transaction(p_aux);
606 return SERVICE_ERROR_IO_ERROR;
608 p_container->destroy_transaction(p_aux);
610 return SERVICE_NO_ERROR;
613 memcpy(&loc, &q_state.
base, SIZE_OF_BASE_ENT_KEY);
614 if (p_container->get(p_aux, loc) != SERVICE_NO_ERROR)
615 return SERVICE_ERROR_BLOCK_NOT_FOUND;
618 p_container->destroy_transaction(p_aux);
620 return SERVICE_ERROR_IO_ERROR;
622 p_container->destroy_transaction(p_aux);
624 return SERVICE_NO_ERROR;
626 return SERVICE_ERROR_MISC_SERVER;
643 if (p_container ==
nullptr)
644 return SERVICE_ERROR_WRONG_BASE;
648 memcpy(&where, &q_state.
base, SIZE_OF_BASE_ENT_KEY);
650 return p_container->put(where, p_block);
BaseAPI: The parent of API and Core.
Definition base_api.h:122
pPersisted get_persisted()
Definition base_api.h:178
StatusCode start()
Definition base_api.cpp:143
pChannels get_channels()
Definition base_api.h:162
StatusCode get_left_local(pTransaction &p_txn, ApiQueryState &q_state)
Definition base_api.h:481
StatusCode get_right_remote(pTransaction &p_txn, ApiQueryState &q_state)
Definition base_api.h:431
virtual pChar const id()
Definition base_api.cpp:133
pVolatile get_volatile()
Definition base_api.h:170
pPersisted p_persisted
The Persisted container.
Definition base_api.h:655
TenBitPtrLUT base_server
A LUT to convert TenBitsAtAddress(base) into a pContainer.
Definition base_api.h:184
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:639
pChannels p_channels
The Channels container.
Definition base_api.h:653
pVolatile p_volatile
The Volatile container.
Definition base_api.h:654
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:207
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:278
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:657
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:186
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:184
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