Skip to content

Commit 855a82f

Browse files
committed
Add a --user-agent option to the ipptool command.
1 parent ac833e7 commit 855a82f

4 files changed

Lines changed: 49 additions & 4 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ libcups v3.0.0 (YYYY-MM-DD)
77
- Added `cupsOAuthGetDeviceGrant`, `cupsOAuthGetJWKS`, and `cupsOAuthGetUserId`
88
APIs.
99
- Added `httpGetCookieValue` and `httpGetSecurity` APIs.
10+
- Added a "--user-agent" option to the `ipptool` command.
1011
- Updated documentation (Issue #113)
1112
- Updated the `cupsOAuth` APIs to support sharing of some OAuth values between
1213
the system (root) and per-user cache values.

doc/ipptool.html

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ <h2 id="ipptool-1.synopsis">Synopsis</h2>
115115
] [
116116
<strong>--stop-after-include-error</strong>
117117
] [
118+
<strong>--user-agent</strong>
119+
<em>USER-AGENT</em>
120+
] [
118121
<strong>--version</strong>
119122
] [
120123
<strong>-4</strong>
@@ -215,6 +218,15 @@ <h2 id="ipptool-1.options">Options</h2>
215218
to stop if an error occurs in an included file. Normally
216219
<strong>ipptool</strong>
217220
will continue with subsequent tests after the INCLUDE directive.
221+
</p>
222+
<p style="margin-left: 2.5em; text-indent: -2.5em;"><strong>--user-agent </strong><em>USER-AGENT</em><br>
223+
Specifies the HTTP User-Agent string to use.
224+
The default is based on the
225+
<strong>UserAgentTokens</strong>
226+
value in the
227+
<a href="client.conf.html"><strong>client.conf</strong>(5)</a>
228+
229+
file.
218230
</p>
219231
<p style="margin-left: 2.5em; text-indent: -2.5em;"><strong>--version</strong><br>
220232
Shows the version of
@@ -411,13 +423,15 @@ <h2 id="ipptool-1.examples">Examples</h2>
411423
ipp://localhost/printers/myprinter create-printer-subscription.test
412424
</pre>
413425
<h2 id="ipptool-1.see-also">See Also</h2>
414-
<a href="ipptoolfile.html"><p><strong>ipptoolfile</strong>(5),</a>
426+
<a href="client.conf.html"><p><strong>client.conf</strong>(5),</a>
427+
428+
<a href="ipptoolfile.html"><strong>ipptoolfile</strong>(5),</a>
415429

416430
IANA IPP Registry (<a href="https://www.iana.org/assignments/ipp-registrations">https://www.iana.org/assignments/ipp-registrations</a>),
417431
PWG Internet Printing Protocol Workgroup (<a href="https://www.pwg.org/ipp">https://www.pwg.org/ipp</a>),
418432
RFC 8011 (<a href="https://datatracker.ietf.org/doc/html/rfc8011">https://datatracker.ietf.org/doc/html/rfc8011</a>)
419433
</p>
420434
<h2 id="ipptool-1.copyright">Copyright</h2>
421-
<p>Copyright &copy; 2021-2024 by OpenPrinting.
435+
<p>Copyright &copy; 2021-2025 by OpenPrinting.
422436
</body>
423437
</html>

man/ipptool.1

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ ipptool \- perform internet printing protocol requests
2626
] [
2727
.B \-\-stop\-after\-include\-error
2828
] [
29+
.B \-\-user\-agent
30+
.I USER-AGENT
31+
] [
2932
.B \-\-version
3033
] [
3134
.B \-4
@@ -123,6 +126,14 @@ to stop if an error occurs in an included file. Normally
123126
.B ipptool
124127
will continue with subsequent tests after the INCLUDE directive.
125128
.TP 5
129+
\fB\-\-user\-agent \fIUSER-AGENT\fR
130+
Specifies the HTTP User-Agent string to use.
131+
The default is based on the
132+
.B UserAgentTokens
133+
value in the
134+
.BR client.conf (5)
135+
file.
136+
.TP 5
126137
.B \-\-version
127138
Shows the version of
128139
.B ipptool
@@ -310,9 +321,10 @@ Send email notifications to "user@example.com" when "myprinter" changes:
310321
ipp://localhost/printers/myprinter create\-printer\-subscription.test
311322
.fi
312323
.SH SEE ALSO
324+
.BR client.conf (5),
313325
.BR ipptoolfile (5),
314326
IANA IPP Registry (https://www.iana.org/assignments/ipp\-registrations),
315327
PWG Internet Printing Protocol Workgroup (https://www.pwg.org/ipp),
316328
RFC 8011 (https://datatracker.ietf.org/doc/html/rfc8011)
317329
.SH COPYRIGHT
318-
Copyright \[co] 2021-2024 by OpenPrinting.
330+
Copyright \[co] 2021-2025 by OpenPrinting.

tools/ipptool.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ typedef struct ipptool_test_s // Test Data
149149
int verbosity; // Show all attributes?
150150

151151
char *bearer_token, // HTTP Bearer token
152-
*client_name; // TLS client certificate name
152+
*client_name, // TLS client certificate name
153+
*user_agent; // HTTP User-Agent value, if any
153154

154155
// Test Defaults
155156
bool def_ignore_errors; // Default IGNORE-ERRORS value
@@ -379,6 +380,19 @@ main(int argc, // I - Number of command-line args
379380
{
380381
data->stop_after_include_error = true;
381382
}
383+
else if (!strcmp(argv[i], "--user-agent"))
384+
{
385+
i ++;
386+
387+
if (i >= argc)
388+
{
389+
cupsLangPrintf(stderr, _("%s: Missing user agent after '--user-agent'."), "ipptool");
390+
free_data(data);
391+
return (usage(stderr));
392+
}
393+
394+
data->user_agent = argv[i];
395+
}
382396
else if (!strcmp(argv[i], "--version"))
383397
{
384398
puts(LIBCUPS_VERSION);
@@ -1055,6 +1069,9 @@ connect_printer(ipptool_test_t *data) // I - Test data
10551069

10561070
httpSetDefaultField(http, HTTP_FIELD_ACCEPT_ENCODING, "deflate, gzip, identity");
10571071

1072+
if (data->user_agent)
1073+
httpSetDefaultField(http, HTTP_FIELD_USER_AGENT, data->user_agent);
1074+
10581075
if (data->timeout > 0.0)
10591076
httpSetTimeout(http, data->timeout, timeout_cb, NULL);
10601077

@@ -6597,6 +6614,7 @@ usage(FILE *out)
65976614
cupsLangPuts(out, _("--help Show this help"));
65986615
cupsLangPuts(out, _("--ippfile FILENAME Produce IPP attribute file"));
65996616
cupsLangPuts(out, _("--stop-after-include-error Stop tests after a failed INCLUDE"));
6617+
cupsLangPuts(out, _("--user-agent USER-AGENT Set the HTTP User-Agent string"));
66006618
cupsLangPuts(out, _("--version Show the program version"));
66016619
cupsLangPuts(out, _("-4 Connect using IPv4"));
66026620
cupsLangPuts(out, _("-6 Connect using IPv6"));

0 commit comments

Comments
 (0)