]>
git.ipfire.org Git - thirdparty/cups.git/blob - cgi-bin/ipp-var.c
2 * "$Id: ipp-var.c,v 1.23.2.8 2003/03/14 21:43:29 mike Exp $"
4 * IPP variable routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2003 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
);
77 setlocale(LC_TIME
, "");
83 * 'ippSetCGIVars()' - Set CGI variables from an IPP response.
87 ippSetCGIVars(ipp_t
*response
, /* I - Response data to be copied... */
88 const char *filter_name
, /* I - Filter name */
89 const char *filter_value
) /* I - Filter value */
91 int element
; /* Element in CGI array */
92 ipp_attribute_t
*attr
, /* Attribute in response... */
93 *filter
; /* Filtering attribute */
94 int i
; /* Looping var */
95 char name
[1024], /* Name of attribute */
96 value
[16384], /* Value(s) */
97 *valptr
; /* Pointer into value */
98 char method
[HTTP_MAX_URI
],
99 username
[HTTP_MAX_URI
],
100 hostname
[HTTP_MAX_URI
],
101 resource
[HTTP_MAX_URI
],
103 int port
; /* URI data */
104 int ishttps
; /* Using encryption? */
105 const char *server
; /* Name of server */
106 char servername
[1024];/* Locale server name */
107 struct tm
*date
; /* Date information */
111 * Set common CGI template variables...
114 ippSetServerVersion();
117 * Get the server name associated with the client interface as well as
118 * the locally configured hostname. We'll check *both* of these to
119 * see if the printer URL is local...
122 server
= getenv("SERVER_NAME");
123 gethostname(servername
, sizeof(servername
));
126 * Flag whether we are using SSL on this connection...
129 ishttps
= getenv("HTTPS") != NULL
;
132 * Loop through the attributes and set them for the template...
135 for (attr
= response
->attrs
;
136 attr
&& attr
->group_tag
== IPP_TAG_OPERATION
;
139 for (element
= 0; attr
!= NULL
; attr
= attr
->next
, element
++)
142 * Copy attributes to a separator...
148 filter
!= NULL
&& filter
->group_tag
!= IPP_TAG_ZERO
;
149 filter
= filter
->next
)
150 if (filter
->name
&& strcmp(filter
->name
, filter_name
) == 0 &&
151 (filter
->value_tag
== IPP_TAG_STRING
||
152 (filter
->value_tag
>= IPP_TAG_TEXTLANG
&&
153 filter
->value_tag
<= IPP_TAG_MIMETYPE
)) &&
154 filter
->values
[0].string
.text
!= NULL
&&
155 strcasecmp(filter
->values
[0].string
.text
, filter_value
) == 0)
161 if (filter
->group_tag
== IPP_TAG_ZERO
)
169 for (; attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_ZERO
; attr
= attr
->next
)
172 * Copy the attribute name, substituting "_" for "-"...
175 if (attr
->name
== NULL
)
178 for (i
= 0; attr
->name
[i
]; i
++)
179 if (attr
->name
[i
] == '-')
182 name
[i
] = attr
->name
[i
];
187 * Add "job_printer_name" variable if we have a "job_printer_uri"
191 if (strcmp(name
, "job_printer_uri") == 0)
193 if ((valptr
= strrchr(attr
->values
[0].string
.text
, '/')) == NULL
)
198 cgiSetArray("job_printer_name", element
, valptr
);
205 value
[0] = '\0'; /* Initially an empty string */
206 valptr
= value
; /* Start at the beginning */
208 for (i
= 0; i
< attr
->num_values
; i
++)
211 strlcat(valptr
, ",", sizeof(value
) - (valptr
- value
));
213 valptr
+= strlen(valptr
);
215 switch (attr
->value_tag
)
217 case IPP_TAG_INTEGER
:
219 if (strncmp(name
, "time_at_", 8) == 0)
221 date
= localtime((time_t *)&(attr
->values
[i
].integer
));
222 strftime(valptr
, sizeof(value
) - (valptr
- value
),
223 CUPS_STRFTIME_FORMAT
, date
);
226 snprintf(valptr
, sizeof(value
) - (valptr
- value
),
227 "%d", attr
->values
[i
].integer
);
230 case IPP_TAG_BOOLEAN
:
231 snprintf(valptr
, sizeof(value
) - (valptr
- value
),
232 "%d", attr
->values
[i
].boolean
);
235 case IPP_TAG_NOVALUE
:
236 strlcat(valptr
, "novalue", sizeof(value
) - (valptr
- value
));
240 snprintf(valptr
, sizeof(value
) - (valptr
- value
),
241 "%d-%d", attr
->values
[i
].range
.lower
,
242 attr
->values
[i
].range
.upper
);
245 case IPP_TAG_RESOLUTION
:
246 snprintf(valptr
, sizeof(value
) - (valptr
- value
),
247 "%dx%d%s", attr
->values
[i
].resolution
.xres
,
248 attr
->values
[i
].resolution
.yres
,
249 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
254 if (strchr(attr
->values
[i
].string
.text
, ':') != NULL
)
256 httpSeparate(attr
->values
[i
].string
.text
, method
, username
,
257 hostname
, &port
, resource
);
259 if (strcmp(method
, "ipp") == 0 ||
260 strcmp(method
, "http") == 0)
263 * Map local access to a local URI...
266 if (strcasecmp(hostname
, server
) == 0 ||
267 strcasecmp(hostname
, servername
) == 0)
270 * Make URI relative to the current server...
273 strlcpy(uri
, resource
, sizeof(uri
));
278 * Rewrite URI with HTTP address...
282 snprintf(uri
, sizeof(uri
), "%s://%s@%s:%d%s",
283 ishttps
? "https" : "http",
284 username
, hostname
, port
, resource
);
286 snprintf(uri
, sizeof(uri
), "%s://%s:%d%s",
287 ishttps
? "https" : "http",
288 hostname
, port
, resource
);
291 strlcat(valptr
, uri
, sizeof(value
) - (valptr
- value
));
296 case IPP_TAG_STRING
:
299 case IPP_TAG_KEYWORD
:
300 case IPP_TAG_CHARSET
:
301 case IPP_TAG_LANGUAGE
:
302 strlcat(valptr
, attr
->values
[i
].string
.text
,
303 sizeof(value
) - (valptr
- value
));
307 break; /* anti-compiler-warning-code */
315 cgiSetArray(name
, element
, value
);
317 /* fprintf(stderr, "DEBUG: %s[%d]=\"%s\"\n", name, element, value);*/
327 * End of "$Id: ipp-var.c,v 1.23.2.8 2003/03/14 21:43:29 mike Exp $".