ExtPackUtil.cpp revision 8479df0918362ee801608d4f48c6d8ee8fdf505e
/* $Id$ */
/** @file
* VirtualBox Main - Extension Pack Utilities and definitions, VBoxC, VBoxSVC, ++.
*/
/*
* Copyright (C) 2010 Oracle Corporation
*
* Oracle Corporation confidential
* All rights reserved
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "include/ExtPackUtil.h"
/**
* 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 the name.
*/
if (!pNameElm)
if (!VBoxExtPackIsValidName(pszName))
if (!pDescElm)
if (!pVersionElm)
uRevision = 0;
if (!pMainModuleElm)
/*
* 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 to free.
*/
{
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 the extension pack main module string.
*
* @returns true if valid, false if not.
* @param pszMainModule The main module string to validate.
*/
bool VBoxExtPackIsValidMainModuleString(const char *pszMainModule)
{
return false;
/* Restricted charset, no extensions (dots). */
while ( RT_C_IS_ALNUM(*pszMainModule)
|| *pszMainModule == '-'
|| *pszMainModule == '_')
return *pszMainModule == '\0';
}