remove libfmd_snmp and smnp-notify
[unleashed.git] / usr / src / cmd / hal / probing / network-printer / probe-network-printer.c
blobfc7296bc9bf82c0cffefd15ddbfd4ecb43dd1df7
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"
14 #ifdef HAVE_CONFIG_H
15 # include <config.h>
16 #endif
18 #include <errno.h>
19 #include <string.h>
20 #include <strings.h>
21 #include <ctype.h>
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <sys/ioctl.h>
25 #include <sys/prnio.h>
26 #include <fcntl.h>
27 #include <unistd.h>
28 #include <ctype.h>
30 #include <libhal.h>
31 #include <logger.h>
33 #include "printer.h"
35 int
36 main(int argc, char *argv[])
38 int ret = 1;
39 char *udi;
40 char *printer_address,
41 *community;
42 DBusError error;
43 LibHalContext *ctx = NULL;
44 LibHalChangeSet *cs = NULL;
45 char *manufacturer = NULL,
46 *model = NULL,
47 *serial_number = NULL,
48 *description = NULL,
49 **command_set = NULL,
50 *device_uri = 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,
54 char **device_uri);
56 dbus_error_init(&error);
58 if ((udi = getenv("UDI")) == NULL)
59 goto out;
61 printer_address = getenv("HAL_PROP_NETWORK_DEVICE_ADDRESS");
62 if (printer_address == NULL)
63 goto out;
65 community = getenv("HAL_PROP_NETWORK_DEVICE_SNMP_COMMUNITY");
66 if (community == NULL)
67 community = "public";
69 setup_logger();
71 dbus_error_init(&error);
73 if ((ctx = libhal_ctx_init_direct(&error)) == NULL)
74 goto out;
76 if ((cs = libhal_device_new_changeset(udi)) == NULL) {
77 HAL_DEBUG(("Cannot allocate changeset"));
78 goto out;
81 /* Probe the printer for characteristics via SNMP */
82 ret = snmp_printer_info(printer_address, community, &manufacturer,
83 &model, &description, &serial_number, &command_set,
84 &device_uri);
85 if (ret < 0) {
86 HAL_DEBUG(("Cannot get snmp data for %s: %s",
87 printer_address, strerror(errno)));
88 goto out;
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);
94 if (ret < 0) {
95 HAL_DEBUG(("Cannot add printer data for %s to %s: %s",
96 printer_address, udi, strerror(errno)));
97 goto out;
100 libhal_device_commit_changeset(ctx, cs, &error);
102 ret = 0;
104 out:
105 if (cs != NULL) {
106 libhal_device_free_changeset(cs);
109 if (ctx != NULL) {
110 if (dbus_error_is_set(&error)) {
111 dbus_error_free(&error);
113 libhal_ctx_shutdown(ctx, &error);
114 libhal_ctx_free(ctx);
117 return (ret);