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