Remoto - VFS: VFS_httpd_browser_responder Class Reference
Remoto - VFS

A subclass of VFS_httpd_responder. More...

#include <VFS_httpd_browser.h>

Inheritance diagram for VFS_httpd_browser_responder:
VFS_httpd_responder

Public Member Functions

 VFS_httpd_browser_responder (QHttpRequest *req, QHttpResponse *resp, VFS_node *node, quint16 port)
 
virtual ~VFS_httpd_browser_responder ()
 
virtual void respond ()
 based on http status, write page contents or an error to the responder More...
 
- Public Member Functions inherited from VFS_httpd_responder
 VFS_httpd_responder (QHttpRequest *req, QHttpResponse *resp)
 
virtual ~VFS_httpd_responder ()
 VFS_httpd_responder destructor. More...
 

Public Attributes

QJsonDocument _data
 The response data, populated after a VFS_request is complete, or immediately if not asynchronous. More...
 
bool _done
 If the _m_resp has finished, or was aborted or deleted, mark this as true. More...
 
QString _mode
 either browse, report, command, or file. Used in fetchFile() More...
 
bool _needsToIssueRequest
 A flag that means the request is asynchronous and will be satisfied after a VFS_request completes. More...
 
- Public Attributes inherited from VFS_httpd_responder
QHttpRequest * _m_req
 http request object More...
 
QHttpResponse * _m_resp
 http response object More...
 
QString _mime
 mime type to send More...
 
QString _path
 path component of url More...
 
quint64 _size
 the size of the response data More...
 
int _status
 http status More...
 
QUrl _url
 requested url More...
 

Protected Slots

void done ()
 Mark the responder as _done, and schedule a deletion with deleteLater(). More...
 
- Protected Slots inherited from VFS_httpd_responder
virtual void accumulate (const QByteArray &)
 This seems to be used during an http push request. More...
 

Protected Member Functions

QByteArray fetchResponse ()
 Actually fetch and/or prep the response data. More...
 
QByteArray lsDir ()
 Convert an incoming json object to an html <ul> for display. More...
 
QByteArray processRHTML (QByteArray page)
 Detokenize an .rhtml file. More...
 
virtual void validatePath (QUrl url)
 Based on the incoming url, decide what work needs to be done. More...
 
- Protected Member Functions inherited from VFS_httpd_responder
virtual QByteArray errorPage ()
 The default error page. More...
 

Protected Attributes

VFS_node_node
 The VFS_node that is _dataRoot. This is unused. More...
 
quint16 _port
 The port that VFS_httpd_browser is listening on. Only used as a print value when processing .rhtml files. More...
 
bool _process
 A flag meaning that the response data must be detokenized. This is used for .rhtml files. More...
 

Private Member Functions

QJsonValue getSystemValue (QString which)
 Return information about the system running VFS. More...
 

Additional Inherited Members

- Signals inherited from VFS_httpd_responder
void done ()
 signal that this responder is complete, and can be deleted More...
 

Detailed Description

A subclass of VFS_httpd_responder.

This class actually does all the work to determine if a request is valid and needs to be processed, and sets the http status.

It also parses and detokenizes .rhtml files.

Definition at line 33 of file VFS_httpd_browser.h.

Constructor & Destructor Documentation

◆ VFS_httpd_browser_responder()

VFS_httpd_browser_responder::VFS_httpd_browser_responder ( QHttpRequest *  req,
QHttpResponse *  resp,
VFS_node node,
quint16  port 
)
Parameters
reqThe http request object
respThe http response object
nodeThe _dataRoot node, which is unused
portThe port that VFS_httpd_browser is listening on. Only used as a print value when processing .rhtml files.

validatePath() is immediately called on the incoming request url.

Definition at line 198 of file VFS_httpd_browser.cpp.

◆ ~VFS_httpd_browser_responder()

VFS_httpd_browser_responder::~VFS_httpd_browser_responder ( )
virtual

Definition at line 212 of file VFS_httpd_browser.cpp.

Member Function Documentation

◆ done

void VFS_httpd_browser_responder::done ( )
protectedslot

Mark the responder as _done, and schedule a deletion with deleteLater().

Definition at line 220 of file VFS_httpd_browser.cpp.

◆ fetchResponse()

QByteArray VFS_httpd_browser_responder::fetchResponse ( )
protected

Actually fetch and/or prep the response data.

Returns
The http response data

At this point, _data has been populated if a VFS_request has completed.

Based on mode, determine if a Qt resource is to be read, ls() formatting needs to be done, or if a /command is to be executed.

The returned data here is written to the end client.

