Skip to content

MDRTOOLS Copybook

Additional MDRest4i utilities used by the SDK, and also available for customer use.

**FREE
// ©=2023 Midrange Dynamics===============================================================
// Create Date : 2023/07/26
// This is an internal copybook used by the MDRest4i SDK. The MDRTOOLS *SRVPGM
// contains modules with the procedures that are prototyped below
// ©=2023 Midrange Dynamics===============================================================

///=======================================================================================
// MDRT_RPG_COBOL_Schema_Extract
//
// Extracts an OAPI Payload Schema from RPG/COBOL Data Structures
//
//   @param (input) handle: threadsafe handler key
//   @param (input) srcMember: name of the source member to scan
//   @param (input) srcFile: name of the source file containing the member
//   @param (input) srcLibrary: source library containing the source member
//   @param (input) srcPath: path to source file containing the data structures (future)
//   @param (input) srcType: RPGLE or SQLRPGLE or CBL,CBLLE, LBL, SQLCBL, SQLCBLLE
//
//   @return Extracted JSON schema for data structure definitions from copybook
//
// Example call:
// OAPISchema = MDRT_RPG_COBOL_Schema_Extract(handle:SourceMember:SourceFile:
//              SrcLibrary:IFSPathOfSource:SrcMemberType);
// @info MDRTOOLS2
///=======================================================================================

dcl-pr MDRT_RPG_COBOL_Schema_Extract varchar(41960) rtnparm;
   handle like(MDR_handle_t);
   srcMember char(10) const;
   srcFile char(10) const;
   srcLibrary char(10) const;
   srcPath varchar(256) const;
   srcType char(10) const;
   errorMessage varchar(50);
end-pr;

///=======================================================================================
// schemaEntryDetails
//
// A data structure representation of an OAPI Schema. Used by procedures in MDRTOOLS3
//
//   sr_entryName = name of object, array or variable
//   sr_entryNamenew = New entry name if special chars or beginning numeric digits
//   sr_entrytype = Expected values "O","A","AO","string","integer","numer","boolean"
//   sr_entdepthlvl = Entry depth level starting 0, increases with next subfield in DS
//   sr_entdatatype = IBMi data type calculated based on entry type
//   sr_entLength = Entry/Variable Length
//   sr_entDecimal = Decimal Positions
//   sr_schemaname = schema name (if applicable) for the entry being processed
//   sr_schematype = "req" or "rsp" for request or response schema
//   sr_maxLength = max Length as specified in "maxLength" for the schema entry
//   sr_maxdecimal = Decimal Precision as in "maximum", "minimum" or "multipleOf"
//   sr_maxArrayItems = Array dimension as found in "maxitems" parameter of schema
//   sr_xibmitype = value found in "x-ibmitype" keyword e.g. zoned, packed
//   si_entrycount = Number of entries loaded in these group of arrays
//
///=======================================================================================

dcl-ds schemaEntryDetails based(schemaEntry_ptr);
  sr_entryName char(40) dim(32766);
  sr_entryNamenew char(40) dim(32766);
  sr_entrytype char(10) dim(32766);
  sr_entDepthlvl zoned(5:0) dim(32766);
  sr_entdatatype char(1) dim(32766);
  sr_entlength packed(7:0) dim(32766);
  sr_entdecimals packed(2:0) dim(32766);
  sr_schemaname like(sr_entryname) dim(32766);
  sr_schematype char(4) dim(32766);
  sr_maxlength packed(9:0) dim(32766);
  sr_maxdecimal packed(3:0) dim(32766);
  sr_maxArrayitems int(10) dim(32766);
  sr_xibmitype char(10) dim(32766);
  si_entrycount zoned(5:0);
end-ds;

// This variable is used where the procedures of MDRTOOLS3 are used
dcl-s schemaEntry_ptr pointer;

///=======================================================================================
// MDRT_ExtractSchemaStructure
//
// This is a recursive procedure to read the OAPI schema starting at "beginNode" of YAJL
// tree and loads the details in "schemaEntryDetails" data structure pointer by the last
// parameter "SchemaEntry_Ptr"
//
//   @param (input) beginNode: Starting node address to begin at
//   @param (input) beginKeyVal: name of the starting node ( object or normal variable name)
//   @param (input) currentDepthLvl: Current depth of DS/subfield nesting
//   @param (input) currentSchema: name of the schema (if applicable) enclosing current entry
//   @param (input) reqrsptype: Type of schema "req" - Request, "rsp" - Response
//   @param (input) mainRoot: Main/original root node of the OAPI schema tree as loaded by YAJL
//   @param (output) schemaEntry_Ptr: Address of "schemaEntryStructure"
//
// Example Call:
//   MDRT_ExtractSchemaStructure(requestNode:'req':0:*blanks:'req':rootPointer:
//                          schemaEntry_Pointer);
// @info MDRTOOLS3
///=======================================================================================

dcl-pr MDRT_ExtractSchemaStructure;
  beginNode pointer;
  beginkeyval varchar(1024) const;
  currentDepthlvl int(5) const;
  currentschema char(100) const;
  reqrsptype char(4) const;
  mainRoot pointer value;
  schemaEntry_ptr pointer value;
end-pr;

///=======================================================================================
// MDRT_BuildSchemaString
//
// Process DS info loaded in "schemaEntryDetails" data structure and build the schema
// in special string format for COBOL
//
//   @param (input) schematype: This can be "req" or "rsp" based on what you want to process
//                              from the entries in "schemaEntryDetails" DS
//   @param (input) schemaEntry_Ptr: Address of the "schemaEntryDetails" data structure where
//                                   entries are loaded
//   @param (input) language: could be COBOL or RPG. COBOL supports "-" (dash) whereas
//                            RPG doesn't
// Example Call:
//   MDRT_BuildSchemaString('req':schemaEntry_Pointer:'COBOL');
// @info MDRTOOLS3
///=======================================================================================


dcl-pr MDRT_BuildSchemaString varchar(32766);
  schematype char(4) const;
  schemaEntry_ptr pointer value;
  language char(10) const;
end-pr;

///=======================================================================================
// MDRT_BuildCobolMember
//
// Generates COBOL member from the entries/variables loaded in "schemaEntryDetails"
// data structure
//
// Parameters:
//   @param (input) schemaEntry_Ptr: Address of the "schemaEntryDetails" data structure where
//                                   entries are loaded
//   @param (input) sourcemember: Name of the COBOL Source member to generate
//   @param (input) sourcefile: Source file where COBOL source member to be generated
//   @param (input) sourceLibrary: Library name where COBOL source member to be generated
//   @param (input) UUID: Unique Identifier
//   @param (input) multiuuid: Y-Append current definitions in existing member. N-Clear member
//                  and write current definitions
//   @param (input) hexformat: whether to generate the schema in hex format
//   @param (input) requestPath: IFS path of the JSON file containing request body structure
//   @param (input) responsePath: IFS path of the JSON file containing response structure
//   @param (input) reqSchemaString: hex/normal string for request schema in MDR-DATAINTO/GEN fmt
//   @param (input) rspSchemaString: hex/normal string for response schema in MDR-DATAINTO/GEN fmt
//   @param (input) referenceText: Reference text to be written in COBOL copybook
//   @param (output) Status: output parameter ("Y" - member generated, "N" - Error occurred)
//   @param (output) errorMsgId - output parameter returning the error message id for any error
//                  encountered while processing the request
//   @param (output) errorMsgData - message data for parameters in error message Id
//
// Example Call:
//   MDRT_BuildCobolMEmber(schemaEntry_Pointer:srcmember:srcfile:srcLibrary:uuid:
//      multiuuid:hexformat:requestPath:responsePath:reqSchemaString:
//      rspSchemaString:referenceText:status:errorMsgId:errorMsgDta);
// @info MDRTOOLS3
///=======================================================================================

dcl-pr MDRT_BuildCobolMember;
  schemaEntry_Ptr pointer;
  sourceMember char(10);
  sourcefile char(10);
  sourceLibrary char(10);
  uuid char(6);
  multiuuid char(1);
  hexformat char(1);
  requestPath varchar(5000:4);
  responsePath varchar(5000:4);
  reqschemaString varchar(32766:4);
  rspschemaString varchar(32766:4);
  referencetext varchar(100:4);
  status char(1);
  errorMsgId char(7);
  errorMsgDta varchar(500);
end-pr;
///=======================================================================================
// MDRT_EncodeHex
//
//   Converts the string into hex format
//
// Parameters:
//   @param (output) destinationStr: Target string where hex encoded string is returned
//   @param (input) sourcestr: Source String which is to be converted to hex format
//
// Example Call:
//   MDRT_EncodeHex(deststr:srcString);
// @info MDRTOOLS3
///=======================================================================================
dcl-pr MDRT_encodeHex;
  destinationstr varchar(500000:4) ;
  sourceStr varchar(250000:4);
end-pr;

///=======================================================================================
// MDRT_GEN_OAPI_Schema
//
// Generate OAPI schema from raw JSON string buffer or from an IFS file
//
// Parameters:
//   @param (input) handle : threadsafe handler key
//   @param (input) stmf: IFS/stream file containing raw JSON to be processed
//   @param (input) jsonString: String containing raw JSON to be processed
//   @param (output) errMsg: Error message(if any) during JSON parsing

//   @return OAPI schema
//
// Example Call: Either of the two calls below
//   SchemaString = MDRT_GEN_OAPI_Schema(handle:ifsfile:*omit:errormessage);
//   SchemaString = MDRT_GEN_OAPI_Schema(handle:*Omit:rawJson:errormessage);
// @info MDRTOOLS5
///=======================================================================================

dcl-pr MDRT_GEN_OAPI_Schema varchar(5242880:4);
  handle    like(MDR_Handle_t);
  stmf        varchar(5000:4)  const options(*varsize: *omit);
  JsonString  varchar(5242880:4) const options(*varsize:*omit);
  errMsg      varchar(4096:4)  options(*varsize:*omit);
end-pr;
///=======================================================================================
// mdrt_getEnvVar
//
// Retrieve the value of environment variable
//
//   @param (input) envVariable : Environment Variable whose value is to be returned
//
//   @return Value if the variable found, blank otherwise
// @info MDRTOOLS4
///=======================================================================================
dcl-pr mdrt_getEnvVar varchar(1024);
  envVariable varchar(256) value;
end-pr;

///=======================================================================================
// MDRT_getMemberInfo
//
// Retrieve source member information for the supplied parameters
// Currently, this function only returns the current number of records but it
// can be ammended to return other values too
//
//   @param (input) srcMember: Name of the source member to retrieve information for
//   @param (input) srcFile: source physical file name containing the source member
//   @param (input) srcLibrary: Name of the library where source member exists
//
//   @return Current number of records in source member
//
// Example Call:
//   numRecords = MDRT_GetMemberInfo(srcMember:srcFile:srcLibrary);
// @info MDRTOOLS4
///=======================================================================================
dcl-pr MDRT_getMemberInfo int(10);
  srcMember char(10) const;
  srcFile char(10) const;
  srcLibrary char(10) const;
end-pr;


///=======================================================================================
// arrayDimInf
//
// structure for array names
//
//   @param (input) arrayName : name of the array
//   @param (input) arrayDim : custom dimension
//   @param (input) arrayOvrFound: Specific to COBOL when array overridden
//   @param (input) i_arrayDimInf: count of array entries loaded in array
///=======================================================================================
dcl-ds arrayDiminf based(arrayDiminf_ptr);
  arrayname varchar(128) dim(20);
  arraydim uns(10) dim(20);
  arrayOvrFound ind dim(20);
  i_arrayDiminf int(5);
end-ds;

dcl-s arrayDiminf_ptr pointer;

///=======================================================================================
// MDRCBLCPY
//
// Prototype declaration for MDRCBLCPY program which generates COBOL copybook for the
// specified request and response JSON at the IFS
//
//   @param (input) requestPath - IFS path of JSON file containing request body structure
//   @param (input) responsePath- IFS path of JSON file containing response structure
//   @param (input) genName - Generated name
//   @param (input) genLibrary - Library name
//   @param (input) genSourceFile - Source File name
//   @param (input) uuid - Unique Threadsafe Identifier
//   @param (input) multiuuid - Y: Check if the supplied UUID section already found.
//                  If found, replace that UUID section with the new content, otherwise
//                  add new section for the supplied UUID. If the source member
//                  doesn't alreay exist, internally change this parameter to "N"
//                  N: Create the new source member (clear if it already exists) and
//                  write the UUID definition block
//   @param (input) hexformat - Y: Generate MDR-DATAGEN/DATAINTO string format for COBOL
//                  in hex
//                  N: Generate MDR-DATAGEN/DATAINTO string format in EBCDIC/plain text
//   @param (input) genSourcePath: Generation source path on the IFS (future provision)
//   @param (input) referenceText - Reference Text to be written in COBOL copybook
//   @param (input) dftDim - default dimension of array entries
//   @param (output) arrayOvrInf - data structure containing the names of arrays and
//                   their custom "dim"
//   @param (output) errorMsgId - output parameter returning the error message Id for any
//                  error encountered while processing the request
//   @param (output) errormsgData - Message data containing replacement parameters in
//                  error MsgId
///=======================================================================================

