Loading...
Searching...
No Matches
aguard.c File Reference

aguard.c - 25 Aug 2024 - aotto1968 More...

#include "common.h"
#include "aguard_crypt.h"
+ Include dependency graph for aguard.c:

Go to the source code of this file.

Data Structures

struct  AGuardCtxS
 

Macros

#define META_FILE_NAME   "AGuard.c"
 
#define META_CONTEXT_S   mqctx
 
#define ENCRYPT   true
 
#define DECRYPT   false
 
#define AGuardT   ((typeof(MqContextC_T)) AGuardTT)
 
#define check_MqError(E)
 
#define myctx   ((struct AGuardCtxS*)META_CONTEXT_S)
 
#define MqReadDump_E(mqctx, dumpP)
 
#define GuardReturn(PROC)
 

Functions

static enum MkErrorE sProxySubCall (MK_RT mkrt, MQ_CTX const targetCtx, MK_PTR const data)
 
static enum MkErrorE MqReadDump (MK_RT mkrt, MQ_CTX const mqctx, struct MqDumpS **dumpP)
 
static enum MkErrorE PkgToGrx2 (MK_RT mkrt, MQ_CTX const mqctx, MQ_TOK const token, MQ_CTX const otherCtx, MQ_LTR otherLId)
 
static enum MkErrorE PkgToGrp (MQ_SERVICE_CALL_ARGS)
 
static enum MkErrorE TrtToGrt (MQ_SERVICE_CALL_ARGS)
 
static enum MkErrorE GrxToPkgError (MK_RT mkrt, MQ_CTX const mqctx)
 
static enum MkErrorE GrxToPkg2 (MK_RT mkrt, MQ_CTX const mqctx, MQ_TOK const intoken, MQ_CTX const otherCtx, MQ_LTR otherLId)
 
static enum MkErrorE GrpToPkg (MQ_SERVICE_CALL_ARGS)
 
static enum MkErrorE GrtToTrt (MQ_SERVICE_CALL_ARGS)
 
static enum MkErrorE FilterCleanup (MQ_SERVICE_CALL_ARGS)
 
static enum MkErrorE FilterSetup (MQ_SERVICE_CALL_ARGS)
 
static enum MkErrorE FilterFactory (MQ_CALLBACK_FACTORY_CTOR_ARGS)
 
int main (const int argc, MK_STRN argv[])
 

Variables

static MK_TYP AGuardTT = NULL
 

Detailed Description

aguard.c - 25 Aug 2024 - aotto1968

Version
c3b28928437a81158df1f3cafe23fbded7b34813
Date
Sun Aug 25 22:59:57 2024 +0200
Author
aotto1968 aotto.nosp@m.1968.nosp@m.@t-on.nosp@m.line.nosp@m..de

Definition in file aguard.c.

Macro Definition Documentation

◆ AGuardT

#define AGuardT   ((typeof(MqContextC_T)) AGuardTT)

Definition at line 35 of file aguard.c.

◆ check_MqError

#define check_MqError ( E)
Value:
if (MkErrorCheckI(E))

Definition at line 46 of file aguard.c.

◆ DECRYPT

#define DECRYPT   false

Definition at line 23 of file aguard.c.

◆ ENCRYPT

#define ENCRYPT   true

Definition at line 22 of file aguard.c.

◆ GuardReturn

#define GuardReturn ( PROC)
Value:
switch (PROC) {\
case MK_OK: return MK_OK; \
case MK_CONTINUE: goto done; \
default: return MkErrorStack_1X (META_CONTEXT_S); \
}
#define META_CONTEXT_S
Definition aguard.c:20
#define MkErrorStack_1X(...)
MK_CONTINUE
MK_OK

Definition at line 319 of file aguard.c.

319#define GuardReturn(PROC) \
320switch (PROC) {\
321 case MK_OK: return MK_OK; \
322 case MK_CONTINUE: goto done; \
323 default: return MkErrorStack_1X (META_CONTEXT_S); \
324}

◆ META_CONTEXT_S

#define META_CONTEXT_S   mqctx

Definition at line 20 of file aguard.c.

◆ META_FILE_NAME

#define META_FILE_NAME   "AGuard.c"

Definition at line 14 of file aguard.c.

◆ MqReadDump_E

