url.cc
3.39 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007, 2008 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include <mailutils/cpp/url.h>
#include <mailutils/cpp/error.h>
#include <errno.h>
using namespace mailutils;
//
// Url
//
Url :: Url (const std::string& str)
{
int status = mu_url_create (&url, str.c_str ());
if (status)
throw Exception ("Url::Url", status);
}
Url :: Url (const char* str)
{
int status = mu_url_create (&url, str);
if (status)
throw Exception ("Url::Url", status);
}
Url :: Url (const mu_url_t url)
{
if (url == 0)
throw Exception ("Url::Url", EINVAL);
this->url = url;
}
Url :: ~Url ()
{
mu_url_destroy (&url);
}
void
Url :: parse ()
{
int status = mu_url_parse (url);
if (status)
throw Exception ("Url::parse", status);
}
long
Url :: getPort ()
{
long port;
int status = mu_url_get_port (url, &port);
if (status)
throw Exception ("Url::getPort", status);
return port;
}
std::string
Url :: getScheme ()
{
int status = mu_url_get_scheme (url, buf, sizeof (buf), NULL);
if (status == MU_ERR_NOENT)
return "";
else if (status)
throw Exception ("Url::getScheme", status);
return std::string (buf);
}
std::string
Url :: getUser ()
{
int status = mu_url_get_user (url, buf, sizeof (buf), NULL);
if (status == MU_ERR_NOENT)
return "";
else if (status)
throw Exception ("Url::getUser", status);
return std::string (buf);
}
std::string
Url :: getPasswd ()
{
int status = mu_url_get_passwd (url, buf, sizeof (buf), NULL);
if (status == MU_ERR_NOENT)
return "";
else if (status)
throw Exception ("Url::getPasswd", status);
return std::string (buf);
}
std::string
Url :: getAuth ()
{
int status = mu_url_get_auth (url, buf, sizeof (buf), NULL);
if (status == MU_ERR_NOENT)
return "";
else if (status)
throw Exception ("Url::getAuth", status);
return std::string (buf);
}
std::string
Url :: getHost ()
{
int status = mu_url_get_host (url, buf, sizeof (buf), NULL);
if (status == MU_ERR_NOENT)
return "";
else if (status)
throw Exception ("Url::getHost", status);
return std::string (buf);
}
std::string
Url :: getPath ()
{
int status = mu_url_get_path (url, buf, sizeof (buf), NULL);
if (status == MU_ERR_NOENT)
return "";
else if (status)
throw Exception ("Url::getPath", status);
return std::string (buf);
}
std::vector<std::string>
Url :: getQuery ()
{
size_t argc;
char **argv;
int status = mu_url_sget_query (url, &argc, &argv);
if (status)
throw Exception ("Url::getQuery", status);
std::vector<std::string> params;
for (int i = 0; i < argc; i++)
params.push_back (argv[i]);
return params;
}