Page MenuHomePhabricator

No OneTemporary

diff --git a/call-control b/call-control
index 692c9aa..5a2f052 100644
--- a/call-control
+++ b/call-control
@@ -1,138 +1,122 @@
#!/usr/bin/env python
# Copyright (C) 2005-2008 AG Projects. See LICENSE for details.
#
"""Implementation of a call controller for OpenSIPS."""
-def debug(method, **kwargs):
- import socket
- import select
-
- sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
- sock.connect('%s/socket' % process.runtime_directory)
-
- sock.sendall('debug\r\nshow: %s\r\n' % method + '\r\n'.join(['%s: %s' % (key, value) for key, value in kwargs.items()]) + '\r\n\r\n')
- response = ''
- while True:
- data = sock.recv(4096)
- response += data
- if not data or data.endswith('\r\n\r\n'):
- break
- sock.close()
- for line in response.splitlines():
- if line:
- print line
-
def send_command(command, **kwargs):
import socket
import select
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect('%s/socket' % process.runtime_directory)
sock.sendall('%s\r\n' % command + '\r\n'.join(['%s: %s' % (key, value) for key, value in kwargs.items()]) + '\r\n\r\n')
response = ''
while True:
data = sock.recv(4096)
response += data
if not data or data.endswith('\r\n\r\n'):
break
sock.close()
for line in response.splitlines():
if line:
print line
if __name__ == '__main__':
import sys
from optparse import OptionParser
from application.process import process, ProcessError
from application import log
import callcontrol
name = 'call-control'
fullname = 'SIP call-control'
description = 'Implementation of call-control for SIP'
config_directory = '/etc/callcontrol'
runtime_directory = '/var/run/callcontrol'
default_pid = "%s/%s.pid" % (runtime_directory, name)
parser = OptionParser(version="%%prog %s" % callcontrol.__version__)
parser.add_option("--no-fork", action="store_false", dest="fork", default=True,
help="run the process in the foreground")
parser.add_option("--pid", dest="pid_file", default='/var/run/callcontrol/call-control.pid',
help="pid file (/var/run/callcontrol/call-control.pid)",
metavar="FILE")
parser.add_option("--debug", dest="debug", default=None,
help="get information about a currently running call-control daemon",
metavar="COMMAND")
parser.add_option("--terminate", dest="terminate", default=None,
help="terminate an on-going session",
metavar="CALLID")
(options, args) = parser.parse_args()
pid_file = options.pid_file
process._system_config_directory = config_directory
try:
process.runtime_directory = runtime_directory
except ProcessError, e:
log.fatal(str(e))
sys.exit(1)
if options.debug is not None and options.terminate is not None:
print >>sys.stderr, 'Cannot run with both --debug and --terminate options in the same time'
sys.exit(1)
if options.debug:
+ if options.debug == '':
+ print >>sys.stderr, 'Must specify debug option'
+ sys.exit(1)
try:
- debug(options.debug, **dict([arg.split('=',1) for arg in args if arg.find('=') >= 0]))
+ send_command('debug', show=options.debug, **dict([arg.split('=',1) for arg in args if arg.find('=') >= 0]))
except Exception, e:
print >>sys.stderr, 'Error while debugging: %s' % e
sys.exit(1)
else:
sys.exit(0)
if options.terminate is not None:
if options.terminate == '':
print >>sys.stderr, 'Must specify callid to terminate'
sys.exit(1)
try:
send_command('terminate', callid=options.terminate)
except Exception, e:
print >>sys.stderr, 'Error while terminating session: %s' % e
else:
sys.exit(0)
if options.fork:
try:
process.daemonize(pid_file)
except ProcessError, e:
log.fatal(str(e))
sys.exit(1)
log.startSyslog(name)
log.msg("Starting %s %s" % (fullname, callcontrol.__version__))
from callcontrol.controller import CallControlServer
if not options.fork:
from application.debug.memory import *
try:
cserver = CallControlServer()
except Exception, e:
log.error("failed to create SIP Call Control Server: %s" % e)
log.err()
sys.exit(1)
try:
cserver.run()
except Exception, e:
log.error("failed to start SIP Call Control Server: %s" % e)
if not options.fork:
memory_dump()

File Metadata

Mime Type
text/x-diff
Expires
Sat, Dec 28, 1:26 PM (1 d, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3454297
Default Alt Text
(4 KB)

Event Timeline