/*
* "$Id: http-support.c 148 2006-04-25 16:54:17Z njacobs $"
*
* HTTP support routines for the Common UNIX Printing System (CUPS) scheduler.
*
* Copyright 1997-2005 by Easy Software Products, all rights reserved.
*
* These coded instructions, statements, and computer programs are the
* property of Easy Software Products and are protected by Federal
* copyright law. Distribution and use rights are outlined in the file
* "LICENSE.txt" which should have been included with this file. If this
* file is missing or damaged please contact Easy Software Products
* at:
*
* Attn: CUPS Licensing Information
* Easy Software Products
* 44141 Airport View Drive, Suite 204
* Hollywood, Maryland 20636 USA
*
* Voice: (301) 373-9600
* EMail: cups-info@cups.org
* WWW: http://www.cups.org
*
* This file is subject to the Apple OS-Developed Software exception.
*
* Contents:
*
* httpSeparate() - Separate a Universal Resource Identifier into its
* components.
* httpSeparate2() - Separate a Universal Resource Identifier into its
* components.
* httpStatus() - Return a short string describing a HTTP status code.
* cups_hstrerror() - hstrerror() emulation function for Solaris and others...
* http_copy_decode() - Copy and decode a URI.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Include necessary headers...
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
#include "string.h"
#include "http.h"
/*
* Local functions...
*/
/*
* 'httpSeparate()' - Separate a Universal Resource Identifier into its
* components.
*/
void
char *method, /* O - Method [32] (http, https, etc.) */
char *username, /* O - Username [1024] */
char *host, /* O - Hostname [1024] */
int *port, /* O - Port number to use */
{
}
/*
* 'httpSeparate2()' - Separate a Universal Resource Identifier into its
* components.
*/
void
char *method, /* O - Method (http, https, etc.) */
int methodlen, /* I - Size of method buffer */
char *username, /* O - Username */
int usernamelen, /* I - Size of username buffer */
char *host, /* O - Hostname */
int hostlen, /* I - Size of hostname buffer */
int *port, /* O - Port number to use */
int resourcelen) /* I - Size of resource buffer */
{
/*
* Range check input...
*/
return;
/*
* Grab the method portion of the URI...
*/
{
/*
* Workaround for HP IPP client bug...
*/
}
else
{
/*
* Standard URI with method...
*/
if (*uri == ':')
uri ++;
/*
* If the method contains a period or slash, then it's probably
*/
{
{
*ptr = '\0';
}
else
resource[0] = '\0';
{
/*
* OK, we have "hostname:port[/resource]"...
*/
if (*uri == '/')
}
else
*port = 631;
username[0] = '\0';
return;
}
else
}
/*
* If the method starts with less than 2 slashes then it is a local resource...
*/
{
username[0] = '\0';
host[0] = '\0';
*port = 0;
return;
}
/*
* Grab the username, if any...
*/
uri += 2;
{
/*
* Got a username:password combo...
*/
}
else
username[0] = '\0';
/*
* Grab the hostname...
*/
if (*uri != ':')
{
*port = 80;
*port = 443;
*port = 631;
*port = 515;
*port = 9100;
else
*port = 0;
}
else
{
/*
* Parse port number...
*/
}
if (*uri == '\0')
{
/*
* Hostname but no port or path...
*/
resource[0] = '/';
return;
}
/*
* The remaining portion is the resource string...
*/
}
/*
* 'httpStatus()' - Return a short string describing a HTTP status code.
*/
const char * /* O - String or NULL */
{
switch (status)
{
case HTTP_CONTINUE :
return ("Continue");
case HTTP_SWITCHING_PROTOCOLS :
return ("Switching Protocols");
case HTTP_OK :
return ("OK");
case HTTP_CREATED :
return ("Created");
case HTTP_ACCEPTED :
return ("Accepted");
case HTTP_NO_CONTENT :
return ("No Content");
case HTTP_NOT_MODIFIED :
return ("Not Modified");
case HTTP_BAD_REQUEST :
return ("Bad Request");
case HTTP_UNAUTHORIZED :
return ("Unauthorized");
case HTTP_FORBIDDEN :
return ("Forbidden");
case HTTP_NOT_FOUND :
return ("Not Found");
case HTTP_REQUEST_TOO_LARGE :
return ("Request Entity Too Large");
case HTTP_URI_TOO_LONG :
return ("URI Too Long");
case HTTP_UPGRADE_REQUIRED :
return ("Upgrade Required");
case HTTP_NOT_IMPLEMENTED :
return ("Not Implemented");
case HTTP_NOT_SUPPORTED :
return ("Not Supported");
default :
return ("Unknown");
}
}
#ifndef HAVE_HSTRERROR
/*
* 'cups_hstrerror()' - hstrerror() emulation function for Solaris and others...
*/
const char * /* O - Error string */
{
{
"OK",
"Host not found.",
"Try again.",
"Unrecoverable lookup error.",
"No data associated with name."
};
return ("Unknown hostname lookup error.");
else
}
#endif /* !HAVE_HSTRERROR */
/*
* 'http_copy_decode()' - Copy and decode a URI.
*/
static const char * /* O - New source pointer */
const char *src, /* I - Source pointer */
int dstsize, /* I - Destination size */
const char *term) /* I - Terminating characters */
{
/*
* Copy the src to the destination until we hit a terminating character
* or the end of the string.
*/
{
{
/*
* Grab a hex-encoded character...
*/
src ++;
else
src ++;
else
}
else
}
*ptr = '\0';
return (src);
}
/*
* End of "$Id: http-support.c 148 2006-04-25 16:54:17Z njacobs $"
*/