diff options
Diffstat (limited to 'camel/camel-service.c')
-rw-r--r-- | camel/camel-service.c | 131 |
1 files changed, 127 insertions, 4 deletions
diff --git a/camel/camel-service.c b/camel/camel-service.c index 19c058f970..f83c3fe612 100644 --- a/camel/camel-service.c +++ b/camel/camel-service.c @@ -60,16 +60,25 @@ static gboolean service_connect(CamelService *service, CamelException *ex); static gboolean service_disconnect(CamelService *service, gboolean clean, CamelException *ex); static void cancel_connect (CamelService *service); -static GList * query_auth_types (CamelService *service, CamelException *ex); -static char * get_name (CamelService *service, gboolean brief); -static char * get_path (CamelService *service); +static GList *query_auth_types (CamelService *service, CamelException *ex); +static char *get_name (CamelService *service, gboolean brief); +static char *get_path (CamelService *service); + +static int service_setv (CamelObject *object, CamelException *ex, CamelArgV *args); +static int service_getv (CamelObject *object, CamelException *ex, CamelArgGetV *args); static void camel_service_class_init (CamelServiceClass *camel_service_class) { + CamelObjectClass *object_class = CAMEL_OBJECT_CLASS (camel_service_class); + parent_class = camel_type_get_global_classfuncs (CAMEL_OBJECT_TYPE); - + + /* virtual method overloading */ + object_class->setv = service_setv; + object_class->getv = service_getv; + /* virtual method definition */ camel_service_class->construct = construct; camel_service_class->connect = service_connect; @@ -144,6 +153,120 @@ camel_service_get_type (void) } +static int +service_setv (CamelObject *object, CamelException *ex, CamelArgV *args) +{ + CamelService *service = (CamelService *) object; + CamelURL *url = service->url; + gboolean reconnect = FALSE; + guint32 tag; + int i; + + for (i = 0; i < args->argc; i++) { + tag = args->argv[i].tag; + + /* make sure this arg wasn't already handled */ + if (tag & CAMEL_ARG_IGNORE) + continue; + + /* make sure this is an arg we're supposed to handle */ + if ((tag & CAMEL_ARG_TAG) <= CAMEL_SERVICE_ARG_FIRST || + (tag & CAMEL_ARG_TAG) >= CAMEL_SERVICE_ARG_FIRST + 100) + continue; + + if (tag == CAMEL_SERVICE_USERNAME) { + /* set the username */ + if (strcmp (url->user, args->argv[i].ca_str) != 0) { + camel_url_set_user (url, args->argv[i].ca_str); + reconnect = TRUE; + } + } else if (tag == CAMEL_SERVICE_AUTH) { + /* set the auth mechanism */ + if (strcmp (url->authmech, args->argv[i].ca_str) != 0) { + camel_url_set_authmech (url, args->argv[i].ca_str); + reconnect = TRUE; + } + } else if (tag == CAMEL_SERVICE_HOSTNAME) { + /* set the hostname */ + if (strcmp (url->host, args->argv[i].ca_str) != 0) { + camel_url_set_host (url, args->argv[i].ca_str); + reconnect = TRUE; + } + } else if (tag == CAMEL_SERVICE_PORT) { + /* set the port */ + if (url->port != args->argv[i].ca_int) { + camel_url_set_port (url, args->argv[i].ca_int); + reconnect = TRUE; + } + } else if (tag == CAMEL_SERVICE_PATH) { + /* set the path */ + if (strcmp (url->path, args->argv[i].ca_str) != 0) { + camel_url_set_host (url, args->argv[i].ca_str); + reconnect = TRUE; + } + } else { + /* error? */ + continue; + } + + /* let our parent know that we've handled this arg */ + camel_argv_ignore (args, i); + } + + if (reconnect) { + /* reconnect the service using the new URL */ + if (camel_service_disconnect (service, TRUE, ex)) + camel_service_connect (service, ex); + } + + return CAMEL_OBJECT_CLASS (parent_class)->setv (object, ex, args); +} + +static int +service_getv (CamelObject *object, CamelException *ex, CamelArgGetV *args) +{ + CamelService *service = (CamelService *) object; + CamelURL *url = service->url; + guint32 tag; + int i; + + for (i = 0; i < args->argc; i++) { + tag = args->argv[i].tag; + + /* make sure this is an arg we're supposed to handle */ + if ((tag & CAMEL_ARG_TAG) <= CAMEL_SERVICE_ARG_FIRST || + (tag & CAMEL_ARG_TAG) >= CAMEL_SERVICE_ARG_FIRST + 100) + continue; + + switch (tag) { + case CAMEL_SERVICE_USERNAME: + /* get the username */ + *args->argv[i].ca_str = url->user; + break; + case CAMEL_SERVICE_AUTH: + /* get the auth mechanism */ + *args->argv[i].ca_str = url->authmech; + break; + case CAMEL_SERVICE_HOSTNAME: + /* get the hostname */ + *args->argv[i].ca_str = url->host; + break; + case CAMEL_SERVICE_PORT: + /* get the port */ + *args->argv[i].ca_int = url->port; + break; + case CAMEL_SERVICE_PATH: + /* get the path */ + *args->argv[i].ca_str = url->path; + break; + default: + /* error? */ + } + } + + return CAMEL_OBJECT_CLASS (parent_class)->getv (object, ex, args); +} + static void construct (CamelService *service, CamelSession *session, CamelProvider *provider, CamelURL *url, CamelException *ex) |