#define MqReadDump_E ( mqctx,
dumpP )
Value:
if (MkErrorCheckI(MqReadDump( MK_RT_CALL mqctx,dumpP))) goto error
static enum MkErrorE MqReadDump(MK_RT mkrt, MQ_CTX const mqctx, struct MqDumpS **dumpP)
Definition aguard.c:71
#define MK_RT_CALL

Definition at line 81 of file aguard.c.

◆ myctx

#define myctx   ((struct AGuardCtxS*)META_CONTEXT_S)

Definition at line 53 of file aguard.c.

Function Documentation

◆ FilterCleanup()

static enum MkErrorE FilterCleanup ( MQ_SERVICE_CALL_ARGS )
static

Definition at line 563 of file aguard.c.

564{
565 MqDumpDelete(myctx->dump);
566 return MK_OK;
567}
#define myctx
Definition aguard.c:53
#define MqDumpDelete(x)
+ Here is the caller graph for this function:

◆ FilterFactory()

static enum MkErrorE FilterFactory ( MQ_CALLBACK_FACTORY_CTOR_ARGS )
static

Definition at line 646 of file aguard.c.

647{
648 MQ_CTX const mqctx = *contextP = MqContextCreate(AGuardTT,tmpl);
649
650 mqctx->setup.isServer = true;
653#if defined(USE_BG_ERROR)
654 mqctx->setup.BgError.fCall = FilterError;
655#endif
656
657 return MK_OK;
658}
static enum MkErrorE FilterSetup(MQ_SERVICE_CALL_ARGS)
Definition aguard.c:570
static enum MkErrorE FilterCleanup(MQ_SERVICE_CALL_ARGS)
Definition aguard.c:563
static MK_TYP AGuardTT
Definition aguard.c:34
#define MqContextCreate(...)
MqTokenF fCall
struct MqSetupS setup
struct MqCallbackS ServerCleanup
struct MqCallbackS BgError
struct MqCallbackS ServerSetup
bool isServer
+ Here is the caller graph for this function:

◆ FilterSetup()

static enum MkErrorE FilterSetup ( MQ_SERVICE_CALL_ARGS )
static

Definition at line 570 of file aguard.c.

571{
572 MQ_CTX ftrctx = MqSlaveGetFilter_e (mqctx);
573
574 myctx->dump = NULL;
575
576 // SERVER: every token (+ALL) have to be "guard_encrypted"
577 MkErrorCheck (MqServiceCreate (mqctx, "+ALL", PkgToGrp, NULL, NULL, NULL));
578 // SERVER: but "+TRT" is special
579 MkErrorCheck (MqServiceCreate (mqctx, "+TRT", TrtToGrt, NULL, NULL, NULL));
580 // SERVER: only the "+GR?" token is "guard_decrypted"
581 MkErrorCheck (MqServiceCreate (mqctx, "+GRP", GrpToPkg, NULL, NULL, NULL));
582 MkErrorCheck (MqServiceCreate (mqctx, "+GRT", GrtToTrt, NULL, NULL, NULL));
583
584 // CLIENT: every token (+ALL) have to be "guard_encrypted"
585 MkErrorCheck (MqServiceCreate (ftrctx, "+ALL", PkgToGrp, NULL, NULL, NULL));
586 // CLIENT: but "+TRT" is special
587 MkErrorCheck (MqServiceCreate (ftrctx, "+TRT", TrtToGrt, NULL, NULL, NULL));
588 // CLIENT: only the "+GR?" token is "guard_decrypted"
589 MkErrorCheck (MqServiceCreate (ftrctx, "+GRP", GrpToPkg, NULL, NULL, NULL));
590 MkErrorCheck (MqServiceCreate (ftrctx, "+GRT", GrtToTrt, NULL, NULL, NULL));
591
592 return MK_OK;
593error:
594 return MkErrorStack_1X(mqctx);
595}
static enum MkErrorE PkgToGrp(MQ_SERVICE_CALL_ARGS)
Definition aguard.c:235
static enum MkErrorE GrpToPkg(MQ_SERVICE_CALL_ARGS)
Definition aguard.c:479
static enum MkErrorE TrtToGrt(MQ_SERVICE_CALL_ARGS)
Definition aguard.c:254
static enum MkErrorE GrtToTrt(MQ_SERVICE_CALL_ARGS)
Definition aguard.c:495
#define MqServiceCreate(...)
#define MqSlaveGetFilter_e(...)
+ Here is the caller graph for this function:

