Ejemplo n.º 1
0
	bool sprite_instance::can_handle_mouse_event()
	// Return true if we have any mouse event handlers.
	{
		static const tu_stringi FN_NAMES[] =
		{
			"onKeyPress",
			"onRelease",
			"onDragOver",
			"onDragOut",
			"onPress",
			"onReleaseOutside",
			"onRollout",
			"onRollover",
		};

		if (is_enabled())
		{
			for (size_t i = 0; i < TU_ARRAYSIZE(FN_NAMES); i++)
			{
				as_value dummy;
				if (get_member(FN_NAMES[i], &dummy))
				{
					return true;
				}
			}
		}
		return false;
	}
Ejemplo n.º 2
0
	void	as_global_textformat_ctor(const fn_call& fn)
	{
		gc_ptr<as_textformat>	obj = new as_textformat(fn.get_player());

		assert(unsigned(fn.nargs) <= TU_ARRAYSIZE(as_global_textformat_ctor_paramnames));

		// TODO: check parameters type
		for (int i = 0; i < fn.nargs; i++)
		{
			obj->set_member(as_global_textformat_ctor_paramnames[i], fn.arg(i));
		}

		fn.result->set_as_object(obj.get_ptr());
	}
Ejemplo n.º 3
0
static const char* lookup_content_type(const char* file_extension)
// Given a file extension, determine the HTTP content type to return.
{
	static stringi_hash<const char*> s_types;
	static bool s_inited = false;
	if (!s_inited) {
		s_inited = true;

		// A small table of well-known content types.
		struct type_pair {
			const char* extension;
			const char* type;
		} types[] = {
			{ "txt", "text/plain" },
			{ "html", "text/html" },
			{ "htm", "text/html" },
			{ "jpg", "image/jpeg" },
			{ "jpeg", "image/jpeg" },
			{ "gif", "image/gif" },
			{ "png", "image/png" },
			{ "js", "text/javascript" },
			// etc.
		};

		// Register the types.
		for (int i = 0, n = TU_ARRAYSIZE(types); i < n; i++) {
			s_types.add(tu_stringi(types[i].extension), types[i].type);
		}
	}

	const char* type = NULL;
	if (s_types.get(tu_stringi(file_extension), &type)) {
		return type;
	}

	// No known type for this file extension.
	return "application/octet-stream";
}
Ejemplo n.º 4
0
/*static*/ void http_server::parse_test()
{
	// Test the parsing of the request line (first line).
	static struct reqline_test_vector
	{
		const char* reqline;
		http_status status;
		const char* method;
		const char* uri;
		int version_x256;
	}
	tests[] =
	{
		{ "GET http://tulrich.com/index.html HTTP/1.1", HTTP_OK, "GET", "http://tulrich.com/index.html", 0x0101 },
		{ "POST /index.html HTTP/1.1", HTTP_OK, "POST", "/index.html", 0x0101 },
		{ "PUT * HTTP/1.0", HTTP_OK, "PUT", "*", 0x0100 },
		{ "OPTIONS http://localhost/ HTTP/1.1", HTTP_OK, "OPTIONS", "http://tulrich.com/", 0x0101 },
		{ "HEAD * HTTP/1.2", HTTP_HTTP_VERSION_NOT_SUPPORTED, "HEAD", "*", 0x0102 },
		{ "nospaces", HTTP_BAD_REQUEST, "", "", 0 },
		{ "one spaces", HTTP_BAD_REQUEST, "", "", 0 },
		{ "too  many spaces", HTTP_BAD_REQUEST, "", "", 0 },
		{ "too many  spaces", HTTP_HTTP_VERSION_NOT_SUPPORTED, "", "", 0 },
	};

	for (int i = 0; i < TU_ARRAYSIZE(tests); i++)
	{
		http_server::http_request_state state;
		int status = state.parse_request_line(tests[i].reqline);
		if (status >= 400)
		{
			// Make sure test is expected to fail.
			assert(tests[i].status >= 400);
			printf("status = %d, expected = %d\n", status, int(tests[i].status));
		}
		else
		{
			assert(state.m_req.m_method == tests[i].method);
			assert(state.m_req.m_uri == tests[i].uri);
			assert(state.m_req.m_http_version_x256 == tests[i].version_x256);

			printf("reqline = %s\n", tests[i].reqline);
			printf("Req method = %s\n", state.m_req.m_method.c_str());
			printf("Req URI = %s\n", state.m_req.m_uri.c_str());
			printf("Req version = 0x%X\n", state.m_req.m_http_version_x256);
		}
		printf("\n");
	}

	// Test parsing of whole header.
	static struct header_test_vector
	{
		const char* headertext;
		http_status status;
		const char* path;
		const char* file;
		const char* arg_list;
		const char* argval_list;
	}
	tests2[] =
	{
		{ "GET http://127.0.0.1/path/to/SomeJunk.html?a=1&b=2 HTTP/1.1\r\n"
		  "Host: 127.0.0.1\r\n"
		  "User-Agent: something or other\r\n"
		  "\r\n"
		  "" // Message body
		  ,
		  HTTP_OK,
		  "path/to",
		  "SomeJunk.html",
		  "a,b",
		  "1,2"
	};
	
}


int main()
{
	http_server::parse_test();

	return 0;
}