示例#1
0
string getCEinfo(string runid) {
    FILE * fp=fopen(tfilename,"w+");
    curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
        curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "fzu.cookie");
        string url=(string)"http://acm.fzu.edu.cn/ce.php?sid="+runid;
        //cout<<url;
        curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
        res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
    }
    fclose(fp);
    string ts=getAllFromFile(tfilename);

    int pos=ts.find("<font color=\"blue\" size=\"-1\">");
    while (ts[pos]!='>') pos++;
    pos++;
    int st=pos;
    pos=ts.find("</font>");
    string info=ts.substr(st,pos-st);
    strcpy(tempce,info.c_str());
    decode_html_entities_utf8(tempce, 0);
    info=tempce;
    /*int position = info.find( "<br/>" );
    while ( position != string::npos ) {
        info.replace( position, strlen("<br/>"), "\n" );
        position = info.find( "<br/>", position );
    }*/
    return info;
}
示例#2
0
string CCUtils::decodeHtmlEntities(const string& src) {
	char* dest = (char*)calloc(src.length() + 1, sizeof(char));
	decode_html_entities_utf8(dest, src.c_str());
	string decoded = string(dest);
	free(dest);
	return decoded;
}
示例#3
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);
}
示例#4
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;
}
示例#5
0
文件: test.cpp 项目: jie414341055/toj
string getCEinfo(string runid) {
	FILE * fp=fopen(tfilename,"w+");
	curl = curl_easy_init();
	if(curl) {
		curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
		curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
		curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "hdu.cookie");
		string url=(string)"http://acm.hdu.edu.cn/viewerror.php?rid="+runid;
		//cout<<url;
		curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
		res = curl_easy_perform(curl);
		curl_easy_cleanup(curl);
	}
	fclose(fp);
	string ts=getAllFromFile(tfilename);

	int pos=ts.find("<pre>");
	while (ts[pos]!='>') pos++;
	pos++;
	int st=pos;
	while (ts[pos]!='<') pos++;
	string info=ts.substr(st,pos-st);
	strcpy(tempce,info.c_str());
	g2u(tempce,strlen(tempce),outs,MAX_DATA_SIZE);
	decode_html_entities_utf8(outs, 0);
	info=outs;
	int position = info.find( "\\" );
	while ( position != string::npos ) {
		info.replace( position, 1, "\\\\" );
		position = info.find( "\\", position + 2 );
	}
	return info;
}
示例#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
string getCEinfo(string runid) {
	FILE * fp=fopen(tfilename,"w+");
	curl = curl_easy_init();
	if(curl) {
		curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
		curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
		curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "pku.cookie");
		string url=(string)"http://poj.org/showcompileinfo?solution_id="+runid;
		//cout<<url;
		curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
		res = curl_easy_perform(curl);
		curl_easy_cleanup(curl);
	}
	fclose(fp);
	string ts=getAllFromFile(tfilename);

	int pos=ts.find("<pre>");
	while (ts[pos]!='>') pos++;
	pos++;
	int st=pos;
	while (ts[pos]!='<') pos++;
	string info=ts.substr(st,pos-st);
	strcpy(tempce,info.c_str());
	decode_html_entities_utf8(tempce, 0);
	info=tempce;
	int position = info.find( "\\" );
	while ( position != string::npos ) {
		info.replace( position, 1, "\\\\" );
		position = info.find( "\\", position + 2 );
	} 
	return info;
}
示例#8
0
int main(void)
{
	{
		static const char SAMPLE[] = "Christoph Gärtner";
		static char buffer[] = "Christoph G&auml;rtner";
		assert(decode_html_entities_utf8(buffer, NULL) == sizeof SAMPLE - 1);
		assert(strcmp(buffer, SAMPLE) == 0);
	}

	{
		static const char SAMPLE[] = "*****@*****.**";
		static const char INPUT[] = "test&#x40;example.org";
		static char buffer[sizeof INPUT];
		assert(decode_html_entities_utf8(buffer, INPUT) == sizeof SAMPLE - 1);
		assert(strcmp(buffer, SAMPLE) == 0);
	}

	fprintf(stdout, "All tests passed :-)\n");
	return EXIT_SUCCESS;
}
struct SeQuestion *se_new_question(int id, int score, int answers,
  int views, int last_activity_date, const char *title, const char *link) {
  struct SeQuestion *q = 
    (struct SeQuestion *)calloc(sizeof(struct SeQuestion), 1);
  char *decoded_title = _strdup(title);
  decode_html_entities_utf8(decoded_title, NULL);
  q->id =                 id;
  q->score =              score;
  q->answers =            answers;
  q->views =              views;
  q->last_activity_date = last_activity_date;
  q->title =              decoded_title;
  q->link =               _strdup(link);
  return q;
}
示例#10
0
文件: main.c 项目: ooxi/gltoolkit
/**
 * Configuration helper
 */
