-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nntp.c
154 lines (124 loc) · 2.64 KB
/
nntp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* Copyright (c) 2016 Richard Russon <rich@flatcap.org>
* Released under the GPLv3 -- see LICENSE.md for details */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "email.h"
#include "folder.h"
#include "nntp.h"
#include "plugin.h"
#include "source.h"
#include "view.h"
void
nntp_destroy (NNTP *n)
{
if (!n) {
return;
}
// Nothing NNTP-specific to release
source_destroy (&n->source); // Destroy parent
}
NNTP *
nntp_create (NNTP *n)
{
if (!n) {
n = calloc (1, sizeof (NNTP));
if (!n) {
return NULL;
}
}
source_create (&n->source); // Construct parent
OBJECT *o = &n->source.container.object;
o->type = MAGIC_NNTP;
o->name = strdup ("nntp");
o->destroy = (object_destroy_fn) nntp_destroy;
return n;
}
static SOURCE *
nntp_init (void)
{
NNTP *ns = nntp_create (NULL);
if (!ns) {
return NULL;
}
return &ns->source;
}
static int
nntp_config_item (const char *name)
{
if (!name) {
return 0;
}
if ((name[0] >= 'a') && (name[0] <= 'e')) {
// printf ("nntp config: %s\n", name);
return 1;
}
return 0;
}
static void
nntp_connect (SOURCE *s)
{
FOLDER *f1 = folder_create (NULL);
FOLDER *f2 = folder_create (NULL);
FOLDER *f3 = folder_create (NULL);
if (!f1 || !f2 || !f3) {
printf ("nntp_connect: folder_create failed\n");
return;
}
f1->container.object.name = strdup ("alt.swedish.chef");
f2->container.object.name = strdup ("rec.arts.poems");
f3->container.object.name = strdup ("sci.fractals");
EMAIL *e1 = email_create (NULL);
EMAIL *e2 = email_create (NULL);
EMAIL *e3 = email_create (NULL);
EMAIL *e4 = email_create (NULL);
EMAIL *e5 = email_create (NULL);
EMAIL *e6 = email_create (NULL);
EMAIL *e7 = email_create (NULL);
if (!e1 || !e2 || !e3 || !e4 || !e5 || !e6 || !e7) {
printf ("nntp_connect: email_create failed\n");
return;
}
e1->item.object.name = strdup ("bork");
e2->item.object.name = strdup ("bork");
e3->item.object.name = strdup ("bork");
e4->item.object.name = strdup ("daffodils");
e5->item.object.name = strdup ("elegy");
e6->item.object.name = strdup ("mandelbrot");
e7->item.object.name = strdup ("siepinski");
add_child (f1, e1);
add_child (f1, e2);
add_child (f1, e3);
add_child (f2, e4);
add_child (f2, e5);
add_child (f3, e6);
add_child (f3, e7);
release (e1);
release (e2);
release (e3);
release (e4);
release (e5);
release (e6);
release (e7);
add_child (s, f1);
add_child (s, f2);
add_child (s, f3);
release (f1);
release (f2);
release (f3);
}
static void
nntp_disconnect (SOURCE *src)
{
if (!src) {
return;
}
}
PLUGIN nntp_plugin = {
MAGIC_NNTP,
"nntp",
nntp_init,
nntp_config_item,
nntp_connect,
nntp_disconnect
};