]> diplodocus.org Git - nmh/blob - h/prototypes.h
a37938681d3d58a2746e114edc3e62cf5e1d54ad
[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 /*
74 * Print null-terminated PROMPT to and flush standard output. Read answers from
75 * standard input until one matches an entry in SWITCHES. When one matches,
76 * return its swret field. Return 0 on EOF.
77 */
78 int read_switch(const char *PROMPT, const struct swit *SWITCHES);
79
80 /*
81 * If standard input is not a tty, return 1 without printing anything. Else,
82 * print null-terminated PROMPT to and flush standard output. Read answers from
83 * standard input until one is "yes" or "no", returning 1 for "yes" and 0 for
84 * "no". Also return 0 on EOF.
85 */
86 int read_yes_or_no_if_tty(const char *PROMPT);
87
88 /*
89 * Print null-terminated PROMPT to and flush standard output. Read multi-word
90 * answers from standard input until a first word matches an entry in SWITCHES.
91 * When one matches, return a pointer to an array of pointers to the words.
92 * Return NULL on EOF, interrupt, or other error.
93 */
94 char **read_switch_multiword(const char *PROMPT, const struct swit *SWITCHES);
95
96 /*
97 * Same as read_switch_multiword but using readline(3) for input.
98 */
99 #ifdef READLINE_SUPPORT
100 char **read_switch_multiword_via_readline (char *, struct swit *);
101 #endif /* READLINE_SUPPORT */
102
103 char **getarguments (char *, int, char **, int);
104
105 /*
106 * Returns the MIME character set indicated by the current locale setting.
107 * Should be used by routines that want to convert to/from the local
108 * character set, or if you want to check to see if you can display content
109 * in the local character set.
110 */
111 char *get_charset(void);
112
113 /* Return malloc'd copy of str, or of "" if NULL, exit on failure. */
114 char *getcpy(const char *str);
115
116 char *m_draft (char *, char *, int, int *);
117
118 m_getfld_state_t m_getfld_state_init(FILE *iob);
119 void m_getfld_state_reset (m_getfld_state_t *);
120 void m_getfld_state_destroy (m_getfld_state_t *);
121 void m_getfld_track_filepos (m_getfld_state_t *, FILE *);
122 void m_getfld_track_filepos2(m_getfld_state_t *);
123 int m_getfld (m_getfld_state_t *, char[NAMESZ], char *, int *, FILE *);
124 int m_getfld2(m_getfld_state_t *, char[NAMESZ], char *, int *);
125 int m_gmprot (void) PURE;
126 char *m_name (int);
127
128 void m_unknown(m_getfld_state_t *, FILE *);
129 void m_unknown2(m_getfld_state_t *);
130
131 char *nmh_getpass(const char *);
132 int pidwait (pid_t, int);
133 char *r1bindex(char *, int) PURE;
134 int refile (char **, char *);
135
136 /*
137 * Read our credentials file and (optionally) ask the user for anything
138 * missing.
139 *
140 * Arguments:
141 *
142 * host - Hostname (to scan credentials file)
143 * aname - Pointer to filled-in username
144 * apass - Pointer to filled-in password
145 * flags - One or more of RUSERPASS_NO_PROMPT_USER,
146 * RUSERPASS_NO_PROMPT_PASSWORD
147 */
148 void ruserpass (const char *host, char **aname, char **apass, int flags);
149 #define RUSERPASS_NO_PROMPT_USER 0x01
150 #define RUSERPASS_NO_PROMPT_PASSWORD 0x02
151
152 int remdir (char *);
153 void scan_detect_mbox_style (FILE *);
154 void scan_finished(void);
155
156 /*
157 * Read the sequence files for the folder referenced in the given
158 * struct msgs and populate the sequence entries in the struct msgs.
159 *
160 * Arguments:
161 *
162 * mp - Folder structure to add sequence entries to
163 * lockflag - If true, obtain a write lock on the sequence file.
164 * Additionally, the sequence file will remain open
165 * and a pointer to the filehandle will be stored in
166 * folder structure, where it will later be used by
167 * seq_save().
168 *
169 * Return values:
170 * OK - successfully read the sequence files, or they don't exist
171 * NOTOK - failed to lock sequence file
172 */
173 int seq_read (struct msgs * mp, int lockflag);
174 void seq_save (struct msgs *);
175 void seq_setcur (struct msgs *, int);
176 void seq_setprev (struct msgs *);
177 void seq_setunseen (struct msgs *, int);
178 int showfile (char **, char *);
179 int smatch(const char *, const struct swit *) PURE;
180
181 /*
182 * Convert a set of bit flags to printable format.
183 *
184 * Arguments:
185 *
186 * buffer - Buffer to output string to.
187 * size - Size of buffer in bytes. Buffer is always NUL terminated.
188 * flags - Binary flags to output
189 * bitfield - Textual representation of bits to output. This string
190 * is in the following format:
191 *
192 * Option byte 0x01 STRING1 0x02 STRING2 ....
193 *
194 * The first byte is an option byte to snprintb(). Currently the only option
195 * supported is 0x08, which indicates that the flags should be output in
196 * octal format; if the option byte is any other value, the flags will be
197 * output in hexadecimal.
198 *
199 * After the option bytes are series of text strings, prefixed by the number
200 * of the bit they correspond to. For example, the bitfield string:
201 *
202 * "\020\01FLAG1\02FLAG2\03FLAG3\04FLAG4"
203 *
204 * will output the following string if "flags" is set to 0x09:
205 *
206 * 0x2<FLAG1,FLAG4>
207 *
208 * You don't have to use octal in the bitfield string, that's just the
209 * convention currently used by the nmh code. The order of flags in the
210 * bitfield string is not significant, but again, general convention is
211 * from least significant bit to most significant.
212 */
213 char *snprintb (char *buffer, size_t size, unsigned flags, char *bitfield);
214 int ssequal (const char *, const char *) PURE;
215 int stringdex (char *, char *) PURE;
216 char *trimcpy (char *);
217
218 int uprf (const char *, const char *) PURE;
219 int vfgets (FILE *, char **);
220
221 /*
222 * Output the local character set name, but make sure it is suitable for
223 * 8-bit characters.
224 */
225 char *write_charset_8bit (void);
226
227
228 /*
229 * prototypes for some routines in uip
230 */
231 int annotate (char *, char *, char *, bool, bool, int, bool);
232 void annolist(char *, char *, char *, int);
233 void annopreserve(int);
234 int mhl(int, char **);
235 int mhlsbr(int, char **, FILE *(*)(char *));
236 int distout (char *, char *, char *);
237 int sendsbr (char **, int, char *, char *, struct stat *, int, const char *);
238 int what_now (char *, int, int, char *, char *,
239 int, struct msgs *, char *, int, char *, int);
240 int WhatNow(int, char **) NORETURN;
241
242 /*
243 * credentials management
244 */
245 void init_credentials_file(void);
246
247 /*
248 * Allocate and return a credentials structure. The credentials structure
249 * is now opaque; you need to use accessors to get inside of it. The
250 * accessors will only prompt the user for missing fields if they are
251 * needed.
252 *
253 * Arguments:
254 *
255 * host - Hostname we're connecting to (used to search credentials file)
256 * user - Username we are logging in as; can be NULL.
257 *
258 * Returns NULL on error, otherwise an allocated nmh_creds structure.
259 */
260 nmh_creds_t nmh_get_credentials (const char *host, const char *user);
261
262 /*
263 * Retrieve the user from a nmh_creds structure. May prompt the user
264 * if one is not defined.
265 *
266 * Arguments:
267 *
268 * creds - Structure from previous nmh_get_credentials() call
269 *
270 * Returns NULL on error, otherwise a NUL-terminated string containing
271 * the username. Points to allocated memory in the credentials structure
272 * that is free()d by nmh_free_credentials().
273 */
274 const char *nmh_cred_get_user(nmh_creds_t creds);
275
276 /*
277 * Retrieve the password from an nmh_creds structure. Otherwise identical
278 * to nmh_cred_get_user().
279 */
280 const char *nmh_cred_get_password(nmh_creds_t creds);
281
282 /*
283 * Free an allocated nmh_creds structure.
284 */
285 void nmh_credentials_free(nmh_creds_t creds);