1
0
mirror of https://github.com/rkd77/elinks.git synced 2025-01-03 14:57:44 -05:00
elinks/src/protocol/nntp/nntp.c

74 lines
1.8 KiB
C
Raw Normal View History

/* Network news transport protocol implementation (RFC 977 and 2980) */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "elinks.h"
#include "config/options.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "protocol/nntp/nntp.h"
/* The official color for this planet is green,
* which grows in pockets of them people willing to scheme. --delasoul */
#define NNTP_HEADER_ENTRIES "Subject,From,Date,Message-ID,Newsgroups"
/* Module and option stuff: */
enum nntp_protocol_option {
NNTP_PROTOCOL_TREE,
NNTP_PROTOCOL_SERVER,
NNTP_PROTOCOL_HEADER_ENTRIES,
NNTP_PROTOCOL_OPTIONS,
};
bug 764: Initialize the right member of union option_value INIT_OPTION used to initialize union option_value at compile time by casting the default value to LIST_OF(struct option) *, which is the type of the first member. On sparc64 and other big-endian systems where sizeof(int) < sizeof(struct list_head *), this tended to leave option->value.number as zero, thus messing up OPT_INT and OPT_BOOL at least. OPT_LONG however tended to work right. This would be easy to fix with C99 designated initializers, but doc/hacking.txt says ELinks must be kept C89 compatible. Another solution would be to make register_options() read the value from option->value.tree (the first member), cast it back to the right type, and write it to the appropriate member; but that would still require somewhat dubious conversions between integers, data pointers, and function pointers. So here's a rather more invasive solution. Add struct option_init, which is somewhat similar to struct option but has non-overlapping members for different types of values, to ensure nothing is lost in compile-time conversions. Move unsigned char *path from struct option_info to struct option_init, and replace struct option_info with a union that contains struct option_init and struct option. Now, this union can be initialized with no portability problems, and register_options() then moves the values from struct option_init to their final places in struct option. In my x86 ELinks build with plenty of options configured in, this change bloated the text section by 340 bytes but compressed the data section by 2784 bytes, presumably because union option_info is a pointer smaller than struct option_info was. (cherry picked from elinks-0.12 commit e5f6592ee20780a61f70feeb1f9e17631b9c5835) Conflicts: src/protocol/fsp/fsp.c: All options had been removed in 0.13.GIT. src/protocol/smb/smb2.c: Ditto.
2009-08-15 15:39:07 -04:00
static union option_info nntp_protocol_options[] = {
INIT_OPT_TREE("protocol", N_("NNTP"),
2022-01-15 14:10:37 -05:00
"nntp", OPT_ZERO,
N_("NNTP and news specific options.")),
INIT_OPT_STRING("protocol.nntp", N_("Default news server"),
2022-01-15 14:10:37 -05:00
"server", OPT_ZERO, "",
N_("Used when resolving news: URIs. "
"If set to the empty string the value of the NNTPSERVER "
"environment variable will be used.")),
INIT_OPT_STRING("protocol.nntp", N_("Message header entries"),
2022-01-15 14:10:37 -05:00
"header_entries", OPT_ZERO, NNTP_HEADER_ENTRIES,
N_("Comma separated list of which entries in the article "
"header to show. E.g. 'Subject' and 'From'. "
"All header entries can be read in the header info dialog.")),
NULL_OPTION_INFO,
};
#define get_opt_nntp(which) nntp_protocol_options[(which)].option
char *
get_nntp_server(void)
{
return get_opt_nntp(NNTP_PROTOCOL_SERVER).value.string;
}
char *
get_nntp_header_entries(void)
{
return get_opt_nntp(NNTP_PROTOCOL_HEADER_ENTRIES).value.string;
}
struct module nntp_protocol_module = struct_module(
/* name: */ N_("NNTP"),
/* options: */ nntp_protocol_options,
/* hooks: */ NULL,
/* submodules: */ NULL,
/* data: */ NULL,
/* init: */ NULL,
/* done: */ NULL
);