Ejemplo n.º 1
0
HttpContext* ContextTree::getContext( const char * pURI ) const
{
    HttpContext* pMatched = m_pRootNode->match( pURI + 1 )->getContext();
    if ( pMatched )
    {
        if ( strcmp( pMatched->getURI(), pURI ) == 0 )
            return pMatched;
    }
    return NULL;
}
Ejemplo n.º 2
0
void HttpServer::onMessage(const TcpConnectionPtr& conn, ByteBuffer *buf, Timestamp receiveTime)
{
     LOG_INFO("HttpServer::onConnection recv data [%d][%s]", conn->fd(), buf->toString().c_str());

     HttpContext *context = zl::stl::any_cast<HttpContext>(conn->getMutableContext());
     assert(context);
     if(!context->parseRequest(buf, receiveTime))
     {
         conn->send("HTTP/1.1 400 Bad Request\r\n\r\n");
         conn->send("HTTP/1.1 400 Bad Request\r\n\r\n");
         conn->shutdown();
     }

     if (context->gotAll())
     {
         LOG_INFO("HttpServer::onMessage  parse request over.");
         response(conn, context->request());
         context->reset();  // process request and return response, then reset, for long-connection
     }
}
Ejemplo n.º 3
0
int testReuse () {
	// Connections shall be kept open...
	// Note: Prosody itself doesn't seem to do that
	// but NGINX does it.
	HttpContext httpContext;
	BoshNodeBuilder builder;
	builder.addAttribute("content", "text/xml; charset=utf-8");
	builder.addAttribute("from", "autotest1@localhost");
	builder.addAttribute("hold", "1");
	builder.addAttribute("to", "localhost");
	builder.addAttribute ("rid", "3000");
	builder.addAttribute ("xmlns","http://jabber.org/protocol/httpbind");

	HttpRequest req;
	req.start ("POST", "https://localhost/http-bind/");
	req.addHeader("Content-Type", "text/xml; charset=utf-8");
	req.addContent (sf::createByteArrayPtr(builder.toString()));
	req.end();
	std::pair<Error, HttpResponsePtr> res = httpContext.syncRequest(req, 60000);
	tcheck1(!res.first);
	test::millisleep_locked(1000);
	tcheck1 (httpContext.pendingConnections() == 1);
	return 0;
}
Ejemplo n.º 4
0
bool UrlElement::siteconnect(const std::string &server, const std::string &path, bool headonly) {
  // check that we actually got data..
  if (server.empty())
    return false;

  if (!context)
    context = new HttpContext();

  string thePath("/");

  // prefix the path with / if it doesn't start with it..
  if (path.c_str()[0] != '/')
    thePath += url;
  else
    thePath = url;

  string url("http://");
  url += server.c_str() + thePath;

  // start the request
  context->request(url, headonly);

  // block until the request is finished
  // or there is timeout
  QTimer timer;
  timer.setSingleShot(true);
  context->setTimer(&timer);
  timer.start(20000);

  while (!context->processed) {
    QCoreApplication::processEvents();
  }

  timer.stop();
  return context->status && context->code < 400;
} /* end, siteconnect */
Ejemplo n.º 5
0
void Awstats::config(HttpVHost *pVHost, int val, char* achBuf, const XmlNode *pAwNode, 
              char* iconURI, const char* vhDomain, int vhAliasesLen )
{
    const char *pURI;
    const char *pValue;
    char *p;
    int handlerType;
    int len = strlen( achBuf );
    int iChrootLen = 0;
    if ( HttpGlobals::s_psChroot != NULL )
    iChrootLen = HttpGlobals::s_psChroot->len();
    setMode( val );
    

    if ( achBuf[len - 1] == '/' )
        achBuf[len - 1] = 0;

    setWorkingDir( achBuf );

    pURI = pAwNode->getChildValue( "awstatsURI" );

    if ( ( !pURI ) || ( *pURI != '/' ) || ( * ( pURI + strlen( pURI ) - 1 ) != '/' )
            || ( strlen( pURI ) > 100 ) )
    {
        ConfigCtx::getCurConfigCtx()->log_warn( "AWStats URI is invalid"
                             ", use default [/awstats/]." );
        iconURI[9] = 0;;
        pURI = iconURI;
    }

    setURI( pURI );

    if ( val == AWS_STATIC )
    {
        handlerType = HandlerType::HT_NULL;
        strcat( achBuf, "/html/" );
    }
    else
    {
        ConfigCtx::getCurConfigCtx()->getValidPath( achBuf, "$SERVER_ROOT/add-ons/awstats/wwwroot/cgi-bin/",
                      "AWStats CGI-BIN directory" );

        if ( pVHost->getRootContext().determineMime( "pl", NULL )->getHandler()->getHandlerType() )
            handlerType = HandlerType::HT_NULL;
        else
            handlerType = HandlerType::HT_CGI;
    }

    HttpContext *pContext =
        pVHost->addContext( pURI, handlerType, &achBuf[iChrootLen], NULL, 1 );

    p = achBuf;
    if ( ConfigCtx::getCurConfigCtx()->getLongValue( pAwNode, "securedConn", 0, 1, 0 ) == 1 )
    {
        p += safe_snprintf( achBuf, 8192,
                "rewriteCond %%{HTTPS} !on\n"
                "rewriteCond %%{HTTP:X-Forwarded-Proto} !https\n"
                "rewriteRule ^(.*)$ https://%%{SERVER_NAME}%%{REQUEST_URI} [R,L]\n" );

    }
    if ( val == AWS_STATIC )
    {
        safe_snprintf( p, &achBuf[8192] - p,
                       "RewriteRule ^$ awstats.%s.html\n",
                       pVHost->getName() );
    }
    else
    {
        safe_snprintf( p, &achBuf[8192] - p, 
                       "RewriteRule ^$ awstats.pl\n"
                       "RewriteCond %%{QUERY_STRING} !configdir=\n"
                       "RewriteRule ^awstats.pl "
                       "$0?config=%s&configdir=%s/conf [QSA]\n",
                       pVHost->getName(),
                       getWorkingDir() + iChrootLen );
        pContext->setUidMode( UID_DOCROOT );
    }

    pContext->enableRewrite( 1 );
    pContext->configRewriteRule( pVHost->getRewriteMaps(), achBuf );

    pValue = pAwNode->getChildValue( "realm" );

    if ( pValue )
        pVHost->configAuthRealm( pContext, pValue );

    pValue = pAwNode->getChildValue( "siteDomain" );

    if ( !pValue )
    {
        ConfigCtx::getCurConfigCtx()->log_warn( "SiteDomain configuration is invalid"
                             ", use default [%s].",  vhDomain );
        pValue = vhDomain;
    }
    else
    {
        ConfigCtx::getCurConfigCtx()->expandDomainNames( pValue, achBuf, 4096 );
        pValue = achBuf;
    }

    setSiteDomain( pValue );

    pValue = pAwNode->getChildValue( "siteAliases" );
    int needConvert = 1;

    if ( !pValue )
    {
        if ( vhAliasesLen == 0 )
        {
            safe_snprintf( achBuf, 8192, "127.0.0.1 localhost REGEX[%s]",
                           getSiteDomain() );
            ConfigCtx::getCurConfigCtx()->log_warn( "SiteAliases configuration is invalid"
                                 ", use default [%s].", achBuf );
            pValue = achBuf;
            needConvert = 0;
        }
        else
            pValue = "$vh_aliases";
    }

    if ( needConvert )
    {
        ConfigCtx::getCurConfigCtx()->expandDomainNames( pValue, &achBuf[4096], 4096, ' ' );
        ConfigCtx::getCurConfigCtx()->convertToRegex( &achBuf[4096], achBuf, 4096 );
        pValue = achBuf;
        ConfigCtx::getCurConfigCtx()->log_info( "SiteAliases is set to '%s'", achBuf );
    }

    setAliases( pValue );

    val = ConfigCtx::getCurConfigCtx()->getLongValue( pAwNode, "updateInterval", 3600, 3600 * 24, 3600 * 24 );

    if ( val % 3600 != 0 )
        val = ( ( val + 3599 ) / 3600 ) * 3600;

    setInterval( val );

    val = ConfigCtx::getCurConfigCtx()->getLongValue( pAwNode, "updateOffset", 0, LONG_MAX, 0 );

    if ( val > getInterval() )
        val %= getInterval();

    setOffset( val );

    pVHost->setAwstats( this );    
}
HttpContext HttpContext::FromStdStringList(const StdStringList& stringList) {
    HttpContext context;
    context.ParseStdStringList(stringList);

    return context;
}
Ejemplo n.º 7
0
        Connection::Connection(HttpContext &context, const std::string &scheme, const std::string &host, int port)
            : _scheme(scheme),
              _host(host),
              _port(port),
			  _context(context),
			  _resolver(context.service()),
			  _connected(false),
			  _busy(false)
        {
			std::string schemeAddress;

#ifdef WINVER
			std::string proxyAddress;
			WINHTTP_CURRENT_USER_IE_PROXY_CONFIG proxy;
			if (WinHttpGetIEProxyConfigForCurrentUser(&proxy)) {
				if (proxy.lpszProxy) {
					proxyAddress = boost::locale::conv::utf_to_utf<char>(proxy.lpszProxy);
					GlobalFree(proxy.lpszProxy);
				}
				if (proxy.lpszProxyBypass) {
					GlobalFree(proxy.lpszProxyBypass);
				}
				if (proxy.lpszAutoConfigUrl) {
					GlobalFree(proxy.lpszProxyBypass);
				}
			}
			enum State
			{
				Key,
				Value
			} state = Key;

			std::string key;
			std::string value;
			std::map<std::string, std::string> list;
			for (auto c : proxyAddress) {
				switch (state) {
				case Key:
					if (c == '=') state = Value;
					else key += c;
					break;
				case Value:
					if (c == ';') {
						list[key] = value;
						key = "";
						value = "";
						state = Key;
					}
					else value += c;
					break;
				}
			}
			if (!value.empty()) list[key] = value;
			if (list.size() == 0) {
				schemeAddress = proxyAddress;
			}
			else {
				auto it = list.find(scheme);
				if (it != list.end()) schemeAddress = it->second;
			}
#else
            char * data = getenv("https_proxy");
			if (data) schemeAddress = data;
#endif
			if (!schemeAddress.empty()) {
				Url proxyUrl(schemeAddress);
				_proxy = proxyUrl.host();
				_proxyPort = proxyUrl.port();
				auto url = host + ":" + boost::lexical_cast<std::string>(port);
				_proxyGreeting = "CONNECT " + url + " HTTP/1.1\r\n"+
					"Host: " + url + "\r\n" +
					"Connection: Keep-Alive\r\n" +
					"User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36\r\n" +
					"\r\n";
			}
        }
Ejemplo n.º 8
0
 SslConnection::SslConnection(HttpContext &context, const std::string &host, int port)
         : Connection(context, "https", host, port == 0 ? 443 : port),
           _socket(context.service(), context.ssl()),
           _resolver(context.service())
 {}