2 * "$Id: http-support.c 5035 2006-02-01 14:58:46Z mike $"
4 * HTTP support routines for the Common UNIX Printing System (CUPS) scheduler.
6 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
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 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * httpAssembleURI() - Assemble a uniform resource identifier from its
30 * httpAssembleURIf() - Assemble a uniform resource identifier from its
31 * components with a formatted resource.
32 * httpDecode64() - Base64-decode a string.
33 * httpDecode64_2() - Base64-decode a string.
34 * httpEncode64() - Base64-encode a string.
35 * httpEncode64_2() - Base64-encode a string.
36 * httpGetDateString() - Get a formatted date/time string from a time value.
37 * httpGetDateString2() - Get a formatted date/time string from a time value.
38 * httpGetDateTime() - Get a time value from a formatted date/time string.
39 * httpSeparate() - Separate a Universal Resource Identifier into its
41 * httpSeparate2() - Separate a Universal Resource Identifier into its
43 * httpSeparateURI() - Separate a Universal Resource Identifier into its
45 * httpStatus() - Return a short string describing a HTTP status code.
46 * _cups_hstrerror() - hstrerror() emulation function for Solaris and
48 * http_copy_decode() - Copy and decode a URI.
49 * http_copy_encode() - Copy and encode a URI.
53 * Include necessary headers...
65 static const char * const http_days
[7] =
74 static const char * const http_months
[12] =
95 static const char *http_copy_decode(char *dst
, const char *src
,
96 int dstsize
, const char *term
,
98 static char *http_copy_encode(char *dst
, const char *src
,
99 char *dstend
, const char *reserved
,
100 const char *term
, int encode
);
104 * 'httpAssembleURI()' - Assemble a uniform resource identifier from its
107 * This function properly escapes all reserved characters in a URI. You
108 * should use this function in place of traditional string functions
109 * whenever you need to create a URI string.
114 http_uri_status_t
/* O - URI status */
116 http_uri_coding_t encoding
, /* I - Encoding flags */
117 char *uri
, /* I - URI buffer */
118 int urilen
, /* I - Size of URI buffer */
119 const char *scheme
, /* I - Scheme name */
120 const char *username
, /* I - Username */
121 const char *host
, /* I - Hostname or address */
122 int port
, /* I - Port number */
123 const char *resource
) /* I - Resource */
125 char *ptr
, /* Pointer into URI buffer */
126 *end
; /* End of URI buffer */
130 * Range check input...
133 if (!uri
|| urilen
< 1 || !scheme
|| port
< 0)
138 return (HTTP_URI_BAD_ARGUMENTS
);
142 * Assemble the URI starting with the scheme...
145 end
= uri
+ urilen
- 1;
146 ptr
= http_copy_encode(uri
, scheme
, end
, NULL
, NULL
, 0);
149 goto assemble_overflow
;
151 if (!strcmp(scheme
, "mailto:"))
154 * mailto: only has :, no //...
160 goto assemble_overflow
;
165 * Schemes other than mailto: all have //...
175 goto assemble_overflow
;
179 * Next the username and hostname, if any...
184 if (username
&& *username
)
187 * Add username@ first...
190 ptr
= http_copy_encode(ptr
, username
, end
, "/?@", NULL
,
191 encoding
& HTTP_URI_CODING_USERNAME
);
194 goto assemble_overflow
;
199 goto assemble_overflow
;
203 * Then add the hostname. Since IPv6 is a particular pain to deal
204 * with, we have several special cases to deal with... If we get
205 * an IPv6 address with brackets around it, assume it is already in
209 if (host
[0] != '[' && strchr(host
, ':'))
212 * We have an IPv6 address...
215 if (strchr(host
, '%'))
218 * We have a link-local address, add "[v1." prefix...
229 goto assemble_overflow
;
234 * We have a normal address, add "[" prefix...
240 goto assemble_overflow
;
244 * Copy the rest of the IPv6 address, and terminate with "]".
247 while (ptr
< end
&& *host
)
251 *ptr
++ = '+'; /* Convert zone separator */
259 goto assemble_overflow
;
264 goto assemble_overflow
;
269 * Otherwise, just copy the host string...
272 ptr
= http_copy_encode(ptr
, host
, end
, NULL
, NULL
,
273 encoding
& HTTP_URI_CODING_HOSTNAME
);
276 goto assemble_overflow
;
280 * Finish things off with the port number...
285 snprintf(ptr
, end
- ptr
+ 1, ":%d", port
);
289 goto assemble_overflow
;
294 * Last but not least, add the resource string...
299 char *query
; /* Pointer to query string */
303 * Copy the resource string up to the query string if present...
306 query
= strchr(resource
, '?');
307 ptr
= http_copy_encode(ptr
, resource
, end
, NULL
, "?",
308 encoding
& HTTP_URI_CODING_RESOURCE
);
310 goto assemble_overflow
;
315 * Copy query string without encoding...
318 ptr
= http_copy_encode(ptr
, query
, end
, NULL
, NULL
,
319 encoding
& HTTP_URI_CODING_QUERY
);
321 goto assemble_overflow
;
327 goto assemble_overflow
;
330 * Nul-terminate the URI buffer and return with no errors...
335 return (HTTP_URI_OK
);
338 * Clear the URI string and return an overflow error; I don't usually
339 * like goto's, but in this case it makes sense...
345 return (HTTP_URI_OVERFLOW
);
350 * 'httpAssembleURIf()' - Assemble a uniform resource identifier from its
351 * components with a formatted resource.
353 * This function creates a formatted version of the resource string
354 * argument "resourcef" and properly escapes all reserved characters
355 * in a URI. You should use this function in place of traditional
356 * string functions whenever you need to create a URI string.
361 http_uri_status_t
/* O - URI status */
363 http_uri_coding_t encoding
, /* I - Encoding flags */
364 char *uri
, /* I - URI buffer */
365 int urilen
, /* I - Size of URI buffer */
366 const char *scheme
, /* I - Scheme name */
367 const char *username
, /* I - Username */
368 const char *host
, /* I - Hostname or address */
369 int port
, /* I - Port number */
370 const char *resourcef
, /* I - Printf-style resource */
371 ...) /* I - Additional arguments as needed */
373 va_list ap
; /* Pointer to additional arguments */
374 char resource
[1024]; /* Formatted resource string */
375 int bytes
; /* Bytes in formatted string */
379 * Range check input...
382 if (!uri
|| urilen
< 1 || !scheme
|| port
< 0 || !resourcef
)
387 return (HTTP_URI_BAD_ARGUMENTS
);
391 * Format the resource string and assemble the URI...
394 va_start(ap
, resourcef
);
395 bytes
= vsnprintf(resource
, sizeof(resource
), resourcef
, ap
);
398 if (bytes
>= sizeof(resource
))
401 return (HTTP_URI_OVERFLOW
);
404 return (httpAssembleURI(encoding
, uri
, urilen
, scheme
, username
, host
,
410 * 'httpDecode64()' - Base64-decode a string.
413 char * /* O - Decoded string */
414 httpDecode64(char *out
, /* I - String to write to */
415 const char *in
) /* I - String to read from */
417 int outlen
; /* Output buffer length */
421 * Use the old maximum buffer size for binary compatibility...
426 return (httpDecode64_2(out
, &outlen
, in
));
431 * 'httpDecode64_2()' - Base64-decode a string.
433 * @since CUPS 1.1.21@
436 char * /* O - Decoded string */
437 httpDecode64_2(char *out
, /* I - String to write to */
438 int *outlen
, /* IO - Size of output string */
439 const char *in
) /* I - String to read from */
441 int pos
, /* Bit position */
442 base64
; /* Value of this character */
443 char *outptr
, /* Output pointer */
444 *outend
; /* End of output buffer */
448 * Range check input...
451 if (!out
|| !outlen
|| *outlen
< 1 || !in
)
463 * Convert from base-64 to bytes...
466 for (outptr
= out
, outend
= out
+ *outlen
- 1, pos
= 0; *in
!= '\0'; in
++)
469 * Decode this character into a number from 0 to 63...
472 if (*in
>= 'A' && *in
<= 'Z')
474 else if (*in
>= 'a' && *in
<= 'z')
475 base64
= *in
- 'a' + 26;
476 else if (*in
>= '0' && *in
<= '9')
477 base64
= *in
- '0' + 52;
488 * Store the result in the appropriate chars...
495 *outptr
= base64
<< 2;
500 *outptr
++ |= (base64
>> 4) & 3;
502 *outptr
= (base64
<< 4) & 255;
507 *outptr
++ |= (base64
>> 2) & 15;
509 *outptr
= (base64
<< 6) & 255;
523 * Return the decoded string and size...
526 *outlen
= (int)(outptr
- out
);
533 * 'httpEncode64()' - Base64-encode a string.
536 char * /* O - Encoded string */
537 httpEncode64(char *out
, /* I - String to write to */
538 const char *in
) /* I - String to read from */
540 return (httpEncode64_2(out
, 512, in
, strlen(in
)));
545 * 'httpEncode64_2()' - Base64-encode a string.
547 * @since CUPS 1.1.21@
550 char * /* O - Encoded string */
551 httpEncode64_2(char *out
, /* I - String to write to */
552 int outlen
, /* I - Size of output string */
553 const char *in
, /* I - String to read from */
554 int inlen
) /* I - Size of input string */
556 char *outptr
, /* Output pointer */
557 *outend
; /* End of output buffer */
558 static const char base64
[] = /* Base64 characters... */
560 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
561 "abcdefghijklmnopqrstuvwxyz"
568 * Range check input...
571 if (!out
|| outlen
< 1 || !in
)
575 * Convert bytes to base-64...
578 for (outptr
= out
, outend
= out
+ outlen
- 1; inlen
> 0; in
++, inlen
--)
581 * Encode the up to 3 characters as 4 Base64 numbers...
585 *outptr
++ = base64
[(in
[0] & 255) >> 2];
587 *outptr
++ = base64
[(((in
[0] & 255) << 4) | ((in
[1] & 255) >> 4)) & 63];
601 *outptr
++ = base64
[(((in
[0] & 255) << 2) | ((in
[1] & 255) >> 6)) & 63];
613 *outptr
++ = base64
[in
[0] & 63];
619 * Return the encoded string...
627 * 'httpGetDateString()' - Get a formatted date/time string from a time value.
632 const char * /* O - Date/time string */
633 httpGetDateString(time_t t
) /* I - UNIX time */
635 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
638 return (httpGetDateString2(t
, cg
->http_date
, sizeof(cg
->http_date
)));
643 * 'httpGetDateString2()' - Get a formatted date/time string from a time value.
648 const char * /* O - Date/time string */
649 httpGetDateString2(time_t t
, /* I - UNIX time */
650 char *s
, /* I - String buffer */
651 int slen
) /* I - Size of string buffer */
653 struct tm
*tdate
; /* UNIX date/time data */
657 snprintf(s
, slen
, "%s, %02d %s %d %02d:%02d:%02d GMT",
658 http_days
[tdate
->tm_wday
], tdate
->tm_mday
,
659 http_months
[tdate
->tm_mon
], tdate
->tm_year
+ 1900,
660 tdate
->tm_hour
, tdate
->tm_min
, tdate
->tm_sec
);
667 * 'httpGetDateTime()' - Get a time value from a formatted date/time string.
670 time_t /* O - UNIX time */
671 httpGetDateTime(const char *s
) /* I - Date/time string */
673 int i
; /* Looping var */
674 char mon
[16]; /* Abbreviated month name */
675 int day
, year
; /* Day of month and year */
676 int hour
, min
, sec
; /* Time */
677 int days
; /* Number of days since 1970 */
678 static const int normal_days
[] = /* Days to a month, normal years */
679 { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
680 static const int leap_days
[] = /* Days to a month, leap years */
681 { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 };
684 DEBUG_printf(("httpGetDateTime(s=\"%s\")\n", s
));
687 * Extract the date and time from the formatted string...
690 if (sscanf(s
, "%*s%d%15s%d%d:%d:%d", &day
, mon
, &year
, &hour
, &min
, &sec
) < 6)
693 DEBUG_printf((" day=%d, mon=\"%s\", year=%d, hour=%d, min=%d, sec=%d\n",
694 day
, mon
, year
, hour
, min
, sec
));
697 * Convert the month name to a number from 0 to 11.
700 for (i
= 0; i
< 12; i
++)
701 if (!strcasecmp(mon
, http_months
[i
]))
707 DEBUG_printf((" i=%d\n", i
));
710 * Now convert the date and time to a UNIX time value in seconds since
711 * 1970. We can't use mktime() since the timezone may not be UTC but
712 * the date/time string *is* UTC.
715 if ((year
& 3) == 0 && ((year
% 100) != 0 || (year
% 400) == 0))
716 days
= leap_days
[i
] + day
- 1;
718 days
= normal_days
[i
] + day
- 1;
720 DEBUG_printf((" days=%d\n", days
));
722 days
+= (year
- 1970) * 365 + /* 365 days per year (normally) */
723 ((year
- 1) / 4 - 492) - /* + leap days */
724 ((year
- 1) / 100 - 19) + /* - 100 year days */
725 ((year
- 1) / 400 - 4); /* + 400 year days */
727 DEBUG_printf((" days=%d\n", days
));
729 return (days
* 86400 + hour
* 3600 + min
* 60 + sec
);
734 * 'httpSeparate()' - Separate a Universal Resource Identifier into its
739 httpSeparate(const char *uri
, /* I - Universal Resource Identifier */
740 char *scheme
, /* O - Scheme [32] (http, https, etc.) */
741 char *username
, /* O - Username [1024] */
742 char *host
, /* O - Hostname [1024] */
743 int *port
, /* O - Port number to use */
744 char *resource
) /* O - Resource/filename [1024] */
746 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, 32, username
,
747 HTTP_MAX_URI
, host
, HTTP_MAX_URI
, port
, resource
,
753 * 'httpSeparate2()' - Separate a Universal Resource Identifier into its
756 * @since CUPS 1.1.21@
760 httpSeparate2(const char *uri
, /* I - Universal Resource Identifier */
761 char *scheme
, /* O - Scheme (http, https, etc.) */
762 int schemelen
, /* I - Size of scheme buffer */
763 char *username
, /* O - Username */
764 int usernamelen
, /* I - Size of username buffer */
765 char *host
, /* O - Hostname */
766 int hostlen
, /* I - Size of hostname buffer */
767 int *port
, /* O - Port number to use */
768 char *resource
, /* O - Resource/filename */
769 int resourcelen
) /* I - Size of resource buffer */
771 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, schemelen
, username
,
772 usernamelen
, host
, hostlen
, port
, resource
, resourcelen
);
777 * 'httpSeparateURI()' - Separate a Universal Resource Identifier into its
783 http_uri_status_t
/* O - Result of separation */
785 http_uri_coding_t decoding
, /* I - Decoding flags */
786 const char *uri
, /* I - Universal Resource Identifier */
787 char *scheme
, /* O - Scheme (http, https, etc.) */
788 int schemelen
, /* I - Size of scheme buffer */
789 char *username
, /* O - Username */
790 int usernamelen
, /* I - Size of username buffer */
791 char *host
, /* O - Hostname */
792 int hostlen
, /* I - Size of hostname buffer */
793 int *port
, /* O - Port number to use */
794 char *resource
, /* O - Resource/filename */
795 int resourcelen
) /* I - Size of resource buffer */
797 char *ptr
, /* Pointer into string... */
798 *end
; /* End of string */
799 const char *sep
; /* Separator character */
800 http_uri_status_t status
; /* Result of separation */
804 * Initialize everything to blank...
807 if (scheme
&& schemelen
> 0)
810 if (username
&& usernamelen
> 0)
813 if (host
&& hostlen
> 0)
819 if (resource
&& resourcelen
> 0)
823 * Range check input...
826 if (!uri
|| !port
|| !scheme
|| schemelen
<= 0 || !username
||
827 usernamelen
<= 0 || !host
|| hostlen
<= 0 || !resource
||
829 return (HTTP_URI_BAD_ARGUMENTS
);
832 return (HTTP_URI_BAD_URI
);
835 * Grab the scheme portion of the URI...
838 status
= HTTP_URI_OK
;
840 if (!strncmp(uri
, "//", 2))
843 * Workaround for HP IPP client bug...
846 strlcpy(scheme
, "ipp", schemelen
);
847 status
= HTTP_URI_MISSING_SCHEME
;
849 else if (*uri
== '/')
855 strlcpy(scheme
, "file", schemelen
);
856 status
= HTTP_URI_MISSING_SCHEME
;
861 * Standard URI with scheme...
864 for (ptr
= scheme
, end
= scheme
+ schemelen
- 1;
865 *uri
&& *uri
!= ':' && ptr
< end
;)
866 if (isalnum(*uri
& 255) || *uri
== '-' || *uri
== '+' || *uri
== '.')
876 return (HTTP_URI_BAD_SCHEME
);
883 * Set the default port number...
886 if (!strcmp(scheme
, "http"))
888 else if (!strcmp(scheme
, "https"))
890 else if (!strcmp(scheme
, "ipp"))
892 else if (!strcasecmp(scheme
, "lpd"))
894 else if (!strcmp(scheme
, "socket")) /* Not yet registered with IANA... */
896 else if (strcmp(scheme
, "file") && strcmp(scheme
, "mailto"))
897 status
= HTTP_URI_UNKNOWN_SCHEME
;
900 * Now see if we have a hostname...
903 if (!strncmp(uri
, "//", 2))
912 * Grab the username, if any...
915 if ((sep
= strpbrk(uri
, "@/")) != NULL
&& *sep
== '@')
918 * Get a username:password combo...
921 uri
= http_copy_decode(username
, uri
, usernamelen
, "@",
922 decoding
& HTTP_URI_CODING_USERNAME
);
927 return (HTTP_URI_BAD_USERNAME
);
934 * Then the hostname/IP address...
940 * Grab IPv6 address...
944 if (!strncmp(uri
, "v1.", 3))
945 uri
+= 3; /* Skip IPvN leader... */
947 uri
= http_copy_decode(host
, uri
, hostlen
, "]",
948 decoding
& HTTP_URI_CODING_HOSTNAME
);
953 return (HTTP_URI_BAD_HOSTNAME
);
963 return (HTTP_URI_BAD_HOSTNAME
);
968 for (ptr
= host
; *ptr
; ptr
++)
972 * Convert zone separator to % and stop here...
978 else if (*ptr
!= ':' && *ptr
!= '.' && !isxdigit(*ptr
& 255))
981 return (HTTP_URI_BAD_HOSTNAME
);
987 * Grab hostname or IPv4 address...
990 uri
= http_copy_decode(host
, uri
, hostlen
, ":?/",
991 decoding
& HTTP_URI_CODING_HOSTNAME
);
996 return (HTTP_URI_BAD_HOSTNAME
);
1003 for (ptr
= host
; *ptr
; ptr
++)
1004 if (!strchr("abcdefghijklmnopqrstuvwxyz"
1005 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1008 "!$&'()*+,;=", *ptr
))
1011 return (HTTP_URI_BAD_HOSTNAME
);
1016 * Validate hostname for file scheme - only empty and localhost are
1020 if (!strcmp(scheme
, "file") && strcmp(host
, "localhost") && host
[0])
1023 return (HTTP_URI_BAD_HOSTNAME
);
1027 * See if we have a port number...
1033 * Yes, collect the port number...
1036 *port
= strtol(uri
+ 1, (char **)&uri
, 10);
1041 return (HTTP_URI_BAD_PORT
);
1047 * The remaining portion is the resource string...
1050 if (*uri
== '?' || !*uri
)
1053 * Hostname but no path...
1056 status
= HTTP_URI_MISSING_RESOURCE
;
1060 * Copy any query string...
1064 uri
= http_copy_decode(resource
+ 1, uri
, resourcelen
- 1, NULL
,
1065 decoding
& HTTP_URI_CODING_QUERY
);
1071 uri
= http_copy_decode(resource
, uri
, resourcelen
, "?",
1072 decoding
& HTTP_URI_CODING_RESOURCE
);
1074 if (uri
&& *uri
== '?')
1077 * Concatenate any query string...
1080 char *resptr
= resource
+ strlen(resource
);
1082 uri
= http_copy_decode(resptr
, uri
, resourcelen
- (resptr
- resource
),
1083 NULL
, decoding
& HTTP_URI_CODING_QUERY
);
1090 return (HTTP_URI_BAD_RESOURCE
);
1094 * Return the URI separation status...
1102 * 'httpStatus()' - Return a short string describing a HTTP status code.
1105 const char * /* O - String or NULL */
1106 httpStatus(http_status_t status
) /* I - HTTP status code */
1110 case HTTP_CONTINUE
:
1111 return ("Continue");
1112 case HTTP_SWITCHING_PROTOCOLS
:
1113 return ("Switching Protocols");
1118 case HTTP_ACCEPTED
:
1119 return ("Accepted");
1120 case HTTP_NO_CONTENT
:
1121 return ("No Content");
1122 case HTTP_NOT_MODIFIED
:
1123 return ("Not Modified");
1124 case HTTP_BAD_REQUEST
:
1125 return ("Bad Request");
1126 case HTTP_UNAUTHORIZED
:
1127 return ("Unauthorized");
1128 case HTTP_FORBIDDEN
:
1129 return ("Forbidden");
1130 case HTTP_NOT_FOUND
:
1131 return ("Not Found");
1132 case HTTP_REQUEST_TOO_LARGE
:
1133 return ("Request Entity Too Large");
1134 case HTTP_URI_TOO_LONG
:
1135 return ("URI Too Long");
1136 case HTTP_UPGRADE_REQUIRED
:
1137 return ("Upgrade Required");
1138 case HTTP_NOT_IMPLEMENTED
:
1139 return ("Not Implemented");
1140 case HTTP_NOT_SUPPORTED
:
1141 return ("Not Supported");
1148 #ifndef HAVE_HSTRERROR
1150 * '_cups_hstrerror()' - hstrerror() emulation function for Solaris and others...
1153 const char * /* O - Error string */
1154 _cups_hstrerror(int error
) /* I - Error number */
1156 static const char * const errors
[] = /* Error strings */
1161 "Unrecoverable lookup error.",
1162 "No data associated with name."
1166 if (error
< 0 || error
> 4)
1167 return ("Unknown hostname lookup error.");
1169 return (errors
[error
]);
1171 #endif /* !HAVE_HSTRERROR */
1175 * 'http_copy_decode()' - Copy and decode a URI.
1178 static const char * /* O - New source pointer or NULL on error */
1179 http_copy_decode(char *dst
, /* O - Destination buffer */
1180 const char *src
, /* I - Source pointer */
1181 int dstsize
, /* I - Destination size */
1182 const char *term
, /* I - Terminating characters */
1183 int decode
) /* I - Decode %-encoded values */
1185 char *ptr
, /* Pointer into buffer */
1186 *end
; /* End of buffer */
1187 int quoted
; /* Quoted character */
1191 * Copy the src to the destination until we hit a terminating character
1192 * or the end of the string.
1195 for (ptr
= dst
, end
= dst
+ dstsize
- 1;
1196 *src
&& (!term
|| !strchr(term
, *src
));
1200 if (*src
== '%' && decode
)
1202 if (isxdigit(src
[1] & 255) && isxdigit(src
[2] & 255))
1205 * Grab a hex-encoded character...
1210 quoted
= (tolower(*src
) - 'a' + 10) << 4;
1212 quoted
= (*src
- '0') << 4;
1216 quoted
|= tolower(*src
) - 'a' + 10;
1218 quoted
|= *src
- '0';
1225 * Bad hex-encoded character...
1243 * 'http_copy_encode()' - Copy and encode a URI.
1246 static char * /* O - End of current URI */
1247 http_copy_encode(char *dst
, /* O - Destination buffer */
1248 const char *src
, /* I - Source pointer */
1249 char *dstend
, /* I - End of destination buffer */
1250 const char *reserved
, /* I - Extra reserved characters */
1251 const char *term
, /* I - Terminating characters */
1252 int encode
) /* I - %-encode reserved chars? */
1254 static const char *hex
= "0123456789ABCDEF";
1257 while (*src
&& dst
< dstend
)
1259 if (term
&& *src
== *term
)
1262 if (encode
&& (*src
== '%' || *src
<= ' ' || *src
& 128 ||
1263 (reserved
&& strchr(reserved
, *src
))))
1266 * Hex encode reserved characters...
1269 if ((dst
+ 2) >= dstend
)
1273 *dst
++ = hex
[(*src
>> 4) & 15];
1274 *dst
++ = hex
[*src
& 15];
1290 * End of "$Id: http-support.c 5035 2006-02-01 14:58:46Z mike $".