core.h
1 #ifndef CORE_H
2 #define CORE_H 1
3 
4 
5 /* ========================================================================== */
6 /* Include files */
7 
8 #include <sys/types.h>
9 #include <limits.h>
10 #include "nntp.h"
11 
12 
13 /*! \addtogroup CORE */
14 /*! @{ */
15 
16 
17 /* ========================================================================== */
18 /* Data types */
19 
20 /*! \brief Article number data type (value zero is always reserved)
21  *
22  * This renames the data type \ref nntp_anum_t .
23  */
24 #define core_anum_t nntp_anum_t
25 
26 /*! \brief Group descriptor structure
27  *
28  * This renames the structure \ref nntp_groupdesc .
29  */
30 #define core_groupdesc nntp_groupdesc
31 
32 /*! \brief Group label structure
33  *
34  * This renames the structure \ref nntp_grouplabel .
35  */
36 #define core_grouplabel nntp_grouplabel
37 
38 /*! \brief Time in seconds since the epoche (in terms of POSIX.1)
39  *
40  * This is the core representation for POSIX \c time_t which is usually signed
41  * and even allowed to be a floating point type (what we don't want for
42  * performance reasons).
43  * Old compilers don't support 64 bit integer data types, therefore we use the
44  * largest mandatory (in terms of C90) unsigned integer type available.
45  * This gives at least additional 68 years beyond 2038 until "end of time" is
46  * reached for the cost that we can't use timestamps before the POSIX epoche
47  * (at this time Usenet was not invented yet and therefore this causes no
48  * problems).
49  *
50  * In the case Usenet would still exist at that time, the limit can be
51  * increased by redefining this to \c uint64_t at the cost of losing
52  * compatibility to historical systems.
53  */
54 typedef unsigned long int core_time_t;
55 
56 /*! \brief Structure to transfer data between core and UI threads
57  *
58  * This structure is moved between the UI and the core threads. Before every
59  * access to it, a mutex must be locked with \ref core_mutex_lock() .
60  *
61  * After a command was completed that was delegated to the core thread, the core
62  * calls \ref ui_wakeup() and the UI uses the \ref cookie field of this
63  * structure to queue the corresponding callback for the command.
64  */
65 struct core_data
66 {
67  unsigned int cookie; /*!< UI callback cookie */
68  int result; /*!< Result (zero on success, negative on error) */
69  size_t size; /*!< Size of data */
70  void* data; /*!< Pointer to data */
71 };
72 
73 /*! \brief Article range linked list element */
74 struct core_range
75 {
76  core_anum_t first; /*!< First article in range */
77  core_anum_t last; /*!< Last article in range */
78  struct core_range* next; /*!< Pointer to next range in list */
79 };
80 
81 /*! \brief Group description */
83 {
84  const char* name; /*!< Group name */
85  struct core_range* info; /*!< Linked list of read article ranges */
86  core_anum_t last_viewed; /*!< Last viewed article */
87 };
88 
89 /*! \brief Article header fields supported by core
90  *
91  * All fields marked with [M] are mandatory for Usenet article headers.
92  * All fields marked with [U] are MIME decoded to UTF-8 and normalized to NFC.
93  *
94  * All fields are initialized by the header object constructor. All mandatory
95  * fields are always initialized with content (even if the article header is
96  * invalid), all optional fields with NULL (if there is no such field in the
97  * article header).
98  *
99  * The field \ref date is a numerical value, not a string.
100  * The fields \ref groups and \ref refs point to NULL terminated arrays of
101  * strings.
102  */
103 /*
104  * If you add or remove fields, don't forget to modify the constructor and
105  * destructor functions for the header object accordingly.
106  */
108 {
109  const char* msgid; /*!< [M] Message ID of the article */
110  const char** groups; /*!< [M] Groups the article is posted to */
111  const char* from; /*!< [M][U] Sender of the article */
112  const char* subject; /*!< [M][U] Subject of the article */
113  core_time_t date; /*!< [M] POSIX timestamp (seconds since epoch) */
114  const char* supers; /*!< Supersedes article with this Message ID */
115  const char* fup2; /*!< Follow up to this group */
116  const char* reply2; /*!< [U] Recipient of replies instead of sender */
117  const char* uagent; /*!< [U] Client program which created article */
118  const char* org; /*!< [U] Organization of sender */
119  const char** refs; /*!< List with references */
120  const char* dist; /*!< Distribution */
121  const char* mime_v; /*!< MIME version */
122  const char* mime_ct; /*!< MIME content type */
123  const char* mime_cte; /*!< MIME content transfer encoding */
124  const char* mime_cd; /*!< MIME content disposition */
125  const char* x_newsr; /*!< [U] Nonstandard equivalent to 'uagent' */
126  const char* x_mailer; /*!< [U] Nonstandard equivalent to 'uagent' */
127  const char* x_pagent; /*!< [U] Nonstandard equivalent to 'uagent' */
128  /* The following fields are marked obsolete by RFC 5536 */
129  unsigned long int lines; /*!< Number of lines in body */
130 };
131 
132 /*! \brief Node in article hierarchy
133  *
134  * The array pointed to by the \ref child field has \ref children entries.
135  */
137 {
138  /*! Article number (only valid for the current server) */
140  /*! Flags (use \c CORE_HE_FLAG_xxx constants) */
141  unsigned int flags;
142  /*! Pointer to article header */
144  /*! Pointer to parent article */
146  /*! Number of child articles in array \ref child */
147  size_t children;
148  /*! Pointer to array of pointers to child articles */
150 };
151 
152 /*! \brief Actions that the article hierarchy manager can handle
153  *
154  * \ref CORE_HIERARCHY_INIT must be the first action that is executed.
155  */
157 {
158  CORE_HIERARCHY_INIT, /*!< Delete hierarchy and create a new empty one */
159  CORE_HIERARCHY_GETROOT, /*!< Get root node of article hierarchy */
160  CORE_HIERARCHY_ADD, /*!< Add article to hierarchy */
161  CORE_HIERARCHY_ADD_OVER, /*!< Add incomplete data (overview) to hierarchy */
162  CORE_HIERARCHY_UPDATE /*!< Update element of hierarchy */
163 };
164 
165 
166 /* ========================================================================== */
167 /* Constants */
168 
169 /*! \brief Article number limit
170  *
171  * This renames the limit from the NNTP transport subsystem
172  * \ref NNTP_ANUM_T_MAX .
173  *
174  * \attention
175  * This value must always be smaller or equal to \c ULONG_MAX because many older
176  * compilers do not provide a larger data type and many older stdio
177  * implementations can't handle larger data types. This means on all platforms
178  * where \c unsigned \c long is 32 bit wide this value is limited to 2^32 - 1.
179  */
180 #define CORE_ANUM_T_MAX NNTP_ANUM_T_MAX
181 
182 /*! \brief Article number limit */
183 #define CORE_TIME_T_MAX ULONG_MAX
184 
185 /*! \name Group flag bits */
186 /*! @{ */
187 /*! Name contains only ASCII characters */
188 #define CORE_GROUP_FLAG_ASCII NNTP_GROUP_FLAG_ASCII
189 /*! @} */
190 
191 /*! \name Hierarchy elements flag bits */
192 /*! @{ */
193 /*! Node contains incomplete data from NNTP overview */
194 #define CORE_HE_FLAG_OVER 1U
195 /*! @} */
196 
197 /*! \name Signature warnings */
198 /*! @{ */
199 #define CORE_SIG_FLAG_SEPARATOR 0x01U /*!< Separator "-- " is missing */
200 #define CORE_SIG_FLAG_INVALID 0x02U /*!< Character set is not UTF-8 */
201 #define CORE_SIG_FLAG_NOTASCII 0x04U /*!< Character set is not US-ASCII */
202 #define CORE_SIG_FLAG_LENGTH 0x08U /*!< Length is too large */
203 /*! @} */
204 
205 /*! \name Algorithms for Cancel-Lock scheme */
206 /*! @{ */
207 #define CORE_CL_INVALID 0U /*!< Invalid scheme */
208 #define CORE_CL_SHA1 1U /*!< SHA1 */
209 #define CORE_CL_SHA256 2U /*!< SHA2-256 */
210 /*! @} */
211 
212 
213 /*! @} */
214 
215 
216 /* ========================================================================== */
217 /* Variables */
218 
219 extern struct core_data data;
220 
221 
222 /* ========================================================================== */
223 /* Function prototypes */
224 
225 const char** core_extract_groups(const char*);
226 int core_get_group_list(unsigned int);
227 int core_get_group_labels(unsigned int);
228 int core_sort_group_list(void);
229 int core_subscribe_group(const char*);
230 int core_unsubscribe_group(size_t*, struct core_groupstate**, size_t*);
231 int core_reset_group_states(unsigned int);
232 int core_export_group_states(size_t, struct core_groupstate*);
234  size_t*);
236 int core_get_subscribed_group_info(const size_t*, struct core_groupstate**,
237  unsigned int);
239 int core_set_group(const char*, unsigned int);
240 int core_get_motd(unsigned int);
241 int core_get_distribution(const char**, const char**);
242 int core_get_subscription_proposals(unsigned int);
243 int core_get_overview(struct core_range*, unsigned int);
244 int core_get_article_by_mid(const char*, unsigned int);
245 int core_get_article(const core_anum_t*, unsigned int);
246 int core_get_article_header(const core_anum_t*, unsigned int);
247 int core_get_article_body(const core_anum_t*, unsigned int);
248 int core_post_article(const char*, unsigned int);
250  struct core_hierarchy_element*);
253 const char* core_convert_canonical_to_posix(const char*, int, int);
254 const char* core_convert_posix_to_canonical(const char*);
258  struct core_range*,
259  const char*);
260 const char* core_entity_parser(const char*, size_t,
261  struct core_article_header**, size_t*);
263 const char* core_get_homedir(void);
264 const char* core_suggest_pathname(void);
265 const char* core_get_datetime(int);
266 const char* core_get_msgid(const char*);
267 const char* core_get_cancel_key(unsigned int, const char*);
268 const char* core_get_cancel_lock(unsigned int, const char*);
269 const char* core_get_signature(unsigned int*);
270 const char* core_get_introduction(const char*, const char*);
271 const char* core_convert_pathname_to_locale(const char*);
272 int core_check_file_exist(const char*);
273 int core_save_to_file(const char*, const char*);
274 const char* core_tmpfile_create(void);
275 void core_tmpfile_delete(const char*);
276 void core_disconnect(void);
277 void core_mutex_lock(void);
278 void core_mutex_unlock(void);
279 int core_check_thread_ui(void);
280 void core_free(void*);
281 int core_init(void);
282 void core_exit(void);
283 
284 
285 #endif /* CORE_H */
286 
287 /* EOF */
core_mutex_lock
void core_mutex_lock(void)
Lock mutex for data object (exported for UI)
Definition: core.c:6562
core_hierarchy_element::header
struct core_article_header * header
Definition: core.h:143
core_suggest_pathname
const char * core_suggest_pathname(void)
Suggest pathname to save something to a file (exported for UI)
Definition: core.c:5411
core_export_group_states
int core_export_group_states(size_t, struct core_groupstate *)
Store states of subscribed groups (exported for UI)
Definition: core.c:3555
core_groupdesc
#define core_groupdesc
Group descriptor structure.
Definition: core.h:30
core_create_hierarchy_from_overview
void core_create_hierarchy_from_overview(struct core_groupstate *, struct core_range *, const char *)
Create article hierarchy from header overview (exported for UI)
Definition: core.c:5116
core_convert_pathname_to_locale
const char * core_convert_pathname_to_locale(const char *)
Convert pathname to codeset of locale (exported for UI)
Definition: core.c:6249
core_convert_canonical_to_posix
const char * core_convert_canonical_to_posix(const char *, int, int)
Convert from canonical (RFC 822) to local (POSIX) form.
Definition: core.c:4966
core_get_group_list
int core_get_group_list(unsigned int)
Get list of available newsgroups (exported for UI)
Definition: core.c:3317
core_data::result
int result
Definition: core.h:68
core_data::size
size_t size
Definition: core.h:69
core_hierarchy_action
core_hierarchy_action
Actions that the article hierarchy manager can handle.
Definition: core.h:156
core_range::next
struct core_range * next
Definition: core.h:78
core_anum_t
#define core_anum_t
Article number data type (value zero is always reserved)
Definition: core.h:24
CORE_HIERARCHY_GETROOT
Definition: core.h:159
core_convert_posix_to_canonical
const char * core_convert_posix_to_canonical(const char *)
Convert from local (POSIX) to canonical (RFC 822) form.
Definition: core.c:4986
core_time_t
unsigned long int core_time_t
Time in seconds since the epoche (in terms of POSIX.1)
Definition: core.h:54
core_get_subscription_proposals
int core_get_subscription_proposals(unsigned int)
Get subscription proposals (exported for UI)
Definition: core.c:4103
CORE_HIERARCHY_ADD
Definition: core.h:160
core_hierarchy_element::children
size_t children
Definition: core.h:147
core_get_homedir
const char * core_get_homedir(void)
Get home directory of user (exported for UI)
Definition: core.c:5377
core_hierarchy_element::child
struct core_hierarchy_element ** child
Definition: core.h:149
core_range
Article range linked list element.
Definition: core.h:74
core_reset_group_states
int core_reset_group_states(unsigned int)
Reset states of subscribed groups (exported for UI)
Definition: core.c:3512
core_groupstate
Group description.
Definition: core.h:82
core_article_header::reply2
const char * reply2
Definition: core.h:116
core_get_distribution
int core_get_distribution(const char **, const char **)
Get distribution suggestions (exported for UI)
Definition: core.c:3885
core_hierarchy_manager
int core_hierarchy_manager(struct core_hierarchy_element **, enum core_hierarchy_action, core_anum_t,...)
Manage article hierarchy in memory (exported for UI)
Definition: core.c:5049
core_article_header::mime_ct
const char * mime_ct
Definition: core.h:122
core_unsubscribe_group
int core_unsubscribe_group(size_t *, struct core_groupstate **, size_t *)
Remove group from list (exported for UI)
Definition: core.c:3468
core_free
void core_free(void *)
Free an object allocated by core (exported for UI)
Definition: core.c:6625
core_article_header::dist
const char * dist
Definition: core.h:120
core_get_cancel_lock
const char * core_get_cancel_lock(unsigned int, const char *)
Create Cancel-Lock for Message-ID (exported for UI)
Definition: core.c:5924
core_mark_as_read
void core_mark_as_read(struct core_groupstate *, core_anum_t)
Mark article as read (exported for UI)
Definition: core.c:4766
core_post_article
int core_post_article(const char *, unsigned int)
Post article (exported for UI)
Definition: core.c:4495
core_article_header::subject
const char * subject
Definition: core.h:112
core_init
int core_init(void)
Initialize core (exported for UI)
Definition: core.c:6641
core_article_header::uagent
const char * uagent
Definition: core.h:117
core_exit
void core_exit(void)
Shutdown core (exported for UI)
Definition: core.c:6699
core_check_thread_ui
int core_check_thread_ui(void)
Check whether code is running in UI thread (exported for UI)
Definition: core.c:6596
core_hierarchy_element::anum
core_anum_t anum
Definition: core.h:139
core_range::first
core_anum_t first
Definition: core.h:76
core_get_subscribed_group_info
int core_get_subscribed_group_info(const size_t *, struct core_groupstate **, unsigned int)
Get information about subscribed groups (exported for UI)
Definition: core.c:3685
core_article_header::groups
const char ** groups
Definition: core.h:110
core_tmpfile_delete
void core_tmpfile_delete(const char *)
Delete temporary file (exported for UI)
Definition: core.c:6530
core_sort_group_list
int core_sort_group_list(void)
Alphabetically sort group list (exported for UI)
Definition: core.c:3416
core_get_motd
int core_get_motd(unsigned int)
Get message of the day (exported for UI)
Definition: core.c:3822
core_subscribe_group
int core_subscribe_group(const char *)
Store group subscription (exported for UI)
Definition: core.c:3436
core_mutex_unlock
void core_mutex_unlock(void)
Unlock mutex for data object (exported for UI)
Definition: core.c:6578
core_get_group_labels
int core_get_group_labels(unsigned int)
Get list of newsgroup labels (exported for UI)
Definition: core.c:3376
core_article_header::from
const char * from
Definition: core.h:111
core_article_header::mime_cte
const char * mime_cte
Definition: core.h:123
core_hierarchy_element::parent
struct core_hierarchy_element * parent
Definition: core.h:145
CORE_HIERARCHY_INIT
Definition: core.h:158
core_get_msgid
const char * core_get_msgid(const char *)
Get globally unique Message-ID (exported for UI)
Definition: core.c:5629
core_destroy_subscribed_group_info
void core_destroy_subscribed_group_info(struct core_groupdesc **)
Destructor for subscribed group information (exported for UI)
Definition: core.c:3732
core_article_header::x_mailer
const char * x_mailer
Definition: core.h:126
core_destroy_subscribed_group_states
void core_destroy_subscribed_group_states(size_t *, struct core_groupstate **)
Destructor for subscribed group states (exported for UI)
Definition: core.c:3641
core_article_header::refs
const char ** refs
Definition: core.h:119
core_article_header::org
const char * org
Definition: core.h:118
core_check_file_exist
int core_check_file_exist(const char *)
Check wheter file exists (exported for UI)
Definition: core.c:6340
core_article_header
Article header fields supported by core.
Definition: core.h:107
core_groupstate::name
const char * name
Definition: core.h:84
CORE_HIERARCHY_ADD_OVER
Definition: core.h:161
core_hierarchy_element
Node in article hierarchy.
Definition: core.h:136
core_mark_as_unread
void core_mark_as_unread(struct core_groupstate *, core_anum_t)
Mark article as unread (exported for UI)
Definition: core.c:4871
core_article_header::supers
const char * supers
Definition: core.h:114
data
struct core_data data
Global data object (shared by all threads)
Definition: core.c:242
core_data::cookie
unsigned int cookie
Definition: core.h:67
core_get_datetime
const char * core_get_datetime(int)
Get current date and time in RFC 5322 format (exported for UI)
Definition: core.c:5485
core_article_header::x_newsr
const char * x_newsr
Definition: core.h:125
core_article_header::mime_v
const char * mime_v
Definition: core.h:121
core_destroy_entity_header
void core_destroy_entity_header(struct core_article_header **)
Destructor for MIME multipart entity header object (exported for UI)
Definition: core.c:5359
core_get_article_body
int core_get_article_body(const core_anum_t *, unsigned int)
Get article body (exported for UI)
Definition: core.c:4421
core_article_header::mime_cd
const char * mime_cd
Definition: core.h:124
core_hierarchy_element::flags
unsigned int flags
Definition: core.h:141
core_get_cancel_key
const char * core_get_cancel_key(unsigned int, const char *)
Create Cancel-Key for Message-ID (exported for UI)
Definition: core.c:5763
core_article_header::fup2
const char * fup2
Definition: core.h:115
CORE_HIERARCHY_UPDATE
Definition: core.h:162
core_get_article_by_mid
int core_get_article_by_mid(const char *, unsigned int)
Get complete article by Message-ID (exported for UI)
Definition: core.c:4235
core_article_header::date
core_time_t date
Definition: core.h:113
core_range::last
core_anum_t last
Definition: core.h:77
core_check_already_read
int core_check_already_read(struct core_groupstate *, struct core_hierarchy_element *)
Check whether article was alread read (exported for UI)
Definition: core.c:4741
core_get_signature
const char * core_get_signature(unsigned int *)
Get signature for outgoing messages (exported for UI)
Definition: core.c:6034
core_data::data
void * data
Definition: core.h:70
core_tmpfile_create
const char * core_tmpfile_create(void)
Create temporary file (exported for UI)
Definition: core.c:6415
core_article_header::lines
unsigned long int lines
Definition: core.h:129
core_get_overview
int core_get_overview(struct core_range *, unsigned int)
Get article header overview (exported for UI)
Definition: core.c:4166
core_get_article_header
int core_get_article_header(const core_anum_t *, unsigned int)
Get article header (exported for UI)
Definition: core.c:4359
core_update_subscribed_group_states
int core_update_subscribed_group_states(size_t *, struct core_groupstate **, size_t *)
Get states of subscribed groups (exported for UI)
Definition: core.c:3581
core_extract_groups
const char ** core_extract_groups(const char *)
Extract groups from 'Newsgroups' header field (exported for UI)
Definition: core.c:3284
core_disconnect
void core_disconnect(void)
Close nexus (exported for UI)
Definition: core.c:6543
core_article_header::x_pagent
const char * x_pagent
Definition: core.h:127
core_groupstate::info
struct core_range * info
Definition: core.h:85
core_get_article
int core_get_article(const core_anum_t *, unsigned int)
Get complete article (exported for UI)
Definition: core.c:4297
core_entity_parser
const char * core_entity_parser(const char *, size_t, struct core_article_header **, size_t *)
Parse header of MIME multipart entity (exported for UI)
Definition: core.c:5295
core_save_to_file
int core_save_to_file(const char *, const char *)
Save string to text file (exported for UI)
Definition: core.c:6370
core_data
Structure to transfer data between core and UI threads.
Definition: core.h:65
core_groupstate::last_viewed
core_anum_t last_viewed
Definition: core.h:86
core_article_header::msgid
const char * msgid
Definition: core.h:109
core_get_introduction
const char * core_get_introduction(const char *, const char *)
Get introduction line for citation (exported for UI)
Definition: core.c:6152
core_set_group
int core_set_group(const char *, unsigned int)
Set current group (exported for UI)
Definition: core.c:3763

Generated at 2024-04-27 using  doxygen