void MainWindow::translate() { Language *srcLn = mLangageModel->language(ui->sourceComboBox->currentIndex()); Language *targetLn = mLangageModel->language(ui->targetComboBox->currentIndex()); QByteArray sourceText = ui->sourceTextEdit->toPlainText().toUtf8(); sourceText.replace("&", "&"); sourceText.replace("<", "<"); sourceText.replace(">", ">"); sourceText.replace("\n", "<br>"); QByteArray postData; QString source = srcLn->id.toUtf8().toPercentEncoding(); QString dest = targetLn->id.toUtf8().toPercentEncoding(); QString texte=ui->sourceTextEdit->toPlainText().toUtf8().toPercentEncoding(); QString st = "text="+texte+"&client=t&sl=" + source + "&tl=" + dest; postData = st.toUtf8(); QNetworkRequest request(QString(GOOGLE_URL)); request.setRawHeader("Content-Type","application/x-www-form-urlencoded"); request.setRawHeader("Host","www.google.com"); request.setRawHeader("User-Agent","Mozilla/5.0"); request.setRawHeader("Accept-Encoding","deflate"); request.setRawHeader("Connection","Close"); QNetworkReply * reply = mNetManager->post(QNetworkRequest(request),postData); qDebug()<<reply->url(); connect(reply,SIGNAL(finished()),this,SLOT(parseResult())); }
void DialogNewCamera::login(std::function<void(const QString &sid)> cb) { QString url = authUrl; url += QStringLiteral("&format=2&account=%1&passwd=%2").arg(ui->dsm_username->text()).arg(ui->dsm_password->text()); QUrl u(url); QNetworkRequest request(u); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); auto reply = nm->get(request); connect(reply, &QNetworkReply::finished, [=]() { reply->deleteLater(); if (reply->error() != QNetworkReply::NoError) { QMessageBox::warning(this, tr("Calaos Installer"), reply->errorString()); cb({}); return; } QByteArray bytes = reply->readAll(); bool err; QJsonObject jdata = parseResult(bytes, err); if (err || !jdata["sid"].isString()) { cb({}); return; } cb(jdata["sid"].toString()); }); }
bool CChangeJavaFunctionPermissionsAction::ActionPerformed(symbolPtr* pSym) { CImpactAction::ActionPerformed(pSym); Boolean bAbstract = XmToggleButtonGadgetGetState(m_abstractInd); string szAbstract = (bAbstract?"1":"0"); Boolean bStatic = XmToggleButtonGadgetGetState(m_staticInd); string szStatic = (bStatic?"1":"0"); Boolean bFinal = XmToggleButtonGadgetGetState(m_finalInd); string szFinal = (bFinal?"1":"0"); Boolean bNative = XmToggleButtonGadgetGetState(m_nativeInd); string szNative = (bNative?"1":"0"); char strPerm[10]; sprintf(strPerm,"%d", m_nPermission); string command = "Impact:ChangeJavaFunctionDeclaration " + prepareQuery(CEntityInfo::etag(pSym)) + " " + strPerm + " " + szAbstract + " " + szFinal + " " + szStatic + " " + szNative; string szDesc = GetName()+" to "; if(bAbstract) szDesc += " abstract"; if(bFinal) szDesc += " final"; if(bStatic) szDesc += " static"; if(bNative) szDesc += " native"; if(m_nPermission==PUBLIC) szDesc += " public"; else if(m_nPermission==PRIVATE) szDesc += " private"; else if(m_nPermission==PROTECTED) szDesc += " protected"; SetDescription(szDesc); string results; CEntityInfo::exec(command,results); parseResult(results); return true; }
void NewsScene::onHttpRequestCompleted(cocos2d::CCObject *pSender, void *data) { HttpResponsePacket *response = (HttpResponsePacket *)data; if (response->request->reqType == cocos2d::extension::kHttpRequestGet) { if (response->succeed) { CCLog("Get Request Completed!"); // CCLog("Content: %s", response->responseData.c_str()); parseResult((char*)response->responseData.c_str()); } else { CCLog("Get Error: %s", response->responseData.c_str()); } } else if (response->request->reqType == cocos2d::extension::kHttpRequestPost) { if (response->succeed) { CCLog("Post Request Completed!"); CCLog("Content: %s", response->responseData.c_str()); } else { CCLog("Post Error: %s", response->responseData.c_str()); } } else if (response->request->reqType == cocos2d::extension::kHttpRequestDownloadFile) { if (response->succeed) { CCLog("Download Request Completed! Downloaded:"); // std::vector<char> *buffer = response->responseData.c_str(); std::vector<std::string>::iterator iter; for (iter = response->request->files.begin(); iter != response->request->files.end(); ++iter) { std::string url = *iter; CCLog("%s", url.c_str()); } } else { CCLog("Download Error: %s", response->responseData.c_str()); } } }
void PasteUpload::downloadFinished() { // if the download succeeded if (m_reply->error() == QNetworkReply::NetworkError::NoError) { QByteArray data = m_reply->readAll(); m_reply.reset(); QJsonParseError jsonError; QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError); if (jsonError.error != QJsonParseError::NoError) { emitFailed(jsonError.errorString()); return; } if (!parseResult(doc)) { emitFailed(tr("paste.ee returned an error. Please consult the logs for more information")); return; } } // else the download failed else { emitFailed(QString("Network error: %1").arg(m_reply->errorString())); m_reply.reset(); return; } emitSucceeded(); }
bool CChangeCPPFieldPermissionsAction::ActionPerformed(symbolPtr* pSym) { CImpactAction::ActionPerformed(pSym); Boolean bStatic = XmToggleButtonGadgetGetState(m_staticInd); string szStatic = (bStatic?"1":"0"); Boolean bConst = XmToggleButtonGadgetGetState(m_constInd); string szConst = (bConst?"1":"0"); char strPerm[10]; sprintf(strPerm,"%d", m_nPermission); string command = "Impact:ChangeCPPFieldDeclaration " + prepareQuery(CEntityInfo::etag(pSym)) + " " + strPerm + " " + szConst + " " + szStatic; string szDesc = GetName()+" to "; if(bConst) szDesc += " const"; if(bStatic) szDesc += " static"; if(m_nPermission==PUBLIC) szDesc += " public"; else if(m_nPermission==PRIVATE) szDesc += " private"; else if(m_nPermission==PROTECTED) szDesc += " protected"; SetDescription(szDesc); string results; CEntityInfo::exec(command,results); parseResult(results); return true; }
bool CAddFieldAction::ActionPerformed(symbolPtr* pSym) { CImpactAction::ActionPerformed(pSym); string name; string type; char* text = XmTextGetString(m_nameField); name = text; XtFree(text); text = XmTextGetString(m_typeField); type = text; XtFree(text); string szDesc = GetName(); if(m_nPermission==PUBLIC) szDesc += " public"; else if(m_nPermission==PRIVATE) szDesc += " private"; else if(m_nPermission==PROTECTED) szDesc += " protected"; szDesc = " " + type + " " + name; SetDescription(szDesc); string command = "Impact:AddVariable " + prepareQuery(CEntityInfo::etag(pSym)) + " " + "{" + type + "}" + " " + name + " "; char strPerm[10]; sprintf(strPerm,"%d", m_nPermission); command += strPerm; string results; CEntityInfo::exec(command,results); parseResult(results); return true; }
bool CChangeBodyAction::ActionPerformed(symbolPtr* pSym) { CImpactAction::ActionPerformed(pSym); string command = CEntityInfo::getChangeBodyCommand(pSym); string results; CEntityInfo::exec(command,results); parseResult(results); return true; }
int LsHelper::makeRequest(const QByteArray& data, ChecksT& checks) { if (m_socketHandler->makeRequest(data) != 0) { m_lastError = QString("%1: %2").arg(Q_FUNC_INFO, m_socketHandler->lastError()); return -1; } parseResult(checks); return 0; }
/** * Method: GetGradesByItemID(QString _rubricItemID) * * Description: * Retrieves all student grades for a particular Rubric Item. * * Attributes: * QString _rubricItemID - the rubric item's id to get grades by * * Author: Joshua Campbell * * Version: 1 */ QList<QMap<QString, QString> > RubricItemGrade::GetGradesByItemID(QString _rubricItemID) { if (DBA.isConnected()) { std::ostringstream oss; oss << "SELECT * FROM RubricItemGrade WHERE rubricItemID='" << _rubricItemID.toStdString() << "' "; oss << "ORDER BY studentID ASC;"; QSqlQuery * query = DBA.__query(oss.str().c_str()); return parseResult(query); } }
void FbxAPI::requestLoginFinished() { QNetworkReply * reply = qobject_cast<QNetworkReply*>(sender()); QJsonDocument doc = QJsonDocument::fromJson(reply->readAll()); if(parseResult(doc)) { requestSession(); } }
ResultParser::ResultParser(QtSslCrawler *crawler) : QObject(crawler), m_crawler(crawler), m_outStream(stdout, QIODevice::WriteOnly) { connect(m_crawler, SIGNAL(crawlResult(QUrl,QUrl,QList<QSslCertificate>)), this, SLOT(parseResult(QUrl,QUrl,QList<QSslCertificate>))); connect(m_crawler, SIGNAL(crawlFinished()), this, SLOT(parseAllResults())); m_outStream << "URL containing certificate;site certificate country;root cert organization;" << "root certificate country;linking URLs\n"; }
void FbxAPI::requestAuthorizeFinished() { QNetworkReply * reply = qobject_cast<QNetworkReply*>(sender()); QJsonDocument doc = QJsonDocument::fromJson(reply->readAll()); if (parseResult(doc)) { QString appToken = doc.object().value("result").toObject().value("app_token").toString(); int trackId = doc.object().value("result").toObject().value("track_id").toDouble(); emit authorizeReceived(appToken, trackId); } }
QList<QMap<QString, QString> > Activity::getRubriclessByCourseID(QString currentCourseID){ QString sqlString = "SELECT DISTINCT * FROM Activity WHERE courseID ='"; sqlString.append(currentCourseID); sqlString.append("' AND activityID NOT IN(SELECT DISTINCT A.activityID FROM Rubric R, Activity A WHERE R.activityID = A.activityID AND A.courseID ='" ); sqlString.append(currentCourseID); sqlString.append("')"); DEBUG(DEBUG_INFO, sqlString); return parseResult(DBA.__query(sqlString)); }
void FbxAPI::requestSessionFinished() { QNetworkReply * reply = qobject_cast<QNetworkReply*>(sender()); QJsonDocument doc = QJsonDocument::fromJson(reply->readAll()); if (parseResult(doc)) { mRequestLoginAttempt = 0; mSessionToken = doc.object().value("result").toObject().value("session_token").toString(); mPermissions = doc.object().value("result").toObject().value("permissions").toObject().keys(); mLogged = true; emit sessionReceived(); emit loginSuccess(); } }
CString DLRacerInterface::sendCommand(CString strCommand) { strCommand += _T("\n"); int status; status = send(racerSocket, strCommand, strCommand.GetLength(), 0); if (status == -1) { int dwError = WSAGetLastError(); MyMessageBox_Error(_T("sendCommand")); return _T("null"); } CString strResult = readFromSocket(); return parseResult(strCommand, strResult); }
void DialogNewCamera::getApiInfo(const QString &api, const QString &method, const QString &version, std::function<void(const QString &url)> cb) { QString host = ui->dsm_url->text(); if (!host.endsWith('/')) host.append('/'); QString url = SynoApiInfo.arg(host).arg(api); QUrl u(url); QNetworkRequest request(u); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); auto reply = nm->get(request); connect(reply, &QNetworkReply::finished, [=]() { reply->deleteLater(); if (reply->error() != QNetworkReply::NoError) { QMessageBox::warning(this, tr("Calaos Installer"), reply->errorString()); cb({}); return; } QByteArray bytes = reply->readAll(); bool err; QJsonObject jdata = parseResult(bytes, err); if (err || !jdata[api].isObject()) { cb({}); return; } QJsonObject japi = jdata[api].toObject(); QString apiurl = SynoApi.arg(host) .arg(japi["path"].toString()) .arg(api) .arg(method) .arg(version); cb({apiurl}); }); }
bool CRemoveFieldAction::ActionPerformed(symbolPtr* pSym) { if(m_pFields->getRecordsCount()>0) { // if we have something to remove - display it CImpactAction::ActionPerformed(pSym); int selectedPosition; XtVaGetValues(m_FieldsList, XmNselectedPosition, &selectedPosition, NULL); TRecord* pRecord = m_pFields->getRecord(selectedPosition); string command = "Impact:DeleteVariableFromClass " + prepareQuery(*(*pRecord)[2]); SetDescription(GetName()+string(" ")+*(*pRecord)[1]); string results; CEntityInfo::exec(command,results); parseResult(results); return true; } else return false; }
bool CDeleteVariableAction::ActionPerformed(symbolPtr* pSym) { if(m_pClasses->getRecordsCount()>0) { CImpactAction::ActionPerformed(pSym); int selectedPosition; XtVaGetValues(m_ClassesList, XmNselectedPosition, &selectedPosition, NULL); TRecord* pRecord = m_pClasses->getRecord(selectedPosition); string command; string result; command = "Impact:DeleteLocalVariable " + prepareQuery(CEntityInfo::etag(pSym)) + " {" + (*pRecord)[2]->c_str() + "} " ; CEntityInfo::exec(command,result); SetDescription(GetName()+string(" ")); parseResult(result); return true; } return false; }
void Translator::match(Plasma::RunnerContext& context) { QString term = context.query(); QString text; QPair<QString, QString> language; if (!parseTerm(term, text, language)) { return; } if (!context.isValid()) { return; } QEventLoop loop; TranslatorJob job(text, language); connect(&job, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); parseResult(job.result(), context, text); }
void HttpClient::onReply(Http::Client& client) { try { Http::MessageProgress progress = client.endReceive(); if( progress.header() ) { //_impl->verifyHeader( client.reply() ); beginResult( client.reply().body() ); } if( progress.body() ) { // reads until error or XML was consumed parseResult(); // discard remaining data client.reply().discard(); } if( ! progress.finished() ) { client.beginReceive(); return; } } catch(const System::IOError&) // HttpError is also an IOError { // finished signal will call onError() setError(); finishResult(); return; } // send finished signal finishResult(); }
void FbxAPI::requestAuthorizeStatusFinished() { QNetworkReply * reply = qobject_cast<QNetworkReply*>(sender()); QJsonDocument doc = QJsonDocument::fromJson(reply->readAll()); if(parseResult(doc)) { QString statusString = doc.object().value("result").toObject().value("status").toString(); AuthStatus status; if (statusString == "unknown") status = UnknownStatus; if (statusString == "pending") status = PendingStatus; if (statusString == "timeout") status = TimeOutStatus; if (statusString == "granted") status = GrantedStatus; if (statusString == "denied") status = DeniedStatus; qDebug()<<statusString<<status; emit authorizeStatusChanged(status); } reply->deleteLater(); }
/** * Method: GetActivityGradesByStudentID(QString _activityID, QString _studentID) * * Description: * Returns a list of RubricItemGrades in the form of a map (table columns and values) for a particular activity and * a particular student. * * Attributes: * QString _activityID - the activity the grades belong to * QString _studentID - the student the grades belong to * * Author: Joshua Campbell * * Version: 1 */ QList<QMap<QString, QString> > RubricItemGrade::GetActivityGradesByStudentID(QString _activityID, QString _studentID) { QList<QMap<QString, QString> > gradeItems; Activity activityModel; QMap<QString, QString> activityMap = activityModel.GetActivityByID(_activityID); activityModel.SetParameters(activityMap); QList<QMap<QString, QString> > rubricMapList = activityModel.getRubric(); QListIterator<QMap<QString, QString> > rubricMapListIterator(rubricMapList); if (rubricMapListIterator.hasNext()) { QMap<QString, QString> rubric = rubricMapListIterator.next(); std::ostringstream oss; oss << "SELECT RubricItemGrade.gradeID, RubricItemGrade.mark, RubricItemGrade.groupID, RubricItemGrade.studentID, "; oss << "RubricItemGrade.markerPrivilege, RubricItemGrade.markerID, RubricItemGrade.rubricItemID "; oss << "FROM RubricItemGrade JOIN RubricItem ON RubricItemGrade.rubricItemID = RubricItem.rubricItemID "; oss << "WHERE RubricItem.rubricID='" << rubric["rubricID"].toStdString().c_str() << "' AND "; oss << "RubricItemGrade.studentID='" << _studentID.toStdString().c_str() << "';"; QSqlQuery * query = DBA.__query(oss.str().c_str()); gradeItems = parseResult(query); if (gradeItems.size() > 0) { DEBUG(DEBUG_ALRM, gradeItems[0]["markerPrivilege"]); } } return gradeItems; }
void AcoustidClient::requestFinished() { QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender()); if (!reply) return; reply->deleteLater(); if (!m_requests.contains(reply)) return; int id = m_requests.take(reply); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if (status != 200) { QTextStream body(reply); qDebug() << "AcoustIdClient POST reply status:" << status << "body:" << body.readAll(); emit(networkError( reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), "AcoustID")); return; } QTextStream textReader(reply); QString body = textReader.readAll(); qDebug() << "AcoustIdClient POST reply status:" << status << "body:" << body; QXmlStreamReader reader(body); QString ID; while (!reader.atEnd()) { if (reader.readNext() == QXmlStreamReader::StartElement && reader.name()== "results") { ID = parseResult(reader); } } emit(finished(id, ID)); }
void DialogNewCamera::listCameras(std::function<void(const QJsonArray &arr)> dataCb) { QString url = listUrl; url += QStringLiteral("&_sid=%1").arg(apiSid); QUrl u(url); QNetworkRequest request(u); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); auto reply = nm->get(request); connect(reply, &QNetworkReply::finished, [=]() { reply->deleteLater(); if (reply->error() != QNetworkReply::NoError) { QMessageBox::warning(this, tr("Calaos Installer"), reply->errorString()); dataCb({}); return; } QByteArray bytes = reply->readAll(); bool err; QJsonObject jdata = parseResult(bytes, err); if (err) QMessageBox::warning(this, tr("Calaos Installer"), tr("Failed to list cameras")); if (err || !jdata["cameras"].isArray()) { dataCb({}); return; } dataCb(jdata["cameras"].toArray()); }); }
void LH_QtPlugin_TS3::TS3DataReceived() { QString receivedMsg = QString::fromUtf8(socket_->readAll()); //QRegExp rxSCHandler("selected schandlerid=([0-9]*)"); QRegExp rxNotify("notify(\\w*) schandlerid=([0-9]*) (.*)"); QRegExp rxMyID("clid=([0-9]*) cid=([0-9]*)"); responseResult result = parseResult(receivedMsg); if(result.isResult && !result.isValid) { if(result.errorCode == 1794) { channels_.clear(); clients_.clear(); speakers_.clear(); updateTalking(); #ifdef TS3_DEBUG_MESSAGES qDebug() << "LH_TS3: Client is not connected to a server."; #endif updateStatus(true); } else { qWarning() << QString("LH_TS3: Unhandled Response Error: %1%2 (%3)").arg(result.errorMessage, (result.extraMessage==""?"":QString(" (%1)").arg(result.extraMessage))).arg(result.errorCode); // Q_ASSERT(false); } } else if(rxNotify.indexIn(receivedMsg)!=-1) { if(rxNotify.cap(1)=="talkstatuschange") talkChanged(rxNotify.cap(3)); if(QString("clientleftview,cliententerview,clientupdated,clientmoved").split(',').contains(rxNotify.cap(1)) || QString("channelcreated,channeledited,channeldeleted,channelmoved").split(',').contains(rxNotify.cap(1)) ) { #ifndef TS3_USER_DEFINED_UID request_WhoAmI(); #else request_ChannelList(); #endif } } else switch(server_action_) { case sa_eventregister_pending: if(!result.isResult) break; #ifndef TS3_USER_DEFINED_UID request_WhoAmI(); #else request_ChannelList(); #endif break; case sa_whoami_pending: if(rxMyID.indexIn(receivedMsg)!=-1) { myclid_ = rxMyID.cap(1).toInt(); updateMyDetails(); request_ChannelList(); } break; case sa_channellist_pending: if(channels_.load(receivedMsg)) { #ifdef TS3_USER_DEFINED_UID updateMyDetails(); #endif updateStatus(true,true,true); #ifdef TS3_DEBUG_MESSAGES qDebug()<<"LH_TS3: Server has " << channels_.count() << " channel(s)"; #endif request_ClientList(); } break; case sa_clientlist_pending: if(clients_.load(receivedMsg)) { updateStatus(true,true,true,true); server_action_ = sa_listening; updateMyDetails(); } break; case sa_none: case sa_disconnected: case sa_connecting: case sa_reconnect: case sa_listening: break; } }
/* parseMessage * Reads message from client */ static int parseMessage(int newsockfd) { char buffer[BUFSIZ]; int n; /* Initialize buffers */ char *wholeMessage = (char*) malloc(READBUFFERSIZE*sizeof(char)); memset(wholeMessage, 0, READBUFFERSIZE); memset(buffer, 0, BUFSIZ); /* Start reading */ n = read(newsockfd, buffer, BUFSIZ); if (n < 0) { fprintf(stderr,"Error: failed to read from socket\n"); return -1; } /* reading a result message, must call read several times */ else if(n > 10) { /* Discard garbage at the end */ buffer[n] = '\0'; /* append to wholeMessage */ strcat(wholeMessage, buffer); /* Clear buffer before reading next chunk */ memset(buffer, 0, BUFSIZ); do { n = read(newsockfd, buffer, BUFSIZ); if (n < 0) { fprintf(stderr,"Error: failed to read from socket\n"); return -1; } else { /* Discard garbage at the end */ buffer[n] = '\0'; /* append to wholeMessage */ strcat(wholeMessage, buffer); /* Clear buffer before reading next chunk */ memset(buffer, 0, BUFSIZ); } } while(n > 0); } /* reading a request message, one read is enough */ else { strcpy(wholeMessage, buffer); } char* result = strdup(wholeMessage); /* Free wholeMessage */ free(wholeMessage); /* Parse message from client */ /* Check first digit of message and verify if it is a * a result or a request */ char *pch; pch = strtok(result, ":"); if(pch[0] == RESULT) { /* Parse rest of the message */ parseResult(pch); } else if(pch[0] == REQUEST) { /* Send hint to the client */ int workingSize; int hint = parseRequest(pch, &workingSize); int ret; if(hint) ret = sendHint(newsockfd, workingSize); else ret = denyRequest(newsockfd); } close(newsockfd); /* Free memory */ free(result); return 1; }
void *doInput(void *details) { prodcons *toProg; Action action; const size_t BUFF_INC = 1000; char inputBuffer[BUFF_INC], *wholeBuffer, *newline, *stripped, *theinput, *firstspace, *command; char *rest; int temp, xboardmode = 0, done = 0; size_t commandLength, currentMaxLength, currentBufferLength; #ifdef DEBUG FILE *debugFile; debugFile = fopen("iolog.log","w"); setlinebuf(debugFile); #endif newline = NULL; toProg = ((threadParameter *) details)->input; wholeBuffer = (char *) xmalloc(BUFF_INC); currentMaxLength = BUFF_INC; while (done == 0) { currentBufferLength = 0; memset((void *) wholeBuffer, '\0', currentMaxLength); do { if (fgets(inputBuffer, BUFF_INC, stdin) == NULL) { done = -1; break; } currentBufferLength += BUFF_INC; if (currentBufferLength > currentMaxLength) { wholeBuffer = (char *) xrealloc((void *) wholeBuffer, currentBufferLength); currentMaxLength = currentBufferLength; } wholeBuffer = strcat(wholeBuffer, inputBuffer); newline = strchr(wholeBuffer, '\n'); } while (newline == NULL); if (newline == NULL) { fprintf(stderr, "Error reading from input\n"); continue; } *newline = '\0'; #ifdef DEBUG fprintf(debugFile,"%s\n",wholeBuffer); #endif stripped = strip(wholeBuffer); action.command = xstrdup(stripped); theinput = uppercase(stripped); free(stripped); if ((theinput != NULL) && (strlen(theinput) > 0)) { firstspace = strchr(theinput, ' '); if (firstspace == NULL) { commandLength = strlen(theinput); rest = NULL; } else { commandLength = firstspace - theinput; rest = xstrdup(firstspace + 1); } /* if (rest != NULL) { * printf("rest: %s\n",rest); * } */ command = (char *) xmalloc(commandLength + 1); memcpy(command, theinput, commandLength); command[commandLength] = '\0'; if (strcmp(command, "USERMOVE") == 0) { action.theType = USERMOVE; if (parseMove(rest, &action.data.move) < 0) { action.data.move.from = -1; } putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_SANMOVE") == 0) || ((!xboardmode) && (strcmp(command, "SANMOVE") == 0))) { action.theType = SP_SANMOVE; action.data.message = (char *) xstrdup(action.command + commandLength + 1); if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "XBOARD") == 0) { xboardmode = 1; action.theType = XBOARD; putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "PROTOVER") == 0) { action.theType = PROTOVER; action.data.message = rest; putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "ACCEPTED") == 0) { action.theType = ACCEPTED; action.data.feature = stringToFeature(rest); if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "REJECTED") == 0) { action.theType = REJECTED; action.data.feature = stringToFeature(rest); if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "NEW") == 0) { action.theType = NEW; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "VARIANT") == 0) { action.theType = VARIANT; action.data.message = rest; putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "QUIT") == 0) { action.theType = QUIT; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "RANDOM") == 0) { action.theType = RANDOM; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "FORCE") == 0) { action.theType = FORCE; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "GO") == 0) { action.theType = GO; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "PLAYOTHER") == 0) { action.theType = PLAYOTHER; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "WHITE") == 0) { action.theType = WHITE; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "BLACK") == 0) { action.theType = BLACK; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "LEVEL") == 0) { action.theType = LEVEL; if (parseLevel(rest, &action.data.timecontrol) == 0) { putAction(toProg, &action); } if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "SD") == 0) { action.theType = SD; action.data.depth = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "ST") == 0) { action.theType = ST; action.data.time = parseInteger(rest) * 100; putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "TIME") == 0) { action.theType = TIME; action.data.time = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "OTIM") == 0) { action.theType = OTIM; action.data.time = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "?") == 0) { action.theType = MOVENOW; putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "PING") == 0) { action.theType = PING; action.data.time = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "DRAW") == 0) { action.theType = DRAW; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "RESULT") == 0) { action.theType = RESULT; if (parseResult(rest, &action.data.result) == 0) { putAction(toProg, &action); } if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "SETBOARD") == 0) { action.theType = SETBOARD; if (rest != NULL) { free(rest); rest = NULL; } action.data.message = (char *) xstrdup(action.command + commandLength + 1); putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "EDIT") == 0) { action.theType = EDIT; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "HINT") == 0) { action.theType = HINT; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "BK") == 0) { action.theType = BK; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "UNDO") == 0) { action.theType = UNDO; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "REMOVE") == 0) { action.theType = REMOVE; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "HARD") == 0) { action.theType = HARD; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "EASY") == 0) { action.theType = EASY; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "POST") == 0) { action.theType = POST; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "NOPOST") == 0) { action.theType = NOPOST; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "EXIT") == 0) { action.theType = EXIT; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "ANALYZE") == 0) { action.theType = ANALYZE; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, ".") == 0) { action.theType = UPDATESTATUS; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "NAME") == 0) { action.theType = NAME; action.data.message = rest; putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "RATING") == 0) { action.theType = RATING; temp = parseRatings(rest, &action.data.ratings); if (rest != NULL) { free(rest); rest = NULL; } if (temp == 0) { putAction(toProg, &action); } else { free(action.command); } goto ENDPARSE; } if (strcmp(command, "ICS") == 0) { action.theType = ICS; action.data.message = rest; putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "COMPUTER") == 0) { action.theType = COMPUTER; putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_DEBUG") == 0) || ((!xboardmode) && (strcmp(command, "DEBUG") == 0))){ action.theType = DEBUG; action.data.message = rest; putAction(toProg, &action); goto ENDPARSE; } if ((strcmp(command, "SP_MOVETOSAN") == 0) || ((!xboardmode) && (strcmp(command, "MOVETOSAN") == 0))){ action.theType = SP_MOVETOSAN; if (parseMove(rest, &action.data.move) < 0) { action.data.move.from = -1; } putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_BENCHMOVEUNMOVE") == 0) || ((!xboardmode) && (strcmp(command, "BENCHMOVEUNMOVE") == 0))) { action.theType = SP_BENCHMOVEUNMOVE; if (parseMove(rest, &action.data.move) < 0) { action.data.move.from = -1; } putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_BENCHMOVEGEN") == 0) || ((!xboardmode) && (strcmp(command, "BENCHMOVEGEN") == 0))){ action.theType = SP_BENCHMOVEGEN; action.data.time = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_BENCHMOVECYCLE") == 0) || ((!xboardmode) && (strcmp(command, "BENCHMOVECYCLE") == 0))) { action.theType = SP_BENCHMOVECYCLE; action.data.time = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_BENCHEVAL") == 0) || ((!xboardmode) && (strcmp(command, "BENCHEVAL") == 0))) { action.theType = SP_BENCHEVAL; action.data.time = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_PERFT") == 0) || ((!xboardmode) && (strcmp(command, "PERFT") == 0))) { action.theType = SP_PERFT; action.data.depth = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_EPDSUITE") == 0) || ((!xboardmode) && (strcmp(command, "EPDSUITE") == 0))) { action.theType = SP_EPDSUITE; action.data.message = (char *) xstrdup(action.command + commandLength + 1); if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if ((strcmp(command, "SP_EPDLINE") == 0) || ((!xboardmode) && (strcmp(command, "EPDLINE") == 0))) { action.theType = SP_EPDLINE; action.data.message = (char *) xstrdup(action.command + commandLength + 1); if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if ((strcmp(command, "SP_MODIFYBOOK") == 0) || ((!xboardmode) && (strcmp(command, "MODIFYBOOK") == 0))) { action.theType = SP_MODIFYBOOK; action.data.message = (char *) xstrdup(action.command + commandLength + 1); if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if ((strcmp(command, "SP_CLOSEBOOK") == 0) || ((!xboardmode) && (strcmp(command, "CLOSEBOOK") == 0))) { action.theType = SP_CLOSEBOOK; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if ((strcmp(command, "SP_SHOWMOVES") == 0) || ((!xboardmode) && (strcmp(command, "SHOWMOVES") == 0))) { action.theType = SP_SHOWMOVES; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if ((strcmp(command, "SP_EVALUATE") == 0) || ((!xboardmode) && (strcmp(command, "EVALUATE") == 0))) { action.theType = SP_EVALUATE; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "HELP") == 0) { action.theType = HELP; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if ((strcmp(command, "SP_EPDMINDEPTH") == 0) || ((!xboardmode) && (strcmp(command, "EPDMINDEPTH") == 0))) { action.theType = SP_EPDMINDEPTH; action.data.depth = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } action.theType = UNKNOWN_COMMAND; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); ENDPARSE:; } free(theinput); theinput = NULL; } free(wholeBuffer); #ifdef DEBUG fclose(debugFile); #endif return NULL; }
void StationScheduleModel::parse(const QByteArray &htmlReply, const QUrl &baseUrl) { Q_UNUSED(baseUrl); qDebug() << "--- start of query result --- cut here ------"; qDebug() << QString::fromUtf8(htmlReply.constData()); qDebug() << "--- end of query result ----- cut here ------"; emit layoutAboutToBeChanged(); beginResetModel(); QWebPage page; page.mainFrame()->setContent(htmlReply, "text/html", baseUrl); QWebElement doc = page.mainFrame()->documentElement(); // Check if the page is reporting an error before parsing it QWebElement errorElement = doc.findFirst("span.errore"); if (!errorElement.isNull()) { m_departureSchedules.clear(); m_arrivalSchedules.clear(); QString errorText = errorElement.toPlainText().trimmed(); if (errorText == "localita' non trovata") { setError(tr("Unknown station")); } else { setError(tr("Unknown error")); } qDebug() << "error:" << error(); return; } // Find the first div QWebElement current = doc.findFirst("div"); qDebug() << "skipping to the departures"; // Skip to the first div of class corpocentrale, which contains the first // departure-related contents while (!current.classes().contains("corpocentrale")) { current = current.nextSibling(); qDebug() << "skipping to the next element"; if (current.isNull()) break; } // Mark every div as a departure class element; the next corpocentrale // marks the start of the arrivals section qDebug() << "marking departures"; do { if (current.classes().contains("bloccorisultato")) { StationScheduleItem schedule = parseResult(current); if (schedule.isValid()) { m_departureSchedules << schedule; } } current = current.nextSibling(); qDebug() << "marking as departures"; if (current.isNull()) break; } while (!current.classes().contains("corpocentrale")); // Mark everything as an arrival, until reaching the footer while (!current.classes().contains("footer")) { if (current.classes().contains("bloccorisultato")) { StationScheduleItem schedule = parseResult(current); if (schedule.isValid()) { m_arrivalSchedules << schedule; } } current = current.nextSibling(); qDebug() << "marking as arrival"; if (current.isNull()) break; } endResetModel(); emit layoutChanged(); }
QString QNapiComplexResult::osRes() const { return parseResult(m_os); }