1LIBINN(3)                  Library Functions Manual                  LIBINN(3)
2
3
4

NAME

6       libinn - InterNetNews library routines
7

SYNOPSIS

9       #include "inn/libinn.h"
10
11       char *
12       GenerateMessageID(domain)
13           char    *domain;
14
15       void
16       HeaderCleanFrom(from)
17           char             *from;
18
19       FILE *
20       CAopen(FromServer, ToServer)
21           FILE             *FromServer;
22           FILE             *ToServer;
23
24       FILE *
25       CAlistopen(FromServer, ToServer, request)
26           FILE             *FromServer;
27           FILE             *ToServer;
28           char             *request;
29
30       void
31       CAclose()
32
33       struct _DDHANDLE *
34       DDstart(FromServer, ToServer)
35           FILE             *FromServer;
36           FILE             *ToServer;
37
38       void
39       DDcheck(h, group)
40           DDHANDLE         *h;
41           char             *group;
42
43       char *
44       DDend(h)
45           DDHANDLE         *h;
46
47       void
48       fdflag_close_exec(fd, flag)
49           int              fd;
50           bool             flag;
51
52       int
53       fdflag_nonblocking(fd, flag)
54           socket_type      fd;
55           bool             flag;
56
57       bool
58       inn_lock_file(fd, type, flag)
59           int              fd;
60           LOCKTYPE         type;
61           bool             block;
62
63       char *
64       inn_getfqdn(domain)
65           const char *domain;
66
67       char *
68       GetModeratorAddress(FromServer, ToServer, group, moderatormailer)
69           FILE             *FromServer;
70           FILE             *ToServer;
71           char             *group;
72           char             *moderatormailer;
73
74       int
75       GetResourceUsage(usertime, systime)
76           double           *usertime;
77           double           *systime;
78
79       int
80       NNTPlocalopen(FromServerp, ToServerp, errbuff, len)
81           FILE             **FromServerp;
82           FILE             **ToServerp;
83           char             *errbuff;
84           size_t  len;
85
86       int
87       NNTPremoteopen(port, FromServerp, ToServerp, errbuff, len)
88           int              port;
89           FILE             **FromServerp;
90           FILE             **ToServerp;
91           char             *errbuff;
92           size_t  len;
93
94       int
95       NNTPconnect(host, port, FromServerp, ToServerp, errbuff, len)
96           char             *host;
97           int              port;
98           FILE             **FromServerp;
99           FILE             **ToServerp;
100           char             *errbuff;
101           size_t  len;
102
103       int
104       NNTPsendarticle(text, ToServer, Terminate)
105           char             *text;
106           FILE             *ToServer;
107           int              Terminate;
108
109       int
110       NNTPsendpassword(server, FromServer, ToServer)
111           char             *server;
112           FILE             *FromServer;
113           FILE             *ToServer;
114
115       void
116       Radix32(value, p)
117           unsigned long    value;
118           char             *p;
119
120       char *
121       ReadInFile(name, Sbp)
122           char             *name;
123           struct stat      *Sbp;
124
125       char *
126       ReadInDescriptor(fd, Sbp)
127           int              fd;
128           struct stat      *Sbp;
129
130       HASH
131       HashMessageID(MessageID)
132           const char *MessageID;
133

DESCRIPTION

