midrange.com code scratchpad |
Name:
Simple Base64 example
|
Scriptlanguage:
Plain Text
|
Tabwidth:
4
|
Date:
12/12/2013 09:17:00 pm
|
IP:
Logged
|
|
Description:
Decoding Base64 from an XML element.
|
Code:
- /copy qrpgsrc,umedheader
- /copy qrpgsrc,httpapi_h
- /copy qrpgsrc,ifsio_h
- /copy qrpgsrc,base64_h
- D Response s 256a
- D DecodedResp s 256a
- D Incoming PR
- D userdata * value
- D depth 10I 0 value
- D name 1024A varying const
- D path 24576A varying const
- D value 65535A varying const
- D Attrs * dim(32767)
- D const options(*varsize)
-
- /free
- Response = '/kevin/testb64.xml';
- DecodedResp = '/kevin/testb64.txt';
- http_parse_xml_stmf( Response
- : HTTP_XML_CALC
- : *null
- : %paddr(Incoming)
- : *null );
- *Inlr = *on;
- Return;
- /end-free
-
- P Incoming B
- D Incoming PI
- D userdata * value
- D depth 10I 0 value
- D name 1024A varying const
- D path 24576A varying const
- D value 65535A varying const
- D attrs * dim(32767)
- D const options(*varsize)
-
- D count s 10I 0
- D attrname s 1024A varying
- D attrval s 65535A varying
- D incval s 32766A varying
- D fourbytes s 4A
- D decbuf s 3a
- D declen s 10i 0
- D outhandle s 10i 0
- /free
- If name = 'Response';
- outhandle = open(%trim(DecodedResp)
- : O_CREAT + O_EXCL + O_WRONLY
- + O_TEXTDATA + O_TEXT_CREAT + O_CCSID
- : S_IRUSR + S_IWUSR
- : 1208
- : 0);
- If outhandle = -1;
- dsply 'Open out failed';
- EndIf;
-
- incval = value;
- dow %len(incval) > 0;
- fourbytes = %subst(incval:1:4);
- If %len(incval) > 4;
- incval = %subst(incval:5);
- Else;
- incval = '';
- EndIf;
- declen = base64_decode(%addr(fourbytes):4
- :%addr(decbuf):3);
- http_xlatep(declen:%addr(decbuf):TO_EBCDIC);
- callp write(outhandle:%addr(decbuf):declen);
- EndDo;
- callp close(outhandle);
- EndIf;
-
- /end-free
- P E
-
-
-
- ************* XML file from /kevin/testb64.xml
- <?xml version="1.0" encoding="iso-8859-1" ?>
- <Body>
- <Response>U2NvdHQgS2xlbWVudCB3cml0ZXMgc29tZSBncmVhdCBzb2Z0d2FyZSE=</Response>
- </Body>
|
|
|