Merging in latest from upstream (FS/freeswitch:refs/heads/master)

* commit 'b60df39b96b05b6c3cf220d5049ea5fc20dfa6e1':
  mod_http_cache: fix configuration so that carriage returns or other whitespace is OK around S3 keys
  mod_http_cache: fixed S3 URL parser to allow mybucketsubdomain.com.s3.amazonaws.com
This commit is contained in:
Stan Gor 2014-08-12 22:08:44 -05:00
commit 4d0b875d4e
3 changed files with 56 additions and 12 deletions

View File

@ -105,6 +105,39 @@ char *aws_s3_signature(char *signature, int signature_length, const char *string
return signature;
}
/**
* Reverse string substring search
*/
static char *my_strrstr(const char *haystack, const char *needle)
{
char *s;
size_t needle_len;
size_t haystack_len;
if (zstr(haystack)) {
return NULL;
}
if (zstr(needle)) {
return (char *)haystack;
}
needle_len = strlen(needle);
haystack_len = strlen(haystack);
if (needle_len > haystack_len) {
return NULL;
}
s = (char *)(haystack + haystack_len - needle_len);
do {
if (!strncmp(s, needle, needle_len)) {
return s;
}
} while (s-- != haystack);
return NULL;
}
/**
* Parse bucket and object from URL
* @param url to parse. This value is modified.
@ -113,7 +146,7 @@ char *aws_s3_signature(char *signature, int signature_length, const char *string
*/
void aws_s3_parse_url(char *url, char **bucket, char **object)
{
char *bucket_start;
char *bucket_start = NULL;
char *bucket_end;
char *object_start;
@ -124,15 +157,18 @@ void aws_s3_parse_url(char *url, char **bucket, char **object)
return;
}
/* expect: http(s)://bucket.s3.amazonaws.com/object */
bucket_start = strstr(url, "://");
if (!bucket_start) {
/* expect: http(s)://bucket.foo-bar.s3.amazonaws.com/object */
if (!strncasecmp(url, "https://", 8)) {
bucket_start = url + 8;
} else if (!strncasecmp(url, "http://", 7)) {
bucket_start = url + 7;
}
if (zstr(bucket_start)) {
/* invalid URL */
return;
}
bucket_start += 3;
bucket_end = strchr(bucket_start, '.');
bucket_end = my_strrstr(bucket_start, ".s3");
if (!bucket_end) {
/* invalid URL */
return;

View File

@ -1395,17 +1395,19 @@ static switch_status_t do_config(url_cache_t *cache)
http_profile_t *profile_obj;
switch_xml_t domains;
switch_xml_t s3 = switch_xml_child(profile, "aws-s3");
const char *access_key_id = NULL;
const char *secret_access_key = NULL;
char *access_key_id = NULL;
char *secret_access_key = NULL;
if (s3) {
switch_xml_t id = switch_xml_child(s3, "access-key-id");
switch_xml_t secret = switch_xml_child(s3, "secret-access-key");
if (id && secret) {
access_key_id = switch_xml_txt(id);
secret_access_key = switch_xml_txt(secret);
if (!access_key_id || !secret_access_key) {
access_key_id = switch_strip_whitespace(switch_xml_txt(id));
secret_access_key = switch_strip_whitespace(switch_xml_txt(secret));
if (zstr(access_key_id) || zstr(secret_access_key)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Missing aws s3 credentials for profile \"%s\"\n", name);
switch_safe_free(access_key_id);
access_key_id = NULL;
switch_safe_free(secret_access_key);
secret_access_key = NULL;
}
} else {
@ -1414,6 +1416,8 @@ static switch_status_t do_config(url_cache_t *cache)
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Adding profile \"%s\" to cache\n", name);
profile_obj = url_cache_http_profile_add(cache, name, access_key_id, secret_access_key);
switch_safe_free(access_key_id);
switch_safe_free(secret_access_key);
domains = switch_xml_child(profile, "domains");
if (domains) {

View File

@ -111,6 +111,10 @@ static void test_parse_url(void)
aws_s3_parse_url(strdup("https://my-bucket-with-dash.s3-us-west-2.amazonaws.com/greeting/file/1002/Lumino.mp3"), &bucket, &object);
ASSERT_STRING_EQUALS("my-bucket-with-dash", bucket);
ASSERT_STRING_EQUALS("greeting/file/1002/Lumino.mp3", object);
aws_s3_parse_url(strdup("http://quotes.s3.foo.bar.s3.amazonaws.com/greeting/file/1002/Lumino.mp3"), &bucket, &object);
ASSERT_STRING_EQUALS("quotes.s3.foo.bar", bucket);
ASSERT_STRING_EQUALS("greeting/file/1002/Lumino.mp3", object);
}
/**