📄 settings.cpp
字号:
{
ASSERT(FALSE);
return E_INVALIDARG;
}
*ppRegistrationProfile = NULL;
ce::auto_bstr RegistrationXML;
HRESULT hr = GetSettingValue(
SIPSettingsType,
&RegistrationXML
);
if (FAILED(hr))
{
PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Failed at getting registration xml, hr = 0x%x", hr));
return hr;
}
IRTCClient* pRTCClient = GetRTCClientPointer();
if (pRTCClient == NULL)
{
return E_FAIL;
}
return CreateProfileFromXML(
RegistrationXML,
pRTCClient,
ppRegistrationProfile
);
}
/*------------------------------------------------------------------------------
Settings_t::GetVoicemailProfile
Get the voicemail RTC profile
Parameters:
ppRegistrationProfile: [out] pointer to a pointer which points the a IRTCProfile object
Returns: S_OK indicates success, otherwise failed
------------------------------------------------------------------------------*/
HRESULT
Settings_t::GetVoicemailProfile(
IRTCProfile** ppVoicemailProfile
)
{
ce::auto_bstr VoicemailXML;
HRESULT hr = GetSettingValue(
SettingTypeVoicemailSettings,
&VoicemailXML
);
if (FAILED(hr))
{
return hr;
}
IRTCClient* pRTCClient = GetRTCClientPointer();
if (pRTCClient == NULL)
{
return E_FAIL;
}
return CreateProfileFromXML(
VoicemailXML,
pRTCClient,
ppVoicemailProfile
);
}
/*------------------------------------------------------------------------------
Settings_t::UpdateVoicemailNumber
read the voice mail number from regisry and cache it as a stat store flag, which
will be shared by cprog or other applications
Parameters:
none
Returns: S_OK indicates success, otherwise failed
------------------------------------------------------------------------------*/
HRESULT
Settings_t::UpdateVoicemailNumber(
void
)
{
//always reset the voicemail number first
RegistrySetString(
SN_VOIP_VOICEMAILNUMBER_ROOT,
SN_VOIP_VOICEMAILNUMBER_PATH,
SN_VOIP_VOICEMAILNUMBER_VALUE,
L""
);
//get the new voicemail number
ce::auto_bstr VoicemailNumber;
HRESULT hr = GetSettingValue(
SettingTypeVoicemailNumber,
&VoicemailNumber
);
if (FAILED(hr))
{
return hr;
}
//save the new voicemail number
return RegistrySetString(
SN_VOIP_VOICEMAILNUMBER_ROOT,
SN_VOIP_VOICEMAILNUMBER_PATH,
SN_VOIP_VOICEMAILNUMBER_VALUE,
VoicemailNumber
);
}
/*------------------------------------------------------------------------------
Settings_t::IsSettingAvailable
Check whether a setting already exists
Parameters:
SettingType: [in] the type of setting we are looking for
Returns: true if it already exists, false otherwise.
------------------------------------------------------------------------------*/
bool
Settings_t::IsSettingAvailable(
SettingType_e SettingType
)
{
int Index = static_cast<int>(SettingType);
ASSERT(Index >= 0 && Index < ARRAYSIZE(sc_VoIPSettings));
switch (sc_VoIPSettings[Index].StorageType)
{
case StorageTypeRegistry:
return SettingAlreadyExistsInRegistry(
sc_VoIPSettings[Index].pSettingName
);
case StorageTypeFile:
return SettingFileAlreadyExists(
sc_VoIPSettings[Index].pSettingName
);
default:
ASSERT(FALSE);
return false;
}
}
/*------------------------------------------------------------------------------
Settings_t::SettingAlreadyExistsInRegistry
Check whether a setting exists in 'active' registry
Parameters:
SettingType: [in] the type of setting we are looking for
Returns: true if it already exists, false otherwise.
------------------------------------------------------------------------------*/
bool
Settings_t::SettingAlreadyExistsInRegistry(
const WCHAR* pSettingName
)
{
ASSERT((pSettingName != NULL) && pSettingName[0]);
ce::auto_hkey SubKey;
long Result = RegOpenKeyEx(
HKEY_LOCAL_MACHINE,
m_pActiveRegKeyName,
0, 0,
&SubKey
);
if (Result != ERROR_SUCCESS)
{
return false;
}
Result = RegQueryValueEx(
SubKey,
pSettingName,
NULL, NULL, NULL, NULL
);
return (Result != ERROR_FILE_NOT_FOUND);
}
/*------------------------------------------------------------------------------
Settings_t::SettingFileAlreadyExists
Check whether a setting exists as an 'active' file
Parameters:
SettingType: [in] the type of setting we are looking for
Returns: true if it already exists, false otherwise.
------------------------------------------------------------------------------*/
bool
Settings_t::SettingFileAlreadyExists(
const WCHAR* pSettingName
)
{
ASSERT((pSettingName != NULL) && pSettingName[0]);
WCHAR FileName[MAX_PATH] = L"";
//get the file name first
HRESULT hr = GetSettingFileName(
m_pActiveFilePrefix,
pSettingName,
FileName,
ARRAYSIZE(FileName)
);
if (FAILED(hr))
{
return false;
}
return PhoneAppUtilities_t::DoesFileExist(FileName);
}
/*------------------------------------------------------------------------------
Settings_t::GetSettingValue
Get setting value either from active registry or from an active setting file
Parameters:
SettingType: [in] the type of setting we are looking for
pSettingValue: [out] pointer to a BSTR which holds the return value
Returns: S_OK if it succeedes, otherwise failed
------------------------------------------------------------------------------*/
HRESULT
Settings_t::GetSettingValue(
SettingType_e SettingType,
BSTR* pSettingValue
)
{
ASSERT(pSettingValue != NULL);
BYTE* pRawValue = NULL;
DWORD RawValueSize;
DATA_BLOB DataIn = {0, NULL};
DATA_BLOB DataOut = {0, NULL};
WCHAR* pSettingString = NULL;
HRESULT hr = GetRawSettingValue(
SettingType,
&pRawValue,
&RawValueSize
);
if (FAILED(hr))
{
goto exit;
}
if (RawValueSize == 0)
{
hr = E_FAIL;
goto exit;
}
pSettingString = reinterpret_cast<WCHAR*>(pRawValue);
//see whether we need to decrypt the value
if (sc_VoIPSettings[static_cast<int>(SettingType)].ShouldBeEncrypted)
{
DataIn.pbData = pRawValue;
DataIn.cbData = RawValueSize;
if (!CryptUnprotectData(&DataIn, NULL, NULL, NULL, NULL, CRYPTPROTECT_SYSTEM, &DataOut))
{
hr = CommonUtilities_t::GetErrorFromWin32();
PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Failed at decrypting the data, hr = 0x%x", hr));
goto exit;
}
pSettingString = reinterpret_cast<WCHAR*>(DataOut.pbData);
}
*pSettingValue = SysAllocString(pSettingString);
if (*pSettingValue == NULL)
{
hr = E_OUTOFMEMORY;
}
exit:
if (pRawValue != NULL)
{
LocalFree(pRawValue);
}
if (DataOut.pbData != NULL)
{
LocalFree(DataOut.pbData);
}
return hr;
}
/*------------------------------------------------------------------------------
Settings_t::GetRawSettingValue
Get raw setting value either from active registry or from an active setting file
Parameters:
SettingType: [in] the type of setting we are looking for
ppValue: [out] the pointer of the address of an buffer which holds the return value
pValueSize: [out] the pointer to a DWORD which indicates the value size
Returns: S_OK succeedes, otherwise failed
------------------------------------------------------------------------------*/
HRESULT
Settings_t::GetRawSettingValue(
SettingType_e SettingType,
BYTE** ppValue,
DWORD* pValueSize
)
{
ASSERT(ppValue != NULL);
ASSERT(pValueSize != NULL);
int Index = static_cast<int>(SettingType);
ASSERT(Index >= 0 && Index < ARRAYSIZE(sc_VoIPSettings));
switch (sc_VoIPSettings[Index].StorageType)
{
case StorageTypeRegistry:
return GetSettingValueFromRegistry(
sc_VoIPSettings[Index].pSettingName,
ppValue,
pValueSize
);
case StorageTypeFile:
return GetSettingValueFromFile(
m_pActiveFilePrefix,
sc_VoIPSettings[Index].pSettingName,
ppValue,
pValueSize
);
default:
ASSERT(FALSE);
return E_FAIL;
}
}
/*------------------------------------------------------------------------------
Settings_t::GetDialPlan
Get the dial plan string
Parameters:
pDialPlanXML: [out] the pointer to a BSTR which holds up the return Dial Plan XML
Returns: S_OK succeedes, otherwise failed
------------------------------------------------------------------------------*/
HRESULT
Settings_t::GetDialPlan(
BSTR* pDialPlanXML
)
{
ASSERT(pDialPlanXML != NULL);
HRESULT hr;
BYTE* pSettingValue = NULL;
DWORD SettingValueSize;
hr = GetSettingValueFromFile(
sc_DialPlanFile,
&pSettingValue,
&SettingValueSize
);
if (FAILED(hr))
{
goto exit;
}
if (SettingValueSize == 0)
{
hr = E_FAIL;
goto exit;
}
*pDialPlanXML = SysAllocString(reinterpret_cast<WCHAR*>(pSettingValue));
if (*pDialPlanXML == NULL)
{
hr = E_OUTOFMEMORY;
}
exit:
if (pSettingValue != NULL)
{
LocalFree(pSettingValue);
}
return hr;
}
/*------------------------------------------------------------------------------
Settings_t::GetSettingValueFromRegistry
Get setting value from active registry, the main reason we have this function,
is to use the utilities function PhoneAppUtilities_t::GetSettingValueFromRegistry(),
which requires us to open and close the reg key by ourselves.
Parameters:
pSettingName: [in] the pointer to the setting name string
ppValue: [out] the pointer to an address of the buffer that holds the return value
pValueSize: [out] the pointer to an DWORD indicates the value size
Returns: S_OK succeedes, otherwise failed
------------------------------------------------------------------------------*/
HRESULT
Settings_t::GetSettingValueFromRegistry(
const WCHAR* pSettingName,
BYTE** ppValue,
DWORD* pValueSize
)
{
ASSERT((pSettingName != NULL) && pSettingName[0]);
ASSERT(ppValue != NULL);
ASSERT(pValueSize != NULL);
HRESULT hr = S_OK;
ce::auto_hkey ActiveRegKey;
long Result = RegOpenKeyEx(
HKEY_LOCAL_MACHINE,
m_pActiveRegKeyName,
0,
0,
&ActiveRegKey
);
if (Result != ERROR_SUCCESS)
{
return CommonUtilities_t::GetErrorFromWin32();
}
hr = GetSettingValueFromRegistryByKey(
ActiveRegKey,
pSettingName,
ppValue,
pValueSize
);
return hr;
}
/*------------------------------------------------------------------------------
QueryRegValueHR
static function to retrieve the type and data for a specified value name
associated with an open registry key
Parameters:
RegKey: [in] handle to currently open key
pSubKeyName: [in] the sub key name
pValueType: [in] Pointer to a variable that receives the type of data
associated with the specified value
pData: [in] Pointer to a buffer that receives the value's data.
DataSize: [in, out] Pointer to a variable that specifies the size, in bytes,
of the buffer pointed to by the lpData parameter
pDoesNotExist: [out, optional] pointer to a bool variable indicates if the value
exists or not
Returns: S_OK indicates success
Otherwise failure.
If the value does not exists, we return failiure. and set the *pDoesNotExist as true
Note: Caller should check *pDoesNotExists only when return value is not S_OK
------------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -