gdSnarfCommon.cpp

Go to the documentation of this file.
00001 // gdSnarfCommon.cpp -- Version 0.0
00002 
00003 #include <string.h>
00004 #include "gdSnarfCommon.h"
00005 ////////////////////////////////////////////////////////////
00006 FILE* gdOptUnweb::DumpStream ()
00007 {
00008  ASSERTION(fDump!=nil,"fDump!=nil");
00009  return fDump;
00010 }
00011 ////////////////////////////////////////////////////////////
00012 sOptSnarf::~sOptSnarf ()
00013 {
00014  delete unwebOpt;
00015  if ( OutStreamWasOpened() ) fclose( fOut );
00016 }
00017 
00018 bool sOptSnarf::HasSpecURI ()
00019 {
00020  return strcmp( myURI.Str(), myURI.GetOriginalStr() )!=0;
00021 }
00022 
00023 FILE* sOptSnarf::OutStream ()
00024 {
00025  ASSERTION(fOut!=nil,"fOut!=nil");
00026  return fOut;
00027 }
00028 
00029 gdOptUnweb& sOptSnarf::UnwebOpt ()
00030 {
00031  ASSERTION(unwebOpt!=nil,"unwebOpt!=nil");
00032  return *unwebOpt;
00033 }
00034 
00035 int sOptSnarf::ShowStats (FILE* fStat, gTimerTic& tic, t_gTicElapsed cpuTics)
00036 {
00037  t_uint32 elapsedMilisec;
00038  t_uint32 inOctets = GetInOctets();
00039  t_uint32 paceMade;
00040  float octPerSec;
00041 
00042  if ( fStat==nil ) return -1;
00043 
00044  elapsedMilisec = tic.GetMilisec();
00045  octPerSec = (float)inOctets / (elapsedMilisec==0 ? 0.001 : (float)elapsedMilisec);
00046  fprintf(fStat,"Stats (in miliseconds):\nTotal: CPU_used=%0.0f ms, elapsed=%u ms\n",
00047          (float)tic.GetMilisecsFromTics( cpuTics ),
00048          elapsedMilisec);
00049  if ( isVerbose==true || inOctets>1000 ) {
00050      fprintf(fStat,"Total octets: %u\n",inOctets);
00051      if ( nStat>2 ) {
00052          paceMade = vStat[3].GetUInt();
00053          fprintf(fStat, "Head reply: %u ms, content reply: %u ms, client pace: %u ms\n",
00054                  vStat[1].GetUInt(),
00055                  vStat[2].GetUInt()-paceMade,
00056                  paceMade);
00057      }
00058      fprintf(fStat,"Throughput (Octets/s): in=%0.1f\n",octPerSec);
00059  }
00060 
00061  return 0;
00062 }
00063 
00064 int sOptSnarf::GoCmdHttp (gURI& aURI)
00065 {
00066  int thisError;
00067  char* strOriginal = aURI.GetOriginalStr();
00068 
00069  thisError = aURI.IsOkScheme()==false;
00070  if ( thisError!=0 ) return 1;  // Invalid scheme
00071 
00072  // If only a domain is given, without any slashes (e.g. gdthreepic http fuji),
00073  // then the URI domain is empty (!) and the path is fuji; this is o.k.,
00074  // as a URI can be just a relative name of a file;
00075  // we need to assume path as / and the domain is the string itself, as the user intended.
00076  gString sTemp( aURI.GetPathStr() );
00077  if ( sTemp.Match( strOriginal ) ) {
00078      sTemp.Add( '/' );
00079      resultURI.SetString( sTemp.Str() );
00080  }
00081  else {
00082      // Just copy aURI into resultURI
00083      resultURI.SetString( aURI.GetOriginalStr() );
00084  }
00085 
00086  return thisError;
00087 }
00088 ////////////////////////////////////////////////////////////
00089 // glib required functions
00090 ////////////////////////////////////////////////////////////
00091 int gglobal_EventTerminate (int v)
00092 {
00093  return 0;
00094 }
00095 ////////////////////////////////////////////////////////////
00096 

Generated on Sat Aug 18 02:40:52 2007 for xpfweb_v2x lib by  doxygen 1.4.2