]>
diplodocus.org Git - nmh/blob - h/prototypes.h
28d21f0b29b0e645550aa8501e82aa97fd294ff2
1 /* prototypes.h -- various prototypes
3 * If you modify functions here, please document their current behavior
4 * as much as practical.
8 * prototype from config.h
10 char *etcpath(char *);
13 * prototypes from the nmh subroutine library
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
*);
30 char **brkstring (char *, char *, char *);
33 * Check to see if we can display a given character set natively.
36 * str - Name of character set to check against
37 * len - Length of "str"
39 * Returns 1 if the specified character set can be displayed natively,
43 int check_charset (char *, int);
44 int client(char *, char *, char *, int, 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 *);
60 int decode_rfc2047 (char *, char *, size_t);
61 void discard (FILE *);
62 char *upcase (const char *);
65 * Decode two characters into their quoted-printable representation.
69 * byte1 - First character of Q-P representation
70 * byte2 - Second character of Q-P representation
72 * Returns the decoded value, -1 if the conversion failed.
74 int decode_qp(unsigned char byte1
, unsigned char byte2
);
76 int default_done (int);
79 * Encode a message header using RFC 2047 encoding. If the message contains
80 * no non-ASCII characters, then leave the header as-is.
84 * name - Message header name
85 * value - Message header content; must point to allocated memory
86 * (may be changed if encoding is necessary)
87 * encoding - Encoding type. May be one of CE_UNKNOWN (function chooses
88 * the encoding), CE_BASE64 or CE_QUOTED
89 * charset - Charset used for encoding. If NULL, obtain from system
92 * Returns 0 on success, any other value on failure.
95 int encode_rfc2047(const char *name
, char **value
, int encoding
,
98 void escape_display_name (char *, size_t);
99 void escape_local_part (char *, size_t);
100 int ext_hook(char *, char *, char *);
101 int fdcompare (int, int);
102 int folder_addmsg (struct msgs
**, char *, int, int, int, int, char *);
103 int folder_delmsgs (struct msgs
*, int, int);
104 void folder_free (struct msgs
*);
105 int folder_pack (struct msgs
**, int);
108 * Read a MH folder structure and return an allocated "struct msgs"
109 * corresponding to the contents of the folder.
113 * name - Name of folder
114 * lockflag - If true, write-lock (and keep open) metadata files.
115 * See comments for seq_read() for more information.
117 struct msgs
*folder_read (char *name
, int lockflag
);
119 struct msgs
*folder_realloc (struct msgs
*, int, int);
122 * Flush standard output, read a line from standard input into a static buffer,
123 * zero out the newline, and return a pointer to the buffer.
124 * On error, return NULL.
126 const char *read_line(void);
129 * Print null-terminated PROMPT to and flush standard output. Read answers from
130 * standard input until one matches an entry in SWITCHES. When one matches,
131 * return its swret field. Return 0 on EOF.
133 int read_switch(const char *PROMPT
, const struct swit
*SWITCHES
);
136 * If standard input is not a tty, return 1 without printing anything. Else,
137 * print null-terminated PROMPT to and flush standard output. Read answers from
138 * standard input until one is "yes" or "no", returning 1 for "yes" and 0 for
139 * "no". Also return 0 on EOF.
141 int read_yes_or_no_if_tty(const char *PROMPT
);
144 * Print null-terminated PROMPT to and flush standard output. Read multi-word
145 * answers from standard input until a first word matches an entry in SWITCHES.
146 * When one matches, return a pointer to an array of pointers to the words.
147 * Return NULL on EOF, interrupt, or other error.
149 char **read_switch_multiword(const char *PROMPT
, const struct swit
*SWITCHES
);
152 * Same as read_switch_multiword but using readline(3) for input.
154 #ifdef READLINE_SUPPORT
155 char **read_switch_multiword_via_readline (char *, struct swit
*);
156 #endif /* READLINE_SUPPORT */
158 char **getarguments (char *, int, char **, int);
161 * Returns the MIME character set indicated by the current locale setting.
162 * Should be used by routines that want to convert to/from the local
163 * character set, or if you want to check to see if you can display content
164 * in the local character set.
166 char *get_charset(void);
168 /* Return malloc'd copy of str, or of "" if NULL, exit on failure. */
169 char *getcpy(const char *str
);
171 char *get_default_editor(void);
172 char *getfolder(int);
175 * Get a string from the terminfo database for the current terminal.
177 * Retrieve the specified terminfo capability and return a string that
178 * can be output to the terminal. The string returned has already been
179 * processed by tputs(), so it is safe to output directly. The return
180 * value of this function is valid until the next call.
184 * capability - The name of the terminfo capability (see terminfo(5)).
186 * Returns a tputs-processed string, or NULL if terminal initialization failed
187 * or the capability wasn't found.
189 char *get_term_stringcap(char *capability
);
192 * Get a parameterized string from the terminfo database for the current
195 * We don't yet have a standardized tparm() that will take a stdarg
196 * argument. Right now we don't want many parameters, so we only
197 * take two. Everything gets passed to tparm() as-is. If we need
198 * a capability with more arguments, we'll just add more later.
202 * capability - The name of the terminfo capability (see terminfo(5)).
203 * arg1..argN - Arguments 1-N.
205 * Returns a tparm and tputs-processed string, or NULL if there was a problem
206 * initialising the terminal or retrieving the capability.
208 char *get_term_stringparm(char *capability
, long arg1
, long arg2
);
211 * Get a number from the terminfo database for the current terminal.
213 * Retrieve the specified terminfo capability and return the numeric
214 * value of that capability from the terminfo database.
218 * capability - The name of the terminfo capability (see terminfo(5)).
220 * Returns the output of tigetnum() for that capability, or -1 if it was
221 * unable to initialize the terminfo database.
223 int get_term_numcap(char *capability
);
226 * Lock open/close routines.
228 * The lk[f]opendata() functions are designed to open "data" files (anything
229 * not a mail spool file) using the locking mechanism configured for data
230 * files. The lk[f]openspool() functions are for opening the mail spool
231 * file, which will use the locking algorithm configured for the mail
234 * Files opened for reading are locked with a read lock (if possible by
235 * the underlying lock mechanism), files opened for writing are locked
236 * using an exclusive lock. The int * argument is used to indicate failure
239 int lkclosedata(int, const char *);
240 int lkclosespool(int, const char *);
241 int lkfclosedata(FILE *, const char *);
242 int lkfclosespool(FILE *, const char *);
243 FILE *lkfopendata(const char *, const char *, int *);
244 int lkopendata(const char *, int, mode_t
, int *);
245 FILE *lkfopenspool(const char *, const char *);
246 int lkopenspool(const char *, int, mode_t
, int *);
248 char *m_backup (const char *);
249 int m_convert (struct msgs
*, char *);
250 char *m_draft (char *, char *, int, int *);
251 void m_getfld_state_reset (m_getfld_state_t
*);
252 void m_getfld_state_destroy (m_getfld_state_t
*);
253 void m_getfld_track_filepos (m_getfld_state_t
*, FILE *);
254 int m_getfld (m_getfld_state_t
*, char[NAMESZ
], char *, int *, FILE *);
256 char *m_maildir (char *);
257 char *m_mailpath (char *);
259 int m_rand (unsigned char *, size_t);
262 * Create a subprocess and redirect our standard output to it.
266 * name - Name of process to create
267 * savestdout - If true, will save the current stdout file descriptor and
268 * m_pclose() will close it at the appropriate time.
270 void m_popen(char *name
, int savestdout
);
273 * Wait for the last process opened by m_popen().
277 void m_unknown(m_getfld_state_t
*, FILE *);
278 int makedir (const char *);
279 char *message_id (time_t, int);
282 * Return a MIME content-type string for the specified file.
284 * If the system supports it, will use the "file" command to determine
285 * the appropriate content-type. Otherwise it will try to determine the
286 * content-type from the suffix. If that fails, the file will be scanned
287 * and either assigned a MIME type of text/plain or application/octet-stream
288 * depending if binary content is present.
292 * filename - The name of the file to determine the MIME type of.
294 * Returns a pointer to a content-type string (which may include MIME
295 * parameters, such as charset). Returns a NULL if it cannot determine
296 * the MIME type of the file. Returns allocated storage that must be
299 char *mime_type(const char *filename
);
302 * Clear the screen, using the appropriate entry from the terminfo database
304 void nmh_clear_screen(void);
305 char *nmh_getpass(const char *);
306 char *new_fs (char *, char *, char *);
307 char *path(char *, int);
308 int pidwait (pid_t
, int);
309 int pidstatus (int, FILE *, char *);
310 char *pluspath(char *);
311 void print_help (char *, struct swit
*, int);
312 void print_intro (FILE *, int);
313 void print_sw (const char *, const struct swit
*, char *, FILE *);
314 void print_version (char *);
317 char *r1bindex(char *, int);
318 void readconfig (struct node
**, FILE *, const char *, int);
319 int refile (char **, char *);
322 * Read our credentials file and (optionally) ask the user for anything
327 * host - Hostname (to scan credentials file)
328 * aname - Pointer to filled-in username
329 * apass - Pointer to filled-in password
330 * flags - One or more of RUSERPASS_NO_PROMPT_USER,
331 * RUSERPASS_NO_PROMPT_PASSWORD
333 void ruserpass (const char *host
, char **aname
, char **apass
, int flags
);
334 #define RUSERPASS_NO_PROMPT_USER 0x01
335 #define RUSERPASS_NO_PROMPT_PASSWORD 0x02
338 void scan_detect_mbox_style (FILE *);
339 void scan_finished(void);
340 int seq_addmsg (struct msgs
*, char *, int, int, int);
341 int seq_addsel (struct msgs
*, char *, int, int);
342 char *seq_bits (struct msgs
*);
343 int seq_delmsg (struct msgs
*, char *, int);
344 int seq_delsel (struct msgs
*, char *, int, int);
345 int seq_getnum (struct msgs
*, char *);
346 char *seq_list (struct msgs
*, char *);
347 int seq_nameok (char *);
348 void seq_print (struct msgs
*, char *);
349 void seq_printall (struct msgs
*);
352 * Read the sequence files for the folder referenced in the given
353 * struct msgs and populate the sequence entries in the struct msgs.
357 * mp - Folder structure to add sequence entries to
358 * lockflag - If true, obtain a write lock on the sequence file.
359 * Additionally, the sequence file will remain open
360 * and a pointer to the filehandle will be stored in
361 * folder structure, where it will later be used by
365 * OK - successfully read the sequence files, or they don't exist
366 * NOTOK - failed to lock sequence file
368 int seq_read (struct msgs
* mp
, int lockflag
);
369 void seq_save (struct msgs
*);
370 void seq_setcur (struct msgs
*, int);
371 void seq_setprev (struct msgs
*);
372 void seq_setunseen (struct msgs
*, int);
373 int showfile (char **, char *);
374 int smatch(const char *, const struct swit
*);
377 * Convert a set of bit flags to printable format.
381 * buffer - Buffer to output string to.
382 * size - Size of buffer in bytes. Buffer is always NUL terminated.
383 * flags - Binary flags to output
384 * bitfield - Textual representation of bits to output. This string
385 * is in the following format:
387 * Option byte 0x01 STRING1 0x02 STRING2 ....
389 * The first byte is an option byte to snprintb(). Currently the only option
390 * supported is 0x08, which indicates that the flags should be output in
391 * octal format; if the option byte is any other value, the flags will be
392 * output in hexadecimal.
394 * After the option bytes are series of text strings, prefixed by the number
395 * of the bit they correspond to. For example, the bitfield string:
397 * "\020\01FLAG1\02FLAG2\03FLAG3\04FLAG4"
399 * will output the following string if "flags" is set to 0x09:
403 * You don't have to use octal in the bitfield string, that's just the
404 * convention currently used by the nmh code. The order of flags in the
405 * bitfield string is not significant, but again, general convention is
406 * from least significant bit to most significant.
408 char *snprintb (char *buffer
, size_t size
, unsigned flags
, char *bitfield
);
409 int ssequal (const char *, const char *);
410 int stringdex (char *, char *);
411 char *trimcpy (char *);
414 * Remove quotes and quoted-pair sequences from RFC-5322 atoms.
416 * Currently the actual algorithm is simpler than it technically should
417 * be: any quotes are simply eaten, unless they're preceded by the escape
418 * character (\). This seems to be sufficient for our needs for now.
422 * input - The input string
423 * output - The output string; is assumed to have at least as much
424 * room as the input string. At worst the output string will
425 * be the same size as the input string; it might be smaller.
428 void unquote_string(const char *input
, char *output
);
429 int uprf (const char *, const char *);
430 int vfgets (FILE *, char **);
433 * Output the local character set name, but make sure it is suitable for
436 char *write_charset_8bit (void);
440 * some prototypes for address parsing system
441 * (others are in addrsbr.h)
443 char *LocalName(int);
444 char *SystemName(void);
447 * prototypes for some routines in uip
449 int annotate (char *, char *, char *, int, int, int, int);
450 void annolist(char *, char *, char *, int);
451 void annopreserve(int);
453 int make_intermediates(char *);
454 int mhl(int, char **);
455 int mhlsbr(int, char **, FILE *(*)(char *));
456 int distout (char *, char *, char *);
457 void replout (FILE *, char *, char *, struct msgs
*, int,
458 int, char *, char *, char *, int);
461 int build_form (char *, char *, int *, char *, char *, char *, char *,
463 int sendsbr (char **, int, char *, char *, struct stat
*, int, const char *);
464 int SOprintf (char *, ...);
465 int what_now (char *, int, int, char *, char *,
466 int, struct msgs
*, char *, int, char *, int);
467 int WhatNow(int, char **);
469 /* Includes trailing NUL */
471 #define BASE64SIZE(x) ((((x + 2) / 3) * 4) + 1)
474 * Copy data from one file to another, converting to base64-encoding.
478 * in - Input filehandle (unencoded data)
479 * out - Output filename (base64-encoded data)
480 * crlf - If set, output encoded CRLF for every LF on input.
482 * Returns OK on success, NOTOK otherwise.
484 int writeBase64aux(FILE *in
, FILE *out
, int crlf
);
486 int writeBase64 (const unsigned char *, size_t, unsigned char *);
487 int writeBase64raw (const unsigned char *, size_t, unsigned char *);
490 * encoded - the string to be decoded
491 * decoded - the decoded bytes
492 * len - number of decoded bytes
493 * skip-crs - non-zero for text content, and for which CR's should be
495 * digest - for an MD5 digest, it can be null
497 int decodeBase64 (const char *encoded
, unsigned char **decoded
, size_t *len
,
498 int skip_crs
, unsigned char *digest
);
500 void hexify (const unsigned char *, size_t, char **);
503 * credentials management
505 void init_credentials_file(void);
508 * Allocate and return a credentials structure. The credentials structure
509 * is now opaque; you need to use accessors to get inside of it. The
510 * accessors will only prompt the user for missing fields if they are
515 * host - Hostname we're connecting to (used to search credentials file)
516 * user - Username we are logging in as; can be NULL.
518 * Returns NULL on error, otherwise an allocated nmh_creds structure.
520 nmh_creds_t
nmh_get_credentials (const char *host
, const char *user
);
523 * Retrieve the user from a nmh_creds structure. May prompt the user
524 * if one is not defined.
528 * creds - Structure from previous nmh_get_credentials() call
530 * Returns NULL on error, otherwise a NUL-terminated string containing
531 * the username. Points to allocated memory in the credentials structure
532 * that is free()d by nmh_free_credentials().
534 const char *nmh_cred_get_user(nmh_creds_t creds
);
537 * Retrieve the password from an nmh_creds structure. Otherwise identical
538 * to nmh_cred_get_user().
540 const char *nmh_cred_get_password(nmh_creds_t creds
);
543 * Free an allocated nmh_creds structure.
545 void nmh_credentials_free(nmh_creds_t creds
);
548 * program initialization
550 * argv0 - argv[0], presumably the program name
551 * read_context - 0: don't read context
552 * - 1: read context, check nmh version, and issue warning message
553 * if non-existent or old
554 * - 2: read context, don't check nmh version
556 int nmh_init(const char *argv0
, int read_context
);