- print "Press Ctrl+D on an empty line to end input and send the MESSAGE request."
+ possible_accounts = [account for account in account_manager.iter_accounts() if self.options.account in account.id and account.enabled]
+ if len(possible_accounts) > 1:
+ self.output.put('More than one account exists which matches %s: %s\n' % (self.options.account, ', '.join(sorted(account.id for account in possible_accounts))))
+ self.output.stop()
+ self.stop()
+ return
+ elif len(possible_accounts) == 0:
+ self.output.put('No enabled account which matches %s was found. Available and enabled accounts: %s\n' % (self.options.account, ', '.join(sorted(account.id for account in account_manager.get_accounts() if account.enabled))))
+ self.output.stop()
+ self.stop()
+ return
else:
- msg_buf.append(message)
- queue.put(("eof", None))
- while True:
- command, data = queue.get()
- if command == "print":
- print data
- if command == "core_event":
- event_name, obj, args = data
- if event_name == "SIPSessionNewIncoming":
- obj.reject(405)
- elif event_name == "DNSLookupDidFail" and obj is dns:
- print "DNS lookup failed: %(error)s" % args
- user_quit = False
- command = "quit"
- elif event_name == "DNSLookupDidSucceed" and obj is dns:
- routes = args["result"]
- if len(routes) == 0:
- print "No route found to SIP proxy"
- user_quit = False
- command = "quit"
- else:
- if sending:
- command = "send_message"
- elif event_name == "SIPEngineGotMessage":
- args["from"] = args["from_header"].body
- print 'Received MESSAGE from "%(from)s", Content-Type: %(content_type)s/%(content_subtype)s' % args
- print args["body"]
- elif event_name == "SIPMessageDidSucceed":
- print "MESSAGE was accepted by remote party."
- user_quit = False
- command = "quit"
- elif event_name == "SIPMessageDidFail":
- print "Could not deliver MESSAGE: %(code)d %(reason)s" % args
+ self.output.put('Listening on: sip:%s@%s:%d;transport=%s\n' % (contact.user, contact.host, contact.port, contact.parameters['transport'] if 'transport' in contact.parameters else 'udp'))
+ self.output.put('No more routes to try. Aborting.\n')
+ self.stop()
- ctrl_d_pressed = False
- try:
- while True:
- try:
- msg = raw_input()
- queue.put(("user_input", msg))
- except EOFError:
- if not ctrl_d_pressed:
- queue.put(("eof", None))
- ctrl_d_pressed = True
- except KeyboardInterrupt:
- if user_quit:
- print "Ctrl+C pressed, exiting instantly!"
- finally:
- queue.put(("quit", True))
- lock.acquire()
-
-def parse_options():
- retval = {}
+if __name__ == '__main__':
description = "This will either sit idle waiting for an incoming MESSAGE request, or send a MESSAGE request to the specified SIP target. In outgoing mode the program will read the contents of the messages to be sent from standard input, Ctrl+D signalling EOF as usual. In listen mode the program will quit when Ctrl+D is pressed."
- parser.add_option("-a", "--account", type="string", dest="account_id", help="The account name to use for any outgoing traffic. If not supplied, the default account will be used.", metavar="NAME")
- parser.add_option("-s", "--trace-sip", action="store_true", dest="trace_sip", default=False, help="Dump the raw contents of incoming and outgoing SIP messages.")
- parser.add_option("-n", "--trace-notifications", action="store_true", dest="trace_notifications", default=False, help="Print all notifications (disabled by default).")
- parser.add_option("-m", "--message", type="string", dest="message", help="Contents of the message to send. This disables reading the message from standard input.")
+ parser.add_option('-a', '--account', type='string', dest='account', help='The account name to use for any outgoing traffic. If not supplied, the default account will be used.', metavar='NAME')
+ parser.add_option('-c', '--config-file', type='string', dest='config_file', help='The path to a configuration file to use. This overrides the default location of the configuration file.', metavar='FILE')
+ parser.add_option('-s', '--trace-sip', action='store_true', dest='trace_sip', default=False, help='Dump the raw contents of incoming and outgoing SIP messages.')
+ parser.add_option('-n', '--trace-notifications', action='store_true', dest='trace_notifications', default=False, help='Print all notifications (disabled by default).')
+ parser.add_option('-b', '--batch', action='store_true', dest='batch_mode', default=False, help='Run the program in batch mode: reading control input from the console is disabled. This is particularly useful when running this script in a non-interactive environment.')
+ parser.add_option('-m', '--message', type='string', dest='message', help='Contents of the message to send. This disables reading the message from standard input.')