-
Notifications
You must be signed in to change notification settings - Fork 287
Make printer's DNS-SD Service Names freely configurable #1570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -485,7 +485,45 @@ dnssdRegisterPrinter( | |
|
|
||
| if (!p->reg_name) | ||
| { | ||
| if (p->info && strlen(p->info) > 0) | ||
| if (DNSSDServiceName && DNSSDServiceName[0] != '\0') { | ||
| char *s = DNSSDServiceName, *e = name + sizeof(name), *q = name, c; | ||
|
|
||
| while (1) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "while (*src && dst < dstend)"? |
||
| c = *s++; | ||
| /* assert(q < e); */ | ||
| if (c == '\0' || q == e - 1) { | ||
| *q = '\0'; | ||
| break; | ||
| } else if (c == '%') { | ||
| c = *s++; | ||
| if (c == '\0') { /* putting this into the case would need a break 2 */ | ||
| *q = '\0'; | ||
| break; | ||
| } else if (c == '%') { /* could be put into case */ | ||
| *q++ = '%'; | ||
| } else { | ||
| char *r; | ||
| switch (c) { | ||
| case 'n': r = p->name; break; | ||
| case 'l': r = p->location; break; | ||
| case 'i': r = p->info; break; | ||
| case 'm': r = p->make_model; break; | ||
| case 'c': r = DNSSDComputerName; break; | ||
| default: continue; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe log a warning message for unknown substitution characters? |
||
| } | ||
| if (r == NULL) continue; | ||
| q += strlcpy(q, r, e - q); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. strlcpy isn't standard. cupsCopyString is the CUPS API that uses strlcpy or its equivalent. But the return value is the number of characters that would have been copied if there was infinite space - I usually do copy and then "q += strlen(q)". |
||
| if (q >= e) { | ||
| *(e - 1) = '\0'; | ||
| break; | ||
| } | ||
| } | ||
| } else { | ||
| *q++ = c; | ||
| } | ||
| } | ||
| } | ||
| else if (p->info && strlen(p->info) > 0) | ||
| { | ||
| if (DNSSDComputerName) | ||
| snprintf(name, sizeof(name), "%s @ %s", p->info, DNSSDComputerName); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The normal coding style here would be to set the end pointer to "name + sizeof(name) - 1" to leave room for the NUL at the end.
Also, you might use "src", "dst", and "dstend" as variable names to make things clearer... :)