{"text":"#include \"UASQuickTabView.h\"\n#include \"ui_UASQuickTabView.h\"\n#include \n#include \n#include \n#include \n\n\nUASQuickTabView::UASQuickTabView(QWidget *parent) :\n ui(new Ui::UASQuickTabView)\n{\n ui->setupUi(this);\n\/\/ this->setLayout(ui->gridLayout);\n\/\/ ui->gridLayout->setContentsMargins(0,0,0,0);\n\/\/ ui->gridLayout->setHorizontalSpacing(0);\n\/\/ ui->gridLayout->setVerticalSpacing(0);\n\/\/ ui->gridLayout->setSpacing(0);\n\/\/ ui->gridLayout->setMargin(0);\n\n\n\n\n\n\n\tQStringList nameList;\/\/ = new QStringList();\n\/\/\tnameList.append(\"Широта:\");\n\/\/\tnameList.append(\"Долгота:\");\n\/\/\tnameList.append(\"Высота:\");\n\/\/\tnameList.append(\"Курс:\");\n\/\/\tnameList.append(\"Крен:\");\n\/\/\tnameList.append(\"Тангаж:\");\n\n nameList.append(tr(\"Latitude:\"));\n nameList.append(tr(\"Longitude:\"));\n nameList.append(tr(\"Altitude:\"));\n nameList.append(tr(\"Roll:\"));\n nameList.append(tr(\"Pitch:\"));\n nameList.append(tr(\"Yaw:\"));\n\n fieldNameList << \"M24:GLOBAL_POSITION_INT.lat\"\n << \"M24:GLOBAL_POSITION_INT.lon\"\n << \"M24:GLOBAL_POSITION_INT.alt\"\n << \"M24:ATTITUDE.roll\"\n << \"M24:ATTITUDE.pitch\"\n << \"M24:ATTITUDE.yaw\";\n\n foreach(QString str, fieldNameList){\n uasPropertyValueMap.insert(str, 0.0);\n }\n\n\tQTextCodec::setCodecForLocale(QTextCodec::codecForName(\"UTF-8\"));\n\tui->tableWidget->setColumnCount(2);\n ui->tableWidget->setRowCount(nameList.count());\n ui->tableWidget->setLineWidth(1);\n ui->tableWidget->setFrameStyle(QFrame::NoFrame);\n \/\/ui->tableWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);\n ui->tableWidget->setStyleSheet(\"gridline-color : dimgray\");\n ui->tableWidget->setWindowFlags(\/*ui->tableWidget->windowFlags()*\/Qt::Widget | Qt::FramelessWindowHint);\n\n\n\n\n \/\/tableFont = new QFont(\"Times New Roman\", 14, 3);\n\/\/ tableFont.setFamily(\"Times New Roman\");\n tableFont.setPixelSize(14);\n tableFont.setBold(3);\n\n for(int i = 0; i < nameList.count(); i++) {\n \/* Add first column that shows lable names.*\/\n QTableWidgetItem* item = new QTableWidgetItem();\n Q_ASSERT(item);\n if (item) {\n item->setText(nameList.at(i));\n tableNameList.append(item);\n item->setFont(tableFont);\n item->setFlags(item->flags() ^ Qt::ItemIsEditable ^ Qt::ItemIsSelectable);\n ui->tableWidget->setItem(i, 0, item);\n }\n\n \/* Add column with values.*\/\n item = new QTableWidgetItem();\n Q_ASSERT(item);\n if (item) {\n tableValueList.append(item);\n item->setFont(tableFont);\n item->setText(\"0.0\");\n item->setFlags(item->flags() ^ Qt::ItemIsEditable ^ Qt::ItemIsSelectable);\n ui->tableWidget->setItem(i, 1, item);\n }\n }\n\n setTableGeometry();\n\n updateTimer = new QTimer(this);\n connect(updateTimer,SIGNAL(timeout()),this,SLOT(updateTimerTick()));\n updateTimer->start(1000);\n\n\n\/\/ testTimerValue = true;\n\/\/ testTimer = new QTimer(this);\n\/\/ testTimer->setSingleShot(false);\n\/\/ connect(testTimer,SIGNAL(timeout()),this,SLOT(testTimerExpired()));\n\/\/ testTimer->start(750);\n\n}\n\nUASQuickTabView::~UASQuickTabView()\n{\n delete ui;\n foreach (QTableWidgetItem* item, tableNameList) {\n delete item;\n }\n foreach (QTableWidgetItem* item, tableValueList) {\n delete item;\n }\n delete updateTimer;\n}\n\nvoid UASQuickTabView::addSource(MAVLinkDecoder *decoder)\n{\n connect(decoder,SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)),this,SLOT(valueChanged(int,QString,QString,QVariant,quint64)));\n}\n\nvoid UASQuickTabView::valueChanged(const int uasId, const QString& name, const QString& unit, const QVariant &variant, const quint64 msec)\n{\n Q_UNUSED(uasId);\n Q_UNUSED(unit);\n Q_UNUSED(msec);\n\n bool ok;\n double value = variant.toDouble(&ok);\n QMetaType::Type metaType = static_cast(variant.type());\n if(!ok || metaType == QMetaType::QString || metaType == QMetaType::QByteArray)\n return;\n \/\/qDebug()<addItem(name);\n\/\/ }\n\/\/ }\n\n if((name == \"M24:GLOBAL_POSITION_INT.lat\")||(name == \"M24:GLOBAL_POSITION_INT.lon\"))\n uasPropertyValueMap[name] = value\/10000000;\n else if(name == \"M24:GLOBAL_POSITION_INT.alt\")\n uasPropertyValueMap[name] = value\/1000;\n else if((name == \"M24:ATTITUDE.roll\")||(name == \"M24:ATTITUDE.pitch\")||(name == \"M24:ATTITUDE.yaw\"))\n uasPropertyValueMap[name] = value\/M_PI*180;\n}\n\nvoid UASQuickTabView::updateTimerTick()\n{\n for(int i = 0; i < fieldNameList.size(); i++){\n \/\/QString str = QString::number(uasPropertyValueMap[fieldNameList.at(i)]);\n QString str = formText(fieldNameList.at(i), uasPropertyValueMap[fieldNameList.at(i)]);\n ui->tableWidget->item(i,1)->setText(str);\n }\n}\n\n\/\/void UASQuickTabView::testTimerExpired(){\n\/\/ if(testTimerValue == true){\n\/\/ valueChanged(0,\"M24:GLOBAL_POSITION_INT.lat\",\"unit\",538893530,0);\n\/\/ valueChanged(0,\"M24:GLOBAL_POSITION_INT.lon\",\"unit\",275296780,0);\n\/\/ valueChanged(0,\"M24:GLOBAL_POSITION_INT.alt\",\"unit\",272000,0);\n\/\/ valueChanged(0,\"M24:ATTITUDE.roll\",\"unit\",0.36814,0);\n\/\/ valueChanged(0,\"M24:ATTITUDE.pitch\",\"unit\",0.56715,0);\n\/\/ valueChanged(0,\"M24:ATTITUDE.yaw\",\"unit\",0.24715,0);\n\/\/ testTimerValue = false;\n\/\/ }\n\/\/ else{\n\/\/ valueChanged(0,\"M24:GLOBAL_POSITION_INT.lat\",\"unit\",-549993530,0);\n\/\/ valueChanged(0,\"M24:GLOBAL_POSITION_INT.lon\",\"unit\",-277796780,0);\n\/\/ valueChanged(0,\"M24:GLOBAL_POSITION_INT.alt\",\"unit\",284000,0);\n\/\/ valueChanged(0,\"M24:ATTITUDE.roll\",\"unit\",0.35614,0);\n\/\/ valueChanged(0,\"M24:ATTITUDE.pitch\",\"unit\",0.46815,0);\n\/\/ valueChanged(0,\"M24:ATTITUDE.yaw\",\"unit\",0.67895,0);\n\/\/ testTimerValue = true;\n\/\/ }\n\/\/}\n\nvoid UASQuickTabView::setTableGeometry(){\n\n int rowCount = ui->tableWidget->rowCount();\n\n \/\/ui->tableWidget->setWi\n\n \/\/ui->tableWidget->verticalHeader()->sectionResized();\n\n ui->tableWidget->resize(this->width(), this->height());\n\n\/\/ ui->tableWidget->setColumnWidth(0, (int)((double)(ui->tableWidget->width())\/2.0));\n\/\/ ui->tableWidget->setColumnWidth(1, (int)((double)(ui->tableWidget->width())\/2.0));\n\n\n ui->tableWidget->setColumnWidth(0, ((ui->tableWidget->width())\/2));\n ui->tableWidget->setColumnWidth(1, ((ui->tableWidget->width())\/2 + (ui->tableWidget->width())%2));\n\n for(int i = 0; i < ui->tableWidget->rowCount() - 1; i++) {\n\n ui->tableWidget->setRowHeight(i, (ui->tableWidget->height())\/rowCount);\n \/\/ui->tableWidget->setRowHeight(i, (ui->tableWidget->height())\/6);\n }\n ui->tableWidget->setRowHeight(ui->tableWidget->rowCount() - 1, ((ui->tableWidget->height())\/rowCount) + ((ui->tableWidget->height())%rowCount));\n\n}\n\nQString UASQuickTabView::formText(QString name, double value){\n\n QString str;\n\n if(name == \"M24:GLOBAL_POSITION_INT.lat\"){\n if(value >= 0){\n str = QString::number(value,'f',5);\n str += 0x00B0;\n str += tr(\" N\");\n }\n else if(value < 0){\n value *=-1;\n str = QString::number(value,'f',5);\n str += 0x00B0;\n str += tr(\" S\");\n }\n }\n\n else if(name == \"M24:GLOBAL_POSITION_INT.lon\"){\n if(value >= 0){\n str = QString::number(value,'f',5);\n str += 0x00B0;\n str += tr(\" E\");\n }\n else if(value < 0){\n value *=-1;\n str = QString::number(value,'f',5);\n str += 0x00B0;\n str += tr(\" W\");\n }\n }\n\n else if(name == \"M24:GLOBAL_POSITION_INT.alt\"){\n str = QString::number(value,'f',1);\n str +=tr(\" m.\");\n }\n else if((name == \"M24:ATTITUDE.roll\")||(name == \"M24:ATTITUDE.pitch\")||(name == \"M24:ATTITUDE.yaw\")){\n str = QString::number(value,'f',2);\n str += 0x00B0;\n }\n return str;\n}\n\nvoid UASQuickTabView::resizeEvent(QResizeEvent *event){\n setTableGeometry();\n}\n\nMinor fixes. Cleaned up code.#include \"UASQuickTabView.h\"\n#include \"ui_UASQuickTabView.h\"\n#include \n#include \n#include \n#include \n\n\nUASQuickTabView::UASQuickTabView(QWidget *parent) :\n ui(new Ui::UASQuickTabView)\n{\n ui->setupUi(this);\n\/\/ this->setLayout(ui->gridLayout);\n\/\/ ui->gridLayout->setContentsMargins(0,0,0,0);\n\/\/ ui->gridLayout->setHorizontalSpacing(0);\n\/\/ ui->gridLayout->setVerticalSpacing(0);\n\/\/ ui->gridLayout->setSpacing(0);\n\/\/ ui->gridLayout->setMargin(0);\n\n\n\n\n\n\n\tQStringList nameList;\/\/ = new QStringList();\n\/\/\tnameList.append(\"Широта:\");\n\/\/\tnameList.append(\"Долгота:\");\n\/\/\tnameList.append(\"Высота:\");\n\/\/\tnameList.append(\"Курс:\");\n\/\/\tnameList.append(\"Крен:\");\n\/\/\tnameList.append(\"Тангаж:\");\n\n nameList.append(tr(\"Latitude:\"));\n nameList.append(tr(\"Longitude:\"));\n nameList.append(tr(\"Altitude:\"));\n nameList.append(tr(\"Roll:\"));\n nameList.append(tr(\"Pitch:\"));\n nameList.append(tr(\"Yaw:\"));\n\n fieldNameList << \"M24:GLOBAL_POSITION_INT.lat\"\n << \"M24:GLOBAL_POSITION_INT.lon\"\n << \"M24:GLOBAL_POSITION_INT.alt\"\n << \"M24:ATTITUDE.roll\"\n << \"M24:ATTITUDE.pitch\"\n << \"M24:ATTITUDE.yaw\";\n\n foreach(QString str, fieldNameList){\n uasPropertyValueMap.insert(str, 0.0);\n }\n\n\tQTextCodec::setCodecForLocale(QTextCodec::codecForName(\"UTF-8\"));\n\tui->tableWidget->setColumnCount(2);\n ui->tableWidget->setRowCount(nameList.count());\n ui->tableWidget->setLineWidth(1);\n ui->tableWidget->setFrameStyle(QFrame::NoFrame);\n \/\/ui->tableWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);\n ui->tableWidget->setStyleSheet(\"gridline-color : dimgray\");\n ui->tableWidget->setWindowFlags(\/*ui->tableWidget->windowFlags()*\/Qt::Widget | Qt::FramelessWindowHint);\n\n\n\n\n \/\/tableFont = new QFont(\"Times New Roman\", 14, 3);\n\/\/ tableFont.setFamily(\"Times New Roman\");\n tableFont.setPixelSize(14);\n tableFont.setBold(3);\n\n for(int i = 0; i < nameList.count(); i++) {\n \/* Add first column that shows lable names.*\/\n QTableWidgetItem* item = new QTableWidgetItem();\n Q_ASSERT(item);\n if (item) {\n item->setText(nameList.at(i));\n tableNameList.append(item);\n item->setFont(tableFont);\n item->setFlags(item->flags() ^ Qt::ItemIsEditable ^ Qt::ItemIsSelectable);\n ui->tableWidget->setItem(i, 0, item);\n }\n\n \/* Add column with values.*\/\n item = new QTableWidgetItem();\n Q_ASSERT(item);\n if (item) {\n tableValueList.append(item);\n item->setFont(tableFont);\n item->setText(\"0.0\");\n item->setFlags(item->flags() ^ Qt::ItemIsEditable ^ Qt::ItemIsSelectable);\n ui->tableWidget->setItem(i, 1, item);\n }\n }\n\n setTableGeometry();\n\n updateTimer = new QTimer(this);\n connect(updateTimer,SIGNAL(timeout()),this,SLOT(updateTimerTick()));\n updateTimer->start(1000);\n\n\n\/\/ testTimerValue = true;\n\/\/ testTimer = new QTimer(this);\n\/\/ testTimer->setSingleShot(false);\n\/\/ connect(testTimer,SIGNAL(timeout()),this,SLOT(testTimerExpired()));\n\/\/ testTimer->start(750);\n\n}\n\nUASQuickTabView::~UASQuickTabView()\n{\n delete ui;\n foreach (QTableWidgetItem* item, tableNameList) {\n delete item;\n }\n foreach (QTableWidgetItem* item, tableValueList) {\n delete item;\n }\n delete updateTimer;\n}\n\nvoid UASQuickTabView::addSource(MAVLinkDecoder *decoder)\n{\n connect(decoder,SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)),this,SLOT(valueChanged(int,QString,QString,QVariant,quint64)));\n}\n\nvoid UASQuickTabView::valueChanged(const int uasId, const QString& name, const QString& unit, const QVariant &variant, const quint64 msec)\n{\n Q_UNUSED(uasId);\n Q_UNUSED(unit);\n Q_UNUSED(msec);\n\n bool ok;\n double value = variant.toDouble(&ok);\n QMetaType::Type metaType = static_cast(variant.type());\n if(!ok || metaType == QMetaType::QString || metaType == QMetaType::QByteArray)\n return;\n \/\/qDebug()<addItem(name);\n\/\/ }\n\/\/ }\n\n if((name == \"M24:GLOBAL_POSITION_INT.lat\")||(name == \"M24:GLOBAL_POSITION_INT.lon\"))\n uasPropertyValueMap[name] = value\/10000000;\n else if(name == \"M24:GLOBAL_POSITION_INT.alt\")\n uasPropertyValueMap[name] = value\/1000;\n else if((name == \"M24:ATTITUDE.roll\")||(name == \"M24:ATTITUDE.pitch\")||(name == \"M24:ATTITUDE.yaw\"))\n uasPropertyValueMap[name] = value\/M_PI*180;\n}\n\nvoid UASQuickTabView::updateTimerTick()\n{\n for(int i = 0; i < fieldNameList.size(); i++){\n \/\/QString str = QString::number(uasPropertyValueMap[fieldNameList.at(i)]);\n QString str = formText(fieldNameList.at(i), uasPropertyValueMap[fieldNameList.at(i)]);\n ui->tableWidget->item(i,1)->setText(str);\n }\n}\n\n\/\/void UASQuickTabView::testTimerExpired(){\n\/\/ if(testTimerValue == true){\n\/\/ valueChanged(0,\"M24:GLOBAL_POSITION_INT.lat\",\"unit\",538893530,0);\n\/\/ valueChanged(0,\"M24:GLOBAL_POSITION_INT.lon\",\"unit\",275296780,0);\n\/\/ valueChanged(0,\"M24:GLOBAL_POSITION_INT.alt\",\"unit\",272000,0);\n\/\/ valueChanged(0,\"M24:ATTITUDE.roll\",\"unit\",0.36814,0);\n\/\/ valueChanged(0,\"M24:ATTITUDE.pitch\",\"unit\",0.56715,0);\n\/\/ valueChanged(0,\"M24:ATTITUDE.yaw\",\"unit\",0.24715,0);\n\/\/ testTimerValue = false;\n\/\/ }\n\/\/ else{\n\/\/ valueChanged(0,\"M24:GLOBAL_POSITION_INT.lat\",\"unit\",-549993530,0);\n\/\/ valueChanged(0,\"M24:GLOBAL_POSITION_INT.lon\",\"unit\",-277796780,0);\n\/\/ valueChanged(0,\"M24:GLOBAL_POSITION_INT.alt\",\"unit\",284000,0);\n\/\/ valueChanged(0,\"M24:ATTITUDE.roll\",\"unit\",0.35614,0);\n\/\/ valueChanged(0,\"M24:ATTITUDE.pitch\",\"unit\",0.46815,0);\n\/\/ valueChanged(0,\"M24:ATTITUDE.yaw\",\"unit\",0.67895,0);\n\/\/ testTimerValue = true;\n\/\/ }\n\/\/}\n\nvoid UASQuickTabView::setTableGeometry(){\n\n ui->tableWidget->resize(this->width(), this->height());\n\n ui->tableWidget->setColumnWidth(0, ((ui->tableWidget->width())\/2));\n ui->tableWidget->setColumnWidth(1, ((ui->tableWidget->width())\/2 + (ui->tableWidget->width())%2));\n\n int rowCount = ui->tableWidget->rowCount();\n for(int i = 0; i < rowCount - 1; i++) {\n\n ui->tableWidget->setRowHeight(i, (ui->tableWidget->height()) \/ rowCount);\n \/\/ui->tableWidget->setRowHeight(i, (ui->tableWidget->height())\/6);\n }\n ui->tableWidget->setRowHeight(rowCount - 1, ((ui->tableWidget->height()) \/ rowCount) + ((ui->tableWidget->height()) % rowCount));\n}\n\nQString UASQuickTabView::formText(QString name, double value){\n\n QString str;\n\n if(name == \"M24:GLOBAL_POSITION_INT.lat\"){\n if(value >= 0){\n str = QString::number(value,'f',5);\n str += 0x00B0;\n str += tr(\" N\");\n }\n else if(value < 0){\n value *=-1;\n str = QString::number(value,'f',5);\n str += 0x00B0;\n str += tr(\" S\");\n }\n }\n\n else if(name == \"M24:GLOBAL_POSITION_INT.lon\"){\n if(value >= 0){\n str = QString::number(value,'f',5);\n str += 0x00B0;\n str += tr(\" E\");\n }\n else if(value < 0){\n value *=-1;\n str = QString::number(value,'f',5);\n str += 0x00B0;\n str += tr(\" W\");\n }\n }\n\n else if(name == \"M24:GLOBAL_POSITION_INT.alt\"){\n str = QString::number(value,'f',1);\n str +=tr(\" m.\");\n }\n else if((name == \"M24:ATTITUDE.roll\")||(name == \"M24:ATTITUDE.pitch\")||(name == \"M24:ATTITUDE.yaw\")){\n str = QString::number(value,'f',2);\n str += 0x00B0;\n }\n return str;\n}\n\nvoid UASQuickTabView::resizeEvent(QResizeEvent *event){\n setTableGeometry();\n}\n\n<|endoftext|>"} {"text":"\/*\n * Copyright (C) 2011 Collabora Ltd. \n * @author Andre Moreira Magalhaes \n * Copyright (C) 2011 David Edmundson \n *\n * This library is free software; you can redistribute it and\/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n *\/\n\n#include \"sasl-auth-op.h\"\n#include \"x-telepathy-password-auth-operation.h\"\n\n#include \n\n#include \n#include \n\n\nSaslAuthOp::SaslAuthOp(const Tp::AccountPtr &account,\n const Tp::ChannelPtr &channel)\n : Tp::PendingOperation(channel),\n m_account(account),\n m_channel(channel),\n m_saslIface(channel->interface())\n{\n connect(m_saslIface->requestAllProperties(),\n SIGNAL(finished(Tp::PendingOperation*)),\n SLOT(gotProperties(Tp::PendingOperation*)));\n}\n\nSaslAuthOp::~SaslAuthOp()\n{\n}\n\nvoid SaslAuthOp::gotProperties(Tp::PendingOperation *op)\n{\n if (op->isError()) {\n kWarning() << \"Unable to retrieve available SASL mechanisms\";\n m_channel->requestClose();\n setFinishedWithError(op->errorName(), op->errorMessage());\n return;\n }\n\n Tp::PendingVariantMap *pvm = qobject_cast(op);\n QVariantMap props = qdbus_cast(pvm->result());\n QStringList mechanisms = qdbus_cast(props.value(\"AvailableMechanisms\"));\n kDebug() << mechanisms;\n\n if (mechanisms.contains(QLatin1String(\"X-TELEPATHY-PASSWORD\"))) {\n \/\/ everything ok, we can return from handleChannels now\n emit ready(this);\n XTelepathyPasswordAuthOperation *authop = new XTelepathyPasswordAuthOperation(m_account, m_saslIface, qdbus_cast(props.value(\"CanTryAgain\")));\n connect (authop, SIGNAL(finished(Tp::PendingOperation*)), SLOT(onAuthOperationFinished(Tp::PendingOperation*)));\n uint status = qdbus_cast(props.value(\"SASLStatus\"));\n QString error = qdbus_cast(props.value(\"SASLError\"));\n QVariantMap errorDetails = qdbus_cast(props.value(\"SASLErrorDetails\"));\n authop->onSASLStatusChanged(status, error, errorDetails);\n } else {\n kWarning() << \"X-TELEPATHY-PASSWORD is the only supported SASL mechanism and is not available:\" << mechanisms;\n m_channel->requestClose();\n setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED,\n QLatin1String(\"X-TELEPATHY-PASSWORD is the only supported SASL mechanism and is not available\"));\n return;\n }\n\n}\n\nvoid SaslAuthOp::onAuthOperationFinished(Tp::PendingOperation *op)\n{\n m_channel->requestClose();\n if(op->isError()) {\n setFinishedWithError(op->errorName(), op->errorMessage());\n } else {\n setFinished();\n }\n}\n\n#include \"sasl-auth-op.moc\"\nCleanup\/*\n * Copyright (C) 2011 Collabora Ltd. \n * @author Andre Moreira Magalhaes \n * Copyright (C) 2011 David Edmundson \n *\n * This library is free software; you can redistribute it and\/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n *\/\n\n#include \"sasl-auth-op.h\"\n#include \"x-telepathy-password-auth-operation.h\"\n\n#include \n\n#include \n#include \n\n\nSaslAuthOp::SaslAuthOp(const Tp::AccountPtr &account,\n const Tp::ChannelPtr &channel)\n : Tp::PendingOperation(channel),\n m_account(account),\n m_channel(channel),\n m_saslIface(channel->interface())\n{\n connect(m_saslIface->requestAllProperties(),\n SIGNAL(finished(Tp::PendingOperation*)),\n SLOT(gotProperties(Tp::PendingOperation*)));\n}\n\nSaslAuthOp::~SaslAuthOp()\n{\n}\n\nvoid SaslAuthOp::gotProperties(Tp::PendingOperation *op)\n{\n if (op->isError()) {\n kWarning() << \"Unable to retrieve available SASL mechanisms\";\n m_channel->requestClose();\n setFinishedWithError(op->errorName(), op->errorMessage());\n return;\n }\n\n Tp::PendingVariantMap *pvm = qobject_cast(op);\n QVariantMap props = qdbus_cast(pvm->result());\n QStringList mechanisms = qdbus_cast(props.value(\"AvailableMechanisms\"));\n kDebug() << mechanisms;\n\n if (mechanisms.contains(QLatin1String(\"X-TELEPATHY-PASSWORD\"))) {\n \/\/ everything ok, we can return from handleChannels now\n emit ready(this);\n XTelepathyPasswordAuthOperation *authop = new XTelepathyPasswordAuthOperation(m_account, m_saslIface, qdbus_cast(props.value(\"CanTryAgain\")));\n connect (authop,\n SIGNAL(finished(Tp::PendingOperation*)),\n SLOT(onAuthOperationFinished(Tp::PendingOperation*)));\n uint status = qdbus_cast(props.value(\"SASLStatus\"));\n QString error = qdbus_cast(props.value(\"SASLError\"));\n QVariantMap errorDetails = qdbus_cast(props.value(\"SASLErrorDetails\"));\n authop->onSASLStatusChanged(status, error, errorDetails);\n } else {\n kWarning() << \"X-TELEPATHY-PASSWORD is the only supported SASL mechanism and is not available:\" << mechanisms;\n m_channel->requestClose();\n setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED,\n QLatin1String(\"X-TELEPATHY-PASSWORD is the only supported SASL mechanism and is not available\"));\n return;\n }\n}\n\nvoid SaslAuthOp::onAuthOperationFinished(Tp::PendingOperation *op)\n{\n m_channel->requestClose();\n if(op->isError()) {\n setFinishedWithError(op->errorName(), op->errorMessage());\n } else {\n setFinished();\n }\n}\n\n#include \"sasl-auth-op.moc\"\n<|endoftext|>"} {"text":"\/*****************************************************************************\n * Media Library\n *****************************************************************************\n * Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs\n *\n * Authors: Hugo Beauzée-Luyssen\n *\n * This program is free software; you can redistribute it and\/or modify it\n * under the terms of the GNU Lesser General Public License as published by\n * the Free Software Foundation; either version 2.1 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public License\n * along with this program; if not, write to the Free Software Foundation,\n * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.\n *****************************************************************************\/\n\n#include \"Tests.h\"\n\n#include \"IHistoryEntry.h\"\n#include \"History.h\"\n#include \"Media.h\"\n\nclass HistoryTest : public Tests\n{\n\n};\n\nTEST_F( HistoryTest, InsertMrl )\n{\n ml->addToHistory( \"upnp:\/\/stream\" );\n auto hList = ml->history();\n ASSERT_EQ( 1u, hList.size() );\n auto h = hList[0];\n ASSERT_EQ( nullptr, h->media() );\n ASSERT_EQ( h->mrl(), \"upnp:\/\/stream\" );\n ASSERT_NE( 0u, h->insertionDate() );\n}\n\nTEST_F( HistoryTest, InsertMedia )\n{\n auto media = ml->addFile( \"media.mkv\" );\n ml->addToHistory( media );\n auto hList = ml->history();\n ASSERT_EQ( 1u, hList.size() );\n auto h = hList[0];\n ASSERT_NE( nullptr, h->media() );\n ASSERT_EQ( media->id(), h->media()->id() );\n ASSERT_EQ( h->mrl(), \"\" );\n ASSERT_NE( 0u, h->insertionDate() );\n}\n\nTEST_F( HistoryTest, MaxEntries )\n{\n for ( auto i = 0u; i < History::MaxEntries; ++i )\n {\n ml->addToHistory( std::to_string( i ) );\n }\n auto hList = ml->history();\n ASSERT_EQ( History::MaxEntries, hList.size() );\n ml->addToHistory( \"new-media\" );\n hList = ml->history();\n ASSERT_EQ( History::MaxEntries, hList.size() );\n ASSERT_EQ( \"1\", hList[99]->mrl() );\n}\n\nTEST_F( HistoryTest, Ordering )\n{\n ml->addToHistory( \"first-stream\" );\n std::this_thread::sleep_for( std::chrono::seconds( 1 ) );\n ml->addToHistory( \"second-stream\" );\n auto hList = ml->history();\n ASSERT_EQ( 2u, hList.size() );\n ASSERT_EQ( hList[0]->mrl(), \"second-stream\" );\n ASSERT_EQ( hList[1]->mrl(), \"first-stream\" );\n}\n\nTEST_F( HistoryTest, UpdateInsertionDate )\n{\n ml->addToHistory( \"stream\" );\n auto hList = ml->history();\n ASSERT_EQ( 1u, hList.size() );\n auto date = hList[0]->insertionDate();\n std::this_thread::sleep_for( std::chrono::seconds( 1 ) );\n ml->addToHistory( \"stream\" );\n hList = ml->history();\n ASSERT_EQ( 1u, hList.size() );\n ASSERT_NE( date, hList[0]->insertionDate() );\n}\n\nTEST_F( HistoryTest, DeleteMedia )\n{\n auto m = ml->addFile( \"media.mkv\" );\n ml->addToHistory( m );\n auto hList = ml->history();\n ASSERT_EQ( 1u, hList.size() );\n auto f = m->files()[0];\n m->removeFile( static_cast( *f ) );\n hList = ml->history();\n ASSERT_EQ( 0u, hList.size() );\n}\nHistoryTests: Remove impossible to predict assertion\/*****************************************************************************\n * Media Library\n *****************************************************************************\n * Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs\n *\n * Authors: Hugo Beauzée-Luyssen\n *\n * This program is free software; you can redistribute it and\/or modify it\n * under the terms of the GNU Lesser General Public License as published by\n * the Free Software Foundation; either version 2.1 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public License\n * along with this program; if not, write to the Free Software Foundation,\n * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.\n *****************************************************************************\/\n\n#include \"Tests.h\"\n\n#include \"IHistoryEntry.h\"\n#include \"History.h\"\n#include \"Media.h\"\n\nclass HistoryTest : public Tests\n{\n\n};\n\nTEST_F( HistoryTest, InsertMrl )\n{\n ml->addToHistory( \"upnp:\/\/stream\" );\n auto hList = ml->history();\n ASSERT_EQ( 1u, hList.size() );\n auto h = hList[0];\n ASSERT_EQ( nullptr, h->media() );\n ASSERT_EQ( h->mrl(), \"upnp:\/\/stream\" );\n ASSERT_NE( 0u, h->insertionDate() );\n}\n\nTEST_F( HistoryTest, InsertMedia )\n{\n auto media = ml->addFile( \"media.mkv\" );\n ml->addToHistory( media );\n auto hList = ml->history();\n ASSERT_EQ( 1u, hList.size() );\n auto h = hList[0];\n ASSERT_NE( nullptr, h->media() );\n ASSERT_EQ( media->id(), h->media()->id() );\n ASSERT_EQ( h->mrl(), \"\" );\n ASSERT_NE( 0u, h->insertionDate() );\n}\n\nTEST_F( HistoryTest, MaxEntries )\n{\n for ( auto i = 0u; i < History::MaxEntries; ++i )\n {\n ml->addToHistory( std::to_string( i ) );\n }\n auto hList = ml->history();\n ASSERT_EQ( History::MaxEntries, hList.size() );\n ml->addToHistory( \"new-media\" );\n hList = ml->history();\n ASSERT_EQ( History::MaxEntries, hList.size() );\n}\n\nTEST_F( HistoryTest, Ordering )\n{\n ml->addToHistory( \"first-stream\" );\n std::this_thread::sleep_for( std::chrono::seconds( 1 ) );\n ml->addToHistory( \"second-stream\" );\n auto hList = ml->history();\n ASSERT_EQ( 2u, hList.size() );\n ASSERT_EQ( hList[0]->mrl(), \"second-stream\" );\n ASSERT_EQ( hList[1]->mrl(), \"first-stream\" );\n}\n\nTEST_F( HistoryTest, UpdateInsertionDate )\n{\n ml->addToHistory( \"stream\" );\n auto hList = ml->history();\n ASSERT_EQ( 1u, hList.size() );\n auto date = hList[0]->insertionDate();\n std::this_thread::sleep_for( std::chrono::seconds( 1 ) );\n ml->addToHistory( \"stream\" );\n hList = ml->history();\n ASSERT_EQ( 1u, hList.size() );\n ASSERT_NE( date, hList[0]->insertionDate() );\n}\n\nTEST_F( HistoryTest, DeleteMedia )\n{\n auto m = ml->addFile( \"media.mkv\" );\n ml->addToHistory( m );\n auto hList = ml->history();\n ASSERT_EQ( 1u, hList.size() );\n auto f = m->files()[0];\n m->removeFile( static_cast( *f ) );\n hList = ml->history();\n ASSERT_EQ( 0u, hList.size() );\n}\n<|endoftext|>"} {"text":"#include \"gtest\/gtest.h\"\n\nTEST(FooTest, HandleNoneZeroInput) {\n EXPECT_EQ(2, 2);\n EXPECT_EQ(6, 3 + 3);\n}\n\nint main(int argc, char *argv[]) {\n testing::InitGoogleTest(&argc, argv);\n return RUN_ALL_TESTS();\n}\nunit test#include \"gtest\/gtest.h\"\n#include \"socket.h\"\n#include \"ioloop.h\"\n\nTEST(FooTest, HandleNoneZeroInput) {\n EXPECT_EQ(2, 2);\n EXPECT_EQ(6, 3 + 3);\n}\n\n#define SOCKET_CONTINER_CAPACITY 10\n\nclass SocketUnittest: public testing::Test {\n protected:\n virtual void SetUp() {\n m_io = NULL;\n memset(m_sockets, 0, sizeof(m_sockets));\n }\n virtual void TearDown() {\n m_io->Release();\n for (int i = 0; i < SOCKET_CONTINER_CAPACITY; ++i) {\n if (m_sockets[i]) {\n delete m_sockets[i];\n m_sockets[i] = NULL;\n }\n delete m_sockets;\n }\n }\n\n IOLoop* m_io;\n Socket* m_sockets[SOCKET_CONTINER_CAPACITY];\n};\n\nint main(int argc, char *argv[]) {\n testing::InitGoogleTest(&argc, argv);\n return RUN_ALL_TESTS();\n}\n<|endoftext|>"} {"text":"\/\/ Copyright (c) 2009-2010 Satoshi Nakamoto\n\/\/ Copyright (c) 2009-2012 The Bitcoin developers\n\/\/ Distributed under the MIT\/X11 software license, see the accompanying\n\/\/ file COPYING or http:\/\/www.opensource.org\/licenses\/mit-license.php.\n\n#include \"keystore.h\"\n#include \"script.h\"\n\nbool CKeyStore::GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const\n{\n CKey key;\n if (!GetKey(address, key))\n return false;\n vchPubKeyOut = key.GetPubKey();\n return true;\n}\n\nbool CBasicKeyStore::AddKey(const CKey& key)\n{\n bool fCompressed = false;\n CSecret secret = key.GetSecret(fCompressed);\n {\n LOCK(cs_KeyStore);\n mapKeys[key.GetPubKey().GetID()] = make_pair(secret, fCompressed);\n }\n return true;\n}\n\nbool CBasicKeyStore::AddCScript(const CScript& redeemScript)\n{\n {\n LOCK(cs_KeyStore);\n mapScripts[redeemScript.GetID()] = redeemScript;\n }\n return true;\n}\n\nbool CBasicKeyStore::HaveCScript(const CScriptID& hash) const\n{\n bool result;\n {\n LOCK(cs_KeyStore);\n result = (mapScripts.count(hash) > 0);\n }\n return result;\n}\n\n\nbool CBasicKeyStore::GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const\n{\n {\n LOCK(cs_KeyStore);\n ScriptMap::const_iterator mi = mapScripts.find(hash);\n if (mi != mapScripts.end())\n {\n redeemScriptOut = (*mi).second;\n return true;\n }\n }\n return false;\n}\n\nbool CCryptoKeyStore::SetCrypted()\n{\n {\n LOCK(cs_KeyStore);\n if (fUseCrypto)\n return true;\n if (!mapKeys.empty())\n return false;\n fUseCrypto = true;\n }\n return true;\n}\n\nbool CCryptoKeyStore::Lock()\n{\n if (!SetCrypted())\n return false;\n\n {\n LOCK(cs_KeyStore);\n vMasterKey.clear();\n }\n\n NotifyStatusChanged(this);\n return true;\n}\n\nbool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn)\n{\n {\n LOCK(cs_KeyStore);\n if (!SetCrypted())\n return false;\n\n CryptedKeyMap::const_iterator mi = mapCryptedKeys.begin();\n for (; mi != mapCryptedKeys.end(); ++mi)\n {\n const CPubKey &vchPubKey = (*mi).second.first;\n const std::vector &vchCryptedSecret = (*mi).second.second;\n CSecret vchSecret;\n if(!DecryptSecret(vMasterKeyIn, vchCryptedSecret, vchPubKey.GetHash(), vchSecret))\n return false;\n if (vchSecret.size() != 32)\n return false;\n CKey key;\n key.SetPubKey(vchPubKey);\n key.SetSecret(vchSecret);\n if (key.GetPubKey() == vchPubKey)\n break;\n return false;\n }\n vMasterKey = vMasterKeyIn;\n }\n NotifyStatusChanged(this);\n return true;\n}\n\nbool CCryptoKeyStore::AddKey(const CKey& key)\n{\n {\n LOCK(cs_KeyStore);\n if (!IsCrypted())\n return CBasicKeyStore::AddKey(key);\n\n if (IsLocked())\n return false;\n\n std::vector vchCryptedSecret;\n CPubKey vchPubKey = key.GetPubKey();\n bool fCompressed;\n if (!EncryptSecret(vMasterKey, key.GetSecret(fCompressed), vchPubKey.GetHash(), vchCryptedSecret))\n return false;\n\n if (!AddCryptedKey(key.GetPubKey(), vchCryptedSecret))\n return false;\n }\n return true;\n}\n\n\nbool CCryptoKeyStore::AddCryptedKey(const CPubKey &vchPubKey, const std::vector &vchCryptedSecret)\n{\n {\n LOCK(cs_KeyStore);\n if (!SetCrypted())\n return false;\n\n mapCryptedKeys[vchPubKey.GetID()] = make_pair(vchPubKey, vchCryptedSecret);\n }\n return true;\n}\n\nbool CCryptoKeyStore::GetKey(const CKeyID &address, CKey& keyOut) const\n{\n {\n LOCK(cs_KeyStore);\n if (!IsCrypted())\n return CBasicKeyStore::GetKey(address, keyOut);\n\n CryptedKeyMap::const_iterator mi = mapCryptedKeys.find(address);\n if (mi != mapCryptedKeys.end())\n {\n const CPubKey &vchPubKey = (*mi).second.first;\n const std::vector &vchCryptedSecret = (*mi).second.second;\n CSecret vchSecret;\n if (!DecryptSecret(vMasterKey, vchCryptedSecret, vchPubKey.GetHash(), vchSecret))\n return false;\n if (vchSecret.size() != 32)\n return false;\n keyOut.SetPubKey(vchPubKey);\n keyOut.SetSecret(vchSecret);\n return true;\n }\n }\n return false;\n}\n\nbool CCryptoKeyStore::GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const\n{\n {\n LOCK(cs_KeyStore);\n if (!IsCrypted())\n return CKeyStore::GetPubKey(address, vchPubKeyOut);\n\n CryptedKeyMap::const_iterator mi = mapCryptedKeys.find(address);\n if (mi != mapCryptedKeys.end())\n {\n vchPubKeyOut = (*mi).second.first;\n return true;\n }\n }\n return false;\n}\n\nbool CCryptoKeyStore::EncryptKeys(CKeyingMaterial& vMasterKeyIn)\n{\n {\n LOCK(cs_KeyStore);\n if (!mapCryptedKeys.empty() || IsCrypted())\n return false;\n\n fUseCrypto = true;\n BOOST_FOREACH(KeyMap::value_type& mKey, mapKeys)\n {\n CKey key;\n if (!key.SetSecret(mKey.second.first, mKey.second.second))\n return false;\n const CPubKey vchPubKey = key.GetPubKey();\n std::vector vchCryptedSecret;\n bool fCompressed;\n if (!EncryptSecret(vMasterKeyIn, key.GetSecret(fCompressed), vchPubKey.GetHash(), vchCryptedSecret))\n return false;\n if (!AddCryptedKey(vchPubKey, vchCryptedSecret))\n return false;\n }\n mapKeys.clear();\n }\n return true;\n}\nUpdate to v3\/\/ Copyright (c) 2009-2010 Satoshi Nakamoto\n\/\/ Copyright (c) 2009-2012 The Bitcoin developers\n\/\/ Distributed under the MIT\/X11 software license, see the accompanying\n\/\/ file COPYING or http:\/\/www.opensource.org\/licenses\/mit-license.php.\n\/\/ Copyright (c) 2013-2014 Memorycoin Dev Team\n#include \"keystore.h\"\n#include \"script.h\"\n\nbool CKeyStore::GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const\n{\n CKey key;\n if (!GetKey(address, key))\n return false;\n vchPubKeyOut = key.GetPubKey();\n return true;\n}\n\nbool CBasicKeyStore::AddKey(const CKey& key)\n{\n bool fCompressed = false;\n CSecret secret = key.GetSecret(fCompressed);\n {\n LOCK(cs_KeyStore);\n mapKeys[key.GetPubKey().GetID()] = make_pair(secret, fCompressed);\n }\n return true;\n}\n\nbool CBasicKeyStore::AddCScript(const CScript& redeemScript)\n{\n {\n LOCK(cs_KeyStore);\n mapScripts[redeemScript.GetID()] = redeemScript;\n }\n return true;\n}\n\nbool CBasicKeyStore::HaveCScript(const CScriptID& hash) const\n{\n bool result;\n {\n LOCK(cs_KeyStore);\n result = (mapScripts.count(hash) > 0);\n }\n return result;\n}\n\n\nbool CBasicKeyStore::GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const\n{\n {\n LOCK(cs_KeyStore);\n ScriptMap::const_iterator mi = mapScripts.find(hash);\n if (mi != mapScripts.end())\n {\n redeemScriptOut = (*mi).second;\n return true;\n }\n }\n return false;\n}\n\nbool CCryptoKeyStore::SetCrypted()\n{\n {\n LOCK(cs_KeyStore);\n if (fUseCrypto)\n return true;\n if (!mapKeys.empty())\n return false;\n fUseCrypto = true;\n }\n return true;\n}\n\nbool CCryptoKeyStore::Lock()\n{\n if (!SetCrypted())\n return false;\n\n {\n LOCK(cs_KeyStore);\n vMasterKey.clear();\n }\n\n NotifyStatusChanged(this);\n return true;\n}\n\nbool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn)\n{\n {\n LOCK(cs_KeyStore);\n if (!SetCrypted())\n return false;\n\n CryptedKeyMap::const_iterator mi = mapCryptedKeys.begin();\n for (; mi != mapCryptedKeys.end(); ++mi)\n {\n const CPubKey &vchPubKey = (*mi).second.first;\n const std::vector &vchCryptedSecret = (*mi).second.second;\n CSecret vchSecret;\n if(!DecryptSecret(vMasterKeyIn, vchCryptedSecret, vchPubKey.GetHash(), vchSecret))\n return false;\n if (vchSecret.size() != 32)\n return false;\n CKey key;\n key.SetPubKey(vchPubKey);\n key.SetSecret(vchSecret);\n if (key.GetPubKey() == vchPubKey)\n break;\n return false;\n }\n vMasterKey = vMasterKeyIn;\n }\n NotifyStatusChanged(this);\n return true;\n}\n\nbool CCryptoKeyStore::AddKey(const CKey& key)\n{\n {\n LOCK(cs_KeyStore);\n if (!IsCrypted())\n return CBasicKeyStore::AddKey(key);\n\n if (IsLocked())\n return false;\n\n std::vector vchCryptedSecret;\n CPubKey vchPubKey = key.GetPubKey();\n bool fCompressed;\n if (!EncryptSecret(vMasterKey, key.GetSecret(fCompressed), vchPubKey.GetHash(), vchCryptedSecret))\n return false;\n\n if (!AddCryptedKey(key.GetPubKey(), vchCryptedSecret))\n return false;\n }\n return true;\n}\n\n\nbool CCryptoKeyStore::AddCryptedKey(const CPubKey &vchPubKey, const std::vector &vchCryptedSecret)\n{\n {\n LOCK(cs_KeyStore);\n if (!SetCrypted())\n return false;\n\n mapCryptedKeys[vchPubKey.GetID()] = make_pair(vchPubKey, vchCryptedSecret);\n }\n return true;\n}\n\nbool CCryptoKeyStore::GetKey(const CKeyID &address, CKey& keyOut) const\n{\n {\n LOCK(cs_KeyStore);\n if (!IsCrypted())\n return CBasicKeyStore::GetKey(address, keyOut);\n\n CryptedKeyMap::const_iterator mi = mapCryptedKeys.find(address);\n if (mi != mapCryptedKeys.end())\n {\n const CPubKey &vchPubKey = (*mi).second.first;\n const std::vector &vchCryptedSecret = (*mi).second.second;\n CSecret vchSecret;\n if (!DecryptSecret(vMasterKey, vchCryptedSecret, vchPubKey.GetHash(), vchSecret))\n return false;\n if (vchSecret.size() != 32)\n return false;\n keyOut.SetPubKey(vchPubKey);\n keyOut.SetSecret(vchSecret);\n return true;\n }\n }\n return false;\n}\n\nbool CCryptoKeyStore::GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const\n{\n {\n LOCK(cs_KeyStore);\n if (!IsCrypted())\n return CKeyStore::GetPubKey(address, vchPubKeyOut);\n\n CryptedKeyMap::const_iterator mi = mapCryptedKeys.find(address);\n if (mi != mapCryptedKeys.end())\n {\n vchPubKeyOut = (*mi).second.first;\n return true;\n }\n }\n return false;\n}\n\nbool CCryptoKeyStore::EncryptKeys(CKeyingMaterial& vMasterKeyIn)\n{\n {\n LOCK(cs_KeyStore);\n if (!mapCryptedKeys.empty() || IsCrypted())\n return false;\n\n fUseCrypto = true;\n BOOST_FOREACH(KeyMap::value_type& mKey, mapKeys)\n {\n CKey key;\n if (!key.SetSecret(mKey.second.first, mKey.second.second))\n return false;\n const CPubKey vchPubKey = key.GetPubKey();\n std::vector vchCryptedSecret;\n bool fCompressed;\n if (!EncryptSecret(vMasterKeyIn, key.GetSecret(fCompressed), vchPubKey.GetHash(), vchCryptedSecret))\n return false;\n if (!AddCryptedKey(vchPubKey, vchCryptedSecret))\n return false;\n }\n mapKeys.clear();\n }\n return true;\n}\n<|endoftext|>"} {"text":"\/\/ $Id$\n\n\/\/ The libMesh Finite Element Library.\n\/\/ Copyright (C) 2002-2008 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner\n \n\/\/ This library is free software; you can redistribute it and\/or\n\/\/ modify it under the terms of the GNU Lesser General Public\n\/\/ License as published by the Free Software Foundation; either\n\/\/ version 2.1 of the License, or (at your option) any later version.\n \n\/\/ This library is distributed in the hope that it will be useful,\n\/\/ but WITHOUT ANY WARRANTY; without even the implied warranty of\n\/\/ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n\/\/ Lesser General Public License for more details.\n \n\/\/ You should have received a copy of the GNU Lesser General Public\n\/\/ License along with this library; if not, write to the Free Software\n\/\/ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n\n\n\n\/\/ C++ includes\n\n\/\/ Local Includes\n#include \"mesh_base.h\"\n#include \"elem.h\"\n#include \"tree.h\"\n#include \"point_locator_tree.h\"\n#include \"mesh_tools.h\"\n\n\n\n\/\/------------------------------------------------------------------\n\/\/ PointLocator methods\nPointLocatorTree::PointLocatorTree (const MeshBase& mesh,\n\t\t\t\t const PointLocatorBase* master) :\n PointLocatorBase (mesh,master),\n _tree (NULL),\n _element (NULL),\n _out_of_mesh_mode(false)\n{\n this->init(Trees::NODES);\n}\n\n\n\n\nPointLocatorTree::PointLocatorTree (const MeshBase& mesh,\n\t\t\t\t const Trees::BuildType build_type,\n\t\t\t\t const PointLocatorBase* master) :\n PointLocatorBase (mesh,master),\n _tree (NULL),\n _element (NULL),\n _out_of_mesh_mode(false)\n{\n this->init(build_type);\n}\n\n\n\n\nPointLocatorTree::~PointLocatorTree ()\n{\n this->clear ();\n}\n\n\n\n\nvoid PointLocatorTree::clear ()\n{\n \/\/ only delete the tree when we are the master\n if (this->_tree != NULL)\n {\n if (this->_master == NULL)\n\t \/\/ we own the tree\n\t delete this->_tree;\n else\n\t \/\/ someone else owns and therefore deletes the tree\n\t this->_tree = NULL;\n }\n}\n\n\n\n\n\nvoid PointLocatorTree::init (const Trees::BuildType build_type)\n{\n libmesh_assert (this->_tree == NULL); \n\n if (this->_initialized)\n {\n libMesh::err << \"ERROR: Already initialized! Will ignore this call...\"\n\t\t << std::endl;\n }\n\n else\n\n {\n\n if (this->_master == NULL)\n {\n\t if (this->_mesh.mesh_dimension() == 3)\n\t _tree = new Trees::OctTree (this->_mesh, 200, build_type);\t\t\n\t else\n\t {\n\t \/\/ A 1D\/2D mesh in 3D space needs special consideration.\n\t \/\/ If the mesh is planar XY, we want to build a QuadTree\n\t \/\/ to search efficiently. If the mesh is truly a manifold,\n\t \/\/ then we need an octree\n\t bool is_planar_xy = false;\n\t \n\t \/\/ Build the bounding box for the mesh. If the delta-z bound is\n\t \/\/ negligibly small then we can use a quadtree.\n\t {\n\t\tMeshTools::BoundingBox bbox = MeshTools::bounding_box(this->_mesh);\n\t\t\n\t\tconst Real\n\t\t Dx = bbox.second(0) - bbox.first(0),\n\t\t Dz = bbox.second(2) - bbox.first(2);\n\t\t\n\t\tif (std::abs(Dz\/(Dx + 1.e-20)) < 1e-10)\n\t\t is_planar_xy = true;\n\t }\n\t \t\t \n\t if (is_planar_xy)\n\t\t_tree = new Trees::QuadTree (this->_mesh, 200, build_type);\n\t else\n\t\t_tree = new Trees::OctTree (this->_mesh, 200, build_type);\n\t }\n\t}\n\n else\n\t \n {\n\t \/\/ We are _not_ the master. Let our Tree point to\n\t \/\/ the master's tree. But for this we first transform\n\t \/\/ the master in a state for which we are friends.\n\t \/\/ And make sure the master @e has a tree!\n\t const PointLocatorTree* my_master =\n\t libmesh_cast_ptr(this->_master);\n\n\t if (my_master->initialized())\n\t this->_tree = my_master->_tree;\n\t else\n\t {\n\t libMesh::err << \"ERROR: Initialize master first, then servants!\"\n\t\t\t << std::endl;\n\t libmesh_error();\n\t }\n }\n\n\n \/\/ Not all PointLocators may own a tree, but all of them\n \/\/ use their own element pointer. Let the element pointer\n \/\/ be unique for every interpolator.\n \/\/ Suppose the interpolators are used concurrently\n \/\/ at different locations in the mesh, then it makes quite\n \/\/ sense to have unique start elements.\n this->_element = NULL;\n }\n\n\n \/\/ ready for take-off\n this->_initialized = true;\n}\n\n\n\n\n\nconst Elem* PointLocatorTree::operator() (const Point& p) const\n{\n libmesh_assert (this->_initialized);\n \n \/\/ First check the element from last time before asking the tree\n if (this->_element==NULL || !(this->_element->contains_point(p)))\n {\n\t\/\/ ask the tree\n\tthis->_element = this->_tree->find_element (p);\n\n\tif (this->_element == NULL)\n\t {\n\t \/* No element seems to contain this point. If out-of-mesh\n\t mode is enabled, just return NULL. If not, however, we\n\t have to perform a linear search before we call \\p\n\t libmesh_error() since in the case of curved elements, the\n\t bounding box computed in \\p TreeNode::insert(const\n\t Elem*) might be slightly inaccurate. *\/\n\t if(!_out_of_mesh_mode)\n\t {\n\t\tMeshBase::const_element_iterator pos = this->_mesh.active_elements_begin();\n\t\tconst MeshBase::const_element_iterator end_pos = this->_mesh.active_elements_end();\n\t\t\n\t\tfor ( ; pos != end_pos; ++pos)\n\t\t if ((*pos)->contains_point(p))\n\t\t return this->_element = (*pos);\n\n\t\tif (this->_element == NULL)\n\t\t {\n\t\t libMesh::err << std::endl\n\t\t\t << \" ******** Serious Problem. Could not find an Element \"\n\t\t\t << \"in the Mesh\" \n\t\t\t << std:: endl\n\t\t\t << \" ******** that contains the Point \"\n\t\t\t << p;\n\t\t libmesh_error();\n\t\t }\n\t }\n\t }\n }\n \n \/\/ the element should be active\n libmesh_assert (this->_element->active());\n\n \/\/ return the element\n return this->_element;\n}\n\nvoid PointLocatorTree::enable_out_of_mesh_mode (void)\n{\n \/* Out-of-mesh mode is currently only supported if all of the\n elements have affine mappings. The reason is that for quadratic\n mappings, it is not easy to construct a relyable bounding box of\n the element, and thus, the fallback linear search in \\p\n operator() is required. Hence, out-of-mesh mode would be\n extremely slow. *\/\n if(!_out_of_mesh_mode)\n {\n#ifdef DEBUG\n MeshBase::const_element_iterator pos = this->_mesh.active_elements_begin();\n const MeshBase::const_element_iterator end_pos = this->_mesh.active_elements_end();\n for ( ; pos != end_pos; ++pos)\n\tif (!(*pos)->has_affine_map())\n\t {\n\t libMesh::err << \"ERROR: Out-of-mesh mode is currently only supported if all elements have affine mappings.\" << std::endl;\n\t libmesh_error();\n\t }\n#endif\n \n _out_of_mesh_mode = true;\n }\n}\n\nvoid PointLocatorTree::disable_out_of_mesh_mode (void)\n{\n _out_of_mesh_mode = false;\n}\n\nFixed the overzealous assertion bug Yujie caught\/\/ $Id$\n\n\/\/ The libMesh Finite Element Library.\n\/\/ Copyright (C) 2002-2008 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner\n \n\/\/ This library is free software; you can redistribute it and\/or\n\/\/ modify it under the terms of the GNU Lesser General Public\n\/\/ License as published by the Free Software Foundation; either\n\/\/ version 2.1 of the License, or (at your option) any later version.\n \n\/\/ This library is distributed in the hope that it will be useful,\n\/\/ but WITHOUT ANY WARRANTY; without even the implied warranty of\n\/\/ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n\/\/ Lesser General Public License for more details.\n \n\/\/ You should have received a copy of the GNU Lesser General Public\n\/\/ License along with this library; if not, write to the Free Software\n\/\/ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n\n\n\n\/\/ C++ includes\n\n\/\/ Local Includes\n#include \"mesh_base.h\"\n#include \"elem.h\"\n#include \"tree.h\"\n#include \"point_locator_tree.h\"\n#include \"mesh_tools.h\"\n\n\n\n\/\/------------------------------------------------------------------\n\/\/ PointLocator methods\nPointLocatorTree::PointLocatorTree (const MeshBase& mesh,\n\t\t\t\t const PointLocatorBase* master) :\n PointLocatorBase (mesh,master),\n _tree (NULL),\n _element (NULL),\n _out_of_mesh_mode(false)\n{\n this->init(Trees::NODES);\n}\n\n\n\n\nPointLocatorTree::PointLocatorTree (const MeshBase& mesh,\n\t\t\t\t const Trees::BuildType build_type,\n\t\t\t\t const PointLocatorBase* master) :\n PointLocatorBase (mesh,master),\n _tree (NULL),\n _element (NULL),\n _out_of_mesh_mode(false)\n{\n this->init(build_type);\n}\n\n\n\n\nPointLocatorTree::~PointLocatorTree ()\n{\n this->clear ();\n}\n\n\n\n\nvoid PointLocatorTree::clear ()\n{\n \/\/ only delete the tree when we are the master\n if (this->_tree != NULL)\n {\n if (this->_master == NULL)\n\t \/\/ we own the tree\n\t delete this->_tree;\n else\n\t \/\/ someone else owns and therefore deletes the tree\n\t this->_tree = NULL;\n }\n}\n\n\n\n\n\nvoid PointLocatorTree::init (const Trees::BuildType build_type)\n{\n libmesh_assert (this->_tree == NULL); \n\n if (this->_initialized)\n {\n libMesh::err << \"ERROR: Already initialized! Will ignore this call...\"\n\t\t << std::endl;\n }\n\n else\n\n {\n\n if (this->_master == NULL)\n {\n\t if (this->_mesh.mesh_dimension() == 3)\n\t _tree = new Trees::OctTree (this->_mesh, 200, build_type);\t\t\n\t else\n\t {\n\t \/\/ A 1D\/2D mesh in 3D space needs special consideration.\n\t \/\/ If the mesh is planar XY, we want to build a QuadTree\n\t \/\/ to search efficiently. If the mesh is truly a manifold,\n\t \/\/ then we need an octree\n\t bool is_planar_xy = false;\n\t \n\t \/\/ Build the bounding box for the mesh. If the delta-z bound is\n\t \/\/ negligibly small then we can use a quadtree.\n\t {\n\t\tMeshTools::BoundingBox bbox = MeshTools::bounding_box(this->_mesh);\n\t\t\n\t\tconst Real\n\t\t Dx = bbox.second(0) - bbox.first(0),\n\t\t Dz = bbox.second(2) - bbox.first(2);\n\t\t\n\t\tif (std::abs(Dz\/(Dx + 1.e-20)) < 1e-10)\n\t\t is_planar_xy = true;\n\t }\n\t \t\t \n\t if (is_planar_xy)\n\t\t_tree = new Trees::QuadTree (this->_mesh, 200, build_type);\n\t else\n\t\t_tree = new Trees::OctTree (this->_mesh, 200, build_type);\n\t }\n\t}\n\n else\n\t \n {\n\t \/\/ We are _not_ the master. Let our Tree point to\n\t \/\/ the master's tree. But for this we first transform\n\t \/\/ the master in a state for which we are friends.\n\t \/\/ And make sure the master @e has a tree!\n\t const PointLocatorTree* my_master =\n\t libmesh_cast_ptr(this->_master);\n\n\t if (my_master->initialized())\n\t this->_tree = my_master->_tree;\n\t else\n\t {\n\t libMesh::err << \"ERROR: Initialize master first, then servants!\"\n\t\t\t << std::endl;\n\t libmesh_error();\n\t }\n }\n\n\n \/\/ Not all PointLocators may own a tree, but all of them\n \/\/ use their own element pointer. Let the element pointer\n \/\/ be unique for every interpolator.\n \/\/ Suppose the interpolators are used concurrently\n \/\/ at different locations in the mesh, then it makes quite\n \/\/ sense to have unique start elements.\n this->_element = NULL;\n }\n\n\n \/\/ ready for take-off\n this->_initialized = true;\n}\n\n\n\n\n\nconst Elem* PointLocatorTree::operator() (const Point& p) const\n{\n libmesh_assert (this->_initialized);\n \n \/\/ First check the element from last time before asking the tree\n if (this->_element==NULL || !(this->_element->contains_point(p)))\n {\n\t\/\/ ask the tree\n\tthis->_element = this->_tree->find_element (p);\n\n\tif (this->_element == NULL)\n\t {\n\t \/* No element seems to contain this point. If out-of-mesh\n\t mode is enabled, just return NULL. If not, however, we\n\t have to perform a linear search before we call \\p\n\t libmesh_error() since in the case of curved elements, the\n\t bounding box computed in \\p TreeNode::insert(const\n\t Elem*) might be slightly inaccurate. *\/\n\t if(!_out_of_mesh_mode)\n\t {\n\t\tMeshBase::const_element_iterator pos = this->_mesh.active_elements_begin();\n\t\tconst MeshBase::const_element_iterator end_pos = this->_mesh.active_elements_end();\n\t\t\n\t\tfor ( ; pos != end_pos; ++pos)\n\t\t if ((*pos)->contains_point(p))\n\t\t return this->_element = (*pos);\n\n\t\tif (this->_element == NULL)\n\t\t {\n\t\t libMesh::err << std::endl\n\t\t\t << \" ******** Serious Problem. Could not find an Element \"\n\t\t\t << \"in the Mesh\" \n\t\t\t << std:: endl\n\t\t\t << \" ******** that contains the Point \"\n\t\t\t << p;\n\t\t libmesh_error();\n\t\t }\n\t }\n\t }\n }\n \n \/\/ If we found an element, it should be active\n libmesh_assert (!this->_element || this->_element->active());\n\n \/\/ return the element\n return this->_element;\n}\n\nvoid PointLocatorTree::enable_out_of_mesh_mode (void)\n{\n \/* Out-of-mesh mode is currently only supported if all of the\n elements have affine mappings. The reason is that for quadratic\n mappings, it is not easy to construct a relyable bounding box of\n the element, and thus, the fallback linear search in \\p\n operator() is required. Hence, out-of-mesh mode would be\n extremely slow. *\/\n if(!_out_of_mesh_mode)\n {\n#ifdef DEBUG\n MeshBase::const_element_iterator pos = this->_mesh.active_elements_begin();\n const MeshBase::const_element_iterator end_pos = this->_mesh.active_elements_end();\n for ( ; pos != end_pos; ++pos)\n\tif (!(*pos)->has_affine_map())\n\t {\n\t libMesh::err << \"ERROR: Out-of-mesh mode is currently only supported if all elements have affine mappings.\" << std::endl;\n\t libmesh_error();\n\t }\n#endif\n \n _out_of_mesh_mode = true;\n }\n}\n\nvoid PointLocatorTree::disable_out_of_mesh_mode (void)\n{\n _out_of_mesh_mode = false;\n}\n\n<|endoftext|>"} {"text":"\/* -------------------------------------------------------------------------- *\/\n\/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) *\/\n\/* *\/\n\/* Licensed under the Apache License, Version 2.0 (the \"License\"); you may *\/\n\/* not use this file except in compliance with the License. You may obtain *\/\n\/* a copy of the License at *\/\n\/* *\/\n\/* http:\/\/www.apache.org\/licenses\/LICENSE-2.0 *\/\n\/* *\/\n\/* Unless required by applicable law or agreed to in writing, software *\/\n\/* distributed under the License is distributed on an \"AS IS\" BASIS, *\/\n\/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *\/\n\/* See the License for the specific language governing permissions and *\/\n\/* limitations under the License. *\/\n\/* -------------------------------------------------------------------------- *\/\n\n#include \"LibVirtDriver.h\"\n\n#include \"Nebula.h\"\n#include \n#include \n#include \n\n\/* ************************************************************************** *\/\n\/* Virtual Network :: Database Access Functions *\/\n\/* ************************************************************************** *\/\n\nconst char * LibVirtDriver::vmware_vnm_name = \"vmware\";\n\nint LibVirtDriver::deployment_description_vmware(\n const VirtualMachine * vm,\n const string& file_name) const\n{\n ofstream file;\n\n int num;\n vector attrs;\n\n string vcpu;\n string memory;\n\n int memory_in_kb = 0;\n\n string arch = \"\";\n\n const VectorAttribute * disk;\n const VectorAttribute * context;\n\n string type = \"\";\n string target = \"\";\n string bus = \"\";\n string ro = \"\";\n string source = \"\";\n string datastore = \"\";\n string driver = \"\";\n string default_driver = \"\";\n bool readonly;\n\n const VectorAttribute * nic;\n\n string network_id = \"\";\n string mac = \"\";\n string bridge = \"\";\n string script = \"\";\n string model = \"\";\n\n const VectorAttribute * raw;\n string data;\n\n \/\/ ------------------------------------------------------------------------\n\n file.open(file_name.c_str(), ios::out);\n\n if (file.fail() == true)\n {\n goto error_vmware_file;\n }\n\n \/\/ ------------------------------------------------------------------------\n \/\/ Starting XML document\n \/\/ ------------------------------------------------------------------------\n\n file << \"\" << endl;\n\n \/\/ ------------------------------------------------------------------------\n \/\/ Domain name\n \/\/ ------------------------------------------------------------------------\n\n file << \"\\tone-\" << vm->get_oid() << \"<\/name>\" << endl;\n\n \/\/ ------------------------------------------------------------------------\n \/\/ CPU\n \/\/ ------------------------------------------------------------------------\n\n vm->get_template_attribute(\"VCPU\", vcpu);\n\n if(vcpu.empty())\n {\n get_default(\"VCPU\", vcpu);\n }\n\n if (!vcpu.empty())\n {\n file << \"\\t\" << vcpu << \"<\/vcpu>\" << endl;\n }\n\n \/\/ ------------------------------------------------------------------------\n \/\/ Memory\n \/\/ ------------------------------------------------------------------------\n\n vm->get_template_attribute(\"MEMORY\",memory);\n\n if (memory.empty())\n {\n get_default(\"MEMORY\",memory);\n }\n\n if (!memory.empty())\n {\n memory_in_kb = atoi(memory.c_str()) * 1024;\n\n file << \"\\t\" << memory_in_kb << \"<\/memory>\" << endl;\n }\n else\n {\n goto error_vmware_memory;\n }\n\n \/\/ ------------------------------------------------------------------------\n \/\/ OS and boot options\n \/\/ ------------------------------------------------------------------------\n\n num = vm->get_template_attribute(\"OS\",attrs);\n\n \/\/ Get values & defaults\n if ( num > 0 )\n {\n const VectorAttribute * os;\n\n os = dynamic_cast(attrs[0]);\n\n if( os != 0 )\n {\n arch = os->vector_value(\"ARCH\");\n }\n }\n\n if ( arch.empty() )\n {\n get_default(\"OS\",\"ARCH\",arch);\n\n if (arch.empty())\n {\n goto error_vmware_arch;\n }\n }\n\n \/\/ Start writing to the file with the info we got\n\n file << \"\\t\" << endl;\n\n file << \"\\t\\thvm<\/type>\" << endl;\n\n file << \"\\t<\/os>\" << endl;\n\n attrs.clear();\n\n \/\/ ------------------------------------------------------------------------\n \/\/ Disks\n \/\/ ------------------------------------------------------------------------\n\n file << \"\\t\" << endl;\n\n get_default(\"DISK\",\"DRIVER\",default_driver);\n\n num = vm->get_template_attribute(\"DISK\",attrs);\n\n if (num!=0)\n {\n get_default(\"DATASTORE\", datastore);\n }\n\n for (int i=0; i < num ;i++)\n {\n disk = dynamic_cast(attrs[i]);\n\n if ( disk == 0 )\n {\n continue;\n }\n\n type = disk->vector_value(\"TYPE\");\n target = disk->vector_value(\"TARGET\");\n ro = disk->vector_value(\"READONLY\");\n bus = disk->vector_value(\"BUS\");\n source = disk->vector_value(\"SOURCE\");\n driver = disk->vector_value(\"DRIVER\");\n\n if (target.empty())\n {\n goto error_vmware_disk;\n }\n\n readonly = false;\n\n if ( !ro.empty() )\n {\n transform(ro.begin(),ro.end(),ro.begin(),(int(*)(int))toupper);\n\n if ( ro == \"YES\" )\n {\n readonly = true;\n }\n }\n\n if (type.empty() == false)\n {\n transform(type.begin(),type.end(),type.begin(),(int(*)(int))toupper);\n }\n\n if ( type == \"BLOCK\" )\n {\n file << \"\\t\\t\" << endl;\n file << \"\\t\\t\\tget_oid()\n << \"\/images\/disk.\" << i << \"'\/>\" << endl;\n }\n else if ( type == \"CDROM\" )\n {\n file << \"\\t\\t\" << endl;\n file << \"\\t\\t\\tget_oid()\n << \"\/images\/disk.\" << i << \".iso'\/>\" << endl;\n }\n else\n {\n file << \"\\t\\t\" << endl\n << \"\\t\\t\\t\" << endl;\n }\n\n file << \"\\t\\t\\t\" << endl;\n }\n else\n {\n file << \"\/>\" << endl;\n }\n\n if ( !driver.empty() )\n {\n file << \"\\t\\t\\t\" << endl;\n }\n else\n {\n if (!default_driver.empty())\n {\n file << \"\\t\\t\\t\" << endl;\n }\n }\n\n if (readonly)\n {\n file << \"\\t\\t\\t\" << endl;\n }\n\n file << \"\\t\\t<\/disk>\" << endl;\n }\n\n attrs.clear();\n\n \/\/ ------------------------------------------------------------------------\n \/\/ Context Device\n \/\/ ------------------------------------------------------------------------\n\n if ( vm->get_template_attribute(\"CONTEXT\",attrs) == 1 )\n {\n context = dynamic_cast(attrs[0]);\n target = context->vector_value(\"TARGET\");\n\n if ( !target.empty() )\n {\n file << \"\\t\\t\" << endl;\n file << \"\\t\\t\\t\" << endl;\n file << \"\\t\\t\\t\" << endl;\n file << \"\\t\\t\\t\" << endl;\n file << \"\\t\\t<\/disk>\" << endl;\n }\n else\n {\n vm->log(\"VMM\", Log::WARNING, \"Could not find target device to\"\n \" attach context, will continue without it.\");\n }\n }\n\n attrs.clear();\n\n \/\/ ------------------------------------------------------------------------\n \/\/ Network interfaces\n \/\/ ------------------------------------------------------------------------\n\n num = vm->get_template_attribute(\"NIC\",attrs);\n\n for(int i=0; i(attrs[i]);\n\n if ( nic == 0 )\n {\n continue;\n }\n\n network_id = nic->vector_value(\"NETWORK_ID\");\n mac = nic->vector_value(\"MAC\");\n target = nic->vector_value(\"TARGET\");\n script = nic->vector_value(\"SCRIPT\");\n model = nic->vector_value(\"MODEL\");\n\n bridge = \"one-pg-\";\n bridge.append(network_id);\n\n file << \"\\t\\t\" << endl;\n file << \"\\t\\t\\t\" << endl;\n\n if( !mac.empty() )\n {\n file << \"\\t\\t\\t\" << endl;\n }\n\n if( !target.empty() )\n {\n file << \"\\t\\t\\t\" << endl;\n }\n\n if( !script.empty() )\n {\n file << \"\\t\\t\\t