Skip to content

Commit 150d7ca

Browse files
committed
Issue 557 - Better handling of vendor/model.
1 parent e60040d commit 150d7ca

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/deviceid.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -524,42 +524,52 @@ static int mice_cmp (const void *px, const void *py)
524524
* AX.25 destination field. The form should be APxxxx.
525525
*
526526
* Search the list looking for the maximum length match.
527-
* For example,
528-
* APXR = Xrouter
529-
* APX = Xastir
527+
*
528+
* tocalls was sorted by decreasing length so the search will go from
529+
* most specific to least specific.
530+
* Example: APY350 or APY008 would match those specific models before
531+
* getting to the more generic APY.
530532
*
531533
*------------------------------------------------------------------*/
532534

533535
void deviceid_decode_dest (char *dest, char *device, size_t device_size)
534536
{
535-
strlcpy (device, "UNKNOWN vendor/model", device_size);
536-
537537
if (ptocalls == NULL) {
538538
text_color_set(DW_COLOR_ERROR);
539539
dw_printf("deviceid_decode_dest called without any deviceid data.\n");
540+
strlcpy (device, "Internal error - UNKNOWN vendor/model", device_size);
540541
return;
541542
}
542543

544+
*device = '\0';
545+
543546
for (int n = 0; n < tocalls_count; n++) {
544547
if (strncmp(dest, ptocalls[n].tocall, strlen(ptocalls[n].tocall)) == 0) {
545548

546-
if (ptocalls[n].vendor != NULL) {
549+
if (ptocalls[n].vendor != NULL && ptocalls[n].model != NULL) { // both vendor & model
550+
snprintf (device, device_size, "%s %s", ptocalls[n].vendor, ptocalls[n].model);
551+
}
552+
553+
else if (ptocalls[n].vendor != NULL) { // only vendor
547554
strlcpy (device, ptocalls[n].vendor, device_size);
548555
}
549556

550-
if (ptocalls[n].vendor != NULL && ptocalls[n].model != NULL) {
551-
strlcat (device, " ", device_size);
557+
else if (ptocalls[n].model != NULL) { // only model
558+
strlcpy (device, ptocalls[n].model, device_size);
552559
}
553560

554-
if (ptocalls[n].model != NULL) {
555-
strlcat (device, ptocalls[n].model, device_size);
561+
else { // found in table but no vendor or model
562+
break;
556563
}
564+
557565
return;
558566
}
559567
}
560568

561-
// Not found in table.
569+
// Not found in table. Or found but both vendor and model are missing.
570+
562571
strlcpy (device, "UNKNOWN vendor/model", device_size);
572+
return;
563573

564574
} // end deviceid_decode_dest
565575

0 commit comments

Comments
 (0)