ExtPackUtil.cpp revision 4b9d6701570cb98fd36e209314239d104ec584d3
/* $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 "ExtPackUtil.h"
/**
* Reads the extension pack description.
*
* @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 description file.
* @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 description.
*/
a_pExtPackDesc->uRevision = 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;
}
/**
* Validates the extension pack name.
*
* @returns true if valid, false if not.
* @param pszName The name to validate.
*/
bool VBoxExtPackIsValidName(const char *pszName)
{
/* This must match the code in the extension manager. */
return false;
pszName++;
return *pszName == '\0';
}
/**
* 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... */
if (!RT_C_IS_DIGIT(*pszVersion))
return false;
for (;;)
{
while (RT_C_IS_DIGIT(*pszVersion))
pszVersion++;
if (*pszVersion != '.')
break;
}
/* 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';
}