| 1 |
|
| 2 |
|
| 3 |
. |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#include "config.h" |
| 21 |
|
| 22 |
#include <stdint.h> |
| 23 |
|
| 24 |
#include <glib-object.h> |
| 25 |
|
| 26 |
#include "goabackendenums-priv.h" |
| 27 |
#include "goabackendenumtypes-priv.h" |
| 28 |
#include "goaserviceconfig.h" |
| 29 |
|
| 30 |
#include "goamailconfig.h" |
| 31 |
|
| 32 |
struct _GoaMailConfig |
| 33 |
{ |
| 34 |
GoaServiceConfig parent_instance; |
| 35 |
|
| 36 |
char *username; |
| 37 |
char *hostname; |
| 38 |
uint16_t port; |
| 39 |
GoaTlsType encryption; |
| 40 |
}; |
| 41 |
|
| 42 |
G_DEFINE_FINAL_TYPE (GoaMailConfig, goa_mail_config, GOA_TYPE_SERVICE_CONFIG) |
| 43 |
|
| 44 |
typedef enum |
| 45 |
{ |
| 46 |
PROP_ENCRYPTION = 1, |
| 47 |
PROP_HOSTNAME, |
| 48 |
PROP_PORT, |
| 49 |
PROP_USERNAME, |
| 50 |
} GoaMailConfigProperty; |
| 51 |
|
| 52 |
static GParamSpec *properties[PROP_USERNAME + 1] = { NULL, }; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
static void |
| 57 |
goa_mail_config_finalize (GObject *object) |
| 58 |
{ |
| 59 |
GoaMailConfig *self = GOA_MAIL_CONFIG (object); |
| 60 |
|
| 61 |
g_clear_pointer (&self->hostname, g_free); |
| 62 |
g_clear_pointer (&self->username, g_free); |
| 63 |
|
| 64 |
G_OBJECT_CLASS (goa_mail_config_parent_class)->finalize (object); |
| 65 |
} |
| 66 |
|
| 67 |
static void |
| 68 |
goa_mail_config_get_property (GObject *object, |
| 69 |
guint prop_id, |
| 70 |
GValue *value, |
| 71 |
GParamSpec *pspec) |
| 72 |
{ |
| 73 |
GoaMailConfig *self = GOA_MAIL_CONFIG (object); |
| 74 |
|
| 75 |
switch ((GoaMailConfigProperty) prop_id) |
| 76 |
{ |
| 77 |
case PROP_ENCRYPTION: |
| 78 |
g_value_set_enum (value, self->encryption); |
| 79 |
break; |
| 80 |
|
| 81 |
case PROP_HOSTNAME: |
| 82 |
g_value_set_string (value, self->hostname); |
| 83 |
break; |
| 84 |
|
| 85 |
case PROP_PORT: |
| 86 |
g_value_set_uint (value, self->port); |
| 87 |
break; |
| 88 |
|
| 89 |
case PROP_USERNAME: |
| 90 |
g_value_set_string (value, self->username); |
| 91 |
break; |
| 92 |
|
| 93 |
default: |
| 94 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 95 |
break; |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
static void |
| 100 |
goa_mail_config_set_property (GObject *object, |
| 101 |
guint prop_id, |
| 102 |
const GValue *value, |
| 103 |
GParamSpec *pspec) |
| 104 |
{ |
| 105 |
GoaMailConfig *self = GOA_MAIL_CONFIG (object); |
| 106 |
|
| 107 |
switch ((GoaMailConfigProperty) prop_id) |
| 108 |
{ |
| 109 |
case PROP_ENCRYPTION: |
| 110 |
goa_mail_config_set_encryption (self, g_value_get_enum (value)); |
| 111 |
break; |
| 112 |
|
| 113 |
case PROP_HOSTNAME: |
| 114 |
goa_mail_config_set_hostname (self, g_value_get_string (value)); |
| 115 |
break; |
| 116 |
|
| 117 |
case PROP_PORT: |
| 118 |
goa_mail_config_set_port (self, g_value_get_uint (value)); |
| 119 |
break; |
| 120 |
|
| 121 |
case PROP_USERNAME: |
| 122 |
goa_mail_config_set_username (self, g_value_get_string (value)); |
| 123 |
break; |
| 124 |
|
| 125 |
default: |
| 126 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 127 |
break; |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
static void |
| 134 |
goa_mail_config_init (GoaMailConfig *self) |
| 135 |
{ |
| 136 |
} |
| 137 |
|
| 138 |
static void |
| 139 |
goa_mail_config_class_init (GoaMailConfigClass *klass) |
| 140 |
{ |
| 141 |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 142 |
|
| 143 |
object_class->finalize = goa_mail_config_finalize; |
| 144 |
object_class->get_property = goa_mail_config_get_property; |
| 145 |
object_class->set_property = goa_mail_config_set_property; |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
properties[PROP_ENCRYPTION] = |
| 153 |
g_param_spec_enum ("encryption", NULL, NULL, |
| 154 |
GOA_TYPE_TLS_TYPE, |
| 155 |
GOA_TLS_TYPE_NONE, |
| 156 |
(G_PARAM_READWRITE | |
| 157 |
G_PARAM_STATIC_STRINGS | |
| 158 |
G_PARAM_EXPLICIT_NOTIFY)); |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
properties[PROP_HOSTNAME] = |
| 166 |
g_param_spec_string ("hostname", NULL, NULL, |
| 167 |
NULL, |
| 168 |
(G_PARAM_READWRITE | |
| 169 |
G_PARAM_STATIC_STRINGS | |
| 170 |
G_PARAM_EXPLICIT_NOTIFY)); |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
properties[PROP_PORT] = |
| 178 |
g_param_spec_uint ("port", NULL, NULL, |
| 179 |
0, G_MAXUINT16, |
| 180 |
0, |
| 181 |
(G_PARAM_READWRITE | |
| 182 |
G_PARAM_STATIC_STRINGS | |
| 183 |
G_PARAM_EXPLICIT_NOTIFY)); |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
properties[PROP_USERNAME] = |
| 191 |
g_param_spec_string ("username", NULL, NULL, |
| 192 |
NULL, |
| 193 |
(G_PARAM_READWRITE | |
| 194 |
G_PARAM_STATIC_STRINGS | |
| 195 |
G_PARAM_EXPLICIT_NOTIFY)); |
| 196 |
|
| 197 |
g_object_class_install_properties (object_class, G_N_ELEMENTS (properties), properties); |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
GoaMailConfig * |
| 211 |
goa_mail_config_new (const char *service) |
| 212 |
{ |
| 213 |
g_return_val_if_fail (service != NULL, NULL); |
| 214 |
|
| 215 |
return g_object_new (GOA_TYPE_MAIL_CONFIG, |
| 216 |
"service", service, |
| 217 |
NULL); |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
GoaTlsType |
| 231 |
goa_mail_config_get_encryption (GoaMailConfig *config) |
| 232 |
{ |
| 233 |
g_return_val_if_fail (GOA_IS_MAIL_CONFIG (config), GOA_TLS_TYPE_NONE); |
| 234 |
|
| 235 |
return config->encryption; |
| 236 |
} |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
void |
| 246 |
goa_mail_config_set_encryption (GoaMailConfig *config, |
| 247 |
GoaTlsType encryption) |
| 248 |
{ |
| 249 |
g_return_if_fail (GOA_IS_MAIL_CONFIG (config)); |
| 250 |
g_return_if_fail (encryption >= GOA_TLS_TYPE_NONE && encryption <= GOA_TLS_TYPE_SSL); |
| 251 |
|
| 252 |
if (config->encryption != encryption) |
| 253 |
{ |
| 254 |
config->encryption = encryption; |
| 255 |
g_object_notify_by_pspec (G_OBJECT (config), properties[PROP_ENCRYPTION]); |
| 256 |
} |
| 257 |
} |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
const char * |
| 270 |
goa_mail_config_get_hostname (GoaMailConfig *config) |
| 271 |
{ |
| 272 |
g_return_val_if_fail (GOA_IS_MAIL_CONFIG (config), NULL); |
| 273 |
|
| 274 |
return config->hostname; |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
void |
| 285 |
goa_mail_config_set_hostname (GoaMailConfig *config, |
| 286 |
const char *hostname) |
| 287 |
{ |
| 288 |
g_return_if_fail (GOA_IS_MAIL_CONFIG (config)); |
| 289 |
|
| 290 |
if (g_set_str (&config->hostname, hostname)) |
| 291 |
g_object_notify_by_pspec (G_OBJECT (config), properties[PROP_HOSTNAME]); |
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
uint16_t |
| 308 |
goa_mail_config_get_port (GoaMailConfig *config) |
| 309 |
{ |
| 310 |
g_return_val_if_fail (GOA_IS_MAIL_CONFIG (config), 0); |
| 311 |
|
| 312 |
if (config->port == 0) |
| 313 |
{ |
| 314 |
const char *service = NULL; |
| 315 |
|
| 316 |
service = goa_service_config_get_service (GOA_SERVICE_CONFIG (config)); |
| 317 |
if (g_ascii_strcasecmp (service, GOA_SERVICE_TYPE_IMAP) == 0) |
| 318 |
{ |
| 319 |
return (config->encryption == GOA_TLS_TYPE_SSL) ? 993 : 143; |
| 320 |
} |
| 321 |
else if (g_ascii_strcasecmp (service, GOA_SERVICE_TYPE_SMTP) == 0) |
| 322 |
{ |
| 323 |
return (config->encryption == GOA_TLS_TYPE_SSL) ? 465 : 587; |
| 324 |
} |
| 325 |
} |
| 326 |
|
| 327 |
return config->port; |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
void |
| 338 |
goa_mail_config_set_port (GoaMailConfig *config, |
| 339 |
uint16_t port) |
| 340 |
{ |
| 341 |
g_return_if_fail (GOA_IS_MAIL_CONFIG (config)); |
| 342 |
g_return_if_fail (port <= G_MAXUINT16); |
| 343 |
|
| 344 |
if (config->port != port) |
| 345 |
{ |
| 346 |
config->port = port; |
| 347 |
g_object_notify_by_pspec (G_OBJECT (config), properties[PROP_PORT]); |
| 348 |
} |
| 349 |
} |
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
const char * |
| 362 |
goa_mail_config_get_username (GoaMailConfig *config) |
| 363 |
{ |
| 364 |
g_return_val_if_fail (GOA_IS_MAIL_CONFIG (config), NULL); |
| 365 |
|
| 366 |
return config->username; |
| 367 |
} |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
void |
| 377 |
goa_mail_config_set_username (GoaMailConfig *config, |
| 378 |
const char *username) |
| 379 |
{ |
| 380 |
g_return_if_fail (GOA_IS_MAIL_CONFIG (config)); |
| 381 |
|
| 382 |
if (g_set_str (&config->username, username)) |
| 383 |
g_object_notify_by_pspec (G_OBJECT (config), properties[PROP_USERNAME]); |
| 384 |
} |
| 385 |
|