aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
authorChris Toshok <toshok@helixcode.com>2000-10-10 08:50:46 +0800
committerChris Toshok <toshok@src.gnome.org>2000-10-10 08:50:46 +0800
commit66cce2a4b4a0dacb1dbc998ad9f0a4226623c5c5 (patch)
tree2383950c89e3fdc28ed2a407d2a2df01f0ecb83f /camel
parent1febeef6becb09f0b6838e3e6850fb7d1e538396 (diff)
downloadgsoc2013-evolution-66cce2a4b4a0dacb1dbc998ad9f0a4226623c5c5.tar
gsoc2013-evolution-66cce2a4b4a0dacb1dbc998ad9f0a4226623c5c5.tar.gz
gsoc2013-evolution-66cce2a4b4a0dacb1dbc998ad9f0a4226623c5c5.tar.bz2
gsoc2013-evolution-66cce2a4b4a0dacb1dbc998ad9f0a4226623c5c5.tar.lz
gsoc2013-evolution-66cce2a4b4a0dacb1dbc998ad9f0a4226623c5c5.tar.xz
gsoc2013-evolution-66cce2a4b4a0dacb1dbc998ad9f0a4226623c5c5.tar.zst
gsoc2013-evolution-66cce2a4b4a0dacb1dbc998ad9f0a4226623c5c5.zip
write out the newsrc. (nntp_store_get_name): if @brief, just return host.
2000-10-09 Chris Toshok <toshok@helixcode.com> * providers/nntp/camel-nntp-store.c (finalize): write out the newsrc. (nntp_store_get_name): if @brief, just return host. * providers/nntp/camel-nntp-newsrc.c: robustification and bug fixes. svn path=/trunk/; revision=5808
Diffstat (limited to 'camel')
-rw-r--r--camel/ChangeLog9
-rw-r--r--camel/providers/nntp/camel-nntp-newsrc.c124
-rw-r--r--camel/providers/nntp/camel-nntp-store.c19
3 files changed, 95 insertions, 57 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 286e92f3d7..6ab300c4b0 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,12 @@
+2000-10-09 Chris Toshok <toshok@helixcode.com>
+
+ * providers/nntp/camel-nntp-store.c (finalize): write out the
+ newsrc.
+ (nntp_store_get_name): if @brief, just return host.
+
+ * providers/nntp/camel-nntp-newsrc.c: robustification and bug
+ fixes.
+
2000-10-06 Jeffrey Stedfast <fejj@helixcode.com>
* camel-folder-summary.c (camel_summary_format_address): Decode
diff --git a/camel/providers/nntp/camel-nntp-newsrc.c b/camel/providers/nntp/camel-nntp-newsrc.c
index 5c92074000..9fa05fbe49 100644
--- a/camel/providers/nntp/camel-nntp-newsrc.c
+++ b/camel/providers/nntp/camel-nntp-newsrc.c
@@ -28,6 +28,7 @@
#include <glib.h>
#include <fcntl.h>
#include <unistd.h>
+#include <errno.h>
#include "camel-nntp-newsrc.h"
#include <camel/camel-folder-summary.h>
@@ -316,15 +317,12 @@ camel_nntp_newsrc_write_group_line(gpointer key, NewsrcGroup *group, struct news
CamelNNTPNewsrc *newsrc;
FILE *fp;
int i;
- int line_length = 0;
fp = newsrc_fp->fp;
newsrc = newsrc_fp->newsrc;
fprintf (fp, "%s%c", group->name, group->subscribed ? ':' : '!');
- line_length += strlen(group->name) + 1;
-
if (group->ranges->len == 1
&& g_array_index (group->ranges, ArticleRange, 0).low == 0
&& g_array_index (group->ranges, ArticleRange, 0).high == 0) {
@@ -338,7 +336,6 @@ camel_nntp_newsrc_write_group_line(gpointer key, NewsrcGroup *group, struct news
}
fprintf (fp, " ");
- line_length += 1;
for (i = 0; i < group->ranges->len; i ++) {
char range_buffer[100];
@@ -355,26 +352,7 @@ camel_nntp_newsrc_write_group_line(gpointer key, NewsrcGroup *group, struct news
if (i != group->ranges->len - 1)
strcat(range_buffer, ",");
- /* this constant (991) gives the same line breaking as faried's .newsrc file */
- if (line_length + strlen(range_buffer) > 991 /*XXX*/) {
- char range_buffer2[101];
- int num_to_print = 991 - line_length;
-
- strcpy(range_buffer2, range_buffer);
- range_buffer2[num_to_print] = '!';
- range_buffer2[num_to_print+1] = '\n';
- range_buffer2[num_to_print+2] = '\0';
-
- fprintf (fp, range_buffer2);
-
- fprintf (fp, range_buffer + num_to_print);
-
- line_length = strlen(range_buffer) - num_to_print;
- }
- else {
- fprintf (fp, range_buffer);
- line_length += strlen(range_buffer);
- }
+ fprintf (fp, range_buffer);
}
fprintf (fp, "\n");
@@ -420,7 +398,7 @@ camel_nntp_newsrc_write(CamelNNTPNewsrc *newsrc)
static void
camel_nntp_newsrc_parse_line(CamelNNTPNewsrc *newsrc, char *line)
{
- char *p, sep, *comma, *dash;
+ char *p, *comma, *dash;
gboolean is_subscribed;
NewsrcGroup *group;
@@ -437,15 +415,10 @@ camel_nntp_newsrc_parse_line(CamelNNTPNewsrc *newsrc, char *line)
return; /* bogus line. */
}
- sep = *p;
- *p = '\0';
+ *p++ = '\0';
group = camel_nntp_newsrc_group_add (newsrc, line, is_subscribed);
- *p = sep;
-
- p++;
-
do {
guint high, low;
@@ -477,38 +450,97 @@ camel_nntp_newsrc_parse_line(CamelNNTPNewsrc *newsrc, char *line)
} while(comma);
}
-#define MAX_LINE_LENGTH 1500
-#define BUFFER_LENGTH (20 * MAX_LINE_LENGTH)
+static char*
+get_line (char *buf, char **p)
+{
+ char *l;
+ char *line;
+
+ g_assert (*p == NULL || **p == '\n' || **p == '\0');
+
+ if (*p == NULL) {
+ *p = buf;
+
+ if (**p == '\0')
+ return NULL;
+ }
+ else {
+ if (**p == '\0')
+ return NULL;
+
+ (*p) ++;
+
+ /* if we just incremented to the end of the buffer, return NULL */
+ if (**p == '\0')
+ return NULL;
+ }
+
+ l = strchr (*p, '\n');
+ if (l) {
+ *l = '\0';
+ line = g_strdup (*p);
+ *l = '\n';
+ *p = l;
+ }
+ else {
+ /* we're at the last line (which isn't terminated by a \n, btw) */
+ line = g_strdup (*p);
+ (*p) += strlen (*p);
+ }
+
+ return line;
+}
CamelNNTPNewsrc *
camel_nntp_newsrc_read_for_server (const char *server)
{
- FILE *fp;
- char buf[BUFFER_LENGTH];
- char *filename = g_strdup_printf ("%s/.newsrc-%s", g_get_home_dir(), server);
+ int fd;
+ char buf[1024];
+ char *file_contents, *line, *p;
+ char *filename;
CamelNNTPNewsrc *newsrc;
+ int newsrc_len;
+ int len_read = 0;
+ struct stat sb;
+
+ filename = g_strdup_printf ("%s/.newsrc-%s", g_get_home_dir(), server);
newsrc = g_new0(CamelNNTPNewsrc, 1);
newsrc->filename = filename;
newsrc->groups = g_hash_table_new (g_str_hash, g_str_equal);
- if ((fp = fopen(filename, "r")) == NULL) {
+ if ((fd = open(filename, O_RDONLY)) == -1) {
g_warning ("~/.newsrc-%s not present.\n", server);
return newsrc;
}
- while (fgets(buf, MAX_LINE_LENGTH, fp) != NULL) {
- /* we silently ignore (and lose!) lines longer than 20 * 1500 chars.
- Too bad for them. */
- while(strlen(buf) < sizeof(buf)
- && buf[strlen(buf) - 2] == '!') {
- fgets(&buf[strlen(buf) - 2], MAX_LINE_LENGTH, fp);
- }
+ if (fstat (fd, &sb) == -1) {
+ g_warning ("failed fstat on ~/.newsrc-%s: %s\n", server, strerror(errno));
+ return newsrc;
+ }
+ newsrc_len = sb.st_size;
+
+ file_contents = g_malloc (newsrc_len + 1);
+
+ while (len_read < newsrc_len) {
+ int c = read (fd, buf, sizeof (buf));
- camel_nntp_newsrc_parse_line(newsrc, buf);
+ if (c == -1)
+ break;
+
+ memcpy (&file_contents[len_read], buf, c);
+ len_read += c;
}
+ file_contents [len_read] = 0;
- fclose(fp);
+ p = NULL;
+ while ((line = get_line (file_contents, &p))) {
+ camel_nntp_newsrc_parse_line(newsrc, line);
+ g_free (line);
+ }
+
+ close (fd);
+ g_free (file_contents);
return newsrc;
}
diff --git a/camel/providers/nntp/camel-nntp-store.c b/camel/providers/nntp/camel-nntp-store.c
index 7f0f09ec27..e814ac3ae3 100644
--- a/camel/providers/nntp/camel-nntp-store.c
+++ b/camel/providers/nntp/camel-nntp-store.c
@@ -122,8 +122,6 @@ camel_nntp_store_get_overview_fmt (CamelNNTPStore *store, CamelException *ex)
int i;
gboolean done = FALSE;
- g_print ("camel_nntp_store_get_overview_fmt\n");
-
status = camel_nntp_command (store, ex, NULL,
"LIST OVERVIEW.FMT");
@@ -281,8 +279,11 @@ nntp_store_disconnect (CamelService *service, CamelException *ex)
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);
+ if (brief)
+ return g_strdup_printf ("%s", service->url->host);
+ else
+ return g_strdup_printf ("USENET News via %s", service->url->host);
+
}
static CamelServiceAuthType password_authtype = {
@@ -477,13 +478,9 @@ nntp_store_unsubscribe_folder (CamelStore *store, const char *folder_name,
static void
finalize (CamelObject *object)
{
- /* Done for us now */
- /*CamelException ex;
- *
- *camel_exception_init (&ex);
- *nntp_store_disconnect (CAMEL_SERVICE (object), &ex);
- *camel_exception_clear (&ex);
- */
+ CamelNNTPStore *nntp_store = CAMEL_NNTP_STORE (object);
+ if (nntp_store->newsrc)
+ camel_nntp_newsrc_write (nntp_store->newsrc);
}
static void