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

RE: Base64 Decoding/Raw vs. Post



I got that from somewhere, can't remember but thought from Scott K's website.  Here is the copy member to include if you want to use it.  They are from IBM so probably documented in the Info Center.

/if defined(APR_BASE64_H)                                                          
 /eof                                                                               
 /endif                                                                             
 /define APR_BASE64_H                                                               
                                                                                    
  // APR_B64_H --  Include file with definitions for the Base64 routines            
  //               included with the Apache Portable Runtime (APR)                  
  //                                                                                
  //               On IBM i, this is shipped in the QSYSDIR/QAXIS10HT               
  //               service program, which is part of 57xx-SS1 option 3              
  //               (57xx-SS1, opt3 = Extended Base Directory Support)               
                                                                                    
  //  APU_DECLARE(int) apr_base64_encode_len(int len);                              
  //  APU_DECLARE(int) apr_base64_encode(char * coded_dst, const char *plain_src,   
  //                                   int len_plain_src);                          
  //  APU_DECLARE(int) apr_base64_encode_binary(char * coded_dst,                   
  //                                          const unsigned char *plain_src,       
  //                                          int len_plain_src);                   
  //  APU_DECLARE(int) apr_base64_decode_len(const char * coded_src);               
  //  APU_DECLARE(int) apr_base64_decode(char * plain_dst, const char *coded_src);  
  //  APU_DECLARE(int) apr_base64_decode_binary(unsigned char * plain_dst,          
  //                                         const char *coded_src);                
                                                                           
D apr_base64_encode_len...                                                 
D                 pr            10i 0 extproc('apr_base64_encode_len')     
D  len                          10i 0 value                                
                                                                           
D apr_base64_encode...                                                     
D                 pr            10i 0 extproc('apr_base64_encode')         
D  encoded_dst               65535a   options(*varsize)                    
D  plain_src                      *   value options(*string)               
D  source_len                   10i 0 value                                
                                                                           
D apr_base64_encode_binary...                                              
D                 pr            10i 0 extproc('apr_base64_encode_binary')  
D  coded_dst                 65535a   options(*varsize)                    
D  plain_src                 65535a   options(*varsize) const              
D  source_len                   10i 0 value                                
                                                                           
D apr_base64_decode_len...                                                 
D                 pr            10i 0 extproc('apr_base64_decode_len')     
D  source_plain                   *   value options(*string)               
                                                                           
D apr_base64_decode...                                                     
D                 pr            10i 0 extproc('apr_base64_decode')         
D  plain_dst                 65535a   options(*varsize)                    
D  coded_src                      *   value options(*string)                
                                                                            
D apr_base64_decode_binary...                                               
D                 pr            10i 0 extproc('apr_base64_decode_binary')   
D  plain_dst                 65535a   options(*varsize)                     
D  coded_src                      *   value options(*string)                                                                                                    

Scott


-----Original Message-----
From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Michael Ryan
Sent: Wednesday, April 22, 2015 12:46 PM
To: HTTPAPI and FTPAPI Projects
Subject: Re: Base64 Decoding/Raw vs. Post

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 < 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: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:
> 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 < 
> 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: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:
> > 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 < 
> > 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: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:
> > > 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:
> > > 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
> ----------------------------------------------------------------------
> -
>
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------