home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / WEBSERVE / PI3 / PI3WEB.EXE / DEVEL / CGI / Redirect.c < prev    next >
C/C++ Source or Header  |  1997-10-19  |  3KB  |  99 lines

  1. /*____________________________________________________________________________*\
  2.  *
  3.  
  4.  Copyright (c) 1997 John Roy. All rights reserved.
  5.  
  6.  These sources, libraries and applications are
  7.  FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
  8.  as long as the following conditions are adhered to.
  9.  
  10.  Redistribution and use in source and binary forms, with or without
  11.  modification, are permitted provided that the following conditions
  12.  are met:
  13.  
  14.  1. Redistributions of source code must retain the above copyright
  15.     notice, this list of conditions and the following disclaimer. 
  16.  
  17.  2. Redistributions in binary form must reproduce the above copyright
  18.     notice, this list of conditions and the following disclaimer in
  19.     the documentation and/or other materials provided with the
  20.     distribution.
  21.  
  22.  3. Redistributions of any form whatsoever and all advertising materials 
  23.     mentioning features must contain the following
  24.     acknowledgment:
  25.     "This product includes software developed by John Roy
  26.     (http://www.johnroy.com/pi3/)."
  27.  
  28.  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  29.  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30.  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  31.  IN NO EVENT SHALL THE AUTHORS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  32.  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33.  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34.  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35.  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  36.  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  37.  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  38.  OF THE POSSIBILITY OF SUCH DAMAGE.
  39.  
  40.  *____________________________________________________________________________*|
  41.  *
  42.  * $Source: Redirect.c$
  43.  * $Date: Sun Aug 10 06:41:31 1997$
  44.  *
  45.  Description:
  46.     Simple CGI program which sends a 'redirect' response to the URL path
  47.     passed into this CGI program in the PATH_INFO environment variable.
  48. \*____________________________________________________________________________*/
  49. /* $SourceTop:$ */
  50.  
  51. #include <stdlib.h>
  52. #include <stdio.h>
  53.  
  54. /*____________________________________________________________________________*\
  55.  *
  56.  Function:
  57.  Synopsis:
  58.  Description:
  59. \*____________________________________________________________________________*/
  60. int main( int iArgc, const char *ppArgv[] )
  61. {
  62.     const char *pPath = getenv( "PATH_INFO" );
  63.     const char *pQuery = getenv( "QUERY_STRING" );
  64.     const char *pProgram = __FILE__;
  65.  
  66.     if ( !pPath || !*pPath )
  67.         {
  68.         /* --- Usage --- */
  69.         printf("Content-Type: text/html\n\n");
  70.         printf("\n");
  71.         printf("<HTML>\n");
  72.         printf("<TITLE>%s usage</TITLE>\n", pProgram );
  73.         printf("<BODY>\n");
  74.         printf("<H1>%s usage</H1>\n", pProgram);
  75.         printf("Specify URL path to which to issue a redirect in \
  76. PATH_INFO<BR>\n");
  77.         printf("Specify message to be send with the redirect in \
  78. the QUERY_STRING<BR>\n");
  79.         printf("i.e.\n" );
  80.         printf("<CODE>http://my_host/this_script<redirect_path>[?message]\
  81. </CODE>\n" );
  82.         printf("</HTML>\n");
  83.         printf("</BODY>\n");
  84.         }
  85.     else
  86.         {
  87.         printf("Location: %s\n\n", pPath);
  88.         };
  89.  
  90.     /* --- send message ? --- */
  91.     if ( pQuery && *pQuery )
  92.         {
  93.         printf(pQuery);
  94.         };
  95.  
  96.     return 0;
  97. }
  98.  
  99.