Skip to content

Commit

Permalink
#836 Исправил ошибки в ini парсере
Browse files Browse the repository at this point in the history
  • Loading branch information
boffart committed Nov 8, 2024
1 parent 145633e commit 78337fc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Core/Asterisk/Configs/IAXConf.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private function generateProviders(): string
$lang = str_replace('_', '-', strtolower($this->generalSettings[PbxSettings::PBX_LANGUAGE]));
$providers = $this->getProviders();
foreach ($providers as $provider) {
$manual_attributes = Util::parseIniSettings(base64_decode($provider['manualattributes']));
$manual_attributes = Util::parseIniSettings($provider['manualattributes']);
$options = [
'type' => 'friend',
'auth' => 'plaintext',
Expand Down
8 changes: 2 additions & 6 deletions src/Core/Asterisk/Configs/SIPConf.php
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ private function generateProvidersPj(): string

// Iterate through each data provider
foreach ($this->data_providers as $provider) {
$manual_attributes = Util::parseIniSettings(base64_decode($provider['manualattributes'] ?? ''));
$manual_attributes = Util::parseIniSettings($provider['manualattributes'] ?? '');

// Generate registration strings for outbound registration type
if ($provider['registration_type'] === Sip::REG_TYPE_OUTBOUND) {
Expand Down Expand Up @@ -1089,11 +1089,7 @@ private function generateProviderEndpoint(array $provider, array $manual_attribu
self::getToneZone($options, $language);

// Override PJSIP options from modules
$options = $this->overridePJSIPOptionsFromModules(
$provider['uniqid'],
$options,
AsteriskConfigInterface::OVERRIDE_PROVIDER_PJSIP_OPTIONS
);
$options = $this->overridePJSIPOptionsFromModules($provider['uniqid'], $options, AsteriskConfigInterface::OVERRIDE_PROVIDER_PJSIP_OPTIONS);

// Add configuration section header
$conf .= "[{$provider['uniqid']}]" . PHP_EOL;
Expand Down
11 changes: 9 additions & 2 deletions src/Core/System/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -742,12 +742,14 @@ public static function parseIniSettings(string $manual_attributes): array
$manual_attributes = implode("\n", $tmp_arr);
// TRIMMING END

$haveSection = strpos($manual_attributes, '[') !== false;

$manual_data = [];
$sections = explode("\n[", str_replace(']', '', $manual_attributes));
foreach ($sections as $section) {
$data_rows = explode("\n", trim($section));
$section_name = trim($data_rows[0] ?? '');
if (empty($section_name) || !str_contains($section_name, '=')) {
if (!$haveSection && str_contains($section_name, '=')) {
// Noname section
$section_name = ' ';
} else {
Expand All @@ -773,7 +775,12 @@ public static function parseIniSettings(string $manual_attributes): array
if (($value !== '0' && empty($value)) || empty($key)) {
continue;
}
$manual_data[$section_name][$key] = $value;
if( ('set_var' === $key && $section_name === 'endpoint') ||
('setvar' === $key && $section_name === ' ')) {
$manual_data[$section_name][$key][] = $value;
}else{
$manual_data[$section_name][$key] = $value;
}
}
}

Expand Down

0 comments on commit 78337fc

Please sign in to comment.