GB35114---基於pjsip協議庫開發問題

如果你在開發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       

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章