Example #1
0
bool Config::ParseFile(const wchar_t * wsPath)
{
	JSONSTREAM *stream = json_new_stream(jsonNodeComplete, jsonNodeError, this);
	
	FILE *f = NULL;
	char buffer[256];
	memset(buffer, 0, sizeof(buffer));
	int iResult = _wfopen_s(&f, wsPath, L"rt");
	if (iResult == 0 && f != NULL)
	{
		while (buffer != NULL && !feof(f))
		{
			fgets(buffer, sizeof(buffer), f);
			RemoveComments(buffer);
			json_stream_push(stream, buffer);
		}

		fclose(f);
	}
	// TODO: file not found

	json_delete_stream(stream);

	if (m_wsUrl != std::wstring())
	{
		m_bLoadSuccess = true;
		return true;
	}

	return false;
}
Example #2
0
SEXP
R_json_stream_push(SEXP r_stream, SEXP r_txt)
{
    JSONSTREAM *stream;
    stream = R_getStreamRef(r_stream);

    json_stream_push(stream, CHAR(STRING_ELT(r_txt, 0)));
    return(ScalarLogical(1));
}
Example #3
0
SEXP
R_json_stream_parse(SEXP str, SEXP fun)
{
    JSONSTREAM *stream;
    SEXP nodeRef;
#ifdef NEW_JSON_NEW_STREAM 
    SEXP expr;
#endif    

    PROTECT(expr = allocVector(LANGSXP, 2));
    SETCAR(expr, fun);
    nodeRef = makeNodeRef(NULL);
    SETCAR(CDR(expr), nodeRef);

#ifdef NEW_JSON_NEW_STREAM 
    stream = json_new_stream(R_stream_callback, NULL, expr);
#else
    stream = json_new_stream(R_stream_callback);
#endif

    json_stream_push(stream, CHAR(STRING_ELT(str, 0)));
    UNPROTECT(1);
    return(R_NilValue);
}
void TestSuite::TestStreams(void){
#ifdef JSON_STREAM
    UnitTest::SetPrefix("TestStreams.cpp - Streams");
    counter = 0;
	errorCounter = 0;

    #ifdef JSON_LIBRARY
	   JSONSTREAM * test = json_new_stream(Callback, errorCallback, (void*)0xDEADBEEF);
	   json_stream_push(test, JSON_TEXT("{}[]"));
	   assertEquals(2, counter);
	   assertEquals(0, errorCounter);
	   json_stream_push(test, JSON_TEXT("{\"hel"));
	   assertEquals(2, counter);
	   assertEquals(0, errorCounter);
	   json_stream_push(test, JSON_TEXT("lo\" : 1"));
	   assertEquals(2, counter);
	   assertEquals(0, errorCounter);
	   json_stream_push(test, JSON_TEXT("}["));
	   assertEquals(3, counter);
	   assertEquals(0, errorCounter);
	   json_stream_push(test, JSON_TEXT("1,2,3]{\"hi\" : { \"one\" : 1}"));
	   assertEquals(4, counter);
	   assertEquals(0, errorCounter);
	   json_stream_push(test, JSON_TEXT("}"));
	   assertEquals(5, counter);
	   assertEquals(0, errorCounter);
	
		#ifdef JSON_SAFE
			json_stream_push(test, JSON_TEXT("{\"hello\":12keaueuataueaouhe"));
			assertEquals(1, errorCounter);
		#endif
	   json_delete_stream(test);
    #else
	   JSONStream test(Callback, errorCallback, (void*)0xDEADBEEF);
	   test << JSON_TEXT("{}[]");
	   assertEquals(2, counter);
	   assertEquals(0, errorCounter);
	   test << JSON_TEXT("{\"hel");
	   assertEquals(2, counter);
	   assertEquals(0, errorCounter);
	   test << JSON_TEXT("lo\" : 1");
	   assertEquals(2, counter);
	   assertEquals(0, errorCounter);
	   test << JSON_TEXT("}[");
	   assertEquals(3, counter);
	   assertEquals(0, errorCounter);
	   test << JSON_TEXT("1,2,3]{\"hi\" : { \"one\" : 1}");
	   assertEquals(4, counter);
	   assertEquals(0, errorCounter);
	   test << JSON_TEXT("}");
	   assertEquals(5, counter);
	   assertEquals(0, errorCounter);
	
		#ifdef JSON_SAFE
			test << JSON_TEXT("{\"hello\":12keaueuataueaouhe");
			assertEquals(1, errorCounter);
		#endif
	
		#ifdef JSON_SECURITY_MAX_STREAM_OBJECTS
			test.reset();
			unsigned int currentCount = errorCounter;
			json_string safe;
			for(int i = 0; i < JSON_SECURITY_MAX_STREAM_OBJECTS; ++i){
				safe += JSON_TEXT("{}");
			}
			test << safe;
			assertEquals(133, counter);
			assertEquals(currentCount, errorCounter);
	
			test.reset();
			json_string unsafe;
			for(int i = 0; i <= JSON_SECURITY_MAX_STREAM_OBJECTS + 1; ++i){
				unsafe += JSON_TEXT("{}");
			}
			test << unsafe;
			assertEquals(261, counter);
			assertEquals(currentCount + 1, errorCounter);
		#endif
    #endif
#endif
}