CLink4SEFile

 1 #ifndef _LINK4SE_FILE_H_031208_
 2 #define _LINK4SE_FILE_H_031208_
 3 
 4 #include "Tse.h"
 5 #include "Url.h"
 6 #include "Page.h"
 7 #include "FileEngine.h"
 8 
 9 class CLink4SEFile : public CFileEngine
10 {
11 public:
12     CLink4SEFile(string str);
13     CLink4SEFile();
14     virtual ~CLink4SEFile();
15 
16     inline int GetFileType() { return LINK4SE; }
17 
18     virtual bool Write(void *arg);
19 };
20 
21 #endif /* _LINK4SE_FILE_H_031208_ */

 

 1 #include "Link4SEFile.h"
 2 
 3 extern map<string,string> mapCacheHostLookup;
 4 extern vector<string> vsParsedLinks;
 5 
 6 CLink4SEFile::CLink4SEFile()
 7 {
 8 }
 9 
10 CLink4SEFile::CLink4SEFile(string str) : CFileEngine(str)
11 {
12 }
13 
14 CLink4SEFile::~CLink4SEFile()
15 {
16     m_ofsFile.close();
17 }
18 
19 bool CLink4SEFile::Write(void * arg)
20 {
21     if (!arg || !m_ofsFile) return false;
22 
23     if (vsParsedLinks.size()==0) return false;
24 
25     file_arg *pFile = (file_arg *)arg;
26 
27     CUrl *iUrl = pFile->pUrl;
28     CPage *iPage = pFile->pPage;
29 
30     char strDownloadTime[128];
31     time_t tDate;
32 
33     memset(strDownloadTime, 0, 128);
34     time(&tDate);
35     strftime(strDownloadTime, 128, "%a, %d %b %Y %H:%M:%S GMT", gmtime(&tDate));
36 
37     string links;
38     vector<string>::iterator it;
39     for (it=vsParsedLinks.begin(); it!=vsParsedLinks.end(); ++it)
40     {
41         links = links + *it + "\n";
42     }
43 
44     m_ofsFile << "version: 1.0\n";
45     if( iPage->m_sLocation.length() == 0 ){
46         m_ofsFile << "url: " << iUrl->m_sUrl;
47     } else {
48         m_ofsFile << "url: " << iPage->m_sLocation;
49         m_ofsFile << "\norigin: " << iUrl->m_sUrl;
50     }
51 
52     m_ofsFile << "\ndate: " << strDownloadTime;
53     if( mapCacheHostLookup.find(iUrl->m_sHost) == mapCacheHostLookup.end() ){
54         m_ofsFile << "\nip: " << iUrl->m_sHost;
55     } else {
56         m_ofsFile << "\nip: " << ( *(mapCacheHostLookup.find(iUrl->m_sHost)) ).second;
57     }
58 
59     m_ofsFile << "\noutdegree: " << vsParsedLinks.size();
60     m_ofsFile << "\nlength: " << links.size() + iPage->m_nLenHeader + 1 
61         << "\n\n" << iPage->m_sHeader << "\n";
62 
63     m_ofsFile << links;
64     m_ofsFile << endl;
65 
66     return true;
67 }

转载于:https://www.cnblogs.com/kakamilan/archive/2012/07/07/2580719.html

你可能感兴趣的:(CLink4SEFile)