1 /***************************************************************************
2                           chublistmanager.h  -  description
3                              -------------------
4     begin                : Don Mai 16 2002
5     copyright            : (C) 2002-2004 by Mathias Küster
6     email                : mathen@users.berlios.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef CHUBLISTMANAGER_H
19 #define CHUBLISTMANAGER_H
20 
21 /**
22   *@author Mathias Küster
23   *
24   * This handles downloading and parsing hublist data,
25   * the data is then sent to CConfig for storage.
26   */
27 
28 #include <dclib/dcos.h>
29 #include <dclib/core/cstring.h>
30 #include <dclib/core/cthread.h>
31 #include <dclib/core/csingleton.h>
32 #include <dclib/core/clist.h>
33 
34 class CHubListManager;
35 class CHttp;
36 class DCConfigHubListUrl;
37 class CByteArray;
38 class DCConfigHubItem;
39 class CXml;
40 class CDCMessage;
41 class _CCallback0;
42 
43 class CXmlColumn {
44 public:
45 	/** */
CXmlColumn()46 	CXmlColumn() {};
47 	/** */
~CXmlColumn()48 	~CXmlColumn() {};
49 	/** Column name */
50 	CString m_sName;
51 	/** Column type */
52 	CString m_sType;
53 	/** Column value */
54 	CString m_sValue;
55 };
56 
57 class CHubListManager : public CSingleton<CHubListManager> {
58 public:
59 	/** */
60 	CHubListManager();
61 	/** */
62 	virtual ~CHubListManager();
63 
64 	/** callback function */
DC_CallBack(CDCMessage *)65 	virtual int DC_CallBack( CDCMessage * ) { return -1; };
66 
67 protected:
68 	/** */
69 	bool GetPublicHubList();
70 	/** */
71 	bool NextHubListUrl();
72 
73 	/** */
74 	CThread m_Thread;
75 
76 	/** */
77 	CHttp * m_pHttp;
78 	/** */
79 	CList<DCConfigHubListUrl> * m_pHubListUrlList;
80 	/** */
81 	DCConfigHubListUrl * m_pHubListUrl;
82 	/** data from old .config format hub lists */
83 	CByteArray * m_pHubListData;
84 	/** data from xml hublists */
85 	CList<DCConfigHubItem> * m_pXmlHubs;
86 
87 
88 private:
89 	/** http callback function */
90 	int HttpCallBack( CDCMessage * msg );
91 	/** called by CManager */
92 	int Callback();
93 	/** */
94 	int ParsePublicHubList();
95 	/** Parses XML hublist, adding items to m_pXmlHubs */
96 	int ParseXmlPublicHubList();
97 	/** Returns number of hubs parsed */
98 	int ParseXmlHubs( CList<CXmlColumn> * cols );
99 	/** Searches for and gets column headings */
100 	CList<CXmlColumn> * FindAndParseXmlColumns();
101 	/** Gets column values for one hub */
102 	void ParseXmlHub( CList<CXmlColumn> * cols );
103 	/** Handle the hublist data, decompressing and parsing the xml if necessary */
104 	void HandleHubListData( const CString & url, CByteArray * data );
105 
106 	/** */
107 	time_t m_nReloadHubListTimeout;
108 	/** */
109 	bool m_bGetHubListDone;
110 	/** CXml object for parsing XML hublists */
111 	CXml * m_pXml;
112 
113 	/** */
114 	_CCallback0 * m_pCallback;
115 };
116 
117 #endif
118