Skip to content

Commit

Permalink
Merge pull request #402 from jookies/v0.9
Browse files Browse the repository at this point in the history
V0.9
  • Loading branch information
farirat committed Mar 1, 2016
2 parents 5601262 + 8ec243e commit e34d87a
Show file tree
Hide file tree
Showing 66 changed files with 927 additions and 696 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
*.py[cod]
*~

# Jasmin
misc/config/store

# C extensions
*.so

Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: python
python:
- '2.7'
env:
- ROOT_PATH=~/jasmin JASMIN_RELEASE=0.8.post14
- ROOT_PATH=~/jasmin JASMIN_RELEASE=0.9b1
# Command to install dependencies
install:
- python setup.py sdist
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ MAINTAINER Jookies LTD <jasmin@jookies.net>
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
RUN groupadd -r jasmin && useradd -r -g jasmin jasmin

ENV JASMIN_VERSION 0.8.post14
ENV JASMIN_VERSION 0.9b1

# Install requirements
RUN apt-get update && apt-get install -y \
Expand Down
6 changes: 3 additions & 3 deletions jasmin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"""Jasmin SMS Gateway by Jookies LTD <jasmin@jookies.net>"""

MAJOR = 0
MINOR = 8
PATCH = 14
META = 'post'
MINOR = 9
PATCH = 1
META = 'b'

def get_version():
"Will return Jasmin's version"
Expand Down
2 changes: 1 addition & 1 deletion jasmin/bin/jasmind.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Options(usage.Options):
class JasminDaemon(object):

def __init__(self, opt):
self.options = options
self.options = opt
self.components = {}

@defer.inlineCallbacks
Expand Down
16 changes: 8 additions & 8 deletions jasmin/config/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def _get(self, section, option, default=None):
otherwise
"""

if self.config.has_section(section) == False:
if not self.config.has_section(section):
return default
if self.config.has_option(section, option) == False:
if not self.config.has_option(section, option):
return default
if self.config.get(section, option) == 'None':
return None
Expand All @@ -45,9 +45,9 @@ def _getint(self, section, option, default=None):
default otherwise
"""

if self.config.has_section(section) == False:
if not self.config.has_section(section):
return default
if self.config.has_option(section, option) == False:
if not self.config.has_option(section, option):
return default
if self.config.get(section, option) == 'None':
return default
Expand All @@ -60,9 +60,9 @@ def _getfloat(self, section, option, default=None):
default otherwise
"""

if self.config.has_section(section) == False:
if not self.config.has_section(section):
return default
if self.config.has_option(section, option) == False:
if not self.config.has_option(section, option):
return default
if self.config.get(section, option) == 'None':
return default
Expand All @@ -75,9 +75,9 @@ def _getbool(self, section, option, default=None):
default otherwise
"""

if self.config.has_section(section) == False:
if not self.config.has_section(section):
return default
if self.config.has_option(section, option) == False:
if not self.config.has_option(section, option):
return default

return self.config.getboolean(section, option)
4 changes: 2 additions & 2 deletions jasmin/interceptor/interceptor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import pickle
import cPickle as pickle
import datetime as dt
from logging.handlers import TimedRotatingFileHandler
from twisted.spread import pb
Expand Down Expand Up @@ -63,7 +63,7 @@ def perspective_run_script(self, pyCode, routable):
self.log.warn('Execution delay [%ss] for script [%s].', delay, pyCode)

if glo['smpp_status'] == 0 and glo['http_status'] == 0:
return pickle.dumps(glo['routable'])
return pickle.dumps(glo['routable'], pickle.HIGHEST_PROTOCOL)
else:
# If we have one of the statuses set to non-zero value
# then both of them must be non-zero to avoid misbehaviour
Expand Down
56 changes: 25 additions & 31 deletions jasmin/managers/clients.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import pickle
import cPickle as pickle
import time
import datetime
from twisted.spread import pb
Expand Down Expand Up @@ -32,7 +32,7 @@ def __init__(self):
self.RouterPB = None
self.connectors = []
self.declared_queues = []
self.pickleProtocol = 2
self.pickleProtocol = pickle.HIGHEST_PROTOCOL

# Persistence flag, accessed through perspective_is_persisted
self.persisted = True
Expand Down Expand Up @@ -530,17 +530,11 @@ def perspective_connector_config(self, cid):
return pickle.dumps(connector['config'], self.pickleProtocol)

@defer.inlineCallbacks
def perspective_submit_sm(self, cid, SubmitSmPDU, priority=1, validity_period=None, pickled=True,
dlr_url=None, dlr_level=1, dlr_method='POST', submit_sm_resp_bill=None,
def perspective_submit_sm(self, cid, SubmitSmPDU, submit_sm_bill, priority=1, validity_period=None,
pickled=True, dlr_url=None, dlr_level=1, dlr_method='POST',
source_connector='httpapi'):
"""This will enqueue a submit_sm to a connector
"""

self.log.debug('Enqueuing a SUBMIT_SM to connector [%s]', cid)
if submit_sm_resp_bill is not None:
self.log.debug("... with a SubmitSmRespBill [bid:%s] [ttlamounts:%s]",
submit_sm_resp_bill.bid, submit_sm_resp_bill.getTotalAmounts())

connector = self.getConnector(cid)
if connector is None:
self.log.error('Trying to enqueue a SUBMIT_SM to a connector with an unknown cid: %s', cid)
Expand Down Expand Up @@ -570,19 +564,19 @@ def perspective_submit_sm(self, cid, SubmitSmPDU, priority=1, validity_period=No
self.log.warn('Removing schedule_delivery_time from SubmitSmPDU.')

PickledSubmitSmPDU = pickle.dumps(SubmitSmPDU, self.pickleProtocol)
submit_sm_resp_bill = pickle.dumps(submit_sm_resp_bill, self.pickleProtocol)
submit_sm_bill = pickle.dumps(submit_sm_bill, self.pickleProtocol)
else:
PickledSubmitSmPDU = SubmitSmPDU
SubmitSmPDU = pickle.loads(PickledSubmitSmPDU)

# Publishing a pickled PDU
self.log.debug('Publishing SubmitSmPDU with routing_key=%s, priority=%s', pubQueueName, priority)
c = SubmitSmContent(
PickledSubmitSmPDU,
responseQueueName,
priority,
validity_period,
submit_sm_resp_bill=submit_sm_resp_bill,
body=PickledSubmitSmPDU,
replyto=responseQueueName,
submit_sm_bill=submit_sm_bill,
priority=priority,
expiration=validity_period,
source_connector='httpapi' if source_connector == 'httpapi' else 'smppsapi')
yield self.amqpBroker.publish(exchange='messaging', routing_key=pubQueueName, content=c)

Expand All @@ -599,14 +593,14 @@ def perspective_submit_sm(self, cid, SubmitSmPDU, priority=1, validity_period=No
connector['config'].dlr_expiry)
# Set values and callback expiration setting
hashKey = "dlr:%s" % (c.properties['message-id'])
hashValues = {'url': dlr_url,
'level':dlr_level,
'method':dlr_method,
'expiry':connector['config'].dlr_expiry}
self.redisClient.setex(
hashKey,
connector['config'].dlr_expiry,
pickle.dumps(hashValues, self.pickleProtocol))
hashValues = {'sc': 'httpapi',
'url': dlr_url,
'level': dlr_level,
'method': dlr_method,
'expiry': connector['config'].dlr_expiry}
self.redisClient.hmset(hashKey, hashValues).addCallback(
lambda response: self.redisClient.expire(
hashKey, connector['config'].dlr_expiry))
elif (isinstance(source_connector, SMPPServerProtocol) and
SubmitSmPDU.params['registered_delivery'].receipt != RegisteredDeliveryReceipt.NO_SMSC_DELIVERY_RECEIPT_REQUESTED):
# If submit_sm is successfully sent from a SMPPServerProtocol connector and DLR is
Expand All @@ -623,16 +617,16 @@ def perspective_submit_sm(self, cid, SubmitSmPDU, priority=1, validity_period=No
SubmitSmPDU.params['registered_delivery'],
source_connector.factory.config.dlr_expiry)
# Set values and callback expiration setting
hashKey = "smppsmap:%s" % (c.properties['message-id'])
hashValues = {'system_id': source_connector.system_id,
hashKey = "dlr:%s" % (c.properties['message-id'])
hashValues = {'sc': 'smppsapi',
'system_id': source_connector.system_id,
'source_addr': SubmitSmPDU.params['source_addr'],
'destination_addr': SubmitSmPDU.params['destination_addr'],
'sub_date': datetime.datetime.now(),
'registered_delivery': SubmitSmPDU.params['registered_delivery'],
'rd_receipt': '%s' % SubmitSmPDU.params['registered_delivery'].receipt,
'expiry': source_connector.factory.config.dlr_expiry}
self.redisClient.setex(
hashKey,
source_connector.factory.config.dlr_expiry,
pickle.dumps(hashValues, self.pickleProtocol))
self.redisClient.hmset(hashKey, hashValues).addCallback(
lambda response: self.redisClient.expire(
hashKey, source_connector.factory.config.dlr_expiry))

defer.returnValue(c.properties['message-id'])
3 changes: 2 additions & 1 deletion jasmin/managers/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Config file handlers for 'client-management' and 'sm-listener' section in jasmin.cfg
"""

import cPickle as pickle
import logging
import ast
import os
Expand Down Expand Up @@ -34,7 +35,7 @@ def __init__(self, config_file=None):
self.log_rotate = self._get('client-management', 'log_rotate', 'W6')
self.log_format = self._get('client-management', 'log_format', DEFAULT_LOGFORMAT)
self.log_date_format = self._get('client-management', 'log_date_format', '%Y-%m-%d %H:%M:%S')
self.pickle_protocol = self._getint('client-management', 'pickle_protocol', 2)
self.pickle_protocol = self._getint('client-management', 'pickle_protocol', pickle.HIGHEST_PROTOCOL)

class SMPPClientSMListenerConfig(ConfigFile):
"Config handler for 'sm-listener' section"
Expand Down
13 changes: 6 additions & 7 deletions jasmin/managers/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

import uuid
import pickle
import cPickle as pickle
import datetime
from txamqp.content import Content

Expand All @@ -20,7 +20,7 @@ def randomUniqueId():
class PDU(Content):
"A generick SMPP PDU Content"

pickleProtocol = 2
pickleProtocol = pickle.HIGHEST_PROTOCOL

def __init__(self, body="", children=None, properties=None, pickleProtocol=2, prePickle=False):
self.pickleProtocol = pickleProtocol
Expand Down Expand Up @@ -97,8 +97,8 @@ def __init__(self, message_status, msgid, system_id, source_addr, destination_ad
class SubmitSmContent(PDU):
"A SMPP SubmitSm Content"

def __init__(self, body, replyto, priority=1, expiration=None, msgid=None,
submit_sm_resp_bill=None, source_connector='httpapi'):
def __init__(self, body, replyto, submit_sm_bill, priority=1, expiration=None, msgid=None,
source_connector='httpapi'):
props = {}

# RabbitMQ does not support priority (yet), anyway, we may use any other amqp broker that supports it
Expand All @@ -116,9 +116,8 @@ def __init__(self, body, replyto, priority=1, expiration=None, msgid=None,
props['message-id'] = msgid
props['reply-to'] = replyto

props['headers'] = {'source_connector': source_connector}
if submit_sm_resp_bill is not None:
props['headers']['submit_sm_resp_bill'] = submit_sm_resp_bill
props['headers'] = {'source_connector': source_connector,
'submit_sm_bill': submit_sm_bill}
if expiration is not None:
props['headers']['expiration'] = expiration

Expand Down

0 comments on commit e34d87a

Please sign in to comment.