Announcement

Collapse
No announcement yet.

PBCC XML CGI Internet

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PBCC XML CGI Internet

    Can the PBCC compiler be used in an Internet setting other than CGI. Since ThinBasic is more like a script engine can it be used.

    I'm looking at using XML as the database since my customers don't produce more than 50,000 records in any table. Has anyone done this.

    Bob Mechler

  • #2
    ???

    CGI is a type of program for Internet access which can be produced with PB/CC .. or PB/Windows, or Microsoft Visual Anything, or COBOL or FORTRAN.

    XML is a data format; it can be handled using PB/CC... .. or PB/Windows, or Microsoft Visual Anything, or COBOL or FORTRAN.

    Internet Access is accomplished thru various Windows API functions which can be called from PB/CC.. or PB/Windows, or Microsoft Visual Anything, or COBOL or FORTRAN.

    I know there are examples of XML-handling here, both "long way" (PB string functions and REGEXPR) and via the COM interface provided by the MSXML libraries; and I know there are examples of internet access here (mostly "download a file/web page" and variations thereof).

    I think we need a little better description of the application to make any usable specific suggestions.

    MCM
    Last edited by Michael Mattias; 28 Dec 2007, 10:58 AM.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Originally posted by BOB MECHLER View Post
      Can the PBCC compiler be used in an Internet setting other than CGI.
      You can write an entire web server in PB if you want (there are at least three examples in these forums), but given today's security issues, I wouldn't go there.

      I'm looking at using XML as the database since my customers don't produce more than 50,000 records in any table.
      Many web sites are designed around XML, as it is very easy to transform into HTML for browsers, VXML for voice response systems, WML for cellphones, etc. all from the same source data. However, the XML is typically transient, the result of a dynamic query from a database. The data is normally stored in a DBMS. XML isn't generally used as the database itself, because it's not very storage efficient, and data insertion/deletion is cumbersome, at best, without a specialized XML database.

      While PB is a great language for many things, you're probably better off using a language specifically designed for the web when building web sites. Most any web hosting service these days has PHP up and running with MySQL databases, and you'll find thousands and thousands of pages of documentation, and a multitude of examples showing how to do anything and everything you may want to do in PHP. Notice that this BBS is written in PHP, and probably has a MySQL database behind it.
      --pdf

      Comment


      • #4
        >CGI is a type of program for Internet access which can be produced with PB/CC .. or PB/Windows, or Microsoft Visual Anything, or COBOL or FORTRAN.

        I don't think it's possible nativly using PB/WIN, CGI requires the stdout and i suspect a console must be present (As PE type for the webserver).
        Not sure though.
        hellobasic

        Comment


        • #5
          hmmm, Bob

          not sure what you mean by an Internet setting?

          xml is just a format, a standard to use for describing data that is transfered between client and server, ie, see,


          http://w3schools.com/xml/note.xml

          in that example you can create any kind of tag you wish, just as long as it also has a closing tag,

          so then you can use your receiving program (client) to find & identify the enclosed data by finding the tags,

          if your program is in a standard web browser, you can use a rss or atom reader to display the xml, or you can write your own reader using javascript, or you can even use PBWin or PBCC to read & display the xml file thru a custom program you write to run on the pc,

          but, all of that is overkill, if all you want is to read & present data from the server, in that case use cgi on the server,

          xml is just a standard so different web based applications can read files from outside sources in a standard way.

          you (IMO) would never want to store data in xml, the tags use to much space, you would rather build the xml on the fly using the data of interest,
          (make sense?)

          so you would want some sort of database which is not xml,

          which can be your own custom written one, or a standardized one like MySQL

          is that helping?

          Comment


          • #6
            I'd like to use an Ajax framework to get asynchronous updating of a page. I've seen some apps like VisualWebGui by Gizmox that offer WinForms from a website instead of the ASP.NET look and feel but they require Visual Studio 2005 or higher, IIS and adding a new extension to the Application Mappings.

            I find ASP.NET just too much to learn and everything I read is too elemental to produce a real app.

            I have PBCC and have done just a little programming where there is a startup page that accepts a login and then from there POST sends data to the STDIN that I would then parse and pump a new page back to the site using STDOUT. If that is only way I can work with PBCC and the Web then so be it.

            I guess I could use some tool to layout pages that look decent and then just capture the html with 'View Source', modify them as needed for the variables and pump it back to the site. I'd also need a session variable to differentiate between different users. I guess I could use a GUIDTXT$ function for that.

            It would just be easier if I could find an app that dealt with several XML tables, screens, one to many, drop downs controls, grids etc. I've tried to reverse engineer a ASP.NET/VB.NET app this way but since I don't know VB.NET/ASP.NET that well, it's been real frustrating.

            I'll just have to buckle down and get some experience in javascript, etc.

            Bob Mechler

            Comment


            • #7
              Don't think of XML being part of any webservice.

              The PB/CC app receives the input as you mentioned and you simply use the XML objects to load and save stuff.
              Personally i think XML itself is a poor choice when you need to deal with multiple users on the same xml-file(s).

              If it's a simple POST and store situation a cgi prob. works fine.
              We had some poor experiances with CGI though, it dependend on the webserver settings and memory.
              This was years ago and we barely use CGI any longer.
              We use ASP.NET.

              At first it does not seem you need something like that but i do expect you getting issues of instability, which is of course not related to PB/CC itself.
              Let's wait..
              hellobasic

              Comment


              • #8
                >I'd also need a session variable to differentiate between different users. I guess I could use a GUIDTXT$ function for that.

                Hmm, i lost you there.
                Afaik, a webserver provides the sessionid and also maintains any memory for this session.
                A CGI app is called and exitting right away.
                And i suspect it's hard to maintain memory between client and user (http is a stateless protocol).
                + you are right to distinct different users but prob. not different sessions like a single user having two browsers in use?

                This is always an issue you should solve differently or accept some conflicts (which usually never happen since it's more like a worse case scenario)

                A mega-benefit in ASP.NET is the viewstate, in this perspective i mean nothing more than hidden input(s) holding data to uniquely identify a user.
                (As far this remains possible)

                In ASP.NET you can use this.ViewState.Add("MyCustomValue", 1);
                On next post you can obtain this value again.
                With ordinary internet programming you'll have to substitute the viewstate for hidden input field if you wish to do the same, pretty daunting job each time.
                hellobasic

                Comment


                • #9
                  I don't think it's possible nativly using PB/WIN, CGI requires the stdout and i suspect a console must be present (As PE type for the webserver).
                  I think you're right. While you can AllocConsole() in your non-console program to get a STDIN STDOUT and STDERR, a regular "GUI" program does not have a STDIN when it starts . I think.. and I think CGI programs need to have STDIN just to get the ball rolling.

                  Then again, when any program is started it can inherit the parent program's standard handles. I'm not sure how CGI programs run. I think I will have to look at the samples provided to figure that out.

                  This might be fun to test, but I am working on something else today.
                  Last edited by Michael Mattias; 28 Dec 2007, 01:37 PM.
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    Hmm, maybe it is possible after all, the webserver will create the handles.
                    Not sure if it needs to have a console..

                    Not certain anymore.
                    hellobasic

                    Comment


                    • #11
                      Originally posted by BOB MECHLER View Post
                      Can the PBCC compiler be used in an Internet setting other than CGI. Since ThinBasic is more like a script engine can it be used. I'm looking at using XML as the database since my customers don't produce more than 50,000 records in any table. Has anyone done this.
                      Bob: I, like the others I believe, are not really sure what it is you want to accomplish. I have written many web sites that incorporate PB CGIs to make some pages "dynamic". The process is solid (never had a stability issue with a CGI in my life) and fairly simple to do. My current project incorporates small javascripts to enable some 'ajax' capabilities. Most of these components were obtained "pre-written" by doing a google search. Its not terribly difficult to add 'ajax' technologies into a web site using PB CGIs on the server. In fact, I've duplicated the function of several PHP sites using PB CGIs where my programs were faster, far more secure, and took a lot less time to load.

                      Is there something specific you are trying to interface with, or is the idea of CGI just a bit foreign? Perhaps if you could embellish a bit more on what your needs are for this, I could give you some additional ideas.
                      Software makes Hardware Happen

                      Comment


                      • #12
                        Hmm, maybe it is possible after all, the webserver will create the handles.
                        Not sure if it needs to have a console..
                        Easy enough to test... write a program with PB/WIN...
                        Code:
                        #INCLUDE "win32api.inc"
                        FUNCTION PbMain() AS LONG
                        
                         LOCAL h AS LONG
                        
                         h = GetStdHandle (%STD_INPUT_HANDLE) 
                        
                         MSGBOX  IIF$ (h=0 or h = -1&, "No STDIN", "We have a STDIN"), _
                             %MB_ICONINFORMATION, "STDIN Status" 
                        
                        END FUNCTION
                        Call from web server just like you'd call a CGI.

                        MCM
                        Michael Mattias
                        Tal Systems (retired)
                        Port Washington WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          Here is a very simple example of where I was trying to go about a year ago. I had a PB programming running as a service and doing silly things like looping and sleeping a short time (task manager showed 0% processor usage) while seeing if a piece of data was put into a defined directory. When the file showed up it took an account number from the dropbox directory and used a full blown PB/WIN program to open files using Btrieve api and gather the information on the customer and put it in another drop-box directory. Meanwhile the page that posted originally went into a similar loop state until the data was in it's receive directory and then a new page was posted back to the web with the data generated by the PB program running as a service. (Simulated Web Service). I was really trying to get a very simple feel for accessing all the power of PB while substituting the GUI with WEB pages.

                          Why did I use a drop-box and not the real program to get the data as a DLL. Well, the Web Site simply wouldn't give permission for the Btrieve API to run. I had no choice but to separate the programs and use this silly drop-box idea.
                          At the time I couldn't figure this out.

                          As you can see Joe, I started with your helpful example and went from there.

                          Code:
                          'contact.bas -- CGI application for CGI Programming Example 1
                          '
                          'See the HTML form counterpart AT www.pbcgi.v990.com
                          '
                          '© 2005 ccSolutions, written by Joe Byrne
                          '˜All code and text are free to use and distribute so long as all credits remain IN tact.
                          
                          #COMPILE EXE "C:\INETPUB\WWWROOT\CGI-BIN\CONTACT.EXE"
                          #INCLUDE "pbcgiboth.inc"
                          FUNCTION PBMAIN() AS LONG
                              LOCAL buffer    AS STRING
                              LOCAL FormAccount  AS STRING
                              LOCAL FormMktDate AS STRING
                              LOCAL FormPath AS STRING
                              LOCAL Message   AS STRING
                              LOCAL BtnText   AS STRING
                              DIM CSORT AS STRING
                              DIM MKTDATE AS STRING
                              DIM FD AS STRING
                              DIM MKTVAL AS DOUBLE
                              'CSORT = "0100054": MKTDATE = "01012006": FD = "C:\FILES\CTRU\"
                              'CALL marketval(CSORT,MKTDATE,FD,MKTVAL) 'This code wasn't allowed to run from a DLL although it worked fine with a standard pbwin pg calling it.
                              MKTVAL = 0
                              '--- Get the data from the Form ---         'Data passed to us as one string via STDIN.
                                                                              'The data is encoded as name=value pairs
                              buffer   = READCGI                          'All field names and data
                          
                              FormAccount   = CGIPARAM(buffer,"Account")        'Data from the 'Name' field
                              FormMktDate  = CGIPARAM(buffer,"MKTDATE")       'Data from the 'email' field
                              FormPath  = CGIPARAM(buffer,"DATAPATH")       'Data from the 'phone' field
                              IF VAL(FormAccount) > 0 THEN
                                CSORT = TRIM$(FormAccount)
                              END IF
                              IF VAL(FormMktDate) > 0 THEN
                                MKTDATE = TRIM$(FormMktDate)
                              END IF
                              IF LEN(TRIM$(FormPath)) > 0 THEN
                                FD = TRIM$(FormPath)
                              END IF
                          
                              OPEN "C:\CTRU\" + CSORT + ".DAT" FOR OUTPUT AS #1 'unique name based on the account number.
                                PRINT#1,CSORT        'account number to gather market value for
                                PRINT#1,MKTDATE    'as of date
                                PRINT#1,FD             'data directory
                                PRINT#1,MKTVAL      'not sure now why I sent this variable. Only needed the one coming back.
                              CLOSE 1
                              '
                              DO                           'Loop waiting for the return information. Always returned with the Market Value in 1 to 3 seconds.
                                IF DIR$("C:\CTRU\" + CSORT + ".TXT") <> "" THEN
                                  OPEN "C:\CTRU\" + CSORT + ".TXT" FOR INPUT AS #1
                                    LINE INPUT #1,M$
                                    MKTVAL# = VAL(M$)
                                  CLOSE 1
                                  EXIT LOOP
                                END IF
                                SLEEP 100
                                INCR I&
                              LOOP
                              KILL "C:\CTRU\" + CSORT + ".TXT"
                          
                              '---Note: Proper case for each parameter (name,email,phone,message & Button) is required.
                          
                              '---At this point, we can do anything with the data that we want.
                              '   For this example, we will just spit it back out to the user
                          WRITECGI "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"">"
                          WRITECGI "<html>"
                          WRITECGI "<head><style type=""text/css"">"
                          WRITECGI "<!--"
                          WRITECGI "body,td,th {"
                          WRITECGI "  font-family: Tahoma, Verdana;"
                          WRITECGI "  font-size: medium;"
                          WRITECGI "'}"
                          '
                          WRITECGI "'-->"
                          WRITECGI "</style>"
                          WRITECGI "  <title>Market Value</title>"
                          WRITECGI "</head>"
                          '
                          WRITECGI "<form action=""/cgi-bin/CONTACT.EXE"" method=""post""name=""Backdated Market Value"">"
                          WRITECGI "<fieldset><legend>Lookup Market Value by date</legend><P>"
                          WRITECGI "<label>Account :</label><input type=""text""name=""Account"" value=" + CSORT$ + " size=""7""maxlength=""7""readonly  tabindex=""1"">"
                          WRITECGI "<label>As of date:</label><input type=""text"" name=""MKTDATE"" value=" + MKTDATE + " size=""10"" maxlength=""10"" readonly tabindex=""2"">"
                          WRITECGI "<label>Market value:</label><input type=""text"" name=""MarketValue"" value=" + USING$("#######.##",MKTVAL#) + " size=""18"" maxlength=""18"" readonly tabindex=""3"">"
                          WRITECGI "'</fieldset></form>"
                          WRITECGI "<label>Press the back button</label>"
                          WRITECGI "<body bgcolor=""#FFFFCC"">"
                          '
                          WRITECGI "</body>"
                          WRITECGI "</html>"
                          
                          END FUNCTION
                          Code to provide STDIN and STDOUT for PB/WIN
                          Code:
                          'PBCGIBOTH.INC   Replacement for PBCGI.INC  to work with PBCC or PBWIN 4/6/2004
                          'Note:  STDIN LINE replacement is webdataStdIn by Dave N  used in ReadCGI "POST"
                          DECLARE FUNCTION webdataStdIn() AS STRING '11/1/2004 not in win32api.inc
                          '#IF NOT %DEF(%WINAPI) 'modified 4/13/04 Mike Doty
                          #IF %DEF(%PB_WIN32) 'modified 4/13/04
                             #INCLUDE "WIN32API.INC"  'in case something changes
                             'DECLARE FUNCTION GetStdHandle LIB "KERNEL32.DLL" ALIAS "GetStdHandle" (BYVAL nStdHandle AS DWORD) AS DWORD
                             'DECLARE FUNCTION ReadFile LIB "KERNEL32.DLL" ALIAS "ReadFile" (BYVAL hFile AS LONG, lpBuffer AS ANY, BYVAL nNumberOfBytesToRead AS LONG, lpNumberOfBytesRead AS LONG, BYVAL lpOverlapped AS LONG) AS LONG
                             'DECLARE FUNCTION WriteFile LIB "KERNEL32.DLL" ALIAS "WriteFile" (BYVAL hFile AS DWORD, lpBuffer AS ANY, BYVAL nNumberOfBytesToWrite AS LONG, lpNumberOfBytesWritten AS LONG, lpOverlapped AS OVERLAPPED) AS LONG
                             'WriteFile needs a type
                             '%NULL  = 0
                             '%STD_INPUT_HANDLE  = -10&
                             '%STD_OUTPUT_HANDLE = -11&
                             '%STD_ERROR_HANDLE  = -12&
                             DECLARE SUB STDOUT(BYVAL sText AS STRING)
                             SUB STDOUT(BYVAL sText AS STRING)
                                LOCAL lWritten AS LONG
                                LOCAL hFile AS LONG
                                sText = sText & $CRLF
                                REPLACE "''" WITH CHR$(34) IN sText
                                hFile = GetStdHandle(%STD_OUTPUT_HANDLE)
                                CALL WriteFile(hFile, BYVAL STRPTR(sText), LEN(sText), lWritten, BYVAL %NULL)
                             END SUB
                          '~~~~~~~~~~~~~~~~~~~~~~~~~~~~  Thanks Dave N and Don D. ~~~~~~~~~~~~~~~~~~~~~~
                          '  webdataStdIn
                          '     Replacement for StdIn Line to read standard input.
                          '     StdIn Line has a limit
                          '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                          FUNCTION webdataStdIn() AS STRING
                             DIM hInput AS LONG
                             DIM iRead AS LONG
                             DIM iResult AS LONG
                             DIM sBuffer AS STRING
                             DIM sOutBuffer AS STRING
                          
                             hInput = GetStdHandle(%STD_INPUT_HANDLE)
                             IF hInput THEN
                                DO
                                   sBuffer = SPACE$(32000)
                                   iResult = ReadFile(hInput, BYVAL STRPTR(sBuffer), _
                                                      LEN(sBuffer), iRead, BYVAL %NULL)
                                   '- If there was an error, return nothing
                                   IF iResult = 0 THEN
                                      EXIT DO
                                   '- We're done if iRead is 0
                                   ELSEIF iRead = 0 THEN
                                      EXIT DO
                                   '- Otherwise, accumulate the buffer
                                   ELSE
                                      sOutBuffer = sOutBuffer + LEFT$(sBuffer, iRead)
                                   END IF
                                   '- Bail if there's nothing left to read.
                                   IF iRead < LEN(sBuffer) THEN
                                      EXIT DO
                                   END IF
                                LOOP
                             END IF
                             FUNCTION = sOutBuffer
                          END FUNCTION
                          #ENDIF
                          '==============================================================================
                          '
                          '  CGI code for the PowerBASIC Console Compiler
                          '  Copyright (c) 1998 by PowerBASIC, Inc. All Rights Reserved.
                          '
                          '  Note:  The POST method only works with Microsoft compatible web servers
                          '         including:  IIS, Peer Web Server, Personal Web Server, WebSite,
                          '         EMWAC, and Apache NT.
                          '
                          '==============================================================================
                          '------------------------------------------------------------------------------
                          ' Return the user authentication and the script is protected. If server
                          ' supports???
                          '
                          FUNCTION Auth_Type() AS STRING
                            FUNCTION = ENVIRON$("AUTH_TYPE")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Return the length of the input string from the form
                          '
                          FUNCTION Content_Length() AS LONG
                            FUNCTION = VAL( ENVIRON$("CONTENT_LENGTH") )
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Return the content type of data supplied from the server.
                          '
                          FUNCTION Content_Type() AS STRING
                            FUNCTION = ENVIRON$("CONTENT_TYPE")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Current document file name.
                          '
                          FUNCTION Document() AS STRING
                            FUNCTION = ENVIRON$("DOCUMENT")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Virtual path to the current document
                          '
                          FUNCTION Document_URI() AS STRING
                            FUNCTION = ENVIRON$("DOCUMENT_URI")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Return the current date in GMT
                          '
                          FUNCTION Date_GMT() AS STRING
                            FUNCTION = ENVIRON$("DATE_GMT")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Return the current local date to the server.
                          '
                          FUNCTION Date_Local() AS STRING
                            FUNCTION = ENVIRON$("DATE_LOCAL")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Return the gateway interface (eg: "CGI 1.1")
                          '
                          FUNCTION Gateway_Interface() AS STRING
                            FUNCTION = ENVIRON$("GATEWAY_INTERFACE")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Last edit date of the document.
                          '
                          FUNCTION Last_Modified() AS STRING
                            FUNCTION = ENVIRON$("LAST_MODIFIED")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          '
                          '
                          FUNCTION Local_Addr() AS STRING
                            FUNCTION = ENVIRON$("LOCAL_ADDR")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Windows NT account details for the user.
                          '
                          FUNCTION Logon_User() AS STRING
                            FUNCTION = ENVIRON$("LOGON_USER")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Return the extra path information as given by the client
                          '
                          FUNCTION Path_Info() AS STRING
                            FUNCTION = ENVIRON$("PATH_INFO")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Return the server provided translated version of Path_Info.
                          '
                          FUNCTION Path_Translated() AS STRING
                            FUNCTION = ENVIRON$("PATH_TRANSLATED")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Return the method used to send data from the web server to the application
                          '
                          FUNCTION Query_Method() AS STRING
                            FUNCTION = ENVIRON$("QUERY_METHOD")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          '
                          '
                          FUNCTION Query_String() AS STRING
                            FUNCTION = ENVIRON$("QUERY_STRING")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          '
                          '
                          FUNCTION Query_String_Unescaped() AS STRING
                            FUNCTION = ENVIRON$("QUERY_STRING_UNESCAPED")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Returns the remote users connection address (not email address)
                          '
                          FUNCTION Remote_Addr() AS STRING
                            FUNCTION = ENVIRON$("REMOTE_ADDR")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Returns the clients reverse DNS of their IP address
                          '
                          FUNCTION Remote_Host() AS STRING
                            FUNCTION = ENVIRON$("REMOTE_HOST")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Return the user name retrieved from the server. If the client supports RFC931
                          ' identification.
                          '
                          FUNCTION Remote_Ident() AS STRING
                            FUNCTION = ENVIRON$("REMOTE_IDENT")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Return the username authentication and the script is protected. If server
                          ' supports???
                          '
                          FUNCTION Remote_User() AS STRING
                            FUNCTION = ENVIRON$("REMOTE_USER")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Return the method used to send data from the web server to the application
                          '
                          FUNCTION Request_Method() AS STRING
                            FUNCTION = ENVIRON$("REQUEST_METHOD")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Return the name of the script which launched the CGI app
                          '
                          FUNCTION Script_Name() AS STRING
                            FUNCTION = ENVIRON$("SCRIPT_NAME")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Return the server's host name
                          '
                          FUNCTION Server_Name() AS STRING
                            FUNCTION = ENVIRON$("SERVER_NAME")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Return the port used to communicate with the server
                          '
                          FUNCTION Server_Port() AS LONG
                            FUNCTION = VAL( ENVIRON$("SERVER_PORT") )
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Return true (-1) if the connection is secure
                          '
                          FUNCTION Server_Port_Secure() AS LONG
                            FUNCTION = ISFALSE ENVIRON$("SERVER_PORT_SECURE") = "0"
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Return the name and revision of the information protocol from the server
                          '
                          FUNCTION Server_Protocol() AS STRING
                            FUNCTION = ENVIRON$("SERVER_PROTOCOL")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Return the name and version of the server software
                          '
                          FUNCTION Server_Software() AS STRING
                            FUNCTION = ENVIRON$("SERVER_SOFTWARE")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' List of the MIME data types the browser can accept.  Values are seperated
                          ' by commas.
                          '
                          FUNCTION Http_Accept() AS STRING
                            FUNCTION = ENVIRON$("HTTP_ACCEPT")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          '
                          FUNCTION Http_Accept_Charset() AS STRING
                            FUNCTION = ENVIRON$("HTTP_ACCEPT_CHARSET")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          '
                          FUNCTION Http_Accept_Encoding() AS STRING
                            FUNCTION = ENVIRON$("HTTP_ACCEPT_ENCODING")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' List of the human languages the client can accept.
                          '
                          FUNCTION Http_Accept_Language() AS STRING
                            FUNCTION = ENVIRON$("HTTP_ACCEPT_LANGUAGE")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          '
                          FUNCTION Http_Connection() AS STRING
                            FUNCTION = ENVIRON$("HTTP_CONNECTION")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Retrieves the Cookie string detected by the server
                          '
                          FUNCTION Http_Cookie() AS STRING
                            FUNCTION = ENVIRON$("HTTP_COOKIE")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Returns the remote clients email address (if available); only works with
                          ' Netscape
                          '
                          FUNCTION Http_From() AS STRING
                            FUNCTION = ENVIRON$("HTTP_FROM")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          '
                          FUNCTION Http_Host() AS STRING
                            FUNCTION = ENVIRON$("HTTP_HOST")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          '
                          FUNCTION Http_Pragma() AS STRING
                            FUNCTION = ENVIRON$("HTTP_PRAGMA")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Return the URL of the document that the client points to before accessing the
                          ' CGI application.
                          '
                          FUNCTION Http_Referer() AS STRING
                            FUNCTION = ENVIRON$("HTTP_REFERER")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Product name of the clients browser software.
                          '
                          FUNCTION Http_User_Agent() AS STRING
                            FUNCTION = ENVIRON$("HTTP_USER_AGENT")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Returns if secure pages are turned on or off
                          '
                          FUNCTION HttpS() AS STRING
                            FUNCTION = ENVIRON$("HTTPS")
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Return the physical path of the CGI application
                          '
                          $IF NOT %DEF(%WINAPI)
                            DECLARE FUNCTION GetModuleFileName LIB "KERNEL32.DLL" ALIAS "GetModuleFileNameA" (BYVAL hModule AS LONG, lpFileName AS ASCIIZ, BYVAL nSize AS LONG) AS LONG
                          $ENDIF
                          FUNCTION AppPath() AS STRING
                            LOCAL p AS ASCIIZ * 256
                            LOCAL x AS LONG
                            GetModuleFileName 0, p, SIZEOF(p)
                            FOR x = LEN(p) TO 1 STEP - 1
                              IF ASC(p, x) = 92 THEN
                                EXIT FOR
                              END IF
                            NEXT
                            FUNCTION = LEFT$(p, x)
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Read data from the CGI script
                          '
                          FUNCTION ReadCGI() AS STRING
                            LOCAL Temp AS STRING
                            SELECT CASE Request_Method
                              CASE "GET", "PUT", "HEAD"
                                FUNCTION = ENVIRON$("QUERY_STRING")
                              CASE "POST"
                                #IF NOT %DEF(%WINAPI)
                                   STDIN LINE Temp
                                #ELSE
                                  Temp = webdataStdIn()
                                #ENDIF
                                FUNCTION = Temp
                              CASE ELSE   'assume the command line
                                FUNCTION = COMMAND$
                            END SELECT
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Write a string to the web server and automatically take care of the header
                          '
                          SUB WriteCGI(BYVAL x AS STRING)
                            STATIC header AS LONG
                            IF ISFALSE header THEN
                              STDOUT "Content-type: text/html" + CHR$(13, 10)
                              header = -1
                            END IF
                            REPLACE "''" WITH CHR$(34) IN x
                            STDOUT x
                          END SUB
                          '------------------------------------------------------------------------------
                          ' Decode all of the special characters in a CGI string
                          '
                          FUNCTION DecodeCGI(BYVAL t AS STRING) AS STRING
                            DIM b_in  AS BYTE PTR
                            DIM b_out AS BYTE PTR
                            DIM h     AS STRING PTR * 2
                            DIM a     AS ASCIIZ PTR
                            IF LEN(t) = 0 THEN
                              EXIT FUNCTION
                            END IF
                            b_in  = STRPTR(t)
                            b_out = b_in
                            DO
                              IF @b_in = 43 THEN          'convert plus to space
                                @b_out = 32
                              ELSEIF @b_in = 37 THEN      'process special chars
                                h = b_in + 1
                                @b_out = VAL("&H" + @h)
                                b_in = b_in + 2
                              ELSE
                                @b_out = @b_in
                              END IF
                              INCR b_in
                              INCR b_out
                            LOOP UNTIL @b_in = 0
                            @b_out = 0
                            a = STRPTR(t)
                            FUNCTION = @a
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' For best effect, do not decode the params string first
                          '
                          FUNCTION ParseParams(BYVAL params AS STRING, Param() AS STRING) AS LONG
                            LOCAL c AS LONG
                            LOCAL x AS LONG
                            c = PARSECOUNT(params, "&")
                            REDIM Param(c) AS STRING
                            FOR x = 1 TO c
                              Param(x) = PARSE$(params, "&", x)
                            NEXT x
                            FUNCTION = c
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          ' Parse raw CGI data and return specified parameter
                          '
                          FUNCTION CgiParam(BYVAL param AS STRING, BYVAL which AS STRING) AS STRING
                            LOCAL x AS LONG
                            LOCAL p AS STRING
                            which = which + "="
                            FOR x = 1 TO PARSECOUNT(param, "&")
                              p = PARSE$(param, "&", x)
                              IF LEFT$(UCASE$(p), LEN(which)) = UCASE$(which) THEN
                                FUNCTION = DecodeCGI(MID$(p, LEN(which) + 1))
                                EXIT FUNCTION
                              END IF
                            NEXT
                          END FUNCTION
                          To make this approach work, I just need some clues on how to communicate with the more substantial PB programs that are already written and only need small changes to move the GUI to generated Web Pages.

                          Bob Mechler
                          Last edited by BOB MECHLER; 28 Dec 2007, 10:20 PM. Reason: Cleanup code and add comments

                          Comment


                          • #14
                            >>Can the PBCC compiler be used in an Internet setting other than CGI. <<
                            yes, from both the client and server side

                            >>I'm looking at using XML as the database <<
                            You don't want to do that. Brad's explanation of XML is perfect.

                            On another note, you can do anything with PBCC that can be done with a scripting language like PHP. Ebay, Google and Amazon all run using CGI.

                            Comment


                            • #15
                              Bob,

                              Its quite possible that it's 1:20am and I've been up a long time today, but I'm still not getting what it is you are doing, or want to do. I guess I'm confused as to why you need this app to be "web" enabled in the first place.

                              Is the data getting into the first drop-box based on the actions of someone using a web page? If so, there is no need to have the PB program constantly monitoring the folder, just call it from the web form when the user 'Submits' the page.

                              Speaking of Submitting the page, the HTML page you're creating after the calculations are done doesn't actually have a submit method so it will never trigger your CGI application. You need a button, or some simple javascript to send the HTML form data to your CGI application.

                              Now, if this is NOT a 'standard' Web program (standard being:
                              • The user requests a page (opens a browser, enters a URL)
                              • Your page provides areas to enter data
                              • The user 'submits' the data to the server (where your CGI app is)
                              • Your app processes the data and....
                              • You app creates a reply by sending back a valid HTML page

                              then you probably don't need the "CGI"ness of PB. If all you are doing is running a LRA (long Running Application) and spitting out a result page, you can do that without a Web server and HTML at all even if the data resides "on the web server". You can create an HTML page and display it using the default browser on the local PC, or just pop up a MSGBOX for that matter.

                              So I guess I'm confused still as to what this program actually does, and what you are trying to accomplish.

                              again, I apologize if I'm missing something obvious here. I've just finished up a 4 server network upgrade that I started Wednesday evening.....I think I dosed off there for an hour or two last night, but I can't be sure
                              Software makes Hardware Happen

                              Comment


                              • #16
                                You can use PB/WIN to create CGIs, they do not need a console as IIS creates one automatically. You can't use "MSGBOX" or anything that requires user interaction or halts the process as the CGI will just time out (my ISP has a 15 second limit). Think "Windows service" or BAT file: the server runs your CGI, the CGI does it's work, outputs info, etc. and quits. If you need to store variables between CGI sessions, use a cookie.
                                kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

                                Comment


                                • #17
                                  >.....I think I dosed off there

                                  I hope that was a typo and you actually "dozed" off.

                                  If you "dosed" off you may well have been in violation of the Comprehensive Drug Abuse Prevention and Control Act of 1970 and you will soon be seeing your family only on visiting day at Club Fed.

                                  MCM
                                  Michael Mattias
                                  Tal Systems (retired)
                                  Port Washington WI USA
                                  [email protected]
                                  http://www.talsystems.com

                                  Comment


                                  • #18
                                    you can simulate a desktop app using PBCC and CGI, like I did here:

                                    http://www.nbson.com/bcm/bcm.htm

                                    Comment


                                    • #19
                                      Here is the code for the default.htm which I should have provided before.

                                      Code:
                                      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
                                      <html>
                                      <head><style type="text/css">
                                      <!--
                                      body,td,th {
                                      	font-family: Tahoma, Verdana;
                                      	font-size: medium;
                                      }
                                      
                                      -->
                                      </style>
                                      	<title>Market Value History</title>
                                      </head>
                                      
                                      
                                      <form action="/cgi-bin/CONTACT.EXE" method="post" name="Backdated Market Value">
                                      <fieldset><legend>Lookup Market Value by date</legend><P>
                                      <label>Account :</label><input type="text" name="Account" size="7" value="0100005" maxlength="7" tabindex="1">
                                      <label>As of date:</label><input type="text" name="MKTDATE" value="01012006" size="10" maxlength="10" tabindex="2">
                                      <input type="hidden" name="DATAPATH" value="C:\FILES\CTRU\"><P>
                                      <input type="submit" name="button" value="Submit">
                                      </fieldset></form><body bgcolor="#FFFFCC">
                                      
                                      
                                      </body>
                                      </html>
                                      The purpose of the program was to test the ability to collect a simple account number and date and return a page with the market value generated by an existing PB program using the btrieve api.

                                      The CONTACT.EXE used to have all the programming needed to get the market value but the web-server I was using had an issue with the btrieve exe loading (6.15). That is when I separated the market value code into a separate program and made it a windows service. Upgrading to the latest Pervasive will probably solve this problem. (And more study!)

                                      In the future I want to create web apps to service a market I have a lot of experience in over the last 20 years. A couple of inexpensive standalone PC's would be all that is necessary to run a multi-user Web App that I would host and manage for a fee of course. None of my competition has this approach or will have in the near future. Virtual directories and SSL would allow security and no upper limit on new customers. If I can add some Ajax page updating in the right places the web app should be plenty slick enough for this market.

                                      A simple cgi app using PB/WIN or PB/CC with some Ajax functionality is what I will search for next.

                                      If and when PB has a linux version, it will open up that as a market too.

                                      It seems to me that there should be a big need for hybrid apps where the home office uses PB/WIN programs and the small satellite offices log in through a web browser to post the day's receipts and requests reports to be prepared as PDF'S etc. Sounds like many are doing that already on this forum. There just seems to be a dearth of 'How to's'.

                                      Bob Mechler

                                      Comment


                                      • #20
                                        Shawn, I didn't see your post till just now, but what you are doing is EXACTLY where I want to go. Just knowing it is possible is very encouraging. I'm sure a lot of trial and error went into this approach.

                                        Bob Mechler

                                        Comment

                                        Working...
                                        X