1 /***************************************************************************
2 *            mgurlparser.h
3 *
4 *  Tue Sep 26 16:17:15 2006
5 *  Copyright  2006  liubin,China
6 *  Email multiget@gmail.com
7 ****************************************************************************/
8 
9 /*
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  (at your option) any later version.
14  *
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, write to the Free Software
22  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23  */
24 
25 #ifndef _URL_PARSER_H
26 #define _URL_PARSER_H
27 #include <string>
28 
29 #include "common.h"
30 
31 
32 
33 class CUrlParser
34 {
35 
36 public:
37     CUrlParser();
38     std::string GetUser();
39     std::string GetPass();
40     std::string GetServer();
41     int GetPort();
42     std::string GetFilePathName();
43     std::string GetEscFilePathName();
44     std::string GetFileName();
45     std::string GetRawUrl();
46     bool IsValidMirror();
47     _PROTYPE GetUrlType();
48     bool SetUrl( std::string fullurl );
49     bool RebuildUrl( std::string& fullurl, std::string user, std::string pass, std::string& rebuild );
50     std::string GetRefer(); //get default refer
51     void SetRefer( std::string& ref ); //set a user refer
52 
53 private:
54 
55     _PROTYPE UrlType( std::string fullurl );
56     bool GetUserAndPass( const std::string& fullurl, std::string& user, std::string& pass );
57     bool GetServerAndPort( const std::string& fullurl, std::string& server, int& port );
58     int GetDefaultPort( _PROTYPE protocol );
59     bool GetRawUrl( std::string& fullurl, std::string& rawurl );
60     bool GetPathFile( std::string& fullurl, std::string& pathfile );
61     bool GetRefer( std::string rawurl, std::string& refer );
62     void Precode( const std::string& pathfile, std::string& escfile );
63     void UnEscape( char *s );
64     void UnEscape( std::string& str );
65     std::string m_user;
66     std::string m_pass;
67     std::string m_file;
68     std::string m_server;
69     std::string m_escfile;
70     std::string m_refer; //only http
71     std::string m_raw;   //不含用户名和密码的URL
72     int m_port;
73     bool	m_bValidMirrorUrl;
74     _PROTYPE m_protocol;
75 
76 };
77 
78 #endif
79 
80