]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
f7faf1f5 | 2 | * "$Id: phpcups.c 5171 2006-02-25 08:44:43Z mike $" |
ef416fc2 | 3 | * |
4 | * Printing utilities for the Common UNIX Printing System (CUPS). | |
5 | * | |
b423cd4c | 6 | * Copyright 1997-2006 by Easy Software Products. |
ef416fc2 | 7 | * |
8 | * These coded instructions, statements, and computer programs are the | |
9 | * property of Easy Software Products and are protected by Federal | |
10 | * copyright law. Distribution and use rights are outlined in the file | |
11 | * "LICENSE.txt" which should have been included with this file. If this | |
12 | * file is missing or damaged please contact Easy Software Products | |
13 | * at: | |
14 | * | |
15 | * Attn: CUPS Licensing Information | |
16 | * Easy Software Products | |
17 | * 44141 Airport View Drive, Suite 204 | |
b423cd4c | 18 | * Hollywood, Maryland 20636 USA |
ef416fc2 | 19 | * |
20 | * Voice: (301) 373-9603 | |
21 | * EMail: cups-info@cups.org | |
b423cd4c | 22 | * WWW: http://www.cups.org/ |
23 | * | |
24 | * Contents: | |
25 | * | |
ef416fc2 | 26 | */ |
27 | ||
ef416fc2 | 28 | /* |
29 | * Include necessary headers... | |
30 | */ | |
31 | ||
ef416fc2 | 32 | #include <cups/string.h> |
b423cd4c | 33 | #include "php.h" |
34 | #include "php_ini.h" | |
35 | #include "ext/standard/info.h" | |
36 | #include "phpcups.h" | |
ef416fc2 | 37 | |
38 | ||
b423cd4c | 39 | /* |
40 | * PHP function list... | |
ef416fc2 | 41 | */ |
42 | ||
b423cd4c | 43 | function_entry phpcups_functions[] = |
44 | { | |
45 | PHP_FE(cups_cancel_job, NULL) | |
46 | PHP_FE(cups_get_dests, NULL) | |
47 | PHP_FE(cups_get_jobs, NULL) | |
48 | PHP_FE(cups_last_error, NULL) | |
49 | PHP_FE(cups_last_error_string, NULL) | |
50 | PHP_FE(cups_print_file, NULL) | |
51 | PHP_FE(cups_print_files, NULL) | |
52 | {NULL, NULL, NULL} | |
53 | }; | |
ef416fc2 | 54 | |
55 | ||
56 | /* | |
b423cd4c | 57 | * PHP module info... |
ef416fc2 | 58 | */ |
59 | ||
b423cd4c | 60 | zend_module_entry phpcups_module_entry = |
61 | { | |
62 | STANDARD_MODULE_HEADER, | |
63 | "phpcups", | |
64 | phpcups_functions, | |
65 | PHP_MINIT(phpcups), | |
66 | NULL, | |
67 | NULL, | |
68 | NULL, | |
69 | NULL, | |
70 | CUPS_SVERSION, | |
71 | STANDARD_MODULE_PROPERTIES | |
ef416fc2 | 72 | }; |
73 | ||
74 | ||
ef416fc2 | 75 | ZEND_GET_MODULE(phpcups) |
ef416fc2 | 76 | |
77 | ||
b423cd4c | 78 | /* |
79 | * 'cups_convert_options()' - Convert a PHP options array to a CUPS options array. | |
80 | */ | |
ef416fc2 | 81 | |
b423cd4c | 82 | static int /* O - Number of options */ |
83 | cups_convert_options( | |
84 | zval *optionsobj, /* I - Options array object */ | |
85 | cups_option_t **options) /* O - Options */ | |
ef416fc2 | 86 | { |
b423cd4c | 87 | int num_options; /* Number of options */ |
88 | HashTable *ht; /* Option array hash table */ | |
89 | Bucket *current; /* Current element in array */ | |
ef416fc2 | 90 | |
91 | ||
b423cd4c | 92 | ht = Z_ARRVAL_P(optionsobj); |
93 | num_options = 0; | |
ef416fc2 | 94 | |
b423cd4c | 95 | for (current = ht->pListHead; current; current = current->pListNext) |
96 | num_options = cupsAddOption(current->arKey, | |
97 | Z_STRVAL_P(((zval *)current->pDataPtr)), | |
98 | num_options, options); | |
ef416fc2 | 99 | |
b423cd4c | 100 | return (num_options); |
ef416fc2 | 101 | } |
102 | ||
ef416fc2 | 103 | |
b423cd4c | 104 | /* |
105 | * 'zm_startup_phpcups()' - Initialize the CUPS module. | |
106 | */ | |
ef416fc2 | 107 | |
b423cd4c | 108 | PHP_MINIT_FUNCTION(phpcups) |
ef416fc2 | 109 | { |
b423cd4c | 110 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_LOCAL", CUPS_PRINTER_LOCAL, CONST_CS); |
111 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_CLASS", CUPS_PRINTER_CLASS, CONST_CS); | |
112 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_REMOTE", CUPS_PRINTER_REMOTE, CONST_CS); | |
113 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_BW", CUPS_PRINTER_BW, CONST_CS); | |
114 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_COLOR", CUPS_PRINTER_COLOR, CONST_CS); | |
115 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_DUPLEX", CUPS_PRINTER_DUPLEX, CONST_CS); | |
116 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_STAPLE", CUPS_PRINTER_STAPLE, CONST_CS); | |
117 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_COPIES", CUPS_PRINTER_COPIES, CONST_CS); | |
118 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_COLLATE", CUPS_PRINTER_COLLATE, CONST_CS); | |
119 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_PUNCH", CUPS_PRINTER_PUNCH, CONST_CS); | |
120 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_COVER", CUPS_PRINTER_COVER, CONST_CS); | |
121 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_BIND", CUPS_PRINTER_BIND, CONST_CS); | |
122 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_SORT", CUPS_PRINTER_SORT, CONST_CS); | |
123 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_SMALL", CUPS_PRINTER_SMALL, CONST_CS); | |
124 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_MEDIUM", CUPS_PRINTER_MEDIUM, CONST_CS); | |
125 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_LARGE", CUPS_PRINTER_LARGE, CONST_CS); | |
126 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_VARIABLE", CUPS_PRINTER_VARIABLE, CONST_CS); | |
127 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_IMPLICIT", CUPS_PRINTER_IMPLICIT, CONST_CS); | |
128 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_DEFAULT", CUPS_PRINTER_DEFAULT, CONST_CS); | |
129 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_FAX", CUPS_PRINTER_FAX, CONST_CS); | |
130 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_REJECTING", CUPS_PRINTER_REJECTING, CONST_CS); | |
131 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_DELETE", CUPS_PRINTER_DELETE, CONST_CS); | |
132 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_NOT_SHARED", CUPS_PRINTER_NOT_SHARED, CONST_CS); | |
133 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_AUTHENTICATED", CUPS_PRINTER_AUTHENTICATED, CONST_CS); | |
134 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_COMMANDS", CUPS_PRINTER_COMMANDS, CONST_CS); | |
135 | REGISTER_LONG_CONSTANT("CUPS_PRINTER_OPTIONS", CUPS_PRINTER_OPTIONS, CONST_CS); | |
136 | ||
137 | REGISTER_LONG_CONSTANT("IPP_OK", IPP_OK, CONST_CS); | |
138 | REGISTER_LONG_CONSTANT("IPP_OK_SUBST", IPP_OK_SUBST, CONST_CS); | |
139 | REGISTER_LONG_CONSTANT("IPP_OK_CONFLICT", IPP_OK_CONFLICT, CONST_CS); | |
140 | REGISTER_LONG_CONSTANT("IPP_OK_IGNORED_SUBSCRIPTIONS", IPP_OK_IGNORED_SUBSCRIPTIONS, CONST_CS); | |
141 | REGISTER_LONG_CONSTANT("IPP_OK_IGNORED_NOTIFICATIONS", IPP_OK_IGNORED_NOTIFICATIONS, CONST_CS); | |
142 | REGISTER_LONG_CONSTANT("IPP_OK_TOO_MANY_EVENTS", IPP_OK_TOO_MANY_EVENTS, CONST_CS); | |
143 | REGISTER_LONG_CONSTANT("IPP_OK_BUT_CANCEL_SUBSCRIPTION", IPP_OK_BUT_CANCEL_SUBSCRIPTION, CONST_CS); | |
144 | REGISTER_LONG_CONSTANT("IPP_OK_EVENTS_COMPLETE", IPP_OK_EVENTS_COMPLETE, CONST_CS); | |
145 | REGISTER_LONG_CONSTANT("IPP_REDIRECTION_OTHER_SITE", IPP_REDIRECTION_OTHER_SITE, CONST_CS); | |
146 | REGISTER_LONG_CONSTANT("IPP_BAD_REQUEST", IPP_BAD_REQUEST, CONST_CS); | |
147 | REGISTER_LONG_CONSTANT("IPP_FORBIDDEN", IPP_FORBIDDEN, CONST_CS); | |
148 | REGISTER_LONG_CONSTANT("IPP_NOT_AUTHENTICATED", IPP_NOT_AUTHENTICATED, CONST_CS); | |
149 | REGISTER_LONG_CONSTANT("IPP_NOT_AUTHORIZED", IPP_NOT_AUTHORIZED, CONST_CS); | |
150 | REGISTER_LONG_CONSTANT("IPP_NOT_POSSIBLE", IPP_NOT_POSSIBLE, CONST_CS); | |
151 | REGISTER_LONG_CONSTANT("IPP_TIMEOUT", IPP_TIMEOUT, CONST_CS); | |
152 | REGISTER_LONG_CONSTANT("IPP_NOT_FOUND", IPP_NOT_FOUND, CONST_CS); | |
153 | REGISTER_LONG_CONSTANT("IPP_GONE", IPP_GONE, CONST_CS); | |
154 | REGISTER_LONG_CONSTANT("IPP_REQUEST_ENTITY", IPP_REQUEST_ENTITY, CONST_CS); | |
155 | REGISTER_LONG_CONSTANT("IPP_REQUEST_VALUE", IPP_REQUEST_VALUE, CONST_CS); | |
156 | REGISTER_LONG_CONSTANT("IPP_DOCUMENT_FORMAT", IPP_DOCUMENT_FORMAT, CONST_CS); | |
157 | REGISTER_LONG_CONSTANT("IPP_ATTRIBUTES", IPP_ATTRIBUTES, CONST_CS); | |
158 | REGISTER_LONG_CONSTANT("IPP_URI_SCHEME", IPP_URI_SCHEME, CONST_CS); | |
159 | REGISTER_LONG_CONSTANT("IPP_CHARSET", IPP_CHARSET, CONST_CS); | |
160 | REGISTER_LONG_CONSTANT("IPP_CONFLICT", IPP_CONFLICT, CONST_CS); | |
161 | REGISTER_LONG_CONSTANT("IPP_COMPRESSION_NOT_SUPPORTED", IPP_COMPRESSION_NOT_SUPPORTED, CONST_CS); | |
162 | REGISTER_LONG_CONSTANT("IPP_COMPRESSION_ERROR", IPP_COMPRESSION_ERROR, CONST_CS); | |
163 | REGISTER_LONG_CONSTANT("IPP_DOCUMENT_FORMAT_ERROR", IPP_DOCUMENT_FORMAT_ERROR, CONST_CS); | |
164 | REGISTER_LONG_CONSTANT("IPP_DOCUMENT_ACCESS_ERROR", IPP_DOCUMENT_ACCESS_ERROR, CONST_CS); | |
165 | REGISTER_LONG_CONSTANT("IPP_ATTRIBUTES_NOT_SETTABLE", IPP_ATTRIBUTES_NOT_SETTABLE, CONST_CS); | |
166 | REGISTER_LONG_CONSTANT("IPP_IGNORED_ALL_SUBSCRIPTIONS", IPP_IGNORED_ALL_SUBSCRIPTIONS, CONST_CS); | |
167 | REGISTER_LONG_CONSTANT("IPP_TOO_MANY_SUBSCRIPTIONS", IPP_TOO_MANY_SUBSCRIPTIONS, CONST_CS); | |
168 | REGISTER_LONG_CONSTANT("IPP_IGNORED_ALL_NOTIFICATIONS", IPP_IGNORED_ALL_NOTIFICATIONS, CONST_CS); | |
169 | REGISTER_LONG_CONSTANT("IPP_PRINT_SUPPORT_FILE_NOT_FOUND", IPP_PRINT_SUPPORT_FILE_NOT_FOUND, CONST_CS); | |
170 | REGISTER_LONG_CONSTANT("IPP_INTERNAL_ERROR", IPP_INTERNAL_ERROR, CONST_CS); | |
171 | REGISTER_LONG_CONSTANT("IPP_OPERATION_NOT_SUPPORTED", IPP_OPERATION_NOT_SUPPORTED, CONST_CS); | |
172 | REGISTER_LONG_CONSTANT("IPP_SERVICE_UNAVAILABLE", IPP_SERVICE_UNAVAILABLE, CONST_CS); | |
173 | REGISTER_LONG_CONSTANT("IPP_VERSION_NOT_SUPPORTED", IPP_VERSION_NOT_SUPPORTED, CONST_CS); | |
174 | REGISTER_LONG_CONSTANT("IPP_DEVICE_ERROR", IPP_DEVICE_ERROR, CONST_CS); | |
175 | REGISTER_LONG_CONSTANT("IPP_TEMPORARY_ERROR", IPP_TEMPORARY_ERROR, CONST_CS); | |
176 | REGISTER_LONG_CONSTANT("IPP_NOT_ACCEPTING", IPP_NOT_ACCEPTING, CONST_CS); | |
177 | REGISTER_LONG_CONSTANT("IPP_PRINTER_BUSY", IPP_PRINTER_BUSY, CONST_CS); | |
178 | REGISTER_LONG_CONSTANT("IPP_ERROR_JOB_CANCELLED", IPP_ERROR_JOB_CANCELLED, CONST_CS); | |
179 | REGISTER_LONG_CONSTANT("IPP_MULTIPLE_JOBS_NOT_SUPPORTED", IPP_MULTIPLE_JOBS_NOT_SUPPORTED, CONST_CS); | |
180 | REGISTER_LONG_CONSTANT("IPP_PRINTER_IS_DEACTIVATED", IPP_PRINTER_IS_DEACTIVATED, CONST_CS); | |
181 | ||
182 | return (SUCCESS); | |
ef416fc2 | 183 | } |
184 | ||
b423cd4c | 185 | /* |
186 | * 'zif_cups_cancel_job()' - Cancel a job. | |
187 | */ | |
ef416fc2 | 188 | |
b423cd4c | 189 | PHP_FUNCTION(cups_cancel_job) |
ef416fc2 | 190 | { |
b423cd4c | 191 | char *dest; /* Destination */ |
192 | int dest_len, /* Length of destination */ | |
193 | id; /* Job ID */ | |
ef416fc2 | 194 | |
ef416fc2 | 195 | |
b423cd4c | 196 | if (ZEND_NUM_ARGS() != 2 || |
197 | zend_parse_parameters(2, "sl", &dest, &dest_len, &id)) | |
198 | { | |
199 | WRONG_PARAM_COUNT; | |
200 | } | |
ef416fc2 | 201 | |
b423cd4c | 202 | RETURN_LONG(cupsCancelJob(dest, id)); |
ef416fc2 | 203 | } |
ef416fc2 | 204 | |
205 | ||
206 | /* | |
b423cd4c | 207 | * 'zif_cups_get_dests()' - . |
ef416fc2 | 208 | */ |
ef416fc2 | 209 | |
b423cd4c | 210 | PHP_FUNCTION(cups_get_dests) |
211 | { | |
212 | int i, j, /* Looping vars */ | |
213 | num_dests; /* Number of destinations */ | |
214 | cups_dest_t *dests, /* Destinations */ | |
215 | *dest; /* Current destination */ | |
216 | cups_option_t *option; /* Current option */ | |
217 | zval *destobj, /* Destination object */ | |
218 | *optionsobj; /* Options object */ | |
ef416fc2 | 219 | |
ef416fc2 | 220 | |
b423cd4c | 221 | if (ZEND_NUM_ARGS() != 0) |
222 | { | |
223 | WRONG_PARAM_COUNT; | |
224 | } | |
ef416fc2 | 225 | |
b423cd4c | 226 | if ((num_dests = cupsGetDests(&dests)) <= 0) |
227 | { | |
228 | RETURN_NULL(); | |
229 | } | |
ef416fc2 | 230 | |
b423cd4c | 231 | if (array_init(return_value) == SUCCESS) |
232 | { | |
233 | for (i = 0, dest = dests; i < num_dests; i ++, dest ++) | |
ef416fc2 | 234 | { |
b423cd4c | 235 | MAKE_STD_ZVAL(destobj); |
ef416fc2 | 236 | |
b423cd4c | 237 | if (object_init(destobj) == SUCCESS) |
ef416fc2 | 238 | { |
b423cd4c | 239 | /* |
240 | * Add properties to the destination for each of the cups_dest_t | |
241 | * members... | |
242 | */ | |
ef416fc2 | 243 | |
b423cd4c | 244 | add_property_string(destobj, "name", dest->name, 1); |
245 | add_property_string(destobj, "instance", | |
246 | dest->instance ? dest->instance : "", 1); | |
247 | add_property_long(destobj, "is_default", dest->is_default); | |
ef416fc2 | 248 | |
b423cd4c | 249 | /* |
250 | * Create an associative array for the options... | |
251 | */ | |
ef416fc2 | 252 | |
b423cd4c | 253 | MAKE_STD_ZVAL(optionsobj); |
ef416fc2 | 254 | |
b423cd4c | 255 | if (array_init(optionsobj) == SUCCESS) |
256 | { | |
257 | for (j = 0, option = dest->options; | |
258 | j < dest->num_options; | |
259 | j ++, option ++) | |
260 | add_assoc_string(optionsobj, option->name, option->value, 1); | |
ef416fc2 | 261 | |
b423cd4c | 262 | add_property_zval(destobj, "options", optionsobj); |
263 | } | |
ef416fc2 | 264 | |
b423cd4c | 265 | add_index_zval(return_value, i, destobj); |
ef416fc2 | 266 | } |
267 | } | |
b423cd4c | 268 | } |
ef416fc2 | 269 | |
b423cd4c | 270 | cupsFreeDests(num_dests, dests); |
ef416fc2 | 271 | } |
272 | ||
273 | ||
ef416fc2 | 274 | /* |
b423cd4c | 275 | * 'zif_cups_get_jobs()' - Get a list of jobs. |
ef416fc2 | 276 | */ |
ef416fc2 | 277 | |
b423cd4c | 278 | PHP_FUNCTION(cups_get_jobs) |
279 | { | |
280 | char *dest; /* Destination */ | |
281 | int dest_len, /* Length of destination */ | |
282 | myjobs, /* Only show my jobs? */ | |
283 | completed; /* Show completed jobs? */ | |
284 | int i, /* Looping var */ | |
285 | num_jobs; /* Number of jobs */ | |
286 | cups_job_t *jobs, /* Jobs */ | |
287 | *job; /* Current job */ | |
288 | zval *jobobj; /* Job object */ | |
ef416fc2 | 289 | |
ef416fc2 | 290 | |
ef416fc2 | 291 | |
ef416fc2 | 292 | |
b423cd4c | 293 | if (ZEND_NUM_ARGS() != 3 || |
294 | zend_parse_parameters(3, "sll", &dest, &dest_len, &myjobs, &completed)) | |
295 | { | |
296 | WRONG_PARAM_COUNT; | |
297 | } | |
ef416fc2 | 298 | |
b423cd4c | 299 | if (!*dest) |
300 | dest = NULL; | |
ef416fc2 | 301 | |
b423cd4c | 302 | if ((num_jobs = cupsGetJobs(&jobs, dest, myjobs, completed)) <= 0) |
303 | { | |
304 | RETURN_NULL(); | |
305 | } | |
ef416fc2 | 306 | |
b423cd4c | 307 | if (array_init(return_value) == SUCCESS) |
308 | { | |
309 | for (i = 0, job = jobs; i < num_jobs; i ++, job ++) | |
ef416fc2 | 310 | { |
b423cd4c | 311 | MAKE_STD_ZVAL(jobobj); |
ef416fc2 | 312 | |
b423cd4c | 313 | if (object_init(jobobj) == SUCCESS) |
ef416fc2 | 314 | { |
b423cd4c | 315 | /* |
316 | * Add properties to the job for each of the cups_job_t | |
317 | * members... | |
318 | */ | |
319 | ||
320 | add_property_long(jobobj, "id", job->id); | |
321 | add_property_string(jobobj, "dest", job->dest, 1); | |
322 | add_property_string(jobobj, "title", job->title, 1); | |
323 | add_property_string(jobobj, "user", job->user, 1); | |
324 | add_property_string(jobobj, "format", job->format, 1); | |
325 | add_property_long(jobobj, "state", job->state); | |
326 | add_property_long(jobobj, "size", job->size); | |
327 | add_property_long(jobobj, "priority", job->priority); | |
328 | add_property_long(jobobj, "completed_time", job->completed_time); | |
329 | add_property_long(jobobj, "creation_time", job->creation_time); | |
330 | add_property_long(jobobj, "processing_time", job->processing_time); | |
331 | ||
332 | add_index_zval(return_value, i, jobobj); | |
ef416fc2 | 333 | } |
334 | } | |
b423cd4c | 335 | } |
ef416fc2 | 336 | |
b423cd4c | 337 | cupsFreeJobs(num_jobs, jobs); |
338 | } | |
ef416fc2 | 339 | |
340 | ||
341 | /* | |
b423cd4c | 342 | * 'zif_cups_last_error()' - Return the last IPP status code. |
ef416fc2 | 343 | */ |
b423cd4c | 344 | |
ef416fc2 | 345 | PHP_FUNCTION(cups_last_error) |
346 | { | |
b423cd4c | 347 | if (ZEND_NUM_ARGS() != 0) |
ef416fc2 | 348 | { |
b423cd4c | 349 | WRONG_PARAM_COUNT; |
ef416fc2 | 350 | } |
ef416fc2 | 351 | |
b423cd4c | 352 | RETURN_LONG(cupsLastError()); |
ef416fc2 | 353 | } |
354 | ||
355 | ||
ef416fc2 | 356 | /* |
b423cd4c | 357 | * 'zif_cups_last_error_string()' - Return the last IPP status-message. |
ef416fc2 | 358 | */ |
ef416fc2 | 359 | |
b423cd4c | 360 | PHP_FUNCTION(cups_last_error_string) |
ef416fc2 | 361 | { |
b423cd4c | 362 | if (ZEND_NUM_ARGS() != 0) |
ef416fc2 | 363 | { |
b423cd4c | 364 | WRONG_PARAM_COUNT; |
ef416fc2 | 365 | } |
ef416fc2 | 366 | |
b423cd4c | 367 | RETURN_STRING((char *)cupsLastErrorString(), 1); |
ef416fc2 | 368 | } |
369 | ||
370 | ||
ef416fc2 | 371 | /* |
b423cd4c | 372 | * 'zif_cups_print_file()' - Print a single file. |
ef416fc2 | 373 | */ |
ef416fc2 | 374 | |
b423cd4c | 375 | PHP_FUNCTION(cups_print_file) |
ef416fc2 | 376 | { |
b423cd4c | 377 | char *dest; /* Destination */ |
378 | int dest_len; /* Length of destination */ | |
379 | char *filename; /* Filename */ | |
380 | int filename_len; /* Length of filename */ | |
381 | char *title; /* Title */ | |
382 | int title_len; /* Length of title */ | |
383 | zval *optionsobj; /* Array of options */ | |
384 | int num_options; /* Number of options */ | |
385 | cups_option_t *options; /* Options */ | |
386 | int id; /* Job ID */ | |
387 | ||
388 | ||
389 | if (ZEND_NUM_ARGS() != 4 || | |
390 | zend_parse_parameters(4, "sssa", &dest, &dest_len, | |
391 | &filename, &filename_len, | |
392 | &title, &title_len, &optionsobj)) | |
ef416fc2 | 393 | { |
b423cd4c | 394 | WRONG_PARAM_COUNT; |
ef416fc2 | 395 | } |
ef416fc2 | 396 | |
b423cd4c | 397 | num_options = cups_convert_options(optionsobj, &options); |
ef416fc2 | 398 | |
b423cd4c | 399 | id = cupsPrintFile(dest, filename, title, num_options, options); |
ef416fc2 | 400 | |
b423cd4c | 401 | cupsFreeOptions(num_options, options); |
ef416fc2 | 402 | |
b423cd4c | 403 | RETURN_LONG(id); |
ef416fc2 | 404 | } |
405 | ||
406 | ||
b423cd4c | 407 | /* |
408 | * 'zif_cups_print_files()' - Print multiple files. | |
409 | */ | |
ef416fc2 | 410 | |
b423cd4c | 411 | PHP_FUNCTION(cups_print_files) |
ef416fc2 | 412 | { |
b423cd4c | 413 | char *dest; /* Destination */ |
414 | int dest_len; /* Length of destination */ | |
415 | zval *filesobj; /* Files array */ | |
416 | int num_files; /* Number of files */ | |
417 | const char *files[1000]; /* Files */ | |
418 | char *title; /* Title */ | |
419 | int title_len; /* Length of title */ | |
420 | zval *optionsobj; /* Array of options */ | |
421 | int num_options; /* Number of options */ | |
422 | cups_option_t *options; /* Options */ | |
423 | HashTable *ht2; /* Option array hash table */ | |
424 | Bucket *current; /* Current element in array */ | |
425 | int id; /* Job ID */ | |
426 | ||
427 | ||
428 | if (ZEND_NUM_ARGS() != 4 || | |
429 | zend_parse_parameters(4, "sasa", &dest, &dest_len, &filesobj, | |
430 | &title, &title_len, &optionsobj)) | |
ef416fc2 | 431 | { |
b423cd4c | 432 | WRONG_PARAM_COUNT; |
ef416fc2 | 433 | } |
434 | ||
b423cd4c | 435 | ht2 = Z_ARRVAL_P(filesobj); |
436 | num_files = 0; | |
ef416fc2 | 437 | |
b423cd4c | 438 | for (current = ht2->pListHead; current; current = current->pListNext) |
ef416fc2 | 439 | { |
b423cd4c | 440 | files[num_files ++] = Z_STRVAL_P(((zval *)current->pDataPtr)); |
ef416fc2 | 441 | |
b423cd4c | 442 | if (num_files >= (int)(sizeof(files) / sizeof(files[0]))) |
443 | break; | |
ef416fc2 | 444 | } |
ef416fc2 | 445 | |
b423cd4c | 446 | num_options = cups_convert_options(optionsobj, &options); |
ef416fc2 | 447 | |
b423cd4c | 448 | id = cupsPrintFiles(dest, num_files, files, title, num_options, options); |
ef416fc2 | 449 | |
b423cd4c | 450 | cupsFreeOptions(num_options, options); |
ef416fc2 | 451 | |
b423cd4c | 452 | RETURN_LONG(id); |
ef416fc2 | 453 | } |
454 | ||
455 | ||
ef416fc2 | 456 | /* |
f7faf1f5 | 457 | * End of "$Id: phpcups.c 5171 2006-02-25 08:44:43Z mike $". |
ef416fc2 | 458 | */ |