Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <QDomDocument>
- #include <QDomElement>
- #include <QDomNode>
- #include <QXmlInputSource>
- #include "chameleonxmlparse.h"
- using namespace std;
- ChameleonXMLParse::ChameleonXMLParse(QObject *parent) :
- QObject(parent)
- {
- }
- UserParams ChameleonXMLParse::parseXML(QString fileName, UserParams *userParams){
- QString errorStr;
- int errorLine;
- int errorColumn;
- QTextStream out(stdout);
- QXmlInputSource inputSource(file);
- QDomDocument doc;
- if (!doc.setContent(&inputSource, false, &errorStr, &errorLine, &errorColumn)) {
- out<< "Error: Parse error at line "<< endl;
- }
- QDomElement root = doc.documentElement();
- if (root.tagName() != "CHAMELEON") {
- out<< "Error: Not a user config file" << endl;
- }
- QDomNode child = root.firstChild();
- QList <QString> codecs;
- while (!child.isNull()) {
- if (child.toElement().tagName() == "DOMAIN"){
- QString domain=child.toElement().text();
- userParams.setDomain(domain);
- }
- else if (child.toElement().tagName() == "USERNAME"){
- QString username=child.toElement().text();
- userParams.setUsername(username);
- }
- else if (child.toElement().tagName() == "PASSWORD"){
- QString password=child.toElement().text();
- userParams.setPassword(password);
- }
- else if (child.toElement().tagName() == "STUN_ADDRESS"){
- QString stunProtocol=child.toElement().text();
- userParams.setStunProtocolAddress(stunProtocol);
- }
- else if (child.toElement().tagName() == "OUTBOUND_PROXY"){
- QString outboundProxy=child.toElement().text();
- userParams.setOutboundProxy(outboundProxy);
- }
- else if (child.toElement().tagName() == "TRANSPORT_PROTOCOL"){
- QString transportProtocol=child.toElement().text();
- userParams.setTransportProtocol(transportProtocol);
- }
- else if (child.toElement().tagName() == "CA_FILE"){
- QString caFile=child.toElement().text();
- userParams.setCAFile(caFile);
- }
- else if (child.toElement().tagName() == "PRIV_KEY_FILE"){
- QString privKeyFile=child.toElement().text();
- userParams.setPrivKeyFile(privKeyFile);
- }
- else if (child.toElement().tagName() == "CERT_KEY_FILE"){
- QString certFile=child.toElement().text();
- userParams.setCERTFile(certFile);
- }
- else if (child.toElement().tagName() == "LOG_FILE"){
- QString logFile=child.toElement().text();
- userParams.setLogFile(logFile);
- }
- else if (child.toElement().tagName() == "SIPPORT"){
- int sipPort=child.toElement().text().toInt();
- userParams.setSIPPort(sipPort);
- }
- else if (child.toElement().tagName() == "RTPPORT"){
- int rtpPort=child.toElement().text().toInt();
- userParams.setRTPPort(rtpPort);
- }
- else if (child.toElement().tagName() == "SRTP_OPTIONS"){
- QString srtp_option=child.toElement().text();
- userParams.setSrtpOption(srtp_option);
- }
- else if (child.toElement().tagName() == "SRTP_PROTOCOL"){
- QString srtpReq_protocol=child.toElement().text();
- userParams.setSrtpReqProtocol(srtpReq_protocol);
- }
- else if (child.toElement().tagName() == "CODEC1"){
- QString codec =child.toElement().text();
- int i = codecs.count();
- codecs.insert(i,codec);
- }
- else if (child.toElement().tagName() == "CODEC2"){
- QString codec =child.toElement().text();
- int i = codecs.count();
- codecs.insert(i,codec);
- }
- else if (child.toElement().tagName() == "CODEC3"){
- QString codec =child.toElement().text();
- int i = codecs.count();
- codecs.insert(i,codec);
- }
- else if (child.toElement().tagName() == "CODEC4"){
- QString codec =child.toElement().text();
- int i = codecs.count();
- codecs.insert(i,codec);
- }
- child = child.nextSibling();
- }
- userParams.setAudioProtocols(codecs);
- return userParams;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement