2 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
5 * Licensed under the Academic Free License version 2.1
8 #pragma ident "%Z%%M% %I% %E% SMI"
33 /* skip the leading whitespace */
34 for (; ((*s
!= NULL
) && (isspace(*s
) != 0)); s
++);
36 /* drop the trailing whitespace */
37 for (p
= s
+ strlen(s
) - 1; ((p
> s
) && (isspace(*p
) != 0));
46 ieee1284_devid_to_printer_info(char *devid_string
, char **manufacturer
,
47 char **model
, char **description
, char **class,
48 char **serial_no
, char ***command_set
)
53 if (devid_string
== NULL
)
56 /* parse the 1284 device id string */
57 for (s
= (char *)strtok_r(devid_string
, ";\n", &iter
); s
!= NULL
;
58 s
= (char *)strtok_r(NULL
, ";\n", &iter
)) {
59 char *t
, *u
, *iter2
= NULL
;
61 if ((t
= (char *)strtok_r(s
, ":\n", &iter2
)) == NULL
)
64 if ((u
= (char *)strtok_r(NULL
, ":\n", &iter2
)) == NULL
)
67 if (((strcasecmp(t
, "MFG") == 0) ||
68 (strcasecmp(t
, "MANUFACTURER") == 0)) &&
69 (manufacturer
!= NULL
))
70 *manufacturer
= strdup(strip_ws(u
));
71 else if (((strcasecmp(t
, "MDL") == 0) ||
72 (strcasecmp(t
, "MODEL") == 0)) &&
74 *model
= strdup(strip_ws(u
));
75 else if (((strcasecmp(t
, "DES") == 0) ||
76 (strcasecmp(t
, "DESCRIPTION") == 0)) &&
77 (description
!= NULL
))
78 *description
= strdup(strip_ws(u
));
79 else if (((strcasecmp(t
, "CLS") == 0) ||
80 (strcasecmp(t
, "CLASS") == 0)) &&
82 *class = strdup(strip_ws(u
));
83 else if (((strcasecmp(t
, "SER") == 0) ||
84 (strcasecmp(t
, "SERNO") == 0)) &&
86 *serial_no
= strdup(strip_ws(u
));
87 else if (((strcasecmp(t
, "CMD") == 0) ||
88 (strcasecmp(t
, "COMMAND SET") == 0)) &&
89 (command_set
!= NULL
)) {
90 /* this should be more dynamic, I got lazy */
91 char *v
, *iter3
= NULL
;
95 memset(&cmds
, 0, sizeof (cmds
));
96 #define NELEM(a) (sizeof (a) / sizeof (*(a)))
97 for (v
= strtok_r(u
, ",\n", &iter3
);
98 ((v
!= NULL
) && (i
< NELEM(cmds
)));
99 v
= strtok_r(NULL
, ",\n", &iter3
)) {
100 cmds
[i
++] = strdup(strip_ws(v
));
103 *command_set
= calloc(++i
, sizeof (char *));
104 for (i
= 0; (cmds
)[i
] != NULL
; i
++)
105 (*command_set
)[i
] = cmds
[i
];
114 add_printer_info(LibHalChangeSet
*cs
, char *udi
, char *manufacturer
,
115 char *model
, char *description
, char *serial_number
,
116 char **command_set
, char *device
)
118 #define NP(x) (x?x:"")
119 HAL_DEBUG(("udi: %s, snmp data: vendor=%s, product=%s, "
120 "description=%s, serial=%s, device=%s\n",
121 NP(udi
), NP(manufacturer
), NP(model
), NP(description
),
122 NP(serial_number
), NP(device
)));
126 libhal_changeset_set_property_string(cs
,
127 "info.product", model
);
128 if (manufacturer
!= NULL
)
129 libhal_changeset_set_property_string(cs
,
130 "printer.vendor", manufacturer
);
132 libhal_changeset_set_property_string(cs
,
133 "printer.product", model
);
134 if (serial_number
!= NULL
)
135 libhal_changeset_set_property_string(cs
,
136 "printer.serial", serial_number
);
137 if (description
!= NULL
)
138 libhal_changeset_set_property_string(cs
,
139 "printer.description", description
);
140 if (command_set
!= NULL
)
141 libhal_changeset_set_property_strlist(cs
, "printer.commandset",
142 (const char **)command_set
);
144 libhal_changeset_set_property_string(cs
,
145 "printer.device", device
);