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