◆ GrpToPkg()

static enum MkErrorE GrpToPkg ( MQ_SERVICE_CALL_ARGS )
static

Definition at line 479 of file aguard.c.

480{
481 MQ_CTX otherCtx;
482
483 MkErrorCheck (MqSlaveGetProxy (mqctx, MQ_SLAVE_OTHER, &otherCtx));
484 MkErrorCheck (GrxToPkg2 ( MK_RT_CALL mqctx, "+GRP", otherCtx, mqctx->link.protect.transLId));
485
486done:
487 return MqSendRETURN(mqctx);
488error:
489 MkErrorStack_1X(mqctx);
491}
static enum MkErrorE GrxToPkgError(MK_RT mkrt, MQ_CTX const mqctx)
Definition aguard.c:293
#define GuardReturn(PROC)
Definition aguard.c:319
static enum MkErrorE GrxToPkg2(MK_RT mkrt, MQ_CTX const mqctx, MQ_TOK const intoken, MQ_CTX const otherCtx, MQ_LTR otherLId)
Definition aguard.c:327
#define MqSendRETURN(...)
#define MqSlaveGetProxy(...)
MQ_SLAVE_OTHER
+ Here is the caller graph for this function:

◆ GrtToTrt()

static enum MkErrorE GrtToTrt ( MQ_SERVICE_CALL_ARGS )
static

Definition at line 495 of file aguard.c.

496{
497 MQ_LTR rmtTransLIdOrig = mqctx->link.protect.rmtTransLId;
498
499 MkDLogV(mqctx,6,"work on 'transLId=" MK_FORMAT_T "'\n", rmtTransLIdOrig);
500
501 if (rmtTransLIdOrig < 0) {
502
503 MkErrorSetC_1XS ("internal-error: unable to GUARD a SEND-LTT");
504 goto error;
505
506 } else if (rmtTransLIdOrig > 0) {
507
508 MQ_CTX otherCtx;
509 MQ_LTR otherLId;
510
511 // step 1. -> get the "original" transaction of "mqctx->link.protect.rmtTransLId" from DB
512 MkErrorCheck (MqStorageResolve (mqctx, &otherCtx, &otherLId));
513
514 // step 2. -> "MqSendSTART" use "link.protect.rmtTransLId" to add the LTT to the data-package
515 mqctx->link.protect.rmtTransLId = otherLId;
516
517 // step 3. -> send data
518 MkErrorCheck (GrxToPkg2 ( MK_RT_CALL mqctx, "+GRT", otherCtx, mqctx->link.protect.rmtTransLId));
519
520 } else {
521 MkErrorSetC_1XS ("internal-error: transLId = 0");
522 goto error;
523 }
524
525done:
526 MqStorageDelete (mqctx, &mqctx->link.protect.transLId);
527 return MqSendRETURN(mqctx);
528error:
529 MqStorageDelete (mqctx, &mqctx->link.protect.transLId);
530 MkErrorStack_1X (mqctx);
532}
#define MkErrorSetC_1XS(message)
#define MkDLogV(x, _debug, printfmt,...)
#define MqStorageResolve(...)
#define MqStorageDelete(...)
int MQ_LTR
+ Here is the caller graph for this function:

◆ GrxToPkg2()

static enum MkErrorE GrxToPkg2 ( MK_RT mkrt,
MQ_CTX const mqctx,
MQ_TOK const intoken,
MQ_CTX const otherCtx,
MQ_LTR otherLId )
static

Definition at line 327 of file aguard.c.

