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