1 /*****
2 *
3 * Copyright (C) 2009-2015 CS-SI. All Rights Reserved.
4 * Author: Yoann Vandoorselaere <yoann@gmail.com>
5 *
6 * This file is part of the Prelude library.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 *****/
23
24 #include "prelude-error.hxx"
25 #include "prelude-client-profile.h"
26 #include "prelude-client-profile.hxx"
27
28
29 using namespace Prelude;
30
31
32
33 #define _RETURN_NEW_BUFFER_FROM_FUNCTION_BUFFERSIZE(function) do { \
34 char buf[PATH_MAX]; \
35 \
36 (function)(_profile, buf, sizeof(buf)); \
37 \
38 return std::string(buf); \
39 } while(0)
40
41
ClientProfile()42 ClientProfile::ClientProfile()
43 {
44 _profile = NULL;
45 }
46
47
ClientProfile(prelude_client_profile_t * profile)48 ClientProfile::ClientProfile(prelude_client_profile_t *profile) : _profile(profile)
49 {
50 _profile = profile;
51 }
52
53
ClientProfile(const char * profile)54 ClientProfile::ClientProfile(const char *profile)
55 {
56 int ret;
57
58 ret = prelude_client_profile_new(&_profile, profile);
59 if ( ret < 0 )
60 throw PreludeError(ret);
61 }
62
ClientProfile(const ClientProfile & p)63 ClientProfile::ClientProfile(const ClientProfile &p)
64 {
65 _profile = (p._profile) ? prelude_client_profile_ref(p._profile) : NULL;
66 }
67
68
~ClientProfile()69 ClientProfile::~ClientProfile()
70 {
71 if ( _profile )
72 prelude_client_profile_destroy(_profile);
73 }
74
75
getConfigFilename()76 const std::string ClientProfile::getConfigFilename()
77 {
78 _RETURN_NEW_BUFFER_FROM_FUNCTION_BUFFERSIZE(prelude_client_profile_get_config_filename);
79 }
80
getAnalyzeridFilename()81 const std::string ClientProfile::getAnalyzeridFilename()
82 {
83 _RETURN_NEW_BUFFER_FROM_FUNCTION_BUFFERSIZE(prelude_client_profile_get_analyzerid_filename);
84 }
85
getTlsKeyFilename()86 const std::string ClientProfile::getTlsKeyFilename()
87 {
88 _RETURN_NEW_BUFFER_FROM_FUNCTION_BUFFERSIZE(prelude_client_profile_get_tls_key_filename);
89 }
90
getTlsServerCaCertFilename()91 const std::string ClientProfile::getTlsServerCaCertFilename()
92 {
93 _RETURN_NEW_BUFFER_FROM_FUNCTION_BUFFERSIZE(prelude_client_profile_get_tls_server_ca_cert_filename);
94 }
95
getTlsServerKeyCertFilename()96 const std::string ClientProfile::getTlsServerKeyCertFilename()
97 {
98 _RETURN_NEW_BUFFER_FROM_FUNCTION_BUFFERSIZE(prelude_client_profile_get_tls_server_keycert_filename);
99 }
100
getTlsServerCrlFilename()101 const std::string ClientProfile::getTlsServerCrlFilename()
102 {
103 _RETURN_NEW_BUFFER_FROM_FUNCTION_BUFFERSIZE(prelude_client_profile_get_tls_server_crl_filename);
104 }
105
getTlsClientKeyCertFilename()106 const std::string ClientProfile::getTlsClientKeyCertFilename()
107 {
108 _RETURN_NEW_BUFFER_FROM_FUNCTION_BUFFERSIZE(prelude_client_profile_get_tls_client_keycert_filename);
109 }
110
getTlsClientTrustedCertFilename()111 const std::string ClientProfile::getTlsClientTrustedCertFilename()
112 {
113 _RETURN_NEW_BUFFER_FROM_FUNCTION_BUFFERSIZE(prelude_client_profile_get_tls_client_trusted_cert_filename);
114 }
115
getBackupDirname()116 const std::string ClientProfile::getBackupDirname()
117 {
118 _RETURN_NEW_BUFFER_FROM_FUNCTION_BUFFERSIZE(prelude_client_profile_get_backup_dirname);
119 }
120
getProfileDirname()121 const std::string ClientProfile::getProfileDirname()
122 {
123 _RETURN_NEW_BUFFER_FROM_FUNCTION_BUFFERSIZE(prelude_client_profile_get_profile_dirname);
124 }
125
126
setPrefix(const char * prefix)127 void ClientProfile::setPrefix(const char *prefix)
128 {
129 int ret;
130
131 ret = prelude_client_profile_set_prefix(_profile, prefix);
132 if ( ret < 0 )
133 throw PreludeError(ret);
134 }
135
136
getPrefix()137 const std::string ClientProfile::getPrefix()
138 {
139 _RETURN_NEW_BUFFER_FROM_FUNCTION_BUFFERSIZE(prelude_client_profile_get_prefix);
140 }
141
142
143
operator prelude_client_profile_t*() const144 ClientProfile::operator prelude_client_profile_t *() const
145 {
146 return _profile;
147 }
148
149
operator =(const ClientProfile & p)150 ClientProfile &ClientProfile::operator=(const ClientProfile &p)
151 {
152 if ( this != &p && _profile != p._profile ) {
153 if ( _profile )
154 prelude_client_profile_destroy(_profile);
155
156 _profile = (p._profile) ? prelude_client_profile_ref(p._profile) : NULL;
157 }
158
159 return *this;
160 }
161