* Local functions...
*/
-static ipp_t *parse_collection(_ipp_file_t *f, _ipp_vars_t *v, _ipp_ferror_cb_t errorcb, void *user_data);
-static int parse_value(_ipp_file_t *f, _ipp_vars_t *v, _ipp_ferror_cb_t errorcb, void *user_data, ipp_t *ipp, ipp_attribute_t **attr, int element);
-static void report_error(_ipp_file_t *f, _ipp_ferror_cb_t errorcb, void *user_data, const char *message, ...) __attribute((__format__ (__printf__, 4, 5)));
+static ipp_t *parse_collection(_ipp_file_t *f, _ipp_vars_t *v, void *user_data);
+static int parse_value(_ipp_file_t *f, _ipp_vars_t *v, void *user_data, ipp_t *ipp, ipp_attribute_t **attr, int element);
+static void report_error(_ipp_file_t *f, _ipp_vars_t *v, void *user_data, const char *message, ...) __attribute((__format__ (__printf__, 4, 5)));
/*
_ippFileParse(
_ipp_vars_t *v, /* I - Variables */
const char *filename, /* I - Name of file to parse */
- _ipp_ftoken_cb_t tokencb, /* I - Callback for unknown tokens */
- _ipp_ferror_cb_t errorcb, /* I - Callback for errors */
void *user_data) /* I - User data pointer */
{
_ipp_file_t f; /* IPP data file information */
+ ipp_t *attrs = NULL; /* Active IPP message */
ipp_attribute_t *attr = NULL; /* Current attribute */
char token[1024]; /* Token string */
+ ipp_t *ignored = NULL; /* Ignored attributes */
- DEBUG_printf(("_ippFileParse(v=%p, filename=\"%s\", tokencb=%p, errorcb=%p, user_data=%p)", (void *)v, filename, (void *)tokencb, (void *)errorcb, user_data));
+ DEBUG_printf(("_ippFileParse(v=%p, filename=\"%s\", user_data=%p)", (void *)v, filename, user_data));
/*
* Initialize file info...
* Do the callback with a NULL token to setup any initial state...
*/
- (*tokencb)(&f, v, user_data, NULL);
+ (*v->tokencb)(&f, v, user_data, NULL);
/*
* Read data file, using the callback function as needed...
}
else
{
- report_error(&f, errorcb, user_data, "Missing %s name and/or value on line %d of \"%s\".", token, f.linenum, f.filename);
+ report_error(&f, v, user_data, "Missing %s name and/or value on line %d of \"%s\".", token, f.linenum, f.filename);
break;
}
}
if (!_ippFileReadToken(&f, syntax, sizeof(syntax)))
{
- report_error(&f, errorcb, user_data, "Missing ATTR syntax on line %d of \"%s\".", f.linenum, f.filename);
+ report_error(&f, v, user_data, "Missing ATTR syntax on line %d of \"%s\".", f.linenum, f.filename);
break;
}
else if ((value_tag = ippTagValue(syntax)) < IPP_TAG_UNSUPPORTED_VALUE)
{
- report_error(&f, errorcb, user_data, "Bad ATTR syntax \"%s\" on line %d of \"%s\".", syntax, f.linenum, f.filename);
+ report_error(&f, v, user_data, "Bad ATTR syntax \"%s\" on line %d of \"%s\".", syntax, f.linenum, f.filename);
break;
}
if (!_ippFileReadToken(&f, name, sizeof(name)) || !name[0])
{
- report_error(&f, errorcb, user_data, "Missing ATTR name on line %d of \"%s\".", f.linenum, f.filename);
+ report_error(&f, v, user_data, "Missing ATTR name on line %d of \"%s\".", f.linenum, f.filename);
break;
}
+ if (!v->attrcb || (*v->attrcb)(&f, user_data, name))
+ {
+ /*
+ * Add this attribute...
+ */
+
+ attrs = f.attrs;
+ }
+ else
+ {
+ /*
+ * Ignore this attribute...
+ */
+
+ if (!ignored)
+ ignored = ippNew();
+
+ attrs = ignored;
+ }
+
if (value_tag < IPP_TAG_INTEGER)
{
/*
* Add out-of-band attribute - no value string needed...
*/
- ippAddOutOfBand(f.attrs, f.group_tag, value_tag, name);
+ ippAddOutOfBand(attrs, f.group_tag, value_tag, name);
}
else
{
* Add attribute with one or more values...
*/
- attr = ippAddString(f.attrs, f.group_tag, value_tag, name, NULL, NULL);
+ attr = ippAddString(attrs, f.group_tag, value_tag, name, NULL, NULL);
- if (!parse_value(&f, v, errorcb, user_data, f.attrs, &attr, 0))
+ if (!parse_value(&f, v, user_data, attrs, &attr, 0))
break;
}
* Additional value...
*/
- if (!parse_value(&f, v, errorcb, user_data, f.attrs, &attr, ippGetCount(attr)))
+ if (!parse_value(&f, v, user_data, attrs, &attr, ippGetCount(attr)))
break;
}
else
* Something else...
*/
- attr = NULL;
+ attr = NULL;
+ attrs = NULL;
- if (!(*tokencb)(&f, v, user_data, token))
+ if (!(*v->tokencb)(&f, v, user_data, token))
break;
}
}
/*
- * Close the file and free attributes, then return...
+ * Close the file and free ignored attributes, then return any attributes we
+ * kept...
*/
cupsFileClose(f.fp);
+ ippDelete(ignored);
return (f.attrs);
}
parse_collection(
_ipp_file_t *f, /* I - IPP data file */
_ipp_vars_t *v, /* I - IPP variables */
- _ipp_ferror_cb_t errorcb, /* I - Error callback */
void *user_data) /* I - User data pointer */
{
ipp_t *col = ippNew(); /* Collection value */
if (!_ippFileReadToken(f, syntax, sizeof(syntax)))
{
- report_error(f, errorcb, user_data, "Missing ATTR syntax on line %d of \"%s\".", f->linenum, f->filename);
+ report_error(f, v, user_data, "Missing ATTR syntax on line %d of \"%s\".", f->linenum, f->filename);
ippDelete(col);
col = NULL;
break;
}
else if ((value_tag = ippTagValue(syntax)) < IPP_TAG_UNSUPPORTED_VALUE)
{
- report_error(f, errorcb, user_data, "Bad ATTR syntax \"%s\" on line %d of \"%s\".", syntax, f->linenum, f->filename);
+ report_error(f, v, user_data, "Bad ATTR syntax \"%s\" on line %d of \"%s\".", syntax, f->linenum, f->filename);
ippDelete(col);
col = NULL;
break;
if (!_ippFileReadToken(f, name, sizeof(name)) || !name[0])
{
- report_error(f, errorcb, user_data, "Missing ATTR name on line %d of \"%s\".", f->linenum, f->filename);
+ report_error(f, v, user_data, "Missing ATTR name on line %d of \"%s\".", f->linenum, f->filename);
ippDelete(col);
col = NULL;
break;
attr = ippAddString(col, IPP_TAG_ZERO, value_tag, name, NULL, NULL);
- if (!parse_value(f, v, errorcb, user_data, col, &attr, 0))
+ if (!parse_value(f, v, user_data, col, &attr, 0))
{
ippDelete(col);
col = NULL;
* Additional value...
*/
- if (!parse_value(f, v, errorcb, user_data, col, &attr, ippGetCount(attr)))
+ if (!parse_value(f, v, user_data, col, &attr, ippGetCount(attr)))
{
ippDelete(col);
col = NULL;
* Something else...
*/
- report_error(f, errorcb, user_data, "Unknown directive \"%s\" on line %d of \"%s\".", token, f->linenum, f->filename);
+ report_error(f, v, user_data, "Unknown directive \"%s\" on line %d of \"%s\".", token, f->linenum, f->filename);
ippDelete(col);
col = NULL;
attr = NULL;
static int /* O - 1 on success or 0 on error */
parse_value(_ipp_file_t *f, /* I - IPP data file */
_ipp_vars_t *v, /* I - IPP variables */
- _ipp_ferror_cb_t errorcb, /* I - Error callback */
void *user_data,/* I - User data pointer */
ipp_t *ipp, /* I - IPP message */
ipp_attribute_t **attr, /* IO - IPP attribute */
if (!_ippFileReadToken(f, temp, sizeof(temp)))
{
- report_error(f, errorcb, user_data, "Missing value on line %d of \"%s\".", f->linenum, f->filename);
+ report_error(f, v, user_data, "Missing value on line %d of \"%s\".", f->linenum, f->filename);
return (0);
}
if (ptr <= value || xres <= 0 || yres <= 0 || !ptr || (_cups_strcasecmp(ptr, "dpi") && _cups_strcasecmp(ptr, "dpc") && _cups_strcasecmp(ptr, "dpcm") && _cups_strcasecmp(ptr, "other")))
{
- report_error(f, errorcb, user_data, "Bad resolution value \"%s\" on line %d of \"%s\".", value, f->linenum, f->filename);
+ report_error(f, v, user_data, "Bad resolution value \"%s\" on line %d of \"%s\".", value, f->linenum, f->filename);
return (0);
}
if (sscanf(value, "%d-%d", &lower, &upper) != 2)
{
- report_error(f, errorcb, user_data, "Bad rangeOfInteger value \"%s\" on line %d of \"%s\".", value, f->linenum, f->filename);
+ report_error(f, v, user_data, "Bad rangeOfInteger value \"%s\" on line %d of \"%s\".", value, f->linenum, f->filename);
return (0);
}
if (strcmp(value, "{"))
{
- report_error(f, errorcb, user_data, "Bad ATTR collection value on line %d of \"%s\".", f->linenum, f->filename);
+ report_error(f, v, user_data, "Bad ATTR collection value on line %d of \"%s\".", f->linenum, f->filename);
return (0);
}
- if ((col = parse_collection(f, v, errorcb, user_data)) == NULL)
+ if ((col = parse_collection(f, v, user_data)) == NULL)
return (0);
status = ippSetCollection(ipp, attr, element, col);
break;
default :
- report_error(f, errorcb, user_data, "Unsupported ATTR value on line %d of \"%s\".", f->linenum, f->filename);
+ report_error(f, v, user_data, "Unsupported ATTR value on line %d of \"%s\".", f->linenum, f->filename);
return (0);
}
static void
report_error(
- _ipp_file_t *f, /* I - IPP data file */
- _ipp_ferror_cb_t errorcb, /* I - Error callback function, if any */
- void *user_data, /* I - User data pointer */
- const char *message, /* I - Printf-style message */
+ _ipp_file_t *f, /* I - IPP data file */
+ _ipp_vars_t *v, /* I - Error callback function, if any */
+ void *user_data, /* I - User data pointer */
+ const char *message, /* I - Printf-style message */
...) /* I - Additional arguments as needed */
{
char buffer[8192]; /* Formatted string */
vsnprintf(buffer, sizeof(buffer), message, ap);
va_end(ap);
- if (errorcb)
- (*errorcb)(f, user_data, buffer);
+ if (v->errorcb)
+ (*v->errorcb)(f, user_data, buffer);
else
fprintf(stderr, "%s\n", buffer);
}