Example #1
0
void WebCoreClass::resumeUpload(DesuraId id, const char* key, WebCore::Misc::ResumeUploadInfo &info)
{
	TiXmlDocument doc;
	PostMap post;

	post["siteareaid"] = id.getItem();
	post["sitearea"] = id.getTypeString();
	post["action"] = "resumeupload";
	post["key"] = key;

	TiXmlNode *uNode = postToServer(getMcfUploadUrl(), "itemupload", post, doc);
	TiXmlNode* mNode = uNode->FirstChild("mcf");

	if (!mNode)
		throw gcException(ERR_BADXML);	

	gcString complete;
	XML::GetChild("complete", complete, mNode);

	if (complete == "1")
		throw gcException(ERR_COMPLETED);

	XML::GetChild("date", info.szDate, mNode);
	XML::GetChild("filehash", info.szHash, mNode);
	XML::GetChild("filesize", info.size, mNode);
	XML::GetChild("filesizeup", info.upsize, mNode);
}
Example #2
0
void WebCoreClass::newUpload(DesuraId id, const char* hash, uint64 fileSize, char **key)
{
	gcString size("{0}", fileSize);

	TiXmlDocument doc;
	PostMap post;

	post["siteareaid"] = id.getItem();
	post["sitearea"] = id.getTypeString();
	post["action"] = "newupload";
	post["filehash"] = hash;
	post["filesize"] = size;

	TiXmlNode *uNode = postToServer(getMcfUploadUrl(), "itemupload", post, doc);
	TiXmlNode* iNode = uNode->FirstChild("mcf");
	
	if (!iNode)
		throw gcException(ERR_BADXML);	

	TiXmlElement* cEl = iNode->ToElement();
		
	if (cEl)
	{
		const char* text = cEl->Attribute("key");

		if (!text)
			throw gcException(ERR_BADXML);	

		Safe::strcpy(key, text, 255);
	}
}
Example #3
0
void WebCoreClass::getUpdatePoll(TiXmlDocument &doc, const std::map<std::string, std::string> &post)
{
	PostMap postData;

	std::for_each(post.begin(), post.end(), [&postData](std::pair<std::string, std::string> p)
	{
		postData[p.first] = p.second;
	});

	TiXmlNode* root = postToServer(getUpdatePollUrl(), "updatepoll", postData, doc);
}
Example #4
0
void WebCoreClass::updateAccountItem(DesuraId id, bool add)
{
	TiXmlDocument doc;
	PostMap post;

	post["siteareaid"] = id.getItem();
	post["sitearea"] = id.getTypeString();
	post["action"] = add?"add":"delete";

	postToServer(getUpdateAccountUrl(), "iteminstall", post, doc);
}
Example #5
0
void postWeather(char* temperature, char* humidity, char* uuid)
{
    int portno =        80;
    char *host =        "192.168.1.20";
    char *message_fmt = "POST /weather/newmeasurement.php HTTP/1.0\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %d\r\n\r\n%s\r\n";

    char message[1024];
    char data[255];
    sprintf(data, "temperature=%s&humidity=%s&uuid=%s", temperature, humidity, uuid);
    sprintf(message,message_fmt,strlen(data), data);

    postToServer(host, portno, message);
}
Example #6
0
/*!
 * @brief 音声合成を行う
 * @param [in] lang      messageの言語
 * @param [in] argv      音声合成するテキスト
 * @param [in] filename  出力ファイル名
 */
