source: qutecom-coip/libs/coipmanager_base/src/serializer/SipAccountXMLSerializer.cpp @ 125:d648f4cb122f

Last change on this file since 125:d648f4cb122f was 125:d648f4cb122f, checked in by laurent, 3 years ago

wengo => qutecom

File size: 5.3 KB
Line 
1/*
2 * QuteCom, a voice over Internet phone
3 * Copyright (C) 2004-2010 Mbdsys
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 */
19
20#include <coipmanager_base/serializer/SipAccountXMLSerializer.h>
21
22#include <coipmanager_base/serializer/SipPeerXMLSerializer.h>
23
24#include <coipmanager_base/account/SipAccount.h>
25
26#include <util/String.h>
27
28#include <tinyxml.h>
29
30SipAccountXMLSerializer::SipAccountXMLSerializer(SipAccount & account) 
31        : IAccountXMLSerializer(account) {
32}
33
34std::string SipAccountXMLSerializer::serialize() {
35        SipAccount & myAccount = static_cast<SipAccount &>(_account);
36
37        SipPeerXMLSerializer sipPeerXMLSerializer(myAccount);
38        std::string result = sipPeerXMLSerializer.serialize();
39       
40        result += "<register.server>" + myAccount.getRegisterServerHostname() + "</register.server>\n";
41        result += "<register.serverport>" + String::fromNumber(myAccount.getRegisterServerPort()) + "</register.serverport>\n";
42        result += "<sipproxy.server>" + myAccount.getSIPProxyServerHostname() + "</sipproxy.server>\n";
43        result += "<sipproxy.serverport>" + String::fromNumber(myAccount.getSIPProxyServerPort()) + "</sipproxy.serverport>\n";
44        result += "<httptunnel.needed>" + String::fromBoolean(myAccount.isHttpTunnelNeeded()) + "</httptunnel.needed>\n";
45        result += "<httptunnel.server>" + myAccount.getHttpTunnelServerHostname() + "</httptunnel.server>\n";
46        result += "<httptunnel.sslserver>" + myAccount.getHttpsTunnelServerHostname() + "</httptunnel.sslserver>\n";
47        result += "<httptunnel.serverport>" + String::fromNumber(myAccount.getHttpTunnelServerPort()) + "</httptunnel.serverport>\n";
48        result += "<httptunnel.useSSL>" + String::fromBoolean(myAccount.useSSLForHttpTunnel()) + "</httptunnel.useSSL>\n";
49        result += "<nattype>" + EnumNatType::toString(myAccount.getNatType()) + "</nattype>\n";
50
51        return result;
52}
53
54bool SipAccountXMLSerializer::unserialize(TiXmlHandle & rootElt) {
55        SipAccount & myAccount = static_cast<SipAccount &>(_account);
56
57        SipPeerXMLSerializer sipPeerXMLSerializer(myAccount);
58        sipPeerXMLSerializer.unserializeContent(rootElt);
59
60        // Retrieving register server
61        TiXmlNode * registerServer = rootElt.FirstChild("register.server").FirstChild().Node();
62        if (registerServer) {
63                myAccount.setRegisterServerHostname(registerServer->Value());
64        }
65        ////
66
67        // Retrieving register server port
68        TiXmlNode * registerServerPort = rootElt.FirstChild("register.serverport").FirstChild().Node();
69        if (registerServerPort) {
70                String sRegisterServerPort = registerServerPort->Value();
71                myAccount.setRegisterServerPort(sRegisterServerPort.toInteger());
72        }
73        ////
74
75        // Retrieving sip proxy server
76        TiXmlNode * sipProxyServer = rootElt.FirstChild("sipproxy.server").FirstChild().Node();
77        if (sipProxyServer) {
78                myAccount.setSIPProxyServerHostname(sipProxyServer->Value());
79        }
80        ////
81
82        // Retrieving sip proxy server port
83        TiXmlNode * sipProxyServerPort = rootElt.FirstChild("sipproxy.serverport").FirstChild().Node();
84        if (sipProxyServerPort) {
85                String sSipProxyServerPort = sipProxyServerPort->Value();
86                myAccount.setSIPProxyServerPort(sSipProxyServerPort.toInteger());
87        }
88        ////
89
90        // Retrieving http tunnel server
91        TiXmlNode * httpTunnelServer = rootElt.FirstChild("httptunnel.server").FirstChild().Node();
92        if (httpTunnelServer) {
93                myAccount.setHttpTunnelServerHostname(httpTunnelServer->Value());
94        }
95        ////
96
97        // Retrieving http tunnel server
98        TiXmlNode * httpsTunnelServer = rootElt.FirstChild("httptunnel.sslserver").FirstChild().Node();
99        if (httpsTunnelServer) {
100                myAccount.setHttpsTunnelServerHostname(httpsTunnelServer->Value());
101        }
102        ////
103
104        // Retrieving http tunnel server port
105        TiXmlNode * httpTunnelServerPort = rootElt.FirstChild("httptunnel.serverport").FirstChild().Node();
106        if (httpTunnelServerPort) {
107                String sHttpTunnelServerPort = httpTunnelServerPort->Value();
108                myAccount.setHttpTunnelServerPort(sHttpTunnelServerPort.toInteger());
109        }
110        ////
111
112        // Retrieving http tunnel needed
113        TiXmlNode * httpTunnelNeeded = rootElt.FirstChild("httptunnel.needed").FirstChild().Node();
114        if (httpTunnelNeeded) {
115                String sHttpTunnelNeeded = httpTunnelNeeded->Value();
116                myAccount.setHttpTunnelNeeded(sHttpTunnelNeeded.toBoolean());
117        }
118        ////
119
120        // Retrieving http tunnel has SSL
121        TiXmlNode * httpTunnelUseSSL = rootElt.FirstChild("httptunnel.useSSL").FirstChild().Node();
122        if (httpTunnelUseSSL) {
123                String sHttpTunnelUseSSL = httpTunnelUseSSL->Value();
124                myAccount.setUseSSLForHttpTunnel(sHttpTunnelUseSSL.toBoolean());
125        }
126        ////
127
128        // Retrieving Nat type
129        TiXmlNode * natType = rootElt.FirstChild("nattype").FirstChild().Node();
130        if (natType) {
131                myAccount.setNatType(EnumNatType::toNatType(natType->Value()));
132        }
133        ////
134
135        return true;
136}
Note: See TracBrowser for help on using the repository browser.