1 /***************************************************************************
3 * probe-network-printer.c : Probe for snmp printer device information
5 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
6 * Use is subject to license terms.
8 * Licensed under the Academic Free License version 2.1
10 **************************************************************************/
12 #pragma ident "%Z%%M% %I% %E% SMI"
24 #include <sys/ioctl.h>
25 #include <sys/prnio.h>
36 main(int argc
, char *argv
[])
40 char *printer_address
,
43 LibHalContext
*ctx
= NULL
;
44 LibHalChangeSet
*cs
= NULL
;
45 char *manufacturer
= NULL
,
47 *serial_number
= NULL
,
51 extern int snmp_printer_info(char *hostname
, char *community
,
52 char **manufacturer
, char **model
, char **description
,
53 char **serial_number
, char ***command_set
,
56 dbus_error_init(&error
);
58 if ((udi
= getenv("UDI")) == NULL
)
61 printer_address
= getenv("HAL_PROP_NETWORK_DEVICE_ADDRESS");
62 if (printer_address
== NULL
)
65 community
= getenv("HAL_PROP_NETWORK_DEVICE_SNMP_COMMUNITY");
66 if (community
== NULL
)
71 dbus_error_init(&error
);
73 if ((ctx
= libhal_ctx_init_direct(&error
)) == NULL
)
76 if ((cs
= libhal_device_new_changeset(udi
)) == NULL
) {
77 HAL_DEBUG(("Cannot allocate changeset"));
81 /* Probe the printer for characteristics via SNMP */
82 ret
= snmp_printer_info(printer_address
, community
, &manufacturer
,
83 &model
, &description
, &serial_number
, &command_set
,
86 HAL_DEBUG(("Cannot get snmp data for %s: %s",
87 printer_address
, strerror(errno
)));
91 /* Add printer characteristics to the HAL device tree */
92 ret
= add_printer_info(cs
, udi
, manufacturer
, model
, description
,
93 serial_number
, command_set
, device_uri
);
95 HAL_DEBUG(("Cannot add printer data for %s to %s: %s",
96 printer_address
, udi
, strerror(errno
)));
100 libhal_device_commit_changeset(ctx
, cs
, &error
);
106 libhal_device_free_changeset(cs
);
110 if (dbus_error_is_set(&error
)) {
111 dbus_error_free(&error
);
113 libhal_ctx_shutdown(ctx
, &error
);
114 libhal_ctx_free(ctx
);