[xiph-commits] r8575 - in trunk/oggdsf/src/tools: . mod_oggchef
ozone at motherfish-iii.xiph.org
ozone at motherfish-iii.xiph.org
Sun Jan 2 06:43:47 PST 2005
Author: ozone
Date: 2005-01-02 06:43:46 -0800 (Sun, 02 Jan 2005)
New Revision: 8575
Added:
trunk/oggdsf/src/tools/mod_oggchef/
trunk/oggdsf/src/tools/mod_oggchef/mod_oggchef.cpp
trunk/oggdsf/src/tools/mod_oggchef/mod_oggchef.vcproj
trunk/oggdsf/src/tools/mod_oggchef/query_utils.c
trunk/oggdsf/src/tools/mod_oggchef/query_utils.h
Removed:
trunk/oggdsf/src/tools/mod_oggchef/mod_timeslice.cpp
trunk/oggdsf/src/tools/mod_oggchef/mod_timeslice.vcproj
trunk/oggdsf/src/tools/mod_timeslice/
Modified:
trunk/oggdsf/src/tools/mod_oggchef/Makefile
trunk/oggdsf/src/tools/mod_oggchef/modules.mk
Log:
oggdsf:
* Rename mod_timeslice to mod_oggchef, since it'll be more appropriate for future work on it ...
* Split some of mod_oggchef's functionality into a separate query_utils.c file
Copied: trunk/oggdsf/src/tools/mod_oggchef (from rev 8573, trunk/oggdsf/src/tools/mod_timeslice)
Modified: trunk/oggdsf/src/tools/mod_oggchef/Makefile
===================================================================
--- trunk/oggdsf/src/tools/mod_timeslice/Makefile 2005-01-02 11:49:36 UTC (rev 8573)
+++ trunk/oggdsf/src/tools/mod_oggchef/Makefile 2005-01-02 14:43:46 UTC (rev 8575)
@@ -1,5 +1,5 @@
#
-# UNIX Makefile for mod_timeslice
+# UNIX Makefile for mod_oggchef
#
# You may need to tweak the following variables in order to get things building
# properly
@@ -43,11 +43,11 @@
# cleanup
clean:
- -rm -f mod_timeslice.o mod_timeslice.lo mod_timeslice.slo mod_timeslice.la
+ -rm -f mod_oggchef.o mod_oggchef.lo mod_oggchef.slo mod_oggchef.la
# simple test
test: reload
- lynx -mime_header http://localhost/timeslice
+ lynx -mime_header http://localhost/oggchef
# install and activate shared object by reloading Apache to
# force a reload of the shared object file
Copied: trunk/oggdsf/src/tools/mod_oggchef/mod_oggchef.cpp (from rev 8573, trunk/oggdsf/src/tools/mod_timeslice/mod_timeslice.cpp)
===================================================================
--- trunk/oggdsf/src/tools/mod_timeslice/mod_timeslice.cpp 2005-01-02 11:49:36 UTC (rev 8573)
+++ trunk/oggdsf/src/tools/mod_oggchef/mod_oggchef.cpp 2005-01-02 14:43:46 UTC (rev 8575)
@@ -0,0 +1,350 @@
+// ===========================================================================
+// Copyright (C) 2004-2005 Zentaro Kavanagh
+// Copyright (C) 2004-2005 Commonwealth Scientific and Industrial Research
+// Organisation (CSIRO) Australia
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// - Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+// - Neither the name of Zentaro Kavanagh, CSIRO Australia nor the names of
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
+// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// ===========================================================================
+
+#include "query_utils.h"
+#include "anx_time.h"
+#include "apr_stdcall.h"
+
+#include "httpd.h"
+#ifdef WIN32
+# undef strtoul /* Otherwise Visual Studio .NET 2003 complains */
+#endif
+#include "http_config.h"
+#include "http_core.h"
+#include "http_log.h"
+#include "http_protocol.h"
+#include "apr_strings.h"
+
+#include <stdio.h>
+#include <string.h>
+
+#include <libOOOgg/libOOOgg.h>
+#include <libOOOgg/dllstuff.h>
+#include <libOOOggSeek/AutoAnxSeekTable.h>
+
+#include <iostream>
+#include <fstream>
+
+
+
+/* Note: This file's pretty ugly at the moment, it's basically a merge of the
+ mod_annodex_ap20 source code and AnxCutter. Don't worry, it will be tidied
+ up :)
+ */
+
+#define DEBUG
+
+#define ANX_MIME_TYPE "application/x-annodex"
+#define CMML_MIME_TYPE "text/x-cmml"
+
+#define CMML_PREAMBLE \
+"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" \
+
+#define MOD_ANNODEX_TYPE_UNKNOWN -1
+
+#define MOD_ANNODEX_TYPE_ANX 0
+#define MOD_ANNODEX_TYPE_CMML 1
+
+#define MEDIA_BUF_LEN 8192
+
+
+
+enum eDemuxState {
+ SEEN_NOTHING,
+ SEEN_ANNODEX_BOS,
+ SEEN_ANNODEX_EOS,
+ SEEN_ALL_CODEC_HEADERS,
+ INVALID = 100
+};
+
+eDemuxState demuxState;
+
+typedef pair<unsigned long, unsigned long> tSerial_HeadCountPair;
+
+unsigned long bytePos;
+
+bool gotAllHeaders;
+
+vector<tSerial_HeadCountPair> theStreams;
+
+unsigned long annodexSerialNo;
+
+using namespace std;
+
+unsigned long headerCount(OggPacket* inPacket)
+{
+ const unsigned short NUM_SEC_HEADERS_OFFSET = 24;
+
+ return iLE_Math::charArrToULong(inPacket->packetData() +
+ NUM_SEC_HEADERS_OFFSET);
+
+}
+
+request_rec *theRequest;
+
+bool writePageToOutputFile(OggPage* inOggPage) {
+ // outputFile.write((char*)inOggPage->createRawPageData(), inOggPage->pageSize());
+ ap_rwrite((char*)inOggPage->createRawPageData(),
+ inOggPage->pageSize(),
+ theRequest);
+ return true;
+}
+
+//This will be called by the callback
+bool pageCB(OggPage* inOggPage, void *)
+{
+
+ bool allEmpty = true;
+
+ switch (demuxState) {
+
+ case SEEN_NOTHING:
+ if ( (inOggPage->numPackets() == 1)
+ && (inOggPage->header()->isBOS())
+ && (strncmp((char*)inOggPage->getPacket(0)->packetData(), "Annodex\0", 8) == 0)) {
+
+ //Advance the state
+ demuxState = SEEN_ANNODEX_BOS;
+
+ //Remember the annodex streams serial no
+ annodexSerialNo = inOggPage->header()->StreamSerialNo();
+
+ //Write out the page.
+ writePageToOutputFile(inOggPage);
+ } else {
+
+ demuxState = INVALID;
+ }
+
+ break;
+ case SEEN_ANNODEX_BOS:
+ if ( (inOggPage->numPackets() == 1)
+ && (inOggPage->header()->isBOS())
+ && (strncmp((char*)inOggPage->getPacket(0)->packetData(), "AnxData\0", 8) == 0)) {
+
+
+ //Create an association of serial no and num headers
+ tSerial_HeadCountPair locMap;
+ locMap.first = inOggPage->header()->StreamSerialNo();
+ locMap.second = headerCount(inOggPage->getPacket(0));
+
+ //Add the association to the list
+ theStreams.push_back(locMap);
+
+ //Write the page out to the output file.
+ writePageToOutputFile(inOggPage);
+ } else if ( (inOggPage->header()->isEOS())
+ && (inOggPage->header()->StreamSerialNo() == annodexSerialNo)) {
+
+ //It's the Annodex EOS.
+ demuxState = SEEN_ANNODEX_EOS;
+ writePageToOutputFile(inOggPage);
+ } else {
+ demuxState = INVALID;
+ }
+ break;
+ case SEEN_ANNODEX_EOS:
+ for (unsigned int i = 0; i < theStreams.size(); i++) {
+ if (theStreams[i].first == inOggPage->header()->StreamSerialNo()) {
+ if (theStreams[i].second >= 1) {
+ theStreams[i].second--;
+ writePageToOutputFile(inOggPage);
+ } else {
+ demuxState = INVALID;
+ }
+ }
+ }
+
+
+ for (unsigned int i = 0; i < theStreams.size(); i++) {
+ if (theStreams[i].second != 0) {
+ allEmpty = false;
+ }
+ }
+
+ if (allEmpty) {
+
+ demuxState = SEEN_ALL_CODEC_HEADERS;
+ }
+ break;
+ case SEEN_ALL_CODEC_HEADERS:
+ break;
+ case INVALID:
+ break;
+ default:
+ break;
+ }
+
+
+ if (demuxState == INVALID) {
+ }
+ // delete inOggPage;
+
+ return true;
+}
+
+static int
+ma_anxenc (request_rec * r, char * filename, char * content_type,
+ apr_table_t * cgi_table)
+{
+ char * val;
+ double seek_offset = 0.0;
+
+ theRequest = r;
+
+ /* put the requested time into seek_offset */
+ val = (char *)apr_table_get (cgi_table, "t");
+
+ if (!val)
+ {
+ fstream inputFile;
+ inputFile.open(filename, ios_base::in | ios_base::binary);
+ for (;;)
+ {
+ const unsigned short BUFF_SIZE = 8092;
+ char* locBuff = new char[BUFF_SIZE];
+
+ inputFile.read(locBuff, BUFF_SIZE);
+ unsigned long locBytesRead = inputFile.gcount();
+ if (locBytesRead == 0) break;
+ ap_rwrite (locBuff, locBytesRead, r);
+ }
+ inputFile.close();
+
+ return 0;
+ }
+
+ seek_offset = anx_parse_time (val);
+
+ /* begin AnxCutter code */
+ demuxState = SEEN_NOTHING;
+ bytePos = 0;
+ gotAllHeaders = false;
+ annodexSerialNo = 0;
+
+ OggDataBuffer testOggBuff;
+ testOggBuff.registerStaticCallback(&pageCB, NULL);
+
+ /* rip out the headers from the file */
+
+ fstream inputFile;
+
+ ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
+ "ma_anxenc t=%s (%ld)\n", val, seek_offset);
+
+ inputFile.open(filename, ios_base::in | ios_base::binary);
+
+ char* locBuff = new char[MEDIA_BUF_LEN];
+ while (demuxState < SEEN_ALL_CODEC_HEADERS) {
+ inputFile.read(locBuff, MEDIA_BUF_LEN);
+ unsigned long locBytesRead = inputFile.gcount();
+ if (locBytesRead > 0)
+ {
+ ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
+ "feeding %ld bytes to testOggBuff", locBytesRead);
+ }
+ testOggBuff.feed((const unsigned char*)locBuff, locBytesRead);
+ }
+ inputFile.close();
+
+ // Build a seek table for the file
+ AutoAnxSeekTable *locSeekTable = new AutoAnxSeekTable(filename);
+ locSeekTable->buildTable();
+
+ // Seek to the user's requested start time
+ LOOG_UINT64 locStartTime = (LOOG_UINT64) seek_offset * 10000000;
+ OggSeekTable::tSeekPair locSeekResult = locSeekTable->getStartPos(locStartTime);
+
+ // Stream-copy everything from the requested timepoint onward to the output file
+ inputFile.open(filename, ios_base::in | ios_base::binary);
+ inputFile.seekg(locSeekResult.second);
+
+ for (;;) {
+ inputFile.read(locBuff, MEDIA_BUF_LEN);
+ unsigned long locBytesRead = inputFile.gcount();
+ if (locBytesRead == 0) break;
+ //outputFile.write(locBuff, locBytesRead);
+ ap_rwrite (locBuff, locBytesRead, r);
+ }
+ inputFile.close();
+
+ ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
+ "Served request");
+}
+
+
+extern "C" {
+
+/* The annodex content handler */
+static int AP_MODULE_ENTRY_POINT annodex_handler(request_rec *r)
+{
+ apr_uri_t * uri;
+ char * filename;
+ apr_table_t * cgi_table;
+
+ ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
+ "Got here 2");
+
+ uri = &(r->parsed_uri);
+
+ /* usually filename is request filename */
+ filename = r->filename;
+
+ ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
+ "filename is %s", filename);
+
+ cgi_table = make_cgi_table (r, uri->query);
+
+ ma_anxenc (r, r->filename, ANX_MIME_TYPE, cgi_table);
+
+ return OK;
+}
+
+static void AP_MODULE_ENTRY_POINT annodex_register_hooks(apr_pool_t *p)
+{
+ ap_hook_handler(AP_HOOK_HANDLER_FUNCTION(annodex_handler),
+ NULL, NULL, APR_HOOK_MIDDLE);
+}
+
+/* Dispatch list for API hooks */
+module AP_MODULE_DECLARE_DATA timeslice_module = {
+ STANDARD20_MODULE_STUFF,
+ NULL, /* create per-dir config structures */
+ NULL, /* merge per-dir config structures */
+ NULL, /* create per-server config structures */
+ NULL, /* merge per-server config structures */
+ NULL, /* table of config file commands */
+ AP_REGISTER_HOOK_FUNCTION(annodex_register_hooks) /* register hooks */
+};
+
+} /* extern "C" */
Copied: trunk/oggdsf/src/tools/mod_oggchef/mod_oggchef.vcproj (from rev 8573, trunk/oggdsf/src/tools/mod_timeslice/mod_timeslice.vcproj)
===================================================================
--- trunk/oggdsf/src/tools/mod_timeslice/mod_timeslice.vcproj 2005-01-02 11:49:36 UTC (rev 8573)
+++ trunk/oggdsf/src/tools/mod_oggchef/mod_oggchef.vcproj 2005-01-02 14:43:46 UTC (rev 8575)
@@ -0,0 +1,219 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.10"
+ Name="mod_oggchef"
+ ProjectGUID="{F8FDD992-E21A-483F-BBE7-305D10163DE4}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="2"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\..\lib\helper;..\..\lib\core\ogg;"C:\Program Files\Apache Group\Apache2\include""
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
+ MinimalRebuild="TRUE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="4"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="4"
+ CallingConvention="2"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalOptions="/NODEFAULTLIB:library"
+ AdditionalDependencies="libhttpd.lib libapr.lib"
+ OutputFile="$(OutDir)/mod_oggchef.so"
+ LinkIncremental="2"
+ AdditionalLibraryDirectories=""C:\Program Files\Apache Group\Apache2\lib""
+ IgnoreAllDefaultLibraries="FALSE"
+ IgnoreDefaultLibraryNames=""
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/mod_oggchef.pdb"
+ SubSystem="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="2"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories="..\..\lib\helper;..\..\lib\core\ogg;"C:\Program Files\Apache Group\Apache2\include""
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="4"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"
+ CallingConvention="2"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalOptions="/NODEFAULTLIB:library"
+ AdditionalDependencies="libapr.lib libaprutil.lib libhttpd.lib apr.lib aprutil.lib"
+ OutputFile="$(OutDir)/mod_oggchef.so"
+ LinkIncremental="1"
+ AdditionalLibraryDirectories=""C:\Program Files\Apache Group\Apache2\lib""
+ IgnoreAllDefaultLibraries="FALSE"
+ IgnoreDefaultLibraryNames="MSVCRT"
+ GenerateDebugInformation="TRUE"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Debug__cdecl|Win32"
+ OutputDirectory="$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="2"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\..\lib\helper;..\..\lib\core\ogg;"C:\Program Files\Apache Group\Apache2\include""
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
+ MinimalRebuild="TRUE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="4"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="4"
+ CallingConvention="0"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalOptions="/NODEFAULTLIB:library"
+ AdditionalDependencies="libhttpd.lib libapr.lib"
+ OutputFile="$(OutDir)/mod_oggchef.so"
+ LinkIncremental="2"
+ AdditionalLibraryDirectories=""C:\Program Files\Apache Group\Apache2\lib""
+ IgnoreAllDefaultLibraries="FALSE"
+ IgnoreDefaultLibraryNames="MSVCRTD"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/mod_oggchef.pdb"
+ SubSystem="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+ <File
+ RelativePath=".\anx_time.c">
+ </File>
+ <File
+ RelativePath=".\mod_oggchef.cpp">
+ </File>
+ <File
+ RelativePath=".\query_utils.c">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+ <File
+ RelativePath=".\anx_time.h">
+ </File>
+ <File
+ RelativePath=".\apr_stdcall.h">
+ </File>
+ <File
+ RelativePath=".\query_utils.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
+ </Filter>
+ <File
+ RelativePath=".\README.txt">
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
Deleted: trunk/oggdsf/src/tools/mod_oggchef/mod_timeslice.cpp
===================================================================
--- trunk/oggdsf/src/tools/mod_timeslice/mod_timeslice.cpp 2005-01-02 11:49:36 UTC (rev 8573)
+++ trunk/oggdsf/src/tools/mod_oggchef/mod_timeslice.cpp 2005-01-02 14:43:46 UTC (rev 8575)
@@ -1,463 +0,0 @@
-// ===========================================================================
-// Copyright (C) 2004-2005 Zentaro Kavanagh
-// Copyright (C) 2004-2005 Commonwealth Scientific and Industrial Research
-// Organisation (CSIRO) Australia
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-//
-// - Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-//
-// - Redistributions in binary form must reproduce the above copyright
-// notice, this list of conditions and the following disclaimer in the
-// documentation and/or other materials provided with the distribution.
-//
-// - Neither the name of Zentaro Kavanagh, CSIRO Australia nor the names of
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
-// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// ===========================================================================
-
-#include "anx_time.h"
-#include "apr_stdcall.h"
-
-#include "httpd.h"
-#ifdef WIN32
-# undef strtoul /* Otherwise Visual Studio .NET 2003 complains */
-#endif
-#include "http_config.h"
-#include "http_core.h"
-#include "http_log.h"
-#include "http_protocol.h"
-#include "apr_strings.h"
-
-#include <stdio.h>
-#include <string.h>
-
-#include <libOOOgg/libOOOgg.h>
-#include <libOOOgg/dllstuff.h>
-#include <libOOOggSeek/AutoAnxSeekTable.h>
-
-#include <iostream>
-#include <fstream>
-
-
-
-/* Note: This file's pretty ugly at the moment, it's basically a merge of the
- mod_annodex_ap20 source code and AnxCutter. Don't worry, it will be tidied
- up :)
- */
-
-#define DEBUG
-
-#define ANX_MIME_TYPE "application/x-annodex"
-#define CMML_MIME_TYPE "text/x-cmml"
-
-#define CMML_PREAMBLE \
-"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" \
-
-#define MOD_ANNODEX_TYPE_UNKNOWN -1
-
-#define MOD_ANNODEX_TYPE_ANX 0
-#define MOD_ANNODEX_TYPE_CMML 1
-
-#define MEDIA_BUF_LEN 8192
-
-
-/**
- * Create a table corresponding to name=value pairs in the query string
- * @param r The resource request
- * @param query The query string
- * @return A newly created table with corresponding name=value keys.
- */
-static apr_table_t *
-make_cgi_table (request_rec * r, char * query)
-{
- apr_table_t * t;
- char * key, * val, * end;
-
- t = apr_table_make (r->pool, 3);
-
- if (!query) return t;
-
- key = query;
-
- do {
- val = strchr (key, '=');
- end = strchr (key, '&');
-
- if (end) {
- if (val) {
- if (val < end) {
- *val++ = '\0';
- } else {
- val = NULL;
- }
- }
- *end++ = '\0';
- } else {
- if (val) *val++ = '\0';
- }
-
- /*ap_rprintf (r, "%s = %s\n", key, val);*/
- apr_table_set (t, key, val);
-
- key = end;
-
- } while (end != NULL);
-
- return t;
-}
-
-/**
- * Determine the relative quality factor of a mime type given the Accept:
- * header of a resource request, following rules of RFC2616 Sec. 14.1
- * @param r The resource request
- * @param content_type The content_type to check
- * @return The relative quality factor
- */
-static float
-get_accept_quality (request_rec * r, char * content_type)
-{
- char * a, * accept, *next, * last, * pnext, * plast;
- float q = 0.0, type_q = 0.0, all_q = 0.0;
- char * m_sep, * m_major;
- apr_size_t m_major_len;
-
- a = (char *)apr_table_get (r->headers_in, (const char *)"Accept");
-
- /* If there was no Accept: header, accept all types equally */
- if (a == NULL) return 1.0;
-
- /* Form a 'major/*' mime type range for later comparison */
- m_sep = strchr (content_type, '/');
- m_major_len = (apr_size_t)(m_sep - content_type);
- m_major = apr_pstrndup (r->pool, content_type, m_major_len + 2);
- *(m_major+m_major_len+1) = '*';
- *(m_major+m_major_len+2) = '\0';
-
- /* Copy the Accept line for tokenization */
- accept = apr_pstrdup (r->pool, a);
-
- apr_collapse_spaces (accept, accept);
-
- next = apr_strtok (accept, ",", &last);
- while (next) {
- pnext = apr_strtok (next, ";", &plast);
-
- if (!strcmp (pnext, content_type)) {
- while (pnext) {
- pnext = apr_strtok (NULL, ";", &plast);
- if (pnext && sscanf (pnext, "q=%f", &q) == 1) {
- return q;
- }
- }
- return 1.0;
- } else if (!strcmp (pnext, "*/*")) {
- while (pnext) {
- pnext = apr_strtok (NULL, ";", &plast);
- if (pnext && sscanf (pnext, "q=%f", &q) == 1) {
- all_q = q;
- }
- }
- all_q = 1.0;
- } else if (!strcmp (pnext, m_major)) {
- while (pnext) {
- pnext = apr_strtok (NULL, ";", &plast);
- if (pnext && sscanf (pnext, "q=%f", &q) == 1) {
- type_q = q;
- }
- }
- type_q = 1.0;
- }
- next = apr_strtok (NULL, ",", &last);
- }
-
- if (q > 0.0) return q;
- else if (type_q > 0.0) return type_q;
- else return all_q;
-}
-
-
-enum eDemuxState {
- SEEN_NOTHING,
- SEEN_ANNODEX_BOS,
- SEEN_ANNODEX_EOS,
- SEEN_ALL_CODEC_HEADERS,
- INVALID = 100
-};
-
-eDemuxState demuxState;
-
-typedef pair<unsigned long, unsigned long> tSerial_HeadCountPair;
-
-unsigned long bytePos;
-
-bool gotAllHeaders;
-
-vector<tSerial_HeadCountPair> theStreams;
-
-unsigned long annodexSerialNo;
-
-using namespace std;
-
-unsigned long headerCount(OggPacket* inPacket)
-{
- const unsigned short NUM_SEC_HEADERS_OFFSET = 24;
-
- return iLE_Math::charArrToULong(inPacket->packetData() +
- NUM_SEC_HEADERS_OFFSET);
-
-}
-
-request_rec *theRequest;
-
-bool writePageToOutputFile(OggPage* inOggPage) {
- // outputFile.write((char*)inOggPage->createRawPageData(), inOggPage->pageSize());
- ap_rwrite((char*)inOggPage->createRawPageData(),
- inOggPage->pageSize(),
- theRequest);
- return true;
-}
-
-//This will be called by the callback
-bool pageCB(OggPage* inOggPage, void *)
-{
-
- bool allEmpty = true;
-
- switch (demuxState) {
-
- case SEEN_NOTHING:
- if ( (inOggPage->numPackets() == 1)
- && (inOggPage->header()->isBOS())
- && (strncmp((char*)inOggPage->getPacket(0)->packetData(), "Annodex\0", 8) == 0)) {
-
- //Advance the state
- demuxState = SEEN_ANNODEX_BOS;
-
- //Remember the annodex streams serial no
- annodexSerialNo = inOggPage->header()->StreamSerialNo();
-
- //Write out the page.
- writePageToOutputFile(inOggPage);
- } else {
-
- demuxState = INVALID;
- }
-
- break;
- case SEEN_ANNODEX_BOS:
- if ( (inOggPage->numPackets() == 1)
- && (inOggPage->header()->isBOS())
- && (strncmp((char*)inOggPage->getPacket(0)->packetData(), "AnxData\0", 8) == 0)) {
-
-
- //Create an association of serial no and num headers
- tSerial_HeadCountPair locMap;
- locMap.first = inOggPage->header()->StreamSerialNo();
- locMap.second = headerCount(inOggPage->getPacket(0));
-
- //Add the association to the list
- theStreams.push_back(locMap);
-
- //Write the page out to the output file.
- writePageToOutputFile(inOggPage);
- } else if ( (inOggPage->header()->isEOS())
- && (inOggPage->header()->StreamSerialNo() == annodexSerialNo)) {
-
- //It's the Annodex EOS.
- demuxState = SEEN_ANNODEX_EOS;
- writePageToOutputFile(inOggPage);
- } else {
- demuxState = INVALID;
- }
- break;
- case SEEN_ANNODEX_EOS:
- for (unsigned int i = 0; i < theStreams.size(); i++) {
- if (theStreams[i].first == inOggPage->header()->StreamSerialNo()) {
- if (theStreams[i].second >= 1) {
- theStreams[i].second--;
- writePageToOutputFile(inOggPage);
- } else {
- demuxState = INVALID;
- }
- }
- }
-
-
- for (unsigned int i = 0; i < theStreams.size(); i++) {
- if (theStreams[i].second != 0) {
- allEmpty = false;
- }
- }
-
- if (allEmpty) {
-
- demuxState = SEEN_ALL_CODEC_HEADERS;
- }
- break;
- case SEEN_ALL_CODEC_HEADERS:
- break;
- case INVALID:
- break;
- default:
- break;
- }
-
-
- if (demuxState == INVALID) {
- }
- // delete inOggPage;
-
- return true;
-}
-
-static int
-ma_anxenc (request_rec * r, char * filename, char * content_type,
- apr_table_t * cgi_table)
-{
- char * val;
- double seek_offset = 0.0;
-
- theRequest = r;
-
- /* put the requested time into seek_offset */
- val = (char *)apr_table_get (cgi_table, "t");
-
- if (!val)
- {
- fstream inputFile;
- inputFile.open(filename, ios_base::in | ios_base::binary);
- for (;;)
- {
- const unsigned short BUFF_SIZE = 8092;
- char* locBuff = new char[BUFF_SIZE];
-
- inputFile.read(locBuff, BUFF_SIZE);
- unsigned long locBytesRead = inputFile.gcount();
- if (locBytesRead == 0) break;
- ap_rwrite (locBuff, locBytesRead, r);
- }
- inputFile.close();
-
- return 0;
- }
-
- seek_offset = anx_parse_time (val);
-
- /* begin AnxCutter code */
- demuxState = SEEN_NOTHING;
- bytePos = 0;
- gotAllHeaders = false;
- annodexSerialNo = 0;
-
- OggDataBuffer testOggBuff;
- testOggBuff.registerStaticCallback(&pageCB, NULL);
-
- /* rip out the headers from the file */
-
- fstream inputFile;
-
- ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
- "ma_anxenc t=%s (%ld)\n", val, seek_offset);
-
- inputFile.open(filename, ios_base::in | ios_base::binary);
-
- char* locBuff = new char[MEDIA_BUF_LEN];
- while (demuxState < SEEN_ALL_CODEC_HEADERS) {
- inputFile.read(locBuff, MEDIA_BUF_LEN);
- unsigned long locBytesRead = inputFile.gcount();
- if (locBytesRead > 0)
- {
- ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
- "feeding %ld bytes to testOggBuff", locBytesRead);
- }
- testOggBuff.feed((const unsigned char*)locBuff, locBytesRead);
- }
- inputFile.close();
-
- // Build a seek table for the file
- AutoAnxSeekTable *locSeekTable = new AutoAnxSeekTable(filename);
- locSeekTable->buildTable();
-
- // Seek to the user's requested start time
- LOOG_UINT64 locStartTime = (LOOG_UINT64) seek_offset * 10000000;
- OggSeekTable::tSeekPair locSeekResult = locSeekTable->getStartPos(locStartTime);
-
- // Stream-copy everything from the requested timepoint onward to the output file
- inputFile.open(filename, ios_base::in | ios_base::binary);
- inputFile.seekg(locSeekResult.second);
-
- for (;;) {
- inputFile.read(locBuff, MEDIA_BUF_LEN);
- unsigned long locBytesRead = inputFile.gcount();
- if (locBytesRead == 0) break;
- //outputFile.write(locBuff, locBytesRead);
- ap_rwrite (locBuff, locBytesRead, r);
- }
- inputFile.close();
-
- ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
- "Served request");
-}
-
-
-extern "C" {
-
-/* The annodex content handler */
-static int AP_MODULE_ENTRY_POINT annodex_handler(request_rec *r)
-{
- apr_uri_t * uri;
- char * filename;
- apr_table_t * cgi_table;
-
- ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
- "Got here 2");
-
- uri = &(r->parsed_uri);
-
- /* usually filename is request filename */
- filename = r->filename;
-
- ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
- "filename is %s", filename);
-
- cgi_table = make_cgi_table (r, uri->query);
-
- ma_anxenc (r, r->filename, ANX_MIME_TYPE, cgi_table);
-
- return OK;
-}
-
-static void AP_MODULE_ENTRY_POINT annodex_register_hooks(apr_pool_t *p)
-{
- ap_hook_handler(AP_HOOK_HANDLER_FUNCTION(annodex_handler),
- NULL, NULL, APR_HOOK_MIDDLE);
-}
-
-/* Dispatch list for API hooks */
-module AP_MODULE_DECLARE_DATA timeslice_module = {
- STANDARD20_MODULE_STUFF,
- NULL, /* create per-dir config structures */
- NULL, /* merge per-dir config structures */
- NULL, /* create per-server config structures */
- NULL, /* merge per-server config structures */
- NULL, /* table of config file commands */
- AP_REGISTER_HOOK_FUNCTION(annodex_register_hooks) /* register hooks */
-};
-
-} /* extern "C" */
Deleted: trunk/oggdsf/src/tools/mod_oggchef/mod_timeslice.vcproj
===================================================================
--- trunk/oggdsf/src/tools/mod_timeslice/mod_timeslice.vcproj 2005-01-02 11:49:36 UTC (rev 8573)
+++ trunk/oggdsf/src/tools/mod_oggchef/mod_timeslice.vcproj 2005-01-02 14:43:46 UTC (rev 8575)
@@ -1,213 +0,0 @@
-<?xml version="1.0" encoding="Windows-1252"?>
-<VisualStudioProject
- ProjectType="Visual C++"
- Version="7.10"
- Name="mod_timeslice"
- ProjectGUID="{F8FDD992-E21A-483F-BBE7-305D10163DE4}"
- Keyword="Win32Proj">
- <Platforms>
- <Platform
- Name="Win32"/>
- </Platforms>
- <Configurations>
- <Configuration
- Name="Debug|Win32"
- OutputDirectory="Debug"
- IntermediateDirectory="Debug"
- ConfigurationType="2"
- CharacterSet="2">
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\lib\helper;..\..\lib\core\ogg;"C:\Program Files\Apache Group\Apache2\include""
- PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
- MinimalRebuild="TRUE"
- BasicRuntimeChecks="3"
- RuntimeLibrary="3"
- UsePrecompiledHeader="0"
- WarningLevel="4"
- Detect64BitPortabilityProblems="TRUE"
- DebugInformationFormat="4"
- CallingConvention="2"/>
- <Tool
- Name="VCCustomBuildTool"/>
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="/NODEFAULTLIB:library"
- AdditionalDependencies="libhttpd.lib libapr.lib"
- OutputFile="$(OutDir)/mod_timeslice.so"
- LinkIncremental="2"
- AdditionalLibraryDirectories=""C:\Program Files\Apache Group\Apache2\lib""
- IgnoreAllDefaultLibraries="FALSE"
- IgnoreDefaultLibraryNames=""
- GenerateDebugInformation="TRUE"
- ProgramDatabaseFile="$(OutDir)/mod_timeslice.pdb"
- SubSystem="2"
- TargetMachine="1"/>
- <Tool
- Name="VCMIDLTool"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
- <Tool
- Name="VCPreLinkEventTool"/>
- <Tool
- Name="VCResourceCompilerTool"/>
- <Tool
- Name="VCWebServiceProxyGeneratorTool"/>
- <Tool
- Name="VCXMLDataGeneratorTool"/>
- <Tool
- Name="VCWebDeploymentTool"/>
- <Tool
- Name="VCManagedWrapperGeneratorTool"/>
- <Tool
- Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
- </Configuration>
- <Configuration
- Name="Release|Win32"
- OutputDirectory="Release"
- IntermediateDirectory="Release"
- ConfigurationType="2"
- CharacterSet="2">
- <Tool
- Name="VCCLCompilerTool"
- AdditionalIncludeDirectories="..\..\lib\helper;..\..\lib\core\ogg;"C:\Program Files\Apache Group\Apache2\include""
- PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
- RuntimeLibrary="2"
- UsePrecompiledHeader="0"
- WarningLevel="4"
- Detect64BitPortabilityProblems="TRUE"
- DebugInformationFormat="3"
- CallingConvention="2"/>
- <Tool
- Name="VCCustomBuildTool"/>
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="/NODEFAULTLIB:library"
- AdditionalDependencies="libapr.lib libaprutil.lib libhttpd.lib apr.lib aprutil.lib"
- OutputFile="$(OutDir)/mod_timeslice.so"
- LinkIncremental="1"
- AdditionalLibraryDirectories=""C:\Program Files\Apache Group\Apache2\lib""
- IgnoreAllDefaultLibraries="FALSE"
- IgnoreDefaultLibraryNames="MSVCRT"
- GenerateDebugInformation="TRUE"
- SubSystem="2"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- TargetMachine="1"/>
- <Tool
- Name="VCMIDLTool"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
- <Tool
- Name="VCPreLinkEventTool"/>
- <Tool
- Name="VCResourceCompilerTool"/>
- <Tool
- Name="VCWebServiceProxyGeneratorTool"/>
- <Tool
- Name="VCXMLDataGeneratorTool"/>
- <Tool
- Name="VCWebDeploymentTool"/>
- <Tool
- Name="VCManagedWrapperGeneratorTool"/>
- <Tool
- Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
- </Configuration>
- <Configuration
- Name="Debug__cdecl|Win32"
- OutputDirectory="$(ConfigurationName)"
- IntermediateDirectory="$(ConfigurationName)"
- ConfigurationType="2"
- CharacterSet="2">
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\lib\helper;..\..\lib\core\ogg;"C:\Program Files\Apache Group\Apache2\include""
- PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
- MinimalRebuild="TRUE"
- BasicRuntimeChecks="3"
- RuntimeLibrary="3"
- UsePrecompiledHeader="0"
- WarningLevel="4"
- Detect64BitPortabilityProblems="TRUE"
- DebugInformationFormat="4"
- CallingConvention="0"/>
- <Tool
- Name="VCCustomBuildTool"/>
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="/NODEFAULTLIB:library"
- AdditionalDependencies="libhttpd.lib libapr.lib"
- OutputFile="$(OutDir)/mod_timeslice.so"
- LinkIncremental="2"
- AdditionalLibraryDirectories=""C:\Program Files\Apache Group\Apache2\lib""
- IgnoreAllDefaultLibraries="FALSE"
- IgnoreDefaultLibraryNames="MSVCRTD"
- GenerateDebugInformation="TRUE"
- ProgramDatabaseFile="$(OutDir)/mod_timeslice.pdb"
- SubSystem="2"
- TargetMachine="1"/>
- <Tool
- Name="VCMIDLTool"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
- <Tool
- Name="VCPreLinkEventTool"/>
- <Tool
- Name="VCResourceCompilerTool"/>
- <Tool
- Name="VCWebServiceProxyGeneratorTool"/>
- <Tool
- Name="VCXMLDataGeneratorTool"/>
- <Tool
- Name="VCWebDeploymentTool"/>
- <Tool
- Name="VCManagedWrapperGeneratorTool"/>
- <Tool
- Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
- </Configuration>
- </Configurations>
- <References>
- </References>
- <Files>
- <Filter
- Name="Source Files"
- Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
- UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
- <File
- RelativePath=".\anx_time.c">
- </File>
- <File
- RelativePath=".\mod_timeslice.cpp">
- </File>
- </Filter>
- <Filter
- Name="Header Files"
- Filter="h;hpp;hxx;hm;inl;inc;xsd"
- UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
- <File
- RelativePath=".\anx_time.h">
- </File>
- <File
- RelativePath=".\apr_stdcall.h">
- </File>
- </Filter>
- <Filter
- Name="Resource Files"
- Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
- UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
- </Filter>
- <File
- RelativePath=".\README.txt">
- </File>
- </Files>
- <Globals>
- </Globals>
-</VisualStudioProject>
Modified: trunk/oggdsf/src/tools/mod_oggchef/modules.mk
===================================================================
--- trunk/oggdsf/src/tools/mod_timeslice/modules.mk 2005-01-02 11:49:36 UTC (rev 8573)
+++ trunk/oggdsf/src/tools/mod_oggchef/modules.mk 2005-01-02 14:43:46 UTC (rev 8575)
@@ -1,4 +1,4 @@
-mod_timeslice.la: mod_timeslice.slo
- $(SH_LINK) -rpath $(libexecdir) -module -avoid-version mod_timeslice.lo
+mod_oggchef.la: mod_oggchef.slo
+ $(SH_LINK) -rpath $(libexecdir) -module -avoid-version mod_oggchef.lo
DISTCLEAN_TARGETS = modules.mk
-shared = mod_timeslice.la
+shared = mod_oggchef.la
Added: trunk/oggdsf/src/tools/mod_oggchef/query_utils.c
===================================================================
--- trunk/oggdsf/src/tools/mod_timeslice/query_utils.c 2005-01-02 11:49:36 UTC (rev 8573)
+++ trunk/oggdsf/src/tools/mod_oggchef/query_utils.c 2005-01-02 14:43:46 UTC (rev 8575)
@@ -0,0 +1,155 @@
+/*
+ Copyright (C) 2003-2005 Commonwealth Scientific and Industrial Research
+ Organisation (CSIRO) Australia
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ - Neither the name of CSIRO Australia nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#include "query_utils.h"
+
+#include "httpd.h"
+#ifdef WIN32
+# undef strtoul /* Otherwise Visual Studio .NET 2003 complains */
+#endif
+#include "apr_strings.h"
+
+
+/**
+ * Determine the relative quality factor of a mime type given the Accept:
+ * header of a resource request, following rules of RFC2616 Sec. 14.1
+ * @param r The resource request
+ * @param content_type The content_type to check
+ * @return The relative quality factor
+ */
+float get_accept_quality (request_rec * r, char * content_type)
+{
+ char * a, * accept, *next, * last, * pnext, * plast;
+ float q = 0.0, type_q = 0.0, all_q = 0.0;
+ char * m_sep, * m_major;
+ apr_size_t m_major_len;
+
+ a = (char *)apr_table_get (r->headers_in, (const char *)"Accept");
+
+ /* If there was no Accept: header, accept all types equally */
+ if (a == NULL) return 1.0;
+
+ /* Form a 'major/*' mime type range for later comparison */
+ m_sep = strchr (content_type, '/');
+ m_major_len = (apr_size_t)(m_sep - content_type);
+ m_major = apr_pstrndup (r->pool, content_type, m_major_len + 2);
+ *(m_major+m_major_len+1) = '*';
+ *(m_major+m_major_len+2) = '\0';
+
+ /* Copy the Accept line for tokenization */
+ accept = apr_pstrdup (r->pool, a);
+
+ apr_collapse_spaces (accept, accept);
+
+ next = apr_strtok (accept, ",", &last);
+ while (next) {
+ pnext = apr_strtok (next, ";", &plast);
+
+ if (!strcmp (pnext, content_type)) {
+ while (pnext) {
+ pnext = apr_strtok (NULL, ";", &plast);
+ if (pnext && sscanf (pnext, "q=%f", &q) == 1) {
+ return q;
+ }
+ }
+ return 1.0;
+ } else if (!strcmp (pnext, "*/*")) {
+ while (pnext) {
+ pnext = apr_strtok (NULL, ";", &plast);
+ if (pnext && sscanf (pnext, "q=%f", &q) == 1) {
+ all_q = q;
+ }
+ }
+ all_q = 1.0;
+ } else if (!strcmp (pnext, m_major)) {
+ while (pnext) {
+ pnext = apr_strtok (NULL, ";", &plast);
+ if (pnext && sscanf (pnext, "q=%f", &q) == 1) {
+ type_q = q;
+ }
+ }
+ type_q = 1.0;
+ }
+ next = apr_strtok (NULL, ",", &last);
+ }
+
+ if (q > 0.0) return q;
+ else if (type_q > 0.0) return type_q;
+ else return all_q;
+}
+
+
+/**
+ * Create a table corresponding to name=value pairs in the query string
+ * @param r The resource request
+ * @param query The query string
+ * @return A newly created table with corresponding name=value keys.
+ */
+apr_table_t *make_cgi_table (request_rec * r, char * query)
+{
+ apr_table_t * t;
+ char * key, * val, * end;
+
+ t = apr_table_make (r->pool, 3);
+
+ if (!query) return t;
+
+ key = query;
+
+ do {
+ val = strchr (key, '=');
+ end = strchr (key, '&');
+
+ if (end) {
+ if (val) {
+ if (val < end) {
+ *val++ = '\0';
+ } else {
+ val = NULL;
+ }
+ }
+ *end++ = '\0';
+ } else {
+ if (val) *val++ = '\0';
+ }
+
+ /*ap_rprintf (r, "%s = %s\n", key, val);*/
+ apr_table_set (t, key, val);
+
+ key = end;
+
+ } while (end != NULL);
+
+ return t;
+}
+
Property changes on: trunk/oggdsf/src/tools/mod_oggchef/query_utils.c
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/oggdsf/src/tools/mod_oggchef/query_utils.h
===================================================================
--- trunk/oggdsf/src/tools/mod_timeslice/query_utils.h 2005-01-02 11:49:36 UTC (rev 8573)
+++ trunk/oggdsf/src/tools/mod_oggchef/query_utils.h 2005-01-02 14:43:46 UTC (rev 8575)
@@ -0,0 +1,50 @@
+/*
+ Copyright (C) 2005 Commonwealth Scientific and Industrial Research
+ Organisation (CSIRO) Australia
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ - Neither the name of CSIRO Australia nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#pragma once
+
+
+#include "httpd.h"
+#ifdef WIN32
+# undef strtoul /* Otherwise Visual Studio .NET 2003 complains */
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+float get_accept_quality (request_rec * r, char * content_type);
+apr_table_t * make_cgi_table (request_rec * r, char * query);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
Property changes on: trunk/oggdsf/src/tools/mod_oggchef/query_utils.h
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the commits
mailing list