mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-04 11:58:52 +00:00
db.c: Remove limit on family/key length
Consumers like media_cache have been running into issues with
the previous astdb "/family/key" limit of 253 bytes when needing
to store things like long URIs. An Amazon S3 URI is a good example
of this. Now, instead of using a static 256 byte buffer for
"/family/key", we use ast_asprintf() to dynamically create it.
Both test_db.c and test_media_cache.c were also updated to use
keys/URIs over the old 253 character limit.
Resolves: #881
UserNote: The `ast_db_*()` APIs have had the 253 byte limit on
"/family/key" removed and will now accept families and keys with a
total length of up to SQLITE_MAX_LENGTH (currently 1e9!). This
affects the `DB*` dialplan applications, dialplan functions,
manager actions and `databse` CLI commands. Since the
media_cache also uses the `ast_db_*()` APIs, you can now store
resources with URIs longer than 253 bytes.
(cherry picked from commit 01aa84e42f
)
This commit is contained in:
committed by
Asterisk Development Team
parent
7977e17a2d
commit
2ddeea3842
@@ -235,6 +235,7 @@ AST_TEST_DEFINE(put_get_long)
|
||||
{
|
||||
int res = AST_TEST_PASS;
|
||||
struct ast_str *s;
|
||||
struct ast_str *key;
|
||||
int i, j;
|
||||
|
||||
#define STR_FILL_32 "abcdefghijklmnopqrstuvwxyz123456"
|
||||
@@ -245,7 +246,7 @@ AST_TEST_DEFINE(put_get_long)
|
||||
info->category = "/main/astdb/";
|
||||
info->summary = "ast_db_(put|get_allocated) unit test";
|
||||
info->description =
|
||||
"Ensures that the ast_db_put and ast_db_get_allocated functions work";
|
||||
"Ensures that the ast_db_put and ast_db_get_allocated functions work with log key and long data";
|
||||
return AST_TEST_NOT_RUN;
|
||||
case TEST_EXECUTE:
|
||||
break;
|
||||
@@ -255,25 +256,34 @@ AST_TEST_DEFINE(put_get_long)
|
||||
return AST_TEST_FAIL;
|
||||
}
|
||||
|
||||
if (!(key = ast_str_create(512))) {
|
||||
return AST_TEST_FAIL;
|
||||
}
|
||||
|
||||
for (j = 0; j < 512; j += sizeof(STR_FILL_32) - 1) {
|
||||
ast_str_append(&key, 0, "%s", STR_FILL_32);
|
||||
}
|
||||
|
||||
for (i = 1024; i <= 1024 * 1024 * 8; i *= 2) {
|
||||
char *out = NULL;
|
||||
|
||||
ast_str_reset(s);
|
||||
ast_str_reset(key);
|
||||
|
||||
for (j = 0; j < i; j += sizeof(STR_FILL_32) - 1) {
|
||||
ast_str_append(&s, 0, "%s", STR_FILL_32);
|
||||
}
|
||||
|
||||
if (ast_db_put("astdbtest", "long", ast_str_buffer(s))) {
|
||||
if (ast_db_put("astdbtest", ast_str_buffer(key), ast_str_buffer(s))) {
|
||||
ast_test_status_update(test, "Failed to put value of %zu bytes\n", ast_str_strlen(s));
|
||||
res = AST_TEST_FAIL;
|
||||
} else if (ast_db_get_allocated("astdbtest", "long", &out)) {
|
||||
} else if (ast_db_get_allocated("astdbtest", ast_str_buffer(key), &out)) {
|
||||
ast_test_status_update(test, "Failed to get value of %zu bytes\n", ast_str_strlen(s));
|
||||
res = AST_TEST_FAIL;
|
||||
} else if (strcmp(ast_str_buffer(s), out)) {
|
||||
ast_test_status_update(test, "Failed to match value of %zu bytes\n", ast_str_strlen(s));
|
||||
res = AST_TEST_FAIL;
|
||||
} else if (ast_db_del("astdbtest", "long")) {
|
||||
} else if (ast_db_del("astdbtest", ast_str_buffer(key))) {
|
||||
ast_test_status_update(test, "Failed to delete astdbtest/long\n");
|
||||
res = AST_TEST_FAIL;
|
||||
}
|
||||
@@ -284,6 +294,7 @@ AST_TEST_DEFINE(put_get_long)
|
||||
}
|
||||
|
||||
ast_free(s);
|
||||
ast_free(key);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@@ -41,8 +41,8 @@
|
||||
/*! The unit test category */
|
||||
#define CATEGORY "/main/media_cache/"
|
||||
|
||||
/*! A 'valid' resource for the test bucket behind the media cache facade */
|
||||
#define VALID_RESOURCE "httptest://localhost:8088/test_media_cache/monkeys.wav"
|
||||
/*! A 'valid' long resource for the test bucket behind the media cache facade */
|
||||
#define VALID_RESOURCE "httptest://localhost:8088/test_media_cache/test_media_cache/test_media_cache/test_media_cache/test_media_cache/test_media_cache/test_media_cache/test_media_cache/test_media_cache/test_media_cache/test_media_cache/test_media_cache/test_media_cache/monkeys.wav"
|
||||
|
||||
/*! An 'invalid' resource for the test bucket behind the media cache facade */
|
||||
#define INVALID_RESOURCE "httptest://localhost:8088/test_media_cache/bad.wav"
|
||||
@@ -109,6 +109,7 @@ static void *bucket_http_test_wizard_retrieve_id(const struct ast_sorcery *sorce
|
||||
static int bucket_http_test_wizard_delete(const struct ast_sorcery *sorcery, void *data,
|
||||
void *object)
|
||||
{
|
||||
ast_media_cache_delete(VALID_RESOURCE);
|
||||
if (!strcmp(ast_sorcery_object_get_id(object), VALID_RESOURCE)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -250,6 +251,8 @@ AST_TEST_DEFINE(create_update_nominal)
|
||||
ast_test_validate(test, res == 0);
|
||||
ast_test_validate(test, strcmp(file_path, tmp_path_two) == 0);
|
||||
|
||||
ast_media_cache_delete(VALID_RESOURCE);
|
||||
|
||||
unlink(tmp_path_one);
|
||||
unlink(tmp_path_two);
|
||||
|
||||
|
Reference in New Issue
Block a user