332 {
333 enum MqHandShakeE hs = mqctx->link.protect.handShake;
334 enum MqTransTypeE tt = mqctx->link.protect.transType;
335 struct MqDumpS *dump = NULL;
336 enum MkErrorE ret = MK_OK;
337 MK_STRB token[5] = "";
338 MkBinaryR bdat = {0};
339
340/*
341->GONE by split PRIVATE and PUBLIC
342 if (otherCtx->link.send == NULL) {
343 return MkErrorSetV_1XS("the '%s' object link is '%s' connected", "msgque", "not");
344 } else
345*/
346 if (strncmp (intoken, MqServiceTokenGet(mqctx), 5) != 0) {
347 return MkErrorSetV_1XS("expect token '%s' but got token '%s", intoken, MqServiceTokenGet(mqctx));
348 }
349
350 MqReadBIN_E (mqctx, &bdat);
351 guard_crypt (bdat.data, bdat.size, DECRYPT);
352 MqSendSTART_E (otherCtx);
353
354 if (tt == MQ_TRANS_TYPE_TRANS) {
355 // in a "longterm-transaction" with "MqProxyForward" and "MqSendRETURN"…
356 // we DONT want any additional message from "MqSendRETURN" send to the "client".
357 // with "link.protect.bits.LIdLck = true" the shortterm-transaction will be deleted in
358 // "MqSendRETURN->sSendEND" → same as in "MqStorageInsert" or "MqDumpExport"
359 //
360 // client.exe
361 // Send("T"…) ->
362 // Filter.exe
363 // Send("R"…) <- ANSWER database INSERT
364 // EventProc
365 // MqProxyForward // forward to "targetctx"
366 // …
367 // MqSendRETURN // THIS is the problem, we DON'T want ANY package from there send to client.exe
368 //
369 mqctx->link.protect.bits.LIdLck = true;
370 }
371
372 // the "Dump" is from an other "filter"… the environment is WRONG
373 dump = (struct MqDumpS*) bdat.data;
374
375 MqDumpTransLIdSet (dump, mqctx->link.protect.transLId);
376 MqDumpRmtTransLIdSet (dump, mqctx->link.protect.rmtTransLId);
377 strncpy (token, MqDumpTokenGet(dump), 4);
378 token[4] = '\0';
379
380 // this code write the "transLId" also
381 MqProxyPackage_E (mqctx, otherCtx, dump);
382
383 if (hs == MQ_HANDSHAKE_START) {
384
385 // basically… MqSendEND_AND_WAIT can fail if an ASYNCRONE error arrive… even if
386 // LTT was successfull send… if "refCount" will be incr AFTER send… an final "+TRT" will NOT find
387 // the according transaction… and will create an ERROR
388 if (tt == MQ_TRANS_TYPE_TRANS) {
389 MkErrorCheck(MqStorageIncrRef(mqctx,otherLId));
390 }
391
392 if (mqctx->link.protect.transSId > 0) { // shortterm-transaction
393
394 // direction: mqctx -> otherCtx
395 switch (tt) {
396 case MQ_TRANS_TYPE_CB:
398 ret = MqSendEND_AND_WAIT (otherCtx, token, MK_TIMEOUT_DEFAULT);
399 break;
401 // protecting of "mqctx" using "refCount" is dangerous… every error break refCount
402 ret = MqSendEND_AND_SUB (otherCtx, token, sProxySubCall, mqctx, NULL, MK_TIMEOUT_DEFAULT);
403 break;
405 ret = MqSendEND_AND_TRANSACTION (otherCtx, token, NULL, MK_TIMEOUT_DEFAULT);
406 break;
407 default:
408 ret = MkErrorSetV_1XS("protocol-error -> invalid transaction-type: %s", MqTransTypeE_ToString(tt));
409 break;
410 }
411 MkErrorCheck (ret);
412
413 // start the answer
414 MqSendSTART_E (mqctx);
415
416 // Forward the "answer" of a STT… but only if "other-context" expect an answer
417 if (tt != MQ_TRANS_TYPE_TRANS) {
418 // answer
419 MqDumpExport_E (otherCtx, &myctx->dump);
420 MkBinaryR bin = MqDumpBinGet(myctx->dump);
421
422 // encrypt
423 guard_crypt (bin.data, bin.size, ENCRYPT);
424 // prepare binary package
425 MqSendBIN_E (mqctx, bin);
426 }
427
428 } else { // transSId == 0
429 // direction: mqctx -> otherCtx
430 switch (tt) {
431 case MQ_TRANS_TYPE_NO:
432 ret = MqSendEND (otherCtx, token, MK_TIMEOUT_DEFAULT);
433 break;
435 ret = MqSendEND_AND_TRANSACTION (otherCtx, token, NULL, 0);
436 break;
437 default:
438 ret = MkErrorSetV_1XS("protocol-error -> invalid transaction-type: %s", MqTransTypeE_ToString(tt));
439 break;
440 }
441 MkErrorCheck (ret);
442 }
443
444 // direction: client <- server = answer from the service → handShake "O" or "E"
445 } else {
446 if (mqctx->link.protect.transSId > 0) { // shortterm-transaction, this is only valid for "+TRT"
447 switch (tt) {
449 ret = MqSendEND_AND_TRANSACTION (otherCtx, token, NULL, MK_TIMEOUT_DEFAULT);
450 break;
451 default:
452 ret = MkErrorSetV_1XS("protocol-error -> invalid transaction-type: %s", MqTransTypeE_ToString(tt));
453 break;
454 }
455 } else { // everything NOT "+TRT"
456 switch (tt) {
457 case MQ_TRANS_TYPE_NO:
458 ret = MqSendEND (otherCtx, token, MK_TIMEOUT_DEFAULT);
459 break;
461 ret = MqSendEND_AND_TRANSACTION (otherCtx, token, NULL, 0);
462 break;
463 default:
464 ret = MkErrorSetV_1XS("protocol-error -> invalid transaction-type: %s", MqTransTypeE_ToString(tt));
465 break;
466 }
467 }
468 MkErrorCheck (ret);
469 }
470
471 return MK_OK;
472
473error:
474 MqContextErrorCopy(mqctx, otherCtx);
475 return MkErrorStack_1X(mqctx);
476}
#define ENCRYPT
Definition aguard.c:22
#define DECRYPT
Definition aguard.c:23
static enum MkErrorE sProxySubCall(MK_RT mkrt, MQ_CTX const targetCtx, MK_PTR const data)
Definition aguard.c:56
static void guard_crypt(register MK_BINN data, MK_SIZE size, bool const flag)
#define MkErrorSetV_1XS(printfmt,...)
MkErrorE
MK_TIMEOUT_DEFAULT
char MK_STRB
#define MqContextErrorCopy(...)
#define MqProxyPackage_E(...)
#define MqReadBIN_E(...)
#define MqSendBIN_E(...)
#define MqSendEND_AND_TRANSACTION(...)
#define MqSendSTART_E(...)
#define MqSendEND_AND_SUB(...)
#define MqSendEND_AND_WAIT(...)
#define MqSendEND(...)
MQ_EXTERN MQ_TOK MqServiceTokenGet(MQ_CTX const ctx)
#define MqStorageIncrRef(...)
MQ_EXTERN void MqDumpRmtTransLIdSet(MQ_DMP const dump, MQ_LTR rmtTransLId)
MQ_EXTERN void MqDumpTransLIdSet(MQ_DMP const dump, MQ_LTR transLId)
MQ_EXTERN MK_STRN MqDumpTokenGet(MQ_DMPN const dump)
#define MqDumpExport_E(...)
MQ_EXTERN MkBinaryR MqDumpBinGet(MQ_DMPN const dump)
MQ_EXTERN MK_STRN MqTransTypeE_ToString(enum MqTransTypeE value)
MqHandShakeE
MqTransTypeE
MQ_HANDSHAKE_START
MQ_TRANS_TYPE_WAIT
MQ_TRANS_TYPE_SUB
MQ_TRANS_TYPE_CB
MQ_TRANS_TYPE_NO
MQ_TRANS_TYPE_TRANS
MK_SIZE size
MK_BINN data
+ Here is the caller graph for this function:

