C/C++
The following C/C++ interface is provided to facilitate exploitation of CBXP by C/C++ callers.
The C/C++ interface for CBXP downloaded from GitHub.
The CBXP PAX provides a Static Library for CBXP at
/lib/libcbxp.aand a C Header for CBXP at/include/cbxp.h. To compile code that uses the C/C++ interface for CBXP, Include/include/cbxp.hat Compile Time and Link with/lib/libcbxp.a.
When compiling and linking C/C++ code with
/lib/libcbxp.a, it is recommended to use IBM Open XL C/C++ 2.2 or newer. See Binary Compatibility for more details.
cbxp()
cbxp_result_t* cbxp(const char* control_block, const char* includes_string,
const char* filters_string, bool debug);
📄 Description
includes_stringandfilters_stringare Optional Parameters that can be excluded by specifyingNULLornullptr.
Extract Control Blocks from Live Memory (storage) and post-process them into JSON.
📥 Parameters
-
control_block
A NULL-Terminated ISO8859-1 Encoded String that contains name of the Control Block to extract. -
includes_string
A NULL-Terminated ISO8859-1 Encoded String that contains a Comma Delimited List of Include Patterns that describe Additional Control Blocks to include that are accessible from the Root Control Block being extracted. -
filters_string
A NULL-Terminated ISO8859-1 Encoded String that contains a Comma Delimited List of Filters that are used to filter the entries returned in Repeated control block data. -
debug
A Boolean that if set totrueindicates that Debug Messages should be printed. If set tofalse, no Debug Messages will be printed.
📤 Returns
cbxp_result_t*
A pointer to acbxp_result_tC Struct.
cbxp_free()
void cbxp_free(cbxp_result_t* cbxp_result, bool debug);
📄 Description
The
cbxp_result_tpointer and theresult_jsonpointer within thecbxp_result_tC Struct it points to are no longer valid after callingcbxp_free(). Using these pointers after callingcbxp_free()will result in Undefined Behavior sincecbxp_free()frees the memory that both of these pointer point to.
Free all Dynamically Allocated Memory associated with a cbxp_result_t pointer returned by cbxp().
📥 Parameters
-
cbxp_result
A pointer to acbxp_result_tC Struct. -
debug
A Boolean that if set totrueindicates that Debug Messages should be printed. If set tofalse, no Debug Messages will be printed.
📤 Returns
void
This function does not return anything.
cbxp_result_t
typedef struct {
char* result_json;
int result_json_length;
int return_code;
} cbxp_result_t;
📄 Description
The C Struct that is used to store all Result Information returned by CBXP.
📋 Fields
-
result_json
When the call tocbxp()is Successful, this field contains pointer to a NULL-Terminated ISO8859-1 Encoded JSON String. When the call tocbxp()is Unsucessful, this field contains a NULL Pointer. -
result_json_length
When the call tocbxp()is Successful, this field contains the length of the NULL-Terminated ISO8859-1 Encoded JSON String stored in theresult_jsonfield. When the call tocbxp()is Unsuccessful, this field contains0. -
return_code
This field will be set bycbxp()to one of the following values:- ✅
0
The call tocbxp()was Successful. - ❌
1
The call tocbxp()was Unsuccessful due to an Unknown Control Block being specified with thecontrol_blockparameter. - ❌
2
The call tocbxp()was Unsuccessful due to a bad Include Pattern being specified within theincludes_stringparameter. - ❌
3
The call tocbxp()was Unsuccessful due to a bad Filter being specified within thefilters_stringparameter.
- ✅
💻 Examples
The following examples assume that the CBXP PAX is extracted in the Current Working Directory.
. |-- cbxp-0.0.3 | |-- LICENSE | |-- NOTICES | |-- bin | | `-- cbxp | |-- include | | `-- cbxp.h | `-- lib | `-- libcbxp.a |-- cbxp-0.0.3.pax.Z |-- main.c |-- main.cpp
The following C example extracts the PSA control block and prints the returned JSON String.
C
#include <cbxp.h>
#include <stdbool.h>
#include <stdio.h>
int main() {
// Call CBXP
puts("Calling CBXP from C...");
cbxp_result_t* cbxp_result = cbxp("psa", NULL, NULL, false);
// Make sure call was successful
if (cbxp_result->return_code != 0) {
fprintf(stderr, "Error: CBXP return with RC=%d\n", cbxp_result->return_code);
// Print Result JSON
} else {
puts(cbxp_result->result_json);
}
// Cleanup
cbxp_free(cbxp_result, false);
return 0;
}
Shell
# Compile
ibm-clang64 -c -fzos-le-char-mode=ascii -I./cbxp-0.0.3/include -o main.o main.c
# Link
ibm-clang++64 -fzos-le-char-mode=ascii -o main ./cbxp-0.0.3/lib/libcbxp.a main.o
# Run
./main
The following C++ example extracts the PSA control block and prints the returned JSON String.
C++
#include <iostream>
#include <cbxp.h>
int main() {
// Call CBXP
std::cout << "Calling CBXP from C++..." << std::endl;
cbxp_result_t * cbxp_result = cbxp("psa", nullptr, nullptr, false);
// Make sure call was successful
if (cbxp_result->return_code != 0) {
std::cerr << "Error: CBXP returned with RC=" << cbxp_result->return_code << std::endl;
// Print result JSON
} else {
std::cout << cbxp_result->result_json << std::endl;
}
// Cleanup
cbxp_free(cbxp_result, false);
return 0;
}
Shell
# Compile
ibm-clang++64 -c -fzos-le-char-mode=ascii -I./cbxp-0.0.3/include -o main.o main.cpp
# Link
ibm-clang++64 -fzos-le-char-mode=ascii -o main ./cbxp-0.0.3/lib/libcbxp.a main.o
# Run
./main