×

Good News Everybody!

The new search engine is LIVE!

Please report any problems to david (at) midrange.com.




Thanks again everyone especially Scott and Charles

Will try both of these methods and also look into what profile is being used
for cgi jobs.

Jim Horn


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


message: 1
date: Tue, 19 Dec 2006 12:06:23 -0600 (CST)
from: Scott Klement <rpg400-l@xxxxxxxxxxxxxxxx>
subject: Re: calling a program from ws or web


I'm trying to have 1 program to respond to requests from a ws session or
from the web(cgi-bin).  How can you tell which way the program was called
(ws session or web) so you can respond appropriately?

I'm not sure what a "ws session" is.  Web service?  Workstation?

If you mean workstation, you can check the REQUEST_METHOD environment 
variable.  IF it's not set, it's a workstation session.  If it's set, it's 
called via CGI (or a regular program that's deliberately trying 
to look like it's calling via CGI, which is often done when testing CGI 
code.)

Here's a proof of concept:

      H DFTACTGRP(*NO) ACTGRP('TEST') BNDDIR('QC2LE')

       *
       *  I use the following (by preference) instead of QtmhGetEnv
       *  (but QtmhGetEnv() would've also worked)
      D getenv          PR              *   extproc('getenv')
      D   varname                       *   value options(*string)

       *
       *  I use the following (by preference) instead of QtmhWrStout
       *  (but QtmhWrStout would've also worked)
      D stdout          s               *   import('_C_IFS_stdout')
      D fputs           PR            10I 0 ExtProc('_C_IFS_fputs')
      D   string                        *   value options(*string)
      D   stream                        *   value
      D fflush          PR            10U 0 ExtProc('_C_IFS_fflush')
      D   stream                        *   value

      D ptr             s               *
      D reqmeth         s             10A   varying
      D data            s            500A   varying
      D wait            s              1A

       /free

           ptr = getenv('REQUEST_METHOD');
           if (ptr = *NULL);
              DSPLY ('Not a CGI job!') ' ' wait;
           else;
              reqmeth = %str(ptr);

              data = 'Content-type: text/html' + x'0d250d25';
              fputs(data: stdout);

              data = '<html><body><h1>'
                   + 'This is a CGI program called with the ' + reqmeth
                   + ' request method.' + '</h1></body></html>' +x'0d25';

              fputs(data: stdout);
              fflush(stdout);
           endif;

           return;
       /end-free

If you meant "web service" rather than workstation, the solution is 
somewhat similar.  Read an environment variable again, but this time look 
for the CONTENT_TYPE variable.  If it's set to text/xml, then it has sent 
you an XML document (and therefore is likely a webservice) if it sends 
Application/x-www-form-urlencoded, then it's a regular web page (HTML 
form).





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

message: 3
date: Tue, 19 Dec 2006 13:19:02 -0500
from: "Wilt, Charles" <CWilt@xxxxxxxxxxxx>
subject: RE: calling a program from ws or web

Jim,

Quick and dirty method would be to check that the job user in position
254-263 of the PSDS      ( as opposed to the current user in position
358-367 ) is QTMHHTP1 (and/or QTMHHTTP?)

Assuming of course the system is running CGI jobs with the default
settings for the user profile to use for CGI jobs.

Charles Wilt
--

iSeries Systems Administrator / Developer
Mitsubishi Electric Automotive America
ph: 513-573-4343
fax: 513-398-1121
  



As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2026 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.