135       Libinn  is  a library of utility routines for manipulating Usenet arti‐
136       cles and related data.
137
138       GenerateMessageID uses the current time, process-ID, and  fully  quali‐
139       fied domain name, which is passed as an argument and used if local host
140       can not be resolved or it is different from ``domain'' set in inn.conf,
141       to  create a Message-ID header that is highly likely to be unique.  The
142       returned value points to static space  that  is  reused  on  subsequent
143       calls.
144
145       HeaderCleanFrom  removes the extraneous information from the value of a
146       ``From'' or ``Reply-To'' header and leaves just  the  official  mailing
147       address.   In particular, the following transformations are made to the
148       from parameter:
149              address          -->  address
150              address (stuff)  -->  address
151              stuff <address>  -->  address
152       The transformations are simple, based on RFC 5536 which limits the for‐
153       mat of the header.
154
155       CAopen and CAclose provide news clients with access to the active file;
156       the ``CA'' stands for Client Active.  CAopen opens the active file  for
157       reading.  It returns a pointer to an open FILE, or NULL on error.  If a
158       local or NFS-mounted copy exists, CAopen will use that file.  The From‐
159       Server  and  ToServer parameters should be FILE's connected to the NNTP
160       server for input and output, respectively.  See NNTPremoteopen or  NNT‐
161       Plocalopen,  below.  If either parameter is NULL, then CAopen will just
162       return NULL if the file is not locally  available.   If  they  are  not
163       NULL,  CAopen will use them to query the NNTP server using the ``list''
164       command to make a local temporary copy.
165
166       The CAlistopen sends a ``list'' command to the  server  and  returns  a
167       temporary  file  containing the results.  The request parameter, if not
168       NULL, will be sent as an argument to the command.  Unlike CAopen,  this
169       routine will never use a locally-available copy of the active file.
170
171       CAclose  closes  the  active  file  and removes any temporary file that
172       might have been created by CAopen or CAlistopen.
173
174       fdflag_close_exec can make a descriptor ``close-on-exec'' so that it is
175       not shared with any child processes.  If the flag is non-zero, the file
176       is so marked; if zero, the ``close-on-exec'' mode is cleared.
177
178       DDstart, DDcheck, and DDend are used to set  the  Distribution  header;
179       the  ``DD''  stands for Default Distribution.  The distrib.pats file is
180       consulted to determine the proper value  for  the  Distribution  header
181       after  all  newsgroups  have been checked.  DDstart begins the parsing.
182       It returns a pointer to an opaque handle that should be used on  subse‐
183       quent  calls.   The FromServer and ToServer parameters should be FILE's
184       connected to the NNTP server for input and  output,  respectively.   If
185       either  parameter  is  NULL,  then  an empty default will ultimately be
186       returned if the file is not locally available.
187
188       DDcheck should be called with the handle, h, returned by DDstart and  a
189       newgroups, group, to check.  It can be called as often as necessary.
190
191       DDend  releases any state maintained in the handle and returns an allo‐
192       cated copy of the text that should be used for the Distribution header.
193
194       fdflag_nonblocking enables (if flag is non-zero) or disables  (if  flag
195       is  zero)  non-blocking I/O on the indicated descriptor.  It returns -1
196       on failure or zero on success.
197
198       inn_lock_file tries to lock the file descriptor fd.  If block  is  true
199       it  will  block  until  the  lock can be made, otherwise it will return
200       false if the file cannot be locked.  type  is  one  of:  INN_LOCK_READ,
201       INN_LOCK_WRITE,  or  INN_LOCK_UNLOCK.   It  returns false on failure or
202       true on success.
203
204       inn_getfqdn returns the fully qualified domain name of the local  host.
205       Domain  is used to qualify the local host name if local host can not be
206       resolved in DNS.  The returned value points to  newly-allocated  memory
207       that the caller is responsible for freeing, or NULL on error.
208
209       GetModeratorAddress  returns  the  mailing address of the moderator for
210       specified group or NULL on  error.   Moderatormailer  is  used  as  its
211       address,  if  there  is  no  matched  moderator.  See moderators(5) for
212       details on how the address is determined.  GetModeratorAddress does  no
213       checking  to  see  if  the  specified group is actually moderated.  The
214       returned value points to static space  that  is  reused  on  subsequent
215       calls.   The  FromServer  and ToServer parameters should be FILE's con‐
216       nected to the NNTP server  for  input  and  output,  respectively.   If
217       either  of  these  parameters  is NULL, then an attempt to get the list
218       from a local copy is made.
219
220       GetResourceUsage fills in the usertime and systime parameters with  the
221       total user and system time used by the current process and any children
222       it may  have  spawned.   If  <HAVE_GETRUSAGE  in  include/config.h>  is
223       defined, it gets the values by doing a getrusage(2) system call; other‐
224       wise it calls times(2).  It returns -1 on failure, or zero on success.
225
226       NNTPlocalopen opens a connection to the private port of an InterNetNews
227       server  running  on  the  local  host,  if <HAVE_UNIX_DOMAIN_SOCKETS in
228       include/config.h> is defined.  It returns -1 on  failure,  or  zero  on
229       success.  FromServerp and ToServerp will be filled in with FILE's which
230       can be used to communicate with the server.  Errbuff can either be NULL
231       or a pointer to a buffer at least 512 bytes long.  If not NULL, and the
232       server refuses the connection, then it will be filled in with the  text
233       of  the  server's reply.  Len should be the length of the buffer.  This
234       routine is  not  for  general  use.   If  <HAVE_UNIX_DOMAIN_SOCKETS  in
235       include/config.h>  is not defined, this is a stub routine, for compati‐
236       bility with systems that have Unix-domain stream  sockets.   It  always
237       returns -1.
238
239       NNTPremoteopen does the same except that it uses ``innconf->server'' as
240       the local server, and opens a connection to the port.  Any client  pro‐
241       gram  can  use this routine.  It returns -1 on failure, or zero on suc‐
242       cess.
243
244       NNTPconnect is the same as NNTPremoteopen except that the desired  host
245       is given as the host parameter.
246
247       NNTPsendarticle writes text on ToServer using NNTP conventions for line
248       termination.  The text should consist of one or more lines ending  with
249       a  newline.  If Terminate is non-zero, then the routine will also write
250       the NNTP data-termination marker on the stream.  It returns -1 on fail‐
251       ure, or zero on success.
252
253       NNTPsendpassword  sends authentication information to an NNTP server by
254       finding the appropriate entry in the passwd.nntp file.  Server contains
255       the  name  of  the  host; ``innconf->server'' will be used if server is
256       NULL.  FromServer and ToServer should be FILE's that are  connected  to
257       the  server.  No action is taken if the specified host is not listed in
258       the password file.
259
260       Radix32 converts the number in value into a radix-32  string  into  the
261       buffer  pointed  to by p.  The number is split into five-bit pieces and
262       each pieces is converted into a character using the  alphabet  0..9a..v
263       to  represent  the numbers 0..32.  Only the lowest 32 bits of value are
264       used, so p need only point to a buffer of eight bytes (seven characters
265       and the trailing \0).
266
267       ReadInFile reads the file named name into allocated memory, appending a
268       terminating \0 byte.  It returns a pointer to the  space,  or  NULL  on
269       error.   If  Sbp  is not NULL, it is taken as the address of a place to
270       store the results of a stat(2) call.
271
272       ReadInDescriptor performs the same function as ReadInFile  except  that
273       fd refers to an already-open file.
274
275       HashMessageID returns hashed message-id using MD5.
276

EXAMPLES

278              char             *p;
279              char             frombuff[256], errbuff[256];
280              FILE             *F;
281              FILE             *ToServer;
282              FILE             *FromServer;
283              int              port = 119;
284
285              strlcpy(frombuff, HDR(HDR__FROM), sizeof(frombuff));
286              HeaderCleanFrom(frombuff);
287
288              if ((F = CAopen(FromServer, ToServer)) == NULL)
289                  Fatal("Can't open active file");
290
291              /* Don't pass the file on to our children. */
292              fdflag_close_exec(fileno(F), true);
293
294              /* Make a local copy. */
295              p = ReadInDescriptor(fileno(F), (struct stat *)NULL);
296
297              /* Close the file. */
298              CAclose();
299
300              if (NNTPremoteopen(port, &FromServer, &ToServer, errbuff, sizeof(errbuff)) < 0)
301                  Fatal("Can't connect to server");
302
303              if ((p = GetModeratorAddress(NULL, NULL, "comp.sources.unix",
304                                           "%s@example.com")) == NULL)
305                  Fatal("Can't find moderator's address");
306

HISTORY

308       Written  by  Rich  $alz <rsalz@uunet.uu.net> for InterNetNews.  This is
309       revision 10304, dated 2018-12-02.
310

SEE ALSO

312       active(5),   dbz(3z),    inn.conf(5),    inndcomm(3),    moderators(5),
313       passwd.nntp(5).
314
315
316
317                                                                     LIBINN(3)
Impressum