Commit acef5b6f acef5b6f3dae4a8a584603ad8947227967bf4736 by Wojciech Polak

Add Secret class to libmu_cpp.

1 parent 1f49d2c9
......@@ -45,7 +45,11 @@ main ()
cout << "\tscheme <" << url.get_scheme () << ">" << endl;
cout << "\tuser <" << url.get_user () << ">" << endl;
cout << "\tpasswd <" << url.get_passwd () << ">" << endl;
Secret sec = url.get_secret ();
cout << "\tpasswd <" << sec.password () << ">" << endl;
sec.password_unref ();
cout << "\tauth <" << url.get_auth () << ">" << endl;
cout << "\thost <" << url.get_host () << ">" << endl;
cout << "\tport " << url.get_port () << endl;
......
......@@ -37,6 +37,7 @@ MU_CXX_INCLUDES = \
mutil.h\
pop3.h\
registrar.h\
secret.h\
stream.h\
url.h
......
......@@ -35,6 +35,7 @@
#include <mailutils/cpp/mutil.h>
#include <mailutils/cpp/pop3.h>
#include <mailutils/cpp/registrar.h>
#include <mailutils/cpp/secret.h>
#include <mailutils/cpp/stream.h>
#include <mailutils/cpp/url.h>
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 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
*/
#ifndef _MUCPP_SECRET_H
#define _MUCPP_SECRET_H
#include <string>
#include <errno.h>
#include <mailutils/secret.h>
#include <mailutils/cpp/error.h>
namespace mailutils
{
class Secret
{
protected:
mu_secret_t secret;
bool owner;
public:
Secret (const std::string&);
Secret (const char* str, size_t len);
Secret (const mu_secret_t);
~Secret ();
std::string password ();
void password_unref ();
};
}
#endif // not _MUCPP_SECRET_H
......@@ -27,6 +27,7 @@
#include <errno.h>
#include <mailutils/url.h>
#include <mailutils/cpp/error.h>
#include <mailutils/cpp/secret.h>
namespace mailutils
{
......@@ -46,11 +47,11 @@ class Url
long get_port ();
std::string get_scheme ();
std::string get_user ();
std::string get_passwd ();
std::string get_auth ();
std::string get_host ();
std::string get_path ();
std::vector<std::string> get_query ();
Secret& get_secret ();
std::string to_string ();
friend std::ostream& operator << (std::ostream&, Url&);
......
......@@ -42,6 +42,7 @@ libmu_cpp_la_SOURCES = \
mutil.cc\
pop3.cc\
registrar.cc\
secret.cc\
stream.cc\
url.cc
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 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/secret.h>
using namespace mailutils;
//
// Secret
//
Secret :: Secret (const std::string& str)
{
int status = mu_secret_create (&secret, str.c_str (), str.size ());
if (status)
throw Exception ("Secret::Secret", status);
this->owner = true;
}
Secret :: Secret (const char* str, size_t len)
{
int status = mu_secret_create (&secret, str, len);
if (status)
throw Exception ("Secret::Secret", status);
this->owner = true;
}
Secret :: Secret (const mu_secret_t secret)
{
if (secret == 0)
throw Exception ("Secret::Secret", EINVAL);
this->secret = secret;
this->owner = false;
}
Secret :: ~Secret ()
{
if (this->owner)
mu_secret_destroy (&secret);
}
std::string
Secret :: password ()
{
return std::string (mu_secret_password (secret));
}
void
Secret :: password_unref ()
{
mu_secret_password_unref (secret);
}
......@@ -95,16 +95,16 @@ Url :: get_user ()
return std::string (buf ? buf : "");
}
std::string
Url :: get_passwd ()
Secret&
Url :: get_secret ()
{
const char* buf = NULL;
int status = mu_url_sget_passwd (url, &buf);
mu_secret_t c_secret;
int status = mu_url_get_secret (url, &c_secret);
if (status == MU_ERR_NOENT)
return "";
return *new Secret ("");
else if (status)
throw Exception ("Url::get_passwd", status);
return std::string (buf ? buf : "");
throw Exception ("Url::get_secret", status);
return *new Secret (c_secret);
}
std::string
......