dcl-pr mdrcblcpy Extpgm('MDRCBLCPY');
  requestPath varchar(5000:4);
  responsePath varchar(5000:4);
  genName char(10);
  genLibrary char(10);
  genSourceFile char(10);
  uuid char(6);
  multiuuid char(1); // Y for multiple UUID per copy book- if UUID already
                     // exists Overwite with new generation, else append to end
  hexformat char(1);
  genSourcePath varchar(1024:4); // Future provision and not used currently
  referenceText varchar(100:4);
  dftdim int(10);
  ArrayOvrInf likeds(arrayDimInf);
  errorMsgId char(7);
  errorMsgData varchar(500);
end-pr;

// This is a data structure representation of a record from the SQL table
// called MDRDCFG
dcl-ds MDRDCFG_t ext extname('MDRDCFG') template qualified end-ds;

///=======================================================================================
//  MDR_logPartDS
//  data structure containing request and response info for logging
//  request: request URL, headers and body
//  response: response headers and body
///=======================================================================================
dcl-ds MDR_logPartDS qualified template;
  dcl-ds request;
    uri ind;
    headers ind;
    body ind;
  end-ds;
  dcl-ds response;
    headers ind;
    body ind;
  end-ds;
end-ds;
///=======================================================================================
// MDR_WriteToConfig
//
// write configurations
//
//   @param (input) rec - values to be inserted into the table
//
//   @return *on if successful, *off otherwise
// @info MDRTOOLS6
///=======================================================================================
dcl-pr MDR_WriteToConfig ind;
  rec likeds(MDRDCFG_t);
end-pr;

///=======================================================================================
// MDR_UpdateConfig
//
// Update configurations
//
//   @param (input) rec - values to overwrite the current record with the same root
//                  resource
//
//   @return *on if successful, *off otherwise
// @info MDRTOOLS6
///=======================================================================================
dcl-pr MDR_UpdateConfig ind;
  rec likeds(MDRDCFG_t);
end-pr;

///=======================================================================================
// MDR_DeleteConfig
//
// Delete configurations
//
//   @param (input) rootrsc - the root resource of the record to delete
//
//   @return *on if successful, *off otherwise
// @info MDRTOOLS6
///=======================================================================================
dcl-pr MDR_DeleteConfig ind;
  rootrsc varchar(2048) const;
end-pr;

///=======================================================================================
// MDR_findConfig
//
// search configuration
//   @param (input) rootrsc - the root resource of the record to find
//   @param (output) rec - the record if found
//
//   @return *on if successful, *off otherwise
// @info MDRTOOLS6
///=======================================================================================
dcl-pr MDR_findConfig ind;
  rootrsc varchar(2048) const;
  rec likeds(MDRDCFG_t);
end-pr;

///=======================================================================================
// MDR_getAllConfigs
//
// Get all configurations
//
//   @param (output) recs - the records from the table
//   @param (input) maxcount - the maximum number of records to return
//
//   @return the number of records put in recs
// @info MDRTOOLS6
///=======================================================================================
dcl-pr MDR_getAllConfigs int(10);
  recs likeds(MDRDCFG_t) dim(6000) options(*varsize);
  maxcount int(10) value;
end-pr;

///=======================================================================================
// MDR_indToYN
//
// Indicator conversion to Y/N
//
//   @param (input) myind - an indicator to convert
//
//   @return 'Y' or 'N'
// @info MDRTOOLS6
///=======================================================================================
dcl-pr MDR_indToYN char(1);
  myind ind const;
end-pr;

///=======================================================================================
// MDR_YNToInd
//
// return *ON or *Off for Y or N values
//
//   @param (input) ltr - (input) a letter to convert
//
//   @return *on if letter is 'Y' or 'y', *off otherwise
// @info MDRTOOLS6
///=======================================================================================
dcl-pr MDR_YNToInd ind;
  ltr char(1) const;
end-pr;

// MDRTOOLS7==============================================================================
/if defined(Plugin_Definitions)
  //======================================================================================
  //  We can write data to different sections (or "chunks")
  //  of source.  The chunks are written to disk in numeric order,
  //  in this example I have:
  //
  //     CH_HEAD       (constant 1) -- program heading
  //     CH_DCL        (constant 2) -- declares at global level
  //     CH_MAIN       (constant 3) -- mainline calcs
  //     CH_PROC       (constant 4) -- subprocedures.
  //     CH_PROCDFN    (constant 5) -- subprocedure definition
  //     CH_PROCVARDCL (constant 6) -- variable declaration within subprocedure
  //     CH_QRYHDRPARM (constant 7) -- query/header parameter declaration
  //     CH_PROCLOGIC  (constant 8) -- processing logic within subprocedure
  //     CH_ENDPROC    (constant 9) -- End of procedure
  //
  // In this case, there might be some stuff I want to add to
  // the top of the mainline calcs. I don't need to wait until I've
  // written all of the declarations, I can write them anywhere
  // since they're in a separate section.
  //

dcl-c CH_HEAD  1;
dcl-c CH_DCL   2;
dcl-c CH_MAIN  3;
dcl-c CH_PROC  4;
dcl-c CH_PROCDFN 5;
dcl-c CH_PROCVARDCL 6;
dcl-c CH_QRYHDRPARM 7;
dcl-c CH_PROCLOGIC 8;
dcl-c CH_ENDPROC 9;

// insert newline character in string being written in source statement
dcl-c NL   x'25';

///=======================================================================================
// MyHandle_t
// Template definition for thread handle commonly used in generators
//
// path = IFS Path
// srcf = Source File
// cpyf = Copybook Member
// errorMsg = Error Message
// paramzcount = number of query/header parameters
// paramz = query/header parameters
// dscount = data structure count
// dslist = names of data structures
// globalpath = global path (not in use)
// source = qualified path of source member
// object = qualified path of the object
// copybk = qualified path for the copybook
// extraoptions = Parameter for extra options
// extraopttype = entry type for extra options
// methChunkNum = chunk number1
// callType = callType handling
// callName = name of called procedure/program
// callLib = library of called program/procedure
// callPrcName = name of the procedure for *MODULE or *SRVPGM entry
//
///=======================================================================================

dcl-ds MyHandle_t qualified template;
  path varchar(4094);
  srcf pointer;
  cpyf pointer;
  errorMsg varchar(500);
  paramzcount int(10);
  paramz varchar(30) dim(99);
  dscount int(10);
  dslist varchar(30) dim(99);
  responsecount int(5);
  schemaPath varchar(1024) dim(99);
  globalpath varchar(4094);
  source varchar(4094);
  object varchar(4094);
  copybk varchar(4094);
  extraoptions varchar(500) dim(10);
  extraopttype varchar(10) dim(10);
  methChunkNum int(5) inz(0);
  callType varchar(10);
  callName varchar(10);
  callLib  varchar(10);
  callPrcName varchar(30);
end-ds;

// current stack of swagger elements with depth value
dcl-ds currentStack_t qualified;
  var varchar(80);
  depth int(5);
  array ind;
end-ds;

// Common variable used for blank padding
dcl-s blanks char(32768);

///=======================================================================================
//  MDRT_defineDS
//
//  This is called from request() and response() procedures to define
//  the variables in data structure corresponding to request body & response.
//
//    @param (input) cfg: plugin details and environment
//    @param (input) info: meta information from the Swagger doc
//    @param (input) opts: generation options from the swagger
//    @param (input) method: HTTP method to generate request for (get, post, put, etc)
//    @param (input) schemaType: type of schema to generate oneOf, anyOf, etc
//    @param (input) schemaCount: number of schemas supported for this request
//    @param (input) schema: array of schema names/paths
//    @param (input) entryFrom: "REQ" - called for request, "RSP" - called for response
//    @param (input/output) indexVars: array being maintained for index variables for array elements
//    @param (input/output) indexPath: array corresponding to "indexVars" for qualified path to find
//                          correct index variable name for array
//    @param (input/output) countIndexVars: number of elements in above two arrays
//    @param (input) chunkNumber: The chunk number to be used to group the source lines being
//                                written
//    @param (output) topLevelArray: set to *On if top level schema element is an array
//
//    @return MDRSDK_SUCCESS or MDRSDK_FAIL
// @info MDRTOOLS7
///=======================================================================================

dcl-pr MDRT_defineDS int(10);
  cfg             likeds(MDRSDK_plugin_t);
  info            likeds(MDRSDK_info_t)                const;
  opts            likeds(MDRSDK_options_t)             const;
  method          varchar(50)                          const;
  schemaType      varchar(10)                          const;
  schemaCount     int(10)                              const;
  schema          likeds(MDRSDK_schemaList_t) dim(500) const;
  entryFrom       char(3) const;
  indexVars       varchar(50) dim(99);
  indexPath       varchar(200) dim(99);
  countIndexVars  int(5);
  chunkNumber     int(5) const;
  topLevelArray   ind;
end-pr;

///=======================================================================================
// MDRT_defineJsonWorkVariables
//
//  This is called for each HTTP method that is found within this path
//  and defines the variables for internal use with DATA-GEN and buffer
//  for YAJL buffer retrieval
//
//    @param (input) cfg: plugin details and environment
//    @param (input) info: meta information from the Swagger doc
//    @param (input) opts: generation options from the swagger
//    @param (input) method: HTTP method to generate request for (get, post, put, etc)
//
//    @return MDRSDK_SUCCESS or MDRSDK_FAIL
// @info MDRTOOLS7
///=======================================================================================

dcl-pr MDRT_defineJsonWorkVariables int(10);
  cfg         likeds(MDRSDK_plugin_t);
  info        likeds(MDRSDK_info_t) const;
  opts        likeds(MDRSDK_options_t) const;
  method      varchar(50)           const;
end-pr;

///=======================================================================================
// MDRT_getVarType
//
// get variable type procedure for source for supplied numeric code
//
//   @param (input) code: numeric code corresponding to data type.
//
//   @return RPGLE data type
// @info MDRTOOLS7
///=======================================================================================

dcl-pr MDRT_getVarType varchar(20);
  code int(10) value;
end-pr;

///=======================================================================================
// MDRT_pad
//
// padding procedure for aligning variable definitions with data type
// keywords
//
//   @param (input) name: variable name to be written with blanks padded
//   @param (input) length: target length with blanks padding
//
//   @return padded statement string to be written to source member
// @info MDRTOOLS7
///=======================================================================================
dcl-pr MDRT_pad varchar(32764);
  name varchar(4096) const;
  length int(10) value;
end-pr;

///=======================================================================================
// MDRT_indent
//
// Procedure for source indenting source within conditional/looping
// blocks
//
//   @param (input) depth: number spaces to indent (add the blank spaces in source)
//
//   @return specified number of spaces for source indentation
// @info MDRTOOLS7
///=======================================================================================

dcl-pr MDRT_indent varchar(32764);
  depth int(10) value;
end-pr;
///=======================================================================================
// MDRT_SetEnvInfo
//
// Set Environemnt Variables
//
//   @param (input) env: environment pointer
// @info MDRTOOLS7
///=======================================================================================
dcl-pr MDRT_SetEnvInfo;
  env    like(MDRSDK_envp);
end-pr;

///=======================================================================================
// MDRT_RemoveSpecialChars
//
// Remove special characters from the JSON name to build an RPG name
//
//   @param (input) originalname - Received variable name coming from JSON
//
//   @return special characters replaced with equivalent characters
// @info MDRTOOLS7
///=======================================================================================

dcl-pr MDRT_RemoveSpecialChars varchar(100);
  originalName varchar(100) options(*varsize);
end-pr;

///=======================================================================================
// MDRT_writeJSONGenLogic
//
// This is called from "response" procedure for each HTTP method when
// the parsemethod is not "DATA-GEN". The procedure writes the response
// using YAJL functions.
//
//    @param (input) cfg: plugin details and environment
//    @param (input) info: meta information from the Swagger doc
//    @param (input) opts: generation options from the swagger
//    @param (input) method: HTTP method to generate request for
//    @param (input) schemaType: type of schema to generate oneOf, anyOf, etc
//    @param (input) schemaCount: number of schemas supported for this request
//    @param (input) schema: array of schema names/paths
//    @param (input) indexVars: array being maintained for index variables for array elements
//    @param (input) indexPath: array corresponding to "indexVars" for qualified path to find
//                   correct index variable name for array
//    @param (input) countIndexVars: number of elements in above two arrays
// @info MDRTOOLS7
///=======================================================================================

dcl-pr MDRT_writeJSONGenLogic;
  cfg         likeds(MDRSDK_plugin_t);
  info        likeds(MDRSDK_info_t) const;
  opts        likeds(MDRSDK_options_t) const;
  method      varchar(50)           const;
  schemaType  varchar(10)           const;
  schemaCount int(10)               const;
  schema      likeds(MDRSDK_schemaList_t) dim(500) const;
  indexVars varchar(50) dim(99);
  indexPath varchar(200) dim(99);
  countIndexVars int(5);
end-pr;

///=======================================================================================
// MDRT_writeJSONParseLogic
//
// Called from "request" procedure for each HTTP method when
// the parsemethod is not "DATA-INTO". The procedure loads the data
// structure using YAJL functions.
//
//   @param (input) cfg: plugin details and environment
//   @param (input) info: meta information from the Swagger doc
//   @param (input) opts: generation options from the swagger
//   @param (input) method: HTTP method to generate request for
//   @param (input) schemaType: type of schema to generate oneOf, anyOf, etc
//   @param (input) schemaCount: number of schemas supported for this request
//   @param (input) schema: array of schema names/paths
//   @param (input) indexVars: array being maintained for index variables for array elements
//   @param (input) indexPath: array corresponding to "indexVars" for qualified path to find
//                  correct index variable name for array
//   @param (input) countIndexVars: number of elements in above two arrays
// @info MDRTOOLS7
///=======================================================================================

dcl-pr MDRT_writeJSONParseLogic;
  cfg            likeds(MDRSDK_plugin_t);
  info           likeds(MDRSDK_info_t)                const;
  opts           likeds(MDRSDK_options_t)             const;
  method         varchar(50)                          const;
  schemaType     varchar(10)                          const;
  schemaCount    int(10)                              const;
  schema         likeds(MDRSDK_schemaList_t) dim(500) const;
  indexVars      varchar(50) dim(99);
  indexPath      varchar(200) dim(99);
  countIndexVars int(5);
end-pr;
///=======================================================================================
// MDRT_getLastName
//
// This procedure is called to extract the last name in schema path
//   @param (input) schemaPath: Path of the schema
//
//   @return last entry in the schema path
// @info MDRTOOLS7
///=======================================================================================

dcl-pr MDRT_getLastName varchar(100);
  schemaPath       varchar(1024) const options(*varsize);
end-pr;
///=======================================================================================
// MDRT_getSetParm
//
// This procedure is called to write the statement in API/consumer
// to get or set query/header parameters
//
//   @param (input) cfg: plugin details and environment
//   @parm (input) opts: generation options from the swagger
//   @parm (input) method: HTTP method to generate request for
//   @param (input) requestType: request Type (SET-Send as response,
//                   GET-Receive from request and load in variable)
//   @param (input) parmType: possible values "query" or "header"
//                   as the requested parameter type processing
//   @param (input) chunknum: chunk number
//
//   @return MDRSDK_SUCCESS or MDRSDK_FAIL
// @info MDRTOOLS7
///=======================================================================================

  dcl-pr MDRT_getSetParm int(10);
    cfg       likeds(MDRSDK_plugin_t);
    opts      likeds(MDRSDK_options_t) const;
    method    varchar(50)           const;
    requestType char(3) const;
    parmtype char(6) const;
    chunknum int(10) value;
  end-pr;

/endif
/if defined(SDKS_Definitions)
///=======================================================================================
// MDRT_validateUser
//
// Validate the user and send the error message if the user has not
// supplied the correct credentials.
//
//   @param (input) handle: context handle, identifies which MDRest4i
//                  session is currently running.
//   @param (input) authUser: the source VARCHAR4 string.
//   @param (output) authPwd: the source VARCHAR4 string.
// @info MDRTOOLS7
///=======================================================================================
  dcl-pr  MDRT_validateUser;
    handle        like(MDR_Handle_t);
    authUser      varchar(10:4);
    authPwd       varchar(2048:4);
  end-pr;
