The core use a separate thread for the transport subsystem calls, otherwise it would block the UI while waiting for data. More...
Classes | |
struct | core_data |
Structure to transfer data between core and UI threads. More... | |
struct | core_range |
Article range linked list element. More... | |
struct | core_groupstate |
Group description. More... | |
struct | core_article_header |
Article header fields supported by core. More... | |
struct | core_hierarchy_element |
Node in article hierarchy. More... | |
Macros | |
#define | MAIN_ERR_PREFIX "CORE: " |
Message prefix for CORE module. | |
#define | CORE_NEXUS_RETRIES 1U |
Number of retries for nexus operations. More... | |
#define | CORE_HEADER_LINE_LENGTH (size_t) 1024 |
Sufficient for any RFC 5536 conformant header line. More... | |
#define | CORE_CL_SECRET_FILE ".cancelsecret" |
#define | CORE_UAGENT_RAW 0 |
Do not parse for content in "User-Agent" header field. More... | |
#define | CORE_GET_EMPTY_STRING(p) |
#define | CORE_GET_ERROR_STRING(p) |
#define | core_anum_t nntp_anum_t |
Article number data type (value zero is always reserved) More... | |
#define | core_groupdesc nntp_groupdesc |
Group descriptor structure. More... | |
#define | core_grouplabel nntp_grouplabel |
Group label structure. More... | |
#define | CORE_ANUM_T_MAX NNTP_ANUM_T_MAX |
Article number limit. More... | |
#define | CORE_TIME_T_MAX ULONG_MAX |
Article number limit. | |
Typedefs | |
typedef unsigned long int | core_time_t |
Time in seconds since the epoche (in terms of POSIX.1) More... | |
Enumerations | |
enum | core_nexus_state { CORE_NEXUS_CLOSED, CORE_NEXUS_ESTABLISHED } |
enum | core_command { CORE_CMD_INVALID, CORE_CMD_GET_MOTD, CORE_CMD_GET_DISTRIB_PATS, CORE_CMD_GET_SUBSCRIPTIONS, CORE_CMD_RESET_GROUPSTATES, CORE_CMD_GET_GROUPLIST, CORE_CMD_GET_GROUPLABELS, CORE_CMD_GET_GROUPINFO, CORE_CMD_SET_GROUP, CORE_CMD_GET_OVERVIEW, CORE_CMD_GET_ARTICLE_BY_MID, CORE_CMD_GET_ARTICLE, CORE_CMD_GET_ARTICLE_HEADER, CORE_CMD_GET_ARTICLE_BODY, CORE_CMD_POST_ARTICLE, CORE_TERMINATE_NEXUS } |
enum | core_header_type { CORE_HT_UNSTRUCT, CORE_HT_STRUCT } |
enum | core_header_id { CORE_HDR_EOH, CORE_HDR_MSGID, CORE_HDR_GROUPS, CORE_HDR_FROM, CORE_HDR_SUBJECT, CORE_HDR_DATE, CORE_HDR_OPT, CORE_HDR_SUPERS, CORE_HDR_FUP2, CORE_HDR_REPLY2, CORE_HDR_UAGENT, CORE_HDR_ORG, CORE_HDR_REFS, CORE_HDR_DIST, CORE_HDR_MIME, CORE_HDR_CT, CORE_HDR_CTE, CORE_HDR_CD, CORE_HDR_X_NEWSR, CORE_HDR_X_MAILER, CORE_HDR_X_PAGENT, CORE_HDR_LINES } |
enum | core_hierarchy_action { CORE_HIERARCHY_INIT, CORE_HIERARCHY_GETROOT, CORE_HIERARCHY_ADD, CORE_HIERARCHY_ADD_OVER, CORE_HIERARCHY_UPDATE } |
Actions that the article hierarchy manager can handle. More... | |
Functions | |
const char ** | core_extract_groups (const char *body) |
Extract groups from 'Newsgroups' header field (exported for UI) More... | |
int | core_get_group_list (unsigned int cookie) |
Get list of available newsgroups (exported for UI) More... | |
int | core_get_group_labels (unsigned int cookie) |
Get list of newsgroup labels (exported for UI) More... | |
int | core_sort_group_list (void) |
Alphabetically sort group list (exported for UI) More... | |
int | core_subscribe_group (const char *name) |
Store group subscription (exported for UI) More... | |
int | core_unsubscribe_group (size_t *num, struct core_groupstate **list, size_t *index) |
Remove group from list (exported for UI) More... | |
int | core_reset_group_states (unsigned int cookie) |
Reset states of subscribed groups (exported for UI) More... | |
int | core_export_group_states (size_t num, struct core_groupstate *list) |
Store states of subscribed groups (exported for UI) More... | |
int | core_update_subscribed_group_states (size_t *num, struct core_groupstate **list, size_t *index) |
Get states of subscribed groups (exported for UI) More... | |
void | core_destroy_subscribed_group_states (size_t *num, struct core_groupstate **list) |
Destructor for subscribed group states (exported for UI) More... | |
int | core_get_subscribed_group_info (const size_t *num, struct core_groupstate **list, unsigned int cookie) |
Get information about subscribed groups (exported for UI) More... | |
void | core_destroy_subscribed_group_info (struct core_groupdesc **list) |
Destructor for subscribed group information (exported for UI) More... | |
int | core_set_group (const char *name, unsigned int cookie) |
Set current group (exported for UI) More... | |
int | core_get_motd (unsigned int cookie) |
Get message of the day (exported for UI) More... | |
int | core_get_distribution (const char **dist, const char **groups) |
Get distribution suggestions (exported for UI) More... | |
int | core_get_subscription_proposals (unsigned int cookie) |
Get subscription proposals (exported for UI) More... | |
int | core_get_overview (struct core_range *range, unsigned int cookie) |
Get article header overview (exported for UI) More... | |
int | core_get_article_by_mid (const char *mid, unsigned int cookie) |
Get complete article by Message-ID (exported for UI) More... | |
int | core_get_article (const core_anum_t *id, unsigned int cookie) |
Get complete article (exported for UI) More... | |
int | core_get_article_header (const core_anum_t *id, unsigned int cookie) |
Get article header (exported for UI) More... | |
int | core_get_article_body (const core_anum_t *id, unsigned int cookie) |
Get article body (exported for UI) More... | |
int | core_post_article (const char *article, unsigned int cookie) |
Post article (exported for UI) More... | |
int | core_check_already_read (struct core_groupstate *group, struct core_hierarchy_element *article) |
Check whether article was alread read (exported for UI) More... | |
void | core_mark_as_read (struct core_groupstate *group, core_anum_t article) |
Mark article as read (exported for UI) More... | |
void | core_mark_as_unread (struct core_groupstate *group, core_anum_t article) |
Mark article as unread (exported for UI) More... | |
const char * | core_convert_canonical_to_posix (const char *s, int rcr, int rlf) |
Convert from canonical (RFC 822) to local (POSIX) form. More... | |
const char * | core_convert_posix_to_canonical (const char *s) |
Convert from local (POSIX) to canonical (RFC 822) form. More... | |
int | core_hierarchy_manager (struct core_hierarchy_element **hier, enum core_hierarchy_action action, core_anum_t anum,...) |
Manage article hierarchy in memory (exported for UI) More... | |
void | core_create_hierarchy_from_overview (struct core_groupstate *group, struct core_range *range, const char *overview) |
Create article hierarchy from header overview (exported for UI) More... | |
const char * | core_entity_parser (const char *entity, size_t len, struct core_article_header **e_h, size_t *e_len) |
Parse header of MIME multipart entity (exported for UI) More... | |
void | core_destroy_entity_header (struct core_article_header **ehp) |
Destructor for MIME multipart entity header object (exported for UI) More... | |
const char * | core_get_homedir (void) |
Get home directory of user (exported for UI) More... | |
const char * | core_suggest_pathname (void) |
Suggest pathname to save something to a file (exported for UI) More... | |
const char * | core_get_datetime (int force_utc) |
Get current date and time in RFC 5322 format (exported for UI) More... | |
const char * | core_get_msgid (const char *fqdn) |
Get globally unique Message-ID (exported for UI) More... | |
const char * | core_get_cancel_key (unsigned int scheme, const char *msgid) |
Create Cancel-Key for Message-ID (exported for UI) More... | |
const char * | core_get_cancel_lock (unsigned int scheme, const char *mid) |
Create Cancel-Lock for Message-ID (exported for UI) More... | |
const char * | core_get_signature (unsigned int *warnings) |
Get signature for outgoing messages (exported for UI) More... | |
const char * | core_get_introduction (const char *ca, const char *ngl) |
Get introduction line for citation (exported for UI) More... | |
const char * | core_convert_pathname_to_locale (const char *pathname) |
Convert pathname to codeset of locale (exported for UI) More... | |
int | core_check_file_exist (const char *pathname) |
Check wheter file exists (exported for UI) More... | |
int | core_save_to_file (const char *pathname, const char *s) |
Save string to text file (exported for UI) More... | |
const char * | core_tmpfile_create (void) |
Create temporary file (exported for UI) More... | |
void | core_tmpfile_delete (const char *pathname) |
Delete temporary file (exported for UI) More... | |
void | core_disconnect (void) |
Close nexus (exported for UI) | |
void | core_mutex_lock (void) |
Lock mutex for data object (exported for UI) More... | |
void | core_mutex_unlock (void) |
Unlock mutex for data object (exported for UI) More... | |
int | core_check_thread_ui (void) |
Check whether code is running in UI thread (exported for UI) More... | |
void | core_free (void *p) |
Free an object allocated by core (exported for UI) More... | |
int | core_init (void) |
Initialize core (exported for UI) More... | |
void | core_exit (void) |
Shutdown core (exported for UI) More... | |
Variables | |
struct core_data | data |
Global data object (shared by all threads) | |
Control flags for header parser (for internal use only) | |
#define | CORE_CFLAG_COMMENT 0x01U |
#define | CORE_CFLAG_QSTRING 0x02U |
#define | CORE_CFLAG_EWORD 0x04U |
Group flag bits | |
#define | CORE_GROUP_FLAG_ASCII NNTP_GROUP_FLAG_ASCII |
Hierarchy elements flag bits | |
#define | CORE_HE_FLAG_OVER 1U |
Signature warnings | |
#define | CORE_SIG_FLAG_SEPARATOR 0x01U |
#define | CORE_SIG_FLAG_INVALID 0x02U |
#define | CORE_SIG_FLAG_NOTASCII 0x04U |
#define | CORE_SIG_FLAG_LENGTH 0x08U |
Algorithms for Cancel-Lock scheme | |
#define | CORE_CL_INVALID 0U |
#define | CORE_CL_SHA1 1U |
#define | CORE_CL_SHA256 2U |
The core use a separate thread for the transport subsystem calls, otherwise it would block the UI while waiting for data.
A nexus binds the core to a transport subsystem (like NNTP or UUCP).
Current limitations:
At least the following things must be (re)implemented for Unicode support at protocol level:
#define core_anum_t nntp_anum_t |
Article number data type (value zero is always reserved)
This renames the data type nntp_anum_t .
#define CORE_ANUM_T_MAX NNTP_ANUM_T_MAX |
Article number limit.
This renames the limit from the NNTP transport subsystem NNTP_ANUM_T_MAX .
ULONG_MAX
because many older compilers do not provide a larger data type and many older stdio implementations can't handle larger data types. This means on all platforms where unsigned
long
is 32 bit wide this value is limited to 2^32 - 1. #define CORE_CL_SECRET_FILE ".cancelsecret" |
#define CORE_GET_EMPTY_STRING | ( | p | ) |
#define CORE_GET_ERROR_STRING | ( | p | ) |
#define CORE_GROUP_FLAG_ASCII NNTP_GROUP_FLAG_ASCII |
#define core_groupdesc nntp_groupdesc |
Group descriptor structure.
This renames the structure nntp_groupdesc .
#define core_grouplabel nntp_grouplabel |
Group label structure.
This renames the structure nntp_grouplabel .
#define CORE_HE_FLAG_OVER 1U |
#define CORE_HEADER_LINE_LENGTH (size_t) 1024 |
#define CORE_NEXUS_RETRIES 1U |
#define CORE_SIG_FLAG_INVALID 0x02U |
#define CORE_SIG_FLAG_NOTASCII 0x04U |
#define CORE_SIG_FLAG_SEPARATOR 0x01U |
#define CORE_UAGENT_RAW 0 |
Do not parse for content in "User-Agent" header field.
Set this to nonzero if you want to see the comments in the GUI.
typedef unsigned long int core_time_t |
Time in seconds since the epoche (in terms of POSIX.1)
This is the core representation for POSIX time_t
which is usually signed and even allowed to be a floating point type (what we don't want for performance reasons). Old compilers don't support 64 bit integer data types, therefore we use the largest mandatory (in terms of C90) unsigned integer type available. This gives at least additional 68 years beyond 2038 until "end of time" is reached for the cost that we can't use timestamps before the POSIX epoche (at this time Usenet was not invented yet and therefore this causes no problems).
In the case Usenet would still exist at that time, the limit can be increased by redefining this to uint64_t
at the cost of losing compatibility to historical systems.
Actions that the article hierarchy manager can handle.
CORE_HIERARCHY_INIT must be the first action that is executed.
int core_check_already_read | ( | struct core_groupstate * | group, |
struct core_hierarchy_element * | article | ||
) |
Check whether article was alread read (exported for UI)
[in] | group | Group in which article resides |
[in] | article | Hierarchy element assigned to article |
Definition at line 4741 of file core.c.
References core_hierarchy_element::anum, core_anum_t, core_range::first, core_groupstate::info, core_range::last, and core_range::next.
int core_check_file_exist | ( | const char * | pathname | ) |
Check wheter file exists (exported for UI)
[in] | pathname | Pathname of file (UTF-8 encoded) |
Definition at line 6340 of file core.c.
References core_convert_pathname_to_locale(), and fu_check_file().
int core_check_thread_ui | ( | void | ) |
Check whether code is running in UI thread (exported for UI)
Definition at line 6596 of file core.c.
Referenced by ts_lock_ui(), and ts_unlock_ui().
const char* core_convert_canonical_to_posix | ( | const char * | s, |
int | rcr, | ||
int | rlf | ||
) |
Convert from canonical (RFC 822) to local (POSIX) form.
According to RFC 822 and RFC 2049 this function accepts plain text article content in canonical form and convert the CR+LF line breaks to local (POSIX, single LF) form. Single CR and LF characters are preserved by default (this can be overridden by rcr and rlf respectively).
[in] | s | String to convert |
[in] | rcr | Insert replacement character for single CR |
[in] | rlf | Insert replacement character for single LF |
Definition at line 4966 of file core.c.
References enc_convert_canonical_to_posix().
const char* core_convert_pathname_to_locale | ( | const char * | pathname | ) |
Convert pathname to codeset of locale (exported for UI)
[in] | pathname | Pathname to convert (UTF-8 encoded) |
On success the caller is responsible to free the memory allocated for the returned pathname.
LC_CTYPE
by the FILTER
module. The locale parsing code should be moved to the CORE
module.Definition at line 6249 of file core.c.
References filter_get_locale_ctype().
Referenced by core_check_file_exist(), and core_save_to_file().
const char* core_convert_posix_to_canonical | ( | const char * | s | ) |
Convert from local (POSIX) to canonical (RFC 822) form.
According to RFC 822 and RFC 2049 this function accepts plain text article content in local (POSIX) form and convert the single LF line breaks to canonical (CR+LF) form. Single CR characters are removed.
[in] | s | String to convert |
Definition at line 4986 of file core.c.
References enc_convert_posix_to_canonical().
void core_create_hierarchy_from_overview | ( | struct core_groupstate * | group, |
struct core_range * | range, | ||
const char * | overview | ||
) |
Create article hierarchy from header overview (exported for UI)
Parser for RFC 3977 conformant header overview data as provided by the function core_get_overview() .
[in,out] | group | Group in which articles reside |
[in] | range | Pointer to article number range |
[in] | overview | Pointer to article header overview data |
Definition at line 5116 of file core.c.
References core_anum_t, core_mutex_lock(), core_range::first, and nntp_get_over_newsgroups_index().
void core_destroy_entity_header | ( | struct core_article_header ** | ehp | ) |
void core_destroy_subscribed_group_info | ( | struct core_groupdesc ** | list | ) |
Destructor for subscribed group information (exported for UI)
[in,out] | list | Pointer to array of group descriptors |
This destructor is intended to destroy the object created by the function core_get_subscribed_group_info() .
If list is NULL
, the function do nothing.
void core_destroy_subscribed_group_states | ( | size_t * | num, |
struct core_groupstate ** | list | ||
) |
Destructor for subscribed group states (exported for UI)
[in] | num | Pointer to number of groups |
[in] | list | Pointer to array of group state structures |
This destructor is intended to destroy the object created by the function core_update_subscribed_group_states() .
If list is NULL
, the function do nothing.
Definition at line 3641 of file core.c.
References group_destroy_list().
const char* core_entity_parser | ( | const char * | entity, |
size_t | len, | ||
struct core_article_header ** | e_h, | ||
size_t * | e_len | ||
) |
Parse header of MIME multipart entity (exported for UI)
[in] | entity | Pointer to beginning of MIME multipart entity |
[in] | len | Length of MIME multipart entity |
[out] | e_h | Object with decoded header of MIME multipart entity |
[out] | e_len | Length of MIME multipart entity content |
On success the caller is responsible to free the memory allocated for the decoded header object. Use the function core_destroy_entity_header() to do this.
void core_exit | ( | void | ) |
Shutdown core (exported for UI)
Cancel the core thread and destroy the article hierarchy.
int core_export_group_states | ( | size_t | num, |
struct core_groupstate * | list | ||
) |
Store states of subscribed groups (exported for UI)
[in] | num | Pointer to number of groups |
[in] | list | Pointer to array of group information structures |
Definition at line 3555 of file core.c.
References group_set_list().
const char** core_extract_groups | ( | const char * | body | ) |
Extract groups from 'Newsgroups' header field (exported for UI)
[in] | body | Unfolded body of Newsgroups header field |
Because the parameter body is allowed to have arbitrary size, the result has arbitrary size too. The result array is terminated with a NULL
entry.
void core_free | ( | void * | p | ) |
Free an object allocated by core (exported for UI)
Use this function to release dynamic memory that was allocated by the core.
[in] | p | Pointer to object |
Release the memory for the object pointed to by p.
NULL
and no operation is performed in this case. Definition at line 6625 of file core.c.
Referenced by core_save_to_file().
int core_get_article | ( | const core_anum_t * | id, |
unsigned int | cookie | ||
) |
Get complete article (exported for UI)
[in] | id | Article number |
[in] | cookie | Callback cookie |
The core will fetch the article with number id from a server (currently always the default one from the configuration config ). After the operation was successfully started, the function returns (with the value 1). After the operation has completed, the core thread calls the function ui_wakeup() with cookie as parameter.
The UI can extract the result of the operation from the core_data object field core_data::result (0 on success, negative on error). On success the field core_data::data points to the buffer with the article. The field core_data::size contains the buffer size. If the server is available but doesn't contain the requested article, success is returned with a NULL
pointer and zero size.
The caller is responsible to free the memory allocated for the buffer.
Definition at line 4297 of file core.c.
References core_mutex_lock().
int core_get_article_body | ( | const core_anum_t * | id, |
unsigned int | cookie | ||
) |
Get article body (exported for UI)
[in] | id | Article number |
[in] | cookie | Callback cookie |
The core will fetch the article body with number id from a server (currently always the default one from the configuration config ). After the operation was successfully started, the function returns (with the value 1). After the operation has completed, the core thread calls the function ui_wakeup() with cookie as parameter.
The UI can extract the result of the operation from the core_data object field core_data::result (0 on success, negative on error). On success the field core_data::data points to the buffer with the article body. The field core_data::size contains the buffer size. If the server is available but doesn't contain the requested article, success is returned with a NULL
pointer and zero size.
The caller is responsible to free the memory allocated for the buffer.
Definition at line 4421 of file core.c.
References core_mutex_lock().
int core_get_article_by_mid | ( | const char * | mid, |
unsigned int | cookie | ||
) |
Get complete article by Message-ID (exported for UI)
[in] | mid | Message-ID (with angle brackets) |
[in] | cookie | Callback cookie |
The core will fetch the article with Message-ID mid from a server (currently always the default one from the configuration config ). After the operation was successfully started, the function returns (with the value 1). After the operation has completed, the core thread calls the function ui_wakeup() with cookie as parameter.
The UI can extract the result of the operation from the core_data object field core_data::result (0 on success, negative on error). On success the field core_data::data points to the buffer with the article. The field core_data::size contains the buffer size. If the server is available but doesn't contain the requested article, success is returned with a NULL
pointer and zero size.
The caller is responsible to free the memory allocated for the buffer.
Definition at line 4235 of file core.c.
References core_mutex_lock().
int core_get_article_header | ( | const core_anum_t * | id, |
unsigned int | cookie | ||
) |
Get article header (exported for UI)
[in] | id | Article number |
[in] | cookie | Callback cookie |
The core will fetch the article header with number id from a server (currently always the default one from the configuration config ). After the operation was successfully started, the function returns (with the value 1). After the operation has completed, the core thread calls the function ui_wakeup() with cookie as parameter.
The UI can extract the result of the operation from the core_data object field core_data::result (0 on success, negative on error). On success the field core_data::data points to the buffer with the article header. The field core_data::size contains the buffer size. If the server is available but doesn't contain the requested article, success is returned with a NULL
pointer and zero size.
The caller is responsible to free the memory allocated for the buffer.
Definition at line 4359 of file core.c.
References core_mutex_lock().
const char* core_get_cancel_key | ( | unsigned int | scheme, |
const char * | msgid | ||
) |
Create Cancel-Key for Message-ID (exported for UI)
[in] | scheme | Algorithm to use for "scheme" |
[in] | msgid | Message-ID of article that should correspond to Cancel-Key |
This function creates a c-key
element with with scheme and mid according to RFC 8315.
On success, the caller is responsible for releasing the memory allocated for the result.
c-key
element on successNULL
on error Definition at line 5763 of file core.c.
References CONF_CANCELKEY, config, CORE_CL_SECRET_FILE, CORE_CL_SHA1, CORE_CL_SHA256, enc_free(), enc_mime_encode_base64(), fu_close_file(), fu_create_path(), fu_open_file(), fu_read_from_filedesc(), hmac_sha1_160(), HMAC_SHA1_160_LEN, hmac_sha2_256(), HMAC_SHA2_256_LEN, main_debug, MAIN_ERR_PREFIX, PRINT_ERROR, conf_entry_val::s, secure_cl_secret(), secure_clear_memory(), conf::val, xdg_append_to_path(), and xdg_get_confdir().
Referenced by core_get_cancel_lock().
const char* core_get_cancel_lock | ( | unsigned int | scheme, |
const char * | mid | ||
) |
Create Cancel-Lock for Message-ID (exported for UI)
[in] | scheme | Algorithm to use for "scheme" |
[in] | mid | Message-ID of article that should correspond to Cancel-Lock |
This function creates a c-lock
element with with scheme and mid according to RFC 8315.
On success, the caller is responsible for releasing the memory allocated for the result.
c-lock
element on successNULL
on error Definition at line 5924 of file core.c.
References CORE_CL_SHA1, CORE_CL_SHA256, core_get_cancel_key(), digest_sha1_160(), DIGEST_SHA1_160_LEN, digest_sha2_256(), DIGEST_SHA2_256_LEN, enc_free(), enc_mime_encode_base64(), and PRINT_ERROR.
const char* core_get_datetime | ( | int | force_utc | ) |
Get current date and time in RFC 5322 format (exported for UI)
[in] | force_utc | Force usage of UTC time with unknown timezone |
RFC 5322 recommends but not require to use the local time. If the POSIX.1-2001 API is available and force_utc is set to zero, then local time is used. Otherwise the returned date is UTC and marked with the unknown timezone information -0000
defined by RFC 5322.
If timestamp_comment
option is enabled in configfile and force_utc is set to a nonzero value, a comment with the abbreviation of the timezone is appended (if the POSIX.1-2001 API or the X/Open XSI extension are provided by the operating system).
NULL
on error Definition at line 5485 of file core.c.
References CONF_TS_COMMENT, CONF_TS_LTIME, config, and PRINT_ERROR.
int core_get_distribution | ( | const char ** | dist, |
const char ** | groups | ||
) |
Get distribution suggestions (exported for UI)
[out] | dist | Suggested distribution for groups |
[in] | groups | Newsgroup list (NULL for empty list is allowed) |
The core will fetch distribution suggestions (if available) from a server (currently always the default one from the configuration config ) for groups . The result is the suggested content for the Distribution
header field.
On success, the caller is responsible to free the memory allocated for the buffer.
Definition at line 3885 of file core.c.
References CONF_DIST_SUGG, config, core_mutex_lock(), data, nntp_get_distrib_pats(), and PRINT_ERROR.
int core_get_group_labels | ( | unsigned int | cookie | ) |
Get list of newsgroup labels (exported for UI)
[in] | cookie | Callback cookie |
The core will fetch the list with newsgroup labels that are available on the server (always the default one from the configuration config ). After the operation was successfully started, the function returns (with the value 1). After the operation has completed, the core thread calls the function ui_wakeup() with cookie as parameter.
The UI can extract the result of the operation from the core_data object field core_data::result (0 on success, negative on error). On success the field core_data::data points to a buffer with the array of group label structures. The field core_data::size contains the number of groups in the array. If the server is available but doesn't contain groups, success is returned with a NULL
pointer and zero size.
The caller is responsible to free the memory allocated for the array and all of its elements.
Definition at line 3376 of file core.c.
References core_mutex_lock().
int core_get_group_list | ( | unsigned int | cookie | ) |
Get list of available newsgroups (exported for UI)
[in] | cookie | Callback cookie |
The core will fetch the list with all groups that are available on the server (always the default one from the configuration config ). After the operation was successfully started, the function returns (with the value 1). After the operation has completed, the core thread calls the function ui_wakeup() with cookie as parameter.
The UI can extract the result of the operation from the core_data object field core_data::result (0 on success, negative on error). On success the field core_data::data points to a buffer with the array of group descriptors. The field core_data::size contains the number of groups in the array. If the server is available but doesn't contain groups, success is returned with a NULL
pointer and zero size.
The caller is responsible to free the memory allocated for the array and all of its elements.
Definition at line 3317 of file core.c.
References core_mutex_lock().
const char* core_get_homedir | ( | void | ) |
Get home directory of user (exported for UI)
NULL
on error Definition at line 5377 of file core.c.
References fu_check_path(), and ts_getenv().
Referenced by core_suggest_pathname().
const char* core_get_introduction | ( | const char * | ca, |
const char * | ngl | ||
) |
Get introduction line for citation (exported for UI)
[in] | ca | Name of cited author |
[in] | ngl | Newsgroup list of the cited article |
The result of this function is an introduction line string without linebreak at the end. The format is taken from the configuration config .
NULL
on error Definition at line 6152 of file core.c.
References CONF_INTRO, config, MAIN_ERR_PREFIX, conf_entry_val::s, and conf::val.
int core_get_motd | ( | unsigned int | cookie | ) |
Get message of the day (exported for UI)
[in] | cookie | Callback cookie |
The core will fetch the message of the day from a server (currently always the default one from the configuration config ).
After the operation was successfully started, the function returns (with the value 1). After the operation has completed, the core thread calls the function ui_wakeup() with cookie as parameter.
The UI can extract the result of the operation from the core_data object field core_data::result (0 on success, negative on error). On success the field core_data::data points to the buffer with the message of the day. The field core_data::size contains the buffer size. If the server is available, but doesn't provide a message of the day, success is returned with a NULL
pointer and zero size.
The caller is responsible to free the memory allocated for the buffer.
const char* core_get_msgid | ( | const char * | fqdn | ) |
Get globally unique Message-ID (exported for UI)
[in] | fqdn | Fully qualified domain name without root domain |
dot-atom
syntax defined in RFC 5322 to be usable as id-right
element of a Message-ID.According to RFC 5536 the following rules are applied:
id-right
element should be a domain => We use FQDN w/o root domain.Description of Message-ID format created by algorithm A3:
date
random_pid
. A3
. program
@ fqdn
The date field contains a modified base64 encoded POSIX timestamp (seconds since epoche) with 48bits.
The random and pid fields are combined into a modified base64 encoded value with 48bits. The first 16bits are random, they are added to deal with real world clocks that are often not synchronized with UTC and don't always run monotonic. They also make the Message-ID unpredictable as recommended by RFC 5536. The last 32bits are the 32 LSBs of the process identifier (PID). The function getpid()
is used for this purpose. Both parts are combined to one value to make the length an integral multiple of octet triplets that can be base64 encoded without padding.
The modified base64 encoding uses the base64 alphabet with /
(slash) replaced by -
(minus).
The Ax field represents the algorithm used to create the message ID. If the algorithm is modified in the future, the number x should be incremented.
The program field contains the value of the variable CFG_NAME
from the configuration file.
The fqdn field is taken from the parameter fqdn and is checked for valid dot-atom
syntax according to RFC 5322.
NULL
on error Definition at line 5629 of file core.c.
References enc_free(), enc_mime_encode_base64(), main_debug, MAIN_ERR_PREFIX, and PRINT_ERROR.
int core_get_overview | ( | struct core_range * | range, |
unsigned int | cookie | ||
) |
Get article header overview (exported for UI)
[in] | range | Pointer to article number range |
[in] | cookie | Callback cookie |
The core will fetch the article headers of range range from a server (currently always the default one from the configuration config ).
After the operation was successfully started, the function returns (with the value 1). After the operation has completed, the core thread calls the function ui_wakeup() with cookie as parameter.
The UI can extract the result of the operation from the core_data object field core_data::result (0 on success, negative on error). On success the field core_data::data points to the buffer with the article headers. The field core_data::size contains the buffer size. If the server is available but doesn't contain the requested articles, success is returned with a NULL
pointer and zero size.
The caller is responsible to free the memory allocated for the buffer.
const char* core_get_signature | ( | unsigned int * | warnings | ) |
Get signature for outgoing messages (exported for UI)
[out] | warnings | Pointer to location for result warning flags |
Use the CORE_SIG_FLAG_xxx
constants to decode warnings .
NULL
for warnings if the caller is not interested in this data.NULL
on error (nothing was written to warnings ) Definition at line 6034 of file core.c.
References CONF_SIGFILE, config, CORE_SIG_FLAG_INVALID, CORE_SIG_FLAG_LENGTH, CORE_SIG_FLAG_NOTASCII, CORE_SIG_FLAG_SEPARATOR, enc_ascii_check(), enc_uc_check_utf8(), fu_check_file(), fu_check_path(), fu_close_file(), fu_open_file(), fu_read_whole_file(), PRINT_ERROR, conf_entry_val::s, ts_getenv(), and conf::val.
int core_get_subscribed_group_info | ( | const size_t * | num, |
struct core_groupstate ** | list, | ||
unsigned int | cookie | ||
) |
Get information about subscribed groups (exported for UI)
[in] | num | Pointer to number of groups in list |
[in] | list | Pointer to array of state structures |
[in] | cookie | Callback cookie |
NULL
in this case.The core will collect the information for the groups listed in list from the server (always the default one from the configuration config ). After the operation was successfully started, the function returns (with the value 1). After the operation has completed, the core thread calls the function ui_wakeup() with cookie as parameter.
The UI can extract the result of the operation from the core_data object field core_data::result (0 on success, negative on error). On success the field core_data::data points to an array of group descriptors with num entries (or is NULL
for an empty group list).
The caller is responsible to free the memory allocated for the information object. The destructor function core_destroy_subscribed_group_info() should be used for this purpose.
Definition at line 3685 of file core.c.
References core_mutex_lock().
int core_get_subscription_proposals | ( | unsigned int | cookie | ) |
Get subscription proposals (exported for UI)
[in] | cookie | Callback cookie |
The core will fetch the subscription proposals from a server (currently always the default one from the configuration config ).
After the operation was successfully started, the function returns (with the value 1). After the operation has completed, the core thread calls the function ui_wakeup() with cookie as parameter.
The UI can extract the result of the operation from the core_data object field core_data::result (0 on success, negative on error). On success the field core_data::data points to the buffer with the newsgroup list. The field core_data::size contains the buffer size. If the server is available, but doesn't provide a message of the day, success is returned with a NULL
pointer and zero size.
The caller is responsible to free the memory allocated for the buffer.
int core_hierarchy_manager | ( | struct core_hierarchy_element ** | hier, |
enum core_hierarchy_action | action, | ||
core_anum_t | anum, | ||
... | |||
) |
Manage article hierarchy in memory (exported for UI)
[in,out] | hier | Pointer to article hierarchy pointer |
[in] | action | What should be done |
[in] | anum | Article number |
To use the default article hierarchy, hier shall be set to NULL
.
The core provides a facility to create a hierarchy from articles that contain the header field "References". The UI can use it as follows:
First the hierarchy must be initialized with the action CORE_HIERARCHY_INIT (this automatically destroys the old hierarchy if one exist). All other parameters are ignored.
At any time after initialization, the root node of the current hierarchy can be read with the action CORE_HIERARCHY_GETROOT . anum must be zero and as additional parameter the address of a buffer must be supplied to which the root node is written on success. The data type must be core_hierarchy_element **
.
After an article header was fetched from the server, it can be added to the hierarchy with the action CORE_HIERARCHY_ADD . anum should be set to the number that the server has assigned to the article and, as additional parameter, a pointer to the raw article header must be provided. The data type must be const
char
*
. The hierarchy manager will parse the article header, check it and extract all relevant information from it. With this information an article header object is created that is part of the hierarchy element object together with the article number, the parent and child article pointers.
The action CORE_HIERARCHY_ADD_OVER does the same, except that a flag is stored into the new node that indicates the incomplete data. This action is intended to add NNTP overview data.
The resulting hierarchy is a tree object that the UI can display without detailed knowledge of the article header format.
In some cases the data in the hierarchy elements is incomplete, e.g. if the hierarchy was created from NNTP overview data. It is possible to recreate single hierarchy elements with additional data in place, e.g. after the complete article was downloaded later. To update an existing hierarchy element, the action must be set to CORE_HIERARCHY_UPDATE . The parameters are the same as for CORE_HIERARCHY_ADD .
int core_init | ( | void | ) |
void core_mark_as_read | ( | struct core_groupstate * | group, |
core_anum_t | article | ||
) |
Mark article as read (exported for UI)
[in,out] | group | Group in which article resides |
[in] | article | Article number |
Definition at line 4766 of file core.c.
References core_anum_t, core_range::first, group_article_range_constructor(), core_groupstate::info, core_range::last, core_groupstate::name, and core_range::next.
void core_mark_as_unread | ( | struct core_groupstate * | group, |
core_anum_t | article | ||
) |
Mark article as unread (exported for UI)
[in,out] | group | Group in which article resides |
[in] | article | Article number |
Definition at line 4871 of file core.c.
References core_anum_t, core_range::first, group_article_range_constructor(), group_article_range_destructor(), core_groupstate::info, core_range::last, core_groupstate::name, and core_range::next.
void core_mutex_lock | ( | void | ) |
Lock mutex for data object (exported for UI)
You need to own the mutex before every access to the global object data to synchronize the threads.
Definition at line 6562 of file core.c.
Referenced by core_create_hierarchy_from_overview(), core_get_article(), core_get_article_body(), core_get_article_by_mid(), core_get_article_header(), core_get_distribution(), core_get_group_labels(), core_get_group_list(), core_get_subscribed_group_info(), core_reset_group_states(), and core_set_group().
void core_mutex_unlock | ( | void | ) |
int core_post_article | ( | const char * | article, |
unsigned int | cookie | ||
) |
Post article (exported for UI)
[in] | article | Pointer to Unicode article in RFC 5536 canonical form |
[in] | cookie | Callback cookie |
This function will check whether the article contains non-ASCII characters. If this is the case in the header, the article is rejected (this is forbidden by RFC 5536).
If the body contains non-ASCII characters, the body is converted to ISO 8859 if possible (this is recommended by RFC 2046, can be disabled with the force_unicode
option in configfile). Two fields are appended to the header indicating a transfer encoding of 8bit
and a content type of text/plain
. For the content type, a parameter for the actual character set is appended. A second parameter is appended that indicates fixed
format (according to RFC 3676).
If injection via external inews is configured, the result is never 1 and success (or error) derived from the exit status is returned immediately. The parameter cookie is not used in this case.
Otherwise the core will post the article pointed to by article to the server (currently always the default one from the configuration config ). After the operation was successfully started, the function returns (with the value 1). After the operation has completed, the core thread calls the function ui_wakeup() with cookie as parameter.
The UI can extract the result of the operation from the core_data object field core_data::result (0 on success, negative on error).
Definition at line 4495 of file core.c.
References CONF_FORCE_UNICODE, config, enc_ascii_check(), enc_convert_to_8bit(), enc_convert_to_utf8_nfc(), ENC_CS_UTF_8, enc_free(), and PRINT_ERROR.
int core_reset_group_states | ( | unsigned int | cookie | ) |
Reset states of subscribed groups (exported for UI)
[in] | cookie | Callback cookie |
Closes the current server nexus and delete all group states. This function must be called after the server has been changed and the mapping from Message-IDs to article numbers is no longer valid. After the operation was successfully started, the function returns (with the value 1). After the operation has completed, the core thread calls the function ui_wakeup() with cookie as parameter.
The UI can extract the result of the operation from the core_data object field core_data::result (0 on success, negative on error).
Definition at line 3512 of file core.c.
References core_mutex_lock().
int core_save_to_file | ( | const char * | pathname, |
const char * | s | ||
) |
Save string to text file (exported for UI)
[in] | pathname | Pathname of file (UTF-8 encoded) |
[in] | s | String to convert |
If the file pathname does not exist, it is created.
Definition at line 6370 of file core.c.
References core_convert_pathname_to_locale(), core_free(), fu_assign_stream(), fu_close_file(), and fu_open_file().
int core_set_group | ( | const char * | name, |
unsigned int | cookie | ||
) |
Set current group (exported for UI)
[in] | name | Group name |
[in] | cookie | Callback cookie |
The core will configure the server (always the default one from the configuration config ) to the current group name . After the operation was successfully started, the function returns (with the value 1). After the operation has completed, the core thread calls the function ui_wakeup() with cookie as parameter.
The UI can extract the result of the operation from the core_data object field core_data::result (0 on success, negative on error). On success the field core_data::data points to the buffer with the group descriptor. The field core_data::size is set to one.
The caller is responsible to free the memory allocated for the buffer.
Definition at line 3763 of file core.c.
References core_mutex_lock().
int core_sort_group_list | ( | void | ) |
Alphabetically sort group list (exported for UI)
Definition at line 3416 of file core.c.
References group_sort_list().
int core_subscribe_group | ( | const char * | name | ) |
Store group subscription (exported for UI)
[in] | name | Group name to add |
Definition at line 3436 of file core.c.
References enc_ascii_check(), group_add(), core_groupstate::info, core_groupstate::name, and PRINT_ERROR.
const char* core_suggest_pathname | ( | void | ) |
Suggest pathname to save something to a file (exported for UI)
Intended as suggestion for "save as" file selection dialogs.
This implementation uses the program name and the date to create the filename. The users home directory is used as path.
NULL
on error Definition at line 5411 of file core.c.
References core_get_homedir(), and PRINT_ERROR.
const char* core_tmpfile_create | ( | void | ) |
Create temporary file (exported for UI)
On success the caller is responsible to free the memory allocated for the returned pathname. Use the function core_tmpfile_delete() to delete the file and free the memory block allocated for the pathname.
$TMPDIR
for the directory. If not set, /tmp
is used instead.void core_tmpfile_delete | ( | const char * | pathname | ) |
Delete temporary file (exported for UI)
[in] | pathname | Pathname of file to delete |
Definition at line 6530 of file core.c.
References fu_unlink_file().
int core_unsubscribe_group | ( | size_t * | num, |
struct core_groupstate ** | list, | ||
size_t * | index | ||
) |
Remove group from list (exported for UI)
[in,out] | num | Pointer to number of groups in list |
[in,out] | list | Pointer to array of group state structures |
[in] | index | Index of group to unsubscribe in list |
Definition at line 3468 of file core.c.
References group_article_range_destructor(), core_groupstate::info, and core_groupstate::name.
int core_update_subscribed_group_states | ( | size_t * | num, |
struct core_groupstate ** | list, | ||
size_t * | index | ||
) |
Get states of subscribed groups (exported for UI)
The states which articles where already read are taken from the groupfile. The last viewed articles of the groups are preserved. The index is updated to match the new group list.
[in,out] | num | Pointer to number of groups in list |
[in,out] | list | Pointer to array of group state structures |
[in,out] | index | Pointer to index of current group in list |
The caller is responsible to free the memory allocated for the information object. The destructor function core_destroy_subscribed_group_states() should be used for this purpose.
Definition at line 3581 of file core.c.
References group_destroy_list(), group_get_list(), core_groupstate::last_viewed, and core_groupstate::name.