UserId DB::getUserId(const QString & login) { TRANSACTION(ta); QSqlQuery query(ta.db); query.prepare( "SELECT " "id " "FROM " "users " "WHERE " "login = :login" ); query.bindValue(":login", login); if (!Database::executeQuery(query)) { return UserId(); } if (!query.next()) { ta.commit(); return UserId(); } const UserId retval = UserId(query.value(0).toInt()); ta.commit(); return retval; }
HistoryMessage::HistoryMessage( not_null<History*> history, const MTPDmessageService &data) : HistoryItem( history, data.vid.v, mtpCastFlags(data.vflags.v), data.vdate.v, data.has_from_id() ? data.vfrom_id.v : UserId(0)) { CreateConfig config; if (data.has_reply_to_msg_id()) config.replyTo = data.vreply_to_msg_id.v; createComponents(config); switch (data.vaction.type()) { case mtpc_messageActionPhoneCall: { _media = std::make_unique<Data::MediaCall>( this, data.vaction.c_messageActionPhoneCall()); } break; default: Unexpected("Service message action type in HistoryMessage."); } setText(TextWithEntities {}); }
void MetaDataStore::maybe_initialise_() { if (not harakoon_.initialized()) { LOG_INFO("Trying to initialize filesystem metadata store"); try { harakoon_.initialize(DirectoryEntry(DirectoryEntry::Type::Directory, alloc_inode(), default_directory_permissions, UserId(::getuid()), GroupId(::getgid()))); LOG_INFO("Initialized filesystem metadata store"); } catch (ara::error_assertion_failed&) { // Another cluster node could've beaten us to it: if (not harakoon_.initialized()) { throw; } else { LOG_INFO("Filesystem metadata store already initialized by another node"); } } } else { LOG_INFO("Filesystem metadata store already initialized"); } }
HistoryMessage::HistoryMessage( not_null<History*> history, const MTPDmessage &data) : HistoryItem( history, data.vid.v, data.vflags.v, data.vdate.v, data.has_from_id() ? data.vfrom_id.v : UserId(0)) { CreateConfig config; if (data.has_fwd_from() && data.vfwd_from.type() == mtpc_messageFwdHeader) { auto &f = data.vfwd_from.c_messageFwdHeader(); config.originalDate = f.vdate.v; if (f.has_from_id() || f.has_channel_id()) { config.senderOriginal = f.has_channel_id() ? peerFromChannel(f.vchannel_id) : peerFromUser(f.vfrom_id); if (f.has_channel_post()) config.originalId = f.vchannel_post.v; if (f.has_post_author()) config.authorOriginal = qs(f.vpost_author); if (f.has_saved_from_peer() && f.has_saved_from_msg_id()) { config.savedFromPeer = peerFromMTP(f.vsaved_from_peer); config.savedFromMsgId = f.vsaved_from_msg_id.v; } } } if (data.has_reply_to_msg_id()) config.replyTo = data.vreply_to_msg_id.v; if (data.has_via_bot_id()) config.viaBotId = data.vvia_bot_id.v; if (data.has_views()) config.viewsCount = data.vviews.v; if (data.has_reply_markup()) config.mtpMarkup = &data.vreply_markup; if (data.has_edit_date()) config.editDate = data.vedit_date.v; if (data.has_post_author()) config.author = qs(data.vpost_author); createComponents(config); if (data.has_media()) { setMedia(data.vmedia); } auto text = TextUtilities::Clean(qs(data.vmessage)); auto entities = data.has_entities() ? TextUtilities::EntitiesFromMTP(data.ventities.v) : EntitiesInText(); setText({ text, entities }); if (data.has_grouped_id()) { setGroupId(MessageGroupId::FromRaw(data.vgrouped_id.v)); } }
not_null<HistoryItem*> HistoryItem::Create( not_null<History*> history, const MTPMessage &message) { return message.match([&](const MTPDmessage &data) -> HistoryItem* { const auto checked = data.has_media() ? CheckMessageMedia(data.vmedia) : MediaCheckResult::Good; if (checked == MediaCheckResult::Unsupported) { return CreateUnsupportedMessage( history, data.vid.v, data.vflags.v, data.vreply_to_msg_id.v, data.vvia_bot_id.v, data.vdate.v, data.vfrom_id.v); } else if (checked == MediaCheckResult::Empty) { const auto text = HistoryService::PreparedText { lang(lng_message_empty) }; return new HistoryService( history, data.vid.v, data.vdate.v, text, data.vflags.v, data.has_from_id() ? data.vfrom_id.v : UserId(0)); } else if (checked == MediaCheckResult::HasTimeToLive) { return new HistoryService(history, data); } return new HistoryMessage(history, data); }, [&](const MTPDmessageService &data) -> HistoryItem* { if (data.vaction.type() == mtpc_messageActionPhoneCall) { return new HistoryMessage(history, data); } return new HistoryService(history, data); }, [&](const MTPDmessageEmpty &data) -> HistoryItem* { const auto text = HistoryService::PreparedText{ lang(lng_message_empty) }; return new HistoryService(history, data.vid.v, TimeId(0), text); }); }
namespace UserUtils { #if !defined( BLOCXX_WIN32 ) const UserId INVALID_USERID = UserId(~0); const GroupId INVALID_GROUPID = GroupId(~0); #endif /** * Get the effective user id. On POSIX platforms this calls geteuid(). * * @return A string representation of the user id. On POSIX * platforms, this can be converted to a UInt64. */ BLOCXX_COMMON_API String getEffectiveUserId(); /** * Get the effective group id. On POSIX platforms this calls getegid(). * * @return A string representation of the group id. On POSIX * platforms, this can be converted to a UInt64. */ BLOCXX_COMMON_API String getEffectiveGroupId(); /** * Return the user name for the current user. */ BLOCXX_COMMON_API String getCurrentUserName(); /** * Return the group name for the current user. */ BLOCXX_COMMON_API String getCurrentGroupName(); /** * If the username is invalid, or if getUserName() fails for any other * reason, 'success' will be set to false. On success, 'success' is * set to true. * @param uid The id to query for user name * @return The user name corresponding to the requested uid, or * an empty string on failure. Check success before relying * on the return result. * * \example utils.cpp */ BLOCXX_COMMON_API String getUserName(UserId uid, bool& success); /** * If the group is invalid, or if getGropuName() fails for any other * reason, 'success' will be set to false. On success, 'success' is * set to true. * @param gid The id to query for group name * @return The group name corresponding to the requested gid, or * an empty string on failure. Check success before relying * on the return result. * * \example utils.cpp */ BLOCXX_COMMON_API String getGroupName(GroupId gid, bool& success); /** * Convert a textual username into a platform native user type. * @param userName The user name to convert. * @param validUserName Out param set to true if the conversion was successful, false otherwise. * @return The user id corresponding to userName. * * \example utils.cpp */ BLOCXX_COMMON_API UserId getUserId(const String& userName, bool& validUserName); /** * Convert a textual group name into a platform native group type. * @param groupName The group name to convert. * @param validGroupName Out param set to true if the conversion was successful, false otherwise. * @return The group id corresponding to groupName. * * \example utils.cpp */ BLOCXX_COMMON_API UserId getGroupId(const String& groupName, bool& validGroupName); } // end namespace UserUtils
void MetaDataStore::add_directories(const FrontendPath& path) { LOG_TRACE(path); FrontendPath p; for (const auto& s : path) { p = FrontendPath(p / s); DirectoryEntryPtr dentry(find(p)); while (true) { if (dentry == nullptr) { DirectoryEntryPtr dentry(boost::make_shared<DirectoryEntry>(DirectoryEntry::Type::Directory, alloc_inode(), default_directory_permissions, UserId(::getuid()), GroupId(::getgid()))); try { struct timespec timebuf; struct timeval tv; TODO("X42: Better use fungi::IOException here? WIP"); int rc = clock_gettime(CLOCK_REALTIME, &timebuf); if (rc != 0) { throw std::system_error(errno, std::system_category()); } add(p, dentry); tv.tv_sec = timebuf.tv_sec; tv.tv_usec = timebuf.tv_nsec / 1000; utimes(FrontendPath(p.parent_path()), tv, tv); break; } catch (FileExistsException&) { LOG_WARN(p << ": someone else created an eponymous entry at the same time"); } } else { if (dentry->type() != DirectoryEntry::Type::Directory) { LOG_ERROR(p << " already exists but is not a directory"); throw fungi::IOException("Entry is not a directory", p.string().c_str(), ENOTDIR); } break; } } } }