bool ServerThread::verify(const QString & name, const QString & password)
{
    if(!database->existsUser(name.toStdString()))
    {
        return false;
    }
    auto info = database->getUserByName(name.toStdString());

    QString s(password);
    s = s + info.getSalt();
    unsigned char hash[32];
    sha2((unsigned char*) s.toUtf8().constData(), s.length(), hash, 0);
    char * base = getAscii85((char*) hash, 32);
    QString hashed(base);
    free(base);
    if(hashed != info.getPass())
    {
        return false;
    }

    return true;


}
예제 #2
0
파일: toxme.cpp 프로젝트: 1KoT1/qTox
QString Toxme::createAddress(ExecCode &code, QString server, ToxId id, QString address,
                             bool keepPrivate, QString bio)
{
    int privacy = keepPrivate ? 0 : 2;
    // JSON injection ?
    bio.replace('\\',"\\\\");
    bio.replace('"',"\"");

    address.replace('\\',"\\\\");
    address.replace('"',"\"");

    bio = bio.trimmed();
    address = address.trimmed();
    server = server.trimmed();
    if (!server.contains("://"))
        server = "https://" + server;

    const QString payload{"{\"tox_id\":\""+id.toString()+"\","
                          "\"name\":\""+address+"\","
                          "\"privacy\":"+QString().setNum(privacy)+","
                          "\"bio\":\""+bio+"\","
                          "\"timestamp\":"+QString().setNum(time(0))+"}"};

    qDebug() << payload;
    QString pubkeyUrl = server + "/pk";
    QString apiUrl =  server + "/api";
    QNetworkReply::NetworkError error = QNetworkReply::NoError;
    QByteArray response = makeJsonRequest(apiUrl, prepareEncryptedJson(pubkeyUrl, 1, payload), error);
    qDebug() << response;

    code = extractError(response);
    if ((code != Registered && code != Updated) || error != QNetworkReply::NoError)
        return QString();

    return getPass(response, code);
}
    /// Add a reference to render an object.
    ///
    /// \param object Object to queue for rendering.
    /// \param transform Object transformation.
    /// \param pass Render pass id.
    /// \param optimistic Can we render in an optimistic manner? (default: true)
    void addObject(const Object &object, const mat4 &transform, unsigned pass = 0, bool optimistic = true,
        const AnimationState *state = NULL)
    {
      ObjectGroup *grp = object.getGroup();      

      ObjectReference &vv = getPass(pass).emplace_back(object, m_screen_transform, m_light_transform,
          transform, state);

      if(grp)
      {
        if(optimistic)
        {
          grp->addObjectReference(m_frame_count, vv);
        }
        else
        {
          vv.setOptimistic(false);
        }
      }
      else
      {
        vv.setOptimistic(true);
      }
    }
