/*
- * "$Id: client.c 6383 2007-03-21 20:01:20Z mike $"
+ * "$Id: client.c 6504 2007-05-02 00:14:56Z mike $"
*
* Client routines for the Common UNIX Printing System (CUPS) scheduler.
*
#ifdef DEBUG
cupsdLogMessage(CUPSD_LOG_DEBUG2,
- "cupsdWriteClient(con=%p) %d response=%p, file=%d "
+ "cupsdWriteClient(con=%p) %d response=%p(%d), file=%d "
"pipe_pid=%d state=%d",
- con, con->http.fd, con->response, con->file, con->pipe_pid,
- con->http.state);
+ con, con->http.fd, con->response, con->response->state,
+ con->file, con->pipe_pid, con->http.state);
#endif /* DEBUG */
if (con->http.state != HTTP_GET_SEND &&
con->file_ready = 0;
}
- if (con->response)
+ if (con->response && con->response->state != IPP_DATA)
{
ipp_state = ippWrite(HTTP(con), con->response);
- bytes = ipp_state != IPP_ERROR && ipp_state != IPP_DATA;
+ bytes = ipp_state != IPP_ERROR &&
+ (con->file >= 0 || ipp_state != IPP_DATA);
}
else if ((bytes = read(con->file, buf, sizeof(buf) - 1)) > 0)
{
cupsdSetString(&con->command, CUPS_JAVA);
if (options)
- cupsdSetStringf(&con->options, "%s %s", filename, options);
+ cupsdSetStringf(&con->options, " %s %s", filename, options);
else
- cupsdSetString(&con->options, filename);
+ cupsdSetStringf(&con->options, " %s", filename);
cupsdLogMessage(CUPSD_LOG_DEBUG2,
"is_cgi: Returning 1 with command=\"%s\" and options=\"%s\"",
cupsdSetString(&con->command, CUPS_PERL);
if (options)
- cupsdSetStringf(&con->options, "%s %s", filename, options);
+ cupsdSetStringf(&con->options, " %s %s", filename, options);
else
- cupsdSetString(&con->options, filename);
+ cupsdSetStringf(&con->options, " %s", filename);
cupsdLogMessage(CUPSD_LOG_DEBUG2,
"is_cgi: Returning 1 with command=\"%s\" and options=\"%s\"",
cupsdSetString(&con->command, CUPS_PHP);
if (options)
- cupsdSetStringf(&con->options, "%s %s", filename, options);
+ cupsdSetStringf(&con->options, " %s %s", filename, options);
else
- cupsdSetString(&con->options, filename);
+ cupsdSetStringf(&con->options, " %s", filename);
cupsdLogMessage(CUPSD_LOG_DEBUG2,
"is_cgi: Returning 1 with command=\"%s\" and options=\"%s\"",
cupsdSetString(&con->command, CUPS_PYTHON);
if (options)
- cupsdSetStringf(&con->options, "%s %s", filename, options);
+ cupsdSetStringf(&con->options, " %s %s", filename, options);
else
- cupsdSetString(&con->options, filename);
+ cupsdSetStringf(&con->options, " %s", filename);
cupsdLogMessage(CUPSD_LOG_DEBUG2,
"is_cgi: Returning 1 with command=\"%s\" and options=\"%s\"",
int envc; /* Number of environment variables */
char argbuf[10240], /* Argument buffer */
*argv[100], /* Argument strings */
- *envp[MAX_ENV + 18]; /* Environment variables */
- char content_length[1024], /* CONTENT_LENGTH environment variable */
+ *envp[MAX_ENV + 20]; /* Environment variables */
+ char auth_type[256], /* AUTH_TYPE environment variable */
+ content_length[1024], /* CONTENT_LENGTH environment variable */
content_type[1024], /* CONTENT_TYPE environment variable */
http_cookie[32768], /* HTTP_COOKIE environment variable */
http_referer[1024], /* HTTP_REFERER environment variable */
remote_addr[1024], /* REMOTE_ADDR environment variable */
remote_host[1024], /* REMOTE_HOST environment variable */
remote_user[1024], /* REMOTE_USER environment variable */
+ script_filename[1024], /* SCRIPT_FILENAME environment variable */
script_name[1024], /* SCRIPT_NAME environment variable */
server_name[1024], /* SERVER_NAME environment variable */
server_port[1024]; /* SERVER_PORT environment variable */
{
commptr = argbuf;
path_info[0] = '\0';
+
+ if (*commptr == ' ')
+ commptr ++;
}
cupsdLogMessage(CUPSD_LOG_INFO, "commptr=\"%s\"", commptr);
* Setup the environment variables as needed...
*/
+ if (con->username[0])
+ {
+ snprintf(auth_type, sizeof(auth_type), "AUTH_TYPE=%s",
+ httpGetField(HTTP(con), HTTP_FIELD_AUTHORIZATION));
+
+ if ((uriptr = strchr(auth_type + 10, ' ')) != NULL)
+ *uriptr = '\0';
+ }
+ else
+ auth_type[0] = '\0';
+
if (con->language)
snprintf(lang, sizeof(lang), "LANG=%s.UTF-8", con->language->language);
else
if ((uriptr = strchr(script_name, '?')) != NULL)
*uriptr = '\0';
+ snprintf(script_filename, sizeof(script_filename), "SCRIPT_FILENAME=%s%s",
+ DocumentRoot, script_name + 12);
+
sprintf(server_port, "SERVER_PORT=%d", con->serverport);
snprintf(server_name, sizeof(server_name), "SERVER_NAME=%s",
envc = cupsdLoadEnv(envp, (int)(sizeof(envp) / sizeof(envp[0])));
+ if (auth_type[0])
+ envp[envc ++] = auth_type;
+
envp[envc ++] = lang;
envp[envc ++] = "REDIRECT_STATUS=1";
+ envp[envc ++] = "GATEWAY_INTERFACE=CGI/1.1";
envp[envc ++] = server_name;
envp[envc ++] = server_port;
envp[envc ++] = remote_addr;
envp[envc ++] = remote_host;
envp[envc ++] = script_name;
+ envp[envc ++] = script_filename;
if (path_info[0])
envp[envc ++] = path_info;
/*
- * End of "$Id: client.c 6383 2007-03-21 20:01:20Z mike $".
+ * End of "$Id: client.c 6504 2007-05-02 00:14:56Z mike $".
*/