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