如果你在开发GB28181时选用了pjsip作为sip协议栈,那么在插入GB35114认证消息时惊奇的发现,我接收不到GB35114的sip消息了。
是的,pjsip将gb35114的消息进行过滤了。
既然过滤掉了我们的消息,我们就要让它对我们需要的消息放行(暴力)。
在sip_parser.c文件内有函数
static pjsip_msg *int_parse_msg( pjsip_parse_ctx *ctx,
pjsip_parser_err_report *err_list);
该函数会对接收到的消息进行格式解析,如果错误会将其插入到err list。
我们在PJ_CATCH_ANY下对gb35114认证消息进行筛选
PJ_CATCH_ANY
{
/* Exception was thrown during parsing.
* Skip until newline, and parse next header.
*/
//add 35114 Authorization bob 2019/10/28
int i,code = 1;
for(i = 0;gb_arry[i].ptr;i++)
{
if(!memcmp(hname.ptr,gb_arry[i].ptr,gb_arry[i].len))
{
//printf("get 35114 msg\n");
code =0;
break;
}
}
if(code)
{
if (err_list) {
pjsip_parser_err_report *err_info;
printf("enter err_list\n");
err_info = PJ_POOL_ALLOC_T(pool, pjsip_parser_err_report);
err_info->except_code = PJ_GET_EXCEPTION();
err_info->line = scanner->line;
/* Scanner's column is zero based, so add 1 */
err_info->col = pj_scan_get_col(scanner) + 1;
if (parsing_headers)
err_info->hname = hname;
else if (msg && msg->type == PJSIP_REQUEST_MSG)
err_info->hname = pj_str("Request Line");
else if (msg && msg->type == PJSIP_RESPONSE_MSG)
err_info->hname = pj_str("Status Line");
else
err_info->hname.slen = 0;
pj_list_insert_before(err_list, err_info);
}
if (parsing_headers) {
if (!pj_scan_is_eof(scanner)) {
/* Skip until next line.
* Watch for header continuation.
*/
do {
pj_scan_skip_line(scanner);
} while (IS_SPACE(*scanner->curptr));
}
/* Restore flag. Flag may be set in int_parse_sip_url() */
scanner->skip_ws = PJ_SCAN_AUTOSKIP_WS_HEADER;
/* Continue parse next header, if any. */
if (!pj_scan_is_eof(scanner) && !IS_NEWLINE(*scanner->curptr)) {
goto retry_parse;
}
}
msg = NULL;
}
}
gb_arry定义
typedef struct _gb35114_auth_t
{
char *ptr;
int len;
}gb35114_auth_t;
static gb35114_auth_t gb_arry[] =
{
{"Authorization: Capability",sizeof("Authorization: Capability")-1},
{"WWW-Authenticate: Unidirection",sizeof("WWW-Authenticate: Unidirection")-1},
{"Authorization: Unidirection",sizeof("Authorization: Unidirection")-1},
{"SecurityInfo: Unidirection",sizeof("SecurityInfo: Unidirection")-1},
{"WWW-Authenticate: Bidirection",sizeof("WWW-Authenticate: Bidirection")-1},
{"Authorization: Bidirection",sizeof("Authorization: Bidirection")-1},
{"SecurityInfo: Bidirection",sizeof("SecurityInfo: Bidirection")-1},
{NULL,0}
};
到此编译,替换掉pjsip库,就能收到gb35114的认证消息了。
https://download.csdn.net/download/xlb8224866/12243447 这是改过之后的源码。
有错误请留言,谢谢
下篇继续
GB35114---基于openssl加密库进行开发(一)
---bob 2020/3/12 11:54