diff --git a/src/protocol/smb/smb2.c b/src/protocol/smb/smb2.c
index 16322fdb..52a4d6d4 100644
--- a/src/protocol/smb/smb2.c
+++ b/src/protocol/smb/smb2.c
@@ -86,76 +86,74 @@ compare(const void *a, const void *b)
return strcmp((*da)->name, (*db)->name);
}
+static void
+smb_add_link(struct string *string, struct smbc_dirent *entry,
+ unsigned char *text, unsigned char dircolor[])
+{
+ add_to_string(string, "name);
+ add_to_string(string, "\">");
+ if (*dircolor) {
+ add_to_string(string, "");
+ }
+ add_to_string(string, entry->name);
+ if (*dircolor) {
+ add_to_string(string, "");
+ }
+ add_to_string(string, "");
+ if (text) add_to_string(string, text);
+}
+
static void
display_entry(struct smbc_dirent *entry, unsigned char dircolor[])
{
+ static unsigned char zero = '\0';
+ struct string string;
+
+ if (!init_string(&string)) return;
+
switch (entry->smbc_type) {
case SMBC_WORKGROUP:
- printf("", entry->name);
- if (*dircolor) {
- printf("", dircolor);
- }
- printf("%s", entry->name);
- if (*dircolor) {
- printf("");
- }
- puts(" WORKGROUP");
+ smb_add_link(&string, entry, " WORKGROUP ", dircolor);
break;
case SMBC_SERVER:
- printf("", entry->name);
- if (*dircolor) {
- printf("", dircolor);
- }
- printf("%s", entry->name);
- if (*dircolor) {
- printf("");
- }
- printf(" SERVER ");
- puts(entry->comment ? entry->comment : "");
+ smb_add_link(&string, entry, " SERVER ", dircolor);
+ if (entry->comment) add_to_string(&string, entry->comment);
break;
case SMBC_FILE_SHARE:
- printf("", entry->name);
- if (*dircolor) {
- printf("", dircolor);
- }
- printf("%s", entry->name);
- if (*dircolor) {
- printf("");
- }
- printf(" FILE SHARE ");
- puts(entry->comment ? entry->comment : "");
+ smb_add_link(&string, entry, " FILE SHARE ", dircolor);
+ if (entry->comment) add_to_string(&string, entry->comment);
break;
case SMBC_PRINTER_SHARE:
- printf("%s PRINTER ", entry->name);
- puts(entry->comment ? entry->comment : "");
+ add_to_string(&string, entry->name);
+ add_to_string(&string, " PRINTER ");
+ if (entry->comment) add_to_string(&string, entry->comment);
break;
case SMBC_COMMS_SHARE:
- printf("%s COMM\n", entry->name);
+ add_to_string(&string, entry->name);
+ add_to_string(&string, " COMM");
break;
case SMBC_IPC_SHARE:
- printf("%s IPC\n", entry->name);
+ add_to_string(&string, entry->name);
+ add_to_string(&string, " IPC");
break;
case SMBC_DIR:
- printf("", entry->name);
- if (*dircolor) {
- printf("", dircolor);
- }
- printf("%s", entry->name);
- if (*dircolor) {
- printf("");
- }
- puts("");
+ smb_add_link(&string, entry, NULL, dircolor);
break;
case SMBC_LINK:
- printf("%s Link\n", entry->name, entry->name);
+ smb_add_link(&string, entry, " Link", &zero);
break;
case SMBC_FILE:
- printf("%s\n", entry->name, entry->name);
+ smb_add_link(&string, entry, NULL, &zero);
break;
default:
/* unknown type */
break;
}
+ puts(string.source);
+ done_string(&string);
}
static void