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