/
url.h
executable file
·99 lines (89 loc) · 2.7 KB
/
url.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* mDownloader - a multiple-threads downloading accelerator program that is based on Myget.
* Homepage: http://qinchuan.me/article.php?id=100
* 2015 By Richard (qc2105@qq.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Myget - A download accelerator for GNU/Linux
* Homepage: http://myget.sf.net
* 2005 by xiaosuo
*/
#ifndef _URL_H
#define _URL_H
// define some protocol type
enum Protocol{
HTTP,
FTP,
SFTP,
HTTPS,
MMS,
RTSP,
NONE
};
// parse the URL
class URL
{
public:
URL();
URL(URL& url);
URL& operator = (URL& url);
// free the stack
~URL();
// set the url
int set_url(const char *url);
// reset the url
int reset_url(const char *url);
// the the encoded url
const char* get_url(){ return url; }
// get the protocol
Protocol get_protocol(){ return protocol; }
// get the user
const char* get_user(){ return user; }
// get the user's password
const char* get_password(){ return password; }
// get the host
const char* get_host(){ return host; }
// get the port
int get_port(){ return port; }
// get the directory
const char* get_dir(){ return dir; }
// get the file
const char* get_file(){ return file; }
// get encode url and file needed by http protocol
const char* get_encoded_path(){ return path; }
// decode(), encode() and pre_encode() return the allocate memory, so need free
static const char* decode(const char* url);
static const char* encode(const char* url);
static const char* pre_encode(const char* pre_url);
private:
int _parse_fragment(char* &url);
int _parse_scheme(char* &url);
int _parse_location(char* &url);
int _parse_query_info(char* &url);
int _parse_parameters(char* &url);
int _parse_path(char* &url);
int _parse(const char *url);
void free_all(void);
const char *url; // the encoded url
const char *path;
Protocol protocol;
const char *user;
const char *password;
const char *host;
int port;
const char *dir;
const char *file;
};
#endif // _URL_H