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
31 /* skip the leading whitespace */
32 for (; ((*s
!= '\0') && (isspace(*s
) != 0)); s
++);
34 /* drop the trailing whitespace */
35 for (p
= s
+ strlen(s
) - 1; ((p
> s
) && (isspace(*p
) != 0));
44 ieee1284_devid_to_printer_info(char *devid_string
, char **manufacturer
,
45 char **model
, char **description
, char **class,
46 char **serial_no
, char ***command_set
)
51 if (devid_string
== NULL
)
54 /* parse the 1284 device id string */
55 for (s
= (char *)strtok_r(devid_string
, ";\n", &iter
); s
!= NULL
;
56 s
= (char *)strtok_r(NULL
, ";\n", &iter
)) {
57 char *t
, *u
, *iter2
= NULL
;
59 if ((t
= (char *)strtok_r(s
, ":\n", &iter2
)) == NULL
)
62 if ((u
= (char *)strtok_r(NULL
, ":\n", &iter2
)) == NULL
)
65 if (((strcasecmp(t
, "MFG") == 0) ||
66 (strcasecmp(t
, "MANUFACTURER") == 0)) &&
67 (manufacturer
!= NULL
))
68 *manufacturer
= strdup(strip_ws(u
));
69 else if (((strcasecmp(t
, "MDL") == 0) ||
70 (strcasecmp(t
, "MODEL") == 0)) &&
72 *model
= strdup(strip_ws(u
));
73 else if (((strcasecmp(t
, "DES") == 0) ||
74 (strcasecmp(t
, "DESCRIPTION") == 0)) &&
75 (description
!= NULL
))
76 *description
= strdup(strip_ws(u
));
77 else if (((strcasecmp(t
, "CLS") == 0) ||
78 (strcasecmp(t
, "CLASS") == 0)) &&
80 *class = strdup(strip_ws(u
));
81 else if (((strcasecmp(t
, "SER") == 0) ||
82 (strcasecmp(t
, "SERNO") == 0)) &&
84 *serial_no
= strdup(strip_ws(u
));
85 else if (((strcasecmp(t
, "CMD") == 0) ||
86 (strcasecmp(t
, "COMMAND SET") == 0)) &&
87 (command_set
!= NULL
)) {
88 /* this should be more dynamic, I got lazy */
89 char *v
, *iter3
= NULL
;
93 memset(&cmds
, 0, sizeof (cmds
));
94 #define NELEM(a) (sizeof (a) / sizeof (*(a)))
95 for (v
= strtok_r(u
, ",\n", &iter3
);
96 ((v
!= NULL
) && (i
< NELEM(cmds
)));
97 v
= strtok_r(NULL
, ",\n", &iter3
)) {
98 cmds
[i
++] = strdup(strip_ws(v
));
101 *command_set
= calloc(++i
, sizeof (char *));
102 for (i
= 0; (cmds
)[i
] != NULL
; i
++)
103 (*command_set
)[i
] = cmds
[i
];
112 add_printer_info(LibHalChangeSet
*cs
, char *udi
, char *manufacturer
,
113 char *model
, char *description
, char *serial_number
,
114 char **command_set
, char *device
)
116 #define NP(x) (x?x:"")
117 HAL_DEBUG(("udi: %s, snmp data: vendor=%s, product=%s, "
118 "description=%s, serial=%s, device=%s\n",
119 NP(udi
), NP(manufacturer
), NP(model
), NP(description
),
120 NP(serial_number
), NP(device
)));
124 libhal_changeset_set_property_string(cs
,
125 "info.product", model
);
126 if (manufacturer
!= NULL
)
127 libhal_changeset_set_property_string(cs
,
128 "printer.vendor", manufacturer
);
130 libhal_changeset_set_property_string(cs
,
131 "printer.product", model
);
132 if (serial_number
!= NULL
)
133 libhal_changeset_set_property_string(cs
,
134 "printer.serial", serial_number
);
135 if (description
!= NULL
)
136 libhal_changeset_set_property_string(cs
,
137 "printer.description", description
);
138 if (command_set
!= NULL
)
139 libhal_changeset_set_property_strlist(cs
, "printer.commandset",
140 (const char **)command_set
);
142 libhal_changeset_set_property_string(cs
,
143 "printer.device", device
);