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