pjsua make_call python中的隐私和自定义标头



我正在尝试添加;隐私:id"根据传出呼叫的标头https://www.rfc-editor.org/rfc/rfc3325#section-9.3

我有一个基于文档的简单调用脚本,它可以进行调用,但当我用tcpdump查看它时,它不会添加头,并且调用方id不会被隐藏。

旧的文档说make_call中的hdr_list应该是一个以昏迷分隔的列表,列表中包含一个扁平字符串中的头键/值对。当我试图传递python列表时,调用失败了,所以我认为平面字符串是正确的,但它不会被传递——尽管在我的测试中,我只使用了一个标头键/值对。

import sys
import pjsua as pj
SOUND_DEVICE = 0
# Logging callback
def log_cb(level, str, len):
print str,
# Callback to receive events from Call
class MyCallCallback(pj.CallCallback):
def __init__(self, call=None):
pj.CallCallback.__init__(self, call)
# Notification when call state has changed
def on_state(self):
print "Call is ", self.call.info().state_text,
print "last code =", self.call.info().last_code,
print "(" + self.call.info().last_reason + ")"
# Notification when call's media state has changed.
def on_media_state(self):
global lib
if self.call.info().media_state == pj.MediaState.ACTIVE:
# Connect the call to sound device
call_slot = self.call.info().conf_slot
lib.conf_connect(call_slot, SOUND_DEVICE)
lib.conf_connect(SOUND_DEVICE, call_slot)
print "Hello world, I can talk!"
try:
# Create library instance
lib = pj.Lib()
# Init library with default config
lib.init(log_cfg = pj.LogConfig(level=3, callback=log_cb))
# no soundcard
lib.set_null_snd_dev()
# Create UDP transport which listens to any available port
transport = lib.create_transport(pj.TransportType.UDP)
# Start the library
lib.start()
# Create local/user-less account
acconf = pj.AccountConfig(domain="myendpoint.com", 
username="my_call_id", 
password="", 
proxy="", 
registrar="")
acc = lib.create_account(acconf, cb=None)
# Make call
call = acc.make_call("sip:my_mobile@myendpoint.com", cb = MyCallCallback(),  hdr_list = "Privacy: id")

# Wait for ENTER before quitting
print "Press <ENTER> to quit"
input = sys.stdin.readline().rstrip("rn")
# We're done, shutdown the library
lib.destroy()
lib = None
except pj.Error, e:
print "Exception: " + str(e)
lib.destroy()
lib = None
sys.exit(1)

如何使用Python接口添加此标头?如果我能避免的话,我真的不想修改库代码。

版本信息:os_core_unix.c!用于POSIX的pjlib 2.11已初始化;pjsua_core.c。用于Linux的pjsua 2.11版本-4.15.0.97/x86_64/glibc-2.27已初始化

函数文档https://www.pjsip.org/python/pjsua.htm#Account具有误导性make_call(self,dst_uri,cb=无,hdr_list=无(

hdr_list—要与传出一起发送的标头的可选列表邀请

基于此,人们会认为需要传递的是["Privacy:id","My other header key:value"]

事实上,一旦读到C库代码,就会明显地看到一个元组列表:

https://github.com/pjsip/pjproject/blob/ea7105c222d657d3c1f7fb18ff9130450e2e40e6/pjsip-apps/src/py_pjsua/py_pjsua.c#L458

if (PyList_Check(py_hdr_list)) {
int i;
for (i = 0; i < PyList_Size(py_hdr_list); i++) 
{ 
pj_str_t hname, hvalue;
pjsip_generic_string_hdr * new_hdr;
PyObject * tuple = PyList_GetItem(py_hdr_list, i);

因此,python包装器应该传递:[("Privacy","id"(,("My other header key","value"(]

为make_call方法生成hdr_list参数的示例辅助函数:

def fill_hdrs(number, domain):
l = list()
l.append(('P-Asserted-Identity','<sip:%s@%s>' % (number, domain)))
l.append(('Privacy','id'))
return(l)

相关内容

  • 没有找到相关文章

最新更新