📄 ipp.c
字号:
for (i = 0, value = attr->values; i < num_values; i ++, value ++) { value->range.lower = lower[i]; value->range.upper = upper[i]; } return (attr);}/* * 'ippAddResolution()' - Add a resolution value to an IPP request. */ipp_attribute_t * /* O - New attribute */ippAddResolution(ipp_t *ipp, /* I - IPP request */ ipp_tag_t group, /* I - IPP group */ const char *name, /* I - Name of attribute */ ipp_res_t units, /* I - Units for resolution */ int xres, /* I - X resolution */ int yres) /* I - Y resolution */{ ipp_attribute_t *attr; /* New attribute */ if (ipp == NULL || name == NULL) return (NULL); if ((attr = _ipp_add_attr(ipp, 1)) == NULL) return (NULL); attr->name = strdup(name); attr->group_tag = group; attr->value_tag = IPP_TAG_RESOLUTION; attr->values[0].resolution.xres = xres; attr->values[0].resolution.yres = yres; attr->values[0].resolution.units = units; return (attr);}/* * 'ippAddResolutions()' - Add resolution values to an IPP request. */ipp_attribute_t * /* O - New attribute */ippAddResolutions(ipp_t *ipp, /* I - IPP request */ ipp_tag_t group, /* I - IPP group */ const char *name, /* I - Name of attribute */ int num_values, /* I - Number of values */ ipp_res_t units, /* I - Units for resolution */ const int *xres, /* I - X resolutions */ const int *yres) /* I - Y resolutions */{ int i; /* Looping var */ ipp_attribute_t *attr; /* New attribute */ ipp_value_t *value; /* Current value */ if (ipp == NULL || name == NULL || num_values < 1) return (NULL); if ((attr = _ipp_add_attr(ipp, num_values)) == NULL) return (NULL); attr->name = strdup(name); attr->group_tag = group; attr->value_tag = IPP_TAG_RESOLUTION; if (xres != NULL && yres != NULL) for (i = 0, value = attr->values; i < num_values; i ++, value ++) { value->resolution.xres = xres[i]; value->resolution.yres = yres[i]; value->resolution.units = units; } return (attr);}/* * 'ippAddSeparator()' - Add a group separator to an IPP request. */ipp_attribute_t * /* O - New attribute */ippAddSeparator(ipp_t *ipp) /* I - IPP request */{ ipp_attribute_t *attr; /* New attribute */ DEBUG_printf(("ippAddSeparator(%p)\n", ipp)); if (ipp == NULL) return (NULL); if ((attr = _ipp_add_attr(ipp, 0)) == NULL) return (NULL); attr->group_tag = IPP_TAG_ZERO; attr->value_tag = IPP_TAG_ZERO; return (attr);}/* * 'ippDateToTime()' - Convert from RFC 1903 Date/Time format to UNIX time * in seconds. */time_t /* O - UNIX time value */ippDateToTime(const ipp_uchar_t *date) /* I - RFC 1903 date info */{ struct tm unixdate; /* UNIX date/time info */ time_t t; /* Computed time */ memset(&unixdate, 0, sizeof(unixdate)); /* * RFC-1903 date/time format is: * * Byte(s) Description * ------- ----------- * 0-1 Year (0 to 65535) * 2 Month (1 to 12) * 3 Day (1 to 31) * 4 Hours (0 to 23) * 5 Minutes (0 to 59) * 6 Seconds (0 to 60, 60 = "leap second") * 7 Deciseconds (0 to 9) * 8 +/- UTC * 9 UTC hours (0 to 11) * 10 UTC minutes (0 to 59) */ unixdate.tm_year = ((date[0] << 8) | date[1]) - 1900; unixdate.tm_mon = date[2] - 1; unixdate.tm_mday = date[3]; unixdate.tm_hour = date[4]; unixdate.tm_min = date[5]; unixdate.tm_sec = date[6]; t = mktime(&unixdate); if (date[8] == '-') t += date[9] * 3600 + date[10] * 60; else t -= date[9] * 3600 + date[10] * 60; return (t);}/* * 'ippDelete()' - Delete an IPP request. */voidippDelete(ipp_t *ipp) /* I - IPP request */{ ipp_attribute_t *attr, /* Current attribute */ *next; /* Next attribute */ DEBUG_printf(("ippDelete(): %p\n", ipp)); if (ipp == NULL) return; for (attr = ipp->attrs; attr != NULL; attr = next) { next = attr->next; _ipp_free_attr(attr); } free(ipp);}/* * 'ippDeleteAttribute()' - Delete a single attribute in an IPP request. */voidippDeleteAttribute(ipp_t *ipp, /* I - IPP request */ ipp_attribute_t *attr) /* I - Attribute to delete */{}/* * 'ippFindAttribute()' - Find a named attribute in a request... */ipp_attribute_t * /* O - Matching attribute */ippFindAttribute(ipp_t *ipp, /* I - IPP request */ const char *name, /* I - Name of attribute */ ipp_tag_t type) /* I - Type of attribute */{ DEBUG_printf(("ippFindAttribute(%p, \'%s\')\n", ipp, name)); if (ipp == NULL || name == NULL) return (NULL); /* * Reset the current pointer... */ ipp->current = NULL; /* * Search for the attribute... */ return (ippFindNextAttribute(ipp, name, type));}/* * 'ippFindNextAttribute()' - Find the next named attribute in a request... */ipp_attribute_t * /* O - Matching attribute */ippFindNextAttribute(ipp_t *ipp, /* I - IPP request */ const char *name, /* I - Name of attribute */ ipp_tag_t type) /* I - Type of attribute */{ ipp_attribute_t *attr; /* Current atttribute */ ipp_tag_t value_tag; /* Value tag */ DEBUG_printf(("ippFindNextAttribute(%p, \'%s\')\n", ipp, name)); if (ipp == NULL || name == NULL) return (NULL); if (ipp->current) attr = ipp->current->next; else attr = ipp->attrs; for (; attr != NULL; attr = attr->next) { DEBUG_printf(("ippFindAttribute: attr = %p, name = \'%s\'\n", attr, attr->name)); value_tag = (ipp_tag_t)(attr->value_tag & IPP_TAG_MASK); if (attr->name != NULL && strcasecmp(attr->name, name) == 0 && (value_tag == type || type == IPP_TAG_ZERO || (value_tag == IPP_TAG_TEXTLANG && type == IPP_TAG_TEXT) || (value_tag == IPP_TAG_NAMELANG && type == IPP_TAG_NAME))) { ipp->current = attr; return (attr); } } ipp->current = NULL; return (NULL);}/* * 'ippLength()' - Compute the length of an IPP request. */size_t /* O - Size of IPP request */ippLength(ipp_t *ipp) /* I - IPP request */{ return (ipp_length(ipp, 0));}/* * 'ippNew()' - Allocate a new IPP request. */ipp_t * /* O - New IPP request */ippNew(void){ ipp_t *temp; /* New IPP request */ if ((temp = (ipp_t *)calloc(1, sizeof(ipp_t))) != NULL) { /* * Default to IPP 1.1... */ temp->request.any.version[0] = 1; temp->request.any.version[1] = 1; } DEBUG_printf(("ippNew(): %p\n", temp)); return (temp);}/* * 'ippRead()' - Read data for an IPP request from a HTTP connection. */ipp_state_t /* O - Current state */ippRead(http_t *http, /* I - HTTP connection */ ipp_t *ipp) /* I - IPP data */{ DEBUG_printf(("ippRead(http=%p, ipp=%p), data_remaining=%d\n", http, ipp, http ? http->data_remaining : -1)); if (http == NULL) return (IPP_ERROR); DEBUG_printf(("http->state = %d\n", http->state)); return (ippReadIO(http, (ipp_iocb_t)ipp_read_http, http->blocking || http->used != 0, NULL, ipp));}/* * 'ippReadFile()' - Read data for an IPP request from a file. */ipp_state_t /* O - Current state */ippReadFile(int fd, /* I - HTTP data */ ipp_t *ipp) /* I - IPP data */{ DEBUG_printf(("ippReadFile(%d, %p)\n", fd, ipp)); return (ippReadIO(&fd, (ipp_iocb_t)ipp_read_file, 1, NULL, ipp));}/* * 'ippReadIO()' - Read data for an IPP request. */ipp_state_t /* O - Current state */ippReadIO(void *src, /* I - Data source */ ipp_iocb_t cb, /* I - Read callback function */ int blocking, /* I - Use blocking IO? */ ipp_t *parent, /* I - Parent request, if any */ ipp_t *ipp) /* I - IPP data */{ int n; /* Length of data */ unsigned char buffer[32768], /* Data buffer */ *bufptr; /* Pointer into buffer */ ipp_attribute_t *attr; /* Current attribute */ ipp_tag_t tag; /* Current tag */ ipp_value_t *value; /* Current value */ DEBUG_printf(("ippReadIO(%p, %p, %d, %p, %p)\n", src, cb, blocking, parent, ipp)); if (src == NULL || ipp == NULL) return (IPP_ERROR); switch (ipp->state) { case IPP_IDLE : ipp->state ++; /* Avoid common problem... */ case IPP_HEADER : if (parent == NULL) { /* * Get the request header... */ if ((n = (*cb)(src, buffer, 8)) < 8) { DEBUG_printf(("ippReadIO: Unable to read header (%d bytes read)!\n", n)); return (n == 0 ? IPP_IDLE : IPP_ERROR); } /* * Verify the major version number... */ if (buffer[0] != 1) { DEBUG_printf(("ippReadIO: version number (%d.%d) is bad.\n", buffer[0], buffer[1])); return (IPP_ERROR); } /* * Then copy the request header over... */ ipp->request.any.version[0] = buffer[0]; ipp->request.any.version[1] = buffer[1]; ipp->request.any.op_status = (buffer[2] << 8) | buffer[3]; ipp->request.any.request_id = (((((buffer[4] << 8) | buffer[5]) << 8) | buffer[6]) << 8) | buffer[7]; } ipp->state = IPP_ATTRIBUTE; ipp->current = NULL; ipp->curtag = IPP_TAG_ZERO; DEBUG_printf(("ippReadIO: version=%d.%d\n", buffer[0], buffer[1])); DEBUG_printf(("ippReadIO: op_status=%04x\n", ipp->request.any.op_status)); DEBUG_printf(("ippReadIO: request_id=%d\n", ipp->request.any.request_id)); /* * If blocking is disabled, stop here... */ if (!blocking) break; case IPP_ATTRIBUTE : while ((*cb)(src, buffer, 1) > 0) { /* * Read this attribute... */ tag = (ipp_tag_t)buffer[0]; if (tag == IPP_TAG_END) { /* * No more attributes left... */ DEBUG_puts("ippReadIO: IPP_TAG_END!"); ipp->state = IPP_DATA; break; } else if (tag < IPP_TAG_UNSUPPORTED_VALUE) { /* * Group tag... Set the current group and continue... */ if (ipp->curtag == tag) ippAddSeparator(ipp); ipp->curtag = tag; ipp->current = NULL; DEBUG_printf(("ippReadIO: group tag = %x\n", tag)); continue; } DEBUG_printf(("ippReadIO: value tag = %x\n", tag)); /* * Get the name... */ if ((*cb)(src, buffer, 2) < 2) { DEBUG_puts("ippReadIO: unable to read name length!"); return (IPP_ERROR); } n = (buffer[0] << 8) | buffer[1]; if (n > (sizeof(buffer) - 1)) { DEBUG_printf(("ippReadIO: bad name length %d!\n", n)); return (IPP_ERROR); } DEBUG_printf(("ippReadIO: name length = %d\n", n)); if (n == 0 && tag != IPP_TAG_MEMBERNAME) { /* * More values for current attribute... */ if (ipp->current == NULL) return (IPP_ERROR); attr = ipp->current; /* * Make sure we aren't adding a new value of a different * type... */ if (attr->value_tag == IPP_TAG_ZERO) { attr->value_tag = tag; } else if (attr->value_tag == IPP_TAG_STRING || (attr->value_tag >= IPP_TAG_TEXTLANG && attr->value_tag <= IPP_TAG_MIMETYPE)) { /* * String values can sometimes come across in different * forms; accept sets of differing values... */ if (tag != IPP_TAG_STRING && (tag < IPP_TAG_TEXTLANG || tag > IPP_TAG_MIMETYPE)) return (IPP_ERROR);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -