Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
asterisk
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Voice
asterisk
Commits
9581407f
Commit
9581407f
authored
8 years ago
by
zuul
Committed by
Gerrit Code Review
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge "json: Check party id name, number, subaddresses for UTF-8."
parents
5b70ae04
774d5f7e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
main/json.c
+14
-11
14 additions, 11 deletions
main/json.c
tests/test_json.c
+22
-12
22 additions, 12 deletions
tests/test_json.c
with
36 additions
and
23 deletions
main/json.c
+
14
−
11
View file @
9581407f
...
@@ -842,16 +842,16 @@ struct ast_json *ast_json_deep_copy(const struct ast_json *value)
...
@@ -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
)
struct
ast_json
*
ast_json_name_number
(
const
char
*
name
,
const
char
*
number
)
{
{
return
ast_json_pack
(
"{s: s, s: s}"
,
return
ast_json_pack
(
"{s: s, s: s}"
,
"name"
,
name
,
"name"
,
AST_JSON_UTF8_VALIDATE
(
name
)
,
"number"
,
number
);
"number"
,
AST_JSON_UTF8_VALIDATE
(
number
)
)
;
}
}
struct
ast_json
*
ast_json_dialplan_cep
(
const
char
*
context
,
const
char
*
exten
,
int
priority
)
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}"
,
return
ast_json_pack
(
"{s: o, s: o, s: o}"
,
"context"
,
context
?
ast_json_string_create
(
context
)
:
ast_json_null
(),
"context"
,
context
?
ast_json_string_create
(
context
)
:
ast_json_null
(),
"exten"
,
exten
?
ast_json_string_create
(
exten
)
:
ast_json_null
(),
"exten"
,
exten
?
ast_json_string_create
(
exten
)
:
ast_json_null
(),
"priority"
,
priority
!=
-
1
?
ast_json_integer_create
(
priority
)
:
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
)
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)
...
@@ -942,7 +942,7 @@ static struct ast_json *json_party_number(struct ast_party_number *number)
return
NULL
;
return
NULL
;
}
}
return
ast_json_pack
(
"{s: s, s: i, s: i, s: s}"
,
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
,
"plan"
,
number
->
plan
,
"presentation"
,
number
->
presentation
,
"presentation"
,
number
->
presentation
,
"presentation_txt"
,
ast_describe_caller_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)
...
@@ -954,7 +954,7 @@ static struct ast_json *json_party_name(struct ast_party_name *name)
return
NULL
;
return
NULL
;
}
}
return
ast_json_pack
(
"{s: s, s: s, s: i, s: s}"
,
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
),
"character_set"
,
ast_party_name_charset_describe
(
name
->
char_set
),
"presentation"
,
name
->
presentation
,
"presentation"
,
name
->
presentation
,
"presentation_txt"
,
ast_describe_caller_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
...
@@ -966,7 +966,7 @@ static struct ast_json *json_party_subaddress(struct ast_party_subaddress *subad
return
NULL
;
return
NULL
;
}
}
return
ast_json_pack
(
"{s: s, s: i, s: b}"
,
return
ast_json_pack
(
"{s: s, s: i, s: b}"
,
"subaddress"
,
subaddress
->
str
,
"subaddress"
,
AST_JSON_UTF8_VALIDATE
(
subaddress
->
str
)
,
"type"
,
subaddress
->
type
,
"type"
,
subaddress
->
type
,
"odd"
,
subaddress
->
odd_even_indicator
);
"odd"
,
subaddress
->
odd_even_indicator
);
}
}
...
@@ -986,17 +986,20 @@ struct ast_json *ast_json_party_id(struct ast_party_id *party)
...
@@ -986,17 +986,20 @@ struct ast_json *ast_json_party_id(struct ast_party_id *party)
}
}
/* Party number */
/* 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
;
return
NULL
;
}
}
/* Party name */
/* 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
;
return
NULL
;
}
}
/* Party subaddress */
/* 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
;
return
NULL
;
}
}
...
...
This diff is collapsed.
Click to expand it.
tests/test_json.c
+
22
−
12
View file @
9581407f
...
@@ -1598,11 +1598,26 @@ AST_TEST_DEFINE(json_test_clever_circle)
...
@@ -1598,11 +1598,26 @@ AST_TEST_DEFINE(json_test_clever_circle)
return
AST_TEST_PASS
;
return
AST_TEST_PASS
;
}
}
AST_TEST_DEFINE
(
json_test_name_
number
)
static
int
test_name_number
(
const
char
*
name
,
const
char
*
number
)
{
{
RAII_VAR
(
struct
ast_json
*
,
uut
,
NULL
,
ast_json_unref
);
int
res
;
RAII_VAR
(
struct
ast_json
*
,
expected
,
NULL
,
ast_json_unref
);
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
)
{
switch
(
cmd
)
{
switch
(
cmd
)
{
case
TEST_INIT
:
case
TEST_INIT
:
info
->
name
=
"name_number"
;
info
->
name
=
"name_number"
;
...
@@ -1614,15 +1629,10 @@ AST_TEST_DEFINE(json_test_name_number)
...
@@ -1614,15 +1629,10 @@ AST_TEST_DEFINE(json_test_name_number)
break
;
break
;
}
}
ast_test_validate
(
test
,
NULL
==
ast_json_name_number
(
"name"
,
NULL
));
ast_test_validate
(
test
,
test_name_number
(
"name"
,
NULL
));
ast_test_validate
(
test
,
NULL
==
ast_json_name_number
(
NULL
,
"1234"
));
ast_test_validate
(
test
,
test_name_number
(
NULL
,
"1234"
));
ast_test_validate
(
test
,
NULL
==
ast_json_name_number
(
NULL
,
NULL
));
ast_test_validate
(
test
,
test_name_number
(
NULL
,
NULL
));
ast_test_validate
(
test
,
test_name_number
(
"Jenny"
,
"867-5309"
));
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
));
return
AST_TEST_PASS
;
return
AST_TEST_PASS
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment