]> git.ipfire.org Git - thirdparty/cups.git/blob - cgi-bin/ipp-var.c
Added templates, CGI variable code, and updated printers CGI to use
[thirdparty/cups.git] / cgi-bin / ipp-var.c
1 /*
2 * "$Id: ipp-var.c,v 1.1 2000/02/01 02:52:23 mike Exp $"
3 *
4 * IPP variable routines for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1997-1999 by Easy Software Products.
7 *
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
19 *
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * Contents:
25 *
26 * ippSetCGIVars() - Set CGI variables from an IPP response.
27 */
28
29 /*
30 * Include necessary headers...
31 */
32
33 #include "ipp-var.h"
34
35
36 /*
37 * 'ippSetCGIVars()' - Set CGI variables from an IPP response.
38 */
39
40 void
41 ippSetCGIVars(ipp_t *response) /* I - Response data to be copied... */
42 {
43 int element; /* Element in CGI array */
44 ipp_attribute_t *attr; /* Attribute in response... */
45 int i; /* Looping var */
46 char name[1024], /* Name of attribute */
47 value[16384], /* Value(s) */
48 *valptr; /* Pointer into value */
49
50
51 cgiSetVariable("SERVER_NAME", getenv("SERVER_NAME"));
52 cgiSetVariable("REMOTE_USER", getenv("REMOTE_USER"));
53 cgiSetVariable("CUPS_VERSION", CUPS_SVERSION);
54
55 for (element = 0, attr = response->attrs;
56 attr != NULL;
57 attr = attr->next, element ++)
58 {
59 /*
60 * Copy attributes to a separator...
61 */
62
63 for (; attr != NULL && attr->group_tag != IPP_TAG_ZERO; attr = attr->next)
64 {
65 /*
66 * Copy the attribute name, substituting "_" for "-"...
67 */
68
69 if (attr->name == NULL)
70 continue;
71
72 for (i = 0; attr->name[i]; i ++)
73 if (attr->name[i] == '-')
74 name[i] = '_';
75 else
76 name[i] = attr->name[i];
77
78 name[i] = '\0';
79
80 /*
81 * Copy values...
82 */
83
84 value[0] = '\0';
85 valptr = value;
86
87 for (i = 0; i < attr->num_values; i ++)
88 {
89 if (i)
90 strcat(valptr, ",");
91
92 valptr += strlen(valptr);
93
94 switch (attr->value_tag)
95 {
96 case IPP_TAG_INTEGER :
97 case IPP_TAG_ENUM :
98 sprintf(valptr, "%d", attr->values[i].integer);
99 break;
100
101 case IPP_TAG_BOOLEAN :
102 if (!attr->values[i].boolean)
103 strcat(valptr, "no");
104
105 case IPP_TAG_NOVALUE :
106 strcat(valptr, attr->name);
107 break;
108
109 case IPP_TAG_RANGE :
110 sprintf(valptr, "%d-%d", attr->values[i].range.lower,
111 attr->values[i].range.upper);
112 break;
113
114 case IPP_TAG_RESOLUTION :
115 sprintf(valptr, "%dx%d%s", attr->values[i].resolution.xres,
116 attr->values[i].resolution.yres,
117 attr->values[i].resolution.units == IPP_RES_PER_INCH ?
118 "dpi" : "dpc");
119 break;
120
121 case IPP_TAG_STRING :
122 case IPP_TAG_TEXT :
123 case IPP_TAG_NAME :
124 case IPP_TAG_KEYWORD :
125 case IPP_TAG_CHARSET :
126 case IPP_TAG_LANGUAGE :
127 strcat(valptr, attr->values[i].string.text);
128 break;
129 }
130 }
131
132 /*
133 * Add the element...
134 */
135
136 cgiSetArray(name, element, value);
137 }
138
139 if (attr == NULL)
140 break;
141 }
142 }
143
144
145 /*
146 * End of "$Id: ipp-var.c,v 1.1 2000/02/01 02:52:23 mike Exp $".
147 */