예제 #4
0
ConnectionProperties::ConnectionProperties(Database *database, MainWin *mainwin)
{
    QPushButton *pBOK;
    QPushButton *pBCancel;
    QWidget *layoutWidget;
    QVBoxLayout *verticalLayout;

    setWindowFlags(Qt::FramelessWindowHint);
    this->setAttribute(Qt::WA_DeleteOnClose);
    resize(256, 288);
    setModal(true);
    setParent(mainwin);
    setWindowFlags(Qt::Window);
    setWindowModality(Qt::WindowModal);
    pBOK = new QPushButton(this);
    pBOK->setObjectName(QString::fromUtf8("pBOK"));
    pBOK->setAutoDefault(false);
    pBOK->setGeometry(QRect(30, 250, 75, 23));
    QFont font;
    font.setFamily(QString::fromUtf8("Verdana"));
    pBOK->setFont(font);
    pBCancel = new QPushButton(this);
    pBCancel->setObjectName(QString::fromUtf8("pBCancel"));
    pBCancel->setGeometry(QRect(140, 250, 75, 23));
    pBCancel->setFont(font);
    pBCancel->setAutoDefault(false);
    setDb(new QLineEdit(this));
    getDb()->setObjectName(QString::fromUtf8("lEDb"));
    getDb()->setGeometry(QRect(100, 90, 133, 20));
    getDb()->setFont(font);
    getDb()->setAutoFillBackground(true);
    getDb()->setInputMethodHints(Qt::ImhNone);
    setSrv(new QLineEdit(this));
    getSrv()->setObjectName(QString::fromUtf8("lESrv"));
    getSrv()->setGeometry(QRect(100, 47, 133, 20));
    getSrv()->setFont(font);
    setPort(new QLineEdit(this));
    getPort()->setObjectName(QString::fromUtf8("lEPort"));
    getPort()->setGeometry(QRect(100, 130, 133, 20));
    getPort()->setFont(font);
    getPort()->setInputMethodHints(Qt::ImhFormattedNumbersOnly);
    getPort()->setInputMask("00000");
    setUser(new QLineEdit(this));
    getUser()->setObjectName(QString::fromUtf8("lEUser"));
    getUser()->setGeometry(QRect(100, 171, 133, 20));
    getUser()->setFont(font);
    setPass(new QLineEdit(this));
    getPass()->setObjectName(QString::fromUtf8("lEPass"));
    getPass()->setGeometry(QRect(100, 213, 133, 20));
    getPass()->setEchoMode(QLineEdit::Password);
    getPass()->setFont(font);
    layoutWidget = new QWidget(this);
    layoutWidget->setObjectName(QString::fromUtf8("layoutWidget"));
    layoutWidget->setGeometry(QRect(20, 40, 71, 201));
    verticalLayout = new QVBoxLayout(layoutWidget);
    verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
    verticalLayout->setContentsMargins(0, 0, 0, 0);
    lSrv = new QLabel(layoutWidget);
    lSrv->setObjectName(QString::fromUtf8("lSrv"));
    lSrv->setFont(font);
    verticalLayout->addWidget(lSrv);
    lDb = new QLabel(layoutWidget);
    lDb->setObjectName(QString::fromUtf8("lDb"));
    lDb->setFont(font);
    verticalLayout->addWidget(lDb);
    lPort = new QLabel(layoutWidget);
    lPort->setObjectName(QString::fromUtf8("lPort"));
    lPort->setFont(font);
    verticalLayout->addWidget(lPort);
    lUser = new QLabel(layoutWidget);
    lUser->setObjectName(QString::fromUtf8("lUser"));
    lUser->setFont(font);
    verticalLayout->addWidget(lUser);
    lPass = new QLabel(layoutWidget);
    lPass->setObjectName(QString::fromUtf8("lPass"));
    lPass->setFont(font);
    verticalLayout->addWidget(lPass);
    lTitle = new QLabel(this);
    lTitle->setObjectName(QString::fromUtf8("lTitle"));
    lTitle->setGeometry(QRect(20, 10, 211, 21));
    lTitle->setAlignment(Qt::AlignHCenter);
    QFont font1;
    font1.setFamily(QString::fromUtf8("Verdana"));
    font1.setPointSize(14);
    lTitle->setFont(font1);
    QWidget::setTabOrder(getSrv(), getDb());
    QWidget::setTabOrder(getDb(), getPort());
    QWidget::setTabOrder(getPort(), getUser());
    QWidget::setTabOrder(getUser(), getPass());
    QWidget::setTabOrder(getPass(), pBOK);
    QWidget::setTabOrder(pBOK, pBCancel);
    QObject::connect(pBCancel, SIGNAL(clicked()), this, SLOT(close()));
    QObject::connect(pBOK, SIGNAL(clicked()), this, SLOT(okslot()));
    QObject::connect(this, SIGNAL(oksignal(QString,qint32,QString,QString,QString)),
                     mainwin, SLOT(newDatabase(QString,qint32,QString,QString,QString)));
    QObject::connect(getSrv(), SIGNAL(returnPressed()), getDb(), SLOT(setFocus()));
    QObject::connect(getDb(), SIGNAL(returnPressed()), getPort(), SLOT(setFocus()));
    QObject::connect(getPort(), SIGNAL(returnPressed()), getUser(), SLOT(setFocus()));
    QObject::connect(getUser(), SIGNAL(returnPressed()), getPass(), SLOT(setFocus()));
    QObject::connect(getPass(), SIGNAL(returnPressed()), pBOK, SLOT(setFocus()));
    setWindowTitle(QApplication::translate("Connection", "Connection", 0, QApplication::UnicodeUTF8));
    pBOK->setText(QApplication::translate("Connection", "OK", 0, QApplication::UnicodeUTF8));
    pBCancel->setText(QApplication::translate("Connection", "Cancel", 0, QApplication::UnicodeUTF8));
    if(!database->getDatabaseStatus()) {
        getSrv()->setText(database->getHost());
        getDb()->setText(database->getName());
        getPort()->setText(database->getPort());
        getUser()->setText(database->getUser());
        getPass()->setText(database->getPassword());
    }
    else {
        QSqlDatabase database_connection = QSqlDatabase::database(QString("base").append(QString::number(database->getId())));
        getSrv()->setText(database_connection.hostName());
        getDb()->setText(database->getName());
        getPort()->setText(QString::number(database_connection.port()));
        getUser()->setText(database_connection.userName());
        getPass()->setText(database_connection.password());
    }
    lTitle->setText(QApplication::translate("Connection", "Connection", 0, QApplication::UnicodeUTF8));
    lSrv->setText(QApplication::translate("Connection", "Server", 0, QApplication::UnicodeUTF8));
    lDb->setText(QApplication::translate("Connection", "Database", 0, QApplication::UnicodeUTF8));
    lPort->setText(QApplication::translate("Connection", "Port", 0, QApplication::UnicodeUTF8));
    lUser->setText(QApplication::translate("Connection", "Username", 0, QApplication::UnicodeUTF8));
    lPass->setText(QApplication::translate("Connection", "Password", 0, QApplication::UnicodeUTF8));
}
예제 #5
0
파일: dlgPass.cpp 프로젝트: monthero/nau
void 
DlgPass::OnProcessPGChange( wxPropertyGridEvent& e)
{
	Pass *p = getPass();

	wxString name,subname,value;
	std::string mat,lib;
	name = e.GetPropertyName();
	int index;
	index = e.GetPropertyValue().GetInteger();

	if (name == wxT("Camera")) {
		value = m_pgCamList.GetLabel(index);
		p->setCamera(std::string(value.mb_str()));	
	}
	else if (name == wxT("Viewport")) {
		if (index == 0)
			p->setViewport(RENDERMANAGER->getCamera(p->getCameraName())->getViewport());
		else {
			value = m_pgViewportList.GetLabel(index-1);
			p->setViewport(RENDERMANAGER->getViewport(std::string(value.mb_str())));
		}
	}
	else if (name == wxT("Use Render Target")) {
		p->enableRenderTarget(0 != e.GetPropertyValue().GetBool());
	}
	else if (name == wxT("Render Target")) {
		value = e.GetPropertyValue().GetString();
		if (value == wxT("None")) {
			p->setRenderTarget(NULL);
			m_PG->SetPropertyValue(wxT("Viewport"),wxT("From Camera"));
			m_PG->EnableProperty(wxT("Viewport"));
		}
		else {
			m_PG->SetPropertyValue(wxT("Viewport"), wxT("From Render Target"));
			m_PG->DisableProperty(wxT("Viewport"));
			p->setRenderTarget(RESOURCEMANAGER->getRenderTarget(std::string(value.mb_str())));
		}
	}
	//else if (name == wxT("Clear Color")) 
	//	p->setPropb(Pass::COLOR_CLEAR, (0 != e.GetPropertyValue().GetBool()));
	//else if (name == wxT("Clear Depth"))
	//	p->setPropb(Pass::DEPTH_CLEAR, (0 != e.GetPropertyValue().GetBool()));
	
	else if (name.substr(0,6) == wxT("Lights")) {

		subname = name.substr(7,std::string::npos);
		bool b = 0 != e.GetPropertyValue().GetBool();
		if (b)
			p->addLight(std::string(subname.mb_str()));
		else
			p->removeLight(std::string(subname.mb_str()));
	}
	else if (name.substr(0,6) == wxT("Scenes")) {

		subname = name.substr(7,std::string::npos);
		bool b = 0 != e.GetPropertyValue().GetBool();
		if (b)
			p->addScene(std::string(subname.mb_str()));
		else
			p->removeScene(std::string(subname.mb_str()));
	}
	else if (name.substr(0,13) == wxT("Material Maps")) { // Material Maps

		subname = name.substr(14, std::string::npos);
		if (subname == wxT("*"))
			value = m_pgMaterialListPlus.GetLabel(e.GetPropertyValue().GetInteger());
		else
			value = m_pgMaterialList.GetLabel(e.GetPropertyValue().GetInteger());
		mat = std::string(value.AfterLast(':').mb_str());
		lib = std::string(value.BeforeFirst(':').mb_str());

		if (subname == wxT("*")) {
			if (mat == "*") {
				p->remapAll(lib);
				updateMats(p);
			}
			else if (value != wxT("None")) {
				p->remapAll(lib,mat);
				updateMats(p);
			}
		}
		else
			p->remapMaterial(std::string(subname.c_str()),lib,mat);
	}
	else
		PropertyManager::updateProp(m_PG, name.ToStdString(), Pass::Attribs, (AttributeValues *)p);

	//else if (name.substr(0,10) == wxT("Parameters")) {

	//	subname = name.substr(11, std::string::npos);
	//	p->setParam(std::string(subname.mb_str()), (float)(e.GetPropertyValue().GetDouble()));
	//
	//} 
}
예제 #6
0
파일: dlgPass.cpp 프로젝트: monthero/nau
void 
DlgPass::updatePipelines() {

	std::vector<std::string> *pips = RENDERMANAGER->getPipelineNames();
	std::vector<std::string>::iterator iter;

	//wxString sel = m_PipelineList->GetStringSelection();
	wxString sel = wxString(RENDERMANAGER->getActivePipelineName());
	m_PipelineList->Clear();
	for (iter = pips->begin(); iter != pips->end(); ++iter)
		m_PipelineList->Append(wxString(iter->c_str()));

	delete pips;

	if (! m_PipelineList->SetStringSelection(sel)) 
		m_PipelineList->SetSelection(0);

	sel = m_PipelineList->GetStringSelection();
	m_ActivePipText->SetLabelText(sel);
	std::string pipName = std::string(sel.mb_str());

	Pipeline *pip = RENDERMANAGER->getPipeline(pipName);
	std::vector<std::string> *passes = pip->getPassNames();

	sel = m_PassList->GetStringSelection();
	m_PassList->Clear();

	for (iter = passes->begin(); iter != passes->end(); ++iter)
		m_PassList->Append(wxString(iter->c_str()));

	delete passes;

	if (! m_PassList->SetStringSelection(sel))
		m_PassList->SetSelection(0);
		
	Pass *p = getPass();


	m_PG->ClearPage(0);

		m_PG->Append(new wxStringProperty(wxT("Class"), wxPG_LABEL, wxT("")));
		m_PG->DisableProperty(wxT("Class"));

		m_pgCamList.Add(wxT("dummy"));
		m_pgPropCam = new wxEnumProperty(wxT("Camera"),wxPG_LABEL,m_pgCamList);
		m_PG->Append(m_pgPropCam);
		
		m_pgViewportList.Add(wxT("From Camera"));
		m_pgPropViewport = new wxEnumProperty(wxT("Viewport"),wxPG_LABEL,m_pgViewportList);
		m_PG->Append(m_pgPropViewport);

		m_PG->Append(new wxBoolProperty(wxT("Use Render Target"), wxPG_LABEL, true));
		m_PG->SetPropertyAttribute( wxT("Use Render Target"),
                              wxPG_BOOL_USE_CHECKBOX,
                              true );

		m_pgRenderTargetList.Add(wxT("None"));
		m_pgPropRenderTarget = new wxEnumProperty(wxT("Render Target"),wxPG_LABEL,m_pgRenderTargetList);
		m_PG->Append(m_pgPropRenderTarget);

		//m_PG->Append(new wxBoolProperty(wxT("Clear Color"), wxPG_LABEL, true));
		//m_PG->SetPropertyAttribute( wxT("Clear Color"),
  //                            wxPG_BOOL_USE_CHECKBOX,
  //                            true );
		//m_PG->Append(new wxBoolProperty(wxT("Clear Depth"), wxPG_LABEL, true));
		//m_PG->SetPropertyAttribute( wxT("Clear Depth"),
  //                            wxPG_BOOL_USE_CHECKBOX,
  //                            true );

	updateLists(p);
	setupGrid();
	updateProperties(p) ;
}
예제 #7
0
static int cb_exec(struct ast_channel *chan, void *data)
{
	int res=0, i=0, pos=0, optLen=0;
	struct userkeyin dtmfinput;
	struct roomdetails dtmfmatch;
	char confno[AST_MAX_EXTENSION] = "";
	char *notdata, *info;

	if (ast_strlen_zero(data)){
		notdata = "";
	} else {
		notdata = data;
	}
	
	info = ast_strdupa(notdata);

	if (info){
		char *tmp = strsep(&info, ",");
		ast_copy_string(confno, tmp, sizeof(confno));
	}

	if (!ast_strlen_zero(confno)){
		strcpy(dtmfinput.inroom, confno);
	} else {
	strcpy(dtmfinput.inroom, "");
	}

	strcpy(dtmfinput.inpass, "");

	/*
	if (!DBOpts) {
	    strcpy(dtmfmatch.roomtype, OptsUsr);
	}
	*/
	

	
	res = getConf(chan, dtmfinput, &dtmfmatch);
	ast_log(LOG_NOTICE, "getConf: %i\n", res);
	if (res == -1) {
		return -1;
	} else {
		if(res==1){
			res = getPass(chan, dtmfinput, &dtmfmatch);
			ast_log(LOG_NOTICE, "getPass: %i\n", res);
		} else {

			optLen = strlen(dtmfmatch.uFlags);
			for (pos = 0; pos < optLen; pos++){
				if ((dtmfmatch.uFlags[pos] != 'm') &&
				    (dtmfmatch.uFlags[pos] != 'w') &&
				    (dtmfmatch.uFlags[pos] != 'l') ) {
					dtmfmatch.roomtype[i++] = dtmfmatch.uFlags[pos];
					dtmfmatch.roomtype[i] = '\0';
				}
			}

			if(strchr(dtmfmatch.aFlags, 'r'))
				strcat(dtmfmatch.roomtype, "r");

			ast_log(LOG_NOTICE, "No User or Admin passwords\n");
			res = 1;
		}
	}
	if(res==1 || res==2 ){
		res = checkMax(chan, &dtmfmatch);
	ast_log(LOG_NOTICE, "checkMax: %i\n", res);}
	if(res==1){
		res = enterConf(chan, &dtmfmatch);
	ast_log(LOG_NOTICE, "enterConf: %i\n", res);}

	return res;
}
예제 #8
0
파일: help.cpp 프로젝트: xurui25/cocos2d-x-
bool Help::init() {
	if (!Layer::init()) {
		return false;
	}

	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();


	//背景精灵
	if (getPass() == 1) {
		auto bg1 = Sprite::create("help_bg1.jpg");
		//为适应屏幕进行缩放
		bg1->setScaleX((float)visibleSize.width / (float)bg1->getContentSize().width);
		bg1->setScaleY((float)visibleSize.height / (float)bg1->getContentSize().height);
		bg1->setPosition(Vec2(origin.x + visibleSize.width / 2, 0));
		bg1->setAnchorPoint(Vec2(0.5, 0));
		bg1->setTag(101);
		this->addChild(bg1, 0);
	}
	else if (getPass() == 2) {
		auto bg1 = Sprite::create("help_bg2.jpg");
		//为适应屏幕进行缩放
		bg1->setScaleX((float)visibleSize.width / (float)bg1->getContentSize().width);
		bg1->setScaleY((float)visibleSize.height / (float)bg1->getContentSize().height);
		bg1->setPosition(Vec2(origin.x + visibleSize.width / 2, 0));
		bg1->setAnchorPoint(Vec2(0.5, 0));
		bg1->setTag(101);
		this->addChild(bg1, 0);
	}
	else if (getPass() == 3){
		auto bg1 = Sprite::create("help_bg3.jpg");
		//为适应屏幕进行缩放
		bg1->setScaleX((float)visibleSize.width / (float)bg1->getContentSize().width);
		bg1->setScaleY((float)visibleSize.height / (float)bg1->getContentSize().height);
		bg1->setPosition(Vec2(origin.x + visibleSize.width / 2, 0));
		bg1->setAnchorPoint(Vec2(0.5, 0));
		bg1->setTag(101);
		this->addChild(bg1, 0);
	}
	else if (getPass() == 4) {
		auto bg1 = Sprite::create("help_bg4.png");
		//为适应屏幕进行缩放
		bg1->setScaleX((float)visibleSize.width / (float)bg1->getContentSize().width);
		bg1->setScaleY((float)visibleSize.height / (float)bg1->getContentSize().height);
		bg1->setPosition(Vec2(origin.x + visibleSize.width / 2, 0));
		bg1->setAnchorPoint(Vec2(0.5, 0));
		bg1->setTag(101);
		this->addChild(bg1, 0);
	}
	else if (getPass() == 5) {
		auto bg1 = Sprite::create("help_bg4.png");
		//为适应屏幕进行缩放
		bg1->setScaleX((float)visibleSize.width / (float)bg1->getContentSize().width);
		bg1->setScaleY((float)visibleSize.height / (float)bg1->getContentSize().height);
		bg1->setPosition(Vec2(origin.x + visibleSize.width / 2, 0));
		bg1->setAnchorPoint(Vec2(0.5, 0));
		bg1->setTag(101);
		this->addChild(bg1, 0);
	}
	
	auto MagicItem = MenuItemImage::create("continue.png", "continue2.png",
		CC_CALLBACK_1(Help::menuContinueCallback, this));
	MagicItem->setPosition(Vec2(visibleSize.width - MagicItem->getContentSize().width - 20, MagicItem->getContentSize().height * 2));
	MagicItem->setAnchorPoint(Vec2(0.5, 0.5));
	auto menu = Menu::create(MagicItem, NULL);
	menu->setPosition(Vec2::ZERO);
	this->addChild(menu, 1);

	return true;
}
예제 #9
0
bool WorkspacePanel::isPass(wxTreeItemId id)
{
	return getPass(id) != NULL;
}
예제 #10
0
void mutt_fetchPopMail (void)
{
  struct sockaddr_in sin;
#if SIZEOF_LONG == 4
  long n;
#else
  int n;
#endif
  struct hostent *he;
  char buffer[2048];
  char msgbuf[SHORT_STRING];
  int s, i, last = 0, msgs, bytes, err = 0;
  CONTEXT ctx;
  MESSAGE *msg = NULL;

  if (!PopHost)
  {
    mutt_error _("POP host is not defined.");
    return;
  }

  if (!PopUser)
  {
    mutt_error _("No POP username is defined.");
    return;
  }
    
  if (!getPass ()) return;

  s = socket (AF_INET, SOCK_STREAM, IPPROTO_IP);

  memset ((char *) &sin, 0, sizeof(sin));
  sin.sin_family = AF_INET;
  sin.sin_port = htons (PopPort);

  if ((n = inet_addr (NONULL(PopHost))) == -1)
  {
    /* Must be a DNS name */
    if ((he = gethostbyname (NONULL(PopHost))) == NULL)
    {
      mutt_error (_("Could not find address for host %s."), PopHost);
      return;
    }
    memcpy ((void *)&sin.sin_addr, *(he->h_addr_list), he->h_length);
  }
  else
    memcpy ((void *)&sin.sin_addr, (void *)&n, sizeof(n));
  
  mutt_message (_("Connecting to %s"), inet_ntoa (sin.sin_addr));

  if (connect (s, (struct sockaddr *) &sin, sizeof (struct sockaddr_in)) == -1)
  {
    mutt_perror ("connect");
    return;
  }
  
  if (getLine (s, buffer, sizeof (buffer)) == -1)
    goto fail;

  if (mutt_strncmp (buffer, "+OK", 3) != 0)
  {
    mutt_remove_trailing_ws (buffer);
    mutt_error ("%s", buffer);
    goto finish;
  }

  snprintf (buffer, sizeof(buffer), "user %s\r\n", PopUser);
  write (s, buffer, mutt_strlen (buffer));

  if (getLine (s, buffer, sizeof (buffer)) == -1)
    goto fail;

  if (mutt_strncmp (buffer, "+OK", 3) != 0)
  {
    mutt_remove_trailing_ws (buffer);
    mutt_error ("%s", buffer);
    goto finish;
  }
  
  snprintf (buffer, sizeof(buffer), "pass %s\r\n", NONULL(PopPass));
  write (s, buffer, mutt_strlen (buffer));
  
  if (getLine (s, buffer, sizeof (buffer)) == -1)
    goto fail;

  if (mutt_strncmp (buffer, "+OK", 3) != 0)
  {
    if(PopPass)
      memset(PopPass, 0, mutt_strlen(PopPass));
    
    safe_free((void **) &PopPass); /* void the given password */
    mutt_remove_trailing_ws (buffer);
    mutt_error ("%s", buffer[0] ? buffer : _("Server closed connection!"));
    goto finish;
  }
  
  /* find out how many messages are in the mailbox. */
  write (s, "stat\r\n", 6);
  
  if (getLine (s, buffer, sizeof (buffer)) == -1)
    goto fail;

  if (mutt_strncmp (buffer, "+OK", 3) != 0)
  {
    mutt_remove_trailing_ws (buffer);
    mutt_error ("%s", buffer);
    goto finish;
  }
  
  sscanf (buffer, "+OK %d %d", &msgs, &bytes);

  if (msgs == 0)
  {
    mutt_message _("No new mail in POP mailbox.");
    goto finish;
  }

  if (mx_open_mailbox (NONULL(Spoolfile), M_APPEND, &ctx) == NULL)
    goto finish;

  /* only get unread messages */
  if(option(OPTPOPLAST))
  {
    write (s, "last\r\n", 6);
    if (getLine (s, buffer, sizeof (buffer)) == -1)
      goto fail;
    
    if (mutt_strncmp (buffer, "+OK", 3) == 0)
      sscanf (buffer, "+OK %d", &last);
    else
      /* ignore an error here and assume all messages are new */
      last = 0;
  }
  
  snprintf (msgbuf, sizeof (msgbuf),
	    msgs > 1 ? _("Reading new messages (%d bytes)...") :
		    _("Reading new message (%d bytes)..."), bytes);
  mutt_message (msgbuf);

  for (i = last + 1 ; i <= msgs ; i++)
  {
    snprintf (buffer, sizeof(buffer), "retr %d\r\n", i);
    write (s, buffer, mutt_strlen (buffer));

    if (getLine (s, buffer, sizeof (buffer)) == -1)
    {
      mx_fastclose_mailbox (&ctx);
      goto fail;
    }

    if (mutt_strncmp (buffer, "+OK", 3) != 0)
    {
      mutt_remove_trailing_ws (buffer);
      mutt_error ("%s", buffer);
      break;
    }

    if ((msg = mx_open_new_message (&ctx, NULL, M_ADD_FROM)) == NULL)
    {
      err = 1;
      break;
    }

    /* Now read the actual message. */
    FOREVER
    {
      char *p;
      int chunk;

      if ((chunk = getLine (s, buffer, sizeof (buffer))) == -1)
      {
	mutt_error _("Error reading message!");
	err = 1;
	break;
      }

      /* check to see if we got a full line */
      if (buffer[chunk-2] == '\r' && buffer[chunk-1] == '\n')
      {
	if (mutt_strcmp(".\r\n", buffer) == 0)
	{
	  /* end of message */
	  break;
	}

	/* change CRLF to just LF */
	buffer[chunk-2] = '\n';
	buffer[chunk-1] = 0;
	chunk--;

	/* see if the line was byte-stuffed */
	if (buffer[0] == '.')
	{
	  p = buffer + 1;
	  chunk--;
	}
	else
	  p = buffer;
      }
      else
	p = buffer;
      
      fwrite (p, 1, chunk, msg->fp);
    }

    if (mx_commit_message (msg, &ctx) != 0)
    {
      mutt_error _("Error while writing mailbox!");
      err = 1;
    }

    mx_close_message (&msg);

    if (err)
      break;

    if (option (OPTPOPDELETE))
    {
      /* delete the message on the server */
      snprintf (buffer, sizeof(buffer), "dele %d\r\n", i);
      write (s, buffer, mutt_strlen (buffer));

      /* eat the server response */
      getLine (s, buffer, sizeof (buffer));
      if (mutt_strncmp (buffer, "+OK", 3) != 0)
      {
	err = 1;
        mutt_remove_trailing_ws (buffer);
	mutt_error ("%s", buffer);
	break;
      }
    }
    
    if ( msgs > 1)
      mutt_message (_("%s [%d of %d messages read]"), msgbuf, i, msgs);
    else
      mutt_message (_("%s [%d message read]"), msgbuf, msgs);

  }

  if (msg)
  {
    if (mx_commit_message (msg, &ctx) != 0)
      err = 1;
    mx_close_message (&msg);
  }
  mx_close_mailbox (&ctx, NULL);

  if (err)
  {
    /* make sure no messages get deleted */
    write (s, "rset\r\n", 6);
    getLine (s, buffer, sizeof (buffer)); /* snarf the response */
  }

finish:

  /* exit gracefully */
  write (s, "quit\r\n", 6);
  getLine (s, buffer, sizeof (buffer)); /* snarf the response */
  close (s);
  return;

  /* not reached */

fail:

  mutt_error _("Server closed connection!");
  close (s);
}
예제 #11
0
파일: map.cpp 프로젝트: 33d/scummvm
void Map::findNearestWalkable(int16 &gobDestX, int16 &gobDestY,
		int16 mouseX, int16 mouseY) {
	int16 mapWidth, mapHeight;
	int16 pos1 = -1, pos2 = -1;
	int16 distance;
	int16 direction;
	int i;

	mapWidth = _screenWidth / _tilesWidth;
	mapHeight = _vm->_height / _tilesHeight;
	direction = 0;

	for (i = 1; i <= gobDestX; i++)
		if (getPass(gobDestX - i, gobDestY) != 0)
			break;
	if (i <= gobDestX)
		pos1 = ((i - 1) * _tilesWidth) + (mouseX % _tilesWidth) + 1;
	distance = i;

	for (i = 1; (gobDestX + i) < mapWidth; i++)
		if (getPass(gobDestX + i, gobDestY) != 0)
			break;
	if ((gobDestX + i) < mapWidth)
		pos2 = (i * _tilesWidth) - (mouseX % _tilesWidth);

	if ((pos2 != -1) && ((pos1 == -1) || (pos1 > pos2))) {
		pos1 = pos2;
		direction = 1;
		distance = i;
	}
	pos2 = -1;

	for (i = 1; (gobDestY + i) < mapHeight; i++)
		if (getPass(gobDestX, gobDestY + i) != 0)
			break;
	if ((gobDestY + i) < mapHeight)
		pos2 = (i * _tilesHeight) - (mouseY % _tilesHeight);

	if ((pos2 != -1) && ((pos1 == -1) || (pos1 > pos2))) {
		pos1 = pos2;
		direction = 2;
		distance = i;
	}
	pos2 = -1;

	for (i = 1; i <= gobDestY; i++)
		if (getPass(gobDestX, gobDestY - i) != 0)
			break;
	if (i <= gobDestY)
		pos2 = ((i - 1) * _tilesHeight) + (mouseY % _tilesHeight) + 1;

	if ((pos2 != -1) && ((pos1 == -1) || (pos1 > pos2))) {
		direction = 3;
		distance = i;
	}

	if (direction == 0)
		gobDestX -= distance;
	else if (direction == 1)
		gobDestX += distance;
	else if (direction == 2)
		gobDestY += distance;
	else if (direction == 3)
		gobDestY -= distance;
}
예제 #12
0
파일: map.cpp 프로젝트: 33d/scummvm
Direction Map::getDirection(int16 x0, int16 y0, int16 x1, int16 y1) {
	if ((x0 == x1) && (y0 == y1))
		// Already at the destination
		return kDirNone;

	if ((x1 < 0) || (x1 > _mapWidth) || (y1 < 0) || (y1 > _mapHeight))
		// Destination out of range
		return kDirNone;

	RelativeDirection relDir = kRelDirNone;

	// Find the direct direction we want to move
	if (y1 > y0)
		relDir = kRelDirDown;
	else if (y1 < y0)
		relDir = kRelDirUp;

	if (x1 > x0)
		relDir = (RelativeDirection)(relDir | kRelDirRight);
	else if (x1 < x0)
		relDir = (RelativeDirection)(relDir | kRelDirLeft);


	// Are we on ladders and can continue the ladder in the wanted direction?
	if ((getPass(x0, y0) == 3) && (relDir & kRelDirUp  ) && (getPass(x0, y0 - 1) != 0))
		return kDirN;

	if ((getPass(x0, y0) == 3) && (relDir & kRelDirDown) && (getPass(x0, y0 + 1) != 0))
		return kDirS;

	if ((getPass(x0, y0) == 6) && (relDir & kRelDirUp  ) && (getPass(x0, y0 - 1) != 0))
		return kDirN;

	if ((getPass(x0, y0) == 6) && (relDir & kRelDirDown) && (getPass(x0, y0 + 1) != 0))
		return kDirS;


	// Want to go left
	if (relDir == kRelDirLeft) {
		if (getPass(x0 - 1, y0) != 0)
			// Can go west
			return kDirW;

		// Can't go
		return kDirNone;
	}

	// Want to go left
	if (relDir == kRelDirRight) {
		if (getPass(x0 + 1, y0) != 0)
			// Can go east
			return kDirE;

		// Can't go
		return kDirNone;
	}


	// Want to go up
	if (relDir == kRelDirUp) {
		if (getPass(x0    , y0 - 1) != 0)
			// Can go north
			return kDirN;

		if (getPass(x0 - 1, y0 - 1) != 0)
			// Can up north-west instead
			return kDirNW;

		if (getPass(x0 + 1, y0 - 1) != 0)
			// Can up north-east instead
			return kDirNE;

		// Can't go at all
		return kDirNone;
	}

	// Want to go down
	if (relDir == kRelDirDown) {
		if (getPass(x0    , y0 + 1) != 0)
			// Can go south
			return kDirS;

		if (getPass(x0 - 1, y0 + 1) != 0)
			// Can up south-west instead
			return kDirSW;

		if (getPass(x0 + 1, y0 + 1) != 0)
			// Can up south-east instead
			return kDirSE;

		// Can't go at all
		return kDirNone;
	}


	// Want to go up and right
	if (relDir == kRelDirRightUp) {
		if (getPass(x0 + 1, y0 - 1) != 0)
			// Can go north-east
			return kDirNE;

		if (getPass(x0    , y0 - 1) != 0)
			// Can only go north
			return kDirN;

		if (getPass(x0 + 1, y0    ) != 0)
			// Can only go east
			return kDirE;

		// Can't go at all
		return kDirNone;
	}

	// Want to go down and right
	if (relDir == kRelDirRightDown) {
		if (getPass(x0 + 1, y0 + 1) != 0)
			// Can go south-east
			return kDirSE;

		if (getPass(x0    , y0 + 1) != 0)
			// Can only go south
			return kDirS;

		if (getPass(x0 + 1, y0    ) != 0)
			// Can only go east
			return kDirE;

		// Can't go at all
		return kDirNone;
	}

	// Want to go up and left
	if (relDir == kRelDirLeftUp) {
		if (getPass(x0 - 1, y0 - 1) != 0)
			// Can go north-west
			return kDirNW;

		if (getPass(x0    , y0 - 1) != 0)
			// Can only go north
			return kDirN;

		if (getPass(x0 - 1, y0    ) != 0)
			// Can only go west
			return kDirW;

		// Can't go at all
		return kDirNone;
	}

	// Want to go left and down
	if (relDir == kRelDirLeftDown) {
		if (getPass(x0 - 1, y0 + 1) != 0)
			// Can go south-west
			return kDirSW;

		if (getPass(x0    , y0 + 1) != 0)
			// Can only go south
			return kDirS;

		if (getPass(x0 - 1, y0    ) != 0)
			// Can only go west
			return kDirW;

		// Can't go at all
		return kDirNone;
	}

	warning("Map::getDirection(): Invalid direction?!?");
	return kDirNone;
}
예제 #13
0
//
// Material init
//
bool ProcessedShaderMaterial::init( const FeatureSet &features, 
                                    const GFXVertexFormat *vertexFormat,
                                    const MatFeaturesDelegate &featuresDelegate )
{
   // Load our textures
   _setStageData();

   // Determine how many stages we use
   mMaxStages = getNumStages(); 
   mVertexFormat = vertexFormat;
   mFeatures.clear();
   mStateHint.clear();
   SAFE_DELETE(mInstancingState);

   for( U32 i=0; i<mMaxStages; i++ )
   {
      MaterialFeatureData fd;

      // Determine the features of this stage
      _determineFeatures( i, fd, features );
   
      // Let the delegate poke at the features.
      if ( featuresDelegate )
         featuresDelegate( this, i, fd, features );

      // Create the passes for this stage
      if ( fd.features.isNotEmpty() )
         if( !_createPasses( fd, i, features ) )
            return false;
   }

   _initRenderPassDataStateBlocks();
   _initMaterialParameters();
   mDefaultParameters =  allocMaterialParameters();
   setMaterialParameters( mDefaultParameters, 0 );
   mStateHint.init( this );   

   // Enable instancing if we have it.
   if ( mFeatures.hasFeature( MFT_UseInstancing ) )
   {
      mInstancingState = new InstancingState();
      mInstancingState->setFormat( &_getRPD( 0 )->shader->mInstancingFormat, mVertexFormat );
   }

   // Check for a RenderTexTargetBin assignment
   // *IMPORTANT NOTE* 
   // This is a temporary solution for getting diffuse mapping working with tex targets for standard materials
   // It should be removed once this is done properly, at that time the sAllowTextureTargetAssignment should also be removed 
   // from Material (it is necessary for catching shadow maps/post effect this shouldn't be applied to)
   if (Material::sAllowTextureTargetAssignment)
      if (mMaterial && mMaterial->mDiffuseMapFilename[0].isNotEmpty() && mMaterial->mDiffuseMapFilename[0].substr( 0, 1 ).equal("#"))
      {
         String texTargetBufferName = mMaterial->mDiffuseMapFilename[0].substr(1, mMaterial->mDiffuseMapFilename[0].length() - 1);
         NamedTexTarget *texTarget = NamedTexTarget::find( texTargetBufferName ); 

         RenderPassData* rpd = getPass(0);      

         if (rpd)
         {
            rpd->mTexSlot[0].texTarget = texTarget;
            rpd->mTexType[0] = Material::TexTarget;
         }
      }

   return true;
}
예제 #14
0
void user::setPassword() {
	cout << "Enter a password:\n";
	getPass(password);
	cout << "\n";
}
 /// Add object without accounting for projection.
 ///
 /// \param object Object to queue for rendering.
 /// \param transform Object transformation.
 /// \param pass Render pass id.
 void addObjectScreenspace(const Object &object, const mat4 &transform, unsigned pass)
 {
   getPass(pass).emplace_back(object, transform, mat4::identity(), mat4::identity());
 }