static void sayTextToSpeach(
    const std::string &lang,
    const std::string &message,
    const std::string &filename)
{
  // サーバに投げるJSON文字列の作成
  std::string json_str = JSON_HEADER + lang + "\", \"" + message + JSON_FOOTER;
  // 例外はmain側に投げる
  std::string body_str = postToServer(json_str, URL_HOST, URL_PATH, HTTP_PORT);

  std::ofstream ofs(filename.c_str(), std::ofstream::binary);
  if (!ofs) {
    throw "Cannot open " + filename;
  }
  ofs << retJsonToWave(body_str);
  ofs.close();
}
Example #7
0
void WebCoreClass::getItemInfo(DesuraId id, TiXmlDocument &doc, MCFBranch mcfBranch, MCFBuild mcfBuild)
{
	PostMap post;

	post["siteareaid"] = id.getItem();
	post["sitearea"] = id.getTypeString();

	if (mcfBuild != 0)
		post["build"] = mcfBuild;

	if (mcfBranch != 0)
	{
		if (mcfBranch.isGlobal())
			post["branchglobal"] = mcfBranch;
		else
			post["branch"] = mcfBranch;
	}

	postToServer(getItemInfoUrl(), "iteminfo", post, doc);
}
Example #8
0
gcString WebCoreClass::getCDKey(DesuraId id, MCFBranch branch)
{
	TiXmlDocument doc;
	PostMap post;

	post["siteareaid"] = id.getItem();
	post["sitearea"] = id.getTypeString();
	post["branch"] = (size_t)branch;
	
#ifdef WIN32
	post["token"] =  UTIL::WIN::getRegValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography\\MachineGuid", true);
#else
	post["token"] = "todo";
#endif

	TiXmlNode* root = postToServer(getCDKeyUrl(), "cdkey", post, doc);
	TiXmlElement* key = root->FirstChildElement("key");

	if (!key)
		throw gcException(ERR_BADXML);

	return key->GetText();
}
Example #9
0
DesuraId WebCoreClass::nameToId(const char* name, const char* type)
{
	if (!name)
		throw gcException(ERR_BADITEM, "The name is NULL");

	gcString key("{0}-{1}", name, type);
	uint32 hash = UTIL::MISC::RSHash_CSTR(key.c_str());

	try 
	{
		sqlite3x::sqlite3_connection db(getWebCoreDb(m_szAppDataPath.c_str()).c_str());
		gcString q("select internalid from namecache where nameid='{0}' and ttl > DATETIME('NOW');",  hash);

		DesuraId id(db.executeint64(q.c_str()));
		if (id.isOk())
			return id;
	}
	catch(std::exception &) 
	{
	}

	TiXmlDocument doc;
	PostMap post;

	post["nameid"] = name;
	post["sitearea"] = type;

	TiXmlNode *uNode = postToServer(getNameLookUpUrl(), "iteminfo", post, doc);
	TiXmlNode* cNode = uNode->FirstChild("item");

	if (cNode)
	{
		TiXmlElement* cEl = cNode->ToElement();
		
		if (cEl)
		{
			const char* idStr = cEl->Attribute("siteareaid");
			const char* typeS = cEl->Attribute("sitearea");

			DesuraId id(idStr, typeS);

			if (!id.isOk() || DesuraId::getTypeString(id.getType()) != type)
			{
				throw gcException(ERR_BADXML);
			}
			else
			{
				try 
				{
					sqlite3x::sqlite3_connection db(getWebCoreDb(m_szAppDataPath.c_str()).c_str());
					gcString q("replace into namecache (internalid, nameid, ttl) values ('{0}','{1}', DATETIME('NOW', '+5 day'));", id.toInt64(), hash);
					db.executenonquery(q.c_str());
				}
				catch(std::exception &ex) 
				{
					Warning(gcString("Failed to update namecache in webcore: {0}\n", ex.what()));
				}	

				return id;
			}
		}
	}

	throw gcException(ERR_BADXML);
}
Example #10
0
TiXmlNode* WebCoreClass::loginToServer(std::string url, std::string resource, PostMap &postData, TiXmlDocument &doc)
{
	return postToServer(url, resource, postData, doc, true);
}
Example #11
0
void WebCoreClass::getLoginItems(TiXmlDocument &doc)
{
	PostMap postData;
	postToServer(getMemberDataUrl(), "memberdata", postData, doc);
}