Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
87cf8808
提交
87cf8808
authored
2月 07, 2017
作者:
colm
提交者:
Mike Jerris
3月 22, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-9952: Update ks json-rpc api
上级
89940dfc
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
234 行增加
和
520 行删除
+234
-520
ks_rpcmessage.h
libs/libks/src/include/ks_rpcmessage.h
+24
-73
ks_rpcmessage.c
libs/libks/src/ks_rpcmessage.c
+170
-259
testmessages.c
libs/libks/test/testmessages.c
+40
-188
没有找到文件。
libs/libks/src/include/ks_rpcmessage.h
浏览文件 @
87cf8808
...
@@ -31,52 +31,6 @@
...
@@ -31,52 +31,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
*/
/*
* Usage notes
*
* ks_rpcmessaging_handle_t *handle;
*
* ks_rpcmessage_init(pool, &handle);
*
* ks_rpcmessage_version(handle, version);
* ks_rpcmessage_namespace(handle, application_namespace);
* ks_rpcmessage_register_function(handle, "invite", handle_invite_message);
* ks_rpcmessage_register_function(handle, "media", handle_media_message);
*
* ...
* cJSON* request = NULL;
* cJSON* parms = NULL;
* cJSON* response = NULL;
*
* request = ks_rpcmessage_create_request(h, "invite", &parms, &request);
* cJSON_AddStringToObject(parms, "hello", "cruel world");
* ... and send
*
*
* static ks_status_t handle_..._message(ks_rpcmessaging_handle_t* handle, cJSON *msg, cJSON **response)
* {
* cJSON *respvalue = cJSON_CreateNumber(1);
* cJSON *x = *response = ks_rpcmessage_create_response(h, msg, &respvalue, response);
* if ( x == NULL) {
* return KS_STATUS_FAIL;
* }
* ...
* return KS_STATUS_SUCCESS;
* }
*
*
*
*
*
*
* ...
* ks_rpcmessage_deinit(&handle);
*
*/
#ifndef _KS_RPCMESSAGE_H_
#ifndef _KS_RPCMESSAGE_H_
#define _KS_RPCMESSAGE_H_
#define _KS_RPCMESSAGE_H_
...
@@ -85,51 +39,48 @@
...
@@ -85,51 +39,48 @@
KS_BEGIN_EXTERN_C
KS_BEGIN_EXTERN_C
#define KS_RPCMESSAGE_NAMESPACE_LENGTH 16
#define KS_RPCMESSAGE_COMMAND_LENGTH 238
#define KS_RPCMESSAGE_FQCOMMAND_LENGTH (KS_RPCMESSAGE_NAMESPACE_LENGTH+KS_RPCMESSAGE_COMMAND_LENGTH+1)
#define KS_RPCMESSAGE_VERSION_LENGTH 9
typedef
struct
ks_rpcmessaging_handle_s
ks_rpcmessaging_handle_t
;
typedef
uint32_t
ks_rpcmessage_id
;
typedef
uint32_t
ks_rpcmessage_id
;
typedef
ks_status_t
(
*
jrpc_func_t
)(
ks_rpcmessaging_handle_t
*
handle
,
cJSON
*
request
,
cJSON
**
responseP
);
KS_DECLARE
(
void
)
ks_rpcmessage_init
(
ks_pool_t
*
pool
);
typedef
ks_status_t
(
*
jrpc_resp_func_t
)(
ks_rpcmessaging_handle_t
*
handle
,
cJSON
*
response
);
KS_DECLARE
(
void
*
)
ks_json_pool_alloc
(
ks_size_t
size
);
KS_DECLARE
(
void
)
ks_json_pool_free
(
void
*
ptr
);
KS_DECLARE
(
ks_rpcmessaging_handle_t
*
)
ks_rpcmessage_init
(
ks_pool_t
*
pool
,
ks_rpcmessaging_handle_t
**
handleP
);
KS_DECLARE
(
void
)
ks_rpcmessage_deinit
(
ks_rpcmessaging_handle_t
**
handleP
);
KS_DECLARE
(
ks_
status_t
)
ks_rpcmessage_namespace
(
ks_rpcmessaging_handle_t
*
handle
,
const
char
*
namespace
,
const
char
*
version
);
KS_DECLARE
(
ks_
rpcmessage_id
)
ks_rpcmessage_create_request
(
char
*
namespace
,
char
*
method
,
KS_DECLARE
(
ks_rpcmessage_id
)
ks_rpcmessage_create_request
(
ks_rpcmessaging_handle_t
*
handle
,
char
*
sessionid
,
c
onst
char
*
method
,
c
har
*
version
,
cJSON
**
parmsP
,
cJSON
**
parmsP
,
cJSON
**
requestP
);
cJSON
**
requestP
);
KS_DECLARE
(
ks_rpcmessage_id
)
ks_rpcmessage_create_response
(
ks_rpcmessaging_handle_t
*
handle
,
KS_DECLARE
(
ks_size_t
)
ks_rpc_create_buffer
(
char
*
namespace
,
char
*
method
,
char
*
sessionid
,
char
*
version
,
cJSON
**
parmsP
,
ks_buffer_t
*
buffer
);
KS_DECLARE
(
ks_rpcmessage_id
)
ks_rpcmessage_create_response
(
const
cJSON
*
request
,
const
cJSON
*
request
,
cJSON
**
resultP
,
cJSON
**
resultP
,
cJSON
**
responseP
);
cJSON
**
responseP
);
KS_DECLARE
(
ks_rpcmessage_id
)
ks_rpcmessage_create_errorresponse
(
ks_rpcmessaging_handle_t
*
handle
,
KS_DECLARE
(
ks_rpcmessage_id
)
ks_rpcmessage_create_errorresponse
(
const
cJSON
*
request
,
const
cJSON
*
request
,
cJSON
**
errorP
,
cJSON
**
errorP
,
cJSON
**
responseP
);
cJSON
**
responseP
);
KS_DECLARE
(
ks_status_t
)
ks_rpcmessage_register_function
(
ks_rpcmessaging_handle_t
*
handle
,
KS_DECLARE
(
ks_bool_t
)
ks_rpcmessage_isrequest
(
cJSON
*
msg
);
const
char
*
command
,
jrpc_func_t
func
,
jrpc_resp_func_t
respfunc
);
KS_DECLARE
(
jrpc_func_t
)
ks_rpcmessage_find_function
(
ks_rpcmessaging_handle_t
*
handle
,
const
char
*
command
);
KS_DECLARE
(
jrpc_resp_func_t
)
ks_rpcmessage_find_response_function
(
ks_rpcmessaging_handle_t
*
handle
,
const
char
*
command
);
KS_DECLARE
(
ks_status_t
)
ks_rpcmessage_process_message
(
ks_rpcmessaging_handle_t
*
handle
,
uint8_t
*
data
,
ks_size_t
size
,
cJSON
**
responseP
);
KS_DECLARE
(
ks_status_t
)
ks_rpcmessage_process_jsonmessage
(
ks_rpcmessaging_handle_t
*
handle
,
cJSON
*
request
,
cJSON
**
responseP
);
KS_DECLARE
(
ks_bool_t
)
ks_rpcmessage_isrpc
(
cJSON
*
msg
);
KS_END_EXTERN_C
KS_END_EXTERN_C
...
...
libs/libks/src/ks_rpcmessage.c
浏览文件 @
87cf8808
差异被折叠。
点击展开。
libs/libks/test/testmessages.c
浏览文件 @
87cf8808
...
@@ -8,170 +8,65 @@
...
@@ -8,170 +8,65 @@
ks_pool_t
*
pool
;
ks_pool_t
*
pool
;
ks_thread_pool_t
*
tpool
;
ks_rpcmessaging_handle_t
*
h
;
static
ks_thread_t
*
threads
[
10
];
static
char
idbuffer
[
51
];
static
ks_status_t
process_wombat_response
(
ks_rpcmessaging_handle_t
*
handle
,
cJSON
*
msg
)
{
printf
(
"entering process_wombat_response
\n
"
);
printf
(
"exiting process_wombat_response
\n
"
);
return
KS_STATUS_FAIL
;
}
static
ks_status_t
process_wombat
(
ks_rpcmessaging_handle_t
*
handle
,
cJSON
*
msg
,
cJSON
**
response
)
{
printf
(
"entering process_wombat
\n
"
);
char
*
b0
=
cJSON_Print
(
msg
);
printf
(
"Request: %s
\n
"
,
b0
);
free
(
b0
);
cJSON
*
msg_id
=
cJSON_GetObjectItem
(
msg
,
"id"
);
if
(
msg_id
)
{
if
(
msg_id
->
type
==
cJSON_Number
)
{
printf
(
"Number int %d double %f
\n
"
,
msg_id
->
valueint
,
msg_id
->
valuedouble
);
}
}
cJSON
*
respvalue
=
cJSON_CreateNumber
(
1
);
ks_rpcmessage_id
msgid
=
ks_rpcmessage_create_response
(
h
,
msg
,
&
respvalue
,
response
);
char
*
b1
=
cJSON_Print
(
*
response
);
//(*response);
printf
(
"Response: msgid %d
\n
%s
\n
"
,
msgid
,
b1
);
free
(
b1
);
printf
(
"exiting process_wombat
\n
"
);
return
KS_STATUS_SUCCESS
;
}
static
ks_status_t
process_badbunny
(
ks_rpcmessaging_handle_t
*
handle
,
cJSON
*
msg
,
cJSON
**
response
)
{
printf
(
"entering process_badbunny
\n
"
);
char
*
b0
=
cJSON_Print
(
msg
);
printf
(
"Request: %s
\n
"
,
b0
);
free
(
b0
);
cJSON
*
msg_id
=
cJSON_GetObjectItem
(
msg
,
"id"
);
if
(
msg_id
)
{
if
(
msg_id
->
type
==
cJSON_Number
)
{
printf
(
"Number int %d double %f
\n
"
,
msg_id
->
valueint
,
msg_id
->
valuedouble
);
}
}
cJSON
*
respvalue
;
ks_rpcmessage_id
msgid
=
ks_rpcmessage_create_errorresponse
(
h
,
msg
,
&
respvalue
,
response
);
char
*
b2
=
cJSON_Print
(
*
response
);
printf
(
"Request: msgid %d
\n
%s
\n
"
,
msgid
,
b2
);
free
(
b2
);
//cJSON *respvalue = cJSON_CreateNumber(1);
char
*
b1
=
cJSON_Print
(
*
response
);
//(*response);
printf
(
"Response: %s
\n
"
,
b1
);
free
(
b1
);
printf
(
"exiting process_badbunny
\n
"
);
return
KS_STATUS_SUCCESS
;
}
void
test01
()
void
test01
()
{
{
printf
(
"**** testrpcmessages - test01 start
\n
"
);
fflush
(
stdout
);
printf
(
"**** testrpcmessages - test01 start
\n
\n
"
);
fflush
(
stdout
);
ks_rpcmessage_register_function
(
h
,
"wombat"
,
process_wombat
,
process_wombat_response
);
cJSON
*
request1
=
NULL
;
ks_rpcmessage_register_function
(
h
,
"badbunny"
,
process_badbunny
,
NULL
)
;
cJSON
*
parms1
=
NULL
;
ks_rpcmessage_register_function
(
h
,
"onewaywombat"
,
NULL
,
process_wombat_response
)
;
cJSON
*
response1
=
NULL
;
cJSON
*
request
=
NULL
;
/*namespace, method, sessionid, version, params, **request */
cJSON
*
parms
=
NULL
;
ks_rpcmessage_id
msgid
=
ks_rpcmessage_create_request
(
"app1"
,
"func1"
,
"s001"
,
"1.0"
,
&
parms1
,
&
request1
);
cJSON
*
response
=
NULL
;
if
(
msgid
==
0
)
{
printf
(
"message create failed %d
\n
"
,
msgid
);
/* try an invalid message */
ks_rpcmessage_id
msgid
=
ks_rpcmessage_create_request
(
h
,
"colm"
,
&
parms
,
&
request
);
if
(
msgid
!=
0
)
{
printf
(
"invalid message created %d
\n
"
,
msgid
);
printf
(
"request:
\n
%s
\n
"
,
cJSON_Print
(
request
));
}
}
/* try a basic message */
cJSON_AddStringToObject
(
parms1
,
"hello"
,
"cruel world"
);
char
*
data
=
cJSON_PrintUnformatted
(
request1
);
msgid
=
ks_rpcmessage_create_request
(
h
,
"wombat"
,
&
parms
,
&
request
);
if
(
msgid
==
0
)
{
printf
(
"failed to create a wombat
\n
"
);
return
;
}
cJSON_AddStringToObject
(
parms
,
"hello"
,
"cruel world"
);
char
*
data
=
cJSON_PrintUnformatted
(
request
);
printf
(
"
\n
test01 request: %d
\n
%s
\n\n
"
,
msgid
,
data
);
printf
(
"test01 request1: %d
\n
%s
\n\n
"
,
msgid
,
data
);
ks_json_pool_free
(
data
);
/* process message */
ks_size_t
size
=
strlen
(
data
);
ks_status_t
status
=
ks_rpcmessage_process_message
(
h
,
(
uint8_t
*
)
data
,
size
,
&
response
);
char
*
data1
=
cJSON_Print
(
response
);
/* convert to buffer */
ks_size_t
size1
=
strlen
(
data1
);
cJSON
*
parms2
=
NULL
;
printf
(
"
\n
test01i response: %d
\n
%s
\n\n
"
,
msgid
,
data1
);
ks_buffer_t
*
buffer
;
/* process response */
ks_
status_t
status1
=
ks_rpcmessage_process_message
(
h
,
(
uint8_t
*
)
data1
,
size1
,
&
response
);
ks_
buffer_create
(
&
buffer
,
256
,
256
,
1024
);
free
(
data
);
ks_size_t
n
=
ks_rpc_create_buffer
(
"app2"
,
"func2"
,
"s002"
,
"1.1"
,
&
parms2
,
buffer
);
free
(
data1
);
cJSON_Delete
(
request
);
/* create message 2 */
ks_size_t
size
=
ks_buffer_len
(
buffer
);
char
*
b
=
(
char
*
)
ks_pool_alloc
(
pool
,
size
+
1
);
ks_buffer_read
(
buffer
,
b
,
size
);
printf
(
"test01 request2: %d %d from ks_buffer
\n
%s
\n\n\n
"
,
n
,
size
,
b
);
cJSON
*
parms1
=
cJSON_CreateNumber
(
1
);
cJSON
*
request1
=
NULL
;
msgid
=
ks_rpcmessage_create_request
(
h
,
"badbunny"
,
&
parms1
,
&
request1
);
/* create message 3 */
cJSON
*
parms3
=
cJSON_CreateNumber
(
1
);
cJSON
*
request3
=
NULL
;
data
=
cJSON_PrintUnformatted
(
request1
);
msgid
=
ks_rpcmessage_create_request
(
"app1"
,
"badbunny"
,
"s002"
,
"1.1"
,
&
parms3
,
&
request3
);
data
=
cJSON_PrintUnformatted
(
request3
);
printf
(
"
\n
test01i request: %d
\n
%s
\n\n
"
,
msgid
,
data
);
printf
(
"
\n
test01i request: %d
\n
%s
\n\n
"
,
msgid
,
data
);
/* process message 2 */
cJSON
*
response3
=
NULL
;
cJSON
*
reply3
=
NULL
;
size
=
strlen
(
data
);
status
=
ks_rpcmessage_process_message
(
h
,
(
uint8_t
*
)
data
,
size
,
&
response
);
data1
=
cJSON_PrintUnformatted
(
response
);
printf
(
"
\n
test01 response: %d
\n
%s
\n\n
"
,
msgid
,
data1
);
/* process response 2 - no handler so this should fail */
size1
=
strlen
(
data1
);
ks_rpcmessage_create_response
(
request3
,
&
reply3
,
&
response3
);
status
=
ks_rpcmessage_process_message
(
h
,
(
uint8_t
*
)
data1
,
size1
,
&
response
);
if
(
status
!=
KS_STATUS_FAIL
)
{
printf
(
"badbunny found a response handler ?
\n
"
);
}
free
(
data
);
data
=
cJSON_PrintUnformatted
(
response3
);
free
(
data1
);
printf
(
"
\n
test01 response3: %d
\n
%s
\n\n
"
,
msgid
,
data
);
cJSON_Delete
(
request1
);
ks_json_pool_free
(
data
);
cJSON_Delete
(
request3
);
cJSON_Delete
(
response3
);
printf
(
"**** testrpcmessages - test01 complete
\n\n\n
"
);
fflush
(
stdout
);
printf
(
"**** testrpcmessages - test01 complete
\n\n\n
"
);
fflush
(
stdout
);
}
}
...
@@ -186,54 +81,13 @@ void test02()
...
@@ -186,54 +81,13 @@ void test02()
/* test06 */
/* ------ */
static
void
*
testnodelocking_ex1
(
ks_thread_t
*
thread
,
void
*
data
)
{
return
NULL
;
}
static
void
*
testnodelocking_ex2
(
ks_thread_t
*
thread
,
void
*
data
)
{
return
NULL
;
}
void
test06
()
{
printf
(
"**** testmessages - test06 start
\n
"
);
fflush
(
stdout
);
ks_thread_t
*
t0
;
ks_thread_create
(
&
t0
,
testnodelocking_ex1
,
NULL
,
pool
);
ks_thread_t
*
t1
;
ks_thread_create
(
&
t1
,
testnodelocking_ex2
,
NULL
,
pool
);
ks_thread_join
(
t1
);
ks_thread_join
(
t0
);
printf
(
"
\n\n
* **testmessages - test06 -- threads complete
\n\n
"
);
fflush
(
stdout
);
printf
(
"**** testmessages - test06 start
\n
"
);
fflush
(
stdout
);
return
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
printf
(
"testmessages - start
\n
"
);
printf
(
"testmessages - start
\n
"
);
int
tests
[
100
];
int
tests
[
100
];
if
(
argc
==
0
)
{
if
(
argc
==
1
)
{
tests
[
0
]
=
1
;
tests
[
0
]
=
1
;
tests
[
1
]
=
2
;
tests
[
2
]
=
3
;
tests
[
3
]
=
4
;
tests
[
4
]
=
5
;
}
}
else
{
else
{
for
(
int
tix
=
1
;
tix
<
100
&&
tix
<
argc
;
++
tix
)
{
for
(
int
tix
=
1
;
tix
<
100
&&
tix
<
argc
;
++
tix
)
{
...
@@ -254,16 +108,14 @@ int main(int argc, char *argv[]) {
...
@@ -254,16 +108,14 @@ int main(int argc, char *argv[]) {
for
(
int
tix
=
0
;
tix
<
argc
;
++
tix
)
{
for
(
int
tix
=
0
;
tix
<
argc
;
++
tix
)
{
if
(
tests
[
tix
]
==
1
)
{
if
(
tests
[
tix
]
==
1
)
{
ks_rpcmessage_init
(
pool
,
&
h
);
ks_rpcmessage_init
(
pool
);
test01
();
test01
();
ks_rpcmessage_deinit
(
&
h
);
continue
;
continue
;
}
}
if
(
tests
[
tix
]
==
2
)
{
if
(
tests
[
tix
]
==
2
)
{
ks_rpcmessage_init
(
pool
,
&
h
);
ks_rpcmessage_init
(
pool
);
test02
();
test02
();
ks_rpcmessage_deinit
(
&
h
);
continue
;
continue
;
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论