diff options
author | Chris Toshok <toshok@helixcode.com> | 2000-07-13 02:14:31 +0800 |
---|---|---|
committer | Chris Toshok <toshok@src.gnome.org> | 2000-07-13 02:14:31 +0800 |
commit | 2d4ee0e3a3b914d14506fa89a15f0dad69498158 (patch) | |
tree | afe5735aa1c119e6586efd9ad542dd7dfc63f551 /camel/providers/nntp/camel-nntp-store.c | |
parent | 87a211d95ff93912225e6f342cee9b5ad47a5f8a (diff) | |
download | gsoc2013-evolution-2d4ee0e3a3b914d14506fa89a15f0dad69498158.tar gsoc2013-evolution-2d4ee0e3a3b914d14506fa89a15f0dad69498158.tar.gz gsoc2013-evolution-2d4ee0e3a3b914d14506fa89a15f0dad69498158.tar.bz2 gsoc2013-evolution-2d4ee0e3a3b914d14506fa89a15f0dad69498158.tar.lz gsoc2013-evolution-2d4ee0e3a3b914d14506fa89a15f0dad69498158.tar.xz gsoc2013-evolution-2d4ee0e3a3b914d14506fa89a15f0dad69498158.tar.zst gsoc2013-evolution-2d4ee0e3a3b914d14506fa89a15f0dad69498158.zip |
don't add test-newsrc to the build since it needs libcamel (which isn't
2000-07-12 Chris Toshok <toshok@helixcode.com>
* providers/nntp/Makefile.am: don't add test-newsrc to the build
since it needs libcamel (which isn't built at the time test-newsrc
needs linking.)
* providers/nntp/camel-nntp-utils.c (get_HEAD_headers): fill in
MessageInfo->message_id.
(get_XOVER_headers): same.
* providers/nntp/camel-nntp-folder.c (nntp_folder_init): move
summary loading here.
(nntp_folder_sync): summary/newsrc changes should be stored here.
put a comment to that effect.
(nntp_folder_set_message_flags): don't save the newsrc here.
(nntp_folder_get_uids): use g_ptr_array_index instead of the
cast/addition.
(nntp_folder_get_summary): no need to check if we should generate
the summary here. already done.
(nntp_folder_get_message_info): implement.
* providers/nntp/camel-nntp-store.c
(camel_nntp_store_get_toplevel_dir): use evolution_dir instead of
computing it ourselves.
(nntp_store_disconnect): call camel_nntp_newsrc_write.
(ensure_news_dir_exists): new function to create the news/<news
server> subdir.
(camel_nntp_store_class_init): hook up connect/disconnect and
finalize.
(nntp_store_connect): if ensure_news_dir_exists fails throw an
exception.
svn path=/trunk/; revision=4113
Diffstat (limited to 'camel/providers/nntp/camel-nntp-store.c')
-rw-r--r-- | camel/providers/nntp/camel-nntp-store.c | 259 |
1 files changed, 140 insertions, 119 deletions
diff --git a/camel/providers/nntp/camel-nntp-store.c b/camel/providers/nntp/camel-nntp-store.c index 96d11b4915..a7b8f7df01 100644 --- a/camel/providers/nntp/camel-nntp-store.c +++ b/camel/providers/nntp/camel-nntp-store.c @@ -55,8 +55,98 @@ static CamelServiceClass *service_class = NULL; #define CF_CLASS(so) CAMEL_FOLDER_CLASS (GTK_OBJECT(so)->klass) #define CNNTPF_CLASS(so) CAMEL_NNTP_FOLDER_CLASS (GTK_OBJECT(so)->klass) -static gboolean nntp_connect (CamelService *service, CamelException *ex); -static gboolean nntp_disconnect (CamelService *service, CamelException *ex); +static gboolean ensure_news_dir_exists (CamelNNTPStore *store); + +static gboolean +nntp_store_connect (CamelService *service, CamelException *ex) +{ + struct hostent *h; + struct sockaddr_in sin; + int fd; + char *buf; + CamelNNTPStore *store = CAMEL_NNTP_STORE (service); + + if (!ensure_news_dir_exists(store)) { + camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, + "Could not open directory for news server: %s", + strerror (errno)); + return FALSE; + } + + if (!service_class->connect (service, ex)) + return FALSE; + + h = camel_service_gethost (service, ex); + if (!h) + return FALSE; + + sin.sin_family = h->h_addrtype; + sin.sin_port = htons (service->url->port ? service->url->port : NNTP_PORT); + memcpy (&sin.sin_addr, h->h_addr, sizeof (sin.sin_addr)); + + fd = socket (h->h_addrtype, SOCK_STREAM, 0); + if (fd == -1 || + connect (fd, (struct sockaddr *)&sin, sizeof(sin)) == -1) { + camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, + "Could not connect to %s (port %s): %s", + service->url->host, service->url->port, + strerror(errno)); + if (fd > -1) + close (fd); + return FALSE; + } + + store->ostream = camel_stream_fs_new_with_fd (fd); + store->istream = camel_stream_buffer_new (store->ostream, + CAMEL_STREAM_BUFFER_READ); + + /* Read the greeting */ + buf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (store->istream)); + if (!buf) { + return -1; + } + + g_free (buf); + + /* get a list of extensions that the server supports */ + if (CAMEL_NNTP_OK == camel_nntp_command (store, NULL, "LIST EXTENSIONS")) { + char *ext_response = camel_nntp_command_get_additional_data(store); + + g_free (ext_response); + } + + return TRUE; +} + +static gboolean +nntp_store_disconnect (CamelService *service, CamelException *ex) +{ + CamelNNTPStore *store = CAMEL_NNTP_STORE (service); + + if (!service->connected) + return TRUE; + + camel_nntp_command (store, NULL, "QUIT"); + + if (store->newsrc) + camel_nntp_newsrc_write (store->newsrc); + + if (!service_class->disconnect (service, ex)) + return FALSE; + + gtk_object_unref (GTK_OBJECT (store->ostream)); + gtk_object_unref (GTK_OBJECT (store->istream)); + store->ostream = NULL; + store->istream = NULL; + return TRUE; +} + +static char * +nntp_store_get_name (CamelService *service, gboolean brief) +{ + /* Same info for long and brief... */ + return g_strdup_printf ("USENET news via %s", service->url->host); +} static CamelFolder * nntp_store_get_folder (CamelStore *store, const gchar *folder_name, @@ -68,7 +158,8 @@ nntp_store_get_folder (CamelStore *store, const gchar *folder_name, /* if we haven't already read our .newsrc, read it now */ if (!nntp_store->newsrc) - nntp_store->newsrc = camel_nntp_newsrc_read_for_server (CAMEL_SERVICE(store)->url->host); + nntp_store->newsrc = + camel_nntp_newsrc_read_for_server (CAMEL_SERVICE(store)->url->host); /* check if folder has already been created */ /* call the standard routine for that when */ @@ -83,11 +174,10 @@ nntp_store_get_folder (CamelStore *store, const gchar *folder_name, */ CF_CLASS (new_folder)->init (new_folder, store, NULL, folder_name, ".", FALSE, ex); - + return new_folder; } - static char * nntp_store_get_folder_name (CamelStore *store, const char *folder_name, CamelException *ex) @@ -95,23 +185,31 @@ nntp_store_get_folder_name (CamelStore *store, const char *folder_name, return g_strdup (folder_name); } -static char * -nntp_store_get_name (CamelService *service, gboolean brief) +static void +finalize (GtkObject *object) { - /* Same info for long and brief... */ - return g_strdup_printf ("USENET news via %s", service->url->host); -} + CamelException ex; + camel_exception_init (&ex); + nntp_store_disconnect (CAMEL_SERVICE (object), &ex); + camel_exception_clear (&ex); +} static void camel_nntp_store_class_init (CamelNNTPStoreClass *camel_nntp_store_class) { + GtkObjectClass *object_class = + GTK_OBJECT_CLASS (camel_nntp_store_class); CamelStoreClass *camel_store_class = CAMEL_STORE_CLASS (camel_nntp_store_class); CamelServiceClass *camel_service_class = CAMEL_SERVICE_CLASS (camel_nntp_store_class); service_class = gtk_type_class (camel_service_get_type ()); /* virtual method overload */ + object_class->finalize = finalize; + + camel_service_class->connect = nntp_store_connect; + camel_service_class->disconnect = nntp_store_disconnect; camel_service_class->get_name = nntp_store_get_name; camel_store_class->get_folder = nntp_store_get_folder; @@ -152,107 +250,6 @@ camel_nntp_store_get_type (void) return camel_nntp_store_type; } -/** - * camel_nntp_store_open: Connect to the server if we are currently - * disconnected. - * @store: the store - * @ex: a CamelException - * - **/ -void -camel_nntp_store_open (CamelNNTPStore *store, CamelException *ex) -{ - CamelService *service = CAMEL_SERVICE (store); - if (!camel_service_is_connected (service)) - nntp_connect (service, ex); -} - -/** - * camel_nntp_store_close: Close the connection to the server - * @store: the store - * @ex: a CamelException - * - **/ -void -camel_nntp_store_close (CamelNNTPStore *store, gboolean expunge, - CamelException *ex) -{ - camel_nntp_command (store, NULL, "QUIT"); - - nntp_disconnect (CAMEL_SERVICE (store), ex); -} - -static gboolean -nntp_connect (CamelService *service, CamelException *ex) -{ - struct hostent *h; - struct sockaddr_in sin; - int fd; - char *buf; - CamelNNTPStore *store = CAMEL_NNTP_STORE (service); - - if (!service_class->connect (service, ex)) - return FALSE; - - h = camel_service_gethost (service, ex); - if (!h) - return FALSE; - - sin.sin_family = h->h_addrtype; - sin.sin_port = htons (service->url->port ? service->url->port : NNTP_PORT); - memcpy (&sin.sin_addr, h->h_addr, sizeof (sin.sin_addr)); - - fd = socket (h->h_addrtype, SOCK_STREAM, 0); - if (fd == -1 || - connect (fd, (struct sockaddr *)&sin, sizeof(sin)) == -1) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not connect to %s (port %s): %s", - service->url->host, service->url->port, - strerror(errno)); - if (fd > -1) - close (fd); - return FALSE; - } - - store->ostream = camel_stream_fs_new_with_fd (fd); - store->istream = camel_stream_buffer_new (store->ostream, - CAMEL_STREAM_BUFFER_READ); - - /* Read the greeting */ - buf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (store->istream)); - if (!buf) { - return -1; - } - - g_free (buf); - - /* get a list of extensions that the server supports */ - if (CAMEL_NNTP_OK == camel_nntp_command (store, NULL, "LIST EXTENSIONS")) { - char *ext_response = camel_nntp_command_get_additional_data(store); - - g_free (ext_response); - } - - return TRUE; -} - -static gboolean -nntp_disconnect (CamelService *service, CamelException *ex) -{ - CamelNNTPStore *store = CAMEL_NNTP_STORE (service); - - if (!service->connected) - return TRUE; - - if (!service_class->disconnect (service, ex)) - return FALSE; - - gtk_object_unref (GTK_OBJECT (store->ostream)); - gtk_object_unref (GTK_OBJECT (store->istream)); - store->ostream = NULL; - store->istream = NULL; - return TRUE; -} /** * camel_nntp_command: Send a command to a NNTP server. @@ -291,7 +288,7 @@ camel_nntp_command (CamelNNTPStore *store, char **ret, char *fmt, ...) /* make sure we're connected */ if (store->ostream == NULL) - nntp_connect (CAMEL_SERVICE (store), ex); + nntp_store_connect (CAMEL_SERVICE (store), ex); if (camel_exception_get_id (ex)) { camel_exception_free (ex); @@ -479,18 +476,42 @@ gchar * camel_nntp_store_get_toplevel_dir (CamelNNTPStore *store) { CamelURL *url = CAMEL_SERVICE (store)->url; - char *news_dir; char *top_dir; + extern char *evolution_dir; g_assert(url != NULL); - news_dir = gnome_util_prepend_user_home ("evolution/news"); - - top_dir = g_strdup_printf( "%s/%s", - news_dir, + top_dir = g_strdup_printf( "%s/news/%s", + evolution_dir, url->host ); - g_free (news_dir); - return top_dir; } + +static gboolean +ensure_news_dir_exists (CamelNNTPStore *store) +{ + gchar *dir = camel_nntp_store_get_toplevel_dir (store); + struct stat sb; + int rv; + + rv = stat (dir, &sb); + if (-1 == rv && errno != ENOENT) { + g_free (dir); + return FALSE; + } + + if (S_ISDIR (sb.st_mode)) { + g_free (dir); + return TRUE; + } + else { + rv = mkdir (dir, 0777); + g_free (dir); + + if (-1 == rv) + return FALSE; + else + return TRUE; + } +} |