◆ GrxToPkgError()

static enum MkErrorE GrxToPkgError ( MK_RT mkrt,
MQ_CTX const mqctx )
static

Definition at line 293 of file aguard.c.

295 {
296 if (MkErrorIsEXIT_0E()) {
297 return MkErrorGetCode_0E();
298 } else {
299
300 // goal → make a "guard" error package
301 check_MqError (MqDumpError (mqctx, &myctx->dump)) goto error_in_error;
302
303 MkBinaryR bin = MqDumpBinGet (myctx->dump);
304
305 // encrypt
306 guard_crypt (bin.data, bin.size, ENCRYPT);
307
308 // prepare binary package
309 check_MqError (MqSendSTART (mqctx)) goto error_in_error;
310 check_MqError (MqSendBIN (mqctx, bin)) goto error_in_error;
311 return MK_CONTINUE;
312 }
313
314error_in_error:
315 MkErrorPrintln_1M (mqctx);
316 return MK_OK;
317}
#define check_MqError(E)
Definition aguard.c:46
#define MkErrorGetCode_0E()
#define MkErrorPrintln_1M(m)
#define MkErrorIsEXIT_0E()
#define MqSendBIN(...)
#define MqSendSTART(...)
#define MqDumpError(...)
+ Here is the caller graph for this function:

