]> diplodocus.org Git - nmh/blob - h/prototypes.h
mhlsbr.c: Don't strchr(3) non-string NUL-less buffer.
[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 *) NONNULL(1);
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, ...) CHECK_PRINTF(1, 2);
20 void adios (const char *, const char *, ...) CHECK_PRINTF(2, 3) NORETURN;
21 void die(const char *, ...) CHECK_PRINTF(1, 2) NORETURN;
22 void admonish (char *, char *, ...) CHECK_PRINTF(2, 3);
23 void advertise (const char *, char *, const char *, va_list) CHECK_PRINTF(3, 0);
24 void advise (const char *, const char *, ...) CHECK_PRINTF(2, 3);
25 char **argsplit (char *, char **, int *) NONNULL(1, 2);
26 void argsplit_msgarg (struct msgs_array *, char *, char **) NONNULL(1, 2, 3);
27 void argsplit_insert (struct msgs_array *, char *, char **) NONNULL(1, 2, 3);
28 void arglist_free (char *, char **);
29 void ambigsw (const char *, const struct swit *) NONNULL(1, 2);
30 int atooi(char *) NONNULL(1) PURE;
31 char **brkstring (char *, char *, char *) NONNULL(1);
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 *, ...) ENDNULL;
48 int context_del (char *);
49 char *context_find (const char *) PURE;
50 char *context_find_by_type (const char *, const char *, const char *);
51 int context_find_prefix(const char *) PURE;
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
64 /*
65 * Decode two characters into their quoted-printable representation.
66 *
67 * Arguments are:
68 *
69 * byte1 - First character of Q-P representation
70 * byte2 - Second character of Q-P representation
71 *
72 * Returns the decoded value, -1 if the conversion failed.
73 */
74 int decode_qp(unsigned char byte1, unsigned char byte2) CONST;
75
76 int default_done (int);
77
78 /*
79 * Encode a message header using RFC 2047 encoding. If the message contains
80 * no non-ASCII characters, then leave the header as-is.
81 *
82 * Arguments include:
83 *
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
90 * locale.
91 *
92 * Returns 0 on success, any other value on failure.
93 */
94
95 int encode_rfc2047(const char *name, char **value, int encoding,
96 const char *charset);
97
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);
106
107 /*
108 * Read a MH folder structure and return an allocated "struct msgs"
109 * corresponding to the contents of the folder.
110 *
111 * Arguments include:
112 *
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.
116 */
117 struct msgs *folder_read (char *name, int lockflag);
118
119 struct msgs *folder_realloc (struct msgs *, int, int);
120
121 /*
122 * Print null-terminated PROMPT to and flush standard output. Read answers from
123 * standard input until one matches an entry in SWITCHES. When one matches,
124 * return its swret field. Return 0 on EOF.
125 */
126 int read_switch(const char *PROMPT, const struct swit *SWITCHES);
127
128 /*
129 * If standard input is not a tty, return 1 without printing anything. Else,
130 * print null-terminated PROMPT to and flush standard output. Read answers from
131 * standard input until one is "yes" or "no", returning 1 for "yes" and 0 for
132 * "no". Also return 0 on EOF.
133 */
134 int read_yes_or_no_if_tty(const char *PROMPT);
135
136 /*
137 * Print null-terminated PROMPT to and flush standard output. Read multi-word
138 * answers from standard input until a first word matches an entry in SWITCHES.
139 * When one matches, return a pointer to an array of pointers to the words.
140 * Return NULL on EOF, interrupt, or other error.
141 */
142 char **read_switch_multiword(const char *PROMPT, const struct swit *SWITCHES);
143
144 /*
145 * Same as read_switch_multiword but using readline(3) for input.
146 */
147 #ifdef READLINE_SUPPORT
148 char **read_switch_multiword_via_readline (char *, struct swit *);
149 #endif /* READLINE_SUPPORT */
150
151 char **getarguments (char *, int, char **, int);
152
153 /*
154 * Returns the MIME character set indicated by the current locale setting.
155 * Should be used by routines that want to convert to/from the local
156 * character set, or if you want to check to see if you can display content
157 * in the local character set.
158 */
159 char *get_charset(void);
160
161 /* Return malloc'd copy of str, or of "" if NULL, exit on failure. */
162 char *getcpy(const char *str);
163
164 char *get_default_editor(void);
165 char *getfolder(int) PURE;
166
167 int m_atoi (char *) PURE;
168 char *m_backup (const char *);
169 int m_convert (struct msgs *, char *);
170 char *m_draft (char *, char *, int, int *);
171
172 m_getfld_state_t m_getfld_state_init(FILE *iob);
173 void m_getfld_state_reset (m_getfld_state_t *);
174 void m_getfld_state_destroy (m_getfld_state_t *);
175 void m_getfld_track_filepos (m_getfld_state_t *, FILE *);
176 void m_getfld_track_filepos2(m_getfld_state_t *);
177 int m_getfld (m_getfld_state_t *, char[NAMESZ], char *, int *, FILE *);
178 int m_getfld2(m_getfld_state_t *, char[NAMESZ], char *, int *);
179 int m_gmprot (void) PURE;
180 char *m_name (int);
181
182 void m_unknown(m_getfld_state_t *, FILE *);
183 void m_unknown2(m_getfld_state_t *);
184
185 char *nmh_getpass(const char *);
186 char *new_fs (char *, char *, char *);
187 char *path(char *, int);
188 int pidwait (pid_t, int);
189 int pidstatus (int, FILE *, char *);
190 char *pluspath(char *);
191 void print_help (char *, struct swit *, int);
192 void print_intro (FILE *, bool);
193 void print_sw (const char *, const struct swit *, char *, FILE *);
194 void print_version (char *);
195 void push (void);
196 char *r1bindex(char *, int) PURE;
197 void readconfig (struct node **, FILE *, const char *, int);
198 int refile (char **, char *);
199
200 /*
201 * Read our credentials file and (optionally) ask the user for anything
202 * missing.
203 *
204 * Arguments:
205 *
206 * host - Hostname (to scan credentials file)
207 * aname - Pointer to filled-in username
208 * apass - Pointer to filled-in password
209 * flags - One or more of RUSERPASS_NO_PROMPT_USER,
210 * RUSERPASS_NO_PROMPT_PASSWORD
211 */
212 void ruserpass (const char *host, char **aname, char **apass, int flags);
213 #define RUSERPASS_NO_PROMPT_USER 0x01
214 #define RUSERPASS_NO_PROMPT_PASSWORD 0x02
215
216 int remdir (char *);
217 void scan_detect_mbox_style (FILE *);
218 void scan_finished(void);
219 int seq_addmsg (struct msgs *, char *, int, int, int);
220 int seq_addsel (struct msgs *, char *, int, int);
221 char *seq_bits (struct msgs *);
222 int seq_delmsg (struct msgs *, char *, int);
223 int seq_delsel (struct msgs *, char *, int, int);
224 int seq_getnum (struct msgs *, char *);
225 char *seq_list (struct msgs *, char *);
226 int seq_nameok (char *);
227 void seq_print (struct msgs *, char *);
228 void seq_printall (struct msgs *);
229
230 /*
231 * Read the sequence files for the folder referenced in the given
232 * struct msgs and populate the sequence entries in the struct msgs.
233 *
234 * Arguments:
235 *
236 * mp - Folder structure to add sequence entries to
237 * lockflag - If true, obtain a write lock on the sequence file.
238 * Additionally, the sequence file will remain open
239 * and a pointer to the filehandle will be stored in
240 * folder structure, where it will later be used by
241 * seq_save().
242 *
243 * Return values:
244 * OK - successfully read the sequence files, or they don't exist
245 * NOTOK - failed to lock sequence file
246 */
247 int seq_read (struct msgs * mp, int lockflag);
248 void seq_save (struct msgs *);
249 void seq_setcur (struct msgs *, int);
250 void seq_setprev (struct msgs *);
251 void seq_setunseen (struct msgs *, int);
252 int showfile (char **, char *);
253 int smatch(const char *, const struct swit *) PURE;
254
255 /*
256 * Convert a set of bit flags to printable format.
257 *
258 * Arguments:
259 *
260 * buffer - Buffer to output string to.
261 * size - Size of buffer in bytes. Buffer is always NUL terminated.
262 * flags - Binary flags to output
263 * bitfield - Textual representation of bits to output. This string
264 * is in the following format:
265 *
266 * Option byte 0x01 STRING1 0x02 STRING2 ....
267 *
268 * The first byte is an option byte to snprintb(). Currently the only option
269 * supported is 0x08, which indicates that the flags should be output in
270 * octal format; if the option byte is any other value, the flags will be
271 * output in hexadecimal.
272 *
273 * After the option bytes are series of text strings, prefixed by the number
274 * of the bit they correspond to. For example, the bitfield string:
275 *
276 * "\020\01FLAG1\02FLAG2\03FLAG3\04FLAG4"
277 *
278 * will output the following string if "flags" is set to 0x09:
279 *
280 * 0x2<FLAG1,FLAG4>
281 *
282 * You don't have to use octal in the bitfield string, that's just the
283 * convention currently used by the nmh code. The order of flags in the
284 * bitfield string is not significant, but again, general convention is
285 * from least significant bit to most significant.
286 */
287 char *snprintb (char *buffer, size_t size, unsigned flags, char *bitfield);
288 int ssequal (const char *, const char *) PURE;
289 int stringdex (char *, char *) PURE;
290 char *trimcpy (char *);
291
292 int uprf (const char *, const char *) PURE;
293 int vfgets (FILE *, char **);
294
295 /*
296 * Output the local character set name, but make sure it is suitable for
297 * 8-bit characters.
298 */
299 char *write_charset_8bit (void);
300
301
302 /*
303 * some prototypes for address parsing system
304 * (others are in addrsbr.h)
305 */
306 char *LocalName(int);
307 char *SystemName(void);
308
309 /*
310 * prototypes for some routines in uip
311 */
312 int annotate (char *, char *, char *, bool, bool, int, bool);
313 void annolist(char *, char *, char *, int);
314 void annopreserve(int);
315 void m_pclose(void);
316 int mhl(int, char **);
317 int mhlsbr(int, char **, FILE *(*)(char *));
318 int distout (char *, char *, char *);
319 void replout (FILE *, char *, char *, struct msgs *, int,
320 int, char *, char *, char *, int);
321 int build_form (char *, char *, int *, char *, char *, char *, char *,
322 char *, char *);
323 int sendsbr (char **, int, char *, char *, struct stat *, int, const char *);
324 int what_now (char *, int, int, char *, char *,
325 int, struct msgs *, char *, int, char *, int);
326 int WhatNow(int, char **) NORETURN;
327
328 /*
329 * credentials management
330 */
331 void init_credentials_file(void);
332
333 /*
334 * Allocate and return a credentials structure. The credentials structure
335 * is now opaque; you need to use accessors to get inside of it. The
336 * accessors will only prompt the user for missing fields if they are
337 * needed.
338 *
339 * Arguments:
340 *
341 * host - Hostname we're connecting to (used to search credentials file)
342 * user - Username we are logging in as; can be NULL.
343 *
344 * Returns NULL on error, otherwise an allocated nmh_creds structure.
345 */
346 nmh_creds_t nmh_get_credentials (const char *host, const char *user);
347
348 /*
349 * Retrieve the user from a nmh_creds structure. May prompt the user
350 * if one is not defined.
351 *
352 * Arguments:
353 *
354 * creds - Structure from previous nmh_get_credentials() call
355 *
356 * Returns NULL on error, otherwise a NUL-terminated string containing
357 * the username. Points to allocated memory in the credentials structure
358 * that is free()d by nmh_free_credentials().
359 */
360 const char *nmh_cred_get_user(nmh_creds_t creds);
361
362 /*
363 * Retrieve the password from an nmh_creds structure. Otherwise identical
364 * to nmh_cred_get_user().
365 */
366 const char *nmh_cred_get_password(nmh_creds_t creds);
367
368 /*
369 * Free an allocated nmh_creds structure.
370 */
371 void nmh_credentials_free(nmh_creds_t creds);