Exemplo n.º 1
0
/*
 *  Just like simpleGet but with an explicit port number
 */
static bool get(MprTestGroup *gp, cchar *host, int port, cchar *uri, int expectCode)
{
    MprHttp     *http;
    int         code;

    http = getHttp(gp);

    if (expectCode <= 0) {
        expectCode = 200;
    }
    if (host) {
        mprSetHttpDefaultHost(http, host);
    }
    if (port > 0) {
        mprSetHttpDefaultPort(http, getDefaultPort(gp) + port);
    }

    if (mprHttpRequest(http, "GET", uri, 0) < 0) {
        return 0;
    }

    code = mprGetHttpCode(http);
    assert(code == expectCode);

    if (code != expectCode) {
        mprLog(gp, 0, "get: HTTP response code %d, expected %d", code, expectCode);
        return 0;
    }

    assert(mprGetHttpError(http) != 0);
    assert(mprGetHttpContent(http) != 0);

    return 1;
}
Exemplo n.º 2
0
void SWProcess::checkInstanceAttributes(IPropertyTree *instanceNode, IPropertyTree *parent)
{
   assert(instanceNode);
   if (portIsRequired() && !instanceNode->hasProp("@port"))
   {
      int port = getDefaultPort();
      if (!port)
         throw MakeStringException(CfgEnvErrorCode::InvalidParams, "Miss port attribute in instance");
      instanceNode->addPropInt("@port", port);
   }

   StringBuffer xpath;
   xpath.clear().appendf("xs:element/xs:complexType/xs:sequence/xs:element[@name=\"%s\"]",m_instanceElemName.str());
   IPropertyTree * instanceSchemaNode = m_pSchema->queryPropTree(xpath.str());
   if (!instanceSchemaNode) return;

   bool needDirProp = false;
   Owned<IPropertyTreeIterator> attrIter = instanceSchemaNode->getElements("xs:complexType/xs:attribute");
   ForEach(*attrIter)
   {
      IPropertyTree * attr = &attrIter->query();
      const char *attrName = attr->queryProp("@name");
      if (!stricmp(attrName, "directory"))
      {
         needDirProp = true;
         continue;
      }

      const char *defaultValue = attr->queryProp("@default");
      if (!defaultValue) continue;
      xpath.clear().appendf("@%s", attrName);
      if (instanceNode->hasProp(xpath.str())) continue;
      const char *use = attr->queryProp("@use");
      if (!use || !stricmp(use, "required")  || !stricmp(use, "optional"))
      {
         StringBuffer sbDefaultValue;
         sbDefaultValue.clear().append(defaultValue);
         sbDefaultValue.replaceString("\\", "\\\\");
         instanceNode->addProp(xpath.str(), sbDefaultValue.str());
       }
   }

   if (needDirProp && !instanceNode->hasProp("@directory"))
   {
      const IProperties *props = m_envHelper->getEnvConfigOptions().getProperties();
      StringBuffer sb;
      sb.clear().appendf("%s/%s",
         props->queryProp("runtime"), parent->queryProp(XML_ATTR_NAME));
      instanceNode->addProp("@directory", sb.str());
   }
}
Exemplo n.º 3
0
Arquivo: uri.c Projeto: DavidQuan/http
/*
    Format a string URI from parts
 */
