예제 #1
0
/**
 * Get compile error info from SCU
 * @param bott      Result bott file
 * @return Compile error info
 */
string SCUJudger::getCEinfo(Bott * bott)
{
	prepareCurl();
	curl_easy_setopt(curl, CURLOPT_URL,
			 ("http://cstest.scu.edu.cn/soj/judge_message.action?id="
			  + bott->Getremote_runid()).c_str());
	performCurl();

	string info = loadAllFromFile(tmpfilename);
	string result;

	char *ce_info = new char[info.length() + 1];
	strcpy(ce_info, info.c_str());
	char *buffer = new char[info.length() * 2];
	// SCU is in GBK charset
	charset_convert("GBK", "UTF-8//TRANSLIT", ce_info, info.length() + 1,
			buffer, info.length() * 2);

	if (!RE2::PartialMatch(buffer, "(?s)<pre>(.*?)</pre>", &result)) {
		return "";
	}

	strcpy(buffer, result.c_str());
	decode_html_entities_utf8(buffer, NULL);
	result = buffer;
	delete[]ce_info;
	delete[]buffer;

	return result;
}
예제 #2
0
/**
 * Get compile error info
 * @param bott      Result bott file
 * @return Compile error info
 */
string NJUPTJudger::getCEinfo(Bott * bott)
{

	prepareCurl();
	curl_easy_setopt(curl, CURLOPT_URL,
			 ("http://acm.njupt.edu.cn/acmhome/compileError.do?id="
			  + bott->Getremote_runid()).c_str());
	performCurl();

	string info = loadAllFromFile(tmpfilename);
	string result;
	char *ce_info = new char[info.length() + 1];
	strcpy(ce_info, info.c_str());
	char *buffer = new char[info.length() * 2];
	// SCU is in GBK charset
	charset_convert("GBK", "UTF-8//TRANSLIT", ce_info, info.length() + 1,
			buffer, info.length() * 2);

	if (!RE2::PartialMatch(buffer,
			       "(?s)Details of Compile Error</strong></h2></div>(.*)<div align=\"center\">",
			       &result)) {
		return "";
	}

	strcpy(buffer, result.c_str());
	decode_html_entities_utf8(buffer, NULL);
	result = buffer;
	delete[]ce_info;
	delete[]buffer;

	return trim(result);
}
예제 #3
0
/**
 * Submit a run
 * @param bott      Bott file for Run info
 * @return Submit status
 */
int LOJJudger::submit(Bott * bott) {

  // prepare form for post
  struct curl_httppost * formpost = NULL;
  struct curl_httppost * lastptr = NULL;
  curl_formadd(&formpost, &lastptr,
               CURLFORM_COPYNAME, "sub_problem",
               CURLFORM_COPYCONTENTS, bott->Getvid().c_str(),
               CURLFORM_END);
  curl_formadd(&formpost, &lastptr,
               CURLFORM_COPYNAME, "language",
               CURLFORM_COPYCONTENTS,
                   convertLanguage(bott->Getlanguage()).c_str(),
               CURLFORM_END);
  curl_formadd(&formpost, &lastptr,
               CURLFORM_COPYNAME, "code",
               CURLFORM_COPYCONTENTS, bott->Getsrc().c_str(),
               CURLFORM_END);

  prepareCurl();
  curl_easy_setopt(curl, CURLOPT_URL,
                   "http://www.lightoj.com/volume_submit.php");
  curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
  performCurl();
  curl_formfree(formpost);

  // check submit status
  string html = loadAllFromFile(tmpfilename);
  if (html.find(
      "<script>location.href='volume_usersubmissions.php'</script>") ==
      string::npos) {
    return SUBMIT_OTHER_ERROR;
  }
  return VirtualJudger::SUBMIT_NORMAL;
}
예제 #4
0
/**
 * Get run details from Codeforces
 * @param contest       Contest ID
 * @param runid         Remote runid
 * @return Verdict details
 */
string CFJudger::getVerdict(string contest, string runid) {
  prepareCurl();
  curl_easy_setopt(curl, CURLOPT_URL, getVerdictUrl(contest, runid).c_str());
  performCurl();

  string html = loadAllFromFile(tmpfilename);
  htmlcxx::HTML::ParserDom parser;
  tree<htmlcxx::HTML::Node> dom = parser.parseTree(html);
  hcxselect::Selector selector(dom);

  // load all roundbox in verdict page
  try {
    selector = selector.select("#content .roundbox");
  } catch (...) {
    log("Parse verdict error, use empty result instead.");
    return "";
  }

  // find the one contains error message
  for (hcxselect::Selector::const_iterator it = selector.begin();
      it != selector.end(); ++it) {
    string content = html.substr((*it)->data.offset(), (*it)->data.length());
    if (content.find("<div  class=\"error\">") != string::npos) return content;
  }

  return "";
}
예제 #5
0
/**
 * Get input=hidden stuffs for submit
 * @param code  Problem code
 * @return Hidden params in pairs
 */
vector < pair < string, string > >CCJudger::getSubmitHiddenParams(string code)
{
	prepareCurl();
	curl_easy_setopt(curl, CURLOPT_URL,
			 ((string) "http://www.codechef.com/submit/" +
			  code).c_str());
	performCurl();

	string html = loadAllFromFile(tmpfilename);
	string form;
	// login form
	if (!RE2::PartialMatch
	    (html, "(?s)(<form.*?node-form.*?</form>)", &form)) {
		throw Exception("Failed to get hidden params.");
	}
	string key, value;
	vector < pair < string, string > >result;
	// get all hidden params
	re2::StringPiece formString(form);
	while (RE2::FindAndConsume(&formString,
				   "(?s)<input type=\"hidden\".*?name=\"(.*?)\".*?value=\"(.*?)\"",
				   &key, &value)) {
		result.push_back(make_pair(key, value));
	}
	return result;
}
예제 #6
0
/**
 * Get compile error info
 * @param bott      Result bott file
 * @return Compile error info
 */
string AizuJudger::getCEinfo(Bott * bott) {

  prepareCurl();
  curl_easy_setopt(curl, CURLOPT_URL,
      ((string) "http://judge.u-aizu.ac.jp/onlinejudge/compile_log.jsp?runID=" +
      bott->Getremote_runid()).c_str());
  performCurl();

  // Aizu is in SHIFT_JIS charset
  string info = charsetConvert("SHIFT_JIS", "UTF-8",
      loadAllFromFile(tmpfilename));
  string result;
  char * buffer = new char[info.length() * 2];

  if (!RE2::PartialMatch(info,
                         "(?s)<p style=\"font-size:11pt;\">(.*)</p>",
                         &result)) {
    return "";
  }

  strcpy(buffer, result.c_str());
  decode_html_entities_utf8(buffer, NULL);
  result = buffer;
  delete [] buffer;

  return trim(result);
}
예제 #7
0
/**
 * Submit a run
 * @param bott      Bott file for Run info
 * @return Submit status
 */
int ZJUJudger::submit(Bott * bott)
{

	prepareCurl();
	curl_easy_setopt(curl, CURLOPT_URL,
			 "http://acm.zju.edu.cn/onlinejudge/submit.do");
	string post =
	    (string) "problemCode=" + bott->Getvid() + "&languageId=" +
	    bott->Getlanguage() + "&source=" + escapeURL(bott->Getsrc());
	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
	performCurl();

	// check submit status
	string html = loadAllFromFile(tmpfilename);
	if (html.find("Submit Successfully</div>") == string::npos) {
		return SUBMIT_OTHER_ERROR;
	}
	// parse remote runid from submit page
	string runid;
	if (!RE2::PartialMatch
	    (html, "(?s)The submission id is.*?>(.*?)<", &runid)) {
		return SUBMIT_OTHER_ERROR;
	}
	bott->Setremote_runid(runid);
	return VirtualJudger::SUBMIT_NORMAL;
}
예제 #8
0
/**
 * Get result and related info
 * @param bott  Original Bott info
 * @return Result Bott file
 */
Bott *SCUJudger::getStatus(Bott * bott)
{
	time_t begin_time = time(NULL);

	Bott *result_bott;
	while (true) {
		// check wait time
		if (time(NULL) - begin_time > info->GetMax_wait_time()) {
			throw
			    Exception
			    ("Failed to get current result, judge time out.");
		}

		prepareCurl();
		curl_easy_setopt(curl, CURLOPT_URL,
				 ("http://cstest.scu.edu.cn/soj/solutions.action?userId="
				  + escapeURL(info->GetUsername()) +
				  "&problemId=" + bott->Getvid()).c_str());
		performCurl();

		string html = loadAllFromFile(tmpfilename);
		string status;
		string runid, result, time_used, memory_used;

		// get first row
		if (!RE2::PartialMatch(html,
				       "(?s).*<table.*?<tr.*?(<tr.*?<td height=\"44\">.*?</tr>)",
				       &status)) {
			throw Exception("Failed to get status row.");
		}
		// get result
		if (!RE2::PartialMatch(status,
				       "(?s)<td.*?>([0-9]*).*?<font.*?>(.*)</font>",
				       &runid, &result)) {
			throw Exception("Failed to get current result.");
		}
		result = trim(result);
		if (isFinalResult(result)) {
			// result is the final one
			result = convertResult(result);
			if (!RE2::PartialMatch(status,
					       "(?s)<td.*?>([0-9]*).*?<font.*?>.*</font>.*?<td>(.*?)</td>.*?<td>(.*?)</td>",
					       &runid, &time_used,
					       &memory_used)) {
				throw
				    Exception
				    ("Failed to parse details from status row.");
			}
			result_bott = new Bott;
			result_bott->Settype(RESULT_REPORT);
			result_bott->Setresult(result);
			result_bott->Settime_used(trim(time_used));
			result_bott->Setmemory_used(trim(memory_used));
			result_bott->Setremote_runid(trim(runid));
			break;
		}
	}
	return result_bott;
}
예제 #9
0
/**
 * Get result and related info
 * @param bott  Original Bott info
 * @return Result Bott file
 */
Bott * LOJJudger::getStatus(Bott * bott) {
  time_t begin_time = time(NULL);

  Bott * result_bott;
  while (true) {
    // check wait time
    if (time(NULL) - begin_time > info->GetMax_wait_time()) {
      throw Exception("Failed to get current result, judge time out.");
    }

    prepareCurl();
    curl_easy_setopt(curl, CURLOPT_URL,
                     "http://www.lightoj.com/volume_usersubmissions.php");
    performCurl();

    string html = loadAllFromFile(tmpfilename);
    string status;
    string runid, result, time_used, memory_used;

    // get first row
    if (!RE2::PartialMatch(html, "(?s)(<tr class=\"newone\">.*?</tr>)",
                           &status)) {
      throw Exception("Failed to get status row.");
    }

    // get result
    if (!RE2::PartialMatch(status, "(?s)sub_id=([0-9]*).*?<div.*?>(.*?)</div>",
                           &runid, &result)) {
      throw Exception("Failed to get current result.");
    }
    result = trim(result);
    if (isFinalResult(result)) {
      // result is the final one
      result = convertResult(result);
      if (result != "Compile Error") {
        // no details for CE results
        if (!RE2::PartialMatch(
            status,
            "(?s)sub_id=([0-9]*).*?<td.*?<td.*?<td.*?<td.*?>(.*?)</td"
                ".*?<td.*?>(.*?)</td>",
            &runid, &time_used, &memory_used)) {
          throw Exception("Failed to parse details from status row.");
        }
        int time_ms = stringToDouble(time_used) * 1000 + 0.001;
        time_used = intToString(time_ms);
      } else {
        memory_used = time_used = "0";
      }
      result_bott = new Bott;
      result_bott->Settype(RESULT_REPORT);
      result_bott->Setresult(result);
      result_bott->Settime_used(stringToInt(time_used));
      result_bott->Setmemory_used(stringToInt(memory_used));
      result_bott->Setremote_runid(trim(runid));
      break;
    }
  }
  return result_bott;
}
예제 #10
0
/**
 * Get result and related info
 * @param bott  Original Bott info
 * @return Result Bott file
 */
Bott * HRBUSTJudger::getStatus(Bott * bott) {
    time_t begin_time = time(NULL);

    Bott * result_bott;
    while (true) {
        // check wait time
        if (time(NULL) - begin_time > info->GetMax_wait_time()) {
            throw Exception("Failed to get current result, judge time out.");
        }

        prepareCurl();
        curl_easy_setopt(
            curl, CURLOPT_URL,
            ((string) "http://acm.hrbust.edu.cn/index.php?m=Status&a="
             "showStatus&problem_id=" + escapeURL(bott->Getvid()) +
             "&user_name=" + escapeURL(info->GetUsername()) + "&language=" +
             convertLanguage(bott->Getlanguage())).c_str());
        performCurl();

        string html = loadAllFromFile(tmpfilename);
        string status;
        string runid, result, time_used, memory_used;

        // get first row
        if (html.find("var is_login=\"\";") != string::npos ||
                !RE2::PartialMatch(html,
                                   "(?s)<table class=\"ojlist\".*?<tr.*?(<tr.*?</tr>)",
                                   &status)) {
            throw Exception("Failed to get status row.");
        }

        // get result
        if (!RE2::PartialMatch(status,
                               "(?s)<td.*?<td>([0-9]*).*?<td.*?<td.*?>(.*?)</td>",
                               &runid, &result)) {
            throw Exception("Failed to get current result.");
        }
        result = convertResult(trim(result));
        if (isFinalResult(result)) {
            // result is the final one
            if (!RE2::PartialMatch(status,
                                   "(?s)>([0-9]*)ms.*?>([0-9]*)k", &time_used,
                                   &memory_used)) {
                throw Exception("Failed to parse details from status row.");
            }
            result_bott = new Bott;
            result_bott->Settype(RESULT_REPORT);
            result_bott->Setresult(result);
            result_bott->Settime_used(stringToInt(time_used));
            result_bott->Setmemory_used(stringToInt(memory_used));
            result_bott->Setremote_runid(trim(runid));
            break;
        }
    }
    return result_bott;
}
예제 #11
0
/**
 * CF needs a _tta for every request, calculated according to _COOKIE[39ce7]
 * @return _tta
 */
string CFJudger::getttaValue() {
  string cookies = loadAllFromFile(cookiefilename);
  string magic;

  if (!RE2::PartialMatch(cookies, "39ce7\\t(.*)", &magic)) {
    throw Exception("Failed to get magic cookie for tta.");
  }
  string tta = intToString(calculatetta(magic));
  log("tta Value: " + tta);
  return tta;
}
예제 #12
0
/**
 * Get compile error info from ZJU
 * @param bott      Result bott file
 * @return Compile error info
 */
string ZJUJudger::getCEinfo(Bott * bott) {
  prepareCurl();
  curl_easy_setopt(
      curl, CURLOPT_URL,
      ((string) "http://acm.zju.edu.cn/onlinejudge/showJudgeComment.do?"
          "submissionId=" + submission_id_for_ce).c_str());
  performCurl();

  string info = loadAllFromFile(tmpfilename);
  return info;
}
예제 #13
0
/**
 * Get compile error info from LOJ
 * @param bott      Result bott file
 * @return Compile error info
 */
string LOJJudger::getCEinfo(Bott * bott) {
  prepareCurl();
  curl_easy_setopt(
      curl, CURLOPT_URL,
      ((string)"http://www.lightoj.com/volume_showcode.php?sub_id=" +
          bott->Getremote_runid()).c_str());
  performCurl();

  string info = loadAllFromFile(tmpfilename);
  string result;
  if (!RE2::PartialMatch(info, "(?s)<textarea.*?>(.*?)</textarea>", &result)) {
    return "";
  }
  return result;
}
예제 #14
0
/**
 * Get Csrf token
 * @param url   URL you need to get csrf token
 * @return Csrf token for current session
 */
string CFJudger::getCsrfParams(string url) {

  prepareCurl();
  curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
  performCurl();

  // Format:
  // <meta name="X-Csrf-Token" content="21d5gfa7bceebhe5f45d6f5eb7930ea7"/>
  string html = loadAllFromFile(tmpfilename);
  string csrf;
  if (!RE2::PartialMatch(html, "X-Csrf-Token.*content=\"(.*?)\"", &csrf)) {
    throw Exception("Failed to get Csrf token.");
  }
  return csrf;
}
예제 #15
0
/**
 * Get compile error info from SPOJ
 * @param bott      Result bott file
 * @return Compile error info
 */
string SPOJJudger::getCEinfo(Bott * bott) {
  prepareCurl();
  curl_easy_setopt(
      curl, CURLOPT_URL,
      ((string) "http://www.spoj.com/error/" +
          bott->Getremote_runid()).c_str());
  performCurl();

  string info = loadAllFromFile(tmpfilename);
  string result;
  if (!RE2::PartialMatch(info, "(?s)<small>(.*?)</small>", &result)) {
    return "";
  }
  return result;
}
예제 #16
0
/**
 * Login to Aizu
 */
void AizuJudger::login() {
  prepareCurl();
  curl_easy_setopt(curl, CURLOPT_URL,
                   "http://judge.u-aizu.ac.jp/onlinejudge/index.jsp");
  string post = (string) "loginUserID=" + info->GetUsername() +
      "&loginPassword="******"&submit=Sign+in";
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
  performCurl();

  string html = loadAllFromFile(tmpfilename);
  //cout<<ts;
  if (html.find("<span class=\"line\">Login</span>") != string::npos) {
    throw Exception("Login failed!");
  }
}
예제 #17
0
/**
 * Login to LOJ
 */
void LOJJudger::login() {

  prepareCurl();
  curl_easy_setopt(curl, CURLOPT_URL, "http://www.lightoj.com/login_check.php");
  string post = "myuserid=" + escapeURL(info->GetUsername()) +
      "&mypassword="******"&Submit=Login";
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
  performCurl();

  // check login status
  string html = loadAllFromFile(tmpfilename);
  if (html.find("login_main.php") != string::npos) {
    throw Exception("Login failed!");
  }
}
예제 #18
0
/**
 * Login to NJUPT
 */
void NJUPTJudger::login() {
  prepareCurl();
  curl_easy_setopt(curl, CURLOPT_URL,
                   "http://acm.njupt.edu.cn/acmhome/login.do");
  string post = (string) "userName="******"&password="******"<div style=\"color:red;\"><UL><LI>") != string::npos) {
    throw Exception("Login failed!");
  }
}
예제 #19
0
/**
 * Login to ZJU
 */
void ZJUJudger::login() {

  prepareCurl();
  curl_easy_setopt(curl, CURLOPT_URL,
                   "http://acm.zju.edu.cn/onlinejudge/login.do");
  string post = "handle=" + escapeURL(info->GetUsername()) +
      "&password="******"Handle or password is invalid.") != string::npos) {
    throw Exception("Login failed!");
  }
}
예제 #20
0
/**
 * Login to SPOJ
 */
void SPOJJudger::login() {

  prepareCurl();
  curl_easy_setopt(curl, CURLOPT_REFERER, "http://www.spoj.com/logout");
  curl_easy_setopt(curl, CURLOPT_URL, "http://www.spoj.com/logout");
  string post = "login_user="******"&password="******"&submit=Log+In";
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
  performCurl();

  // check login status
  string html = loadAllFromFile(tmpfilename);
  if (html.find("Authentication failed! <br/><a href=\"/forgot\">") !=
      string::npos) {
    throw Exception("Login failed!");
  }
}
예제 #21
0
/**
 * Login to HRBUST
 */
void HRBUSTJudger::login() {
    prepareCurl();
    curl_easy_setopt(curl, CURLOPT_URL,
                     "http://acm.hrbust.edu.cn/index.php?m=User&a=login");
    string post = (string) "m=User&a=login&ajax=1&user_name=" +
                  escapeURL(info->GetUsername()) + "&password="******"{\"status\":0") != string::npos ||
            html.find("<div class='body'>Sorry!Login Error,Please Retry!</div>") !=
            string::npos) {
        throw Exception("Login failed!");
    }
}
예제 #22
0
/**
 * Submit a run
 * @param bott      Bott file for Run info
 * @return Submit status
 */
int HRBUSTJudger::submit(Bott * bott) {
    prepareCurl();
    curl_easy_setopt(curl,
                     CURLOPT_URL,
                     "http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=postCode");
    string post = (string) "jumpUrl=&language=" +
                  convertLanguage(bott->Getlanguage()) + "&problem_id=" + bott->Getvid() +
                  "&source_code=" + escapeURL(bott->Getsrc());
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
    performCurl();

    string html = loadAllFromFile(tmpfilename);
    if (html.find("<html") == string::npos ||
            html.find("var is_login=\"\";") != string::npos)
        return SUBMIT_OTHER_ERROR;
    return SUBMIT_NORMAL;
}
예제 #23
0
/**
 * Login to CodeChef
 */
void CCJudger::login() {
  string hiddenParams = getLoginHiddenParams();

  prepareCurl();
  curl_easy_setopt(curl, CURLOPT_URL,
                   "https://www.codechef.com/node?destination=node");
  string post = hiddenParams + "name=" + escapeURL(info->GetUsername()) +
      "&pass="******"&submit.x=0&submit.y=0";
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
  performCurl();

  // check login status
  string html = loadAllFromFile(tmpfilename);
  if (html.find("<a class=\"login-link\"") != string::npos) {
    throw Exception("Login failed!");
  }
}
예제 #24
0
/**
 * Get compile error info
 * @param bott      Result bott file
 * @return Compile error info
 */
string HRBUSTJudger::getCEinfo(Bott * bott) {

    prepareCurl();
    curl_easy_setopt(
        curl, CURLOPT_URL,
        ((string)"http://acm.hrbust.edu.cn/index.php?m=Status&a="
         "showCompileError&run_id=" + bott->Getremote_runid()).c_str());
    performCurl();

    string info = loadAllFromFile(tmpfilename);
    string result;
    if (!RE2::PartialMatch(info, "(?s)showcode_mod_info.*?>(.*?)</td>",
                           &result)) {
        return "";
    }

    return result;
}
예제 #25
0
/**
 * Get compile error info from CodeForces
 * @param bott      Result bott file
 * @return Compile error info
 */
string CFJudger::getCEinfo(Bott * bott) {
  string csrf = getCsrfParams("http://codeforces.com/problemset/submit");

  prepareCurl();
  curl_easy_setopt(curl, CURLOPT_URL,
                   "http://codeforces.com/data/judgeProtocol");
  string post = (string) "submissionId=" + bott->Getremote_runid() +
      "&csrf_token=" + csrf;
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
  performCurl();

  string info = loadAllFromFile(tmpfilename);
  string result;
  if (!RE2::FullMatch(info, "\"(.*)\"", &result)) {
    return "";
  }
  return unescapeString(result);
}
예제 #26
0
/**
 * Login to SCU
 */
void SCUJudger::login()
{

	prepareCurl();
	curl_easy_setopt(curl, CURLOPT_URL,
			 "http://cstest.scu.edu.cn/soj/login.action");
	string post =
	    "back=2&submit=login&id=" + escapeURL(info->GetUsername()) +
	    "&password="******"<title>ERROR</title>") != string::npos) {
		throw Exception("Login failed!");
	}
}
예제 #27
0
/**
 * Login to CodeForces
 */
