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

Re: Base64 Decoding/Raw vs. Post



Mike,

"APR" is the Apache Portable Runtime. IBM has included some of the Apache Portable Runtime (including the APR base64 encode/decode routines) along with some of the tools in IBM i. (I think this first appeared when they started offering web services, but I could be wrong... I know it hasn't been around as long as the HTTP server has been.)

Anyway, the apr_base64_decode should work fine. It's not documented by IBM, but I stumbled on it one day when I was looking around the system (I don't remember what I was looking for at the time) and wrote an article about it. So you can use that if you want.

The base64_decode() routine is one that I wrote. My routine is open source, pure RPG, and has been available on the platform longer. But, it might be a hassle to have to install the extra software if IBM has apr_base64_decode already included in the OS. So, I guess it's up to you.

I don't know how big your files are -- but 65535 seems a bit small for an entire PDF to me. If this is embedded in XML, I would turn on pointer support, so that HTTPAPI uses dynamic pointer allocation and gives you all the data in one big buffer. Then I would dynamically allocate another buffer (you can calculate the size off of the one you get from HTTPAPI) to decode the base64 into. Then write the whole she-bang to the IFS, and free up the pointers.

Just my 2 cents.


On 4/22/2015 1:46 PM, Michael Ryan wrote:
    Cool. Thanks. What's the difference between apr_base64_decode and
    base64_decode? I see you're passing two parameters instead of four.

    On Wed, Apr 22, 2015 at 2:15 PM, Scott Mildenberger
    <[1]SMildenberger@xxxxxxxxxxxxxxxxxx> wrote:

      Correct, HOSLog3 is the last element of the message I receive and I
      need the attributes from it to decide where I save the PDF file.�
      � To answer your next question, yes those are globals and are
      defined as
      �  �  � d PDFData�  �  �  �  � s�  �  �  �  �  65535
      �  �  � d TmpValue�  �  �  �  s�  �  �  �  �  65535�  �  � varying
      Scott
      -----Original Message-----
      From: [2]ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
      [mailto:[3]ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of
      Michael Ryan

    Sent: Wednesday, April 22, 2015 11:09 AM
    To: HTTPAPI and FTPAPI Projects
    Subject: Re: Base64 Decoding/Raw vs. Post
    Oh! Ok...I get it. You've already captured the value of PDFData and
    TmpValue, but you write the file when you get the HOSLog3 element. I
    assume that follows the PDFData element, right?
    And HTTPAPI converts tag and attribute names to EBCDIC when we use
    http_url_post_xml, right?
    On Wed, Apr 22, 2015 at 12:57 PM, Scott Mildenberger <
    [4]SMildenberger@xxxxxxxxxxxxxxxxxx> wrote:
    > No it is in an element called 'PDFData' - there is a when where I
    save
    > the value there.�  I wait until I receive the HOSLog3 element before
    I
    > decode and write the pdf file to the IFS.�  The loop inside HOSLog3
    for
    > the attributes is just collecting other info I need but is not
    related
    > to getting and saving the PDF file.
    >
    > Scott
    >
    >
    > -----Original Message-----
    > From: [5]ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:
    > [6]ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Michael Ryan
    > Sent: Wednesday, April 22, 2015 10:48 AM
    > To: HTTPAPI and FTPAPI Projects
    > Subject: Re: Base64 Decoding/Raw vs. Post
    >
    > Thanks Scott! Just what I needed! I take it the PDF file is in an
    > attribute and not an element, right?
    >
    > On Wed, Apr 22, 2015 at 12:40 PM, Scott Mildenberger <
    > [7]SMildenberger@xxxxxxxxxxxxxxxxxx> wrote:
    >
    > > I use http_url_post_xml() to receive a pdf file that is Base64
    encoded.
    > > Below is my incoming() procedure.�  In the tag PDFData is the
    Base64
    > > encoded data and I decode and write it out to an IFS file when I
    > > receive the tag HOSLog3.�  Let me know if you have questions on
    > > anything
    > I am doing here.
    > >
    > >�  �  �  P Incoming�  �  �  �  B
    > >�  �  �  D Incoming�  �  �  �  PI
    > >�  �  �  D�  � LoadId�  �  �  �  �  �  �  �  �  �  �  10i 0
    > >�  �  �  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 Program�  �  �  �  � c�  �  �  �  �  �  �  �  �
    � 'UTILS/XUSERMSG'
    > >
    > >�  �  �  D attrname�  �  �  �  s�  �  �  �  �  � 1024A�  � varying
    > >�  �  �  D attrval�  �  �  �  � s�  �  �  �  �  65535A�  � varying
    > >�  �  �  d BigMsg�  �  �  �  �  s�  �  �  �  �  �  512
    > >�  �  �  D count�  �  �  �  �  � s�  �  �  �  �  �  � 10I 0
    > >�  �  �  d Filename�  �  �  �  s�  �  �  �  �  �  100�  �  varying
    > >�  �  �  d Msg�  �  �  �  �  �  � s�  �  �  �  �  �  � 50
    > >�  �  �  d retlen�  �  �  �  �  s�  �  �  �  �  �  � 10i 0
    > >�  �  �  d TimeString�  �  �  s�  �  �  �  �  �  � 26
    > >�  �  �  d User�  �  �  �  �  �  s�  �  �  �  �  �  � 10
    > >
    > >�  �  �  D atoi�  �  �  �  �  �  PR�  �  �  �  �  �  10i 0
    extproc('atoi')
    > >�  �  �  D�  � string�  �  �  �  �  �  �  �  �  �  �  �  *�  � value
    options(*string)
    > >
    > >
    > >�  �  �  � /free
    > >�  �  �  �  �  //Msg = 'In:' + name;
    > >�  �  �  �  �  //dsply Msg 'SCOTT';
    > >�  �  �  �  �  //Msg = 'Value:' + value;
    > >�  �  �  �  �  //dsply Msg 'SCOTT';
    > >�  �  �  �  �  select;
    > >�  �  �  �  �  �  when name = 'HOSLog3';
    > >�  �  �  �  �  �  �  count = 1;
    > >�  �  �  �  �  �  �  dow http_nextXmlAttr(attrs: count: attrname:
    attrval);
    > >�  �  �  �  �  �  �  �  select;
    > >�  �  �  �  �  �  �  �  �  when (attrname = 'id');
    > >�  �  �  �  �  �  �  �  �  �  //Msg = 'ID=' + attrval;
    > >�  �  �  �  �  �  �  �  �  �  //dsply Msg 'SCOTT';
    > >�  �  �  �  �  �  �  �  �  �  LastIndex = %int(%trim(attrval));
    > >�  �  �  �  �  �  �  �  �  when (attrname = 'date');
    > >�  �  �  �  �  �  �  �  �  �  LogDate = %date(%trim(attrval) :
    *ISO);
    > >�  �  �  �  �  �  �  �  endsl;
    > >�  �  �  �  �  �  �  enddo;
    > >
    > >�  �  �  �  �  �  �  //�  Base64 decode the pdf
    > >�  �  �  �  �  �  �  retlen = apr_base64_decode(PDFData : TmpValue);
    > >
    > >�  �  �  �  �  �  �  //�  Create directory for this truck if it
    doesn't exist.
    > >�  �  �  �  �  �  �  Filename = '/home/Driver Logs/' + Truck;
    > >�  �  �  �  �  �  �  if syscall('crtdir dir(''' + Filename + ''')' :
    > > 'CPFA0A0') <> '';
    > >�  �  �  �  �  �  �  �  //�  Send error message
    > >�  �  �  �  �  �  �  �  dsply ('Error creating log directory for ' +
    Truck)
    > 'SCOTT';
    > >�  �  �  �  �  �  �  �  return;
    > >�  �  �  �  �  �  �  endif;
    > >
    > >�  �  �  �  �  �  �  //�  Store PDFData to an ifs file.
    > >�  �  �  �  �  �  �  Filename += '/Log' + %char(LogDate : *ISO0) +
    '.pdf';
    > >�  �  �  �  �  �  �  unlink(Filename);
    > >�  �  �  �  �  �  �  fd = open(Filename :
    > >�  �  �  �  �  �  �  �  �  �  �  �  O_WRONLY+O_CREAT+O_CODEPAGE:
    > >�  �  �  �  �  �  �  �  �  �  �  �  S_IRUSR + S_IWUSR + S_IXUSR
    > >�  �  �  �  �  �  �  �  �  �  �  �  + S_IRGRP + S_IXGRP
    > >�  �  �  �  �  �  �  �  �  �  �  �  + S_IROTH + S_IXOTH : 819);
    > >�  �  �  �  �  �  �  if fd < 0;
    > >�  �  �  �  �  �  �  �  EscErrno(errno);
    > >�  �  �  �  �  �  �  �  dsply ('RANDRTVLOG Write PDF Error: ' +
    %char(errno))
    > > 'SCOTT';
    > >�  �  �  �  �  �  �  endif;
    > >
    > >
    > >�  �  �  �  �  �  �  if write(fd: %addr(PDFData): retlen) < retlen;
    > >�  �  �  �  �  �  �  �  err = errno;
    > >�  �  �  �  �  �  �  �  callp close(fd);
    > >�  �  �  �  �  �  �  �  EscErrno(err);
    > >�  �  �  �  �  �  �  endif;
    > >
    > >�  �  �  �  �  �  �  callp close(fd);
    > >
    > >�  �  �  �  �  �  when name = 'Vehicle';
    > >�  �  �  �  �  �  �  Truck = %trim(value);
    > >
    > >�  �  �  �  �  �  when name = 'PDFData';
    > >�  �  �  �  �  �  �  PDFData = value;
    > >�  �  �  �  �  �  �  TmpValue = %subst(PDFData : 1 : %len(value));
    > >
    > >�  �  �  �  �  �  when name = 'TotalRecordCount';
    > >�  �  �  �  �  �  �  QueueDepth = %int(%trim(value));
    > >
    > >�  �  �  �  �  endsl;
    > >
    > >�  �  �  � /end-free
    > >�  �  �  P�  �  �  �  �  �  �  �  � E
    > >
    > >
    > > Scott
    > >
    > > -----Original Message-----
    > > From: [8]ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:
    > > [9]ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Michael Ryan
    > > Sent: Wednesday, April 22, 2015 10:08 AM
    > > To: HTTPAPI and FTPAPI Projects
    > > Subject: Base64 Decoding/Raw vs. Post
    > >
    > > Ok...I need to receive a Base64 document in an XML tag. I'm
    > > currently using http_url_post_raw and converting to EBCDIC, but
    > > that's not going to work, is it? Dumb question: if I use
    > > http_url_post_xml to get the
    > > Base64 data, that will still be in binary, right? And then I can
    > > decode it and write it to a file, right?
    > >
    > > Anyone have an example? Thanks!
    > >
    --------------------------------------------------------------------
    > > --
    > > - This is the FTPAPI mailing list.�  To unsubscribe, please go to:
    > > [10]http://www.scottklement.com/mailman/listinfo/ftpapi
    > >
    --------------------------------------------------------------------
    > > --
    > > -
    > >
    >
    ----------------------------------------------------------------------
    > - This is the FTPAPI mailing list.�  To unsubscribe, please go to:
    > [11]http://www.scottklement.com/mailman/listinfo/ftpapi
    >
    ----------------------------------------------------------------------
    > -
    >
    -----------------------------------------------------------------------
    This is the FTPAPI mailing list.�  To unsubscribe, please go to:
    [12]http://www.scottklement.com/mailman/listinfo/ftpapi
    -----------------------------------------------------------------------

References

    1. mailto:SMildenberger@xxxxxxxxxxxxxxxxxx
    2. mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
    3. mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
    4. mailto:SMildenberger@xxxxxxxxxxxxxxxxxx
    5. mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
    6. mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
    7. mailto:SMildenberger@xxxxxxxxxxxxxxxxxx
    8. mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
    9. mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
   10. http://www.scottklement.com/mailman/listinfo/ftpapi
   11. http://www.scottklement.com/mailman/listinfo/ftpapi
   12. http://www.scottklement.com/mailman/listinfo/ftpapi



-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------

-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------