static uint8_t* configuration_value(
			struct xml_node* configuration,
			uint8_t const* key
		) {

	if (!configuration) {
		return 0;
	}

	uint8_t* value = xml_easy_content(xml_easy_child(
		configuration, key, 0
	));
	if (!value) {
		return 0;
	}

	decode_html_entities_utf8(value, 0);
	return value;
}
示例#11
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;
}
示例#12
0
static int parse_tweets(char *json)
{
    int err = 1;
    json_tokener* tok;
    json_object *root = NULL, *results;
    unsigned int i;

    prepare_json_for_libjsonc(json);

    tok = json_tokener_new();
    if (!tok) {
        fprintf(stderr, "Could not initialize tokenizer\n");
        goto cleanup;
    }
    root = json_tokener_parse_ex(tok, json, -1);
    if (tok->err != json_tokener_success) {
        fprintf(stderr, "json_tokener_parse_ex: error %s at offset %d\n",
                        json_tokener_errors[tok->err], tok->char_offset);
        goto cleanup;
    }

    if (!root) {
        fprintf(stderr, "Could not parse twitter response\n");
        goto cleanup;
    }

    if (!(results = json_object_object_get(root, "results"))) {
        fprintf(stderr, "Could not find 'results' in twitter response\n");
        goto cleanup;
    }

    if (json_object_get_type(results) != json_type_array) {
        fprintf(stderr, "'results' in twitter response is no array\n");
        goto cleanup;
    }

    for (i = 0; i < json_object_array_length(results); ++i) {
        json_object *result, *created_at, *from_user, *text, *id_str;
        const char *created_at_cstr, *from_user_cstr, *text_cstr, *id_str_cstr;

        if (!(result = json_object_array_get_idx(results, i))) {
            fprintf(stderr, "Could not get results array from response\n");
            continue;
        }

        if (!(created_at = json_object_object_get(result, "created_at")) ||
             !(from_user = json_object_object_get(result, "from_user")) ||
                !(id_str = json_object_object_get(result, "id_str")) ||
                  !(text = json_object_object_get(result, "text"))) {
            fprintf(stderr, "Could not get specified field(s) from result\n");
            continue;
        }

        if (!(created_at_cstr = json_object_get_string(created_at)) ||
             !(from_user_cstr = json_object_get_string(from_user)) ||
                !(id_str_cstr = json_object_get_string(id_str)) ||
                  !(text_cstr = json_object_get_string(text))) {
            fprintf(stderr, "Expected different type of result field\n");
            continue;
        }

        tweets[i].created_at = strdup(created_at_cstr);
        tweets[i].from_user = strdup(from_user_cstr);
        tweets[i].text = strdup(text_cstr);
        tweets[i].id_str = strdup(id_str_cstr);

        decode_html_entities_utf8(tweets[i].from_user);
        decode_html_entities_utf8(tweets[i].text);
    }

    err = 0;

  cleanup:
    json_tokener_free(tok);
    if (root) {
        json_object_put(root);
        root = NULL;
    }
    return err;
}