void CFJudger::login() {
  string csrf = getCsrfParams("http://codeforces.com/enter");

  prepareCurl();
  curl_easy_setopt(curl, CURLOPT_REFERER, "http://codeforces.com/enter");
  curl_easy_setopt(curl, CURLOPT_URL, "http://codeforces.com/enter");
  string post = (string) "csrf_token=" + csrf +
      "&action=enter&handle=" + info->GetUsername() +
      "&password="******"&_tta=" + getttaValue();
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
  performCurl();

  // check login status
  string html = loadAllFromFile(tmpfilename);
  if (html.find("Invalid handle or password") != string::npos) {
    throw Exception("Login failed!");
  }
}
예제 #28
0
/**
 * Get compile error info from CodeChef
 * @param bott      Result bott file
 * @return Compile error info
 */
string CCJudger::getCEinfo(Bott * bott) {
  prepareCurl();
  curl_easy_setopt(curl, CURLOPT_URL,
                   ((string) "https://www.codechef.com/view/error/" +
                   bott->Getremote_runid()).c_str());
  performCurl();

  string info = loadAllFromFile(tmpfilename);
  string result;
  if (!RE2::PartialMatch(info, "(?s)<pre>(.*)</pre>", &result)) {
    return "";
  }

  char * ce_info = new char[info.length() + 1];
  decode_html_entities_utf8(ce_info, result.c_str());
  result = ce_info;
  delete [] ce_info;

  return result;
}
예제 #29
0
/**
 * Submit a run
 * @param bott      Bott file for Run info
 * @return Submit status
 */
int NJUPTJudger::submit(Bott * bott) {
  prepareCurl();
  curl_easy_setopt(curl, CURLOPT_URL,
                   "http://acm.njupt.edu.cn/acmhome/submitcode.do");
  string post = (string) "problemId=" + bott->Getvid() +
      "&language=" + convertLanguage(bott->Getlanguage()) +
      "&code=" + escapeURL(bott->Getsrc());
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());

  try {
    performCurl();
  } catch (Exception & e) {
    return SUBMIT_OTHER_ERROR;
  }

  string html = loadAllFromFile(tmpfilename);
  if (html.find("<div style=\"color:red;\"><UL><LI>") != string::npos)
    return SUBMIT_OTHER_ERROR;
  return SUBMIT_NORMAL;
}
예제 #30
0
/**
 * Submit a run
 * @param bott      Bott file for Run info
 * @return Submit status
 */
int SPOJJudger::submit(Bott * bott) {

  // prepare form for post
  struct curl_httppost * formpost = NULL;
  struct curl_httppost * lastptr = NULL;
  curl_formadd(&formpost, &lastptr,
               CURLFORM_COPYNAME, "submit",
               CURLFORM_COPYCONTENTS, "Send",
               CURLFORM_END);
  curl_formadd(&formpost, &lastptr,
               CURLFORM_COPYNAME, "problemcode",
               CURLFORM_COPYCONTENTS, bott->Getvid().c_str(),
               CURLFORM_END);
  curl_formadd(&formpost, &lastptr,
               CURLFORM_COPYNAME, "lang",
               CURLFORM_COPYCONTENTS,
                   convertLanguage(bott->Getlanguage()).c_str(),
               CURLFORM_END);
  curl_formadd(&formpost, &lastptr,
               CURLFORM_COPYNAME, "file",
               CURLFORM_COPYCONTENTS, bott->Getsrc().c_str(),
               CURLFORM_END);

  prepareCurl();
  curl_easy_setopt(curl, CURLOPT_URL, "http://www.spoj.com/submit/complete/");
  curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
  performCurl();

  // check submit status
  string html = loadAllFromFile(tmpfilename);
  // cout << html << endl;
  if (html.find("in this language for this problem") != string::npos) {
    return SUBMIT_INVALID_LANGUAGE;
  }
  if (html.find("<form name=\"login\"  action=\"") != string::npos) {
    return SUBMIT_OTHER_ERROR;
  }
  return VirtualJudger::SUBMIT_NORMAL;
}