1NE_SET_SERVER_AUTH(3) neon API reference NE_SET_SERVER_AUTH(3)
2
3
4
6 ne_set_server_auth, ne_set_proxy_auth, ne_forget_auth - register
7 authentication callbacks
8
10 #include <ne_auth.h>
11
12 typedef int (*ne_auth_creds)(void *userdata, const char *realm,
13 int attempt, char *username,
14 char *password);
15
16 void ne_set_server_auth(ne_session *session, ne_auth_creds callback,
17 void *userdata);
18
19 void ne_set_proxy_auth(ne_session *session, ne_auth_creds callback,
20 void *userdata);
21
22 void ne_forget_auth(ne_session *session);
23
25 The ne_auth_creds function type defines a callback which is invoked
26 when a server or proxy server requires user authentication for a
27 particular request. The realm string is supplied by the server. The
28 attempt is a counter giving the number of times the request has been
29 retried with different authentication credentials. The first time the
30 callback is invoked for a particular request, attempt will be zero.
31
32 To retry the request using new authentication credentials, the callback
33 should return zero, and the username and password buffers must contain
34 NUL-terminated strings. The NE_ABUFSIZ constant gives the size of these
35 buffers.
36
37 Tip
38 If you only wish to allow the user one attempt to enter
39 credentials, use the value of the attempt parameter as the return
40 value of the callback.
41
42 To abort the request, the callback should return a non-zero value; in
43 which case the contents of the username and password buffers are
44 ignored.
45
46 The ne_forget_auth function can be used to discard the cached
47 authentication credentials.
48
50 /* Function which prompts for a line of user input: */
51 extern char *prompt_for(const char *prompt);
52
53 static int
54 my_auth(void *userdata, const char *realm, int attempts,
55 char *username, char *password)
56 {
57 strncpy(username, prompt_for("Username: "), NE_ABUFSIZ);
58 strncpy(password, prompt_for("Password: "), NE_ABUFSIZ);
59 return attempts;
60 }
61
62 int main(...)
63 {
64 ne_session *sess = ne_session_create(...);
65
66 ne_set_server_auth(sess, my_auth, NULL);
67
68 /* ... */
69 }
70
72 Joe Orton <neon@lists.manyfish.co.uk>
73 Author.
74
76neon 0.32.2 12 January 2022 NE_SET_SERVER_AUTH(3)