[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Ftpapi] Need to understand how decode from Base64 to Ascii



Hi Luca,

Unfortunately, I don't have time to write an example for you.   I asked you previously for more information about your scenario, but you weren't able to provide any technical information (you provided a lot of background information, but nothing technical that you hadn't already said.)  So even if I did make time to write an example, it may be very different from what you actually need to do.

Here is what I would do, in pseudocode:

1.  Use http_XmlReturnPtr() to enable HTTPAPI to pass back XML data using pointers so that size is not an issue.

2. Use http_parse_xml_stmf() to read your XML file from the IFS. The handler that processes end elements will be passed a pointer with all of the base64-encoded data.

3. Given the input size passed to your handler, calculate what the decoded size would be.  Then allocate enough memory for the base64 decoded size to a pointer.

4. call base64_decode -- it can decode the whole thing in one call, there's no need for a loop.

5. Use the open, write, and close APIs to write it to disk.  The data should already be ASCII, so do not use O_TEXTDATA, just write it in binary mode.  You'll want to use O_CCSID to assign the proper CCSID to the file.  (Note that "ASCII" is unspecific, it is a whole family of encodings.  You'll want to know the specific encoding (iso-8859-1 is 819, windows latin-1 is 1252, there are many others) and set the CCSID appropriately.

6. Don't forget to free up the memory you allocated.


That's pretty much it... it's very simple.  No translation should be needed, since this base64 encoded data is ALREADY in ASCII. You are creating a lot of extra steps (and places where something can go wrong) by translating it.  Also calling base64_decode in a loop is creating extra complexity.

-SK


On 6/20/2018 7:08 AM, Luca Giammattei wrote:
Il 19/06/2018 23:43, Scott Klement ha scritto:
Hi Luca,

I also don't understand why this works, it seems like it should not, and is not the way that I would do it.

Scott, if you find time to write, I'd really appreciate to know how you would have dealt with the problem. Not the code, of course, simply the logical steps you would have followed, I am always eager to learn and compare.

Briefly summarize: the aim is to have a ascii file on the IFS, available to be processed by an RPG program and a windows based one. The file is contained in a tag of an xml file, a string of encoded characters Base64 whose length is not known before being processed.

Thanks in advance for your consideration.


--
_______________________________________________
Ftpapi mailing list
Ftpapi@xxxxxxxxxxxxxxxxxxxxxx
http://scottklement.com/mailman/listinfo/ftpapi