std::shared_ptr<rapidjson::Document> Page::getJSONObject(long long headerpos) { //reading the Page tasking::RWLockGuard<> lock(m_rwLock, tasking::READ); //get the header first auto l_header = reinterpret_cast<HeaderMetaData*>(static_cast<char*>(m_header) + headerpos); //get the type auto l_objectType = l_header->getObjektType(); //get the idx auto& l_metaIdx = meta::MetaIndex::getInstance(); //get the meta dataset auto& l_meta = l_metaIdx[l_objectType]; //create the document auto l_obj = std::make_shared<rapidjson::Document>(); l_obj->SetObject(); //now generate the inner part of the object rapidjson::Value l_value; l_value.SetObject(); //calc the start id void* start = (static_cast<char*>(m_body) + l_header->getPos()); auto temp = buildObject(l_objectType, start, l_value, l_obj->GetAllocator()); if(temp == nullptr) { LOG_WARN << "build failed id: " << l_header->getOID(); return nullptr; } //generate name auto l_objName = l_meta->getName(); rapidjson::Value l_name(l_objName.c_str(), l_objName.length(), l_obj->GetAllocator()); //now add the inner object l_obj->AddMember(l_name, l_value, l_obj->GetAllocator()); return l_obj; }
bool CTarArchive::FillHeader(const std::string& filename, posix_header& header) { bool Ret = false; #if defined DEBUG && defined VERBOSE std::cout << i8n("[DBG]File header for ") << filename << " :" << '\n'; #endif struct stat Info; memset(&header, 0, 512); //Try to stat file. if(stat(filename.c_str(), &Info) == -1) { std::cout << i8n("[WNG] Cannot stat file: ") << filename.c_str() << i8n(" so I skip it !") << '\n'; Ret = false; } else { std::string l_name(filename); #if defined WIN32 // No UID or GID support for Windows - Hack it up. strncpy(header.mode, "0100777", 8); strncpy(header.uid, "0000000", 8); strncpy(header.gid, "0000000", 8); #else int Mode = 0; //Never reached ? if(!(Info.st_mode & S_IFREG)) { // Not a normal file. Let's archive it anyway, but warn the user. std::cout << i8n("[WNG] Archiving non-ordinary file (Linked or Device file?)") << '\n'; } // Add the normal file bit. Mode += 100000; // Find out the file permissions. if(Info.st_mode & TUREAD) Mode += 400; if(Info.st_mode & TUWRITE) Mode += 200; if(Info.st_mode & TUEXEC) Mode += 100; if(Info.st_mode & TGREAD) Mode += 40; if(Info.st_mode & TGWRITE) Mode += 20; if(Info.st_mode & TGEXEC) Mode += 10; if(Info.st_mode & TOREAD) Mode += 4; if(Info.st_mode & TOWRITE) Mode += 2; if(Info.st_mode & TOEXEC) Mode += 1; std::string Modestr(itos(Mode)); Modestr = PadWithZeros(Modestr, 8); strncpy(header.mode, Modestr.c_str(), 8); //UID std::string l_uid(DecToOct(Info.st_uid)); l_uid = PadWithZeros(l_uid, 8); strncpy(header.uid, l_uid.c_str(), 8); //GID std::string l_gid(DecToOct(Info.st_gid)); l_gid = PadWithZeros(l_gid, 8); strncpy(header.gid, l_gid.c_str(), 8); // File Size. std::string Size = DecToOct(Info.st_size); Size = PadWithZeros(Size, 12); strncpy(header.size, Size.c_str(), 12); // Time of modification std::string l_mtime = DecToOct(time(0)); l_mtime = PadWithZeros(l_mtime, 12); strncpy(header.mtime, l_mtime.c_str(), 12); // Type of file. header.typeflag = REGTYPE; if (S_ISLNK(Info.st_mode)) header.typeflag = SYMTYPE; else { if (S_ISDIR(Info.st_mode)) { header.typeflag = DIRTYPE; l_name += "/"; } } strncpy(header.name, l_name.c_str(), 100); strncpy(header.linkname, "", 100); // Magic strncpy(header.magic, TMAGIC, TMAGLEN); strncpy(header.version, TVERSION, TVERSLEN); // Windows again, let's cheat. #if defined WIN32 strncpy(header.uname, "root", 32); strncpy(header.gname, "root", 32); #else passwd* l_pwdFileInfo = getpwuid(Info.st_uid); group* l_grpFileInfo = getgrgid(Info.st_gid); if(!l_pwdFileInfo || !l_grpFileInfo) { // No entry. Let's fake it. strncpy(header.uname, header.uid, 32); strncpy(header.gname, header.gid, 32); } else { strncpy(header.uname, l_pwdFileInfo->pw_name, 32); strncpy(header.gname, l_grpFileInfo->gr_name, 32); } #endif // Skip devminor and devmajor. strncpy(header.devmajor, "", 8); strncpy(header.devminor, "", 8); // Fill the prefix. strncpy(header.prefix, "", 167); // Initialize our pointer. char* l_startheaderPtr = reinterpret_cast<char*>(&header); char* lheaderPtr ; int l_checksum = 0; // Find the checksum. for(lheaderPtr = l_startheaderPtr; (lheaderPtr - l_startheaderPtr) < 512; ++lheaderPtr) l_checksum += static_cast<int>(*lheaderPtr); // Add 256 (2^8) l_checksum += 256; // Get it to Octal. std::string l_checksumstr = DecToOct(l_checksum); l_checksumstr = PadWithZeros(l_checksumstr, 8); strncpy(header.chksum, l_checksumstr.c_str(), 8); #if defined DEBUG && defined VERBOSE Log::CLog::Instance()->Log(__FILE__, __LINE__, "Mode (8bytes) : ", header.mode, true); Log::CLog::Instance()->Log(__FILE__, __LINE__, "UID (8b) : ", header.uid, true); Log::CLog::Instance()->Log(__FILE__, __LINE__, "GID (8b) : ", header.gid, true); Log::CLog::Instance()->Log(__FILE__, __LINE__, "Size (12b) : ", header.size, true); Log::CLog::Instance()->Log(__FILE__, __LINE__, "Time (12b) : ", header.mtime, true); Log::CLog::Instance()->Log(__FILE__, __LINE__, "Checksum : ", header.chksum, true); #endif #endif Ret=true; } return Ret; }
void LLPanelFriends::refreshNames(U32 changed_mask, const std::string& search_string) { LLDynamicArray<LLUUID> selected_ids = getSelectedIDs(); S32 pos = mFriendsList->getScrollPos(); // get all buddies we know about LLAvatarTracker::buddy_map_t all_buddies; LLAvatarTracker::instance().copyBuddyList(all_buddies); BOOL have_names = TRUE; // I hate doing it this way. There's no need for it. I blame LL -- MC if (search_string.empty()) { if(changed_mask & (LLFriendObserver::ADD | LLFriendObserver::REMOVE)) { have_names &= refreshNamesSync(all_buddies); } if(changed_mask & LLFriendObserver::ONLINE) { have_names &= refreshNamesPresence(all_buddies); } } else { std::string firstname; std::string lastname; std::string filter = search_string; LLStringUtil::toLower(filter); LLAvatarTracker::buddy_map_t temp_buddies; for (LLAvatarTracker::buddy_map_t::reverse_iterator bIt = all_buddies.rbegin(); bIt != all_buddies.rend(); ++bIt) { if (gCacheName->getName((*bIt).first, firstname, lastname)) { std::string l_name(firstname); LLStringUtil::toLower(l_name); std::string l_sname(lastname); LLStringUtil::toLower(l_sname); if (l_name.find(filter) == 0 || l_sname.find(filter) == 0) { temp_buddies.insert(temp_buddies.begin(), std::pair<LLUUID, LLRelationship*>((*bIt).first, (*bIt).second)); } } } if(changed_mask & (LLFriendObserver::ADD | LLFriendObserver::REMOVE)) { have_names &= refreshNamesSync(temp_buddies); } if(changed_mask & LLFriendObserver::ONLINE) { have_names &= refreshNamesPresence(temp_buddies); } } if (!have_names) { mEventTimer.start(); } // Changed item in place, need to request sort and update columns // because we might have changed data in a column on which the user // has already sorted. JC mFriendsList->sortItems(); // re-select items mFriendsList->selectMultiple(selected_ids); mFriendsList->setScrollPos(pos); }