mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
httpコネクションをメンバ変数で持つように
SimpleXmlParser、BgsCommunicatorのテストを追加 git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@575 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
parent
4337476c65
commit
7721b74533
@ -187,7 +187,7 @@ u8 USER_ORIGIN_PRIVATE_KEY[] =
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BgsCommunicator::BgsCommunicator()
|
BgsCommunicator::BgsCommunicator() : m_Result(nn::ResultSuccess())
|
||||||
{
|
{
|
||||||
// TODO 自動生成されたコンストラクター・スタブ
|
// TODO 自動生成されたコンストラクター・スタブ
|
||||||
}
|
}
|
||||||
@ -199,122 +199,116 @@ BgsCommunicator::~BgsCommunicator()
|
|||||||
|
|
||||||
bool BgsCommunicator::Execute(const void* buf, size_t size)
|
bool BgsCommunicator::Execute(const void* buf, size_t size)
|
||||||
{
|
{
|
||||||
nn::Result result;
|
m_Result = common::InitializeNetwork();
|
||||||
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result);
|
||||||
result = common::InitializeNetwork();
|
|
||||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------
|
||||||
ライブラリの初期化(HTTPライブラリ使用前に、各プロセスで一度だけ実行する。)
|
ライブラリの初期化(HTTPライブラリ使用前に、各プロセスで一度だけ実行する。)
|
||||||
------------------------------------------------------------------------ */
|
------------------------------------------------------------------------ */
|
||||||
result = nn::http::Initialize(reinterpret_cast<uptr>(s_PostBuffer), sizeof(s_PostBuffer));
|
m_Result = nn::http::Initialize(reinterpret_cast<uptr>(s_PostBuffer), sizeof(s_PostBuffer));
|
||||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result);
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------
|
||||||
通信準備
|
通信準備
|
||||||
------------------------------------------------------------------------ */
|
------------------------------------------------------------------------ */
|
||||||
//Connectionインスタンスの生成
|
|
||||||
nn::http::Connection httpCon;
|
|
||||||
|
|
||||||
//通信先の設定
|
//通信先の設定
|
||||||
//<<HTTPS特有コード>>URLの先頭文字はhttpsとなります
|
//<<HTTPS特有コード>>URLの先頭文字はhttpsとなります
|
||||||
result = httpCon.Initialize("https://10.12.3.73/bgs/services/BusinessGatewaySOAP", nn::http::REQUEST_METHOD_POST);
|
m_Result = m_HttpCon.Initialize("https://10.12.3.73/bgs/services/BusinessGatewaySOAP", nn::http::REQUEST_METHOD_POST);
|
||||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result);
|
||||||
|
|
||||||
result = httpCon.AddHeaderField("Accept-Encoding", "identity");
|
m_Result = m_HttpCon.AddHeaderField("Accept-Encoding", "identity");
|
||||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result);
|
||||||
|
|
||||||
result = httpCon.AddHeaderField("SOAPAction", "urn:bgs.wsapi.broadon.com/GetPreInstalledInfo");
|
m_Result = m_HttpCon.AddHeaderField("SOAPAction", "urn:bgs.wsapi.broadon.com/GetPreInstalledInfo");
|
||||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result);
|
||||||
|
|
||||||
result = httpCon.AddHeaderField("Content-Type", "text/xml; charset=utf-8");
|
m_Result = m_HttpCon.AddHeaderField("Content-Type", "text/xml; charset=utf-8");
|
||||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result);
|
||||||
|
|
||||||
// POSTデータの設定
|
// POSTデータの設定
|
||||||
result = httpCon.AddPostDataRaw(buf, size);
|
m_Result = m_HttpCon.AddPostDataRaw(buf, size);
|
||||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result);
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------
|
||||||
<<HTTPS特有コード>>SSL処理用設定
|
<<HTTPS特有コード>>SSL処理用設定
|
||||||
------------------------------------------------------------------------ */
|
------------------------------------------------------------------------ */
|
||||||
//ルート証明書の設定
|
//ルート証明書の設定
|
||||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED( httpCon.SetRootCa( NNSSL_CACERT_PUBLIC_CA_1 ));
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED( m_HttpCon.SetRootCa( NNSSL_CACERT_PUBLIC_CA_1 ));
|
||||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED( httpCon.SetRootCa( NNSSL_CACERT_PUBLIC_CA_2 ));
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED( m_HttpCon.SetRootCa( NNSSL_CACERT_PUBLIC_CA_2 ));
|
||||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED( httpCon.SetRootCa( NNSSL_CACERT_PUBLIC_CA_3 ));
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED( m_HttpCon.SetRootCa( NNSSL_CACERT_PUBLIC_CA_3 ));
|
||||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED( httpCon.SetRootCa( NNSSL_CACERT_PUBLIC_CA_4 ));
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED( m_HttpCon.SetRootCa( NNSSL_CACERT_PUBLIC_CA_4 ));
|
||||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result);
|
||||||
|
|
||||||
s32 sslError;
|
s32 sslError;
|
||||||
httpCon.GetSslError(&sslError);
|
m_HttpCon.GetSslError(&sslError);
|
||||||
NN_LOG("sslerror = %x\n", sslError);
|
NN_LOG("sslerror = %x\n", sslError);
|
||||||
|
|
||||||
result = httpCon.SetClientCert(USER_ORIGIN_CLIENT_CERT_DATA, sizeof(USER_ORIGIN_CLIENT_CERT_DATA),
|
m_Result = m_HttpCon.SetClientCert(USER_ORIGIN_CLIENT_CERT_DATA, sizeof(USER_ORIGIN_CLIENT_CERT_DATA),
|
||||||
USER_ORIGIN_PRIVATE_KEY, sizeof(USER_ORIGIN_PRIVATE_KEY)); //クライアント証明書を設定する。
|
USER_ORIGIN_PRIVATE_KEY, sizeof(USER_ORIGIN_PRIVATE_KEY)); //クライアント証明書を設定する。
|
||||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result);
|
||||||
|
|
||||||
|
|
||||||
// 証明書が適当?なので検証項目を減らす
|
// 証明書が適当?なので検証項目を減らす
|
||||||
result = httpCon.DisableVerifyOptionForDebug(
|
m_Result = m_HttpCon.DisableVerifyOptionForDebug(
|
||||||
nn::ssl::VERIFY_COMMON_NAME | nn::ssl::VERIFY_SUBJECT_ALT_NAME | nn::ssl::VERIFY_ROOT_CA);
|
nn::ssl::VERIFY_COMMON_NAME | nn::ssl::VERIFY_SUBJECT_ALT_NAME | nn::ssl::VERIFY_ROOT_CA);
|
||||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result);
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------
|
||||||
通信実行
|
通信実行
|
||||||
------------------------------------------------------------------------ */
|
------------------------------------------------------------------------ */
|
||||||
//通信の開始
|
//通信の開始
|
||||||
result = httpCon.Connect(); //リクエストの送信を開始する。機器が同時実行可能な最大個数のHTTP通信がすでに実行中の場合は、空きができるまでブロック
|
m_Result = m_HttpCon.Connect(); //リクエストの送信を開始する。機器が同時実行可能な最大個数のHTTP通信がすでに実行中の場合は、空きができるまでブロック
|
||||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result);
|
||||||
|
|
||||||
httpCon.GetSslError(&sslError);
|
nn::http::ResultCode resultCode;
|
||||||
|
m_Result = m_HttpCon.GetError(&resultCode);
|
||||||
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result);
|
||||||
|
NN_LOG("resultCode = %x\n", resultCode);
|
||||||
|
|
||||||
|
m_Result = m_HttpCon.GetSslError(&sslError);
|
||||||
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result);
|
||||||
NN_LOG("sslerror = %x\n", sslError);
|
NN_LOG("sslerror = %x\n", sslError);
|
||||||
|
|
||||||
//HTTPレスポンスの取得
|
return true;
|
||||||
u8 bodyBuf[4096];
|
}
|
||||||
memset(bodyBuf, 0, sizeof(bodyBuf));
|
|
||||||
result = httpCon.Read(bodyBuf, sizeof(bodyBuf)); //読み取りが完了するまでブロック。Bodyの最後までの読み込みが成功した場合は、Successを表すResultが返る。バッファサイズが足りない場合は、エラー(Description==ER_RES_BODYBUF_SHORTAGEのResult)が返る*/
|
|
||||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
|
||||||
httpCon.GetSslError(&sslError);
|
|
||||||
NN_LOG("sslerror = %x\n", sslError);
|
|
||||||
|
|
||||||
//必要に応じて、通信エラーを確認
|
|
||||||
//nn::http::ResultCode resultCode;
|
|
||||||
//result = httpCon.GetError(&resultCode);
|
|
||||||
|
|
||||||
//<<HTTPS特有コード>>必要に応じて、SSL通信エラーを確認
|
|
||||||
//nn::ssl::ResultCode sslResultCode;
|
|
||||||
//result = httpCon.GetSslError(&sslResultCode);
|
|
||||||
|
|
||||||
|
size_t BgsCommunicator::GetBodySize()
|
||||||
|
{
|
||||||
/* ------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------
|
||||||
HTTPレスポンスに対するアプリ側の処理。(この部分はアプリ毎に任意の処理を行う。本デモでは例として、メッセージヘッダの一部とメッセージボディ全体をダンプする処理を実装する。)
|
HTTPレスポンスに対するアプリ側の処理。(この部分はアプリ毎に任意の処理を行う。本デモでは例として、メッセージヘッダの一部とメッセージボディ全体をダンプする処理を実装する。)
|
||||||
------------------------------------------------------------------------ */
|
------------------------------------------------------------------------ */
|
||||||
//HTTPヘッダの情報読み出し
|
//HTTPヘッダの情報読み出し
|
||||||
s32 statusCode = 0;
|
s32 statusCode = 0;
|
||||||
result = httpCon.GetStatusCode(&statusCode); //Statusコードの取得
|
m_Result = m_HttpCon.GetStatusCode(&statusCode); //Statusコードの取得
|
||||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result);
|
||||||
NN_LOG("---HTTP ResultCode = %d---\n", statusCode);
|
NN_LOG("---HTTP ResultCode = %d---\n", statusCode);
|
||||||
|
|
||||||
char headerFields[1024];
|
char headerFields[1024];
|
||||||
memset(headerFields, 0, sizeof(headerFields));
|
memset(headerFields, 0, sizeof(headerFields));
|
||||||
u32 fieldLen = sizeof(headerFields);
|
u32 fieldLen = sizeof(headerFields);
|
||||||
result = httpCon.GetHeaderField("Content-Length", headerFields, fieldLen, &fieldLen); //特定のヘッダフィールドをラベルから取得
|
m_Result = m_HttpCon.GetHeaderField("Content-Length", headerFields, fieldLen, &fieldLen); //特定のヘッダフィールドをラベルから取得
|
||||||
//result = httpCon.GetHeaderAll(headerFields, fieldLen, &fieldLen);//全ヘッダフィールドを一括取得
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result);
|
||||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
m_BodySize = std::strtol(headerFields, NULL, 10);
|
||||||
u32 contentLength = std::atoi(headerFields);
|
NN_LOG("---HTTP Content-Length = %d---\n", m_BodySize);
|
||||||
NN_LOG("---HTTP Content-Length = %d---\n", contentLength);
|
|
||||||
|
|
||||||
result = common::FinalizeNetwork();
|
return m_BodySize;
|
||||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t BgsCommunicator::GetBodySize()
|
bool BgsCommunicator::GetBody(u8 *buf, size_t size)
|
||||||
{
|
{
|
||||||
return 0;
|
//HTTPレスポンスの取得
|
||||||
|
memset(buf, 0, size);
|
||||||
|
m_Result = m_HttpCon.Read(buf, size); //読み取りが完了するまでブロック。Bodyの最後までの読み込みが成功した場合は、Successを表すResultが返る。バッファサイズが足りない場合は、エラー(Description==ER_RES_BODYBUF_SHORTAGEのResult)が返る*/
|
||||||
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BgsCommunicator::GetBody(void *buf)
|
bool BgsCommunicator::Finalize()
|
||||||
{
|
{
|
||||||
NN_UNUSED_VAR(buf);
|
m_Result = common::FinalizeNetwork();
|
||||||
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* namespace ConsoleRestore */
|
} /* namespace ConsoleRestore */
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
#define BGSCOMMUNICATOR_H_
|
#define BGSCOMMUNICATOR_H_
|
||||||
|
|
||||||
#include <nn.h>
|
#include <nn.h>
|
||||||
|
#include <nn/http.h>
|
||||||
namespace ConsoleRestore
|
namespace ConsoleRestore
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -34,10 +35,23 @@ public:
|
|||||||
//! @brief 通信結果のサイズを取得します
|
//! @brief 通信結果のサイズを取得します
|
||||||
size_t GetBodySize();
|
size_t GetBodySize();
|
||||||
|
|
||||||
//! @brief 通信結果を取得します
|
//! @brief 通信結果をバッファに書き込みます。正しく結果を取得するには GetBodySizeで取得したサイズのバッファが必要です。
|
||||||
//! @param[out] buf 通信結果を書き込むバッファ
|
//! @param[out] buf 通信結果を書き込むバッファ
|
||||||
void GetBody(void* buf);
|
//! @param[in] size バッファサイズ
|
||||||
|
bool GetBody(u8* buf, size_t size);
|
||||||
|
|
||||||
|
bool Finalize();
|
||||||
|
|
||||||
|
nn::Result GetLastResult();
|
||||||
|
|
||||||
|
private:
|
||||||
|
nn::Result m_Result;
|
||||||
|
|
||||||
|
//! @brief HTTPレスポンスのサイズ
|
||||||
|
size_t m_BodySize;
|
||||||
|
|
||||||
|
//Connectionインスタンス
|
||||||
|
nn::http::Connection m_HttpCon;
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace ConsoleRestore */
|
} /* namespace ConsoleRestore */
|
||||||
|
|||||||
@ -0,0 +1,71 @@
|
|||||||
|
#!/usr/bin/env omake
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Project: Horizon
|
||||||
|
# File: OMakefile
|
||||||
|
#
|
||||||
|
# Copyright (C)2009 Nintendo Co., Ltd. All rights reserved.
|
||||||
|
#
|
||||||
|
# These coded instructions, statements, and computer programs contain
|
||||||
|
# proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||||
|
# Company Ltd., and are protected by Federal copyright law. They may
|
||||||
|
# not be disclosed to third parties or copied or duplicated in any form,
|
||||||
|
# in whole or in part, without the prior written consent of Nintendo.
|
||||||
|
#
|
||||||
|
# $Rev$
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
SUPPORTED_TARGETS = CTR-*.Process.MPCore.*
|
||||||
|
|
||||||
|
include $(makePlatformDefsPath tests)
|
||||||
|
|
||||||
|
SAMPLED_DEMOS_COMMON_INCLUDE_DIR = $(dir $(HORIZON_ROOT)/../CTR/SampleDemos/common/include)
|
||||||
|
INCLUDES += $(SAMPLED_DEMOS_COMMON_INCLUDE_DIR) \
|
||||||
|
../../../common \
|
||||||
|
../../../ConsoleRestore \
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TEST_COMMON_SOURCES[] =
|
||||||
|
../../../ConsoleRestore/Shop.cpp
|
||||||
|
../../../ConsoleRestore/XmlCreator.cpp
|
||||||
|
../../../ConsoleRestore/SimpleXmlPreprocessor.cpp
|
||||||
|
../../../ConsoleRestore/BgsCommunicator.cpp
|
||||||
|
../../../common/Util.cpp
|
||||||
|
../../../common/HeapManager.cpp
|
||||||
|
../../../common/SdLogger.cpp
|
||||||
|
../../../common/LogConsole.cpp
|
||||||
|
../../../common/CommonLogger.cpp
|
||||||
|
../../../common/SdMountManager.cpp
|
||||||
|
../../../common/VersionDetect.cpp
|
||||||
|
../../../common/HardwareStateManager.cpp
|
||||||
|
../../../common/FileTransfer.cpp
|
||||||
|
../../../common/SdReaderWriter.cpp
|
||||||
|
|
||||||
|
CCFLAGS += -DCOMMON_LOGGER_DETAIL_ENABLE
|
||||||
|
|
||||||
|
SOURCES_TEST[] = test_BgsCommunicator.cpp
|
||||||
|
|
||||||
|
ROMFS_ROOT = ../../../common/romfiles
|
||||||
|
|
||||||
|
TEST_ENVIRONMENT_PROCESSLIST = true
|
||||||
|
TEST_ENVIRONMENT_EMUMEM = true
|
||||||
|
|
||||||
|
LIBS += libnn_test \
|
||||||
|
libnn_mcu \
|
||||||
|
libnn_ps \
|
||||||
|
libnn_am \
|
||||||
|
lib_demo \
|
||||||
|
libnn_nim \
|
||||||
|
libnn_xml_simple \
|
||||||
|
|
||||||
|
ROM_SPEC_FILE = ../../../ConsoleRestore/ConsoleRestore.rsf
|
||||||
|
DESCRIPTOR = $(HORIZON_ROOT)/resources/specfiles/private/RepairTool.desc
|
||||||
|
|
||||||
|
|
||||||
|
DEPEND_PROCESSES[] =
|
||||||
|
test_BgsCommunicator>$(GetProcessCdiPathList http)
|
||||||
|
|
||||||
|
|
||||||
|
include $(makePlatformDefsPath build.tests)
|
||||||
|
|
||||||
|
|
||||||
|
tests: $(TEST_TARGETS)
|
||||||
@ -0,0 +1,171 @@
|
|||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Project: Horizon
|
||||||
|
File: test_BgsCommunicator.cpp
|
||||||
|
|
||||||
|
Copyright (C)2012 Nintendo Co., Ltd. All rights reserved.
|
||||||
|
|
||||||
|
These coded instructions, statements, and computer programs contain
|
||||||
|
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||||
|
Company Ltd., and are protected by Federal copyright law. They may
|
||||||
|
not be disclosed to third parties or copied or duplicated in any form,
|
||||||
|
in whole or in part, without the prior written consent of Nintendo.
|
||||||
|
|
||||||
|
$Rev$
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
#include <nn.h>
|
||||||
|
#include <nn/test/test_Test.h>
|
||||||
|
#include <nn/cfg/CTR/cfg_ApiSys.h>
|
||||||
|
#include <nn/fs.h>
|
||||||
|
#include <nn/fs/CTR/fs_ArchiveTypesForSystem.h>
|
||||||
|
#include <nn/fs/CTR/MPCore/fs_FileSystemBasePrivate.h>
|
||||||
|
#include <nn/fs/fs_ApiSysSaveData.h>
|
||||||
|
#include <nn/am.h>
|
||||||
|
#include <nn/cfg.h>
|
||||||
|
#include <nn/cfg/CTR/cfg_ApiInit.h>
|
||||||
|
|
||||||
|
#include "demo.h"
|
||||||
|
|
||||||
|
#include "common_Types.h"
|
||||||
|
#include "CommonLogger.h"
|
||||||
|
#include "HeapManager.h"
|
||||||
|
#include "XmlCreator.h"
|
||||||
|
#include "BgsCommunicator.h"
|
||||||
|
#include "SimpleXmlPreprocessor.h"
|
||||||
|
|
||||||
|
using namespace nn::test;
|
||||||
|
|
||||||
|
class BgsCommunicatorTest : public Suite {
|
||||||
|
public:
|
||||||
|
virtual bool InitializeSuite();
|
||||||
|
virtual void FinalizeSuite();
|
||||||
|
|
||||||
|
BgsCommunicatorTest() {
|
||||||
|
TEST_ADD(BgsCommunicatorTest::Exec);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
void Exec();
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
void PutString(std::string str)
|
||||||
|
{
|
||||||
|
if (str.size() > 254)
|
||||||
|
{
|
||||||
|
for (size_t pos = 0; pos < str.size(); pos += 254)
|
||||||
|
{
|
||||||
|
NN_LOG("%s", str.substr(pos, nn::math::Min(static_cast<unsigned int>(254), str.size() - pos)).c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NN_LOG("%s\n", str.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
void DumpHttpBody(u8* pBodyBuf, size_t contentLength)
|
||||||
|
{
|
||||||
|
#ifndef NN_SWITCH_DISABLE_DEBUG_PRINT
|
||||||
|
NN_LOG("---HTTP Body Dump(Content-Length=%d)---\n", contentLength);
|
||||||
|
int hexCheckCount = 0;
|
||||||
|
for (int i = 0; i < contentLength; ++i)
|
||||||
|
{
|
||||||
|
NN_LOG("%02x ", pBodyBuf[i]);
|
||||||
|
++hexCheckCount;
|
||||||
|
if (hexCheckCount == 16)
|
||||||
|
{
|
||||||
|
NN_LOG("\n");
|
||||||
|
hexCheckCount = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NN_LOG("\n---HTTP Body Dump END---------------------------------\n");
|
||||||
|
#else
|
||||||
|
NN_UNUSED_VAR(pBodyBuf);
|
||||||
|
NN_UNUSED_VAR(contentLength);
|
||||||
|
NN_UNUSED_VAR(statusCode);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const size_t s_GxHeapSize = 0x800000;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
// Initialize/Finalize
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool BgsCommunicatorTest::InitializeSuite()
|
||||||
|
{
|
||||||
|
// os の初期化
|
||||||
|
nn::os::Initialize();
|
||||||
|
|
||||||
|
nn::fs::Initialize();
|
||||||
|
|
||||||
|
// amの初期化
|
||||||
|
nn::am::InitializeForLocalImporter();
|
||||||
|
|
||||||
|
// cfgの初期化
|
||||||
|
nn::cfg::init::Initialize();
|
||||||
|
nn::cfg::system::Initialize();
|
||||||
|
|
||||||
|
// ヒープの確保
|
||||||
|
common::InitializeHeap();
|
||||||
|
common::HeapManager gxHeap(s_GxHeapSize);
|
||||||
|
|
||||||
|
// RenderSystem の準備
|
||||||
|
uptr heapForGx = reinterpret_cast<uptr>(gxHeap.GetAddr());
|
||||||
|
demo::RenderSystemDrawing renderSystem;
|
||||||
|
renderSystem.Initialize(heapForGx, s_GxHeapSize);
|
||||||
|
|
||||||
|
// ログ描画の初期化
|
||||||
|
common::Logger::GetLoggerInstance()->Initialize(common::CONSOLE_WIDTH, common::CONSOLE_HEIGHT,
|
||||||
|
common::CONSOLE_MAX_LINE, &renderSystem);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void BgsCommunicatorTest::FinalizeSuite()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
// Test Util
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
// Test Functions
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
|
||||||
|
void BgsCommunicatorTest::Exec()
|
||||||
|
{
|
||||||
|
NN_LOG("BgsCommunicator Exec\n");
|
||||||
|
ConsoleRestore::BgsCommunicator comm;
|
||||||
|
|
||||||
|
ConsoleRestore::XmlCreator xml;
|
||||||
|
xml.Exec(17179924184, reinterpret_cast<u8*>(const_cast<char*>("EJA20305940")));
|
||||||
|
|
||||||
|
comm.Execute(xml.GetData().c_str(), xml.GetData().size());
|
||||||
|
size_t bufSize = comm.GetBodySize();
|
||||||
|
common::HeapManager heap(bufSize);
|
||||||
|
void* buf = heap.GetAddr();
|
||||||
|
comm.GetBody(reinterpret_cast<u8*>(buf), bufSize);
|
||||||
|
comm.Finalize();
|
||||||
|
|
||||||
|
// simpleXMLに変換します
|
||||||
|
ConsoleRestore::SimpleXmlPreprocessor pp;
|
||||||
|
std::string xmlData(reinterpret_cast<char*>(buf));
|
||||||
|
pp.Canonicalize(xmlData);
|
||||||
|
|
||||||
|
PutString(xmlData);
|
||||||
|
}
|
||||||
|
|
||||||
|
NN_TEST_DEFINE_MAIN(BgsCommunicatorTest)
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
End of file
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
@ -15,6 +15,6 @@
|
|||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
if $(IsTestBuild)
|
if $(IsTestBuild)
|
||||||
.SUBDIRS: TitleDownloader BgsCommunicator
|
.SUBDIRS: $(glob D, *)
|
||||||
|
|
||||||
DefineDefaultRules()
|
DefineDefaultRules()
|
||||||
|
|||||||
@ -0,0 +1,48 @@
|
|||||||
|
#!/usr/bin/env omake
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Project: Horizon
|
||||||
|
# File: OMakefile
|
||||||
|
#
|
||||||
|
# Copyright (C)2009 Nintendo Co., Ltd. All rights reserved.
|
||||||
|
#
|
||||||
|
# These coded instructions, statements, and computer programs contain
|
||||||
|
# proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||||
|
# Company Ltd., and are protected by Federal copyright law. They may
|
||||||
|
# not be disclosed to third parties or copied or duplicated in any form,
|
||||||
|
# in whole or in part, without the prior written consent of Nintendo.
|
||||||
|
#
|
||||||
|
# $Rev$
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
SUPPORTED_TARGETS = CTR-*.Process.MPCore.*
|
||||||
|
|
||||||
|
include $(makePlatformDefsPath tests)
|
||||||
|
|
||||||
|
SAMPLED_DEMOS_COMMON_INCLUDE_DIR = $(dir $(HORIZON_ROOT)/../CTR/SampleDemos/common/include)
|
||||||
|
INCLUDES += $(SAMPLED_DEMOS_COMMON_INCLUDE_DIR) \
|
||||||
|
../../../common \
|
||||||
|
../../../ConsoleRestore \
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TEST_COMMON_SOURCES[] =
|
||||||
|
../../../ConsoleRestore/SimpleXmlPreprocessor.cpp
|
||||||
|
|
||||||
|
CCFLAGS += -DCOMMON_LOGGER_DETAIL_ENABLE
|
||||||
|
|
||||||
|
SOURCES_TEST[] = test_SimpleXmlParser.cpp
|
||||||
|
|
||||||
|
ROMFS_ROOT = ../../../common/romfiles
|
||||||
|
|
||||||
|
TEST_ENVIRONMENT_PROCESSLIST = true
|
||||||
|
TEST_ENVIRONMENT_EMUMEM = true
|
||||||
|
|
||||||
|
LIBS += libnn_test \
|
||||||
|
libnn_xml_simple \
|
||||||
|
|
||||||
|
ROM_SPEC_FILE = ../../../ConsoleRestore/ConsoleRestore.rsf
|
||||||
|
DESCRIPTOR = $(HORIZON_ROOT)/resources/specfiles/private/RepairTool.desc
|
||||||
|
|
||||||
|
include $(makePlatformDefsPath build.tests)
|
||||||
|
|
||||||
|
|
||||||
|
tests: $(TEST_TARGETS)
|
||||||
@ -0,0 +1,165 @@
|
|||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Project: Horizon
|
||||||
|
File: test_SimpleXmlParser.cpp
|
||||||
|
|
||||||
|
Copyright (C)2011 Nintendo Co., Ltd. All rights reserved.
|
||||||
|
|
||||||
|
These coded instructions, statements, and computer programs contain
|
||||||
|
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||||
|
Company Ltd., and are protected by Federal copyright law. They may
|
||||||
|
not be disclosed to third parties or copied or duplicated in any form,
|
||||||
|
in whole or in part, without the prior written consent of Nintendo.
|
||||||
|
|
||||||
|
$Rev$
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include <nn.h>
|
||||||
|
#include <nn/test/test_Test.h>
|
||||||
|
#include <nn/cfg/CTR/cfg_ApiSys.h>
|
||||||
|
#include <nn/fs.h>
|
||||||
|
#include <nn/fs/CTR/fs_ArchiveTypesForSystem.h>
|
||||||
|
#include <nn/fs/CTR/MPCore/fs_FileSystemBasePrivate.h>
|
||||||
|
#include <nn/fs/fs_ApiSysSaveData.h>
|
||||||
|
#include <nn/am.h>
|
||||||
|
#include <nn/cfg.h>
|
||||||
|
#include <nn/cfg/CTR/cfg_ApiInit.h>
|
||||||
|
#include <nn/xml/simple/xml_simple_SimpleXmlParser.h>
|
||||||
|
|
||||||
|
#include "demo.h"
|
||||||
|
|
||||||
|
#include "common_Types.h"
|
||||||
|
#include "CommonLogger.h"
|
||||||
|
#include "HeapManager.h"
|
||||||
|
#include "XmlCreator.h"
|
||||||
|
#include "SimpleXmlPreprocessor.h"
|
||||||
|
|
||||||
|
using namespace nn::test;
|
||||||
|
|
||||||
|
class SimpleXmlParserTest : public Suite {
|
||||||
|
public:
|
||||||
|
SimpleXmlParserTest() {
|
||||||
|
TEST_ADD(SimpleXmlParserTest::Find);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
void Find();
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
class SimpleXmlParserGetter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static const char* GetName(const nn::xml::simple::SimpleXmlParser::Node* pNode);
|
||||||
|
static const char* GetContent(const nn::xml::simple::SimpleXmlParser::Node* pNode);
|
||||||
|
|
||||||
|
static const size_t BUF_SIZE = 1024;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static char m_Buf[BUF_SIZE];
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const char* SimpleXmlParserGetter::GetName(const nn::xml::simple::SimpleXmlParser::Node* pNode)
|
||||||
|
{
|
||||||
|
if(!pNode)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
std::memset(m_Buf, 0, sizeof(m_Buf));
|
||||||
|
std::memcpy(m_Buf, pNode->name, pNode->nameSize);
|
||||||
|
return m_Buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* SimpleXmlParserGetter::GetContent(const nn::xml::simple::SimpleXmlParser::Node* pNode)
|
||||||
|
{
|
||||||
|
if(!pNode)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
std::memset(m_Buf, 0, sizeof(m_Buf));
|
||||||
|
std::memcpy(m_Buf, pNode->content, pNode->contentSize);
|
||||||
|
return m_Buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
char SimpleXmlParserGetter::m_Buf[SimpleXmlParserGetter::BUF_SIZE];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
// Test Functions
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
|
||||||
|
void SimpleXmlParserTest::Find()
|
||||||
|
{
|
||||||
|
const char testText[] = "\
|
||||||
|
<Envelope>\
|
||||||
|
<Body>\
|
||||||
|
<GetPreInstalledInfoResponse>\
|
||||||
|
<GetPreInstalledInfoResponse>\
|
||||||
|
<Version></Version>\
|
||||||
|
<MessageId></MessageId>\
|
||||||
|
<TimeStamp>1326939225587</TimeStamp>\
|
||||||
|
<ErrorCode>0</ErrorCode>\
|
||||||
|
<ListResultTotalSize>1</ListResultTotalSize>\
|
||||||
|
<PreinstalledInfo>\
|
||||||
|
<DeviceId>17179924184</DeviceId>\
|
||||||
|
<SerialNo>EJA20305940</SerialNo>\
|
||||||
|
<Region>JPN</Region>\
|
||||||
|
<ManufactureDate>1324339327000</ManufactureDate>\
|
||||||
|
<TitleIds>000400000FEEB400,000400000FEEB000</TitleIds>\
|
||||||
|
</PreinstalledInfo>\
|
||||||
|
</GetPreInstalledInfoResponse>\
|
||||||
|
</GetPreInstalledInfoResponse>\
|
||||||
|
</Body>\
|
||||||
|
</Envelope>\
|
||||||
|
";
|
||||||
|
|
||||||
|
nn::fnd::IAllocator* pAllocator = nn::init::GetAllocator();
|
||||||
|
nn::xml::simple::SimpleXmlParser simpleXmlParser(pAllocator);
|
||||||
|
simpleXmlParser.parse(reinterpret_cast<u8*>(const_cast<char*>(testText)), sizeof(testText) - 1);
|
||||||
|
|
||||||
|
|
||||||
|
NN_TEST_ASSERT(!simpleXmlParser.isError());
|
||||||
|
const nn::xml::simple::SimpleXmlParser::Node* pRootNode = simpleXmlParser.getRootNode();
|
||||||
|
const nn::xml::simple::SimpleXmlParser::Node* pTargetNode = pRootNode->firstChild;
|
||||||
|
// 欲しい情報がある場所まで階層を掘り下げる
|
||||||
|
const nn::xml::simple::SimpleXmlParser::Node* pPriorityNode = nn::xml::simple::SimpleXmlParser::FindNextNode(
|
||||||
|
pTargetNode, "Body");
|
||||||
|
pPriorityNode = nn::xml::simple::SimpleXmlParser::FindNextNode(pPriorityNode->firstChild,
|
||||||
|
"GetPreInstalledInfoResponse");
|
||||||
|
pPriorityNode = nn::xml::simple::SimpleXmlParser::FindNextNode(pPriorityNode->firstChild,
|
||||||
|
"GetPreInstalledInfoResponse");
|
||||||
|
pPriorityNode = nn::xml::simple::SimpleXmlParser::FindNextNode(pPriorityNode->firstChild, "PreinstalledInfo");
|
||||||
|
|
||||||
|
{
|
||||||
|
const nn::xml::simple::SimpleXmlParser::Node* pTaskIdNode = nn::xml::simple::SimpleXmlParser::FindNextNode(
|
||||||
|
pPriorityNode->firstChild, "DeviceId");
|
||||||
|
NN_TEST_ASSERT(pTaskIdNode);
|
||||||
|
NN_TEST_ASSERT_EQUAL(std::strcmp("DeviceId", SimpleXmlParserGetter::GetName(pTaskIdNode)), 0);
|
||||||
|
NN_TEST_ASSERT_EQUAL(std::strcmp("17179924184", SimpleXmlParserGetter::GetContent(pTaskIdNode)), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const nn::xml::simple::SimpleXmlParser::Node* pTaskIdNode = nn::xml::simple::SimpleXmlParser::FindNextNode(
|
||||||
|
pPriorityNode->firstChild, "SerialNo");
|
||||||
|
NN_TEST_ASSERT(pTaskIdNode);
|
||||||
|
NN_TEST_ASSERT_EQUAL(std::strcmp("SerialNo", SimpleXmlParserGetter::GetName(pTaskIdNode)), 0);
|
||||||
|
NN_TEST_ASSERT_EQUAL(std::strcmp("EJA20305940", SimpleXmlParserGetter::GetContent(pTaskIdNode)), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const nn::xml::simple::SimpleXmlParser::Node* pTaskIdNode = nn::xml::simple::SimpleXmlParser::FindNextNode(
|
||||||
|
pPriorityNode->firstChild, "TitleIds");
|
||||||
|
NN_TEST_ASSERT(pTaskIdNode);
|
||||||
|
NN_TEST_ASSERT_EQUAL(std::strcmp("TitleIds", SimpleXmlParserGetter::GetName(pTaskIdNode)), 0);
|
||||||
|
NN_TEST_ASSERT_EQUAL(std::strcmp("000400000FEEB400,000400000FEEB000", SimpleXmlParserGetter::GetContent(pTaskIdNode)), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
NN_TEST_DEFINE_MAIN(SimpleXmlParserTest)
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
End of file
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
Loading…
Reference in New Issue
Block a user