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