PUBLIC char *httpFormatUri(cchar *scheme, cchar *host, int port, cchar *path, cchar *reference, cchar *query, int flags)
{
    char    *uri;
    cchar   *portStr, *hostDelim, *portDelim, *pathDelim, *queryDelim, *referenceDelim, *cp;

    portDelim = "";
    portStr = "";
    hostDelim = "";

    if (flags & HTTP_COMPLETE_URI) {
        if (scheme == 0 || *scheme == '\0') {
            scheme = "http";
        }
        if (host == 0 || *host == '\0') {
            if (port || path || reference || query) {
                host = "localhost";
            }
        }
    } 
    if (scheme) {
        hostDelim = "://";
    }
    if (!host) {
        host = "";
    }
    if (mprIsIPv6(host)) {
        if (*host != '[') {
            host = sfmt("[%s]", host);
        } else if ((cp = scontains(host, "]:")) != 0) {
            port = 0;
        }
    } else if (schr(host, ':')) {
        port = 0;
    }
    if (port != 0 && port != getDefaultPort(scheme)) {
        portStr = itos(port);
        portDelim = ":";
    }
    if (scheme == 0) {
        scheme = "";
    }
    if (path && *path) {
        if (*host) {
            pathDelim = (*path == '/') ? "" :  "/";
        } else {
            pathDelim = "";
        }
    } else {
        pathDelim = path = "";
    }
    if (reference && *reference) {
        referenceDelim = "#";
    } else {
        referenceDelim = reference = "";
    }
    if (query && *query) {
        queryDelim = "?";
    } else {
        queryDelim = query = "";
    }
    if (*portDelim) {
        uri = sjoin(scheme, hostDelim, host, portDelim, portStr, pathDelim, path, referenceDelim, reference, 
            queryDelim, query, NULL);
    } else {
        uri = sjoin(scheme, hostDelim, host, pathDelim, path, referenceDelim, reference, queryDelim, query, NULL);
    }
    return uri;
}
Exemplo n.º 4
0
static void setup(MprTestGroup *gp)
{
    if (!simpleGet(gp, "/index.html", 0)) {
        mprError(gp, "Can't access web server at http://%s:%d/index.html", getDefaultHost(gp), getDefaultPort(gp));
        exit(5);
    }
}
Exemplo n.º 5
0
DBConfWindow::DBConfWindow(DBSettings* _dbs, QFrame* _parent)
: QFrame(_parent),
dbSettings(_dbs),
saved(false) {
  // First, check if the DBSettings object is valid.  This constructor does not
  // need a valid settings object to begin with (if this is the first run of
  // an app, the database settings have probably not been configured yet).
  if (!dbSettings) {
    dbSettings = new DBSettings("/tmp/dbc/dbsettings.ini", this);
    tempSettings = true;
  }
  else {
    tempSettings = false;
  }

  QFormLayout* form = new QFormLayout();

  // Database type widget
  dbTypeWidget = new QComboBox();
  // NOTE: Order of widgets matches order defined by DBSettings::DBType
  dbTypeWidget->addItem(tr("MySQL"));
  dbTypeWidget->addItem(tr("Microsoft SQL or Similar"));
  dbTypeWidget->addItem(tr("Postgre SQL"));
  dbTypeWidget->addItem(tr("SQLite v2"));
  dbTypeWidget->addItem(tr("SQLite v3"));
  // Have to connect after adding the widgets or segfaults happen (b/c)
  // the other widgets are not created yet when trying to enable/disable them
  // in dbTypeChanged().
  connect(dbTypeWidget, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), 
          this,         &DBConfWindow::dbTypeChanged);

  // Database host/IP widget
  dbHostWidget = new QLineEdit();
  dbHostWidget->setPlaceholderText(dbSettings->dbHost().toString());
  // TODO: check out potential for QValidator, confirm correct signal
  connect(dbHostWidget, &QLineEdit::textChanged,
          this,         &DBConfWindow::dbHostChanged);

  // Database port widget
  dbPortWidget = new QSpinBox();
  dbPortWidget->setMinimum(0);
  dbPortWidget->setMaximum(65535);

  // Database name widget
  dbNameWidget = new QLineEdit();
  dbNameWidget->setPlaceholderText(dbSettings->dbName());
  connect(dbNameWidget, &QLineEdit::textChanged,
          this,         &DBConfWindow::dbNameChanged);

  // Database user widget
  dbUserWidget = new QLineEdit();
  dbUserWidget->setPlaceholderText(dbSettings->dbUser());
  connect(dbUserWidget, &QLineEdit::textChanged,
          this,         &DBConfWindow::dbUserChanged);

  // Database password widget
  dbPassWidget = new QLineEdit();
  QString placeholder = "Set password...";
  if (dbSettings->dbPass() != "") {
    placeholder = "Change password...";
  }
  dbPassWidget->setPlaceholderText(placeholder);
  dbPassWidget->setEchoMode(QLineEdit::Password);
  connect(dbPassWidget, &QLineEdit::textChanged,
          this,         &DBConfWindow::dbPassChanged);

  showPassButton = new QPushButton("Show Password");
  showPassButton->setCheckable(true);
  connect(showPassButton, &QPushButton::clicked, this, &DBConfWindow::showPass);
  showPassButton->setChecked(false);

  dbPassWGroup = new QWidget();
  // dbPassWGroup->setContentsMargins(0, 0, 0, 0);
  QHBoxLayout* passLayout = new QHBoxLayout(dbPassWGroup);
  passLayout->setContentsMargins(0, 0, 0, 0);
  passLayout->addWidget(dbPassWidget);
  passLayout->addWidget(showPassButton);

  // Database file widget
  dbFileWidget = new QLineEdit();
  dbFileWidget->setPlaceholderText("File path");
  connect(dbFileWidget, &QLineEdit::textChanged,
          this,         &DBConfWindow::dbFileChanged);

  dbFileLocateButton = new QPushButton("Find File");
  connect(dbFileLocateButton, &QPushButton::clicked, 
          this,               &DBConfWindow::locateDBFile);

  dbFileWGroup = new QWidget();
  // dbFileWGroup->setContentsMargins(0, 0, 0, 0);
  QHBoxLayout* fileLayout = new QHBoxLayout(dbFileWGroup);
  fileLayout->setContentsMargins(0, 0, 0, 0);
  fileLayout->addWidget(dbFileWidget);
  fileLayout->addWidget(dbFileLocateButton);

  // Now that everything is created and pointers are validated, we can set
  // some defaults
  if (tempSettings) {
    dbTypeWidget->setCurrentIndex((int)DBSettings::MYSQL);
    dbPortWidget->setValue(getDefaultPort());
  }
  else {
    dbTypeWidget->setCurrentIndex((int)dbSettings->dbType());
    dbPortWidget->setValue(dbSettings->dbPort());
    // TODO: set dbFile also
  }
  dbTypeChanged((int)DBSettings::MYSQL);

  // Add the input widgets to the form layout
  form->addRow(tr("Database &Type:"),   dbTypeWidget);
  form->addRow(tr("IP/&Hostname:"),     dbHostWidget);
  form->addRow(tr("P&ort Number:"),     dbPortWidget);
  form->addRow(tr("Database &Name:"),   dbNameWidget);
  form->addRow(tr("Database &User:"******"User's &Password:"******"SQLite 2/3 &File:"), dbFileWGroup);

  // Create the "Do not show this window again" button
  // TODO: Make this checkbox actually hide the window in the future
  QCheckBox* hideWindowInFuture = new QCheckBox("Do not show this window at startup.");
  hideWindowInFuture->setChecked(false);

  // Create the test and save buttons
  QHBoxLayout* buttons = new QHBoxLayout();
  testButton = new QPushButton("Test Connection");
  connect(testButton, &QPushButton::pressed,
          this,       &DBConfWindow::testConnection);
  verifyTablesButton = new QPushButton("Verify Tables");
  connect(verifyTablesButton, &QPushButton::pressed,
          this,               &DBConfWindow::verifyTables);
  saveButton = new QPushButton("Save Settings");
  connect(saveButton, &QPushButton::pressed,
          this,       &DBConfWindow::saveDBSettings);
  buttons->addWidget(testButton);
  buttons->addWidget(verifyTablesButton);
  buttons->addWidget(saveButton);

  // Create the status message area
  statusBox = new QTextEdit();
  statusBox->setReadOnly(true);
  // statusBox->setStyleSheet("QTextArea {background-color: black;}");
  // statusBox->setTextBackgroundColor(Qt::black);
  // statusBox->setTextColor(Qt::green);
  statusBox->setVisible(false);
  statusScroll = statusBox->verticalScrollBar();

  // Add everything to the main layout
  QVBoxLayout* layout = new QVBoxLayout(this);
  layout->addLayout(form);

  QFrame* line = new QFrame();
  line->setFrameShape(QFrame::HLine);
  line->setFrameShadow(QFrame::Sunken);
  layout->addWidget(line);

  layout->addWidget(hideWindowInFuture);
  layout->addLayout(buttons);
  layout->addWidget(statusBox);

  show();
}