1 / 21

CGI Programming Languages

CGI Programming Languages. Web Based Software Development July 21, 2005 Song, JaeHa. Agenda. Introduction CGI Mechanism CGI Languages Alternatives Conclusion. Introduction: Definition. CGI: Common Gateway Interface A simple interface for running gateways In an information server

jess
Download Presentation

CGI Programming Languages

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 CGI Request Meta-variable Server Scripts Internal services HTTP Request Internal Request HTTP Response CGI Response Internal 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 <stdio.h> 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("<html>\n") ; printf("<head><title>CGI Output</title></head>\n") ; printf("<body>\n") ; printf("<h1>Hello, world.</h1>\n") ; printf("</body>\n") ; printf("</html>\n") ; exit(0) ; }

  14. CGI Languages: CGI I/O in C #include <stdio.h> … 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 • CGICGI::CookieCGI::HtmlExtensionCGI::QueryExtensionCGI::SessionCGI::Session::FileStoreCGI::Session::MemoryStoreCGI::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 "<html><body>Hello World!</body></html>\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 • W3C’s CGI Pages: • http://www.w3.org/CGI • CGI FAQ • http://www.htmlhelp.com/faq/cgifaq.1.html • Another CGI FAQ: • http://www.webthing.com/tutorials/cgifaq.html • Dynamic Programming Language Choice Criteria: • http://www.apacheweek.com/features/dynamicpages • Ruby CGI: • http://www.ruby-doc.org/stdlib/libdoc/cgi/rdoc/ • Web Programming Languages Introduction: • http://www.freelance-help.com/web-programming.php

More Related