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