Definition at line 355 of file VFS_httpd_browser.cpp.

◆ getSystemValue()

QJsonValue VFS_httpd_browser_responder::getSystemValue ( QString  which)
private

Return information about the system running VFS.

Parameters
whichWhich parameter to fetch
Returns
A QJsonValue containing the result

Possible values:

  • cpucount
  • cpusample
  • memtotal
  • memsample

Definition at line 593 of file VFS_httpd_browser.cpp.

◆ lsDir()

QByteArray VFS_httpd_browser_responder::lsDir ( )
protected

Convert an incoming json object to an html <ul> for display.

Returns
the html <ul> list

Definition at line 504 of file VFS_httpd_browser.cpp.

◆ processRHTML()

QByteArray VFS_httpd_browser_responder::processRHTML ( QByteArray  page)
protected

Detokenize an .rhtml file.

Parameters
pageThe incoming file contents
Returns
The detokenized contents

Tokens will be in the form [###token###]

<p>Here is some <b>html</b> text with a token: [###token###]</p>

Only a few tokens are recognized:

  • hostname
  • port
  • app_path
  • arguments
  • version
  • uptime
  • vfs_requests

Definition at line 551 of file VFS_httpd_browser.cpp.

◆ respond()

void VFS_httpd_browser_responder::respond ( )
virtual

based on http status, write page contents or an error to the responder

Reimplemented from VFS_httpd_responder.

Definition at line 231 of file VFS_httpd_browser.cpp.

◆ validatePath()

void VFS_httpd_browser_responder::validatePath ( QUrl  url)
protectedvirtual

Based on the incoming url, decide what work needs to be done.

Parameters
urlThe url

The VFS_httpd_browser serves some basic files from its Qt resource object. But more importantly it uses paths to create commands.

The path prefixes are:

  • /browse[/some/VFS/path] – return the list of children for a subpath
  • /report[/some/VFS/path] – fetch a report for a node
  • /read[/some/VFS/path] – read the contents of a node. Useful for reading logs.
  • /command/exit – kill the VFS server
  • /command/parameters – fetch VFS::parameters()
  • /status – a json object with an aggregate of all statuses
  • /status/requests – a json object reporting VFS_request information
  • /status/requests/outstanding – a sample of the number of outstanding VFS_requests exist. This number should be near zero on a system without leaking VFS_request instances.
  • /status/requests/sample – the number of VFS_request instances created since the sample buffer was cleared. If a VFS_activity node is present, this will clear once per second.
  • /status/system – json report of information available about the system running VFS
  • /status/system/cpu – cpu information: count=number of logical cores, sample=sample percent usage of cpu resources
  • /status/system/memory – memory information: total=amount, in gigabytes, available on the system; sample=percent of current memory usage
  • /status/system/uptime – uptime for the system: string=human readable, ms=milliseconds
  • / – serve the root index.rhtml file
  • /[some/path] – see if a path exists in the local Qt resource object

This method sets the responder mode, the mime type and http status for the response, and flags this request as asynchronous or not.

Reimplemented from VFS_httpd_responder.

Definition at line 286 of file VFS_httpd_browser.cpp.

Member Data Documentation

◆ _data

QJsonDocument VFS_httpd_browser_responder::_data

The response data, populated after a VFS_request is complete, or immediately if not asynchronous.

Definition at line 45 of file VFS_httpd_browser.h.

◆ _done

bool VFS_httpd_browser_responder::_done

If the _m_resp has finished, or was aborted or deleted, mark this as true.

Definition at line 47 of file VFS_httpd_browser.h.

◆ _mode

QString VFS_httpd_browser_responder::_mode

either browse, report, command, or file. Used in fetchFile()

Definition at line 44 of file VFS_httpd_browser.h.

◆ _needsToIssueRequest

bool VFS_httpd_browser_responder::_needsToIssueRequest

A flag that means the request is asynchronous and will be satisfied after a VFS_request completes.

Definition at line 43 of file VFS_httpd_browser.h.

◆ _node

VFS_node* VFS_httpd_browser_responder::_node
protected

The VFS_node that is _dataRoot. This is unused.

Definition at line 52 of file VFS_httpd_browser.h.

◆ _port

quint16 VFS_httpd_browser_responder::_port
protected

The port that VFS_httpd_browser is listening on. Only used as a print value when processing .rhtml files.

Definition at line 53 of file VFS_httpd_browser.h.

◆ _process

bool VFS_httpd_browser_responder::_process
protected

A flag meaning that the response data must be detokenized. This is used for .rhtml files.

Definition at line 50 of file VFS_httpd_browser.h.


The documentation for this class was generated from the following files: