/*
- * "$Id: http.c,v 1.140 2004/07/02 04:05:34 mike Exp $"
+ * "$Id: http.c,v 1.141 2004/08/18 15:34:02 mike Exp $"
*
* HTTP routines for the Common UNIX Printing System (CUPS).
*
httpDecode64(char *out, /* I - String to write to */
const char *in) /* I - String to read from */
{
- return (httpDecode64_2(out, in, 512));
+ int outlen; /* Output buffer length */
+
+
+ /*
+ * Use the old maximum buffer size for binary compatibility...
+ */
+
+ outlen = 512;
+
+ return (httpDecode64_2(out, &outlen, in));
}
* 'httpDecode64_2()' - Base64-decode a string.
*/
-char * /* O - Decoded string */
-httpDecode64_2(char *out, /* I - String to write to */
- const char *in, /* I - String to read from */
- int outlen) /* I - Size of output string */
+char * /* O - Decoded string */
+httpDecode64_2(char *out, /* I - String to write to */
+ int *outlen, /* IO - Size of output string */
+ const char *in) /* I - String to read from */
{
int pos, /* Bit position */
base64; /* Value of this character */
*outend; /* End of output buffer */
- for (outptr = out, outend = out + outlen - 1, pos = 0; *in != '\0'; in ++)
+ /*
+ * Range check input...
+ */
+
+ if (!out || !outlen || *outlen < 1 || !in || !*in)
+ return (NULL);
+
+ /*
+ * Convert from base-64 to bytes...
+ */
+
+ for (outptr = out, outend = out + *outlen - 1, pos = 0; *in != '\0'; in ++)
{
/*
* Decode this character into a number from 0 to 63...
*outptr = '\0';
/*
- * Return the decoded string...
+ * Return the decoded string and size...
*/
+ *outlen = (int)(outptr - out);
+
return (out);
}
httpEncode64(char *out, /* I - String to write to */
const char *in) /* I - String to read from */
{
- return (httpEncode64_2(out, in, 512));
+ return (httpEncode64_2(out, 512, in, strlen(in)));
}
char * /* O - Encoded string */
httpEncode64_2(char *out, /* I - String to write to */
+ int outlen, /* I - Size of output string */
const char *in, /* I - String to read from */
- int outlen) /* I - Size of output string */
+ int inlen) /* I - Size of input string */
{
char *outptr, /* Output pointer */
*outend; /* End of output buffer */
};
- for (outptr = out, outend = out + outlen - 1; *in != '\0'; in ++)
+ /*
+ * Range check input...
+ */
+
+ if (!out || outlen < 1 || !in || inlen < 1)
+ return (NULL);
+
+ /*
+ * Convert bytes to base-64...
+ */
+
+ for (outptr = out, outend = out + outlen - 1; inlen > 0; in ++, inlen --)
{
/*
* Encode the up to 3 characters as 4 Base64 numbers...
*outptr ++ = base64[((in[0] << 4) | (in[1] >> 4)) & 63];
in ++;
- if (*in == '\0')
+ inlen --;
+ if (inlen <= 0)
{
if (outptr < outend)
*outptr ++ = '=';
*outptr ++ = base64[((in[0] << 2) | (in[1] >> 6)) & 63];
in ++;
- if (*in == '\0')
+ inlen --;
+ if (inlen <= 0)
{
if (outptr < outend)
*outptr ++ = '=';
/*
- * End of "$Id: http.c,v 1.140 2004/07/02 04:05:34 mike Exp $".
+ * End of "$Id: http.c,v 1.141 2004/08/18 15:34:02 mike Exp $".
*/
/*
- * "$Id: http.h,v 1.50 2004/07/02 04:05:34 mike Exp $"
+ * "$Id: http.h,v 1.51 2004/08/18 15:34:02 mike Exp $"
*
* Hyper-Text Transport Protocol definitions for the Common UNIX Printing
* System (CUPS).
extern int httpWait(http_t *http, int msec);
/**** New in CUPS 1.1.21 ****/
-extern char *httpDecode64_2(char *out, const char *in, int outlen);
-extern char *httpEncode64_2(char *out, const char *in, int outlen);
+extern char *httpDecode64_2(char *out, int *outlen, const char *in);
+extern char *httpEncode64_2(char *out, int outlen, const char *in,
+ int inlen);
extern void httpSeparate2(const char *uri,
char *method, int methodlen,
char *username, int usernamelen,
#endif /* !_CUPS_HTTP_H_ */
/*
- * End of "$Id: http.h,v 1.50 2004/07/02 04:05:34 mike Exp $".
+ * End of "$Id: http.h,v 1.51 2004/08/18 15:34:02 mike Exp $".
*/