Revision: 14696
Author: adrian.chadd
Date: Sun May 23 07:00:44 2010
Log: Create urlMakeHttpCanonical() out of the guts of urlCanonical().
http://code.google.com/p/lusca-cache/source/detail?r=14696
Modified:
/branches/LUSCA_HEAD/libsqurl/url.c
/branches/LUSCA_HEAD/libsqurl/url.h
/branches/LUSCA_HEAD/src/url.c
=======================================
--- /branches/LUSCA_HEAD/libsqurl/url.c Sun May 23 06:10:13 2010
+++ /branches/LUSCA_HEAD/libsqurl/url.c Sun May 23 07:00:44 2010
@@ -9,6 +9,7 @@
#include "../libcore/tools.h"
+#include "proto.h"
#include "defines.h"
#include "url.h"
@@ -93,3 +94,30 @@
return host;
}
+/*
+ * Create a canonical HTTP style URL using the given components.
+ *
+ * "urlbuf" must be a MAX_URL sized buffer. The NUL terminated URL
+ * will be written into that.
+ */
+int
+urlMakeHttpCanonical(char *urlbuf, protocol_t protocol, const char *login,
+ const char *host, int port, const char *urlpath, int urlpath_len)
+{
+ LOCAL_ARRAY(char, portbuf, 32);
+ int len;
+
+ portbuf[0] = '\0';
+
+ if (port != urlDefaultPort(protocol))
+ snprintf(portbuf, 32, ":%d", port);
+ len = snprintf(urlbuf, MAX_URL, "%s://%s%s%s%s%.*s",
+ ProtocolStr[protocol],
+ login,
+ *login ? "@" : "",
+ host,
+ portbuf,
+ urlpath_len, urlpath);
+
+ return len;
+}
=======================================
--- /branches/LUSCA_HEAD/libsqurl/url.h Sun May 23 06:10:13 2010
+++ /branches/LUSCA_HEAD/libsqurl/url.h Sun May 23 07:00:44 2010
@@ -4,6 +4,8 @@
extern char * url_convert_hex(char *org_url, int allocate);
extern int urlIsRelative(const char *url);
extern char * urlHostname(const char *url);
-
+extern int urlMakeHttpCanonical(char *urlbuf, protocol_t protocol,
+ const char *login, const char *host, int port, const char *urlpath,
+ int urlpath_len);
#endif
=======================================
--- /branches/LUSCA_HEAD/src/url.c Sun May 23 06:10:13 2010
+++ /branches/LUSCA_HEAD/src/url.c Sun May 23 07:00:44 2010
@@ -261,7 +261,6 @@
const char *
urlCanonical(request_t * request)
{
- LOCAL_ARRAY(char, portbuf, 32);
LOCAL_ARRAY(char, urlbuf, MAX_URL);
if (request->canonical)
return request->canonical;
@@ -273,17 +272,8 @@
snprintf(urlbuf, MAX_URL, "%s:%d", request->host, request->port);
break;
default:
- portbuf[0] = '\0';
- if (request->port != urlDefaultPort(request->protocol))
- snprintf(portbuf, 32, ":%d", request->port);
- snprintf(urlbuf, MAX_URL, "%s://%s%s%s%s%.*s",
- ProtocolStr[request->protocol],
- request->login,
- *request->login ? "@" : null_string,
- request->host,
- portbuf,
- strLen2(request->urlpath),
- strBuf2(request->urlpath));
+ (void) urlMakeHttpCanonical(urlbuf, request->protocol,
request->login,
+ request->host, request->port, strBuf2(request->urlpath),
strLen2(request->urlpath));
break;
}
}
--
You received this message because you are subscribed to the Google Groups
"lusca-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/lusca-commit?hl=en.