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