prefsofia.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. #include <QtGui>
  2. #include <fshost.h>
  3. #include "prefsofia.h"
  4. PrefSofia::PrefSofia(Ui::PrefDialog *ui, QObject *parent) :
  5. QObject(parent),
  6. _ui(ui)
  7. {
  8. }
  9. void PrefSofia::readConfig()
  10. {
  11. ISettings *settings = new ISettings();
  12. QDomElement cfg = settings->getConfigNode("sofia.conf");
  13. if ( cfg.isNull() ) {
  14. qDebug() << "Issue a big warning!";
  15. return;
  16. }
  17. int guess_mask;
  18. char guess_ip[80];
  19. switch_find_local_ip(guess_ip, sizeof(guess_ip), &guess_mask, AF_INET);
  20. _ui->sofiaRtpIpEdit->setText(QString(guess_ip));
  21. _ui->sofiaSipIpEdit->setText(QString(guess_ip));
  22. /* General Settings */
  23. QDomNodeList l = cfg.elementsByTagName("global_settings");
  24. QDomNodeList global_params = l.at(0).toElement().elementsByTagName("param");
  25. for (int i = 0; i < global_params.count(); i++) {
  26. QDomElement el = global_params.at(i).toElement();
  27. if ( el.attribute("name") == "log-level" ) {
  28. _ui->sofiaLogLevelSpin->setValue(el.attribute("value").toInt());
  29. }
  30. if ( el.attribute("name") == "auto-restart") {
  31. _ui->sofiaAutoRestartCombo->setCurrentIndex(_ui->sofiaAutoRestartCombo->findText(el.attribute("value")));
  32. }
  33. if ( el.attribute("name") == "debug-presence") {
  34. _ui->sofiaDebugPresenceSpin->setValue(el.attribute("value").toInt());
  35. }
  36. }
  37. /* Profile settings */
  38. /* Get only the first settings, meaning one profile supported so far */
  39. QDomNodeList params = cfg.elementsByTagName("settings").at(0).toElement().elementsByTagName("param");
  40. for (int i = 0; i < params.count(); i++) {
  41. QDomElement el = params.at(i).toElement();
  42. if ( el.attribute("name") == "user-agent-string") {
  43. _ui->sofiaUserAgentStringEdit->setText(el.attribute("value"));
  44. }
  45. if ( el.attribute("name") == "debug") {
  46. _ui->sofiaDebugSpin->setValue(el.attribute("value").toInt());
  47. }
  48. if ( el.attribute("name") == "sip-trace") {
  49. _ui->sofiaSipTraceCombo->setCurrentIndex(_ui->sofiaSipTraceCombo->findText(el.attribute("value")));
  50. }
  51. if ( el.attribute("name") == "context") {
  52. _ui->sofiaContextEdit->setText(el.attribute("value"));
  53. }
  54. if ( el.attribute("name") == "rfc2833-pt") {
  55. _ui->sofiaRfc2833PtEdit->setText(el.attribute("value"));
  56. }
  57. if ( el.attribute("name") == "sip-port") {
  58. _ui->sofiaSipPortSpin->setValue(el.attribute("value").toInt());
  59. }
  60. if ( el.attribute("name") == "dialplan") {
  61. _ui->sofiaDialplanEdit->setText(el.attribute("value"));
  62. }
  63. if ( el.attribute("name") == "dtmf-duration") {
  64. _ui->sofiaDtmfDurationSpin->setValue(el.attribute("value").toInt());
  65. }
  66. if ( el.attribute("name") == "codec-prefs") {
  67. _ui->sofiaProfileCodecWidget->setCodecString(el.attribute("value"));
  68. }
  69. if ( el.attribute("name") == "use-rtp-timer") {
  70. _ui->sofiaUseRtpTimerCombo->setCurrentIndex(_ui->sofiaUseRtpTimerCombo->findText(el.attribute("value")));
  71. }
  72. if ( el.attribute("name") == "rtp-timer-name") {
  73. _ui->sofiaRtpTimerNameEdit->setText(el.attribute("value"));
  74. }
  75. if ( el.attribute("name") == "rtp-ip") {
  76. _ui->sofiaRtpIpEdit->setText(el.attribute("value"));
  77. }
  78. if ( el.attribute("name") == "sip-ip") {
  79. _ui->sofiaSipIpEdit->setText(el.attribute("value"));
  80. }
  81. if ( el.attribute("name") == "hold-music") {
  82. _ui->sofiaHoldMusicEdit->setText(el.attribute("value"));
  83. }
  84. if ( el.attribute("name") == "apply-nat-acl") {
  85. _ui->sofiaApplyNatAclEdit->setText(el.attribute("value"));
  86. }
  87. if ( el.attribute("name") == "manage-presence") {
  88. _ui->sofiaManagePresenceCombo->setCurrentIndex(_ui->sofiaManagePresenceCombo->findText(el.attribute("value")));
  89. }
  90. if ( el.attribute("name") == "max-proceeding") {
  91. _ui->sofiaMaxProceedingEdit->setValue(el.attribute("value").toInt());
  92. }
  93. if ( el.attribute("name") == "inbound-codec-negotiation") {
  94. _ui->sofiaInboundCodecNegotiationCombo->setCurrentIndex(_ui->sofiaInboundCodecNegotiationCombo->findText(el.attribute("value")));
  95. }
  96. if ( el.attribute("name") == "nonce-ttl") {
  97. _ui->sofiaNonceTtlSpin->setValue(el.attribute("value").toInt());
  98. }
  99. if ( el.attribute("name") == "auth-calls") {
  100. _ui->sofiaAuthCallsCombo->setCurrentIndex(_ui->sofiaAuthCallsCombo->findText(el.attribute("value")));
  101. }
  102. if ( el.attribute("name") == "auth-all-packets") {
  103. _ui->sofiaAuthAllPacketsCombo->setCurrentIndex(_ui->sofiaAuthAllPacketsCombo->findText(el.attribute("value")));
  104. }
  105. if ( el.attribute("name") == "ext-sip-ip") {
  106. _ui->sofiaExtSipIpEdit->setText(el.attribute("value"));
  107. }
  108. if ( el.attribute("name") == "rtp-timeout-sec") {
  109. _ui->sofiaRtpTimeoutSecSpin->setValue(el.attribute("value").toInt());
  110. }
  111. if ( el.attribute("name") == "rtp-hold-timeout-sec") {
  112. _ui->sofiaRtpHoldTimeoutSecSpin->setValue(el.attribute("value").toInt());
  113. }
  114. if ( el.attribute("name") == "disable-register") {
  115. _ui->sofiaDisableRegisterCombo->setCurrentIndex(_ui->sofiaDisableRegisterCombo->findText(el.attribute("value")));
  116. }
  117. if ( el.attribute("name") == "challenge-realm") {
  118. _ui->sofiaChallengeRealmCombo->setCurrentIndex(_ui->sofiaChallengeRealmCombo->findText(el.attribute("value")));
  119. }
  120. }
  121. delete (settings);
  122. }
  123. void PrefSofia::postWriteConfig() {
  124. /* Here, we have to know if we need to restart the profile or not */
  125. return;
  126. }
  127. void PrefSofia::writeConfig()
  128. {
  129. ISettings *settings = new ISettings(this);
  130. QDomElement e = settings->getConfigNode("sofia.conf");
  131. QDomNodeList nl = e.elementsByTagName("global_settings").at(0).toElement().elementsByTagName("param");
  132. /* General Settings */
  133. for (int i = 0; i < nl.count(); i++) {
  134. QDomElement el = nl.at(i).toElement();
  135. QDomAttr val = el.attributeNode("value");
  136. QDomAttr var = el.attributeNode("name");
  137. if ( var.value() == "log-level" ) {
  138. val.setValue(QString::number(_ui->sofiaLogLevelSpin->value()));
  139. }
  140. if ( var.value() == "auto-restart" ) {
  141. val.setValue(_ui->sofiaAutoRestartCombo->currentText());
  142. }
  143. if ( var.value() == "debug-presence" ) {
  144. val.setValue(QString::number(_ui->sofiaDebugPresenceSpin->value()));
  145. }
  146. if ( var.value() == "rewrite-multicasted-fs-path" ) {
  147. val.setValue(_ui->sofiaRewriteMulticastedFsPathCombo->currentText());
  148. }
  149. }
  150. /* Profile settings */
  151. /* Get only the first settings, meaning one profile supported so far */
  152. QDomNodeList params = e.elementsByTagName("settings").at(0).toElement().elementsByTagName("param");
  153. for (int i = 0; i < params.count(); i++) {
  154. QDomElement el = params.at(i).toElement();
  155. QDomAttr val = el.attributeNode("value");
  156. if ( el.attribute("name") == "user-agent-string") {
  157. val.setValue(_ui->sofiaUserAgentStringEdit->text());
  158. }
  159. if ( el.attribute("name") == "debug") {
  160. val.setValue(QString::number(_ui->sofiaDebugSpin->value()));
  161. }
  162. if ( el.attribute("name") == "sip-trace") {
  163. val.setValue(_ui->sofiaSipTraceCombo->currentText());
  164. }
  165. if ( el.attribute("name") == "context") {
  166. val.setValue(_ui->sofiaContextEdit->text());
  167. }
  168. if ( el.attribute("name") == "rfc2833-pt") {
  169. val.setValue(_ui->sofiaRfc2833PtEdit->text());
  170. }
  171. if ( el.attribute("name") == "sip-port") {
  172. val.setValue(QString::number(_ui->sofiaSipPortSpin->value()));
  173. }
  174. if ( el.attribute("name") == "dialplan") {
  175. val.setValue(_ui->sofiaDialplanEdit->text());
  176. }
  177. if ( el.attribute("name") == "dtmf-duration") {
  178. val.setValue(QString::number(_ui->sofiaDtmfDurationSpin->value()));
  179. }
  180. if ( el.attribute("name") == "codec-prefs") {
  181. val.setValue(_ui->sofiaProfileCodecWidget->getCodecString());
  182. }
  183. if ( el.attribute("name") == "use-rtp-timer") {
  184. val.setValue(_ui->sofiaUseRtpTimerCombo->currentText());
  185. }
  186. if ( el.attribute("name") == "rtp-timer-name") {
  187. val.setValue(_ui->sofiaRtpTimerNameEdit->text());
  188. }
  189. if ( el.attribute("name") == "rtp-ip") {
  190. val.setValue(_ui->sofiaRtpIpEdit->text());
  191. }
  192. if ( el.attribute("name") == "sip-ip") {
  193. val.setValue(_ui->sofiaSipIpEdit->text());
  194. }
  195. if ( el.attribute("name") == "hold-music") {
  196. val.setValue(_ui->sofiaHoldMusicEdit->text());
  197. }
  198. if ( el.attribute("name") == "apply-nat-acl") {
  199. val.setValue(_ui->sofiaApplyNatAclEdit->text());
  200. }
  201. if ( el.attribute("name") == "manage-presence") {
  202. val.setValue(_ui->sofiaManagePresenceCombo->currentText());
  203. }
  204. if ( el.attribute("name") == "max-proceeding") {
  205. val.setValue(_ui->sofiaMaxProceedingEdit->text());
  206. }
  207. if ( el.attribute("name") == "inbound-codec-negotiation") {
  208. val.setValue(_ui->sofiaInboundCodecNegotiationCombo->currentText());
  209. }
  210. if ( el.attribute("name") == "nonce-ttl") {
  211. val.setValue(QString::number(_ui->sofiaNonceTtlSpin->value()));
  212. }
  213. if ( el.attribute("name") == "auth-calls") {
  214. val.setValue(_ui->sofiaAuthCallsCombo->currentText());
  215. }
  216. if ( el.attribute("name") == "auth-all-packets") {
  217. val.setValue(_ui->sofiaAuthAllPacketsCombo->currentText());
  218. }
  219. if ( el.attribute("name") == "ext-rtp-ip") {
  220. val.setValue(_ui->sofiaExtRtpIpEdit->text());
  221. }
  222. if ( el.attribute("name") == "ext-sip-ip") {
  223. val.setValue(_ui->sofiaExtSipIpEdit->text());
  224. }
  225. if ( el.attribute("name") == "rtp-timeout-sec") {
  226. val.setValue(QString::number(_ui->sofiaRtpTimeoutSecSpin->value()));
  227. }
  228. if ( el.attribute("name") == "rtp-hold-timeout-sec") {
  229. val.setValue(QString::number(_ui->sofiaRtpHoldTimeoutSecSpin->value()));
  230. }
  231. if ( el.attribute("name") == "disable-register") {
  232. val.setValue(_ui->sofiaDisableRegisterCombo->currentText());
  233. }
  234. if ( el.attribute("name") == "challenge-realm") {
  235. val.setValue(_ui->sofiaChallengeRealmCombo->currentText());
  236. }
  237. }
  238. settings->setConfigNode(e, "sofia.conf");
  239. delete(settings);
  240. }