◆ main()

int main ( const int argc,
MK_STRN argv[] )

Definition at line 668 of file aguard.c.

669{
671
672 // define the new type
674 AGuardTT->objsize = sizeof(struct AGuardCtxS);
675 AGuardT->fHelp = FilterHelp;
676
677 // parse the command-line
678 MK_BFL args = MkBufferListCreateVC (argc, argv);
679 MQ_CTX mqctx = NULL;
680
681 // call Factory
682 MQ_FCT fct = MqFactoryAdd(MK_ERROR_PANIC, FilterFactory, NULL, NULL, NULL, NULL, NULL, NULL, NULL, IDENT);
683 MqFactoryNew_E (fct, NULL, &mqctx);
684
685 // filter args
686 MkContinueCheck(FilterArgs(MK_RT_CALL mqctx,args));
687
688 // create the Link
689 MqLinkCreate_E (mqctx, args);
690
691 // start event-loop and wait forever
693
694 // finish and exit
695cont:
696error:
697 MkBufferListDelete(args);
698 MqExit_1 (mqctx);
699}
static enum MkErrorE FilterFactory(MQ_CALLBACK_FACTORY_CTOR_ARGS)
Definition aguard.c:646
#define AGuardT
Definition aguard.c:35
#define IDENT
static void FilterHelp(const char *base)
static enum MkErrorE FilterArgs(MK_RT mkrt, MQ_CTX mqctx, MK_BFL args)
#define MkBufferListCreateVC(...)
#define MkBufferListDelete(x)
#define MK_ERROR_PANIC
#define AllRtSetup_NULL
#define MkTypeDup2(...)
#define MqContextC_TT
#define MqExit_1(ctx)
#define MqProcessEvent_E(...)
#define MqFactoryNew_E(...)
#define MqFactoryAdd(...)
MQ_WAIT_FOREVER
struct MqContextS mqctx
Definition aguard.c:49
size_t objsize

◆ MqReadDump()

static enum MkErrorE MqReadDump ( MK_RT mkrt,
MQ_CTX const mqctx,
struct MqDumpS ** dumpP )
inlinestatic

Definition at line 71 of file aguard.c.

74 {
75 MkBinaryR out;
76 enum MkErrorE ret = MqReadBIN (mqctx, &out);
77 *dumpP = (struct MqDumpS *)out.data;
78 MkErrorReturn (ret);
79}
#define MqReadBIN(...)

◆ PkgToGrp()

static enum MkErrorE PkgToGrp ( MQ_SERVICE_CALL_ARGS )
static

Definition at line 235 of file aguard.c.

236{
237 enum MkErrorE ret;
238
239 MQ_CTX otherCtx = MqSlaveGetProxy_e (mqctx, MQ_SLAVE_OTHER);
240 MqEnvProtect(otherCtx);
241 ret = PkgToGrx2 ( MK_RT_CALL mqctx, "+GRP", otherCtx, mqctx->link.protect.transLId);
242 MqEnvRestore(otherCtx);
243 MkErrorCheck (ret);
244
245done:
246 return MqSendRETURN(mqctx);
247error:
248 MkErrorStack_1X(mqctx);
249 goto done;
250}
static enum MkErrorE PkgToGrx2(MK_RT mkrt, MQ_CTX const mqctx, MQ_TOK const token, MQ_CTX const otherCtx, MQ_LTR otherLId)
Definition aguard.c:84
#define MqEnvProtect(...)
MQ_EXTERN void MqEnvRestore(MQ_CTX ctx)
#define MqSlaveGetProxy_e(...)
+ Here is the caller graph for this function:

◆ PkgToGrx2()

static enum MkErrorE PkgToGrx2 ( MK_RT mkrt,
MQ_CTX const mqctx,
MQ_TOK const token,
MQ_CTX const otherCtx,
MQ_LTR otherLId )
static

Definition at line 84 of file aguard.c.

