/** * Read File * Read a file from disk and return the appropriate Resource object * * @param path Full disk path of the file * @param sb Filled in stat struct * @return Return's the resource object upon successful load */ Resource* ResourceHost::readFile(std::string path, struct stat sb) { // Make sure the webserver USER owns the file if(!(sb.st_mode & S_IRWXU)) return NULL; std::ifstream file; unsigned int len = 0; // Open the file file.open(path.c_str(), std::ios::binary); // Return null if the file failed to open if(!file.is_open()) return NULL; // Get the length of the file /*file.seekg(0, std::ios::end); len = file.tellg(); file.seekg(0, std::ios::beg);*/ len = sb.st_size; // Allocate memory for contents of file and read in the contents byte* fdata = new byte[len]; file.read((char*)fdata, len); // Close the file file.close(); // Create a new Resource object and setup it's contents Resource* res = new Resource(path); res->setMimeType(lookupMimeType(res->getExtension())); res->setData(fdata, len); return res; }
NSPluginInstance *NSPluginLoader::newInstance(QWidget *parent, QString url, QString mimeType, bool embed, QStringList argn, QStringList argv, QString appId, QString callbackId, bool reload, bool doPost, QByteArray postData) { kdDebug() << "-> NSPluginLoader::NewInstance( parent=" << (void*)parent << ", url=" << url << ", mime=" << mimeType << ", ...)" << endl; if ( !_viewer ) { // load plugin viewer process loadViewer(); if ( !_viewer ) { kdDebug() << "No viewer dcop stub found" << endl; return 0; } } // check the mime type QString mime = mimeType; if (mime.isEmpty()) { mime = lookupMimeType( url ); argn << "MIME"; argv << mime; } if (mime.isEmpty()) { kdDebug() << "Unknown MimeType" << endl; return 0; } // lookup plugin for mime type QString plugin_name = lookup(mime); if (plugin_name.isEmpty()) { kdDebug() << "No suitable plugin" << endl; return 0; } // get plugin class object DCOPRef cls_ref = _viewer->newClass( plugin_name ); if ( cls_ref.isNull() ) { kdDebug() << "Couldn't create plugin class" << endl; return 0; } NSPluginClassIface_stub *cls = new NSPluginClassIface_stub( cls_ref.app(), cls_ref.object() ); // handle special plugin cases if ( mime=="application/x-shockwave-flash" ) embed = true; // flash doesn't work in full mode :( NSPluginInstance *plugin = new NSPluginInstance( parent ); kdDebug() << "<- NSPluginLoader::NewInstance = " << (void*)plugin << endl; // get plugin instance DCOPRef inst_ref = cls->newInstance( url, mime, embed, argn, argv, appId, callbackId, reload, doPost, postData, plugin->winId()); if ( inst_ref.isNull() ) { kdDebug() << "Couldn't create plugin instance" << endl; delete plugin; return 0; } plugin->init( inst_ref.app(), inst_ref.object() ); return plugin; }