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

Re: HTTP_get_url_raw



Sender: Scott Klement <klemscot@xxxxxxxxxxxx>


Hi Dirk,

I'm going to send a copy of my response to the FTPAPI mailing list (which
is used for both FTPAPI and HTTPAPI) so that other people can learn from
the answers to your questions.

> We are trying your HTTPAPI program, and we are looking for an example of
> HTTP_get_url_raw. This procedure has 3 parameters, the first one is the
> url, the third is a pointer of a procedure, but the second we can't
> determine what that is.

It's just a number which is passed back to your procedure.   If you did
this:

        http_url_get_raw('http://foo.com/bar.html': 5: %paddr('MYPROC'))

then each time the procedure called MYPROC is called, it will be passed
the number 5 as the first argument to the procedure.   That's all it
does, HTTPAPI does not use the number for anything.

It's convienient for passing a file descriptor when you're writing the
result to a stream file.

>
> Please can you send me an example of this API?
>

Sure...   Here's a sample program which downloads my socket tutorial to
your IFS using the http_url_get_raw() routine:


      *
      *  Example of using the http_url_get_raw() routine to receive
      *  data from a web server, and display how many bytes have
      *  been transferred
      *
     H DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('LIBHTTP/HTTPAPI': 'QC2LE')

     D/copy libhttp/qrpglesrc,httpapi_h
     D/copy libhttp/qrpglesrc,ifsio_h
     D/copy libhttp/qrpglesrc,errno_h

     D save_to_disk    PR            10I 0
     D   peFD                        10I 0 value
     D   peData                        *   value
     D   peLen                       10I 0 value

     D fd              s             10I 0
     D rc              s             10I 0
     D msg             s             52A
     D Bytes           s             16P 0

     c                   eval      *inlr = *on

     C* Open a stream file
     c                   eval      fd = open('/sock_tutorial.pdf':
     c                                      O_WRONLY+O_TRUNC+O_CREAT: 511)
     c                   if        fd < 0
     c                   eval      msg = %str(strerror(errno))
     c                   dsply                   msg
     c                   return
     c                   endif

     C* Retrieve Scott Klement's sockets tutorial:

     c                   eval      rc = http_url_get_raw(
     c                             'http://www.scottklement.com/rpg/' +
     c                             'socktut/tutorial.pdf': FD:
     c                              %paddr('SAVE_TO_DISK'))

     c                   if        rc <> 1
     c                   eval      msg = http_error
     c                   dsply                   msg
     c                   endif


      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      *   This is called by the HTTP_url_get_raw() API each time
      *   data is received from the HTTP server.
      *
      *   We use it to show the user how many bytes have been
      *   received, and then we write the received data to disk.
      *
      *   Parameters:
      *        peFD = number that we passed to HTTP_url_get_raw().
      *               (We use the file descriptor that we got when
      *                we opened the stream file that we're saving to)
      *      peData = pointer to the data that was received from http
      *                server.
      *       peLen = length of data received
      *
      *   we return the length we received from HTTPAPI if successful
      *     or -1 if we can't write the data to disk.
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P save_to_disk    B
     D save_to_disk    PI            10I 0
     D   peFD                        10I 0 value
     D   peData                        *   value
     D   peLen                       10I 0 value

     D QMHSNDPM        PR                  ExtPgm('QMHSNDPM')
     D   MessageID                    7A   Const
     D   QualMsgF                    20A   Const
     D   MsgData                    256A   Const
     D   MsgDtaLen                   10I 0 Const
     D   MsgType                     10A   Const
     D   CallStkEnt                  10A   Const
     D   CallStkCnt                  10I 0 Const
     D   MessageKey                   4A
     D   ErrorCode                32766A   options(*varsize)

     D dsEC            DS
     D  dsECBytesP             1      4I 0 inz(0)
     D  dsECBytesA             5      8I 0 inz(0)

     D wwMsgKey        S              4A
     D wwText          s            100A   varying

     c                   eval      Bytes = Bytes + peLen
     c                   eval      wwText = %trim(%editc(Bytes:'P')) +
     c                                ' bytes received'

     c                   callp     QMHSNDPM('CPF9897': 'QCPFMSG   *LIBL':
     c                               wwText: %len(wwText): '*STATUS':
     c                               '*EXT': 0: wwMsgKey: dsEC)

     c                   if        write(peFd: peData: peLen) < 1
     c                   return    -1
     c                   endif

     c                   return    peLen
     P                 E


      /define ERRNO_LOAD_PROCEDURE
      /copy libhttp/qrpglesrc,errno_h
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubsribe from the list send mail
to majordomo@xxxxxxxxxxxxx with the body: unsubscribe ftpapi mymailaddr
-----------------------------------------------------------------------