Skip to content
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

GSoC IPPServer Functionality #120 #121 #122 #139

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 36 additions & 38 deletions cups/ipp-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,31 +647,37 @@ parse_value(_ipp_file_t *f, /* I - IPP data file */
{
if(value[0]=='<') /* Input is binary(in form of hex) values*/
{
memmove(value, value+1, strlen(value)); /* Eliminate the '<' sign */
char value_concat[50000]; /* Concatenated string with hexadecimal values without whitespace */
int starting_line_number = f->linenum;
while(value[strlen(value)-1] != '>')
{
strcat(value_concat,value);
if (!_ippFileReadToken(f, value, sizeof(value)))
{
report_error(f, v, user_data, "hexadecimal value not terminated starting line %d of \"%s\".", starting_line_number, f->filename);
return (0);
}
}
value[(strlen(value)-1)]='\0'; /* Eliminate the last '>' sign */
strcat(value_concat,value); /* Final concatenation for hexadecimal value to be complete*/
int i; /* Iterating variable*/
for(i=0;i<strlen(value_concat);i++) /* Sanity Check*/
{
if(!(value_concat[i] >= '0' && value_concat[i]<= '9') || (value_concat[i]>='a' && value_concat[i]<='f'))
{
report_error(f, v, user_data, "Bad hexadecimal value \"%s\" on line %d of \"%s\".", value_concat, starting_line_number, f->filename);
return (0);
}
}
return (ippSetOctetString(ipp, attr, element, value_concat, (int)strlen(value_concat)));
}
unsigned char data[32767], *dataptr = data; /*data: decoded hex, dataptr:iterating pointer */
char *valptr = value + 1; /*Value iterating pointer*/
while (1)
{
while (isxdigit(valptr[0]) && isxdigit(valptr[1]))
{
char c = valptr[0], d=valptr[1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need "tolower" here, as "isxdigit" allows upper and lowercase letters.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

/*decode hex pair into 8 bit string */
dataptr = (d>='a')?(10+d-'a'):(d-'0') + (c>= 'a') ? ((10+c -'a') << 4) : ((c-'0') <<4);
valptr += 2;
dataptr ++;
if (dataptr >= (data + sizeof(data)))
break;
}
if (*valptr == '>')
break;
else if (*valptr) /*If string is not in pairs, or has a non-hex digit*/
{
report_error(f, v, user_data, "Bad hexadecimal value \"%s\" on line %d of \"%s\".", value+1, f->linenum, f->filename);
return (0);
}
if (!_ippFileReadToken(f, value, sizeof(value)))
{
report_error(f, v, user_data, "Missing value on line %d of \"%s\".", f->linenum, f->filename);
return (0);
}
valptr = value;
}
return (ippSetOctetString(ipp, attr, element, data, (int)strlen(data)));
}

else
{
return (ippSetOctetString(ipp, attr, element, value, (int)strlen(value))); /* If a quoted string like "..", pass it on */
Expand All @@ -682,19 +688,6 @@ parse_value(_ipp_file_t *f, /* I - IPP data file */
break;

case IPP_TAG_TEXTLANG :
{
(*attr)->values[element].string.text = _cupsStrAlloc(value);
if (!_ippFileReadToken(f, value, sizeof(value)))
{
report_error(f, v, user_data, "No Language Data in line %d of \"%s\".", f->linenum, f->filename);
return (0);
}
memmove(value, value+1, strlen(value));
value[strlen(value)-1]='\0'; /* Purge parenthesis */
(*attr)->values[element].string.language = _cupsStrAlloc(value);

}
break;
case IPP_TAG_NAMELANG :
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the same code for IPP_TAG_NAMELANG and IPP_TAG_TEXTLANG (with the two case statements together feeding into the same code).

(*attr)->values[element].string.text = _cupsStrAlloc(value);
Expand All @@ -703,6 +696,11 @@ parse_value(_ipp_file_t *f, /* I - IPP data file */
report_error(f, v, user_data, "No Language Data in line %d of \"%s\".", f->linenum, f->filename);
return (0);
}
if (!(value[0] == '(' && value[strlen(value)-1] == ')'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you need to read another token here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi!
For input like "my string"(language), the var, value, at line 695, initially contains 'my string' , which then is fed into string.text.
Next a token i.e. (language) is read into var value at line 696, which then is fed into string.language.
I don't think another token needs to be read here, is it ?

{
report_error(f, v, user_data, "Bad Language Value in line %d of \"%s\".", f->linenum, f->filename);
return (0);
}
memmove(value, value+1, strlen(value));
value[strlen(value)-1]='\0'; /* Purge parenthesis */
(*attr)->values[element].string.language = _cupsStrAlloc(value);
Expand Down