Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.33 KB | None | 0 0
  1. #include <QDomDocument>
  2. #include <QDomElement>
  3. #include <QDomNode>
  4. #include <QXmlInputSource>
  5.  
  6. #include "chameleonxmlparse.h"
  7.  
  8.  
  9. using namespace std;
  10.  
  11. ChameleonXMLParse::ChameleonXMLParse(QObject *parent) :
  12.     QObject(parent)
  13. {
  14. }
  15.  
  16. UserParams ChameleonXMLParse::parseXML(QString fileName, UserParams *userParams){
  17.  
  18.     QString errorStr;
  19.     int errorLine;
  20.     int errorColumn;
  21.     QTextStream out(stdout);
  22.  
  23.     QXmlInputSource inputSource(file);
  24.  
  25.  
  26.     QDomDocument doc;
  27.     if (!doc.setContent(&inputSource, false, &errorStr, &errorLine, &errorColumn)) {
  28.         out<< "Error: Parse error at line "<< endl;
  29.     }
  30.  
  31.     QDomElement root = doc.documentElement();
  32.     if (root.tagName() != "CHAMELEON") {
  33.         out<< "Error: Not a user config file" << endl;
  34.     }
  35.  
  36.     QDomNode child = root.firstChild();
  37.     QList <QString> codecs;
  38.  
  39.     while (!child.isNull()) {
  40.         if (child.toElement().tagName() == "DOMAIN"){
  41.             QString domain=child.toElement().text();
  42.             userParams.setDomain(domain);
  43.         }
  44.  
  45.         else if (child.toElement().tagName() == "USERNAME"){
  46.             QString username=child.toElement().text();
  47.             userParams.setUsername(username);
  48.         }
  49.  
  50.         else if (child.toElement().tagName() == "PASSWORD"){
  51.             QString password=child.toElement().text();
  52.             userParams.setPassword(password);
  53.         }
  54.  
  55.         else if (child.toElement().tagName() == "STUN_ADDRESS"){
  56.             QString stunProtocol=child.toElement().text();
  57.             userParams.setStunProtocolAddress(stunProtocol);
  58.         }
  59.  
  60.         else if (child.toElement().tagName() == "OUTBOUND_PROXY"){
  61.             QString outboundProxy=child.toElement().text();
  62.             userParams.setOutboundProxy(outboundProxy);
  63.         }
  64.  
  65.         else if (child.toElement().tagName() == "TRANSPORT_PROTOCOL"){
  66.             QString transportProtocol=child.toElement().text();
  67.             userParams.setTransportProtocol(transportProtocol);
  68.         }
  69.  
  70.         else if (child.toElement().tagName() == "CA_FILE"){
  71.             QString caFile=child.toElement().text();
  72.             userParams.setCAFile(caFile);
  73.         }
  74.  
  75.         else if (child.toElement().tagName() == "PRIV_KEY_FILE"){
  76.             QString privKeyFile=child.toElement().text();
  77.             userParams.setPrivKeyFile(privKeyFile);
  78.         }
  79.  
  80.         else if (child.toElement().tagName() == "CERT_KEY_FILE"){
  81.             QString certFile=child.toElement().text();
  82.             userParams.setCERTFile(certFile);
  83.         }
  84.  
  85.         else if (child.toElement().tagName() == "LOG_FILE"){
  86.             QString logFile=child.toElement().text();
  87.             userParams.setLogFile(logFile);
  88.         }
  89.  
  90.         else if (child.toElement().tagName() == "SIPPORT"){
  91.             int sipPort=child.toElement().text().toInt();
  92.             userParams.setSIPPort(sipPort);
  93.         }
  94.  
  95.         else if (child.toElement().tagName() == "RTPPORT"){
  96.             int rtpPort=child.toElement().text().toInt();
  97.             userParams.setRTPPort(rtpPort);
  98.         }
  99.  
  100.         else if (child.toElement().tagName() == "SRTP_OPTIONS"){
  101.             QString srtp_option=child.toElement().text();
  102.             userParams.setSrtpOption(srtp_option);
  103.         }
  104.  
  105.         else if (child.toElement().tagName() == "SRTP_PROTOCOL"){
  106.             QString srtpReq_protocol=child.toElement().text();
  107.             userParams.setSrtpReqProtocol(srtpReq_protocol);
  108.         }
  109.  
  110.         else if (child.toElement().tagName() == "CODEC1"){
  111.             QString codec =child.toElement().text();
  112.             int i = codecs.count();
  113.             codecs.insert(i,codec);
  114.         }
  115.  
  116.         else if (child.toElement().tagName() == "CODEC2"){
  117.             QString codec =child.toElement().text();
  118.             int i = codecs.count();
  119.             codecs.insert(i,codec);
  120.         }
  121.  
  122.         else if (child.toElement().tagName() == "CODEC3"){
  123.             QString codec =child.toElement().text();
  124.             int i = codecs.count();
  125.             codecs.insert(i,codec);
  126.         }
  127.  
  128.         else if (child.toElement().tagName() == "CODEC4"){
  129.             QString codec =child.toElement().text();
  130.             int i = codecs.count();
  131.             codecs.insert(i,codec);
  132.         }
  133.  
  134.         child = child.nextSibling();
  135.  
  136.     }
  137.  
  138.     userParams.setAudioProtocols(codecs);
  139.  
  140.     return userParams;
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement