Presentation is loading. Please wait.

Presentation is loading. Please wait.

CGI Programming Languages Web Based Software Development July 21, 2005 Song, JaeHa.

Similar presentations


Presentation on theme: "CGI Programming Languages Web Based Software Development July 21, 2005 Song, JaeHa."— Presentation transcript:

1 CGI Programming Languages Web Based Software Development July 21, 2005 Song, JaeHa

2 Agenda  Introduction  CGI Mechanism  CGI Languages  Alternatives  Conclusion

3 Introduction: Definition  CGI: Common Gateway Interface  A simple interface for running gateways  In an information server  In Platform-independent manner  Gateway: a program that provides path into internal applications or resources, such as database or file system

4 Introduction: Conceptual diagram  Script: The software that is invoked by the server according to this interface.  Server: The application program that invokes the script in order to service requests from the client.  Meta-variable: A named parameter which carries information from the server to the script. Client ServerScripts Internal services HTTP Request CGI Request Meta-variable Internal Request HTTP ResponseCGI ResponseInternal Response

5 CGI Mechanisms: Server  As an Application gateway  Receive request from client  Select CGI script to handle request  Convert client request to CGI request  Execute script  Convert CGI response into response for client  Authentication and security handling  Manages special directory such as /cgi-bin  CGI time-out handling  Error page handling

6 CGI Mechanisms: CGI request  Request meta-variables  sources  Environment variables  STDIN  Command line arguments  CONTENT_TYPE  REQUEST_METHOD  QUERY_STRING  CONTENT_LENGTH  …  Request message body  For POST method

7 CGI Mechanisms: CGI response  Response header fields  CGI-field  Content-Type  Location  Status  Other-field  Protocol-specific header fields  Extension header fields  Response message body  STDOUT

8 CGI Mechanisms: Interface ports  Input  STDIN  POST method with 0 < CONTENT_LENGTH  Environment variables  Request meta-variables  Command line argument  ISINDEX query  Output  STDOUT

9 CGI Languages: Only Perl ?  Almost written in Perl  But, CGI needs only  environment variables  STDIN/STDOUT  command line arguments

10 CGI Languages: Others  C/C++  Fortran  TCL  Unix shells  Visual Basic  Apple scripts  Ruby  Etc.

11 CGI Languages: Choosing Others  Perl is always best ?  Concerns  Productivity  Learning curve  Execution overhead  Etc.

12 CGI Languages: CGI in C  C for CGI Programming  Well known: Short Learning Curve  Low execution overhead  inconvenient in String handling

13 CGI Languages: CGI Output in C #include void main() { /** Print the CGI response header, required for all HTML output.**/ /** Note the extra \n, to send the blank line. **/ printf("Content-type: text/html\n\n") ; /** Print the HTML response page to STDOUT. **/ printf(" \n") ; printf(" CGI Output \n") ; printf(" \n") ; printf(" Hello, world. \n") ; printf(" \n") ; exit(0) ; }

14 CGI Languages: CGI I/O in C #include … main(int argc, char *argv[]) { entry entries[MAX_ENTRIES]; register int x,m=0; int cl; printf("Content-type: text/html%c%c",10,10); if(strcmp(getenv("REQUEST_METHOD"),"POST")) { … } if(strcmp(getenv("CONTENT_TYPE"),"application/x-www-form- urlencoded")) { printf("This script can only be used to decode form results. \n"); exit(1); } cl = atoi(getenv("CONTENT_LENGTH")); for(x=0;cl && (!feof(stdin));x++) { … } … }

15 CGI Languages: CGI in Ruby  Ruby for CGI Programming  Packages for Productivity improvement  CGI CGI::Cookie CGI::HtmlExtension CGI::QueryExtension CGI::Session CGI::Session::FileStore CGI::Session::MemoryStore CGI::Session::PStore  Stylish  Under development  Small user group

16 CGI Languages: CGI in Ruby #!/usr/bin/env ruby print "HTTP/1.0 200 OK\r\n“ print "Content-type: text/html\r\n\r\n“ print " Hello World! \r\n" … require "cgi“ cgi = CGI.new value = cgi['field_name'] fields = cgi.keys cgi.has_key?('field_name') cgi.include?('field_name') …

17 Alternatives: SSI/Servlets/Server API  SSI  Server Side Includes  Simple interface for basic dynamic content  Non-standard  Servlets  an alternative API for JAVA  overcomes the limitation of JAVA not supporting environment variables  Server API  Generally the most powerful and most complex option  Non portable  Varies from server to server

18 Alternatives: Servlets/JSP  Kinds of CGI scripts  Scripts: … It need not be a standalone program, but could be a dynamically loaded or shared library or even a subroutine in the server.  Servlets: Thread instead of process  Lightweight : less overhead in execution  Sharing states: i.e. session information  Crash propagation  Cold deploy  JSP: reversion between hosts and guests  Contents oriented instead of control oriented  Less ‘ ” ’  Easy to read  Hot deploy

19 Alternatives: CGI Pros and Cons  Advantages  Separation of concerns  Server for client request handling  Scripts for application issues  Simple  Drawbacks  Performance  Scalability  Maintainability  Security

20 Conclusion  Common Gateway Interface  A simple interface for information server extension  For simple dynamic web programming  Any languages are possible when they supports minimum set of mechanisms  STDIN/STDOUT  Environment variables  Able to invoke in Information server  Mainly in Perl

21 References  CGI Programming RFC Page:  http://www.faqs.org/rfcs/rfc3875.html http://www.faqs.org/rfcs/rfc3875.html  W3C’s CGI Pages:  http://www.w3.org/CGI http://www.w3.org/CGI  CGI FAQ  http://www.htmlhelp.com/faq/cgifaq.1.html http://www.htmlhelp.com/faq/cgifaq.1.html  Another CGI FAQ:  http://www.webthing.com/tutorials/cgifaq.html http://www.webthing.com/tutorials/cgifaq.html  Dynamic Programming Language Choice Criteria:  http://www.apacheweek.com/features/dynamicpages http://www.apacheweek.com/features/dynamicpages  Ruby CGI:  http://www.ruby-doc.org/stdlib/libdoc/cgi/rdoc/ http://www.ruby-doc.org/stdlib/libdoc/cgi/rdoc/  Web Programming Languages Introduction:  http://www.freelance-help.com/web-programming.php http://www.freelance-help.com/web-programming.php


Download ppt "CGI Programming Languages Web Based Software Development July 21, 2005 Song, JaeHa."

Similar presentations


Ads by Google