90{
91 enum MqHandShakeE hs = mqctx->link.protect.handShake;
92 enum MqTransTypeE tt = mqctx->link.protect.transType;
93 enum MkErrorE ret = MK_OK;
94 MkBinaryR bdat = {0};
95
96/*
97->GONE by split PRIVATE and PUBLIC
98
99 if (otherCtx->link.send == NULL) {
100 return MkErrorSetV_1XS("the '%s' object link is '%s' connected", "msgque", "not");
101 }
102*/
103
104//printLV("objsize=%zd, dump=%p\n",mqctx->obj.type->objsize, myctx->dump)
105
106 MqDumpExport_E (mqctx, &myctx->dump);
107
108 MkBinaryR bin = MqDumpBinGet(myctx->dump);
109
110 guard_crypt (bin.data, bin.size, ENCRYPT);
111 MqSendSTART_E (otherCtx);
112 MqSendSetHandShake_E (otherCtx, hs);
113
114 if (tt == MQ_TRANS_TYPE_TRANS) {
115 // in a "longterm-transaction" with "MqProxyForward" and "MqSendRETURN"…
116 // we DONT want any additional message from "MqSendRETURN" send to the "client".
117 // with "link.protect.bits.LIdLck = true" the shortterm-transaction will be deleted in
118 // "MqSendRETURN->sSendEND" → same as in "MqStorageInsert" or "MqDumpExport"
119 //
120 // client.exe
121 // Send("T"…) ->
122 // Filter.exe
123 // Send("R"…) <- ANSWER database INSERT
124 // EventProc
125 // MqProxyForward // forward to "targetctx"
126 // …
127 // MqSendRETURN // THIS is the problem, we DON'T want ANY package from there send to client.exe
128 //
129 mqctx->link.protect.bits.LIdLck = true;
130
131 // set the "transLId"
132 MqSendLTR_E (otherCtx, otherLId);
133 }
134
135 MqSendBIN_E (otherCtx, bin);
136
137 // direction: client -> server = call a service
138 if (hs == MQ_HANDSHAKE_START) {
139
140 // basically… MqSendEND_AND_WAIT can fail if an ASYNCRONE error arrive… even if
141 // LTT was successfull send… if "refCount" will be incr AFTER send… an final "+TRT" will NOT find
142 // the according transaction… and will create an ERROR
143 if (tt == MQ_TRANS_TYPE_TRANS) {
144 MkErrorCheck(MqStorageIncrRef(mqctx,otherLId));
145 }
146
147 if (mqctx->link.protect.transSId != 0) { // shortterm-transaction
148
149 // direction: mqctx -> otherCtx
150 switch (tt) {
151 case MQ_TRANS_TYPE_CB:
153 ret = MqSendEND_AND_WAIT (otherCtx, token, MK_TIMEOUT_DEFAULT);
154 break;
156 ret = MqSendEND_AND_SUB (otherCtx, token, sProxySubCall, mqctx, NULL, MK_TIMEOUT_DEFAULT);
157 break;
159 ret = MqSendEND_AND_TRANSACTION (otherCtx, token, NULL, MK_TIMEOUT_DEFAULT);
160 break;
161 default:
162 ret = MkErrorSetV_1XS("protocol-error -> invalid transaction-type: %s", MqTransTypeE_ToString(tt));
163 break;
164 }
165 MkErrorCheck (ret);
166
167 // start the answer
168 MqSendSTART_E (mqctx);
169
170 // Forward the "answer" of a STT… but only if "other-context" expect an answer
171 if (tt != MQ_TRANS_TYPE_TRANS) {
172
173 // read the answer
174 MqReadBIN_E (otherCtx, &bdat);
175
176 guard_crypt (bdat.data, bdat.size, DECRYPT);
177
178 // copy the answer from "otherCtx" to "mqctx"
179 MqProxyPackage_E (otherCtx, mqctx, (struct MqDumpS *) bdat.data);
180 }
181 } else { // transSId == 0
182 // direction: mqctx -> otherCtx
183 switch (tt) {
184 case MQ_TRANS_TYPE_NO:
185 ret = MqSendEND (otherCtx, token, MK_TIMEOUT_DEFAULT);
186 break;
188 ret = MqSendEND_AND_TRANSACTION (otherCtx, token, NULL, 0);
189 break;
190 default:
191 ret = MkErrorSetV_1XS("protocol-error -> invalid transaction-type: %s", MqTransTypeE_ToString(tt));
192 break;
193 }
194 MkErrorCheck (ret);
195 }
196
197 // direction: client <- server = answer from the service → handShake "O" or "E"
198 } else {
199
200 if (mqctx->link.protect.transSId != 0) { // shortterm-transaction, this is only valid for "+TRT"
201 switch (tt) {
203 ret = MqSendEND_AND_TRANSACTION (otherCtx, token, NULL, MK_TIMEOUT_DEFAULT);
204 break;
205 default:
206 ret = MkErrorSetV_1XS("protocol-error -> invalid transaction-type: %s", MqTransTypeE_ToString(tt));
207 break;
208 }
209 } else { // everything NOT "+TRT"
210 switch (tt) {
211 case MQ_TRANS_TYPE_NO:
212 ret = MqSendEND (otherCtx, token, MK_TIMEOUT_DEFAULT);
213 break;
215 ret = MqSendEND_AND_TRANSACTION (otherCtx, token, NULL, 0);
216 break;
217 default:
218 ret = MkErrorSetV_1XS("protocol-error -> invalid transaction-type: %s", MqTransTypeE_ToString(tt));
219 break;
220 }
221 }
222 MkErrorCheck (ret);
223 }
224
225done:
226 return MkErrorGetCode_0E();
227
228error:
229 MqContextErrorCopy(mqctx, otherCtx);
230 MkErrorStack_1X(mqctx);
231 goto done;
232}
#define MqSendSetHandShake_E(...)
#define MqSendLTR_E(...)
+ Here is the caller graph for this function:

