Back to index

courier  0.68.2
cgihttpsscriptptr.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 2007 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 /*
00007 */
00008 #include      "cgi.h"
00009 
00010 #if    HAVE_UNISTD_H
00011 #include      <unistd.h>
00012 #endif
00013 
00014 #include      <string.h>
00015 #include      <stdlib.h>
00016 #include      <stdio.h>
00017 
00018 static char *scriptptr=0;
00019 extern void error(const char *);
00020 
00021 void cgihttpsscriptptr_init()
00022 {
00023        /* Reinitialisation required when running as fastcgi */ 
00024        if (scriptptr) {
00025               free(scriptptr);
00026               scriptptr=0;
00027        }
00028 }
00029 
00030 const char *cgihttpsscriptptr()
00031 {
00032        if (!scriptptr)
00033        {
00034        char   *p=getenv("SCRIPT_NAME");
00035        char   *h=getenv("HTTP_HOST");
00036        char   *q;
00037 
00038               if (!h)       h="";
00039               if (!p)       p="";
00040 
00041               q=malloc(strlen(p)+strlen(h)+sizeof("https://"));
00042               if (!q)       error("Out of memory.");
00043               sprintf(q, "https:%s%s%s", (*h ? "//":""), h, p);
00044               scriptptr=q;
00045        }
00046        return (scriptptr);
00047 }