zoukankan      html  css  js  c++  java
  • CTianwangFile

     1 #ifndef _TIANWANG_FILE_H_031104_
     2 #define _TIANWANG_FILE_H_031104_
     3 
     4 #include "Tse.h"
     5 #include "Url.h"
     6 #include "Page.h"
     7 #include "FileEngine.h"
     8 
     9 class CTianwangFile : public CFileEngine
    10 {
    11 public:
    12     CTianwangFile(string str);
    13     CTianwangFile();
    14     virtual ~CTianwangFile();
    15 
    16     inline int GetFileType() { return TIANWANG; }
    17 
    18     virtual bool Write(void *arg);
    19 };
    20 
    21 #endif /* _TIANWANG_FILE_H_031104_ */
     1 #include "TianwangFile.h"
     2 
     3 extern map<string,string> mapCacheHostLookup;
     4 
     5 CTianwangFile::CTianwangFile()
     6 {
     7 }
     8 
     9 CTianwangFile::CTianwangFile(string str) : CFileEngine(str)
    10 {
    11 }
    12 
    13 CTianwangFile::~CTianwangFile()
    14 {
    15     m_ofsFile.close();
    16 }
    17 
    18 bool CTianwangFile::Write(void * arg)
    19 {
    20     if( !arg || !m_ofsFile ){
    21         return false;
    22     }
    23 
    24     file_arg *pFile = (file_arg *)arg;
    25 
    26     CUrl *iUrl = pFile->pUrl;
    27     CPage *iPage = pFile->pPage;
    28 
    29     char strDownloadTime[128];
    30     time_t tDate;
    31 
    32     memset(strDownloadTime, 0, 128);
    33     time(&tDate);
    34     strftime(strDownloadTime, 128, "%a, %d %b %Y %H:%M:%S GMT", gmtime(&tDate));
    35 
    36     m_ofsFile << "version: 1.0\n";
    37     if( iPage->m_sLocation.length() == 0 ){//没有重定向
    38         m_ofsFile << "url: " << iUrl->m_sUrl;
    39     } else {//重定向了
    40         m_ofsFile << "url: " << iPage->m_sLocation;
    41         m_ofsFile << "\norigin: " << iUrl->m_sUrl;
    42     }
    43 
    44     m_ofsFile << "\ndate: " << strDownloadTime;//记录下下载时间
    45 
    46     //保存IP地址信息
    47     if( mapCacheHostLookup.find(iUrl->m_sHost) == mapCacheHostLookup.end() ){
    48         m_ofsFile << "\nip: " << iUrl->m_sHost;
    49     } else {
    50         m_ofsFile << "\nip: " << ( *(mapCacheHostLookup.find(iUrl->m_sHost)) ).second;
    51     }
    52 
    53     //保存网页长度
    54     m_ofsFile << "\nlength: " << iPage->m_nLenContent + iPage->m_nLenHeader + 1
    55         << "\n\n" << iPage->m_sHeader << "\n";
    56 
    57     m_ofsFile.write( iPage->m_sContent.c_str(), iPage->m_nLenContent );
    58     m_ofsFile << endl;
    59 
    60     return true;
    61 }
  • 相关阅读:
    Lucene全文检索
    数据库设计样例
    tortoisegit 保存用户名密码
    ServletContextListener 解析用法
    !! 浅谈Java学习方法和后期面试技巧
    佳能2780打印机老出5100错误
    蓝屏
    股市口诀
    如何准确进行T+0操作
    通达信:显示K线图日期
  • 原文地址:https://www.cnblogs.com/kakamilan/p/2580727.html
Copyright © 2011-2022 走看看