⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ipp.c

📁 ipp打印机服务器原代码 注意:请将ipp.gz改为ipp.tar.gz 然后使用tar zxvf ipp.tar.gz解压 站长注意
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * "$Id: ipp.c,v 1.98 2005/01/03 19:29:45 mike Exp $" * *   Internet Printing Protocol support functions for the Common UNIX *   Printing System (CUPS). * *   Copyright 1997-2005 by Easy Software Products, all rights reserved. * *   These coded instructions, statements, and computer programs are the *   property of Easy Software Products and are protected by Federal *   copyright law.  Distribution and use rights are outlined in the file *   "LICENSE.txt" which should have been included with this file.  If this *   file is missing or damaged please contact Easy Software Products *   at: * *       Attn: CUPS Licensing Information *       Easy Software Products *       44141 Airport View Drive, Suite 204 *       Hollywood, Maryland 20636 USA * *       Voice: (301) 373-9600 *       EMail: cups-info@cups.org *         WWW: http://www.cups.org * *   This file is subject to the Apple OS-Developed Software exception. * * Contents: * *   ippAddBoolean()        - Add a boolean attribute to an IPP request. *   ippAddBooleans()       - Add an array of boolean values. *   ippAddDate()           - Add a date attribute to an IPP request. *   ippAddInteger()        - Add a integer attribute to an IPP request. *   ippAddIntegers()       - Add an array of integer values. *   ippAddString()         - Add a language-encoded string to an IPP request. *   ippAddStrings()        - Add language-encoded strings to an IPP request. *   ippAddRange()          - Add a range of values to an IPP request. *   ippAddRanges()         - Add ranges of values to an IPP request. *   ippAddResolution()     - Add a resolution value to an IPP request. *   ippAddResolutions()    - Add resolution values to an IPP request. *   ippAddSeparator()      - Add a group separator to an IPP request. *   ippDateToTime()        - Convert from RFC 1903 Date/Time format to *                            UNIX time in seconds. *   ippDelete()            - Delete an IPP request. *   ippDeleteAttribute()   - Delete a single attribute in an IPP request. *   ippFindAttribute()     - Find a named attribute in a request... *   ippFindNextAttribute() - Find the next named attribute in a request... *   ippLength()            - Compute the length of an IPP request. *   ippNew()               - Allocate a new IPP request. *   ippRead()              - Read data for an IPP request from a HTTP *                            connection. *   ippReadFile()          - Read data for an IPP request from a file. *   ippReadIO()            - Read data for an IPP request. *   ippTimeToDate()        - Convert from UNIX time to RFC 1903 format. *   ippWrite()             - Write data for an IPP request to a HTTP *                            connection. *   ippWriteFile()         - Write data for an IPP request to a file. *   ippWriteIO()           - Write data for an IPP request. *   _ipp_add_attr()        - Add a new attribute to the request. *   _ipp_free_attr()       - Free an attribute. *   ipp_length()           - Compute the length of an IPP request or *                            collection value. *   ipp_read_http()        - Semi-blocking read on a HTTP connection... *   ipp_read_file()        - Read IPP data from a file. *   ipp_write_file()       - Write IPP data to a file. *//* * Include necessary headers... */#include <stdio.h>#include <stdlib.h>#include "string.h"#include "ipp.h"#include "debug.h"#include <ctype.h>#include <errno.h>#ifdef WIN32#  include <io.h>#endif // WIN32/* * Local functions... */static size_t		ipp_length(ipp_t *ipp, int collection);static int		ipp_read_http(http_t *http, ipp_uchar_t *buffer, int length);static int		ipp_read_file(int *fd, ipp_uchar_t *buffer, int length);static int		ipp_write_file(int *fd, ipp_uchar_t *buffer, int length);/* * 'ippAddBoolean()' - Add a boolean attribute to an IPP request. */ipp_attribute_t *				/* O - New attribute */ippAddBoolean(ipp_t      *ipp,			/* I - IPP request */              ipp_tag_t  group,			/* I - IPP group */              const char *name,			/* I - Name of attribute */              char       value)			/* I - Value of attribute */{  ipp_attribute_t	*attr;			/* New attribute */  DEBUG_printf(("ippAddBoolean(%p, %02x, \'%s\', %d)\n", ipp, group, name, value));  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_BOOLEAN;  attr->values[0].boolean = value;  return (attr);}/* * 'ippAddBooleans()' - Add an array of boolean values. */ipp_attribute_t *				/* O - New attribute */ippAddBooleans(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 */	       const char *values)		/* I - Values */{  int			i;			/* Looping var */  ipp_attribute_t	*attr;			/* New attribute */  ipp_value_t		*value;			/* Current value */  DEBUG_printf(("ippAddBooleans(%p, %02x, \'%s\', %d, %p)\n", ipp,                group, name, num_values, values));  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_BOOLEAN;  if (values != NULL)    for (i = 0, value = attr->values;	 i < num_values;	 i ++, value ++)      value->boolean = values[i];  return (attr);}/* * 'ippAddCollection()' - Add a collection value. */ipp_attribute_t *				/* O - New attribute */ippAddCollection(ipp_t      *ipp,		/* I - IPP request */                 ipp_tag_t  group,		/* I - IPP group */		 const char *name,		/* I - Name of attribute */		 ipp_t      *value)		/* I - Value */{  ipp_attribute_t	*attr;			/* New attribute */  DEBUG_printf(("ippAddCollection(%p, %02x, \'%s\', %p)\n", ipp, group, name,                value));  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_BEGIN_COLLECTION;  attr->values[0].collection = value;  return (attr);}/* * 'ippAddCollections()' - Add an array of collection values. */ipp_attribute_t *				/* O - New attribute */ippAddCollections(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 */		  const ipp_t **values)		/* I - Values */{  int			i;			/* Looping var */  ipp_attribute_t	*attr;			/* New attribute */  ipp_value_t		*value;			/* Current value */  DEBUG_printf(("ippAddCollections(%p, %02x, \'%s\', %d, %p)\n", ipp,                group, name, num_values, values));  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_BEGIN_COLLECTION;  if (values != NULL)    for (i = 0, value = attr->values;	 i < num_values;	 i ++, value ++)      value->collection = (ipp_t *)values[i];  return (attr);}/* * 'ippAddDate()' - Add a date attribute to an IPP request. */ipp_attribute_t *				/* O - New attribute */ippAddDate(ipp_t             *ipp,		/* I - IPP request */           ipp_tag_t         group,		/* I - IPP group */	   const char        *name,		/* I - Name of attribute */	   const ipp_uchar_t *value)		/* I - Value */{  ipp_attribute_t	*attr;			/* New attribute */  DEBUG_printf(("ippAddDate(%p, %02x, \'%s\', %p)\n", ipp, group, name,                value));  if (ipp == NULL || name == NULL || value == 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_DATE;  memcpy(attr->values[0].date, value, 11);  return (attr);}/* * 'ippAddInteger()' - Add a integer attribute to an IPP request. */ipp_attribute_t *				/* O - New attribute */ippAddInteger(ipp_t      *ipp,			/* I - IPP request */              ipp_tag_t  group,			/* I - IPP group */	      ipp_tag_t  type,			/* I - Type of attribute */              const char *name,			/* I - Name of attribute */              int        value)			/* I - Value of attribute */{  ipp_attribute_t	*attr;			/* New attribute */  DEBUG_printf(("ippAddInteger(%p, %d, \'%s\', %d)\n", ipp, group, name,                value));  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         = type;  attr->values[0].integer = value;  return (attr);}/* * 'ippAddIntegers()' - Add an array of integer values. */ipp_attribute_t *				/* O - New attribute */ippAddIntegers(ipp_t      *ipp,			/* I - IPP request */               ipp_tag_t  group,		/* I - IPP group */	       ipp_tag_t  type,			/* I - Type of attribute */	       const char *name,		/* I - Name of attribute */	       int        num_values,		/* I - Number of values */	       const int  *values)		/* I - Values */{  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 = type;  if (values != NULL)    for (i = 0, value = attr->values;	 i < num_values;	 i ++, value ++)      value->integer = values[i];  return (attr);}/* * 'ippAddString()' - Add a language-encoded string to an IPP request. */ipp_attribute_t *				/* O - New attribute */ippAddString(ipp_t      *ipp,			/* I - IPP request */             ipp_tag_t  group,			/* I - IPP group */	     ipp_tag_t  type,			/* I - Type of attribute */             const char *name,			/* I - Name of attribute */             const char *charset,		/* I - Character set */             const char *value)			/* I - Value */{  ipp_attribute_t	*attr;			/* New attribute */  if (ipp == NULL || name == NULL)    return (NULL);  if ((attr = _ipp_add_attr(ipp, 1)) == NULL)    return (NULL); /*  * Force value to be English for the POSIX locale...  */  if (type == IPP_TAG_LANGUAGE && strcasecmp(value, "C") == 0)    value = "en"; /*  * Initialize the attribute data...  */  attr->name                      = strdup(name);  attr->group_tag                 = group;  attr->value_tag                 = type;  attr->values[0].string.charset  = ((int)type & IPP_TAG_COPY) ? (char *)charset :                                    charset ? strdup(charset) : NULL;  attr->values[0].string.text     = ((int)type & IPP_TAG_COPY) ? (char *)value :                                    value ? strdup(value) : NULL; /*  * Convert language values to lowercase and change _ to - as needed...  */  if ((type == IPP_TAG_LANGUAGE || type == IPP_TAG_CHARSET) &&      attr->values[0].string.text)  {    char *p;    for (p = attr->values[0].string.text; *p; p ++)      if (*p == '_')        *p = '-';      else        *p = tolower(*p & 255);  }  return (attr);}/* * 'ippAddStrings()' - Add language-encoded strings to an IPP request. */ipp_attribute_t *				/* O - New attribute */ippAddStrings(ipp_t              *ipp,		/* I - IPP request */              ipp_tag_t          group,		/* I - IPP group */	      ipp_tag_t          type,		/* I - Type of attribute */	      const char         *name,		/* I - Name of attribute */	      int                num_values,	/* I - Number of values */	      const char         *charset,	/* I - Character set */	      const char * const *values)	/* I - Values */{  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); /*  * Initialize the attribute data...  */  attr->name      = strdup(name);  attr->group_tag = group;  attr->value_tag = type;  for (i = 0, value = attr->values;       i < num_values;       i ++, value ++)  {    if (i == 0)      value->string.charset = ((int)type & IPP_TAG_COPY) ? (char *)charset :                                   charset ? strdup(charset) : NULL;    else      value->string.charset = attr->values[0].string.charset;    if (values != NULL)    {     /*      * Force language to be English for the POSIX locale...      */      if (type == IPP_TAG_LANGUAGE && strcasecmp(values[i], "C") == 0)	value->string.text = ((int)type & IPP_TAG_COPY) ? "en" :                                      strdup("en");      else	value->string.text = ((int)type & IPP_TAG_COPY) ? (char *)values[i] :                                      strdup(values[i]);    }  }  return (attr);}/* * 'ippAddRange()' - Add a range of values to an IPP request. */ipp_attribute_t *				/* O - New attribute */ippAddRange(ipp_t      *ipp,			/* I - IPP request */            ipp_tag_t  group,			/* I - IPP group */	    const char *name,			/* I - Name of attribute */	    int        lower,			/* I - Lower value */	    int        upper)			/* I - Upper value */{  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_RANGE;  attr->values[0].range.lower = lower;  attr->values[0].range.upper = upper;  return (attr);}/* * 'ippAddRanges()' - Add ranges of values to an IPP request. */ipp_attribute_t *				/* O - New attribute */ippAddRanges(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 */	     const int  *lower,			/* I - Lower values */	     const int  *upper)			/* I - Upper values */{  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_RANGE;  if (lower != NULL && upper != NULL)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -