[xiph-commits] r3814 - liboggz/trunk/src/tools/oggz-chop
conrad at svn.annodex.net
conrad at svn.annodex.net
Fri Dec 5 19:05:03 PST 2008
Author: conrad
Date: 2008-12-05 19:05:03 -0800 (Fri, 05 Dec 2008)
New Revision: 3814
Modified:
liboggz/trunk/src/tools/oggz-chop/cgi.c
Log:
oggz-chop CGI: add customization for DocumentRoot, for servers that don't
provide PATH_TRANSLATED
Modified: liboggz/trunk/src/tools/oggz-chop/cgi.c
===================================================================
--- liboggz/trunk/src/tools/oggz-chop/cgi.c 2008-12-06 03:04:45 UTC (rev 3813)
+++ liboggz/trunk/src/tools/oggz-chop/cgi.c 2008-12-06 03:05:03 UTC (rev 3814)
@@ -13,6 +13,11 @@
#include "httpdate.h"
#include "timespec.h"
+/* Customization: for servers that do not set PATH_TRANSLATED, specify the
+ * DocumentRoot here and it will be prepended to PATH_INFO */
+//#define DOCUMENT_ROOT "/var/www"
+#define DOCUMENT_ROOT NULL
+
static void
set_param (OCState * state, char * key, char * val)
{
@@ -121,6 +126,33 @@
}
#endif
+static char *
+prepend_document_root (char * path_info)
+{
+ char * dr = DOCUMENT_ROOT;
+ char * path_translated;
+ int dr_len, pt_len;
+
+ if (path_info == NULL) return NULL;
+
+ if (dr == NULL || *dr == '\0') return strdup (path_info);
+
+ dr_len = strlen (dr);
+
+ pt_len = dr_len + strlen(path_info) + 1;
+ path_translated = malloc (pt_len);
+ snprintf (path_translated, pt_len , "%s%s", dr, path_info);
+
+ return path_translated;
+}
+
+static int
+path_undefined (char * vars)
+{
+ fprintf (stderr, "oggz-chop: Cannot determine real filename due to CGI configuration error: %s undefined\n", vars);
+ return -1;
+}
+
int
cgi_main (OCState * state)
{
@@ -131,6 +163,7 @@
char * if_modified_since;
time_t since_time, last_time;
struct stat statbuf;
+ int built_path_translated=0;
httpdate_init ();
@@ -140,25 +173,29 @@
if_modified_since = getenv ("HTTP_IF_MODIFIED_SINCE");
memset (state, 0, sizeof(*state));
- state->infilename = path_translated;
state->end = -1.0;
state->do_skeleton = 1;
- /*photo_init (¶ms->in, path_translated);*/
+ if (path_translated == NULL) {
+ if (path_info == NULL)
+ return path_undefined ("PATH_TRANSLATED and PATH_INFO");
- if (path_translated == NULL) {
- fprintf (stderr, "oggz-chop: CGI configuration error: PATH_TRANSLATED undefined\n");
- return -1;
+ path_translated = prepend_document_root (path_info);
+ if (path_translated == NULL)
+ return path_undefined ("PATH_TRANSLATED");
+
+ built_path_translated = 1;
}
+ state->infilename = path_translated;
+
/* Get Last-Modified time */
if (stat (path_translated, &statbuf) == -1) {
switch (errno) {
case ENOENT:
return 0;
default:
- fprintf (stderr, "oggz-chop: Error checking %s: %s\n",
- path_translated, strerror(errno));
+ fprintf (stderr, "oggz-chop: %s: %s\n", path_translated, strerror(errno));
return -1;
}
}
@@ -209,6 +246,9 @@
#else
err = chop (state);
#endif
+
+ if (built_path_translated && path_translated != NULL)
+ free (path_translated);
return err;
}
More information about the commits
mailing list