#include "os.h"
#include "common.h"
#include "RRcommon.h"
void
common_printCCSMPversion ( void )
{
printf ( "Unknown library version, solClient_version_get returns FAIL\n\n" );
} else {
}
}
void
{
"%s - ReturnCode=\"%s\", SubCode=\"%s\", ResponseCode=%d, Info=\"%s\"",
}
void
common_parseUsernameAndVpn ( const char *inName, char *outUsername, size_t usernameLen, char *outVpn, size_t vpnLen )
{
const char *c = inName;
char *dest = outUsername;
size_t remaining = usernameLen;
while ( *c ) {
if ( *c == '@' ) {
*dest = '\0';
dest = outVpn;
remaining = vpnLen;
} else {
if ( remaining ) {
*dest++ = *c;
remaining--;
} else {
*( dest - 1 ) = '\0';
}
}
c++;
}
*dest = '\0';
}
void
common_initCommandOptions ( struct commonOptions *commonOpt,
int requiredParams,
int optionals)
{
if (commonOpt != NULL) {
commonOpt->username[0] = ( char ) 0;
commonOpt->password[0] = ( char ) 0;
commonOpt->vpn[0] = ( char ) 0;
commonOpt->targetHost[0] = ( char ) 0;
commonOpt->cacheName[0] = ( char ) 0;
commonOpt->replayStartLocation[0] = ( char ) 0;
commonOpt->usingTopic = TRUE;
commonOpt->usingAD = FALSE;
commonOpt->destinationName[0] = ( char ) 0;
commonOpt->numMsgsToSend = 1;
commonOpt->msgRate = 1;
commonOpt->gdWindow = 0;
commonOpt->usingDurable = FALSE;
commonOpt->enableCompression = FALSE;
commonOpt->useGSS = FALSE;
commonOpt->requiredFields = requiredParams;
commonOpt->optionalFields = optionals;
}
}
int
common_parseCommandOptions ( int argc, charPtr32 *argv, struct commonOptions *commonOpt, const char *positionalDesc )
{
static char *optstring = "a:c:dgl:m:n:p:r:s:t:u:w:zR:";
static struct option longopts[] = {
{"cache", 1, NULL, 'a'},
{"cip", 1, NULL, 'c'},
{"durable", 0, NULL, 'd'},
{"gss", 0, NULL, 'g'},
{"log", 1, NULL, 'l'},
{"cu", 1, NULL, 'u'},
{"mn", 1, NULL, 'n'},
{"cp", 1, NULL, 'p'},
{"mr", 1, NULL, 'r'},
{"topic", 1, NULL, 't'},
{"win", 1, NULL, 'w'},
{"zip", 0, NULL, 'z'},
{"replay", 1, NULL, 'R'},
{0, 0, 0, 0}
};
int c;
int rc = 1;
char *end_p;
charPtr *argVOS;
INIT_OS_ARGS(argc, argv, argVOS);
while ( ( c = getopt_long ( argc, argVOS, optstring, longopts, NULL ) ) != -1 ) {
switch ( c ) {
case 'a':
strncpy ( commonOpt->cacheName, optarg, sizeof ( commonOpt->cacheName ) );
break;
case 'c':
strncpy ( commonOpt->targetHost, optarg, sizeof ( commonOpt->targetHost ) );
break;
case 'd':
commonOpt->usingDurable = TRUE;
break;
case 'g':
commonOpt->useGSS = TRUE;
break;
case 'z':
commonOpt->enableCompression = TRUE;
break;
case 'R':
strncpy ( commonOpt->replayStartLocation, optarg, sizeof ( commonOpt->replayStartLocation ) );
break;
case 'l':
if ( strcasecmp ( optarg, "debug" ) == 0 ) {
} else if ( strcasecmp ( optarg, "info" ) == 0 ) {
} else if ( strcasecmp ( optarg, "notice" ) == 0 ) {
} else if ( strcasecmp ( optarg, "warn" ) == 0 ) {
} else if ( strcasecmp ( optarg, "error" ) == 0 ) {
} else if ( strcasecmp ( optarg, "critical" ) == 0 ) {
} else {
rc = 0;
}
}
break;
case 'n':
commonOpt->numMsgsToSend = atoi ( optarg );
if ( commonOpt->numMsgsToSend <= 0 )
rc = 0;
break;
case 'r':
commonOpt->msgRate = atoi ( optarg );
if ( commonOpt->msgRate <= 0 )
rc = 0;
break;
case 't':
strncpy ( commonOpt->destinationName, optarg, sizeof ( commonOpt->destinationName ) );
break;
case 'u':
common_parseUsernameAndVpn ( optarg,
commonOpt->username,
sizeof ( commonOpt->username ), commonOpt->vpn, sizeof ( commonOpt->vpn ) );
break;
case 'p':
strncpy ( commonOpt->password, optarg, sizeof ( commonOpt->password ) );
break;
case 'w':
commonOpt->gdWindow = atoi ( optarg );
if ( commonOpt->gdWindow <= 0 )
rc = 0;
break;
default:
rc = 0;
break;
}
}
if ( ( commonOpt->requiredFields & HOST_PARAM_MASK ) && ( commonOpt->targetHost[0] == ( char ) 0 ) ) {
printf ( "Missing required parameter '--cip'\n" );
rc = 0;
}
if ( ( commonOpt->requiredFields & USER_PARAM_MASK ) && ( commonOpt->username[0] == ( char ) 0 ) && !commonOpt->useGSS) {
printf ( "Missing required parameter '--cu'\n" );
rc = 0;
}
if ( ( commonOpt->requiredFields & DEST_PARAM_MASK ) && ( commonOpt->destinationName[0] == ( char ) 0 ) ) {
printf ( "Missing required parameter '--topic'\n" );
rc = 0;
}
if ( ( commonOpt->requiredFields & PASS_PARAM_MASK ) && ( commonOpt->password[0] == ( char ) 0 ) ) {
printf ( "Missing required parameter '--cp'\n" );
rc = 0;
}
if ( ( commonOpt->requiredFields & CACHE_PARAM_MASK) && ( commonOpt->cacheName[0] == ( char ) 0) ) {
printf ( "Missing required parameter '--cache'\n" );
rc = 0;
}
if (rc == 0) {
if (positionalDesc == NULL) {
printf ("\nUsage: %s PARAMETERS [OPTIONS]\n\n",
argVOS[0]
);
} else {
printf ("\nUsage: %s PARAMETERS [OPTIONS] [ARGUMENTS]\n\n",
argVOS[0]
);
}
printf (
"Where PARAMETERS are:\n%s%s%s%s%s%s"
"Where OPTIONS are:\n%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
( commonOpt->requiredFields & HOST_PARAM_MASK ) ? HOST_PARAM_STRING : "",
( commonOpt->requiredFields & USER_PARAM_MASK ) ? USER_PARAM_STRING : "",
( commonOpt->requiredFields & DEST_PARAM_MASK ) ? DEST_PARAM_STRING : "",
( commonOpt->requiredFields & PASS_PARAM_MASK ) ? PASS_PARAM_STRING : "",
( commonOpt->requiredFields & CACHE_PARAM_MASK ) ? CACHE_PARAM_STRING : "",
( commonOpt->requiredFields & REPLAY_START_MASK ) ? REPLAY_START_STRING : "",
( commonOpt->optionalFields & HOST_PARAM_MASK ) ? HOST_PARAM_STRING : "",
( commonOpt->optionalFields & USER_PARAM_MASK ) ? USER_PARAM_STRING : "",
( commonOpt->optionalFields & DEST_PARAM_MASK ) ? DEST_PARAM_STRING : "",
( commonOpt->optionalFields & PASS_PARAM_MASK ) ? PASS_PARAM_STRING : "",
( commonOpt->optionalFields & CACHE_PARAM_MASK ) ? CACHE_PARAM_STRING : "",
( commonOpt->optionalFields & DURABLE_MASK ) ? DURABLE_STRING : "",
( commonOpt->optionalFields & NUM_MSGS_MASK ) ? NUM_MSGS_STRING : "",
( commonOpt->optionalFields & MSG_RATE_MASK ) ? MSG_RATE_STRING : "",
( commonOpt->optionalFields & WINDOW_SIZE_MASK ) ? WINDOW_SIZE_STRING : "",
( commonOpt->optionalFields & LOG_LEVEL_MASK ) ? LOG_LEVEL_STRING : "",
( commonOpt->optionalFields & USE_GSS_MASK ) ? USE_GSS_STRING : "",
( commonOpt->optionalFields & ZIP_LEVEL_MASK ) ? ZIP_LEVEL_STRING : "",
( commonOpt->optionalFields & REPLAY_START_MASK ) ? REPLAY_START_STRING : ""
);
if (positionalDesc != NULL) {
printf (
"Where ARGUMENTS are:\n%s",
positionalDesc
);
}
}
FREE_OS_ARGS
return ( rc );
}
void *user_p, struct commonOptions * commonOpts )
{
const char *sessionProps[50];
int propIndex = 0;
propIndex = 0;
if ( commonOpts->targetHost[0] ) {
sessionProps[propIndex++] = commonOpts->targetHost;
}
sessionProps[propIndex++] = ( commonOpts->enableCompression ) ? "9" : "0";
sessionProps[propIndex++] = "3";
sessionProps[propIndex++] = "3";
if ( commonOpts->vpn[0] ) {
sessionProps[propIndex++] = commonOpts->vpn;
}
sessionProps[propIndex++] = commonOpts->username;
sessionProps[propIndex++] = commonOpts->password;
if ( commonOpts->useGSS ) {
}
sessionProps[propIndex] = NULL;
context_p,
session_p, &sessionFuncInfo,
sizeof ( sessionFuncInfo ) ) ) !=
SOLCLIENT_OK ) {
common_handleError ( rc, "solClient_session_create()" );
return rc;
}
common_handleError ( rc, "solClient_session_connect()" );
return rc;
}
}
{
const char *props[40];
int propIndex = 0;
props[propIndex++] = queueName_p;
if ( strcmp ( queueName_p, COMMON_DMQ_NAME ) != 0 ) {
}
props[propIndex] = NULL;
NULL,
common_handleError ( rc, "solClient_session_endpointProvision()" );
return rc;
}
}
{
const char *props[40];
int propIndex = 0;
props[propIndex++] = queueName_p;
props[propIndex] = NULL;
common_handleError ( rc, "solClient_session_endpointDeprovision()" );
return rc;
}
}
{
common_handleError ( rc, "solClient_msg_alloc()" );
return rc;
}
common_handleError ( rc, "solClient_msg_setDeliveryMode()" );
goto freeMessage;
}
destination.
dest = topic_p;
common_handleError ( rc, "solClient_msg_setDestination()" );
goto freeMessage;
}
common_handleError ( rc, "solClient_session_sendMsg()" );
goto freeMessage;
}
freeMessage:
common_handleError ( rcFreeMsg, "solClient_msg_free()" );
}
return rc;
}
void
{
printf ( "common_cacheEventCallback() called - %s\n"
"topic: %s\n"
"responseCode: (%d) %s\n"
"subCode: (%d) %s\n"
"cacheRequestId: %llu\n\n",
}
void
{
"common_eventCallback() called - %s\n",
break;
printf ( "common_eventCallback() called - %s; subCode %s, responseCode %d, reason %s\n",
break;
default:
printf ( "common_eventCallback() called - %s. Unrecognized or deprecated event.\n",
break;
}
}
void
{
}
void
{
"common_flowEventCallback() called - %s\n",
break;
printf ( "common_flowEventCallback() called - %s; subCode %s, responseCode %d, reason %s\n",
break;
default:
printf ( "common_flowEventCallback() called - %s. Unrecognized or deprecated event.\n",
break;
}
}
{
int *counter_p;
if ( user_p == NULL ) {
printf ( "Received message on flow. (Message ID: %lld).\n", msgId );
} else {
printf ( "Received message on flow.\n" );
}
} else {
counter_p = ( int * ) user_p;
( *counter_p )++;
}
}
{
printf ( "Acknowledging message Id: %lld.\n", msgId );
} else {
printf ( "Received message on flow.\n" );
}
}
{
printf ( "Received message:\n" );
common_handleError ( rc, "solClient_msg_dump()" );
}
printf ( "\n" );
}
{
printf ( "Received message:\n" );
common_handleError ( rc, "solClient_msg_dump()" );
}
printf ( "\n" );
printf ( "Acknowledging message Id: %lld.\n", msgId );
}
}
{
const char *senderId_p;
rxSeqNum = 0;
} else {
common_handleError ( rc, "solClient_msg_getSequenceNumber()" );
}
}
senderId_p = "";
} else {
common_handleError ( rc, "solClient_msg_getSenderId()" );
}
}
if ( user_p != NULL ) {
printf ( "%s received message from '%s' (seq# %llu)\n", ( char * ) user_p, senderId_p, rxSeqNum );
} else {
printf ( "Received message from '%s' (seq# %llu)\n", senderId_p, rxSeqNum );
}
}
{
if ( user_p != NULL ) {
printf ( "%s Received message:\n", (char *)user_p );
} else {
printf ( "Received message:\n" );
}
common_handleError ( rc, "solClient_msg_dump()" );
}
printf ( "\n" );
}
{
}
threadRetType
# ifdef WIN32
__stdcall
# endif
common_contextThread ( void *contextInfo_p )
{
contextThreadInfo_t *info_p = ( contextThreadInfo_t * ) contextInfo_p;
info_p->rc = 0;
while ( !info_p->stopContextThread ) {
common_handleError ( rc, "solClient_context_processEvents" );
break;
}
}
# ifdef WIN32
return 0;
# else
return NULL;
# endif
}
common_initContextThread ( contextThreadInfo_t * info_p )
{
};
info_p->stopContextThread = 0;
info_p->contextThreadStarted = 0;
}
int
common_startContextThread ( contextThreadInfo_t * info_p )
{
int rc = 1;
info_p->stopContextThread = 0;
# ifdef WIN32
info_p->handle = CreateThread ( NULL,
0,
common_contextThread,
( void * ) info_p,
0,
NULL );
if ( info_p->handle == NULL ) {
rc = 0;
} else {
info_p->contextThreadStarted = 1;
}
# else
if ( pthread_create ( &( info_p->handle ), NULL, common_contextThread, ( void * ) info_p ) < 0 ) {
rc = 0;
} else {
info_p->contextThreadStarted = 1;
}
# endif
return rc;
}
int
common_startThread ( threadFn_pt threadFunction, void *user_p, threadInfo_t * info_p )
{
int rc = 1;
info_p->stopThread = 0;
info_p->user_p = user_p;
# ifdef WIN32
info_p->handle = CreateThread ( NULL,
0,
threadFunction,
( void * ) info_p,
0,
NULL );
if ( info_p->handle == NULL ) {
rc = 0;
} else {
info_p->threadStarted = 1;
}
# else
if ( pthread_create ( &( info_p->handle ), NULL, threadFunction, ( void * ) info_p ) < 0 ) {
rc = 0;
} else {
info_p->threadStarted = 1;
}
# endif
return rc;
}
void
common_stopContextThread ( contextThreadInfo_t * info_p )
{
info_p->stopContextThread = 1;
# ifdef WIN32
WaitForSingleObject ( info_p->handle, INFINITE );
CloseHandle ( info_p->handle );
info_p->handle = NULL;
# else
void *value_p;
pthread_join ( info_p->handle, &value_p );
# endif
}
void
common_stopThread ( threadInfo_t * info_p )
{
info_p->stopThread = 1;
# ifdef WIN32
WaitForSingleObject ( info_p->handle, INFINITE );
CloseHandle ( info_p->handle );
info_p->handle = NULL;
# else
void *value_p;
pthread_join ( info_p->handle, &value_p );
# endif
}
const char *
RR_operationToString ( RR_operation_t operation )
{
static char *plusString = "PLUS";
static char *minusString = "MINUS";
static char *timesString = "TIMES";
static char *divideString = "DIVIDED_BY";
static char *unknownString = "UNKNOWN";
switch ( operation ) {
case plusOperation:
return plusString;
case minusOperation:
return minusString;
case timesOperation:
return timesString;
case divideOperation:
return divideString;
default:
return unknownString;
}
}