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

📄 ipp.c

📁 ipp打印机服务器原代码 注意:请将ipp.gz改为ipp.tar.gz 然后使用tar zxvf ipp.tar.gz解压 站长注意
💻 C
📖 第 1 页 / 共 5 页
字号:
		    * Write the value tag, name length, and name string...		    */	            			DEBUG_printf(("ippWrite: writing value tag = %x\n", attr->value_tag));	            			DEBUG_printf(("ippWrite: writing name = %d, \'%s\'\n", n, attr->name));			            	    *bufptr++ = attr->value_tag;				    *bufptr++ = n >> 8;				    *bufptr++ = n;				    memcpy(bufptr, attr->name, n);				    bufptr += n;	          		}		  	else		 	{	           /*		    * Get the length of the attribute name, and make sure it won't		    * overflow the buffer...		    */	            			if ((n = strlen(attr->name)) > (sizeof(buffer) - 7))		     			 return (IPP_ERROR);	           /*		    * Write the member name tag, name length, name string, value tag,		    * and empty name for the collection member attribute...		    */			            DEBUG_printf(("ippWrite: writing value tag = %x\n",				                  IPP_TAG_MEMBERNAME));			            DEBUG_printf(("ippWrite: writing name = %d, \'%s\'\n", n, attr->name));			            DEBUG_printf(("ippWrite: writing value tag = %x\n", attr->value_tag));			            DEBUG_puts("ippWrite: writing name = 0, \'\'\n");			            *bufptr++ = IPP_TAG_MEMBERNAME;				    *bufptr++ = 0;				    *bufptr++ = 0;				    *bufptr++ = n >> 8;				    *bufptr++ = n;				    memcpy(bufptr, attr->name, n);				    bufptr += n;				*bufptr++ = attr->value_tag;				*bufptr++ = 0;				*bufptr++ = 0;		  	}         /*	  * Now write the attribute value(s)...	  */	  		switch (attr->value_tag & ~IPP_TAG_COPY)	  		{	    			case IPP_TAG_INTEGER :	    			case IPP_TAG_ENUM :				        for (i = 0, value = attr->values;					     i < attr->num_values;					     i ++, value ++)				        {                  					if ((sizeof(buffer) - (bufptr - buffer)) < 9)		  				{                    						if ((*cb)(dst, buffer, bufptr - buffer) < 0)							            {							              DEBUG_puts("ippWrite: Could not write IPP attribute...");							              return (IPP_ERROR);							            }		    					bufptr = buffer;		  				}						  if (i)						  {						   /*						    * Arrays and sets are done by sending additional						    * values with a zero-length name...						    */				                    *bufptr++ = attr->value_tag;						    *bufptr++ = 0;						    *bufptr++ = 0;						  }		 /*	          * Integers and enumerations are both 4-byte signed		  * (twos-complement) values.		  *		  * Put the 2-byte length and 4-byte value into the buffer...		  */					          *bufptr++ = 0;						  *bufptr++ = 4;						  *bufptr++ = value->integer >> 24;						  *bufptr++ = value->integer >> 16;						  *bufptr++ = value->integer >> 8;						  *bufptr++ = value->integer;						}						break;	    			case IPP_TAG_BOOLEAN :	        				for (i = 0, value = attr->values;						     i < attr->num_values;						     i ++, value ++)					{				                  	if ((sizeof(buffer) - (bufptr - buffer)) < 6)						  {				                   		 if ((*cb)(dst, buffer, bufptr - buffer) < 0)					            		{					              		DEBUG_puts("ippWrite: Could not write IPP attribute...");					              		return (IPP_ERROR);					            		}						    	bufptr = buffer;						  }		  				if (i)						{							   /*							    * Arrays and sets are done by sending additional							    * values with a zero-length name...							    */					                    	*bufptr++ = attr->value_tag;							    *bufptr++ = 0;							    *bufptr++ = 0;						}                 /*		  * Boolean values are 1-byte; 0 = false, 1 = true.		  *		  * Put the 2-byte length and 1-byte value into the buffer...		  */					          *bufptr++ = 0;						  *bufptr++ = 1;						  *bufptr++ = value->boolean;					}					break;	    case IPP_TAG_TEXT :	    case IPP_TAG_NAME :	    case IPP_TAG_KEYWORD :	    case IPP_TAG_STRING :	    case IPP_TAG_URI :	    case IPP_TAG_URISCHEME :	    case IPP_TAG_CHARSET :	    case IPP_TAG_LANGUAGE :	    case IPP_TAG_MIMETYPE :	        for (i = 0, value = attr->values;		     i < attr->num_values;		     i ++, value ++)		{		  if (i)		  {		   /*		    * Arrays and sets are done by sending additional		    * values with a zero-length name...		    */        	    DEBUG_printf(("ippWrite: writing value tag = %x\n",		                  attr->value_tag));        	    DEBUG_printf(("ippWrite: writing name = 0, \'\'\n"));                    if ((sizeof(buffer) - (bufptr - buffer)) < 3)		    {                      if ((*cb)(dst, buffer, bufptr - buffer) < 0)	              {	        	DEBUG_puts("ippWrite: Could not write IPP attribute...");	        	return (IPP_ERROR);	              }		      bufptr = buffer;		    }                    *bufptr++ = attr->value_tag;		    *bufptr++ = 0;		    *bufptr++ = 0;		  }                  if (value->string.text != NULL)                    n = strlen(value->string.text);		  else		    n = 0;                  if (n > (sizeof(buffer) - 2))		    return (IPP_ERROR);                  DEBUG_printf(("ippWrite: writing string = %d, \'%s\'\n", n,		                value->string.text));                  if ((int)(sizeof(buffer) - (bufptr - buffer)) < (n + 2))		  {                    if ((*cb)(dst, buffer, bufptr - buffer) < 0)	            {	              DEBUG_puts("ippWrite: Could not write IPP attribute...");	              return (IPP_ERROR);	            }		    bufptr = buffer;		  }		 /*		  * All simple strings consist of the 2-byte length and		  * character data without the trailing nul normally found		  * in C strings.  Also, strings cannot be longer than 32767		  * bytes since the 2-byte length is a signed (twos-complement)		  * value.		  *		  * Put the 2-byte length and string characters in the buffer.		  */	          *bufptr++ = n >> 8;		  *bufptr++ = n;		  if (n > 0)		  {		    memcpy(bufptr, value->string.text, n);		    bufptr += n;		  }		}		break;	    case IPP_TAG_DATE :	        for (i = 0, value = attr->values;		     i < attr->num_values;		     i ++, value ++)		{                  if ((sizeof(buffer) - (bufptr - buffer)) < 16)		  {                    if ((*cb)(dst, buffer, bufptr - buffer) < 0)	            {	              DEBUG_puts("ippWrite: Could not write IPP attribute...");	              return (IPP_ERROR);	            }		    bufptr = buffer;		  }		  if (i)		  {		   /*		    * Arrays and sets are done by sending additional		    * values with a zero-length name...		    */                    *bufptr++ = attr->value_tag;		    *bufptr++ = 0;		    *bufptr++ = 0;		  }                 /*		  * Date values consist of a 2-byte length and an		  * 11-byte date/time structure defined by RFC 1903.		  *		  * Put the 2-byte length and 11-byte date/time		  * structure in the buffer.		  */	          *bufptr++ = 0;		  *bufptr++ = 11;		  memcpy(bufptr, value->date, 11);		  bufptr += 11;		}		break;	    case IPP_TAG_RESOLUTION :	        for (i = 0, value = attr->values;		     i < attr->num_values;		     i ++, value ++)		{                  if ((sizeof(buffer) - (bufptr - buffer)) < 14)		  {                    if ((*cb)(dst, buffer, bufptr - buffer) < 0)	            {	              DEBUG_puts("ippWrite: Could not write IPP attribute...");	              return (IPP_ERROR);	            }		    bufptr = buffer;		  }		  if (i)		  {		   /*		    * Arrays and sets are done by sending additional		    * values with a zero-length name...		    */                    *bufptr++ = attr->value_tag;		    *bufptr++ = 0;		    *bufptr++ = 0;		  }                 /*		  * Resolution values consist of a 2-byte length,		  * 4-byte horizontal resolution value, 4-byte vertical		  * resolution value, and a 1-byte units value.		  *		  * Put the 2-byte length and resolution value data		  * into the buffer.		  */	          *bufptr++ = 0;		  *bufptr++ = 9;		  *bufptr++ = value->resolution.xres >> 24;		  *bufptr++ = value->resolution.xres >> 16;		  *bufptr++ = value->resolution.xres >> 8;		  *bufptr++ = value->resolution.xres;		  *bufptr++ = value->resolution.yres >> 24;		  *bufptr++ = value->resolution.yres >> 16;		  *bufptr++ = value->resolution.yres >> 8;		  *bufptr++ = value->resolution.yres;		  *bufptr++ = value->resolution.units;		}		break;	    case IPP_TAG_RANGE :	        for (i = 0, value = attr->values;		     i < attr->num_values;		     i ++, value ++)		{                  if ((sizeof(buffer) - (bufptr - buffer)) < 13)		  {                    if ((*cb)(dst, buffer, bufptr - buffer) < 0)	            {	              DEBUG_puts("ippWrite: Could not write IPP attribute...");	              return (IPP_ERROR);	            }		    bufptr = buffer;		  }		  if (i)		  {		   /*		    * Arrays and sets are done by sending additional		    * values with a zero-length name...		    */                    *bufptr++ = attr->value_tag;		    *bufptr++ = 0;		    *bufptr++ = 0;		  }                 /*		  * Range values consist of a 2-byte length,		  * 4-byte lower value, and 4-byte upper value.		  *		  * Put the 2-byte length and range value data		  * into the buffer.		  */	          *bufptr++ = 0;		  *bufptr++ = 8;		  *bufptr++ = value->range.lower >> 24;		  *bufptr++ = value->range.lower >> 16;		  *bufptr++ = value->range.lower >> 8;		  *bufptr++ = value->range.lower;		  *bufptr++ = value->range.upper >> 24;		  *bufptr++ = value->range.upper >> 16;		  *bufptr++ = value->range.upper >> 8;		  *bufptr++ = value->range.upper;		}		break;	    case IPP_TAG_TEXTLANG :	    case IPP_TAG_NAMELANG :	        for (i = 0, value = attr->values;		     i < attr->num_values;		     i ++, value ++)		{		  if (i)		  {		   /*		    * Arrays and sets are done by sending additional		    * values with a zero-length name...		    */                    if ((sizeof(buffer) - (bufptr - buffer)) < 3)		    {                      if ((*cb)(dst, buffer, bufptr - buffer) < 0)	              {	        	DEBUG_puts("ippWrite: Could not write IPP attribute...");	        	return (IPP_ERROR);	              }		      bufptr = buffer;		    }                    *bufptr++ = attr->value_tag;		    *bufptr++ = 0;		    *bufptr++ = 0;		  }                 /*		  * textWithLanguage and nameWithLanguage values consist		  * of a 2-byte length for both strings and their		  * individual lengths, a 2-byte length for the		  * character string, the character string without the		  * trailing nul, a 2-byte length for the character		  * set string, and the character set string without		  * the trailing nul.		  */                  n = 4;		  if (value->string.charset != NULL)                    n += strlen(value->string.charset);		  if (value->string.text != NULL)                    n += strlen(value->string.text);                  if (n > (sizeof(buffer) - 2))		    return (IPP_ERROR);                  if ((int)(sizeof(buffer) - (bufptr - buffer)) < (n + 2))		  {                    if ((*cb)(dst, buffer, bufptr - buffer) < 0)	            {	              DEBUG_puts("ippWrite: Could not write IPP attribute...");	              return (IPP_ERROR);	            }		    bufptr = buffer;		  }                 /* Length of entire value */	          *bufptr++ = n >> 8;		  *bufptr++ = n;                 /* Length of charset */		  if (value->string.charset != NULL)		    n = strlen(value->string.charset);		  else		    n = 0;	          *bufptr++ = n >> 8;		  *bufptr++ = n;                 /* Charset */		  if (n > 0)		  {		    memcpy(bufptr, value->string.charset, n);		    bufptr += n;		  }                 /* Length of text */                  if (value->string.text != NULL)		    n = strlen(value->string.text);		  else		    n = 0;	          *bufptr++ = n >> 8;		  *bufptr++ = n;                 /* Text */		  if (n > 0)		  {		    memcpy(bufptr, value->string.text, n);		    bufptr += n;		  }		}		break;            case IPP_TAG_BEGIN_COLLECTION :	        for (i = 0, value = attr->values;		     i < attr->num_values;		     i ++, value ++)		{		 /*		  * Collections are written with the begin-collection		  * tag first with a value of 0 length, followed by the		  * attributes in the collection, then the end-collection		  * value...		  */                  if ((sizeof(buffer) - (bufptr - buffer)) < 5)		  {                    if ((*cb)(dst, buffer, bufptr - buffer) < 0)	            {	              DEBUG_puts("ippWrite: Could not write IPP attribute...");	              return (IPP_ERROR);	            }		    bufptr = buffer;		  }		  if (i)		  {		   /*		    * Arrays and sets are done by sending additional		    * values with a zero-length name...		    */                    *bufptr++ = attr->value_tag;		    *bufptr++ = 0;		    *bufptr++ = 0;		  }                 /*		  * Write a data length of 0 and flush the buffer...		  */	          *bufptr++ = 0;		  *bufptr++ = 0;                  if ((*cb)(dst, buffer, bufptr - buffer) < 0)	          {	            DEBUG_puts("ippWrite: Could not write IPP attribute...");	            return (IPP_ERROR);	          }		  bufptr = buffer;                 /*

⌨️ 快捷键说明

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