ExtPackUtil.cpp revision fb6a9e540c97943a42cda9701205455121e688d5
/* $Id$ */
/** @file
* VirtualBox Main - Extension Pack Utilities and definitions, VBoxC, VBoxSVC, ++.
*/
/*
* Copyright (C) 2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "include/ExtPackUtil.h"
/**
* Worker for VBoxExtPackLoadDesc that loads the plug-in descriptors.
*
* @returns Same as VBoxExtPackLoadDesc.
* @param pVBoxExtPackElm
* @param pcPlugIns Where to return the number of plug-ins in the
* array.
* @param paPlugIns Where to return the plug-in descriptor array.
* (RTMemFree it even on failure)
*/
static iprt::MiniString *
{
*pcPlugIns = 0;
/** @todo plug-ins */
return NULL;
}
/**
* Reads the extension pack descriptor.
*
* @returns NULL on success, pointer to an error message on failure (caller
* deletes it).
* @param a_pszDir The directory containing the description file.
* @param a_pExtPackDesc Where to store the extension pack descriptor.
* @param a_pObjInfo Where to store the object info for the file (unix
* attribs). Optional.
*/
iprt::MiniString *VBoxExtPackLoadDesc(const char *a_pszDir, PVBOXEXTPACKDESC a_pExtPackDesc, PRTFSOBJINFO a_pObjInfo)
{
/*
* Clear the descriptor.
*/
a_pExtPackDesc->uRevision = 0;
a_pExtPackDesc->cPlugIns = 0;
/*
* Validate, open and parse the XML file.
*/
char szFilePath[RTPATH_MAX];
if (RT_FAILURE(vrc))
if (RT_FAILURE(vrc))
if (a_pObjInfo)
*a_pObjInfo = ObjInfo;
{
return &(new iprt::MiniString)->printf("The XML file is not a file (fMode=%#x)", ObjInfo.Attr.fMode);
}
try
{
}
{
}
/*
* Get the main element and check its version.
*/
if ( !pVBoxExtPackElm
/*
* Read and validate mandatory bits.
*/
if (!pNameElm)
if (!VBoxExtPackIsValidName(pszName))
if (!pDescElm)
if (!pVersionElm)
uRevision = 0;
if (!pMainModuleElm)
/*
* The VRDE module, optional.
* Accept both none and empty as tokens of no VRDE module.
*/
const char *pszVrdeModule = NULL;
if (pVrdeModuleElm)
{
else if (!VBoxExtPackIsValidModuleString(pszVrdeModule))
}
/*
* Parse plug-in descriptions.
*/
if (pstrRet)
{
return pstrRet;
}
/*
* Everything seems fine, fill in the return values and return successfully.
*/
return NULL;
}
/**
* Frees all resources associated with a extension pack descriptor.
*
* @param a_pExtPackDesc The extension pack descriptor which members
* should be freed.
*/
{
if (!a_pExtPackDesc)
return;
a_pExtPackDesc->uRevision = 0;
a_pExtPackDesc->cPlugIns = 0;
}
/**
* Extract the extension pack name from the tarball path.
*
* @returns String containing the name on success, the caller must delete it.
* NULL if no valid name was found or if we ran out of memory.
* @param pszTarball The path to the tarball.
*/
{
/*
* Skip ahead to the filename part and count the number of characters
* that matches the criteria for a extension pack name.
*/
if (!pszSrc)
return NULL;
off++;
/*
* Check min and max name limits.
*/
if ( off > VBOX_EXTPACK_NAME_MIN_LEN
|| off < VBOX_EXTPACK_NAME_MIN_LEN)
return NULL;
/*
* Make a duplicate of the name and return it.
*/
return pStrRet;
}
/**
* Validates the extension pack name.
*
* @returns true if valid, false if not.
* @param pszName The name to validate.
* @sa VBoxExtPackExtractNameFromTarballPath
*/
bool VBoxExtPackIsValidName(const char *pszName)
{
if (!pszName)
return false;
/*
* Check the characters making up the name, only english alphabet
* characters, decimal digits and spaces are allowed.
*/
{
return false;
off++;
}
/*
* Check min and max name limits.
*/
if ( off > VBOX_EXTPACK_NAME_MAX_LEN
|| off < VBOX_EXTPACK_NAME_MIN_LEN)
return false;
return true;
}
/**
* Validates the extension pack version string.
*
* @returns true if valid, false if not.
* @param pszVersion The version string to validate.
*/
bool VBoxExtPackIsValidVersionString(const char *pszVersion)
{
return false;
/* 1.x.y.z... */
for (;;)
{
if (!RT_C_IS_DIGIT(*pszVersion))
return false;
do
pszVersion++;
while (RT_C_IS_DIGIT(*pszVersion));
if (*pszVersion != '.')
break;
pszVersion++;
}
/* upper case string + numbers indicating the build type */
{
do
pszVersion++;
while ( RT_C_IS_DIGIT(*pszVersion)
|| RT_C_IS_UPPER(*pszVersion)
|| *pszVersion == '-'
|| *pszVersion == '_');
}
/* revision or nothing */
if (*pszVersion != '\0')
{
if (*pszVersion != 'r')
return false;
do
pszVersion++;
while (RT_C_IS_DIGIT(*pszVersion));
}
return *pszVersion == '\0';
}
/**
* Validates an extension pack module string.
*
* @returns true if valid, false if not.
* @param pszModule The module string to validate.
*/
bool VBoxExtPackIsValidModuleString(const char *pszModule)
{
return false;
/* Restricted charset, no extensions (dots). */
while ( RT_C_IS_ALNUM(*pszModule)
|| *pszModule == '-'
|| *pszModule == '_')
pszModule++;
return *pszModule == '\0';
}