一、安装OpenXCAP
前提环境:
· libxml2: 2.6.32.dfsg-2
· python: 2.5.2
· python-application: 1.1.5
· python-gnutls: 1.1.8
· python-lxml: 2.0.7-1
· python-sqlobject: 0.10.1
· python-twisted-core: 8.1.0
· python-twisted-web: 8.1.0
· python-twisted-web2: 8.1.0
· python-zopeinterface: 3.3.1-6
Debian or Ubuntu Linux
Debian packages are available for Debian (unstable distribution) systems. To install the packages add the following lines to /etc/apt/sources.list:
deb http://ag-projects.com/debian unstable main
deb-src http://ag-projects.com/debian unstable main
安装AG Projects debian repository signing key:
wget http://download.ag-projects.com/agp-debian-gpg.key
apt-key add agp-debian-gpg.key
安装 the software on the designated XCAP server machine:
apt-get update
apt-get install openxcap soap-simple-proxy
安装 the software on the designated SIP Proxy machine:
apt-get update
apt-get install opensips-mi-proxy
安装 the xcap client library:
apt-get update
apt-get install python-xcaplib
配置文件:
(1)配置openxcap服务器:
cp /etc/openxcap/config.ini.sample /etc/openxcap/config.ini
主要配置xcap-root以及数据库,数据库地址得填正确,否则会报500.
一些片段如下:
; This is a comma/space separated list of XCAP root URIs. The first is the
; primary XCAP root URI, while the others (if specified) are aliases.
; The primary root URI is used when generating xcap-diff
; root = https://192.168.190.129/xcap-root
root = http://192.168.190.129/xcap-root
; The default authentication realm
default_realm = 192.168.190.129
[Database]
; The database connection URI for the datase with subscriber accounts
authentication_db_uri = mysql://root:passw0rd@localhost/opensips
; The database connection URI for the database that stores the XCAP documents
storage_db_uri = mysql://root:passw0rd@localhost/opensips
; Authentication and storage tables
subscriber_table = subscriber
xcap_table = xcap
[OpenSIPS]
; The address and port of the xml-rpc management interface
xmlrpc_url = http://192.168.190.129:8080
需要建立/root/.xcapclient.ini 用于使用xcapclient指令客户端的测试;
注意.xcapclient.ini 中的用户,是需要认证的,所以务必与数据库一致。注意localhost的使用,与数据库要一致。尽量统一使用“localhost”,移植也方便。
如果测试不成功,根据返回状态编号,可以分析出错的原因:401未认证;500服务器错误。
Xcap服务认证注意要完全对应,包括localhost。
另外一个客户端的配置脚本:/root/.sipclient/config.ini
(2)配置opensips-mi-proxy服务器:
copy /etc/opensips-mi-proxy/config.ini.sample to /etc/opensips-mi-proxy/config.ini
默认情况下,无需做更改;
(3)配置soap-服务器
copy /etc/soap-simple-proxy/config.ini.sample to /etc/soap-simple-proxy/config.ini
[SOAP Server]
; IP address and port to listen for requests
; 0.0.0.0 means any address of this host
address = 0.0.0.0
port = 9300
; enable logging of requests to syslog
log_requests = Yes
[WSDL]
; set the HTTP URLs where the WSDL file is served
; There are two locations:
; - a public URL which can be accessed from the Internet (should be under https)
; - an internal URL which can be accessed from the local network, for higher speed
public_service_url = https://192.168.190.129/soap-simple-proxy/
internal_service_url = http://192.168.190.129:9200/
[XCAP]
; the root URI of the XCAP server. Use https to enable TLS connections
root_uri = http://192.168.190.129/xcap-root
If nessary you need to copy openxcap, soap-simple-proxy and opensips-mi-proxy startup scripts from their debian directory present in each tar file to /etc/init.d/ and edit them to match your system.
启动 OpenXCAP:
/etc/init.d/openxcap start
启动 opensips-mi-proxy:
/etc/init.d/opensips-mi-proxy start
启动 soap-simple-proxy:
/etc/init.d/soap-simple-proxy start
辅助安装:
PHP,apache,phpmyadmin
debian:/etc/openxcap# apt-get -d install phpmyadmin
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
将会安装下列额外的软件包:
apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common dbconfig-common javascript-common libapache2-mod-php5 libapr1
libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libgd2-xpm libjs-mootools libltdl7 libmcrypt4 libsqlite3-0 libt1-5 libuuid1
php5-common php5-gd php5-mcrypt php5-mysql php5-suhosin wwwconfig-common
建议安装的软件包:
apache2-doc apache2-suexec apache2-suexec-custom apache2 httpd php-pear libgd-tools libmcrypt-dev mcrypt postgresql-client
apache apache-ssl
推荐安装的软件包:
uuid-runtime
下列【新】软件包将被安装:
apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common dbconfig-common javascript-common libapache2-mod-php5 libapr1
libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libgd2-xpm libjs-mootools libltdl7 libmcrypt4 libt1-5 php5-common php5-gd
php5-mcrypt php5-mysql php5-suhosin phpmyadmin wwwconfig-common
下列的软件包将被升级:
libsqlite3-0 libuuid1
共升级了 2 个软件包,新安装了 23 个软件包,要卸载 0 个软件包,有 567 个软件未被升级。
需要下载 10.5MB 的软件包。
解压缩后会消耗掉 32.0MB 的额外空间。
通过指令行客户端进行测试:
需要建立一个/root/.xcapclient.ini文件,内容格式如下,在测试时需要对其进行认证,相当于身份证明:
[Account]
sip_address=1001@localhost
password=1001
xcap_root = http://192.168.190.129/xcap-root
测试过程:
在xcap-client源码包内有example xml文件,可以对其进行操作。
PUT操作:
xcapclient -i pres-rules.xml put
GET操作:
xcapclient --app resource-lists get
or
xcapclient --app pres-rules get
or
xcapclient --app rls-services get
This will print the document you've just put, along with its tag.
or
xcapclient --app xcap-caps get
will print the capabilities of the XCAP server.
DELETE操作:
xcapclient --app resource-lists delete
and
xcapclient --app pres-rules delete
and
xcapclient --app rls-services delete
对XCAP文件中的某个元素进行操作:替换,插入,删除
To address an element, a node selector is required, which is an XPATH-like expression, defined in http://tools.ietf.org/html/rfc4825#section-6.3. (定位某一个节点)
Let's put the document in section 1 again to server, so we can fetch some elements from it.
xcapclient --app resource-lists get '/resource-lists/list[@name="friends"]/entry[1]/display-name'
To replace an element, use the node selector you would have used for retrieving the element but do PUT instead. For example if we want to fix Bill's display name:
bill_display_name_fixed.xml put '/resource-lists/list[@name="friends"]/entry[1]/display-name'
To insert a new element one must construct a node selector that doesn't point to an existing element.
xcapclient -i alice.xml put '/resource-lists/list[@name="friends"]/entry[1][@uri="sip:alice@example.com"]'
This will shift Bill's entry to the second position.
See README of python-xcaplib package for more detailed examples on how to create/retrieve XCAP documents.
通过脚本对各项进行批量测试:
安装完成后,会自己带有一个test.py的脚本,本机的路径为:
/usr/lib/pymodules/python2.5/xcap/test/test.py
如不清楚,可以用locate test.py 进行查找。
直接运行即可,如有问题,会有相关的报错。
下面是在本机测试成功后的显示:
debian:~/.sipclient# /usr/lib/pymodules/python2.5/xcap/test/test.py
test400_1 (test_errors.ErrorsTest) ... ok
test400_2 (test_errors.ErrorsTest) ... ok
test404 (test_errors.ErrorsTest) ... ok
test405 (test_errors.ErrorsTest) ... ok
test409 (test_errors.ErrorsTest) ... ok
test_gibberish (test_errors.ErrorsTest) ... ok
test_schema (test_xcap_caps.XCAPCaps) ... ok
test_pidf_manipulation (test_pidf.PIDFTest) ... ok
test_has_global (test_global.TestGlobal) ... ok
test_no_global (test_global.TestGlobal) ... ok
test_global_auth (test_auth.AuthTest_org_openmobilealliance_pres_rules) ... ok
test_users_auth (test_auth.AuthTest_org_openmobilealliance_pres_rules) ... ok
test_global_auth (test_auth.AuthTest_pidf_manipulation) ... ok
test_users_auth (test_auth.AuthTest_pidf_manipulation) ... ok
test_global_auth (test_auth.AuthTest_pres_rules) ... ok
test_users_auth (test_auth.AuthTest_pres_rules) ... ok
test_global_auth (test_auth.AuthTest_resource_lists) ... ok
test_users_auth (test_auth.AuthTest_resource_lists) ... ok
test_global_auth (test_auth.AuthTest_rls_services) ... ok
test_users_auth (test_auth.AuthTest_rls_services) ... ok
test_global_auth (test_auth.AuthTest_test_app) ... ok
test_users_auth (test_auth.AuthTest_test_app) ... ok
test_global_auth (test_auth.AuthTest_watchers) ... ok
test_users_auth (test_auth.AuthTest_watchers) ... ok
test_global_auth (test_auth.AuthTest_xcap_caps) ... ok
test_users_auth (test_auth.AuthTest_xcap_caps) ... ok
Testing different ways of inserting an element as described in examples from Section 8.2.3 ... ok
Testing PUT requests of form '*[@att="some"]' which require looking into body of PUT ... ok
test_replacement (test_element_put.PutElementTest) ... ok
test_ns_bindings (test_nsbindings.NSBindingsTest) ... ok
test_delete (test_attribute.AttributeTest) ... ok
test_get (test_attribute.AttributeTest) ... WARNING: test with URI in att_value is disabled
ok
test_put (test_attribute.AttributeTest) ... ok
test_conditional_GET (test_etags.ETagTest) ... ok
test_conditional_PUT (test_etags.ETagTest) ... ok
test_conditional_GET (test_etags.ETagTest2) ... ok
test_conditional_PUT (test_etags.ETagTest2) ... ok
test_etag_parsing (test_etags.ETagTest2) ... ok
test_get (test_watchers.Test) ... ok
test_pidf_manipulation (test_presrules.PresenceRulesTest) ... ok
test_errors (test_fragment.FragmentTest) ... ok
test_success (test_fragment.FragmentTest) ... ok
test_operations (test_resourcelists.DocumentTest) ... ok
test_operations (test_rlsservices.DocumentTest) ... ok
test_delete (test_element.ElementTest) ... ok
test_get (test_element.ElementTest) ... WARNING: test with URI in att_value is disabled
ok
test_put_error (test_element.ElementTest) ... ok
----------------------------------------------------------------------
Ran 47 tests in 6.465s
OK