Last active
March 20, 2022 17:59
-
-
Save RainerRoss/281091a59d2d0d5e44ae7385a93dc837 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//------------------------------------------------------------------// | |
// Create JSON-Status // | |
//------------------------------------------------------------------// | |
dcl-pr crtJSONStatus char(270) ccsid(*utf8) rtnparm; | |
PiSuccess varchar(05) const; | |
PiErrmsg char(256) const; | |
end-pr; | |
//------------------------------------------------------------------// | |
// Send JSON to HTTP-Server // | |
//------------------------------------------------------------------// | |
dcl-pr sendJSON; | |
PiData_p pointer value; // Data-Pointer | |
PiLength uns(10) const; // Data-Length | |
end-pr; | |
//------------------------------------------------------------------// | |
// Create Hash // | |
//------------------------------------------------------------------// | |
dcl-pr crtHash char(128); // Result Hexstring | |
PiString_p pointer const; // String-Pointer | |
PiLength uns(10) const; // String-Length | |
PiHashAlg int(10) const; // HashAlgorithm | |
end-pr; | |
//------------------------------------------------------------------// | |
// Check Session // | |
//------------------------------------------------------------------// | |
dcl-pr checkSession varchar(256) rtnparm; | |
PiUserId like(DsSession.Userid) const; | |
PiType like(DsSession.Type) const; | |
PiSessionId like(DsSession.SessionId) const; | |
end-pr; | |
//------------------------------------------------------------------// | |
// Decode Image Data // | |
//------------------------------------------------------------------// | |
dcl-pr decodeImageData; | |
PiData_p pointer const; | |
end-pr; | |
//------------------------------------------------------------------// | |
// Write Image to IFS // | |
//------------------------------------------------------------------// | |
dcl-pr writeImageToIFS; | |
PiData_p pointer const; | |
end-pr; | |
//------------------------------------------------------------------// | |
// Array Files // | |
//------------------------------------------------------------------// | |
dcl-ds DsSession extname('SESSIONS00') qualified template end-ds; | |
//------------------------------------------------------------------// | |
// Variables // | |
//------------------------------------------------------------------// | |
dcl-s GblStatus SQLType(CLOB:270) ccsid(*utf8); | |
dcl-s GblSecret varchar(256); | |
//------------------------------------------------------------------// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ctl-opt nomain alloc(*teraspace); | |
//------------------------------------------------------------------// | |
// Prototypes // | |
//------------------------------------------------------------------// | |
/copy webutl/qcpysrc,webutl | |
/copy webutl/qcpysrc,status | |
/copy webutl/qcpysrc,base64 | |
/copy webutl/qcpysrc,ifs | |
/copy webutl/qcpysrc,dsimage | |
/copy webutl/qcpysrc,calchash | |
/copy webutl/qcpysrc,apierr | |
/copy comutl/qcpysrc,comutl | |
//------------------------------------------------------------------// | |
// Create JSON-Status // | |
//------------------------------------------------------------------// | |
dcl-proc crtJSONStatus export; | |
dcl-pi *n like(LocResult) rtnparm; | |
PiSuccess like(DsStatus.Success) const; | |
PiErrmsg like(DsStatus.Errmsg) const; | |
end-pi; | |
dcl-s LocResult char(270) ccsid(*utf8); | |
exec sql | |
values JSON_OBJECT( | |
'success' value trim(:PiSuccess) Format JSON, | |
'errmsg' value trim(:PiErrmsg) | |
) | |
into :LocResult; | |
return LocResult; | |
end-proc; | |
//------------------------------------------------------------------// | |
// Send JSON to HTTP-Server // | |
//------------------------------------------------------------------// | |
dcl-proc sendJSON export; | |
dcl-pi *n; | |
PiData_p pointer value; // Data-Pointer | |
PiLength uns(10) const; // Data-Length | |
end-pi; | |
dcl-s LocHeader like(GblHeader); | |
LocHeader = getHeader(JSON); // Get HTTP-Header | |
sndHttp(%addr(LocHeader:*data):%len(LocHeader):DsApierr); | |
if PiData_p <> *null and PiLength > *zero; | |
sndHttp(PiData_p:PiLength:DsApierr); | |
endif; | |
end-proc; | |
//------------------------------------------------------------------// | |
// Create Hash // | |
//------------------------------------------------------------------// | |
dcl-proc crtHash export; | |
dcl-pi *n like(LocHex); // Result Hexstring | |
PiString_p pointer const; // String-Pointer | |
PiLength uns(10) const; // String-Length | |
PiHashAlg int(10) const; // HashAlgorithm | |
end-pi; | |
dcl-s LocBin char(64); // Binary | |
dcl-s LocHex char(128); // Hex | |
dcl-s LocLen uns(10); // Length | |
DsAlg.HashAlg = PiHashAlg; // Algorithm | |
calcHash(PiString_p:PiLength:GblDatfmt:DsAlg: | |
GblAlgfmt:'0':*omit:LocBin:DsApierr); | |
cvthc(LocHex:LocBin:%len(%trimr(LocBin)) * 2); // Binary to Hex | |
LocHex = %xlate(UpChar:LowChar:LocHex); // upper -> lower | |
return LocHex; // Result | |
end-proc; | |
//------------------------------------------------------------------// | |
// Check Session // | |
//------------------------------------------------------------------// | |
dcl-proc checkSession export; | |
dcl-pi *n varchar(256) rtnparm; | |
PiUserId like(PsSession.Userid) const; | |
PiType like(PsSession.Type) const; | |
PiSessionId like(PsSession.SessionId) const; | |
end-pi; | |
dcl-ds PsSession extname('SESSIONS00') template qualified end-ds; | |
dcl-s LocUserId like(PsSession.UserId); | |
select; | |
when PiUserId = *zero; | |
return 'UserId is zero'; | |
when PiSessionId = *blanks; | |
return 'SessionId is blank'; | |
endsl; | |
exec sql | |
select UserId | |
into :LocUserId | |
from SESSIONS00 | |
where UserId = :PiUserId | |
and Type = :PiType | |
and SessionId = :PiSessionId; | |
select; | |
when sqlcode = *zero; // found = ok | |
return *blanks; | |
when sqlcode > *zero and sqlcode = 100; // not found | |
return 'UserId and SessionId not valid - ' + | |
'SQLCode: ' + %char(sqlcode); | |
endsl; | |
end-proc; | |
//------------------------------------------------------------------// | |
// Decode Image Data // | |
// The Base64-Image Data has the following format // | |
// 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAA...' // | |
// - Extract the Data beginning at comma // | |
// - Decode the Base64-Data to JPG // | |
//------------------------------------------------------------------// | |
dcl-proc decodeImageData export; | |
dcl-pi *n; | |
PiData_p pointer const; | |
end-pi; | |
dcl-ds PsImage Likeds(DsImage) based (PiData_p); | |
PsImage.Dec_p = %alloc(PsImage.Data_Len); | |
PsImage.Dec_Len = decBase64Bin(PsImage.Dec_p:PsImage.Data_p); | |
if PsImage.Dec_Len > *zero; // Decoded-Length | |
writeImageToIFS(PiData_p); | |
endif; | |
end-proc; | |
//------------------------------------------------------------------// | |
// Write Image to IFS // | |
//------------------------------------------------------------------// | |
dcl-proc writeImageToIFS export; | |
dcl-pi *n; | |
PiData_p pointer const; | |
end-pi; | |
dcl-ds PsImage Likeds(DsImage) based (PiData_p); | |
dcl-s LocFlags like(GblFlags); // IFS-Flags | |
dcl-s LocAuth like(GblAuth); // IFS-Authority | |
dcl-s LocFd like(GblFd); // File-Descriptior | |
dcl-s LocStmf like(GblStmf); // Streamfile | |
LocFlags = o#rdwr + o#creat + o#ccsid + // IFS-Flags | |
o#textdata + o#textcreat; | |
LocAuth = s#irwxu + s#irgrp + s#iroth; // IFS-Authority | |
LocStmf = PsImage.Dir + PsImage.File; // Streamfile | |
LocFd = open(LocStmf:LocFlags:LocAuth:1208:1208); | |
if LocFd >= *zero; // no Error | |
callp write(LocFd:PsImage.Dec_p:PsImage.Dec_Len); | |
callp close(LocFd); | |
endif; | |
end-proc; | |
//------------------------------------------------------------------// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment