• Home
  • Raw
  • Download

Lines Matching +full:data +full:- +full:uri +full:- +full:to +full:- +full:buffer

2  * User-defined destination (and option) support for CUPS.
4 * Copyright © 2007-2019 by Apple Inc.
5 * Copyright © 1997-2007 by Easy Software Products.
15 #include "cups-private.h"
16 #include "debug-internal.h"
32 # include <avahi-client/client.h>
33 # include <avahi-client/lookup.h>
34 # include <avahi-common/simple-watch.h>
35 # include <avahi-common/domain.h>
36 # include <avahi-common/error.h>
37 # include <avahi-common/malloc.h>
82 typedef struct _cups_dnssd_data_s /* Enumeration data */
89 int got_data; /* Did we get data? */
93 void *user_data; /* User data pointer */
118 typedef struct _cups_dnssd_resolve_s /* Data for resolving URI */
120 int *cancel; /* Pointer to "cancel" variable */
189 _cups_dnssd_data_t *data);
191 cups_dnssd_get_device(_cups_dnssd_data_t *data,
218 static const char *cups_dnssd_resolve(cups_dest_t *dest, const char *uri,
230 static int cups_get_cb(_cups_getdata_t *data, unsigned flags, cups_dest_t *dest);
234 static char *cups_make_string(ipp_attribute_t *attr, char *buffer,
236 static int cups_name_cb(_cups_namedata_t *data, unsigned flags, cups_dest_t *dest);
241 * 'cupsAddDest()' - Add a destination to the list of destinations.
243 * This function cannot be used to add a new class or printer queue,
251 * Use the @link cupsSaveDests@ function to save the updated list of
252 * destinations to the user's lpoptions file.
255 int /* O - New number of destinations */
256 cupsAddDest(const char *name, /* I - Destination name */ in cupsAddDest()
257 const char *instance, /* I - Instance name or @code NULL@ for none/primary */ in cupsAddDest()
258 int num_dests, /* I - Number of destinations */ in cupsAddDest()
259 cups_dest_t **dests) /* IO - Destinations */ in cupsAddDest()
289 if (instance && parent && parent->num_options > 0) in cupsAddDest()
295 dest->options = calloc(sizeof(cups_option_t), (size_t)parent->num_options); in cupsAddDest()
297 if (dest->options) in cupsAddDest()
299 dest->num_options = parent->num_options; in cupsAddDest()
301 for (i = dest->num_options, doption = dest->options, in cupsAddDest()
302 poption = parent->options; in cupsAddDest()
304 i --, doption ++, poption ++) in cupsAddDest()
306 doption->name = _cupsStrRetain(poption->name); in cupsAddDest()
307 doption->value = _cupsStrRetain(poption->value); in cupsAddDest()
319 * '_cupsAppleCopyDefaultPaperID()' - Get the default paper ID.
322 CFStringRef /* O - Default paper ID */
331 * '_cupsAppleCopyDefaultPrinter()' - Get the default printer at this location.
334 CFStringRef /* O - Default printer name */
344 * Use location-based defaults only if "use last printer" is selected in the in _cupsAppleCopyDefaultPrinter()
361 DEBUG_puts("1_cupsAppleCopyDefaultPrinter: Unable to get current " in _cupsAppleCopyDefaultPrinter()
373 * Missing or bad location array, so no location-based default... in _cupsAppleCopyDefaultPrinter()
402 * '_cupsAppleGetUseLastPrinter()' - Get whether to use the last used printer.
405 int /* O - 1 to use last printer, 0 otherwise */
426 * '_cupsAppleSetDefaultPaperID()' - Set the default paper id.
431 CFStringRef name) /* I - New paper ID */ in _cupsAppleSetDefaultPaperID()
443 * '_cupsAppleSetDefaultPrinter()' - Set the default printer for this location.
448 CFStringRef name) /* I - Default printer/class name */ in _cupsAppleSetDefaultPrinter()
465 DEBUG_puts("1_cupsAppleSetDefaultPrinter: Unable to get current network..."); in _cupsAppleSetDefaultPrinter()
478 locindex = -1; in _cupsAppleSetDefaultPrinter()
484 * Need to change the locations array... in _cupsAppleSetDefaultPrinter()
514 * Limit the number of locations to 10... in _cupsAppleSetDefaultPrinter()
552 * '_cupsAppleSetUseLastPrinter()' - Set whether to use the last used printer.
557 int uselast) /* O - 1 to use last printer, 0 otherwise */ in _cupsAppleSetUseLastPrinter()
572 * 'cupsConnectDest()' - Open a connection to the destination.
574 * Connect to the destination, returning a new @code http_t@ connection object
575 * and optionally the resource path to use for the destination. These calls
577 * pointed to by "cancel" is non-zero, or the callback function (or block)
582 * for the "flags" argument to connect directly to the device associated with
583 * the destination. Otherwise, the connection is made to the CUPS scheduler
589 http_t * /* O - Connection to destination or @code NULL@ */
591 cups_dest_t *dest, /* I - Destination */ in cupsConnectDest()
592 unsigned flags, /* I - Connection flags */ in cupsConnectDest()
593 int msec, /* I - Timeout in milliseconds */ in cupsConnectDest()
594 int *cancel, /* I - Pointer to "cancel" variable */ in cupsConnectDest()
595 char *resource, /* I - Resource buffer */ in cupsConnectDest()
596 size_t resourcesize, /* I - Size of resource buffer */ in cupsConnectDest()
597 cups_dest_cb_t cb, /* I - Callback function */ in cupsConnectDest()
598 void *user_data) /* I - User data pointer */ in cupsConnectDest()
600 const char *uri; /* Printer URI */ in cupsConnectDest() local
601 char scheme[32], /* URI scheme */ in cupsConnectDest()
604 tempresource[1024]; /* Temporary resource buffer */ in cupsConnectDest()
607 http_encryption_t encryption; /* Encryption to use */ in cupsConnectDest()
609 http_t *http; /* Connection to server */ in cupsConnectDest()
612 …er_data=%p)", (void *)dest, flags, msec, (void *)cancel, cancel ? *cancel : -1, resource, CUPS_LLC… in cupsConnectDest()
634 * Grab the printer URI... in cupsConnectDest()
639 if ((uri = cupsGetOption("device-uri", dest->num_options, dest->options)) != NULL) in cupsConnectDest()
642 if (strstr(uri, "._tcp")) in cupsConnectDest()
643 uri = cups_dnssd_resolve(dest, uri, msec, cancel, cb, user_data); in cupsConnectDest()
647 else if ((uri = cupsGetOption("printer-uri-supported", dest->num_options, dest->options)) == NULL) in cupsConnectDest()
649 if ((uri = cupsGetOption("device-uri", dest->num_options, dest->options)) != NULL) in cupsConnectDest()
652 if (strstr(uri, "._tcp")) in cupsConnectDest()
653 uri = cups_dnssd_resolve(dest, uri, msec, cancel, cb, user_data); in cupsConnectDest()
657 if (uri) in cupsConnectDest()
658uri = _cupsCreateDest(dest->name, cupsGetOption("printer-info", dest->num_options, dest->options),… in cupsConnectDest()
660 if (uri) in cupsConnectDest()
662 …dest->num_options = cupsAddOption("printer-uri-supported", uri, dest->num_options, &dest->options); in cupsConnectDest()
664 uri = cupsGetOption("printer-uri-supported", dest->num_options, dest->options); in cupsConnectDest()
668 if (!uri) in cupsConnectDest()
678 if (httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme), in cupsConnectDest()
682 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad printer-uri."), 1); in cupsConnectDest()
719 * Create the HTTP object pointing to the server referenced by the URI... in cupsConnectDest()
761 * 'cupsConnectDestBlock()' - Open a connection to the destination.
763 * Connect to the destination, returning a new @code http_t@ connection object
764 * and optionally the resource path to use for the destination. These calls
766 * pointed to by "cancel" is non-zero, or the block returns 0. The caller is
770 * for the "flags" argument to connect directly to the device associated with
771 * the destination. Otherwise, the connection is made to the CUPS scheduler
777 http_t * /* O - Connection to destination or @code NULL@ */
779 cups_dest_t *dest, /* I - Destination */ in cupsConnectDestBlock()
780 unsigned flags, /* I - Connection flags */ in cupsConnectDestBlock()
781 int msec, /* I - Timeout in milliseconds */ in cupsConnectDestBlock()
782 int *cancel, /* I - Pointer to "cancel" variable */ in cupsConnectDestBlock()
783 char *resource, /* I - Resource buffer */ in cupsConnectDestBlock()
784 size_t resourcesize, /* I - Size of resource buffer */ in cupsConnectDestBlock()
785 cups_dest_block_t block) /* I - Callback block */ in cupsConnectDestBlock()
794 * 'cupsCopyDest()' - Copy a destination.
796 * Make a copy of the destination to an array of destinations (or just a single
797 * copy) - for use with the cupsEnumDests* functions. The caller is responsible
803 int /* O - New number of destinations */
804 cupsCopyDest(cups_dest_t *dest, /* I - Destination to copy */ in cupsCopyDest()
805 int num_dests, /* I - Number of destinations */ in cupsCopyDest()
806 cups_dest_t **dests) /* IO - Destination array */ in cupsCopyDest()
825 if ((new_dest = cupsGetDest(dest->name, dest->instance, num_dests, in cupsCopyDest()
829 * Protect against copying destination to itself... in cupsCopyDest()
839 cupsFreeOptions(new_dest->num_options, new_dest->options); in cupsCopyDest()
841 new_dest->num_options = 0; in cupsCopyDest()
842 new_dest->options = NULL; in cupsCopyDest()
845 new_dest = cups_add_dest(dest->name, dest->instance, &num_dests, dests); in cupsCopyDest()
849 new_dest->is_default = dest->is_default; in cupsCopyDest()
851 if ((new_dest->options = calloc(sizeof(cups_option_t), (size_t)dest->num_options)) == NULL) in cupsCopyDest()
852 return (cupsRemoveDest(dest->name, dest->instance, num_dests, dests)); in cupsCopyDest()
854 new_dest->num_options = dest->num_options; in cupsCopyDest()
856 for (i = dest->num_options, option = dest->options, in cupsCopyDest()
857 new_option = new_dest->options; in cupsCopyDest()
859 i --, option ++, new_option ++) in cupsCopyDest()
861 new_option->name = _cupsStrRetain(option->name); in cupsCopyDest()
862 new_option->value = _cupsStrRetain(option->value); in cupsCopyDest()
871 * '_cupsCreateDest()' - Create a local (temporary) queue.
874 char * /* O - Printer URI or @code NULL@ on error */
875 _cupsCreateDest(const char *name, /* I - Printer name */ in _cupsCreateDest()
876 const char *info, /* I - Printer description of @code NULL@ */ in _cupsCreateDest()
877 const char *device_id, /* I - 1284 Device ID or @code NULL@ */ in _cupsCreateDest()
878 const char *device_uri, /* I - Device URI */ in _cupsCreateDest()
879 char *uri, /* I - Printer URI buffer */ in _cupsCreateDest() argument
880 size_t urisize) /* I - Size of URI buffer */ in _cupsCreateDest()
882 http_t *http; /* Connection to server */ in _cupsCreateDest()
883 ipp_t *request, /* CUPS-Create-Local-Printer request */ in _cupsCreateDest()
884 *response; /* CUPS-Create-Local-Printer response */ in _cupsCreateDest()
885 ipp_attribute_t *attr; /* printer-uri-supported attribute */ in _cupsCreateDest()
887 /* printer-state value */ in _cupsCreateDest()
890 if (!name || !device_uri || !uri || urisize < 32) in _cupsCreateDest()
898 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, "ipp://localhost/"); in _cupsCreateDest()
899 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser()); in _cupsCreateDest()
901 ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL, device_uri); in _cupsCreateDest()
902 ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-name", NULL, name); in _cupsCreateDest()
904 ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-info", NULL, info); in _cupsCreateDest()
906 ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-device-id", NULL, device_id); in _cupsCreateDest()
910 if ((attr = ippFindAttribute(response, "printer-uri-supported", IPP_TAG_URI)) != NULL) in _cupsCreateDest()
911 strlcpy(uri, ippGetString(attr, 0, NULL), urisize); in _cupsCreateDest()
919 if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL) in _cupsCreateDest()
929 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri); in _cupsCreateDest()
930 … ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser()); in _cupsCreateDest()
931 …String(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", NULL, "printer-state"); in _cupsCreateDest()
935 if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL) in _cupsCreateDest()
943 return (uri); in _cupsCreateDest()
948 * 'cupsEnumDests()' - Enumerate available destinations with a callback function.
952 * be used as input to the @link cupsCopyDest@ function. The function must
953 * return 1 to continue enumeration or 0 to stop.
955 * The @code type@ and @code mask@ arguments allow the caller to filter the
957 * printers. The constant @code CUPS_PRINTER_DISCOVERED@ is used to filter on
964 * destinations - it is up to the caller to suppress any duplicate destinations.
969 int /* O - 1 on success, 0 on failure */
971 unsigned flags, /* I - Enumeration flags */ in cupsEnumDests()
972 int msec, /* I - Timeout in milliseconds, -1 for indefinite */ in cupsEnumDests()
973 int *cancel, /* I - Pointer to "cancel" variable */ in cupsEnumDests()
974 cups_ptype_t type, /* I - Printer type bits */ in cupsEnumDests()
975 cups_ptype_t mask, /* I - Mask for printer type bits */ in cupsEnumDests()
976 cups_dest_cb_t cb, /* I - Callback function */ in cupsEnumDests()
977 void *user_data) /* I - User data */ in cupsEnumDests()
985 * 'cupsEnumDestsBlock()' - Enumerate available destinations with a block.
989 * input to the @link cupsCopyDest@ function. The block must return 1 to
990 * continue enumeration or 0 to stop.
992 * The @code type@ and @code mask@ arguments allow the caller to filter the
994 * printers. The constant @code CUPS_PRINTER_DISCOVERED@ is used to filter on
1001 * destinations - it is up to the caller to suppress any duplicate destinations.
1006 int /* O - 1 on success, 0 on failure */
1008 unsigned flags, /* I - Enumeration flags */ in cupsEnumDestsBlock()
1009 int timeout, /* I - Timeout in milliseconds, 0 for indefinite */ in cupsEnumDestsBlock()
1010 int *cancel, /* I - Pointer to "cancel" variable */ in cupsEnumDestsBlock()
1011 cups_ptype_t type, /* I - Printer type bits */ in cupsEnumDestsBlock()
1012 cups_ptype_t mask, /* I - Mask for printer type bits */ in cupsEnumDestsBlock()
1013 cups_dest_block_t block) /* I - Block */ in cupsEnumDestsBlock()
1022 * 'cupsFreeDests()' - Free the memory used by the list of destinations.
1026 cupsFreeDests(int num_dests, /* I - Number of destinations */ in cupsFreeDests()
1027 cups_dest_t *dests) /* I - Destinations */ in cupsFreeDests()
1036 for (i = num_dests, dest = dests; i > 0; i --, dest ++) in cupsFreeDests()
1038 _cupsStrFree(dest->name); in cupsFreeDests()
1039 _cupsStrFree(dest->instance); in cupsFreeDests()
1041 cupsFreeOptions(dest->num_options, dest->options); in cupsFreeDests()
1049 * 'cupsGetDest()' - Get the named destination from the list.
1051 * Use the @link cupsEnumDests@ or @link cupsGetDests2@ functions to get a
1055 cups_dest_t * /* O - Destination pointer or @code NULL@ */
1056 cupsGetDest(const char *name, /* I - Destination name or @code NULL@ for the default destination … in cupsGetDest()
1057 const char *instance, /* I - Instance name or @code NULL@ */ in cupsGetDest()
1058 int num_dests, /* I - Number of destinations */ in cupsGetDest()
1059 cups_dest_t *dests) /* I - Destinations */ in cupsGetDest()
1076 if (dests->is_default) in cupsGetDest()
1079 num_dests --; in cupsGetDest()
1089 match = cups_find_dest(name, instance, num_dests, dests, -1, &diff); in cupsGetDest()
1100 * '_cupsGetDestResource()' - Get the resource path and URI for a destination.
1103 const char * /* O - URI */
1105 cups_dest_t *dest, /* I - Destination */ in _cupsGetDestResource()
1106 unsigned flags, /* I - Destination flags */ in _cupsGetDestResource()
1107 char *resource, /* I - Resource buffer */ in _cupsGetDestResource()
1108 size_t resourcesize) /* I - Size of resource buffer */ in _cupsGetDestResource()
1110 const char *uri, /* URI */ in _cupsGetDestResource() local
1111 *device_uri, /* Device URI */ in _cupsGetDestResource()
1112 *printer_uri; /* Printer URI */ in _cupsGetDestResource()
1113 char scheme[32], /* URI scheme */ in _cupsGetDestResource()
1119 …ce(dest=%p(%s), flags=%u, resource=%p, resourcesize=%d)", (void *)dest, dest->name, flags, (void *… in _cupsGetDestResource()
1138 device_uri = cupsGetOption("device-uri", dest->num_options, dest->options); in _cupsGetDestResource()
1139 printer_uri = cupsGetOption("printer-uri-supported", dest->num_options, dest->options); in _cupsGetDestResource()
1141 …DEBUG_printf(("1_cupsGetDestResource: device-uri=\"%s\", printer-uri-supported=\"%s\".", device_ur… in _cupsGetDestResource()
1148 DEBUG_printf(("1_cupsGetDestResource: Resolved device-uri=\"%s\".", device_uri)); in _cupsGetDestResource()
1152 DEBUG_puts("1_cupsGetDestResource: Unable to resolve device."); in _cupsGetDestResource()
1166 uri = device_uri; in _cupsGetDestResource()
1170 uri = printer_uri; in _cupsGetDestResource()
1174uri = _cupsCreateDest(dest->name, cupsGetOption("printer-info", dest->num_options, dest->options),… in _cupsGetDestResource()
1176 if (uri) in _cupsGetDestResource()
1178 DEBUG_printf(("1_cupsGetDestResource: Local printer-uri-supported=\"%s\"", uri)); in _cupsGetDestResource()
1180 …dest->num_options = cupsAddOption("printer-uri-supported", uri, dest->num_options, &dest->options); in _cupsGetDestResource()
1182 uri = cupsGetOption("printer-uri-supported", dest->num_options, dest->options); in _cupsGetDestResource()
1186 if (!uri) in _cupsGetDestResource()
1188 DEBUG_puts("1_cupsGetDestResource: No printer-uri-supported or device-uri found."); in _cupsGetDestResource()
1197 …else if (httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme), userpass, sizeof(userpa… in _cupsGetDestResource()
1199 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad URI."), 1); in _cupsGetDestResource()
1206 return (uri); in _cupsGetDestResource()
1211 * 'cupsGetDestWithURI()' - Get a destination associated with a URI.
1214 * created using the URI.
1216 * "uri" is the "ipp" or "ipps" URI for the printer.
1221 cups_dest_t * /* O - Destination or @code NULL@ */
1222 cupsGetDestWithURI(const char *name, /* I - Desired printer name or @code NULL@ */ in cupsGetDestWithURI()
1223 const char *uri) /* I - URI for the printer */ in cupsGetDestWithURI() argument
1227 scheme[256], /* Scheme from URI */ in cupsGetDestWithURI()
1228 userpass[256], /* Username:password from URI */ in cupsGetDestWithURI()
1229 hostname[256], /* Hostname from URI */ in cupsGetDestWithURI()
1230 resource[1024], /* Resource path from URI */ in cupsGetDestWithURI()
1232 const char *info; /* printer-info string */ in cupsGetDestWithURI()
1233 int port; /* Port number from URI */ in cupsGetDestWithURI()
1240 if (!uri) in cupsGetDestWithURI()
1246 …if (httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme), userpass, sizeof(userpass), … in cupsGetDestWithURI()
1247 (strncmp(uri, "ipp://", 6) && strncmp(uri, "ipps://", 7))) in cupsGetDestWithURI()
1249 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad printer-uri."), 1); in cupsGetDestWithURI()
1261 * Create the name from the URI... in cupsGetDestWithURI()
1312 dest->name = _cupsStrAlloc(name); in cupsGetDestWithURI()
1313 dest->num_options = cupsAddOption("device-uri", uri, dest->num_options, &(dest->options)); in cupsGetDestWithURI()
1314 dest->num_options = cupsAddOption("printer-info", info, dest->num_options, &(dest->options)); in cupsGetDestWithURI()
1321 * '_cupsGetDests()' - Get destinations from a server.
1323 * "op" is IPP_OP_CUPS_GET_PRINTERS to get a full list, IPP_OP_CUPS_GET_DEFAULT
1324 * to get the system-wide default printer, or IPP_OP_GET_PRINTER_ATTRIBUTES for
1330 * "dest" is initialized to point to the array of destinations.
1343 int /* O - Number of destinations */
1344 _cupsGetDests(http_t *http, /* I - Connection to server or in _cupsGetDests()
1346 ipp_op_t op, /* I - IPP operation */ in _cupsGetDests()
1347 const char *name, /* I - Name of destination */ in _cupsGetDests()
1348 cups_dest_t **dests, /* IO - Destinations */ in _cupsGetDests()
1349 cups_ptype_t type, /* I - Printer type bits */ in _cupsGetDests()
1350 cups_ptype_t mask) /* I - Printer type mask */ in _cupsGetDests()
1357 const char *printer_name; /* printer-name attribute */ in _cupsGetDests()
1358 char uri[1024]; /* printer-uri value */ in _cupsGetDests() local
1369 "auth-info-required", in _cupsGetDests()
1370 "device-uri", in _cupsGetDests()
1371 "job-sheets-default", in _cupsGetDests()
1372 "marker-change-time", in _cupsGetDests()
1373 "marker-colors", in _cupsGetDests()
1374 "marker-high-levels", in _cupsGetDests()
1375 "marker-levels", in _cupsGetDests()
1376 "marker-low-levels", in _cupsGetDests()
1377 "marker-message", in _cupsGetDests()
1378 "marker-names", in _cupsGetDests()
1379 "marker-types", in _cupsGetDests()
1381 "media-supported", in _cupsGetDests()
1383 "printer-commands", in _cupsGetDests()
1384 "printer-defaults", in _cupsGetDests()
1385 "printer-info", in _cupsGetDests()
1386 "printer-is-accepting-jobs", in _cupsGetDests()
1387 "printer-is-shared", in _cupsGetDests()
1388 "printer-is-temporary", in _cupsGetDests()
1389 "printer-location", in _cupsGetDests()
1390 "printer-make-and-model", in _cupsGetDests()
1391 "printer-mandatory-job-attributes", in _cupsGetDests()
1392 "printer-name", in _cupsGetDests()
1393 "printer-state", in _cupsGetDests()
1394 "printer-state-change-time", in _cupsGetDests()
1395 "printer-state-reasons", in _cupsGetDests()
1396 "printer-type", in _cupsGetDests()
1397 "printer-uri-supported" in _cupsGetDests()
1416 * attributes-charset in _cupsGetDests()
1417 * attributes-natural-language in _cupsGetDests()
1418 * requesting-user-name in _cupsGetDests()
1419 * printer-uri [for IPP_OP_GET_PRINTER_ATTRIBUTES] in _cupsGetDests()
1425 "requested-attributes", sizeof(pattrs) / sizeof(pattrs[0]), in _cupsGetDests()
1429 "requesting-user-name", NULL, cupsUser()); in _cupsGetDests()
1433 httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, in _cupsGetDests()
1435 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, in _cupsGetDests()
1436 uri); in _cupsGetDests()
1440 ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_ENUM, "printer-type", (int)type); in _cupsGetDests()
1441 ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_ENUM, "printer-type-mask", (int)mask); in _cupsGetDests()
1450 for (attr = response->attrs; attr != NULL; attr = attr->next) in _cupsGetDests()
1456 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER) in _cupsGetDests()
1457 attr = attr->next; in _cupsGetDests()
1470 for (; attr && attr->group_tag == IPP_TAG_PRINTER; attr = attr->next) in _cupsGetDests()
1472 if (attr->value_tag != IPP_TAG_INTEGER && in _cupsGetDests()
1473 attr->value_tag != IPP_TAG_ENUM && in _cupsGetDests()
1474 attr->value_tag != IPP_TAG_BOOLEAN && in _cupsGetDests()
1475 attr->value_tag != IPP_TAG_TEXT && in _cupsGetDests()
1476 attr->value_tag != IPP_TAG_TEXTLANG && in _cupsGetDests()
1477 attr->value_tag != IPP_TAG_NAME && in _cupsGetDests()
1478 attr->value_tag != IPP_TAG_NAMELANG && in _cupsGetDests()
1479 attr->value_tag != IPP_TAG_KEYWORD && in _cupsGetDests()
1480 attr->value_tag != IPP_TAG_RANGE && in _cupsGetDests()
1481 attr->value_tag != IPP_TAG_URI) in _cupsGetDests()
1484 if (!strcmp(attr->name, "auth-info-required") || in _cupsGetDests()
1485 !strcmp(attr->name, "device-uri") || in _cupsGetDests()
1486 !strcmp(attr->name, "marker-change-time") || in _cupsGetDests()
1487 !strcmp(attr->name, "marker-colors") || in _cupsGetDests()
1488 !strcmp(attr->name, "marker-high-levels") || in _cupsGetDests()
1489 !strcmp(attr->name, "marker-levels") || in _cupsGetDests()
1490 !strcmp(attr->name, "marker-low-levels") || in _cupsGetDests()
1491 !strcmp(attr->name, "marker-message") || in _cupsGetDests()
1492 !strcmp(attr->name, "marker-names") || in _cupsGetDests()
1493 !strcmp(attr->name, "marker-types") || in _cupsGetDests()
1494 !strcmp(attr->name, "printer-commands") || in _cupsGetDests()
1495 !strcmp(attr->name, "printer-info") || in _cupsGetDests()
1496 !strcmp(attr->name, "printer-is-shared") || in _cupsGetDests()
1497 !strcmp(attr->name, "printer-is-temporary") || in _cupsGetDests()
1498 !strcmp(attr->name, "printer-make-and-model") || in _cupsGetDests()
1499 !strcmp(attr->name, "printer-mandatory-job-attributes") || in _cupsGetDests()
1500 !strcmp(attr->name, "printer-state") || in _cupsGetDests()
1501 !strcmp(attr->name, "printer-state-change-time") || in _cupsGetDests()
1502 !strcmp(attr->name, "printer-type") || in _cupsGetDests()
1503 !strcmp(attr->name, "printer-is-accepting-jobs") || in _cupsGetDests()
1504 !strcmp(attr->name, "printer-location") || in _cupsGetDests()
1505 !strcmp(attr->name, "printer-state-reasons") || in _cupsGetDests()
1506 !strcmp(attr->name, "printer-uri-supported")) in _cupsGetDests()
1512 num_options = cupsAddOption(attr->name, in _cupsGetDests()
1518 else if (!strcmp(attr->name, "media-supported") && media_default[0]) in _cupsGetDests()
1526 for (i = 0; i < attr->num_values; i ++) in _cupsGetDests()
1527 if (!_cups_strcasecmp(media_default, attr->values[i].string.text)) in _cupsGetDests()
1529 DEBUG_printf(("1_cupsGetDests: Setting media to '%s'.", media_default)); in _cupsGetDests()
1535 else if (!strcmp(attr->name, "printer-name") && in _cupsGetDests()
1536 attr->value_tag == IPP_TAG_NAME) in _cupsGetDests()
1537 printer_name = attr->values[0].string.text; in _cupsGetDests()
1538 else if (strncmp(attr->name, "notify-", 7) && in _cupsGetDests()
1539 strncmp(attr->name, "print-quality-", 14) && in _cupsGetDests()
1540 (attr->value_tag == IPP_TAG_BOOLEAN || in _cupsGetDests()
1541 attr->value_tag == IPP_TAG_ENUM || in _cupsGetDests()
1542 attr->value_tag == IPP_TAG_INTEGER || in _cupsGetDests()
1543 attr->value_tag == IPP_TAG_KEYWORD || in _cupsGetDests()
1544 attr->value_tag == IPP_TAG_NAME || in _cupsGetDests()
1545 attr->value_tag == IPP_TAG_RANGE) && in _cupsGetDests()
1546 (ptr = strstr(attr->name, "-default")) != NULL) in _cupsGetDests()
1552 strlcpy(optname, attr->name, sizeof(optname)); in _cupsGetDests()
1553 optname[ptr - attr->name] = '\0'; in _cupsGetDests()
1576 dest->num_options = num_options; in _cupsGetDests()
1577 dest->options = options; in _cupsGetDests()
1598 * 'cupsGetDests()' - Get the list of destinations from the default server.
1601 * "printer-info", "printer-is-accepting-jobs", "printer-is-shared",
1602 * "printer-make-and-model", "printer-state", "printer-state-change-time",
1603 * "printer-state-reasons", "printer-type", and "printer-uri-supported"
1606 * CUPS 1.4 adds the "marker-change-time", "marker-colors",
1607 * "marker-high-levels", "marker-levels", "marker-low-levels", "marker-message",
1608 * "marker-names", "marker-types", and "printer-commands" attributes as options.
1610 * CUPS 2.2 adds accessible IPP printers to the list of destinations that can
1611 * be used. The "printer-uri-supported" option will be present for those IPP
1614 * Use the @link cupsFreeDests@ function to free the destination list and
1615 * the @link cupsGetDest@ function to find a particular destination.
1620 int /* O - Number of destinations */
1621 cupsGetDests(cups_dest_t **dests) /* O - Destinations */ in cupsGetDests()
1628 * 'cupsGetDests2()' - Get the list of destinations from the specified server.
1631 * "printer-info", "printer-is-accepting-jobs", "printer-is-shared",
1632 * "printer-make-and-model", "printer-state", "printer-state-change-time",
1633 * "printer-state-reasons", "printer-type", and "printer-uri-supported"
1636 * CUPS 1.4 adds the "marker-change-time", "marker-colors",
1637 * "marker-high-levels", "marker-levels", "marker-low-levels", "marker-message",
1638 * "marker-names", "marker-types", and "printer-commands" attributes as options.
1640 * CUPS 2.2 adds accessible IPP printers to the list of destinations that can
1641 * be used. The "printer-uri-supported" option will be present for those IPP
1644 * Use the @link cupsFreeDests@ function to free the destination list and
1645 * the @link cupsGetDest@ function to find a particular destination.
1650 int /* O - Number of destinations */
1651 cupsGetDests2(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ in cupsGetDests2()
1652 cups_dest_t **dests) /* O - Destinations */ in cupsGetDests2()
1654 _cups_getdata_t data; /* Enumeration data */ in cupsGetDests2() local
1671 * Connect to the server as needed... in cupsGetDests2()
1688 data.num_dests = 0; in cupsGetDests2()
1689 data.dests = NULL; in cupsGetDests2()
1694 * When talking to a remote cupsd, just enumerate printers on the remote in cupsGetDests2()
1698 …p, 0, _CUPS_DNSSD_GET_DESTS, NULL, 0, CUPS_PRINTER_DISCOVERED, (cups_dest_cb_t)cups_get_cb, &data); in cupsGetDests2()
1703 * When talking to a local cupsd, enumerate both local printers and ones we in cupsGetDests2()
1707 cups_enum_dests(http, 0, _CUPS_DNSSD_GET_DESTS, NULL, 0, 0, (cups_dest_cb_t)cups_get_cb, &data); in cupsGetDests2()
1714 *dests = data.dests; in cupsGetDests2()
1716 if (data.num_dests > 0) in cupsGetDests2()
1719 DEBUG_printf(("1cupsGetDests2: Returning %d destinations.", data.num_dests)); in cupsGetDests2()
1721 return (data.num_dests); in cupsGetDests2()
1726 * 'cupsGetNamedDest()' - Get options for the named destination.
1730 * either know the name of the destination or want to print to the default
1734 * If "http" is @code CUPS_HTTP_DEFAULT@, the connection to the default print
1746 cups_dest_t * /* O - Destination or @code NULL@ */
1747 cupsGetNamedDest(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ in cupsGetNamedDest()
1748 … const char *name, /* I - Destination name or @code NULL@ for the default destination */ in cupsGetNamedDest()
1749 const char *instance) /* I - Instance name or @code NULL@ */ in cupsGetNamedDest()
1753 char filename[1024], /* Path to lpoptions */ in cupsGetNamedDest()
1757 /* IPP operation to get server ops */ in cupsGetNamedDest()
1758 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ in cupsGetNamedDest()
1786 else if (cg->home) in cupsGetNamedDest()
1792 snprintf(filename, sizeof(filename), "%s/.cups/lpoptions", cg->home); in cupsGetNamedDest()
1806 snprintf(filename, sizeof(filename), "%s/lpoptions", cg->cups_serverroot); in cupsGetNamedDest()
1816 * No locally-set default destination, ask the server... in cupsGetNamedDest()
1836 _cups_namedata_t data; /* Callback data */ in cupsGetNamedDest() local
1840 data.name = name; in cupsGetNamedDest()
1841 data.dest = NULL; in cupsGetNamedDest()
1843 cupsEnumDests(0, 1000, NULL, 0, 0, (cups_dest_cb_t)cups_name_cb, &data); in cupsGetNamedDest()
1845 if (!data.dest) in cupsGetNamedDest()
1851 dest = data.dest; in cupsGetNamedDest()
1889 dest->instance = _cupsStrAlloc(instance); in cupsGetNamedDest()
1892 dest->is_default = 1; in cupsGetNamedDest()
1898 snprintf(filename, sizeof(filename), "%s/lpoptions", cg->cups_serverroot); in cupsGetNamedDest()
1901 if (cg->home) in cupsGetNamedDest()
1903 snprintf(filename, sizeof(filename), "%s/.cups/lpoptions", cg->home); in cupsGetNamedDest()
1917 * 'cupsRemoveDest()' - Remove a destination from the destination list.
1921 * @link cupsSetDests@ or @link cupsSetDests2@ functions to save the new
1927 int /* O - New number of destinations */
1928 cupsRemoveDest(const char *name, /* I - Destination name */ in cupsRemoveDest()
1929 const char *instance, /* I - Instance name or @code NULL@ */ in cupsRemoveDest()
1930 int num_dests, /* I - Number of destinations */ in cupsRemoveDest()
1931 cups_dest_t **dests) /* IO - Destinations */ in cupsRemoveDest()
1934 cups_dest_t *dest; /* Pointer to destination */ in cupsRemoveDest()
1948 _cupsStrFree(dest->name); in cupsRemoveDest()
1949 _cupsStrFree(dest->instance); in cupsRemoveDest()
1950 cupsFreeOptions(dest->num_options, dest->options); in cupsRemoveDest()
1956 num_dests --; in cupsRemoveDest()
1958 i = (int)(dest - *dests); in cupsRemoveDest()
1961 memmove(dest, dest + 1, (size_t)(num_dests - i) * sizeof(cups_dest_t)); in cupsRemoveDest()
1968 * 'cupsSetDefaultDest()' - Set the default destination.
1975 const char *name, /* I - Destination name */ in cupsSetDefaultDest()
1976 const char *instance, /* I - Instance name or @code NULL@ */ in cupsSetDefaultDest()
1977 int num_dests, /* I - Number of destinations */ in cupsSetDefaultDest()
1978 cups_dest_t *dests) /* I - Destinations */ in cupsSetDefaultDest()
1996 for (i = num_dests, dest = dests; i > 0; i --, dest ++) in cupsSetDefaultDest()
1997 dest->is_default = !_cups_strcasecmp(name, dest->name) && in cupsSetDefaultDest()
1998 ((!instance && !dest->instance) || in cupsSetDefaultDest()
1999 (instance && dest->instance && in cupsSetDefaultDest()
2000 !_cups_strcasecmp(instance, dest->instance))); in cupsSetDefaultDest()
2005 * 'cupsSetDests()' - Save the list of destinations for the default server.
2007 * This function saves the destinations to /etc/cups/lpoptions when run
2014 cupsSetDests(int num_dests, /* I - Number of destinations */ in cupsSetDests()
2015 cups_dest_t *dests) /* I - Destinations */ in cupsSetDests()
2022 * 'cupsSetDests2()' - Save the list of destinations for the specified server.
2024 * This function saves the destinations to /etc/cups/lpoptions when run
2030 int /* O - 0 on success, -1 on error */
2031 cupsSetDests2(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ in cupsSetDests2()
2032 int num_dests, /* I - Number of destinations */ in cupsSetDests2()
2033 cups_dest_t *dests) /* I - Destinations */ in cupsSetDests2()
2046 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ in cupsSetDests2()
2054 return (-1); in cupsSetDests2()
2065 return (-1); in cupsSetDests2()
2069 * Figure out which file to write to... in cupsSetDests2()
2072 snprintf(filename, sizeof(filename), "%s/lpoptions", cg->cups_serverroot); in cupsSetDests2()
2074 if (cg->home) in cupsSetDests2()
2080 snprintf(filename, sizeof(filename), "%s/.cups", cg->home); in cupsSetDests2()
2084 snprintf(filename, sizeof(filename), "%s/.cups/lpoptions", cg->home); in cupsSetDests2()
2088 * Try to open the file... in cupsSetDests2()
2094 return (-1); in cupsSetDests2()
2099 * Set the permissions to 0644 when saving to the /etc/cups/lpoptions in cupsSetDests2()
2114 for (i = num_dests, dest = dests; i > 0; i --, dest ++) in cupsSetDests2()
2115 if (dest->instance != NULL || dest->num_options != 0 || dest->is_default) in cupsSetDests2()
2117 if (dest->is_default) in cupsSetDests2()
2119 fprintf(fp, "Default %s", dest->name); in cupsSetDests2()
2120 if (dest->instance) in cupsSetDests2()
2121 fprintf(fp, "/%s", dest->instance); in cupsSetDests2()
2128 temp = cupsGetDest(dest->name, NULL, num_temps, temps); in cupsSetDests2()
2130 for (j = dest->num_options, option = dest->options; j > 0; j --, option ++) in cupsSetDests2()
2136 if ((match = _ippFindOption(option->name)) != NULL && match->group_tag == IPP_TAG_PRINTER) in cupsSetDests2()
2143 …emp && (val = cupsGetOption(option->name, temp->num_options, temp->options)) != NULL && !_cups_str… in cupsSetDests2()
2147 * Options don't match, write to the file... in cupsSetDests2()
2152 fprintf(fp, "Dest %s", dest->name); in cupsSetDests2()
2153 if (dest->instance) in cupsSetDests2()
2154 fprintf(fp, "/%s", dest->instance); in cupsSetDests2()
2158 if (option->value[0]) in cupsSetDests2()
2160 …if (strchr(option->value, ' ') || strchr(option->value, '\\') || strchr(option->value, '\"') || st… in cupsSetDests2()
2166 fprintf(fp, " %s=\"", option->name); in cupsSetDests2()
2168 for (val = option->value; *val; val ++) in cupsSetDests2()
2184 fprintf(fp, " %s=%s", option->name, option->value); in cupsSetDests2()
2188 fprintf(fp, " %s", option->name); in cupsSetDests2()
2205 * Set the default printer for this location - this allows command-line in cupsSetDests2()
2206 * and GUI applications to share the same default destination... in cupsSetDests2()
2211 …CFStringRef name = CFStringCreateWithCString(kCFAllocatorDefault, dest->name, kCFStringEncodingUTF… in cupsSetDests2()
2236 * '_cupsUserDefault()' - Get the user default printer from environment
2240 char * /* O - Default printer or NULL */
2241 _cupsUserDefault(char *name, /* I - Name buffer */ in _cupsUserDefault()
2242 size_t namesize) /* I - Size of name buffer */ in _cupsUserDefault()
2262 * Use location-based defaults if "use last printer" is selected in the in _cupsUserDefault()
2280 * No location-based defaults on this platform... in _cupsUserDefault()
2291 * 'appleCopyLocations()' - Copy the location history array.
2294 static CFArrayRef /* O - Location array or NULL */
2319 * 'appleCopyNetwork()' - Get the network ID for the current location.
2322 static CFStringRef /* O - Network ID */
2325 SCDynamicStoreRef dynamicStore; /* System configuration data */ in appleCopyNetwork()
2327 CFDictionaryRef ip_dict; /* Network configuration data */ in appleCopyNetwork()
2336 * be a globally-unique link-local address. in appleCopyNetwork()
2387 * 'appleGetPaperSize()' - Get the default paper size.
2390 static char * /* O - Default paper size */
2391 appleGetPaperSize(char *name, /* I - Paper size name buffer */ in appleGetPaperSize()
2392 size_t namesize) /* I - Size of buffer */ in appleGetPaperSize()
2404 strlcpy(name, pwgmedia->pwg, namesize); in appleGetPaperSize()
2416 * 'appleGetPrinter()' - Get a printer from the history array.
2419 static CFStringRef /* O - Printer name or NULL */
2420 appleGetPrinter(CFArrayRef locations, /* I - Location array */ in appleGetPrinter()
2421 CFStringRef network, /* I - Network name */ in appleGetPrinter()
2422 CFIndex *locindex) /* O - Index in array */ in appleGetPrinter()
2456 * 'cups_add_dest()' - Add a destination to the array.
2461 static cups_dest_t * /* O - New destination */
2462 cups_add_dest(const char *name, /* I - Name of destination */ in cups_add_dest()
2463 const char *instance, /* I - Instance or NULL */ in cups_add_dest()
2464 int *num_dests, /* IO - Number of destinations */ in cups_add_dest()
2465 cups_dest_t **dests) /* IO - Destinations */ in cups_add_dest()
2487 * Find where to insert the destination... in cups_add_dest()
2494 insert = cups_find_dest(name, instance, *num_dests, *dests, *num_dests - 1, in cups_add_dest()
2506 …memmove(*dests + insert + 1, *dests + insert, (size_t)(*num_dests - insert) * sizeof(cups_dest_t)); in cups_add_dest()
2515 dest->name = _cupsStrAlloc(name); in cups_add_dest()
2516 dest->instance = _cupsStrAlloc(instance); in cups_add_dest()
2517 dest->is_default = 0; in cups_add_dest()
2518 dest->num_options = 0; in cups_add_dest()
2519 dest->options = (cups_option_t *)0; in cups_add_dest()
2527 * 'cups_block_cb()' - Enumeration callback for block API.
2530 static int /* O - 1 to continue, 0 to stop */
2532 cups_dest_block_t block, /* I - Block */ in cups_block_cb()
2533 unsigned flags, /* I - Destination flags */ in cups_block_cb()
2534 cups_dest_t *dest) /* I - Destination */ in cups_block_cb()
2542 * 'cups_compare_dests()' - Compare two destinations.
2545 static int /* O - Result of comparison */
2546 cups_compare_dests(cups_dest_t *a, /* I - First destination */ in cups_compare_dests()
2547 cups_dest_t *b) /* I - Second destination */ in cups_compare_dests()
2552 if ((diff = _cups_strcasecmp(a->name, b->name)) != 0) in cups_compare_dests()
2554 else if (a->instance && b->instance) in cups_compare_dests()
2555 return (_cups_strcasecmp(a->instance, b->instance)); in cups_compare_dests()
2557 return ((a->instance && !b->instance) - (!a->instance && b->instance)); in cups_compare_dests()
2564 * 'cups_dnssd_browse_cb()' - Browse for printers.
2569 DNSServiceRef sdRef, /* I - Service reference */ in cups_dnssd_browse_cb()
2570 DNSServiceFlags flags, /* I - Option flags */ in cups_dnssd_browse_cb()
2571 uint32_t interfaceIndex, /* I - Interface number */ in cups_dnssd_browse_cb()
2572 DNSServiceErrorType errorCode, /* I - Error, if any */ in cups_dnssd_browse_cb()
2573 const char *serviceName, /* I - Name of service/device */ in cups_dnssd_browse_cb()
2574 const char *regtype, /* I - Type of service */ in cups_dnssd_browse_cb()
2575 const char *replyDomain, /* I - Service domain */ in cups_dnssd_browse_cb()
2576 void *context) /* I - Enumeration data */ in cups_dnssd_browse_cb()
2578 _cups_dnssd_data_t *data = (_cups_dnssd_data_t *)context; in cups_dnssd_browse_cb() local
2579 /* Enumeration data */ in cups_dnssd_browse_cb()
2595 cups_dnssd_get_device(data, serviceName, regtype, replyDomain); in cups_dnssd_browse_cb()
2601 * 'cups_dnssd_browse_cb()' - Browse for printers.
2606 AvahiServiceBrowser *browser, /* I - Browser */ in cups_dnssd_browse_cb()
2607 AvahiIfIndex interface, /* I - Interface index (unused) */ in cups_dnssd_browse_cb()
2608 AvahiProtocol protocol, /* I - Network protocol (unused) */ in cups_dnssd_browse_cb()
2609 AvahiBrowserEvent event, /* I - What happened */ in cups_dnssd_browse_cb()
2610 const char *name, /* I - Service name */ in cups_dnssd_browse_cb()
2611 const char *type, /* I - Registration type */ in cups_dnssd_browse_cb()
2612 const char *domain, /* I - Domain */ in cups_dnssd_browse_cb()
2613 AvahiLookupResultFlags flags, /* I - Flags */ in cups_dnssd_browse_cb()
2614 void *context) /* I - Devices array */ in cups_dnssd_browse_cb()
2620 _cups_dnssd_data_t *data = (_cups_dnssd_data_t *)context; in cups_dnssd_browse_cb() local
2621 /* Enumeration data */ in cups_dnssd_browse_cb()
2634 avahi_simple_poll_quit(data->simple_poll); in cups_dnssd_browse_cb()
2642 cups_dnssd_get_device(data, name, type, domain); in cups_dnssd_browse_cb()
2651 data->browsers --; in cups_dnssd_browse_cb()
2658 * 'cups_dnssd_client_cb()' - Avahi client callback function.
2663 AvahiClient *client, /* I - Client information (unused) */ in cups_dnssd_client_cb()
2664 AvahiClientState state, /* I - Current state */ in cups_dnssd_client_cb()
2665 void *context) /* I - User data (unused) */ in cups_dnssd_client_cb()
2667 _cups_dnssd_data_t *data = (_cups_dnssd_data_t *)context; in cups_dnssd_client_cb() local
2668 /* Enumeration data */ in cups_dnssd_client_cb()
2682 avahi_simple_poll_quit(data->simple_poll); in cups_dnssd_client_cb()
2689 * 'cups_dnssd_compare_device()' - Compare two devices.
2692 static int /* O - Result of comparison */
2694 _cups_dnssd_device_t *a, /* I - First device */ in cups_dnssd_compare_devices()
2695 _cups_dnssd_device_t *b) /* I - Second device */ in cups_dnssd_compare_devices()
2697 return (strcmp(a->dest.name, b->dest.name)); in cups_dnssd_compare_devices()
2702 * 'cups_dnssd_free_device()' - Free the memory used by a device.
2707 _cups_dnssd_device_t *device, /* I - Device */ in cups_dnssd_free_device()
2708 _cups_dnssd_data_t *data) /* I - Enumeration data */ in cups_dnssd_free_device() argument
2710 …rintf(("5cups_dnssd_free_device(device=%p(%s), data=%p)", (void *)device, device->dest.name, (void… in cups_dnssd_free_device()
2713 if (device->ref) in cups_dnssd_free_device()
2714 DNSServiceRefDeallocate(device->ref); in cups_dnssd_free_device()
2716 if (device->ref) in cups_dnssd_free_device()
2717 avahi_record_browser_free(device->ref); in cups_dnssd_free_device()
2720 _cupsStrFree(device->domain); in cups_dnssd_free_device()
2721 _cupsStrFree(device->fullName); in cups_dnssd_free_device()
2722 _cupsStrFree(device->regtype); in cups_dnssd_free_device()
2723 _cupsStrFree(device->dest.name); in cups_dnssd_free_device()
2725 cupsFreeOptions(device->dest.num_options, device->dest.options); in cups_dnssd_free_device()
2732 * 'cups_dnssd_get_device()' - Lookup a device and create it as needed.
2735 static _cups_dnssd_device_t * /* O - Device */
2737 _cups_dnssd_data_t *data, /* I - Enumeration data */ in cups_dnssd_get_device() argument
2738 const char *serviceName, /* I - Service name */ in cups_dnssd_get_device()
2739 const char *regtype, /* I - Registration type */ in cups_dnssd_get_device()
2740 const char *replyDomain) /* I - Domain name */ in cups_dnssd_get_device()
2749 …EBUG_printf(("5cups_dnssd_get_device(data=%p, serviceName=\"%s\", regtype=\"%s\", replyDomain=\"%s… in cups_dnssd_get_device()
2759 if ((device = cupsArrayFind(data->devices, &key)) != NULL) in cups_dnssd_get_device()
2762 * Yes, see if we need to do anything with this... in cups_dnssd_get_device()
2765 int update = 0; /* Non-zero if we need to update */ in cups_dnssd_get_device()
2768 _cups_strcasecmp(device->domain, replyDomain)) in cups_dnssd_get_device()
2771 * Update the "global" listing to use the .local domain name instead. in cups_dnssd_get_device()
2774 _cupsStrFree(device->domain); in cups_dnssd_get_device()
2775 device->domain = _cupsStrAlloc(replyDomain); in cups_dnssd_get_device()
2777 DEBUG_printf(("6cups_dnssd_get_device: Updating '%s' to use local " in cups_dnssd_get_device()
2778 "domain.", device->dest.name)); in cups_dnssd_get_device()
2784 _cups_strcasecmp(device->regtype, regtype)) in cups_dnssd_get_device()
2790 _cupsStrFree(device->regtype); in cups_dnssd_get_device()
2791 device->regtype = _cupsStrAlloc(regtype); in cups_dnssd_get_device()
2793 DEBUG_printf(("6cups_dnssd_get_device: Updating '%s' to use IPPS.", in cups_dnssd_get_device()
2794 device->dest.name)); in cups_dnssd_get_device()
2801 DEBUG_printf(("6cups_dnssd_get_device: No changes to '%s'.", in cups_dnssd_get_device()
2802 device->dest.name)); in cups_dnssd_get_device()
2818 device->dest.name = _cupsStrAlloc(name); in cups_dnssd_get_device()
2819 device->domain = _cupsStrAlloc(replyDomain); in cups_dnssd_get_device()
2820 device->regtype = _cupsStrAlloc(regtype); in cups_dnssd_get_device()
2822 device->dest.num_options = cupsAddOption("printer-info", serviceName, 0, &device->dest.options); in cups_dnssd_get_device()
2824 cupsArrayAdd(data->devices, device); in cups_dnssd_get_device()
2837 _cupsStrFree(device->fullName); in cups_dnssd_get_device()
2838 device->fullName = _cupsStrAlloc(fullName); in cups_dnssd_get_device()
2840 if (device->ref) in cups_dnssd_get_device()
2843 DNSServiceRefDeallocate(device->ref); in cups_dnssd_get_device()
2845 avahi_record_browser_free(device->ref); in cups_dnssd_get_device()
2848 device->ref = 0; in cups_dnssd_get_device()
2851 if (device->state == _CUPS_DNSSD_ACTIVE) in cups_dnssd_get_device()
2853 DEBUG_printf(("6cups_dnssd_get_device: Remove callback for \"%s\".", device->dest.name)); in cups_dnssd_get_device()
2855 (*data->cb)(data->user_data, CUPS_DEST_FLAGS_REMOVED, &device->dest); in cups_dnssd_get_device()
2856 device->state = _CUPS_DNSSD_NEW; in cups_dnssd_get_device()
2865 * 'cups_dnssd_poll_cb()' - Wait for input on the specified file descriptors.
2874 static int /* O - Number of file descriptors matching */
2876 struct pollfd *pollfds, /* I - File descriptors */ in cups_dnssd_poll_cb()
2877 unsigned int num_pollfds, /* I - Number of file descriptors */ in cups_dnssd_poll_cb()
2878 int timeout, /* I - Timeout in milliseconds (unused) */ in cups_dnssd_poll_cb()
2879 void *context) /* I - User data (unused) */ in cups_dnssd_poll_cb()
2881 _cups_dnssd_data_t *data = (_cups_dnssd_data_t *)context; in cups_dnssd_poll_cb() local
2882 /* Enumeration data */ in cups_dnssd_poll_cb()
2900 data->got_data = 1; in cups_dnssd_poll_cb()
2909 * 'cups_dnssd_query_cb()' - Process query data.
2915 DNSServiceRef sdRef, /* I - Service reference */ in cups_dnssd_query_cb()
2916 DNSServiceFlags flags, /* I - Data flags */ in cups_dnssd_query_cb()
2917 uint32_t interfaceIndex, /* I - Interface */ in cups_dnssd_query_cb()
2918 DNSServiceErrorType errorCode, /* I - Error, if any */ in cups_dnssd_query_cb()
2919 const char *fullName, /* I - Full service name */ in cups_dnssd_query_cb()
2920 uint16_t rrtype, /* I - Record type */ in cups_dnssd_query_cb()
2921 uint16_t rrclass, /* I - Record class */ in cups_dnssd_query_cb()
2922 uint16_t rdlen, /* I - Length of record data */ in cups_dnssd_query_cb()
2923 const void *rdata, /* I - Record data */ in cups_dnssd_query_cb()
2924 uint32_t ttl, /* I - Time-to-live */ in cups_dnssd_query_cb()
2926 AvahiRecordBrowser *browser, /* I - Record browser */ in cups_dnssd_query_cb()
2928 /* I - Interface index (unused) */ in cups_dnssd_query_cb()
2929 AvahiProtocol protocol, /* I - Network protocol (unused) */ in cups_dnssd_query_cb()
2930 AvahiBrowserEvent event, /* I - What happened? */ in cups_dnssd_query_cb()
2931 const char *fullName, /* I - Service name */ in cups_dnssd_query_cb()
2932 uint16_t rrclass, /* I - Record class */ in cups_dnssd_query_cb()
2933 uint16_t rrtype, /* I - Record type */ in cups_dnssd_query_cb()
2934 const void *rdata, /* I - TXT record */ in cups_dnssd_query_cb()
2935 size_t rdlen, /* I - Length of TXT record */ in cups_dnssd_query_cb()
2936 AvahiLookupResultFlags flags, /* I - Flags */ in cups_dnssd_query_cb()
2938 void *context) /* I - Enumeration data */ in cups_dnssd_query_cb()
2944 _cups_dnssd_data_t *data = (_cups_dnssd_data_t *)context; in cups_dnssd_query_cb() local
2945 /* Enumeration data */ in cups_dnssd_query_cb()
2957 * Only process "add" data... in cups_dnssd_query_cb()
2967 * Only process "add" data... in cups_dnssd_query_cb()
2992 if ((device = cupsArrayFind(data->devices, &dkey)) != NULL && device->state == _CUPS_DNSSD_NEW) in cups_dnssd_query_cb()
2998 const uint8_t *txt, /* Pointer into data */ in cups_dnssd_query_cb()
3007 uriname[1024], /* Name for URI */ in cups_dnssd_query_cb()
3008 uri[1024]; /* Printer URI */ in cups_dnssd_query_cb() local
3012 /* Did we see a printer-type key? */ in cups_dnssd_query_cb()
3014 device->state = _CUPS_DNSSD_PENDING; in cups_dnssd_query_cb()
3024 * Read a key/value pair starting with an 8-bit length. Since the in cups_dnssd_query_cb()
3026 * don't need to check for overflow... in cups_dnssd_query_cb()
3045 memcpy(value, txt, (size_t)(txtnext - txt)); in cups_dnssd_query_cb()
3046 value[txtnext - txt] = '\0'; in cups_dnssd_query_cb()
3071 if ((ptr = value + strlen(value) - 1) > value && *ptr == ')') in cups_dnssd_query_cb()
3087 device->dest.num_options = cupsAddOption("printer-location", value, in cups_dnssd_query_cb()
3088 device->dest.num_options, in cups_dnssd_query_cb()
3089 &device->dest.options); in cups_dnssd_query_cb()
3093 * Look for PDF-capable printers; only PDF-capable printers are shown. in cups_dnssd_query_cb()
3107 …else if ((!_cups_strncasecmp(start, "image/pwg-raster", 16) && (!start[16] || start[16] == ',')) || in cups_dnssd_query_cb()
3119 device->state = _CUPS_DNSSD_INCOMPATIBLE; in cups_dnssd_query_cb()
3121 else if (!_cups_strcasecmp(key, "printer-type")) in cups_dnssd_query_cb()
3158 if (!_cups_strcasecmp(value, "legal-a4")) in cups_dnssd_query_cb()
3160 else if (!_cups_strcasecmp(value, "isoc-a2")) in cups_dnssd_query_cb()
3162 else if (!_cups_strcasecmp(value, ">isoc-a2")) in cups_dnssd_query_cb()
3181 * Save the printer-xxx values... in cups_dnssd_query_cb()
3189 …device->dest.num_options = cupsAddOption("printer-make-and-model", make_and_model, device->dest.nu… in cups_dnssd_query_cb()
3192 …device->dest.num_options = cupsAddOption("printer-make-and-model", model, device->dest.num_options… in cups_dnssd_query_cb()
3194 device->type = type; in cups_dnssd_query_cb()
3196 …device->dest.num_options = cupsAddOption("printer-type", value, device->dest.num_options, &device- in cups_dnssd_query_cb()
3199 * Save the URI... in cups_dnssd_query_cb()
3202 cups_dnssd_unquote(uriname, device->fullName, sizeof(uriname)); in cups_dnssd_query_cb()
3203 httpAssembleURI(HTTP_URI_CODING_ALL, uri, sizeof(uri), in cups_dnssd_query_cb()
3204 !strcmp(device->regtype, "_ipps._tcp") ? "ipps" : "ipp", in cups_dnssd_query_cb()
3207 DEBUG_printf(("6cups_dnssd_query: device-uri=\"%s\"", uri)); in cups_dnssd_query_cb()
3209 …device->dest.num_options = cupsAddOption("device-uri", uri, device->dest.num_options, &device->des… in cups_dnssd_query_cb()
3218 * 'cups_dnssd_resolve()' - Resolve a Bonjour printer URI.
3221 static const char * /* O - Resolved URI or NULL */
3223 cups_dest_t *dest, /* I - Destination */ in cups_dnssd_resolve()
3224 const char *uri, /* I - Current printer URI */ in cups_dnssd_resolve() argument
3225 int msec, /* I - Time in milliseconds */ in cups_dnssd_resolve()
3226 int *cancel, /* I - Pointer to "cancel" variable */ in cups_dnssd_resolve()
3227 cups_dest_cb_t cb, /* I - Callback */ in cups_dnssd_resolve()
3228 void *user_data) /* I - User data for callback */ in cups_dnssd_resolve()
3230 char tempuri[1024]; /* Temporary URI buffer */ in cups_dnssd_resolve()
3231 _cups_dnssd_resolve_t resolve; /* Resolve data */ in cups_dnssd_resolve()
3235 * Resolve the URI... in cups_dnssd_resolve()
3248 resolve.end_time.tv_usec -= 1000000; in cups_dnssd_resolve()
3257 …if ((uri = _httpResolveURI(uri, tempuri, sizeof(tempuri), _HTTP_RESOLVE_DEFAULT, cups_dnssd_resolv… in cups_dnssd_resolve()
3259 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Unable to resolve printer-uri."), 1); in cups_dnssd_resolve()
3268 * Save the resolved URI... in cups_dnssd_resolve()
3271 dest->num_options = cupsAddOption("device-uri", uri, dest->num_options, &dest->options); in cups_dnssd_resolve()
3273 return (cupsGetOption("device-uri", dest->num_options, dest->options)); in cups_dnssd_resolve()
3278 * 'cups_dnssd_resolve_cb()' - See if we should continue resolving.
3281 static int /* O - 1 to continue, 0 to stop */
3282 cups_dnssd_resolve_cb(void *context) /* I - Resolve data */ in cups_dnssd_resolve_cb()
3285 /* Resolve data */ in cups_dnssd_resolve_cb()
3293 if (resolve->cancel && *(resolve->cancel)) in cups_dnssd_resolve_cb()
3305 …6d", (int)curtime.tv_sec, (int)curtime.tv_usec, (int)resolve->end_time.tv_sec, (int)resolve->end_t… in cups_dnssd_resolve_cb()
3307 return (curtime.tv_sec < resolve->end_time.tv_sec || in cups_dnssd_resolve_cb()
3308 (curtime.tv_sec == resolve->end_time.tv_sec && in cups_dnssd_resolve_cb()
3309 curtime.tv_usec < resolve->end_time.tv_usec)); in cups_dnssd_resolve_cb()
3314 * 'cups_dnssd_unquote()' - Unquote a name string.
3318 cups_dnssd_unquote(char *dst, /* I - Destination buffer */ in cups_dnssd_unquote()
3319 const char *src, /* I - Source string */ in cups_dnssd_unquote()
3320 size_t dstsize) /* I - Size of destination buffer */ in cups_dnssd_unquote()
3322 char *dstend = dst + dstsize - 1; /* End of destination buffer */ in cups_dnssd_unquote()
3333 *dst++ = ((((src[0] - '0') * 10) + src[1] - '0') * 10) + src[2] - '0'; in cups_dnssd_unquote()
3350 * 'cups_elapsed()' - Return the elapsed time in milliseconds.
3353 static int /* O - Elapsed time in milliseconds */
3354 cups_elapsed(struct timeval *t) /* IO - Previous time */ in cups_elapsed()
3362 msecs = (int)(1000 * (nt.tv_sec - t->tv_sec) + (nt.tv_usec - t->tv_usec) / 1000); in cups_elapsed()
3372 * 'cups_enum_dests()' - Enumerate destinations from a specific server.
3375 static int /* O - 1 on success, 0 on failure */
3377 http_t *http, /* I - Connection to scheduler */ in cups_enum_dests()
3378 unsigned flags, /* I - Enumeration flags */ in cups_enum_dests()
3379 int msec, /* I - Timeout in milliseconds, -1 for indefinite */ in cups_enum_dests()
3380 int *cancel, /* I - Pointer to "cancel" variable */ in cups_enum_dests()
3381 cups_ptype_t type, /* I - Printer type bits */ in cups_enum_dests()
3382 cups_ptype_t mask, /* I - Mask for printer type bits */ in cups_enum_dests()
3383 cups_dest_cb_t cb, /* I - Callback function */ in cups_enum_dests()
3384 void *user_data) /* I - User data */ in cups_enum_dests()
3397 _cups_dnssd_data_t data; /* Data for callback */ in cups_enum_dests() local
3407 struct pollfd pfd; /* Polling data */ in cups_enum_dests()
3420 _cups_getdata_t data; /* Data for callback */ in cups_enum_dests() local
3423 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ in cups_enum_dests()
3444 memset(&data, 0, sizeof(data)); in cups_enum_dests()
3446 user_default = _cupsUserDefault(data.def_name, sizeof(data.def_name)); in cups_enum_dests()
3448 snprintf(filename, sizeof(filename), "%s/lpoptions", cg->cups_serverroot); in cups_enum_dests()
3449data.num_dests = cups_get_dests(filename, NULL, NULL, 1, user_default != NULL, data.num_dests, &da… in cups_enum_dests()
3451 if (cg->home) in cups_enum_dests()
3453 snprintf(filename, sizeof(filename), "%s/.cups/lpoptions", cg->home); in cups_enum_dests()
3455data.num_dests = cups_get_dests(filename, NULL, NULL, 1, user_default != NULL, data.num_dests, &da… in cups_enum_dests()
3458 if (!user_default && (dest = cupsGetDest(NULL, NULL, data.num_dests, data.dests)) != NULL) in cups_enum_dests()
3464 if (dest->instance) in cups_enum_dests()
3465 snprintf(data.def_name, sizeof(data.def_name), "%s/%s", dest->name, dest->instance); in cups_enum_dests()
3467 strlcpy(data.def_name, dest->name, sizeof(data.def_name)); in cups_enum_dests()
3474 strlcpy(data.def_name, default_printer, sizeof(data.def_name)); in cups_enum_dests()
3477 if (data.def_name[0]) in cups_enum_dests()
3483 if ((data.def_instance = strchr(data.def_name, '/')) != NULL) in cups_enum_dests()
3484 *data.def_instance++ = '\0'; in cups_enum_dests()
3487 …DEBUG_printf(("1cups_enum_dests: def_name=\"%s\", def_instance=\"%s\"", data.def_name, data.def_in… in cups_enum_dests()
3490 * Get ready to enumerate... in cups_enum_dests()
3494 data.type = type; in cups_enum_dests()
3495 data.mask = mask; in cups_enum_dests()
3496 data.cb = cb; in cups_enum_dests()
3497 data.user_data = user_data; in cups_enum_dests()
3498data.devices = cupsArrayNew3((cups_array_func_t)cups_dnssd_compare_devices, NULL, NULL, 0, NULL,… in cups_enum_dests()
3504 * Get the list of local printers and pass them to the callback function... in cups_enum_dests()
3509 if (data.def_name[0]) in cups_enum_dests()
3515 if ((dest = cupsGetDest(data.def_name, data.def_instance, num_dests, dests)) != NULL) in cups_enum_dests()
3517 DEBUG_printf(("1cups_enum_dests: Setting is_default on \"%s/%s\".", dest->name, dest->instance)); in cups_enum_dests()
3518 dest->is_default = 1; in cups_enum_dests()
3524 i --, dest ++) in cups_enum_dests()
3528 const char *device_uri; /* Device URI */ in cups_enum_dests()
3531 if ((user_dest = cupsGetDest(dest->name, NULL, data.num_dests, data.dests)) != NULL) in cups_enum_dests()
3534 * Apply user defaults to this destination for all instances... in cups_enum_dests()
3537 for (j = user_dest - data.dests; j < data.num_dests; j ++, user_dest ++) in cups_enum_dests()
3539 if (_cups_strcasecmp(user_dest->name, dest->name)) in cups_enum_dests()
3541 j = data.num_dests; in cups_enum_dests()
3545 for (k = dest->num_options, option = dest->options; k > 0; k --, option ++) in cups_enum_dests()
3546 …user_dest->num_options = cupsAddOption(option->name, option->value, user_dest->num_options, &user_… in cups_enum_dests()
3552 if (j < data.num_dests) in cups_enum_dests()
3559 …if (!dest->instance && (device_uri = cupsGetOption("device-uri", dest->num_options, dest->options)… in cups_enum_dests()
3565 char scheme[32], /* URI scheme */ in cups_enum_dests()
3584 … if ((device = cups_dnssd_get_device(&data, serviceName, regtype, replyDomain)) != NULL) in cups_enum_dests()
3585 device->state = _CUPS_DNSSD_ACTIVE; in cups_enum_dests()
3600 * Return early if the caller doesn't want to do discovery... in cups_enum_dests()
3608 * Get Bonjour-shared printers... in cups_enum_dests()
3614 if (DNSServiceCreateConnection(&data.main_ref) != kDNSServiceErr_NoError) in cups_enum_dests()
3616 DEBUG_puts("1cups_enum_dests: Unable to create service browser, returning 0."); in cups_enum_dests()
3618 cupsFreeDests(data.num_dests, data.dests); in cups_enum_dests()
3623 main_fd = DNSServiceRefSockFD(data.main_ref); in cups_enum_dests()
3625 ipp_ref = data.main_ref; in cups_enum_dests()
3626 …tion, 0, "_ipp._tcp", NULL, (DNSServiceBrowseReply)cups_dnssd_browse_cb, &data) != kDNSServiceErr_… in cups_enum_dests()
3628 DEBUG_puts("1cups_enum_dests: Unable to create IPP browser, returning 0."); in cups_enum_dests()
3629 DNSServiceRefDeallocate(data.main_ref); in cups_enum_dests()
3631 cupsFreeDests(data.num_dests, data.dests); in cups_enum_dests()
3637 ipps_ref = data.main_ref; in cups_enum_dests()
3638 …ion, 0, "_ipps._tcp", NULL, (DNSServiceBrowseReply)cups_dnssd_browse_cb, &data) != kDNSServiceErr_… in cups_enum_dests()
3640 DEBUG_puts("1cups_enum_dests: Unable to create IPPS browser, returning 0."); in cups_enum_dests()
3641 DNSServiceRefDeallocate(data.main_ref); in cups_enum_dests()
3643 cupsFreeDests(data.num_dests, data.dests); in cups_enum_dests()
3650 if ((data.simple_poll = avahi_simple_poll_new()) == NULL) in cups_enum_dests()
3652 DEBUG_puts("1cups_enum_dests: Unable to create Avahi poll, returning 0."); in cups_enum_dests()
3654 cupsFreeDests(data.num_dests, data.dests); in cups_enum_dests()
3659 avahi_simple_poll_set_func(data.simple_poll, cups_dnssd_poll_cb, &data); in cups_enum_dests()
3661 data.client = avahi_client_new(avahi_simple_poll_get(data.simple_poll), in cups_enum_dests()
3662 0, cups_dnssd_client_cb, &data, in cups_enum_dests()
3664 if (!data.client) in cups_enum_dests()
3666 DEBUG_puts("1cups_enum_dests: Unable to create Avahi client, returning 0."); in cups_enum_dests()
3667 avahi_simple_poll_free(data.simple_poll); in cups_enum_dests()
3669 cupsFreeDests(data.num_dests, data.dests); in cups_enum_dests()
3674 data.browsers = 1; in cups_enum_dests()
3675 … avahi_service_browser_new(data.client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_ipp._tcp", NULL, 0,… in cups_enum_dests()
3677 DEBUG_puts("1cups_enum_dests: Unable to create Avahi IPP browser, returning 0."); in cups_enum_dests()
3679 avahi_client_free(data.client); in cups_enum_dests()
3680 avahi_simple_poll_free(data.simple_poll); in cups_enum_dests()
3682 cupsFreeDests(data.num_dests, data.dests); in cups_enum_dests()
3688 data.browsers ++; in cups_enum_dests()
3689 …avahi_service_browser_new(data.client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_ipps._tcp", NULL, 0,… in cups_enum_dests()
3691 DEBUG_puts("1cups_enum_dests: Unable to create Avahi IPPS browser, returning 0."); in cups_enum_dests()
3694 avahi_client_free(data.client); in cups_enum_dests()
3695 avahi_simple_poll_free(data.simple_poll); in cups_enum_dests()
3697 cupsFreeDests(data.num_dests, data.dests); in cups_enum_dests()
3737 DNSServiceProcessResult(data.main_ref); in cups_enum_dests()
3742 data.got_data = 0; in cups_enum_dests()
3744 if ((error = avahi_simple_poll_iterate(data.simple_poll, _CUPS_DNSSD_MAXTIME)) > 0) in cups_enum_dests()
3747 * We've been told to exit the loop. Perhaps the connection to in cups_enum_dests()
3754 DEBUG_printf(("1cups_enum_dests: got_data=%d", data.got_data)); in cups_enum_dests()
3757 remaining -= cups_elapsed(&curtime); in cups_enum_dests()
3759 for (device = (_cups_dnssd_device_t *)cupsArrayFirst(data.devices), in cups_enum_dests()
3762 device = (_cups_dnssd_device_t *)cupsArrayNext(data.devices)) in cups_enum_dests()
3764 if (device->ref) in cups_enum_dests()
3767 if (device->state == _CUPS_DNSSD_ACTIVE) in cups_enum_dests()
3770 if (!device->ref && device->state == _CUPS_DNSSD_NEW) in cups_enum_dests()
3772 DEBUG_printf(("1cups_enum_dests: Querying '%s'.", device->fullName)); in cups_enum_dests()
3775 device->ref = data.main_ref; in cups_enum_dests()
3777->ref), kDNSServiceFlagsShareConnection, 0, device->fullName, kDNSServiceType_TXT, kDNSServiceClas… in cups_enum_dests()
3783 device->ref = 0; in cups_enum_dests()
3784 device->state = _CUPS_DNSSD_ERROR; in cups_enum_dests()
3790->ref = avahi_record_browser_new(data.client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, device->fullNam… in cups_enum_dests()
3792 DEBUG_printf(("1cups_enum_dests: Query ref=%p", device->ref)); in cups_enum_dests()
3797 device->state = _CUPS_DNSSD_ERROR; in cups_enum_dests()
3799 …UG_printf(("1cups_enum_dests: Query failed: %s", avahi_strerror(avahi_client_errno(data.client)))); in cups_enum_dests()
3803 else if (device->ref && device->state == _CUPS_DNSSD_PENDING) in cups_enum_dests()
3807 DEBUG_printf(("1cups_enum_dests: Query for \"%s\" is complete.", device->fullName)); in cups_enum_dests()
3809 if ((device->type & mask) == type) in cups_enum_dests()
3813 dest = &device->dest; in cups_enum_dests()
3815 if ((user_dest = cupsGetDest(dest->name, dest->instance, data.num_dests, data.dests)) != NULL) in cups_enum_dests()
3818 * Apply user defaults to this destination for all instances... in cups_enum_dests()
3821 for (j = user_dest - data.dests; j < data.num_dests; j ++, user_dest ++) in cups_enum_dests()
3823 if (_cups_strcasecmp(user_dest->name, dest->name)) in cups_enum_dests()
3825 j = data.num_dests; in cups_enum_dests()
3829 for (k = dest->num_options, option = dest->options; k > 0; k --, option ++) in cups_enum_dests()
3830 …user_dest->num_options = cupsAddOption(option->name, option->value, user_dest->num_options, &user_… in cups_enum_dests()
3836 if (j < data.num_dests) in cups_enum_dests()
3838 remaining = -1; in cups_enum_dests()
3844 if (!strcasecmp(dest->name, data.def_name) && !data.def_instance) in cups_enum_dests()
3846 DEBUG_printf(("1cups_enum_dests: Setting is_default on discovered \"%s\".", dest->name)); in cups_enum_dests()
3847 dest->is_default = 1; in cups_enum_dests()
3850 DEBUG_printf(("1cups_enum_dests: Add callback for \"%s\".", device->dest.name)); in cups_enum_dests()
3853 remaining = -1; in cups_enum_dests()
3859 device->state = _CUPS_DNSSD_ACTIVE; in cups_enum_dests()
3864 …leted=%d, count=%d, devices count=%d", remaining, data.browsers, completed, count, cupsArrayCount( in cups_enum_dests()
3866 if (data.browsers == 0 && completed == cupsArrayCount(data.devices)) in cups_enum_dests()
3869 …leted=%d, count=%d, devices count=%d", remaining, completed, count, cupsArrayCount(data.devices))); in cups_enum_dests()
3871 if (completed == cupsArrayCount(data.devices)) in cups_enum_dests()
3883 cupsFreeDests(data.num_dests, data.dests); in cups_enum_dests()
3886 cupsArrayDelete(data.devices); in cups_enum_dests()
3897 if (data.main_ref) in cups_enum_dests()
3898 DNSServiceRefDeallocate(data.main_ref); in cups_enum_dests()
3908 if (data.client) in cups_enum_dests()
3909 avahi_client_free(data.client); in cups_enum_dests()
3910 if (data.simple_poll) in cups_enum_dests()
3911 avahi_simple_poll_free(data.simple_poll); in cups_enum_dests()
3922 * 'cups_find_dest()' - Find a destination using a binary search.
3925 static int /* O - Index of match */
3926 cups_find_dest(const char *name, /* I - Destination name */ in cups_find_dest()
3927 const char *instance, /* I - Instance or NULL */ in cups_find_dest()
3928 int num_dests, /* I - Number of destinations */ in cups_find_dest()
3929 cups_dest_t *dests, /* I - Destinations */ in cups_find_dest()
3930 int prev, /* I - Previous index */ in cups_find_dest()
3931 int *rdiff) /* O - Difference of match */ in cups_find_dest()
3951 (diff > 0 && prev == (num_dests - 1))) in cups_find_dest()
3972 right = num_dests - 1; in cups_find_dest()
3982 right = num_dests - 1; in cups_find_dest()
3997 while ((right - left) > 1); in cups_find_dest()
4025 * 'cups_get_cb()' - Collect enumerated destinations.
4028 static int /* O - 1 to continue, 0 to stop */
4029 cups_get_cb(_cups_getdata_t *data, /* I - Data from cupsGetDests */ in cups_get_cb() argument
4030 unsigned flags, /* I - Enumeration flags */ in cups_get_cb()
4031 cups_dest_t *dest) /* I - Destination */ in cups_get_cb()
4039 data->num_dests = cupsRemoveDest(dest->name, dest->instance, data->num_dests, &data->dests); in cups_get_cb()
4044 * Add destination to array... in cups_get_cb()
4047 data->num_dests = cupsCopyDest(dest, data->num_dests, &data->dests); in cups_get_cb()
4055 * 'cups_get_default()' - Get the default destination from an lpoptions file.
4058 static char * /* O - Default destination or NULL */
4059 cups_get_default(const char *filename, /* I - File to read */ in cups_get_default()
4060 char *namebuf, /* I - Name buffer */ in cups_get_default()
4061 size_t namesize, /* I - Size of name buffer */ in cups_get_default()
4062 const char **instance) /* I - Instance */ in cups_get_default()
4104 * 'cups_get_dests()' - Get destinations from a file.
4107 static int /* O - Number of destinations */
4109 const char *filename, /* I - File to read from */ in cups_get_dests()
4110 const char *match_name, /* I - Destination name we want */ in cups_get_dests()
4111 const char *match_inst, /* I - Instance name we want */ in cups_get_dests()
4112 int load_all, /* I - Load all saved destinations? */ in cups_get_dests()
4113 int user_default_set, /* I - User default printer set? */ in cups_get_dests()
4114 int num_dests, /* I - Number of destinations */ in cups_get_dests()
4115 cups_dest_t **dests) /* IO - Destinations */ in cups_get_dests()
4130 * Try to open the file... in cups_get_dests()
4236 dest->num_options = cupsParseOptions(lineptr, dest->num_options, &(dest->options)); in cups_get_dests()
4256 dest->is_default = 1; in cups_get_dests()
4271 * 'cups_make_string()' - Make a comma-separated string of values from an IPP
4275 static char * /* O - New string */
4277 ipp_attribute_t *attr, /* I - Attribute to convert */ in cups_make_string()
4278 char *buffer, /* I - Buffer */ in cups_make_string() argument
4279 size_t bufsize) /* I - Size of buffer */ in cups_make_string()
4282 char *ptr, /* Pointer into buffer */ in cups_make_string()
4283 *end, /* Pointer to end of buffer */ in cups_make_string()
4291 if (attr->num_values == 1 && in cups_make_string()
4292 attr->value_tag != IPP_TAG_INTEGER && in cups_make_string()
4293 attr->value_tag != IPP_TAG_ENUM && in cups_make_string()
4294 attr->value_tag != IPP_TAG_BOOLEAN && in cups_make_string()
4295 attr->value_tag != IPP_TAG_RANGE) in cups_make_string()
4296 return (attr->values[0].string.text); in cups_make_string()
4299 * Copy the values to the string, separating with commas and escaping strings in cups_make_string()
4303 end = buffer + bufsize - 1; in cups_make_string()
4305 for (i = 0, ptr = buffer; i < attr->num_values && ptr < end; i ++) in cups_make_string()
4310 switch (attr->value_tag) in cups_make_string()
4314 snprintf(ptr, (size_t)(end - ptr + 1), "%d", attr->values[i].integer); in cups_make_string()
4318 if (attr->values[i].boolean) in cups_make_string()
4319 strlcpy(ptr, "true", (size_t)(end - ptr + 1)); in cups_make_string()
4321 strlcpy(ptr, "false", (size_t)(end - ptr + 1)); in cups_make_string()
4325 if (attr->values[i].range.lower == attr->values[i].range.upper) in cups_make_string()
4326 snprintf(ptr, (size_t)(end - ptr + 1), "%d", attr->values[i].range.lower); in cups_make_string()
4328 …snprintf(ptr, (size_t)(end - ptr + 1), "%d-%d", attr->values[i].range.lower, attr->values[i].range… in cups_make_string()
4332 for (valptr = attr->values[i].string.text; in cups_make_string()
4337 if (ptr >= (end - 1)) in cups_make_string()
4355 return (buffer); in cups_make_string()
4360 * 'cups_name_cb()' - Find an enumerated destination.
4363 static int /* O - 1 to continue, 0 to stop */
4364 cups_name_cb(_cups_namedata_t *data, /* I - Data from cupsGetNamedDest */ in cups_name_cb() argument
4365 unsigned flags, /* I - Enumeration flags */ in cups_name_cb()
4366 cups_dest_t *dest) /* I - Destination */ in cups_name_cb()
4368 …DEBUG_printf(("2cups_name_cb(data=%p(%s), flags=%x, dest=%p(%s)", (void *)data, data->name, flags,… in cups_name_cb()
4370 if (!(flags & CUPS_DEST_FLAGS_REMOVED) && !dest->instance && !strcasecmp(data->name, dest->name)) in cups_name_cb()
4376 cupsCopyDest(dest, 0, &data->dest); in cups_name_cb()
4385 * 'cups_queue_name()' - Create a local queue name based on the service name.
4390 char *name, /* I - Name buffer */ in cups_queue_name()
4391 const char *serviceName, /* I - Service name */ in cups_queue_name()
4392 size_t namesize) /* I - Size of name buffer */ in cups_queue_name()
4398 for (nameptr = name, ptr = serviceName; *ptr && nameptr < (name + namesize - 1); ptr ++) in cups_queue_name()
4406 else if (nameptr == name || nameptr[-1] != '_') in cups_queue_name()
4415 if (nameptr > (name + 1) && nameptr[-1] == '_') in cups_queue_name()
4416 nameptr --; in cups_queue_name()