]>
git.ipfire.org Git - thirdparty/cups.git/blob - cgi-bin/ipp-var.c
2 * "$Id: ipp-var.c,v 1.23.2.3 2002/04/08 16:28:59 mike Exp $"
4 * IPP variable routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2002 by Easy Software Products.
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
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * ippGetTemplateDir() - Get the templates directory...
27 * ippSetServerVersion() - Set the server name and CUPS version...
28 * ippSetCGIVars() - Set CGI variables from an IPP response.
32 * Include necessary headers...
39 * 'ippGetTemplateDir()' - Get the templates directory...
42 char * /* O - Template directory */
43 ippGetTemplateDir(void)
45 const char *datadir
; /* CUPS_DATADIR env var */
46 static char templates
[1024] = ""; /* Template directory */
52 * Build the template directory pathname...
55 if ((datadir
= getenv("CUPS_DATADIR")) == NULL
)
56 datadir
= CUPS_DATADIR
;
58 snprintf(templates
, sizeof(templates
), "%s/templates", datadir
);
66 * 'ippSetServerVersion()' - Set the server name and CUPS version...
70 ippSetServerVersion(void)
72 cgiSetVariable("SERVER_NAME", getenv("SERVER_NAME"));
73 cgiSetVariable("REMOTE_USER", getenv("REMOTE_USER"));
74 cgiSetVariable("CUPS_VERSION", CUPS_SVERSION
);
79 * 'ippSetCGIVars()' - Set CGI variables from an IPP response.
83 ippSetCGIVars(ipp_t
*response
, /* I - Response data to be copied... */
84 const char *filter_name
, /* I - Filter name */
85 const char *filter_value
) /* I - Filter value */
87 int element
; /* Element in CGI array */
88 ipp_attribute_t
*attr
, /* Attribute in response... */
89 *filter
; /* Filtering attribute */
90 int i
; /* Looping var */
91 char name
[1024], /* Name of attribute */
92 value
[16384], /* Value(s) */
93 *valptr
; /* Pointer into value */
94 char method
[HTTP_MAX_URI
],
95 username
[HTTP_MAX_URI
],
96 hostname
[HTTP_MAX_URI
],
97 resource
[HTTP_MAX_URI
],
99 int port
; /* URI data */
100 int ishttps
; /* Using encryption? */
101 const char *server
; /* Name of server */
102 struct tm
*date
; /* Date information */
105 ippSetServerVersion();
107 server
= getenv("SERVER_NAME");
108 ishttps
= getenv("HTTPS") != NULL
;
110 for (attr
= response
->attrs
;
111 attr
&& attr
->group_tag
== IPP_TAG_OPERATION
;
114 for (element
= 0; attr
!= NULL
; attr
= attr
->next
, element
++)
117 * Copy attributes to a separator...
123 filter
!= NULL
&& filter
->group_tag
!= IPP_TAG_ZERO
;
124 filter
= filter
->next
)
125 if (filter
->name
&& strcmp(filter
->name
, filter_name
) == 0 &&
126 (filter
->value_tag
== IPP_TAG_STRING
||
127 (filter
->value_tag
>= IPP_TAG_TEXTLANG
&&
128 filter
->value_tag
<= IPP_TAG_MIMETYPE
)) &&
129 filter
->values
[0].string
.text
!= NULL
&&
130 strcasecmp(filter
->values
[0].string
.text
, filter_value
) == 0)
136 if (filter
->group_tag
== IPP_TAG_ZERO
)
144 for (; attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_ZERO
; attr
= attr
->next
)
147 * Copy the attribute name, substituting "_" for "-"...
150 if (attr
->name
== NULL
)
153 for (i
= 0; attr
->name
[i
]; i
++)
154 if (attr
->name
[i
] == '-')
157 name
[i
] = attr
->name
[i
];
162 * Add "job_printer_name" variable if we have a "job_printer_uri"
166 if (strcmp(name
, "job_printer_uri") == 0)
168 if ((valptr
= strrchr(attr
->values
[0].string
.text
, '/')) == NULL
)
173 cgiSetArray("job_printer_name", element
, valptr
);
180 value
[0] = '\0'; /* Initially an empty string */
181 value
[sizeof(value
) - 1] = '\0'; /* In case string gets full */
182 valptr
= value
; /* Start at the beginning */
184 for (i
= 0; i
< attr
->num_values
; i
++)
187 strncat(valptr
, ",", sizeof(value
) - (valptr
- value
) - 1);
189 valptr
+= strlen(valptr
);
191 switch (attr
->value_tag
)
193 case IPP_TAG_INTEGER
:
195 if (strncmp(name
, "time_at_", 8) == 0)
197 date
= localtime((time_t *)&(attr
->values
[i
].integer
));
198 strftime(valptr
, sizeof(value
) - (valptr
- value
),
199 CUPS_STRFTIME_FORMAT
, date
);
202 snprintf(valptr
, sizeof(value
) - (valptr
- value
),
203 "%d", attr
->values
[i
].integer
);
206 case IPP_TAG_BOOLEAN
:
207 snprintf(valptr
, sizeof(value
) - (valptr
- value
),
208 "%d", attr
->values
[i
].boolean
);
211 case IPP_TAG_NOVALUE
:
212 strncat(valptr
, "novalue", sizeof(value
) - (valptr
- value
) - 1);
216 snprintf(valptr
, sizeof(value
) - (valptr
- value
),
217 "%d-%d", attr
->values
[i
].range
.lower
,
218 attr
->values
[i
].range
.upper
);
221 case IPP_TAG_RESOLUTION
:
222 snprintf(valptr
, sizeof(value
) - (valptr
- value
),
223 "%dx%d%s", attr
->values
[i
].resolution
.xres
,
224 attr
->values
[i
].resolution
.yres
,
225 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
230 if (strchr(attr
->values
[i
].string
.text
, ':') != NULL
)
232 httpSeparate(attr
->values
[i
].string
.text
, method
, username
,
233 hostname
, &port
, resource
);
235 if (strcmp(method
, "ipp") == 0 ||
236 strcmp(method
, "http") == 0)
239 * Map localhost access to localhost and local port...
242 if (strcasecmp(hostname
, server
) == 0)
245 * Make URI relative to the current server...
248 strncpy(uri
, resource
, sizeof(uri
) - 1);
249 uri
[sizeof(uri
) - 1] = '\0';
254 * Rewrite URI with HTTP address...
258 snprintf(uri
, sizeof(uri
), "%s://%s@%s:%d%s",
259 ishttps
? "https" : "http",
260 username
, hostname
, port
, resource
);
262 snprintf(uri
, sizeof(uri
), "%s://%s:%d%s",
263 ishttps
? "https" : "http",
264 hostname
, port
, resource
);
267 strncat(valptr
, uri
, sizeof(value
) - (valptr
- value
) - 1);
272 case IPP_TAG_STRING
:
275 case IPP_TAG_KEYWORD
:
276 case IPP_TAG_CHARSET
:
277 case IPP_TAG_LANGUAGE
:
278 strncat(valptr
, attr
->values
[i
].string
.text
,
279 sizeof(value
) - (valptr
- value
) - 1);
283 break; /* anti-compiler-warning-code */
291 cgiSetArray(name
, element
, value
);
301 * End of "$Id: ipp-var.c,v 1.23.2.3 2002/04/08 16:28:59 mike Exp $".