void GSwifi::httpdPoll () { for (int cid = 0; cid < 16; cid ++) { if (isConnected(cid) && _con[cid].protocol == PROTO_HTTPD) { if (_httpd[cid].mode == HTTPDMODE_ENTER) { int i = httpdGetHandler(_httpd[cid].uri); if (i >= 0) { if (_httpd_handler[i].dir) { // file httpdFile(cid, _httpd_handler[i].dir); } else if (_httpd_handler[i].func && !_httpd_handler[i].ws) { // cgi _httpd_handler[i].func(cid); // _httpd[cid].keepalive = 0; } else { httpdError(cid, 403); } } else { httpdError(cid, 404); } if (_httpd[cid].keepalive) { DBG("keepalive %d", _httpd[cid].keepalive); _httpd[cid].keepalive --; } else { close(cid); } _httpd[cid].mode = HTTPDMODE_REQUEST; #ifdef CFG_ENABLE_WEBSOCKET } else if (_httpd[cid].mode == HTTPDMODE_WEBSOCKET_BEGIN) { wsAccept(cid); _httpd[cid].mode = HTTPDMODE_WEBSOCKET; } else if (_httpd[cid].mode == HTTPDMODE_WEBSOCKET_ENTER) { wsParseRequest(cid); _httpd[cid].mode = HTTPDMODE_WEBSOCKET; #endif } } // PROTO_HTTPD } // for }
/*! Run a micro_httpd instance to process http traffic. */ void InetdAdaptor::runMicroHttpd( HttpWorker *worker ) { worker->httpd = new QProcess(); connect( worker->httpd, SIGNAL(readyRead()), this, SLOT(httpdReadyRead()) ); connect( worker->httpd, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(disconnected()) ); connect( worker->httpd, SIGNAL(error(QProcess::ProcessError)), this, SLOT(httpdError(QProcess::ProcessError)) ); // TODO: make the directory path for the webserver configurable QString httpdPath = QCoreApplication::applicationDirPath() + "/micro_httpd"; if ( !QFile::exists( httpdPath )) qFatal( "Could not find micro_httpd binary" ); worker->httpd->start( httpdPath, QStringList( QDir::currentPath() )); }