100 std::string nnn = objname;
105 while ((pos = nnn.find_first_of(
"- []<>#:&?/\'\"\\")) != std::string::npos)
106 nnn.replace(pos, 1,
"_");
108 itemname = nnn.c_str();
112 itemname.
Form(
"%s_%d", nnn.c_str(),
cnt++);
228 "When member specified, pointer on object (not member) should be provided; use SetFoundResult");
307 if (obj && !obj_name)
311 if (!obj_name || (*obj_name == 0))
314 const char *full_name =
nullptr;
318 const char *
slash = strrchr(obj_name,
'/');
320 full_name = obj_name;
321 obj_name =
slash + 1;
363 while (*separ ==
'/') {
419 :
TNamed(
name,
"sniffer of root objects"), fObjectsPath(objpath)
463 const char *rslash = strrchr(path,
'/');
466 if (!rslash || (*rslash == 0))
496 if (!item_name || (*item_name == 0) || !
fCurrentArg)
511 if (!username || !option || (*option == 0))
514 if (strcmp(option,
"all") == 0)
517 if (strcmp(username, option) == 0)
520 if (strstr(option, username) == 0)
529 return find ? 2 : -1;
543 if (!full_item_name || (*full_item_name == 0))
546 const char *item_name = strrchr(full_item_name,
'/');
549 if (!item_name || (*item_name == 0))
550 item_name = full_item_name;
555 const char *options =
nullptr;
559 while ((obj = iter()) !=
nullptr) {
560 const char *title = obj->
GetTitle();
562 if (strstr(title, pattern1.
Data()) == title) {
563 options = title + pattern1.
Length();
566 if (strstr(title, pattern2.
Data()) == title) {
567 options = title + pattern2.
Length();
606 if (!cl || !ptr || rec.
Done())
616 while ((obj = iter()) !=
nullptr) {
618 if (!rdata || strchr(rdata->
GetName(),
'.'))
628 member_ptr = *((
char **)member_ptr);
632 if (chld.
GoInside(rec, member, 0,
this)) {
637 if (coll_offset >= 0) {
645 const char *title = member->
GetTitle();
646 if (title && (strlen(title) != 0))
674 if (coll_offset >= 0) {
697 TClass *cl = obj ? obj->IsA() :
nullptr;
699 const char *pos = strstr(cl ? cl->
GetTitle() :
"",
"*SNIFF*");
710 const char *pos0 = pos;
711 while ((*pos != 0) && (*pos !=
'='))
717 Bool_t quotes = (*pos ==
'\"');
722 while ((*pos != 0) && (*pos != (quotes ?
'\"' :
' ')))
724 TString value(pos0, pos - pos0);
738 if (strcmp(key->
GetClassName(),
"TDirectoryFile") == 0) {
743 obj_class = dir->IsA();
775 if ((!lst || (lst->
GetSize() == 0)) && (!keys_lst || (keys_lst->
GetSize() == 0)))
780 if (!folderrec.
GoInside(rec,
nullptr, foldername,
this))
804 if (!chld.
GoInside(master, obj,
nullptr,
this)) {
816 while ((next = iter()) !=
nullptr) {
842 TIter iter(keys_lst);
845 while ((kobj = iter()) !=
nullptr) {
846 TKey *key =
dynamic_cast<TKey *
>(kobj);
869 if (chld.
GoInside(master, obj, fullname.
Data(),
this)) {
874 if (chld.
SetResult(keyobj, keyobj->IsA()))
881 TClass *obj_class = obj->IsA();
917 fTopFolder = std::make_unique<TFolder>(
"http",
"Dedicated instance");
936 Error(
"RegisterObject",
"Not found top ROOT folder!!!");
944 httpfold = topf->
AddFolder(
"http",
"ROOT http server");
948 gROOT->GetListOfCleanups()->Add(httpfold);
977 if (chld.
GoInside(rec,
nullptr,
"StreamerInfo",
this)) {
981 chld.
SetField(
"_after_request",
"JSROOT.MarkAsStreamerInfo");
1054 if (res_member && res_cl && !member) {
1060 res = *((
char **)res);
1069 *member = res_member;
1107 TClass *obj_cl =
nullptr;
1118 TClass *obj_cl =
nullptr;
1121 return res && (obj_chld > 0);
1133 const char *path_ = path.c_str();
1144 TClass *obj_cl =
nullptr;
1147 if (!obj_ptr || (!obj_cl && !member))
1154 return !res.empty();
1166 if ((kind == 0) || (strcmp(kind,
"Command") != 0)) {
1168 Info(
"ExecuteCmd",
"Entry %s is not a command", path.c_str());
1173 const char *cmethod =
GetItemField(parent, obj,
"method");
1174 if (!cmethod || (strlen(cmethod) == 0)) {
1176 Info(
"ExecuteCmd",
"Entry %s do not defines method for execution", path.c_str());
1186 Info(
"ExecuteCmd",
"Entry %s not allowed for specified user", path.c_str());
1194 const char *cnumargs =
GetItemField(parent, obj,
"_numargs");
1201 for (
Int_t n = 0;
n < numargs;
n++) {
1206 Info(
"ExecuteCmd",
"For command %s argument %s not specified in options %s", path.c_str(), argname.
Data(),
1219 Info(
"ExecuteCmd",
"Executing command %s method:%s", path.c_str(), method.
Data());
1224 if (method.
Index(
"this->") == 0) {
1228 }
else if (separ !=
kNPOS) {
1236 Info(
"ExecuteCmd",
"Executing %s", method.
Data());
1241 res = std::to_string(
v);
1261 return !res.empty();
1280 if (!value || (strlen(value) == 0))
1294 if (remove_quotes && (res.
Length() > 1) && ((res[0] ==
'\'') || (res[0] ==
'\"')) &&
1295 (res[0] == res[res.
Length() - 1])) {
1347 std::vector<std::string> mem;
1352 for (
Int_t n = 0;
n < number;
n++) {
1353 const char *next = args;
1354 while ((next < ends) && (*next !=
'\n'))
1357 Error(
"ProduceMulti",
"Not enough arguments in POST block");
1361 std::string file1(args, next - args);
1364 std::string path1, opt1;
1367 std::size_t pos = file1.find_first_of(
'?');
1368 if (pos != std::string::npos) {
1369 opt1 = file1.substr(pos + 1, file1.length() - pos);
1374 pos = file1.find_last_of(
'/');
1375 if (pos != std::string::npos) {
1376 path1 = file1.substr(0, pos);
1377 file1.erase(0, pos + 1);
1381 path1 = path +
"/" + path1;
1386 Produce(path1, file1, opt1, res1);
1396 mem.emplace_back(std::move(res1));
1404 for (
unsigned n = 0;
n < mem.size();
n++)
1405 length += 4 + mem[
n].length();
1407 char *curr = (
char *)str.data();
1408 for (
unsigned n = 0;
n < mem.size();
n++) {
1410 *curr++ = (char)(
l & 0xff);
1412 *curr++ = (char)(
l & 0xff);
1414 *curr++ = (char)(
l & 0xff);
1416 *curr++ = (char)(
l & 0xff);
1417 if (!mem[
n].empty())
1418 memcpy(curr, mem[
n].data(), mem[
n].length());
1419 curr += mem[
n].length();
1484 if (
file ==
"root.bin")
1487 if (
file ==
"root.png")
1490 if (
file ==
"root.jpeg")
1493 if (
file ==
"root.gif")
1496 if (
file ==
"exe.bin")
1499 if (
file ==
"root.xml")
1502 if (
file ==
"root.json")
1506 if (
file ==
"exe.txt")
1509 if (
file ==
"exe.json")
1512 if (
file ==
"cmd.json")
1515 if (
file ==
"item.json")
1518 if (
file ==
"item.xml")
1521 if (
file ==
"multi.bin")
1524 if (
file ==
"multi.json")
1536 if (!httpfold)
return nullptr;
1546 if (within_objects && ((path.
Length() == 0) || (path[0] !=
'/')))
1552 while (path.
Tokenize(tok, from,
"/")) {
1561 while ((obj = iter()) !=
nullptr) {
1571 obj = fold->
AddFolder(tok,
"sub-folder");
1588 return dynamic_cast<TFolder *
>(
GetItem(subfolder, parent, force));
1638 Error(
"UnregisterObject",
"Not found top folder");
1682 Info(
"AccessField",
"Should be special case for top folder, support later");
1691 if (parent == chld) {
1692 last_find = find =
kTRUE;
1695 while ((obj = iter()) !=
nullptr) {
1700 last_find = (obj == chld);
1703 if (find && !last_find)
1714 return curr !=
nullptr;
1739 Error(
"AccessField",
"Fail cast to TList");
1756 if (!fullname || !
name)
1762 if (!parent || !obj)
1781 if (!parent || !obj || !
name)
1789 return field ? field->
GetTitle() :
nullptr;
1839 if (strncmp(icon,
"button;", 7) == 0) {
1850 if (strstr(method, nextname.
Data()) ==
nullptr)
1853 }
while (numargs < 100);
#define ROOT_VERSION_CODE
R__EXTERN TVirtualMutex * gROOTMutex
const char * item_prop_typename
const char * item_prop_realname
const char * item_prop_user
const char * item_prop_autoload
const char * item_prop_more
const char * item_prop_kind
const char * item_prop_arraydim
const char * item_prop_title
const char * item_prop_rootversion
const char * item_prop_hidden
char * Form(const char *fmt,...)
#define R__LOCKGUARD(mutex)
static TString ConvertToJSON(const TObject *obj, Int_t compact=0, const char *member_name=nullptr)
Converts object, inherited from TObject class, to JSON string Lower digit of compact parameter define...
TClass instances represent classes, structs and namespaces in the ROOT type system.
void BuildRealData(void *pointer=0, Bool_t isTransient=kFALSE)
Build a full list of persistent data members.
TList * GetListOfRealData() const
Int_t GetBaseClassOffset(const TClass *toBase, void *address=0, bool isDerivedObject=true)
Long_t Property() const
Set TObject::fBits and fStreamerType to cache information about the class.
TRealData * GetRealData(const char *name) const
Return pointer to TRealData element with name "name".
Collection abstract base class.
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
All ROOT classes may have RTTI (run time type identification) support added.
Int_t GetMaxIndex(Int_t dim) const
Return maximum index for array dimension "dim".
const char * GetTrueTypeName() const
Get full type description of data member, e,g.: "class TDirectory*".
Int_t GetArrayDim() const
Return number of array dimensions.
Bool_t IsBasic() const
Return true if data member is a basic type, e.g. char, int, long...
Int_t IsSTLContainer()
The return type is defined in TDictionary (kVector, kList, etc.)
Bool_t IsaPointer() const
Return true if data member is a pointer.
const char * GetTypeName() const
Get type of data member, e,g.: "class TDirectory*" -> "TDirectory".
const char * GetArrayIndex() const
If the data member is pointer and has a valid array size in its comments GetArrayIndex returns a stri...
Long_t Property() const
Get property description word. For meaning of bits see EProperty.
Describe directory structure in memory.
virtual TList * GetList() const
virtual TList * GetListOfKeys() const
A TFolder object is a collection of objects and folders.
TFolder * AddFolder(const char *name, const char *title, TCollection *collection=0)
Create a new folder and add it to the list of folders of this folder, return a pointer to the created...
TCollection * GetListOfFolders() const
virtual void Add(TObject *obj)
Add object to this folder. obj must be a TObject or a TFolder.
virtual TObject * FindObject(const char *name) const
Search object identified by name in the tree of folders inside this folder.
virtual void RecursiveRemove(TObject *obj)
Recursively remove object from a folder.
virtual void Remove(TObject *obj)
Remove object from this folder. obj must be a TObject or a TFolder.
const char * GetUserName() const
return authenticated user name (0 - when no authentication)
const void * GetPostData() const
return pointer on posted with request data
Long_t GetPostDataLength() const
return length of posted with request data
Book space in a file, create I/O buffers, to fill them, (un)compress them.
virtual const char * GetClassName() const
Short_t GetCycle() const
Return cycle number associated to this key.
virtual TObject * ReadObj()
To read a TObject* from the file.
virtual void Add(TObject *obj)
virtual void AddFirst(TObject *obj)
Add object at the beginning of the list.
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
virtual void AddAfter(const TObject *after, TObject *obj)
Insert object after object after in the list.
The TNamed class is the base class for all named ROOT classes.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
virtual const char * GetTitle() const
Returns title of object.
virtual const char * GetName() const
Returns name of object.
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
Collectable string class.
Mother of all ROOT objects.
virtual const char * GetName() const
Returns name of object.
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
virtual const char * ClassName() const
Returns name of class to which the object belongs.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual const char * GetTitle() const
Returns title of object.
@ kCanDelete
if object in a list can be deleted
@ kMustCleanup
if object destructor must call RecursiveRemove()
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
The TRealData class manages the effective list of all data members for a given class.
TDataMember * GetDataMember() const
virtual const char * GetName() const
Returns name of object.
Long_t GetThisOffset() const
TString fItemName
! name of current item
Int_t fLevel
! current level of hierarchy
Int_t fRestriction
! restriction 0 - default, 1 - read-only, 2 - full access
Bool_t CanExpandItem()
Returns true when item can be expanded.
TRootSnifferStore * fStore
! object to store results
@ kSearch
search for specified item (only objects and collections)
@ kOnlyFields
if set, only fields for specified item will be set (but all fields)
@ kExpand
expand of specified item - allowed to scan object members
@ kCheckChilds
check if there childs, very similar to search
@ kScan
normal scan of hierarchy
@ kActions
mask for actions, only actions copied to child rec
virtual ~TRootSnifferScanRec()
destructor
void SetField(const char *name, const char *value, Bool_t with_quotes=kTRUE)
Set item field only when creating is specified.
void CloseNode()
close started node
Bool_t CanSetFields() const
return true when fields could be set to the hierarchy item
UInt_t fMask
! defines operation kind
void MakeItemName(const char *objname, TString &itemname)
Construct item name, using object name as basis.
Bool_t IsReadyForResult() const
Checks if result will be accepted.
Bool_t SetResult(void *obj, TClass *cl, TDataMember *member=nullptr)
Obsolete, use SetFoundResult instead.
Bool_t fHasMore
! indicates that potentially there are more items can be found
Bool_t IsReadOnly(Bool_t dflt=kTRUE)
Returns read-only flag for current item.
Bool_t GoInside(TRootSnifferScanRec &super, TObject *obj, const char *obj_name=nullptr, TRootSniffer *sniffer=nullptr)
Method verifies if new level of hierarchy should be started with provided object.
void BeforeNextChild()
indicates that new child for current element will be started
TRootSnifferScanRec * fParent
! pointer on parent record
void SetRootClass(TClass *cl)
Mark item with ROOT class and correspondent streamer info.
void CreateNode(const char *_node_name)
Starts new node, must be closed at the end.
Int_t fNumChilds
! number of childs
Int_t fNumFields
! number of fields
Bool_t fNodeStarted
! indicate if node was started
Bool_t SetFoundResult(void *obj, TClass *cl, TDataMember *member=nullptr)
Set found element with class and datamember (optional)
const char * fSearchPath
! current path searched
Int_t Depth() const
Returns depth of hierarchy.
TList fItemsNames
! list of created items names, need to avoid duplication
Bool_t Done() const
Method indicates that scanning can be interrupted while result is set.
Bool_t ScanOnlyFields() const
return true when only fields are scanned by the sniffer
void BuildFullName(TString &buf, TRootSnifferScanRec *prnt=nullptr)
Produces full name for the current item.
TRootSnifferScanRec()
constructor
Storage of hierarchy scan in TRootSniffer in JSON format.
Storage of hierarchy scan in TRootSniffer in XML format.
Abstract interface for storage of hierarchy scan in TRootSniffer.
Int_t GetResNumChilds() const
TDataMember * GetResMember() const
virtual void CreateNode(Int_t, const char *)
void SetResult(void *_res, TClass *_rescl, TDataMember *_resmemb, Int_t _res_chld, Int_t restr=0)
set pointer on found element, class and number of childs
virtual void CloseNode(Int_t, Int_t)
TClass * GetResClass() const
virtual void BeforeNextChild(Int_t, Int_t, Int_t)
Int_t GetResRestrict() const
virtual void SetField(Int_t, const char *, const char *, Bool_t)
void ScanObjectMembers(TRootSnifferScanRec &rec, TClass *cl, char *ptr)
scan object data members some members like enum or static members will be excluded
const char * GetAutoLoad() const
return name of configured autoload scripts (or 0)
TString fObjectsPath
! default path for registered objects
void ScanHierarchy(const char *topname, const char *path, TRootSnifferStore *store, Bool_t only_fields=kFALSE)
Method scans normal objects, registered in ROOT.
void SetCurrentCallArg(THttpCallArg *arg)
set current http arguments, which then used in different process methods For instance,...
TList fRestrictions
! list of restrictions for different locations
Bool_t RegisterObject(const char *subfolder, TObject *obj)
Register object in subfolder structure subfolder parameter can have many levels like:
virtual void ScanObjectChilds(TRootSnifferScanRec &rec, TObject *obj)
scans object childs (if any) here one scans collection, branches, trees and so on
TString fCurrentAllowedMethods
! list of allowed methods, extracted when analyzed object restrictions
virtual Bool_t HasStreamerInfo() const
Bool_t UnregisterObject(TObject *obj)
unregister (remove) object from folders structures folder itself will remain even when it will be emp...
virtual void ScanKeyProperties(TRootSnifferScanRec &rec, TKey *key, TObject *&obj, TClass *&obj_class)
scans key properties in special cases load objects from the file
Bool_t CreateItem(const char *fullname, const char *title)
create item element
virtual Bool_t ExecuteCmd(const std::string &path, const std::string &options, std::string &res)
Execute command marked as _kind=='Command'.
TRootSniffer(const char *name, const char *objpath="Objects")
constructor
Bool_t HasRestriction(const char *item_name)
Made fast check if item with specified name is in restriction list If returns true,...
virtual void ScanObjectProperties(TRootSnifferScanRec &rec, TObject *obj)
scans object properties here such fields as _autoload or _icon properties depending on class or objec...
virtual void ScanRoot(TRootSnifferScanRec &rec)
scan complete ROOT objects hierarchy For the moment it includes objects in gROOT directory and list o...
Bool_t Produce(const std::string &path, const std::string &file, const std::string &options, std::string &res)
Method produce different kind of data out of object Parameter 'path' specifies object or object membe...
virtual Bool_t ProduceJson(const std::string &path, const std::string &options, std::string &res)
Produce JSON data for specified item For object conversion TBufferJSON is used.
void CreateOwnTopFolder()
Create own TFolder structures independent from gROOT This allows to have many independent TRootSniffe...
virtual Bool_t ProduceExe(const std::string &path, const std::string &options, Int_t reskind, std::string &res)
Execute command for specified object Options include method and extra list of parameters sniffer shou...
virtual Bool_t ProduceXml(const std::string &path, const std::string &options, std::string &res)
Produce XML data for specified item For object conversion TBufferXML is used.
TString DecodeUrlOptionValue(const char *value, Bool_t remove_quotes=kTRUE)
method replaces all kind of special symbols, which could appear in URL options
void Restrict(const char *path, const char *options)
Restrict access to the specified location.
virtual ULong_t GetItemHash(const char *itemname)
Get hash function for specified item used to detect any changes in the specified object.
Bool_t fReadOnly
! indicate if sniffer allowed to change ROOT structures - like read objects from file
void SetScanGlobalDir(Bool_t on=kTRUE)
When enabled (default), sniffer scans gROOT for files, canvases, histograms.
TObject * GetItem(const char *fullname, TFolder *&parent, Bool_t force=kFALSE, Bool_t within_objects=kTRUE)
return item from the subfolders structure
THttpCallArg * fCurrentArg
! current http arguments (if any)
virtual Bool_t ProduceImage(Int_t kind, const std::string &path, const std::string &options, std::string &res)
Method to produce image from specified object.
TObject * FindTObjectInHierarchy(const char *path)
Search element in hierarchy, derived from TObject.
void SetAutoLoad(const char *scripts="")
When specified, _autoload attribute will be always add to top element of h.json/h....
virtual void * FindInHierarchy(const char *path, TClass **cl=nullptr, TDataMember **member=nullptr, Int_t *chld=nullptr)
Search element with specified path Returns pointer on element Optionally one could obtain element cla...
virtual Bool_t ProduceItem(const std::string &path, const std::string &options, std::string &res, Bool_t asjson=kTRUE)
Produce JSON/XML for specified item contrary to h.json request, only fields for specified item are st...
Int_t CheckRestriction(const char *item_name)
Checked if restriction is applied to the item full_item_name should have full path to the item.
Bool_t IsItemField(TObject *obj) const
return true when object is TNamed with kItemField bit set such objects used to keep field values for ...
virtual ~TRootSniffer()
destructor
virtual Bool_t CanDrawClass(TClass *)
Int_t fCurrentRestrict
! current restriction for last-found object
TFolder * GetTopFolder(Bool_t force=kFALSE)
Returns top TFolder instance for the sniffer.
const char * GetItemField(TFolder *parent, TObject *item, const char *name)
return field for specified item
std::unique_ptr< TFolder > fTopFolder
! own top TFolder object, used for registering objects
Bool_t CanExploreItem(const char *path)
Method returns true when object has childs or one could try to expand item.
Bool_t SetItemField(const char *fullname, const char *name, const char *value)
set field for specified item
Int_t WithCurrentUserName(const char *option)
return 2 when option match to current user name return 1 when option==all return 0 when option does n...
Bool_t RegisterCommand(const char *cmdname, const char *method, const char *icon)
Register command which can be executed from web interface.
TString fAutoLoad
! scripts names, which are add as _autoload parameter to h.json request
Bool_t IsScanGlobalDir() const
Returns true when sniffer allowed to scan global directories.
virtual Bool_t ProduceBinary(const std::string &path, const std::string &options, std::string &res)
Produce binary data for specified item if "zipped" option specified in query, buffer will be compress...
TFolder * GetSubFolder(const char *foldername, Bool_t force=kFALSE)
creates subfolder where objects can be registered
void ScanCollection(TRootSnifferScanRec &rec, TCollection *lst, const char *foldername=nullptr, TCollection *keys_lst=nullptr)
scan collection content
Bool_t AccessField(TFolder *parent, TObject *item, const char *name, const char *value, TNamed **only_get=nullptr)
set or get field for the child each field coded as TNamed object, placed after chld in the parent hie...
virtual Bool_t ProduceMulti(const std::string &path, const std::string &options, std::string &res, Bool_t asjson=kTRUE)
Process several requests, packing all results into binary or JSON buffer Input parameters should be c...
Bool_t CanDrawItem(const char *path)
Method verifies if object can be drawn.
virtual Int_t GetLast() const
Returns index of last object in collection.
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Int_t Atoi() const
Return integer value of string.
const char * Data() const
TString & ReplaceAll(const TString &s1, const TString &s2)
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
UInt_t Hash(ECaseCompare cmp=kExact) const
Return hash value.
TString & Remove(Ssiz_t pos)
TString & Append(const char *cs)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
This class represents a WWW compatible URL.
const char * GetValueFromOptions(const char *key) const
Return a value for a given key from the URL options.
Int_t GetIntValueFromOptions(const char *key) const
Return a value for a given key from the URL options as an Int_t, a missing key returns -1.
void SetOptions(const char *opt)
void ParseOptions() const
Parse URL options into a key/value map.