◆ sProxySubCall()

static enum MkErrorE sProxySubCall ( MK_RT mkrt,
MQ_CTX const targetCtx,
MK_PTR const data )
static

Definition at line 56 of file aguard.c.

57{
58 MQ_CTX sourceCtx = (MQ_CTX ) data;
59 if (strncmp(MqServiceTokenGet (targetCtx), "_RSB",5) == 0) {
61 MkErrorCheck (MqProxyPackage (targetCtx, sourceCtx, NULL));
62 MkErrorCheck (MqSendRETURN_SUB(sourceCtx));
63 }
64 return MK_OK;
65error:
66 MqContextErrorCopy(targetCtx, sourceCtx);
67 return MkErrorStack_1X(targetCtx);
68}
struct MqContextS * MQ_CTX
#define MqProxyPackage(...)
#define MqSendRETURN_SUB(...)
struct MqLinkS link
enum MqHandShakeE handShake
+ Here is the caller graph for this function:

◆ TrtToGrt()

static enum MkErrorE TrtToGrt ( MQ_SERVICE_CALL_ARGS )
static

Definition at line 254 of file aguard.c.

255{
256 MQ_LTR rmtTransLIdOrig = mqctx->link.protect.rmtTransLId;
257
258 MkDLogV(mqctx,6,"work on 'transLId=" MK_FORMAT_T "'\n", rmtTransLIdOrig);
259
260 if (rmtTransLIdOrig < 0) {
261
262 MkErrorSetC_1XS ("internal-error: unable to GUARD a SEND-LTT");
263 goto error;
264
265 } else if (rmtTransLIdOrig > 0) {
266 MQ_LTR otherLId;
267 MQ_CTX otherCtx;
268 enum MkErrorE ret;
269
270 // step 1. -> get the "original" transaction of "mqctx->link.protect.rmtTransLId" from DB
271 MkErrorCheck (MqStorageResolve (mqctx, &otherCtx, &otherLId));
272
273 // step 2. -> send data
274 MqEnvProtect(otherCtx);
275 ret = PkgToGrx2 ( MK_RT_CALL mqctx, "+GRT", otherCtx, otherLId);
276 MqEnvRestore(otherCtx);
277 MkErrorCheck (ret);
278
279 } else {
280 MkPanicSYS (mqctx);
281 }
282
283done:
284 MqStorageDelete (mqctx, &mqctx->link.protect.transLId);
285 return MqSendRETURN(mqctx);
286error:
287 MkErrorStack_1X (mqctx);
288 goto done;
289}
#define MkPanicSYS(mngx)
+ Here is the caller graph for this function:

Variable Documentation

◆ AGuardTT

MK_TYP AGuardTT = NULL
static

Definition at line 34 of file aguard.c.