<p>Pascal Cadotte Michaud has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/10554">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">contrib/sip_to_pjsip: handle setvar in conversion<br><br>Given a sip.conf with the following content:<br><br>setvar FOO=1<br>setvar BAR=42<br><br>I want my generated pjsip.conf to containt the following set_vars<br><br>set_var FOO=1<br>set_var BAR=42<br><br>in the matching endpoint section.<br><br>Change-Id: I6c822401fda4133c3b44bf31e655b4eb939d4d26<br>---<br>M contrib/scripts/sip_to_pjsip/sip_to_pjsip.py<br>1 file changed, 20 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/54/10554/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py b/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py</span><br><span>index d05f97d..1860a31 100755</span><br><span>--- a/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py</span><br><span>+++ b/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py</span><br><span>@@ -40,6 +40,11 @@</span><br><span> return sect</span><br><span> </span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+def ignore(key=None, val=None, section=None, pjsip=None,</span><br><span style="color: hsl(120, 100%, 40%);">+ nmapped=None, type='endpoint'):</span><br><span style="color: hsl(120, 100%, 40%);">+ """Ignore a key and mark it as mapped"""</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> def set_value(key=None, val=None, section=None, pjsip=None,</span><br><span> nmapped=None, type='endpoint'):</span><br><span> """Sets the key to the value within the section in pjsip.conf"""</span><br><span>@@ -508,6 +513,7 @@</span><br><span> ['dtlscapath', set_value('dtls_ca_path')],</span><br><span> ['dtlssetup', set_value('dtls_setup')],</span><br><span> ['encryption_taglen', from_encryption_taglen],</span><br><span style="color: hsl(120, 100%, 40%);">+ ['setvar', ignore],</span><br><span> </span><br><span> ############################ maps to an aor ###################################</span><br><span> </span><br><span>@@ -1117,6 +1123,19 @@</span><br><span> reg.write(pjsip, nmapped)</span><br><span> </span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+def map_setvars(sip, section, pjsip, nmapped):</span><br><span style="color: hsl(120, 100%, 40%);">+ """</span><br><span style="color: hsl(120, 100%, 40%);">+ Map all setvar in peer section to the appropriate endpoint set_var</span><br><span style="color: hsl(120, 100%, 40%);">+ """</span><br><span style="color: hsl(120, 100%, 40%);">+ try:</span><br><span style="color: hsl(120, 100%, 40%);">+ setvars = sip.section(section)[0].get('setvar')</span><br><span style="color: hsl(120, 100%, 40%);">+ except LookupError:</span><br><span style="color: hsl(120, 100%, 40%);">+ return</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ for setvar in setvars:</span><br><span style="color: hsl(120, 100%, 40%);">+ set_value('set_var', setvar, section, pjsip, nmapped)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> def map_peer(sip, section, pjsip, nmapped):</span><br><span> """</span><br><span> Map the options from a peer section in sip.conf into the appropriate</span><br><span>@@ -1218,6 +1237,7 @@</span><br><span> pass</span><br><span> else:</span><br><span> map_peer(sip, section, pjsip, nmapped)</span><br><span style="color: hsl(120, 100%, 40%);">+ map_setvars(sip, section, pjsip, nmapped)</span><br><span> </span><br><span> find_non_mapped(sip.defaults(), nmapped)</span><br><span> find_non_mapped(sip.sections(), nmapped)</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10554">change 10554</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/10554"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I6c822401fda4133c3b44bf31e655b4eb939d4d26 </div>
<div style="display:none"> Gerrit-Change-Number: 10554 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Pascal Cadotte Michaud <pcm@wazo.io> </div>