コード例 #1
0
ファイル: O2Boards.cpp プロジェクト: Hiroyuki-Nagata/o2on
/*
 *	Get()
 *	URLから取得
 */
uint
O2Boards::
Get(const char *url)
{
	const char *target_url = url ? url : DEFAULT_BBSMENU_URL;
	HTTPSocket *socket = new HTTPSocket(SELECT_TIMEOUT_MS, Profile->GetUserAgentA());

	HTTPHeader h(HTTPHEADERTYPE_REQUEST);
	if (LastModified)
		h.AddFieldDate("If-Modified-Since", LastModified);

	string out;
	HTTPHeader oh(HTTPHEADERTYPE_RESPONSE);
	if (!socket->request(target_url, h, NULL, 0)) {
		delete socket;
		return (0);
	}
	while (socket->response(out, oh) >= 0)
	{
		if (oh.contentlength) {
			if (out.size() - oh.length >= oh.contentlength)
				break;
		}
	}
	delete socket;

	if (oh.status != 200)
		return (oh.status);

	if (!Update(&out[oh.length]))
		return (0);

	strmap::iterator it = oh.fields.find("Last-Modified");
	if (it == oh.fields.end())
		it = oh.fields.find("Date");
	if (it == oh.fields.end())
		return (0);

	time_t t = oh.httpdate2time_t(it->second.c_str());
	LastModified = t;
/*
	TRACEA(it->first.c_str());
	TRACEA(": ");
	TRACEA(it->second.c_str());
	TRACEA("\n");
	TRACEA(ctime(&LastModified));
*/
	return (oh.status);
}