summaryrefslogtreecommitdiff
path: root/src/VBox/Main/include/GuestCtrlImplPrivate.h
diff options
context:
space:
mode:
authorvboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f>2023-04-13 16:48:07 +0000
committervboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f>2023-04-13 16:48:07 +0000
commitc23c41087495dbadb52e678829759dee0393bdef (patch)
tree40194a0259e49bdba4e8f47ed107cb636e25f295 /src/VBox/Main/include/GuestCtrlImplPrivate.h
parent2f2e09ff8c6839b82d91c57dbcc60531064a7616 (diff)
downloadVirtualBox-svn-c23c41087495dbadb52e678829759dee0393bdef.tar.gz
Guest Control: Completely revamped / overhauled the (now legacy) stream output parsing code and added lots of documentation to it. This way it should be a lot clearer what it's supposed to be doing.
Also, this now should fix some nasty bugs in that area we had in the past especially with some Linux guests (i.e. OL6), which sometimes send output data in a very unsteady manner. Also overhauled the testcases while at it. Luckily, this is all host-based code, so older Guest Additions also will benefit from this. git-svn-id: https://www.virtualbox.org/svn/vbox/trunk@99392 cfe28804-0f27-0410-a406-dd0f0b0b656f
Diffstat (limited to 'src/VBox/Main/include/GuestCtrlImplPrivate.h')
-rw-r--r--src/VBox/Main/include/GuestCtrlImplPrivate.h47
1 files changed, 40 insertions, 7 deletions
diff --git a/src/VBox/Main/include/GuestCtrlImplPrivate.h b/src/VBox/Main/include/GuestCtrlImplPrivate.h
index 394c4a328db..a9365b74b9f 100644
--- a/src/VBox/Main/include/GuestCtrlImplPrivate.h
+++ b/src/VBox/Main/include/GuestCtrlImplPrivate.h
@@ -972,8 +972,8 @@ class GuestToolboxStreamValue
public:
GuestToolboxStreamValue(void) { }
- GuestToolboxStreamValue(const char *pszValue)
- : mValue(pszValue) {}
+ GuestToolboxStreamValue(const char *pszValue, size_t cwcValue = RTSTR_MAX)
+ : mValue(pszValue, cwcValue) {}
GuestToolboxStreamValue(const GuestToolboxStreamValue& aThat)
: mValue(aThat.mValue) { }
@@ -995,16 +995,22 @@ typedef std::map < Utf8Str, GuestToolboxStreamValue > GuestCtrlStreamPairMap;
typedef std::map < Utf8Str, GuestToolboxStreamValue >::iterator GuestCtrlStreamPairMapIter;
typedef std::map < Utf8Str, GuestToolboxStreamValue >::const_iterator GuestCtrlStreamPairMapIterConst;
+class GuestToolboxStream;
+
/**
* Class representing a block of stream pairs (key=value). Each block in a raw guest
* output stream is separated by "\0\0", each pair is separated by "\0". The overall
* end of a guest stream is marked by "\0\0\0\0".
*
+ * An empty stream block will be treated as being incomplete.
+ *
* Only used for the busybox-like toolbox commands within VBoxService.
* Deprecated, do not use anymore.
*/
class GuestToolboxStreamBlock
{
+ friend GuestToolboxStream;
+
public:
GuestToolboxStreamBlock(void);
@@ -1028,13 +1034,19 @@ public:
uint32_t GetUInt32(const char *pszKey, uint32_t uDefault = 0) const;
int32_t GetInt32(const char *pszKey, int32_t iDefault = 0) const;
- bool IsEmpty(void) { return mPairs.empty(); }
+ bool IsComplete(void) const { return !m_mapPairs.empty() && m_fComplete; }
+ bool IsEmpty(void) const { return m_mapPairs.empty(); }
+ int SetValueEx(const char *pszKey, size_t cwcKey, const char *pszValue, size_t cwcValue, bool fOverwrite = false);
int SetValue(const char *pszKey, const char *pszValue);
protected:
- GuestCtrlStreamPairMap mPairs;
+ /** Wheter the stream block is marked as complete.
+ * An empty stream block is considered as incomplete. */
+ bool m_fComplete;
+ /** Map of stream pairs this block contains.*/
+ GuestCtrlStreamPairMap m_mapPairs;
};
/** Vector containing multiple allocated stream pair objects. */
@@ -1042,6 +1054,23 @@ typedef std::vector< GuestToolboxStreamBlock > GuestCtrlStreamObjects;
typedef std::vector< GuestToolboxStreamBlock >::iterator GuestCtrlStreamObjectsIter;
typedef std::vector< GuestToolboxStreamBlock >::const_iterator GuestCtrlStreamObjectsIterConst;
+/** Defines a single terminator as a single char. */
+#define GUESTTOOLBOX_STRM_TERM '\0'
+/** Defines a single terminator as a string. */
+#define GUESTTOOLBOX_STRM_TERM_STR "\0"
+/** Defines the termination sequence for a single key/value pair. */
+#define GUESTTOOLBOX_STRM_TERM_PAIR_STR GUESTTOOLBOX_STRM_TERM_STR
+/** Defines the termination sequence for a single stream block. */
+#define GUESTTOOLBOX_STRM_TERM_BLOCK_STR GUESTTOOLBOX_STRM_TERM_STR GUESTTOOLBOX_STRM_TERM_STR
+/** Defines the termination sequence for the stream. */
+#define GUESTTOOLBOX_STRM_TERM_STREAM_STR GUESTTOOLBOX_STRM_TERM_STR GUESTTOOLBOX_STRM_TERM_STR GUESTTOOLBOX_STRM_TERM_STR GUESTTOOLBOX_STRM_TERM_STR
+/** Defines how many consequtive terminators a key/value pair has. */
+#define GUESTTOOLBOX_STRM_PAIR_TERM_CNT 1
+/** Defines how many consequtive terminators a stream block has. */
+#define GUESTTOOLBOX_STRM_BLK_TERM_CNT 2
+/** Defines how many consequtive terminators a stream has. */
+#define GUESTTOOLBOX_STRM_TERM_CNT 4
+
/**
* Class for parsing machine-readable guest process output by VBoxService'
* toolbox commands ("vbox_ls", "vbox_stat" etc), aka "guest stream".
@@ -1067,9 +1096,11 @@ public:
void Dump(const char *pszFile);
#endif
- size_t GetOffset() { return m_offBuffer; }
+ size_t GetOffset(void) const { return m_offBuf; }
+
+ size_t GetSize(void) const { return m_cbUsed; }
- size_t GetSize() { return m_cbUsed; }
+ size_t GetBlocks(void) const { return m_cBlocks; }
int ParseBlock(GuestToolboxStreamBlock &streamBlock);
@@ -1083,9 +1114,11 @@ protected:
/** Currently used size at m_offBuffer. */
size_t m_cbUsed;
/** Current byte offset within the internal stream buffer. */
- size_t m_offBuffer;
+ size_t m_offBuf;
/** Internal stream buffer. */
BYTE *m_pbBuffer;
+ /** How many completed stream blocks already were processed. */
+ size_t m_cBlocks;
};
class Guest;