Skip to content

Commit

Permalink
Merge branch 'Jordan-branch-2' of github.com:zowe/zowe-common-c into …
Browse files Browse the repository at this point in the history
…Jordan-branch-2
  • Loading branch information
jordanfilteau1995 committed Aug 30, 2023
2 parents d4821d3 + e5d0628 commit 6b1ac24
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 82 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Zowe Common C Changelog

## `2.11.0`

- WTO printing methods have been moved to zos.c to be more available as utilities (for ex: for the Launcher)

## `2.10.0`

- Feature: The configmgr can now use the 'zos' module in YAML config templates. The 'zos' module is only added when run on ZOS. For a list of available functions, see https://github.com/zowe/zowe-install-packaging/blob/v2.x/staging/build/zwe/types/%40qjstypes/zos.d.ts (#384)
Expand Down
11 changes: 6 additions & 5 deletions c/configmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,18 +694,19 @@ static Json *readYamlIntoJson(ConfigManager *mgr, char *filename, bool allowMiss
*/
e2a(errorBuffer,sizeof(errorBuffer));
#endif
trace(mgr,INFO,"%s - %s\n","ZWEL0318E",msg);
trace(mgr,INFO,"%s - %s\n","ZWEL0318E",errorBuffer);
return NULL;
}
}

