Esempio n. 1
0
int  WUserManager::GetNumberOfUserRecords() const {
    File userList(m_dataDirectory, USER_LST);
    if (userList.Open(File::modeReadOnly | File::modeBinary)) {
        long nSize = userList.GetLength();
        int nNumRecords = (static_cast<int>(nSize / m_nUserRecordLength) - 1);
        return nNumRecords;
    }
    return 0;
}
Esempio n. 2
0
bool WUserManager::WriteUserNoCache(WUser *pUser, int nUserNumber) {
    File userList(m_dataDirectory, USER_LST);
    if (userList.Open(File::modeReadWrite | File::modeBinary | File::modeCreateFile)) {
        long pos = static_cast<long>(m_nUserRecordLength) * static_cast<long>(nUserNumber);
        userList.Seek(pos, File::seekBegin);
        userList.Write(&pUser->data,  m_nUserRecordLength);
        return true;
    }
    return false;
}
Esempio n. 3
0
bool WUserManager::ReadUserNoCache(WUser *pUser, int nUserNumber) {
    File userList(m_dataDirectory, USER_LST);
    if (!userList.Open(File::modeReadOnly | File::modeBinary)) {
        pUser->data.inact = inact_deleted;
        pUser->FixUp();
        return false;
    }
    long nSize = userList.GetLength();
    int nNumUserRecords = (static_cast<int>(nSize / m_nUserRecordLength) - 1);

    if (nUserNumber > nNumUserRecords) {
        pUser->data.inact = inact_deleted;
        pUser->FixUp();
        return false;
    }
    long pos = static_cast<long>(m_nUserRecordLength) * static_cast<long>(nUserNumber);
    userList.Seek(pos, File::seekBegin);
    userList.Read(&pUser->data,  m_nUserRecordLength);
    pUser->FixUp();
    return true;
}
Esempio n. 4
0
int main(int argc, char **argv)
{
    bool readStdin = false;
    int numOptions = 0;
    QString user;
    Session session = DefaultSession;
    QString sessionName;
    bool updateUserTime = true;

    cin_.setEncoding(QTextStream::Locale);

    // Scan for command-line options first
    for(int pos = 1; pos <= argc - 1; pos++)
    {
        if(strcmp(argv[pos], "--help") == 0)
            showHelp(0);
        else if(strcmp(argv[pos], "--pipe") == 0)
        {
            readStdin = true;
            numOptions++;
        }
        else if(strcmp(argv[pos], "--user") == 0)
        {
            if(pos <= argc - 2)
            {
                user = QString::fromLocal8Bit(argv[pos + 1]);
                numOptions += 2;
                pos++;
            }
            else
            {
                cerr_ << "Missing username for '--user' option!" << endl << endl;
                showHelp(-1);
            }
        }
        else if(strcmp(argv[pos], "--session") == 0)
        {
            if(session == AllSessions)
            {
                cerr_ << "ERROR: --session cannot be mixed with --all-sessions!" << endl << endl;
                showHelp(-1);
            }
            else if(pos <= argc - 2)
            {
                sessionName = QString::fromLocal8Bit(argv[pos + 1]);
                numOptions += 2;
                pos++;
            }
            else
            {
                cerr_ << "Missing session name for '--session' option!" << endl << endl;
                showHelp(-1);
            }
        }
        else if(strcmp(argv[pos], "--all-users") == 0)
        {
            user = "******";
            numOptions++;
        }
        else if(strcmp(argv[pos], "--list-sessions") == 0)
        {
            session = QuerySessions;
            numOptions++;
        }
        else if(strcmp(argv[pos], "--all-sessions") == 0)
        {
            if(!sessionName.isEmpty())
            {
                cerr_ << "ERROR: --session cannot be mixed with --all-sessions!" << endl << endl;
                showHelp(-1);
            }
            session = AllSessions;
            numOptions++;
        }
        else if(strcmp(argv[pos], "--no-user-time") == 0)
        {
            updateUserTime = false;
            numOptions++;
        }
        else if(argv[pos][0] == '-')
        {
            cerr_ << "Unknown command-line option '" << argv[pos] << "'." << endl << endl;
            showHelp(-1);
        }
        else
            break; // End of options
    }

    argc -= numOptions;

    KStringList args;

#ifdef DCOPQUIT
    if(argc > 1)
    {
        QCString prog = argv[numOptions + 1];

        if(!prog.isEmpty())
        {
            args.append(prog);

            // Pass as-is if it ends with a wildcard
            if(prog[prog.length() - 1] != '*')
            {
                // Strip a trailing -<PID> part.
                int i = prog.findRev('-');
                if((i >= 0) && prog.mid(i + 1).toLong())
                {
                    prog = prog.left(i);
                }
                args.append("qt/" + prog);
                args.append("quit()");
            }
        }
    }
#else
    for(int i = numOptions; i < argc + numOptions - 1; i++)
        args.append(argv[i + 1]);
#endif

    if(readStdin && args.count() < 3)
    {
        cerr_ << "--pipe option only supported for function calls!" << endl << endl;
        showHelp(-1);
    }

    if(user == "*" && args.count() < 3 && session != QuerySessions)
    {
        cerr_ << "ERROR: The --all-users option is only supported for function calls!" << endl << endl;
        showHelp(-1);
    }

    if(session == QuerySessions && !args.isEmpty())
    {
        cerr_ << "ERROR: The --list-sessions option cannot be used for actual DCOP calls!" << endl << endl;
        showHelp(-1);
    }

    if(session == QuerySessions && user.isEmpty())
    {
        cerr_ << "ERROR: The --list-sessions option can only be used with the --user or" << endl << "--all-users options!" << endl << endl;
        showHelp(-1);
    }

    if(session != DefaultSession && session != QuerySessions && args.count() < 3)
    {
        cerr_ << "ERROR: The --session and --all-sessions options are only supported for function" << endl << "calls!" << endl << endl;
        showHelp(-1);
    }

    UserList users;
    if(user == "*")
        users = userList();
    else if(!user.isEmpty())
        users[user] = userList()[user];

    int retval = runDCOP(args, users, session, sessionName, readStdin, updateUserTime);

    return retval;
}