⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ftpdirectorydocument.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        ASSERT(hour >= 0 && hour < 24);                if (hour < 12) {            if (hour == 0)                hour = 12;            timeOfDay = String::format(", %i:%02i AM", hour, fileTime.tm_min);        } else {            hour = hour - 12;            if (hour == 0)                hour = 12;            timeOfDay = String::format(", %i:%02i PM", hour, fileTime.tm_min);        }    }        // If it was today or yesterday, lets just do that - but we have to compare to the current time    struct tm now;    time_t now_t = time(NULL);    localtime_r(&now_t, &now);        // localtime does "year = current year - 1900", compensate for that for readability and comparison purposes    now.tm_year += 1900;            if (fileTime.tm_year == now.tm_year) {        if (fileTime.tm_mon == now.tm_mon) {            if (fileTime.tm_mday == now.tm_mday)                return "Today" + timeOfDay;            if (fileTime.tm_mday == now.tm_mday - 1)                return "Yesterday" + timeOfDay;        }                if (now.tm_mday == 1 && (now.tm_mon == fileTime.tm_mon + 1 || now.tm_mon == 0 && fileTime.tm_mon == 11) &&            wasLastDayOfMonth(fileTime.tm_year, fileTime.tm_mon, fileTime.tm_mday))                return "Yesterday" + timeOfDay;    }        if (fileTime.tm_year == now.tm_year - 1 && fileTime.tm_mon == 12 && fileTime.tm_mday == 31 && now.tm_mon == 1 && now.tm_mday == 1)        return "Yesterday" + timeOfDay;    static const char* months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???" };        int month = fileTime.tm_mon;    if (month < 0 || month > 11)        month = 12;        String dateString;        if (fileTime.tm_year > -1)        dateString = String::format("%s %i, %i", months[month], fileTime.tm_mday, fileTime.tm_year);    else        dateString = String::format("%s %i, %i", months[month], fileTime.tm_mday, now.tm_year);        return dateString + timeOfDay;}void FTPDirectoryTokenizer::parseAndAppendOneLine(const String& inputLine){    ListResult result;    FTPEntryType typeResult = parseOneFTPLine(inputLine.latin1().data(), m_listState, result);        // FTPMiscEntry is a comment or usage statistic which we don't care about, and junk is invalid data - bail in these 2 cases    if (typeResult == FTPMiscEntry || typeResult == FTPJunkEntry)        return;            String filename(result.filename, result.filenameLength);    if (result.type == FTPDirectoryEntry) {        filename.append("/");                // We have no interest in linking to "current directory"        if (filename == "./")            return;    }    LOG(FTP, "Appending entry - %s, %s", filename.ascii().data(), result.fileSize.ascii().data());            appendEntry(filename, processFilesizeString(result.fileSize, result.type == FTPDirectoryEntry), processFileDateString(result.modifiedTime), result.type == FTPDirectoryEntry);}static inline PassRefPtr<SharedBuffer> createTemplateDocumentData(Settings* settings){    RefPtr<SharedBuffer> buffer = 0;    if (settings)        buffer = SharedBuffer::createWithContentsOfFile(settings->ftpDirectoryTemplatePath());    if (buffer)        LOG(FTP, "Loaded FTPDirectoryTemplate of length %i\n", buffer->size());    return buffer.release();}    bool FTPDirectoryTokenizer::loadDocumentTemplate(){    DEFINE_STATIC_LOCAL(RefPtr<SharedBuffer>, templateDocumentData, (createTemplateDocumentData(m_doc->settings())));    // FIXME: Instead of storing the data, we'd rather actually parse the template data into the template Document once,    // store that document, then "copy" it whenever we get an FTP directory listing.  There are complexities with this     // approach that make it worth putting this off.        if (!templateDocumentData) {        LOG_ERROR("Could not load templateData");        return false;    }        // Tokenize the template as an HTML document synchronously    setForceSynchronous(true);    HTMLTokenizer::write(String(templateDocumentData->data(), templateDocumentData->size()), true);    setForceSynchronous(false);        RefPtr<Element> tableElement = m_doc->getElementById("ftpDirectoryTable");    if (!tableElement)        LOG_ERROR("Unable to find element by id \"ftpDirectoryTable\" in the template document.");    else if (!tableElement->hasTagName(tableTag))        LOG_ERROR("Element of id \"ftpDirectoryTable\" is not a table element");    else         m_tableElement = static_cast<HTMLTableElement*>(tableElement.get());    // Bail if we found the table element    if (m_tableElement)        return true;    // Otherwise create one manually    tableElement = m_doc->createElement(tableTag, false);    m_tableElement = static_cast<HTMLTableElement*>(tableElement.get());    ExceptionCode ec;            m_tableElement->setAttribute("id", "ftpDirectoryTable", ec);    // If we didn't find the table element, lets try to append our own to the body    // If that fails for some reason, cram it on the end of the document as a last    // ditch effort    if (Element* body = m_doc->body())        body->appendChild(m_tableElement, ec);    else        m_doc->appendChild(m_tableElement, ec);            return true;}void FTPDirectoryTokenizer::createBasicDocument(){    LOG(FTP, "Creating a basic FTP document structure as no template was loaded");    // FIXME: Make this "basic document" more acceptable        RefPtr<Element> bodyElement = m_doc->createElement(bodyTag, false);                                ExceptionCode ec;    m_doc->appendChild(bodyElement, ec);        RefPtr<Element> tableElement = m_doc->createElement(tableTag, false);    m_tableElement = static_cast<HTMLTableElement*>(tableElement.get());    m_tableElement->setAttribute("id", "ftpDirectoryTable", ec);    bodyElement->appendChild(m_tableElement, ec);}void FTPDirectoryTokenizer::write(const SegmentedString& s, bool /*appendData*/){        // Make sure we have the table element to append to by loading the template set in the pref, or    // creating a very basic document with the appropriate table    if (!m_tableElement) {        if (!loadDocumentTemplate())            createBasicDocument();        ASSERT(m_tableElement);    }            bool foundNewLine = false;        m_dest = m_buffer;    SegmentedString str = s;    while (!str.isEmpty()) {        UChar c = *str;                if (c == '\r') {            *m_dest++ = '\n';            foundNewLine = true;            // possibly skip an LF in the case of an CRLF sequence            m_skipLF = true;        } else if (c == '\n') {            if (!m_skipLF)                *m_dest++ = c;            else                m_skipLF = false;        } else {            *m_dest++ = c;            m_skipLF = false;        }                str.advance();                // Maybe enlarge the buffer        checkBuffer();    }        if (!foundNewLine) {        m_dest = m_buffer;        return;    }    UChar* start = m_buffer;    UChar* cursor = start;        while (cursor < m_dest) {        if (*cursor == '\n') {            m_carryOver.append(String(start, cursor - start));            LOG(FTP, "%s", m_carryOver.ascii().data());            parseAndAppendOneLine(m_carryOver);            m_carryOver = String();            start = ++cursor;        } else             cursor++;    }        // Copy the partial line we have left to the carryover buffer    if (cursor - start > 1)        m_carryOver.append(String(start, cursor - start - 1));}void FTPDirectoryTokenizer::finish(){    // Possible the last line in the listing had no newline, so try to parse it now    if (!m_carryOver.isEmpty()) {        parseAndAppendOneLine(m_carryOver);        m_carryOver = String();    }        m_tableElement = 0;    fastFree(m_buffer);            HTMLTokenizer::finish();}FTPDirectoryDocument::FTPDirectoryDocument(Frame* frame)    : HTMLDocument(frame){#ifndef NDEBUG    LogFTP.state = WTFLogChannelOn;#endif}Tokenizer* FTPDirectoryDocument::createTokenizer(){    return new FTPDirectoryTokenizer(this);}}#endif // ENABLE(FTPDIR)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -