void SCXWQLSelectStatementCMPI::SetExp(CMPISelectExp *exp) { SCX_LOGTRACE(this->m_log, L"SetExp(CMPISelectExp *exp)"); if(exp) { cmpiExp = exp; CMPIStatus st; CMPISelectCond *cond = exp->ft->getDOC(exp, &st); if(CMPI_RC_OK != st.rc) { throw SCXInternalErrorException(L"GetDoc failed in CMPI: " + StrFromUTF8(st.msg->ft->getCharPtr(st.msg, NULL) ? st.msg->ft->getCharPtr(st.msg, NULL) : ""), SCXSRCLOCATION); } unsigned i = cond->ft->getCountAndType(cond, NULL, &st); if(CMPI_RC_OK != st.rc) { throw SCXInternalErrorException(L"GetCountAndType failed in CMPI: " + StrFromUTF8(st.msg->ft->getCharPtr(st.msg, NULL) ? st.msg->ft->getCharPtr(st.msg, NULL) : ""), SCXSRCLOCATION); } for (unsigned j = 0; j< i; j++) { SCXHandle<Condition> c = CreateCondition(cond->ft->getSubCondAt(cond, j, &st)); if(CMPI_RC_OK != st.rc) throw SCXInternalErrorException(L"getSubCondAt failed in CMPI: " + StrFromUTF8(st.msg->ft->getCharPtr(st.msg, NULL) ? st.msg->ft->getCharPtr(st.msg, NULL) : ""), SCXSRCLOCATION); this->doc.push_back(*c); } } SCX_LOGTRACE(this->m_log, L"Exit SetExp(CMPISelectExp *exp)"); }
void SCXWQLSelectStatementCMPI::SetProjection(CMPIArray *projectionPtr) { SCX_LOGTRACE(this->m_log, L"SetProjection(CMPIArray *projectionPtr)"); if(projectionPtr) { cmpiProjection = projectionPtr; CMPIStatus st; unsigned i = projectionPtr->ft->getSize(projectionPtr, &st); if(CMPI_RC_OK != st.rc) { throw SCXInternalErrorException(L"GetSize failed in CMPI: " + StrFromUTF8(st.msg->ft->getCharPtr(st.msg, NULL) ? st.msg->ft->getCharPtr(st.msg, NULL) : ""), SCXSRCLOCATION); } for (unsigned j = 0; j< i; j++) { CMPIData d = projectionPtr->ft->getElementAt(projectionPtr, j, &st); if(CMPI_RC_OK != st.rc) { throw SCXInternalErrorException(L"getElementAt failed in CMPI: " + StrFromUTF8(st.msg->ft->getCharPtr(st.msg, NULL) ? st.msg->ft->getCharPtr(st.msg, NULL) : ""), SCXSRCLOCATION); } if(CMPI_string == d.type) { SCXHandle<SCXProperty> p(new SCXProperty(StrFromUTF8(d.value.string->ft->getCharPtr(d.value.string, &st)), StrFromUTF8(d.value.string->ft->getCharPtr(d.value.string, &st)))); this->projection.push_back(*p); } else { throw SCXInternalErrorException(L"Projection contains property which is not a string type", SCXSRCLOCATION); } } } SCX_LOGTRACE(this->m_log, L"Exit SetProjection(CMPIArray *projectionPtr)"); }
void SCXGlob::DoGlob() { SCX_LOGTRACE(m_logHandle, L"Initialize()"); // Set a default m_index = cNoData; if (this->m_pathnames) { globfree(&this->m_globHolder); memset(&m_globHolder, 0, sizeof(glob_t)); this->m_pathnames = 0; } // Prepares the flag to pass to the OS-provided glob(). int flag = 0; if (!(this->m_isBackSlashEscapeOn)) { flag |= GLOB_NOESCAPE; } if (this->m_isErrorAbortOn) { flag |= GLOB_ERR; } // Calls the OS-provided glob(). int ret = glob(m_pattern.c_str(), flag, NULL, &this->m_globHolder); switch (ret) { case 0: this->m_pathnames = this->m_globHolder.gl_pathv; m_index = cBegin; break; case GLOB_NOMATCH: // No matching pathname exists in the file system. // Does nothing here. break; case GLOB_NOSPACE: { globfree(&this->m_globHolder); wstring message = L"SCXGlob_NoSpace_Error: " + StrFromUTF8(this->m_pattern); throw SCXResourceExhaustedException(L"Memory", message, SCXSRCLOCATION); } case GLOB_ABORTED: { // We are here only if isErrorAbortOn is true. globfree(&this->m_globHolder); wstring message = L"SCXGlob::Initialize(): " + StrFromUTF8(this->m_pattern); throw SCXErrnoException(message, errno, SCXSRCLOCATION); } default: globfree(&this->m_globHolder); wstring message = L"SCXGlob_Unknown_Error: " + StrFromUTF8(this->m_pattern); throw SCXInternalErrorException(message, SCXSRCLOCATION); } }
SCXWQLSelectStatementCMPI::SCXWQLSelectStatementCMPI(const std::wstring& queryString, CMPIBroker *broker) : SCXWQLSelectStatementBase(queryString) { if( NULL == broker) { throw SCXInternalErrorException(L"Broker passed into select statement is null.", SCXSRCLOCATION); } this->cmpiBroker = broker; this->cmpiExp = NULL; this->cmpiProjection = NULL; }
/** Deletes the specified file. An exception is not thrown if the specified file does not exist \param[in] path The path to the file to be deleted. \throws SCXUnauthorizedFileSystemAccessException The caller does not have the required permission or path is a directory or path specified a read-only file The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see GetCurrentDirectory */ void SCXFile::Delete(const SCXFilePath& path) { #if defined(WIN32) int failure = _wremove(path.Get().c_str()); #elif defined(SCX_UNIX) std::string localizedPath = SCXFileSystem::EncodePath(path); int failure = remove(localizedPath.c_str()); #else #error #endif if (failure) { if (errno == EACCES || errno == EBUSY || errno == EPERM || errno == EROFS) { throw SCXUnauthorizedFileSystemAccessException(path, SCXFileSystem::GetAttributes(path), SCXSRCLOCATION); } else if (errno == ENOENT) { const int existenceOnly = 00; #if defined(WIN32) failure = _waccess(path.Get().c_str(), existenceOnly); #elif defined(SCX_UNIX) failure = access(localizedPath.c_str(), existenceOnly); #else #error #endif bool fileStillExists = !failure; if (fileStillExists) { // We got ENOENT when trying to remove the file, // but appearently the file exists. That means that // the file is not a file but a directory throw SCXUnauthorizedFileSystemAccessException(path, SCXFileSystem::GetAttributes(path), SCXSRCLOCATION); } if (errno == EACCES) { throw SCXUnauthorizedFileSystemAccessException(path, SCXFileSystem::GetAttributes(path), SCXSRCLOCATION); } else if (errno == EINVAL) { throw SCXInvalidArgumentException(L"path", L"Invalid format of path " + path.Get(), SCXSRCLOCATION); } else if (errno != ENOENT) { std::wstring problem(L"Failed to delete " + path.Get()); throw SCXInternalErrorException(UnexpectedErrno(problem, errno), SCXSRCLOCATION); } } else { std::wstring problem(L"Failed to delete " + path.Get()); throw SCXInternalErrorException(UnexpectedErrno(problem, errno), SCXSRCLOCATION); } } }
/** Creates a temp file and writes to it \param[in] fileContent Content to write to file. \returns Complete path of newly created file. */ SCXFilePath SCXFile::CreateTempFile(const std::wstring& fileContent) { /** * The code below behaves as it does because of limitations in the * various temp file functions. * * \li Use the tempnam function to retrieve an "appropriate" directory * to store files in. * \li Only use the directory part of what is returned and append a * pattern to use for creating temporary file. * \li Use the pattern as argument to mkstemp which is the recommended * function since it avoids race conditions. * */ SCXFilePath pattern; char* fp = tempnam(0, 0); if (fp == 0) { throw SCXInternalErrorException( UnexpectedErrno(L"Failed to find an appropriate temporary file directory", errno), SCXSRCLOCATION); } try { pattern = SCXFileSystem::DecodePath(fp); } catch ( SCXCoreLib::SCXException& e ) { free(fp); fp = 0; SCXRETHROW(e, L"Unable to decode file path." ); } free(fp); fp = 0; pattern.SetFilename(L"scxXXXXXX"); std::string patternString = SCXFileSystem::EncodePath(pattern); std::vector<char> buf; buf.resize( patternString.length()+1, 0 ); strcpy(&buf[0], patternString.c_str()); mode_t oldUmask = umask(077); int fileDescriptor = mkstemp(&buf[0]); umask(oldUmask); if (fileDescriptor == -1) { std::wstring problem(L"Failed to create temporary file from pattern " + pattern.Get()); throw SCXInternalErrorException(UnexpectedErrno(problem, errno), SCXSRCLOCATION); } SCXFilePath filepath = SCXFileSystem::DecodePath(&buf[0]); std::ostringstream fileContentStream; SCXStream::WriteAsUTF8(fileContentStream, fileContent); std::string fileContentUTF8 = fileContentStream.str(); ssize_t written = write(fileDescriptor, fileContentUTF8.c_str(), fileContentUTF8.length()); if (written == -1) { std::wstring problem(L"Failed to write to temporary file " + filepath.Get()); close(fileDescriptor); throw SCXInternalErrorException(UnexpectedErrno(problem, errno), SCXSRCLOCATION); } close(fileDescriptor); return filepath; }
/** Update /detailed This method parses an entire line of a route file and creates an instance for each line which is then stored in an array. @param[in] updateInstances If true (the default) the file will be read. If false, the file will not be read and instead any pre-loaded testing lines will instead be used. @throws SCXInternalErrorException If 11 elements are not parsed for each route file line. */ void NxNetRouteEnumeration::Update(bool updateInstances /* = true */ ) { SCX_LOGTRACE(m_log, L"NxNetRouteEnumeration Update()"); if( updateInstances ) { m_deps->Init(); // read in data from file } RemoveInstances(); vector<std::wstring>::iterator iter; iter = m_deps->GetLines().begin();// get iterator at beginning of file while (iter != m_deps->GetLines().end()) { std::wstring temp = *iter; std::vector<std::wstring> lineElements; StrTokenize(temp, lineElements, L"\t\n"); if (lineElements.size() != 11) { std::wostringstream error; error << L"NxNetRouteEnumeration::Update expected 11 elements in line, got " << std::endl; error << lineElements.size() << "." << std::endl; throw SCXInternalErrorException(error.str(), SCXSRCLOCATION); } if (m_log.GetSeverityThreshold() <= SCXCoreLib::eTrace ) { std::wostringstream error; error << L"NxNetRouteEnumeration::Update, parsing line of file:" << std::endl; error << temp; SCX_LOGTRACE( m_log, error.str() ); } // create new instance SCXCoreLib::SCXHandle<NxNetRouteInstance> route; route = new NxNetRouteInstance(lineElements[0], lineElements[1], lineElements[2], lineElements[3], lineElements[4], lineElements[5], lineElements[6], lineElements[7], lineElements[8], lineElements[9], lineElements[10]); AddInstance(route); ++iter;// next line } SCX_LOGTRACE(m_log, L"NxNetRouteEnumeration Update()"); }