コード例 #1
0
ファイル: serverskt.cpp プロジェクト: sdlylshl/sokit
void ServerSktTcp::newConnection()
{
	QTcpServer* server = qobject_cast<QTcpServer*>(sender());
	if (!server) return;

	QTcpSocket* client = server->nextPendingConnection();
	while (client)
	{
		Conn* conn = new Conn;
		if (!conn)
		{
			client->deleteLater();
		}
		else
		{
			client->setProperty(PROP_CONN, qVariantFromValue((void*)conn));

			conn->client = client;
			conn->key = TK::ipstr(client->peerAddress(),client->peerPort(), true);

			connect(client, SIGNAL(readyRead()), this, SLOT(newData()));
			connect(client, SIGNAL(destroyed(QObject*)), this, SLOT(close(QObject*)));
			connect(client, SIGNAL(disconnected()), client, SLOT(deleteLater()));
			connect(client, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error()));

			setCookie(conn->key, conn);
		}
		client = server->nextPendingConnection();
	}
}
コード例 #2
0
ファイル: main.cpp プロジェクト: aoyama-nanami/amatsukaze
int main(int argc, char *argv[]) {
  QApplication app(argc, argv);

  ProxyServiceThread proxyServer;
  proxyServer.start();

  QNetworkProxy::setApplicationProxy({QNetworkProxy::HttpProxy, "localhost",
                                      proxyServer.ServerPort()});
  QWebEngineSettings::globalSettings()->setAttribute(
      QWebEngineSettings::PluginsEnabled, true);

  MainWindow main_window;
  auto view = main_window.GetWebEngineView();
  view->page()->profile()->setHttpUserAgent("Chrome/45.0.2431.0");
  auto cookieStore = view->page()->profile()->cookieStore();
  for (auto cookie: GenerateKanColleCookies()) {
    cookieStore->setCookie(cookie);
  }

  view->load(QUrl(KANCOLLE_URL));

  main_window.show();

  return app.exec();
}
コード例 #3
0
ファイル: shibbolethcredentials.cpp プロジェクト: Pro/mirall
QNetworkAccessManager* ShibbolethCredentials::getQNAM() const
{
    ShibbolethAccessManager* qnam(new ShibbolethAccessManager(_shibCookie));

    connect(this, SIGNAL(newCookie(QNetworkCookie)),
            qnam, SLOT(setCookie(QNetworkCookie)));
    return qnam;
}
コード例 #4
0
ファイル: Request.cpp プロジェクト: dreamsxin/WebCpp
void Request::setCookie(const String& name,
                        const String& value,
                        ExpiryPolicy expiryPolicy,
                        const String& path,
                        const String& domain,
                        bool https)
{
	DateTimeDuration duration;
	if (expiryPolicy == Never)
		duration += DateTimeDuration("0005-00-00");
	else if (expiryPolicy == OneMonth)
		duration += DateTimeDuration("0000-01-00");
	setCookie(name, value, duration, path, domain, https);
}
コード例 #5
0
ファイル: cpppage.cpp プロジェクト: yuchengwen/cgi.cpp
void Page::setSession(const String & key, const String & value, int live)
{
    String sid = _cookie[SESSION_COOKIE_NAME];
    if(sid.empty())
    {
        sid = randomString();
        // 保存标识到浏览器
        setCookie(SESSION_COOKIE_NAME, sid, live);
    }

    // 保存会话值到服务器
    if(!_session)
        _session = new Config(SESSION_FILE_TAG + sid);
    _session->set(key, value);
}
コード例 #6
0
ファイル: serverskt.cpp プロジェクト: sdlylshl/sokit
void ServerSktUdp::newData()
{
	QUdpSocket* s = qobject_cast<QUdpSocket*>(sender());
	if (!s) return;

	qint64 bufLen = s->pendingDatagramSize();
	char* buf = TK::createBuffer(bufLen, MAXBUFFER);
	if (!buf) return;

	QHostAddress addr; quint16 port(0);

	qint64 readLen = 0;
	qint64 ioLen = s->readDatagram(buf, bufLen, &addr, &port);

	//while (ioLen > 0)
	//{
		readLen += ioLen;
	//	ioLen = s->readDatagram(buf+readLen, bufLen-readLen, &addr, &port);
	//}

	if (ioLen >= 0)
	{
		Conn* conn = (Conn*)getCookie(TK::ipstr(addr, port, false));
		if (!conn)
		{
			conn = new Conn;
			if (conn)
			{
				conn->key  = TK::ipstr(addr, port, false);
				conn->addr = addr;
				conn->port = port;
				setCookie(conn->key, conn);
			}
		}

		if (conn)
		{
			recordRecv(readLen);

			conn->stamp = QDateTime::currentDateTime();
			dump(buf, readLen, false, conn->key);
		}
	}

	TK::releaseBuffer(buf);
}
コード例 #7
0
ファイル: Player.cpp プロジェクト: Nephos/Gomoku
/* Else, wait for the other client */
bool Player::parseAnswer(const std::string &str) {
  if (str.empty())
    return true;
  if (str.find("401 Unauthorized") != std::string::npos) {
    std::istringstream ss(str);
    std::string tmp;
    while (std::getline(ss, tmp)) {
      if (tmp.find("Not your turn.") != std::string::npos)
        return false;
      else if (tmp.find("failed. not ready") == 0)
        return false;
    }
    _moveFailed = true;
    _myTurn = true;
    return false;
  }
  else if (str.find("403 Forbidden") != std::string::npos) {
    connect();
    return false;
  }
  else {
    std::istringstream ss(str);
    std::string tmp;
    while (std::getline(ss, tmp)) {
      if (tmp.find("failed.") == 0) { // failed + code 200 = loose !!
	std::cout << "Game over :(" << std::endl;
        _gameOver = true;
        _win = false;
        updateMap(ss);
      }
      else if (tmp.find("win.") == 0) {
        _gameOver = true;
        _win = true;
        updateMap(ss);
      }
      else if (tmp.find("continue.") == 0 || tmp.find("ok.") == 0) {
        if (tmp.find("continue") == 0) {
	  _myTurn = !_myTurn;
        }
        updateMap(ss);
      }
    }
  }
  setCookie(str);
  return true;
}
コード例 #8
0
ファイル: settings.cpp プロジェクト: icaruseffect/kaktus
void Settings::reset()
{
    if (!getSignedIn()) {
        setLastUpdateDate(0);
        setDashboardInUse("");
        setPassword("");
        setHelpDone(false);
        setCookie("");
        setTwitterCookie("");
        setAuthUrl("");
        setHint1Done(false);
        setCachingMode(0);
        setRetentionDays(14);
        setSyncRead(false);
        setProvider("");
        setUserId("");
        setShowBroadcast(true);
    }
}
コード例 #9
0
ファイル: xtraz.cpp プロジェクト: Anderty/qutim
XtrazRequestPacket::XtrazRequestPacket(IcqContact *contact, const QString &query, const QString &notify)
{
	QString body;
	{
		QXmlStreamWriter xml(&body);
		xml.writeStartElement("N");
		xml.writeStartElement("QUERY");
		xml.writeCharacters(query);
		xml.writeEndElement();
		xml.writeStartElement("NOTIFY");
		xml.writeCharacters(notify);
		xml.writeEndElement();
		xml.writeEndElement();
	}
	XtrazData data(body);
	Cookie cookie = data.cookie();
	cookie.setContact(contact);
	setCookie(cookie);
	init(contact, 2, cookie);
	appendTLV(0x05, Channel2MessageData(1, data).data());
	appendTLV(0x03);
}
コード例 #10
0
ファイル: RockCom.cpp プロジェクト: Bonio/moorie
int RockComMailbox::downloadRequest(int seg)
{
// 	LOG_ENTER("RockComMailbox::downloadRequest");
	//cout << hdr.uniqueId << endl;
// 	string page=doGet("http://mymail.rock.com/scripts/mail/"+hdr.uniqueId);
// 	smatch match;
// 	regex re("<A HREF=\"(/getattach/[^\"]*)");
// 	if(!regex_search(page,match,re))
// 		return 1;
// 	else
// 		return 0;
// 		throw MoorieException("Unable to download attachement.");
// 	setState(Mailbox::DownloadIP);
// 	setSegment(s);
// 	doGet("http://mymail.rock.com"+match[1]);
	std::string mylink = getLink(seg);
	setCookie(auth);
	page = doGet("http://mymail.rock.com/scripts/mail/"+mylink);
	boost::regex re("<A HREF=\"(/getattach/[^\"]*)");

	boost::smatch match;
	std::string link, downlink;
 	if(boost::regex_search(page,match,re)) {
		link=match[1];
//		cout << link << endl;
		downlink = "http://mymail.rock.com"+link;
		LOG(Log::Debug, downlink);
		downloadSeg();
		doGet(downlink);
		if (downloadSegDone() == 0)
			return 0;
		else
			return 1;
//		setState(Mailbox::DownloadIP);
//		setSegment(s);
	} else
		return 1;

}
コード例 #11
0
int RewriteEngine::expandEnv( const RewriteRule * pRule, HttpConnection * pConn )
{
    RewriteSubstFormat * pEnv = pRule->getEnv()->begin();
    const char * pKey;
    const char * pKeyEnd;
    const char * pValue;
    const char * pValEnd;
    char achCacheCtrl[REWRITE_BUF_SIZE];
    int ccLen = 0;
    int len = REWRITE_BUF_SIZE;
    char achBuf[REWRITE_BUF_SIZE];
    if ( !pEnv )
        return 0;
    while( pEnv )
    {
        len = REWRITE_BUF_SIZE - 1;
        buildString( pEnv, pConn, achBuf, len );
        if ( pEnv->isCookie() )
        {
            //FIXME: enable it later
            setCookie( achBuf, len, pConn );
            pEnv = (RewriteSubstFormat *)pEnv->next();
            continue;
        }
        pKeyEnd = strchr( achBuf, ':' );
        if ( pKeyEnd )
        {
            pKey = achBuf;
            pValue = pKeyEnd + 1;
            pValEnd = &achBuf[len];
            StringTool::strtrim( pKey, pKeyEnd );
            StringTool::strtrim( pValue, pValEnd );
            *(char*)pKeyEnd = 0;
            *(char*)pValEnd = 0;
            if ( strcasecmp( pKey, "dontlog" ) == 0 )
            {
                if ( m_logLevel > 4 )
                    LOG_INFO(( pConn->getLogger(),
                        "[%s] [REWRITE] disable access log for this request.",
                         pConn->getLogId() ));
                pConn->getResp()->needLogAccess(0);
            }
            else if ( strcasecmp( pKey, "nokeepalive" ) == 0 )
            {
                if ( m_logLevel > 4 )
                    LOG_INFO(( pConn->getLogger(),
                        "[%s] [REWRITE] turn off connection keepalive.",
                         pConn->getLogId() ));
                pConn->getReq()->keepAlive( false );
            }
//            else if ( strcasecmp( pKey, "noconntimeout" ) == 0 )
//            {
//                if ( m_logLevel > 4 )
//                    LOG_INFO(( pConn->getLogger(),
//                        "[%s] [REWRITE] turn off connection timeout.",
//                         pConn->getLogId() ));
//                pConn->getReq()->orContextState( NO_CONN_TIMEOUT );
//            }
//            else if (( pRule->getAction() == RULE_ACTION_PROXY)&&
//                    ( strcasecmp( pKey, "Proxy-Host" ) == 0 ))
//            {
//                pConn->getReq()->setNewHost( pValue, 
//                        pValEnd - pValue );
//                if ( m_logLevel > 4 )
//                    LOG_INFO(( pConn->getLogger(),
//                        "[%s] [REWRITE] Set Proxy Host header to: '%s' ",
//                    pConn->getLogId(), pKey, pValue ));
//            }
            else if ( strcasecmp( pKey, "no-gzip" ) == 0 )
            {
                if ( strncmp( pValue, "0", 1 ) != 0 )
                {
                    if ( m_logLevel > 4 )
                        LOG_INFO(( pConn->getLogger(),
                          "[%s] [REWRITE] turn off gzip compression for this requst.",
                             pConn->getLogId()));
                    pConn->getReq()->andGzip( ~GZIP_ENABLED );
                }
            }
            else
            {
                pConn->getReq()->addEnv( pKey, pKeyEnd - pKey, pValue, pValEnd - pValue );
                if ( m_logLevel > 4 )
                    LOG_INFO(( pConn->getLogger(),
                        "[%s] [REWRITE] add ENV: '%s:%s' ",
                        pConn->getLogId(), pKey, pValue ));
            }
        }
        pEnv = (RewriteSubstFormat *)pEnv->next();
    }
    return 0;
}
コード例 #12
0
void Settings::generateCookie()
{
    setCookie(getRandomString());
}
コード例 #13
0
ファイル: server.cpp プロジェクト: GianpaoloR/polyphemus
void Server::initCookies(std::vector<cgicc::HTTPCookie> cookieList) {
    for(cgicc::const_cookie_iterator cci = cookieList.begin(); cci != cookieList.end(); cci++) {
        setCookie(cci->getName(), cci->getValue());
    }
}
コード例 #14
0
ファイル: request.c プロジェクト: Dream74/Web_Server
static int staticProcess(const ExHttp *pHttp)
{
  char buf[BUFSIZ] ;
  char *pBuf = buf ;
  int ret = 0 ;

  int code = cacheCheck( pHttp ) ;
  pBuf += codeSet( pBuf, code ) ;
  if ( code==200 ) {
    pBuf += fileSet( pBuf, pHttp ) ;
  }

  if ( strcmp( get_mime_type( pHttp->url ), "image/png" )!=0 )
    pBuf += setCookie( pBuf, pHttp ) ;

  do {
    if ( code==206 ) {
      char rangeTemp[128] ;
      char * range = ( char * ) get_head_info( pHttp, "Range" ) ;
      strncpy( ( char * ) &rangeTemp, range, 128 ) ;
      range = ( char * ) &rangeTemp ;
      SKIP( &range, '=' ) ;
      char * sRange = range ;
      SKIP( &range, '-' ) ;

      char date[35] ;
      strftime( date, 35, "%a, %d %b %Y %X GMT", localtime( &(pHttp->st.st_ctime) ) ) ;

      int startRange = (*sRange=='\0') ? -1 : atoi( sRange ) ;
      int endRange = (*range=='\0') ? -1 : atoi( range ) ;
			// printf("start :%d end :%d\n",startRange,endRange ) ;
      if ( startRange<0 ) {
        startRange = pHttp->st.st_size-endRange ;
        endRange = pHttp->st.st_size ;
      }
      else if ( endRange<0 ) {
        endRange = pHttp->st.st_size ;
      }
      pBuf += sprintf( pBuf, "connection: close\n"
              "Last-Modified: %s\n"
              "Accept-Ranges: bytes\n"
              "Content-Length: %d\n"
              "Content-Range: bytes %d-%d/%d\n",
              date,
              endRange-startRange,
              startRange,
              endRange,
              pHttp->st.st_size
              ) ;
      if ( (ret = sendHead( pHttp, buf, pBuf-buf ))<0 )
        break ;
      ret = sendFileRangeStream( pHttp, pHttp->url, startRange, endRange + 1 ) ;
      break ;
    }

    if ( (ret = sendHead( pHttp, buf, pBuf-buf ))<0 )
      break ;

    if ( code==304|| code == 412 || 'H'== *(pHttp->method) )
      break ;
    ret = sendFileStream( pHttp, pHttp->url ) ;
  } while ( 0 ) ;
  return ret ;
}
コード例 #15
0
ファイル: Response.cpp プロジェクト: hzx/shot
void Response::setSecureCookie(const char* name, const char* value, int expiresDays) {
    string enc = encodeCookie(Options::instance().cookieSecret, name, value, std::time(nullptr));
    setCookie(name, enc.data(), expiresDays);
}