void ModulePropertyWindow::updateParamteres()
{
    // updating parameters
    typedef Gtk::TreeModel::Children type_children;
    type_children children = m_refTreeModel->children();
    OSTRINGSTREAM strParams;
    Glib::ustring strName;
    for(type_children::iterator iter = children.begin(); iter!=children.end(); ++iter)
    {
        strName = Glib::ustring((*iter)[m_Columns.m_col_name]);
        if(strName == "Parameters")
        {
            for(type_children::iterator jter = (*iter).children().begin(); 
                jter!=(*iter).children().end(); ++jter)
            {
                Glib::ustring strItem = Glib::ustring((*jter)[m_Columns.m_col_name]);
                Glib::ustring strValue = Glib::ustring((*jter)[m_Columns.m_col_value]);
                for(int i=0; i<m_pModule->argumentCount(); i++) 
                {
                    if(strItem == m_pModule->getArgumentAt(i).getParam())
                    {   
                        if(strValue.size())
                        {
                            if(!m_pModule->getArgumentAt(i).isSwitch())                            
                                strParams<<"--"<<strItem<<" "<<strValue<<" ";
                            else
                            {
                                if(compareString(strValue.c_str(), "on" ))
                                    strParams<<"--"<<strItem<<" ";
                                else
                                    (*jter)[m_Columns.m_col_value] = "off";
                            }
                        }
                        else
                            if(m_pModule->getArgumentAt(i).isSwitch())                            
                                (*jter)[m_Columns.m_col_value] = "off";
                    }    

                    if((strItem == m_pModule->getArgumentAt(i).getParam()) &&
                        m_pModule->getArgumentAt(i).isRequired())
                    {    
                        if(!strValue.size())
                            (*jter)[m_Columns.m_col_color_item] = Gdk::Color("#BF0303");
                        else
                            (*jter)[m_Columns.m_col_color_item] = Gdk::Color("#000000");
                    }
                }
            }
            (*iter)[m_Columns.m_col_value] = strParams.str();
            updateModule(strName.c_str(), strParams.str().c_str());
            break;
        }
    }        
}
Exemple #2
0
//
// close()
//
void SSLOutputStream::close()
    throw(IOException)
{

  int ret = SSL_shutdown(_ssl);

  if (ret == 2) 
    ret = SSL_shutdown(_ssl);

  if (!ret) {

    int ssl_error = SSL_get_error(_ssl, ret);
    int error = ERR_get_error();
    
    OSTRINGSTREAM reason;
    reason << "SSLOutputStream::close error: ";
      
    switch(ssl_error) {
      case SSL_ERROR_NONE:
        reason << "SSL_ERROR_NONE reason: " << ERR_reason_error_string(error) << ends;
        throw IOException(reason.str().c_str());
        break;
      case SSL_ERROR_WANT_READ:
        reason << "SSL_ERROR_WANT_READ reason: " << ERR_reason_error_string(error) << ends;
        throw IOException(reason.str().c_str());
        break;
      case SSL_ERROR_WANT_WRITE:
        reason << "SSL_ERROR_WANT_WRITE reason: " << ERR_reason_error_string(error) << ends;
        throw IOException(reason.str().c_str());
        break;
      case SSL_ERROR_ZERO_RETURN:
        reason << "SSL_ERROR_ZERO_RETURN reason: " << ERR_reason_error_string(error) << ends;
        throw IOException(reason.str().c_str());
        break;
      case SSL_ERROR_WANT_CONNECT:
        reason << "SSL_ERROR_WANT_CONNECT reason: " << ERR_reason_error_string(error) << ends;
        throw IOException(reason.str().c_str());
        break;
      case SSL_ERROR_WANT_X509_LOOKUP:
        reason << "SSL_ERROR_WANT_X509_LOOKUP reason: " << ERR_reason_error_string(error) << ends;
        throw IOException(reason.str().c_str());
        break;
      case SSL_ERROR_SYSCALL:
        reason << "SSL_ERROR_SYSCALL reason: " << ERR_reason_error_string(error) << ends;
        throw IOException(reason.str().c_str());
        break;
      case SSL_ERROR_SSL:
        reason << "SSL_ERROR_SSL reason: " << ERR_reason_error_string(error) << ends;
        throw IOException(reason.str().c_str());
        break;
      default:
        reason << "unknown: " << ends;
        throw IOException(reason.str().c_str());
    }
  }


}
Exemple #3
0
bool ScriptLocalBroker::init(const char* szcmd, const char* szparam,
            const char* szhost, const char* szstdio,
            const char* szworkdir, const char* szenv )
{
    OSTRINGSTREAM strDevParam;
    std::string strParam;
    std::string strCmd;
    if(szcmd)
    {
        yarp::os::Bottle possiblePaths = parsePaths(yarp::os::NetworkBase::getEnvironment("PATH"));
        for (size_t i=0; i<possiblePaths.size(); ++i)
        {
            std::string guessString=possiblePaths.get(i).asString() + slash + szcmd;
            const char* guess=guessString.c_str();
            if (fileExists (guess))
            {
#if defined(_WIN32)
                strCmd = "\"" + std::string(guess) + "\"";
#else
                strCmd = guess;
#endif
                break;
            }
        }

    }
    if(strCmd=="")
        return false;
    if(szparam) strParam = szparam;
    strDevParam<<strCmd<<" "<<strParam;
    return LocalBroker::init(script.c_str(), strDevParam.str().c_str(),
                                szhost, szstdio, szworkdir, szenv);
     }
