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

RE: Hit to use Iconv in sending Big5 Chinese Character through httpapi



   Dear Sc


   I just find it is as simple as to change two default values in
   CONFIG_H and re-run INSTALL will do.

   No need to use those http_setCCSIDs(), HTTP_url_encoder_new(),
   HTTP_url_encoder_addvar,.. as those are used in HTTP_url_get()


   [CONFIG_H]

   D*HTTP_EBCDIC     C                   CONST(0)

   D*HTTP_ASCII      C                   CONST(819)

   D HTTP_EBCDIC     C                   CONST(937)

   D HTTP_ASCII      C                   CONST(950)


   Actually, may be just change the HTTP_ASCII will do as HTTP_EBCDIC
   depends on the running job.


   Best Regards

   --------------------------------------

   Dear Scott,


   I try to use Iconv(), as below [Coding], it work for me

   The input value  ' 我 ' is equal to x'0E4F5C0F' and return as x'A7DA'
   as expected (0E and 0F Shift I/O is removed automatically)


   Could you update you code such that '%' is not need as '%A7%DA' ?


   When setting up the parameter URL in http_url_get(), we just type
   'http://.....'  in AS400

   And your code can translate all from EBCDIC to ASCII for english.

   For example, in sending english character 'ABCD' (EBCDIC with
   x'C1C2C3C4') your can send as x'41424344' and we just do nothing.

   URL = 'http://...&msg=ABCD'


   Can you do the same as Big 5?

   ie. the URL = 'http://....&msg= 我 ...'     OR  URL =
   'http://....&msg=x'0E4F5C0F'


   [Coding]

   HDEBUG(*YES)

   HDFTACTGRP(*NO)

   HBNDDIR('QC2LE')

    *  Prototype DS

   D QtqCode_T       DS                  Qualified

   D  CCSID                        10I 0 Inz(0)

   D  CvtAlt                       10I 0 Inz(0)

   D  SubAlt                       10I 0 Inz(0)

   D  ShiftState                   10I 0 Inz(1)

   D  InLenOpt                     10I 0 Inz(0)

    ** some pgm use value 1 for MixDataErrOpt

   D  MixDataErrOpt                10I 0 Inz(0)

   D  Reserved                      8A   Inz(*ALLX'00')

    *

   D iconv_t         DS                  Qualified INZ

   D  rtn_value                    10I
   0

   D  cd                           10I 0
   Dim(12)

    * To create a conversion environment, we need to call QtqIconvOpen.
   The following prototype allows

    * QtqIconvOpen to be called from RPG
   IV:

   D QtqIConvOpen    PR
   ExtProc('QtqIconvOpen')

   D
   LikeDS(iconv_T)

   D  toCCSID
   LikeDS(QtqCode_T)

   D  fromCCSID
   LikeDS(QtqCode_T)

    * The QtqIconvOpen API uses the following data structure to create
   the conversion environment:

   D iconv           PR            10U 0
   ExtProc('iconv')

   D  hConv                              LikeDS(iconv_t)
   VALUE

   D  pInBuff                        *   VALUE

   D  nInLen                         *
   VALUE

   D  pOutBuff                       *
   VALUE

   D  nOutLen                        *
   VALUE

    *  iconv_close clear memory after
   used

   D iconv_close     PR            10I 0
   ExtProc('iconv_close')

   D  hConv                              LikeDS(iconv_t)
   VALUE

    * Calling QtqIconvOpen to establish/create the conversion environment
   to convert from the job's

    * CCSID to ASCII used on the IFS, we would use the following
   code:

   D fromCCSID       DS
   LikeDS(QtqCode_T)

   D                                     Inz(*LIKEDS)

   D toCCSID         DS
   LikeDS(QtqCode_T)

   D
   Inz(*LIKEDS)

   D hConv           DS
   LikeDS(iconv_T)

   D
   Inz(*LIKEDS)

    * Input Value

   D MyData          S
   10A

   D pData           S
   *

   D ppData          S               *
   Inz(%addr(pData))

   D nInLen          S             10I 0

    * Output value

   D OutData         S             10A

   D pOutData        S               *

   D ppOutData       S               *   Inz(%addr(pOutData))

   D nOutLen         S             10I 0

    *

    * MI function to get a hex dump of data in memory

    *   (target will be twice the size of the source)

   D HexDump         PR                  ExtProc('cvthc')

   D   target                   32767A   options(*varsize)

   D   src_bits                 32767A   options(*varsize) const

   D   length                      10I 0 value

    * At double of MyData above

   D HexData         S             20A

   D nReturn         S             10U 0

   D w1DspMsg        S             52A

    *

    * Use Chinse Char x'0E4F5C0F'

   C                   Eval      MyData = ' |* '

    * if above data and CCSID from 0 to 937, 950

    * HexValue in EBCDIC :
   0E4F5C0F

    * HexValue in ASCII  : A7DA with Shift In/Out (0E, 0F)
   removed

   C                   eval      fromCCSID.CCSID =
   937

   C                   Eval      toCCSID.CCSID =
   950

   C                   Eval      hConv =
   *ALLX'00'

   C                   Eval      hConv =
   QtqIconvOpen(toCCSID:fromCCSID)

    *  Handle
   error

   C                   if        hConv.rtn_value  =
   -1

   C     '0001'        DUMP

   C                   Eval      w1DspMsg  = 'QtqIconvOpen
   Error'

   c                   dsply
   w1DspMsg

   C                   Endif

    *

   C                   eval      nInLen =
   %len(%TrimR(mydata))

   C                   eval      nOutLen =
   %size(mydata)

   C                   eval      pData =
   %addr(myData)

    * Create hex dump to Check before
   conversion

   c                   callp     HexDump(
   HexData

   c                                    :
   myData

   c                                    : %size(HexData))

   c                   dsply                   HexData

    * run Iconv() for xlate

   C                   eval      pOutData = %addr(OutData)

   C                   Eval      nReturn =  iconv(hConv : ppData

   C                                     : %addr(nInLen)

   C                                     : ppOutData:%addr(nOutLen))

    *  Handle error

   C                   If        nReturn = -1

   C     '0003'        DUMP

   C                   Endif

    * Create hex dump to Check after conversion,

   c                   callp     HexDump( HexData

   c                                    : OutData

   c                                    : %size(HexData))

   c                   dsply                   HexData

    * Close the iconv, clear memory

   C                   callp     iconv_close(hConv)

    * Clear the conversion handle just for good measure

   C                   eval      hConv = *ALLX'00'

   C                   Eval      *INLR = *On

   C                   Return







   Best Regards


   ---------------------------------------------------

   From Hang-Lam CHAN

       Senior Manager  (MCSE, MCDBA, CCNA, OCA)

       Systems Engineering Service

   mailto:hl.chan@xxxxxxxxxxx

    ---------------------------------------------------

   CISD (ASIA) CO., LTD

   Progressing Hand-in-Hand with our Customer  !


   TEL: (852) 3199-1411     FAX: (852) 2865-4689

   URL:  http://www.cisd.com.hk

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