PageRenderTime 29ms CodeModel.GetById 16ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llcommandhandler.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 108 lines | 31 code | 10 blank | 67 comment | 0 complexity | 1c4e8e7f7879098edeea211c6391c22a MD5 | raw file
  1/**
  2 * @file llcommandhandler.h
  3 * @brief Central registry for text-driven "commands", most of
  4 * which manipulate user interface.  For example, the command
  5 * "agent (uuid) about" will open the UI for an avatar's profile.
  6 *
  7 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  8 * Second Life Viewer Source Code
  9 * Copyright (C) 2010, Linden Research, Inc.
 10 * 
 11 * This library is free software; you can redistribute it and/or
 12 * modify it under the terms of the GNU Lesser General Public
 13 * License as published by the Free Software Foundation;
 14 * version 2.1 of the License only.
 15 * 
 16 * This library is distributed in the hope that it will be useful,
 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 19 * Lesser General Public License for more details.
 20 * 
 21 * You should have received a copy of the GNU Lesser General Public
 22 * License along with this library; if not, write to the Free Software
 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 24 * 
 25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 26 * $/LicenseInfo$
 27 */
 28#ifndef LLCOMMANDHANDLER_H
 29#define LLCOMMANDHANDLER_H
 30
 31#include "llsd.h"
 32
 33/* Example:  secondlife:///app/foo/<uuid>
 34   Command "foo" that takes one parameter, a UUID.
 35
 36class LLFooHandler : public LLCommandHandler
 37{
 38public:
 39    // Inform the system you handle commands starting
 40	// with "foo" and they are only allowed from
 41	// "trusted" (pointed at Linden content) browsers
 42	LLFooHandler() : LLCommandHandler("foo", UNTRUSTED_BLOCK) { }
 43
 44    // Your code here
 45	bool handle(const LLSD& tokens, const LLSD& query_map,
 46				LLMediaCtrl* web)
 47	{
 48		if (tokens.size() < 1) return false;
 49		LLUUID id( tokens[0] );
 50		return do_foo(id);
 51	}
 52};
 53
 54// *NOTE: Creating the object registers with the dispatcher.
 55LLFooHandler gFooHandler;
 56
 57*/
 58
 59class LLMediaCtrl;
 60
 61class LLCommandHandler
 62{
 63public:
 64	enum EUntrustedAccess
 65	{
 66		UNTRUSTED_ALLOW,       // allow commands from untrusted browsers
 67		UNTRUSTED_BLOCK,       // ignore commands from untrusted browsers
 68		UNTRUSTED_THROTTLE     // allow untrusted, but only a few per min.
 69	};
 70
 71	LLCommandHandler(const char* command, EUntrustedAccess untrusted_access);
 72		// Automatically registers object to get called when 
 73		// command is executed.  All commands can be processed
 74		// in links from LLMediaCtrl, but some (like teleport)
 75		// should not be allowed from outside the app.
 76		
 77	virtual ~LLCommandHandler();
 78
 79	virtual bool handle(const LLSD& params,
 80						const LLSD& query_map,
 81						LLMediaCtrl* web) = 0;
 82		// For URL secondlife:///app/foo/bar/baz?cat=1&dog=2
 83		// @params - array of "bar", "baz", possibly empty
 84		// @query_map - map of "cat" -> 1, "dog" -> 2, possibly empty
 85		// @web - pointer to web browser control, possibly NULL
 86		// Return true if you did something, false if the parameters
 87		// are invalid or on error.
 88};
 89
 90
 91class LLCommandDispatcher
 92{
 93public:
 94	static bool dispatch(const std::string& cmd,
 95						 const LLSD& params,
 96						 const LLSD& query_map,
 97						 LLMediaCtrl* web,
 98						 const std::string& nav_type,
 99						 bool trusted_browser);
100		// Execute a command registered via the above mechanism,
101		// passing string parameters.
102		// Returns true if command was found and executed correctly.
103	/// Return an LLSD::Map of registered LLCommandHandlers and associated
104	/// info (e.g. EUntrustedAccess).
105	static LLSD enumerate();
106};
107
108#endif