Skip to content

Commit 6720984

Browse files
committed
Update docos.
1 parent e04e3e4 commit 6720984

File tree

5 files changed

+99
-50
lines changed

5 files changed

+99
-50
lines changed

cups/cups.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,10 @@ typedef bool (*cups_cert_san_cb_t)(const char *common_name, const char *subject_
288288
typedef bool (*cups_dest_cb_t)(void *user_data, cups_dest_flags_t flags, cups_dest_t *dest);
289289
// Destination enumeration callback
290290

291-
typedef const char *(*cups_oauth_cb_t)(http_t *http, const char *realm, const char *scope, const char *resource, void *user_data);
291+
typedef const char *(*cups_oauth_cb_t)(http_t *http, const char *realm, const char *scope, const char *resource, void *cb_data);
292292
// OAuth callback
293293

294-
typedef const char *(*cups_password_cb_t)(const char *prompt, http_t *http, const char *method, const char *resource, void *user_data);
294+
typedef const char *(*cups_password_cb_t)(const char *prompt, http_t *http, const char *method, const char *resource, void *cb_data);
295295
// New password callback
296296

297297

@@ -393,12 +393,12 @@ extern size_t cupsRemoveOption(const char *name, size_t num_options, cups_optio
393393

394394
extern bool cupsSaveCredentials(const char *path, const char *common_name, const char *credentials, const char *key) _CUPS_PUBLIC;
395395
extern http_status_t cupsSendRequest(http_t *http, ipp_t *request, const char *resource, size_t length) _CUPS_PUBLIC;
396-
extern void cupsSetOAuthCB(cups_oauth_cb_t cb, void *data) _CUPS_PUBLIC;
397396
extern bool cupsSetClientCredentials(const char *credentials, const char *key) _CUPS_PUBLIC;
398397
extern void cupsSetDefaultDest(const char *name, const char *instance, size_t num_dests, cups_dest_t *dests) _CUPS_PUBLIC;
399398
extern bool cupsSetDests(http_t *http, size_t num_dests, cups_dest_t *dests) _CUPS_PUBLIC;
400399
extern void cupsSetEncryption(http_encryption_t e) _CUPS_PUBLIC;
401-
extern void cupsSetPasswordCB(cups_password_cb_t cb, void *user_data) _CUPS_PUBLIC;
400+
extern void cupsSetOAuthCB(cups_oauth_cb_t cb, void *cb_data) _CUPS_PUBLIC;
401+
extern void cupsSetPasswordCB(cups_password_cb_t cb, void *cb_data) _CUPS_PUBLIC;
402402
extern void cupsSetServer(const char *server) _CUPS_PUBLIC;
403403
extern bool cupsSetServerCredentials(const char *path, const char *common_name, bool auto_create) _CUPS_PUBLIC;
404404
extern void cupsSetUser(const char *user) _CUPS_PUBLIC;

cups/cupspm.md

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,8 @@ handle `HTTP_STATUS_UNAUTHORIZED` responses beyond simply calling
11201120

11211121
## Authentication Using Passwords
11221122

1123-
When you call [`cupsDoAuthentication`](@@), CUPS normally requests a password
1123+
When you call [`cupsDoAuthentication`](@@) and the HTTP server requires the
1124+
"Basic" or "Digest" authentication schemes, CUPS normally requests a password
11241125
from the console. GUI applications should set a password callback using the
11251126
[`cupsSetPasswordCB`](@@) function:
11261127

@@ -1149,16 +1150,50 @@ authenticated. The password callback can call the [`httpGetField`](@@) and
11491150
authentication challenge.
11501151

11511152
The "method" argument specifies the HTTP method used for the request and is
1152-
typically "POST".
1153+
typically "GET", "POST", or "PUT".
11531154

1154-
The "resource" argument specifies the path used for the request.
1155+
The "resource" argument specifies the path or URI used for the request.
11551156

1156-
The "cb_data" argument provides the user data pointer from the
1157+
The "cb_data" argument provides the data pointer from the
11571158
[`cupsSetPasswordCB`](@@) call.
11581159

11591160

11601161
## Authorization using OAuth/OpenID Connect
11611162

1163+
When you call [`cupsDoAuthentication`](@@) and the HTTP server requires the
1164+
"Bearer" authentication scheme, CUPS will call an OAuth callback that you
1165+
register using the [`cupsSetOAuthCB`](@@) function:
1166+
1167+
```c
1168+
void
1169+
cupsSetOAuthCB(cups_oauth_cb_t cb, void *cb_data);
1170+
```
1171+
1172+
The OAuth callback is called when needed and is responsible for performing any
1173+
necessary authorization and returning an access token string:
1174+
1175+
```c
1176+
const char *
1177+
cups_oauth_cb(http_t *http, const char *realm, const char *scope,
1178+
const char *resource, void *cb_data);
1179+
```
1180+
1181+
The "http" argument is the connection hosting the request that is being
1182+
authenticated. The OAuth callback can call the [`httpGetField`](@@) and
1183+
[`httpGetSubField`](@@) functions to look for additional details concerning the
1184+
authentication challenge.
1185+
1186+
The "realm" and "scope" arguments provide the "realm" and "scope" parameters, if
1187+
any, from the "WWW-Authenticate" header.
1188+
1189+
The "resource" argument specifies the path or URI used for the request.
1190+
1191+
The "cb_data" argument provides the data pointer from the
1192+
[`cupsSetOAuthCB`](@@) call.
1193+
1194+
1195+
### OAuth Client Functions
1196+
11621197
CUPS provides a generic OAuth/OpenID client for authorizing access to printers
11631198
and other network resources. The following functions are provided:
11641199

@@ -1244,6 +1279,7 @@ if (access_token == NULL)
12441279
12451280
// Set the Bearer token for authorization.
12461281
httpSetAuthString(http, "Bearer", access_token);
1282+
free(access_token);
12471283
```
12481284

12491285

@@ -1321,6 +1357,7 @@ if (access_token == NULL)
13211357
13221358
// Set the Bearer token for authorization.
13231359
httpSetAuthString(http, "Bearer", access_token);
1360+
free(access_token);
13241361
```
13251362

13261363

cups/usersys.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,7 @@ cupsSetEncryption(http_encryption_t e) // I - New encryption preference
279279
// 'cupsSetOAuthCB()' - Set the OAuth 2.0 callback for CUPS.
280280
//
281281
// This function sets the OAuth 2.0 callback for the various CUPS APIs that
282-
// send HTTP requests. Pass `NULL` to restore the default (console-based)
283-
// callback.
282+
// send HTTP requests. Pass `NULL` to disable OAuth authorization.
284283
//
285284
// The OAuth callback receives the HTTP connection, realm name, scope name (if
286285
// any), resource path, and the "user_data" pointer for each request that
@@ -296,19 +295,17 @@ cupsSetEncryption(http_encryption_t e) // I - New encryption preference
296295
// program. Multi-threaded programs that override the callback need to do so in
297296
// each thread for the same callback to be used.
298297
//
299-
//
300-
//
301298

302299
void
303300
cupsSetOAuthCB(
304301
cups_oauth_cb_t cb, // I - Callback function
305-
void *user_data) // I - User data pointer
302+
void *cb_data) // I - Callback data pointer
306303
{
307304
_cups_globals_t *cg = _cupsGlobals(); // Pointer to library globals
308305

309306

310307
cg->oauth_cb = cb;
311-
cg->oauth_data = user_data;
308+
cg->oauth_data = cb_data;
312309
}
313310

314311

@@ -326,7 +323,7 @@ cupsSetOAuthCB(
326323
void
327324
cupsSetPasswordCB(
328325
cups_password_cb_t cb, // I - Callback function
329-
void *user_data) // I - User data pointer
326+
void *cb_data) // I - Callback data pointer
330327
{
331328
_cups_globals_t *cg = _cupsGlobals(); // Pointer to library globals
332329

@@ -336,7 +333,7 @@ cupsSetPasswordCB(
336333
else
337334
cg->password_cb = cb;
338335

339-
cg->password_data = user_data;
336+
cg->password_data = cb_data;
340337
}
341338

342339

doc/cupspm.epub

254 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)