Module Name:    src
Committed By:   plunky
Date:           Thu Jul  7 10:26:01 UTC 2011

Modified Files:
        src/usr.bin/sdpquery: print.c

Log Message:
parse IEEE 1284 Device ID, since it is not strictly a
string, and may run longer than a line


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/sdpquery/print.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/sdpquery/print.c
diff -u src/usr.bin/sdpquery/print.c:1.14 src/usr.bin/sdpquery/print.c:1.15
--- src/usr.bin/sdpquery/print.c:1.14	Sat Jun 25 09:16:52 2011
+++ src/usr.bin/sdpquery/print.c	Thu Jul  7 10:26:00 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: print.c,v 1.14 2011/06/25 09:16:52 plunky Exp $	*/
+/*	$NetBSD: print.c,v 1.15 2011/07/07 10:26:00 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: print.c,v 1.14 2011/06/25 09:16:52 plunky Exp $");
+__RCSID("$NetBSD: print.c,v 1.15 2011/07/07 10:26:00 plunky Exp $");
 
 #include <ctype.h>
 #include <iconv.h>
@@ -117,6 +117,7 @@
 static void print_bip_features(sdp_data_t *);
 static void print_bip_functions(sdp_data_t *);
 static void print_bip_capacity(sdp_data_t *);
+static void print_1284id(sdp_data_t *);
 
 static void print_rfcomm(sdp_data_t *);
 static void print_bnep(sdp_data_t *);
@@ -249,7 +250,7 @@
 	{ 0x0352, "CharacterRepertoiresSupported",	print_character_repertoires },
 	{ 0x0354, "XHTML-PrintImageFormatsSupported",	print_string_list },
 	{ 0x0356, "ColorSupported",			print_bool },
-	{ 0x0358, "1284ID",				print_string },
+	{ 0x0358, "1284ID",				print_1284id },
 	{ 0x035a, "PrinterName",			print_string },
 	{ 0x035c, "PrinterLocation",			print_string },
 	{ 0x035e, "DuplexSupported",			print_bool },
@@ -305,7 +306,7 @@
 };
 
 attr_t hcr_attrs[] = {	/* Hardcopy Cable Replacement */
-	{ 0x0300, "1284ID",				print_string },
+	{ 0x0300, "1284ID",				print_1284id },
 	{ 0x0302, "DeviceName",				print_string },
 	{ 0x0304, "FriendlyName",			print_string },
 	{ 0x0306, "DeviceLocation",			print_string },
@@ -1560,6 +1561,38 @@
 }
 
 static void
+print_1284id(sdp_data_t *data)
+{
+	char *str, *ep;
+	size_t len, l;
+
+	if (!sdp_get_str(data, &str, &len))
+		return;
+
+	if (len < 2 || len != be16dec(str)) {
+		printf("[invalid IEEE 1284 Device ID]\n");
+		return;
+	}
+
+	str += 2;
+	len -= 2;
+
+	printf("\n");
+	while (len > 0) {
+		ep = memchr(str, (int)';', len);
+		if (ep == NULL) {
+			printf("[invalid IEEE 1284 Device ID]\n");
+			return;
+		}
+
+		l = (size_t)(ep - str + 1);
+		printf("    %s\n", string_vis(VIS_CSTYLE, str, l));
+		str += l;
+		len -= l;
+	}
+}
+
+static void
 print_rfcomm(sdp_data_t *data)
 {
 	uint8_t v;

Reply via email to