Print this page
4023 - Typo in file(1) manpage and various others
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/man/man3papi/papiJobSubmit.3papi
+++ new/usr/src/man/man3papi/papiJobSubmit.3papi
1 1 '\" te
2 2 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
3 3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 -.TH PAPIJOBSUBMIT 3PAPI "Jan 17, 2007"
6 +.TH PAPIJOBSUBMIT 3PAPI "Sep 10, 2013"
7 7 .SH NAME
8 8 papiJobSubmit, papiJobSubmitByReference, papiJobValidate, papiJobStreamOpen,
9 9 papiJobStreamWrite, papiJobStreamClose, papiJobQuery, papiJobModify,
10 10 papiJobMove, papiJobCancel, papiJobHold, papiJobRelease, papiJobRestart,
11 11 papiJobPromote, papiJobGetAttributeList, papiJobGetPrinterName, papiJobGetId,
12 12 papiJobGetJobTicket, papiJobFree, papiJobListFree \- job object manipulation
13 13 .SH SYNOPSIS
14 14 .LP
15 15 .nf
16 16 cc [ \fIflag\fR\&.\|.\|. ] \fIfile\fR\&.\|.\|. \fB-lpapi\fR [ \fIlibrary\fR\&.\|.\|. ]
17 17 #include <papi.h>
18 18
19 19 \fBpapi_status_t\fR \fBpapiJobSubmit\fR(\fBpapi_service_t\fR \fIhandle\fR,
20 20 \fBchar *\fR\fIprinter\fR, \fBpapi_attribute_t **\fR\fIjob_attributes\fR,
21 21 \fBpapi_job_ticket_t *\fR\fIjob_ticket\fR, \fBchar **\fR\fIfiles\fR,
22 22 \fBpapi_job_t *\fR\fIjob\fR);
23 23 .fi
24 24
25 25 .LP
26 26 .nf
27 27 \fBpapi_status_t\fR \fBpapiJobSubmitByReference\fR(\fBpapi_service_t\fR \fIhandle\fR,
28 28 \fBchar *\fR\fIprinter\fR, \fBpapi_attribute_t **\fR\fIjob_attributes\fR,
29 29 \fBpapi_job_ticket_t *\fR\fIjob_ticket\fR, \fBchar **\fR\fIfiles\fR,
30 30 \fBpapi_job_t *\fR\fIjob\fR);
31 31 .fi
32 32
33 33 .LP
34 34 .nf
35 35 \fBpapi_status_t\fR \fBpapiJobValidate\fR(\fBpapi_service_t\fR \fIhandle\fR,
36 36 \fBchar *\fR\fIprinter\fR, \fBpapi_attribute_t **\fR\fIjob_attributes\fR,
37 37 \fBpapi_job_ticket_t *\fR\fIjob_ticket\fR, \fBchar **\fR\fIfiles\fR,
38 38 \fBpapi_job_t *\fR\fIjob\fR);
39 39 .fi
40 40
41 41 .LP
42 42 .nf
43 43 \fBpapi_status_t\fR \fBpapiJobStreamOpen\fR(\fBpapi_service_t\fR \fIhandle\fR,
44 44 \fBchar *\fR\fIprinter\fR, \fBpapi_attribute_t **\fR\fIjob_attributes\fR,
45 45 \fBpapi_job_ticket_t *\fR\fIjob_ticket\fR, \fBpapi_stream_t *\fR\fIstream\fR);
46 46 .fi
47 47
48 48 .LP
49 49 .nf
50 50 \fBpapi_status_t\fR \fBpapiJobStreamWrite\fR(\fBpapi_service_t\fR \fIhandle\fR,
51 51 \fBpapi_stream_t\fR \fIstream\fR, \fBvoid *\fR\fIbuffer\fR, \fBsize_t\fR \fIbuflen\fR);
52 52 .fi
53 53
54 54 .LP
55 55 .nf
56 56 \fBpapi_status_t\fR \fBpapiJobStreamClose\fR(\fBpapi_service_t\fR \fIhandle\fR,
57 57 \fBpapi_stream_t\fR \fIstream\fR, \fBpapi_job_t *\fR\fIjob\fR);
58 58 .fi
59 59
60 60 .LP
61 61 .nf
62 62 \fBpapi_status_t\fR \fBpapiJobQuery\fR(\fBpapi_service_t\fR \fIhandle\fR,
63 63 \fBchar *\fR\fIprinter\fR, \fBint32_t\fR \fIjob_id\fR, \fBchar **\fR\fIrequested_attrs\fR,
64 64 \fBpapi_job_t *\fR\fIjob\fR);
65 65 .fi
66 66
67 67 .LP
68 68 .nf
69 69 \fBpapi_status_t\fR \fBpapiJobModify\fR(\fBpapi_service_t\fR \fIhandle\fR,
70 70 \fBchar *\fR\fIprinter\fR, \fBint32_t\fR \fIjob_id\fR,
71 71 \fBpapi_attribute_t **\fR\fIattributes\fR, \fBpapi_job_t *\fR\fIjob\fR);
72 72 .fi
73 73
74 74 .LP
75 75 .nf
76 76 \fBpapi_status_t\fR \fBpapiJobMove\fR(\fBpapi_service_t\fR \fIhandle\fR,
77 77 \fBchar *\fR\fIprinter\fR, \fBint32_t\fR \fIjob_id\fR, \fBchar *\fR\fIdestination\fR);
78 78 .fi
79 79
80 80 .LP
81 81 .nf
82 82 \fBpapi_status_t\fR \fBpapiJobCancel\fR(\fBpapi_service_t\fR \fIhandle\fR,
83 83 \fBchar *\fR\fIprinter\fR, \fBint32_t\fR \fIjob_id\fR);
84 84 .fi
85 85
86 86 .LP
87 87 .nf
88 88 \fBpapi_status_t\fR \fBpapiJobHold\fR(\fBpapi_service_t\fR \fIhandle\fR,
89 89 \fBchar *\fR\fIprinter\fR, \fBint32_t\fR \fIjob_id\fR);
90 90 .fi
91 91
92 92 .LP
93 93 .nf
94 94 \fBpapi_status_t\fR \fBpapiJobRelease\fR(\fBpapi_service_t\fR \fIhandle\fR,
95 95 \fBchar *\fR\fIprinter\fR, \fBint32_t\fR \fIjob_id\fR);
96 96 .fi
97 97
98 98 .LP
99 99 .nf
100 100 \fBpapi_status_t\fR \fBpapiJobRestart\fR(\fBpapi_service_t\fR \fIhandle\fR,
101 101 \fBchar *\fR\fIprinter\fR, \fBint32_t\fR \fIjob_id\fR);
102 102 .fi
103 103
104 104 .LP
105 105 .nf
106 106 \fBpapi_status_t\fR \fBpapiJobPromote\fR(\fBpapi_service_t\fR \fIhandle\fR,
107 107 \fBchar *\fR\fIprinter\fR, \fBint32_t\fR \fIjob_id\fR);
108 108 .fi
109 109
110 110 .LP
111 111 .nf
112 112 \fBpapi_attribute_t **\fR\fBpapiJobGetAttributeList\fR(\fBpapi_job_t\fR \fIjob\fR);
113 113 .fi
114 114
115 115 .LP
116 116 .nf
117 117 \fBchar *\fR\fBpapiJobGetPrinterName\fR(\fBpapi_job_t\fR \fIjob\fR);
118 118 .fi
119 119
120 120 .LP
121 121 .nf
122 122 \fBint32_t\fR \fBpapiJobGetId\fR(\fBpapi_job_t\fR \fIjob\fR);
123 123 .fi
124 124
125 125 .LP
126 126 .nf
127 127 \fBpapi_job_ticket_t *\fR\fBpapiJobGetJobTicket\fR(\fBpapi_job_t\fR \fIjob\fR);
128 128 .fi
129 129
130 130 .LP
131 131 .nf
132 132 \fBvoid\fR \fBpapiJobFree\fR(\fBpapi_job_t\fR \fIjob\fR);
133 133 .fi
134 134
135 135 .LP
136 136 .nf
137 137 \fBvoid\fR \fBpapiJobListFree\fR(\fBpapi_job_t *\fR\fIjobs\fR);
138 138 .fi
139 139
140 140 .SH PARAMETERS
141 141 .sp
142 142 .ne 2
143 143 .na
144 144 \fB\fIattributes\fR\fR
145 145 .ad
146 146 .RS 19n
147 147 a set of attributes to be applied to a printer object
148 148 .RE
149 149
150 150 .sp
151 151 .ne 2
152 152 .na
153 153 \fB\fIbuffer\fR\fR
154 154 .ad
155 155 .RS 19n
156 156 a buffer of data to be written to the job stream
157 157 .RE
158 158
159 159 .sp
160 160 .ne 2
161 161 .na
162 162 \fB\fIbufflen\fR\fR
163 163 .ad
164 164 .RS 19n
165 165 the size of the supplied buffer
166 166 .RE
167 167
168 168 .sp
169 169 .ne 2
170 170 .na
171 171 \fB\fIdestination\fR\fR
172 172 .ad
173 173 .RS 19n
174 174 the name of the printer where a print job should be relocated, which must
175 175 reside within the same print services as the job is currently queued
176 176 .RE
177 177
178 178 .sp
179 179 .ne 2
180 180 .na
181 181 \fB\fIfiles\fR\fR
182 182 .ad
183 183 .RS 19n
184 184 files to use during job submission
185 185 .RE
186 186
187 187 .sp
188 188 .ne 2
189 189 .na
190 190 \fB\fIhandle\fR\fR
191 191 .ad
192 192 .RS 19n
193 193 a pointer to a handle to be used for all PAPI operations that is created by
194 194 calling \fBpapiServiceCreate()\fR
195 195 .RE
196 196
197 197 .sp
198 198 .ne 2
199 199 .na
200 200 \fB\fIjob\fR\fR
201 201 .ad
202 202 .RS 19n
203 203 a pointer to a printer object (initialized to NULL) to be filled in by
204 204 \fBpapiJobQuery()\fR, \fBpapiJobSubmit()\fR, \fBpapiJobSubmitByReference()\fR,
205 205 \fBpapiJobValidate()\fR, \fBpapiJobStreamClose()\fR, and \fBpapiJobModify()\fR
206 206 .RE
207 207
208 208 .sp
209 209 .ne 2
210 210 .na
211 211 \fB\fIjob_attributes\fR\fR
212 212 .ad
213 213 .RS 19n
214 214 attributes to apply during job creation or modification
215 215 .RE
216 216
217 217 .sp
218 218 .ne 2
219 219 .na
220 220 \fB\fIjob_id\fR\fR
221 221 .ad
222 222 .RS 19n
223 223 ID number of the job reported on or manipulated
224 224 .RE
225 225
226 226 .sp
227 227 .ne 2
228 228 .na
229 229 \fB\fIjob_ticket\fR\fR
230 230 .ad
231 231 .RS 19n
232 232 unused
233 233 .RE
234 234
235 235 .sp
236 236 .ne 2
237 237 .na
238 238 \fB\fIjobs\fR\fR
239 239 .ad
240 240 .RS 19n
241 241 a list of job objects returned by \fBpapiPrinterListJobs()\fR or
242 242 \fBpapiPrinterPurgeJobs()\fR
243 243 .RE
244 244
245 245 .sp
246 246 .ne 2
247 247 .na
248 248 \fB\fIprinter\fR\fR
249 249 .ad
250 250 .RS 19n
251 251 name of the printer where the job is or should reside
252 252 .RE
253 253
254 254 .sp
255 255 .ne 2
256 256 .na
257 257 \fB\fIrequested_attrs\fR\fR
258 258 .ad
259 259 .RS 19n
260 260 a null-terminated array of pointers to attribute names requested during job
261 261 enumeration (\fBpapiPrinterListJobs()\fR) or job query (\fBpapiJobQuery()\fR)
262 262 .RE
263 263
264 264 .sp
265 265 .ne 2
266 266 .na
267 267 \fB\fIstream\fR\fR
268 268 .ad
269 269 .RS 19n
270 270 a communication endpoint for sending print job data
271 271 .RE
272 272
273 273 .SH DESCRIPTION
274 274 .sp
275 275 .LP
276 276 The \fBpapiJobSubmit()\fR function creates a print job containing the passed in
277 277 files with the supplied attributes. When the function returns, the data in the
278 278 passed files will have been copied by the print service. A job object is
279 279 returned that reflects the state of the job.
280 280 .sp
281 281 .LP
282 282 The \fBpapiJobSubmitByReference()\fR function creates a print job containing
283 283 the passed in files with the supplied attributes. When the function returns,
284 284 the data in the passed files might have been copied by the print service. A job
285 285 object is returned that reflects the state of the job.
286 286 .sp
287 287 .LP
288 288 The \fBpapiJobStreamOpen()\fR, \fBpapiJobStreamWrite()\fR,
289 289 \fBpapiJobStreamClose()\fR functions create a print job by opening a stream,
290 290 writing to the stream, and closing it.
291 291 .sp
292 292 .LP
293 293 The \fBpapiJobValidate()\fR function validates that the supplied attributes and
294 294 files will result in a valid print job.
295 295 .sp
296 296 .LP
297 297 The \fBpapiJobQuery()\fR function retrieves job information from the print
298 298 service.
299 299 .sp
300 300 .LP
301 301 The \fBpapiJobModify()\fR function modifies a queued job according to the
302 302 attribute list passed into the call. A job object is returned that reflects
303 303 the state of the job after the modification has been applied.
304 304 .sp
305 305 .LP
306 306 The \fBpapiJobMove()\fR function moves a job from its current queue to the
307 307 named destination within the same print service.
308 308 .sp
309 309 .LP
310 310 The \fBpapiJobCancel()\fR function removes a job from the queue.
311 311 .sp
312 312 .LP
313 313 The \fBpapiJobHold()\fR and \fBpapiJobRelease()\fR functions set the job state
314 314 to "held" or "idle" to indicate whether the job is eligible for processing.
315 315 .sp
316 316 .LP
317 317 The \fBpapiJobRestart()\fR function restarts processing of a currently queued
318 318 print job.
319 319 .sp
320 320 .LP
321 321 The \fBpapiJobGetAttributeList()\fR function returns a list of attributes
322 322 describing the job. This list can be searched and/or enumerated using
323 323 \fBpapiAttributeList*()\fR calls. See \fBpapiAttributeListAddValue\fR(3PAPI).
324 324 .sp
325 325 .LP
326 326 The \fBpapiJobGetPrinterName()\fR function returns the name of the queue where
327 327 the job is currently queued.
328 328 .sp
329 329 .LP
330 330 The \fBpapiJobGetId()\fR function returns a job identifier number from the job
331 331 object passed in.
332 332 .sp
333 333 .LP
334 334 The \fBpapiJobPromote()\fR function moves a job to the head of the print queue.
335 335 .sp
336 336 .LP
337 337 The \fBpapiJobGetJobTicket()\fR function retrieves a pointer to a job ticket
338 338 associated with the job object.
339 339 .sp
340 340 .LP
341 341 The \fBpapiJobFree()\fR and \fBpapiJobListFree()\fR functions deallocate memory
342 342 allocated for the return of printer object(s) from functions that return
343 343 printer objects.
344 344 .SH RETURN VALUES
345 345 .sp
346 346 .LP
347 347 Upon successful completion, all \fBpapiJob*()\fR functions that return a value
348 348 return \fBPAPI_OK\fR. Otherwise, they return an appropriate \fBpapi_status_t\fR
349 349 indicating the type of failure.
350 350 .sp
351 351 .LP
352 352 Upon successful completion, \fBpapiJobGetAttributeList()\fR returns a pointer
353 353 to the requested data. Otherwise, it returns \fINULL\fR.
354 354 .SH EXAMPLES
355 355 .LP
356 356 \fBExample 1 \fREnumerate all jobs in a queue
357 357 .sp
358 358 .in +2
359 359 .nf
360 360 /*
361 361 * program to enumerate queued jobs using PAPI interfaces.
362 362 */
363 363 #include <stdio.h>
364 364 #include <stdlib.h>
365 365 #include <unistd.h>
366 366 #include <libintl.h>
367 367 #include <pwd.h>
368 368 #include <papi.h>
369 369
370 370 static int
371 371 authCB(papi_service_t svc, void *app_data)
372 372 {
373 373 char prompt[BUFSIZ];
374 374 char *user, *svc_name, *passphrase;
375 375
376 376 /* get the name of the service we are contacting */
377 377 if ((svc_name = papiServiceGetServiceName(svc)) == NULL)
378 378 return (-1);
379 379
380 380 /* find out who we are supposed to be */
381 381 if ((user = papiServiceGetUserName(svc)) == NULL) {
382 382 struct passwd *pw;
383 383
384 384 if ((pw = getpwuid(getuid())) != NULL)
385 385 user = pw->pw_name;
386 386 else
387 387 user = "nobody";
388 388 }
389 389
390 390 /* build the prompt string */
391 391 snprintf(prompt, sizeof (prompt),
392 392 gettext("passphrase for %s to access %s: "), user,
393 393 svc_name);
394 394
395 395 /* ask for the passphrase */
396 396 if ((passphrase = getpassphrase(prompt)) != NULL)
397 397 papiServiceSetPassword(svc, passphrase);
398 398
399 399 return (0);
400 400 }
401 401
402 402 /*ARGSUSED*/
403 403 int
404 404 main(int ac, char *av[])
405 405 {
406 406 papi_status_t status;
407 407 papi_service_t svc = NULL;
408 408 papi_job_t *jobs = NULL;
409 409 char *svc_name = NULL;
410 410 char *pname = "unknown";
411 411 int c;
412 412
413 413 while ((c = getopt(ac, av, "s:p:")) != EOF)
414 414 switch (c) {
415 415 case 's':
416 416 svc_name = optarg;
↓ open down ↓ |
400 lines elided |
↑ open up ↑ |
417 417 break;
418 418 case 'p':
419 419 pname = optarg;
420 420 break;
421 421 }
422 422
423 423 status = papiServiceCreate(&svc, svc_name, NULL, NULL, authCB,
424 424 PAPI_ENCRYPT_NEVER, NULL);
425 425
426 426 if (status != PAPI_OK) {
427 - printf("papiServiceCreate(%s): %s\n", svc_name ? svc_name :
427 + printf("papiServiceCreate(%s): %s\en", svc_name ? svc_name :
428 428 "NULL", papiStatusString(status));
429 429 papiServiceDestroy(svc);
430 430 exit(1);
431 431 }
432 432
433 433 status = papiPrinterListJobs(svc, pname, NULL, 0, 0, &jobs);
434 434 if (status != PAPI_OK) {
435 - printf("papiPrinterListJobs(%s): %s\n", pname,
435 + printf("papiPrinterListJobs(%s): %s\en", pname,
436 436 papiStatusString(status));
437 437 papiServiceDestroy(svc);
438 438 exit(1);
439 439 }
440 440
441 441 if (jobs != NULL) {
442 442 int i;
443 443
444 444 for (i = 0; jobs[i] != NULL; i++) {
445 445 papi_attribute_t **list = papiJobGetAttributeList(jobs[i]);
446 446
447 447 if (list != NULL) {
448 448 char *name = "unknown";
449 449 int32_t id = 0;
450 450 char *buffer = NULL;
↓ open down ↓ |
5 lines elided |
↑ open up ↑ |
451 451 size_t size = 0;
452 452
453 453 (void) papiAttributeListGetString(list, NULL,
454 454 "printer-name", &name);
455 455 (void) papiAttributeListGetInteger(list, NULL,
456 456 "job-id", &id);
457 457 while (papiAttributeListToString(list, "\n\t", buffer,
458 458 size) != PAPI_OK)
459 459 buffer = realloc(buffer, size += BUFSIZ);
460 460
461 - printf("%s-%d:\n\t%s\n", name, id, buffer);
461 + printf("%s-%d:\en\t%s\en", name, id, buffer);
462 462 free(buffer);
463 463 }
464 464 }
465 465 papiJobListFree(jobs);
466 466 }
467 467
468 468 papiServiceDestroy(svc);
469 469
470 470 exit(0);
471 471 }
472 472 .fi
473 473 .in -2
474 474
475 475 .LP
476 476 \fBExample 2 \fRDump all job attributes.
477 477 .sp
478 478 .in +2
479 479 .nf
480 480 /*
481 481 * program to dump a queued job's attributes using PAPI interfaces.
482 482 */
483 483 #include <stdio.h>
484 484 #include <stdlib.h>
485 485 #include <unistd.h>
486 486 #include <libintl.h>
487 487 #include <pwd.h>
488 488 #include <papi.h>
489 489
490 490 static int
491 491 authCB(papi_service_t svc, void *app_data)
492 492 {
493 493 char prompt[BUFSIZ];
494 494 char *user, *svc_name, *passphrase;
495 495
496 496 /* get the name of the service we are contacting */
497 497 if ((svc_name = papiServiceGetServiceName(svc)) == NULL)
498 498 return (-1);
499 499
500 500 /* find out who we are supposed to be */
501 501 if ((user = papiServiceGetUserName(svc)) == NULL) {
502 502 struct passwd *pw;
503 503
504 504 if ((pw = getpwuid(getuid())) != NULL)
505 505 user = pw->pw_name;
506 506 else
507 507 user = "nobody";
508 508 }
509 509
510 510 /* build the prompt string */
511 511 snprintf(prompt, sizeof (prompt),
512 512 gettext("passphrase for %s to access %s: "), user,
513 513 svc_name);
514 514
515 515 /* ask for the passphrase */
516 516 if ((passphrase = getpassphrase(prompt)) != NULL)
517 517 papiServiceSetPassword(svc, passphrase);
518 518
519 519 return (0);
520 520 }
521 521
522 522 /*ARGSUSED*/
523 523 int
524 524 main(int ac, char *av[])
525 525 {
526 526 papi_status_t status;
527 527 papi_service_t svc = NULL;
528 528 papi_job_t job = NULL;
529 529 char *svc_name = NULL;
530 530 char *pname = "unknown";
531 531 int id = 0;
532 532 int c;
533 533
534 534 while ((c = getopt(ac, av, "s:p:j:")) != EOF)
535 535 switch (c) {
536 536 case 's':
537 537 svc_name = optarg;
538 538 break;
539 539 case 'p':
540 540 pname = optarg;
↓ open down ↓ |
69 lines elided |
↑ open up ↑ |
541 541 break;
542 542 case 'j':
543 543 id = atoi(optarg);
544 544 break;
545 545 }
546 546
547 547 status = papiServiceCreate(&svc, svc_name, NULL, NULL, authCB,
548 548 PAPI_ENCRYPT_NEVER, NULL);
549 549
550 550 if (status != PAPI_OK) {
551 - printf("papiServiceCreate(%s): %s\n", svc_name ? svc_name :
551 + printf("papiServiceCreate(%s): %s\en", svc_name ? svc_name :
552 552 "NULL", papiStatusString(status));
553 553 papiServiceDestroy(svc);
554 554 exit(1);
555 555 }
556 556
557 557 status = papiJobQuery(svc, pname, id, NULL, &job);
558 558 if ((status == PAPI_OK) && (job != NULL)) {
559 559 papi_attribute_t **list = papiJobGetAttributeList(job);
560 560
561 561 if (list != NULL) {
562 562 char *name = "unknown";
563 563 int32_t id = 0;
564 564 char *buffer = NULL;
565 565 size_t size = 0;
566 566
567 567 (void) papiAttributeListGetString(list, NULL,
568 568 "printer-name", &name);
569 569 (void) papiAttributeListGetInteger(list, NULL,
570 570 "job-id", &id);
571 - while (papiAttributeListToString(list, "\n\t", buffer, size)
571 + while (papiAttributeListToString(list, "\en\et", buffer, size)
572 572 != PAPI_OK)
573 573 buffer = realloc(buffer, size += BUFSIZ);
574 574
575 - printf("%s-%d:\n\t%s\n", name, id, buffer);
575 + printf("%s-%d:\en\et%s\n", name, id, buffer);
576 576 free(buffer);
577 577 }
578 578 } else
579 - printf("papiJobQuery(%s-%d): %s\n", pname, id,
579 + printf("papiJobQuery(%s-%d): %s\en", pname, id,
580 580 papiStatusString(status));
581 581
582 582 papiJobFree(job);
583 583 papiServiceDestroy(svc);
584 584
585 585 exit(0);
586 586 }
587 587 .fi
588 588 .in -2
589 589
590 590 .LP
591 591 \fBExample 3 \fRSubmit a job (stream).
592 592 .sp
593 593 .in +2
594 594 .nf
595 595 /*
596 596 * program to submit a job from standard input.
597 597 */
598 598 #include <stdio.h>
599 599 #include <stdlib.h>
600 600 #include <unistd.h>
601 601 #include <libintl.h>
602 602 #include <pwd.h>
603 603 #include <papi.h>
604 604
605 605 static int
606 606 authCB(papi_service_t svc, void *app_data)
607 607 {
608 608 char prompt[BUFSIZ];
609 609 char *user, *svc_name, *passphrase;
610 610
611 611 /* get the name of the service we are contacting */
612 612 if ((svc_name = papiServiceGetServiceName(svc)) == NULL)
613 613 return (-1);
614 614
615 615 /* find out who we are supposed to be */
616 616 if ((user = papiServiceGetUserName(svc)) == NULL) {
617 617 struct passwd *pw;
618 618
619 619 if ((pw = getpwuid(getuid())) != NULL)
620 620 user = pw->pw_name;
621 621 else
622 622 user = "nobody";
623 623 }
624 624
625 625 /* build the prompt string */
626 626 snprintf(prompt, sizeof (prompt),
627 627 gettext("passphrase for %s to access %s: "), user,
628 628 svc_name);
629 629
630 630 /* ask for the passphrase */
631 631 if ((passphrase = getpassphrase(prompt)) != NULL)
632 632 papiServiceSetPassword(svc, passphrase);
633 633
634 634 return (0);
635 635 }
636 636
637 637 /*ARGSUSED*/
638 638 int
639 639 main(int ac, char *av[])
640 640 {
641 641 papi_status_t status;
642 642 papi_service_t svc = NULL;
643 643 papi_stream_t stream = NULL;
644 644 papi_job_t job = NULL;
645 645 papi_attribute_t **attrs = NULL;
646 646 char *svc_name = NULL;
647 647 char *pname = "unknown";
648 648 int id = 0;
649 649 int c;
650 650 int rc;
651 651 char buf[BUFSIZ];
652 652
653 653 while ((c = getopt(ac, av, "s:p:")) != EOF)
654 654 switch (c) {
655 655 case 's':
656 656 svc_name = optarg;
↓ open down ↓ |
67 lines elided |
↑ open up ↑ |
657 657 break;
658 658 case 'p':
659 659 pname = optarg;
660 660 break;
661 661 }
662 662
663 663 status = papiServiceCreate(&svc, svc_name, NULL, NULL, authCB,
664 664 PAPI_ENCRYPT_NEVER, NULL);
665 665
666 666 if (status != PAPI_OK) {
667 - printf("papiServiceCreate(%s): %s\n", svc_name ? svc_name :
667 + printf("papiServiceCreate(%s): %s\en", svc_name ? svc_name :
668 668 "NULL", papiStatusString(status));
669 669 papiServiceDestroy(svc);
670 670 exit(1);
671 671 }
672 672
673 673 papiAttributeListAddInteger(&attrs, PAPI_ATTR_EXCL, "copies", 1);
674 674 papiAttributeListAddString(&attrs, PAPI_ATTR_EXCL,
675 675 "document-format", "application/octet-stream");
676 676 papiAttributeListAddString(&attrs, PAPI_ATTR_EXCL,
677 677 "job-title", "Standard Input");
678 678
679 679 status = papiJobStreamOpen(svc, pname, attrs, NULL, &stream);
680 680 while ((status == PAPI_OK) && ((rc = read(0, buf,
681 681 sizeof (buf))) > 0))
682 682 status = papiJobStreamWrite(svc, stream, buf, rc);
683 683
684 684 if (status == PAPI_OK)
685 685 status = papiJobStreamClose(svc, stream, &job);
686 686
687 687
688 688 if ((status == PAPI_OK) && (job != NULL)) {
689 689 papi_attribute_t **list = papiJobGetAttributeList(job);
690 690
691 691 if (list != NULL) {
692 692 char *name = "unknown";
693 693 int32_t id = 0;
694 694 char *buffer = NULL;
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
695 695 size_t size = 0;
696 696
697 697 (void) papiAttributeListGetString(list, NULL,
698 698 "printer-name", &name);
699 699 (void) papiAttributeListGetInteger(list, NULL,
700 700 "job-id", &id);
701 701 while (papiAttributeListToString(list, "\n\t", buffer, size)
702 702 != PAPI_OK)
703 703 buffer = realloc(buffer, size += BUFSIZ);
704 704
705 - printf("%s-%d:\n\t%s\n", name, id, buffer);
705 + printf("%s-%d:\en\t%s\en", name, id, buffer);
706 706 free(buffer);
707 707 }
708 708 } else
709 - printf("papiJobStream*(%s-%d): %s\n", pname, id,
709 + printf("papiJobStream*(%s-%d): %s\en", pname, id,
710 710 papiStatusString(status));
711 711
712 712 papiJobFree(job);
713 713 papiServiceDestroy(svc);
714 714
715 715 exit(0);
716 716 }
717 717 .fi
718 718 .in -2
719 719
720 720 .SH ATTRIBUTES
721 721 .sp
722 722 .LP
723 723 See \fBattributes\fR(5) for descriptions of the following attributes:
724 724 .sp
725 725
726 726 .sp
727 727 .TS
728 728 box;
729 729 c | c
730 730 l | l .
731 731 ATTRIBUTE TYPE ATTRIBUTE VALUE
732 732 _
733 733 Interface Stability Volatile
734 734 _
735 735 MT-Level Safe
736 736 .TE
737 737
738 738 .SH SEE ALSO
739 739 .sp
740 740 .LP
741 741 \fBlibpapi\fR(3LIB), \fBpapiAttributeListAddValue\fR(3PAPI),
742 742 \fBattributes\fR(5)
↓ open down ↓ |
23 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX