nsresult
nsAboutCacheEntry::WriteCacheEntryDescription(nsICacheEntryDescriptor *descriptor)
{
    nsresult rv;
    nsCString buffer;
    uint32_t n;

    nsAutoCString str;

    rv = descriptor->GetKey(str);
    if (NS_FAILED(rv)) return rv;

    buffer.SetCapacity(4096);
    buffer.AssignLiteral("<table>\n"
                         "  <tr>\n"
                         "    <th>key:</th>\n"
                         "    <td id=\"td-key\">");

    // Test if the key is actually a URI
    nsCOMPtr<nsIURI> uri;
    bool isJS = false;
    bool isData = false;

    rv = NS_NewURI(getter_AddRefs(uri), str);
    // javascript: and data: URLs should not be linkified
    // since clicking them can cause scripts to run - bug 162584
    if (NS_SUCCEEDED(rv)) {
        uri->SchemeIs("javascript", &isJS);
        uri->SchemeIs("data", &isData);
    }
    char* escapedStr = nsEscapeHTML(str.get());
    if (NS_SUCCEEDED(rv) && !(isJS || isData)) {
        buffer.AppendLiteral("<a href=\"");
        buffer.Append(escapedStr);
        buffer.AppendLiteral("\">");
        buffer.Append(escapedStr);
        buffer.AppendLiteral("</a>");
        uri = 0;
    }
    else
        buffer.Append(escapedStr);
    nsMemory::Free(escapedStr);
    buffer.AppendLiteral("</td>\n"
                         "  </tr>\n");

    // temp vars for reporting
    char timeBuf[255];
    uint32_t u = 0;
    int32_t  i = 0;
    nsAutoCString s;

    // Fetch Count
    s.Truncate();
    descriptor->GetFetchCount(&i);
    s.AppendInt(i);
    APPEND_ROW("fetch count", s);

    // Last Fetched
    descriptor->GetLastFetched(&u);
    if (u) {
        PrintTimeString(timeBuf, sizeof(timeBuf), u);
        APPEND_ROW("last fetched", timeBuf);
    } else {
        APPEND_ROW("last fetched", "No last fetch time");
    }

    // Last Modified
    descriptor->GetLastModified(&u);
    if (u) {
        PrintTimeString(timeBuf, sizeof(timeBuf), u);
        APPEND_ROW("last modified", timeBuf);
    } else {
        APPEND_ROW("last modified", "No last modified time");
    }

    // Expiration Time
    descriptor->GetExpirationTime(&u);
    if (u < 0xFFFFFFFF) {
        PrintTimeString(timeBuf, sizeof(timeBuf), u);
        APPEND_ROW("expires", timeBuf);
    } else {
        APPEND_ROW("expires", "No expiration time");
    }

    // Data Size
    s.Truncate();
    uint32_t dataSize;
    descriptor->GetStorageDataSize(&dataSize);
    s.AppendInt((int32_t)dataSize);     // XXX nsICacheEntryInfo interfaces should be fixed.
    APPEND_ROW("Data size", s);

    // Storage Policy

    // XXX Stream Based?

    // XXX Cache Device
    // File on disk
    nsCOMPtr<nsIFile> cacheFile;
    rv = descriptor->GetFile(getter_AddRefs(cacheFile));
    if (NS_SUCCEEDED(rv)) {
        nsAutoString filePath;
        cacheFile->GetPath(filePath);
        APPEND_ROW("file on disk", NS_ConvertUTF16toUTF8(filePath));
    }
    else
        APPEND_ROW("file on disk", "none");

    // Security Info
    nsCOMPtr<nsISupports> securityInfo;
    descriptor->GetSecurityInfo(getter_AddRefs(securityInfo));
    if (securityInfo) {
        APPEND_ROW("Security", "This is a secure document.");
    } else {
        APPEND_ROW("Security",
                   "This document does not have any security info associated with it.");
    }

    buffer.AppendLiteral("</table>\n"
                         "<hr/>\n"
                         "<table>\n");
    // Meta Data
    // let's just look for some well known (HTTP) meta data tags, for now.

    // Client ID
    nsXPIDLCString str2;
    descriptor->GetClientID(getter_Copies(str2));
    if (!str2.IsEmpty())  APPEND_ROW("Client", str2);


    mBuffer = &buffer;  // make it available for VisitMetaDataElement().
    // nsCacheEntryDescriptor::VisitMetaData calls
    // nsCacheEntry.h VisitMetaDataElements, which returns
    // nsCacheMetaData::VisitElements, which calls
    // nsAboutCacheEntry::VisitMetaDataElement (below) in a loop.
    descriptor->VisitMetaData(this);
    mBuffer = nullptr;

    buffer.AppendLiteral("</table>\n");
    mOutputStream->Write(buffer.get(), buffer.Length(), &n);

    buffer.Truncate();

    // Provide a hexdump of the data
    if (dataSize) { // don't draw an <hr> if the Data Size is 0.
        nsCOMPtr<nsIInputStream> stream;
        descriptor->OpenInputStream(0, getter_AddRefs(stream));
        if (stream) {
            buffer.AssignLiteral("<hr/>\n"
                                 "<pre>");
            uint32_t hexDumpState = 0;
            char chunk[4096];
            while(NS_SUCCEEDED(stream->Read(chunk, sizeof(chunk), &n)) && 
                  n > 0) {
                HexDump(&hexDumpState, chunk, n, buffer);
                mOutputStream->Write(buffer.get(), buffer.Length(), &n);
                buffer.Truncate();
            }
            buffer.AssignLiteral("</pre>\n");
            mOutputStream->Write(buffer.get(), buffer.Length(), &n);
      }
    }
    return NS_OK;
}
Exemplo n.º 2
0
NS_IMETHODIMP
nsAboutCache::VisitEntry(const char *deviceID,
                         nsICacheEntryInfo *entryInfo,
                         PRBool *visitNext)
{
    // We need mStream for this
    if (!mStream)
      return NS_ERROR_FAILURE;

    nsresult        rv;
    PRUint32        bytesWritten;
    nsCAutoString   key;
    nsXPIDLCString  clientID;
    PRBool          streamBased;
    
    rv = entryInfo->GetKey(key);
    if (NS_FAILED(rv))  return rv;

    rv = entryInfo->GetClientID(getter_Copies(clientID));
    if (NS_FAILED(rv))  return rv;

    rv = entryInfo->IsStreamBased(&streamBased);
    if (NS_FAILED(rv)) return rv;

    // Generate a about:cache-entry URL for this entry...
    nsCAutoString url;
    url.AssignLiteral("about:cache-entry?client=");
    url += clientID;
    url.AppendLiteral("&amp;sb=");
    url += streamBased ? '1' : '0';
    url.AppendLiteral("&amp;key=");
    char* escapedKey = nsEscapeHTML(key.get());
    url += escapedKey; // key

    // Entry start...

    // URI
    mBuffer.AssignLiteral("<b>           Key:</b> <a href=\"");
    mBuffer.Append(url);
    mBuffer.AppendLiteral("\">");
    mBuffer.Append(escapedKey);
    nsMemory::Free(escapedKey);
    mBuffer.AppendLiteral("</a>");

    // Content length
    PRUint32 length = 0;
    entryInfo->GetDataSize(&length);

    mBuffer.AppendLiteral("\n<b>     Data size:</b> ");
    mBuffer.AppendInt(length);
    mBuffer.AppendLiteral(" bytes");

    // Number of accesses
    PRInt32 fetchCount = 0;
    entryInfo->GetFetchCount(&fetchCount);

    mBuffer.AppendLiteral("\n<b>   Fetch count:</b> ");
    mBuffer.AppendInt(fetchCount);

    // vars for reporting time
    char buf[255];
    PRUint32 t;

    // Last modified time
    mBuffer.AppendLiteral("\n<b> Last modified:</b> ");
    entryInfo->GetLastModified(&t);
    if (t) {
        PrintTimeString(buf, sizeof(buf), t);
        mBuffer.Append(buf);
    } else
        mBuffer.AppendLiteral("No last modified time");

    // Expires time
    mBuffer.AppendLiteral("\n<b>       Expires:</b> ");
    entryInfo->GetExpirationTime(&t);
    if (t < 0xFFFFFFFF) {
        PrintTimeString(buf, sizeof(buf), t);
        mBuffer.Append(buf);
    } else {
        mBuffer.AppendLiteral("No expiration time");
    }

    // Entry is done...
    mBuffer.AppendLiteral("\n\n");

    mStream->Write(mBuffer.get(), mBuffer.Length(), &bytesWritten);

    *visitNext = PR_TRUE;
    return NS_OK;
}
Exemplo n.º 3
0
int main (int argc, char **argv)
{
BOOL verbose   = FALSE;
char *server   = DEFAULT_SERVER;
char *reply    = NULL;
char *log, *sta=NULL;
ISI_PARAM par;
int i, port, debug, nchn;
ISI_STREAM_NAME name[MAXCHN];
BOOL NeedBeg=TRUE, NeedEnd=TRUE;
ISI_SOH_REPORT *soh;
REAL64 beg = 0.0;
REAL64 end = 0.0;
REAL64 maxlen = 7200.0;
struct utsname system;

    if (uname(&system) == -1) {
        fprintf(stderr, "%s: ", argv[0]);
        perror("uname");
        exit(1);
    }

    utilNetworkInit();
    isiInitDefaultPar(&par);

    for (i = 1; i < argc; i++) {
        if (strncmp(argv[i], "server=", strlen("server=")) == 0) {
            server = argv[i] + strlen("server=");
        } else if (strncmp(argv[i], "port=", strlen("port=")) == 0) {
            port = atoi(argv[i] + strlen("port="));
            isiSetServerPort(&par, port);
        } else if (strncmp(argv[i], "beg=", strlen("beg=")) == 0) {
            beg = utilAttodt(argv[i] + strlen("beg="));
            NeedBeg = FALSE;
        } else if (strncmp(argv[i], "end=", strlen("end=")) == 0) {
            end = utilAttodt(argv[i] + strlen("end="));
            NeedEnd = FALSE;
        } else if (strncmp(argv[i], "maxlen=", strlen("maxlen=")) == 0) {
            maxlen = utilAttodt(argv[i] + strlen("maxlen="));
        } else if (strncmp(argv[i], "debug=", strlen("debug=")) == 0) {
            debug = atoi(argv[i] + strlen("debug="));
            isiSetDebugFlag(&par, debug);
        } else if (strncmp(argv[i], "log=", strlen("log=")) == 0) {
            log = argv[i] + strlen("log=");
            isiStartLogging(&par, log, NULL, argv[0]);
        } else if (strncmp(argv[i], "reply=", strlen("reply=")) == 0) {
            reply = argv[i] + strlen("reply=");
        } else if (strcmp(argv[i], "-v") == 0) {
            verbose = TRUE;
        } else if (sta == NULL) {
            sta = argv[i];
        } else {
           fprintf(stderr, "%s: unrecognized argument: '%s'\n", argv[0], argv[i]);
            help(argv[0]);
        }
    }

    if (sta == NULL) help(argv[0]);

    if (verbose) fprintf(stderr, "%s %s\n", argv[0], VersionIdentString);

    if ((soh = isiSoh(server, &par)) == NULL) {
        perror("isiSoh");
        exit(1);
    }

/* Find all channels for the specified station */

    nchn = 0;
    for (i = 0; i < soh->nentry; i++) {
        if (strcmp(soh->entry[i].name.sta, sta) == 0) {
            if (NeedBeg && soh->entry[i].tols.value > 0.0) {
                if (beg == 0.0 || beg > soh->entry[i].tols.value) {
                    beg = soh->entry[i].tols.value;
                }
            }
            if (nchn == MAXCHN) {
                fprintf(stderr, "%s: INCREASE MAXCHN\n", argv[0]);
                exit(1);
            }
            name[nchn++] = soh->entry[i].name;
        }
    }

    if (nchn == 0) {
        fprintf(stderr, "%s: 0 channels found for station %s\n", argv[0], sta);
        exit(1);
    }

    if (NeedEnd) end = (REAL64) (time(NULL) - FUDGE_FACTOR);

    if (end - beg > maxlen) end = beg + maxlen;

/* Print out the request */

    printf("BEGIN GSE2.0\n");
    printf("MSG_TYPE REQUEST\n");
    printf("MSG_ID %s[%d] %s\n", argv[0], getpid(), system.nodename);
    printf("STA_LIST %s\n", sta);
    printf("TIME ");
    PrintTimeString(beg);
    printf(" to ");
    PrintTimeString(end);
    printf("\n");
    printf("CHAN_LIST ");
    for (i = 0; i < nchn; i++) printf(" %s%s", name[i].chn, name[i].loc);
    printf("\n");
    printf("WAVEFORM NATIVE\n");
    if (reply == NULL) {
        printf("FTP %sreply@%s\n", sta, system.nodename);
    } else {
        printf("FTP %s\n", reply);
    }
    printf("STOP\n");

    exit(0);
}