Skip to content

Commit

Permalink
Issues/188: data_coding should not be applied to all C-Octet String f…
Browse files Browse the repository at this point in the history
…ields (#190)

What:
 - BugFix, `data_coding` should not be applied to all fields that are of type C-octet string
- Have the naz messsage protocol only use `utf8` for encoding/decoding

Why:
- fixes: #188
- A  C-Octet string, is a series of ASCII characters terminated with the NULL character.      
   see; section 3.1 of SMPP spec      
  Thus we need to encode any field that is a C-Octet strings as ascii and also terminate them with NULL char(chr(0).encode())     
eg, ` system_id.encode("ascii") + chr(0).encode()`     
  Also they should be decoded as such; `message_id.decode('ascii')`
  • Loading branch information
komuw authored Dec 5, 2019
1 parent cc6ce64 commit 309030d
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 131 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
static_analysis:
name: static_analysis
runs-on: ubuntu-18.04
timeout-minutes: 5
timeout-minutes: 6
steps:
- name: Set up python
uses: actions/setup-python@v1
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ most recent version is listed first.
- Rename `naz.nazcodec.BaseNazCodec` to `naz.codec.BaseCodec`: https://github.com/komuw/naz/pull/191
- Rename `naz.Client.codec_class` to `naz.Client.codec`: https://github.com/komuw/naz/pull/191
- Add ability for `naz.log.SimpleLogger` to render logs as a python dictionary: https://github.com/komuw/naz/pull/191
- BugFix, `data_coding` should not be applied to all fields that are of type C-octet string: https://github.com/komuw/naz/pull/190
- Have the naz messsage protocol only use utf8 for encoding/decoding: https://github.com/komuw/naz/pull/190


## **version:** v0.7.4
Expand Down
36 changes: 17 additions & 19 deletions docs/_modules/naz/client.html

Large diffs are not rendered by default.

48 changes: 12 additions & 36 deletions docs/_modules/naz/protocol.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/client.html
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@
<dl class="method">
<dt id="naz.client.Client.tranceiver_bind">
<em class="property">async </em><code class="sig-name descname">tranceiver_bind</code><span class="sig-paren">(</span><em class="sig-param">log_id=''</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/naz/client.html#Client.tranceiver_bind"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#naz.client.Client.tranceiver_bind" title="Permalink to this definition"></a></dt>
<dd><p>send a BIND_RECEIVER pdu to SMSC.</p>
<dd><p>send a BIND_TRANSCEIVER pdu to SMSC.</p>
<dl class="field-list simple">
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p><code class="docutils literal notranslate"><span class="pre">None</span></code></p>
Expand Down
18 changes: 7 additions & 11 deletions docs/protocol.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
<span id="protocol"></span><h1>protocol<a class="headerlink" href="#module-naz.protocol" title="Permalink to this headline"></a></h1>
<dl class="class">
<dt id="naz.protocol.Message">
<em class="property">class </em><code class="sig-prename descclassname">naz.protocol.</code><code class="sig-name descname">Message</code><span class="sig-paren">(</span><em class="sig-param">version</em>, <em class="sig-param">smpp_command</em>, <em class="sig-param">log_id</em>, <em class="sig-param">pdu=None</em>, <em class="sig-param">codec=None</em>, <em class="sig-param">short_message=None</em>, <em class="sig-param">source_addr=None</em>, <em class="sig-param">destination_addr=None</em>, <em class="sig-param">hook_metadata=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/naz/protocol.html#Message"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#naz.protocol.Message" title="Permalink to this definition"></a></dt>
<em class="property">class </em><code class="sig-prename descclassname">naz.protocol.</code><code class="sig-name descname">Message</code><span class="sig-paren">(</span><em class="sig-param">version</em>, <em class="sig-param">smpp_command</em>, <em class="sig-param">log_id</em>, <em class="sig-param">pdu=None</em>, <em class="sig-param">short_message=None</em>, <em class="sig-param">source_addr=None</em>, <em class="sig-param">destination_addr=None</em>, <em class="sig-param">hook_metadata=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/naz/protocol.html#Message"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#naz.protocol.Message" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>The message protocol for <cite>naz</cite>. It is the code representation of what
gets queued into a naz broker.</p>
Expand All @@ -188,16 +188,16 @@
</div>
<dl class="method">
<dt id="naz.protocol.Message.__init__">
<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param">version</em>, <em class="sig-param">smpp_command</em>, <em class="sig-param">log_id</em>, <em class="sig-param">pdu=None</em>, <em class="sig-param">codec=None</em>, <em class="sig-param">short_message=None</em>, <em class="sig-param">source_addr=None</em>, <em class="sig-param">destination_addr=None</em>, <em class="sig-param">hook_metadata=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/naz/protocol.html#Message.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#naz.protocol.Message.__init__" title="Permalink to this definition"></a></dt>
<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param">version</em>, <em class="sig-param">smpp_command</em>, <em class="sig-param">log_id</em>, <em class="sig-param">pdu=None</em>, <em class="sig-param">short_message=None</em>, <em class="sig-param">source_addr=None</em>, <em class="sig-param">destination_addr=None</em>, <em class="sig-param">hook_metadata=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/naz/protocol.html#Message.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#naz.protocol.Message.__init__" title="Permalink to this definition"></a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>version</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code>) – This indicates the current version of the naz message protocol. This version will enable naz to be able to evolve in future; a future version of <cite>naz</cite> may ship with a different message protocol.</p></li>
<li><p><strong>smpp_command</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) – any one of the SMSC commands eg submit_sm</p></li>
<li><p><strong>log_id</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) – a unique identify of this reque</p></li>
<li><p><strong>pdu</strong> (<code class="xref py py-data docutils literal notranslate"><span class="pre">Union</span></code>[<code class="docutils literal notranslate"><span class="pre">None</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code>]) – the full PDU as sent to SMSC. It is mutually exclusive with <cite>short_message</cite>.</p></li>
<li><p><strong>codec</strong> (<code class="xref py py-data docutils literal notranslate"><span class="pre">Union</span></code>[<code class="docutils literal notranslate"><span class="pre">None</span></code>, <a class="reference internal" href="codec.html#naz.codec.BaseCodec" title="naz.codec.BaseCodec"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseCodec</span></code></a>]) – python class instance to be used to encode/decode messages. It should be a child class of <cite>naz.codec.BaseCodec</cite>.
You should only specify this, if you also specified <cite>pdu</cite>, else you can leave it as None.</p></li>
<li><p><strong>pdu</strong> (<code class="xref py py-data docutils literal notranslate"><span class="pre">Union</span></code>[<code class="docutils literal notranslate"><span class="pre">None</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code>]) – the full PDU as sent to SMSC. It is mutually exclusive with <cite>short_message</cite>.
Note that the pdu is a byte that may contain different SMSC fields that are encoded using different schemes.
Some fields may be <cite>struct.pack(“&gt;I”)</cite> others <cite>.encode(“ascii”)</cite> and still others <cite>codec.encode(“ucs2”)</cite></p></li>
<li><p><strong>short_message</strong> (<code class="xref py py-data docutils literal notranslate"><span class="pre">Union</span></code>[<code class="docutils literal notranslate"><span class="pre">None</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>]) – message to send to SMSC. It is mutually exclusive with <cite>pdu</cite></p></li>
<li><p><strong>source_addr</strong> (<code class="xref py py-data docutils literal notranslate"><span class="pre">Union</span></code>[<code class="docutils literal notranslate"><span class="pre">None</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>]) – the identifier(eg msisdn) of the message sender.</p></li>
<li><p><strong>destination_addr</strong> (<code class="xref py py-data docutils literal notranslate"><span class="pre">Union</span></code>[<code class="docutils literal notranslate"><span class="pre">None</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>]) – the identifier(eg msisdn) of the message receiver.</p></li>
Expand All @@ -212,16 +212,12 @@

<dl class="method">
<dt id="naz.protocol.Message.from_json">
<em class="property">static </em><code class="sig-name descname">from_json</code><span class="sig-paren">(</span><em class="sig-param">json_message</em>, <em class="sig-param">codec=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/naz/protocol.html#Message.from_json"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#naz.protocol.Message.from_json" title="Permalink to this definition"></a></dt>
<em class="property">static </em><code class="sig-name descname">from_json</code><span class="sig-paren">(</span><em class="sig-param">json_message</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/naz/protocol.html#Message.from_json"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#naz.protocol.Message.from_json" title="Permalink to this definition"></a></dt>
<dd><p>Deserializes the message protocol from json. You can use this method if you would
like to return the <cite>Message</cite> from a broker like redis/rabbitmq/postgres etc.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>json_message</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) – <cite>naz.protocol.Message</cite> in json format.</p></li>
<li><p><strong>codec</strong> (<code class="xref py py-data docutils literal notranslate"><span class="pre">Union</span></code>[<code class="docutils literal notranslate"><span class="pre">None</span></code>, <a class="reference internal" href="codec.html#naz.codec.BaseCodec" title="naz.codec.BaseCodec"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseCodec</span></code></a>]) – python class instance to be used to encode/decode messages. It should be a child class of <cite>naz.codec.BaseCodec</cite>.
You should only specify this, if <cite>json_message</cite> has a key called <cite>pdu</cite> and it is not None.</p></li>
</ul>
<dd class="field-odd"><p><strong>json_message</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) – <cite>naz.protocol.Message</cite> in json format.</p>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p><a class="reference internal" href="#naz.protocol.Message" title="naz.protocol.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a></p>
Expand Down
Loading

0 comments on commit 309030d

Please sign in to comment.