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 "RioMMKeywords.h"
00023 #include "common.h"
00024 #include "CommonLibraries.h"
00025
00026 #include <qstring.h>
00027
00028 CRioMMKeywords::CRioMMKeywords( char *KeywordsName, unsigned int blocksize,
00029 RioBlock numBuffers, struct timeval RTT_average,
00030 RioMMInterface *rio_interface )
00031 : CRioMMObject( KeywordsName, blocksize, numBuffers , RTT_average )
00032 {
00033 setRio( rio_interface );
00034 KeywordsFile = NULL;
00035 }
00036
00037 int CRioMMKeywords::GetKeywords( RioAccess Access, CRioStream *Stream )
00038 {
00039 int rc;
00040 char tempdir[ MAXPATHSIZE ] = "RIOxmlXXXXXX";
00041 char tempfilename[ MAXPATHSIZE ];
00042
00043 KeywordsFile = new RioFile( MMObjectName, BlockSize );
00044 RioFile *DTDFile = new RioFile( "/etc/dtd/keyword.dtd", BlockSize );
00045
00046 rc = KeywordsFile->Open( Access, Stream );
00047 if( rc < 0 )
00048 {
00049 return rc;
00050 }
00051
00052 rc = DTDFile->Open( Access, Stream );
00053 if( rc < 0 )
00054 {
00055 sendMsg( QString( "RioMMKeywords" ),
00056 QString( "DTD file not found at server.\n" ) +
00057 QString( "Keyword file will not be loaded." ), getRio() );
00058
00059 KeywordsFile->Close();
00060 return rc;
00061 }
00062
00063
00064
00065
00066
00067 if( RIOmktemp( tempdir ) == false )
00068 {
00069 RioErr << "[RioMMKeywords]: Cannot create directory " << tempdir << endl;
00070
00071 KeywordsFile->Close();
00072 delete DTDFile;
00073 return 0;
00074 }
00075
00076 mkdir( tempdir, 0700 );
00077
00078 strcpy( tempfilename, tempdir );
00079 strcat( tempfilename, "/keywords.index" );
00080 KeywordsFile->Download( tempfilename );
00081
00082 strcpy( tempfilename, tempdir );
00083 strcat( tempfilename, "/keyword.dtd" );
00084 DTDFile->Download( tempfilename );
00085 setDomTree( new QDomDocument );
00086
00087 QFile opmlFile( KeywordsFile->GetLocalFilename() );
00088
00089 QFile dtdLocalFile( DTDFile->GetLocalFilename() );
00090
00091
00092 xmlDoValidityCheckingDefaultValue = 1;
00093 xmlDocPtr doc = xmlParseFile( KeywordsFile->GetLocalFilename() );
00094
00095 xmlValidCtxt cvp;
00096 cvp.userData = NULL;
00097 cvp.error = (xmlValidityErrorFunc) donothing2;
00098 cvp.warning = (xmlValidityWarningFunc) donothing2;
00099
00100 if( !xmlValidateDocumentFinal( &cvp, doc ) ||
00101 !xmlValidateDocument( &cvp, doc ) )
00102 {
00103 sendMsg( QString( "RioMMKeywords" ),
00104 QString( "Invalid keyword file according to DTD.\n" ) +
00105 QString( "It will not be loaded." ), getRio() );
00106 opmlFile.close();
00107 opmlFile.remove();
00108 dtdLocalFile.remove();
00109 rmdir( tempdir );
00110
00111 KeywordsFile->Close();
00112 delete DTDFile;
00113 return 0;
00114 }
00115
00116 xmlXIncludeProcess( doc );
00117 xmlFreeDoc( doc );
00118 xmlCleanupParser();
00119 xmlMemoryDump();
00120
00121 if( !opmlFile.open( IO_ReadOnly ) )
00122 {
00123 RioErr << "[RioMMKeywords]: Cannot open keywords file." << endl;
00124 opmlFile.close();
00125 opmlFile.remove();
00126 dtdLocalFile.remove();
00127 rmdir( tempdir );
00128
00129 KeywordsFile->Close();
00130 delete DTDFile;
00131 return 0;
00132 }
00133
00134 if( !getDomTree()->setContent( &opmlFile ) )
00135 {
00136 RioErr << "[RioMMKeywords]: Parsing error for keyword file." << endl;
00137 opmlFile.close();
00138 opmlFile.remove();
00139 dtdLocalFile.remove();
00140 rmdir( tempdir );
00141
00142 KeywordsFile->Close();
00143 delete DTDFile;
00144 return 0;
00145 }
00146
00147 opmlFile.close();
00148 opmlFile.remove();
00149 dtdLocalFile.remove();
00150 rmdir( tempdir );
00151
00152
00153 QCustomEvent *event = new QCustomEvent( (QEvent::Type)(QEvent::User + 6),
00154 getDomTree() );
00155 QApplication::postEvent( getRio(), event );
00156
00157
00158 KeywordsFile->Close();
00159 delete DTDFile;
00160
00161 return 1;
00162 }
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 void CRioMMKeywords::Play()
00175 {
00176 }
00177
00178 void CRioMMKeywords::Stop()
00179 {
00180 }
00181
00182 void CRioMMKeywords::Pause()
00183 {
00184 }
00185
00186 void CRioMMKeywords::FastRewind()
00187 {
00188 }
00189
00190 void CRioMMKeywords::FastForward()
00191 {
00192 }
00193
00194 void CRioMMKeywords::GoTo( unsigned int )
00195 {
00196 }
00197
00198 int CRioMMKeywords::init()
00199 {
00200 return 0;
00201 }
00202
00203 RioBlock CRioMMKeywords::GetCurrentPosition()
00204 {
00205 return 0;
00206 }
00207
00208 RioBlock CRioMMKeywords::GetTotalPositions()
00209 {
00210 return 0;
00211 }
00212
00213 void CRioMMKeywords::setDomTree( QDomDocument *d )
00214 {
00215 domTree = d;
00216 }
00217
00218 QDomDocument *CRioMMKeywords::getDomTree()
00219 {
00220 return domTree;
00221 }
00222
00223 void CRioMMKeywords::setRio( RioMMInterface *r )
00224 {
00225 rio = r;
00226 }
00227
00228 RioMMInterface *CRioMMKeywords::getRio()
00229 {
00230 return rio;
00231 }
00232
00233 CRioMMKeywords::~CRioMMKeywords()
00234 {
00235 if( KeywordsFile )
00236 {
00237 delete KeywordsFile;
00238 KeywordsFile = NULL;
00239 }
00240 }
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 void donothing2()
00251 {
00252 }