Exemple #4
0
void MessagesList::addWarning( const char* warning)
{
    OSTRINGSTREAM msg;
    msg<<"[WAR]:   "<<warning;
    Gtk::TreeModel::Row row = *(m_refListStore->append());
    row.set_value(0, Glib::ustring(msg.str()));
    row[m_Columns.m_col_color] = Gdk::Color("#FFF6C8");
    m_TreeView.scroll_to_row( m_refListStore->get_path(row));
}
Exemple #5
0
void MessagesList::addError(const char* error)
{
    OSTRINGSTREAM msg;
    msg<<"[ERR]:   "<<error;
    Gtk::TreeModel::Row row = *(m_refListStore->append());
    row.set_value(0, Glib::ustring(msg.str()));
    row[m_Columns.m_col_color] = Gdk::Color("#F9CCCA");
    m_TreeView.scroll_to_row( m_refListStore->get_path(row));
}
Exemple #6
0
bool ScriptYarprunBroker::init(const char* szcmd, const char* szparam,
            const char* szhost, const char* szstdio,
            const char* szworkdir, const char* szenv )
{

    OSTRINGSTREAM strDevParam;
    std::string strParam;
    std::string strCmd;
    if(szcmd)
    {
        std::string strHost;
        if(szhost[0] != '/')
            strHost = string("/") + string(szhost);
        else
            strHost = szhost;
        whichFile(strHost.c_str(), szcmd, strCmd);
    }
    if(szparam) strParam = szparam;
    strDevParam<<strCmd<<" "<<strParam;
    return YarpBroker::init(script.c_str(), strDevParam.str().c_str(),
                                szhost, szstdio, szworkdir, szenv);
}
Exemple #7
0
bool XmlAppSaver::serialXml(Application* app, const char* szFile)
{

    // updating application xml file name
    app->setXmlFile(szFile);

    ErrorLogger* logger  = ErrorLogger::Instance();

    TiXmlDocument doc; //(szFile);
    TiXmlElement * root = new TiXmlElement("application");
    doc.LinkEndChild( root );
    TiXmlElement * appName = new TiXmlElement("name");  //are all these NEW ok?
    appName->LinkEndChild(new TiXmlText(app->getName()));
    root->LinkEndChild(appName);


    if (strcmp(app->getDescription(), ""))
    {
        TiXmlElement * desc= new TiXmlElement( "description");
        desc->LinkEndChild(new TiXmlText( app->getDescription()));
        root->LinkEndChild(desc);
    }

    if(strcmp (app->getVersion(), ""))
    {
        TiXmlElement * vers= new TiXmlElement( "version");
        vers->LinkEndChild(new TiXmlText( app->getVersion()));
        root->LinkEndChild(vers);

    }

    /*
     * TODO: setting prefix of the main application is inactivated.
     * Check this should be supported in future or not!
     */
    /*
    if(strcmp (app->getPrefix(), ""))
        {
        TiXmlElement * prefix= new TiXmlElement( "prefix");
        prefix->LinkEndChild(new TiXmlText( app->getPrefix()));
        root->LinkEndChild(prefix);

    }
    */

    if(app->authorCount()>0)
    {
        TiXmlElement *auths=new TiXmlElement("authors");
        for (int i=0; i<app->authorCount(); i++)
        {
            //app->getAuthorAt(i);
            TiXmlElement *auth=new TiXmlElement("author");
            auth->SetAttribute("email", app->getAuthorAt(i).getEmail());
            auth->LinkEndChild(new TiXmlText(app->getAuthorAt(i).getName()));
            auths->LinkEndChild(auth);
        }
        root->LinkEndChild(auths);
    }

    // iterate over modules
    {
        int nModules=app->imoduleCount();
        for (int modCt=0; modCt<nModules; ++modCt)
        {
            TiXmlElement * newMod = new TiXmlElement("module");
            root->LinkEndChild(newMod); //add module element
            ModuleInterface curMod=app->getImoduleAt(modCt);

            TiXmlElement *name = new TiXmlElement("name");
            name->LinkEndChild(new TiXmlText(curMod.getName()));
            newMod->LinkEndChild(name);

            TiXmlElement *parameters=new TiXmlElement("parameters");
            parameters->LinkEndChild(new TiXmlText(curMod.getParam()));
            newMod->LinkEndChild(parameters);

            TiXmlElement *node = new TiXmlElement("node");
            node->LinkEndChild(new TiXmlText(curMod.getHost())); //is host the same as node?
            newMod->LinkEndChild(node);

            TiXmlElement *prefix=new TiXmlElement("prefix");
            prefix->LinkEndChild(new TiXmlText(curMod.getPrefix()));
            newMod->LinkEndChild(prefix);

            if(strcmp(curMod.getStdio(), ""))
            {
                TiXmlElement *stdio=new TiXmlElement("stdio");
                stdio->LinkEndChild(new TiXmlText(curMod.getStdio()));
                newMod->LinkEndChild(stdio);
            }

            if(strcmp(curMod.getWorkDir(), ""))
            {
                TiXmlElement *workdir=new TiXmlElement("workdir");
                workdir->LinkEndChild(new TiXmlText(curMod.getWorkDir()));
                newMod->LinkEndChild(workdir);
            }

            if(strcmp(curMod.getBroker(), ""))
            {
                TiXmlElement *broker=new TiXmlElement("deployer");
                broker->LinkEndChild(new TiXmlText(curMod.getBroker()));
                newMod->LinkEndChild(broker);
            }
            /*
            if(curMod.getRank()>0) //TODO check here how is rank handled
            {
                TiXmlElement *rank=new TiXmlElement("rank");
                char str[256];
                sprintf(str,"%d", curMod.getRank());
                rank->LinkEndChild(new TiXmlText(str));
                newMod->LinkEndChild(rank);
            }
            */

            GraphicModel model = curMod.getModelBase();
            OSTRINGSTREAM txt;
            if(model.points.size()>0)
            {
                txt<<"(Pos (x "<<model.points[0].x<<") "<<"(y "<<model.points[0].y<<"))";
                TiXmlElement *geometry=new TiXmlElement("geometry");
                geometry->LinkEndChild(new TiXmlText(txt.str().c_str()));
                newMod->LinkEndChild(geometry);
            }
        }

    }

    // iterate over embedded applications
    {
        int nApps=app->iapplicationCount();
        for (int appCt=0; appCt<nApps; ++appCt)
        {
            TiXmlElement *newApp  = new TiXmlElement("application");
            root->LinkEndChild(newApp); //add application element
            ApplicationInterface curApp=app->getIapplicationAt(appCt);

            TiXmlElement *name = new TiXmlElement("name");
            name->LinkEndChild(new TiXmlText(curApp.getName()));
            newApp->LinkEndChild(name);


            TiXmlElement *prefix=new TiXmlElement("prefix");
            prefix->LinkEndChild(new TiXmlText(curApp.getPrefix()));
            newApp->LinkEndChild(prefix);

            GraphicModel model = curApp.getModelBase();
            OSTRINGSTREAM txt;
            if(model.points.size()>0)
            {
                txt<<"(Pos (x "<<model.points[0].x<<") "<<"(y "<<model.points[0].y<<"))";
                TiXmlElement *geometry=new TiXmlElement("geometry");
                geometry->LinkEndChild(new TiXmlText(txt.str().c_str()));
                newApp->LinkEndChild(geometry);
            }

        }
    }

    // iterate over connections
    {
        int nConns=app->connectionCount();
        for (int connCt=0; connCt<nConns; ++connCt)
        {
            TiXmlElement *newConn=new TiXmlElement("connection");
            Connection curConn=app->getConnectionAt(connCt);

            if(strlen(curConn.getId()))
                newConn->SetAttribute("id", curConn.getId());

            if(curConn.isPersistent())
                newConn->SetAttribute("persist", "true");

            TiXmlElement *from = new TiXmlElement("from");
            if (curConn.isExternalFrom())
                from->SetAttribute("external", "true");
            from->LinkEndChild(new TiXmlText(curConn.from()));
            newConn->LinkEndChild(from);

            TiXmlElement *to = new TiXmlElement("to");
            if (curConn.isExternalTo())
                to->SetAttribute("external", "true");
            to->LinkEndChild(new TiXmlText(curConn.to()));
            newConn->LinkEndChild(to);

            TiXmlElement *protocol = new TiXmlElement("protocol");
            protocol->LinkEndChild(new TiXmlText(curConn.carrier()));
            newConn->LinkEndChild(protocol);

            GraphicModel model = curConn.getModelBase();
            OSTRINGSTREAM txt;
            if(model.points.size()>0)
            {
                txt<<"(Pos ";
                for(unsigned int i=0; i<model.points.size(); i++)
                    txt<<"((x "<<model.points[i].x<<") "<<"(y "<<model.points[i].y<<")) ";
                txt<<" )";
                TiXmlElement *geometry=new TiXmlElement("geometry");
                geometry->LinkEndChild(new TiXmlText(txt.str().c_str()));
                newConn->LinkEndChild(geometry);
            }

            root->LinkEndChild(newConn);
        }

    }

    // iterate over arbitrators
        for(int i=0; i<app->arbitratorCount(); i++)
        {
            Arbitrator& arb = app->getArbitratorAt(i);
            TiXmlElement *newArb = new TiXmlElement("arbitrator");

            TiXmlElement *port = new TiXmlElement("port");
            port->LinkEndChild(new TiXmlText(arb.getPort()));
            newArb->LinkEndChild(port);

            std::map<string, string> &rules = arb.getRuleMap();
            for(std::map<string, string>::iterator it=rules.begin(); it!=rules.end(); ++it)
            {
                TiXmlElement *rule = new TiXmlElement("rule");
                rule->SetAttribute("connection", it->first.c_str());
                rule->LinkEndChild(new TiXmlText(it->second.c_str()));
                newArb->LinkEndChild(rule);
            }

            GraphicModel model = arb.getModelBase();
            OSTRINGSTREAM txt;
            if(model.points.size()>0)
            {
                txt<<"(Pos ";
                for(unsigned int i=0; i<model.points.size(); i++)
                    txt<<"((x "<<model.points[i].x<<") "<<"(y "<<model.points[i].y<<")) ";
                txt<<" )";
                TiXmlElement *geometry=new TiXmlElement("geometry");
                geometry->LinkEndChild(new TiXmlText(txt.str().c_str()));
                newArb->LinkEndChild(geometry);
            }
            root->LinkEndChild(newArb);
        }


    bool ok=doc.SaveFile(app->getXmlFile());
    if (!ok)
    {

        OSTRINGSTREAM err;
        err<<"tinyXml error for file " << app->getXmlFile();
        if (doc.Error())
            err <<" at line " << doc.ErrorRow() << ", column " << doc.ErrorCol() << ": " << doc.ErrorDesc();
        logger->addError(err);
        err <<"\n";
        return false;
    }
    else return true;

}
Exemple #8
0
// Starts an SSL handshake on this connection.
void SSLSocket::startHandshake() 
  throw(IOException)
{
  Synchronized synchronized(_sync);

  // TODO: 
  if (_session != NULL)
    SSL_set_session(_ssl, _session->_session);
  

  // TODO: add some checks...
  if (!_use_client_mode)
    return;

  int ret = SSL_connect(_ssl);

  if (ret != 1) {
  
    int ssl_error = SSL_get_error(_ssl, ret);
    int error = ERR_get_error();
    
    OSTRINGSTREAM reason;
    reason << "SSLSocket::startHandshake connect error: ";
  
    switch (ssl_error) { 
      reason << "SSL_ERROR_NONE reason: " << ERR_reason_error_string(error) << ends;
      throw IOException(reason.str().c_str());
      break;
    case SSL_ERROR_WANT_READ:
      reason << "SSL_ERROR_WANT_READ reason: " << ERR_reason_error_string(error) << ends;
      throw IOException(reason.str().c_str());
      break;
    case SSL_ERROR_WANT_WRITE:
      reason << "SSL_ERROR_WANT_WRITE reason: " << ERR_reason_error_string(error) << ends;
      throw IOException(reason.str().c_str());
      break;
    case SSL_ERROR_ZERO_RETURN:
      reason << "SSL_ERROR_ZERO_RETURN reason: " << ERR_reason_error_string(error) << ends;
      throw IOException(reason.str().c_str());
      break;
    case SSL_ERROR_WANT_CONNECT:
      reason << "SSL_ERROR_WANT_CONNECT reason: " << ERR_reason_error_string(error) << ends;
      throw IOException(reason.str().c_str());
      break;
    case SSL_ERROR_WANT_X509_LOOKUP:
      reason << "SSL_ERROR_WANT_X509_LOOKUP reason: " << ERR_reason_error_string(error) << ends;
      throw IOException(reason.str().c_str());
      break;
    case SSL_ERROR_SYSCALL:
      reason << "SSL_ERROR_SYSCALL reason: " << ERR_reason_error_string(error) << ends;
      throw IOException(reason.str().c_str());
      break;
    case SSL_ERROR_SSL:
      reason << "SSL_ERROR_SSL reason: " << ERR_reason_error_string(error) << ends;
      throw IOException(reason.str().c_str());
      break;
    default:
      reason << "unknown: " << ends;
      throw IOException(reason.str().c_str());
    }
  }

//   if (!SSL_session_reused(_ssl))
//     cerr << " new session negotiated" << endl;

  //check_cert(ssl,host);

  
}
Exemple #9
0
ModuleModel::ModuleModel(ApplicationWindow* parentWnd, Module* mod, bool nested) : GroupModel()
{
    parentWindow = parentWnd;
    module = mod;
    bNested = nested;
    mod->setModel(this);

    // adding module name
    Glib::RefPtr<Goocanvas::TextModel> text = Goocanvas::TextModel::create(mod->getName());
#ifdef GLIBMM_PROPERTIES_ENABLED
    text->property_font() = FONT_DESC;
    text->property_alignment().set_value(Pango::ALIGN_CENTER);
#endif

    PangoLayout *layout = gtk_widget_create_pango_layout((GtkWidget*)parentWindow->gobj(), 
                            mod->getName());
    int text_w, text_h;
    PangoFontDescription *fontdesc = pango_font_description_from_string(FONT_DESC);
    pango_layout_set_font_description (layout, fontdesc);
    pango_layout_get_pixel_size (layout, &text_w, &text_h);

    //double w = strlen(mod->getName()) * FONT_WIDTH;
    double w = text_w + TEXT_MARGINE*2;

    int nInputs = module->inputCount();
    int nPorts = MAX(nInputs, module->outputCount());
    double h = nPorts*PORT_SIZE + 
              (nPorts-1)*PORT_GAP + 2*PORT_GAP;
    h = (h<MIN_HEIGHT) ? MIN_HEIGHT : h;

    
    shadowRect = Goocanvas::RectModel::create(3, 3, w, h);
    shadowRect->property_line_width().set_value(1.5) ;
    shadowRect->property_radius_x().set_value(3.0) ;
    shadowRect->property_radius_y().set_value(3.0) ;
    shadowRect->property_stroke_color().set_value("gray");
    shadowRect->property_fill_color().set_value("gray");    
    this->add_child(shadowRect);    

    mainRect = Goocanvas::RectModel::create(0,0, w, h);
    mainRect->property_line_width().set_value(1.2); 
    mainRect->property_radius_x().set_value(3.0) ;
    mainRect->property_radius_y().set_value(3.0) ;
    mainRect->property_stroke_color().set_value("DodgerBlue3");
    mainRect->property_fill_color().set_value(MODULE_COLOR);
    
    //if(module->owner() != parentWindow->manager.getKnowledgeBase()->getApplication())
    if(bNested)
    {
        GooCanvasLineDash *dash = goo_canvas_line_dash_new (2, 3.0, 3.0);
        g_object_set(mainRect->gobj(), "line-dash", dash, NULL);
    }
    this->add_child(mainRect);

    text->property_x().set_value(TEXT_MARGINE);
    text->property_y().set_value(h/2.0 - text_h/2.0);
    this->add_child(text);

    double top = (h - (nInputs*PORT_SIZE+(nInputs-1)*PORT_GAP))/2.0;
    for(int i=0; i<module->inputCount(); i++)
    {
        Glib::RefPtr<InternalPortModel> port = InternalPortModel::create(parentWindow, INPUTD, 
                                                        &module->getInputAt(i));
        port->set_property("x", -15);
        port->set_property("y", top +i*PORT_SIZE + i*PORT_GAP);
        this->add_child(port);
        // adding module name
        OSTRINGSTREAM str;
        str<<"I"<<i+1;
        Glib::RefPtr<Goocanvas::TextModel> text = Goocanvas::TextModel::create(str.str().c_str());
#ifdef GLIBMM_PROPERTIES_ENABLED
        text->property_font() = "Monospace 9";
        text->property_alignment().set_value(Pango::ALIGN_LEFT);
        text->property_x().set_value(8);
        text->property_y().set_value(top +i*PORT_SIZE + i*PORT_GAP);
#endif
        this->add_child(text);
    }

    top = (h - (module->outputCount()*PORT_SIZE+(module->outputCount()-1)*PORT_GAP))/2.0;  
    for(int i=0; i<module->outputCount(); i++)
    {
        Glib::RefPtr<InternalPortModel> port = InternalPortModel::create(parentWindow, OUTPUTD, 
                                                         &module->getOutputAt(i));
        port->set_property("x", w);
        port->set_property("y", top +i*PORT_SIZE + i*PORT_GAP);
        this->add_child(port);
        OSTRINGSTREAM str;
        str<<"O"<<i+1;
        Glib::RefPtr<Goocanvas::TextModel> text = Goocanvas::TextModel::create(str.str().c_str());
#ifdef GLIBMM_PROPERTIES_ENABLED
        text->property_font() = "Monospace 9";
        text->property_alignment().set_value(Pango::ALIGN_RIGHT);
        text->property_x().set_value(w-strlen(str.str().c_str())*10);
        text->property_y().set_value(top +i*PORT_SIZE + i*PORT_GAP);
#endif
        this->add_child(text);
    }
    
    width  = w;
    height = h;
}
bool BinaryExpParser::checkExpression(std::string& strexp)
{
    ErrorLogger* logger = ErrorLogger::Instance();

    if(std::count(strexp.begin(), strexp.end(), '(') != 
        std::count(strexp.begin(), strexp.end(), ')'))
    {
        logger->addError("Incorrect expression format! (parentheses do not match)");
        return false;
    }
    if(std::count(strexp.begin(), strexp.end(), IMPLY) != 1 )
    {
        logger->addError("Incorrect expression format! (no implication ':' found)");
        return false;
    }

    // erassing all the sapces
    strexp.erase(std::remove_if(strexp.begin(), strexp.end(), ::isspace), strexp.end());
    if(!strexp.size())
    {
       logger->addError("Empty expression!");
       return false;
    }

    // making a copy of strexp and checking more
    string  dummy = strexp;
    // removing all pranteses 
    dummy.erase(std::remove_if(dummy.begin(), dummy.end(), isParentheses), dummy.end());
    leftOpr = dummy.substr(0, dummy.find(IMPLY)); 
    if(!leftOpr.size())
    {
        logger->addError("Missing operand before ':'");
        return false; 
    }
    if(dummy.find(IMPLY) == (dummy.size()-1))
    {
        logger->addError("Missing operands after ':'");
        return false; 
    }

    dummy.erase(0, dummy.find(IMPLY)+1);
    if(dummy.find(leftOpr) != string::npos)
    {
        std::string msg;
        msg = "recursive assignment of operand '" + leftOpr + "'";
        logger->addError(msg.c_str());
        return false;       
    }

    // checking '~'
    size_t n = dummy.find(EXPNOT);
    while(n != string::npos)
    { 
        OSTRINGSTREAM msg;        
        bool bError = ((n+1) == dummy.length()); // empty operand after ~
        if((n+1) < dummy.length())
        {
            bError |= (dummy[n+1] == EXPAND);        // operator & after ~
            bError |= (dummy[n+1] == EXPOR);         // operand | after ~
        }            
        if(n != 0)
            bError |= (dummy[n-1] != EXPAND) && (dummy[n-1] != EXPOR);  // an operand before ~
        if(bError)
        {
            msg<<"Incorrect expression format of '~' at "<<(int)n;
            logger->addError(msg.str().c_str());
            return false;
        }
        n = dummy.find(EXPNOT, n+1);
    }

    // checking '| &'
    n = dummy.find_first_of("&|");
    while(n != string::npos)
    {
        OSTRINGSTREAM msg;        
        bool bError = ((n+1) == dummy.length());    // empty operand after & or |
        if((n+1) < dummy.length())
        {
            bError |= (dummy[n+1] == EXPAND);        // operator & after & or |
            bError |= (dummy[n+1] == EXPOR);         // operand | after & or |
        }            
        bError |= (n == 0);                      // empty operand before & or |
        if(n != 0)
        {
            bError |= (dummy[n-1] == EXPAND);        // operator & before & or |
            bError |= (dummy[n-1] == EXPOR);         // operand | before & or |
            bError |= (dummy[n-1] == EXPOR);         // operand ~ before & or |
        } 
        if(bError)
        {
            msg<<"Incorrect expression format of '&' or '|' at "<<(int)n;
            logger->addError(msg.str().c_str());
            return false;
        }
        n = dummy.find_first_of("&|", n+1);
    }

    // at the end
    strexp.erase(0, strexp.find(IMPLY)+1);
    return true;
}
Exemple #11
0
//
// write()
//
ssize_t
SSLOutputStream::write(const unsigned char* b, size_t size, size_t off, size_t len)
    throw(IOException, IllegalBlockingModeException, IndexOutOfBoundsException)
{
    // Comprueba los limites del array
    if (off + len > size)
    {
        throw IndexOutOfBoundsException("Index out of bounds");
    }

    // Delega la operacion en el canal, si este existe
    if (_channel)
    {
        SocketChannel* ch = dynamic_cast<SocketChannel*>(_channel);
        return ch->write(b+off, len);
    }

    
    //SSL_set_connect_state(_ssl);
    //SSL_set_mode(_ssl,SSL_MODE_ENABLE_PARTIAL_WRITE);


    //ssize_t n = ::SSL_write(_ssl, (void*) (b + off), len);
    // Temporal workaround: 2 SSL_write per operation in order to force flush
    ssize_t n = ::SSL_write(_ssl, (void*) (b + off), len-1);
    n += ::SSL_write(_ssl, (void*) (b + off + len - 1), 1);

    if (n <= 0)
    {
      int ssl_error = SSL_get_error(_ssl, n);
      int error = ERR_get_error();
      
      OSTRINGSTREAM reason;
      reason << "SSLOutputStream::write error: ";

      switch(ssl_error) {
      case SSL_ERROR_NONE:
        reason << "SSL_ERROR_NONE reason: " << ERR_reason_error_string(error) << ends;
        throw IOException(reason.str().c_str());
        break;
      case SSL_ERROR_WANT_READ:
        reason << "SSL_ERROR_WANT_READ reason: " << ERR_reason_error_string(error) << ends;
        throw IOException(reason.str().c_str());
        break;
      case SSL_ERROR_WANT_WRITE:
        reason << "SSL_ERROR_WANT_WRITE reason: " << ERR_reason_error_string(error) << ends;
        throw IOException(reason.str().c_str());
        break;
      case SSL_ERROR_ZERO_RETURN:
        reason << "SSL_ERROR_ZERO_RETURN reason: " << ERR_reason_error_string(error) << ends;
        throw IOException(reason.str().c_str());
        break;
      case SSL_ERROR_WANT_CONNECT:
        reason << "SSL_ERROR_WANT_CONNECT reason: " << ERR_reason_error_string(error) << ends;
        throw IOException(reason.str().c_str());
        break;
      case SSL_ERROR_WANT_X509_LOOKUP:
        reason << "SSL_ERROR_WANT_X509_LOOKUP reason: " << ERR_reason_error_string(error) << ends;
        throw IOException(reason.str().c_str());
        break;
      case SSL_ERROR_SYSCALL:
        reason << "SSL_ERROR_SYSCALL reason: " << ERR_reason_error_string(error) << ends;
        throw IOException(reason.str().c_str());
        break;
      case SSL_ERROR_SSL:
        reason << "SSL_ERROR_SSL reason: " << ERR_reason_error_string(error) << ends;
        throw IOException(reason.str().c_str());
        break;
      default:
        reason << "unknown: " << ends;
        throw IOException(reason.str().c_str());
      }

    }

    
    //BIO_flush(_sbio);
    return n;
}
Exemple #12
0
void ErrorLogger::addError(OSTRINGSTREAM &stream) {
    addError(stream.str());
}
Exemple #13
0
void ErrorLogger::addWarning(OSTRINGSTREAM &stream) {
    addWarning(stream.str());
}