# If NAPTR lookup fails for some reason, try SRV lookup for all supported transports.
# Only the transports of those lookups that succeed are supported by the server.
srv_candidates = [(transport, "%s.%s" % (_transport_srv_service_map[transport], uri.host)) for transport in supported_transports]
else:
# If NAPTR lookup succeeds, order those entries that are applicable for SIP based on server prefernce.
naptr_answers = [answer for answer in naptr_answers if answer.flags.lower() == "s" and answer.service.lower() in _naptr_service_transport_map and _naptr_service_transport_map[answer.service.lower()] in supported_transports]
naptr_answers.sort(key=lambda x: x.preference)
naptr_answers.sort(key=lambda x: x.order)
if len(naptr_answers) == 0:
raise RuntimeError("Could find a suitable transport in NAPTR record of domain")
srv_candidates = [(_naptr_service_transport_map[answer.service.lower()], answer.replacement) for answer in naptr_answers]
else:
# Directly try the SRV record of the requested transport.
description = "This script can sit idle waiting for an incoming audio call, or perform an outgoing audio call to the target SIP account. The program will close the session and quit when Ctrl+D is pressed."
parser.add_option("-a", "--account-name", type="string", dest="account_name", help="The account name from which to read account settings. Corresponds to section Account_NAME in the configuration file. If not supplied, the section Account will be read.", metavar="NAME")
parser.add_option("--sip-address", type="string", dest="sip_address", help="SIP address of the user in the form user@domain")
parser.add_option("-p", "--password", type="string", dest="password", help="Password to use to authenticate the local account. This overrides the setting from the config file.")
parser.add_option("-n", "--display-name", type="string", dest="display_name", help="Display name to use for the local account. This overrides the setting from the config file.")
parser.add_option("-o", "--outbound-proxy", type="string", action="callback", callback=parse_outbound_proxy, help="Outbound SIP proxy to use. By default a lookup of the domain is performed based on SRV and A records. This overrides the setting from the config file.", metavar="IP[:PORT]")
parser.add_option("-s", "--trace-sip", action="store_true", dest="trace_sip", help="Dump the raw contents of incoming and outgoing SIP messages (disabled by default).")
parser.add_option("-t", "--ec-tail-length", type="int", dest="ec_tail_length", help='Echo cancellation tail length in ms, setting this to 0 will disable echo cancellation. Default is 50 ms.')
parser.add_option("-r", "--sample-rate", type="int", dest="sample_rate", help='Sample rate in kHz, should be one of 8, 16 or 32kHz. Default is 32kHz.')
parser.add_option("-c", "--codecs", type="string", action="callback", callback=split_codec_list, help='Comma separated list of codecs to be used. Default is "speex,g711,ilbc,gsm,g722".')
parser.add_option("-S", "--disable-sound", action="store_true", dest="disable_sound", help="Do not initialize the soundcard (by default the soundcard is enabled).")
parser.add_option("--auto-hangup", action="callback", callback=parse_auto_hangup, help="Interval after which to hangup an on-going call (applies only to outgoing calls, disabled by default). If the option is specified but the interval is not, it defaults to 0 (hangup the call as soon as it connects).", metavar="[INTERVAL]")
description = "This script will publish rich presence state of the specified SIP account to a SIP Presence Agent, the presence information can be changed using a menu-driven interface."
parser.add_option("-a", "--account-name", type="string", dest="account_name", help="The account name from which to read account settings. Corresponds to section Account_NAME in the configuration file. If not supplied, the section Account will be read.", metavar="NAME")
parser.add_option("--sip-address", type="string", dest="sip_address", help="SIP address of the user in the form user@domain")
parser.add_option("-e", "--expires", type="int", dest="expires", help='"Expires" value to set in PUBLISH. Default is 300 seconds.')
parser.add_option("-o", "--outbound-proxy", type="string", action="callback", callback=parse_outbound_proxy, help="Outbound SIP proxy to use. By default a lookup of the domain is performed based on SRV and A records. This overrides the setting from the config file.", metavar="IP[:PORT]")
parser.add_option("-i", "--interval", type="int", dest="interval", help='Time between state changes. Default is 60 seconds.')
parser.add_option("-s", "--trace-sip", action="store_true", dest="trace_sip", help="Dump the raw contents of incoming and outgoing SIP messages (disabled by default).")
print 'Registering "%s" at %s:%s:%d' % (credentials.uri, route.transport, route.host, route.port)
reg.register()
else:
if message is None:
print "Press Ctrl+D on an empty line to end input and send the MESSAGE request."
else:
msg_buf.append(message)
queue.put(("eof", None))
while True:
command, data = queue.get()
if command == "print":
print data
if command == "pypjua_event":
event_name, args = data
if event_name == "Registration_state":
if args["state"] == "registered":
if not printed:
print "REGISTER was successful"
print "Contact: %s (expires in %d seconds)" % (args["contact_uri"], args["expires"])
if len(args["contact_uri_list"]) > 1:
print "Other registered contacts:\n%s" % "\n".join(["%s (expires in %d seconds)" % contact_tup for contact_tup in args["contact_uri_list"] if contact_tup[0] != args["contact_uri"]])
print "Press Ctrl+D to stop the program."
printed = True
elif args["state"] == "unregistered":
if "code" in args and args["code"] / 100 != 2:
print "Unregistered: %(code)d %(reason)s" % args
user_quit = False
command = "quit"
elif event_name == "Invitation_state":
if args["state"] == "INCOMING":
args["obj"].end()
elif event_name == "message":
print 'Received MESSAGE from "%(from_uri)s", Content-Type: %(content_type)s/%(content_subtype)s' % args
print args["body"]
elif event_name == "message_response":
if args["code"] / 100 != 2:
print "Could not deliver MESSAGE: %(code)d %(reason)s" % args
else:
print "MESSAGE was accepted by remote party."
user_quit = False
command = "quit"
if command == "user_input":
if not sent:
msg_buf.append(data)
if command == "eof":
if target_uri is None:
reg.unregister()
elif not sent:
sent = True
print 'Sending MESSAGE from "%s" to "%s" using proxy %s:%s:%d' % (credentials.uri, target_uri, route.transport, route.host, route.port)
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-name", type="string", dest="account_name", help="The account name from which to read account settings. Corresponds to section Account_NAME in the configuration file.")
parser.add_option("-p", "--password", type="string", dest="password", help="Password to use to authenticate the local account. This overrides the setting from the config file.")
parser.add_option("-n", "--display-name", type="string", dest="display_name", help="Display name to use for the local account. This overrides the setting from the config file.")
parser.add_option("-o", "--outbound-proxy", type="string", action="callback", callback=parse_outbound_proxy, help="Outbound SIP proxy to use. By default a lookup of the domain is performed based on SRV and A records. This overrides the setting from the config file.", metavar="IP[:PORT]")
parser.add_option("-s", "--trace-sip", action="store_true", dest="trace_sip", help="Dump the raw contents of incoming and outgoing SIP messages (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.")
description = "This script will publish rich presence state of the specified SIP account to a SIP Presence Agent, the presence information can be changed using a menu-driven interface."
parser.add_option("-a", "--account-name", type="string", dest="account_name", help="The account name from which to read account settings. Corresponds to section Account_NAME in the configuration file. If not supplied, the section Account will be read.", metavar="NAME")
parser.add_option("--sip-address", type="string", dest="sip_address", help="SIP address of the user in the form user@domain")
parser.add_option("-e", "--expires", type="int", dest="expires", help='"Expires" value to set in PUBLISH. Default is 300 seconds.')
parser.add_option("-o", "--outbound-proxy", type="string", action="callback", callback=parse_outbound_proxy, help="Outbound SIP proxy to use. By default a lookup of the domain is performed based on SRV and A records. This overrides the setting from the config file.", metavar="IP[:PORT]")
parser.add_option("-s", "--trace-sip", action="store_true", dest="trace_sip", help="Dump the raw contents of incoming and outgoing SIP messages (disabled by default).")
print 'Registering "%s" at %s:%s:%d' % (credentials.uri, route.transport, route.host, route.port)
reg.register()
while True:
command, data = queue.get()
if command == "print":
print data
if command == "pypjua_event":
event_name, args = data
if event_name == "Registration_state":
if args["state"] == "registered":
return_code = 0
if not printed:
print "REGISTER was successful"
print "Contact: %s (expires in %d seconds)" % (args["contact_uri"], args["expires"])
if len(args["contact_uri_list"]) > 1:
print "Other registered contacts:\n%s" % "\n".join(["%s (expires in %d seconds)" % contact_tup for contact_tup in args["contact_uri_list"] if contact_tup[0] != args["contact_uri"]])
print "Press Ctrl+D to stop the program."
printed = True
if max_registers is not None:
max_registers -= 1
if max_registers <= 0:
command = "eof"
elif args["state"] == "unregistered":
if "code" in args and args["code"] / 100 != 2:
print "Unregistered: %(code)d %(reason)s" % args
user_quit = False
command = "quit"
elif event_name == "Invitation_state":
if args["state"] == "INCOMING":
args["obj"].end()
if command == "user_input":
key = data
if key == 's':
logger.trace_sip = not logger.trace_sip
print "SIP tracing is now %s" % ("activated" if logger.trace_sip else "deactivated")
if key == 'l':
do_trace_pjsip = not do_trace_pjsip
print "PJSIP logging is now %s" % ("activated" if do_trace_pjsip else "deactivated")
if command == "eof":
reg.unregister()
if command == "quit":
break
except:
user_quit = False
traceback.print_exc()
finally:
e.stop()
logger.stop()
if not user_quit:
os.kill(os.getpid(), signal.SIGINT)
lock.release()
def do_register(**kwargs):
global user_quit, lock, queue, do_trace_pjsip, logger
description = "This script will register a SIP account to a SIP registrar and refresh it while the program is running. When Ctrl+D is pressed it will unregister."
parser.add_option("-a", "--account-name", type="string", dest="account_name", help="The account name from which to read account settings. Corresponds to section Account_NAME in the configuration file.")
parser.add_option("-p", "--password", type="string", dest="password", help="Password to use to authenticate the local account. This overrides the setting from the config file.")
parser.add_option("-n", "--display-name", type="string", dest="display_name", help="Display name to use for the local account. This overrides the setting from the config file.")
parser.add_option("-e", "--expires", type="int", dest="expires", help='"Expires" value to set in REGISTER. Default is 300 seconds.')
parser.add_option("-o", "--outbound-proxy", type="string", action="callback", callback=parse_outbound_proxy, help="Outbound SIP proxy to use. By default a lookup of the domain is performed based on SRV and A records. This overrides the setting from the config file.", metavar="IP[:PORT]")
parser.add_option("-s", "--trace-sip", action="store_true", dest="trace_sip", help="Dump the raw contents of incoming and outgoing SIP messages (disabled by default).")
description = "This script will SUBSCRIBE to the presence event published by the specified SIP target. If a SIP target is not specified, it will subscribe to its own address. It will then interprete PIDF bodies contained in NOTIFYs and display their meaning. The program will un-SUBSCRIBE and quit when CTRL+D is pressed."
parser.add_option("-a", "--account-name", type="string", dest="account_name", help="The account name from which to read account settings. Corresponds to section Account_NAME in the configuration file. If not supplied, the section Account will be read.", metavar="NAME")
parser.add_option("--sip-address", type="string", dest="sip_address", help="SIP address of the user in the form user@domain")
parser.add_option("-p", "--password", type="string", dest="password", help="Password to use to authenticate the local account. This overrides the setting from the config file.")
parser.add_option("-n", "--display-name", type="string", dest="display_name", help="Display name to use for the local account. This overrides the setting from the config file.")
parser.add_option("-e", "--expires", type="int", dest="expires", help='"Expires" value to set in SUBSCRIBE. Default is 300 seconds.')
parser.add_option("-o", "--outbound-proxy", type="string", action="callback", callback=parse_outbound_proxy, help="Outbound SIP proxy to use. By default a lookup of the domain is performed based on SRV and A records. This overrides the setting from the config file.", metavar="IP[:PORT]")
parser.add_option("-c", "--content-type", type="string", dest="content_type", help = '"Content-Type" the UA expects to receving in a NOTIFY for this subscription. For the known events this does not need to be specified, but may be overridden".')
parser.add_option("-s", "--trace-sip", action="store_true", dest="trace_sip", help="Dump the raw contents of incoming and outgoing SIP messages (disabled by default).")
buf.append(" Current sphere: %s" % person.sphere.values[0])
# display status icon
if person.status_icon is not None:
buf.append(" Status icon: %s" % person.status_icon)
# display time offset
if person.time_offset is not None:
buf.append(" Time offset from UTC: %s minutes %s" % (person.time_offset, (person.time_offset.description is not None and ('(%s)' % person.time_offset.description) or '')))
# display user input
if person.user_input is not None:
buf.append(" User is %s" % person.user_input)
if person.user_input.last_input:
buf.append(" Last input at: %s" % person.user_input.last_input)
description = "This script will SUBSCRIBE to the presence event published by the specified SIP target assuming it is a resource list handled by a RLS server. The RLS server will then SUBSCRIBE in behalf of the account, collect NOTIFYs with the presence information of the recipients and provide periodically aggregated NOTIFYs back to the subscriber. If a target address is not specified, it will subscribe to the account's own address. It will then interprete PIDF bodies contained in NOTIFYs and display their meaning. The program will un-SUBSCRIBE and quit when CTRL+D is pressed."
parser.add_option("-a", "--account-name", type="string", dest="account_name", help="The account name from which to read account settings. Corresponds to section Account_NAME in the configuration file. If not supplied, the section Account will be read.", metavar="NAME")
parser.add_option("--sip-address", type="string", dest="sip_address", help="SIP address of the user in the form user@domain")
parser.add_option("-p", "--password", type="string", dest="password", help="Password to use to authenticate the local account. This overrides the setting from the config file.")
parser.add_option("-n", "--display-name", type="string", dest="display_name", help="Display name to use for the local account. This overrides the setting from the config file.")
parser.add_option("-e", "--expires", type="int", dest="expires", help='"Expires" value to set in SUBSCRIBE. Default is 300 seconds.')
parser.add_option("-o", "--outbound-proxy", type="string", action="callback", callback=parse_outbound_proxy, help="Outbound SIP proxy to use. By default a lookup of the domain is performed based on SRV and A records. This overrides the setting from the config file.", metavar="IP[:PORT]")
parser.add_option("-c", "--content-type", type="string", dest="content_type", help = '"Content-Type" the UA expects to receving in a NOTIFY for this subscription. For the known events this does not need to be specified, but may be overridden".')
parser.add_option("-s", "--trace-sip", action="store_true", dest="trace_sip", help="Dump the raw contents of incoming and outgoing SIP messages (disabled by default).")
print 'Retrieving current presence rules from %s' % xcap_root
get_prules()
print 'Allowed list:'
if allow_rule_identities is not None:
for identity in allow_rule_identities:
print '\t%s' % identity
print 'Blocked list:'
if block_rule_identities is not None:
for identity in block_rule_identities:
print '\t%s' % identity
print 'Polite-blocked list:'
if polite_block_rule_identities is not None:
for identity in polite_block_rule_identities:
print '\t%s' % identity
print 'Subscribing to "%s@%s" for the presence.winfo event, at %s:%d' % (sip_uri.user, sip_uri.host, route.host, route.port)
sub.subscribe()
while True:
command, data = queue.get()
if command == "print":
print data
if len(pending) > 0:
print "%s watcher %s wants to subscribe to your presence information. Press (a) for allow, (d) for deny or (p) for polite blocking:" % (pending[0].status.capitalize(), pending[0])
if command == "pypjua_event":
event_name, args = data
if command == "user_input":
key = data
if len(pending) > 0:
if key == 'a':
watcher = pending.popleft()
allow_watcher(watcher)
elif key == 'd':
watcher = pending.popleft()
block_watcher(watcher)
elif key == 'p':
watcher = pending.popleft()
polite_block_watcher(watcher)
else:
print "Please select a valid choice. Press (a) to allow, (d) to deny, (p) to polite block"
if len(pending) > 0:
print "%s watcher %s wants to subscribe to your presence information. Press (a) for allow, (d) for deny or (p) for polite blocking:" % (pending[0].status.capitalize(), pending[0])
if command == "eof":
command = "end"
want_quit = True
if command == "end":
try:
sub.unsubscribe()
except:
pass
if command == "quit":
user_quit = False
break
except:
user_quit = False
traceback.print_exc()
finally:
e.stop()
logger.stop()
if not user_quit:
os.kill(os.getpid(), signal.SIGINT)
lock.release()
def do_subscribe(**kwargs):
global user_quit, lock, queue, do_trace_pjsip, logger
description = "This script displays the current presence rules, SUBSCRIBEs to the presence.winfo event of itself and prompts the user to update the presence rules document when a new watcher is in 'pending'/'waiting' state. The program will un-SUBSCRIBE and quit when CTRL+D is pressed."
parser.add_option("-a", "--account-name", type="string", dest="account_name", help="The account name from which to read account settings. Corresponds to section Account_NAME in the configuration file. If not supplied, the section Account will be read.", metavar="NAME")
parser.add_option("--sip-address", type="string", dest="sip_address", help="SIP address of the user in the form user@domain")
parser.add_option("-p", "--password", type="string", dest="password", help="Password to use to authenticate the local account. This overrides the setting from the config file.")
parser.add_option("-n", "--display-name", type="string", dest="display_name", help="Display name to use for the local account. This overrides the setting from the config file.")
parser.add_option("-e", "--expires", type="int", dest="expires", help='"Expires" value to set in SUBSCRIBE. Default is 300 seconds.')
parser.add_option("-o", "--outbound-proxy", type="string", action="callback", callback=parse_outbound_proxy, help="Outbound SIP proxy to use. By default a lookup of the domain is performed based on SRV and A records. This overrides the setting from the config file.", metavar="IP[:PORT]")
parser.add_option("-x", "--xcap-root", type="string", dest="xcap_root", help = 'The XCAP root to use to access the pres-rules document for authorizing subscriptions to presence.')
parser.add_option("-s", "--trace-sip", action="store_true", dest="trace_sip", help="Dump the raw contents of incoming and outgoing SIP messages (disabled by default).")
res = xcap_client.put('pres-rules', prules.toxml(pretty_print=True), etag=prules_etag)
except HTTPError, e:
print "Cannot PUT 'pres-rules' document: %s" % str(e)
prules = None
else:
prules_etag = res.etag
if show_xml:
print "Presence rules document:"
print prules.toxml(pretty_print=True)
print "Watcher %s is now politely blocked" % watcher
break
sleep(0.1)
else:
print "Could not politely block authorization of watcher %s" % watcher
def remove_watcher(watcher):
global prules, prules_etag, allow_rule_identities, block_rule_identities, polite_block_rule_identities
for i in xrange(3):
if prules is None:
get_prules()
if prules is not None:
if allow_rule_identities is not None and str(watcher) in allow_rule_identities:
allow_rule_identities.remove(str(watcher))
if len(allow_rule_identities) == 0:
prules.remove(allow_rule)
if block_rule_identities is not None and str(watcher) in block_rule_identities:
block_rule_identities.remove(str(watcher))
if len(block_rule_identities) == 0:
prules.remove(block_rule)
if polite_block_rule_identities is not None and str(watcher) in polite_block_rule_identities:
polite_block_rule_identities.remove(str(watcher))
if len(polite_block_rule_identities) == 0:
prules.remove(polite_block_rule)
try:
res = xcap_client.put('pres-rules', prules.toxml(pretty_print=True), etag=prules_etag)
except HTTPError, e:
print "Cannot PUT 'pres-rules' document: %s" % str(e)
prules = None
else:
prules_etag = res.etag
if show_xml:
print "Presence rules document:"
print prules.toxml(pretty_print=True)
print "Watcher %s has been removed from the rules" % watcher
break
sleep(0.1)
else:
print "Could not politely block authorization of watcher %s" % watcher
def print_prules():
global allow_rule_identities, block_rule_identities, polite_block_rule_identities
print 'Allowed watchers:'
if allow_rule_identities is not None:
for identity in allow_rule_identities:
print '\t%s' % str(identity).replace('sip:', '')
print 'Blocked watchers:'
if block_rule_identities is not None:
for identity in block_rule_identities:
print '\t%s' % str(identity).replace('sip:', '')
print 'Polite-blocked watchers:'
if polite_block_rule_identities is not None:
for identity in polite_block_rule_identities:
print '\t%s' % str(identity).replace('sip:', '')
print "Press (a) to allow, (d) to deny, (p) to politely block a new watcher or (r) to remove a watcher from the rules. (s) will show the presence rules xml."
print 'Retrieving current presence rules from %s' % xcap_root
get_prules()
if show_xml and prules is not None:
print "Presence rules document:"
print prules.toxml(pretty_print=True)
print_prules()
while True:
command, data = queue.get()
if command == "print":
print data
if command == "pypjua_event":
event_name, args = data
if command == "user_input":
key = data
if key == 'a':
watcher = getstr('watcher')
if watcher != '':
watcher = 'sip:' + watcher
allow_watcher(watcher)
elif key == 'd':
watcher = getstr('watcher')
if watcher != '':
watcher = 'sip:' + watcher
block_watcher(watcher)
elif key == 'p':
watcher = getstr('watcher')
if watcher != '':
watcher = 'sip:' + watcher
polite_block_watcher(watcher)
elif key == 'r':
watcher = getstr('watcher')
if watcher != '':
watcher = 'sip:' + watcher
remove_watcher(watcher)
elif key == 's':
if prules is not None:
print "Presence rules document:"
print prules.toxml(pretty_print=True)
print_prules()
if command == "eof":
command = "end"
want_quit = True
if command == "quit" or command == "end":
user_quit = False
break
except:
user_quit = False
traceback.print_exc()
finally:
if not user_quit:
os.kill(os.getpid(), signal.SIGINT)
lock.release()
def do_xcap_pres_rules(**kwargs):
global user_quit, lock, queue, string, getstr_event, old, show_xml
ctrl_d_pressed = False
show_xml = kwargs.pop('show_xml')
start_new_thread(read_queue,(), kwargs)
atexit.register(termios_restore)
try:
while True:
char = getchar()
if char == "\x04":
if not ctrl_d_pressed:
queue.put(("eof", None))
ctrl_d_pressed = True
else:
if string is not None:
if char == "\x7f":
if len(string) > 0:
char = "\x08"
sys.stdout.write("\x08 \x08")
sys.stdout.flush()
string = string[:-1]
else:
if old is not None:
sys.stdout.write(char)
sys.stdout.flush()
if char == "\x0A":
getstr_event.set()
else:
string += char
else:
queue.put(("user_input", char))
except KeyboardInterrupt:
if user_quit:
print "Ctrl+C pressed, exiting instantly!"
queue.put(("quit", True))
lock.acquire()
return
def parse_options():
retval = {}
description = "This example script will use the specified SIP account to manage presence rules via XCAP. The program will quit when CTRL+D is pressed."
parser.add_option("-a", "--account-name", type="string", dest="account_name", help="The account name from which to read account settings. Corresponds to section Account_NAME in the configuration file. If not supplied, the section Account will be read.", metavar="NAME")
parser.add_option("--sip-address", type="string", dest="sip_address", help="SIP address of the user in the form user@domain")
parser.add_option("-p", "--password", type="string", dest="password", help="Password to use to authenticate the local account. This overrides the setting from the config file.")
parser.add_option("-x", "--xcap-root", type="string", dest="xcap_root", help = 'The XCAP root to use to access the pres-rules document for authorizing subscriptions to presence.')
parser.add_option("-s", "--show-xml", action="store_true", dest="show_xml", help = 'Show the presence rules XML whenever it is changed and at start-up.')
print 'Retrieving current RLS services from %s' % xcap_root
get_rls_services()
if show_xml and rls_services is not None:
print "RLS services document:"
print rls_services.toxml(pretty_print=True)
print 'Managing service URI %s' % service_uri
print_rls_services()
while True:
command, data = queue.get()
if command == "print":
print data
if command == "pypjua_event":
event_name, args = data
if command == "user_input":
key = data
if key == 'a':
buddy = getstr('new buddy')
if buddy != '':
if '@' not in buddy:
buddy = 'sip:%s@%s' % (buddy, domain)
else:
buddy = 'sip:%s' % buddy
add_buddy(buddy)
elif key == 'r':
buddy = getstr('buddy to delete')
if buddy != '':
if '@' not in buddy:
buddy = 'sip:%s@%s' % (buddy, domain)
else:
buddy = 'sip:%s' % buddy
remove_buddy(buddy)
elif key == 's':
if rls_services is not None:
print "RLS services document:"
print rls_services.toxml(pretty_print=True)
elif key == 'd':
delete_service()
if key != 'd':
print_rls_services()
if command == "eof":
command = "end"
want_quit = True
if command == "quit" or command == "end":
user_quit = False
break
except:
user_quit = False
traceback.print_exc()
finally:
if not user_quit:
os.kill(os.getpid(), signal.SIGINT)
lock.release()
def do_xcap_rls_services(**kwargs):
global user_quit, lock, queue, string, getstr_event, old, show_xml
ctrl_d_pressed = False
show_xml = kwargs.pop('show_xml')
start_new_thread(read_queue,(), kwargs)
atexit.register(termios_restore)
try:
while True:
for char in getchar():
if char == "\x04":
if not ctrl_d_pressed:
queue.put(("eof", None))
ctrl_d_pressed = True
break
else:
if string is not None:
if char == "\x7f":
if len(string) > 0:
char = "\x08"
sys.stdout.write("\x08 \x08")
sys.stdout.flush()
string = string[:-1]
else:
if old is not None:
sys.stdout.write(char)
sys.stdout.flush()
if char == "\x0A":
getstr_event.set()
break
else:
string += char
else:
queue.put(("user_input", char))
except KeyboardInterrupt:
if user_quit:
print "Ctrl+C pressed, exiting instantly!"
queue.put(("quit", True))
lock.acquire()
return
def parse_options():
global service_uri
retval = {}
description = "This example script will use the specified SIP account to manage rls services via XCAP. The program will quit when CTRL+D is pressed. You can specify the service URI as an argument (if domain name is not specified, the user's domain name will be used). If it is not specified, it defaults to username-buddies@domain."
parser.add_option("-a", "--account-name", type="string", dest="account_name", help="The account name from which to read account settings. Corresponds to section Account_NAME in the configuration file. If not supplied, the section Account will be read.", metavar="NAME")
parser.add_option("--sip-address", type="string", dest="sip_address", help="SIP address of the user in the form user@domain")
parser.add_option("-p", "--password", type="string", dest="password", help="Password to use to authenticate the local account. This overrides the setting from the config file.")
parser.add_option("-x", "--xcap-root", type="string", dest="xcap_root", help = 'The XCAP root to use to access the rls-services document to manage.')
parser.add_option("-s", "--show-xml", action="store_true", dest="show_xml", help = 'Show the RLS services XML whenever it is changed and at start-up.')