00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <stdlib.h>
00019 #include <sys/stat.h>
00020 #include <libxml/xinclude.h>
00021
00022 #include "RioMMTopics.h"
00023 #include "common.h"
00024 #include "CommonLibraries.h"
00025
00026 #include <qfile.h>
00027 #include <qheader.h>
00028 #include <qstring.h>
00029 #include <qmessagebox.h>
00030 #include <qdialog.h>
00031
00032 CRioMMTopics::CRioMMTopics( char *TopicsName, unsigned int blocksize,
00033 RioBlock numBuffers,
00034 struct timeval RTT_average,
00035 RioMMInterface *rio_interface )
00036 : CRioMMObject( TopicsName, blocksize, numBuffers , RTT_average )
00037 {
00038 setRio( rio_interface );
00039 TopicsFile = NULL;
00040 }
00041
00042 int CRioMMTopics::GetTopics( RioAccess Access, CRioStream *Stream )
00043 {
00044 int rc;
00045 char tempdir[MAXPATHSIZE] = "RIOxmlXXXXXX";
00046 char tempfilename[MAXPATHSIZE];
00047
00048 TopicsFile = new RioFile( MMObjectName, BlockSize );
00049 RioFile *DTDFile = new RioFile( "/etc/dtd/index.dtd", BlockSize );
00050
00051 rc = TopicsFile->Open( Access, Stream );
00052 if( rc < 0 )
00053 {
00054 return rc;
00055 }
00056
00057 rc = DTDFile->Open( Access, Stream );
00058 if( rc < 0 )
00059 {
00060 sendMsg( QString( "RioMMTopics" ), QString( "DTD file not found " ) +
00061 QString( "at server.\nIndex file will not be loaded." ),
00062 getRio() );
00063
00064 TopicsFile->Close();
00065 return rc;
00066 }
00067
00068
00069
00070
00071
00072 if( RIOmktemp( tempdir ) == false )
00073 {
00074 RioErr << "[RioMMTopics]: Cannot create directory " << tempdir << endl;
00075
00076 TopicsFile->Close();
00077 delete DTDFile;
00078 return 0;
00079 }
00080
00081 mkdir( tempdir, 0700 );
00082
00083 strcpy( tempfilename, tempdir );
00084 strcat( tempfilename, "/topics.index" );
00085 TopicsFile->Download( tempfilename );
00086
00087 strcpy( tempfilename, tempdir );
00088 strcat( tempfilename, "/index.dtd" );
00089 DTDFile->Download( tempfilename );
00090 setDomTree( new QDomDocument );
00091
00092 QFile opmlFile( TopicsFile->GetLocalFilename() );
00093
00094 QFile dtdLocalFile( DTDFile->GetLocalFilename() );
00095
00096
00097 xmlDoValidityCheckingDefaultValue = 1;
00098 xmlDocPtr doc = xmlParseFile( TopicsFile->GetLocalFilename() );
00099
00100 xmlValidCtxt cvp;
00101 cvp.userData = NULL;
00102 cvp.error = (xmlValidityErrorFunc) donothing;
00103 cvp.warning = (xmlValidityWarningFunc) donothing;
00104
00105 if( !xmlValidateDocumentFinal( &cvp, doc ) ||
00106 !xmlValidateDocument( &cvp, doc )
00107 )
00108 {
00109 sendMsg( QString( "RioMMTopics" ),
00110 QString( "Invalid index file according to DTD.\n") +
00111 QString( "It will not be loaded." ), getRio() );
00112 opmlFile.close();
00113 opmlFile.remove();
00114 dtdLocalFile.remove();
00115 rmdir( tempdir );
00116
00117 TopicsFile->Close();
00118 delete DTDFile;
00119 return 0;
00120 }
00121 xmlXIncludeProcess( doc );
00122 xmlFreeDoc( doc );
00123 xmlCleanupParser();
00124 xmlMemoryDump();
00125
00126 if( !opmlFile.open( IO_ReadOnly ) )
00127 {
00128 RioErr << "[RioMMTopics]: Cannot open topics file." << endl;
00129 opmlFile.close();
00130 opmlFile.remove();
00131 dtdLocalFile.remove();
00132 rmdir( tempdir );
00133
00134 TopicsFile->Close();
00135 delete DTDFile;
00136 return 0;
00137 }
00138 if( !getDomTree()->setContent( &opmlFile ) )
00139 {
00140 RioErr << "[RioMMTopics]: Parsing error for index file." << endl;
00141 opmlFile.close();
00142 opmlFile.remove();
00143 dtdLocalFile.remove();
00144 rmdir( tempdir );
00145
00146 TopicsFile->Close();
00147 delete DTDFile;
00148 return 0;
00149 }
00150 opmlFile.close();
00151 opmlFile.remove();
00152 dtdLocalFile.remove();
00153 rmdir( tempdir );
00154
00155
00156 QCustomEvent *event = new QCustomEvent( (QEvent::Type)(QEvent::User + 3),
00157 getDomTree() );
00158 QApplication::postEvent( getRio(), event );
00159
00160
00161 TopicsFile->Close();
00162 delete DTDFile;
00163
00164 return 1;
00165 }
00166
00167 void CRioMMTopics::Play() {}
00168 void CRioMMTopics::Stop() {}
00169 void CRioMMTopics::Pause() {}
00170 void CRioMMTopics::FastRewind() {}
00171 void CRioMMTopics::FastForward() {}
00172 void CRioMMTopics::GoTo(unsigned int) {}
00173 int CRioMMTopics::init() { return 0;}
00174 RioBlock CRioMMTopics::GetCurrentPosition() { return 0; }
00175 RioBlock CRioMMTopics::GetTotalPositions() { return 0; }
00176
00177 void CRioMMTopics::setDomTree( QDomDocument *d ) { domTree = d; }
00178 QDomDocument *CRioMMTopics::getDomTree() { return domTree; }
00179
00180 void CRioMMTopics::setRio( RioMMInterface *r ) { rio = r; }
00181 RioMMInterface *CRioMMTopics::getRio() { return rio; }
00182
00183 CRioMMTopics::~CRioMMTopics()
00184 {
00185 if( TopicsFile )
00186 {
00187 delete TopicsFile;
00188 TopicsFile = NULL;
00189 }
00190 }
00191
00192 void donothing(){}