///=======================================================================================
// MDRT_CrtPAT
//
// Create the PAT token as per supplied length
//
//   @param (output) token: the source VARCHAR2 string.
//   @param (input)  tokenLen: the source PACKED decimal.
// @info MDRTOOLS7
///=======================================================================================
  dcl-pr  MDRT_CrtPAT;
    token         varchar(256);
    tokenLen      packed(3: 0);
  end-pr;

///=======================================================================================
// MDRT_crtToken
//
// Create the token as per supplied length
//
//   @param (output) result: the source VARCHAR2 string.
//   @param (input)  minlen: the source PACKED decimal.
// @info MDRTOOLS7
///=======================================================================================
  dcl-pr  MDRT_crtToken;
    result        varchar(256);
    minlen        packed(3: 0);
  end-pr;

///=======================================================================================
// MDRT_GetToken
//
// Create the PAT token as per supplied length
//
//   @param (input) handle: context handle, identifies which MDRest4i
//                  session is currently running.
//   @param (input) method: HTTP method.
//   @param (input/output) tokenval: Token value.
//   @param (input) type: processing type (OAPI, USER, PAGE).
//
//   @return *on if error, otherwise it will be *off.
// @info MDRTOOLS7
///=======================================================================================
dcl-pr  MDRT_GetToken ind;
  handle    like(MDR_Handle_t);
  method    char(32) const;
  tokenval  varchar(32);
  type      varchar(4) const;
end-pr;
/endif
///=======================================================================================
// MDRT_initVariants
//
// Initialization of Variant Characters values for multi-CCSID usage where hard coded
// variant characters are used in compilable programs
// @info MDRTOOLS7
///=======================================================================================
dcl-pr MDRT_initVariants;
end-pr;
///=======================================================================================
// Workfields used for Variant Character assignment in programs and MDRT_initVariants
Dcl-S mdrt_OpenCurly   Char(1);
Dcl-S mdrt_CloseCurly  Char(1);
Dcl-S mdrt_OpenSquare  Char(1);
Dcl-S mdrt_CloseSquare Char(1);
Dcl-S mdrt_EscapeChar  Char(1);
Dcl-S mdrt_Power       Char(1);
Dcl-S mdrt_Tilde       Char(1);
Dcl-S mdrt_Exclaim     Char(1);
Dcl-S mdrt_Hash        Char(1);
Dcl-S mdrt_Pipe        Char(1);
Dcl-S mdrt_Accent      Char(1);
Dcl-S mdrt_Dollar      Char(1);
Dcl-S mdrt_AtSign      Char(1);
// Variant character assignment with UNICODE values
dcl-c C_OpenCurly     u'007B';
dcl-c C_CloseCurly    u'007D';
dcl-c C_OpenSquare    u'005B';
dcl-c C_CloseSquare   u'005D';
dcl-c C_EscapeChar    u'005C';
dcl-c C_Power         u'005E';
dcl-c C_Tilde         u'007E';
dcl-c C_Exclaim       u'0021';
dcl-c C_Hash          u'0023';
dcl-c C_Pipe          u'007C';
dcl-c C_Accent        u'0060';
dcl-c C_Dollar        u'0024';
dcl-c C_AtSign        u'0040';
///=======================================================================================
// MDRT_locationInfo
//
// Provides root IFS folder and IFS folder to use
//   @param (output) library: MDREST4I Library (MDRST....)
//   @param (output) rootIFSPath: MDREST4I root IFS path
//   @param (output) instFolder: instance folder name (default, T14, ...)
///=======================================================================================
Dcl-Pr MDRT_locationInfo ExtPgm('MRLOCINF');
  library       char(10);
  rootIFSPath   char(20);
  instFolder    char(7);
end-pr;
///=======================================================================================
// MDRT_SDKRootInfo
//
// Provides root IFS folder to use for the SDK Web UI
//   @param (output) sdkroot: IFS folder for the SDK Web UI
///=======================================================================================
Dcl-Pr MDRT_SDKRootInfo ExtPgm('MDRSDKROOT');
  sdkroot       char(100);
end-pr;
///=======================================================================================
// MDRT_ValueVRM
//
// Provides version of the IBM i operating system
//   @param (output) OSversion: IBM i OS version i (V7R2M0, V7R3M0...)
///=======================================================================================
Dcl-Pr MDRT_ValueVRM ExtPgm('MDRVALVRM');
  OSVersion       char(6);
end-pr;