static char *getAbsolutePathOrKeepRelativePath(const char *filename, ShortLivedHeap *slh) {
static char *getAbsolutePathOrKeepRelativePath(const char *filename, ConfigManager *mgr) {

char *fileOrPath = SLHAlloc(slh, USS_MAX_PATH_LENGTH+1);
char *fileOrPath = SLHAlloc(mgr->slh, USS_MAX_PATH_LENGTH+1);

if (fileOrPath) {
memset(fileOrPath, 0, USS_MAX_PATH_LENGTH+1);
if (!realpath(filename, fileOrPath)) {
trace(mgr,DEBUG,"Couldn't get absolute path for '%s'. errno=%d\n", filename, errno);
trace(mgr, DEBUG, "Couldn't get absolute path for '%s'. errno=%d\n", filename, errno);
strcpy(fileOrPath, filename);
}
}
Expand All @@ -729,7 +730,7 @@ static Json *readJson(ConfigManager *mgr, CFGConfig *config, ConfigPathElement *
* Just in case, we will default to pathElement->data if 'absolutePath' comes back as null because
* it should be the same thing anyways.
*/
char *absolutePath = getAbsolutePathOrKeepRelativePath(pathElement->data,mgr->slh);
char *absolutePath = getAbsolutePathOrKeepRelativePath(pathElement->data,mgr);
return readYamlIntoJson(mgr,absolutePath ? absolutePath : pathElement->data,false);
} else if (pathElement->flags & CONFIG_PATH_MVS_PARMLIB){
char pdsMemberSpec[MAX_PDS_NAME];
Expand Down
2 changes: 1 addition & 1 deletion c/le.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ char *getCAA(void){
}

#ifndef LE_MAX_SUPPORTED_ZOS
#define LE_MAX_SUPPORTED_ZOS 0x01020500u
#define LE_MAX_SUPPORTED_ZOS 0x01030100u
#endif

void abortIfUnsupportedCAA() {
Expand Down
69 changes: 8 additions & 61 deletions c/metalio.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "qsam.h"
#include "metalio.h"
#include "alloc.h"
#include "zos.h"

static int isopen(void * dcbptr) {

Expand Down Expand Up @@ -378,30 +379,7 @@ SYSOUT *getSYSOUTStruct(char *ddname, SYSOUT *existingSysout, char *buffer){
*/
void message(char *message){

ALLOC_STRUCT31(
STRUCT31_NAME(below2G),
STRUCT31_FIELDS(
WTOCommon31 common;
char text[126]; /* Maximum length of WTO text is 126 - ABEND D23-xxxx0005 if longer than 126 */
)
);

int len = strlen(message);
if (len>sizeof(below2G->text))
len=sizeof(below2G->text);

below2G->common.length = len+sizeof(below2G->common); /* +4 for header */
memcpy(below2G->text,message,len);

__asm(ASM_PREFIX
" WTO MF=(E,(%[wtobuf])) \n"
:
:[wtobuf]"NR:r1"(&below2G->common)
:"r0","r1","r15");

FREE_STRUCT31(
STRUCT31_NAME(below2G)
);
wtoMessage(message);
}

/* this can only be called from authorized callers */
Expand Down Expand Up @@ -485,44 +463,13 @@ void sendWTO(int descriptorCode, int routingCode, char *message, int length){
}

#define WTO_MAX_SIZE 126
void wtoPrintf(char *formatString, ...){
char text[WTO_MAX_SIZE+1]; /* Allow for trailing null character */
void wtoPrintf(char *formatString, ...) {
va_list argPointer;
int cnt;

for (int pass=0; pass<2; pass++){

/* The resulting text string from vsnprintf is unpredictable if
there is an error in the format string or arguments. In that
case we will set the output text area to null, repeat the
vsnprintf, and then find the length of the null terminated
string. This avoids initializing the output text area prior
to every successful request.
*/

va_start(argPointer,formatString);
cnt = vsnprintf(text,sizeof(text),formatString,argPointer);
va_end(argPointer);

if (cnt<0){
if (pass==0)
memset(text,0,sizeof(text)); /* Clear the text buffer before retrying the vsnprint request */
else {
text[WTO_MAX_SIZE] = 0; /* Ensure strlen stops at the end of the text buffer */
cnt = strlen(text); /* Find the end of the text string */
}
} else
break; /* vsnprintf did not return an error - cnt was set */
}
if (cnt>WTO_MAX_SIZE) /* If more data to format than the text buffer length */
cnt = WTO_MAX_SIZE; /* Truncate the formatted length to the text buffer length */

/* We never want to include a final \n character in the WTO text */

if (cnt>0 && text[cnt-1] == '\n') /* If text ends with \n */
text[cnt-1] = 0; /* Change it into a null character */

message(text);
va_start(argPointer, formatString);

wtoPrintf3(formatString, argPointer);

va_end(argPointer);
}

void authWTOPrintf(char *formatString, ...){
Expand Down
1 change: 1 addition & 0 deletions c/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Copyright Contributors to the Zowe Project.
*/
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <errno.h>
#include "alloc.h"
Expand Down
17 changes: 9 additions & 8 deletions c/yaml2json.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,14 @@ static void decodeParserError(yaml_parser_t *parser, char *errorBuf, size_t erro
strcpy(problemNative, parser->problem);
convertToNative(problemNative, problemLen);
}
char *nativeContext = NULL;
size_t contextLen = 0;
char *contextNative = NULL;
if (parser->context) {
size_t contextLen = strlen(parser->context);
nativeContext = safeMalloc(contextLen + 1, "parser context");
if (nativeContext) {
memset(nativeContext, 0, contextLen + 1);
strcpy(nativeContext, parser->context);
contextLen = strlen(parser->context);
contextNative = safeMalloc(contextLen + 1, "parser context");
if (contextNative) {
memset(contextNative, 0, contextLen + 1);
strcpy(contextNative, parser->context);
convertToNative(contextNative, contextLen);
}
}
Expand All @@ -164,7 +165,7 @@ static void decodeParserError(yaml_parser_t *parser, char *errorBuf, size_t erro
snprintf(errorBuf, errorBufSize,
"Couldn't scan file '%s': %s at line %d, column %d, "
"%s at line %d, column %d.",
filename, nativeContext,
filename, contextNative,
(int)parser->context_mark.line+1, (int)parser->context_mark.column+1,
problemNative, (int)parser->problem_mark.line+1,
(int)parser->problem_mark.column+1);
Expand All @@ -180,7 +181,7 @@ static void decodeParserError(yaml_parser_t *parser, char *errorBuf, size_t erro
snprintf(errorBuf, errorBufSize,
"Couldn't parse file '%s': %s at line %d, column %d, "
"%s at line %d, column %d.",
filename, nativeContext,
filename, contextNative,
(int)parser->context_mark.line+1, (int)parser->context_mark.column+1,
problemNative, (int)parser->problem_mark.line+1,
(int)parser->problem_mark.column+1);
Expand Down
72 changes: 72 additions & 0 deletions c/zos.c
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,78 @@ int safStat(int options, char *safClass, char *copy, int copyLength, int *racfSt
get current TCB AC
*/

/* begin WTO SECTION */

void wtoMessage(const char *message){

ALLOC_STRUCT31(
STRUCT31_NAME(below2G),
STRUCT31_FIELDS(
WTOCommon31 common;
char text[126]; /* Maximum length of WTO text is 126 - ABEND D23-xxxx0005 if longer than 126 */
)
);

int len = strlen(message);
if (len>sizeof(below2G->text))
len=sizeof(below2G->text);

below2G->common.length = len+sizeof(below2G->common); /* +4 for header */
memcpy(below2G->text,message,len);

__asm(ASM_PREFIX
" WTO MF=(E,(%[wtobuf])) \n"
:
:[wtobuf]"NR:r1"(&below2G->common)
:"r0","r1","r15");

FREE_STRUCT31(
STRUCT31_NAME(below2G)
);
}

#define WTO_MAX_SIZE 126
void wtoPrintf3(const char *formatString, ...) {
char text[WTO_MAX_SIZE+1]; /* Allow for trailing null character */
va_list argPointer;
int cnt;

for (int pass=0; pass<2; pass++){

/* The resulting text string from vsnprintf is unpredictable if
there is an error in the format string or arguments. In that
case we will set the output text area to null, repeat the
vsnprintf, and then find the length of the null terminated
string. This avoids initializing the output text area prior
to every successful request.
*/

va_start(argPointer,formatString);
cnt = vsnprintf(text,sizeof(text),formatString,argPointer);
va_end(argPointer);

if (cnt<0){
if (pass==0)
memset(text,0,sizeof(text)); /* Clear the text buffer before retrying the vsnprint request */
else {
text[WTO_MAX_SIZE] = 0; /* Ensure strlen stops at the end of the text buffer */
cnt = strlen(text); /* Find the end of the text string */
}
} else
break; /* vsnprintf did not return an error - cnt was set */
}
if (cnt>WTO_MAX_SIZE) /* If more data to format than the text buffer length */
cnt = WTO_MAX_SIZE; /* Truncate the formatted length to the text buffer length */

/* We never want to include a final \n character in the WTO text */

if (cnt>0 && text[cnt-1] == '\n') /* If text ends with \n */
text[cnt-1] = 0; /* Change it into a null character */

wtoMessage(text);
}

/* end WTO SECTION */

/* LOCATE/CAMLIST */

Expand Down
7 changes: 0 additions & 7 deletions h/metalio.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,6 @@ typedef struct WTORPrefix31_tag{
char *replayECBAddress;
} WTORPrefix31;

typedef struct WTOCommon31_tag{
char replyBufferLength; /* 31-bit WTOR only, else 0 */
char length; /* message length +4 */
char mcsFlags1;
char mcsFlags2;
} WTOCommon31;

#define WTO_ROUTE_CODE_OPERATOR_ACTION 1
#define WTO_ROUTE_CODE_OPERATOR_INFORMATION 2
#define WTO_ROUTE_CODE_TAPE_POOL 3
Expand Down
11 changes: 11 additions & 0 deletions h/zos.h
Original file line number Diff line number Diff line change
Expand Up @@ -1522,13 +1522,24 @@ typedef struct IDTA_tag {
char reserved[8];
} IDTA;

typedef struct WTOCommon31_tag{
char replyBufferLength; /* 31-bit WTOR only, else 0 */
char length; /* message length +4 */
char mcsFlags1;
char mcsFlags2;
} WTOCommon31;

ZOWE_PRAGMA_PACK_RESET

DSAB *getDSAB(char *ddname);


int dsabIsOMVS(DSAB *dsab);

void wtoMessage(const char *message);

void wtoPrintf3(const char *formatString, ...);

int locate(char *dsn, int *volserCount, char *firstVolser);

/*
Expand Down

0 comments on commit 6b1ac24

Please sign in to comment.