Merge pull request #17 from outis1one/claude/fix-extension-connectivity-QNhcq
Fix device listing parser to match bash script logic
This commit is contained in:
+49
-41
@@ -3773,58 +3773,66 @@ def get_registered_endpoints():
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
def get_devices():
|
def get_devices():
|
||||||
"""Parse pjsip.conf to get device information"""
|
"""Parse pjsip.conf to get device information - matches bash script logic"""
|
||||||
devices = []
|
devices = []
|
||||||
if not os.path.exists(PJSIP_CONF):
|
if not os.path.exists(PJSIP_CONF):
|
||||||
return devices
|
return devices
|
||||||
|
|
||||||
with open(PJSIP_CONF, 'r') as f:
|
with open(PJSIP_CONF, 'r') as f:
|
||||||
content = f.read()
|
lines = f.readlines()
|
||||||
|
|
||||||
# Parse devices using a state machine approach
|
dev_name = None
|
||||||
current_device = None
|
dev_cat = None
|
||||||
current_ext = None
|
dev_aa = None
|
||||||
|
|
||||||
for line in content.split('\n'):
|
for line in lines:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
|
|
||||||
# Match device comment line (handles variable spacing before ===)
|
# Match device comment line
|
||||||
if line.startswith('; === Device:'):
|
if '; === Device:' in line:
|
||||||
match = re.match(r'; === Device:\s*(.+?)\s*\((\w+)\)\s*(\[AA:(yes|no)\])?\s*===', line)
|
# Parse: ; === Device: Name (category) [AA:yes/no] ===
|
||||||
if match:
|
temp = line.split('; === Device:')[1] if '; === Device:' in line else ''
|
||||||
current_device = {
|
temp = temp.split('===')[0].strip() # Remove trailing ===
|
||||||
'name': match.group(1).strip(),
|
|
||||||
'category': match.group(2),
|
|
||||||
'auto_answer': match.group(4) if match.group(3) else None,
|
|
||||||
'extension': None,
|
|
||||||
'password': None,
|
|
||||||
'transport': 'udp',
|
|
||||||
'encryption': 'no'
|
|
||||||
}
|
|
||||||
current_ext = None
|
|
||||||
|
|
||||||
# Match extension section header
|
# Check for AA tag
|
||||||
elif current_device and re.match(r'^\[(\d{3})\]$', line):
|
dev_aa = None
|
||||||
ext = re.match(r'^\[(\d{3})\]$', line).group(1)
|
if '[AA:yes]' in temp:
|
||||||
if current_device['extension'] is None:
|
dev_aa = 'yes'
|
||||||
current_device['extension'] = ext
|
temp = temp.replace('[AA:yes]', '').strip()
|
||||||
current_ext = ext
|
elif '[AA:no]' in temp:
|
||||||
elif ext == current_ext:
|
dev_aa = 'no'
|
||||||
# Same extension, could be auth or aor section
|
temp = temp.replace('[AA:no]', '').strip()
|
||||||
pass
|
|
||||||
|
|
||||||
# Parse properties within sections
|
# Extract category from parentheses
|
||||||
elif current_device and current_ext:
|
if '(' in temp and ')' in temp:
|
||||||
if line.startswith('transport=transport-'):
|
dev_cat = temp[temp.rfind('(')+1:temp.rfind(')')]
|
||||||
current_device['transport'] = line.split('-')[1]
|
dev_name = temp[:temp.rfind('(')].strip()
|
||||||
elif line.startswith('media_encryption='):
|
else:
|
||||||
current_device['encryption'] = line.split('=')[1]
|
dev_name = temp
|
||||||
elif line.startswith('password='):
|
dev_cat = 'unknown'
|
||||||
current_device['password'] = line.split('=')[1]
|
|
||||||
# Found password, device is complete
|
# Match extension line [xxx]
|
||||||
devices.append(current_device)
|
elif dev_name and re.match(r'^\[(\d+)\]$', line):
|
||||||
current_device = None
|
ext = re.match(r'^\[(\d+)\]$', line).group(1)
|
||||||
current_ext = None
|
devices.append({
|
||||||
|
'name': dev_name,
|
||||||
|
'category': dev_cat,
|
||||||
|
'extension': ext,
|
||||||
|
'auto_answer': dev_aa,
|
||||||
|
'transport': 'udp', # Default, will check below
|
||||||
|
'encryption': 'no'
|
||||||
|
})
|
||||||
|
dev_name = None
|
||||||
|
dev_cat = None
|
||||||
|
dev_aa = None
|
||||||
|
|
||||||
|
# Update transport/encryption for last added device
|
||||||
|
elif devices and line.startswith('transport=transport-'):
|
||||||
|
devices[-1]['transport'] = line.split('transport-')[1]
|
||||||
|
elif devices and line.startswith('media_encryption='):
|
||||||
|
val = line.split('=')[1]
|
||||||
|
if val != 'no':
|
||||||
|
devices[-1]['encryption'] = val
|
||||||
|
|
||||||
return devices
|
return devices
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user