]> diplodocus.org Git - nmh/blob - h/prototypes.h
fgets() reserves space for the NUL itself.
[nmh] / h / prototypes.h
1
2 /*
3 * prototypes.h -- various prototypes
4 *
5 * If you modify functions here, please document their current behavior
6 * as much as practical.
7 */
8
9 /*
10 * prototype from config.h
11 */
12 char *etcpath(char *);
13
14 /*
15 * prototypes from the nmh subroutine library
16 */
17
18 struct msgs_array;
19
20 void add_profile_entry (const char *, const char *);
21 void adios (const char *, const char *, ...) NORETURN;
22 void admonish (char *, char *, ...);
23 void advertise (const char *, char *, const char *, va_list);
24 void advise (const char *, const char *, ...);
25 char **argsplit (char *, char **, int *);
26 void argsplit_msgarg (struct msgs_array *, char *, char **);
27 void argsplit_insert (struct msgs_array *, char *, char **);
28 void arglist_free (char *, char **);
29 void ambigsw (const char *, const struct swit *);
30 int atooi(char *);
31 char **brkstring (char *, char *, char *);
32
33 /*
34 * Check to see if we can display a given character set natively.
35 * Arguments include:
36 *
37 * str - Name of character set to check against
38 * len - Length of "str"
39 *
40 * Returns 1 if the specified character set can be displayed natively,
41 * 0 otherwise.
42 */
43
44 int check_charset (char *, int);
45 int client(char *, char *, char *, int, int);
46 void closefds(int);
47 char *concat (const char *, ...);
48 int context_del (char *);
49 char *context_find (const char *);
50 char *context_find_by_type (const char *, const char *, const char *);
51 int context_find_prefix(const char *);
52 int context_foil (char *);
53 void context_read (void);
54 void context_replace (char *, char *);
55 void context_save (void);
56 char *copy (const char *, char *);
57 char **copyip (char **, char **, int);
58 void cpydata (int, int, const char *, const char *);
59 void cpydgst (int, int, char *, char *);
60 char *cpytrim (const char *);
61 char *rtrim (char *);
62 int decode_rfc2047 (char *, char *, size_t);
63 void discard (FILE *);
64 char *upcase (const char *);
65
66 /*
67 * Decode two characters into their quoted-printable representation.
68 *
69 * Arguments are:
70 *
71 * byte1 - First character of Q-P representation
72 * byte2 - Second character of Q-P representation
73 *
74 * Returns the decoded value, -1 if the conversion failed.
75 */
76 int decode_qp(unsigned char byte1, unsigned char byte2);
77
78 int default_done (int);
79
80 /*
81 * Encode a message header using RFC 2047 encoding. If the message contains
82 * no non-ASCII characters, then leave the header as-is.
83 *
84 * Arguments include:
85 *
86 * name - Message header name
87 * value - Message header content; must point to allocated memory
88 * (may be changed if encoding is necessary)
89 * encoding - Encoding type. May be one of CE_UNKNOWN (function chooses
90 * the encoding), CE_BASE64 or CE_QUOTED
91 * charset - Charset used for encoding. If NULL, obtain from system
92 * locale.
93 *
94 * Returns 0 on success, any other value on failure.
95 */
96
97 int encode_rfc2047(const char *name, char **value, int encoding,
98 const char *charset);
99
100 void escape_display_name (char *, size_t);
101 void escape_local_part (char *, size_t);
102 int ext_hook(char *, char *, char *);
103 int fdcompare (int, int);
104 int folder_addmsg (struct msgs **, char *, int, int, int, int, char *);
105 int folder_delmsgs (struct msgs *, int, int);
106 void folder_free (struct msgs *);
107 int folder_pack (struct msgs **, int);
108
109 /*
110 * Read a MH folder structure and return an allocated "struct msgs"
111 * corresponding to the contents of the folder.
112 *
113 * Arguments include:
114 *
115 * name - Name of folder
116 * lockflag - If true, write-lock (and keep open) metadata files.
117 * See comments for seq_read() for more information.
118 */
119 struct msgs *folder_read (char *name, int lockflag);
120
121 struct msgs *folder_realloc (struct msgs *, int, int);
122
123 /*
124 * Flush standard output, read a line from standard input into a static buffer,
125 * zero out the newline, and return a pointer to the buffer.
126 * On error, return NULL.
127 */
128 const char *read_line(void);
129
130 /*
131 * Print null-terminated PROMPT to and flush standard output. Read answers from
132 * standard input until one matches an entry in SWITCHES. When one matches,
133 * return its swret field. Return 0 on EOF.
134 */
135 int read_switch(const char *PROMPT, const struct swit *SWITCHES);
136
137 /*
138 * If standard input is not a tty, return 1 without printing anything. Else,
139 * print null-terminated PROMPT to and flush standard output. Read answers from
140 * standard input until one is "yes" or "no", returning 1 for "yes" and 0 for
141 * "no". Also return 0 on EOF.
142 */
143 int read_yes_or_no_if_tty(const char *PROMPT);
144
145 /*
146 * Print null-terminated PROMPT to and flush standard output. Read multi-word
147 * answers from standard input until a first word matches an entry in SWITCHES.
148 * When one matches, return a pointer to an array of pointers to the words.
149 * Return NULL on EOF, interrupt, or other error.
150 */
151 char **read_switch_multiword(const char *PROMPT, const struct swit *SWITCHES);
152
153 /*
154 * Same as read_switch_multiword but using readline(3) for input.
155 */
156 #ifdef READLINE_SUPPORT
157 char **read_switch_multiword_via_readline (char *, struct swit *);
158 #endif /* READLINE_SUPPORT */
159
160 char **getarguments (char *, int, char **, int);
161
162 /*
163 * Returns the MIME character set indicated by the current locale setting.
164 * Should be used by routines that want to convert to/from the local
165 * character set, or if you want to check to see if you can display content
166 * in the local character set.
167 */
168 char *get_charset(void);
169
170 /* Return malloc'd copy of str, or of "" if NULL, exit on failure. */
171 char *getcpy(const char *str);
172
173 char *get_default_editor(void);
174 char *getfolder(int);
175
176 /*
177 * Get a string from the terminfo database for the current terminal.
178 *
179 * Retrieve the specified terminfo capability and return a string that
180 * can be output to the terminal. The string returned has already been
181 * processed by tputs(), so it is safe to output directly. The return
182 * value of this function is valid until the next call.
183 *
184 * Arguments:
185 *
186 * capability - The name of the terminfo capability (see terminfo(5)).
187 *
188 * Returns a tputs-processed string, or NULL if terminal initialization failed
189 * or the capability wasn't found.
190 */
191 char *get_term_stringcap(char *capability);
192
193 /*
194 * Get a parameterized string from the terminfo database for the current
195 * terminal.
196 *
197 * We don't yet have a standardized tparm() that will take a stdarg
198 * argument. Right now we don't want many parameters, so we only
199 * take two. Everything gets passed to tparm() as-is. If we need
200 * a capability with more arguments, we'll just add more later.
201 *
202 * Arguments:
203 *
204 * capability - The name of the terminfo capability (see terminfo(5)).
205 * arg1..argN - Arguments 1-N.
206 *
207 * Returns a tparm and tputs-processed string, or NULL if there was a problem
208 * initializating the terminal or retrieving the capability.
209 */
210 char *get_term_stringparm(char *capability, long arg1, long arg2);
211
212 /*
213 * Get a number from the terminfo database for the current terminal.
214 *
215 * Retrieve the specified terminfo capability and return the numeric
216 * value of that capability from the terminfo database.
217 *
218 * Arguments:
219 *
220 * capability - The name of the terminfo capability (see terminfo(5)).
221 *
222 * Returns the output of tigetnum() for that capability, or -1 if it was
223 * unable to initialize the terminfo database.
224 */
225 int get_term_numcap(char *capability);
226
227 /*
228 * Lock open/close routines.
229 *
230 * The lk[f]opendata() functions are designed to open "data" files (anything
231 * not a mail spool file) using the locking mechanism configured for data
232 * files. The lk[f]openspool() functions are for opening the mail spool
233 * file, which will use the locking algorithm configured for the mail
234 * spool.
235 *
236 * Files opened for reading are locked with a read lock (if possible by
237 * the underlying lock mechanism), files opened for writing are locked
238 * using an exclusive lock. The int * argument is used to indicate failure
239 * to acquire a lock.
240 */
241 int lkclosedata(int, const char *);
242 int lkclosespool(int, const char *);
243 int lkfclosedata(FILE *, const char *);
244 int lkfclosespool(FILE *, const char *);
245 FILE *lkfopendata(const char *, const char *, int *);
246 int lkopendata(const char *, int, mode_t, int *);
247 FILE *lkfopenspool(const char *, const char *);
248 int lkopenspool(const char *, int, mode_t, int *);
249 int m_atoi (char *);
250 char *m_backup (const char *);
251 int m_convert (struct msgs *, char *);
252 char *m_draft (char *, char *, int, int *);
253 void m_getfld_state_reset (m_getfld_state_t *);
254 void m_getfld_state_destroy (m_getfld_state_t *);
255 void m_getfld_track_filepos (m_getfld_state_t *, FILE *);
256 int m_getfld (m_getfld_state_t *, char[NAMESZ], char *, int *, FILE *);
257 int m_gmprot (void);
258 char *m_maildir (char *);
259 char *m_mailpath (char *);
260 char *m_name (int);
261 int m_putenv (char *, char *);
262 int m_rand (unsigned char *, size_t);
263 char *m_mktemp(const char *, int *, FILE **);
264 char *m_mktemp2(const char *, const char *, int *, FILE **);
265 char *m_mktemps(const char *pfx, const char *suffix, int *, FILE **);
266 char *get_temp_dir();
267
268 /*
269 * Create a subprocess and redirect our standard output to it.
270 *
271 * Arguments are:
272 *
273 * name - Name of process to create
274 * savestdout - If true, will save the current stdout file descriptor and
275 * m_pclose() will close it at the appropriate time.
276 */
277 void m_popen(char *name, int savestdout);
278
279 /*
280 * Wait for the last process opened by m_popen().
281 */
282 void m_pclose(void);
283
284 void m_unknown(m_getfld_state_t *, FILE *);
285 int makedir (const char *);
286 char *message_id (time_t, int);
287
288 /*
289 * Return a MIME content-type string for the specified file.
290 *
291 * If the system supports it, will use the "file" command to determine
292 * the appropriate content-type. Otherwise it will try to determine the
293 * content-type from the suffix. If that fails, the file will be scanned
294 * and either assigned a MIME type of text/plain or application/octet-stream
295 * depending if binary content is present.
296 *
297 * Arguments:
298 *
299 * filename - The name of the file to determine the MIME type of.
300 *
301 * Returns a pointer to a content-type string (which may include MIME
302 * parameters, such as charset). Returns a NULL if it cannot determine
303 * the MIME type of the file. Returns allocated storage that must be
304 * free'd.
305 */
306 char *mime_type(const char *filename);
307
308 /*
309 * Clear the screen, using the appropriate entry from the terminfo database
310 */
311 void nmh_clear_screen(void);
312 char *nmh_getpass(const char *);
313 char *new_fs (char *, char *, char *);
314 char *path(char *, int);
315 int pidwait (pid_t, int);
316 int pidstatus (int, FILE *, char *);
317 char *pluspath(char *);
318 void print_help (char *, struct swit *, int);
319 void print_intro (FILE *, int);
320 void print_sw (const char *, const struct swit *, char *, FILE *);
321 void print_version (char *);
322 void push (void);
323 char *pwd (void);
324 char *r1bindex(char *, int);
325 void readconfig (struct node **, FILE *, const char *, int);
326 int refile (char **, char *);
327
328 /*
329 * Read our credentials file and (optionally) ask the user for anything
330 * missing.
331 *
332 * Arguments:
333 *
334 * host - Hostname (to scan credentials file)
335 * aname - Pointer to filled-in username
336 * apass - Pointer to filled-in password
337 * flags - One or more of RUSERPASS_NO_PROMPT_USER,
338 * RUSERPASS_NO_PROMPT_PASSWORD
339 */
340 void ruserpass (const char *host, char **aname, char **apass, int flags);
341 #define RUSERPASS_NO_PROMPT_USER 0x01
342 #define RUSERPASS_NO_PROMPT_PASSWORD 0x02
343
344 int remdir (char *);
345 void scan_detect_mbox_style (FILE *);
346 void scan_finished ();
347 void scan_reset_m_getfld_state ();
348 int seq_addmsg (struct msgs *, char *, int, int, int);
349 int seq_addsel (struct msgs *, char *, int, int);
350 char *seq_bits (struct msgs *);
351 int seq_delmsg (struct msgs *, char *, int);
352 int seq_delsel (struct msgs *, char *, int, int);
353 int seq_getnum (struct msgs *, char *);
354 char *seq_list (struct msgs *, char *);
355 int seq_nameok (char *);
356 void seq_print (struct msgs *, char *);
357 void seq_printall (struct msgs *);
358
359 /*
360 * Read the sequence files for the folder referenced in the given
361 * struct msgs and populate the sequence entries in the struct msgs.
362 *
363 * Arguments:
364 *
365 * mp - Folder structure to add sequence entries to
366 * lockflag - If true, obtain a write lock on the sequence file.
367 * Additionally, the sequence file will remain open
368 * and a pointer to the filehandle will be stored in
369 * folder structure, where it will later be used by
370 * seq_save().
371 *
372 * Return values:
373 * OK - successfully read the sequence files, or they don't exist
374 * NOTOK - failed to lock sequence file
375 */
376 int seq_read (struct msgs * mp, int lockflag);
377 void seq_save (struct msgs *);
378 void seq_setcur (struct msgs *, int);
379 void seq_setprev (struct msgs *);
380 void seq_setunseen (struct msgs *, int);
381 int showfile (char **, char *);
382 int smatch(const char *, const struct swit *);
383
384 /*
385 * Convert a set of bit flags to printable format.
386 *
387 * Arguments:
388 *
389 * buffer - Buffer to output string to.
390 * size - Size of buffer in bytes. Buffer is always NUL terminated.
391 * flags - Binary flags to output
392 * bitfield - Textual representation of bits to output. This string
393 * is in the following format:
394 *
395 * Option byte 0x01 STRING1 0x02 STRING2 ....
396 *
397 * The first byte is an option byte to snprintb(). Currently the only option
398 * supported is 0x08, which indicates that the flags should be output in
399 * octal format; if the option byte is any other value, the flags will be
400 * output in hexadecimal.
401 *
402 * After the option bytes are series of text strings, prefixed by the number
403 * of the bit they correspond to. For example, the bitfield string:
404 *
405 * "\020\01FLAG1\02FLAG2\03FLAG3\04FLAG4"
406 *
407 * will output the following string if "flags" is set to 0x09:
408 *
409 * 0x2<FLAG1,FLAG4>
410 *
411 * You don't have to use octal in the bitfield string, that's just the
412 * convention currently used by the nmh code. The order of flags in the
413 * bitfield string is not significant, but again, general convention is
414 * from least significant bit to most significant.
415 */
416 char *snprintb (char *buffer, size_t size, unsigned flags, char *bitfield);
417 int ssequal (const char *, const char *);
418 int stringdex (char *, char *);
419 char *trimcpy (char *);
420 int unputenv (char *);
421
422 /*
423 * Remove quotes and quoted-pair sequences from RFC-5322 atoms.
424 *
425 * Currently the actual algorithm is simpler than it technically should
426 * be: any quotes are simply eaten, unless they're preceded by the escape
427 * character (\). This seems to be sufficient for our needs for now.
428 *
429 * Arguments:
430 *
431 * input - The input string
432 * output - The output string; is assumed to have at least as much
433 * room as the input string. At worst the output string will
434 * be the same size as the input string; it might be smaller.
435 *
436 */
437 void unquote_string(const char *input, char *output);
438 int uprf (const char *, const char *);
439 int vfgets (FILE *, char **);
440
441 /*
442 * Output the local character set name, but make sure it is suitable for
443 * 8-bit characters.
444 */
445 char *write_charset_8bit (void);
446
447
448 /*
449 * some prototypes for address parsing system
450 * (others are in addrsbr.h)
451 */
452 char *LocalName(int);
453 char *SystemName(void);
454
455 /*
456 * prototypes for some routines in uip
457 */
458 int annotate (char *, char *, char *, int, int, int, int);
459 void annolist(char *, char *, char *, int);
460 void annopreserve(int);
461 void m_pclose(void);
462 int make_intermediates(char *);
463 int mhl(int, char **);
464 int mhlsbr(int, char **, FILE *(*)(char *));
465 int distout (char *, char *, char *);
466 void replout (FILE *, char *, char *, struct msgs *, int,
467 int, char *, char *, char *, int);
468 int sc_length(void);
469 int sc_width(void);
470 int build_form (char *, char *, int *, char *, char *, char *, char *,
471 char *, char *);
472 int sendsbr (char **, int, char *, char *, struct stat *, int, const char *);
473 int SOprintf (char *, ...);
474 int what_now (char *, int, int, char *, char *,
475 int, struct msgs *, char *, int, char *, int);
476 int WhatNow(int, char **);
477
478 /* Includes trailing NUL */
479
480 #define BASE64SIZE(x) ((((x + 2) / 3) * 4) + 1)
481
482 /*
483 * Copy data from one file to another, converting to base64-encoding.
484 *
485 * Arguments include:
486 *
487 * in - Input filehandle (unencoded data)
488 * out - Output filename (base64-encoded data)
489 * crlf - If set, output encoded CRLF for every LF on input.
490 *
491 * Returns OK on success, NOTOK otherwise.
492 */
493 int writeBase64aux(FILE *in, FILE *out, int crlf);
494
495 int writeBase64 (const unsigned char *, size_t, unsigned char *);
496 int writeBase64raw (const unsigned char *, size_t, unsigned char *);
497
498 /*
499 * encoded - the string to be decoded
500 * decoded - the decoded bytes
501 * len - number of decoded bytes
502 * skip-crs - non-zero for text content, and for which CR's should be
503 * skipped
504 * digest - for an MD5 digest, it can be null
505 */
506 int decodeBase64 (const char *encoded, unsigned char **decoded, size_t *len,
507 int skip_crs, unsigned char *digest);
508
509 void hexify (const unsigned char *, size_t, char **);
510
511 /*
512 * credentials management
513 */
514 void init_credentials_file ();
515
516 /*
517 * Allocate and return a credentials structure. The credentials structure
518 * is now opaque; you need to use accessors to get inside of it. The
519 * accessors will only prompt the user for missing fields if they are
520 * needed.
521 *
522 * Arguments:
523 *
524 * host - Hostname we're connecting to (used to search credentials file)
525 * user - Username we are logging in as; can be NULL.
526 *
527 * Returns NULL on error, otherwise an allocated nmh_creds structure.
528 */
529 nmh_creds_t nmh_get_credentials (const char *host, const char *user);
530
531 /*
532 * Retrieve the user from a nmh_creds structure. May prompt the user
533 * if one is not defined.
534 *
535 * Arguments:
536 *
537 * creds - Structure from previous nmh_get_credentials() call
538 *
539 * Returns NULL on error, otherwise a NUL-termined string containing
540 * the username. Points to allocated memory in the credentials structure
541 * that is free()d by nmh_free_credentials().
542 */
543 const char *nmh_cred_get_user(nmh_creds_t creds);
544
545 /*
546 * Retrieve the password from an nmh_creds structure. Otherwise identical
547 * to nmh_cred_get_user().
548 */
549 const char *nmh_cred_get_password(nmh_creds_t creds);
550
551 /*
552 * Free an allocated nmh_creds structure.
553 */
554 void nmh_credentials_free(nmh_creds_t creds);
555
556 /*
557 * program initialization
558 *
559 * argv0 - argv[0], presumably the program name
560 * read_context - 0: don't read context
561 * - 1: read context, check nmh version, and issue warning message
562 * if non-existent or old
563 * - 2: read context, don't check nmh version
564 */
565 int nmh_init(const char *argv0, int read_context);
566
567 /*
568 * temporary file management
569 */
570 int m_unlink(const char *);
571 void unregister_for_removal(int remove_files);