/**************************************************************************** Desc: Generates the html to display a row in a table. If *ppSCache is a valid pointer, then that line will have hyperlinks in it. ****************************************************************************/ FSTATIC void flmPrintCacheLine( HRequest * pHRequest, const char * pszHREF, const char * pszName, void * pBaseAddr, SCACHE ** ppSCache) { char szAddress[20]; char szOffset[8]; PRINTF_FN fnPrintf = gv_FlmSysData.HttpConfigParms.fnPrintf; printAddress( *ppSCache, szAddress); printOffset( pBaseAddr, ppSCache, szOffset); if ((*ppSCache) && (*ppSCache)->pFile && pszHREF) { // We have a pointer to a valid SCache block and a valid HREF string, // so we need hyperlinks to appear in the browser... fnPrintf( pHRequest, TD_s TD_a_s_s " </td> <td> SCACHE * </td> " TD_a_s_s TR_END, szOffset, pszHREF, pszName, pszHREF, szAddress); } else { fnPrintf( pHRequest, TD_s TD_s " <td> SCACHE * </td> " TD_s TR_END, szOffset, pszName, szAddress ); } }
/* wmfp->offsetを1ドット分だけ進める関数 return 成功:0 失敗:-1 */ static int wseek_dot(WFILE *wmfp) { woff_t *offset; offset = &wmfp->offset; /* oftを更新(座標、色、ビットプレーンの番号) */ if(offset->color == COLOR_ALPHA){ /* RGBAの最後のカラーだったら */ if(offset->x == wmfp->sspecs.x_size - 1){ /* ビットプレーンの横軸のMAXまでいっていたら */ if(offset->y == wmfp->sspecs.y_size -1){ /* ビットプレーンの最後までいっていたら */ offset->y = 0; offset->x = 0; if(offset->plane_no == 7){ #ifdef DEBUG printOffset(offset); puts("wseek_dot:watermark size over-flowed"); #endif return -1; /* 画像に埋め込める上限を越えたときは考慮されていない */ } else{ offset->plane_no++; } } else{ offset->x = 0; offset->y++; } } else{ offset->x++; } offset->color = COLOR_RED; } else{ /* ピクセル内で色を変えるだけ(ピクセル位置は変えない) */ offset->color++; } offset->total_bit++; return 0; }
/* WFILEからビットストリームで1バイト読み込み、埋め込まれている透かしを返す関数 @wmfp 処理するWFILEエントリ @return 成功:透かし1バイトの内容 失敗:-1 */ static char wread_byte(WFILE *wmfp) { int i, bit; png_byte color; char result = -1; /* 透かしは文字なのでcharでいい(asciiコードにマイナスの値は無い) */ if((wmfp->bs = openBitStream(NULL, 1, "w")) == NULL){ /* 書き込みモードでビットストリームをopen */ puts("wread_byte:cannot open bitwmfp"); return result; } for(i = 0; i < 8; i++){ /* 8ドット分ループ */ color = getColorFromOft(wmfp); /* ドットの値はunsigend char(0 - 255) */ bit = pick_nbit8(color, wmfp->offset.plane_no); #ifdef DEBUG printOffset(&wmfp->offset); printf("bit:%d, color:%d\n", bit, color); #endif /* ビットストリームに書き込む */ writeBitStream(wmfp->bs, bit); /* 1 dot分だけオフセットを進める */ wseek_dot(wmfp); } #ifdef DEBUG //printf("%d 0x%02x ", *(char *)wmfp->bs->raw_data, *(char *)wmfp->bs->raw_data); /* 読み出す時は透かし(== ascii)なのでchar変数として読み出し */ #endif memcpy(&result, (char *)wmfp->bs->raw_data, 1); closeBitStream(wmfp->bs); /* ビットストリームをclose */ printf("result = %d(%c)\n", result, result); return result; }
MiscQuery::MiscQuery(Index *index, const char *command, const char **modifiers, const char *body, uid_t userID, int memoryLimit) { this->index = index; resultLine = (char*)malloc(MAX_RESULT_LENGTH); visibleExtents = index->getVisibleExtents(userID, false); mustFreeVisibleExtentsInDestructor = true; processModifiers(modifiers); if (strcasecmp(command, "size") == 0) { // @size asks for number of tokens in the corpus if (body[0] != 0) { takesNoArgumentsError(resultLine, command); ok = false; return; } if (visibleExtents == NULL) printOffset(0, resultLine); else { ExtentList *list = visibleExtents->getExtentList(); offset totalSize = list->getTotalSize(); delete list; printOffset(totalSize, resultLine); } ok = true; } else if (strcasecmp(command, "stem") == 0) { // @stem stems the given string char *string = strcpy((char*)malloc(strlen(body) * 2 + 4), body); Stemmer::stem(string, LANGUAGE_ENGLISH, false); if (string[0] == 0) strcpy(resultLine, "[unstemmable]"); else strcpy(resultLine, string); free(string); ok = true; } else if (strcasecmp(command, "files") == 0) { if (body[0] != 0) { takesNoArgumentsError(resultLine, command); ok = false; return; } ExtentList *list = visibleExtents->getExtentList(); printOffset(list->getLength(), resultLine); delete list; ok = true; } else if (strcasecmp(command, "about") == 0) { if (body[0] != 0) { takesNoArgumentsError(resultLine, command); ok = false; return; } char minusLine[256], wumpusLine[256], formatString[32]; int lineLen = sprintf(wumpusLine, "| Wumpus Search Engine [" WUMPUS_VERSION "] - Copyright (c) 2011 by Stefan Buettcher. |"); sprintf(formatString, "%%-%ds|\n", lineLen - 1); minusLine[0] = '+'; for (int i = 1; i < lineLen - 1; i++) minusLine[i] = '-'; minusLine[lineLen - 1] = '+'; minusLine[lineLen] = 0; int len = 0; len += sprintf(&resultLine[len], "%s\n", minusLine); len += sprintf(&resultLine[len], "%s\n", wumpusLine); len += sprintf(&resultLine[len], formatString, "|"); len += sprintf(&resultLine[len], formatString, "| This is free software according to the GNU General Public License (GPL)."); len += sprintf(&resultLine[len], formatString, "| - http://www.gnu.org/philosophy/free-sw.html"); len += sprintf(&resultLine[len], formatString, "| - http://www.gnu.org/copyleft/gpl.html"); len += sprintf(&resultLine[len], "%s", minusLine); ok = true; } else if (strcasecmp(command, "fileinfo") == 0) { bool syntax = isNumber(body); offset value; if (sscanf(body, OFFSET_FORMAT, &value) != 1) syntax = false; if ((syntax) && (value >= 0)) { char *fileName = visibleExtents->getFileNameForOffset(value); if (fileName == NULL) { strcpy(resultLine, "File not found."); ok = false; } else { int documentType = index->getDocumentType(fileName); char *fileType = FilteredInputStream::documentTypeToString(documentType); sprintf(resultLine, "%s %s", fileType, fileName); free(fileType); free(fileName); ok = true; } } else { strcpy(resultLine, "Syntax error."); ok = false; } } else if (strcasecmp(command, "summary") == 0) { if (body[0] != 0) { ok = false; return; } resultLine[0] = 0; index->getIndexSummary(resultLine); if (resultLine[0] != 0) if (resultLine[strlen(resultLine) - 1] == '\n') resultLine[strlen(resultLine) - 1] = 0; ok = true; } else if (strcasecmp(command, "filestats") == 0) { if (body[0] != 0) { takesNoArgumentsError(resultLine, command); ok = false; return; } ExtentList *files = getPostings("<file!>", Index::GOD); ExtentList *visible = visibleExtents->restrictList(files); offset s, e, p = 0; int table[256]; memset(table, 0, sizeof(table)); while (visible->getFirstStartBiggerEq(p, &s, &e)) { int documentType = visibleExtents->getDocumentTypeForOffset(s); if (documentType >= 0) table[documentType]++; p = s + 1; } delete visible; int outLen = 0; resultLine[outLen] = 0; for (int i = 0; i < 256; i++) if (table[i] > 0) { char *typeString = FilteredInputStream::documentTypeToString(i); outLen += sprintf(&resultLine[outLen], "%s: %d\n", typeString, table[i]); free(typeString); } if (outLen > 0) resultLine[outLen - 1] = 0; ok = true; } else if (strcasecmp(command, "dictionarysize") == 0) { // @dictionarysize asks for the number of terms in the Lexicon; // note that only superuser and index owner may send this query if (body[0] != 0) { takesNoArgumentsError(resultLine, command); ok = false; return; } if ((userID == index->SUPERUSER) || (userID == index->getOwner())) { offset lower, upper; index->getDictionarySize(&lower, &upper); if (lower == upper) sprintf(resultLine, "#terms = " OFFSET_FORMAT, lower); else sprintf(resultLine, OFFSET_FORMAT " <= #terms <= " OFFSET_FORMAT, lower, upper); ok = true; } else { sprintf(resultLine, "Permission denied."); ok = false; } } else if (strcasecmp(command, "addannotation") == 0) { int pos = 0; offset indexOffset = 0; while ((body[pos] >= '0') && (body[pos] <= '9')) { indexOffset = indexOffset * 10 + (body[pos] - '0'); pos++; } if ((body[pos] > ' ') || (body[pos] < 0)) { sprintf(resultLine, "Illegal index position."); ok = false; } else { while ((body[pos] > 0) && (body[pos] <= ' ')) pos++; if (body[pos] == 0) { sprintf(resultLine, "No annotation specified."); ok = false; } else if (!mayAccessIndexExtent(indexOffset, indexOffset)) { sprintf(resultLine, "Permission denied."); ok = false; } else { index->addAnnotation(indexOffset, &body[pos]); sprintf(resultLine, "# Annotation added."); ok = true; } } } else if (strcasecmp(command, "getannotation") == 0) { int pos = 0; offset indexOffset = 0; while ((body[pos] >= '0') && (body[pos] <= '9')) { indexOffset = indexOffset * 10 + (body[pos] - '0'); pos++; } if ((body[pos] > ' ') || (body[pos] < 0)) { sprintf(resultLine, "Illegal index position."); ok = false; } else { while ((body[pos] > 0) && (body[pos] <= ' ')) pos++; if (body[pos] != 0) { sprintf(resultLine, "Illegal number of arguments."); ok = false; } else if (!mayAccessIndexExtent(indexOffset, indexOffset)) { sprintf(resultLine, "Permission denied."); ok = false; } else { index->getAnnotation(indexOffset, resultLine); ok = true; } } } else if (strcasecmp(command, "removeannotation") == 0) { int pos = 0; offset indexOffset = 0; while ((body[pos] >= '0') && (body[pos] <= '9')) { indexOffset = indexOffset * 10 + (body[pos] - '0'); pos++; } if ((body[pos] > ' ') || (body[pos] < 0)) { sprintf(resultLine, "Illegal index position."); ok = false; } else { while ((body[pos] > 0) && (body[pos] <= ' ')) pos++; if (body[pos] != 0) { sprintf(resultLine, "Illegal number of arguments."); ok = false; } else if (!mayAccessIndexExtent(indexOffset, indexOffset)) { sprintf(resultLine, "Permission denied."); ok = false; } else { index->removeAnnotation(indexOffset); sprintf(resultLine, "# Annotation removed."); ok = true; } } } else if (strcasecmp(command, "system") == 0) { if ((userID == index->SUPERUSER) || (userID == index->getOwner())) { ok = (system(body) >= 0); resultLine[0] = 0; } else { strcpy(resultLine, "Permission denied."); ok = false; } } else { strcpy(resultLine, "Illegal command."); ok = false; } } // end of MiscQuery(Index*, char*, char*, char*, int)
/**************************************************************************** Desc: Prints the web page for an SCACHEMGR struct (The URL for this page requires no parameters since there is only one SCACHE_MGR per copy of FLAIM.) ****************************************************************************/ RCODE F_SCacheMgrPage::display( FLMUINT uiNumParams, const char ** ppszParams) { RCODE rc = FERR_OK; SCACHE_MGR LocalSCacheMgr; FLMBOOL bAutoRefresh; #define NUM_CACHE_REQ_STRINGS 4 char * pszSCacheRequestString[ NUM_CACHE_REQ_STRINGS]; char szOffsetTable[12][6]; char szAddressTable[2][20]; FLMBOOL bHighlight = FALSE; char * pszTemp = NULL; FLMUINT uiLoop; // Note: The SCacheBlock requests need the following params: // "BlockAddress", "File", "LowTransID" and "HighTransID" // ex: <A href="SCacheBlock?BlockAddress=100?File=5?LowTransID=30?HighTransID=100"> pMRUCache </A> if( RC_BAD( rc = f_alloc( 200, &pszTemp))) { printErrorPage( rc, TRUE, (char *)"Failed to allocate temporary buffer"); goto Exit; } // First thing that we need to do is grab a local copy of gv_FlmSysData.SCacheMgr, // and of the data for the three SCache blocks that it has pointers to... for (uiLoop = 0; uiLoop < NUM_CACHE_REQ_STRINGS; uiLoop++) { if( RC_BAD( rc = f_alloc( 150, &pszSCacheRequestString[ uiLoop]))) { printErrorPage( rc, TRUE, (char *)"Failed to allocate temporary buffer"); goto Exit; } } f_mutexLock( gv_FlmSysData.hShareMutex); f_memcpy (&LocalSCacheMgr, &gv_FlmSysData.SCacheMgr, sizeof (LocalSCacheMgr)); flmBuildSCacheBlockString( pszSCacheRequestString[0], LocalSCacheMgr.pMRUCache); flmBuildSCacheBlockString( pszSCacheRequestString[1], LocalSCacheMgr.pLRUCache); flmBuildSCacheBlockString( pszSCacheRequestString[2], LocalSCacheMgr.pFirstFree); flmBuildSCacheBlockString( pszSCacheRequestString[3], LocalSCacheMgr.pLastFree); f_mutexUnlock( gv_FlmSysData.hShareMutex); bAutoRefresh = DetectParameter( uiNumParams, ppszParams, "Refresh"); // Now - are we being asked to display the usage stats? Or is this a regular page... if (DetectParameter( uiNumParams, ppszParams, "Usage")) { // There's a function to handle display the usage info (because both // RCacheMgr and SCacheMgr have usage stats). writeUsage( &LocalSCacheMgr.Usage, bAutoRefresh, "/SCacheMgr?Usage", "Usage Statistics for the SCache"); } else // This is a regular SCacheMgr page... { // Determine if we are being requested to refresh this page or not. stdHdr(); fnPrintf( m_pHRequest, HTML_DOCTYPE "<HTML>\n"); if (bAutoRefresh) { // Send back the page with a refresh command in the header fnPrintf( m_pHRequest, "<HEAD>" "<META http-equiv=\"refresh\" content=\"5; url=%s/SCacheMgr?Refresh\">" "<TITLE>gv_FlmSysData.SCacheMgr</TITLE>\n", m_pszURLString); printStyle(); popupFrame(); //Spits out a Javascript function that will open a new window.. fnPrintf( m_pHRequest, "\n</HEAD>\n<body>\n"); f_sprintf( (char *)pszTemp, "<A HREF=%s/SCacheMgr>Stop Auto-refresh</A>", m_pszURLString); } else // bAutoRefresh == FALSE { // Send back a page without the refresh command fnPrintf( m_pHRequest, "<HEAD>" "<TITLE>gv_FlmSysData.SCacheMgr</TITLE>\n"); printStyle(); popupFrame(); //Spits out a Javascript function that will open a new window.. fnPrintf( m_pHRequest, "\n</HEAD>\n<body>\n"); f_sprintf( (char *)pszTemp, "<A HREF=%s/SCacheMgr?Refresh>Start Auto-refresh (5 sec.)</A>", m_pszURLString); } // Write out the table headings printTableStart( "SCache Manager Structure", 4); printTableRowStart(); printColumnHeading( "", JUSTIFY_LEFT, FLM_IMON_COLOR_PUTTY_1, 4, 1, FALSE); fnPrintf( m_pHRequest, "<A HREF=%s/SCacheMgr>Refresh</A>, %s\n", m_pszURLString, pszTemp); printColumnHeadingClose(); printTableRowEnd(); // Write out the table headings. printTableRowStart(); printColumnHeading( "Byte Offset (hex)"); printColumnHeading( "Field Name"); printColumnHeading( "Field Type"); printColumnHeading( "Value"); printTableRowEnd(); //Now - we have three rows in the table that may or may not have hyperlinks in them. printTableRowStart( bHighlight = ~bHighlight); flmPrintCacheLine(m_pHRequest, pszSCacheRequestString[0], "pMRUCache", &LocalSCacheMgr, &LocalSCacheMgr.pMRUCache); printTableRowStart( bHighlight = ~bHighlight); flmPrintCacheLine(m_pHRequest, pszSCacheRequestString[1], "pLRUCache", &LocalSCacheMgr, &LocalSCacheMgr.pLRUCache); printTableRowStart( bHighlight = ~bHighlight); flmPrintCacheLine(m_pHRequest, pszSCacheRequestString[2], "pFirstFree", &LocalSCacheMgr, &LocalSCacheMgr.pFirstFree); printTableRowStart( bHighlight = ~bHighlight); flmPrintCacheLine(m_pHRequest, pszSCacheRequestString[3], "pLastFree", &LocalSCacheMgr, &LocalSCacheMgr.pLastFree); //Format the strings that are displayed in the Offset column on of the table printOffset(&LocalSCacheMgr, &LocalSCacheMgr.ppHashTbl, szOffsetTable[0]); printOffset(&LocalSCacheMgr, &LocalSCacheMgr.Usage, szOffsetTable[1]); printOffset(&LocalSCacheMgr, &LocalSCacheMgr.bAutoCalcMaxDirty, szOffsetTable[2]); printOffset(&LocalSCacheMgr, &LocalSCacheMgr.uiMaxDirtyCache, szOffsetTable[3]); printOffset(&LocalSCacheMgr, &LocalSCacheMgr.uiLowDirtyCache, szOffsetTable[4]); printOffset(&LocalSCacheMgr, &LocalSCacheMgr.uiTotalUses, szOffsetTable[5]); printOffset(&LocalSCacheMgr, &LocalSCacheMgr.uiBlocksUsed, szOffsetTable[6]); printOffset(&LocalSCacheMgr, &LocalSCacheMgr.uiPendingReads, szOffsetTable[7]); printOffset(&LocalSCacheMgr, &LocalSCacheMgr.uiIoWaits, szOffsetTable[8]); printOffset(&LocalSCacheMgr, &LocalSCacheMgr.uiHashTblSize, szOffsetTable[9]); printOffset(&LocalSCacheMgr, &LocalSCacheMgr.uiHashTblBits, szOffsetTable[10]); #ifdef FLM_DEBUG printOffset(&LocalSCacheMgr, &LocalSCacheMgr.bDebug, szOffsetTable[11]); #endif printAddress( LocalSCacheMgr.ppHashTbl, szAddressTable[0]); printAddress( &LocalSCacheMgr.Usage, szAddressTable[1]); printTableRowStart( bHighlight = ~bHighlight); fnPrintf( m_pHRequest, TD_s "<td><A HREF=\"%s/SCacheHashTable?Start=0\">ppHashTbl</A></td>\n" "<td>SCACHE **</td>\n" "<td><A href=\"%s/SCacheHashTbl\">%s</A></td>\n", szOffsetTable[0], m_pszURLString, m_pszURLString, szAddressTable[0]); printTableRowEnd(); printTableRowStart( bHighlight = ~bHighlight); fnPrintf( m_pHRequest, TD_s "<td><A href=\"javascript:openPopup('%s/SCacheMgr?Usage')\">Usage</A></td>\n" "<td>FLM_CACHE_USAGE</td>\n" "<td><A href=\"javascript:openPopup('%s/SCacheMgr?Usage')\">%s</A></td>\n", szOffsetTable[1], m_pszURLString, m_pszURLString, szAddressTable[1]); printTableRowEnd(); // uiFreeCount printHTMLUint( (char *)"uiFreeCount", (char *)"FLMUINT", (void *)&LocalSCacheMgr, (void *)&LocalSCacheMgr.uiFreeCount, LocalSCacheMgr.uiFreeCount, (bHighlight = ~bHighlight)); // uiFreeBytes printHTMLUint( (char *)"uiFreeBytes", (char *)"FLMUINT", (void *)&LocalSCacheMgr, (void *)&LocalSCacheMgr.uiFreeBytes, LocalSCacheMgr.uiFreeBytes, (bHighlight = ~bHighlight)); // uiReplaceableCount printHTMLUint( (char *)"uiReplaceableCount", (char *)"FLMUINT", (void *)&LocalSCacheMgr, (void *)&LocalSCacheMgr.uiReplaceableCount, LocalSCacheMgr.uiReplaceableCount, (bHighlight = ~bHighlight)); // uiReplaceableBytes printHTMLUint( (char *)"uiReplaceableBytes", (char *)"FLMUINT", (void *)&LocalSCacheMgr, (void *)&LocalSCacheMgr.uiReplaceableBytes, LocalSCacheMgr.uiReplaceableBytes, (bHighlight = ~bHighlight)); printTableRowStart( bHighlight = ~bHighlight); fnPrintf( m_pHRequest, TD_s "<td>bAutoCalcMaxDirty</td>\n" "<td>FLMBOOL</td>\n" TD_i, szOffsetTable[2], LocalSCacheMgr.bAutoCalcMaxDirty); printTableRowEnd(); printTableRowStart( bHighlight = ~bHighlight); fnPrintf( m_pHRequest, TD_s "<td>uiMaxDirtyCache</td>\n" "<td>FLMUINT</td>\n" TD_lu, szOffsetTable[3], LocalSCacheMgr.uiMaxDirtyCache); printTableRowEnd(); printTableRowStart( bHighlight = ~bHighlight); fnPrintf( m_pHRequest, TD_s "<td>uiLowDirtyCache</td>\n" "<td>FLMUINT</td>\n" TD_lu, szOffsetTable[4], LocalSCacheMgr.uiLowDirtyCache); printTableRowEnd(); printTableRowStart( bHighlight = ~bHighlight); fnPrintf( m_pHRequest, TD_s "<td>uiTotalUses</td>\n" "<td>FLMUINT</td>\n" TD_lu, szOffsetTable[5], LocalSCacheMgr.uiTotalUses); printTableRowEnd(); printTableRowStart( bHighlight = ~bHighlight); fnPrintf( m_pHRequest, TD_s "<td>uiBlocksUsed</td> <td>FLMUINT</td>\n" TD_lu, szOffsetTable[6], LocalSCacheMgr.uiBlocksUsed); printTableRowEnd(); printTableRowStart( bHighlight = ~bHighlight); fnPrintf( m_pHRequest, TD_s "<td>uiPendingReads</td>\n" "<td>FLMUINT</td>\n" TD_lu, szOffsetTable[7], LocalSCacheMgr.uiPendingReads); printTableRowEnd(); printTableRowStart( bHighlight = ~bHighlight); fnPrintf( m_pHRequest, TD_s "<td>uiIoWaits</td>\n <td>FLMUINT</td>\n" TD_lu, szOffsetTable[8], LocalSCacheMgr.uiIoWaits); printTableRowEnd(); printTableRowStart( bHighlight = ~bHighlight); fnPrintf( m_pHRequest, TD_s "<td>uiHashTableSize</td>\n" "<td>FLMUINT</td>\n" TD_lu, szOffsetTable[9], LocalSCacheMgr.uiHashTblSize); printTableRowEnd(); printTableRowStart( bHighlight = ~bHighlight); fnPrintf( m_pHRequest, TD_s "<td>uiHashTableBits</td>\n" "<td>FLMUINT</td>\n" TD_lu, szOffsetTable[10], LocalSCacheMgr.uiHashTblBits); printTableRowEnd(); #ifdef FLM_DEBUG printTableRowStart( bHighlight = ~bHighlight); fnPrintf( m_pHRequest, TD_s "<td>bDebug</td>\n" "<td>FLMBOOL</td>\n" TD_i, szOffsetTable[11], LocalSCacheMgr.bDebug); printTableRowEnd(); #endif printTableEnd(); fnPrintf( m_pHRequest, "</BODY></HTML>\n"); fnEmit(); } Exit: if (pszTemp) { f_free( &pszTemp); } for (uiLoop = 0; uiLoop < NUM_CACHE_REQ_STRINGS; uiLoop++) { if( pszSCacheRequestString[uiLoop]) { f_free( &pszSCacheRequestString[uiLoop]); } } return( rc); }
/**************************************************************************** Desc: Prints the web page for an SCACHE struct ****************************************************************************/ RCODE F_SCacheBlockPage::display( FLMUINT uiNumParams, const char ** ppszParams) { RCODE rc = FERR_OK; FLMUINT uiBlkAddress = 0; FLMUINT uiLowTransID = 0; FLMUINT uiHighTransID = 0; FFILE * pFile; FLMBOOL bHighlight = FALSE; char * pszTemp = NULL; char * pszTemp1 = NULL; FLMUINT uiLoop = 0; char szOffsetTable[10][6]; char szAddressTable[4][20]; SCACHE LocalSCacheBlock; FLMUINT uiPFileBucket = 0; char * pszSCacheRequestString[8] = {0, 0, 0, 0, 0, 0, 0, 0}; char * pszSCacheDataRequest = NULL; char * pszSCacheAutoRequest = NULL; char * pszSCacheUseListRequest = NULL; char * pszSCacheNotifyListRequest = NULL; char * pszFFileRequest = NULL; char * pszFlagNames = NULL; if( RC_BAD( rc = f_alloc( 200, &pszTemp))) { printErrorPage( rc, TRUE, (char *)"Failed to allocate temporary buffer"); goto Exit; } if( RC_BAD( rc = f_alloc( 200, &pszTemp1))) { printErrorPage( rc, TRUE, (char *)"Failed to allocate temporary buffer"); goto Exit; } // Allocate memory for all those string pointers we declared above... for (uiLoop = 0; uiLoop < 8; uiLoop++) { if( RC_BAD( rc = f_alloc( 150, &pszSCacheRequestString[ uiLoop]))) { goto Exit; } } if( RC_BAD( rc = f_alloc( 150, &pszSCacheDataRequest))) { goto Exit; } if( RC_BAD( rc = f_alloc( 150, &pszSCacheAutoRequest))) { goto Exit; } if( RC_BAD( rc = f_alloc( 150, &pszSCacheUseListRequest))) { goto Exit; } if( RC_BAD( rc = f_alloc( 150, &pszSCacheNotifyListRequest))) { goto Exit; } if( RC_BAD( rc = f_alloc( 100, &pszFFileRequest))) { goto Exit; } if( RC_BAD( rc = f_alloc( 100, &pszFlagNames))) { goto Exit; } f_mutexLock( gv_FlmSysData.hShareMutex); rc = locateSCacheBlock( uiNumParams, ppszParams, &LocalSCacheBlock, &uiBlkAddress, &uiLowTransID, &uiHighTransID, &pFile); if (RC_OK(rc) && LocalSCacheBlock.pFile) { uiPFileBucket = LocalSCacheBlock.pFile->uiBucket; } if (RC_OK( rc)) { // Build the proper strings to request various other SCache blocks flmBuildSCacheBlockString( pszSCacheRequestString[0], LocalSCacheBlock.pPrevInFile); flmBuildSCacheBlockString( pszSCacheRequestString[1], LocalSCacheBlock.pNextInFile); flmBuildSCacheBlockString( pszSCacheRequestString[2], LocalSCacheBlock.pPrevInGlobalList); flmBuildSCacheBlockString( pszSCacheRequestString[3], LocalSCacheBlock.pNextInGlobalList); flmBuildSCacheBlockString( pszSCacheRequestString[4], LocalSCacheBlock.pPrevInHashBucket); flmBuildSCacheBlockString( pszSCacheRequestString[5], LocalSCacheBlock.pNextInHashBucket); flmBuildSCacheBlockString( pszSCacheRequestString[6], LocalSCacheBlock.pPrevInVersionList); flmBuildSCacheBlockString( pszSCacheRequestString[7], LocalSCacheBlock.pNextInVersionList); // Build the proper string to request the current Page flmBuildSCacheBlockString( pszSCacheAutoRequest, &LocalSCacheBlock); } f_mutexUnlock( gv_FlmSysData.hShareMutex); if (RC_BAD( rc)) { if (rc == FERR_NOT_FOUND) { // The block wasn't there, print an error message and exit notFoundErr(); rc = FERR_OK; } else if (rc == FERR_MEM) { // Parameters were too long to store in the space provided. // Probably means that the URL was malformed... malformedUrlErr(); rc = FERR_OK; } goto Exit; } //Build the proper string to request this block's data... printAddress( pFile, szAddressTable[0]); f_sprintf( (char *)pszSCacheDataRequest, "%s/SCacheData?BlockAddress=%lu&File=%s&LowTransID=%lu&HighTransID=%lu", m_pszURLString, LocalSCacheBlock.uiBlkAddress, szAddressTable[0], uiLowTransID, uiHighTransID); #ifdef FLM_DEBUG //Build the proper string to request this block's use list if( LocalSCacheBlock.pUseList) { f_sprintf( (char *)pszSCacheUseListRequest, "%s/SCacheUseList?BlockAddress=%lu&File=%s&LowTransID=%lu&HighTransID=%lu", m_pszURLString, LocalSCacheBlock.uiBlkAddress, szAddressTable[0], uiLowTransID, uiHighTransID); } else { pszSCacheUseListRequest[0] = '\0'; } #endif //Build the proper string to request the notify list data... if (LocalSCacheBlock.pNotifyList) { f_sprintf( (char *)pszSCacheNotifyListRequest, "%s/SCacheNotifyList?BlockAddress=%lu&File=%s&LowTransID=%lu&HighTransID=%lu", m_pszURLString, LocalSCacheBlock.uiBlkAddress, szAddressTable[0], uiLowTransID, uiHighTransID); } else { pszSCacheNotifyListRequest[0] = '\0'; } //Build the proper string to request the FFile printAddress( LocalSCacheBlock.pFile, szAddressTable[0]); f_sprintf( (char *)pszFFileRequest, "%s/FFile?From=SCacheBlock&Bucket=%lu&Address=%s", m_pszURLString, uiPFileBucket, szAddressTable[0]); // Build a string with the names of all the flags that have been set... pszFlagNames[0]='\0'; if (LocalSCacheBlock.ui16Flags & CA_DIRTY) { f_strcat( pszFlagNames, "<BR> CA_DIRTY"); } if (LocalSCacheBlock.ui16Flags & CA_READ_PENDING) { f_strcat( pszFlagNames, "<BR> CA_READ_PENDING"); } if (LocalSCacheBlock.ui16Flags & CA_WRITE_TO_LOG) { f_strcat( pszFlagNames, "<BR> CA_WRITE_TO_LOG"); } if (LocalSCacheBlock.ui16Flags & CA_LOG_FOR_CP) { f_strcat( pszFlagNames, "<BR> CA_LOG_FOR_CP"); } if (LocalSCacheBlock.ui16Flags & CA_WAS_DIRTY) { f_strcat( pszFlagNames, "<BR> CA_WAS_DIRTY"); } if (LocalSCacheBlock.ui16Flags & CA_WRITE_PENDING) { f_strcat( pszFlagNames, "<BR> CA_WRITE_PENDING"); } if (LocalSCacheBlock.ui16Flags & CA_IN_WRITE_PENDING_LIST) { f_strcat( pszFlagNames, "<BR> CA_IN_WRITE_PENDING_LIST"); } // OK - Start outputting HTML... stdHdr(); fnPrintf( m_pHRequest, HTML_DOCTYPE "<html>\n"); // Determine if we are being requested to refresh this page or not. if (DetectParameter( uiNumParams, ppszParams, "Refresh")) { // Send back the page with a refresh command in the header fnPrintf( m_pHRequest, "<HEAD>\n" "<META http-equiv=\"refresh\" content=\"5; url=\"%s\">" "<TITLE>SCache Block</TITLE>\n", pszSCacheAutoRequest); printStyle(); popupFrame(); //Spits out a Javascript function that will open a new window.. fnPrintf( m_pHRequest, "</HEAD>\n<body>\n"); f_sprintf( (char*)pszTemp, "<A HREF=\"%s\">Stop Auto-refresh</A>", pszSCacheAutoRequest); } else { // Send back a page without the refresh command fnPrintf( m_pHRequest, "<HEAD>\n"); printStyle(); popupFrame(); //Spits out a Javascript function that will open a new window.. fnPrintf( m_pHRequest, "</HEAD>\n<body>\n"); f_sprintf( (char *)pszTemp, "<A HREF=\"%s?Refresh\">Start Auto-refresh (5 sec.)</A>", pszSCacheAutoRequest); } // Write out the table headings printTableStart( "SCache Block Structure", 4, 100); printTableRowStart(); printColumnHeading( "", JUSTIFY_LEFT, FLM_IMON_COLOR_PUTTY_1, 4, 1, FALSE); fnPrintf( m_pHRequest, "<A HREF=\"%s\">Refresh</A>, %s\n", pszSCacheAutoRequest, pszTemp); printColumnHeadingClose(); printTableRowEnd(); // Write out the table headings. printTableRowStart(); printColumnHeading( "Byte Offset (hex)"); printColumnHeading( "Field Name"); printColumnHeading( "Field Type"); printColumnHeading( "Value"); printTableRowEnd(); // Print the two rows for pPrevInFile and pNextInFile printTableRowStart( bHighlight = ~bHighlight); flmPrintCacheLine(m_pHRequest, pszSCacheRequestString[0], "pPrevInFile", &LocalSCacheBlock, &LocalSCacheBlock.pPrevInFile); printTableRowStart( bHighlight = ~bHighlight); flmPrintCacheLine(m_pHRequest, pszSCacheRequestString[1], "pNextInFile", &LocalSCacheBlock, &LocalSCacheBlock.pNextInFile); // Format the strings that are displayed in the Offset and Address // columns of the table printOffset( &LocalSCacheBlock, &LocalSCacheBlock.pucBlk, szOffsetTable[0]); printOffset( &LocalSCacheBlock, &LocalSCacheBlock.pFile, szOffsetTable[1]); printOffset( &LocalSCacheBlock, &LocalSCacheBlock.uiBlkAddress, szOffsetTable[2]); printOffset( &LocalSCacheBlock, &LocalSCacheBlock.pNotifyList, szOffsetTable[3]); printOffset( &LocalSCacheBlock, &LocalSCacheBlock.uiHighTransID, szOffsetTable[4]); printOffset( &LocalSCacheBlock, &LocalSCacheBlock.uiUseCount, szOffsetTable[5]); printOffset( &LocalSCacheBlock, &LocalSCacheBlock.ui16Flags, szOffsetTable[6]); printOffset( &LocalSCacheBlock, &LocalSCacheBlock.ui16BlkSize, szOffsetTable[7]); #ifdef FLM_DEBUG printOffset( &LocalSCacheBlock, &LocalSCacheBlock.uiChecksum, szOffsetTable[8]); printOffset( &LocalSCacheBlock, &LocalSCacheBlock.pUseList, szOffsetTable[9]); #endif printAddress( LocalSCacheBlock.pucBlk, szAddressTable[0]); printAddress( LocalSCacheBlock.pFile, szAddressTable[1]); printAddress( LocalSCacheBlock.pNotifyList, szAddressTable[2]); #ifdef FLM_DEBUG printAddress( LocalSCacheBlock.pUseList, szAddressTable[3]); #endif printTableRowStart( bHighlight = ~bHighlight); fnPrintf( m_pHRequest, TD_s "<td><A HREF=\"javascript:openPopup('%s')\">pucBlk</A></td>\n" "<td>FLMBYTE *</td>\n<td><A HREF=\"javascript:openPopup('%s')\">%s</A></td>\n", szOffsetTable[0], pszSCacheDataRequest, pszSCacheDataRequest, szAddressTable[0] ); printTableRowEnd(); printTableRowStart( bHighlight = ~bHighlight); fnPrintf( m_pHRequest, TD_s "<td><A href=%s>pFile</A></td>\n" "<td>FFILE *</td>\n<td><A HREF=%s>%s</a></td>\n", szOffsetTable[1], pszFFileRequest, pszFFileRequest, szAddressTable[1]); printTableRowEnd(); printTableRowStart( bHighlight = ~bHighlight); fnPrintf( m_pHRequest, TD_s "<td>uiBlkAddress</td>\n<td>FLMUINT</td>\n" "<td>0x%lX</td>\n", szOffsetTable[2], LocalSCacheBlock.uiBlkAddress); printTableRowEnd(); //Print the rows for the remaining SCache * fields printTableRowStart( bHighlight = ~bHighlight); flmPrintCacheLine(m_pHRequest, pszSCacheRequestString[2], "pPrevInGlobalList", &LocalSCacheBlock, &LocalSCacheBlock.pPrevInGlobalList); printTableRowStart( bHighlight = ~bHighlight); flmPrintCacheLine(m_pHRequest, pszSCacheRequestString[3], "pNextInGlobalList", &LocalSCacheBlock, &LocalSCacheBlock.pNextInGlobalList); printTableRowStart( bHighlight = ~bHighlight); flmPrintCacheLine(m_pHRequest, pszSCacheRequestString[4], "pPrevInHashBucket", &LocalSCacheBlock, &LocalSCacheBlock.pPrevInHashBucket); printTableRowStart( bHighlight = ~bHighlight); flmPrintCacheLine(m_pHRequest, pszSCacheRequestString[5], "pNextInHashBucket", &LocalSCacheBlock, &LocalSCacheBlock.pNextInHashBucket); printTableRowStart( bHighlight = ~bHighlight); flmPrintCacheLine(m_pHRequest, pszSCacheRequestString[6], "pPrevInVersionList", &LocalSCacheBlock, &LocalSCacheBlock.pPrevInVersionList); printTableRowStart( bHighlight = ~bHighlight); flmPrintCacheLine(m_pHRequest, pszSCacheRequestString[7], "pNextInVersionList", &LocalSCacheBlock, &LocalSCacheBlock.pNextInVersionList); //Notify list line printTableRowStart( bHighlight = ~bHighlight); if (LocalSCacheBlock.pNotifyList) { fnPrintf( m_pHRequest, TD_s " <td> <A HREF=\"javascript:openPopup('%s')\"> pNotifyList </A> </td> <td>FNOTIFY *</td> " "<td> <A HREF=\"javascript:openPopup('%s')\"> %s </A> </td>", szOffsetTable[3], pszSCacheNotifyListRequest, pszSCacheNotifyListRequest, szAddressTable[2]); } else { fnPrintf( m_pHRequest, TD_s " <td> pNotifyList </td> <td>FNOTIFY *</td> " "<td> 0x0 </td>", szOffsetTable[3]); } printTableRowEnd(); printTableRowStart( bHighlight = ~bHighlight); fnPrintf( m_pHRequest, TD_s "<td>uiHighTransID</td>\n" "<td>FLMUINT</td>\n" TD_8x, szOffsetTable[4], LocalSCacheBlock.uiHighTransID); printTableRowEnd(); printTableRowStart( bHighlight = ~bHighlight); fnPrintf( m_pHRequest, TD_s "<td>uiUseCount</td>\n<td>FLMUINT</td>\n" TD_lu, szOffsetTable[5], LocalSCacheBlock.uiUseCount); printTableRowEnd(); printTableRowStart( bHighlight = ~bHighlight); fnPrintf( m_pHRequest, TD_s "<td>ui16Flags</td>\n<td>FLMUINT16</td>\n" "<td>0x%04X %s</td>\n", szOffsetTable[6], LocalSCacheBlock.ui16Flags, pszFlagNames); printTableRowEnd(); printTableRowStart( bHighlight = ~bHighlight); fnPrintf( m_pHRequest, TD_s "<td>ui16BlkSize</td>\n<td>FLMUINT16</td>\n" TD_i, szOffsetTable[7], LocalSCacheBlock.ui16BlkSize); printTableRowEnd(); #ifdef FLM_DEBUG printTableRowStart( bHighlight = ~bHighlight); fnPrintf( m_pHRequest, TD_s "<td>uiChecksum</td>\n" "<td>FLMUINT</td>\n" TD_8x, szOffsetTable[8], LocalSCacheBlock.uiChecksum); printTableRowEnd(); #endif #ifdef FLM_DEBUG //Last line - the use list... printTableRowStart( bHighlight = ~bHighlight); if (LocalSCacheBlock.pUseList) { fnPrintf( m_pHRequest, TD_s " <td> <A href=\"javascript:openPopup('%s')> pUseList </A> </td> <td> SCACHE_USE_p </td> <td> <A href=\"javascript:openPopup('%s')> %s </A></td>", szOffsetTable[9], pszSCacheUseListRequest, pszSCacheUseListRequest, szAddressTable[3]); } else { fnPrintf( m_pHRequest, TD_s " <td> pUseList </td> <td> SCACHE_USE_p </td> <td> 0x0 </td>", szOffsetTable[9]); } printTableRowEnd(); #endif fnPrintf( m_pHRequest, TABLE_END "</BODY></HTML>\n"); fnEmit(); Exit: // Even though uiLoop2 is not in the same scope as uiLoop, VC6 still // complains if this is called uiLoop.... for (FLMUINT uiLoop2 = 0; uiLoop2 < 8; uiLoop2++) { if (pszSCacheRequestString[uiLoop2]) { f_free( &pszSCacheRequestString[uiLoop2]); } } if (pszSCacheDataRequest) { f_free( &pszSCacheDataRequest); } if (pszSCacheAutoRequest) { f_free( &pszSCacheAutoRequest); } if (pszSCacheUseListRequest) { f_free( &pszSCacheUseListRequest); } if (pszSCacheNotifyListRequest) { f_free( &pszSCacheNotifyListRequest); } if( pszFFileRequest) { f_free( &pszFFileRequest); } if( pszFlagNames) { f_free( &pszFlagNames); } if (pszTemp) { f_free( &pszTemp); } if (pszTemp1) { f_free( &pszTemp1); } return( rc); }
void printOffset(int64_t o, FILE *stream) { char temp[32]; printOffset(o, temp); printf("%s", temp); } // end of printOffset(FILE*)