Code:
#include <stdio.h>
#include <ctype.h>
#include <atmi.h> /* TUXEDO Header File */
#include <userlog.h> /* TUXEDO Header File */
#ifdef WIN32
#include <sys/stat.h>
#else
#include <unistd.h>
#endif
#include "mt.c"
#include "tuxerrs.h"
#include "utils.h"
#include "fts_request.h" /* view definition for main transaction */
/* These can be varied from the command line parameters */
int debugOn = 0;
static unsigned long updateTimeout = 80;
/* tpsvrinit is executed when a server is booted, before it begins
processing requests. It is not necessary to have this function.
Also available is tpsvrdone (not used in this example), which is
called at server shutdown time.
*/
#if defined(__STDC__) || defined(__cplusplus)
tpsvrinit(int argc, char *argv[])
#else
tpsvrinit(argc, argv)
int argc;
char **argv;
#endif
{
int c = 0;
unsigned long temp = 0;
/* Some compilers warn if argc and argv aren't used. */
argc = argc;
argv = argv;
/* userlog writes to the central TUXEDO message log */
userlog("Welcome to the ARMTRX server v1.0.0");
while ((c = getopt(argc, argv, "d:t:")) != -1)
{
switch(c)
{
case 'd':
temp = (unsigned long) atol(optarg);
if (temp == 0)
debugOn = 0;
else
debugOn = 1;
break;
case 't':
temp = (unsigned long) atol(optarg);
if (temp > 0)
updateTimeout = temp;
else
userlog("TUXWARN: Invalid value for '-t' on command line");
break;
default:
userlog("TUXERR: Invalid command line option, '%c'", c);
return -1;
}
}
return(0);
}
/* This TUX service acts as a service dispatcher and invokes the actual
service required to handle the client's transaction.
Its argument is a structure containing among other things a pointer
to the data buffer, and the length of the data buffer. The data contains
a transaction code which allows us to identify which service should be
invoked.
*/
#ifdef __cplusplus
extern "C"
#endif
void
#if defined(__STDC__) || defined(__cplusplus)
ARMTRX(TPSVCINFO *rqst)
#else
ARMTRX(rqst)
TPSVCINFO *rqst;
#endif
{
struct fts_request_in *pstrARM_in = NULL; /* ARM Input */
struct fts_request_out *pstrARM_out = NULL; /* ARM Final Output */
struct fts_request_out *pstrARM_tmp = NULL; /* ARM Temp Output */
char *serviceName = rqst->name;
long rcode = 0;
long answer_len = 0;
int xdone = 0;
long acall = 0; /* jb01 return code for tpacall */
char TranCode[9];
char TempBuff[9];
char service_name[16];
/* Nad1-->> */
long mtrcode =0;
char *StpData =NULL;
/* Nad1 <<--*/
long
performTPCALL(
char* service_call,
struct fts_request_in *input_buffer,
struct fts_request_out **output_buffer
);
/* Retrieve the input data */
pstrARM_in = (struct fts_request_in *) rqst->data;
if (pstrARM_in == NULL)
{
userlog("TUXERR: Unable to read input buffer [Key = %.35s]", pstrARM_in);
tpreturn(TPFAIL, -1, NULL, 0L, 0L);
}
if ((pstrARM_out = (struct fts_request_out *)tpalloc("VIEW32",
"fts_request_out", sizeof(struct fts_request_out) + 8))
== (struct fts_request_out *)NULL)
{
userlog("TUXERR: tpalloc(\"fts_request_out\") failed, %s\n [Key = %.35s]",
tpstrerror(tperrno), pstrARM_in);
tpreturn(TPFAIL, -1, NULL, 0L, 0L);
}
memset(pstrARM_out, '\0', sizeof(struct fts_request_out));
/*
* Check Transaction Type and process accordingly.
*/
memcpy(pstrARM_in->fts_tranref, "RETARMCO", 8); /* Prep Input */
memset(TempBuff, 0, sizeof(TempBuff));
memset(TranCode, 0, sizeof(TranCode));
memcpy(TempBuff, ((struct fts_request_in*)pstrARM_in)->fts_request_fn+4,4);
sscanf(TempBuff, "%s", TranCode);
memset(service_name, 0, sizeof(service_name));
if (strncmp(TranCode, "NQ11", 4) == 0)
{
memcpy(pstrARM_out, pstrARM_in, 160);
memcpy(pstrARM_out->fts_camm_action_code, "0000", 4); /* Initialize */
rcode = tpbegin(updateTimeout, 0);
if (rcode == -1)
{
userlog("TUXERR: tpbegin() failed, %s [Key = %.35s]", tpstrerror(tperrno), pstrARM_in);
/* Return original message to caller with new action code. */
memcpy(pstrARM_out, pstrARM_in, sizeof(struct fts_request_out));
memcpy(pstrARM_out->fts_camm_action_code, TUXCODE_GENERALFAIL, 4);
answer_len = strlen((char*)pstrARM_out);
tpreturn(TPSUCCESS, -1, (char *)pstrARM_out, answer_len, 0L);
}
memcpy(service_name, "FTSREQ_RETARMCO", 16); /* Access to FTS */
rcode = performTPCALL(service_name, pstrARM_in, &pstrARM_out);
answer_len = strlen((char *) pstrARM_out);
if (rcode != 0)
{
rcode = tpabort(0);
if (rcode == -1)
{
userlog("TUXERR: tpabort() failed, %s [Key = %.35s]", tpstrerror(tperrno), pstrARM_in);
}
tpreturn(TPSUCCESS, rcode, (char *)pstrARM_out, answer_len, 0L);
}
/*
* Beyond this point, reply is successful.
* Commit the transaction.
*/
rcode = tpcommit(0);
if (rcode == -1)
{
/* Commit failure, attempt to tpabort(). */
userlog("TUXERR: tpcommit() failed, %s [Key = %.35s]", tpstrerror(tperrno), pstrARM_in);
rcode = tpabort(0);
if (rcode == -1)
{
userlog("TUXERR: tpabort() failed, %s [Key = %.35s]", tpstrerror(tperrno), pstrARM_in);
}
/* Return original message to caller with new action code. */
memcpy(pstrARM_out, pstrARM_in, sizeof(struct fts_request_out));
memcpy(pstrARM_out->fts_camm_action_code, TUXCODE_COMMITFAIL, 4);
answer_len = strlen((char*)pstrARM_out);
tpreturn(TPSUCCESS, -1, (char *)pstrARM_out, answer_len, 0L);
}
}
else if (strncmp(TranCode, "PD03", 4) == 0 ||
strncmp(TranCode, "PD06", 4) == 0 ||
strncmp(TranCode, "PD10", 4) == 0)
{
memcpy(service_name, "FTSREQ_RETARMCO", 16); /* Access to FTS */
rcode = performTPCALL(service_name, pstrARM_in, &pstrARM_out);
answer_len = strlen((char *) pstrARM_out);
if (strncmp(pstrARM_out->fts_result_code,"0000", 4) != 0 ||
rcode != 0)
{
tpreturn(TPSUCCESS, -1, (char *)pstrARM_out, answer_len, 0L);
}
if ((pstrARM_tmp = (struct fts_request_out *)tpalloc("VIEW32",
"fts_request_out", sizeof(struct fts_request_out) + 8))
== (struct fts_request_out *)NULL)
{
userlog("TUXERR: tpalloc(\"fts_request_out\") failed, %s [Key = %.35s]",
tpstrerror(tperrno), pstrARM_in);
tpreturn(TPFAIL, -1, NULL, 0L, 0L);
}
memset(pstrARM_tmp, '\0', sizeof(struct fts_request_out));
rcode = performTPCALL("GFCUPD", pstrARM_out, &pstrARM_tmp);
memcpy(pstrARM_out, '\0', 161);
memcpy(pstrARM_out, pstrARM_in, 160);
memcpy(pstrARM_out->fts_camm_action_code,
pstrARM_tmp->fts_camm_action_code, 4);
memcpy(pstrARM_out->fts_result_code,
pstrARM_tmp->fts_result_code, 4);
tpfree((char *)pstrARM_tmp);
tpreturn(TPSUCCESS, rcode, (char *)pstrARM_out, answer_len, 0L);
}
else if (strncmp(TranCode, "NQ99", 4) == 0)
{
if ((pstrARM_tmp = (struct fts_request_out *)tpalloc("VIEW32",
"fts_request_out", sizeof(struct fts_request_out) + 8))
== (struct fts_request_out *)NULL)
{
userlog("TUXERR: tpalloc(\"fts_request_out\") failed, %s [Key = %.35s]",
tpstrerror(tperrno), pstrARM_in);
tpreturn(TPFAIL, -1, NULL, 0L, 0L);
}
memset(pstrARM_tmp, '\0', sizeof(struct fts_request_out));
memcpy(service_name, "FTSREQ_RETARMCO", 16); /* Access to FTS */
xdone = 0;
while (!xdone)
{
rcode = performTPCALL(service_name, pstrARM_in, &pstrARM_out);
answer_len = strlen((char *) pstrARM_out);
if (strncmp(pstrARM_out->fts_output1,"NIL", 3) == 0 ||
strncmp(pstrARM_out->fts_output1,"ERR", 3) == 0 )
{
xdone = 1;
}
else
{
rcode = performTPCALL("GFCUPD", pstrARM_out, &pstrARM_tmp);
/*Nad1 */ StpData=pstrARM_out->fts_output1;
if (strncmp(pstrARM_tmp->fts_camm_action_code, "0000", 4) != 0)
{
memcpy(pstrARM_tmp->fts_output1,"REV",3);
memcpy(pstrARM_tmp->fts_output4,pstrARM_out->fts_output1+239,10); /*jb02*/
userlog("REVERT: [%s]", pstrARM_tmp);
rcode = performTPCALL(service_name, pstrARM_tmp, &pstrARM_out);
xdone = 1;
}
/* jb01 begin */
if (strncmp(pstrARM_in->fts_input+125, "CCSWP", 5) == 0)
{
memcpy(pstrARM_in->fts_input+125,"CCVRF",5);
acall = tpacall(service_name, (char*)pstrARM_in, 0L,
TPNOTRAN|TPNOREPLY);
/* Nad1 -->>*/
if (strncmp(pstrARM_tmp->fts_camm_action_code, "0000", 4) == 0)
{
userlog("The Input To Stp is [%s]",StpData);
mtrcode= mt( StpData,"/tuxhome/tuxadmin/src/armreq/" );
}
/*Nad End <<--- */
xdone = 1;
}
/* jb01 end */
}
}
}
else /* Transaction Code is Invalid */
{
memcpy(pstrARM_out, pstrARM_in, 160);
memcpy(pstrARM_out->fts_camm_action_code, TUXCODE_BADTXN, 4);
userlog("Invalid Transaction Code %s [Key = %.35s]", TranCode, pstrARM_in);
answer_len = strlen((char*)pstrARM_out);
tpreturn(TPSUCCESS, -1, (char *)pstrARM_out, answer_len, 0L);
}
answer_len = strlen((char *) pstrARM_out);
tpreturn(TPSUCCESS, 0, (char *)pstrARM_out, answer_len, 0L);
}
/*
* Function to perform tpcall to Services.
* - checks return code in message
*
* Returns:
* 0 : success, reply placed in output_buffer
* 1 : failure, error reply placed in output_buffer
*/
long
performTPCALL(
char* service_call,
struct fts_request_in *input_buffer,
struct fts_request_out **output_buffer
)
{
struct fts_request_out *output_buffer_ptr = *output_buffer;
long view_len = 0;
long rcode = 0;
if (debugOn)
{
userlog("DEBUG: About to call service '%s' [Key = %.35s]", service_call, input_buffer->fts_source_id);
}
view_len = sizeof(struct fts_request_out);
rcode = tpcall(service_call, (char *)input_buffer, 0,
(char **)&output_buffer_ptr, &view_len, 0);
*output_buffer = output_buffer_ptr;
if (rcode == -1)
{
userlog("TUXERR: tpcall(\"%s\") failed, %s [Key = %.35s]",
service_call, tpstrerror(tperrno), input_buffer);
/* Return original message to caller with new action code. */
memcpy(output_buffer_ptr, input_buffer, sizeof(struct fts_request_out));
memcpy(output_buffer_ptr->fts_camm_action_code, TUXCODE_SVCFAIL, 4);
return -1;
}
/* inspect action code in message */
if (strncmp(output_buffer_ptr->fts_camm_action_code, "0000", 4) != 0 &&
strncmp(output_buffer_ptr->fts_camm_action_code, "5555", 4) != 0 )
{
userlog("ERROR: Request to %s failed: [%.4s] [Key = %.35s]",
service_call, output_buffer_ptr->fts_camm_action_code, input_buffer);
return 1;
}
/* NB: reply is already in output_buffer for caller */
return 0;
} /* performTPCALL() */