/*
- * "$Id: http-support.c 5023 2006-01-29 14:39:44Z mike $"
+ * "$Id: http-support.c 6304 2007-02-22 22:06:23Z mike $"
*
* HTTP support routines for the Common UNIX Printing System (CUPS) scheduler.
*
- * Copyright 1997-2006 by Easy Software Products, all rights reserved.
+ * Copyright 1997-2007 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
* 'httpAssembleURI()' - Assemble a uniform resource identifier from its
* components.
*
- * This function properly escapes all reserved characters in a URI. You
- * should use this function in place of traditional string functions
- * whenever you need to create a URI string.
+ * This function escapes reserved characters in the URI depending on the
+ * value of the "encoding" argument. You should use this function in
+ * place of traditional string functions whenever you need to create a
+ * URI string.
*
* @since CUPS 1.2@
*/
if (!ptr)
goto assemble_overflow;
- if (!strcmp(scheme, "mailto:"))
+ if (!strcmp(scheme, "mailto"))
{
/*
* mailto: only has :, no //...
* components with a formatted resource.
*
* This function creates a formatted version of the resource string
- * argument "resourcef" and properly escapes all reserved characters
- * in a URI. You should use this function in place of traditional
- * string functions whenever you need to create a URI string.
+ * argument "resourcef" and escapes reserved characters in the URI
+ * depending on the value of the "encoding" argument. You should use
+ * this function in place of traditional string functions whenever
+ * you need to create a URI string.
*
* @since CUPS 1.2@
*/
/*
* 'httpDecode64()' - Base64-decode a string.
+ *
+ * This function is deprecated. Use the httpDecode64_2() function instead
+ * which provides buffer length arguments.
+ *
+ * @deprecated@
*/
char * /* O - Decoded string */
/*
* 'httpEncode64()' - Base64-encode a string.
+ *
+ * This function is deprecated. Use the httpEncode64_2() function instead
+ * which provides buffer length arguments.
+ *
+ * @deprecated@
*/
char * /* O - Encoded string */
httpEncode64(char *out, /* I - String to write to */
const char *in) /* I - String to read from */
{
- return (httpEncode64_2(out, 512, in, strlen(in)));
+ return (httpEncode64_2(out, 512, in, (int)strlen(in)));
}
if (outptr < outend)
*outptr ++ = base64[(in[0] & 255) >> 2];
+
if (outptr < outend)
- *outptr ++ = base64[(((in[0] & 255) << 4) | ((in[1] & 255) >> 4)) & 63];
+ {
+ if (inlen > 1)
+ *outptr ++ = base64[(((in[0] & 255) << 4) | ((in[1] & 255) >> 4)) & 63];
+ else
+ *outptr ++ = base64[((in[0] & 255) << 4) & 63];
+ }
in ++;
inlen --;
}
if (outptr < outend)
- *outptr ++ = base64[(((in[0] & 255) << 2) | ((in[1] & 255) >> 6)) & 63];
+ {
+ if (inlen > 1)
+ *outptr ++ = base64[(((in[0] & 255) << 2) | ((in[1] & 255) >> 6)) & 63];
+ else
+ *outptr ++ = base64[((in[0] & 255) << 2) & 63];
+ }
in ++;
inlen --;
/*
* 'httpSeparate()' - Separate a Universal Resource Identifier into its
* components.
+ *
+ * This function is deprecated; use the httpSeparateURI() function instead.
+ *
+ * @deprecated@
*/
void
* 'httpSeparate2()' - Separate a Universal Resource Identifier into its
* components.
*
+ * This function is deprecated; use the httpSeparateURI() function instead.
+ *
* @since CUPS 1.1.21@
+ * @deprecated@
*/
void
else
{
/*
- * Grab hostname or IPv4 address...
+ * Validate the hostname or IPv4 address first...
+ */
+
+ for (ptr = (char *)uri; *ptr; ptr ++)
+ if (strchr(":?/", *ptr))
+ break;
+ else if (!strchr("abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "0123456789"
+ "-._~"
+ "%"
+ "!$&'()*+,;=", *ptr))
+ {
+ *host = '\0';
+ return (HTTP_URI_BAD_HOSTNAME);
+ }
+
+ /*
+ * Then copy the hostname or IPv4 address to the buffer...
*/
uri = http_copy_decode(host, uri, hostlen, ":?/",
*host = '\0';
return (HTTP_URI_BAD_HOSTNAME);
}
-
- /*
- * Validate value...
- */
-
- for (ptr = host; *ptr; ptr ++)
- if (!strchr("abcdefghijklmnopqrstuvwxyz"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "0123456789"
- "-._~"
- "!$&'()*+,;=", *ptr))
- {
- *host = '\0';
- return (HTTP_URI_BAD_HOSTNAME);
- }
}
/*
*port = strtol(uri + 1, (char **)&uri, 10);
- if (*uri != '/')
+ if (*uri != '/' && *uri)
{
*port = 0;
return (HTTP_URI_BAD_PORT);
char *resptr = resource + strlen(resource);
- uri = http_copy_decode(resptr, uri, resourcelen - (resptr - resource),
+ uri = http_copy_decode(resptr, uri, resourcelen - (int)(resptr - resource),
NULL, decoding & HTTP_URI_CODING_QUERY);
}
}
return ("Accepted");
case HTTP_NO_CONTENT :
return ("No Content");
+ case HTTP_MOVED_PERMANENTLY :
+ return ("Moved Permanently");
+ case HTTP_SEE_OTHER :
+ return ("See Other");
case HTTP_NOT_MODIFIED :
return ("Not Modified");
case HTTP_BAD_REQUEST :
return ("Not Implemented");
case HTTP_NOT_SUPPORTED :
return ("Not Supported");
+ case HTTP_EXPECTATION_FAILED :
+ return ("Expectation Failed");
+
default :
return ("Unknown");
}
* or the end of the string.
*/
- for (ptr = dst, end = dst + dstsize - 1; *src && !strchr(term, *src); src ++)
+ for (ptr = dst, end = dst + dstsize - 1;
+ *src && (!term || !strchr(term, *src));
+ src ++)
if (ptr < end)
{
if (*src == '%' && decode)
/*
- * End of "$Id: http-support.c 5023 2006-01-29 14:39:44Z mike $".
+ * End of "$Id: http-support.c 6304 2007-02-22 22:06:23Z mike $".
*/