All of lore.kernel.org
 help / color / mirror / Atom feed
* [Patch] tabled: fix buckets in subdomains
@ 2009-10-20 16:59 Pete Zaitcev
  2009-10-21 15:15 ` Jeff Garzik
  0 siblings, 1 reply; 2+ messages in thread
From: Pete Zaitcev @ 2009-10-20 16:59 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: Project Hail List

Make sure that bucket names in subdomains actually work. As it turned out,
we had some simple issues, like them working with bucket.pretzel.yyz.us
only, some time ago, and even that bitrotted.

Signed-off-by: Pete Zaitcev <zaitcev@redhat.com>

---
 server/bucket.c |   23 +++++++++++++++++++++++
 server/server.c |   22 ++++------------------
 server/tabled.h |    2 +-
 3 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/server/bucket.c b/server/bucket.c
index 976d716..c13ec05 100644
--- a/server/bucket.c
+++ b/server/bucket.c
@@ -408,6 +408,29 @@ bool bucket_base(const char *uri_path, char **pbucket, char **ppath)
 	return true;
 }
 
+/*
+ * Match host against ourhost and return the bucket, if any.
+ * This used to be handled with a regexp "^\\s*(\\w+)\\.(\\w.*)$",
+ * but that failed due to hostnames having a dash in them.
+ */
+char *bucket_host(const char *host, const char *ourhost)
+{
+	size_t ourhlen = strlen(ourhost);
+	size_t hlen = strlen(host);
+	size_t bucklen;
+
+	if (ourhlen >= hlen)
+		return NULL;
+	bucklen = hlen-ourhlen;		/* at least one */
+	if (strcasecmp(host + bucklen, ourhost))
+		return NULL;
+	if (host[--bucklen] != '.')
+		return NULL;
+	if (bucklen == 0)
+		return NULL;
+	return g_strndup(host, bucklen);
+}
+
 bool bucket_add(struct client *cli, const char *user, const char *bucket)
 {
 	char *hdr, timestr[64];
diff --git a/server/server.c b/server/server.c
index d9320ec..f7ea446 100644
--- a/server/server.c
+++ b/server/server.c
@@ -53,8 +53,6 @@
 
 #define PROGRAM_NAME "tabled"
 
-#define MY_ENDPOINT "pretzel.yyz.us"
-
 const char *argp_program_version = PACKAGE_VERSION;
 
 enum {
@@ -103,9 +101,6 @@ struct server tabled_srv = {
 struct tabledb tdb;
 
 struct compiled_pat patterns[] = {
-	[pat_bucket_host] =
-	{ "^\\s*(\\w+)\\.(\\w.*)$", 0, },
-
 	[pat_auth] =
 	{ "^AWS (\\w+):(\\S+)", 0, },
 
@@ -805,7 +800,6 @@ bool cli_resp_xml(struct client *cli, int http_status,
 
 static bool cli_evt_http_req(struct client *cli, unsigned int events)
 {
-	int captured[16];
 	struct http_req *req = &cli->req;
 	char *host, *auth, *content_len_str;
 	char *bucket = NULL;
@@ -842,21 +836,13 @@ static bool cli_evt_http_req(struct client *cli, unsigned int events)
 		return cli_err(cli, InvalidArgument);
 
 	/* attempt to obtain bucket name from Host */
-	if (pcre_exec(patterns[pat_bucket_host].re, NULL,
-		      host, strlen(host), 0, 0, captured, 16) == 3) {
-		if ((strlen(MY_ENDPOINT) == (captured[5] - captured[4])) &&
-		    (!memcmp(MY_ENDPOINT, host + captured[4],
-		    	     strlen(MY_ENDPOINT)))) {
-			bucket = g_strndup(host + captured[2],
-					 captured[3] - captured[2]);
-			path = g_strndup(req->uri.path, req->uri.path_len);
-		}
-	}
+	bucket = bucket_host(host, tabled_srv.ourhost);
 
 	/* attempt to obtain bucket name from URI path */
-	if (!bucket) {
+	if (!bucket)
 		buck_in_path = bucket_base(req->uri.path, &bucket, &path);
-	}
+	else
+		path = strdup(req->uri.path);
 
 	if (!path)
 		path = strdup("/");
diff --git a/server/tabled.h b/server/tabled.h
index 3cb6ab3..91eb025 100644
--- a/server/tabled.h
+++ b/server/tabled.h
@@ -69,7 +69,6 @@ struct client_write;
 struct server_socket;
 
 enum {
-	pat_bucket_host,
 	pat_auth,
 	pat_ipv4_addr,
 };
@@ -257,6 +256,7 @@ extern bool bucket_list(struct client *cli, const char *user, const char *bucket
 extern bool bucket_del(struct client *cli, const char *user, const char *bucket);
 extern bool bucket_add(struct client *cli, const char *user, const char *bucket);
 extern bool bucket_valid(const char *bucket);
+extern char *bucket_host(const char *host, const char *ourhost);
 extern bool bucket_base(const char *uri_path, char **pbucket, char **ppath);
 extern bool service_list(struct client *cli, const char *user);
 

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-10-21 15:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-20 16:59 [Patch] tabled: fix buckets in subdomains Pete Zaitcev
2009-10-21 15:15 ` Jeff Garzik

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.