Example #1
0
bool ExecutionContext::obFlush() {
  assert(m_protectedLevel >= 0);
  if ((int)m_buffers.size() > m_protectedLevel) {
    std::list<OutputBuffer*>::const_iterator iter = m_buffers.end();
    OutputBuffer *last = *(--iter);
    const int flag = k_PHP_OUTPUT_HANDLER_START | k_PHP_OUTPUT_HANDLER_END;
    if (iter != m_buffers.begin()) {
      OutputBuffer *prev = *(--iter);
      if (last->handler.isNull()) {
        prev->oss.absorb(last->oss);
      } else {
        try {
          Variant tout = vm_call_user_func(
            last->handler, make_packed_array(last->oss.detach(), flag)
          );
          prev->oss.append(tout.toString());
          last->oss.clear();
        } catch (...) {
          prev->oss.absorb(last->oss);
        }
      }
      return true;
    }

    if (!last->handler.isNull()) {
      try {
        Variant tout = vm_call_user_func(
          last->handler, make_packed_array(last->oss.detach(), flag)
        );
        String sout = tout.toString();
        writeStdout(sout.data(), sout.size());
        last->oss.clear();
        return true;
      } catch (...) {}
    }

    writeStdout(last->oss.data(), last->oss.size());
    last->oss.clear();
    return true;
  }
  return false;
}
void ExecutionContext::write(const char *s, int len) {
  if (m_sb) {
    m_sb->append(s, len);
    if (m_out && m_out->chunk_size > 0) {
      if (m_sb->size() >= m_out->chunk_size) {
        obFlush();
      }
    }
  } else {
    writeStdout(s, len);
  }
  if (m_implicitFlush) flush();
}
Example #3
0
void ExecutionContext::flush() {
  if (m_buffers.empty()) {
    fflush(stdout);
  } else if (RuntimeOption::EnableEarlyFlush && m_protectedLevel &&
             (m_transport == nullptr ||
              (m_transport->getHTTPVersion() == "1.1" &&
               m_transport->getMethod() != Transport::Method::HEAD))) {
    StringBuffer &oss = m_buffers.front()->oss;
    if (!oss.empty()) {
      if (m_transport) {
        m_transport->sendRaw((void*)oss.data(), oss.size(), 200, false, true);
      } else {
        writeStdout(oss.data(), oss.size());
        fflush(stdout);
      }
      oss.clear();
    }
  }
}
Example #4
0
void Xmpp_client::receive_payload(QString s)
{
   // writeStdout("PARSE : " + s);
    //return;
    //std::cout << s.toStdString() << std::endl;
    // Do something with your received data here
    //writeStdout(s);

    QString t_log = "Xmpp_client::receive_payload : " + s;
    log->write(t_log.toAscii());
    log->write("\n");
    log->flush();


    QVariant json = QxtJSON::parse(s);



    if (json.toMap().contains("login") &&
            json.toMap().contains("password"))
    {
        QString user_login = json.toMap()["login"].toString();
        QString user_password = json.toMap()["password"].toString();


      /*  writeStdout("event : " + event);
        qDebug() << "usageid : " << usageid;
        qDebug() << "value : " << value;
        qDebug() << "contentid : " << contentid;
        */

        //$datetime=date('Y-m-d H:i:s',$dt);
        //QDateTime l_timestamp = QDateTime::currentDateTimeUtc();
        //QString timestamp = l_timestamp.toString("yyyy-MM-dd HH:mm:ss");

        bool res = true;
  ///      if (command == "add")
            //res = add_user(user_email, user_password, user_path);
         //   users[user_login] = user_password;

       /* if (command == "reload")
        {
            res = delete_user(user_email);
            res = add_user(user_email, user_password, user_path);
        }
*/
        //writeStdout("REQ SQL : " + req);


        /*query->exec("SELECT VERSION()");

        while (query->next())
        {
            QString name = query->value(0).toString();
            //qDebug() << name;
            writeStdout(name);
        }*/

            res = true;

        QString t_bool = res ? "ok" : "ko";
        writeStdout("{\"action\": \"terminate\", \"status\": \"" + t_bool + "\"}");
    }
    else
        writeStdout("{\"error\": \"parsing json\", \"status\": \"false\"}");



}
Example #5
0
void Nodemail::receive_payload(QString s)
{
   // m_mutex->lock();
    //qDebug() << "!!!!!! Email::sendEmail  : " << json;

     //writeStdout("PARSE : " + s);

    QVariant json = QxtJSON::parse(s);


    if (json.toMap().contains("exp")
            && json.toMap().contains("dest")
            && json.toMap().contains("object")
            && json.toMap().contains("body")
            )
    {
         QString exp = json.toMap()["exp"].toString();
         QString dest = json.toMap()["dest"].toString();
         QString object = json.toMap()["object"].toString();
         QString body = json.toMap()["body"].toString();

         //QString log = exp + " " + dest + " " + field3;

       // if (m_smtp) delete(m_smtp);
        if (m_message) delete(m_message);
       // m_smtp = NULL;
        m_message = NULL;


/*
        m_smtp = new QxtSmtp();

        connect(m_smtp, SIGNAL(mailFailed(int,int)), this, SLOT(failed()));
        connect(m_smtp, SIGNAL(mailSent(int)), this, SLOT(success()));
*/

        m_message = new QxtMailMessage();

        m_message->setSender(exp.toLatin1());
        m_message->setSubject(object.toLatin1());
        m_message->setBody(body.toLatin1());
        m_message->addRecipient(dest.toLatin1());

        QHash<QString,QString> headers;
        headers.insert("MIME-Version","1.0");
        headers.insert("Content-type","text/html; charset=utf-8");
        headers.insert("from", exp.toLatin1());
        m_message->setExtraHeaders(headers);

        /*
        m_smtp->connectToSecureHost(m_host.toAscii());
        m_smtp->setStartTlsDisabled(true);
        m_smtp->setUsername(m_username.toAscii());
        m_smtp->setPassword(m_password.toAscii());
*/

        m_smtp->send(*m_message);
    }
    else
        writeStdout("{\"error\": \"parsing json\", \"status\": \"false\"}");


}