mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-02 19:16:15 +00:00
json: Check party id name, number, subaddresses for UTF-8.
* Updated unit test as ast_json_name_number() is now NULL tolerant. ASTERISK-26466 #close Reported by: Richard Mudgett Change-Id: I7d4e14194f8f81f24a1dc34d1b8602c0950265a6
This commit is contained in:
25
main/json.c
25
main/json.c
@@ -842,16 +842,16 @@ struct ast_json *ast_json_deep_copy(const struct ast_json *value)
|
||||
struct ast_json *ast_json_name_number(const char *name, const char *number)
|
||||
{
|
||||
return ast_json_pack("{s: s, s: s}",
|
||||
"name", name,
|
||||
"number", number);
|
||||
"name", AST_JSON_UTF8_VALIDATE(name),
|
||||
"number", AST_JSON_UTF8_VALIDATE(number));
|
||||
}
|
||||
|
||||
struct ast_json *ast_json_dialplan_cep(const char *context, const char *exten, int priority)
|
||||
{
|
||||
return ast_json_pack("{s: o, s: o, s: o}",
|
||||
"context", context ? ast_json_string_create(context) : ast_json_null(),
|
||||
"exten", exten ? ast_json_string_create(exten) : ast_json_null(),
|
||||
"priority", priority != -1 ? ast_json_integer_create(priority) : ast_json_null());
|
||||
"context", context ? ast_json_string_create(context) : ast_json_null(),
|
||||
"exten", exten ? ast_json_string_create(exten) : ast_json_null(),
|
||||
"priority", priority != -1 ? ast_json_integer_create(priority) : ast_json_null());
|
||||
}
|
||||
|
||||
struct ast_json *ast_json_timeval(const struct timeval tv, const char *zone)
|
||||
@@ -942,7 +942,7 @@ static struct ast_json *json_party_number(struct ast_party_number *number)
|
||||
return NULL;
|
||||
}
|
||||
return ast_json_pack("{s: s, s: i, s: i, s: s}",
|
||||
"number", number->str,
|
||||
"number", AST_JSON_UTF8_VALIDATE(number->str),
|
||||
"plan", number->plan,
|
||||
"presentation", number->presentation,
|
||||
"presentation_txt", ast_describe_caller_presentation(number->presentation));
|
||||
@@ -954,7 +954,7 @@ static struct ast_json *json_party_name(struct ast_party_name *name)
|
||||
return NULL;
|
||||
}
|
||||
return ast_json_pack("{s: s, s: s, s: i, s: s}",
|
||||
"name", name->str,
|
||||
"name", AST_JSON_UTF8_VALIDATE(name->str),
|
||||
"character_set", ast_party_name_charset_describe(name->char_set),
|
||||
"presentation", name->presentation,
|
||||
"presentation_txt", ast_describe_caller_presentation(name->presentation));
|
||||
@@ -966,7 +966,7 @@ static struct ast_json *json_party_subaddress(struct ast_party_subaddress *subad
|
||||
return NULL;
|
||||
}
|
||||
return ast_json_pack("{s: s, s: i, s: b}",
|
||||
"subaddress", subaddress->str,
|
||||
"subaddress", AST_JSON_UTF8_VALIDATE(subaddress->str),
|
||||
"type", subaddress->type,
|
||||
"odd", subaddress->odd_even_indicator);
|
||||
}
|
||||
@@ -986,17 +986,20 @@ struct ast_json *ast_json_party_id(struct ast_party_id *party)
|
||||
}
|
||||
|
||||
/* Party number */
|
||||
if (party->number.valid && ast_json_object_set(json_party_id, "number", json_party_number(&party->number))) {
|
||||
if (party->number.valid
|
||||
&& ast_json_object_set(json_party_id, "number", json_party_number(&party->number))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Party name */
|
||||
if (party->name.valid && ast_json_object_set(json_party_id, "name", json_party_name(&party->name))) {
|
||||
if (party->name.valid
|
||||
&& ast_json_object_set(json_party_id, "name", json_party_name(&party->name))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Party subaddress */
|
||||
if (party->subaddress.valid && ast_json_object_set(json_party_id, "subaddress", json_party_subaddress(&party->subaddress))) {
|
||||
if (party->subaddress.valid
|
||||
&& ast_json_object_set(json_party_id, "subaddress", json_party_subaddress(&party->subaddress))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@@ -1598,11 +1598,26 @@ AST_TEST_DEFINE(json_test_clever_circle)
|
||||
return AST_TEST_PASS;
|
||||
}
|
||||
|
||||
static int test_name_number(const char *name, const char *number)
|
||||
{
|
||||
int res;
|
||||
struct ast_json *uut;
|
||||
struct ast_json *expected;
|
||||
|
||||
expected = ast_json_pack("{s: s, s: s}",
|
||||
"name", name ?: "",
|
||||
"number", number ?: "");
|
||||
uut = ast_json_name_number(name, number);
|
||||
|
||||
res = ast_json_equal(expected, uut);
|
||||
|
||||
ast_json_unref(expected);
|
||||
ast_json_unref(uut);
|
||||
return res;
|
||||
}
|
||||
|
||||
AST_TEST_DEFINE(json_test_name_number)
|
||||
{
|
||||
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
|
||||
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
|
||||
|
||||
switch (cmd) {
|
||||
case TEST_INIT:
|
||||
info->name = "name_number";
|
||||
@@ -1614,15 +1629,10 @@ AST_TEST_DEFINE(json_test_name_number)
|
||||
break;
|
||||
}
|
||||
|
||||
ast_test_validate(test, NULL == ast_json_name_number("name", NULL));
|
||||
ast_test_validate(test, NULL == ast_json_name_number(NULL, "1234"));
|
||||
ast_test_validate(test, NULL == ast_json_name_number(NULL, NULL));
|
||||
|
||||
expected = ast_json_pack("{s: s, s: s}",
|
||||
"name", "Jenny",
|
||||
"number", "867-5309");
|
||||
uut = ast_json_name_number("Jenny", "867-5309");
|
||||
ast_test_validate(test, ast_json_equal(expected, uut));
|
||||
ast_test_validate(test, test_name_number("name", NULL));
|
||||
ast_test_validate(test, test_name_number(NULL, "1234"));
|
||||
ast_test_validate(test, test_name_number(NULL, NULL));
|
||||
ast_test_validate(test, test_name_number("Jenny", "867-5309"));
|
||||
|
||||
return AST_TEST_PASS;
|
||||
}
|
||||
|
Reference in New Issue
Block a user