-
Notifications
You must be signed in to change notification settings - Fork 195
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
Added the functionality of Preserved Comments in cupsd.conf when cups… #640
base: master
Are you sure you want to change the base?
Changes from 5 commits
4d13be6
b9c57d1
ccf71a9
d999b0d
1c0ae05
d08c54f
0a6b3b3
d351867
d92236a
f241386
952fd3f
7470d73
d9c1986
04b6730
07e9450
5150a47
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 |
---|---|---|
|
@@ -842,6 +842,142 @@ cupsFileGetConf(cups_file_t *fp, /* I - CUPS file */ | |
} | ||
|
||
|
||
/* | ||
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. Move the function definition to an alphabetically correct place in the file (under _cupsFileCheckFilter()) |
||
* 'cupsFileGetConfAndComments()' - Get line and comments from a configuration file. | ||
*/ | ||
|
||
char * /* O - Line read or @code NULL@ on end of file or error */ | ||
_cupsFileGetConfAndComments(cups_file_t *fp, /* I - CUPS file */ | ||
char *buf, /* O - String buffer */ | ||
size_t buflen, /* I - Size of string buffer */ | ||
char **value, /* O - Pointer to value */ | ||
int *linenum) /* IO - Current line number */ | ||
{ | ||
char *ptr; /* Pointer into line */ | ||
|
||
|
||
/* | ||
* Range check input... | ||
*/ | ||
|
||
DEBUG_printf(("2cupsFileGetConf(fp=%p, buf=%p, buflen=" CUPS_LLFMT | ||
", value=%p, linenum=%p)", (void *)fp, (void *)buf, CUPS_LLCAST buflen, (void *)value, (void *)linenum)); | ||
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. Remains of copy&paste :) |
||
|
||
if (!fp || (fp->mode != 'r' && fp->mode != 's') || | ||
!buf || buflen < 2 || !value) | ||
{ | ||
if (value) | ||
*value = NULL; | ||
|
||
return (NULL); | ||
} | ||
|
||
/* | ||
* Read the next non-comment line... | ||
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. Copy&paste remain... |
||
*/ | ||
|
||
*value = NULL; | ||
|
||
while (cupsFileGets(fp, buf, buflen)) | ||
{ | ||
(*linenum) ++; | ||
|
||
/* | ||
* Strip any comments... | ||
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. Copy and paste leftover. |
||
*/ | ||
|
||
if ((ptr = strchr(buf, '#')) != NULL) | ||
{ | ||
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. If we go with passing comments via 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. @zdohnal I made the changes as you requested. Now I 'm using line variable to get comments. Please review them. |
||
if (ptr > buf && ptr[-1] == '\\') | ||
{ | ||
// Unquote the #... | ||
_cups_strcpy(ptr - 1, ptr); | ||
} | ||
else | ||
{ | ||
// Strip the comment and any trailing whitespace... | ||
while (ptr > buf) | ||
{ | ||
if (!_cups_isspace(ptr[-1])) | ||
break; | ||
|
||
ptr --; | ||
} | ||
|
||
return (buf); | ||
*ptr = '\0'; | ||
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. This will become a dead code if we return before that. Additionally I've realized we should deal with inline comments in case they appear (even though they are prohibited by cupsd.conf man page) in a way. So I propose:
So the block |
||
} | ||
} | ||
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. Additionally you should review every cupsFilePut() below in Rephrase the comments mentioned in The code:
The default cupsd.conf.in:
so once you remove the cupsFilePut(), update the cupsd.conf.in to look like this f.e.:
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.
@zdohnal for the above part what should be the comment that I need to write in conf/cupsd.conf.in ? 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. For example:
|
||
|
||
/* | ||
* Strip leading whitespace... | ||
*/ | ||
|
||
for (ptr = buf; _cups_isspace(*ptr); ptr ++); | ||
|
||
if (ptr > buf) | ||
_cups_strcpy(buf, ptr); | ||
|
||
/* | ||
* See if there is anything left... | ||
*/ | ||
|
||
if (buf[0]) | ||
{ | ||
/* | ||
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. Here we could check whether the first char is # and if so, return buf. With appropriate comment. |
||
* Yes, grab any value and return... | ||
*/ | ||
|
||
for (ptr = buf; *ptr; ptr ++) | ||
if (_cups_isspace(*ptr)) | ||
break; | ||
|
||
if (*ptr) | ||
{ | ||
/* | ||
* Have a value, skip any other spaces... | ||
*/ | ||
|
||
while (_cups_isspace(*ptr)) | ||
*ptr++ = '\0'; | ||
|
||
if (*ptr) | ||
*value = ptr; | ||
|
||
/* | ||
* Strip trailing whitespace and > for lines that begin with <... | ||
*/ | ||
|
||
ptr += strlen(ptr) - 1; | ||
|
||
if (buf[0] == '<' && *ptr == '>') | ||
*ptr-- = '\0'; | ||
else if (buf[0] == '<' && *ptr != '>') | ||
{ | ||
/* | ||
* Syntax error... | ||
*/ | ||
|
||
*value = NULL; | ||
return (buf); | ||
} | ||
|
||
while (ptr > *value && _cups_isspace(*ptr)) | ||
*ptr-- = '\0'; | ||
} | ||
|
||
/* | ||
* Return the line... | ||
*/ | ||
|
||
return (buf); | ||
} | ||
} | ||
|
||
return (NULL); | ||
} | ||
|
||
|
||
/* | ||
* 'cupsFileGetLine()' - Get a CR and/or LF-terminated line that may | ||
* contain binary data. | ||
|
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.
As I said in the comment, I would let here the simple cupsFilePrintf() as it was there - the code will be simpler and we get rid of the new variable.